neo4j-driver 5.3.0 → 5.4.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.
@@ -1,22 +1,4 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
- var _neo4jDriverCore = require("neo4j-driver-core");
15
-
16
- var _rxjs = require("rxjs");
17
-
18
- var _operators = require("rxjs/operators");
19
-
20
2
  /**
21
3
  * Copyright (c) "Neo4j"
22
4
  * Neo4j Sweden AB [http://neo4j.com]
@@ -35,105 +17,75 @@ var _operators = require("rxjs/operators");
35
17
  * See the License for the specific language governing permissions and
36
18
  * limitations under the License.
37
19
  */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var neo4j_driver_core_1 = require("neo4j-driver-core");
38
22
  // eslint-disable-next-line no-unused-vars
39
- var Logger = _neo4jDriverCore.internal.logger.Logger;
40
- var SERVICE_UNAVAILABLE = _neo4jDriverCore.error.SERVICE_UNAVAILABLE;
23
+ var rxjs_1 = require("rxjs");
24
+ var operators_1 = require("rxjs/operators");
25
+ var
26
+ // eslint-disable-next-line no-unused-vars
27
+ Logger = neo4j_driver_core_1.internal.logger.Logger;
28
+ var SERVICE_UNAVAILABLE = neo4j_driver_core_1.error.SERVICE_UNAVAILABLE;
41
29
  var DEFAULT_MAX_RETRY_TIME_MS = 30 * 1000; // 30 seconds
42
-
43
30
  var DEFAULT_INITIAL_RETRY_DELAY_MS = 1000; // 1 seconds
44
-
45
31
  var DEFAULT_RETRY_DELAY_MULTIPLIER = 2.0;
46
32
  var DEFAULT_RETRY_DELAY_JITTER_FACTOR = 0.2;
47
-
48
- var RxRetryLogic = /*#__PURE__*/function () {
49
- /**
50
- *
51
- * @param {Object} args
52
- * @param {Logger} args.logger
53
- */
54
- function RxRetryLogic() {
55
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
56
- _ref$maxRetryTimeout = _ref.maxRetryTimeout,
57
- maxRetryTimeout = _ref$maxRetryTimeout === void 0 ? DEFAULT_MAX_RETRY_TIME_MS : _ref$maxRetryTimeout,
58
- _ref$initialDelay = _ref.initialDelay,
59
- initialDelay = _ref$initialDelay === void 0 ? DEFAULT_INITIAL_RETRY_DELAY_MS : _ref$initialDelay,
60
- _ref$delayMultiplier = _ref.delayMultiplier,
61
- delayMultiplier = _ref$delayMultiplier === void 0 ? DEFAULT_RETRY_DELAY_MULTIPLIER : _ref$delayMultiplier,
62
- _ref$delayJitter = _ref.delayJitter,
63
- delayJitter = _ref$delayJitter === void 0 ? DEFAULT_RETRY_DELAY_JITTER_FACTOR : _ref$delayJitter,
64
- _ref$logger = _ref.logger,
65
- logger = _ref$logger === void 0 ? null : _ref$logger;
66
-
67
- (0, _classCallCheck2["default"])(this, RxRetryLogic);
68
- this._maxRetryTimeout = valueOrDefault(maxRetryTimeout, DEFAULT_MAX_RETRY_TIME_MS);
69
- this._initialDelay = valueOrDefault(initialDelay, DEFAULT_INITIAL_RETRY_DELAY_MS);
70
- this._delayMultiplier = valueOrDefault(delayMultiplier, DEFAULT_RETRY_DELAY_MULTIPLIER);
71
- this._delayJitter = valueOrDefault(delayJitter, DEFAULT_RETRY_DELAY_JITTER_FACTOR);
72
- this._logger = logger;
73
- }
74
- /**
75
- *
76
- * @param {Observable<Any>} work
77
- */
78
-
79
-
80
- (0, _createClass2["default"])(RxRetryLogic, [{
81
- key: "retry",
82
- value: function retry(work) {
83
- var _this = this;
84
-
85
- return work.pipe((0, _operators.retryWhen)(function (failedWork) {
86
- var handledExceptions = [];
87
- var startTime = Date.now();
88
- var retryCount = 1;
89
- var delayDuration = _this._initialDelay;
90
- return failedWork.pipe((0, _operators.mergeMap)(function (err) {
91
- if (!(0, _neo4jDriverCore.isRetriableError)(err)) {
92
- return (0, _rxjs.throwError)(function () {
93
- return err;
94
- });
95
- }
96
-
97
- handledExceptions.push(err);
98
-
99
- if (retryCount >= 2 && Date.now() - startTime >= _this._maxRetryTimeout) {
100
- var _error = (0, _neo4jDriverCore.newError)("Failed after retried for ".concat(retryCount, " times in ").concat(_this._maxRetryTimeout, " ms. Make sure that your database is online and retry again."), SERVICE_UNAVAILABLE);
101
-
102
- _error.seenErrors = handledExceptions;
103
- return (0, _rxjs.throwError)(function () {
104
- return _error;
105
- });
106
- }
107
-
108
- var nextDelayDuration = _this._computeNextDelay(delayDuration);
109
-
110
- delayDuration = delayDuration * _this._delayMultiplier;
111
- retryCount++;
112
-
113
- if (_this._logger) {
114
- _this._logger.warn("Transaction failed and will be retried in ".concat(nextDelayDuration));
115
- }
116
-
117
- return (0, _rxjs.of)(1).pipe((0, _operators.delay)(nextDelayDuration));
118
- }));
119
- }));
120
- }
121
- }, {
122
- key: "_computeNextDelay",
123
- value: function _computeNextDelay(delay) {
124
- var jitter = delay * this._delayJitter;
125
- return delay - jitter + 2 * jitter * Math.random();
33
+ var RxRetryLogic = /** @class */ (function () {
34
+ /**
35
+ *
36
+ * @param {Object} args
37
+ * @param {Logger} args.logger
38
+ */
39
+ function RxRetryLogic(_a) {
40
+ var _b = _a === void 0 ? {} : _a, _c = _b.maxRetryTimeout, maxRetryTimeout = _c === void 0 ? DEFAULT_MAX_RETRY_TIME_MS : _c, _d = _b.initialDelay, initialDelay = _d === void 0 ? DEFAULT_INITIAL_RETRY_DELAY_MS : _d, _e = _b.delayMultiplier, delayMultiplier = _e === void 0 ? DEFAULT_RETRY_DELAY_MULTIPLIER : _e, _f = _b.delayJitter, delayJitter = _f === void 0 ? DEFAULT_RETRY_DELAY_JITTER_FACTOR : _f, _g = _b.logger, logger = _g === void 0 ? null : _g;
41
+ this._maxRetryTimeout = valueOrDefault(maxRetryTimeout, DEFAULT_MAX_RETRY_TIME_MS);
42
+ this._initialDelay = valueOrDefault(initialDelay, DEFAULT_INITIAL_RETRY_DELAY_MS);
43
+ this._delayMultiplier = valueOrDefault(delayMultiplier, DEFAULT_RETRY_DELAY_MULTIPLIER);
44
+ this._delayJitter = valueOrDefault(delayJitter, DEFAULT_RETRY_DELAY_JITTER_FACTOR);
45
+ this._logger = logger;
126
46
  }
127
- }]);
128
- return RxRetryLogic;
129
- }();
130
-
131
- exports["default"] = RxRetryLogic;
132
-
47
+ /**
48
+ *
49
+ * @param {Observable<Any>} work
50
+ */
51
+ RxRetryLogic.prototype.retry = function (work) {
52
+ var _this = this;
53
+ return work.pipe((0, operators_1.retryWhen)(function (failedWork) {
54
+ var handledExceptions = [];
55
+ var startTime = Date.now();
56
+ var retryCount = 1;
57
+ var delayDuration = _this._initialDelay;
58
+ return failedWork.pipe((0, operators_1.mergeMap)(function (err) {
59
+ if (!(0, neo4j_driver_core_1.isRetriableError)(err)) {
60
+ return (0, rxjs_1.throwError)(function () { return err; });
61
+ }
62
+ handledExceptions.push(err);
63
+ if (retryCount >= 2 &&
64
+ Date.now() - startTime >= _this._maxRetryTimeout) {
65
+ var error_1 = (0, neo4j_driver_core_1.newError)("Failed after retried for ".concat(retryCount, " times in ").concat(_this._maxRetryTimeout, " ms. Make sure that your database is online and retry again."), SERVICE_UNAVAILABLE);
66
+ error_1.seenErrors = handledExceptions;
67
+ return (0, rxjs_1.throwError)(function () { return error_1; });
68
+ }
69
+ var nextDelayDuration = _this._computeNextDelay(delayDuration);
70
+ delayDuration = delayDuration * _this._delayMultiplier;
71
+ retryCount++;
72
+ if (_this._logger) {
73
+ _this._logger.warn("Transaction failed and will be retried in ".concat(nextDelayDuration));
74
+ }
75
+ return (0, rxjs_1.of)(1).pipe((0, operators_1.delay)(nextDelayDuration));
76
+ }));
77
+ }));
78
+ };
79
+ RxRetryLogic.prototype._computeNextDelay = function (delay) {
80
+ var jitter = delay * this._delayJitter;
81
+ return delay - jitter + 2 * jitter * Math.random();
82
+ };
83
+ return RxRetryLogic;
84
+ }());
85
+ exports.default = RxRetryLogic;
133
86
  function valueOrDefault(value, defaultValue) {
134
- if (value || value === 0) {
135
- return value;
136
- }
137
-
138
- return defaultValue;
87
+ if (value || value === 0) {
88
+ return value;
89
+ }
90
+ return defaultValue;
139
91
  }
@@ -1,18 +1,4 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.VERSION_IN_DEV = exports.VERSION_4_0_0 = exports.VERSION_3_5_0 = exports.VERSION_3_4_0 = exports.VERSION_3_2_0 = exports.ServerVersion = void 0;
9
-
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
- var _neo4jDriverCore = require("neo4j-driver-core");
15
-
16
2
  /**
17
3
  * Copyright (c) "Neo4j"
18
4
  * Neo4j Sweden AB [http://neo4j.com]
@@ -31,125 +17,100 @@ var _neo4jDriverCore = require("neo4j-driver-core");
31
17
  * See the License for the specific language governing permissions and
32
18
  * limitations under the License.
33
19
  */
34
- var assertString = _neo4jDriverCore.internal.util.assertString;
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.VERSION_IN_DEV = exports.VERSION_4_0_0 = exports.VERSION_3_5_0 = exports.VERSION_3_4_0 = exports.VERSION_3_2_0 = exports.ServerVersion = void 0;
22
+ var neo4j_driver_core_1 = require("neo4j-driver-core");
23
+ var assertString = neo4j_driver_core_1.internal.util.assertString;
35
24
  var SERVER_VERSION_REGEX = /^(Neo4j\/)?(\d+)\.(\d+)(?:\.)?(\d*)(\.|-|\+)?([0-9A-Za-z-.]*)?$/;
36
25
  var NEO4J_IN_DEV_VERSION_STRING = 'Neo4j/dev';
37
-
38
- var ServerVersion = /*#__PURE__*/function () {
39
- /**
40
- * @constructor
41
- * @param {number} major the major version number.
42
- * @param {number} minor the minor version number.
43
- * @param {number} patch the patch version number.
44
- * @param {string} [originalVersionString] the original version string
45
- */
46
- function ServerVersion(major, minor, patch, originalVersionString) {
47
- (0, _classCallCheck2["default"])(this, ServerVersion);
48
- this.major = major;
49
- this.minor = minor;
50
- this.patch = patch;
51
- this._originalVersionString = originalVersionString;
52
- }
53
- /**
54
- * Fetch server version using the given driver.
55
- * @param {Driver} driver the driver to use.
56
- * @return {Promise<ServerVersion>} promise resolved with a {@link ServerVersion} object or rejected with error.
57
- */
58
-
59
-
60
- (0, _createClass2["default"])(ServerVersion, [{
61
- key: "compareTo",
62
- value:
26
+ var ServerVersion = /** @class */ (function () {
63
27
  /**
64
- * Compare this version to the given one.
65
- * @param {ServerVersion} other the version to compare with.
66
- * @return {number} value 0 if this version is the same as the given one, value less then 0 when this version
67
- * was released earlier than the given one and value greater then 0 when this version was released after
68
- * than the given one.
28
+ * @constructor
29
+ * @param {number} major the major version number.
30
+ * @param {number} minor the minor version number.
31
+ * @param {number} patch the patch version number.
32
+ * @param {string} [originalVersionString] the original version string
69
33
  */
70
- function compareTo(other) {
71
- var result = compareInts(this.major, other.major);
72
-
73
- if (result === 0) {
74
- result = compareInts(this.minor, other.minor);
75
-
76
- if (result === 0) {
77
- result = compareInts(this.patch, other.patch);
78
- }
79
- }
80
-
81
- return result;
34
+ function ServerVersion(major, minor, patch, originalVersionString) {
35
+ this.major = major;
36
+ this.minor = minor;
37
+ this.patch = patch;
38
+ this._originalVersionString = originalVersionString;
82
39
  }
83
- }, {
84
- key: "toString",
85
- value: function toString() {
86
- if (this._originalVersionString) {
87
- return this._originalVersionString;
88
- }
89
-
90
- return "".concat(this.major, ".").concat(this.minor, ".").concat(this.patch);
91
- }
92
- }], [{
93
- key: "fromDriver",
94
- value: function fromDriver(driver) {
95
- var session = driver.session();
96
- return session.run('RETURN 1').then(function (result) {
97
- return session.close().then(function () {
98
- return ServerVersion.fromString(result.summary.server.version);
40
+ /**
41
+ * Fetch server version using the given driver.
42
+ * @param {Driver} driver the driver to use.
43
+ * @return {Promise<ServerVersion>} promise resolved with a {@link ServerVersion} object or rejected with error.
44
+ */
45
+ ServerVersion.fromDriver = function (driver) {
46
+ var session = driver.session();
47
+ return session
48
+ .run('RETURN 1')
49
+ .then(function (result) {
50
+ return session
51
+ .close()
52
+ .then(function () { return ServerVersion.fromString(result.summary.server.version); });
99
53
  });
100
- });
101
- }
54
+ };
102
55
  /**
103
56
  * Parse given string to a {@link ServerVersion} object.
104
57
  * @param {string} versionStr the string to parse.
105
58
  * @return {ServerVersion} version for the given string.
106
59
  * @throws Error if given string can't be parsed.
107
60
  */
108
-
109
- }, {
110
- key: "fromString",
111
- value: function fromString(versionStr) {
112
- if (!versionStr) {
113
- return new ServerVersion(3, 0, 0);
114
- }
115
-
116
- assertString(versionStr, 'Neo4j version string');
117
-
118
- if (versionStr.toLowerCase() === NEO4J_IN_DEV_VERSION_STRING.toLowerCase()) {
119
- return VERSION_IN_DEV;
120
- }
121
-
122
- var version = versionStr.match(SERVER_VERSION_REGEX);
123
-
124
- if (!version) {
125
- throw new Error("Unparsable Neo4j version: ".concat(versionStr));
126
- }
127
-
128
- var major = parseIntStrict(version[2]);
129
- var minor = parseIntStrict(version[3]);
130
- var patch = parseIntStrict(version[4] || 0);
131
- return new ServerVersion(major, minor, patch, versionStr);
132
- }
133
- }]);
134
- return ServerVersion;
135
- }();
136
-
61
+ ServerVersion.fromString = function (versionStr) {
62
+ if (!versionStr) {
63
+ return new ServerVersion(3, 0, 0);
64
+ }
65
+ assertString(versionStr, 'Neo4j version string');
66
+ if (versionStr.toLowerCase() === NEO4J_IN_DEV_VERSION_STRING.toLowerCase()) {
67
+ return VERSION_IN_DEV;
68
+ }
69
+ var version = versionStr.match(SERVER_VERSION_REGEX);
70
+ if (!version) {
71
+ throw new Error("Unparsable Neo4j version: ".concat(versionStr));
72
+ }
73
+ var major = parseIntStrict(version[2]);
74
+ var minor = parseIntStrict(version[3]);
75
+ var patch = parseIntStrict(version[4] || 0);
76
+ return new ServerVersion(major, minor, patch, versionStr);
77
+ };
78
+ /**
79
+ * Compare this version to the given one.
80
+ * @param {ServerVersion} other the version to compare with.
81
+ * @return {number} value 0 if this version is the same as the given one, value less then 0 when this version
82
+ * was released earlier than the given one and value greater then 0 when this version was released after
83
+ * than the given one.
84
+ */
85
+ ServerVersion.prototype.compareTo = function (other) {
86
+ var result = compareInts(this.major, other.major);
87
+ if (result === 0) {
88
+ result = compareInts(this.minor, other.minor);
89
+ if (result === 0) {
90
+ result = compareInts(this.patch, other.patch);
91
+ }
92
+ }
93
+ return result;
94
+ };
95
+ ServerVersion.prototype.toString = function () {
96
+ if (this._originalVersionString) {
97
+ return this._originalVersionString;
98
+ }
99
+ return "".concat(this.major, ".").concat(this.minor, ".").concat(this.patch);
100
+ };
101
+ return ServerVersion;
102
+ }());
137
103
  exports.ServerVersion = ServerVersion;
138
-
139
104
  function parseIntStrict(str, name) {
140
- var value = parseInt(str, 10);
141
-
142
- if (!value && value !== 0) {
143
- throw new Error("Unparsable number ".concat(name, ": '").concat(str, "'"));
144
- }
145
-
146
- return value;
105
+ var value = parseInt(str, 10);
106
+ if (!value && value !== 0) {
107
+ throw new Error("Unparsable number ".concat(name, ": '").concat(str, "'"));
108
+ }
109
+ return value;
147
110
  }
148
-
149
111
  function compareInts(x, y) {
150
- return x < y ? -1 : x === y ? 0 : 1;
112
+ return x < y ? -1 : x === y ? 0 : 1;
151
113
  }
152
-
153
114
  var VERSION_3_2_0 = ServerVersion.fromString('Neo4j/3.2.0');
154
115
  exports.VERSION_3_2_0 = VERSION_3_2_0;
155
116
  var VERSION_3_4_0 = ServerVersion.fromString('Neo4j/3.4.0');