gremlin 3.5.1 → 3.5.4

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 (128) hide show
  1. package/.eslintrc.js +155 -0
  2. package/.prettierrc.js +29 -0
  3. package/Gruntfile.js +15 -16
  4. package/doc/AnonymousTraversalSource.html +5 -5
  5. package/doc/Authenticator.html +2 -2
  6. package/doc/Bytecode.html +7 -7
  7. package/doc/Client.html +138 -64
  8. package/doc/Connection.html +93 -9
  9. package/doc/DriverRemoteConnection.html +11 -11
  10. package/doc/EdgeLabelVerificationStrategy.html +3 -3
  11. package/doc/Graph.html +2 -2
  12. package/doc/GraphSON2Reader.html +4 -4
  13. package/doc/GraphSON2Writer.html +3 -3
  14. package/doc/GraphSON3Reader.html +3 -3
  15. package/doc/GraphSON3Writer.html +3 -3
  16. package/doc/GraphTraversal.html +107 -107
  17. package/doc/GraphTraversalSource.html +19 -19
  18. package/doc/HaltedTraverserStrategy.html +3 -3
  19. package/doc/MatchAlgorithmStrategy.html +3 -3
  20. package/doc/P.html +13 -13
  21. package/doc/PartitionStrategy.html +3 -3
  22. package/doc/Path.html +2 -2
  23. package/doc/PlainTextSaslAuthenticator.html +2 -2
  24. package/doc/ProductiveByStrategy.html +288 -0
  25. package/doc/RemoteConnection.html +10 -10
  26. package/doc/RemoteStrategy.html +4 -4
  27. package/doc/RemoteTraversal.html +3 -3
  28. package/doc/ReservedKeysVerificationStrategy.html +3 -3
  29. package/doc/ResponseError.html +2 -2
  30. package/doc/ResultSet.html +7 -7
  31. package/doc/SaslAuthenticator.html +2 -2
  32. package/doc/SaslMechanismBase.html +2 -2
  33. package/doc/SaslMechanismPlain.html +6 -6
  34. package/doc/SeedStrategy.html +288 -0
  35. package/doc/SubgraphStrategy.html +3 -3
  36. package/doc/TextP.html +10 -10
  37. package/doc/Transaction.html +6 -6
  38. package/doc/Translator.html +198 -4
  39. package/doc/TraversalStrategies.html +5 -5
  40. package/doc/TraversalStrategy.html +3 -3
  41. package/doc/TypeSerializer.html +2 -2
  42. package/doc/driver_auth_authenticator.js.html +4 -4
  43. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +3 -3
  44. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +26 -17
  45. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +7 -7
  46. package/doc/driver_auth_sasl-authenticator.js.html +3 -3
  47. package/doc/driver_client.js.html +73 -23
  48. package/doc/driver_connection.js.html +134 -92
  49. package/doc/driver_driver-remote-connection.js.html +12 -11
  50. package/doc/driver_remote-connection.js.html +4 -5
  51. package/doc/driver_response-error.js.html +5 -4
  52. package/doc/driver_result-set.js.html +4 -4
  53. package/doc/global.html +264 -3
  54. package/doc/index.html +2 -2
  55. package/doc/module.exports.html +301 -0
  56. package/doc/process_anonymous-traversal.js.html +4 -4
  57. package/doc/process_bytecode.js.html +11 -9
  58. package/doc/process_graph-traversal.js.html +194 -143
  59. package/doc/process_transaction.js.html +16 -9
  60. package/doc/process_translator.js.html +53 -37
  61. package/doc/process_traversal-strategy.js.html +70 -53
  62. package/doc/process_traversal.js.html +101 -108
  63. package/doc/structure_graph.js.html +7 -7
  64. package/doc/structure_io_binary_internals_DataType.js.html +148 -0
  65. package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +131 -0
  66. package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +134 -0
  67. package/doc/structure_io_graph-serializer.js.html +65 -18
  68. package/doc/structure_io_type-serializers.js.html +86 -89
  69. package/index.js +5 -5
  70. package/lib/driver/auth/authenticator.js +2 -2
  71. package/lib/driver/auth/mechanisms/sasl-mechanism-base.js +1 -1
  72. package/lib/driver/auth/mechanisms/sasl-mechanism-plain.js +24 -15
  73. package/lib/driver/auth/plain-text-sasl-authenticator.js +5 -5
  74. package/lib/driver/auth/sasl-authenticator.js +1 -1
  75. package/lib/driver/client.js +71 -21
  76. package/lib/driver/connection.js +132 -90
  77. package/lib/driver/driver-remote-connection.js +10 -9
  78. package/lib/driver/remote-connection.js +2 -3
  79. package/lib/driver/response-error.js +2 -2
  80. package/lib/driver/result-set.js +1 -2
  81. package/lib/process/anonymous-traversal.js +1 -2
  82. package/lib/process/bytecode.js +9 -7
  83. package/lib/process/graph-traversal.js +191 -141
  84. package/lib/process/transaction.js +13 -7
  85. package/lib/process/translator.js +50 -35
  86. package/lib/process/traversal-strategy.js +67 -51
  87. package/lib/process/traversal.js +99 -106
  88. package/lib/structure/graph.js +5 -5
  89. package/lib/structure/io/binary/GraphBinary.js +109 -0
  90. package/lib/structure/io/binary/internals/AnySerializer.js +95 -0
  91. package/lib/structure/io/binary/internals/ArraySerializer.js +135 -0
  92. package/lib/structure/io/binary/internals/BigIntegerSerializer.js +151 -0
  93. package/lib/structure/io/binary/internals/BooleanSerializer.js +103 -0
  94. package/lib/structure/io/binary/internals/BulkSetSerializer.js +124 -0
  95. package/lib/structure/io/binary/internals/ByteBufferSerializer.js +124 -0
  96. package/lib/structure/io/binary/internals/ByteSerializer.js +95 -0
  97. package/lib/structure/io/binary/internals/BytecodeSerializer.js +249 -0
  98. package/lib/structure/io/binary/internals/DataType.js +97 -0
  99. package/lib/structure/io/binary/internals/DateSerializer.js +103 -0
  100. package/lib/structure/io/binary/internals/DoubleSerializer.js +99 -0
  101. package/lib/structure/io/binary/internals/EdgeSerializer.js +215 -0
  102. package/lib/structure/io/binary/internals/EnumSerializer.js +148 -0
  103. package/lib/structure/io/binary/internals/FloatSerializer.js +99 -0
  104. package/lib/structure/io/binary/internals/GraphBinaryReader.js +80 -0
  105. package/lib/structure/io/binary/internals/GraphBinaryWriter.js +83 -0
  106. package/lib/structure/io/binary/internals/IntSerializer.js +112 -0
  107. package/lib/structure/io/binary/internals/LambdaSerializer.js +70 -0
  108. package/lib/structure/io/binary/internals/LongSerializer.js +107 -0
  109. package/lib/structure/io/binary/internals/LongSerializerNg.js +102 -0
  110. package/lib/structure/io/binary/internals/MapSerializer.js +153 -0
  111. package/lib/structure/io/binary/internals/NumberSerializationStrategy.js +68 -0
  112. package/lib/structure/io/binary/internals/PSerializer.js +151 -0
  113. package/lib/structure/io/binary/internals/PathSerializer.js +123 -0
  114. package/lib/structure/io/binary/internals/PropertySerializer.js +141 -0
  115. package/lib/structure/io/binary/internals/ShortSerializer.js +99 -0
  116. package/lib/structure/io/binary/internals/StringSerializer.js +114 -0
  117. package/lib/structure/io/binary/internals/TextPSerializer.js +145 -0
  118. package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +72 -0
  119. package/lib/structure/io/binary/internals/TraverserSerializer.js +123 -0
  120. package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +75 -0
  121. package/lib/structure/io/binary/internals/UuidSerializer.js +119 -0
  122. package/lib/structure/io/binary/internals/VertexPropertySerializer.js +172 -0
  123. package/lib/structure/io/binary/internals/VertexSerializer.js +135 -0
  124. package/lib/structure/io/binary/internals/utils.js +59 -0
  125. package/lib/structure/io/graph-serializer.js +62 -16
  126. package/lib/structure/io/type-serializers.js +84 -87
  127. package/lib/utils.js +15 -10
  128. package/package.json +21 -8
@@ -0,0 +1,95 @@
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
+ /**
21
+ * @author Igor Ostapenko
22
+ */
23
+ 'use strict';
24
+
25
+ module.exports = class ByteSerializer {
26
+ constructor(ioc) {
27
+ this.ioc = ioc;
28
+ this.ioc.serializers[ioc.DataType.BYTE] = this;
29
+ }
30
+
31
+ serialize(item, fullyQualifiedFormat = true) {
32
+ if (item === undefined || item === null) {
33
+ if (fullyQualifiedFormat) {
34
+ return Buffer.from([this.ioc.DataType.BYTE, 0x01]);
35
+ }
36
+ return Buffer.from([0x00]);
37
+ }
38
+
39
+ const bufs = [];
40
+ if (fullyQualifiedFormat) {
41
+ bufs.push(Buffer.from([this.ioc.DataType.BYTE, 0x00]));
42
+ }
43
+ const v = Buffer.alloc(1);
44
+ v.writeUInt8(item); // if item is not within uint8 limits writeUInt8 will error
45
+ bufs.push(v);
46
+
47
+ return Buffer.concat(bufs);
48
+ }
49
+
50
+ deserialize(buffer, fullyQualifiedFormat = true) {
51
+ let len = 0;
52
+ let cursor = buffer;
53
+
54
+ try {
55
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
56
+ throw new Error('buffer is missing');
57
+ }
58
+ if (buffer.length < 1) {
59
+ throw new Error('buffer is empty');
60
+ }
61
+
62
+ if (fullyQualifiedFormat) {
63
+ const type_code = cursor.readUInt8();
64
+ len++;
65
+ if (type_code !== this.ioc.DataType.BYTE) {
66
+ throw new Error('unexpected {type_code}');
67
+ }
68
+ cursor = cursor.slice(1);
69
+
70
+ if (cursor.length < 1) {
71
+ throw new Error('{value_flag} is missing');
72
+ }
73
+ const value_flag = cursor.readUInt8();
74
+ len++;
75
+ if (value_flag === 1) {
76
+ return { v: null, len };
77
+ }
78
+ if (value_flag !== 0) {
79
+ throw new Error('unexpected {value_flag}');
80
+ }
81
+ cursor = cursor.slice(1);
82
+ }
83
+
84
+ if (cursor.length < 1) {
85
+ throw new Error('unexpected {value} length');
86
+ }
87
+ len += 1;
88
+
89
+ const v = cursor.readUInt8();
90
+ return { v, len };
91
+ } catch (err) {
92
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
93
+ }
94
+ }
95
+ };
@@ -0,0 +1,249 @@
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
+ /**
21
+ * @author Igor Ostapenko
22
+ */
23
+ 'use strict';
24
+
25
+ const Bytecode = require('../../../../process/bytecode');
26
+ const t = require('../../../../process/traversal');
27
+
28
+ module.exports = class BytecodeSerializer {
29
+ constructor(ioc) {
30
+ this.ioc = ioc;
31
+ this.ioc.serializers[ioc.DataType.BYTECODE] = this;
32
+ }
33
+
34
+ canBeUsedFor(value) {
35
+ return value instanceof Bytecode || value instanceof t.Traversal;
36
+ }
37
+
38
+ serialize(item, fullyQualifiedFormat = true) {
39
+ if (item === undefined || item === null) {
40
+ if (fullyQualifiedFormat) {
41
+ return Buffer.from([this.ioc.DataType.BYTECODE, 0x01]);
42
+ }
43
+ const steps_length = [0x00, 0x00, 0x00, 0x00]; // 0
44
+ const sources_length = [0x00, 0x00, 0x00, 0x00]; // 0
45
+ return Buffer.from([...steps_length, ...sources_length]);
46
+ }
47
+
48
+ if (item instanceof t.Traversal) {
49
+ item = item.getBytecode();
50
+ }
51
+
52
+ const bufs = [];
53
+ if (fullyQualifiedFormat) {
54
+ bufs.push(Buffer.from([this.ioc.DataType.BYTECODE, 0x00]));
55
+ }
56
+
57
+ // {steps_length}{step_0}...{step_n}
58
+ bufs.push(this.ioc.intSerializer.serialize(item.stepInstructions.length, false)); // TODO: what if steps_length > INT32_MAX
59
+ for (let i = 0; i < item.stepInstructions.length; i++) {
60
+ // {step_i} is composed of {name}{values_length}{value_0}...{value_n}
61
+ const step = item.stepInstructions[i];
62
+ const name = step[0];
63
+ const values_length = step.length - 1;
64
+ bufs.push(this.ioc.stringSerializer.serialize(name, false));
65
+ bufs.push(this.ioc.intSerializer.serialize(values_length, false));
66
+ for (let j = 0; j < values_length; j++) {
67
+ bufs.push(this.ioc.anySerializer.serialize(step[1 + j], true));
68
+ }
69
+ }
70
+
71
+ // {sources_length}{source_0}...{source_n}
72
+ bufs.push(this.ioc.intSerializer.serialize(item.sourceInstructions.length, false)); // TODO: what if sources_length > INT32_MAX
73
+ for (let i = 0; i < item.sourceInstructions.length; i++) {
74
+ // {source_i} is composed of {name}{values_length}{value_0}...{value_n}
75
+ const source = item.sourceInstructions[i];
76
+ const name = source[0];
77
+ const values_length = source.length - 1;
78
+ bufs.push(this.ioc.stringSerializer.serialize(name, false));
79
+ bufs.push(this.ioc.intSerializer.serialize(values_length, false));
80
+ for (let j = 0; j < values_length; j++) {
81
+ bufs.push(this.ioc.anySerializer.serialize(source[1 + j], true));
82
+ }
83
+ }
84
+
85
+ return Buffer.concat(bufs);
86
+ }
87
+
88
+ deserialize(buffer, fullyQualifiedFormat = true) {
89
+ let len = 0;
90
+ let cursor = buffer;
91
+
92
+ try {
93
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
94
+ throw new Error('buffer is missing');
95
+ }
96
+ if (buffer.length < 1) {
97
+ throw new Error('buffer is empty');
98
+ }
99
+
100
+ if (fullyQualifiedFormat) {
101
+ const type_code = cursor.readUInt8();
102
+ len++;
103
+ if (type_code !== this.ioc.DataType.BYTECODE) {
104
+ throw new Error('unexpected {type_code}');
105
+ }
106
+ cursor = cursor.slice(1);
107
+
108
+ if (cursor.length < 1) {
109
+ throw new Error('{value_flag} is missing');
110
+ }
111
+ const value_flag = cursor.readUInt8();
112
+ len++;
113
+ if (value_flag === 1) {
114
+ return { v: null, len };
115
+ }
116
+ if (value_flag !== 0) {
117
+ throw new Error('unexpected {value_flag}');
118
+ }
119
+ cursor = cursor.slice(1);
120
+ }
121
+
122
+ const v = new Bytecode();
123
+
124
+ // steps
125
+
126
+ let steps_length, steps_length_len;
127
+ try {
128
+ ({ v: steps_length, len: steps_length_len } = this.ioc.intSerializer.deserialize(cursor, false));
129
+ len += steps_length_len;
130
+ } catch (err) {
131
+ err.message = '{steps_length}: ' + err.message;
132
+ throw err;
133
+ }
134
+ if (steps_length < 0) {
135
+ throw new Error('{steps_length} is less than zero');
136
+ }
137
+ cursor = cursor.slice(steps_length_len);
138
+
139
+ // {step_i} is composed of {name}{values_length}{value_0}...{value_n}
140
+ for (let i = 0; i < steps_length; i++) {
141
+ // {name} is a String
142
+ let name, name_len;
143
+ try {
144
+ ({ v: name, len: name_len } = this.ioc.stringSerializer.deserialize(cursor, false));
145
+ len += name_len;
146
+ } catch (err) {
147
+ err.message = `{step_${i}} {name}: ` + err.message;
148
+ throw err;
149
+ }
150
+ cursor = cursor.slice(name_len);
151
+
152
+ // {values_length} is an Int describing the amount values
153
+ let values_length, values_length_len;
154
+ try {
155
+ ({ v: values_length, len: values_length_len } = this.ioc.intSerializer.deserialize(cursor, false));
156
+ len += values_length_len;
157
+ } catch (err) {
158
+ err.message = `{step_${i}} {values_length}: ` + err.message;
159
+ throw err;
160
+ }
161
+ if (values_length < 0) {
162
+ throw new Error(`{step_${i}} {values_length} is less than zero`);
163
+ }
164
+ cursor = cursor.slice(values_length_len);
165
+
166
+ // {value_i} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value} describing the step argument
167
+ const values = [];
168
+ let value, value_len;
169
+ for (let j = 0; j < values_length; j++) {
170
+ try {
171
+ ({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
172
+ len += value_len;
173
+ values.push(value);
174
+ } catch (err) {
175
+ err.message = `{step_${i}} {value_${j}}: ` + err.message;
176
+ throw err;
177
+ }
178
+ cursor = cursor.slice(value_len);
179
+ }
180
+
181
+ v.addStep(name, values);
182
+ }
183
+
184
+ // sources
185
+
186
+ let sources_length, sources_length_len;
187
+ try {
188
+ ({ v: sources_length, len: sources_length_len } = this.ioc.intSerializer.deserialize(cursor, false));
189
+ len += sources_length_len;
190
+ } catch (err) {
191
+ err.message = '{sources_length}: ' + err.message;
192
+ throw err;
193
+ }
194
+ if (sources_length < 0) {
195
+ throw new Error('{sources_length} is less than zero');
196
+ }
197
+ cursor = cursor.slice(sources_length_len);
198
+
199
+ // {source_i} is composed of {name}{values_length}{value_0}...{value_n}
200
+ for (let i = 0; i < sources_length; i++) {
201
+ // {name} is a String
202
+ let name, name_len;
203
+ try {
204
+ ({ v: name, len: name_len } = this.ioc.stringSerializer.deserialize(cursor, false));
205
+ len += name_len;
206
+ } catch (err) {
207
+ err.message = `{source_${i}} {name}: ` + err.message;
208
+ throw err;
209
+ }
210
+ cursor = cursor.slice(name_len);
211
+
212
+ // {values_length} is an Int describing the amount values
213
+ let values_length, values_length_len;
214
+ try {
215
+ ({ v: values_length, len: values_length_len } = this.ioc.intSerializer.deserialize(cursor, false));
216
+ len += values_length_len;
217
+ } catch (err) {
218
+ err.message = `{source_${i}} {values_length}: ` + err.message;
219
+ throw err;
220
+ }
221
+ if (values_length < 0) {
222
+ throw new Error(`{source_${i}} {values_length} is less than zero`);
223
+ }
224
+ cursor = cursor.slice(values_length_len);
225
+
226
+ // {value_i} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value}
227
+ const values = [];
228
+ let value, value_len;
229
+ for (let j = 0; j < values_length; j++) {
230
+ try {
231
+ ({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
232
+ len += value_len;
233
+ values.push(value);
234
+ } catch (err) {
235
+ err.message = `{source_${i}} {value_${j}}: ` + err.message;
236
+ throw err;
237
+ }
238
+ cursor = cursor.slice(value_len);
239
+ }
240
+
241
+ v.addSource(name, values);
242
+ }
243
+
244
+ return { v, len };
245
+ } catch (err) {
246
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
247
+ }
248
+ }
249
+ };
@@ -0,0 +1,97 @@
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
+ /**
21
+ * @author Igor Ostapenko
22
+ */
23
+ 'use strict';
24
+
25
+ /**
26
+ * Represents a GraphBinary data type.
27
+ *
28
+ * See org.apache.tinkerpop.gremlin.structure.io.binary.DataType Java class.
29
+ */
30
+ const DataType = {
31
+ INT: 0x01,
32
+ LONG: 0x02,
33
+ STRING: 0x03,
34
+ DATE: 0x04,
35
+ TIMESTAMP: 0x05,
36
+ CLASS: 0x06,
37
+ DOUBLE: 0x07,
38
+ FLOAT: 0x08,
39
+ LIST: 0x09,
40
+ MAP: 0x0a,
41
+ SET: 0x0b,
42
+ UUID: 0x0c,
43
+ EDGE: 0x0d,
44
+ PATH: 0x0e,
45
+ PROPERTY: 0x0f,
46
+ GRAPH: 0x10,
47
+ VERTEX: 0x11,
48
+ VERTEXPROPERTY: 0x12,
49
+ BARRIER: 0x13,
50
+ BINDING: 0x14,
51
+ BYTECODE: 0x15,
52
+ CARDINALITY: 0x16,
53
+ COLUMN: 0x17,
54
+ DIRECTION: 0x18,
55
+ OPERATOR: 0x19,
56
+ ORDER: 0x1a,
57
+ PICK: 0x1b,
58
+ POP: 0x1c,
59
+ LAMBDA: 0x1d,
60
+ P: 0x1e,
61
+ SCOPE: 0x1f,
62
+ T: 0x20,
63
+ TRAVERSER: 0x21,
64
+ BIGDECIMAL: 0x22,
65
+ BIGINTEGER: 0x23,
66
+ BYTE: 0x24,
67
+ BYTEBUFFER: 0x25,
68
+ SHORT: 0x26,
69
+ BOOLEAN: 0x27,
70
+ TEXTP: 0x28,
71
+ TRAVERSALSTRATEGY: 0x29,
72
+ BULKSET: 0x2a,
73
+ TREE: 0x2b,
74
+ METRICS: 0x2c,
75
+ TRAVERSALMETRICS: 0x2d,
76
+
77
+ CHAR: 0x80,
78
+ DURATION: 0x81,
79
+ INETADDRESS: 0x82,
80
+ INSTANT: 0x83,
81
+ LOCALDATE: 0x84,
82
+ LOCALDATETIME: 0x85,
83
+ LOCALTIME: 0x86,
84
+ MONTHDAY: 0x87,
85
+ OFFSETDATETIME: 0x88,
86
+ OFFSETTIME: 0x89,
87
+ PERIOD: 0x8a,
88
+ YEAR: 0x8b,
89
+ YEARMONTH: 0x8c,
90
+ ZONEDATETIME: 0x8d,
91
+ ZONEOFFSET: 0x8e,
92
+
93
+ CUSTOM: 0,
94
+ UNSPECIFIED_NULL: 0xfe,
95
+ };
96
+
97
+ module.exports = DataType;
@@ -0,0 +1,103 @@
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
+ /**
21
+ * @author Igor Ostapenko
22
+ */
23
+ 'use strict';
24
+
25
+ module.exports = class DateSerializer {
26
+ constructor(ioc, ID) {
27
+ this.ioc = ioc;
28
+ this.ID = ID;
29
+ this.ioc.serializers[ID] = this;
30
+ }
31
+
32
+ canBeUsedFor(value) {
33
+ return value instanceof Date;
34
+ }
35
+
36
+ serialize(item, fullyQualifiedFormat = true) {
37
+ if (item === undefined || item === null) {
38
+ if (fullyQualifiedFormat) {
39
+ return Buffer.from([this.ID, 0x01]);
40
+ }
41
+ return Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
42
+ }
43
+
44
+ const bufs = [];
45
+ if (fullyQualifiedFormat) {
46
+ bufs.push(Buffer.from([this.ID, 0x00]));
47
+ }
48
+
49
+ const v = Buffer.alloc(8);
50
+ v.writeBigInt64BE(BigInt(item.getTime()));
51
+ bufs.push(v);
52
+
53
+ return Buffer.concat(bufs);
54
+ }
55
+
56
+ deserialize(buffer, fullyQualifiedFormat = true) {
57
+ let len = 0;
58
+ let cursor = buffer;
59
+
60
+ try {
61
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
62
+ throw new Error('buffer is missing');
63
+ }
64
+ if (buffer.length < 1) {
65
+ throw new Error('buffer is empty');
66
+ }
67
+
68
+ if (fullyQualifiedFormat) {
69
+ const type_code = cursor.readUInt8();
70
+ len++;
71
+ if (type_code !== this.ID) {
72
+ throw new Error('unexpected {type_code}');
73
+ }
74
+ cursor = cursor.slice(1);
75
+
76
+ if (cursor.length < 1) {
77
+ throw new Error('{value_flag} is missing');
78
+ }
79
+ const value_flag = cursor.readUInt8();
80
+ len++;
81
+ if (value_flag === 1) {
82
+ return { v: null, len };
83
+ }
84
+ if (value_flag !== 0) {
85
+ throw new Error('unexpected {value_flag}');
86
+ }
87
+ cursor = cursor.slice(1);
88
+ }
89
+
90
+ if (cursor.length < 8) {
91
+ throw new Error('unexpected {value} length');
92
+ }
93
+ len += 8;
94
+
95
+ const ms = cursor.readBigInt64BE();
96
+ const v = new Date(Number(ms));
97
+
98
+ return { v, len };
99
+ } catch (err) {
100
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
101
+ }
102
+ }
103
+ };
@@ -0,0 +1,99 @@
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
+ /**
21
+ * @author Igor Ostapenko
22
+ */
23
+ 'use strict';
24
+
25
+ module.exports = class DoubleSerializer {
26
+ constructor(ioc) {
27
+ this.ioc = ioc;
28
+ this.ioc.serializers[ioc.DataType.DOUBLE] = this;
29
+ }
30
+
31
+ canBeUsedFor(value) {
32
+ return typeof value === 'number' && !Number.isInteger(value);
33
+ }
34
+
35
+ serialize(item, fullyQualifiedFormat = true) {
36
+ if (item === undefined || item === null) {
37
+ if (fullyQualifiedFormat) {
38
+ return Buffer.from([this.ioc.DataType.DOUBLE, 0x01]);
39
+ }
40
+ return Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
41
+ }
42
+
43
+ const bufs = [];
44
+ if (fullyQualifiedFormat) {
45
+ bufs.push(Buffer.from([this.ioc.DataType.DOUBLE, 0x00]));
46
+ }
47
+ const v = Buffer.alloc(8);
48
+ v.writeDoubleBE(item);
49
+ bufs.push(v);
50
+
51
+ return Buffer.concat(bufs);
52
+ }
53
+
54
+ deserialize(buffer, fullyQualifiedFormat = true) {
55
+ let len = 0;
56
+ let cursor = buffer;
57
+
58
+ try {
59
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
60
+ throw new Error('buffer is missing');
61
+ }
62
+ if (buffer.length < 1) {
63
+ throw new Error('buffer is empty');
64
+ }
65
+
66
+ if (fullyQualifiedFormat) {
67
+ const type_code = cursor.readUInt8();
68
+ len++;
69
+ if (type_code !== this.ioc.DataType.DOUBLE) {
70
+ throw new Error('unexpected {type_code}');
71
+ }
72
+ cursor = cursor.slice(1);
73
+
74
+ if (cursor.length < 1) {
75
+ throw new Error('{value_flag} is missing');
76
+ }
77
+ const value_flag = cursor.readUInt8();
78
+ len++;
79
+ if (value_flag === 1) {
80
+ return { v: null, len };
81
+ }
82
+ if (value_flag !== 0) {
83
+ throw new Error('unexpected {value_flag}');
84
+ }
85
+ cursor = cursor.slice(1);
86
+ }
87
+
88
+ if (cursor.length < 8) {
89
+ throw new Error('unexpected {value} length');
90
+ }
91
+ len += 8;
92
+
93
+ const v = cursor.readDoubleBE();
94
+ return { v, len };
95
+ } catch (err) {
96
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
97
+ }
98
+ }
99
+ };