Socket
Socket
Sign inDemoInstall

neo4j-driver

Package Overview
Dependencies
Maintainers
2
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

neo4j-driver - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0-rc1

lib/v1/internal/connection-holder.js

18

gulpfile.babel.js

@@ -167,9 +167,6 @@ /**

return gulp.src('test/**/*.test.js')
.pipe(jasmine({
// reporter: new reporters.JUnitXmlReporter({
// savePath: "build/nodejs-test-reports",
// consolidateAll: false
// }),
includeStackTrace: true
}));
.pipe(jasmine({
includeStackTrace: true,
verbose: true
}));
});

@@ -180,7 +177,4 @@

.pipe(jasmine({
// reporter: new reporters.JUnitXmlReporter({
// savePath: "build/nodejs-test-reports",
// consolidateAll: false
// }),
includeStackTrace: true
includeStackTrace: true,
verbose: true
}));

@@ -187,0 +181,0 @@ });

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -8,61 +8,47 @@ Object.defineProperty(exports, "__esModule", {

var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require("babel-runtime/helpers/get");
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require("babel-runtime/helpers/inherits");
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _promise = require("babel-runtime/core-js/promise");
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _promise2 = _interopRequireDefault(_promise);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require("babel-runtime/helpers/createClass");
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _session = require("./session");
var _session = require('./session');
var _session2 = _interopRequireDefault(_session);
var _pool = require("./internal/pool");
var _pool = require('./internal/pool');
var _pool2 = _interopRequireDefault(_pool);
var _connector = require("./internal/connector");
var _connector = require('./internal/connector');
var _streamObserver = require("./internal/stream-observer");
var _streamObserver = require('./internal/stream-observer');
var _streamObserver2 = _interopRequireDefault(_streamObserver);
var _error = require("./error");
var _error = require('./error');
var _connectionProviders = require('./internal/connection-providers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var READ = 'READ',
WRITE = 'WRITE';
/**
* A driver maintains one or more {@link Session sessions} with a remote
* Neo4j instance. Through the {@link Session sessions} you can send statements
* and retrieve results from the database.
*
* Drivers are reasonably expensive to create - you should strive to keep one
* driver instance around per Neo4j Instance you connect to.
*
* @access public
*/
/**
* Copyright (c) 2002-2017 "Neo Technology,","

@@ -86,2 +72,15 @@ * Network Engine for Objects in Lund AB [http://neotechnology.com]

var READ = 'READ',
WRITE = 'WRITE';
/**
* A driver maintains one or more {@link Session sessions} with a remote
* Neo4j instance. Through the {@link Session sessions} you can send statements
* and retrieve results from the database.
*
* Drivers are reasonably expensive to create - you should strive to keep one
* driver instance around per Neo4j Instance you connect to.
*
* @access public
*/
var Driver = function () {

@@ -109,2 +108,3 @@ /**

this._pool = new _pool2.default(this._createConnection.bind(this), this._destroyConnection.bind(this), Driver._validateConnection.bind(this), config.connectionPoolSize);
this._connectionProvider = this._createConnectionProvider(url, this._pool, this._driverOnErrorCallback.bind(this));
}

@@ -120,3 +120,3 @@

(0, _createClass3.default)(Driver, [{
key: "_createConnection",
key: '_createConnection',
value: function _createConnection(url, release) {

@@ -143,3 +143,3 @@ var sessionId = this._sessionIdGenerator++;

}, {
key: "_destroyConnection",
key: '_destroyConnection',

@@ -168,3 +168,5 @@

*
* @param {String} mode of session - optional
* @param {string} [mode=WRITE] the access mode of this session, allowed values are {@link READ} and {@link WRITE}.
* @param {string} [bookmark=null] the initial reference to some previous transaction. Value is optional and
* absence indicates that that the bookmark does not exist or is unknown.
* @return {Session} new session.

@@ -174,52 +176,14 @@ */

}, {
key: "session",
value: function session(mode) {
var _this = this;
key: 'session',
value: function session(mode, bookmark) {
var sessionMode = Driver._validateSessionMode(mode);
var connectionPromise = this._acquireConnection(sessionMode);
connectionPromise.catch(function (err) {
if (_this.onError && err.code === _error.SERVICE_UNAVAILABLE) {
_this.onError(err);
} else {
//we don't need to tell the driver about this error
}
});
return this._createSession(connectionPromise, this._releaseConnection(connectionPromise));
return this._createSession(sessionMode, this._connectionProvider, bookmark, this._config);
}
/**
* The returned function gets called on Session#close(), and is where we return the pooled 'connection' instance.
* We don't pool Session instances, to avoid users using the Session after they've called close.
* The `Session` object is just a thin wrapper around Connection anyway, so it makes little difference.
* @param {Promise} connectionPromise - promise resolved with the connection.
* @return {function(callback: function)} - function that releases the connection and then executes an optional callback.
* @protected
*/
}, {
key: "_releaseConnection",
value: function _releaseConnection(connectionPromise) {
return function (userDefinedCallback) {
connectionPromise.then(function (conn) {
// Queue up a 'reset', to ensure the next user gets a clean session to work with.
conn.reset();
conn.sync();
key: '_createConnectionProvider',
// Return connection to the pool
conn._release();
}).catch(function (ignoredError) {});
if (userDefinedCallback) {
userDefinedCallback();
}
};
}
}, {
key: "_acquireConnection",
//Extension point
value: function _acquireConnection(mode) {
return _promise2.default.resolve(this._pool.acquire(this._url));
value: function _createConnectionProvider(address, connectionPool, driverOnErrorCallback) {
return new _connectionProviders.DirectConnectionProvider(address, connectionPool, driverOnErrorCallback);
}

@@ -230,6 +194,16 @@

}, {
key: "_createSession",
value: function _createSession(connectionPromise, cb) {
return new _session2.default(connectionPromise, cb);
key: '_createSession',
value: function _createSession(mode, connectionProvider, bookmark, config) {
return new _session2.default(mode, connectionProvider, bookmark, config);
}
}, {
key: '_driverOnErrorCallback',
value: function _driverOnErrorCallback(error) {
var userDefinedOnErrorCallback = this.onError;
if (userDefinedOnErrorCallback && error.code === _error.SERVICE_UNAVAILABLE) {
userDefinedOnErrorCallback(error);
} else {
// we don't need to tell the driver about this error
}
}

@@ -243,3 +217,3 @@ /**

}, {
key: "close",
key: 'close',
value: function close() {

@@ -254,3 +228,3 @@ for (var sessionId in this._openSessions) {

}], [{
key: "_validateConnection",
key: '_validateConnection',
value: function _validateConnection(conn) {

@@ -260,3 +234,3 @@ return conn.isOpen();

}, {
key: "_validateSessionMode",
key: '_validateSessionMode',
value: function _validateSessionMode(rawMode) {

@@ -282,15 +256,15 @@ var mode = rawMode || WRITE;

var _this2 = (0, _possibleConstructorReturn3.default)(this, (_ConnectionStreamObserver.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver)).call(this));
var _this = (0, _possibleConstructorReturn3.default)(this, (_ConnectionStreamObserver.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver)).call(this));
_this2._driver = driver;
_this2._conn = conn;
_this2._hasFailed = false;
return _this2;
_this._driver = driver;
_this._conn = conn;
_this._hasFailed = false;
return _this;
}
(0, _createClass3.default)(_ConnectionStreamObserver, [{
key: "onError",
key: 'onError',
value: function onError(error) {
if (!this._hasFailed) {
(0, _get3.default)(_ConnectionStreamObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver.prototype), "onError", this).call(this, error);
(0, _get3.default)(_ConnectionStreamObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver.prototype), 'onError', this).call(this, error);
if (this._driver.onError) {

@@ -303,3 +277,3 @@ this._driver.onError(error);

}, {
key: "onCompleted",
key: 'onCompleted',
value: function onCompleted(message) {

@@ -306,0 +280,0 @@ if (this._driver.onCompleted) {

@@ -51,3 +51,3 @@ "use strict";

* @constructor
* @param {string} identity - Unique identity
* @param {Integer} identity - Unique identity
* @param {Array} labels - Array for all labels

@@ -95,5 +95,5 @@ * @param {Object} properties - Map with node properties

* @constructor
* @param {string} identity - Unique identity
* @param {string} start - Identity of start Node
* @param {string} end - Identity of end Node
* @param {Integer} identity - Unique identity
* @param {Integer} start - Identity of start Node
* @param {Integer} end - Identity of end Node
* @param {string} type - Relationship type

@@ -141,3 +141,3 @@ * @param {Object} properties - Map with relationship properties

* @constructor
* @param {string} identity - Unique identity
* @param {Integer} identity - Unique identity
* @param {string} type - Relationship type

@@ -156,4 +156,4 @@ * @param {Object} properties - Map with relationship properties

* Bind relationship
* @param {string} start - Indentity of start node
* @param {string} end - Indentity of end node
* @param {Integer} start - Identity of start node
* @param {Integer} end - Identity of end node
* @return {Relationship} - Created relationship

@@ -196,5 +196,5 @@ */

* @constructor
* @param {string} start - Identity of start Node
* @param {Relationship} rel - Relationship segment
* @param {string} end - Identity of end Node
* @param {Node} start - start node
* @param {Relationship} rel - relationship that connects start and end node
* @param {Node} end - end node
*/

@@ -201,0 +201,0 @@ function PathSegment(start, rel, end) {

@@ -134,2 +134,12 @@ 'use strict';

* knownHosts:"~/.neo4j/known_hosts",
*
* // The max number of connections that are allowed idle in the pool at any time.
* // Connection will be destroyed if this threshold is exceeded.
* connectionPoolSize: 50,
*
* // Specify the maximum time in milliseconds transactions are allowed to retry via
* // {@link Session#readTransaction()} and {@link Session#writeTransaction()} functions. These functions
* // will retry the given unit of work on `ServiceUnavailable`, `SessionExpired` and transient errors with
* // exponential backoff using initial delay of 1 second. Default value is 30000 which is 30 seconds.
* maxTransactionRetryTime: 30000,
* }

@@ -136,0 +146,0 @@ *

@@ -456,10 +456,10 @@ 'use strict';

/** Queue a RESET-message to be sent to the database */
/** Queue a RESET-message to be sent to the database. Mutes failure handling. */
}, {
key: 'reset',
value: function reset(observer) {
key: 'resetAsync',
value: function resetAsync(observer) {
var _this6 = this;
log("C", "RESET");
log("C", "RESET_ASYNC");
this._isHandlingFailure = true;

@@ -484,2 +484,17 @@ var self = this;

/** Queue a RESET-message to be sent to the database */
}, {
key: 'reset',
value: function reset(observer) {
var _this7 = this;
log('C', 'RESET');
this._queueObserver(observer);
this._packer.packStruct(RESET, [], function (err) {
return _this7._handleFatalError(err);
});
this._chunker.messageBoundary();
}
/** Queue a ACK_FAILURE-message to be sent to the database */

@@ -490,3 +505,3 @@

value: function _ackFailure(observer) {
var _this7 = this;
var _this8 = this;

@@ -496,3 +511,3 @@ log("C", "ACK_FAILURE");

this._packer.packStruct(ACK_FAILURE, [], function (err) {
return _this7._handleFatalError(err);
return _this8._handleFatalError(err);
});

@@ -558,6 +573,6 @@ this._chunker.messageBoundary();

value: function _packable(value) {
var _this8 = this;
var _this9 = this;
return this._packer.packable(value, function (err) {
return _this8._handleFatalError(err);
return _this9._handleFatalError(err);
});

@@ -564,0 +579,0 @@ }

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -7,21 +7,21 @@ Object.defineProperty(exports, "__esModule", {

var _stringify = require("babel-runtime/core-js/json/stringify");
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require("babel-runtime/helpers/createClass");
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _roundRobinArray = require("./round-robin-array");
var _roundRobinArray = require('./round-robin-array');
var _roundRobinArray2 = _interopRequireDefault(_roundRobinArray);
var _error = require("../error");
var _error = require('../error');
var _integer = require("../integer");
var _integer = require('../integer');

@@ -59,3 +59,3 @@ var _integer2 = _interopRequireDefault(_integer);

(0, _createClass3.default)(GetServersUtil, [{
key: "callGetServers",
key: 'callGetServers',
value: function callGetServers(session, routerAddress) {

@@ -76,3 +76,3 @@ return session.run(PROCEDURE_CALL).then(function (result) {

}, {
key: "parseTtl",
key: 'parseTtl',
value: function parseTtl(record, routerAddress) {

@@ -92,3 +92,3 @@ try {

}, {
key: "parseServers",
key: 'parseServers',
value: function parseServers(record, routerAddress) {

@@ -95,0 +95,0 @@ try {

@@ -38,3 +38,3 @@ "use strict";

*
* record.get("n.name")
* record.get("u.name")
*

@@ -41,0 +41,0 @@ * Or by it's position:

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -7,18 +7,20 @@ Object.defineProperty(exports, "__esModule", {

var _promise = require("babel-runtime/core-js/promise");
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require("babel-runtime/helpers/createClass");
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _resultSummary = require("./result-summary");
var _resultSummary = require('./result-summary');
var _resultSummary2 = _interopRequireDefault(_resultSummary);
var _connectionHolder = require('./internal/connection-holder');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -30,2 +32,21 @@

*/
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Result = function () {

@@ -40,4 +61,5 @@ /**

* @param metaSupplier function, when called provides metadata
* @param {ConnectionHolder} connectionHolder - to be notified when result is either fully consumed or error happened.
*/
function Result(streamObserver, statement, parameters, metaSupplier) {
function Result(streamObserver, statement, parameters, metaSupplier, connectionHolder) {
(0, _classCallCheck3.default)(this, Result);

@@ -52,2 +74,3 @@

};
this._connectionHolder = connectionHolder || _connectionHolder.EMPTY_CONNECTION_HOLDER;
}

@@ -63,3 +86,3 @@

(0, _createClass3.default)(Result, [{
key: "_createPromise",
key: '_createPromise',
value: function _createPromise() {

@@ -97,3 +120,3 @@ if (this._p) {

}, {
key: "then",
key: 'then',
value: function then(onFulfilled, onRejected) {

@@ -112,3 +135,3 @@ this._createPromise();

}, {
key: "catch",
key: 'catch',
value: function _catch(onRejected) {

@@ -131,3 +154,3 @@ this._createPromise();

}, {
key: "subscribe",
key: 'subscribe',
value: function subscribe(observer) {

@@ -147,8 +170,24 @@ var _this = this;

var sum = new _resultSummary2.default(_this._statement, _this._parameters, metadata);
onCompletedOriginal.call(observer, sum);
// notify connection holder that the used connection is not needed any more because result has
// been fully consumed; call the original onCompleted callback after that
self._connectionHolder.releaseConnection().then(function () {
onCompletedOriginal.call(observer, sum);
});
};
observer.onCompleted = onCompletedWrapper;
observer.onError = observer.onError || function (err) {
console.log("Uncaught error when processing result: " + err);
var onErrorOriginal = observer.onError || function (error) {
console.log("Uncaught error when processing result: " + error);
};
var onErrorWrapper = function onErrorWrapper(error) {
// notify connection holder that the used connection is not needed any more because error happened
// and result can't bee consumed any further; call the original onError callback after that
self._connectionHolder.releaseConnection().then(function () {
onErrorOriginal.call(observer, error);
});
};
observer.onError = onErrorWrapper;
this._streamObserver.subscribe(observer);

@@ -158,21 +197,4 @@ }

return Result;
}(); /**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
}();
exports.default = Result;

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -7,46 +7,32 @@ Object.defineProperty(exports, "__esModule", {

var _promise = require("babel-runtime/core-js/promise");
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _promise2 = _interopRequireDefault(_promise);
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require("babel-runtime/helpers/createClass");
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require("babel-runtime/helpers/inherits");
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _session = require("./session");
var _session = require('./session');
var _session2 = _interopRequireDefault(_session);
var _driver = require("./driver");
var _driver = require('./driver');
var _error = require("./error");
var _error = require('./error');
var _roundRobinArray = require("./internal/round-robin-array");
var _connectionProviders = require('./internal/connection-providers');
var _roundRobinArray2 = _interopRequireDefault(_roundRobinArray);
var _routingTable = require("./internal/routing-table");
var _routingTable2 = _interopRequireDefault(_routingTable);
var _rediscovery = require("./internal/rediscovery");
var _rediscovery2 = _interopRequireDefault(_rediscovery);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -83,23 +69,20 @@

(0, _classCallCheck3.default)(this, RoutingDriver);
var _this = (0, _possibleConstructorReturn3.default)(this, (RoutingDriver.__proto__ || (0, _getPrototypeOf2.default)(RoutingDriver)).call(this, url, userAgent, token, RoutingDriver._validateConfig(config)));
_this._routingTable = new _routingTable2.default(new _roundRobinArray2.default([url]));
_this._rediscovery = new _rediscovery2.default();
return _this;
return (0, _possibleConstructorReturn3.default)(this, (RoutingDriver.__proto__ || (0, _getPrototypeOf2.default)(RoutingDriver)).call(this, url, userAgent, token, RoutingDriver._validateConfig(config)));
}
(0, _createClass3.default)(RoutingDriver, [{
key: "_createSession",
value: function _createSession(connectionPromise, cb) {
key: '_createConnectionProvider',
value: function _createConnectionProvider(address, connectionPool, driverOnErrorCallback) {
return new _connectionProviders.LoadBalancer(address, connectionPool, driverOnErrorCallback);
}
}, {
key: '_createSession',
value: function _createSession(mode, connectionProvider, bookmark, config) {
var _this2 = this;
return new RoutingSession(connectionPromise, cb, function (error, conn) {
return new RoutingSession(mode, connectionProvider, bookmark, config, function (error, conn) {
if (error.code === _error.SERVICE_UNAVAILABLE || error.code === _error.SESSION_EXPIRED) {
// connection is undefined if error happened before connection was acquired
if (conn) {
_this2._forget(conn.url);
} else {
connectionPromise.then(function (conn) {
_this2._forget(conn.url);
}).catch(function () {/*ignore*/});
_this2._connectionProvider.forget(conn.url);
}

@@ -109,9 +92,6 @@ return error;

var url = 'UNKNOWN';
// connection is undefined if error happened before connection was acquired
if (conn) {
url = conn.url;
_this2._routingTable.forgetWriter(conn.url);
} else {
connectionPromise.then(function (conn) {
_this2._routingTable.forgetWriter(conn.url);
}).catch(function () {/*ignore*/});
_this2._connectionProvider.forgetWriter(conn.url);
}

@@ -124,109 +104,4 @@ return (0, _error.newError)('No longer possible to write to server at ' + url, _error.SESSION_EXPIRED);

}
}, {
key: "_acquireConnection",
value: function _acquireConnection(mode) {
var _this3 = this;
return this._freshRoutingTable().then(function (routingTable) {
if (mode === _driver.READ) {
return _this3._acquireConnectionToServer(routingTable.readers, "read");
} else if (mode === _driver.WRITE) {
return _this3._acquireConnectionToServer(routingTable.writers, "write");
} else {
throw (0, _error.newError)('Illegal session mode ' + mode);
}
});
}
}, {
key: "_acquireConnectionToServer",
value: function _acquireConnectionToServer(serversRoundRobinArray, serverName) {
var address = serversRoundRobinArray.next();
if (!address) {
return _promise2.default.reject((0, _error.newError)('No ' + serverName + ' servers available', _error.SESSION_EXPIRED));
}
return this._pool.acquire(address);
}
}, {
key: "_freshRoutingTable",
value: function _freshRoutingTable() {
var currentRoutingTable = this._routingTable;
if (!currentRoutingTable.isStale()) {
return _promise2.default.resolve(currentRoutingTable);
}
return this._refreshRoutingTable(currentRoutingTable);
}
}, {
key: "_refreshRoutingTable",
value: function _refreshRoutingTable(currentRoutingTable) {
var _this4 = this;
var knownRouters = currentRoutingTable.routers.toArray();
var refreshedTablePromise = knownRouters.reduce(function (refreshedTablePromise, currentRouter, currentIndex) {
return refreshedTablePromise.then(function (newRoutingTable) {
if (newRoutingTable) {
if (!newRoutingTable.writers.isEmpty()) {
// valid routing table was fetched - just return it, try next router otherwise
return newRoutingTable;
}
} else {
// returned routing table was undefined, this means a connection error happened and we need to forget the
// previous router and try the next one
var previousRouter = knownRouters[currentIndex - 1];
if (previousRouter) {
currentRoutingTable.forgetRouter(previousRouter);
}
}
// try next router
var session = _this4._createSessionForRediscovery(currentRouter);
return _this4._rediscovery.lookupRoutingTableOnRouter(session, currentRouter);
});
}, _promise2.default.resolve(null));
return refreshedTablePromise.then(function (newRoutingTable) {
if (newRoutingTable && !newRoutingTable.writers.isEmpty()) {
_this4._updateRoutingTable(newRoutingTable);
return newRoutingTable;
}
throw (0, _error.newError)('Could not perform discovery. No routing servers available.', _error.SERVICE_UNAVAILABLE);
});
}
}, {
key: "_createSessionForRediscovery",
value: function _createSessionForRediscovery(routerAddress) {
var connection = this._pool.acquire(routerAddress);
var connectionPromise = _promise2.default.resolve(connection);
// error transformer here is a no-op unlike the one in a regular session, this is so because errors are
// handled in the rediscovery promise chain and we do not need to do this in the error transformer
var errorTransformer = function errorTransformer(error) {
return error;
};
return new RoutingSession(connectionPromise, this._releaseConnection(connectionPromise), errorTransformer);
}
}, {
key: "_forget",
value: function _forget(url) {
this._routingTable.forget(url);
this._pool.purge(url);
}
}, {
key: "_updateRoutingTable",
value: function _updateRoutingTable(newRoutingTable) {
var _this5 = this;
var currentRoutingTable = this._routingTable;
// close old connections to servers not present in the new routing table
var staleServers = currentRoutingTable.serversDiff(newRoutingTable);
staleServers.forEach(function (server) {
return _this5._pool.purge;
});
// make this driver instance aware of the new table
this._routingTable = newRoutingTable;
}
}], [{
key: "_validateConfig",
key: '_validateConfig',
value: function _validateConfig(config) {

@@ -245,13 +120,13 @@ if (config.trust === 'TRUST_ON_FIRST_USE') {

function RoutingSession(connectionPromise, onClose, onFailedConnection) {
function RoutingSession(mode, connectionProvider, bookmark, config, onFailedConnection) {
(0, _classCallCheck3.default)(this, RoutingSession);
var _this6 = (0, _possibleConstructorReturn3.default)(this, (RoutingSession.__proto__ || (0, _getPrototypeOf2.default)(RoutingSession)).call(this, connectionPromise, onClose));
var _this3 = (0, _possibleConstructorReturn3.default)(this, (RoutingSession.__proto__ || (0, _getPrototypeOf2.default)(RoutingSession)).call(this, mode, connectionProvider, bookmark, config));
_this6._onFailedConnection = onFailedConnection;
return _this6;
_this3._onFailedConnection = onFailedConnection;
return _this3;
}
(0, _createClass3.default)(RoutingSession, [{
key: "_onRunFailure",
key: '_onRunFailure',
value: function _onRunFailure() {

@@ -258,0 +133,0 @@ return this._onFailedConnection;

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -7,50 +7,62 @@ Object.defineProperty(exports, "__esModule", {

var _assign = require("babel-runtime/core-js/object/assign");
var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require("babel-runtime/helpers/get");
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require("babel-runtime/helpers/inherits");
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _typeof2 = require("babel-runtime/helpers/typeof");
var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require("babel-runtime/helpers/createClass");
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _streamObserver = require("./internal/stream-observer");
var _streamObserver = require('./internal/stream-observer');
var _streamObserver2 = _interopRequireDefault(_streamObserver);
var _result = require("./result");
var _result = require('./result');
var _result2 = _interopRequireDefault(_result);
var _transaction = require("./transaction");
var _transaction = require('./transaction');
var _transaction2 = _interopRequireDefault(_transaction);
var _error = require("./error");
var _error = require('./error');
var _util = require("./internal/util");
var _util = require('./internal/util');
var _connectionHolder = require('./internal/connection-holder');
var _connectionHolder2 = _interopRequireDefault(_connectionHolder);
var _driver = require('./driver');
var _driver2 = _interopRequireDefault(_driver);
var _transactionExecutor = require('./internal/transaction-executor');
var _transactionExecutor2 = _interopRequireDefault(_transactionExecutor);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -64,14 +76,39 @@

/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Session = function () {
/**
* @constructor
* @param {Promise.<Connection>} connectionPromise - Promise of a connection to use
* @param {function()} onClose - Function to be called on connection close
* @param {string} mode the default access mode for this session.
* @param {ConnectionProvider} connectionProvider - the connection provider to acquire connections from.
* @param {string} [bookmark=undefined] - the initial bookmark for this session.
* @param {Object} [config={}] - this driver configuration.
*/
function Session(connectionPromise, onClose) {
function Session(mode, connectionProvider, bookmark, config) {
(0, _classCallCheck3.default)(this, Session);
this._connectionPromise = connectionPromise;
this._onClose = onClose;
this._mode = mode;
this._readConnectionHolder = new _connectionHolder2.default(_driver.READ, connectionProvider);
this._writeConnectionHolder = new _connectionHolder2.default(_driver.WRITE, connectionProvider);
this._open = true;
this._hasTx = false;
this._lastBookmark = bookmark;
this._transactionExecutor = _createTransactionExecutor(config);
}

@@ -90,7 +127,7 @@

(0, _createClass3.default)(Session, [{
key: "run",
key: 'run',
value: function run(statement) {
var parameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if ((typeof statement === "undefined" ? "undefined" : (0, _typeof3.default)(statement)) === 'object' && statement.text) {
if ((typeof statement === 'undefined' ? 'undefined' : (0, _typeof3.default)(statement)) === 'object' && statement.text) {
parameters = statement.parameters || {};

@@ -102,10 +139,12 @@ statement = statement.text;

var streamObserver = new _RunObserver(this._onRunFailure());
var connectionHolder = this._connectionHolderWithMode(this._mode);
if (!this._hasTx) {
this._connectionPromise.then(function (conn) {
streamObserver.resolveConnection(conn);
conn.run(statement, parameters, streamObserver);
conn.pullAll(streamObserver);
conn.sync();
}).catch(function (err) {
return streamObserver.onError(err);
connectionHolder.initializeConnection();
connectionHolder.getConnection().then(function (connection) {
streamObserver.resolveConnection(connection);
connection.run(statement, parameters, streamObserver);
connection.pullAll(streamObserver);
connection.sync();
}).catch(function (error) {
return streamObserver.onError(error);
});

@@ -117,3 +156,3 @@ } else {

return streamObserver.meta();
});
}, connectionHolder);
}

@@ -127,2 +166,5 @@

*
* @param {string} bookmark - a reference to a previous transaction. DEPRECATED: This parameter is deprecated in
* favour of {@link Driver#session(string)} that accepts an initial bookmark. Session will ensure that all nested
* transactions are chained with bookmarks to guarantee causal consistency.
* @returns {Transaction} - New Transaction

@@ -132,23 +174,38 @@ */

}, {
key: "beginTransaction",
key: 'beginTransaction',
value: function beginTransaction(bookmark) {
return this._beginTransaction(this._mode, bookmark);
}
}, {
key: '_beginTransaction',
value: function _beginTransaction(accessMode, bookmark) {
var _this = this;
if (bookmark) {
(0, _util.assertString)(bookmark, "Bookmark");
(0, _util.assertString)(bookmark, 'Bookmark');
this._updateBookmark(bookmark);
}
if (this._hasTx) {
throw (0, _error.newError)("You cannot begin a transaction on a session with an " + "open transaction; either run from within the transaction or use a " + "different session.");
throw (0, _error.newError)('You cannot begin a transaction on a session with an open transaction; ' + 'either run from within the transaction or use a different session.');
}
var mode = _driver2.default._validateSessionMode(accessMode);
var connectionHolder = this._connectionHolderWithMode(mode);
connectionHolder.initializeConnection();
this._hasTx = true;
return new _transaction2.default(this._connectionPromise, function () {
return new _transaction2.default(connectionHolder, function () {
_this._hasTx = false;
}, this._onRunFailure(), bookmark, function (bookmark) {
_this._lastBookmark = bookmark;
});
}, this._onRunFailure(), this._lastBookmark, this._updateBookmark.bind(this));
}
/**
* Return the bookmark received following the last completed {@link Transaction}.
*
* @return a reference to a previous transac'tion
*/
}, {
key: "lastBookmark",
key: 'lastBookmark',
value: function lastBookmark() {

@@ -159,4 +216,60 @@ return this._lastBookmark;

/**
* Execute given unit of work in a {@link Driver#READ} transaction.
*
* Transaction will automatically be committed unless the given function throws or returns a rejected promise.
* Some failures of the given function or the commit itself will be retried with exponential backoff with initial
* delay of 1 second and maximum retry time of 30 seconds. Maximum retry time is configurable via driver config's
* <code>maxTransactionRetryTime</code> property in milliseconds.
*
* @param {function(tx: Transaction): Promise} transactionWork - callback that executes operations against
* a given {@link Transaction}.
* @return {Promise} resolved promise as returned by the given function or rejected promise when given
* function or commit fails.
*/
}, {
key: 'readTransaction',
value: function readTransaction(transactionWork) {
return this._runTransaction(_driver.READ, transactionWork);
}
/**
* Execute given unit of work in a {@link Driver#WRITE} transaction.
*
* Transaction will automatically be committed unless the given function throws or returns a rejected promise.
* Some failures of the given function or the commit itself will be retried with exponential backoff with initial
* delay of 1 second and maximum retry time of 30 seconds. Maximum retry time is configurable via driver config's
* <code>maxTransactionRetryTime</code> property in milliseconds.
*
* @param {function(tx: Transaction): Promise} transactionWork - callback that executes operations against
* a given {@link Transaction}.
* @return {Promise} resolved promise as returned by the given function or rejected promise when given
* function or commit fails.
*/
}, {
key: 'writeTransaction',
value: function writeTransaction(transactionWork) {
return this._runTransaction(_driver.WRITE, transactionWork);
}
}, {
key: '_runTransaction',
value: function _runTransaction(accessMode, transactionWork) {
var _this2 = this;
return this._transactionExecutor.execute(function () {
return _this2._beginTransaction(accessMode, _this2.lastBookmark());
}, transactionWork);
}
}, {
key: '_updateBookmark',
value: function _updateBookmark(newBookmark) {
if (newBookmark) {
this._lastBookmark = newBookmark;
}
}
/**
* Close this session.
* @param {function()} cb - Function to be called after the session has been closed
* @param {function()} callback - Function to be called after the session has been closed
* @return

@@ -166,16 +279,20 @@ */

}, {
key: "close",
key: 'close',
value: function close() {
var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
var _this3 = this;
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
return null;
};
if (this._onClose) {
try {
this._onClose(cb);
} finally {
this._onClose = null;
}
if (this._open) {
this._open = false;
this._transactionExecutor.close();
this._readConnectionHolder.close().then(function () {
_this3._writeConnectionHolder.close().then(function () {
callback();
});
});
} else {
cb();
callback();
}

@@ -187,3 +304,3 @@ }

}, {
key: "_onRunFailure",
key: '_onRunFailure',
value: function _onRunFailure() {

@@ -194,2 +311,13 @@ return function (err) {

}
}, {
key: '_connectionHolderWithMode',
value: function _connectionHolderWithMode(mode) {
if (mode === _driver.READ) {
return this._readConnectionHolder;
} else if (mode === _driver.WRITE) {
return this._writeConnectionHolder;
} else {
throw (0, _error.newError)('Unknown access mode: ' + mode);
}
}
}]);

@@ -200,20 +328,2 @@ return Session;

/** Internal stream observer used for transactional results*/
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@@ -227,12 +337,12 @@

var _this2 = (0, _possibleConstructorReturn3.default)(this, (_RunObserver.__proto__ || (0, _getPrototypeOf2.default)(_RunObserver)).call(this, onError));
var _this4 = (0, _possibleConstructorReturn3.default)(this, (_RunObserver.__proto__ || (0, _getPrototypeOf2.default)(_RunObserver)).call(this, onError));
_this2._meta = {};
return _this2;
_this4._meta = {};
return _this4;
}
(0, _createClass3.default)(_RunObserver, [{
key: "onCompleted",
key: 'onCompleted',
value: function onCompleted(meta) {
(0, _get3.default)(_RunObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_RunObserver.prototype), "onCompleted", this).call(this, meta);
(0, _get3.default)(_RunObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_RunObserver.prototype), 'onCompleted', this).call(this, meta);
for (var key in meta) {

@@ -245,3 +355,3 @@ if (meta.hasOwnProperty(key)) {

}, {
key: "meta",
key: 'meta',
value: function meta() {

@@ -255,2 +365,7 @@ var serverMeta = { server: this._conn.server };

function _createTransactionExecutor(config) {
var maxRetryTimeMs = config && config.maxTransactionRetryTime ? config.maxTransactionRetryTime : null;
return new _transactionExecutor2.default(maxRetryTimeMs);
}
exports.default = Session;

@@ -23,2 +23,6 @@ 'use strict';

var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _typeof2 = require('babel-runtime/helpers/typeof');

@@ -46,2 +50,4 @@

var _connectionHolder = require('./internal/connection-holder');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -54,6 +60,24 @@

*/
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Transaction = function () {
/**
* @constructor
* @param {Promise} connectionPromise - A connection to use
* @param {ConnectionHolder} connectionHolder - the connection holder to get connection from.
* @param {function()} onClose - Function to be called when transaction is committed or rolled back.

@@ -64,6 +88,6 @@ * @param errorTransformer callback use to transform error

*/
function Transaction(connectionPromise, onClose, errorTransformer, bookmark, onBookmark) {
function Transaction(connectionHolder, onClose, errorTransformer, bookmark, onBookmark) {
(0, _classCallCheck3.default)(this, Transaction);
this._connectionPromise = connectionPromise;
this._connectionHolder = connectionHolder;
var streamObserver = new _TransactionStreamObserver(this);

@@ -74,7 +98,10 @@ var params = {};

}
this._connectionPromise.then(function (conn) {
this._connectionHolder.getConnection().then(function (conn) {
streamObserver.resolveConnection(conn);
conn.run("BEGIN", params, streamObserver);
conn.discardAll(streamObserver);
}).catch(streamObserver.onError);
conn.run('BEGIN', params, streamObserver);
conn.pullAll(streamObserver);
}).catch(function (error) {
return streamObserver.onError(error);
});

@@ -93,3 +120,3 @@ this._state = _states.ACTIVE;

* @param {Object} parameters - Map with parameters to use in statement
* @return {Result} - New Result
* @return {Result} New Result
*/

@@ -107,3 +134,3 @@

return this._state.run(this._connectionPromise, new _TransactionStreamObserver(this), statement, parameters);
return this._state.run(this._connectionHolder, new _TransactionStreamObserver(this), statement, parameters);
}

@@ -116,3 +143,3 @@

*
* @returns {Result} - New Result
* @returns {Result} New Result
*/

@@ -123,3 +150,3 @@

value: function commit() {
var committed = this._state.commit(this._connectionPromise, new _TransactionStreamObserver(this));
var committed = this._state.commit(this._connectionHolder, new _TransactionStreamObserver(this));
this._state = committed.state;

@@ -136,3 +163,3 @@ //clean up

*
* @returns {Result} - New Result
* @returns {Result} New Result
*/

@@ -143,3 +170,3 @@

value: function rollback() {
var committed = this._state.rollback(this._connectionPromise, new _TransactionStreamObserver(this));
var committed = this._state.rollback(this._connectionHolder, new _TransactionStreamObserver(this));
this._state = committed.state;

@@ -150,13 +177,33 @@ //clean up

}
/**
* Check if this transaction is active, which means commit and rollback did not happen.
* @return {boolean} <code>true</code> when not committed and not rolled back, <code>false</code> otherwise.
*/
}, {
key: 'isOpen',
value: function isOpen() {
return this._state == _states.ACTIVE;
}
}, {
key: '_onError',
value: function _onError() {
// rollback explicitly if tx.run failed, rollback
if (this._state == _states.ACTIVE) {
this.rollback();
var _this = this;
if (this.isOpen()) {
// attempt to rollback, useful when Transaction#run() failed
return this.rollback().catch(function (ignoredError) {
// ignore all errors because it is best effort and transaction might already be rolled back
}).then(function () {
// after rollback attempt change this transaction's state to FAILED
_this._state = _states.FAILED;
});
} else {
// else just do the cleanup
// error happened in in-active transaction, just to the cleanup and change state to FAILED
this._state = _states.FAILED;
this._onClose();
// no async actions needed - return resolved promise
return _promise2.default.resolve();
}
this._state = _states.FAILED;
}

@@ -168,20 +215,2 @@ }]);

/** Internal stream observer used for transactional results*/
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@@ -195,10 +224,10 @@

var _this = (0, _possibleConstructorReturn3.default)(this, (_TransactionStreamObserver.__proto__ || (0, _getPrototypeOf2.default)(_TransactionStreamObserver)).call(this, tx._errorTransformer || function (err) {
var _this2 = (0, _possibleConstructorReturn3.default)(this, (_TransactionStreamObserver.__proto__ || (0, _getPrototypeOf2.default)(_TransactionStreamObserver)).call(this, tx._errorTransformer || function (err) {
return err;
}));
_this._tx = tx;
_this2._tx = tx;
//this is to to avoid multiple calls to onError caused by IGNORED
_this._hasFailed = false;
return _this;
_this2._hasFailed = false;
return _this2;
}

@@ -209,6 +238,9 @@

value: function onError(error) {
var _this3 = this;
if (!this._hasFailed) {
this._tx._onError();
(0, _get3.default)(_TransactionStreamObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_TransactionStreamObserver.prototype), 'onError', this).call(this, error);
this._hasFailed = true;
this._tx._onError().then(function () {
(0, _get3.default)(_TransactionStreamObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_TransactionStreamObserver.prototype), 'onError', _this3).call(_this3, error);
_this3._hasFailed = true;
});
}

@@ -239,11 +271,11 @@ }

ACTIVE: {
commit: function commit(connectionPromise, observer) {
return { result: _runDiscardAll("COMMIT", connectionPromise, observer),
commit: function commit(connectionHolder, observer) {
return { result: _runPullAll("COMMIT", connectionHolder, observer),
state: _states.SUCCEEDED };
},
rollback: function rollback(connectionPromise, observer) {
return { result: _runDiscardAll("ROLLBACK", connectionPromise, observer), state: _states.ROLLED_BACK };
rollback: function rollback(connectionHolder, observer) {
return { result: _runPullAll("ROLLBACK", connectionHolder, observer), state: _states.ROLLED_BACK };
},
run: function run(connectionPromise, observer, statement, parameters) {
connectionPromise.then(function (conn) {
run: function run(connectionHolder, observer, statement, parameters) {
connectionHolder.getConnection().then(function (conn) {
observer.resolveConnection(conn);

@@ -253,5 +285,7 @@ conn.run(statement, parameters || {}, observer);

conn.sync();
}).catch(observer.onError);
}).catch(function (error) {
return observer.onError(error);
});
return new _result2.default(observer, statement, parameters, function () {
return newRunResult(observer, statement, parameters, function () {
return observer.serverMeta();

@@ -265,15 +299,15 @@ });

FAILED: {
commit: function commit(conn, observer) {
commit: function commit(connectionHolder, observer) {
observer.onError({
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."
});
return { result: new _result2.default(observer, "COMMIT", {}), state: _states.FAILED };
return { result: newDummyResult(observer, "COMMIT", {}), state: _states.FAILED };
},
rollback: function rollback(conn, observer) {
rollback: function rollback(connectionHolder, observer) {
observer.onError({ error: "Cannot rollback transaction, because previous statements in the " + "transaction has failed and the transaction has already been rolled back." });
return { result: new _result2.default(observer, "ROLLBACK", {}), state: _states.FAILED };
return { result: newDummyResult(observer, "ROLLBACK", {}), state: _states.FAILED };
},
run: function run(conn, observer, statement, parameters) {
run: function run(connectionHolder, observer, statement, parameters) {
observer.onError({ error: "Cannot run statement, because previous statements in the " + "transaction has failed and the transaction has already been rolled back." });
return new _result2.default(observer, statement, parameters);
return newDummyResult(observer, statement, parameters);
}

@@ -284,15 +318,15 @@ },

SUCCEEDED: {
commit: function commit(conn, observer) {
commit: function commit(connectionHolder, observer) {
observer.onError({
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."
});
return { result: new _result2.default(observer, "COMMIT", {}), state: _states.SUCCEEDED };
return { result: newDummyResult(observer, "COMMIT", {}), state: _states.SUCCEEDED };
},
rollback: function rollback(conn, observer) {
rollback: function rollback(connectionHolder, observer) {
observer.onError({ error: "Cannot rollback transaction, because transaction has already been successfully closed." });
return { result: new _result2.default(observer, "ROLLBACK", {}), state: _states.SUCCEEDED };
return { result: newDummyResult(observer, "ROLLBACK", {}), state: _states.SUCCEEDED };
},
run: function run(conn, observer, statement, parameters) {
run: function run(connectionHolder, observer, statement, parameters) {
observer.onError({ error: "Cannot run statement, because transaction has already been successfully closed." });
return new _result2.default(observer, statement, parameters);
return newDummyResult(observer, statement, parameters);
}

@@ -303,15 +337,15 @@ },

ROLLED_BACK: {
commit: function commit(conn, observer) {
commit: function commit(connectionHolder, observer) {
observer.onError({
error: "Cannot commit this transaction, because it has already been rolled back."
});
return { result: new _result2.default(observer, "COMMIT", {}), state: _states.ROLLED_BACK };
return { result: newDummyResult(observer, "COMMIT", {}), state: _states.ROLLED_BACK };
},
rollback: function rollback(conn, observer) {
rollback: function rollback(connectionHolder, observer) {
observer.onError({ error: "Cannot rollback transaction, because transaction has already been rolled back." });
return { result: new _result2.default(observer, "ROLLBACK", {}), state: _states.ROLLED_BACK };
return { result: newDummyResult(observer, "ROLLBACK", {}), state: _states.ROLLED_BACK };
},
run: function run(conn, observer, statement, parameters) {
run: function run(connectionHolder, observer, statement, parameters) {
observer.onError({ error: "Cannot run statement, because transaction has already been rolled back." });
return new _result2.default(observer, statement, parameters);
return newDummyResult(observer, statement, parameters);
}

@@ -321,13 +355,49 @@ }

function _runDiscardAll(msg, connectionPromise, observer) {
connectionPromise.then(function (conn) {
function _runPullAll(msg, connectionHolder, observer) {
connectionHolder.getConnection().then(function (conn) {
observer.resolveConnection(conn);
conn.run(msg, {}, observer);
conn.discardAll(observer);
conn.pullAll(observer);
conn.sync();
}).catch(observer.onError);
}).catch(function (error) {
return observer.onError(error);
});
return new _result2.default(observer, msg, {});
// for commit & rollback we need result that uses real connection holder and notifies it when
// connection is not needed and can be safely released to the pool
return new _result2.default(observer, msg, {}, emptyMetadataSupplier, connectionHolder);
}
/**
* Creates a {@link Result} with empty connection holder.
* Should be used as a result for running cypher statements. They can result in metadata but should not
* influence real connection holder to release connections because single transaction can have
* {@link Transaction#run} called multiple times.
* @param {StreamObserver} observer - an observer for the created result.
* @param {string} statement - the cypher statement that produced the result.
* @param {object} parameters - the parameters for cypher statement that produced the result.
* @param {function} metadataSupplier - the function that returns a metadata object.
* @return {Result} new result.
*/
function newRunResult(observer, statement, parameters, metadataSupplier) {
return new _result2.default(observer, statement, parameters, metadataSupplier, _connectionHolder.EMPTY_CONNECTION_HOLDER);
}
/**
* Creates a {@link Result} without metadata supplier and with empty connection holder.
* For cases when result represents an intermediate or failed action, does not require any metadata and does not
* need to influence real connection holder to release connections.
* @param {StreamObserver} observer - an observer for the created result.
* @param {string} statement - the cypher statement that produced the result.
* @param {object} parameters - the parameters for cypher statement that produced the result.
* @return {Result} new result.
*/
function newDummyResult(observer, statement, parameters) {
return new _result2.default(observer, statement, parameters, emptyMetadataSupplier, _connectionHolder.EMPTY_CONNECTION_HOLDER);
}
function emptyMetadataSupplier() {
return {};
}
exports.default = Transaction;

@@ -32,2 +32,2 @@ "use strict";

// system to control version names at packaging time.
exports.default = "1.1.1";
exports.default = "1.2.0-rc1";
{
"name": "neo4j-driver",
"version": "1.1.1",
"version": "1.2.0-rc1",
"description": "Connect to Neo4j 3.1.0 and up from JavaScript",

@@ -5,0 +5,0 @@ "author": "Neo Technology Inc.",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc