@agile-team/mach-report 2.16.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -12
- package/dist/{ExcelBindingWizard-CP6h2x1f.cjs → ExcelBindingWizard-Czn3C2yE.cjs} +1 -1
- package/dist/{ExcelBindingWizard-HhB3hAJE.js → ExcelBindingWizard-DMGZj6I6.js} +3 -3
- package/dist/ParamEditor-KzDQvbHY.js +732 -0
- package/dist/ParamEditor-oDfD8LgE.cjs +1 -0
- package/dist/{ReportBatchPanel-ruxcbfY6.js → ReportBatchPanel-BJK7PvZ4.js} +39 -39
- package/dist/ReportBatchPanel-DnmNRssu.cjs +1 -0
- package/dist/ReportParamPanel-mQkeN70Q.js +1020 -0
- package/dist/ReportParamPanel-sOANVRz-.cjs +1 -0
- package/dist/ReportPreview-BxWWTUL5.js +5583 -0
- package/dist/ReportPreview-Yf99omi3.cjs +6 -0
- package/dist/{ReportTemplateLibrary-DcwrH-63.js → ReportTemplateLibrary-BFjB08Wu.js} +1 -1
- package/dist/{ReportTemplateLibrary-BDlNT8JN.cjs → ReportTemplateLibrary-BO42QnWd.cjs} +1 -1
- package/dist/RuleEditor-CqxT1a-W.js +2337 -0
- package/dist/RuleEditor-D7YWigD9.cjs +1 -0
- package/dist/{TemplateOutlinePanel-CGrT5DFN.cjs → TemplateOutlinePanel-B0XX350V.cjs} +1 -1
- package/dist/{TemplateOutlinePanel-SXCjaPKR.js → TemplateOutlinePanel-zG0DrsIB.js} +2 -2
- package/dist/{TemplateReusePanel-6Z3wRFz8.cjs → TemplateReusePanel-BD0HSKp_.cjs} +1 -1
- package/dist/{TemplateReusePanel-lHLOS9Wn.js → TemplateReusePanel-Czwe5GbC.js} +2 -2
- package/dist/{TemplateReviewPanel-Dpk7sLcF.cjs → TemplateReviewPanel-CA5sdffM.cjs} +1 -1
- package/dist/{TemplateReviewPanel-CJ9PLc48.js → TemplateReviewPanel-NhmQI65C.js} +2 -2
- package/dist/analytics.cjs +1 -1
- package/dist/analytics.d.cts +163 -42
- package/dist/analytics.d.ts +163 -42
- package/dist/analytics.js +76 -141
- package/dist/artifact-integrity.json +110 -108
- package/dist/assets-2eC3mOcV.js +232 -0
- package/dist/assets-B0Hxn4l6.cjs +1 -0
- package/dist/{auto-uVBjX1j5.cjs → auto-B0EZFIK1.cjs} +1 -1
- package/dist/{auto-YR7a4BtF.js → auto-BlchZ1b8.js} +10 -10
- package/dist/{batch-WzDIXJAt.js → batch-DGCt44XM.js} +1 -1
- package/dist/{batch-z6Aw5GEY.cjs → batch-DYcokH4v.cjs} +1 -1
- package/dist/charts-Dlv8j2AG.js +141 -0
- package/dist/charts-aCtoswXq.cjs +1 -0
- package/dist/codes.cjs +9 -9
- package/dist/codes.d.cts +54 -0
- package/dist/codes.d.ts +54 -0
- package/dist/codes.js +12097 -13668
- package/dist/column-visual-BpgQVWwT.js +238 -0
- package/dist/column-visual-CtYxnBCP.cjs +1 -0
- package/dist/component-tree-6TV7W6Yj.cjs +1 -0
- package/dist/component-tree-CvW4lzpv.js +67 -0
- package/dist/computed-4TnxzgIh.cjs +1 -0
- package/dist/computed-C8NRZQss.js +739 -0
- package/dist/data-bar-Ce38juRZ.cjs +1 -0
- package/dist/data-bar-PtjXhMgN.js +9 -0
- package/dist/dataset-DL83majE.js +161 -0
- package/dist/dataset-IrlXbUvh.cjs +1 -0
- package/dist/designer--TKECSEc.cjs +2 -0
- package/dist/designer-d6hJS41w.js +5683 -0
- package/dist/designer.cjs +1 -1
- package/dist/designer.d.cts +835 -45
- package/dist/designer.d.ts +835 -45
- package/dist/designer.js +23 -20
- package/dist/{encoding-BYF9ZTl9.cjs → encoding-B--eZpp1.cjs} +1 -1
- package/dist/{encoding-BOGq4qYL.js → encoding-mctOLocI.js} +2 -2
- package/dist/{font-loader-EKLzOJxf.cjs → font-loader-DBBJ5KE9.cjs} +1 -1
- package/dist/{font-loader-CzI1GuBc.js → font-loader-DW8tIaNp.js} +1 -1
- package/dist/index-CPh6tqge.js +1575 -0
- package/dist/index-CUNw7dL9.cjs +1 -0
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +534 -16
- package/dist/index.d.ts +534 -16
- package/dist/index.js +1393 -955
- package/dist/json-snapshot-By4ZVVUt.js +1967 -0
- package/dist/json-snapshot-jiXff4lc.cjs +2 -0
- package/dist/matrix-0hywp0-F.cjs +1 -0
- package/dist/matrix-Dy-tyY7E.js +381 -0
- package/dist/param-validation-C-8sRJLq.cjs +1 -0
- package/dist/param-validation-CnDEd2l-.js +333 -0
- package/dist/{pdf-DJ5S6ukC.js → pdf-CKROKygt.js} +1845 -1845
- package/dist/{pdf-ByVCb1i6.cjs → pdf-DqyxJ96U.cjs} +47 -47
- package/dist/pdf.cjs +1 -1
- package/dist/pdf.d.cts +66 -0
- package/dist/pdf.d.ts +66 -0
- package/dist/pdf.js +2 -2
- package/dist/{plugin-C2j5_mhx.js → plugin-ByjF2kiV.js} +5 -5
- package/dist/{plugin-Dr39GBRG.cjs → plugin-DM1M2wlI.cjs} +1 -1
- package/dist/prefill-B8H9qwE4.js +371 -0
- package/dist/prefill-D7EswyTI.cjs +1 -0
- package/dist/{prepared-DqtpvRTn.js → prepared-BE-4jfX5.js} +2 -2
- package/dist/{prepared-DdrjLC7L.cjs → prepared-CGVphji3.cjs} +1 -1
- package/dist/{protocol-BzwMP4Vw.cjs → protocol-ByRVzzQG.cjs} +1 -1
- package/dist/{protocol-kt4Iy6-3.js → protocol-Cr81vFSQ.js} +3 -3
- package/dist/{record-bindings-CZWBJ1fU.js → record-bindings-DEJtmo3p.js} +67 -107
- package/dist/record-bindings-ehjnCDHt.cjs +1 -0
- package/dist/{region-binding-workflow-CWNvIjkV.js → region-binding-workflow-CBg0l_tj.js} +2 -2
- package/dist/{region-binding-workflow-CqSMxQ4p.cjs → region-binding-workflow-D05tOYn3.cjs} +1 -1
- package/dist/report-encoding-worker.cjs +1 -1
- package/dist/report-encoding-worker.js +1 -1
- package/dist/{report-params-B1RzkhJj.js → report-params-D9tBuM9B.js} +1 -1
- package/dist/{report-params-WDGrA4oP.cjs → report-params-VTg8MoCp.cjs} +1 -1
- package/dist/runtime-CDA6d263.cjs +1 -0
- package/dist/runtime-CEMvybO7.js +170 -0
- package/dist/sbom.cdx.json +1 -1
- package/dist/server/node.d.cts +121 -7
- package/dist/server/node.d.ts +121 -7
- package/dist/server-node.cjs +4 -4
- package/dist/server-node.js +3446 -2115
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +417 -29
- package/dist/server.d.ts +417 -29
- package/dist/server.js +787 -544
- package/dist/sha256-BDQ1Qk7A.js +158 -0
- package/dist/sha256-DgZAKXqI.cjs +1 -0
- package/dist/style.css +1 -1
- package/dist/template-bindings-Cg5oBLFT.cjs +1 -0
- package/dist/template-bindings-TKnXM7ll.js +62 -0
- package/dist/{template-catalog-BtR2JmCL.js → template-catalog-CmbWOJqy.js} +16 -16
- package/dist/template-catalog-Utu4GP09.cjs +1 -0
- package/dist/{template-fragments-BVsbxs4a.cjs → template-fragments-C_zSHJAa.cjs} +1 -1
- package/dist/{template-fragments-By0aZC1D.js → template-fragments-DWgo9tlZ.js} +2 -2
- package/dist/{template-outline-BwRV_eRo.cjs → template-outline-DWkzZXVC.cjs} +1 -1
- package/dist/{template-outline-cnWfT_LK.js → template-outline-DiADphlq.js} +1 -1
- package/dist/{template-registry-Cw3vRTX2.js → template-registry-BIhIHOab.js} +319 -314
- package/dist/template-registry-DzWswQI5.cjs +1 -0
- package/dist/vue/async.d.cts +636 -35
- package/dist/vue/async.d.ts +636 -35
- package/dist/vue/index.d.cts +746 -67
- package/dist/vue/index.d.ts +746 -67
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +94 -89
- package/dist/{workbook-session-Cbts-22R.cjs → workbook-session-B94EwVa_.cjs} +1 -1
- package/dist/{workbook-session-BeSO8PFB.js → workbook-session-BoScoOg-.js} +2 -2
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +75 -7
- package/dist/worker.d.ts +75 -7
- package/dist/worker.js +4 -4
- package/dist/xlsx.cjs +4 -4
- package/dist/xlsx.d.cts +208 -15
- package/dist/xlsx.d.ts +208 -15
- package/dist/xlsx.js +288 -252
- package/package.json +1 -1
- package/dist/ParamEditor-CUQLgoxa.cjs +0 -1
- package/dist/ParamEditor-OKesP_nO.js +0 -594
- package/dist/ReportBatchPanel-cZCAMAwH.cjs +0 -1
- package/dist/ReportPreview-BcDKCLiK.js +0 -4834
- package/dist/ReportPreview-Bk9nLfO9.cjs +0 -6
- package/dist/RuleEditor-BX5S8RSF.cjs +0 -1
- package/dist/RuleEditor-CGl9XY2s.js +0 -2037
- package/dist/assets-CqIbfbTr.js +0 -126
- package/dist/assets-e4YSke8n.cjs +0 -1
- package/dist/capabilities-DDwXr_cA.js +0 -103
- package/dist/capabilities-DNLyZdNw.cjs +0 -1
- package/dist/component-tree-Ca6YYfHq.js +0 -61
- package/dist/component-tree-DkGLEfZC.cjs +0 -1
- package/dist/computed-C-4C2S5h.js +0 -521
- package/dist/computed-CGV2a809.cjs +0 -1
- package/dist/config-Dg_o8e7m.cjs +0 -1
- package/dist/config-XQ4qrQ7Q.js +0 -844
- package/dist/dataset-BkRmwgeJ.cjs +0 -1
- package/dist/dataset-H5pFuQGU.js +0 -121
- package/dist/designer-BfQSahxq.js +0 -5163
- package/dist/designer-CPPdeM5_.cjs +0 -2
- package/dist/diagnostic-notification-B9K9We3h.cjs +0 -1
- package/dist/diagnostic-notification-qGAYZdkB.js +0 -7
- package/dist/drill-CsdjgkRM.cjs +0 -1
- package/dist/drill-DIGsZfyB.js +0 -145
- package/dist/json-snapshot-D6ioHth9.js +0 -1702
- package/dist/json-snapshot-DknkjvxP.cjs +0 -2
- package/dist/matrix-CGRGkn5s.js +0 -112
- package/dist/matrix-gEO7ZM_u.cjs +0 -1
- package/dist/param-validation-C3HlcLLO.cjs +0 -1
- package/dist/param-validation-Do7Eg8Zv.js +0 -181
- package/dist/record-bindings-DUX1VMlR.cjs +0 -1
- package/dist/runtime-BjKBI530.js +0 -168
- package/dist/runtime-CBFEPKEs.cjs +0 -1
- package/dist/sha256-BshdOkCC.cjs +0 -1
- package/dist/sha256-DTG-Gq8i.js +0 -157
- package/dist/template-bindings-C2SpvsMU.js +0 -58
- package/dist/template-bindings-CEtWyiLX.cjs +0 -1
- package/dist/template-catalog-C2NLdrwB.cjs +0 -1
- package/dist/template-registry-C62vpv4a.cjs +0 -1
- package/dist/tree-BX380Rr7.cjs +0 -1
- package/dist/tree-CjVZLRw7.js +0 -172
|
@@ -0,0 +1,739 @@
|
|
|
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 O(r) {
|
|
7
|
+
if (r.coefficient.toString().length > 1e3 * 2 || r.scale > 1e3 * 2)
|
|
8
|
+
throw new Error("十进制结果超出精度预算");
|
|
9
|
+
return r;
|
|
10
|
+
}
|
|
11
|
+
function l(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 t = /^([+-]?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d{1,4}))?$/.exec(
|
|
17
|
+
e
|
|
18
|
+
);
|
|
19
|
+
if (!t) throw new Error("无效十进制文本");
|
|
20
|
+
const n = t[3] ?? "", i = Number(t[4] ?? 0), c = n.length - i, o = BigInt(
|
|
21
|
+
`${t[1] === "-" ? "-" : ""}${t[2]}${n}`
|
|
22
|
+
);
|
|
23
|
+
return O(
|
|
24
|
+
c < 0 ? { coefficient: o * g(-c), scale: 0 } : { coefficient: o, scale: c }
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
function J(r, e) {
|
|
28
|
+
const t = Math.max(r.scale, e.scale);
|
|
29
|
+
return [
|
|
30
|
+
r.coefficient * g(t - r.scale),
|
|
31
|
+
e.coefficient * g(t - e.scale),
|
|
32
|
+
t
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
function b(r, e) {
|
|
36
|
+
const [t, n] = J(r, e);
|
|
37
|
+
return t < n ? -1 : t > n ? 1 : 0;
|
|
38
|
+
}
|
|
39
|
+
function E(r, e) {
|
|
40
|
+
const [t, n, i] = J(r, e);
|
|
41
|
+
return O({ coefficient: t + n, scale: i });
|
|
42
|
+
}
|
|
43
|
+
function Y(r, e) {
|
|
44
|
+
return O({
|
|
45
|
+
coefficient: r.coefficient * e.coefficient,
|
|
46
|
+
scale: r.scale + e.scale
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function V(r, e) {
|
|
50
|
+
const t = r / e, n = r % e, i = (c) => c < 0n ? -c : c;
|
|
51
|
+
return i(n) * 2n < i(e) ? t : t + (r < 0n == e < 0n ? 1n : -1n);
|
|
52
|
+
}
|
|
53
|
+
function w(r) {
|
|
54
|
+
if (!Number.isInteger(r) || r < 0 || r > 100)
|
|
55
|
+
throw new Error("十进制小数位应为 0–100 的整数");
|
|
56
|
+
}
|
|
57
|
+
function j(r, e, t = 20) {
|
|
58
|
+
if (w(t), e.coefficient === 0n) throw new Error("不能除以零");
|
|
59
|
+
const n = e.scale - r.scale + t, i = r.coefficient * g(Math.max(0, n)), c = e.coefficient * g(Math.max(0, -n));
|
|
60
|
+
return O({
|
|
61
|
+
coefficient: V(i, c),
|
|
62
|
+
scale: t
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function S(r, e) {
|
|
66
|
+
let t = r.coefficient, n = r.scale;
|
|
67
|
+
e !== void 0 && (w(e), t = e >= n ? t * g(e - n) : V(t, g(n - e)), n = e);
|
|
68
|
+
const i = t < 0n, c = (i ? -t : t).toString().padStart(n + 1, "0");
|
|
69
|
+
let o = n ? c.slice(-n) : "";
|
|
70
|
+
return e === void 0 && (o = o.replace(/0+$/, "")), `${i ? "-" : ""}${n ? c.slice(0, -n) : c}${o ? `.${o}` : ""}`;
|
|
71
|
+
}
|
|
72
|
+
function Fr(r, e, t = !1, n = !1) {
|
|
73
|
+
let i = l(r);
|
|
74
|
+
n && (i = Y(i, { coefficient: 100n, scale: 0 }));
|
|
75
|
+
const [c, o] = S(i, e).split(".");
|
|
76
|
+
return `${t ? c.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : c}${o === void 0 ? "" : `.${o}`}${n ? "%" : ""}`;
|
|
77
|
+
}
|
|
78
|
+
const H = [
|
|
79
|
+
"sum",
|
|
80
|
+
"count",
|
|
81
|
+
"avg",
|
|
82
|
+
"min",
|
|
83
|
+
"max",
|
|
84
|
+
"weightedAvg"
|
|
85
|
+
];
|
|
86
|
+
function _(r) {
|
|
87
|
+
if (typeof r != "number" || !Number.isFinite(r))
|
|
88
|
+
throw new Error(
|
|
89
|
+
"聚合度量必须是有限数字,不能隐式转换;小数文本请显式选择 decimal"
|
|
90
|
+
);
|
|
91
|
+
return r;
|
|
92
|
+
}
|
|
93
|
+
function A(r, e) {
|
|
94
|
+
return e && Object.prototype.hasOwnProperty.call(r, e) ? r[e] : void 0;
|
|
95
|
+
}
|
|
96
|
+
function Q(r) {
|
|
97
|
+
let e = 0, t = 0, n = 0, i = 0, c = 1 / 0, o = -1 / 0;
|
|
98
|
+
const a = (s) => {
|
|
99
|
+
const f = s - n, u = t + f;
|
|
100
|
+
n = u - t - f, t = u;
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
add(s) {
|
|
104
|
+
const f = A(s, r.field);
|
|
105
|
+
if (r.op === "count") {
|
|
106
|
+
(!r.field || f != null) && e++;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (f == null) return;
|
|
110
|
+
const u = _(f), C = r.op === "weightedAvg" ? A(s, r.weightField) : 1;
|
|
111
|
+
if (C == null) return;
|
|
112
|
+
const N = _(C);
|
|
113
|
+
if (r.op === "weightedAvg" && N < 0)
|
|
114
|
+
throw new Error("加权平均的权重不能为负数");
|
|
115
|
+
["sum", "avg", "weightedAvg"].includes(r.op) && a(u * N), i += N, c = Math.min(c, u), o = Math.max(o, u), e++;
|
|
116
|
+
},
|
|
117
|
+
value() {
|
|
118
|
+
if (r.op === "count") return e;
|
|
119
|
+
if (!e) return null;
|
|
120
|
+
const s = r.op === "min" ? c : r.op === "max" ? o : r.op === "avg" ? t / e : r.op === "weightedAvg" ? i === 0 ? null : t / i : t;
|
|
121
|
+
if (s !== null && !Number.isFinite(s))
|
|
122
|
+
throw new Error("聚合计算溢出");
|
|
123
|
+
return s;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function q(r) {
|
|
128
|
+
let e = 0, t = l("0"), n = l("0"), i, c;
|
|
129
|
+
return {
|
|
130
|
+
add(o) {
|
|
131
|
+
const a = A(o, r.field);
|
|
132
|
+
if (r.op === "count") {
|
|
133
|
+
(!r.field || a != null) && e++;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (a == null) return;
|
|
137
|
+
const s = r.op === "weightedAvg" ? A(o, r.weightField) : "1";
|
|
138
|
+
if (s == null) return;
|
|
139
|
+
const f = l(a), u = l(s);
|
|
140
|
+
if (r.op === "weightedAvg" && u.coefficient < 0n)
|
|
141
|
+
throw new Error("加权平均的权重不能为负数");
|
|
142
|
+
["sum", "avg", "weightedAvg"].includes(r.op) && (t = E(t, Y(f, u))), r.op === "weightedAvg" && (n = E(n, u)), (!i || b(f, i) < 0) && (i = f), (!c || b(f, c) > 0) && (c = f), e++;
|
|
143
|
+
},
|
|
144
|
+
value() {
|
|
145
|
+
if (r.op === "count") return e;
|
|
146
|
+
if (!e || r.op === "weightedAvg" && n.coefficient === 0n)
|
|
147
|
+
return null;
|
|
148
|
+
let o = r.op === "min" ? i : r.op === "max" ? c : t;
|
|
149
|
+
return r.op === "avg" && (o = j(t, l(e), r.digits)), r.op === "weightedAvg" && (o = j(t, n, r.digits)), S(o, r.digits);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function rr(r) {
|
|
154
|
+
if (r.digits !== void 0 && w(r.digits), r.numeric !== void 0 && r.numeric !== "number" && r.numeric !== "decimal")
|
|
155
|
+
throw new Error("未知聚合数值模式");
|
|
156
|
+
if (!H.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" ? q(r) : Q(r);
|
|
162
|
+
}
|
|
163
|
+
function $(r, e) {
|
|
164
|
+
const t = rr(e);
|
|
165
|
+
for (const n of r) t.add(n);
|
|
166
|
+
return t.value();
|
|
167
|
+
}
|
|
168
|
+
const Z = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
169
|
+
function K(r) {
|
|
170
|
+
if (!r || typeof r != "object" || Array.isArray(r) || ![Object.prototype, null].includes(Object.getPrototypeOf(r))) throw new Error("条件应为普通声明式对象");
|
|
171
|
+
for (const [e, t] of Object.entries(Object.getOwnPropertyDescriptors(r))) if (Z.has(e) || !Object.prototype.hasOwnProperty.call(t, "value")) throw new Error("条件不允许访问器或不安全属性");
|
|
172
|
+
}
|
|
173
|
+
function T(r) {
|
|
174
|
+
if (typeof r != "string" || !r.trim() || r.length > 512 || Z.has(r)) throw new Error("条件字段应为安全的非空字段名");
|
|
175
|
+
}
|
|
176
|
+
function M(r) {
|
|
177
|
+
if (r !== null && typeof r != "boolean" && typeof r != "string" && !(typeof r == "number" && Number.isFinite(r))) throw new Error("条件常量应为有限 JSON 标量");
|
|
178
|
+
if (typeof r == "string" && r.length > 16384) throw new Error("条件文本超出预算");
|
|
179
|
+
}
|
|
180
|
+
function F(r) {
|
|
181
|
+
if (typeof r != "string" || !/^\d{4}-\d{2}-\d{2}$/.test(r)) throw new Error("日期条件使用 YYYY-MM-DD 日历日");
|
|
182
|
+
const [e, t, n] = r.split("-").map(Number), i = /* @__PURE__ */ new Date(0);
|
|
183
|
+
if (i.setUTCFullYear(e, t - 1, n), i.setUTCHours(0, 0, 0, 0), i.getUTCFullYear() !== e || i.getUTCMonth() !== t - 1 || i.getUTCDate() !== n) throw new Error("无效日历日");
|
|
184
|
+
return r;
|
|
185
|
+
}
|
|
186
|
+
function B(r) {
|
|
187
|
+
return ["string", "boolean"].includes(typeof r) || typeof r == "number" && Number.isFinite(r);
|
|
188
|
+
}
|
|
189
|
+
function U(r) {
|
|
190
|
+
return r == null || r === "";
|
|
191
|
+
}
|
|
192
|
+
function er(r) {
|
|
193
|
+
const e = r.values?.[0] ?? (r.right && "value" in r.right ? r.right.value : r.value);
|
|
194
|
+
return r.valueType ?? r.numeric ?? (typeof e == "number" ? "decimal" : typeof e == "boolean" ? "boolean" : "text");
|
|
195
|
+
}
|
|
196
|
+
function h(r, e, t) {
|
|
197
|
+
if (U(r) || U(e)) return;
|
|
198
|
+
const n = er(t);
|
|
199
|
+
try {
|
|
200
|
+
if (n === "decimal") return b(l(r), l(e));
|
|
201
|
+
if (n === "number")
|
|
202
|
+
return !["number", "string"].includes(typeof r) || !["number", "string"].includes(typeof e) ? void 0 : b(l(r), l(e));
|
|
203
|
+
if (n === "date" && (r = F(r), e = F(e)), n === "boolean" && (typeof r != "boolean" || typeof e != "boolean") || n === "text" && (!B(r) || !B(e))) return;
|
|
204
|
+
const i = String(r), c = String(e);
|
|
205
|
+
return i < c ? -1 : i > c ? 1 : 0;
|
|
206
|
+
} catch {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function tr(r) {
|
|
211
|
+
if (T(r.field), ![">", ">=", "<", "<=", "==", "!=", "between", "contains", "isNull", "isNotNull"].includes(r.op)) throw new Error("未知条件运算符");
|
|
212
|
+
if (r.numeric !== void 0 && !["number", "decimal"].includes(r.numeric)) throw new Error("未知条件数值模式");
|
|
213
|
+
if (r.valueType !== void 0 && !["number", "decimal", "text", "date", "boolean"].includes(r.valueType)) throw new Error("未知条件值类型");
|
|
214
|
+
if (!(r.op === "isNull" || r.op === "isNotNull"))
|
|
215
|
+
if (r.op === "between") {
|
|
216
|
+
if (!Array.isArray(r.values) || r.values.length !== 2 || Object.keys(r.values).length !== 2) throw new Error("范围条件需要两个明确边界");
|
|
217
|
+
r.values.forEach(M);
|
|
218
|
+
const e = h(r.values[0], r.values[1], r);
|
|
219
|
+
if (e === void 0 || e > 0) throw new Error("范围边界无效或顺序颠倒");
|
|
220
|
+
} else if (r.right !== void 0) {
|
|
221
|
+
if (K(r.right), Object.keys(r.right).length !== 1) throw new Error("条件 right 只能指定一个 field 或 value");
|
|
222
|
+
if ("field" in r.right ? T(r.right.field) : M(r.right.value), r.value !== void 0) throw new Error("条件不能同时指定 value 和 right");
|
|
223
|
+
} else M(r.value);
|
|
224
|
+
}
|
|
225
|
+
function D(r, e) {
|
|
226
|
+
if (e === void 0) return !1;
|
|
227
|
+
switch (r) {
|
|
228
|
+
case ">":
|
|
229
|
+
return e > 0;
|
|
230
|
+
case ">=":
|
|
231
|
+
return e >= 0;
|
|
232
|
+
case "<":
|
|
233
|
+
return e < 0;
|
|
234
|
+
case "<=":
|
|
235
|
+
return e <= 0;
|
|
236
|
+
case "==":
|
|
237
|
+
return e === 0;
|
|
238
|
+
case "!=":
|
|
239
|
+
return e !== 0;
|
|
240
|
+
default:
|
|
241
|
+
return !1;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function nr(r) {
|
|
245
|
+
tr(r), r = { ...r, right: r.right ? { ...r.right } : void 0, values: r.values ? [r.values[0], r.values[1]] : void 0 };
|
|
246
|
+
const e = (t, n) => Object.prototype.hasOwnProperty.call(t, n) ? t[n] : void 0;
|
|
247
|
+
return (t) => {
|
|
248
|
+
const n = e(t, r.field);
|
|
249
|
+
if (r.op === "isNull") return n == null;
|
|
250
|
+
if (r.op === "isNotNull") return n != null;
|
|
251
|
+
if (r.op === "between") return D(">=", h(n, r.values[0], r)) && D("<=", h(n, r.values[1], r));
|
|
252
|
+
const i = r.right ? "field" in r.right ? e(t, r.right.field) : r.right.value : r.value;
|
|
253
|
+
return r.op === "contains" ? typeof n == "string" && typeof i == "string" && n.includes(i) : D(r.op, h(n, i, r));
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function p(r, e = { nodes: 0 }, t = 0) {
|
|
257
|
+
if (++e.nodes > 256 || t > 16) throw new Error("条件超出深度或节点预算");
|
|
258
|
+
if (K(r), ["all", "any", "not", "field"].filter((i) => Object.prototype.hasOwnProperty.call(r, i)).length !== 1) throw new Error("条件只能指定一种组合或比较");
|
|
259
|
+
if ("not" in r) {
|
|
260
|
+
const i = p(r.not, e, t + 1);
|
|
261
|
+
return (c) => !i(c);
|
|
262
|
+
}
|
|
263
|
+
if ("all" in r || "any" in r) {
|
|
264
|
+
const i = "all" in r ? r.all : r.any;
|
|
265
|
+
if (!Array.isArray(i) || i.length < 1 || i.length > 256 || Object.keys(i).length !== i.length) throw new Error("组合条件需要有界、无空位的非空数组");
|
|
266
|
+
const c = i.map((o) => p(o, e, t + 1));
|
|
267
|
+
return "all" in r ? (o) => c.every((a) => a(o)) : (o) => c.some((a) => a(o));
|
|
268
|
+
}
|
|
269
|
+
return nr(r);
|
|
270
|
+
}
|
|
271
|
+
function xr(r, e) {
|
|
272
|
+
return p(e)(r);
|
|
273
|
+
}
|
|
274
|
+
function ir(r) {
|
|
275
|
+
p(r);
|
|
276
|
+
const e = /* @__PURE__ */ new Set();
|
|
277
|
+
function t(n) {
|
|
278
|
+
"all" in n ? n.all.forEach(t) : "any" in n ? n.any.forEach(t) : "not" in n ? t(n.not) : (e.add(n.field), n.right && "field" in n.right && e.add(n.right.field));
|
|
279
|
+
}
|
|
280
|
+
return t(r), [...e];
|
|
281
|
+
}
|
|
282
|
+
const or = [
|
|
283
|
+
{ name: "add", minArgs: 2, maxArgs: 256, input: "numeric", output: "numeric", example: "add(quantity, adjustment)" },
|
|
284
|
+
{ name: "subtract", minArgs: 2, maxArgs: 2, input: "numeric", output: "numeric", example: "subtract(input, output)" },
|
|
285
|
+
{ name: "multiply", minArgs: 2, maxArgs: 256, input: "numeric", output: "numeric", example: "multiply(quantity, price)" },
|
|
286
|
+
{ name: "divide", minArgs: 2, maxArgs: 2, input: "numeric", output: "numeric", example: "divide(amount, quantity)" },
|
|
287
|
+
{ name: "coalesce", minArgs: 2, maxArgs: 256, input: "scalar", output: "scalar", example: "coalesce(actual, planned)" },
|
|
288
|
+
{ name: "if", minArgs: 2, maxArgs: 2, input: "condition + branches", output: "scalar", example: "if(quantity > 0, divide(amount, quantity), null)" },
|
|
289
|
+
{ name: "round", minArgs: 1, maxArgs: 2, input: "numeric, digits?", output: "numeric", example: "round(amount, 2)" },
|
|
290
|
+
{ name: "abs", minArgs: 1, maxArgs: 1, input: "numeric", output: "numeric", example: "abs(difference)" },
|
|
291
|
+
{ name: "concat", minArgs: 2, maxArgs: 256, input: "text", output: "text", example: "concat(plant, '-' , heat)" },
|
|
292
|
+
{ name: "trim", minArgs: 1, maxArgs: 1, input: "text", output: "text", example: "trim(heat)" },
|
|
293
|
+
{ name: "upper", minArgs: 1, maxArgs: 1, input: "text", output: "text", example: "upper(grade)" },
|
|
294
|
+
{ name: "lower", minArgs: 1, maxArgs: 1, input: "text", output: "text", example: "lower(code)" },
|
|
295
|
+
{ name: "dateYear", minArgs: 1, maxArgs: 1, input: "YYYY-MM-DD", output: "number", example: "dateYear(reportDate)" },
|
|
296
|
+
{ name: "dateMonth", minArgs: 1, maxArgs: 1, input: "YYYY-MM-DD", output: "number", example: "dateMonth(reportDate)" },
|
|
297
|
+
{ name: "dateDay", minArgs: 1, maxArgs: 1, input: "YYYY-MM-DD", output: "number", example: "dateDay(reportDate)" }
|
|
298
|
+
], x = Object.freeze(or.map((r) => Object.freeze(r)));
|
|
299
|
+
function cr(r, e, t, n, i) {
|
|
300
|
+
if (e.some((a) => a == null)) {
|
|
301
|
+
if (i === "error") throw new Error("函数参数包含空值");
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
if (r === "round" || r === "abs") return ar(r, e, t, n);
|
|
305
|
+
if (r.startsWith("date")) {
|
|
306
|
+
const a = F(e[0]);
|
|
307
|
+
return Number(a.slice(r === "dateYear" ? 0 : r === "dateMonth" ? 5 : 8, r === "dateYear" ? 4 : r === "dateMonth" ? 7 : 10));
|
|
308
|
+
}
|
|
309
|
+
if (e.some((a) => typeof a != "string")) throw new Error("文本函数只接受文本,不隐式转换数字或空值");
|
|
310
|
+
if (e.reduce((a, s) => a + s.length, 0) > 1e6) throw new Error("计算文本超出长度预算");
|
|
311
|
+
const c = e[0], o = r === "concat" ? e.join("") : r === "trim" ? c.trim() : r === "upper" ? c.toUpperCase() : c.toLowerCase();
|
|
312
|
+
if (o.length > 1e6) throw new Error("计算文本超出长度预算");
|
|
313
|
+
return o;
|
|
314
|
+
}
|
|
315
|
+
function ar(r, e, t, n) {
|
|
316
|
+
const i = e[0];
|
|
317
|
+
if (t !== "decimal" && (typeof i != "number" || !Number.isFinite(i))) throw new Error("普通数值函数需要有限数字");
|
|
318
|
+
const c = l(i);
|
|
319
|
+
r === "abs" && (c.coefficient = c.coefficient < 0n ? -c.coefficient : c.coefficient);
|
|
320
|
+
const o = r === "round" ? e.length === 2 ? e[1] : n ?? 0 : n;
|
|
321
|
+
if (o !== void 0) {
|
|
322
|
+
if (typeof o != "number") throw new Error("小数位必须为数字");
|
|
323
|
+
w(o);
|
|
324
|
+
}
|
|
325
|
+
const a = S(c, o), s = Number(a);
|
|
326
|
+
if (t !== "decimal" && !Number.isFinite(s)) throw new Error("计算结果不是有限数字");
|
|
327
|
+
return t === "decimal" ? a : s;
|
|
328
|
+
}
|
|
329
|
+
const sr = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
330
|
+
function d(r) {
|
|
331
|
+
if (typeof r != "string" || !r.trim() || sr.has(r))
|
|
332
|
+
throw new Error("计算字段应为安全的非空字段名");
|
|
333
|
+
}
|
|
334
|
+
function I(r) {
|
|
335
|
+
return r === null || ["string", "boolean"].includes(typeof r) || typeof r == "number" && Number.isFinite(r);
|
|
336
|
+
}
|
|
337
|
+
function fr(r) {
|
|
338
|
+
if (r.some((e) => typeof e != "number" || !Number.isFinite(e)))
|
|
339
|
+
throw new Error("算术参数必须是有限数字;空值和小数文本不会隐式转换");
|
|
340
|
+
return r;
|
|
341
|
+
}
|
|
342
|
+
function ur(r, e) {
|
|
343
|
+
const t = fr(e);
|
|
344
|
+
let n;
|
|
345
|
+
if (r === "add") n = t.reduce((i, c) => i + c, 0);
|
|
346
|
+
else if (r === "multiply") n = t.reduce((i, c) => i * c, 1);
|
|
347
|
+
else if (r === "subtract") n = t[0] - t[1];
|
|
348
|
+
else {
|
|
349
|
+
if (t[1] === 0) throw new Error("不能除以零");
|
|
350
|
+
n = t[0] / t[1];
|
|
351
|
+
}
|
|
352
|
+
if (!Number.isFinite(n)) throw new Error("计算结果不是有限数字");
|
|
353
|
+
return n;
|
|
354
|
+
}
|
|
355
|
+
function lr(r, e, t) {
|
|
356
|
+
const n = e.map(l);
|
|
357
|
+
let i;
|
|
358
|
+
return r === "add" ? i = n.reduce(E) : r === "multiply" ? i = n.reduce(Y) : r === "subtract" ? i = E(n[0], {
|
|
359
|
+
...n[1],
|
|
360
|
+
coefficient: -n[1].coefficient
|
|
361
|
+
}) : i = j(n[0], n[1], t), S(i, t);
|
|
362
|
+
}
|
|
363
|
+
function mr(r, e, t) {
|
|
364
|
+
return t.nulls !== "error" && e.some((n) => n == null) || r === "divide" && t.divisionByZero === "null" && (t.numeric === "decimal" ? l(e[1]).coefficient === 0n : e[1] === 0) ? null : t.numeric === "decimal" ? lr(r, e, t.digits) : ur(r, e);
|
|
365
|
+
}
|
|
366
|
+
function gr(r, e) {
|
|
367
|
+
r.field !== void 0 && d(r.field), r.weightField !== void 0 && d(r.weightField);
|
|
368
|
+
const t = {
|
|
369
|
+
op: r.aggregate,
|
|
370
|
+
field: r.field,
|
|
371
|
+
weightField: r.weightField,
|
|
372
|
+
numeric: e.numeric,
|
|
373
|
+
digits: e.digits
|
|
374
|
+
};
|
|
375
|
+
$([], t);
|
|
376
|
+
const n = /* @__PURE__ */ new WeakMap();
|
|
377
|
+
return (i) => {
|
|
378
|
+
let c = n.get(i.rows);
|
|
379
|
+
if (!c) {
|
|
380
|
+
try {
|
|
381
|
+
c = { value: $(i.rows, t) };
|
|
382
|
+
} catch (o) {
|
|
383
|
+
c = {
|
|
384
|
+
error: o instanceof Error ? o : new Error(String(o))
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
n.set(i.rows, c);
|
|
388
|
+
}
|
|
389
|
+
if (c.error) throw c.error;
|
|
390
|
+
return c.value;
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function dr(r, e) {
|
|
394
|
+
for (const t of r) {
|
|
395
|
+
const n = t(e);
|
|
396
|
+
if (n != null) return n;
|
|
397
|
+
}
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
function P(r, e = {}, t = { nodes: 0 }, n = 0) {
|
|
401
|
+
if (++t.nodes > 256 || n > 16)
|
|
402
|
+
throw new Error("计算表达式超出深度或节点预算");
|
|
403
|
+
if (!r || typeof r != "object" || Array.isArray(r))
|
|
404
|
+
throw new Error("计算表达式应为声明式对象");
|
|
405
|
+
if ("aggregate" in r) return gr(r, e);
|
|
406
|
+
if ("field" in r) {
|
|
407
|
+
d(r.field);
|
|
408
|
+
const i = r.field;
|
|
409
|
+
return ({ row: c }) => Object.prototype.hasOwnProperty.call(c, i) ? c[i] : void 0;
|
|
410
|
+
}
|
|
411
|
+
if ("value" in r) {
|
|
412
|
+
if (!I(r.value))
|
|
413
|
+
throw new Error("常量应为有限 JSON 标量");
|
|
414
|
+
return () => r.value;
|
|
415
|
+
}
|
|
416
|
+
return pr(r, e, t, n);
|
|
417
|
+
}
|
|
418
|
+
function pr(r, e, t, n) {
|
|
419
|
+
const i = x.find((a) => a.name === r.op);
|
|
420
|
+
if (!i || !Array.isArray(r.args)) throw new Error("未知计算操作");
|
|
421
|
+
if (r.args.length > 256 || Object.keys(r.args).length !== r.args.length) throw new Error("计算参数超出预算或包含空位");
|
|
422
|
+
if (r.args.length < i.minArgs || r.args.length > i.maxArgs) throw new Error("运算参数数量不正确");
|
|
423
|
+
const c = r.op === "if" ? p(r.condition, t, n + 1) : void 0;
|
|
424
|
+
if (r.op !== "if" && r.condition !== void 0) throw new Error("仅 IF 运算接受 condition");
|
|
425
|
+
const o = r.args.map(
|
|
426
|
+
(a) => P(a, e, t, n + 1)
|
|
427
|
+
);
|
|
428
|
+
return c ? (a) => o[c(a.row) ? 0 : 1](a) : ["add", "subtract", "multiply", "divide", "coalesce"].includes(r.op) ? r.op === "coalesce" ? (a) => dr(o, a) : (a) => mr(
|
|
429
|
+
r.op,
|
|
430
|
+
o.map((s) => s(a)),
|
|
431
|
+
e
|
|
432
|
+
) : (a) => cr(r.op, o.map((s) => s(a)), e.numeric, e.digits, e.nulls);
|
|
433
|
+
}
|
|
434
|
+
function wr(r) {
|
|
435
|
+
P(r);
|
|
436
|
+
const e = /* @__PURE__ */ new Set(), t = (n) => {
|
|
437
|
+
"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), n.condition && ir(n.condition).forEach((i) => e.add(i)));
|
|
438
|
+
};
|
|
439
|
+
return t(r), [...e];
|
|
440
|
+
}
|
|
441
|
+
const hr = 16, k = 1024 * 1024, X = 5e5, v = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ Symbol("uncacheable-computation-definition");
|
|
442
|
+
function y(r, e, t = 0) {
|
|
443
|
+
if (++e.nodes > 1e4 || t > 32) throw m;
|
|
444
|
+
if (r == null) return [String(r)];
|
|
445
|
+
if (typeof r == "number") return ["number", Object.is(r, -0) ? "-0" : String(r)];
|
|
446
|
+
if (typeof r == "boolean") return ["boolean", r];
|
|
447
|
+
if (typeof r == "string") {
|
|
448
|
+
if (e.units += r.length, e.units > k) throw m;
|
|
449
|
+
return ["string", r];
|
|
450
|
+
}
|
|
451
|
+
if (typeof r != "object") throw m;
|
|
452
|
+
if (Array.isArray(r)) {
|
|
453
|
+
if (Object.getPrototypeOf(r) !== Array.prototype || Object.keys(r).length !== r.length) throw m;
|
|
454
|
+
return ["array", Array.from({ length: r.length }, (n, i) => y(W(r, String(i)), e, t + 1))];
|
|
455
|
+
}
|
|
456
|
+
if (Object.getPrototypeOf(r) !== Object.prototype && Object.getPrototypeOf(r) !== null) throw m;
|
|
457
|
+
return ["object", Object.keys(r).map((n) => [y(n, e, t + 1), y(W(r, n), e, t + 1)])];
|
|
458
|
+
}
|
|
459
|
+
function W(r, e) {
|
|
460
|
+
const t = Object.getOwnPropertyDescriptor(r, e);
|
|
461
|
+
if (!t || t.get || t.set) throw m;
|
|
462
|
+
return t.value;
|
|
463
|
+
}
|
|
464
|
+
function yr(r) {
|
|
465
|
+
try {
|
|
466
|
+
return JSON.stringify(y(r, { nodes: 0, units: 0 }));
|
|
467
|
+
} catch (e) {
|
|
468
|
+
if (e !== m) throw e;
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function kr(r) {
|
|
473
|
+
v.set(r, { programs: /* @__PURE__ */ new Map(), units: 0, slots: 0 });
|
|
474
|
+
}
|
|
475
|
+
function Yr(r, e) {
|
|
476
|
+
const t = v.get(r);
|
|
477
|
+
if (!t) return;
|
|
478
|
+
const n = { programs: /* @__PURE__ */ new Map(), units: t.units, slots: t.slots };
|
|
479
|
+
for (const [i, c] of t.programs) {
|
|
480
|
+
const o = /* @__PURE__ */ new WeakMap();
|
|
481
|
+
e.forEach((a, s) => {
|
|
482
|
+
const f = c.rows.get(r[s]);
|
|
483
|
+
f && o.set(a, f);
|
|
484
|
+
}), n.programs.set(i, { ...c, rows: o });
|
|
485
|
+
}
|
|
486
|
+
v.set(e, n);
|
|
487
|
+
}
|
|
488
|
+
function br(r, e, t) {
|
|
489
|
+
const n = v.get(r);
|
|
490
|
+
if (!n || e.some((f) => typeof f.expression == "string")) return;
|
|
491
|
+
const i = yr(e);
|
|
492
|
+
if (i === void 0 || i.length > k) return;
|
|
493
|
+
const c = n.programs.get(i);
|
|
494
|
+
if (c) return c;
|
|
495
|
+
const o = t(), a = r.length * o.reduce((f, u) => f + u.dependencies.length + 1, 0), s = { fields: o, rows: /* @__PURE__ */ new WeakMap(), slots: a, cacheRows: a <= X };
|
|
496
|
+
if (!s.cacheRows) return s;
|
|
497
|
+
for (; n.programs.size >= hr || n.units + i.length > k || n.slots + a > X; ) {
|
|
498
|
+
const f = n.programs.keys().next().value;
|
|
499
|
+
n.slots -= n.programs.get(f).slots, n.units -= f.length, n.programs.delete(f);
|
|
500
|
+
}
|
|
501
|
+
return n.programs.set(i, s), n.units += i.length, n.slots += a, s;
|
|
502
|
+
}
|
|
503
|
+
function Er(r, e, t, n) {
|
|
504
|
+
if ((t.definition.scope ?? "row") !== "row") return;
|
|
505
|
+
const i = r.program?.rows.get(e)?.get(t.definition.field);
|
|
506
|
+
return i?.dependencies.every((c, o) => Object.is(n[t.dependencies[o]], c)) ? i : void 0;
|
|
507
|
+
}
|
|
508
|
+
function Ar(r, e, t, n, i) {
|
|
509
|
+
const c = r.program;
|
|
510
|
+
if (!c?.cacheRows || (t.definition.scope ?? "row") !== "row") return;
|
|
511
|
+
let o = r.writes.get(e);
|
|
512
|
+
o || (o = new Map(c.rows.get(e)), r.writes.set(e, o), c.rows.set(e, o)), o.set(t.definition.field, {
|
|
513
|
+
dependencies: t.dependencies.map((a) => n[a]),
|
|
514
|
+
value: n[t.definition.field],
|
|
515
|
+
...i ? { issue: { field: i.field, message: i.message } } : {}
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
function vr(r) {
|
|
519
|
+
if (d(r.field), r.scope !== void 0 && !["row", "group", "dataset"].includes(r.scope))
|
|
520
|
+
throw new Error("未知计算范围");
|
|
521
|
+
if (r.numeric !== void 0 && r.numeric !== "number" && r.numeric !== "decimal")
|
|
522
|
+
throw new Error("未知数值模式");
|
|
523
|
+
if (r.digits !== void 0 && w(r.digits), r.nulls !== void 0 && r.nulls !== "propagate" && r.nulls !== "error")
|
|
524
|
+
throw new Error("未知空值规则");
|
|
525
|
+
if (r.divisionByZero !== void 0 && r.divisionByZero !== "null" && r.divisionByZero !== "error")
|
|
526
|
+
throw new Error("未知除零规则");
|
|
527
|
+
if (r.scope === "group" && (!Array.isArray(r.groupBy) || !r.groupBy.length))
|
|
528
|
+
throw new Error("分组计算需要 groupBy 字段");
|
|
529
|
+
Or(r);
|
|
530
|
+
}
|
|
531
|
+
function Or(r) {
|
|
532
|
+
if (r.groupBy !== void 0) {
|
|
533
|
+
if (!Array.isArray(r.groupBy) || r.groupBy.length > 16)
|
|
534
|
+
throw new Error("计算分组最多 16 级");
|
|
535
|
+
r.groupBy.forEach(d);
|
|
536
|
+
}
|
|
537
|
+
if (r.dependsOn !== void 0) {
|
|
538
|
+
if (!Array.isArray(r.dependsOn) || r.dependsOn.length > 2048)
|
|
539
|
+
throw new Error("计算依赖超出预算");
|
|
540
|
+
r.dependsOn.forEach(d);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
function R(r) {
|
|
544
|
+
return [
|
|
545
|
+
.../* @__PURE__ */ new Set([
|
|
546
|
+
...typeof r.expression == "string" ? r.dependsOn ?? [] : wr(r.expression),
|
|
547
|
+
...r.groupBy ?? []
|
|
548
|
+
])
|
|
549
|
+
];
|
|
550
|
+
}
|
|
551
|
+
function L(r) {
|
|
552
|
+
if (!Array.isArray(r) || r.length > 2048)
|
|
553
|
+
throw new Error("计算字段应为数组且最多2048项");
|
|
554
|
+
const e = /* @__PURE__ */ new Map();
|
|
555
|
+
for (const o of r) {
|
|
556
|
+
if (vr(o), e.has(o.field)) throw new Error(`计算字段重复:${o.field}`);
|
|
557
|
+
e.set(o.field, o);
|
|
558
|
+
}
|
|
559
|
+
const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), i = [];
|
|
560
|
+
function c(o) {
|
|
561
|
+
if (!n.has(o.field)) {
|
|
562
|
+
if (t.has(o.field))
|
|
563
|
+
throw new Error(
|
|
564
|
+
`计算字段存在循环依赖:${[...t, o.field].join(" → ")}`
|
|
565
|
+
);
|
|
566
|
+
t.add(o.field);
|
|
567
|
+
for (const a of R(o)) {
|
|
568
|
+
const s = e.get(a);
|
|
569
|
+
s && c(s);
|
|
570
|
+
}
|
|
571
|
+
t.delete(o.field), n.add(o.field), i.push(o);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return r.forEach(c), i;
|
|
575
|
+
}
|
|
576
|
+
function Ir(r) {
|
|
577
|
+
try {
|
|
578
|
+
const e = L(r);
|
|
579
|
+
return {
|
|
580
|
+
valid: !0,
|
|
581
|
+
errors: [],
|
|
582
|
+
order: e.map((t) => t.field),
|
|
583
|
+
fields: r.map((t) => ({
|
|
584
|
+
field: t.field,
|
|
585
|
+
dependencies: R(t),
|
|
586
|
+
scope: t.scope ?? "row"
|
|
587
|
+
}))
|
|
588
|
+
};
|
|
589
|
+
} catch (e) {
|
|
590
|
+
return {
|
|
591
|
+
valid: !1,
|
|
592
|
+
errors: [e instanceof Error ? e.message : String(e)],
|
|
593
|
+
fields: [],
|
|
594
|
+
order: []
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function Pr(r = []) {
|
|
599
|
+
return {
|
|
600
|
+
fields: r.map((e) => ({ ...e })),
|
|
601
|
+
functions: x,
|
|
602
|
+
operations: x.map((e) => e.name),
|
|
603
|
+
aggregates: ["sum", "count", "avg", "min", "max", "weightedAvg"],
|
|
604
|
+
scopes: ["row", "group", "dataset"],
|
|
605
|
+
numericModes: ["number", "decimal"],
|
|
606
|
+
rules: {
|
|
607
|
+
nulls: "propagate",
|
|
608
|
+
aggregateNulls: "skip",
|
|
609
|
+
emptyAggregate: null,
|
|
610
|
+
countEmpty: 0,
|
|
611
|
+
divisionByZero: "error",
|
|
612
|
+
decimalOutput: "string",
|
|
613
|
+
rounding: "half-away-from-zero"
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
function z(r) {
|
|
618
|
+
return L(r.fields).map((e) => {
|
|
619
|
+
const t = R(e);
|
|
620
|
+
if (typeof e.expression != "string")
|
|
621
|
+
return {
|
|
622
|
+
definition: e,
|
|
623
|
+
dependencies: t,
|
|
624
|
+
read: P(e.expression, e)
|
|
625
|
+
};
|
|
626
|
+
if (!r.formula)
|
|
627
|
+
throw new Error("字符串公式需要显式配置 formula adapter");
|
|
628
|
+
const n = e.expression;
|
|
629
|
+
return {
|
|
630
|
+
definition: e,
|
|
631
|
+
dependencies: t,
|
|
632
|
+
read: (i) => r.formula.evaluate(n, i)
|
|
633
|
+
};
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
function Sr(r, e) {
|
|
637
|
+
return JSON.stringify(
|
|
638
|
+
e.map((t) => {
|
|
639
|
+
const n = Object.prototype.hasOwnProperty.call(r, t) ? r[t] : null;
|
|
640
|
+
if (n != null && !I(n))
|
|
641
|
+
throw new Error("分组字段应为有限 JSON 标量");
|
|
642
|
+
return [typeof n, n ?? null];
|
|
643
|
+
})
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
function Nr(r, e) {
|
|
647
|
+
if (e.scope === "dataset") return () => r;
|
|
648
|
+
if (e.scope !== "group") {
|
|
649
|
+
const i = /* @__PURE__ */ new WeakMap();
|
|
650
|
+
return (c) => {
|
|
651
|
+
let o = i.get(c);
|
|
652
|
+
return o || (o = [c], i.set(c, o)), o;
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new WeakMap();
|
|
656
|
+
for (const i of r) {
|
|
657
|
+
const c = Sr(i, e.groupBy);
|
|
658
|
+
n.set(i, c);
|
|
659
|
+
const o = t.get(c);
|
|
660
|
+
o ? o.push(i) : t.set(c, [i]);
|
|
661
|
+
}
|
|
662
|
+
return (i) => t.get(n.get(i));
|
|
663
|
+
}
|
|
664
|
+
function Mr(r, e) {
|
|
665
|
+
const t = e.maxRows ?? 1e5, n = e.maxCells ?? 2e6;
|
|
666
|
+
if (!Array.isArray(r) || !Number.isSafeInteger(t) || t < 1 || r.length > t)
|
|
667
|
+
throw new Error("计算数据行数超出预算或输入不是数组");
|
|
668
|
+
if (!Array.isArray(e.fields) || e.fields.length > 2048)
|
|
669
|
+
throw new Error("计算字段应为数组且最多2048项");
|
|
670
|
+
if (!Number.isSafeInteger(n) || n < 1 || r.length * e.fields.length > n)
|
|
671
|
+
throw new Error("计算单元格超出 maxCells 预算");
|
|
672
|
+
}
|
|
673
|
+
function G(r) {
|
|
674
|
+
if (r?.aborted) {
|
|
675
|
+
const e = new Error("数据计算已取消");
|
|
676
|
+
throw e.name = "AbortError", e;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function Dr(r, e, t, n, i, c) {
|
|
680
|
+
try {
|
|
681
|
+
const o = r.read({ row: e, rowIndex: t, rows: n });
|
|
682
|
+
if (o !== void 0 && !I(o))
|
|
683
|
+
throw new Error("计算结果应为有限 JSON 标量,异步公式请先在数据源中求值");
|
|
684
|
+
e[r.definition.field] = o ?? null;
|
|
685
|
+
} catch (o) {
|
|
686
|
+
const a = o instanceof Error ? o.message : String(o);
|
|
687
|
+
if (i.onError !== "null")
|
|
688
|
+
throw Object.assign(
|
|
689
|
+
new Error(`第 ${t + 1} 行 ${r.definition.field}:${a}`),
|
|
690
|
+
{ cause: o }
|
|
691
|
+
);
|
|
692
|
+
e[r.definition.field] = null, c.push({ rowIndex: t, field: r.definition.field, message: a });
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
function jr(r, e, t, n, i, c, o, a) {
|
|
696
|
+
const s = Er(r, e, t, n);
|
|
697
|
+
if (s && (!s.issue || o.onError === "null")) {
|
|
698
|
+
n[t.definition.field] = s.value, s.issue && a.push({ ...s.issue, rowIndex: i });
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
const f = a.length;
|
|
702
|
+
Dr(t, n, i, c, o, a), Ar(r, e, t, n, a.length > f ? a[a.length - 1] : void 0);
|
|
703
|
+
}
|
|
704
|
+
function Rr(r, e) {
|
|
705
|
+
Mr(r, e), G(e.signal);
|
|
706
|
+
const t = br(r, e.fields, () => z(e)), n = { program: t, writes: /* @__PURE__ */ new WeakMap() }, i = t?.fields ?? z(e), c = [], o = r.map((a, s) => {
|
|
707
|
+
if (!a || typeof a != "object" || Array.isArray(a))
|
|
708
|
+
throw new Error(`第 ${s + 1} 行应为对象`);
|
|
709
|
+
return { ...a };
|
|
710
|
+
});
|
|
711
|
+
for (const a of i) {
|
|
712
|
+
const s = Nr(o, a.definition);
|
|
713
|
+
o.forEach((f, u) => {
|
|
714
|
+
G(e.signal), jr(n, r[u], a, f, u, s(f), e, c);
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
return { rows: o, issues: c };
|
|
718
|
+
}
|
|
719
|
+
export {
|
|
720
|
+
E as a,
|
|
721
|
+
$ as b,
|
|
722
|
+
rr as c,
|
|
723
|
+
b as d,
|
|
724
|
+
Rr as e,
|
|
725
|
+
w as f,
|
|
726
|
+
j as g,
|
|
727
|
+
Fr as h,
|
|
728
|
+
Pr as i,
|
|
729
|
+
S as j,
|
|
730
|
+
p as k,
|
|
731
|
+
xr as l,
|
|
732
|
+
Y as m,
|
|
733
|
+
d as n,
|
|
734
|
+
Yr as o,
|
|
735
|
+
l as p,
|
|
736
|
+
kr as q,
|
|
737
|
+
ir as r,
|
|
738
|
+
Ir as v
|
|
739
|
+
};
|