gremlin 3.5.1 → 3.5.4

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 (128) hide show
  1. package/.eslintrc.js +155 -0
  2. package/.prettierrc.js +29 -0
  3. package/Gruntfile.js +15 -16
  4. package/doc/AnonymousTraversalSource.html +5 -5
  5. package/doc/Authenticator.html +2 -2
  6. package/doc/Bytecode.html +7 -7
  7. package/doc/Client.html +138 -64
  8. package/doc/Connection.html +93 -9
  9. package/doc/DriverRemoteConnection.html +11 -11
  10. package/doc/EdgeLabelVerificationStrategy.html +3 -3
  11. package/doc/Graph.html +2 -2
  12. package/doc/GraphSON2Reader.html +4 -4
  13. package/doc/GraphSON2Writer.html +3 -3
  14. package/doc/GraphSON3Reader.html +3 -3
  15. package/doc/GraphSON3Writer.html +3 -3
  16. package/doc/GraphTraversal.html +107 -107
  17. package/doc/GraphTraversalSource.html +19 -19
  18. package/doc/HaltedTraverserStrategy.html +3 -3
  19. package/doc/MatchAlgorithmStrategy.html +3 -3
  20. package/doc/P.html +13 -13
  21. package/doc/PartitionStrategy.html +3 -3
  22. package/doc/Path.html +2 -2
  23. package/doc/PlainTextSaslAuthenticator.html +2 -2
  24. package/doc/ProductiveByStrategy.html +288 -0
  25. package/doc/RemoteConnection.html +10 -10
  26. package/doc/RemoteStrategy.html +4 -4
  27. package/doc/RemoteTraversal.html +3 -3
  28. package/doc/ReservedKeysVerificationStrategy.html +3 -3
  29. package/doc/ResponseError.html +2 -2
  30. package/doc/ResultSet.html +7 -7
  31. package/doc/SaslAuthenticator.html +2 -2
  32. package/doc/SaslMechanismBase.html +2 -2
  33. package/doc/SaslMechanismPlain.html +6 -6
  34. package/doc/SeedStrategy.html +288 -0
  35. package/doc/SubgraphStrategy.html +3 -3
  36. package/doc/TextP.html +10 -10
  37. package/doc/Transaction.html +6 -6
  38. package/doc/Translator.html +198 -4
  39. package/doc/TraversalStrategies.html +5 -5
  40. package/doc/TraversalStrategy.html +3 -3
  41. package/doc/TypeSerializer.html +2 -2
  42. package/doc/driver_auth_authenticator.js.html +4 -4
  43. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +3 -3
  44. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +26 -17
  45. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +7 -7
  46. package/doc/driver_auth_sasl-authenticator.js.html +3 -3
  47. package/doc/driver_client.js.html +73 -23
  48. package/doc/driver_connection.js.html +134 -92
  49. package/doc/driver_driver-remote-connection.js.html +12 -11
  50. package/doc/driver_remote-connection.js.html +4 -5
  51. package/doc/driver_response-error.js.html +5 -4
  52. package/doc/driver_result-set.js.html +4 -4
  53. package/doc/global.html +264 -3
  54. package/doc/index.html +2 -2
  55. package/doc/module.exports.html +301 -0
  56. package/doc/process_anonymous-traversal.js.html +4 -4
  57. package/doc/process_bytecode.js.html +11 -9
  58. package/doc/process_graph-traversal.js.html +194 -143
  59. package/doc/process_transaction.js.html +16 -9
  60. package/doc/process_translator.js.html +53 -37
  61. package/doc/process_traversal-strategy.js.html +70 -53
  62. package/doc/process_traversal.js.html +101 -108
  63. package/doc/structure_graph.js.html +7 -7
  64. package/doc/structure_io_binary_internals_DataType.js.html +148 -0
  65. package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +131 -0
  66. package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +134 -0
  67. package/doc/structure_io_graph-serializer.js.html +65 -18
  68. package/doc/structure_io_type-serializers.js.html +86 -89
  69. package/index.js +5 -5
  70. package/lib/driver/auth/authenticator.js +2 -2
  71. package/lib/driver/auth/mechanisms/sasl-mechanism-base.js +1 -1
  72. package/lib/driver/auth/mechanisms/sasl-mechanism-plain.js +24 -15
  73. package/lib/driver/auth/plain-text-sasl-authenticator.js +5 -5
  74. package/lib/driver/auth/sasl-authenticator.js +1 -1
  75. package/lib/driver/client.js +71 -21
  76. package/lib/driver/connection.js +132 -90
  77. package/lib/driver/driver-remote-connection.js +10 -9
  78. package/lib/driver/remote-connection.js +2 -3
  79. package/lib/driver/response-error.js +2 -2
  80. package/lib/driver/result-set.js +1 -2
  81. package/lib/process/anonymous-traversal.js +1 -2
  82. package/lib/process/bytecode.js +9 -7
  83. package/lib/process/graph-traversal.js +191 -141
  84. package/lib/process/transaction.js +13 -7
  85. package/lib/process/translator.js +50 -35
  86. package/lib/process/traversal-strategy.js +67 -51
  87. package/lib/process/traversal.js +99 -106
  88. package/lib/structure/graph.js +5 -5
  89. package/lib/structure/io/binary/GraphBinary.js +109 -0
  90. package/lib/structure/io/binary/internals/AnySerializer.js +95 -0
  91. package/lib/structure/io/binary/internals/ArraySerializer.js +135 -0
  92. package/lib/structure/io/binary/internals/BigIntegerSerializer.js +151 -0
  93. package/lib/structure/io/binary/internals/BooleanSerializer.js +103 -0
  94. package/lib/structure/io/binary/internals/BulkSetSerializer.js +124 -0
  95. package/lib/structure/io/binary/internals/ByteBufferSerializer.js +124 -0
  96. package/lib/structure/io/binary/internals/ByteSerializer.js +95 -0
  97. package/lib/structure/io/binary/internals/BytecodeSerializer.js +249 -0
  98. package/lib/structure/io/binary/internals/DataType.js +97 -0
  99. package/lib/structure/io/binary/internals/DateSerializer.js +103 -0
  100. package/lib/structure/io/binary/internals/DoubleSerializer.js +99 -0
  101. package/lib/structure/io/binary/internals/EdgeSerializer.js +215 -0
  102. package/lib/structure/io/binary/internals/EnumSerializer.js +148 -0
  103. package/lib/structure/io/binary/internals/FloatSerializer.js +99 -0
  104. package/lib/structure/io/binary/internals/GraphBinaryReader.js +80 -0
  105. package/lib/structure/io/binary/internals/GraphBinaryWriter.js +83 -0
  106. package/lib/structure/io/binary/internals/IntSerializer.js +112 -0
  107. package/lib/structure/io/binary/internals/LambdaSerializer.js +70 -0
  108. package/lib/structure/io/binary/internals/LongSerializer.js +107 -0
  109. package/lib/structure/io/binary/internals/LongSerializerNg.js +102 -0
  110. package/lib/structure/io/binary/internals/MapSerializer.js +153 -0
  111. package/lib/structure/io/binary/internals/NumberSerializationStrategy.js +68 -0
  112. package/lib/structure/io/binary/internals/PSerializer.js +151 -0
  113. package/lib/structure/io/binary/internals/PathSerializer.js +123 -0
  114. package/lib/structure/io/binary/internals/PropertySerializer.js +141 -0
  115. package/lib/structure/io/binary/internals/ShortSerializer.js +99 -0
  116. package/lib/structure/io/binary/internals/StringSerializer.js +114 -0
  117. package/lib/structure/io/binary/internals/TextPSerializer.js +145 -0
  118. package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +72 -0
  119. package/lib/structure/io/binary/internals/TraverserSerializer.js +123 -0
  120. package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +75 -0
  121. package/lib/structure/io/binary/internals/UuidSerializer.js +119 -0
  122. package/lib/structure/io/binary/internals/VertexPropertySerializer.js +172 -0
  123. package/lib/structure/io/binary/internals/VertexSerializer.js +135 -0
  124. package/lib/structure/io/binary/internals/utils.js +59 -0
  125. package/lib/structure/io/graph-serializer.js +62 -16
  126. package/lib/structure/io/type-serializers.js +84 -87
  127. package/lib/utils.js +15 -10
  128. package/package.json +21 -8
@@ -20,9 +20,9 @@
20
20
  /**
21
21
  * @author Jorge Bay Gondra
22
22
  */
23
+
23
24
  'use strict';
24
25
 
25
- const utils = require('../utils');
26
26
  const itemDone = Object.freeze({ value: null, done: true });
27
27
  const asyncIteratorSymbol = Symbol.asyncIterator || Symbol('@@asyncIterator');
28
28
 
@@ -63,19 +63,21 @@ class Traversal {
63
63
  }
64
64
  return result;
65
65
  });
66
- };
66
+ }
67
67
 
68
68
  /**
69
69
  * Determines if there are any more items to iterate from the traversal.
70
70
  * @returns {Promise.<boolean>}
71
71
  */
72
- hasNext() {
73
- return this._applyStrategies().then(() => {
74
- return this.traversers && this.traversers.length > 0 &&
75
- this._traversersIteratorIndex < this.traversers.length &&
76
- this.traversers[this._traversersIteratorIndex].bulk > 0;
77
- });
78
- }
72
+ hasNext() {
73
+ return this._applyStrategies().then(
74
+ () =>
75
+ this.traversers &&
76
+ this.traversers.length > 0 &&
77
+ this._traversersIteratorIndex < this.traversers.length &&
78
+ this.traversers[this._traversersIteratorIndex].bulk > 0,
79
+ );
80
+ }
79
81
 
80
82
  /**
81
83
  * Iterates all Traverser instances in the traversal.
@@ -86,6 +88,7 @@ class Traversal {
86
88
  return this._applyStrategies().then(() => {
87
89
  let it;
88
90
  while ((it = this._getNext()) && !it.done) {
91
+ //
89
92
  }
90
93
  });
91
94
  }
@@ -105,7 +108,7 @@ class Traversal {
105
108
  */
106
109
  _getNext() {
107
110
  while (this.traversers && this._traversersIteratorIndex < this.traversers.length) {
108
- let traverser = this.traversers[this._traversersIteratorIndex];
111
+ const traverser = this.traversers[this._traversersIteratorIndex];
109
112
  if (traverser.bulk > 0) {
110
113
  traverser.bulk--;
111
114
  return { value: traverser.object, done: false };
@@ -120,14 +123,14 @@ class Traversal {
120
123
  // Apply strategies only once
121
124
  return this._traversalStrategiesPromise;
122
125
  }
123
- return this._traversalStrategiesPromise = this.traversalStrategies.applyStrategies(this);
126
+ return (this._traversalStrategiesPromise = this.traversalStrategies.applyStrategies(this));
124
127
  }
125
128
 
126
129
  /**
127
130
  * Returns step instructions during JSON serialization
128
131
  * @returns {Array}
129
132
  */
130
- toJSON(){
133
+ toJSON() {
131
134
  return this.bytecode.stepInstructions;
132
135
  }
133
136
 
@@ -137,106 +140,103 @@ class Traversal {
137
140
  */
138
141
  toString() {
139
142
  return this.bytecode.toString();
140
- };
143
+ }
141
144
  }
142
145
 
143
-
144
146
  class IO {
147
+ static get graphml() {
148
+ return 'graphml';
149
+ }
145
150
 
146
- static get graphml() {
147
- return "graphml"
148
- }
149
-
150
- static get graphson() {
151
- return "graphson"
152
- }
151
+ static get graphson() {
152
+ return 'graphson';
153
+ }
153
154
 
154
- static get gryo() {
155
- return "gryo"
156
- }
155
+ static get gryo() {
156
+ return 'gryo';
157
+ }
157
158
 
158
- static get reader() {
159
- return "~tinkerpop.io.reader"
160
- }
159
+ static get reader() {
160
+ return '~tinkerpop.io.reader';
161
+ }
161
162
 
162
- static get registry() {
163
- return "~tinkerpop.io.registry"
164
- }
163
+ static get registry() {
164
+ return '~tinkerpop.io.registry';
165
+ }
165
166
 
166
- static get writer() {
167
- return "~tinkerpop.io.writer"
168
- }
167
+ static get writer() {
168
+ return '~tinkerpop.io.writer';
169
+ }
169
170
  }
170
171
 
172
+ // eslint-disable-next-line no-unused-vars
171
173
  class ConnectedComponent {
174
+ static get component() {
175
+ return 'gremlin.connectedComponentVertexProgram.component';
176
+ }
172
177
 
173
- static get component() {
174
- return "gremlin.connectedComponentVertexProgram.component"
175
- }
176
-
177
- static get edges() {
178
- return "~tinkerpop.connectedComponent.edges"
179
- }
178
+ static get edges() {
179
+ return '~tinkerpop.connectedComponent.edges';
180
+ }
180
181
 
181
- static get propertyName() {
182
- return "~tinkerpop.connectedComponent.propertyName"
183
- }
182
+ static get propertyName() {
183
+ return '~tinkerpop.connectedComponent.propertyName';
184
+ }
184
185
  }
185
186
 
187
+ // eslint-disable-next-line no-unused-vars
186
188
  class ShortestPath {
189
+ static get distance() {
190
+ return '~tinkerpop.shortestPath.distance';
191
+ }
187
192
 
188
- static get distance() {
189
- return "~tinkerpop.shortestPath.distance"
190
- }
191
-
192
- static get edges() {
193
- return "~tinkerpop.shortestPath.edges"
194
- }
193
+ static get edges() {
194
+ return '~tinkerpop.shortestPath.edges';
195
+ }
195
196
 
196
- static get includeEdges() {
197
- return "~tinkerpop.shortestPath.includeEdges"
198
- }
197
+ static get includeEdges() {
198
+ return '~tinkerpop.shortestPath.includeEdges';
199
+ }
199
200
 
200
- static get maxDistance() {
201
- return "~tinkerpop.shortestPath.maxDistance"
202
- }
201
+ static get maxDistance() {
202
+ return '~tinkerpop.shortestPath.maxDistance';
203
+ }
203
204
 
204
- static get target() {
205
- return "~tinkerpop.shortestPath.target"
206
- }
205
+ static get target() {
206
+ return '~tinkerpop.shortestPath.target';
207
+ }
207
208
  }
208
209
 
210
+ // eslint-disable-next-line no-unused-vars
209
211
  class PageRank {
212
+ static get edges() {
213
+ return '~tinkerpop.pageRank.edges';
214
+ }
210
215
 
211
- static get edges() {
212
- return "~tinkerpop.pageRank.edges"
213
- }
214
-
215
- static get propertyName() {
216
- return "~tinkerpop.pageRank.propertyName"
217
- }
216
+ static get propertyName() {
217
+ return '~tinkerpop.pageRank.propertyName';
218
+ }
218
219
 
219
- static get times() {
220
- return "~tinkerpop.pageRank.times"
221
- }
220
+ static get times() {
221
+ return '~tinkerpop.pageRank.times';
222
+ }
222
223
  }
223
224
 
225
+ // eslint-disable-next-line no-unused-vars
224
226
  class PeerPressure {
227
+ static get edges() {
228
+ return '~tinkerpop.peerPressure.edges';
229
+ }
225
230
 
226
- static get edges() {
227
- return "~tinkerpop.peerPressure.edges"
228
- }
229
-
230
- static get propertyName() {
231
- return "~tinkerpop.peerPressure.propertyName"
232
- }
231
+ static get propertyName() {
232
+ return '~tinkerpop.peerPressure.propertyName';
233
+ }
233
234
 
234
- static get times() {
235
- return "~tinkerpop.peerPressure.times"
236
- }
235
+ static get times() {
236
+ return '~tinkerpop.peerPressure.times';
237
+ }
237
238
  }
238
239
 
239
-
240
240
  class P {
241
241
  /**
242
242
  * Represents an operation.
@@ -253,16 +253,16 @@ class P {
253
253
  * @returns {string}
254
254
  */
255
255
  toString() {
256
- function formatValue(value){
256
+ function formatValue(value) {
257
257
  if (Array.isArray(value)) {
258
- let acc = [];
258
+ const acc = [];
259
259
  for (const item of value) {
260
260
  acc.push(formatValue(item));
261
261
  }
262
262
  return acc;
263
263
  }
264
- if (value && typeof value === "string"){
265
- return "'" + value + "'";
264
+ if (value && typeof value === 'string') {
265
+ return `'${value}'`;
266
266
  }
267
267
  return value;
268
268
  }
@@ -283,21 +283,18 @@ class P {
283
283
 
284
284
  static within(...args) {
285
285
  if (args.length === 1 && Array.isArray(args[0])) {
286
- return new P("within", args[0], null);
287
- } else {
288
- return new P("within", args, null);
286
+ return new P('within', args[0], null);
289
287
  }
288
+ return new P('within', args, null);
290
289
  }
291
290
 
292
291
  static without(...args) {
293
292
  if (args.length === 1 && Array.isArray(args[0])) {
294
- return new P("without", args[0], null);
295
- } else {
296
- return new P("without", args, null);
293
+ return new P('without', args[0], null);
297
294
  }
295
+ return new P('without', args, null);
298
296
  }
299
297
 
300
-
301
298
  /** @param {...Object} args */
302
299
  static between(...args) {
303
300
  return createP('between', args);
@@ -352,12 +349,11 @@ class P {
352
349
  static test(...args) {
353
350
  return createP('test', args);
354
351
  }
355
-
356
352
  }
357
353
 
358
354
  function createP(operator, args) {
359
355
  args.unshift(null, operator);
360
- return new (Function.prototype.bind.apply(P, args));
356
+ return new (Function.prototype.bind.apply(P, args))();
361
357
  }
362
358
 
363
359
  class TextP {
@@ -376,9 +372,9 @@ class TextP {
376
372
  * @returns {string}
377
373
  */
378
374
  toString() {
379
- function formatValue(value){
380
- if (value && typeof value === "string"){
381
- return "'" + value + "'";
375
+ function formatValue(value) {
376
+ if (value && typeof value === 'string') {
377
+ return `'${value}'`;
382
378
  }
383
379
  return value;
384
380
  }
@@ -426,12 +422,11 @@ class TextP {
426
422
  static startingWith(...args) {
427
423
  return createTextP('startingWith', args);
428
424
  }
429
-
430
425
  }
431
426
 
432
427
  function createTextP(operator, args) {
433
428
  args.unshift(null, operator);
434
- return new (Function.prototype.bind.apply(TextP, args));
429
+ return new (Function.prototype.bind.apply(TextP, args))();
435
430
  }
436
431
 
437
432
  class Traverser {
@@ -441,26 +436,24 @@ class Traverser {
441
436
  }
442
437
  }
443
438
 
444
- class TraversalSideEffects {
445
-
446
- }
439
+ class TraversalSideEffects {}
447
440
 
448
441
  const withOptions = {
449
- tokens: "~tinkerpop.valueMap.tokens",
442
+ tokens: '~tinkerpop.valueMap.tokens',
450
443
  none: 0,
451
444
  ids: 1,
452
445
  labels: 2,
453
446
  keys: 4,
454
447
  values: 8,
455
448
  all: 15,
456
- indexer: "~tinkerpop.index.indexer",
449
+ indexer: '~tinkerpop.index.indexer',
457
450
  list: 0,
458
- map: 1
451
+ map: 1,
459
452
  };
460
453
 
461
454
  function toEnum(typeName, keys) {
462
455
  const result = {};
463
- keys.split(' ').forEach(k => {
456
+ keys.split(' ').forEach((k) => {
464
457
  let jsKey = k;
465
458
  if (jsKey === jsKey.toUpperCase()) {
466
459
  jsKey = jsKey.toLowerCase();
@@ -501,5 +494,5 @@ module.exports = {
501
494
  pick: toEnum('Pick', 'any none'),
502
495
  pop: toEnum('Pop', 'all first last mixed'),
503
496
  scope: toEnum('Scope', 'global local'),
504
- t: toEnum('T', 'id key label value')
497
+ t: toEnum('T', 'id key label value'),
505
498
  };
@@ -57,7 +57,7 @@ class Element {
57
57
  * @returns {boolean}
58
58
  */
59
59
  equals(other) {
60
- return (other instanceof Element) && this.id === other.id;
60
+ return other instanceof Element && this.id === other.id;
61
61
  }
62
62
  }
63
63
 
@@ -119,7 +119,7 @@ class Property {
119
119
  }
120
120
 
121
121
  equals(other) {
122
- return (other instanceof Property) && this.key === other.key && this.value === other.value;
122
+ return other instanceof Property && this.key === other.key && this.value === other.value;
123
123
  }
124
124
  }
125
125
 
@@ -136,7 +136,7 @@ class Path {
136
136
  }
137
137
 
138
138
  toString() {
139
- return `path[${(this.objects || []).join(", ")}]`;
139
+ return `path[${(this.objects || []).join(', ')}]`;
140
140
  }
141
141
 
142
142
  equals(other) {
@@ -162,7 +162,7 @@ function areEqual(obj1, obj2) {
162
162
  return false;
163
163
  }
164
164
  for (let i = 0; i < obj1.length; i++) {
165
- if (!areEqual(obj1[i], obj2[i])){
165
+ if (!areEqual(obj1[i], obj2[i])) {
166
166
  return false;
167
167
  }
168
168
  }
@@ -186,5 +186,5 @@ module.exports = {
186
186
  Path,
187
187
  Property,
188
188
  Vertex,
189
- VertexProperty
189
+ VertexProperty,
190
190
  };
@@ -0,0 +1,109 @@
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
+ * GraphBinary 1.0 support implementation.
22
+ *
23
+ * The officially expected entrypoint is GraphBinaryReader/GraphBinaryWriter pair of classes,
24
+ * examine lib/driver/** for use cases.
25
+ *
26
+ * See AnySerializer.serialize() for the mechanism of serializer selection for a given JavaScript value,
27
+ * also consider AnySerializer.serialize() unit tests for real examples.
28
+ * See NumberSerializationStrategy to understand how it deals with JavaScript numbers' serialization.
29
+ *
30
+ * Consider AnySerializer.serialize()/deserialize() unit tests to see what is not implemented,
31
+ * what is ignored, what is not expected to be (de)serialized, etc.
32
+ *
33
+ * TODO: it has the following open topics:
34
+ * - [] Should we do anything for application/vnd.graphbinary-v1.0-stringd mime type support?
35
+ * Core Data Types support:
36
+ * - [] 0x22: BigDecimal
37
+ * - [] 0x2b: Tree
38
+ * - [] 0x2c: Metrics
39
+ * - [] 0x2d: TraversalMetrics
40
+ * - [] 0x00: Custom
41
+ * Extended Types support:
42
+ * - [] 0x80: Char
43
+ * - [] 0x81: Duration
44
+ * - [] 0x82: InetAddress
45
+ * - [] 0x83: Instant
46
+ * - [] 0x84: LocalDate
47
+ * - [] 0x85: LocalDateTime
48
+ * - [] 0x86: LocalTime
49
+ * - [] 0x87: MonthDay
50
+ * - [] 0x88: OffsetDateTime
51
+ * - [] 0x89: OffsetTime
52
+ * - [] 0x8a: Period
53
+ * - [] 0x8b: Year
54
+ * - [] 0x8c: YearMonth
55
+ * - [] 0x8d: ZonedDateTime
56
+ * - [] 0x8e: ZoneOffset
57
+ *
58
+ * @author Igor Ostapenko
59
+ */
60
+ /*eslint-disable*/
61
+ 'use strict';
62
+
63
+ const ioc = {};
64
+
65
+ ioc.DataType = require('./internals/DataType');
66
+ ioc.utils = require('./internals/utils');
67
+
68
+ ioc.serializers = {};
69
+
70
+ ioc.intSerializer = new (require('./internals/IntSerializer'))(ioc);
71
+ ioc.longSerializer = new (require('./internals/LongSerializer'))(ioc);
72
+ ioc.longSerializerNg = new (require('./internals/LongSerializerNg'))(ioc);
73
+ ioc.stringSerializer = new (require('./internals/StringSerializer'))(ioc, ioc.DataType.STRING);
74
+ ioc.dateSerializer = new (require('./internals/DateSerializer'))(ioc, ioc.DataType.DATE);
75
+ ioc.timestampSerializer = new (require('./internals/DateSerializer'))(ioc, ioc.DataType.TIMESTAMP);
76
+ ioc.classSerializer = new (require('./internals/StringSerializer'))(ioc, ioc.DataType.CLASS);
77
+ ioc.doubleSerializer = new (require('./internals/DoubleSerializer'))(ioc);
78
+ ioc.floatSerializer = new (require('./internals/FloatSerializer'))(ioc);
79
+ ioc.listSerializer = new (require('./internals/ArraySerializer'))(ioc, ioc.DataType.LIST);
80
+ ioc.mapSerializer = new (require('./internals/MapSerializer'))(ioc);
81
+ ioc.setSerializer = new (require('./internals/ArraySerializer'))(ioc, ioc.DataType.SET);
82
+ ioc.uuidSerializer = new (require('./internals/UuidSerializer'))(ioc);
83
+ ioc.edgeSerializer = new (require('./internals/EdgeSerializer'))(ioc);
84
+ ioc.pathSerializer = new (require('./internals/PathSerializer'))(ioc);
85
+ ioc.propertySerializer = new (require('./internals/PropertySerializer'))(ioc);
86
+ ioc.vertexSerializer = new (require('./internals/VertexSerializer'))(ioc);
87
+ ioc.vertexPropertySerializer = new (require('./internals/VertexPropertySerializer'))(ioc);
88
+ ioc.bytecodeSerializer = new (require('./internals/BytecodeSerializer'))(ioc);
89
+ ioc.pSerializer = new (require('./internals/PSerializer'))(ioc);
90
+ ioc.traverserSerializer = new (require('./internals/TraverserSerializer'))(ioc);
91
+ ioc.enumSerializer = new (require('./internals/EnumSerializer'))(ioc);
92
+ ioc.lambdaSerializer = new (require('./internals/LambdaSerializer'))(ioc);
93
+ ioc.bigIntegerSerializer = new (require('./internals/BigIntegerSerializer'))(ioc);
94
+ ioc.byteSerializer = new (require('./internals/ByteSerializer'))(ioc);
95
+ ioc.byteBufferSerializer = new (require('./internals/ByteBufferSerializer'))(ioc);
96
+ ioc.shortSerializer = new (require('./internals/ShortSerializer'))(ioc);
97
+ ioc.booleanSerializer = new (require('./internals/BooleanSerializer'))(ioc);
98
+ ioc.textPSerializer = new (require('./internals/TextPSerializer'))(ioc);
99
+ ioc.traversalStrategySerializer = new (require('./internals/TraversalStrategySerializer'))(ioc);
100
+ ioc.bulkSetSerializer = new (require('./internals/BulkSetSerializer'))(ioc);
101
+ ioc.unspecifiedNullSerializer = new (require('./internals/UnspecifiedNullSerializer'))(ioc);
102
+
103
+ ioc.numberSerializationStrategy = new (require('./internals/NumberSerializationStrategy'))(ioc);
104
+ ioc.anySerializer = new (require('./internals/AnySerializer'))(ioc);
105
+
106
+ ioc.graphBinaryReader = new (require('./internals/GraphBinaryReader.js'))(ioc);
107
+ ioc.graphBinaryWriter = new (require('./internals/GraphBinaryWriter'))(ioc);
108
+
109
+ module.exports = ioc;
@@ -0,0 +1,95 @@
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
+ module.exports = class AnySerializer {
26
+ constructor(ioc) {
27
+ this.ioc = ioc;
28
+
29
+ // specifically ordered, the first canBeUsedFor=true wins
30
+ this.serializers = [
31
+ ioc.unspecifiedNullSerializer,
32
+
33
+ ioc.numberSerializationStrategy,
34
+
35
+ ioc.booleanSerializer,
36
+ ioc.dateSerializer,
37
+ ioc.bytecodeSerializer,
38
+ ioc.pSerializer,
39
+ ioc.traverserSerializer,
40
+ ioc.enumSerializer,
41
+ ioc.listSerializer,
42
+ ioc.uuidSerializer,
43
+ ioc.edgeSerializer,
44
+ ioc.pathSerializer,
45
+ ioc.propertySerializer,
46
+ ioc.vertexSerializer,
47
+ ioc.vertexPropertySerializer,
48
+ ioc.stringSerializer,
49
+ ioc.textPSerializer,
50
+ ioc.traversalStrategySerializer,
51
+
52
+ ioc.byteBufferSerializer, // Buffer instance
53
+ ioc.lambdaSerializer, // any function
54
+ ioc.mapSerializer, // Map or any Object
55
+ ];
56
+ }
57
+
58
+ getSerializerCanBeUsedFor(item) {
59
+ for (let i = 0; i < this.serializers.length; i++) {
60
+ if (this.serializers[i].canBeUsedFor(item)) {
61
+ return this.serializers[i];
62
+ }
63
+ }
64
+
65
+ throw new Error(
66
+ `No serializer found to support item where typeof(item)='${typeof item}' and String(item)='${String(item)}'.`,
67
+ );
68
+ }
69
+
70
+ serialize(item, fullyQualifiedFormat = true) {
71
+ return this.getSerializerCanBeUsedFor(item).serialize(item, fullyQualifiedFormat);
72
+ }
73
+
74
+ deserialize(buffer) {
75
+ // obviously, fullyQualifiedFormat always is true
76
+ try {
77
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
78
+ throw new Error('buffer is missing');
79
+ }
80
+ if (buffer.length < 1) {
81
+ throw new Error('buffer is empty');
82
+ }
83
+
84
+ const type_code = buffer.readUInt8();
85
+ const serializer = this.ioc.serializers[type_code];
86
+ if (!serializer) {
87
+ throw new Error('unknown {type_code}');
88
+ }
89
+
90
+ return serializer.deserialize(buffer);
91
+ } catch (err) {
92
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, err });
93
+ }
94
+ }
95
+ };