本文整理汇总了TypeScript中arangojs.Graph.traversal方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Graph.traversal方法的具体用法?TypeScript Graph.traversal怎么用?TypeScript Graph.traversal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arangojs.Graph
的用法示例。
在下文中一共展示了Graph.traversal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: traversal
/**
* collection traversal - Performs a traversal starting from the given
* startVertex and following edges contained in this edge collection.
*
* @param {String} collectionName collection name
* @param {String | String[]} startVertex Start vertex or vertices.
* This can be either the _id of a document in the database,
* the _key of an edge in the collection, or a document
* (i.e. an object with an _id or _key property).
* @param {any} opts opts.direction opts.filter, opts.visitor,
* opts.init, opts.expander, opts.sort
* @return {[Object]} edge traversal path
*/
async traversal(startVertex: string | string[], opts: any, collectionName?: string,
edgeName?: string, data_flag?: boolean, path_flag?: boolean,
aql?: boolean): Promise<Object> {
let collection;
let traversedData;
if (_.isNil(startVertex)) {
throw new Error('missing start vertex name');
}
if (opts.lowest_common_ancestor) {
return this.findTreesCommonAncestor(startVertex as string[],
collectionName, edgeName);
}
let response: any = {
vertex_fields: [],
data: {},
paths: {}
};
if (aql && aql == true) {
// get all the first level childrens for the start vertex
let result = await this.getAllChildrenNodes(startVertex as string, edgeName);
let finalResponse = [];
for (let item of result._result) {
finalResponse.push(_.omit(item, ['_key', '_id', '_rev']));
}
response.data.value = Buffer.from(JSON.stringify(finalResponse));
return response;
}
const vertex = startVertex as string;
if (_.isArray(vertex)) {
throw new Error('Invalid number of starting vertices for traversal: ' + vertex.length);
}
for (let key in opts) {
if (_.isEmpty(opts[key])) {
delete opts[key];
}
}
if (opts && opts.filter) {
opts.filter = this.traversalFilter(opts.filter);
} else if (opts && opts.expander) {
opts.expander = this.traversalExpander(opts.expander);
}
if (!opts) {
// make outbound traversal by default if not provided
opts = {};
opts.direction = 'outbound';
}
try {
if (collectionName) {
collection = this.graph.edgeCollection(collectionName);
traversedData = await collection.traversal(vertex, opts);
} else {
traversedData = await this.graph.traversal(vertex, opts);
}
} catch (err) {
throw { code: err.code, message: err.message };
}
let encodedData = new Set<Object>();
if (data_flag) {
if (traversedData.visited && traversedData.visited.vertices) {
traversedData.visited.vertices = this.arrUnique(traversedData.visited.vertices);
for (let vertice of traversedData.visited.vertices) {
response.vertex_fields.push(_.pick(vertice, ['_id', '_key', '_rev', 'id']));
encodedData.add(_.omit(vertice, ['_key', '_rev']));
}
response.data.value = encodeMessage(Array.from(encodedData));
}
}
if (path_flag) {
if (traversedData.visited && traversedData.visited.paths) {
traversedData.visited.paths = this.arrUnique(traversedData.visited.paths);
const encodedPaths = encodeMessage(traversedData.visited.paths);
response.paths.value = encodedPaths;
}
}
return response;
}