gremlin
Version:
JavaScript Gremlin Language Variant
242 lines (200 loc) • 8.28 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: structure/graph.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: structure/graph.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @author Jorge Bay Gondra
*/
'use strict';
const gt = require('../process/graph-traversal');
const { TraversalStrategies } = require('../process/traversal-strategy');
/**
* An "empty" graph object to server only as a reference.
*/
class Graph {
/**
* Returns the graph traversal source.
* @param {Function} [traversalSourceClass] The constructor to use for the {@code GraphTraversalSource} instance.
* @returns {GraphTraversalSource}
* @deprecated As of release 3.3.5, replaced by the traversal() anonymous function.
*/
traversal(traversalSourceClass) {
const traversalSourceConstructor = traversalSourceClass || gt.GraphTraversalSource;
return new traversalSourceConstructor(this, new TraversalStrategies());
}
toString() {
return 'graph[]';
}
}
class Element {
constructor(id, label) {
this.id = id;
this.label = label;
}
/**
* Compares this instance to another and determines if they can be considered as equal.
* @param {Element} other
* @returns {boolean}
*/
equals(other) {
return other instanceof Element && this.id === other.id;
}
}
class Vertex extends Element {
constructor(id, label, properties) {
super(id, label);
this.properties = properties;
}
toString() {
return `v[${this.id}]`;
}
}
class Edge extends Element {
constructor(id, outV, label, inV, properties) {
super(id, label);
this.outV = outV;
this.inV = inV;
this.properties = {};
if (properties) {
const keys = Object.keys(properties);
for (let i = 0; i < keys.length; i++) {
const k = keys[i];
this.properties[k] = properties[k].value;
}
}
}
toString() {
const outVId = this.outV ? this.outV.id : '?';
const inVId = this.inV ? this.inV.id : '?';
return `e[${this.id}][${outVId}-${this.label}->${inVId}]`;
}
}
class VertexProperty extends Element {
constructor(id, label, value, properties) {
super(id, label);
this.value = value;
this.key = this.label;
this.properties = properties;
}
toString() {
return `vp[${this.label}->${summarize(this.value)}]`;
}
}
class Property {
constructor(key, value) {
this.key = key;
this.value = value;
}
toString() {
return `p[${this.key}->${summarize(this.value)}]`;
}
equals(other) {
return other instanceof Property && this.key === other.key && this.value === other.value;
}
}
class Path {
/**
* Represents a walk through a graph as defined by a traversal.
* @param {Array} labels
* @param {Array} objects
* @constructor
*/
constructor(labels, objects) {
this.labels = labels;
this.objects = objects;
}
toString() {
return `path[${(this.objects || []).join(', ')}]`;
}
equals(other) {
if (!(other instanceof Path)) {
return false;
}
if (other === this) {
return true;
}
return areEqual(this.objects, other.objects) && areEqual(this.labels, other.labels);
}
}
function areEqual(obj1, obj2) {
if (obj1 === obj2) {
return true;
}
if (typeof obj1.equals === 'function') {
return obj1.equals(obj2);
}
if (Array.isArray(obj1) && Array.isArray(obj2)) {
if (obj1.length !== obj2.length) {
return false;
}
for (let i = 0; i < obj1.length; i++) {
if (!areEqual(obj1[i], obj2[i])) {
return false;
}
}
return true;
}
return false;
}
function summarize(value) {
if (value === null || value === undefined) {
return value;
}
const strValue = value.toString();
return strValue.length > 20 ? strValue.substr(0, 20) : strValue;
}
module.exports = {
Edge,
Graph,
Path,
Property,
Vertex,
VertexProperty,
};
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnonymousTraversalSource.html">AnonymousTraversalSource</a></li><li><a href="Authenticator.html">Authenticator</a></li><li><a href="Bytecode.html">Bytecode</a></li><li><a href="CardinalityValue.html">CardinalityValue</a></li><li><a href="Client.html">Client</a></li><li><a href="Connection.html">Connection</a></li><li><a href="DriverRemoteConnection.html">DriverRemoteConnection</a></li><li><a href="EdgeLabelVerificationStrategy.html">EdgeLabelVerificationStrategy</a></li><li><a href="Graph.html">Graph</a></li><li><a href="GraphSON2Reader.html">GraphSON2Reader</a></li><li><a href="GraphSON2Writer.html">GraphSON2Writer</a></li><li><a href="GraphSON3Reader.html">GraphSON3Reader</a></li><li><a href="GraphSON3Writer.html">GraphSON3Writer</a></li><li><a href="GraphTraversal.html">GraphTraversal</a></li><li><a href="GraphTraversalSource.html">GraphTraversalSource</a></li><li><a href="HaltedTraverserStrategy.html">HaltedTraverserStrategy</a></li><li><a href="MatchAlgorithmStrategy.html">MatchAlgorithmStrategy</a></li><li><a href="module.exports.html">exports</a></li><li><a href="P.html">P</a></li><li><a href="PartitionStrategy.html">PartitionStrategy</a></li><li><a href="Path.html">Path</a></li><li><a href="PlainTextSaslAuthenticator.html">PlainTextSaslAuthenticator</a></li><li><a href="ProductiveByStrategy.html">ProductiveByStrategy</a></li><li><a href="RemoteConnection.html">RemoteConnection</a></li><li><a href="RemoteStrategy.html">RemoteStrategy</a></li><li><a href="RemoteTraversal.html">RemoteTraversal</a></li><li><a href="ReservedKeysVerificationStrategy.html">ReservedKeysVerificationStrategy</a></li><li><a href="ResponseError.html">ResponseError</a></li><li><a href="ResultSet.html">ResultSet</a></li><li><a href="SaslAuthenticator.html">SaslAuthenticator</a></li><li><a href="SaslMechanismBase.html">SaslMechanismBase</a></li><li><a href="SaslMechanismPlain.html">SaslMechanismPlain</a></li><li><a href="SeedStrategy.html">SeedStrategy</a></li><li><a href="SubgraphStrategy.html">SubgraphStrategy</a></li><li><a href="TextP.html">TextP</a></li><li><a href="Transaction.html">Transaction</a></li><li><a href="Translator.html">Translator</a></li><li><a href="TraversalStrategies.html">TraversalStrategies</a></li><li><a href="TraversalStrategy.html">TraversalStrategy</a></li><li><a href="TypeSerializer.html">TypeSerializer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#DataType">DataType</a></li><li><a href="global.html#statics">statics</a></li><li><a href="global.html#toArrayBuffer">toArrayBuffer</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Fri Aug 08 2025 09:56:42 GMT-0700 (Pacific Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>