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,131 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>JSDoc: Source: structure/io/binary/internals/GraphBinaryReader.js</title>
6
+
7
+ <script src="scripts/prettify/prettify.js"> </script>
8
+ <script src="scripts/prettify/lang-css.js"> </script>
9
+ <!--[if lt IE 9]>
10
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11
+ <![endif]-->
12
+ <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13
+ <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14
+ </head>
15
+
16
+ <body>
17
+
18
+ <div id="main">
19
+
20
+ <h1 class="page-title">Source: structure/io/binary/internals/GraphBinaryReader.js</h1>
21
+
22
+
23
+
24
+
25
+
26
+
27
+ <section>
28
+ <article>
29
+ <pre class="prettyprint source linenums"><code>/*
30
+ * Licensed to the Apache Software Foundation (ASF) under one
31
+ * or more contributor license agreements. See the NOTICE file
32
+ * distributed with this work for additional information
33
+ * regarding copyright ownership. The ASF licenses this file
34
+ * to you under the Apache License, Version 2.0 (the
35
+ * "License"); you may not use this file except in compliance
36
+ * with the License. You may obtain a copy of the License at
37
+ *
38
+ * http://www.apache.org/licenses/LICENSE-2.0
39
+ *
40
+ * Unless required by applicable law or agreed to in writing,
41
+ * software distributed under the License is distributed on an
42
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
43
+ * KIND, either express or implied. See the License for the
44
+ * specific language governing permissions and limitations
45
+ * under the License.
46
+ */
47
+
48
+ /**
49
+ * @author Igor Ostapenko
50
+ */
51
+ 'use strict';
52
+
53
+ /**
54
+ * GraphBinary reader.
55
+ */
56
+ module.exports = class GraphBinaryReader {
57
+ constructor(ioc) {
58
+ this.ioc = ioc;
59
+ }
60
+
61
+ readResponse(buffer) {
62
+ if (buffer === undefined || buffer === null) {
63
+ throw new Error('Buffer is missing.');
64
+ }
65
+ if (!(buffer instanceof Buffer)) {
66
+ throw new Error('Not an instance of Buffer.');
67
+ }
68
+ if (buffer.length &lt; 1) {
69
+ throw new Error('Buffer is empty.');
70
+ }
71
+
72
+ const response = { status: {}, result: {} };
73
+ let cursor = buffer;
74
+ let len;
75
+
76
+ // {version} is a Byte representing the protocol version
77
+ const version = cursor[0];
78
+ if (version !== 0x81) {
79
+ throw new Error(`Unsupported version '${version}'.`);
80
+ }
81
+ cursor = cursor.slice(1); // skip version
82
+
83
+ // {request_id} is a nullable UUID
84
+ ({ v: response.requestId, len } = this.ioc.uuidSerializer.deserialize(cursor, false, true));
85
+ cursor = cursor.slice(len);
86
+
87
+ // {status_code} is an Int
88
+ ({ v: response.status.code, len } = this.ioc.intSerializer.deserialize(cursor, false));
89
+ cursor = cursor.slice(len);
90
+
91
+ // {status_message} is a nullable String
92
+ ({ v: response.status.message, len } = this.ioc.stringSerializer.deserialize(cursor, false, true));
93
+ cursor = cursor.slice(len);
94
+
95
+ // {status_attributes} is a Map
96
+ ({ v: response.status.attributes, len } = this.ioc.mapSerializer.deserialize(cursor, false));
97
+ cursor = cursor.slice(len);
98
+
99
+ // {result_meta} is a Map
100
+ ({ v: response.result.meta, len } = this.ioc.mapSerializer.deserialize(cursor, false));
101
+ cursor = cursor.slice(len);
102
+
103
+ // {result_data} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value}
104
+ ({ v: response.result.data } = this.ioc.anySerializer.deserialize(cursor));
105
+
106
+ return response;
107
+ }
108
+ };
109
+ </code></pre>
110
+ </article>
111
+ </section>
112
+
113
+
114
+
115
+
116
+ </div>
117
+
118
+ <nav>
119
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnonymousTraversalSource.html">AnonymousTraversalSource</a></li><li><a href="Authenticator.html">Authenticator</a></li><li><a href="Bytecode.html">Bytecode</a></li><li><a href="Client.html">Client</a></li><li><a href="Connection.html">Connection</a></li><li><a href="DriverRemoteConnection.html">DriverRemoteConnection</a></li><li><a href="EdgeLabelVerificationStrategy.html">EdgeLabelVerificationStrategy</a></li><li><a href="Graph.html">Graph</a></li><li><a href="GraphSON2Reader.html">GraphSON2Reader</a></li><li><a href="GraphSON2Writer.html">GraphSON2Writer</a></li><li><a href="GraphSON3Reader.html">GraphSON3Reader</a></li><li><a href="GraphSON3Writer.html">GraphSON3Writer</a></li><li><a href="GraphTraversal.html">GraphTraversal</a></li><li><a href="GraphTraversalSource.html">GraphTraversalSource</a></li><li><a href="HaltedTraverserStrategy.html">HaltedTraverserStrategy</a></li><li><a href="MatchAlgorithmStrategy.html">MatchAlgorithmStrategy</a></li><li><a href="module.exports.html">exports</a></li><li><a href="P.html">P</a></li><li><a href="PartitionStrategy.html">PartitionStrategy</a></li><li><a href="Path.html">Path</a></li><li><a href="PlainTextSaslAuthenticator.html">PlainTextSaslAuthenticator</a></li><li><a href="ProductiveByStrategy.html">ProductiveByStrategy</a></li><li><a href="RemoteConnection.html">RemoteConnection</a></li><li><a href="RemoteStrategy.html">RemoteStrategy</a></li><li><a href="RemoteTraversal.html">RemoteTraversal</a></li><li><a href="ReservedKeysVerificationStrategy.html">ReservedKeysVerificationStrategy</a></li><li><a href="ResponseError.html">ResponseError</a></li><li><a href="ResultSet.html">ResultSet</a></li><li><a href="SaslAuthenticator.html">SaslAuthenticator</a></li><li><a href="SaslMechanismBase.html">SaslMechanismBase</a></li><li><a href="SaslMechanismPlain.html">SaslMechanismPlain</a></li><li><a href="SubgraphStrategy.html">SubgraphStrategy</a></li><li><a href="TextP.html">TextP</a></li><li><a href="Transaction.html">Transaction</a></li><li><a href="Translator.html">Translator</a></li><li><a href="TraversalStrategies.html">TraversalStrategies</a></li><li><a href="TraversalStrategy.html">TraversalStrategy</a></li><li><a href="TypeSerializer.html">TypeSerializer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#DataType">DataType</a></li><li><a href="global.html#statics">statics</a></li></ul>
120
+ </nav>
121
+
122
+ <br class="clear">
123
+
124
+ <footer>
125
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Tue Jul 26 2022 15:51:52 GMT-0400 (Eastern Daylight Time)
126
+ </footer>
127
+
128
+ <script> prettyPrint(); </script>
129
+ <script src="scripts/linenumber.js"> </script>
130
+ </body>
131
+ </html>
@@ -0,0 +1,134 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>JSDoc: Source: structure/io/binary/internals/GraphBinaryWriter.js</title>
6
+
7
+ <script src="scripts/prettify/prettify.js"> </script>
8
+ <script src="scripts/prettify/lang-css.js"> </script>
9
+ <!--[if lt IE 9]>
10
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11
+ <![endif]-->
12
+ <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13
+ <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14
+ </head>
15
+
16
+ <body>
17
+
18
+ <div id="main">
19
+
20
+ <h1 class="page-title">Source: structure/io/binary/internals/GraphBinaryWriter.js</h1>
21
+
22
+
23
+
24
+
25
+
26
+
27
+ <section>
28
+ <article>
29
+ <pre class="prettyprint source linenums"><code>/*
30
+ * Licensed to the Apache Software Foundation (ASF) under one
31
+ * or more contributor license agreements. See the NOTICE file
32
+ * distributed with this work for additional information
33
+ * regarding copyright ownership. The ASF licenses this file
34
+ * to you under the Apache License, Version 2.0 (the
35
+ * "License"); you may not use this file except in compliance
36
+ * with the License. You may obtain a copy of the License at
37
+ *
38
+ * http://www.apache.org/licenses/LICENSE-2.0
39
+ *
40
+ * Unless required by applicable law or agreed to in writing,
41
+ * software distributed under the License is distributed on an
42
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
43
+ * KIND, either express or implied. See the License for the
44
+ * specific language governing permissions and limitations
45
+ * under the License.
46
+ */
47
+
48
+ /**
49
+ * @author Igor Ostapenko
50
+ */
51
+ 'use strict';
52
+
53
+ /**
54
+ * GraphBinary writer.
55
+ */
56
+ module.exports = class GraphBinaryWriter {
57
+ constructor(ioc) {
58
+ this.ioc = ioc;
59
+ }
60
+
61
+ writeRequest({ requestId, op, processor, args }) {
62
+ const bufs = [
63
+ // {version} 1 byte
64
+ Buffer.from([0x81]),
65
+ // {request_id} UUID
66
+ this.ioc.uuidSerializer.serialize(requestId, false),
67
+ // {op} String
68
+ this.ioc.stringSerializer.serialize(op, false),
69
+ // {processor} String
70
+ this.ioc.stringSerializer.serialize(processor, false),
71
+ // {args} Map
72
+ this.ioc.mapSerializer.serialize(args, false),
73
+ ];
74
+ return Buffer.concat(bufs);
75
+
76
+ /*// Detailed example for a quick reference:
77
+ // {version}
78
+ 0x81,
79
+ // {request_id} UUID
80
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
81
+ // {op} String
82
+ 0x00,0x00,0x00,0x08, ...Buffer.from('bytecode'),
83
+ // {processor} String
84
+ 0x00,0x00,0x00,0x09, ...Buffer.from('traversal'),
85
+ // {args} Map
86
+ 0x00,0x00,0x00,0x02,
87
+ // 1.
88
+ // args.aliases key String
89
+ 0x03,0x00, 0x00,0x00,0x00,0x07, ...Buffer.from('aliases'),
90
+ // args.aliases value Map
91
+ 0x0A,0x00, 0x00,0x00,0x00,0x01,
92
+ // aliases.g key String
93
+ 0x03,0x00, 0x00,0x00,0x00,0x01, ...Buffer.from('g'),
94
+ // aliases.g value String
95
+ 0x03,0x00, 0x00,0x00,0x00,0x01, ...Buffer.from('g'),
96
+ // 2.
97
+ // args.gremlin key String
98
+ 0x03,0x00, 0x00,0x00,0x00,0x07, ...Buffer.from('gremlin'),
99
+ // args.gremlin value Bytecode
100
+ 0x15,0x00,
101
+ // {steps_length}
102
+ 0x00,0x00,0x00,0x01,
103
+ // step 1 - {name} String
104
+ 0x00,0x00,0x00,0x01, ...Buffer.from('V'),
105
+ // step 1 - {values_length} Int
106
+ 0x00,0x00,0x00,0x00,
107
+ // {sources_length}
108
+ 0x00,0x00,0x00,0x00,
109
+ */
110
+ }
111
+ };
112
+ </code></pre>
113
+ </article>
114
+ </section>
115
+
116
+
117
+
118
+
119
+ </div>
120
+
121
+ <nav>
122
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnonymousTraversalSource.html">AnonymousTraversalSource</a></li><li><a href="Authenticator.html">Authenticator</a></li><li><a href="Bytecode.html">Bytecode</a></li><li><a href="Client.html">Client</a></li><li><a href="Connection.html">Connection</a></li><li><a href="DriverRemoteConnection.html">DriverRemoteConnection</a></li><li><a href="EdgeLabelVerificationStrategy.html">EdgeLabelVerificationStrategy</a></li><li><a href="Graph.html">Graph</a></li><li><a href="GraphSON2Reader.html">GraphSON2Reader</a></li><li><a href="GraphSON2Writer.html">GraphSON2Writer</a></li><li><a href="GraphSON3Reader.html">GraphSON3Reader</a></li><li><a href="GraphSON3Writer.html">GraphSON3Writer</a></li><li><a href="GraphTraversal.html">GraphTraversal</a></li><li><a href="GraphTraversalSource.html">GraphTraversalSource</a></li><li><a href="HaltedTraverserStrategy.html">HaltedTraverserStrategy</a></li><li><a href="MatchAlgorithmStrategy.html">MatchAlgorithmStrategy</a></li><li><a href="module.exports.html">exports</a></li><li><a href="P.html">P</a></li><li><a href="PartitionStrategy.html">PartitionStrategy</a></li><li><a href="Path.html">Path</a></li><li><a href="PlainTextSaslAuthenticator.html">PlainTextSaslAuthenticator</a></li><li><a href="ProductiveByStrategy.html">ProductiveByStrategy</a></li><li><a href="RemoteConnection.html">RemoteConnection</a></li><li><a href="RemoteStrategy.html">RemoteStrategy</a></li><li><a href="RemoteTraversal.html">RemoteTraversal</a></li><li><a href="ReservedKeysVerificationStrategy.html">ReservedKeysVerificationStrategy</a></li><li><a href="ResponseError.html">ResponseError</a></li><li><a href="ResultSet.html">ResultSet</a></li><li><a href="SaslAuthenticator.html">SaslAuthenticator</a></li><li><a href="SaslMechanismBase.html">SaslMechanismBase</a></li><li><a href="SaslMechanismPlain.html">SaslMechanismPlain</a></li><li><a href="SubgraphStrategy.html">SubgraphStrategy</a></li><li><a href="TextP.html">TextP</a></li><li><a href="Transaction.html">Transaction</a></li><li><a href="Translator.html">Translator</a></li><li><a href="TraversalStrategies.html">TraversalStrategies</a></li><li><a href="TraversalStrategy.html">TraversalStrategy</a></li><li><a href="TypeSerializer.html">TypeSerializer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#DataType">DataType</a></li><li><a href="global.html#statics">statics</a></li></ul>
123
+ </nav>
124
+
125
+ <br class="clear">
126
+
127
+ <footer>
128
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Tue Jul 26 2022 15:51:52 GMT-0400 (Eastern Daylight Time)
129
+ </footer>
130
+
131
+ <script> prettyPrint(); </script>
132
+ <script src="scripts/linenumber.js"> </script>
133
+ </body>
134
+ </html>
@@ -51,12 +51,12 @@
51
51
  'use strict';
52
52
 
53
53
  const typeSerializers = require('./type-serializers');
54
+ const Bytecode = require('../../process/bytecode');
54
55
 
55
56
  /**
56
57
  * GraphSON2 writer.
57
58
  */
58
59
  class GraphSON2Writer {
59
-
60
60
  /**
61
61
  * @param {Object} [options]
62
62
  * @param {Object} [options.serializers] An object used as an associative array with GraphSON 2 type name as keys and
@@ -66,7 +66,7 @@ class GraphSON2Writer {
66
66
  constructor(options) {
67
67
  this._options = options || {};
68
68
  // Create instance of the default serializers
69
- this._serializers = this.getDefaultSerializers().map(serializerConstructor => {
69
+ this._serializers = this.getDefaultSerializers().map((serializerConstructor) => {
70
70
  const s = new serializerConstructor();
71
71
  s.writer = this;
72
72
  return s;
@@ -74,7 +74,7 @@ class GraphSON2Writer {
74
74
 
75
75
  const customSerializers = this._options.serializers || {};
76
76
 
77
- Object.keys(customSerializers).forEach(key => {
77
+ Object.keys(customSerializers).forEach((key) => {
78
78
  const s = customSerializers[key];
79
79
  if (!s.serialize) {
80
80
  return;
@@ -111,7 +111,7 @@ class GraphSON2Writer {
111
111
  if (Array.isArray(value)) {
112
112
  // We need to handle arrays when there is no serializer
113
113
  // for older versions of GraphSON
114
- return value.map(item => this.adaptObject(item));
114
+ return value.map((item) => this.adaptObject(item));
115
115
  }
116
116
 
117
117
  // Default (strings / objects / ...)
@@ -126,6 +126,48 @@ class GraphSON2Writer {
126
126
  write(obj) {
127
127
  return JSON.stringify(this.adaptObject(obj));
128
128
  }
129
+
130
+ writeRequest({ requestId, op, processor, args }) {
131
+ const req = {
132
+ requestId: { '@type': 'g:UUID', '@value': requestId },
133
+ op,
134
+ processor,
135
+ args: this._adaptArgs(args, true),
136
+ };
137
+
138
+ if (req.args['gremlin'] instanceof Bytecode) {
139
+ req.args['gremlin'] = this.adaptObject(req.args['gremlin']);
140
+ }
141
+
142
+ return Buffer.from(JSON.stringify(req));
143
+ }
144
+
145
+ /**
146
+ * Takes the given args map and ensures all arguments are passed through to adaptObject
147
+ * @param {Object} args Map of arguments to process.
148
+ * @param {Boolean} protocolLevel Determines whether it's a protocol level binding.
149
+ * @returns {Object}
150
+ * @private
151
+ */
152
+ _adaptArgs(args, protocolLevel) {
153
+ if (args instanceof Object) {
154
+ const newObj = {};
155
+ Object.keys(args).forEach((key) => {
156
+ // bindings key (at the protocol-level needs special handling. without this, it wraps the generated Map
157
+ // in another map for types like EnumValue. Could be a nicer way to do this but for now it's solving the
158
+ // problem with script submission of non JSON native types
159
+ if (protocolLevel &amp;&amp; key === 'bindings') {
160
+ newObj[key] = this._adaptArgs(args[key], false);
161
+ } else {
162
+ newObj[key] = this.adaptObject(args[key]);
163
+ }
164
+ });
165
+
166
+ return newObj;
167
+ }
168
+
169
+ return args;
170
+ }
129
171
  }
130
172
 
131
173
  /**
@@ -153,7 +195,7 @@ class GraphSON2Reader {
153
195
  this._deserializers = {};
154
196
 
155
197
  const defaultDeserializers = this.getDefaultDeserializers();
156
- Object.keys(defaultDeserializers).forEach(typeName => {
198
+ Object.keys(defaultDeserializers).forEach((typeName) => {
157
199
  const serializerConstructor = defaultDeserializers[typeName];
158
200
  const s = new serializerConstructor();
159
201
  s.reader = this;
@@ -162,7 +204,7 @@ class GraphSON2Reader {
162
204
 
163
205
  if (this._options.serializers) {
164
206
  const customSerializers = this._options.serializers || {};
165
- Object.keys(customSerializers).forEach(key => {
207
+ Object.keys(customSerializers).forEach((key) => {
166
208
  const s = customSerializers[key];
167
209
  if (!s.deserialize) {
168
210
  return;
@@ -189,7 +231,7 @@ class GraphSON2Reader {
189
231
  return null;
190
232
  }
191
233
  if (Array.isArray(obj)) {
192
- return obj.map(item => this.read(item));
234
+ return obj.map((item) => this.read(item));
193
235
  }
194
236
  const type = obj[typeSerializers.typeKey];
195
237
  if (type) {
@@ -207,6 +249,10 @@ class GraphSON2Reader {
207
249
  return obj;
208
250
  }
209
251
 
252
+ readResponse(buffer) {
253
+ return this.read(JSON.parse(buffer.toString()));
254
+ }
255
+
210
256
  _deserializeObject(obj) {
211
257
  const keys = Object.keys(obj);
212
258
  const result = {};
@@ -229,9 +275,9 @@ class GraphSON3Reader extends GraphSON2Reader {
229
275
  const graphSON2Deserializers = {
230
276
  'g:Traverser': typeSerializers.TraverserSerializer,
231
277
  'g:TraversalStrategy': typeSerializers.TraversalStrategySerializer,
232
- 'g:Int32': typeSerializers.NumberSerializer,
233
- 'g:Int64': typeSerializers.NumberSerializer,
234
- 'g:Float': typeSerializers.NumberSerializer,
278
+ 'g:Int32': typeSerializers.NumberSerializer,
279
+ 'g:Int64': typeSerializers.NumberSerializer,
280
+ 'g:Float': typeSerializers.NumberSerializer,
235
281
  'g:Double': typeSerializers.NumberSerializer,
236
282
  'g:Date': typeSerializers.DateSerializer,
237
283
  'g:Direction': typeSerializers.DirectionSerializer,
@@ -242,13 +288,13 @@ const graphSON2Deserializers = {
242
288
  'g:Path': typeSerializers.Path3Serializer,
243
289
  'g:TextP': typeSerializers.TextPSerializer,
244
290
  'g:T': typeSerializers.TSerializer,
245
- 'g:BulkSet': typeSerializers.BulkSetSerializer
291
+ 'g:BulkSet': typeSerializers.BulkSetSerializer,
246
292
  };
247
293
 
248
294
  const graphSON3Deserializers = Object.assign({}, graphSON2Deserializers, {
249
295
  'g:List': typeSerializers.ListSerializer,
250
296
  'g:Set': typeSerializers.SetSerializer,
251
- 'g:Map': typeSerializers.MapSerializer
297
+ 'g:Map': typeSerializers.MapSerializer,
252
298
  });
253
299
 
254
300
  const graphSON2Serializers = [
@@ -263,13 +309,13 @@ const graphSON2Serializers = [
263
309
  typeSerializers.EnumSerializer,
264
310
  typeSerializers.VertexSerializer,
265
311
  typeSerializers.EdgeSerializer,
266
- typeSerializers.LongSerializer
312
+ typeSerializers.LongSerializer,
267
313
  ];
268
314
 
269
315
  const graphSON3Serializers = graphSON2Serializers.concat([
270
316
  typeSerializers.ListSerializer,
271
317
  typeSerializers.SetSerializer,
272
- typeSerializers.MapSerializer
318
+ typeSerializers.MapSerializer,
273
319
  ]);
274
320
 
275
321
  module.exports = {
@@ -278,8 +324,9 @@ module.exports = {
278
324
  GraphSON2Writer,
279
325
  GraphSON2Reader,
280
326
  GraphSONWriter: GraphSON3Writer,
281
- GraphSONReader: GraphSON3Reader
282
- };</code></pre>
327
+ GraphSONReader: GraphSON3Reader,
328
+ };
329
+ </code></pre>
283
330
  </article>
284
331
  </section>
285
332
 
@@ -289,13 +336,13 @@ module.exports = {
289
336
  </div>
290
337
 
291
338
  <nav>
292
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnonymousTraversalSource.html">AnonymousTraversalSource</a></li><li><a href="Authenticator.html">Authenticator</a></li><li><a href="Bytecode.html">Bytecode</a></li><li><a href="Client.html">Client</a></li><li><a href="Connection.html">Connection</a></li><li><a href="DriverRemoteConnection.html">DriverRemoteConnection</a></li><li><a href="EdgeLabelVerificationStrategy.html">EdgeLabelVerificationStrategy</a></li><li><a href="Graph.html">Graph</a></li><li><a href="GraphSON2Reader.html">GraphSON2Reader</a></li><li><a href="GraphSON2Writer.html">GraphSON2Writer</a></li><li><a href="GraphSON3Reader.html">GraphSON3Reader</a></li><li><a href="GraphSON3Writer.html">GraphSON3Writer</a></li><li><a href="GraphTraversal.html">GraphTraversal</a></li><li><a href="GraphTraversalSource.html">GraphTraversalSource</a></li><li><a href="HaltedTraverserStrategy.html">HaltedTraverserStrategy</a></li><li><a href="MatchAlgorithmStrategy.html">MatchAlgorithmStrategy</a></li><li><a href="P.html">P</a></li><li><a href="PartitionStrategy.html">PartitionStrategy</a></li><li><a href="Path.html">Path</a></li><li><a href="PlainTextSaslAuthenticator.html">PlainTextSaslAuthenticator</a></li><li><a href="RemoteConnection.html">RemoteConnection</a></li><li><a href="RemoteStrategy.html">RemoteStrategy</a></li><li><a href="RemoteTraversal.html">RemoteTraversal</a></li><li><a href="ReservedKeysVerificationStrategy.html">ReservedKeysVerificationStrategy</a></li><li><a href="ResponseError.html">ResponseError</a></li><li><a href="ResultSet.html">ResultSet</a></li><li><a href="SaslAuthenticator.html">SaslAuthenticator</a></li><li><a href="SaslMechanismBase.html">SaslMechanismBase</a></li><li><a href="SaslMechanismPlain.html">SaslMechanismPlain</a></li><li><a href="SubgraphStrategy.html">SubgraphStrategy</a></li><li><a href="TextP.html">TextP</a></li><li><a href="Transaction.html">Transaction</a></li><li><a href="Translator.html">Translator</a></li><li><a href="TraversalStrategies.html">TraversalStrategies</a></li><li><a href="TraversalStrategy.html">TraversalStrategy</a></li><li><a href="TypeSerializer.html">TypeSerializer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#statics">statics</a></li></ul>
339
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnonymousTraversalSource.html">AnonymousTraversalSource</a></li><li><a href="Authenticator.html">Authenticator</a></li><li><a href="Bytecode.html">Bytecode</a></li><li><a href="Client.html">Client</a></li><li><a href="Connection.html">Connection</a></li><li><a href="DriverRemoteConnection.html">DriverRemoteConnection</a></li><li><a href="EdgeLabelVerificationStrategy.html">EdgeLabelVerificationStrategy</a></li><li><a href="Graph.html">Graph</a></li><li><a href="GraphSON2Reader.html">GraphSON2Reader</a></li><li><a href="GraphSON2Writer.html">GraphSON2Writer</a></li><li><a href="GraphSON3Reader.html">GraphSON3Reader</a></li><li><a href="GraphSON3Writer.html">GraphSON3Writer</a></li><li><a href="GraphTraversal.html">GraphTraversal</a></li><li><a href="GraphTraversalSource.html">GraphTraversalSource</a></li><li><a href="HaltedTraverserStrategy.html">HaltedTraverserStrategy</a></li><li><a href="MatchAlgorithmStrategy.html">MatchAlgorithmStrategy</a></li><li><a href="module.exports.html">exports</a></li><li><a href="P.html">P</a></li><li><a href="PartitionStrategy.html">PartitionStrategy</a></li><li><a href="Path.html">Path</a></li><li><a href="PlainTextSaslAuthenticator.html">PlainTextSaslAuthenticator</a></li><li><a href="ProductiveByStrategy.html">ProductiveByStrategy</a></li><li><a href="RemoteConnection.html">RemoteConnection</a></li><li><a href="RemoteStrategy.html">RemoteStrategy</a></li><li><a href="RemoteTraversal.html">RemoteTraversal</a></li><li><a href="ReservedKeysVerificationStrategy.html">ReservedKeysVerificationStrategy</a></li><li><a href="ResponseError.html">ResponseError</a></li><li><a href="ResultSet.html">ResultSet</a></li><li><a href="SaslAuthenticator.html">SaslAuthenticator</a></li><li><a href="SaslMechanismBase.html">SaslMechanismBase</a></li><li><a href="SaslMechanismPlain.html">SaslMechanismPlain</a></li><li><a href="SubgraphStrategy.html">SubgraphStrategy</a></li><li><a href="TextP.html">TextP</a></li><li><a href="Transaction.html">Transaction</a></li><li><a href="Translator.html">Translator</a></li><li><a href="TraversalStrategies.html">TraversalStrategies</a></li><li><a href="TraversalStrategy.html">TraversalStrategy</a></li><li><a href="TypeSerializer.html">TypeSerializer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#DataType">DataType</a></li><li><a href="global.html#statics">statics</a></li></ul>
293
340
  </nav>
294
341
 
295
342
  <br class="clear">
296
343
 
297
344
  <footer>
298
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Mon Jul 26 2021 10:29:09 GMT+0200 (Central European Summer Time)
345
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Tue Jul 26 2022 15:51:52 GMT-0400 (Eastern Daylight Time)
299
346
  </footer>
300
347
 
301
348
  <script> prettyPrint(); </script>