@agile-team/mach-report 2.10.0 → 2.11.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 +6 -2
- package/dist/ExcelBindingWizard-CjIiVox-.cjs +1 -0
- package/dist/ExcelBindingWizard-Dxm-K5HL.js +1240 -0
- package/dist/ParamEditor-D-Hf5xfO.cjs +1 -0
- package/dist/ParamEditor-DRGxzxeO.js +381 -0
- package/dist/ReportBatchPanel-BYgg0EDB.cjs +1 -0
- package/dist/ReportBatchPanel-Bby5yLzU.js +287 -0
- package/dist/ReportPreview-DWXROHBP.cjs +6 -0
- package/dist/ReportPreview-DiNXhQI0.js +4138 -0
- package/dist/ReportTemplateLibrary-C6CO7YCT.cjs +1 -0
- package/dist/ReportTemplateLibrary-DfzDXRvr.js +260 -0
- package/dist/RuleEditor-C2QsOHOs.cjs +1 -0
- package/dist/RuleEditor-D9wQHrkf.js +2024 -0
- package/dist/TemplateReviewPanel-BKofGrV9.js +222 -0
- package/dist/TemplateReviewPanel-DwtOcLue.cjs +1 -0
- package/dist/analytics.cjs +1 -1
- package/dist/analytics.d.cts +2 -0
- package/dist/analytics.d.ts +2 -0
- package/dist/analytics.js +29 -29
- package/dist/batch-Bt3Fd27Z.cjs +1 -0
- package/dist/batch-mRqhhhjt.js +364 -0
- package/dist/computed-Bvk0W15F.js +521 -0
- package/dist/computed-CGV2a809.cjs +1 -0
- package/dist/config-B612mw0x.js +525 -0
- package/dist/config-BRoLo2oj.cjs +1 -0
- package/dist/designer.cjs +2 -2
- package/dist/designer.d.cts +659 -9
- package/dist/designer.d.ts +659 -9
- package/dist/designer.js +2030 -1824
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +147 -3
- package/dist/index.d.ts +147 -3
- package/dist/index.js +639 -592
- package/dist/injection-keys-Db_DyLkm.cjs +1 -0
- package/dist/injection-keys-e85udZCp.js +7 -0
- package/dist/list-cell-BuYn4tGF.cjs +1 -0
- package/dist/{list-cell-Dxyi7DOw.js → list-cell-ClFra1zS.js} +54 -40
- package/dist/matrix-DVyWiYsd.cjs +1 -0
- package/dist/matrix-yZsGnldA.js +227 -0
- package/dist/param-validation-BlHHXs6u.js +153 -0
- package/dist/param-validation-DCK039V1.cjs +1 -0
- package/dist/pdf.cjs +25 -25
- package/dist/pdf.d.cts +3 -0
- package/dist/pdf.d.ts +3 -0
- package/dist/pdf.js +677 -677
- package/dist/plugin-BDTU4D94.cjs +1 -0
- package/dist/plugin-Cd5G2QQn.js +22 -0
- package/dist/region-binding-workflow-CXDmt9Bs.js +977 -0
- package/dist/region-binding-workflow-DhQvu1co.cjs +3 -0
- package/dist/{report-params-B_VCihAh.js → report-params-B44imUd4.js} +1 -1
- package/dist/{report-params-CjWrjPl6.cjs → report-params-SJfhKgaX.cjs} +1 -1
- package/dist/server/node.d.cts +5 -2
- package/dist/server/node.d.ts +5 -2
- package/dist/server-node.cjs +1 -1
- package/dist/server-node.js +87 -87
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +201 -2
- package/dist/server.d.ts +201 -2
- package/dist/server.js +557 -658
- package/dist/style.css +1 -1
- package/dist/template-registry-WNXdkiET.js +506 -0
- package/dist/template-registry-ukBGlm8N.cjs +1 -0
- package/dist/template-review-BXp2oyqg.cjs +1 -0
- package/dist/template-review-BdcXSYbx.js +1616 -0
- package/dist/tree-BX380Rr7.cjs +1 -0
- package/dist/tree-CqcQ99NM.js +172 -0
- package/dist/{validate-UUy9yP4K.js → validate-7s0yn6ii.js} +44 -44
- package/dist/validate-DsRiNw8h.cjs +1 -0
- package/dist/vue/async.d.cts +93 -4
- package/dist/vue/async.d.ts +93 -4
- package/dist/vue/index.d.cts +145 -7
- package/dist/vue/index.d.ts +145 -7
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +5 -5
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +116 -113
- package/dist/{workbook-session-B-bW5_yR.js → workbook-session-BKOTwcoq.js} +1 -1
- package/dist/{workbook-session-D7RtdNo0.cjs → workbook-session-CLYLhZWu.cjs} +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +5 -2
- package/dist/worker.d.ts +5 -2
- package/dist/worker.js +1 -1
- package/dist/xlsx.cjs +3 -3
- package/dist/xlsx.d.cts +129 -2
- package/dist/xlsx.d.ts +129 -2
- package/dist/xlsx.js +336 -242
- package/package.json +1 -1
- package/dist/ExcelBindingWizard-CF7RplWm.cjs +0 -1
- package/dist/ExcelBindingWizard-qhwEderR.js +0 -842
- package/dist/ReportPreview-BE1tCHqE.js +0 -4604
- package/dist/ReportPreview-QKRKQOe3.cjs +0 -6
- package/dist/RuleEditor-BA36yIV6.js +0 -1723
- package/dist/RuleEditor-CczJ6mJm.cjs +0 -1
- package/dist/TemplateReviewPanel-CHi4Alqa.cjs +0 -1
- package/dist/TemplateReviewPanel-Dz0G5o83.js +0 -217
- package/dist/binding-preview-BWsdf_z2.cjs +0 -2
- package/dist/binding-preview-DILq0-0f.js +0 -649
- package/dist/decimal-CI1OAczk.js +0 -87
- package/dist/decimal-CQA0xJex.cjs +0 -1
- package/dist/list-cell-CyM1ZlRN.cjs +0 -1
- package/dist/matrix-BbXarwyk.js +0 -661
- package/dist/matrix-Cm65WLLP.cjs +0 -1
- package/dist/param-validation-BWNjLcN0.js +0 -116
- package/dist/param-validation-CiTxFeZ8.cjs +0 -1
- package/dist/plugin-CThk42vJ.cjs +0 -1
- package/dist/plugin-tGn7-5oF.js +0 -25
- package/dist/template-registry-CGWTLtIA.cjs +0 -1
- package/dist/template-registry-DzlQs3OF.js +0 -434
- package/dist/template-review-D1RoNCPw.cjs +0 -1
- package/dist/template-review-fnteXRng.js +0 -1473
- package/dist/validate-Bf6ccFr2.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const E="mach-report/fetcher",R="mach-report/pdf-exporter",_="mach-report/config",O="mach-report/controller";exports.MACH_REPORT_CONFIG_KEY=_;exports.MACH_REPORT_CONTROLLER_KEY=O;exports.MACH_REPORT_FETCHER_KEY=E;exports.MACH_REPORT_PDF_EXPORTER_KEY=R;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const m=require("./defaults-xhmcLLrf.cjs"),o=require("./computed-CGV2a809.cjs"),l=require("./style-UgIJSA1F.cjs");function b(e){if(!e||e.kind==="date")return;const t=e.digits;if(!(t!==void 0&&(!Number.isInteger(t)||t<0||t>100))){if(e.kind==="percent"){const r=t??2;return`0${r?`.${"0".repeat(r)}`:""}%`}return t===void 0?e.thousands?"#,##0.###############":void 0:`${e.thousands?"#,##0":"0"}${t?`.${"0".repeat(t)}`:""}`}}function y(e){const t=/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());if(t){const n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));return Number.isNaN(n.getTime())?null:n}const r=new Date(e);return Number.isNaN(r.getTime())?null:r}function f(e,t){return e.toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t})}function M(e,t){const r=n=>String(n).padStart(2,"0");return t.replace(/YYYY/g,String(e.getFullYear())).replace(/MM/g,r(e.getMonth()+1)).replace(/DD/g,r(e.getDate())).replace(/hh/g,r(e.getHours())).replace(/mm/g,r(e.getMinutes())).replace(/ss/g,r(e.getSeconds()))}function L(e,t,r){return r!=null?t?f(e,r):e.toFixed(r):t?f(e):String(e)}function c(e){const t=typeof e=="number"?e:Number(String(e).replace(/,/g,""));return Number.isFinite(t)?t:null}function S(e,t){if(e==null||e===""||!t)return String(e??"");switch(t.kind){case"number":{if(typeof e=="string")try{return o.formatDecimal(e,t.digits,t.thousands===!0)}catch{return e}const r=c(e);return r==null?String(e):L(r,t.thousands===!0,t.digits)}case"percent":{if(typeof e=="string")try{return o.formatDecimal(e,t.digits??2,!0,!0)}catch{return e}const r=c(e);return r==null?String(e):`${f(r*100,t.digits??2)}%`}case"date":{const r=t.pattern??"YYYY-MM-DD",n=e instanceof Date?e:y(String(e));return n?M(n,r):String(e)}default:return String(e)}}function g(e,t){const r=e[t.field];if(r==null||r==="")return!1;if(typeof t.value=="number"||t.numeric!==void 0){let s;try{s=o.compareDecimal(o.parseDecimal(r),o.parseDecimal(t.value))}catch{return!1}if(!Number.isFinite(s))return!1;switch(t.op){case">":return s>0;case">=":return s>=0;case"<":return s<0;case"<=":return s<=0;case"==":return s===0;case"!=":return s!==0}}const n=String(r),i=String(t.value);switch(t.op){case"==":return n===i;case"!=":return n!==i;case">":return n>i;case">=":return n>=i;case"<":return n<i;case"<=":return n<=i}return!1}function h(e,t,r,n=e.paddingMm??1){return t.field!==e.tree.labelField?0:Math.min(r.depth*(e.tree.indentMm??3),Math.max(0,t.widthMm-n*2-4))}function N(e,t,r,n){const i=n.tree;(i.input==="nested"||[i.idField,i.parentField].includes(t.field))&&(e.editable=!1),r.hasChildren&&i.parentValues==="leaf-aggregate"&&i.aggregates?.some(s=>s.field===t.field)&&(e.derived=!0,e.editable=!1)}function D(e,t,r){return r==="identifier"||r==="dimension"||r==="date"?"center":r==="measure"?"right":r==="text"?"left":t?.kind==="number"||t?.kind==="percent"?"right":t?.kind==="date"||e instanceof Date||typeof e=="boolean"?"center":typeof e=="number"&&Number.isFinite(e)?"right":"left"}function T(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number")return String(e);if(typeof e=="boolean")return e?"是":"否";if(e instanceof Date)return e.toISOString().slice(0,10);try{return JSON.stringify(e)}catch{return String(e)}}function C(e,t){let r=l.mergeComponentStyles({fontSize:e.fontSizePt??m.DEFAULT_FONT_PT,bold:e.headerBold??!0,align:"center",verticalAlign:"middle",backgroundColor:e.headerBackgroundColor},t.style);return e.headerAlign!==void 0&&(r.align=e.headerAlign),r=l.mergeComponentStyles(r,e.headerStyle),t.headerAlign!==void 0&&(r.align=t.headerAlign),l.mergeComponentStyles(r,t.headerStyle)}function A(e,t,r){(r===null||typeof r=="string"||typeof r=="boolean"||typeof r=="number"&&Number.isFinite(r))&&(e.value=r);const n=t.format?.kind==="number"||t.format?.kind==="percent";t.valueType!==void 0?e.valueType=t.valueType:n&&(e.valueType="number"),t.editable!==void 0&&(e.editable=t.editable);const i=b(t.format);(typeof e.value=="number"||e.value==null)&&i!==void 0&&(e.numberFormat=i)}function F(e,t,r){const n=!!t.visibleWhen&&!g(r,t.visibleWhen),i=n?null:r[t.field],s=t.align??t.style?.align??e.align??"left";let d=l.mergeComponentStyles({fontSize:e.fontSizePt??m.DEFAULT_FONT_PT,verticalAlign:"middle"},t.style);d.align=s==="auto"?D(i,t.format,t.semanticRole):s;const p=t.rules?.find(u=>g(r,u.when));p&&(d=l.mergeComponentStyles(d,p.style));const a={text:t.format?S(i,t.format):T(i),style:d};return A(a,t,i),e.computed?.some(u=>u.field===t.field)&&(a.derived=!0,a.editable=!1),n&&(a.editable=!1),a}function k(e,t,r){const n=F(e,t,r.row),i=h(e,t,r);return t.field===e.tree.labelField&&(n.style={...n.style,align:"left"}),i&&(n.indentMm=i),N(n,t,r,e),n}exports.applyListTreeMetadata=N;exports.evalStyleRule=g;exports.formatValue=S;exports.listCellText=T;exports.listTreeIndent=h;exports.parseDateLocal=y;exports.resolveListAutoAlignment=D;exports.resolveListHeaderStyle=C;exports.resolveListSampleCell=F;exports.resolveTreeListSampleCell=k;exports.toExcelNumberFormat=b;exports.toNumber=c;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as b } from "./defaults-DXhiM1ZD.js";
|
|
2
|
-
import { c as y, p as
|
|
3
|
-
import { e as
|
|
4
|
-
function
|
|
2
|
+
import { c as y, p as l, h as g } from "./computed-Bvk0W15F.js";
|
|
3
|
+
import { e as f } from "./style-CQ1PK8ZB.js";
|
|
4
|
+
function h(e) {
|
|
5
5
|
if (!e || e.kind === "date") return;
|
|
6
6
|
const t = e.digits;
|
|
7
7
|
if (!(t !== void 0 && (!Number.isInteger(t) || t < 0 || t > 100))) {
|
|
@@ -12,7 +12,7 @@ function S(e) {
|
|
|
12
12
|
return t === void 0 ? e.thousands ? "#,##0.###############" : void 0 : `${e.thousands ? "#,##0" : "0"}${t ? `.${"0".repeat(t)}` : ""}`;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function S(e) {
|
|
16
16
|
const t = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());
|
|
17
17
|
if (t) {
|
|
18
18
|
const n = new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3]));
|
|
@@ -21,7 +21,7 @@ function h(e) {
|
|
|
21
21
|
const r = new Date(e);
|
|
22
22
|
return Number.isNaN(r.getTime()) ? null : r;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function o(e, t) {
|
|
25
25
|
return e.toLocaleString("en-US", {
|
|
26
26
|
minimumFractionDigits: t,
|
|
27
27
|
maximumFractionDigits: t
|
|
@@ -32,7 +32,7 @@ function N(e, t) {
|
|
|
32
32
|
return t.replace(/YYYY/g, String(e.getFullYear())).replace(/MM/g, r(e.getMonth() + 1)).replace(/DD/g, r(e.getDate())).replace(/hh/g, r(e.getHours())).replace(/mm/g, r(e.getMinutes())).replace(/ss/g, r(e.getSeconds()));
|
|
33
33
|
}
|
|
34
34
|
function D(e, t, r) {
|
|
35
|
-
return r != null ? t ?
|
|
35
|
+
return r != null ? t ? o(e, r) : e.toFixed(r) : t ? o(e) : String(e);
|
|
36
36
|
}
|
|
37
37
|
function p(e) {
|
|
38
38
|
const t = typeof e == "number" ? e : Number(String(e).replace(/,/g, ""));
|
|
@@ -44,7 +44,7 @@ function F(e, t) {
|
|
|
44
44
|
case "number": {
|
|
45
45
|
if (typeof e == "string")
|
|
46
46
|
try {
|
|
47
|
-
return
|
|
47
|
+
return g(e, t.digits, t.thousands === !0);
|
|
48
48
|
} catch {
|
|
49
49
|
return e;
|
|
50
50
|
}
|
|
@@ -54,15 +54,15 @@ function F(e, t) {
|
|
|
54
54
|
case "percent": {
|
|
55
55
|
if (typeof e == "string")
|
|
56
56
|
try {
|
|
57
|
-
return
|
|
57
|
+
return g(e, t.digits ?? 2, !0, !0);
|
|
58
58
|
} catch {
|
|
59
59
|
return e;
|
|
60
60
|
}
|
|
61
61
|
const r = p(e);
|
|
62
|
-
return r == null ? String(e) : `${
|
|
62
|
+
return r == null ? String(e) : `${o(r * 100, t.digits ?? 2)}%`;
|
|
63
63
|
}
|
|
64
64
|
case "date": {
|
|
65
|
-
const r = t.pattern ?? "YYYY-MM-DD", n = e instanceof Date ? e :
|
|
65
|
+
const r = t.pattern ?? "YYYY-MM-DD", n = e instanceof Date ? e : S(String(e));
|
|
66
66
|
return n ? N(n, r) : String(e);
|
|
67
67
|
}
|
|
68
68
|
default:
|
|
@@ -73,26 +73,26 @@ function m(e, t) {
|
|
|
73
73
|
const r = e[t.field];
|
|
74
74
|
if (r == null || r === "") return !1;
|
|
75
75
|
if (typeof t.value == "number" || t.numeric !== void 0) {
|
|
76
|
-
let
|
|
76
|
+
let a;
|
|
77
77
|
try {
|
|
78
|
-
|
|
78
|
+
a = y(l(r), l(t.value));
|
|
79
79
|
} catch {
|
|
80
80
|
return !1;
|
|
81
81
|
}
|
|
82
|
-
if (!Number.isFinite(
|
|
82
|
+
if (!Number.isFinite(a)) return !1;
|
|
83
83
|
switch (t.op) {
|
|
84
84
|
case ">":
|
|
85
|
-
return
|
|
85
|
+
return a > 0;
|
|
86
86
|
case ">=":
|
|
87
|
-
return
|
|
87
|
+
return a >= 0;
|
|
88
88
|
case "<":
|
|
89
|
-
return
|
|
89
|
+
return a < 0;
|
|
90
90
|
case "<=":
|
|
91
|
-
return
|
|
91
|
+
return a <= 0;
|
|
92
92
|
case "==":
|
|
93
|
-
return
|
|
93
|
+
return a === 0;
|
|
94
94
|
case "!=":
|
|
95
|
-
return
|
|
95
|
+
return a !== 0;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
const n = String(r), i = String(t.value);
|
|
@@ -112,10 +112,17 @@ function m(e, t) {
|
|
|
112
112
|
}
|
|
113
113
|
return !1;
|
|
114
114
|
}
|
|
115
|
-
function
|
|
115
|
+
function M(e, t, r, n = e.paddingMm ?? 1) {
|
|
116
|
+
return t.field !== e.tree.labelField ? 0 : Math.min(r.depth * (e.tree.indentMm ?? 3), Math.max(0, t.widthMm - n * 2 - 4));
|
|
117
|
+
}
|
|
118
|
+
function T(e, t, r, n) {
|
|
119
|
+
const i = n.tree;
|
|
120
|
+
(i.input === "nested" || [i.idField, i.parentField].includes(t.field)) && (e.editable = !1), r.hasChildren && i.parentValues === "leaf-aggregate" && i.aggregates?.some((a) => a.field === t.field) && (e.derived = !0, e.editable = !1);
|
|
121
|
+
}
|
|
122
|
+
function k(e, t, r) {
|
|
116
123
|
return r === "identifier" || r === "dimension" || r === "date" ? "center" : r === "measure" ? "right" : r === "text" ? "left" : t?.kind === "number" || t?.kind === "percent" ? "right" : t?.kind === "date" || e instanceof Date || typeof e == "boolean" ? "center" : typeof e == "number" && Number.isFinite(e) ? "right" : "left";
|
|
117
124
|
}
|
|
118
|
-
function
|
|
125
|
+
function x(e) {
|
|
119
126
|
if (e == null) return "";
|
|
120
127
|
if (typeof e == "string" || typeof e == "number") return String(e);
|
|
121
128
|
if (typeof e == "boolean") return e ? "是" : "否";
|
|
@@ -126,34 +133,41 @@ function k(e) {
|
|
|
126
133
|
return String(e);
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
|
-
function
|
|
130
|
-
let r =
|
|
131
|
-
return e.headerAlign !== void 0 && (r.align = e.headerAlign), r =
|
|
136
|
+
function z(e, t) {
|
|
137
|
+
let r = f({ fontSize: e.fontSizePt ?? b, bold: e.headerBold ?? !0, align: "center", verticalAlign: "middle", backgroundColor: e.headerBackgroundColor }, t.style);
|
|
138
|
+
return e.headerAlign !== void 0 && (r.align = e.headerAlign), r = f(r, e.headerStyle), t.headerAlign !== void 0 && (r.align = t.headerAlign), f(r, t.headerStyle);
|
|
132
139
|
}
|
|
133
140
|
function A(e, t, r) {
|
|
134
141
|
(r === null || typeof r == "string" || typeof r == "boolean" || typeof r == "number" && Number.isFinite(r)) && (e.value = r);
|
|
135
142
|
const n = t.format?.kind === "number" || t.format?.kind === "percent";
|
|
136
143
|
t.valueType !== void 0 ? e.valueType = t.valueType : n && (e.valueType = "number"), t.editable !== void 0 && (e.editable = t.editable);
|
|
137
|
-
const i =
|
|
144
|
+
const i = h(t.format);
|
|
138
145
|
(typeof e.value == "number" || e.value == null) && i !== void 0 && (e.numberFormat = i);
|
|
139
146
|
}
|
|
140
|
-
function
|
|
141
|
-
const n = !!t.visibleWhen && !m(r, t.visibleWhen), i = n ? null : r[t.field],
|
|
142
|
-
let
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
return A(
|
|
147
|
+
function Y(e, t, r) {
|
|
148
|
+
const n = !!t.visibleWhen && !m(r, t.visibleWhen), i = n ? null : r[t.field], a = t.align ?? t.style?.align ?? e.align ?? "left";
|
|
149
|
+
let d = f({ fontSize: e.fontSizePt ?? b, verticalAlign: "middle" }, t.style);
|
|
150
|
+
d.align = a === "auto" ? k(i, t.format, t.semanticRole) : a;
|
|
151
|
+
const c = t.rules?.find((u) => m(r, u.when));
|
|
152
|
+
c && (d = f(d, c.style));
|
|
153
|
+
const s = { text: t.format ? F(i, t.format) : x(i), style: d };
|
|
154
|
+
return A(s, t, i), e.computed?.some((u) => u.field === t.field) && (s.derived = !0, s.editable = !1), n && (s.editable = !1), s;
|
|
155
|
+
}
|
|
156
|
+
function P(e, t, r) {
|
|
157
|
+
const n = Y(e, t, r.row), i = M(e, t, r);
|
|
158
|
+
return t.field === e.tree.labelField && (n.style = { ...n.style, align: "left" }), i && (n.indentMm = i), T(n, t, r, e), n;
|
|
148
159
|
}
|
|
149
160
|
export {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
161
|
+
P as a,
|
|
162
|
+
z as b,
|
|
163
|
+
p as c,
|
|
164
|
+
k as d,
|
|
153
165
|
m as e,
|
|
154
166
|
F as f,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
S as
|
|
167
|
+
M as g,
|
|
168
|
+
T as h,
|
|
169
|
+
x as l,
|
|
170
|
+
S as p,
|
|
171
|
+
Y as r,
|
|
172
|
+
h as t
|
|
159
173
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const A=require("./computed-CGV2a809.cjs");function g(r,e){return Object.prototype.hasOwnProperty.call(r,e)?r[e]:void 0}function x(r){if(r==null)return"null";if(typeof r!="string"&&typeof r!="boolean"&&!(typeof r=="number"&&Number.isFinite(r)))throw new Error("交叉表维度应为字符串、布尔、有限数字或空值");return JSON.stringify([typeof r,r])}function E(r){return r==null?"":String(r)}function b(r,e){const l=r??e;if(!Number.isInteger(l)||l<1)throw new Error("交叉表预算应为正整数");return l}function O(r,e,l,t){const m=l?1:0;if((r+m)*(e+1+m)>t)throw new Error("交叉表输出单元格超出 maxCells 预算,请减少维度或服务端预聚合")}function M(r,e){if(!Array.isArray(r))throw new Error("交叉表数据应为对象数组");const l=e.aggregate??"sum";if(!["sum","count","avg","min","max","weightedAvg"].includes(l))throw new Error("未知交叉表聚合类型");if(!e.rowField||!e.columnField||l!=="count"&&!e.valueField)throw new Error("交叉表需要明确的行维度、列维度和度量字段");if(r.length>b(e.maxInputRows,1e5))throw new Error("交叉表输入超出预算,请在服务端预聚合");const t=b(e.maxRows,1e3),m=b(e.maxColumns,200),w=b(e.maxCells,2e6),i=()=>A.createAggregateAccumulator({op:l,field:l==="count"&&e.countMode!=="nonNull"?void 0:e.valueField,weightField:e.weightField,numeric:e.numeric,digits:e.digits}),c=new Map,u=new Map,d=new Map,h=i();for(const n of r){const s=x(g(n,e.rowField)),o=x(g(n,e.columnField));if(c.has(o)||c.set(o,E(g(n,e.columnField))),u.has(s)||u.set(s,{label:E(g(n,e.rowField)),cells:new Map,total:i()}),c.size>m||u.size>t)throw new Error("交叉表维度数量超出预算");O(u.size,c.size,e.totals,w);const f=u.get(s);f.cells.has(o)||f.cells.set(o,i()),d.has(o)||d.set(o,i());for(const F of[f.cells.get(o),f.total,d.get(o),h])F.add(n)}const a={columns:[{header:e.rowHeader??e.rowField,field:"rowLabel",semanticRole:"dimension"},...[...c.values()].map((n,s)=>({header:n,field:`c${s}`,semanticRole:"measure"}))],rows:[...u.values()].map(n=>({rowLabel:n.label,...Object.fromEntries([...c.keys()].map((s,o)=>[`c${o}`,n.cells.get(s)?.value()??(l==="count"?0:null)])),...e.totals?{total:n.total.value()}:{}}))};return e.totals&&(a.columns.push({header:"合计",field:"total",semanticRole:"measure"}),r.length&&a.rows.push({rowLabel:"合计",...Object.fromEntries([...c.keys()].map((n,s)=>[`c${s}`,d.get(n)?.value()??(l==="count"?0:null)])),total:h.value()})),a}function y(r,e){const l=e.map(t=>Object.prototype.hasOwnProperty.call(r,t)?r[t]:null);if(l.some(t=>t!=null&&typeof t!="string"&&typeof t!="boolean"&&!(typeof t=="number"&&Number.isFinite(t))))throw new Error("矩阵维度必须是有限 JSON 标量");return{key:JSON.stringify(l.map(t=>[typeof t,t??null])),label:l.map(t=>t==null?"":String(t)).join(" / ")}}function R(r){for(const e of["maxRows","maxColumns","maxInputRows","maxCells"])if(r[e]!==void 0&&(!Number.isSafeInteger(r[e])||r[e]<1))throw new Error("矩阵预算应为正安全整数");for(const e of["columnWidthMm","rowWidthMm"])if(r[e]!==void 0&&(!Number.isFinite(r[e])||r[e]<=0))throw new Error("矩阵列宽应为正数")}function N(r){if(!r||!Array.isArray(r.rowFields)||!Array.isArray(r.columnFields)||!Array.isArray(r.measures))throw new Error("矩阵需要行维度、列维度和度量数组");for(const l of[r.rowFields,r.columnFields])if(l.some(t=>typeof t!="string"||!t.trim())||new Set(l).size!==l.length)throw new Error("矩阵维度字段应非空且唯一");if(R(r),!r.rowFields.length||!r.columnFields.length||r.rowFields.length>16||r.columnFields.length>16)throw new Error("矩阵需要 1–16 个行/列维度");if(!r.measures.length||r.measures.length>32)throw new Error("矩阵需要 1–32 个度量");if(r.measures.map(l=>{if(!l||typeof l!="object")throw new Error("矩阵度量应为对象");if(A.createAggregateAccumulator({...l,field:l.valueField??l.field}),l.label!==void 0&&typeof l.label!="string")throw new Error("矩阵度量标签应为字符串");return l.field}).some(l=>typeof l!="string"||!l.trim()))throw new Error("矩阵度量字段应非空")}function k(r,e){if(N(e),!Array.isArray(r)||r.length>(e.maxInputRows??1e5))throw new Error("矩阵输入超出预算");const l=new Set,t=new Set;for(const i of r){if(!i||typeof i!="object"||Array.isArray(i))throw new Error("矩阵数据行应为对象");if(l.add(y(i,e.rowFields).key),t.add(y(i,e.columnFields).key),l.size>(e.maxRows??1e3)||t.size>(e.maxColumns??200))throw new Error("矩阵维度数量超出预算");if((l.size+ +!!e.totals)*((t.size+ +!!e.totals)*e.measures.length+1)>(e.maxCells??2e6))throw new Error("矩阵输出超出 maxCells 预算")}const m=l.size+ +(!!e.totals&&r.length>0),w=(t.size+ +!!e.totals)*e.measures.length+1;return{rowCount:m,columnCount:w,cells:m*w}}function C(r,e){let l=e;for(;r.some(t=>Object.prototype.hasOwnProperty.call(t,l));)l+="_";return l}function L(r,e){k(r,e);const l=new Map,t=new Map,m=C(r,"__matrix_row"),w=C(r,"__matrix_column"),i=r.map(a=>{const n=y(a,e.rowFields),s=y(a,e.columnFields);return l.set(n.key,n.label),t.set(s.key,s.label),{...a,[m]:n.key,[w]:s.key}}),c=e.maxCells??2e6;if((l.size+ +!!e.totals)*((t.size+ +!!e.totals)*e.measures.length+1)>c)throw new Error("矩阵输出超出 maxCells 预算");const u=e.measures.map(a=>M(i,{rowField:m,columnField:w,valueField:a.valueField??a.field,aggregate:a.op,countMode:"nonNull",weightField:a.weightField,numeric:a.numeric,digits:a.digits,totals:e.totals,maxRows:e.maxRows,maxColumns:e.maxColumns,maxInputRows:e.maxInputRows,maxCells:c})),d=u[0].rows.map(a=>({rowLabel:l.get(String(a.rowLabel))??String(a.rowLabel)})),h=[{field:"rowLabel",header:e.rowHeader??e.rowFields.join(" / "),semanticRole:"dimension"}];for(let a=0;a<u.length;a++){const n=u[a],s=e.measures[a];for(const o of n.columns.slice(1)){const f=`${o.field}_${a}`;h.push({...o,field:f,...s.digits===void 0?{}:{format:{kind:"number",digits:s.digits}},header:`${t.get(o.header)??o.header} · ${s.label??`${s.field} (${s.op})`}`}),n.rows.forEach((F,z)=>{d[z][f]=F[o.field]})}}return{rows:d,columns:h}}exports.createCrossTable=M;exports.createMatrixTable=L;exports.estimateMatrixTable=k;exports.validateMatrixOptions=N;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { e as N } from "./computed-Bvk0W15F.js";
|
|
2
|
+
function g(r, e) {
|
|
3
|
+
return Object.prototype.hasOwnProperty.call(r, e) ? r[e] : void 0;
|
|
4
|
+
}
|
|
5
|
+
function x(r) {
|
|
6
|
+
if (r == null) return "null";
|
|
7
|
+
if (typeof r != "string" && typeof r != "boolean" && !(typeof r == "number" && Number.isFinite(r)))
|
|
8
|
+
throw new Error("交叉表维度应为字符串、布尔、有限数字或空值");
|
|
9
|
+
return JSON.stringify([typeof r, r]);
|
|
10
|
+
}
|
|
11
|
+
function E(r) {
|
|
12
|
+
return r == null ? "" : String(r);
|
|
13
|
+
}
|
|
14
|
+
function y(r, e) {
|
|
15
|
+
const l = r ?? e;
|
|
16
|
+
if (!Number.isInteger(l) || l < 1)
|
|
17
|
+
throw new Error("交叉表预算应为正整数");
|
|
18
|
+
return l;
|
|
19
|
+
}
|
|
20
|
+
function A(r, e, l, t) {
|
|
21
|
+
const m = l ? 1 : 0;
|
|
22
|
+
if ((r + m) * (e + 1 + m) > t)
|
|
23
|
+
throw new Error(
|
|
24
|
+
"交叉表输出单元格超出 maxCells 预算,请减少维度或服务端预聚合"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
function z(r, e) {
|
|
28
|
+
if (!Array.isArray(r)) throw new Error("交叉表数据应为对象数组");
|
|
29
|
+
const l = e.aggregate ?? "sum";
|
|
30
|
+
if (!["sum", "count", "avg", "min", "max", "weightedAvg"].includes(l))
|
|
31
|
+
throw new Error("未知交叉表聚合类型");
|
|
32
|
+
if (!e.rowField || !e.columnField || l !== "count" && !e.valueField)
|
|
33
|
+
throw new Error("交叉表需要明确的行维度、列维度和度量字段");
|
|
34
|
+
if (r.length > y(e.maxInputRows, 1e5))
|
|
35
|
+
throw new Error("交叉表输入超出预算,请在服务端预聚合");
|
|
36
|
+
const t = y(e.maxRows, 1e3), m = y(e.maxColumns, 200), w = y(e.maxCells, 2e6), i = () => N({
|
|
37
|
+
op: l,
|
|
38
|
+
field: l === "count" && e.countMode !== "nonNull" ? void 0 : e.valueField,
|
|
39
|
+
weightField: e.weightField,
|
|
40
|
+
numeric: e.numeric,
|
|
41
|
+
digits: e.digits
|
|
42
|
+
}), c = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), h = i();
|
|
43
|
+
for (const n of r) {
|
|
44
|
+
const s = x(g(n, e.rowField)), o = x(g(n, e.columnField));
|
|
45
|
+
if (c.has(o) || c.set(o, E(g(n, e.columnField))), u.has(s) || u.set(s, {
|
|
46
|
+
label: E(g(n, e.rowField)),
|
|
47
|
+
cells: /* @__PURE__ */ new Map(),
|
|
48
|
+
total: i()
|
|
49
|
+
}), c.size > m || u.size > t)
|
|
50
|
+
throw new Error("交叉表维度数量超出预算");
|
|
51
|
+
A(u.size, c.size, e.totals, w);
|
|
52
|
+
const d = u.get(s);
|
|
53
|
+
d.cells.has(o) || d.cells.set(o, i()), f.has(o) || f.set(o, i());
|
|
54
|
+
for (const F of [
|
|
55
|
+
d.cells.get(o),
|
|
56
|
+
d.total,
|
|
57
|
+
f.get(o),
|
|
58
|
+
h
|
|
59
|
+
])
|
|
60
|
+
F.add(n);
|
|
61
|
+
}
|
|
62
|
+
const a = {
|
|
63
|
+
columns: [
|
|
64
|
+
{
|
|
65
|
+
header: e.rowHeader ?? e.rowField,
|
|
66
|
+
field: "rowLabel",
|
|
67
|
+
semanticRole: "dimension"
|
|
68
|
+
},
|
|
69
|
+
...[...c.values()].map(
|
|
70
|
+
(n, s) => ({
|
|
71
|
+
header: n,
|
|
72
|
+
field: `c${s}`,
|
|
73
|
+
semanticRole: "measure"
|
|
74
|
+
})
|
|
75
|
+
)
|
|
76
|
+
],
|
|
77
|
+
rows: [...u.values()].map((n) => ({
|
|
78
|
+
rowLabel: n.label,
|
|
79
|
+
...Object.fromEntries(
|
|
80
|
+
[...c.keys()].map((s, o) => [
|
|
81
|
+
`c${o}`,
|
|
82
|
+
n.cells.get(s)?.value() ?? (l === "count" ? 0 : null)
|
|
83
|
+
])
|
|
84
|
+
),
|
|
85
|
+
...e.totals ? { total: n.total.value() } : {}
|
|
86
|
+
}))
|
|
87
|
+
};
|
|
88
|
+
return e.totals && (a.columns.push({
|
|
89
|
+
header: "合计",
|
|
90
|
+
field: "total",
|
|
91
|
+
semanticRole: "measure"
|
|
92
|
+
}), r.length && a.rows.push({
|
|
93
|
+
rowLabel: "合计",
|
|
94
|
+
...Object.fromEntries(
|
|
95
|
+
[...c.keys()].map((n, s) => [
|
|
96
|
+
`c${s}`,
|
|
97
|
+
f.get(n)?.value() ?? (l === "count" ? 0 : null)
|
|
98
|
+
])
|
|
99
|
+
),
|
|
100
|
+
total: h.value()
|
|
101
|
+
})), a;
|
|
102
|
+
}
|
|
103
|
+
function b(r, e) {
|
|
104
|
+
const l = e.map(
|
|
105
|
+
(t) => Object.prototype.hasOwnProperty.call(r, t) ? r[t] : null
|
|
106
|
+
);
|
|
107
|
+
if (l.some(
|
|
108
|
+
(t) => t != null && typeof t != "string" && typeof t != "boolean" && !(typeof t == "number" && Number.isFinite(t))
|
|
109
|
+
))
|
|
110
|
+
throw new Error("矩阵维度必须是有限 JSON 标量");
|
|
111
|
+
return {
|
|
112
|
+
key: JSON.stringify(l.map((t) => [typeof t, t ?? null])),
|
|
113
|
+
label: l.map((t) => t == null ? "" : String(t)).join(" / ")
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function M(r) {
|
|
117
|
+
for (const e of [
|
|
118
|
+
"maxRows",
|
|
119
|
+
"maxColumns",
|
|
120
|
+
"maxInputRows",
|
|
121
|
+
"maxCells"
|
|
122
|
+
])
|
|
123
|
+
if (r[e] !== void 0 && (!Number.isSafeInteger(r[e]) || r[e] < 1))
|
|
124
|
+
throw new Error("矩阵预算应为正安全整数");
|
|
125
|
+
for (const e of ["columnWidthMm", "rowWidthMm"])
|
|
126
|
+
if (r[e] !== void 0 && (!Number.isFinite(r[e]) || r[e] <= 0))
|
|
127
|
+
throw new Error("矩阵列宽应为正数");
|
|
128
|
+
}
|
|
129
|
+
function R(r) {
|
|
130
|
+
if (!r || !Array.isArray(r.rowFields) || !Array.isArray(r.columnFields) || !Array.isArray(r.measures))
|
|
131
|
+
throw new Error("矩阵需要行维度、列维度和度量数组");
|
|
132
|
+
for (const l of [r.rowFields, r.columnFields])
|
|
133
|
+
if (l.some((t) => typeof t != "string" || !t.trim()) || new Set(l).size !== l.length)
|
|
134
|
+
throw new Error("矩阵维度字段应非空且唯一");
|
|
135
|
+
if (M(r), !r.rowFields.length || !r.columnFields.length || r.rowFields.length > 16 || r.columnFields.length > 16)
|
|
136
|
+
throw new Error("矩阵需要 1–16 个行/列维度");
|
|
137
|
+
if (!r.measures.length || r.measures.length > 32)
|
|
138
|
+
throw new Error("矩阵需要 1–32 个度量");
|
|
139
|
+
if (r.measures.map((l) => {
|
|
140
|
+
if (!l || typeof l != "object") throw new Error("矩阵度量应为对象");
|
|
141
|
+
if (N({
|
|
142
|
+
...l,
|
|
143
|
+
field: l.valueField ?? l.field
|
|
144
|
+
}), l.label !== void 0 && typeof l.label != "string")
|
|
145
|
+
throw new Error("矩阵度量标签应为字符串");
|
|
146
|
+
return l.field;
|
|
147
|
+
}).some((l) => typeof l != "string" || !l.trim()))
|
|
148
|
+
throw new Error("矩阵度量字段应非空");
|
|
149
|
+
}
|
|
150
|
+
function O(r, e) {
|
|
151
|
+
if (R(e), !Array.isArray(r) || r.length > (e.maxInputRows ?? 1e5))
|
|
152
|
+
throw new Error("矩阵输入超出预算");
|
|
153
|
+
const l = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set();
|
|
154
|
+
for (const i of r) {
|
|
155
|
+
if (!i || typeof i != "object" || Array.isArray(i))
|
|
156
|
+
throw new Error("矩阵数据行应为对象");
|
|
157
|
+
if (l.add(b(i, e.rowFields).key), t.add(b(i, e.columnFields).key), l.size > (e.maxRows ?? 1e3) || t.size > (e.maxColumns ?? 200))
|
|
158
|
+
throw new Error("矩阵维度数量超出预算");
|
|
159
|
+
if ((l.size + +!!e.totals) * ((t.size + +!!e.totals) * e.measures.length + 1) > (e.maxCells ?? 2e6))
|
|
160
|
+
throw new Error("矩阵输出超出 maxCells 预算");
|
|
161
|
+
}
|
|
162
|
+
const m = l.size + +(!!e.totals && r.length > 0), w = (t.size + +!!e.totals) * e.measures.length + 1;
|
|
163
|
+
return { rowCount: m, columnCount: w, cells: m * w };
|
|
164
|
+
}
|
|
165
|
+
function C(r, e) {
|
|
166
|
+
let l = e;
|
|
167
|
+
for (; r.some((t) => Object.prototype.hasOwnProperty.call(t, l)); )
|
|
168
|
+
l += "_";
|
|
169
|
+
return l;
|
|
170
|
+
}
|
|
171
|
+
function S(r, e) {
|
|
172
|
+
O(r, e);
|
|
173
|
+
const l = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), m = C(r, "__matrix_row"), w = C(r, "__matrix_column"), i = r.map((a) => {
|
|
174
|
+
const n = b(a, e.rowFields), s = b(a, e.columnFields);
|
|
175
|
+
return l.set(n.key, n.label), t.set(s.key, s.label), { ...a, [m]: n.key, [w]: s.key };
|
|
176
|
+
}), c = e.maxCells ?? 2e6;
|
|
177
|
+
if ((l.size + +!!e.totals) * ((t.size + +!!e.totals) * e.measures.length + 1) > c)
|
|
178
|
+
throw new Error("矩阵输出超出 maxCells 预算");
|
|
179
|
+
const u = e.measures.map(
|
|
180
|
+
(a) => z(i, {
|
|
181
|
+
rowField: m,
|
|
182
|
+
columnField: w,
|
|
183
|
+
valueField: a.valueField ?? a.field,
|
|
184
|
+
aggregate: a.op,
|
|
185
|
+
countMode: "nonNull",
|
|
186
|
+
weightField: a.weightField,
|
|
187
|
+
numeric: a.numeric,
|
|
188
|
+
digits: a.digits,
|
|
189
|
+
totals: e.totals,
|
|
190
|
+
maxRows: e.maxRows,
|
|
191
|
+
maxColumns: e.maxColumns,
|
|
192
|
+
maxInputRows: e.maxInputRows,
|
|
193
|
+
maxCells: c
|
|
194
|
+
})
|
|
195
|
+
), f = u[0].rows.map(
|
|
196
|
+
(a) => ({
|
|
197
|
+
rowLabel: l.get(String(a.rowLabel)) ?? String(a.rowLabel)
|
|
198
|
+
})
|
|
199
|
+
), h = [
|
|
200
|
+
{
|
|
201
|
+
field: "rowLabel",
|
|
202
|
+
header: e.rowHeader ?? e.rowFields.join(" / "),
|
|
203
|
+
semanticRole: "dimension"
|
|
204
|
+
}
|
|
205
|
+
];
|
|
206
|
+
for (let a = 0; a < u.length; a++) {
|
|
207
|
+
const n = u[a], s = e.measures[a];
|
|
208
|
+
for (const o of n.columns.slice(1)) {
|
|
209
|
+
const d = `${o.field}_${a}`;
|
|
210
|
+
h.push({
|
|
211
|
+
...o,
|
|
212
|
+
field: d,
|
|
213
|
+
...s.digits === void 0 ? {} : { format: { kind: "number", digits: s.digits } },
|
|
214
|
+
header: `${t.get(o.header) ?? o.header} · ${s.label ?? `${s.field} (${s.op})`}`
|
|
215
|
+
}), n.rows.forEach((F, k) => {
|
|
216
|
+
f[k][d] = F[o.field];
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { rows: f, columns: h };
|
|
221
|
+
}
|
|
222
|
+
export {
|
|
223
|
+
S as a,
|
|
224
|
+
z as c,
|
|
225
|
+
O as e,
|
|
226
|
+
R as v
|
|
227
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
function u(t) {
|
|
2
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(t) || t.startsWith("0000-")) return !1;
|
|
3
|
+
const e = /* @__PURE__ */ new Date(`${t}T00:00:00.000Z`);
|
|
4
|
+
return Number.isFinite(e.getTime()) && e.toISOString().slice(0, 10) === t;
|
|
5
|
+
}
|
|
6
|
+
function c(t) {
|
|
7
|
+
return t.length === 4 && /^\d{4}$/.test(t) && t !== "0000";
|
|
8
|
+
}
|
|
9
|
+
function f(t) {
|
|
10
|
+
return t.length === 7 && /^\d{4}-(?:0[1-9]|1[0-2])$/.test(t) && c(t.slice(0, 4));
|
|
11
|
+
}
|
|
12
|
+
function h(t) {
|
|
13
|
+
const [e, r, n] = t.split("/");
|
|
14
|
+
if (!(n !== void 0 || !e || !r || !u(e) || !u(r) || e > r))
|
|
15
|
+
return { start: e, end: r };
|
|
16
|
+
}
|
|
17
|
+
function O(t) {
|
|
18
|
+
const e = `${t.start}/${t.end}`;
|
|
19
|
+
if (!h(e)) throw new RangeError("日期范围必须为完整且有序的 YYYY-MM-DD/YYYY-MM-DD");
|
|
20
|
+
return e;
|
|
21
|
+
}
|
|
22
|
+
function x(t, e) {
|
|
23
|
+
return typeof e != "string" ? !1 : t === "month" ? f(e) : t === "year" ? c(e) : (t === "date" || t === "dateRange") && u(e);
|
|
24
|
+
}
|
|
25
|
+
function $(t, e) {
|
|
26
|
+
if (t === "date" && !u(e)) return "应为有效的 YYYY-MM-DD 日期";
|
|
27
|
+
if (t === "month" && !f(e)) return "应为有效的 YYYY-MM 月份";
|
|
28
|
+
if (t === "year" && !c(e)) return "应为 0001 至 9999 的四位年份";
|
|
29
|
+
if (t === "dateRange" && !h(e)) return "应为完整且有序的 YYYY-MM-DD/YYYY-MM-DD 日期范围";
|
|
30
|
+
}
|
|
31
|
+
class g extends Error {
|
|
32
|
+
constructor(e) {
|
|
33
|
+
super(e.map((r) => `${r.field}: ${r.message}`).join("; ")), this.issues = e, this.code = "params", this.name = "ReportParamValidationError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function y(t) {
|
|
37
|
+
return /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(t) && Number.isFinite(Number(t));
|
|
38
|
+
}
|
|
39
|
+
function b(t, e) {
|
|
40
|
+
if (t.type === "number" && !y(e)) return [["type", "应为有限数字"]];
|
|
41
|
+
const r = $(t.type, e);
|
|
42
|
+
if (r) return [["type", r]];
|
|
43
|
+
const n = [];
|
|
44
|
+
t.type === "select" && t.options && !t.options.some((i) => i.value === e) && n.push(["option", "不在允许的选项中"]);
|
|
45
|
+
const s = Array.from(e).length;
|
|
46
|
+
return t.minLength !== void 0 && s < t.minLength && n.push(["minLength", `至少 ${t.minLength} 个字符`]), t.maxLength !== void 0 && s > t.maxLength && n.push(["maxLength", `最多 ${t.maxLength} 个字符`]), n.push(...Y(t, e)), n;
|
|
47
|
+
}
|
|
48
|
+
function Y(t, e) {
|
|
49
|
+
const r = t.type === "dateRange" ? h(e) : void 0, n = r?.start ?? (t.type === "number" ? Number(e) : e), s = r?.end ?? n, i = [];
|
|
50
|
+
return t.min !== void 0 && n < t.min && i.push(["minimum", `不能小于 ${t.min}`]), t.max !== void 0 && s > t.max && i.push(["maximum", `不能大于 ${t.max}`]), i;
|
|
51
|
+
}
|
|
52
|
+
function v(t) {
|
|
53
|
+
const e = [];
|
|
54
|
+
for (const s of ["min", "max"]) {
|
|
55
|
+
const i = t[s];
|
|
56
|
+
if (i === void 0) continue;
|
|
57
|
+
x(t.type, i) || t.type === "number" && typeof i == "number" && Number.isFinite(i) || e.push(`${s} 应为数字的有限边界或日期/月/年的规范字符串边界`);
|
|
58
|
+
}
|
|
59
|
+
const r = typeof t.min == "number" && typeof t.max == "number" && t.min > t.max, n = typeof t.min == "string" && typeof t.max == "string" && t.min > t.max;
|
|
60
|
+
return (r || n) && e.push("最小边界不能大于最大边界"), [...e, ...L(t)];
|
|
61
|
+
}
|
|
62
|
+
function L(t) {
|
|
63
|
+
const e = [];
|
|
64
|
+
t.type === "number" && (t.minLength !== void 0 || t.maxLength !== void 0) && e.push("number 参数使用 min/max 而不是文本长度约束");
|
|
65
|
+
for (const r of ["minLength", "maxLength"]) {
|
|
66
|
+
const n = t[r];
|
|
67
|
+
n !== void 0 && (!Number.isSafeInteger(n) || n < 0) && e.push(`${r} 应为非负整数`);
|
|
68
|
+
}
|
|
69
|
+
return typeof t.minLength == "number" && typeof t.maxLength == "number" && t.minLength > t.maxLength && e.push("最小长度不能大于最大长度"), e;
|
|
70
|
+
}
|
|
71
|
+
function d(t) {
|
|
72
|
+
if (!Array.isArray(t)) return [{ code: "definition", field: "", path: "$.paramDefs", message: "参数定义应为数组" }];
|
|
73
|
+
const e = /* @__PURE__ */ new Set();
|
|
74
|
+
return t.flatMap((r, n) => {
|
|
75
|
+
const s = r && typeof r.field == "string" ? r.field : "";
|
|
76
|
+
return V(r, e).map((o) => ({ code: "definition", field: s, path: `$.paramDefs.${n}`, message: o }));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function R(t) {
|
|
80
|
+
return Array.isArray(t) && t.every((e) => !!e && typeof e == "object" && typeof e.value == "string" && typeof e.label == "string");
|
|
81
|
+
}
|
|
82
|
+
function D(t) {
|
|
83
|
+
const e = [];
|
|
84
|
+
return t.type !== void 0 && !["text", "number", "date", "month", "year", "dateRange", "select"].includes(t.type) && e.push("未知参数类型"), t.label !== void 0 && typeof t.label != "string" && e.push("参数标签应为字符串"), t.placeholder !== void 0 && typeof t.placeholder != "string" && e.push("提示文字应为字符串"), t.required !== void 0 && typeof t.required != "boolean" && e.push("required 应为布尔值"), t.defaultValue !== void 0 && typeof t.defaultValue != "string" && e.push("默认值应为字符串"), t.options !== void 0 && !R(t.options) && e.push("选项应为包含字符串 label/value 的数组"), e;
|
|
85
|
+
}
|
|
86
|
+
function V(t, e) {
|
|
87
|
+
if (!t || typeof t != "object" || Array.isArray(t)) return ["参数定义项应为对象"];
|
|
88
|
+
const r = D(t);
|
|
89
|
+
return typeof t.field != "string" || !t.field.trim() || e.has(t.field) ? r.push("参数名应为非空且不重复的字符串") : e.add(t.field), r.length || (r.push(...v(t)), r.length) || (t.options && new Set(t.options.map((n) => n.value)).size !== t.options.length && r.push("选项值不能重复"), t.defaultValue !== void 0 && (t.required && !t.defaultValue.trim() ? r.push("必填参数的默认值不能为空") : t.defaultValue.trim() && r.push(...b(t, t.defaultValue).map(([, n]) => `默认值${n}`)))), r;
|
|
90
|
+
}
|
|
91
|
+
function w(t, e, r) {
|
|
92
|
+
for (const [n, s] of Object.entries(t))
|
|
93
|
+
(typeof s == "string" || typeof s == "number" && Number.isFinite(s)) && (Object.defineProperty(e, n, { value: String(s), writable: !0, enumerable: !0, configurable: !0 }), Object.defineProperty(r, n, { value: s, writable: !0, enumerable: !0, configurable: !0 }));
|
|
94
|
+
}
|
|
95
|
+
function M(t) {
|
|
96
|
+
return t == null || typeof t == "string" && !t.trim();
|
|
97
|
+
}
|
|
98
|
+
function j(t, e = {}) {
|
|
99
|
+
const r = /* @__PURE__ */ Object.create(null), n = /* @__PURE__ */ Object.create(null), s = d(t);
|
|
100
|
+
if ((!e || typeof e != "object" || Array.isArray(e)) && s.push({ code: "type", field: "", path: "$.params", message: "参数应为对象" }), s.length) return { ok: !1, values: r, typedValues: n, issues: s };
|
|
101
|
+
w(e, r, n);
|
|
102
|
+
for (const i of t) {
|
|
103
|
+
const o = Object.prototype.hasOwnProperty.call(e, i.field) && e[i.field] !== void 0 ? e[i.field] : i.defaultValue, m = (p, l) => s.push({ code: p, path: `$.params.${i.field}`, field: i.field, message: l });
|
|
104
|
+
if (M(o)) {
|
|
105
|
+
i.required && m("required", "此参数为必填项"), typeof o == "string" && (r[i.field] = o), delete n[i.field];
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (typeof o != "string" && !(typeof o == "number" && Number.isFinite(o))) {
|
|
109
|
+
m("type", "参数应为字符串或有限数字");
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const a = String(o);
|
|
113
|
+
r[i.field] = a, b(i, a).forEach(([p, l]) => m(p, l)), n[i.field] = i.type === "number" && y(a) ? Number(a) : a;
|
|
114
|
+
}
|
|
115
|
+
return { ok: s.length === 0, values: r, typedValues: n, issues: s };
|
|
116
|
+
}
|
|
117
|
+
function P(t, e = {}) {
|
|
118
|
+
const r = j(t, e);
|
|
119
|
+
if (!r.ok) throw new g(r.issues);
|
|
120
|
+
return r.values;
|
|
121
|
+
}
|
|
122
|
+
function N(t) {
|
|
123
|
+
const e = {}, r = "(?![\\s\\S])";
|
|
124
|
+
return t.type === "date" && (e.format = "date"), t.type === "month" && (e.pattern = `^(?!0000)[0-9]{4}-(0[1-9]|1[0-2])${r}`), t.type === "year" && (e.pattern = `^(?!0000)[0-9]{4}${r}`), t.type === "dateRange" && (e.pattern = `^[0-9]{4}-[0-9]{2}-[0-9]{2}/[0-9]{4}-[0-9]{2}-[0-9]{2}${r}`), t.type === "dateRange" && (e["x-report-date-range"] = { separator: "/", ordered: !0, calendarDates: !0 }), e;
|
|
125
|
+
}
|
|
126
|
+
function S(t) {
|
|
127
|
+
const e = { type: t.type === "number" ? "number" : "string", title: t.label ?? t.field, ...N(t) };
|
|
128
|
+
return t.required && t.type !== "number" && !e.pattern && (e.pattern = "\\S"), t.type === "select" && t.options && (e.enum = t.options.map((r) => r.value)), t.defaultValue !== void 0 && (t.type !== "number" || t.defaultValue.trim()) && (e.default = t.type === "number" ? Number(t.defaultValue) : t.defaultValue), t.minLength !== void 0 && (e.minLength = t.minLength), t.maxLength !== void 0 && (e.maxLength = t.maxLength), typeof t.min == "number" && (e.minimum = t.min), typeof t.max == "number" && (e.maximum = t.max), typeof t.min == "string" && (e["x-report-minimum"] = t.min), typeof t.max == "string" && (e["x-report-maximum"] = t.max), e;
|
|
129
|
+
}
|
|
130
|
+
function q(t) {
|
|
131
|
+
const e = d(t);
|
|
132
|
+
if (e.length) throw new g(e);
|
|
133
|
+
return {
|
|
134
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
135
|
+
type: "object",
|
|
136
|
+
properties: Object.fromEntries(t.map((r) => [r.field, S(r)])),
|
|
137
|
+
required: t.filter((r) => r.required).map((r) => r.field),
|
|
138
|
+
additionalProperties: !0
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
g as R,
|
|
143
|
+
P as a,
|
|
144
|
+
f as b,
|
|
145
|
+
c,
|
|
146
|
+
j as d,
|
|
147
|
+
x as e,
|
|
148
|
+
O as f,
|
|
149
|
+
u as i,
|
|
150
|
+
h as p,
|
|
151
|
+
q as r,
|
|
152
|
+
d as v
|
|
153
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function u(t){if(!/^\d{4}-\d{2}-\d{2}$/.test(t)||t.startsWith("0000-"))return!1;const e=new Date(`${t}T00:00:00.000Z`);return Number.isFinite(e.getTime())&&e.toISOString().slice(0,10)===t}function m(t){return t.length===4&&/^\d{4}$/.test(t)&&t!=="0000"}function f(t){return t.length===7&&/^\d{4}-(?:0[1-9]|1[0-2])$/.test(t)&&m(t.slice(0,4))}function p(t){const[e,r,n]=t.split("/");if(!(n!==void 0||!e||!r||!u(e)||!u(r)||e>r))return{start:e,end:r}}function Y(t){const e=`${t.start}/${t.end}`;if(!p(e))throw new RangeError("日期范围必须为完整且有序的 YYYY-MM-DD/YYYY-MM-DD");return e}function b(t,e){return typeof e!="string"?!1:t==="month"?f(e):t==="year"?m(e):(t==="date"||t==="dateRange")&&u(e)}function $(t,e){if(t==="date"&&!u(e))return"应为有效的 YYYY-MM-DD 日期";if(t==="month"&&!f(e))return"应为有效的 YYYY-MM 月份";if(t==="year"&&!m(e))return"应为 0001 至 9999 的四位年份";if(t==="dateRange"&&!p(e))return"应为完整且有序的 YYYY-MM-DD/YYYY-MM-DD 日期范围"}class g extends Error{constructor(e){super(e.map(r=>`${r.field}: ${r.message}`).join("; ")),this.issues=e,this.code="params",this.name="ReportParamValidationError"}}function d(t){return/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(t)&&Number.isFinite(Number(t))}function x(t,e){if(t.type==="number"&&!d(e))return[["type","应为有限数字"]];const r=$(t.type,e);if(r)return[["type",r]];const n=[];t.type==="select"&&t.options&&!t.options.some(i=>i.value===e)&&n.push(["option","不在允许的选项中"]);const o=Array.from(e).length;return t.minLength!==void 0&&o<t.minLength&&n.push(["minLength",`至少 ${t.minLength} 个字符`]),t.maxLength!==void 0&&o>t.maxLength&&n.push(["maxLength",`最多 ${t.maxLength} 个字符`]),n.push(...v(t,e)),n}function v(t,e){const r=t.type==="dateRange"?p(e):void 0,n=r?.start??(t.type==="number"?Number(e):e),o=r?.end??n,i=[];return t.min!==void 0&&n<t.min&&i.push(["minimum",`不能小于 ${t.min}`]),t.max!==void 0&&o>t.max&&i.push(["maximum",`不能大于 ${t.max}`]),i}function D(t){const e=[];for(const o of["min","max"]){const i=t[o];if(i===void 0)continue;b(t.type,i)||t.type==="number"&&typeof i=="number"&&Number.isFinite(i)||e.push(`${o} 应为数字的有限边界或日期/月/年的规范字符串边界`)}const r=typeof t.min=="number"&&typeof t.max=="number"&&t.min>t.max,n=typeof t.min=="string"&&typeof t.max=="string"&&t.min>t.max;return(r||n)&&e.push("最小边界不能大于最大边界"),[...e,...L(t)]}function L(t){const e=[];t.type==="number"&&(t.minLength!==void 0||t.maxLength!==void 0)&&e.push("number 参数使用 min/max 而不是文本长度约束");for(const r of["minLength","maxLength"]){const n=t[r];n!==void 0&&(!Number.isSafeInteger(n)||n<0)&&e.push(`${r} 应为非负整数`)}return typeof t.minLength=="number"&&typeof t.maxLength=="number"&&t.minLength>t.maxLength&&e.push("最小长度不能大于最大长度"),e}function y(t){if(!Array.isArray(t))return[{code:"definition",field:"",path:"$.paramDefs",message:"参数定义应为数组"}];const e=new Set;return t.flatMap((r,n)=>{const o=r&&typeof r.field=="string"?r.field:"";return P(r,e).map(s=>({code:"definition",field:o,path:`$.paramDefs.${n}`,message:s}))})}function V(t){return Array.isArray(t)&&t.every(e=>!!e&&typeof e=="object"&&typeof e.value=="string"&&typeof e.label=="string")}function M(t){const e=[];return t.type!==void 0&&!["text","number","date","month","year","dateRange","select"].includes(t.type)&&e.push("未知参数类型"),t.label!==void 0&&typeof t.label!="string"&&e.push("参数标签应为字符串"),t.placeholder!==void 0&&typeof t.placeholder!="string"&&e.push("提示文字应为字符串"),t.required!==void 0&&typeof t.required!="boolean"&&e.push("required 应为布尔值"),t.defaultValue!==void 0&&typeof t.defaultValue!="string"&&e.push("默认值应为字符串"),t.options!==void 0&&!V(t.options)&&e.push("选项应为包含字符串 label/value 的数组"),e}function P(t,e){if(!t||typeof t!="object"||Array.isArray(t))return["参数定义项应为对象"];const r=M(t);return typeof t.field!="string"||!t.field.trim()||e.has(t.field)?r.push("参数名应为非空且不重复的字符串"):e.add(t.field),r.length||(r.push(...D(t)),r.length)||(t.options&&new Set(t.options.map(n=>n.value)).size!==t.options.length&&r.push("选项值不能重复"),t.defaultValue!==void 0&&(t.required&&!t.defaultValue.trim()?r.push("必填参数的默认值不能为空"):t.defaultValue.trim()&&r.push(...x(t,t.defaultValue).map(([,n])=>`默认值${n}`)))),r}function w(t,e,r){for(const[n,o]of Object.entries(t))(typeof o=="string"||typeof o=="number"&&Number.isFinite(o))&&(Object.defineProperty(e,n,{value:String(o),writable:!0,enumerable:!0,configurable:!0}),Object.defineProperty(r,n,{value:o,writable:!0,enumerable:!0,configurable:!0}))}function j(t){return t==null||typeof t=="string"&&!t.trim()}function R(t,e={}){const r=Object.create(null),n=Object.create(null),o=y(t);if((!e||typeof e!="object"||Array.isArray(e))&&o.push({code:"type",field:"",path:"$.params",message:"参数应为对象"}),o.length)return{ok:!1,values:r,typedValues:n,issues:o};w(e,r,n);for(const i of t){const s=Object.prototype.hasOwnProperty.call(e,i.field)&&e[i.field]!==void 0?e[i.field]:i.defaultValue,l=(c,h)=>o.push({code:c,path:`$.params.${i.field}`,field:i.field,message:h});if(j(s)){i.required&&l("required","此参数为必填项"),typeof s=="string"&&(r[i.field]=s),delete n[i.field];continue}if(typeof s!="string"&&!(typeof s=="number"&&Number.isFinite(s))){l("type","参数应为字符串或有限数字");continue}const a=String(s);r[i.field]=a,x(i,a).forEach(([c,h])=>l(c,h)),n[i.field]=i.type==="number"&&d(a)?Number(a):a}return{ok:o.length===0,values:r,typedValues:n,issues:o}}function S(t,e={}){const r=R(t,e);if(!r.ok)throw new g(r.issues);return r.values}function N(t){const e={},r="(?![\\s\\S])";return t.type==="date"&&(e.format="date"),t.type==="month"&&(e.pattern=`^(?!0000)[0-9]{4}-(0[1-9]|1[0-2])${r}`),t.type==="year"&&(e.pattern=`^(?!0000)[0-9]{4}${r}`),t.type==="dateRange"&&(e.pattern=`^[0-9]{4}-[0-9]{2}-[0-9]{2}/[0-9]{4}-[0-9]{2}-[0-9]{2}${r}`),t.type==="dateRange"&&(e["x-report-date-range"]={separator:"/",ordered:!0,calendarDates:!0}),e}function I(t){const e={type:t.type==="number"?"number":"string",title:t.label??t.field,...N(t)};return t.required&&t.type!=="number"&&!e.pattern&&(e.pattern="\\S"),t.type==="select"&&t.options&&(e.enum=t.options.map(r=>r.value)),t.defaultValue!==void 0&&(t.type!=="number"||t.defaultValue.trim())&&(e.default=t.type==="number"?Number(t.defaultValue):t.defaultValue),t.minLength!==void 0&&(e.minLength=t.minLength),t.maxLength!==void 0&&(e.maxLength=t.maxLength),typeof t.min=="number"&&(e.minimum=t.min),typeof t.max=="number"&&(e.maximum=t.max),typeof t.min=="string"&&(e["x-report-minimum"]=t.min),typeof t.max=="string"&&(e["x-report-maximum"]=t.max),e}function O(t){const e=y(t);if(e.length)throw new g(e);return{$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:Object.fromEntries(t.map(r=>[r.field,I(r)])),required:t.filter(r=>r.required).map(r=>r.field),additionalProperties:!0}}exports.ReportParamValidationError=g;exports.assertReportParams=S;exports.formatReportDateRange=Y;exports.isReportDate=u;exports.isReportMonth=f;exports.isReportTemporalBound=b;exports.isReportYear=m;exports.parseReportDateRange=p;exports.reportParamsJsonSchema=O;exports.validateReportParamDefinitions=y;exports.validateReportParams=R;
|