Skip to content

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Apr 29, 2019
1 parent 4f35119 commit 1e9d481
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seneca/graph",
"version": "0.1.0",
"version": "0.1.1",
"description": "A Seneca plugin that provides basic graph operations.",
"main": "seneca-graph.js",
"scripts": {
Expand Down
36 changes: 22 additions & 14 deletions seneca-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const Docs = require('./seneca-graph-docs.js')

module.exports = seneca_graph
module.exports.defaults = {
maxdepth: Joi.number().default(22).description("Global maximum depth of traversal.")
maxdepth: Joi.number()
.default(22)
.description('Global maximum depth of traversal.')
}
module.exports.errors = {}

Expand Down Expand Up @@ -85,7 +87,14 @@ function seneca_graph(options) {
const maxdepth = msg.depth || 1

// NOTE: start with a virtual node to ensure traversal can descend from-wise
const root = await intern.traverse(this, { t: msg.from }, spec, msg, maxdepth, 0)
const root = await intern.traverse(
this,
{ t: msg.from },
spec,
msg,
maxdepth,
0
)

return {
from: msg.from,
Expand All @@ -101,27 +110,26 @@ const intern = (seneca_graph.intern = {
traverse: async function(seneca, root, spec, msg, maxdepth, depth) {
depth++
var list = await seneca
.entity('graph/'+spec.graph.name)
// NOTE: the next level is "from" the "to" of parent level
.list$({ f: root.t, r: spec.rel.name })
.entity('graph/' + spec.graph.name)

// NOTE: the next level is "from" the "to" of parent level
.list$({ f: root.t, r: spec.rel.name })

root.c = list.map(x => x.data$(false))
if (msg.entity) {
await intern.load_ents(seneca, spec.graph, root.c, msg.entity)
}

if (msg.entity) {
await intern.load_ents(seneca, spec.graph, root.c, msg.entity)
}

if (depth < maxdepth && depth < intern.MAXDEPTH) {
for (var i = 0; i < root.c.length; i++) {
await intern.traverse(seneca, root.c[i], spec, msg, maxdepth, depth)
}
}

return root
},


load_ents: async function(seneca, graph, list, side) {
if ('from' === side || 'both' === side) {
await load_ents_side('f')
Expand Down

0 comments on commit 1e9d481

Please sign in to comment.