http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js index d887fe0..2877f02 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js @@ -26,202 +26,209 @@ const utils = require('../utils'); const parseArgs = utils.parseArgs; const itemDone = Object.freeze({ value: null, done: true }); -function Traversal(graph, traversalStrategies, bytecode) { - this.graph = graph; - this.traversalStrategies = traversalStrategies; - this.bytecode = bytecode; - /** @type {Array<Traverser>} */ - this.traversers = null; - this.sideEffects = null; - this._traversalStrategiesPromise = null; - this._traversersIteratorIndex = 0; -} +class Traversal { + constructor(graph, traversalStrategies, bytecode) { + this.graph = graph; + this.traversalStrategies = traversalStrategies; + this.bytecode = bytecode; + /** @type {Array<Traverser>} */ + this.traversers = null; + this.sideEffects = null; + this._traversalStrategiesPromise = null; + this._traversersIteratorIndex = 0; + } -/** @returns {Bytecode} */ -Traversal.prototype.getBytecode = function () { - return this.bytecode; -}; + /** @returns {Bytecode} */ + getBytecode() { + return this.bytecode; + } -/** - * Returns an Array containing the traverser objects. - * @returns {Promise.<Array>} - */ -Traversal.prototype.toList = function () { - return this._applyStrategies().then(() => { - const result = []; - let it; - while ((it = this._getNext()) && !it.done) { - result.push(it.value); + /** + * Returns an Array containing the traverser objects. + * @returns {Promise.<Array>} + */ + toList() { + return this._applyStrategies().then(() => { + const result = []; + let it; + while ((it = this._getNext()) && !it.done) { + result.push(it.value); + } + return result; + }); + }; + + /** + * Iterates all Traverser instances in the traversal. + * @returns {Promise} + */ + iterate() { + return this._applyStrategies().then(() => { + let it; + while ((it = this._getNext()) && !it.done) { + } + }); + } + + /** + * Async iterator method implementation. + * Returns a promise containing an iterator item. + * @returns {Promise.<{value, done}>} + */ + next() { + return this._applyStrategies().then(() => this._getNext()); + } + + /** + * Synchronous iterator of traversers including + * @private + */ + _getNext() { + while (this.traversers && this._traversersIteratorIndex < this.traversers.length) { + let traverser = this.traversers[this._traversersIteratorIndex]; + if (traverser.bulk > 0) { + traverser.bulk--; + return { value: traverser.object, done: false }; + } + this._traversersIteratorIndex++; } - return result; - }); -}; + return itemDone; + } -/** - * Iterates all Traverser instances in the traversal. - * @returns {Promise} - */ -Traversal.prototype.iterate = function () { - return this._applyStrategies().then(() => { - let it; - while ((it = this._getNext()) && !it.done) { + _applyStrategies() { + if (this._traversalStrategiesPromise) { + // Apply strategies only once + return this._traversalStrategiesPromise; } - }); -}; + return this._traversalStrategiesPromise = this.traversalStrategies.applyStrategies(this); + } -/** - * Async iterator method implementation. - * Returns a promise containing an iterator item. - * @returns {Promise.<{value, done}>} - */ -Traversal.prototype.next = function () { - return this._applyStrategies().then(() => this._getNext()); -}; + /** + * Returns the Bytecode JSON representation of the traversal + * @returns {String} + */ + toString() { + return this.bytecode.toString(); + }; +} -/** - * Synchronous iterator of traversers including - * @private - */ -Traversal.prototype._getNext = function () { - while (this.traversers && this._traversersIteratorIndex < this.traversers.length) { - let traverser = this.traversers[this._traversersIteratorIndex]; - if (traverser.bulk > 0) { - traverser.bulk--; - return { value: traverser.object, done: false }; +class P { + /** + * Represents an operation. + * @constructor + */ + constructor(operator, value, other) { + this.operator = operator; + this.value = value; + this.other = other; + } + + /** + * Returns the string representation of the instance. + * @returns {string} + */ + toString() { + if (this.other === undefined) { + return this.operator + '(' + this.value + ')'; } - this._traversersIteratorIndex++; + return this.operator + '(' + this.value + ', ' + this.other + ')'; } - return itemDone; -}; -Traversal.prototype._applyStrategies = function () { - if (this._traversalStrategiesPromise) { - // Apply strategies only once - return this._traversalStrategiesPromise; + and(arg) { + return new P('and', this, arg); } - return this._traversalStrategiesPromise = this.traversalStrategies.applyStrategies(this); -}; -/** - * Returns the Bytecode JSON representation of the traversal - * @returns {String} - */ -Traversal.prototype.toString = function () { - return this.bytecode.toString(); -}; + or(arg) { + return new P('or', this, arg); + } -/** - * Represents an operation. - * @constructor - */ -function P(operator, value, other) { - this.operator = operator; - this.value = value; - this.other = other; -} + /** @param {...Object} args */ + static between(args) { + return createP('between', parseArgs.apply(null, arguments)); + } -/** - * Returns the string representation of the instance. - * @returns {string} - */ -P.prototype.toString = function () { - if (this.other === undefined) { - return this.operator + '(' + this.value + ')'; + /** @param {...Object} args */ + static eq(args) { + return createP('eq', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static gt(args) { + return createP('gt', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static gte(args) { + return createP('gte', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static inside(args) { + return createP('inside', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static lt(args) { + return createP('lt', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static lte(args) { + return createP('lte', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static neq(args) { + return createP('neq', parseArgs.apply(null, arguments)); } - return this.operator + '(' + this.value + ', ' + this.other + ')'; -}; + + /** @param {...Object} args */ + static not(args) { + return createP('not', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static outside(args) { + return createP('outside', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static test(args) { + return createP('test', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static within(args) { + return createP('within', parseArgs.apply(null, arguments)); + } + + /** @param {...Object} args */ + static without(args) { + return createP('without', parseArgs.apply(null, arguments)); + } + +} 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 || 1; +class Traverser { + constructor(object, bulk) { + this.object = object; + this.bulk = bulk || 1; + } } -function TraversalSideEffects() { +class TraversalSideEffects { } function toEnum(typeName, keys) { - var result = {}; - keys.split(' ').forEach(function (k) { - var jsKey = k; + const result = {}; + keys.split(' ').forEach(k => { + let jsKey = k; if (jsKey === jsKey.toUpperCase()) { jsKey = jsKey.toLowerCase(); } @@ -230,17 +237,19 @@ function toEnum(typeName, keys) { return result; } -function EnumValue(typeName, elementName) { - this.typeName = typeName; - this.elementName = elementName; +class EnumValue { + constructor(typeName, elementName) { + this.typeName = typeName; + this.elementName = elementName; + } } module.exports = { - EnumValue: EnumValue, - P: P, - Traversal: Traversal, - TraversalSideEffects: TraversalSideEffects, - Traverser: Traverser, + EnumValue, + P, + Traversal, + TraversalSideEffects, + Traverser, barrier: toEnum('Barrier', 'normSack'), cardinality: toEnum('Cardinality', 'list set single'), column: toEnum('Column', 'keys values'),
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/graph.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/graph.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/graph.js index cbb7e2c..2861a50 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/graph.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/graph.js @@ -22,120 +22,120 @@ */ 'use strict'; -var gt = require('../process/graph-traversal'); -var TraversalStrategies = require('../process/traversal-strategy').TraversalStrategies; -var utils = require('../utils'); -var inherits = utils.inherits; - -function Graph() { +const gt = require('../process/graph-traversal'); +const TraversalStrategies = require('../process/traversal-strategy').TraversalStrategies; + +class Graph { + /** + * Returns the graph traversal source. + * @returns {GraphTraversalSource} + */ + traversal() { + return new gt.GraphTraversalSource(this, new TraversalStrategies()); + } + toString() { + return 'graph[empty]'; + } } -/** - * Returns the graph traversal source. - * @returns {GraphTraversalSource} - */ -Graph.prototype.traversal = function () { - return new gt.GraphTraversalSource(this, new TraversalStrategies()); -}; - -Graph.prototype.toString = function () { - return 'graph[empty]'; -}; +class Element { + constructor(id, label) { + this.id = id; + this.label = label; + } -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} + */ + equals(other) { + return (other instanceof Element) && this.id === other.id; + } } -/** - * 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; -}; +class Vertex extends Element { + constructor(id, label, properties) { + super(id, label); + this.properties = properties; + } -function Vertex(id, label, properties) { - Element.call(this, id, label); - this.properties = properties; + toString() { + return 'v[' + this.id + ']'; + } } -Vertex.prototype.toString = function () { - return 'v[' + this.id + ']'; -}; - -inherits(Vertex, Element); - -function Edge(id, outV, label, inV, properties) { - Element.call(this, id, label); - this.outV = outV; - this.inV = inV; - this.properties = {}; - (function adaptProperties(self) { +class Edge extends Element { + constructor(id, outV, label, inV, properties) { + super(id, label); + this.outV = outV; + this.inV = inV; + this.properties = {}; if (properties) { - var keys = Object.keys(properties); - for (var i = 0; i < keys.length; i++) { - var k = keys[i]; - self.properties[k] = properties[k].value; + const keys = Object.keys(properties); + for (let i = 0; i < keys.length; i++) { + const k = keys[i]; + this.properties[k] = properties[k].value; } } - })(this); -} - -inherits(Edge, Element); - -Edge.prototype.toString = function () { - return 'e[' + this.id + '][' + this.outV.id + '-' + this.label + '->' + this.inV.id + ']'; -}; + } -function VertexProperty(id, label, value, properties) { - Element.call(this, id, label); - this.value = value; - this.key = this.label; - this.properties = properties; + toString() { + return 'e[' + this.id + '][' + this.outV.id + '-' + this.label + '->' + this.inV.id + ']'; + } } -inherits(VertexProperty, Element); - -VertexProperty.prototype.toString = function () { - return 'vp[' + this.label + '->' + this.value.substr(0, 20) + ']'; -}; +class VertexProperty extends Element { + constructor(id, label, value, properties) { + super(id, label); + this.value = value; + this.key = this.label; + this.properties = properties; + } -function Property(key, value) { - this.key = key; - this.value = value; + toString() { + return 'vp[' + this.label + '->' + this.value.substr(0, 20) + ']'; + } } -Property.prototype.toString = function () { - return 'p[' + this.key + '->' + this.value.substr(0, 20) + ']'; -}; +class Property { + constructor(key, value) { + this.key = key; + this.value = value; + } -Property.prototype.equals = function (other) { - return (other instanceof Property) && this.key === other.key && this.value === other.value; -}; + toString() { + return 'p[' + this.key + '->' + this.value.substr(0, 20) + ']'; + } -/** - * 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; + equals(other) { + return (other instanceof Property) && this.key === other.key && this.value === other.value; + } } -Path.prototype.equals = function (other) { - if (!(other instanceof Path)) { - return false; +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; } - if (other === this) { - return true; + + equals(other) { + if (!(other instanceof Path)) { + return false; + } + if (other === this) { + return true; + } + return areEqual(this.objects, other.objects) && areEqual(this.labels, other.labels); } - return areEqual(this.objects, other.objects) && areEqual(this.labels, other.labels); -}; +} function areEqual(obj1, obj2) { if (obj1 === obj2) { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js index 8e4ad5e..3dbd340 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js @@ -22,430 +22,159 @@ */ 'use strict'; -var t = require('../../process/traversal'); -var Bytecode = require('../../process/bytecode'); -var g = require('../graph'); -var utils = require('../../utils'); - -/** - * 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, - VertexSerializer, - EdgeSerializer, - LongSerializer -]; +const typeSerializers = require('./type-serializers'); /** * 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) { +class GraphSONWriter { + /** + * @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 + */ + constructor(options) { + this._options = options || {}; + // Create instance of the default serializers + this._serializers = serializers.map(serializerConstructor => { + const s = new serializerConstructor(); + s.writer = this; + return s; + }); + const customSerializers = this._options.serializers || {}; + Object.keys(customSerializers).forEach(key => { + const s = customSerializers[key]; + if (!s.serialize) { return; } - s.reader = this; - this._deserializers[key] = s; - }, this); + s.writer = this; + // Insert custom serializers first + this._serializers.unshift(s); + }); } -} -GraphSONReader.prototype.read = function (obj) { - if (obj === undefined) { - return undefined; - } - if (obj === null) { - return null; - } - 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); + adaptObject(value) { + let s; + if (Array.isArray(value)) { + return value.map(item => this.adaptObject(item)); } - return obj[valueKey]; - } - if (obj && typeof obj === 'object' && obj.constructor === Object) { - return this._deserializeObject(obj); + for (let i = 0; i < this._serializers.length; i++) { + const currentSerializer = this._serializers[i]; + if (currentSerializer.canBeUsedFor && currentSerializer.canBeUsedFor(value)) { + s = currentSerializer; + break; + } + } + if (s) { + return s.serialize(value); + } + // Default (strings / objects / ...) + return value; } - // 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]]); + /** + * Returns the GraphSON representation of the provided object instance. + * @param {Object} obj + * @returns {String} + */ + write(obj) { + return JSON.stringify(this.adaptObject(obj)); } - 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 LongSerializer() { - -} - -NumberSerializer.prototype.serialize = function (item) { - return { - [typeKey]: 'g:Int64', - [valueKey]: item.value - }; -}; - -NumberSerializer.prototype.canBeUsedFor = function (value) { - return (value instanceof utils.Long); -}; - -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; +class GraphSONReader { + /** + * 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 + */ + constructor(options) { + this._options = options || {}; + this._deserializers = {}; + Object.keys(deserializers).forEach(typeName => { + const serializerConstructor = deserializers[typeName]; + const s = new serializerConstructor(); + s.reader = this; + this._deserializers[typeName] = s; + }); + if (this._options.serializers) { + const customSerializers = this._options.serializers || {}; + Object.keys(customSerializers).forEach(key => { + const s = customSerializers[key]; + if (!s.deserialize) { + return; + } + s.reader = this; + this._deserializers[key] = s; + }); + } } - 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 = 0; i < instructions.length; i++) { - result[i] = this.writer.adaptObject(instructions[i]); + read(obj) { + if (obj === undefined) { + return undefined; + } + if (obj === null) { + return null; + } + if (Array.isArray(obj)) { + return obj.map(item => this.read(item)); + } + const type = obj[typeSerializers.typeKey]; + if (type) { + const d = this._deserializers[type]; + if (d) { + // Use type serializer + return d.deserialize(obj); + } + return obj[typeSerializers.valueKey]; + } + if (obj && typeof obj === 'object' && obj.constructor === Object) { + return this._deserializeObject(obj); + } + // Default (for boolean, number and other scalars) + return obj; } - return result; -}; - -BytecodeSerializer.prototype.canBeUsedFor = function (value) { - return (value instanceof 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 || item.other === null) { - resultValue['value'] = this.writer.adaptObject(item.value); - } - else { - resultValue['value'] = [ this.writer.adaptObject(item.value), this.writer.adaptObject(item.other) ]; + _deserializeObject(obj) { + const keys = Object.keys(obj); + const result = {}; + for (let i = 0; i < keys.length; i++) { + result[keys[i]] = this.read(obj[keys[i]]); + } + return result; } - 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'])); -}; - -/** @param {Vertex} item */ -VertexSerializer.prototype.serialize = function (item) { - var result = {}; - result[typeKey] = 'g:Vertex'; - result[valueKey] = { - 'id': this.writer.adaptObject(item.id), - 'label': item.label - }; - return result; -}; - -VertexSerializer.prototype.canBeUsedFor = function (value) { - return (value instanceof g.Vertex); -}; - -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']), - this.reader.read(value['properties']) - ); -}; - -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']), - this.reader.read(value['properties']) - ); -}; - -/** @param {Edge} item */ -EdgeSerializer.prototype.serialize = function (item) { - var result = {}; - result[typeKey] = 'g:Edge'; - result[valueKey] = { - 'id': this.writer.adaptObject(item.id), - 'label': item.label, - 'outV': this.writer.adaptObject(item.outV.id), - 'outVLabel': item.outV.label, - 'inV': this.writer.adaptObject(item.inV.id), - 'inVLabel': item.inV.label - }; - return result; -}; - -EdgeSerializer.prototype.canBeUsedFor = function (value) { - return (value instanceof g.Edge); -}; - -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); -}; +const deserializers = { + 'g:Traverser': typeSerializers.TraverserSerializer, + 'g:Int32': typeSerializers.NumberSerializer, + 'g:Int64': typeSerializers.NumberSerializer, + 'g:Float': typeSerializers.NumberSerializer, + 'g:Double': typeSerializers.NumberSerializer, + 'g:Vertex': typeSerializers.VertexSerializer, + 'g:Edge': typeSerializers.EdgeSerializer, + 'g:VertexProperty': typeSerializers.VertexPropertySerializer, + 'g:Property': typeSerializers.PropertySerializer, + 'g:Path': typeSerializers.PathSerializer +}; + +const serializers = [ + typeSerializers.NumberSerializer, + typeSerializers.BytecodeSerializer, + typeSerializers.TraverserSerializer, + typeSerializers.PSerializer, + typeSerializers.LambdaSerializer, + typeSerializers.EnumSerializer, + typeSerializers.VertexSerializer, + typeSerializers.EdgeSerializer, + typeSerializers.LongSerializer +]; module.exports = { - GraphSONWriter: GraphSONWriter, - GraphSONReader: GraphSONReader + GraphSONWriter, + GraphSONReader }; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js new file mode 100644 index 0000000..d6f131c --- /dev/null +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js @@ -0,0 +1,288 @@ +/* + * 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 t = require('../../process/traversal'); +const Bytecode = require('../../process/bytecode'); +const g = require('../graph'); +const utils = require('../../utils'); + +const valueKey = '@value'; +const typeKey = '@type'; + +/** + * @abstract + */ +class TypeSerializer { + serialize() { + throw new Error('serialize() method not implemented for ' + this.constructor.name); + } + + deserialize() { + throw new Error('deserialize() method not implemented for ' + this.constructor.name); + } + + canBeUsedFor() { + throw new Error('canBeUsedFor() method not implemented for ' + this.constructor.name); + } +} + +class NumberSerializer extends TypeSerializer { + serialize(item) { + return item; + } + + deserialize(obj) { + return parseFloat(obj[valueKey]); + } + + canBeUsedFor(value) { + return (typeof value === 'number'); + } +} + +class LongSerializer extends TypeSerializer { + serialize(item) { + return { + [typeKey]: 'g:Int64', + [valueKey]: item.value + }; + } + + canBeUsedFor(value) { + return (value instanceof utils.Long); + } +} + +class BytecodeSerializer extends TypeSerializer { + serialize(item) { + let bytecode = item; + if (item instanceof t.Traversal) { + bytecode = item.getBytecode(); + } + const result = {}; + result[typeKey] = 'g:Bytecode'; + const resultValue = result[valueKey] = {}; + const sources = this._serializeInstructions(bytecode.sourceInstructions); + if (sources) { + resultValue['source'] = sources; + } + const steps = this._serializeInstructions(bytecode.stepInstructions); + if (steps) { + resultValue['step'] = steps; + } + return result; + } + + _serializeInstructions(instructions) { + if (instructions.length === 0) { + return null; + } + const result = new Array(instructions.length); + result[0] = instructions[0]; + for (let i = 0; i < instructions.length; i++) { + result[i] = this.writer.adaptObject(instructions[i]); + } + return result; + } + + canBeUsedFor(value) { + return (value instanceof Bytecode) || (value instanceof t.Traversal); + } +} + +class PSerializer extends TypeSerializer { + /** @param {P} item */ + serialize(item) { + const result = {}; + result[typeKey] = 'g:P'; + const resultValue = result[valueKey] = { + 'predicate': item.operator + }; + if (item.other === undefined || item.other === null) { + resultValue['value'] = this.writer.adaptObject(item.value); + } + else { + resultValue['value'] = [ this.writer.adaptObject(item.value), this.writer.adaptObject(item.other) ]; + } + return result; + } + + canBeUsedFor(value) { + return (value instanceof t.P); + } +} + +class LambdaSerializer extends TypeSerializer { + /** @param {Function} item */ + serialize(item) { + return { + [typeKey]: 'g:Lambda', + [valueKey]: { + 'arguments': item.length, + 'language': 'gremlin-javascript', + 'script': item.toString() + } + }; + } + + canBeUsedFor(value) { + return (typeof value === 'function'); + } +} + +class EnumSerializer extends TypeSerializer { + /** @param {EnumValue} item */ + serialize(item) { + return { + [typeKey]: 'g:' + item.typeName, + [valueKey]: item.elementName + }; + } + + canBeUsedFor(value) { + return value && value.typeName && value instanceof t.EnumValue; + } +} + +class TraverserSerializer extends TypeSerializer { + /** @param {Traverser} item */ + serialize(item) { + return { + [typeKey]: 'g:Traverser', + [valueKey]: { + 'value': this.writer.adaptObject(item.object), + 'bulk': this.writer.adaptObject(item.bulk) + } + }; + } + + deserialize(obj) { + const value = obj[valueKey]; + return new t.Traverser(this.reader.read(value['value']), this.reader.read(value['bulk'])); + } + + canBeUsedFor(value) { + return (value instanceof t.Traverser); + } +} + +class VertexSerializer extends TypeSerializer { + deserialize(obj) { + const value = obj[valueKey]; + return new g.Vertex(this.reader.read(value['id']), value['label'], this.reader.read(value['properties'])); + } + + /** @param {Vertex} item */ + serialize(item) { + return { + [typeKey]: 'g:Vertex', + [valueKey]: { + 'id': this.writer.adaptObject(item.id), + 'label': item.label + } + }; + } + + canBeUsedFor(value) { + return (value instanceof g.Vertex); + } +} + +class VertexPropertySerializer extends TypeSerializer { + deserialize(obj) { + const value = obj[valueKey]; + return new g.VertexProperty( + this.reader.read(value['id']), + value['label'], + this.reader.read(value['value']), + this.reader.read(value['properties']) + ); + } +} + +class PropertySerializer extends TypeSerializer { + deserialize(obj) { + const value = obj[valueKey]; + return new g.Property( + value['key'], + this.reader.read(value['value'])); + } +} + +class EdgeSerializer extends TypeSerializer { + deserialize(obj) { + const value = obj[valueKey]; + return new g.Edge( + this.reader.read(value['id']), + this.reader.read(value['outV']), + value['label'], + this.reader.read(value['inV']), + this.reader.read(value['properties']) + ); + } + + /** @param {Edge} item */ + serialize(item) { + return { + [typeKey]: 'g:Edge', + [valueKey]: { + 'id': this.writer.adaptObject(item.id), + 'label': item.label, + 'outV': this.writer.adaptObject(item.outV.id), + 'outVLabel': item.outV.label, + 'inV': this.writer.adaptObject(item.inV.id), + 'inVLabel': item.inV.label + } + }; + } + + canBeUsedFor(value) { + return (value instanceof g.Edge); + } +} + +class PathSerializer extends TypeSerializer { + deserialize(obj) { + const value = obj[valueKey]; + const objects = value['objects'].map(o => this.reader.read(o)); + return new g.Path(this.reader.read(value['labels']), objects); + } +} + +module.exports = { + BytecodeSerializer, + EdgeSerializer, + EnumSerializer, + LambdaSerializer, + LongSerializer, + NumberSerializer, + PathSerializer, + PropertySerializer, + PSerializer, + TraverserSerializer, + typeKey, + valueKey, + VertexPropertySerializer, + VertexSerializer +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/utils.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/utils.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/utils.js index cbaa53e..bf87368 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/utils.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/utils.js @@ -22,9 +22,6 @@ * @author Jorge Bay Gondra */ 'use strict'; -var util = require('util'); - -exports.inherits = util.inherits; exports.parseArgs = function parseArgs() { return (arguments.length === 1 ? [ arguments[0] ] : Array.apply(null, arguments)); @@ -56,7 +53,7 @@ exports.resolvedPromise = function (promiseFactory) { }); }; -var toPromise = exports.toPromise = function toPromise(promiseFactory, handler) { +const toPromise = exports.toPromise = function toPromise(promiseFactory, handler) { promiseFactory = promiseFactory || defaultPromiseFactory; return promiseFactory(handler); }; @@ -65,7 +62,7 @@ exports.toLong = function toLong(value) { return new Long(value); }; -var Long = exports.Long = function Long(value) { +const Long = exports.Long = function Long(value) { if (typeof value !== 'string' && typeof value !== 'number') { throw new TypeError('Ty') } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js index e4895fe..9e115be 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js @@ -27,7 +27,7 @@ const Bytecode = require('../../lib/process/bytecode'); const graphModule = require('../../lib/structure/graph'); const helper = require('../helper'); -var connection; +let connection; describe('DriverRemoteConnection', function () { before(function () { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js index 7109427..01dde62 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js @@ -29,7 +29,7 @@ const Vertex = graphModule.Vertex; const utils = require('../../lib/utils'); const helper = require('../helper'); -var connection; +let connection; describe('Traversal', function () { before(function () { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js index 3864a4a..53b6577 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js @@ -22,8 +22,8 @@ */ 'use strict'; -var assert = require('assert'); -var glvModule = require('../../'); +const assert = require('assert'); +const glvModule = require('../../'); describe('API', function () { it('should export fields under process', function () { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js index ed5beb3..8bc7571 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js @@ -22,23 +22,23 @@ */ 'use strict'; -var assert = require('assert'); -var graph = require('../../lib/structure/graph'); -var t = require('../../lib/process/traversal.js'); -var gs = require('../../lib/structure/io/graph-serializer.js'); -var GraphSONReader = gs.GraphSONReader; -var GraphSONWriter = gs.GraphSONWriter; -var P = t.P; +const assert = require('assert'); +const graph = require('../../lib/structure/graph'); +const t = require('../../lib/process/traversal.js'); +const gs = require('../../lib/structure/io/graph-serializer.js'); +const GraphSONReader = gs.GraphSONReader; +const GraphSONWriter = gs.GraphSONWriter; +const P = t.P; describe('GraphSONReader', function () { it('should parse GraphSON int32, float and double to Number from GraphSON', function () { - var reader = new GraphSONReader(); + const reader = new GraphSONReader(); [ [ 'g:Int32', 31 ], [ 'g:Float', 31.3], [ 'g:Double', 31.2] ].forEach(function (item) { - var result = reader.read({ + const result = reader.read({ "@type": item[0], "@value": item[1] }); @@ -47,12 +47,12 @@ describe('GraphSONReader', function () { }); }); it('should parse vertices from GraphSON', function () { - var obj = { + const obj = { "@type":"g:Vertex", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"person", "properties":{"name":[{"id":{"@type":"g:Int64","@value":0},"value":"marko"}], "age":[{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29}}]}}}; - var reader = new GraphSONReader(obj); - var result = reader.read(obj); + const reader = new GraphSONReader(obj); + const result = reader.read(obj); assert.ok(result instanceof graph.Vertex); assert.strictEqual(result.label, 'person'); assert.strictEqual(typeof result.id, 'number'); @@ -65,7 +65,7 @@ describe('GraphSONReader', function () { assert.strictEqual(result.properties['age'][0].value, 29); }); it('should parse paths from GraphSON', function () { - var obj = {"@type":"g:Path","@value":{"labels":[["a"],["b","c"],[]],"objects":[ + const obj = {"@type":"g:Path","@value":{"labels":[["a"],["b","c"],[]],"objects":[ { "@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person", "properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0}, @@ -79,8 +79,8 @@ describe('GraphSONReader', function () { "lang":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":5}, "value":"java","label":"lang"}}]}}}, "lop"]}}; - var reader = new GraphSONReader(obj); - var result = reader.read(obj); + const reader = new GraphSONReader(obj); + const result = reader.read(obj); assert.ok(result); assert.ok(result.objects); assert.ok(result.labels); @@ -93,17 +93,17 @@ describe('GraphSONReader', function () { }); describe('GraphSONWriter', function () { it('should write numbers', function () { - var writer = new GraphSONWriter(); + const writer = new GraphSONWriter(); assert.strictEqual(writer.write(2), '2'); }); it('should write boolean values', function () { - var writer = new GraphSONWriter(); + const writer = new GraphSONWriter(); assert.strictEqual(writer.write(true), 'true'); assert.strictEqual(writer.write(false), 'false'); }); it('should write P', function () { - var writer = new GraphSONWriter(); - var expected = JSON.stringify({"@type":"g:P","@value":{"predicate":"and","value":[ + const writer = new GraphSONWriter(); + const expected = JSON.stringify({"@type":"g:P","@value":{"predicate":"and","value":[ {"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}}, {"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}}, {"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cdd114c1/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/traversal-test.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/traversal-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/traversal-test.js index 2be504b..9310143 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/traversal-test.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/traversal-test.js @@ -33,8 +33,8 @@ describe('Traversal', function () { describe('#getByteCode()', function () { it('should add steps for with a string parameter', function () { - var g = new graph.Graph().traversal(); - var bytecode = g.V().out('created').getBytecode(); + const g = new graph.Graph().traversal(); + const bytecode = g.V().out('created').getBytecode(); assert.ok(bytecode); assert.strictEqual(bytecode.sourceInstructions.length, 0); assert.strictEqual(bytecode.stepInstructions.length, 2); @@ -44,8 +44,8 @@ describe('Traversal', function () { }); it('should add steps with an enum value', function () { - var g = new graph.Graph().traversal(); - var bytecode = g.V().order().by('age', t.order.decr).getBytecode(); + const g = new graph.Graph().traversal(); + const bytecode = g.V().order().by('age', t.order.decr).getBytecode(); assert.ok(bytecode); assert.strictEqual(bytecode.sourceInstructions.length, 0); assert.strictEqual(bytecode.stepInstructions.length, 3); @@ -61,15 +61,15 @@ describe('Traversal', function () { describe('#next()', function () { it('should apply the strategies and return a Promise with the iterator item', function () { - var strategyMock = { + const strategyMock = { apply: function (traversal) { traversal.traversers = [ new t.Traverser(1, 1), new t.Traverser(2, 1) ]; return utils.resolvedPromise(); } }; - var strategies = new TraversalStrategies(); + const strategies = new TraversalStrategies(); strategies.addStrategy(strategyMock); - var traversal = new t.Traversal(null, strategies, null); + const traversal = new t.Traversal(null, strategies, null); return traversal.next() .then(function (item) { assert.strictEqual(item.value, 1); @@ -125,15 +125,15 @@ describe('Traversal', function () { describe('#toList()', function () { it('should apply the strategies and return a Promise with an array', function () { - var strategyMock = { + const strategyMock = { apply: function (traversal) { traversal.traversers = [ new t.Traverser('a', 1), new t.Traverser('b', 1) ]; return utils.resolvedPromise(); } }; - var strategies = new TraversalStrategies(); + const strategies = new TraversalStrategies(); strategies.addStrategy(strategyMock); - var traversal = new t.Traversal(null, strategies, null); + const traversal = new t.Traversal(null, strategies, null); return traversal.toList().then(function (list) { assert.ok(list); assert.deepEqual(list, [ 'a', 'b' ]); @@ -141,15 +141,15 @@ describe('Traversal', function () { }); it('should return an empty array when traversers is empty', function () { - var strategyMock = { + const strategyMock = { apply: function (traversal) { traversal.traversers = []; return utils.resolvedPromise(); } }; - var strategies = new TraversalStrategies(); + const strategies = new TraversalStrategies(); strategies.addStrategy(strategyMock); - var traversal = new t.Traversal(null, strategies, null); + const traversal = new t.Traversal(null, strategies, null); return traversal.toList().then(function (list) { assert.ok(Array.isArray(list)); assert.strictEqual(list.length, 0);