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
@@ -102,7 +102,7 @@ class HaltedTraverserStrategy extends TraversalStrategy {
102
102
  /**
103
103
  * @param {String} haltedTraverserFactory full qualified class name in Java of a {@code HaltedTraverserFactory} implementation
104
104
  */
105
- constructor(haltedTraverserFactory) {
105
+ constructor({ haltedTraverserFactory } = {}) {
106
106
  super('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy');
107
107
  if (haltedTraverserFactory !== undefined) {
108
108
  this.configuration['haltedTraverserFactory'] = haltedTraverserFactory;
@@ -110,9 +110,20 @@ class HaltedTraverserStrategy extends TraversalStrategy {
110
110
  }
111
111
  }
112
112
 
113
+ class MessagePassingReductionStrategy extends TraversalStrategy {
114
+ constructor() {
115
+ super(
116
+ 'org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.optimization.MessagePassingReductionStrategy',
117
+ );
118
+ }
119
+ }
120
+
113
121
  class OptionsStrategy extends TraversalStrategy {
114
122
  constructor(options) {
115
- super('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy', options);
123
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy');
124
+ if (options !== undefined) {
125
+ this.configuration = options;
126
+ }
116
127
  }
117
128
  }
118
129
 
@@ -129,6 +140,24 @@ class PartitionStrategy extends TraversalStrategy {
129
140
  }
130
141
  }
131
142
 
143
+ class ProfileStrategy extends TraversalStrategy {
144
+ constructor() {
145
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.ProfileStrategy');
146
+ }
147
+ }
148
+
149
+ class SeedStrategy extends TraversalStrategy {
150
+ /**
151
+ * @param {Object} [options]
152
+ * @param {number} [options.seed] the seed to provide to the random number generator for the traversal
153
+ */
154
+ constructor(options) {
155
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SeedStrategy', {
156
+ seed: options?.seed,
157
+ });
158
+ }
159
+ }
160
+
132
161
  class SubgraphStrategy extends TraversalStrategy {
133
162
  /**
134
163
  * @param {Object} [options]
@@ -151,13 +180,9 @@ class SubgraphStrategy extends TraversalStrategy {
151
180
  }
152
181
  }
153
182
 
154
- class ProductiveByStrategy extends TraversalStrategy {
155
- /**
156
- * @param {Object} [options]
157
- * @param {Array<String>} [options.productiveKeys] set of keys that will always be productive
158
- */
159
- constructor(options) {
160
- super('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.ProductiveByStrategy', options);
183
+ class ReferenceElementStrategy extends TraversalStrategy {
184
+ constructor() {
185
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.ReferenceElementStrategy');
161
186
  }
162
187
  }
163
188
 
@@ -171,7 +196,7 @@ class MatchAlgorithmStrategy extends TraversalStrategy {
171
196
  /**
172
197
  * @param matchAlgorithm
173
198
  */
174
- constructor(matchAlgorithm) {
199
+ constructor({ matchAlgorithm } = {}) {
175
200
  super('org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.MatchAlgorithmStrategy');
176
201
  if (matchAlgorithm !== undefined) {
177
202
  this.configuration['matchAlgorithm'] = matchAlgorithm;
@@ -179,12 +204,24 @@ class MatchAlgorithmStrategy extends TraversalStrategy {
179
204
  }
180
205
  }
181
206
 
207
+ class ComputerFinalizationStrategy extends TraversalStrategy {
208
+ constructor() {
209
+ super('org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.finalization.ComputerFinalizationStrategy');
210
+ }
211
+ }
212
+
182
213
  class AdjacentToIncidentStrategy extends TraversalStrategy {
183
214
  constructor() {
184
215
  super('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.AdjacentToIncidentStrategy');
185
216
  }
186
217
  }
187
218
 
219
+ class ByModulatorOptimizationStrategy extends TraversalStrategy {
220
+ constructor() {
221
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.ByModulatorOptimizationStrategy');
222
+ }
223
+ }
224
+
188
225
  class FilterRankingStrategy extends TraversalStrategy {
189
226
  constructor() {
190
227
  super('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.FilterRankingStrategy');
@@ -239,6 +276,17 @@ class PathRetractionStrategy extends TraversalStrategy {
239
276
  }
240
277
  }
241
278
 
279
+ class ProductiveByStrategy extends TraversalStrategy {
280
+ /**
281
+ * @param {Object} [options]
282
+ * @param {Array<String>} productiveKeys set of keys that will always be productive
283
+ */
284
+ constructor({ productiveKeys = [] } = {}) {
285
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.ProductiveByStrategy');
286
+ this.configuration['productiveKeys'] = productiveKeys;
287
+ }
288
+ }
289
+
242
290
  class CountStrategy extends TraversalStrategy {
243
291
  constructor() {
244
292
  super('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.CountStrategy');
@@ -253,7 +301,7 @@ class RepeatUnrollStrategy extends TraversalStrategy {
253
301
 
254
302
  class GraphFilterStrategy extends TraversalStrategy {
255
303
  constructor() {
256
- super('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.GraphFilterStrategy');
304
+ super('org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.optimization.GraphFilterStrategy');
257
305
  }
258
306
  }
259
307
 
@@ -263,6 +311,12 @@ class EarlyLimitStrategy extends TraversalStrategy {
263
311
  }
264
312
  }
265
313
 
314
+ class ComputerVerificationStrategy extends TraversalStrategy {
315
+ constructor() {
316
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ComputerVerificationStrategy');
317
+ }
318
+ }
319
+
266
320
  class LambdaRestrictionStrategy extends TraversalStrategy {
267
321
  constructor() {
268
322
  super('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.LambdaRestrictionStrategy');
@@ -280,11 +334,10 @@ class EdgeLabelVerificationStrategy extends TraversalStrategy {
280
334
  * @param {boolean} logWarnings determines if warnings should be written to the logger when verification fails
281
335
  * @param {boolean} throwException determines if exceptions should be thrown when verifications fails
282
336
  */
283
- constructor(logWarnings = false, throwException = false) {
284
- super('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.EdgeLabelVerificationStrategy', {
285
- logWarnings: logWarnings,
286
- throwException: throwException,
287
- });
337
+ constructor({ logWarnings = false, throwException = false } = {}) {
338
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.EdgeLabelVerificationStrategy');
339
+ this.configuration['logWarnings'] = logWarnings;
340
+ this.configuration['throwException'] = throwException;
288
341
  }
289
342
  }
290
343
 
@@ -294,24 +347,25 @@ class ReservedKeysVerificationStrategy extends TraversalStrategy {
294
347
  * @param {boolean} throwException determines if exceptions should be thrown when verifications fails
295
348
  * @param {Array<String>} keys the list of reserved keys to verify
296
349
  */
297
- constructor(logWarnings = false, throwException = false, keys = ['id', 'label']) {
298
- super('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReservedKeysVerificationStrategy', {
299
- logWarnings: logWarnings,
300
- throwException: throwException,
301
- keys: keys,
302
- });
350
+ constructor({ logWarnings = false, throwException = false, keys = ['id', 'label'] } = {}) {
351
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReservedKeysVerificationStrategy');
352
+ this.configuration['logWarnings'] = logWarnings;
353
+ this.configuration['throwException'] = throwException;
354
+ this.configuration['keys'] = keys;
303
355
  }
304
356
  }
305
357
 
306
- class SeedStrategy extends TraversalStrategy {
307
- /**
308
- * @param {Object} [options]
309
- * @param {number} [options.seed] the seed to provide to the random number generator for the traversal
310
- */
311
- constructor(options) {
312
- super('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SeedStrategy', {
313
- seed: options.seed,
314
- });
358
+ class VertexProgramRestrictionStrategy extends TraversalStrategy {
359
+ constructor() {
360
+ super(
361
+ 'org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.verification.VertexProgramRestrictionStrategy',
362
+ );
363
+ }
364
+ }
365
+
366
+ class StandardVerificationStrategy extends TraversalStrategy {
367
+ constructor() {
368
+ super('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.StandardVerificationStrategy');
315
369
  }
316
370
  }
317
371
 
@@ -319,11 +373,15 @@ module.exports = {
319
373
  TraversalStrategies: TraversalStrategies,
320
374
  TraversalStrategy: TraversalStrategy,
321
375
  // decoration
376
+ ComputerFinalizationStrategy: ComputerFinalizationStrategy,
322
377
  ConnectiveStrategy: ConnectiveStrategy,
323
378
  ElementIdStrategy: ElementIdStrategy,
324
379
  HaltedTraverserStrategy: HaltedTraverserStrategy,
380
+ MessagePassingReductionStrategy: MessagePassingReductionStrategy,
325
381
  OptionsStrategy: OptionsStrategy,
326
382
  PartitionStrategy: PartitionStrategy,
383
+ ProfileStrategy: ProfileStrategy,
384
+ ReferenceElementStrategy: ReferenceElementStrategy,
327
385
  SeedStrategy: SeedStrategy,
328
386
  SubgraphStrategy: SubgraphStrategy,
329
387
  VertexProgramStrategy: VertexProgramStrategy,
@@ -331,6 +389,7 @@ module.exports = {
331
389
  MatchAlgorithmStrategy: MatchAlgorithmStrategy,
332
390
  // optimization
333
391
  AdjacentToIncidentStrategy: AdjacentToIncidentStrategy,
392
+ ByModulatorOptimizationStrategy: ByModulatorOptimizationStrategy,
334
393
  FilterRankingStrategy: FilterRankingStrategy,
335
394
  IdentityRemovalStrategy: IdentityRemovalStrategy,
336
395
  IncidentToAdjacentStrategy: IncidentToAdjacentStrategy,
@@ -346,8 +405,11 @@ module.exports = {
346
405
  GraphFilterStrategy: GraphFilterStrategy,
347
406
  EarlyLimitStrategy: EarlyLimitStrategy,
348
407
  // verification
408
+ ComputerVerificationStrategy: ComputerVerificationStrategy,
349
409
  EdgeLabelVerificationStrategy: EdgeLabelVerificationStrategy,
350
410
  LambdaRestrictionStrategy: LambdaRestrictionStrategy,
351
411
  ReadOnlyStrategy: ReadOnlyStrategy,
352
412
  ReservedKeysVerificationStrategy: ReservedKeysVerificationStrategy,
413
+ StandardVerificationStrategy: StandardVerificationStrategy,
414
+ VertexProgramRestrictionStrategy: VertexProgramRestrictionStrategy,
353
415
  };
@@ -84,7 +84,7 @@ class Traversal {
84
84
  * @returns {Promise}
85
85
  */
86
86
  iterate() {
87
- this.bytecode.addStep('none');
87
+ this.bytecode.addStep('discard');
88
88
  return this._applyStrategies().then(() => {
89
89
  let it;
90
90
  while ((it = this._getNext()) && !it.done) {
@@ -345,6 +345,11 @@ class P {
345
345
  return createP('outside', args);
346
346
  }
347
347
 
348
+ /** @param {...Object} args */
349
+ static typeOf(...args) {
350
+ return createP('typeOf', args);
351
+ }
352
+
348
353
  /** @param {...Object} args */
349
354
  static test(...args) {
350
355
  return createP('test', args);
@@ -487,6 +492,14 @@ function toDirectionEnum(typeName, keys) {
487
492
  return result;
488
493
  }
489
494
 
495
+ function toGTypeEnum(typeName, keys) {
496
+ const result = {};
497
+ keys.split(' ').forEach((k) => {
498
+ result[k] = new EnumValue(typeName, k.toUpperCase());
499
+ });
500
+ return result;
501
+ }
502
+
490
503
  class EnumValue {
491
504
  constructor(typeName, elementName) {
492
505
  this.typeName = typeName;
@@ -512,12 +525,16 @@ module.exports = {
512
525
  column: toEnum('Column', 'keys values'),
513
526
  direction: toDirectionEnum('Direction', 'BOTH IN OUT from_ to'),
514
527
  dt: toEnum('DT', 'second minute hour day'),
528
+ gType: toGTypeEnum(
529
+ 'GType',
530
+ 'bigDecimal bigInt binary boolean byte char datetime double duration edge float graph int list long map null number path property set short string tree uuid vertex vproperty',
531
+ ),
515
532
  graphSONVersion: toEnum('GraphSONVersion', 'V1_0 V2_0 V3_0'),
516
533
  gryoVersion: toEnum('GryoVersion', 'V1_0 V3_0'),
517
534
  merge: toEnum('Merge', 'onCreate onMatch outV inV'),
518
535
  operator: toEnum('Operator', 'addAll and assign div max min minus mult or sum sumLong'),
519
536
  order: toEnum('Order', 'asc desc shuffle'),
520
- pick: toEnum('Pick', 'any none'),
537
+ pick: toEnum('Pick', 'any none unproductive'),
521
538
  pop: toEnum('Pop', 'all first last mixed'),
522
539
  scope: toEnum('Scope', 'global local'),
523
540
  t: toEnum('T', 'id key label value'),
@@ -46,9 +46,11 @@ class Graph {
46
46
  }
47
47
 
48
48
  class Element {
49
- constructor(id, label) {
49
+ // properties are stored as list of property objects
50
+ constructor(id, label, properties = []) {
50
51
  this.id = id;
51
52
  this.label = label;
53
+ this.properties = properties != null ? properties : [];
52
54
  }
53
55
 
54
56
  /**
@@ -62,9 +64,8 @@ class Element {
62
64
  }
63
65
 
64
66
  class Vertex extends Element {
65
- constructor(id, label, properties) {
66
- super(id, label);
67
- this.properties = properties;
67
+ constructor(id, label, properties = []) {
68
+ super(id, label, properties);
68
69
  }
69
70
 
70
71
  toString() {
@@ -73,18 +74,10 @@ class Vertex extends Element {
73
74
  }
74
75
 
75
76
  class Edge extends Element {
76
- constructor(id, outV, label, inV, properties) {
77
- super(id, label);
77
+ constructor(id, outV, label, inV, properties = []) {
78
+ super(id, label, properties);
78
79
  this.outV = outV;
79
80
  this.inV = inV;
80
- this.properties = {};
81
- if (properties) {
82
- const keys = Object.keys(properties);
83
- for (let i = 0; i < keys.length; i++) {
84
- const k = keys[i];
85
- this.properties[k] = properties[k].value;
86
- }
87
- }
88
81
  }
89
82
 
90
83
  toString() {
@@ -96,11 +89,10 @@ class Edge extends Element {
96
89
  }
97
90
 
98
91
  class VertexProperty extends Element {
99
- constructor(id, label, value, properties) {
100
- super(id, label);
92
+ constructor(id, label, value, properties = []) {
93
+ super(id, label, properties);
101
94
  this.value = value;
102
95
  this.key = this.label;
103
- this.properties = properties;
104
96
  }
105
97
 
106
98
  toString() {
@@ -71,14 +71,15 @@ ioc.intSerializer = new (require('./internals/IntSerializer'))(ioc
71
71
  ioc.longSerializer = new (require('./internals/LongSerializer'))(ioc);
72
72
  ioc.longSerializerNg = new (require('./internals/LongSerializerNg'))(ioc);
73
73
  ioc.stringSerializer = new (require('./internals/StringSerializer'))(ioc, ioc.DataType.STRING);
74
+ ioc.offsetDateTimeSerializer = new (require('./internals/OffsetDateTimeSerializer'))(ioc, ioc.DataType.OFFSETDATETIME);
74
75
  ioc.dateSerializer = new (require('./internals/DateSerializer'))(ioc, ioc.DataType.DATE);
75
76
  ioc.timestampSerializer = new (require('./internals/DateSerializer'))(ioc, ioc.DataType.TIMESTAMP);
76
- ioc.classSerializer = new (require('./internals/StringSerializer'))(ioc, ioc.DataType.CLASS);
77
+ ioc.classSerializer = new (require('./internals/ClassSerializer'))(ioc);
77
78
  ioc.doubleSerializer = new (require('./internals/DoubleSerializer'))(ioc);
78
79
  ioc.floatSerializer = new (require('./internals/FloatSerializer'))(ioc);
79
80
  ioc.listSerializer = new (require('./internals/ArraySerializer'))(ioc, ioc.DataType.LIST);
80
81
  ioc.mapSerializer = new (require('./internals/MapSerializer'))(ioc);
81
- ioc.setSerializer = new (require('./internals/ArraySerializer'))(ioc, ioc.DataType.SET);
82
+ ioc.setSerializer = new (require('./internals/SetSerializer'))(ioc, ioc.DataType.SET);
82
83
  ioc.uuidSerializer = new (require('./internals/UuidSerializer'))(ioc);
83
84
  ioc.edgeSerializer = new (require('./internals/EdgeSerializer'))(ioc);
84
85
  ioc.pathSerializer = new (require('./internals/PathSerializer'))(ioc);
@@ -35,11 +35,13 @@ module.exports = class AnySerializer {
35
35
  ioc.numberSerializationStrategy,
36
36
 
37
37
  ioc.booleanSerializer,
38
+ ioc.offsetDateTimeSerializer,
38
39
  ioc.dateSerializer,
39
40
  ioc.bytecodeSerializer,
40
41
  ioc.pSerializer,
41
42
  ioc.traverserSerializer,
42
43
  ioc.enumSerializer,
44
+ ioc.setSerializer,
43
45
  ioc.listSerializer,
44
46
  ioc.uuidSerializer,
45
47
  ioc.edgeSerializer,
@@ -47,6 +49,7 @@ module.exports = class AnySerializer {
47
49
  ioc.propertySerializer,
48
50
  ioc.vertexSerializer,
49
51
  ioc.vertexPropertySerializer,
52
+ ioc.classSerializer,
50
53
  ioc.stringSerializer,
51
54
  ioc.textPSerializer,
52
55
  ioc.traversalStrategySerializer,
@@ -0,0 +1,60 @@
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
+ 'use strict';
21
+
22
+ const { TraversalStrategy } = require('../../../../process/traversal-strategy');
23
+ const { Buffer } = require('buffer');
24
+
25
+ module.exports = class ClassSerializer {
26
+ constructor(ioc) {
27
+ this.ioc = ioc;
28
+ this.ioc.serializers[ioc.DataType.CLASS] = this;
29
+ }
30
+
31
+ canBeUsedFor(value) {
32
+ return (
33
+ typeof value === 'function' &&
34
+ !!value.prototype &&
35
+ !!value.prototype.constructor.name &&
36
+ new value() instanceof TraversalStrategy
37
+ );
38
+ }
39
+
40
+ serialize(item, fullyQualifiedFormat = true) {
41
+ if (item === undefined || item === null) {
42
+ if (fullyQualifiedFormat) {
43
+ return Buffer.from([this.ioc.DataType.CLASS, 0x01]);
44
+ }
45
+ return this.ioc.intSerializer.serialize(0, false);
46
+ }
47
+
48
+ const bufs = [];
49
+ if (fullyQualifiedFormat) {
50
+ bufs.push(Buffer.from([this.ioc.DataType.CLASS, 0x00]));
51
+ }
52
+
53
+ const fqcn = new item().fqcn;
54
+ const v = Buffer.from(fqcn, 'utf8');
55
+ bufs.push(this.ioc.intSerializer.serialize(fqcn.length, false));
56
+ bufs.push(v);
57
+
58
+ return Buffer.concat(bufs);
59
+ }
60
+ };
@@ -75,6 +75,7 @@ const DataType = {
75
75
  TRAVERSALMETRICS: 0x2d,
76
76
  MERGE: 0x2e,
77
77
  DT: 0x2f,
78
+ GTYPE: 0x30,
78
79
 
79
80
  CHAR: 0x80,
80
81
  DURATION: 0x81,
@@ -43,6 +43,7 @@ module.exports = class EnumSerializer {
43
43
  { name: 'Column', code: DT.COLUMN, enum: to_orig_enum(t.column) },
44
44
  { name: 'Direction', code: DT.DIRECTION, enum: to_orig_enum(t.direction) },
45
45
  { name: 'DT', code: DT.DT, enum: to_orig_enum(t.dt) },
46
+ { name: 'GType', code: DT.GTYPE, enum: to_orig_enum(t.gType) },
46
47
  { name: 'Merge', code: DT.MERGE, enum: to_orig_enum(t.merge) },
47
48
  { name: 'Operator', code: DT.OPERATOR, enum: to_orig_enum(t.operator) },
48
49
  { name: 'Order', code: DT.ORDER, enum: to_orig_enum(t.order) },
@@ -58,7 +58,12 @@ module.exports = class NumberSerializationStrategy {
58
58
  // INT32_MIN/MAX
59
59
  return this.ioc.intSerializer.serialize(item, fullyQualifiedFormat);
60
60
  }
61
- return this.ioc.longSerializer.serialize(item, fullyQualifiedFormat);
61
+ // eslint-disable-next-line no-loss-of-precision
62
+ if (item >= -9223372036854775808 && item < 9223372036854775807) {
63
+ // INT64_MIN/MAX
64
+ return this.ioc.longSerializer.serialize(item, fullyQualifiedFormat);
65
+ }
66
+ return this.ioc.doubleSerializer.serialize(item, fullyQualifiedFormat);
62
67
  }
63
68
 
64
69
  if (typeof item === 'bigint') {
@@ -0,0 +1,151 @@
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
+ 'use strict';
21
+
22
+ const { Buffer } = require('buffer');
23
+
24
+ module.exports = class OffsetDateTimeSerializer {
25
+ constructor(ioc, ID) {
26
+ this.ioc = ioc;
27
+ this.ID = ID;
28
+ this.ioc.serializers[ID] = this;
29
+ }
30
+
31
+ canBeUsedFor(value) {
32
+ return value instanceof Date;
33
+ }
34
+
35
+ serialize(item, fullyQualifiedFormat = true) {
36
+ if (item === undefined || item === null) {
37
+ if (fullyQualifiedFormat) {
38
+ return Buffer.from([this.ID, 0x01]);
39
+ }
40
+ return Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
41
+ }
42
+
43
+ const bufs = [];
44
+ if (fullyQualifiedFormat) {
45
+ bufs.push(Buffer.from([this.ID, 0x00]));
46
+ }
47
+
48
+ // NOTE: js Date will always display time in UTC, but regular date/hour getters will return in local system time.
49
+ // To avoid inconsistency we will always serialize the UTC representation of the Date object with offset of 0.
50
+
51
+ // {year}
52
+ let v = Buffer.alloc(4);
53
+ v.writeInt32BE(item.getUTCFullYear());
54
+ bufs.push(v);
55
+
56
+ // {month}
57
+ v = Buffer.alloc(1);
58
+ v.writeUInt8(item.getUTCMonth() + 1); // Java Core DateTime serializer uses 1 - 12 for months, JS uses indices
59
+ bufs.push(v);
60
+
61
+ // {day} - in UTC
62
+ v = Buffer.alloc(1);
63
+ v.writeUInt8(item.getUTCDate());
64
+ bufs.push(v);
65
+
66
+ // {nanoseconds}
67
+ const h = item.getUTCHours(); // in UTC
68
+ const m = item.getUTCMinutes();
69
+ const s = item.getUTCSeconds();
70
+ const ms = item.getUTCMilliseconds();
71
+ const ns = h * 60 * 60 * 1e9 + m * 60 * 1e9 + s * 1e9 + ms * 1e6;
72
+ v = Buffer.alloc(8);
73
+ v.writeBigInt64BE(BigInt(ns));
74
+ bufs.push(v);
75
+
76
+ // {zone offset} - UTC is always used for serialization, as such offset will be 0
77
+ v = Buffer.alloc(4);
78
+ v.writeInt32BE(0);
79
+ bufs.push(v);
80
+
81
+ return Buffer.concat(bufs);
82
+ }
83
+
84
+ deserialize(buffer, fullyQualifiedFormat = true) {
85
+ let len = 0;
86
+ let cursor = buffer;
87
+
88
+ try {
89
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
90
+ throw new Error('buffer is missing');
91
+ }
92
+ if (buffer.length < 1) {
93
+ throw new Error('buffer is empty');
94
+ }
95
+
96
+ if (fullyQualifiedFormat) {
97
+ const type_code = cursor.readUInt8();
98
+ len++;
99
+ if (type_code !== this.ID) {
100
+ throw new Error('unexpected {type_code}');
101
+ }
102
+ cursor = cursor.slice(1);
103
+
104
+ if (cursor.length < 1) {
105
+ throw new Error('{value_flag} is missing');
106
+ }
107
+ const value_flag = cursor.readUInt8();
108
+ len++;
109
+ if (value_flag === 1) {
110
+ return { v: null, len };
111
+ }
112
+ if (value_flag !== 0) {
113
+ throw new Error('unexpected {value_flag}');
114
+ }
115
+ cursor = cursor.slice(1);
116
+ }
117
+
118
+ if (cursor.length < 8) {
119
+ throw new Error('unexpected {value} length');
120
+ }
121
+ len += 18;
122
+
123
+ const year = cursor.readInt32BE();
124
+ cursor = cursor.slice(4);
125
+ const month = cursor.readUInt8() - 1;
126
+ cursor = cursor.slice(1);
127
+ const date = cursor.readUInt8();
128
+ cursor = cursor.slice(1);
129
+ const ns = cursor.readBigInt64BE();
130
+ cursor = cursor.slice(8);
131
+ const offset = cursor.readInt32BE();
132
+ cursor.slice(4);
133
+
134
+ // calculate hour, minute, second, and ms from ns as JS Date doesn't have ns precision
135
+ const totalMS = ns / BigInt(1e6);
136
+ const ms = Number(totalMS) % 1e3;
137
+ const totalS = Math.trunc(Number(totalMS) / 1e3) - offset; // js Date doesn't have a way to set offset properly, account offset here to use UTC
138
+ const s = totalS % 60;
139
+ const totalM = Math.trunc(totalS / 60);
140
+ const m = totalM % 60;
141
+ const h = Math.trunc(totalM / 60);
142
+
143
+ // use UTC time calculated with offset above
144
+ const v = new Date(Date.UTC(year, month, date, h, m, s, ms));
145
+
146
+ return { v, len };
147
+ } catch (err) {
148
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
149
+ }
150
+ }
151
+ };