Comparing version 5.1.1 to 6.0.0
# Changelog | ||
## v6.0.0 | ||
Breaking: | ||
- `opts.publish` was replaced with `opts.create` as a reflection of the API now closely reflecting `ssb-db2`'s `ssb.db.create` signature. | ||
## v5.0.0 | ||
@@ -4,0 +9,0 @@ |
@@ -1,2 +0,1 @@ | ||
const createInputs = [ | ||
@@ -3,0 +2,0 @@ // ...props |
60
index.js
@@ -0,1 +1,2 @@ | ||
/* eslint-disable brace-style */ | ||
const Strategy = require('@tangle/strategy') | ||
@@ -22,2 +23,39 @@ const Overwrite = require('@tangle/overwrite') | ||
const defaultCreate = (ssb) => { | ||
// if we're db1 | ||
if (!ssb.db) return defaultCreateDB1 | ||
// if we're db2 | ||
else return defaultCreateDB2 | ||
function defaultCreateDB1 (input, cb) { | ||
if (input.allowPublic) ssb.publish(input, cb) | ||
// NOTE if we run ssb.publish({ content, allowPublic }, cb) | ||
// and dont't have ssb-recps-guard installed, we get an error, | ||
// but that's ok (intended behaviour) | ||
else ssb.publish(input.content, cb) | ||
} | ||
function defaultCreateDB2 (input, cb) { | ||
const noEncryptionRequired = ( | ||
!input.content.recps || // => intended to be public | ||
typeof input.content === 'string' // => already encrypted | ||
) | ||
if (noEncryptionRequired) ssb.db.create(input, cb) | ||
else { | ||
if (ssb.tribes && ssb.tribes.publish) { | ||
ssb.tribes.publish(input.content, cb) | ||
} | ||
else { | ||
ssb.db.create({ | ||
...input, | ||
...(ssb.box2 ? { encryptionFormat: 'box2' } : {}) | ||
}, cb) | ||
// WARNING will be encrypted but will lack group tangle data | ||
// as ssb.tribes.publish takes care of that | ||
} | ||
} | ||
} | ||
} | ||
module.exports = class CRUT { | ||
@@ -30,6 +68,10 @@ constructor (ssb, spec, opts = {}) { | ||
const { | ||
publish = ssb.publish, | ||
create = defaultCreate(ssb), | ||
feedId = ssb.id | ||
} = opts | ||
if (opts.publish) { | ||
throw Error('opts.publish no longer supported, please use opts.create') | ||
} | ||
this.spec = merge( | ||
@@ -65,3 +107,3 @@ { | ||
this.resolveTangle = ResolveTangle(ssb, this) | ||
this.handlePublish = HandlePublish({ crut: this, publish, feedId, ssb }) | ||
this.handlePublish = HandlePublish({ crut: this, create, feedId, ssb }) | ||
@@ -140,6 +182,3 @@ if (this.spec.arbitraryRoot) this.getTribe = (groupId, cb) => ssb.tribes.get(groupId, cb) | ||
conflictFields: [], | ||
// legacy | ||
states: tangle.tips | ||
.map(({ key, T }) => ({ key, ...this.strategy.mapToOutput(T) })) | ||
states: [] | ||
} | ||
@@ -165,5 +204,8 @@ | ||
bestGuessState = this.strategy.mapToOutput(T) | ||
// these are never needed if there was no conflict | ||
} // eslint-disable-line | ||
// Otherwise, we fall back to the tip with the latest entry | ||
else { | ||
result.states = tangle.tips | ||
.map(({ key, T }) => ({ key, ...this.strategy.mapToOutput(T) })) | ||
bestGuessState = { ...result.states[0] } | ||
@@ -375,5 +417,5 @@ result.conflictFields = this.strategy.isValidMerge.fields | ||
function checkOpts (opts) { | ||
if (opts.publish) { | ||
if (typeof opts.publish !== 'function') throw new Error('opts.publish must be a function') | ||
if (typeof opts.feedId !== 'string') throw new Error('opts.feedId must be provided if opts.publish is used') | ||
if (opts.create) { | ||
if (typeof opts.create !== 'function') throw new Error('opts.create must be a function') | ||
if (typeof opts.feedId !== 'string') throw new Error('opts.feedId must be provided if opts.create is used') | ||
} | ||
@@ -380,0 +422,0 @@ } |
@@ -6,3 +6,3 @@ const stringify = require('fast-json-stable-stringify') | ||
module.exports = function HandlePublish ({ crut, publish, feedId, ssb }) { | ||
module.exports = function HandlePublish ({ crut, create, feedId, ssb }) { | ||
const { spec, isRoot, isUpdate } = crut | ||
@@ -43,3 +43,3 @@ const msgToNode = MsgToNode(spec) | ||
publish(guard(content, allowPublic), (err, msg) => { | ||
create(guard(content, allowPublic), (err, msg) => { | ||
if (err) return cb(err) | ||
@@ -101,4 +101,4 @@ | ||
return allowPublic | ||
? { content, options: { allowPublic: true } } | ||
: content | ||
? { content, allowPublic: true } | ||
: { content } | ||
} | ||
@@ -105,0 +105,0 @@ |
{ | ||
"name": "ssb-crut", | ||
"version": "5.1.1", | ||
"version": "6.0.0", | ||
"description": "easy CRUT methods for secure scuttlebutt", | ||
@@ -11,4 +11,4 @@ "main": "index.js", | ||
"test": "npm run test:js:db1 && npm run test:js:db2 && npm run lint && npm run test:only ", | ||
"test:js:db1": "tape 'test/**/*.test.js' | tap-arc", | ||
"test:js:db2": "cross-env DB2=1 tape 'test/**/*.test.js' | tap-arc", | ||
"test:js:db1": "tape 'test/**/*.test.js' | tap-arc --bail", | ||
"test:js:db2": "cross-env DB2=1 tape 'test/**/*.test.js' | tap-arc --bail", | ||
"test:only": "if grep -r --exclude-dir=node_modules --exclude-dir=.git --color 'test\\.only' ; then exit 1; fi", | ||
@@ -34,3 +34,3 @@ "lint": "standard --fix" | ||
"@tangle/graph": "^3.2.0", | ||
"@tangle/reduce": "^5.0.4", | ||
"@tangle/reduce": "^5.0.5", | ||
"@tangle/strategy": "^4.1.2", | ||
@@ -50,12 +50,15 @@ "fast-json-stable-stringify": "^2.1.0", | ||
"cross-env": "^7.0.3", | ||
"scuttle-testbot": "^1.11.0", | ||
"scuttle-testbot": "^2.2.0", | ||
"ssb-backlinks": "^2.1.1", | ||
"ssb-db2": "^7.0.0", | ||
"ssb-box2": "^7.5.0", | ||
"ssb-classic": "^1.1.0", | ||
"ssb-db2": "^8.1.0", | ||
"ssb-query": "^2.4.5", | ||
"ssb-recps-guard": "^2.1.0", | ||
"ssb-tribes": "^3.1.3", | ||
"standard": "^17.0.0", | ||
"tap-arc": "^0.3.5", | ||
"ssb-recps-guard": "^2.3.0", | ||
"ssb-tribes": "^4.0.0", | ||
"ssb-tribes-db1": "npm:ssb-tribes@3.1.3", | ||
"standard": "^17.1.0", | ||
"tap-arc": "^1.2.2", | ||
"tape": "^4.16.2" | ||
} | ||
} |
@@ -190,4 +190,7 @@ # ssb-crut | ||
`opts` can have the following properties: | ||
- `publish(content, cb)`, a custom publish function instead of the default ssb.publish. Could be `publishAs` when using ssb-db2 to publish the content as another feedId | ||
- `feedId`, the feedId to publish as. Defaults to ssb.id. | ||
- `opts.create(input, cb)`, a custom publish function which is expected where: | ||
- `input` is `{ content, allowPublic }` | ||
- `content` is the message content | ||
- `allowPublic` will be present and `true` if `allowPublic` was passed into `create/update`. It's there to be used with `ssb-recps-guard` | ||
- `opts.feedId`, the feedId to publish as. Defaults to ssb.id. | ||
@@ -233,17 +236,19 @@ ### `crut.create(input, cb)` | ||
{ | ||
key: A, // the key of the tangle root message | ||
key: A, // the key of the tangle root message | ||
type, | ||
...staticProps, // any staticProp values | ||
...props // best guess of state (auto-merged states or if conflict the most recent state) | ||
states: [ | ||
...staticProps, // any staticProp values | ||
...props, // best guess of state (auto-merged states || most recent state) | ||
conflictFields: ['name'] // IF conflict, names trouble fields | ||
states: [ // IF conflect shows the full state of tips | ||
{ | ||
key: D, // key of tangle tip message | ||
...props // reified state of props for this tangle tip | ||
key: D, // key of tangle tip message | ||
name: 'Mix' // reified state of props for this tangle tip | ||
// ... | ||
}, | ||
{ | ||
key: B, // key of tangle tip message | ||
...props // reified state of props for this tangle tip | ||
key: B, | ||
name: 'mixmix', | ||
// ... | ||
} | ||
}, | ||
conflictFields: [] // names of trouble fields if there is a conflict | ||
} | ||
@@ -250,0 +255,0 @@ ``` |
@@ -0,1 +1,2 @@ | ||
const { promisify: p } = require('util') | ||
const test = require('tape') | ||
@@ -167,4 +168,2 @@ const pull = require('pull-stream') | ||
test('create (ssb-recps-guard)', t => { | ||
if (process.env.DB2) return t.end() | ||
let ssb = SSB({ recpsGuard: true }) | ||
@@ -177,3 +176,3 @@ const spec = Spec() | ||
err.message, | ||
/recps-guard: public messages .* not allowed$/, | ||
/(recps-guard: public messages .* not allowed|tribes.publish requires content.recps)$/, | ||
'recps guard blocks public message' | ||
@@ -253,5 +252,3 @@ ) | ||
test('create, opts = { feedId, publish }', t => { | ||
if (!process.env.DB2) return t.end() | ||
test('create, opts = { feedId, create }', t => { | ||
const otherKeys = keys.generate() | ||
@@ -263,3 +260,11 @@ | ||
feedId: otherKeys.id, | ||
publish: (content, cb) => ssb.db.publishAs(otherKeys, content, cb) | ||
create (input, cb) { | ||
process.env.DB2 | ||
? ssb.db.create({ | ||
keys: otherKeys, | ||
content: input.content, | ||
encryptionFormat: 'box2' | ||
}, cb) | ||
: ssb.publish(input.content, cb) | ||
} | ||
}) | ||
@@ -269,4 +274,5 @@ | ||
t.error(err, 'creates') | ||
ssb.get(msgKey, (_, value) => { | ||
t.equal(value.author, otherKeys.id, 'create with proper author') | ||
ssb.get(msgKey, (err, value) => { | ||
if (err) t.error(err, 'reads msg with id ' + msgKey) | ||
if (process.env.DB2) t.equal(value.author, otherKeys.id, 'create with proper author') | ||
@@ -278,1 +284,27 @@ ssb.close() | ||
}) | ||
test('create with recps but without tribes in db2', async t => { | ||
if (!process.env.DB2) { | ||
console.log('DB2 only test') | ||
t.end() | ||
return | ||
} | ||
const ssb = SSB() | ||
const spec = Spec() | ||
const crut = new CRUT(ssb, spec) | ||
const profileId = await crut.create({ | ||
parent: 'Taranga', | ||
preferredName: 'Māui', | ||
attendees: { | ||
add: [{ id: ssb.id, seq: 33 }] | ||
}, | ||
recps: [ssb.id] | ||
}) | ||
.catch(t.error) | ||
t.true(profileId, 'creates a profile') | ||
await p(ssb.close)() | ||
t.end() | ||
}) |
@@ -8,3 +8,2 @@ const { replicate } = require('scuttle-testbot') | ||
fixRecps, | ||
expectedState, | ||
setupForked: require('./setup-forked') | ||
@@ -20,11 +19,1 @@ } | ||
} | ||
// Returns the best guess state that is the first (or only) of the tangle tips without the key. | ||
function expectedState (states) { | ||
const state = { ...states[0] } | ||
delete state.key | ||
// WARNING - this is not exactly how expectedState works every time! | ||
// in some cases if the tips are auto-mergeable (no conflicts), then you get a merged state | ||
return state | ||
} |
@@ -18,2 +18,4 @@ const pull = require('pull-stream') | ||
const publish = (ssb, content, cb) => ssb.db ? ssb.db.create({ content }, cb) : ssb.publish(content, cb) | ||
module.exports = function setupForked (ssb, initial, forks, cb) { | ||
@@ -59,3 +61,3 @@ if (cb === undefined) return promisify(setupForked)(ssb, initial, forks) | ||
if (count === 0) ssb.publish(manualUpdate, cb) | ||
if (count === 0) publish(ssb, manualUpdate, cb) | ||
else otherPublish(manualUpdate, cb) | ||
@@ -81,3 +83,4 @@ count++ | ||
const other = SSB() | ||
other.publish(manualUpdate, (err, msg) => { | ||
publish(other, manualUpdate, (err, msg) => { | ||
other.close() | ||
@@ -84,0 +87,0 @@ if (err) return cb(err) |
@@ -13,5 +13,3 @@ const Stack = require('scuttle-testbot') | ||
if (process.env.DB2) { opts.db2 = true } | ||
return opts.db2 | ||
return process.env.DB2 | ||
? db2SSB(opts) | ||
@@ -29,3 +27,3 @@ : db1SSB(opts) | ||
stack = stack | ||
.use(require('ssb-tribes')) | ||
.use(require('ssb-tribes-db1')) | ||
} | ||
@@ -37,3 +35,6 @@ | ||
return stack(opts) | ||
return stack({ | ||
db1: true, | ||
...opts | ||
}) | ||
} | ||
@@ -43,7 +44,27 @@ | ||
let stack = Stack // eslint-disable-line | ||
.use(require('ssb-db2/core')) | ||
.use(require('ssb-classic')) | ||
.use(require('ssb-db2/compat/db')) | ||
.use(require('ssb-db2/compat/history-stream')) | ||
.use(require('ssb-db2/compat/feedstate')) | ||
.use(require('ssb-db2/compat/post')) | ||
.use(require('ssb-box2')) | ||
return stack(opts) | ||
if (opts.tribes || opts.recpsGuard) { | ||
stack = stack | ||
.use(require('ssb-tribes')) | ||
} | ||
if (opts.recpsGuard === true) { | ||
stack = stack.use(require('ssb-recps-guard')) | ||
} | ||
return stack({ | ||
noDefaultUse: true, | ||
...opts, | ||
box2: { | ||
legacyMode: true, | ||
...opts.box2 | ||
} | ||
}) | ||
} |
@@ -51,3 +51,3 @@ const test = require('tape') | ||
t.deepEqual(profile.states.length, 1, 'forcedUpdate merges the branched states') | ||
t.deepEqual(profile.conflictFields.length, 0, 'forcedUpdate merges the branched states') | ||
@@ -84,3 +84,3 @@ server1.close() | ||
t.true(profile.tombstone, 'isTombstoned') | ||
t.equal(profile.states.length, 1, 'forceTombstone merges the branched states') | ||
t.equal(profile.conflictFields.length, 0, 'forceTombstone merges the branched states') | ||
@@ -87,0 +87,0 @@ server1.close() |
@@ -23,3 +23,3 @@ const test = require('tape') | ||
// meanwhile I publish a bunch of records | ||
const me = SSB({ tribes: !process.env.DB2 }) | ||
const me = SSB({ tribes: true }) | ||
const crut = new CRUT(me, spec) | ||
@@ -154,13 +154,11 @@ const create = async (name, recps) => { | ||
if (!process.env.DB2) { | ||
/* opts.groupId */ | ||
const { groupId } = await promisify(me.tribes.create)({}) | ||
await create(4, [groupId]) | ||
list = await crut.list({ groupId }) | ||
t.deepEqual( | ||
list.map(record => record.name), | ||
[4], | ||
'opts.groupId' | ||
) | ||
} | ||
/* opts.groupId */ | ||
const { groupId } = await promisify(me.tribes.create)({}) | ||
await create(4, [groupId]) | ||
list = await crut.list({ groupId }) | ||
t.deepEqual( | ||
list.map(record => record.name), | ||
[4], | ||
'opts.groupId' | ||
) | ||
@@ -167,0 +165,0 @@ me.close() |
@@ -24,3 +24,3 @@ const test = require('tape') | ||
/* public root */ | ||
let root = await p(ssb.publish)({ type: 'profile' }) | ||
let root = ssb.db ? await p(ssb.db.create)({ content: { type: 'profile' } }) : await p(ssb.publish)({ type: 'profile' }) | ||
let updateId = await settings.update(root.key, { autoFollow: true }) | ||
@@ -49,7 +49,3 @@ let update = await p(ssb.get)({ id: updateId, private: true }) | ||
recps: null, | ||
states: [{ | ||
key: updateId, | ||
autoFollow: true, | ||
tombstone: null | ||
}], | ||
states: [], | ||
autoFollow: true, | ||
@@ -64,3 +60,3 @@ tombstone: null, | ||
/* private root */ | ||
root = await p(ssb.publish)({ type: 'profile', recps: [ssb.id] }) | ||
root = ssb.db ? await p(ssb.db.create)({ content: { type: 'profile', recps: [ssb.id] }, encryptionFormat: 'box2' }) : await p(ssb.publish)({ type: 'profile', recps: [ssb.id] }) | ||
updateId = await settings.update(root.key, { autoFollow: true }) | ||
@@ -92,7 +88,3 @@ update = await p(ssb.get)({ id: updateId, private: true }) | ||
recps: [ssb.id], | ||
states: [{ | ||
key: updateId, | ||
autoFollow: true, | ||
tombstone: null | ||
}], | ||
states: [], | ||
autoFollow: true, | ||
@@ -105,10 +97,2 @@ tombstone: null, | ||
// db2 doesn't support tribes (yet) | ||
if (ssb.db) { | ||
ssb.close() | ||
t.skip('db2 tribes tests') | ||
t.end() | ||
return | ||
} | ||
// HACK - we need the last posted message to the group for the | ||
@@ -150,7 +134,3 @@ // groups tangle (it's a group/add-member adding ourselves) | ||
recps: [groupId], | ||
states: [{ | ||
key: updateId, | ||
autoFollow: true, | ||
tombstone: null | ||
}], | ||
states: [], | ||
autoFollow: true, | ||
@@ -172,10 +152,2 @@ tombstone: null, | ||
// db2 doesn't support tribes (yet) | ||
if (ssb.db) { | ||
ssb.close() | ||
t.skip('db2 tribes tests') | ||
t.end() | ||
return | ||
} | ||
const spec = { | ||
@@ -182,0 +154,0 @@ type: 'settings', |
@@ -74,11 +74,6 @@ const test = require('tape') | ||
t.deepEqual( | ||
profile.states[0], | ||
{ | ||
key: profileId, // root is current tip | ||
preferredName: 'huatli', | ||
history: [ | ||
{ field: 'preferredName', author: ssb.id, value: 'huatli' } | ||
], | ||
tombstone: null | ||
}, | ||
profile.history, | ||
[ | ||
{ field: 'preferredName', author: ssb.id, value: 'huatli' } | ||
], | ||
'reading can be mutated by spec.getTransformation' | ||
@@ -160,9 +155,4 @@ ) | ||
t.deepEqual( | ||
profile.states[0], | ||
{ | ||
key: updateId, // update is current tip | ||
preferredName: 'HUATLI', | ||
legalName: null, | ||
tombstone: null | ||
}, | ||
profile.preferredName, | ||
'HUATLI', | ||
'crut.read processes messages mutated by spec.getTransformation' | ||
@@ -169,0 +159,0 @@ ) |
const test = require('tape') | ||
const { promisify } = require('util') | ||
const { promisify: p } = require('util') | ||
const { SSB, Spec, replicate, expectedState } = require('./helpers') | ||
const { SSB, Spec, replicate } = require('./helpers') | ||
const CRUT = require('../') | ||
function publish (ssb, content, cb) { | ||
ssb.db ? ssb.db.create({ content }, cb) : ssb.publish(content, cb) | ||
} | ||
function delay (fn, timeout = 100) { | ||
return (...args) => setTimeout(fn, timeout, ...args) | ||
} | ||
test('read', t => { | ||
@@ -35,3 +43,3 @@ const ssb = SSB() | ||
ssb.publish(manualUpdate, (err, update) => { | ||
publish(ssb, manualUpdate, (err, update) => { | ||
t.error(err, 'manually publishes an update') | ||
@@ -41,12 +49,3 @@ | ||
if (err) throw err | ||
const states = [{ | ||
key: update.key, | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null | ||
}] | ||
const expected = { | ||
@@ -59,4 +58,10 @@ key: profileId, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -86,11 +91,10 @@ } | ||
try { | ||
const profileId = await crut.create( | ||
{ | ||
parent: 'Taranga', | ||
preferredName: 'Māui', | ||
attendees: { | ||
add: [{ id: Māui, seq: 33 }] | ||
} | ||
const profileId = await crut.create({ | ||
parent: 'Taranga', | ||
preferredName: 'Māui', | ||
attendees: { | ||
add: [{ id: Māui, seq: 33 }] | ||
} | ||
) | ||
}) | ||
const manualUpdate = { | ||
@@ -106,3 +110,4 @@ type: spec.type, | ||
} | ||
ssb.publish(manualUpdate, async (err, update) => { | ||
publish(ssb, manualUpdate, async (err, update) => { | ||
t.error(err, 'manually publishes an update') | ||
@@ -112,12 +117,2 @@ | ||
const states = [{ | ||
key: update.key, | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null | ||
}] | ||
t.deepEqual( | ||
@@ -132,4 +127,10 @@ profile, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -148,3 +149,3 @@ }, | ||
test('read (multiple states - conflicting)', t => { | ||
test('read (multiple states - conflicting)', { objectPrintDepth: 10 }, async t => { | ||
const ssb = SSB() | ||
@@ -183,6 +184,6 @@ const spec = Spec() | ||
ssb.publish(manualUpdateA, (err, updateA) => { | ||
publish(ssb, manualUpdateA, (err, updateA) => { | ||
t.error(err, 'manually publishes an updateA') | ||
ssb.publish(manualUpdateB, (err, updateB) => { | ||
delay(publish, 100)(ssb, manualUpdateB, (err, updateB) => { | ||
t.error(err, 'manually publishes an updateB') | ||
@@ -222,4 +223,9 @@ crut.read(profileId, (err, profile) => { | ||
recps: null, | ||
preferredName: 'Māui B', // < | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null, | ||
states, | ||
...expectedState(states), | ||
conflictFields: ['preferredName'] | ||
@@ -239,3 +245,3 @@ }, | ||
test('read (multiple states - auto-mergeable)', async t => { | ||
test('read (multiple states - auto-mergeable)', { objectPrintDepth: 10 }, async t => { | ||
const ssb = SSB() | ||
@@ -253,5 +259,5 @@ const spec = Spec() | ||
const publish = promisify(ssb.publish) | ||
const publishP = p((content, cb) => publish(ssb, content, cb)) | ||
// NOTE these both branch off from the root (see tangle previous) | ||
const updateA = await publish({ | ||
await publishP({ | ||
type: spec.type, | ||
@@ -264,3 +270,3 @@ preferredName: { set: 'Māui A' }, | ||
await new Promise(resolve => setTimeout(resolve, 10)) // ensure not published at same time! | ||
const updateB = await publish({ | ||
await publishP({ | ||
type: spec.type, | ||
@@ -282,18 +288,2 @@ legalName: { set: 'Māui B' }, | ||
recps: null, | ||
states: [ | ||
{ | ||
key: updateB.key, | ||
preferredName: 'Māui', | ||
legalName: 'Māui B', | ||
attendees: { [ssb.id]: [{ start: 1, end: null }] }, | ||
tombstone: null | ||
}, | ||
{ | ||
key: updateA.key, | ||
preferredName: 'Māui A', | ||
legalName: null, | ||
attendees: { [ssb.id]: [{ start: 1, end: null }] }, | ||
tombstone: null | ||
} | ||
], | ||
preferredName: 'Māui A', | ||
@@ -303,2 +293,3 @@ legalName: 'Māui B', | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -349,3 +340,3 @@ } | ||
// Hine tries to publish an update which removes Māui and adds herself! | ||
friend.publish(manualUpdate, (err, update) => { | ||
publish(friend, manualUpdate, (err, update) => { | ||
t.error(err, 'friend manually publishes an update') | ||
@@ -359,12 +350,2 @@ | ||
const states = [{ | ||
key: profileId, | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null | ||
}] | ||
const expected = { | ||
@@ -377,4 +358,9 @@ key: profileId, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -431,3 +417,3 @@ } | ||
// NOTE for this particular spec removal is not possible | ||
friend.publish(manualUpdate, (err, update) => { | ||
publish(friend, manualUpdate, (err, update) => { | ||
t.error(err, 'friend manually publishes an update') | ||
@@ -441,13 +427,2 @@ | ||
const states = [{ | ||
key: update.key, | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
[Hine]: [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null | ||
}] | ||
const expected = { | ||
@@ -460,4 +435,10 @@ key: profileId, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
[Hine]: [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -506,3 +487,3 @@ } | ||
ssb.publish(manualUpdate, (err, update) => { | ||
publish(ssb, manualUpdate, (err, update) => { | ||
t.error(err, 'manually publishes an update') | ||
@@ -512,12 +493,3 @@ | ||
if (err) throw err | ||
const states = [{ | ||
key: update.key, | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null | ||
}] | ||
t.deepEqual( | ||
@@ -532,4 +504,10 @@ profile, | ||
recps: [ssb.id], | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -580,11 +558,3 @@ }, | ||
if (err) throw err | ||
const states = [{ | ||
key: profileId, | ||
preferredName: { author: Māui, value: 'Māui' }, | ||
legalName: 'Ben', | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null | ||
}] | ||
t.deepEqual( | ||
@@ -599,4 +569,9 @@ profile, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: { author: Māui, value: 'Māui' }, | ||
legalName: 'Ben', | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -644,3 +619,3 @@ }, | ||
} | ||
ssb.publish(content, (err, m) => { | ||
publish(ssb, content, (err, m) => { | ||
if (err) throw err | ||
@@ -657,3 +632,3 @@ | ||
} | ||
ssb.publish(badContent, (err, m) => { | ||
publish(ssb, badContent, (err, m) => { | ||
if (err) throw err | ||
@@ -703,3 +678,3 @@ | ||
t.equal(data.conflictFields.length, 0, 'no conflicts') | ||
t.equal(data.states[0].extraInfo, undefined, 'nextStepData not in states') | ||
t.equal(data.extraInfo, undefined, 'nextStepData not in states') | ||
@@ -714,3 +689,3 @@ // manual publish | ||
} | ||
ssb.publish(content, (err, m) => { | ||
publish(ssb, content, (err, m) => { | ||
if (err) throw err | ||
@@ -722,3 +697,3 @@ | ||
t.equal(data.conflictFields.length, 0, 'no conflicts') | ||
t.equal(data.states[0].extraInfo, undefined, 'nextStepData not in states') | ||
t.equal(data.extraInfo, undefined, 'nextStepData not in states') | ||
@@ -725,0 +700,0 @@ ssb.close() |
const test = require('tape') | ||
const { SSB, Spec, expectedState } = require('./helpers') | ||
const { SSB, Spec } = require('./helpers') | ||
const CRUT = require('../') | ||
@@ -35,4 +35,9 @@ | ||
const states = [{ | ||
key: updateId, | ||
const expected = { | ||
key: profileId, | ||
type: spec.type, | ||
originalAuthor: ssb.id, | ||
parent: 'Taranga', | ||
child: null, | ||
recps: null, | ||
preferredName: 'Māui', | ||
@@ -45,13 +50,4 @@ legalName: null, | ||
reason: 'woops' | ||
} | ||
}] | ||
const expected = { | ||
key: profileId, | ||
type: spec.type, | ||
originalAuthor: ssb.id, | ||
parent: 'Taranga', | ||
child: null, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
}, | ||
states: [], | ||
conflictFields: [] | ||
@@ -67,9 +63,2 @@ } | ||
if (err) throw err | ||
const states = [{ | ||
key: updateId, | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: {}, | ||
tombstone: null | ||
}] | ||
@@ -83,4 +72,7 @@ const expected = { | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: {}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -118,4 +110,9 @@ } | ||
const states = [{ | ||
key: updateId, | ||
const expected = { | ||
key: profileId, | ||
type: spec.type, | ||
originalAuthor: ssb.id, | ||
parent: 'Taranga', | ||
child: null, | ||
recps: null, | ||
preferredName: 'Māui', | ||
@@ -128,13 +125,4 @@ legalName: null, | ||
reason: 'woops' | ||
} | ||
}] | ||
const expected = { | ||
key: profileId, | ||
type: spec.type, | ||
originalAuthor: ssb.id, | ||
parent: 'Taranga', | ||
child: null, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
}, | ||
states: [], | ||
conflictFields: [] | ||
@@ -141,0 +129,0 @@ } |
@@ -5,3 +5,3 @@ const test = require('tape') | ||
const { SSB, Spec, replicate, expectedState } = require('./helpers') | ||
const { SSB, Spec, replicate } = require('./helpers') | ||
const CRUT = require('../') | ||
@@ -41,13 +41,2 @@ | ||
ssb.get(updateId, (_, value) => { | ||
const states = [{ | ||
key: updateId, | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null | ||
}] | ||
const expected = { | ||
@@ -60,4 +49,10 @@ key: profileId, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -104,12 +99,2 @@ } | ||
ssb.get(updateId, (_, value) => { | ||
const states = [{ | ||
key: updateId, | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null | ||
}] | ||
const expected = { | ||
@@ -122,4 +107,10 @@ key: profileId, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 41 }], | ||
'@Hine-nui-te-pō': [{ start: 5000, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -173,4 +164,2 @@ } | ||
test('update (ssb-recps-guard)', t => { | ||
if (process.env.DB2) return t.end() | ||
const ssb = SSB({ recpsGuard: true }) | ||
@@ -188,3 +177,3 @@ const spec = Spec() | ||
crut.update(id, { preferredName: 'M' }, (err) => { | ||
t.match(err.message, /recps-guard/, 'recps-guard blocks public updates') | ||
t.match(err.message, /recps-guard|tribes.publish requires content.recps/, 'recps-guard blocks public updates') | ||
@@ -273,13 +262,2 @@ crut.update(id, { preferredName: 'M', allowPublic: true }, (err) => { | ||
const states = [{ | ||
key: updateId, | ||
preferredName: { author: ssb2.id, value: 'Māui !!!' }, | ||
legalName: 'Ben', | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }], | ||
[ssb2.id]: [{ start: 1, end: null }] | ||
}, | ||
tombstone: null | ||
}] | ||
t.deepEqual( | ||
@@ -294,4 +272,10 @@ profile, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: { author: ssb2.id, value: 'Māui !!!' }, | ||
legalName: 'Ben', | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }], | ||
[ssb2.id]: [{ start: 1, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -375,5 +359,3 @@ }, | ||
test('update, opts = { feedId, publish }', t => { | ||
if (!process.env.DB2) return t.end() | ||
test('update, opts = { feedId, create }', t => { | ||
const otherKeys = keys.generate() | ||
@@ -385,3 +367,7 @@ | ||
feedId: otherKeys.id, | ||
publish: (content, cb) => ssb.db.publishAs(otherKeys, content, cb) | ||
create (input, cb) { | ||
process.env.DB2 | ||
? ssb.db.create({ ...input, keys: otherKeys }, cb) | ||
: ssb.publish(input.content, cb) | ||
} | ||
}) | ||
@@ -400,4 +386,5 @@ | ||
ssb.get(updateId, (_, value) => { | ||
t.equal(value.author, otherKeys.id, 'update with proper author') | ||
ssb.get(updateId, (err, value) => { | ||
if (err) t.error(err) | ||
if (process.env.DB2) t.equal(value.author, otherKeys.id, 'update with proper author') | ||
@@ -404,0 +391,0 @@ ssb.close() |
const test = require('tape') | ||
const { promisify } = require('util') | ||
const { SSB, expectedState, setupForked } = require('./helpers') | ||
const { SSB, setupForked } = require('./helpers') | ||
@@ -38,3 +38,3 @@ function ForceUpdate (crut) { | ||
test('update-force (force update a forked state)', { objectPrintDepth: 6 }, async t => { | ||
console.log('This is a DEMO') | ||
// This is a DEMO | ||
const ssb = SSB() | ||
@@ -75,17 +75,5 @@ const Māui = ssb.id | ||
const updateId = await crut.forceUpdate(rootId, {}) | ||
await crut.forceUpdate(rootId, {}) | ||
const profile = await crut.read(rootId) | ||
const states = [ | ||
{ | ||
key: updateId, | ||
preferredName: 'Māui B', // ends up with newest state for preferredName | ||
legalName: 'Māui Au', | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null | ||
} | ||
] | ||
const expected = { | ||
@@ -98,4 +86,9 @@ key: rootId, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui B', // ends up with newest state for preferredName | ||
legalName: 'Māui Au', | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -102,0 +95,0 @@ } |
const test = require('tape') | ||
const { SSB, expectedState, setupForked } = require('./helpers') | ||
const { SSB, setupForked } = require('./helpers') | ||
@@ -31,14 +31,2 @@ test('update-merge (update a forked state)', t => { | ||
const states = [ | ||
{ | ||
key: updateId, | ||
preferredName: 'Māui C', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null | ||
} | ||
] | ||
const expected = { | ||
@@ -51,4 +39,9 @@ key: rootId, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui C', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -127,4 +120,9 @@ } | ||
recps: null, | ||
preferredName: 'Māui B', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null, | ||
states, | ||
...expectedState(states), | ||
conflictFields: ['preferredName'] | ||
@@ -203,4 +201,9 @@ } | ||
recps: null, | ||
preferredName: 'Māui B', | ||
legalName: 'Legal B', | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null, | ||
states, | ||
...expectedState(states), | ||
conflictFields: ['preferredName', 'legalName'] | ||
@@ -257,3 +260,6 @@ } | ||
*/ | ||
ssb.publish(manualUpdateD, (err, updateD) => { | ||
const publish = (ssb, content, cb) => ssb.db ? ssb.db.create({ content }, cb) : ssb.publish(content, cb) | ||
publish(ssb, manualUpdateD, (err, updateD) => { | ||
t.error(err, 'manually publish a second forked update') | ||
@@ -268,14 +274,2 @@ | ||
const states = [ | ||
{ | ||
key: updateId, | ||
preferredName: 'Māui E', | ||
legalName: 'Māui D', | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null | ||
} | ||
] | ||
const expected = { | ||
@@ -288,4 +282,9 @@ key: rootId, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui E', | ||
legalName: 'Māui D', | ||
attendees: { | ||
[Māui]: [{ start: 33, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -355,13 +354,2 @@ } | ||
const states = [ | ||
{ | ||
key: updateId, | ||
preferredName: 'Māui C', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 39 }, { start: 200, end: null }] | ||
}, | ||
tombstone: null | ||
} | ||
] | ||
const expected = { | ||
@@ -374,4 +362,9 @@ key: rootId, | ||
recps: null, | ||
states, | ||
...expectedState(states), | ||
preferredName: 'Māui C', | ||
legalName: null, | ||
attendees: { | ||
[Māui]: [{ start: 33, end: 39 }, { start: 200, end: null }] | ||
}, | ||
tombstone: null, | ||
states: [], | ||
conflictFields: [] | ||
@@ -378,0 +371,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
138185
377
9
17
3723
Updated@tangle/reduce@^5.0.5