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
|
@@ -24,13 +24,15 @@ const buffer_1 = require("node:buffer");
|
|
|
24
24
|
function basic(username, password) {
|
|
25
25
|
return (request) => {
|
|
26
26
|
request.headers['authorization'] = 'Basic ' + buffer_1.Buffer.from(`${username}:${password}`).toString('base64');
|
|
27
|
-
return request;
|
|
28
27
|
};
|
|
29
28
|
}
|
|
30
29
|
function sigv4(region, service, credentialsProvider) {
|
|
31
30
|
let signer;
|
|
32
31
|
let resolvedProvider;
|
|
33
32
|
return async (request) => {
|
|
33
|
+
// Ensure body is serialized to JSON bytes before signing.
|
|
34
|
+
// serializeBody is idempotent: safe to call even if already serialized.
|
|
35
|
+
request.serializeBody();
|
|
34
36
|
// Lazy-initialize signer and credentials provider on first use
|
|
35
37
|
if (!signer) {
|
|
36
38
|
const { SignatureV4 } = await import('@smithy/signature-v4');
|
|
@@ -51,6 +53,11 @@ function sigv4(region, service, credentialsProvider) {
|
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
const url = new URL(request.url);
|
|
56
|
+
// Sign only the Host header; the signer itself adds (and signs) x-amz-date, the payload hash,
|
|
57
|
+
// and x-amz-security-token for session credentials. The request's own headers (accept,
|
|
58
|
+
// content-type, ...) are deliberately NOT fed into the signature: the HTTP stack may add or
|
|
59
|
+
// rewrite transport-managed headers such as accept-encoding after this interceptor runs, so a
|
|
60
|
+
// signature covering them would no longer match the bytes actually sent.
|
|
54
61
|
const signed = await signer.sign({
|
|
55
62
|
method: request.method,
|
|
56
63
|
protocol: url.protocol,
|
|
@@ -58,12 +65,12 @@ function sigv4(region, service, credentialsProvider) {
|
|
|
58
65
|
port: url.port ? Number(url.port) : undefined,
|
|
59
66
|
path: url.pathname + url.search,
|
|
60
67
|
headers: {
|
|
61
|
-
...request.headers,
|
|
62
68
|
host: url.host,
|
|
63
69
|
},
|
|
64
70
|
body: request.body,
|
|
65
71
|
});
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
// Merge the signed auth headers onto the request; the request's other headers (accept,
|
|
73
|
+
// content-type, ...) still reach the wire, they are simply not part of the signature.
|
|
74
|
+
request.headers = { ...request.headers, ...signed.headers };
|
|
68
75
|
};
|
|
69
76
|
}
|
|
@@ -23,10 +23,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
const connection_js_1 = __importDefault(require("./connection.cjs"));
|
|
25
25
|
const request_message_js_1 = require("./request-message.cjs");
|
|
26
|
+
const transaction_js_1 = require("../process/transaction.cjs");
|
|
26
27
|
/**
|
|
27
28
|
* A {@link Client} contains methods to send messages to a Gremlin Server.
|
|
28
29
|
*/
|
|
29
30
|
class Client {
|
|
31
|
+
url;
|
|
30
32
|
options;
|
|
31
33
|
_connection;
|
|
32
34
|
/**
|
|
@@ -34,7 +36,12 @@ class Client {
|
|
|
34
36
|
* @param {String} url The resource uri.
|
|
35
37
|
* @param {ClientOptions} [options] The connection options.
|
|
36
38
|
*/
|
|
39
|
+
// Tracks open transactions for cascade rollback on close. JS Set iteration
|
|
40
|
+
// is safe during concurrent modification (deleting the current element during
|
|
41
|
+
// for-of is spec-guaranteed to not affect remaining iterations).
|
|
42
|
+
_trackedTransactions = new Set();
|
|
37
43
|
constructor(url, options = {}) {
|
|
44
|
+
this.url = url;
|
|
38
45
|
this.options = options;
|
|
39
46
|
this._connection = new connection_js_1.default(url, options);
|
|
40
47
|
}
|
|
@@ -53,67 +60,104 @@ class Client {
|
|
|
53
60
|
return this._connection.isOpen;
|
|
54
61
|
}
|
|
55
62
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
58
|
-
* @
|
|
59
|
-
* @
|
|
60
|
-
* @
|
|
61
|
-
* @property {Boolean} bulkResults - Indicates whether results should be returned in bulk format.
|
|
62
|
-
* @property {Object} params - Additional parameters to include with the request.
|
|
63
|
-
* @property {Number} batchSize - The size in which the result of a request is to be 'batched' back to the client.
|
|
64
|
-
* @property {String} userAgent - The user agent string to send with the request.
|
|
65
|
-
* @property {Number} evaluationTimeout - The timeout for the evaluation of the request.
|
|
66
|
-
* @property {String} materializeProperties - Indicates whether element properties should be returned or not.
|
|
63
|
+
* Send a request to the Gremlin Server and buffer the entire response.
|
|
64
|
+
* @param {string} message The script to send
|
|
65
|
+
* @param {Object|null} [parameters] The query parameters, if any.
|
|
66
|
+
* @param {RequestOptions} [requestOptions] Configuration specific to the current request.
|
|
67
|
+
* @returns {Promise<ResultSet>}
|
|
67
68
|
*/
|
|
69
|
+
submit(message, parameters, requestOptions) {
|
|
70
|
+
return this._connection.submit(this.#buildRequest(message, parameters, requestOptions));
|
|
71
|
+
}
|
|
68
72
|
/**
|
|
69
|
-
* Send a request to the Gremlin Server.
|
|
73
|
+
* Send a request to the Gremlin Server and stream results incrementally.
|
|
74
|
+
* Returns an AsyncGenerator that yields individual result items as they are
|
|
75
|
+
* deserialized from the response. For bulked responses, yields Traverser objects.
|
|
70
76
|
* @param {string} message The script to send
|
|
71
|
-
* @param {Object|null} [
|
|
77
|
+
* @param {Object|null} [parameters] The query parameters, if any.
|
|
72
78
|
* @param {RequestOptions} [requestOptions] Configuration specific to the current request.
|
|
73
|
-
* @returns {
|
|
74
|
-
*/
|
|
75
|
-
|
|
79
|
+
* @returns {AsyncGenerator<any>}
|
|
80
|
+
*/
|
|
81
|
+
async *stream(message, parameters, requestOptions) {
|
|
82
|
+
return yield* this._connection.stream(this.#buildRequest(message, parameters, requestOptions));
|
|
83
|
+
}
|
|
84
|
+
#buildRequest(message, parameters, requestOptions) {
|
|
76
85
|
const requestBuilder = request_message_js_1.RequestMessage.build(message)
|
|
77
86
|
.addG(this.options.traversalSource || 'g');
|
|
78
87
|
if (requestOptions?.language) {
|
|
79
88
|
requestBuilder.addLanguage(requestOptions.language);
|
|
80
89
|
}
|
|
81
|
-
if (requestOptions?.
|
|
82
|
-
|
|
90
|
+
if (requestOptions?.parameters) {
|
|
91
|
+
if (typeof requestOptions.parameters === 'string') {
|
|
92
|
+
requestBuilder.addParametersString(requestOptions.parameters);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
requestBuilder.addParameters(requestOptions.parameters);
|
|
96
|
+
}
|
|
83
97
|
}
|
|
84
|
-
if (
|
|
85
|
-
|
|
98
|
+
if (parameters) {
|
|
99
|
+
if (typeof parameters === 'string') {
|
|
100
|
+
requestBuilder.addParametersString(parameters);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
requestBuilder.addParameters(parameters);
|
|
104
|
+
}
|
|
86
105
|
}
|
|
87
106
|
if (requestOptions?.materializeProperties) {
|
|
88
107
|
requestBuilder.addMaterializeProperties(requestOptions.materializeProperties);
|
|
89
108
|
}
|
|
90
|
-
if (requestOptions?.
|
|
91
|
-
requestBuilder.addTimeoutMillis(requestOptions.
|
|
109
|
+
if (requestOptions?.timeoutMillis) {
|
|
110
|
+
requestBuilder.addTimeoutMillis(requestOptions.timeoutMillis);
|
|
92
111
|
}
|
|
93
|
-
|
|
112
|
+
// Per-request value wins (including an explicit `false`); otherwise apply the
|
|
113
|
+
// connection-level default only when it is true.
|
|
114
|
+
if (requestOptions?.bulkResults !== undefined) {
|
|
94
115
|
requestBuilder.addBulkResults(requestOptions.bulkResults);
|
|
95
116
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
117
|
+
else if (this._connection.bulkResults) {
|
|
118
|
+
requestBuilder.addBulkResults(true);
|
|
119
|
+
}
|
|
120
|
+
// Fill the per-request batchSize from the connection-level default when unset.
|
|
121
|
+
const batchSize = requestOptions?.batchSize ?? this._connection.batchSize;
|
|
122
|
+
if (batchSize !== undefined) {
|
|
123
|
+
requestBuilder.addBatchSize(batchSize);
|
|
124
|
+
}
|
|
125
|
+
if (requestOptions?.transactionId) {
|
|
126
|
+
requestBuilder.addField('transactionId', requestOptions.transactionId);
|
|
127
|
+
}
|
|
128
|
+
return requestBuilder.create();
|
|
108
129
|
}
|
|
109
130
|
/**
|
|
110
131
|
* Closes the underlying connection
|
|
111
|
-
* send session close request before connection close if session mode
|
|
112
132
|
* @returns {Promise}
|
|
113
133
|
*/
|
|
114
|
-
close() {
|
|
134
|
+
async close() {
|
|
135
|
+
// Best-effort rollback of any open transactions before closing connections
|
|
136
|
+
for (const tx of this._trackedTransactions) {
|
|
137
|
+
try {
|
|
138
|
+
await tx.close();
|
|
139
|
+
}
|
|
140
|
+
catch { }
|
|
141
|
+
}
|
|
142
|
+
this._trackedTransactions.clear();
|
|
115
143
|
return this._connection.close();
|
|
116
144
|
}
|
|
145
|
+
trackTransaction(tx) {
|
|
146
|
+
this._trackedTransactions.add(tx);
|
|
147
|
+
}
|
|
148
|
+
untrackTransaction(tx) {
|
|
149
|
+
this._trackedTransactions.delete(tx);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Creates a new Transaction for executing operations within an explicit transaction.
|
|
153
|
+
* Transactions are short-lived and single-use. After commit or rollback,
|
|
154
|
+
* create a new Transaction for the next unit of work.
|
|
155
|
+
* The traversal source (g alias) is inherited from this Client.
|
|
156
|
+
* @returns {Transaction}
|
|
157
|
+
*/
|
|
158
|
+
transact() {
|
|
159
|
+
return new transaction_js_1.Transaction(this);
|
|
160
|
+
}
|
|
117
161
|
/**
|
|
118
162
|
* Adds an event listener to the connection
|
|
119
163
|
* @param {String} event The event name that you want to listen to.
|
|
@@ -123,7 +167,7 @@ class Client {
|
|
|
123
167
|
this._connection.on(event, handler);
|
|
124
168
|
}
|
|
125
169
|
/**
|
|
126
|
-
* Removes a
|
|
170
|
+
* Removes a previously added event listener to the connection
|
|
127
171
|
* @param {String} event The event name that you want to listen to.
|
|
128
172
|
* @param {Function} handler The event handler to be removed.
|
|
129
173
|
*/
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ConnectionOptions } from './connection.cjs';
|
|
2
|
-
import {
|
|
2
|
+
import { Transaction } from '../process/transaction.cjs';
|
|
3
3
|
export type RequestOptions = {
|
|
4
|
-
|
|
4
|
+
parameters?: any;
|
|
5
5
|
language?: string;
|
|
6
6
|
accept?: string;
|
|
7
|
-
|
|
7
|
+
timeoutMillis?: number;
|
|
8
8
|
batchSize?: number;
|
|
9
9
|
userAgent?: string;
|
|
10
10
|
materializeProperties?: string;
|
|
11
11
|
bulkResults?: boolean;
|
|
12
12
|
params?: Record<string, any>;
|
|
13
|
+
transactionId?: string;
|
|
13
14
|
};
|
|
14
15
|
export type ClientOptions = ConnectionOptions & RequestOptions & {
|
|
15
16
|
processor?: string;
|
|
@@ -18,13 +19,16 @@ export type ClientOptions = ConnectionOptions & RequestOptions & {
|
|
|
18
19
|
* A {@link Client} contains methods to send messages to a Gremlin Server.
|
|
19
20
|
*/
|
|
20
21
|
export default class Client {
|
|
21
|
-
private
|
|
22
|
+
#private;
|
|
23
|
+
readonly url: string;
|
|
24
|
+
readonly options: ClientOptions;
|
|
22
25
|
private readonly _connection;
|
|
23
26
|
/**
|
|
24
27
|
* Creates a new instance of {@link Client}.
|
|
25
28
|
* @param {String} url The resource uri.
|
|
26
29
|
* @param {ClientOptions} [options] The connection options.
|
|
27
30
|
*/
|
|
31
|
+
private readonly _trackedTransactions;
|
|
28
32
|
constructor(url: string, options?: ClientOptions);
|
|
29
33
|
/**
|
|
30
34
|
* Opens the underlying connection to the Gremlin Server, if it's not already opened.
|
|
@@ -37,39 +41,38 @@ export default class Client {
|
|
|
37
41
|
*/
|
|
38
42
|
get isOpen(): boolean;
|
|
39
43
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @typedef {Object} RequestOptions
|
|
42
|
-
* @property {any} bindings - The parameter bindings to apply to the script.
|
|
43
|
-
* @property {String} language - The language of the script to execute. Defaults to 'gremlin-lang'.
|
|
44
|
-
* @property {String} accept - The MIME type expected in the response.
|
|
45
|
-
* @property {Boolean} bulkResults - Indicates whether results should be returned in bulk format.
|
|
46
|
-
* @property {Object} params - Additional parameters to include with the request.
|
|
47
|
-
* @property {Number} batchSize - The size in which the result of a request is to be 'batched' back to the client.
|
|
48
|
-
* @property {String} userAgent - The user agent string to send with the request.
|
|
49
|
-
* @property {Number} evaluationTimeout - The timeout for the evaluation of the request.
|
|
50
|
-
* @property {String} materializeProperties - Indicates whether element properties should be returned or not.
|
|
51
|
-
*/
|
|
52
|
-
/**
|
|
53
|
-
* Send a request to the Gremlin Server.
|
|
44
|
+
* Send a request to the Gremlin Server and buffer the entire response.
|
|
54
45
|
* @param {string} message The script to send
|
|
55
|
-
* @param {Object|null} [
|
|
46
|
+
* @param {Object|null} [parameters] The query parameters, if any.
|
|
56
47
|
* @param {RequestOptions} [requestOptions] Configuration specific to the current request.
|
|
57
|
-
* @returns {Promise}
|
|
58
|
-
*/
|
|
48
|
+
* @returns {Promise<ResultSet>}
|
|
49
|
+
*/
|
|
50
|
+
submit(message: string, parameters: any | null, requestOptions?: RequestOptions): Promise<any>;
|
|
59
51
|
/**
|
|
60
|
-
* Send a request to the Gremlin Server and
|
|
52
|
+
* Send a request to the Gremlin Server and stream results incrementally.
|
|
53
|
+
* Returns an AsyncGenerator that yields individual result items as they are
|
|
54
|
+
* deserialized from the response. For bulked responses, yields Traverser objects.
|
|
61
55
|
* @param {string} message The script to send
|
|
62
|
-
* @param {Object} [
|
|
56
|
+
* @param {Object|null} [parameters] The query parameters, if any.
|
|
63
57
|
* @param {RequestOptions} [requestOptions] Configuration specific to the current request.
|
|
64
|
-
* @returns {
|
|
58
|
+
* @returns {AsyncGenerator<any>}
|
|
65
59
|
*/
|
|
66
|
-
stream(message: string,
|
|
60
|
+
stream(message: string, parameters: any | null, requestOptions?: RequestOptions): AsyncGenerator<any>;
|
|
67
61
|
/**
|
|
68
62
|
* Closes the underlying connection
|
|
69
|
-
* send session close request before connection close if session mode
|
|
70
63
|
* @returns {Promise}
|
|
71
64
|
*/
|
|
72
65
|
close(): Promise<void>;
|
|
66
|
+
trackTransaction(tx: any): void;
|
|
67
|
+
untrackTransaction(tx: any): void;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new Transaction for executing operations within an explicit transaction.
|
|
70
|
+
* Transactions are short-lived and single-use. After commit or rollback,
|
|
71
|
+
* create a new Transaction for the next unit of work.
|
|
72
|
+
* The traversal source (g alias) is inherited from this Client.
|
|
73
|
+
* @returns {Transaction}
|
|
74
|
+
*/
|
|
75
|
+
transact(): Transaction;
|
|
73
76
|
/**
|
|
74
77
|
* Adds an event listener to the connection
|
|
75
78
|
* @param {String} event The event name that you want to listen to.
|
|
@@ -77,7 +80,7 @@ export default class Client {
|
|
|
77
80
|
*/
|
|
78
81
|
addListener(event: string, handler: (...args: any[]) => unknown): void;
|
|
79
82
|
/**
|
|
80
|
-
* Removes a
|
|
83
|
+
* Removes a previously added event listener to the connection
|
|
81
84
|
* @param {String} event The event name that you want to listen to.
|
|
82
85
|
* @param {Function} handler The event handler to be removed.
|
|
83
86
|
*/
|