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