gremlin 3.7.4 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +1 -1
  2. package/doc/AnonymousTraversalSource.html +82 -20
  3. package/doc/Authenticator.html +2 -2
  4. package/doc/Bytecode.html +2 -2
  5. package/doc/CardinalityValue.html +6 -6
  6. package/doc/Client.html +2 -2
  7. package/doc/Connection.html +5 -5
  8. package/doc/DataType.js.html +150 -0
  9. package/doc/DriverRemoteConnection.html +2 -2
  10. package/doc/EdgeLabelVerificationStrategy.html +3 -17
  11. package/doc/Graph.html +2 -2
  12. package/doc/GraphBinaryReader.js.html +132 -0
  13. package/doc/GraphBinaryWriter.js.html +135 -0
  14. package/doc/GraphSON2Reader.html +2 -2
  15. package/doc/GraphSON2Writer.html +2 -2
  16. package/doc/GraphSON3Reader.html +2 -2
  17. package/doc/GraphSON3Writer.html +2 -2
  18. package/doc/GraphTraversal.html +667 -333
  19. package/doc/GraphTraversalSource.html +23 -174
  20. package/doc/HaltedTraverserStrategy.html +2 -2
  21. package/doc/MatchAlgorithmStrategy.html +3 -3
  22. package/doc/P.html +147 -2
  23. package/doc/PartitionStrategy.html +3 -3
  24. package/doc/Path.html +3 -3
  25. package/doc/PlainTextSaslAuthenticator.html +2 -2
  26. package/doc/ProductiveByStrategy.html +7 -37
  27. package/doc/RemoteConnection.html +2 -2
  28. package/doc/RemoteStrategy.html +2 -2
  29. package/doc/RemoteTraversal.html +2 -2
  30. package/doc/ReservedKeysVerificationStrategy.html +3 -21
  31. package/doc/ResponseError.html +2 -2
  32. package/doc/ResultSet.html +2 -2
  33. package/doc/SaslAuthenticator.html +2 -2
  34. package/doc/SaslMechanismBase.html +2 -2
  35. package/doc/SaslMechanismPlain.html +2 -2
  36. package/doc/SeedStrategy.html +3 -3
  37. package/doc/SubgraphStrategy.html +3 -3
  38. package/doc/TextP.html +12 -12
  39. package/doc/Transaction.html +2 -2
  40. package/doc/Translator.html +2 -2
  41. package/doc/TraversalStrategies.html +2 -2
  42. package/doc/TraversalStrategy.html +2 -2
  43. package/doc/TypeSerializer.html +2 -2
  44. package/doc/driver_auth_authenticator.js.html +2 -2
  45. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +2 -2
  46. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +2 -2
  47. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +2 -2
  48. package/doc/driver_auth_sasl-authenticator.js.html +2 -2
  49. package/doc/driver_client.js.html +2 -2
  50. package/doc/driver_connection.js.html +23 -9
  51. package/doc/driver_driver-remote-connection.js.html +2 -2
  52. package/doc/driver_remote-connection.js.html +2 -2
  53. package/doc/driver_response-error.js.html +2 -2
  54. package/doc/driver_result-set.js.html +2 -2
  55. package/doc/global.html +91 -3
  56. package/doc/index.html +3 -3
  57. package/doc/module.exports.html +2 -2
  58. package/doc/process_anonymous-traversal.js.html +28 -18
  59. package/doc/process_bytecode.js.html +2 -2
  60. package/doc/process_graph-traversal.js.html +41 -34
  61. package/doc/process_transaction.js.html +2 -2
  62. package/doc/process_translator.js.html +2 -2
  63. package/doc/process_traversal-strategy.js.html +95 -33
  64. package/doc/process_traversal.js.html +21 -4
  65. package/doc/structure_graph.js.html +11 -19
  66. package/doc/structure_io_binary_internals_DataType.js.html +3 -2
  67. package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +2 -2
  68. package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +2 -2
  69. package/doc/structure_io_graph-serializer.js.html +5 -3
  70. package/doc/structure_io_type-serializers.js.html +70 -8
  71. package/doc/utils.js.html +3 -3
  72. package/docker-compose.yml +2 -1
  73. package/lib/driver/connection.js +21 -7
  74. package/lib/process/anonymous-traversal.js +26 -16
  75. package/lib/process/graph-traversal.js +39 -32
  76. package/lib/process/traversal-strategy.js +93 -31
  77. package/lib/process/traversal.js +19 -2
  78. package/lib/structure/graph.js +9 -17
  79. package/lib/structure/io/binary/GraphBinary.js +3 -2
  80. package/lib/structure/io/binary/internals/AnySerializer.js +3 -0
  81. package/lib/structure/io/binary/internals/ClassSerializer.js +60 -0
  82. package/lib/structure/io/binary/internals/DataType.js +1 -0
  83. package/lib/structure/io/binary/internals/EnumSerializer.js +1 -0
  84. package/lib/structure/io/binary/internals/NumberSerializationStrategy.js +6 -1
  85. package/lib/structure/io/binary/internals/OffsetDateTimeSerializer.js +151 -0
  86. package/lib/structure/io/binary/internals/SetSerializer.js +134 -0
  87. package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +1 -6
  88. package/lib/structure/io/graph-serializer.js +3 -1
  89. package/lib/structure/io/type-serializers.js +68 -6
  90. package/lib/utils.js +1 -1
  91. package/package.json +10 -6
@@ -0,0 +1,134 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ /**
21
+ * @author Igor Ostapenko
22
+ */
23
+ 'use strict';
24
+
25
+ const { Buffer } = require('buffer');
26
+ module.exports = class SetSerializer {
27
+ constructor(ioc, ID) {
28
+ this.ioc = ioc;
29
+ this.ID = ID;
30
+ this.ioc.serializers[ID] = this;
31
+ }
32
+
33
+ canBeUsedFor(value) {
34
+ return value instanceof Set;
35
+ }
36
+
37
+ serialize(item, fullyQualifiedFormat = true) {
38
+ if (item === undefined || item === null) {
39
+ if (fullyQualifiedFormat) {
40
+ return Buffer.from([this.ID, 0x01]);
41
+ }
42
+ return Buffer.from([0x00, 0x00, 0x00, 0x00]); // {length} = 0
43
+ }
44
+
45
+ const bufs = [];
46
+ if (fullyQualifiedFormat) {
47
+ bufs.push(Buffer.from([this.ID, 0x00]));
48
+ }
49
+
50
+ // {length}
51
+ let length = item.size;
52
+ if (length < 0) {
53
+ length = 0;
54
+ }
55
+ if (length > this.ioc.intSerializer.INT32_MAX) {
56
+ throw new Error(`Set length=${length} is greater than supported max_length=${this.ioc.intSerializer.INT32_MAX}.`);
57
+ }
58
+ bufs.push(this.ioc.intSerializer.serialize(length, false));
59
+
60
+ // {item_0}...{item_n}
61
+ for (const i of item) {
62
+ bufs.push(this.ioc.anySerializer.serialize(i));
63
+ }
64
+
65
+ return Buffer.concat(bufs);
66
+ }
67
+
68
+ deserialize(buffer, fullyQualifiedFormat = true) {
69
+ let len = 0;
70
+ let cursor = buffer;
71
+
72
+ try {
73
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
74
+ throw new Error('buffer is missing');
75
+ }
76
+ if (buffer.length < 1) {
77
+ throw new Error('buffer is empty');
78
+ }
79
+
80
+ if (fullyQualifiedFormat) {
81
+ const typeCode = cursor.readUInt8();
82
+ len++;
83
+ if (typeCode !== this.ID) {
84
+ throw new Error('unexpected {type_code}');
85
+ }
86
+ cursor = cursor.slice(1);
87
+
88
+ if (cursor.length < 1) {
89
+ throw new Error('{value_flag} is missing');
90
+ }
91
+ const valueFlag = cursor.readUInt8();
92
+ len++;
93
+ if (valueFlag === 1) {
94
+ return { v: null, len };
95
+ }
96
+ if (valueFlag !== 0) {
97
+ throw new Error('unexpected {value_flag}');
98
+ }
99
+ cursor = cursor.slice(1);
100
+ }
101
+
102
+ let length, lengthLen;
103
+ try {
104
+ ({ v: length, len: lengthLen } = this.ioc.intSerializer.deserialize(cursor, false));
105
+ len += lengthLen;
106
+ } catch (err) {
107
+ err.message = '{length}: ' + err.message;
108
+ throw err;
109
+ }
110
+ if (length < 0) {
111
+ throw new Error('{length} is less than zero');
112
+ }
113
+ cursor = cursor.slice(lengthLen);
114
+
115
+ const v = new Set();
116
+ for (let i = 0; i < length; i++) {
117
+ let value, valueLen;
118
+ try {
119
+ ({ v: value, len: valueLen } = this.ioc.anySerializer.deserialize(cursor));
120
+ len += valueLen;
121
+ } catch (err) {
122
+ err.message = `{item_${i}}: ` + err.message;
123
+ throw err;
124
+ }
125
+ cursor = cursor.slice(valueLen);
126
+ v.add(value);
127
+ }
128
+
129
+ return { v, len };
130
+ } catch (err) {
131
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
132
+ }
133
+ }
134
+ };
@@ -29,7 +29,6 @@ const { TraversalStrategySerializer: GraphsonTraversalStrategySerializer } = req
29
29
  module.exports = class TraversalStrategySerializer {
30
30
  constructor(ioc) {
31
31
  this.ioc = ioc;
32
- // this.ioc.serializers[ioc.DataType.TRAVERSALSTRATEGY] = this; // TODO: it's not expected to be deserialized
33
32
  this.graphsonTraversalStrategySerializer = new GraphsonTraversalStrategySerializer();
34
33
  }
35
34
 
@@ -45,8 +44,6 @@ module.exports = class TraversalStrategySerializer {
45
44
  const strategy_class = [0x00, 0x00, 0x00, 0x00]; // ''
46
45
  const configuration = [0x00, 0x00, 0x00, 0x00]; // {}
47
46
  return Buffer.from([...strategy_class, ...configuration]);
48
- // TODO: should we delegate these to respective serializers like classSerializer.serialize(undefined, false) ?
49
- // Consider to make it the same way for all other serializers
50
47
  }
51
48
 
52
49
  const bufs = [];
@@ -54,8 +51,6 @@ module.exports = class TraversalStrategySerializer {
54
51
  bufs.push(Buffer.from([this.ioc.DataType.TRAVERSALSTRATEGY, 0x00]));
55
52
  }
56
53
 
57
- // let's repeat the logic of Graphson's TraversalStrategySerializer:
58
- const strategy_class = item.fqcn;
59
54
  const conf = {};
60
55
  for (const k in item.configuration) {
61
56
  if (item.configuration.hasOwnProperty(k)) {
@@ -64,7 +59,7 @@ module.exports = class TraversalStrategySerializer {
64
59
  }
65
60
 
66
61
  // {strategy_class}
67
- bufs.push(this.ioc.classSerializer.serialize(strategy_class, false));
62
+ bufs.push(this.ioc.classSerializer.serialize(item.constructor, false));
68
63
 
69
64
  // {configuration}
70
65
  bufs.push(this.ioc.mapSerializer.serialize(conf, false));
@@ -253,6 +253,7 @@ const graphSON2Deserializers = {
253
253
  'g:Float': typeSerializers.NumberSerializer,
254
254
  'g:Double': typeSerializers.NumberSerializer,
255
255
  'g:Date': typeSerializers.DateSerializer,
256
+ 'gx:OffsetDateTime': typeSerializers.OffsetDateTimeSerializer,
256
257
  'g:Direction': typeSerializers.DirectionSerializer,
257
258
  'g:Vertex': typeSerializers.VertexSerializer,
258
259
  'g:Edge': typeSerializers.EdgeSerializer,
@@ -272,12 +273,13 @@ const graphSON3Deserializers = Object.assign({}, graphSON2Deserializers, {
272
273
 
273
274
  const graphSON2Serializers = [
274
275
  typeSerializers.NumberSerializer,
275
- typeSerializers.DateSerializer,
276
+ typeSerializers.OffsetDateTimeSerializer,
276
277
  typeSerializers.BytecodeSerializer,
277
278
  typeSerializers.TraverserSerializer,
278
279
  typeSerializers.TraversalStrategySerializer,
279
280
  typeSerializers.PSerializer,
280
281
  typeSerializers.TextPSerializer,
282
+ typeSerializers.ClassSerializer,
281
283
  typeSerializers.LambdaSerializer,
282
284
  typeSerializers.EnumSerializer,
283
285
  typeSerializers.VertexSerializer,
@@ -87,10 +87,18 @@ class NumberSerializer extends TypeSerializer {
87
87
  }
88
88
 
89
89
  class DateSerializer extends TypeSerializer {
90
+ // only deserialize g:Date objects
91
+ deserialize(obj) {
92
+ return new Date(obj[valueKey]);
93
+ }
94
+ }
95
+
96
+ class OffsetDateTimeSerializer extends TypeSerializer {
97
+ // Date objects are serialized as OffsetDateTime by default
90
98
  serialize(item) {
91
99
  return {
92
- [typeKey]: 'g:Date',
93
- [valueKey]: item.getTime(),
100
+ [typeKey]: 'gx:OffsetDateTime',
101
+ [valueKey]: item.toISOString(),
94
102
  };
95
103
  }
96
104
 
@@ -103,6 +111,24 @@ class DateSerializer extends TypeSerializer {
103
111
  }
104
112
  }
105
113
 
114
+ class ClassSerializer extends TypeSerializer {
115
+ serialize(item) {
116
+ return {
117
+ [typeKey]: 'g:Class',
118
+ [valueKey]: new item().fqcn,
119
+ };
120
+ }
121
+
122
+ canBeUsedFor(value) {
123
+ return (
124
+ typeof value === 'function' &&
125
+ !!value.prototype &&
126
+ !!value.prototype.constructor.name &&
127
+ new value() instanceof ts.TraversalStrategy
128
+ );
129
+ }
130
+ }
131
+
106
132
  class LongSerializer extends TypeSerializer {
107
133
  serialize(item) {
108
134
  return {
@@ -276,7 +302,7 @@ class TraversalStrategySerializer extends TypeSerializer {
276
302
 
277
303
  return {
278
304
  [typeKey]: 'g:' + item.constructor.name,
279
- [valueKey]: conf,
305
+ [valueKey]: { ['fqcn']: item.fqcn, ['conf']: conf },
280
306
  };
281
307
  }
282
308
 
@@ -285,10 +311,29 @@ class TraversalStrategySerializer extends TypeSerializer {
285
311
  }
286
312
  }
287
313
 
314
+ /**
315
+ * Helper function to deserialize properties into arrays of VertexProperty or Property according to graphSONV3.
316
+ */
317
+ function deserializeProperties(value, reader) {
318
+ let properties = [];
319
+ if ('properties' in value) {
320
+ const props = reader.read(value['properties']);
321
+ if (props !== null && props !== undefined) {
322
+ properties = Object.entries(props).flatMap(([key, values]) => {
323
+ if (Array.isArray(values) && values.length > 0 && values[0] instanceof g.VertexProperty) {
324
+ return values; // Flatten VertexProperty arrays
325
+ }
326
+ return values instanceof g.Property ? values : new g.Property(key, values); // create Property object when needed
327
+ });
328
+ }
329
+ }
330
+ return properties;
331
+ }
332
+
288
333
  class VertexSerializer extends TypeSerializer {
289
334
  deserialize(obj) {
290
335
  const value = obj[valueKey];
291
- return new g.Vertex(this.reader.read(value['id']), value['label'], this.reader.read(value['properties']));
336
+ return new g.Vertex(this.reader.read(value['id']), value['label'], deserializeProperties(value, this.reader));
292
337
  }
293
338
 
294
339
  /** @param {Vertex} item */
@@ -314,7 +359,7 @@ class VertexPropertySerializer extends TypeSerializer {
314
359
  this.reader.read(value['id']),
315
360
  value['label'],
316
361
  this.reader.read(value['value']),
317
- this.reader.read(value['properties']),
362
+ deserializeProperties(value, this.reader),
318
363
  );
319
364
  }
320
365
  }
@@ -334,7 +379,7 @@ class EdgeSerializer extends TypeSerializer {
334
379
  new g.Vertex(this.reader.read(value['outV']), this.reader.read(value['outVLabel'])),
335
380
  value['label'],
336
381
  new g.Vertex(this.reader.read(value['inV']), this.reader.read(value['inVLabel'])),
337
- this.reader.read(value['properties']),
382
+ deserializeProperties(value, this.reader),
338
383
  );
339
384
  }
340
385
 
@@ -474,12 +519,29 @@ class SetSerializer extends ArraySerializer {
474
519
  constructor() {
475
520
  super('g:Set');
476
521
  }
522
+
523
+ deserialize(obj) {
524
+ return new Set(super.deserialize(obj));
525
+ }
526
+
527
+ serialize(item) {
528
+ return {
529
+ [typeKey]: this.typeKey,
530
+ [valueKey]: [...item].map((x) => this.writer.adaptObject(x)),
531
+ };
532
+ }
533
+
534
+ canBeUsedFor(value) {
535
+ return value instanceof Set;
536
+ }
477
537
  }
478
538
 
479
539
  module.exports = {
480
540
  BulkSetSerializer,
481
541
  BytecodeSerializer,
542
+ ClassSerializer,
482
543
  DateSerializer,
544
+ OffsetDateTimeSerializer,
483
545
  DirectionSerializer,
484
546
  EdgeSerializer,
485
547
  EnumSerializer,
package/lib/utils.js CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  const uuid = require('uuid');
27
27
 
28
- const gremlinVersion = '3.7.4'; // DO NOT MODIFY - Configured automatically by Maven Replacer Plugin
28
+ const gremlinVersion = '3.8.0'; // DO NOT MODIFY - Configured automatically by Maven Replacer Plugin
29
29
 
30
30
  exports.toLong = function toLong(value) {
31
31
  return new Long(value);
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "gremlin",
3
- "version": "3.7.4",
3
+ "version": "3.8.0",
4
4
  "description": "JavaScript Gremlin Language Variant",
5
- "author": "Apache TinkerPop team",
5
+ "author": {
6
+ "name": "Apache TinkerPop team"
7
+ },
6
8
  "keywords": [
7
9
  "graph",
8
10
  "gremlin",
9
11
  "tinkerpop",
12
+ "apache-tinkerpop",
10
13
  "connection",
11
14
  "glv",
12
15
  "driver",
16
+ "database",
13
17
  "graphdb"
14
18
  ],
15
19
  "license": "Apache-2.0",
@@ -51,11 +55,11 @@
51
55
  "integration-test-graphbinary": "cross-env CLIENT_MIMETYPE='application/vnd.graphbinary-v1.0' ./node_modules/mocha/bin/mocha.js test/integration -t 5000",
52
56
  "TODO": "# test other mime types like graphbinary stringd",
53
57
  "features": "npm run features-graphson30 && npm run features-graphbinary",
54
- "features-graphson30": "cross-env CLIENT_MIMETYPE='application/vnd.gremlin-v3.0+json' cucumber-js --require test/cucumber ../../../../../gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/",
55
- "features-graphbinary": "cross-env CLIENT_MIMETYPE='application/vnd.graphbinary-v1.0' cucumber-js --require test/cucumber ../../../../../gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/",
58
+ "features-graphson30": "cross-env CLIENT_MIMETYPE='application/vnd.gremlin-v3.0+json' cucumber-js --tags \"not @DataUUID and not @DataLong\" --require test/cucumber ../../../../../gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/",
59
+ "features-graphbinary": "cross-env CLIENT_MIMETYPE='application/vnd.graphbinary-v1.0' cucumber-js --tags \"not @DataBigDecimal and not @DataBigInt and not @DataUUID and not @DataLong\" --require test/cucumber ../../../../../gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/",
56
60
  "features-docker": "npm run features-graphson30-docker && npm run features-graphbinary-docker",
57
- "features-graphson30-docker": "cross-env CLIENT_MIMETYPE='application/vnd.gremlin-v3.0+json' cucumber-js --require test/cucumber ../gremlin-test/",
58
- "features-graphbinary-docker": "cross-env CLIENT_MIMETYPE='application/vnd.graphbinary-v1.0' cucumber-js --require test/cucumber ../gremlin-test/",
61
+ "features-graphson30-docker": "cross-env CLIENT_MIMETYPE='application/vnd.gremlin-v3.0+json' cucumber-js --tags \"not @DataUUID and not @DataLong\" --require test/cucumber ../gremlin-test/",
62
+ "features-graphbinary-docker": "cross-env CLIENT_MIMETYPE='application/vnd.graphbinary-v1.0' cucumber-js --tags \"not @DataBigDecimal and not @DataBigInt and not @DataUUID and not @DataLong\" --require test/cucumber ../gremlin-test/",
59
63
  "lint": "eslint --ext .js ."
60
64
  },
61
65
  "engines": {