@agile-team/mach-report 2.16.0 → 2.18.0

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