@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.
Files changed (155) hide show
  1. package/README.md +14 -9
  2. package/dist/{ExcelBindingWizard-Bs43BGNp.cjs → ExcelBindingWizard-CP6h2x1f.cjs} +1 -1
  3. package/dist/{ExcelBindingWizard-BKH1nGNS.js → ExcelBindingWizard-HhB3hAJE.js} +3 -3
  4. package/dist/{ParamEditor-Da4akw6V.cjs → ParamEditor-CUQLgoxa.cjs} +1 -1
  5. package/dist/{ParamEditor-DoAhzJsm.js → ParamEditor-OKesP_nO.js} +1 -1
  6. package/dist/{ReportBatchPanel-wP9m9Pj1.cjs → ReportBatchPanel-cZCAMAwH.cjs} +1 -1
  7. package/dist/{ReportBatchPanel-BMf6boMA.js → ReportBatchPanel-ruxcbfY6.js} +3 -3
  8. package/dist/ReportPreview-BcDKCLiK.js +4834 -0
  9. package/dist/ReportPreview-Bk9nLfO9.cjs +6 -0
  10. package/dist/{ReportTemplateLibrary-Sxr3eD0J.cjs → ReportTemplateLibrary-BDlNT8JN.cjs} +1 -1
  11. package/dist/{ReportTemplateLibrary-C9wutIiT.js → ReportTemplateLibrary-DcwrH-63.js} +1 -1
  12. package/dist/{RuleEditor-XhGHK8DE.cjs → RuleEditor-BX5S8RSF.cjs} +1 -1
  13. package/dist/{RuleEditor-C_Clasvd.js → RuleEditor-CGl9XY2s.js} +2 -2
  14. package/dist/{TemplateOutlinePanel-JTSR53vJ.cjs → TemplateOutlinePanel-CGrT5DFN.cjs} +1 -1
  15. package/dist/{TemplateOutlinePanel-D6Bkny59.js → TemplateOutlinePanel-SXCjaPKR.js} +1 -1
  16. package/dist/{TemplateReusePanel-Kx35S0Ql.cjs → TemplateReusePanel-6Z3wRFz8.cjs} +1 -1
  17. package/dist/{TemplateReusePanel-rVuK1kTz.js → TemplateReusePanel-lHLOS9Wn.js} +2 -2
  18. package/dist/{TemplateReviewPanel-B0ar9_zf.js → TemplateReviewPanel-CJ9PLc48.js} +1 -1
  19. package/dist/{TemplateReviewPanel-Dn6X9UmY.cjs → TemplateReviewPanel-Dpk7sLcF.cjs} +1 -1
  20. package/dist/analytics.d.cts +2 -0
  21. package/dist/analytics.d.ts +2 -0
  22. package/dist/artifact-integrity.json +99 -91
  23. package/dist/{assets-DEaz4qsp.js → assets-CqIbfbTr.js} +24 -22
  24. package/dist/assets-e4YSke8n.cjs +1 -0
  25. package/dist/auto-YR7a4BtF.js +240 -0
  26. package/dist/auto-uVBjX1j5.cjs +1 -0
  27. package/dist/{batch-BfZHN1do.js → batch-WzDIXJAt.js} +1 -1
  28. package/dist/{batch-CLpELXBl.cjs → batch-z6Aw5GEY.cjs} +1 -1
  29. package/dist/capabilities-DDwXr_cA.js +103 -0
  30. package/dist/capabilities-DNLyZdNw.cjs +1 -0
  31. package/dist/codes.d.cts +2 -0
  32. package/dist/codes.d.ts +2 -0
  33. package/dist/component-tree-Ca6YYfHq.js +61 -0
  34. package/dist/component-tree-DkGLEfZC.cjs +1 -0
  35. package/dist/config-Dg_o8e7m.cjs +1 -0
  36. package/dist/{config-BVsJXSqS.js → config-XQ4qrQ7Q.js} +66 -64
  37. package/dist/designer-BfQSahxq.js +5163 -0
  38. package/dist/designer-CPPdeM5_.cjs +2 -0
  39. package/dist/designer.cjs +1 -1
  40. package/dist/designer.d.cts +53 -0
  41. package/dist/designer.d.ts +53 -0
  42. package/dist/designer.js +1 -1
  43. package/dist/diagnostic-notification-B9K9We3h.cjs +1 -0
  44. package/dist/diagnostic-notification-qGAYZdkB.js +7 -0
  45. package/dist/drill-CsdjgkRM.cjs +1 -0
  46. package/dist/{drill-ByJviLXS.js → drill-DIGsZfyB.js} +11 -11
  47. package/dist/encoding-BOGq4qYL.js +21 -0
  48. package/dist/encoding-BYF9ZTl9.cjs +1 -0
  49. package/dist/{font-loader-Q3bQjmrI.js → font-loader-CzI1GuBc.js} +1 -1
  50. package/dist/{font-loader-B_UkxpzC.cjs → font-loader-EKLzOJxf.cjs} +1 -1
  51. package/dist/index.cjs +7 -8
  52. package/dist/index.d.cts +2 -0
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.js +865 -834
  55. package/dist/json-snapshot-D6ioHth9.js +1702 -0
  56. package/dist/json-snapshot-DknkjvxP.cjs +2 -0
  57. package/dist/{pdf-CvvrjPQg.cjs → pdf-ByVCb1i6.cjs} +48 -50
  58. package/dist/{pdf-BwNyeGpt.js → pdf-DJ5S6ukC.js} +2737 -2749
  59. package/dist/pdf.cjs +1 -1
  60. package/dist/pdf.d.cts +2 -0
  61. package/dist/pdf.d.ts +2 -0
  62. package/dist/pdf.js +2 -2
  63. package/dist/{plugin-Ca_XZG3l.js → plugin-C2j5_mhx.js} +1 -1
  64. package/dist/{plugin-DHO7X8z2.cjs → plugin-Dr39GBRG.cjs} +1 -1
  65. package/dist/prepared-DdrjLC7L.cjs +1 -0
  66. package/dist/prepared-DqtpvRTn.js +87 -0
  67. package/dist/progress-BXzlVbIp.js +29 -0
  68. package/dist/progress-DJBd9Rb9.cjs +1 -0
  69. package/dist/{progress-D-OTpEav.js → progress-Hc2vxoCs.js} +2 -2
  70. package/dist/protocol-BzwMP4Vw.cjs +1 -0
  71. package/dist/protocol-kt4Iy6-3.js +90 -0
  72. package/dist/{record-bindings-Do_b3h4V.js → record-bindings-CZWBJ1fU.js} +9 -10
  73. package/dist/record-bindings-DUX1VMlR.cjs +1 -0
  74. package/dist/{region-binding-workflow-BMhK_TjP.js → region-binding-workflow-CWNvIjkV.js} +1 -1
  75. package/dist/{region-binding-workflow-DIYJdCUr.cjs → region-binding-workflow-CqSMxQ4p.cjs} +1 -1
  76. package/dist/report-encoding-worker.cjs +1 -0
  77. package/dist/report-encoding-worker.d.ts +1 -0
  78. package/dist/report-encoding-worker.js +2 -0
  79. package/dist/rich-text-layout-ALlMoYOG.cjs +3 -0
  80. package/dist/rich-text-layout-Ct5WrY1g.js +102 -0
  81. package/dist/runtime-BjKBI530.js +168 -0
  82. package/dist/runtime-CBFEPKEs.cjs +1 -0
  83. package/dist/sbom.cdx.json +2 -2
  84. package/dist/server/node.d.cts +86 -1
  85. package/dist/server/node.d.ts +86 -1
  86. package/dist/server-node.cjs +5 -1
  87. package/dist/server-node.js +4558 -473
  88. package/dist/server.cjs +1 -1
  89. package/dist/server.d.cts +8 -1
  90. package/dist/server.d.ts +8 -1
  91. package/dist/server.js +634 -792
  92. package/dist/sha256-BshdOkCC.cjs +1 -0
  93. package/dist/sha256-DTG-Gq8i.js +157 -0
  94. package/dist/style-67OqfNed.js +73 -0
  95. package/dist/style-C22Pbv3T.cjs +1 -0
  96. package/dist/style.css +1 -1
  97. package/dist/{template-catalog-j2B1MJlL.js → template-catalog-BtR2JmCL.js} +9 -9
  98. package/dist/{template-catalog-FJE_c9Qe.cjs → template-catalog-C2NLdrwB.cjs} +1 -1
  99. package/dist/{template-fragments-DcKeiylI.cjs → template-fragments-BVsbxs4a.cjs} +1 -1
  100. package/dist/{template-fragments-BGbQLGlV.js → template-fragments-By0aZC1D.js} +2 -2
  101. package/dist/template-registry-C62vpv4a.cjs +1 -0
  102. package/dist/{template-registry-BtaKPELV.js → template-registry-Cw3vRTX2.js} +389 -321
  103. package/dist/{textwrap-DE1kgcJB.js → textwrap-BEIg2w8y.js} +1 -1
  104. package/dist/textwrap-BI-yJ6Wt.cjs +4 -0
  105. package/dist/vue/async.d.cts +66 -0
  106. package/dist/vue/async.d.ts +66 -0
  107. package/dist/vue/index.d.cts +89 -1
  108. package/dist/vue/index.d.ts +89 -1
  109. package/dist/vue-async.cjs +1 -1
  110. package/dist/vue-async.js +3 -3
  111. package/dist/vue.cjs +1 -1
  112. package/dist/vue.js +7 -7
  113. package/dist/{workbook-session-BvToI-Fd.js → workbook-session-BeSO8PFB.js} +153 -140
  114. package/dist/{workbook-session-Bjv1YCRK.cjs → workbook-session-Cbts-22R.cjs} +12 -12
  115. package/dist/worker.cjs +1 -1
  116. package/dist/worker.d.cts +84 -1
  117. package/dist/worker.d.ts +84 -1
  118. package/dist/worker.js +12 -157
  119. package/dist/xlsx-node.cjs +33 -33
  120. package/dist/xlsx-node.js +1282 -1289
  121. package/dist/xlsx.cjs +4 -3
  122. package/dist/xlsx.d.cts +2 -0
  123. package/dist/xlsx.d.ts +2 -0
  124. package/dist/xlsx.js +297 -279
  125. package/package.json +6 -3
  126. package/dist/ReportPreview-ChV19HBp.js +0 -4619
  127. package/dist/ReportPreview-DbLvvOUT.cjs +0 -6
  128. package/dist/assets-B9ImAi6_.cjs +0 -1
  129. package/dist/batch-BaP6pWDE.cjs +0 -1
  130. package/dist/batch-CGyt-b2W.js +0 -273
  131. package/dist/capabilities-CAh2Nrue.cjs +0 -1
  132. package/dist/capabilities-DskCHs3V.js +0 -69
  133. package/dist/config-D10us76d.cjs +0 -1
  134. package/dist/data-explanation-B8MZRYVS.js +0 -16
  135. package/dist/data-explanation-DE55G30w.cjs +0 -1
  136. package/dist/defaults-DXhiM1ZD.js +0 -10
  137. package/dist/defaults-xhmcLLrf.cjs +0 -1
  138. package/dist/designer-2bDlcNXQ.js +0 -5136
  139. package/dist/designer-BT7XCdbW.cjs +0 -2
  140. package/dist/drill-DYTxuL3A.cjs +0 -1
  141. package/dist/grid-strokes-Cr7DwUux.cjs +0 -1
  142. package/dist/grid-strokes-DyyG1q_o.js +0 -53
  143. package/dist/json-snapshot-DFb2eWkf.js +0 -1416
  144. package/dist/json-snapshot-WWSGlaHG.cjs +0 -2
  145. package/dist/prepared-CFy9B75C.cjs +0 -1
  146. package/dist/prepared-ajM-H-9B.js +0 -69
  147. package/dist/record-bindings-By_UKZ2g.cjs +0 -1
  148. package/dist/render-plan-7xpGrCEl.cjs +0 -1
  149. package/dist/render-plan-Ck6koX9L.js +0 -13
  150. package/dist/sha256-ArEYjaTI.cjs +0 -1
  151. package/dist/sha256-DPEuJ3nh.js +0 -155
  152. package/dist/style-CQ1PK8ZB.js +0 -67
  153. package/dist/style-UgIJSA1F.cjs +0 -1
  154. package/dist/template-registry-Co1zPq5e.cjs +0 -1
  155. package/dist/textwrap-CWHyzkBH.cjs +0 -4
package/dist/server.js CHANGED
@@ -1,863 +1,705 @@
1
- import { m as C, t as Ae, R as B, n as G, o as _, g as je, q as Ne, u as $e, a as Be, P as Je, h as De, s as ye, v as Ce } from "./json-snapshot-DFb2eWkf.js";
2
- import { g as Q } from "./report-params-B1RzkhJj.js";
3
- import { d as Z, r as Me, R as he } from "./param-validation-Do7Eg8Zv.js";
4
- import { t as h, a as I, v as Fe, c as $, R as T, p as Le } from "./sha256-DPEuJ3nh.js";
5
- import { a as be, p as J, v as ze } from "./template-registry-BtaKPELV.js";
6
- import { T as qe } from "./tree-CjVZLRw7.js";
7
- import { r as se } from "./assets-DEaz4qsp.js";
8
- import { s as F, a as W, b as _e, c as Ve, r as He, v as Ue } from "./prepared-ajM-H-9B.js";
9
- import { R, c as Y, s as N, a as U, j as Ke, b as Xe, r as Ge } from "./batch-BfZHN1do.js";
10
- import { d as ur, e as pr, f as wr, v as gr, g as mr } from "./batch-BfZHN1do.js";
11
- import { r as Qe, a as Ze } from "./template-catalog-j2B1MJlL.js";
12
- import { g as ve } from "./record-bindings-Do_b3h4V.js";
13
- import { v as xe } from "./dataset-H5pFuQGU.js";
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 T("budget", "队列并发应为正整数,排队上限应为非负整数");
174
- const s = [], n = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
175
- let o = !1, d = 0;
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 && n.size < t && s.length; ) s.shift().start();
19
+ for (; !o && s.size < t && n.length; ) n.shift().start();
178
20
  };
179
21
  return {
180
22
  get active() {
181
- return n.size;
23
+ return s.size;
182
24
  },
183
25
  get pending() {
184
- return s.length;
26
+ return n.length;
185
27
  },
186
- enqueue: (l, f = {}) => {
187
- if (o) throw new T("closed", "任务队列已关闭");
188
- if (h(f.signal), n.size >= t && s.length >= r) throw new T("queue-full", "报表任务队列已满");
189
- const u = f.id ?? `report-${++d}`;
190
- if (a.has(u)) throw new T("queue-full", "任务 ID 正在执行或排队");
191
- const w = new AbortController();
192
- let p = "queued", b, m, g, k;
193
- const D = new Promise((S, j) => {
194
- g = S, k = j;
195
- }), x = () => {
196
- f.signal?.removeEventListener("abort", E), a.delete(u);
197
- }, v = (S) => {
198
- if (p !== "queued" && p !== "running") return;
199
- const j = p === "queued";
200
- p = "cancelled", w.abort(S);
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
- h(w.signal);
203
- } catch (z) {
204
- k(z);
44
+ y(m.signal);
45
+ } catch (D) {
46
+ S(D);
205
47
  }
206
- if (j) {
207
- const z = s.indexOf(O);
208
- z >= 0 && s.splice(z, 1), x(), c();
48
+ if (E) {
49
+ const D = n.indexOf(x);
50
+ D >= 0 && n.splice(D, 1), N(), c();
209
51
  }
210
- }, E = () => v(f.signal?.reason), A = (S, j) => {
211
- p === "running" && (!Number.isFinite(S) || S < 0 || j !== void 0 && (!Number.isFinite(j) || j < S) || (b = { completed: S, ...j === void 0 ? {} : { total: j } }));
212
- }, P = (S) => {
213
- p !== "running" || w.signal.aborted || (m = { ...S, taskId: u }, S.completed !== void 0 && A(S.completed, S.total), _(f.onEvent, m, w.signal));
214
- }, O = {
215
- cancel: v,
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
- p === "queued" && (p = "running", n.add(O), Promise.resolve().then(() => (h(w.signal), l({ taskId: u, signal: w.signal, reportProgress: A, onEvent: P }))).then(
218
- (S) => {
219
- p === "running" && (p = "completed", g(S));
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
- (S) => {
222
- p === "running" && (p = "failed", k(S));
63
+ (R) => {
64
+ h === "running" && (h = "failed", S(R));
223
65
  }
224
66
  ).finally(() => {
225
- n.delete(O), x(), c();
67
+ s.delete(x), N(), c();
226
68
  }));
227
69
  }
228
70
  };
229
- return a.add(u), f.signal?.addEventListener("abort", E, { once: !0 }), f.signal?.aborted ? v(f.signal.reason) : n.size < t ? O.start() : s.push(O), { id: u, get status() {
230
- return p;
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 m;
235
- }, result: D, cancel: v };
76
+ return g;
77
+ }, result: B, cancel: k };
236
78
  },
237
79
  close: (l = {}) => {
238
80
  o = !0;
239
- for (const f of [...s]) f.cancel(new T("closed", "任务队列已关闭"));
240
- if (l.cancelRunning) for (const f of n) f.cancel(new T("closed", "任务队列已关闭"));
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 et(e) {
86
+ function Ee(e) {
245
87
  let t, r;
246
- const s = new Promise((n, a) => {
247
- t = n, r = a;
88
+ const n = new Promise((s, a) => {
89
+ t = s, r = a;
248
90
  });
249
- return s.catch(() => {
250
- }), { progress: e, promise: s, resolve: t, reject: r };
91
+ return n.catch(() => {
92
+ }), { progress: e, promise: n, resolve: t, reject: r };
251
93
  }
252
- function ce(e) {
94
+ function K(e) {
253
95
  const t = Promise.reject(e);
254
96
  return t.catch(() => {
255
97
  }), t;
256
98
  }
257
- function tt(e, t) {
258
- let r, s, n = !0, a;
99
+ function Ie(e, t) {
100
+ let r, n, s = !0, a;
259
101
  function o(i) {
260
- a ??= i ?? new Error("任务心跳更新失败"), s?.reject(a), s = void 0, t(a);
102
+ a ??= i ?? new Error("任务心跳更新失败"), n?.reject(a), n = void 0, t(a);
261
103
  }
262
- function d(i) {
104
+ function f(i) {
263
105
  const l = Promise.resolve().then(() => e(i?.progress)).then(
264
106
  () => i?.resolve(),
265
- (f) => {
266
- i?.reject(f), o(f);
107
+ (d) => {
108
+ i?.reject(d), o(d);
267
109
  }
268
110
  ).finally(() => {
269
111
  r = void 0;
270
- const f = s;
271
- s = void 0, f && a === void 0 && d(f);
112
+ const d = n;
113
+ n = void 0, d && a === void 0 && f(d);
272
114
  });
273
- r = l, l.catch((f) => {
274
- o(f);
115
+ r = l, l.catch((d) => {
116
+ o(d);
275
117
  });
276
118
  }
277
119
  function c(i) {
278
- if (!n)
279
- return ce(
280
- new R("closed", "任务进度上报已结束")
120
+ if (!s)
121
+ return K(
122
+ new v("closed", "任务进度上报已结束")
281
123
  );
282
- if (a !== void 0) return ce(a);
283
- s ? s.progress = i : s = et(i);
284
- const l = s;
285
- return r || (s = void 0, d(l)), l.promise;
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
- n && !r && a === void 0 && d();
132
+ s && !r && a === void 0 && f();
291
133
  },
292
134
  async finish() {
293
- for (n = !1; r; ) await r;
135
+ for (s = !1; r; ) await r;
294
136
  if (a !== void 0) throw a;
295
137
  }
296
138
  };
297
139
  }
298
- class de extends R {
140
+ class G extends v {
299
141
  constructor() {
300
142
  super("capacity", "任务结果超过独立预算,请保存文件引用");
301
143
  }
302
144
  }
303
- function rt(e) {
304
- const t = e.concurrency ?? 1, r = e.leaseMs ?? 3e4, s = e.heartbeatMs ?? 1e4, n = e.maxResultBytes ?? 256 * 1024;
305
- if (![t, r, s, n].every(
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
- ) || s * 2 > r)
308
- throw new R(
149
+ ) || n * 2 > r)
150
+ throw new v(
309
151
  "input",
310
152
  "并发、租约、心跳应为正整数,租约至少为心跳的两倍"
311
153
  );
312
- if (s > 2147483647)
313
- throw new R(
154
+ if (n > 2147483647)
155
+ throw new v(
314
156
  "input",
315
157
  "心跳间隔超过平台定时器上限(2147483647毫秒)"
316
158
  );
317
- return { concurrency: t, leaseMs: r, heartbeatMs: s, maxResultBytes: n, now: () => {
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 R("input", "任务时钟应返回非负整数毫秒");
162
+ throw new v("input", "任务时钟应返回非负整数毫秒");
321
163
  return o;
322
164
  } };
323
165
  }
324
- async function H(e, t, r) {
325
- Y(t, r);
326
- const s = await e.read(t, r);
327
- if (!s) throw new R("missing", "报表任务不存在");
328
- return s;
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 L(e, t, r, s = []) {
331
- const n = { ...t, ...r, revision: t.revision + 1 };
332
- for (const a of s) delete n[a];
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
- n
179
+ s
338
180
  ))
339
- throw new R("conflict", "报表任务已被其他请求更新");
340
- return U(n);
181
+ throw new v("conflict", "报表任务已被其他请求更新");
182
+ return z(s);
341
183
  }
342
- async function st(e, t, r, s) {
184
+ async function Ae(e, t, r, n) {
343
185
  if (!t.trim() || t.length > 128)
344
- throw new R("input", "workerId应为1–128位标识");
345
- for (const n of await e.store.candidates(s, 100)) {
346
- const a = n.cancelRequested ? {
347
- ...n,
348
- revision: n.revision + 1,
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: s
192
+ updatedAt: n
351
193
  } : {
352
- ...n,
353
- revision: n.revision + 1,
194
+ ...s,
195
+ revision: s.revision + 1,
354
196
  status: "running",
355
- attempt: n.attempt + 1,
356
- updatedAt: s,
357
- lease: { owner: t, expiresAt: s + r }
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
- n.scope,
361
- n.id,
362
- n.revision,
202
+ s.scope,
203
+ s.id,
204
+ s.revision,
363
205
  a
364
206
  ))
365
207
  return a;
366
208
  }
367
209
  }
368
- function fe(e, t, r, s) {
369
- return e.status === "running" && e.attempt === s && e.lease?.owner === t && e.lease.expiresAt > r;
370
- }
371
- async function nt(e, t, r, s) {
372
- const { scope: n, id: a } = r, o = r.lease.owner;
373
- let d;
374
- const c = tt(
375
- async (m) => {
376
- const g = await H(e.store, n, a), k = t.now();
377
- if (!fe(g, o, k, r.attempt))
378
- throw new R("lease", "报表任务租约已失效");
379
- if (g.cancelRequested) {
380
- s.abort(new R("closed", "任务已请求取消"));
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 L(e.store, g, {
384
- updatedAt: k,
385
- lease: { owner: o, expiresAt: k + t.leaseMs },
386
- ...m ? { progress: m } : {}
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
- (m) => {
390
- d = m, s.abort(m);
231
+ (g) => {
232
+ f = g, n.abort(g);
391
233
  }
392
- ), i = (m, g) => !Number.isFinite(m) || m < 0 || g !== void 0 && (!Number.isFinite(g) || g < m) ? Promise.reject(new R("input", "任务进度无效")) : c.progress({
393
- completed: m,
394
- ...g === void 0 ? {} : { total: g }
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 f, u;
240
+ let d, u;
399
241
  try {
400
- const m = Object.prototype.hasOwnProperty.call(
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 (!m) throw new R("input", "报表任务处理器未注册");
405
- if (!s.signal.aborted) {
406
- const g = await m(U(r.request.payload), {
407
- scope: n,
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([n, a, r.attempt]),
411
- signal: s.signal,
252
+ executionToken: JSON.stringify([s, a, r.attempt]),
253
+ signal: n.signal,
412
254
  reportProgress: i
413
255
  });
414
- if (f = JSON.parse(N(g)), Ke(f) > t.maxResultBytes) throw new de();
256
+ if (d = JSON.parse(O(w)), pe(d) > t.maxResultBytes) throw new G();
415
257
  }
416
- } catch (m) {
417
- u = m ?? new Error("报表任务执行失败");
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 w = await H(e.store, n, a), p = t.now();
423
- if (!fe(w, o, p, r.attempt))
424
- throw new R("lease", "任务租约已失效,迟到结果不会写回");
425
- const b = { ...w, updatedAt: p };
426
- delete b.lease, u ??= d, w.cancelRequested || s.signal.aborted && d === void 0 ? b.status = "cancelled" : u !== void 0 ? (b.status = "failed", b.error = {
427
- code: u instanceof de ? "result-budget" : u instanceof R ? u.code : "execution",
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 = f);
271
+ }) : (b.status = "completed", b.result = d);
430
272
  try {
431
- N(b);
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 at(e.store, w, b);
280
+ return je(e.store, m, b);
439
281
  }
440
- async function at(e, t, r) {
282
+ async function je(e, t, r) {
441
283
  try {
442
- return await L(e, t, r, ["lease"]);
443
- } catch (s) {
444
- if (!(s instanceof R) || s.code !== "capacity" || r.status !== "completed") throw s;
445
- return delete r.result, r.status = "failed", r.error = { code: "result-budget", message: "任务结果超过存储剩余预算,请保存文件引用而非文件内容" }, L(e, t, r, ["lease", "result"]);
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 le(e, t, r, s) {
449
- const n = await e.readTombstone?.(t, r);
450
- if (n) {
451
- if (n.requestHash !== await Xe(s)) throw new R("conflict", "相同任务ID不能提交不同内容(幂等保留期内)");
452
- return { scope: t, id: r, revision: n.revision, request: U(s), status: n.status, createdAt: n.createdAt, updatedAt: n.updatedAt, attempt: n.attempt, archived: !0 };
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 rr(e) {
297
+ function Et(e) {
456
298
  e = { ...e, handlers: { ...e.handlers } };
457
- const t = rt(e), r = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
458
- let n = !1, a = 0;
459
- const o = (i, l) => (Y(i, l), e.store.read(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 }, Y(i.scope, i.id), !Object.prototype.hasOwnProperty.call(e.handlers, i.kind) || typeof e.handlers[i.kind] != "function")
463
- throw new R("input", "报表任务处理器未注册");
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
- N(i.payload, {
309
+ O(i.payload, {
468
310
  maxNodes: 19e3,
469
311
  maxCharacters: 75e4
470
312
  })
471
313
  )
472
- }, f = await o(i.scope, i.id);
473
- if (f) {
474
- if (N(f.request) !== N(l))
475
- throw new R("conflict", "相同任务ID不能提交不同内容");
476
- return f;
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 le(e.store, i.scope, i.id, l);
320
+ const u = await Z(e.store, i.scope, i.id, l);
479
321
  if (u) return u;
480
- const w = t.now(), p = {
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: w,
487
- updatedAt: w,
328
+ createdAt: m,
329
+ updatedAt: m,
488
330
  attempt: 0
489
331
  };
490
- if (!await e.store.compareAndSwap(i.scope, i.id, null, p)) {
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 && N(b.request) === N(l))
334
+ if (b && O(b.request) === O(l))
493
335
  return b;
494
- const m = await le(e.store, i.scope, i.id, l);
495
- if (m) return m;
496
- throw new R("conflict", "报表任务提交发生冲突");
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 U(p);
340
+ return z(h);
499
341
  },
500
342
  get: o,
501
343
  runNext: (i) => {
502
- if (n)
503
- return Promise.reject(new R("closed", "报表任务服务已关闭"));
344
+ if (s)
345
+ return Promise.reject(new v("closed", "报表任务服务已关闭"));
504
346
  if (a >= t.concurrency)
505
347
  return Promise.reject(
506
- new R("capacity", "报表任务执行槽位已满")
348
+ new v("capacity", "报表任务执行槽位已满")
507
349
  );
508
350
  a++;
509
351
  const l = new AbortController();
510
352
  r.add(l);
511
- const f = (async () => {
353
+ const d = (async () => {
512
354
  try {
513
- const u = await st(
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 nt(e, t, u, l) : u;
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 s.add(f), f.then(
525
- () => s.delete(f),
526
- () => s.delete(f)
527
- ), f;
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 f = await H(e.store, i, l);
534
- return f.status !== "queued" && f.status !== "running" ? f : L(e.store, f, {
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
- ...f.status === "queued" ? { status: "cancelled" } : { cancelRequested: !0 }
378
+ ...d.status === "queued" ? { status: "cancelled" } : { cancelRequested: !0 }
537
379
  });
538
380
  },
539
- retry: async (i, l, f) => {
540
- const u = await H(e.store, i, l);
541
- if (u.revision !== f || u.status !== "failed")
542
- throw new R("conflict", "仅可重试当前修订的失败任务");
543
- const w = {
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 w.error, delete w.progress, L(e.store, u, w, ["error", "progress"]);
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 R("input", "当前任务适配器未实现可选终态保留能力");
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
- n = !0;
397
+ s = !0;
556
398
  for (const i of r)
557
- i.abort(new R("closed", "任务服务正在关闭"));
558
- await Promise.allSettled([...s]);
399
+ i.abort(new v("closed", "任务服务正在关闭"));
400
+ await Promise.allSettled([...n]);
559
401
  }
560
402
  };
561
403
  }
562
- function Ie(e, t) {
563
- const r = e.assets, s = e[t];
564
- if (!(!r && !s?.assetRenderers))
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
- ...s?.assetFailure === void 0 ? {} : { assetFailure: s.assetFailure },
568
- ...s?.onDiagnostic === void 0 ? {} : { onDiagnostic: s.onDiagnostic },
569
- assetRenderers: { ...r?.assetRenderers, ...s?.assetRenderers },
570
- assetBudget: { ...r?.assetBudget, ...s?.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 ue(e, t) {
574
- return !e || e.code !== "missing-image" || e.format !== "pdf" && e.format !== "xlsx" ? !1 : typeof Ie(t, e.format)?.assetRenderers?.[e.kind] == "function";
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 ot(e, t) {
577
- const r = Qe(e, t), s = r.issues.filter((a) => !ue(a.diagnostic, t)), n = r.samples.map((a) => ({ ...a, diagnostics: a.diagnostics.filter((o) => !ue(o, t)) }));
578
- return { ...r, issues: s, samples: n, ok: s.every((a) => a.severity !== "error"), artifacts: [] };
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 it(e, t, r, s, n) {
581
- const a = re({ reports: { sample: { template: r, datasets: e.datasets } }, assets: Ie(s, t), budget: {
582
- maxRows: s.maxSampleRows ?? 1e3,
583
- maxPages: s.maxPages ?? 100,
584
- maxCells: s.maxCells ?? 25e4,
585
- maxOutputBytes: s.maxOutputBytes ?? 2e7,
586
- maxDurationMs: s.maxDurationMs ?? 3e4
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: d } = await $(s.signal, s.maxDurationMs ?? 3e4, async (c) => {
590
- const i = await a.export({ reportIds: ["sample"], params: e.params, format: t, signal: c, fidelity: s.strictOutputs ? "strict" : "warn", pdf: s.pdf, xlsx: s.xlsx }), l = i.diagnostics.filter((u) => u.severity !== "info");
591
- if (s.strictOutputs && l.length) throw new Error(`Strict ${t} encoding found fidelity issues: ${l.slice(0, 3).map((u) => u.message).join("; ")}`);
592
- const f = await s.digest?.(i.bytes);
593
- return h(c), await s.onArtifact?.(e.name, i), h(c), { result: i, digest: f };
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
- n.artifacts.push({ fixture: e.name, format: t, bytes: o.bytes.byteLength, pages: o.stats.pages, ...d ? { digest: d } : {} }), n.issues.push(...o.diagnostics.map((c) => ({ code: "output", severity: s.strictOutputs || c.severity === "error" ? "error" : "warning", path: "$.template", fixture: e.name, message: `${t}: ${c.message}` })));
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
- h(s.signal), n.issues.push({ code: "output", severity: "error", path: "$.template", fixture: e.name, message: `${t}: ${o instanceof Error ? o.message : String(o)}` });
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 sr(e, t = {}) {
601
- h(t.signal);
602
- const r = ot(e, t);
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 s = J(e).template, n = [...new Set(t.formats ?? ["pdf", "xlsx"])];
605
- if (!n.length || n.some((a) => a !== "pdf" && a !== "xlsx"))
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 n)
609
- h(t.signal), !(o !== "pdf" && o !== "xlsx") && await it(a, o, s, t, r);
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 y extends Error {
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 M(e, t) {
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 y("input", "实例范围应非空,ID 应为安全标识");
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 ct(e, t) {
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 y("input", "实例应为普通 JSON 对象");
623
- if (t && Object.keys(e).some((n) => n !== String(Number(n)) || !Number.isSafeInteger(Number(n)) || Number(n) < 0 || Number(n) >= e.length)) throw new y("input", "实例数组不能包含额外属性");
624
- if (Object.getOwnPropertyNames(e).filter((n) => !(t && n === "length")).length !== Object.keys(e).length) throw new y("input", "实例不能包含不可枚举属性");
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 dt(e) {
627
- if (!Number.isSafeInteger(e.revision) || e.revision < 1 || typeof e.title != "string" || !e.title.trim() || e.title.length > 512) throw new y("input", "实例修订或标题无效");
628
- if (typeof e.generatedAt != "string" || !Number.isFinite(Date.parse(e.generatedAt)) || new Date(e.generatedAt).toISOString() !== e.generatedAt) throw new y("input", "实例生成时间应为 ISO UTC 字符串");
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 y("input", "实例报表 ID 应非空且唯一");
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 ft(e) {
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 Oe(e, t) {
635
- if (!Number.isSafeInteger(t) || t < 1) throw new y("input", "实例快照字节预算应为正安全整数");
636
- let r = 0, s = 0;
637
- const n = /* @__PURE__ */ new Set();
638
- function a(d, c) {
639
- if (++r > 1e6 || c > 64) throw new y("capacity", "实例节点或嵌套深度超过预算");
640
- if (typeof d == "string" && (s += d.length, s > t))
641
- throw new y("capacity", "实例文本超过预算");
642
- if (ft(d)) return d;
643
- if (!d || typeof d != "object" || n.has(d)) throw new y("input", "实例只允许无循环的有限 JSON 值");
644
- const i = Array.isArray(d);
645
- ct(d, i), n.add(d);
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 f of Object.keys(d)) {
648
- if (s += f.length, s > t) throw new y("capacity", "实例文本超过预算");
649
- const u = Object.getOwnPropertyDescriptor(d, f);
650
- if (u.get || u.set || ["__proto__", "constructor", "prototype"].includes(f)) throw new y("input", "实例不能包含访问器或危险键");
651
- u.value !== void 0 && (l[f] = a(u.value, c + 1));
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 (n.delete(d), i) {
654
- if (Object.keys(l).length !== d.length) throw new y("input", "实例数组不能稀疏或包含额外属性");
655
- return Array.from({ length: d.length }, (f, u) => l[String(u)]);
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 y("capacity", "实例快照超过单条字节预算");
502
+ if (new TextEncoder().encode(o).byteLength > t) throw new p("capacity", "实例快照超过单条字节预算");
661
503
  return o;
662
504
  }
663
- function ee(e, t = 8e6) {
664
- const r = JSON.parse(Oe(e, t));
665
- M(r.scope, r.id);
666
- const s = /* @__PURE__ */ new Set(["scope", "id", "revision", "title", "generatedAt", "reportIds", "params", "templateRevisions", "sourceRevisions", "plan", "artifacts", "output"]);
667
- if (Object.keys(r).some((a) => !s.has(a))) throw new y("input", "实例包含未知字段");
668
- dt(r);
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 y("input", "实例参数和修订应为字符串字典");
671
- if (r.reportIds.some((a) => !r.templateRevisions[a])) throw new y("input", "每张报表都应记录生成时的模板修订");
672
- const n = be(r.plan);
673
- if (!n.ok) throw new y("input", `实例渲染计划无效:${n.errors[0]?.path}`);
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 y("input", "实例输出元数据只允许统计、诊断和字体度量;不保存来源令牌");
676
- if (Ue({ ...r.output, plan: r.plan, revisions: {} }), r.output.sources?.some((a) => "sourceToken" in a)) throw new y("input", "实例来源清单不保存来源令牌");
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 && lt(r.artifacts), r;
520
+ return r.artifacts !== void 0 && De(r.artifacts), r;
679
521
  }
680
- function lt(e) {
681
- if (!Array.isArray(e) || e.length > 100) throw new y("input", "实例文件列表无效");
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 y("input", "实例文件应包含唯一存储键、格式、大小和可选 SHA256");
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 ut(e) {
689
- const { scope: t, id: r, revision: s, title: n, generatedAt: a, reportIds: o, params: d, templateRevisions: c, sourceRevisions: i } = e;
690
- return JSON.parse(JSON.stringify({ scope: t, id: r, revision: s, title: n, generatedAt: a, reportIds: o, params: d, templateRevisions: c, sourceRevisions: i }));
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 pt(e) {
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 y("input", "实例存储预算应为正安全整数");
536
+ if (Object.values(t).some((r) => !Number.isSafeInteger(r) || r < 1)) throw new p("input", "实例存储预算应为正安全整数");
695
537
  return t;
696
538
  }
697
- function nr(e = {}) {
698
- const t = pt(e), r = /* @__PURE__ */ new Map();
699
- let s = 0;
539
+ function Ot(e = {}) {
540
+ const t = Ce(e), r = /* @__PURE__ */ new Map();
541
+ let n = 0;
700
542
  return {
701
- read: async (n, a, o, d) => {
702
- h(d), M(n, a);
703
- const c = r.get(JSON.stringify([n, a])), i = c?.get(o ?? c.size);
704
- return i ? ee(i, t.maxSnapshotBytes) : void 0;
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 (n, a = {}) => {
707
- h(a.signal), M(n, "list");
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 y("input", "实例每页数量应为 1–100");
710
- const d = Array.from(r.values(), (c) => c.get(c.size)).filter((c) => c.scope === n && (!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);
711
- return { items: d.slice(0, o).map(ut), ...d.length > o ? { next: d[o - 1].id } : {} };
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 (n, a, o, d, c) => {
714
- h(c), M(n, a);
715
- const i = ee(d, t.maxSnapshotBytes);
716
- if (i.scope !== n || i.id !== a || i.revision !== (o ?? 0) + 1) throw new y("input", "实例身份或修订不一致");
717
- const l = JSON.stringify([n, a]), f = r.get(l) ?? /* @__PURE__ */ new Map();
718
- if ((f.size || null) !== o) return !1;
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 (f.size >= t.maxRevisions || s + u > t.maxBytes || !f.size && r.size >= t.maxInstances) throw new y("capacity", "实例存储达到预算,请使用持久化归档策略或显式调整容量");
721
- return f.set(i.revision, i), r.set(l, f), s += u, !0;
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 wt(e, t = {}) {
567
+ function ze(e, t = {}) {
726
568
  const r = t.maxSnapshotBytes ?? 8e6;
727
- if (!Number.isSafeInteger(r) || r < 1) throw new y("input", "实例快照字节预算应为正安全整数");
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 (s, n) => {
732
- const a = n.expectedRevision;
733
- if (a !== null && (!Number.isSafeInteger(a) || a < 1 || a >= Number.MAX_SAFE_INTEGER)) throw new y("input", "实例预期修订无效");
734
- const o = JSON.parse(Oe(s, r)), d = ee({ ...o, revision: (a ?? 0) + 1 }, r);
735
- if (h(n.signal), !await e.compareAndSwap(d.scope, d.id, a, d, n.signal)) throw new y("conflict", "实例已存在或已变化,请显式确认修订后保存");
736
- return d;
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 ar(e, t) {
741
- return N({ reportIds: e, params: t });
582
+ function At(e, t) {
583
+ return O({ reportIds: e, params: t });
742
584
  }
743
- function gt(e) {
744
- if (!e || typeof e != "object" || Object.getOwnPropertySymbols(e).length) throw new y("input", "生成请求应为普通对象");
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 s = /* @__PURE__ */ new Set(["scope", "id", "title", "reportIds", "params", "expectedRevision", "signal"]);
748
- for (const n of Object.getOwnPropertyNames(e)) {
749
- const a = Object.getOwnPropertyDescriptor(e, n);
750
- if (!s.has(n) || !a.enumerable || a.get || a.set) throw new y("input", "生成请求不能包含未知字段或访问器");
751
- n === "signal" ? r = a.value : a.value !== void 0 && (t[n] = a.value);
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(N(t)) };
595
+ return { signal: r, request: JSON.parse(O(t)) };
754
596
  }
755
- function mt(e) {
756
- const t = JSON.parse(N(e.templateRevisions)), r = F(e.pdf), s = wt(e.instances, { maxSnapshotBytes: e.maxSnapshotBytes });
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(n) {
759
- const { signal: a, request: o } = gt(n);
760
- if (M(o.scope, o.id), o.expectedRevision !== null && (!Number.isSafeInteger(o.expectedRevision) || o.expectedRevision < 1)) throw new y("input", "实例预期修订无效");
761
- const d = e.runtime.validate(o);
762
- if (!d.ok) throw new he(d.issues);
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 g of o.reportIds) {
765
- if (typeof t[g] != "string" || !t[g]) throw new TypeError(`报表 ${g} 缺少生成时的模板修订`);
766
- c[g] = t[g];
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 (h(a), ((await e.instances.read(o.scope, o.id, void 0, a))?.revision ?? null) !== o.expectedRevision)
769
- throw new y("conflict", "实例已存在或已变化,请显式确认修订后生成");
770
- const l = await e.runtime.prepare({ reportIds: o.reportIds, params: d.values, pdf: r, signal: a });
771
- h(a);
772
- const f = /* @__PURE__ */ Object.create(null);
773
- for (const [g, k] of Object.entries(l.revisions)) k.revision !== void 0 && (f[g] = k.revision);
774
- const { plan: u, revisions: w, sources: p, ...b } = l, m = { ...b, ...p ? { sources: p.map(({ sourceToken: g, ...k }) => k) } : {} };
775
- return s.save({
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: d.values,
622
+ params: f.values,
781
623
  templateRevisions: c,
782
- sourceRevisions: f,
624
+ sourceRevisions: d,
783
625
  generatedAt: (e.now?.() ?? /* @__PURE__ */ new Date()).toISOString(),
784
626
  plan: u,
785
- output: m
627
+ output: g
786
628
  }, { expectedRevision: o.expectedRevision, signal: a });
787
629
  },
788
- read: s.read,
789
- list: s.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(n) {
792
- const { scope: a, id: o, revision: d, signal: c, format: i, fidelity: l, taskId: f, correlationId: u, onEvent: w } = n, p = F(n.pdf ?? r), b = W(n.xlsx);
793
- M(a, o), h(c);
794
- const m = await s.read(a, o, d, c);
795
- if (!m) throw new y("input", "报表实例不存在");
796
- const g = {
797
- plan: m.plan,
798
- revisions: Object.fromEntries(m.reportIds.map((k) => [k, { revision: m.sourceRevisions[k] }])),
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: m.plan.pages.length, cells: 0, durationMs: 0 },
801
- ...m.output
642
+ stats: { rows: 0, pages: g.plan.pages.length, cells: 0, durationMs: 0 },
643
+ ...g.output
802
644
  };
803
- return e.runtime.exportPrepared({ prepared: g, format: i, fidelity: l, pdf: p, xlsx: b, signal: c, taskId: f, correlationId: u, onEvent: w });
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: s.save
648
+ save: n.save
807
649
  };
808
650
  }
809
- function q(e, t, r) {
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 pe(e) {
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 yt(e) {
818
- if (!ze(e).ok || !e.repeat) throw new TypeError("分批生成仅支持有效的逐记录固定标签模板");
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 ht(e) {
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 s = (n) => {
825
- n.binding && t.add(n.binding.field);
826
- for (const a of n.grid?.cells ?? []) for (const o of a) o?.children?.forEach(s);
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((n) => n.components.forEach((a) => s(a))), [...t];
670
+ return e.pages.forEach((s) => s.components.forEach((a) => n(a))), [...t];
829
671
  }
830
- function bt(e, t, r, s) {
831
- if (!e || typeof e != "object" || Array.isArray(e)) throw new TypeError(`标签记录 ${s} 应为对象`);
832
- const n = /* @__PURE__ */ Object.create(null);
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 = ve(e, a, { dataset: r, rowIndex: s });
835
- if (typeof o == "string" && o.length > 1e6) throw new T("budget", "标签字段超过 1 MB 字符预算", `$.datasets.${r}[${s}].${a}`);
836
- o !== void 0 && (n[a] = o);
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 n;
680
+ return s;
839
681
  }
840
- function vt(e, t, r, s) {
841
- const n = t.repeat;
842
- if (!n.rowKey) return;
843
- const a = ve(e, n.rowKey, { rowIndex: s, dataset: n.dataset });
844
- if (!(typeof a == "string" && a.trim() || typeof a == "number" && Number.isFinite(a))) throw new TypeError(`标签记录 ${s} 的业务主键无效`);
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(`标签记录 ${s} 的业务主键重复(包含先前批次)`);
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 xt(e) {
850
- return Object.entries(e).reduce((t, [r, s]) => t + 64 + r.length * 2 + (typeof s == "string" ? s.length * 2 : 8), 0);
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 Rt(e, t) {
694
+ function Ke(e, t) {
853
695
  if (!t) return e;
854
696
  for (const r of e.plan.pages) {
855
- const s = r.meta?.record;
856
- s && typeof s == "object" && "rowIndex" in s && typeof s.rowIndex == "number" && (s.rowIndex += t);
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 St(e, t) {
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 $(t, void 0, () => r);
710
+ await j(t, void 0, () => r);
869
711
  }
870
- async function we(e, t, r) {
871
- const s = Promise.resolve().then(() => e.onReceipt?.(t, r));
872
- s.catch(() => {
873
- }), await $(r.signal, void 0, () => s);
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 kt(e, t, r) {
876
- return new Promise((s, n) => {
877
- let a = !1, o = !1, d;
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(d), t.removeEventListener("abort", i);
721
+ clearTimeout(f), t.removeEventListener("abort", i);
880
722
  }, i = () => {
881
- a || d !== void 0 || (d = setTimeout(() => {
723
+ a || f !== void 0 || (f = setTimeout(() => {
882
724
  if (!a) {
883
725
  a = !0, o = !0, c();
884
726
  try {
885
- h(t);
727
+ y(t);
886
728
  } catch (l) {
887
- n(l);
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 or(e, t) {
905
- const r = q(t.batchSize ?? 100, 1e3, "batchSize"), s = q(t.maxRows ?? 1e5, 1e6, "maxRows"), n = q(t.maxChunks ?? 1e3, 1e4, "maxChunks"), a = q(t.maxRetainedBytes ?? 16e6, 64e6, "maxRetainedBytes"), o = yt(t.template), d = ht(o);
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 $(t.signal, t.runtime?.budget?.maxDurationMs ?? 12e4, async (c) => {
908
- const i = { rows: 0, chunks: [] }, l = { keys: /* @__PURE__ */ new Set(), bytes: 0 }, f = e[Symbol.asyncIterator]();
909
- let u = !1, w = !1, p;
910
- const b = () => p ??= St(f, c), m = () => {
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", m, { once: !0 });
756
+ c.addEventListener("abort", g, { once: !0 });
915
757
  try {
916
758
  for (; !u; ) {
917
- h(c);
918
- const g = [];
919
- let k = 0;
920
- for (; g.length < r; ) {
921
- const O = await $(c, void 0, () => Promise.resolve(f.next()));
922
- if (O.done) {
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 + g.length >= s) throw new T("budget", "标签来源行数超过预算", "$.maxRows");
927
- if (i.chunks.length >= n) throw new T("budget", "标签分块数量超过预算", "$.maxChunks");
928
- const S = bt(O.value, d, o.repeat.dataset, i.rows + g.length);
929
- if (vt(S, o, l, i.rows + g.length), k += xt(S), l.bytes + k > a) throw new T("budget", "标签当前块字段与全局主键索引超过内存预算", "$.maxRetainedBytes");
930
- g.push(S);
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 (!g.length) break;
933
- const D = re({ ...t.runtime, reports: { labels: { template: o, datasets: { [o.repeat.dataset]: g } } } });
934
- let x;
935
- const v = {
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: g.length,
780
+ rowCount: w.length,
939
781
  signal: c,
940
- export: (O) => D.exportPrepared({ pdf: t.pdf, ...O, prepared: x, signal: c })
782
+ export: (x) => B.exportPrepared({ pdf: t.pdf, ...x, prepared: N, signal: c })
941
783
  };
942
- let E;
943
- const P = (await Ge([{ id: `labels-${v.index}`, params: {} }], async () => {
784
+ let $;
785
+ const A = (await ye([{ id: `labels-${k.index}`, params: {} }], async () => {
944
786
  try {
945
- x = Rt(await D.prepare({ reportIds: ["labels"], pdf: t.pdf, signal: c }), v.rowOffset), h(c);
946
- const O = Promise.resolve(t.execute(x, v)), S = await kt(O, c, (j) => we(t, pe(j), v));
947
- return pe(S);
948
- } catch (O) {
949
- throw E = O, O;
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 (P.status === "cancelled")
953
- throw h(c), new Error("标签分批任务已取消");
954
- if (P.status === "failed") throw E ?? new Error(P.error.message);
955
- i.chunks.push({ ...P.value, index: v.index, rowOffset: v.rowOffset, rowCount: v.rowCount }), i.rows += g.length, await we(t, P.value, v);
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 (g) {
959
- throw w = !0, g;
800
+ } catch (w) {
801
+ throw m = !0, w;
960
802
  } finally {
961
- c.removeEventListener("abort", m), u || await b().catch((g) => {
962
- if (!w) throw g;
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 It(e, t) {
968
- const r = t.document().id, s = () => t.editor.saving || t.editor.blocked;
969
- if (s()) throw new Error("草稿尚未保存,请处理设计器提示后再发布");
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 || s()) throw new Error("草稿尚未保存,请处理设计器提示后再发布");
814
+ if (await t.editor.save(), await t.afterSave(), t.successfulSaves() === a || t.editor.pendingLocalChanges || n()) throw new Error("草稿尚未保存,请处理设计器提示后再发布");
973
815
  }
974
- const n = t.document();
975
- if (n.id !== r) throw new y("conflict", "当前模板已切换,请重新确认后发布");
976
- return e.publish(n.id, { expectedRevision: n.revision ?? null });
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 Ot(e, t) {
820
+ function Qe(e, t) {
979
821
  return {
980
822
  async search(r) {
981
- h(r.signal);
982
- const s = await e.list(r.signal);
983
- if (s.length > 1e3) throw new RangeError("本地模板连接目录最多 1000 项;更大目录请使用宿主分页查询适配器");
984
- const n = [];
985
- for (const a of s) {
986
- h(r.signal);
987
- const [o, d] = await Promise.all([e.get(a.id, { draft: !0, signal: r.signal }), e.get(a.id, { signal: r.signal })]), c = o ?? d;
988
- c && n.push({ document: c, published: d, draftRevision: o?.revision, publishedRevision: d?.revision, ...t?.(J(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 Ze(n).search(r);
832
+ return me(s).search(r);
991
833
  },
992
- async get(r, s) {
993
- return s.mode === "published" ? e.get(r, { signal: s.signal }) : await e.get(r, { draft: !0, signal: s.signal }) ?? e.get(r, { signal: s.signal });
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 Et(e = 1e3) {
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(s, n) {
1002
- if (![s, n].every((c) => typeof c == "string" && c.length > 0 && c.length <= 256)) throw new TypeError("模板与参数组标识无效");
1003
- const a = JSON.stringify([s, n]), o = t.get(a);
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 d = `instance-${r}-${(t.size + 1).toString(36)}`;
1007
- return t.set(a, d), d;
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 Pt(e, t, r) {
1012
- const s = Object.keys(r);
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 === s.length && s.every((n) => r[n] === e.params[n]);
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 ge(e) {
857
+ function ee(e) {
1016
858
  return { instanceId: e.id, label: e.title };
1017
859
  }
1018
- function Tt(e, t, r) {
1019
- const s = J(e);
1020
- if (!s.revision) throw new Error("请先发布该模板");
1021
- const n = typeof t.data == "function" ? t.data(J(s)) : t.data, a = re({ ...t.runtime, reports: { [s.id]: { ...n, template: s.template } } }), o = mt({ runtime: a, instances: t.instances, templateRevisions: { [s.id]: s.revision }, pdf: t.pdf });
1022
- async function d(c, i, l) {
1023
- h(l);
1024
- const f = await t.instances.read(t.scope, c, void 0, l);
1025
- if (h(l), !!f) {
1026
- if (!Pt(f, s, i)) throw new y("conflict", "此参数组已用于其他参数或发布修订,请复制为新任务生成");
1027
- return ge(f);
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: J(s),
873
+ document: T(n),
1032
874
  async execute(c, { signal: i }) {
1033
- h(i);
1034
- const l = a.validate({ reportIds: [s.id], params: c.params });
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 f = r(s.id, c.id), u = await d(f, l.values, i);
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 ge(await o.generate({
881
+ return ee(await o.generate({
1040
882
  scope: t.scope,
1041
- id: f,
1042
- title: (t.title?.(J(s), c, l.values) ?? `${s.name} · ${c.id}`).slice(0, 512),
1043
- reportIds: [s.id],
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 (w) {
1049
- if (w instanceof y && w.code === "conflict") {
1050
- const p = await d(f, l.values, i);
1051
- if (p) return p;
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 w;
895
+ throw m;
1054
896
  }
1055
897
  }
1056
898
  };
1057
899
  }
1058
- function ir(e) {
900
+ function jt(e) {
1059
901
  e = { ...e };
1060
- const t = Et(), r = e.instanceId ?? t.forCase;
902
+ const t = We(), r = e.instanceId ?? t.forCase;
1061
903
  return {
1062
- catalog: e.catalog ?? Ot(e.templates, e.catalogMetadata),
1063
- publish: (s) => It(e.templates, s),
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(s, n = {}) {
1066
- const { expectedRevision: a, signal: o } = n, d = await e.templates.get(s, { signal: o });
1067
- if (h(o), !d?.revision) throw new Error("请先发布该模板");
1068
- if (a !== void 0 && d.revision !== a) throw new y("conflict", "模板发布版本已变化,请重新打开后生成");
1069
- return Tt(d, e, r);
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 Ee = "2.15.0";
1074
- function X(e, t) {
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((n) => !Number.isSafeInteger(n) || n < 0)) throw new TypeError("模板包图片位置无效");
1077
- let s = e.template.pages[t.pageIndex]?.components[r[0]];
1078
- for (let n = 1; s && n < r.length; n += 3) s = s.grid?.cells[r[n]]?.[r[n + 1]]?.children?.[r[n + 2]];
1079
- if (!s || s.kind !== "image" || s.binding) throw new TypeError("模板包图片位置应指向静态图片组件");
1080
- return s;
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 At(e) {
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 jt(e, t) {
1090
- if (At(e), e.kind === "font") {
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((s) => !["family", "face"].includes(s))) throw new TypeError("字体资源需要family和face");
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((s) => !["pageIndex", "componentPath"].includes(s))) throw new TypeError("模板图片位置包含未知字段");
1100
- X(t, r);
941
+ if (Object.keys(r).some((n) => !["pageIndex", "componentPath"].includes(n))) throw new TypeError("模板图片位置包含未知字段");
942
+ L(t, r);
1101
943
  }
1102
944
  }
1103
- function Nt(e, t) {
1104
- const r = (s) => s.every((n, a) => e[a] === n);
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 $t(e) {
949
+ function st(e) {
1108
950
  if (!(e instanceof Uint8Array) || !e.byteLength || e.byteLength > 32e6) throw new RangeError("资源摘要只接受1–32MB字节");
1109
- return Le(e);
951
+ return le(e);
1110
952
  }
1111
- function Pe(e, t, r = Re()) {
1112
- const s = new Set(t.flatMap((o) => (o.targets ?? []).map((d) => X(e, d)))), n = /* @__PURE__ */ new Map(), a = (o) => {
1113
- if (o.imageData && !s.has(o)) {
1114
- const d = r(o.imageData);
1115
- n.set(d.dataUrl, d.bytes.byteLength);
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 d of o.grid?.cells ?? []) for (const c of d) for (const i of c?.children ?? []) a(i);
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 d of o.components) a(d);
1120
- return [...n.values()].reduce((o, d) => o + d, 0);
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 Bt(e, t) {
964
+ function at(e, t) {
1123
965
  let r = "";
1124
- for (let s = 0; s < e.length; s += 16384) r += String.fromCharCode(...e.subarray(s, s + 16384));
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 Jt(e, t, r, s, n = 3e4) {
1128
- if (!Number.isFinite(n) || n < 1 || n > 2147483647) throw new RangeError("模板资源加载超时应为1–2147483647毫秒");
1129
- return $(s, n, async (a) => {
1130
- const o = [], d = Re();
1131
- Pe(e, t, d);
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
- h(a);
1134
- const i = await $(a, void 0, () => Promise.resolve(r(JSON.parse(JSON.stringify(c)), { signal: a })));
1135
- if (h(a), !i || !(i.bytes instanceof Uint8Array) || i.mediaType !== c.mediaType || i.bytes.byteLength !== c.bytes) throw new TypeError(`资源 ${c.id} 的类型或大小与清单不一致`);
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 (!Nt(l, c.mediaType) || $t(l) !== c.sha256) throw new TypeError(`资源 ${c.id} 的文件标识或SHA256与清单不一致`);
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 f = d(Bt(l, c.mediaType)).dataUrl;
1141
- for (const u of c.targets) X(e, u).imageData = f;
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 me(e) {
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 Dt(e, t) {
1152
- const r = me(e), s = me(t);
1153
- for (let n = 0; n < 3; n++) {
1154
- if (s[n] > r[n]) return;
1155
- if (s[n] < r[n]) throw new Error(`模板包需要MachReport ${e}或更新版本`);
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 te(e, t, r) {
1159
- const s = e ?? t;
1160
- if (!Number.isSafeInteger(s) || s < 1 || s > r) throw new RangeError("模板包字节预算无效");
1161
- return s;
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 Ct(e) {
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
- xe([], r);
1010
+ se([], r);
1169
1011
  }
1170
1012
  }
1171
1013
  }
1172
- function Mt(e, t) {
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((s) => !["name", "deidentified", "datasets", "params"].includes(s))) throw new TypeError("模板包样例包含未知字段");
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 (Ft(e, t), !Z(t.document.template.params ?? [], e.params).ok) throw new TypeError(`样例 ${e.name} 的参数不符合模板定义`);
1018
+ if (dt(e, t), !ke(t.document.template.params ?? [], e.params).ok) throw new TypeError(`样例 ${e.name} 的参数不符合模板定义`);
1177
1019
  }
1178
- function Ft(e, t) {
1020
+ function dt(e, t) {
1179
1021
  let r = 0;
1180
- for (const n of Object.values(e.datasets))
1181
- if (!Array.isArray(n) || n.some((a) => !a || typeof a != "object" || Array.isArray(a))) throw new TypeError("模板包样例应为对象行数组");
1182
- const s = Ce(t.document.template, e.datasets, { maxRows: 1e3 });
1183
- for (const [n, a] of Object.entries(s)) {
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?.[n];
1186
- if (o && !xe(a, o).ok) throw new TypeError(`样例 ${e.name} 不符合 ${n} 字段契约`);
1027
+ const o = t.contracts?.[s];
1028
+ if (o && !se(a, o).ok) throw new TypeError(`样例 ${e.name} 不符合 ${s} 字段契约`);
1187
1029
  }
1188
- for (const n of Object.keys(t.contracts ?? {})) if (!Object.prototype.hasOwnProperty.call(e.datasets, n)) throw new TypeError(`样例 ${e.name} 缺少 ${n} 数据集`);
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 Lt(e) {
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 (Mt(r, e), t.has(r.name)) throw new TypeError("模板包样例名称重复");
1037
+ if (ft(r, e), t.has(r.name)) throw new TypeError("模板包样例名称重复");
1196
1038
  t.add(r.name);
1197
1039
  }
1198
1040
  }
1199
- function zt(e, t) {
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(), s = /* @__PURE__ */ new Set(), n = /* @__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 (jt(o, e.document), r.has(o.id)) throw new TypeError("模板资源ID重复");
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 d = o.font && JSON.stringify([o.font.family, o.font.face]);
1207
- if (d && n.has(d)) throw new TypeError("模板包字体family/face重复");
1208
- d && n.add(d);
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 (s.has(i)) throw new TypeError("同一图片位置不能绑定多个资源");
1212
- s.add(i);
1053
+ if (n.has(i)) throw new TypeError("同一图片位置不能绑定多个资源");
1054
+ n.add(i);
1213
1055
  }
1214
1056
  }
1215
- if (a + Pe(e.document, e.resources) > t) throw new RangeError("模板包内嵌与外部资源总大小超过预算");
1057
+ if (a + fe(e.document, e.resources) > t) throw new RangeError("模板包内嵌与外部资源总大小超过预算");
1216
1058
  }
1217
- function Te(e, t = {}) {
1218
- h(t.signal);
1219
- const r = te(t.maxBytes, 8e6, 32e6);
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 s = ye(e, { maxBytes: r, check: () => h(t.signal), error: (n, a) => new TypeError(a) });
1225
- if (!s || typeof s != "object" || Array.isArray(s) || s.schemaVersion !== "1.0" || Object.keys(s).some((n) => !["schemaVersion", "minimumVersion", "document", "contracts", "resources", "fixtures"].includes(n))) throw new TypeError("模板包结构或版本无效");
1226
- return Dt(s.minimumVersion, t.runtimeVersion ?? Ee), s.document = J(s.document), Ct(s), Lt(s), zt(s, te(t.maxResourceBytes, 32e6, 64e6)), s;
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 cr(e, t = {}) {
1229
- const r = ye(e, { maxBytes: te(t.maxBytes, 8e6, 32e6), check: () => h(t.signal), error: (n, a) => new TypeError(a) }), s = Te({ schemaVersion: "1.0", ...r, minimumVersion: r.minimumVersion ?? Ee, resources: r.resources ?? [] }, t);
1230
- for (const n of s.resources) for (const a of n.targets ?? []) delete X(s.document, a).imageData;
1231
- return s;
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 dr(e, t) {
1234
- const { resolve: r, signal: s, maxDurationMs: n } = t, a = Te(e, t), o = await Jt(a.document, a.resources, r, s, n);
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
- y as ReportInstanceError,
1239
- R as ReportJobError,
1240
- T as ReportRuntimeError,
1241
- M as checkInstanceIdentity,
1242
- Y as checkJobIdentity,
1243
- U as cloneJob,
1244
- Ot as createManagerTemplateCatalog,
1245
- Et as createMemoryReportInstanceIds,
1246
- nr as createMemoryReportInstanceStore,
1247
- ur as createMemoryReportJobStore,
1248
- mt as createReportGenerationService,
1249
- wt as createReportInstanceManager,
1250
- rr as createReportJobService,
1251
- re as createReportRuntime,
1252
- tr as createReportTaskQueue,
1253
- cr as createReportTemplatePackage,
1254
- ir as createReportWorkflow,
1255
- Te as parseReportTemplatePackage,
1256
- ar as reportInstanceParameterKey,
1257
- ut as reportInstanceSummary,
1258
- $t as reportPackageResourceDigest,
1259
- dr as resolveReportTemplatePackage,
1260
- sr as reviewReportPublication,
1261
- or as runLabelStream,
1262
- Ge as runReportBatch,
1263
- pr as runnableJob,
1264
- It as saveAndPublishReportTemplate,
1265
- N as serializeJobJson,
1266
- wr as snapshotReportBatchCases,
1267
- ee as snapshotReportInstance,
1268
- gr as validateJobRecord,
1269
- mr as validateJobTransition
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
  };