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