gremlin 3.6.0 → 3.6.2

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 (113) hide show
  1. package/.eslintrc.js +3 -2
  2. package/NOTICE +1 -1
  3. package/doc/AnonymousTraversalSource.html +2 -2
  4. package/doc/Authenticator.html +2 -2
  5. package/doc/Bytecode.html +2 -2
  6. package/doc/Client.html +174 -9
  7. package/doc/Connection.html +43 -10
  8. package/doc/DriverRemoteConnection.html +144 -12
  9. package/doc/EdgeLabelVerificationStrategy.html +2 -2
  10. package/doc/Graph.html +2 -2
  11. package/doc/GraphSON2Reader.html +2 -2
  12. package/doc/GraphSON2Writer.html +2 -2
  13. package/doc/GraphSON3Reader.html +2 -2
  14. package/doc/GraphSON3Writer.html +2 -2
  15. package/doc/GraphTraversal.html +112 -112
  16. package/doc/GraphTraversalSource.html +19 -19
  17. package/doc/HaltedTraverserStrategy.html +2 -2
  18. package/doc/MatchAlgorithmStrategy.html +2 -2
  19. package/doc/P.html +2 -2
  20. package/doc/PartitionStrategy.html +2 -2
  21. package/doc/Path.html +2 -2
  22. package/doc/PlainTextSaslAuthenticator.html +2 -2
  23. package/doc/ProductiveByStrategy.html +2 -2
  24. package/doc/RemoteConnection.html +2 -2
  25. package/doc/RemoteStrategy.html +2 -2
  26. package/doc/RemoteTraversal.html +2 -2
  27. package/doc/ReservedKeysVerificationStrategy.html +2 -2
  28. package/doc/ResponseError.html +2 -2
  29. package/doc/ResultSet.html +2 -2
  30. package/doc/SaslAuthenticator.html +2 -2
  31. package/doc/SaslMechanismBase.html +2 -2
  32. package/doc/SaslMechanismPlain.html +2 -2
  33. package/doc/SeedStrategy.html +2 -2
  34. package/doc/SubgraphStrategy.html +2 -2
  35. package/doc/TextP.html +2 -2
  36. package/doc/Transaction.html +2 -2
  37. package/doc/Translator.html +2 -2
  38. package/doc/TraversalStrategies.html +2 -2
  39. package/doc/TraversalStrategy.html +2 -2
  40. package/doc/TypeSerializer.html +2 -2
  41. package/doc/driver_auth_authenticator.js.html +2 -2
  42. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +2 -2
  43. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +2 -2
  44. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +2 -2
  45. package/doc/driver_auth_sasl-authenticator.js.html +2 -2
  46. package/doc/driver_client.js.html +7 -2
  47. package/doc/driver_connection.js.html +49 -13
  48. package/doc/driver_driver-remote-connection.js.html +6 -2
  49. package/doc/driver_remote-connection.js.html +2 -2
  50. package/doc/driver_response-error.js.html +2 -2
  51. package/doc/driver_result-set.js.html +2 -2
  52. package/doc/global.html +68 -4
  53. package/doc/index.html +2 -2
  54. package/doc/module.exports.html +301 -0
  55. package/doc/process_anonymous-traversal.js.html +2 -2
  56. package/doc/process_bytecode.js.html +2 -2
  57. package/doc/process_graph-traversal.js.html +25 -13
  58. package/doc/process_transaction.js.html +2 -2
  59. package/doc/process_translator.js.html +2 -2
  60. package/doc/process_traversal-strategy.js.html +3 -3
  61. package/doc/process_traversal.js.html +4 -4
  62. package/doc/structure_graph.js.html +2 -2
  63. package/doc/structure_io_binary_internals_DataType.js.html +149 -0
  64. package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +131 -0
  65. package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +134 -0
  66. package/doc/structure_io_graph-serializer.js.html +2 -2
  67. package/doc/structure_io_type-serializers.js.html +2 -2
  68. package/docker-compose.yml +62 -0
  69. package/index.js +1 -0
  70. package/lib/driver/client.js +5 -0
  71. package/lib/driver/connection.js +47 -11
  72. package/lib/driver/driver-remote-connection.js +4 -0
  73. package/lib/process/graph-traversal.js +23 -11
  74. package/lib/process/traversal-strategy.js +1 -1
  75. package/lib/process/traversal.js +2 -2
  76. package/lib/structure/io/binary/GraphBinary.js +109 -0
  77. package/lib/structure/io/binary/internals/AnySerializer.js +95 -0
  78. package/lib/structure/io/binary/internals/ArraySerializer.js +135 -0
  79. package/lib/structure/io/binary/internals/BigIntegerSerializer.js +151 -0
  80. package/lib/structure/io/binary/internals/BooleanSerializer.js +103 -0
  81. package/lib/structure/io/binary/internals/BulkSetSerializer.js +124 -0
  82. package/lib/structure/io/binary/internals/ByteBufferSerializer.js +124 -0
  83. package/lib/structure/io/binary/internals/ByteSerializer.js +95 -0
  84. package/lib/structure/io/binary/internals/BytecodeSerializer.js +249 -0
  85. package/lib/structure/io/binary/internals/DataType.js +98 -0
  86. package/lib/structure/io/binary/internals/DateSerializer.js +103 -0
  87. package/lib/structure/io/binary/internals/DoubleSerializer.js +99 -0
  88. package/lib/structure/io/binary/internals/EdgeSerializer.js +215 -0
  89. package/lib/structure/io/binary/internals/EnumSerializer.js +149 -0
  90. package/lib/structure/io/binary/internals/FloatSerializer.js +99 -0
  91. package/lib/structure/io/binary/internals/GraphBinaryReader.js +80 -0
  92. package/lib/structure/io/binary/internals/GraphBinaryWriter.js +83 -0
  93. package/lib/structure/io/binary/internals/IntSerializer.js +112 -0
  94. package/lib/structure/io/binary/internals/LambdaSerializer.js +70 -0
  95. package/lib/structure/io/binary/internals/LongSerializer.js +107 -0
  96. package/lib/structure/io/binary/internals/LongSerializerNg.js +102 -0
  97. package/lib/structure/io/binary/internals/MapSerializer.js +153 -0
  98. package/lib/structure/io/binary/internals/NumberSerializationStrategy.js +68 -0
  99. package/lib/structure/io/binary/internals/PSerializer.js +151 -0
  100. package/lib/structure/io/binary/internals/PathSerializer.js +123 -0
  101. package/lib/structure/io/binary/internals/PropertySerializer.js +141 -0
  102. package/lib/structure/io/binary/internals/ShortSerializer.js +99 -0
  103. package/lib/structure/io/binary/internals/StringSerializer.js +114 -0
  104. package/lib/structure/io/binary/internals/TextPSerializer.js +145 -0
  105. package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +72 -0
  106. package/lib/structure/io/binary/internals/TraverserSerializer.js +123 -0
  107. package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +75 -0
  108. package/lib/structure/io/binary/internals/UuidSerializer.js +119 -0
  109. package/lib/structure/io/binary/internals/VertexPropertySerializer.js +172 -0
  110. package/lib/structure/io/binary/internals/VertexSerializer.js +135 -0
  111. package/lib/structure/io/binary/internals/utils.js +59 -0
  112. package/lib/utils.js +29 -0
  113. package/package.json +22 -12
@@ -0,0 +1,135 @@
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 VertexSerializer {
28
+ constructor(ioc) {
29
+ this.ioc = ioc;
30
+ this.ioc.serializers[ioc.DataType.VERTEX] = this;
31
+ }
32
+
33
+ canBeUsedFor(value) {
34
+ return value instanceof g.Vertex;
35
+ }
36
+
37
+ serialize(item, fullyQualifiedFormat = true) {
38
+ if (item === undefined || item === null) {
39
+ if (fullyQualifiedFormat) {
40
+ return Buffer.from([this.ioc.DataType.VERTEX, 0x01]);
41
+ }
42
+ const id = [0x03, 0x00, 0x00, 0x00, 0x00, 0x00]; // String ''
43
+ const label = [0x00, 0x00, 0x00, 0x00]; // ''
44
+ const properties = [0xfe, 0x01]; // null
45
+ return Buffer.from([...id, ...label, ...properties]);
46
+ }
47
+
48
+ const bufs = [];
49
+ if (fullyQualifiedFormat) {
50
+ bufs.push(Buffer.from([this.ioc.DataType.VERTEX, 0x00]));
51
+ }
52
+
53
+ // {id}
54
+ bufs.push(this.ioc.anySerializer.serialize(item.id));
55
+
56
+ // {label}
57
+ bufs.push(this.ioc.stringSerializer.serialize(item.label, false));
58
+
59
+ // {properties}
60
+ bufs.push(this.ioc.anySerializer.serialize(item.properties));
61
+
62
+ return Buffer.concat(bufs);
63
+ }
64
+
65
+ deserialize(buffer, fullyQualifiedFormat = true) {
66
+ let len = 0;
67
+ let cursor = buffer;
68
+
69
+ try {
70
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
71
+ throw new Error('buffer is missing');
72
+ }
73
+ if (buffer.length < 1) {
74
+ throw new Error('buffer is empty');
75
+ }
76
+
77
+ if (fullyQualifiedFormat) {
78
+ const type_code = cursor.readUInt8();
79
+ len++;
80
+ if (type_code !== this.ioc.DataType.VERTEX) {
81
+ throw new Error('unexpected {type_code}');
82
+ }
83
+ cursor = cursor.slice(1);
84
+
85
+ if (cursor.length < 1) {
86
+ throw new Error('{value_flag} is missing');
87
+ }
88
+ const value_flag = cursor.readUInt8();
89
+ len++;
90
+ if (value_flag === 1) {
91
+ return { v: null, len };
92
+ }
93
+ if (value_flag !== 0) {
94
+ throw new Error('unexpected {value_flag}');
95
+ }
96
+ cursor = cursor.slice(1);
97
+ }
98
+
99
+ let id, id_len;
100
+ try {
101
+ ({ v: id, len: id_len } = this.ioc.anySerializer.deserialize(cursor));
102
+ len += id_len;
103
+ } catch (err) {
104
+ err.message = '{id}: ' + err.message;
105
+ throw err;
106
+ }
107
+ cursor = cursor.slice(id_len);
108
+
109
+ let label, label_len;
110
+ try {
111
+ ({ v: label, len: label_len } = this.ioc.stringSerializer.deserialize(cursor, false));
112
+ len += label_len;
113
+ } catch (err) {
114
+ err.message = '{label}: ' + err.message;
115
+ throw err;
116
+ }
117
+ cursor = cursor.slice(label_len);
118
+
119
+ let properties, properties_len;
120
+ try {
121
+ ({ v: properties, len: properties_len } = this.ioc.anySerializer.deserialize(cursor));
122
+ len += properties_len;
123
+ } catch (err) {
124
+ err.message = '{properties}: ' + err.message;
125
+ throw err;
126
+ }
127
+ cursor = cursor.slice(properties_len);
128
+
129
+ const v = new g.Vertex(id, label, properties);
130
+ return { v, len };
131
+ } catch (err) {
132
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
133
+ }
134
+ }
135
+ };
@@ -0,0 +1,59 @@
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
+ * Deserialization error general constructor.
27
+ */
28
+ const des_error = ({ serializer, args, cursor, err }) => {
29
+ if (cursor === undefined) {
30
+ cursor = args[0]; // buffer
31
+ }
32
+ let cursor_tail = '';
33
+ if (cursor instanceof Buffer) {
34
+ if (cursor.length > 32) {
35
+ cursor_tail = '...';
36
+ }
37
+ cursor = cursor.slice(0, 32).toString('hex');
38
+ }
39
+
40
+ const fullyQualifiedFormat = args[1];
41
+ const nullable = args[2];
42
+
43
+ let m = `${serializer.constructor.name}.deserialize(cursor=${cursor}${cursor_tail}`;
44
+ if (fullyQualifiedFormat !== undefined) {
45
+ m += `, fullyQualifiedFormat=${fullyQualifiedFormat}`;
46
+ }
47
+ if (nullable !== undefined) {
48
+ m += `, nullable=${nullable}`;
49
+ }
50
+ m += `): ${err.message.replace(/\.$/, '')}.`;
51
+
52
+ err.message = m;
53
+
54
+ return err;
55
+ };
56
+
57
+ module.exports = {
58
+ des_error,
59
+ };
package/lib/utils.js CHANGED
@@ -24,6 +24,8 @@
24
24
  'use strict';
25
25
 
26
26
  const crypto = require('crypto');
27
+ const os = require('os');
28
+ const { readFileSync } = require('fs');
27
29
 
28
30
  exports.toLong = function toLong(value) {
29
31
  return new Long(value);
@@ -79,3 +81,30 @@ class ImmutableMap extends Map {
79
81
  }
80
82
 
81
83
  exports.ImmutableMap = ImmutableMap;
84
+
85
+ function generateUserAgent() {
86
+ const applicationName = (process.env.npm_package_name || 'NotAvailable').replace('_', ' ');
87
+ let driverVersion;
88
+ try {
89
+ driverVersion = JSON.parse(readFileSync(__dirname + '/../package.json')).version.replace('_', ' ');
90
+ } catch (e) {
91
+ driverVersion = 'NotAvailable';
92
+ }
93
+ const runtimeVersion = process.version.replace(' ', '_');
94
+ const osName = os.platform().replace(' ', '_');
95
+ const osVersion = os.release().replace(' ', '_');
96
+ const cpuArch = process.arch.replace(' ', '_');
97
+ const userAgent = `${applicationName} Gremlin-Javascript.${driverVersion} ${runtimeVersion} ${osName}.${osVersion} ${cpuArch}`;
98
+
99
+ return userAgent;
100
+ }
101
+
102
+ exports.getUserAgentHeader = function getUserAgentHeader() {
103
+ return 'User-Agent';
104
+ };
105
+
106
+ const userAgent = generateUserAgent();
107
+
108
+ exports.getUserAgent = function getUserAgent() {
109
+ return userAgent;
110
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gremlin",
3
- "version": "3.6.0",
3
+ "version": "3.6.2",
4
4
  "description": "JavaScript Gremlin Language Variant",
5
5
  "author": "Apache TinkerPop team",
6
6
  "keywords": [
@@ -14,21 +14,22 @@
14
14
  ],
15
15
  "license": "Apache-2.0",
16
16
  "dependencies": {
17
- "ws": "^6.2.2"
17
+ "ws": "^8.11.0"
18
18
  },
19
19
  "devDependencies": {
20
- "chai": "~4.1.2",
20
+ "chai": "~4.3.6",
21
21
  "chai-string": "~1.5.0",
22
22
  "colors": "1.4.0",
23
- "cucumber": "~4.2.1",
24
- "eslint": "^7.32.0",
23
+ "cross-env": "^7.0.3",
24
+ "cucumber": "~6.0.7",
25
+ "eslint": "^8.30.0",
25
26
  "eslint-config-prettier": "^8.5.0",
26
27
  "eslint-plugin-prettier": "^4.0.0",
27
- "grunt": "^1.4.1",
28
- "grunt-cli": "~1.3.2",
28
+ "grunt": "^1.5.3",
29
+ "grunt-cli": "~1.4.3",
29
30
  "grunt-jsdoc": "~2.4.1",
30
- "mocha": "^9.2.2",
31
- "prettier": "^2.5.1"
31
+ "mocha": "^10.2.0",
32
+ "prettier": "^2.7.1"
32
33
  },
33
34
  "repository": {
34
35
  "type": "git",
@@ -39,9 +40,18 @@
39
40
  "url": "https://issues.apache.org/jira/browse/TINKERPOP"
40
41
  },
41
42
  "scripts": {
42
- "test": "./node_modules/mocha/bin/mocha test/unit test/integration -t 5000",
43
- "features": "./node_modules/.bin/cucumber-js --require test/cucumber ../../../../../gremlin-test/features/",
44
- "unit-test": "./node_modules/mocha/bin/mocha test/unit",
43
+ "test": "npm run unit-test && npm run integration-test",
44
+ "unit-test": "mocha test/unit/*",
45
+ "integration-test": "npm run integration-test-graphson30 && npm run integration-test-graphbinary",
46
+ "integration-test-graphson30": "cross-env CLIENT_MIMETYPE='application/vnd.gremlin-v3.0+json' ./node_modules/mocha/bin/mocha.js test/integration -t 5000",
47
+ "integration-test-graphbinary": "cross-env CLIENT_MIMETYPE='application/vnd.graphbinary-v1.0' ./node_modules/mocha/bin/mocha.js test/integration -t 5000",
48
+ "TODO": "# test other mime types like graphbinary stringd",
49
+ "features": "npm run features-graphson30 && npm run features-graphbinary",
50
+ "features-graphson30": "cross-env CLIENT_MIMETYPE='application/vnd.gremlin-v3.0+json' cucumber-js --require test/cucumber ../../../../../gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/",
51
+ "features-graphbinary": "cross-env CLIENT_MIMETYPE='application/vnd.graphbinary-v1.0' cucumber-js --require test/cucumber ../../../../../gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/",
52
+ "features-docker": "npm run features-graphson30-docker && npm run features-graphbinary-docker",
53
+ "features-graphson30-docker": "cross-env CLIENT_MIMETYPE='application/vnd.gremlin-v3.0+json' cucumber-js --require test/cucumber ../gremlin-test/",
54
+ "features-graphbinary-docker": "cross-env CLIENT_MIMETYPE='application/vnd.graphbinary-v1.0' cucumber-js --require test/cucumber ../gremlin-test/",
45
55
  "lint": "eslint --ext .js ."
46
56
  },
47
57
  "engines": {