gremlin 3.8.1 → 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 (455) hide show
  1. package/README.md +18 -4
  2. package/build/cjs/driver/auth.cjs +76 -0
  3. package/build/cjs/driver/auth.d.cts +9 -0
  4. package/build/cjs/driver/client.cjs +178 -0
  5. package/build/cjs/driver/client.d.cts +88 -0
  6. package/build/cjs/driver/connection.cjs +363 -0
  7. package/build/cjs/driver/connection.d.cts +106 -0
  8. package/build/cjs/driver/dispatcher.browser.cjs +57 -0
  9. package/build/cjs/driver/dispatcher.browser.d.cts +35 -0
  10. package/build/cjs/driver/dispatcher.cjs +101 -0
  11. package/build/cjs/driver/dispatcher.d.cts +48 -0
  12. package/build/cjs/driver/driver-remote-connection.cjs +153 -0
  13. package/build/cjs/driver/driver-remote-connection.d.cts +39 -0
  14. package/build/cjs/driver/http-request.cjs +64 -0
  15. package/build/cjs/driver/http-request.d.cts +28 -0
  16. package/build/cjs/driver/logger.cjs +45 -0
  17. package/build/cjs/driver/logger.d.cts +29 -0
  18. package/build/cjs/driver/remote-connection.cjs +72 -0
  19. package/build/cjs/driver/remote-connection.d.cts +57 -0
  20. package/build/cjs/driver/request-message.cjs +246 -0
  21. package/build/cjs/driver/request-message.d.cts +79 -0
  22. package/build/cjs/driver/response-error.cjs +45 -0
  23. package/build/cjs/driver/response-error.d.cts +13 -0
  24. package/build/cjs/driver/result-set.cjs +111 -0
  25. package/build/cjs/driver/result-set.d.cts +29 -0
  26. package/build/cjs/index.cjs +146 -0
  27. package/build/cjs/index.d.cts +440 -0
  28. package/build/cjs/language/grammar/GremlinLexer.cjs +1905 -0
  29. package/build/cjs/language/grammar/GremlinLexer.d.cts +349 -0
  30. package/build/cjs/language/grammar/GremlinListener.cjs +4804 -0
  31. package/build/cjs/language/grammar/GremlinListener.d.cts +5239 -0
  32. package/build/cjs/language/grammar/GremlinParser.cjs +38146 -0
  33. package/build/cjs/language/grammar/GremlinParser.d.cts +6260 -0
  34. package/build/cjs/language/index.cjs +48 -0
  35. package/build/cjs/language/index.d.cts +12 -0
  36. package/build/cjs/language/translator/AnonymizedTranslateVisitor.cjs +166 -0
  37. package/build/cjs/language/translator/AnonymizedTranslateVisitor.d.cts +39 -0
  38. package/build/cjs/language/translator/DotNetTranslateVisitor.cjs +935 -0
  39. package/build/cjs/language/translator/DotNetTranslateVisitor.d.cts +166 -0
  40. package/build/cjs/language/translator/GoTranslateVisitor.cjs +421 -0
  41. package/build/cjs/language/translator/GoTranslateVisitor.d.cts +40 -0
  42. package/build/cjs/language/translator/GremlinTranslator.cjs +96 -0
  43. package/build/cjs/language/translator/GremlinTranslator.d.cts +18 -0
  44. package/build/cjs/language/translator/GroovyTranslateVisitor.cjs +310 -0
  45. package/build/cjs/language/translator/GroovyTranslateVisitor.d.cts +37 -0
  46. package/build/cjs/language/translator/JavaTranslateVisitor.cjs +270 -0
  47. package/build/cjs/language/translator/JavaTranslateVisitor.d.cts +26 -0
  48. package/build/cjs/language/translator/JavascriptTranslateVisitor.cjs +231 -0
  49. package/build/cjs/language/translator/JavascriptTranslateVisitor.d.cts +28 -0
  50. package/build/cjs/language/translator/PythonTranslateVisitor.cjs +340 -0
  51. package/build/cjs/language/translator/PythonTranslateVisitor.d.cts +31 -0
  52. package/build/cjs/language/translator/TranslateVisitor.cjs +398 -0
  53. package/build/cjs/language/translator/TranslateVisitor.d.cts +94 -0
  54. package/build/cjs/language/translator/Translation.cjs +47 -0
  55. package/build/cjs/language/translator/Translation.d.cts +13 -0
  56. package/build/cjs/language/translator/Translator.cjs +46 -0
  57. package/build/cjs/language/translator/Translator.d.cts +24 -0
  58. package/build/cjs/language/translator/TranslatorException.cjs +31 -0
  59. package/build/cjs/language/translator/TranslatorException.d.cts +6 -0
  60. package/build/cjs/process/anonymous-traversal.cjs +82 -0
  61. package/build/cjs/process/anonymous-traversal.d.cts +40 -0
  62. package/build/cjs/process/graph-traversal.cjs +1833 -0
  63. package/build/cjs/process/graph-traversal.d.cts +1215 -0
  64. package/build/cjs/process/gremlin-lang.cjs +308 -0
  65. package/build/cjs/process/gremlin-lang.d.cts +20 -0
  66. package/{lib/driver/response-error.js → build/cjs/process/gvalue.cjs} +23 -28
  67. package/build/cjs/process/gvalue.d.cts +7 -0
  68. package/build/cjs/process/transaction.cjs +171 -0
  69. package/build/cjs/process/transaction.d.cts +70 -0
  70. package/build/cjs/process/traversal-strategy.cjs +360 -0
  71. package/build/cjs/process/traversal-strategy.d.cts +211 -0
  72. package/build/cjs/process/traversal.cjs +539 -0
  73. package/build/cjs/process/traversal.d.cts +212 -0
  74. package/build/cjs/structure/PDTRegistry.cjs +116 -0
  75. package/build/cjs/structure/PDTRegistry.d.cts +34 -0
  76. package/build/cjs/structure/graph.cjs +500 -0
  77. package/build/cjs/structure/graph.d.cts +176 -0
  78. package/build/cjs/structure/io/binary/GraphBinary.cjs +177 -0
  79. package/build/cjs/structure/io/binary/GraphBinary.d.cts +105 -0
  80. package/build/cjs/structure/io/binary/internals/AnySerializer.cjs +97 -0
  81. package/build/cjs/structure/io/binary/internals/AnySerializer.d.cts +18 -0
  82. package/build/cjs/structure/io/binary/internals/ArraySerializer.cjs +108 -0
  83. package/build/cjs/structure/io/binary/internals/ArraySerializer.d.cts +22 -0
  84. package/build/cjs/structure/io/binary/internals/BigIntegerSerializer.cjs +116 -0
  85. package/build/cjs/structure/io/binary/internals/BigIntegerSerializer.d.cts +19 -0
  86. package/build/cjs/structure/io/binary/internals/BinarySerializer.cjs +92 -0
  87. package/build/cjs/structure/io/binary/internals/BinarySerializer.d.cts +19 -0
  88. package/build/cjs/structure/io/binary/internals/BooleanSerializer.cjs +79 -0
  89. package/build/cjs/structure/io/binary/internals/BooleanSerializer.d.cts +19 -0
  90. package/build/cjs/structure/io/binary/internals/ByteSerializer.cjs +74 -0
  91. package/build/cjs/structure/io/binary/internals/ByteSerializer.d.cts +18 -0
  92. package/build/cjs/structure/io/binary/internals/CompositePDTSerializer.cjs +81 -0
  93. package/build/cjs/structure/io/binary/internals/CompositePDTSerializer.d.cts +10 -0
  94. package/build/cjs/structure/io/binary/internals/DataType.cjs +63 -0
  95. package/build/cjs/structure/io/binary/internals/DataType.d.cts +35 -0
  96. package/build/cjs/structure/io/binary/internals/DateTimeSerializer.cjs +122 -0
  97. package/build/cjs/structure/io/binary/internals/DateTimeSerializer.d.cts +20 -0
  98. package/build/cjs/structure/io/binary/internals/DoubleSerializer.cjs +77 -0
  99. package/build/cjs/structure/io/binary/internals/DoubleSerializer.d.cts +19 -0
  100. package/build/cjs/structure/io/binary/internals/EdgeSerializer.cjs +146 -0
  101. package/build/cjs/structure/io/binary/internals/EdgeSerializer.d.cts +22 -0
  102. package/build/cjs/structure/io/binary/internals/EnumSerializer.cjs +115 -0
  103. package/build/cjs/structure/io/binary/internals/EnumSerializer.d.cts +39 -0
  104. package/build/cjs/structure/io/binary/internals/FloatSerializer.cjs +77 -0
  105. package/build/cjs/structure/io/binary/internals/FloatSerializer.d.cts +19 -0
  106. package/build/cjs/structure/io/binary/internals/GraphBinaryReader.cjs +171 -0
  107. package/build/cjs/structure/io/binary/internals/GraphBinaryReader.d.cts +43 -0
  108. package/build/cjs/structure/io/binary/internals/GraphBinaryWriter.cjs +85 -0
  109. package/build/cjs/structure/io/binary/internals/GraphBinaryWriter.d.cts +9 -0
  110. package/build/cjs/structure/io/binary/internals/GraphSerializer.cjs +184 -0
  111. package/build/cjs/structure/io/binary/internals/GraphSerializer.d.cts +22 -0
  112. package/build/cjs/structure/io/binary/internals/IntSerializer.cjs +98 -0
  113. package/build/cjs/structure/io/binary/internals/IntSerializer.d.cts +28 -0
  114. package/build/cjs/structure/io/binary/internals/LongSerializer.cjs +82 -0
  115. package/build/cjs/structure/io/binary/internals/LongSerializer.d.cts +20 -0
  116. package/build/cjs/structure/io/binary/internals/MapSerializer.cjs +110 -0
  117. package/build/cjs/structure/io/binary/internals/MapSerializer.d.cts +20 -0
  118. package/build/cjs/structure/io/binary/internals/MarkerSerializer.cjs +60 -0
  119. package/build/cjs/structure/io/binary/internals/MarkerSerializer.d.cts +17 -0
  120. package/build/cjs/structure/io/binary/internals/NumberSerializationStrategy.cjs +92 -0
  121. package/build/cjs/structure/io/binary/internals/NumberSerializationStrategy.d.cts +6 -0
  122. package/build/cjs/structure/io/binary/internals/PathSerializer.cjs +88 -0
  123. package/build/cjs/structure/io/binary/internals/PathSerializer.d.cts +22 -0
  124. package/build/cjs/structure/io/binary/internals/PrimitivePDTSerializer.cjs +80 -0
  125. package/build/cjs/structure/io/binary/internals/PrimitivePDTSerializer.d.cts +10 -0
  126. package/build/cjs/structure/io/binary/internals/PropertySerializer.cjs +93 -0
  127. package/build/cjs/structure/io/binary/internals/PropertySerializer.d.cts +22 -0
  128. package/build/cjs/structure/io/binary/internals/SetSerializer.cjs +104 -0
  129. package/build/cjs/structure/io/binary/internals/SetSerializer.d.cts +22 -0
  130. package/build/cjs/structure/io/binary/internals/ShortSerializer.cjs +77 -0
  131. package/build/cjs/structure/io/binary/internals/ShortSerializer.d.cts +19 -0
  132. package/build/cjs/structure/io/binary/internals/StreamReader.cjs +184 -0
  133. package/build/cjs/structure/io/binary/internals/StreamReader.d.cts +69 -0
  134. package/build/cjs/structure/io/binary/internals/StringSerializer.cjs +88 -0
  135. package/build/cjs/structure/io/binary/internals/StringSerializer.d.cts +21 -0
  136. package/build/cjs/structure/io/binary/internals/StubSerializer.cjs +33 -0
  137. package/build/cjs/structure/io/binary/internals/StubSerializer.d.cts +7 -0
  138. package/build/cjs/structure/io/binary/internals/TreeSerializer.cjs +139 -0
  139. package/build/cjs/structure/io/binary/internals/TreeSerializer.d.cts +54 -0
  140. package/build/cjs/structure/io/binary/internals/UnspecifiedNullSerializer.cjs +47 -0
  141. package/build/cjs/structure/io/binary/internals/UnspecifiedNullSerializer.d.cts +13 -0
  142. package/build/cjs/structure/io/binary/internals/UuidSerializer.cjs +93 -0
  143. package/build/cjs/structure/io/binary/internals/UuidSerializer.d.cts +19 -0
  144. package/build/cjs/structure/io/binary/internals/VertexPropertySerializer.cjs +105 -0
  145. package/build/cjs/structure/io/binary/internals/VertexPropertySerializer.d.cts +22 -0
  146. package/build/cjs/structure/io/binary/internals/VertexSerializer.cjs +101 -0
  147. package/build/cjs/structure/io/binary/internals/VertexSerializer.d.cts +22 -0
  148. package/build/cjs/structure/io/binary/internals/utils.cjs +53 -0
  149. package/build/cjs/structure/io/binary/internals/utils.d.cts +6 -0
  150. package/build/cjs/utils.cjs +259 -0
  151. package/build/cjs/utils.d.cts +78 -0
  152. package/build/esm/driver/auth.d.ts +9 -0
  153. package/build/esm/driver/auth.js +72 -0
  154. package/build/esm/driver/client.d.ts +88 -0
  155. package/build/esm/driver/client.js +172 -0
  156. package/build/esm/driver/connection.d.ts +106 -0
  157. package/build/esm/driver/connection.js +323 -0
  158. package/build/esm/driver/dispatcher.browser.d.ts +35 -0
  159. package/build/esm/driver/dispatcher.browser.js +53 -0
  160. package/build/esm/driver/dispatcher.d.ts +48 -0
  161. package/build/esm/driver/dispatcher.js +94 -0
  162. package/build/esm/driver/driver-remote-connection.d.ts +39 -0
  163. package/build/esm/driver/driver-remote-connection.js +114 -0
  164. package/build/esm/driver/http-request.d.ts +28 -0
  165. package/build/esm/driver/http-request.js +60 -0
  166. package/build/esm/driver/logger.d.ts +29 -0
  167. package/build/esm/driver/logger.js +42 -0
  168. package/build/esm/driver/remote-connection.d.ts +57 -0
  169. package/build/esm/driver/remote-connection.js +66 -0
  170. package/build/esm/driver/request-message.d.ts +79 -0
  171. package/build/esm/driver/request-message.js +238 -0
  172. package/build/esm/driver/response-error.d.ts +13 -0
  173. package/{lib/driver/auth/mechanisms/sasl-mechanism-base.js → build/esm/driver/response-error.js} +24 -34
  174. package/build/esm/driver/result-set.d.ts +29 -0
  175. package/build/esm/driver/result-set.js +75 -0
  176. package/build/esm/index.d.ts +440 -0
  177. package/{index.js → build/esm/index.js} +44 -33
  178. package/build/esm/language/grammar/GremlinLexer.d.ts +349 -0
  179. package/build/esm/language/grammar/GremlinLexer.js +1868 -0
  180. package/build/esm/language/grammar/GremlinListener.d.ts +5239 -0
  181. package/build/esm/language/grammar/GremlinListener.js +4800 -0
  182. package/build/esm/language/grammar/GremlinParser.d.ts +6260 -0
  183. package/build/esm/language/grammar/GremlinParser.js +37579 -0
  184. package/build/esm/language/index.d.ts +12 -0
  185. package/build/esm/language/index.js +30 -0
  186. package/build/esm/language/translator/AnonymizedTranslateVisitor.d.ts +39 -0
  187. package/build/esm/language/translator/AnonymizedTranslateVisitor.js +160 -0
  188. package/build/esm/language/translator/DotNetTranslateVisitor.d.ts +166 -0
  189. package/build/esm/language/translator/DotNetTranslateVisitor.js +929 -0
  190. package/build/esm/language/translator/GoTranslateVisitor.d.ts +40 -0
  191. package/build/esm/language/translator/GoTranslateVisitor.js +415 -0
  192. package/build/esm/language/translator/GremlinTranslator.d.ts +18 -0
  193. package/build/esm/language/translator/GremlinTranslator.js +89 -0
  194. package/build/esm/language/translator/GroovyTranslateVisitor.d.ts +37 -0
  195. package/build/esm/language/translator/GroovyTranslateVisitor.js +304 -0
  196. package/build/esm/language/translator/JavaTranslateVisitor.d.ts +26 -0
  197. package/build/esm/language/translator/JavaTranslateVisitor.js +264 -0
  198. package/build/esm/language/translator/JavascriptTranslateVisitor.d.ts +28 -0
  199. package/build/esm/language/translator/JavascriptTranslateVisitor.js +225 -0
  200. package/build/esm/language/translator/PythonTranslateVisitor.d.ts +31 -0
  201. package/build/esm/language/translator/PythonTranslateVisitor.js +334 -0
  202. package/build/esm/language/translator/TranslateVisitor.d.ts +94 -0
  203. package/build/esm/language/translator/TranslateVisitor.js +395 -0
  204. package/build/esm/language/translator/Translation.d.ts +13 -0
  205. package/build/esm/language/translator/Translation.js +43 -0
  206. package/build/esm/language/translator/Translator.d.ts +24 -0
  207. package/build/esm/language/translator/Translator.js +40 -0
  208. package/build/esm/language/translator/TranslatorException.d.ts +6 -0
  209. package/build/esm/language/translator/TranslatorException.js +27 -0
  210. package/build/esm/process/anonymous-traversal.d.ts +40 -0
  211. package/build/esm/process/anonymous-traversal.js +76 -0
  212. package/build/esm/process/graph-traversal.d.ts +1215 -0
  213. package/build/esm/process/graph-traversal.js +1824 -0
  214. package/build/esm/process/gremlin-lang.d.ts +20 -0
  215. package/build/esm/process/gremlin-lang.js +305 -0
  216. package/build/esm/process/gvalue.d.ts +7 -0
  217. package/{lib/driver/auth/authenticator.js → build/esm/process/gvalue.js} +19 -19
  218. package/build/esm/process/transaction.d.ts +70 -0
  219. package/build/esm/process/transaction.js +164 -0
  220. package/build/esm/process/traversal-strategy.d.ts +211 -0
  221. package/build/esm/process/traversal-strategy.js +319 -0
  222. package/build/esm/process/traversal.d.ts +212 -0
  223. package/build/esm/process/traversal.js +526 -0
  224. package/build/esm/structure/PDTRegistry.d.ts +34 -0
  225. package/build/esm/structure/PDTRegistry.js +112 -0
  226. package/build/esm/structure/graph.d.ts +176 -0
  227. package/build/esm/structure/graph.js +488 -0
  228. package/build/esm/structure/io/binary/GraphBinary.d.ts +105 -0
  229. package/build/esm/structure/io/binary/GraphBinary.js +136 -0
  230. package/build/esm/structure/io/binary/internals/AnySerializer.d.ts +18 -0
  231. package/build/esm/structure/io/binary/internals/AnySerializer.js +94 -0
  232. package/build/esm/structure/io/binary/internals/ArraySerializer.d.ts +22 -0
  233. package/build/esm/structure/io/binary/internals/ArraySerializer.js +105 -0
  234. package/build/esm/structure/io/binary/internals/BigIntegerSerializer.d.ts +19 -0
  235. package/build/esm/structure/io/binary/internals/BigIntegerSerializer.js +113 -0
  236. package/build/esm/structure/io/binary/internals/BinarySerializer.d.ts +19 -0
  237. package/build/esm/structure/io/binary/internals/BinarySerializer.js +89 -0
  238. package/build/esm/structure/io/binary/internals/BooleanSerializer.d.ts +19 -0
  239. package/build/esm/structure/io/binary/internals/BooleanSerializer.js +76 -0
  240. package/build/esm/structure/io/binary/internals/ByteSerializer.d.ts +18 -0
  241. package/build/esm/structure/io/binary/internals/ByteSerializer.js +71 -0
  242. package/build/esm/structure/io/binary/internals/CompositePDTSerializer.d.ts +10 -0
  243. package/build/esm/structure/io/binary/internals/CompositePDTSerializer.js +78 -0
  244. package/build/esm/structure/io/binary/internals/DataType.d.ts +35 -0
  245. package/build/esm/structure/io/binary/internals/DataType.js +61 -0
  246. package/build/esm/structure/io/binary/internals/DateTimeSerializer.d.ts +20 -0
  247. package/build/esm/structure/io/binary/internals/DateTimeSerializer.js +119 -0
  248. package/build/esm/structure/io/binary/internals/DoubleSerializer.d.ts +19 -0
  249. package/build/esm/structure/io/binary/internals/DoubleSerializer.js +74 -0
  250. package/build/esm/structure/io/binary/internals/EdgeSerializer.d.ts +22 -0
  251. package/build/esm/structure/io/binary/internals/EdgeSerializer.js +143 -0
  252. package/build/esm/structure/io/binary/internals/EnumSerializer.d.ts +39 -0
  253. package/build/esm/structure/io/binary/internals/EnumSerializer.js +112 -0
  254. package/build/esm/structure/io/binary/internals/FloatSerializer.d.ts +19 -0
  255. package/build/esm/structure/io/binary/internals/FloatSerializer.js +74 -0
  256. package/build/esm/structure/io/binary/internals/GraphBinaryReader.d.ts +43 -0
  257. package/build/esm/structure/io/binary/internals/GraphBinaryReader.js +165 -0
  258. package/build/esm/structure/io/binary/internals/GraphBinaryWriter.d.ts +9 -0
  259. package/build/esm/structure/io/binary/internals/GraphBinaryWriter.js +82 -0
  260. package/build/esm/structure/io/binary/internals/GraphSerializer.d.ts +22 -0
  261. package/build/esm/structure/io/binary/internals/GraphSerializer.js +181 -0
  262. package/build/esm/structure/io/binary/internals/IntSerializer.d.ts +28 -0
  263. package/build/esm/structure/io/binary/internals/IntSerializer.js +95 -0
  264. package/build/esm/structure/io/binary/internals/LongSerializer.d.ts +20 -0
  265. package/build/esm/structure/io/binary/internals/LongSerializer.js +79 -0
  266. package/build/esm/structure/io/binary/internals/MapSerializer.d.ts +20 -0
  267. package/build/esm/structure/io/binary/internals/MapSerializer.js +107 -0
  268. package/build/esm/structure/io/binary/internals/MarkerSerializer.d.ts +17 -0
  269. package/build/esm/structure/io/binary/internals/MarkerSerializer.js +56 -0
  270. package/build/esm/structure/io/binary/internals/NumberSerializationStrategy.d.ts +6 -0
  271. package/build/esm/structure/io/binary/internals/NumberSerializationStrategy.js +89 -0
  272. package/build/esm/structure/io/binary/internals/PathSerializer.d.ts +22 -0
  273. package/build/esm/structure/io/binary/internals/PathSerializer.js +85 -0
  274. package/build/esm/structure/io/binary/internals/PrimitivePDTSerializer.d.ts +10 -0
  275. package/build/esm/structure/io/binary/internals/PrimitivePDTSerializer.js +77 -0
  276. package/build/esm/structure/io/binary/internals/PropertySerializer.d.ts +22 -0
  277. package/build/esm/structure/io/binary/internals/PropertySerializer.js +90 -0
  278. package/build/esm/structure/io/binary/internals/SetSerializer.d.ts +22 -0
  279. package/build/esm/structure/io/binary/internals/SetSerializer.js +101 -0
  280. package/build/esm/structure/io/binary/internals/ShortSerializer.d.ts +19 -0
  281. package/build/esm/structure/io/binary/internals/ShortSerializer.js +74 -0
  282. package/build/esm/structure/io/binary/internals/StreamReader.d.ts +69 -0
  283. package/build/esm/structure/io/binary/internals/StreamReader.js +181 -0
  284. package/build/esm/structure/io/binary/internals/StringSerializer.d.ts +21 -0
  285. package/build/esm/structure/io/binary/internals/StringSerializer.js +85 -0
  286. package/build/esm/structure/io/binary/internals/StubSerializer.d.ts +7 -0
  287. package/{.prettierrc.js → build/esm/structure/io/binary/internals/StubSerializer.js} +12 -11
  288. package/build/esm/structure/io/binary/internals/TreeSerializer.d.ts +54 -0
  289. package/build/esm/structure/io/binary/internals/TreeSerializer.js +136 -0
  290. package/build/esm/structure/io/binary/internals/UnspecifiedNullSerializer.d.ts +13 -0
  291. package/build/esm/structure/io/binary/internals/UnspecifiedNullSerializer.js +44 -0
  292. package/build/esm/structure/io/binary/internals/UuidSerializer.d.ts +19 -0
  293. package/build/esm/structure/io/binary/internals/UuidSerializer.js +90 -0
  294. package/build/esm/structure/io/binary/internals/VertexPropertySerializer.d.ts +22 -0
  295. package/build/esm/structure/io/binary/internals/VertexPropertySerializer.js +102 -0
  296. package/build/esm/structure/io/binary/internals/VertexSerializer.d.ts +22 -0
  297. package/build/esm/structure/io/binary/internals/VertexSerializer.js +98 -0
  298. package/build/esm/structure/io/binary/internals/utils.d.ts +6 -0
  299. package/{lib → build/esm}/structure/io/binary/internals/utils.js +23 -35
  300. package/build/esm/utils.d.ts +78 -0
  301. package/build/esm/utils.js +237 -0
  302. package/package.json +71 -26
  303. package/.nvmrc +0 -1
  304. package/NOTICE +0 -5
  305. package/doc/AnonymousTraversalSource.html +0 -793
  306. package/doc/Authenticator.html +0 -303
  307. package/doc/Bytecode.html +0 -941
  308. package/doc/CardinalityValue.html +0 -711
  309. package/doc/Client.html +0 -1869
  310. package/doc/Connection.html +0 -1192
  311. package/doc/DriverRemoteConnection.html +0 -1528
  312. package/doc/EdgeLabelVerificationStrategy.html +0 -238
  313. package/doc/Graph.html +0 -343
  314. package/doc/GraphSON2Reader.html +0 -407
  315. package/doc/GraphSON2Writer.html +0 -558
  316. package/doc/GraphSON3Reader.html +0 -170
  317. package/doc/GraphSON3Writer.html +0 -170
  318. package/doc/GraphTraversal.html +0 -22974
  319. package/doc/GraphTraversalSource.html +0 -3683
  320. package/doc/HaltedTraverserStrategy.html +0 -215
  321. package/doc/MatchAlgorithmStrategy.html +0 -210
  322. package/doc/P.html +0 -2020
  323. package/doc/PartitionStrategy.html +0 -387
  324. package/doc/Path.html +0 -242
  325. package/doc/PlainTextSaslAuthenticator.html +0 -456
  326. package/doc/ProductiveByStrategy.html +0 -258
  327. package/doc/RemoteConnection.html +0 -1086
  328. package/doc/RemoteStrategy.html +0 -307
  329. package/doc/RemoteTraversal.html +0 -170
  330. package/doc/ReservedKeysVerificationStrategy.html +0 -261
  331. package/doc/ResponseError.html +0 -360
  332. package/doc/ResultSet.html +0 -633
  333. package/doc/SaslAuthenticator.html +0 -455
  334. package/doc/SaslMechanismBase.html +0 -506
  335. package/doc/SaslMechanismPlain.html +0 -925
  336. package/doc/SeedStrategy.html +0 -288
  337. package/doc/SubgraphStrategy.html +0 -387
  338. package/doc/TextP.html +0 -1440
  339. package/doc/Transaction.html +0 -655
  340. package/doc/Translator.html +0 -527
  341. package/doc/TraversalStrategies.html +0 -652
  342. package/doc/TraversalStrategy.html +0 -393
  343. package/doc/TypeSerializer.html +0 -166
  344. package/doc/driver_auth_authenticator.js.html +0 -89
  345. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +0 -103
  346. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +0 -157
  347. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +0 -106
  348. package/doc/driver_auth_sasl-authenticator.js.html +0 -100
  349. package/doc/driver_client.js.html +0 -250
  350. package/doc/driver_connection.js.html +0 -518
  351. package/doc/driver_driver-remote-connection.js.html +0 -193
  352. package/doc/driver_remote-connection.js.html +0 -198
  353. package/doc/driver_response-error.js.html +0 -98
  354. package/doc/driver_result-set.js.html +0 -134
  355. package/doc/fonts/OpenSans-Bold-webfont.eot +0 -0
  356. package/doc/fonts/OpenSans-Bold-webfont.svg +0 -1830
  357. package/doc/fonts/OpenSans-Bold-webfont.woff +0 -0
  358. package/doc/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  359. package/doc/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  360. package/doc/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  361. package/doc/fonts/OpenSans-Italic-webfont.eot +0 -0
  362. package/doc/fonts/OpenSans-Italic-webfont.svg +0 -1830
  363. package/doc/fonts/OpenSans-Italic-webfont.woff +0 -0
  364. package/doc/fonts/OpenSans-Light-webfont.eot +0 -0
  365. package/doc/fonts/OpenSans-Light-webfont.svg +0 -1831
  366. package/doc/fonts/OpenSans-Light-webfont.woff +0 -0
  367. package/doc/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  368. package/doc/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  369. package/doc/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  370. package/doc/fonts/OpenSans-Regular-webfont.eot +0 -0
  371. package/doc/fonts/OpenSans-Regular-webfont.svg +0 -1831
  372. package/doc/fonts/OpenSans-Regular-webfont.woff +0 -0
  373. package/doc/global.html +0 -728
  374. package/doc/index.html +0 -185
  375. package/doc/module.exports.html +0 -301
  376. package/doc/process_anonymous-traversal.js.html +0 -138
  377. package/doc/process_bytecode.js.html +0 -175
  378. package/doc/process_graph-traversal.js.html +0 -1936
  379. package/doc/process_transaction.js.html +0 -151
  380. package/doc/process_translator.js.html +0 -172
  381. package/doc/process_traversal-strategy.js.html +0 -466
  382. package/doc/process_traversal.js.html +0 -592
  383. package/doc/scripts/linenumber.js +0 -25
  384. package/doc/scripts/prettify/Apache-License-2.0.txt +0 -202
  385. package/doc/scripts/prettify/lang-css.js +0 -2
  386. package/doc/scripts/prettify/prettify.js +0 -28
  387. package/doc/structure_graph.js.html +0 -233
  388. package/doc/structure_io_binary_internals_DataType.js.html +0 -151
  389. package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +0 -133
  390. package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +0 -136
  391. package/doc/structure_io_graph-serializer.js.html +0 -354
  392. package/doc/structure_io_type-serializers.js.html +0 -617
  393. package/doc/styles/jsdoc-default.css +0 -358
  394. package/doc/styles/prettify-jsdoc.css +0 -111
  395. package/doc/styles/prettify-tomorrow.css +0 -132
  396. package/doc/utils.js.html +0 -181
  397. package/docker-compose.yml +0 -76
  398. package/eslint.config.mjs +0 -143
  399. package/lib/driver/auth/mechanisms/sasl-mechanism-plain.js +0 -106
  400. package/lib/driver/auth/plain-text-sasl-authenticator.js +0 -55
  401. package/lib/driver/auth/sasl-authenticator.js +0 -49
  402. package/lib/driver/client.js +0 -199
  403. package/lib/driver/connection.js +0 -467
  404. package/lib/driver/driver-remote-connection.js +0 -142
  405. package/lib/driver/remote-connection.js +0 -147
  406. package/lib/driver/result-set.js +0 -83
  407. package/lib/process/anonymous-traversal.js +0 -87
  408. package/lib/process/bytecode.js +0 -124
  409. package/lib/process/graph-traversal.js +0 -1885
  410. package/lib/process/transaction.js +0 -100
  411. package/lib/process/translator.js +0 -121
  412. package/lib/process/traversal-strategy.js +0 -415
  413. package/lib/process/traversal.js +0 -541
  414. package/lib/structure/graph.js +0 -182
  415. package/lib/structure/io/binary/GraphBinary.js +0 -110
  416. package/lib/structure/io/binary/internals/AnySerializer.js +0 -100
  417. package/lib/structure/io/binary/internals/ArraySerializer.js +0 -137
  418. package/lib/structure/io/binary/internals/BigIntegerSerializer.js +0 -153
  419. package/lib/structure/io/binary/internals/BooleanSerializer.js +0 -105
  420. package/lib/structure/io/binary/internals/BulkSetSerializer.js +0 -126
  421. package/lib/structure/io/binary/internals/ByteBufferSerializer.js +0 -126
  422. package/lib/structure/io/binary/internals/ByteSerializer.js +0 -97
  423. package/lib/structure/io/binary/internals/BytecodeSerializer.js +0 -250
  424. package/lib/structure/io/binary/internals/ClassSerializer.js +0 -60
  425. package/lib/structure/io/binary/internals/DataType.js +0 -100
  426. package/lib/structure/io/binary/internals/DateSerializer.js +0 -105
  427. package/lib/structure/io/binary/internals/DoubleSerializer.js +0 -101
  428. package/lib/structure/io/binary/internals/EdgeSerializer.js +0 -216
  429. package/lib/structure/io/binary/internals/EnumSerializer.js +0 -152
  430. package/lib/structure/io/binary/internals/FloatSerializer.js +0 -101
  431. package/lib/structure/io/binary/internals/GraphBinaryReader.js +0 -82
  432. package/lib/structure/io/binary/internals/GraphBinaryWriter.js +0 -85
  433. package/lib/structure/io/binary/internals/IntSerializer.js +0 -114
  434. package/lib/structure/io/binary/internals/LambdaSerializer.js +0 -71
  435. package/lib/structure/io/binary/internals/LongSerializer.js +0 -109
  436. package/lib/structure/io/binary/internals/LongSerializerNg.js +0 -104
  437. package/lib/structure/io/binary/internals/MapSerializer.js +0 -155
  438. package/lib/structure/io/binary/internals/NumberSerializationStrategy.js +0 -73
  439. package/lib/structure/io/binary/internals/OffsetDateTimeSerializer.js +0 -151
  440. package/lib/structure/io/binary/internals/PSerializer.js +0 -152
  441. package/lib/structure/io/binary/internals/PathSerializer.js +0 -124
  442. package/lib/structure/io/binary/internals/PropertySerializer.js +0 -142
  443. package/lib/structure/io/binary/internals/SetSerializer.js +0 -134
  444. package/lib/structure/io/binary/internals/ShortSerializer.js +0 -101
  445. package/lib/structure/io/binary/internals/StringSerializer.js +0 -116
  446. package/lib/structure/io/binary/internals/TextPSerializer.js +0 -146
  447. package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +0 -69
  448. package/lib/structure/io/binary/internals/TraverserSerializer.js +0 -124
  449. package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +0 -77
  450. package/lib/structure/io/binary/internals/UuidSerializer.js +0 -121
  451. package/lib/structure/io/binary/internals/VertexPropertySerializer.js +0 -176
  452. package/lib/structure/io/binary/internals/VertexSerializer.js +0 -139
  453. package/lib/structure/io/graph-serializer.js +0 -303
  454. package/lib/structure/io/type-serializers.js +0 -566
  455. package/lib/utils.js +0 -130
@@ -0,0 +1,172 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * 'License'); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ import Connection from './connection.js';
20
+ import { RequestMessage } from "./request-message.js";
21
+ import { Transaction } from '../process/transaction.js';
22
+ /**
23
+ * A {@link Client} contains methods to send messages to a Gremlin Server.
24
+ */
25
+ export default class Client {
26
+ url;
27
+ options;
28
+ _connection;
29
+ /**
30
+ * Creates a new instance of {@link Client}.
31
+ * @param {String} url The resource uri.
32
+ * @param {ClientOptions} [options] The connection options.
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();
38
+ constructor(url, options = {}) {
39
+ this.url = url;
40
+ this.options = options;
41
+ this._connection = new Connection(url, options);
42
+ }
43
+ /**
44
+ * Opens the underlying connection to the Gremlin Server, if it's not already opened.
45
+ * @returns {Promise}
46
+ */
47
+ open() {
48
+ return this._connection.open();
49
+ }
50
+ /**
51
+ * Returns true if the underlying connection is open
52
+ * @returns {Boolean}
53
+ */
54
+ get isOpen() {
55
+ return this._connection.isOpen;
56
+ }
57
+ /**
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>}
63
+ */
64
+ submit(message, parameters, requestOptions) {
65
+ return this._connection.submit(this.#buildRequest(message, parameters, requestOptions));
66
+ }
67
+ /**
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.
71
+ * @param {string} message The script to send
72
+ * @param {Object|null} [parameters] The query parameters, if any.
73
+ * @param {RequestOptions} [requestOptions] Configuration specific to the current request.
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) {
80
+ const requestBuilder = RequestMessage.build(message)
81
+ .addG(this.options.traversalSource || 'g');
82
+ if (requestOptions?.language) {
83
+ requestBuilder.addLanguage(requestOptions.language);
84
+ }
85
+ if (requestOptions?.parameters) {
86
+ if (typeof requestOptions.parameters === 'string') {
87
+ requestBuilder.addParametersString(requestOptions.parameters);
88
+ }
89
+ else {
90
+ requestBuilder.addParameters(requestOptions.parameters);
91
+ }
92
+ }
93
+ if (parameters) {
94
+ if (typeof parameters === 'string') {
95
+ requestBuilder.addParametersString(parameters);
96
+ }
97
+ else {
98
+ requestBuilder.addParameters(parameters);
99
+ }
100
+ }
101
+ if (requestOptions?.materializeProperties) {
102
+ requestBuilder.addMaterializeProperties(requestOptions.materializeProperties);
103
+ }
104
+ if (requestOptions?.timeoutMillis) {
105
+ requestBuilder.addTimeoutMillis(requestOptions.timeoutMillis);
106
+ }
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) {
110
+ requestBuilder.addBulkResults(requestOptions.bulkResults);
111
+ }
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();
124
+ }
125
+ /**
126
+ * Closes the underlying connection
127
+ * @returns {Promise}
128
+ */
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();
138
+ return this._connection.close();
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
+ }
156
+ /**
157
+ * Adds an event listener to the connection
158
+ * @param {String} event The event name that you want to listen to.
159
+ * @param {Function} handler The callback to be called when the event occurs.
160
+ */
161
+ addListener(event, handler) {
162
+ this._connection.on(event, handler);
163
+ }
164
+ /**
165
+ * Removes a previously added event listener to the connection
166
+ * @param {String} event The event name that you want to listen to.
167
+ * @param {Function} handler The event handler to be removed.
168
+ */
169
+ removeListener(event, handler) {
170
+ this._connection.removeListener(event, handler);
171
+ }
172
+ }
@@ -0,0 +1,106 @@
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import ResultSet from './result-set.js';
3
+ import { RequestMessage } from "./request-message.js";
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';
12
+ export type ConnectionOptions = {
13
+ preciseNumbers?: boolean;
14
+ pdtRegistry?: any;
15
+ responseSerializer?: any;
16
+ traversalSource?: string;
17
+ enableUserAgentOnConnect?: boolean;
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;
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;
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;
46
+ /**
47
+ * Represents a single connection to a Gremlin Server.
48
+ */
49
+ export default class Connection extends EventEmitter {
50
+ #private;
51
+ readonly url: string;
52
+ readonly options: ConnectionOptions;
53
+ private readonly _responseSerializer;
54
+ isOpen: boolean;
55
+ traversalSource: string;
56
+ private readonly _enableUserAgentOnConnect;
57
+ private readonly _interceptors;
58
+ private readonly _dispatcher;
59
+ private readonly _compression;
60
+ private readonly _batchSize;
61
+ private readonly _bulkResults;
62
+ private readonly _log;
63
+ /**
64
+ * Creates a new instance of {@link Connection}.
65
+ * @param {String} url The resource uri.
66
+ * @param {ConnectionOptions} [options] The connection options.
67
+ */
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;
78
+ /**
79
+ * Opens the connection, if its not already opened.
80
+ * @returns {Promise}
81
+ */
82
+ open(): Promise<void>;
83
+ /**
84
+ * Send a request and buffer the entire response. Returns a Promise<ResultSet>.
85
+ */
86
+ submit(request: RequestMessage): Promise<ResultSet>;
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>;
101
+ /**
102
+ * Closes the Connection.
103
+ * @return {Promise}
104
+ */
105
+ close(): Promise<void>;
106
+ }
@@ -0,0 +1,323 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ /**
20
+ * @author Jorge Bay Gondra
21
+ */
22
+ import { Buffer } from 'buffer';
23
+ import { EventEmitter } from 'eventemitter3';
24
+ import ioc, { createPreciseReader } from '../structure/io/binary/GraphBinary.js';
25
+ import GraphBinaryReader from '../structure/io/binary/internals/GraphBinaryReader.js';
26
+ import StreamReader from '../structure/io/binary/internals/StreamReader.js';
27
+ import * as utils from '../utils.js';
28
+ import ResultSet from './result-set.js';
29
+ import { RequestMessage } from "./request-message.js";
30
+ import { HttpRequest } from './http-request.js';
31
+ import ResponseError from './response-error.js';
32
+ import { Traverser } from '../process/traversal.js';
33
+ import { buildDispatcher, httpFetch } from './dispatcher.js';
34
+ import { normalizeLogger } from './logger.js';
35
+ const responseStatusCode = {
36
+ success: 200,
37
+ noContent: 204,
38
+ partialContent: 206,
39
+ };
40
+ /** The default per-request batch size used when neither the request nor the connection sets one. */
41
+ export const DEFAULT_BATCH_SIZE = 64;
42
+ /**
43
+ * Represents a single connection to a Gremlin Server.
44
+ */
45
+ export default class Connection extends EventEmitter {
46
+ url;
47
+ options;
48
+ _responseSerializer;
49
+ isOpen = true;
50
+ traversalSource;
51
+ _enableUserAgentOnConnect;
52
+ _interceptors;
53
+ _dispatcher;
54
+ _compression;
55
+ _batchSize;
56
+ _bulkResults;
57
+ _log;
58
+ /**
59
+ * Creates a new instance of {@link Connection}.
60
+ * @param {String} url The resource uri.
61
+ * @param {ConnectionOptions} [options] The connection options.
62
+ */
63
+ constructor(url, options = {}) {
64
+ super();
65
+ this.url = url;
66
+ this.options = options;
67
+ this._responseSerializer =
68
+ options.responseSerializer || (options.preciseNumbers === true ? createPreciseReader() : new GraphBinaryReader(ioc));
69
+ if (options.pdtRegistry) {
70
+ this._responseSerializer.pdtRegistry = options.pdtRegistry;
71
+ }
72
+ this.traversalSource = options.traversalSource || 'g';
73
+ this._enableUserAgentOnConnect = options.enableUserAgentOnConnect !== false;
74
+ this._log = normalizeLogger(options.logger);
75
+ if (options.compression === undefined) {
76
+ this._compression = 'deflate';
77
+ }
78
+ else if (options.compression === 'none' || options.compression === 'deflate') {
79
+ this._compression = options.compression;
80
+ }
81
+ else {
82
+ throw new TypeError(`compression must be 'none' or 'deflate'`);
83
+ }
84
+ this._batchSize = options.batchSize ?? DEFAULT_BATCH_SIZE;
85
+ this._bulkResults = options.bulkResults ?? false;
86
+ // The driver builds and owns the undici dispatcher from the discrete options.
87
+ // TLS is configured through the Node/undici runtime (e.g. NODE_EXTRA_CA_CERTS),
88
+ // not through a driver option.
89
+ this._dispatcher = buildDispatcher({
90
+ maxConnections: options.maxConnections,
91
+ readTimeoutMillis: options.readTimeoutMillis,
92
+ maxResponseHeaderBytes: options.maxResponseHeaderBytes,
93
+ keepAliveTimeMillis: options.keepAliveTimeMillis,
94
+ proxy: options.proxy,
95
+ });
96
+ const interceptors = options.interceptors;
97
+ if (typeof interceptors === 'function') {
98
+ this._interceptors = [interceptors];
99
+ }
100
+ else if (Array.isArray(interceptors)) {
101
+ this._interceptors = [...interceptors];
102
+ }
103
+ else if (interceptors === undefined || interceptors === null) {
104
+ this._interceptors = [];
105
+ }
106
+ else {
107
+ throw new TypeError('interceptors must be a function, array, or undefined');
108
+ }
109
+ // Auth interceptor is always last so it runs after user interceptors
110
+ if (options.auth) {
111
+ this._interceptors.push(options.auth);
112
+ }
113
+ this._log('debug', `Connection created for ${this.url}`);
114
+ }
115
+ /**
116
+ * The connection-level default batch size, used to fill a request's `batchSize` when unset.
117
+ */
118
+ get batchSize() {
119
+ return this._batchSize;
120
+ }
121
+ /**
122
+ * The connection-level default for `bulkResults`, applied to every request unless overridden
123
+ * per-request. Defaults to `false`.
124
+ */
125
+ get bulkResults() {
126
+ return this._bulkResults;
127
+ }
128
+ /**
129
+ * Opens the connection, if its not already opened.
130
+ * @returns {Promise}
131
+ */
132
+ async open() {
133
+ // No-op for HTTP connections
134
+ return Promise.resolve();
135
+ }
136
+ /**
137
+ * Send a request and buffer the entire response. Returns a Promise<ResultSet>.
138
+ */
139
+ async submit(request) {
140
+ const response = await this.#makeHttpRequest(request);
141
+ return this.#handleResponse(response);
142
+ }
143
+ /**
144
+ * Send a request and stream the response incrementally.
145
+ * Returns an AsyncGenerator that yields deserialized result items.
146
+ * For bulked responses, yields Traverser objects.
147
+ *
148
+ * In the GraphBinary v4 streaming protocol, the server sends the status after all
149
+ * result data. If the server encounters an error mid-traversal, values yielded before
150
+ * the error are valid partial results. A ResponseError is thrown after the last value
151
+ * has been yielded.
152
+ *
153
+ * @param {RequestMessage} request
154
+ * @returns {AsyncGenerator<any>}
155
+ */
156
+ async *stream(request) {
157
+ const abortController = new AbortController();
158
+ let response;
159
+ try {
160
+ response = await this.#makeHttpRequest(request, abortController.signal);
161
+ }
162
+ catch (e) {
163
+ throw new Error(`Stream request failed: ${e.message}`, { cause: e });
164
+ }
165
+ if (!response.ok) {
166
+ // For error responses, buffer and parse the error body
167
+ const buffer = Buffer.from(await response.arrayBuffer());
168
+ const errorMessage = `Server returned HTTP ${response.status}: ${response.statusText}`;
169
+ const contentType = response.headers.get("Content-Type");
170
+ const reader = this.#getReaderForContentType(contentType);
171
+ try {
172
+ if (reader) {
173
+ const deserialized = await reader.readResponse(buffer);
174
+ throw new ResponseError(errorMessage, {
175
+ code: deserialized.status.code,
176
+ message: deserialized.status.message || response.statusText,
177
+ exception: deserialized.status.exception,
178
+ });
179
+ }
180
+ else if (contentType === 'application/json') {
181
+ const errorBody = JSON.parse(buffer.toString());
182
+ throw new ResponseError(errorMessage, {
183
+ code: response.status,
184
+ message: errorBody.message || errorBody.error || response.statusText,
185
+ });
186
+ }
187
+ }
188
+ catch (err) {
189
+ if (err instanceof ResponseError)
190
+ throw err;
191
+ }
192
+ throw new ResponseError(errorMessage, {
193
+ code: response.status,
194
+ message: response.statusText,
195
+ });
196
+ }
197
+ if (!response.body) {
198
+ // 204 No Content - nothing to yield
199
+ return;
200
+ }
201
+ const streamReader = StreamReader.fromReadableStream(response.body);
202
+ let completed = false;
203
+ try {
204
+ yield* this._responseSerializer.readResponseStream(streamReader);
205
+ completed = true;
206
+ }
207
+ finally {
208
+ if (!completed) {
209
+ // Consumer broke out early or an error occurred - abort to release the connection
210
+ abortController.abort();
211
+ }
212
+ }
213
+ }
214
+ #getReaderForContentType(contentType) {
215
+ if (!contentType) {
216
+ return this._responseSerializer;
217
+ }
218
+ if (contentType === this._responseSerializer.mimeType) {
219
+ return this._responseSerializer;
220
+ }
221
+ return null;
222
+ }
223
+ async #makeHttpRequest(request, signal) {
224
+ const headers = {
225
+ 'Accept': this._responseSerializer.mimeType,
226
+ };
227
+ if (this._compression === 'deflate') {
228
+ headers['Accept-Encoding'] = 'deflate';
229
+ }
230
+ if (this._enableUserAgentOnConnect) {
231
+ const userAgent = await utils.getUserAgent();
232
+ if (userAgent !== undefined) {
233
+ headers[utils.getUserAgentHeader()] = userAgent;
234
+ }
235
+ }
236
+ const httpRequest = new HttpRequest('POST', this.url, headers, request);
237
+ // Promote transactionId to HTTP header before interceptors run.
238
+ // The field remains in the serialized body as well (dual transmission
239
+ // per the HTTP transaction protocol specification).
240
+ if (request instanceof RequestMessage) {
241
+ const fields = request.getFields();
242
+ if (fields.has('transactionId')) {
243
+ httpRequest.headers['X-Transaction-Id'] = fields.get('transactionId');
244
+ }
245
+ }
246
+ for (let i = 0; i < this._interceptors.length; i++) {
247
+ try {
248
+ await this._interceptors[i](httpRequest);
249
+ }
250
+ catch (e) {
251
+ throw new Error(`Request interceptor at index ${i} failed: ${e.message}`, { cause: e });
252
+ }
253
+ }
254
+ // Auto-serialize body to JSON after interceptors run (idempotent if already serialized)
255
+ httpRequest.serializeBody();
256
+ this._log('debug', `Sending ${httpRequest.method} request to ${httpRequest.url}`);
257
+ return httpFetch.fetch(httpRequest.url, {
258
+ method: httpRequest.method,
259
+ headers: httpRequest.headers,
260
+ body: httpRequest.body,
261
+ signal,
262
+ // Node only: the undici dispatcher carries the connection-pool options. In the browser
263
+ // it is undefined and the field is omitted, letting the user agent manage the transport.
264
+ ...(this._dispatcher ? { dispatcher: this._dispatcher } : {}),
265
+ });
266
+ }
267
+ async #handleResponse(response) {
268
+ const contentType = response.headers.get("Content-Type");
269
+ const buffer = Buffer.from(await response.arrayBuffer());
270
+ const reader = this.#getReaderForContentType(contentType);
271
+ if (!response.ok) {
272
+ const errorMessage = `Server returned HTTP ${response.status}: ${response.statusText}`;
273
+ try {
274
+ if (reader) {
275
+ const deserialized = await reader.readResponse(buffer);
276
+ throw new ResponseError(errorMessage, {
277
+ code: deserialized.status.code,
278
+ message: deserialized.status.message || response.statusText,
279
+ exception: deserialized.status.exception,
280
+ });
281
+ }
282
+ else if (contentType === 'application/json') {
283
+ const errorBody = JSON.parse(buffer.toString());
284
+ throw new ResponseError(errorMessage, {
285
+ code: response.status,
286
+ message: errorBody.message || errorBody.error || response.statusText,
287
+ });
288
+ }
289
+ }
290
+ catch (err) {
291
+ if (err instanceof ResponseError) {
292
+ throw err;
293
+ }
294
+ }
295
+ throw new ResponseError(errorMessage, {
296
+ code: response.status,
297
+ message: response.statusText,
298
+ });
299
+ }
300
+ if (!reader) {
301
+ throw new Error(`Response Content-Type '${contentType}' does not match the configured response serializer (expected '${this._responseSerializer.mimeType}')`);
302
+ }
303
+ const deserialized = await reader.readResponse(buffer);
304
+ if (deserialized.status.code && deserialized.status.code !== responseStatusCode.success && deserialized.status.code !== responseStatusCode.noContent && deserialized.status.code !== responseStatusCode.partialContent) {
305
+ throw new ResponseError(`Server error: ${deserialized.status.message || 'Unknown error'} (${deserialized.status.code})`, {
306
+ code: deserialized.status.code,
307
+ message: deserialized.status.message || '',
308
+ exception: deserialized.status.exception,
309
+ });
310
+ }
311
+ return new ResultSet(deserialized.result.bulked
312
+ ? deserialized.result.data.map((item) => new Traverser(item.v, item.bulk))
313
+ : deserialized.result.data, new Map());
314
+ }
315
+ /**
316
+ * Closes the Connection.
317
+ * @return {Promise}
318
+ */
319
+ async close() {
320
+ this._log('debug', `Closing connection to ${this.url}`);
321
+ await this._dispatcher?.close();
322
+ }
323
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Browser counterpart of {@link ./dispatcher.ts}. The Node build configures the underlying HTTP
3
+ * transport through an `undici` dispatcher, but `undici` is built on `node:net`/`node:tls` and
4
+ * cannot run in a browser. Bundlers pick this file up via the `"browser"` field in `package.json`,
5
+ * so a browser bundle never imports `undici`.
6
+ *
7
+ * The browser's HTTP stack manages the connection-pool options that the Node dispatcher carries,
8
+ * so {@link buildDispatcher} throws if any is set explicitly (rather than silently ignoring it)
9
+ * and otherwise returns `undefined`, leaving the connection to issue a plain `fetch`. It is the
10
+ * only export the connection imports through the swapped `./dispatcher.js` path.
11
+ */
12
+ /** Transport options accepted by {@link buildDispatcher}; mirrors the Node dispatcher's options. */
13
+ type DispatcherOptions = {
14
+ maxConnections?: number;
15
+ readTimeoutMillis?: number;
16
+ maxResponseHeaderBytes?: number;
17
+ keepAliveTimeMillis?: number;
18
+ proxy?: string;
19
+ };
20
+ /**
21
+ * In the browser there is no `undici` dispatcher, so `fetch` is issued without one and the browser
22
+ * manages the transport. Any {@link NODE_ONLY_OPTIONS} set explicitly cannot be honored and throws,
23
+ * so a misconfiguration surfaces immediately instead of being silently dropped. With none set this
24
+ * returns `undefined` and the connection omits the `dispatcher` field.
25
+ */
26
+ export declare function buildDispatcher(options?: DispatcherOptions): undefined;
27
+ /**
28
+ * Browser counterpart of the Node `httpFetch` holder. There is no `undici` in the browser, so
29
+ * requests use the global `fetch` and the user agent manages the transport. Same holder shape as
30
+ * the Node build.
31
+ */
32
+ export declare const httpFetch: {
33
+ fetch: typeof globalThis.fetch;
34
+ };
35
+ export {};
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ /**
20
+ * Connection-pool / transport options that only the Node (`undici`) dispatcher can honor. The
21
+ * browser's HTTP stack owns these concerns and exposes no `fetch` API to configure them, so they
22
+ * are rejected here rather than silently ignored. `readTimeoutMillis` is intentionally not in this list:
23
+ * it has a browser analog (an `AbortSignal`-based timeout) and is handled by the connection.
24
+ */
25
+ const NODE_ONLY_OPTIONS = [
26
+ 'maxConnections',
27
+ 'keepAliveTimeMillis',
28
+ 'maxResponseHeaderBytes',
29
+ 'proxy',
30
+ ];
31
+ /**
32
+ * In the browser there is no `undici` dispatcher, so `fetch` is issued without one and the browser
33
+ * manages the transport. Any {@link NODE_ONLY_OPTIONS} set explicitly cannot be honored and throws,
34
+ * so a misconfiguration surfaces immediately instead of being silently dropped. With none set this
35
+ * returns `undefined` and the connection omits the `dispatcher` field.
36
+ */
37
+ export function buildDispatcher(options = {}) {
38
+ const unsupported = NODE_ONLY_OPTIONS.filter((key) => options[key] !== undefined);
39
+ if (unsupported.length > 0) {
40
+ throw new Error(`The following connection options are not supported in the browser and are managed by the ` +
41
+ `browser's HTTP stack: ${unsupported.join(', ')}. Remove them when running in a browser ` +
42
+ `(they are supported in Node).`);
43
+ }
44
+ return undefined;
45
+ }
46
+ /**
47
+ * Browser counterpart of the Node `httpFetch` holder. There is no `undici` in the browser, so
48
+ * requests use the global `fetch` and the user agent manages the transport. Same holder shape as
49
+ * the Node build.
50
+ */
51
+ export const httpFetch = {
52
+ fetch: globalThis.fetch.bind(globalThis),
53
+ };