sqlite-executor 4.0.11 → 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,32 +55,111 @@ __webpack_require__.d(__webpack_exports__, {
55
55
  return metrics_Metrics;
56
56
  }
57
57
  });
58
- var DEFAULT_STATEMENT_TIMEOUT = 30000;
59
- function formatDateTime(date) {
60
- var y = date.getFullYear();
61
- var M = String(date.getMonth() + 1).padStart(2, "0");
62
- var d = String(date.getDate()).padStart(2, "0");
63
- var h = String(date.getHours()).padStart(2, "0");
64
- var m = String(date.getMinutes()).padStart(2, "0");
65
- var s = String(date.getSeconds()).padStart(2, "0");
66
- var ms = String(date.getMilliseconds()).padStart(3, "0");
67
- return "".concat(y, "-").concat(M, "-").concat(d, " ").concat(h, ":").concat(m, ":").concat(s, ".").concat(ms);
68
- }
69
- function formatDuration(ms) {
70
- if (ms < 1000) return "".concat(ms, "ms");
71
- if (ms < 60000) return "".concat((ms / 1000).toFixed(1), "s");
72
- var mins = Math.floor(ms / 60000);
73
- var secs = (ms % 60000 / 1000).toFixed(1);
74
- return "".concat(mins, "m ").concat(secs, "s");
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);
75
103
  }
104
+ var DEFAULT_STATEMENT_TIMEOUT = 30000;
76
105
  function createTimeoutError(timeout, sql, startTime) {
77
- if (void 0 !== startTime) {
78
- var elapsed = Math.max(0, performance.now() - startTime);
79
- var startDate = new Date(Date.now() - elapsed);
80
- var deadlineDate = new Date(startDate.getTime() + timeout);
81
- return new Error("SQLite statement timed out after ".concat(formatDuration(timeout), " ") + "(start: ".concat(formatDateTime(startDate), ", ") + "deadline: ".concat(formatDateTime(deadlineDate), "): ").concat(sql));
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
+ }
82
157
  }
83
- return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(sql));
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");
84
163
  }
85
164
  function toError(value) {
86
165
  return value instanceof Error ? value : new Error(String(value));
@@ -625,7 +704,6 @@ function createTransactionHandle(scopeId, executor) {
625
704
  return handle;
626
705
  }
627
706
  var external_node_child_process_namespaceObject = require("node:child_process");
628
- var external_node_events_namespaceObject = require("node:events");
629
707
  var external_node_fs_namespaceObject = require("node:fs");
630
708
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
631
709
  var external_node_path_namespaceObject = require("node:path");
@@ -1023,7 +1101,7 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1023
1101
  value: function() {
1024
1102
  var _this = this;
1025
1103
  return _async_to_generator(function() {
1026
- var proc, timer, _proc_stdin;
1104
+ var proc;
1027
1105
  return _ts_generator(this, function(_state) {
1028
1106
  switch(_state.label){
1029
1107
  case 0:
@@ -1031,6 +1109,9 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1031
1109
  if (!proc) return [
1032
1110
  2
1033
1111
  ];
1112
+ if (null !== proc.exitCode || null !== proc.signalCode) return [
1113
+ 2
1114
+ ];
1034
1115
  if (!(process_class_private_field_get(_this, _draining) || process_class_private_field_get(_this, _writeBuffer).length > 0)) return [
1035
1116
  3,
1036
1117
  2
@@ -1049,40 +1130,43 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1049
1130
  _state.sent();
1050
1131
  _state.label = 2;
1051
1132
  case 2:
1052
- timer = setTimeout(function() {
1053
- proc.kill();
1054
- }, GRACEFUL_SHUTDOWN_TIMEOUT).unref();
1055
- _state.label = 3;
1056
- case 3:
1057
- _state.trys.push([
1058
- 3,
1059
- 5,
1060
- 6,
1061
- 7
1062
- ]);
1063
- null == (_proc_stdin = proc.stdin) || _proc_stdin.write(".quit\n");
1064
- return [
1065
- 4,
1066
- (0, external_node_events_namespaceObject.once)(proc, "close")
1133
+ if (null !== proc.exitCode || null !== proc.signalCode) return [
1134
+ 2
1067
1135
  ];
1068
- case 4:
1069
- _state.sent();
1070
1136
  return [
1071
- 3,
1072
- 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
+ })
1073
1167
  ];
1074
- case 5:
1168
+ case 3:
1075
1169
  _state.sent();
1076
- return [
1077
- 3,
1078
- 7
1079
- ];
1080
- case 6:
1081
- clearTimeout(timer);
1082
- return [
1083
- 7
1084
- ];
1085
- case 7:
1086
1170
  return [
1087
1171
  2
1088
1172
  ];
@@ -1901,13 +1985,13 @@ function shrinkIfNeeded() {
1901
1985
  queue_class_private_field_set(this, _mask, INITIAL_CAPACITY - 1);
1902
1986
  }
1903
1987
  }
1904
- function _array_like_to_array(arr, len) {
1988
+ function inflightTracker_array_like_to_array(arr, len) {
1905
1989
  if (null == len || len > arr.length) len = arr.length;
1906
1990
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1907
1991
  return arr2;
1908
1992
  }
1909
1993
  function _array_without_holes(arr) {
1910
- if (Array.isArray(arr)) return _array_like_to_array(arr);
1994
+ if (Array.isArray(arr)) return inflightTracker_array_like_to_array(arr);
1911
1995
  }
1912
1996
  function inflightTracker_check_private_redeclaration(obj, privateCollection) {
1913
1997
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -1984,15 +2068,15 @@ function _non_iterable_spread() {
1984
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.");
1985
2069
  }
1986
2070
  function _to_consumable_array(arr) {
1987
- 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();
1988
2072
  }
1989
- function _unsupported_iterable_to_array(o, minLen) {
2073
+ function inflightTracker_unsupported_iterable_to_array(o, minLen) {
1990
2074
  if (!o) return;
1991
- if ("string" == typeof o) return _array_like_to_array(o, minLen);
2075
+ if ("string" == typeof o) return inflightTracker_array_like_to_array(o, minLen);
1992
2076
  var n = Object.prototype.toString.call(o).slice(8, -1);
1993
2077
  if ("Object" === n && o.constructor) n = o.constructor.name;
1994
2078
  if ("Map" === n || "Set" === n) return Array.from(n);
1995
- 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);
1996
2080
  }
1997
2081
  var _tasks = /*#__PURE__*/ new WeakMap(), inflightTracker_head = /*#__PURE__*/ new WeakMap();
1998
2082
  var inflightTracker_InflightTracker = /*#__PURE__*/ function() {
@@ -2293,7 +2377,7 @@ function prepareTaskTimeout(task, metrics) {
2293
2377
  if (task.settled) return null;
2294
2378
  task.timedout = true;
2295
2379
  null == metrics || metrics.incrementTasksTimeout();
2296
- return createTimeoutError(task.timeout, task.sql, task.startTime);
2380
+ return createTimeoutError(task.timeout, task.sql, task.startedAt);
2297
2381
  }
2298
2382
  function createSweeper(param) {
2299
2383
  var inflight = param.inflight, sweepIntervalMs = param.sweepIntervalMs, handleTaskTimeout = param.handleTaskTimeout;
@@ -2303,9 +2387,8 @@ function createSweeper(param) {
2303
2387
  sweepTimer = setTimeout(function() {
2304
2388
  sweepTimer = null;
2305
2389
  var now = performance.now();
2306
- inflight.forEach(function(task) {
2307
- if (now - task.startTime > task.timeout) handleTaskTimeout(task);
2308
- });
2390
+ var task = inflight.first;
2391
+ if (task && now - task.startTime > task.timeout) handleTaskTimeout(task);
2309
2392
  if (inflight.count > 0) schedule();
2310
2393
  }, sweepIntervalMs).unref();
2311
2394
  };
@@ -2411,7 +2494,10 @@ function advanceNextInflightStartTime(inflight) {
2411
2494
  var next = inflight.first;
2412
2495
  if (next && next.startTime > 0) {
2413
2496
  var now = performance.now();
2414
- if (now > next.startTime) next.startTime = now;
2497
+ if (now > next.startTime) {
2498
+ next.startTime = now;
2499
+ next.startedAt = Date.now();
2500
+ }
2415
2501
  }
2416
2502
  }
2417
2503
  function handleParsedValue(raw, inflight, param) {
@@ -2460,6 +2546,7 @@ function createPumpQueue(param) {
2460
2546
  }
2461
2547
  if (0 === batch.length) return;
2462
2548
  var now = performance.now();
2549
+ var startedAt = Date.now();
2463
2550
  var payload = buildBatchPayload(batch);
2464
2551
  var batchId = nextBatchId++;
2465
2552
  var useWalBatch = payload.startsWith("BEGIN;");
@@ -2468,6 +2555,7 @@ function createPumpQueue(param) {
2468
2555
  for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2469
2556
  var task1 = _step.value;
2470
2557
  task1.startTime = now;
2558
+ task1.startedAt = startedAt;
2471
2559
  task1.batchId = batchId;
2472
2560
  task1.walBatch = useWalBatch;
2473
2561
  }
@@ -2872,7 +2960,8 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2872
2960
  consumerError: null,
2873
2961
  stderrText: "",
2874
2962
  settled: false,
2875
- startTime: 0
2963
+ startTime: 0,
2964
+ startedAt: 0
2876
2965
  };
2877
2966
  null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _metrics)) || _$_class_private_field_get.incrementTasksTotal(config.kind);
2878
2967
  taskWorker_class_private_field_get(this, _pendingQueue).enqueue(task);
@@ -4534,6 +4623,7 @@ function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
4534
4623
  stderrText: "",
4535
4624
  settled: false,
4536
4625
  startTime: 0,
4626
+ startedAt: 0,
4537
4627
  rowParser: null,
4538
4628
  rows: "query" === kind ? [] : null
4539
4629
  };