neo4j-driver 1.3.0-beta01 → 1.3.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.
- package/lib/browser/neo4j-web.js +76 -35
- package/lib/browser/neo4j-web.min.js +13 -13
- package/lib/v1/driver.js +3 -3
- package/lib/v1/error.js +9 -0
- package/lib/v1/graph-types.js +2 -2
- package/lib/v1/internal/connector.js +31 -7
- package/lib/v1/internal/routing-util.js +8 -3
- package/lib/v1/record.js +1 -1
- package/lib/v1/result-summary.js +1 -1
- package/lib/v1/routing-driver.js +1 -0
- package/lib/v1/session.js +4 -4
- package/lib/v1/transaction.js +15 -13
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/lib/v1/driver.js
CHANGED
|
@@ -71,8 +71,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
71
71
|
var READ = 'READ',
|
|
72
72
|
WRITE = 'WRITE';
|
|
73
73
|
/**
|
|
74
|
-
* A driver maintains one or more {@link Session
|
|
75
|
-
* Neo4j instance. Through the {@link Session
|
|
74
|
+
* A driver maintains one or more {@link Session}s with a remote
|
|
75
|
+
* Neo4j instance. Through the {@link Session}s you can send statements
|
|
76
76
|
* and retrieve results from the database.
|
|
77
77
|
*
|
|
78
78
|
* Drivers are reasonably expensive to create - you should strive to keep one
|
|
@@ -161,7 +161,7 @@ var Driver = function () {
|
|
|
161
161
|
* will be pulling a session out of the common pool.
|
|
162
162
|
*
|
|
163
163
|
* This comes with some responsibility - make sure you always call
|
|
164
|
-
* {@link
|
|
164
|
+
* {@link close} when you are done using a session, and likewise,
|
|
165
165
|
* make sure you don't close your session before you are done using it. Once
|
|
166
166
|
* it is returned to the pool, the session will be reset to a clean state and
|
|
167
167
|
* made available for others to use.
|
package/lib/v1/error.js
CHANGED
|
@@ -45,8 +45,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
45
45
|
// A common place for constructing error objects, to keep them
|
|
46
46
|
// uniform across the driver surface.
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @type {string}
|
|
50
|
+
*/
|
|
48
51
|
var SERVICE_UNAVAILABLE = 'ServiceUnavailable';
|
|
52
|
+
/**
|
|
53
|
+
* @type {string}
|
|
54
|
+
*/
|
|
49
55
|
var SESSION_EXPIRED = 'SessionExpired';
|
|
56
|
+
/**
|
|
57
|
+
* @type {string}
|
|
58
|
+
*/
|
|
50
59
|
var PROTOCOL_ERROR = 'ProtocolError';
|
|
51
60
|
|
|
52
61
|
function newError(message) {
|
package/lib/v1/graph-types.js
CHANGED
|
@@ -49,7 +49,7 @@ var Node = function () {
|
|
|
49
49
|
/**
|
|
50
50
|
* @constructor
|
|
51
51
|
* @param {Integer} identity - Unique identity
|
|
52
|
-
* @param {Array} labels - Array for all labels
|
|
52
|
+
* @param {Array<string>} labels - Array for all labels
|
|
53
53
|
* @param {Object} properties - Map with node properties
|
|
54
54
|
*/
|
|
55
55
|
function Node(identity, labels, properties) {
|
|
@@ -211,7 +211,7 @@ var Path =
|
|
|
211
211
|
* @constructor
|
|
212
212
|
* @param {Node} start - start node
|
|
213
213
|
* @param {Node} end - end node
|
|
214
|
-
* @param {Array} segments - Array of Segments
|
|
214
|
+
* @param {Array<PathSegment>} segments - Array of Segments
|
|
215
215
|
*/
|
|
216
216
|
function Path(start, end, segments) {
|
|
217
217
|
(0, _classCallCheck3.default)(this, Path);
|
|
@@ -303,7 +303,7 @@ var Connection = function () {
|
|
|
303
303
|
* failing, and the connection getting ejected from the session pool.
|
|
304
304
|
*
|
|
305
305
|
* @param err an error object, forwarded to all current and future subscribers
|
|
306
|
-
* @
|
|
306
|
+
* @protected
|
|
307
307
|
*/
|
|
308
308
|
|
|
309
309
|
|
|
@@ -327,6 +327,12 @@ var Connection = function () {
|
|
|
327
327
|
value: function _handleMessage(msg) {
|
|
328
328
|
var _this = this;
|
|
329
329
|
|
|
330
|
+
if (this._isBroken) {
|
|
331
|
+
// ignore all incoming messages when this connection is broken. all previously pending observers failed
|
|
332
|
+
// with the fatal error. all future observers will fail with same fatal error.
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
330
336
|
var payload = msg.fields[0];
|
|
331
337
|
|
|
332
338
|
switch (msg.signature) {
|
|
@@ -339,7 +345,7 @@ var Connection = function () {
|
|
|
339
345
|
try {
|
|
340
346
|
this._currentObserver.onCompleted(payload);
|
|
341
347
|
} finally {
|
|
342
|
-
this.
|
|
348
|
+
this._updateCurrentObserver();
|
|
343
349
|
}
|
|
344
350
|
break;
|
|
345
351
|
case FAILURE:
|
|
@@ -348,7 +354,7 @@ var Connection = function () {
|
|
|
348
354
|
this._currentFailure = (0, _error.newError)(payload.message, payload.code);
|
|
349
355
|
this._currentObserver.onError(this._currentFailure);
|
|
350
356
|
} finally {
|
|
351
|
-
this.
|
|
357
|
+
this._updateCurrentObserver();
|
|
352
358
|
// Things are now broken. Pending observers will get FAILURE messages routed until
|
|
353
359
|
// We are done handling this failure.
|
|
354
360
|
if (!this._isHandlingFailure) {
|
|
@@ -375,7 +381,7 @@ var Connection = function () {
|
|
|
375
381
|
try {
|
|
376
382
|
if (this._currentFailure && this._currentObserver.onError) this._currentObserver.onError(this._currentFailure);else if (this._currentObserver.onError) this._currentObserver.onError(payload);
|
|
377
383
|
} finally {
|
|
378
|
-
this.
|
|
384
|
+
this._updateCurrentObserver();
|
|
379
385
|
}
|
|
380
386
|
break;
|
|
381
387
|
default:
|
|
@@ -533,6 +539,17 @@ var Connection = function () {
|
|
|
533
539
|
return this._state.initializationCompleted();
|
|
534
540
|
}
|
|
535
541
|
|
|
542
|
+
/*
|
|
543
|
+
* Pop next pending observer form the list of observers and make it current observer.
|
|
544
|
+
* @protected
|
|
545
|
+
*/
|
|
546
|
+
|
|
547
|
+
}, {
|
|
548
|
+
key: '_updateCurrentObserver',
|
|
549
|
+
value: function _updateCurrentObserver() {
|
|
550
|
+
this._currentObserver = this._pendingObservers.shift();
|
|
551
|
+
}
|
|
552
|
+
|
|
536
553
|
/**
|
|
537
554
|
* Synchronize - flush all queued outgoing messages and route their responses
|
|
538
555
|
* to their respective handlers.
|
|
@@ -604,7 +621,8 @@ var ConnectionState = function () {
|
|
|
604
621
|
}
|
|
605
622
|
|
|
606
623
|
/**
|
|
607
|
-
* Wrap the given observer to track connection's initialization state.
|
|
624
|
+
* Wrap the given observer to track connection's initialization state. Connection is closed by the server if
|
|
625
|
+
* processing of INIT message fails so returned observer will handle initialization failure as a fatal error.
|
|
608
626
|
* @param {StreamObserver} observer the observer used for INIT message.
|
|
609
627
|
* @return {StreamObserver} updated observer.
|
|
610
628
|
*/
|
|
@@ -627,8 +645,14 @@ var ConnectionState = function () {
|
|
|
627
645
|
_this10._rejectPromise(error);
|
|
628
646
|
_this10._rejectPromise = null;
|
|
629
647
|
}
|
|
630
|
-
|
|
631
|
-
|
|
648
|
+
|
|
649
|
+
_this10._connection._updateCurrentObserver(); // make sure this same observer will not be called again
|
|
650
|
+
try {
|
|
651
|
+
if (observer && observer.onError) {
|
|
652
|
+
observer.onError(error);
|
|
653
|
+
}
|
|
654
|
+
} finally {
|
|
655
|
+
_this10._connection._handleFatalError(error);
|
|
632
656
|
}
|
|
633
657
|
},
|
|
634
658
|
onCompleted: function onCompleted(metaData) {
|
|
@@ -57,6 +57,7 @@ var CALL_GET_SERVERS = 'CALL dbms.cluster.routing.getServers';
|
|
|
57
57
|
var GET_ROUTING_TABLE_PARAM = 'context';
|
|
58
58
|
var CALL_GET_ROUTING_TABLE = 'CALL dbms.cluster.routing.getRoutingTable({' + GET_ROUTING_TABLE_PARAM + '})';
|
|
59
59
|
var PROCEDURE_NOT_FOUND_CODE = 'Neo.ClientError.Procedure.ProcedureNotFound';
|
|
60
|
+
var UNAUTHORIZED_CODE = 'Neo.ClientError.Security.Unauthorized';
|
|
60
61
|
|
|
61
62
|
var RoutingUtil = function () {
|
|
62
63
|
function RoutingUtil(routingContext) {
|
|
@@ -84,10 +85,14 @@ var RoutingUtil = function () {
|
|
|
84
85
|
if (error.code === PROCEDURE_NOT_FOUND_CODE) {
|
|
85
86
|
// throw when getServers procedure not found because this is clearly a configuration issue
|
|
86
87
|
throw (0, _error.newError)('Server ' + routerAddress + ' could not perform routing. ' + 'Make sure you are connecting to a causal cluster', _error.SERVICE_UNAVAILABLE);
|
|
88
|
+
} else if (error.code === UNAUTHORIZED_CODE) {
|
|
89
|
+
// auth error is a sign of a configuration issue, rediscovery should not proceed
|
|
90
|
+
throw error;
|
|
91
|
+
} else {
|
|
92
|
+
// return nothing when failed to connect because code higher in the callstack is still able to retry with a
|
|
93
|
+
// different session towards a different router
|
|
94
|
+
return null;
|
|
87
95
|
}
|
|
88
|
-
// return nothing when failed to connect because code higher in the callstack is still able to retry with a
|
|
89
|
-
// different session towards a different router
|
|
90
|
-
return null;
|
|
91
96
|
});
|
|
92
97
|
}
|
|
93
98
|
}, {
|
package/lib/v1/record.js
CHANGED
|
@@ -89,7 +89,7 @@ var Record = function () {
|
|
|
89
89
|
* will get three arguments - the value, the key and this record, in that
|
|
90
90
|
* order.
|
|
91
91
|
*
|
|
92
|
-
* @param visitor
|
|
92
|
+
* @param {function(value: Object, key: string, record: Record)} visitor the function to apply to each field.
|
|
93
93
|
*/
|
|
94
94
|
|
|
95
95
|
|
package/lib/v1/result-summary.js
CHANGED
package/lib/v1/routing-driver.js
CHANGED
package/lib/v1/session.js
CHANGED
|
@@ -166,7 +166,7 @@ var Session = function () {
|
|
|
166
166
|
* While a transaction is open the session cannot be used to run statements outside the transaction.
|
|
167
167
|
*
|
|
168
168
|
* @param {string} bookmark - a reference to a previous transaction. DEPRECATED: This parameter is deprecated in
|
|
169
|
-
* favour of {@link Driver#session
|
|
169
|
+
* favour of {@link Driver#session} that accepts an initial bookmark. Session will ensure that all nested
|
|
170
170
|
* transactions are chained with bookmarks to guarantee causal consistency.
|
|
171
171
|
* @returns {Transaction} - New Transaction
|
|
172
172
|
*/
|
|
@@ -203,7 +203,7 @@ var Session = function () {
|
|
|
203
203
|
/**
|
|
204
204
|
* Return the bookmark received following the last completed {@link Transaction}.
|
|
205
205
|
*
|
|
206
|
-
* @return a reference to a previous
|
|
206
|
+
* @return a reference to a previous transaction
|
|
207
207
|
*/
|
|
208
208
|
|
|
209
209
|
}, {
|
|
@@ -213,7 +213,7 @@ var Session = function () {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
|
-
* Execute given unit of work in a {@link
|
|
216
|
+
* Execute given unit of work in a {@link READ} transaction.
|
|
217
217
|
*
|
|
218
218
|
* Transaction will automatically be committed unless the given function throws or returns a rejected promise.
|
|
219
219
|
* Some failures of the given function or the commit itself will be retried with exponential backoff with initial
|
|
@@ -233,7 +233,7 @@ var Session = function () {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
/**
|
|
236
|
-
* Execute given unit of work in a {@link
|
|
236
|
+
* Execute given unit of work in a {@link WRITE} transaction.
|
|
237
237
|
*
|
|
238
238
|
* Transaction will automatically be committed unless the given function throws or returns a rejected promise.
|
|
239
239
|
* Some failures of the given function or the commit itself will be retried with exponential backoff with initial
|
package/lib/v1/transaction.js
CHANGED
|
@@ -108,7 +108,7 @@ var Transaction = function () {
|
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* Run Cypher statement
|
|
111
|
-
* Could be called with a statement object i.e.: {statement: "MATCH ...", parameters: {param: 1}}
|
|
111
|
+
* Could be called with a statement object i.e.: <code>{statement: "MATCH ...", parameters: {param: 1}}</code>
|
|
112
112
|
* or with the statement and parameters as separate arguments.
|
|
113
113
|
* @param {mixed} statement - Cypher statement to execute
|
|
114
114
|
* @param {Object} parameters - Map with parameters to use in statement
|
|
@@ -270,7 +270,7 @@ var _states = {
|
|
|
270
270
|
return observer.onError(error);
|
|
271
271
|
});
|
|
272
272
|
|
|
273
|
-
return
|
|
273
|
+
return _newRunResult(observer, statement, parameters, function () {
|
|
274
274
|
return observer.serverMeta();
|
|
275
275
|
});
|
|
276
276
|
}
|
|
@@ -283,15 +283,15 @@ var _states = {
|
|
|
283
283
|
observer.onError({
|
|
284
284
|
error: "Cannot commit statements in this transaction, because previous statements in the " + "transaction has failed and the transaction has been rolled back. Please start a new" + " transaction to run another statement."
|
|
285
285
|
});
|
|
286
|
-
return { result:
|
|
286
|
+
return { result: _newDummyResult(observer, "COMMIT", {}), state: _states.FAILED };
|
|
287
287
|
},
|
|
288
288
|
rollback: function rollback(connectionHolder, observer) {
|
|
289
289
|
observer.onError({ error: "Cannot rollback transaction, because previous statements in the " + "transaction has failed and the transaction has already been rolled back." });
|
|
290
|
-
return { result:
|
|
290
|
+
return { result: _newDummyResult(observer, "ROLLBACK", {}), state: _states.FAILED };
|
|
291
291
|
},
|
|
292
292
|
run: function run(connectionHolder, observer, statement, parameters) {
|
|
293
293
|
observer.onError({ error: "Cannot run statement, because previous statements in the " + "transaction has failed and the transaction has already been rolled back." });
|
|
294
|
-
return
|
|
294
|
+
return _newDummyResult(observer, statement, parameters);
|
|
295
295
|
}
|
|
296
296
|
},
|
|
297
297
|
|
|
@@ -301,15 +301,15 @@ var _states = {
|
|
|
301
301
|
observer.onError({
|
|
302
302
|
error: "Cannot commit statements in this transaction, because commit has already been successfully called on the transaction and transaction has been closed. Please start a new" + " transaction to run another statement."
|
|
303
303
|
});
|
|
304
|
-
return { result:
|
|
304
|
+
return { result: _newDummyResult(observer, "COMMIT", {}), state: _states.SUCCEEDED };
|
|
305
305
|
},
|
|
306
306
|
rollback: function rollback(connectionHolder, observer) {
|
|
307
307
|
observer.onError({ error: "Cannot rollback transaction, because transaction has already been successfully closed." });
|
|
308
|
-
return { result:
|
|
308
|
+
return { result: _newDummyResult(observer, "ROLLBACK", {}), state: _states.SUCCEEDED };
|
|
309
309
|
},
|
|
310
310
|
run: function run(connectionHolder, observer, statement, parameters) {
|
|
311
311
|
observer.onError({ error: "Cannot run statement, because transaction has already been successfully closed." });
|
|
312
|
-
return
|
|
312
|
+
return _newDummyResult(observer, statement, parameters);
|
|
313
313
|
}
|
|
314
314
|
},
|
|
315
315
|
|
|
@@ -319,15 +319,15 @@ var _states = {
|
|
|
319
319
|
observer.onError({
|
|
320
320
|
error: "Cannot commit this transaction, because it has already been rolled back."
|
|
321
321
|
});
|
|
322
|
-
return { result:
|
|
322
|
+
return { result: _newDummyResult(observer, "COMMIT", {}), state: _states.ROLLED_BACK };
|
|
323
323
|
},
|
|
324
324
|
rollback: function rollback(connectionHolder, observer) {
|
|
325
325
|
observer.onError({ error: "Cannot rollback transaction, because transaction has already been rolled back." });
|
|
326
|
-
return { result:
|
|
326
|
+
return { result: _newDummyResult(observer, "ROLLBACK", {}), state: _states.ROLLED_BACK };
|
|
327
327
|
},
|
|
328
328
|
run: function run(connectionHolder, observer, statement, parameters) {
|
|
329
329
|
observer.onError({ error: "Cannot run statement, because transaction has already been rolled back." });
|
|
330
|
-
return
|
|
330
|
+
return _newDummyResult(observer, statement, parameters);
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
};
|
|
@@ -357,8 +357,9 @@ function _runPullAll(msg, connectionHolder, observer) {
|
|
|
357
357
|
* @param {object} parameters - the parameters for cypher statement that produced the result.
|
|
358
358
|
* @param {function} metadataSupplier - the function that returns a metadata object.
|
|
359
359
|
* @return {Result} new result.
|
|
360
|
+
* @private
|
|
360
361
|
*/
|
|
361
|
-
function
|
|
362
|
+
function _newRunResult(observer, statement, parameters, metadataSupplier) {
|
|
362
363
|
return new _result2.default(observer, statement, parameters, metadataSupplier, _connectionHolder.EMPTY_CONNECTION_HOLDER);
|
|
363
364
|
}
|
|
364
365
|
|
|
@@ -370,8 +371,9 @@ function newRunResult(observer, statement, parameters, metadataSupplier) {
|
|
|
370
371
|
* @param {string} statement - the cypher statement that produced the result.
|
|
371
372
|
* @param {object} parameters - the parameters for cypher statement that produced the result.
|
|
372
373
|
* @return {Result} new result.
|
|
374
|
+
* @private
|
|
373
375
|
*/
|
|
374
|
-
function
|
|
376
|
+
function _newDummyResult(observer, statement, parameters) {
|
|
375
377
|
return new _result2.default(observer, statement, parameters, emptyMetadataSupplier, _connectionHolder.EMPTY_CONNECTION_HOLDER);
|
|
376
378
|
}
|
|
377
379
|
|
package/lib/version.js
CHANGED
|
@@ -29,4 +29,4 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
29
29
|
// This is set up this way to keep the version in the code in
|
|
30
30
|
// sync with the npm package version, and to allow the build
|
|
31
31
|
// system to control version names at packaging time.
|
|
32
|
-
exports.default = "1.3.0
|
|
32
|
+
exports.default = "1.3.0";
|