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