gremlin 3.5.0 → 3.5.3
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.
- package/.eslintrc.js +154 -0
- package/.prettierrc.js +29 -0
- package/Gruntfile.js +15 -16
- package/NOTICE +1 -1
- package/doc/AnonymousTraversalSource.html +7 -7
- package/doc/Authenticator.html +3 -3
- package/doc/Bytecode.html +249 -5
- package/doc/Client.html +139 -65
- package/doc/Connection.html +90 -6
- package/doc/DriverRemoteConnection.html +380 -8
- package/doc/EdgeLabelVerificationStrategy.html +3 -3
- package/doc/Graph.html +2 -2
- package/doc/GraphSON2Reader.html +4 -4
- package/doc/GraphSON2Writer.html +3 -3
- package/doc/GraphSON3Reader.html +3 -3
- package/doc/GraphSON3Writer.html +3 -3
- package/doc/GraphTraversal.html +107 -107
- package/doc/GraphTraversalSource.html +130 -19
- package/doc/HaltedTraverserStrategy.html +3 -3
- package/doc/MatchAlgorithmStrategy.html +3 -3
- package/doc/P.html +13 -13
- package/doc/PartitionStrategy.html +3 -3
- package/doc/Path.html +2 -2
- package/doc/PlainTextSaslAuthenticator.html +2 -2
- package/doc/ProductiveByStrategy.html +288 -0
- package/doc/RemoteConnection.html +484 -10
- package/doc/RemoteStrategy.html +4 -4
- package/doc/RemoteTraversal.html +3 -3
- package/doc/ReservedKeysVerificationStrategy.html +3 -3
- package/doc/ResponseError.html +3 -3
- package/doc/ResultSet.html +8 -8
- package/doc/SaslAuthenticator.html +2 -2
- package/doc/SaslMechanismBase.html +3 -3
- package/doc/SaslMechanismPlain.html +6 -6
- package/doc/{GraphSONReader.html → SeedStrategy.html} +12 -15
- package/doc/SubgraphStrategy.html +3 -3
- package/doc/TextP.html +10 -10
- package/doc/Transaction.html +655 -0
- package/doc/Translator.html +200 -6
- package/doc/TraversalStrategies.html +137 -4
- package/doc/TraversalStrategy.html +4 -4
- package/doc/TypeSerializer.html +2 -2
- package/doc/driver_auth_authenticator.js.html +4 -4
- package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +3 -3
- package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +26 -17
- package/doc/driver_auth_plain-text-sasl-authenticator.js.html +7 -7
- package/doc/driver_auth_sasl-authenticator.js.html +3 -3
- package/doc/driver_client.js.html +75 -25
- package/doc/driver_connection.js.html +108 -89
- package/doc/driver_driver-remote-connection.js.html +40 -9
- package/doc/driver_remote-connection.js.html +47 -6
- package/doc/driver_response-error.js.html +5 -4
- package/doc/driver_result-set.js.html +4 -4
- package/doc/global.html +200 -3
- package/doc/index.html +2 -2
- package/doc/process_anonymous-traversal.js.html +5 -5
- package/doc/process_bytecode.js.html +32 -7
- package/doc/process_graph-traversal.js.html +213 -143
- package/doc/process_transaction.js.html +143 -0
- package/doc/process_translator.js.html +58 -39
- package/doc/process_traversal-strategy.js.html +79 -52
- package/doc/process_traversal.js.html +101 -108
- package/doc/structure_graph.js.html +7 -7
- package/doc/structure_io_graph-serializer.js.html +65 -18
- package/doc/structure_io_type-serializers.js.html +86 -89
- package/index.js +5 -5
- package/lib/driver/auth/authenticator.js +2 -2
- package/lib/driver/auth/mechanisms/sasl-mechanism-base.js +1 -1
- package/lib/driver/auth/mechanisms/sasl-mechanism-plain.js +24 -15
- package/lib/driver/auth/plain-text-sasl-authenticator.js +5 -5
- package/lib/driver/auth/sasl-authenticator.js +1 -1
- package/lib/driver/client.js +73 -23
- package/lib/driver/connection.js +106 -87
- package/lib/driver/driver-remote-connection.js +38 -7
- package/lib/driver/remote-connection.js +45 -4
- package/lib/driver/response-error.js +2 -2
- package/lib/driver/result-set.js +1 -2
- package/lib/process/anonymous-traversal.js +2 -3
- package/lib/process/bytecode.js +30 -5
- package/lib/process/graph-traversal.js +210 -141
- package/lib/process/transaction.js +92 -0
- package/lib/process/translator.js +55 -37
- package/lib/process/traversal-strategy.js +76 -50
- package/lib/process/traversal.js +99 -106
- package/lib/structure/graph.js +5 -5
- package/lib/structure/io/graph-serializer.js +62 -16
- package/lib/structure/io/type-serializers.js +84 -87
- package/lib/utils.js +15 -10
- package/package.json +11 -5
- package/doc/GraphSONWriter.html +0 -436
- package/gremlin-javascript.iml +0 -9
|
@@ -25,14 +25,15 @@
|
|
|
25
25
|
const rcModule = require('./remote-connection');
|
|
26
26
|
const RemoteConnection = rcModule.RemoteConnection;
|
|
27
27
|
const RemoteTraversal = rcModule.RemoteTraversal;
|
|
28
|
+
const utils = require('../utils');
|
|
28
29
|
const Client = require('./client');
|
|
30
|
+
const Bytecode = require('../process/bytecode');
|
|
29
31
|
const OptionsStrategy = require('../process/traversal-strategy').OptionsStrategy;
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* Represents the default {@link RemoteConnection} implementation.
|
|
33
35
|
*/
|
|
34
36
|
class DriverRemoteConnection extends RemoteConnection {
|
|
35
|
-
|
|
36
37
|
/**
|
|
37
38
|
* Creates a new instance of {@link DriverRemoteConnection}.
|
|
38
39
|
* @param {String} url The resource uri.
|
|
@@ -49,8 +50,8 @@ class DriverRemoteConnection extends RemoteConnection {
|
|
|
49
50
|
* @param {Object} [options.headers] An associative array containing the additional header key/values for the initial request.
|
|
50
51
|
* @constructor
|
|
51
52
|
*/
|
|
52
|
-
constructor(url, options) {
|
|
53
|
-
super(url);
|
|
53
|
+
constructor(url, options = {}) {
|
|
54
|
+
super(url, options);
|
|
54
55
|
this._client = new Client(url, options);
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -59,27 +60,57 @@ class DriverRemoteConnection extends RemoteConnection {
|
|
|
59
60
|
return this._client.open();
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
/** @override */
|
|
62
64
|
get isOpen() {
|
|
63
65
|
return this._client.isOpen;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/** @override */
|
|
67
69
|
submit(bytecode) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
const optionsStrategy = bytecode.sourceInstructions.find(
|
|
71
|
+
(i) => i[0] === 'withStrategies' && i[1] instanceof OptionsStrategy,
|
|
72
|
+
);
|
|
70
73
|
const allowedKeys = ['evaluationTimeout', 'scriptEvaluationTimeout', 'batchSize', 'requestId', 'userAgent'];
|
|
71
74
|
|
|
72
75
|
let requestOptions = undefined;
|
|
73
76
|
if (optionsStrategy !== undefined) {
|
|
74
77
|
requestOptions = {};
|
|
75
78
|
const conf = optionsStrategy[1].configuration;
|
|
76
|
-
for (
|
|
79
|
+
for (const key in conf) {
|
|
77
80
|
if (conf.hasOwnProperty(key) && allowedKeys.indexOf(key) > -1) {
|
|
78
81
|
requestOptions[key] = conf[key];
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
|
-
|
|
85
|
+
|
|
86
|
+
return this._client.submit(bytecode, null, requestOptions).then((result) => new RemoteTraversal(result.toArray()));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @override */
|
|
90
|
+
createSession() {
|
|
91
|
+
if (this.isSessionBound) {
|
|
92
|
+
throw new Error('Connection is already bound to a session - child sessions are not allowed');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// make sure a fresh session is used when starting a new transaction
|
|
96
|
+
const copiedOptions = Object.assign({}, this.options);
|
|
97
|
+
copiedOptions.session = utils.getUuid();
|
|
98
|
+
return new DriverRemoteConnection(this.url, copiedOptions);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @override */
|
|
102
|
+
get isSessionBound() {
|
|
103
|
+
return this.options.session;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @override */
|
|
107
|
+
commit() {
|
|
108
|
+
return this._client.submit(Bytecode.GraphOp.commit, null);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @override */
|
|
112
|
+
rollback() {
|
|
113
|
+
return this._client.submit(Bytecode.GraphOp.rollback, null);
|
|
83
114
|
}
|
|
84
115
|
|
|
85
116
|
/** @override */
|
|
@@ -30,8 +30,13 @@ const TraversalStrategy = require('../process/traversal-strategy').TraversalStra
|
|
|
30
30
|
* returning results.
|
|
31
31
|
*/
|
|
32
32
|
class RemoteConnection {
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* @param {String} url The resource uri.
|
|
35
|
+
* @param {Object} [options] The connection options.
|
|
36
|
+
*/
|
|
37
|
+
constructor(url, options = {}) {
|
|
34
38
|
this.url = url;
|
|
39
|
+
this.options = options;
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
/**
|
|
@@ -50,6 +55,15 @@ class RemoteConnection {
|
|
|
50
55
|
throw new Error('isOpen() must be implemented');
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Determines if the connection is already bound to a session. If so, this indicates that the
|
|
60
|
+
* <code>#createSession()</code> cannot be called so as to produce child sessions.
|
|
61
|
+
* @returns {boolean}
|
|
62
|
+
*/
|
|
63
|
+
get isSessionBound() {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
53
67
|
/**
|
|
54
68
|
* Submits the <code>Bytecode</code> provided and returns a <code>RemoteTraversal</code>.
|
|
55
69
|
* @abstract
|
|
@@ -58,10 +72,34 @@ class RemoteConnection {
|
|
|
58
72
|
*/
|
|
59
73
|
submit(bytecode) {
|
|
60
74
|
throw new Error('submit() must be implemented');
|
|
61
|
-
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Create a new <code>RemoteConnection</code> that is bound to a session using the configuration from this one.
|
|
79
|
+
* If the connection is already session bound then this function should throw an exception.
|
|
80
|
+
* @returns {RemoteConnection}
|
|
81
|
+
*/
|
|
82
|
+
createSession() {
|
|
83
|
+
throw new Error('createSession() must be implemented');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Submits a <code>Bytecode.GraphOp.commit</code> to the server and closes the connection.
|
|
88
|
+
* @returns {Promise}
|
|
89
|
+
*/
|
|
90
|
+
commit() {
|
|
91
|
+
throw new Error('commit() must be implemented');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Submits a <code>Bytecode.GraphOp.rollback</code> to the server and closes the connection.
|
|
95
|
+
* @returns {Promise}
|
|
96
|
+
*/
|
|
97
|
+
rollback() {
|
|
98
|
+
throw new Error('rollback() must be implemented');
|
|
99
|
+
}
|
|
62
100
|
|
|
63
101
|
/**
|
|
64
|
-
* Closes the connection
|
|
102
|
+
* Closes the connection where open transactions will close according to the features of the graph provider.
|
|
65
103
|
* @returns {Promise}
|
|
66
104
|
*/
|
|
67
105
|
close() {
|
|
@@ -86,7 +124,10 @@ class RemoteStrategy extends TraversalStrategy {
|
|
|
86
124
|
* @param {RemoteConnection} connection
|
|
87
125
|
*/
|
|
88
126
|
constructor(connection) {
|
|
89
|
-
|
|
127
|
+
// gave this a fqcn that has a local "js:" prefix since this strategy isn't sent as bytecode to the server.
|
|
128
|
+
// this is a sort of local-only strategy that actually executes client side. not sure if this prefix is the
|
|
129
|
+
// right way to name this or not, but it should have a name to identify it.
|
|
130
|
+
super('js:RemoteStrategy');
|
|
90
131
|
this.connection = connection;
|
|
91
132
|
}
|
|
92
133
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
class ResponseError extends Error {
|
|
26
26
|
constructor(message, responseStatus) {
|
|
27
27
|
super(message);
|
|
28
|
-
this.name =
|
|
28
|
+
this.name = 'ResponseError';
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Gets the server status code.
|
|
@@ -44,4 +44,4 @@ class ResponseError extends Error {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
module.exports = ResponseError;
|
|
47
|
+
module.exports = ResponseError;
|
package/lib/driver/result-set.js
CHANGED
|
@@ -31,7 +31,6 @@ const emptyMap = Object.freeze(new utils.ImmutableMap());
|
|
|
31
31
|
* Represents the response returned from the execution of a Gremlin traversal or script.
|
|
32
32
|
*/
|
|
33
33
|
class ResultSet {
|
|
34
|
-
|
|
35
34
|
/**
|
|
36
35
|
* Creates a new instance of {@link ResultSet}.
|
|
37
36
|
* @param {Array} items
|
|
@@ -90,4 +89,4 @@ class ResultSet {
|
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
module.exports = ResultSet;
|
|
92
|
+
module.exports = ResultSet;
|
|
@@ -30,7 +30,6 @@ const Graph = require('../structure/graph').Graph;
|
|
|
30
30
|
* instance or a <code>RemoteConnection</code>.
|
|
31
31
|
*/
|
|
32
32
|
class AnonymousTraversalSource {
|
|
33
|
-
|
|
34
33
|
/**
|
|
35
34
|
* Creates a new instance of {@code AnonymousTraversalSource}.
|
|
36
35
|
* @param {Function} [traversalSourceClass] Optional {@code GraphTraversalSource} constructor.
|
|
@@ -52,7 +51,7 @@ class AnonymousTraversalSource {
|
|
|
52
51
|
/**
|
|
53
52
|
* Creates a {@link GraphTraversalSource} binding a {@link RemoteConnection} to a remote {@link Graph} instances as its
|
|
54
53
|
* reference so that traversals spawned from it will execute over that reference.
|
|
55
|
-
* @param {
|
|
54
|
+
* @param {RemoteConnection} remoteConnection
|
|
56
55
|
* @return {GraphTraversalSource}
|
|
57
56
|
*/
|
|
58
57
|
withRemote(remoteConnection) {
|
|
@@ -75,4 +74,4 @@ class AnonymousTraversalSource {
|
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
module.exports = AnonymousTraversalSource;
|
|
77
|
+
module.exports = AnonymousTraversalSource;
|
package/lib/process/bytecode.js
CHANGED
|
@@ -33,8 +33,7 @@ class Bytecode {
|
|
|
33
33
|
if (!toClone) {
|
|
34
34
|
this.sourceInstructions = [];
|
|
35
35
|
this.stepInstructions = [];
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
36
|
+
} else {
|
|
38
37
|
this.sourceInstructions = [...toClone.sourceInstructions];
|
|
39
38
|
this.stepInstructions = [...toClone.stepInstructions];
|
|
40
39
|
}
|
|
@@ -79,9 +78,12 @@ class Bytecode {
|
|
|
79
78
|
instruction[0] = name;
|
|
80
79
|
for (let i = 1; i < length; i++) {
|
|
81
80
|
const val = values[i - 1];
|
|
82
|
-
if (val instanceof Traversal && val.graph != null)
|
|
83
|
-
throw new Error(
|
|
84
|
-
|
|
81
|
+
if (val instanceof Traversal && val.graph != null) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`The child traversal of ${val} was not spawned anonymously - use ` +
|
|
84
|
+
'the __ class rather than a TraversalSource to construct the child traversal',
|
|
85
|
+
);
|
|
86
|
+
}
|
|
85
87
|
instruction[i] = val;
|
|
86
88
|
}
|
|
87
89
|
return instruction;
|
|
@@ -94,6 +96,29 @@ class Bytecode {
|
|
|
94
96
|
toString() {
|
|
95
97
|
return JSON.stringify([this.sourceInstructions, this.stepInstructions]);
|
|
96
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Adds a new source instructions
|
|
102
|
+
* @param {String} name
|
|
103
|
+
* @param {Array} values
|
|
104
|
+
* @returns {Bytecode}
|
|
105
|
+
*/
|
|
106
|
+
static _createGraphOp(name, values) {
|
|
107
|
+
const bc = new Bytecode();
|
|
108
|
+
bc.addSource(name, values);
|
|
109
|
+
return bc;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Gets the <code>Bytecode</code> that is meant to be sent as "graph operations" to the server.
|
|
114
|
+
* @returns {{rollback: Bytecode, commit: Bytecode}}
|
|
115
|
+
*/
|
|
116
|
+
static get GraphOp() {
|
|
117
|
+
return {
|
|
118
|
+
commit: Bytecode._createGraphOp('tx', ['commit']),
|
|
119
|
+
rollback: Bytecode._createGraphOp('tx', ['rollback']),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
97
122
|
}
|
|
98
123
|
|
|
99
124
|
module.exports = Bytecode;
|