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