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
@@ -1,34 +1,70 @@
1
+ import Client from '../driver/client.js';
1
2
  import { GraphTraversalSource } from './graph-traversal.js';
2
3
  /**
3
- * A controller for a remote transaction that is constructed from <code>g.tx()</code>. Calling <code>begin()</code>
4
- * on this object will produce a new <code>GraphTraversalSource</code> that is bound to a remote transaction over which
5
- * multiple traversals may be executed in that context. Calling <code>commit()</code> or <code>rollback()</code> will
6
- * then close the transaction and thus, the session. This feature only works with transaction enabled graphs.
4
+ * Controls an explicit remote transaction. A thin wrapper around a Client that
5
+ * adds transaction lifecycle (begin/commit/rollback/close) and attaches a
6
+ * transactionId to every request.
7
+ *
8
+ * Created via Client.transact() or g.tx(). The traversal source (g alias) is
9
+ * inherited from the Client and cannot be changed.
10
+ *
11
+ * Transactions are short-lived and single-use. After commit or rollback, the
12
+ * transaction ID is invalid and the object cannot be reused.
13
+ *
14
+ * Each traversal on the transaction-bound source must be awaited before
15
+ * submitting the next, to ensure the server receives requests in order.
16
+ *
17
+ * This class is NOT thread-safe. Do not share a Transaction across concurrent
18
+ * async contexts without external synchronization.
7
19
  */
8
20
  export declare class Transaction {
9
- private readonly g;
10
- private _sessionBasedConnection?;
11
- constructor(g: GraphTraversalSource);
21
+ #private;
22
+ private _transactionId?;
23
+ private _isOpen;
24
+ private _failed;
25
+ private readonly _client;
12
26
  /**
13
- * Spawns a <code>GraphTraversalSource</code> that is bound to a remote session which enables a transaction.
14
- * @returns {GraphTraversalSource}
27
+ * Creates a Transaction. Accepts a Client which provides the connection
28
+ * and traversal source for all transaction requests.
15
29
  */
16
- begin(): GraphTraversalSource;
30
+ constructor(client: Client);
17
31
  /**
18
- * @returns {Promise}
32
+ * Spawns a GraphTraversalSource that is bound to a remote transaction.
33
+ *
34
+ * begin() is idempotent: calling it while a transaction is already open does not send a
35
+ * second begin to the server and does not throw - it reuses the existing transaction ID and
36
+ * returns a source bound to the same transaction. A transaction is single-use, so calling
37
+ * begin() after it has been closed (commit/rollback/failed begin) throws.
38
+ * @returns {Promise<GraphTraversalSource>}
39
+ */
40
+ begin(): Promise<GraphTraversalSource>;
41
+ /**
42
+ * Commits the transaction.
43
+ * @returns {Promise<void>}
19
44
  */
20
45
  commit(): Promise<void>;
21
46
  /**
22
- * @returns {Promise}
47
+ * Rolls back the transaction.
48
+ * @returns {Promise<void>}
23
49
  */
24
50
  rollback(): Promise<void>;
25
51
  /**
26
52
  * Returns true if transaction is open.
27
- * @returns {Boolean}
28
53
  */
29
54
  get isOpen(): boolean;
30
55
  /**
31
- * @returns {Promise}
56
+ * Returns the server-generated transaction ID, or undefined if not yet begun.
57
+ */
58
+ get transactionId(): string | undefined;
59
+ /**
60
+ * Closes the transaction. Default behavior is rollback: partial work is
61
+ * discarded rather than accidentally persisted.
62
+ * @returns {Promise<void>}
32
63
  */
33
64
  close(): Promise<void>;
65
+ /**
66
+ * Submits a gremlin-lang string within this transaction. The transactionId
67
+ * is automatically attached. Has the same signature as Client.submit().
68
+ */
69
+ submit(gremlin: string, parameters?: any, requestOptions?: any): Promise<any>;
34
70
  }
@@ -16,50 +16,149 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { RemoteStrategy } from '../driver/remote-connection.js';
20
+ import DriverRemoteConnection from '../driver/driver-remote-connection.js';
21
+ import GremlinLang from './gremlin-lang.js';
22
+ import { GraphTraversalSource } from './graph-traversal.js';
23
+ import { TraversalStrategies } from './traversal-strategy.js';
19
24
  /**
20
- * A controller for a remote transaction that is constructed from <code>g.tx()</code>. Calling <code>begin()</code>
21
- * on this object will produce a new <code>GraphTraversalSource</code> that is bound to a remote transaction over which
22
- * multiple traversals may be executed in that context. Calling <code>commit()</code> or <code>rollback()</code> will
23
- * then close the transaction and thus, the session. This feature only works with transaction enabled graphs.
25
+ * Controls an explicit remote transaction. A thin wrapper around a Client that
26
+ * adds transaction lifecycle (begin/commit/rollback/close) and attaches a
27
+ * transactionId to every request.
28
+ *
29
+ * Created via Client.transact() or g.tx(). The traversal source (g alias) is
30
+ * inherited from the Client and cannot be changed.
31
+ *
32
+ * Transactions are short-lived and single-use. After commit or rollback, the
33
+ * transaction ID is invalid and the object cannot be reused.
34
+ *
35
+ * Each traversal on the transaction-bound source must be awaited before
36
+ * submitting the next, to ensure the server receives requests in order.
37
+ *
38
+ * This class is NOT thread-safe. Do not share a Transaction across concurrent
39
+ * async contexts without external synchronization.
24
40
  */
25
41
  export class Transaction {
26
- g;
27
- _sessionBasedConnection = undefined;
28
- constructor(g) {
29
- this.g = g;
42
+ _transactionId;
43
+ _isOpen = false;
44
+ _failed = false;
45
+ _client;
46
+ /**
47
+ * Creates a Transaction. Accepts a Client which provides the connection
48
+ * and traversal source for all transaction requests.
49
+ */
50
+ constructor(client) {
51
+ if (!client) {
52
+ throw new Error('Client is required for transactions');
53
+ }
54
+ this._client = client;
30
55
  }
31
56
  /**
32
- * Spawns a <code>GraphTraversalSource</code> that is bound to a remote session which enables a transaction.
33
- * @returns {GraphTraversalSource}
57
+ * Spawns a GraphTraversalSource that is bound to a remote transaction.
58
+ *
59
+ * begin() is idempotent: calling it while a transaction is already open does not send a
60
+ * second begin to the server and does not throw - it reuses the existing transaction ID and
61
+ * returns a source bound to the same transaction. A transaction is single-use, so calling
62
+ * begin() after it has been closed (commit/rollback/failed begin) throws.
63
+ * @returns {Promise<GraphTraversalSource>}
34
64
  */
35
- begin() {
36
- throw new Error("Transactions are not yet implemented");
65
+ async begin() {
66
+ if (this._failed) {
67
+ throw new Error('Transaction is closed and cannot be reused; begin a new transaction');
68
+ }
69
+ // idempotent: if a transaction is already open, reuse the existing transactionId without
70
+ // sending a second begin to the server, and return a source bound to the same transaction
71
+ if (!this._isOpen) {
72
+ let result;
73
+ try {
74
+ result = await this._client.submit('g.tx().begin()', null);
75
+ }
76
+ catch (e) {
77
+ this._failed = true;
78
+ throw e;
79
+ }
80
+ const resultArray = result.toArray();
81
+ if (!resultArray || resultArray.length === 0) {
82
+ this._failed = true;
83
+ throw new Error('Server did not return transaction ID');
84
+ }
85
+ const resultMap = resultArray[0];
86
+ if (!resultMap || !(resultMap instanceof Map) || !resultMap.get('transactionId')) {
87
+ this._failed = true;
88
+ throw new Error('Server did not return transaction ID in expected format');
89
+ }
90
+ this._transactionId = resultMap.get('transactionId');
91
+ this._isOpen = true;
92
+ this._client.trackTransaction(this);
93
+ }
94
+ // Create a DriverRemoteConnection bound to this transaction. The DRC
95
+ // will automatically attach the transactionId to all requests.
96
+ const txConnection = new DriverRemoteConnection(this._client.url, this._client.options, this._transactionId);
97
+ const strategies = new TraversalStrategies();
98
+ strategies.addStrategy(new RemoteStrategy(txConnection));
99
+ const gtx = new GraphTraversalSource(null, strategies, new GremlinLang());
100
+ gtx._boundTransaction = this;
101
+ return gtx;
37
102
  }
38
103
  /**
39
- * @returns {Promise}
104
+ * Commits the transaction.
105
+ * @returns {Promise<void>}
40
106
  */
41
- commit() {
42
- throw new Error("Transactions are not yet implemented");
107
+ async commit() {
108
+ await this.#closeTransaction('g.tx().commit()');
43
109
  }
44
110
  /**
45
- * @returns {Promise}
111
+ * Rolls back the transaction.
112
+ * @returns {Promise<void>}
46
113
  */
47
- rollback() {
48
- throw new Error("Transactions are not yet implemented");
114
+ async rollback() {
115
+ await this.#closeTransaction('g.tx().rollback()');
49
116
  }
50
117
  /**
51
118
  * Returns true if transaction is open.
52
- * @returns {Boolean}
53
119
  */
54
120
  get isOpen() {
55
- return this._sessionBasedConnection?.isOpen ?? false;
121
+ return this._isOpen;
56
122
  }
57
123
  /**
58
- * @returns {Promise}
124
+ * Returns the server-generated transaction ID, or undefined if not yet begun.
125
+ */
126
+ get transactionId() {
127
+ return this._transactionId;
128
+ }
129
+ /**
130
+ * Closes the transaction. Default behavior is rollback: partial work is
131
+ * discarded rather than accidentally persisted.
132
+ * @returns {Promise<void>}
59
133
  */
60
134
  async close() {
61
- if (this._sessionBasedConnection) {
62
- this._sessionBasedConnection.close();
135
+ if (this._isOpen) {
136
+ await this.rollback();
137
+ }
138
+ }
139
+ /**
140
+ * Submits a gremlin-lang string within this transaction. The transactionId
141
+ * is automatically attached. Has the same signature as Client.submit().
142
+ */
143
+ async submit(gremlin, parameters, requestOptions) {
144
+ if (!this._isOpen) {
145
+ throw new Error('Transaction is not open');
146
+ }
147
+ const opts = {
148
+ ...requestOptions,
149
+ transactionId: this._transactionId,
150
+ };
151
+ return this._client.submit(gremlin, parameters || null, opts);
152
+ }
153
+ async #closeTransaction(script) {
154
+ if (!this._isOpen) {
155
+ throw new Error('Transaction is not open');
63
156
  }
157
+ await this._client.submit(script, null, {
158
+ transactionId: this._transactionId
159
+ });
160
+ this._isOpen = false;
161
+ this._failed = true; // Terminal state: transaction cannot be reused
162
+ this._client.untrackTransaction(this);
64
163
  }
65
164
  }
@@ -13,13 +13,29 @@ export declare class Traversal {
13
13
  graph: Graph | null;
14
14
  traversalStrategies: TraversalStrategies | null;
15
15
  gremlinLang: GremlinLang;
16
- results: any[] | null;
16
+ /** @internal Async results stream set by RemoteStrategy */
17
+ _resultsStream: AsyncGenerator<any> | null;
18
+ /** @internal Buffered traverser for bulk expansion and hasNext peek */
19
+ private _currentTraverser;
20
+ /** Trailing response status from the server, populated after iteration completes. */
21
+ private _status;
17
22
  sideEffects?: any;
18
23
  private _traversalStrategiesPromise;
19
- private _resultsIteratorIndex;
24
+ private _done;
20
25
  constructor(graph: Graph | null, traversalStrategies: TraversalStrategies | null, gremlinLang?: GremlinLang);
21
26
  /** @returns {GremlinLang} */
22
27
  getGremlinLang(): GremlinLang;
28
+ /**
29
+ * Gets the trailing response status from the server.
30
+ * Available after the traversal has been fully iterated (via toList(), iterate(), or manual iteration).
31
+ * Returns null if the traversal has not completed.
32
+ * @returns {{ code: number, message: string | null, exception: string | null } | null}
33
+ */
34
+ getStatus(): {
35
+ code: number;
36
+ message: string | null;
37
+ exception: string | null;
38
+ } | null;
23
39
  /**
24
40
  * Returns an Array containing the traverser objects.
25
41
  * @returns {Promise.<Array>}
@@ -36,16 +52,27 @@ export declare class Traversal {
36
52
  */
37
53
  iterate(): Promise<void>;
38
54
  /**
39
- * Async iterator method implementation.
40
- * Returns a promise containing an iterator item.
41
- * @returns {Promise.<{value, done}>}
55
+ * Returns the next result from the traversal.
56
+ *
57
+ * When called without an argument, returns a Promise that resolves to an iterator
58
+ * item ({value, done}), following the async iterator protocol.
59
+ *
60
+ * When called with an amount, returns a Promise that resolves to an Array containing
61
+ * up to {@code amount} result values. The Array form is always used when an amount is
62
+ * supplied, including {@code next(1)}, which resolves to an Array of one value rather
63
+ * than a bare value, matching the behavior of next(n) in the other Gremlin language
64
+ * variants. If fewer results remain, the Array contains only those that remain, and an
65
+ * amount of zero or less yields an empty Array.
66
+ * @param {Number} [amount] The number of results to retrieve.
67
+ * @returns {Promise.<{value, done}>|Promise.<Array>}
42
68
  */
43
69
  next<T>(): Promise<IteratorResult<T, null>>;
70
+ next<T>(amount: number): Promise<T[]>;
44
71
  /**
45
- * Synchronous iterator of traversers including
72
+ * Pull the next value, handling Traverser bulk expansion.
46
73
  * @private
47
74
  */
48
- _getNext<T>(): IteratorResult<T, null>;
75
+ _getNext<T>(): Promise<IteratorResult<T, null>>;
49
76
  _applyStrategies(): Promise<void>;
50
77
  /**
51
78
  * Returns step instructions during JSON serialization
@@ -81,8 +108,8 @@ export declare class P<T1 = any, T2 = any> {
81
108
  toString(): string;
82
109
  and(arg?: any): P<this, any>;
83
110
  or(arg?: any): P<this, any>;
84
- static within(...args: any[]): P<any[], null>;
85
- static without(...args: any[]): P<any[], null>;
111
+ static within(...args: any[]): P<any, null>;
112
+ static without(...args: any[]): P<any, null>;
86
113
  /** @param {...Object} args */
87
114
  static between(...args: any[]): any;
88
115
  /** @param {...Object} args */
@@ -173,7 +200,6 @@ export declare const dt: Record<string, EnumValue>;
173
200
  export declare const gType: {
174
201
  [key: string]: any;
175
202
  };
176
- export declare const graphSONVersion: Record<string, EnumValue>;
177
203
  export declare const gryoVersion: Record<string, EnumValue>;
178
204
  export declare const merge: Record<string, EnumValue>;
179
205
  export declare const operator: Record<string, EnumValue>;
@@ -23,10 +23,15 @@ export class Traversal {
23
23
  graph;
24
24
  traversalStrategies;
25
25
  gremlinLang;
26
- results = null;
26
+ /** @internal Async results stream set by RemoteStrategy */
27
+ _resultsStream = null;
28
+ /** @internal Buffered traverser for bulk expansion and hasNext peek */
29
+ _currentTraverser = null;
30
+ /** Trailing response status from the server, populated after iteration completes. */
31
+ _status = null;
27
32
  sideEffects = null;
28
33
  _traversalStrategiesPromise = null;
29
- _resultsIteratorIndex = 0;
34
+ _done = false;
30
35
  constructor(graph, traversalStrategies, gremlinLang = new GremlinLang()) {
31
36
  this.graph = graph;
32
37
  this.traversalStrategies = traversalStrategies;
@@ -42,75 +47,122 @@ export class Traversal {
42
47
  getGremlinLang() {
43
48
  return this.gremlinLang;
44
49
  }
50
+ /**
51
+ * Gets the trailing response status from the server.
52
+ * Available after the traversal has been fully iterated (via toList(), iterate(), or manual iteration).
53
+ * Returns null if the traversal has not completed.
54
+ * @returns {{ code: number, message: string | null, exception: string | null } | null}
55
+ */
56
+ getStatus() {
57
+ return this._status;
58
+ }
45
59
  /**
46
60
  * Returns an Array containing the traverser objects.
47
61
  * @returns {Promise.<Array>}
48
62
  */
49
- toList() {
50
- return this._applyStrategies().then(() => {
51
- const result = [];
52
- let it;
53
- while ((it = this._getNext()) && !it.done) {
54
- result.push(it.value);
55
- }
56
- return result;
57
- });
63
+ async toList() {
64
+ await this._applyStrategies();
65
+ const result = [];
66
+ while (true) {
67
+ const it = await this._getNext();
68
+ if (it.done)
69
+ break;
70
+ result.push(it.value);
71
+ }
72
+ return result;
58
73
  }
59
74
  /**
60
75
  * Determines if there are any more items to iterate from the traversal.
61
76
  * @returns {Promise.<boolean>}
62
77
  */
63
- hasNext() {
64
- return this._applyStrategies().then(() => {
65
- if (!this.results || this.results.length <= 0 || this._resultsIteratorIndex >= this.results.length) {
78
+ async hasNext() {
79
+ await this._applyStrategies();
80
+ // If we have a current traverser with remaining bulk, there's more
81
+ if (this._currentTraverser && this._currentTraverser.bulk > 0) {
82
+ return true;
83
+ }
84
+ if (this._done)
85
+ return false;
86
+ // Try to pull the next item from the source to check
87
+ if (this._resultsStream) {
88
+ const { value, done } = await this._resultsStream.next();
89
+ if (done) {
90
+ this._done = true;
66
91
  return false;
67
92
  }
68
- if (this.results[this._resultsIteratorIndex] instanceof Traverser) {
69
- return this.results[this._resultsIteratorIndex].bulk > 0 || this._resultsIteratorIndex + 1 < this.results.length;
70
- }
71
- else {
72
- return true;
73
- }
74
- });
93
+ // Buffer it as a traverser for the next _getNext() call
94
+ this._currentTraverser = value instanceof Traverser ? value : new Traverser(value, 1);
95
+ return true;
96
+ }
97
+ return false;
75
98
  }
76
99
  /**
77
100
  * Iterates all Traverser instances in the traversal.
78
101
  * @returns {Promise}
79
102
  */
80
- iterate() {
103
+ async iterate() {
81
104
  this.gremlinLang.addStep('discard');
82
- return this._applyStrategies().then(() => {
83
- let it;
84
- while ((it = this._getNext()) && !it.done) {
85
- //
86
- }
87
- });
105
+ await this._applyStrategies();
106
+ while (true) {
107
+ const it = await this._getNext();
108
+ if (it.done)
109
+ break;
110
+ }
88
111
  }
89
- /**
90
- * Async iterator method implementation.
91
- * Returns a promise containing an iterator item.
92
- * @returns {Promise.<{value, done}>}
93
- */
94
- next() {
95
- return this._applyStrategies().then(() => this._getNext());
112
+ async next(amount) {
113
+ await this._applyStrategies();
114
+ if (amount === undefined || amount === null) {
115
+ return this._getNext();
116
+ }
117
+ const result = [];
118
+ for (let i = 0; i < amount; i++) {
119
+ const it = await this._getNext();
120
+ if (it.done) {
121
+ break;
122
+ }
123
+ result.push(it.value);
124
+ }
125
+ return result;
96
126
  }
97
127
  /**
98
- * Synchronous iterator of traversers including
128
+ * Pull the next value, handling Traverser bulk expansion.
99
129
  * @private
100
130
  */
101
- _getNext() {
102
- while (this.results && this._resultsIteratorIndex < this.results.length) {
103
- const next = this.results[this._resultsIteratorIndex];
104
- if (next instanceof Traverser) {
105
- if (next.bulk > 0) {
106
- next.bulk--;
107
- return { value: next.object, done: false };
131
+ async _getNext() {
132
+ // Drain current traverser's bulk first
133
+ if (this._currentTraverser) {
134
+ if (this._currentTraverser.bulk > 0) {
135
+ this._currentTraverser.bulk--;
136
+ const value = this._currentTraverser.object;
137
+ if (this._currentTraverser.bulk <= 0) {
138
+ this._currentTraverser = null;
108
139
  }
140
+ return { value, done: false };
109
141
  }
110
- this._resultsIteratorIndex++;
111
- if (!(next instanceof Traverser)) {
112
- return { value: next, done: false };
142
+ this._currentTraverser = null;
143
+ }
144
+ // Streaming source path
145
+ if (this._resultsStream) {
146
+ if (this._done)
147
+ return itemDone;
148
+ const { value, done } = await this._resultsStream.next();
149
+ if (done) {
150
+ this._done = true;
151
+ this._status = value ?? null;
152
+ return itemDone;
113
153
  }
154
+ if (value instanceof Traverser) {
155
+ if (value.bulk > 0) {
156
+ value.bulk--;
157
+ const result = value.object;
158
+ if (value.bulk > 0) {
159
+ this._currentTraverser = value;
160
+ }
161
+ return { value: result, done: false };
162
+ }
163
+ return itemDone;
164
+ }
165
+ return { value, done: false };
114
166
  }
115
167
  return itemDone;
116
168
  }
@@ -255,12 +307,18 @@ export class P {
255
307
  if (args.length === 1 && Array.isArray(args[0])) {
256
308
  return new P('within', args[0], null);
257
309
  }
310
+ if (args.length === 1 && args[0] != null && typeof args[0].getGremlinLang === 'function') {
311
+ return new P('within', args[0], null);
312
+ }
258
313
  return new P('within', args, null);
259
314
  }
260
315
  static without(...args) {
261
316
  if (args.length === 1 && Array.isArray(args[0])) {
262
317
  return new P('without', args[0], null);
263
318
  }
319
+ if (args.length === 1 && args[0] != null && typeof args[0].getGremlinLang === 'function') {
320
+ return new P('without', args[0], null);
321
+ }
264
322
  return new P('without', args, null);
265
323
  }
266
324
  /** @param {...Object} args */
@@ -457,7 +515,6 @@ export const column = toEnum('Column', 'keys values');
457
515
  export const direction = toDirectionEnum('Direction', 'BOTH IN OUT from_ to');
458
516
  export const dt = toEnum('DT', 'second minute hour day');
459
517
  export const gType = toGTypeEnum('GType', 'bigDecimal bigInt binary boolean byte char datetime double duration edge float graph int list long map null number path property set short string tree uuid vertex vproperty');
460
- export const graphSONVersion = toEnum('GraphSONVersion', 'V1_0 V2_0 V3_0');
461
518
  export const gryoVersion = toEnum('GryoVersion', 'V1_0 V3_0');
462
519
  export const merge = toEnum('Merge', 'onCreate onMatch outV inV');
463
520
  export const operator = toEnum('Operator', 'addAll and assign div max min minus mult or sum sumLong');
@@ -0,0 +1,34 @@
1
+ export interface PdtAdapter {
2
+ serialize: (obj: any) => Record<string, any>;
3
+ deserialize: (fields: Record<string, any>) => any;
4
+ }
5
+ export interface PrimitivePdtAdapter {
6
+ toValue: (obj: any) => string;
7
+ fromValue: (value: string) => any;
8
+ }
9
+ /**
10
+ * A standalone registry that allows users to register adapters for hydrating
11
+ * raw {@link CompositePDT} and {@link PrimitivePDT} instances
12
+ * into domain-specific objects.
13
+ */
14
+ export declare class PDTRegistry {
15
+ private readonly _adapters;
16
+ private readonly _adaptersByClass;
17
+ private readonly _primitiveAdapters;
18
+ private readonly _primitiveAdaptersByClass;
19
+ register(typeName: string, adapter: PdtAdapter, targetClass?: Function): void;
20
+ registerPrimitive(typeName: string, adapter: PrimitivePdtAdapter, targetClass?: Function): void;
21
+ hydrate(pdt: any): any;
22
+ hydratePrimitive(pdt: any): any;
23
+ hasAdapter(typeName: string): boolean;
24
+ hasPrimitiveAdapter(typeName: string): boolean;
25
+ getSerializer(typeName: string): ((obj: any) => Record<string, any>) | null;
26
+ getAdapterByClass(cls: Function): {
27
+ typeName: string;
28
+ serialize: (obj: any) => Record<string, any>;
29
+ } | null;
30
+ getPrimitiveAdapterByClass(cls: Function): {
31
+ typeName: string;
32
+ toValue: (obj: any) => string;
33
+ } | null;
34
+ }