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.
Files changed (261) hide show
  1. package/build/cjs/driver/auth.cjs +11 -4
  2. package/build/cjs/driver/auth.d.cts +1 -1
  3. package/build/cjs/driver/client.cjs +82 -38
  4. package/build/cjs/driver/client.d.cts +30 -27
  5. package/build/cjs/driver/connection.cjs +173 -60
  6. package/build/cjs/driver/connection.d.cts +69 -26
  7. package/build/cjs/driver/dispatcher.browser.cjs +57 -0
  8. package/build/cjs/driver/dispatcher.browser.d.cts +35 -0
  9. package/build/cjs/driver/dispatcher.cjs +101 -0
  10. package/build/cjs/driver/dispatcher.d.cts +48 -0
  11. package/build/cjs/driver/driver-remote-connection.cjs +27 -15
  12. package/build/cjs/driver/driver-remote-connection.d.cts +10 -4
  13. package/build/cjs/driver/http-request.cjs +64 -0
  14. package/build/cjs/driver/http-request.d.cts +28 -0
  15. package/build/cjs/driver/logger.cjs +45 -0
  16. package/build/cjs/driver/logger.d.cts +29 -0
  17. package/build/cjs/driver/remote-connection.cjs +5 -8
  18. package/build/cjs/driver/remote-connection.d.cts +6 -21
  19. package/build/cjs/driver/request-message.cjs +110 -21
  20. package/build/cjs/driver/request-message.d.cts +38 -8
  21. package/build/cjs/driver/response-error.cjs +3 -3
  22. package/build/cjs/driver/response-error.d.cts +2 -2
  23. package/build/cjs/index.cjs +21 -0
  24. package/build/cjs/index.d.cts +47 -0
  25. package/build/cjs/language/grammar/GremlinLexer.cjs +1669 -1615
  26. package/build/cjs/language/grammar/GremlinLexer.d.cts +325 -316
  27. package/build/cjs/language/grammar/GremlinListener.cjs +322 -8
  28. package/build/cjs/language/grammar/GremlinListener.d.cts +351 -10
  29. package/build/cjs/language/grammar/GremlinParser.cjs +8700 -5798
  30. package/build/cjs/language/grammar/GremlinParser.d.cts +998 -619
  31. package/build/cjs/language/translator/AnonymizedTranslateVisitor.cjs +9 -0
  32. package/build/cjs/language/translator/AnonymizedTranslateVisitor.d.cts +3 -0
  33. package/build/cjs/language/translator/DotNetTranslateVisitor.cjs +113 -4
  34. package/build/cjs/language/translator/DotNetTranslateVisitor.d.cts +13 -2
  35. package/build/cjs/language/translator/GoTranslateVisitor.cjs +82 -0
  36. package/build/cjs/language/translator/GoTranslateVisitor.d.cts +9 -0
  37. package/build/cjs/language/translator/GroovyTranslateVisitor.cjs +23 -0
  38. package/build/cjs/language/translator/GroovyTranslateVisitor.d.cts +3 -0
  39. package/build/cjs/language/translator/JavaTranslateVisitor.cjs +23 -0
  40. package/build/cjs/language/translator/JavaTranslateVisitor.d.cts +3 -0
  41. package/build/cjs/language/translator/JavascriptTranslateVisitor.cjs +11 -0
  42. package/build/cjs/language/translator/JavascriptTranslateVisitor.d.cts +3 -0
  43. package/build/cjs/language/translator/PythonTranslateVisitor.cjs +39 -3
  44. package/build/cjs/language/translator/PythonTranslateVisitor.d.cts +3 -0
  45. package/build/cjs/language/translator/TranslateVisitor.cjs +9 -0
  46. package/build/cjs/language/translator/TranslateVisitor.d.cts +3 -0
  47. package/build/cjs/process/anonymous-traversal.cjs +5 -1
  48. package/build/cjs/process/graph-traversal.cjs +139 -8
  49. package/build/cjs/process/graph-traversal.d.cts +84 -3
  50. package/build/cjs/process/gremlin-lang.cjs +119 -7
  51. package/build/cjs/process/gremlin-lang.d.cts +6 -1
  52. package/build/cjs/process/gvalue.cjs +42 -0
  53. package/build/cjs/process/gvalue.d.cts +7 -0
  54. package/build/cjs/process/transaction.cjs +125 -23
  55. package/build/cjs/process/transaction.d.cts +50 -14
  56. package/build/cjs/process/traversal.cjs +105 -48
  57. package/build/cjs/process/traversal.d.cts +36 -10
  58. package/build/cjs/structure/PDTRegistry.cjs +116 -0
  59. package/build/cjs/structure/PDTRegistry.d.cts +34 -0
  60. package/build/cjs/structure/graph.cjs +351 -8
  61. package/build/cjs/structure/graph.d.cts +122 -3
  62. package/build/cjs/structure/io/binary/GraphBinary.cjs +68 -39
  63. package/build/cjs/structure/io/binary/GraphBinary.d.cts +15 -1
  64. package/build/cjs/structure/io/binary/internals/AnySerializer.cjs +34 -17
  65. package/build/cjs/structure/io/binary/internals/AnySerializer.d.cts +12 -2
  66. package/build/cjs/structure/io/binary/internals/ArraySerializer.cjs +41 -72
  67. package/build/cjs/structure/io/binary/internals/ArraySerializer.d.cts +14 -7
  68. package/build/cjs/structure/io/binary/internals/BigIntegerSerializer.cjs +34 -54
  69. package/build/cjs/structure/io/binary/internals/BigIntegerSerializer.d.cts +12 -7
  70. package/build/cjs/structure/io/binary/internals/BinarySerializer.cjs +31 -51
  71. package/build/cjs/structure/io/binary/internals/BinarySerializer.d.cts +12 -4
  72. package/build/cjs/structure/io/binary/internals/BooleanSerializer.cjs +28 -42
  73. package/build/cjs/structure/io/binary/internals/BooleanSerializer.d.cts +12 -4
  74. package/build/cjs/structure/io/binary/internals/ByteSerializer.cjs +24 -38
  75. package/build/cjs/structure/io/binary/internals/ByteSerializer.d.cts +12 -4
  76. package/build/cjs/structure/io/binary/internals/CompositePDTSerializer.cjs +81 -0
  77. package/build/cjs/structure/io/binary/internals/CompositePDTSerializer.d.cts +10 -0
  78. package/build/cjs/structure/io/binary/internals/DateTimeSerializer.cjs +52 -69
  79. package/build/cjs/structure/io/binary/internals/DateTimeSerializer.d.cts +12 -7
  80. package/build/cjs/structure/io/binary/internals/DoubleSerializer.cjs +24 -38
  81. package/build/cjs/structure/io/binary/internals/DoubleSerializer.d.cts +12 -4
  82. package/build/cjs/structure/io/binary/internals/EdgeSerializer.cjs +69 -124
  83. package/build/cjs/structure/io/binary/internals/EdgeSerializer.d.cts +14 -12
  84. package/build/cjs/structure/io/binary/internals/EnumSerializer.cjs +47 -59
  85. package/build/cjs/structure/io/binary/internals/EnumSerializer.d.cts +19 -4
  86. package/build/cjs/structure/io/binary/internals/FloatSerializer.cjs +24 -38
  87. package/build/cjs/structure/io/binary/internals/FloatSerializer.d.cts +12 -4
  88. package/build/cjs/structure/io/binary/internals/GraphBinaryReader.cjs +111 -37
  89. package/build/cjs/structure/io/binary/internals/GraphBinaryReader.d.cts +26 -2
  90. package/build/cjs/structure/io/binary/internals/GraphBinaryWriter.cjs +6 -6
  91. package/build/cjs/structure/io/binary/internals/GraphSerializer.cjs +184 -0
  92. package/build/cjs/structure/io/binary/internals/GraphSerializer.d.cts +22 -0
  93. package/build/cjs/structure/io/binary/internals/IntSerializer.cjs +33 -38
  94. package/build/cjs/structure/io/binary/internals/IntSerializer.d.cts +19 -4
  95. package/build/cjs/structure/io/binary/internals/LongSerializer.cjs +29 -42
  96. package/build/cjs/structure/io/binary/internals/LongSerializer.d.cts +13 -4
  97. package/build/cjs/structure/io/binary/internals/MapSerializer.cjs +36 -70
  98. package/build/cjs/structure/io/binary/internals/MapSerializer.d.cts +14 -7
  99. package/build/cjs/structure/io/binary/internals/MarkerSerializer.cjs +30 -33
  100. package/build/cjs/structure/io/binary/internals/MarkerSerializer.d.cts +13 -4
  101. package/build/cjs/structure/io/binary/internals/NumberSerializationStrategy.cjs +28 -2
  102. package/build/cjs/structure/io/binary/internals/NumberSerializationStrategy.d.cts +0 -3
  103. package/build/cjs/structure/io/binary/internals/PathSerializer.cjs +30 -55
  104. package/build/cjs/structure/io/binary/internals/PathSerializer.d.cts +14 -7
  105. package/build/cjs/structure/io/binary/internals/PrimitivePDTSerializer.cjs +80 -0
  106. package/build/cjs/structure/io/binary/internals/PrimitivePDTSerializer.d.cts +10 -0
  107. package/build/cjs/structure/io/binary/internals/PropertySerializer.cjs +32 -69
  108. package/build/cjs/structure/io/binary/internals/PropertySerializer.d.cts +14 -7
  109. package/build/cjs/structure/io/binary/internals/SetSerializer.cjs +39 -73
  110. package/build/cjs/structure/io/binary/internals/SetSerializer.d.cts +14 -7
  111. package/build/cjs/structure/io/binary/internals/ShortSerializer.cjs +24 -38
  112. package/build/cjs/structure/io/binary/internals/ShortSerializer.d.cts +12 -4
  113. package/build/cjs/structure/io/binary/internals/StreamReader.cjs +184 -0
  114. package/build/cjs/structure/io/binary/internals/StreamReader.d.cts +69 -0
  115. package/build/cjs/structure/io/binary/internals/StringSerializer.cjs +34 -53
  116. package/build/cjs/structure/io/binary/internals/StringSerializer.d.cts +14 -4
  117. package/build/cjs/structure/io/binary/internals/StubSerializer.cjs +2 -1
  118. package/build/cjs/structure/io/binary/internals/StubSerializer.d.cts +1 -1
  119. package/build/cjs/structure/io/binary/internals/TreeSerializer.cjs +139 -0
  120. package/build/cjs/structure/io/binary/internals/TreeSerializer.d.cts +54 -0
  121. package/build/cjs/structure/io/binary/internals/UnspecifiedNullSerializer.cjs +8 -31
  122. package/build/cjs/structure/io/binary/internals/UnspecifiedNullSerializer.d.cts +6 -4
  123. package/build/cjs/structure/io/binary/internals/UuidSerializer.cjs +33 -49
  124. package/build/cjs/structure/io/binary/internals/UuidSerializer.d.cts +12 -7
  125. package/build/cjs/structure/io/binary/internals/VertexPropertySerializer.cjs +37 -95
  126. package/build/cjs/structure/io/binary/internals/VertexPropertySerializer.d.cts +14 -7
  127. package/build/cjs/structure/io/binary/internals/VertexSerializer.cjs +41 -68
  128. package/build/cjs/structure/io/binary/internals/VertexSerializer.d.cts +14 -9
  129. package/build/cjs/utils.cjs +157 -40
  130. package/build/cjs/utils.d.cts +62 -4
  131. package/build/esm/driver/auth.d.ts +1 -1
  132. package/build/esm/driver/auth.js +11 -4
  133. package/build/esm/driver/client.d.ts +30 -27
  134. package/build/esm/driver/client.js +82 -38
  135. package/build/esm/driver/connection.d.ts +69 -26
  136. package/build/esm/driver/connection.js +172 -60
  137. package/build/esm/driver/dispatcher.browser.d.ts +35 -0
  138. package/build/esm/driver/dispatcher.browser.js +53 -0
  139. package/build/esm/driver/dispatcher.d.ts +48 -0
  140. package/build/esm/driver/dispatcher.js +94 -0
  141. package/build/esm/driver/driver-remote-connection.d.ts +10 -4
  142. package/build/esm/driver/driver-remote-connection.js +27 -15
  143. package/build/esm/driver/http-request.d.ts +28 -0
  144. package/build/esm/driver/http-request.js +60 -0
  145. package/build/esm/driver/logger.d.ts +29 -0
  146. package/build/esm/driver/logger.js +42 -0
  147. package/build/esm/driver/remote-connection.d.ts +6 -21
  148. package/build/esm/driver/remote-connection.js +5 -8
  149. package/build/esm/driver/request-message.d.ts +38 -8
  150. package/build/esm/driver/request-message.js +107 -21
  151. package/build/esm/driver/response-error.d.ts +2 -2
  152. package/build/esm/driver/response-error.js +3 -3
  153. package/build/esm/index.d.ts +47 -0
  154. package/build/esm/index.js +21 -0
  155. package/build/esm/language/grammar/GremlinLexer.d.ts +325 -316
  156. package/build/esm/language/grammar/GremlinLexer.js +1669 -1615
  157. package/build/esm/language/grammar/GremlinListener.d.ts +351 -10
  158. package/build/esm/language/grammar/GremlinListener.js +322 -8
  159. package/build/esm/language/grammar/GremlinParser.d.ts +998 -619
  160. package/build/esm/language/grammar/GremlinParser.js +8646 -5778
  161. package/build/esm/language/translator/AnonymizedTranslateVisitor.d.ts +3 -0
  162. package/build/esm/language/translator/AnonymizedTranslateVisitor.js +9 -0
  163. package/build/esm/language/translator/DotNetTranslateVisitor.d.ts +13 -2
  164. package/build/esm/language/translator/DotNetTranslateVisitor.js +113 -4
  165. package/build/esm/language/translator/GoTranslateVisitor.d.ts +9 -0
  166. package/build/esm/language/translator/GoTranslateVisitor.js +82 -0
  167. package/build/esm/language/translator/GroovyTranslateVisitor.d.ts +3 -0
  168. package/build/esm/language/translator/GroovyTranslateVisitor.js +23 -0
  169. package/build/esm/language/translator/JavaTranslateVisitor.d.ts +3 -0
  170. package/build/esm/language/translator/JavaTranslateVisitor.js +23 -0
  171. package/build/esm/language/translator/JavascriptTranslateVisitor.d.ts +3 -0
  172. package/build/esm/language/translator/JavascriptTranslateVisitor.js +11 -0
  173. package/build/esm/language/translator/PythonTranslateVisitor.d.ts +3 -0
  174. package/build/esm/language/translator/PythonTranslateVisitor.js +39 -3
  175. package/build/esm/language/translator/TranslateVisitor.d.ts +3 -0
  176. package/build/esm/language/translator/TranslateVisitor.js +9 -0
  177. package/build/esm/process/anonymous-traversal.js +5 -1
  178. package/build/esm/process/graph-traversal.d.ts +84 -3
  179. package/build/esm/process/graph-traversal.js +139 -8
  180. package/build/esm/process/gremlin-lang.d.ts +6 -1
  181. package/build/esm/process/gremlin-lang.js +121 -9
  182. package/build/esm/process/gvalue.d.ts +7 -0
  183. package/build/esm/process/gvalue.js +38 -0
  184. package/build/esm/process/transaction.d.ts +50 -14
  185. package/build/esm/process/transaction.js +122 -23
  186. package/build/esm/process/traversal.d.ts +36 -10
  187. package/build/esm/process/traversal.js +104 -47
  188. package/build/esm/structure/PDTRegistry.d.ts +34 -0
  189. package/build/esm/structure/PDTRegistry.js +112 -0
  190. package/build/esm/structure/graph.d.ts +122 -3
  191. package/build/esm/structure/graph.js +347 -7
  192. package/build/esm/structure/io/binary/GraphBinary.d.ts +15 -1
  193. package/build/esm/structure/io/binary/GraphBinary.js +66 -38
  194. package/build/esm/structure/io/binary/internals/AnySerializer.d.ts +12 -2
  195. package/build/esm/structure/io/binary/internals/AnySerializer.js +34 -17
  196. package/build/esm/structure/io/binary/internals/ArraySerializer.d.ts +14 -7
  197. package/build/esm/structure/io/binary/internals/ArraySerializer.js +41 -72
  198. package/build/esm/structure/io/binary/internals/BigIntegerSerializer.d.ts +12 -7
  199. package/build/esm/structure/io/binary/internals/BigIntegerSerializer.js +34 -54
  200. package/build/esm/structure/io/binary/internals/BinarySerializer.d.ts +12 -4
  201. package/build/esm/structure/io/binary/internals/BinarySerializer.js +31 -51
  202. package/build/esm/structure/io/binary/internals/BooleanSerializer.d.ts +12 -4
  203. package/build/esm/structure/io/binary/internals/BooleanSerializer.js +28 -42
  204. package/build/esm/structure/io/binary/internals/ByteSerializer.d.ts +12 -4
  205. package/build/esm/structure/io/binary/internals/ByteSerializer.js +24 -38
  206. package/build/esm/structure/io/binary/internals/CompositePDTSerializer.d.ts +10 -0
  207. package/build/esm/structure/io/binary/internals/CompositePDTSerializer.js +78 -0
  208. package/build/esm/structure/io/binary/internals/DateTimeSerializer.d.ts +12 -7
  209. package/build/esm/structure/io/binary/internals/DateTimeSerializer.js +52 -69
  210. package/build/esm/structure/io/binary/internals/DoubleSerializer.d.ts +12 -4
  211. package/build/esm/structure/io/binary/internals/DoubleSerializer.js +24 -38
  212. package/build/esm/structure/io/binary/internals/EdgeSerializer.d.ts +14 -12
  213. package/build/esm/structure/io/binary/internals/EdgeSerializer.js +69 -124
  214. package/build/esm/structure/io/binary/internals/EnumSerializer.d.ts +19 -4
  215. package/build/esm/structure/io/binary/internals/EnumSerializer.js +47 -59
  216. package/build/esm/structure/io/binary/internals/FloatSerializer.d.ts +12 -4
  217. package/build/esm/structure/io/binary/internals/FloatSerializer.js +24 -38
  218. package/build/esm/structure/io/binary/internals/GraphBinaryReader.d.ts +26 -2
  219. package/build/esm/structure/io/binary/internals/GraphBinaryReader.js +108 -37
  220. package/build/esm/structure/io/binary/internals/GraphBinaryWriter.js +6 -6
  221. package/build/esm/structure/io/binary/internals/GraphSerializer.d.ts +22 -0
  222. package/build/esm/structure/io/binary/internals/GraphSerializer.js +181 -0
  223. package/build/esm/structure/io/binary/internals/IntSerializer.d.ts +19 -4
  224. package/build/esm/structure/io/binary/internals/IntSerializer.js +33 -38
  225. package/build/esm/structure/io/binary/internals/LongSerializer.d.ts +13 -4
  226. package/build/esm/structure/io/binary/internals/LongSerializer.js +29 -42
  227. package/build/esm/structure/io/binary/internals/MapSerializer.d.ts +14 -7
  228. package/build/esm/structure/io/binary/internals/MapSerializer.js +36 -70
  229. package/build/esm/structure/io/binary/internals/MarkerSerializer.d.ts +13 -4
  230. package/build/esm/structure/io/binary/internals/MarkerSerializer.js +29 -33
  231. package/build/esm/structure/io/binary/internals/NumberSerializationStrategy.d.ts +0 -3
  232. package/build/esm/structure/io/binary/internals/NumberSerializationStrategy.js +28 -2
  233. package/build/esm/structure/io/binary/internals/PathSerializer.d.ts +14 -7
  234. package/build/esm/structure/io/binary/internals/PathSerializer.js +30 -55
  235. package/build/esm/structure/io/binary/internals/PrimitivePDTSerializer.d.ts +10 -0
  236. package/build/esm/structure/io/binary/internals/PrimitivePDTSerializer.js +77 -0
  237. package/build/esm/structure/io/binary/internals/PropertySerializer.d.ts +14 -7
  238. package/build/esm/structure/io/binary/internals/PropertySerializer.js +32 -69
  239. package/build/esm/structure/io/binary/internals/SetSerializer.d.ts +14 -7
  240. package/build/esm/structure/io/binary/internals/SetSerializer.js +39 -73
  241. package/build/esm/structure/io/binary/internals/ShortSerializer.d.ts +12 -4
  242. package/build/esm/structure/io/binary/internals/ShortSerializer.js +24 -38
  243. package/build/esm/structure/io/binary/internals/StreamReader.d.ts +69 -0
  244. package/build/esm/structure/io/binary/internals/StreamReader.js +181 -0
  245. package/build/esm/structure/io/binary/internals/StringSerializer.d.ts +14 -4
  246. package/build/esm/structure/io/binary/internals/StringSerializer.js +34 -53
  247. package/build/esm/structure/io/binary/internals/StubSerializer.d.ts +1 -1
  248. package/build/esm/structure/io/binary/internals/StubSerializer.js +2 -1
  249. package/build/esm/structure/io/binary/internals/TreeSerializer.d.ts +54 -0
  250. package/build/esm/structure/io/binary/internals/TreeSerializer.js +136 -0
  251. package/build/esm/structure/io/binary/internals/UnspecifiedNullSerializer.d.ts +6 -4
  252. package/build/esm/structure/io/binary/internals/UnspecifiedNullSerializer.js +8 -31
  253. package/build/esm/structure/io/binary/internals/UuidSerializer.d.ts +12 -7
  254. package/build/esm/structure/io/binary/internals/UuidSerializer.js +33 -49
  255. package/build/esm/structure/io/binary/internals/VertexPropertySerializer.d.ts +14 -7
  256. package/build/esm/structure/io/binary/internals/VertexPropertySerializer.js +37 -95
  257. package/build/esm/structure/io/binary/internals/VertexSerializer.d.ts +14 -9
  258. package/build/esm/structure/io/binary/internals/VertexSerializer.js +41 -68
  259. package/build/esm/utils.d.ts +62 -4
  260. package/build/esm/utils.js +145 -6
  261. package/package.json +27 -18
@@ -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
- * @param {...Object} args
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(...args: any[]): this;
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;
@@ -23,6 +23,7 @@ import { Traversal, cardinality } from './traversal.js';
23
23
  import { Transaction } from './transaction.js';
24
24
  import { TraversalStrategies, VertexProgramStrategy, OptionsStrategy } from './traversal-strategy.js';
25
25
  import { Vertex } from '../structure/graph.js';
26
+ import DriverRemoteConnection from '../driver/driver-remote-connection.js';
26
27
  import GremlinLang from './gremlin-lang.js';
27
28
  /**
28
29
  * Represents the primary DSL of the Gremlin traversal machine.
@@ -34,6 +35,8 @@ export class GraphTraversalSource {
34
35
  graphTraversalSourceClass;
35
36
  graphTraversalClass;
36
37
  remoteConnection;
38
+ /** @internal - set by Transaction.begin() for gtx.tx() to return the owning transaction */
39
+ _boundTransaction;
37
40
  /**
38
41
  * Creates a new instance of {@link GraphTraversalSource}.
39
42
  * @param {Graph} graph
@@ -56,11 +59,89 @@ export class GraphTraversalSource {
56
59
  * @returns {Transaction}
57
60
  */
58
61
  tx() {
59
- // you can't do g.tx().begin().tx() - no child transactions
60
- if (this.remoteConnection) {
62
+ // If this GTS is already bound to a transaction, return that transaction.
63
+ if (this._boundTransaction) {
64
+ return this._boundTransaction;
65
+ }
66
+ if (!this.remoteConnection) {
67
+ throw new Error('Remote connection is required for transactions');
68
+ }
69
+ // If the DRC has a transactionId, it was created by a Transaction.begin().
70
+ // But we don't have the Transaction reference here (only _boundTransaction above).
71
+ if (this.remoteConnection instanceof DriverRemoteConnection && this.remoteConnection.transactionId) {
61
72
  throw new Error('This TraversalSource is already bound to a transaction - child transactions are not supported');
62
73
  }
63
- return new Transaction(this);
74
+ // Extract the Client from the DriverRemoteConnection.
75
+ const client = this.remoteConnection._client;
76
+ return new Transaction(client);
77
+ }
78
+ /**
79
+ * Runs a unit of work inside a transaction, owning the full lifecycle.
80
+ *
81
+ * The transaction is begun automatically and the resulting transaction-bound
82
+ * <code>GraphTraversalSource</code> (<code>gtx</code>) is passed to the
83
+ * callback as its sole argument. Only <code>gtx</code> is in scope inside the
84
+ * callback, which avoids accidentally issuing traversals against the
85
+ * non-transactional <code>g</code>.
86
+ *
87
+ * On normal completion of the callback the transaction is committed; on any
88
+ * abnormal exit (a thrown error or a rejected promise) the transaction is
89
+ * rolled back. This is a single-shot operation: there is exactly one attempt
90
+ * (begin -> run -> commit/rollback) and no retry. A second transaction may not
91
+ * be opened from inside the callback (calling <code>gtx.tx().begin()</code>
92
+ * throws via the existing double-begin guard).
93
+ *
94
+ * The callback may be synchronous or asynchronous; its return value (or the
95
+ * value its promise resolves to) is awaited and returned from
96
+ * <code>executeInTx</code>. If the callback returns nothing the result is
97
+ * <code>undefined</code>.
98
+ *
99
+ * Error handling: if the callback throws/rejects, the original error is
100
+ * re-raised unchanged after rollback is attempted. If the commit itself fails,
101
+ * the commit error propagates and a rollback is still attempted afterward for
102
+ * server-side hygiene. In both cases a failed rollback during cleanup is logged
103
+ * as a warning and never replaces the primary error.
104
+ *
105
+ * @param txWork callback that receives the transaction-bound GraphTraversalSource
106
+ * @returns {Promise<T>} resolves to the callback's value (undefined if none)
107
+ */
108
+ async executeInTx(txWork) {
109
+ const tx = this.tx();
110
+ const gtx = await tx.begin();
111
+ let result;
112
+ // Phase 1: run the user's work. If it throws, roll back and rethrow the body error - the
113
+ // throw below exits the method, so a failed body never reaches the commit in phase 2.
114
+ try {
115
+ result = await txWork(gtx);
116
+ }
117
+ catch (bodyError) {
118
+ try {
119
+ await tx.rollback();
120
+ }
121
+ catch (rollbackError) {
122
+ console.warn('Rollback failed after transaction body error', rollbackError);
123
+ }
124
+ // Re-raise the exact original error; rollback failures never replace it.
125
+ throw bodyError;
126
+ }
127
+ // Phase 2: the body succeeded, so commit. A separate try because this failure mode is
128
+ // distinct (commit, not body): we still roll back for server hygiene, then rethrow the
129
+ // commit error as the primary error.
130
+ try {
131
+ await tx.commit();
132
+ }
133
+ catch (commitError) {
134
+ try {
135
+ // Attempt rollback so the server does not keep the transaction around.
136
+ await tx.rollback();
137
+ }
138
+ catch (rollbackError) {
139
+ console.warn('Rollback failed after commit failure', rollbackError);
140
+ }
141
+ // The commit error stays primary; rollback was only for server hygiene.
142
+ throw commitError;
143
+ }
144
+ return result;
64
145
  }
65
146
  /**
66
147
  * @param graphComputer
@@ -111,6 +192,10 @@ export class GraphTraversalSource {
111
192
  }
112
193
  glStrategies[glStrategies.length - 1].configuration[key] = val;
113
194
  const gl = new GremlinLang(this.gremlinLang);
195
+ // Render multilabel/singlelabel in gremlin text (temporary until these options are removed)
196
+ if (key === 'multilabel' || key === 'singlelabel') {
197
+ gl.appendGremlin(`.with("${key}")`);
198
+ }
114
199
  return new this.graphTraversalSourceClass(this.graph, new TraversalStrategies(this.traversalStrategies), gl, this.graphTraversalSourceClass, this.graphTraversalClass);
115
200
  }
116
201
  /**
@@ -269,6 +354,17 @@ export class GraphTraversalSource {
269
354
  const gl = new GremlinLang(this.gremlinLang).addStep('union', args);
270
355
  return new this.graphTraversalClass(this.graph, new TraversalStrategies(this.traversalStrategies), gl);
271
356
  }
357
+ /**
358
+ * Spawns a {@link GraphTraversal} by executing a declarative pattern match query.
359
+ * @param {string} matchQuery - the declarative query string
360
+ * @param {Record<string, any>} [params] - optional query parameters
361
+ * @returns {GraphTraversal}
362
+ */
363
+ match(matchQuery, params) {
364
+ const args = params !== undefined ? [matchQuery, params] : [matchQuery];
365
+ const gl = new GremlinLang(this.gremlinLang).addStep('match', args);
366
+ return new this.graphTraversalClass(this.graph, new TraversalStrategies(this.traversalStrategies), gl);
367
+ }
272
368
  }
273
369
  /**
274
370
  * Represents a graph traversal.
@@ -324,6 +420,15 @@ export class GraphTraversal extends Traversal {
324
420
  this.gremlinLang.addStep('addV', args);
325
421
  return this;
326
422
  }
423
+ /**
424
+ * Graph traversal addLabel method.
425
+ * @param {...Object} args
426
+ * @returns {GraphTraversal}
427
+ */
428
+ addLabel(...args) {
429
+ this.gremlinLang.addStep('addLabel', args);
430
+ return this;
431
+ }
327
432
  /**
328
433
  * Graph traversal aggregate method.
329
434
  * @param {...Object} args
@@ -630,6 +735,24 @@ export class GraphTraversal extends Traversal {
630
735
  this.gremlinLang.addStep('drop', args);
631
736
  return this;
632
737
  }
738
+ /**
739
+ * Graph traversal dropLabel method.
740
+ * @param {...Object} args
741
+ * @returns {GraphTraversal}
742
+ */
743
+ dropLabel(...args) {
744
+ this.gremlinLang.addStep('dropLabel', args);
745
+ return this;
746
+ }
747
+ /**
748
+ * Graph traversal dropLabels method.
749
+ * @param {...Object} args
750
+ * @returns {GraphTraversal}
751
+ */
752
+ dropLabels(...args) {
753
+ this.gremlinLang.addStep('dropLabels', args);
754
+ return this;
755
+ }
633
756
  /**
634
757
  * Graph traversal element method.
635
758
  * @param {...Object} args
@@ -887,6 +1010,15 @@ export class GraphTraversal extends Traversal {
887
1010
  this.gremlinLang.addStep('label', args);
888
1011
  return this;
889
1012
  }
1013
+ /**
1014
+ * Graph traversal labels method.
1015
+ * @param {...Object} args
1016
+ * @returns {GraphTraversal}
1017
+ */
1018
+ labels(...args) {
1019
+ this.gremlinLang.addStep('labels', args);
1020
+ return this;
1021
+ }
890
1022
  /**
891
1023
  * Graph traversal length method.
892
1024
  * @param {...Object} args
@@ -941,11 +1073,6 @@ export class GraphTraversal extends Traversal {
941
1073
  this.gremlinLang.addStep('map', args);
942
1074
  return this;
943
1075
  }
944
- /**
945
- * Graph traversal match method.
946
- * @param {...Object} args
947
- * @returns {GraphTraversal}
948
- */
949
1076
  match(...args) {
950
1077
  this.gremlinLang.addStep('match', args);
951
1078
  return this;
@@ -1570,6 +1697,7 @@ export const statics = {
1570
1697
  V: (...args) => callOnEmptyTraversal('V', args),
1571
1698
  addE: (...args) => callOnEmptyTraversal('addE', args),
1572
1699
  addV: (...args) => callOnEmptyTraversal('addV', args),
1700
+ addLabel: (...args) => callOnEmptyTraversal('addLabel', args),
1573
1701
  aggregate: (...args) => callOnEmptyTraversal('aggregate', args),
1574
1702
  all: (...args) => callOnEmptyTraversal('all', args),
1575
1703
  and: (...args) => callOnEmptyTraversal('and', args),
@@ -1602,6 +1730,8 @@ export const statics = {
1602
1730
  discard: (...args) => callOnEmptyTraversal('discard', args),
1603
1731
  disjunct: (...args) => callOnEmptyTraversal('disjunct', args),
1604
1732
  drop: (...args) => callOnEmptyTraversal('drop', args),
1733
+ dropLabel: (...args) => callOnEmptyTraversal('dropLabel', args),
1734
+ dropLabels: (...args) => callOnEmptyTraversal('dropLabels', args),
1605
1735
  element: (...args) => callOnEmptyTraversal('element', args),
1606
1736
  elementMap: (...args) => callOnEmptyTraversal('elementMap', args),
1607
1737
  emit: (...args) => callOnEmptyTraversal('emit', args),
@@ -1629,6 +1759,7 @@ export const statics = {
1629
1759
  is: (...args) => callOnEmptyTraversal('is', args),
1630
1760
  key: (...args) => callOnEmptyTraversal('key', args),
1631
1761
  label: (...args) => callOnEmptyTraversal('label', args),
1762
+ labels: (...args) => callOnEmptyTraversal('labels', args),
1632
1763
  length: (...args) => callOnEmptyTraversal('length', args),
1633
1764
  limit: (...args) => callOnEmptyTraversal('limit', args),
1634
1765
  local: (...args) => callOnEmptyTraversal('local', args),
@@ -1,15 +1,20 @@
1
1
  import { OptionsStrategy } from './traversal-strategy.js';
2
+ import { PDTRegistry } from '../structure/PDTRegistry.js';
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
- addG(g: string): void;
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
  }
@@ -18,24 +18,30 @@
18
18
  */
19
19
  import { P, TextP, EnumValue } from './traversal.js';
20
20
  import { OptionsStrategy, TraversalStrategy } from './traversal-strategy.js';
21
- import { Long } from '../utils.js';
22
- import { Vertex } from '../structure/graph.js';
21
+ import { Long, Int, Float, Double, Short, Byte, INT32_MIN, INT32_MAX } from '../utils.js';
22
+ import { Vertex, CompositePDT, PrimitivePDT } from '../structure/graph.js';
23
+ import { GValue } from './gvalue.js';
24
+ import { isDeepStrictEqual } from 'node:util';
25
+ import { Buffer } from 'buffer';
26
+ const PARAM_NAME_PATTERN = /^[\p{L}_$][\p{L}\p{Nd}_$]*$/u;
23
27
  export default class GremlinLang {
24
28
  gremlin = '';
25
29
  optionsStrategies = [];
26
30
  parameters = new Map();
31
+ pdtRegistry = null;
27
32
  constructor(toClone) {
28
33
  if (toClone) {
29
34
  this.gremlin = toClone.gremlin;
30
35
  this.optionsStrategies = [...toClone.optionsStrategies];
31
36
  this.parameters = new Map(toClone.parameters);
37
+ this.pdtRegistry = toClone.pdtRegistry;
32
38
  }
33
39
  }
34
40
  getOptionsStrategies() {
35
41
  return this.optionsStrategies;
36
42
  }
37
- addG(g) {
38
- this.parameters.set('g', g);
43
+ appendGremlin(text) {
44
+ this.gremlin += text;
39
45
  }
40
46
  getParameters() {
41
47
  return this.parameters;
@@ -46,7 +52,15 @@ export default class GremlinLang {
46
52
  }
47
53
  let result = p.operator + '(';
48
54
  if (Array.isArray(p.value)) {
49
- result += '[' + p.value.map(v => this._argAsString(v)).join(',') + ']';
55
+ // If all elements are traversals, serialize as comma-separated args (no brackets)
56
+ // This matches the server grammar: within(trav1, trav2) via genericArgumentVarargs
57
+ const allTraversals = p.value.length > 0 && p.value.every((v) => v != null && typeof v.getGremlinLang === 'function');
58
+ if (allTraversals) {
59
+ result += p.value.map((v) => this._argAsString(v)).join(',');
60
+ }
61
+ else {
62
+ result += '[' + p.value.map((v) => this._argAsString(v)).join(',') + ']';
63
+ }
50
64
  }
51
65
  else {
52
66
  result += this._argAsString(p.value);
@@ -65,6 +79,21 @@ export default class GremlinLang {
65
79
  if (arg instanceof Long) {
66
80
  return String(arg.value) + 'L';
67
81
  }
82
+ if (arg instanceof Float) {
83
+ return GremlinLang._fpAsString(arg.value, 'F');
84
+ }
85
+ if (arg instanceof Double) {
86
+ return GremlinLang._fpAsString(arg.value, 'D');
87
+ }
88
+ if (arg instanceof Short) {
89
+ return String(arg.value) + 'S';
90
+ }
91
+ if (arg instanceof Byte) {
92
+ return String(arg.value) + 'B';
93
+ }
94
+ if (arg instanceof Int) {
95
+ return String(arg.value);
96
+ }
68
97
  if (typeof arg === 'bigint') {
69
98
  return String(arg) + 'N';
70
99
  }
@@ -77,9 +106,9 @@ export default class GremlinLang {
77
106
  return '-Infinity';
78
107
  if (!Number.isInteger(arg))
79
108
  return String(arg) + 'D';
80
- if (arg >= -2147483648 && arg <= 2147483647)
109
+ if (arg >= INT32_MIN && arg <= INT32_MAX)
81
110
  return String(arg);
82
- // Outside safe integer range, values have lost precision and may exceed Java Long — emit as Double.
111
+ // Outside safe integer range, values have lost precision and may exceed Java Long - emit as Double.
83
112
  if (arg > Number.MAX_SAFE_INTEGER || arg < -Number.MAX_SAFE_INTEGER)
84
113
  return String(arg) + 'D';
85
114
  return String(arg) + 'L';
@@ -94,6 +123,21 @@ export default class GremlinLang {
94
123
  const escaped = JSON.stringify(arg).slice(1, -1).replace(/'/g, "\\'");
95
124
  return `'${escaped}'`;
96
125
  }
126
+ if (arg instanceof GValue) {
127
+ const key = arg.name;
128
+ if (!PARAM_NAME_PATTERN.test(key)) {
129
+ throw new Error(`Invalid parameter name [${key}].`);
130
+ }
131
+ if (this.parameters.has(key)) {
132
+ if (!isDeepStrictEqual(this.parameters.get(key), arg.value)) {
133
+ throw new Error(`Parameter with name ${key} already exists.`);
134
+ }
135
+ }
136
+ else {
137
+ this.parameters.set(key, arg.value);
138
+ }
139
+ return key;
140
+ }
97
141
  if (arg instanceof P || arg instanceof TextP) {
98
142
  return this._predicateAsString(arg);
99
143
  }
@@ -112,10 +156,29 @@ export default class GremlinLang {
112
156
  if (typeof arg === 'function' && arg.prototype instanceof TraversalStrategy) {
113
157
  return arg.name;
114
158
  }
159
+ if (arg instanceof PrimitivePDT) {
160
+ // PDT literals use double-quoted strings (consistent with the composite PDT form below);
161
+ // JSON.stringify handles special-character escaping, then the outer quotes are stripped.
162
+ const escapedName = JSON.stringify(arg.name).slice(1, -1);
163
+ const escapedValue = JSON.stringify(arg.value).slice(1, -1);
164
+ return `PDT("${escapedName}","${escapedValue}")`;
165
+ }
166
+ if (arg instanceof CompositePDT) {
167
+ const fields = arg.fields;
168
+ const keys = Object.keys(fields);
169
+ const escapedName = JSON.stringify(arg.name).slice(1, -1);
170
+ if (keys.length === 0)
171
+ return `PDT("${escapedName}",[:])`;
172
+ const entries = keys.map(k => `${this._argAsString(k)}:${this._argAsString(fields[k])}`);
173
+ return `PDT("${escapedName}",[${entries.join(',')}])`;
174
+ }
115
175
  if (arg instanceof Vertex) {
116
176
  return this._argAsString(arg.id);
117
177
  }
118
178
  if (arg instanceof GremlinLang) {
179
+ // Merge the child's parameters so GValue bindings nested inside a child
180
+ // traversal are still sent to the server alongside the rendered query.
181
+ arg.parameters.forEach((v, k) => this.parameters.set(k, v));
119
182
  return arg.getGremlin('__');
120
183
  }
121
184
  if (typeof arg.getGremlinLang === 'function') {
@@ -123,7 +186,14 @@ export default class GremlinLang {
123
186
  if (arg.graph != null) {
124
187
  throw new Error('Child traversal must be anonymous - use __ not g');
125
188
  }
126
- return arg.getGremlinLang().getGremlin('__');
189
+ const childLang = arg.getGremlinLang();
190
+ // Merge the child's parameters so GValue bindings nested inside a child
191
+ // traversal are still sent to the server alongside the rendered query.
192
+ childLang.parameters.forEach((v, k) => this.parameters.set(k, v));
193
+ return childLang.getGremlin('__');
194
+ }
195
+ if (arg instanceof Uint8Array) {
196
+ return `Binary("${Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength).toString('base64')}")`;
127
197
  }
128
198
  if (arg instanceof Set) {
129
199
  const items = [...arg];
@@ -151,7 +221,20 @@ export default class GremlinLang {
151
221
  return '[:]';
152
222
  return '[' + entries.map(([k, v]) => `${this._argAsString(k)}:${this._argAsString(v)}`).join(',') + ']';
153
223
  }
154
- return String(arg);
224
+ // Registry-based dehydration
225
+ if (this.pdtRegistry && typeof arg === 'object' && arg.constructor) {
226
+ const primitiveEntry = this.pdtRegistry.getPrimitiveAdapterByClass(arg.constructor);
227
+ if (primitiveEntry) {
228
+ const value = primitiveEntry.toValue(arg);
229
+ return this._argAsString(new PrimitivePDT(primitiveEntry.typeName, value));
230
+ }
231
+ const entry = this.pdtRegistry.getAdapterByClass(arg.constructor);
232
+ if (entry) {
233
+ const fields = entry.serialize(arg);
234
+ return this._argAsString(new CompositePDT(entry.typeName, fields));
235
+ }
236
+ }
237
+ throw new TypeError(`GremlinLang contains at least one type [${arg?.constructor?.name ?? typeof arg}] that cannot be represented as text.`);
155
238
  }
156
239
  addStep(name, args) {
157
240
  const argsStr = args?.length ? args.map(a => this._argAsString(a)).join(',') : '';
@@ -169,6 +252,13 @@ export default class GremlinLang {
169
252
  for (const strategy of args) {
170
253
  if (strategy instanceof OptionsStrategy) {
171
254
  this.optionsStrategies.push(strategy);
255
+ // Render multilabel/singlelabel in gremlin text (temporary until these options are removed)
256
+ if (strategy.configuration['multilabel'] !== undefined) {
257
+ this.gremlin += '.with("multilabel")';
258
+ }
259
+ if (strategy.configuration['singlelabel'] !== undefined) {
260
+ this.gremlin += '.with("singlelabel")';
261
+ }
172
262
  }
173
263
  else {
174
264
  nonOptionsStrategies.push(strategy);
@@ -184,10 +274,32 @@ export default class GremlinLang {
184
274
  this.gremlin += `.${name}(${argsStr})`;
185
275
  return this;
186
276
  }
277
+ static _fpAsString(v, suffix) {
278
+ if (v === Infinity)
279
+ return '+Infinity';
280
+ if (v === -Infinity)
281
+ return '-Infinity';
282
+ if (Number.isNaN(v))
283
+ return 'NaN';
284
+ return Number.isInteger(v) ? `${v}.0${suffix}` : `${v}${suffix}`;
285
+ }
187
286
  getGremlin(prefix = 'g') {
188
287
  if (this.gremlin.length > 0 && this.gremlin[0] !== '.') {
189
288
  return this.gremlin;
190
289
  }
191
290
  return prefix + this.gremlin;
192
291
  }
292
+ getParametersAsString() {
293
+ return GremlinLang.convertParametersToString(this.parameters);
294
+ }
295
+ static convertParametersToString(params) {
296
+ if (params == null || params.size === 0)
297
+ return '[:]';
298
+ const helper = new GremlinLang();
299
+ const parts = [];
300
+ params.forEach((v, k) => {
301
+ parts.push(`${helper._argAsString(k)}:${helper._argAsString(v)}`);
302
+ });
303
+ return '[' + parts.join(',') + ']';
304
+ }
193
305
  }
@@ -0,0 +1,7 @@
1
+ export declare class GValue<T = any> {
2
+ readonly name: string;
3
+ readonly value: T;
4
+ constructor(name: string, value: T);
5
+ isNull(): boolean;
6
+ toString(): string;
7
+ }
@@ -0,0 +1,38 @@
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
+ export class GValue {
20
+ name;
21
+ value;
22
+ constructor(name, value) {
23
+ if (value instanceof GValue) {
24
+ throw new Error('GValues cannot be nested');
25
+ }
26
+ if (name == null) {
27
+ throw new Error('GValue name cannot be null.');
28
+ }
29
+ this.name = name;
30
+ this.value = value;
31
+ }
32
+ isNull() {
33
+ return this.value == null;
34
+ }
35
+ toString() {
36
+ return `${this.name}=${this.value}`;
37
+ }
38
+ }