Parse Edge and VertexProperty properties To follow the decision around TINKERPOP-1474 for the GLV to parse properties.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2eb588d3 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2eb588d3 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2eb588d3 Branch: refs/heads/TINKERPOP-1489 Commit: 2eb588d343a94ca9ef4218ca6ca87eb312be10b5 Parents: ca2f349 Author: Jorge Bay Gondra <jorgebaygon...@gmail.com> Authored: Wed Nov 16 13:41:46 2016 +0100 Committer: Jorge Bay Gondra <jorgebaygon...@gmail.com> Committed: Mon Jan 8 11:28:32 2018 +0100 ---------------------------------------------------------------------- .../javascript/gremlin-javascript/structure/graph.js | 15 +++++++++++++-- .../structure/io/graph-serializer.js | 13 +++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2eb588d3/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 index 7c48819..cd408ae 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/graph.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/structure/graph.js @@ -68,10 +68,20 @@ inherits(Vertex, Element); - function Edge(id, outV, label, inV) { + function Edge(id, outV, label, inV, properties) { Element.call(this, id, label); this.outV = outV; this.inV = inV; + this.properties = {}; + (function adaptProperties(self) { + 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; + } + } + })(this); } inherits(Edge, Element); @@ -80,10 +90,11 @@ return 'e[' + this.id + '][' + this.outV.id + '-' + this.label + '->' + this.inV.id + ']'; }; - function VertexProperty(id, label, value) { + function VertexProperty(id, label, value, properties) { Element.call(this, id, label); this.value = value; this.key = this.label; + this.properties = properties; } inherits(VertexProperty, Element); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2eb588d3/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 index 2dde340..31652da 100644 --- 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 @@ -155,6 +155,9 @@ } GraphSONReader.prototype.read = function (obj) { + if (obj === undefined) { + return undefined; + } if (Array.isArray(obj)) { return obj.map(function mapEach(item) { return this.read(item); @@ -340,7 +343,12 @@ 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'])); + return new g.VertexProperty( + this.reader.read(value['id']), + value['label'], + this.reader.read(value['value']), + this.reader.read(value['properties']) + ); }; function PropertySerializer() { @@ -364,7 +372,8 @@ this.reader.read(value['id']), this.reader.read(value['outV']), value['label'], - this.reader.read(value['inV']) + this.reader.read(value['inV']), + this.reader.read(value['properties']) ); };