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