gremlin 3.5.3 → 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 (105) hide show
  1. package/.eslintrc.js +3 -2
  2. package/doc/AnonymousTraversalSource.html +2 -2
  3. package/doc/Authenticator.html +2 -2
  4. package/doc/Bytecode.html +2 -2
  5. package/doc/Client.html +2 -2
  6. package/doc/Connection.html +10 -10
  7. package/doc/DriverRemoteConnection.html +2 -2
  8. package/doc/EdgeLabelVerificationStrategy.html +2 -2
  9. package/doc/Graph.html +2 -2
  10. package/doc/GraphSON2Reader.html +2 -2
  11. package/doc/GraphSON2Writer.html +2 -2
  12. package/doc/GraphSON3Reader.html +2 -2
  13. package/doc/GraphSON3Writer.html +2 -2
  14. package/doc/GraphTraversal.html +2 -2
  15. package/doc/GraphTraversalSource.html +2 -2
  16. package/doc/HaltedTraverserStrategy.html +2 -2
  17. package/doc/MatchAlgorithmStrategy.html +2 -2
  18. package/doc/P.html +2 -2
  19. package/doc/PartitionStrategy.html +2 -2
  20. package/doc/Path.html +2 -2
  21. package/doc/PlainTextSaslAuthenticator.html +2 -2
  22. package/doc/ProductiveByStrategy.html +2 -2
  23. package/doc/RemoteConnection.html +2 -2
  24. package/doc/RemoteStrategy.html +2 -2
  25. package/doc/RemoteTraversal.html +2 -2
  26. package/doc/ReservedKeysVerificationStrategy.html +2 -2
  27. package/doc/ResponseError.html +2 -2
  28. package/doc/ResultSet.html +2 -2
  29. package/doc/SaslAuthenticator.html +2 -2
  30. package/doc/SaslMechanismBase.html +2 -2
  31. package/doc/SaslMechanismPlain.html +2 -2
  32. package/doc/SeedStrategy.html +2 -2
  33. package/doc/SubgraphStrategy.html +2 -2
  34. package/doc/TextP.html +2 -2
  35. package/doc/Transaction.html +2 -2
  36. package/doc/Translator.html +2 -2
  37. package/doc/TraversalStrategies.html +2 -2
  38. package/doc/TraversalStrategy.html +2 -2
  39. package/doc/TypeSerializer.html +2 -2
  40. package/doc/driver_auth_authenticator.js.html +2 -2
  41. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +2 -2
  42. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +2 -2
  43. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +2 -2
  44. package/doc/driver_auth_sasl-authenticator.js.html +2 -2
  45. package/doc/driver_client.js.html +2 -2
  46. package/doc/driver_connection.js.html +32 -9
  47. package/doc/driver_driver-remote-connection.js.html +2 -2
  48. package/doc/driver_remote-connection.js.html +2 -2
  49. package/doc/driver_response-error.js.html +2 -2
  50. package/doc/driver_result-set.js.html +2 -2
  51. package/doc/global.html +66 -2
  52. package/doc/index.html +2 -2
  53. package/doc/module.exports.html +301 -0
  54. package/doc/process_anonymous-traversal.js.html +2 -2
  55. package/doc/process_bytecode.js.html +2 -2
  56. package/doc/process_graph-traversal.js.html +2 -2
  57. package/doc/process_transaction.js.html +2 -2
  58. package/doc/process_translator.js.html +2 -2
  59. package/doc/process_traversal-strategy.js.html +3 -3
  60. package/doc/process_traversal.js.html +2 -2
  61. package/doc/structure_graph.js.html +2 -2
  62. package/doc/structure_io_binary_internals_DataType.js.html +148 -0
  63. package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +131 -0
  64. package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +134 -0
  65. package/doc/structure_io_graph-serializer.js.html +2 -2
  66. package/doc/structure_io_type-serializers.js.html +2 -2
  67. package/lib/driver/connection.js +30 -7
  68. package/lib/process/traversal-strategy.js +1 -1
  69. package/lib/structure/io/binary/GraphBinary.js +109 -0
  70. package/lib/structure/io/binary/internals/AnySerializer.js +95 -0
  71. package/lib/structure/io/binary/internals/ArraySerializer.js +135 -0
  72. package/lib/structure/io/binary/internals/BigIntegerSerializer.js +151 -0
  73. package/lib/structure/io/binary/internals/BooleanSerializer.js +103 -0
  74. package/lib/structure/io/binary/internals/BulkSetSerializer.js +124 -0
  75. package/lib/structure/io/binary/internals/ByteBufferSerializer.js +124 -0
  76. package/lib/structure/io/binary/internals/ByteSerializer.js +95 -0
  77. package/lib/structure/io/binary/internals/BytecodeSerializer.js +249 -0
  78. package/lib/structure/io/binary/internals/DataType.js +97 -0
  79. package/lib/structure/io/binary/internals/DateSerializer.js +103 -0
  80. package/lib/structure/io/binary/internals/DoubleSerializer.js +99 -0
  81. package/lib/structure/io/binary/internals/EdgeSerializer.js +215 -0
  82. package/lib/structure/io/binary/internals/EnumSerializer.js +148 -0
  83. package/lib/structure/io/binary/internals/FloatSerializer.js +99 -0
  84. package/lib/structure/io/binary/internals/GraphBinaryReader.js +80 -0
  85. package/lib/structure/io/binary/internals/GraphBinaryWriter.js +83 -0
  86. package/lib/structure/io/binary/internals/IntSerializer.js +112 -0
  87. package/lib/structure/io/binary/internals/LambdaSerializer.js +70 -0
  88. package/lib/structure/io/binary/internals/LongSerializer.js +107 -0
  89. package/lib/structure/io/binary/internals/LongSerializerNg.js +102 -0
  90. package/lib/structure/io/binary/internals/MapSerializer.js +153 -0
  91. package/lib/structure/io/binary/internals/NumberSerializationStrategy.js +68 -0
  92. package/lib/structure/io/binary/internals/PSerializer.js +151 -0
  93. package/lib/structure/io/binary/internals/PathSerializer.js +123 -0
  94. package/lib/structure/io/binary/internals/PropertySerializer.js +141 -0
  95. package/lib/structure/io/binary/internals/ShortSerializer.js +99 -0
  96. package/lib/structure/io/binary/internals/StringSerializer.js +114 -0
  97. package/lib/structure/io/binary/internals/TextPSerializer.js +145 -0
  98. package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +72 -0
  99. package/lib/structure/io/binary/internals/TraverserSerializer.js +123 -0
  100. package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +75 -0
  101. package/lib/structure/io/binary/internals/UuidSerializer.js +119 -0
  102. package/lib/structure/io/binary/internals/VertexPropertySerializer.js +172 -0
  103. package/lib/structure/io/binary/internals/VertexSerializer.js +135 -0
  104. package/lib/structure/io/binary/internals/utils.js +59 -0
  105. package/package.json +14 -7
@@ -0,0 +1,153 @@
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 MapSerializer {
26
+ constructor(ioc) {
27
+ this.ioc = ioc;
28
+ this.ioc.serializers[ioc.DataType.MAP] = this;
29
+ }
30
+
31
+ canBeUsedFor(value) {
32
+ if (value === null || value === undefined) {
33
+ return false;
34
+ }
35
+ if (value instanceof Map) {
36
+ return true;
37
+ }
38
+ if (Array.isArray(value)) {
39
+ return false;
40
+ }
41
+
42
+ return typeof value === 'object';
43
+ }
44
+
45
+ serialize(item, fullyQualifiedFormat = true) {
46
+ if (item === undefined || item === null) {
47
+ if (fullyQualifiedFormat) {
48
+ return Buffer.from([this.ioc.DataType.MAP, 0x01]);
49
+ }
50
+ return this.ioc.intSerializer.serialize(0, false);
51
+ }
52
+
53
+ const isMap = item instanceof Map;
54
+
55
+ const keys = isMap ? Array.from(item.keys()) : Object.keys(item);
56
+ let map_length = keys.length;
57
+ if (map_length < 0) {
58
+ map_length = 0;
59
+ } else if (map_length > this.ioc.intSerializer.INT32_MAX) {
60
+ map_length = this.ioc.intSerializer.INT32_MAX; // TODO: is it expected to be silenced? or it's better to error instead?
61
+ }
62
+
63
+ const bufs = [];
64
+ if (fullyQualifiedFormat) {
65
+ bufs.push(Buffer.from([this.ioc.DataType.MAP, 0x00]));
66
+ }
67
+ bufs.push(this.ioc.intSerializer.serialize(map_length, false));
68
+ for (let i = 0; i < map_length; i++) {
69
+ const key = keys[i];
70
+ const value = isMap ? item.get(key) : item[key];
71
+ bufs.push(this.ioc.anySerializer.serialize(key), this.ioc.anySerializer.serialize(value));
72
+ }
73
+ return Buffer.concat(bufs);
74
+ }
75
+
76
+ deserialize(buffer, fullyQualifiedFormat = true) {
77
+ let len = 0;
78
+ let cursor = buffer;
79
+
80
+ try {
81
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
82
+ throw new Error('buffer is missing');
83
+ }
84
+ if (buffer.length < 1) {
85
+ throw new Error('buffer is empty');
86
+ }
87
+
88
+ if (fullyQualifiedFormat) {
89
+ const type_code = cursor.readUInt8();
90
+ len++;
91
+ if (type_code !== this.ioc.DataType.MAP) {
92
+ throw new Error('unexpected {type_code}');
93
+ }
94
+ cursor = cursor.slice(1);
95
+
96
+ if (cursor.length < 1) {
97
+ throw new Error('{value_flag} is missing');
98
+ }
99
+ const value_flag = cursor.readUInt8();
100
+ len++;
101
+ if (value_flag === 1) {
102
+ return { v: null, len };
103
+ }
104
+ if (value_flag !== 0) {
105
+ throw new Error('unexpected {value_flag}');
106
+ }
107
+ cursor = cursor.slice(1);
108
+ }
109
+
110
+ let length, length_len;
111
+ try {
112
+ ({ v: length, len: length_len } = this.ioc.intSerializer.deserialize(cursor, false));
113
+ len += length_len;
114
+ } catch (err) {
115
+ err.message = '{length}: ' + err.message;
116
+ throw err;
117
+ }
118
+ if (length < 0) {
119
+ throw new Error('{length} is less than zero');
120
+ }
121
+ cursor = cursor.slice(length_len);
122
+
123
+ const v = new Map();
124
+ for (let i = 0; i < length; i++) {
125
+ let key, key_len;
126
+ try {
127
+ ({ v: key, len: key_len } = this.ioc.anySerializer.deserialize(cursor));
128
+ len += key_len;
129
+ } catch (err) {
130
+ err.message = `{item_${i}} key: ` + err.message;
131
+ throw err;
132
+ }
133
+ cursor = cursor.slice(key_len);
134
+
135
+ let value, value_len;
136
+ try {
137
+ ({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
138
+ len += value_len;
139
+ } catch (err) {
140
+ err.message = `{item_${i}} value: ` + err.message;
141
+ throw err;
142
+ }
143
+ cursor = cursor.slice(value_len);
144
+
145
+ v.set(key, value);
146
+ }
147
+
148
+ return { v, len };
149
+ } catch (err) {
150
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
151
+ }
152
+ }
153
+ };
@@ -0,0 +1,68 @@
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
+ // Based on GraphSON NumberSerializer.serialize().
26
+ // It's tested by AnySerializer.serialize() tests.
27
+ module.exports = class NumberSerializationStrategy {
28
+ constructor(ioc) {
29
+ this.ioc = ioc;
30
+ }
31
+
32
+ canBeUsedFor(value) {
33
+ if (Number.isNaN(value) || value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) {
34
+ return true;
35
+ }
36
+ if (typeof value === 'number') {
37
+ return true;
38
+ }
39
+ if (typeof value === 'bigint') {
40
+ return true;
41
+ }
42
+
43
+ return false;
44
+ }
45
+
46
+ serialize(item, fullyQualifiedFormat = true) {
47
+ if (typeof item === 'number') {
48
+ if (
49
+ Number.isNaN(item) ||
50
+ item === Number.POSITIVE_INFINITY ||
51
+ item === Number.NEGATIVE_INFINITY ||
52
+ !Number.isInteger(item)
53
+ ) {
54
+ return this.ioc.doubleSerializer.serialize(item, fullyQualifiedFormat);
55
+ }
56
+
57
+ if (item >= -2147483648 && item <= 2147483647) {
58
+ // INT32_MIN/MAX
59
+ return this.ioc.intSerializer.serialize(item, fullyQualifiedFormat);
60
+ }
61
+ return this.ioc.longSerializer.serialize(item, fullyQualifiedFormat);
62
+ }
63
+
64
+ if (typeof item === 'bigint') {
65
+ return this.ioc.bigIntegerSerializer.serialize(item, fullyQualifiedFormat);
66
+ }
67
+ }
68
+ };
@@ -0,0 +1,151 @@
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 t = require('../../../../process/traversal');
26
+
27
+ module.exports = class PSerializer {
28
+ constructor(ioc) {
29
+ this.ioc = ioc;
30
+ this.ioc.serializers[ioc.DataType.P] = this;
31
+ }
32
+
33
+ canBeUsedFor(value) {
34
+ return value instanceof t.P;
35
+ }
36
+
37
+ serialize(item, fullyQualifiedFormat = true) {
38
+ if (item === undefined || item === null) {
39
+ if (fullyQualifiedFormat) {
40
+ return Buffer.from([this.ioc.DataType.P, 0x01]);
41
+ }
42
+ const name = [0x00, 0x00, 0x00, 0x00]; // ''
43
+ const values_length = [0x00, 0x00, 0x00, 0x00]; // 0
44
+ return Buffer.from([...name, ...values_length]);
45
+ }
46
+
47
+ const bufs = [];
48
+ if (fullyQualifiedFormat) {
49
+ bufs.push(Buffer.from([this.ioc.DataType.P, 0x00]));
50
+ }
51
+
52
+ // {name}
53
+ bufs.push(this.ioc.stringSerializer.serialize(item.operator, false));
54
+
55
+ // {values_length}{value_0}...{value_n}
56
+ //
57
+ // This is a tricky part due to the nature of t.P.
58
+ // GraphBinary states that {name} is followed by list only,
59
+ // but t.P may be constructed such way that its item.value can be
60
+ // a usual string or something, that's why we should care here
61
+ // to get it wrapped into a list.
62
+ //
63
+ // It tries to resemble the same if-else structure as
64
+ // GraphSON.PSerializer.serialize() does.
65
+ let list;
66
+ if (item.other === undefined || item.other === null) {
67
+ if (Array.isArray(item.value)) {
68
+ list = item.value;
69
+ } else {
70
+ list = [item.value];
71
+ }
72
+ } else {
73
+ list = [item.value, item.other];
74
+ }
75
+ bufs.push(this.ioc.listSerializer.serialize(list, false));
76
+
77
+ return Buffer.concat(bufs);
78
+ }
79
+
80
+ deserialize(buffer, fullyQualifiedFormat = true) {
81
+ let len = 0;
82
+ let cursor = buffer;
83
+
84
+ try {
85
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
86
+ throw new Error('buffer is missing');
87
+ }
88
+ if (buffer.length < 1) {
89
+ throw new Error('buffer is empty');
90
+ }
91
+
92
+ if (fullyQualifiedFormat) {
93
+ const type_code = cursor.readUInt8();
94
+ len++;
95
+ if (type_code !== this.ioc.DataType.P) {
96
+ throw new Error('unexpected {type_code}');
97
+ }
98
+ cursor = cursor.slice(1);
99
+
100
+ if (cursor.length < 1) {
101
+ throw new Error('{value_flag} is missing');
102
+ }
103
+ const value_flag = cursor.readUInt8();
104
+ len++;
105
+ if (value_flag === 1) {
106
+ return { v: null, len };
107
+ }
108
+ if (value_flag !== 0) {
109
+ throw new Error('unexpected {value_flag}');
110
+ }
111
+ cursor = cursor.slice(1);
112
+ }
113
+
114
+ let name, name_len;
115
+ try {
116
+ ({ v: name, len: name_len } = this.ioc.stringSerializer.deserialize(cursor, false));
117
+ len += name_len;
118
+ } catch (err) {
119
+ err.message = '{name}: ' + err.message;
120
+ throw err;
121
+ }
122
+ cursor = cursor.slice(name_len);
123
+
124
+ let values, values_len;
125
+ try {
126
+ ({ v: values, len: values_len } = this.ioc.listSerializer.deserialize(cursor, false));
127
+ len += values_len;
128
+ } catch (err) {
129
+ err.message = '{values}: ' + err.message;
130
+ throw err;
131
+ }
132
+ cursor = cursor.slice(values_len);
133
+
134
+ if (values.length < 1) {
135
+ return { v: new t.P(''), len };
136
+ }
137
+
138
+ let v;
139
+ const P_static = t.P[name];
140
+ if (typeof P_static === 'function') {
141
+ v = P_static(...values); // it's better to follow existing logic which may depend on an operator name
142
+ } else {
143
+ v = new t.P(name, ...values);
144
+ }
145
+
146
+ return { v, len };
147
+ } catch (err) {
148
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
149
+ }
150
+ }
151
+ };
@@ -0,0 +1,123 @@
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 g = require('../../../graph');
26
+
27
+ module.exports = class PathSerializer {
28
+ constructor(ioc) {
29
+ this.ioc = ioc;
30
+ this.ioc.serializers[ioc.DataType.PATH] = this;
31
+ }
32
+
33
+ canBeUsedFor(value) {
34
+ return value instanceof g.Path;
35
+ }
36
+
37
+ serialize(item, fullyQualifiedFormat = true) {
38
+ if (item === undefined || item === null) {
39
+ if (fullyQualifiedFormat) {
40
+ return Buffer.from([this.ioc.DataType.PATH, 0x01]);
41
+ }
42
+ return Buffer.concat([
43
+ this.ioc.listSerializer.serialize([]), // {labels}=[]
44
+ this.ioc.listSerializer.serialize([]), // {objects}=[]
45
+ ]);
46
+ }
47
+
48
+ const bufs = [];
49
+ if (fullyQualifiedFormat) {
50
+ bufs.push(Buffer.from([this.ioc.DataType.PATH, 0x00]));
51
+ }
52
+
53
+ // {labels} is a List in which each item is a Set of String
54
+ bufs.push(this.ioc.listSerializer.serialize(item.labels));
55
+
56
+ // {objects} is a List of fully qualified typed values
57
+ bufs.push(this.ioc.listSerializer.serialize(item.objects));
58
+
59
+ return Buffer.concat(bufs);
60
+ }
61
+
62
+ deserialize(buffer, fullyQualifiedFormat = true) {
63
+ let len = 0;
64
+ let cursor = buffer;
65
+
66
+ try {
67
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
68
+ throw new Error('buffer is missing');
69
+ }
70
+ if (buffer.length < 1) {
71
+ throw new Error('buffer is empty');
72
+ }
73
+
74
+ if (fullyQualifiedFormat) {
75
+ const type_code = cursor.readUInt8();
76
+ len++;
77
+ if (type_code !== this.ioc.DataType.PATH) {
78
+ throw new Error('unexpected {type_code}');
79
+ }
80
+ cursor = cursor.slice(1);
81
+
82
+ if (cursor.length < 1) {
83
+ throw new Error('{value_flag} is missing');
84
+ }
85
+ const value_flag = cursor.readUInt8();
86
+ len++;
87
+ if (value_flag === 1) {
88
+ return { v: null, len };
89
+ }
90
+ if (value_flag !== 0) {
91
+ throw new Error('unexpected {value_flag}');
92
+ }
93
+ cursor = cursor.slice(1);
94
+ }
95
+
96
+ let labels, labels_len;
97
+ try {
98
+ ({ v: labels, len: labels_len } = this.ioc.listSerializer.deserialize(cursor));
99
+ len += labels_len;
100
+ } catch (err) {
101
+ err.message = '{labels}: ' + err.message;
102
+ throw err;
103
+ }
104
+ // TODO: should we check content of labels to make sure it's List< Set<String> > ?
105
+ cursor = cursor.slice(labels_len);
106
+
107
+ let objects, objects_len;
108
+ try {
109
+ ({ v: objects, len: objects_len } = this.ioc.listSerializer.deserialize(cursor));
110
+ len += objects_len;
111
+ } catch (err) {
112
+ err.message = '{objects}: ' + err.message;
113
+ throw err;
114
+ }
115
+ cursor = cursor.slice(objects_len);
116
+
117
+ const v = new g.Path(labels, objects);
118
+ return { v, len };
119
+ } catch (err) {
120
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
121
+ }
122
+ }
123
+ };
@@ -0,0 +1,141 @@
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 g = require('../../../graph');
26
+
27
+ module.exports = class PropertySerializer {
28
+ constructor(ioc) {
29
+ this.ioc = ioc;
30
+ this.ioc.serializers[ioc.DataType.PROPERTY] = this;
31
+ }
32
+
33
+ canBeUsedFor(value) {
34
+ return value instanceof g.Property;
35
+ }
36
+
37
+ serialize(item, fullyQualifiedFormat = true) {
38
+ if (item === undefined || item === null) {
39
+ if (fullyQualifiedFormat) {
40
+ return Buffer.from([this.ioc.DataType.PROPERTY, 0x01]);
41
+ }
42
+ return Buffer.concat([
43
+ this.ioc.stringSerializer.serialize('', false), // {key}=''
44
+ this.ioc.unspecifiedNullSerializer.serialize(null), // {value}=null
45
+ this.ioc.unspecifiedNullSerializer.serialize(null), // {parent}=null
46
+ ]);
47
+ }
48
+
49
+ const bufs = [];
50
+ if (fullyQualifiedFormat) {
51
+ bufs.push(Buffer.from([this.ioc.DataType.PROPERTY, 0x00]));
52
+ }
53
+
54
+ // {key}
55
+ bufs.push(this.ioc.stringSerializer.serialize(item.key, false));
56
+
57
+ // {value}
58
+ bufs.push(this.ioc.anySerializer.serialize(item.value));
59
+
60
+ // {parent}
61
+ bufs.push(this.ioc.unspecifiedNullSerializer.serialize(null));
62
+
63
+ return Buffer.concat(bufs);
64
+ }
65
+
66
+ deserialize(buffer, fullyQualifiedFormat = true) {
67
+ let len = 0;
68
+ let cursor = buffer;
69
+
70
+ try {
71
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
72
+ throw new Error('buffer is missing');
73
+ }
74
+ if (buffer.length < 1) {
75
+ throw new Error('buffer is empty');
76
+ }
77
+
78
+ if (fullyQualifiedFormat) {
79
+ const type_code = cursor.readUInt8();
80
+ len++;
81
+ if (type_code !== this.ioc.DataType.PROPERTY) {
82
+ throw new Error('unexpected {type_code}');
83
+ }
84
+ cursor = cursor.slice(1);
85
+
86
+ if (cursor.length < 1) {
87
+ throw new Error('{value_flag} is missing');
88
+ }
89
+ const value_flag = cursor.readUInt8();
90
+ len++;
91
+ if (value_flag === 1) {
92
+ return { v: null, len };
93
+ }
94
+ if (value_flag !== 0) {
95
+ throw new Error('unexpected {value_flag}');
96
+ }
97
+ cursor = cursor.slice(1);
98
+ }
99
+
100
+ // {key} is a String value
101
+ let key, key_len;
102
+ try {
103
+ ({ v: key, len: key_len } = this.ioc.stringSerializer.deserialize(cursor, false));
104
+ len += key_len;
105
+ } catch (err) {
106
+ err.message = '{key}: ' + err.message;
107
+ throw err;
108
+ }
109
+ cursor = cursor.slice(key_len);
110
+
111
+ // {value} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value}
112
+ let value, value_len;
113
+ try {
114
+ ({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
115
+ len += value_len;
116
+ } catch (err) {
117
+ err.message = '{value}: ' + err.message;
118
+ throw err;
119
+ }
120
+ cursor = cursor.slice(value_len);
121
+
122
+ // {parent} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value} which is either an Edge or VertexProperty.
123
+ // Note that as TinkerPop currently sends "references" only this value will always be null.
124
+ let parent_len;
125
+ try {
126
+ ({ len: parent_len } = this.ioc.unspecifiedNullSerializer.deserialize(cursor));
127
+ len += parent_len;
128
+ } catch (err) {
129
+ err.message = '{parent}: ' + err.message;
130
+ throw err;
131
+ }
132
+ // TODO: should we verify that parent is null?
133
+ cursor = cursor.slice(parent_len);
134
+
135
+ const v = new g.Property(key, value);
136
+ return { v, len };
137
+ } catch (err) {
138
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
139
+ }
140
+ }
141
+ };