UNPKG

4.08 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports["default"] = void 0;
9
10var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
12var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
14var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
16var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
17
18var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
20var _driver = require("./driver");
21
22var _error = require("./error");
23
24var _connectionProviderRouting = _interopRequireDefault(require("./internal/connection-provider-routing"));
25
26var _leastConnectedLoadBalancingStrategy = _interopRequireDefault(require("./internal/least-connected-load-balancing-strategy"));
27
28var _connectionErrorHandler = _interopRequireDefault(require("./internal/connection-error-handler"));
29
30var _configuredCustomResolver = _interopRequireDefault(require("./internal/resolver/configured-custom-resolver"));
31
32/**
33 * Copyright (c) 2002-2019 "Neo4j,"
34 * Neo4j Sweden AB [http://neo4j.com]
35 *
36 * This file is part of Neo4j.
37 *
38 * Licensed under the Apache License, Version 2.0 (the "License");
39 * you may not use this file except in compliance with the License.
40 * You may obtain a copy of the License at
41 *
42 * http://www.apache.org/licenses/LICENSE-2.0
43 *
44 * Unless required by applicable law or agreed to in writing, software
45 * distributed under the License is distributed on an "AS IS" BASIS,
46 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
47 * See the License for the specific language governing permissions and
48 * limitations under the License.
49 */
50
51/**
52 * A driver that supports routing in a causal cluster.
53 * @private
54 */
55var RoutingDriver =
56/*#__PURE__*/
57function (_Driver) {
58 (0, _inherits2["default"])(RoutingDriver, _Driver);
59
60 function RoutingDriver(address, routingContext, userAgent) {
61 var _this;
62
63 var token = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
64 var config = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
65 (0, _classCallCheck2["default"])(this, RoutingDriver);
66 _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(RoutingDriver).call(this, address, userAgent, token, validateConfig(config)));
67 _this._routingContext = routingContext;
68 return _this;
69 }
70
71 (0, _createClass2["default"])(RoutingDriver, [{
72 key: "_afterConstruction",
73 value: function _afterConstruction() {
74 this._log.info("Routing driver ".concat(this._id, " created for server address ").concat(this._address));
75 }
76 }, {
77 key: "_createConnectionProvider",
78 value: function _createConnectionProvider(address, userAgent, authToken) {
79 return new _connectionProviderRouting["default"]({
80 id: this._id,
81 address: address,
82 routingContext: this._routingContext,
83 hostNameResolver: createHostNameResolver(this._config),
84 config: this._config,
85 log: this._log,
86 userAgent: userAgent,
87 authToken: authToken
88 });
89 }
90 }]);
91 return RoutingDriver;
92}(_driver.Driver);
93/**
94 * @private
95 * @returns {ConfiguredCustomResolver} new custom resolver that wraps the passed-in resolver function.
96 * If resolved function is not specified, it defaults to an identity resolver.
97 */
98
99
100function createHostNameResolver(config) {
101 return new _configuredCustomResolver["default"](config.resolver);
102}
103/**
104 * @private
105 * @returns {Object} the given config.
106 */
107
108
109function validateConfig(config) {
110 var resolver = config.resolver;
111
112 if (resolver && typeof resolver !== 'function') {
113 throw new TypeError("Configured resolver should be a function. Got: ".concat(resolver));
114 }
115
116 return config;
117}
118
119var _default = RoutingDriver;
120exports["default"] = _default;
\No newline at end of file