Comparing version 4.1.0 to 4.2.0
@@ -223,2 +223,6 @@ const Strategy = require('@tangle/strategy') | ||
opts.filter | ||
? pull.filter(opts.filter) | ||
: null, | ||
// limit | ||
@@ -225,0 +229,0 @@ opts.limit ? pull.take(opts.limit) : null, |
@@ -0,1 +1,3 @@ | ||
const CREATE_TIME = 'createTime' | ||
module.exports = function CreateStream (ssb, spec) { | ||
@@ -14,3 +16,3 @@ if (ssb.db) { | ||
opts.descending === false ? null : descending(), | ||
opts.sortBy === 'createdTime' ? null : sortByArrival(), | ||
(opts.orderBy || opts.sortBy) === CREATE_TIME ? null : sortByArrival(), | ||
toPullStream() | ||
@@ -34,3 +36,3 @@ ) | ||
}] | ||
if (opts.sortBy === 'createdTime') { | ||
if ((opts.orderBy || opts.sortBy) === CREATE_TIME) { | ||
query[0].$filter.value.timestamp = { $gt: 0 } | ||
@@ -37,0 +39,0 @@ // this is a common ssb-query hack to stimulate the tya index to be used |
{ | ||
"name": "ssb-crut", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "easy CRUT methods for secure scuttlebutt", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -265,3 +265,3 @@ # ssb-crut | ||
- `err.message` - describes in human sentence the fields which has conflicts | ||
- `err.fields` - an Array of fields which had conflicts | ||
- `err.conflictFields` - an Array of fields which had conflicts | ||
@@ -301,11 +301,18 @@ - by default, updates are accepted from everyone. To change this, specifiy behaviour in `isValidUpdate` e.g. | ||
List all records (or some subset) of this crut type from your database. | ||
`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.limit` *Integer* - how many records you would like (after all filters have been applied) | ||
- `opts.filter` *Function* - apply a filter to records being returned (is given a full `record`) | ||
- `opts.orderBy` *String* | ||
- define what order to pull the records in by, looks at the times recorded on the **initial message** of the record. | ||
- options: `receiveTime|createTime` | ||
- default: `receiveTime` | ||
- `opts.descending` *Boolean* | ||
- sets whether the receiveTime/createTime/updateTime is _descending_ throughour the results | ||
- default: true | ||
- `opts.startFrom` *String* | ||
- start reading from a particular message key _onwards_ (it will exclude the provided key) | ||
- start reading from a particular message key _onwards_ (it will exclude the provided key) | ||
- `opts.tombstoned` *Boolean* (default: false) | ||
- only show tombstoned records | ||
- only show tombstoned records | ||
@@ -312,0 +319,0 @@ --- |
@@ -64,3 +64,3 @@ const test = require('tape') | ||
// sortBy | ||
// orderBy | ||
await replicate({ from: friend, to: me }) | ||
@@ -72,12 +72,22 @@ | ||
[0, 3, 2.0, 1], | ||
'opts.sortBy = receivedTime (after replicate))' | ||
'opts.orderBy = receivedTime (after replicate))' | ||
) | ||
list = await crut.list({ sortBy: 'createdTime' }) | ||
list = await crut.list({ orderBy: 'createTime' }) | ||
t.deepEqual( | ||
list.map(record => record.name), | ||
[3, 2.0, 1, 0], | ||
'opts.sortBy = createdTime (after replicate))' | ||
'opts.orderBy = createdTime (after replicate))' | ||
) | ||
/* opts.filter */ | ||
list = await crut.list({ | ||
filter: record => Math.floor(record.name % 2 === 0) | ||
}) | ||
t.deepEqual( | ||
list.map(record => record.name), | ||
[0, 2.0], // NOTE 'receivedTime' is the default orderBy | ||
'opts.filter' | ||
) | ||
// tombstone | ||
@@ -88,3 +98,3 @@ await crut.tombstone(recordId, {}) | ||
list.map(record => record.name), | ||
[0, 3, 1], // NOTE 'receivedTime' is the default sortBy | ||
[0, 3, 1], // NOTE 'receivedTime' is the default orderBy | ||
'tombstone ignored' | ||
@@ -91,0 +101,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
111376
3169
339