@agile-team/mach-report 2.16.0 → 2.18.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 +25 -12
- package/dist/{ExcelBindingWizard-CP6h2x1f.cjs → ExcelBindingWizard-Czn3C2yE.cjs} +1 -1
- package/dist/{ExcelBindingWizard-HhB3hAJE.js → ExcelBindingWizard-DMGZj6I6.js} +3 -3
- package/dist/ParamEditor-KzDQvbHY.js +732 -0
- package/dist/ParamEditor-oDfD8LgE.cjs +1 -0
- package/dist/{ReportBatchPanel-ruxcbfY6.js → ReportBatchPanel-BJK7PvZ4.js} +39 -39
- package/dist/ReportBatchPanel-DnmNRssu.cjs +1 -0
- package/dist/ReportParamPanel-mQkeN70Q.js +1020 -0
- package/dist/ReportParamPanel-sOANVRz-.cjs +1 -0
- package/dist/ReportPreview-BxWWTUL5.js +5583 -0
- package/dist/ReportPreview-Yf99omi3.cjs +6 -0
- package/dist/{ReportTemplateLibrary-DcwrH-63.js → ReportTemplateLibrary-BFjB08Wu.js} +1 -1
- package/dist/{ReportTemplateLibrary-BDlNT8JN.cjs → ReportTemplateLibrary-BO42QnWd.cjs} +1 -1
- package/dist/RuleEditor-CqxT1a-W.js +2337 -0
- package/dist/RuleEditor-D7YWigD9.cjs +1 -0
- package/dist/{TemplateOutlinePanel-CGrT5DFN.cjs → TemplateOutlinePanel-B0XX350V.cjs} +1 -1
- package/dist/{TemplateOutlinePanel-SXCjaPKR.js → TemplateOutlinePanel-zG0DrsIB.js} +2 -2
- package/dist/{TemplateReusePanel-6Z3wRFz8.cjs → TemplateReusePanel-BD0HSKp_.cjs} +1 -1
- package/dist/{TemplateReusePanel-lHLOS9Wn.js → TemplateReusePanel-Czwe5GbC.js} +2 -2
- package/dist/{TemplateReviewPanel-Dpk7sLcF.cjs → TemplateReviewPanel-CA5sdffM.cjs} +1 -1
- package/dist/{TemplateReviewPanel-CJ9PLc48.js → TemplateReviewPanel-NhmQI65C.js} +2 -2
- package/dist/analytics.cjs +1 -1
- package/dist/analytics.d.cts +163 -42
- package/dist/analytics.d.ts +163 -42
- package/dist/analytics.js +76 -141
- package/dist/artifact-integrity.json +110 -108
- package/dist/assets-2eC3mOcV.js +232 -0
- package/dist/assets-B0Hxn4l6.cjs +1 -0
- package/dist/{auto-uVBjX1j5.cjs → auto-B0EZFIK1.cjs} +1 -1
- package/dist/{auto-YR7a4BtF.js → auto-BlchZ1b8.js} +10 -10
- package/dist/{batch-WzDIXJAt.js → batch-DGCt44XM.js} +1 -1
- package/dist/{batch-z6Aw5GEY.cjs → batch-DYcokH4v.cjs} +1 -1
- package/dist/charts-Dlv8j2AG.js +141 -0
- package/dist/charts-aCtoswXq.cjs +1 -0
- package/dist/codes.cjs +9 -9
- package/dist/codes.d.cts +54 -0
- package/dist/codes.d.ts +54 -0
- package/dist/codes.js +12097 -13668
- package/dist/column-visual-BpgQVWwT.js +238 -0
- package/dist/column-visual-CtYxnBCP.cjs +1 -0
- package/dist/component-tree-6TV7W6Yj.cjs +1 -0
- package/dist/component-tree-CvW4lzpv.js +67 -0
- package/dist/computed-4TnxzgIh.cjs +1 -0
- package/dist/computed-C8NRZQss.js +739 -0
- package/dist/data-bar-Ce38juRZ.cjs +1 -0
- package/dist/data-bar-PtjXhMgN.js +9 -0
- package/dist/dataset-DL83majE.js +161 -0
- package/dist/dataset-IrlXbUvh.cjs +1 -0
- package/dist/designer--TKECSEc.cjs +2 -0
- package/dist/designer-d6hJS41w.js +5683 -0
- package/dist/designer.cjs +1 -1
- package/dist/designer.d.cts +835 -45
- package/dist/designer.d.ts +835 -45
- package/dist/designer.js +23 -20
- package/dist/{encoding-BYF9ZTl9.cjs → encoding-B--eZpp1.cjs} +1 -1
- package/dist/{encoding-BOGq4qYL.js → encoding-mctOLocI.js} +2 -2
- package/dist/{font-loader-EKLzOJxf.cjs → font-loader-DBBJ5KE9.cjs} +1 -1
- package/dist/{font-loader-CzI1GuBc.js → font-loader-DW8tIaNp.js} +1 -1
- package/dist/index-CPh6tqge.js +1575 -0
- package/dist/index-CUNw7dL9.cjs +1 -0
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +534 -16
- package/dist/index.d.ts +534 -16
- package/dist/index.js +1393 -955
- package/dist/json-snapshot-By4ZVVUt.js +1967 -0
- package/dist/json-snapshot-jiXff4lc.cjs +2 -0
- package/dist/matrix-0hywp0-F.cjs +1 -0
- package/dist/matrix-Dy-tyY7E.js +381 -0
- package/dist/param-validation-C-8sRJLq.cjs +1 -0
- package/dist/param-validation-CnDEd2l-.js +333 -0
- package/dist/{pdf-DJ5S6ukC.js → pdf-CKROKygt.js} +1845 -1845
- package/dist/{pdf-ByVCb1i6.cjs → pdf-DqyxJ96U.cjs} +47 -47
- package/dist/pdf.cjs +1 -1
- package/dist/pdf.d.cts +66 -0
- package/dist/pdf.d.ts +66 -0
- package/dist/pdf.js +2 -2
- package/dist/{plugin-C2j5_mhx.js → plugin-ByjF2kiV.js} +5 -5
- package/dist/{plugin-Dr39GBRG.cjs → plugin-DM1M2wlI.cjs} +1 -1
- package/dist/prefill-B8H9qwE4.js +371 -0
- package/dist/prefill-D7EswyTI.cjs +1 -0
- package/dist/{prepared-DqtpvRTn.js → prepared-BE-4jfX5.js} +2 -2
- package/dist/{prepared-DdrjLC7L.cjs → prepared-CGVphji3.cjs} +1 -1
- package/dist/{protocol-BzwMP4Vw.cjs → protocol-ByRVzzQG.cjs} +1 -1
- package/dist/{protocol-kt4Iy6-3.js → protocol-Cr81vFSQ.js} +3 -3
- package/dist/{record-bindings-CZWBJ1fU.js → record-bindings-DEJtmo3p.js} +67 -107
- package/dist/record-bindings-ehjnCDHt.cjs +1 -0
- package/dist/{region-binding-workflow-CWNvIjkV.js → region-binding-workflow-CBg0l_tj.js} +2 -2
- package/dist/{region-binding-workflow-CqSMxQ4p.cjs → region-binding-workflow-D05tOYn3.cjs} +1 -1
- package/dist/report-encoding-worker.cjs +1 -1
- package/dist/report-encoding-worker.js +1 -1
- package/dist/{report-params-B1RzkhJj.js → report-params-D9tBuM9B.js} +1 -1
- package/dist/{report-params-WDGrA4oP.cjs → report-params-VTg8MoCp.cjs} +1 -1
- package/dist/runtime-CDA6d263.cjs +1 -0
- package/dist/runtime-CEMvybO7.js +170 -0
- package/dist/sbom.cdx.json +1 -1
- package/dist/server/node.d.cts +121 -7
- package/dist/server/node.d.ts +121 -7
- package/dist/server-node.cjs +4 -4
- package/dist/server-node.js +3446 -2115
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +417 -29
- package/dist/server.d.ts +417 -29
- package/dist/server.js +787 -544
- package/dist/sha256-BDQ1Qk7A.js +158 -0
- package/dist/sha256-DgZAKXqI.cjs +1 -0
- package/dist/style.css +1 -1
- package/dist/template-bindings-Cg5oBLFT.cjs +1 -0
- package/dist/template-bindings-TKnXM7ll.js +62 -0
- package/dist/{template-catalog-BtR2JmCL.js → template-catalog-CmbWOJqy.js} +16 -16
- package/dist/template-catalog-Utu4GP09.cjs +1 -0
- package/dist/{template-fragments-BVsbxs4a.cjs → template-fragments-C_zSHJAa.cjs} +1 -1
- package/dist/{template-fragments-By0aZC1D.js → template-fragments-DWgo9tlZ.js} +2 -2
- package/dist/{template-outline-BwRV_eRo.cjs → template-outline-DWkzZXVC.cjs} +1 -1
- package/dist/{template-outline-cnWfT_LK.js → template-outline-DiADphlq.js} +1 -1
- package/dist/{template-registry-Cw3vRTX2.js → template-registry-BIhIHOab.js} +319 -314
- package/dist/template-registry-DzWswQI5.cjs +1 -0
- package/dist/vue/async.d.cts +636 -35
- package/dist/vue/async.d.ts +636 -35
- package/dist/vue/index.d.cts +746 -67
- package/dist/vue/index.d.ts +746 -67
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +94 -89
- package/dist/{workbook-session-Cbts-22R.cjs → workbook-session-B94EwVa_.cjs} +1 -1
- package/dist/{workbook-session-BeSO8PFB.js → workbook-session-BoScoOg-.js} +2 -2
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +75 -7
- package/dist/worker.d.ts +75 -7
- package/dist/worker.js +4 -4
- package/dist/xlsx.cjs +4 -4
- package/dist/xlsx.d.cts +208 -15
- package/dist/xlsx.d.ts +208 -15
- package/dist/xlsx.js +288 -252
- package/package.json +1 -1
- package/dist/ParamEditor-CUQLgoxa.cjs +0 -1
- package/dist/ParamEditor-OKesP_nO.js +0 -594
- package/dist/ReportBatchPanel-cZCAMAwH.cjs +0 -1
- package/dist/ReportPreview-BcDKCLiK.js +0 -4834
- package/dist/ReportPreview-Bk9nLfO9.cjs +0 -6
- package/dist/RuleEditor-BX5S8RSF.cjs +0 -1
- package/dist/RuleEditor-CGl9XY2s.js +0 -2037
- package/dist/assets-CqIbfbTr.js +0 -126
- package/dist/assets-e4YSke8n.cjs +0 -1
- package/dist/capabilities-DDwXr_cA.js +0 -103
- package/dist/capabilities-DNLyZdNw.cjs +0 -1
- package/dist/component-tree-Ca6YYfHq.js +0 -61
- package/dist/component-tree-DkGLEfZC.cjs +0 -1
- package/dist/computed-C-4C2S5h.js +0 -521
- package/dist/computed-CGV2a809.cjs +0 -1
- package/dist/config-Dg_o8e7m.cjs +0 -1
- package/dist/config-XQ4qrQ7Q.js +0 -844
- package/dist/dataset-BkRmwgeJ.cjs +0 -1
- package/dist/dataset-H5pFuQGU.js +0 -121
- package/dist/designer-BfQSahxq.js +0 -5163
- package/dist/designer-CPPdeM5_.cjs +0 -2
- package/dist/diagnostic-notification-B9K9We3h.cjs +0 -1
- package/dist/diagnostic-notification-qGAYZdkB.js +0 -7
- package/dist/drill-CsdjgkRM.cjs +0 -1
- package/dist/drill-DIGsZfyB.js +0 -145
- package/dist/json-snapshot-D6ioHth9.js +0 -1702
- package/dist/json-snapshot-DknkjvxP.cjs +0 -2
- package/dist/matrix-CGRGkn5s.js +0 -112
- package/dist/matrix-gEO7ZM_u.cjs +0 -1
- package/dist/param-validation-C3HlcLLO.cjs +0 -1
- package/dist/param-validation-Do7Eg8Zv.js +0 -181
- package/dist/record-bindings-DUX1VMlR.cjs +0 -1
- package/dist/runtime-BjKBI530.js +0 -168
- package/dist/runtime-CBFEPKEs.cjs +0 -1
- package/dist/sha256-BshdOkCC.cjs +0 -1
- package/dist/sha256-DTG-Gq8i.js +0 -157
- package/dist/template-bindings-C2SpvsMU.js +0 -58
- package/dist/template-bindings-CEtWyiLX.cjs +0 -1
- package/dist/template-catalog-C2NLdrwB.cjs +0 -1
- package/dist/template-registry-C62vpv4a.cjs +0 -1
- package/dist/tree-BX380Rr7.cjs +0 -1
- package/dist/tree-CjVZLRw7.js +0 -172
package/dist/server.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { R as
|
|
3
|
-
import {
|
|
4
|
-
import { R
|
|
5
|
-
import { d as
|
|
6
|
-
import { r as
|
|
7
|
-
import { p as
|
|
8
|
-
import { v as
|
|
9
|
-
import { R as
|
|
10
|
-
import { g as
|
|
11
|
-
import { v as
|
|
12
|
-
import { c as
|
|
13
|
-
|
|
1
|
+
import { c as W } from "./runtime-CEMvybO7.js";
|
|
2
|
+
import { R as A, t as h, c as T, p as Re } from "./sha256-BDQ1Qk7A.js";
|
|
3
|
+
import { J as Se, s as Y, K as Ie } from "./json-snapshot-By4ZVVUt.js";
|
|
4
|
+
import { R, c as X, s as P, a as H, j as Ee, b as ke, r as Oe } from "./batch-DGCt44XM.js";
|
|
5
|
+
import { d as rr, e as nr, f as sr, v as ar, g as or } from "./batch-DGCt44XM.js";
|
|
6
|
+
import { r as Ae, a as Pe } from "./template-catalog-CmbWOJqy.js";
|
|
7
|
+
import { p as $, b as le, v as je } from "./template-registry-BIhIHOab.js";
|
|
8
|
+
import { v as pe, s as ee, a as Te } from "./prepared-BE-4jfX5.js";
|
|
9
|
+
import { R as Ne, l as Be } from "./param-validation-CnDEd2l-.js";
|
|
10
|
+
import { g as we } from "./record-bindings-DEJtmo3p.js";
|
|
11
|
+
import { v as ye } from "./dataset-DL83majE.js";
|
|
12
|
+
import { c as me } from "./media-Y90dHK9z.js";
|
|
13
|
+
import { R as $e } from "./component-tree-CvW4lzpv.js";
|
|
14
|
+
function zt(e = {}) {
|
|
14
15
|
const t = e.concurrency ?? 1, r = e.maxQueued ?? 20;
|
|
15
|
-
if (!Number.isSafeInteger(t) || t < 1 || !Number.isSafeInteger(r) || r < 0) throw new
|
|
16
|
+
if (!Number.isSafeInteger(t) || t < 1 || !Number.isSafeInteger(r) || r < 0) throw new A("budget", "队列并发应为正整数,排队上限应为非负整数");
|
|
16
17
|
const n = [], s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
17
|
-
let o = !1,
|
|
18
|
-
const
|
|
18
|
+
let o = !1, u = 0;
|
|
19
|
+
const f = () => {
|
|
19
20
|
for (; !o && s.size < t && n.length; ) n.shift().start();
|
|
20
21
|
};
|
|
21
22
|
return {
|
|
@@ -25,65 +26,65 @@ function kt(e = {}) {
|
|
|
25
26
|
get pending() {
|
|
26
27
|
return n.length;
|
|
27
28
|
},
|
|
28
|
-
enqueue: (
|
|
29
|
-
if (o) throw new
|
|
30
|
-
if (
|
|
31
|
-
const
|
|
32
|
-
if (a.has(
|
|
33
|
-
const
|
|
34
|
-
let
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
}),
|
|
38
|
-
d.signal?.removeEventListener("abort",
|
|
39
|
-
},
|
|
40
|
-
if (
|
|
41
|
-
const
|
|
42
|
-
|
|
29
|
+
enqueue: (i, d = {}) => {
|
|
30
|
+
if (o) throw new A("closed", "任务队列已关闭");
|
|
31
|
+
if (h(d.signal), s.size >= t && n.length >= r) throw new A("queue-full", "报表任务队列已满");
|
|
32
|
+
const l = d.id ?? `report-${++u}`;
|
|
33
|
+
if (a.has(l)) throw new A("queue-full", "任务 ID 正在执行或排队");
|
|
34
|
+
const p = new AbortController();
|
|
35
|
+
let w = "queued", g, y, m, v;
|
|
36
|
+
const N = new Promise((S, k) => {
|
|
37
|
+
m = S, v = k;
|
|
38
|
+
}), M = () => {
|
|
39
|
+
d.signal?.removeEventListener("abort", C), a.delete(l);
|
|
40
|
+
}, E = (S) => {
|
|
41
|
+
if (w !== "queued" && w !== "running") return;
|
|
42
|
+
const k = w === "queued";
|
|
43
|
+
w = "cancelled", p.abort(S);
|
|
43
44
|
try {
|
|
44
|
-
|
|
45
|
-
} catch (
|
|
46
|
-
|
|
45
|
+
h(p.signal);
|
|
46
|
+
} catch (z) {
|
|
47
|
+
v(z);
|
|
47
48
|
}
|
|
48
|
-
if (
|
|
49
|
-
const
|
|
50
|
-
|
|
49
|
+
if (k) {
|
|
50
|
+
const z = n.indexOf(I);
|
|
51
|
+
z >= 0 && n.splice(z, 1), M(), f();
|
|
51
52
|
}
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
cancel:
|
|
53
|
+
}, C = () => E(d.signal?.reason), K = (S, k) => {
|
|
54
|
+
w === "running" && (!Number.isFinite(S) || S < 0 || k !== void 0 && (!Number.isFinite(k) || k < S) || (g = { completed: S, ...k === void 0 ? {} : { total: k } }));
|
|
55
|
+
}, B = (S) => {
|
|
56
|
+
w !== "running" || p.signal.aborted || (y = { ...S, taskId: l }, S.completed !== void 0 && K(S.completed, S.total), Se(d.onEvent, y, p.signal));
|
|
57
|
+
}, I = {
|
|
58
|
+
cancel: E,
|
|
58
59
|
start: () => {
|
|
59
|
-
|
|
60
|
-
(
|
|
61
|
-
|
|
60
|
+
w === "queued" && (w = "running", s.add(I), Promise.resolve().then(() => (h(p.signal), i({ taskId: l, signal: p.signal, reportProgress: K, onEvent: B }))).then(
|
|
61
|
+
(S) => {
|
|
62
|
+
w === "running" && (w = "completed", m(S));
|
|
62
63
|
},
|
|
63
|
-
(
|
|
64
|
-
|
|
64
|
+
(S) => {
|
|
65
|
+
w === "running" && (w = "failed", v(S));
|
|
65
66
|
}
|
|
66
67
|
).finally(() => {
|
|
67
|
-
s.delete(
|
|
68
|
+
s.delete(I), M(), f();
|
|
68
69
|
}));
|
|
69
70
|
}
|
|
70
71
|
};
|
|
71
|
-
return a.add(
|
|
72
|
-
return
|
|
72
|
+
return a.add(l), d.signal?.addEventListener("abort", C, { once: !0 }), d.signal?.aborted ? E(d.signal.reason) : s.size < t ? I.start() : n.push(I), { id: l, get status() {
|
|
73
|
+
return w;
|
|
73
74
|
}, get progress() {
|
|
74
|
-
return b;
|
|
75
|
-
}, get event() {
|
|
76
75
|
return g;
|
|
77
|
-
},
|
|
76
|
+
}, get event() {
|
|
77
|
+
return y;
|
|
78
|
+
}, result: N, cancel: E };
|
|
78
79
|
},
|
|
79
|
-
close: (
|
|
80
|
+
close: (i = {}) => {
|
|
80
81
|
o = !0;
|
|
81
|
-
for (const d of [...n]) d.cancel(new
|
|
82
|
-
if (
|
|
82
|
+
for (const d of [...n]) d.cancel(new A("closed", "任务队列已关闭"));
|
|
83
|
+
if (i.cancelRunning) for (const d of s) d.cancel(new A("closed", "任务队列已关闭"));
|
|
83
84
|
}
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
|
-
function
|
|
87
|
+
function Me(e) {
|
|
87
88
|
let t, r;
|
|
88
89
|
const n = new Promise((s, a) => {
|
|
89
90
|
t = s, r = a;
|
|
@@ -91,45 +92,45 @@ function Ee(e) {
|
|
|
91
92
|
return n.catch(() => {
|
|
92
93
|
}), { progress: e, promise: n, resolve: t, reject: r };
|
|
93
94
|
}
|
|
94
|
-
function
|
|
95
|
+
function te(e) {
|
|
95
96
|
const t = Promise.reject(e);
|
|
96
97
|
return t.catch(() => {
|
|
97
98
|
}), t;
|
|
98
99
|
}
|
|
99
|
-
function
|
|
100
|
+
function De(e, t) {
|
|
100
101
|
let r, n, s = !0, a;
|
|
101
|
-
function o(
|
|
102
|
-
a ??=
|
|
102
|
+
function o(c) {
|
|
103
|
+
a ??= c ?? new Error("任务心跳更新失败"), n?.reject(a), n = void 0, t(a);
|
|
103
104
|
}
|
|
104
|
-
function
|
|
105
|
-
const
|
|
106
|
-
() =>
|
|
105
|
+
function u(c) {
|
|
106
|
+
const i = Promise.resolve().then(() => e(c?.progress)).then(
|
|
107
|
+
() => c?.resolve(),
|
|
107
108
|
(d) => {
|
|
108
|
-
|
|
109
|
+
c?.reject(d), o(d);
|
|
109
110
|
}
|
|
110
111
|
).finally(() => {
|
|
111
112
|
r = void 0;
|
|
112
113
|
const d = n;
|
|
113
|
-
n = void 0, d && a === void 0 &&
|
|
114
|
+
n = void 0, d && a === void 0 && u(d);
|
|
114
115
|
});
|
|
115
|
-
r =
|
|
116
|
+
r = i, i.catch((d) => {
|
|
116
117
|
o(d);
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
|
-
function c
|
|
120
|
+
function f(c) {
|
|
120
121
|
if (!s)
|
|
121
|
-
return
|
|
122
|
-
new
|
|
122
|
+
return te(
|
|
123
|
+
new R("closed", "任务进度上报已结束")
|
|
123
124
|
);
|
|
124
|
-
if (a !== void 0) return
|
|
125
|
-
n ? n.progress =
|
|
126
|
-
const
|
|
127
|
-
return r || (n = void 0,
|
|
125
|
+
if (a !== void 0) return te(a);
|
|
126
|
+
n ? n.progress = c : n = Me(c);
|
|
127
|
+
const i = n;
|
|
128
|
+
return r || (n = void 0, u(i)), i.promise;
|
|
128
129
|
}
|
|
129
130
|
return {
|
|
130
|
-
progress:
|
|
131
|
+
progress: f,
|
|
131
132
|
pulse() {
|
|
132
|
-
s && !r && a === void 0 &&
|
|
133
|
+
s && !r && a === void 0 && u();
|
|
133
134
|
},
|
|
134
135
|
async finish() {
|
|
135
136
|
for (s = !1; r; ) await r;
|
|
@@ -137,39 +138,39 @@ function Ie(e, t) {
|
|
|
137
138
|
}
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
|
-
class
|
|
141
|
+
class re extends R {
|
|
141
142
|
constructor() {
|
|
142
143
|
super("capacity", "任务结果超过独立预算,请保存文件引用");
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
|
-
function
|
|
146
|
+
function Je(e) {
|
|
146
147
|
const t = e.concurrency ?? 1, r = e.leaseMs ?? 3e4, n = e.heartbeatMs ?? 1e4, s = e.maxResultBytes ?? 256 * 1024;
|
|
147
148
|
if (![t, r, n, s].every(
|
|
148
149
|
(o) => Number.isSafeInteger(o) && o > 0
|
|
149
150
|
) || n * 2 > r)
|
|
150
|
-
throw new
|
|
151
|
+
throw new R(
|
|
151
152
|
"input",
|
|
152
153
|
"并发、租约、心跳应为正整数,租约至少为心跳的两倍"
|
|
153
154
|
);
|
|
154
155
|
if (n > 2147483647)
|
|
155
|
-
throw new
|
|
156
|
+
throw new R(
|
|
156
157
|
"input",
|
|
157
158
|
"心跳间隔超过平台定时器上限(2147483647毫秒)"
|
|
158
159
|
);
|
|
159
160
|
return { concurrency: t, leaseMs: r, heartbeatMs: n, maxResultBytes: s, now: () => {
|
|
160
161
|
const o = (e.now ?? Date.now)();
|
|
161
162
|
if (!Number.isSafeInteger(o) || o < 0)
|
|
162
|
-
throw new
|
|
163
|
+
throw new R("input", "任务时钟应返回非负整数毫秒");
|
|
163
164
|
return o;
|
|
164
165
|
} };
|
|
165
166
|
}
|
|
166
|
-
async function
|
|
167
|
-
|
|
167
|
+
async function F(e, t, r) {
|
|
168
|
+
X(t, r);
|
|
168
169
|
const n = await e.read(t, r);
|
|
169
|
-
if (!n) throw new
|
|
170
|
+
if (!n) throw new R("missing", "报表任务不存在");
|
|
170
171
|
return n;
|
|
171
172
|
}
|
|
172
|
-
async function
|
|
173
|
+
async function q(e, t, r, n = []) {
|
|
173
174
|
const s = { ...t, ...r, revision: t.revision + 1 };
|
|
174
175
|
for (const a of n) delete s[a];
|
|
175
176
|
if (!await e.compareAndSwap(
|
|
@@ -178,12 +179,12 @@ async function J(e, t, r, n = []) {
|
|
|
178
179
|
t.revision,
|
|
179
180
|
s
|
|
180
181
|
))
|
|
181
|
-
throw new
|
|
182
|
-
return
|
|
182
|
+
throw new R("conflict", "报表任务已被其他请求更新");
|
|
183
|
+
return H(s);
|
|
183
184
|
}
|
|
184
|
-
async function
|
|
185
|
+
async function Ce(e, t, r, n) {
|
|
185
186
|
if (!t.trim() || t.length > 128)
|
|
186
|
-
throw new
|
|
187
|
+
throw new R("input", "workerId应为1–128位标识");
|
|
187
188
|
for (const s of await e.store.candidates(n, 100)) {
|
|
188
189
|
const a = s.cancelRequested ? {
|
|
189
190
|
...s,
|
|
@@ -207,160 +208,160 @@ async function Ae(e, t, r, n) {
|
|
|
207
208
|
return a;
|
|
208
209
|
}
|
|
209
210
|
}
|
|
210
|
-
function
|
|
211
|
+
function ne(e, t, r, n) {
|
|
211
212
|
return e.status === "running" && e.attempt === n && e.lease?.owner === t && e.lease.expiresAt > r;
|
|
212
213
|
}
|
|
213
|
-
async function
|
|
214
|
+
async function qe(e, t, r, n) {
|
|
214
215
|
const { scope: s, id: a } = r, o = r.lease.owner;
|
|
215
|
-
let
|
|
216
|
-
const
|
|
217
|
-
async (
|
|
218
|
-
const
|
|
219
|
-
if (!
|
|
220
|
-
throw new
|
|
221
|
-
if (
|
|
222
|
-
n.abort(new
|
|
216
|
+
let u;
|
|
217
|
+
const f = De(
|
|
218
|
+
async (y) => {
|
|
219
|
+
const m = await F(e.store, s, a), v = t.now();
|
|
220
|
+
if (!ne(m, o, v, r.attempt))
|
|
221
|
+
throw new R("lease", "报表任务租约已失效");
|
|
222
|
+
if (m.cancelRequested) {
|
|
223
|
+
n.abort(new R("closed", "任务已请求取消"));
|
|
223
224
|
return;
|
|
224
225
|
}
|
|
225
|
-
await
|
|
226
|
-
updatedAt:
|
|
227
|
-
lease: { owner: o, expiresAt:
|
|
228
|
-
...
|
|
226
|
+
await q(e.store, m, {
|
|
227
|
+
updatedAt: v,
|
|
228
|
+
lease: { owner: o, expiresAt: v + t.leaseMs },
|
|
229
|
+
...y ? { progress: y } : {}
|
|
229
230
|
});
|
|
230
231
|
},
|
|
231
|
-
(
|
|
232
|
-
|
|
232
|
+
(y) => {
|
|
233
|
+
u = y, n.abort(y);
|
|
233
234
|
}
|
|
234
|
-
),
|
|
235
|
-
completed:
|
|
236
|
-
...
|
|
237
|
-
}),
|
|
238
|
-
|
|
235
|
+
), c = (y, m) => !Number.isFinite(y) || y < 0 || m !== void 0 && (!Number.isFinite(m) || m < y) ? Promise.reject(new R("input", "任务进度无效")) : f.progress({
|
|
236
|
+
completed: y,
|
|
237
|
+
...m === void 0 ? {} : { total: m }
|
|
238
|
+
}), i = setInterval(() => {
|
|
239
|
+
f.pulse();
|
|
239
240
|
}, t.heartbeatMs);
|
|
240
|
-
let d,
|
|
241
|
+
let d, l;
|
|
241
242
|
try {
|
|
242
|
-
const
|
|
243
|
+
const y = Object.prototype.hasOwnProperty.call(
|
|
243
244
|
e.handlers,
|
|
244
245
|
r.request.kind
|
|
245
246
|
) ? e.handlers[r.request.kind] : void 0;
|
|
246
|
-
if (!
|
|
247
|
+
if (!y) throw new R("input", "报表任务处理器未注册");
|
|
247
248
|
if (!n.signal.aborted) {
|
|
248
|
-
const
|
|
249
|
+
const m = await y(H(r.request.payload), {
|
|
249
250
|
scope: s,
|
|
250
251
|
taskId: a,
|
|
251
252
|
attempt: r.attempt,
|
|
252
253
|
executionToken: JSON.stringify([s, a, r.attempt]),
|
|
253
254
|
signal: n.signal,
|
|
254
|
-
reportProgress:
|
|
255
|
+
reportProgress: c
|
|
255
256
|
});
|
|
256
|
-
if (d = JSON.parse(
|
|
257
|
+
if (d = JSON.parse(P(m)), Ee(d) > t.maxResultBytes) throw new re();
|
|
257
258
|
}
|
|
258
|
-
} catch (
|
|
259
|
-
|
|
259
|
+
} catch (y) {
|
|
260
|
+
l = y ?? new Error("报表任务执行失败");
|
|
260
261
|
} finally {
|
|
261
|
-
clearInterval(
|
|
262
|
+
clearInterval(i), await f.finish().catch(() => {
|
|
262
263
|
});
|
|
263
264
|
}
|
|
264
|
-
const
|
|
265
|
-
if (!
|
|
266
|
-
throw new
|
|
267
|
-
const
|
|
268
|
-
delete
|
|
269
|
-
code:
|
|
270
|
-
message:
|
|
271
|
-
}) : (
|
|
265
|
+
const p = await F(e.store, s, a), w = t.now();
|
|
266
|
+
if (!ne(p, o, w, r.attempt))
|
|
267
|
+
throw new R("lease", "任务租约已失效,迟到结果不会写回");
|
|
268
|
+
const g = { ...p, updatedAt: w };
|
|
269
|
+
delete g.lease, l ??= u, p.cancelRequested || n.signal.aborted && u === void 0 ? g.status = "cancelled" : l !== void 0 ? (g.status = "failed", g.error = {
|
|
270
|
+
code: l instanceof re ? "result-budget" : l instanceof R ? l.code : "execution",
|
|
271
|
+
message: l instanceof Error ? l.message.slice(0, 500) : "报表任务执行失败"
|
|
272
|
+
}) : (g.status = "completed", g.result = d);
|
|
272
273
|
try {
|
|
273
|
-
|
|
274
|
+
P(g);
|
|
274
275
|
} catch {
|
|
275
|
-
delete
|
|
276
|
+
delete g.result, g.status = "failed", g.error = {
|
|
276
277
|
code: "result-budget",
|
|
277
278
|
message: "任务结果与请求的组合超过存储预算,请保存文件引用而非文件内容"
|
|
278
279
|
};
|
|
279
280
|
}
|
|
280
|
-
return
|
|
281
|
+
return ze(e.store, p, g);
|
|
281
282
|
}
|
|
282
|
-
async function
|
|
283
|
+
async function ze(e, t, r) {
|
|
283
284
|
try {
|
|
284
|
-
return await
|
|
285
|
+
return await q(e, t, r, ["lease"]);
|
|
285
286
|
} catch (n) {
|
|
286
|
-
if (!(n instanceof
|
|
287
|
-
return delete r.result, r.status = "failed", r.error = { code: "result-budget", message: "任务结果超过存储剩余预算,请保存文件引用而非文件内容" },
|
|
287
|
+
if (!(n instanceof R) || n.code !== "capacity" || r.status !== "completed") throw n;
|
|
288
|
+
return delete r.result, r.status = "failed", r.error = { code: "result-budget", message: "任务结果超过存储剩余预算,请保存文件引用而非文件内容" }, q(e, t, r, ["lease", "result"]);
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
|
-
async function
|
|
291
|
+
async function se(e, t, r, n) {
|
|
291
292
|
const s = await e.readTombstone?.(t, r);
|
|
292
293
|
if (s) {
|
|
293
|
-
if (s.requestHash !== await
|
|
294
|
-
return { scope: t, id: r, revision: s.revision, request:
|
|
294
|
+
if (s.requestHash !== await ke(n)) throw new R("conflict", "相同任务ID不能提交不同内容(幂等保留期内)");
|
|
295
|
+
return { scope: t, id: r, revision: s.revision, request: H(n), status: s.status, createdAt: s.createdAt, updatedAt: s.updatedAt, attempt: s.attempt, archived: !0 };
|
|
295
296
|
}
|
|
296
297
|
}
|
|
297
|
-
function
|
|
298
|
+
function _t(e) {
|
|
298
299
|
e = { ...e, handlers: { ...e.handlers } };
|
|
299
|
-
const t =
|
|
300
|
+
const t = Je(e), r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
|
|
300
301
|
let s = !1, a = 0;
|
|
301
|
-
const o = (
|
|
302
|
+
const o = (c, i) => (X(c, i), e.store.read(c, i));
|
|
302
303
|
return {
|
|
303
|
-
submit: async (
|
|
304
|
-
if (
|
|
305
|
-
throw new
|
|
306
|
-
const
|
|
307
|
-
kind:
|
|
304
|
+
submit: async (c) => {
|
|
305
|
+
if (c = { ...c }, X(c.scope, c.id), !Object.prototype.hasOwnProperty.call(e.handlers, c.kind) || typeof e.handlers[c.kind] != "function")
|
|
306
|
+
throw new R("input", "报表任务处理器未注册");
|
|
307
|
+
const i = {
|
|
308
|
+
kind: c.kind,
|
|
308
309
|
payload: JSON.parse(
|
|
309
|
-
|
|
310
|
+
P(c.payload, {
|
|
310
311
|
maxNodes: 19e3,
|
|
311
312
|
maxCharacters: 75e4
|
|
312
313
|
})
|
|
313
314
|
)
|
|
314
|
-
}, d = await o(
|
|
315
|
+
}, d = await o(c.scope, c.id);
|
|
315
316
|
if (d) {
|
|
316
|
-
if (
|
|
317
|
-
throw new
|
|
317
|
+
if (P(d.request) !== P(i))
|
|
318
|
+
throw new R("conflict", "相同任务ID不能提交不同内容");
|
|
318
319
|
return d;
|
|
319
320
|
}
|
|
320
|
-
const
|
|
321
|
-
if (
|
|
322
|
-
const
|
|
323
|
-
scope:
|
|
324
|
-
id:
|
|
321
|
+
const l = await se(e.store, c.scope, c.id, i);
|
|
322
|
+
if (l) return l;
|
|
323
|
+
const p = t.now(), w = {
|
|
324
|
+
scope: c.scope,
|
|
325
|
+
id: c.id,
|
|
325
326
|
revision: 1,
|
|
326
|
-
request:
|
|
327
|
+
request: i,
|
|
327
328
|
status: "queued",
|
|
328
|
-
createdAt:
|
|
329
|
-
updatedAt:
|
|
329
|
+
createdAt: p,
|
|
330
|
+
updatedAt: p,
|
|
330
331
|
attempt: 0
|
|
331
332
|
};
|
|
332
|
-
if (!await e.store.compareAndSwap(
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
335
|
-
return
|
|
336
|
-
const
|
|
337
|
-
if (
|
|
338
|
-
throw new
|
|
333
|
+
if (!await e.store.compareAndSwap(c.scope, c.id, null, w)) {
|
|
334
|
+
const g = await o(c.scope, c.id);
|
|
335
|
+
if (g && P(g.request) === P(i))
|
|
336
|
+
return g;
|
|
337
|
+
const y = await se(e.store, c.scope, c.id, i);
|
|
338
|
+
if (y) return y;
|
|
339
|
+
throw new R("conflict", "报表任务提交发生冲突");
|
|
339
340
|
}
|
|
340
|
-
return
|
|
341
|
+
return H(w);
|
|
341
342
|
},
|
|
342
343
|
get: o,
|
|
343
|
-
runNext: (
|
|
344
|
+
runNext: (c) => {
|
|
344
345
|
if (s)
|
|
345
|
-
return Promise.reject(new
|
|
346
|
+
return Promise.reject(new R("closed", "报表任务服务已关闭"));
|
|
346
347
|
if (a >= t.concurrency)
|
|
347
348
|
return Promise.reject(
|
|
348
|
-
new
|
|
349
|
+
new R("capacity", "报表任务执行槽位已满")
|
|
349
350
|
);
|
|
350
351
|
a++;
|
|
351
|
-
const
|
|
352
|
-
r.add(
|
|
352
|
+
const i = new AbortController();
|
|
353
|
+
r.add(i);
|
|
353
354
|
const d = (async () => {
|
|
354
355
|
try {
|
|
355
|
-
const
|
|
356
|
+
const l = await Ce(
|
|
356
357
|
e,
|
|
357
|
-
|
|
358
|
+
c,
|
|
358
359
|
t.leaseMs,
|
|
359
360
|
t.now()
|
|
360
361
|
);
|
|
361
|
-
return
|
|
362
|
+
return l?.status === "running" ? await qe(e, t, l, i) : l;
|
|
362
363
|
} finally {
|
|
363
|
-
a--, r.delete(
|
|
364
|
+
a--, r.delete(i);
|
|
364
365
|
}
|
|
365
366
|
})();
|
|
366
367
|
return n.add(d), d.then(
|
|
@@ -371,56 +372,59 @@ function Et(e) {
|
|
|
371
372
|
get active() {
|
|
372
373
|
return a;
|
|
373
374
|
},
|
|
374
|
-
cancel: async (
|
|
375
|
-
const d = await
|
|
376
|
-
return d.status !== "queued" && d.status !== "running" ? d :
|
|
375
|
+
cancel: async (c, i) => {
|
|
376
|
+
const d = await F(e.store, c, i);
|
|
377
|
+
return d.status !== "queued" && d.status !== "running" ? d : q(e.store, d, {
|
|
377
378
|
updatedAt: t.now(),
|
|
378
379
|
...d.status === "queued" ? { status: "cancelled" } : { cancelRequested: !0 }
|
|
379
380
|
});
|
|
380
381
|
},
|
|
381
|
-
retry: async (
|
|
382
|
-
const
|
|
383
|
-
if (
|
|
384
|
-
throw new
|
|
385
|
-
const
|
|
386
|
-
...
|
|
382
|
+
retry: async (c, i, d) => {
|
|
383
|
+
const l = await F(e.store, c, i);
|
|
384
|
+
if (l.revision !== d || l.status !== "failed")
|
|
385
|
+
throw new R("conflict", "仅可重试当前修订的失败任务");
|
|
386
|
+
const p = {
|
|
387
|
+
...l,
|
|
387
388
|
status: "queued",
|
|
388
389
|
updatedAt: t.now()
|
|
389
390
|
};
|
|
390
|
-
return delete
|
|
391
|
+
return delete p.error, delete p.progress, q(e.store, l, p, ["error", "progress"]);
|
|
391
392
|
},
|
|
392
|
-
prune: async (
|
|
393
|
-
if (!e.store.prune || !e.store.readTombstone) throw new
|
|
394
|
-
return e.store.prune({ ...
|
|
393
|
+
prune: async (c) => {
|
|
394
|
+
if (!e.store.prune || !e.store.readTombstone) throw new R("input", "当前任务适配器未实现可选终态保留能力");
|
|
395
|
+
return e.store.prune({ ...c, now: t.now() });
|
|
395
396
|
},
|
|
396
397
|
close: async () => {
|
|
397
398
|
s = !0;
|
|
398
|
-
for (const
|
|
399
|
-
|
|
399
|
+
for (const c of r)
|
|
400
|
+
c.abort(new R("closed", "任务服务正在关闭"));
|
|
400
401
|
await Promise.allSettled([...n]);
|
|
401
402
|
}
|
|
402
403
|
};
|
|
403
404
|
}
|
|
404
|
-
function
|
|
405
|
+
function ge(e, t) {
|
|
405
406
|
const r = e.assets, n = e[t];
|
|
406
|
-
if (!(!r && !n?.assetRenderers))
|
|
407
|
+
if (!(!r && !n?.assetRenderers && !n?.assetRegistry))
|
|
407
408
|
return {
|
|
408
409
|
...r,
|
|
409
410
|
...n?.assetFailure === void 0 ? {} : { assetFailure: n.assetFailure },
|
|
410
411
|
...n?.onDiagnostic === void 0 ? {} : { onDiagnostic: n.onDiagnostic },
|
|
412
|
+
assetRegistry: n?.assetRegistry ?? r?.assetRegistry,
|
|
411
413
|
assetRenderers: { ...r?.assetRenderers, ...n?.assetRenderers },
|
|
412
414
|
assetBudget: { ...r?.assetBudget, ...n?.assetBudget }
|
|
413
415
|
};
|
|
414
416
|
}
|
|
415
|
-
function
|
|
416
|
-
|
|
417
|
+
function ae(e, t) {
|
|
418
|
+
if (!e || e.code !== "missing-image" || e.format !== "pdf" && e.format !== "xlsx") return !1;
|
|
419
|
+
const r = ge(t, e.format);
|
|
420
|
+
return typeof r?.assetRenderers?.[e.kind] == "function" || !!(e.extension && r?.assetRegistry?.hasExtension(e.extension.id, e.extension.version, e.kind));
|
|
417
421
|
}
|
|
418
|
-
function
|
|
419
|
-
const r =
|
|
422
|
+
function _e(e, t) {
|
|
423
|
+
const r = Ae(e, t), n = r.issues.filter((a) => !ae(a.diagnostic, t)), s = r.samples.map((a) => ({ ...a, diagnostics: a.diagnostics.filter((o) => !ae(o, t)) }));
|
|
420
424
|
return { ...r, issues: n, samples: s, ok: n.every((a) => a.severity !== "error"), artifacts: [] };
|
|
421
425
|
}
|
|
422
|
-
async function
|
|
423
|
-
const a =
|
|
426
|
+
async function Le(e, t, r, n, s) {
|
|
427
|
+
const a = W({ reports: { sample: { template: r, datasets: e.datasets } }, assets: ge(n, t), budget: {
|
|
424
428
|
maxRows: n.maxSampleRows ?? 1e3,
|
|
425
429
|
maxPages: n.maxPages ?? 100,
|
|
426
430
|
maxCells: n.maxCells ?? 25e4,
|
|
@@ -428,239 +432,239 @@ async function Pe(e, t, r, n, s) {
|
|
|
428
432
|
maxDurationMs: n.maxDurationMs ?? 3e4
|
|
429
433
|
} });
|
|
430
434
|
try {
|
|
431
|
-
const { result: o, digest:
|
|
432
|
-
const
|
|
433
|
-
if (n.strictOutputs &&
|
|
434
|
-
const d = await n.digest?.(
|
|
435
|
-
return
|
|
435
|
+
const { result: o, digest: u } = await T(n.signal, n.maxDurationMs ?? 3e4, async (f) => {
|
|
436
|
+
const c = await a.export({ reportIds: ["sample"], params: e.params, format: t, signal: f, fidelity: n.strictOutputs ? "strict" : "warn", pdf: n.pdf, xlsx: n.xlsx }), i = c.diagnostics.filter((l) => l.severity !== "info");
|
|
437
|
+
if (n.strictOutputs && i.length) throw new Error(`Strict ${t} encoding found fidelity issues: ${i.slice(0, 3).map((l) => l.message).join("; ")}`);
|
|
438
|
+
const d = await n.digest?.(c.bytes);
|
|
439
|
+
return h(f), await n.onArtifact?.(e.name, c), h(f), { result: c, digest: d };
|
|
436
440
|
});
|
|
437
|
-
s.artifacts.push({ fixture: e.name, format: t, bytes: o.bytes.byteLength, pages: o.stats.pages, ...
|
|
441
|
+
s.artifacts.push({ fixture: e.name, format: t, bytes: o.bytes.byteLength, pages: o.stats.pages, ...u ? { digest: u } : {} }), s.issues.push(...o.diagnostics.map((f) => ({ code: "output", severity: n.strictOutputs || f.severity === "error" ? "error" : "warning", path: "$.template", fixture: e.name, message: `${t}: ${f.message}` })));
|
|
438
442
|
} catch (o) {
|
|
439
|
-
|
|
443
|
+
h(n.signal), s.issues.push({ code: "output", severity: "error", path: "$.template", fixture: e.name, message: `${t}: ${o instanceof Error ? o.message : String(o)}` });
|
|
440
444
|
}
|
|
441
445
|
}
|
|
442
|
-
async function
|
|
443
|
-
|
|
444
|
-
const r =
|
|
446
|
+
async function Lt(e, t = {}) {
|
|
447
|
+
h(t.signal);
|
|
448
|
+
const r = _e(e, t);
|
|
445
449
|
if (!r.ok) return r;
|
|
446
|
-
const n =
|
|
450
|
+
const n = $(e).template, s = [...new Set(t.formats ?? ["pdf", "xlsx"])];
|
|
447
451
|
if (!s.length || s.some((a) => a !== "pdf" && a !== "xlsx"))
|
|
448
452
|
return r.issues.push({ code: "output", severity: "error", path: "$.formats", message: "真实文件验收应至少选择PDF/XLSX之一" }), r.ok = !1, r;
|
|
449
453
|
for (const a of t.fixtures ?? [])
|
|
450
454
|
for (const o of s)
|
|
451
|
-
|
|
455
|
+
h(t.signal), !(o !== "pdf" && o !== "xlsx") && await Le(a, o, n, t, r);
|
|
452
456
|
return r.ok = r.issues.every((a) => a.severity !== "error"), r;
|
|
453
457
|
}
|
|
454
|
-
class
|
|
458
|
+
class b extends Error {
|
|
455
459
|
constructor(t, r) {
|
|
456
460
|
super(r), this.code = t, this.name = "ReportInstanceError";
|
|
457
461
|
}
|
|
458
462
|
}
|
|
459
|
-
function
|
|
460
|
-
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
|
|
463
|
+
function J(e, t) {
|
|
464
|
+
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 b("input", "实例范围应非空,ID 应为安全标识");
|
|
461
465
|
}
|
|
462
|
-
function
|
|
466
|
+
function Fe(e, t) {
|
|
463
467
|
const r = Object.getPrototypeOf(e);
|
|
464
|
-
if (r !== (t ? Array.prototype : Object.prototype) && !(r === null && !t) || Object.getOwnPropertySymbols(e).length) throw new
|
|
465
|
-
if (t && Object.keys(e).some((s) => s !== String(Number(s)) || !Number.isSafeInteger(Number(s)) || Number(s) < 0 || Number(s) >= e.length)) throw new
|
|
466
|
-
if (Object.getOwnPropertyNames(e).filter((s) => !(t && s === "length")).length !== Object.keys(e).length) throw new
|
|
468
|
+
if (r !== (t ? Array.prototype : Object.prototype) && !(r === null && !t) || Object.getOwnPropertySymbols(e).length) throw new b("input", "实例应为普通 JSON 对象");
|
|
469
|
+
if (t && Object.keys(e).some((s) => s !== String(Number(s)) || !Number.isSafeInteger(Number(s)) || Number(s) < 0 || Number(s) >= e.length)) throw new b("input", "实例数组不能包含额外属性");
|
|
470
|
+
if (Object.getOwnPropertyNames(e).filter((s) => !(t && s === "length")).length !== Object.keys(e).length) throw new b("input", "实例不能包含不可枚举属性");
|
|
467
471
|
}
|
|
468
|
-
function
|
|
469
|
-
if (!Number.isSafeInteger(e.revision) || e.revision < 1 || typeof e.title != "string" || !e.title.trim() || e.title.length > 512) throw new
|
|
470
|
-
if (typeof e.generatedAt != "string" || !Number.isFinite(Date.parse(e.generatedAt)) || new Date(e.generatedAt).toISOString() !== e.generatedAt) throw new
|
|
471
|
-
if (!Array.isArray(e.reportIds) || !e.reportIds.length || e.reportIds.length > 100 || e.reportIds.some((t) => typeof t != "string" || !t.trim()) || new Set(e.reportIds).size !== e.reportIds.length) throw new
|
|
472
|
+
function Ve(e) {
|
|
473
|
+
if (!Number.isSafeInteger(e.revision) || e.revision < 1 || typeof e.title != "string" || !e.title.trim() || e.title.length > 512) throw new b("input", "实例修订或标题无效");
|
|
474
|
+
if (typeof e.generatedAt != "string" || !Number.isFinite(Date.parse(e.generatedAt)) || new Date(e.generatedAt).toISOString() !== e.generatedAt) throw new b("input", "实例生成时间应为 ISO UTC 字符串");
|
|
475
|
+
if (!Array.isArray(e.reportIds) || !e.reportIds.length || e.reportIds.length > 100 || e.reportIds.some((t) => typeof t != "string" || !t.trim()) || new Set(e.reportIds).size !== e.reportIds.length) throw new b("input", "实例报表 ID 应非空且唯一");
|
|
472
476
|
}
|
|
473
|
-
function
|
|
477
|
+
function He(e) {
|
|
474
478
|
return e === null || typeof e == "boolean" || typeof e == "string" || typeof e == "number" && Number.isFinite(e);
|
|
475
479
|
}
|
|
476
|
-
function
|
|
477
|
-
if (!Number.isSafeInteger(t) || t < 1) throw new
|
|
480
|
+
function he(e, t) {
|
|
481
|
+
if (!Number.isSafeInteger(t) || t < 1) throw new b("input", "实例快照字节预算应为正安全整数");
|
|
478
482
|
let r = 0, n = 0;
|
|
479
483
|
const s = /* @__PURE__ */ new Set();
|
|
480
|
-
function a(
|
|
481
|
-
if (++r > 1e6 ||
|
|
482
|
-
if (typeof
|
|
483
|
-
throw new
|
|
484
|
-
if (
|
|
485
|
-
if (!
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
const
|
|
489
|
-
for (const d of Object.keys(
|
|
490
|
-
if (n += d.length, n > t) throw new
|
|
491
|
-
const
|
|
492
|
-
if (
|
|
493
|
-
|
|
484
|
+
function a(u, f) {
|
|
485
|
+
if (++r > 1e6 || f > 64) throw new b("capacity", "实例节点或嵌套深度超过预算");
|
|
486
|
+
if (typeof u == "string" && (n += u.length, n > t))
|
|
487
|
+
throw new b("capacity", "实例文本超过预算");
|
|
488
|
+
if (He(u)) return u;
|
|
489
|
+
if (!u || typeof u != "object" || s.has(u)) throw new b("input", "实例只允许无循环的有限 JSON 值");
|
|
490
|
+
const c = Array.isArray(u);
|
|
491
|
+
Fe(u, c), s.add(u);
|
|
492
|
+
const i = /* @__PURE__ */ Object.create(null);
|
|
493
|
+
for (const d of Object.keys(u)) {
|
|
494
|
+
if (n += d.length, n > t) throw new b("capacity", "实例文本超过预算");
|
|
495
|
+
const l = Object.getOwnPropertyDescriptor(u, d);
|
|
496
|
+
if (l.get || l.set || ["__proto__", "constructor", "prototype"].includes(d)) throw new b("input", "实例不能包含访问器或危险键");
|
|
497
|
+
l.value !== void 0 && (i[d] = a(l.value, f + 1));
|
|
494
498
|
}
|
|
495
|
-
if (s.delete(
|
|
496
|
-
if (Object.keys(
|
|
497
|
-
return Array.from({ length:
|
|
499
|
+
if (s.delete(u), c) {
|
|
500
|
+
if (Object.keys(i).length !== u.length) throw new b("input", "实例数组不能稀疏或包含额外属性");
|
|
501
|
+
return Array.from({ length: u.length }, (d, l) => i[String(l)]);
|
|
498
502
|
}
|
|
499
|
-
return
|
|
503
|
+
return i;
|
|
500
504
|
}
|
|
501
505
|
const o = JSON.stringify(a(e, 0));
|
|
502
|
-
if (new TextEncoder().encode(o).byteLength > t) throw new
|
|
506
|
+
if (new TextEncoder().encode(o).byteLength > t) throw new b("capacity", "实例快照超过单条字节预算");
|
|
503
507
|
return o;
|
|
504
508
|
}
|
|
505
|
-
function
|
|
506
|
-
const r = JSON.parse(
|
|
507
|
-
|
|
509
|
+
function G(e, t = 8e6) {
|
|
510
|
+
const r = JSON.parse(he(e, t));
|
|
511
|
+
J(r.scope, r.id);
|
|
508
512
|
const n = /* @__PURE__ */ new Set(["scope", "id", "revision", "title", "generatedAt", "reportIds", "params", "templateRevisions", "sourceRevisions", "plan", "artifacts", "output"]);
|
|
509
|
-
if (Object.keys(r).some((a) => !n.has(a))) throw new
|
|
510
|
-
|
|
513
|
+
if (Object.keys(r).some((a) => !n.has(a))) throw new b("input", "实例包含未知字段");
|
|
514
|
+
Ve(r);
|
|
511
515
|
for (const a of [r.params, r.templateRevisions, r.sourceRevisions])
|
|
512
|
-
if (!a || typeof a != "object" || Array.isArray(a) || Object.values(a).some((o) => typeof o != "string")) throw new
|
|
513
|
-
if (r.reportIds.some((a) => !r.templateRevisions[a])) throw new
|
|
514
|
-
const s =
|
|
515
|
-
if (!s.ok) throw new
|
|
516
|
+
if (!a || typeof a != "object" || Array.isArray(a) || Object.values(a).some((o) => typeof o != "string")) throw new b("input", "实例参数和修订应为字符串字典");
|
|
517
|
+
if (r.reportIds.some((a) => !r.templateRevisions[a])) throw new b("input", "每张报表都应记录生成时的模板修订");
|
|
518
|
+
const s = le(r.plan);
|
|
519
|
+
if (!s.ok) throw new b("input", `实例渲染计划无效:${s.errors[0]?.path}`);
|
|
516
520
|
if (r.output !== void 0) {
|
|
517
|
-
if (!r.output || Object.keys(r.output).some((a) => !["stats", "diagnostics", "layout", "sources"].includes(a))) throw new
|
|
518
|
-
if (
|
|
521
|
+
if (!r.output || Object.keys(r.output).some((a) => !["stats", "diagnostics", "layout", "sources"].includes(a))) throw new b("input", "实例输出元数据只允许统计、诊断和字体度量;不保存来源令牌");
|
|
522
|
+
if (pe({ ...r.output, plan: r.plan, revisions: {} }), r.output.sources?.some((a) => "sourceToken" in a)) throw new b("input", "实例来源清单不保存来源令牌");
|
|
519
523
|
}
|
|
520
|
-
return r.artifacts !== void 0 &&
|
|
524
|
+
return r.artifacts !== void 0 && Ue(r.artifacts), r;
|
|
521
525
|
}
|
|
522
|
-
function
|
|
523
|
-
if (!Array.isArray(e) || e.length > 100) throw new
|
|
526
|
+
function Ue(e) {
|
|
527
|
+
if (!Array.isArray(e) || e.length > 100) throw new b("input", "实例文件列表无效");
|
|
524
528
|
const t = /* @__PURE__ */ new Set();
|
|
525
529
|
for (const r of e) {
|
|
526
|
-
if (!r || typeof r.key != "string" || !r.key.trim() || r.key.length > 1024 || t.has(r.key) || !["pdf", "xlsx"].includes(r.format) || !Number.isSafeInteger(r.bytes) || r.bytes < 0 || r.sha256 !== void 0 && (typeof r.sha256 != "string" || r.sha256.length !== 64 || !/^[a-f0-9]{64}$/i.test(r.sha256))) throw new
|
|
530
|
+
if (!r || typeof r.key != "string" || !r.key.trim() || r.key.length > 1024 || t.has(r.key) || !["pdf", "xlsx"].includes(r.format) || !Number.isSafeInteger(r.bytes) || r.bytes < 0 || r.sha256 !== void 0 && (typeof r.sha256 != "string" || r.sha256.length !== 64 || !/^[a-f0-9]{64}$/i.test(r.sha256))) throw new b("input", "实例文件应包含唯一存储键、格式、大小和可选 SHA256");
|
|
527
531
|
t.add(r.key);
|
|
528
532
|
}
|
|
529
533
|
}
|
|
530
|
-
function
|
|
531
|
-
const { scope: t, id: r, revision: n, title: s, generatedAt: a, reportIds: o, params:
|
|
532
|
-
return JSON.parse(JSON.stringify({ scope: t, id: r, revision: n, title: s, generatedAt: a, reportIds: o, params:
|
|
534
|
+
function Ke(e) {
|
|
535
|
+
const { scope: t, id: r, revision: n, title: s, generatedAt: a, reportIds: o, params: u, templateRevisions: f, sourceRevisions: c } = e;
|
|
536
|
+
return JSON.parse(JSON.stringify({ scope: t, id: r, revision: n, title: s, generatedAt: a, reportIds: o, params: u, templateRevisions: f, sourceRevisions: c }));
|
|
533
537
|
}
|
|
534
|
-
function
|
|
538
|
+
function Ze(e) {
|
|
535
539
|
const t = { maxInstances: 100, maxRevisions: 20, maxBytes: 64e6, maxSnapshotBytes: 8e6, ...e };
|
|
536
|
-
if (Object.values(t).some((r) => !Number.isSafeInteger(r) || r < 1)) throw new
|
|
540
|
+
if (Object.values(t).some((r) => !Number.isSafeInteger(r) || r < 1)) throw new b("input", "实例存储预算应为正安全整数");
|
|
537
541
|
return t;
|
|
538
542
|
}
|
|
539
|
-
function
|
|
540
|
-
const t =
|
|
543
|
+
function Ft(e = {}) {
|
|
544
|
+
const t = Ze(e), r = /* @__PURE__ */ new Map();
|
|
541
545
|
let n = 0;
|
|
542
546
|
return {
|
|
543
|
-
read: async (s, a, o,
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
return
|
|
547
|
+
read: async (s, a, o, u) => {
|
|
548
|
+
h(u), J(s, a);
|
|
549
|
+
const f = r.get(JSON.stringify([s, a])), c = f?.get(o ?? f.size);
|
|
550
|
+
return c ? G(c, t.maxSnapshotBytes) : void 0;
|
|
547
551
|
},
|
|
548
552
|
list: async (s, a = {}) => {
|
|
549
|
-
|
|
553
|
+
h(a.signal), J(s, "list");
|
|
550
554
|
const o = a.limit ?? 25;
|
|
551
|
-
if (!Number.isSafeInteger(o) || o < 1 || o > 100) throw new
|
|
552
|
-
const
|
|
553
|
-
return { items:
|
|
555
|
+
if (!Number.isSafeInteger(o) || o < 1 || o > 100) throw new b("input", "实例每页数量应为 1–100");
|
|
556
|
+
const u = Array.from(r.values(), (f) => f.get(f.size)).filter((f) => f.scope === s && (!a.after || f.id > a.after) && (!a.reportId || f.reportIds.includes(a.reportId))).sort((f, c) => f.id < c.id ? -1 : 1).slice(0, o + 1);
|
|
557
|
+
return { items: u.slice(0, o).map(Ke), ...u.length > o ? { next: u[o - 1].id } : {} };
|
|
554
558
|
},
|
|
555
|
-
compareAndSwap: async (s, a, o,
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
if (
|
|
559
|
-
const
|
|
559
|
+
compareAndSwap: async (s, a, o, u, f) => {
|
|
560
|
+
h(f), J(s, a);
|
|
561
|
+
const c = G(u, t.maxSnapshotBytes);
|
|
562
|
+
if (c.scope !== s || c.id !== a || c.revision !== (o ?? 0) + 1) throw new b("input", "实例身份或修订不一致");
|
|
563
|
+
const i = JSON.stringify([s, a]), d = r.get(i) ?? /* @__PURE__ */ new Map();
|
|
560
564
|
if ((d.size || null) !== o) return !1;
|
|
561
|
-
const
|
|
562
|
-
if (d.size >= t.maxRevisions || n +
|
|
563
|
-
return d.set(
|
|
565
|
+
const l = new TextEncoder().encode(JSON.stringify(c)).byteLength;
|
|
566
|
+
if (d.size >= t.maxRevisions || n + l > t.maxBytes || !d.size && r.size >= t.maxInstances) throw new b("capacity", "实例存储达到预算,请使用持久化归档策略或显式调整容量");
|
|
567
|
+
return d.set(c.revision, c), r.set(i, d), n += l, !0;
|
|
564
568
|
}
|
|
565
569
|
};
|
|
566
570
|
}
|
|
567
|
-
function
|
|
571
|
+
function Xe(e, t = {}) {
|
|
568
572
|
const r = t.maxSnapshotBytes ?? 8e6;
|
|
569
|
-
if (!Number.isSafeInteger(r) || r < 1) throw new
|
|
573
|
+
if (!Number.isSafeInteger(r) || r < 1) throw new b("input", "实例快照字节预算应为正安全整数");
|
|
570
574
|
return {
|
|
571
575
|
read: e.read.bind(e),
|
|
572
576
|
list: e.list.bind(e),
|
|
573
577
|
save: async (n, s) => {
|
|
574
578
|
const a = s.expectedRevision;
|
|
575
|
-
if (a !== null && (!Number.isSafeInteger(a) || a < 1 || a >= Number.MAX_SAFE_INTEGER)) throw new
|
|
576
|
-
const o = JSON.parse(
|
|
577
|
-
if (
|
|
578
|
-
return
|
|
579
|
+
if (a !== null && (!Number.isSafeInteger(a) || a < 1 || a >= Number.MAX_SAFE_INTEGER)) throw new b("input", "实例预期修订无效");
|
|
580
|
+
const o = JSON.parse(he(n, r)), u = G({ ...o, revision: (a ?? 0) + 1 }, r);
|
|
581
|
+
if (h(s.signal), !await e.compareAndSwap(u.scope, u.id, a, u, s.signal)) throw new b("conflict", "实例已存在或已变化,请显式确认修订后保存");
|
|
582
|
+
return u;
|
|
579
583
|
}
|
|
580
584
|
};
|
|
581
585
|
}
|
|
582
|
-
function
|
|
583
|
-
return
|
|
586
|
+
function Vt(e, t) {
|
|
587
|
+
return P({ reportIds: e, params: t });
|
|
584
588
|
}
|
|
585
|
-
function
|
|
586
|
-
if (!e || typeof e != "object" || Object.getOwnPropertySymbols(e).length) throw new
|
|
589
|
+
function Ge(e) {
|
|
590
|
+
if (!e || typeof e != "object" || Object.getOwnPropertySymbols(e).length) throw new b("input", "生成请求应为普通对象");
|
|
587
591
|
const t = /* @__PURE__ */ Object.create(null);
|
|
588
592
|
let r;
|
|
589
593
|
const n = /* @__PURE__ */ new Set(["scope", "id", "title", "reportIds", "params", "expectedRevision", "signal"]);
|
|
590
594
|
for (const s of Object.getOwnPropertyNames(e)) {
|
|
591
595
|
const a = Object.getOwnPropertyDescriptor(e, s);
|
|
592
|
-
if (!n.has(s) || !a.enumerable || a.get || a.set) throw new
|
|
596
|
+
if (!n.has(s) || !a.enumerable || a.get || a.set) throw new b("input", "生成请求不能包含未知字段或访问器");
|
|
593
597
|
s === "signal" ? r = a.value : a.value !== void 0 && (t[s] = a.value);
|
|
594
598
|
}
|
|
595
|
-
return { signal: r, request: JSON.parse(
|
|
599
|
+
return { signal: r, request: JSON.parse(P(t)) };
|
|
596
600
|
}
|
|
597
|
-
function
|
|
598
|
-
const t = JSON.parse(
|
|
601
|
+
function Qe(e) {
|
|
602
|
+
const t = JSON.parse(P(e.templateRevisions)), r = ee(e.pdf), n = Xe(e.instances, { maxSnapshotBytes: e.maxSnapshotBytes });
|
|
599
603
|
return {
|
|
600
604
|
async generate(s) {
|
|
601
|
-
const { signal: a, request: o } =
|
|
602
|
-
if (
|
|
603
|
-
const
|
|
604
|
-
if (!
|
|
605
|
-
const
|
|
606
|
-
for (const
|
|
607
|
-
if (typeof t[
|
|
608
|
-
|
|
605
|
+
const { signal: a, request: o } = Ge(s);
|
|
606
|
+
if (J(o.scope, o.id), o.expectedRevision !== null && (!Number.isSafeInteger(o.expectedRevision) || o.expectedRevision < 1)) throw new b("input", "实例预期修订无效");
|
|
607
|
+
const u = e.runtime.validate(o);
|
|
608
|
+
if (!u.ok) throw new Ne(u.issues);
|
|
609
|
+
const f = /* @__PURE__ */ Object.create(null);
|
|
610
|
+
for (const m of o.reportIds) {
|
|
611
|
+
if (typeof t[m] != "string" || !t[m]) throw new TypeError(`报表 ${m} 缺少生成时的模板修订`);
|
|
612
|
+
f[m] = t[m];
|
|
609
613
|
}
|
|
610
|
-
if (
|
|
611
|
-
throw new
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
+
if (h(a), ((await e.instances.read(o.scope, o.id, void 0, a))?.revision ?? null) !== o.expectedRevision)
|
|
615
|
+
throw new b("conflict", "实例已存在或已变化,请显式确认修订后生成");
|
|
616
|
+
const i = await e.runtime.prepare({ reportIds: o.reportIds, params: u.values, pdf: r, signal: a });
|
|
617
|
+
h(a);
|
|
614
618
|
const d = /* @__PURE__ */ Object.create(null);
|
|
615
|
-
for (const [
|
|
616
|
-
const { plan:
|
|
619
|
+
for (const [m, v] of Object.entries(i.revisions)) v.revision !== void 0 && (d[m] = v.revision);
|
|
620
|
+
const { plan: l, revisions: p, sources: w, ...g } = i, y = { ...g, ...w ? { sources: w.map(({ sourceToken: m, ...v }) => v) } : {} };
|
|
617
621
|
return n.save({
|
|
618
622
|
scope: o.scope,
|
|
619
623
|
id: o.id,
|
|
620
624
|
title: o.title,
|
|
621
625
|
reportIds: o.reportIds,
|
|
622
|
-
params:
|
|
623
|
-
templateRevisions:
|
|
626
|
+
params: u.values,
|
|
627
|
+
templateRevisions: f,
|
|
624
628
|
sourceRevisions: d,
|
|
625
629
|
generatedAt: (e.now?.() ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
626
|
-
plan:
|
|
627
|
-
output:
|
|
630
|
+
plan: l,
|
|
631
|
+
output: y
|
|
628
632
|
}, { expectedRevision: o.expectedRevision, signal: a });
|
|
629
633
|
},
|
|
630
634
|
read: n.read,
|
|
631
635
|
list: n.list,
|
|
632
636
|
/** Read an immutable saved revision and encode its plan, never re-query the business source. */
|
|
633
637
|
async exportInstance(s) {
|
|
634
|
-
const { scope: a, id: o, revision:
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
if (!
|
|
638
|
-
const
|
|
639
|
-
plan:
|
|
640
|
-
revisions: Object.fromEntries(
|
|
638
|
+
const { scope: a, id: o, revision: u, signal: f, format: c, fidelity: i, taskId: d, correlationId: l, onEvent: p } = s, w = ee(s.pdf ?? r), g = Te(s.xlsx);
|
|
639
|
+
J(a, o), h(f);
|
|
640
|
+
const y = await n.read(a, o, u, f);
|
|
641
|
+
if (!y) throw new b("input", "报表实例不存在");
|
|
642
|
+
const m = {
|
|
643
|
+
plan: y.plan,
|
|
644
|
+
revisions: Object.fromEntries(y.reportIds.map((v) => [v, { revision: y.sourceRevisions[v] }])),
|
|
641
645
|
diagnostics: [{ code: "instance-row-count", severity: "info", message: "历史实例未保存原始取数行数;本次 rows 统计为 0,页面及单元格数由已保存计划校验。" }],
|
|
642
|
-
stats: { rows: 0, pages:
|
|
643
|
-
...
|
|
646
|
+
stats: { rows: 0, pages: y.plan.pages.length, cells: 0, durationMs: 0 },
|
|
647
|
+
...y.output
|
|
644
648
|
};
|
|
645
|
-
return e.runtime.exportPrepared({ prepared:
|
|
649
|
+
return e.runtime.exportPrepared({ prepared: m, format: c, fidelity: i, pdf: w, xlsx: g, signal: f, taskId: d, correlationId: l, onEvent: p });
|
|
646
650
|
},
|
|
647
651
|
/** Instance edits are explicit snapshots; source business persistence remains the Provider.save responsibility. */
|
|
648
652
|
save: n.save
|
|
649
653
|
};
|
|
650
654
|
}
|
|
651
|
-
function
|
|
655
|
+
function _(e, t, r) {
|
|
652
656
|
if (!Number.isSafeInteger(e) || e < 1 || e > t) throw new RangeError(`${r} 应为 1–${t} 的安全整数`);
|
|
653
657
|
return e;
|
|
654
658
|
}
|
|
655
|
-
function
|
|
659
|
+
function oe(e) {
|
|
656
660
|
if (!e || typeof e.key != "string" || !e.key.trim() || e.key.length > 1024 || !["pdf", "xlsx"].includes(e.format) || !Number.isSafeInteger(e.bytes) || e.bytes < 0 || e.sha256 !== void 0 && !/^[a-f0-9]{64}$/i.test(e.sha256)) throw new TypeError("分批归档回执应包含存储键、格式、大小和可选 SHA256");
|
|
657
661
|
return { key: e.key, format: e.format, bytes: e.bytes, ...e.sha256 ? { sha256: e.sha256 } : {} };
|
|
658
662
|
}
|
|
659
|
-
function
|
|
660
|
-
if (!
|
|
663
|
+
function We(e) {
|
|
664
|
+
if (!je(e).ok || !e.repeat) throw new TypeError("分批生成仅支持有效的逐记录固定标签模板");
|
|
661
665
|
return JSON.parse(JSON.stringify(e));
|
|
662
666
|
}
|
|
663
|
-
function
|
|
667
|
+
function Ye(e) {
|
|
664
668
|
const t = /* @__PURE__ */ new Set(), r = e.repeat;
|
|
665
669
|
r.rowKey && t.add(r.rowKey), typeof r.copies == "object" && t.add(r.copies.field);
|
|
666
670
|
const n = (s) => {
|
|
@@ -669,29 +673,29 @@ function _e(e) {
|
|
|
669
673
|
};
|
|
670
674
|
return e.pages.forEach((s) => s.components.forEach((a) => n(a))), [...t];
|
|
671
675
|
}
|
|
672
|
-
function
|
|
676
|
+
function et(e, t, r, n) {
|
|
673
677
|
if (!e || typeof e != "object" || Array.isArray(e)) throw new TypeError(`标签记录 ${n} 应为对象`);
|
|
674
678
|
const s = /* @__PURE__ */ Object.create(null);
|
|
675
679
|
for (const a of t) {
|
|
676
|
-
const o =
|
|
677
|
-
if (typeof o == "string" && o.length > 1e6) throw new
|
|
680
|
+
const o = we(e, a, { dataset: r, rowIndex: n });
|
|
681
|
+
if (typeof o == "string" && o.length > 1e6) throw new A("budget", "标签字段超过 1 MB 字符预算", `$.datasets.${r}[${n}].${a}`);
|
|
678
682
|
o !== void 0 && (s[a] = o);
|
|
679
683
|
}
|
|
680
684
|
return s;
|
|
681
685
|
}
|
|
682
|
-
function
|
|
686
|
+
function tt(e, t, r, n) {
|
|
683
687
|
const s = t.repeat;
|
|
684
688
|
if (!s.rowKey) return;
|
|
685
|
-
const a =
|
|
689
|
+
const a = we(e, s.rowKey, { rowIndex: n, dataset: s.dataset });
|
|
686
690
|
if (!(typeof a == "string" && a.trim() || typeof a == "number" && Number.isFinite(a))) throw new TypeError(`标签记录 ${n} 的业务主键无效`);
|
|
687
691
|
const o = JSON.stringify([typeof a, a]);
|
|
688
692
|
if (r.keys.has(o)) throw new TypeError(`标签记录 ${n} 的业务主键重复(包含先前批次)`);
|
|
689
693
|
r.bytes += o.length * 2 + 64, r.keys.add(o);
|
|
690
694
|
}
|
|
691
|
-
function
|
|
695
|
+
function rt(e) {
|
|
692
696
|
return Object.entries(e).reduce((t, [r, n]) => t + 64 + r.length * 2 + (typeof n == "string" ? n.length * 2 : 8), 0);
|
|
693
697
|
}
|
|
694
|
-
function
|
|
698
|
+
function nt(e, t) {
|
|
695
699
|
if (!t) return e;
|
|
696
700
|
for (const r of e.plan.pages) {
|
|
697
701
|
const n = r.meta?.record;
|
|
@@ -699,7 +703,7 @@ function Ke(e, t) {
|
|
|
699
703
|
}
|
|
700
704
|
return e;
|
|
701
705
|
}
|
|
702
|
-
async function
|
|
706
|
+
async function st(e, t) {
|
|
703
707
|
if (!e.return) return;
|
|
704
708
|
const r = Promise.resolve(e.return());
|
|
705
709
|
if (t.aborted) {
|
|
@@ -707,106 +711,106 @@ async function Ge(e, t) {
|
|
|
707
711
|
});
|
|
708
712
|
return;
|
|
709
713
|
}
|
|
710
|
-
await
|
|
714
|
+
await T(t, void 0, () => r);
|
|
711
715
|
}
|
|
712
|
-
async function
|
|
716
|
+
async function ie(e, t, r) {
|
|
713
717
|
const n = Promise.resolve().then(() => e.onReceipt?.(t, r));
|
|
714
718
|
n.catch(() => {
|
|
715
|
-
}), await
|
|
719
|
+
}), await T(r.signal, void 0, () => n);
|
|
716
720
|
}
|
|
717
|
-
function
|
|
721
|
+
function at(e, t, r) {
|
|
718
722
|
return new Promise((n, s) => {
|
|
719
|
-
let a = !1, o = !1,
|
|
720
|
-
const
|
|
721
|
-
clearTimeout(
|
|
722
|
-
},
|
|
723
|
-
a ||
|
|
723
|
+
let a = !1, o = !1, u;
|
|
724
|
+
const f = () => {
|
|
725
|
+
clearTimeout(u), t.removeEventListener("abort", c);
|
|
726
|
+
}, c = () => {
|
|
727
|
+
a || u !== void 0 || (u = setTimeout(() => {
|
|
724
728
|
if (!a) {
|
|
725
|
-
a = !0, o = !0,
|
|
729
|
+
a = !0, o = !0, f();
|
|
726
730
|
try {
|
|
727
|
-
|
|
728
|
-
} catch (
|
|
729
|
-
s(
|
|
731
|
+
h(t);
|
|
732
|
+
} catch (i) {
|
|
733
|
+
s(i);
|
|
730
734
|
}
|
|
731
735
|
}
|
|
732
736
|
}, 0));
|
|
733
737
|
};
|
|
734
|
-
e.then((
|
|
738
|
+
e.then((i) => {
|
|
735
739
|
if (o) {
|
|
736
|
-
Promise.resolve().then(() => r(
|
|
740
|
+
Promise.resolve().then(() => r(i)).catch(() => {
|
|
737
741
|
});
|
|
738
742
|
return;
|
|
739
743
|
}
|
|
740
|
-
a || (a = !0,
|
|
741
|
-
}, (
|
|
742
|
-
a || (a = !0,
|
|
743
|
-
}), t.addEventListener("abort",
|
|
744
|
+
a || (a = !0, f(), n(i));
|
|
745
|
+
}, (i) => {
|
|
746
|
+
a || (a = !0, f(), s(i));
|
|
747
|
+
}), t.addEventListener("abort", c, { once: !0 }), t.aborted && c();
|
|
744
748
|
});
|
|
745
749
|
}
|
|
746
|
-
async function
|
|
747
|
-
const r =
|
|
750
|
+
async function Ht(e, t) {
|
|
751
|
+
const r = _(t.batchSize ?? 100, 1e3, "batchSize"), n = _(t.maxRows ?? 1e5, 1e6, "maxRows"), s = _(t.maxChunks ?? 1e3, 1e4, "maxChunks"), a = _(t.maxRetainedBytes ?? 16e6, 64e6, "maxRetainedBytes"), o = We(t.template), u = Ye(o);
|
|
748
752
|
if (!e || typeof e[Symbol.asyncIterator] != "function") throw new TypeError("标签来源应为 AsyncIterable");
|
|
749
|
-
return
|
|
750
|
-
const
|
|
751
|
-
let
|
|
752
|
-
const
|
|
753
|
-
|
|
753
|
+
return T(t.signal, t.runtime?.budget?.maxDurationMs ?? 12e4, async (f) => {
|
|
754
|
+
const c = { rows: 0, chunks: [] }, i = { keys: /* @__PURE__ */ new Set(), bytes: 0 }, d = e[Symbol.asyncIterator]();
|
|
755
|
+
let l = !1, p = !1, w;
|
|
756
|
+
const g = () => w ??= st(d, f), y = () => {
|
|
757
|
+
l || g().catch(() => {
|
|
754
758
|
});
|
|
755
759
|
};
|
|
756
|
-
|
|
760
|
+
f.addEventListener("abort", y, { once: !0 });
|
|
757
761
|
try {
|
|
758
|
-
for (; !
|
|
759
|
-
|
|
760
|
-
const
|
|
761
|
-
let
|
|
762
|
-
for (;
|
|
763
|
-
const
|
|
764
|
-
if (
|
|
765
|
-
|
|
762
|
+
for (; !l; ) {
|
|
763
|
+
h(f);
|
|
764
|
+
const m = [];
|
|
765
|
+
let v = 0;
|
|
766
|
+
for (; m.length < r; ) {
|
|
767
|
+
const I = await T(f, void 0, () => Promise.resolve(d.next()));
|
|
768
|
+
if (I.done) {
|
|
769
|
+
l = !0;
|
|
766
770
|
break;
|
|
767
771
|
}
|
|
768
|
-
if (
|
|
769
|
-
if (
|
|
770
|
-
const
|
|
771
|
-
if (
|
|
772
|
-
|
|
772
|
+
if (c.rows + m.length >= n) throw new A("budget", "标签来源行数超过预算", "$.maxRows");
|
|
773
|
+
if (c.chunks.length >= s) throw new A("budget", "标签分块数量超过预算", "$.maxChunks");
|
|
774
|
+
const S = et(I.value, u, o.repeat.dataset, c.rows + m.length);
|
|
775
|
+
if (tt(S, o, i, c.rows + m.length), v += rt(S), i.bytes + v > a) throw new A("budget", "标签当前块字段与全局主键索引超过内存预算", "$.maxRetainedBytes");
|
|
776
|
+
m.push(S);
|
|
773
777
|
}
|
|
774
|
-
if (!
|
|
775
|
-
const
|
|
776
|
-
let
|
|
777
|
-
const
|
|
778
|
-
index:
|
|
779
|
-
rowOffset:
|
|
780
|
-
rowCount:
|
|
781
|
-
signal:
|
|
782
|
-
export: (
|
|
778
|
+
if (!m.length) break;
|
|
779
|
+
const N = W({ ...t.runtime, reports: { labels: { template: o, datasets: { [o.repeat.dataset]: m } } } });
|
|
780
|
+
let M;
|
|
781
|
+
const E = {
|
|
782
|
+
index: c.chunks.length,
|
|
783
|
+
rowOffset: c.rows,
|
|
784
|
+
rowCount: m.length,
|
|
785
|
+
signal: f,
|
|
786
|
+
export: (I) => N.exportPrepared({ pdf: t.pdf, ...I, prepared: M, signal: f })
|
|
783
787
|
};
|
|
784
|
-
let
|
|
785
|
-
const
|
|
788
|
+
let C;
|
|
789
|
+
const B = (await Oe([{ id: `labels-${E.index}`, params: {} }], async () => {
|
|
786
790
|
try {
|
|
787
|
-
|
|
788
|
-
const
|
|
789
|
-
return
|
|
790
|
-
} catch (
|
|
791
|
-
throw
|
|
791
|
+
M = nt(await N.prepare({ reportIds: ["labels"], pdf: t.pdf, signal: f }), E.rowOffset), h(f);
|
|
792
|
+
const I = Promise.resolve(t.execute(M, E)), S = await at(I, f, (k) => ie(t, oe(k), E));
|
|
793
|
+
return oe(S);
|
|
794
|
+
} catch (I) {
|
|
795
|
+
throw C = I, I;
|
|
792
796
|
}
|
|
793
|
-
}, { concurrency: 1, signal:
|
|
794
|
-
if (
|
|
795
|
-
throw
|
|
796
|
-
if (
|
|
797
|
-
|
|
797
|
+
}, { concurrency: 1, signal: f, failure: "stop" }))[0];
|
|
798
|
+
if (B.status === "cancelled")
|
|
799
|
+
throw h(f), new Error("标签分批任务已取消");
|
|
800
|
+
if (B.status === "failed") throw C ?? new Error(B.error.message);
|
|
801
|
+
c.chunks.push({ ...B.value, index: E.index, rowOffset: E.rowOffset, rowCount: E.rowCount }), c.rows += m.length, await ie(t, B.value, E);
|
|
798
802
|
}
|
|
799
|
-
return
|
|
800
|
-
} catch (
|
|
801
|
-
throw
|
|
803
|
+
return c;
|
|
804
|
+
} catch (m) {
|
|
805
|
+
throw p = !0, m;
|
|
802
806
|
} finally {
|
|
803
|
-
|
|
804
|
-
if (!
|
|
807
|
+
f.removeEventListener("abort", y), l || await g().catch((m) => {
|
|
808
|
+
if (!p) throw m;
|
|
805
809
|
});
|
|
806
810
|
}
|
|
807
811
|
});
|
|
808
812
|
}
|
|
809
|
-
async function
|
|
813
|
+
async function ot(e, t) {
|
|
810
814
|
const r = t.document().id, n = () => t.editor.saving || t.editor.blocked;
|
|
811
815
|
if (n()) throw new Error("草稿尚未保存,请处理设计器提示后再发布");
|
|
812
816
|
if (t.editor.pendingLocalChanges) {
|
|
@@ -814,106 +818,106 @@ async function Ze(e, t) {
|
|
|
814
818
|
if (await t.editor.save(), await t.afterSave(), t.successfulSaves() === a || t.editor.pendingLocalChanges || n()) throw new Error("草稿尚未保存,请处理设计器提示后再发布");
|
|
815
819
|
}
|
|
816
820
|
const s = t.document();
|
|
817
|
-
if (s.id !== r) throw new
|
|
821
|
+
if (s.id !== r) throw new b("conflict", "当前模板已切换,请重新确认后发布");
|
|
818
822
|
return e.publish(s.id, { expectedRevision: s.revision ?? null });
|
|
819
823
|
}
|
|
820
|
-
function
|
|
824
|
+
function it(e, t) {
|
|
821
825
|
return {
|
|
822
826
|
async search(r) {
|
|
823
|
-
|
|
827
|
+
h(r.signal);
|
|
824
828
|
const n = await e.list(r.signal);
|
|
825
829
|
if (n.length > 1e3) throw new RangeError("本地模板连接目录最多 1000 项;更大目录请使用宿主分页查询适配器");
|
|
826
830
|
const s = [];
|
|
827
831
|
for (const a of n) {
|
|
828
|
-
|
|
829
|
-
const [o,
|
|
830
|
-
|
|
832
|
+
h(r.signal);
|
|
833
|
+
const [o, u] = await Promise.all([e.get(a.id, { draft: !0, signal: r.signal }), e.get(a.id, { signal: r.signal })]), f = o ?? u;
|
|
834
|
+
f && s.push({ document: f, published: u, draftRevision: o?.revision, publishedRevision: u?.revision, ...t?.($(f)) });
|
|
831
835
|
}
|
|
832
|
-
return
|
|
836
|
+
return Pe(s).search(r);
|
|
833
837
|
},
|
|
834
838
|
async get(r, n) {
|
|
835
839
|
return n.mode === "published" ? e.get(r, { signal: n.signal }) : await e.get(r, { draft: !0, signal: n.signal }) ?? e.get(r, { signal: n.signal });
|
|
836
840
|
}
|
|
837
841
|
};
|
|
838
842
|
}
|
|
839
|
-
function
|
|
843
|
+
function ct(e = 1e3) {
|
|
840
844
|
if (!Number.isSafeInteger(e) || e < 1 || e > 1e3) throw new RangeError("本地生成意图上限应为 1–1000");
|
|
841
845
|
const t = /* @__PURE__ */ new Map(), r = globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
842
846
|
return {
|
|
843
847
|
forCase(n, s) {
|
|
844
|
-
if (![n, s].every((
|
|
848
|
+
if (![n, s].every((f) => typeof f == "string" && f.length > 0 && f.length <= 256)) throw new TypeError("模板与参数组标识无效");
|
|
845
849
|
const a = JSON.stringify([n, s]), o = t.get(a);
|
|
846
850
|
if (o) return o;
|
|
847
851
|
if (t.size >= e) throw new RangeError("本地生成意图已达上限,请使用持久化任务服务");
|
|
848
|
-
const
|
|
849
|
-
return t.set(a,
|
|
852
|
+
const u = `instance-${r}-${(t.size + 1).toString(36)}`;
|
|
853
|
+
return t.set(a, u), u;
|
|
850
854
|
}
|
|
851
855
|
};
|
|
852
856
|
}
|
|
853
|
-
function
|
|
857
|
+
function ft(e, t, r) {
|
|
854
858
|
const n = Object.keys(r);
|
|
855
859
|
return e.reportIds.length === 1 && e.reportIds[0] === t.id && Object.keys(e.templateRevisions).length === 1 && e.templateRevisions[t.id] === t.revision && Object.keys(e.params).length === n.length && n.every((s) => r[s] === e.params[s]);
|
|
856
860
|
}
|
|
857
|
-
function
|
|
861
|
+
function ce(e) {
|
|
858
862
|
return { instanceId: e.id, label: e.title };
|
|
859
863
|
}
|
|
860
|
-
function
|
|
861
|
-
const n =
|
|
864
|
+
function dt(e, t, r) {
|
|
865
|
+
const n = $(e);
|
|
862
866
|
if (!n.revision) throw new Error("请先发布该模板");
|
|
863
|
-
const s = typeof t.data == "function" ? t.data(
|
|
864
|
-
async function f
|
|
865
|
-
|
|
866
|
-
const d = await t.instances.read(t.scope,
|
|
867
|
-
if (
|
|
868
|
-
if (!
|
|
869
|
-
return
|
|
867
|
+
const s = typeof t.data == "function" ? t.data($(n)) : t.data, a = W({ ...t.runtime, reports: { [n.id]: { ...s, template: n.template } } }), o = Qe({ runtime: a, instances: t.instances, templateRevisions: { [n.id]: n.revision }, pdf: t.pdf });
|
|
868
|
+
async function u(f, c, i) {
|
|
869
|
+
h(i);
|
|
870
|
+
const d = await t.instances.read(t.scope, f, void 0, i);
|
|
871
|
+
if (h(i), !!d) {
|
|
872
|
+
if (!ft(d, n, c)) throw new b("conflict", "此参数组已用于其他参数或发布修订,请复制为新任务生成");
|
|
873
|
+
return ce(d);
|
|
870
874
|
}
|
|
871
875
|
}
|
|
872
876
|
return {
|
|
873
|
-
document:
|
|
874
|
-
async execute(
|
|
875
|
-
|
|
876
|
-
const
|
|
877
|
-
if (!
|
|
878
|
-
const d = r(n.id,
|
|
879
|
-
if (
|
|
877
|
+
document: $(n),
|
|
878
|
+
async execute(f, { signal: c }) {
|
|
879
|
+
h(c);
|
|
880
|
+
const i = a.validate({ reportIds: [n.id], params: f.params });
|
|
881
|
+
if (!i.ok) throw new Error(i.issues[0]?.message ?? "生成参数无效");
|
|
882
|
+
const d = r(n.id, f.id), l = await u(d, i.values, c);
|
|
883
|
+
if (l) return l;
|
|
880
884
|
try {
|
|
881
|
-
return
|
|
885
|
+
return ce(await o.generate({
|
|
882
886
|
scope: t.scope,
|
|
883
887
|
id: d,
|
|
884
|
-
title: (t.title?.(
|
|
888
|
+
title: (t.title?.($(n), f, i.values) ?? `${n.name} · ${f.id}`).slice(0, 512),
|
|
885
889
|
reportIds: [n.id],
|
|
886
|
-
params:
|
|
890
|
+
params: i.values,
|
|
887
891
|
expectedRevision: null,
|
|
888
|
-
signal:
|
|
892
|
+
signal: c
|
|
889
893
|
}));
|
|
890
|
-
} catch (
|
|
891
|
-
if (
|
|
892
|
-
const
|
|
893
|
-
if (
|
|
894
|
+
} catch (p) {
|
|
895
|
+
if (p instanceof b && p.code === "conflict") {
|
|
896
|
+
const w = await u(d, i.values, c);
|
|
897
|
+
if (w) return w;
|
|
894
898
|
}
|
|
895
|
-
throw
|
|
899
|
+
throw p;
|
|
896
900
|
}
|
|
897
901
|
}
|
|
898
902
|
};
|
|
899
903
|
}
|
|
900
|
-
function
|
|
904
|
+
function Ut(e) {
|
|
901
905
|
e = { ...e };
|
|
902
|
-
const t =
|
|
906
|
+
const t = ct(), r = e.instanceId ?? t.forCase;
|
|
903
907
|
return {
|
|
904
|
-
catalog: e.catalog ??
|
|
905
|
-
publish: (n) =>
|
|
908
|
+
catalog: e.catalog ?? it(e.templates, e.catalogMetadata),
|
|
909
|
+
publish: (n) => ot(e.templates, n),
|
|
906
910
|
/** Resolve only a manager-owned publication, then keep that exact revision for this batch. */
|
|
907
911
|
async batch(n, s = {}) {
|
|
908
|
-
const { expectedRevision: a, signal: o } = s,
|
|
909
|
-
if (
|
|
910
|
-
if (a !== void 0 &&
|
|
911
|
-
return
|
|
912
|
+
const { expectedRevision: a, signal: o } = s, u = await e.templates.get(n, { signal: o });
|
|
913
|
+
if (h(o), !u?.revision) throw new Error("请先发布该模板");
|
|
914
|
+
if (a !== void 0 && u.revision !== a) throw new b("conflict", "模板发布版本已变化,请重新打开后生成");
|
|
915
|
+
return dt(u, e, r);
|
|
912
916
|
}
|
|
913
917
|
};
|
|
914
918
|
}
|
|
915
|
-
const
|
|
916
|
-
function
|
|
919
|
+
const be = "2.18.0";
|
|
920
|
+
function U(e, t) {
|
|
917
921
|
const r = t?.componentPath;
|
|
918
922
|
if (!Number.isSafeInteger(t?.pageIndex) || t.pageIndex < 0 || !Array.isArray(r) || r.length < 1 || r.length > 31 || r.length % 3 !== 1 || r.some((s) => !Number.isSafeInteger(s) || s < 0)) throw new TypeError("模板包图片位置无效");
|
|
919
923
|
let n = e.template.pages[t.pageIndex]?.components[r[0]];
|
|
@@ -921,15 +925,15 @@ function L(e, t) {
|
|
|
921
925
|
if (!n || n.kind !== "image" || n.binding) throw new TypeError("模板包图片位置应指向静态图片组件");
|
|
922
926
|
return n;
|
|
923
927
|
}
|
|
924
|
-
function
|
|
928
|
+
function ut(e) {
|
|
925
929
|
const t = ["id", "kind", "mediaType", "bytes", "sha256", "license", "font", "targets"];
|
|
926
930
|
if (!e || Object.keys(e).some((r) => !t.includes(r))) throw new TypeError("模板资源包含未知字段");
|
|
927
931
|
if (typeof e.id != "string" || !/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{0,127}$/.test(e.id)) throw new TypeError("模板资源ID应为安全标识");
|
|
928
932
|
if (!Number.isSafeInteger(e.bytes) || e.bytes < 1 || e.bytes > 32e6 || !/^[a-f0-9]{64}$/.test(e.sha256)) throw new TypeError("模板资源大小或SHA256无效");
|
|
929
933
|
if (e.license !== void 0 && (typeof e.license != "string" || e.license.length > 512)) throw new TypeError("模板资源许可说明无效");
|
|
930
934
|
}
|
|
931
|
-
function
|
|
932
|
-
if (
|
|
935
|
+
function lt(e, t) {
|
|
936
|
+
if (ut(e), e.kind === "font") {
|
|
933
937
|
if (!["font/ttf", "font/otf"].includes(e.mediaType) || e.targets !== void 0) throw new TypeError("字体资源类型无效");
|
|
934
938
|
const r = e.font;
|
|
935
939
|
if (!r || typeof r.family != "string" || !r.family.trim() || r.family.length > 128 || !["regular", "bold", "italic", "boldItalic"].includes(r.face) || Object.keys(r).some((n) => !["family", "face"].includes(n))) throw new TypeError("字体资源需要family和face");
|
|
@@ -939,174 +943,413 @@ function rt(e, t) {
|
|
|
939
943
|
if (!Array.isArray(e.targets) || !e.targets.length || e.targets.length > 1e3) throw new TypeError("模板图片需要1–1000个位置");
|
|
940
944
|
for (const r of e.targets) {
|
|
941
945
|
if (Object.keys(r).some((n) => !["pageIndex", "componentPath"].includes(n))) throw new TypeError("模板图片位置包含未知字段");
|
|
942
|
-
|
|
946
|
+
U(t, r);
|
|
943
947
|
}
|
|
944
948
|
}
|
|
945
|
-
function
|
|
949
|
+
function pt(e, t) {
|
|
946
950
|
const r = (n) => n.every((s, a) => e[a] === s);
|
|
947
951
|
return t === "image/png" ? r([137, 80, 78, 71, 13, 10, 26, 10]) : t === "image/jpeg" ? r([255, 216, 255]) : t === "font/otf" ? r([79, 84, 84, 79]) : r([0, 1, 0, 0]) || r([116, 114, 117, 101]);
|
|
948
952
|
}
|
|
949
|
-
function
|
|
953
|
+
function wt(e) {
|
|
950
954
|
if (!(e instanceof Uint8Array) || !e.byteLength || e.byteLength > 32e6) throw new RangeError("资源摘要只接受1–32MB字节");
|
|
951
|
-
return
|
|
955
|
+
return Re(e);
|
|
952
956
|
}
|
|
953
|
-
function
|
|
954
|
-
const n = new Set(t.flatMap((o) => (o.targets ?? []).map((
|
|
957
|
+
function ve(e, t, r = me()) {
|
|
958
|
+
const n = new Set(t.flatMap((o) => (o.targets ?? []).map((u) => U(e, u)))), s = /* @__PURE__ */ new Map(), a = (o) => {
|
|
955
959
|
if (o.imageData && !n.has(o)) {
|
|
956
|
-
const
|
|
957
|
-
s.set(
|
|
960
|
+
const u = r(o.imageData);
|
|
961
|
+
s.set(u.dataUrl, u.bytes.byteLength);
|
|
958
962
|
}
|
|
959
|
-
for (const
|
|
963
|
+
for (const u of o.grid?.cells ?? []) for (const f of u) for (const c of f?.children ?? []) a(c);
|
|
960
964
|
};
|
|
961
|
-
for (const o of e.template.pages) for (const
|
|
962
|
-
return [...s.values()].reduce((o,
|
|
965
|
+
for (const o of e.template.pages) for (const u of o.components) a(u);
|
|
966
|
+
return [...s.values()].reduce((o, u) => o + u, 0);
|
|
963
967
|
}
|
|
964
|
-
function
|
|
968
|
+
function yt(e, t) {
|
|
965
969
|
let r = "";
|
|
966
970
|
for (let n = 0; n < e.length; n += 16384) r += String.fromCharCode(...e.subarray(n, n + 16384));
|
|
967
971
|
return `data:${t};base64,${btoa(r)}`;
|
|
968
972
|
}
|
|
969
|
-
async function
|
|
973
|
+
async function mt(e, t, r, n, s = 3e4) {
|
|
970
974
|
if (!Number.isFinite(s) || s < 1 || s > 2147483647) throw new RangeError("模板资源加载超时应为1–2147483647毫秒");
|
|
971
|
-
return
|
|
972
|
-
const o = [],
|
|
973
|
-
|
|
974
|
-
for (const
|
|
975
|
-
|
|
976
|
-
const
|
|
977
|
-
if (
|
|
978
|
-
const
|
|
979
|
-
if (!
|
|
980
|
-
if (
|
|
975
|
+
return T(n, s, async (a) => {
|
|
976
|
+
const o = [], u = me();
|
|
977
|
+
ve(e, t, u);
|
|
978
|
+
for (const f of t) {
|
|
979
|
+
h(a);
|
|
980
|
+
const c = await T(a, void 0, () => Promise.resolve(r(JSON.parse(JSON.stringify(f)), { signal: a })));
|
|
981
|
+
if (h(a), !c || !(c.bytes instanceof Uint8Array) || c.mediaType !== f.mediaType || c.bytes.byteLength !== f.bytes) throw new TypeError(`资源 ${f.id} 的类型或大小与清单不一致`);
|
|
982
|
+
const i = new Uint8Array(c.bytes);
|
|
983
|
+
if (!pt(i, f.mediaType) || wt(i) !== f.sha256) throw new TypeError(`资源 ${f.id} 的文件标识或SHA256与清单不一致`);
|
|
984
|
+
if (f.kind === "font") o.push({ id: f.id, family: f.font.family, face: f.font.face, bytes: i });
|
|
981
985
|
else {
|
|
982
|
-
const d =
|
|
983
|
-
for (const
|
|
986
|
+
const d = u(yt(i, f.mediaType)).dataUrl;
|
|
987
|
+
for (const l of f.targets) U(e, l).imageData = d;
|
|
984
988
|
}
|
|
985
989
|
}
|
|
986
990
|
return o;
|
|
987
991
|
});
|
|
988
992
|
}
|
|
989
|
-
function
|
|
993
|
+
function fe(e) {
|
|
990
994
|
if (typeof e != "string" || !/^(0|[1-9]\d{0,5})\.(0|[1-9]\d{0,5})\.(0|[1-9]\d{0,5})$/.test(e)) throw new TypeError("模板包最低版本与运行版本应为正式版本x.y.z");
|
|
991
995
|
return e.split(".").map(Number);
|
|
992
996
|
}
|
|
993
|
-
function
|
|
994
|
-
const r =
|
|
997
|
+
function gt(e, t) {
|
|
998
|
+
const r = fe(e), n = fe(t);
|
|
995
999
|
for (let s = 0; s < 3; s++) {
|
|
996
1000
|
if (n[s] > r[s]) return;
|
|
997
1001
|
if (n[s] < r[s]) throw new Error(`模板包需要MachReport ${e}或更新版本`);
|
|
998
1002
|
}
|
|
999
1003
|
}
|
|
1000
|
-
function
|
|
1004
|
+
function Q(e, t, r) {
|
|
1001
1005
|
const n = e ?? t;
|
|
1002
1006
|
if (!Number.isSafeInteger(n) || n < 1 || n > r) throw new RangeError("模板包字节预算无效");
|
|
1003
1007
|
return n;
|
|
1004
1008
|
}
|
|
1005
|
-
function
|
|
1009
|
+
function ht(e) {
|
|
1006
1010
|
if (e.contracts !== void 0) {
|
|
1007
1011
|
if (!e.contracts || typeof e.contracts != "object" || Array.isArray(e.contracts) || Object.keys(e.contracts).length > 100) throw new TypeError("模板包字段契约应为最多100个数据集");
|
|
1008
1012
|
for (const [t, r] of Object.entries(e.contracts)) {
|
|
1009
1013
|
if (!t.trim() || t.length > 256) throw new TypeError("模板包数据集名称无效");
|
|
1010
|
-
|
|
1014
|
+
ye([], r);
|
|
1011
1015
|
}
|
|
1012
1016
|
}
|
|
1013
1017
|
}
|
|
1014
|
-
function
|
|
1018
|
+
function bt(e, t) {
|
|
1015
1019
|
if (!e || e.deidentified !== !0 || typeof e.name != "string" || !e.name.trim() || e.name.length > 128) throw new TypeError("样例需要名称和明确的deidentified:true确认");
|
|
1016
1020
|
if (Object.keys(e).some((n) => !["name", "deidentified", "datasets", "params"].includes(n))) throw new TypeError("模板包样例包含未知字段");
|
|
1017
1021
|
if (!e.datasets || typeof e.datasets != "object" || Array.isArray(e.datasets)) throw new TypeError("模板包样例数据集无效");
|
|
1018
|
-
if (
|
|
1022
|
+
if (vt(e, t), !Be(t.document.template.params ?? [], e.params).ok) throw new TypeError(`样例 ${e.name} 的参数不符合模板定义`);
|
|
1019
1023
|
}
|
|
1020
|
-
function
|
|
1024
|
+
function vt(e, t) {
|
|
1021
1025
|
let r = 0;
|
|
1022
1026
|
for (const s of Object.values(e.datasets))
|
|
1023
1027
|
if (!Array.isArray(s) || s.some((a) => !a || typeof a != "object" || Array.isArray(a))) throw new TypeError("模板包样例应为对象行数组");
|
|
1024
|
-
const n =
|
|
1028
|
+
const n = Ie(t.document.template, e.datasets, { maxRows: 1e3 });
|
|
1025
1029
|
for (const [s, a] of Object.entries(n)) {
|
|
1026
1030
|
if (r += a.length, r > 1e3) throw new RangeError("模板包每个样例最多1000行");
|
|
1027
1031
|
const o = t.contracts?.[s];
|
|
1028
|
-
if (o && !
|
|
1032
|
+
if (o && !ye(a, o).ok) throw new TypeError(`样例 ${e.name} 不符合 ${s} 字段契约`);
|
|
1029
1033
|
}
|
|
1030
1034
|
for (const s of Object.keys(t.contracts ?? {})) if (!Object.prototype.hasOwnProperty.call(e.datasets, s)) throw new TypeError(`样例 ${e.name} 缺少 ${s} 数据集`);
|
|
1031
1035
|
}
|
|
1032
|
-
function
|
|
1036
|
+
function xt(e) {
|
|
1033
1037
|
if (e.fixtures === void 0) return;
|
|
1034
1038
|
if (!Array.isArray(e.fixtures) || e.fixtures.length > 20) throw new RangeError("模板包最多20个脱敏样例");
|
|
1035
1039
|
const t = /* @__PURE__ */ new Set();
|
|
1036
1040
|
for (const r of e.fixtures) {
|
|
1037
|
-
if (
|
|
1041
|
+
if (bt(r, e), t.has(r.name)) throw new TypeError("模板包样例名称重复");
|
|
1038
1042
|
t.add(r.name);
|
|
1039
1043
|
}
|
|
1040
1044
|
}
|
|
1041
|
-
function
|
|
1045
|
+
function Rt(e, t) {
|
|
1042
1046
|
if (!Array.isArray(e.resources) || e.resources.length > 64) throw new RangeError("模板包最多64个资源依赖");
|
|
1043
1047
|
const r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
|
|
1044
1048
|
let a = 0;
|
|
1045
1049
|
for (const o of e.resources) {
|
|
1046
|
-
if (
|
|
1050
|
+
if (lt(o, e.document), r.has(o.id)) throw new TypeError("模板资源ID重复");
|
|
1047
1051
|
if (r.add(o.id), a += o.bytes, a > t) throw new RangeError("模板包资源总大小超过预算");
|
|
1048
|
-
const
|
|
1049
|
-
if (
|
|
1050
|
-
|
|
1051
|
-
for (const
|
|
1052
|
-
const
|
|
1053
|
-
if (n.has(
|
|
1054
|
-
n.add(
|
|
1052
|
+
const u = o.font && JSON.stringify([o.font.family, o.font.face]);
|
|
1053
|
+
if (u && s.has(u)) throw new TypeError("模板包字体family/face重复");
|
|
1054
|
+
u && s.add(u);
|
|
1055
|
+
for (const f of o.targets ?? []) {
|
|
1056
|
+
const c = JSON.stringify([f.pageIndex, f.componentPath]);
|
|
1057
|
+
if (n.has(c)) throw new TypeError("同一图片位置不能绑定多个资源");
|
|
1058
|
+
n.add(c);
|
|
1055
1059
|
}
|
|
1056
1060
|
}
|
|
1057
|
-
if (a +
|
|
1061
|
+
if (a + ve(e.document, e.resources) > t) throw new RangeError("模板包内嵌与外部资源总大小超过预算");
|
|
1058
1062
|
}
|
|
1059
|
-
function
|
|
1060
|
-
|
|
1061
|
-
const r =
|
|
1063
|
+
function xe(e, t = {}) {
|
|
1064
|
+
h(t.signal);
|
|
1065
|
+
const r = Q(t.maxBytes, 8e6, 32e6);
|
|
1062
1066
|
if (typeof e == "string") {
|
|
1063
1067
|
if (e.length > r || new TextEncoder().encode(e).byteLength > r) throw new RangeError("模板包JSON超过预算");
|
|
1064
1068
|
e = JSON.parse(e);
|
|
1065
1069
|
}
|
|
1066
|
-
const n =
|
|
1070
|
+
const n = Y(e, { maxBytes: r, check: () => h(t.signal), error: (s, a) => new TypeError(a) });
|
|
1067
1071
|
if (!n || typeof n != "object" || Array.isArray(n) || n.schemaVersion !== "1.0" || Object.keys(n).some((s) => !["schemaVersion", "minimumVersion", "document", "contracts", "resources", "fixtures"].includes(s))) throw new TypeError("模板包结构或版本无效");
|
|
1068
|
-
return
|
|
1072
|
+
return gt(n.minimumVersion, t.runtimeVersion ?? be), n.document = $(n.document), ht(n), xt(n), Rt(n, Q(t.maxResourceBytes, 32e6, 64e6)), n;
|
|
1069
1073
|
}
|
|
1070
|
-
function
|
|
1071
|
-
const r =
|
|
1072
|
-
for (const s of n.resources) for (const a of s.targets ?? []) delete
|
|
1074
|
+
function Kt(e, t = {}) {
|
|
1075
|
+
const r = Y(e, { maxBytes: Q(t.maxBytes, 8e6, 32e6), check: () => h(t.signal), error: (s, a) => new TypeError(a) }), n = xe({ schemaVersion: "1.0", ...r, minimumVersion: r.minimumVersion ?? be, resources: r.resources ?? [] }, t);
|
|
1076
|
+
for (const s of n.resources) for (const a of s.targets ?? []) delete U(n.document, a).imageData;
|
|
1073
1077
|
return n;
|
|
1074
1078
|
}
|
|
1075
|
-
async function
|
|
1076
|
-
const { resolve: r, signal: n, maxDurationMs: s } = t, a =
|
|
1079
|
+
async function Zt(e, t) {
|
|
1080
|
+
const { resolve: r, signal: n, maxDurationMs: s } = t, a = xe(e, t), o = await mt(a.document, a.resources, r, n, s);
|
|
1077
1081
|
return { document: a.document, fonts: o, contracts: a.contracts, fixtures: a.fixtures ?? [] };
|
|
1078
1082
|
}
|
|
1083
|
+
class x extends Error {
|
|
1084
|
+
constructor(t, r) {
|
|
1085
|
+
super(r), this.code = t, this.name = "ReportDocumentError";
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
function St(e = {}) {
|
|
1089
|
+
const t = { maxDocuments: e.maxDocuments ?? 32, maxBytes: e.maxBytes ?? 64e6, maxPages: e.maxPages ?? 1e4, maxPageBytes: e.maxPageBytes ?? 4e6, maxManifestBytes: e.maxManifestBytes ?? 1e6 };
|
|
1090
|
+
if (Object.values(t).some((r) => !Number.isSafeInteger(r) || r < 1)) throw new x("input", "文档预算应为正安全整数");
|
|
1091
|
+
return t;
|
|
1092
|
+
}
|
|
1093
|
+
function j(e, t, r) {
|
|
1094
|
+
if ([e, t, ...r === void 0 ? [] : [r]].some((n) => typeof n != "string" || !n.trim() || n.length > 256)) throw new x("input", "文档 scope、id、version 应为 1–256 位非空字符串");
|
|
1095
|
+
return JSON.stringify([e, t]);
|
|
1096
|
+
}
|
|
1097
|
+
function O(e, t, r) {
|
|
1098
|
+
return Y(e, { maxBytes: t, maxNodes: t, check: () => h(r), error: (n, s) => new x(n === "budget" ? "capacity" : "input", s) });
|
|
1099
|
+
}
|
|
1100
|
+
function D(e) {
|
|
1101
|
+
return new TextEncoder().encode(JSON.stringify(e)).byteLength;
|
|
1102
|
+
}
|
|
1103
|
+
function de(e) {
|
|
1104
|
+
if (!e || e.schemaVersion !== $e || "pages" in e || e.requiresRecalculation !== void 0 && typeof e.requiresRecalculation != "boolean") throw new x("input", "文档计划头应使用当前版本,且不得携带 pages");
|
|
1105
|
+
}
|
|
1106
|
+
function L(e, t) {
|
|
1107
|
+
e.bytes = 0;
|
|
1108
|
+
for (let r = 0; r < 8; r++) {
|
|
1109
|
+
const n = t + D(e);
|
|
1110
|
+
if (n === e.bytes) return;
|
|
1111
|
+
e.bytes = n;
|
|
1112
|
+
}
|
|
1113
|
+
throw new x("capacity", "文档容量统计无效");
|
|
1114
|
+
}
|
|
1115
|
+
function It(e, t, r = []) {
|
|
1116
|
+
const n = /* @__PURE__ */ new Map();
|
|
1117
|
+
let s = 0, a = Promise.resolve();
|
|
1118
|
+
for (const i of r) {
|
|
1119
|
+
const d = j(i.scope, i.id, i.version);
|
|
1120
|
+
if (de(i.plan), n.has(d) || !Number.isSafeInteger(i.bytes) || i.bytes < 0 || !Number.isSafeInteger(i.pageCount) || i.pageCount < 0 || i.pageCount > t.maxPages || !["building", "complete", "failed"].includes(i.state) || i.revision !== i.pageCount + (i.state === "building" ? 0 : 1)) throw new x("input", "文档清单无效");
|
|
1121
|
+
n.set(d, O(i, t.maxManifestBytes)), s += i.bytes;
|
|
1122
|
+
}
|
|
1123
|
+
function o(i, d) {
|
|
1124
|
+
if (s - (d?.bytes ?? 0) + i.bytes > t.maxBytes || !d && n.size >= t.maxDocuments) throw new x("capacity", "文档存储容量已满,请显式清理旧文档");
|
|
1125
|
+
}
|
|
1126
|
+
if (n.size > t.maxDocuments || s > t.maxBytes) throw new x("capacity", "已存文档超过预算");
|
|
1127
|
+
const u = (i) => {
|
|
1128
|
+
const d = a.then(i);
|
|
1129
|
+
return a = d.then(() => {
|
|
1130
|
+
}, () => {
|
|
1131
|
+
}), d;
|
|
1132
|
+
}, f = (i, d, l, p) => {
|
|
1133
|
+
const w = n.get(j(i, d, l));
|
|
1134
|
+
if (!w) throw new x("missing", "文档不存在");
|
|
1135
|
+
if (w.version !== l || p !== void 0 && w.revision !== p) throw new x("conflict", "文档已变化,请重新读取清单");
|
|
1136
|
+
return w;
|
|
1137
|
+
}, c = async (i, d, l) => {
|
|
1138
|
+
const p = O(i, t.maxManifestBytes);
|
|
1139
|
+
return o(p, d), await e.write(p, l), n.set(j(i.scope, i.id), p), s += i.bytes - (d?.bytes ?? 0), O(p, t.maxManifestBytes);
|
|
1140
|
+
};
|
|
1141
|
+
return {
|
|
1142
|
+
create: (i, d) => {
|
|
1143
|
+
const l = O(i, t.maxManifestBytes, d), p = j(l.scope, l.id, l.version);
|
|
1144
|
+
return de(l.plan), u(async () => {
|
|
1145
|
+
if (h(d), n.has(p)) throw new x("conflict", "文档已存在,不可覆盖");
|
|
1146
|
+
const w = { ...l, revision: 0, state: "building", pageCount: 0, bytes: 0 };
|
|
1147
|
+
return L(w, 0), c(w);
|
|
1148
|
+
});
|
|
1149
|
+
},
|
|
1150
|
+
append: (i, d, l, p, w, g) => {
|
|
1151
|
+
const y = O(w, t.maxPageBytes, g), m = le({ pages: [y] });
|
|
1152
|
+
if (!m.ok) throw new x("input", m.errors[0].message);
|
|
1153
|
+
return u(async () => {
|
|
1154
|
+
h(g);
|
|
1155
|
+
const v = f(i, d, l, p);
|
|
1156
|
+
if (v.state !== "building") throw new x("conflict", "已完成文档不可追加");
|
|
1157
|
+
if (v.pageCount >= t.maxPages) throw new x("capacity", "文档页数超过预算");
|
|
1158
|
+
const N = { ...v, revision: p + 1, pageCount: v.pageCount + 1 };
|
|
1159
|
+
return L(N, v.bytes - D(v) + D(y)), c(N, v, { index: v.pageCount, value: y });
|
|
1160
|
+
});
|
|
1161
|
+
},
|
|
1162
|
+
complete: (i, d, l, p, w, g) => {
|
|
1163
|
+
const y = w === void 0 ? void 0 : O(w, t.maxManifestBytes, g);
|
|
1164
|
+
return y && pe({ ...y }), u(async () => {
|
|
1165
|
+
h(g);
|
|
1166
|
+
const m = f(i, d, l, p);
|
|
1167
|
+
if (m.state !== "building") throw new x("conflict", "文档已完成");
|
|
1168
|
+
if (y && y.stats.pages !== m.pageCount) throw new x("input", "准备结果页数与文档页数不一致");
|
|
1169
|
+
const v = { ...m, revision: p + 1, state: "complete", ...y ? { metadata: y } : {} };
|
|
1170
|
+
return L(v, m.bytes - D(m)), c(v, m);
|
|
1171
|
+
});
|
|
1172
|
+
},
|
|
1173
|
+
fail: (i, d, l, p, w) => {
|
|
1174
|
+
const g = O(w, 4096);
|
|
1175
|
+
if (!g || !["cancelled", "generation"].includes(g.code) || typeof g.message != "string" || !g.message.trim() || g.message.length > 1024) throw new x("input", "文档失败状态无效");
|
|
1176
|
+
return u(async () => {
|
|
1177
|
+
const y = f(i, d, l, p);
|
|
1178
|
+
if (y.state !== "building") throw new x("conflict", "终态文档不可变更");
|
|
1179
|
+
const m = { ...y, state: "failed", revision: p + 1, failure: g };
|
|
1180
|
+
return L(m, y.bytes - D(y)), c(m, y);
|
|
1181
|
+
});
|
|
1182
|
+
},
|
|
1183
|
+
read: async (i, d, l) => {
|
|
1184
|
+
h(l);
|
|
1185
|
+
const p = j(i, d);
|
|
1186
|
+
await a, h(l);
|
|
1187
|
+
const w = n.get(p);
|
|
1188
|
+
return w ? O(w, t.maxManifestBytes) : void 0;
|
|
1189
|
+
},
|
|
1190
|
+
readPage: (i, d, l, p, w) => u(async () => {
|
|
1191
|
+
h(w);
|
|
1192
|
+
const g = f(i, d, l);
|
|
1193
|
+
if (!Number.isSafeInteger(p) || p < 0) throw new x("input", "页索引应为非负安全整数");
|
|
1194
|
+
if (p >= g.pageCount) return;
|
|
1195
|
+
const y = await e.readPage(i, d, p);
|
|
1196
|
+
if (h(w), !y) throw new x("missing", "已提交的文档页缺失");
|
|
1197
|
+
return O(y, t.maxPageBytes, w);
|
|
1198
|
+
}),
|
|
1199
|
+
remove: (i, d, l, p) => u(async () => {
|
|
1200
|
+
h(p);
|
|
1201
|
+
const w = j(i, d, l), g = n.get(w);
|
|
1202
|
+
return g ? (f(i, d, l), await e.remove(g), n.delete(w), s -= g.bytes, !0) : !1;
|
|
1203
|
+
})
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
function Xt(e = {}) {
|
|
1207
|
+
const t = /* @__PURE__ */ new Map();
|
|
1208
|
+
return It({
|
|
1209
|
+
write: async (r, n) => {
|
|
1210
|
+
if (!n) return;
|
|
1211
|
+
const s = j(r.scope, r.id), a = t.get(s) ?? [];
|
|
1212
|
+
a[n.index] = n.value, t.set(s, a);
|
|
1213
|
+
},
|
|
1214
|
+
readPage: async (r, n, s) => t.get(j(r, n))?.[s],
|
|
1215
|
+
remove: async (r) => {
|
|
1216
|
+
t.delete(j(r.scope, r.id));
|
|
1217
|
+
}
|
|
1218
|
+
}, St(e));
|
|
1219
|
+
}
|
|
1220
|
+
async function Gt(e, t) {
|
|
1221
|
+
const r = t.fromPage ?? 0, n = t.limit ?? 4, s = t.maxBytes ?? 8e6;
|
|
1222
|
+
if (!Number.isSafeInteger(r) || r < 0 || !Number.isSafeInteger(n) || n < 1 || n > 32 || !Number.isSafeInteger(s) || s < 1) throw new x("input", "页窗口参数无效;每次最多读取 32 页");
|
|
1223
|
+
const a = await e.read(t.scope, t.id, t.signal);
|
|
1224
|
+
if (!a) throw new x("missing", "文档不存在");
|
|
1225
|
+
if (a.version !== t.version) throw new x("conflict", "文档版本已变化");
|
|
1226
|
+
const o = [];
|
|
1227
|
+
let u = 0, f = Math.min(r, a.pageCount);
|
|
1228
|
+
for (; f < Math.min(a.pageCount, r + n); f++) {
|
|
1229
|
+
const c = await e.readPage(t.scope, t.id, t.version, f, t.signal);
|
|
1230
|
+
if (!c) throw new x("missing", "文档页缺失");
|
|
1231
|
+
const i = D(c);
|
|
1232
|
+
if (u + i > s) {
|
|
1233
|
+
if (!o.length) throw new x("capacity", "单页超过读取窗口预算");
|
|
1234
|
+
break;
|
|
1235
|
+
}
|
|
1236
|
+
o.push(c), u += i;
|
|
1237
|
+
}
|
|
1238
|
+
return { manifest: a, pages: o, nextPage: f };
|
|
1239
|
+
}
|
|
1240
|
+
async function Qt(e, t) {
|
|
1241
|
+
const { scope: r, id: n, version: s, signal: a, pages: o } = t, u = t.metadata === void 0 ? void 0 : O(t.metadata, 1e6, a);
|
|
1242
|
+
let f = await e.create({ scope: r, id: n, version: s, plan: t.plan }, a), c;
|
|
1243
|
+
try {
|
|
1244
|
+
const i = Symbol.asyncIterator in o ? o[Symbol.asyncIterator]() : o[Symbol.iterator]();
|
|
1245
|
+
for (c = i; ; ) {
|
|
1246
|
+
const d = await T(a, void 0, () => Promise.resolve(i.next()));
|
|
1247
|
+
if (d.done) break;
|
|
1248
|
+
f = await e.append(r, n, s, f.revision, d.value, a);
|
|
1249
|
+
}
|
|
1250
|
+
return await e.complete(r, n, s, f.revision, u, a);
|
|
1251
|
+
} catch (i) {
|
|
1252
|
+
throw Promise.resolve(c?.return?.()).catch(() => {
|
|
1253
|
+
}), await e.fail(r, n, s, f.revision, a?.aborted ? { code: "cancelled", message: "报表文档生成已取消" } : { code: "generation", message: "报表文档生成失败" }).catch(() => {
|
|
1254
|
+
}), i;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
const Et = "1.0", ue = Object.freeze({ params: 422, validate: 422, fetch: 502, config: 400, input: 400, budget: 413, capacity: 413, timeout: 504, "queue-full": 429, closed: 503, cancelled: 499, "output-fidelity": 422, conflict: 409, missing: 404 });
|
|
1258
|
+
function V(e) {
|
|
1259
|
+
return e && typeof e == "object" ? e : {};
|
|
1260
|
+
}
|
|
1261
|
+
function kt(e) {
|
|
1262
|
+
if (Array.isArray(e))
|
|
1263
|
+
return e.slice(0, 100).map((t) => Object.fromEntries(["code", "path", "field", "message"].flatMap((r) => typeof V(t)[r] == "string" ? [[r, V(t)[r].slice(0, 4096)]] : [])));
|
|
1264
|
+
}
|
|
1265
|
+
function Wt(e, t) {
|
|
1266
|
+
const r = V(e), n = r.name === "AbortError" ? "cancelled" : r.code, s = typeof n == "string" && Object.prototype.hasOwnProperty.call(ue, n) ? n : "internal", a = s === "internal" ? void 0 : kt(r.issues ?? V(r.cause).issues);
|
|
1267
|
+
return { status: ue[s] ?? 500, body: { error: {
|
|
1268
|
+
code: s,
|
|
1269
|
+
message: s === "internal" ? "Report execution failed" : typeof r.message == "string" ? r.message.slice(0, 4096) : "Report request failed",
|
|
1270
|
+
correlationId: t.slice(0, 128),
|
|
1271
|
+
...s !== "internal" && typeof r.path == "string" ? { path: r.path.slice(0, 4096) } : {},
|
|
1272
|
+
...a ? { issues: a } : {}
|
|
1273
|
+
} } };
|
|
1274
|
+
}
|
|
1275
|
+
function Z(e, t, r) {
|
|
1276
|
+
return { description: r, headers: { "X-Request-Id": { schema: { type: "string" }, description: "Request correlation identity" } }, content: { [e]: { schema: t } } };
|
|
1277
|
+
}
|
|
1278
|
+
function Ot(e) {
|
|
1279
|
+
return {
|
|
1280
|
+
type: "object",
|
|
1281
|
+
additionalProperties: !1,
|
|
1282
|
+
properties: Object.fromEntries(e.params.map((t) => [t.field, { type: "string" }])),
|
|
1283
|
+
required: e.params.filter((t) => t.required && t.defaultValue === void 0).map((t) => t.field),
|
|
1284
|
+
"x-report-typedSchema": e.paramsSchema
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
function Yt(e, t = {}) {
|
|
1288
|
+
const r = t.basePath ?? "/reports";
|
|
1289
|
+
if (!/^\/[A-Za-z0-9/_-]*[A-Za-z0-9_-]$/.test(r)) throw new Error("OpenAPI basePath 应为不含查询串、参数和尾斜线的绝对路径");
|
|
1290
|
+
const n = {
|
|
1291
|
+
[r]: { get: { operationId: "describeReports", responses: { 200: Z("application/json", { type: "array", items: { type: "object" } }, "Authorized report descriptions") } } }
|
|
1292
|
+
}, s = /* @__PURE__ */ new Set();
|
|
1293
|
+
for (const a of e) {
|
|
1294
|
+
if (!a.id.trim() || s.has(a.id) || [".", ".."].includes(a.id)) throw new Error("OpenAPI 报表 ID 应非空、唯一且不是路径跳转段");
|
|
1295
|
+
s.add(a.id);
|
|
1296
|
+
for (const o of ["prepare", "pdf", "xlsx"]) {
|
|
1297
|
+
const u = o === "prepare" ? "prepare" : `export/${o}`, f = o !== "prepare", c = { 200: Z(f ? o === "pdf" ? "application/pdf" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : "application/json", f ? { type: "string", format: "binary" } : { type: "object", required: ["plan", "stats", "diagnostics", "revisions"] }, f ? "Report file" : "Prepared report snapshot") };
|
|
1298
|
+
for (const i of [400, 413, 422, 429, 499, 500, 502, 503, 504]) c[String(i)] = Z("application/json", { $ref: "#/components/schemas/ReportError" }, "Structured report error");
|
|
1299
|
+
n[`${r}/${encodeURIComponent(a.id)}/${u}`] = { post: {
|
|
1300
|
+
operationId: `report_${s.size}_${o}`,
|
|
1301
|
+
parameters: [{ in: "header", name: "X-Request-Id", schema: { type: "string", pattern: "^[A-Za-z0-9._-]{1,80}$" } }],
|
|
1302
|
+
requestBody: { required: !0, content: { "application/json": { schema: { type: "object", required: ["params"], additionalProperties: !1, properties: { params: Ot(a) } } } } },
|
|
1303
|
+
responses: c,
|
|
1304
|
+
"x-report-datasets": a.datasetsSchema
|
|
1305
|
+
} };
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
return {
|
|
1309
|
+
openapi: "3.1.0",
|
|
1310
|
+
info: { title: t.title ?? "MachReport HTTP", version: t.version ?? Et },
|
|
1311
|
+
paths: n,
|
|
1312
|
+
components: { schemas: { ReportError: { type: "object", required: ["error"], properties: { error: { type: "object", required: ["code", "message", "correlationId"], properties: { code: { type: "string" }, message: { type: "string" }, correlationId: { type: "string" }, path: { type: "string" }, issues: { type: "array", items: { type: "object", additionalProperties: { type: "string" } } } } } } } } }
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1079
1315
|
export {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1316
|
+
Et as REPORT_HTTP_CONTRACT_VERSION,
|
|
1317
|
+
x as ReportDocumentError,
|
|
1318
|
+
b as ReportInstanceError,
|
|
1319
|
+
R as ReportJobError,
|
|
1320
|
+
A as ReportRuntimeError,
|
|
1321
|
+
J as checkInstanceIdentity,
|
|
1322
|
+
X as checkJobIdentity,
|
|
1323
|
+
H as cloneJob,
|
|
1324
|
+
it as createManagerTemplateCatalog,
|
|
1325
|
+
Xt as createMemoryReportDocumentStore,
|
|
1326
|
+
ct as createMemoryReportInstanceIds,
|
|
1327
|
+
Ft as createMemoryReportInstanceStore,
|
|
1328
|
+
rr as createMemoryReportJobStore,
|
|
1329
|
+
Qe as createReportGenerationService,
|
|
1330
|
+
Xe as createReportInstanceManager,
|
|
1331
|
+
_t as createReportJobService,
|
|
1332
|
+
Yt as createReportOpenApi,
|
|
1333
|
+
W as createReportRuntime,
|
|
1334
|
+
zt as createReportTaskQueue,
|
|
1335
|
+
Kt as createReportTemplatePackage,
|
|
1336
|
+
Ut as createReportWorkflow,
|
|
1337
|
+
xe as parseReportTemplatePackage,
|
|
1338
|
+
Gt as readReportDocumentPages,
|
|
1339
|
+
Wt as reportHttpError,
|
|
1340
|
+
Vt as reportInstanceParameterKey,
|
|
1341
|
+
Ke as reportInstanceSummary,
|
|
1342
|
+
wt as reportPackageResourceDigest,
|
|
1343
|
+
Zt as resolveReportTemplatePackage,
|
|
1344
|
+
Lt as reviewReportPublication,
|
|
1345
|
+
Ht as runLabelStream,
|
|
1346
|
+
Oe as runReportBatch,
|
|
1347
|
+
nr as runnableJob,
|
|
1348
|
+
ot as saveAndPublishReportTemplate,
|
|
1349
|
+
P as serializeJobJson,
|
|
1350
|
+
sr as snapshotReportBatchCases,
|
|
1351
|
+
G as snapshotReportInstance,
|
|
1352
|
+
ar as validateJobRecord,
|
|
1353
|
+
or as validateJobTransition,
|
|
1354
|
+
Qt as writeReportDocument
|
|
1112
1355
|
};
|