sqlite-executor 4.0.10 → 4.0.12

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.
@@ -55,9 +55,111 @@ __webpack_require__.d(__webpack_exports__, {
55
55
  return metrics_Metrics;
56
56
  }
57
57
  });
58
+ function _array_like_to_array(arr, len) {
59
+ if (null == len || len > arr.length) len = arr.length;
60
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
61
+ return arr2;
62
+ }
63
+ function _array_with_holes(arr) {
64
+ if (Array.isArray(arr)) return arr;
65
+ }
66
+ function _iterable_to_array_limit(arr, i) {
67
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
68
+ if (null == _i) return;
69
+ var _arr = [];
70
+ var _n = true;
71
+ var _d = false;
72
+ var _s, _e;
73
+ try {
74
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
75
+ _arr.push(_s.value);
76
+ if (i && _arr.length === i) break;
77
+ }
78
+ } catch (err) {
79
+ _d = true;
80
+ _e = err;
81
+ } finally{
82
+ try {
83
+ if (!_n && null != _i["return"]) _i["return"]();
84
+ } finally{
85
+ if (_d) throw _e;
86
+ }
87
+ }
88
+ return _arr;
89
+ }
90
+ function _non_iterable_rest() {
91
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
92
+ }
93
+ function _sliced_to_array(arr, i) {
94
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
95
+ }
96
+ function _unsupported_iterable_to_array(o, minLen) {
97
+ if (!o) return;
98
+ if ("string" == typeof o) return _array_like_to_array(o, minLen);
99
+ var n = Object.prototype.toString.call(o).slice(8, -1);
100
+ if ("Object" === n && o.constructor) n = o.constructor.name;
101
+ if ("Map" === n || "Set" === n) return Array.from(n);
102
+ if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
103
+ }
58
104
  var DEFAULT_STATEMENT_TIMEOUT = 30000;
59
- function createTimeoutError(timeout, sql) {
60
- return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(sql));
105
+ function createTimeoutError(timeout, sql, startTime) {
106
+ var startedAt = resolveStartTimestamp(startTime, timeout);
107
+ var deadline = startedAt + timeout;
108
+ var duration = formatDuration(timeout);
109
+ var rawDuration = duration === "".concat(timeout, "ms") ? "" : " (".concat(timeout, "ms)");
110
+ return new Error("SQLite statement timed out after ".concat(duration).concat(rawDuration, "; ") + "started at ".concat(formatTimestamp(startedAt), "; ") + "deadline at ".concat(formatTimestamp(deadline), "; SQL: ").concat(sql));
111
+ }
112
+ function resolveStartTimestamp(startTime, timeout) {
113
+ if (!Number.isFinite(startTime)) return Date.now() - timeout;
114
+ if (startTime >= 1000000000000) return startTime;
115
+ return Date.now() - Math.max(0, performance.now() - startTime);
116
+ }
117
+ function formatDuration(milliseconds) {
118
+ var remaining = milliseconds;
119
+ var parts = [];
120
+ var units = [
121
+ [
122
+ 86400000,
123
+ "d"
124
+ ],
125
+ [
126
+ 3600000,
127
+ "h"
128
+ ],
129
+ [
130
+ 60000,
131
+ "m"
132
+ ],
133
+ [
134
+ 1000,
135
+ "s"
136
+ ]
137
+ ];
138
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
139
+ try {
140
+ for(var _iterator = units[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
141
+ var _step_value = _sliced_to_array(_step.value, 2), unitMilliseconds = _step_value[0], suffix = _step_value[1];
142
+ var value = Math.floor(remaining / unitMilliseconds);
143
+ if (value > 0) {
144
+ parts.push("".concat(value).concat(suffix));
145
+ remaining -= value * unitMilliseconds;
146
+ }
147
+ }
148
+ } catch (err) {
149
+ _didIteratorError = true;
150
+ _iteratorError = err;
151
+ } finally{
152
+ try {
153
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
154
+ } finally{
155
+ if (_didIteratorError) throw _iteratorError;
156
+ }
157
+ }
158
+ if (remaining > 0 || 0 === parts.length) parts.push("".concat(remaining, "ms"));
159
+ return parts.join(" ");
160
+ }
161
+ function formatTimestamp(timestamp) {
162
+ return new Date(timestamp).toISOString().replace("T", " ").replace("Z", " UTC");
61
163
  }
62
164
  function toError(value) {
63
165
  return value instanceof Error ? value : new Error(String(value));
@@ -602,7 +704,6 @@ function createTransactionHandle(scopeId, executor) {
602
704
  return handle;
603
705
  }
604
706
  var external_node_child_process_namespaceObject = require("node:child_process");
605
- var external_node_events_namespaceObject = require("node:events");
606
707
  var external_node_fs_namespaceObject = require("node:fs");
607
708
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
608
709
  var external_node_path_namespaceObject = require("node:path");
@@ -1000,7 +1101,7 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1000
1101
  value: function() {
1001
1102
  var _this = this;
1002
1103
  return _async_to_generator(function() {
1003
- var proc, timer, _proc_stdin;
1104
+ var proc;
1004
1105
  return _ts_generator(this, function(_state) {
1005
1106
  switch(_state.label){
1006
1107
  case 0:
@@ -1008,6 +1109,9 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1008
1109
  if (!proc) return [
1009
1110
  2
1010
1111
  ];
1112
+ if (null !== proc.exitCode || null !== proc.signalCode) return [
1113
+ 2
1114
+ ];
1011
1115
  if (!(process_class_private_field_get(_this, _draining) || process_class_private_field_get(_this, _writeBuffer).length > 0)) return [
1012
1116
  3,
1013
1117
  2
@@ -1026,40 +1130,43 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1026
1130
  _state.sent();
1027
1131
  _state.label = 2;
1028
1132
  case 2:
1029
- timer = setTimeout(function() {
1030
- proc.kill();
1031
- }, GRACEFUL_SHUTDOWN_TIMEOUT).unref();
1032
- _state.label = 3;
1033
- case 3:
1034
- _state.trys.push([
1035
- 3,
1036
- 5,
1037
- 6,
1038
- 7
1039
- ]);
1040
- null == (_proc_stdin = proc.stdin) || _proc_stdin.write(".quit\n");
1041
- return [
1042
- 4,
1043
- (0, external_node_events_namespaceObject.once)(proc, "close")
1133
+ if (null !== proc.exitCode || null !== proc.signalCode) return [
1134
+ 2
1044
1135
  ];
1045
- case 4:
1046
- _state.sent();
1047
1136
  return [
1048
- 3,
1049
- 7
1137
+ 4,
1138
+ new Promise(function(resolve) {
1139
+ var settled = false;
1140
+ var finish = function() {
1141
+ if (settled) return;
1142
+ settled = true;
1143
+ clearTimeout(timer);
1144
+ proc.off("close", finish);
1145
+ proc.off("error", finish);
1146
+ resolve();
1147
+ };
1148
+ var forceClose = function() {
1149
+ try {
1150
+ proc.kill();
1151
+ } catch (e) {}
1152
+ finish();
1153
+ };
1154
+ var timer = setTimeout(forceClose, GRACEFUL_SHUTDOWN_TIMEOUT);
1155
+ proc.once("close", finish);
1156
+ proc.once("error", finish);
1157
+ if (null !== proc.exitCode || null !== proc.signalCode) return void finish();
1158
+ try {
1159
+ if (!proc.stdin) return void forceClose();
1160
+ proc.stdin.write(".quit\n", function(error) {
1161
+ if (error) forceClose();
1162
+ });
1163
+ } catch (e) {
1164
+ forceClose();
1165
+ }
1166
+ })
1050
1167
  ];
1051
- case 5:
1168
+ case 3:
1052
1169
  _state.sent();
1053
- return [
1054
- 3,
1055
- 7
1056
- ];
1057
- case 6:
1058
- clearTimeout(timer);
1059
- return [
1060
- 7
1061
- ];
1062
- case 7:
1063
1170
  return [
1064
1171
  2
1065
1172
  ];
@@ -1878,13 +1985,13 @@ function shrinkIfNeeded() {
1878
1985
  queue_class_private_field_set(this, _mask, INITIAL_CAPACITY - 1);
1879
1986
  }
1880
1987
  }
1881
- function _array_like_to_array(arr, len) {
1988
+ function inflightTracker_array_like_to_array(arr, len) {
1882
1989
  if (null == len || len > arr.length) len = arr.length;
1883
1990
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1884
1991
  return arr2;
1885
1992
  }
1886
1993
  function _array_without_holes(arr) {
1887
- if (Array.isArray(arr)) return _array_like_to_array(arr);
1994
+ if (Array.isArray(arr)) return inflightTracker_array_like_to_array(arr);
1888
1995
  }
1889
1996
  function inflightTracker_check_private_redeclaration(obj, privateCollection) {
1890
1997
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -1961,15 +2068,15 @@ function _non_iterable_spread() {
1961
2068
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1962
2069
  }
1963
2070
  function _to_consumable_array(arr) {
1964
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
2071
+ return _array_without_holes(arr) || _iterable_to_array(arr) || inflightTracker_unsupported_iterable_to_array(arr) || _non_iterable_spread();
1965
2072
  }
1966
- function _unsupported_iterable_to_array(o, minLen) {
2073
+ function inflightTracker_unsupported_iterable_to_array(o, minLen) {
1967
2074
  if (!o) return;
1968
- if ("string" == typeof o) return _array_like_to_array(o, minLen);
2075
+ if ("string" == typeof o) return inflightTracker_array_like_to_array(o, minLen);
1969
2076
  var n = Object.prototype.toString.call(o).slice(8, -1);
1970
2077
  if ("Object" === n && o.constructor) n = o.constructor.name;
1971
2078
  if ("Map" === n || "Set" === n) return Array.from(n);
1972
- if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
2079
+ if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return inflightTracker_array_like_to_array(o, minLen);
1973
2080
  }
1974
2081
  var _tasks = /*#__PURE__*/ new WeakMap(), inflightTracker_head = /*#__PURE__*/ new WeakMap();
1975
2082
  var inflightTracker_InflightTracker = /*#__PURE__*/ function() {
@@ -2270,7 +2377,7 @@ function prepareTaskTimeout(task, metrics) {
2270
2377
  if (task.settled) return null;
2271
2378
  task.timedout = true;
2272
2379
  null == metrics || metrics.incrementTasksTimeout();
2273
- return createTimeoutError(task.timeout, task.sql);
2380
+ return createTimeoutError(task.timeout, task.sql, task.startedAt);
2274
2381
  }
2275
2382
  function createSweeper(param) {
2276
2383
  var inflight = param.inflight, sweepIntervalMs = param.sweepIntervalMs, handleTaskTimeout = param.handleTaskTimeout;
@@ -2280,9 +2387,8 @@ function createSweeper(param) {
2280
2387
  sweepTimer = setTimeout(function() {
2281
2388
  sweepTimer = null;
2282
2389
  var now = performance.now();
2283
- inflight.forEach(function(task) {
2284
- if (now - task.startTime > task.timeout) handleTaskTimeout(task);
2285
- });
2390
+ var task = inflight.first;
2391
+ if (task && now - task.startTime > task.timeout) handleTaskTimeout(task);
2286
2392
  if (inflight.count > 0) schedule();
2287
2393
  }, sweepIntervalMs).unref();
2288
2394
  };
@@ -2388,7 +2494,10 @@ function advanceNextInflightStartTime(inflight) {
2388
2494
  var next = inflight.first;
2389
2495
  if (next && next.startTime > 0) {
2390
2496
  var now = performance.now();
2391
- if (now > next.startTime) next.startTime = now;
2497
+ if (now > next.startTime) {
2498
+ next.startTime = now;
2499
+ next.startedAt = Date.now();
2500
+ }
2392
2501
  }
2393
2502
  }
2394
2503
  function handleParsedValue(raw, inflight, param) {
@@ -2437,6 +2546,7 @@ function createPumpQueue(param) {
2437
2546
  }
2438
2547
  if (0 === batch.length) return;
2439
2548
  var now = performance.now();
2549
+ var startedAt = Date.now();
2440
2550
  var payload = buildBatchPayload(batch);
2441
2551
  var batchId = nextBatchId++;
2442
2552
  var useWalBatch = payload.startsWith("BEGIN;");
@@ -2445,6 +2555,7 @@ function createPumpQueue(param) {
2445
2555
  for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2446
2556
  var task1 = _step.value;
2447
2557
  task1.startTime = now;
2558
+ task1.startedAt = startedAt;
2448
2559
  task1.batchId = batchId;
2449
2560
  task1.walBatch = useWalBatch;
2450
2561
  }
@@ -2849,7 +2960,8 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2849
2960
  consumerError: null,
2850
2961
  stderrText: "",
2851
2962
  settled: false,
2852
- startTime: 0
2963
+ startTime: 0,
2964
+ startedAt: 0
2853
2965
  };
2854
2966
  null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _metrics)) || _$_class_private_field_get.incrementTasksTotal(config.kind);
2855
2967
  taskWorker_class_private_field_get(this, _pendingQueue).enqueue(task);
@@ -4511,6 +4623,7 @@ function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
4511
4623
  stderrText: "",
4512
4624
  settled: false,
4513
4625
  startTime: 0,
4626
+ startedAt: 0,
4514
4627
  rowParser: null,
4515
4628
  rows: "query" === kind ? [] : null
4516
4629
  };