@agile-team/mach-report 2.11.2 → 2.13.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.
Files changed (88) hide show
  1. package/README.md +30 -5
  2. package/THIRD_PARTY_NOTICES.md +270 -0
  3. package/dist/{ExcelBindingWizard-LWX6G1A2.js → ExcelBindingWizard-CeAf4QSE.js} +2 -2
  4. package/dist/{ExcelBindingWizard-a4kslPHF.cjs → ExcelBindingWizard-y0mT-AHR.cjs} +1 -1
  5. package/dist/{ReportBatchPanel-B5ClP9tm.js → ReportBatchPanel-CW2HV9I8.js} +1 -1
  6. package/dist/{ReportBatchPanel-Dc-SDkYA.cjs → ReportBatchPanel-Fp1ePFag.cjs} +1 -1
  7. package/dist/ReportPreview-BN6fk7Wz.cjs +6 -0
  8. package/dist/ReportPreview-D2Jkyh1U.js +4243 -0
  9. package/dist/{RuleEditor-C2QsOHOs.cjs → RuleEditor-ChRzNQuF.cjs} +1 -1
  10. package/dist/{RuleEditor-D9wQHrkf.js → RuleEditor-DzAmW5YH.js} +1 -1
  11. package/dist/analytics.d.cts +28 -0
  12. package/dist/analytics.d.ts +28 -0
  13. package/dist/assets-C2U-e-Sz.cjs +4 -0
  14. package/dist/assets-Q0wUwNrV.js +217 -0
  15. package/dist/code-options-BKXXY7NI.js +18 -0
  16. package/dist/code-options-BUTChiZZ.cjs +1 -0
  17. package/dist/codes.cjs +9 -0
  18. package/dist/codes.d.cts +223 -0
  19. package/dist/codes.d.ts +223 -0
  20. package/dist/codes.js +26917 -0
  21. package/dist/config-Bb7RiIO5.cjs +1 -0
  22. package/dist/{config-B612mw0x.js → config-XVwG87IA.js} +4 -0
  23. package/dist/designer.cjs +2 -2
  24. package/dist/designer.d.cts +283 -0
  25. package/dist/designer.d.ts +283 -0
  26. package/dist/designer.js +2852 -2010
  27. package/dist/grid-strokes-Cr7DwUux.cjs +1 -0
  28. package/dist/grid-strokes-DyyG1q_o.js +53 -0
  29. package/dist/index.cjs +7 -7
  30. package/dist/index.d.cts +105 -1
  31. package/dist/index.d.ts +105 -1
  32. package/dist/index.js +488 -439
  33. package/dist/pdf.cjs +76 -59
  34. package/dist/pdf.d.cts +51 -0
  35. package/dist/pdf.d.ts +51 -0
  36. package/dist/pdf.js +32128 -32048
  37. package/dist/{plugin-Cd5G2QQn.js → plugin-D4wizDXB.js} +1 -1
  38. package/dist/{plugin-BDTU4D94.cjs → plugin-DzS6pxTA.cjs} +1 -1
  39. package/dist/record-bindings-By_UKZ2g.cjs +1 -0
  40. package/dist/{list-cell-ClFra1zS.js → record-bindings-D-5jQlTj.js} +67 -44
  41. package/dist/{region-binding-workflow-DhQvu1co.cjs → region-binding-workflow-BzfbxRiR.cjs} +1 -1
  42. package/dist/{region-binding-workflow-CXDmt9Bs.js → region-binding-workflow-CcUq8W2Q.js} +1 -1
  43. package/dist/server/node.d.cts +52 -1
  44. package/dist/server/node.d.ts +52 -1
  45. package/dist/server-node.cjs +1 -1
  46. package/dist/server-node.js +239 -210
  47. package/dist/server.cjs +1 -1
  48. package/dist/server.d.cts +95 -3
  49. package/dist/server.d.ts +95 -3
  50. package/dist/server.js +457 -434
  51. package/dist/style.css +1 -1
  52. package/dist/{template-registry-WNXdkiET.js → template-registry-BjE1VS6g.js} +221 -157
  53. package/dist/template-registry-D3SjENi6.cjs +1 -0
  54. package/dist/template-review-DGwWOoCv.cjs +2 -0
  55. package/dist/{template-review-BdcXSYbx.js → template-review-PgEe_Wr9.js} +792 -666
  56. package/dist/validate-BJ5HIWY8.cjs +1 -0
  57. package/dist/validate-DbgEM1Hh.js +163 -0
  58. package/dist/vue/async.d.cts +125 -2
  59. package/dist/vue/async.d.ts +125 -2
  60. package/dist/vue/index.d.cts +121 -8
  61. package/dist/vue/index.d.ts +121 -8
  62. package/dist/vue-async.cjs +1 -1
  63. package/dist/vue-async.js +3 -3
  64. package/dist/vue.cjs +1 -1
  65. package/dist/vue.js +5 -5
  66. package/dist/{workbook-session-BKOTwcoq.js → workbook-session-BPb3TMnT.js} +1 -1
  67. package/dist/{workbook-session-CLYLhZWu.cjs → workbook-session-DNa2RHNG.cjs} +1 -1
  68. package/dist/worker.cjs +1 -1
  69. package/dist/worker.d.cts +52 -1
  70. package/dist/worker.d.ts +52 -1
  71. package/dist/worker.js +2 -2
  72. package/dist/xlsx.cjs +1 -1
  73. package/dist/xlsx.d.cts +40 -0
  74. package/dist/xlsx.d.ts +40 -0
  75. package/dist/xlsx.js +3 -3
  76. package/package.json +16 -3
  77. package/dist/ReportPreview-DWXROHBP.cjs +0 -6
  78. package/dist/ReportPreview-DiNXhQI0.js +0 -4138
  79. package/dist/assets-Bu6UohJx.cjs +0 -1
  80. package/dist/assets-DegqDNqY.js +0 -160
  81. package/dist/config-BRoLo2oj.cjs +0 -1
  82. package/dist/list-cell-BuYn4tGF.cjs +0 -1
  83. package/dist/template-registry-ukBGlm8N.cjs +0 -1
  84. package/dist/template-review-BXp2oyqg.cjs +0 -1
  85. package/dist/textwrap-CWHyzkBH.cjs +0 -4
  86. package/dist/textwrap-DE1kgcJB.js +0 -110
  87. package/dist/validate-7s0yn6ii.js +0 -148
  88. package/dist/validate-DsRiNw8h.cjs +0 -1
@@ -1,8 +1,8 @@
1
- import { parentPort as C, Worker as H } from "node:worker_threads";
2
- import { randomUUID as q, createHash as W } from "node:crypto";
3
- import { promises as l } from "node:fs";
4
- import v from "node:path";
5
- function K(e, t, n) {
1
+ import { parentPort as H, Worker as K } from "node:worker_threads";
2
+ import { randomUUID as P, createHash as W } from "node:crypto";
3
+ import { promises as h } from "node:fs";
4
+ import S from "node:path";
5
+ function Z(e, t, n) {
6
6
  if (!n?.aborted)
7
7
  try {
8
8
  const o = e?.({ ...t });
@@ -11,13 +11,13 @@ function K(e, t, n) {
11
11
  } catch {
12
12
  }
13
13
  }
14
- function V(e, t, n) {
14
+ function Q(e, t, n) {
15
15
  e.editable !== void 0 && typeof e.editable != "boolean" && n.push({ path: `${t}.editable`, message: "编辑控制应为布尔值" }), e.valueType !== void 0 && !["text", "number", "boolean"].includes(e.valueType) && n.push({ path: `${t}.valueType`, message: "编辑类型应为 text、number 或 boolean" });
16
16
  }
17
- function G(e, t, n) {
18
- V(e, t, n), e.indentMm !== void 0 && (typeof e.indentMm != "number" || !Number.isFinite(e.indentMm) || e.indentMm < 0) && n.push({ path: `${t}.indentMm`, message: "单元格缩进应为有限非负数" }), e.derived !== void 0 && typeof e.derived != "boolean" && n.push({ path: `${t}.derived`, message: "派生结果标记应为布尔值" }), F(e.source, `${t}.source`, n, !0), e.formula !== void 0 && typeof e.formula != "string" && n.push({ path: `${t}.formula`, message: "单元格公式应为字符串" });
17
+ function V(e, t, n) {
18
+ Q(e, t, n), e.indentMm !== void 0 && (typeof e.indentMm != "number" || !Number.isFinite(e.indentMm) || e.indentMm < 0) && n.push({ path: `${t}.indentMm`, message: "单元格缩进应为有限非负数" }), e.derived !== void 0 && typeof e.derived != "boolean" && n.push({ path: `${t}.derived`, message: "派生结果标记应为布尔值" }), U(e.source, `${t}.source`, n, !0), e.formula !== void 0 && typeof e.formula != "string" && n.push({ path: `${t}.formula`, message: "单元格公式应为字符串" });
19
19
  }
20
- function F(e, t, n, o = !1) {
20
+ function U(e, t, n, o = !1) {
21
21
  if (e === void 0) return;
22
22
  if (!e || typeof e != "object" || Array.isArray(e)) {
23
23
  n.push({ path: t, message: "业务来源应为对象" });
@@ -32,7 +32,22 @@ function F(e, t, n, o = !1) {
32
32
  }
33
33
  r.sourceToken !== void 0 && typeof r.sourceToken != "string" && n.push({ path: `${t}.sourceToken`, message: "来源令牌应为字符串" });
34
34
  }
35
- const X = /* @__PURE__ */ new Set([
35
+ function G(e) {
36
+ const t = [];
37
+ return e.value !== void 0 && typeof e.value != "string" && t.push({ path: "value", message: "Symbol value must be a string." }), e.symbology !== void 0 && !["code128", "code39", "ean13", "ean8"].includes(e.symbology) && t.push({ path: "symbology", message: "Unsupported barcode symbology." }), e.errorCorrection !== void 0 && !["L", "M", "Q", "H"].includes(e.errorCorrection) && t.push({ path: "errorCorrection", message: "Unsupported QR error correction." }), e.showText !== void 0 && typeof e.showText != "boolean" && t.push({ path: "showText", message: "showText must be a boolean." }), t;
38
+ }
39
+ function X(e, t) {
40
+ const n = [];
41
+ return t !== "barcode" && t !== "qrcode" && n.push({ path: "", message: "code is only supported by barcode and qrcode components." }), t === "qrcode" && e.symbology !== void 0 && n.push({ path: "symbology", message: "QR components do not use a linear symbology." }), t === "qrcode" && e.showText === !0 && n.push({ path: "showText", message: "Use a separate text component below a QR code." }), t === "barcode" && e.errorCorrection !== void 0 && n.push({ path: "errorCorrection", message: "Linear barcodes do not use QR error correction." }), n;
42
+ }
43
+ function Y(e, t) {
44
+ if (typeof e != "object" || e === null || Array.isArray(e)) return [{ path: "", message: "code must be an object." }];
45
+ const n = e, o = [...G(n), ...X(n, t)];
46
+ for (const i of Object.keys(n)) ["value", "symbology", "errorCorrection", "quietZoneModules", "showText"].includes(i) || o.push({ path: i, message: "Unknown symbol option." });
47
+ const r = n.symbology === "ean13" || n.symbology === "ean8", s = t === "qrcode" ? 4 : r ? 11 : 10;
48
+ return n.quietZoneModules !== void 0 && (!Number.isSafeInteger(n.quietZoneModules) || Number(n.quietZoneModules) < s || Number(n.quietZoneModules) > 64) && o.push({ path: "quietZoneModules", message: `Quiet zone must contain ${s}–64 whole modules.` }), o;
49
+ }
50
+ const ee = /* @__PURE__ */ new Set([
36
51
  "text",
37
52
  "image",
38
53
  "barcode",
@@ -42,19 +57,19 @@ const X = /* @__PURE__ */ new Set([
42
57
  "rect",
43
58
  "ellipse"
44
59
  ]);
45
- function N(e) {
60
+ function A(e) {
46
61
  return typeof e == "object" && e !== null && !Array.isArray(e);
47
62
  }
48
- function Z(e, t, n, o) {
63
+ function te(e, t, n, o) {
49
64
  const r = e[t];
50
65
  (typeof r != "number" || !Number.isFinite(r)) && o.push({ path: `${n}.${t}`, message: `应为有限数字,实际 ${JSON.stringify(r)}` });
51
66
  }
52
- function Q(e, t, n) {
67
+ function ne(e, t, n) {
53
68
  if (e !== void 0) {
54
69
  const o = `${t}.table`;
55
- if (!N(e)) n.push({ path: o, message: "逻辑表来源应为对象" });
70
+ if (!A(e)) n.push({ path: o, message: "逻辑表来源应为对象" });
56
71
  else {
57
- F(e.source, `${o}.source`, n), (typeof e.id != "string" || !e.id.trim()) && n.push({ path: `${o}.id`, message: "逻辑表 ID 应为非空字符串" });
72
+ U(e.source, `${o}.source`, n), (typeof e.id != "string" || !e.id.trim()) && n.push({ path: `${o}.id`, message: "逻辑表 ID 应为非空字符串" });
58
73
  const r = e.role;
59
74
  ["header", "body", "group-header", "subtotal", "grand-total"].includes(r) || n.push({ path: `${o}.role`, message: "未知逻辑表行角色" });
60
75
  const s = e.rowIndex;
@@ -62,9 +77,9 @@ function Q(e, t, n) {
62
77
  }
63
78
  }
64
79
  }
65
- function Y(e, t, n, o) {
80
+ function re(e, t, n, o) {
66
81
  if (e !== void 0)
67
- if (!N(e) || !Array.isArray(e.cells))
82
+ if (!A(e) || !Array.isArray(e.cells))
68
83
  n.push({ path: `${t}.grid.cells`, message: "grid.cells 应为二维数组" });
69
84
  else {
70
85
  const r = e.paddingMm;
@@ -73,68 +88,82 @@ function Y(e, t, n, o) {
73
88
  n.push({ path: `${t}.grid.cells.${i}`, message: "行应为数组" });
74
89
  return;
75
90
  }
76
- s.forEach((m, h) => {
77
- if (m == null) return;
78
- const u = `${t}.grid.cells.${i}.${h}`;
79
- if (!N(m)) {
91
+ s.forEach((d, y) => {
92
+ if (d == null) return;
93
+ const u = `${t}.grid.cells.${i}.${y}`;
94
+ if (!A(d)) {
80
95
  n.push({ path: u, message: "网格单元格应为对象或 null" });
81
96
  return;
82
97
  }
83
- G(m, u, n), Array.isArray(m.children) && m.children.forEach((b, k) => {
84
- D(b, `${t}.grid.cells.${i}.${h}.children.${k}`, n, o);
98
+ V(d, u, n), Array.isArray(d.children) && d.children.forEach((b, k) => {
99
+ C(b, `${t}.grid.cells.${i}.${y}.children.${k}`, n, o);
85
100
  });
86
101
  });
87
102
  });
88
103
  }
89
104
  }
90
- function ee(e, t, n) {
105
+ function oe(e, t, n) {
91
106
  e !== void 0 && (Array.isArray(e) ? e.forEach((o, r) => {
92
- (!N(o) || !Array.isArray(o.segments)) && n.push({ path: `${t}.richParagraphs.${r}`, message: "段落缺少 segments 数组" });
107
+ (!A(o) || !Array.isArray(o.segments)) && n.push({ path: `${t}.richParagraphs.${r}`, message: "段落缺少 segments 数组" });
93
108
  }) : n.push({ path: `${t}.richParagraphs`, message: "richParagraphs 应为数组" }));
94
109
  }
95
- function D(e, t, n, o = []) {
96
- if (!N(e)) {
110
+ function C(e, t, n, o = []) {
111
+ if (!A(e)) {
97
112
  n.push({ path: t, message: "组件应为对象" });
98
113
  return;
99
114
  }
100
115
  const r = e.kind;
101
- typeof r != "string" ? n.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : X.has(r) || o.push({
116
+ typeof r != "string" ? n.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : ee.has(r) || o.push({
102
117
  path: `${t}.kind`,
103
118
  message: `未知组件类型 ${JSON.stringify(r)},将以兜底方式渲染`
104
119
  });
105
120
  for (const s of ["leftMm", "topMm", "widthMm", "heightMm"])
106
- Z(e, s, t, n);
121
+ te(e, s, t, n);
107
122
  typeof e.leftMm == "number" && e.leftMm < -100 && n.push({ path: `${t}.leftMm`, message: "几何数值异常(leftMm<-100)" });
108
123
  for (const s of ["widthMm", "heightMm"])
109
124
  typeof e[s] == "number" && e[s] < 0 && n.push({ path: `${t}.${s}`, message: "组件尺寸不能为负数" });
110
- Q(e.table, t, n), e.pageAnchor !== void 0 && !["header", "footer"].includes(e.pageAnchor) && n.push({ path: `${t}.pageAnchor`, message: "页面锚点应为 header 或 footer" }), e.lineDirection !== void 0 && !["down", "up"].includes(e.lineDirection) && n.push({ path: `${t}.lineDirection`, message: "线段方向应为 down 或 up" }), Y(e.grid, t, n, o), ee(e.richParagraphs, t, n);
125
+ ne(e.table, t, n), se(e.code, r, t, n), e.pageAnchor !== void 0 && !["header", "footer"].includes(e.pageAnchor) && n.push({ path: `${t}.pageAnchor`, message: "页面锚点应为 header 或 footer" }), e.lineDirection !== void 0 && !["down", "up"].includes(e.lineDirection) && n.push({ path: `${t}.lineDirection`, message: "线段方向应为 down 或 up" }), re(e.grid, t, n, o), oe(e.richParagraphs, t, n);
111
126
  }
112
- function te(e, t, n, o = []) {
113
- if (!N(e)) {
127
+ function se(e, t, n, o) {
128
+ if (e !== void 0)
129
+ for (const r of Y(e, t)) o.push({ path: `${n}.code${r.path ? `.${r.path}` : ""}`, message: r.message });
130
+ }
131
+ function F(e, t, n) {
132
+ if (!A(e)) return;
133
+ e.binding !== void 0 && n.push({ path: `${t}.binding`, message: "渲染计划不允许未解析字段绑定" });
134
+ const o = e.grid;
135
+ !A(o) || !Array.isArray(o.cells) || o.cells.forEach((r, s) => {
136
+ Array.isArray(r) && r.forEach((i, d) => {
137
+ !A(i) || !Array.isArray(i.children) || i.children.forEach((y, u) => F(y, `${t}.grid.cells.${s}.${d}.children.${u}`, n));
138
+ });
139
+ });
140
+ }
141
+ function ie(e, t, n, o = []) {
142
+ if (!A(e)) {
114
143
  n.push({ path: t, message: "页应为对象" });
115
144
  return;
116
145
  }
117
146
  const r = e.pageWidthMm, s = e.pageHeightMm;
118
147
  (typeof r != "number" || !Number.isFinite(r) || r <= 0) && n.push({ path: `${t}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(r)}` }), (typeof s != "number" || !(s > 0 && s < 5e3)) && n.push({ path: `${t}.pageHeightMm`, message: `页高非法: ${JSON.stringify(s)}` }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && n.push({ path: `${t}.layout`, message: "布局应为 page 或 wide" });
119
148
  const i = e.components;
120
- Array.isArray(i) ? Array.isArray(i) && i.forEach(
121
- (m, h) => D(m, `${t}.components.${h}`, n, o)
122
- ) : n.push({ path: `${t}.components`, message: "components 应为数组" });
149
+ Array.isArray(i) ? Array.isArray(i) && i.forEach((d, y) => {
150
+ C(d, `${t}.components.${y}`, n, o), F(d, `${t}.components.${y}`, n);
151
+ }) : n.push({ path: `${t}.components`, message: "components 应为数组" });
123
152
  }
124
- function ne(e) {
125
- const t = [], n = [], o = N(e) ? e.pages : void 0;
126
- if (N(e) && e.requiresRecalculation !== void 0 && typeof e.requiresRecalculation != "boolean" && t.push({ path: "$.requiresRecalculation", message: "重算能力要求应为布尔值" }), !Array.isArray(o))
153
+ function ae(e) {
154
+ const t = [], n = [], o = A(e) ? e.pages : void 0;
155
+ if (A(e) && e.requiresRecalculation !== void 0 && typeof e.requiresRecalculation != "boolean" && t.push({ path: "$.requiresRecalculation", message: "重算能力要求应为布尔值" }), !Array.isArray(o))
127
156
  t.push({
128
157
  path: "$.pages",
129
158
  message: e == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
130
159
  });
131
160
  else {
132
- o.forEach((s, i) => te(s, `$.pages.${i}`, t, n)), o.length > 2e3 && n.push({
161
+ o.forEach((s, i) => ie(s, `$.pages.${i}`, t, n)), o.length > 2e3 && n.push({
133
162
  path: "$.pages",
134
163
  message: `页数异常大(${o.length} 页),渲染与打印耗时可能显著增加`
135
164
  });
136
165
  const r = o.reduce(
137
- (s, i) => s + (N(i) && Array.isArray(i.components) ? i.components.length : 0),
166
+ (s, i) => s + (A(i) && Array.isArray(i.components) ? i.components.length : 0),
138
167
  0
139
168
  );
140
169
  r > 5e4 && n.push({
@@ -144,7 +173,7 @@ function ne(e) {
144
173
  }
145
174
  return { ok: t.length === 0, errors: t, warnings: n };
146
175
  }
147
- const E = "mach-report-worker/1";
176
+ const M = "mach-report-worker/1";
148
177
  class B extends Error {
149
178
  constructor(t) {
150
179
  super(t.message), this.name = t.name, this.code = t.code, this.path = t.path, this.issues = t.issues, this.diagnostics = t.diagnostics;
@@ -153,22 +182,22 @@ class B extends Error {
153
182
  function R(e) {
154
183
  return !!e && typeof e == "object" && !Array.isArray(e);
155
184
  }
156
- function re(e) {
185
+ function ce(e) {
157
186
  return R(e) ? ["rows", "pages", "cells"].every((t) => typeof e[t] == "number" && Number.isSafeInteger(e[t]) && e[t] >= 0) && typeof e.durationMs == "number" && Number.isFinite(e.durationMs) && e.durationMs >= 0 : !1;
158
187
  }
159
- function oe(e) {
188
+ function fe(e) {
160
189
  return Array.isArray(e) && e.every((t) => R(t) && typeof t.code == "string" && typeof t.message == "string" && ["info", "warning", "error"].includes(t.severity));
161
190
  }
162
- function se(e) {
191
+ function ue(e) {
163
192
  return R(e) && Object.values(e).every((t) => R(t) && (t.revision === void 0 || typeof t.revision == "string") && (t.sourceToken === void 0 || typeof t.sourceToken == "string"));
164
193
  }
165
- function ie(e, t) {
166
- if (!R(e) || !re(e.stats) || !oe(e.diagnostics) || !se(e.revisions)) return !1;
167
- if (t === "prepare") return ne(e.plan).ok;
194
+ function pe(e, t) {
195
+ if (!R(e) || !ce(e.stats) || !fe(e.diagnostics) || !ue(e.revisions)) return !1;
196
+ if (t === "prepare") return ae(e.plan).ok;
168
197
  const n = e.format === "pdf" ? "application/pdf" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
169
198
  return e.bytes instanceof Uint8Array && (e.format === "pdf" || e.format === "xlsx") && e.contentType === n;
170
199
  }
171
- function U(e) {
200
+ function D(e) {
172
201
  if (!e || typeof e != "object") return { message: String(e) };
173
202
  const t = {};
174
203
  for (const n of ["code", "path", "field", "message"]) {
@@ -177,14 +206,14 @@ function U(e) {
177
206
  }
178
207
  return t;
179
208
  }
180
- function ae(e) {
181
- const t = U(e);
209
+ function de(e) {
210
+ const t = D(e);
182
211
  if (!R(e)) return t;
183
212
  for (const n of ["format", "severity", "kind", "nid"]) typeof e[n] == "string" && (t[n] = e[n]);
184
213
  for (const n of ["pageIndex", "componentIndex"]) Number.isSafeInteger(e[n]) && e[n] >= 0 && (t[n] = e[n]);
185
214
  return Array.isArray(e.componentPath) && e.componentPath.every((n) => Number.isSafeInteger(n) && n >= 0) && (t.componentPath = e.componentPath), t;
186
215
  }
187
- function ce(e) {
216
+ function me(e) {
188
217
  if (!(e instanceof Error)) return { name: "Error", message: String(e) };
189
218
  const t = e;
190
219
  return {
@@ -192,89 +221,89 @@ function ce(e) {
192
221
  message: e.message,
193
222
  ...typeof t.code == "string" ? { code: t.code } : {},
194
223
  ...typeof t.path == "string" ? { path: t.path } : {},
195
- ...Array.isArray(t.issues) ? { issues: t.issues.map(U) } : {},
196
- ...Array.isArray(t.diagnostics) ? { diagnostics: t.diagnostics.map(ae) } : {}
224
+ ...Array.isArray(t.issues) ? { issues: t.issues.map(D) } : {},
225
+ ...Array.isArray(t.diagnostics) ? { diagnostics: t.diagnostics.map(de) } : {}
197
226
  };
198
227
  }
199
- function fe(e) {
228
+ function ye(e) {
200
229
  if (!e || typeof e != "object") return !1;
201
230
  const t = e;
202
- return t.protocol === E && typeof t.id == "string" && (t.operation === "prepare" || t.operation === "export") && !!t.input && typeof t.input == "object";
231
+ return t.protocol === M && typeof t.id == "string" && (t.operation === "prepare" || t.operation === "export") && !!t.input && typeof t.input == "object";
203
232
  }
204
- async function ue(e, t, n) {
233
+ async function le(e, t, n) {
205
234
  try {
206
235
  const o = t.operation === "prepare" ? await e.prepare({ ...t.input, onEvent: n }) : await e.export({ ...t.input, onEvent: n });
207
- return { protocol: E, id: t.id, result: o };
236
+ return { protocol: M, id: t.id, result: o };
208
237
  } catch (o) {
209
- return { protocol: E, id: t.id, error: ce(o) };
238
+ return { protocol: M, id: t.id, error: me(o) };
210
239
  }
211
240
  }
212
- function pe(e) {
241
+ function he(e) {
213
242
  const t = e.result;
214
243
  return !t || !("bytes" in t) || !(t.bytes.buffer instanceof ArrayBuffer) ? [] : [t.bytes.buffer];
215
244
  }
216
- function de(e, t) {
217
- if (!R(e) || typeof e.taskId != "string" || !e.taskId || t.taskId !== void 0 && e.taskId !== t.taskId || e.correlationId !== t.correlationId || e.reportId !== void 0 && (typeof e.reportId != "string" || !t.reportIds.includes(e.reportId)) || !["query", "validate", "layout", "encode"].includes(e.stage) || !["started", "completed", "failed"].includes(e.status)) return !1;
245
+ function ge(e, t) {
246
+ if (!R(e) || typeof e.taskId != "string" || !e.taskId || t.taskId !== void 0 && e.taskId !== t.taskId || e.correlationId !== t.correlationId || e.reportId !== void 0 && (typeof e.reportId != "string" || !t.reportIds.includes(e.reportId)) || !["query", "validate", "layout", "assets", "encode"].includes(e.stage) || !["started", "completed", "failed"].includes(e.status)) return !1;
218
247
  for (const n of ["completed", "total"]) if (e[n] !== void 0 && (typeof e[n] != "number" || !Number.isFinite(e[n]) || e[n] < 0)) return !1;
219
248
  return e.completed === void 0 || e.total === void 0 || e.completed <= e.total;
220
249
  }
221
- let me = 0;
222
- function P(e) {
250
+ let we = 0;
251
+ function J(e) {
223
252
  const t = new Error("报表 Worker 任务已取消");
224
253
  return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e }), t;
225
254
  }
226
- function ye(e, t) {
255
+ function be(e, t) {
227
256
  if (!e || typeof e != "object") return;
228
257
  const n = e;
229
- return n.protocol === E && n.id === t ? n : void 0;
258
+ return n.protocol === M && n.id === t ? n : void 0;
230
259
  }
231
- function le(e, t = {}) {
260
+ function Ae(e, t = {}) {
232
261
  const n = t.timeoutMs ?? 12e4;
233
262
  if (!Number.isFinite(n) || n <= 0 || n > 2147483647) throw new RangeError("Worker timeoutMs 应为正有限数字,且不能超过 2147483647");
234
- const o = (r, s, i, m) => i?.aborted ? Promise.reject(P(i.reason)) : new Promise((h, u) => {
263
+ const o = (r, s, i, d) => i?.aborted ? Promise.reject(J(i.reason)) : new Promise((y, u) => {
235
264
  let b;
236
265
  try {
237
266
  b = e();
238
- } catch (y) {
239
- u(y);
267
+ } catch (l) {
268
+ u(l);
240
269
  return;
241
270
  }
242
- const k = `mach-report-${Date.now()}-${++me}`;
271
+ const k = `mach-report-${Date.now()}-${++we}`;
243
272
  let p = !1, f = () => {
244
273
  }, c;
245
- const d = (y, w) => {
274
+ const m = (l, w) => {
246
275
  p || (p = !0, c && clearTimeout(c), f(), i?.removeEventListener("abort", g), Promise.resolve().then(() => b.terminate()).then(
247
- () => y === void 0 ? h(w) : u(y),
248
- ($) => u(y ?? $)
276
+ () => l === void 0 ? y(w) : u(l),
277
+ (N) => u(l ?? N)
249
278
  ));
250
- }, g = () => d(P(i?.reason)), A = (y) => {
251
- const w = ye(y, k);
279
+ }, g = () => m(J(i?.reason)), x = (l) => {
280
+ const w = be(l, k);
252
281
  if (!(!w || p)) {
253
282
  if ("type" in w && w.type === "event") {
254
- const $ = "event" in w ? w.event : void 0;
255
- de($, s) ? K(m, $, i) : d(new Error("报表 Worker 返回无效阶段事件"));
283
+ const N = "event" in w ? w.event : void 0;
284
+ ge(N, s) ? Z(d, N, i) : m(new Error("报表 Worker 返回无效阶段事件"));
256
285
  return;
257
286
  }
258
- w.error && typeof w.error.name == "string" && typeof w.error.message == "string" ? d(new B(w.error)) : ie(w.result, r) && (r !== "export" || "format" in w.result && "format" in s && w.result.format === s.format) ? d(void 0, w.result) : d(new Error("报表 Worker 返回无效响应"));
287
+ w.error && typeof w.error.name == "string" && typeof w.error.message == "string" ? m(new B(w.error)) : pe(w.result, r) && (r !== "export" || "format" in w.result && "format" in s && w.result.format === s.format) ? m(void 0, w.result) : m(new Error("报表 Worker 返回无效响应"));
259
288
  }
260
289
  };
261
290
  try {
262
- if (f = b.subscribe(A, (y) => d(y ?? new Error("报表 Worker 执行失败"))), p) {
291
+ if (f = b.subscribe(x, (l) => m(l ?? new Error("报表 Worker 执行失败"))), p) {
263
292
  f();
264
293
  return;
265
294
  }
266
- if (i?.addEventListener("abort", g, { once: !0 }), c = setTimeout(() => d(new B({ name: "ReportRuntimeError", code: "timeout", message: `报表 Worker 执行超过 ${n}ms` })), n), i?.aborted) g();
295
+ if (i?.addEventListener("abort", g, { once: !0 }), c = setTimeout(() => m(new B({ name: "ReportRuntimeError", code: "timeout", message: `报表 Worker 执行超过 ${n}ms` })), n), i?.aborted) g();
267
296
  else {
268
- const { onEvent: y, signal: w, ...$ } = s;
269
- b.postMessage({ protocol: E, id: k, operation: r, input: $ });
297
+ const { onEvent: l, signal: w, ...N } = s;
298
+ b.postMessage({ protocol: M, id: k, operation: r, input: N });
270
299
  }
271
- } catch (y) {
272
- d(y);
300
+ } catch (l) {
301
+ m(l);
273
302
  }
274
303
  });
275
304
  return { prepare: (r, s, i) => o("prepare", r, s, i), export: (r, s, i) => o("export", r, s, i) };
276
305
  }
277
- const he = new Uint32Array([
306
+ const xe = new Uint32Array([
278
307
  1116352408,
279
308
  1899447441,
280
309
  3049323471,
@@ -339,35 +368,35 @@ const he = new Uint32Array([
339
368
  2756734187,
340
369
  3204031479,
341
370
  3329325298
342
- ]), x = (e, t) => e >>> t | e << 32 - t;
343
- function ge(e, t, n) {
371
+ ]), $ = (e, t) => e >>> t | e << 32 - t;
372
+ function $e(e, t, n) {
344
373
  const o = new DataView(e.buffer, e.byteOffset + t, 64);
345
374
  for (let r = 0; r < 16; r++) n[r] = o.getUint32(r * 4);
346
375
  for (let r = 16; r < 64; r++) {
347
- const s = n[r - 15], i = n[r - 2], m = x(s, 7) ^ x(s, 18) ^ s >>> 3, h = x(i, 17) ^ x(i, 19) ^ i >>> 10;
348
- n[r] = n[r - 16] + m + n[r - 7] + h;
376
+ const s = n[r - 15], i = n[r - 2], d = $(s, 7) ^ $(s, 18) ^ s >>> 3, y = $(i, 17) ^ $(i, 19) ^ i >>> 10;
377
+ n[r] = n[r - 16] + d + n[r - 7] + y;
349
378
  }
350
379
  }
351
- function we(e, t) {
352
- let n = e[0], o = e[1], r = e[2], s = e[3], i = e[4], m = e[5], h = e[6], u = e[7];
380
+ function ke(e, t) {
381
+ let n = e[0], o = e[1], r = e[2], s = e[3], i = e[4], d = e[5], y = e[6], u = e[7];
353
382
  for (let b = 0; b < 64; b++) {
354
- const k = x(i, 6) ^ x(i, 11) ^ x(i, 25), p = i & m ^ ~i & h, f = u + k + p + he[b] + t[b] >>> 0, c = x(n, 2) ^ x(n, 13) ^ x(n, 22), d = n & o ^ n & r ^ o & r, g = c + d >>> 0;
355
- u = h, h = m, m = i, i = s + f >>> 0, s = r, r = o, o = n, n = f + g >>> 0;
383
+ const k = $(i, 6) ^ $(i, 11) ^ $(i, 25), p = i & d ^ ~i & y, f = u + k + p + xe[b] + t[b] >>> 0, c = $(n, 2) ^ $(n, 13) ^ $(n, 22), m = n & o ^ n & r ^ o & r, g = c + m >>> 0;
384
+ u = y, y = d, d = i, i = s + f >>> 0, s = r, r = o, o = n, n = f + g >>> 0;
356
385
  }
357
- e[0] = e[0] + n, e[1] = e[1] + o, e[2] = e[2] + r, e[3] = e[3] + s, e[4] = e[4] + i, e[5] = e[5] + m, e[6] = e[6] + h, e[7] = e[7] + u;
386
+ e[0] = e[0] + n, e[1] = e[1] + o, e[2] = e[2] + r, e[3] = e[3] + s, e[4] = e[4] + i, e[5] = e[5] + d, e[6] = e[6] + y, e[7] = e[7] + u;
358
387
  }
359
- function be(e) {
388
+ function Ne(e) {
360
389
  const t = new Uint8Array(Math.ceil((e.byteLength + 9) / 64) * 64);
361
390
  t.set(e), t[e.byteLength] = 128;
362
391
  const n = new DataView(t.buffer);
363
392
  return n.setUint32(t.length - 8, Math.floor(e.byteLength / 536870912)), n.setUint32(t.length - 4, e.byteLength * 8 >>> 0), t;
364
393
  }
365
- const Ae = () => new Uint32Array([1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]), xe = (e) => Array.from(e, (t) => t.toString(16).padStart(8, "0")).join("");
366
- async function ke(e) {
367
- const t = be(e), n = Ae(), o = new Uint32Array(64);
394
+ const ve = () => new Uint32Array([1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]), Se = (e) => Array.from(e, (t) => t.toString(16).padStart(8, "0")).join("");
395
+ async function Re(e) {
396
+ const t = Ne(e), n = ve(), o = new Uint32Array(64);
368
397
  for (let r = 0; r < t.length; r += 64)
369
- r > 0 && r % 262144 === 0 && await new Promise((s) => setTimeout(s, 0)), ge(t, r, o), we(n, o);
370
- return xe(n);
398
+ r > 0 && r % 262144 === 0 && await new Promise((s) => setTimeout(s, 0)), $e(t, r, o), ke(n, o);
399
+ return Se(n);
371
400
  }
372
401
  class a extends Error {
373
402
  constructor(t, n) {
@@ -377,7 +406,7 @@ class a extends Error {
377
406
  function T(e, t) {
378
407
  if (typeof e != "string" || !e.trim() || e.length > 256 || typeof t != "string" || t !== t.trim() || !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{0,127}$/.test(t)) throw new a("input", "任务范围应非空,ID应为1–128位安全标识");
379
408
  }
380
- function $e(e) {
409
+ function Me(e) {
381
410
  const t = Array.isArray(e), n = Object.getPrototypeOf(e), o = Object.keys(e);
382
411
  if (n !== (t ? Array.prototype : Object.prototype) && !(n === null && !t)) throw new a("input", "任务对象应为普通 JSON 对象");
383
412
  if (Object.getOwnPropertySymbols(e).length) throw new a("input", "任务不能包含Symbol");
@@ -385,17 +414,17 @@ function $e(e) {
385
414
  if (t && (o.length !== e.length || o.some((s) => s !== String(Number(s)) || !Number.isSafeInteger(Number(s)) || Number(s) < 0 || Number(s) >= e.length))) throw new a("input", "任务数组不能稀疏或包含额外属性");
386
415
  return o.sort();
387
416
  }
388
- function Ne(e, t) {
417
+ function Ee(e, t) {
389
418
  const n = Object.getOwnPropertyDescriptor(e, t);
390
419
  if (["__proto__", "prototype", "constructor"].includes(t) || n.get || n.set) throw new a("input", "任务不能包含危险键或访问器");
391
420
  return n.value;
392
421
  }
393
- function S(e, t = {}) {
422
+ function v(e, t = {}) {
394
423
  const n = t.maxNodes ?? 2e4, o = t.maxCharacters ?? 1e6;
395
424
  if (!Number.isSafeInteger(n) || n < 1 || n > 2e4 || !Number.isSafeInteger(o) || o < 1 || o > 1e6) throw new a("input", "任务JSON预算无效");
396
425
  let r = 0, s = 0;
397
426
  const i = /* @__PURE__ */ new Set();
398
- function m(u, b) {
427
+ function d(u, b) {
399
428
  if (++r > n || b > 32) throw new a("input", "任务数据超过节点或深度预算");
400
429
  if (typeof u == "string") {
401
430
  if (s += u.length, s > o) throw new a("input", "任务文本超过预算");
@@ -403,36 +432,36 @@ function S(e, t = {}) {
403
432
  }
404
433
  if (u === null || typeof u == "boolean" || typeof u == "number" && Number.isFinite(u)) return u;
405
434
  if (!u || typeof u != "object" || i.has(u)) throw new a("input", "任务只允许无循环的有限 JSON 值");
406
- const k = Array.isArray(u), p = $e(u);
435
+ const k = Array.isArray(u), p = Me(u);
407
436
  i.add(u);
408
437
  const f = /* @__PURE__ */ Object.create(null);
409
438
  for (const c of p) {
410
439
  if (s += c.length, s > o) throw new a("input", "任务文本超过预算");
411
- f[c] = m(Ne(u, c), b + 1);
440
+ f[c] = d(Ee(u, c), b + 1);
412
441
  }
413
- return i.delete(u), k ? Array.from({ length: u.length }, (c, d) => f[String(d)]) : f;
442
+ return i.delete(u), k ? Array.from({ length: u.length }, (c, m) => f[String(m)]) : f;
414
443
  }
415
- const h = JSON.stringify(m(e, 0));
416
- if (h.length > o) throw new a("input", "任务序列化数据超过字符预算");
417
- return h;
444
+ const y = JSON.stringify(d(e, 0));
445
+ if (y.length > o) throw new a("input", "任务序列化数据超过字符预算");
446
+ return y;
418
447
  }
419
448
  function j(e) {
420
449
  return JSON.parse(JSON.stringify(e));
421
450
  }
422
- function z(e, t, n, o) {
451
+ function L(e, t, n, o) {
423
452
  if (T(t, n), e.scope !== t || e.id !== n || e.revision !== (o ?? 0) + 1 || !Number.isSafeInteger(e.revision)) throw new a("input", "任务身份或修订不匹配");
424
453
  if (![e.createdAt, e.updatedAt, e.attempt].every((r) => Number.isSafeInteger(r) && r >= 0) || !["queued", "running", "completed", "failed", "cancelled"].includes(e.status)) throw new a("input", "任务状态无效");
425
454
  if (e.lease && (!e.lease.owner || !Number.isSafeInteger(e.lease.expiresAt))) throw new a("input", "任务租约无效");
426
455
  if (!e.request || typeof e.request.kind != "string" || !e.request.kind.trim() || e.request.kind.length > 128) throw new a("input", "任务类型无效");
427
- S(e.request.payload, { maxNodes: 19e3, maxCharacters: 75e4 }), S(e);
456
+ v(e.request.payload, { maxNodes: 19e3, maxCharacters: 75e4 }), v(e);
428
457
  }
429
- function Se(e, t) {
430
- if (e && (e.createdAt !== t.createdAt || S(e.request) !== S(t.request))) throw new a("input", "任务创建时间与请求不可变更,请使用新任务ID");
458
+ function Oe(e, t) {
459
+ if (e && (e.createdAt !== t.createdAt || v(e.request) !== v(t.request))) throw new a("input", "任务创建时间与请求不可变更,请使用新任务ID");
431
460
  }
432
- function ve(e, t) {
461
+ function Ie(e, t) {
433
462
  return e.status === "queued" || e.status === "running" && (e.lease?.expiresAt ?? 0) <= t;
434
463
  }
435
- function Re(e = {}) {
464
+ function Te(e = {}) {
436
465
  const t = {
437
466
  maxRecords: e.maxRecords ?? 1e4,
438
467
  maxBytes: e.maxBytes ?? 67108864,
@@ -444,36 +473,36 @@ function Re(e = {}) {
444
473
  if (!Object.values(t).every((n) => Number.isSafeInteger(n) && n > 0) || t.controlReserveBytes < 4096) throw new a("input", "任务容量应为正整数,控制状态预留至少4096字节");
445
474
  return t;
446
475
  }
447
- function M(e) {
448
- return new TextEncoder().encode(S(e)).byteLength;
476
+ function E(e) {
477
+ return new TextEncoder().encode(v(e)).byteLength;
449
478
  }
450
- function L(e, t) {
479
+ function z(e, t) {
451
480
  const n = { scope: e.scope, id: e.id, revision: 1, request: e.request, status: "queued", createdAt: e.createdAt, updatedAt: e.createdAt, attempt: 0 }, o = { ...e };
452
481
  delete o.result;
453
- const r = e.result === void 0 ? 0 : M(e.result);
482
+ const r = e.result === void 0 ? 0 : E(e.result);
454
483
  if (r > t.maxResultBytes) throw new a("capacity", "任务结果超过独立预算,请保存文件引用");
455
- return Math.max(M(n) + t.controlReserveBytes, M(o)) + r;
484
+ return Math.max(E(n) + t.controlReserveBytes, E(o)) + r;
456
485
  }
457
486
  function _(e) {
458
487
  return e.status !== "queued" && e.status !== "running";
459
488
  }
460
- function Ee(e) {
489
+ function je(e) {
461
490
  const t = { ...e, tombstoneRetentionMs: e.tombstoneRetentionMs ?? 6048e5, limit: e.limit ?? 100 };
462
491
  if (![t.now, t.terminalBefore].every((n) => Number.isSafeInteger(n) && n >= 0) || t.terminalBefore > t.now) throw new a("input", "终态清理时间应为不超过当前时间的非负整数");
463
492
  if (![t.tombstoneRetentionMs, t.limit].every((n) => Number.isSafeInteger(n) && n > 0) || !Number.isSafeInteger(t.now + t.tombstoneRetentionMs)) throw new a("input", "幂等保留期与清理批量应为正整数");
464
493
  return t;
465
494
  }
466
- async function Me(e) {
467
- const t = new TextEncoder().encode(S(e)), n = globalThis.crypto?.subtle;
468
- if (!n) return ke(t);
495
+ async function qe(e) {
496
+ const t = new TextEncoder().encode(v(e)), n = globalThis.crypto?.subtle;
497
+ if (!n) return Re(t);
469
498
  const o = await n.digest("SHA-256", t);
470
499
  return Array.from(new Uint8Array(o), (r) => r.toString(16).padStart(2, "0")).join("");
471
500
  }
472
- async function Oe(e, t) {
501
+ async function Be(e, t) {
473
502
  if (!_(e)) throw new a("input", "只能归档终态任务");
474
- return { scope: e.scope, id: e.id, revision: e.revision, status: e.status, createdAt: e.createdAt, updatedAt: e.updatedAt, attempt: e.attempt, requestHash: await Me(e.request), expiresAt: t };
503
+ return { scope: e.scope, id: e.id, revision: e.revision, status: e.status, createdAt: e.createdAt, updatedAt: e.updatedAt, attempt: e.attempt, requestHash: await qe(e.request), expiresAt: t };
475
504
  }
476
- function Ie(e) {
505
+ function Je(e) {
477
506
  if (!e || !["completed", "failed", "cancelled"].includes(e.status) || !/^[a-f0-9]{64}$/.test(e.requestHash)) throw new a("input", "任务幂等摘要无效");
478
507
  if (![e.revision, e.createdAt, e.updatedAt, e.attempt, e.expiresAt].every((t) => Number.isSafeInteger(t) && t >= 0) || e.revision < 1) throw new a("input", "任务幂等摘要时间或修订无效");
479
508
  }
@@ -483,16 +512,16 @@ function I(e) {
483
512
  function O(e, t) {
484
513
  return W("sha256").update(JSON.stringify([e, t])).digest("hex") + ".json";
485
514
  }
486
- async function J(e) {
515
+ async function q(e) {
487
516
  try {
488
- return await l.readFile(e, "utf8");
517
+ return await h.readFile(e, "utf8");
489
518
  } catch (t) {
490
519
  if (I(t) === "ENOENT") return;
491
520
  throw t;
492
521
  }
493
522
  }
494
- async function Te(e, t) {
495
- const n = await J(e);
523
+ async function Pe(e, t) {
524
+ const n = await q(e);
496
525
  if (n === void 0) return;
497
526
  let o;
498
527
  try {
@@ -505,110 +534,110 @@ async function Te(e, t) {
505
534
  process.kill(o.pid, 0);
506
535
  } catch (r) {
507
536
  if (I(r) === "ESRCH") {
508
- await l.unlink(e);
537
+ await h.unlink(e);
509
538
  return;
510
539
  }
511
540
  throw r;
512
541
  }
513
542
  throw new a("conflict", "任务目录的写入进程仍在运行");
514
543
  }
515
- async function je(e, t) {
544
+ async function We(e, t) {
516
545
  if (!t) throw new a("conflict", "任务目录已有写入进程;多实例请使用数据库CAS适配器");
517
546
  const n = e + ".recovery";
518
547
  let o;
519
548
  try {
520
- o = await l.open(n, "wx", 384);
549
+ o = await h.open(n, "wx", 384);
521
550
  } catch (r) {
522
551
  throw I(r) === "EEXIST" ? new a("conflict", "任务目录恢复正在进行,请稍后重试") : r;
523
552
  }
524
553
  try {
525
- return await o.writeFile(JSON.stringify({ pid: process.pid })), await Te(e, !0), await l.open(e, "wx", 384);
554
+ return await o.writeFile(JSON.stringify({ pid: process.pid })), await Pe(e, !0), await h.open(e, "wx", 384);
526
555
  } finally {
527
- await o.close(), await l.unlink(n);
556
+ await o.close(), await h.unlink(n);
528
557
  }
529
558
  }
530
- async function Je(e, t) {
531
- const n = v.join(e, ".writer-lock"), o = q();
559
+ async function Ue(e, t) {
560
+ const n = S.join(e, ".writer-lock"), o = P();
532
561
  let r;
533
562
  try {
534
- r = await l.open(n, "wx", 384);
563
+ r = await h.open(n, "wx", 384);
535
564
  } catch (s) {
536
565
  if (I(s) !== "EEXIST") throw s;
537
- r = await je(n, t);
566
+ r = await We(n, t);
538
567
  }
539
568
  try {
540
569
  await r.writeFile(JSON.stringify({ pid: process.pid, token: o })), await r.sync();
541
570
  } catch (s) {
542
- throw await r.close(), await l.unlink(n).catch(() => {
571
+ throw await r.close(), await h.unlink(n).catch(() => {
543
572
  }), s;
544
573
  }
545
574
  return { file: n, token: o, handle: r };
546
575
  }
547
- function Be(e, t, n, o) {
576
+ function Ce(e, t, n, o) {
548
577
  if ("tombstone" in n) {
549
578
  const r = n.tombstone;
550
- if (Ie(r), T(r.scope, r.id), O(r.scope, r.id) !== t) throw new a("input", "持久任务摘要身份不匹配");
551
- const s = M(r);
579
+ if (Je(r), T(r.scope, r.id), O(r.scope, r.id) !== t) throw new a("input", "持久任务摘要身份不匹配");
580
+ const s = E(r);
552
581
  e.tombstoneBytes += s, e.tombstones.set(t, { value: r, bytes: s });
553
582
  } else {
554
- if (z(n, n.scope, n.id, n.revision - 1), O(n.scope, n.id) !== t) throw new a("input", "持久任务文件身份不匹配");
555
- const r = L(n, o);
583
+ if (L(n, n.scope, n.id, n.revision - 1), O(n.scope, n.id) !== t) throw new a("input", "持久任务文件身份不匹配");
584
+ const r = z(n, o);
556
585
  e.bytes += r, e.records.set(t, { record: n, bytes: r });
557
586
  }
558
587
  if (e.bytes > o.maxBytes || e.records.size > o.maxRecords || e.tombstoneBytes > o.maxTombstoneBytes || e.tombstones.size > o.maxTombstones) throw new a("capacity", "持久任务及控制状态预留超过目录预算");
559
588
  }
560
- async function Pe(e, t) {
561
- const n = await l.readdir(e);
562
- for (const s of n.filter((i) => /^\.pending-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(i))) await l.unlink(v.join(e, s));
589
+ async function Fe(e, t) {
590
+ const n = await h.readdir(e);
591
+ for (const s of n.filter((i) => /^\.pending-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(i))) await h.unlink(S.join(e, s));
563
592
  const o = n.filter((s) => /^[a-f0-9]{64}\.json$/.test(s));
564
593
  if (o.length > t.maxRecords + t.maxTombstones) throw new a("capacity", "持久任务数量超过目录预算");
565
594
  const r = { records: /* @__PURE__ */ new Map(), tombstones: /* @__PURE__ */ new Map(), bytes: 0, tombstoneBytes: 0 };
566
595
  for (const s of o) {
567
- const i = v.join(e, s);
568
- if ((await l.stat(i)).size > 4e6) throw new a("capacity", "持久任务文件超过单文件预算");
569
- Be(r, s, JSON.parse(await l.readFile(i, "utf8")), t);
596
+ const i = S.join(e, s);
597
+ if ((await h.stat(i)).size > 4e6) throw new a("capacity", "持久任务文件超过单文件预算");
598
+ Ce(r, s, JSON.parse(await h.readFile(i, "utf8")), t);
570
599
  }
571
600
  return r;
572
601
  }
573
- async function qe(e, t, n) {
574
- const o = v.join(e, `.pending-${q()}`);
602
+ async function De(e, t, n) {
603
+ const o = S.join(e, `.pending-${P()}`);
575
604
  try {
576
- const r = await l.open(o, "wx", 384);
605
+ const r = await h.open(o, "wx", 384);
577
606
  try {
578
607
  await r.writeFile(n), await r.sync();
579
608
  } finally {
580
609
  await r.close();
581
610
  }
582
- await l.rename(o, v.join(e, t));
583
- const s = await l.open(e, "r");
611
+ await h.rename(o, S.join(e, t));
612
+ const s = await h.open(e, "r");
584
613
  try {
585
614
  await s.sync();
586
615
  } finally {
587
616
  await s.close();
588
617
  }
589
618
  } finally {
590
- await l.unlink(o).catch((r) => {
619
+ await h.unlink(o).catch((r) => {
591
620
  if (I(r) !== "ENOENT") throw r;
592
621
  });
593
622
  }
594
623
  }
595
- async function ze(e) {
596
- const t = v.resolve(e.directory), n = Re(e);
597
- await l.mkdir(t, { recursive: !0, mode: 448 });
598
- const o = await Je(t, e.recoverDeadOwner ?? !1);
624
+ async function Ke(e) {
625
+ const t = S.resolve(e.directory), n = Te(e);
626
+ await h.mkdir(t, { recursive: !0, mode: 448 });
627
+ const o = await Ue(t, e.recoverDeadOwner ?? !1);
599
628
  let r;
600
629
  try {
601
- r = await Pe(t, n);
630
+ r = await Fe(t, n);
602
631
  } catch (p) {
603
- throw await o.handle.close(), await l.unlink(o.file), p;
632
+ throw await o.handle.close(), await h.unlink(o.file), p;
604
633
  }
605
634
  let s = !1, i = Promise.resolve();
606
- const m = () => {
635
+ const d = () => {
607
636
  if (s) throw new a("closed", "持久任务存储已关闭");
608
- }, h = (p) => {
609
- m();
637
+ }, y = (p) => {
638
+ d();
610
639
  const f = i.then(async () => {
611
- if (JSON.parse(await l.readFile(o.file, "utf8")).token !== o.token) throw new a("closed", "持久任务存储写入锁已失效");
640
+ if (JSON.parse(await h.readFile(o.file, "utf8")).token !== o.token) throw new a("closed", "持久任务存储写入锁已失效");
612
641
  return p();
613
642
  });
614
643
  return i = f.then(() => {
@@ -616,57 +645,57 @@ async function ze(e) {
616
645
  }), f;
617
646
  }, u = async (p, f, c) => {
618
647
  try {
619
- await qe(t, p, f);
620
- } catch (d) {
621
- throw await J(v.join(t, p)) === f && c(), d;
648
+ await De(t, p, f);
649
+ } catch (m) {
650
+ throw await q(S.join(t, p)) === f && c(), m;
622
651
  }
623
652
  c();
624
653
  };
625
654
  return {
626
655
  read: async (p, f) => {
627
- m(), T(p, f), await i;
656
+ d(), T(p, f), await i;
628
657
  const c = r.records.get(O(p, f));
629
658
  return c ? j(c.record) : void 0;
630
659
  },
631
660
  readTombstone: async (p, f) => {
632
- m(), T(p, f), await i;
661
+ d(), T(p, f), await i;
633
662
  const c = r.tombstones.get(O(p, f));
634
663
  return c ? j(c.value) : void 0;
635
664
  },
636
- candidates: async (p, f) => (m(), await i, Array.from(r.records.values(), (c) => c.record).filter((c) => ve(c, p)).sort((c, d) => c.createdAt - d.createdAt).slice(0, f).map(j)),
637
- compareAndSwap: async (p, f, c, d) => {
638
- const g = JSON.parse(S(d));
639
- return z(g, p, f, c), h(async () => {
640
- const A = O(p, f), y = r.records.get(A);
641
- if ((y?.record.revision ?? null) !== c || r.tombstones.has(A)) return !1;
642
- Se(y?.record, g);
643
- const w = L(g, n), $ = r.bytes - (y?.bytes ?? 0) + w;
644
- if ($ > n.maxBytes || !y && r.records.size >= n.maxRecords) throw new a("capacity", "持久任务容量已满,请清理终态任务或扩大显式预算");
645
- return await u(A, S(g), () => {
646
- r.records.set(A, { record: g, bytes: w }), r.bytes = $;
665
+ candidates: async (p, f) => (d(), await i, Array.from(r.records.values(), (c) => c.record).filter((c) => Ie(c, p)).sort((c, m) => c.createdAt - m.createdAt).slice(0, f).map(j)),
666
+ compareAndSwap: async (p, f, c, m) => {
667
+ const g = JSON.parse(v(m));
668
+ return L(g, p, f, c), y(async () => {
669
+ const x = O(p, f), l = r.records.get(x);
670
+ if ((l?.record.revision ?? null) !== c || r.tombstones.has(x)) return !1;
671
+ Oe(l?.record, g);
672
+ const w = z(g, n), N = r.bytes - (l?.bytes ?? 0) + w;
673
+ if (N > n.maxBytes || !l && r.records.size >= n.maxRecords) throw new a("capacity", "持久任务容量已满,请清理终态任务或扩大显式预算");
674
+ return await u(x, v(g), () => {
675
+ r.records.set(x, { record: g, bytes: w }), r.bytes = N;
647
676
  }), !0;
648
677
  });
649
678
  },
650
679
  prune: async (p) => {
651
- const f = Ee(p);
652
- return h(async () => {
680
+ const f = je(p);
681
+ return y(async () => {
653
682
  const c = { archived: 0, expired: 0 };
654
- for (const [d, g] of r.tombstones)
655
- g.value.expiresAt > f.now || c.expired >= f.limit || (await l.unlink(v.join(t, d)), r.tombstones.delete(d), r.tombstoneBytes -= g.bytes, c.expired++);
656
- for (const [d, g] of r.records) {
683
+ for (const [m, g] of r.tombstones)
684
+ g.value.expiresAt > f.now || c.expired >= f.limit || (await h.unlink(S.join(t, m)), r.tombstones.delete(m), r.tombstoneBytes -= g.bytes, c.expired++);
685
+ for (const [m, g] of r.records) {
657
686
  if (!_(g.record) || g.record.updatedAt > f.terminalBefore || c.archived + c.expired >= f.limit) continue;
658
- const A = await Oe(g.record, f.now + f.tombstoneRetentionMs), y = M(A);
659
- if (r.tombstones.size >= n.maxTombstones || r.tombstoneBytes + y > n.maxTombstoneBytes) break;
660
- await u(d, S({ tombstone: A }), () => {
661
- r.tombstones.set(d, { value: A, bytes: y }), r.tombstoneBytes += y, r.records.delete(d), r.bytes -= g.bytes;
687
+ const x = await Be(g.record, f.now + f.tombstoneRetentionMs), l = E(x);
688
+ if (r.tombstones.size >= n.maxTombstones || r.tombstoneBytes + l > n.maxTombstoneBytes) break;
689
+ await u(m, v({ tombstone: x }), () => {
690
+ r.tombstones.set(m, { value: x, bytes: l }), r.tombstoneBytes += l, r.records.delete(m), r.bytes -= g.bytes;
662
691
  }), c.archived++;
663
692
  }
664
693
  if (c.expired) {
665
- const d = await l.open(t, "r");
694
+ const m = await h.open(t, "r");
666
695
  try {
667
- await d.sync();
696
+ await m.sync();
668
697
  } finally {
669
- await d.close();
698
+ await m.close();
670
699
  }
671
700
  }
672
701
  return c;
@@ -675,16 +704,16 @@ async function ze(e) {
675
704
  close: async () => {
676
705
  if (s) return;
677
706
  s = !0, await i, await o.handle.close();
678
- const p = await J(o.file);
679
- p && JSON.parse(p).token === o.token && await l.unlink(o.file);
707
+ const p = await q(o.file);
708
+ p && JSON.parse(p).token === o.token && await h.unlink(o.file);
680
709
  }
681
710
  };
682
711
  }
683
- function Le(e) {
712
+ function Ze(e) {
684
713
  const t = e.filename ?? e.workerUrl;
685
714
  if (!t || e.filename && e.workerUrl) throw new TypeError("请且仅请指定 filename 或 workerUrl");
686
- return le(() => {
687
- const n = new H(t, e.workerOptions);
715
+ return Ae(() => {
716
+ const n = new K(t, e.workerOptions);
688
717
  return {
689
718
  postMessage: (o) => n.postMessage(o),
690
719
  terminate: () => n.terminate(),
@@ -697,21 +726,21 @@ function Le(e) {
697
726
  };
698
727
  }, e);
699
728
  }
700
- function _e(e) {
701
- const t = C;
729
+ function Qe(e) {
730
+ const t = H;
702
731
  if (!t) throw new Error("serveNodeReportWorker 只能在 worker_threads 中调用");
703
732
  const n = (o) => {
704
- fe(o) && ue(e, o, (r) => t.postMessage({ protocol: E, id: o.id, type: "event", event: r })).then((r) => t.postMessage(r, pe(r)));
733
+ ye(o) && le(e, o, (r) => t.postMessage({ protocol: M, id: o.id, type: "event", event: r })).then((r) => t.postMessage(r, he(r)));
705
734
  };
706
735
  return t.on("message", n), () => t.off("message", n);
707
736
  }
708
- function Ce(e) {
737
+ function Ve(e) {
709
738
  return W("sha256").update(e).digest("hex");
710
739
  }
711
740
  export {
712
741
  B as ReportWorkerError,
713
- Le as createNodeReportExecutor,
714
- ze as openFileReportJobStore,
715
- Ce as reportArtifactSha256,
716
- _e as serveNodeReportWorker
742
+ Ze as createNodeReportExecutor,
743
+ Ke as openFileReportJobStore,
744
+ Ve as reportArtifactSha256,
745
+ Qe as serveNodeReportWorker
717
746
  };