@agile-team/mach-report 2.14.0 → 2.16.0

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