gremlin 3.7.1 → 3.7.2

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 (118) hide show
  1. package/.eslintrc.js +3 -4
  2. package/.nvmrc +1 -0
  3. package/LICENSE +9 -1
  4. package/NOTICE +1 -1
  5. package/README.md +1 -1
  6. package/doc/AnonymousTraversalSource.html +2 -2
  7. package/doc/Authenticator.html +2 -2
  8. package/doc/Bytecode.html +2 -2
  9. package/doc/CardinalityValue.html +2 -2
  10. package/doc/Client.html +9 -108
  11. package/doc/Connection.html +9 -196
  12. package/doc/DataType.js.html +149 -0
  13. package/doc/DriverRemoteConnection.html +12 -111
  14. package/doc/EdgeLabelVerificationStrategy.html +2 -2
  15. package/doc/Graph.html +2 -2
  16. package/doc/GraphBinaryReader.js.html +132 -0
  17. package/doc/GraphBinaryWriter.js.html +135 -0
  18. package/doc/GraphSON2Reader.html +4 -4
  19. package/doc/GraphSON2Writer.html +5 -5
  20. package/doc/GraphSON3Reader.html +3 -3
  21. package/doc/GraphSON3Writer.html +3 -3
  22. package/doc/GraphTraversal.html +2 -2
  23. package/doc/GraphTraversalSource.html +2 -2
  24. package/doc/HaltedTraverserStrategy.html +2 -2
  25. package/doc/MatchAlgorithmStrategy.html +2 -2
  26. package/doc/P.html +2 -2
  27. package/doc/PartitionStrategy.html +2 -2
  28. package/doc/Path.html +2 -2
  29. package/doc/PlainTextSaslAuthenticator.html +2 -2
  30. package/doc/ProductiveByStrategy.html +2 -2
  31. package/doc/RemoteConnection.html +2 -2
  32. package/doc/RemoteStrategy.html +2 -2
  33. package/doc/RemoteTraversal.html +2 -2
  34. package/doc/ReservedKeysVerificationStrategy.html +2 -2
  35. package/doc/ResponseError.html +2 -2
  36. package/doc/ResultSet.html +7 -95
  37. package/doc/SaslAuthenticator.html +2 -2
  38. package/doc/SaslMechanismBase.html +2 -2
  39. package/doc/SaslMechanismPlain.html +7 -7
  40. package/doc/SeedStrategy.html +2 -2
  41. package/doc/SubgraphStrategy.html +2 -2
  42. package/doc/TextP.html +2 -2
  43. package/doc/Transaction.html +5 -5
  44. package/doc/Translator.html +2 -2
  45. package/doc/TraversalStrategies.html +2 -2
  46. package/doc/TraversalStrategy.html +2 -2
  47. package/doc/TypeSerializer.html +2 -2
  48. package/doc/driver_auth_authenticator.js.html +2 -2
  49. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +2 -2
  50. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +3 -2
  51. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +2 -2
  52. package/doc/driver_auth_sasl-authenticator.js.html +2 -2
  53. package/doc/driver_client.js.html +2 -5
  54. package/doc/driver_connection.js.html +82 -118
  55. package/doc/driver_driver-remote-connection.js.html +2 -5
  56. package/doc/driver_remote-connection.js.html +2 -2
  57. package/doc/driver_response-error.js.html +2 -2
  58. package/doc/driver_result-set.js.html +2 -11
  59. package/doc/global.html +158 -3
  60. package/doc/index.html +3 -3
  61. package/doc/module.exports.html +4 -4
  62. package/doc/process_anonymous-traversal.js.html +2 -2
  63. package/doc/process_bytecode.js.html +2 -2
  64. package/doc/process_graph-traversal.js.html +2 -2
  65. package/doc/process_transaction.js.html +12 -4
  66. package/doc/process_translator.js.html +2 -2
  67. package/doc/process_traversal-strategy.js.html +2 -2
  68. package/doc/process_traversal.js.html +2 -2
  69. package/doc/structure_graph.js.html +2 -2
  70. package/doc/structure_io_binary_internals_DataType.js.html +2 -2
  71. package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +4 -2
  72. package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +4 -2
  73. package/doc/structure_io_graph-serializer.js.html +3 -2
  74. package/doc/structure_io_type-serializers.js.html +2 -2
  75. package/doc/utils.js.html +181 -0
  76. package/lib/driver/auth/mechanisms/sasl-mechanism-plain.js +1 -0
  77. package/lib/driver/client.js +0 -3
  78. package/lib/driver/connection.js +80 -116
  79. package/lib/driver/driver-remote-connection.js +0 -3
  80. package/lib/driver/result-set.js +0 -9
  81. package/lib/process/transaction.js +10 -2
  82. package/lib/structure/io/binary/internals/AnySerializer.js +2 -0
  83. package/lib/structure/io/binary/internals/ArraySerializer.js +2 -0
  84. package/lib/structure/io/binary/internals/BigIntegerSerializer.js +2 -0
  85. package/lib/structure/io/binary/internals/BooleanSerializer.js +2 -0
  86. package/lib/structure/io/binary/internals/BulkSetSerializer.js +2 -0
  87. package/lib/structure/io/binary/internals/ByteBufferSerializer.js +2 -0
  88. package/lib/structure/io/binary/internals/ByteSerializer.js +2 -0
  89. package/lib/structure/io/binary/internals/BytecodeSerializer.js +1 -0
  90. package/lib/structure/io/binary/internals/DateSerializer.js +2 -0
  91. package/lib/structure/io/binary/internals/DoubleSerializer.js +2 -0
  92. package/lib/structure/io/binary/internals/EdgeSerializer.js +1 -0
  93. package/lib/structure/io/binary/internals/EnumSerializer.js +1 -0
  94. package/lib/structure/io/binary/internals/FloatSerializer.js +2 -0
  95. package/lib/structure/io/binary/internals/GraphBinaryReader.js +2 -0
  96. package/lib/structure/io/binary/internals/GraphBinaryWriter.js +2 -0
  97. package/lib/structure/io/binary/internals/IntSerializer.js +2 -0
  98. package/lib/structure/io/binary/internals/LambdaSerializer.js +1 -0
  99. package/lib/structure/io/binary/internals/LongSerializer.js +2 -0
  100. package/lib/structure/io/binary/internals/LongSerializerNg.js +2 -0
  101. package/lib/structure/io/binary/internals/MapSerializer.js +2 -0
  102. package/lib/structure/io/binary/internals/PSerializer.js +1 -0
  103. package/lib/structure/io/binary/internals/PathSerializer.js +1 -0
  104. package/lib/structure/io/binary/internals/PropertySerializer.js +1 -0
  105. package/lib/structure/io/binary/internals/ShortSerializer.js +2 -0
  106. package/lib/structure/io/binary/internals/StringSerializer.js +2 -0
  107. package/lib/structure/io/binary/internals/TextPSerializer.js +1 -0
  108. package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +2 -0
  109. package/lib/structure/io/binary/internals/TraverserSerializer.js +1 -0
  110. package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +2 -0
  111. package/lib/structure/io/binary/internals/UuidSerializer.js +2 -0
  112. package/lib/structure/io/binary/internals/VertexPropertySerializer.js +1 -0
  113. package/lib/structure/io/binary/internals/VertexSerializer.js +1 -0
  114. package/lib/structure/io/binary/internals/utils.js +2 -0
  115. package/lib/structure/io/graph-serializer.js +1 -0
  116. package/lib/utils.js +40 -29
  117. package/licenses/chai +21 -0
  118. package/package.json +7 -3
@@ -22,11 +22,11 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
- const EventEmitter = require('events');
26
- const Stream = require('stream');
27
- const WebSocket = require('ws');
28
- const util = require('util');
25
+ const { Buffer } = require('buffer');
26
+ const EventEmitter = require('eventemitter3');
27
+ const Stream = require('readable-stream');
29
28
  const utils = require('../utils');
29
+ const { DeferredPromise } = utils;
30
30
  const serializer = require('../structure/io/graph-serializer');
31
31
  const { graphBinaryReader, graphBinaryWriter } = require('../structure/io/binary/GraphBinary');
32
32
  const ResultSet = require('./result-set');
@@ -43,9 +43,6 @@ const defaultMimeType = 'application/vnd.gremlin-v3.0+json';
43
43
  const graphSON2MimeType = 'application/vnd.gremlin-v2.0+json';
44
44
  const graphBinaryMimeType = 'application/vnd.graphbinary-v1.0';
45
45
 
46
- const pingIntervalDelay = 60 * 1000;
47
- const pongTimeoutDelay = 30 * 1000;
48
-
49
46
  const uuidPattern = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
50
47
 
51
48
  /**
@@ -67,9 +64,6 @@ class Connection extends EventEmitter {
67
64
  * @param {Authenticator} [options.authenticator] The authentication handler to use.
68
65
  * @param {Object} [options.headers] An associative array containing the additional header key/values for the initial request.
69
66
  * @param {Boolean} [options.enableUserAgentOnConnect] Determines if a user agent will be sent during connection handshake. Defaults to: true
70
- * @param {Boolean} [options.pingEnabled] Setup ping interval. Defaults to: true.
71
- * @param {Number} [options.pingInterval] Ping request interval in ms if ping enabled. Defaults to: 60000.
72
- * @param {Number} [options.pongTimeout] Timeout of pong response in ms after sending a ping. Defaults to: 30000.
73
67
  * @param {http.Agent} [options.agent] The http.Agent implementation to use.
74
68
  * @constructor
75
69
  */
@@ -87,14 +81,12 @@ class Connection extends EventEmitter {
87
81
 
88
82
  // A map containing the request id and the handler. The id should be in lower case to prevent string comparison issues.
89
83
  this._responseHandlers = {};
90
- this._reader = options.reader || this._getDefaultReader(this.mimeType);
91
- this._writer = options.writer || this._getDefaultWriter(this.mimeType);
84
+ this._reader = options.reader || this.#getDefaultReader(this.mimeType);
85
+ this._writer = options.writer || this.#getDefaultWriter(this.mimeType);
92
86
  this._openPromise = null;
93
87
  this._openCallback = null;
94
88
  this._closePromise = null;
95
89
  this._closeCallback = null;
96
- this._pingInterval = null;
97
- this._pongTimeout = null;
98
90
 
99
91
  this._header = String.fromCharCode(this.mimeType.length) + this.mimeType; // TODO: what if mimeType.length > 255
100
92
  this._header_buf = Buffer.from(this._header);
@@ -102,70 +94,61 @@ class Connection extends EventEmitter {
102
94
  this.traversalSource = options.traversalSource || 'g';
103
95
  this._authenticator = options.authenticator;
104
96
  this._enableUserAgentOnConnect = options.enableUserAgentOnConnect !== false;
105
-
106
- this._pingEnabled = this.options.pingEnabled === false ? false : true;
107
- this._pingIntervalDelay = this.options.pingInterval || pingIntervalDelay;
108
- this._pongTimeoutDelay = this.options.pongTimeout || pongTimeoutDelay;
109
97
  }
110
98
 
111
99
  /**
112
100
  * Opens the connection, if its not already opened.
113
101
  * @returns {Promise}
114
102
  */
115
- open() {
103
+ async open() {
116
104
  if (this.isOpen) {
117
- return Promise.resolve();
105
+ return;
118
106
  }
119
107
  if (this._openPromise) {
120
108
  return this._openPromise;
121
109
  }
122
110
 
111
+ this._openPromise = DeferredPromise();
112
+
123
113
  this.emit('log', 'ws open');
124
114
  let headers = this.options.headers;
125
115
  if (this._enableUserAgentOnConnect) {
126
116
  if (!headers) {
127
117
  headers = [];
128
118
  }
129
- headers[utils.getUserAgentHeader()] = utils.getUserAgent();
119
+
120
+ const userAgent = await utils.getUserAgent();
121
+ if (userAgent !== undefined) {
122
+ headers[utils.getUserAgentHeader()] = await utils.getUserAgent();
123
+ }
130
124
  }
131
125
 
132
- this._ws = new WebSocket(this.url, {
133
- headers: headers,
134
- ca: this.options.ca,
135
- cert: this.options.cert,
136
- pfx: this.options.pfx,
137
- rejectUnauthorized: this.options.rejectUnauthorized,
138
- agent: this.options.agent,
139
- });
126
+ const WebSocket = globalThis.WebSocket ?? (await import('ws')).default;
127
+
128
+ this._ws = new WebSocket(
129
+ this.url,
130
+ globalThis.WebSocket === undefined
131
+ ? {
132
+ headers: headers,
133
+ ca: this.options.ca,
134
+ cert: this.options.cert,
135
+ pfx: this.options.pfx,
136
+ rejectUnauthorized: this.options.rejectUnauthorized,
137
+ agent: this.options.agent,
138
+ }
139
+ : undefined,
140
+ );
140
141
 
141
- this._ws.on('message', (data) => this._handleMessage(data));
142
- this._ws.on('close', (code, message) => this._handleClose(code, message));
142
+ if ('binaryType' in this._ws) {
143
+ this._ws.binaryType = 'arraybuffer';
144
+ }
143
145
 
144
- this._ws.on('pong', () => {
145
- this.emit('log', 'ws pong received');
146
- if (this._pongTimeout) {
147
- clearTimeout(this._pongTimeout);
148
- this._pongTimeout = null;
149
- }
150
- });
151
- this._ws.on('ping', () => {
152
- this.emit('log', 'ws ping received');
153
- this._ws.pong();
154
- });
146
+ this._ws.addEventListener('open', this.#handleOpen);
147
+ this._ws.addEventListener('error', this.#handleError);
148
+ this._ws.addEventListener('message', this.#handleMessage);
149
+ this._ws.addEventListener('close', this.#handleClose);
155
150
 
156
- return (this._openPromise = new Promise((resolve, reject) => {
157
- this._ws.on('open', () => {
158
- this.isOpen = true;
159
- if (this._pingEnabled) {
160
- this._pingHeartbeat();
161
- }
162
- resolve();
163
- });
164
- this._ws.on('error', (err) => {
165
- this._handleError(err);
166
- reject(err);
167
- });
168
- }));
151
+ return await this._openPromise;
169
152
  }
170
153
 
171
154
  /** @override */
@@ -195,7 +178,7 @@ class Connection extends EventEmitter {
195
178
  };
196
179
 
197
180
  const request_buf = this._writer.writeRequest(request);
198
- const message = Buffer.concat([this._header_buf, request_buf]);
181
+ const message = utils.toArrayBuffer(Buffer.concat([this._header_buf, request_buf]));
199
182
  this._ws.send(message);
200
183
  }),
201
184
  );
@@ -230,7 +213,7 @@ class Connection extends EventEmitter {
230
213
  };
231
214
 
232
215
  const request_buf = this._writer.writeRequest(request);
233
- const message = Buffer.concat([this._header_buf, request_buf]);
216
+ const message = utils.toArrayBuffer(Buffer.concat([this._header_buf, request_buf]));
234
217
  this._ws.send(message);
235
218
  })
236
219
  .catch((err) => readableStream.destroy(err));
@@ -238,7 +221,7 @@ class Connection extends EventEmitter {
238
221
  return readableStream;
239
222
  }
240
223
 
241
- _getDefaultReader(mimeType) {
224
+ #getDefaultReader(mimeType) {
242
225
  if (mimeType === graphBinaryMimeType) {
243
226
  return graphBinaryReader;
244
227
  }
@@ -246,7 +229,7 @@ class Connection extends EventEmitter {
246
229
  return mimeType === graphSON2MimeType ? new serializer.GraphSON2Reader() : new serializer.GraphSONReader();
247
230
  }
248
231
 
249
- _getDefaultWriter(mimeType) {
232
+ #getDefaultWriter(mimeType) {
250
233
  if (mimeType === graphBinaryMimeType) {
251
234
  return graphBinaryWriter;
252
235
  }
@@ -254,68 +237,58 @@ class Connection extends EventEmitter {
254
237
  return mimeType === graphSON2MimeType ? new serializer.GraphSON2Writer() : new serializer.GraphSONWriter();
255
238
  }
256
239
 
257
- _pingHeartbeat() {
258
- if (this._pingInterval) {
259
- clearInterval(this._pingInterval);
260
- this._pingInterval = null;
261
- }
240
+ #handleOpen = () => {
241
+ this._openPromise.resolve();
242
+ this.isOpen = true;
243
+ };
262
244
 
263
- this._pingInterval = setInterval(() => {
264
- if (this.isOpen === false) {
265
- // in case of if not open..
266
- if (this._pingInterval) {
267
- clearInterval(this._pingInterval);
268
- this._pingInterval = null;
269
- }
270
- }
271
-
272
- this._pongTimeout = setTimeout(() => {
273
- this._ws.terminate();
274
- }, this._pongTimeoutDelay);
275
-
276
- this._ws.ping();
277
- }, this._pingIntervalDelay);
278
- }
279
-
280
- _handleError(err) {
281
- this.emit('log', `ws error ${err}`);
282
- this._cleanupWebsocket(err);
283
- this.emit('socketError', err);
284
- }
245
+ /**
246
+ * @param {Event} event
247
+ */
248
+ #handleError = ({ error }) => {
249
+ this._openPromise.reject(error);
250
+ this.emit('log', `ws error ${error}`);
251
+ this.#cleanupWebsocket(error);
252
+ this.emit('socketError', error);
253
+ };
285
254
 
286
- _handleClose(code, message) {
255
+ /**
256
+ * @param {CloseEvent} event
257
+ */
258
+ #handleClose = ({ code, message }) => {
287
259
  this.emit('log', `ws close code=${code} message=${message}`);
288
- this._cleanupWebsocket();
260
+ this.#cleanupWebsocket();
289
261
  if (this._closeCallback) {
290
262
  this._closeCallback();
291
263
  }
292
264
  this.emit('close', code, message);
293
- }
265
+ };
266
+
267
+ /**
268
+ * @param {MessageEvent<any>} event
269
+ */
270
+ #handleMessage = ({ data: _data }) => {
271
+ const data = _data instanceof ArrayBuffer ? Buffer.from(_data) : _data;
294
272
 
295
- _handleMessage(data) {
296
273
  const response = this._reader.readResponse(data);
297
274
  if (response.requestId === null || response.requestId === undefined) {
298
275
  // There was a serialization issue on the server that prevented the parsing of the request id
299
276
  // We invoke any of the pending handlers with an error
300
277
  Object.keys(this._responseHandlers).forEach((requestId) => {
301
278
  const handler = this._responseHandlers[requestId];
302
- this._clearHandler(requestId);
279
+ this.#clearHandler(requestId);
303
280
  if (response.status !== undefined && response.status.message) {
304
281
  return handler.callback(
305
282
  // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
306
283
  new ResponseError(
307
- util.format(
308
- 'Server error (no request information): %s (%d)',
309
- response.status.message,
310
- response.status.code,
311
- ),
284
+ `Server error (no request information): ${response.status.message} (${response.status.code})`,
312
285
  response.status,
313
286
  ),
314
287
  );
315
288
  }
316
289
  // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
317
290
  return handler.callback(
318
- new ResponseError(util.format('Server error (no request information): %j', response), response.status),
291
+ new ResponseError(`Server error (no request information): ${JSON.stringify(response)}`, response.status),
319
292
  );
320
293
  });
321
294
  return;
@@ -342,10 +315,7 @@ class Connection extends EventEmitter {
342
315
  // callback in error
343
316
  return handler.callback(
344
317
  // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
345
- new ResponseError(
346
- util.format('Server error: %s (%d)', response.status.message, response.status.code),
347
- response.status,
348
- ),
318
+ new ResponseError(`Server error: ${response.status.message} (${response.status.code})`, response.status),
349
319
  );
350
320
  }
351
321
 
@@ -353,7 +323,7 @@ class Connection extends EventEmitter {
353
323
 
354
324
  switch (response.status.code) {
355
325
  case responseStatusCode.noContent:
356
- this._clearHandler(response.requestId);
326
+ this.#clearHandler(response.requestId);
357
327
  if (isStreamingResponse) {
358
328
  handler.result.push(new ResultSet(utils.emptyArray, response.status.attributes));
359
329
  return handler.callback(null);
@@ -377,24 +347,15 @@ class Connection extends EventEmitter {
377
347
  } else {
378
348
  handler.result = response.result.data;
379
349
  }
380
- this._clearHandler(response.requestId);
350
+ this.#clearHandler(response.requestId);
381
351
  return handler.callback(null, new ResultSet(handler.result, response.status.attributes));
382
352
  }
383
- }
353
+ };
384
354
 
385
355
  /**
386
356
  * clean websocket context
387
357
  */
388
- _cleanupWebsocket(err) {
389
- if (this._pingInterval) {
390
- clearInterval(this._pingInterval);
391
- }
392
- this._pingInterval = null;
393
- if (this._pongTimeout) {
394
- clearTimeout(this._pongTimeout);
395
- }
396
- this._pongTimeout = null;
397
-
358
+ #cleanupWebsocket(err) {
398
359
  // Invoke waiting callbacks to complete Promises when closing the websocket
399
360
  Object.keys(this._responseHandlers).forEach((requestId) => {
400
361
  const handler = this._responseHandlers[requestId];
@@ -406,7 +367,10 @@ class Connection extends EventEmitter {
406
367
  handler.callback(cause);
407
368
  }
408
369
  });
409
- this._ws.removeAllListeners();
370
+ this._ws.removeEventListener('open', this.#handleOpen);
371
+ this._ws.removeEventListener('error', this.#handleError);
372
+ this._ws.removeEventListener('message', this.#handleMessage);
373
+ this._ws.removeEventListener('close', this.#handleClose);
410
374
  this._openPromise = null;
411
375
  this._closePromise = null;
412
376
  this.isOpen = false;
@@ -417,7 +381,7 @@ class Connection extends EventEmitter {
417
381
  * @param requestId
418
382
  * @private
419
383
  */
420
- _clearHandler(requestId) {
384
+ #clearHandler(requestId) {
421
385
  delete this._responseHandlers[requestId];
422
386
  }
423
387
 
@@ -49,9 +49,6 @@ class DriverRemoteConnection extends RemoteConnection {
49
49
  * @param {Authenticator} [options.authenticator] The authentication handler to use.
50
50
  * @param {Object} [options.headers] An associative array containing the additional header key/values for the initial request.
51
51
  * @param {Boolean} [options.enableUserAgentOnConnect] Determines if a user agent will be sent during connection handshake. Defaults to: true
52
- * @param {Boolean} [options.pingEnabled] Setup ping interval. Defaults to: true.
53
- * @param {Number} [options.pingInterval] Ping request interval in ms if ping enabled. Defaults to: 60000.
54
- * @param {Number} [options.pongTimeout] Timeout of pong response in ms after sending a ping. Defaults to: 30000.
55
52
  * @param {http.Agent} [options.agent] The http.Agent implementation to use.
56
53
  * @constructor
57
54
  */
@@ -22,8 +22,6 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
- const util = require('util');
26
- const inspect = util.inspect.custom || 'inspect';
27
25
  const utils = require('../utils');
28
26
  const emptyMap = Object.freeze(new utils.ImmutableMap());
29
27
 
@@ -64,13 +62,6 @@ class ResultSet {
64
62
  return this._items[Symbol.iterator]();
65
63
  }
66
64
 
67
- /**
68
- * Provides a representation useful for debug and tracing.
69
- */
70
- [inspect]() {
71
- return this._items;
72
- }
73
-
74
65
  /**
75
66
  * Gets an array of result items.
76
67
  * @returns {Array}
@@ -59,14 +59,22 @@ class Transaction {
59
59
  * @returns {Promise}
60
60
  */
61
61
  commit() {
62
- return this._sessionBasedConnection.commit().then(() => this.close());
62
+ if (!this._sessionBasedConnection) {
63
+ throw new Error('Cannot commit a transaction that is not started');
64
+ }
65
+
66
+ return this._sessionBasedConnection.commit().finally(() => this.close());
63
67
  }
64
68
 
65
69
  /**
66
70
  * @returns {Promise}
67
71
  */
68
72
  rollback() {
69
- return this._sessionBasedConnection.rollback().then(() => this.close());
73
+ if (!this._sessionBasedConnection) {
74
+ throw new Error('Cannot rollback a transaction that is not started');
75
+ }
76
+
77
+ return this._sessionBasedConnection.rollback().finally(() => this.close());
70
78
  }
71
79
 
72
80
  /**
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class AnySerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class ArraySerializer {
26
28
  constructor(ioc, ID) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  // TODO: it has room for performance improvements
26
28
  module.exports = class BigIntegerSerializer {
27
29
  constructor(ioc) {
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class BooleanSerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class BulkSetSerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class ByteBufferSerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class ByteSerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,7 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
25
26
  const Bytecode = require('../../../../process/bytecode');
26
27
  const t = require('../../../../process/traversal');
27
28
 
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class DateSerializer {
26
28
  constructor(ioc, ID) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class DoubleSerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,7 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
25
26
  const g = require('../../../graph');
26
27
 
27
28
  module.exports = class EdgeSerializer {
@@ -22,6 +22,7 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
25
26
  const t = require('../../../../process/traversal');
26
27
 
27
28
  module.exports = class EnumSerializer {
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class FloatSerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  /**
26
28
  * GraphBinary reader.
27
29
  */
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  /**
26
28
  * GraphBinary writer.
27
29
  */
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class IntSerializer {
26
28
  get INT32_MIN() {
27
29
  return -2147483648;
@@ -22,6 +22,7 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
25
26
  const { valueKey, LambdaSerializer: GraphsonLambdaSerializer } = require('../../type-serializers');
26
27
 
27
28
  module.exports = class LambdaSerializer {
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class LongSerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  // TODO: it's based on BigInt native JavaScript type to completely support
26
28
  // 64 bits integers, but for backward compatibility with current GraphSON
27
29
  // implementation we do not use this for now. Consider its removal.
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class MapSerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,7 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
25
26
  const t = require('../../../../process/traversal');
26
27
 
27
28
  module.exports = class PSerializer {
@@ -22,6 +22,7 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
25
26
  const g = require('../../../graph');
26
27
 
27
28
  module.exports = class PathSerializer {
@@ -22,6 +22,7 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
25
26
  const g = require('../../../graph');
26
27
 
27
28
  module.exports = class PropertySerializer {
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class ShortSerializer {
26
28
  constructor(ioc) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,8 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
26
+
25
27
  module.exports = class StringSerializer {
26
28
  constructor(ioc, ID) {
27
29
  this.ioc = ioc;
@@ -22,6 +22,7 @@
22
22
  */
23
23
  'use strict';
24
24
 
25
+ const { Buffer } = require('buffer');
25
26
  const t = require('../../../../process/traversal');
26
27
 
27
28
  module.exports = class TextPSerializer {