UNPKG

js-node-arango

Version:
59 lines 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArangoEdgeQueryBuilder = void 0; const arango_query_options_interface_1 = require("../types/arango-query-options.interface"); const base_query_builder_1 = require("./base-query-builder"); class ArangoEdgeQueryBuilder extends base_query_builder_1.ArangoBaseQueryBuilder { constructor(options) { var _a, _b; var _c, _d; super(options); this.options = options; this.doc = 'vertex'; this.returnClause = 'vertex'; this.edges = ''; this.rootDoc = ''; this.startingVertexId = ''; (_a = (_c = this.options).depth) !== null && _a !== void 0 ? _a : (_c.depth = 1); (_b = (_d = this.options).direction) !== null && _b !== void 0 ? _b : (_d.direction = arango_query_options_interface_1.Direction.Any); } setRootDocSelector(doc) { this.checkSafe(doc); this.rootDoc = doc; return this; } buildSelector() { this.buildEdges(); this.buildStartingVertexId(); const depthKeyName = `depth_${this.getNextGlobalTick()}`; this.selector = `FOR ${this.doc} IN 1..@${depthKeyName} ${this.options.direction} ${this.startingVertexId} ${this.edges} `; this.bindVars[depthKeyName] = this.options.depth; } buildEdges() { const edgeCollections = Array.isArray(this.options.edgeCollections) ? this.options.edgeCollections : [this.options.edgeCollections]; this.edges = this.handleCommaSeparated(edgeCollections, 'edge'); } buildStartingVertexId() { if (this.options.startingVertexId) { if (!/^[A-Za-z][A-Za-z0-9\-_]*\/[A-Za-z0-9\-_]+$/.test(this.options.startingVertexId)) { throw new Error('startingVertexId must be an ArangoDB document ID. For example: manifest/2df48bfb-48ab-4a95-84cc-0802c7f842b9'); } const id = `starting_vertex_${this.getNextGlobalTick()}`; this.startingVertexId = `@${id}`; this.bindVars[id] = this.options.startingVertexId; return; } if (!this.rootDoc) { const parent = this.getTopmostParentQuery(); if (parent === this) { throw new Error('You must provide startingVertexId in options'); } this.rootDoc = parent.getDocSelector(); } this.startingVertexId = `${this.rootDoc}._id`; } } exports.ArangoEdgeQueryBuilder = ArangoEdgeQueryBuilder; //# sourceMappingURL=edge-query-builder.js.map