gremlin 3.7.1 → 3.7.3
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.
- package/.eslintrc.js +3 -4
- package/.nvmrc +1 -0
- package/LICENSE +9 -1
- package/NOTICE +1 -1
- package/README.md +1 -1
- package/doc/AnonymousTraversalSource.html +2 -2
- package/doc/Authenticator.html +2 -2
- package/doc/Bytecode.html +2 -2
- package/doc/CardinalityValue.html +2 -2
- package/doc/Client.html +15 -81
- package/doc/Connection.html +15 -169
- package/doc/DataType.js.html +149 -0
- package/doc/DriverRemoteConnection.html +18 -84
- package/doc/EdgeLabelVerificationStrategy.html +2 -2
- package/doc/Graph.html +2 -2
- package/doc/GraphBinaryReader.js.html +132 -0
- package/doc/GraphBinaryWriter.js.html +135 -0
- package/doc/GraphSON2Reader.html +4 -4
- package/doc/GraphSON2Writer.html +5 -5
- package/doc/GraphSON3Reader.html +3 -3
- package/doc/GraphSON3Writer.html +3 -3
- package/doc/GraphTraversal.html +2 -2
- package/doc/GraphTraversalSource.html +2 -2
- package/doc/HaltedTraverserStrategy.html +2 -2
- package/doc/MatchAlgorithmStrategy.html +2 -2
- package/doc/P.html +2 -2
- package/doc/PartitionStrategy.html +2 -2
- package/doc/Path.html +2 -2
- package/doc/PlainTextSaslAuthenticator.html +2 -2
- package/doc/ProductiveByStrategy.html +2 -2
- package/doc/RemoteConnection.html +2 -2
- package/doc/RemoteStrategy.html +2 -2
- package/doc/RemoteTraversal.html +2 -2
- package/doc/ReservedKeysVerificationStrategy.html +2 -2
- package/doc/ResponseError.html +2 -2
- package/doc/ResultSet.html +7 -95
- package/doc/SaslAuthenticator.html +2 -2
- package/doc/SaslMechanismBase.html +2 -2
- package/doc/SaslMechanismPlain.html +7 -7
- package/doc/SeedStrategy.html +2 -2
- package/doc/SubgraphStrategy.html +2 -2
- package/doc/TextP.html +2 -2
- package/doc/Transaction.html +5 -5
- package/doc/Translator.html +2 -2
- package/doc/TraversalStrategies.html +2 -2
- package/doc/TraversalStrategy.html +2 -2
- package/doc/TypeSerializer.html +2 -2
- package/doc/driver_auth_authenticator.js.html +2 -2
- package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +2 -2
- package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +3 -2
- package/doc/driver_auth_plain-text-sasl-authenticator.js.html +2 -2
- package/doc/driver_auth_sasl-authenticator.js.html +2 -2
- package/doc/driver_client.js.html +3 -5
- package/doc/driver_connection.js.html +85 -118
- package/doc/driver_driver-remote-connection.js.html +3 -5
- package/doc/driver_remote-connection.js.html +2 -2
- package/doc/driver_response-error.js.html +2 -2
- package/doc/driver_result-set.js.html +2 -11
- package/doc/global.html +158 -3
- package/doc/index.html +3 -3
- package/doc/module.exports.html +4 -4
- package/doc/process_anonymous-traversal.js.html +2 -2
- package/doc/process_bytecode.js.html +2 -2
- package/doc/process_graph-traversal.js.html +2 -2
- package/doc/process_transaction.js.html +12 -4
- package/doc/process_translator.js.html +5 -5
- package/doc/process_traversal-strategy.js.html +2 -2
- package/doc/process_traversal.js.html +2 -2
- package/doc/structure_graph.js.html +2 -2
- package/doc/structure_io_binary_internals_DataType.js.html +2 -2
- package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +4 -2
- package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +4 -2
- package/doc/structure_io_graph-serializer.js.html +3 -2
- package/doc/structure_io_type-serializers.js.html +2 -2
- package/doc/utils.js.html +181 -0
- package/docker-compose.yml +0 -2
- package/lib/driver/auth/mechanisms/sasl-mechanism-plain.js +1 -0
- package/lib/driver/client.js +1 -3
- package/lib/driver/connection.js +83 -116
- package/lib/driver/driver-remote-connection.js +1 -3
- package/lib/driver/result-set.js +0 -9
- package/lib/process/transaction.js +10 -2
- package/lib/process/translator.js +3 -3
- package/lib/structure/io/binary/internals/AnySerializer.js +2 -0
- package/lib/structure/io/binary/internals/ArraySerializer.js +2 -0
- package/lib/structure/io/binary/internals/BigIntegerSerializer.js +2 -0
- package/lib/structure/io/binary/internals/BooleanSerializer.js +2 -0
- package/lib/structure/io/binary/internals/BulkSetSerializer.js +2 -0
- package/lib/structure/io/binary/internals/ByteBufferSerializer.js +2 -0
- package/lib/structure/io/binary/internals/ByteSerializer.js +2 -0
- package/lib/structure/io/binary/internals/BytecodeSerializer.js +1 -0
- package/lib/structure/io/binary/internals/DateSerializer.js +2 -0
- package/lib/structure/io/binary/internals/DoubleSerializer.js +2 -0
- package/lib/structure/io/binary/internals/EdgeSerializer.js +1 -0
- package/lib/structure/io/binary/internals/EnumSerializer.js +1 -0
- package/lib/structure/io/binary/internals/FloatSerializer.js +2 -0
- package/lib/structure/io/binary/internals/GraphBinaryReader.js +2 -0
- package/lib/structure/io/binary/internals/GraphBinaryWriter.js +2 -0
- package/lib/structure/io/binary/internals/IntSerializer.js +2 -0
- package/lib/structure/io/binary/internals/LambdaSerializer.js +1 -0
- package/lib/structure/io/binary/internals/LongSerializer.js +2 -0
- package/lib/structure/io/binary/internals/LongSerializerNg.js +2 -0
- package/lib/structure/io/binary/internals/MapSerializer.js +2 -0
- package/lib/structure/io/binary/internals/PSerializer.js +1 -0
- package/lib/structure/io/binary/internals/PathSerializer.js +1 -0
- package/lib/structure/io/binary/internals/PropertySerializer.js +1 -0
- package/lib/structure/io/binary/internals/ShortSerializer.js +2 -0
- package/lib/structure/io/binary/internals/StringSerializer.js +2 -0
- package/lib/structure/io/binary/internals/TextPSerializer.js +1 -0
- package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +2 -0
- package/lib/structure/io/binary/internals/TraverserSerializer.js +1 -0
- package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +2 -0
- package/lib/structure/io/binary/internals/UuidSerializer.js +2 -0
- package/lib/structure/io/binary/internals/VertexPropertySerializer.js +5 -1
- package/lib/structure/io/binary/internals/VertexSerializer.js +5 -1
- package/lib/structure/io/binary/internals/utils.js +2 -0
- package/lib/structure/io/graph-serializer.js +1 -0
- package/lib/utils.js +40 -29
- package/licenses/chai +21 -0
- package/package.json +8 -4
package/lib/driver/connection.js
CHANGED
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
*/
|
|
23
23
|
'use strict';
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
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,10 +64,8 @@ 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.
|
|
68
|
+
* @param {Boolean} [options.enableCompression] Enable per-message deflate compression. Defaults to: false.
|
|
74
69
|
* @constructor
|
|
75
70
|
*/
|
|
76
71
|
constructor(url, options) {
|
|
@@ -87,14 +82,12 @@ class Connection extends EventEmitter {
|
|
|
87
82
|
|
|
88
83
|
// A map containing the request id and the handler. The id should be in lower case to prevent string comparison issues.
|
|
89
84
|
this._responseHandlers = {};
|
|
90
|
-
this._reader = options.reader || this
|
|
91
|
-
this._writer = options.writer || this
|
|
85
|
+
this._reader = options.reader || this.#getDefaultReader(this.mimeType);
|
|
86
|
+
this._writer = options.writer || this.#getDefaultWriter(this.mimeType);
|
|
92
87
|
this._openPromise = null;
|
|
93
88
|
this._openCallback = null;
|
|
94
89
|
this._closePromise = null;
|
|
95
90
|
this._closeCallback = null;
|
|
96
|
-
this._pingInterval = null;
|
|
97
|
-
this._pongTimeout = null;
|
|
98
91
|
|
|
99
92
|
this._header = String.fromCharCode(this.mimeType.length) + this.mimeType; // TODO: what if mimeType.length > 255
|
|
100
93
|
this._header_buf = Buffer.from(this._header);
|
|
@@ -102,70 +95,62 @@ class Connection extends EventEmitter {
|
|
|
102
95
|
this.traversalSource = options.traversalSource || 'g';
|
|
103
96
|
this._authenticator = options.authenticator;
|
|
104
97
|
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
98
|
}
|
|
110
99
|
|
|
111
100
|
/**
|
|
112
101
|
* Opens the connection, if its not already opened.
|
|
113
102
|
* @returns {Promise}
|
|
114
103
|
*/
|
|
115
|
-
open() {
|
|
104
|
+
async open() {
|
|
116
105
|
if (this.isOpen) {
|
|
117
|
-
return
|
|
106
|
+
return;
|
|
118
107
|
}
|
|
119
108
|
if (this._openPromise) {
|
|
120
109
|
return this._openPromise;
|
|
121
110
|
}
|
|
122
111
|
|
|
112
|
+
this._openPromise = DeferredPromise();
|
|
113
|
+
|
|
123
114
|
this.emit('log', 'ws open');
|
|
124
115
|
let headers = this.options.headers;
|
|
125
116
|
if (this._enableUserAgentOnConnect) {
|
|
126
117
|
if (!headers) {
|
|
127
118
|
headers = [];
|
|
128
119
|
}
|
|
129
|
-
|
|
120
|
+
|
|
121
|
+
const userAgent = await utils.getUserAgent();
|
|
122
|
+
if (userAgent !== undefined) {
|
|
123
|
+
headers[utils.getUserAgentHeader()] = await utils.getUserAgent();
|
|
124
|
+
}
|
|
130
125
|
}
|
|
131
126
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
const WebSocket = globalThis.WebSocket ?? (await import('ws')).default;
|
|
128
|
+
|
|
129
|
+
this._ws = new WebSocket(
|
|
130
|
+
this.url,
|
|
131
|
+
globalThis.WebSocket === undefined
|
|
132
|
+
? {
|
|
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
|
+
perMessageDeflate: this.options.enableCompression,
|
|
140
|
+
}
|
|
141
|
+
: undefined,
|
|
142
|
+
);
|
|
140
143
|
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
if ('binaryType' in this._ws) {
|
|
145
|
+
this._ws.binaryType = 'arraybuffer';
|
|
146
|
+
}
|
|
143
147
|
|
|
144
|
-
this._ws.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this._pongTimeout = null;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
this._ws.on('ping', () => {
|
|
152
|
-
this.emit('log', 'ws ping received');
|
|
153
|
-
this._ws.pong();
|
|
154
|
-
});
|
|
148
|
+
this._ws.addEventListener('open', this.#handleOpen);
|
|
149
|
+
this._ws.addEventListener('error', this.#handleError);
|
|
150
|
+
this._ws.addEventListener('message', this.#handleMessage);
|
|
151
|
+
this._ws.addEventListener('close', this.#handleClose);
|
|
155
152
|
|
|
156
|
-
return
|
|
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
|
-
}));
|
|
153
|
+
return await this._openPromise;
|
|
169
154
|
}
|
|
170
155
|
|
|
171
156
|
/** @override */
|
|
@@ -195,7 +180,7 @@ class Connection extends EventEmitter {
|
|
|
195
180
|
};
|
|
196
181
|
|
|
197
182
|
const request_buf = this._writer.writeRequest(request);
|
|
198
|
-
const message = Buffer.concat([this._header_buf, request_buf]);
|
|
183
|
+
const message = utils.toArrayBuffer(Buffer.concat([this._header_buf, request_buf]));
|
|
199
184
|
this._ws.send(message);
|
|
200
185
|
}),
|
|
201
186
|
);
|
|
@@ -230,7 +215,7 @@ class Connection extends EventEmitter {
|
|
|
230
215
|
};
|
|
231
216
|
|
|
232
217
|
const request_buf = this._writer.writeRequest(request);
|
|
233
|
-
const message = Buffer.concat([this._header_buf, request_buf]);
|
|
218
|
+
const message = utils.toArrayBuffer(Buffer.concat([this._header_buf, request_buf]));
|
|
234
219
|
this._ws.send(message);
|
|
235
220
|
})
|
|
236
221
|
.catch((err) => readableStream.destroy(err));
|
|
@@ -238,7 +223,7 @@ class Connection extends EventEmitter {
|
|
|
238
223
|
return readableStream;
|
|
239
224
|
}
|
|
240
225
|
|
|
241
|
-
|
|
226
|
+
#getDefaultReader(mimeType) {
|
|
242
227
|
if (mimeType === graphBinaryMimeType) {
|
|
243
228
|
return graphBinaryReader;
|
|
244
229
|
}
|
|
@@ -246,7 +231,7 @@ class Connection extends EventEmitter {
|
|
|
246
231
|
return mimeType === graphSON2MimeType ? new serializer.GraphSON2Reader() : new serializer.GraphSONReader();
|
|
247
232
|
}
|
|
248
233
|
|
|
249
|
-
|
|
234
|
+
#getDefaultWriter(mimeType) {
|
|
250
235
|
if (mimeType === graphBinaryMimeType) {
|
|
251
236
|
return graphBinaryWriter;
|
|
252
237
|
}
|
|
@@ -254,68 +239,58 @@ class Connection extends EventEmitter {
|
|
|
254
239
|
return mimeType === graphSON2MimeType ? new serializer.GraphSON2Writer() : new serializer.GraphSONWriter();
|
|
255
240
|
}
|
|
256
241
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
242
|
+
#handleOpen = () => {
|
|
243
|
+
this._openPromise.resolve();
|
|
244
|
+
this.isOpen = true;
|
|
245
|
+
};
|
|
262
246
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
}
|
|
247
|
+
/**
|
|
248
|
+
* @param {Event} event
|
|
249
|
+
*/
|
|
250
|
+
#handleError = ({ error }) => {
|
|
251
|
+
this._openPromise.reject(error);
|
|
252
|
+
this.emit('log', `ws error ${error}`);
|
|
253
|
+
this.#cleanupWebsocket(error);
|
|
254
|
+
this.emit('socketError', error);
|
|
255
|
+
};
|
|
285
256
|
|
|
286
|
-
|
|
257
|
+
/**
|
|
258
|
+
* @param {CloseEvent} event
|
|
259
|
+
*/
|
|
260
|
+
#handleClose = ({ code, message }) => {
|
|
287
261
|
this.emit('log', `ws close code=${code} message=${message}`);
|
|
288
|
-
this
|
|
262
|
+
this.#cleanupWebsocket();
|
|
289
263
|
if (this._closeCallback) {
|
|
290
264
|
this._closeCallback();
|
|
291
265
|
}
|
|
292
266
|
this.emit('close', code, message);
|
|
293
|
-
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @param {MessageEvent<any>} event
|
|
271
|
+
*/
|
|
272
|
+
#handleMessage = ({ data: _data }) => {
|
|
273
|
+
const data = _data instanceof ArrayBuffer ? Buffer.from(_data) : _data;
|
|
294
274
|
|
|
295
|
-
_handleMessage(data) {
|
|
296
275
|
const response = this._reader.readResponse(data);
|
|
297
276
|
if (response.requestId === null || response.requestId === undefined) {
|
|
298
277
|
// There was a serialization issue on the server that prevented the parsing of the request id
|
|
299
278
|
// We invoke any of the pending handlers with an error
|
|
300
279
|
Object.keys(this._responseHandlers).forEach((requestId) => {
|
|
301
280
|
const handler = this._responseHandlers[requestId];
|
|
302
|
-
this
|
|
281
|
+
this.#clearHandler(requestId);
|
|
303
282
|
if (response.status !== undefined && response.status.message) {
|
|
304
283
|
return handler.callback(
|
|
305
284
|
// TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
|
|
306
285
|
new ResponseError(
|
|
307
|
-
|
|
308
|
-
'Server error (no request information): %s (%d)',
|
|
309
|
-
response.status.message,
|
|
310
|
-
response.status.code,
|
|
311
|
-
),
|
|
286
|
+
`Server error (no request information): ${response.status.message} (${response.status.code})`,
|
|
312
287
|
response.status,
|
|
313
288
|
),
|
|
314
289
|
);
|
|
315
290
|
}
|
|
316
291
|
// TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
|
|
317
292
|
return handler.callback(
|
|
318
|
-
new ResponseError(
|
|
293
|
+
new ResponseError(`Server error (no request information): ${JSON.stringify(response)}`, response.status),
|
|
319
294
|
);
|
|
320
295
|
});
|
|
321
296
|
return;
|
|
@@ -339,13 +314,11 @@ class Connection extends EventEmitter {
|
|
|
339
314
|
|
|
340
315
|
return;
|
|
341
316
|
} else if (response.status.code >= 400) {
|
|
317
|
+
this.#clearHandler(response.requestId);
|
|
342
318
|
// callback in error
|
|
343
319
|
return handler.callback(
|
|
344
320
|
// 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
|
-
),
|
|
321
|
+
new ResponseError(`Server error: ${response.status.message} (${response.status.code})`, response.status),
|
|
349
322
|
);
|
|
350
323
|
}
|
|
351
324
|
|
|
@@ -353,7 +326,7 @@ class Connection extends EventEmitter {
|
|
|
353
326
|
|
|
354
327
|
switch (response.status.code) {
|
|
355
328
|
case responseStatusCode.noContent:
|
|
356
|
-
this
|
|
329
|
+
this.#clearHandler(response.requestId);
|
|
357
330
|
if (isStreamingResponse) {
|
|
358
331
|
handler.result.push(new ResultSet(utils.emptyArray, response.status.attributes));
|
|
359
332
|
return handler.callback(null);
|
|
@@ -377,24 +350,15 @@ class Connection extends EventEmitter {
|
|
|
377
350
|
} else {
|
|
378
351
|
handler.result = response.result.data;
|
|
379
352
|
}
|
|
380
|
-
this
|
|
353
|
+
this.#clearHandler(response.requestId);
|
|
381
354
|
return handler.callback(null, new ResultSet(handler.result, response.status.attributes));
|
|
382
355
|
}
|
|
383
|
-
}
|
|
356
|
+
};
|
|
384
357
|
|
|
385
358
|
/**
|
|
386
359
|
* clean websocket context
|
|
387
360
|
*/
|
|
388
|
-
|
|
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
|
-
|
|
361
|
+
#cleanupWebsocket(err) {
|
|
398
362
|
// Invoke waiting callbacks to complete Promises when closing the websocket
|
|
399
363
|
Object.keys(this._responseHandlers).forEach((requestId) => {
|
|
400
364
|
const handler = this._responseHandlers[requestId];
|
|
@@ -406,7 +370,10 @@ class Connection extends EventEmitter {
|
|
|
406
370
|
handler.callback(cause);
|
|
407
371
|
}
|
|
408
372
|
});
|
|
409
|
-
this._ws.
|
|
373
|
+
this._ws.removeEventListener('open', this.#handleOpen);
|
|
374
|
+
this._ws.removeEventListener('error', this.#handleError);
|
|
375
|
+
this._ws.removeEventListener('message', this.#handleMessage);
|
|
376
|
+
this._ws.removeEventListener('close', this.#handleClose);
|
|
410
377
|
this._openPromise = null;
|
|
411
378
|
this._closePromise = null;
|
|
412
379
|
this.isOpen = false;
|
|
@@ -417,7 +384,7 @@ class Connection extends EventEmitter {
|
|
|
417
384
|
* @param requestId
|
|
418
385
|
* @private
|
|
419
386
|
*/
|
|
420
|
-
|
|
387
|
+
#clearHandler(requestId) {
|
|
421
388
|
delete this._responseHandlers[requestId];
|
|
422
389
|
}
|
|
423
390
|
|
|
@@ -49,10 +49,8 @@ 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.
|
|
53
|
+
* @param {Boolean} [options.enableCompression] Enable per-message deflate compression. Defaults to: false.
|
|
56
54
|
* @constructor
|
|
57
55
|
*/
|
|
58
56
|
constructor(url, options = {}) {
|
package/lib/driver/result-set.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -106,12 +106,12 @@ class Translator {
|
|
|
106
106
|
} else {
|
|
107
107
|
script += anyObject.toString();
|
|
108
108
|
}
|
|
109
|
-
} else if (anyObject === undefined) {
|
|
110
|
-
script += '';
|
|
109
|
+
} else if (anyObject === undefined || anyObject === null) {
|
|
110
|
+
script += 'null';
|
|
111
111
|
} else if (typeof anyObject === 'number' || typeof anyObject === 'boolean') {
|
|
112
112
|
script += anyObject;
|
|
113
113
|
} else {
|
|
114
|
-
script += `'${anyObject}'`;
|
|
114
|
+
script += `'${`${anyObject}`.replace("'", "\\'")}'`; // eslint-disable-line quotes
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
return script;
|
|
@@ -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.
|