'use strict'
const traverseOp = require('../operations/traverse')
const { omit } = require('lodash')
const { JoiRG, validate, checkValidation } = require('../routes/helpers')
const { DOC_ID_REGEX } = require('../constants')
const { TRAVERSE_BODY_SCHEMA } = require('../routes/schemas')
const intSchema = JoiRG.number().integer()
const docIDSchema = JoiRG.string().regex(DOC_ID_REGEX).required()
const optionsSchema = TRAVERSE_BODY_SCHEMA.concat(JoiRG.object().keys({
bfs: JoiRG.boolean(),
uniqueVertices: JoiRG.string().valid('path', 'global', 'none'),
uniqueEdges: JoiRG.string().valid('path', 'none'),
returnVertices: JoiRG.boolean(),
returnEdges: JoiRG.boolean(),
returnPaths: JoiRG.boolean()
}))
const providerSchemas = [
JoiRG.number(), docIDSchema, intSchema.min(0), intSchema.min(0), optionsSchema
]
function traverse (req) {
const options = omit(req.queryParams, 'timestamp', 'svid', 'minDepth', 'maxDepth')
const { edges: edgeCollections, vFilter, eFilter, pFilter } = req.body
const { timestamp, svid, minDepth, maxDepth } = req.queryParams
return traverseOp(timestamp, svid, minDepth, maxDepth, edgeCollections,
Object.assign({ vFilter, eFilter, pFilter }, options))
}
traverseProvider
Returns a traversal over past states for nodes matching the given filters.
Args:
timestamp
- The unix timestamp (sec) for which to traverse node states. Precision: 0.1μs. Example: timestamp=1581583228.2800217. Default: Current Time.svid
- The id of the starting vertex from which to begin traversal.minDepth
- The minimum depth from which to emit vertices, edges and paths.maxDepth
- The maximum depth till which the traversal should execute.edges
- The edge collections to traverse along with their specified directions.options
- An optional object, containing any combination of the following keys:uniqueVertices
- Restrict traversal to unique vertices within the specified scope - one ofpath
,global
ornone
. Default:none
.uniqueEdges
- Restrict traversal to unique vertices within the specified scope - one ofpath
ornone
. Default:path
.bfs
- Determines whether to run a breadth-first traversal. Default:true
ifuniqueVertices
isglobal
,false
otherwise. It is also internally forced totrue
whenuniqueVertices
isglobal
.vFilter
- The filter expression to apply on the traversed vertices.eFilter
- The filter expression to apply on the traversed edges.pFilter
- The filter expression to apply on the traversed paths.returnVertices
- Whether to return the vertices visited during the traversal (at depth >=minDepth
). Visit order is maintained. Defaulttrue
.returnEdges
- Whether to return the edges visited during the traversal (at depth >=minDepth
). Visit order is maintained. Defaulttrue
.returnPaths
- Whether to return the paths traversed. Traverse order is maintained. Defaulttrue
.Return:
The contents of the result returned by the method is identical to the contents of the response body of the corresponding HTTP API, invoked with identical input, except when the method throws an error. In the latter case, the error message would be identical to the error response of the HTTP call.
Errors:
Any error that occurs while executing the method is thrown back to the caller.
Examples: