gremlin 3.5.1 → 3.6.0

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 (89) hide show
  1. package/.eslintrc.js +154 -0
  2. package/.prettierrc.js +29 -0
  3. package/Gruntfile.js +15 -16
  4. package/README.md +2 -2
  5. package/doc/AnonymousTraversalSource.html +5 -5
  6. package/doc/Authenticator.html +2 -2
  7. package/doc/Bytecode.html +7 -7
  8. package/doc/Client.html +138 -64
  9. package/doc/Connection.html +89 -5
  10. package/doc/DriverRemoteConnection.html +11 -11
  11. package/doc/EdgeLabelVerificationStrategy.html +3 -3
  12. package/doc/Graph.html +2 -2
  13. package/doc/GraphSON2Reader.html +4 -4
  14. package/doc/GraphSON2Writer.html +3 -3
  15. package/doc/GraphSON3Reader.html +3 -3
  16. package/doc/GraphSON3Writer.html +3 -3
  17. package/doc/GraphTraversal.html +1025 -190
  18. package/doc/GraphTraversalSource.html +520 -19
  19. package/doc/HaltedTraverserStrategy.html +3 -3
  20. package/doc/MatchAlgorithmStrategy.html +3 -3
  21. package/doc/P.html +13 -13
  22. package/doc/PartitionStrategy.html +3 -3
  23. package/doc/Path.html +2 -2
  24. package/doc/PlainTextSaslAuthenticator.html +2 -2
  25. package/doc/ProductiveByStrategy.html +288 -0
  26. package/doc/RemoteConnection.html +10 -10
  27. package/doc/RemoteStrategy.html +4 -4
  28. package/doc/RemoteTraversal.html +3 -3
  29. package/doc/ReservedKeysVerificationStrategy.html +3 -3
  30. package/doc/ResponseError.html +2 -2
  31. package/doc/ResultSet.html +7 -7
  32. package/doc/SaslAuthenticator.html +2 -2
  33. package/doc/SaslMechanismBase.html +2 -2
  34. package/doc/SaslMechanismPlain.html +6 -6
  35. package/doc/SeedStrategy.html +288 -0
  36. package/doc/SubgraphStrategy.html +3 -3
  37. package/doc/TextP.html +300 -10
  38. package/doc/Transaction.html +6 -6
  39. package/doc/Translator.html +198 -4
  40. package/doc/TraversalStrategies.html +5 -5
  41. package/doc/TraversalStrategy.html +3 -3
  42. package/doc/TypeSerializer.html +2 -2
  43. package/doc/driver_auth_authenticator.js.html +4 -4
  44. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +3 -3
  45. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +26 -17
  46. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +7 -7
  47. package/doc/driver_auth_sasl-authenticator.js.html +3 -3
  48. package/doc/driver_client.js.html +73 -23
  49. package/doc/driver_connection.js.html +108 -89
  50. package/doc/driver_driver-remote-connection.js.html +12 -11
  51. package/doc/driver_remote-connection.js.html +4 -5
  52. package/doc/driver_response-error.js.html +5 -4
  53. package/doc/driver_result-set.js.html +4 -4
  54. package/doc/global.html +200 -3
  55. package/doc/index.html +4 -4
  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 +277 -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 +83 -53
  62. package/doc/process_traversal.js.html +111 -107
  63. package/doc/structure_graph.js.html +7 -7
  64. package/doc/structure_io_graph-serializer.js.html +65 -18
  65. package/doc/structure_io_type-serializers.js.html +86 -89
  66. package/index.js +5 -5
  67. package/lib/driver/auth/authenticator.js +2 -2
  68. package/lib/driver/auth/mechanisms/sasl-mechanism-base.js +1 -1
  69. package/lib/driver/auth/mechanisms/sasl-mechanism-plain.js +24 -15
  70. package/lib/driver/auth/plain-text-sasl-authenticator.js +5 -5
  71. package/lib/driver/auth/sasl-authenticator.js +1 -1
  72. package/lib/driver/client.js +71 -21
  73. package/lib/driver/connection.js +106 -87
  74. package/lib/driver/driver-remote-connection.js +10 -9
  75. package/lib/driver/remote-connection.js +2 -3
  76. package/lib/driver/response-error.js +2 -2
  77. package/lib/driver/result-set.js +1 -2
  78. package/lib/process/anonymous-traversal.js +1 -2
  79. package/lib/process/bytecode.js +9 -7
  80. package/lib/process/graph-traversal.js +274 -141
  81. package/lib/process/transaction.js +13 -7
  82. package/lib/process/translator.js +50 -35
  83. package/lib/process/traversal-strategy.js +80 -51
  84. package/lib/process/traversal.js +109 -105
  85. package/lib/structure/graph.js +5 -5
  86. package/lib/structure/io/graph-serializer.js +62 -16
  87. package/lib/structure/io/type-serializers.js +84 -87
  88. package/lib/utils.js +15 -10
  89. package/package.json +11 -4
@@ -63,7 +63,7 @@ class SaslAuthenticator extends Authenticator {
63
63
  throw new Error('No Sasl Mechanism Specified');
64
64
  }
65
65
  }
66
-
66
+
67
67
  /**
68
68
  * Evaluates the challenge from the server and returns appropriate response.
69
69
  * @param {String} challenge Challenge string presented by the server.
@@ -85,13 +85,13 @@ module.exports = SaslAuthenticator;
85
85
  </div>
86
86
 
87
87
  <nav>
88
- <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>
88
+ <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="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="SeedStrategy.html">SeedStrategy</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>
89
89
  </nav>
90
90
 
91
91
  <br class="clear">
92
92
 
93
93
  <footer>
94
- 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)
94
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Mon Apr 11 2022 07:53:52 GMT-0400 (Eastern Daylight Time)
95
95
  </footer>
96
96
 
97
97
  <script> prettyPrint(); </script>
@@ -32,14 +32,14 @@
32
32
  * distributed with this work for additional information
33
33
  * regarding copyright ownership. The ASF licenses this file
34
34
  * to you under the Apache License, Version 2.0 (the
35
- * "License"); you may not use this file except in compliance
35
+ * 'License'); you may not use this file except in compliance
36
36
  * with the License. You may obtain a copy of the License at
37
37
  *
38
38
  * http://www.apache.org/licenses/LICENSE-2.0
39
39
  *
40
40
  * Unless required by applicable law or agreed to in writing,
41
41
  * software distributed under the License is distributed on an
42
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
42
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
43
43
  * KIND, either express or implied. See the License for the
44
44
  * specific language governing permissions and limitations
45
45
  * under the License.
@@ -54,7 +54,6 @@ const Bytecode = require('../process/bytecode');
54
54
  * A {@link Client} contains methods to send messages to a Gremlin Server.
55
55
  */
56
56
  class Client {
57
-
58
57
  /**
59
58
  * Creates a new instance of {@link Client}.
60
59
  * @param {String} url The resource uri.
@@ -101,25 +100,35 @@ class Client {
101
100
  return this._connection.isOpen;
102
101
  }
103
102
 
103
+ /**
104
+ * Configuration specific to the current request.
105
+ * @typedef {Object} RequestOptions
106
+ * @property {String} requestId - User specified request identifier which must be a UUID.
107
+ * @property {Number} batchSize - Indicates whether the Power component is present.
108
+ * @property {String} userAgent - The size in which the result of a request is to be 'batched' back to the client
109
+ * @property {Number} evaluationTimeout - The timeout for the evaluation of the request.
110
+ */
111
+
104
112
  /**
105
113
  * Send a request to the Gremlin Server, can send a script or bytecode steps.
106
114
  * @param {Bytecode|string} message The bytecode or script to send
107
115
  * @param {Object} [bindings] The script bindings, if any.
108
- * @param {Object} [requestOptions] Configuration specific to the current request.
109
- * @param {String} [requestOptions.requestId] User specified request identifier which must be a UUID.
110
- * @param {Number} [requestOptions.batchSize] The size in which the result of a request is to be "batched" back to the client
111
- * @param {String} [requestOptions.userAgent] A custom string that specifies to the server where the request came from.
112
- * @param {Number} [requestOptions.evaluationTimeout] The timeout for the evaluation of the request.
116
+ * @param {RequestOptions} [requestOptions] Configuration specific to the current request.
113
117
  * @returns {Promise}
114
118
  */
115
119
  submit(message, bindings, requestOptions) {
116
- const requestIdOverride = requestOptions &amp;&amp; requestOptions.requestId
117
- if (requestIdOverride) delete requestOptions['requestId'];
120
+ const requestIdOverride = requestOptions &amp;&amp; requestOptions.requestId;
121
+ if (requestIdOverride) {
122
+ delete requestOptions['requestId'];
123
+ }
118
124
 
119
- const args = Object.assign({
120
- gremlin: message,
121
- aliases: { 'g': this._options.traversalSource || 'g' }
122
- }, requestOptions)
125
+ const args = Object.assign(
126
+ {
127
+ gremlin: message,
128
+ aliases: { g: this._options.traversalSource || 'g' },
129
+ },
130
+ requestOptions,
131
+ );
123
132
 
124
133
  if (this._options.session &amp;&amp; this._options.processor === 'session') {
125
134
  args['session'] = this._options.session;
@@ -128,17 +137,54 @@ class Client {
128
137
  if (message instanceof Bytecode) {
129
138
  if (this._options.session &amp;&amp; this._options.processor === 'session') {
130
139
  return this._connection.submit('session', 'bytecode', args, requestIdOverride);
131
- } else {
132
- return this._connection.submit('traversal', 'bytecode', args, requestIdOverride);
133
140
  }
141
+ return this._connection.submit('traversal', 'bytecode', args, requestIdOverride);
142
+ } else if (typeof message === 'string') {
143
+ args['bindings'] = bindings;
144
+ args['language'] = 'gremlin-groovy';
145
+ args['accept'] = this._connection.mimeType;
146
+ return this._connection.submit(this._options.processor || '', 'eval', args, requestIdOverride);
147
+ }
148
+ throw new TypeError('message must be of type Bytecode or string');
149
+ }
150
+
151
+ /**
152
+ * Send a request to the Gremlin Server and receive a stream for the results, can send a script or bytecode steps.
153
+ * @param {Bytecode|string} message The bytecode or script to send
154
+ * @param {Object} [bindings] The script bindings, if any.
155
+ * @param {RequestOptions} [requestOptions] Configuration specific to the current request.
156
+ * @returns {ReadableStream}
157
+ */
158
+ stream(message, bindings, requestOptions) {
159
+ const requestIdOverride = requestOptions &amp;&amp; requestOptions.requestId;
160
+ if (requestIdOverride) {
161
+ delete requestOptions['requestId'];
162
+ }
163
+
164
+ const args = Object.assign(
165
+ {
166
+ gremlin: message,
167
+ aliases: { g: this._options.traversalSource || 'g' },
168
+ },
169
+ requestOptions,
170
+ );
171
+
172
+ if (this._options.session &amp;&amp; this._options.processor === 'session') {
173
+ args['session'] = this._options.session;
174
+ }
175
+
176
+ if (message instanceof Bytecode) {
177
+ if (this._options.session &amp;&amp; this._options.processor === 'session') {
178
+ return this._connection.stream('session', 'bytecode', args, requestIdOverride);
179
+ }
180
+ return this._connection.stream('traversal', 'bytecode', args, requestIdOverride);
134
181
  } else if (typeof message === 'string') {
135
182
  args['bindings'] = bindings;
136
183
  args['language'] = 'gremlin-groovy';
137
184
  args['accept'] = this._connection.mimeType;
138
- return this._connection.submit(this._options.processor || '','eval', args, requestIdOverride);
139
- } else {
140
- throw new TypeError("message must be of type Bytecode or string");
185
+ return this._connection.stream(this._options.processor || '', 'eval', args, requestIdOverride);
141
186
  }
187
+ throw new TypeError('message must be of type Bytecode or string');
142
188
  }
143
189
 
144
190
  /**
@@ -147,6 +193,10 @@ class Client {
147
193
  * @returns {Promise}
148
194
  */
149
195
  close() {
196
+ if (this._options.session &amp;&amp; this._options.processor === 'session') {
197
+ const args = { session: this._options.session };
198
+ return this._connection.submit(this._options.processor, 'close', args, null).then(() => this._connection.close());
199
+ }
150
200
  return this._connection.close();
151
201
  }
152
202
 
@@ -156,7 +206,7 @@ class Client {
156
206
  * @param {Function} handler The callback to be called when the event occurs.
157
207
  */
158
208
  addListener(event, handler) {
159
- this._connection.on(event, handler)
209
+ this._connection.on(event, handler);
160
210
  }
161
211
 
162
212
  /**
@@ -165,7 +215,7 @@ class Client {
165
215
  * @param {Function} handler The event handler to be removed.
166
216
  */
167
217
  removeListener(event, handler) {
168
- this._connection.removeListener(event, handler)
218
+ this._connection.removeListener(event, handler);
169
219
  }
170
220
  }
171
221
 
@@ -180,13 +230,13 @@ module.exports = Client;
180
230
  </div>
181
231
 
182
232
  <nav>
183
- <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>
233
+ <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="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="SeedStrategy.html">SeedStrategy</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>
184
234
  </nav>
185
235
 
186
236
  <br class="clear">
187
237
 
188
238
  <footer>
189
- 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)
239
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Mon Apr 11 2022 07:53:52 GMT-0400 (Eastern Daylight Time)
190
240
  </footer>
191
241
 
192
242
  <script> prettyPrint(); </script>
@@ -51,19 +51,19 @@
51
51
  'use strict';
52
52
 
53
53
  const EventEmitter = require('events');
54
+ const Stream = require('stream');
54
55
  const WebSocket = require('ws');
55
56
  const util = require('util');
56
57
  const utils = require('../utils');
57
58
  const serializer = require('../structure/io/graph-serializer');
58
59
  const ResultSet = require('./result-set');
59
60
  const ResponseError = require('./response-error');
60
- const Bytecode = require('../process/bytecode');
61
61
 
62
62
  const responseStatusCode = {
63
63
  success: 200,
64
64
  noContent: 204,
65
65
  partialContent: 206,
66
- authenticationChallenge: 407,
66
+ authenticationChallenge: 407,
67
67
  };
68
68
 
69
69
  const defaultMimeType = 'application/vnd.gremlin-v3.0+json';
@@ -76,7 +76,6 @@ const pongTimeoutDelay = 30 * 1000;
76
76
  * Represents a single connection to a Gremlin Server.
77
77
  */
78
78
  class Connection extends EventEmitter {
79
-
80
79
  /**
81
80
  * Creates a new instance of {@link Connection}.
82
81
  * @param {String} url The resource uri.
@@ -120,7 +119,8 @@ class Connection extends EventEmitter {
120
119
  this._pingInterval = null;
121
120
  this._pongTimeout = null;
122
121
 
123
- this._header = String.fromCharCode(this.mimeType.length) + this.mimeType;
122
+ this._header = String.fromCharCode(this.mimeType.length) + this.mimeType; // TODO: what if mimeType.length > 255
123
+ this._header_buf = Buffer.from(this._header);
124
124
  this.isOpen = false;
125
125
  this.traversalSource = options.traversalSource || 'g';
126
126
  this._authenticator = options.authenticator;
@@ -146,14 +146,14 @@ class Connection extends EventEmitter {
146
146
  return this._openPromise;
147
147
  }
148
148
 
149
- this.emit('log', `ws open`);
149
+ this.emit('log', 'ws open');
150
150
 
151
151
  this._ws = new WebSocket(this.url, {
152
152
  headers: this.options.headers,
153
153
  ca: this.options.ca,
154
154
  cert: this.options.cert,
155
155
  pfx: this.options.pfx,
156
- rejectUnauthorized: this.options.rejectUnauthorized
156
+ rejectUnauthorized: this.options.rejectUnauthorized,
157
157
  });
158
158
 
159
159
  this._ws.on('message', (data) => this._handleMessage(data));
@@ -171,7 +171,7 @@ class Connection extends EventEmitter {
171
171
  this._ws.pong();
172
172
  });
173
173
 
174
- return this._openPromise = new Promise((resolve, reject) => {
174
+ return (this._openPromise = new Promise((resolve, reject) => {
175
175
  this._ws.on('open', () => {
176
176
  this.isOpen = true;
177
177
  if (this._pingEnabled) {
@@ -183,59 +183,79 @@ class Connection extends EventEmitter {
183
183
  this._handleError(err);
184
184
  reject(err);
185
185
  });
186
- });
186
+ }));
187
187
  }
188
188
 
189
189
  /** @override */
190
190
  submit(processor, op, args, requestId) {
191
191
  const rid = requestId || utils.getUuid();
192
- return this.open().then(() => new Promise((resolve, reject) => {
193
- if (op !== 'authentication') {
194
- this._responseHandlers[rid] = {
195
- callback: (err, result) => err ? reject(err) : resolve(result),
196
- result: null
192
+ return this.open().then(
193
+ () =>
194
+ new Promise((resolve, reject) => {
195
+ if (op !== 'authentication') {
196
+ this._responseHandlers[rid] = {
197
+ callback: (err, result) => (err ? reject(err) : resolve(result)),
198
+ result: null,
199
+ };
200
+ }
201
+
202
+ const request = {
203
+ requestId: rid,
204
+ op: op || 'bytecode',
205
+ // if using op eval need to ensure processor stays unset if caller didn't set it.
206
+ processor: !processor &amp;&amp; op !== 'eval' ? 'traversal' : processor,
207
+ args: args || {},
208
+ };
209
+
210
+ const request_buf = this._writer.writeRequest(request);
211
+ const message = Buffer.concat([this._header_buf, request_buf], this._header_buf.length + request_buf.length);
212
+ this._ws.send(message);
213
+ }),
214
+ );
215
+ }
216
+
217
+ /** @override */
218
+ stream(processor, op, args, requestId) {
219
+ const rid = requestId || utils.getUuid();
220
+
221
+ const readableStream = new Stream.Readable({
222
+ objectMode: true,
223
+ read() {},
224
+ });
225
+
226
+ this._responseHandlers[rid] = {
227
+ callback: (err) => (err ? readableStream.destroy(err) : readableStream.push(null)),
228
+ result: readableStream,
229
+ };
230
+
231
+ this.open()
232
+ .then(() => {
233
+ const request = {
234
+ requestId: rid,
235
+ op: op || 'bytecode',
236
+ // if using op eval need to ensure processor stays unset if caller didn't set it.
237
+ processor: !processor &amp;&amp; op !== 'eval' ? 'traversal' : processor,
238
+ args: args || {},
197
239
  };
198
- }
199
240
 
200
- const message = Buffer.from(this._header + JSON.stringify(this._getRequest(rid, op, args, processor)));
201
- this._ws.send(message);
202
- }));
241
+ const request_buf = this._writer.writeRequest(request);
242
+ const message = Buffer.concat([this._header_buf, request_buf], this._header_buf.length + request_buf.length);
243
+ this._ws.send(message);
244
+ })
245
+ .catch((err) => readableStream.destroy(err));
246
+
247
+ return readableStream;
203
248
  }
204
249
 
205
250
  _getDefaultReader(mimeType) {
206
- return mimeType === graphSON2MimeType
207
- ? new serializer.GraphSON2Reader()
208
- : new serializer.GraphSONReader();
251
+ return mimeType === graphSON2MimeType ? new serializer.GraphSON2Reader() : new serializer.GraphSONReader();
209
252
  }
210
253
 
211
254
  _getDefaultWriter(mimeType) {
212
- return mimeType === graphSON2MimeType
213
- ? new serializer.GraphSON2Writer()
214
- : new serializer.GraphSONWriter();
215
- }
216
-
217
- _getRequest(id, op, args, processor) {
218
- if (args) {
219
- args = this._adaptArgs(args, true);
220
- } else {
221
- args = {};
222
- }
223
-
224
- if (args['gremlin'] instanceof Bytecode) {
225
- args['gremlin'] = this._writer.adaptObject(args['gremlin']);
226
- }
227
-
228
- return ({
229
- 'requestId': { '@type': 'g:UUID', '@value': id },
230
- 'op': op || 'bytecode',
231
- // if using op eval need to ensure processor stays unset if caller didn't set it.
232
- 'processor': (!processor &amp;&amp; op !== 'eval') ? 'traversal' : processor,
233
- 'args': args
234
- });
255
+ return mimeType === graphSON2MimeType ? new serializer.GraphSON2Writer() : new serializer.GraphSONWriter();
235
256
  }
236
257
 
237
258
  _pingHeartbeat() {
238
-
239
259
  if (this._pingInterval) {
240
260
  clearInterval(this._pingInterval);
241
261
  this._pingInterval = null;
@@ -255,7 +275,6 @@ class Connection extends EventEmitter {
255
275
  }, this._pongTimeoutDelay);
256
276
 
257
277
  this._ws.ping();
258
-
259
278
  }, this._pingIntervalDelay);
260
279
  }
261
280
 
@@ -275,22 +294,30 @@ class Connection extends EventEmitter {
275
294
  }
276
295
 
277
296
  _handleMessage(data) {
278
- const response = this._reader.read(JSON.parse(data.toString()));
297
+ const response = this._reader.readResponse(data);
279
298
  if (response.requestId === null || response.requestId === undefined) {
280
299
  // There was a serialization issue on the server that prevented the parsing of the request id
281
300
  // We invoke any of the pending handlers with an error
282
- Object.keys(this._responseHandlers).forEach(requestId => {
301
+ Object.keys(this._responseHandlers).forEach((requestId) => {
283
302
  const handler = this._responseHandlers[requestId];
284
303
  this._clearHandler(requestId);
285
304
  if (response.status !== undefined &amp;&amp; response.status.message) {
286
305
  return handler.callback(
287
306
  // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
288
- new ResponseError(util.format(
289
- 'Server error (no request information): %s (%d)', response.status.message, response.status.code), response.status));
290
- } else {
291
- // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
292
- return handler.callback(new ResponseError(util.format('Server error (no request information): %j', response), response.status));
307
+ new ResponseError(
308
+ util.format(
309
+ 'Server error (no request information): %s (%d)',
310
+ response.status.message,
311
+ response.status.code,
312
+ ),
313
+ response.status,
314
+ ),
315
+ );
293
316
  }
317
+ // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
318
+ return handler.callback(
319
+ new ResponseError(util.format('Server error (no request information): %j', response), response.status),
320
+ );
294
321
  });
295
322
  return;
296
323
  }
@@ -304,31 +331,49 @@ class Connection extends EventEmitter {
304
331
  }
305
332
 
306
333
  if (response.status.code === responseStatusCode.authenticationChallenge &amp;&amp; this._authenticator) {
307
- this._authenticator.evaluateChallenge(response.result.data).then(res => {
308
- return this.submit(undefined, 'authentication', res, response.requestId);
309
- }).catch(handler.callback);
334
+ this._authenticator
335
+ .evaluateChallenge(response.result.data)
336
+ .then((res) => this.submit(undefined, 'authentication', res, response.requestId))
337
+ .catch(handler.callback);
310
338
 
311
339
  return;
312
- }
313
- else if (response.status.code >= 400) {
340
+ } else if (response.status.code >= 400) {
314
341
  // callback in error
315
342
  return handler.callback(
316
343
  // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
317
- new ResponseError(util.format('Server error: %s (%d)', response.status.message, response.status.code), response.status));
344
+ new ResponseError(
345
+ util.format('Server error: %s (%d)', response.status.message, response.status.code),
346
+ response.status,
347
+ ),
348
+ );
318
349
  }
350
+
351
+ const isStreamingResponse = handler.result instanceof Stream.Readable;
352
+
319
353
  switch (response.status.code) {
320
354
  case responseStatusCode.noContent:
321
355
  this._clearHandler(response.requestId);
356
+ if (isStreamingResponse) {
357
+ handler.result.push(new ResultSet(utils.emptyArray, response.status.attributes));
358
+ return handler.callback(null);
359
+ }
322
360
  return handler.callback(null, new ResultSet(utils.emptyArray, response.status.attributes));
323
361
  case responseStatusCode.partialContent:
362
+ if (isStreamingResponse) {
363
+ handler.result.push(new ResultSet(response.result.data, response.status.attributes));
364
+ break;
365
+ }
324
366
  handler.result = handler.result || [];
325
367
  handler.result.push.apply(handler.result, response.result.data);
326
368
  break;
327
369
  default:
370
+ if (isStreamingResponse) {
371
+ handler.result.push(new ResultSet(response.result.data, response.status.attributes));
372
+ return handler.callback(null);
373
+ }
328
374
  if (handler.result) {
329
375
  handler.result.push.apply(handler.result, response.result.data);
330
- }
331
- else {
376
+ } else {
332
377
  handler.result = response.result.data;
333
378
  }
334
379
  this._clearHandler(response.requestId);
@@ -364,32 +409,6 @@ class Connection extends EventEmitter {
364
409
  delete this._responseHandlers[requestId];
365
410
  }
366
411
 
367
- /**
368
- * Takes the given args map and ensures all arguments are passed through to _write.adaptObject
369
- * @param {Object} args Map of arguments to process.
370
- * @param {Boolean} protocolLevel Determines whether it's a protocol level binding.
371
- * @returns {Object}
372
- * @private
373
- */
374
- _adaptArgs(args, protocolLevel) {
375
- if (args instanceof Object) {
376
- let newObj = {};
377
- Object.keys(args).forEach((key) => {
378
- // bindings key (at the protocol-level needs special handling. without this, it wraps the generated Map
379
- // in another map for types like EnumValue. Could be a nicer way to do this but for now it's solving the
380
- // problem with script submission of non JSON native types
381
- if (protocolLevel &amp;&amp; key === 'bindings')
382
- newObj[key] = this._adaptArgs(args[key], false);
383
- else
384
- newObj[key] = this._writer.adaptObject(args[key]);
385
- });
386
-
387
- return newObj;
388
- }
389
-
390
- return args;
391
- }
392
-
393
412
  /**
394
413
  * Closes the Connection.
395
414
  * @return {Promise}
@@ -399,7 +418,7 @@ class Connection extends EventEmitter {
399
418
  return Promise.resolve();
400
419
  }
401
420
  if (!this._closePromise) {
402
- this._closePromise = new Promise(resolve => {
421
+ this._closePromise = new Promise((resolve) => {
403
422
  this._closeCallback = resolve;
404
423
  this._ws.close();
405
424
  });
@@ -419,13 +438,13 @@ module.exports = Connection;
419
438
  </div>
420
439
 
421
440
  <nav>
422
- <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>
441
+ <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="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="SeedStrategy.html">SeedStrategy</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>
423
442
  </nav>
424
443
 
425
444
  <br class="clear">
426
445
 
427
446
  <footer>
428
- 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)
447
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Mon Apr 11 2022 07:53:52 GMT-0400 (Eastern Daylight Time)
429
448
  </footer>
430
449
 
431
450
  <script> prettyPrint(); </script>