@agile-team/mach-report 2.9.1 → 2.11.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 (115) hide show
  1. package/README.md +11 -7
  2. package/dist/ExcelBindingWizard-CjIiVox-.cjs +1 -0
  3. package/dist/ExcelBindingWizard-Dxm-K5HL.js +1240 -0
  4. package/dist/ParamEditor-D-Hf5xfO.cjs +1 -0
  5. package/dist/ParamEditor-DRGxzxeO.js +381 -0
  6. package/dist/ReportBatchPanel-BYgg0EDB.cjs +1 -0
  7. package/dist/ReportBatchPanel-Bby5yLzU.js +287 -0
  8. package/dist/ReportPreview-DWXROHBP.cjs +6 -0
  9. package/dist/ReportPreview-DiNXhQI0.js +4138 -0
  10. package/dist/ReportTemplateLibrary-C6CO7YCT.cjs +1 -0
  11. package/dist/ReportTemplateLibrary-DfzDXRvr.js +260 -0
  12. package/dist/RuleEditor-C2QsOHOs.cjs +1 -0
  13. package/dist/RuleEditor-D9wQHrkf.js +2024 -0
  14. package/dist/TemplateReviewPanel-BKofGrV9.js +222 -0
  15. package/dist/TemplateReviewPanel-DwtOcLue.cjs +1 -0
  16. package/dist/analytics.cjs +1 -1
  17. package/dist/analytics.d.cts +4 -0
  18. package/dist/analytics.d.ts +4 -0
  19. package/dist/analytics.js +40 -39
  20. package/dist/{assets-ahTRUXRk.cjs → assets-Bu6UohJx.cjs} +1 -1
  21. package/dist/{assets-DDsfEi8R.js → assets-DegqDNqY.js} +1 -1
  22. package/dist/batch-Bt3Fd27Z.cjs +1 -0
  23. package/dist/batch-mRqhhhjt.js +364 -0
  24. package/dist/{capabilities-Cm9hZ3uV.js → capabilities-CK_7hizc.js} +16 -16
  25. package/dist/capabilities-CsZ-pNHR.cjs +1 -0
  26. package/dist/computed-Bvk0W15F.js +521 -0
  27. package/dist/computed-CGV2a809.cjs +1 -0
  28. package/dist/config-B612mw0x.js +525 -0
  29. package/dist/config-BRoLo2oj.cjs +1 -0
  30. package/dist/designer.cjs +2 -2
  31. package/dist/designer.d.cts +695 -50
  32. package/dist/designer.d.ts +695 -50
  33. package/dist/designer.js +2213 -1748
  34. package/dist/index.cjs +8 -8
  35. package/dist/index.d.cts +205 -6
  36. package/dist/index.d.ts +205 -6
  37. package/dist/index.js +808 -1033
  38. package/dist/injection-keys-Db_DyLkm.cjs +1 -0
  39. package/dist/injection-keys-e85udZCp.js +7 -0
  40. package/dist/list-cell-BuYn4tGF.cjs +1 -0
  41. package/dist/list-cell-ClFra1zS.js +173 -0
  42. package/dist/matrix-DVyWiYsd.cjs +1 -0
  43. package/dist/matrix-yZsGnldA.js +227 -0
  44. package/dist/param-validation-BlHHXs6u.js +153 -0
  45. package/dist/param-validation-DCK039V1.cjs +1 -0
  46. package/dist/pdf.cjs +49 -49
  47. package/dist/pdf.d.cts +31 -1
  48. package/dist/pdf.d.ts +31 -1
  49. package/dist/pdf.js +4797 -4650
  50. package/dist/plugin-BDTU4D94.cjs +1 -0
  51. package/dist/plugin-Cd5G2QQn.js +22 -0
  52. package/dist/region-binding-workflow-CXDmt9Bs.js +977 -0
  53. package/dist/region-binding-workflow-DhQvu1co.cjs +3 -0
  54. package/dist/{report-params-B_VCihAh.js → report-params-B44imUd4.js} +1 -1
  55. package/dist/{report-params-CjWrjPl6.cjs → report-params-SJfhKgaX.cjs} +1 -1
  56. package/dist/server/node.d.cts +48 -5
  57. package/dist/server/node.d.ts +48 -5
  58. package/dist/server-node.cjs +1 -1
  59. package/dist/server-node.js +503 -317
  60. package/dist/server.cjs +1 -1
  61. package/dist/server.d.cts +252 -4
  62. package/dist/server.d.ts +252 -4
  63. package/dist/server.js +567 -469
  64. package/dist/style.css +1 -1
  65. package/dist/template-registry-WNXdkiET.js +506 -0
  66. package/dist/template-registry-ukBGlm8N.cjs +1 -0
  67. package/dist/template-review-BXp2oyqg.cjs +1 -0
  68. package/dist/template-review-BdcXSYbx.js +1616 -0
  69. package/dist/tree-BX380Rr7.cjs +1 -0
  70. package/dist/tree-CqcQ99NM.js +172 -0
  71. package/dist/useLocalDraft-C07SYRnC.js +11 -0
  72. package/dist/useLocalDraft-Yiw1wFgI.cjs +1 -0
  73. package/dist/{validate-DWPF7icl.js → validate-7s0yn6ii.js} +26 -26
  74. package/dist/validate-DsRiNw8h.cjs +1 -0
  75. package/dist/vue/async.d.cts +118 -6
  76. package/dist/vue/async.d.ts +118 -6
  77. package/dist/vue/index.d.cts +177 -11
  78. package/dist/vue/index.d.ts +177 -11
  79. package/dist/vue-async.cjs +1 -1
  80. package/dist/vue-async.js +5 -5
  81. package/dist/vue.cjs +1 -1
  82. package/dist/vue.js +116 -113
  83. package/dist/{import-template-CNMLJSQw.js → workbook-session-BKOTwcoq.js} +4290 -4227
  84. package/dist/{import-template-CpxunKVp.cjs → workbook-session-CLYLhZWu.cjs} +17 -17
  85. package/dist/worker.cjs +1 -1
  86. package/dist/worker.d.cts +9 -2
  87. package/dist/worker.d.ts +9 -2
  88. package/dist/worker.js +1 -1
  89. package/dist/xlsx.cjs +4 -2
  90. package/dist/xlsx.d.cts +159 -3
  91. package/dist/xlsx.d.ts +159 -3
  92. package/dist/xlsx.js +354 -192
  93. package/package.json +1 -1
  94. package/dist/ExcelBindingWizard-DiaxvWpQ.cjs +0 -1
  95. package/dist/ExcelBindingWizard-RLJIXKKG.js +0 -816
  96. package/dist/ReportPreview-B5ZNEasW.js +0 -4439
  97. package/dist/ReportPreview-DRtVPUYo.cjs +0 -6
  98. package/dist/RuleEditor-CskN5Fr3.cjs +0 -1
  99. package/dist/RuleEditor-CtJFzKuY.js +0 -1578
  100. package/dist/TemplateReviewPanel-C_Lmzis6.cjs +0 -1
  101. package/dist/TemplateReviewPanel-Cn32OY4_.js +0 -173
  102. package/dist/binding-preview-B5834rml.cjs +0 -2
  103. package/dist/binding-preview-ChXjN5L5.js +0 -649
  104. package/dist/capabilities-DYzWL7KS.cjs +0 -1
  105. package/dist/matrix-CNPDJxED.js +0 -745
  106. package/dist/matrix-Div9Ilh3.cjs +0 -1
  107. package/dist/param-validation-BWNjLcN0.js +0 -116
  108. package/dist/param-validation-CiTxFeZ8.cjs +0 -1
  109. package/dist/plugin-BWwIgZXV.js +0 -25
  110. package/dist/plugin-Dg-J1Rbm.cjs +0 -1
  111. package/dist/template-registry-CHMYZ7SD.cjs +0 -1
  112. package/dist/template-registry-R61AMCr0.js +0 -433
  113. package/dist/template-review-hvWWQFsi.js +0 -1027
  114. package/dist/template-review-jEcOfmGr.cjs +0 -1
  115. package/dist/validate-BDiMqkJC.cjs +0 -1
@@ -1,38 +1,38 @@
1
- import { parentPort as K, Worker as L } from "node:worker_threads";
2
- import { randomUUID as T, createHash as W } from "node:crypto";
3
- import { promises as d } from "node:fs";
4
- import N from "node:path";
5
- function U(e, t, r) {
6
- if (!r?.aborted)
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) {
6
+ if (!n?.aborted)
7
7
  try {
8
- const n = e?.({ ...t });
9
- n && typeof n.then == "function" && Promise.resolve(n).catch(() => {
8
+ const o = e?.({ ...t });
9
+ o && typeof o.then == "function" && Promise.resolve(o).catch(() => {
10
10
  });
11
11
  } catch {
12
12
  }
13
13
  }
14
- function B(e, t, r) {
15
- e.editable !== void 0 && typeof e.editable != "boolean" && r.push({ path: `${t}.editable`, message: "编辑控制应为布尔值" }), e.valueType !== void 0 && !["text", "number", "boolean"].includes(e.valueType) && r.push({ path: `${t}.valueType`, message: "编辑类型应为 text、number 或 boolean" });
14
+ function V(e, t, n) {
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 H(e, t, r) {
18
- B(e, t, r), F(e.source, `${t}.source`, r, !0), e.formula !== void 0 && typeof e.formula != "string" && r.push({ path: `${t}.formula`, message: "单元格公式应为字符串" });
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: "单元格公式应为字符串" });
19
19
  }
20
- function F(e, t, r, n = !1) {
20
+ function F(e, t, n, o = !1) {
21
21
  if (e === void 0) return;
22
22
  if (!e || typeof e != "object" || Array.isArray(e)) {
23
- r.push({ path: t, message: "业务来源应为对象" });
23
+ n.push({ path: t, message: "业务来源应为对象" });
24
24
  return;
25
25
  }
26
- const o = e;
27
- for (const s of ["datasetId", ...n ? ["field"] : []])
28
- (typeof o[s] != "string" || !o[s].trim()) && r.push({ path: `${t}.${s}`, message: "业务标识应为非空字符串" });
26
+ const r = e;
27
+ for (const s of ["datasetId", ...o ? ["field"] : []])
28
+ (typeof r[s] != "string" || !r[s].trim()) && n.push({ path: `${t}.${s}`, message: "业务标识应为非空字符串" });
29
29
  for (const s of ["rowKey", "revision"]) {
30
- const i = o[s];
31
- i === void 0 && !(n && s === "rowKey") || typeof i != "string" && !(typeof i == "number" && Number.isFinite(i)) && r.push({ path: `${t}.${s}`, message: "业务键及修订号应为字符串或有限数字" });
30
+ const i = r[s];
31
+ i === void 0 && !(o && s === "rowKey") || typeof i != "string" && !(typeof i == "number" && Number.isFinite(i)) && n.push({ path: `${t}.${s}`, message: "业务键及修订号应为字符串或有限数字" });
32
32
  }
33
- o.sourceToken !== void 0 && typeof o.sourceToken != "string" && r.push({ path: `${t}.sourceToken`, message: "来源令牌应为字符串" });
33
+ r.sourceToken !== void 0 && typeof r.sourceToken != "string" && n.push({ path: `${t}.sourceToken`, message: "来源令牌应为字符串" });
34
34
  }
35
- const G = /* @__PURE__ */ new Set([
35
+ const X = /* @__PURE__ */ new Set([
36
36
  "text",
37
37
  "image",
38
38
  "barcode",
@@ -42,149 +42,149 @@ const G = /* @__PURE__ */ new Set([
42
42
  "rect",
43
43
  "ellipse"
44
44
  ]);
45
- function $(e) {
45
+ function N(e) {
46
46
  return typeof e == "object" && e !== null && !Array.isArray(e);
47
47
  }
48
- function X(e, t, r, n) {
49
- const o = e[t];
50
- (typeof o != "number" || !Number.isFinite(o)) && n.push({ path: `${r}.${t}`, message: `应为有限数字,实际 ${JSON.stringify(o)}` });
48
+ function Z(e, t, n, o) {
49
+ const r = e[t];
50
+ (typeof r != "number" || !Number.isFinite(r)) && o.push({ path: `${n}.${t}`, message: `应为有限数字,实际 ${JSON.stringify(r)}` });
51
51
  }
52
- function Z(e, t, r) {
52
+ function Q(e, t, n) {
53
53
  if (e !== void 0) {
54
- const n = `${t}.table`;
55
- if (!$(e)) r.push({ path: n, message: "逻辑表来源应为对象" });
54
+ const o = `${t}.table`;
55
+ if (!N(e)) n.push({ path: o, message: "逻辑表来源应为对象" });
56
56
  else {
57
- F(e.source, `${n}.source`, r), (typeof e.id != "string" || !e.id.trim()) && r.push({ path: `${n}.id`, message: "逻辑表 ID 应为非空字符串" });
58
- const o = e.role;
59
- ["header", "body", "group-header", "subtotal", "grand-total"].includes(o) || r.push({ path: `${n}.role`, message: "未知逻辑表行角色" });
57
+ F(e.source, `${o}.source`, n), (typeof e.id != "string" || !e.id.trim()) && n.push({ path: `${o}.id`, message: "逻辑表 ID 应为非空字符串" });
58
+ const r = e.role;
59
+ ["header", "body", "group-header", "subtotal", "grand-total"].includes(r) || n.push({ path: `${o}.role`, message: "未知逻辑表行角色" });
60
60
  const s = e.rowIndex;
61
- (typeof s != "number" || !Number.isInteger(s) || (o === "header" ? s !== -1 : s < 0)) && r.push({ path: `${n}.rowIndex`, message: "表头索引应为 -1,内容行索引应为非负整数" }), (!Array.isArray(e.columnKeys) || e.columnKeys.some((i) => typeof i != "string")) && r.push({ path: `${n}.columnKeys`, message: "逻辑列字段应为字符串数组" }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && r.push({ path: `${n}.layout`, message: "布局应为 page 或 wide" }), e.title !== void 0 && typeof e.title != "string" && r.push({ path: `${n}.title`, message: "逻辑表名称应为字符串" });
61
+ (typeof s != "number" || !Number.isInteger(s) || (r === "header" ? s !== -1 : s < 0)) && n.push({ path: `${o}.rowIndex`, message: "表头索引应为 -1,内容行索引应为非负整数" }), (!Array.isArray(e.columnKeys) || e.columnKeys.some((i) => typeof i != "string")) && n.push({ path: `${o}.columnKeys`, message: "逻辑列字段应为字符串数组" }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && n.push({ path: `${o}.layout`, message: "布局应为 page 或 wide" }), e.title !== void 0 && typeof e.title != "string" && n.push({ path: `${o}.title`, message: "逻辑表名称应为字符串" });
62
62
  }
63
63
  }
64
64
  }
65
- function V(e, t, r, n) {
65
+ function Y(e, t, n, o) {
66
66
  if (e !== void 0)
67
- if (!$(e) || !Array.isArray(e.cells))
68
- r.push({ path: `${t}.grid.cells`, message: "grid.cells 应为二维数组" });
67
+ if (!N(e) || !Array.isArray(e.cells))
68
+ n.push({ path: `${t}.grid.cells`, message: "grid.cells 应为二维数组" });
69
69
  else {
70
- const o = e.paddingMm;
71
- o !== void 0 && (typeof o != "number" || !Number.isFinite(o) || o < 0) && r.push({ path: `${t}.grid.paddingMm`, message: "单元格内距应为有限非负数" }), e.cells.forEach((s, i) => {
70
+ const r = e.paddingMm;
71
+ r !== void 0 && (typeof r != "number" || !Number.isFinite(r) || r < 0) && n.push({ path: `${t}.grid.paddingMm`, message: "单元格内距应为有限非负数" }), e.cells.forEach((s, i) => {
72
72
  if (!Array.isArray(s)) {
73
- r.push({ path: `${t}.grid.cells.${i}`, message: "行应为数组" });
73
+ n.push({ path: `${t}.grid.cells.${i}`, message: "行应为数组" });
74
74
  return;
75
75
  }
76
- s.forEach((u, l) => {
77
- if (u == null) return;
78
- const c = `${t}.grid.cells.${i}.${l}`;
79
- if (!$(u)) {
80
- r.push({ path: c, message: "网格单元格应为对象或 null" });
76
+ s.forEach((m, h) => {
77
+ if (m == null) return;
78
+ const u = `${t}.grid.cells.${i}.${h}`;
79
+ if (!N(m)) {
80
+ n.push({ path: u, message: "网格单元格应为对象或 null" });
81
81
  return;
82
82
  }
83
- H(u, c, r), Array.isArray(u.children) && u.children.forEach((a, m) => {
84
- D(a, `${t}.grid.cells.${i}.${l}.children.${m}`, r, n);
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);
85
85
  });
86
86
  });
87
87
  });
88
88
  }
89
89
  }
90
- function Q(e, t, r) {
91
- e !== void 0 && (Array.isArray(e) ? e.forEach((n, o) => {
92
- (!$(n) || !Array.isArray(n.segments)) && r.push({ path: `${t}.richParagraphs.${o}`, message: "段落缺少 segments 数组" });
93
- }) : r.push({ path: `${t}.richParagraphs`, message: "richParagraphs 应为数组" }));
90
+ function ee(e, t, n) {
91
+ 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 数组" });
93
+ }) : n.push({ path: `${t}.richParagraphs`, message: "richParagraphs 应为数组" }));
94
94
  }
95
- function D(e, t, r, n = []) {
96
- if (!$(e)) {
97
- r.push({ path: t, message: "组件应为对象" });
95
+ function D(e, t, n, o = []) {
96
+ if (!N(e)) {
97
+ n.push({ path: t, message: "组件应为对象" });
98
98
  return;
99
99
  }
100
- const o = e.kind;
101
- typeof o != "string" ? r.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : G.has(o) || n.push({
100
+ const r = e.kind;
101
+ typeof r != "string" ? n.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : X.has(r) || o.push({
102
102
  path: `${t}.kind`,
103
- message: `未知组件类型 ${JSON.stringify(o)},将以兜底方式渲染`
103
+ message: `未知组件类型 ${JSON.stringify(r)},将以兜底方式渲染`
104
104
  });
105
105
  for (const s of ["leftMm", "topMm", "widthMm", "heightMm"])
106
- X(e, s, t, r);
107
- typeof e.leftMm == "number" && e.leftMm < -100 && r.push({ path: `${t}.leftMm`, message: "几何数值异常(leftMm<-100)" });
106
+ Z(e, s, t, n);
107
+ typeof e.leftMm == "number" && e.leftMm < -100 && n.push({ path: `${t}.leftMm`, message: "几何数值异常(leftMm<-100)" });
108
108
  for (const s of ["widthMm", "heightMm"])
109
- typeof e[s] == "number" && e[s] < 0 && r.push({ path: `${t}.${s}`, message: "组件尺寸不能为负数" });
110
- Z(e.table, t, r), e.pageAnchor !== void 0 && !["header", "footer"].includes(e.pageAnchor) && r.push({ path: `${t}.pageAnchor`, message: "页面锚点应为 header 或 footer" }), e.lineDirection !== void 0 && !["down", "up"].includes(e.lineDirection) && r.push({ path: `${t}.lineDirection`, message: "线段方向应为 down 或 up" }), V(e.grid, t, r, n), Q(e.richParagraphs, t, r);
109
+ 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);
111
111
  }
112
- function Y(e, t, r, n = []) {
113
- if (!$(e)) {
114
- r.push({ path: t, message: "页应为对象" });
112
+ function te(e, t, n, o = []) {
113
+ if (!N(e)) {
114
+ n.push({ path: t, message: "页应为对象" });
115
115
  return;
116
116
  }
117
- const o = e.pageWidthMm, s = e.pageHeightMm;
118
- (typeof o != "number" || !Number.isFinite(o) || o <= 0) && r.push({ path: `${t}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(o)}` }), (typeof s != "number" || !(s > 0 && s < 5e3)) && r.push({ path: `${t}.pageHeightMm`, message: `页高非法: ${JSON.stringify(s)}` }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && r.push({ path: `${t}.layout`, message: "布局应为 page 或 wide" });
117
+ const r = e.pageWidthMm, s = e.pageHeightMm;
118
+ (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
119
  const i = e.components;
120
120
  Array.isArray(i) ? Array.isArray(i) && i.forEach(
121
- (u, l) => D(u, `${t}.components.${l}`, r, n)
122
- ) : r.push({ path: `${t}.components`, message: "components 应为数组" });
121
+ (m, h) => D(m, `${t}.components.${h}`, n, o)
122
+ ) : n.push({ path: `${t}.components`, message: "components 应为数组" });
123
123
  }
124
- function ee(e) {
125
- const t = [], r = [], n = $(e) ? e.pages : void 0;
126
- if (!Array.isArray(n))
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))
127
127
  t.push({
128
128
  path: "$.pages",
129
129
  message: e == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
130
130
  });
131
131
  else {
132
- n.forEach((s, i) => Y(s, `$.pages.${i}`, t, r)), n.length > 2e3 && r.push({
132
+ o.forEach((s, i) => te(s, `$.pages.${i}`, t, n)), o.length > 2e3 && n.push({
133
133
  path: "$.pages",
134
- message: `页数异常大(${n.length} 页),渲染与打印耗时可能显著增加`
134
+ message: `页数异常大(${o.length} 页),渲染与打印耗时可能显著增加`
135
135
  });
136
- const o = n.reduce(
137
- (s, i) => s + ($(i) && Array.isArray(i.components) ? i.components.length : 0),
136
+ const r = o.reduce(
137
+ (s, i) => s + (N(i) && Array.isArray(i.components) ? i.components.length : 0),
138
138
  0
139
139
  );
140
- o > 5e4 && r.push({
140
+ r > 5e4 && n.push({
141
141
  path: "$.pages",
142
- message: `组件总数异常大(${o} 个),可能触发浏览器性能限制`
142
+ message: `组件总数异常大(${r} 个),可能触发浏览器性能限制`
143
143
  });
144
144
  }
145
- return { ok: t.length === 0, errors: t, warnings: r };
145
+ return { ok: t.length === 0, errors: t, warnings: n };
146
146
  }
147
- const x = "mach-report-worker/1";
148
- class J extends Error {
147
+ const E = "mach-report-worker/1";
148
+ class B extends Error {
149
149
  constructor(t) {
150
150
  super(t.message), this.name = t.name, this.code = t.code, this.path = t.path, this.issues = t.issues, this.diagnostics = t.diagnostics;
151
151
  }
152
152
  }
153
- function E(e) {
153
+ function R(e) {
154
154
  return !!e && typeof e == "object" && !Array.isArray(e);
155
155
  }
156
- function te(e) {
157
- return E(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
- }
159
156
  function re(e) {
160
- return Array.isArray(e) && e.every((t) => E(t) && typeof t.code == "string" && typeof t.message == "string" && ["info", "warning", "error"].includes(t.severity));
157
+ 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;
161
158
  }
162
- function ne(e) {
163
- return E(e) && Object.values(e).every((t) => E(t) && (t.revision === void 0 || typeof t.revision == "string") && (t.sourceToken === void 0 || typeof t.sourceToken == "string"));
159
+ function oe(e) {
160
+ return Array.isArray(e) && e.every((t) => R(t) && typeof t.code == "string" && typeof t.message == "string" && ["info", "warning", "error"].includes(t.severity));
164
161
  }
165
- function oe(e, t) {
166
- if (!E(e) || !te(e.stats) || !re(e.diagnostics) || !ne(e.revisions)) return !1;
167
- if (t === "prepare") return ee(e.plan).ok;
168
- const r = e.format === "pdf" ? "application/pdf" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
169
- return e.bytes instanceof Uint8Array && (e.format === "pdf" || e.format === "xlsx") && e.contentType === r;
162
+ function se(e) {
163
+ 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"));
170
164
  }
171
- function _(e) {
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;
168
+ const n = e.format === "pdf" ? "application/pdf" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
169
+ return e.bytes instanceof Uint8Array && (e.format === "pdf" || e.format === "xlsx") && e.contentType === n;
170
+ }
171
+ function U(e) {
172
172
  if (!e || typeof e != "object") return { message: String(e) };
173
173
  const t = {};
174
- for (const r of ["code", "path", "field", "message"]) {
175
- const n = e[r];
176
- typeof n == "string" && (t[r] = n);
174
+ for (const n of ["code", "path", "field", "message"]) {
175
+ const o = e[n];
176
+ typeof o == "string" && (t[n] = o);
177
177
  }
178
178
  return t;
179
179
  }
180
- function se(e) {
181
- const t = _(e);
182
- if (!E(e)) return t;
183
- for (const r of ["format", "severity", "kind", "nid"]) typeof e[r] == "string" && (t[r] = e[r]);
184
- for (const r of ["pageIndex", "componentIndex"]) Number.isSafeInteger(e[r]) && e[r] >= 0 && (t[r] = e[r]);
185
- return Array.isArray(e.componentPath) && e.componentPath.every((r) => Number.isSafeInteger(r) && r >= 0) && (t.componentPath = e.componentPath), t;
180
+ function ae(e) {
181
+ const t = U(e);
182
+ if (!R(e)) return t;
183
+ for (const n of ["format", "severity", "kind", "nid"]) typeof e[n] == "string" && (t[n] = e[n]);
184
+ for (const n of ["pageIndex", "componentIndex"]) Number.isSafeInteger(e[n]) && e[n] >= 0 && (t[n] = e[n]);
185
+ return Array.isArray(e.componentPath) && e.componentPath.every((n) => Number.isSafeInteger(n) && n >= 0) && (t.componentPath = e.componentPath), t;
186
186
  }
187
- function ie(e) {
187
+ function ce(e) {
188
188
  if (!(e instanceof Error)) return { name: "Error", message: String(e) };
189
189
  const t = e;
190
190
  return {
@@ -192,340 +192,526 @@ function ie(e) {
192
192
  message: e.message,
193
193
  ...typeof t.code == "string" ? { code: t.code } : {},
194
194
  ...typeof t.path == "string" ? { path: t.path } : {},
195
- ...Array.isArray(t.issues) ? { issues: t.issues.map(_) } : {},
196
- ...Array.isArray(t.diagnostics) ? { diagnostics: t.diagnostics.map(se) } : {}
195
+ ...Array.isArray(t.issues) ? { issues: t.issues.map(U) } : {},
196
+ ...Array.isArray(t.diagnostics) ? { diagnostics: t.diagnostics.map(ae) } : {}
197
197
  };
198
198
  }
199
- function ae(e) {
199
+ function fe(e) {
200
200
  if (!e || typeof e != "object") return !1;
201
201
  const t = e;
202
- return t.protocol === x && typeof t.id == "string" && (t.operation === "prepare" || t.operation === "export") && !!t.input && typeof t.input == "object";
202
+ return t.protocol === E && typeof t.id == "string" && (t.operation === "prepare" || t.operation === "export") && !!t.input && typeof t.input == "object";
203
203
  }
204
- async function ce(e, t, r) {
204
+ async function ue(e, t, n) {
205
205
  try {
206
- const n = t.operation === "prepare" ? await e.prepare({ ...t.input, onEvent: r }) : await e.export({ ...t.input, onEvent: r });
207
- return { protocol: x, id: t.id, result: n };
208
- } catch (n) {
209
- return { protocol: x, id: t.id, error: ie(n) };
206
+ 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 };
208
+ } catch (o) {
209
+ return { protocol: E, id: t.id, error: ce(o) };
210
210
  }
211
211
  }
212
- function fe(e) {
212
+ function pe(e) {
213
213
  const t = e.result;
214
214
  return !t || !("bytes" in t) || !(t.bytes.buffer instanceof ArrayBuffer) ? [] : [t.bytes.buffer];
215
215
  }
216
- function ue(e, t) {
217
- if (!E(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;
218
- for (const r of ["completed", "total"]) if (e[r] !== void 0 && (typeof e[r] != "number" || !Number.isFinite(e[r]) || e[r] < 0)) return !1;
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;
218
+ 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
219
  return e.completed === void 0 || e.total === void 0 || e.completed <= e.total;
220
220
  }
221
- let pe = 0;
222
- function j(e) {
221
+ let me = 0;
222
+ function P(e) {
223
223
  const t = new Error("报表 Worker 任务已取消");
224
224
  return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e }), t;
225
225
  }
226
- function de(e, t) {
226
+ function ye(e, t) {
227
227
  if (!e || typeof e != "object") return;
228
- const r = e;
229
- return r.protocol === x && r.id === t ? r : void 0;
228
+ const n = e;
229
+ return n.protocol === E && n.id === t ? n : void 0;
230
230
  }
231
231
  function le(e, t = {}) {
232
- const r = t.timeoutMs ?? 12e4;
233
- if (!Number.isFinite(r) || r <= 0 || r > 2147483647) throw new RangeError("Worker timeoutMs 应为正有限数字,且不能超过 2147483647");
234
- const n = (o, s, i, u) => i?.aborted ? Promise.reject(j(i.reason)) : new Promise((l, c) => {
235
- let a;
232
+ const n = t.timeoutMs ?? 12e4;
233
+ 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) => {
235
+ let b;
236
236
  try {
237
- a = e();
238
- } catch (h) {
239
- c(h);
237
+ b = e();
238
+ } catch (y) {
239
+ u(y);
240
240
  return;
241
241
  }
242
- const m = `mach-report-${Date.now()}-${++pe}`;
243
- let y = !1, b = () => {
244
- }, g;
245
- const w = (h, p) => {
246
- y || (y = !0, g && clearTimeout(g), b(), i?.removeEventListener("abort", S), Promise.resolve().then(() => a.terminate()).then(
247
- () => h === void 0 ? l(p) : c(h),
248
- (k) => c(h ?? k)
242
+ const k = `mach-report-${Date.now()}-${++me}`;
243
+ let p = !1, f = () => {
244
+ }, c;
245
+ const d = (y, w) => {
246
+ 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 ?? $)
249
249
  ));
250
- }, S = () => w(j(i?.reason)), A = (h) => {
251
- const p = de(h, m);
252
- if (!(!p || y)) {
253
- if ("type" in p && p.type === "event") {
254
- const k = "event" in p ? p.event : void 0;
255
- ue(k, s) ? U(u, k, i) : w(new Error("报表 Worker 返回无效阶段事件"));
250
+ }, g = () => d(P(i?.reason)), A = (y) => {
251
+ const w = ye(y, k);
252
+ if (!(!w || p)) {
253
+ 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 返回无效阶段事件"));
256
256
  return;
257
257
  }
258
- p.error && typeof p.error.name == "string" && typeof p.error.message == "string" ? w(new J(p.error)) : oe(p.result, o) && (o !== "export" || "format" in p.result && "format" in s && p.result.format === s.format) ? w(void 0, p.result) : w(new Error("报表 Worker 返回无效响应"));
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 返回无效响应"));
259
259
  }
260
260
  };
261
261
  try {
262
- if (b = a.subscribe(A, (h) => w(h ?? new Error("报表 Worker 执行失败"))), y) {
263
- b();
262
+ if (f = b.subscribe(A, (y) => d(y ?? new Error("报表 Worker 执行失败"))), p) {
263
+ f();
264
264
  return;
265
265
  }
266
- if (i?.addEventListener("abort", S, { once: !0 }), g = setTimeout(() => w(new J({ name: "ReportRuntimeError", code: "timeout", message: `报表 Worker 执行超过 ${r}ms` })), r), i?.aborted) S();
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();
267
267
  else {
268
- const { onEvent: h, signal: p, ...k } = s;
269
- a.postMessage({ protocol: x, id: m, operation: o, input: k });
268
+ const { onEvent: y, signal: w, ...$ } = s;
269
+ b.postMessage({ protocol: E, id: k, operation: r, input: $ });
270
270
  }
271
- } catch (h) {
272
- w(h);
271
+ } catch (y) {
272
+ d(y);
273
273
  }
274
274
  });
275
- return { prepare: (o, s, i) => n("prepare", o, s, i), export: (o, s, i) => n("export", o, s, i) };
275
+ return { prepare: (r, s, i) => o("prepare", r, s, i), export: (r, s, i) => o("export", r, s, i) };
276
+ }
277
+ const he = new Uint32Array([
278
+ 1116352408,
279
+ 1899447441,
280
+ 3049323471,
281
+ 3921009573,
282
+ 961987163,
283
+ 1508970993,
284
+ 2453635748,
285
+ 2870763221,
286
+ 3624381080,
287
+ 310598401,
288
+ 607225278,
289
+ 1426881987,
290
+ 1925078388,
291
+ 2162078206,
292
+ 2614888103,
293
+ 3248222580,
294
+ 3835390401,
295
+ 4022224774,
296
+ 264347078,
297
+ 604807628,
298
+ 770255983,
299
+ 1249150122,
300
+ 1555081692,
301
+ 1996064986,
302
+ 2554220882,
303
+ 2821834349,
304
+ 2952996808,
305
+ 3210313671,
306
+ 3336571891,
307
+ 3584528711,
308
+ 113926993,
309
+ 338241895,
310
+ 666307205,
311
+ 773529912,
312
+ 1294757372,
313
+ 1396182291,
314
+ 1695183700,
315
+ 1986661051,
316
+ 2177026350,
317
+ 2456956037,
318
+ 2730485921,
319
+ 2820302411,
320
+ 3259730800,
321
+ 3345764771,
322
+ 3516065817,
323
+ 3600352804,
324
+ 4094571909,
325
+ 275423344,
326
+ 430227734,
327
+ 506948616,
328
+ 659060556,
329
+ 883997877,
330
+ 958139571,
331
+ 1322822218,
332
+ 1537002063,
333
+ 1747873779,
334
+ 1955562222,
335
+ 2024104815,
336
+ 2227730452,
337
+ 2361852424,
338
+ 2428436474,
339
+ 2756734187,
340
+ 3204031479,
341
+ 3329325298
342
+ ]), x = (e, t) => e >>> t | e << 32 - t;
343
+ function ge(e, t, n) {
344
+ const o = new DataView(e.buffer, e.byteOffset + t, 64);
345
+ for (let r = 0; r < 16; r++) n[r] = o.getUint32(r * 4);
346
+ 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;
349
+ }
276
350
  }
277
- class f extends Error {
278
- constructor(t, r) {
279
- super(r), this.code = t, this.name = "ReportJobError";
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];
353
+ 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;
356
+ }
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;
358
+ }
359
+ function be(e) {
360
+ const t = new Uint8Array(Math.ceil((e.byteLength + 9) / 64) * 64);
361
+ t.set(e), t[e.byteLength] = 128;
362
+ const n = new DataView(t.buffer);
363
+ return n.setUint32(t.length - 8, Math.floor(e.byteLength / 536870912)), n.setUint32(t.length - 4, e.byteLength * 8 >>> 0), t;
364
+ }
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);
368
+ 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);
371
+ }
372
+ class a extends Error {
373
+ constructor(t, n) {
374
+ super(n), this.code = t, this.name = "ReportJobError";
280
375
  }
281
376
  }
282
- function q(e, t) {
283
- if (typeof e != "string" || !e.trim() || e.length > 256 || typeof t != "string" || !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{0,127}$/.test(t)) throw new f("input", "任务范围应非空,ID应为1–128位安全标识");
284
- }
285
- function ye(e) {
286
- const t = Array.isArray(e), r = Object.getPrototypeOf(e), n = Object.keys(e);
287
- if (r !== (t ? Array.prototype : Object.prototype) && !(r === null && !t)) throw new f("input", "任务对象应为普通 JSON 对象");
288
- if (Object.getOwnPropertySymbols(e).length) throw new f("input", "任务不能包含Symbol");
289
- if (Object.getOwnPropertyNames(e).filter((s) => !(t && s === "length")).length !== n.length) throw new f("input", "任务不能包含不可枚举属性");
290
- if (t && (n.length !== e.length || n.some((s) => !/^(0|[1-9]\d*)$/.test(s) || Number(s) >= e.length))) throw new f("input", "任务数组不能稀疏或包含额外属性");
291
- return n.sort();
292
- }
293
- function he(e, t) {
294
- const r = Object.getOwnPropertyDescriptor(e, t);
295
- if (["__proto__", "prototype", "constructor"].includes(t) || r.get || r.set) throw new f("input", "任务不能包含危险键或访问器");
296
- return r.value;
297
- }
298
- function O(e, t = {}) {
299
- const r = t.maxNodes ?? 2e4, n = t.maxCharacters ?? 1e6;
300
- if (!Number.isSafeInteger(r) || r < 1 || r > 2e4 || !Number.isSafeInteger(n) || n < 1 || n > 1e6) throw new f("input", "任务JSON预算无效");
301
- let o = 0, s = 0;
377
+ function T(e, t) {
378
+ 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
+ }
380
+ function $e(e) {
381
+ const t = Array.isArray(e), n = Object.getPrototypeOf(e), o = Object.keys(e);
382
+ if (n !== (t ? Array.prototype : Object.prototype) && !(n === null && !t)) throw new a("input", "任务对象应为普通 JSON 对象");
383
+ if (Object.getOwnPropertySymbols(e).length) throw new a("input", "任务不能包含Symbol");
384
+ if (Object.getOwnPropertyNames(e).filter((s) => !(t && s === "length")).length !== o.length) throw new a("input", "任务不能包含不可枚举属性");
385
+ 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
+ return o.sort();
387
+ }
388
+ function Ne(e, t) {
389
+ const n = Object.getOwnPropertyDescriptor(e, t);
390
+ if (["__proto__", "prototype", "constructor"].includes(t) || n.get || n.set) throw new a("input", "任务不能包含危险键或访问器");
391
+ return n.value;
392
+ }
393
+ function S(e, t = {}) {
394
+ const n = t.maxNodes ?? 2e4, o = t.maxCharacters ?? 1e6;
395
+ if (!Number.isSafeInteger(n) || n < 1 || n > 2e4 || !Number.isSafeInteger(o) || o < 1 || o > 1e6) throw new a("input", "任务JSON预算无效");
396
+ let r = 0, s = 0;
302
397
  const i = /* @__PURE__ */ new Set();
303
- function u(c, a) {
304
- if (++o > r || a > 32) throw new f("input", "任务数据超过节点或深度预算");
305
- if (typeof c == "string") {
306
- if (s += c.length, s > n) throw new f("input", "任务文本超过预算");
307
- return c;
398
+ function m(u, b) {
399
+ if (++r > n || b > 32) throw new a("input", "任务数据超过节点或深度预算");
400
+ if (typeof u == "string") {
401
+ if (s += u.length, s > o) throw new a("input", "任务文本超过预算");
402
+ return u;
308
403
  }
309
- if (c === null || typeof c == "boolean" || typeof c == "number" && Number.isFinite(c)) return c;
310
- if (!c || typeof c != "object" || i.has(c)) throw new f("input", "任务只允许无循环的有限 JSON 值");
311
- const m = Array.isArray(c), y = ye(c);
312
- i.add(c);
313
- const b = /* @__PURE__ */ Object.create(null);
314
- for (const g of y) {
315
- if (s += g.length, s > n) throw new f("input", "任务文本超过预算");
316
- b[g] = u(he(c, g), a + 1);
404
+ if (u === null || typeof u == "boolean" || typeof u == "number" && Number.isFinite(u)) return u;
405
+ if (!u || typeof u != "object" || i.has(u)) throw new a("input", "任务只允许无循环的有限 JSON 值");
406
+ const k = Array.isArray(u), p = $e(u);
407
+ i.add(u);
408
+ const f = /* @__PURE__ */ Object.create(null);
409
+ for (const c of p) {
410
+ if (s += c.length, s > o) throw new a("input", "任务文本超过预算");
411
+ f[c] = m(Ne(u, c), b + 1);
317
412
  }
318
- return i.delete(c), m ? Array.from({ length: c.length }, (g, w) => b[String(w)]) : b;
413
+ return i.delete(u), k ? Array.from({ length: u.length }, (c, d) => f[String(d)]) : f;
319
414
  }
320
- const l = JSON.stringify(u(e, 0));
321
- if (l.length > n) throw new f("input", "任务序列化数据超过字符预算");
322
- return l;
415
+ const h = JSON.stringify(m(e, 0));
416
+ if (h.length > o) throw new a("input", "任务序列化数据超过字符预算");
417
+ return h;
323
418
  }
324
- function P(e) {
419
+ function j(e) {
325
420
  return JSON.parse(JSON.stringify(e));
326
421
  }
327
- function z(e, t, r, n) {
328
- if (q(t, r), e.scope !== t || e.id !== r || e.revision !== (n ?? 0) + 1 || !Number.isSafeInteger(e.revision)) throw new f("input", "任务身份或修订不匹配");
329
- if (![e.createdAt, e.updatedAt, e.attempt].every((o) => Number.isSafeInteger(o) && o >= 0) || !["queued", "running", "completed", "failed", "cancelled"].includes(e.status)) throw new f("input", "任务状态无效");
330
- if (e.lease && (!e.lease.owner || !Number.isSafeInteger(e.lease.expiresAt))) throw new f("input", "任务租约无效");
331
- if (!e.request || typeof e.request.kind != "string" || !e.request.kind.trim() || e.request.kind.length > 128) throw new f("input", "任务类型无效");
332
- O(e.request.payload, { maxNodes: 19e3, maxCharacters: 75e4 }), O(e);
422
+ function z(e, t, n, o) {
423
+ if (T(t, n), e.scope !== t || e.id !== n || e.revision !== (o ?? 0) + 1 || !Number.isSafeInteger(e.revision)) throw new a("input", "任务身份或修订不匹配");
424
+ 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
+ if (e.lease && (!e.lease.owner || !Number.isSafeInteger(e.lease.expiresAt))) throw new a("input", "任务租约无效");
426
+ 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);
333
428
  }
334
- function me(e, t) {
335
- if (e && (e.createdAt !== t.createdAt || O(e.request) !== O(t.request))) throw new f("input", "任务创建时间与请求不可变更,请使用新任务ID");
429
+ function Se(e, t) {
430
+ if (e && (e.createdAt !== t.createdAt || S(e.request) !== S(t.request))) throw new a("input", "任务创建时间与请求不可变更,请使用新任务ID");
336
431
  }
337
- function ge(e, t) {
432
+ function ve(e, t) {
338
433
  return e.status === "queued" || e.status === "running" && (e.lease?.expiresAt ?? 0) <= t;
339
434
  }
340
- function v(e) {
435
+ function Re(e = {}) {
436
+ const t = {
437
+ maxRecords: e.maxRecords ?? 1e4,
438
+ maxBytes: e.maxBytes ?? 67108864,
439
+ maxResultBytes: e.maxResultBytes ?? 262144,
440
+ controlReserveBytes: e.controlReserveBytes ?? 4096,
441
+ maxTombstones: e.maxTombstones ?? 1e4,
442
+ maxTombstoneBytes: e.maxTombstoneBytes ?? 16777216
443
+ };
444
+ if (!Object.values(t).every((n) => Number.isSafeInteger(n) && n > 0) || t.controlReserveBytes < 4096) throw new a("input", "任务容量应为正整数,控制状态预留至少4096字节");
445
+ return t;
446
+ }
447
+ function M(e) {
448
+ return new TextEncoder().encode(S(e)).byteLength;
449
+ }
450
+ function L(e, t) {
451
+ 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
+ delete o.result;
453
+ const r = e.result === void 0 ? 0 : M(e.result);
454
+ if (r > t.maxResultBytes) throw new a("capacity", "任务结果超过独立预算,请保存文件引用");
455
+ return Math.max(M(n) + t.controlReserveBytes, M(o)) + r;
456
+ }
457
+ function _(e) {
458
+ return e.status !== "queued" && e.status !== "running";
459
+ }
460
+ function Ee(e) {
461
+ const t = { ...e, tombstoneRetentionMs: e.tombstoneRetentionMs ?? 6048e5, limit: e.limit ?? 100 };
462
+ if (![t.now, t.terminalBefore].every((n) => Number.isSafeInteger(n) && n >= 0) || t.terminalBefore > t.now) throw new a("input", "终态清理时间应为不超过当前时间的非负整数");
463
+ if (![t.tombstoneRetentionMs, t.limit].every((n) => Number.isSafeInteger(n) && n > 0) || !Number.isSafeInteger(t.now + t.tombstoneRetentionMs)) throw new a("input", "幂等保留期与清理批量应为正整数");
464
+ return t;
465
+ }
466
+ async function Me(e) {
467
+ const t = new TextEncoder().encode(S(e)), n = globalThis.crypto?.subtle;
468
+ if (!n) return ke(t);
469
+ const o = await n.digest("SHA-256", t);
470
+ return Array.from(new Uint8Array(o), (r) => r.toString(16).padStart(2, "0")).join("");
471
+ }
472
+ async function Oe(e, t) {
473
+ 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 };
475
+ }
476
+ function Ie(e) {
477
+ if (!e || !["completed", "failed", "cancelled"].includes(e.status) || !/^[a-f0-9]{64}$/.test(e.requestHash)) throw new a("input", "任务幂等摘要无效");
478
+ 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
+ }
480
+ function I(e) {
341
481
  return e?.code;
342
482
  }
343
- function M(e, t) {
483
+ function O(e, t) {
344
484
  return W("sha256").update(JSON.stringify([e, t])).digest("hex") + ".json";
345
485
  }
346
- async function R(e) {
486
+ async function J(e) {
347
487
  try {
348
- return await d.readFile(e, "utf8");
488
+ return await l.readFile(e, "utf8");
349
489
  } catch (t) {
350
- if (v(t) === "ENOENT") return;
490
+ if (I(t) === "ENOENT") return;
351
491
  throw t;
352
492
  }
353
493
  }
354
- async function we(e, t) {
355
- const r = await R(e);
356
- if (r === void 0) return;
357
- let n;
494
+ async function Te(e, t) {
495
+ const n = await J(e);
496
+ if (n === void 0) return;
497
+ let o;
358
498
  try {
359
- n = JSON.parse(r);
499
+ o = JSON.parse(n);
360
500
  } catch {
361
- throw new f("conflict", "任务锁尚未完整写入或已损坏,拒绝自动移除");
501
+ throw new a("conflict", "任务锁尚未完整写入或已损坏,拒绝自动移除");
362
502
  }
363
- if (!n || !Number.isSafeInteger(n.pid) || n.pid < 1) throw new f("conflict", "任务锁身份无效,拒绝自动移除");
503
+ if (!o || !Number.isSafeInteger(o.pid) || o.pid < 1) throw new a("conflict", "任务锁身份无效,拒绝自动移除");
364
504
  try {
365
- process.kill(n.pid, 0);
366
- } catch (o) {
367
- if (v(o) === "ESRCH") {
368
- await d.unlink(e);
505
+ process.kill(o.pid, 0);
506
+ } catch (r) {
507
+ if (I(r) === "ESRCH") {
508
+ await l.unlink(e);
369
509
  return;
370
510
  }
371
- throw o;
511
+ throw r;
372
512
  }
373
- throw new f("conflict", "任务目录的写入进程仍在运行");
513
+ throw new a("conflict", "任务目录的写入进程仍在运行");
374
514
  }
375
- async function be(e, t) {
376
- if (!t) throw new f("conflict", "任务目录已有写入进程;多实例请使用数据库CAS适配器");
377
- const r = e + ".recovery";
378
- let n;
515
+ async function je(e, t) {
516
+ if (!t) throw new a("conflict", "任务目录已有写入进程;多实例请使用数据库CAS适配器");
517
+ const n = e + ".recovery";
518
+ let o;
379
519
  try {
380
- n = await d.open(r, "wx", 384);
381
- } catch (o) {
382
- throw v(o) === "EEXIST" ? new f("conflict", "任务目录恢复正在进行,请稍后重试") : o;
520
+ o = await l.open(n, "wx", 384);
521
+ } catch (r) {
522
+ throw I(r) === "EEXIST" ? new a("conflict", "任务目录恢复正在进行,请稍后重试") : r;
383
523
  }
384
524
  try {
385
- return await n.writeFile(JSON.stringify({ pid: process.pid })), await we(e, !0), await d.open(e, "wx", 384);
525
+ return await o.writeFile(JSON.stringify({ pid: process.pid })), await Te(e, !0), await l.open(e, "wx", 384);
386
526
  } finally {
387
- await n.close(), await d.unlink(r);
527
+ await o.close(), await l.unlink(n);
388
528
  }
389
529
  }
390
- async function ke(e, t) {
391
- const r = N.join(e, ".writer-lock"), n = T();
392
- let o;
530
+ async function Je(e, t) {
531
+ const n = v.join(e, ".writer-lock"), o = q();
532
+ let r;
393
533
  try {
394
- o = await d.open(r, "wx", 384);
534
+ r = await l.open(n, "wx", 384);
395
535
  } catch (s) {
396
- if (v(s) !== "EEXIST") throw s;
397
- o = await be(r, t);
536
+ if (I(s) !== "EEXIST") throw s;
537
+ r = await je(n, t);
398
538
  }
399
539
  try {
400
- await o.writeFile(JSON.stringify({ pid: process.pid, token: n })), await o.sync();
540
+ await r.writeFile(JSON.stringify({ pid: process.pid, token: o })), await r.sync();
401
541
  } catch (s) {
402
- throw await o.close(), await d.unlink(r).catch(() => {
542
+ throw await r.close(), await l.unlink(n).catch(() => {
403
543
  }), s;
404
544
  }
405
- return { file: r, token: n, handle: o };
406
- }
407
- async function $e(e, t, r) {
408
- const n = await d.readdir(e);
409
- for (const u of n.filter((l) => /^\.pending-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(l))) await d.unlink(N.join(e, u));
410
- const o = n.filter((u) => /^[a-f0-9]{64}\.json$/.test(u));
411
- if (o.length > t) throw new f("capacity", "持久任务数量超过目录预算");
412
- const s = /* @__PURE__ */ new Map();
413
- let i = 0;
414
- for (const u of o) {
415
- const l = N.join(e, u), c = await d.stat(l);
416
- if (i += c.size, c.size > 4e6 || i > r) throw new f("capacity", "持久任务文件超过容量预算");
417
- const a = JSON.parse(await d.readFile(l, "utf8"));
418
- if (z(a, a.scope, a.id, a.revision - 1), M(a.scope, a.id) !== u) throw new f("input", "持久任务文件身份不匹配");
419
- s.set(u, { record: a, bytes: c.size });
545
+ return { file: n, token: o, handle: r };
546
+ }
547
+ function Be(e, t, n, o) {
548
+ if ("tombstone" in n) {
549
+ 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);
552
+ e.tombstoneBytes += s, e.tombstones.set(t, { value: r, bytes: s });
553
+ } 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);
556
+ e.bytes += r, e.records.set(t, { record: n, bytes: r });
557
+ }
558
+ if (e.bytes > o.maxBytes || e.records.size > o.maxRecords || e.tombstoneBytes > o.maxTombstoneBytes || e.tombstones.size > o.maxTombstones) throw new a("capacity", "持久任务及控制状态预留超过目录预算");
559
+ }
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));
563
+ const o = n.filter((s) => /^[a-f0-9]{64}\.json$/.test(s));
564
+ if (o.length > t.maxRecords + t.maxTombstones) throw new a("capacity", "持久任务数量超过目录预算");
565
+ const r = { records: /* @__PURE__ */ new Map(), tombstones: /* @__PURE__ */ new Map(), bytes: 0, tombstoneBytes: 0 };
566
+ 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);
420
570
  }
421
- return { records: s, bytes: i };
571
+ return r;
422
572
  }
423
- async function Ae(e, t, r) {
424
- const n = N.join(e, `.pending-${T()}`);
573
+ async function qe(e, t, n) {
574
+ const o = v.join(e, `.pending-${q()}`);
425
575
  try {
426
- const o = await d.open(n, "wx", 384);
576
+ const r = await l.open(o, "wx", 384);
427
577
  try {
428
- await o.writeFile(r), await o.sync();
578
+ await r.writeFile(n), await r.sync();
429
579
  } finally {
430
- await o.close();
580
+ await r.close();
431
581
  }
432
- await d.rename(n, N.join(e, t));
433
- const s = await d.open(e, "r");
582
+ await l.rename(o, v.join(e, t));
583
+ const s = await l.open(e, "r");
434
584
  try {
435
585
  await s.sync();
436
586
  } finally {
437
587
  await s.close();
438
588
  }
439
589
  } finally {
440
- await d.unlink(n).catch((o) => {
441
- if (v(o) !== "ENOENT") throw o;
590
+ await l.unlink(o).catch((r) => {
591
+ if (I(r) !== "ENOENT") throw r;
442
592
  });
443
593
  }
444
594
  }
445
- async function Oe(e) {
446
- const t = N.resolve(e.directory), r = e.maxRecords ?? 1e4, n = e.maxBytes ?? 64 * 1024 * 1024;
447
- if (![r, n].every((a) => Number.isSafeInteger(a) && a > 0)) throw new f("input", "持久任务预算应为正整数");
448
- await d.mkdir(t, { recursive: !0, mode: 448 });
449
- const o = await ke(t, e.recoverDeadOwner ?? !1);
450
- let s;
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);
599
+ let r;
451
600
  try {
452
- s = await $e(t, r, n);
453
- } catch (a) {
454
- throw await o.handle.close(), await d.unlink(o.file), a;
601
+ r = await Pe(t, n);
602
+ } catch (p) {
603
+ throw await o.handle.close(), await l.unlink(o.file), p;
455
604
  }
456
- let i = !1, u = Promise.resolve();
457
- const l = () => {
458
- if (i) throw new f("closed", "持久任务存储已关闭");
605
+ let s = !1, i = Promise.resolve();
606
+ const m = () => {
607
+ if (s) throw new a("closed", "持久任务存储已关闭");
608
+ }, h = (p) => {
609
+ m();
610
+ const f = i.then(async () => {
611
+ if (JSON.parse(await l.readFile(o.file, "utf8")).token !== o.token) throw new a("closed", "持久任务存储写入锁已失效");
612
+ return p();
613
+ });
614
+ return i = f.then(() => {
615
+ }, () => {
616
+ }), f;
617
+ }, u = async (p, f, c) => {
618
+ try {
619
+ await qe(t, p, f);
620
+ } catch (d) {
621
+ throw await J(v.join(t, p)) === f && c(), d;
622
+ }
623
+ c();
459
624
  };
460
625
  return {
461
- read: async (a, m) => {
462
- l(), q(a, m), await u;
463
- const y = s.records.get(M(a, m));
464
- return y ? P(y.record) : void 0;
626
+ read: async (p, f) => {
627
+ m(), T(p, f), await i;
628
+ const c = r.records.get(O(p, f));
629
+ return c ? j(c.record) : void 0;
465
630
  },
466
- candidates: async (a, m) => (l(), await u, Array.from(s.records.values(), (y) => y.record).filter((y) => ge(y, a)).sort((y, b) => y.createdAt - b.createdAt).slice(0, m).map(P)),
467
- compareAndSwap: async (a, m, y, b) => {
468
- l();
469
- const g = JSON.parse(O(b));
470
- z(g, a, m, y);
471
- let w = !1;
472
- const S = u.then(async () => {
473
- if (JSON.parse(await d.readFile(o.file, "utf8")).token !== o.token) throw new f("closed", "持久任务存储写入锁已失效");
474
- const A = M(a, m), h = s.records.get(A);
475
- if ((h?.record.revision ?? null) !== y) return;
476
- me(h?.record, g);
477
- const p = O(g), k = Buffer.byteLength(p, "utf8"), I = s.bytes - (h?.bytes ?? 0) + k;
478
- if (I > n || !h && s.records.size >= r) throw new f("capacity", "持久任务容量已满,请归档旧任务或扩大显式预算");
479
- try {
480
- await Ae(t, A, p);
481
- } catch (C) {
482
- throw await R(N.join(t, A)) === p && (s.records.set(A, { record: g, bytes: k }), s.bytes = I), C;
631
+ readTombstone: async (p, f) => {
632
+ m(), T(p, f), await i;
633
+ const c = r.tombstones.get(O(p, f));
634
+ return c ? j(c.value) : void 0;
635
+ },
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 = $;
647
+ }), !0;
648
+ });
649
+ },
650
+ prune: async (p) => {
651
+ const f = Ee(p);
652
+ return h(async () => {
653
+ 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) {
657
+ 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;
662
+ }), c.archived++;
483
663
  }
484
- s.records.set(A, { record: g, bytes: k }), s.bytes = I, w = !0;
664
+ if (c.expired) {
665
+ const d = await l.open(t, "r");
666
+ try {
667
+ await d.sync();
668
+ } finally {
669
+ await d.close();
670
+ }
671
+ }
672
+ return c;
485
673
  });
486
- return u = S.catch(() => {
487
- }), await S, w;
488
674
  },
489
675
  close: async () => {
490
- if (i) return;
491
- i = !0, await u, await o.handle.close();
492
- const a = await R(o.file);
493
- a && JSON.parse(a).token === o.token && await d.unlink(o.file);
676
+ if (s) return;
677
+ 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);
494
680
  }
495
681
  };
496
682
  }
497
- function ve(e) {
683
+ function Le(e) {
498
684
  const t = e.filename ?? e.workerUrl;
499
685
  if (!t || e.filename && e.workerUrl) throw new TypeError("请且仅请指定 filename 或 workerUrl");
500
686
  return le(() => {
501
- const r = new L(t, e.workerOptions);
687
+ const n = new H(t, e.workerOptions);
502
688
  return {
503
- postMessage: (n) => r.postMessage(n),
504
- terminate: () => r.terminate(),
505
- subscribe: (n, o) => {
506
- const s = (i) => o(new Error(`报表 Worker 在响应前退出(code ${i})`));
507
- return r.on("message", n), r.on("error", o), r.on("messageerror", o), r.on("exit", s), () => {
508
- r.off("message", n), r.off("error", o), r.off("messageerror", o), r.off("exit", s);
689
+ postMessage: (o) => n.postMessage(o),
690
+ terminate: () => n.terminate(),
691
+ subscribe: (o, r) => {
692
+ const s = (i) => r(new Error(`报表 Worker 在响应前退出(code ${i})`));
693
+ return n.on("message", o), n.on("error", r), n.on("messageerror", r), n.on("exit", s), () => {
694
+ n.off("message", o), n.off("error", r), n.off("messageerror", r), n.off("exit", s);
509
695
  };
510
696
  }
511
697
  };
512
698
  }, e);
513
699
  }
514
- function Ie(e) {
515
- const t = K;
700
+ function _e(e) {
701
+ const t = C;
516
702
  if (!t) throw new Error("serveNodeReportWorker 只能在 worker_threads 中调用");
517
- const r = (n) => {
518
- ae(n) && ce(e, n, (o) => t.postMessage({ protocol: x, id: n.id, type: "event", event: o })).then((o) => t.postMessage(o, fe(o)));
703
+ 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)));
519
705
  };
520
- return t.on("message", r), () => t.off("message", r);
706
+ return t.on("message", n), () => t.off("message", n);
521
707
  }
522
- function Me(e) {
708
+ function Ce(e) {
523
709
  return W("sha256").update(e).digest("hex");
524
710
  }
525
711
  export {
526
- J as ReportWorkerError,
527
- ve as createNodeReportExecutor,
528
- Oe as openFileReportJobStore,
529
- Me as reportArtifactSha256,
530
- Ie as serveNodeReportWorker
712
+ B as ReportWorkerError,
713
+ Le as createNodeReportExecutor,
714
+ ze as openFileReportJobStore,
715
+ Ce as reportArtifactSha256,
716
+ _e as serveNodeReportWorker
531
717
  };