@agile-team/mach-report 2.14.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 (256) hide show
  1. package/README.md +16 -11
  2. package/THIRD_PARTY_NOTICES.md +3 -1
  3. package/dist/{ExcelBindingWizard-CvsWR8Ga.js → ExcelBindingWizard-BKH1nGNS.js} +3 -3
  4. package/dist/{ExcelBindingWizard-CLT2p7P3.cjs → ExcelBindingWizard-Bs43BGNp.cjs} +1 -1
  5. package/dist/ParamEditor-Da4akw6V.cjs +1 -0
  6. package/dist/ParamEditor-DoAhzJsm.js +594 -0
  7. package/dist/{ReportBatchPanel-LqVgiqp7.js → ReportBatchPanel-BMf6boMA.js} +39 -39
  8. package/dist/{ReportBatchPanel-DkxTzBkD.cjs → ReportBatchPanel-wP9m9Pj1.cjs} +1 -1
  9. package/dist/ReportPreview-ChV19HBp.js +4619 -0
  10. package/dist/ReportPreview-DbLvvOUT.cjs +6 -0
  11. package/dist/{ReportTemplateLibrary-MjWEtc7X.js → ReportTemplateLibrary-C9wutIiT.js} +1 -1
  12. package/dist/{ReportTemplateLibrary-cQ1sqNYo.cjs → ReportTemplateLibrary-Sxr3eD0J.cjs} +1 -1
  13. package/dist/{RuleEditor-ChuXMlei.js → RuleEditor-C_Clasvd.js} +5 -5
  14. package/dist/{RuleEditor-BaR6xUiI.cjs → RuleEditor-XhGHK8DE.cjs} +1 -1
  15. package/dist/{TemplateOutlinePanel-Dci6aRn1.js → TemplateOutlinePanel-D6Bkny59.js} +2 -2
  16. package/dist/{TemplateOutlinePanel-BHKP89Xz.cjs → TemplateOutlinePanel-JTSR53vJ.cjs} +1 -1
  17. package/dist/{TemplateReusePanel-CY5eO2Sh.cjs → TemplateReusePanel-Kx35S0Ql.cjs} +1 -1
  18. package/dist/{TemplateReusePanel-B7Gmyc1z.js → TemplateReusePanel-rVuK1kTz.js} +2 -2
  19. package/dist/{TemplateReviewPanel-DjlX3xpt.js → TemplateReviewPanel-B0ar9_zf.js} +2 -2
  20. package/dist/{TemplateReviewPanel-JvZe9_4G.cjs → TemplateReviewPanel-Dn6X9UmY.cjs} +1 -1
  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 -1
  44. package/dist/designer.d.cts +144 -16
  45. package/dist/designer.d.ts +144 -16
  46. package/dist/designer.js +1 -1
  47. package/dist/drill-ByJviLXS.js +145 -0
  48. package/dist/drill-DYTxuL3A.cjs +1 -0
  49. package/dist/{font-loader-vhCT8znW.cjs → font-loader-B_UkxpzC.cjs} +1 -1
  50. package/dist/{font-loader-DHto6Lra.js → font-loader-Q3bQjmrI.js} +1 -1
  51. package/dist/index.cjs +8 -8
  52. package/dist/index.d.cts +82 -4
  53. package/dist/index.d.ts +82 -4
  54. package/dist/index.js +785 -820
  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-8UPQebOE.js → pdf-BwNyeGpt.js} +4385 -4321
  161. package/dist/{pdf-AyJGb22z.cjs → pdf-CvvrjPQg.cjs} +51 -49
  162. package/dist/pdf.cjs +1 -1
  163. package/dist/pdf.d.cts +18 -3
  164. package/dist/pdf.d.ts +18 -3
  165. package/dist/pdf.js +2 -2
  166. package/dist/{plugin-BGKf-Tqg.js → plugin-Ca_XZG3l.js} +2 -2
  167. package/dist/{plugin-CktLH_Iy.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-By_UKZ2g.cjs +1 -0
  173. package/dist/record-bindings-Do_b3h4V.js +196 -0
  174. package/dist/{region-binding-workflow-DEJbhpCv.js → region-binding-workflow-BMhK_TjP.js} +1 -1
  175. package/dist/{region-binding-workflow-BzfbxRiR.cjs → region-binding-workflow-DIYJdCUr.cjs} +1 -1
  176. package/dist/{report-params-B44imUd4.js → report-params-B1RzkhJj.js} +1 -1
  177. package/dist/{report-params-SJfhKgaX.cjs → report-params-WDGrA4oP.cjs} +1 -1
  178. package/dist/sbom.cdx.json +3982 -0
  179. package/dist/server/node.d.cts +20 -1
  180. package/dist/server/node.d.ts +20 -1
  181. package/dist/server-node.cjs +1 -1
  182. package/dist/server-node.js +247 -237
  183. package/dist/server.cjs +1 -1
  184. package/dist/server.d.cts +772 -4
  185. package/dist/server.d.ts +772 -4
  186. package/dist/server.js +885 -645
  187. package/dist/sha256-ArEYjaTI.cjs +1 -0
  188. package/dist/sha256-DPEuJ3nh.js +155 -0
  189. package/dist/style.css +1 -1
  190. package/dist/template-bindings-C2SpvsMU.js +58 -0
  191. package/dist/template-bindings-CEtWyiLX.cjs +1 -0
  192. package/dist/template-catalog-FJE_c9Qe.cjs +1 -0
  193. package/dist/template-catalog-j2B1MJlL.js +414 -0
  194. package/dist/{template-fragments-CLkGo6To.js → template-fragments-BGbQLGlV.js} +21 -21
  195. package/dist/{template-fragments-DFUpq5QM.cjs → template-fragments-DcKeiylI.cjs} +1 -1
  196. package/dist/{template-outline-B3xVkzSv.cjs → template-outline-BwRV_eRo.cjs} +1 -1
  197. package/dist/{template-outline-CFenM1PV.js → template-outline-cnWfT_LK.js} +3 -3
  198. package/dist/{template-registry-COXDEJEM.js → template-registry-BtaKPELV.js} +364 -201
  199. package/dist/template-registry-Co1zPq5e.cjs +1 -0
  200. package/dist/textwrap-CWHyzkBH.cjs +4 -0
  201. package/dist/textwrap-DE1kgcJB.js +110 -0
  202. package/dist/{tree-CqcQ99NM.js → tree-CjVZLRw7.js} +1 -1
  203. package/dist/vue/async.d.cts +123 -14
  204. package/dist/vue/async.d.ts +123 -14
  205. package/dist/vue/index.d.cts +158 -22
  206. package/dist/vue/index.d.ts +158 -22
  207. package/dist/vue-async.cjs +1 -1
  208. package/dist/vue-async.js +3 -3
  209. package/dist/vue.cjs +1 -1
  210. package/dist/vue.js +80 -78
  211. package/dist/{workbook-session-DNa2RHNG.cjs → workbook-session-Bjv1YCRK.cjs} +18 -18
  212. package/dist/{workbook-session-BfK1yHOO.js → workbook-session-BvToI-Fd.js} +5440 -5288
  213. package/dist/worker.cjs +1 -1
  214. package/dist/worker.d.cts +20 -1
  215. package/dist/worker.d.ts +20 -1
  216. package/dist/worker.js +33 -32
  217. package/dist/xlsx-node.cjs +34 -34
  218. package/dist/xlsx-node.js +878 -870
  219. package/dist/xlsx.cjs +3 -4
  220. package/dist/xlsx.d.cts +22 -10
  221. package/dist/xlsx.d.ts +22 -10
  222. package/dist/xlsx.js +261 -253
  223. package/package.json +2 -2
  224. package/dist/ParamEditor-CflQV3eQ.js +0 -526
  225. package/dist/ParamEditor-vIDzvpPV.cjs +0 -1
  226. package/dist/ReportPreview-CvbqLUzM.cjs +0 -6
  227. package/dist/ReportPreview-D_ywJ_-H.js +0 -4533
  228. package/dist/assets-C2U-e-Sz.cjs +0 -4
  229. package/dist/assets-Q0wUwNrV.js +0 -217
  230. package/dist/batch-DzaTNLWI.js +0 -371
  231. package/dist/batch-xMkqYiTr.cjs +0 -1
  232. package/dist/capabilities-CK_7hizc.js +0 -63
  233. package/dist/capabilities-CsZ-pNHR.cjs +0 -1
  234. package/dist/config-0UIohTS7.cjs +0 -1
  235. package/dist/config-Dt9NtCPl.js +0 -566
  236. package/dist/data-explanation-BktvER5B.cjs +0 -1
  237. package/dist/data-explanation-C_J6jYNi.js +0 -16
  238. package/dist/designer-Ci1LizA9.js +0 -5020
  239. package/dist/designer-rtmVIIdN.cjs +0 -2
  240. package/dist/json-snapshot-BeFT3Tso.js +0 -1952
  241. package/dist/json-snapshot-D1NTP2oI.cjs +0 -2
  242. package/dist/matrix-DVyWiYsd.cjs +0 -1
  243. package/dist/matrix-yZsGnldA.js +0 -227
  244. package/dist/page-window-index-CIuT4BAv.js +0 -43
  245. package/dist/page-window-index-DEjnM6IB.cjs +0 -1
  246. package/dist/param-validation-BlHHXs6u.js +0 -153
  247. package/dist/param-validation-DCK039V1.cjs +0 -1
  248. package/dist/progress-7OSZbFok.js +0 -39
  249. package/dist/progress-BnLiS5eH.cjs +0 -1
  250. package/dist/task-events-DQ276fn2.cjs +0 -1
  251. package/dist/task-events-Dpsvf_t2.js +0 -47
  252. package/dist/template-bindings-BJR4k7qZ.cjs +0 -1
  253. package/dist/template-bindings-Daui7hLF.js +0 -252
  254. package/dist/template-registry-D3SjENi6.cjs +0 -1
  255. package/dist/validate-BJ5HIWY8.cjs +0 -1
  256. package/dist/validate-CkQBWCeg.js +0 -163
package/dist/server.js CHANGED
@@ -1,110 +1,65 @@
1
- import { R as P, s as xe, C as Re, l as Se, E as Ie, b as Oe, P as Pe, n as ke, z as Ae } from "./json-snapshot-BeFT3Tso.js";
2
- import { g as X } from "./report-params-B44imUd4.js";
3
- import { d as Z, r as Be, R as le } from "./param-validation-BlHHXs6u.js";
4
- import { t as v, a as O, R as k, p as Y, v as Ee, c as j, b as x, d as Q, s as F, e as U, j as Ne, f as Fe, r as je } from "./batch-DzaTNLWI.js";
5
- import { g as Ft, h as jt, i as Mt, k as $t, l as Jt } from "./batch-DzaTNLWI.js";
6
- import { v as fe } from "./validate-CkQBWCeg.js";
7
- import { c as $, r as V, n as q } from "./task-events-Dpsvf_t2.js";
8
- import { T as Me } from "./tree-CqcQ99NM.js";
9
- import { r as ee } from "./assets-Q0wUwNrV.js";
10
- import { h as $e } from "./data-explanation-C_J6jYNi.js";
11
- import { p as Je, v as Ce } from "./template-registry-COXDEJEM.js";
12
- import { h as pe } from "./template-bindings-Daui7hLF.js";
13
- function z(e = []) {
14
- return e.map(({ code: t, message: r, severity: a, pageIndex: s, componentIndex: n }) => ({ code: t, message: r, severity: a, path: `$.pages.${s}.components.${n}` }));
15
- }
16
- async function te(e, t, r = Date.now()) {
17
- const a = e.prepared, s = e.format === "pdf" ? await import("@agile-team/mach-report/pdf") : void 0;
18
- v(e.signal);
19
- const n = e.pdf?.customFontFaces ?? (e.pdf?.customFontBytes ? { regular: e.pdf.customFontBytes } : void 0), o = s && n ? s.createFontBytesMeasurer(n) : void 0, d = $(e), c = await d.run("encode", async () => {
20
- let u;
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;
21
23
  if (e.format === "pdf") {
22
- v(e.signal);
23
- const l = await s.renderPlanToPdf(a.plan, { ...e.pdf, ...o ? { measurer: o } : {}, fidelity: e.fidelity, signal: e.signal, onProgress: (w, p) => d.progress("encode", w, p) });
24
- u = l.bytes, a.diagnostics.push(...z(l.diagnostics)), a.diagnostics.push(...l.fidelityWarnings.map((w) => ({ code: "pdf-fidelity", message: w, severity: "warning" })), ...l.pageErrors.map((w) => ({ code: "pdf-page", message: w, severity: "error" }))), l.unsupportedTextCount && a.diagnostics.push({ code: "pdf-font", message: `${l.unsupportedTextCount} 段文本包含当前字体不支持的字符`, severity: "warning" });
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" });
25
27
  } else {
26
- const { renderPlanToXlsx: l } = await import("@agile-team/mach-report/xlsx");
27
- v(e.signal);
28
- const w = await l(a.plan, { ...e.xlsx, fidelity: e.fidelity, signal: e.signal, onProgress: (p, g) => d.progress("encode", p, g) });
29
- u = new Uint8Array(w.buffer), a.diagnostics.push(...z(w.diagnostics)), a.diagnostics.push(...w.warnings.map((p) => ({ code: "xlsx-fidelity", message: p, severity: "warning" })));
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" })));
30
32
  }
31
- return v(e.signal), u;
32
- });
33
- O(t, "maxOutputBytes", c.byteLength);
34
- const { plan: i, ...f } = a;
35
- return { ...f, bytes: c, format: e.format, contentType: e.format === "pdf" ? "application/pdf" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", stats: { ...f.stats, durationMs: Date.now() - r, outputBytes: c.byteLength } };
36
- }
37
- function G(e) {
38
- return e && { ...e };
39
- }
40
- function C(e) {
41
- if (!e) return;
42
- const t = (r) => {
43
- if (!(r instanceof Uint8Array) && !(r instanceof ArrayBuffer)) throw new P("validate", "字体应为 Uint8Array 或 ArrayBuffer");
44
- if (r.byteLength > 32e6) throw new k("budget", "单份字体超过 32 MB", "$.pdf");
45
- return new Uint8Array(r instanceof Uint8Array ? r : new Uint8Array(r));
46
- };
47
- if (e.customFontFaces) {
48
- const r = e.customFontFaces;
49
- return { customFontName: e.customFontName, customFontFaces: { regular: t(r.regular), ...r.bold ? { bold: t(r.bold) } : {}, ...r.italic ? { italic: t(r.italic) } : {}, ...r.boldItalic ? { boldItalic: t(r.boldItalic) } : {} } };
50
- }
51
- return { customFontName: e.customFontName, ...e.customFontBytes ? { customFontBytes: t(e.customFontBytes) } : {} };
52
- }
53
- function we(e) {
54
- const t = e?.customFontFaces ?? (e?.customFontBytes ? { regular: e.customFontBytes } : void 0);
55
- if (!t) return;
56
- const r = ["regular", "bold", "italic", "boldItalic"].map((a) => {
57
- const s = t[a];
58
- if (!s) return [a, null];
59
- const n = s instanceof Uint8Array ? s : new Uint8Array(s);
60
- if (n.byteLength > 32e6) throw new k("budget", "单份字体超过 32 MB", "$.pdf");
61
- return [a, Y(n)];
33
+ return h(e.signal), f;
62
34
  });
63
- return Y(new TextEncoder().encode(JSON.stringify(r)));
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 } };
64
38
  }
65
- function De(e, t, r) {
66
- const a = xe(e, {
67
- maxBytes: t,
68
- check: () => v(r),
69
- error: (s, n) => s === "budget" ? new k("budget", n, "$.budget.maxPreparedBytes") : new P("validate", n)
70
- });
71
- return ge(a), a;
39
+ function ae(e) {
40
+ return { ...e, reportIds: [...e.reportIds], ...e.params ? { params: { ...e.params } } : {} };
72
41
  }
73
- function ge(e) {
74
- if (!e?.stats || ["rows", "pages", "cells"].some((t) => !Number.isSafeInteger(e.stats[t]) || e.stats[t] < 0) || !Number.isFinite(e.stats.durationMs) || e.stats.durationMs < 0) throw new P("validate", "准备结果统计无效");
75
- if (!Array.isArray(e.diagnostics) || e.diagnostics.some((t) => !t || typeof t.code != "string" || typeof t.message != "string" || !["info", "warning", "error"].includes(t.severity) || !$e(t))) throw new P("validate", "准备结果诊断无效");
76
- if (!e.revisions || typeof e.revisions != "object" || Array.isArray(e.revisions) || Object.values(e.revisions).some((t) => !t || typeof t != "object" || t.revision !== void 0 && typeof t.revision != "string" || t.sourceToken !== void 0 && typeof t.sourceToken != "string")) throw new P("validate", "准备结果修订无效");
77
- if (e.layout && (!["heuristic", "provided", "font-bytes"].includes(e.layout.textMetrics) || e.layout.fontFingerprint !== void 0 && !/^[a-f0-9]{64}$/.test(e.layout.fontFingerprint))) throw new P("validate", "准备结果字体度量标识无效");
78
- }
79
- function Te(e) {
80
- if (e.format !== "pdf") return;
81
- const t = e.prepared.layout?.fontFingerprint, r = we(e.pdf);
82
- if (t === r && (t !== void 0 || e.prepared.layout?.textMetrics === "heuristic" && !r)) return;
83
- const a = "已准备计划的字体度量无法与本次 PDF 字体确认一致;保持现有分页,未重新查询或排版。请在 prepare 和 exportPrepared 提供相同字体字节。";
84
- if (e.fidelity === "strict") throw new P("validate", a);
85
- e.prepared.diagnostics.push({ code: "prepared-font-metrics", severity: "warning", message: a });
86
- }
87
- function me(e, t) {
88
- if (t.length === 0) throw new P("config", "缺少报表 ID");
42
+ function Se(e, t) {
43
+ if (t.length === 0) throw new B("config", "缺少报表 ID");
89
44
  return t.map((r) => {
90
- if (!Object.prototype.hasOwnProperty.call(e, r)) throw new P("config", `未注册报表 ${r}`);
45
+ if (!Object.prototype.hasOwnProperty.call(e, r)) throw new B("config", `未注册报表 ${r}`);
91
46
  return e[r];
92
47
  });
93
48
  }
94
- function H(e) {
95
- return e.grid?.cells.reduce((t, r) => t + r.reduce((a, s) => a + (s ? 1 + (s.children?.reduce((n, o) => n + H(o), 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;
96
51
  }
97
- function Le(e, t, r) {
98
- return e.pages.reduce((a, s) => a + s.components.reduce((n, o) => o.kind !== "list" ? n + H(o) : n + ke(o, 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);
99
54
  }
100
- function qe(e, t = Object.keys(e)) {
101
- return me(e, t).map((r, a) => {
102
- const s = t[a], n = X(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]);
103
58
  return {
104
- id: s,
105
- params: JSON.parse(JSON.stringify(n)),
106
- paramsSchema: Be(n),
107
- datasetsSchema: Object.fromEntries(Object.entries(r.dataSchema ?? {}).map(([o, d]) => [o, Re(typeof r.template == "function" ? void 0 : r.template, o, d)])),
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)])),
108
63
  capabilities: {
109
64
  save: !!r.provider?.save,
110
65
  export: !!r.provider?.export,
@@ -113,789 +68,796 @@ function qe(e, t = Object.keys(e)) {
113
68
  };
114
69
  });
115
70
  }
116
- function ye(e, t) {
117
- me(e, t.reportIds);
118
- const r = Z(X(e, t.reportIds), t.params), a = t.reportIds.flatMap((n) => Z(X(e, [n]), t.params).issues), s = new Map(a.map((n) => [JSON.stringify(n), n]));
119
- 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()] };
120
75
  }
121
- function re(e, t) {
122
- const r = fe(e.plan);
123
- if (!r.ok) throw new P("validate", `执行器返回无效计划:${r.errors[0]?.path}`);
124
- const a = e.plan.pages.length, s = e.plan.pages.reduce((n, o) => n + o.components.reduce((d, c) => d + H(c), 0), 0);
125
- return O(t, "maxRows", e.stats.rows), O(t, "maxPages", a), O(t, "maxCells", s), { ...e, stats: { ...e.stats, pages: a, cells: s } };
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 } };
126
81
  }
127
- function se(e, t) {
128
- const r = ye(e.reports, t);
129
- if (!r.ok) throw new le(r.issues);
82
+ function ie(e, t) {
83
+ const r = ke(e.reports, t);
84
+ if (!r.ok) throw new he(r.issues);
130
85
  }
131
- function he(e) {
86
+ function re(e) {
132
87
  const t = { maxRows: 1e5, maxPages: 1e4, maxCells: 2e6, maxOutputBytes: 1e8, maxPreparedBytes: 64e6, maxDurationMs: 12e4, ...e.budget };
133
- Ee(t);
134
- const r = async (s, n) => {
88
+ Fe(t);
89
+ const r = async (n, a) => {
135
90
  const o = Date.now();
136
91
  let d = 0, c = 0;
137
- const i = [], f = {}, u = Object.fromEntries(Object.entries(e.reports).map(([b, S]) => [b, {
138
- ...S,
139
- pagination: { ...e.pagination, ...S.pagination, ...n ? { measurer: n } : {} },
92
+ const i = [], l = {}, f = [], u = Object.fromEntries(Object.entries(e.reports).map(([x, v]) => [x, {
93
+ ...v,
94
+ pagination: { ...e.pagination, ...v.pagination, ...a ? { measurer: a } : {} },
140
95
  dataValidation: {
141
- ...S.dataValidation,
142
- maxRows: Math.min(t.maxRows ?? 1e5, S.dataValidation?.maxRows ?? 1 / 0),
143
- maxCells: Math.min(t.maxCells ?? 2e6, S.dataValidation?.maxCells ?? 1 / 0)
96
+ ...v.dataValidation,
97
+ maxRows: Math.min(t.maxRows ?? 1e5, v.dataValidation?.maxRows ?? 1 / 0),
98
+ maxCells: Math.min(t.maxCells ?? 2e6, v.dataValidation?.maxCells ?? 1 / 0)
144
99
  }
145
- }])), w = await Se(u, { maxPages: t.maxPages, maxCells: t.maxCells, onDatasets: (b, S, I) => {
100
+ }])), p = await je(u, { maxPages: t.maxPages, maxCells: t.maxCells, onDatasets: (x, v, E) => {
146
101
  try {
147
- d += Ie(I, S, { maxRows: t.maxRows, signal: s.signal });
148
- } catch (E) {
149
- throw E instanceof Me ? new k("budget", E.message, "$.budget.maxRows") : E;
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;
150
105
  }
151
- O(t, "maxRows", d), c += Le(I, S, u[b]?.pagination), O(t, "maxCells", c);
152
- } })({ ...s, params: s.params ?? {}, onWarning: (b) => i.push({ code: "layout", message: b, severity: "warning" }), onQueryResult: (b, S) => {
153
- Object.defineProperty(f, b, { value: { revision: S.revision, sourceToken: S.sourceToken }, enumerable: !0, writable: !0 }), i.push(...S.diagnostics ?? []);
154
- } }).catch((b) => {
155
- throw b instanceof P && b.cause instanceof Oe ? new k("budget", b.cause.message, "$.budget.maxPages") : b instanceof P && b.cause instanceof Pe ? new k("budget", b.cause.message, "$.budget.maxCells") : b;
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;
156
116
  });
157
- v(s.signal);
158
- const p = e.assets ? await $(s).run("assets", () => ee(w, { ...e.assets, signal: s.signal })) : { plan: w, diagnostics: [] }, g = p.plan;
159
- i.push(...z(p.diagnostics));
160
- const m = g.pages.reduce((b, S) => b + S.components.reduce((I, E) => I + H(E), 0), 0);
161
- O(t, "maxPages", g.pages.length), O(t, "maxCells", m);
162
- const y = we(s.pdf), A = e.pagination?.measurer || Object.values(e.reports).some((b) => b.pagination?.measurer);
163
- return { plan: g, diagnostics: i, revisions: f, layout: { textMetrics: y ? "font-bytes" : A ? "provided" : "heuristic", ...y ? { fontFingerprint: y } : {} }, stats: { rows: d, pages: g.pages.length, cells: m, durationMs: Date.now() - o } };
164
- }, a = async (s) => {
165
- const n = Date.now();
166
- if (s.format !== "pdf" && s.format !== "xlsx") throw new P("config", "不支持的报表导出格式");
167
- const o = s.format === "pdf" ? await import("@agile-team/mach-report/pdf") : void 0;
168
- v(s.signal);
169
- const d = s.pdf?.customFontFaces ?? (s.pdf?.customFontBytes ? { regular: s.pdf.customFontBytes } : void 0), c = o && d ? o.createFontBytesMeasurer(d) : void 0, i = await r(s, c);
170
- return v(s.signal), te({ ...s, prepared: i }, t, n);
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);
171
131
  };
172
132
  return {
173
- describe: (s) => qe(e.reports, s),
174
- validate: (s) => ye(e.reports, s),
175
- prepare: (s) => j(s.signal, t.maxDurationMs, async (n) => {
176
- const { signal: o, onEvent: d, ...c } = s, i = { ...c, ...c.pdf ? { pdf: C(c.pdf) } : {}, taskId: c.taskId ?? V() }, f = d ? (g) => q(d, g, n) : void 0, u = { ...i, signal: n, onEvent: f };
177
- $(u).runSync("validate", () => se(e, i));
178
- let l;
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;
179
139
  const w = i.pdf?.customFontFaces ?? (i.pdf?.customFontBytes ? { regular: i.pdf.customFontBytes } : void 0);
180
140
  if (!e.executor && w) {
181
- const g = await import("@agile-team/mach-report/pdf");
182
- v(n), l = g.createFontBytesMeasurer(w);
141
+ const b = await import("@agile-team/mach-report/pdf");
142
+ h(a), u = b.createFontBytesMeasurer(w);
183
143
  }
184
- const p = e.executor ? await e.executor.prepare(i, n, f) : await r(u, l);
185
- return re(p, t);
144
+ const p = e.executor ? await e.executor.prepare(i, a, l) : await r(f, u);
145
+ return oe(p, t);
186
146
  }),
187
- exportPrepared: (s) => j(s.signal, t.maxDurationMs, async (n) => {
188
- const o = Date.now(), { signal: d, onEvent: c, ...i } = s, f = re(De(s.prepared, t.maxPreparedBytes ?? 64e6, n), t), u = { ...i, xlsx: G(i.xlsx), prepared: f, ...i.pdf ? { pdf: C(i.pdf) } : {}, taskId: i.taskId ?? V() };
189
- if (u.format !== "pdf" && u.format !== "xlsx") throw new P("config", "不支持的报表导出格式");
190
- const l = c ? (p) => q(c, p, n) : void 0;
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;
191
151
  if (e.executor) {
192
- if (!e.executor.exportPrepared) throw new P("config", "执行器未实现 exportPrepared;请升级执行器或显式使用本地运行时");
193
- const p = await e.executor.exportPrepared(u, n, l);
194
- return O(t, "maxRows", p.stats.rows), O(t, "maxPages", p.stats.pages), O(t, "maxCells", p.stats.cells), O(t, "maxOutputBytes", p.bytes.byteLength), { ...p, stats: { ...p.stats, outputBytes: p.bytes.byteLength } };
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 } };
195
155
  }
196
- const w = { ...u, signal: n, onEvent: l };
197
- if ($(w).runSync("validate", () => Te(w)), e.assets) {
198
- const p = await $(w).run("assets", () => ee(f.plan, { ...e.assets, signal: n }));
199
- f.plan = p.plan, f.diagnostics.push(...z(p.diagnostics));
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));
200
160
  }
201
- return te(w, t, o);
161
+ return ne(w, t, o);
202
162
  }),
203
- export: (s) => j(s.signal, t.maxDurationMs, async (n) => {
204
- const { signal: o, onEvent: d, ...c } = s, i = { ...c, xlsx: G(c.xlsx), ...c.pdf ? { pdf: C(c.pdf) } : {}, taskId: c.taskId ?? V() }, f = d ? (w) => q(d, w, n) : void 0, u = { ...i, signal: n, onEvent: f };
205
- if ($(u).runSync("validate", () => se(e, i)), i.format !== "pdf" && i.format !== "xlsx") throw new P("config", "不支持的报表导出格式");
206
- const l = e.executor ? await e.executor.export(i, n, f) : await a(u);
207
- return O(t, "maxRows", l.stats.rows), O(t, "maxPages", l.stats.pages), O(t, "maxCells", l.stats.cells), O(t, "maxOutputBytes", l.bytes.byteLength), { ...l, stats: { ...l.stats, outputBytes: l.bytes.byteLength } };
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 } };
208
168
  })
209
169
  };
210
170
  }
211
- function St(e = {}) {
171
+ function tr(e = {}) {
212
172
  const t = e.concurrency ?? 1, r = e.maxQueued ?? 20;
213
- if (!Number.isSafeInteger(t) || t < 1 || !Number.isSafeInteger(r) || r < 0) throw new k("budget", "队列并发应为正整数,排队上限应为非负整数");
214
- const a = [], s = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
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();
215
175
  let o = !1, d = 0;
216
176
  const c = () => {
217
- for (; !o && s.size < t && a.length; ) a.shift().start();
177
+ for (; !o && n.size < t && s.length; ) s.shift().start();
218
178
  };
219
179
  return {
220
180
  get active() {
221
- return s.size;
181
+ return n.size;
222
182
  },
223
183
  get pending() {
224
- return a.length;
184
+ return s.length;
225
185
  },
226
- enqueue: (f, u = {}) => {
227
- if (o) throw new k("closed", "任务队列已关闭");
228
- if (v(u.signal), s.size >= t && a.length >= r) throw new k("queue-full", "报表任务队列已满");
229
- const l = u.id ?? `report-${++d}`;
230
- if (n.has(l)) throw new k("queue-full", "任务 ID 正在执行或排队");
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 正在执行或排队");
231
191
  const w = new AbortController();
232
- let p = "queued", g, m, y, A;
233
- const b = new Promise((R, N) => {
234
- y = R, A = N;
235
- }), S = () => {
236
- u.signal?.removeEventListener("abort", E), n.delete(l);
237
- }, I = (R) => {
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) => {
238
198
  if (p !== "queued" && p !== "running") return;
239
- const N = p === "queued";
240
- p = "cancelled", w.abort(R);
199
+ const j = p === "queued";
200
+ p = "cancelled", w.abort(S);
241
201
  try {
242
- v(w.signal);
243
- } catch (T) {
244
- A(T);
202
+ h(w.signal);
203
+ } catch (z) {
204
+ k(z);
245
205
  }
246
- if (N) {
247
- const T = a.indexOf(B);
248
- T >= 0 && a.splice(T, 1), S(), c();
206
+ if (j) {
207
+ const z = s.indexOf(O);
208
+ z >= 0 && s.splice(z, 1), x(), c();
249
209
  }
250
- }, E = () => I(u.signal?.reason), K = (R, N) => {
251
- p === "running" && (!Number.isFinite(R) || R < 0 || N !== void 0 && (!Number.isFinite(N) || N < R) || (g = { completed: R, ...N === void 0 ? {} : { total: N } }));
252
- }, M = (R) => {
253
- p !== "running" || w.signal.aborted || (m = { ...R, taskId: l }, R.completed !== void 0 && K(R.completed, R.total), q(u.onEvent, m, w.signal));
254
- }, B = {
255
- cancel: I,
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,
256
216
  start: () => {
257
- p === "queued" && (p = "running", s.add(B), Promise.resolve().then(() => (v(w.signal), f({ taskId: l, signal: w.signal, reportProgress: K, onEvent: M }))).then(
258
- (R) => {
259
- p === "running" && (p = "completed", y(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));
260
220
  },
261
- (R) => {
262
- p === "running" && (p = "failed", A(R));
221
+ (S) => {
222
+ p === "running" && (p = "failed", k(S));
263
223
  }
264
224
  ).finally(() => {
265
- s.delete(B), S(), c();
225
+ n.delete(O), x(), c();
266
226
  }));
267
227
  }
268
228
  };
269
- return n.add(l), u.signal?.addEventListener("abort", E, { once: !0 }), u.signal?.aborted ? I(u.signal.reason) : s.size < t ? B.start() : a.push(B), { id: l, get status() {
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() {
270
230
  return p;
271
231
  }, get progress() {
272
- return g;
232
+ return b;
273
233
  }, get event() {
274
234
  return m;
275
- }, result: b, cancel: I };
235
+ }, result: D, cancel: v };
276
236
  },
277
- close: (f = {}) => {
237
+ close: (l = {}) => {
278
238
  o = !0;
279
- for (const u of [...a]) u.cancel(new k("closed", "任务队列已关闭"));
280
- if (f.cancelRunning) for (const u of s) u.cancel(new k("closed", "任务队列已关闭"));
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", "任务队列已关闭"));
281
241
  }
282
242
  };
283
243
  }
284
- function ze(e) {
244
+ function et(e) {
285
245
  let t, r;
286
- const a = new Promise((s, n) => {
287
- t = s, r = n;
246
+ const s = new Promise((n, a) => {
247
+ t = n, r = a;
288
248
  });
289
- return a.catch(() => {
290
- }), { progress: e, promise: a, resolve: t, reject: r };
249
+ return s.catch(() => {
250
+ }), { progress: e, promise: s, resolve: t, reject: r };
291
251
  }
292
- function ne(e) {
252
+ function ce(e) {
293
253
  const t = Promise.reject(e);
294
254
  return t.catch(() => {
295
255
  }), t;
296
256
  }
297
- function _e(e, t) {
298
- let r, a, s = !0, n;
257
+ function tt(e, t) {
258
+ let r, s, n = !0, a;
299
259
  function o(i) {
300
- n ??= i ?? new Error("任务心跳更新失败"), a?.reject(n), a = void 0, t(n);
260
+ a ??= i ?? new Error("任务心跳更新失败"), s?.reject(a), s = void 0, t(a);
301
261
  }
302
262
  function d(i) {
303
- const f = Promise.resolve().then(() => e(i?.progress)).then(
263
+ const l = Promise.resolve().then(() => e(i?.progress)).then(
304
264
  () => i?.resolve(),
305
- (u) => {
306
- i?.reject(u), o(u);
265
+ (f) => {
266
+ i?.reject(f), o(f);
307
267
  }
308
268
  ).finally(() => {
309
269
  r = void 0;
310
- const u = a;
311
- a = void 0, u && n === void 0 && d(u);
270
+ const f = s;
271
+ s = void 0, f && a === void 0 && d(f);
312
272
  });
313
- r = f, f.catch((u) => {
314
- o(u);
273
+ r = l, l.catch((f) => {
274
+ o(f);
315
275
  });
316
276
  }
317
277
  function c(i) {
318
- if (!s)
319
- return ne(
320
- new x("closed", "任务进度上报已结束")
278
+ if (!n)
279
+ return ce(
280
+ new R("closed", "任务进度上报已结束")
321
281
  );
322
- if (n !== void 0) return ne(n);
323
- a ? a.progress = i : a = ze(i);
324
- const f = a;
325
- return r || (a = void 0, d(f)), f.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;
326
286
  }
327
287
  return {
328
288
  progress: c,
329
289
  pulse() {
330
- s && !r && n === void 0 && d();
290
+ n && !r && a === void 0 && d();
331
291
  },
332
292
  async finish() {
333
- for (s = !1; r; ) await r;
334
- if (n !== void 0) throw n;
293
+ for (n = !1; r; ) await r;
294
+ if (a !== void 0) throw a;
335
295
  }
336
296
  };
337
297
  }
338
- class ae extends x {
298
+ class de extends R {
339
299
  constructor() {
340
300
  super("capacity", "任务结果超过独立预算,请保存文件引用");
341
301
  }
342
302
  }
343
- function Ue(e) {
344
- const t = e.concurrency ?? 1, r = e.leaseMs ?? 3e4, a = e.heartbeatMs ?? 1e4, s = e.maxResultBytes ?? 256 * 1024;
345
- if (![t, r, a, s].every(
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(
346
306
  (o) => Number.isSafeInteger(o) && o > 0
347
- ) || a * 2 > r)
348
- throw new x(
307
+ ) || s * 2 > r)
308
+ throw new R(
349
309
  "input",
350
310
  "并发、租约、心跳应为正整数,租约至少为心跳的两倍"
351
311
  );
352
- if (a > 2147483647)
353
- throw new x(
312
+ if (s > 2147483647)
313
+ throw new R(
354
314
  "input",
355
315
  "心跳间隔超过平台定时器上限(2147483647毫秒)"
356
316
  );
357
- return { concurrency: t, leaseMs: r, heartbeatMs: a, maxResultBytes: s, now: () => {
317
+ return { concurrency: t, leaseMs: r, heartbeatMs: s, maxResultBytes: n, now: () => {
358
318
  const o = (e.now ?? Date.now)();
359
319
  if (!Number.isSafeInteger(o) || o < 0)
360
- throw new x("input", "任务时钟应返回非负整数毫秒");
320
+ throw new R("input", "任务时钟应返回非负整数毫秒");
361
321
  return o;
362
322
  } };
363
323
  }
364
- async function _(e, t, r) {
365
- Q(t, r);
366
- const a = await e.read(t, r);
367
- if (!a) throw new x("missing", "报表任务不存在");
368
- 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;
369
329
  }
370
- async function D(e, t, r, a = []) {
371
- const s = { ...t, ...r, revision: t.revision + 1 };
372
- 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];
373
333
  if (!await e.compareAndSwap(
374
334
  t.scope,
375
335
  t.id,
376
336
  t.revision,
377
- s
337
+ n
378
338
  ))
379
- throw new x("conflict", "报表任务已被其他请求更新");
380
- return U(s);
339
+ throw new R("conflict", "报表任务已被其他请求更新");
340
+ return U(n);
381
341
  }
382
- async function He(e, t, r, a) {
342
+ async function st(e, t, r, s) {
383
343
  if (!t.trim() || t.length > 128)
384
- throw new x("input", "workerId应为1–128位标识");
385
- for (const s of await e.store.candidates(a, 100)) {
386
- const n = s.cancelRequested ? {
387
- ...s,
388
- 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,
389
349
  status: "cancelled",
390
- updatedAt: a
350
+ updatedAt: s
391
351
  } : {
392
- ...s,
393
- revision: s.revision + 1,
352
+ ...n,
353
+ revision: n.revision + 1,
394
354
  status: "running",
395
- attempt: s.attempt + 1,
396
- updatedAt: a,
397
- lease: { owner: t, expiresAt: a + r }
355
+ attempt: n.attempt + 1,
356
+ updatedAt: s,
357
+ lease: { owner: t, expiresAt: s + r }
398
358
  };
399
- if (n.status === "cancelled" && delete n.lease, await e.store.compareAndSwap(
400
- s.scope,
401
- s.id,
402
- s.revision,
403
- n
359
+ if (a.status === "cancelled" && delete a.lease, await e.store.compareAndSwap(
360
+ n.scope,
361
+ n.id,
362
+ n.revision,
363
+ a
404
364
  ))
405
- return n;
365
+ return a;
406
366
  }
407
367
  }
408
- function oe(e, t, r, a) {
409
- return e.status === "running" && e.attempt === a && e.lease?.owner === t && e.lease.expiresAt > r;
368
+ function fe(e, t, r, s) {
369
+ return e.status === "running" && e.attempt === s && e.lease?.owner === t && e.lease.expiresAt > r;
410
370
  }
411
- async function Ke(e, t, r, a) {
412
- const { scope: s, id: n } = r, o = r.lease.owner;
371
+ async function nt(e, t, r, s) {
372
+ const { scope: n, id: a } = r, o = r.lease.owner;
413
373
  let d;
414
- const c = _e(
374
+ const c = tt(
415
375
  async (m) => {
416
- const y = await _(e.store, s, n), A = t.now();
417
- if (!oe(y, o, A, r.attempt))
418
- throw new x("lease", "报表任务租约已失效");
419
- if (y.cancelRequested) {
420
- a.abort(new x("closed", "任务已请求取消"));
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", "任务已请求取消"));
421
381
  return;
422
382
  }
423
- await D(e.store, y, {
424
- updatedAt: A,
425
- lease: { owner: o, expiresAt: A + t.leaseMs },
383
+ await L(e.store, g, {
384
+ updatedAt: k,
385
+ lease: { owner: o, expiresAt: k + t.leaseMs },
426
386
  ...m ? { progress: m } : {}
427
387
  });
428
388
  },
429
389
  (m) => {
430
- d = m, a.abort(m);
390
+ d = m, s.abort(m);
431
391
  }
432
- ), i = (m, y) => !Number.isFinite(m) || m < 0 || y !== void 0 && (!Number.isFinite(y) || y < m) ? Promise.reject(new x("input", "任务进度无效")) : c.progress({
392
+ ), i = (m, g) => !Number.isFinite(m) || m < 0 || g !== void 0 && (!Number.isFinite(g) || g < m) ? Promise.reject(new R("input", "任务进度无效")) : c.progress({
433
393
  completed: m,
434
- ...y === void 0 ? {} : { total: y }
435
- }), f = setInterval(() => {
394
+ ...g === void 0 ? {} : { total: g }
395
+ }), l = setInterval(() => {
436
396
  c.pulse();
437
397
  }, t.heartbeatMs);
438
- let u, l;
398
+ let f, u;
439
399
  try {
440
400
  const m = Object.prototype.hasOwnProperty.call(
441
401
  e.handlers,
442
402
  r.request.kind
443
403
  ) ? e.handlers[r.request.kind] : void 0;
444
- if (!m) throw new x("input", "报表任务处理器未注册");
445
- if (!a.signal.aborted) {
446
- const y = await m(U(r.request.payload), {
447
- scope: s,
448
- taskId: n,
449
- signal: a.signal,
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,
450
412
  reportProgress: i
451
413
  });
452
- if (u = JSON.parse(F(y)), Ne(u) > t.maxResultBytes) throw new ae();
414
+ if (f = JSON.parse(N(g)), Ke(f) > t.maxResultBytes) throw new de();
453
415
  }
454
416
  } catch (m) {
455
- l = m ?? new Error("报表任务执行失败");
417
+ u = m ?? new Error("报表任务执行失败");
456
418
  } finally {
457
- clearInterval(f), await c.finish().catch(() => {
419
+ clearInterval(l), await c.finish().catch(() => {
458
420
  });
459
421
  }
460
- const w = await _(e.store, s, n), p = t.now();
461
- if (!oe(w, o, p, r.attempt))
462
- throw new x("lease", "任务租约已失效,迟到结果不会写回");
463
- const g = { ...w, updatedAt: p };
464
- delete g.lease, l ??= d, w.cancelRequested || a.signal.aborted && d === void 0 ? g.status = "cancelled" : l !== void 0 ? (g.status = "failed", g.error = {
465
- code: l instanceof ae ? "result-budget" : l instanceof x ? l.code : "execution",
466
- message: l instanceof Error ? l.message.slice(0, 500) : "报表任务执行失败"
467
- }) : (g.status = "completed", g.result = u);
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",
428
+ message: u instanceof Error ? u.message.slice(0, 500) : "报表任务执行失败"
429
+ }) : (b.status = "completed", b.result = f);
468
430
  try {
469
- F(g);
431
+ N(b);
470
432
  } catch {
471
- delete g.result, g.status = "failed", g.error = {
433
+ delete b.result, b.status = "failed", b.error = {
472
434
  code: "result-budget",
473
435
  message: "任务结果与请求的组合超过存储预算,请保存文件引用而非文件内容"
474
436
  };
475
437
  }
476
- return Ve(e.store, w, g);
438
+ return at(e.store, w, b);
477
439
  }
478
- async function Ve(e, t, r) {
440
+ async function at(e, t, r) {
479
441
  try {
480
- return await D(e, t, r, ["lease"]);
481
- } catch (a) {
482
- if (!(a instanceof x) || a.code !== "capacity" || r.status !== "completed") throw a;
483
- return delete r.result, r.status = "failed", r.error = { code: "result-budget", message: "任务结果超过存储剩余预算,请保存文件引用而非文件内容" }, D(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"]);
484
446
  }
485
447
  }
486
- async function ie(e, t, r, a) {
487
- const s = await e.readTombstone?.(t, r);
488
- if (s) {
489
- if (s.requestHash !== await Fe(a)) throw new x("conflict", "相同任务ID不能提交不同内容(幂等保留期内)");
490
- return { scope: t, id: r, revision: s.revision, request: U(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 };
491
453
  }
492
454
  }
493
- function It(e) {
455
+ function rr(e) {
494
456
  e = { ...e, handlers: { ...e.handlers } };
495
- const t = Ue(e), r = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
496
- let s = !1, n = 0;
497
- const o = (i, f) => (Q(i, f), e.store.read(i, f));
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));
498
460
  return {
499
461
  submit: async (i) => {
500
- if (i = { ...i }, Q(i.scope, i.id), !Object.prototype.hasOwnProperty.call(e.handlers, i.kind) || typeof e.handlers[i.kind] != "function")
501
- throw new x("input", "报表任务处理器未注册");
502
- const f = {
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 = {
503
465
  kind: i.kind,
504
466
  payload: JSON.parse(
505
- F(i.payload, {
467
+ N(i.payload, {
506
468
  maxNodes: 19e3,
507
469
  maxCharacters: 75e4
508
470
  })
509
471
  )
510
- }, u = await o(i.scope, i.id);
511
- if (u) {
512
- if (F(u.request) !== F(f))
513
- throw new x("conflict", "相同任务ID不能提交不同内容");
514
- return u;
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;
515
477
  }
516
- const l = await ie(e.store, i.scope, i.id, f);
517
- if (l) return l;
478
+ const u = await le(e.store, i.scope, i.id, l);
479
+ if (u) return u;
518
480
  const w = t.now(), p = {
519
481
  scope: i.scope,
520
482
  id: i.id,
521
483
  revision: 1,
522
- request: f,
484
+ request: l,
523
485
  status: "queued",
524
486
  createdAt: w,
525
487
  updatedAt: w,
526
488
  attempt: 0
527
489
  };
528
490
  if (!await e.store.compareAndSwap(i.scope, i.id, null, p)) {
529
- const g = await o(i.scope, i.id);
530
- if (g && F(g.request) === F(f))
531
- return g;
532
- const m = await ie(e.store, i.scope, i.id, f);
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);
533
495
  if (m) return m;
534
- throw new x("conflict", "报表任务提交发生冲突");
496
+ throw new R("conflict", "报表任务提交发生冲突");
535
497
  }
536
498
  return U(p);
537
499
  },
538
500
  get: o,
539
501
  runNext: (i) => {
540
- if (s)
541
- return Promise.reject(new x("closed", "报表任务服务已关闭"));
542
- if (n >= t.concurrency)
502
+ if (n)
503
+ return Promise.reject(new R("closed", "报表任务服务已关闭"));
504
+ if (a >= t.concurrency)
543
505
  return Promise.reject(
544
- new x("capacity", "报表任务执行槽位已满")
506
+ new R("capacity", "报表任务执行槽位已满")
545
507
  );
546
- n++;
547
- const f = new AbortController();
548
- r.add(f);
549
- const u = (async () => {
508
+ a++;
509
+ const l = new AbortController();
510
+ r.add(l);
511
+ const f = (async () => {
550
512
  try {
551
- const l = await He(
513
+ const u = await st(
552
514
  e,
553
515
  i,
554
516
  t.leaseMs,
555
517
  t.now()
556
518
  );
557
- return l?.status === "running" ? await Ke(e, t, l, f) : l;
519
+ return u?.status === "running" ? await nt(e, t, u, l) : u;
558
520
  } finally {
559
- n--, r.delete(f);
521
+ a--, r.delete(l);
560
522
  }
561
523
  })();
562
- return a.add(u), u.then(
563
- () => a.delete(u),
564
- () => a.delete(u)
565
- ), u;
524
+ return s.add(f), f.then(
525
+ () => s.delete(f),
526
+ () => s.delete(f)
527
+ ), f;
566
528
  },
567
529
  get active() {
568
- return n;
530
+ return a;
569
531
  },
570
- cancel: async (i, f) => {
571
- const u = await _(e.store, i, f);
572
- return u.status !== "queued" && u.status !== "running" ? u : D(e.store, u, {
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, {
573
535
  updatedAt: t.now(),
574
- ...u.status === "queued" ? { status: "cancelled" } : { cancelRequested: !0 }
536
+ ...f.status === "queued" ? { status: "cancelled" } : { cancelRequested: !0 }
575
537
  });
576
538
  },
577
- retry: async (i, f, u) => {
578
- const l = await _(e.store, i, f);
579
- if (l.revision !== u || l.status !== "failed")
580
- throw new x("conflict", "仅可重试当前修订的失败任务");
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", "仅可重试当前修订的失败任务");
581
543
  const w = {
582
- ...l,
544
+ ...u,
583
545
  status: "queued",
584
546
  updatedAt: t.now()
585
547
  };
586
- return delete w.error, delete w.progress, D(e.store, l, w, ["error", "progress"]);
548
+ return delete w.error, delete w.progress, L(e.store, u, w, ["error", "progress"]);
587
549
  },
588
550
  prune: async (i) => {
589
- if (!e.store.prune || !e.store.readTombstone) throw new x("input", "当前任务适配器未实现可选终态保留能力");
551
+ if (!e.store.prune || !e.store.readTombstone) throw new R("input", "当前任务适配器未实现可选终态保留能力");
590
552
  return e.store.prune({ ...i, now: t.now() });
591
553
  },
592
554
  close: async () => {
593
- s = !0;
555
+ n = !0;
594
556
  for (const i of r)
595
- i.abort(new x("closed", "任务服务正在关闭"));
596
- await Promise.allSettled([...a]);
557
+ i.abort(new R("closed", "任务服务正在关闭"));
558
+ await Promise.allSettled([...s]);
597
559
  }
598
560
  };
599
561
  }
600
- function ve(e, t) {
601
- const r = e.assets, a = e[t];
602
- if (!(!r && !a?.assetRenderers))
562
+ function Ie(e, t) {
563
+ const r = e.assets, s = e[t];
564
+ if (!(!r && !s?.assetRenderers))
603
565
  return {
604
566
  ...r,
605
- ...a?.assetFailure === void 0 ? {} : { assetFailure: a.assetFailure },
606
- ...a?.onDiagnostic === void 0 ? {} : { onDiagnostic: a.onDiagnostic },
607
- assetRenderers: { ...r?.assetRenderers, ...a?.assetRenderers },
608
- 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 }
609
571
  };
610
572
  }
611
- function ce(e, t) {
612
- return !e || e.code !== "missing-image" || e.format !== "pdf" && e.format !== "xlsx" ? !1 : typeof ve(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";
613
575
  }
614
- function Xe(e, t) {
615
- const r = Ae(e, t), a = r.issues.filter((n) => !ce(n.diagnostic, t)), s = r.samples.map((n) => ({ ...n, diagnostics: n.diagnostics.filter((o) => !ce(o, t)) }));
616
- 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: [] };
617
579
  }
618
- async function Qe(e, t, r, a, s) {
619
- const n = he({ reports: { sample: { template: r, datasets: e.datasets } }, assets: ve(a, t), budget: {
620
- maxRows: a.maxSampleRows ?? 1e3,
621
- maxPages: a.maxPages ?? 100,
622
- maxCells: a.maxCells ?? 25e4,
623
- maxOutputBytes: a.maxOutputBytes ?? 2e7,
624
- 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
625
587
  } });
626
588
  try {
627
- const { result: o, digest: d } = await j(a.signal, a.maxDurationMs ?? 3e4, async (c) => {
628
- const i = await n.export({ reportIds: ["sample"], params: e.params, format: t, signal: c, fidelity: a.strictOutputs ? "strict" : "warn", pdf: a.pdf, xlsx: a.xlsx }), f = i.diagnostics.filter((l) => l.severity !== "info");
629
- if (a.strictOutputs && f.length) throw new Error(`Strict ${t} encoding found fidelity issues: ${f.slice(0, 3).map((l) => l.message).join("; ")}`);
630
- const u = await a.digest?.(i.bytes);
631
- return v(c), await a.onArtifact?.(e.name, i), v(c), { result: i, digest: u };
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 };
632
594
  });
633
- s.artifacts.push({ fixture: e.name, format: t, bytes: o.bytes.byteLength, pages: o.stats.pages, ...d ? { digest: d } : {} }), s.issues.push(...o.diagnostics.map((c) => ({ code: "output", severity: a.strictOutputs || c.severity === "error" ? "error" : "warning", path: "$.template", fixture: e.name, message: `${t}: ${c.message}` })));
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}` })));
634
596
  } catch (o) {
635
- v(a.signal), s.issues.push({ code: "output", severity: "error", path: "$.template", fixture: e.name, message: `${t}: ${o instanceof Error ? o.message : String(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)}` });
636
598
  }
637
599
  }
638
- async function Ot(e, t = {}) {
639
- v(t.signal);
640
- const r = Xe(e, t);
600
+ async function sr(e, t = {}) {
601
+ h(t.signal);
602
+ const r = ot(e, t);
641
603
  if (!r.ok) return r;
642
- const a = Je(e).template, s = [...new Set(t.formats ?? ["pdf", "xlsx"])];
643
- 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"))
644
606
  return r.issues.push({ code: "output", severity: "error", path: "$.formats", message: "真实文件验收应至少选择PDF/XLSX之一" }), r.ok = !1, r;
645
- for (const n of t.fixtures ?? [])
646
- for (const o of s)
647
- v(t.signal), !(o !== "pdf" && o !== "xlsx") && await Qe(n, o, a, t, r);
648
- 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;
649
611
  }
650
- class h extends Error {
612
+ class y extends Error {
651
613
  constructor(t, r) {
652
614
  super(r), this.code = t, this.name = "ReportInstanceError";
653
615
  }
654
616
  }
655
- function J(e, t) {
656
- 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 h("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 应为安全标识");
657
619
  }
658
- function Ge(e, t) {
620
+ function ct(e, t) {
659
621
  const r = Object.getPrototypeOf(e);
660
- if (r !== (t ? Array.prototype : Object.prototype) && !(r === null && !t) || Object.getOwnPropertySymbols(e).length) throw new h("input", "实例应为普通 JSON 对象");
661
- if (t && Object.keys(e).some((s) => s !== String(Number(s)) || !Number.isSafeInteger(Number(s)) || Number(s) < 0 || Number(s) >= e.length)) throw new h("input", "实例数组不能包含额外属性");
662
- if (Object.getOwnPropertyNames(e).filter((s) => !(t && s === "length")).length !== Object.keys(e).length) throw new h("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", "实例不能包含不可枚举属性");
663
625
  }
664
- function We(e) {
665
- if (!Number.isSafeInteger(e.revision) || e.revision < 1 || typeof e.title != "string" || !e.title.trim() || e.title.length > 512) throw new h("input", "实例修订或标题无效");
666
- if (typeof e.generatedAt != "string" || !Number.isFinite(Date.parse(e.generatedAt)) || new Date(e.generatedAt).toISOString() !== e.generatedAt) throw new h("input", "实例生成时间应为 ISO UTC 字符串");
667
- 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 h("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 应非空且唯一");
668
630
  }
669
- function Ze(e) {
631
+ function ft(e) {
670
632
  return e === null || typeof e == "boolean" || typeof e == "string" || typeof e == "number" && Number.isFinite(e);
671
633
  }
672
- function be(e, t) {
673
- if (!Number.isSafeInteger(t) || t < 1) throw new h("input", "实例快照字节预算应为正安全整数");
674
- let r = 0, a = 0;
675
- const s = /* @__PURE__ */ new Set();
676
- function n(d, c) {
677
- if (++r > 1e6 || c > 64) throw new h("capacity", "实例节点或嵌套深度超过预算");
678
- if (typeof d == "string" && (a += d.length, a > t))
679
- throw new h("capacity", "实例文本超过预算");
680
- if (Ze(d)) return d;
681
- if (!d || typeof d != "object" || s.has(d)) throw new h("input", "实例只允许无循环的有限 JSON 值");
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 值");
682
644
  const i = Array.isArray(d);
683
- Ge(d, i), s.add(d);
684
- const f = /* @__PURE__ */ Object.create(null);
685
- for (const u of Object.keys(d)) {
686
- if (a += u.length, a > t) throw new h("capacity", "实例文本超过预算");
687
- const l = Object.getOwnPropertyDescriptor(d, u);
688
- if (l.get || l.set || ["__proto__", "constructor", "prototype"].includes(u)) throw new h("input", "实例不能包含访问器或危险键");
689
- l.value !== void 0 && (f[u] = n(l.value, c + 1));
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));
690
652
  }
691
- if (s.delete(d), i) {
692
- if (Object.keys(f).length !== d.length) throw new h("input", "实例数组不能稀疏或包含额外属性");
693
- return Array.from({ length: d.length }, (u, l) => f[String(l)]);
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)]);
694
656
  }
695
- return f;
657
+ return l;
696
658
  }
697
- const o = JSON.stringify(n(e, 0));
698
- if (new TextEncoder().encode(o).byteLength > t) throw new h("capacity", "实例快照超过单条字节预算");
659
+ const o = JSON.stringify(a(e, 0));
660
+ if (new TextEncoder().encode(o).byteLength > t) throw new y("capacity", "实例快照超过单条字节预算");
699
661
  return o;
700
662
  }
701
- function W(e, t = 8e6) {
702
- const r = JSON.parse(be(e, t));
703
- J(r.scope, r.id);
704
- const a = /* @__PURE__ */ new Set(["scope", "id", "revision", "title", "generatedAt", "reportIds", "params", "templateRevisions", "sourceRevisions", "plan", "artifacts", "output"]);
705
- if (Object.keys(r).some((n) => !a.has(n))) throw new h("input", "实例包含未知字段");
706
- We(r);
707
- for (const n of [r.params, r.templateRevisions, r.sourceRevisions])
708
- if (!n || typeof n != "object" || Array.isArray(n) || Object.values(n).some((o) => typeof o != "string")) throw new h("input", "实例参数和修订应为字符串字典");
709
- if (r.reportIds.some((n) => !r.templateRevisions[n])) throw new h("input", "每张报表都应记录生成时的模板修订");
710
- const s = fe(r.plan);
711
- if (!s.ok) throw new h("input", `实例渲染计划无效:${s.errors[0]?.path}`);
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}`);
712
674
  if (r.output !== void 0) {
713
- if (!r.output || Object.keys(r.output).some((n) => !["stats", "diagnostics", "layout"].includes(n))) throw new h("input", "实例输出元数据只允许统计、诊断和字体度量;不保存来源令牌");
714
- ge({ ...r.output, plan: r.plan, revisions: {} });
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", "实例来源清单不保存来源令牌");
715
677
  }
716
- return r.artifacts !== void 0 && Ye(r.artifacts), r;
678
+ return r.artifacts !== void 0 && lt(r.artifacts), r;
717
679
  }
718
- function Ye(e) {
719
- if (!Array.isArray(e) || e.length > 100) throw new h("input", "实例文件列表无效");
680
+ function lt(e) {
681
+ if (!Array.isArray(e) || e.length > 100) throw new y("input", "实例文件列表无效");
720
682
  const t = /* @__PURE__ */ new Set();
721
683
  for (const r of e) {
722
- 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 h("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");
723
685
  t.add(r.key);
724
686
  }
725
687
  }
726
- function et(e) {
727
- const { scope: t, id: r, revision: a, title: s, generatedAt: n, reportIds: o, params: d, templateRevisions: c, sourceRevisions: i } = e;
728
- return JSON.parse(JSON.stringify({ scope: t, id: r, revision: a, title: s, generatedAt: n, reportIds: o, params: d, templateRevisions: c, sourceRevisions: i }));
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 }));
729
691
  }
730
- function tt(e) {
692
+ function pt(e) {
731
693
  const t = { maxInstances: 100, maxRevisions: 20, maxBytes: 64e6, maxSnapshotBytes: 8e6, ...e };
732
- if (Object.values(t).some((r) => !Number.isSafeInteger(r) || r < 1)) throw new h("input", "实例存储预算应为正安全整数");
694
+ if (Object.values(t).some((r) => !Number.isSafeInteger(r) || r < 1)) throw new y("input", "实例存储预算应为正安全整数");
733
695
  return t;
734
696
  }
735
- function Pt(e = {}) {
736
- const t = tt(e), r = /* @__PURE__ */ new Map();
737
- let a = 0;
697
+ function nr(e = {}) {
698
+ const t = pt(e), r = /* @__PURE__ */ new Map();
699
+ let s = 0;
738
700
  return {
739
- read: async (s, n, o, d) => {
740
- v(d), J(s, n);
741
- const c = r.get(JSON.stringify([s, n])), i = c?.get(o ?? c.size);
742
- return i ? W(i, 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;
743
705
  },
744
- list: async (s, n = {}) => {
745
- v(n.signal), J(s, "list");
746
- const o = n.limit ?? 25;
747
- if (!Number.isSafeInteger(o) || o < 1 || o > 100) throw new h("input", "实例每页数量应为 1–100");
748
- const d = Array.from(r.values(), (c) => c.get(c.size)).filter((c) => c.scope === s && (!n.after || c.id > n.after) && (!n.reportId || c.reportIds.includes(n.reportId))).sort((c, i) => c.id < i.id ? -1 : 1).slice(0, o + 1);
749
- return { items: d.slice(0, o).map(et), ...d.length > o ? { next: d[o - 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 } : {} };
750
712
  },
751
- compareAndSwap: async (s, n, o, d, c) => {
752
- v(c), J(s, n);
753
- const i = W(d, t.maxSnapshotBytes);
754
- if (i.scope !== s || i.id !== n || i.revision !== (o ?? 0) + 1) throw new h("input", "实例身份或修订不一致");
755
- const f = JSON.stringify([s, n]), u = r.get(f) ?? /* @__PURE__ */ new Map();
756
- if ((u.size || null) !== o) return !1;
757
- const l = new TextEncoder().encode(JSON.stringify(i)).byteLength;
758
- if (u.size >= t.maxRevisions || a + l > t.maxBytes || !u.size && r.size >= t.maxInstances) throw new h("capacity", "实例存储达到预算,请使用持久化归档策略或显式调整容量");
759
- return u.set(i.revision, i), r.set(f, u), a += l, !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;
760
722
  }
761
723
  };
762
724
  }
763
- function rt(e, t = {}) {
725
+ function wt(e, t = {}) {
764
726
  const r = t.maxSnapshotBytes ?? 8e6;
765
- if (!Number.isSafeInteger(r) || r < 1) throw new h("input", "实例快照字节预算应为正安全整数");
727
+ if (!Number.isSafeInteger(r) || r < 1) throw new y("input", "实例快照字节预算应为正安全整数");
766
728
  return {
767
729
  read: e.read.bind(e),
768
730
  list: e.list.bind(e),
769
- save: async (a, s) => {
770
- const n = s.expectedRevision;
771
- if (n !== null && (!Number.isSafeInteger(n) || n < 1 || n >= Number.MAX_SAFE_INTEGER)) throw new h("input", "实例预期修订无效");
772
- const o = JSON.parse(be(a, r)), d = W({ ...o, revision: (n ?? 0) + 1 }, r);
773
- if (v(s.signal), !await e.compareAndSwap(d.scope, d.id, n, d, s.signal)) throw new h("conflict", "实例已存在或已变化,请显式确认修订后保存");
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", "实例已存在或已变化,请显式确认修订后保存");
774
736
  return d;
775
737
  }
776
738
  };
777
739
  }
778
- function kt(e, t) {
779
- return F({ reportIds: e, params: t });
740
+ function ar(e, t) {
741
+ return N({ reportIds: e, params: t });
780
742
  }
781
- function st(e) {
782
- if (!e || typeof e != "object" || Object.getOwnPropertySymbols(e).length) throw new h("input", "生成请求应为普通对象");
743
+ function gt(e) {
744
+ if (!e || typeof e != "object" || Object.getOwnPropertySymbols(e).length) throw new y("input", "生成请求应为普通对象");
783
745
  const t = /* @__PURE__ */ Object.create(null);
784
746
  let r;
785
- const a = /* @__PURE__ */ new Set(["scope", "id", "title", "reportIds", "params", "expectedRevision", "signal"]);
786
- for (const s of Object.getOwnPropertyNames(e)) {
787
- const n = Object.getOwnPropertyDescriptor(e, s);
788
- if (!a.has(s) || !n.enumerable || n.get || n.set) throw new h("input", "生成请求不能包含未知字段或访问器");
789
- 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);
790
752
  }
791
- return { signal: r, request: JSON.parse(F(t)) };
753
+ return { signal: r, request: JSON.parse(N(t)) };
792
754
  }
793
- function At(e) {
794
- const t = JSON.parse(F(e.templateRevisions)), r = C(e.pdf), a = rt(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 });
795
757
  return {
796
- async generate(s) {
797
- const { signal: n, request: o } = st(s);
798
- if (J(o.scope, o.id), o.expectedRevision !== null && (!Number.isSafeInteger(o.expectedRevision) || o.expectedRevision < 1)) throw new h("input", "实例预期修订无效");
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", "实例预期修订无效");
799
761
  const d = e.runtime.validate(o);
800
- if (!d.ok) throw new le(d.issues);
762
+ if (!d.ok) throw new he(d.issues);
801
763
  const c = /* @__PURE__ */ Object.create(null);
802
764
  for (const g of o.reportIds) {
803
765
  if (typeof t[g] != "string" || !t[g]) throw new TypeError(`报表 ${g} 缺少生成时的模板修订`);
804
766
  c[g] = t[g];
805
767
  }
806
- if (v(n), ((await e.instances.read(o.scope, o.id, void 0, n))?.revision ?? null) !== o.expectedRevision)
807
- throw new h("conflict", "实例已存在或已变化,请显式确认修订后生成");
808
- const f = await e.runtime.prepare({ reportIds: o.reportIds, params: d.values, pdf: r, signal: n });
809
- v(n);
810
- const u = /* @__PURE__ */ Object.create(null);
811
- for (const [g, m] of Object.entries(f.revisions)) m.revision !== void 0 && (u[g] = m.revision);
812
- const { plan: l, revisions: w, ...p } = f;
813
- return a.save({
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({
814
776
  scope: o.scope,
815
777
  id: o.id,
816
778
  title: o.title,
817
779
  reportIds: o.reportIds,
818
780
  params: d.values,
819
781
  templateRevisions: c,
820
- sourceRevisions: u,
782
+ sourceRevisions: f,
821
783
  generatedAt: (e.now?.() ?? /* @__PURE__ */ new Date()).toISOString(),
822
- plan: l,
823
- output: p
824
- }, { expectedRevision: o.expectedRevision, signal: n });
784
+ plan: u,
785
+ output: m
786
+ }, { expectedRevision: o.expectedRevision, signal: a });
825
787
  },
826
- read: a.read,
827
- list: a.list,
788
+ read: s.read,
789
+ list: s.list,
828
790
  /** Read an immutable saved revision and encode its plan, never re-query the business source. */
829
- async exportInstance(s) {
830
- const { scope: n, id: o, revision: d, signal: c, format: i, fidelity: f, taskId: u, correlationId: l, onEvent: w } = s, p = C(s.pdf ?? r), g = G(s.xlsx);
831
- J(n, o), v(c);
832
- const m = await a.read(n, o, d, c);
833
- if (!m) throw new h("input", "报表实例不存在");
834
- const y = {
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 = {
835
797
  plan: m.plan,
836
- revisions: Object.fromEntries(m.reportIds.map((A) => [A, { revision: m.sourceRevisions[A] }])),
798
+ revisions: Object.fromEntries(m.reportIds.map((k) => [k, { revision: m.sourceRevisions[k] }])),
837
799
  diagnostics: [{ code: "instance-row-count", severity: "info", message: "历史实例未保存原始取数行数;本次 rows 统计为 0,页面及单元格数由已保存计划校验。" }],
838
800
  stats: { rows: 0, pages: m.plan.pages.length, cells: 0, durationMs: 0 },
839
801
  ...m.output
840
802
  };
841
- return e.runtime.exportPrepared({ prepared: y, format: i, fidelity: f, pdf: p, xlsx: g, signal: c, taskId: u, correlationId: l, onEvent: w });
803
+ return e.runtime.exportPrepared({ prepared: g, format: i, fidelity: l, pdf: p, xlsx: b, signal: c, taskId: f, correlationId: u, onEvent: w });
842
804
  },
843
805
  /** Instance edits are explicit snapshots; source business persistence remains the Provider.save responsibility. */
844
- save: a.save
806
+ save: s.save
845
807
  };
846
808
  }
847
- function L(e, t, r) {
809
+ function q(e, t, r) {
848
810
  if (!Number.isSafeInteger(e) || e < 1 || e > t) throw new RangeError(`${r} 应为 1–${t} 的安全整数`);
849
811
  return e;
850
812
  }
851
- function ue(e) {
813
+ function pe(e) {
852
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");
853
815
  return { key: e.key, format: e.format, bytes: e.bytes, ...e.sha256 ? { sha256: e.sha256 } : {} };
854
816
  }
855
- function nt(e) {
856
- if (!Ce(e).ok || !e.repeat) throw new TypeError("分批生成仅支持有效的逐记录固定标签模板");
817
+ function yt(e) {
818
+ if (!ze(e).ok || !e.repeat) throw new TypeError("分批生成仅支持有效的逐记录固定标签模板");
857
819
  return JSON.parse(JSON.stringify(e));
858
820
  }
859
- function at(e) {
821
+ function ht(e) {
860
822
  const t = /* @__PURE__ */ new Set(), r = e.repeat;
861
823
  r.rowKey && t.add(r.rowKey), typeof r.copies == "object" && t.add(r.copies.field);
862
- const a = (s) => {
863
- s.binding && t.add(s.binding.field);
864
- for (const n of s.grid?.cells ?? []) for (const o of n) o?.children?.forEach(a);
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);
865
827
  };
866
- return e.pages.forEach((s) => s.components.forEach((n) => a(n))), [...t];
867
- }
868
- function ot(e, t, r, a) {
869
- if (!e || typeof e != "object" || Array.isArray(e)) throw new TypeError(`标签记录 ${a} 应为对象`);
870
- const s = /* @__PURE__ */ Object.create(null);
871
- for (const n of t) {
872
- const o = pe(e, n, { dataset: r, rowIndex: a });
873
- if (typeof o == "string" && o.length > 1e6) throw new k("budget", "标签字段超过 1 MB 字符预算", `$.datasets.${r}[${a}].${n}`);
874
- o !== void 0 && (s[n] = o);
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);
875
837
  }
876
- return s;
838
+ return n;
877
839
  }
878
- function it(e, t, r, a) {
879
- const s = t.repeat;
880
- if (!s.rowKey) return;
881
- const n = pe(e, s.rowKey, { rowIndex: a, dataset: s.dataset });
882
- if (!(typeof n == "string" && n.trim() || typeof n == "number" && Number.isFinite(n))) throw new TypeError(`标签记录 ${a} 的业务主键无效`);
883
- const o = JSON.stringify([typeof n, n]);
884
- if (r.keys.has(o)) throw new TypeError(`标签记录 ${a} 的业务主键重复(包含先前批次)`);
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} 的业务主键重复(包含先前批次)`);
885
847
  r.bytes += o.length * 2 + 64, r.keys.add(o);
886
848
  }
887
- function ct(e) {
888
- return Object.entries(e).reduce((t, [r, a]) => t + 64 + r.length * 2 + (typeof a == "string" ? a.length * 2 : 8), 0);
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);
889
851
  }
890
- function ut(e, t) {
852
+ function Rt(e, t) {
891
853
  if (!t) return e;
892
854
  for (const r of e.plan.pages) {
893
- const a = r.meta?.record;
894
- a && typeof a == "object" && "rowIndex" in a && typeof a.rowIndex == "number" && (a.rowIndex += t);
855
+ const s = r.meta?.record;
856
+ s && typeof s == "object" && "rowIndex" in s && typeof s.rowIndex == "number" && (s.rowIndex += t);
895
857
  }
896
858
  return e;
897
859
  }
898
- async function dt(e, t) {
860
+ async function St(e, t) {
899
861
  if (!e.return) return;
900
862
  const r = Promise.resolve(e.return());
901
863
  if (t.aborted) {
@@ -903,128 +865,406 @@ async function dt(e, t) {
903
865
  });
904
866
  return;
905
867
  }
906
- await j(t, void 0, () => r);
868
+ await $(t, void 0, () => r);
907
869
  }
908
- async function de(e, t, r) {
909
- const a = Promise.resolve().then(() => e.onReceipt?.(t, r));
910
- a.catch(() => {
911
- }), await j(r.signal, void 0, () => a);
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);
912
874
  }
913
- function lt(e, t, r) {
914
- return new Promise((a, s) => {
915
- let n = !1, o = !1, d;
875
+ function kt(e, t, r) {
876
+ return new Promise((s, n) => {
877
+ let a = !1, o = !1, d;
916
878
  const c = () => {
917
879
  clearTimeout(d), t.removeEventListener("abort", i);
918
880
  }, i = () => {
919
- n || d !== void 0 || (d = setTimeout(() => {
920
- if (!n) {
921
- n = !0, o = !0, c();
881
+ a || d !== void 0 || (d = setTimeout(() => {
882
+ if (!a) {
883
+ a = !0, o = !0, c();
922
884
  try {
923
- v(t);
924
- } catch (f) {
925
- s(f);
885
+ h(t);
886
+ } catch (l) {
887
+ n(l);
926
888
  }
927
889
  }
928
890
  }, 0));
929
891
  };
930
- e.then((f) => {
892
+ e.then((l) => {
931
893
  if (o) {
932
- Promise.resolve().then(() => r(f)).catch(() => {
894
+ Promise.resolve().then(() => r(l)).catch(() => {
933
895
  });
934
896
  return;
935
897
  }
936
- n || (n = !0, c(), a(f));
937
- }, (f) => {
938
- n || (n = !0, c(), s(f));
898
+ a || (a = !0, c(), s(l));
899
+ }, (l) => {
900
+ a || (a = !0, c(), n(l));
939
901
  }), t.addEventListener("abort", i, { once: !0 }), t.aborted && i();
940
902
  });
941
903
  }
942
- async function Bt(e, t) {
943
- const r = L(t.batchSize ?? 100, 1e3, "batchSize"), a = L(t.maxRows ?? 1e5, 1e6, "maxRows"), s = L(t.maxChunks ?? 1e3, 1e4, "maxChunks"), n = L(t.maxRetainedBytes ?? 16e6, 64e6, "maxRetainedBytes"), o = nt(t.template), d = at(o);
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);
944
906
  if (!e || typeof e[Symbol.asyncIterator] != "function") throw new TypeError("标签来源应为 AsyncIterable");
945
- return j(t.signal, t.runtime?.budget?.maxDurationMs ?? 12e4, async (c) => {
946
- const i = { rows: 0, chunks: [] }, f = { keys: /* @__PURE__ */ new Set(), bytes: 0 }, u = e[Symbol.asyncIterator]();
947
- let l = !1, w = !1, p;
948
- const g = () => p ??= dt(u, c), m = () => {
949
- l || g().catch(() => {
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(() => {
950
912
  });
951
913
  };
952
914
  c.addEventListener("abort", m, { once: !0 });
953
915
  try {
954
- for (; !l; ) {
955
- v(c);
956
- const y = [];
957
- let A = 0;
958
- for (; y.length < r; ) {
959
- const B = await j(c, void 0, () => Promise.resolve(u.next()));
960
- if (B.done) {
961
- l = !0;
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;
962
924
  break;
963
925
  }
964
- if (i.rows + y.length >= a) throw new k("budget", "标签来源行数超过预算", "$.maxRows");
965
- if (i.chunks.length >= s) throw new k("budget", "标签分块数量超过预算", "$.maxChunks");
966
- const R = ot(B.value, d, o.repeat.dataset, i.rows + y.length);
967
- if (it(R, o, f, i.rows + y.length), A += ct(R), f.bytes + A > n) throw new k("budget", "标签当前块字段与全局主键索引超过内存预算", "$.maxRetainedBytes");
968
- y.push(R);
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);
969
931
  }
970
- if (!y.length) break;
971
- const b = he({ ...t.runtime, reports: { labels: { template: o, datasets: { [o.repeat.dataset]: y } } } });
972
- let S;
973
- const I = {
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 = {
974
936
  index: i.chunks.length,
975
937
  rowOffset: i.rows,
976
- rowCount: y.length,
938
+ rowCount: g.length,
977
939
  signal: c,
978
- export: (B) => b.exportPrepared({ pdf: t.pdf, ...B, prepared: S, signal: c })
940
+ export: (O) => D.exportPrepared({ pdf: t.pdf, ...O, prepared: x, signal: c })
979
941
  };
980
942
  let E;
981
- const M = (await je([{ id: `labels-${I.index}`, params: {} }], async () => {
943
+ const P = (await Ge([{ id: `labels-${v.index}`, params: {} }], async () => {
982
944
  try {
983
- S = ut(await b.prepare({ reportIds: ["labels"], pdf: t.pdf, signal: c }), I.rowOffset), v(c);
984
- const B = Promise.resolve(t.execute(S, I)), R = await lt(B, c, (N) => de(t, ue(N), I));
985
- return ue(R);
986
- } catch (B) {
987
- throw E = B, B;
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;
988
950
  }
989
951
  }, { concurrency: 1, signal: c, failure: "stop" }))[0];
990
- if (M.status === "cancelled")
991
- throw v(c), new Error("标签分批任务已取消");
992
- if (M.status === "failed") throw E ?? new Error(M.error.message);
993
- i.chunks.push({ ...M.value, index: I.index, rowOffset: I.rowOffset, rowCount: I.rowCount }), i.rows += y.length, await de(t, M.value, I);
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);
994
956
  }
995
957
  return i;
996
- } catch (y) {
997
- throw w = !0, y;
958
+ } catch (g) {
959
+ throw w = !0, g;
998
960
  } finally {
999
- c.removeEventListener("abort", m), l || await g().catch((y) => {
1000
- if (!w) throw y;
961
+ c.removeEventListener("abort", m), u || await b().catch((g) => {
962
+ if (!w) throw g;
1001
963
  });
1002
964
  }
1003
965
  });
1004
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
+ }
1005
1237
  export {
1006
- h as ReportInstanceError,
1007
- x as ReportJobError,
1008
- k as ReportRuntimeError,
1009
- J as checkInstanceIdentity,
1010
- Q as checkJobIdentity,
1238
+ y as ReportInstanceError,
1239
+ R as ReportJobError,
1240
+ T as ReportRuntimeError,
1241
+ M as checkInstanceIdentity,
1242
+ Y as checkJobIdentity,
1011
1243
  U as cloneJob,
1012
- Pt as createMemoryReportInstanceStore,
1013
- Ft as createMemoryReportJobStore,
1014
- At as createReportGenerationService,
1015
- rt as createReportInstanceManager,
1016
- It as createReportJobService,
1017
- he as createReportRuntime,
1018
- St as createReportTaskQueue,
1019
- kt as reportInstanceParameterKey,
1020
- et as reportInstanceSummary,
1021
- Ot as reviewReportPublication,
1022
- Bt as runLabelStream,
1023
- je as runReportBatch,
1024
- jt as runnableJob,
1025
- F as serializeJobJson,
1026
- Mt as snapshotReportBatchCases,
1027
- W as snapshotReportInstance,
1028
- $t as validateJobRecord,
1029
- Jt as validateJobTransition
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
1030
1270
  };