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
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to the Apache Software Foundation (ASF) under one
4
+ * or more contributor license agreements. See the NOTICE file
5
+ * distributed with this work for additional information
6
+ * regarding copyright ownership. The ASF licenses this file
7
+ * to you under the Apache License, Version 2.0 (the
8
+ * "License"); you may not use this file except in compliance
9
+ * with the License. You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.PDTRegistry = void 0;
22
+ const graph_js_1 = require("./graph.cjs");
23
+ /**
24
+ * A standalone registry that allows users to register adapters for hydrating
25
+ * raw {@link CompositePDT} and {@link PrimitivePDT} instances
26
+ * into domain-specific objects.
27
+ */
28
+ class PDTRegistry {
29
+ _adapters = new Map();
30
+ _adaptersByClass = new Map();
31
+ _primitiveAdapters = new Map();
32
+ _primitiveAdaptersByClass = new Map();
33
+ register(typeName, adapter, targetClass) {
34
+ this._adapters.set(typeName, adapter);
35
+ if (targetClass) {
36
+ this._adaptersByClass.set(targetClass, { typeName, adapter });
37
+ }
38
+ }
39
+ registerPrimitive(typeName, adapter, targetClass) {
40
+ this._primitiveAdapters.set(typeName, adapter);
41
+ if (targetClass) {
42
+ this._primitiveAdaptersByClass.set(targetClass, { typeName, adapter });
43
+ }
44
+ }
45
+ hydrate(pdt) {
46
+ if (!(pdt instanceof graph_js_1.CompositePDT))
47
+ return pdt;
48
+ const adapter = this._adapters.get(pdt.name);
49
+ const hydratedFields = {};
50
+ let changed = false;
51
+ for (const [k, v] of Object.entries(pdt.fields)) {
52
+ if (v instanceof graph_js_1.CompositePDT) {
53
+ const h = this.hydrate(v);
54
+ hydratedFields[k] = h;
55
+ if (h !== v)
56
+ changed = true;
57
+ }
58
+ else if (v instanceof graph_js_1.PrimitivePDT) {
59
+ const h = this.hydratePrimitive(v);
60
+ hydratedFields[k] = h;
61
+ if (h !== v)
62
+ changed = true;
63
+ }
64
+ else {
65
+ hydratedFields[k] = v;
66
+ }
67
+ }
68
+ if (!adapter) {
69
+ return changed ? new graph_js_1.CompositePDT(pdt.name, hydratedFields) : pdt;
70
+ }
71
+ try {
72
+ return adapter.deserialize(hydratedFields);
73
+ }
74
+ catch (e) {
75
+ console.warn(`PDT hydration failed for '${pdt.name}': ${e.message}`);
76
+ return pdt;
77
+ }
78
+ }
79
+ hydratePrimitive(pdt) {
80
+ if (!(pdt instanceof graph_js_1.PrimitivePDT))
81
+ return pdt;
82
+ const adapter = this._primitiveAdapters.get(pdt.name);
83
+ if (!adapter)
84
+ return pdt;
85
+ try {
86
+ return adapter.fromValue(pdt.value);
87
+ }
88
+ catch (e) {
89
+ console.warn(`Primitive PDT hydration failed for '${pdt.name}': ${e.message}`);
90
+ return pdt;
91
+ }
92
+ }
93
+ hasAdapter(typeName) {
94
+ return this._adapters.has(typeName);
95
+ }
96
+ hasPrimitiveAdapter(typeName) {
97
+ return this._primitiveAdapters.has(typeName);
98
+ }
99
+ getSerializer(typeName) {
100
+ const adapter = this._adapters.get(typeName);
101
+ return adapter ? adapter.serialize : null;
102
+ }
103
+ getAdapterByClass(cls) {
104
+ const entry = this._adaptersByClass.get(cls);
105
+ if (!entry)
106
+ return null;
107
+ return { typeName: entry.typeName, serialize: entry.adapter.serialize };
108
+ }
109
+ getPrimitiveAdapterByClass(cls) {
110
+ const entry = this._primitiveAdaptersByClass.get(cls);
111
+ if (!entry)
112
+ return null;
113
+ return { typeName: entry.typeName, toValue: entry.adapter.toValue };
114
+ }
115
+ }
116
+ exports.PDTRegistry = PDTRegistry;
@@ -0,0 +1,34 @@
1
+ export interface PdtAdapter {
2
+ serialize: (obj: any) => Record<string, any>;
3
+ deserialize: (fields: Record<string, any>) => any;
4
+ }
5
+ export interface PrimitivePdtAdapter {
6
+ toValue: (obj: any) => string;
7
+ fromValue: (value: string) => any;
8
+ }
9
+ /**
10
+ * A standalone registry that allows users to register adapters for hydrating
11
+ * raw {@link CompositePDT} and {@link PrimitivePDT} instances
12
+ * into domain-specific objects.
13
+ */
14
+ export declare class PDTRegistry {
15
+ private readonly _adapters;
16
+ private readonly _adaptersByClass;
17
+ private readonly _primitiveAdapters;
18
+ private readonly _primitiveAdaptersByClass;
19
+ register(typeName: string, adapter: PdtAdapter, targetClass?: Function): void;
20
+ registerPrimitive(typeName: string, adapter: PrimitivePdtAdapter, targetClass?: Function): void;
21
+ hydrate(pdt: any): any;
22
+ hydratePrimitive(pdt: any): any;
23
+ hasAdapter(typeName: string): boolean;
24
+ hasPrimitiveAdapter(typeName: string): boolean;
25
+ getSerializer(typeName: string): ((obj: any) => Record<string, any>) | null;
26
+ getAdapterByClass(cls: Function): {
27
+ typeName: string;
28
+ serialize: (obj: any) => Record<string, any>;
29
+ } | null;
30
+ getPrimitiveAdapterByClass(cls: Function): {
31
+ typeName: string;
32
+ toValue: (obj: any) => string;
33
+ } | null;
34
+ }
@@ -18,16 +18,25 @@
18
18
  * under the License.
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.Path = exports.Property = exports.VertexProperty = exports.Edge = exports.Vertex = exports.Graph = void 0;
21
+ exports.PrimitivePDT = exports.CompositePDT = exports.Path = exports.Tree = exports.Property = exports.VertexProperty = exports.Edge = exports.Vertex = exports.Graph = void 0;
22
22
  /**
23
23
  * @author Jorge Bay Gondra
24
24
  */
25
25
  /**
26
26
  * An "empty" graph object to server only as a reference.
27
+ *
28
+ * Holds in-memory collections of vertices and edges so that GraphBinary
29
+ * Graph (0x10) deserialization can return a usable data container.
27
30
  */
28
31
  class Graph {
32
+ vertices;
33
+ edges;
34
+ constructor() {
35
+ this.vertices = new Map();
36
+ this.edges = new Map();
37
+ }
29
38
  toString() {
30
- return 'graph[]';
39
+ return `graph[vertices:${this.vertices.size} edges:${this.edges.size}]`;
31
40
  }
32
41
  }
33
42
  exports.Graph = Graph;
@@ -50,8 +59,17 @@ class Element {
50
59
  }
51
60
  }
52
61
  class Vertex extends Element {
53
- constructor(id, label, properties = []) {
54
- super(id, label, properties ?? []);
62
+ labels;
63
+ constructor(id, label, properties = [], labels) {
64
+ // Determine the canonical labels array from either explicit labels param or label param
65
+ const resolvedLabels = labels
66
+ ? labels
67
+ : Array.isArray(label) ? label
68
+ : label ? [label]
69
+ : ['vertex'];
70
+ const primaryLabel = (resolvedLabels.length > 0 ? resolvedLabels[0] : 'vertex');
71
+ super(id, primaryLabel, properties ?? []);
72
+ this.labels = new Set(resolvedLabels);
55
73
  }
56
74
  toString() {
57
75
  return `v[${this.id}]`;
@@ -60,13 +78,20 @@ class Vertex extends Element {
60
78
  exports.Vertex = Vertex;
61
79
  class Edge extends Element {
62
80
  outV;
63
- label;
64
81
  inV;
65
- constructor(id, outV, label, inV, properties = []) {
66
- super(id, label, properties ?? []);
82
+ labels;
83
+ constructor(id, outV, label, inV, properties = [], labels) {
84
+ // Determine the canonical labels array from either explicit labels param or label param
85
+ const resolvedLabels = labels
86
+ ? labels
87
+ : Array.isArray(label) ? label
88
+ : label ? [label]
89
+ : ['edge'];
90
+ const primaryLabel = (resolvedLabels.length > 0 ? resolvedLabels[0] : 'edge');
91
+ super(id, primaryLabel, properties ?? []);
67
92
  this.outV = outV;
68
- this.label = label;
69
93
  this.inV = inV;
94
+ this.labels = new Set(resolvedLabels);
70
95
  }
71
96
  toString() {
72
97
  const outVId = this.outV ? this.outV.id : '?';
@@ -104,6 +129,270 @@ class Property {
104
129
  }
105
130
  }
106
131
  exports.Property = Property;
132
+ /**
133
+ * A tree data structure with a tree-shaped public API.
134
+ *
135
+ * Children are kept in a private, ordered array of {key, value} entries (not a
136
+ * native {@link Map}, whose reference-identity keys would break value-equality).
137
+ * Access is only through the read API; lookups use {@link treeKeysEqual}, which
138
+ * compares keys by value and treats null/undefined as a distinct key.
139
+ */
140
+ class Tree {
141
+ #entries;
142
+ constructor(...rootValues) {
143
+ this.#entries = [];
144
+ for (const value of rootValues) {
145
+ this.#entries.push({ key: value, value: new Tree() });
146
+ }
147
+ }
148
+ /**
149
+ * Locates the entry whose key is structurally equal to the given key.
150
+ * @returns the matching entry, or undefined if none exists.
151
+ */
152
+ _findEntry(key) {
153
+ for (const entry of this.#entries) {
154
+ if (treeKeysEqual(entry.key, key)) {
155
+ return entry;
156
+ }
157
+ }
158
+ return undefined;
159
+ }
160
+ /**
161
+ * Returns the keys at the root of this tree.
162
+ */
163
+ rootNodes() {
164
+ return this.#entries.map((e) => e.key);
165
+ }
166
+ /**
167
+ * Returns the child subtree for the given key.
168
+ * @throws {Error} if no child exists for the given key.
169
+ */
170
+ childAt(key) {
171
+ const entry = this._findEntry(key);
172
+ if (entry === undefined) {
173
+ throw new Error(`Tree has no child for key: ${key}`);
174
+ }
175
+ return entry.value;
176
+ }
177
+ /**
178
+ * Returns true if the given key is an immediate child of this tree.
179
+ */
180
+ hasChild(key) {
181
+ return this._findEntry(key) !== undefined;
182
+ }
183
+ /**
184
+ * Returns true if the given value appears as a key anywhere in this tree (recursive).
185
+ */
186
+ contains(value) {
187
+ for (const entry of this.#entries) {
188
+ if (treeKeysEqual(entry.key, value)) {
189
+ return true;
190
+ }
191
+ }
192
+ for (const entry of this.#entries) {
193
+ if (entry.value.contains(value)) {
194
+ return true;
195
+ }
196
+ }
197
+ return false;
198
+ }
199
+ /**
200
+ * Recursively searches the tree for the first subtree rooted at key.
201
+ * @returns the matching subtree, or undefined if absent.
202
+ */
203
+ findSubtree(key) {
204
+ const entry = this._findEntry(key);
205
+ if (entry !== undefined) {
206
+ return entry.value;
207
+ }
208
+ for (const e of this.#entries) {
209
+ const found = e.value.findSubtree(key);
210
+ if (found !== undefined) {
211
+ return found;
212
+ }
213
+ }
214
+ return undefined;
215
+ }
216
+ /**
217
+ * Returns the existing child for key, or inserts and returns a new empty Tree if absent.
218
+ */
219
+ getOrCreateChild(key) {
220
+ const entry = this._findEntry(key);
221
+ if (entry !== undefined) {
222
+ return entry.value;
223
+ }
224
+ const child = new Tree();
225
+ this.#entries.push({ key, value: child });
226
+ return child;
227
+ }
228
+ /**
229
+ * Returns true if this tree has no children. An empty tree is considered a leaf.
230
+ */
231
+ isLeaf() {
232
+ return this.#entries.length === 0;
233
+ }
234
+ /**
235
+ * Returns the total number of nodes (keys) in the tree, counted recursively.
236
+ */
237
+ nodeCount() {
238
+ let count = this.#entries.length;
239
+ for (const entry of this.#entries) {
240
+ count += entry.value.nodeCount();
241
+ }
242
+ return count;
243
+ }
244
+ /**
245
+ * Returns the keys at the given depth. Depth 0 returns the root keys.
246
+ * Negative depths or depths beyond the tree's height return an empty array.
247
+ */
248
+ getNodesAtDepth(depth) {
249
+ const list = [];
250
+ for (const t of this.getTreesAtDepth(depth)) {
251
+ for (const entry of t.#entries) {
252
+ list.push(entry.key);
253
+ }
254
+ }
255
+ return list;
256
+ }
257
+ /**
258
+ * Returns the trees at the given depth. Depth 0 returns a singleton list containing this tree.
259
+ * Negative depths or depths beyond the tree's height return an empty array.
260
+ */
261
+ getTreesAtDepth(depth) {
262
+ if (depth < 0) {
263
+ return [];
264
+ }
265
+ let currentDepth = [this];
266
+ for (let i = 0; i < depth; i++) {
267
+ const next = [];
268
+ for (const t of currentDepth) {
269
+ for (const entry of t.#entries) {
270
+ next.push(entry.value);
271
+ }
272
+ }
273
+ if (next.length === 0) {
274
+ return [];
275
+ }
276
+ currentDepth = next;
277
+ }
278
+ return currentDepth;
279
+ }
280
+ /**
281
+ * Returns all keys whose subtrees are leaves.
282
+ */
283
+ getLeafNodes() {
284
+ const leaves = [];
285
+ this._collectLeafKeys(leaves);
286
+ return leaves;
287
+ }
288
+ _collectLeafKeys(out) {
289
+ for (const entry of this.#entries) {
290
+ if (entry.value.isLeaf()) {
291
+ out.push(entry.key);
292
+ }
293
+ else {
294
+ entry.value._collectLeafKeys(out);
295
+ }
296
+ }
297
+ }
298
+ /**
299
+ * Returns single-key trees representing each leaf key in this tree, preserving the original
300
+ * key-to-empty-subtree mapping.
301
+ */
302
+ getLeafTrees() {
303
+ const leaves = [];
304
+ this._collectLeafTrees(leaves);
305
+ return leaves;
306
+ }
307
+ _collectLeafTrees(out) {
308
+ for (const entry of this.#entries) {
309
+ if (entry.value.isLeaf()) {
310
+ const leaf = new Tree();
311
+ leaf.#entries.push({ key: entry.key, value: entry.value });
312
+ out.push(leaf);
313
+ }
314
+ else {
315
+ entry.value._collectLeafTrees(out);
316
+ }
317
+ }
318
+ }
319
+ /**
320
+ * Recursively merges other into this tree. For overlapping keys, child subtrees are merged in turn.
321
+ * For keys present only in other, the corresponding subtree reference is adopted directly.
322
+ */
323
+ addTree(other) {
324
+ for (const entry of other.#entries) {
325
+ const existing = this._findEntry(entry.key);
326
+ if (existing !== undefined) {
327
+ existing.value.addTree(entry.value);
328
+ }
329
+ else {
330
+ this.#entries.push({ key: entry.key, value: entry.value });
331
+ }
332
+ }
333
+ }
334
+ /**
335
+ * Splits this tree into one tree per root key. If the tree has a single root, returns a singleton list
336
+ * containing this tree.
337
+ */
338
+ splitParents() {
339
+ if (this.#entries.length === 1) {
340
+ return [this];
341
+ }
342
+ const parents = [];
343
+ for (const entry of this.#entries) {
344
+ const parentTree = new Tree();
345
+ parentTree.#entries.push({ key: entry.key, value: entry.value });
346
+ parents.push(parentTree);
347
+ }
348
+ return parents;
349
+ }
350
+ /**
351
+ * Produces a formatted string representation of the tree structure using a |-- ASCII style,
352
+ * Uses a |-- ASCII style with a 3-space indent per level and no trailing newline.
353
+ */
354
+ prettyPrint() {
355
+ const lines = [];
356
+ this._prettyPrint(lines, '');
357
+ return lines.join('\n');
358
+ }
359
+ _prettyPrint(lines, prefix) {
360
+ for (const entry of this.#entries) {
361
+ lines.push(`${prefix}|--${entry.key}`);
362
+ entry.value._prettyPrint(lines, `${prefix} `);
363
+ }
364
+ }
365
+ /**
366
+ * Structural recursive equality. Order across siblings is irrelevant; two trees are equal if they have the
367
+ * same set of keys and each key's subtree is recursively equal.
368
+ */
369
+ equals(other) {
370
+ if (this === other) {
371
+ return true;
372
+ }
373
+ if (!(other instanceof Tree)) {
374
+ return false;
375
+ }
376
+ if (this.#entries.length !== other.#entries.length) {
377
+ return false;
378
+ }
379
+ for (const entry of this.#entries) {
380
+ const match = other._findEntry(entry.key);
381
+ if (match === undefined) {
382
+ return false;
383
+ }
384
+ if (!entry.value.equals(match.value)) {
385
+ return false;
386
+ }
387
+ }
388
+ return true;
389
+ }
390
+ toString() {
391
+ const parts = this.#entries.map((e) => `${e.key}=${e.value.toString()}`);
392
+ return `{${parts.join(', ')}}`;
393
+ }
394
+ }
395
+ exports.Tree = Tree;
107
396
  /**
108
397
  * Represents a walk through a graph as defined by a traversal.
109
398
  */
@@ -128,6 +417,24 @@ class Path {
128
417
  }
129
418
  }
130
419
  exports.Path = Path;
420
+ /**
421
+ * Null-safe structural key comparison for Tree keys, built on {@link areEqual}.
422
+ * areEqual dereferences obj.equals, so null/undefined keys are handled here first.
423
+ * Element keys also require matching concrete type (the shared {@link Element.equals}
424
+ * compares by id only), so a Vertex and an Edge with the same id stay distinct keys.
425
+ */
426
+ function treeKeysEqual(a, b) {
427
+ if (a === b) {
428
+ return true;
429
+ }
430
+ if (a === null || a === undefined || b === null || b === undefined) {
431
+ return false;
432
+ }
433
+ if (a instanceof Element && b instanceof Element && a.constructor !== b.constructor) {
434
+ return false;
435
+ }
436
+ return areEqual(a, b);
437
+ }
131
438
  function areEqual(obj1, obj2) {
132
439
  if (obj1 === obj2) {
133
440
  return true;
@@ -148,6 +455,42 @@ function areEqual(obj1, obj2) {
148
455
  }
149
456
  return false;
150
457
  }
458
+ /**
459
+ * Represents a composite Provider Defined Type (PDT).
460
+ */
461
+ class CompositePDT {
462
+ name;
463
+ fields;
464
+ constructor(name, fields) {
465
+ if (!name)
466
+ throw new Error('CompositePDT name cannot be null or empty');
467
+ this.name = name;
468
+ this.fields = Object.freeze(fields || {});
469
+ }
470
+ toString() {
471
+ return `pdt[${this.name}]${JSON.stringify(this.fields)}`;
472
+ }
473
+ }
474
+ exports.CompositePDT = CompositePDT;
475
+ /**
476
+ * Represents a primitive Provider Defined Type (PDT).
477
+ */
478
+ class PrimitivePDT {
479
+ name;
480
+ value;
481
+ constructor(name, value) {
482
+ if (!name)
483
+ throw new Error('PrimitivePDT name cannot be null or empty');
484
+ if (value === null || value === undefined)
485
+ throw new Error('PrimitivePDT value cannot be null');
486
+ this.name = name;
487
+ this.value = value;
488
+ }
489
+ toString() {
490
+ return `pdt[${this.name}:${this.value}]`;
491
+ }
492
+ }
493
+ exports.PrimitivePDT = PrimitivePDT;
151
494
  function summarize(value) {
152
495
  if (value === null || value === undefined) {
153
496
  return value;