gremlin 4.0.0-beta.2 → 4.0.0-beta.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/build/cjs/driver/auth.cjs +11 -4
- package/build/cjs/driver/auth.d.cts +1 -1
- package/build/cjs/driver/client.cjs +82 -38
- package/build/cjs/driver/client.d.cts +30 -27
- package/build/cjs/driver/connection.cjs +173 -60
- package/build/cjs/driver/connection.d.cts +69 -26
- package/build/cjs/driver/dispatcher.browser.cjs +57 -0
- package/build/cjs/driver/dispatcher.browser.d.cts +35 -0
- package/build/cjs/driver/dispatcher.cjs +101 -0
- package/build/cjs/driver/dispatcher.d.cts +48 -0
- package/build/cjs/driver/driver-remote-connection.cjs +27 -15
- package/build/cjs/driver/driver-remote-connection.d.cts +10 -4
- package/build/cjs/driver/http-request.cjs +64 -0
- package/build/cjs/driver/http-request.d.cts +28 -0
- package/build/cjs/driver/logger.cjs +45 -0
- package/build/cjs/driver/logger.d.cts +29 -0
- package/build/cjs/driver/remote-connection.cjs +5 -8
- package/build/cjs/driver/remote-connection.d.cts +6 -21
- package/build/cjs/driver/request-message.cjs +110 -21
- package/build/cjs/driver/request-message.d.cts +38 -8
- package/build/cjs/driver/response-error.cjs +3 -3
- package/build/cjs/driver/response-error.d.cts +2 -2
- package/build/cjs/index.cjs +21 -0
- package/build/cjs/index.d.cts +47 -0
- package/build/cjs/language/grammar/GremlinLexer.cjs +1669 -1615
- package/build/cjs/language/grammar/GremlinLexer.d.cts +325 -316
- package/build/cjs/language/grammar/GremlinListener.cjs +322 -8
- package/build/cjs/language/grammar/GremlinListener.d.cts +351 -10
- package/build/cjs/language/grammar/GremlinParser.cjs +8700 -5798
- package/build/cjs/language/grammar/GremlinParser.d.cts +998 -619
- package/build/cjs/language/translator/AnonymizedTranslateVisitor.cjs +9 -0
- package/build/cjs/language/translator/AnonymizedTranslateVisitor.d.cts +3 -0
- package/build/cjs/language/translator/DotNetTranslateVisitor.cjs +113 -4
- package/build/cjs/language/translator/DotNetTranslateVisitor.d.cts +13 -2
- package/build/cjs/language/translator/GoTranslateVisitor.cjs +82 -0
- package/build/cjs/language/translator/GoTranslateVisitor.d.cts +9 -0
- package/build/cjs/language/translator/GroovyTranslateVisitor.cjs +23 -0
- package/build/cjs/language/translator/GroovyTranslateVisitor.d.cts +3 -0
- package/build/cjs/language/translator/JavaTranslateVisitor.cjs +23 -0
- package/build/cjs/language/translator/JavaTranslateVisitor.d.cts +3 -0
- package/build/cjs/language/translator/JavascriptTranslateVisitor.cjs +11 -0
- package/build/cjs/language/translator/JavascriptTranslateVisitor.d.cts +3 -0
- package/build/cjs/language/translator/PythonTranslateVisitor.cjs +39 -3
- package/build/cjs/language/translator/PythonTranslateVisitor.d.cts +3 -0
- package/build/cjs/language/translator/TranslateVisitor.cjs +9 -0
- package/build/cjs/language/translator/TranslateVisitor.d.cts +3 -0
- package/build/cjs/process/anonymous-traversal.cjs +5 -1
- package/build/cjs/process/graph-traversal.cjs +139 -8
- package/build/cjs/process/graph-traversal.d.cts +84 -3
- package/build/cjs/process/gremlin-lang.cjs +119 -7
- package/build/cjs/process/gremlin-lang.d.cts +6 -1
- package/build/cjs/process/gvalue.cjs +42 -0
- package/build/cjs/process/gvalue.d.cts +7 -0
- package/build/cjs/process/transaction.cjs +125 -23
- package/build/cjs/process/transaction.d.cts +50 -14
- package/build/cjs/process/traversal.cjs +105 -48
- package/build/cjs/process/traversal.d.cts +36 -10
- package/build/cjs/structure/PDTRegistry.cjs +116 -0
- package/build/cjs/structure/PDTRegistry.d.cts +34 -0
- package/build/cjs/structure/graph.cjs +351 -8
- package/build/cjs/structure/graph.d.cts +122 -3
- package/build/cjs/structure/io/binary/GraphBinary.cjs +68 -39
- package/build/cjs/structure/io/binary/GraphBinary.d.cts +15 -1
- package/build/cjs/structure/io/binary/internals/AnySerializer.cjs +34 -17
- package/build/cjs/structure/io/binary/internals/AnySerializer.d.cts +12 -2
- package/build/cjs/structure/io/binary/internals/ArraySerializer.cjs +41 -72
- package/build/cjs/structure/io/binary/internals/ArraySerializer.d.cts +14 -7
- package/build/cjs/structure/io/binary/internals/BigIntegerSerializer.cjs +34 -54
- package/build/cjs/structure/io/binary/internals/BigIntegerSerializer.d.cts +12 -7
- package/build/cjs/structure/io/binary/internals/BinarySerializer.cjs +31 -51
- package/build/cjs/structure/io/binary/internals/BinarySerializer.d.cts +12 -4
- package/build/cjs/structure/io/binary/internals/BooleanSerializer.cjs +28 -42
- package/build/cjs/structure/io/binary/internals/BooleanSerializer.d.cts +12 -4
- package/build/cjs/structure/io/binary/internals/ByteSerializer.cjs +24 -38
- package/build/cjs/structure/io/binary/internals/ByteSerializer.d.cts +12 -4
- package/build/cjs/structure/io/binary/internals/CompositePDTSerializer.cjs +81 -0
- package/build/cjs/structure/io/binary/internals/CompositePDTSerializer.d.cts +10 -0
- package/build/cjs/structure/io/binary/internals/DateTimeSerializer.cjs +52 -69
- package/build/cjs/structure/io/binary/internals/DateTimeSerializer.d.cts +12 -7
- package/build/cjs/structure/io/binary/internals/DoubleSerializer.cjs +24 -38
- package/build/cjs/structure/io/binary/internals/DoubleSerializer.d.cts +12 -4
- package/build/cjs/structure/io/binary/internals/EdgeSerializer.cjs +69 -124
- package/build/cjs/structure/io/binary/internals/EdgeSerializer.d.cts +14 -12
- package/build/cjs/structure/io/binary/internals/EnumSerializer.cjs +47 -59
- package/build/cjs/structure/io/binary/internals/EnumSerializer.d.cts +19 -4
- package/build/cjs/structure/io/binary/internals/FloatSerializer.cjs +24 -38
- package/build/cjs/structure/io/binary/internals/FloatSerializer.d.cts +12 -4
- package/build/cjs/structure/io/binary/internals/GraphBinaryReader.cjs +111 -37
- package/build/cjs/structure/io/binary/internals/GraphBinaryReader.d.cts +26 -2
- package/build/cjs/structure/io/binary/internals/GraphBinaryWriter.cjs +6 -6
- package/build/cjs/structure/io/binary/internals/GraphSerializer.cjs +184 -0
- package/build/cjs/structure/io/binary/internals/GraphSerializer.d.cts +22 -0
- package/build/cjs/structure/io/binary/internals/IntSerializer.cjs +33 -38
- package/build/cjs/structure/io/binary/internals/IntSerializer.d.cts +19 -4
- package/build/cjs/structure/io/binary/internals/LongSerializer.cjs +29 -42
- package/build/cjs/structure/io/binary/internals/LongSerializer.d.cts +13 -4
- package/build/cjs/structure/io/binary/internals/MapSerializer.cjs +36 -70
- package/build/cjs/structure/io/binary/internals/MapSerializer.d.cts +14 -7
- package/build/cjs/structure/io/binary/internals/MarkerSerializer.cjs +30 -33
- package/build/cjs/structure/io/binary/internals/MarkerSerializer.d.cts +13 -4
- package/build/cjs/structure/io/binary/internals/NumberSerializationStrategy.cjs +28 -2
- package/build/cjs/structure/io/binary/internals/NumberSerializationStrategy.d.cts +0 -3
- package/build/cjs/structure/io/binary/internals/PathSerializer.cjs +30 -55
- package/build/cjs/structure/io/binary/internals/PathSerializer.d.cts +14 -7
- package/build/cjs/structure/io/binary/internals/PrimitivePDTSerializer.cjs +80 -0
- package/build/cjs/structure/io/binary/internals/PrimitivePDTSerializer.d.cts +10 -0
- package/build/cjs/structure/io/binary/internals/PropertySerializer.cjs +32 -69
- package/build/cjs/structure/io/binary/internals/PropertySerializer.d.cts +14 -7
- package/build/cjs/structure/io/binary/internals/SetSerializer.cjs +39 -73
- package/build/cjs/structure/io/binary/internals/SetSerializer.d.cts +14 -7
- package/build/cjs/structure/io/binary/internals/ShortSerializer.cjs +24 -38
- package/build/cjs/structure/io/binary/internals/ShortSerializer.d.cts +12 -4
- package/build/cjs/structure/io/binary/internals/StreamReader.cjs +184 -0
- package/build/cjs/structure/io/binary/internals/StreamReader.d.cts +69 -0
- package/build/cjs/structure/io/binary/internals/StringSerializer.cjs +34 -53
- package/build/cjs/structure/io/binary/internals/StringSerializer.d.cts +14 -4
- package/build/cjs/structure/io/binary/internals/StubSerializer.cjs +2 -1
- package/build/cjs/structure/io/binary/internals/StubSerializer.d.cts +1 -1
- package/build/cjs/structure/io/binary/internals/TreeSerializer.cjs +139 -0
- package/build/cjs/structure/io/binary/internals/TreeSerializer.d.cts +54 -0
- package/build/cjs/structure/io/binary/internals/UnspecifiedNullSerializer.cjs +8 -31
- package/build/cjs/structure/io/binary/internals/UnspecifiedNullSerializer.d.cts +6 -4
- package/build/cjs/structure/io/binary/internals/UuidSerializer.cjs +33 -49
- package/build/cjs/structure/io/binary/internals/UuidSerializer.d.cts +12 -7
- package/build/cjs/structure/io/binary/internals/VertexPropertySerializer.cjs +37 -95
- package/build/cjs/structure/io/binary/internals/VertexPropertySerializer.d.cts +14 -7
- package/build/cjs/structure/io/binary/internals/VertexSerializer.cjs +41 -68
- package/build/cjs/structure/io/binary/internals/VertexSerializer.d.cts +14 -9
- package/build/cjs/utils.cjs +157 -40
- package/build/cjs/utils.d.cts +62 -4
- package/build/esm/driver/auth.d.ts +1 -1
- package/build/esm/driver/auth.js +11 -4
- package/build/esm/driver/client.d.ts +30 -27
- package/build/esm/driver/client.js +82 -38
- package/build/esm/driver/connection.d.ts +69 -26
- package/build/esm/driver/connection.js +172 -60
- package/build/esm/driver/dispatcher.browser.d.ts +35 -0
- package/build/esm/driver/dispatcher.browser.js +53 -0
- package/build/esm/driver/dispatcher.d.ts +48 -0
- package/build/esm/driver/dispatcher.js +94 -0
- package/build/esm/driver/driver-remote-connection.d.ts +10 -4
- package/build/esm/driver/driver-remote-connection.js +27 -15
- package/build/esm/driver/http-request.d.ts +28 -0
- package/build/esm/driver/http-request.js +60 -0
- package/build/esm/driver/logger.d.ts +29 -0
- package/build/esm/driver/logger.js +42 -0
- package/build/esm/driver/remote-connection.d.ts +6 -21
- package/build/esm/driver/remote-connection.js +5 -8
- package/build/esm/driver/request-message.d.ts +38 -8
- package/build/esm/driver/request-message.js +107 -21
- package/build/esm/driver/response-error.d.ts +2 -2
- package/build/esm/driver/response-error.js +3 -3
- package/build/esm/index.d.ts +47 -0
- package/build/esm/index.js +21 -0
- package/build/esm/language/grammar/GremlinLexer.d.ts +325 -316
- package/build/esm/language/grammar/GremlinLexer.js +1669 -1615
- package/build/esm/language/grammar/GremlinListener.d.ts +351 -10
- package/build/esm/language/grammar/GremlinListener.js +322 -8
- package/build/esm/language/grammar/GremlinParser.d.ts +998 -619
- package/build/esm/language/grammar/GremlinParser.js +8646 -5778
- package/build/esm/language/translator/AnonymizedTranslateVisitor.d.ts +3 -0
- package/build/esm/language/translator/AnonymizedTranslateVisitor.js +9 -0
- package/build/esm/language/translator/DotNetTranslateVisitor.d.ts +13 -2
- package/build/esm/language/translator/DotNetTranslateVisitor.js +113 -4
- package/build/esm/language/translator/GoTranslateVisitor.d.ts +9 -0
- package/build/esm/language/translator/GoTranslateVisitor.js +82 -0
- package/build/esm/language/translator/GroovyTranslateVisitor.d.ts +3 -0
- package/build/esm/language/translator/GroovyTranslateVisitor.js +23 -0
- package/build/esm/language/translator/JavaTranslateVisitor.d.ts +3 -0
- package/build/esm/language/translator/JavaTranslateVisitor.js +23 -0
- package/build/esm/language/translator/JavascriptTranslateVisitor.d.ts +3 -0
- package/build/esm/language/translator/JavascriptTranslateVisitor.js +11 -0
- package/build/esm/language/translator/PythonTranslateVisitor.d.ts +3 -0
- package/build/esm/language/translator/PythonTranslateVisitor.js +39 -3
- package/build/esm/language/translator/TranslateVisitor.d.ts +3 -0
- package/build/esm/language/translator/TranslateVisitor.js +9 -0
- package/build/esm/process/anonymous-traversal.js +5 -1
- package/build/esm/process/graph-traversal.d.ts +84 -3
- package/build/esm/process/graph-traversal.js +139 -8
- package/build/esm/process/gremlin-lang.d.ts +6 -1
- package/build/esm/process/gremlin-lang.js +121 -9
- package/build/esm/process/gvalue.d.ts +7 -0
- package/build/esm/process/gvalue.js +38 -0
- package/build/esm/process/transaction.d.ts +50 -14
- package/build/esm/process/transaction.js +122 -23
- package/build/esm/process/traversal.d.ts +36 -10
- package/build/esm/process/traversal.js +104 -47
- package/build/esm/structure/PDTRegistry.d.ts +34 -0
- package/build/esm/structure/PDTRegistry.js +112 -0
- package/build/esm/structure/graph.d.ts +122 -3
- package/build/esm/structure/graph.js +347 -7
- package/build/esm/structure/io/binary/GraphBinary.d.ts +15 -1
- package/build/esm/structure/io/binary/GraphBinary.js +66 -38
- package/build/esm/structure/io/binary/internals/AnySerializer.d.ts +12 -2
- package/build/esm/structure/io/binary/internals/AnySerializer.js +34 -17
- package/build/esm/structure/io/binary/internals/ArraySerializer.d.ts +14 -7
- package/build/esm/structure/io/binary/internals/ArraySerializer.js +41 -72
- package/build/esm/structure/io/binary/internals/BigIntegerSerializer.d.ts +12 -7
- package/build/esm/structure/io/binary/internals/BigIntegerSerializer.js +34 -54
- package/build/esm/structure/io/binary/internals/BinarySerializer.d.ts +12 -4
- package/build/esm/structure/io/binary/internals/BinarySerializer.js +31 -51
- package/build/esm/structure/io/binary/internals/BooleanSerializer.d.ts +12 -4
- package/build/esm/structure/io/binary/internals/BooleanSerializer.js +28 -42
- package/build/esm/structure/io/binary/internals/ByteSerializer.d.ts +12 -4
- package/build/esm/structure/io/binary/internals/ByteSerializer.js +24 -38
- package/build/esm/structure/io/binary/internals/CompositePDTSerializer.d.ts +10 -0
- package/build/esm/structure/io/binary/internals/CompositePDTSerializer.js +78 -0
- package/build/esm/structure/io/binary/internals/DateTimeSerializer.d.ts +12 -7
- package/build/esm/structure/io/binary/internals/DateTimeSerializer.js +52 -69
- package/build/esm/structure/io/binary/internals/DoubleSerializer.d.ts +12 -4
- package/build/esm/structure/io/binary/internals/DoubleSerializer.js +24 -38
- package/build/esm/structure/io/binary/internals/EdgeSerializer.d.ts +14 -12
- package/build/esm/structure/io/binary/internals/EdgeSerializer.js +69 -124
- package/build/esm/structure/io/binary/internals/EnumSerializer.d.ts +19 -4
- package/build/esm/structure/io/binary/internals/EnumSerializer.js +47 -59
- package/build/esm/structure/io/binary/internals/FloatSerializer.d.ts +12 -4
- package/build/esm/structure/io/binary/internals/FloatSerializer.js +24 -38
- package/build/esm/structure/io/binary/internals/GraphBinaryReader.d.ts +26 -2
- package/build/esm/structure/io/binary/internals/GraphBinaryReader.js +108 -37
- package/build/esm/structure/io/binary/internals/GraphBinaryWriter.js +6 -6
- package/build/esm/structure/io/binary/internals/GraphSerializer.d.ts +22 -0
- package/build/esm/structure/io/binary/internals/GraphSerializer.js +181 -0
- package/build/esm/structure/io/binary/internals/IntSerializer.d.ts +19 -4
- package/build/esm/structure/io/binary/internals/IntSerializer.js +33 -38
- package/build/esm/structure/io/binary/internals/LongSerializer.d.ts +13 -4
- package/build/esm/structure/io/binary/internals/LongSerializer.js +29 -42
- package/build/esm/structure/io/binary/internals/MapSerializer.d.ts +14 -7
- package/build/esm/structure/io/binary/internals/MapSerializer.js +36 -70
- package/build/esm/structure/io/binary/internals/MarkerSerializer.d.ts +13 -4
- package/build/esm/structure/io/binary/internals/MarkerSerializer.js +29 -33
- package/build/esm/structure/io/binary/internals/NumberSerializationStrategy.d.ts +0 -3
- package/build/esm/structure/io/binary/internals/NumberSerializationStrategy.js +28 -2
- package/build/esm/structure/io/binary/internals/PathSerializer.d.ts +14 -7
- package/build/esm/structure/io/binary/internals/PathSerializer.js +30 -55
- package/build/esm/structure/io/binary/internals/PrimitivePDTSerializer.d.ts +10 -0
- package/build/esm/structure/io/binary/internals/PrimitivePDTSerializer.js +77 -0
- package/build/esm/structure/io/binary/internals/PropertySerializer.d.ts +14 -7
- package/build/esm/structure/io/binary/internals/PropertySerializer.js +32 -69
- package/build/esm/structure/io/binary/internals/SetSerializer.d.ts +14 -7
- package/build/esm/structure/io/binary/internals/SetSerializer.js +39 -73
- package/build/esm/structure/io/binary/internals/ShortSerializer.d.ts +12 -4
- package/build/esm/structure/io/binary/internals/ShortSerializer.js +24 -38
- package/build/esm/structure/io/binary/internals/StreamReader.d.ts +69 -0
- package/build/esm/structure/io/binary/internals/StreamReader.js +181 -0
- package/build/esm/structure/io/binary/internals/StringSerializer.d.ts +14 -4
- package/build/esm/structure/io/binary/internals/StringSerializer.js +34 -53
- package/build/esm/structure/io/binary/internals/StubSerializer.d.ts +1 -1
- package/build/esm/structure/io/binary/internals/StubSerializer.js +2 -1
- package/build/esm/structure/io/binary/internals/TreeSerializer.d.ts +54 -0
- package/build/esm/structure/io/binary/internals/TreeSerializer.js +136 -0
- package/build/esm/structure/io/binary/internals/UnspecifiedNullSerializer.d.ts +6 -4
- package/build/esm/structure/io/binary/internals/UnspecifiedNullSerializer.js +8 -31
- package/build/esm/structure/io/binary/internals/UuidSerializer.d.ts +12 -7
- package/build/esm/structure/io/binary/internals/UuidSerializer.js +33 -49
- package/build/esm/structure/io/binary/internals/VertexPropertySerializer.d.ts +14 -7
- package/build/esm/structure/io/binary/internals/VertexPropertySerializer.js +37 -95
- package/build/esm/structure/io/binary/internals/VertexSerializer.d.ts +14 -9
- package/build/esm/structure/io/binary/internals/VertexSerializer.js +41 -68
- package/build/esm/utils.d.ts +62 -4
- package/build/esm/utils.js +145 -6
- package/package.json +27 -18
|
@@ -21,31 +21,40 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { Buffer } from 'buffer';
|
|
23
23
|
import { EventEmitter } from 'eventemitter3';
|
|
24
|
-
import ioc from '../structure/io/binary/GraphBinary.js';
|
|
24
|
+
import ioc, { createPreciseReader } from '../structure/io/binary/GraphBinary.js';
|
|
25
|
+
import GraphBinaryReader from '../structure/io/binary/internals/GraphBinaryReader.js';
|
|
26
|
+
import StreamReader from '../structure/io/binary/internals/StreamReader.js';
|
|
25
27
|
import * as utils from '../utils.js';
|
|
26
28
|
import ResultSet from './result-set.js';
|
|
29
|
+
import { RequestMessage } from "./request-message.js";
|
|
30
|
+
import { HttpRequest } from './http-request.js';
|
|
27
31
|
import ResponseError from './response-error.js';
|
|
28
32
|
import { Traverser } from '../process/traversal.js';
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
import { buildDispatcher, httpFetch } from './dispatcher.js';
|
|
34
|
+
import { normalizeLogger } from './logger.js';
|
|
31
35
|
const responseStatusCode = {
|
|
32
36
|
success: 200,
|
|
33
37
|
noContent: 204,
|
|
34
38
|
partialContent: 206,
|
|
35
|
-
authenticationChallenge: 407,
|
|
36
39
|
};
|
|
40
|
+
/** The default per-request batch size used when neither the request nor the connection sets one. */
|
|
41
|
+
export const DEFAULT_BATCH_SIZE = 64;
|
|
37
42
|
/**
|
|
38
43
|
* Represents a single connection to a Gremlin Server.
|
|
39
44
|
*/
|
|
40
45
|
export default class Connection extends EventEmitter {
|
|
41
46
|
url;
|
|
42
47
|
options;
|
|
43
|
-
|
|
44
|
-
_writer;
|
|
48
|
+
_responseSerializer;
|
|
45
49
|
isOpen = true;
|
|
46
50
|
traversalSource;
|
|
47
51
|
_enableUserAgentOnConnect;
|
|
48
52
|
_interceptors;
|
|
53
|
+
_dispatcher;
|
|
54
|
+
_compression;
|
|
55
|
+
_batchSize;
|
|
56
|
+
_bulkResults;
|
|
57
|
+
_log;
|
|
49
58
|
/**
|
|
50
59
|
* Creates a new instance of {@link Connection}.
|
|
51
60
|
* @param {String} url The resource uri.
|
|
@@ -55,16 +64,41 @@ export default class Connection extends EventEmitter {
|
|
|
55
64
|
super();
|
|
56
65
|
this.url = url;
|
|
57
66
|
this.options = options;
|
|
58
|
-
this.
|
|
59
|
-
|
|
67
|
+
this._responseSerializer =
|
|
68
|
+
options.responseSerializer || (options.preciseNumbers === true ? createPreciseReader() : new GraphBinaryReader(ioc));
|
|
69
|
+
if (options.pdtRegistry) {
|
|
70
|
+
this._responseSerializer.pdtRegistry = options.pdtRegistry;
|
|
71
|
+
}
|
|
60
72
|
this.traversalSource = options.traversalSource || 'g';
|
|
61
73
|
this._enableUserAgentOnConnect = options.enableUserAgentOnConnect !== false;
|
|
74
|
+
this._log = normalizeLogger(options.logger);
|
|
75
|
+
if (options.compression === undefined) {
|
|
76
|
+
this._compression = 'deflate';
|
|
77
|
+
}
|
|
78
|
+
else if (options.compression === 'none' || options.compression === 'deflate') {
|
|
79
|
+
this._compression = options.compression;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw new TypeError(`compression must be 'none' or 'deflate'`);
|
|
83
|
+
}
|
|
84
|
+
this._batchSize = options.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
85
|
+
this._bulkResults = options.bulkResults ?? false;
|
|
86
|
+
// The driver builds and owns the undici dispatcher from the discrete options.
|
|
87
|
+
// TLS is configured through the Node/undici runtime (e.g. NODE_EXTRA_CA_CERTS),
|
|
88
|
+
// not through a driver option.
|
|
89
|
+
this._dispatcher = buildDispatcher({
|
|
90
|
+
maxConnections: options.maxConnections,
|
|
91
|
+
readTimeoutMillis: options.readTimeoutMillis,
|
|
92
|
+
maxResponseHeaderBytes: options.maxResponseHeaderBytes,
|
|
93
|
+
keepAliveTimeMillis: options.keepAliveTimeMillis,
|
|
94
|
+
proxy: options.proxy,
|
|
95
|
+
});
|
|
62
96
|
const interceptors = options.interceptors;
|
|
63
97
|
if (typeof interceptors === 'function') {
|
|
64
98
|
this._interceptors = [interceptors];
|
|
65
99
|
}
|
|
66
100
|
else if (Array.isArray(interceptors)) {
|
|
67
|
-
this._interceptors = interceptors;
|
|
101
|
+
this._interceptors = [...interceptors];
|
|
68
102
|
}
|
|
69
103
|
else if (interceptors === undefined || interceptors === null) {
|
|
70
104
|
this._interceptors = [];
|
|
@@ -72,6 +106,24 @@ export default class Connection extends EventEmitter {
|
|
|
72
106
|
else {
|
|
73
107
|
throw new TypeError('interceptors must be a function, array, or undefined');
|
|
74
108
|
}
|
|
109
|
+
// Auth interceptor is always last so it runs after user interceptors
|
|
110
|
+
if (options.auth) {
|
|
111
|
+
this._interceptors.push(options.auth);
|
|
112
|
+
}
|
|
113
|
+
this._log('debug', `Connection created for ${this.url}`);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The connection-level default batch size, used to fill a request's `batchSize` when unset.
|
|
117
|
+
*/
|
|
118
|
+
get batchSize() {
|
|
119
|
+
return this._batchSize;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The connection-level default for `bulkResults`, applied to every request unless overridden
|
|
123
|
+
* per-request. Defaults to `false`.
|
|
124
|
+
*/
|
|
125
|
+
get bulkResults() {
|
|
126
|
+
return this._bulkResults;
|
|
75
127
|
}
|
|
76
128
|
/**
|
|
77
129
|
* Opens the connection, if its not already opened.
|
|
@@ -81,34 +133,99 @@ export default class Connection extends EventEmitter {
|
|
|
81
133
|
// No-op for HTTP connections
|
|
82
134
|
return Promise.resolve();
|
|
83
135
|
}
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return this.#handleResponse(response);
|
|
91
|
-
});
|
|
136
|
+
/**
|
|
137
|
+
* Send a request and buffer the entire response. Returns a Promise<ResultSet>.
|
|
138
|
+
*/
|
|
139
|
+
async submit(request) {
|
|
140
|
+
const response = await this.#makeHttpRequest(request);
|
|
141
|
+
return this.#handleResponse(response);
|
|
92
142
|
}
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Send a request and stream the response incrementally.
|
|
145
|
+
* Returns an AsyncGenerator that yields deserialized result items.
|
|
146
|
+
* For bulked responses, yields Traverser objects.
|
|
147
|
+
*
|
|
148
|
+
* In the GraphBinary v4 streaming protocol, the server sends the status after all
|
|
149
|
+
* result data. If the server encounters an error mid-traversal, values yielded before
|
|
150
|
+
* the error are valid partial results. A ResponseError is thrown after the last value
|
|
151
|
+
* has been yielded.
|
|
152
|
+
*
|
|
153
|
+
* @param {RequestMessage} request
|
|
154
|
+
* @returns {AsyncGenerator<any>}
|
|
155
|
+
*/
|
|
156
|
+
async *stream(request) {
|
|
157
|
+
const abortController = new AbortController();
|
|
158
|
+
let response;
|
|
159
|
+
try {
|
|
160
|
+
response = await this.#makeHttpRequest(request, abortController.signal);
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
throw new Error(`Stream request failed: ${e.message}`, { cause: e });
|
|
164
|
+
}
|
|
165
|
+
if (!response.ok) {
|
|
166
|
+
// For error responses, buffer and parse the error body
|
|
167
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
168
|
+
const errorMessage = `Server returned HTTP ${response.status}: ${response.statusText}`;
|
|
169
|
+
const contentType = response.headers.get("Content-Type");
|
|
170
|
+
const reader = this.#getReaderForContentType(contentType);
|
|
171
|
+
try {
|
|
172
|
+
if (reader) {
|
|
173
|
+
const deserialized = await reader.readResponse(buffer);
|
|
174
|
+
throw new ResponseError(errorMessage, {
|
|
175
|
+
code: deserialized.status.code,
|
|
176
|
+
message: deserialized.status.message || response.statusText,
|
|
177
|
+
exception: deserialized.status.exception,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
else if (contentType === 'application/json') {
|
|
181
|
+
const errorBody = JSON.parse(buffer.toString());
|
|
182
|
+
throw new ResponseError(errorMessage, {
|
|
183
|
+
code: response.status,
|
|
184
|
+
message: errorBody.message || errorBody.error || response.statusText,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
if (err instanceof ResponseError)
|
|
190
|
+
throw err;
|
|
191
|
+
}
|
|
192
|
+
throw new ResponseError(errorMessage, {
|
|
193
|
+
code: response.status,
|
|
194
|
+
message: response.statusText,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (!response.body) {
|
|
198
|
+
// 204 No Content - nothing to yield
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const streamReader = StreamReader.fromReadableStream(response.body);
|
|
202
|
+
let completed = false;
|
|
203
|
+
try {
|
|
204
|
+
yield* this._responseSerializer.readResponseStream(streamReader);
|
|
205
|
+
completed = true;
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
if (!completed) {
|
|
209
|
+
// Consumer broke out early or an error occurred - abort to release the connection
|
|
210
|
+
abortController.abort();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
96
213
|
}
|
|
97
214
|
#getReaderForContentType(contentType) {
|
|
98
215
|
if (!contentType) {
|
|
99
|
-
return this.
|
|
216
|
+
return this._responseSerializer;
|
|
100
217
|
}
|
|
101
|
-
if (contentType === this.
|
|
102
|
-
return this.
|
|
218
|
+
if (contentType === this._responseSerializer.mimeType) {
|
|
219
|
+
return this._responseSerializer;
|
|
103
220
|
}
|
|
104
221
|
return null;
|
|
105
222
|
}
|
|
106
|
-
async #makeHttpRequest(
|
|
223
|
+
async #makeHttpRequest(request, signal) {
|
|
107
224
|
const headers = {
|
|
108
|
-
'Accept': this.
|
|
225
|
+
'Accept': this._responseSerializer.mimeType,
|
|
109
226
|
};
|
|
110
|
-
if (this.
|
|
111
|
-
headers['
|
|
227
|
+
if (this._compression === 'deflate') {
|
|
228
|
+
headers['Accept-Encoding'] = 'deflate';
|
|
112
229
|
}
|
|
113
230
|
if (this._enableUserAgentOnConnect) {
|
|
114
231
|
const userAgent = await utils.getUserAgent();
|
|
@@ -116,29 +233,35 @@ export default class Connection extends EventEmitter {
|
|
|
116
233
|
headers[utils.getUserAgentHeader()] = userAgent;
|
|
117
234
|
}
|
|
118
235
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
236
|
+
const httpRequest = new HttpRequest('POST', this.url, headers, request);
|
|
237
|
+
// Promote transactionId to HTTP header before interceptors run.
|
|
238
|
+
// The field remains in the serialized body as well (dual transmission
|
|
239
|
+
// per the HTTP transaction protocol specification).
|
|
240
|
+
if (request instanceof RequestMessage) {
|
|
241
|
+
const fields = request.getFields();
|
|
242
|
+
if (fields.has('transactionId')) {
|
|
243
|
+
httpRequest.headers['X-Transaction-Id'] = fields.get('transactionId');
|
|
244
|
+
}
|
|
123
245
|
}
|
|
124
|
-
let httpRequest = {
|
|
125
|
-
url: this.url,
|
|
126
|
-
method: 'POST',
|
|
127
|
-
headers,
|
|
128
|
-
body,
|
|
129
|
-
};
|
|
130
246
|
for (let i = 0; i < this._interceptors.length; i++) {
|
|
131
247
|
try {
|
|
132
|
-
|
|
248
|
+
await this._interceptors[i](httpRequest);
|
|
133
249
|
}
|
|
134
250
|
catch (e) {
|
|
135
251
|
throw new Error(`Request interceptor at index ${i} failed: ${e.message}`, { cause: e });
|
|
136
252
|
}
|
|
137
253
|
}
|
|
138
|
-
|
|
254
|
+
// Auto-serialize body to JSON after interceptors run (idempotent if already serialized)
|
|
255
|
+
httpRequest.serializeBody();
|
|
256
|
+
this._log('debug', `Sending ${httpRequest.method} request to ${httpRequest.url}`);
|
|
257
|
+
return httpFetch.fetch(httpRequest.url, {
|
|
139
258
|
method: httpRequest.method,
|
|
140
259
|
headers: httpRequest.headers,
|
|
141
260
|
body: httpRequest.body,
|
|
261
|
+
signal,
|
|
262
|
+
// Node only: the undici dispatcher carries the connection-pool options. In the browser
|
|
263
|
+
// it is undefined and the field is omitted, letting the user agent manage the transport.
|
|
264
|
+
...(this._dispatcher ? { dispatcher: this._dispatcher } : {}),
|
|
142
265
|
});
|
|
143
266
|
}
|
|
144
267
|
async #handleResponse(response) {
|
|
@@ -149,16 +272,11 @@ export default class Connection extends EventEmitter {
|
|
|
149
272
|
const errorMessage = `Server returned HTTP ${response.status}: ${response.statusText}`;
|
|
150
273
|
try {
|
|
151
274
|
if (reader) {
|
|
152
|
-
const deserialized = reader.readResponse(buffer);
|
|
153
|
-
const attributes = new Map();
|
|
154
|
-
if (deserialized.status.exception) {
|
|
155
|
-
attributes.set('exceptions', deserialized.status.exception);
|
|
156
|
-
attributes.set('stackTrace', deserialized.status.exception);
|
|
157
|
-
}
|
|
275
|
+
const deserialized = await reader.readResponse(buffer);
|
|
158
276
|
throw new ResponseError(errorMessage, {
|
|
159
277
|
code: deserialized.status.code,
|
|
160
278
|
message: deserialized.status.message || response.statusText,
|
|
161
|
-
|
|
279
|
+
exception: deserialized.status.exception,
|
|
162
280
|
});
|
|
163
281
|
}
|
|
164
282
|
else if (contentType === 'application/json') {
|
|
@@ -166,7 +284,6 @@ export default class Connection extends EventEmitter {
|
|
|
166
284
|
throw new ResponseError(errorMessage, {
|
|
167
285
|
code: response.status,
|
|
168
286
|
message: errorBody.message || errorBody.error || response.statusText,
|
|
169
|
-
attributes: new Map(),
|
|
170
287
|
});
|
|
171
288
|
}
|
|
172
289
|
}
|
|
@@ -178,23 +295,17 @@ export default class Connection extends EventEmitter {
|
|
|
178
295
|
throw new ResponseError(errorMessage, {
|
|
179
296
|
code: response.status,
|
|
180
297
|
message: response.statusText,
|
|
181
|
-
attributes: new Map(),
|
|
182
298
|
});
|
|
183
299
|
}
|
|
184
300
|
if (!reader) {
|
|
185
|
-
throw new Error(`Response Content-Type '${contentType}' does not match the configured
|
|
186
|
-
}
|
|
187
|
-
const deserialized = reader.readResponse(buffer);
|
|
188
|
-
if (deserialized.status.code && deserialized.status.code !==
|
|
189
|
-
const attributes = new Map();
|
|
190
|
-
if (deserialized.status.exception) {
|
|
191
|
-
attributes.set('exceptions', deserialized.status.exception);
|
|
192
|
-
attributes.set('stackTrace', deserialized.status.exception);
|
|
193
|
-
}
|
|
301
|
+
throw new Error(`Response Content-Type '${contentType}' does not match the configured response serializer (expected '${this._responseSerializer.mimeType}')`);
|
|
302
|
+
}
|
|
303
|
+
const deserialized = await reader.readResponse(buffer);
|
|
304
|
+
if (deserialized.status.code && deserialized.status.code !== responseStatusCode.success && deserialized.status.code !== responseStatusCode.noContent && deserialized.status.code !== responseStatusCode.partialContent) {
|
|
194
305
|
throw new ResponseError(`Server error: ${deserialized.status.message || 'Unknown error'} (${deserialized.status.code})`, {
|
|
195
306
|
code: deserialized.status.code,
|
|
196
307
|
message: deserialized.status.message || '',
|
|
197
|
-
|
|
308
|
+
exception: deserialized.status.exception,
|
|
198
309
|
});
|
|
199
310
|
}
|
|
200
311
|
return new ResultSet(deserialized.result.bulked
|
|
@@ -205,7 +316,8 @@ export default class Connection extends EventEmitter {
|
|
|
205
316
|
* Closes the Connection.
|
|
206
317
|
* @return {Promise}
|
|
207
318
|
*/
|
|
208
|
-
close() {
|
|
209
|
-
|
|
319
|
+
async close() {
|
|
320
|
+
this._log('debug', `Closing connection to ${this.url}`);
|
|
321
|
+
await this._dispatcher?.close();
|
|
210
322
|
}
|
|
211
323
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser counterpart of {@link ./dispatcher.ts}. The Node build configures the underlying HTTP
|
|
3
|
+
* transport through an `undici` dispatcher, but `undici` is built on `node:net`/`node:tls` and
|
|
4
|
+
* cannot run in a browser. Bundlers pick this file up via the `"browser"` field in `package.json`,
|
|
5
|
+
* so a browser bundle never imports `undici`.
|
|
6
|
+
*
|
|
7
|
+
* The browser's HTTP stack manages the connection-pool options that the Node dispatcher carries,
|
|
8
|
+
* so {@link buildDispatcher} throws if any is set explicitly (rather than silently ignoring it)
|
|
9
|
+
* and otherwise returns `undefined`, leaving the connection to issue a plain `fetch`. It is the
|
|
10
|
+
* only export the connection imports through the swapped `./dispatcher.js` path.
|
|
11
|
+
*/
|
|
12
|
+
/** Transport options accepted by {@link buildDispatcher}; mirrors the Node dispatcher's options. */
|
|
13
|
+
type DispatcherOptions = {
|
|
14
|
+
maxConnections?: number;
|
|
15
|
+
readTimeoutMillis?: number;
|
|
16
|
+
maxResponseHeaderBytes?: number;
|
|
17
|
+
keepAliveTimeMillis?: number;
|
|
18
|
+
proxy?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* In the browser there is no `undici` dispatcher, so `fetch` is issued without one and the browser
|
|
22
|
+
* manages the transport. Any {@link NODE_ONLY_OPTIONS} set explicitly cannot be honored and throws,
|
|
23
|
+
* so a misconfiguration surfaces immediately instead of being silently dropped. With none set this
|
|
24
|
+
* returns `undefined` and the connection omits the `dispatcher` field.
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildDispatcher(options?: DispatcherOptions): undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Browser counterpart of the Node `httpFetch` holder. There is no `undici` in the browser, so
|
|
29
|
+
* requests use the global `fetch` and the user agent manages the transport. Same holder shape as
|
|
30
|
+
* the Node build.
|
|
31
|
+
*/
|
|
32
|
+
export declare const httpFetch: {
|
|
33
|
+
fetch: typeof globalThis.fetch;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
* Connection-pool / transport options that only the Node (`undici`) dispatcher can honor. The
|
|
21
|
+
* browser's HTTP stack owns these concerns and exposes no `fetch` API to configure them, so they
|
|
22
|
+
* are rejected here rather than silently ignored. `readTimeoutMillis` is intentionally not in this list:
|
|
23
|
+
* it has a browser analog (an `AbortSignal`-based timeout) and is handled by the connection.
|
|
24
|
+
*/
|
|
25
|
+
const NODE_ONLY_OPTIONS = [
|
|
26
|
+
'maxConnections',
|
|
27
|
+
'keepAliveTimeMillis',
|
|
28
|
+
'maxResponseHeaderBytes',
|
|
29
|
+
'proxy',
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* In the browser there is no `undici` dispatcher, so `fetch` is issued without one and the browser
|
|
33
|
+
* manages the transport. Any {@link NODE_ONLY_OPTIONS} set explicitly cannot be honored and throws,
|
|
34
|
+
* so a misconfiguration surfaces immediately instead of being silently dropped. With none set this
|
|
35
|
+
* returns `undefined` and the connection omits the `dispatcher` field.
|
|
36
|
+
*/
|
|
37
|
+
export function buildDispatcher(options = {}) {
|
|
38
|
+
const unsupported = NODE_ONLY_OPTIONS.filter((key) => options[key] !== undefined);
|
|
39
|
+
if (unsupported.length > 0) {
|
|
40
|
+
throw new Error(`The following connection options are not supported in the browser and are managed by the ` +
|
|
41
|
+
`browser's HTTP stack: ${unsupported.join(', ')}. Remove them when running in a browser ` +
|
|
42
|
+
`(they are supported in Node).`);
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Browser counterpart of the Node `httpFetch` holder. There is no `undici` in the browser, so
|
|
48
|
+
* requests use the global `fetch` and the user agent manages the transport. Same holder shape as
|
|
49
|
+
* the Node build.
|
|
50
|
+
*/
|
|
51
|
+
export const httpFetch = {
|
|
52
|
+
fetch: globalThis.fetch.bind(globalThis),
|
|
53
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Agent, buildConnector, Dispatcher } from 'undici';
|
|
2
|
+
/** Default concurrent-connections-per-origin cap (Node's global fetch is uncapped). */
|
|
3
|
+
export declare const DEFAULT_MAX_CONNECTIONS = 128;
|
|
4
|
+
/** Canonical TinkerPop 4.x default TCP keep-alive idle time (30s), shared across the GLVs. */
|
|
5
|
+
export declare const DEFAULT_KEEP_ALIVE_TIME = 30000;
|
|
6
|
+
/** Options for the default undici {@link Dispatcher}; unset fields use undici defaults. */
|
|
7
|
+
export type DispatcherOptions = {
|
|
8
|
+
/** Max concurrent connections per origin. Defaults to {@link DEFAULT_MAX_CONNECTIONS}. */
|
|
9
|
+
maxConnections?: number;
|
|
10
|
+
/** Read timeout in ms. Maps to undici `headersTimeout` (wait for first response byte) and `bodyTimeout` (idle between body chunks). */
|
|
11
|
+
readTimeoutMillis?: number;
|
|
12
|
+
/** Max response header size in bytes. Maps to undici `maxHeaderSize`. */
|
|
13
|
+
maxResponseHeaderBytes?: number;
|
|
14
|
+
/** Idle ms before TCP keep-alive probes begin. Defaults to 30s; `0` disables keep-alive. */
|
|
15
|
+
keepAliveTimeMillis?: number;
|
|
16
|
+
/** HTTP proxy URI. When set, a {@link ProxyAgent} is built instead of an {@link Agent}. */
|
|
17
|
+
proxy?: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the effective keep-alive idle delay: unset falls back to {@link DEFAULT_KEEP_ALIVE_TIME},
|
|
21
|
+
* a non-positive value disables keep-alive (returns `null`).
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveKeepAliveTime(keepAliveTime?: number): number | null;
|
|
24
|
+
/**
|
|
25
|
+
* Builds an undici connector that sets `SO_KEEPALIVE` with the given idle delay on each new socket.
|
|
26
|
+
* `baseConnector` is parameterised so the wiring can be unit-tested with a fake connector.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildKeepAliveConnector(delay: number, baseConnector?: ReturnType<typeof buildConnector>): ReturnType<typeof buildConnector>;
|
|
29
|
+
/**
|
|
30
|
+
* Maps the discrete driver options onto undici {@link Agent.Options} (the single source of truth
|
|
31
|
+
* for that mapping). Exported as a seam so the mapping can be asserted in unit tests.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildAgentOptions(options?: DispatcherOptions): Agent.Options;
|
|
34
|
+
/**
|
|
35
|
+
* Builds the default undici {@link Dispatcher}: a {@link ProxyAgent} when `proxy` is set, otherwise
|
|
36
|
+
* a plain {@link Agent}. (Agent and ProxyAgent share one dispatcher slot, so only one is built.)
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildDispatcher(options?: DispatcherOptions): Dispatcher;
|
|
39
|
+
/**
|
|
40
|
+
* HTTP `fetch` for the Node build. Uses undici's own `fetch` (not the global one) so `fetch` and the
|
|
41
|
+
* {@link buildDispatcher} dispatcher share one undici version, whatever undici the Node runtime
|
|
42
|
+
* bundles (e.g. Node 26 ships undici 8, incompatible with an undici 6 dispatcher). A holder object,
|
|
43
|
+
* not a bare export, so tests can swap `fetch` (an ESM export can't be reassigned, an object
|
|
44
|
+
* property can). The cast aligns undici's `fetch` type with the global one.
|
|
45
|
+
*/
|
|
46
|
+
export declare const httpFetch: {
|
|
47
|
+
fetch: typeof globalThis.fetch;
|
|
48
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
import { Agent, ProxyAgent, buildConnector, fetch as undiciFetch } from 'undici';
|
|
20
|
+
/** Default concurrent-connections-per-origin cap (Node's global fetch is uncapped). */
|
|
21
|
+
export const DEFAULT_MAX_CONNECTIONS = 128;
|
|
22
|
+
/** Canonical TinkerPop 4.x default TCP keep-alive idle time (30s), shared across the GLVs. */
|
|
23
|
+
export const DEFAULT_KEEP_ALIVE_TIME = 30000;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the effective keep-alive idle delay: unset falls back to {@link DEFAULT_KEEP_ALIVE_TIME},
|
|
26
|
+
* a non-positive value disables keep-alive (returns `null`).
|
|
27
|
+
*/
|
|
28
|
+
export function resolveKeepAliveTime(keepAliveTime) {
|
|
29
|
+
const effective = keepAliveTime ?? DEFAULT_KEEP_ALIVE_TIME;
|
|
30
|
+
return effective > 0 ? effective : null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Builds an undici connector that sets `SO_KEEPALIVE` with the given idle delay on each new socket.
|
|
34
|
+
* `baseConnector` is parameterised so the wiring can be unit-tested with a fake connector.
|
|
35
|
+
*/
|
|
36
|
+
export function buildKeepAliveConnector(delay, baseConnector = buildConnector({})) {
|
|
37
|
+
return (connectOptions, callback) => {
|
|
38
|
+
baseConnector(connectOptions, (err, socket) => {
|
|
39
|
+
if (err) {
|
|
40
|
+
callback(err, null);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (socket) {
|
|
44
|
+
socket.setKeepAlive(true, delay);
|
|
45
|
+
}
|
|
46
|
+
callback(null, socket);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Maps the discrete driver options onto undici {@link Agent.Options} (the single source of truth
|
|
52
|
+
* for that mapping). Exported as a seam so the mapping can be asserted in unit tests.
|
|
53
|
+
*/
|
|
54
|
+
export function buildAgentOptions(options = {}) {
|
|
55
|
+
const maxConnections = options.maxConnections ?? DEFAULT_MAX_CONNECTIONS;
|
|
56
|
+
const agentOptions = {
|
|
57
|
+
connections: maxConnections,
|
|
58
|
+
};
|
|
59
|
+
// Connect/idle timeouts are intentionally left to undici defaults (the GLV spec marks the JS
|
|
60
|
+
// connect/idle timeout as N/A), not exposed as driver options.
|
|
61
|
+
if (options.readTimeoutMillis !== undefined) {
|
|
62
|
+
agentOptions.headersTimeout = options.readTimeoutMillis;
|
|
63
|
+
agentOptions.bodyTimeout = options.readTimeoutMillis;
|
|
64
|
+
}
|
|
65
|
+
if (options.maxResponseHeaderBytes !== undefined) {
|
|
66
|
+
agentOptions.maxHeaderSize = options.maxResponseHeaderBytes;
|
|
67
|
+
}
|
|
68
|
+
const keepAliveDelay = resolveKeepAliveTime(options.keepAliveTimeMillis);
|
|
69
|
+
if (keepAliveDelay !== null) {
|
|
70
|
+
agentOptions.connect = buildKeepAliveConnector(keepAliveDelay);
|
|
71
|
+
}
|
|
72
|
+
return agentOptions;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Builds the default undici {@link Dispatcher}: a {@link ProxyAgent} when `proxy` is set, otherwise
|
|
76
|
+
* a plain {@link Agent}. (Agent and ProxyAgent share one dispatcher slot, so only one is built.)
|
|
77
|
+
*/
|
|
78
|
+
export function buildDispatcher(options = {}) {
|
|
79
|
+
const agentOptions = buildAgentOptions(options);
|
|
80
|
+
if (options.proxy) {
|
|
81
|
+
return new ProxyAgent({ uri: options.proxy, ...agentOptions });
|
|
82
|
+
}
|
|
83
|
+
return new Agent(agentOptions);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* HTTP `fetch` for the Node build. Uses undici's own `fetch` (not the global one) so `fetch` and the
|
|
87
|
+
* {@link buildDispatcher} dispatcher share one undici version, whatever undici the Node runtime
|
|
88
|
+
* bundles (e.g. Node 26 ships undici 8, incompatible with an undici 6 dispatcher). A holder object,
|
|
89
|
+
* not a bare export, so tests can swap `fetch` (an ESM export can't be reassigned, an object
|
|
90
|
+
* property can). The cast aligns undici's `fetch` type with the global one.
|
|
91
|
+
*/
|
|
92
|
+
export const httpFetch = {
|
|
93
|
+
fetch: undiciFetch,
|
|
94
|
+
};
|
|
@@ -3,27 +3,33 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as rcModule from './remote-connection.js';
|
|
5
5
|
declare const RemoteConnection: typeof rcModule.RemoteConnection;
|
|
6
|
+
import Client from './client.js';
|
|
6
7
|
import GremlinLang from '../process/gremlin-lang.js';
|
|
7
8
|
import { ConnectionOptions } from './connection.js';
|
|
8
9
|
/**
|
|
9
10
|
* Represents the default `RemoteConnection` implementation.
|
|
10
11
|
*/
|
|
11
12
|
export default class DriverRemoteConnection extends RemoteConnection {
|
|
12
|
-
private
|
|
13
|
+
#private;
|
|
14
|
+
readonly _client: Client;
|
|
15
|
+
private _transactionId?;
|
|
13
16
|
/**
|
|
14
17
|
* Creates a new instance of {@link DriverRemoteConnection}.
|
|
15
18
|
* @param {String} url The resource uri.
|
|
16
19
|
* @param {ConnectionOptions} [options] The connection options.
|
|
20
|
+
* @param {String} [transactionId] Optional transaction ID to attach to all requests.
|
|
17
21
|
*/
|
|
18
|
-
constructor(url: string, options?: ConnectionOptions);
|
|
22
|
+
constructor(url: string, options?: ConnectionOptions, transactionId?: string);
|
|
23
|
+
/**
|
|
24
|
+
* Returns the transaction ID if this connection is bound to a transaction, undefined otherwise.
|
|
25
|
+
*/
|
|
26
|
+
get transactionId(): string | undefined;
|
|
19
27
|
/** @override */
|
|
20
28
|
open(): Promise<void>;
|
|
21
29
|
/** @override */
|
|
22
30
|
get isOpen(): boolean;
|
|
23
31
|
/** @override */
|
|
24
32
|
submit(gremlinLang: GremlinLang): Promise<rcModule.RemoteTraversal>;
|
|
25
|
-
commit(): Promise<any>;
|
|
26
|
-
rollback(): Promise<any>;
|
|
27
33
|
close(): Promise<void>;
|
|
28
34
|
/** @override */
|
|
29
35
|
addListener(event: string, handler: (...args: any[]) => unknown): void;
|