@agile-team/mach-report 2.11.2 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +14 -5
  2. package/THIRD_PARTY_NOTICES.md +270 -0
  3. package/dist/{ExcelBindingWizard-LWX6G1A2.js → ExcelBindingWizard-CeAf4QSE.js} +2 -2
  4. package/dist/{ExcelBindingWizard-a4kslPHF.cjs → ExcelBindingWizard-y0mT-AHR.cjs} +1 -1
  5. package/dist/{RuleEditor-C2QsOHOs.cjs → RuleEditor-ChRzNQuF.cjs} +1 -1
  6. package/dist/{RuleEditor-D9wQHrkf.js → RuleEditor-DzAmW5YH.js} +1 -1
  7. package/dist/analytics.d.cts +28 -0
  8. package/dist/analytics.d.ts +28 -0
  9. package/dist/assets-C2U-e-Sz.cjs +4 -0
  10. package/dist/assets-Q0wUwNrV.js +217 -0
  11. package/dist/code-options-BKXXY7NI.js +18 -0
  12. package/dist/code-options-BUTChiZZ.cjs +1 -0
  13. package/dist/codes.cjs +9 -0
  14. package/dist/codes.d.cts +223 -0
  15. package/dist/codes.d.ts +223 -0
  16. package/dist/codes.js +26917 -0
  17. package/dist/designer.cjs +2 -2
  18. package/dist/designer.d.cts +267 -0
  19. package/dist/designer.d.ts +267 -0
  20. package/dist/designer.js +2737 -1941
  21. package/dist/grid-strokes-Cr7DwUux.cjs +1 -0
  22. package/dist/grid-strokes-DyyG1q_o.js +53 -0
  23. package/dist/index.cjs +7 -7
  24. package/dist/index.d.cts +80 -1
  25. package/dist/index.d.ts +80 -1
  26. package/dist/index.js +404 -374
  27. package/dist/pdf.cjs +76 -59
  28. package/dist/pdf.d.cts +51 -0
  29. package/dist/pdf.d.ts +51 -0
  30. package/dist/pdf.js +32128 -32048
  31. package/dist/record-bindings-By_UKZ2g.cjs +1 -0
  32. package/dist/{list-cell-ClFra1zS.js → record-bindings-D-5jQlTj.js} +67 -44
  33. package/dist/{region-binding-workflow-DhQvu1co.cjs → region-binding-workflow-BzfbxRiR.cjs} +1 -1
  34. package/dist/{region-binding-workflow-CXDmt9Bs.js → region-binding-workflow-CcUq8W2Q.js} +1 -1
  35. package/dist/server/node.d.cts +52 -1
  36. package/dist/server/node.d.ts +52 -1
  37. package/dist/server-node.cjs +1 -1
  38. package/dist/server-node.js +239 -210
  39. package/dist/server.cjs +1 -1
  40. package/dist/server.d.cts +95 -3
  41. package/dist/server.d.ts +95 -3
  42. package/dist/server.js +456 -433
  43. package/dist/style.css +1 -1
  44. package/dist/{template-registry-WNXdkiET.js → template-registry-BjE1VS6g.js} +221 -157
  45. package/dist/template-registry-D3SjENi6.cjs +1 -0
  46. package/dist/template-review-BfCC8Ng9.cjs +2 -0
  47. package/dist/{template-review-BdcXSYbx.js → template-review-BzpcI-tR.js} +772 -666
  48. package/dist/validate-BJ5HIWY8.cjs +1 -0
  49. package/dist/validate-DbgEM1Hh.js +163 -0
  50. package/dist/vue/async.d.cts +121 -2
  51. package/dist/vue/async.d.ts +121 -2
  52. package/dist/vue/index.d.cts +114 -6
  53. package/dist/vue/index.d.ts +114 -6
  54. package/dist/{workbook-session-BKOTwcoq.js → workbook-session-BPb3TMnT.js} +1 -1
  55. package/dist/{workbook-session-CLYLhZWu.cjs → workbook-session-DNa2RHNG.cjs} +1 -1
  56. package/dist/worker.cjs +1 -1
  57. package/dist/worker.d.cts +52 -1
  58. package/dist/worker.d.ts +52 -1
  59. package/dist/worker.js +2 -2
  60. package/dist/xlsx.cjs +1 -1
  61. package/dist/xlsx.d.cts +40 -0
  62. package/dist/xlsx.d.ts +40 -0
  63. package/dist/xlsx.js +3 -3
  64. package/package.json +16 -3
  65. package/dist/assets-Bu6UohJx.cjs +0 -1
  66. package/dist/assets-DegqDNqY.js +0 -160
  67. package/dist/list-cell-BuYn4tGF.cjs +0 -1
  68. package/dist/template-registry-ukBGlm8N.cjs +0 -1
  69. package/dist/template-review-BXp2oyqg.cjs +0 -1
  70. package/dist/textwrap-CWHyzkBH.cjs +0 -4
  71. package/dist/textwrap-DE1kgcJB.js +0 -110
  72. package/dist/validate-7s0yn6ii.js +0 -148
  73. package/dist/validate-DsRiNw8h.cjs +0 -1
package/dist/server.js CHANGED
@@ -1,422 +1,425 @@
1
- import { A as oe, b as P, k as ie, B as ce, a as le, P as ue, n as de, y as fe } from "./template-review-BdcXSYbx.js";
2
- import { g as T } from "./report-params-B44imUd4.js";
3
- import { d as H, r as pe, R as Y } from "./param-validation-BlHHXs6u.js";
4
- import { v as ge, c as q, a as R, t as b, R as A, b as v, d as $, s as I, e as D, j as we, f as me } from "./batch-mRqhhhjt.js";
5
- import { g as et, r as tt, h as rt, i as st, k as nt, l as at } from "./batch-mRqhhhjt.js";
6
- import { c as ee } from "./validate-7s0yn6ii.js";
7
- import { r as Q, c as M, n as z } from "./task-events-Dpsvf_t2.js";
8
- import { T as ye } from "./tree-CqcQ99NM.js";
9
- import { p as he } from "./template-registry-WNXdkiET.js";
10
- function te(e, t) {
11
- if (t.length === 0) throw new P("config", "缺少报表 ID");
12
- return t.map((s) => {
13
- if (!Object.prototype.hasOwnProperty.call(e, s)) throw new P("config", `未注册报表 ${s}`);
14
- return e[s];
1
+ import { A as ce, b as k, k as le, B as ue, a as de, P as fe, n as pe, y as ge } from "./template-review-BzpcI-tR.js";
2
+ import { g as F } from "./report-params-B44imUd4.js";
3
+ import { d as X, r as we, R as te } from "./param-validation-BlHHXs6u.js";
4
+ import { v as me, c as z, a as R, t as x, R as A, b, d as L, s as I, e as T, j as ye, f as he } from "./batch-mRqhhhjt.js";
5
+ import { g as at, r as ot, h as it, i as ct, k as lt, l as ut } from "./batch-mRqhhhjt.js";
6
+ import { c as re } from "./validate-DbgEM1Hh.js";
7
+ import { r as G, c as C, n as _ } from "./task-events-Dpsvf_t2.js";
8
+ import { T as ve } from "./tree-CqcQ99NM.js";
9
+ import { r as be } from "./assets-Q0wUwNrV.js";
10
+ import { p as xe } from "./template-registry-BjE1VS6g.js";
11
+ function se(e, t) {
12
+ if (t.length === 0) throw new k("config", "缺少报表 ID");
13
+ return t.map((r) => {
14
+ if (!Object.prototype.hasOwnProperty.call(e, r)) throw new k("config", `未注册报表 ${r}`);
15
+ return e[r];
15
16
  });
16
17
  }
17
- function C(e) {
18
- return e.grid?.cells.reduce((t, s) => t + s.reduce((a, r) => a + (r ? 1 + (r.children?.reduce((n, i) => n + C(i), 0) ?? 0) : 0), 0), 0) ?? 0;
18
+ function $(e) {
19
+ return e.grid?.cells.reduce((t, r) => t + r.reduce((a, s) => a + (s ? 1 + (s.children?.reduce((n, i) => n + $(i), 0) ?? 0) : 0), 0), 0) ?? 0;
19
20
  }
20
- function ve(e, t, s) {
21
- return e.pages.reduce((a, r) => a + r.components.reduce((n, i) => i.kind !== "list" ? n + C(i) : n + de(i, t, s), 0), 0);
21
+ function Se(e, t, r) {
22
+ return e.pages.reduce((a, s) => a + s.components.reduce((n, i) => i.kind !== "list" ? n + $(i) : n + pe(i, t, r), 0), 0);
22
23
  }
23
- function be(e, t = Object.keys(e)) {
24
- return te(e, t).map((s, a) => {
25
- const r = t[a], n = T(e, [r]);
24
+ function Re(e, t = Object.keys(e)) {
25
+ return se(e, t).map((r, a) => {
26
+ const s = t[a], n = F(e, [s]);
26
27
  return {
27
- id: r,
28
+ id: s,
28
29
  params: JSON.parse(JSON.stringify(n)),
29
- paramsSchema: pe(n),
30
- datasetsSchema: Object.fromEntries(Object.entries(s.dataSchema ?? {}).map(([i, l]) => [i, oe(typeof s.template == "function" ? void 0 : s.template, i, l)])),
30
+ paramsSchema: we(n),
31
+ datasetsSchema: Object.fromEntries(Object.entries(r.dataSchema ?? {}).map(([i, l]) => [i, ce(typeof r.template == "function" ? void 0 : r.template, i, l)])),
31
32
  capabilities: {
32
- save: !!s.provider?.save,
33
- export: !!s.provider?.export,
34
- templates: !!s.provider?.templates
33
+ save: !!r.provider?.save,
34
+ export: !!r.provider?.export,
35
+ templates: !!r.provider?.templates
35
36
  }
36
37
  };
37
38
  });
38
39
  }
39
- function re(e, t) {
40
- te(e, t.reportIds);
41
- const s = H(T(e, t.reportIds), t.params), a = t.reportIds.flatMap((n) => H(T(e, [n]), t.params).issues), r = new Map(a.map((n) => [JSON.stringify(n), n]));
42
- return { ...s, ok: r.size === 0, issues: [...r.values()] };
40
+ function ne(e, t) {
41
+ se(e, t.reportIds);
42
+ const r = X(F(e, t.reportIds), t.params), a = t.reportIds.flatMap((n) => X(F(e, [n]), t.params).issues), s = new Map(a.map((n) => [JSON.stringify(n), n]));
43
+ return { ...r, ok: s.size === 0, issues: [...s.values()] };
43
44
  }
44
- function xe(e, t) {
45
- const s = ee(e.plan);
46
- if (!s.ok) throw new P("validate", `执行器返回无效计划:${s.errors[0]?.path}`);
47
- const a = e.plan.pages.length, r = e.plan.pages.reduce((n, i) => n + i.components.reduce((l, f) => l + C(f), 0), 0);
48
- return R(t, "maxRows", e.stats.rows), R(t, "maxPages", a), R(t, "maxCells", r), { ...e, stats: { ...e.stats, pages: a, cells: r } };
45
+ function Ie(e, t) {
46
+ const r = re(e.plan);
47
+ if (!r.ok) throw new k("validate", `执行器返回无效计划:${r.errors[0]?.path}`);
48
+ const a = e.plan.pages.length, s = e.plan.pages.reduce((n, i) => n + i.components.reduce((l, f) => l + $(f), 0), 0);
49
+ return R(t, "maxRows", e.stats.rows), R(t, "maxPages", a), R(t, "maxCells", s), { ...e, stats: { ...e.stats, pages: a, cells: s } };
49
50
  }
50
- function X(e, t) {
51
- const s = re(e.reports, t);
52
- if (!s.ok) throw new Y(s.issues);
51
+ function U(e, t) {
52
+ const r = ne(e.reports, t);
53
+ if (!r.ok) throw new te(r.issues);
53
54
  }
54
- function G(e = []) {
55
- return e.map(({ code: t, message: s, severity: a, pageIndex: r, componentIndex: n }) => ({ code: t, message: s, severity: a, path: `$.pages.${r}.components.${n}` }));
55
+ function q(e = []) {
56
+ return e.map(({ code: t, message: r, severity: a, pageIndex: s, componentIndex: n }) => ({ code: t, message: r, severity: a, path: `$.pages.${s}.components.${n}` }));
56
57
  }
57
- function Se(e) {
58
+ function Oe(e) {
58
59
  const t = { maxRows: 1e5, maxPages: 1e4, maxCells: 2e6, maxOutputBytes: 1e8, maxDurationMs: 12e4, ...e.budget };
59
- ge(t);
60
- const s = async (r, n) => {
60
+ me(t);
61
+ const r = async (s, n) => {
61
62
  const i = Date.now();
62
63
  let l = 0, f = 0;
63
- const o = [], u = {}, c = Object.fromEntries(Object.entries(e.reports).map(([g, p]) => [g, {
64
- ...p,
65
- pagination: { ...e.pagination, ...p.pagination, ...n ? { measurer: n } : {} },
64
+ const o = [], d = {}, c = Object.fromEntries(Object.entries(e.reports).map(([p, v]) => [p, {
65
+ ...v,
66
+ pagination: { ...e.pagination, ...v.pagination, ...n ? { measurer: n } : {} },
66
67
  dataValidation: {
67
- ...p.dataValidation,
68
- maxRows: Math.min(t.maxRows ?? 1e5, p.dataValidation?.maxRows ?? 1 / 0),
69
- maxCells: Math.min(t.maxCells ?? 2e6, p.dataValidation?.maxCells ?? 1 / 0)
68
+ ...v.dataValidation,
69
+ maxRows: Math.min(t.maxRows ?? 1e5, v.dataValidation?.maxRows ?? 1 / 0),
70
+ maxCells: Math.min(t.maxCells ?? 2e6, v.dataValidation?.maxCells ?? 1 / 0)
70
71
  }
71
- }])), m = await ie(c, { maxPages: t.maxPages, maxCells: t.maxCells, onDatasets: (g, p, h) => {
72
+ }])), y = await le(c, { maxPages: t.maxPages, maxCells: t.maxCells, onDatasets: (p, v, j) => {
72
73
  try {
73
- l += ce(h, p, { maxRows: t.maxRows, signal: r.signal });
74
- } catch (S) {
75
- throw S instanceof ye ? new A("budget", S.message, "$.budget.maxRows") : S;
74
+ l += ue(j, v, { maxRows: t.maxRows, signal: s.signal });
75
+ } catch (P) {
76
+ throw P instanceof ve ? new A("budget", P.message, "$.budget.maxRows") : P;
76
77
  }
77
- R(t, "maxRows", l), f += ve(h, p, c[g]?.pagination), R(t, "maxCells", f);
78
- } })({ ...r, params: r.params ?? {}, onWarning: (g) => o.push({ code: "layout", message: g, severity: "warning" }), onQueryResult: (g, p) => {
79
- Object.defineProperty(u, g, { value: { revision: p.revision, sourceToken: p.sourceToken }, enumerable: !0, writable: !0 }), o.push(...p.diagnostics ?? []);
80
- } }).catch((g) => {
81
- throw g instanceof P && g.cause instanceof le ? new A("budget", g.cause.message, "$.budget.maxPages") : g instanceof P && g.cause instanceof ue ? new A("budget", g.cause.message, "$.budget.maxCells") : g;
78
+ R(t, "maxRows", l), f += Se(j, v, c[p]?.pagination), R(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;
82
83
  });
83
- b(r.signal);
84
- const y = m.pages.reduce((g, p) => g + p.components.reduce((h, S) => h + C(S), 0), 0);
85
- return R(t, "maxPages", m.pages.length), R(t, "maxCells", y), { plan: m, diagnostics: o, revisions: u, stats: { rows: l, pages: m.pages.length, cells: y, durationMs: Date.now() - i } };
86
- }, a = async (r) => {
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 R(t, "maxPages", w.pages.length), R(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) => {
87
90
  const n = Date.now();
88
- if (r.format !== "pdf" && r.format !== "xlsx") throw new P("config", "不支持的报表导出格式");
89
- const i = r.format === "pdf" ? await import("@agile-team/mach-report/pdf") : void 0;
90
- b(r.signal);
91
- const l = r.pdf?.customFontFaces ?? (r.pdf?.customFontBytes ? { regular: r.pdf.customFontBytes } : void 0), f = i && l ? i.createFontBytesMeasurer(l) : void 0, o = await s(r, f);
92
- b(r.signal);
93
- const u = M(r), c = await u.run("encode", async () => {
94
- let y;
95
- if (r.format === "pdf") {
96
- b(r.signal);
97
- const g = await i.renderPlanToPdf(o.plan, { ...r.pdf, ...f ? { measurer: f } : {}, fidelity: r.fidelity, signal: r.signal, onProgress: (p, h) => u.progress("encode", p, h) });
98
- y = g.bytes, o.diagnostics.push(...G(g.diagnostics)), o.diagnostics.push(...g.fidelityWarnings.map((p) => ({ code: "pdf-fidelity", message: p, severity: "warning" })), ...g.pageErrors.map((p) => ({ code: "pdf-page", message: p, severity: "error" }))), g.unsupportedTextCount && o.diagnostics.push({ code: "pdf-font", message: `${g.unsupportedTextCount} 段文本包含当前字体不支持的字符`, severity: "warning" });
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" });
99
102
  } else {
100
- const { renderPlanToXlsx: g } = await import("@agile-team/mach-report/xlsx");
101
- b(r.signal);
102
- const p = await g(o.plan, { ...r.xlsx, fidelity: r.fidelity, signal: r.signal, onProgress: (h, S) => u.progress("encode", h, S) });
103
- y = new Uint8Array(p.buffer), o.diagnostics.push(...G(p.diagnostics)), o.diagnostics.push(...p.warnings.map((h) => ({ code: "xlsx-fidelity", message: h, severity: "warning" })));
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" })));
104
107
  }
105
- return b(r.signal), y;
108
+ return x(s.signal), h;
106
109
  });
107
110
  R(t, "maxOutputBytes", c.byteLength);
108
- const { plan: d, ...m } = o;
109
- return { ...m, bytes: c, format: r.format, contentType: r.format === "pdf" ? "application/pdf" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", stats: { ...m.stats, durationMs: Date.now() - n, outputBytes: c.byteLength } };
111
+ const { plan: u, ...y } = o;
112
+ return { ...y, bytes: c, format: s.format, contentType: s.format === "pdf" ? "application/pdf" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", stats: { ...y.stats, durationMs: Date.now() - n, outputBytes: c.byteLength } };
110
113
  };
111
114
  return {
112
- describe: (r) => be(e.reports, r),
113
- validate: (r) => re(e.reports, r),
114
- prepare: (r) => q(r.signal, t.maxDurationMs, async (n) => {
115
- const { signal: i, onEvent: l, ...f } = r, o = { ...f, taskId: f.taskId ?? Q() }, u = l ? (m) => z(l, m, n) : void 0, c = { ...o, signal: n, onEvent: u };
116
- M(c).runSync("validate", () => X(e, o));
117
- const d = e.executor ? await e.executor.prepare(o, n, u) : await s(c);
118
- return xe(d, t);
115
+ describe: (s) => Re(e.reports, s),
116
+ validate: (s) => ne(e.reports, s),
117
+ prepare: (s) => z(s.signal, t.maxDurationMs, async (n) => {
118
+ const { signal: i, onEvent: l, ...f } = s, o = { ...f, taskId: f.taskId ?? G() }, d = l ? (y) => _(l, y, n) : void 0, c = { ...o, signal: n, onEvent: d };
119
+ C(c).runSync("validate", () => U(e, o));
120
+ const u = e.executor ? await e.executor.prepare(o, n, d) : await r(c);
121
+ return Ie(u, t);
119
122
  }),
120
- export: (r) => q(r.signal, t.maxDurationMs, async (n) => {
121
- const { signal: i, onEvent: l, ...f } = r, o = { ...f, taskId: f.taskId ?? Q() }, u = l ? (m) => z(l, m, n) : void 0, c = { ...o, signal: n, onEvent: u };
122
- if (M(c).runSync("validate", () => X(e, o)), o.format !== "pdf" && o.format !== "xlsx") throw new P("config", "不支持的报表导出格式");
123
- const d = e.executor ? await e.executor.export(o, n, u) : await a(c);
124
- return R(t, "maxRows", d.stats.rows), R(t, "maxPages", d.stats.pages), R(t, "maxCells", d.stats.cells), R(t, "maxOutputBytes", d.bytes.byteLength), { ...d, stats: { ...d.stats, outputBytes: d.bytes.byteLength } };
123
+ export: (s) => z(s.signal, t.maxDurationMs, async (n) => {
124
+ const { signal: i, onEvent: l, ...f } = s, o = { ...f, taskId: f.taskId ?? G() }, d = l ? (y) => _(l, y, n) : void 0, c = { ...o, signal: n, onEvent: d };
125
+ if (C(c).runSync("validate", () => U(e, o)), o.format !== "pdf" && o.format !== "xlsx") throw new k("config", "不支持的报表导出格式");
126
+ const u = e.executor ? await e.executor.export(o, n, d) : await a(c);
127
+ return R(t, "maxRows", u.stats.rows), R(t, "maxPages", u.stats.pages), R(t, "maxCells", u.stats.cells), R(t, "maxOutputBytes", u.bytes.byteLength), { ...u, stats: { ...u.stats, outputBytes: u.bytes.byteLength } };
125
128
  })
126
129
  };
127
130
  }
128
- function Qe(e = {}) {
129
- const t = e.concurrency ?? 1, s = e.maxQueued ?? 20;
130
- if (!Number.isSafeInteger(t) || t < 1 || !Number.isSafeInteger(s) || s < 0) throw new A("budget", "队列并发应为正整数,排队上限应为非负整数");
131
- const a = [], r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
131
+ function Ze(e = {}) {
132
+ const t = e.concurrency ?? 1, r = e.maxQueued ?? 20;
133
+ if (!Number.isSafeInteger(t) || t < 1 || !Number.isSafeInteger(r) || r < 0) throw new A("budget", "队列并发应为正整数,排队上限应为非负整数");
134
+ const a = [], s = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
132
135
  let i = !1, l = 0;
133
136
  const f = () => {
134
- for (; !i && r.size < t && a.length; ) a.shift().start();
137
+ for (; !i && s.size < t && a.length; ) a.shift().start();
135
138
  };
136
139
  return {
137
140
  get active() {
138
- return r.size;
141
+ return s.size;
139
142
  },
140
143
  get pending() {
141
144
  return a.length;
142
145
  },
143
- enqueue: (u, c = {}) => {
146
+ enqueue: (d, c = {}) => {
144
147
  if (i) throw new A("closed", "任务队列已关闭");
145
- if (b(c.signal), r.size >= t && a.length >= s) throw new A("queue-full", "报表任务队列已满");
146
- const d = c.id ?? `report-${++l}`;
147
- if (n.has(d)) throw new A("queue-full", "任务 ID 正在执行或排队");
148
- const m = new AbortController();
149
- let y = "queued", g, p, h, S;
150
- const ne = new Promise((x, O) => {
151
- h = x, S = O;
152
- }), F = () => {
153
- c.signal?.removeEventListener("abort", _), n.delete(d);
154
- }, E = (x) => {
155
- if (y !== "queued" && y !== "running") return;
156
- const O = y === "queued";
157
- y = "cancelled", m.abort(x);
148
+ if (x(c.signal), s.size >= t && a.length >= r) throw new A("queue-full", "报表任务队列已满");
149
+ const u = c.id ?? `report-${++l}`;
150
+ if (n.has(u)) throw new A("queue-full", "任务 ID 正在执行或排队");
151
+ const y = new AbortController();
152
+ let h = "queued", w, g, p, v;
153
+ const j = new Promise((S, O) => {
154
+ p = S, v = O;
155
+ }), P = () => {
156
+ c.signal?.removeEventListener("abort", H), n.delete(u);
157
+ }, J = (S) => {
158
+ if (h !== "queued" && h !== "running") return;
159
+ const O = h === "queued";
160
+ h = "cancelled", y.abort(S);
158
161
  try {
159
- b(m.signal);
160
- } catch (J) {
161
- S(J);
162
+ x(y.signal);
163
+ } catch (D) {
164
+ v(D);
162
165
  }
163
166
  if (O) {
164
- const J = a.indexOf(k);
165
- J >= 0 && a.splice(J, 1), F(), f();
167
+ const D = a.indexOf(N);
168
+ D >= 0 && a.splice(D, 1), P(), f();
166
169
  }
167
- }, _ = () => E(c.signal?.reason), V = (x, O) => {
168
- y === "running" && (!Number.isFinite(x) || x < 0 || O !== void 0 && (!Number.isFinite(O) || O < x) || (g = { completed: x, ...O === void 0 ? {} : { total: O } }));
169
- }, ae = (x) => {
170
- y !== "running" || m.signal.aborted || (p = { ...x, taskId: d }, x.completed !== void 0 && V(x.completed, x.total), z(c.onEvent, p, m.signal));
171
- }, k = {
172
- cancel: E,
170
+ }, H = () => J(c.signal?.reason), Q = (S, O) => {
171
+ h === "running" && (!Number.isFinite(S) || S < 0 || O !== void 0 && (!Number.isFinite(O) || O < S) || (w = { completed: S, ...O === void 0 ? {} : { total: O } }));
172
+ }, ie = (S) => {
173
+ h !== "running" || y.signal.aborted || (g = { ...S, taskId: u }, S.completed !== void 0 && Q(S.completed, S.total), _(c.onEvent, g, y.signal));
174
+ }, N = {
175
+ cancel: J,
173
176
  start: () => {
174
- y === "queued" && (y = "running", r.add(k), Promise.resolve().then(() => (b(m.signal), u({ taskId: d, signal: m.signal, reportProgress: V, onEvent: ae }))).then(
175
- (x) => {
176
- y === "running" && (y = "completed", h(x));
177
+ h === "queued" && (h = "running", s.add(N), Promise.resolve().then(() => (x(y.signal), d({ taskId: u, signal: y.signal, reportProgress: Q, onEvent: ie }))).then(
178
+ (S) => {
179
+ h === "running" && (h = "completed", p(S));
177
180
  },
178
- (x) => {
179
- y === "running" && (y = "failed", S(x));
181
+ (S) => {
182
+ h === "running" && (h = "failed", v(S));
180
183
  }
181
184
  ).finally(() => {
182
- r.delete(k), F(), f();
185
+ s.delete(N), P(), f();
183
186
  }));
184
187
  }
185
188
  };
186
- return n.add(d), c.signal?.addEventListener("abort", _, { once: !0 }), c.signal?.aborted ? E(c.signal.reason) : r.size < t ? k.start() : a.push(k), { id: d, get status() {
187
- return y;
189
+ return n.add(u), c.signal?.addEventListener("abort", H, { once: !0 }), c.signal?.aborted ? J(c.signal.reason) : s.size < t ? N.start() : a.push(N), { id: u, get status() {
190
+ return h;
188
191
  }, get progress() {
189
- return g;
192
+ return w;
190
193
  }, get event() {
191
- return p;
192
- }, result: ne, cancel: E };
194
+ return g;
195
+ }, result: j, cancel: J };
193
196
  },
194
- close: (u = {}) => {
197
+ close: (d = {}) => {
195
198
  i = !0;
196
199
  for (const c of [...a]) c.cancel(new A("closed", "任务队列已关闭"));
197
- if (u.cancelRunning) for (const c of r) c.cancel(new A("closed", "任务队列已关闭"));
200
+ if (d.cancelRunning) for (const c of s) c.cancel(new A("closed", "任务队列已关闭"));
198
201
  }
199
202
  };
200
203
  }
201
- function Re(e) {
202
- let t, s;
203
- const a = new Promise((r, n) => {
204
- t = r, s = n;
204
+ function Ae(e) {
205
+ let t, r;
206
+ const a = new Promise((s, n) => {
207
+ t = s, r = n;
205
208
  });
206
209
  return a.catch(() => {
207
- }), { progress: e, promise: a, resolve: t, reject: s };
210
+ }), { progress: e, promise: a, resolve: t, reject: r };
208
211
  }
209
- function U(e) {
212
+ function W(e) {
210
213
  const t = Promise.reject(e);
211
214
  return t.catch(() => {
212
215
  }), t;
213
216
  }
214
- function Ie(e, t) {
215
- let s, a, r = !0, n;
217
+ function Pe(e, t) {
218
+ let r, a, s = !0, n;
216
219
  function i(o) {
217
220
  n ??= o ?? new Error("任务心跳更新失败"), a?.reject(n), a = void 0, t(n);
218
221
  }
219
222
  function l(o) {
220
- const u = Promise.resolve().then(() => e(o?.progress)).then(
223
+ const d = Promise.resolve().then(() => e(o?.progress)).then(
221
224
  () => o?.resolve(),
222
225
  (c) => {
223
226
  o?.reject(c), i(c);
224
227
  }
225
228
  ).finally(() => {
226
- s = void 0;
229
+ r = void 0;
227
230
  const c = a;
228
231
  a = void 0, c && n === void 0 && l(c);
229
232
  });
230
- s = u, u.catch((c) => {
233
+ r = d, d.catch((c) => {
231
234
  i(c);
232
235
  });
233
236
  }
234
237
  function f(o) {
235
- if (!r)
236
- return U(
237
- new v("closed", "任务进度上报已结束")
238
+ if (!s)
239
+ return W(
240
+ new b("closed", "任务进度上报已结束")
238
241
  );
239
- if (n !== void 0) return U(n);
240
- a ? a.progress = o : a = Re(o);
241
- const u = a;
242
- return s || (a = void 0, l(u)), u.promise;
242
+ if (n !== void 0) return W(n);
243
+ a ? a.progress = o : a = Ae(o);
244
+ const d = a;
245
+ return r || (a = void 0, l(d)), d.promise;
243
246
  }
244
247
  return {
245
248
  progress: f,
246
249
  pulse() {
247
- r && !s && n === void 0 && l();
250
+ s && !r && n === void 0 && l();
248
251
  },
249
252
  async finish() {
250
- for (r = !1; s; ) await s;
253
+ for (s = !1; r; ) await r;
251
254
  if (n !== void 0) throw n;
252
255
  }
253
256
  };
254
257
  }
255
- class W extends v {
258
+ class Z extends b {
256
259
  constructor() {
257
260
  super("capacity", "任务结果超过独立预算,请保存文件引用");
258
261
  }
259
262
  }
260
- function Oe(e) {
261
- const t = e.concurrency ?? 1, s = e.leaseMs ?? 3e4, a = e.heartbeatMs ?? 1e4, r = e.maxResultBytes ?? 256 * 1024;
262
- if (![t, s, a, r].every(
263
+ function ke(e) {
264
+ const t = e.concurrency ?? 1, r = e.leaseMs ?? 3e4, a = e.heartbeatMs ?? 1e4, s = e.maxResultBytes ?? 256 * 1024;
265
+ if (![t, r, a, s].every(
263
266
  (i) => Number.isSafeInteger(i) && i > 0
264
- ) || a * 2 > s)
265
- throw new v(
267
+ ) || a * 2 > r)
268
+ throw new b(
266
269
  "input",
267
270
  "并发、租约、心跳应为正整数,租约至少为心跳的两倍"
268
271
  );
269
272
  if (a > 2147483647)
270
- throw new v(
273
+ throw new b(
271
274
  "input",
272
275
  "心跳间隔超过平台定时器上限(2147483647毫秒)"
273
276
  );
274
- return { concurrency: t, leaseMs: s, heartbeatMs: a, maxResultBytes: r, now: () => {
277
+ return { concurrency: t, leaseMs: r, heartbeatMs: a, maxResultBytes: s, now: () => {
275
278
  const i = (e.now ?? Date.now)();
276
279
  if (!Number.isSafeInteger(i) || i < 0)
277
- throw new v("input", "任务时钟应返回非负整数毫秒");
280
+ throw new b("input", "任务时钟应返回非负整数毫秒");
278
281
  return i;
279
282
  } };
280
283
  }
281
- async function B(e, t, s) {
282
- $(t, s);
283
- const a = await e.read(t, s);
284
- if (!a) throw new v("missing", "报表任务不存在");
284
+ async function M(e, t, r) {
285
+ L(t, r);
286
+ const a = await e.read(t, r);
287
+ if (!a) throw new b("missing", "报表任务不存在");
285
288
  return a;
286
289
  }
287
- async function j(e, t, s, a = []) {
288
- const r = { ...t, ...s, revision: t.revision + 1 };
289
- for (const n of a) delete r[n];
290
+ async function B(e, t, r, a = []) {
291
+ const s = { ...t, ...r, revision: t.revision + 1 };
292
+ for (const n of a) delete s[n];
290
293
  if (!await e.compareAndSwap(
291
294
  t.scope,
292
295
  t.id,
293
296
  t.revision,
294
- r
297
+ s
295
298
  ))
296
- throw new v("conflict", "报表任务已被其他请求更新");
297
- return D(r);
299
+ throw new b("conflict", "报表任务已被其他请求更新");
300
+ return T(s);
298
301
  }
299
- async function Ae(e, t, s, a) {
302
+ async function je(e, t, r, a) {
300
303
  if (!t.trim() || t.length > 128)
301
- throw new v("input", "workerId应为1–128位标识");
302
- for (const r of await e.store.candidates(a, 100)) {
303
- const n = r.cancelRequested ? {
304
- ...r,
305
- revision: r.revision + 1,
304
+ throw new b("input", "workerId应为1–128位标识");
305
+ for (const s of await e.store.candidates(a, 100)) {
306
+ const n = s.cancelRequested ? {
307
+ ...s,
308
+ revision: s.revision + 1,
306
309
  status: "cancelled",
307
310
  updatedAt: a
308
311
  } : {
309
- ...r,
310
- revision: r.revision + 1,
312
+ ...s,
313
+ revision: s.revision + 1,
311
314
  status: "running",
312
- attempt: r.attempt + 1,
315
+ attempt: s.attempt + 1,
313
316
  updatedAt: a,
314
- lease: { owner: t, expiresAt: a + s }
317
+ lease: { owner: t, expiresAt: a + r }
315
318
  };
316
319
  if (n.status === "cancelled" && delete n.lease, await e.store.compareAndSwap(
317
- r.scope,
318
- r.id,
319
- r.revision,
320
+ s.scope,
321
+ s.id,
322
+ s.revision,
320
323
  n
321
324
  ))
322
325
  return n;
323
326
  }
324
327
  }
325
- function Z(e, t, s, a) {
326
- return e.status === "running" && e.attempt === a && e.lease?.owner === t && e.lease.expiresAt > s;
328
+ function K(e, t, r, a) {
329
+ return e.status === "running" && e.attempt === a && e.lease?.owner === t && e.lease.expiresAt > r;
327
330
  }
328
- async function Pe(e, t, s, a) {
329
- const { scope: r, id: n } = s, i = s.lease.owner;
331
+ async function Ne(e, t, r, a) {
332
+ const { scope: s, id: n } = r, i = r.lease.owner;
330
333
  let l;
331
- const f = Ie(
332
- async (p) => {
333
- const h = await B(e.store, r, n), S = t.now();
334
- if (!Z(h, i, S, s.attempt))
335
- throw new v("lease", "报表任务租约已失效");
336
- if (h.cancelRequested) {
337
- a.abort(new v("closed", "任务已请求取消"));
334
+ const f = Pe(
335
+ async (g) => {
336
+ const p = await M(e.store, s, n), v = t.now();
337
+ if (!K(p, i, v, r.attempt))
338
+ throw new b("lease", "报表任务租约已失效");
339
+ if (p.cancelRequested) {
340
+ a.abort(new b("closed", "任务已请求取消"));
338
341
  return;
339
342
  }
340
- await j(e.store, h, {
341
- updatedAt: S,
342
- lease: { owner: i, expiresAt: S + t.leaseMs },
343
- ...p ? { progress: p } : {}
343
+ await B(e.store, p, {
344
+ updatedAt: v,
345
+ lease: { owner: i, expiresAt: v + t.leaseMs },
346
+ ...g ? { progress: g } : {}
344
347
  });
345
348
  },
346
- (p) => {
347
- l = p, a.abort(p);
349
+ (g) => {
350
+ l = g, a.abort(g);
348
351
  }
349
- ), o = (p, h) => !Number.isFinite(p) || p < 0 || h !== void 0 && (!Number.isFinite(h) || h < p) ? Promise.reject(new v("input", "任务进度无效")) : f.progress({
350
- completed: p,
351
- ...h === void 0 ? {} : { total: h }
352
- }), u = setInterval(() => {
352
+ ), o = (g, p) => !Number.isFinite(g) || g < 0 || p !== void 0 && (!Number.isFinite(p) || p < g) ? Promise.reject(new b("input", "任务进度无效")) : f.progress({
353
+ completed: g,
354
+ ...p === void 0 ? {} : { total: p }
355
+ }), d = setInterval(() => {
353
356
  f.pulse();
354
357
  }, t.heartbeatMs);
355
- let c, d;
358
+ let c, u;
356
359
  try {
357
- const p = Object.prototype.hasOwnProperty.call(
360
+ const g = Object.prototype.hasOwnProperty.call(
358
361
  e.handlers,
359
- s.request.kind
360
- ) ? e.handlers[s.request.kind] : void 0;
361
- if (!p) throw new v("input", "报表任务处理器未注册");
362
+ r.request.kind
363
+ ) ? e.handlers[r.request.kind] : void 0;
364
+ if (!g) throw new b("input", "报表任务处理器未注册");
362
365
  if (!a.signal.aborted) {
363
- const h = await p(D(s.request.payload), {
364
- scope: r,
366
+ const p = await g(T(r.request.payload), {
367
+ scope: s,
365
368
  taskId: n,
366
369
  signal: a.signal,
367
370
  reportProgress: o
368
371
  });
369
- if (c = JSON.parse(I(h)), we(c) > t.maxResultBytes) throw new W();
372
+ if (c = JSON.parse(I(p)), ye(c) > t.maxResultBytes) throw new Z();
370
373
  }
371
- } catch (p) {
372
- d = p ?? new Error("报表任务执行失败");
374
+ } catch (g) {
375
+ u = g ?? new Error("报表任务执行失败");
373
376
  } finally {
374
- clearInterval(u), await f.finish().catch(() => {
377
+ clearInterval(d), await f.finish().catch(() => {
375
378
  });
376
379
  }
377
- const m = await B(e.store, r, n), y = t.now();
378
- if (!Z(m, i, y, s.attempt))
379
- throw new v("lease", "任务租约已失效,迟到结果不会写回");
380
- const g = { ...m, updatedAt: y };
381
- delete g.lease, d ??= l, m.cancelRequested || a.signal.aborted && l === void 0 ? g.status = "cancelled" : d !== void 0 ? (g.status = "failed", g.error = {
382
- code: d instanceof W ? "result-budget" : d instanceof v ? d.code : "execution",
383
- message: d instanceof Error ? d.message.slice(0, 500) : "报表任务执行失败"
384
- }) : (g.status = "completed", g.result = c);
380
+ const y = await M(e.store, s, n), h = t.now();
381
+ if (!K(y, i, h, r.attempt))
382
+ throw new b("lease", "任务租约已失效,迟到结果不会写回");
383
+ const w = { ...y, updatedAt: h };
384
+ delete w.lease, u ??= l, y.cancelRequested || a.signal.aborted && l === void 0 ? w.status = "cancelled" : u !== void 0 ? (w.status = "failed", w.error = {
385
+ code: u instanceof Z ? "result-budget" : u instanceof b ? u.code : "execution",
386
+ message: u instanceof Error ? u.message.slice(0, 500) : "报表任务执行失败"
387
+ }) : (w.status = "completed", w.result = c);
385
388
  try {
386
- I(g);
389
+ I(w);
387
390
  } catch {
388
- delete g.result, g.status = "failed", g.error = {
391
+ delete w.result, w.status = "failed", w.error = {
389
392
  code: "result-budget",
390
393
  message: "任务结果与请求的组合超过存储预算,请保存文件引用而非文件内容"
391
394
  };
392
395
  }
393
- return ke(e.store, m, g);
396
+ return Ee(e.store, y, w);
394
397
  }
395
- async function ke(e, t, s) {
398
+ async function Ee(e, t, r) {
396
399
  try {
397
- return await j(e, t, s, ["lease"]);
400
+ return await B(e, t, r, ["lease"]);
398
401
  } catch (a) {
399
- if (!(a instanceof v) || a.code !== "capacity" || s.status !== "completed") throw a;
400
- return delete s.result, s.status = "failed", s.error = { code: "result-budget", message: "任务结果超过存储剩余预算,请保存文件引用而非文件内容" }, j(e, t, s, ["lease", "result"]);
402
+ if (!(a instanceof b) || a.code !== "capacity" || r.status !== "completed") throw a;
403
+ return delete r.result, r.status = "failed", r.error = { code: "result-budget", message: "任务结果超过存储剩余预算,请保存文件引用而非文件内容" }, B(e, t, r, ["lease", "result"]);
401
404
  }
402
405
  }
403
- async function K(e, t, s, a) {
404
- const r = await e.readTombstone?.(t, s);
405
- if (r) {
406
- if (r.requestHash !== await me(a)) throw new v("conflict", "相同任务ID不能提交不同内容(幂等保留期内)");
407
- return { scope: t, id: s, revision: r.revision, request: D(a), status: r.status, createdAt: r.createdAt, updatedAt: r.updatedAt, attempt: r.attempt, archived: !0 };
406
+ async function Y(e, t, r, a) {
407
+ const s = await e.readTombstone?.(t, r);
408
+ if (s) {
409
+ if (s.requestHash !== await he(a)) throw new b("conflict", "相同任务ID不能提交不同内容(幂等保留期内)");
410
+ return { scope: t, id: r, revision: s.revision, request: T(a), status: s.status, createdAt: s.createdAt, updatedAt: s.updatedAt, attempt: s.attempt, archived: !0 };
408
411
  }
409
412
  }
410
- function Xe(e) {
413
+ function Ke(e) {
411
414
  e = { ...e, handlers: { ...e.handlers } };
412
- const t = Oe(e), s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
413
- let r = !1, n = 0;
414
- const i = (o, u) => ($(o, u), e.store.read(o, u));
415
+ const t = ke(e), r = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
416
+ let s = !1, n = 0;
417
+ const i = (o, d) => (L(o, d), e.store.read(o, d));
415
418
  return {
416
419
  submit: async (o) => {
417
- if (o = { ...o }, $(o.scope, o.id), !Object.prototype.hasOwnProperty.call(e.handlers, o.kind) || typeof e.handlers[o.kind] != "function")
418
- throw new v("input", "报表任务处理器未注册");
419
- const u = {
420
+ if (o = { ...o }, L(o.scope, o.id), !Object.prototype.hasOwnProperty.call(e.handlers, o.kind) || typeof e.handlers[o.kind] != "function")
421
+ throw new b("input", "报表任务处理器未注册");
422
+ const d = {
420
423
  kind: o.kind,
421
424
  payload: JSON.parse(
422
425
  I(o.payload, {
@@ -426,54 +429,54 @@ function Xe(e) {
426
429
  )
427
430
  }, c = await i(o.scope, o.id);
428
431
  if (c) {
429
- if (I(c.request) !== I(u))
430
- throw new v("conflict", "相同任务ID不能提交不同内容");
432
+ if (I(c.request) !== I(d))
433
+ throw new b("conflict", "相同任务ID不能提交不同内容");
431
434
  return c;
432
435
  }
433
- const d = await K(e.store, o.scope, o.id, u);
434
- if (d) return d;
435
- const m = t.now(), y = {
436
+ const u = await Y(e.store, o.scope, o.id, d);
437
+ if (u) return u;
438
+ const y = t.now(), h = {
436
439
  scope: o.scope,
437
440
  id: o.id,
438
441
  revision: 1,
439
- request: u,
442
+ request: d,
440
443
  status: "queued",
441
- createdAt: m,
442
- updatedAt: m,
444
+ createdAt: y,
445
+ updatedAt: y,
443
446
  attempt: 0
444
447
  };
445
- if (!await e.store.compareAndSwap(o.scope, o.id, null, y)) {
446
- const g = await i(o.scope, o.id);
447
- if (g && I(g.request) === I(u))
448
- return g;
449
- const p = await K(e.store, o.scope, o.id, u);
450
- if (p) return p;
451
- throw new v("conflict", "报表任务提交发生冲突");
448
+ if (!await e.store.compareAndSwap(o.scope, o.id, null, h)) {
449
+ const w = await i(o.scope, o.id);
450
+ if (w && I(w.request) === I(d))
451
+ return w;
452
+ const g = await Y(e.store, o.scope, o.id, d);
453
+ if (g) return g;
454
+ throw new b("conflict", "报表任务提交发生冲突");
452
455
  }
453
- return D(y);
456
+ return T(h);
454
457
  },
455
458
  get: i,
456
459
  runNext: (o) => {
457
- if (r)
458
- return Promise.reject(new v("closed", "报表任务服务已关闭"));
460
+ if (s)
461
+ return Promise.reject(new b("closed", "报表任务服务已关闭"));
459
462
  if (n >= t.concurrency)
460
463
  return Promise.reject(
461
- new v("capacity", "报表任务执行槽位已满")
464
+ new b("capacity", "报表任务执行槽位已满")
462
465
  );
463
466
  n++;
464
- const u = new AbortController();
465
- s.add(u);
467
+ const d = new AbortController();
468
+ r.add(d);
466
469
  const c = (async () => {
467
470
  try {
468
- const d = await Ae(
471
+ const u = await je(
469
472
  e,
470
473
  o,
471
474
  t.leaseMs,
472
475
  t.now()
473
476
  );
474
- return d?.status === "running" ? await Pe(e, t, d, u) : d;
477
+ return u?.status === "running" ? await Ne(e, t, u, d) : u;
475
478
  } finally {
476
- n--, s.delete(u);
479
+ n--, r.delete(d);
477
480
  }
478
481
  })();
479
482
  return a.add(c), c.then(
@@ -484,38 +487,56 @@ function Xe(e) {
484
487
  get active() {
485
488
  return n;
486
489
  },
487
- cancel: async (o, u) => {
488
- const c = await B(e.store, o, u);
489
- return c.status !== "queued" && c.status !== "running" ? c : j(e.store, c, {
490
+ cancel: async (o, d) => {
491
+ const c = await M(e.store, o, d);
492
+ return c.status !== "queued" && c.status !== "running" ? c : B(e.store, c, {
490
493
  updatedAt: t.now(),
491
494
  ...c.status === "queued" ? { status: "cancelled" } : { cancelRequested: !0 }
492
495
  });
493
496
  },
494
- retry: async (o, u, c) => {
495
- const d = await B(e.store, o, u);
496
- if (d.revision !== c || d.status !== "failed")
497
- throw new v("conflict", "仅可重试当前修订的失败任务");
498
- const m = {
499
- ...d,
497
+ retry: async (o, d, c) => {
498
+ const u = await M(e.store, o, d);
499
+ if (u.revision !== c || u.status !== "failed")
500
+ throw new b("conflict", "仅可重试当前修订的失败任务");
501
+ const y = {
502
+ ...u,
500
503
  status: "queued",
501
504
  updatedAt: t.now()
502
505
  };
503
- return delete m.error, delete m.progress, j(e.store, d, m, ["error", "progress"]);
506
+ return delete y.error, delete y.progress, B(e.store, u, y, ["error", "progress"]);
504
507
  },
505
508
  prune: async (o) => {
506
- if (!e.store.prune || !e.store.readTombstone) throw new v("input", "当前任务适配器未实现可选终态保留能力");
509
+ if (!e.store.prune || !e.store.readTombstone) throw new b("input", "当前任务适配器未实现可选终态保留能力");
507
510
  return e.store.prune({ ...o, now: t.now() });
508
511
  },
509
512
  close: async () => {
510
- r = !0;
511
- for (const o of s)
512
- o.abort(new v("closed", "任务服务正在关闭"));
513
+ s = !0;
514
+ for (const o of r)
515
+ o.abort(new b("closed", "任务服务正在关闭"));
513
516
  await Promise.allSettled([...a]);
514
517
  }
515
518
  };
516
519
  }
517
- async function Ne(e, t, s, a, r) {
518
- const n = Se({ reports: { sample: { template: s, datasets: e.datasets } }, budget: {
520
+ function ae(e, t) {
521
+ const r = e.assets, a = e[t];
522
+ if (!(!r && !a?.assetRenderers))
523
+ return {
524
+ ...r,
525
+ ...a?.assetFailure === void 0 ? {} : { assetFailure: a.assetFailure },
526
+ ...a?.onDiagnostic === void 0 ? {} : { onDiagnostic: a.onDiagnostic },
527
+ assetRenderers: { ...r?.assetRenderers, ...a?.assetRenderers },
528
+ assetBudget: { ...r?.assetBudget, ...a?.assetBudget }
529
+ };
530
+ }
531
+ function ee(e, t) {
532
+ return !e || e.code !== "missing-image" || e.format !== "pdf" && e.format !== "xlsx" ? !1 : typeof ae(t, e.format)?.assetRenderers?.[e.kind] == "function";
533
+ }
534
+ function Be(e, t) {
535
+ const r = ge(e, t), a = r.issues.filter((n) => !ee(n.diagnostic, t)), s = r.samples.map((n) => ({ ...n, diagnostics: n.diagnostics.filter((i) => !ee(i, t)) }));
536
+ return { ...r, issues: a, samples: s, ok: a.every((n) => n.severity !== "error"), artifacts: [] };
537
+ }
538
+ async function Je(e, t, r, a, s) {
539
+ const n = Oe({ reports: { sample: { template: r, datasets: e.datasets } }, assets: ae(a, t), budget: {
519
540
  maxRows: a.maxSampleRows ?? 1e3,
520
541
  maxPages: a.maxPages ?? 100,
521
542
  maxCells: a.maxCells ?? 25e4,
@@ -523,225 +544,227 @@ async function Ne(e, t, s, a, r) {
523
544
  maxDurationMs: a.maxDurationMs ?? 3e4
524
545
  } });
525
546
  try {
526
- const { result: i, digest: l } = await q(a.signal, a.maxDurationMs ?? 3e4, async (f) => {
527
- const o = await n.export({ reportIds: ["sample"], params: e.params, format: t, signal: f, fidelity: a.strictOutputs ? "strict" : "warn", pdf: a.pdf, xlsx: a.xlsx }), u = await a.digest?.(o.bytes);
528
- return b(f), await a.onArtifact?.(e.name, o), b(f), { result: o, digest: u };
547
+ const { result: i, digest: l } = await z(a.signal, a.maxDurationMs ?? 3e4, async (f) => {
548
+ const o = await n.export({ reportIds: ["sample"], params: e.params, format: t, signal: f, fidelity: a.strictOutputs ? "strict" : "warn", pdf: a.pdf, xlsx: a.xlsx }), d = o.diagnostics.filter((u) => u.severity !== "info");
549
+ if (a.strictOutputs && d.length) throw new Error(`Strict ${t} encoding found fidelity issues: ${d.slice(0, 3).map((u) => u.message).join("; ")}`);
550
+ const c = await a.digest?.(o.bytes);
551
+ return x(f), await a.onArtifact?.(e.name, o), x(f), { result: o, digest: c };
529
552
  });
530
- r.artifacts.push({ fixture: e.name, format: t, bytes: i.bytes.byteLength, pages: i.stats.pages, ...l ? { digest: l } : {} }), r.issues.push(...i.diagnostics.map((f) => ({ code: "output", severity: a.strictOutputs || f.severity === "error" ? "error" : "warning", path: "$.template", fixture: e.name, message: `${t}: ${f.message}` })));
553
+ s.artifacts.push({ fixture: e.name, format: t, bytes: i.bytes.byteLength, pages: i.stats.pages, ...l ? { digest: l } : {} }), s.issues.push(...i.diagnostics.map((f) => ({ code: "output", severity: a.strictOutputs || f.severity === "error" ? "error" : "warning", path: "$.template", fixture: e.name, message: `${t}: ${f.message}` })));
531
554
  } catch (i) {
532
- b(a.signal), r.issues.push({ code: "output", severity: "error", path: "$.template", fixture: e.name, message: `${t}: ${i instanceof Error ? i.message : String(i)}` });
555
+ x(a.signal), s.issues.push({ code: "output", severity: "error", path: "$.template", fixture: e.name, message: `${t}: ${i instanceof Error ? i.message : String(i)}` });
533
556
  }
534
557
  }
535
- async function Ge(e, t = {}) {
536
- b(t.signal);
537
- const s = { ...fe(e, t), artifacts: [] };
538
- if (!s.ok) return s;
539
- const a = he(e).template, r = [...new Set(t.formats ?? ["pdf", "xlsx"])];
540
- if (!r.length || r.some((n) => n !== "pdf" && n !== "xlsx"))
541
- return s.issues.push({ code: "output", severity: "error", path: "$.formats", message: "真实文件验收应至少选择PDF/XLSX之一" }), s.ok = !1, s;
558
+ async function Ye(e, t = {}) {
559
+ x(t.signal);
560
+ const r = Be(e, t);
561
+ if (!r.ok) return r;
562
+ const a = xe(e).template, s = [...new Set(t.formats ?? ["pdf", "xlsx"])];
563
+ if (!s.length || s.some((n) => n !== "pdf" && n !== "xlsx"))
564
+ return r.issues.push({ code: "output", severity: "error", path: "$.formats", message: "真实文件验收应至少选择PDF/XLSX之一" }), r.ok = !1, r;
542
565
  for (const n of t.fixtures ?? [])
543
- for (const i of r)
544
- b(t.signal), !(i !== "pdf" && i !== "xlsx") && await Ne(n, i, a, t, s);
545
- return s.ok = s.issues.every((n) => n.severity !== "error"), s;
566
+ for (const i of s)
567
+ x(t.signal), !(i !== "pdf" && i !== "xlsx") && await Je(n, i, a, t, r);
568
+ return r.ok = r.issues.every((n) => n.severity !== "error"), r;
546
569
  }
547
- class w extends Error {
548
- constructor(t, s) {
549
- super(s), this.code = t, this.name = "ReportInstanceError";
570
+ class m extends Error {
571
+ constructor(t, r) {
572
+ super(r), this.code = t, this.name = "ReportInstanceError";
550
573
  }
551
574
  }
552
- function N(e, t) {
553
- 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 w("input", "实例范围应非空,ID 应为安全标识");
575
+ function E(e, t) {
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 m("input", "实例范围应非空,ID 应为安全标识");
554
577
  }
555
- function je(e, t) {
556
- const s = Object.getPrototypeOf(e);
557
- if (s !== (t ? Array.prototype : Object.prototype) && !(s === null && !t) || Object.getOwnPropertySymbols(e).length) throw new w("input", "实例应为普通 JSON 对象");
558
- if (t && Object.keys(e).some((r) => r !== String(Number(r)) || !Number.isSafeInteger(Number(r)) || Number(r) < 0 || Number(r) >= e.length)) throw new w("input", "实例数组不能包含额外属性");
559
- if (Object.getOwnPropertyNames(e).filter((r) => !(t && r === "length")).length !== Object.keys(e).length) throw new w("input", "实例不能包含不可枚举属性");
578
+ function De(e, t) {
579
+ const r = Object.getPrototypeOf(e);
580
+ if (r !== (t ? Array.prototype : Object.prototype) && !(r === null && !t) || Object.getOwnPropertySymbols(e).length) throw new m("input", "实例应为普通 JSON 对象");
581
+ if (t && Object.keys(e).some((s) => s !== String(Number(s)) || !Number.isSafeInteger(Number(s)) || Number(s) < 0 || Number(s) >= e.length)) throw new m("input", "实例数组不能包含额外属性");
582
+ if (Object.getOwnPropertyNames(e).filter((s) => !(t && s === "length")).length !== Object.keys(e).length) throw new m("input", "实例不能包含不可枚举属性");
560
583
  }
561
- function Ee(e) {
562
- if (!Number.isSafeInteger(e.revision) || e.revision < 1 || typeof e.title != "string" || !e.title.trim() || e.title.length > 512) throw new w("input", "实例修订或标题无效");
563
- if (typeof e.generatedAt != "string" || !Number.isFinite(Date.parse(e.generatedAt)) || new Date(e.generatedAt).toISOString() !== e.generatedAt) throw new w("input", "实例生成时间应为 ISO UTC 字符串");
564
- 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 w("input", "实例报表 ID 应非空且唯一");
584
+ function Ce(e) {
585
+ if (!Number.isSafeInteger(e.revision) || e.revision < 1 || typeof e.title != "string" || !e.title.trim() || e.title.length > 512) throw new m("input", "实例修订或标题无效");
586
+ if (typeof e.generatedAt != "string" || !Number.isFinite(Date.parse(e.generatedAt)) || new Date(e.generatedAt).toISOString() !== e.generatedAt) throw new m("input", "实例生成时间应为 ISO UTC 字符串");
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 m("input", "实例报表 ID 应非空且唯一");
565
588
  }
566
- function Je(e) {
589
+ function Me(e) {
567
590
  return e === null || typeof e == "boolean" || typeof e == "string" || typeof e == "number" && Number.isFinite(e);
568
591
  }
569
- function se(e, t) {
570
- if (!Number.isSafeInteger(t) || t < 1) throw new w("input", "实例快照字节预算应为正安全整数");
571
- let s = 0, a = 0;
572
- const r = /* @__PURE__ */ new Set();
592
+ function oe(e, t) {
593
+ if (!Number.isSafeInteger(t) || t < 1) throw new m("input", "实例快照字节预算应为正安全整数");
594
+ let r = 0, a = 0;
595
+ const s = /* @__PURE__ */ new Set();
573
596
  function n(l, f) {
574
- if (++s > 1e6 || f > 64) throw new w("capacity", "实例节点或嵌套深度超过预算");
597
+ if (++r > 1e6 || f > 64) throw new m("capacity", "实例节点或嵌套深度超过预算");
575
598
  if (typeof l == "string" && (a += l.length, a > t))
576
- throw new w("capacity", "实例文本超过预算");
577
- if (Je(l)) return l;
578
- if (!l || typeof l != "object" || r.has(l)) throw new w("input", "实例只允许无循环的有限 JSON 值");
599
+ throw new m("capacity", "实例文本超过预算");
600
+ if (Me(l)) return l;
601
+ if (!l || typeof l != "object" || s.has(l)) throw new m("input", "实例只允许无循环的有限 JSON 值");
579
602
  const o = Array.isArray(l);
580
- je(l, o), r.add(l);
581
- const u = /* @__PURE__ */ Object.create(null);
603
+ De(l, o), s.add(l);
604
+ const d = /* @__PURE__ */ Object.create(null);
582
605
  for (const c of Object.keys(l)) {
583
- if (a += c.length, a > t) throw new w("capacity", "实例文本超过预算");
584
- const d = Object.getOwnPropertyDescriptor(l, c);
585
- if (d.get || d.set || ["__proto__", "constructor", "prototype"].includes(c)) throw new w("input", "实例不能包含访问器或危险键");
586
- d.value !== void 0 && (u[c] = n(d.value, f + 1));
606
+ if (a += c.length, a > t) throw new m("capacity", "实例文本超过预算");
607
+ const u = Object.getOwnPropertyDescriptor(l, c);
608
+ if (u.get || u.set || ["__proto__", "constructor", "prototype"].includes(c)) throw new m("input", "实例不能包含访问器或危险键");
609
+ u.value !== void 0 && (d[c] = n(u.value, f + 1));
587
610
  }
588
- if (r.delete(l), o) {
589
- if (Object.keys(u).length !== l.length) throw new w("input", "实例数组不能稀疏或包含额外属性");
590
- return Array.from({ length: l.length }, (c, d) => u[String(d)]);
611
+ if (s.delete(l), o) {
612
+ if (Object.keys(d).length !== l.length) throw new m("input", "实例数组不能稀疏或包含额外属性");
613
+ return Array.from({ length: l.length }, (c, u) => d[String(u)]);
591
614
  }
592
- return u;
615
+ return d;
593
616
  }
594
617
  const i = JSON.stringify(n(e, 0));
595
- if (new TextEncoder().encode(i).byteLength > t) throw new w("capacity", "实例快照超过单条字节预算");
618
+ if (new TextEncoder().encode(i).byteLength > t) throw new m("capacity", "实例快照超过单条字节预算");
596
619
  return i;
597
620
  }
598
- function L(e, t = 8e6) {
599
- const s = JSON.parse(se(e, t));
600
- N(s.scope, s.id);
621
+ function V(e, t = 8e6) {
622
+ const r = JSON.parse(oe(e, t));
623
+ E(r.scope, r.id);
601
624
  const a = /* @__PURE__ */ new Set(["scope", "id", "revision", "title", "generatedAt", "reportIds", "params", "templateRevisions", "sourceRevisions", "plan", "artifacts"]);
602
- if (Object.keys(s).some((n) => !a.has(n))) throw new w("input", "实例包含未知字段");
603
- Ee(s);
604
- for (const n of [s.params, s.templateRevisions, s.sourceRevisions])
605
- if (!n || typeof n != "object" || Array.isArray(n) || Object.values(n).some((i) => typeof i != "string")) throw new w("input", "实例参数和修订应为字符串字典");
606
- if (s.reportIds.some((n) => !s.templateRevisions[n])) throw new w("input", "每张报表都应记录生成时的模板修订");
607
- const r = ee(s.plan);
608
- if (!r.ok) throw new w("input", `实例渲染计划无效:${r.errors[0]?.path}`);
609
- return s.artifacts !== void 0 && Be(s.artifacts), s;
610
- }
611
- function Be(e) {
612
- if (!Array.isArray(e) || e.length > 100) throw new w("input", "实例文件列表无效");
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", "实例文件列表无效");
613
636
  const t = /* @__PURE__ */ new Set();
614
- for (const s of e) {
615
- if (!s || typeof s.key != "string" || !s.key.trim() || s.key.length > 1024 || t.has(s.key) || !["pdf", "xlsx"].includes(s.format) || !Number.isSafeInteger(s.bytes) || s.bytes < 0 || s.sha256 !== void 0 && (typeof s.sha256 != "string" || s.sha256.length !== 64 || !/^[a-f0-9]{64}$/i.test(s.sha256))) throw new w("input", "实例文件应包含唯一存储键、格式、大小和可选 SHA256");
616
- t.add(s.key);
637
+ 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 m("input", "实例文件应包含唯一存储键、格式、大小和可选 SHA256");
639
+ t.add(r.key);
617
640
  }
618
641
  }
619
- function De(e) {
620
- const { scope: t, id: s, revision: a, title: r, generatedAt: n, reportIds: i, params: l, templateRevisions: f, sourceRevisions: o } = e;
621
- return JSON.parse(JSON.stringify({ scope: t, id: s, revision: a, title: r, generatedAt: n, reportIds: i, params: l, templateRevisions: f, sourceRevisions: o }));
642
+ function $e(e) {
643
+ const { scope: t, id: r, revision: a, title: s, generatedAt: n, reportIds: i, params: l, templateRevisions: f, sourceRevisions: o } = e;
644
+ return JSON.parse(JSON.stringify({ scope: t, id: r, revision: a, title: s, generatedAt: n, reportIds: i, params: l, templateRevisions: f, sourceRevisions: o }));
622
645
  }
623
- function Ce(e) {
646
+ function qe(e) {
624
647
  const t = { maxInstances: 100, maxRevisions: 20, maxBytes: 64e6, maxSnapshotBytes: 8e6, ...e };
625
- if (Object.values(t).some((s) => !Number.isSafeInteger(s) || s < 1)) throw new w("input", "实例存储预算应为正安全整数");
648
+ if (Object.values(t).some((r) => !Number.isSafeInteger(r) || r < 1)) throw new m("input", "实例存储预算应为正安全整数");
626
649
  return t;
627
650
  }
628
- function Ue(e = {}) {
629
- const t = Ce(e), s = /* @__PURE__ */ new Map();
651
+ function et(e = {}) {
652
+ const t = qe(e), r = /* @__PURE__ */ new Map();
630
653
  let a = 0;
631
654
  return {
632
- read: async (r, n, i, l) => {
633
- b(l), N(r, n);
634
- const f = s.get(JSON.stringify([r, n])), o = f?.get(i ?? f.size);
635
- return o ? L(o, t.maxSnapshotBytes) : void 0;
655
+ read: async (s, n, i, l) => {
656
+ x(l), E(s, n);
657
+ const f = r.get(JSON.stringify([s, n])), o = f?.get(i ?? f.size);
658
+ return o ? V(o, t.maxSnapshotBytes) : void 0;
636
659
  },
637
- list: async (r, n = {}) => {
638
- b(n.signal), N(r, "list");
660
+ list: async (s, n = {}) => {
661
+ x(n.signal), E(s, "list");
639
662
  const i = n.limit ?? 25;
640
- if (!Number.isSafeInteger(i) || i < 1 || i > 100) throw new w("input", "实例每页数量应为 1–100");
641
- const l = Array.from(s.values(), (f) => f.get(f.size)).filter((f) => f.scope === r && (!n.after || f.id > n.after) && (!n.reportId || f.reportIds.includes(n.reportId))).sort((f, o) => f.id < o.id ? -1 : 1).slice(0, i + 1);
642
- return { items: l.slice(0, i).map(De), ...l.length > i ? { next: l[i - 1].id } : {} };
663
+ if (!Number.isSafeInteger(i) || i < 1 || i > 100) throw new m("input", "实例每页数量应为 1–100");
664
+ const l = Array.from(r.values(), (f) => f.get(f.size)).filter((f) => f.scope === s && (!n.after || f.id > n.after) && (!n.reportId || f.reportIds.includes(n.reportId))).sort((f, o) => f.id < o.id ? -1 : 1).slice(0, i + 1);
665
+ return { items: l.slice(0, i).map($e), ...l.length > i ? { next: l[i - 1].id } : {} };
643
666
  },
644
- compareAndSwap: async (r, n, i, l, f) => {
645
- b(f), N(r, n);
646
- const o = L(l, t.maxSnapshotBytes);
647
- if (o.scope !== r || o.id !== n || o.revision !== (i ?? 0) + 1) throw new w("input", "实例身份或修订不一致");
648
- const u = JSON.stringify([r, n]), c = s.get(u) ?? /* @__PURE__ */ new Map();
667
+ compareAndSwap: async (s, n, i, l, f) => {
668
+ x(f), E(s, n);
669
+ const o = V(l, t.maxSnapshotBytes);
670
+ if (o.scope !== s || o.id !== n || o.revision !== (i ?? 0) + 1) throw new m("input", "实例身份或修订不一致");
671
+ const d = JSON.stringify([s, n]), c = r.get(d) ?? /* @__PURE__ */ new Map();
649
672
  if ((c.size || null) !== i) return !1;
650
- const d = new TextEncoder().encode(JSON.stringify(o)).byteLength;
651
- if (c.size >= t.maxRevisions || a + d > t.maxBytes || !c.size && s.size >= t.maxInstances) throw new w("capacity", "实例存储达到预算,请使用持久化归档策略或显式调整容量");
652
- return c.set(o.revision, o), s.set(u, c), a += d, !0;
673
+ const u = new TextEncoder().encode(JSON.stringify(o)).byteLength;
674
+ if (c.size >= t.maxRevisions || a + u > t.maxBytes || !c.size && r.size >= t.maxInstances) throw new m("capacity", "实例存储达到预算,请使用持久化归档策略或显式调整容量");
675
+ return c.set(o.revision, o), r.set(d, c), a += u, !0;
653
676
  }
654
677
  };
655
678
  }
656
- function Me(e, t = {}) {
657
- const s = t.maxSnapshotBytes ?? 8e6;
658
- if (!Number.isSafeInteger(s) || s < 1) throw new w("input", "实例快照字节预算应为正安全整数");
679
+ function Fe(e, t = {}) {
680
+ const r = t.maxSnapshotBytes ?? 8e6;
681
+ if (!Number.isSafeInteger(r) || r < 1) throw new m("input", "实例快照字节预算应为正安全整数");
659
682
  return {
660
683
  read: e.read.bind(e),
661
684
  list: e.list.bind(e),
662
- save: async (a, r) => {
663
- const n = r.expectedRevision;
664
- if (n !== null && (!Number.isSafeInteger(n) || n < 1 || n >= Number.MAX_SAFE_INTEGER)) throw new w("input", "实例预期修订无效");
665
- const i = JSON.parse(se(a, s)), l = L({ ...i, revision: (n ?? 0) + 1 }, s);
666
- if (b(r.signal), !await e.compareAndSwap(l.scope, l.id, n, l, r.signal)) throw new w("conflict", "实例已存在或已变化,请显式确认修订后保存");
685
+ save: async (a, s) => {
686
+ const n = s.expectedRevision;
687
+ if (n !== null && (!Number.isSafeInteger(n) || n < 1 || n >= Number.MAX_SAFE_INTEGER)) throw new m("input", "实例预期修订无效");
688
+ const i = JSON.parse(oe(a, r)), l = V({ ...i, revision: (n ?? 0) + 1 }, r);
689
+ if (x(s.signal), !await e.compareAndSwap(l.scope, l.id, n, l, s.signal)) throw new m("conflict", "实例已存在或已变化,请显式确认修订后保存");
667
690
  return l;
668
691
  }
669
692
  };
670
693
  }
671
- function We(e, t) {
694
+ function tt(e, t) {
672
695
  return I({ reportIds: e, params: t });
673
696
  }
674
- function Te(e) {
675
- if (!e || typeof e != "object" || Object.getOwnPropertySymbols(e).length) throw new w("input", "生成请求应为普通对象");
697
+ function ze(e) {
698
+ if (!e || typeof e != "object" || Object.getOwnPropertySymbols(e).length) throw new m("input", "生成请求应为普通对象");
676
699
  const t = /* @__PURE__ */ Object.create(null);
677
- let s;
700
+ let r;
678
701
  const a = /* @__PURE__ */ new Set(["scope", "id", "title", "reportIds", "params", "expectedRevision", "signal"]);
679
- for (const r of Object.getOwnPropertyNames(e)) {
680
- const n = Object.getOwnPropertyDescriptor(e, r);
681
- if (!a.has(r) || !n.enumerable || n.get || n.set) throw new w("input", "生成请求不能包含未知字段或访问器");
682
- r === "signal" ? s = n.value : n.value !== void 0 && (t[r] = n.value);
702
+ for (const s of Object.getOwnPropertyNames(e)) {
703
+ const n = Object.getOwnPropertyDescriptor(e, s);
704
+ if (!a.has(s) || !n.enumerable || n.get || n.set) throw new m("input", "生成请求不能包含未知字段或访问器");
705
+ s === "signal" ? r = n.value : n.value !== void 0 && (t[s] = n.value);
683
706
  }
684
- return { signal: s, request: JSON.parse(I(t)) };
707
+ return { signal: r, request: JSON.parse(I(t)) };
685
708
  }
686
- function Ze(e) {
687
- const t = JSON.parse(I(e.templateRevisions)), s = Me(e.instances, { maxSnapshotBytes: e.maxSnapshotBytes });
709
+ function rt(e) {
710
+ const t = JSON.parse(I(e.templateRevisions)), r = Fe(e.instances, { maxSnapshotBytes: e.maxSnapshotBytes });
688
711
  return {
689
712
  async generate(a) {
690
- const { signal: r, request: n } = Te(a);
691
- if (N(n.scope, n.id), n.expectedRevision !== null && (!Number.isSafeInteger(n.expectedRevision) || n.expectedRevision < 1)) throw new w("input", "实例预期修订无效");
713
+ const { signal: s, request: n } = ze(a);
714
+ if (E(n.scope, n.id), n.expectedRevision !== null && (!Number.isSafeInteger(n.expectedRevision) || n.expectedRevision < 1)) throw new m("input", "实例预期修订无效");
692
715
  const i = e.runtime.validate(n);
693
- if (!i.ok) throw new Y(i.issues);
716
+ if (!i.ok) throw new te(i.issues);
694
717
  const l = /* @__PURE__ */ Object.create(null);
695
718
  for (const c of n.reportIds) {
696
719
  if (typeof t[c] != "string" || !t[c]) throw new TypeError(`报表 ${c} 缺少生成时的模板修订`);
697
720
  l[c] = t[c];
698
721
  }
699
- if (b(r), ((await e.instances.read(n.scope, n.id, void 0, r))?.revision ?? null) !== n.expectedRevision)
700
- throw new w("conflict", "实例已存在或已变化,请显式确认修订后生成");
701
- const o = await e.runtime.prepare({ reportIds: n.reportIds, params: i.values, signal: r });
702
- b(r);
703
- const u = /* @__PURE__ */ Object.create(null);
704
- for (const [c, d] of Object.entries(o.revisions)) d.revision !== void 0 && (u[c] = d.revision);
705
- return s.save({
722
+ if (x(s), ((await e.instances.read(n.scope, n.id, void 0, s))?.revision ?? null) !== n.expectedRevision)
723
+ throw new m("conflict", "实例已存在或已变化,请显式确认修订后生成");
724
+ const o = await e.runtime.prepare({ reportIds: n.reportIds, params: i.values, signal: s });
725
+ x(s);
726
+ const d = /* @__PURE__ */ Object.create(null);
727
+ for (const [c, u] of Object.entries(o.revisions)) u.revision !== void 0 && (d[c] = u.revision);
728
+ return r.save({
706
729
  scope: n.scope,
707
730
  id: n.id,
708
731
  title: n.title,
709
732
  reportIds: n.reportIds,
710
733
  params: i.values,
711
734
  templateRevisions: l,
712
- sourceRevisions: u,
735
+ sourceRevisions: d,
713
736
  generatedAt: (e.now?.() ?? /* @__PURE__ */ new Date()).toISOString(),
714
737
  plan: o.plan
715
- }, { expectedRevision: n.expectedRevision, signal: r });
738
+ }, { expectedRevision: n.expectedRevision, signal: s });
716
739
  },
717
- read: s.read,
718
- list: s.list,
740
+ read: r.read,
741
+ list: r.list,
719
742
  /** Instance edits are explicit snapshots; source business persistence remains the Provider.save responsibility. */
720
- save: s.save
743
+ save: r.save
721
744
  };
722
745
  }
723
746
  export {
724
- w as ReportInstanceError,
725
- v as ReportJobError,
747
+ m as ReportInstanceError,
748
+ b as ReportJobError,
726
749
  A as ReportRuntimeError,
727
- N as checkInstanceIdentity,
728
- $ as checkJobIdentity,
729
- D as cloneJob,
730
- Ue as createMemoryReportInstanceStore,
731
- et as createMemoryReportJobStore,
732
- Ze as createReportGenerationService,
733
- Me as createReportInstanceManager,
734
- Xe as createReportJobService,
735
- Se as createReportRuntime,
736
- Qe as createReportTaskQueue,
737
- We as reportInstanceParameterKey,
738
- De as reportInstanceSummary,
739
- Ge as reviewReportPublication,
740
- tt as runReportBatch,
741
- rt as runnableJob,
750
+ E as checkInstanceIdentity,
751
+ L as checkJobIdentity,
752
+ T as cloneJob,
753
+ et as createMemoryReportInstanceStore,
754
+ at as createMemoryReportJobStore,
755
+ rt as createReportGenerationService,
756
+ Fe as createReportInstanceManager,
757
+ Ke as createReportJobService,
758
+ Oe as createReportRuntime,
759
+ Ze as createReportTaskQueue,
760
+ tt as reportInstanceParameterKey,
761
+ $e as reportInstanceSummary,
762
+ Ye as reviewReportPublication,
763
+ ot as runReportBatch,
764
+ it as runnableJob,
742
765
  I as serializeJobJson,
743
- st as snapshotReportBatchCases,
744
- L as snapshotReportInstance,
745
- nt as validateJobRecord,
746
- at as validateJobTransition
766
+ ct as snapshotReportBatchCases,
767
+ V as snapshotReportInstance,
768
+ lt as validateJobRecord,
769
+ ut as validateJobTransition
747
770
  };