http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ac983179/gremlin-javascript/src/main/javascript/gremlin-javascript/process/graph-traversal.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/process/graph-traversal.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/process/graph-traversal.js new file mode 100644 index 0000000..d9803ba --- /dev/null +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/process/graph-traversal.js @@ -0,0 +1,2025 @@ +/* + * 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 + */ +(function defineGraphTraversalModule() { + "use strict"; + + var t = loadModule.call(this, './traversal.js'); + var remote = loadModule.call(this, '../driver/remote-connection.js'); + var Bytecode = t.Bytecode; + var inherits = t.inherits; + var parseArgs = t.parseArgs; + + /** + * + * @param {Graph} graph + * @param {TraversalStrategies} traversalStrategies + * @param {Bytecode} [bytecode] + * @constructor + */ + function GraphTraversalSource(graph, traversalStrategies, bytecode) { + this._graph = graph; + this._traversalStrategies = traversalStrategies; + this._bytecode = bytecode || new Bytecode(); + } + + /** + * @param remoteConnection + * @returns {GraphTraversal} + */ + GraphTraversalSource.prototype.withRemote = function (remoteConnection) { + var traversalStrategy = new t.TraversalStrategies(this._traversalStrategies); + traversalStrategy.addStrategy(new remote.RemoteStrategy(remoteConnection)); + return new GraphTraversal(this._graph, traversalStrategy, new Bytecode(this._bytecode)); + }; + + /** + * Returns the string representation of the GraphTraversalSource. + * @returns {string} + */ + GraphTraversalSource.prototype.toString = function () { + return 'graphtraversalsource[' + this._graph.toString() + ']'; + }; + + /** + * withBulk GraphTraversalSource method. + * @param {...Object} args + * @returns {GraphTraversalSource} + */ + GraphTraversalSource.prototype.withBulk = function (args) { + var b = new Bytecode(this._bytecode).addSource('withBulk', parseArgs.apply(null, arguments)); + return new GraphTraversalSource(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * withComputer GraphTraversalSource method. + * @param {...Object} args + * @returns {GraphTraversalSource} + */ + GraphTraversalSource.prototype.withComputer = function (args) { + var b = new Bytecode(this._bytecode).addSource('withComputer', parseArgs.apply(null, arguments)); + return new GraphTraversalSource(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * withPath GraphTraversalSource method. + * @param {...Object} args + * @returns {GraphTraversalSource} + */ + GraphTraversalSource.prototype.withPath = function (args) { + var b = new Bytecode(this._bytecode).addSource('withPath', parseArgs.apply(null, arguments)); + return new GraphTraversalSource(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * withSack GraphTraversalSource method. + * @param {...Object} args + * @returns {GraphTraversalSource} + */ + GraphTraversalSource.prototype.withSack = function (args) { + var b = new Bytecode(this._bytecode).addSource('withSack', parseArgs.apply(null, arguments)); + return new GraphTraversalSource(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * withSideEffect GraphTraversalSource method. + * @param {...Object} args + * @returns {GraphTraversalSource} + */ + GraphTraversalSource.prototype.withSideEffect = function (args) { + var b = new Bytecode(this._bytecode).addSource('withSideEffect', parseArgs.apply(null, arguments)); + return new GraphTraversalSource(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * withStrategies GraphTraversalSource method. + * @param {...Object} args + * @returns {GraphTraversalSource} + */ + GraphTraversalSource.prototype.withStrategies = function (args) { + var b = new Bytecode(this._bytecode).addSource('withStrategies', parseArgs.apply(null, arguments)); + return new GraphTraversalSource(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * withoutStrategies GraphTraversalSource method. + * @param {...Object} args + * @returns {GraphTraversalSource} + */ + GraphTraversalSource.prototype.withoutStrategies = function (args) { + var b = new Bytecode(this._bytecode).addSource('withoutStrategies', parseArgs.apply(null, arguments)); + return new GraphTraversalSource(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * E GraphTraversalSource step method. + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversalSource.prototype.E = function (args) { + var b = new Bytecode(this._bytecode).addStep('E', parseArgs.apply(null, arguments)); + return new GraphTraversal(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * V GraphTraversalSource step method. + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversalSource.prototype.V = function (args) { + var b = new Bytecode(this._bytecode).addStep('V', parseArgs.apply(null, arguments)); + return new GraphTraversal(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * addV GraphTraversalSource step method. + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversalSource.prototype.addV = function (args) { + var b = new Bytecode(this._bytecode).addStep('addV', parseArgs.apply(null, arguments)); + return new GraphTraversal(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * inject GraphTraversalSource step method. + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversalSource.prototype.inject = function (args) { + var b = new Bytecode(this._bytecode).addStep('inject', parseArgs.apply(null, arguments)); + return new GraphTraversal(this._graph, new t.TraversalStrategies(this._traversalStrategies), b); + }; + + /** + * Represents a graph traversal. + * @constructor + */ + function GraphTraversal(graph, traversalStrategies, bytecode) { + t.Traversal.call(this, graph, traversalStrategies, bytecode); + } + + inherits(GraphTraversal, t.Traversal); + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.V = function (args) { + this._bytecode.addStep('V', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.addE = function (args) { + this._bytecode.addStep('addE', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.addInE = function (args) { + this._bytecode.addStep('addInE', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.addOutE = function (args) { + this._bytecode.addStep('addOutE', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.addV = function (args) { + this._bytecode.addStep('addV', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.aggregate = function (args) { + this._bytecode.addStep('aggregate', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.and = function (args) { + this._bytecode.addStep('and', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.as = function (args) { + this._bytecode.addStep('as', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.barrier = function (args) { + this._bytecode.addStep('barrier', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.both = function (args) { + this._bytecode.addStep('both', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.bothE = function (args) { + this._bytecode.addStep('bothE', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.bothV = function (args) { + this._bytecode.addStep('bothV', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.branch = function (args) { + this._bytecode.addStep('branch', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.by = function (args) { + this._bytecode.addStep('by', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.cap = function (args) { + this._bytecode.addStep('cap', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.choose = function (args) { + this._bytecode.addStep('choose', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.coalesce = function (args) { + this._bytecode.addStep('coalesce', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.coin = function (args) { + this._bytecode.addStep('coin', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.constant = function (args) { + this._bytecode.addStep('constant', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.count = function (args) { + this._bytecode.addStep('count', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.cyclicPath = function (args) { + this._bytecode.addStep('cyclicPath', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.dedup = function (args) { + this._bytecode.addStep('dedup', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.drop = function (args) { + this._bytecode.addStep('drop', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.emit = function (args) { + this._bytecode.addStep('emit', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.filter = function (args) { + this._bytecode.addStep('filter', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.flatMap = function (args) { + this._bytecode.addStep('flatMap', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.fold = function (args) { + this._bytecode.addStep('fold', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.from_ = function (args) { + this._bytecode.addStep('from', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.group = function (args) { + this._bytecode.addStep('group', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.groupCount = function (args) { + this._bytecode.addStep('groupCount', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.groupV3d0 = function (args) { + this._bytecode.addStep('groupV3d0', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.has = function (args) { + this._bytecode.addStep('has', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.hasId = function (args) { + this._bytecode.addStep('hasId', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.hasKey = function (args) { + this._bytecode.addStep('hasKey', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.hasLabel = function (args) { + this._bytecode.addStep('hasLabel', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.hasNot = function (args) { + this._bytecode.addStep('hasNot', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.hasValue = function (args) { + this._bytecode.addStep('hasValue', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.id = function (args) { + this._bytecode.addStep('id', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.identity = function (args) { + this._bytecode.addStep('identity', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.inE = function (args) { + this._bytecode.addStep('inE', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.inV = function (args) { + this._bytecode.addStep('inV', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.in_ = function (args) { + this._bytecode.addStep('in', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.inject = function (args) { + this._bytecode.addStep('inject', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.is = function (args) { + this._bytecode.addStep('is', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.key = function (args) { + this._bytecode.addStep('key', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.label = function (args) { + this._bytecode.addStep('label', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.limit = function (args) { + this._bytecode.addStep('limit', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.local = function (args) { + this._bytecode.addStep('local', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.loops = function (args) { + this._bytecode.addStep('loops', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.map = function (args) { + this._bytecode.addStep('map', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.mapKeys = function (args) { + this._bytecode.addStep('mapKeys', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.mapValues = function (args) { + this._bytecode.addStep('mapValues', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.match = function (args) { + this._bytecode.addStep('match', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.max = function (args) { + this._bytecode.addStep('max', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.mean = function (args) { + this._bytecode.addStep('mean', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.min = function (args) { + this._bytecode.addStep('min', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.not = function (args) { + this._bytecode.addStep('not', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.option = function (args) { + this._bytecode.addStep('option', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.optional = function (args) { + this._bytecode.addStep('optional', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.or = function (args) { + this._bytecode.addStep('or', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.order = function (args) { + this._bytecode.addStep('order', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.otherV = function (args) { + this._bytecode.addStep('otherV', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.out = function (args) { + this._bytecode.addStep('out', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.outE = function (args) { + this._bytecode.addStep('outE', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.outV = function (args) { + this._bytecode.addStep('outV', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.pageRank = function (args) { + this._bytecode.addStep('pageRank', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.path = function (args) { + this._bytecode.addStep('path', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.peerPressure = function (args) { + this._bytecode.addStep('peerPressure', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.profile = function (args) { + this._bytecode.addStep('profile', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.program = function (args) { + this._bytecode.addStep('program', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.project = function (args) { + this._bytecode.addStep('project', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.properties = function (args) { + this._bytecode.addStep('properties', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.property = function (args) { + this._bytecode.addStep('property', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.propertyMap = function (args) { + this._bytecode.addStep('propertyMap', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.range = function (args) { + this._bytecode.addStep('range', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.repeat = function (args) { + this._bytecode.addStep('repeat', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.sack = function (args) { + this._bytecode.addStep('sack', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.sample = function (args) { + this._bytecode.addStep('sample', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.select = function (args) { + this._bytecode.addStep('select', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.sideEffect = function (args) { + this._bytecode.addStep('sideEffect', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.simplePath = function (args) { + this._bytecode.addStep('simplePath', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.store = function (args) { + this._bytecode.addStep('store', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.subgraph = function (args) { + this._bytecode.addStep('subgraph', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.sum = function (args) { + this._bytecode.addStep('sum', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.tail = function (args) { + this._bytecode.addStep('tail', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.timeLimit = function (args) { + this._bytecode.addStep('timeLimit', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.times = function (args) { + this._bytecode.addStep('times', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.to = function (args) { + this._bytecode.addStep('to', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.toE = function (args) { + this._bytecode.addStep('toE', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.toV = function (args) { + this._bytecode.addStep('toV', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.tree = function (args) { + this._bytecode.addStep('tree', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.unfold = function (args) { + this._bytecode.addStep('unfold', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.union = function (args) { + this._bytecode.addStep('union', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.until = function (args) { + this._bytecode.addStep('until', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.value = function (args) { + this._bytecode.addStep('value', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.valueMap = function (args) { + this._bytecode.addStep('valueMap', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.values = function (args) { + this._bytecode.addStep('values', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * @param {...Object} args + * @returns {GraphTraversal} + */ + GraphTraversal.prototype.where = function (args) { + this._bytecode.addStep('where', parseArgs.apply(null, arguments)); + return this; + }; + + /** + * Contains the static method definitions + * @type {Object} + */ + var statics = {}; + + /** + * V() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.V = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.V.apply(g, arguments); + }; + + /** + * __() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.__ = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.__.apply(g, arguments); + }; + + /** + * addE() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.addE = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.addE.apply(g, arguments); + }; + + /** + * addInE() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.addInE = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.addInE.apply(g, arguments); + }; + + /** + * addOutE() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.addOutE = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.addOutE.apply(g, arguments); + }; + + /** + * addV() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.addV = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.addV.apply(g, arguments); + }; + + /** + * aggregate() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.aggregate = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.aggregate.apply(g, arguments); + }; + + /** + * and() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.and = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.and.apply(g, arguments); + }; + + /** + * as() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.as = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.as.apply(g, arguments); + }; + + /** + * barrier() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.barrier = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.barrier.apply(g, arguments); + }; + + /** + * both() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.both = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.both.apply(g, arguments); + }; + + /** + * bothE() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.bothE = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.bothE.apply(g, arguments); + }; + + /** + * bothV() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.bothV = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.bothV.apply(g, arguments); + }; + + /** + * branch() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.branch = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.branch.apply(g, arguments); + }; + + /** + * cap() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.cap = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.cap.apply(g, arguments); + }; + + /** + * choose() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.choose = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.choose.apply(g, arguments); + }; + + /** + * coalesce() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.coalesce = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.coalesce.apply(g, arguments); + }; + + /** + * coin() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.coin = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.coin.apply(g, arguments); + }; + + /** + * constant() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.constant = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.constant.apply(g, arguments); + }; + + /** + * count() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.count = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.count.apply(g, arguments); + }; + + /** + * cyclicPath() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.cyclicPath = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.cyclicPath.apply(g, arguments); + }; + + /** + * dedup() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.dedup = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.dedup.apply(g, arguments); + }; + + /** + * drop() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.drop = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.drop.apply(g, arguments); + }; + + /** + * emit() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.emit = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.emit.apply(g, arguments); + }; + + /** + * filter() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.filter = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.filter.apply(g, arguments); + }; + + /** + * flatMap() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.flatMap = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.flatMap.apply(g, arguments); + }; + + /** + * fold() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.fold = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.fold.apply(g, arguments); + }; + + /** + * group() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.group = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.group.apply(g, arguments); + }; + + /** + * groupCount() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.groupCount = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.groupCount.apply(g, arguments); + }; + + /** + * groupV3d0() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.groupV3d0 = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.groupV3d0.apply(g, arguments); + }; + + /** + * has() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.has = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.has.apply(g, arguments); + }; + + /** + * hasId() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.hasId = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.hasId.apply(g, arguments); + }; + + /** + * hasKey() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.hasKey = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.hasKey.apply(g, arguments); + }; + + /** + * hasLabel() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.hasLabel = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.hasLabel.apply(g, arguments); + }; + + /** + * hasNot() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.hasNot = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.hasNot.apply(g, arguments); + }; + + /** + * hasValue() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.hasValue = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.hasValue.apply(g, arguments); + }; + + /** + * id() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.id = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.id.apply(g, arguments); + }; + + /** + * identity() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.identity = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.identity.apply(g, arguments); + }; + + /** + * inE() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.inE = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.inE.apply(g, arguments); + }; + + /** + * inV() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.inV = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.inV.apply(g, arguments); + }; + + /** + * in_() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.in_ = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.in_.apply(g, arguments); + }; + + /** + * inject() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.inject = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.inject.apply(g, arguments); + }; + + /** + * is() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.is = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.is.apply(g, arguments); + }; + + /** + * key() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.key = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.key.apply(g, arguments); + }; + + /** + * label() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.label = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.label.apply(g, arguments); + }; + + /** + * limit() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.limit = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.limit.apply(g, arguments); + }; + + /** + * local() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.local = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.local.apply(g, arguments); + }; + + /** + * loops() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.loops = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.loops.apply(g, arguments); + }; + + /** + * map() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.map = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.map.apply(g, arguments); + }; + + /** + * mapKeys() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.mapKeys = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.mapKeys.apply(g, arguments); + }; + + /** + * mapValues() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.mapValues = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.mapValues.apply(g, arguments); + }; + + /** + * match() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.match = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.match.apply(g, arguments); + }; + + /** + * max() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.max = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.max.apply(g, arguments); + }; + + /** + * mean() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.mean = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.mean.apply(g, arguments); + }; + + /** + * min() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.min = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.min.apply(g, arguments); + }; + + /** + * not() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.not = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.not.apply(g, arguments); + }; + + /** + * optional() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.optional = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.optional.apply(g, arguments); + }; + + /** + * or() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.or = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.or.apply(g, arguments); + }; + + /** + * order() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.order = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.order.apply(g, arguments); + }; + + /** + * otherV() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.otherV = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.otherV.apply(g, arguments); + }; + + /** + * out() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.out = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.out.apply(g, arguments); + }; + + /** + * outE() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.outE = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.outE.apply(g, arguments); + }; + + /** + * outV() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.outV = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.outV.apply(g, arguments); + }; + + /** + * path() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.path = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.path.apply(g, arguments); + }; + + /** + * project() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.project = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.project.apply(g, arguments); + }; + + /** + * properties() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.properties = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.properties.apply(g, arguments); + }; + + /** + * property() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.property = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.property.apply(g, arguments); + }; + + /** + * propertyMap() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.propertyMap = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.propertyMap.apply(g, arguments); + }; + + /** + * range() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.range = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.range.apply(g, arguments); + }; + + /** + * repeat() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.repeat = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.repeat.apply(g, arguments); + }; + + /** + * sack() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.sack = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.sack.apply(g, arguments); + }; + + /** + * sample() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.sample = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.sample.apply(g, arguments); + }; + + /** + * select() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.select = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.select.apply(g, arguments); + }; + + /** + * sideEffect() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.sideEffect = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.sideEffect.apply(g, arguments); + }; + + /** + * simplePath() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.simplePath = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.simplePath.apply(g, arguments); + }; + + /** + * start() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.start = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.start.apply(g, arguments); + }; + + /** + * store() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.store = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.store.apply(g, arguments); + }; + + /** + * subgraph() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.subgraph = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.subgraph.apply(g, arguments); + }; + + /** + * sum() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.sum = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.sum.apply(g, arguments); + }; + + /** + * tail() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.tail = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.tail.apply(g, arguments); + }; + + /** + * timeLimit() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.timeLimit = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.timeLimit.apply(g, arguments); + }; + + /** + * times() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.times = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.times.apply(g, arguments); + }; + + /** + * to() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.to = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.to.apply(g, arguments); + }; + + /** + * toE() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.toE = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.toE.apply(g, arguments); + }; + + /** + * toV() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.toV = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.toV.apply(g, arguments); + }; + + /** + * tree() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.tree = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.tree.apply(g, arguments); + }; + + /** + * unfold() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.unfold = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.unfold.apply(g, arguments); + }; + + /** + * union() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.union = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.union.apply(g, arguments); + }; + + /** + * until() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.until = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.until.apply(g, arguments); + }; + + /** + * value() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.value = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.value.apply(g, arguments); + }; + + /** + * valueMap() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.valueMap = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.valueMap.apply(g, arguments); + }; + + /** + * values() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.values = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.values.apply(g, arguments); + }; + + /** + * where() static method + * @param {...Object} args + * @returns {GraphTraversal} + */ + statics.where = function (args) { + var g = new GraphTraversal(null, null, new Bytecode()); + return g.where.apply(g, arguments); + }; + + function loadModule(moduleName) { + if (typeof require !== 'undefined') { + return require(moduleName); + } + if (typeof load !== 'undefined') { + var path = new java.io.File(__DIR__ + moduleName).getCanonicalPath(); + this.__dependencies = this.__dependencies || {}; + return this.__dependencies[path] = (this.__dependencies[path] || load(path)); + } + throw new Error('No module loader was found'); + } + + var toExport = { + GraphTraversal: GraphTraversal, + GraphTraversalSource: GraphTraversalSource, + statics: statics + }; + if (typeof module !== 'undefined') { + // CommonJS + module.exports = toExport; + return; + } + // Nashorn and rest + return toExport; +}).call(this);
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ac983179/gremlin-javascript/src/main/javascript/gremlin-javascript/process/traversal.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/process/traversal.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/process/traversal.js new file mode 100644 index 0000000..5c9bf6c --- /dev/null +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/process/traversal.js @@ -0,0 +1,395 @@ +/* + * 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 + */ +(function defineTraversalModule() { + "use strict"; + + function Traversal(graph, traversalStrategies, bytecode) { + this._graph = graph; + this._traversalStrategies = traversalStrategies; + this._bytecode = bytecode; + this.traversers = null; + this.sideEffects = null; + } + + /** @returns {Bytecode} */ + Traversal.prototype.getBytecode = function () { + return this._bytecode; + }; + + /** @param {Function} callback */ + Traversal.prototype.list = function (callback) { + var self = this; + this._traversalStrategies.applyStrategies(this, function (err) { + if (err) { + return callback(err); + } + callback(err, self.traversers); + }); + }; + + /** @param {Function} callback */ + Traversal.prototype.one = function (callback) { + this.list(function (err, result) { + callback(err, result ? result[0] : null); + }); + }; + + /** + * Returns the Bytecode JSON representation of the traversal + * @returns {String} + */ + Traversal.prototype.toString = function () { + return this._bytecode.toString(); + }; + + /** + * Represents an operation. + * @constructor + */ + function P(operator, value, other) { + this.operator = operator; + this.value = value; + this.other = other; + } + + /** + * Returns the string representation of the instance. + * @returns {string} + */ + P.prototype.toString = function () { + if (this.other === undefined) { + return this.operator + '(' + this.value + ')'; + } + return this.operator + '(' + this.value + ', ' + this.other + ')'; + }; + + function createP(operator, args) { + args.unshift(null, operator); + return new (Function.prototype.bind.apply(P, args)); + } + + /** @param {...Object} args */ + P.between = function (args) { + return createP('between', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.eq = function (args) { + return createP('eq', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.gt = function (args) { + return createP('gt', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.gte = function (args) { + return createP('gte', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.inside = function (args) { + return createP('inside', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.lt = function (args) { + return createP('lt', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.lte = function (args) { + return createP('lte', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.neq = function (args) { + return createP('neq', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.not = function (args) { + return createP('not', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.outside = function (args) { + return createP('outside', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.test = function (args) { + return createP('test', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.within = function (args) { + return createP('within', parseArgs.apply(null, arguments)); + }; + + /** @param {...Object} args */ + P.without = function (args) { + return createP('without', parseArgs.apply(null, arguments)); + }; + + P.prototype.and = function (arg) { + return new P('and', this, arg); + }; + + P.prototype.or = function (arg) { + return new P('or', this, arg); + }; + + function Traverser(object, bulk) { + this.object = object; + this.bulk = bulk == undefined ? 1 : bulk; + } + + function TraversalSideEffects() { + + } + + /** + * Creates a new instance of TraversalStrategies. + * @param {TraversalStrategies} [traversalStrategies] + * @constructor + */ + function TraversalStrategies(traversalStrategies) { + /** @type {Array<TraversalStrategy>} */ + this.strategies = traversalStrategies ? traversalStrategies.strategies : []; + } + + /** @param {TraversalStrategy} strategy */ + TraversalStrategies.prototype.addStrategy = function (strategy) { + this.strategies.push(strategy); + }; + + /** @param {Traversal} traversal */ + TraversalStrategies.prototype.applyStrategies = function (traversal) { + this.strategies.forEach(function eachStrategy(s) { + s.apply(traversal); + }); + }; + + /** + * @abstract + * @constructor + */ + function TraversalStrategy() { + + } + + /** + * @abstract + * @param {Traversal} traversal + */ + TraversalStrategy.prototype.apply = function (traversal) { + + }; + + /** + * Creates a new instance of Bytecode + * @param {Bytecode} [toClone] + * @constructor + */ + function Bytecode(toClone) { + this._bindings = {}; + if (!toClone) { + this.sourceInstructions = []; + this.stepInstructions = []; + } + else { + this.sourceInstructions = toClone.sourceInstructions.slice(0); + this.stepInstructions = toClone.sourceInstructions.slice(0); + } + } + + /** + * Adds a new source instructions + * @param {String} name + * @param {Array} values + * @returns {Bytecode} + */ + Bytecode.prototype.addSource = function (name, values) { + if (name === undefined) { + throw new Error('Name is not defined'); + } + var instruction = new Array(values.length + 1); + instruction[0] = name; + for (var i = 0; i < values.length; ++i) { + instruction[i + 1] = this._convertToArgument(values[i]); + } + this.sourceInstructions.push(this._generateInstruction(name, values)); + return this; + }; + + /** + * Adds a new step instructions + * @param {String} name + * @param {Array} values + * @returns {Bytecode} + */ + Bytecode.prototype.addStep = function (name, values) { + if (name === undefined) { + throw new Error('Name is not defined'); + } + this.stepInstructions.push(this._generateInstruction(name, values)); + return this; + }; + + Bytecode.prototype._generateInstruction = function (name, values) { + var instruction = new Array(values.length + 1); + instruction[0] = name; + for (var i = 0; i < values.length; ++i) { + instruction[i + 1] = this._convertToArgument(values[i]); + } + return instruction; + }; + + /** + * Returns the JSON representation of the source and step instructions + * @returns {String} + */ + Bytecode.prototype.toString = function () { + return ( + (this.sourceInstructions.length > 0 ? JSON.stringify(this.sourceInstructions) : '') + + (this.stepInstructions.length > 0 ? JSON.stringify(this.stepInstructions) : '') + ); + }; + + Bytecode.prototype._convertToArgument = function (value) { + return value; + }; + + function toEnum(typeName, keys) { + var result = {}; + keys.split(' ').forEach(function (k) { + if (k === k.toUpperCase()) { + k = k.toLowerCase(); + } + result[k] = new EnumValue(typeName, k); + }); + return result; + } + + function EnumValue(typeName, elementName) { + this.typeName = typeName; + this.elementName = elementName; + } + + /** + * @type {{barrier, cardinality, column, direction, operator, order, pop, scope, t}} + */ + var enums = {}; + enums.barrier = toEnum('Barrier', 'normSack'); + enums.cardinality = toEnum('Cardinality', 'list set single'); + enums.column = toEnum('Column', 'keys values'); + enums.direction = toEnum('Direction', 'BOTH IN OUT'); + enums.operator = toEnum('Operator', 'addAll and assign div max min minus mult or sum sumLong'); + enums.order = toEnum('Order', 'decr incr keyDecr keyIncr shuffle valueDecr valueIncr'); + enums.pop = toEnum('Pop', 'all first last'); + enums.scope = toEnum('Scope', 'global local'); + enums.t = toEnum('T', 'id key label value'); + + // Utility functions + /** @returns {Array} */ + function parseArgs() { + return (arguments.length === 1 ? [ arguments[0] ] : Array.apply(null, arguments)); + } + + /** + * @param {Array} arr + * @param {Function} fn + * @param {Function} [callback] + */ + function eachSeries(arr, fn, callback) { + if (!Array.isArray(arr)) { + throw new TypeError('First parameter is not an Array'); + } + callback = callback || noop; + var length = arr.length; + if (length === 0) { + return callback(); + } + var sync; + var index = 1; + fn(arr[0], next); + if (sync === undefined) { + sync = false; + } + + function next(err) { + if (err) { + return callback(err); + } + if (index >= length) { + return callback(); + } + if (sync === undefined) { + sync = true; + } + if (sync) { + return process.nextTick(function () { + fn(arr[index++], next); + }); + } + fn(arr[index++], next); + } + } + + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + } + + var toExport = { + Bytecode: Bytecode, + EnumValue: EnumValue, + inherits: inherits, + P: P, + parseArgs: parseArgs, + Traversal: Traversal, + TraversalSideEffects: TraversalSideEffects, + TraversalStrategies: TraversalStrategies, + TraversalStrategy: TraversalStrategy, + Traverser: Traverser + }; + Object.keys(enums).forEach(function (k) { + toExport[k] = enums[k]; + }); + if (typeof module !== 'undefined') { + // CommonJS + module.exports = toExport; + return; + } + // Nashorn and rest + return toExport; +}).call(this); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ac983179/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/graph.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/graph.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/graph.js new file mode 100644 index 0000000..7c48819 --- /dev/null +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/graph.js @@ -0,0 +1,146 @@ +/* + * 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 + */ +(function defineGraphModule() { + "use strict"; + + var gt = loadModule.call(this, '../process/graph-traversal.js'); + var t = loadModule.call(this, '../process/traversal.js'); + var inherits = t.inherits; + + function Graph() { + + } + + /** + * Returns the graph traversal source. + * @returns {GraphTraversalSource} + */ + Graph.prototype.traversal = function () { + return new gt.GraphTraversalSource(this, new t.TraversalStrategies()); + }; + + Graph.prototype.toString = function () { + return 'graph[empty]'; + }; + + function Element(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} + */ + Element.prototype.equals = function (other) { + return (other instanceof Element) && this.id === other.id; + }; + + function Vertex(id, label, properties) { + Element.call(this, id, label); + this.properties = properties; + } + + Vertex.prototype.toString = function () { + return 'v[' + this.id + ']'; + }; + + inherits(Vertex, Element); + + function Edge(id, outV, label, inV) { + Element.call(this, id, label); + this.outV = outV; + this.inV = inV; + } + + inherits(Edge, Element); + + Edge.prototype.toString = function () { + return 'e[' + this.id + '][' + this.outV.id + '-' + this.label + '->' + this.inV.id + ']'; + }; + + function VertexProperty(id, label, value) { + Element.call(this, id, label); + this.value = value; + this.key = this.label; + } + + inherits(VertexProperty, Element); + + VertexProperty.prototype.toString = function () { + return 'vp[' + this.label + '->' + this.value.substr(0, 20) + ']'; + }; + + function Property(key, value) { + this.key = key; + this.value = value; + } + + Property.prototype.toString = function () { + return 'p[' + this.key + '->' + this.value.substr(0, 20) + ']'; + }; + + Property.prototype.equals = function (other) { + return (other instanceof Property) && this.key === other.key && this.value === other.value; + }; + + /** + * Represents a walk through a graph as defined by a traversal. + * @param {Array} labels + * @param {Array} objects + * @constructor + */ + function Path(labels, objects) { + this.labels = labels; + this.objects = objects; + } + + function loadModule(moduleName) { + if (typeof require !== 'undefined') { + return require(moduleName); + } + if (typeof load !== 'undefined') { + var path = new java.io.File(__DIR__ + moduleName).getCanonicalPath(); + this.__dependencies = this.__dependencies || {}; + return this.__dependencies[path] = (this.__dependencies[path] || load(path)); + } + throw new Error('No module loader was found'); + } + + var toExport = { + Edge: Edge, + Graph: Graph, + Path: Path, + Property: Property, + Vertex: Vertex, + VertexProperty: VertexProperty + }; + if (typeof module !== 'undefined') { + // CommonJS + module.exports = toExport; + return; + } + // Nashorn and rest + return toExport; +}).call(this); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ac983179/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/io/graph-serializer.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/io/graph-serializer.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/io/graph-serializer.js new file mode 100644 index 0000000..2dde340 --- /dev/null +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/io/graph-serializer.js @@ -0,0 +1,406 @@ +/* + * 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 + */ +(function graphSerializerModule() { + "use strict"; + + var t = loadModule.call(this, '../../process/traversal.js'); + var g = loadModule.call(this, '../graph.js'); + + /** + * A type serializer + * @typedef {Object} Serializer + * @property {Function} serialize + * @property {Function} deserialize + * @property {Function} [canBeUsedFor] + */ + + /** + * @const + * @private + */ + var valueKey = '@value'; + + /** + * @const + * @private + */ + var typeKey = '@type'; + + var deserializers = { + 'g:Traverser': TraverserSerializer, + 'g:Int32': NumberSerializer, + 'g:Int64': NumberSerializer, + 'g:Float': NumberSerializer, + 'g:Double': NumberSerializer, + 'g:Vertex': VertexSerializer, + 'g:Edge': EdgeSerializer, + 'g:VertexProperty': VertexPropertySerializer, + 'g:Property': PropertySerializer, + 'g:Path': PathSerializer + }; + + var serializers = [ + NumberSerializer, + BytecodeSerializer, + TraverserSerializer, + PSerializer, + LambdaSerializer, + EnumSerializer + ]; + + /** + * GraphSON Writer + * @param {Object} [options] + * @param {Object} options.serializers An object used as an associative array with GraphSON 2 type name as keys and + * serializer instances as values, ie: { 'g:Int64': longSerializer }. + * @constructor + */ + function GraphSONWriter(options) { + this._options = options || {}; + // Create instance of the default serializers + this._serializers = serializers.map(function (serializerConstructor) { + var s = new serializerConstructor(); + s.writer = this; + return s; + }, this); + var customSerializers = this._options.serializers || {}; + Object.keys(customSerializers).forEach(function (key) { + var s = customSerializers[key]; + if (!s.serialize) { + return; + } + s.writer = this; + // Insert custom serializers first + this._serializers.unshift(s); + }, this); + } + + GraphSONWriter.prototype.adaptObject = function (value) { + var s; + if (Array.isArray(value)) { + return value.map(function (item) { + return this.adaptObject(item); + }, this); + } + for (var i = 0; i < this._serializers.length; i++) { + var currentSerializer = this._serializers[i]; + if (currentSerializer.canBeUsedFor && currentSerializer.canBeUsedFor(value)) { + s = currentSerializer; + break; + } + } + if (s) { + return s.serialize(value); + } + // Default (strings / objects / ...) + return value; + }; + + /** + * Returns the GraphSON representation of the provided object instance. + * @param {Object} obj + * @returns {String} + */ + GraphSONWriter.prototype.write = function (obj) { + return JSON.stringify(this.adaptObject(obj)); + }; + + /** + * GraphSON Reader + * @param {Object} [options] + * @param {Object} [options.serializers] An object used as an associative array with GraphSON 2 type name as keys and + * deserializer instances as values, ie: { 'g:Int64': longSerializer }. + * @constructor + */ + function GraphSONReader(options) { + this._options = options || {}; + this._deserializers = {}; + Object.keys(deserializers).forEach(function (typeName) { + var serializerConstructor = deserializers[typeName]; + var s = new serializerConstructor(); + s.reader = this; + this._deserializers[typeName] = s; + }, this); + if (this._options.serializers) { + var customSerializers = this._options.serializers || {}; + Object.keys(customSerializers).forEach(function (key) { + var s = customSerializers[key]; + if (!s.deserialize) { + return; + } + s.reader = this; + this._deserializers[key] = s; + }, this); + } + } + + GraphSONReader.prototype.read = function (obj) { + if (Array.isArray(obj)) { + return obj.map(function mapEach(item) { + return this.read(item); + }, this); + } + var type = obj[typeKey]; + if (type) { + var d = this._deserializers[type]; + if (d) { + // Use type serializer + return d.deserialize(obj); + } + return obj[valueKey]; + } + if (obj && typeof obj === 'object' && obj.constructor === Object) { + return this._deserializeObject(obj); + } + // Default (for boolean, number and other scalars) + return obj; + }; + + GraphSONReader.prototype._deserializeObject = function (obj) { + var keys = Object.keys(obj); + var result = {}; + for (var i = 0; i < keys.length; i++) { + result[keys[i]] = this.read(obj[keys[i]]); + } + return result; + }; + + function NumberSerializer() { + + } + + NumberSerializer.prototype.serialize = function (item) { + return item; + }; + + NumberSerializer.prototype.deserialize = function (obj) { + var value = obj[valueKey]; + return parseFloat(value); + }; + + NumberSerializer.prototype.canBeUsedFor = function (value) { + return (typeof value === 'number'); + }; + + function BytecodeSerializer() { + + } + + BytecodeSerializer.prototype.serialize = function (item) { + var bytecode = item; + if (item instanceof t.Traversal) { + bytecode = item.getBytecode(); + } + var result = {}; + result[typeKey] = 'g:Bytecode'; + var resultValue = result[valueKey] = {}; + var sources = this._serializeInstructions(bytecode.sourceInstructions); + if (sources) { + resultValue['source'] = sources; + } + var steps = this._serializeInstructions(bytecode.stepInstructions); + if (steps) { + resultValue['step'] = steps; + } + return result; + }; + + BytecodeSerializer.prototype._serializeInstructions = function (instructions) { + if (instructions.length === 0) { + return null; + } + var result = new Array(instructions.length); + result[0] = instructions[0]; + for (var i = 1; i < instructions.length; i++) { + result[i] = this.writer.adaptObject(instructions[i]); + } + return result; + }; + + BytecodeSerializer.prototype.canBeUsedFor = function (value) { + return (value instanceof t.Bytecode) || (value instanceof t.Traversal); + }; + + function PSerializer() { + + } + + /** @param {P} item */ + PSerializer.prototype.serialize = function (item) { + var result = {}; + result[typeKey] = 'g:P'; + var resultValue = result[valueKey] = { + 'predicate': item.operator + }; + if (item.other == undefined) { + resultValue['value'] = this.writer.adaptObject(item.value); + } + else { + resultValue['value'] = [ this.writer.adaptObject(item.value), this.writer.adaptObject(item.other) ]; + } + return result; + }; + + PSerializer.prototype.canBeUsedFor = function (value) { + return (value instanceof t.P); + }; + + function LambdaSerializer() { + + } + + /** @param {Function} item */ + LambdaSerializer.prototype.serialize = function (item) { + var result = {}; + result[typeKey] = 'g:Lambda'; + result[valueKey] = { + 'arguments': item.length, + 'language': 'gremlin-javascript', + 'script': item.toString() + }; + return result; + }; + + LambdaSerializer.prototype.canBeUsedFor = function (value) { + return (typeof value === 'function'); + }; + + function EnumSerializer() { + + } + + /** @param {EnumValue} item */ + EnumSerializer.prototype.serialize = function (item) { + var result = {}; + result[typeKey] = 'g:' + item.typeName; + result[valueKey] = item.elementName; + return result; + }; + + EnumSerializer.prototype.canBeUsedFor = function (value) { + return value && value.typeName && value instanceof t.EnumValue; + }; + + function TraverserSerializer() { + + } + + /** @param {Traverser} item */ + TraverserSerializer.prototype.serialize = function (item) { + var result = {}; + result[typeKey] = 'g:Traverser'; + result[valueKey] = { + 'value': this.writer.adaptObject(item.object), + 'bulk': this.writer.adaptObject(item.bulk) + }; + return result; + }; + + TraverserSerializer.prototype.deserialize = function (obj) { + var value = obj[valueKey]; + return new t.Traverser(this.reader.read(value['value']), this.reader.read(value['bulk'])); + }; + + TraverserSerializer.prototype.canBeUsedFor = function (value) { + return (value instanceof t.Traverser); + }; + + function VertexSerializer() { + + } + + VertexSerializer.prototype.deserialize = function (obj) { + var value = obj[valueKey]; + return new g.Vertex(this.reader.read(value['id']), value['label'], this.reader.read(value['properties'])); + }; + + function VertexPropertySerializer() { + + } + + VertexPropertySerializer.prototype.deserialize = function (obj) { + var value = obj[valueKey]; + return new g.VertexProperty(this.reader.read(value['id']), value['label'], this.reader.read(value['value'])); + }; + + function PropertySerializer() { + + } + + PropertySerializer.prototype.deserialize = function (obj) { + var value = obj[valueKey]; + return new g.Property( + value['key'], + this.reader.read(value['value'])); + }; + + function EdgeSerializer() { + + } + + EdgeSerializer.prototype.deserialize = function (obj) { + var value = obj[valueKey]; + return new g.Edge( + this.reader.read(value['id']), + this.reader.read(value['outV']), + value['label'], + this.reader.read(value['inV']) + ); + }; + + function PathSerializer() { + + } + + PathSerializer.prototype.deserialize = function (obj) { + var value = obj[valueKey]; + var objects = value['objects'].map(function objectMapItem(o) { + return this.reader.read(o); + }, this); + return new g.Path(this.reader.read(value['labels']), objects); + }; + + function loadModule(moduleName) { + if (typeof require !== 'undefined') { + return require(moduleName); + } + if (typeof load !== 'undefined') { + var path = new java.io.File(__DIR__ + moduleName).getCanonicalPath(); + this.__dependencies = this.__dependencies || {}; + return this.__dependencies[path] = (this.__dependencies[path] || load(path)); + } + throw new Error('No module loader was found'); + } + + var toExport = { + GraphSONWriter: GraphSONWriter, + GraphSONReader: GraphSONReader + }; + if (typeof module !== 'undefined') { + // CommonJS + module.exports = toExport; + return; + } + // Nashorn and rest + return toExport; +}).call(this); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ac983179/gremlin-javascript/src/test/javascript/gremlin-javascript/helper.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/test/javascript/gremlin-javascript/helper.js b/gremlin-javascript/src/test/javascript/gremlin-javascript/helper.js new file mode 100644 index 0000000..858ed06 --- /dev/null +++ b/gremlin-javascript/src/test/javascript/gremlin-javascript/helper.js @@ -0,0 +1,84 @@ +/* + * 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 + */ +(function defineHelperModule() { + "use strict"; + + var assert = { + ok: function (condition, message) { + if (!condition) { + throw new AssertError(message || (condition + ' == true')); + } + }, + strictEqual: function (val1, val2, message) { + if (val1 !== val2) { + throw new AssertError(message || (val1 + ' === ' + val2)); + } + } + }; + + function loadLibModule(moduleName) { + if (typeof require !== 'undefined') { + moduleName = '../lib/' + moduleName; + return require(moduleName); + } + if (typeof load !== 'undefined' && typeof java !== 'undefined') { + moduleName = __DIR__ + '../../../main/javascript/gremlin-javascript/' + moduleName; + var path = new java.io.File(moduleName).getCanonicalPath(); + this.__dependencies = this.__dependencies || {}; + return this.__dependencies[path] = (this.__dependencies[path] || load(path)); + } + throw new Error('No module loader was found'); + } + + function AssertError(message) { + Error.call(this, message); + this.stack = (new Error(message)).stack; + if (typeof print !== 'undefined') { + print(this.stack); + } + } + + inherits(AssertError, Error); + + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + } + var toExport = { + assert: assert, + loadLibModule: loadLibModule + }; + if (typeof module !== 'undefined') { + // CommonJS + module.exports = toExport; + return; + } + return toExport; +}).call(this); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ac983179/gremlin-javascript/src/test/javascript/gremlin-javascript/test-exports.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/test/javascript/gremlin-javascript/test-exports.js b/gremlin-javascript/src/test/javascript/gremlin-javascript/test-exports.js new file mode 100644 index 0000000..6edb323 --- /dev/null +++ b/gremlin-javascript/src/test/javascript/gremlin-javascript/test-exports.js @@ -0,0 +1,78 @@ +/* + * 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 + */ +(function defineTestCases() { + "use strict"; + + var helper = loadModule.call(this, './helper.js'); + var assert = helper.assert; + var glvModule = helper.loadLibModule.call(this, './index.js'); + + [ + function testExports() { + assert.ok(glvModule); + + assert.ok(glvModule.process); + assert.strictEqual(typeof glvModule.process.Bytecode, 'function'); + assert.strictEqual(typeof glvModule.process.EnumValue, 'function'); + assert.strictEqual(typeof glvModule.process.inherits, 'function'); + assert.strictEqual(typeof glvModule.process.P, 'function'); + assert.strictEqual(typeof glvModule.process.parseArgs, 'function'); + assert.strictEqual(typeof glvModule.process.Traversal, 'function'); + assert.strictEqual(typeof glvModule.process.TraversalSideEffects, 'function'); + assert.strictEqual(typeof glvModule.process.TraversalStrategies, 'function'); + assert.strictEqual(typeof glvModule.process.TraversalStrategy, 'function'); + assert.strictEqual(typeof glvModule.process.Traverser, 'function'); + assert.strictEqual(typeof glvModule.process.GraphTraversal, 'function'); + assert.strictEqual(typeof glvModule.process.GraphTraversalSource, 'function'); + assert.ok(glvModule.process.statics); + + assert.ok(glvModule.structure); + assert.ok(glvModule.structure.io); + assert.strictEqual(typeof glvModule.structure.io.GraphSONReader, 'function'); + assert.strictEqual(typeof glvModule.structure.io.GraphSONWriter, 'function'); + assert.strictEqual(typeof glvModule.structure.Edge, 'function'); + assert.strictEqual(typeof glvModule.structure.Graph, 'function'); + assert.strictEqual(typeof glvModule.structure.Path, 'function'); + assert.strictEqual(typeof glvModule.structure.Property, 'function'); + assert.strictEqual(typeof glvModule.structure.Vertex, 'function'); + assert.strictEqual(typeof glvModule.structure.VertexProperty, 'function'); + + assert.ok(glvModule.driver); + assert.strictEqual(typeof glvModule.driver.RemoteConnection, 'function'); + assert.strictEqual(typeof glvModule.driver.RemoteStrategy, 'function'); + assert.strictEqual(typeof glvModule.driver.RemoteTraversal, 'function'); + } + ].forEach(function (testCase) { + testCase.call(null); + }); + + function loadModule(moduleName) { + if (typeof require !== 'undefined') { + return require(moduleName); + } + if (typeof load !== 'undefined') { + return load(__DIR__ + moduleName); + } + throw new Error('No module loader was found'); + } +}).call(this) \ No newline at end of file