sqlite-executor 4.0.10 → 4.0.11

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.
@@ -5,8 +5,9 @@ export const DEFAULT_STATEMENT_TIMEOUT: 30000;
5
5
  * 创建包含 SQL 上下文的超时错误。
6
6
  * 注意:sql 应已由调用方完成规范化,本函数不再内部调用 normalizeSQL。
7
7
  *
8
- * @param timeout - 超时时间(毫秒)
9
- * @param sql - 超时发生时正在执行的 SQL 语句(已规范化)
10
- * @returns 包含超时时间和 SQL 信息的 Error 实例
8
+ * @param timeout - 超时时间(毫秒)
9
+ * @param sql - 超时发生时正在执行的 SQL 语句(已规范化)
10
+ * @param startTime - 任务开始时的 performance.now() 值(可选);提供后会生成人类可读的时间信息
11
+ * @returns 包含超时时间、时间信息和 SQL 的 Error 实例
11
12
  */
12
- export function createTimeoutError(timeout: number, sql: string): Error;
13
+ export function createTimeoutError(timeout: number, sql: string, startTime?: number): Error;
@@ -4,7 +4,30 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
6
6
  var DEFAULT_STATEMENT_TIMEOUT = 30000;
7
- function createTimeoutError(timeout, sql) {
7
+ function formatDateTime(date) {
8
+ var y = date.getFullYear();
9
+ var M = String(date.getMonth() + 1).padStart(2, "0");
10
+ var d = String(date.getDate()).padStart(2, "0");
11
+ var h = String(date.getHours()).padStart(2, "0");
12
+ var m = String(date.getMinutes()).padStart(2, "0");
13
+ var s = String(date.getSeconds()).padStart(2, "0");
14
+ var ms = String(date.getMilliseconds()).padStart(3, "0");
15
+ return "".concat(y, "-").concat(M, "-").concat(d, " ").concat(h, ":").concat(m, ":").concat(s, ".").concat(ms);
16
+ }
17
+ function formatDuration(ms) {
18
+ if (ms < 1000) return "".concat(ms, "ms");
19
+ if (ms < 60000) return "".concat((ms / 1000).toFixed(1), "s");
20
+ var mins = Math.floor(ms / 60000);
21
+ var secs = (ms % 60000 / 1000).toFixed(1);
22
+ return "".concat(mins, "m ").concat(secs, "s");
23
+ }
24
+ function createTimeoutError(timeout, sql, startTime) {
25
+ if (void 0 !== startTime) {
26
+ var elapsed = Math.max(0, performance.now() - startTime);
27
+ var startDate = new Date(Date.now() - elapsed);
28
+ var deadlineDate = new Date(startDate.getTime() + timeout);
29
+ return new Error("SQLite statement timed out after ".concat(formatDuration(timeout), " ") + "(start: ".concat(formatDateTime(startDate), ", ") + "deadline: ".concat(formatDateTime(deadlineDate), "): ").concat(sql));
30
+ }
8
31
  return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(sql));
9
32
  }
10
33
  function toError(value) {
@@ -2210,7 +2233,7 @@ function prepareTaskTimeout(task, metrics) {
2210
2233
  if (task.settled) return null;
2211
2234
  task.timedout = true;
2212
2235
  null == metrics || metrics.incrementTasksTimeout();
2213
- return createTimeoutError(task.timeout, task.sql);
2236
+ return createTimeoutError(task.timeout, task.sql, task.startTime);
2214
2237
  }
2215
2238
  function createSweeper(param) {
2216
2239
  var inflight = param.inflight, sweepIntervalMs = param.sweepIntervalMs, handleTaskTimeout = param.handleTaskTimeout;