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.
- package/README.md +97 -35
- package/gulpfile.babel.js +15 -52
- package/lib/browser/neo4j-web.js +3882 -1919
- package/lib/browser/neo4j-web.min.js +16 -15
- package/lib/v1/driver.js +93 -93
- package/lib/v1/error.js +9 -0
- package/lib/v1/graph-types.js +12 -12
- package/lib/v1/index.js +53 -31
- package/lib/v1/internal/ch-config.js +87 -0
- package/lib/v1/internal/ch-dummy.js +6 -1
- package/lib/v1/internal/ch-node.js +50 -44
- package/lib/v1/internal/ch-websocket.js +9 -10
- package/lib/v1/internal/connection-holder.js +204 -0
- package/lib/v1/internal/connection-providers.js +378 -0
- package/lib/v1/internal/connector.js +177 -55
- package/lib/v1/internal/features.js +11 -0
- package/lib/v1/internal/get-servers-util.js +10 -10
- package/lib/v1/internal/host-name-resolvers.js +131 -0
- package/lib/v1/internal/rediscovery.js +49 -38
- package/lib/v1/internal/round-robin-array.js +9 -0
- package/lib/v1/internal/routing-table.js +49 -35
- package/lib/v1/internal/routing-util.js +168 -0
- package/lib/v1/internal/server-version.js +123 -0
- package/lib/v1/internal/stream-observer.js +4 -2
- package/lib/v1/internal/transaction-executor.js +204 -0
- package/lib/v1/internal/util.js +66 -6
- package/lib/v1/record.js +2 -2
- package/lib/v1/result-summary.js +1 -1
- package/lib/v1/result.js +53 -31
- package/lib/v1/routing-driver.js +49 -152
- package/lib/v1/session.js +196 -74
- package/lib/v1/transaction.js +147 -75
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/.gitmodules +0 -3
- package/neokit/README.md +0 -89
- package/neokit/neoctl.py +0 -131
- package/neokit/neoget.py +0 -185
- package/neokit/neorun.py +0 -180
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Connection = exports.
|
|
6
|
+
exports.Connection = exports.connect = undefined;
|
|
7
|
+
|
|
8
|
+
var _promise = require('babel-runtime/core-js/promise');
|
|
9
|
+
|
|
10
|
+
var _promise2 = _interopRequireDefault(_promise);
|
|
7
11
|
|
|
8
12
|
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
|
9
13
|
|
|
@@ -27,10 +31,6 @@ var _chNode2 = _interopRequireDefault(_chNode);
|
|
|
27
31
|
|
|
28
32
|
var _chunking = require('./chunking');
|
|
29
33
|
|
|
30
|
-
var _features = require('./features');
|
|
31
|
-
|
|
32
|
-
var _features2 = _interopRequireDefault(_features);
|
|
33
|
-
|
|
34
34
|
var _packstream = require('./packstream');
|
|
35
35
|
|
|
36
36
|
var _buf = require('./buf');
|
|
@@ -39,6 +39,16 @@ var _graphTypes = require('../graph-types');
|
|
|
39
39
|
|
|
40
40
|
var _error = require('./../error');
|
|
41
41
|
|
|
42
|
+
var _chConfig = require('./ch-config');
|
|
43
|
+
|
|
44
|
+
var _chConfig2 = _interopRequireDefault(_chConfig);
|
|
45
|
+
|
|
46
|
+
var _util = require('./util');
|
|
47
|
+
|
|
48
|
+
var _streamObserver = require('./stream-observer');
|
|
49
|
+
|
|
50
|
+
var _streamObserver2 = _interopRequireDefault(_streamObserver);
|
|
51
|
+
|
|
42
52
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
43
53
|
|
|
44
54
|
/**
|
|
@@ -59,6 +69,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
59
69
|
* See the License for the specific language governing permissions and
|
|
60
70
|
* limitations under the License.
|
|
61
71
|
*/
|
|
72
|
+
|
|
62
73
|
var Channel = void 0;
|
|
63
74
|
if (_chNode2.default.available) {
|
|
64
75
|
Channel = _chNode2.default.channel;
|
|
@@ -101,28 +112,6 @@ NODE = 0x4E,
|
|
|
101
112
|
MAGIC_PREAMBLE = 0x6060B017,
|
|
102
113
|
DEBUG = false;
|
|
103
114
|
|
|
104
|
-
var URLREGEX = new RegExp(["([^/]+//)?", // scheme
|
|
105
|
-
"(([^:/?#]*)", // hostname
|
|
106
|
-
"(?::([0-9]+))?)", // port (optional)
|
|
107
|
-
".*"].join("")); // everything else
|
|
108
|
-
|
|
109
|
-
function parseScheme(url) {
|
|
110
|
-
var scheme = url.match(URLREGEX)[1] || '';
|
|
111
|
-
return scheme.toLowerCase();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function parseUrl(url) {
|
|
115
|
-
return url.match(URLREGEX)[2];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function parseHost(url) {
|
|
119
|
-
return url.match(URLREGEX)[3];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function parsePort(url) {
|
|
123
|
-
return url.match(URLREGEX)[4];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
115
|
/**
|
|
127
116
|
* Very rudimentary log handling, should probably be replaced by something proper at some point.
|
|
128
117
|
* @param actor the part that sent the message, 'S' for server and 'C' for client
|
|
@@ -245,6 +234,8 @@ var Connection = function () {
|
|
|
245
234
|
this._isHandlingFailure = false;
|
|
246
235
|
this._currentFailure = null;
|
|
247
236
|
|
|
237
|
+
this._state = new ConnectionState(this);
|
|
238
|
+
|
|
248
239
|
// Set to true on fatal errors, to get this out of session pool.
|
|
249
240
|
this._isBroken = false;
|
|
250
241
|
|
|
@@ -312,7 +303,7 @@ var Connection = function () {
|
|
|
312
303
|
* failing, and the connection getting ejected from the session pool.
|
|
313
304
|
*
|
|
314
305
|
* @param err an error object, forwarded to all current and future subscribers
|
|
315
|
-
* @
|
|
306
|
+
* @protected
|
|
316
307
|
*/
|
|
317
308
|
|
|
318
309
|
|
|
@@ -336,6 +327,12 @@ var Connection = function () {
|
|
|
336
327
|
value: function _handleMessage(msg) {
|
|
337
328
|
var _this = this;
|
|
338
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
|
+
|
|
339
336
|
var payload = msg.fields[0];
|
|
340
337
|
|
|
341
338
|
switch (msg.signature) {
|
|
@@ -348,7 +345,7 @@ var Connection = function () {
|
|
|
348
345
|
try {
|
|
349
346
|
this._currentObserver.onCompleted(payload);
|
|
350
347
|
} finally {
|
|
351
|
-
this.
|
|
348
|
+
this._updateCurrentObserver();
|
|
352
349
|
}
|
|
353
350
|
break;
|
|
354
351
|
case FAILURE:
|
|
@@ -357,7 +354,7 @@ var Connection = function () {
|
|
|
357
354
|
this._currentFailure = (0, _error.newError)(payload.message, payload.code);
|
|
358
355
|
this._currentObserver.onError(this._currentFailure);
|
|
359
356
|
} finally {
|
|
360
|
-
this.
|
|
357
|
+
this._updateCurrentObserver();
|
|
361
358
|
// Things are now broken. Pending observers will get FAILURE messages routed until
|
|
362
359
|
// We are done handling this failure.
|
|
363
360
|
if (!this._isHandlingFailure) {
|
|
@@ -384,7 +381,7 @@ var Connection = function () {
|
|
|
384
381
|
try {
|
|
385
382
|
if (this._currentFailure && this._currentObserver.onError) this._currentObserver.onError(this._currentFailure);else if (this._currentObserver.onError) this._currentObserver.onError(payload);
|
|
386
383
|
} finally {
|
|
387
|
-
this.
|
|
384
|
+
this._updateCurrentObserver();
|
|
388
385
|
}
|
|
389
386
|
break;
|
|
390
387
|
default:
|
|
@@ -400,7 +397,8 @@ var Connection = function () {
|
|
|
400
397
|
var _this2 = this;
|
|
401
398
|
|
|
402
399
|
log("C", "INIT", clientName, token);
|
|
403
|
-
this.
|
|
400
|
+
var initObserver = this._state.wrap(observer);
|
|
401
|
+
this._queueObserver(initObserver);
|
|
404
402
|
this._packer.packStruct(INIT, [this._packable(clientName), this._packable(token)], function (err) {
|
|
405
403
|
return _this2._handleFatalError(err);
|
|
406
404
|
});
|
|
@@ -453,14 +451,14 @@ var Connection = function () {
|
|
|
453
451
|
this._chunker.messageBoundary();
|
|
454
452
|
}
|
|
455
453
|
|
|
456
|
-
/** Queue a RESET-message to be sent to the database */
|
|
454
|
+
/** Queue a RESET-message to be sent to the database. Mutes failure handling. */
|
|
457
455
|
|
|
458
456
|
}, {
|
|
459
|
-
key: '
|
|
460
|
-
value: function
|
|
457
|
+
key: 'resetAsync',
|
|
458
|
+
value: function resetAsync(observer) {
|
|
461
459
|
var _this6 = this;
|
|
462
460
|
|
|
463
|
-
log("C", "
|
|
461
|
+
log("C", "RESET_ASYNC");
|
|
464
462
|
this._isHandlingFailure = true;
|
|
465
463
|
var self = this;
|
|
466
464
|
var wrappedObs = {
|
|
@@ -480,17 +478,32 @@ var Connection = function () {
|
|
|
480
478
|
this._chunker.messageBoundary();
|
|
481
479
|
}
|
|
482
480
|
|
|
481
|
+
/** Queue a RESET-message to be sent to the database */
|
|
482
|
+
|
|
483
|
+
}, {
|
|
484
|
+
key: 'reset',
|
|
485
|
+
value: function reset(observer) {
|
|
486
|
+
var _this7 = this;
|
|
487
|
+
|
|
488
|
+
log('C', 'RESET');
|
|
489
|
+
this._queueObserver(observer);
|
|
490
|
+
this._packer.packStruct(RESET, [], function (err) {
|
|
491
|
+
return _this7._handleFatalError(err);
|
|
492
|
+
});
|
|
493
|
+
this._chunker.messageBoundary();
|
|
494
|
+
}
|
|
495
|
+
|
|
483
496
|
/** Queue a ACK_FAILURE-message to be sent to the database */
|
|
484
497
|
|
|
485
498
|
}, {
|
|
486
499
|
key: '_ackFailure',
|
|
487
500
|
value: function _ackFailure(observer) {
|
|
488
|
-
var
|
|
501
|
+
var _this8 = this;
|
|
489
502
|
|
|
490
503
|
log("C", "ACK_FAILURE");
|
|
491
504
|
this._queueObserver(observer);
|
|
492
505
|
this._packer.packStruct(ACK_FAILURE, [], function (err) {
|
|
493
|
-
return
|
|
506
|
+
return _this8._handleFatalError(err);
|
|
494
507
|
});
|
|
495
508
|
this._chunker.messageBoundary();
|
|
496
509
|
}
|
|
@@ -514,6 +527,29 @@ var Connection = function () {
|
|
|
514
527
|
}
|
|
515
528
|
}
|
|
516
529
|
|
|
530
|
+
/**
|
|
531
|
+
* Get promise resolved when connection initialization succeed or rejected when it fails.
|
|
532
|
+
* Connection is initialized using {@link initialize} function.
|
|
533
|
+
* @return {Promise<Connection>} the result of connection initialization.
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
}, {
|
|
537
|
+
key: 'initializationCompleted',
|
|
538
|
+
value: function initializationCompleted() {
|
|
539
|
+
return this._state.initializationCompleted();
|
|
540
|
+
}
|
|
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
|
+
|
|
517
553
|
/**
|
|
518
554
|
* Synchronize - flush all queued outgoing messages and route their responses
|
|
519
555
|
* to their respective handlers.
|
|
@@ -551,10 +587,10 @@ var Connection = function () {
|
|
|
551
587
|
}, {
|
|
552
588
|
key: '_packable',
|
|
553
589
|
value: function _packable(value) {
|
|
554
|
-
var
|
|
590
|
+
var _this9 = this;
|
|
555
591
|
|
|
556
592
|
return this._packer.packable(value, function (err) {
|
|
557
|
-
return
|
|
593
|
+
return _this9._handleFatalError(err);
|
|
558
594
|
});
|
|
559
595
|
}
|
|
560
596
|
}, {
|
|
@@ -566,36 +602,122 @@ var Connection = function () {
|
|
|
566
602
|
return Connection;
|
|
567
603
|
}();
|
|
568
604
|
|
|
605
|
+
var ConnectionState = function () {
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* @constructor
|
|
609
|
+
* @param {Connection} connection the connection to track state for.
|
|
610
|
+
*/
|
|
611
|
+
function ConnectionState(connection) {
|
|
612
|
+
(0, _classCallCheck3.default)(this, ConnectionState);
|
|
613
|
+
|
|
614
|
+
this._connection = connection;
|
|
615
|
+
|
|
616
|
+
this._initialized = false;
|
|
617
|
+
this._initializationError = null;
|
|
618
|
+
|
|
619
|
+
this._resolvePromise = null;
|
|
620
|
+
this._rejectPromise = null;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
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.
|
|
626
|
+
* @param {StreamObserver} observer the observer used for INIT message.
|
|
627
|
+
* @return {StreamObserver} updated observer.
|
|
628
|
+
*/
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
(0, _createClass3.default)(ConnectionState, [{
|
|
632
|
+
key: 'wrap',
|
|
633
|
+
value: function wrap(observer) {
|
|
634
|
+
var _this10 = this;
|
|
635
|
+
|
|
636
|
+
return {
|
|
637
|
+
onNext: function onNext(record) {
|
|
638
|
+
if (observer && observer.onNext) {
|
|
639
|
+
observer.onNext(record);
|
|
640
|
+
}
|
|
641
|
+
},
|
|
642
|
+
onError: function onError(error) {
|
|
643
|
+
_this10._initializationError = error;
|
|
644
|
+
if (_this10._rejectPromise) {
|
|
645
|
+
_this10._rejectPromise(error);
|
|
646
|
+
_this10._rejectPromise = null;
|
|
647
|
+
}
|
|
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);
|
|
656
|
+
}
|
|
657
|
+
},
|
|
658
|
+
onCompleted: function onCompleted(metaData) {
|
|
659
|
+
if (metaData && metaData.server) {
|
|
660
|
+
_this10._connection.setServerVersion(metaData.server);
|
|
661
|
+
}
|
|
662
|
+
_this10._initialized = true;
|
|
663
|
+
if (_this10._resolvePromise) {
|
|
664
|
+
_this10._resolvePromise(_this10._connection);
|
|
665
|
+
_this10._resolvePromise = null;
|
|
666
|
+
}
|
|
667
|
+
if (observer && observer.onCompleted) {
|
|
668
|
+
observer.onCompleted(metaData);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Get promise resolved when connection initialization succeed or rejected when it fails.
|
|
676
|
+
* @return {Promise<Connection>} the result of connection initialization.
|
|
677
|
+
*/
|
|
678
|
+
|
|
679
|
+
}, {
|
|
680
|
+
key: 'initializationCompleted',
|
|
681
|
+
value: function initializationCompleted() {
|
|
682
|
+
var _this11 = this;
|
|
683
|
+
|
|
684
|
+
if (this._initialized) {
|
|
685
|
+
return _promise2.default.resolve(this._connection);
|
|
686
|
+
} else if (this._initializationError) {
|
|
687
|
+
return _promise2.default.reject(this._initializationError);
|
|
688
|
+
} else {
|
|
689
|
+
return new _promise2.default(function (resolve, reject) {
|
|
690
|
+
_this11._resolvePromise = resolve;
|
|
691
|
+
_this11._rejectPromise = reject;
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}]);
|
|
696
|
+
return ConnectionState;
|
|
697
|
+
}();
|
|
698
|
+
|
|
569
699
|
/**
|
|
570
700
|
* Crete new connection to the provided url.
|
|
571
701
|
* @access private
|
|
572
702
|
* @param {string} url - 'neo4j'-prefixed URL to Neo4j Bolt endpoint
|
|
573
|
-
* @param {object} config
|
|
703
|
+
* @param {object} config - this driver configuration
|
|
704
|
+
* @param {string=null} connectionErrorCode - error code for errors raised on connection errors
|
|
574
705
|
* @return {Connection} - New connection
|
|
575
706
|
*/
|
|
576
707
|
|
|
577
708
|
|
|
578
709
|
function connect(url) {
|
|
579
710
|
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
711
|
+
var connectionErrorCode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
580
712
|
|
|
581
713
|
var Ch = config.channel || Channel;
|
|
582
|
-
var host = parseHost(url);
|
|
583
|
-
var port = parsePort(url) || 7687;
|
|
714
|
+
var host = (0, _util.parseHost)(url);
|
|
715
|
+
var port = (0, _util.parsePort)(url) || 7687;
|
|
584
716
|
var completeUrl = host + ':' + port;
|
|
717
|
+
var channelConfig = new _chConfig2.default(host, port, config, connectionErrorCode);
|
|
585
718
|
|
|
586
|
-
return new Connection(new Ch(
|
|
587
|
-
host: parseHost(url),
|
|
588
|
-
port: parsePort(url) || 7687,
|
|
589
|
-
// Default to using encryption if trust-on-first-use is available
|
|
590
|
-
encrypted: config.encrypted == null ? (0, _features2.default)("trust_all_certificates") : config.encrypted,
|
|
591
|
-
// Default to using TRUST_ALL_CERTIFICATES if it is available
|
|
592
|
-
trust: config.trust || ((0, _features2.default)("trust_all_certificates") ? "TRUST_ALL_CERTIFICATES" : "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES"),
|
|
593
|
-
trustedCertificates: config.trustedCertificates || [],
|
|
594
|
-
knownHosts: config.knownHosts
|
|
595
|
-
}), completeUrl);
|
|
719
|
+
return new Connection(new Ch(channelConfig), completeUrl);
|
|
596
720
|
}
|
|
597
721
|
|
|
598
722
|
exports.connect = connect;
|
|
599
|
-
exports.parseScheme = parseScheme;
|
|
600
|
-
exports.parseUrl = parseUrl;
|
|
601
723
|
exports.Connection = Connection;
|
|
@@ -45,6 +45,17 @@ var FEATURES = {
|
|
|
45
45
|
} catch (e) {
|
|
46
46
|
return false;
|
|
47
47
|
}
|
|
48
|
+
},
|
|
49
|
+
dns_lookup: function dns_lookup() {
|
|
50
|
+
try {
|
|
51
|
+
var lookupFunction = require('dns').lookup;
|
|
52
|
+
if (lookupFunction && typeof lookupFunction === 'function') {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
48
59
|
}
|
|
49
60
|
};
|
|
50
61
|
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var _stringify = require(
|
|
7
|
+
var _stringify = require('babel-runtime/core-js/json/stringify');
|
|
8
8
|
|
|
9
9
|
var _stringify2 = _interopRequireDefault(_stringify);
|
|
10
10
|
|
|
11
|
-
var _classCallCheck2 = require(
|
|
11
|
+
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
|
12
12
|
|
|
13
13
|
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
|
14
14
|
|
|
15
|
-
var _createClass2 = require(
|
|
15
|
+
var _createClass2 = require('babel-runtime/helpers/createClass');
|
|
16
16
|
|
|
17
17
|
var _createClass3 = _interopRequireDefault(_createClass2);
|
|
18
18
|
|
|
19
|
-
var _roundRobinArray = require(
|
|
19
|
+
var _roundRobinArray = require('./round-robin-array');
|
|
20
20
|
|
|
21
21
|
var _roundRobinArray2 = _interopRequireDefault(_roundRobinArray);
|
|
22
22
|
|
|
23
|
-
var _error = require(
|
|
23
|
+
var _error = require('../error');
|
|
24
24
|
|
|
25
|
-
var _integer = require(
|
|
25
|
+
var _integer = require('../integer');
|
|
26
26
|
|
|
27
27
|
var _integer2 = _interopRequireDefault(_integer);
|
|
28
28
|
|
|
@@ -55,7 +55,7 @@ var GetServersUtil = function () {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
(0, _createClass3.default)(GetServersUtil, [{
|
|
58
|
-
key:
|
|
58
|
+
key: 'callGetServers',
|
|
59
59
|
value: function callGetServers(session, routerAddress) {
|
|
60
60
|
return session.run(PROCEDURE_CALL).then(function (result) {
|
|
61
61
|
session.close();
|
|
@@ -71,7 +71,7 @@ var GetServersUtil = function () {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
}, {
|
|
74
|
-
key:
|
|
74
|
+
key: 'parseTtl',
|
|
75
75
|
value: function parseTtl(record, routerAddress) {
|
|
76
76
|
try {
|
|
77
77
|
var now = (0, _integer.int)(Date.now());
|
|
@@ -86,7 +86,7 @@ var GetServersUtil = function () {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}, {
|
|
89
|
-
key:
|
|
89
|
+
key: 'parseServers',
|
|
90
90
|
value: function parseServers(record, routerAddress) {
|
|
91
91
|
try {
|
|
92
92
|
var servers = record.get('servers');
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DnsHostNameResolver = exports.DummyHostNameResolver = undefined;
|
|
7
|
+
|
|
8
|
+
var _promise = require('babel-runtime/core-js/promise');
|
|
9
|
+
|
|
10
|
+
var _promise2 = _interopRequireDefault(_promise);
|
|
11
|
+
|
|
12
|
+
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
|
|
13
|
+
|
|
14
|
+
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
|
15
|
+
|
|
16
|
+
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
|
17
|
+
|
|
18
|
+
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
|
19
|
+
|
|
20
|
+
var _inherits2 = require('babel-runtime/helpers/inherits');
|
|
21
|
+
|
|
22
|
+
var _inherits3 = _interopRequireDefault(_inherits2);
|
|
23
|
+
|
|
24
|
+
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
|
25
|
+
|
|
26
|
+
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
|
27
|
+
|
|
28
|
+
var _createClass2 = require('babel-runtime/helpers/createClass');
|
|
29
|
+
|
|
30
|
+
var _createClass3 = _interopRequireDefault(_createClass2);
|
|
31
|
+
|
|
32
|
+
var _util = require('./util');
|
|
33
|
+
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
|
+
|
|
36
|
+
var HostNameResolver = function () {
|
|
37
|
+
function HostNameResolver() {
|
|
38
|
+
(0, _classCallCheck3.default)(this, HostNameResolver);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
(0, _createClass3.default)(HostNameResolver, [{
|
|
42
|
+
key: 'resolve',
|
|
43
|
+
value: function resolve() {
|
|
44
|
+
throw new Error('Abstract function');
|
|
45
|
+
}
|
|
46
|
+
}]);
|
|
47
|
+
return HostNameResolver;
|
|
48
|
+
}(); /**
|
|
49
|
+
* Copyright (c) 2002-2017 "Neo Technology,","
|
|
50
|
+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
|
|
51
|
+
*
|
|
52
|
+
* This file is part of Neo4j.
|
|
53
|
+
*
|
|
54
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
55
|
+
* you may not use this file except in compliance with the License.
|
|
56
|
+
* You may obtain a copy of the License at
|
|
57
|
+
*
|
|
58
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
59
|
+
*
|
|
60
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
61
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
62
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
63
|
+
* See the License for the specific language governing permissions and
|
|
64
|
+
* limitations under the License.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
var DummyHostNameResolver = exports.DummyHostNameResolver = function (_HostNameResolver) {
|
|
68
|
+
(0, _inherits3.default)(DummyHostNameResolver, _HostNameResolver);
|
|
69
|
+
|
|
70
|
+
function DummyHostNameResolver() {
|
|
71
|
+
(0, _classCallCheck3.default)(this, DummyHostNameResolver);
|
|
72
|
+
return (0, _possibleConstructorReturn3.default)(this, (DummyHostNameResolver.__proto__ || (0, _getPrototypeOf2.default)(DummyHostNameResolver)).apply(this, arguments));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
(0, _createClass3.default)(DummyHostNameResolver, [{
|
|
76
|
+
key: 'resolve',
|
|
77
|
+
value: function resolve(seedRouter) {
|
|
78
|
+
return resolveToItself(seedRouter);
|
|
79
|
+
}
|
|
80
|
+
}]);
|
|
81
|
+
return DummyHostNameResolver;
|
|
82
|
+
}(HostNameResolver);
|
|
83
|
+
|
|
84
|
+
var DnsHostNameResolver = exports.DnsHostNameResolver = function (_HostNameResolver2) {
|
|
85
|
+
(0, _inherits3.default)(DnsHostNameResolver, _HostNameResolver2);
|
|
86
|
+
|
|
87
|
+
function DnsHostNameResolver() {
|
|
88
|
+
(0, _classCallCheck3.default)(this, DnsHostNameResolver);
|
|
89
|
+
|
|
90
|
+
var _this2 = (0, _possibleConstructorReturn3.default)(this, (DnsHostNameResolver.__proto__ || (0, _getPrototypeOf2.default)(DnsHostNameResolver)).call(this));
|
|
91
|
+
|
|
92
|
+
_this2._dns = require('dns');
|
|
93
|
+
return _this2;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
(0, _createClass3.default)(DnsHostNameResolver, [{
|
|
97
|
+
key: 'resolve',
|
|
98
|
+
value: function resolve(seedRouter) {
|
|
99
|
+
var _this3 = this;
|
|
100
|
+
|
|
101
|
+
var seedRouterHost = (0, _util.parseHost)(seedRouter);
|
|
102
|
+
var seedRouterPort = (0, _util.parsePort)(seedRouter);
|
|
103
|
+
|
|
104
|
+
return new _promise2.default(function (resolve) {
|
|
105
|
+
_this3._dns.lookup(seedRouterHost, { all: true }, function (error, addresses) {
|
|
106
|
+
if (error) {
|
|
107
|
+
resolve(resolveToItself(seedRouter));
|
|
108
|
+
} else {
|
|
109
|
+
var addressesWithPorts = addresses.map(function (address) {
|
|
110
|
+
return addressWithPort(address, seedRouterPort);
|
|
111
|
+
});
|
|
112
|
+
resolve(addressesWithPorts);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}]);
|
|
118
|
+
return DnsHostNameResolver;
|
|
119
|
+
}(HostNameResolver);
|
|
120
|
+
|
|
121
|
+
function resolveToItself(address) {
|
|
122
|
+
return _promise2.default.resolve([address]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function addressWithPort(addressObject, port) {
|
|
126
|
+
var address = addressObject.address;
|
|
127
|
+
if (port) {
|
|
128
|
+
return address + ':' + port;
|
|
129
|
+
}
|
|
130
|
+
return address;
|
|
131
|
+
}
|