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
@@ -20,13 +20,15 @@ import { Buffer } from 'buffer';
20
20
  export function basic(username, password) {
21
21
  return (request) => {
22
22
  request.headers['authorization'] = 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
23
- return request;
24
23
  };
25
24
  }
26
25
  export function sigv4(region, service, credentialsProvider) {
27
26
  let signer;
28
27
  let resolvedProvider;
29
28
  return async (request) => {
29
+ // Ensure body is serialized to JSON bytes before signing.
30
+ // serializeBody is idempotent: safe to call even if already serialized.
31
+ request.serializeBody();
30
32
  // Lazy-initialize signer and credentials provider on first use
31
33
  if (!signer) {
32
34
  const { SignatureV4 } = await import('@smithy/signature-v4');
@@ -47,6 +49,11 @@ export function sigv4(region, service, credentialsProvider) {
47
49
  });
48
50
  }
49
51
  const url = new URL(request.url);
52
+ // Sign only the Host header; the signer itself adds (and signs) x-amz-date, the payload hash,
53
+ // and x-amz-security-token for session credentials. The request's own headers (accept,
54
+ // content-type, ...) are deliberately NOT fed into the signature: the HTTP stack may add or
55
+ // rewrite transport-managed headers such as accept-encoding after this interceptor runs, so a
56
+ // signature covering them would no longer match the bytes actually sent.
50
57
  const signed = await signer.sign({
51
58
  method: request.method,
52
59
  protocol: url.protocol,
@@ -54,12 +61,12 @@ export function sigv4(region, service, credentialsProvider) {
54
61
  port: url.port ? Number(url.port) : undefined,
55
62
  path: url.pathname + url.search,
56
63
  headers: {
57
- ...request.headers,
58
64
  host: url.host,
59
65
  },
60
66
  body: request.body,
61
67
  });
62
- request.headers = signed.headers;
63
- return request;
68
+ // Merge the signed auth headers onto the request; the request's other headers (accept,
69
+ // content-type, ...) still reach the wire, they are simply not part of the signature.
70
+ request.headers = { ...request.headers, ...signed.headers };
64
71
  };
65
72
  }
@@ -1,15 +1,16 @@
1
1
  import { ConnectionOptions } from './connection.js';
2
- import { Readable } from 'stream';
2
+ import { Transaction } from '../process/transaction.js';
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
  */
@@ -18,10 +18,12 @@
18
18
  */
19
19
  import Connection from './connection.js';
20
20
  import { RequestMessage } from "./request-message.js";
21
+ import { Transaction } from '../process/transaction.js';
21
22
  /**
22
23
  * A {@link Client} contains methods to send messages to a Gremlin Server.
23
24
  */
24
25
  export default class Client {
26
+ url;
25
27
  options;
26
28
  _connection;
27
29
  /**
@@ -29,7 +31,12 @@ export default class Client {
29
31
  * @param {String} url The resource uri.
30
32
  * @param {ClientOptions} [options] The connection options.
31
33
  */
34
+ // Tracks open transactions for cascade rollback on close. JS Set iteration
35
+ // is safe during concurrent modification (deleting the current element during
36
+ // for-of is spec-guaranteed to not affect remaining iterations).
37
+ _trackedTransactions = new Set();
32
38
  constructor(url, options = {}) {
39
+ this.url = url;
33
40
  this.options = options;
34
41
  this._connection = new Connection(url, options);
35
42
  }
@@ -48,67 +55,104 @@ export default class Client {
48
55
  return this._connection.isOpen;
49
56
  }
50
57
  /**
51
- * Configuration specific to the current request.
52
- * @typedef {Object} RequestOptions
53
- * @property {any} bindings - The parameter bindings to apply to the script.
54
- * @property {String} language - The language of the script to execute. Defaults to 'gremlin-lang'.
55
- * @property {String} accept - The MIME type expected in the response.
56
- * @property {Boolean} bulkResults - Indicates whether results should be returned in bulk format.
57
- * @property {Object} params - Additional parameters to include with the request.
58
- * @property {Number} batchSize - The size in which the result of a request is to be 'batched' back to the client.
59
- * @property {String} userAgent - The user agent string to send with the request.
60
- * @property {Number} evaluationTimeout - The timeout for the evaluation of the request.
61
- * @property {String} materializeProperties - Indicates whether element properties should be returned or not.
58
+ * Send a request to the Gremlin Server and buffer the entire response.
59
+ * @param {string} message The script to send
60
+ * @param {Object|null} [parameters] The query parameters, if any.
61
+ * @param {RequestOptions} [requestOptions] Configuration specific to the current request.
62
+ * @returns {Promise<ResultSet>}
62
63
  */
64
+ submit(message, parameters, requestOptions) {
65
+ return this._connection.submit(this.#buildRequest(message, parameters, requestOptions));
66
+ }
63
67
  /**
64
- * Send a request to the Gremlin Server.
68
+ * Send a request to the Gremlin Server and stream results incrementally.
69
+ * Returns an AsyncGenerator that yields individual result items as they are
70
+ * deserialized from the response. For bulked responses, yields Traverser objects.
65
71
  * @param {string} message The script to send
66
- * @param {Object|null} [bindings] The script bindings, if any.
72
+ * @param {Object|null} [parameters] The query parameters, if any.
67
73
  * @param {RequestOptions} [requestOptions] Configuration specific to the current request.
68
- * @returns {Promise}
69
- */ //TODO:: tighten return type to Promise<ResultSet>
70
- submit(message, bindings, requestOptions) {
74
+ * @returns {AsyncGenerator<any>}
75
+ */
76
+ async *stream(message, parameters, requestOptions) {
77
+ return yield* this._connection.stream(this.#buildRequest(message, parameters, requestOptions));
78
+ }
79
+ #buildRequest(message, parameters, requestOptions) {
71
80
  const requestBuilder = RequestMessage.build(message)
72
81
  .addG(this.options.traversalSource || 'g');
73
82
  if (requestOptions?.language) {
74
83
  requestBuilder.addLanguage(requestOptions.language);
75
84
  }
76
- if (requestOptions?.bindings) {
77
- requestBuilder.addBindings(requestOptions.bindings);
85
+ if (requestOptions?.parameters) {
86
+ if (typeof requestOptions.parameters === 'string') {
87
+ requestBuilder.addParametersString(requestOptions.parameters);
88
+ }
89
+ else {
90
+ requestBuilder.addParameters(requestOptions.parameters);
91
+ }
78
92
  }
79
- if (bindings) {
80
- requestBuilder.addBindings(bindings);
93
+ if (parameters) {
94
+ if (typeof parameters === 'string') {
95
+ requestBuilder.addParametersString(parameters);
96
+ }
97
+ else {
98
+ requestBuilder.addParameters(parameters);
99
+ }
81
100
  }
82
101
  if (requestOptions?.materializeProperties) {
83
102
  requestBuilder.addMaterializeProperties(requestOptions.materializeProperties);
84
103
  }
85
- if (requestOptions?.evaluationTimeout) {
86
- requestBuilder.addTimeoutMillis(requestOptions.evaluationTimeout);
104
+ if (requestOptions?.timeoutMillis) {
105
+ requestBuilder.addTimeoutMillis(requestOptions.timeoutMillis);
87
106
  }
88
- if (requestOptions?.bulkResults) {
107
+ // Per-request value wins (including an explicit `false`); otherwise apply the
108
+ // connection-level default only when it is true.
109
+ if (requestOptions?.bulkResults !== undefined) {
89
110
  requestBuilder.addBulkResults(requestOptions.bulkResults);
90
111
  }
91
- return this._connection.submit(requestBuilder.create());
92
- }
93
- /**
94
- * Send a request to the Gremlin Server and receive a stream for the results.
95
- * @param {string} message The script to send
96
- * @param {Object} [bindings] The script bindings, if any.
97
- * @param {RequestOptions} [requestOptions] Configuration specific to the current request.
98
- * @returns {ReadableStream}
99
- */
100
- //TODO:: Update stream() to mirror submit()
101
- stream(message, bindings, requestOptions) {
102
- throw new Error("Stream not yet implemented");
112
+ else if (this._connection.bulkResults) {
113
+ requestBuilder.addBulkResults(true);
114
+ }
115
+ // Fill the per-request batchSize from the connection-level default when unset.
116
+ const batchSize = requestOptions?.batchSize ?? this._connection.batchSize;
117
+ if (batchSize !== undefined) {
118
+ requestBuilder.addBatchSize(batchSize);
119
+ }
120
+ if (requestOptions?.transactionId) {
121
+ requestBuilder.addField('transactionId', requestOptions.transactionId);
122
+ }
123
+ return requestBuilder.create();
103
124
  }
104
125
  /**
105
126
  * Closes the underlying connection
106
- * send session close request before connection close if session mode
107
127
  * @returns {Promise}
108
128
  */
109
- close() {
129
+ async close() {
130
+ // Best-effort rollback of any open transactions before closing connections
131
+ for (const tx of this._trackedTransactions) {
132
+ try {
133
+ await tx.close();
134
+ }
135
+ catch { }
136
+ }
137
+ this._trackedTransactions.clear();
110
138
  return this._connection.close();
111
139
  }
140
+ trackTransaction(tx) {
141
+ this._trackedTransactions.add(tx);
142
+ }
143
+ untrackTransaction(tx) {
144
+ this._trackedTransactions.delete(tx);
145
+ }
146
+ /**
147
+ * Creates a new Transaction for executing operations within an explicit transaction.
148
+ * Transactions are short-lived and single-use. After commit or rollback,
149
+ * create a new Transaction for the next unit of work.
150
+ * The traversal source (g alias) is inherited from this Client.
151
+ * @returns {Transaction}
152
+ */
153
+ transact() {
154
+ return new Transaction(this);
155
+ }
112
156
  /**
113
157
  * Adds an event listener to the connection
114
158
  * @param {String} event The event name that you want to listen to.
@@ -118,7 +162,7 @@ export default class Client {
118
162
  this._connection.on(event, handler);
119
163
  }
120
164
  /**
121
- * Removes a previowsly added event listener to the connection
165
+ * Removes a previously added event listener to the connection
122
166
  * @param {String} event The event name that you want to listen to.
123
167
  * @param {Function} handler The event handler to be removed.
124
168
  */
@@ -1,32 +1,48 @@
1
- /**
2
- * @author Jorge Bay Gondra
3
- */
4
- import { Buffer } from 'buffer';
5
1
  import { EventEmitter } from 'eventemitter3';
6
- import type { Agent } from 'node:http';
7
2
  import ResultSet from './result-set.js';
8
3
  import { RequestMessage } from "./request-message.js";
9
- import { Readable } from "stream";
10
- export type HttpRequest = {
11
- url: string;
12
- method: string;
13
- headers: Record<string, string>;
14
- body: any;
15
- };
16
- export type RequestInterceptor = (request: HttpRequest) => HttpRequest | Promise<HttpRequest>;
4
+ import { RequestInterceptor } from './http-request.js';
5
+ import { Logger } from './logger.js';
6
+ /**
7
+ * Selects the content encoding requested from, and decoded for, the server. `'deflate'` (the
8
+ * default) sends an `Accept-Encoding: deflate` header and decodes deflate responses; `'none'`
9
+ * turns compression off.
10
+ */
11
+ export type Compression = 'none' | 'deflate';
17
12
  export type ConnectionOptions = {
18
- ca?: string[];
19
- cert?: string | string[] | Buffer;
20
- pfx?: string | Buffer;
21
- reader?: any;
22
- rejectUnauthorized?: boolean;
13
+ preciseNumbers?: boolean;
14
+ pdtRegistry?: any;
15
+ responseSerializer?: any;
23
16
  traversalSource?: string;
24
- writer?: any | null;
25
- headers?: Record<string, string | string[]>;
26
17
  enableUserAgentOnConnect?: boolean;
27
- agent?: Agent;
18
+ /** Maximum number of concurrent connections per origin. Defaults to 128. */
19
+ maxConnections?: number;
20
+ /** Read timeout in ms, applied to the default dispatcher. Maps to undici `headersTimeout` (wait for first response byte) and `bodyTimeout` (idle between body chunks). */
21
+ readTimeoutMillis?: number;
22
+ /** Maximum size of the response headers in bytes, applied to the default dispatcher. */
23
+ maxResponseHeaderBytes?: number;
24
+ /**
25
+ * Idle time in milliseconds before TCP keep-alive probes begin on a connection. Defaults to
26
+ * 30000 (30s) when unset. Set to `0` to disable keep-alive entirely.
27
+ */
28
+ keepAliveTimeMillis?: number;
29
+ /** HTTP proxy URI. When set, requests are routed through an undici `ProxyAgent`. */
30
+ proxy?: string;
31
+ /** Response compression codec. Defaults to `'deflate'` (on). */
32
+ compression?: Compression;
33
+ /** Connection-level default that fills a request's `batchSize` when it is left unset. Defaults to 64. */
34
+ batchSize?: number;
35
+ /** Connection-level default for `bulkResults`, applied to every request unless overridden per-request. Defaults to `false`. */
36
+ bulkResults?: boolean;
37
+ /** An optional logger (a logger object or a callback). Logging is disabled when unset. */
38
+ logger?: Logger;
28
39
  interceptors?: RequestInterceptor | RequestInterceptor[];
40
+ /** An optional auth interceptor. As a convenience, this is always appended to the end of the
41
+ * interceptor list so it runs last, after any user interceptors have modified the request. */
42
+ auth?: RequestInterceptor;
29
43
  };
44
+ /** The default per-request batch size used when neither the request nor the connection sets one. */
45
+ export declare const DEFAULT_BATCH_SIZE = 64;
30
46
  /**
31
47
  * Represents a single connection to a Gremlin Server.
32
48
  */
@@ -34,27 +50,54 @@ export default class Connection extends EventEmitter {
34
50
  #private;
35
51
  readonly url: string;
36
52
  readonly options: ConnectionOptions;
37
- private readonly _reader;
38
- private readonly _writer;
53
+ private readonly _responseSerializer;
39
54
  isOpen: boolean;
40
55
  traversalSource: string;
41
56
  private readonly _enableUserAgentOnConnect;
42
57
  private readonly _interceptors;
58
+ private readonly _dispatcher;
59
+ private readonly _compression;
60
+ private readonly _batchSize;
61
+ private readonly _bulkResults;
62
+ private readonly _log;
43
63
  /**
44
64
  * Creates a new instance of {@link Connection}.
45
65
  * @param {String} url The resource uri.
46
66
  * @param {ConnectionOptions} [options] The connection options.
47
67
  */
48
68
  constructor(url: string, options?: ConnectionOptions);
69
+ /**
70
+ * The connection-level default batch size, used to fill a request's `batchSize` when unset.
71
+ */
72
+ get batchSize(): number;
73
+ /**
74
+ * The connection-level default for `bulkResults`, applied to every request unless overridden
75
+ * per-request. Defaults to `false`.
76
+ */
77
+ get bulkResults(): boolean;
49
78
  /**
50
79
  * Opens the connection, if its not already opened.
51
80
  * @returns {Promise}
52
81
  */
53
82
  open(): Promise<void>;
54
- /** @override */
83
+ /**
84
+ * Send a request and buffer the entire response. Returns a Promise<ResultSet>.
85
+ */
55
86
  submit(request: RequestMessage): Promise<ResultSet>;
56
- /** @override */
57
- stream(request: RequestMessage): Readable;
87
+ /**
88
+ * Send a request and stream the response incrementally.
89
+ * Returns an AsyncGenerator that yields deserialized result items.
90
+ * For bulked responses, yields Traverser objects.
91
+ *
92
+ * In the GraphBinary v4 streaming protocol, the server sends the status after all
93
+ * result data. If the server encounters an error mid-traversal, values yielded before
94
+ * the error are valid partial results. A ResponseError is thrown after the last value
95
+ * has been yielded.
96
+ *
97
+ * @param {RequestMessage} request
98
+ * @returns {AsyncGenerator<any>}
99
+ */
100
+ stream(request: RequestMessage): AsyncGenerator<any>;
58
101
  /**
59
102
  * Closes the Connection.
60
103
  * @return {Promise}