@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.
- package/README.md +26 -16
- package/THIRD_PARTY_NOTICES.md +3 -1
- package/dist/{ExcelBindingWizard-CLT2p7P3.cjs → ExcelBindingWizard-CP6h2x1f.cjs} +1 -1
- package/dist/{ExcelBindingWizard-CvsWR8Ga.js → ExcelBindingWizard-HhB3hAJE.js} +3 -3
- package/dist/ParamEditor-CUQLgoxa.cjs +1 -0
- package/dist/ParamEditor-OKesP_nO.js +594 -0
- package/dist/{ReportBatchPanel-DkxTzBkD.cjs → ReportBatchPanel-cZCAMAwH.cjs} +1 -1
- package/dist/{ReportBatchPanel-LqVgiqp7.js → ReportBatchPanel-ruxcbfY6.js} +39 -39
- package/dist/ReportPreview-BcDKCLiK.js +4834 -0
- package/dist/ReportPreview-Bk9nLfO9.cjs +6 -0
- package/dist/{ReportTemplateLibrary-cQ1sqNYo.cjs → ReportTemplateLibrary-BDlNT8JN.cjs} +1 -1
- package/dist/{ReportTemplateLibrary-MjWEtc7X.js → ReportTemplateLibrary-DcwrH-63.js} +1 -1
- package/dist/{RuleEditor-BaR6xUiI.cjs → RuleEditor-BX5S8RSF.cjs} +1 -1
- package/dist/{RuleEditor-ChuXMlei.js → RuleEditor-CGl9XY2s.js} +5 -5
- package/dist/{TemplateOutlinePanel-BHKP89Xz.cjs → TemplateOutlinePanel-CGrT5DFN.cjs} +1 -1
- package/dist/{TemplateOutlinePanel-Dci6aRn1.js → TemplateOutlinePanel-SXCjaPKR.js} +2 -2
- package/dist/{TemplateReusePanel-CY5eO2Sh.cjs → TemplateReusePanel-6Z3wRFz8.cjs} +1 -1
- package/dist/{TemplateReusePanel-B7Gmyc1z.js → TemplateReusePanel-lHLOS9Wn.js} +2 -2
- package/dist/{TemplateReviewPanel-DjlX3xpt.js → TemplateReviewPanel-CJ9PLc48.js} +2 -2
- package/dist/{TemplateReviewPanel-JvZe9_4G.cjs → TemplateReviewPanel-Dpk7sLcF.cjs} +1 -1
- package/dist/analytics.cjs +1 -1
- package/dist/analytics.d.cts +5 -1
- package/dist/analytics.d.ts +5 -1
- package/dist/analytics.js +154 -60
- package/dist/artifact-integrity.json +143 -0
- package/dist/assets-CqIbfbTr.js +126 -0
- package/dist/assets-e4YSke8n.cjs +1 -0
- package/dist/auto-YR7a4BtF.js +240 -0
- package/dist/auto-uVBjX1j5.cjs +1 -0
- package/dist/batch-WzDIXJAt.js +220 -0
- package/dist/batch-z6Aw5GEY.cjs +1 -0
- package/dist/capabilities-DDwXr_cA.js +103 -0
- package/dist/capabilities-DNLyZdNw.cjs +1 -0
- package/dist/codes.d.cts +4 -0
- package/dist/codes.d.ts +4 -0
- package/dist/component-tree-Ca6YYfHq.js +61 -0
- package/dist/component-tree-DkGLEfZC.cjs +1 -0
- package/dist/{computed-Bvk0W15F.js → computed-C-4C2S5h.js} +3 -3
- package/dist/config-Dg_o8e7m.cjs +1 -0
- package/dist/config-XQ4qrQ7Q.js +844 -0
- package/dist/designer-BfQSahxq.js +5163 -0
- package/dist/designer-CPPdeM5_.cjs +2 -0
- package/dist/designer.cjs +1 -1
- package/dist/designer.d.cts +197 -16
- package/dist/designer.d.ts +197 -16
- package/dist/designer.js +1 -1
- package/dist/diagnostic-notification-B9K9We3h.cjs +1 -0
- package/dist/diagnostic-notification-qGAYZdkB.js +7 -0
- package/dist/drill-CsdjgkRM.cjs +1 -0
- package/dist/drill-DIGsZfyB.js +145 -0
- package/dist/encoding-BOGq4qYL.js +21 -0
- package/dist/encoding-BYF9ZTl9.cjs +1 -0
- package/dist/{font-loader-DHto6Lra.js → font-loader-CzI1GuBc.js} +1 -1
- package/dist/{font-loader-vhCT8znW.cjs → font-loader-EKLzOJxf.cjs} +1 -1
- package/dist/index.cjs +8 -9
- package/dist/index.d.cts +84 -4
- package/dist/index.d.ts +84 -4
- package/dist/index.js +829 -833
- package/dist/json-snapshot-D6ioHth9.js +1702 -0
- package/dist/json-snapshot-DknkjvxP.cjs +2 -0
- package/dist/licenses/_bwip-js_generic-4.11.4.txt +24 -0
- package/dist/licenses/_fast-csv_format-4.3.5.txt +22 -0
- package/dist/licenses/_fast-csv_parse-4.3.6.txt +22 -0
- package/dist/licenses/_pdf-lib_fontkit-1.1.1.txt +326 -0
- package/dist/licenses/_pdf-lib_standard-fonts-1.0.0.txt +22 -0
- package/dist/licenses/_pdf-lib_upng-1.0.1.txt +22 -0
- package/dist/licenses/_types_node-14.18.63.txt +22 -0
- package/dist/licenses/_types_pako-2.0.3.txt +22 -0
- package/dist/licenses/_types_pegjs-0.10.6.txt +22 -0
- package/dist/licenses/archiver-5.3.2.txt +23 -0
- package/dist/licenses/archiver-utils-2.1.0.txt +23 -0
- package/dist/licenses/archiver-utils-3.0.4.txt +23 -0
- package/dist/licenses/async-3.2.6.txt +20 -0
- package/dist/licenses/balanced-match-1.0.2.txt +22 -0
- package/dist/licenses/base64-js-1.5.1.txt +22 -0
- package/dist/licenses/big-integer-1.6.52.txt +25 -0
- package/dist/licenses/binary-0.3.0.txt +178 -0
- package/dist/licenses/bl-4.1.0.txt +14 -0
- package/dist/licenses/bluebird-3.4.7.txt +22 -0
- package/dist/licenses/brace-expansion-1.1.21.txt +22 -0
- package/dist/licenses/brace-expansion-2.1.7.txt +22 -0
- package/dist/licenses/buffer-5.7.1.txt +22 -0
- package/dist/licenses/buffer-crc32-0.2.13.txt +20 -0
- package/dist/licenses/buffer-indexof-polyfill-1.0.2.txt +23 -0
- package/dist/licenses/buffers-0.1.1.txt +140 -0
- package/dist/licenses/chainsaw-0.1.0.txt +184 -0
- package/dist/licenses/compress-commons-4.1.2.txt +23 -0
- package/dist/licenses/concat-map-0.0.1.txt +19 -0
- package/dist/licenses/core-util-is-1.0.3.txt +20 -0
- package/dist/licenses/crc-32-1.2.2.txt +202 -0
- package/dist/licenses/crc32-stream-4.0.3.txt +23 -0
- package/dist/licenses/dayjs-1.11.23.txt +22 -0
- package/dist/licenses/duplexer2-0.1.4.txt +27 -0
- package/dist/licenses/end-of-stream-1.4.5.txt +22 -0
- package/dist/licenses/exceljs-4.4.0.txt +23 -0
- package/dist/licenses/fast-csv-4.3.6.txt +22 -0
- package/dist/licenses/fast-png-6.4.0.txt +22 -0
- package/dist/licenses/fs-constants-1.0.0.txt +22 -0
- package/dist/licenses/fs.realpath-1.0.0.txt +44 -0
- package/dist/licenses/fstream-1.0.12.txt +16 -0
- package/dist/licenses/glob-7.2.3.txt +22 -0
- package/dist/licenses/graceful-fs-4.2.11.txt +16 -0
- package/dist/licenses/ieee754-1.2.1.txt +12 -0
- package/dist/licenses/immediate-3.0.6.txt +21 -0
- package/dist/licenses/inflight-1.0.6.txt +16 -0
- package/dist/licenses/inherits-2.0.4.txt +17 -0
- package/dist/licenses/iobuffer-5.4.0.txt +23 -0
- package/dist/licenses/isarray-1.0.0.txt +61 -0
- package/dist/licenses/jszip-3.10.2.txt +652 -0
- package/dist/licenses/lazystream-1.0.1.txt +24 -0
- package/dist/licenses/lie-3.3.0.txt +8 -0
- package/dist/licenses/listenercount-1.0.1.txt +6 -0
- package/dist/licenses/lodash.defaults-4.2.0.txt +48 -0
- package/dist/licenses/lodash.difference-4.5.0.txt +48 -0
- package/dist/licenses/lodash.escaperegexp-4.1.2.txt +48 -0
- package/dist/licenses/lodash.flatten-4.4.0.txt +48 -0
- package/dist/licenses/lodash.groupby-4.6.0.txt +48 -0
- package/dist/licenses/lodash.isboolean-3.0.3.txt +23 -0
- package/dist/licenses/lodash.isequal-4.5.0.txt +48 -0
- package/dist/licenses/lodash.isfunction-3.0.9.txt +48 -0
- package/dist/licenses/lodash.isnil-4.0.0.txt +23 -0
- package/dist/licenses/lodash.isplainobject-4.0.6.txt +48 -0
- package/dist/licenses/lodash.isundefined-3.0.1.txt +23 -0
- package/dist/licenses/lodash.union-4.6.0.txt +48 -0
- package/dist/licenses/lodash.uniq-4.5.0.txt +48 -0
- package/dist/licenses/minimatch-3.1.5.txt +16 -0
- package/dist/licenses/minimatch-5.1.9.txt +16 -0
- package/dist/licenses/minimist-1.2.8.txt +19 -0
- package/dist/licenses/mkdirp-0.5.6.txt +22 -0
- package/dist/licenses/node-sql-parser-5.4.0.txt +202 -0
- package/dist/licenses/normalize-path-3.0.0.txt +22 -0
- package/dist/licenses/once-1.4.0.txt +16 -0
- package/dist/licenses/pako-1.0.11.txt +22 -0
- package/dist/licenses/pako-2.2.0.txt +22 -0
- package/dist/licenses/path-is-absolute-1.0.1.txt +22 -0
- package/dist/licenses/pdf-lib-1.17.1.txt +22 -0
- package/dist/licenses/process-nextick-args-2.0.1.txt +20 -0
- package/dist/licenses/readable-stream-2.3.8.txt +48 -0
- package/dist/licenses/readable-stream-3.6.2.txt +48 -0
- package/dist/licenses/readdir-glob-1.1.3.txt +202 -0
- package/dist/licenses/rimraf-2.7.1.txt +16 -0
- package/dist/licenses/safe-buffer-5.1.2.txt +22 -0
- package/dist/licenses/safe-buffer-5.2.1.txt +22 -0
- package/dist/licenses/saxes-5.0.1.txt +397 -0
- package/dist/licenses/setimmediate-1.0.5.txt +21 -0
- package/dist/licenses/string_decoder-1.1.1.txt +49 -0
- package/dist/licenses/string_decoder-1.3.0.txt +49 -0
- package/dist/licenses/tar-stream-2.2.0.txt +22 -0
- package/dist/licenses/tmp-0.2.7.txt +22 -0
- package/dist/licenses/traverse-0.3.9.txt +25 -0
- package/dist/licenses/tslib-1.14.1.txt +13 -0
- package/dist/licenses/unzipper-0.10.14.txt +26 -0
- package/dist/licenses/util-deprecate-1.0.2.txt +25 -0
- package/dist/licenses/uuid-11.1.1.txt +10 -0
- package/dist/licenses/wrappy-1.0.2.txt +16 -0
- package/dist/licenses/xmlchars-2.2.0.txt +19 -0
- package/dist/licenses/zip-stream-4.1.1.txt +23 -0
- package/dist/matrix-CGRGkn5s.js +112 -0
- package/dist/matrix-gEO7ZM_u.cjs +1 -0
- package/dist/media-B7vnpD8k.cjs +1 -0
- package/dist/media-Y90dHK9z.js +70 -0
- package/dist/param-validation-C3HlcLLO.cjs +1 -0
- package/dist/param-validation-Do7Eg8Zv.js +181 -0
- package/dist/{pdf-AyJGb22z.cjs → pdf-ByVCb1i6.cjs} +49 -49
- package/dist/{pdf-8UPQebOE.js → pdf-DJ5S6ukC.js} +4924 -4872
- package/dist/pdf.cjs +1 -1
- package/dist/pdf.d.cts +20 -3
- package/dist/pdf.d.ts +20 -3
- package/dist/pdf.js +2 -2
- package/dist/{plugin-BGKf-Tqg.js → plugin-C2j5_mhx.js} +2 -2
- package/dist/{plugin-CktLH_Iy.cjs → plugin-Dr39GBRG.cjs} +1 -1
- package/dist/prepared-DdrjLC7L.cjs +1 -0
- package/dist/prepared-DqtpvRTn.js +87 -0
- package/dist/progress-B0ctFpKf.cjs +1 -0
- package/dist/progress-BXzlVbIp.js +29 -0
- package/dist/progress-DJBd9Rb9.cjs +1 -0
- package/dist/progress-Hc2vxoCs.js +52 -0
- package/dist/protocol-BzwMP4Vw.cjs +1 -0
- package/dist/protocol-kt4Iy6-3.js +90 -0
- package/dist/record-bindings-CZWBJ1fU.js +195 -0
- package/dist/record-bindings-DUX1VMlR.cjs +1 -0
- package/dist/{region-binding-workflow-DEJbhpCv.js → region-binding-workflow-CWNvIjkV.js} +1 -1
- package/dist/{region-binding-workflow-BzfbxRiR.cjs → region-binding-workflow-CqSMxQ4p.cjs} +1 -1
- package/dist/report-encoding-worker.cjs +1 -0
- package/dist/report-encoding-worker.d.ts +1 -0
- package/dist/report-encoding-worker.js +2 -0
- package/dist/{report-params-B44imUd4.js → report-params-B1RzkhJj.js} +1 -1
- package/dist/{report-params-SJfhKgaX.cjs → report-params-WDGrA4oP.cjs} +1 -1
- package/dist/rich-text-layout-ALlMoYOG.cjs +3 -0
- package/dist/rich-text-layout-Ct5WrY1g.js +102 -0
- package/dist/runtime-BjKBI530.js +168 -0
- package/dist/runtime-CBFEPKEs.cjs +1 -0
- package/dist/sbom.cdx.json +3982 -0
- package/dist/server/node.d.cts +106 -2
- package/dist/server/node.d.ts +106 -2
- package/dist/server-node.cjs +5 -1
- package/dist/server-node.js +4634 -539
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +780 -5
- package/dist/server.d.ts +780 -5
- package/dist/server.js +773 -691
- package/dist/sha256-BshdOkCC.cjs +1 -0
- package/dist/sha256-DTG-Gq8i.js +157 -0
- package/dist/style-67OqfNed.js +73 -0
- package/dist/style-C22Pbv3T.cjs +1 -0
- package/dist/style.css +1 -1
- package/dist/template-bindings-C2SpvsMU.js +58 -0
- package/dist/template-bindings-CEtWyiLX.cjs +1 -0
- package/dist/template-catalog-BtR2JmCL.js +414 -0
- package/dist/template-catalog-C2NLdrwB.cjs +1 -0
- package/dist/{template-fragments-DFUpq5QM.cjs → template-fragments-BVsbxs4a.cjs} +1 -1
- package/dist/{template-fragments-CLkGo6To.js → template-fragments-By0aZC1D.js} +21 -21
- package/dist/{template-outline-B3xVkzSv.cjs → template-outline-BwRV_eRo.cjs} +1 -1
- package/dist/{template-outline-CFenM1PV.js → template-outline-cnWfT_LK.js} +3 -3
- package/dist/template-registry-C62vpv4a.cjs +1 -0
- package/dist/template-registry-Cw3vRTX2.js +801 -0
- package/dist/textwrap-BEIg2w8y.js +110 -0
- package/dist/textwrap-BI-yJ6Wt.cjs +4 -0
- package/dist/{tree-CqcQ99NM.js → tree-CjVZLRw7.js} +1 -1
- package/dist/vue/async.d.cts +189 -14
- package/dist/vue/async.d.ts +189 -14
- package/dist/vue/index.d.cts +246 -22
- package/dist/vue/index.d.ts +246 -22
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +80 -78
- package/dist/{workbook-session-BfK1yHOO.js → workbook-session-BeSO8PFB.js} +5460 -5295
- package/dist/{workbook-session-DNa2RHNG.cjs → workbook-session-Cbts-22R.cjs} +19 -19
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +104 -2
- package/dist/worker.d.ts +104 -2
- package/dist/worker.js +12 -156
- package/dist/xlsx-node.cjs +35 -35
- package/dist/xlsx-node.js +2138 -2137
- package/dist/xlsx.cjs +4 -4
- package/dist/xlsx.d.cts +24 -10
- package/dist/xlsx.d.ts +24 -10
- package/dist/xlsx.js +303 -277
- package/package.json +7 -4
- package/dist/ParamEditor-CflQV3eQ.js +0 -526
- package/dist/ParamEditor-vIDzvpPV.cjs +0 -1
- package/dist/ReportPreview-CvbqLUzM.cjs +0 -6
- package/dist/ReportPreview-D_ywJ_-H.js +0 -4533
- package/dist/assets-C2U-e-Sz.cjs +0 -4
- package/dist/assets-Q0wUwNrV.js +0 -217
- package/dist/batch-DzaTNLWI.js +0 -371
- package/dist/batch-xMkqYiTr.cjs +0 -1
- package/dist/capabilities-CK_7hizc.js +0 -63
- package/dist/capabilities-CsZ-pNHR.cjs +0 -1
- package/dist/config-0UIohTS7.cjs +0 -1
- package/dist/config-Dt9NtCPl.js +0 -566
- package/dist/data-explanation-BktvER5B.cjs +0 -1
- package/dist/data-explanation-C_J6jYNi.js +0 -16
- package/dist/defaults-DXhiM1ZD.js +0 -10
- package/dist/defaults-xhmcLLrf.cjs +0 -1
- package/dist/designer-Ci1LizA9.js +0 -5020
- package/dist/designer-rtmVIIdN.cjs +0 -2
- package/dist/grid-strokes-Cr7DwUux.cjs +0 -1
- package/dist/grid-strokes-DyyG1q_o.js +0 -53
- package/dist/json-snapshot-BeFT3Tso.js +0 -1952
- package/dist/json-snapshot-D1NTP2oI.cjs +0 -2
- package/dist/matrix-DVyWiYsd.cjs +0 -1
- package/dist/matrix-yZsGnldA.js +0 -227
- package/dist/page-window-index-CIuT4BAv.js +0 -43
- package/dist/page-window-index-DEjnM6IB.cjs +0 -1
- package/dist/param-validation-BlHHXs6u.js +0 -153
- package/dist/param-validation-DCK039V1.cjs +0 -1
- package/dist/progress-7OSZbFok.js +0 -39
- package/dist/progress-BnLiS5eH.cjs +0 -1
- package/dist/render-plan-7xpGrCEl.cjs +0 -1
- package/dist/render-plan-Ck6koX9L.js +0 -13
- package/dist/style-CQ1PK8ZB.js +0 -67
- package/dist/style-UgIJSA1F.cjs +0 -1
- package/dist/task-events-DQ276fn2.cjs +0 -1
- package/dist/task-events-Dpsvf_t2.js +0 -47
- package/dist/template-bindings-BJR4k7qZ.cjs +0 -1
- package/dist/template-bindings-Daui7hLF.js +0 -252
- package/dist/template-registry-COXDEJEM.js +0 -570
- package/dist/template-registry-D3SjENi6.cjs +0 -1
- package/dist/validate-BJ5HIWY8.cjs +0 -1
- package/dist/validate-CkQBWCeg.js +0 -163
package/dist/server.js
CHANGED
|
@@ -1,901 +1,705 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
function
|
|
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
|
|
214
|
-
const
|
|
215
|
-
let o = !1,
|
|
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 &&
|
|
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
|
|
26
|
+
return n.length;
|
|
225
27
|
},
|
|
226
|
-
enqueue: (
|
|
227
|
-
if (o) throw new
|
|
228
|
-
if (
|
|
229
|
-
const
|
|
230
|
-
if (
|
|
231
|
-
const
|
|
232
|
-
let
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
}),
|
|
236
|
-
|
|
237
|
-
},
|
|
238
|
-
if (
|
|
239
|
-
const
|
|
240
|
-
|
|
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
|
-
|
|
243
|
-
} catch (
|
|
244
|
-
|
|
44
|
+
y(m.signal);
|
|
45
|
+
} catch (D) {
|
|
46
|
+
S(D);
|
|
245
47
|
}
|
|
246
|
-
if (
|
|
247
|
-
const
|
|
248
|
-
|
|
48
|
+
if (E) {
|
|
49
|
+
const D = n.indexOf(x);
|
|
50
|
+
D >= 0 && n.splice(D, 1), N(), c();
|
|
249
51
|
}
|
|
250
|
-
},
|
|
251
|
-
|
|
252
|
-
},
|
|
253
|
-
|
|
254
|
-
},
|
|
255
|
-
cancel:
|
|
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
|
-
|
|
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
|
-
|
|
61
|
+
h === "running" && (h = "completed", w(R));
|
|
260
62
|
},
|
|
261
63
|
(R) => {
|
|
262
|
-
|
|
64
|
+
h === "running" && (h = "failed", S(R));
|
|
263
65
|
}
|
|
264
66
|
).finally(() => {
|
|
265
|
-
s.delete(
|
|
67
|
+
s.delete(x), N(), c();
|
|
266
68
|
}));
|
|
267
69
|
}
|
|
268
70
|
};
|
|
269
|
-
return
|
|
270
|
-
return
|
|
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
|
|
74
|
+
return b;
|
|
273
75
|
}, get event() {
|
|
274
|
-
return
|
|
275
|
-
}, result:
|
|
76
|
+
return g;
|
|
77
|
+
}, result: B, cancel: k };
|
|
276
78
|
},
|
|
277
|
-
close: (
|
|
79
|
+
close: (l = {}) => {
|
|
278
80
|
o = !0;
|
|
279
|
-
for (const
|
|
280
|
-
if (
|
|
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
|
|
86
|
+
function Ee(e) {
|
|
285
87
|
let t, r;
|
|
286
|
-
const
|
|
287
|
-
t = s, r =
|
|
88
|
+
const n = new Promise((s, a) => {
|
|
89
|
+
t = s, r = a;
|
|
288
90
|
});
|
|
289
|
-
return
|
|
290
|
-
}), { progress: e, promise:
|
|
91
|
+
return n.catch(() => {
|
|
92
|
+
}), { progress: e, promise: n, resolve: t, reject: r };
|
|
291
93
|
}
|
|
292
|
-
function
|
|
94
|
+
function K(e) {
|
|
293
95
|
const t = Promise.reject(e);
|
|
294
96
|
return t.catch(() => {
|
|
295
97
|
}), t;
|
|
296
98
|
}
|
|
297
|
-
function
|
|
298
|
-
let r,
|
|
99
|
+
function Ie(e, t) {
|
|
100
|
+
let r, n, s = !0, a;
|
|
299
101
|
function o(i) {
|
|
300
|
-
|
|
102
|
+
a ??= i ?? new Error("任务心跳更新失败"), n?.reject(a), n = void 0, t(a);
|
|
301
103
|
}
|
|
302
|
-
function
|
|
303
|
-
const
|
|
104
|
+
function f(i) {
|
|
105
|
+
const l = Promise.resolve().then(() => e(i?.progress)).then(
|
|
304
106
|
() => i?.resolve(),
|
|
305
|
-
(
|
|
306
|
-
i?.reject(
|
|
107
|
+
(d) => {
|
|
108
|
+
i?.reject(d), o(d);
|
|
307
109
|
}
|
|
308
110
|
).finally(() => {
|
|
309
111
|
r = void 0;
|
|
310
|
-
const
|
|
311
|
-
|
|
112
|
+
const d = n;
|
|
113
|
+
n = void 0, d && a === void 0 && f(d);
|
|
312
114
|
});
|
|
313
|
-
r =
|
|
314
|
-
o(
|
|
115
|
+
r = l, l.catch((d) => {
|
|
116
|
+
o(d);
|
|
315
117
|
});
|
|
316
118
|
}
|
|
317
119
|
function c(i) {
|
|
318
120
|
if (!s)
|
|
319
|
-
return
|
|
320
|
-
new
|
|
121
|
+
return K(
|
|
122
|
+
new v("closed", "任务进度上报已结束")
|
|
321
123
|
);
|
|
322
|
-
if (
|
|
323
|
-
|
|
324
|
-
const
|
|
325
|
-
return r || (
|
|
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 &&
|
|
132
|
+
s && !r && a === void 0 && f();
|
|
331
133
|
},
|
|
332
134
|
async finish() {
|
|
333
135
|
for (s = !1; r; ) await r;
|
|
334
|
-
if (
|
|
136
|
+
if (a !== void 0) throw a;
|
|
335
137
|
}
|
|
336
138
|
};
|
|
337
139
|
}
|
|
338
|
-
class
|
|
140
|
+
class G extends v {
|
|
339
141
|
constructor() {
|
|
340
142
|
super("capacity", "任务结果超过独立预算,请保存文件引用");
|
|
341
143
|
}
|
|
342
144
|
}
|
|
343
|
-
function
|
|
344
|
-
const t = e.concurrency ?? 1, r = e.leaseMs ?? 3e4,
|
|
345
|
-
if (![t, r,
|
|
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
|
-
) ||
|
|
348
|
-
throw new
|
|
149
|
+
) || n * 2 > r)
|
|
150
|
+
throw new v(
|
|
349
151
|
"input",
|
|
350
152
|
"并发、租约、心跳应为正整数,租约至少为心跳的两倍"
|
|
351
153
|
);
|
|
352
|
-
if (
|
|
353
|
-
throw new
|
|
154
|
+
if (n > 2147483647)
|
|
155
|
+
throw new v(
|
|
354
156
|
"input",
|
|
355
157
|
"心跳间隔超过平台定时器上限(2147483647毫秒)"
|
|
356
158
|
);
|
|
357
|
-
return { concurrency: t, leaseMs: r, heartbeatMs:
|
|
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
|
|
162
|
+
throw new v("input", "任务时钟应返回非负整数毫秒");
|
|
361
163
|
return o;
|
|
362
164
|
} };
|
|
363
165
|
}
|
|
364
|
-
async function
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
if (!
|
|
368
|
-
return
|
|
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
|
|
172
|
+
async function J(e, t, r, n = []) {
|
|
371
173
|
const s = { ...t, ...r, revision: t.revision + 1 };
|
|
372
|
-
for (const
|
|
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
|
|
380
|
-
return
|
|
181
|
+
throw new v("conflict", "报表任务已被其他请求更新");
|
|
182
|
+
return z(s);
|
|
381
183
|
}
|
|
382
|
-
async function
|
|
184
|
+
async function Ae(e, t, r, n) {
|
|
383
185
|
if (!t.trim() || t.length > 128)
|
|
384
|
-
throw new
|
|
385
|
-
for (const s of await e.store.candidates(
|
|
386
|
-
const
|
|
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:
|
|
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:
|
|
397
|
-
lease: { owner: t, expiresAt:
|
|
198
|
+
updatedAt: n,
|
|
199
|
+
lease: { owner: t, expiresAt: n + r }
|
|
398
200
|
};
|
|
399
|
-
if (
|
|
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
|
-
|
|
205
|
+
a
|
|
404
206
|
))
|
|
405
|
-
return
|
|
207
|
+
return a;
|
|
406
208
|
}
|
|
407
209
|
}
|
|
408
|
-
function
|
|
409
|
-
return e.status === "running" && e.attempt ===
|
|
410
|
-
}
|
|
411
|
-
async function
|
|
412
|
-
const { scope: s, id:
|
|
413
|
-
let
|
|
414
|
-
const c =
|
|
415
|
-
async (
|
|
416
|
-
const
|
|
417
|
-
if (!
|
|
418
|
-
throw new
|
|
419
|
-
if (
|
|
420
|
-
|
|
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
|
|
424
|
-
updatedAt:
|
|
425
|
-
lease: { owner: o, expiresAt:
|
|
426
|
-
...
|
|
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
|
-
(
|
|
430
|
-
|
|
231
|
+
(g) => {
|
|
232
|
+
f = g, n.abort(g);
|
|
431
233
|
}
|
|
432
|
-
), i = (
|
|
433
|
-
completed:
|
|
434
|
-
...
|
|
435
|
-
}),
|
|
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
|
|
240
|
+
let d, u;
|
|
439
241
|
try {
|
|
440
|
-
const
|
|
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 (!
|
|
445
|
-
if (!
|
|
446
|
-
const
|
|
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:
|
|
449
|
-
|
|
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 (
|
|
256
|
+
if (d = JSON.parse(O(w)), pe(d) > t.maxResultBytes) throw new G();
|
|
453
257
|
}
|
|
454
|
-
} catch (
|
|
455
|
-
|
|
258
|
+
} catch (g) {
|
|
259
|
+
u = g ?? new Error("报表任务执行失败");
|
|
456
260
|
} finally {
|
|
457
|
-
clearInterval(
|
|
261
|
+
clearInterval(l), await c.finish().catch(() => {
|
|
458
262
|
});
|
|
459
263
|
}
|
|
460
|
-
const
|
|
461
|
-
if (!
|
|
462
|
-
throw new
|
|
463
|
-
const
|
|
464
|
-
delete
|
|
465
|
-
code:
|
|
466
|
-
message:
|
|
467
|
-
}) : (
|
|
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
|
-
|
|
273
|
+
O(b);
|
|
470
274
|
} catch {
|
|
471
|
-
delete
|
|
275
|
+
delete b.result, b.status = "failed", b.error = {
|
|
472
276
|
code: "result-budget",
|
|
473
277
|
message: "任务结果与请求的组合超过存储预算,请保存文件引用而非文件内容"
|
|
474
278
|
};
|
|
475
279
|
}
|
|
476
|
-
return
|
|
280
|
+
return je(e.store, m, b);
|
|
477
281
|
}
|
|
478
|
-
async function
|
|
282
|
+
async function je(e, t, r) {
|
|
479
283
|
try {
|
|
480
|
-
return await
|
|
481
|
-
} catch (
|
|
482
|
-
if (!(
|
|
483
|
-
return delete r.result, r.status = "failed", r.error = { code: "result-budget", message: "任务结果超过存储剩余预算,请保存文件引用而非文件内容" },
|
|
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
|
|
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
|
|
490
|
-
return { scope: t, id: r, revision: s.revision, request:
|
|
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
|
|
297
|
+
function Et(e) {
|
|
494
298
|
e = { ...e, handlers: { ...e.handlers } };
|
|
495
|
-
const t =
|
|
496
|
-
let s = !1,
|
|
497
|
-
const o = (i,
|
|
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 },
|
|
501
|
-
throw new
|
|
502
|
-
const
|
|
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
|
-
|
|
309
|
+
O(i.payload, {
|
|
506
310
|
maxNodes: 19e3,
|
|
507
311
|
maxCharacters: 75e4
|
|
508
312
|
})
|
|
509
313
|
)
|
|
510
|
-
},
|
|
511
|
-
if (
|
|
512
|
-
if (
|
|
513
|
-
throw new
|
|
514
|
-
return
|
|
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
|
|
517
|
-
if (
|
|
518
|
-
const
|
|
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:
|
|
326
|
+
request: l,
|
|
523
327
|
status: "queued",
|
|
524
|
-
createdAt:
|
|
525
|
-
updatedAt:
|
|
328
|
+
createdAt: m,
|
|
329
|
+
updatedAt: m,
|
|
526
330
|
attempt: 0
|
|
527
331
|
};
|
|
528
|
-
if (!await e.store.compareAndSwap(i.scope, i.id, null,
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
531
|
-
return
|
|
532
|
-
const
|
|
533
|
-
if (
|
|
534
|
-
throw new
|
|
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
|
|
340
|
+
return z(h);
|
|
537
341
|
},
|
|
538
342
|
get: o,
|
|
539
343
|
runNext: (i) => {
|
|
540
344
|
if (s)
|
|
541
|
-
return Promise.reject(new
|
|
542
|
-
if (
|
|
345
|
+
return Promise.reject(new v("closed", "报表任务服务已关闭"));
|
|
346
|
+
if (a >= t.concurrency)
|
|
543
347
|
return Promise.reject(
|
|
544
|
-
new
|
|
348
|
+
new v("capacity", "报表任务执行槽位已满")
|
|
545
349
|
);
|
|
546
|
-
|
|
547
|
-
const
|
|
548
|
-
r.add(
|
|
549
|
-
const
|
|
350
|
+
a++;
|
|
351
|
+
const l = new AbortController();
|
|
352
|
+
r.add(l);
|
|
353
|
+
const d = (async () => {
|
|
550
354
|
try {
|
|
551
|
-
const
|
|
355
|
+
const u = await Ae(
|
|
552
356
|
e,
|
|
553
357
|
i,
|
|
554
358
|
t.leaseMs,
|
|
555
359
|
t.now()
|
|
556
360
|
);
|
|
557
|
-
return
|
|
361
|
+
return u?.status === "running" ? await Te(e, t, u, l) : u;
|
|
558
362
|
} finally {
|
|
559
|
-
|
|
363
|
+
a--, r.delete(l);
|
|
560
364
|
}
|
|
561
365
|
})();
|
|
562
|
-
return
|
|
563
|
-
() =>
|
|
564
|
-
() =>
|
|
565
|
-
),
|
|
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
|
|
372
|
+
return a;
|
|
569
373
|
},
|
|
570
|
-
cancel: async (i,
|
|
571
|
-
const
|
|
572
|
-
return
|
|
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
|
-
...
|
|
378
|
+
...d.status === "queued" ? { status: "cancelled" } : { cancelRequested: !0 }
|
|
575
379
|
});
|
|
576
380
|
},
|
|
577
|
-
retry: async (i,
|
|
578
|
-
const
|
|
579
|
-
if (
|
|
580
|
-
throw new
|
|
581
|
-
const
|
|
582
|
-
...
|
|
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
|
|
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
|
|
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
|
|
596
|
-
await Promise.allSettled([...
|
|
399
|
+
i.abort(new v("closed", "任务服务正在关闭"));
|
|
400
|
+
await Promise.allSettled([...n]);
|
|
597
401
|
}
|
|
598
402
|
};
|
|
599
403
|
}
|
|
600
|
-
function
|
|
601
|
-
const r = e.assets,
|
|
602
|
-
if (!(!r && !
|
|
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
|
-
...
|
|
606
|
-
...
|
|
607
|
-
assetRenderers: { ...r?.assetRenderers, ...
|
|
608
|
-
assetBudget: { ...r?.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
|
|
612
|
-
return !e || e.code !== "missing-image" || e.format !== "pdf" && e.format !== "xlsx" ? !1 : typeof
|
|
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
|
|
615
|
-
const r =
|
|
616
|
-
return { ...r, issues:
|
|
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
|
|
619
|
-
const
|
|
620
|
-
maxRows:
|
|
621
|
-
maxPages:
|
|
622
|
-
maxCells:
|
|
623
|
-
maxOutputBytes:
|
|
624
|
-
maxDurationMs:
|
|
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:
|
|
628
|
-
const i = await
|
|
629
|
-
if (
|
|
630
|
-
const
|
|
631
|
-
return
|
|
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, ...
|
|
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
|
-
|
|
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
|
|
639
|
-
|
|
640
|
-
const r =
|
|
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
|
|
643
|
-
if (!s.length || s.some((
|
|
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
|
|
449
|
+
for (const a of t.fixtures ?? [])
|
|
646
450
|
for (const o of s)
|
|
647
|
-
|
|
648
|
-
return r.ok = r.issues.every((
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
662
|
-
if (Object.getOwnPropertyNames(e).filter((s) => !(t && s === "length")).length !== Object.keys(e).length) throw new
|
|
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
|
|
665
|
-
if (!Number.isSafeInteger(e.revision) || e.revision < 1 || typeof e.title != "string" || !e.title.trim() || e.title.length > 512) throw new
|
|
666
|
-
if (typeof e.generatedAt != "string" || !Number.isFinite(Date.parse(e.generatedAt)) || new Date(e.generatedAt).toISOString() !== e.generatedAt) throw new
|
|
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
|
|
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
|
|
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
|
|
673
|
-
if (!Number.isSafeInteger(t) || t < 1) throw new
|
|
674
|
-
let r = 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
|
|
677
|
-
if (++r > 1e6 || c > 64) throw new
|
|
678
|
-
if (typeof
|
|
679
|
-
throw new
|
|
680
|
-
if (
|
|
681
|
-
if (!
|
|
682
|
-
const i = Array.isArray(
|
|
683
|
-
|
|
684
|
-
const
|
|
685
|
-
for (const
|
|
686
|
-
if (
|
|
687
|
-
const
|
|
688
|
-
if (
|
|
689
|
-
|
|
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(
|
|
692
|
-
if (Object.keys(
|
|
693
|
-
return Array.from({ length:
|
|
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
|
|
499
|
+
return l;
|
|
696
500
|
}
|
|
697
|
-
const o = JSON.stringify(
|
|
698
|
-
if (new TextEncoder().encode(o).byteLength > t) throw new
|
|
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
|
|
702
|
-
const r = JSON.parse(
|
|
703
|
-
|
|
704
|
-
const
|
|
705
|
-
if (Object.keys(r).some((
|
|
706
|
-
|
|
707
|
-
for (const
|
|
708
|
-
if (!
|
|
709
|
-
if (r.reportIds.some((
|
|
710
|
-
const s =
|
|
711
|
-
if (!s.ok) throw new
|
|
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((
|
|
714
|
-
|
|
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 &&
|
|
520
|
+
return r.artifacts !== void 0 && De(r.artifacts), r;
|
|
717
521
|
}
|
|
718
|
-
function
|
|
719
|
-
if (!Array.isArray(e) || e.length > 100) throw new
|
|
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
|
|
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
|
|
727
|
-
const { scope: t, id: r, revision:
|
|
728
|
-
return JSON.parse(JSON.stringify({ scope: t, id: r, revision:
|
|
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
|
|
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
|
|
536
|
+
if (Object.values(t).some((r) => !Number.isSafeInteger(r) || r < 1)) throw new p("input", "实例存储预算应为正安全整数");
|
|
733
537
|
return t;
|
|
734
538
|
}
|
|
735
|
-
function
|
|
736
|
-
const t =
|
|
737
|
-
let
|
|
539
|
+
function Ot(e = {}) {
|
|
540
|
+
const t = Ce(e), r = /* @__PURE__ */ new Map();
|
|
541
|
+
let n = 0;
|
|
738
542
|
return {
|
|
739
|
-
read: async (s,
|
|
740
|
-
|
|
741
|
-
const c = r.get(JSON.stringify([s,
|
|
742
|
-
return i ?
|
|
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,
|
|
745
|
-
|
|
746
|
-
const o =
|
|
747
|
-
if (!Number.isSafeInteger(o) || o < 1 || o > 100) throw new
|
|
748
|
-
const
|
|
749
|
-
return { items:
|
|
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,
|
|
752
|
-
|
|
753
|
-
const i =
|
|
754
|
-
if (i.scope !== s || i.id !==
|
|
755
|
-
const
|
|
756
|
-
if ((
|
|
757
|
-
const
|
|
758
|
-
if (
|
|
759
|
-
return
|
|
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
|
|
567
|
+
function ze(e, t = {}) {
|
|
764
568
|
const r = t.maxSnapshotBytes ?? 8e6;
|
|
765
|
-
if (!Number.isSafeInteger(r) || r < 1) throw new
|
|
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 (
|
|
770
|
-
const
|
|
771
|
-
if (
|
|
772
|
-
const o = JSON.parse(
|
|
773
|
-
if (
|
|
774
|
-
return
|
|
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
|
|
779
|
-
return
|
|
582
|
+
function At(e, t) {
|
|
583
|
+
return O({ reportIds: e, params: t });
|
|
780
584
|
}
|
|
781
|
-
function
|
|
782
|
-
if (!e || typeof e != "object" || Object.getOwnPropertySymbols(e).length) throw new
|
|
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
|
|
589
|
+
const n = /* @__PURE__ */ new Set(["scope", "id", "title", "reportIds", "params", "expectedRevision", "signal"]);
|
|
786
590
|
for (const s of Object.getOwnPropertyNames(e)) {
|
|
787
|
-
const
|
|
788
|
-
if (!
|
|
789
|
-
s === "signal" ? r =
|
|
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(
|
|
595
|
+
return { signal: r, request: JSON.parse(O(t)) };
|
|
792
596
|
}
|
|
793
|
-
function
|
|
794
|
-
const t = JSON.parse(
|
|
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:
|
|
798
|
-
if (
|
|
799
|
-
const
|
|
800
|
-
if (!
|
|
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
|
|
803
|
-
if (typeof t[
|
|
804
|
-
c[
|
|
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 (
|
|
807
|
-
throw new
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
const
|
|
811
|
-
for (const [
|
|
812
|
-
const { plan:
|
|
813
|
-
return
|
|
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:
|
|
622
|
+
params: f.values,
|
|
819
623
|
templateRevisions: c,
|
|
820
|
-
sourceRevisions:
|
|
624
|
+
sourceRevisions: d,
|
|
821
625
|
generatedAt: (e.now?.() ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
822
|
-
plan:
|
|
823
|
-
output:
|
|
824
|
-
}, { expectedRevision: o.expectedRevision, signal:
|
|
626
|
+
plan: u,
|
|
627
|
+
output: g
|
|
628
|
+
}, { expectedRevision: o.expectedRevision, signal: a });
|
|
825
629
|
},
|
|
826
|
-
read:
|
|
827
|
-
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:
|
|
831
|
-
|
|
832
|
-
const
|
|
833
|
-
if (!
|
|
834
|
-
const
|
|
835
|
-
plan:
|
|
836
|
-
revisions: Object.fromEntries(
|
|
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:
|
|
839
|
-
...
|
|
642
|
+
stats: { rows: 0, pages: g.plan.pages.length, cells: 0, durationMs: 0 },
|
|
643
|
+
...g.output
|
|
840
644
|
};
|
|
841
|
-
return e.runtime.exportPrepared({ prepared:
|
|
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:
|
|
648
|
+
save: n.save
|
|
845
649
|
};
|
|
846
650
|
}
|
|
847
|
-
function
|
|
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
|
|
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
|
|
856
|
-
if (!
|
|
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
|
|
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
|
|
666
|
+
const n = (s) => {
|
|
863
667
|
s.binding && t.add(s.binding.field);
|
|
864
|
-
for (const
|
|
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((
|
|
670
|
+
return e.pages.forEach((s) => s.components.forEach((a) => n(a))), [...t];
|
|
867
671
|
}
|
|
868
|
-
function
|
|
869
|
-
if (!e || typeof e != "object" || Array.isArray(e)) throw new TypeError(`标签记录 ${
|
|
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
|
|
872
|
-
const o =
|
|
873
|
-
if (typeof o == "string" && o.length > 1e6) throw new
|
|
874
|
-
o !== void 0 && (s[
|
|
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
|
|
682
|
+
function He(e, t, r, n) {
|
|
879
683
|
const s = t.repeat;
|
|
880
684
|
if (!s.rowKey) return;
|
|
881
|
-
const
|
|
882
|
-
if (!(typeof
|
|
883
|
-
const o = JSON.stringify([typeof
|
|
884
|
-
if (r.keys.has(o)) throw new TypeError(`标签记录 ${
|
|
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
|
|
888
|
-
return Object.entries(e).reduce((t, [r,
|
|
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
|
|
694
|
+
function Ke(e, t) {
|
|
891
695
|
if (!t) return e;
|
|
892
696
|
for (const r of e.plan.pages) {
|
|
893
|
-
const
|
|
894
|
-
|
|
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
|
|
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
|
|
909
|
-
const
|
|
910
|
-
|
|
911
|
-
}), await j(r.signal, void 0, () =>
|
|
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
|
|
914
|
-
return new Promise((
|
|
915
|
-
let
|
|
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(
|
|
721
|
+
clearTimeout(f), t.removeEventListener("abort", i);
|
|
918
722
|
}, i = () => {
|
|
919
|
-
|
|
920
|
-
if (!
|
|
921
|
-
|
|
723
|
+
a || f !== void 0 || (f = setTimeout(() => {
|
|
724
|
+
if (!a) {
|
|
725
|
+
a = !0, o = !0, c();
|
|
922
726
|
try {
|
|
923
|
-
|
|
924
|
-
} catch (
|
|
925
|
-
s(
|
|
727
|
+
y(t);
|
|
728
|
+
} catch (l) {
|
|
729
|
+
s(l);
|
|
926
730
|
}
|
|
927
731
|
}
|
|
928
732
|
}, 0));
|
|
929
733
|
};
|
|
930
|
-
e.then((
|
|
734
|
+
e.then((l) => {
|
|
931
735
|
if (o) {
|
|
932
|
-
Promise.resolve().then(() => r(
|
|
736
|
+
Promise.resolve().then(() => r(l)).catch(() => {
|
|
933
737
|
});
|
|
934
738
|
return;
|
|
935
739
|
}
|
|
936
|
-
|
|
937
|
-
}, (
|
|
938
|
-
|
|
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
|
|
943
|
-
const r =
|
|
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: [] },
|
|
947
|
-
let
|
|
948
|
-
const
|
|
949
|
-
|
|
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",
|
|
756
|
+
c.addEventListener("abort", g, { once: !0 });
|
|
953
757
|
try {
|
|
954
|
-
for (; !
|
|
955
|
-
|
|
956
|
-
const
|
|
957
|
-
let
|
|
958
|
-
for (;
|
|
959
|
-
const
|
|
960
|
-
if (
|
|
961
|
-
|
|
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 +
|
|
965
|
-
if (i.chunks.length >= s) throw new
|
|
966
|
-
const R =
|
|
967
|
-
if (
|
|
968
|
-
|
|
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 (!
|
|
971
|
-
const
|
|
972
|
-
let
|
|
973
|
-
const
|
|
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:
|
|
780
|
+
rowCount: w.length,
|
|
977
781
|
signal: c,
|
|
978
|
-
export: (
|
|
782
|
+
export: (x) => B.exportPrepared({ pdf: t.pdf, ...x, prepared: N, signal: c })
|
|
979
783
|
};
|
|
980
|
-
let
|
|
981
|
-
const
|
|
784
|
+
let $;
|
|
785
|
+
const A = (await ye([{ id: `labels-${k.index}`, params: {} }], async () => {
|
|
982
786
|
try {
|
|
983
|
-
|
|
984
|
-
const
|
|
985
|
-
return
|
|
986
|
-
} catch (
|
|
987
|
-
throw
|
|
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 (
|
|
991
|
-
throw
|
|
992
|
-
if (
|
|
993
|
-
i.chunks.push({ ...
|
|
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 (
|
|
997
|
-
throw
|
|
800
|
+
} catch (w) {
|
|
801
|
+
throw m = !0, w;
|
|
998
802
|
} finally {
|
|
999
|
-
c.removeEventListener("abort",
|
|
1000
|
-
if (!
|
|
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
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
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
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1109
|
+
_ as snapshotReportInstance,
|
|
1110
|
+
Ct as validateJobRecord,
|
|
1111
|
+
zt as validateJobTransition
|
|
1030
1112
|
};
|