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
|
@@ -27,15 +27,26 @@ import Client from './client.js';
|
|
|
27
27
|
* Represents the default `RemoteConnection` implementation.
|
|
28
28
|
*/
|
|
29
29
|
export default class DriverRemoteConnection extends RemoteConnection {
|
|
30
|
+
// Exposed as package-internal for Transaction to submit begin/commit/rollback.
|
|
31
|
+
// Not part of the public API contract.
|
|
30
32
|
_client;
|
|
33
|
+
_transactionId;
|
|
31
34
|
/**
|
|
32
35
|
* Creates a new instance of {@link DriverRemoteConnection}.
|
|
33
36
|
* @param {String} url The resource uri.
|
|
34
37
|
* @param {ConnectionOptions} [options] The connection options.
|
|
38
|
+
* @param {String} [transactionId] Optional transaction ID to attach to all requests.
|
|
35
39
|
*/
|
|
36
|
-
constructor(url, options = {}) {
|
|
40
|
+
constructor(url, options = {}, transactionId) {
|
|
37
41
|
super(url, options);
|
|
38
42
|
this._client = new Client(url, options);
|
|
43
|
+
this._transactionId = transactionId;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the transaction ID if this connection is bound to a transaction, undefined otherwise.
|
|
47
|
+
*/
|
|
48
|
+
get transactionId() {
|
|
49
|
+
return this._transactionId;
|
|
39
50
|
}
|
|
40
51
|
/** @override */
|
|
41
52
|
open() {
|
|
@@ -47,14 +58,18 @@ export default class DriverRemoteConnection extends RemoteConnection {
|
|
|
47
58
|
}
|
|
48
59
|
/** @override */
|
|
49
60
|
submit(gremlinLang) {
|
|
50
|
-
|
|
61
|
+
const { gremlin, requestOptions } = this.#buildRequestArgs(gremlinLang);
|
|
62
|
+
// Use streaming internally — returns an AsyncGenerator backed RemoteTraversal
|
|
63
|
+
const generator = this._client.stream(gremlin, null, requestOptions);
|
|
64
|
+
return Promise.resolve(new RemoteTraversal(generator));
|
|
65
|
+
}
|
|
66
|
+
#buildRequestArgs(gremlinLang) {
|
|
51
67
|
let requestOptions = undefined;
|
|
52
68
|
const strategies = gremlinLang.getOptionsStrategies();
|
|
53
69
|
if (strategies.length > 0) {
|
|
54
70
|
requestOptions = {};
|
|
55
71
|
const allowedKeys = [
|
|
56
|
-
'
|
|
57
|
-
'scriptEvaluationTimeout',
|
|
72
|
+
'timeoutMillis',
|
|
58
73
|
'batchSize',
|
|
59
74
|
'requestId',
|
|
60
75
|
'userAgent',
|
|
@@ -75,18 +90,15 @@ export default class DriverRemoteConnection extends RemoteConnection {
|
|
|
75
90
|
if (!('bulkResults' in requestOptions)) {
|
|
76
91
|
requestOptions.bulkResults = true;
|
|
77
92
|
}
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
requestOptions.
|
|
93
|
+
const parametersString = gremlinLang.getParametersAsString();
|
|
94
|
+
if (parametersString !== '[:]') {
|
|
95
|
+
requestOptions.parameters = parametersString;
|
|
81
96
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
rollback() {
|
|
89
|
-
return this._client.submit('g.tx().rollback()', null);
|
|
97
|
+
// If this connection is bound to a transaction, attach the transactionId
|
|
98
|
+
if (this._transactionId) {
|
|
99
|
+
requestOptions.transactionId = this._transactionId;
|
|
100
|
+
}
|
|
101
|
+
return { gremlin: gremlinLang.getGremlin(), requestOptions };
|
|
90
102
|
}
|
|
91
103
|
close() {
|
|
92
104
|
return this._client.close();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { RequestMessage } from './request-message.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents an HTTP request that is passed through interceptors before being sent to the server.
|
|
5
|
+
* Interceptors may mutate any field. The {@link serializeBody} method serializes the body to JSON
|
|
6
|
+
* if it is still a RequestMessage, or returns the existing bytes if already serialized.
|
|
7
|
+
*/
|
|
8
|
+
export declare class HttpRequest {
|
|
9
|
+
url: string;
|
|
10
|
+
method: string;
|
|
11
|
+
headers: Record<string, string>;
|
|
12
|
+
body: RequestMessage | Buffer | any;
|
|
13
|
+
constructor(method: string, url: string, headers: Record<string, string>, body: any);
|
|
14
|
+
/**
|
|
15
|
+
* Serializes the request body to JSON if it is still a RequestMessage.
|
|
16
|
+
* If body is already a Buffer, returns it as-is (idempotent).
|
|
17
|
+
* Sets Content-Type and Content-Length headers on successful serialization.
|
|
18
|
+
*
|
|
19
|
+
* @returns The serialized body as a Buffer.
|
|
20
|
+
* @throws Error if body is neither a RequestMessage nor a Buffer.
|
|
21
|
+
*/
|
|
22
|
+
serializeBody(): Buffer;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A request interceptor receives an HttpRequest and mutates it in place.
|
|
26
|
+
* Interceptors must not return a value.
|
|
27
|
+
*/
|
|
28
|
+
export type RequestInterceptor = (request: HttpRequest) => void | Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { Buffer } from 'buffer';
|
|
20
|
+
import { RequestMessage } from './request-message.js';
|
|
21
|
+
/**
|
|
22
|
+
* Represents an HTTP request that is passed through interceptors before being sent to the server.
|
|
23
|
+
* Interceptors may mutate any field. The {@link serializeBody} method serializes the body to JSON
|
|
24
|
+
* if it is still a RequestMessage, or returns the existing bytes if already serialized.
|
|
25
|
+
*/
|
|
26
|
+
export class HttpRequest {
|
|
27
|
+
url;
|
|
28
|
+
method;
|
|
29
|
+
headers;
|
|
30
|
+
body;
|
|
31
|
+
constructor(method, url, headers, body) {
|
|
32
|
+
this.method = method;
|
|
33
|
+
this.url = url;
|
|
34
|
+
this.headers = headers;
|
|
35
|
+
this.body = body;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Serializes the request body to JSON if it is still a RequestMessage.
|
|
39
|
+
* If body is already a Buffer, returns it as-is (idempotent).
|
|
40
|
+
* Sets Content-Type and Content-Length headers on successful serialization.
|
|
41
|
+
*
|
|
42
|
+
* @returns The serialized body as a Buffer.
|
|
43
|
+
* @throws Error if body is neither a RequestMessage nor a Buffer.
|
|
44
|
+
*/
|
|
45
|
+
serializeBody() {
|
|
46
|
+
if (Buffer.isBuffer(this.body)) {
|
|
47
|
+
return this.body;
|
|
48
|
+
}
|
|
49
|
+
if (this.body instanceof RequestMessage) {
|
|
50
|
+
// RequestMessage.toJSON() produces the flattened wire object (standard + custom fields).
|
|
51
|
+
const data = Buffer.from(JSON.stringify(this.body), 'utf-8');
|
|
52
|
+
this.body = data;
|
|
53
|
+
this.headers['Content-Type'] = 'application/json';
|
|
54
|
+
this.headers['Content-Length'] = String(data.length);
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
const typeName = this.body === null ? 'null' : typeof this.body;
|
|
58
|
+
throw new Error(`unsupported body type: ${typeName}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** The set of log levels emitted by the driver, ordered from least to most severe. */
|
|
2
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
3
|
+
/**
|
|
4
|
+
* A logger object with one method per {@link LogLevel}. This shape is compatible with the
|
|
5
|
+
* global `console` as well as common logging libraries.
|
|
6
|
+
*/
|
|
7
|
+
export interface LoggerObject {
|
|
8
|
+
debug(message: string, ...args: any[]): void;
|
|
9
|
+
info(message: string, ...args: any[]): void;
|
|
10
|
+
warn(message: string, ...args: any[]): void;
|
|
11
|
+
error(message: string, ...args: any[]): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A logger callback that receives the level alongside the message and any extra arguments.
|
|
15
|
+
*/
|
|
16
|
+
export type LoggerCallback = (level: LogLevel, message: string, ...args: any[]) => void;
|
|
17
|
+
/**
|
|
18
|
+
* The `logger` connection option. It may be either a {@link LoggerObject} (e.g. the global
|
|
19
|
+
* `console`) or a {@link LoggerCallback}. Logging is disabled when no logger is provided.
|
|
20
|
+
*/
|
|
21
|
+
export type Logger = LoggerObject | LoggerCallback;
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes the user-supplied {@link Logger} option into a single callback. When no logger is
|
|
24
|
+
* provided, a no-op callback is returned so call sites do not need to null-check.
|
|
25
|
+
*
|
|
26
|
+
* @param {Logger} [logger] The user-supplied logger option.
|
|
27
|
+
* @returns {LoggerCallback} A callback that dispatches to the configured logger.
|
|
28
|
+
*/
|
|
29
|
+
export declare function normalizeLogger(logger?: Logger): LoggerCallback;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
* Normalizes the user-supplied {@link Logger} option into a single callback. When no logger is
|
|
21
|
+
* provided, a no-op callback is returned so call sites do not need to null-check.
|
|
22
|
+
*
|
|
23
|
+
* @param {Logger} [logger] The user-supplied logger option.
|
|
24
|
+
* @returns {LoggerCallback} A callback that dispatches to the configured logger.
|
|
25
|
+
*/
|
|
26
|
+
export function normalizeLogger(logger) {
|
|
27
|
+
if (logger === undefined || logger === null) {
|
|
28
|
+
return () => { };
|
|
29
|
+
}
|
|
30
|
+
if (typeof logger === 'function') {
|
|
31
|
+
return logger;
|
|
32
|
+
}
|
|
33
|
+
if (typeof logger === 'object') {
|
|
34
|
+
return (level, message, ...args) => {
|
|
35
|
+
const fn = logger[level];
|
|
36
|
+
if (typeof fn === 'function') {
|
|
37
|
+
fn.call(logger, message, ...args);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
throw new TypeError('logger must be a function, a logger object, or undefined');
|
|
42
|
+
}
|
|
@@ -3,23 +3,20 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import GremlinLang from '../process/gremlin-lang.js';
|
|
5
5
|
import { TraversalStrategy } from '../process/traversal-strategy.js';
|
|
6
|
-
import { Traversal
|
|
6
|
+
import { Traversal } from '../process/traversal.js';
|
|
7
7
|
import type { ConnectionOptions } from './connection.js';
|
|
8
|
-
export type RemoteConnectionOptions = ConnectionOptions & {
|
|
9
|
-
session?: string;
|
|
10
|
-
};
|
|
11
8
|
/**
|
|
12
9
|
* Represents an abstraction of a "connection" to a "server" that is capable of processing a traversal and
|
|
13
10
|
* returning results.
|
|
14
11
|
*/
|
|
15
12
|
export declare abstract class RemoteConnection {
|
|
16
13
|
url: string;
|
|
17
|
-
|
|
14
|
+
readonly options: ConnectionOptions;
|
|
18
15
|
/**
|
|
19
16
|
* @param {String} url The resource uri.
|
|
20
|
-
* @param {
|
|
17
|
+
* @param {ConnectionOptions} [options] The connection options.
|
|
21
18
|
*/
|
|
22
|
-
constructor(url: string, options?:
|
|
19
|
+
constructor(url: string, options?: ConnectionOptions);
|
|
23
20
|
/**
|
|
24
21
|
* Opens the connection, if its not already opened.
|
|
25
22
|
* @returns {Promise}
|
|
@@ -37,17 +34,7 @@ export declare abstract class RemoteConnection {
|
|
|
37
34
|
*/
|
|
38
35
|
abstract submit(gremlinLang: GremlinLang): Promise<RemoteTraversal>;
|
|
39
36
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @returns {Promise}
|
|
42
|
-
*/
|
|
43
|
-
abstract commit(): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Submits a rollback operation to the server and closes the connection.
|
|
46
|
-
* @returns {Promise}
|
|
47
|
-
*/
|
|
48
|
-
abstract rollback(): Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Closes the connection where open transactions will close according to the features of the graph provider.
|
|
37
|
+
* Closes the connection and releases any associated resources.
|
|
51
38
|
* @returns {Promise}
|
|
52
39
|
*/
|
|
53
40
|
abstract close(): Promise<void>;
|
|
@@ -56,9 +43,7 @@ export declare abstract class RemoteConnection {
|
|
|
56
43
|
* Represents a traversal as a result of a {@link RemoteConnection} submission.
|
|
57
44
|
*/
|
|
58
45
|
export declare class RemoteTraversal extends Traversal {
|
|
59
|
-
|
|
60
|
-
sideEffects?: any[] | undefined;
|
|
61
|
-
constructor(results: Traverser<any>[], sideEffects?: any[] | undefined);
|
|
46
|
+
constructor(source: AsyncGenerator<any>, sideEffects?: any[]);
|
|
62
47
|
}
|
|
63
48
|
export declare class RemoteStrategy extends TraversalStrategy {
|
|
64
49
|
connection: RemoteConnection;
|
|
@@ -27,7 +27,7 @@ export class RemoteConnection {
|
|
|
27
27
|
options;
|
|
28
28
|
/**
|
|
29
29
|
* @param {String} url The resource uri.
|
|
30
|
-
* @param {
|
|
30
|
+
* @param {ConnectionOptions} [options] The connection options.
|
|
31
31
|
*/
|
|
32
32
|
constructor(url, options = {}) {
|
|
33
33
|
this.url = url;
|
|
@@ -38,12 +38,9 @@ export class RemoteConnection {
|
|
|
38
38
|
* Represents a traversal as a result of a {@link RemoteConnection} submission.
|
|
39
39
|
*/
|
|
40
40
|
export class RemoteTraversal extends Traversal {
|
|
41
|
-
|
|
42
|
-
sideEffects;
|
|
43
|
-
constructor(results, sideEffects) {
|
|
41
|
+
constructor(source, sideEffects) {
|
|
44
42
|
super(null, null);
|
|
45
|
-
this.
|
|
46
|
-
this.sideEffects = sideEffects;
|
|
43
|
+
this._resultsStream = source;
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
export class RemoteStrategy extends TraversalStrategy {
|
|
@@ -58,12 +55,12 @@ export class RemoteStrategy extends TraversalStrategy {
|
|
|
58
55
|
}
|
|
59
56
|
/** @override */
|
|
60
57
|
apply(traversal) {
|
|
61
|
-
if (traversal.
|
|
58
|
+
if (traversal._resultsStream) {
|
|
62
59
|
return Promise.resolve();
|
|
63
60
|
}
|
|
64
61
|
return this.connection.submit(traversal.getGremlinLang()).then(function (remoteTraversal) {
|
|
65
62
|
traversal.sideEffects = remoteTraversal.sideEffects;
|
|
66
|
-
traversal.
|
|
63
|
+
traversal._resultsStream = remoteTraversal._resultsStream;
|
|
67
64
|
});
|
|
68
65
|
}
|
|
69
66
|
}
|
|
@@ -4,21 +4,32 @@
|
|
|
4
4
|
export declare class RequestMessage {
|
|
5
5
|
private gremlin;
|
|
6
6
|
private language;
|
|
7
|
-
private
|
|
8
|
-
private
|
|
7
|
+
private timeoutMillis?;
|
|
8
|
+
private parameters?;
|
|
9
9
|
private g?;
|
|
10
10
|
private materializeProperties?;
|
|
11
11
|
private bulkResults?;
|
|
12
|
+
private batchSize?;
|
|
12
13
|
private customFields;
|
|
13
14
|
private constructor();
|
|
14
15
|
getGremlin(): string;
|
|
15
16
|
getLanguage(): string;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
getTimeoutMillis(): number | undefined;
|
|
18
|
+
getParameters(): object | undefined;
|
|
18
19
|
getG(): string | undefined;
|
|
19
20
|
getMaterializeProperties(): string | undefined;
|
|
20
21
|
getBulkResults(): boolean | undefined;
|
|
22
|
+
getBatchSize(): number | undefined;
|
|
21
23
|
getFields(): ReadonlyMap<string, any>;
|
|
24
|
+
/**
|
|
25
|
+
* Builds the plain object that represents this message on the wire. Standard fields are
|
|
26
|
+
* included when set, and custom fields are flattened to the top level. This method is
|
|
27
|
+
* invoked automatically by {@link JSON.stringify}.
|
|
28
|
+
*
|
|
29
|
+
* When a new standard field is added to this class, it should be added here as well so that
|
|
30
|
+
* it is included in the serialized request body.
|
|
31
|
+
*/
|
|
32
|
+
toJSON(): Record<string, any>;
|
|
22
33
|
static build(gremlin: string): Builder;
|
|
23
34
|
}
|
|
24
35
|
/**
|
|
@@ -26,21 +37,40 @@ export declare class RequestMessage {
|
|
|
26
37
|
*/
|
|
27
38
|
export declare class Builder {
|
|
28
39
|
private readonly gremlin;
|
|
29
|
-
private readonly
|
|
40
|
+
private readonly parameters;
|
|
41
|
+
private parametersString?;
|
|
30
42
|
language: string;
|
|
31
|
-
|
|
43
|
+
timeoutMillis?: number;
|
|
32
44
|
g?: string;
|
|
33
45
|
materializeProperties?: string;
|
|
34
46
|
bulkResults?: boolean;
|
|
47
|
+
batchSize?: number;
|
|
35
48
|
additionalFields: Map<string, any>;
|
|
36
49
|
constructor(gremlin: string);
|
|
37
50
|
addLanguage(language: string): Builder;
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Adds a single query parameter. The accumulated parameters map is converted to a gremlin-lang
|
|
53
|
+
* map literal string when the message is created.
|
|
54
|
+
* Cannot be mixed with {@link addParametersString}.
|
|
55
|
+
*/
|
|
56
|
+
addParameter(key: string, value: any): Builder;
|
|
57
|
+
/**
|
|
58
|
+
* Merges the provided parameters into the accumulated parameters map. The values are converted to a
|
|
59
|
+
* gremlin-lang map literal string when the message is created.
|
|
60
|
+
* Cannot be mixed with {@link addParametersString}.
|
|
61
|
+
*/
|
|
62
|
+
addParameters(otherParameters: object): Builder;
|
|
63
|
+
/**
|
|
64
|
+
* Sets the query parameters as a pre-formatted gremlin-lang map literal string (e.g. `'["x":1,"y":"knows"]'`).
|
|
65
|
+
* Calling this method replaces any previously set parameters string (last-one-wins).
|
|
66
|
+
* Cannot be mixed with {@link addParameter} or {@link addParameters}.
|
|
67
|
+
*/
|
|
68
|
+
addParametersString(parametersString: string): Builder;
|
|
40
69
|
addG(g: string): Builder;
|
|
41
70
|
addMaterializeProperties(materializeProps: string): Builder;
|
|
42
71
|
addTimeoutMillis(timeout: number): Builder;
|
|
43
72
|
addBulkResults(bulking: boolean): Builder;
|
|
73
|
+
addBatchSize(batchSize: number): Builder;
|
|
44
74
|
addField(key: string, value: any): Builder;
|
|
45
75
|
/**
|
|
46
76
|
* Create the request message given the settings provided to the Builder.
|
|
@@ -16,14 +16,16 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import GremlinLang from '../process/gremlin-lang.js';
|
|
19
20
|
// Token constants
|
|
20
21
|
const Tokens = {
|
|
21
22
|
ARGS_LANGUAGE: 'language',
|
|
22
|
-
|
|
23
|
+
ARGS_PARAMETERS: 'parameters',
|
|
23
24
|
ARGS_G: 'g',
|
|
24
25
|
ARGS_MATERIALIZE_PROPERTIES: 'materializeProperties',
|
|
25
|
-
|
|
26
|
+
TIMEOUT_MILLIS: 'timeoutMillis',
|
|
26
27
|
BULK_RESULTS: 'bulkResults',
|
|
28
|
+
BATCH_SIZE: 'batchSize',
|
|
27
29
|
MATERIALIZE_PROPERTIES_TOKENS: 'tokens',
|
|
28
30
|
MATERIALIZE_PROPERTIES_ALL: 'all'
|
|
29
31
|
};
|
|
@@ -33,23 +35,25 @@ const Tokens = {
|
|
|
33
35
|
export class RequestMessage {
|
|
34
36
|
gremlin;
|
|
35
37
|
language;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
timeoutMillis;
|
|
39
|
+
parameters;
|
|
38
40
|
g;
|
|
39
41
|
materializeProperties;
|
|
40
42
|
bulkResults;
|
|
43
|
+
batchSize;
|
|
41
44
|
customFields;
|
|
42
|
-
constructor(gremlin, language,
|
|
45
|
+
constructor(gremlin, language, timeoutMillis, parameters, g, materializeProperties, bulkResults, batchSize, customFields) {
|
|
43
46
|
if (!gremlin) {
|
|
44
47
|
throw new Error('RequestMessage requires gremlin argument');
|
|
45
48
|
}
|
|
46
49
|
this.gremlin = gremlin;
|
|
47
50
|
this.language = language;
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
51
|
+
this.timeoutMillis = timeoutMillis;
|
|
52
|
+
this.parameters = parameters;
|
|
50
53
|
this.g = g;
|
|
51
54
|
this.materializeProperties = materializeProperties;
|
|
52
55
|
this.bulkResults = bulkResults;
|
|
56
|
+
this.batchSize = batchSize;
|
|
53
57
|
this.customFields = customFields;
|
|
54
58
|
}
|
|
55
59
|
getGremlin() {
|
|
@@ -58,11 +62,11 @@ export class RequestMessage {
|
|
|
58
62
|
getLanguage() {
|
|
59
63
|
return this.language;
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
return this.
|
|
65
|
+
getTimeoutMillis() {
|
|
66
|
+
return this.timeoutMillis;
|
|
63
67
|
}
|
|
64
|
-
|
|
65
|
-
return this.
|
|
68
|
+
getParameters() {
|
|
69
|
+
return this.parameters;
|
|
66
70
|
}
|
|
67
71
|
getG() {
|
|
68
72
|
return this.g;
|
|
@@ -73,9 +77,49 @@ export class RequestMessage {
|
|
|
73
77
|
getBulkResults() {
|
|
74
78
|
return this.bulkResults;
|
|
75
79
|
}
|
|
80
|
+
getBatchSize() {
|
|
81
|
+
return this.batchSize;
|
|
82
|
+
}
|
|
76
83
|
getFields() {
|
|
77
84
|
return this.customFields;
|
|
78
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Builds the plain object that represents this message on the wire. Standard fields are
|
|
88
|
+
* included when set, and custom fields are flattened to the top level. This method is
|
|
89
|
+
* invoked automatically by {@link JSON.stringify}.
|
|
90
|
+
*
|
|
91
|
+
* When a new standard field is added to this class, it should be added here as well so that
|
|
92
|
+
* it is included in the serialized request body.
|
|
93
|
+
*/
|
|
94
|
+
toJSON() {
|
|
95
|
+
const payload = { gremlin: this.gremlin };
|
|
96
|
+
if (this.language) {
|
|
97
|
+
payload['language'] = this.language;
|
|
98
|
+
}
|
|
99
|
+
if (this.g) {
|
|
100
|
+
payload['g'] = this.g;
|
|
101
|
+
}
|
|
102
|
+
if (this.parameters !== undefined) {
|
|
103
|
+
payload['parameters'] = this.parameters;
|
|
104
|
+
}
|
|
105
|
+
if (this.timeoutMillis !== undefined) {
|
|
106
|
+
payload['timeoutMillis'] = this.timeoutMillis;
|
|
107
|
+
}
|
|
108
|
+
if (this.materializeProperties) {
|
|
109
|
+
payload['materializeProperties'] = this.materializeProperties;
|
|
110
|
+
}
|
|
111
|
+
if (this.bulkResults !== undefined) {
|
|
112
|
+
payload['bulkResults'] = this.bulkResults;
|
|
113
|
+
}
|
|
114
|
+
if (this.batchSize !== undefined) {
|
|
115
|
+
payload['batchSize'] = this.batchSize;
|
|
116
|
+
}
|
|
117
|
+
// Flatten custom/provider fields to the top level
|
|
118
|
+
this.customFields.forEach((v, k) => {
|
|
119
|
+
payload[k] = v;
|
|
120
|
+
});
|
|
121
|
+
return payload;
|
|
122
|
+
}
|
|
79
123
|
static build(gremlin) {
|
|
80
124
|
return new Builder(gremlin);
|
|
81
125
|
}
|
|
@@ -85,12 +129,14 @@ export class RequestMessage {
|
|
|
85
129
|
*/
|
|
86
130
|
export class Builder {
|
|
87
131
|
gremlin;
|
|
88
|
-
|
|
132
|
+
parameters = {};
|
|
133
|
+
parametersString;
|
|
89
134
|
language;
|
|
90
|
-
|
|
135
|
+
timeoutMillis;
|
|
91
136
|
g;
|
|
92
137
|
materializeProperties;
|
|
93
138
|
bulkResults;
|
|
139
|
+
batchSize;
|
|
94
140
|
additionalFields = new Map();
|
|
95
141
|
constructor(gremlin) {
|
|
96
142
|
this.gremlin = gremlin;
|
|
@@ -102,14 +148,39 @@ export class Builder {
|
|
|
102
148
|
this.language = language;
|
|
103
149
|
return this;
|
|
104
150
|
}
|
|
105
|
-
|
|
106
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Adds a single query parameter. The accumulated parameters map is converted to a gremlin-lang
|
|
153
|
+
* map literal string when the message is created.
|
|
154
|
+
* Cannot be mixed with {@link addParametersString}.
|
|
155
|
+
*/
|
|
156
|
+
addParameter(key, value) {
|
|
157
|
+
if (this.parametersString)
|
|
158
|
+
throw new Error('Cannot mix addParameter() with addParametersString().');
|
|
159
|
+
Object.assign(this.parameters, { [key]: value });
|
|
107
160
|
return this;
|
|
108
161
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Merges the provided parameters into the accumulated parameters map. The values are converted to a
|
|
164
|
+
* gremlin-lang map literal string when the message is created.
|
|
165
|
+
* Cannot be mixed with {@link addParametersString}.
|
|
166
|
+
*/
|
|
167
|
+
addParameters(otherParameters) {
|
|
168
|
+
if (!otherParameters)
|
|
169
|
+
throw new Error('parameters argument cannot be null.');
|
|
170
|
+
if (this.parametersString)
|
|
171
|
+
throw new Error('Cannot mix addParameters() with addParametersString().');
|
|
172
|
+
Object.assign(this.parameters, otherParameters);
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Sets the query parameters as a pre-formatted gremlin-lang map literal string (e.g. `'["x":1,"y":"knows"]'`).
|
|
177
|
+
* Calling this method replaces any previously set parameters string (last-one-wins).
|
|
178
|
+
* Cannot be mixed with {@link addParameter} or {@link addParameters}.
|
|
179
|
+
*/
|
|
180
|
+
addParametersString(parametersString) {
|
|
181
|
+
if (Object.keys(this.parameters).length > 0)
|
|
182
|
+
throw new Error('Cannot mix addParametersString() with addParameter()/addParameters().');
|
|
183
|
+
this.parametersString = parametersString;
|
|
113
184
|
return this;
|
|
114
185
|
}
|
|
115
186
|
addG(g) {
|
|
@@ -131,13 +202,19 @@ export class Builder {
|
|
|
131
202
|
addTimeoutMillis(timeout) {
|
|
132
203
|
if (timeout < 0)
|
|
133
204
|
throw new Error('timeout argument cannot be negative.');
|
|
134
|
-
this.
|
|
205
|
+
this.timeoutMillis = timeout;
|
|
135
206
|
return this;
|
|
136
207
|
}
|
|
137
208
|
addBulkResults(bulking) {
|
|
138
209
|
this.bulkResults = bulking;
|
|
139
210
|
return this;
|
|
140
211
|
}
|
|
212
|
+
addBatchSize(batchSize) {
|
|
213
|
+
if (batchSize <= 0)
|
|
214
|
+
throw new Error('batchSize argument must be positive.');
|
|
215
|
+
this.batchSize = batchSize;
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
141
218
|
addField(key, value) {
|
|
142
219
|
this.additionalFields.set(key, value);
|
|
143
220
|
return this;
|
|
@@ -146,7 +223,16 @@ export class Builder {
|
|
|
146
223
|
* Create the request message given the settings provided to the Builder.
|
|
147
224
|
*/
|
|
148
225
|
create() {
|
|
226
|
+
// mutual exclusion between addParameters/addParameter and addParametersString is
|
|
227
|
+
// enforced at call time, so only one path can be set here
|
|
228
|
+
let parameters;
|
|
229
|
+
if (this.parametersString) {
|
|
230
|
+
parameters = this.parametersString;
|
|
231
|
+
}
|
|
232
|
+
else if (Object.keys(this.parameters).length > 0) {
|
|
233
|
+
parameters = GremlinLang.convertParametersToString(new Map(Object.entries(this.parameters)));
|
|
234
|
+
}
|
|
149
235
|
// @ts-ignore - accessing private constructor from Builder
|
|
150
|
-
return new RequestMessage(this.gremlin, this.language || 'gremlin-lang', this.
|
|
236
|
+
return new RequestMessage(this.gremlin, this.language || 'gremlin-lang', this.timeoutMillis, parameters, this.g, this.materializeProperties, this.bulkResults, this.batchSize, this.additionalFields);
|
|
151
237
|
}
|
|
152
238
|
}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
export default class ResponseError extends Error {
|
|
5
5
|
statusCode: number;
|
|
6
6
|
statusMessage: string;
|
|
7
|
-
|
|
7
|
+
statusException: string | null;
|
|
8
8
|
constructor(message: string, responseStatus: {
|
|
9
9
|
code: ResponseError['statusCode'];
|
|
10
10
|
message: ResponseError['statusMessage'];
|
|
11
|
-
|
|
11
|
+
exception?: ResponseError['statusException'];
|
|
12
12
|
});
|
|
13
13
|
}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
export default class ResponseError extends Error {
|
|
23
23
|
statusCode;
|
|
24
24
|
statusMessage;
|
|
25
|
-
|
|
25
|
+
statusException;
|
|
26
26
|
constructor(message, responseStatus) {
|
|
27
27
|
super(message);
|
|
28
28
|
this.name = 'ResponseError';
|
|
@@ -35,8 +35,8 @@ export default class ResponseError extends Error {
|
|
|
35
35
|
*/
|
|
36
36
|
this.statusMessage = responseStatus.message;
|
|
37
37
|
/**
|
|
38
|
-
* Gets the server
|
|
38
|
+
* Gets the server exception string (v4 protocol).
|
|
39
39
|
*/
|
|
40
|
-
this.
|
|
40
|
+
this.statusException = responseStatus.exception ?? null;
|
|
41
41
|
}
|
|
42
42
|
}
|