@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.
- package/README.md +11 -7
- package/dist/ExcelBindingWizard-CjIiVox-.cjs +1 -0
- package/dist/ExcelBindingWizard-Dxm-K5HL.js +1240 -0
- package/dist/ParamEditor-D-Hf5xfO.cjs +1 -0
- package/dist/ParamEditor-DRGxzxeO.js +381 -0
- package/dist/ReportBatchPanel-BYgg0EDB.cjs +1 -0
- package/dist/ReportBatchPanel-Bby5yLzU.js +287 -0
- package/dist/ReportPreview-DWXROHBP.cjs +6 -0
- package/dist/ReportPreview-DiNXhQI0.js +4138 -0
- package/dist/ReportTemplateLibrary-C6CO7YCT.cjs +1 -0
- package/dist/ReportTemplateLibrary-DfzDXRvr.js +260 -0
- package/dist/RuleEditor-C2QsOHOs.cjs +1 -0
- package/dist/RuleEditor-D9wQHrkf.js +2024 -0
- package/dist/TemplateReviewPanel-BKofGrV9.js +222 -0
- package/dist/TemplateReviewPanel-DwtOcLue.cjs +1 -0
- package/dist/analytics.cjs +1 -1
- package/dist/analytics.d.cts +4 -0
- package/dist/analytics.d.ts +4 -0
- package/dist/analytics.js +40 -39
- package/dist/{assets-ahTRUXRk.cjs → assets-Bu6UohJx.cjs} +1 -1
- package/dist/{assets-DDsfEi8R.js → assets-DegqDNqY.js} +1 -1
- package/dist/batch-Bt3Fd27Z.cjs +1 -0
- package/dist/batch-mRqhhhjt.js +364 -0
- package/dist/{capabilities-Cm9hZ3uV.js → capabilities-CK_7hizc.js} +16 -16
- package/dist/capabilities-CsZ-pNHR.cjs +1 -0
- package/dist/computed-Bvk0W15F.js +521 -0
- package/dist/computed-CGV2a809.cjs +1 -0
- package/dist/config-B612mw0x.js +525 -0
- package/dist/config-BRoLo2oj.cjs +1 -0
- package/dist/designer.cjs +2 -2
- package/dist/designer.d.cts +695 -50
- package/dist/designer.d.ts +695 -50
- package/dist/designer.js +2213 -1748
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +205 -6
- package/dist/index.d.ts +205 -6
- package/dist/index.js +808 -1033
- package/dist/injection-keys-Db_DyLkm.cjs +1 -0
- package/dist/injection-keys-e85udZCp.js +7 -0
- package/dist/list-cell-BuYn4tGF.cjs +1 -0
- package/dist/list-cell-ClFra1zS.js +173 -0
- package/dist/matrix-DVyWiYsd.cjs +1 -0
- package/dist/matrix-yZsGnldA.js +227 -0
- package/dist/param-validation-BlHHXs6u.js +153 -0
- package/dist/param-validation-DCK039V1.cjs +1 -0
- package/dist/pdf.cjs +49 -49
- package/dist/pdf.d.cts +31 -1
- package/dist/pdf.d.ts +31 -1
- package/dist/pdf.js +4797 -4650
- package/dist/plugin-BDTU4D94.cjs +1 -0
- package/dist/plugin-Cd5G2QQn.js +22 -0
- package/dist/region-binding-workflow-CXDmt9Bs.js +977 -0
- package/dist/region-binding-workflow-DhQvu1co.cjs +3 -0
- package/dist/{report-params-B_VCihAh.js → report-params-B44imUd4.js} +1 -1
- package/dist/{report-params-CjWrjPl6.cjs → report-params-SJfhKgaX.cjs} +1 -1
- package/dist/server/node.d.cts +48 -5
- package/dist/server/node.d.ts +48 -5
- package/dist/server-node.cjs +1 -1
- package/dist/server-node.js +503 -317
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +252 -4
- package/dist/server.d.ts +252 -4
- package/dist/server.js +567 -469
- package/dist/style.css +1 -1
- package/dist/template-registry-WNXdkiET.js +506 -0
- package/dist/template-registry-ukBGlm8N.cjs +1 -0
- package/dist/template-review-BXp2oyqg.cjs +1 -0
- package/dist/template-review-BdcXSYbx.js +1616 -0
- package/dist/tree-BX380Rr7.cjs +1 -0
- package/dist/tree-CqcQ99NM.js +172 -0
- package/dist/useLocalDraft-C07SYRnC.js +11 -0
- package/dist/useLocalDraft-Yiw1wFgI.cjs +1 -0
- package/dist/{validate-DWPF7icl.js → validate-7s0yn6ii.js} +26 -26
- package/dist/validate-DsRiNw8h.cjs +1 -0
- package/dist/vue/async.d.cts +118 -6
- package/dist/vue/async.d.ts +118 -6
- package/dist/vue/index.d.cts +177 -11
- package/dist/vue/index.d.ts +177 -11
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +5 -5
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +116 -113
- package/dist/{import-template-CNMLJSQw.js → workbook-session-BKOTwcoq.js} +4290 -4227
- package/dist/{import-template-CpxunKVp.cjs → workbook-session-CLYLhZWu.cjs} +17 -17
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +9 -2
- package/dist/worker.d.ts +9 -2
- package/dist/worker.js +1 -1
- package/dist/xlsx.cjs +4 -2
- package/dist/xlsx.d.cts +159 -3
- package/dist/xlsx.d.ts +159 -3
- package/dist/xlsx.js +354 -192
- package/package.json +1 -1
- package/dist/ExcelBindingWizard-DiaxvWpQ.cjs +0 -1
- package/dist/ExcelBindingWizard-RLJIXKKG.js +0 -816
- package/dist/ReportPreview-B5ZNEasW.js +0 -4439
- package/dist/ReportPreview-DRtVPUYo.cjs +0 -6
- package/dist/RuleEditor-CskN5Fr3.cjs +0 -1
- package/dist/RuleEditor-CtJFzKuY.js +0 -1578
- package/dist/TemplateReviewPanel-C_Lmzis6.cjs +0 -1
- package/dist/TemplateReviewPanel-Cn32OY4_.js +0 -173
- package/dist/binding-preview-B5834rml.cjs +0 -2
- package/dist/binding-preview-ChXjN5L5.js +0 -649
- package/dist/capabilities-DYzWL7KS.cjs +0 -1
- package/dist/matrix-CNPDJxED.js +0 -745
- package/dist/matrix-Div9Ilh3.cjs +0 -1
- package/dist/param-validation-BWNjLcN0.js +0 -116
- package/dist/param-validation-CiTxFeZ8.cjs +0 -1
- package/dist/plugin-BWwIgZXV.js +0 -25
- package/dist/plugin-Dg-J1Rbm.cjs +0 -1
- package/dist/template-registry-CHMYZ7SD.cjs +0 -1
- package/dist/template-registry-R61AMCr0.js +0 -433
- package/dist/template-review-hvWWQFsi.js +0 -1027
- package/dist/template-review-jEcOfmGr.cjs +0 -1
- package/dist/validate-BDiMqkJC.cjs +0 -1
package/dist/server-node.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { parentPort as
|
|
2
|
-
import { randomUUID as
|
|
3
|
-
import { promises as
|
|
4
|
-
import
|
|
5
|
-
function
|
|
6
|
-
if (!
|
|
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
|
|
9
|
-
|
|
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
|
|
15
|
-
e.editable !== void 0 && typeof e.editable != "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
|
|
18
|
-
|
|
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,
|
|
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
|
-
|
|
23
|
+
n.push({ path: t, message: "业务来源应为对象" });
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const
|
|
27
|
-
for (const s of ["datasetId", ...
|
|
28
|
-
(typeof
|
|
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 =
|
|
31
|
-
i === void 0 && !(
|
|
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
|
-
|
|
33
|
+
r.sourceToken !== void 0 && typeof r.sourceToken != "string" && n.push({ path: `${t}.sourceToken`, message: "来源令牌应为字符串" });
|
|
34
34
|
}
|
|
35
|
-
const
|
|
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
|
|
45
|
+
function N(e) {
|
|
46
46
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
(typeof
|
|
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
|
|
52
|
+
function Q(e, t, n) {
|
|
53
53
|
if (e !== void 0) {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
54
|
+
const o = `${t}.table`;
|
|
55
|
+
if (!N(e)) n.push({ path: o, message: "逻辑表来源应为对象" });
|
|
56
56
|
else {
|
|
57
|
-
F(e.source, `${
|
|
58
|
-
const
|
|
59
|
-
["header", "body", "group-header", "subtotal", "grand-total"].includes(
|
|
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) || (
|
|
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
|
|
65
|
+
function Y(e, t, n, o) {
|
|
66
66
|
if (e !== void 0)
|
|
67
|
-
if (
|
|
68
|
-
|
|
67
|
+
if (!N(e) || !Array.isArray(e.cells))
|
|
68
|
+
n.push({ path: `${t}.grid.cells`, message: "grid.cells 应为二维数组" });
|
|
69
69
|
else {
|
|
70
|
-
const
|
|
71
|
-
|
|
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
|
-
|
|
73
|
+
n.push({ path: `${t}.grid.cells.${i}`, message: "行应为数组" });
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
s.forEach((
|
|
77
|
-
if (
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
|
|
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
|
-
|
|
84
|
-
D(
|
|
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
|
|
91
|
-
e !== void 0 && (Array.isArray(e) ? e.forEach((
|
|
92
|
-
(
|
|
93
|
-
}) :
|
|
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,
|
|
96
|
-
if (
|
|
97
|
-
|
|
95
|
+
function D(e, t, n, o = []) {
|
|
96
|
+
if (!N(e)) {
|
|
97
|
+
n.push({ path: t, message: "组件应为对象" });
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
typeof
|
|
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(
|
|
103
|
+
message: `未知组件类型 ${JSON.stringify(r)},将以兜底方式渲染`
|
|
104
104
|
});
|
|
105
105
|
for (const s of ["leftMm", "topMm", "widthMm", "heightMm"])
|
|
106
|
-
|
|
107
|
-
typeof e.leftMm == "number" && e.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 &&
|
|
110
|
-
|
|
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
|
|
113
|
-
if (
|
|
114
|
-
|
|
112
|
+
function te(e, t, n, o = []) {
|
|
113
|
+
if (!N(e)) {
|
|
114
|
+
n.push({ path: t, message: "页应为对象" });
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
|
-
const
|
|
118
|
-
(typeof
|
|
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
|
-
(
|
|
122
|
-
) :
|
|
121
|
+
(m, h) => D(m, `${t}.components.${h}`, n, o)
|
|
122
|
+
) : n.push({ path: `${t}.components`, message: "components 应为数组" });
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
const t = [],
|
|
126
|
-
if (!Array.isArray(
|
|
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
|
-
|
|
132
|
+
o.forEach((s, i) => te(s, `$.pages.${i}`, t, n)), o.length > 2e3 && n.push({
|
|
133
133
|
path: "$.pages",
|
|
134
|
-
message: `页数异常大(${
|
|
134
|
+
message: `页数异常大(${o.length} 页),渲染与打印耗时可能显著增加`
|
|
135
135
|
});
|
|
136
|
-
const
|
|
137
|
-
(s, i) => s + (
|
|
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
|
-
|
|
140
|
+
r > 5e4 && n.push({
|
|
141
141
|
path: "$.pages",
|
|
142
|
-
message: `组件总数异常大(${
|
|
142
|
+
message: `组件总数异常大(${r} 个),可能触发浏览器性能限制`
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
return { ok: t.length === 0, errors: t, warnings:
|
|
145
|
+
return { ok: t.length === 0, errors: t, warnings: n };
|
|
146
146
|
}
|
|
147
|
-
const
|
|
148
|
-
class
|
|
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
|
|
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
|
|
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
|
|
163
|
-
return
|
|
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
|
|
166
|
-
|
|
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
|
|
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
|
|
175
|
-
const
|
|
176
|
-
typeof
|
|
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
|
|
181
|
-
const t =
|
|
182
|
-
if (!
|
|
183
|
-
for (const
|
|
184
|
-
for (const
|
|
185
|
-
return Array.isArray(e.componentPath) && e.componentPath.every((
|
|
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
|
|
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(
|
|
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
|
|
199
|
+
function fe(e) {
|
|
200
200
|
if (!e || typeof e != "object") return !1;
|
|
201
201
|
const t = e;
|
|
202
|
-
return t.protocol ===
|
|
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
|
|
204
|
+
async function ue(e, t, n) {
|
|
205
205
|
try {
|
|
206
|
-
const
|
|
207
|
-
return { protocol:
|
|
208
|
-
} catch (
|
|
209
|
-
return { protocol:
|
|
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
|
|
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
|
|
217
|
-
if (!
|
|
218
|
-
for (const
|
|
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
|
|
222
|
-
function
|
|
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
|
|
226
|
+
function ye(e, t) {
|
|
227
227
|
if (!e || typeof e != "object") return;
|
|
228
|
-
const
|
|
229
|
-
return
|
|
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
|
|
233
|
-
if (!Number.isFinite(
|
|
234
|
-
const
|
|
235
|
-
let
|
|
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
|
-
|
|
238
|
-
} catch (
|
|
239
|
-
|
|
237
|
+
b = e();
|
|
238
|
+
} catch (y) {
|
|
239
|
+
u(y);
|
|
240
240
|
return;
|
|
241
241
|
}
|
|
242
|
-
const
|
|
243
|
-
let
|
|
244
|
-
},
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
() =>
|
|
248
|
-
(
|
|
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
|
-
},
|
|
251
|
-
const
|
|
252
|
-
if (!(!
|
|
253
|
-
if ("type" in
|
|
254
|
-
const
|
|
255
|
-
|
|
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
|
-
|
|
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 (
|
|
263
|
-
|
|
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",
|
|
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:
|
|
269
|
-
|
|
268
|
+
const { onEvent: y, signal: w, ...$ } = s;
|
|
269
|
+
b.postMessage({ protocol: E, id: k, operation: r, input: $ });
|
|
270
270
|
}
|
|
271
|
-
} catch (
|
|
272
|
-
|
|
271
|
+
} catch (y) {
|
|
272
|
+
d(y);
|
|
273
273
|
}
|
|
274
274
|
});
|
|
275
|
-
return { prepare: (
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
|
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
|
|
284
|
-
}
|
|
285
|
-
function
|
|
286
|
-
const t = Array.isArray(e),
|
|
287
|
-
if (
|
|
288
|
-
if (Object.getOwnPropertySymbols(e).length) throw new
|
|
289
|
-
if (Object.getOwnPropertyNames(e).filter((s) => !(t && s === "length")).length !==
|
|
290
|
-
if (t && (
|
|
291
|
-
return
|
|
292
|
-
}
|
|
293
|
-
function
|
|
294
|
-
const
|
|
295
|
-
if (["__proto__", "prototype", "constructor"].includes(t) ||
|
|
296
|
-
return
|
|
297
|
-
}
|
|
298
|
-
function
|
|
299
|
-
const
|
|
300
|
-
if (!Number.isSafeInteger(
|
|
301
|
-
let
|
|
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
|
|
304
|
-
if (++
|
|
305
|
-
if (typeof
|
|
306
|
-
if (s +=
|
|
307
|
-
return
|
|
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 (
|
|
310
|
-
if (!
|
|
311
|
-
const
|
|
312
|
-
i.add(
|
|
313
|
-
const
|
|
314
|
-
for (const
|
|
315
|
-
if (s +=
|
|
316
|
-
|
|
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(
|
|
413
|
+
return i.delete(u), k ? Array.from({ length: u.length }, (c, d) => f[String(d)]) : f;
|
|
319
414
|
}
|
|
320
|
-
const
|
|
321
|
-
if (
|
|
322
|
-
return
|
|
415
|
+
const h = JSON.stringify(m(e, 0));
|
|
416
|
+
if (h.length > o) throw new a("input", "任务序列化数据超过字符预算");
|
|
417
|
+
return h;
|
|
323
418
|
}
|
|
324
|
-
function
|
|
419
|
+
function j(e) {
|
|
325
420
|
return JSON.parse(JSON.stringify(e));
|
|
326
421
|
}
|
|
327
|
-
function z(e, t,
|
|
328
|
-
if (
|
|
329
|
-
if (![e.createdAt, e.updatedAt, e.attempt].every((
|
|
330
|
-
if (e.lease && (!e.lease.owner || !Number.isSafeInteger(e.lease.expiresAt))) throw new
|
|
331
|
-
if (!e.request || typeof e.request.kind != "string" || !e.request.kind.trim() || e.request.kind.length > 128) throw new
|
|
332
|
-
|
|
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
|
|
335
|
-
if (e && (e.createdAt !== t.createdAt ||
|
|
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
|
|
432
|
+
function ve(e, t) {
|
|
338
433
|
return e.status === "queued" || e.status === "running" && (e.lease?.expiresAt ?? 0) <= t;
|
|
339
434
|
}
|
|
340
|
-
function
|
|
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
|
|
483
|
+
function O(e, t) {
|
|
344
484
|
return W("sha256").update(JSON.stringify([e, t])).digest("hex") + ".json";
|
|
345
485
|
}
|
|
346
|
-
async function
|
|
486
|
+
async function J(e) {
|
|
347
487
|
try {
|
|
348
|
-
return await
|
|
488
|
+
return await l.readFile(e, "utf8");
|
|
349
489
|
} catch (t) {
|
|
350
|
-
if (
|
|
490
|
+
if (I(t) === "ENOENT") return;
|
|
351
491
|
throw t;
|
|
352
492
|
}
|
|
353
493
|
}
|
|
354
|
-
async function
|
|
355
|
-
const
|
|
356
|
-
if (
|
|
357
|
-
let
|
|
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
|
-
|
|
499
|
+
o = JSON.parse(n);
|
|
360
500
|
} catch {
|
|
361
|
-
throw new
|
|
501
|
+
throw new a("conflict", "任务锁尚未完整写入或已损坏,拒绝自动移除");
|
|
362
502
|
}
|
|
363
|
-
if (!
|
|
503
|
+
if (!o || !Number.isSafeInteger(o.pid) || o.pid < 1) throw new a("conflict", "任务锁身份无效,拒绝自动移除");
|
|
364
504
|
try {
|
|
365
|
-
process.kill(
|
|
366
|
-
} catch (
|
|
367
|
-
if (
|
|
368
|
-
await
|
|
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
|
|
511
|
+
throw r;
|
|
372
512
|
}
|
|
373
|
-
throw new
|
|
513
|
+
throw new a("conflict", "任务目录的写入进程仍在运行");
|
|
374
514
|
}
|
|
375
|
-
async function
|
|
376
|
-
if (!t) throw new
|
|
377
|
-
const
|
|
378
|
-
let
|
|
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
|
-
|
|
381
|
-
} catch (
|
|
382
|
-
throw
|
|
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
|
|
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
|
|
527
|
+
await o.close(), await l.unlink(n);
|
|
388
528
|
}
|
|
389
529
|
}
|
|
390
|
-
async function
|
|
391
|
-
const
|
|
392
|
-
let
|
|
530
|
+
async function Je(e, t) {
|
|
531
|
+
const n = v.join(e, ".writer-lock"), o = q();
|
|
532
|
+
let r;
|
|
393
533
|
try {
|
|
394
|
-
|
|
534
|
+
r = await l.open(n, "wx", 384);
|
|
395
535
|
} catch (s) {
|
|
396
|
-
if (
|
|
397
|
-
|
|
536
|
+
if (I(s) !== "EEXIST") throw s;
|
|
537
|
+
r = await je(n, t);
|
|
398
538
|
}
|
|
399
539
|
try {
|
|
400
|
-
await
|
|
540
|
+
await r.writeFile(JSON.stringify({ pid: process.pid, token: o })), await r.sync();
|
|
401
541
|
} catch (s) {
|
|
402
|
-
throw await
|
|
542
|
+
throw await r.close(), await l.unlink(n).catch(() => {
|
|
403
543
|
}), s;
|
|
404
544
|
}
|
|
405
|
-
return { file:
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
|
571
|
+
return r;
|
|
422
572
|
}
|
|
423
|
-
async function
|
|
424
|
-
const
|
|
573
|
+
async function qe(e, t, n) {
|
|
574
|
+
const o = v.join(e, `.pending-${q()}`);
|
|
425
575
|
try {
|
|
426
|
-
const
|
|
576
|
+
const r = await l.open(o, "wx", 384);
|
|
427
577
|
try {
|
|
428
|
-
await
|
|
578
|
+
await r.writeFile(n), await r.sync();
|
|
429
579
|
} finally {
|
|
430
|
-
await
|
|
580
|
+
await r.close();
|
|
431
581
|
}
|
|
432
|
-
await
|
|
433
|
-
const s = await
|
|
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
|
|
441
|
-
if (
|
|
590
|
+
await l.unlink(o).catch((r) => {
|
|
591
|
+
if (I(r) !== "ENOENT") throw r;
|
|
442
592
|
});
|
|
443
593
|
}
|
|
444
594
|
}
|
|
445
|
-
async function
|
|
446
|
-
const t =
|
|
447
|
-
|
|
448
|
-
await
|
|
449
|
-
|
|
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
|
-
|
|
453
|
-
} catch (
|
|
454
|
-
throw await o.handle.close(), await
|
|
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
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
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 (
|
|
462
|
-
|
|
463
|
-
const
|
|
464
|
-
return
|
|
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
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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
|
-
|
|
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 (
|
|
491
|
-
|
|
492
|
-
const
|
|
493
|
-
|
|
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
|
|
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
|
|
687
|
+
const n = new H(t, e.workerOptions);
|
|
502
688
|
return {
|
|
503
|
-
postMessage: (
|
|
504
|
-
terminate: () =>
|
|
505
|
-
subscribe: (
|
|
506
|
-
const s = (i) =>
|
|
507
|
-
return
|
|
508
|
-
|
|
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
|
|
515
|
-
const t =
|
|
700
|
+
function _e(e) {
|
|
701
|
+
const t = C;
|
|
516
702
|
if (!t) throw new Error("serveNodeReportWorker 只能在 worker_threads 中调用");
|
|
517
|
-
const
|
|
518
|
-
|
|
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",
|
|
706
|
+
return t.on("message", n), () => t.off("message", n);
|
|
521
707
|
}
|
|
522
|
-
function
|
|
708
|
+
function Ce(e) {
|
|
523
709
|
return W("sha256").update(e).digest("hex");
|
|
524
710
|
}
|
|
525
711
|
export {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
712
|
+
B as ReportWorkerError,
|
|
713
|
+
Le as createNodeReportExecutor,
|
|
714
|
+
ze as openFileReportJobStore,
|
|
715
|
+
Ce as reportArtifactSha256,
|
|
716
|
+
_e as serveNodeReportWorker
|
|
531
717
|
};
|