@agile-team/mach-report 2.16.0 → 2.17.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 (128) hide show
  1. package/README.md +10 -6
  2. package/dist/{ExcelBindingWizard-CP6h2x1f.cjs → ExcelBindingWizard-Bq6FYME6.cjs} +1 -1
  3. package/dist/{ExcelBindingWizard-HhB3hAJE.js → ExcelBindingWizard-Co1svTsw.js} +3 -3
  4. package/dist/{ParamEditor-CUQLgoxa.cjs → ParamEditor-B5UZRgxv.cjs} +1 -1
  5. package/dist/{ParamEditor-OKesP_nO.js → ParamEditor-DNNARyeB.js} +1 -1
  6. package/dist/{ReportBatchPanel-cZCAMAwH.cjs → ReportBatchPanel-Ctvs2t_9.cjs} +1 -1
  7. package/dist/{ReportBatchPanel-ruxcbfY6.js → ReportBatchPanel-uQh06usx.js} +1 -1
  8. package/dist/ReportPreview-BdQawRh0.js +4879 -0
  9. package/dist/ReportPreview-CJC_-j2I.cjs +6 -0
  10. package/dist/{ReportTemplateLibrary-BDlNT8JN.cjs → ReportTemplateLibrary-CnP7_1pH.cjs} +1 -1
  11. package/dist/{ReportTemplateLibrary-DcwrH-63.js → ReportTemplateLibrary-TIL_Oj2l.js} +1 -1
  12. package/dist/RuleEditor-DkRjOLlr.js +2141 -0
  13. package/dist/RuleEditor-h5anGsDB.cjs +1 -0
  14. package/dist/{TemplateOutlinePanel-CGrT5DFN.cjs → TemplateOutlinePanel-BlLxRrfu.cjs} +1 -1
  15. package/dist/{TemplateOutlinePanel-SXCjaPKR.js → TemplateOutlinePanel-BouxsuqQ.js} +1 -1
  16. package/dist/{TemplateReusePanel-lHLOS9Wn.js → TemplateReusePanel-BEACLPaN.js} +2 -2
  17. package/dist/{TemplateReusePanel-6Z3wRFz8.cjs → TemplateReusePanel-yxsHSO40.cjs} +1 -1
  18. package/dist/{TemplateReviewPanel-CJ9PLc48.js → TemplateReviewPanel-B1OGRY2i.js} +1 -1
  19. package/dist/{TemplateReviewPanel-Dpk7sLcF.cjs → TemplateReviewPanel-D9Cx0m2N.cjs} +1 -1
  20. package/dist/analytics.cjs +1 -1
  21. package/dist/analytics.d.cts +63 -1
  22. package/dist/analytics.d.ts +63 -1
  23. package/dist/analytics.js +4 -4
  24. package/dist/artifact-integrity.json +86 -90
  25. package/dist/assets-BIMVwjQe.js +231 -0
  26. package/dist/assets-Dfs2ElxI.cjs +1 -0
  27. package/dist/{auto-YR7a4BtF.js → auto-BIOmtVhk.js} +14 -14
  28. package/dist/{auto-uVBjX1j5.cjs → auto-DDHflI9v.cjs} +1 -1
  29. package/dist/computed-BW5a8QFk.js +612 -0
  30. package/dist/computed-C2GD3XcE.cjs +1 -0
  31. package/dist/dataset-DL83majE.js +161 -0
  32. package/dist/dataset-IrlXbUvh.cjs +1 -0
  33. package/dist/{designer-BfQSahxq.js → designer-D9XAxqSc.js} +1194 -1179
  34. package/dist/designer-uCDo5XSK.cjs +2 -0
  35. package/dist/designer.cjs +1 -1
  36. package/dist/designer.d.cts +125 -3
  37. package/dist/designer.d.ts +125 -3
  38. package/dist/designer.js +1 -1
  39. package/dist/{drill-CsdjgkRM.cjs → drill-ByN8COs_.cjs} +1 -1
  40. package/dist/{drill-DIGsZfyB.js → drill-CKW3Xtfa.js} +11 -11
  41. package/dist/{encoding-BYF9ZTl9.cjs → encoding-BFMFIc4r.cjs} +1 -1
  42. package/dist/{encoding-BOGq4qYL.js → encoding-DP_Eaf0A.js} +2 -2
  43. package/dist/{font-loader-EKLzOJxf.cjs → font-loader-7FWVlykp.cjs} +1 -1
  44. package/dist/{font-loader-CzI1GuBc.js → font-loader-CQZowp0I.js} +1 -1
  45. package/dist/index.cjs +8 -8
  46. package/dist/index.d.cts +173 -1
  47. package/dist/index.d.ts +173 -1
  48. package/dist/index.js +1205 -808
  49. package/dist/json-snapshot-D7PE1NsU.cjs +2 -0
  50. package/dist/{json-snapshot-D6ioHth9.js → json-snapshot-DYmEe3sO.js} +769 -692
  51. package/dist/matrix-JLAXlux-.js +302 -0
  52. package/dist/matrix-gTHpDTGm.cjs +1 -0
  53. package/dist/{pdf-ByVCb1i6.cjs → pdf-B8JouyYv.cjs} +47 -47
  54. package/dist/{pdf-DJ5S6ukC.js → pdf-l3ea86di.js} +13 -15
  55. package/dist/pdf.cjs +1 -1
  56. package/dist/pdf.d.cts +12 -0
  57. package/dist/pdf.d.ts +12 -0
  58. package/dist/pdf.js +2 -2
  59. package/dist/{plugin-C2j5_mhx.js → plugin-BBp74CQZ.js} +1 -1
  60. package/dist/{plugin-Dr39GBRG.cjs → plugin-CtFX9PFG.cjs} +1 -1
  61. package/dist/{prepared-DqtpvRTn.js → prepared-CARicKYh.js} +1 -1
  62. package/dist/{prepared-DdrjLC7L.cjs → prepared-Ch1x_Gog.cjs} +1 -1
  63. package/dist/{protocol-BzwMP4Vw.cjs → protocol-B5A2uom4.cjs} +1 -1
  64. package/dist/{protocol-kt4Iy6-3.js → protocol-BaiWjq5w.js} +3 -3
  65. package/dist/{record-bindings-DUX1VMlR.cjs → record-bindings-B86Sur_y.cjs} +1 -1
  66. package/dist/{record-bindings-CZWBJ1fU.js → record-bindings-D4TuMzHs.js} +1 -1
  67. package/dist/{region-binding-workflow-CWNvIjkV.js → region-binding-workflow-BNasF5kz.js} +2 -2
  68. package/dist/{region-binding-workflow-CqSMxQ4p.cjs → region-binding-workflow-O2Cni3mF.cjs} +1 -1
  69. package/dist/report-encoding-worker.cjs +1 -1
  70. package/dist/report-encoding-worker.js +1 -1
  71. package/dist/runtime-DakRXui3.js +170 -0
  72. package/dist/runtime-dL5ygIfa.cjs +1 -0
  73. package/dist/sbom.cdx.json +1 -1
  74. package/dist/server/node.d.cts +46 -0
  75. package/dist/server/node.d.ts +46 -0
  76. package/dist/server-node.cjs +4 -4
  77. package/dist/server-node.js +2540 -1911
  78. package/dist/server.cjs +1 -1
  79. package/dist/server.d.cts +174 -1
  80. package/dist/server.d.ts +174 -1
  81. package/dist/server.js +787 -544
  82. package/dist/style.css +1 -1
  83. package/dist/template-catalog-Dua8h9ZA.cjs +1 -0
  84. package/dist/{template-catalog-BtR2JmCL.js → template-catalog-wT1fNeAP.js} +4 -4
  85. package/dist/{template-fragments-BVsbxs4a.cjs → template-fragments-BajTajb4.cjs} +1 -1
  86. package/dist/{template-fragments-By0aZC1D.js → template-fragments-DmX5XK4N.js} +1 -1
  87. package/dist/{template-registry-C62vpv4a.cjs → template-registry-CpysHAxy.cjs} +1 -1
  88. package/dist/{template-registry-Cw3vRTX2.js → template-registry-u11fPd8D.js} +5 -5
  89. package/dist/{tree-BX380Rr7.cjs → tree-CLpxYbKa.cjs} +1 -1
  90. package/dist/{tree-CjVZLRw7.js → tree-DNJorJUf.js} +1 -1
  91. package/dist/vue/async.d.cts +108 -2
  92. package/dist/vue/async.d.ts +108 -2
  93. package/dist/vue/index.d.cts +130 -3
  94. package/dist/vue/index.d.ts +130 -3
  95. package/dist/vue-async.cjs +1 -1
  96. package/dist/vue-async.js +3 -3
  97. package/dist/vue.cjs +1 -1
  98. package/dist/vue.js +4 -4
  99. package/dist/{workbook-session-BeSO8PFB.js → workbook-session-B8pNW24X.js} +1 -1
  100. package/dist/{workbook-session-Cbts-22R.cjs → workbook-session-DN5LSA5C.cjs} +1 -1
  101. package/dist/worker.cjs +1 -1
  102. package/dist/worker.js +4 -4
  103. package/dist/xlsx.cjs +4 -4
  104. package/dist/xlsx.d.cts +88 -2
  105. package/dist/xlsx.d.ts +88 -2
  106. package/dist/xlsx.js +232 -230
  107. package/package.json +1 -1
  108. package/dist/ReportPreview-BcDKCLiK.js +0 -4834
  109. package/dist/ReportPreview-Bk9nLfO9.cjs +0 -6
  110. package/dist/RuleEditor-BX5S8RSF.cjs +0 -1
  111. package/dist/RuleEditor-CGl9XY2s.js +0 -2037
  112. package/dist/assets-CqIbfbTr.js +0 -126
  113. package/dist/assets-e4YSke8n.cjs +0 -1
  114. package/dist/capabilities-DDwXr_cA.js +0 -103
  115. package/dist/capabilities-DNLyZdNw.cjs +0 -1
  116. package/dist/computed-C-4C2S5h.js +0 -521
  117. package/dist/computed-CGV2a809.cjs +0 -1
  118. package/dist/dataset-BkRmwgeJ.cjs +0 -1
  119. package/dist/dataset-H5pFuQGU.js +0 -121
  120. package/dist/designer-CPPdeM5_.cjs +0 -2
  121. package/dist/diagnostic-notification-B9K9We3h.cjs +0 -1
  122. package/dist/diagnostic-notification-qGAYZdkB.js +0 -7
  123. package/dist/json-snapshot-DknkjvxP.cjs +0 -2
  124. package/dist/matrix-CGRGkn5s.js +0 -112
  125. package/dist/matrix-gEO7ZM_u.cjs +0 -1
  126. package/dist/runtime-BjKBI530.js +0 -168
  127. package/dist/runtime-CBFEPKEs.cjs +0 -1
  128. package/dist/template-catalog-C2NLdrwB.cjs +0 -1
@@ -1,521 +0,0 @@
1
- function g(r) {
2
- if (!Number.isSafeInteger(r) || r < 0 || r > 1e3 * 2)
3
- throw new Error("十进制精度超出预算");
4
- return 10n ** BigInt(r);
5
- }
6
- function h(r) {
7
- if (r.coefficient.toString().length > 1e3 * 2 || r.scale > 1e3 * 2)
8
- throw new Error("十进制结果超出精度预算");
9
- return r;
10
- }
11
- function s(r) {
12
- if (typeof r != "string" && !(typeof r == "number" && Number.isFinite(r)))
13
- throw new Error("十进制参数必须是有限数字或十进制文本");
14
- const e = String(r);
15
- if (e.length > 1e3) throw new Error("十进制文本超出精度预算");
16
- const n = /^([+-]?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d{1,4}))?$/.exec(
17
- e
18
- );
19
- if (!n) throw new Error("无效十进制文本");
20
- const t = n[3] ?? "", o = Number(n[4] ?? 0), i = t.length - o, c = BigInt(
21
- `${n[1] === "-" ? "-" : ""}${n[2]}${t}`
22
- );
23
- return h(
24
- i < 0 ? { coefficient: c * g(-i), scale: 0 } : { coefficient: c, scale: i }
25
- );
26
- }
27
- function B(r, e) {
28
- const n = Math.max(r.scale, e.scale);
29
- return [
30
- r.coefficient * g(n - r.scale),
31
- e.coefficient * g(n - e.scale),
32
- n
33
- ];
34
- }
35
- function O(r, e) {
36
- const [n, t] = B(r, e);
37
- return n < t ? -1 : n > t ? 1 : 0;
38
- }
39
- function m(r, e) {
40
- const [n, t, o] = B(r, e);
41
- return h({ coefficient: n + t, scale: o });
42
- }
43
- function A(r, e) {
44
- return h({
45
- coefficient: r.coefficient * e.coefficient,
46
- scale: r.scale + e.scale
47
- });
48
- }
49
- function D(r, e) {
50
- const n = r / e, t = r % e, o = (i) => i < 0n ? -i : i;
51
- return o(t) * 2n < o(e) ? n : n + (r < 0n == e < 0n ? 1n : -1n);
52
- }
53
- function p(r) {
54
- if (!Number.isInteger(r) || r < 0 || r > 100)
55
- throw new Error("十进制小数位应为 0–100 的整数");
56
- }
57
- function E(r, e, n = 20) {
58
- if (p(n), e.coefficient === 0n) throw new Error("不能除以零");
59
- const t = e.scale - r.scale + n, o = r.coefficient * g(Math.max(0, t)), i = e.coefficient * g(Math.max(0, -t));
60
- return h({
61
- coefficient: D(o, i),
62
- scale: n
63
- });
64
- }
65
- function v(r, e) {
66
- let n = r.coefficient, t = r.scale;
67
- e !== void 0 && (p(e), n = e >= t ? n * g(e - t) : D(n, g(t - e)), t = e);
68
- const o = n < 0n, i = (o ? -n : n).toString().padStart(t + 1, "0");
69
- let c = t ? i.slice(-t) : "";
70
- return e === void 0 && (c = c.replace(/0+$/, "")), `${o ? "-" : ""}${t ? i.slice(0, -t) : i}${c ? `.${c}` : ""}`;
71
- }
72
- function q(r, e, n = !1, t = !1) {
73
- let o = s(r);
74
- t && (o = A(o, { coefficient: 100n, scale: 0 }));
75
- const [i, c] = v(o, e).split(".");
76
- return `${n ? i.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : i}${c === void 0 ? "" : `.${c}`}${t ? "%" : ""}`;
77
- }
78
- const j = [
79
- "sum",
80
- "count",
81
- "avg",
82
- "min",
83
- "max",
84
- "weightedAvg"
85
- ];
86
- function N(r) {
87
- if (typeof r != "number" || !Number.isFinite(r))
88
- throw new Error(
89
- "聚合度量必须是有限数字,不能隐式转换;小数文本请显式选择 decimal"
90
- );
91
- return r;
92
- }
93
- function w(r, e) {
94
- return e && Object.prototype.hasOwnProperty.call(r, e) ? r[e] : void 0;
95
- }
96
- function _(r) {
97
- let e = 0, n = 0, t = 0, o = 0, i = 1 / 0, c = -1 / 0;
98
- const u = (a) => {
99
- const f = a - t, l = n + f;
100
- t = l - n - f, n = l;
101
- };
102
- return {
103
- add(a) {
104
- const f = w(a, r.field);
105
- if (r.op === "count") {
106
- (!r.field || f != null) && e++;
107
- return;
108
- }
109
- if (f == null) return;
110
- const l = N(f), F = r.op === "weightedAvg" ? w(a, r.weightField) : 1;
111
- if (F == null) return;
112
- const y = N(F);
113
- if (r.op === "weightedAvg" && y < 0)
114
- throw new Error("加权平均的权重不能为负数");
115
- ["sum", "avg", "weightedAvg"].includes(r.op) && u(l * y), o += y, i = Math.min(i, l), c = Math.max(c, l), e++;
116
- },
117
- value() {
118
- if (r.op === "count") return e;
119
- if (!e) return null;
120
- const a = r.op === "min" ? i : r.op === "max" ? c : r.op === "avg" ? n / e : r.op === "weightedAvg" ? o === 0 ? null : n / o : n;
121
- if (a !== null && !Number.isFinite(a))
122
- throw new Error("聚合计算溢出");
123
- return a;
124
- }
125
- };
126
- }
127
- function R(r) {
128
- let e = 0, n = s("0"), t = s("0"), o, i;
129
- return {
130
- add(c) {
131
- const u = w(c, r.field);
132
- if (r.op === "count") {
133
- (!r.field || u != null) && e++;
134
- return;
135
- }
136
- if (u == null) return;
137
- const a = r.op === "weightedAvg" ? w(c, r.weightField) : "1";
138
- if (a == null) return;
139
- const f = s(u), l = s(a);
140
- if (r.op === "weightedAvg" && l.coefficient < 0n)
141
- throw new Error("加权平均的权重不能为负数");
142
- ["sum", "avg", "weightedAvg"].includes(r.op) && (n = m(n, A(f, l))), r.op === "weightedAvg" && (t = m(t, l)), (!o || O(f, o) < 0) && (o = f), (!i || O(f, i) > 0) && (i = f), e++;
143
- },
144
- value() {
145
- if (r.op === "count") return e;
146
- if (!e || r.op === "weightedAvg" && t.coefficient === 0n)
147
- return null;
148
- let c = r.op === "min" ? o : r.op === "max" ? i : n;
149
- return r.op === "avg" && (c = E(n, s(e), r.digits)), r.op === "weightedAvg" && (c = E(n, t, r.digits)), v(c, r.digits);
150
- }
151
- };
152
- }
153
- function T(r) {
154
- if (r.digits !== void 0 && p(r.digits), r.numeric !== void 0 && r.numeric !== "number" && r.numeric !== "decimal")
155
- throw new Error("未知聚合数值模式");
156
- if (!j.includes(r.op)) throw new Error("未知聚合操作");
157
- if (r.op !== "count" && !r.field)
158
- throw new Error("聚合需要度量字段");
159
- if (r.op === "weightedAvg" && !r.weightField)
160
- throw new Error("加权平均需要权重字段");
161
- return r.numeric === "decimal" ? R(r) : _(r);
162
- }
163
- function $(r, e) {
164
- const n = T(e);
165
- for (const t of r) n.add(t);
166
- return n.value();
167
- }
168
- const C = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
169
- function d(r) {
170
- if (typeof r != "string" || !r.trim() || C.has(r))
171
- throw new Error("计算字段应为安全的非空字段名");
172
- }
173
- function b(r) {
174
- return r === null || ["string", "boolean"].includes(typeof r) || typeof r == "number" && Number.isFinite(r);
175
- }
176
- function G(r) {
177
- if (r.some((e) => typeof e != "number" || !Number.isFinite(e)))
178
- throw new Error("算术参数必须是有限数字;空值和小数文本不会隐式转换");
179
- return r;
180
- }
181
- function X(r, e) {
182
- const n = G(e);
183
- let t;
184
- if (r === "add") t = n.reduce((o, i) => o + i, 0);
185
- else if (r === "multiply") t = n.reduce((o, i) => o * i, 1);
186
- else if (r === "subtract") t = n[0] - n[1];
187
- else {
188
- if (n[1] === 0) throw new Error("不能除以零");
189
- t = n[0] / n[1];
190
- }
191
- if (!Number.isFinite(t)) throw new Error("计算结果不是有限数字");
192
- return t;
193
- }
194
- function Z(r, e, n) {
195
- const t = e.map(s);
196
- let o;
197
- return r === "add" ? o = t.reduce(m) : r === "multiply" ? o = t.reduce(A) : r === "subtract" ? o = m(t[0], {
198
- ...t[1],
199
- coefficient: -t[1].coefficient
200
- }) : o = E(t[0], t[1], n), v(o, n);
201
- }
202
- function J(r, e, n) {
203
- return n.nulls !== "error" && e.some((t) => t == null) || r === "divide" && n.divisionByZero === "null" && (n.numeric === "decimal" ? s(e[1]).coefficient === 0n : e[1] === 0) ? null : n.numeric === "decimal" ? Z(r, e, n.digits) : X(r, e);
204
- }
205
- function P(r, e) {
206
- r.field !== void 0 && d(r.field), r.weightField !== void 0 && d(r.weightField);
207
- const n = {
208
- op: r.aggregate,
209
- field: r.field,
210
- weightField: r.weightField,
211
- numeric: e.numeric,
212
- digits: e.digits
213
- };
214
- $([], n);
215
- const t = /* @__PURE__ */ new WeakMap();
216
- return (o) => {
217
- let i = t.get(o.rows);
218
- if (!i) {
219
- try {
220
- i = { value: $(o.rows, n) };
221
- } catch (c) {
222
- i = {
223
- error: c instanceof Error ? c : new Error(String(c))
224
- };
225
- }
226
- t.set(o.rows, i);
227
- }
228
- if (i.error) throw i.error;
229
- return i.value;
230
- };
231
- }
232
- function z(r, e) {
233
- for (const n of r) {
234
- const t = n(e);
235
- if (t != null) return t;
236
- }
237
- return null;
238
- }
239
- function S(r, e = {}, n = { nodes: 0 }, t = 0) {
240
- if (++n.nodes > 256 || t > 16)
241
- throw new Error("计算表达式超出深度或节点预算");
242
- if (!r || typeof r != "object" || Array.isArray(r))
243
- throw new Error("计算表达式应为声明式对象");
244
- if ("aggregate" in r) return P(r, e);
245
- if ("field" in r) {
246
- d(r.field);
247
- const o = r.field;
248
- return ({ row: i }) => Object.prototype.hasOwnProperty.call(i, o) ? i[o] : void 0;
249
- }
250
- if ("value" in r) {
251
- if (!b(r.value))
252
- throw new Error("常量应为有限 JSON 标量");
253
- return () => r.value;
254
- }
255
- return W(r, e, n, t);
256
- }
257
- function W(r, e, n, t) {
258
- if (!["add", "subtract", "multiply", "divide", "coalesce"].includes(
259
- r.op
260
- ) || !Array.isArray(r.args))
261
- throw new Error("未知计算操作");
262
- if (r.args.length > 256 || Object.keys(r.args).length !== r.args.length)
263
- throw new Error("计算参数超出预算或包含空位");
264
- if (r.args.length < 2 || ["subtract", "divide"].includes(r.op) && r.args.length !== 2)
265
- throw new Error("运算参数数量不正确");
266
- const o = r.args.map(
267
- (i) => S(i, e, n, t + 1)
268
- );
269
- return r.op === "coalesce" ? (i) => z(o, i) : (i) => J(
270
- r.op,
271
- o.map((c) => c(i)),
272
- e
273
- );
274
- }
275
- function K(r) {
276
- S(r);
277
- const e = /* @__PURE__ */ new Set(), n = (t) => {
278
- "field" in t && t.field && e.add(t.field), "aggregate" in t && t.weightField && e.add(t.weightField), "args" in t && t.args.forEach(n);
279
- };
280
- return n(r), [...e];
281
- }
282
- function Q(r) {
283
- if (d(r.field), r.scope !== void 0 && !["row", "group", "dataset"].includes(r.scope))
284
- throw new Error("未知计算范围");
285
- if (r.numeric !== void 0 && r.numeric !== "number" && r.numeric !== "decimal")
286
- throw new Error("未知数值模式");
287
- if (r.digits !== void 0 && p(r.digits), r.nulls !== void 0 && r.nulls !== "propagate" && r.nulls !== "error")
288
- throw new Error("未知空值规则");
289
- if (r.divisionByZero !== void 0 && r.divisionByZero !== "null" && r.divisionByZero !== "error")
290
- throw new Error("未知除零规则");
291
- if (r.scope === "group" && (!Array.isArray(r.groupBy) || !r.groupBy.length))
292
- throw new Error("分组计算需要 groupBy 字段");
293
- U(r);
294
- }
295
- function U(r) {
296
- if (r.groupBy !== void 0) {
297
- if (!Array.isArray(r.groupBy) || r.groupBy.length > 16)
298
- throw new Error("计算分组最多 16 级");
299
- r.groupBy.forEach(d);
300
- }
301
- if (r.dependsOn !== void 0) {
302
- if (!Array.isArray(r.dependsOn) || r.dependsOn.length > 2048)
303
- throw new Error("计算依赖超出预算");
304
- r.dependsOn.forEach(d);
305
- }
306
- }
307
- function M(r) {
308
- return [
309
- .../* @__PURE__ */ new Set([
310
- ...typeof r.expression == "string" ? r.dependsOn ?? [] : K(r.expression),
311
- ...r.groupBy ?? []
312
- ])
313
- ];
314
- }
315
- function k(r) {
316
- if (!Array.isArray(r) || r.length > 2048)
317
- throw new Error("计算字段应为数组且最多2048项");
318
- const e = /* @__PURE__ */ new Map();
319
- for (const c of r) {
320
- if (Q(c), e.has(c.field)) throw new Error(`计算字段重复:${c.field}`);
321
- e.set(c.field, c);
322
- }
323
- const n = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set(), o = [];
324
- function i(c) {
325
- if (!t.has(c.field)) {
326
- if (n.has(c.field))
327
- throw new Error(
328
- `计算字段存在循环依赖:${[...n, c.field].join(" → ")}`
329
- );
330
- n.add(c.field);
331
- for (const u of M(c)) {
332
- const a = e.get(u);
333
- a && i(a);
334
- }
335
- n.delete(c.field), t.add(c.field), o.push(c);
336
- }
337
- }
338
- return r.forEach(i), o;
339
- }
340
- function rr(r) {
341
- try {
342
- const e = k(r);
343
- return {
344
- valid: !0,
345
- errors: [],
346
- order: e.map((n) => n.field),
347
- fields: r.map((n) => ({
348
- field: n.field,
349
- dependencies: M(n),
350
- scope: n.scope ?? "row"
351
- }))
352
- };
353
- } catch (e) {
354
- return {
355
- valid: !1,
356
- errors: [e instanceof Error ? e.message : String(e)],
357
- fields: [],
358
- order: []
359
- };
360
- }
361
- }
362
- function er(r = []) {
363
- return {
364
- fields: r.map((e) => ({ ...e })),
365
- functions: [
366
- {
367
- name: "add",
368
- minArgs: 2,
369
- maxArgs: 256,
370
- input: "numeric",
371
- output: "numeric"
372
- },
373
- {
374
- name: "subtract",
375
- minArgs: 2,
376
- maxArgs: 2,
377
- input: "numeric",
378
- output: "numeric"
379
- },
380
- {
381
- name: "multiply",
382
- minArgs: 2,
383
- maxArgs: 256,
384
- input: "numeric",
385
- output: "numeric"
386
- },
387
- {
388
- name: "divide",
389
- minArgs: 2,
390
- maxArgs: 2,
391
- input: "numeric",
392
- output: "numeric"
393
- },
394
- {
395
- name: "coalesce",
396
- minArgs: 2,
397
- maxArgs: 256,
398
- input: "scalar",
399
- output: "scalar"
400
- }
401
- ],
402
- operations: ["add", "subtract", "multiply", "divide", "coalesce"],
403
- aggregates: ["sum", "count", "avg", "min", "max", "weightedAvg"],
404
- scopes: ["row", "group", "dataset"],
405
- numericModes: ["number", "decimal"],
406
- rules: {
407
- nulls: "propagate",
408
- aggregateNulls: "skip",
409
- emptyAggregate: null,
410
- countEmpty: 0,
411
- divisionByZero: "error",
412
- decimalOutput: "string",
413
- rounding: "half-away-from-zero"
414
- }
415
- };
416
- }
417
- function V(r) {
418
- return k(r.fields).map((e) => {
419
- if (typeof e.expression != "string")
420
- return {
421
- definition: e,
422
- read: S(e.expression, e)
423
- };
424
- if (!r.formula)
425
- throw new Error("字符串公式需要显式配置 formula adapter");
426
- const n = e.expression;
427
- return {
428
- definition: e,
429
- read: (t) => r.formula.evaluate(n, t)
430
- };
431
- });
432
- }
433
- function H(r, e) {
434
- return JSON.stringify(
435
- e.map((n) => {
436
- const t = Object.prototype.hasOwnProperty.call(r, n) ? r[n] : null;
437
- if (t != null && !b(t))
438
- throw new Error("分组字段应为有限 JSON 标量");
439
- return [typeof t, t ?? null];
440
- })
441
- );
442
- }
443
- function L(r, e) {
444
- if (e.scope === "dataset") return () => r;
445
- if (e.scope !== "group") {
446
- const o = /* @__PURE__ */ new WeakMap();
447
- return (i) => {
448
- let c = o.get(i);
449
- return c || (c = [i], o.set(i, c)), c;
450
- };
451
- }
452
- const n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new WeakMap();
453
- for (const o of r) {
454
- const i = H(o, e.groupBy);
455
- t.set(o, i);
456
- const c = n.get(i);
457
- c ? c.push(o) : n.set(i, [o]);
458
- }
459
- return (o) => n.get(t.get(o));
460
- }
461
- function Y(r, e) {
462
- const n = e.maxRows ?? 1e5, t = e.maxCells ?? 2e6;
463
- if (!Array.isArray(r) || !Number.isSafeInteger(n) || n < 1 || r.length > n)
464
- throw new Error("计算数据行数超出预算或输入不是数组");
465
- if (!Array.isArray(e.fields) || e.fields.length > 2048)
466
- throw new Error("计算字段应为数组且最多2048项");
467
- if (!Number.isSafeInteger(t) || t < 1 || r.length * e.fields.length > t)
468
- throw new Error("计算单元格超出 maxCells 预算");
469
- }
470
- function I(r) {
471
- if (r?.aborted) {
472
- const e = new Error("数据计算已取消");
473
- throw e.name = "AbortError", e;
474
- }
475
- }
476
- function x(r, e, n, t, o, i) {
477
- try {
478
- const c = r.read({ row: e, rowIndex: n, rows: t });
479
- if (c !== void 0 && !b(c))
480
- throw new Error("计算结果应为有限 JSON 标量,异步公式请先在数据源中求值");
481
- e[r.definition.field] = c ?? null;
482
- } catch (c) {
483
- const u = c instanceof Error ? c.message : String(c);
484
- if (o.onError !== "null")
485
- throw Object.assign(
486
- new Error(`第 ${n + 1} 行 ${r.definition.field}:${u}`),
487
- { cause: c }
488
- );
489
- e[r.definition.field] = null, i.push({ rowIndex: n, field: r.definition.field, message: u });
490
- }
491
- }
492
- function nr(r, e) {
493
- Y(r, e), I(e.signal);
494
- const n = V(e), t = [], o = r.map((i, c) => {
495
- if (!i || typeof i != "object" || Array.isArray(i))
496
- throw new Error(`第 ${c + 1} 行应为对象`);
497
- return { ...i };
498
- });
499
- for (const i of n) {
500
- const c = L(o, i.definition);
501
- o.forEach((u, a) => {
502
- I(e.signal), x(i, u, a, c(u), e, t);
503
- });
504
- }
505
- return { rows: o, issues: t };
506
- }
507
- export {
508
- m as a,
509
- $ as b,
510
- T as c,
511
- O as d,
512
- nr as e,
513
- p as f,
514
- E as g,
515
- q as h,
516
- er as i,
517
- v as j,
518
- A as m,
519
- s as p,
520
- rr as v
521
- };
@@ -1 +0,0 @@
1
- "use strict";function g(r){if(!Number.isSafeInteger(r)||r<0||r>1e3*2)throw new Error("十进制精度超出预算");return 10n**BigInt(r)}function y(r){if(r.coefficient.toString().length>1e3*2||r.scale>1e3*2)throw new Error("十进制结果超出精度预算");return r}function s(r){if(typeof r!="string"&&!(typeof r=="number"&&Number.isFinite(r)))throw new Error("十进制参数必须是有限数字或十进制文本");const e=String(r);if(e.length>1e3)throw new Error("十进制文本超出精度预算");const t=/^([+-]?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d{1,4}))?$/.exec(e);if(!t)throw new Error("无效十进制文本");const n=t[3]??"",o=Number(t[4]??0),i=n.length-o,c=BigInt(`${t[1]==="-"?"-":""}${t[2]}${n}`);return y(i<0?{coefficient:c*g(-i),scale:0}:{coefficient:c,scale:i})}function I(r,e){const t=Math.max(r.scale,e.scale);return[r.coefficient*g(t-r.scale),e.coefficient*g(t-e.scale),t]}function b(r,e){const[t,n]=I(r,e);return t<n?-1:t>n?1:0}function m(r,e){const[t,n,o]=I(r,e);return y({coefficient:t+n,scale:o})}function E(r,e){return y({coefficient:r.coefficient*e.coefficient,scale:r.scale+e.scale})}function M(r,e){const t=r/e,n=r%e,o=i=>i<0n?-i:i;return o(n)*2n<o(e)?t:t+(r<0n==e<0n?1n:-1n)}function w(r){if(!Number.isInteger(r)||r<0||r>100)throw new Error("十进制小数位应为 0–100 的整数")}function h(r,e,t=20){if(w(t),e.coefficient===0n)throw new Error("不能除以零");const n=e.scale-r.scale+t,o=r.coefficient*g(Math.max(0,n)),i=e.coefficient*g(Math.max(0,-n));return y({coefficient:M(o,i),scale:t})}function A(r,e){let t=r.coefficient,n=r.scale;e!==void 0&&(w(e),t=e>=n?t*g(e-n):M(t,g(n-e)),n=e);const o=t<0n,i=(o?-t:t).toString().padStart(n+1,"0");let c=n?i.slice(-n):"";return e===void 0&&(c=c.replace(/0+$/,"")),`${o?"-":""}${n?i.slice(0,-n):i}${c?`.${c}`:""}`}function _(r,e,t=!1,n=!1){let o=s(r);n&&(o=E(o,{coefficient:100n,scale:0}));const[i,c]=A(o,e).split(".");return`${t?i.replace(/\B(?=(\d{3})+(?!\d))/g,","):i}${c===void 0?"":`.${c}`}${n?"%":""}`}const R=["sum","count","avg","min","max","weightedAvg"];function N(r){if(typeof r!="number"||!Number.isFinite(r))throw new Error("聚合度量必须是有限数字,不能隐式转换;小数文本请显式选择 decimal");return r}function p(r,e){return e&&Object.prototype.hasOwnProperty.call(r,e)?r[e]:void 0}function C(r){let e=0,t=0,n=0,o=0,i=1/0,c=-1/0;const u=a=>{const l=a-n,f=t+l;n=f-t-l,t=f};return{add(a){const l=p(a,r.field);if(r.op==="count"){(!r.field||l!=null)&&e++;return}if(l==null)return;const f=N(l),O=r.op==="weightedAvg"?p(a,r.weightField):1;if(O==null)return;const v=N(O);if(r.op==="weightedAvg"&&v<0)throw new Error("加权平均的权重不能为负数");["sum","avg","weightedAvg"].includes(r.op)&&u(f*v),o+=v,i=Math.min(i,f),c=Math.max(c,f),e++},value(){if(r.op==="count")return e;if(!e)return null;const a=r.op==="min"?i:r.op==="max"?c:r.op==="avg"?t/e:r.op==="weightedAvg"?o===0?null:t/o:t;if(a!==null&&!Number.isFinite(a))throw new Error("聚合计算溢出");return a}}}function T(r){let e=0,t=s("0"),n=s("0"),o,i;return{add(c){const u=p(c,r.field);if(r.op==="count"){(!r.field||u!=null)&&e++;return}if(u==null)return;const a=r.op==="weightedAvg"?p(c,r.weightField):"1";if(a==null)return;const l=s(u),f=s(a);if(r.op==="weightedAvg"&&f.coefficient<0n)throw new Error("加权平均的权重不能为负数");["sum","avg","weightedAvg"].includes(r.op)&&(t=m(t,E(l,f))),r.op==="weightedAvg"&&(n=m(n,f)),(!o||b(l,o)<0)&&(o=l),(!i||b(l,i)>0)&&(i=l),e++},value(){if(r.op==="count")return e;if(!e||r.op==="weightedAvg"&&n.coefficient===0n)return null;let c=r.op==="min"?o:r.op==="max"?i:t;return r.op==="avg"&&(c=h(t,s(e),r.digits)),r.op==="weightedAvg"&&(c=h(t,n,r.digits)),A(c,r.digits)}}}function B(r){if(r.digits!==void 0&&w(r.digits),r.numeric!==void 0&&r.numeric!=="number"&&r.numeric!=="decimal")throw new Error("未知聚合数值模式");if(!R.includes(r.op))throw new Error("未知聚合操作");if(r.op!=="count"&&!r.field)throw new Error("聚合需要度量字段");if(r.op==="weightedAvg"&&!r.weightField)throw new Error("加权平均需要权重字段");return r.numeric==="decimal"?T(r):C(r)}function S(r,e){const t=B(e);for(const n of r)t.add(n);return t.value()}const G=new Set(["__proto__","prototype","constructor"]);function d(r){if(typeof r!="string"||!r.trim()||G.has(r))throw new Error("计算字段应为安全的非空字段名")}function D(r){return r===null||["string","boolean"].includes(typeof r)||typeof r=="number"&&Number.isFinite(r)}function X(r){if(r.some(e=>typeof e!="number"||!Number.isFinite(e)))throw new Error("算术参数必须是有限数字;空值和小数文本不会隐式转换");return r}function Z(r,e){const t=X(e);let n;if(r==="add")n=t.reduce((o,i)=>o+i,0);else if(r==="multiply")n=t.reduce((o,i)=>o*i,1);else if(r==="subtract")n=t[0]-t[1];else{if(t[1]===0)throw new Error("不能除以零");n=t[0]/t[1]}if(!Number.isFinite(n))throw new Error("计算结果不是有限数字");return n}function J(r,e,t){const n=e.map(s);let o;return r==="add"?o=n.reduce(m):r==="multiply"?o=n.reduce(E):r==="subtract"?o=m(n[0],{...n[1],coefficient:-n[1].coefficient}):o=h(n[0],n[1],t),A(o,t)}function P(r,e,t){return t.nulls!=="error"&&e.some(n=>n==null)||r==="divide"&&t.divisionByZero==="null"&&(t.numeric==="decimal"?s(e[1]).coefficient===0n:e[1]===0)?null:t.numeric==="decimal"?J(r,e,t.digits):Z(r,e)}function z(r,e){r.field!==void 0&&d(r.field),r.weightField!==void 0&&d(r.weightField);const t={op:r.aggregate,field:r.field,weightField:r.weightField,numeric:e.numeric,digits:e.digits};S([],t);const n=new WeakMap;return o=>{let i=n.get(o.rows);if(!i){try{i={value:S(o.rows,t)}}catch(c){i={error:c instanceof Error?c:new Error(String(c))}}n.set(o.rows,i)}if(i.error)throw i.error;return i.value}}function W(r,e){for(const t of r){const n=t(e);if(n!=null)return n}return null}function F(r,e={},t={nodes:0},n=0){if(++t.nodes>256||n>16)throw new Error("计算表达式超出深度或节点预算");if(!r||typeof r!="object"||Array.isArray(r))throw new Error("计算表达式应为声明式对象");if("aggregate"in r)return z(r,e);if("field"in r){d(r.field);const o=r.field;return({row:i})=>Object.prototype.hasOwnProperty.call(i,o)?i[o]:void 0}if("value"in r){if(!D(r.value))throw new Error("常量应为有限 JSON 标量");return()=>r.value}return K(r,e,t,n)}function K(r,e,t,n){if(!["add","subtract","multiply","divide","coalesce"].includes(r.op)||!Array.isArray(r.args))throw new Error("未知计算操作");if(r.args.length>256||Object.keys(r.args).length!==r.args.length)throw new Error("计算参数超出预算或包含空位");if(r.args.length<2||["subtract","divide"].includes(r.op)&&r.args.length!==2)throw new Error("运算参数数量不正确");const o=r.args.map(i=>F(i,e,t,n+1));return r.op==="coalesce"?i=>W(o,i):i=>P(r.op,o.map(c=>c(i)),e)}function Q(r){F(r);const e=new Set,t=n=>{"field"in n&&n.field&&e.add(n.field),"aggregate"in n&&n.weightField&&e.add(n.weightField),"args"in n&&n.args.forEach(t)};return t(r),[...e]}function U(r){if(d(r.field),r.scope!==void 0&&!["row","group","dataset"].includes(r.scope))throw new Error("未知计算范围");if(r.numeric!==void 0&&r.numeric!=="number"&&r.numeric!=="decimal")throw new Error("未知数值模式");if(r.digits!==void 0&&w(r.digits),r.nulls!==void 0&&r.nulls!=="propagate"&&r.nulls!=="error")throw new Error("未知空值规则");if(r.divisionByZero!==void 0&&r.divisionByZero!=="null"&&r.divisionByZero!=="error")throw new Error("未知除零规则");if(r.scope==="group"&&(!Array.isArray(r.groupBy)||!r.groupBy.length))throw new Error("分组计算需要 groupBy 字段");V(r)}function V(r){if(r.groupBy!==void 0){if(!Array.isArray(r.groupBy)||r.groupBy.length>16)throw new Error("计算分组最多 16 级");r.groupBy.forEach(d)}if(r.dependsOn!==void 0){if(!Array.isArray(r.dependsOn)||r.dependsOn.length>2048)throw new Error("计算依赖超出预算");r.dependsOn.forEach(d)}}function k(r){return[...new Set([...typeof r.expression=="string"?r.dependsOn??[]:Q(r.expression),...r.groupBy??[]])]}function j(r){if(!Array.isArray(r)||r.length>2048)throw new Error("计算字段应为数组且最多2048项");const e=new Map;for(const c of r){if(U(c),e.has(c.field))throw new Error(`计算字段重复:${c.field}`);e.set(c.field,c)}const t=new Set,n=new Set,o=[];function i(c){if(!n.has(c.field)){if(t.has(c.field))throw new Error(`计算字段存在循环依赖:${[...t,c.field].join(" → ")}`);t.add(c.field);for(const u of k(c)){const a=e.get(u);a&&i(a)}t.delete(c.field),n.add(c.field),o.push(c)}}return r.forEach(i),o}function H(r){try{const e=j(r);return{valid:!0,errors:[],order:e.map(t=>t.field),fields:r.map(t=>({field:t.field,dependencies:k(t),scope:t.scope??"row"}))}}catch(e){return{valid:!1,errors:[e instanceof Error?e.message:String(e)],fields:[],order:[]}}}function L(r=[]){return{fields:r.map(e=>({...e})),functions:[{name:"add",minArgs:2,maxArgs:256,input:"numeric",output:"numeric"},{name:"subtract",minArgs:2,maxArgs:2,input:"numeric",output:"numeric"},{name:"multiply",minArgs:2,maxArgs:256,input:"numeric",output:"numeric"},{name:"divide",minArgs:2,maxArgs:2,input:"numeric",output:"numeric"},{name:"coalesce",minArgs:2,maxArgs:256,input:"scalar",output:"scalar"}],operations:["add","subtract","multiply","divide","coalesce"],aggregates:["sum","count","avg","min","max","weightedAvg"],scopes:["row","group","dataset"],numericModes:["number","decimal"],rules:{nulls:"propagate",aggregateNulls:"skip",emptyAggregate:null,countEmpty:0,divisionByZero:"error",decimalOutput:"string",rounding:"half-away-from-zero"}}}function Y(r){return j(r.fields).map(e=>{if(typeof e.expression!="string")return{definition:e,read:F(e.expression,e)};if(!r.formula)throw new Error("字符串公式需要显式配置 formula adapter");const t=e.expression;return{definition:e,read:n=>r.formula.evaluate(t,n)}})}function x(r,e){return JSON.stringify(e.map(t=>{const n=Object.prototype.hasOwnProperty.call(r,t)?r[t]:null;if(n!=null&&!D(n))throw new Error("分组字段应为有限 JSON 标量");return[typeof n,n??null]}))}function q(r,e){if(e.scope==="dataset")return()=>r;if(e.scope!=="group"){const o=new WeakMap;return i=>{let c=o.get(i);return c||(c=[i],o.set(i,c)),c}}const t=new Map,n=new WeakMap;for(const o of r){const i=x(o,e.groupBy);n.set(o,i);const c=t.get(i);c?c.push(o):t.set(i,[o])}return o=>t.get(n.get(o))}function rr(r,e){const t=e.maxRows??1e5,n=e.maxCells??2e6;if(!Array.isArray(r)||!Number.isSafeInteger(t)||t<1||r.length>t)throw new Error("计算数据行数超出预算或输入不是数组");if(!Array.isArray(e.fields)||e.fields.length>2048)throw new Error("计算字段应为数组且最多2048项");if(!Number.isSafeInteger(n)||n<1||r.length*e.fields.length>n)throw new Error("计算单元格超出 maxCells 预算")}function $(r){if(r?.aborted){const e=new Error("数据计算已取消");throw e.name="AbortError",e}}function er(r,e,t,n,o,i){try{const c=r.read({row:e,rowIndex:t,rows:n});if(c!==void 0&&!D(c))throw new Error("计算结果应为有限 JSON 标量,异步公式请先在数据源中求值");e[r.definition.field]=c??null}catch(c){const u=c instanceof Error?c.message:String(c);if(o.onError!=="null")throw Object.assign(new Error(`第 ${t+1} 行 ${r.definition.field}:${u}`),{cause:c});e[r.definition.field]=null,i.push({rowIndex:t,field:r.definition.field,message:u})}}function tr(r,e){rr(r,e),$(e.signal);const t=Y(e),n=[],o=r.map((i,c)=>{if(!i||typeof i!="object"||Array.isArray(i))throw new Error(`第 ${c+1} 行应为对象`);return{...i}});for(const i of t){const c=q(o,i.definition);o.forEach((u,a)=>{$(e.signal),er(i,u,a,c(u),e,n)})}return{rows:o,issues:n}}exports.addDecimal=m;exports.aggregateRows=S;exports.compareDecimal=b;exports.computeDataset=tr;exports.createAggregateAccumulator=B;exports.decimalDigits=w;exports.divideDecimal=h;exports.formatDecimal=_;exports.getComputationMetadata=L;exports.multiplyDecimal=E;exports.parseDecimal=s;exports.printDecimal=A;exports.validateComputedFields=H;
@@ -1 +0,0 @@
1
- "use strict";const c=["text","number","boolean","date","decimal"],p=new Set(["__proto__","prototype","constructor"]);function i(e){throw new Error(`数据契约无效:${e}`)}function g(e){(!e||!Array.isArray(e.fields)||!e.fields.length||e.fields.length>2048)&&i("fields 应包含 1–2048 个字段");const n=new Set;for(const t of e.fields)(!t||typeof t.field!="string"||!t.field.trim()||p.has(t.field)||n.has(t.field))&&i("字段名应安全、非空且唯一"),n.add(t.field),c.includes(t.type)||i(`未知字段类型 ${t.type}`),x(t),l(t),d(t);b(e,n)}function d(e){e.enum!==void 0&&(!Array.isArray(e.enum)||!e.enum.length||e.enum.some(n=>!f(n,e.type)))&&i("enum 应为匹配字段类型的非空标量数组")}function b(e,n){e.rowKey!==void 0&&((typeof e.rowKey!="string"||!e.rowKey.trim()||!n.has(e.rowKey))&&i("rowKey 应为引用已声明字段的非空字符串"),e.fields.find(t=>t.field===e.rowKey)?.type==="boolean"&&i("布尔字段不能作为业务主键"))}function l(e){for(const n of["label","unit"])e[n]!==void 0&&typeof e[n]!="string"&&i(`${n} 应为字符串`);for(const n of["required","nullable"])e[n]!==void 0&&typeof e[n]!="boolean"&&i(`${n} 应为布尔值`);e.semanticRole!==void 0&&!["identifier","dimension","measure","date","text"].includes(e.semanticRole)&&i("未知字段语义")}function x(e){for(const n of["min","max","minLength","maxLength"]){const t=e[n];t!==void 0&&(!Number.isFinite(t)||n.includes("Length")&&(!Number.isInteger(t)||t<0))&&i(`${n} 无效`)}e.min!==void 0&&e.max!==void 0&&e.min>e.max&&i("min 不能超过 max"),e.minLength!==void 0&&e.maxLength!==void 0&&e.minLength>e.maxLength&&i("minLength 不能超过 maxLength"),e.type!=="number"&&(e.min!==void 0||e.max!==void 0)&&i("min/max 仅适用于 number,精确小数文本需业务校验"),["number","boolean"].includes(e.type)&&(e.minLength!==void 0||e.maxLength!==void 0)&&i("长度约束仅适用于文本类型")}function w(e){const n=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!n)return!1;const t=Number(n[1]),r=Number(n[2]),s=Number(n[3]),m=t%4===0&&(t%100!==0||t%400===0);return t>0&&r>=1&&r<=12&&s>=1&&s<=[31,m?29:28,31,30,31,30,31,31,30,31,30,31][r-1]}function f(e,n){return n==="number"?typeof e=="number"&&Number.isFinite(e):n==="boolean"?typeof e=="boolean":typeof e!="string"?!1:n==="date"?w(e):n==="decimal"?e.length<=1e4&&/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(e):!0}function L(e,n){if(e==null)return n.required||e===null&&n.nullable===!1?{code:"required",message:"缺少必需字段值"}:void 0;if(!f(e,n.type))return{code:"type",message:`值应为 ${n.type},不会自动转换原始值`};if(n.enum&&!n.enum.includes(e))return{code:"enum",message:"值不在允许的枚举中"};if(typeof e=="number"&&(n.min!==void 0&&e<n.min||n.max!==void 0&&e>n.max))return{code:"range",message:"数值超出范围"};if(typeof e=="string"&&!v(e,n))return{code:"range",message:"文本长度超出范围"}}function v(e,n){if(n.minLength===void 0&&n.maxLength===void 0)return!0;let t=0;for(const r of e)t++;return(n.minLength===void 0||t>=n.minLength)&&(n.maxLength===void 0||t<=n.maxLength)}function h(e,n){const t=e??n;if(!Number.isInteger(t)||t<1)throw new Error("数据校验预算应为正整数");return t}function $(e,n,t){const r=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if((typeof r!="string"||!r.trim())&&!(typeof r=="number"&&Number.isFinite(r)))return"业务主键应为非空字符串或有限数字";const s=JSON.stringify([typeof r,r]);if(t.has(s))return"业务主键重复";t.add(s)}function K(e,n,t={}){g(n);const r=t.path??"$.rows",s=[],m=h(t.maxIssues,100);if(!Array.isArray(e))return{ok:!1,issues:[{code:"row",path:r,message:"数据集应为对象数组"}]};if(e.length>h(t.maxRows,1e5)||e.length*n.fields.length>h(t.maxCells,2e6))return{ok:!1,issues:[{code:"budget",path:r,message:"数据校验超出行数或单元格预算"}]};const u=new Set;for(let o=0;o<e.length&&s.length<m;o++){const a=e[o];if(!a||typeof a!="object"||Array.isArray(a)){s.push({code:"row",path:`${r}[${o}]`,rowIndex:o,message:"行应为对象"});continue}k(a,n,o,r,u,s,m)}return{ok:s.length===0,issues:s}}function k(e,n,t,r,s,m,u){for(const o of n.fields){if(m.length>=u)return;const a=L(Object.prototype.hasOwnProperty.call(e,o.field)?e[o.field]:void 0,o);a&&m.push({...a,rowIndex:t,field:o.field,path:`${r}[${t}].${o.field}`})}if(n.rowKey&&m.length<u){const o=$(e,n.rowKey,s);o&&m.push({code:"row-key",path:`${r}[${t}].${n.rowKey}`,message:o,rowIndex:t,field:n.rowKey})}}function S(e){return g(e),{$schema:"https://json-schema.org/draft/2020-12/schema",type:"array",items:{type:"object",properties:Object.fromEntries(e.fields.map(t=>[t.field,N(t,t.field===e.rowKey)])),required:e.fields.filter(t=>t.required||t.field===e.rowKey).map(t=>t.field),additionalProperties:!0},...e.rowKey?{"x-report-rowKey":e.rowKey}:{}}}function N(e,n){const t=!n&&e.nullable!==!1&&!e.required;return{type:t?[y(e.type),"null"]:y(e.type),...e.label?{title:e.label}:{},...e.type==="date"?{format:"date"}:{},...e.type==="decimal"?{pattern:"^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?$"}:{},...e.enum?{enum:t?[...e.enum,null]:[...e.enum]}:{},...e.min===void 0?{}:{minimum:e.min},...e.max===void 0?{}:{maximum:e.max},...R(e,n),...n&&e.type==="text"?{pattern:"\\S"}:{},...e.unit?{"x-report-unit":e.unit}:{},...e.semanticRole?{"x-report-semanticRole":e.semanticRole}:{}}}function R(e,n){const t={};return(e.minLength!==void 0||n&&e.type!=="number")&&(t.minLength=Math.max(e.minLength??0,n?1:0)),e.type==="decimal"?t.maxLength=Math.min(e.maxLength??1e4,1e4):e.maxLength!==void 0&&(t.maxLength=e.maxLength),t}function y(e){return e==="text"||e==="date"||e==="decimal"?"string":e}exports.datasetJsonSchema=S;exports.validateDatasetRows=K;