ahau-fixtures
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -12,13 +12,42 @@ const pull = require('pull-stream') | ||
const queue = Pushable() | ||
const authors = { add: ['*'] } | ||
const createPerson = (cb) => { | ||
// start | ||
console.time('create-whakapapa-tree') | ||
// make initial profile | ||
createPerson((err, profileId) => { | ||
if (err) return cb(err) | ||
queue.push(profileId) | ||
// create a view which points to that profile (focus) | ||
ssb.whakapapa.view.create( | ||
{ | ||
name: 'bulk-' + N, | ||
focus: profileId, | ||
authors, | ||
recps: [groupId] | ||
}, | ||
(err, viewId) => { | ||
if (err) return cb(err) | ||
// build a whakapapa below that profile | ||
createTree((err) => err ? cb(err) : cb(null, viewId)) | ||
} | ||
) | ||
}) | ||
// | ||
function createPerson (cb) { | ||
ssb.profile.person.group.create( | ||
{ preferredName: String(++profileCount), authors, recps: [groupId] }, | ||
{ | ||
preferredName: String(++profileCount), | ||
authors, | ||
recps: [groupId] | ||
}, | ||
cb | ||
) | ||
} | ||
const createChild = (parentId, cb) => { | ||
function createChild (parentId, cb) { | ||
if (profileCount >= N) return cb(null) | ||
@@ -28,2 +57,3 @@ | ||
if (err) return cb(err) | ||
process.stdout.write('.') | ||
@@ -33,4 +63,10 @@ queue.push(childId) | ||
ssb.whakapapa.child.create( | ||
{ parent: parentId, child: childId }, | ||
{ relationshipType: 'birth', recps: [groupId] }, | ||
{ | ||
parent: parentId, | ||
child: childId | ||
}, | ||
{ | ||
relationshipType: 'birth', | ||
recps: [groupId] | ||
}, | ||
cb | ||
@@ -41,17 +77,3 @@ ) | ||
// start | ||
console.time('create-whakapapa-tree') | ||
createPerson((err, profileId) => { | ||
if (err) throw err | ||
queue.push(profileId) | ||
ssb.whakapapa.view.create({ name: 'bulk-' + N, focus: profileId, authors, recps: [groupId] }, (err, viewId) => { | ||
if (err) throw err | ||
createTree(viewId) | ||
}) | ||
}) | ||
function createTree (viewId) { | ||
function createTree (cb) { | ||
pull( | ||
@@ -61,17 +83,16 @@ queue, | ||
let numberOfChildren = Math.floor(Math.random() * 7) | ||
if (queue.length === 0 && numberOfChildren === 0) numberOfChildren++ | ||
if (queue.buffer.length === 0 && numberOfChildren === 0) numberOfChildren++ | ||
return new Array(numberOfChildren).fill(parentId) | ||
}), | ||
paraMap(createChild, 4), | ||
paraMap(createChild, 3), | ||
pull.take(N - 1), | ||
pull.collect((err) => { | ||
if (err) throw err | ||
if (err) return cb(err) | ||
console.log('DONE') | ||
console.timeEnd('create-whakapapa-tree') | ||
console.log('profileCount', profileCount) | ||
console.log('profiles:', profileCount) | ||
cb(null, viewId) | ||
cb(null) | ||
}) | ||
@@ -78,0 +99,0 @@ ) |
{ | ||
"name": "ahau-fixtures", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "a generator of mock ahau databases", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
4794
83