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
@@ -58,46 +58,41 @@ class IntSerializer {
58
58
  bufs.push(v);
59
59
  return buffer_1.Buffer.concat(bufs);
60
60
  }
61
- deserialize(buffer, fullyQualifiedFormat = true) {
62
- let len = 0;
63
- let cursor = buffer;
64
- try {
65
- if (buffer === undefined || buffer === null || !(buffer instanceof buffer_1.Buffer)) {
66
- throw new Error('buffer is missing');
67
- }
68
- if (buffer.length < 1) {
69
- throw new Error('buffer is empty');
70
- }
71
- if (fullyQualifiedFormat) {
72
- const type_code = cursor.readUInt8();
73
- len++;
74
- if (type_code !== this.ioc.DataType.INT) {
75
- throw new Error('unexpected {type_code}');
76
- }
77
- cursor = cursor.slice(1);
78
- if (cursor.length < 1) {
79
- throw new Error('{value_flag} is missing');
80
- }
81
- const value_flag = cursor.readUInt8();
82
- len++;
83
- if (value_flag === 1) {
84
- return { v: null, len };
85
- }
86
- if (value_flag !== 0) {
87
- throw new Error('unexpected {value_flag}');
88
- }
89
- cursor = cursor.slice(1);
90
- }
91
- if (cursor.length < 4) {
92
- throw new Error('unexpected {value} length');
93
- }
94
- len += 4;
95
- const v = cursor.readInt32BE();
96
- return { v, len };
61
+ /**
62
+ * Read a bare int32 value from the StreamReader (no type_code or value_flag).
63
+ * @param {StreamReader} reader
64
+ * @returns {Promise<number>}
65
+ */
66
+ async deserializeBare(reader) {
67
+ return await reader.readInt32BE();
68
+ }
69
+ /**
70
+ * @param {StreamReader} reader
71
+ * @param {number} valueFlag - already consumed by AnySerializer
72
+ * @param {number} typeCode
73
+ * @returns {Promise<number>}
74
+ */
75
+ async deserializeValue(reader, valueFlag, typeCode) {
76
+ return await reader.readInt32BE();
77
+ }
78
+ /**
79
+ * Read a fully-qualified int from the StreamReader (type_code + value_flag + value).
80
+ * @param {StreamReader} reader
81
+ * @returns {Promise<number|null>}
82
+ */
83
+ async deserialize(reader) {
84
+ const type_code = await reader.readUInt8();
85
+ if (type_code !== this.ioc.DataType.INT) {
86
+ throw new Error(`IntSerializer: unexpected {type_code}=0x${type_code.toString(16)}`);
87
+ }
88
+ const value_flag = await reader.readUInt8();
89
+ if (value_flag === 0x01) {
90
+ return null;
97
91
  }
98
- catch (err) {
99
- throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
92
+ if (value_flag !== 0x00) {
93
+ throw new Error(`IntSerializer: unexpected {value_flag}=0x${value_flag.toString(16)}`);
100
94
  }
95
+ return this.deserializeValue(reader, value_flag, type_code);
101
96
  }
102
97
  }
103
98
  exports.default = IntSerializer;
@@ -5,9 +5,24 @@ export default class IntSerializer {
5
5
  ioc: any;
6
6
  canBeUsedFor(value: any): boolean;
7
7
  serialize(item: any, fullyQualifiedFormat?: boolean): Buffer<ArrayBuffer>;
8
- deserialize(buffer: any, fullyQualifiedFormat?: boolean, ...args: any[]): {
9
- v: any;
10
- len: number;
11
- };
8
+ /**
9
+ * Read a bare int32 value from the StreamReader (no type_code or value_flag).
10
+ * @param {StreamReader} reader
11
+ * @returns {Promise<number>}
12
+ */
13
+ deserializeBare(reader: StreamReader): Promise<number>;
14
+ /**
15
+ * @param {StreamReader} reader
16
+ * @param {number} valueFlag - already consumed by AnySerializer
17
+ * @param {number} typeCode
18
+ * @returns {Promise<number>}
19
+ */
20
+ deserializeValue(reader: StreamReader, valueFlag: number, typeCode: number): Promise<number>;
21
+ /**
22
+ * Read a fully-qualified int from the StreamReader (type_code + value_flag + value).
23
+ * @param {StreamReader} reader
24
+ * @returns {Promise<number|null>}
25
+ */
26
+ deserialize(reader: StreamReader): Promise<number | null>;
12
27
  }
13
28
  import { Buffer } from 'buffer';
@@ -46,50 +46,37 @@ class LongSerializer {
46
46
  bufs.push(v);
47
47
  return buffer_1.Buffer.concat(bufs);
48
48
  }
49
- deserialize(buffer, fullyQualifiedFormat = true) {
50
- let len = 0;
51
- let cursor = buffer;
52
- try {
53
- if (buffer === undefined || buffer === null || !(buffer instanceof buffer_1.Buffer)) {
54
- throw new Error('buffer is missing');
55
- }
56
- if (buffer.length < 1) {
57
- throw new Error('buffer is empty');
58
- }
59
- if (fullyQualifiedFormat) {
60
- const type_code = cursor.readUInt8();
61
- len++;
62
- if (type_code !== this.ioc.DataType.LONG) {
63
- throw new Error('unexpected {type_code}');
64
- }
65
- cursor = cursor.slice(1);
66
- if (cursor.length < 1) {
67
- throw new Error('{value_flag} is missing');
68
- }
69
- const value_flag = cursor.readUInt8();
70
- len++;
71
- if (value_flag === 1) {
72
- return { v: null, len };
73
- }
74
- if (value_flag !== 0) {
75
- throw new Error('unexpected {value_flag}');
76
- }
77
- cursor = cursor.slice(1);
78
- }
79
- if (cursor.length < 8) {
80
- throw new Error('unexpected {value} length');
81
- }
82
- len += 8;
83
- let v = cursor.readBigInt64BE();
84
- if (v >= Number.MIN_SAFE_INTEGER && v <= Number.MAX_SAFE_INTEGER) {
85
- v = Number(v);
86
- }
87
- // Values outside safe integer range stay as BigInt to preserve precision.
88
- return { v, len };
49
+ /**
50
+ * @param {StreamReader} reader
51
+ * @param {number} valueFlag - already consumed by AnySerializer
52
+ * @param {number} typeCode
53
+ * @returns {Promise<number|bigint>}
54
+ */
55
+ async deserializeValue(reader, valueFlag, typeCode) {
56
+ let v = await reader.readBigInt64BE();
57
+ if (v >= Number.MIN_SAFE_INTEGER && v <= Number.MAX_SAFE_INTEGER) {
58
+ v = Number(v);
59
+ }
60
+ return v;
61
+ }
62
+ /**
63
+ * Read a fully-qualified long from the StreamReader.
64
+ * @param {StreamReader} reader
65
+ * @returns {Promise<number|bigint|null>}
66
+ */
67
+ async deserialize(reader) {
68
+ const type_code = await reader.readUInt8();
69
+ if (type_code !== this.ioc.DataType.LONG) {
70
+ throw new Error(`LongSerializer: unexpected {type_code}=0x${type_code.toString(16)}`);
71
+ }
72
+ const value_flag = await reader.readUInt8();
73
+ if (value_flag === 0x01) {
74
+ return null;
89
75
  }
90
- catch (err) {
91
- throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
76
+ if (value_flag !== 0x00) {
77
+ throw new Error(`LongSerializer: unexpected {value_flag}=0x${value_flag.toString(16)}`);
92
78
  }
79
+ return this.deserializeValue(reader, value_flag, type_code);
93
80
  }
94
81
  }
95
82
  exports.default = LongSerializer;
@@ -3,9 +3,18 @@ export default class LongSerializer {
3
3
  ioc: any;
4
4
  canBeUsedFor(): void;
5
5
  serialize(item: any, fullyQualifiedFormat?: boolean): Buffer<ArrayBuffer>;
6
- deserialize(buffer: any, fullyQualifiedFormat?: boolean, ...args: any[]): {
7
- v: any;
8
- len: number;
9
- };
6
+ /**
7
+ * @param {StreamReader} reader
8
+ * @param {number} valueFlag - already consumed by AnySerializer
9
+ * @param {number} typeCode
10
+ * @returns {Promise<number|bigint>}
11
+ */
12
+ deserializeValue(reader: StreamReader, valueFlag: number, typeCode: number): Promise<number | bigint>;
13
+ /**
14
+ * Read a fully-qualified long from the StreamReader.
15
+ * @param {StreamReader} reader
16
+ * @returns {Promise<number|bigint|null>}
17
+ */
18
+ deserialize(reader: StreamReader): Promise<number | bigint | null>;
10
19
  }
11
20
  import { Buffer } from 'buffer';
@@ -67,78 +67,44 @@ class MapSerializer {
67
67
  }
68
68
  return buffer_1.Buffer.concat(bufs);
69
69
  }
70
- deserialize(buffer, fullyQualifiedFormat = true) {
71
- let len = 0;
72
- let cursor = buffer;
73
- try {
74
- if (buffer === undefined || buffer === null || !(buffer instanceof buffer_1.Buffer)) {
75
- throw new Error('buffer is missing');
76
- }
77
- if (buffer.length < 1) {
78
- throw new Error('buffer is empty');
79
- }
80
- if (fullyQualifiedFormat) {
81
- const type_code = cursor.readUInt8();
82
- len++;
83
- if (type_code !== this.ioc.DataType.MAP) {
84
- throw new Error('unexpected {type_code}');
85
- }
86
- cursor = cursor.slice(1);
87
- if (cursor.length < 1) {
88
- throw new Error('{value_flag} is missing');
89
- }
90
- const value_flag = cursor.readUInt8();
91
- len++;
92
- if (value_flag === 0x01) {
93
- return { v: null, len };
94
- }
95
- if (value_flag !== 0x00 && value_flag !== 0x02) {
96
- throw new Error('unexpected {value_flag}');
97
- }
98
- cursor = cursor.slice(1);
99
- }
100
- let length, length_len;
101
- try {
102
- ({ v: length, len: length_len } = this.ioc.intSerializer.deserialize(cursor, false));
103
- len += length_len;
104
- }
105
- catch (err) {
106
- err.message = '{length}: ' + err.message;
107
- throw err;
108
- }
109
- if (length < 0) {
110
- throw new Error('{length} is less than zero');
111
- }
112
- cursor = cursor.slice(length_len);
113
- const v = new Map();
114
- for (let i = 0; i < length; i++) {
115
- let key, key_len;
116
- try {
117
- ({ v: key, len: key_len } = this.ioc.anySerializer.deserialize(cursor));
118
- len += key_len;
119
- }
120
- catch (err) {
121
- err.message = `{item_${i}} key: ` + err.message;
122
- throw err;
123
- }
124
- cursor = cursor.slice(key_len);
125
- let value, value_len;
126
- try {
127
- ({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
128
- len += value_len;
129
- }
130
- catch (err) {
131
- err.message = `{item_${i}} value: ` + err.message;
132
- throw err;
133
- }
134
- cursor = cursor.slice(value_len);
135
- v.set(key, value);
136
- }
137
- return { v, len };
70
+ /**
71
+ * Async deserialization of map value bytes from a StreamReader.
72
+ * @param {StreamReader} reader
73
+ * @param {number} valueFlag
74
+ * @param {number} typeCode
75
+ * @returns {Promise<Map>}
76
+ */
77
+ async deserializeValue(reader, valueFlag, typeCode) {
78
+ const length = await this.ioc.intSerializer.deserializeBare(reader);
79
+ if (length < 0) {
80
+ throw new Error(`MapSerializer: {length}=${length} is less than zero`);
81
+ }
82
+ const v = new Map();
83
+ for (let i = 0; i < length; i++) {
84
+ const key = await this.ioc.anySerializer.deserialize(reader);
85
+ const value = await this.ioc.anySerializer.deserialize(reader);
86
+ v.set(key, value);
87
+ }
88
+ return v;
89
+ }
90
+ /**
91
+ * Async fully-qualified deserialization from a StreamReader.
92
+ * @param {StreamReader} reader
93
+ * @returns {Promise<Map|null>}
94
+ */
95
+ async deserialize(reader) {
96
+ const type_code = await reader.readUInt8();
97
+ if (type_code !== this.ioc.DataType.MAP) {
98
+ throw new Error(`MapSerializer: unexpected {type_code}=0x${type_code.toString(16)}`);
99
+ }
100
+ const value_flag = await reader.readUInt8();
101
+ if (value_flag === 0x01) {
102
+ return null;
138
103
  }
139
- catch (err) {
140
- throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
104
+ if (value_flag !== 0x00 && value_flag !== 0x02) {
105
+ throw new Error(`MapSerializer: unexpected {value_flag}=0x${value_flag.toString(16)}`);
141
106
  }
107
+ return this.deserializeValue(reader, value_flag, type_code);
142
108
  }
143
109
  }
144
110
  exports.default = MapSerializer;
@@ -3,11 +3,18 @@ export default class MapSerializer {
3
3
  ioc: any;
4
4
  canBeUsedFor(value: any): boolean;
5
5
  serialize(item: any, fullyQualifiedFormat?: boolean): any;
6
- deserialize(buffer: any, fullyQualifiedFormat?: boolean, ...args: any[]): {
7
- v: null;
8
- len: number;
9
- } | {
10
- v: Map<any, any>;
11
- len: number;
12
- };
6
+ /**
7
+ * Async deserialization of map value bytes from a StreamReader.
8
+ * @param {StreamReader} reader
9
+ * @param {number} valueFlag
10
+ * @param {number} typeCode
11
+ * @returns {Promise<Map>}
12
+ */
13
+ deserializeValue(reader: StreamReader, valueFlag: number, typeCode: number): Promise<Map<any, any>>;
14
+ /**
15
+ * Async fully-qualified deserialization from a StreamReader.
16
+ * @param {StreamReader} reader
17
+ * @returns {Promise<Map|null>}
18
+ */
19
+ deserialize(reader: StreamReader): Promise<Map<any, any> | null>;
13
20
  }
@@ -18,46 +18,43 @@
18
18
  * under the License.
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- const buffer_1 = require("node:buffer");
21
+ exports.END_OF_STREAM = void 0;
22
+ exports.END_OF_STREAM = Symbol('EndOfStream');
22
23
  class MarkerSerializer {
23
24
  constructor(ioc) {
24
25
  this.ioc = ioc;
25
26
  this.ioc.serializers[ioc.DataType.MARKER] = this;
26
27
  }
27
- deserialize(buffer, fullyQualifiedFormat = true) {
28
- let len = 0;
29
- let cursor = buffer;
30
- try {
31
- if (buffer === undefined || buffer === null || !(buffer instanceof buffer_1.Buffer)) {
32
- throw new Error('buffer is missing');
33
- }
34
- if (buffer.length < (fullyQualifiedFormat ? 3 : 1)) {
35
- throw new Error('buffer is too short for marker');
36
- }
37
- if (fullyQualifiedFormat) {
38
- const type_code = cursor.readUInt8();
39
- len++;
40
- if (type_code !== this.ioc.DataType.MARKER) {
41
- throw new Error('unexpected {type_code}');
42
- }
43
- cursor = cursor.slice(1);
44
- const value_flag = cursor.readUInt8();
45
- len++;
46
- if (value_flag !== 0) {
47
- throw new Error('unexpected {value_flag}');
48
- }
49
- cursor = cursor.slice(1);
50
- }
51
- const value = cursor.readUInt8();
52
- len++;
53
- if (value !== 0) {
54
- throw new Error('unexpected marker value');
55
- }
56
- return { v: 'marker', len };
28
+ /**
29
+ * @param {StreamReader} reader
30
+ * @param {number} valueFlag - already consumed by AnySerializer
31
+ * @returns {Promise<symbol>}
32
+ */
33
+ async deserializeValue(reader, valueFlag) {
34
+ const value = await reader.readUInt8();
35
+ if (value !== 0) {
36
+ throw new Error(`unexpected marker value: ${value}`);
57
37
  }
58
- catch (err) {
59
- throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
38
+ return exports.END_OF_STREAM;
39
+ }
40
+ /**
41
+ * Async fully-qualified deserialization from a StreamReader.
42
+ * @param {StreamReader} reader
43
+ * @returns {Promise<symbol|null>}
44
+ */
45
+ async deserialize(reader) {
46
+ const type_code = await reader.readUInt8();
47
+ if (type_code !== this.ioc.DataType.MARKER) {
48
+ throw new Error(`MarkerSerializer: unexpected {type_code}=0x${type_code.toString(16)}`);
49
+ }
50
+ const value_flag = await reader.readUInt8();
51
+ if (value_flag === 0x01) {
52
+ return null;
53
+ }
54
+ if (value_flag !== 0x00) {
55
+ throw new Error(`MarkerSerializer: unexpected {value_flag}=0x${value_flag.toString(16)}`);
60
56
  }
57
+ return this.deserializeValue(reader, value_flag);
61
58
  }
62
59
  }
63
60
  exports.default = MarkerSerializer;
@@ -1,8 +1,17 @@
1
+ export const END_OF_STREAM: unique symbol;
1
2
  export default class MarkerSerializer {
2
3
  constructor(ioc: any);
3
4
  ioc: any;
4
- deserialize(buffer: any, fullyQualifiedFormat?: boolean, ...args: any[]): {
5
- v: string;
6
- len: number;
7
- };
5
+ /**
6
+ * @param {StreamReader} reader
7
+ * @param {number} valueFlag - already consumed by AnySerializer
8
+ * @returns {Promise<symbol>}
9
+ */
10
+ deserializeValue(reader: StreamReader, valueFlag: number): Promise<symbol>;
11
+ /**
12
+ * Async fully-qualified deserialization from a StreamReader.
13
+ * @param {StreamReader} reader
14
+ * @returns {Promise<symbol|null>}
15
+ */
16
+ deserialize(reader: StreamReader): Promise<symbol | null>;
8
17
  }
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  /**
22
22
  * @author Igor Ostapenko
23
23
  */
24
+ const utils_js_1 = require("../../../../utils.cjs");
24
25
  // Based on GraphSON NumberSerializer.serialize().
25
26
  // It's tested by AnySerializer.serialize() tests.
26
27
  class NumberSerializationStrategy {
@@ -28,6 +29,14 @@ class NumberSerializationStrategy {
28
29
  this.ioc = ioc;
29
30
  }
30
31
  canBeUsedFor(value) {
32
+ if (value instanceof utils_js_1.Long ||
33
+ value instanceof utils_js_1.Int ||
34
+ value instanceof utils_js_1.Float ||
35
+ value instanceof utils_js_1.Double ||
36
+ value instanceof utils_js_1.Short ||
37
+ value instanceof utils_js_1.Byte) {
38
+ return true;
39
+ }
31
40
  if (Number.isNaN(value) || value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) {
32
41
  return true;
33
42
  }
@@ -40,6 +49,24 @@ class NumberSerializationStrategy {
40
49
  return false;
41
50
  }
42
51
  serialize(item, fullyQualifiedFormat = true) {
52
+ if (item instanceof utils_js_1.Float) {
53
+ return this.ioc.floatSerializer.serialize(item.value, fullyQualifiedFormat);
54
+ }
55
+ if (item instanceof utils_js_1.Double) {
56
+ return this.ioc.doubleSerializer.serialize(item.value, fullyQualifiedFormat);
57
+ }
58
+ if (item instanceof utils_js_1.Int) {
59
+ return this.ioc.intSerializer.serialize(item.value, fullyQualifiedFormat);
60
+ }
61
+ if (item instanceof utils_js_1.Long) {
62
+ return this.ioc.longSerializer.serialize(item.value, fullyQualifiedFormat);
63
+ }
64
+ if (item instanceof utils_js_1.Short) {
65
+ return this.ioc.shortSerializer.serialize(item.value, fullyQualifiedFormat);
66
+ }
67
+ if (item instanceof utils_js_1.Byte) {
68
+ return this.ioc.byteSerializer.serialize(item.value, fullyQualifiedFormat);
69
+ }
43
70
  if (typeof item === 'number') {
44
71
  if (Number.isNaN(item) ||
45
72
  item === Number.POSITIVE_INFINITY ||
@@ -48,8 +75,7 @@ class NumberSerializationStrategy {
48
75
  Object.is(item, -0)) {
49
76
  return this.ioc.doubleSerializer.serialize(item, fullyQualifiedFormat);
50
77
  }
51
- if (item >= -2147483648 && item <= 2147483647) {
52
- // INT32_MIN/MAX
78
+ if (item >= utils_js_1.INT32_MIN && item <= utils_js_1.INT32_MAX) {
53
79
  return this.ioc.intSerializer.serialize(item, fullyQualifiedFormat);
54
80
  }
55
81
  if (item >= Number.MIN_SAFE_INTEGER && item <= Number.MAX_SAFE_INTEGER) {
@@ -1,6 +1,3 @@
1
- /**
2
- * @author Igor Ostapenko
3
- */
4
1
  export default class NumberSerializationStrategy {
5
2
  constructor(ioc: any);
6
3
  ioc: any;
@@ -51,63 +51,38 @@ class PathSerializer {
51
51
  bufs.push(this.ioc.listSerializer.serialize(item.objects));
52
52
  return buffer_1.Buffer.concat(bufs);
53
53
  }
54
- deserialize(buffer, fullyQualifiedFormat = true) {
55
- let len = 0;
56
- let cursor = buffer;
57
- try {
58
- if (buffer === undefined || buffer === null || !(buffer instanceof buffer_1.Buffer)) {
59
- throw new Error('buffer is missing');
60
- }
61
- if (buffer.length < 1) {
62
- throw new Error('buffer is empty');
63
- }
64
- if (fullyQualifiedFormat) {
65
- const type_code = cursor.readUInt8();
66
- len++;
67
- if (type_code !== this.ioc.DataType.PATH) {
68
- throw new Error('unexpected {type_code}');
69
- }
70
- cursor = cursor.slice(1);
71
- if (cursor.length < 1) {
72
- throw new Error('{value_flag} is missing');
73
- }
74
- const value_flag = cursor.readUInt8();
75
- len++;
76
- if (value_flag === 1) {
77
- return { v: null, len };
78
- }
79
- if (value_flag !== 0) {
80
- throw new Error('unexpected {value_flag}');
81
- }
82
- cursor = cursor.slice(1);
83
- }
84
- let labels, labels_len;
85
- try {
86
- ({ v: labels, len: labels_len } = this.ioc.listSerializer.deserialize(cursor));
87
- len += labels_len;
88
- }
89
- catch (err) {
90
- err.message = '{labels}: ' + err.message;
91
- throw err;
92
- }
93
- // TODO: should we check content of labels to make sure it's List< Set<String> > ?
94
- cursor = cursor.slice(labels_len);
95
- let objects, objects_len;
96
- try {
97
- ({ v: objects, len: objects_len } = this.ioc.listSerializer.deserialize(cursor));
98
- len += objects_len;
99
- }
100
- catch (err) {
101
- err.message = '{objects}: ' + err.message;
102
- throw err;
103
- }
104
- cursor = cursor.slice(objects_len);
105
- const v = new graph_js_1.Path(labels, objects);
106
- return { v, len };
54
+ /**
55
+ * Async deserialization of path value bytes from a StreamReader.
56
+ * @param {StreamReader} reader
57
+ * @param {number} valueFlag
58
+ * @param {number} typeCode
59
+ * @returns {Promise<Path>}
60
+ */
61
+ async deserializeValue(reader, valueFlag, typeCode) {
62
+ // {labels} fully qualified list
63
+ const labels = await this.ioc.anySerializer.deserialize(reader);
64
+ // {objects} fully qualified list
65
+ const objects = await this.ioc.anySerializer.deserialize(reader);
66
+ return new graph_js_1.Path(labels, objects);
67
+ }
68
+ /**
69
+ * Async fully-qualified deserialization from a StreamReader.
70
+ * @param {StreamReader} reader
71
+ * @returns {Promise<Path|null>}
72
+ */
73
+ async deserialize(reader) {
74
+ const type_code = await reader.readUInt8();
75
+ if (type_code !== this.ioc.DataType.PATH) {
76
+ throw new Error(`PathSerializer: unexpected {type_code}=0x${type_code.toString(16)}`);
77
+ }
78
+ const value_flag = await reader.readUInt8();
79
+ if (value_flag === 0x01) {
80
+ return null;
107
81
  }
108
- catch (err) {
109
- throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
82
+ if (value_flag !== 0x00) {
83
+ throw new Error(`PathSerializer: unexpected {value_flag}=0x${value_flag.toString(16)}`);
110
84
  }
85
+ return this.deserializeValue(reader, value_flag, type_code);
111
86
  }
112
87
  }
113
88
  exports.default = PathSerializer;
@@ -3,13 +3,20 @@ export default class PathSerializer {
3
3
  ioc: any;
4
4
  canBeUsedFor(value: any): value is Path;
5
5
  serialize(item: any, fullyQualifiedFormat?: boolean): Buffer<ArrayBuffer>;
6
- deserialize(buffer: any, fullyQualifiedFormat?: boolean, ...args: any[]): {
7
- v: null;
8
- len: number;
9
- } | {
10
- v: Path;
11
- len: number;
12
- };
6
+ /**
7
+ * Async deserialization of path value bytes from a StreamReader.
8
+ * @param {StreamReader} reader
9
+ * @param {number} valueFlag
10
+ * @param {number} typeCode
11
+ * @returns {Promise<Path>}
12
+ */
13
+ deserializeValue(reader: StreamReader, valueFlag: number, typeCode: number): Promise<Path>;
14
+ /**
15
+ * Async fully-qualified deserialization from a StreamReader.
16
+ * @param {StreamReader} reader
17
+ * @returns {Promise<Path|null>}
18
+ */
19
+ deserialize(reader: StreamReader): Promise<Path | null>;
13
20
  }
14
21
  import { Path } from '../../../graph.cjs';
15
22
  import { Buffer } from 'buffer';