Comparing version 4.0.0 to 4.1.0
48
index.js
@@ -5,2 +5,3 @@ const Strategy = require('@tangle/strategy') | ||
const { promisify } = require('util') | ||
const pull = require('pull-stream') | ||
@@ -12,2 +13,3 @@ const isValidSpec = require('./lib/is-valid-spec') | ||
const HandlePublish = require('./lib/handle-publish') | ||
const CreateStream = require('./lib/create-stream') | ||
const { merge, isObject, pick, defaultGetTransformation } = require('./lib/util') | ||
@@ -57,2 +59,4 @@ | ||
if (this.spec.arbitraryRoot && ssb.tribes) this.getTribe = ssb.tribes.get | ||
this.createStream = CreateStream(ssb, this.spec) | ||
} | ||
@@ -191,2 +195,39 @@ | ||
list (opts, cb) { | ||
if (opts === undefined) opts = {} | ||
if (cb === undefined) return promisify(this.list).call(this, opts) | ||
let hasReachedStartFrom = false | ||
pull( | ||
this.createStream(opts), | ||
opts.startFrom | ||
? pull.filter(msg => { | ||
if (hasReachedStartFrom) return true | ||
if (msg.key === opts.startFrom) hasReachedStartFrom = true | ||
return false | ||
}) | ||
: null, | ||
// map rootMsg => record (and filter out the ones which were junk) | ||
pull.asyncMap((msg, cb) => { | ||
this.read(msg.key, (err, record) => { | ||
if (err) cb(null, false) | ||
else cb(null, record) | ||
}) | ||
}), | ||
pull.filter(Boolean), | ||
// filter out the tombstoned | ||
opts.tombstoned | ||
? pull.filter(record => record.tombstone !== null) | ||
: pull.filter(record => record.tombstone === null), | ||
// limit | ||
opts.limit ? pull.take(opts.limit) : null, | ||
pull.collect(cb) | ||
) | ||
} | ||
tombstone (id, props, cb) { | ||
@@ -255,3 +296,8 @@ if (cb === undefined) return promisify(this.tombstone).call(this, id, props) | ||
function checkServerDeps (ssb) { | ||
if (!ssb.db && !ssb.backlinks) throw new Error('ssb-crut requires EITHER ssb-db + ssb-backlinks OR ssb-db2') | ||
const db1Support = Boolean(ssb.backlinks) && Boolean(ssb.query) | ||
const db2Support = Boolean(ssb.db) | ||
if (!db1Support && !db2Support) { | ||
throw new Error('ssb-crut requires EITHER (ssb-db + ssb-backlinks + ssb-query) OR ssb-db2') | ||
} | ||
} | ||
@@ -258,0 +304,0 @@ |
{ | ||
"name": "ssb-crut", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "easy CRUT methods for secure scuttlebutt", | ||
@@ -48,3 +48,3 @@ "main": "index.js", | ||
"ssb-backlinks": "^2.1.1", | ||
"ssb-db2": "^2.4.0", | ||
"ssb-db2": "^3.1.0", | ||
"ssb-query": "^2.4.5", | ||
@@ -51,0 +51,0 @@ "ssb-recps-guard": "^2.1.0", |
@@ -65,2 +65,3 @@ # ssb-crut | ||
.use(require('ssb-backlinks')) | ||
.use(require('ssb-query')) | ||
// ... | ||
@@ -297,2 +298,15 @@ | ||
## crut.list(opts, cb) | ||
`opts` *Object* (optional) where: | ||
- `opts.limit` *Integer* | ||
- `opts.descending` *Boolean* (default: true) | ||
- `opts.sortBy` *String* `createTime|receiveTime` (default: 'receiveTime') | ||
- NOTE: updates do not effect this sorting | ||
- `opts.startFrom` *String* | ||
- start reading from a particular message key _onwards_ (it will exclude the provided key) | ||
- `opts.tombstoned` *Boolean* (default: false) | ||
- only show tombstoned records | ||
--- | ||
@@ -299,0 +313,0 @@ |
@@ -6,6 +6,20 @@ const test = require('tape') | ||
const server = { backlinks: true } // mock server! | ||
// mock server! | ||
const server = process.env.DB2 | ||
? { db: true } | ||
: { backlinks: true, query: true } | ||
let spec | ||
test('new Crut', t => { | ||
/* server checks */ | ||
const dudServer = process.env.DB2 | ||
? { db: undefined } | ||
: { backlinks: true, query: undefined } | ||
t.throws( | ||
() => new CRUT(dudServer, Spec()), | ||
/ssb-crut requires EITHER.*ssb.db \+ ssb-backlinks \+ ssb-query.*OR ssb-db2/, | ||
'server with missing deps throws' | ||
) | ||
/* spec checks */ | ||
@@ -12,0 +26,0 @@ t.throws( |
@@ -23,2 +23,3 @@ const Server = require('scuttle-testbot') | ||
.use(require('ssb-backlinks')) | ||
.use(require('ssb-query')) | ||
@@ -28,3 +29,2 @@ // only add ssb-tribes when testing recps, as keystore startup takes 500ms | ||
stack = stack | ||
.use(require('ssb-query')) | ||
.use(require('ssb-tribes')) | ||
@@ -31,0 +31,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110509
29
3156
332
7