neo4j-driver 1.1.1 → 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.
Files changed (39) hide show
  1. package/README.md +97 -35
  2. package/gulpfile.babel.js +15 -52
  3. package/lib/browser/neo4j-web.js +3882 -1919
  4. package/lib/browser/neo4j-web.min.js +16 -15
  5. package/lib/v1/driver.js +93 -93
  6. package/lib/v1/error.js +9 -0
  7. package/lib/v1/graph-types.js +12 -12
  8. package/lib/v1/index.js +53 -31
  9. package/lib/v1/internal/ch-config.js +87 -0
  10. package/lib/v1/internal/ch-dummy.js +6 -1
  11. package/lib/v1/internal/ch-node.js +50 -44
  12. package/lib/v1/internal/ch-websocket.js +9 -10
  13. package/lib/v1/internal/connection-holder.js +204 -0
  14. package/lib/v1/internal/connection-providers.js +378 -0
  15. package/lib/v1/internal/connector.js +177 -55
  16. package/lib/v1/internal/features.js +11 -0
  17. package/lib/v1/internal/get-servers-util.js +10 -10
  18. package/lib/v1/internal/host-name-resolvers.js +131 -0
  19. package/lib/v1/internal/rediscovery.js +49 -38
  20. package/lib/v1/internal/round-robin-array.js +9 -0
  21. package/lib/v1/internal/routing-table.js +49 -35
  22. package/lib/v1/internal/routing-util.js +168 -0
  23. package/lib/v1/internal/server-version.js +123 -0
  24. package/lib/v1/internal/stream-observer.js +4 -2
  25. package/lib/v1/internal/transaction-executor.js +204 -0
  26. package/lib/v1/internal/util.js +66 -6
  27. package/lib/v1/record.js +2 -2
  28. package/lib/v1/result-summary.js +1 -1
  29. package/lib/v1/result.js +53 -31
  30. package/lib/v1/routing-driver.js +49 -152
  31. package/lib/v1/session.js +196 -74
  32. package/lib/v1/transaction.js +147 -75
  33. package/lib/version.js +1 -1
  34. package/package.json +1 -1
  35. package/.gitmodules +0 -3
  36. package/neokit/README.md +0 -89
  37. package/neokit/neoctl.py +0 -131
  38. package/neokit/neoget.py +0 -185
  39. package/neokit/neorun.py +0 -180
package/lib/v1/driver.js CHANGED
@@ -1,68 +1,54 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.WRITE = exports.READ = exports.Driver = undefined;
7
7
 
8
- var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
8
+ var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
9
9
 
10
10
  var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
11
11
 
12
- var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
12
+ var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
13
13
 
14
14
  var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
15
15
 
16
- var _get2 = require("babel-runtime/helpers/get");
16
+ var _get2 = require('babel-runtime/helpers/get');
17
17
 
18
18
  var _get3 = _interopRequireDefault(_get2);
19
19
 
20
- var _inherits2 = require("babel-runtime/helpers/inherits");
20
+ var _inherits2 = require('babel-runtime/helpers/inherits');
21
21
 
22
22
  var _inherits3 = _interopRequireDefault(_inherits2);
23
23
 
24
- var _promise = require("babel-runtime/core-js/promise");
25
-
26
- var _promise2 = _interopRequireDefault(_promise);
27
-
28
- var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
24
+ var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
29
25
 
30
26
  var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
31
27
 
32
- var _createClass2 = require("babel-runtime/helpers/createClass");
28
+ var _createClass2 = require('babel-runtime/helpers/createClass');
33
29
 
34
30
  var _createClass3 = _interopRequireDefault(_createClass2);
35
31
 
36
- var _session = require("./session");
32
+ var _session = require('./session');
37
33
 
38
34
  var _session2 = _interopRequireDefault(_session);
39
35
 
40
- var _pool = require("./internal/pool");
36
+ var _pool = require('./internal/pool');
41
37
 
42
38
  var _pool2 = _interopRequireDefault(_pool);
43
39
 
44
- var _connector = require("./internal/connector");
40
+ var _connector = require('./internal/connector');
45
41
 
46
- var _streamObserver = require("./internal/stream-observer");
42
+ var _streamObserver = require('./internal/stream-observer');
47
43
 
48
44
  var _streamObserver2 = _interopRequireDefault(_streamObserver);
49
45
 
50
- var _error = require("./error");
46
+ var _error = require('./error');
47
+
48
+ var _connectionProviders = require('./internal/connection-providers');
51
49
 
52
50
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
51
 
54
- var READ = 'READ',
55
- WRITE = 'WRITE';
56
- /**
57
- * A driver maintains one or more {@link Session sessions} with a remote
58
- * Neo4j instance. Through the {@link Session sessions} you can send statements
59
- * and retrieve results from the database.
60
- *
61
- * Drivers are reasonably expensive to create - you should strive to keep one
62
- * driver instance around per Neo4j Instance you connect to.
63
- *
64
- * @access public
65
- */
66
52
  /**
67
53
  * Copyright (c) 2002-2017 "Neo Technology,","
68
54
  * Network Engine for Objects in Lund AB [http://neotechnology.com]
@@ -82,6 +68,19 @@ var READ = 'READ',
82
68
  * limitations under the License.
83
69
  */
84
70
 
71
+ var READ = 'READ',
72
+ WRITE = 'WRITE';
73
+ /**
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
+ * and retrieve results from the database.
77
+ *
78
+ * Drivers are reasonably expensive to create - you should strive to keep one
79
+ * driver instance around per Neo4j Instance you connect to.
80
+ *
81
+ * @access public
82
+ */
83
+
85
84
  var Driver = function () {
86
85
  /**
87
86
  * You should not be calling this directly, instead use {@link driver}.
@@ -104,6 +103,13 @@ var Driver = function () {
104
103
  this._token = token;
105
104
  this._config = config;
106
105
  this._pool = new _pool2.default(this._createConnection.bind(this), this._destroyConnection.bind(this), Driver._validateConnection.bind(this), config.connectionPoolSize);
106
+
107
+ /**
108
+ * Reference to the connection provider. Initialized lazily by {@link _getOrCreateConnectionProvider}.
109
+ * @type {ConnectionProvider}
110
+ * @private
111
+ */
112
+ this._connectionProvider = null;
107
113
  }
108
114
 
109
115
  /**
@@ -114,10 +120,10 @@ var Driver = function () {
114
120
 
115
121
 
116
122
  (0, _createClass3.default)(Driver, [{
117
- key: "_createConnection",
123
+ key: '_createConnection',
118
124
  value: function _createConnection(url, release) {
119
125
  var sessionId = this._sessionIdGenerator++;
120
- var conn = (0, _connector.connect)(url, this._config);
126
+ var conn = (0, _connector.connect)(url, this._config, this._connectionErrorCode());
121
127
  var streamObserver = new _ConnectionStreamObserver(this, conn);
122
128
  conn.initialize(this._userAgent, this._token, streamObserver);
123
129
  conn._id = sessionId;
@@ -136,7 +142,7 @@ var Driver = function () {
136
142
  **/
137
143
 
138
144
  }, {
139
- key: "_destroyConnection",
145
+ key: '_destroyConnection',
140
146
 
141
147
 
142
148
  /**
@@ -155,74 +161,67 @@ var Driver = function () {
155
161
  * will be pulling a session out of the common pool.
156
162
  *
157
163
  * This comes with some responsibility - make sure you always call
158
- * {@link Session#close()} when you are done using a session, and likewise,
164
+ * {@link close} when you are done using a session, and likewise,
159
165
  * make sure you don't close your session before you are done using it. Once
160
166
  * it is returned to the pool, the session will be reset to a clean state and
161
167
  * made available for others to use.
162
168
  *
163
- * @param {String} mode of session - optional
169
+ * @param {string} [mode=WRITE] the access mode of this session, allowed values are {@link READ} and {@link WRITE}.
170
+ * @param {string} [bookmark=null] the initial reference to some previous transaction. Value is optional and
171
+ * absence indicates that that the bookmark does not exist or is unknown.
164
172
  * @return {Session} new session.
165
173
  */
166
174
 
167
175
  }, {
168
- key: "session",
169
- value: function session(mode) {
170
- var _this = this;
171
-
176
+ key: 'session',
177
+ value: function session(mode, bookmark) {
172
178
  var sessionMode = Driver._validateSessionMode(mode);
173
- var connectionPromise = this._acquireConnection(sessionMode);
174
- connectionPromise.catch(function (err) {
175
- if (_this.onError && err.code === _error.SERVICE_UNAVAILABLE) {
176
- _this.onError(err);
177
- } else {
178
- //we don't need to tell the driver about this error
179
- }
180
- });
181
- return this._createSession(connectionPromise, this._releaseConnection(connectionPromise));
179
+ var connectionProvider = this._getOrCreateConnectionProvider();
180
+ return this._createSession(sessionMode, connectionProvider, bookmark, this._config);
182
181
  }
182
+ }, {
183
+ key: '_createConnectionProvider',
183
184
 
184
- /**
185
- * The returned function gets called on Session#close(), and is where we return the pooled 'connection' instance.
186
- * We don't pool Session instances, to avoid users using the Session after they've called close.
187
- * The `Session` object is just a thin wrapper around Connection anyway, so it makes little difference.
188
- * @param {Promise} connectionPromise - promise resolved with the connection.
189
- * @return {function(callback: function)} - function that releases the connection and then executes an optional callback.
190
- * @protected
191
- */
192
185
 
193
- }, {
194
- key: "_releaseConnection",
195
- value: function _releaseConnection(connectionPromise) {
196
- return function (userDefinedCallback) {
197
- connectionPromise.then(function (conn) {
198
- // Queue up a 'reset', to ensure the next user gets a clean session to work with.
199
- conn.reset();
200
- conn.sync();
201
-
202
- // Return connection to the pool
203
- conn._release();
204
- }).catch(function (ignoredError) {});
205
-
206
- if (userDefinedCallback) {
207
- userDefinedCallback();
208
- }
209
- };
186
+ // Extension point
187
+ value: function _createConnectionProvider(address, connectionPool, driverOnErrorCallback) {
188
+ return new _connectionProviders.DirectConnectionProvider(address, connectionPool, driverOnErrorCallback);
210
189
  }
211
- }, {
212
- key: "_acquireConnection",
213
190
 
191
+ // Extension point
214
192
 
215
- //Extension point
216
- value: function _acquireConnection(mode) {
217
- return _promise2.default.resolve(this._pool.acquire(this._url));
193
+ }, {
194
+ key: '_createSession',
195
+ value: function _createSession(mode, connectionProvider, bookmark, config) {
196
+ return new _session2.default(mode, connectionProvider, bookmark, config);
218
197
  }
219
198
 
220
- //Extension point
199
+ // Extension point
221
200
 
222
201
  }, {
223
- key: "_createSession",
224
- value: function _createSession(connectionPromise, cb) {
225
- return new _session2.default(connectionPromise, cb);
202
+ key: '_connectionErrorCode',
203
+ value: function _connectionErrorCode() {
204
+ // connection errors might result in different error codes depending on the driver
205
+ return _error.SERVICE_UNAVAILABLE;
206
+ }
207
+ }, {
208
+ key: '_getOrCreateConnectionProvider',
209
+ value: function _getOrCreateConnectionProvider() {
210
+ if (!this._connectionProvider) {
211
+ var driverOnErrorCallback = this._driverOnErrorCallback.bind(this);
212
+ this._connectionProvider = this._createConnectionProvider(this._url, this._pool, driverOnErrorCallback);
213
+ }
214
+ return this._connectionProvider;
215
+ }
216
+ }, {
217
+ key: '_driverOnErrorCallback',
218
+ value: function _driverOnErrorCallback(error) {
219
+ var userDefinedOnErrorCallback = this.onError;
220
+ if (userDefinedOnErrorCallback && error.code === _error.SERVICE_UNAVAILABLE) {
221
+ userDefinedOnErrorCallback(error);
222
+ } else {
223
+ // we don't need to tell the driver about this error
224
+ }
226
225
  }
227
226
 
228
227
  /**
@@ -232,7 +231,7 @@ var Driver = function () {
232
231
  */
233
232
 
234
233
  }, {
235
- key: "close",
234
+ key: 'close',
236
235
  value: function close() {
237
236
  for (var sessionId in this._openSessions) {
238
237
  if (this._openSessions.hasOwnProperty(sessionId)) {
@@ -242,12 +241,12 @@ var Driver = function () {
242
241
  }
243
242
  }
244
243
  }], [{
245
- key: "_validateConnection",
244
+ key: '_validateConnection',
246
245
  value: function _validateConnection(conn) {
247
246
  return conn.isOpen();
248
247
  }
249
248
  }, {
250
- key: "_validateSessionMode",
249
+ key: '_validateSessionMode',
251
250
  value: function _validateSessionMode(rawMode) {
252
251
  var mode = rawMode || WRITE;
253
252
  if (mode !== READ && mode !== WRITE) {
@@ -268,19 +267,19 @@ var _ConnectionStreamObserver = function (_StreamObserver) {
268
267
  function _ConnectionStreamObserver(driver, conn) {
269
268
  (0, _classCallCheck3.default)(this, _ConnectionStreamObserver);
270
269
 
271
- var _this2 = (0, _possibleConstructorReturn3.default)(this, (_ConnectionStreamObserver.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver)).call(this));
270
+ var _this = (0, _possibleConstructorReturn3.default)(this, (_ConnectionStreamObserver.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver)).call(this));
272
271
 
273
- _this2._driver = driver;
274
- _this2._conn = conn;
275
- _this2._hasFailed = false;
276
- return _this2;
272
+ _this._driver = driver;
273
+ _this._conn = conn;
274
+ _this._hasFailed = false;
275
+ return _this;
277
276
  }
278
277
 
279
278
  (0, _createClass3.default)(_ConnectionStreamObserver, [{
280
- key: "onError",
279
+ key: 'onError',
281
280
  value: function onError(error) {
282
281
  if (!this._hasFailed) {
283
- (0, _get3.default)(_ConnectionStreamObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver.prototype), "onError", this).call(this, error);
282
+ (0, _get3.default)(_ConnectionStreamObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver.prototype), 'onError', this).call(this, error);
284
283
  if (this._driver.onError) {
285
284
  this._driver.onError(error);
286
285
  }
@@ -288,13 +287,14 @@ var _ConnectionStreamObserver = function (_StreamObserver) {
288
287
  }
289
288
  }
290
289
  }, {
291
- key: "onCompleted",
290
+ key: 'onCompleted',
292
291
  value: function onCompleted(message) {
293
292
  if (this._driver.onCompleted) {
294
293
  this._driver.onCompleted(message);
295
294
  }
296
- if (this._conn && message && message.server) {
297
- this._conn.setServerVersion(message.server);
295
+
296
+ if (this._observer && this._observer.onComplete) {
297
+ this._observer.onCompleted(message);
298
298
  }
299
299
  }
300
300
  }]);
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) {
@@ -48,8 +48,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
48
48
  var Node = function () {
49
49
  /**
50
50
  * @constructor
51
- * @param {string} identity - Unique identity
52
- * @param {Array} labels - Array for all labels
51
+ * @param {Integer} identity - Unique identity
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) {
@@ -91,9 +91,9 @@ var Node = function () {
91
91
  var Relationship = function () {
92
92
  /**
93
93
  * @constructor
94
- * @param {string} identity - Unique identity
95
- * @param {string} start - Identity of start Node
96
- * @param {string} end - Identity of end Node
94
+ * @param {Integer} identity - Unique identity
95
+ * @param {Integer} start - Identity of start Node
96
+ * @param {Integer} end - Identity of end Node
97
97
  * @param {string} type - Relationship type
98
98
  * @param {Object} properties - Map with relationship properties
99
99
  */
@@ -136,7 +136,7 @@ var Relationship = function () {
136
136
  var UnboundRelationship = function () {
137
137
  /**
138
138
  * @constructor
139
- * @param {string} identity - Unique identity
139
+ * @param {Integer} identity - Unique identity
140
140
  * @param {string} type - Relationship type
141
141
  * @param {Object} properties - Map with relationship properties
142
142
  */
@@ -150,8 +150,8 @@ var UnboundRelationship = function () {
150
150
 
151
151
  /**
152
152
  * Bind relationship
153
- * @param {string} start - Indentity of start node
154
- * @param {string} end - Indentity of end node
153
+ * @param {Integer} start - Identity of start node
154
+ * @param {Integer} end - Identity of end node
155
155
  * @return {Relationship} - Created relationship
156
156
  */
157
157
 
@@ -189,9 +189,9 @@ var UnboundRelationship = function () {
189
189
  var PathSegment =
190
190
  /**
191
191
  * @constructor
192
- * @param {string} start - Identity of start Node
193
- * @param {Relationship} rel - Relationship segment
194
- * @param {string} end - Identity of end Node
192
+ * @param {Node} start - start node
193
+ * @param {Relationship} rel - relationship that connects start and end node
194
+ * @param {Node} end - end node
195
195
  */
196
196
  function PathSegment(start, rel, end) {
197
197
  (0, _classCallCheck3.default)(this, PathSegment);
@@ -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);
package/lib/v1/index.js CHANGED
@@ -33,51 +33,59 @@ var _version = require('../version');
33
33
 
34
34
  var _version2 = _interopRequireDefault(_version);
35
35
 
36
- var _connector = require('./internal/connector');
37
-
38
36
  var _util = require('./internal/util');
39
37
 
40
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
41
39
 
40
+ /**
41
+ * Copyright (c) 2002-2017 "Neo Technology,","
42
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
43
+ *
44
+ * This file is part of Neo4j.
45
+ *
46
+ * Licensed under the Apache License, Version 2.0 (the "License");
47
+ * you may not use this file except in compliance with the License.
48
+ * You may obtain a copy of the License at
49
+ *
50
+ * http://www.apache.org/licenses/LICENSE-2.0
51
+ *
52
+ * Unless required by applicable law or agreed to in writing, software
53
+ * distributed under the License is distributed on an "AS IS" BASIS,
54
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55
+ * See the License for the specific language governing permissions and
56
+ * limitations under the License.
57
+ */
58
+
42
59
  var auth = {
43
60
  basic: function basic(username, password) {
44
61
  var realm = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
45
62
 
46
63
  if (realm) {
47
- return { scheme: "basic", principal: username, credentials: password, realm: realm };
64
+ return { scheme: 'basic', principal: username, credentials: password, realm: realm };
48
65
  } else {
49
- return { scheme: "basic", principal: username, credentials: password };
66
+ return { scheme: 'basic', principal: username, credentials: password };
50
67
  }
51
68
  },
69
+ kerberos: function kerberos(base64EncodedTicket) {
70
+ return {
71
+ scheme: 'kerberos',
72
+ principal: '', // This empty string is required for backwards compatibility.
73
+ credentials: base64EncodedTicket
74
+ };
75
+ },
52
76
  custom: function custom(principal, credentials, realm, scheme) {
53
77
  var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
54
78
 
55
79
  if (parameters) {
56
- return { scheme: scheme, principal: principal, credentials: credentials, realm: realm,
57
- parameters: parameters };
80
+ return {
81
+ scheme: scheme, principal: principal, credentials: credentials, realm: realm,
82
+ parameters: parameters
83
+ };
58
84
  } else {
59
85
  return { scheme: scheme, principal: principal, credentials: credentials, realm: realm };
60
86
  }
61
87
  }
62
- }; /**
63
- * Copyright (c) 2002-2017 "Neo Technology,","
64
- * Network Engine for Objects in Lund AB [http://neotechnology.com]
65
- *
66
- * This file is part of Neo4j.
67
- *
68
- * Licensed under the Apache License, Version 2.0 (the "License");
69
- * you may not use this file except in compliance with the License.
70
- * You may obtain a copy of the License at
71
- *
72
- * http://www.apache.org/licenses/LICENSE-2.0
73
- *
74
- * Unless required by applicable law or agreed to in writing, software
75
- * distributed under the License is distributed on an "AS IS" BASIS,
76
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77
- * See the License for the specific language governing permissions and
78
- * limitations under the License.
79
- */
80
-
88
+ };
81
89
  var USER_AGENT = "neo4j-javascript/" + _version2.default;
82
90
 
83
91
  /**
@@ -131,6 +139,16 @@ var USER_AGENT = "neo4j-javascript/" + _version2.default;
131
139
  * // port, and this is then used to verify the host certificate does not change.
132
140
  * // This setting has no effect unless TRUST_ON_FIRST_USE is enabled.
133
141
  * knownHosts:"~/.neo4j/known_hosts",
142
+ *
143
+ * // The max number of connections that are allowed idle in the pool at any time.
144
+ * // Connection will be destroyed if this threshold is exceeded.
145
+ * connectionPoolSize: 50,
146
+ *
147
+ * // Specify the maximum time in milliseconds transactions are allowed to retry via
148
+ * // {@link Session#readTransaction()} and {@link Session#writeTransaction()} functions. These functions
149
+ * // will retry the given unit of work on `ServiceUnavailable`, `SessionExpired` and transient errors with
150
+ * // exponential backoff using initial delay of 1 second. Default value is 30000 which is 30 seconds.
151
+ * maxTransactionRetryTime: 30000,
134
152
  * }
135
153
  *
136
154
  * @param {string} url The URL for the Neo4j database, for instance "bolt://localhost"
@@ -142,13 +160,17 @@ function driver(url, authToken) {
142
160
  var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
143
161
 
144
162
  (0, _util.assertString)(url, 'Bolt URL');
145
- var scheme = (0, _connector.parseScheme)(url);
146
- if (scheme === "bolt+routing://") {
147
- return new _routingDriver2.default((0, _connector.parseUrl)(url), USER_AGENT, authToken, config);
148
- } else if (scheme === "bolt://") {
149
- return new _driver.Driver((0, _connector.parseUrl)(url), USER_AGENT, authToken, config);
163
+ var scheme = (0, _util.parseScheme)(url);
164
+ var routingContext = (0, _util.parseRoutingContext)(url);
165
+ if (scheme === 'bolt+routing://') {
166
+ return new _routingDriver2.default((0, _util.parseUrl)(url), routingContext, USER_AGENT, authToken, config);
167
+ } else if (scheme === 'bolt://') {
168
+ if (!(0, _util.isEmptyObjectOrNull)(routingContext)) {
169
+ throw new Error('Parameters are not supported with scheme \'bolt\'. Given URL: \'' + url + '\'');
170
+ }
171
+ return new _driver.Driver((0, _util.parseUrl)(url), USER_AGENT, authToken, config);
150
172
  } else {
151
- throw new Error("Unknown scheme: " + scheme);
173
+ throw new Error('Unknown scheme: ' + scheme);
152
174
  }
153
175
  }
154
176
 
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
8
+
9
+ var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
10
+
11
+ var _createClass2 = require('babel-runtime/helpers/createClass');
12
+
13
+ var _createClass3 = _interopRequireDefault(_createClass2);
14
+
15
+ var _features = require('./features');
16
+
17
+ var _features2 = _interopRequireDefault(_features);
18
+
19
+ var _error = require('../error');
20
+
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+
23
+ /**
24
+ * Copyright (c) 2002-2017 "Neo Technology,","
25
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
26
+ *
27
+ * This file is part of Neo4j.
28
+ *
29
+ * Licensed under the Apache License, Version 2.0 (the "License");
30
+ * you may not use this file except in compliance with the License.
31
+ * You may obtain a copy of the License at
32
+ *
33
+ * http://www.apache.org/licenses/LICENSE-2.0
34
+ *
35
+ * Unless required by applicable law or agreed to in writing, software
36
+ * distributed under the License is distributed on an "AS IS" BASIS,
37
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
+ * See the License for the specific language governing permissions and
39
+ * limitations under the License.
40
+ */
41
+
42
+ var ChannelConfig = function () {
43
+ function ChannelConfig(host, port, driverConfig, connectionErrorCode) {
44
+ (0, _classCallCheck3.default)(this, ChannelConfig);
45
+
46
+ this.host = host;
47
+ this.port = port;
48
+ this.encrypted = ChannelConfig._extractEncrypted(driverConfig);
49
+ this.trust = ChannelConfig._extractTrust(driverConfig);
50
+ this.trustedCertificates = ChannelConfig._extractTrustedCertificates(driverConfig);
51
+ this.knownHostsPath = ChannelConfig._extractKnownHostsPath(driverConfig);
52
+ this.connectionErrorCode = connectionErrorCode || _error.SERVICE_UNAVAILABLE;
53
+ }
54
+
55
+ (0, _createClass3.default)(ChannelConfig, null, [{
56
+ key: '_extractEncrypted',
57
+ value: function _extractEncrypted(driverConfig) {
58
+ // check if encryption was configured by the user, use explicit null check because we permit boolean value
59
+ var encryptionConfigured = driverConfig.encrypted == null;
60
+ // default to using encryption if trust-all-certificates is available
61
+ return encryptionConfigured ? (0, _features2.default)('trust_all_certificates') : driverConfig.encrypted;
62
+ }
63
+ }, {
64
+ key: '_extractTrust',
65
+ value: function _extractTrust(driverConfig) {
66
+ if (driverConfig.trust) {
67
+ return driverConfig.trust;
68
+ }
69
+ // default to using TRUST_ALL_CERTIFICATES if it is available
70
+ return (0, _features2.default)('trust_all_certificates') ? 'TRUST_ALL_CERTIFICATES' : 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES';
71
+ }
72
+ }, {
73
+ key: '_extractTrustedCertificates',
74
+ value: function _extractTrustedCertificates(driverConfig) {
75
+ return driverConfig.trustedCertificates || [];
76
+ }
77
+ }, {
78
+ key: '_extractKnownHostsPath',
79
+ value: function _extractKnownHostsPath(driverConfig) {
80
+ return driverConfig.knownHosts || null;
81
+ }
82
+ }]);
83
+ return ChannelConfig;
84
+ }();
85
+
86
+ exports.default = ChannelConfig;
87
+ ;
@@ -42,7 +42,12 @@ var observer = {
42
42
  */
43
43
 
44
44
  var DummyChannel = function () {
45
- function DummyChannel(opts) {
45
+
46
+ /**
47
+ * @constructor
48
+ * @param {ChannelConfig} config - configuration for the new channel.
49
+ */
50
+ function DummyChannel(config) {
46
51
  (0, _classCallCheck3.default)(this, DummyChannel);
47
52
 
48
53
  this.written = [];