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
|
@@ -29,6 +29,7 @@ const traversal_js_1 = require("./traversal.cjs");
|
|
|
29
29
|
const transaction_js_1 = require("./transaction.cjs");
|
|
30
30
|
const traversal_strategy_js_1 = require("./traversal-strategy.cjs");
|
|
31
31
|
const graph_js_1 = require("../structure/graph.cjs");
|
|
32
|
+
const driver_remote_connection_js_1 = __importDefault(require("../driver/driver-remote-connection.cjs"));
|
|
32
33
|
const gremlin_lang_js_1 = __importDefault(require("./gremlin-lang.cjs"));
|
|
33
34
|
/**
|
|
34
35
|
* Represents the primary DSL of the Gremlin traversal machine.
|
|
@@ -40,6 +41,8 @@ class GraphTraversalSource {
|
|
|
40
41
|
graphTraversalSourceClass;
|
|
41
42
|
graphTraversalClass;
|
|
42
43
|
remoteConnection;
|
|
44
|
+
/** @internal - set by Transaction.begin() for gtx.tx() to return the owning transaction */
|
|
45
|
+
_boundTransaction;
|
|
43
46
|
/**
|
|
44
47
|
* Creates a new instance of {@link GraphTraversalSource}.
|
|
45
48
|
* @param {Graph} graph
|
|
@@ -62,11 +65,89 @@ class GraphTraversalSource {
|
|
|
62
65
|
* @returns {Transaction}
|
|
63
66
|
*/
|
|
64
67
|
tx() {
|
|
65
|
-
//
|
|
66
|
-
if (this.
|
|
68
|
+
// If this GTS is already bound to a transaction, return that transaction.
|
|
69
|
+
if (this._boundTransaction) {
|
|
70
|
+
return this._boundTransaction;
|
|
71
|
+
}
|
|
72
|
+
if (!this.remoteConnection) {
|
|
73
|
+
throw new Error('Remote connection is required for transactions');
|
|
74
|
+
}
|
|
75
|
+
// If the DRC has a transactionId, it was created by a Transaction.begin().
|
|
76
|
+
// But we don't have the Transaction reference here (only _boundTransaction above).
|
|
77
|
+
if (this.remoteConnection instanceof driver_remote_connection_js_1.default && this.remoteConnection.transactionId) {
|
|
67
78
|
throw new Error('This TraversalSource is already bound to a transaction - child transactions are not supported');
|
|
68
79
|
}
|
|
69
|
-
|
|
80
|
+
// Extract the Client from the DriverRemoteConnection.
|
|
81
|
+
const client = this.remoteConnection._client;
|
|
82
|
+
return new transaction_js_1.Transaction(client);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Runs a unit of work inside a transaction, owning the full lifecycle.
|
|
86
|
+
*
|
|
87
|
+
* The transaction is begun automatically and the resulting transaction-bound
|
|
88
|
+
* <code>GraphTraversalSource</code> (<code>gtx</code>) is passed to the
|
|
89
|
+
* callback as its sole argument. Only <code>gtx</code> is in scope inside the
|
|
90
|
+
* callback, which avoids accidentally issuing traversals against the
|
|
91
|
+
* non-transactional <code>g</code>.
|
|
92
|
+
*
|
|
93
|
+
* On normal completion of the callback the transaction is committed; on any
|
|
94
|
+
* abnormal exit (a thrown error or a rejected promise) the transaction is
|
|
95
|
+
* rolled back. This is a single-shot operation: there is exactly one attempt
|
|
96
|
+
* (begin -> run -> commit/rollback) and no retry. A second transaction may not
|
|
97
|
+
* be opened from inside the callback (calling <code>gtx.tx().begin()</code>
|
|
98
|
+
* throws via the existing double-begin guard).
|
|
99
|
+
*
|
|
100
|
+
* The callback may be synchronous or asynchronous; its return value (or the
|
|
101
|
+
* value its promise resolves to) is awaited and returned from
|
|
102
|
+
* <code>executeInTx</code>. If the callback returns nothing the result is
|
|
103
|
+
* <code>undefined</code>.
|
|
104
|
+
*
|
|
105
|
+
* Error handling: if the callback throws/rejects, the original error is
|
|
106
|
+
* re-raised unchanged after rollback is attempted. If the commit itself fails,
|
|
107
|
+
* the commit error propagates and a rollback is still attempted afterward for
|
|
108
|
+
* server-side hygiene. In both cases a failed rollback during cleanup is logged
|
|
109
|
+
* as a warning and never replaces the primary error.
|
|
110
|
+
*
|
|
111
|
+
* @param txWork callback that receives the transaction-bound GraphTraversalSource
|
|
112
|
+
* @returns {Promise<T>} resolves to the callback's value (undefined if none)
|
|
113
|
+
*/
|
|
114
|
+
async executeInTx(txWork) {
|
|
115
|
+
const tx = this.tx();
|
|
116
|
+
const gtx = await tx.begin();
|
|
117
|
+
let result;
|
|
118
|
+
// Phase 1: run the user's work. If it throws, roll back and rethrow the body error - the
|
|
119
|
+
// throw below exits the method, so a failed body never reaches the commit in phase 2.
|
|
120
|
+
try {
|
|
121
|
+
result = await txWork(gtx);
|
|
122
|
+
}
|
|
123
|
+
catch (bodyError) {
|
|
124
|
+
try {
|
|
125
|
+
await tx.rollback();
|
|
126
|
+
}
|
|
127
|
+
catch (rollbackError) {
|
|
128
|
+
console.warn('Rollback failed after transaction body error', rollbackError);
|
|
129
|
+
}
|
|
130
|
+
// Re-raise the exact original error; rollback failures never replace it.
|
|
131
|
+
throw bodyError;
|
|
132
|
+
}
|
|
133
|
+
// Phase 2: the body succeeded, so commit. A separate try because this failure mode is
|
|
134
|
+
// distinct (commit, not body): we still roll back for server hygiene, then rethrow the
|
|
135
|
+
// commit error as the primary error.
|
|
136
|
+
try {
|
|
137
|
+
await tx.commit();
|
|
138
|
+
}
|
|
139
|
+
catch (commitError) {
|
|
140
|
+
try {
|
|
141
|
+
// Attempt rollback so the server does not keep the transaction around.
|
|
142
|
+
await tx.rollback();
|
|
143
|
+
}
|
|
144
|
+
catch (rollbackError) {
|
|
145
|
+
console.warn('Rollback failed after commit failure', rollbackError);
|
|
146
|
+
}
|
|
147
|
+
// The commit error stays primary; rollback was only for server hygiene.
|
|
148
|
+
throw commitError;
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
70
151
|
}
|
|
71
152
|
/**
|
|
72
153
|
* @param graphComputer
|
|
@@ -117,6 +198,10 @@ class GraphTraversalSource {
|
|
|
117
198
|
}
|
|
118
199
|
glStrategies[glStrategies.length - 1].configuration[key] = val;
|
|
119
200
|
const gl = new gremlin_lang_js_1.default(this.gremlinLang);
|
|
201
|
+
// Render multilabel/singlelabel in gremlin text (temporary until these options are removed)
|
|
202
|
+
if (key === 'multilabel' || key === 'singlelabel') {
|
|
203
|
+
gl.appendGremlin(`.with("${key}")`);
|
|
204
|
+
}
|
|
120
205
|
return new this.graphTraversalSourceClass(this.graph, new traversal_strategy_js_1.TraversalStrategies(this.traversalStrategies), gl, this.graphTraversalSourceClass, this.graphTraversalClass);
|
|
121
206
|
}
|
|
122
207
|
/**
|
|
@@ -275,6 +360,17 @@ class GraphTraversalSource {
|
|
|
275
360
|
const gl = new gremlin_lang_js_1.default(this.gremlinLang).addStep('union', args);
|
|
276
361
|
return new this.graphTraversalClass(this.graph, new traversal_strategy_js_1.TraversalStrategies(this.traversalStrategies), gl);
|
|
277
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* Spawns a {@link GraphTraversal} by executing a declarative pattern match query.
|
|
365
|
+
* @param {string} matchQuery - the declarative query string
|
|
366
|
+
* @param {Record<string, any>} [params] - optional query parameters
|
|
367
|
+
* @returns {GraphTraversal}
|
|
368
|
+
*/
|
|
369
|
+
match(matchQuery, params) {
|
|
370
|
+
const args = params !== undefined ? [matchQuery, params] : [matchQuery];
|
|
371
|
+
const gl = new gremlin_lang_js_1.default(this.gremlinLang).addStep('match', args);
|
|
372
|
+
return new this.graphTraversalClass(this.graph, new traversal_strategy_js_1.TraversalStrategies(this.traversalStrategies), gl);
|
|
373
|
+
}
|
|
278
374
|
}
|
|
279
375
|
exports.GraphTraversalSource = GraphTraversalSource;
|
|
280
376
|
/**
|
|
@@ -331,6 +427,15 @@ class GraphTraversal extends traversal_js_1.Traversal {
|
|
|
331
427
|
this.gremlinLang.addStep('addV', args);
|
|
332
428
|
return this;
|
|
333
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* Graph traversal addLabel method.
|
|
432
|
+
* @param {...Object} args
|
|
433
|
+
* @returns {GraphTraversal}
|
|
434
|
+
*/
|
|
435
|
+
addLabel(...args) {
|
|
436
|
+
this.gremlinLang.addStep('addLabel', args);
|
|
437
|
+
return this;
|
|
438
|
+
}
|
|
334
439
|
/**
|
|
335
440
|
* Graph traversal aggregate method.
|
|
336
441
|
* @param {...Object} args
|
|
@@ -637,6 +742,24 @@ class GraphTraversal extends traversal_js_1.Traversal {
|
|
|
637
742
|
this.gremlinLang.addStep('drop', args);
|
|
638
743
|
return this;
|
|
639
744
|
}
|
|
745
|
+
/**
|
|
746
|
+
* Graph traversal dropLabel method.
|
|
747
|
+
* @param {...Object} args
|
|
748
|
+
* @returns {GraphTraversal}
|
|
749
|
+
*/
|
|
750
|
+
dropLabel(...args) {
|
|
751
|
+
this.gremlinLang.addStep('dropLabel', args);
|
|
752
|
+
return this;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Graph traversal dropLabels method.
|
|
756
|
+
* @param {...Object} args
|
|
757
|
+
* @returns {GraphTraversal}
|
|
758
|
+
*/
|
|
759
|
+
dropLabels(...args) {
|
|
760
|
+
this.gremlinLang.addStep('dropLabels', args);
|
|
761
|
+
return this;
|
|
762
|
+
}
|
|
640
763
|
/**
|
|
641
764
|
* Graph traversal element method.
|
|
642
765
|
* @param {...Object} args
|
|
@@ -894,6 +1017,15 @@ class GraphTraversal extends traversal_js_1.Traversal {
|
|
|
894
1017
|
this.gremlinLang.addStep('label', args);
|
|
895
1018
|
return this;
|
|
896
1019
|
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Graph traversal labels method.
|
|
1022
|
+
* @param {...Object} args
|
|
1023
|
+
* @returns {GraphTraversal}
|
|
1024
|
+
*/
|
|
1025
|
+
labels(...args) {
|
|
1026
|
+
this.gremlinLang.addStep('labels', args);
|
|
1027
|
+
return this;
|
|
1028
|
+
}
|
|
897
1029
|
/**
|
|
898
1030
|
* Graph traversal length method.
|
|
899
1031
|
* @param {...Object} args
|
|
@@ -948,11 +1080,6 @@ class GraphTraversal extends traversal_js_1.Traversal {
|
|
|
948
1080
|
this.gremlinLang.addStep('map', args);
|
|
949
1081
|
return this;
|
|
950
1082
|
}
|
|
951
|
-
/**
|
|
952
|
-
* Graph traversal match method.
|
|
953
|
-
* @param {...Object} args
|
|
954
|
-
* @returns {GraphTraversal}
|
|
955
|
-
*/
|
|
956
1083
|
match(...args) {
|
|
957
1084
|
this.gremlinLang.addStep('match', args);
|
|
958
1085
|
return this;
|
|
@@ -1579,6 +1706,7 @@ exports.statics = {
|
|
|
1579
1706
|
V: (...args) => callOnEmptyTraversal('V', args),
|
|
1580
1707
|
addE: (...args) => callOnEmptyTraversal('addE', args),
|
|
1581
1708
|
addV: (...args) => callOnEmptyTraversal('addV', args),
|
|
1709
|
+
addLabel: (...args) => callOnEmptyTraversal('addLabel', args),
|
|
1582
1710
|
aggregate: (...args) => callOnEmptyTraversal('aggregate', args),
|
|
1583
1711
|
all: (...args) => callOnEmptyTraversal('all', args),
|
|
1584
1712
|
and: (...args) => callOnEmptyTraversal('and', args),
|
|
@@ -1611,6 +1739,8 @@ exports.statics = {
|
|
|
1611
1739
|
discard: (...args) => callOnEmptyTraversal('discard', args),
|
|
1612
1740
|
disjunct: (...args) => callOnEmptyTraversal('disjunct', args),
|
|
1613
1741
|
drop: (...args) => callOnEmptyTraversal('drop', args),
|
|
1742
|
+
dropLabel: (...args) => callOnEmptyTraversal('dropLabel', args),
|
|
1743
|
+
dropLabels: (...args) => callOnEmptyTraversal('dropLabels', args),
|
|
1614
1744
|
element: (...args) => callOnEmptyTraversal('element', args),
|
|
1615
1745
|
elementMap: (...args) => callOnEmptyTraversal('elementMap', args),
|
|
1616
1746
|
emit: (...args) => callOnEmptyTraversal('emit', args),
|
|
@@ -1638,6 +1768,7 @@ exports.statics = {
|
|
|
1638
1768
|
is: (...args) => callOnEmptyTraversal('is', args),
|
|
1639
1769
|
key: (...args) => callOnEmptyTraversal('key', args),
|
|
1640
1770
|
label: (...args) => callOnEmptyTraversal('label', args),
|
|
1771
|
+
labels: (...args) => callOnEmptyTraversal('labels', args),
|
|
1641
1772
|
length: (...args) => callOnEmptyTraversal('length', args),
|
|
1642
1773
|
limit: (...args) => callOnEmptyTraversal('limit', args),
|
|
1643
1774
|
local: (...args) => callOnEmptyTraversal('local', args),
|
|
@@ -17,6 +17,8 @@ export declare class GraphTraversalSource {
|
|
|
17
17
|
graphTraversalSourceClass: typeof GraphTraversalSource;
|
|
18
18
|
graphTraversalClass: typeof GraphTraversal;
|
|
19
19
|
remoteConnection?: RemoteConnection;
|
|
20
|
+
/** @internal - set by Transaction.begin() for gtx.tx() to return the owning transaction */
|
|
21
|
+
_boundTransaction?: Transaction;
|
|
20
22
|
/**
|
|
21
23
|
* Creates a new instance of {@link GraphTraversalSource}.
|
|
22
24
|
* @param {Graph} graph
|
|
@@ -31,6 +33,37 @@ export declare class GraphTraversalSource {
|
|
|
31
33
|
* @returns {Transaction}
|
|
32
34
|
*/
|
|
33
35
|
tx(): Transaction;
|
|
36
|
+
/**
|
|
37
|
+
* Runs a unit of work inside a transaction, owning the full lifecycle.
|
|
38
|
+
*
|
|
39
|
+
* The transaction is begun automatically and the resulting transaction-bound
|
|
40
|
+
* <code>GraphTraversalSource</code> (<code>gtx</code>) is passed to the
|
|
41
|
+
* callback as its sole argument. Only <code>gtx</code> is in scope inside the
|
|
42
|
+
* callback, which avoids accidentally issuing traversals against the
|
|
43
|
+
* non-transactional <code>g</code>.
|
|
44
|
+
*
|
|
45
|
+
* On normal completion of the callback the transaction is committed; on any
|
|
46
|
+
* abnormal exit (a thrown error or a rejected promise) the transaction is
|
|
47
|
+
* rolled back. This is a single-shot operation: there is exactly one attempt
|
|
48
|
+
* (begin -> run -> commit/rollback) and no retry. A second transaction may not
|
|
49
|
+
* be opened from inside the callback (calling <code>gtx.tx().begin()</code>
|
|
50
|
+
* throws via the existing double-begin guard).
|
|
51
|
+
*
|
|
52
|
+
* The callback may be synchronous or asynchronous; its return value (or the
|
|
53
|
+
* value its promise resolves to) is awaited and returned from
|
|
54
|
+
* <code>executeInTx</code>. If the callback returns nothing the result is
|
|
55
|
+
* <code>undefined</code>.
|
|
56
|
+
*
|
|
57
|
+
* Error handling: if the callback throws/rejects, the original error is
|
|
58
|
+
* re-raised unchanged after rollback is attempted. If the commit itself fails,
|
|
59
|
+
* the commit error propagates and a rollback is still attempted afterward for
|
|
60
|
+
* server-side hygiene. In both cases a failed rollback during cleanup is logged
|
|
61
|
+
* as a warning and never replaces the primary error.
|
|
62
|
+
*
|
|
63
|
+
* @param txWork callback that receives the transaction-bound GraphTraversalSource
|
|
64
|
+
* @returns {Promise<T>} resolves to the callback's value (undefined if none)
|
|
65
|
+
*/
|
|
66
|
+
executeInTx<T>(txWork: (gtx: GraphTraversalSource) => T | Promise<T>): Promise<T>;
|
|
34
67
|
/**
|
|
35
68
|
* @param graphComputer
|
|
36
69
|
* @param workers
|
|
@@ -150,6 +183,13 @@ export declare class GraphTraversalSource {
|
|
|
150
183
|
* @returns {GraphTraversal}
|
|
151
184
|
*/
|
|
152
185
|
union(...args: any[]): GraphTraversal;
|
|
186
|
+
/**
|
|
187
|
+
* Spawns a {@link GraphTraversal} by executing a declarative pattern match query.
|
|
188
|
+
* @param {string} matchQuery - the declarative query string
|
|
189
|
+
* @param {Record<string, any>} [params] - optional query parameters
|
|
190
|
+
* @returns {GraphTraversal}
|
|
191
|
+
*/
|
|
192
|
+
match(matchQuery: string, params?: Record<string, any>): GraphTraversal;
|
|
153
193
|
}
|
|
154
194
|
/**
|
|
155
195
|
* Represents a graph traversal.
|
|
@@ -184,6 +224,12 @@ export declare class GraphTraversal extends Traversal {
|
|
|
184
224
|
* @returns {GraphTraversal}
|
|
185
225
|
*/
|
|
186
226
|
addV(...args: any[]): this;
|
|
227
|
+
/**
|
|
228
|
+
* Graph traversal addLabel method.
|
|
229
|
+
* @param {...Object} args
|
|
230
|
+
* @returns {GraphTraversal}
|
|
231
|
+
*/
|
|
232
|
+
addLabel(...args: any[]): this;
|
|
187
233
|
/**
|
|
188
234
|
* Graph traversal aggregate method.
|
|
189
235
|
* @param {...Object} args
|
|
@@ -388,6 +434,18 @@ export declare class GraphTraversal extends Traversal {
|
|
|
388
434
|
* @returns {GraphTraversal}
|
|
389
435
|
*/
|
|
390
436
|
drop(...args: any[]): this;
|
|
437
|
+
/**
|
|
438
|
+
* Graph traversal dropLabel method.
|
|
439
|
+
* @param {...Object} args
|
|
440
|
+
* @returns {GraphTraversal}
|
|
441
|
+
*/
|
|
442
|
+
dropLabel(...args: any[]): this;
|
|
443
|
+
/**
|
|
444
|
+
* Graph traversal dropLabels method.
|
|
445
|
+
* @param {...Object} args
|
|
446
|
+
* @returns {GraphTraversal}
|
|
447
|
+
*/
|
|
448
|
+
dropLabels(...args: any[]): this;
|
|
391
449
|
/**
|
|
392
450
|
* Graph traversal element method.
|
|
393
451
|
* @param {...Object} args
|
|
@@ -556,6 +614,12 @@ export declare class GraphTraversal extends Traversal {
|
|
|
556
614
|
* @returns {GraphTraversal}
|
|
557
615
|
*/
|
|
558
616
|
label(...args: any[]): this;
|
|
617
|
+
/**
|
|
618
|
+
* Graph traversal labels method.
|
|
619
|
+
* @param {...Object} args
|
|
620
|
+
* @returns {GraphTraversal}
|
|
621
|
+
*/
|
|
622
|
+
labels(...args: any[]): this;
|
|
559
623
|
/**
|
|
560
624
|
* Graph traversal length method.
|
|
561
625
|
* @param {...Object} args
|
|
@@ -593,11 +657,24 @@ export declare class GraphTraversal extends Traversal {
|
|
|
593
657
|
*/
|
|
594
658
|
map(...args: any[]): this;
|
|
595
659
|
/**
|
|
596
|
-
* Graph traversal match method.
|
|
597
|
-
*
|
|
660
|
+
* Graph traversal match method. Accepts either traversal-based match patterns
|
|
661
|
+
* (deprecated) or a declarative query string.
|
|
662
|
+
* @param {string} matchQuery - declarative query string
|
|
663
|
+
* @returns {GraphTraversal}
|
|
664
|
+
*/
|
|
665
|
+
match(matchQuery: string): this;
|
|
666
|
+
/**
|
|
667
|
+
* @param {string} matchQuery - declarative query string
|
|
668
|
+
* @param {Record<string, any>} params - query parameters
|
|
669
|
+
* @returns {GraphTraversal}
|
|
670
|
+
*/
|
|
671
|
+
match(matchQuery: string, params: Record<string, any>): this;
|
|
672
|
+
/**
|
|
673
|
+
* @deprecated Use match(String) for declarative pattern matching.
|
|
674
|
+
* @param {...any} matchTraversals - traversal-based match patterns
|
|
598
675
|
* @returns {GraphTraversal}
|
|
599
676
|
*/
|
|
600
|
-
match(...
|
|
677
|
+
match(...matchTraversals: any[]): this;
|
|
601
678
|
/**
|
|
602
679
|
* Graph traversal math method.
|
|
603
680
|
* @param {...Object} args
|
|
@@ -1011,6 +1088,7 @@ export declare const statics: {
|
|
|
1011
1088
|
V: (...args: any[]) => any;
|
|
1012
1089
|
addE: (...args: any[]) => any;
|
|
1013
1090
|
addV: (...args: any[]) => any;
|
|
1091
|
+
addLabel: (...args: any[]) => any;
|
|
1014
1092
|
aggregate: (...args: any[]) => any;
|
|
1015
1093
|
all: (...args: any[]) => any;
|
|
1016
1094
|
and: (...args: any[]) => any;
|
|
@@ -1043,6 +1121,8 @@ export declare const statics: {
|
|
|
1043
1121
|
discard: (...args: any[]) => any;
|
|
1044
1122
|
disjunct: (...args: any[]) => any;
|
|
1045
1123
|
drop: (...args: any[]) => any;
|
|
1124
|
+
dropLabel: (...args: any[]) => any;
|
|
1125
|
+
dropLabels: (...args: any[]) => any;
|
|
1046
1126
|
element: (...args: any[]) => any;
|
|
1047
1127
|
elementMap: (...args: any[]) => any;
|
|
1048
1128
|
emit: (...args: any[]) => any;
|
|
@@ -1070,6 +1150,7 @@ export declare const statics: {
|
|
|
1070
1150
|
is: (...args: any[]) => any;
|
|
1071
1151
|
key: (...args: any[]) => any;
|
|
1072
1152
|
label: (...args: any[]) => any;
|
|
1153
|
+
labels: (...args: any[]) => any;
|
|
1073
1154
|
length: (...args: any[]) => any;
|
|
1074
1155
|
limit: (...args: any[]) => any;
|
|
1075
1156
|
local: (...args: any[]) => any;
|
|
@@ -22,22 +22,28 @@ const traversal_js_1 = require("./traversal.cjs");
|
|
|
22
22
|
const traversal_strategy_js_1 = require("./traversal-strategy.cjs");
|
|
23
23
|
const utils_js_1 = require("../utils.cjs");
|
|
24
24
|
const graph_js_1 = require("../structure/graph.cjs");
|
|
25
|
+
const gvalue_js_1 = require("./gvalue.cjs");
|
|
26
|
+
const node_util_1 = require("node:util");
|
|
27
|
+
const buffer_1 = require("node:buffer");
|
|
28
|
+
const PARAM_NAME_PATTERN = /^[\p{L}_$][\p{L}\p{Nd}_$]*$/u;
|
|
25
29
|
class GremlinLang {
|
|
26
30
|
gremlin = '';
|
|
27
31
|
optionsStrategies = [];
|
|
28
32
|
parameters = new Map();
|
|
33
|
+
pdtRegistry = null;
|
|
29
34
|
constructor(toClone) {
|
|
30
35
|
if (toClone) {
|
|
31
36
|
this.gremlin = toClone.gremlin;
|
|
32
37
|
this.optionsStrategies = [...toClone.optionsStrategies];
|
|
33
38
|
this.parameters = new Map(toClone.parameters);
|
|
39
|
+
this.pdtRegistry = toClone.pdtRegistry;
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
42
|
getOptionsStrategies() {
|
|
37
43
|
return this.optionsStrategies;
|
|
38
44
|
}
|
|
39
|
-
|
|
40
|
-
this.
|
|
45
|
+
appendGremlin(text) {
|
|
46
|
+
this.gremlin += text;
|
|
41
47
|
}
|
|
42
48
|
getParameters() {
|
|
43
49
|
return this.parameters;
|
|
@@ -48,7 +54,15 @@ class GremlinLang {
|
|
|
48
54
|
}
|
|
49
55
|
let result = p.operator + '(';
|
|
50
56
|
if (Array.isArray(p.value)) {
|
|
51
|
-
|
|
57
|
+
// If all elements are traversals, serialize as comma-separated args (no brackets)
|
|
58
|
+
// This matches the server grammar: within(trav1, trav2) via genericArgumentVarargs
|
|
59
|
+
const allTraversals = p.value.length > 0 && p.value.every((v) => v != null && typeof v.getGremlinLang === 'function');
|
|
60
|
+
if (allTraversals) {
|
|
61
|
+
result += p.value.map((v) => this._argAsString(v)).join(',');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
result += '[' + p.value.map((v) => this._argAsString(v)).join(',') + ']';
|
|
65
|
+
}
|
|
52
66
|
}
|
|
53
67
|
else {
|
|
54
68
|
result += this._argAsString(p.value);
|
|
@@ -67,6 +81,21 @@ class GremlinLang {
|
|
|
67
81
|
if (arg instanceof utils_js_1.Long) {
|
|
68
82
|
return String(arg.value) + 'L';
|
|
69
83
|
}
|
|
84
|
+
if (arg instanceof utils_js_1.Float) {
|
|
85
|
+
return GremlinLang._fpAsString(arg.value, 'F');
|
|
86
|
+
}
|
|
87
|
+
if (arg instanceof utils_js_1.Double) {
|
|
88
|
+
return GremlinLang._fpAsString(arg.value, 'D');
|
|
89
|
+
}
|
|
90
|
+
if (arg instanceof utils_js_1.Short) {
|
|
91
|
+
return String(arg.value) + 'S';
|
|
92
|
+
}
|
|
93
|
+
if (arg instanceof utils_js_1.Byte) {
|
|
94
|
+
return String(arg.value) + 'B';
|
|
95
|
+
}
|
|
96
|
+
if (arg instanceof utils_js_1.Int) {
|
|
97
|
+
return String(arg.value);
|
|
98
|
+
}
|
|
70
99
|
if (typeof arg === 'bigint') {
|
|
71
100
|
return String(arg) + 'N';
|
|
72
101
|
}
|
|
@@ -79,9 +108,9 @@ class GremlinLang {
|
|
|
79
108
|
return '-Infinity';
|
|
80
109
|
if (!Number.isInteger(arg))
|
|
81
110
|
return String(arg) + 'D';
|
|
82
|
-
if (arg >=
|
|
111
|
+
if (arg >= utils_js_1.INT32_MIN && arg <= utils_js_1.INT32_MAX)
|
|
83
112
|
return String(arg);
|
|
84
|
-
// Outside safe integer range, values have lost precision and may exceed Java Long
|
|
113
|
+
// Outside safe integer range, values have lost precision and may exceed Java Long - emit as Double.
|
|
85
114
|
if (arg > Number.MAX_SAFE_INTEGER || arg < -Number.MAX_SAFE_INTEGER)
|
|
86
115
|
return String(arg) + 'D';
|
|
87
116
|
return String(arg) + 'L';
|
|
@@ -96,6 +125,21 @@ class GremlinLang {
|
|
|
96
125
|
const escaped = JSON.stringify(arg).slice(1, -1).replace(/'/g, "\\'");
|
|
97
126
|
return `'${escaped}'`;
|
|
98
127
|
}
|
|
128
|
+
if (arg instanceof gvalue_js_1.GValue) {
|
|
129
|
+
const key = arg.name;
|
|
130
|
+
if (!PARAM_NAME_PATTERN.test(key)) {
|
|
131
|
+
throw new Error(`Invalid parameter name [${key}].`);
|
|
132
|
+
}
|
|
133
|
+
if (this.parameters.has(key)) {
|
|
134
|
+
if (!(0, node_util_1.isDeepStrictEqual)(this.parameters.get(key), arg.value)) {
|
|
135
|
+
throw new Error(`Parameter with name ${key} already exists.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.parameters.set(key, arg.value);
|
|
140
|
+
}
|
|
141
|
+
return key;
|
|
142
|
+
}
|
|
99
143
|
if (arg instanceof traversal_js_1.P || arg instanceof traversal_js_1.TextP) {
|
|
100
144
|
return this._predicateAsString(arg);
|
|
101
145
|
}
|
|
@@ -114,10 +158,29 @@ class GremlinLang {
|
|
|
114
158
|
if (typeof arg === 'function' && arg.prototype instanceof traversal_strategy_js_1.TraversalStrategy) {
|
|
115
159
|
return arg.name;
|
|
116
160
|
}
|
|
161
|
+
if (arg instanceof graph_js_1.PrimitivePDT) {
|
|
162
|
+
// PDT literals use double-quoted strings (consistent with the composite PDT form below);
|
|
163
|
+
// JSON.stringify handles special-character escaping, then the outer quotes are stripped.
|
|
164
|
+
const escapedName = JSON.stringify(arg.name).slice(1, -1);
|
|
165
|
+
const escapedValue = JSON.stringify(arg.value).slice(1, -1);
|
|
166
|
+
return `PDT("${escapedName}","${escapedValue}")`;
|
|
167
|
+
}
|
|
168
|
+
if (arg instanceof graph_js_1.CompositePDT) {
|
|
169
|
+
const fields = arg.fields;
|
|
170
|
+
const keys = Object.keys(fields);
|
|
171
|
+
const escapedName = JSON.stringify(arg.name).slice(1, -1);
|
|
172
|
+
if (keys.length === 0)
|
|
173
|
+
return `PDT("${escapedName}",[:])`;
|
|
174
|
+
const entries = keys.map(k => `${this._argAsString(k)}:${this._argAsString(fields[k])}`);
|
|
175
|
+
return `PDT("${escapedName}",[${entries.join(',')}])`;
|
|
176
|
+
}
|
|
117
177
|
if (arg instanceof graph_js_1.Vertex) {
|
|
118
178
|
return this._argAsString(arg.id);
|
|
119
179
|
}
|
|
120
180
|
if (arg instanceof GremlinLang) {
|
|
181
|
+
// Merge the child's parameters so GValue bindings nested inside a child
|
|
182
|
+
// traversal are still sent to the server alongside the rendered query.
|
|
183
|
+
arg.parameters.forEach((v, k) => this.parameters.set(k, v));
|
|
121
184
|
return arg.getGremlin('__');
|
|
122
185
|
}
|
|
123
186
|
if (typeof arg.getGremlinLang === 'function') {
|
|
@@ -125,7 +188,14 @@ class GremlinLang {
|
|
|
125
188
|
if (arg.graph != null) {
|
|
126
189
|
throw new Error('Child traversal must be anonymous - use __ not g');
|
|
127
190
|
}
|
|
128
|
-
|
|
191
|
+
const childLang = arg.getGremlinLang();
|
|
192
|
+
// Merge the child's parameters so GValue bindings nested inside a child
|
|
193
|
+
// traversal are still sent to the server alongside the rendered query.
|
|
194
|
+
childLang.parameters.forEach((v, k) => this.parameters.set(k, v));
|
|
195
|
+
return childLang.getGremlin('__');
|
|
196
|
+
}
|
|
197
|
+
if (arg instanceof Uint8Array) {
|
|
198
|
+
return `Binary("${buffer_1.Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength).toString('base64')}")`;
|
|
129
199
|
}
|
|
130
200
|
if (arg instanceof Set) {
|
|
131
201
|
const items = [...arg];
|
|
@@ -153,7 +223,20 @@ class GremlinLang {
|
|
|
153
223
|
return '[:]';
|
|
154
224
|
return '[' + entries.map(([k, v]) => `${this._argAsString(k)}:${this._argAsString(v)}`).join(',') + ']';
|
|
155
225
|
}
|
|
156
|
-
|
|
226
|
+
// Registry-based dehydration
|
|
227
|
+
if (this.pdtRegistry && typeof arg === 'object' && arg.constructor) {
|
|
228
|
+
const primitiveEntry = this.pdtRegistry.getPrimitiveAdapterByClass(arg.constructor);
|
|
229
|
+
if (primitiveEntry) {
|
|
230
|
+
const value = primitiveEntry.toValue(arg);
|
|
231
|
+
return this._argAsString(new graph_js_1.PrimitivePDT(primitiveEntry.typeName, value));
|
|
232
|
+
}
|
|
233
|
+
const entry = this.pdtRegistry.getAdapterByClass(arg.constructor);
|
|
234
|
+
if (entry) {
|
|
235
|
+
const fields = entry.serialize(arg);
|
|
236
|
+
return this._argAsString(new graph_js_1.CompositePDT(entry.typeName, fields));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
throw new TypeError(`GremlinLang contains at least one type [${arg?.constructor?.name ?? typeof arg}] that cannot be represented as text.`);
|
|
157
240
|
}
|
|
158
241
|
addStep(name, args) {
|
|
159
242
|
const argsStr = args?.length ? args.map(a => this._argAsString(a)).join(',') : '';
|
|
@@ -171,6 +254,13 @@ class GremlinLang {
|
|
|
171
254
|
for (const strategy of args) {
|
|
172
255
|
if (strategy instanceof traversal_strategy_js_1.OptionsStrategy) {
|
|
173
256
|
this.optionsStrategies.push(strategy);
|
|
257
|
+
// Render multilabel/singlelabel in gremlin text (temporary until these options are removed)
|
|
258
|
+
if (strategy.configuration['multilabel'] !== undefined) {
|
|
259
|
+
this.gremlin += '.with("multilabel")';
|
|
260
|
+
}
|
|
261
|
+
if (strategy.configuration['singlelabel'] !== undefined) {
|
|
262
|
+
this.gremlin += '.with("singlelabel")';
|
|
263
|
+
}
|
|
174
264
|
}
|
|
175
265
|
else {
|
|
176
266
|
nonOptionsStrategies.push(strategy);
|
|
@@ -186,11 +276,33 @@ class GremlinLang {
|
|
|
186
276
|
this.gremlin += `.${name}(${argsStr})`;
|
|
187
277
|
return this;
|
|
188
278
|
}
|
|
279
|
+
static _fpAsString(v, suffix) {
|
|
280
|
+
if (v === Infinity)
|
|
281
|
+
return '+Infinity';
|
|
282
|
+
if (v === -Infinity)
|
|
283
|
+
return '-Infinity';
|
|
284
|
+
if (Number.isNaN(v))
|
|
285
|
+
return 'NaN';
|
|
286
|
+
return Number.isInteger(v) ? `${v}.0${suffix}` : `${v}${suffix}`;
|
|
287
|
+
}
|
|
189
288
|
getGremlin(prefix = 'g') {
|
|
190
289
|
if (this.gremlin.length > 0 && this.gremlin[0] !== '.') {
|
|
191
290
|
return this.gremlin;
|
|
192
291
|
}
|
|
193
292
|
return prefix + this.gremlin;
|
|
194
293
|
}
|
|
294
|
+
getParametersAsString() {
|
|
295
|
+
return GremlinLang.convertParametersToString(this.parameters);
|
|
296
|
+
}
|
|
297
|
+
static convertParametersToString(params) {
|
|
298
|
+
if (params == null || params.size === 0)
|
|
299
|
+
return '[:]';
|
|
300
|
+
const helper = new GremlinLang();
|
|
301
|
+
const parts = [];
|
|
302
|
+
params.forEach((v, k) => {
|
|
303
|
+
parts.push(`${helper._argAsString(k)}:${helper._argAsString(v)}`);
|
|
304
|
+
});
|
|
305
|
+
return '[' + parts.join(',') + ']';
|
|
306
|
+
}
|
|
195
307
|
}
|
|
196
308
|
exports.default = GremlinLang;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { OptionsStrategy } from './traversal-strategy.cjs';
|
|
2
|
+
import { PDTRegistry } from '../structure/PDTRegistry.cjs';
|
|
2
3
|
export default class GremlinLang {
|
|
3
4
|
private gremlin;
|
|
4
5
|
private optionsStrategies;
|
|
5
6
|
private parameters;
|
|
7
|
+
pdtRegistry: PDTRegistry | null;
|
|
6
8
|
constructor(toClone?: GremlinLang);
|
|
7
9
|
getOptionsStrategies(): OptionsStrategy[];
|
|
8
|
-
|
|
10
|
+
appendGremlin(text: string): void;
|
|
9
11
|
getParameters(): Map<string, any>;
|
|
10
12
|
private _predicateAsString;
|
|
11
13
|
private _argAsString;
|
|
12
14
|
addStep(name: string, args?: any[]): GremlinLang;
|
|
13
15
|
addSource(name: string, args?: any[]): GremlinLang;
|
|
16
|
+
private static _fpAsString;
|
|
14
17
|
getGremlin(prefix?: string): string;
|
|
18
|
+
getParametersAsString(): string;
|
|
19
|
+
static convertParametersToString(params: Map<string, any> | null): string;
|
|
15
20
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.GValue = void 0;
|
|
22
|
+
class GValue {
|
|
23
|
+
name;
|
|
24
|
+
value;
|
|
25
|
+
constructor(name, value) {
|
|
26
|
+
if (value instanceof GValue) {
|
|
27
|
+
throw new Error('GValues cannot be nested');
|
|
28
|
+
}
|
|
29
|
+
if (name == null) {
|
|
30
|
+
throw new Error('GValue name cannot be null.');
|
|
31
|
+
}
|
|
32
|
+
this.name = name;
|
|
33
|
+
this.value = value;
|
|
34
|
+
}
|
|
35
|
+
isNull() {
|
|
36
|
+
return this.value == null;
|
|
37
|
+
}
|
|
38
|
+
toString() {
|
|
39
|
+
return `${this.name}=${this.value}`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.GValue = GValue;
|