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