@nice2dev/ui 1.4.5 → 1.4.7
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/CHANGELOG.md +76 -0
- package/dist/{NiceDataGrid-mrnaLHQk.cjs → NiceDataGrid-D3qRQSjy.cjs} +1 -1
- package/dist/NiceForm-BWb4LTQJ.cjs +1 -0
- package/dist/{NiceHtmlEditor-C1OVtLQ6.cjs → NiceHtmlEditor-BzECmDO3.cjs} +1 -1
- package/dist/{NiceMention-tgJKS8PH.cjs → NiceMention-CYRqPKGU.cjs} +19 -19
- package/dist/NiceModuleLifecyclePanel-CiYbPcHV.cjs +1 -0
- package/dist/{NicePagination-D7XxeNFz.cjs → NicePagination-BAxwqeEd.cjs} +1 -1
- package/dist/{NicePivotGrid-Cnkr9WkC.cjs → NicePivotGrid-Cxu5PECg.cjs} +1 -1
- package/dist/{NiceSavedQueryPanel-U1-yaw-Q.cjs → NiceSavedQueryPanel-BSZhE-_l.cjs} +6 -6
- package/dist/{NiceScheduler-Boo-D1S-.cjs → NiceScheduler-BqYiHPvz.cjs} +1 -1
- package/dist/{core-lazy-C_qnVGxE.cjs → core-lazy-BQexApr7.cjs} +1 -1
- package/dist/data.cjs +1 -1
- package/dist/database/NiceDataSourceEditor.mjs +370 -0
- package/dist/database/NiceQueryDesigner.mjs +958 -0
- package/dist/database/moduleDataSource.mjs +151 -0
- package/dist/database/queryDesign.mjs +396 -0
- package/dist/database/queryDesignerPanels.mjs +1214 -0
- package/dist/database/querySql.mjs +481 -0
- package/dist/editors.cjs +1 -1
- package/dist/index.cjs +188 -181
- package/dist/index.d.ts +674 -0
- package/dist/index.mjs +774 -720
- package/dist/lazy.cjs +1 -1
- package/dist/navigation.cjs +1 -1
- package/dist/no-code/NiceNoCodeScriptEditor.mjs +584 -0
- package/dist/no-code/noCodeScript.mjs +326 -0
- package/dist/no-code-B1jzfUF5.cjs +331 -0
- package/dist/no-code.cjs +1 -1
- package/dist/no-code.d.ts +177 -0
- package/dist/no-code.mjs +26 -16
- package/dist/style.css +2 -2
- package/package.json +4 -4
- package/dist/NiceForm-O3sv-DNX.cjs +0 -1
- package/dist/NiceModuleLifecyclePanel-DKlqKPy2.cjs +0 -1
- package/dist/NiceSelect-BNPXs6FQ.cjs +0 -1
- package/dist/no-code-B3BHeyG-.cjs +0 -331
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import { rootTableId as ee, queryParameterNames as te, nestPathOf as b, outputColumns as ne, nestNameOf as re, listJoinOf as se, tableHandleOf as B, valueTypeOf as ae, NICE_SQL_FUNCTIONS as oe } from "./queryDesign.mjs";
|
|
2
|
+
const K = "parentKeys", L = "__parent";
|
|
3
|
+
function q(e, t = "postgresql") {
|
|
4
|
+
switch (t) {
|
|
5
|
+
case "sqlserver":
|
|
6
|
+
return `[${e.replace(/]/g, "]]")}]`;
|
|
7
|
+
case "mysql":
|
|
8
|
+
return `\`${e.replace(/`/g, "``")}\``;
|
|
9
|
+
default:
|
|
10
|
+
return `"${e.replace(/"/g, '""')}"`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const G = (e) => `'${e.replace(/'/g, "''")}'`, H = (e, t) => `${t === "oracle" ? ":" : "@"}${e}`;
|
|
14
|
+
function W(e, t) {
|
|
15
|
+
return t === "sqlserver" || t === "mysql" ? `CONCAT(${e.join(", ")})` : `(${e.join(" || ")})`;
|
|
16
|
+
}
|
|
17
|
+
const F = (e) => ({
|
|
18
|
+
postgresql: "CURRENT_DATE",
|
|
19
|
+
sqlserver: "CAST(GETDATE() AS date)",
|
|
20
|
+
mysql: "CURDATE()",
|
|
21
|
+
sqlite: "date('now')",
|
|
22
|
+
oracle: "TRUNC(SYSDATE)"
|
|
23
|
+
})[e];
|
|
24
|
+
function M(e, t) {
|
|
25
|
+
const r = e.trim(), n = /^-?\d+$/.test(r);
|
|
26
|
+
switch (t) {
|
|
27
|
+
case "postgresql":
|
|
28
|
+
return `(CURRENT_DATE + ${n ? r : `CAST(${r} AS integer)`})`;
|
|
29
|
+
case "sqlserver":
|
|
30
|
+
return `DATEADD(day, ${r}, CAST(GETDATE() AS date))`;
|
|
31
|
+
case "mysql":
|
|
32
|
+
return `(CURDATE() + INTERVAL ${r} DAY)`;
|
|
33
|
+
case "sqlite":
|
|
34
|
+
return n ? `date('now', '${Number(r) >= 0 ? "+" : ""}${r} days')` : `date('now', (${r}) || ' days')`;
|
|
35
|
+
case "oracle":
|
|
36
|
+
return `(TRUNC(SYSDATE) + ${r})`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function le(e, t) {
|
|
40
|
+
switch (t) {
|
|
41
|
+
case "postgresql":
|
|
42
|
+
return [
|
|
43
|
+
`DATE_TRUNC('${e}', CURRENT_DATE)`,
|
|
44
|
+
`(DATE_TRUNC('${e}', CURRENT_DATE) + INTERVAL '1 ${e}')`
|
|
45
|
+
];
|
|
46
|
+
case "sqlserver": {
|
|
47
|
+
const r = e === "month" ? "DATEFROMPARTS(YEAR(GETDATE()), MONTH(GETDATE()), 1)" : "DATEFROMPARTS(YEAR(GETDATE()), 1, 1)";
|
|
48
|
+
return [r, `DATEADD(${e}, 1, ${r})`];
|
|
49
|
+
}
|
|
50
|
+
case "mysql": {
|
|
51
|
+
const r = e === "month" ? "DATE_FORMAT(CURDATE(), '%Y-%m-01')" : "DATE_FORMAT(CURDATE(), '%Y-01-01')";
|
|
52
|
+
return [r, `(${r} + INTERVAL 1 ${e.toUpperCase()})`];
|
|
53
|
+
}
|
|
54
|
+
case "sqlite":
|
|
55
|
+
return [`date('now', 'start of ${e}')`, `date('now', 'start of ${e}', '+1 ${e}')`];
|
|
56
|
+
case "oracle": {
|
|
57
|
+
const r = e === "month" ? "TRUNC(SYSDATE, 'MM')" : "TRUNC(SYSDATE, 'YYYY')";
|
|
58
|
+
return [r, `ADD_MONTHS(${r}, ${e === "month" ? 1 : 12})`];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function P(e, t, r) {
|
|
63
|
+
switch (r) {
|
|
64
|
+
case "postgresql":
|
|
65
|
+
return `DATE_TRUNC('${t}', ${e})`;
|
|
66
|
+
case "sqlserver":
|
|
67
|
+
return t === "day" ? `CAST(${e} AS date)` : t === "month" ? `DATEFROMPARTS(YEAR(${e}), MONTH(${e}), 1)` : t === "quarter" ? `DATEFROMPARTS(YEAR(${e}), (DATEPART(quarter, ${e}) - 1) * 3 + 1, 1)` : `DATEFROMPARTS(YEAR(${e}), 1, 1)`;
|
|
68
|
+
case "mysql":
|
|
69
|
+
return t === "day" ? `DATE(${e})` : t === "month" ? `DATE_FORMAT(${e}, '%Y-%m-01')` : t === "quarter" ? `(MAKEDATE(YEAR(${e}), 1) + INTERVAL QUARTER(${e}) - 1 QUARTER)` : `DATE_FORMAT(${e}, '%Y-01-01')`;
|
|
70
|
+
case "sqlite":
|
|
71
|
+
return t === "day" ? `date(${e})` : t === "month" ? `strftime('%Y-%m-01', ${e})` : t === "quarter" ? `(strftime('%Y', ${e}) || '-' || printf('%02d', ((CAST(strftime('%m', ${e}) AS INTEGER) - 1) / 3) * 3 + 1) || '-01')` : `strftime('%Y-01-01', ${e})`;
|
|
72
|
+
case "oracle":
|
|
73
|
+
return `TRUNC(${e}, '${{ day: "DD", month: "MM", quarter: "Q", year: "YYYY" }[t]}')`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function Q(e, t, r) {
|
|
77
|
+
const [n = "NULL", s = "NULL", a = "NULL"] = t;
|
|
78
|
+
switch (e) {
|
|
79
|
+
case "upper":
|
|
80
|
+
return `UPPER(${n})`;
|
|
81
|
+
case "lower":
|
|
82
|
+
return `LOWER(${n})`;
|
|
83
|
+
case "trim":
|
|
84
|
+
return `TRIM(${n})`;
|
|
85
|
+
case "concat":
|
|
86
|
+
return W(t.length ? t : ["''"], r);
|
|
87
|
+
case "left":
|
|
88
|
+
return r === "sqlite" || r === "oracle" ? `SUBSTR(${n}, 1, ${s})` : `LEFT(${n}, ${s})`;
|
|
89
|
+
case "length":
|
|
90
|
+
return r === "sqlserver" ? `LEN(${n})` : r === "mysql" ? `CHAR_LENGTH(${n})` : `LENGTH(${n})`;
|
|
91
|
+
case "replace":
|
|
92
|
+
return `REPLACE(${n}, ${s}, ${a})`;
|
|
93
|
+
case "round":
|
|
94
|
+
return `ROUND(${n}, ${t[1] ?? "0"})`;
|
|
95
|
+
case "abs":
|
|
96
|
+
return `ABS(${n})`;
|
|
97
|
+
case "floor":
|
|
98
|
+
return `FLOOR(${n})`;
|
|
99
|
+
case "ceil":
|
|
100
|
+
return r === "sqlserver" ? `CEILING(${n})` : `CEIL(${n})`;
|
|
101
|
+
case "add":
|
|
102
|
+
return `(${n} + ${s})`;
|
|
103
|
+
case "subtract":
|
|
104
|
+
return `(${n} - ${s})`;
|
|
105
|
+
case "multiply":
|
|
106
|
+
return `(${n} * ${s})`;
|
|
107
|
+
case "divide":
|
|
108
|
+
return `(${n} * 1.0 / NULLIF(${s}, 0))`;
|
|
109
|
+
case "year":
|
|
110
|
+
case "month":
|
|
111
|
+
case "day":
|
|
112
|
+
return r === "sqlite" ? `CAST(strftime('${{ year: "%Y", month: "%m", day: "%d" }[e]}', ${n}) AS INTEGER)` : r === "postgresql" || r === "oracle" ? `EXTRACT(${e.toUpperCase()} FROM ${n})` : `${e.toUpperCase()}(${n})`;
|
|
113
|
+
case "date":
|
|
114
|
+
return r === "mysql" ? `DATE(${n})` : r === "sqlite" ? `date(${n})` : r === "oracle" ? `TRUNC(${n})` : `CAST(${n} AS date)`;
|
|
115
|
+
case "daysBetween":
|
|
116
|
+
switch (r) {
|
|
117
|
+
case "postgresql":
|
|
118
|
+
return `(CAST(${s} AS date) - CAST(${n} AS date))`;
|
|
119
|
+
case "sqlserver":
|
|
120
|
+
return `DATEDIFF(day, ${n}, ${s})`;
|
|
121
|
+
case "mysql":
|
|
122
|
+
return `DATEDIFF(${s}, ${n})`;
|
|
123
|
+
case "sqlite":
|
|
124
|
+
return `CAST(julianday(${s}) - julianday(${n}) AS INTEGER)`;
|
|
125
|
+
case "oracle":
|
|
126
|
+
return `(TRUNC(${s}) - TRUNC(${n}))`;
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
case "now":
|
|
130
|
+
return "CURRENT_TIMESTAMP";
|
|
131
|
+
case "coalesce":
|
|
132
|
+
return `COALESCE(${t.join(", ") || "NULL"})`;
|
|
133
|
+
}
|
|
134
|
+
return "NULL";
|
|
135
|
+
}
|
|
136
|
+
const V = (e, t) => e === "COUNT_DISTINCT" ? `COUNT(DISTINCT ${t})` : `${e}(${t})`, A = (e, t) => q(t, e.d);
|
|
137
|
+
function h(e, t, r) {
|
|
138
|
+
const n = e.byId.get(t);
|
|
139
|
+
return n ? `${A(e, B(n))}.${A(e, r)}` : A(e, r);
|
|
140
|
+
}
|
|
141
|
+
function _(e, t) {
|
|
142
|
+
const r = t.schema === "source" ? e.sources[t.name] : void 0;
|
|
143
|
+
if (r)
|
|
144
|
+
return `(${r}) ${A(e, B(t))}`;
|
|
145
|
+
const n = (t.schema && t.schema !== "source" ? `${A(e, t.schema)}.` : "") + A(e, t.name);
|
|
146
|
+
return t.alias ? `${n} ${A(e, t.alias)}` : n;
|
|
147
|
+
}
|
|
148
|
+
function ue(e, t) {
|
|
149
|
+
if (t?.kind === "column") {
|
|
150
|
+
const r = e.byId.get(t.tableId)?.columns.find((n) => n.name === t.column);
|
|
151
|
+
return t.aggregate === "COUNT" || t.aggregate === "COUNT_DISTINCT" ? "number" : ae(r?.dataType);
|
|
152
|
+
}
|
|
153
|
+
if (t?.kind === "computed") {
|
|
154
|
+
const r = e.model.computed?.find((n) => n.id === t.id);
|
|
155
|
+
return oe.find((n) => n.id === r?.fn)?.result ?? "any";
|
|
156
|
+
}
|
|
157
|
+
return "any";
|
|
158
|
+
}
|
|
159
|
+
function j(e, t, r) {
|
|
160
|
+
const n = t.trim();
|
|
161
|
+
if (r === "number" && /^-?\d+(\.\d+)?$/.test(n))
|
|
162
|
+
return n;
|
|
163
|
+
if (r === "boolean") {
|
|
164
|
+
const s = /^(true|1|yes|tak)$/i.test(n);
|
|
165
|
+
return e.d === "postgresql" ? s ? "TRUE" : "FALSE" : s ? "1" : "0";
|
|
166
|
+
}
|
|
167
|
+
return G(t);
|
|
168
|
+
}
|
|
169
|
+
function J(e, t, r = /* @__PURE__ */ new Set()) {
|
|
170
|
+
if (r.has(t.id))
|
|
171
|
+
return "NULL";
|
|
172
|
+
const n = t.args.map((s) => S(e, s, "any", /* @__PURE__ */ new Set([...r, t.id])));
|
|
173
|
+
return Q(t.fn, n, e.d);
|
|
174
|
+
}
|
|
175
|
+
function S(e, t, r, n = /* @__PURE__ */ new Set()) {
|
|
176
|
+
if (!t)
|
|
177
|
+
return "NULL";
|
|
178
|
+
switch (t.kind) {
|
|
179
|
+
case "column": {
|
|
180
|
+
const s = h(e, t.tableId, t.column);
|
|
181
|
+
return t.aggregate ? V(t.aggregate, s) : s;
|
|
182
|
+
}
|
|
183
|
+
case "computed": {
|
|
184
|
+
const s = e.model.computed?.find((a) => a.id === t.id);
|
|
185
|
+
return s ? J(e, s, n) : "NULL";
|
|
186
|
+
}
|
|
187
|
+
case "value":
|
|
188
|
+
return j(e, t.value, r);
|
|
189
|
+
case "values":
|
|
190
|
+
return t.values.map((s) => j(e, s, r)).join(", ") || "NULL";
|
|
191
|
+
case "parameter":
|
|
192
|
+
return H(t.name, e.d);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function I(e, t, r, n) {
|
|
196
|
+
if (t?.kind === "value")
|
|
197
|
+
return G(`${r ? "%" : ""}${t.value}${n ? "%" : ""}`);
|
|
198
|
+
const s = S(e, t, "text"), a = [...r ? ["'%'"] : [], s, ...n ? ["'%'"] : []];
|
|
199
|
+
return W(a, e.d);
|
|
200
|
+
}
|
|
201
|
+
function y(e, t, r, n) {
|
|
202
|
+
return e.d === "postgresql" ? `${t} ${n ? "NOT ILIKE" : "ILIKE"} ${r}` : e.d === "oracle" ? `UPPER(${t}) ${n ? "NOT LIKE" : "LIKE"} UPPER(${r})` : `${t} ${n ? "NOT LIKE" : "LIKE"} ${r}`;
|
|
203
|
+
}
|
|
204
|
+
function ie(e, t) {
|
|
205
|
+
const r = ue(e, t.left), n = S(e, t.left, r), s = () => S(e, t.right, r);
|
|
206
|
+
switch (t.operator) {
|
|
207
|
+
case "eq":
|
|
208
|
+
return `${n} = ${s()}`;
|
|
209
|
+
case "ne":
|
|
210
|
+
return `${n} <> ${s()}`;
|
|
211
|
+
case "gt":
|
|
212
|
+
return `${n} > ${s()}`;
|
|
213
|
+
case "ge":
|
|
214
|
+
return `${n} >= ${s()}`;
|
|
215
|
+
case "lt":
|
|
216
|
+
return `${n} < ${s()}`;
|
|
217
|
+
case "le":
|
|
218
|
+
return `${n} <= ${s()}`;
|
|
219
|
+
case "contains":
|
|
220
|
+
return y(e, n, I(e, t.right, !0, !0), !1);
|
|
221
|
+
case "notContains":
|
|
222
|
+
return y(e, n, I(e, t.right, !0, !0), !0);
|
|
223
|
+
case "startsWith":
|
|
224
|
+
return y(e, n, I(e, t.right, !1, !0), !1);
|
|
225
|
+
case "endsWith":
|
|
226
|
+
return y(e, n, I(e, t.right, !0, !1), !1);
|
|
227
|
+
case "in":
|
|
228
|
+
return `${n} IN (${s()})`;
|
|
229
|
+
case "notIn":
|
|
230
|
+
return `${n} NOT IN (${s()})`;
|
|
231
|
+
case "between":
|
|
232
|
+
return `${n} BETWEEN ${s()} AND ${S(e, t.right2, r)}`;
|
|
233
|
+
case "isEmpty":
|
|
234
|
+
return r === "text" ? `(${n} IS NULL OR ${n} = '')` : `${n} IS NULL`;
|
|
235
|
+
case "isNotEmpty":
|
|
236
|
+
return r === "text" ? `(${n} IS NOT NULL AND ${n} <> '')` : `${n} IS NOT NULL`;
|
|
237
|
+
case "isTrue":
|
|
238
|
+
return `${n} = ${e.d === "postgresql" ? "TRUE" : "1"}`;
|
|
239
|
+
case "isFalse":
|
|
240
|
+
return `${n} = ${e.d === "postgresql" ? "FALSE" : "0"}`;
|
|
241
|
+
case "today":
|
|
242
|
+
return `${Q("date", [n], e.d)} = ${F(e.d)}`;
|
|
243
|
+
case "lastDays": {
|
|
244
|
+
const a = t.right?.kind === "value" ? String(Number(t.right.value) || 0) : s();
|
|
245
|
+
return `${n} >= ${M(/^\d+$/.test(a) ? `-${a}` : `-(${a})`, e.d)}`;
|
|
246
|
+
}
|
|
247
|
+
case "nextDays": {
|
|
248
|
+
const a = t.right?.kind === "value" ? String((Number(t.right.value) || 0) + 1) : `(${s()}) + 1`;
|
|
249
|
+
return `(${n} >= ${F(e.d)} AND ${n} < ${M(a, e.d)})`;
|
|
250
|
+
}
|
|
251
|
+
case "thisMonth":
|
|
252
|
+
case "thisYear": {
|
|
253
|
+
const [a, l] = le(t.operator === "thisMonth" ? "month" : "year", e.d);
|
|
254
|
+
return `(${n} >= ${a} AND ${n} < ${l})`;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const ce = (e, t) => [e.left, e.right, e.right2].every((r) => r?.kind !== "column" || t.has(r.tableId));
|
|
259
|
+
function O(e, t, r) {
|
|
260
|
+
const n = t.items.map(
|
|
261
|
+
(a) => a.kind === "group" ? O(e, a, r) : ce(a, r) ? ie(e, a) : ""
|
|
262
|
+
).filter(Boolean);
|
|
263
|
+
if (!n.length)
|
|
264
|
+
return "";
|
|
265
|
+
const s = n.length === 1 ? n[0] : `(${n.join(` ${t.logic} `)})`;
|
|
266
|
+
return t.not ? `NOT ${n.length === 1 ? `(${s})` : s}` : s;
|
|
267
|
+
}
|
|
268
|
+
function $e(e, t) {
|
|
269
|
+
const r = [];
|
|
270
|
+
return e.model.conditions.forEach((n) => {
|
|
271
|
+
if (!t.has(n.tableId))
|
|
272
|
+
return;
|
|
273
|
+
const s = h(e, n.tableId, n.column), a = n.operator === "BETWEEN" ? `${s} BETWEEN ${n.value} AND ${n.value2 ?? ""}` : n.operator === "IS NULL" || n.operator === "IS NOT NULL" ? `${s} ${n.operator}` : `${s} ${n.operator} ${n.value}`;
|
|
274
|
+
r.push((r.length ? `${n.logicalOperator ?? "AND"} ` : "") + a);
|
|
275
|
+
}), r.join(" ");
|
|
276
|
+
}
|
|
277
|
+
function Te(e, t, r, n) {
|
|
278
|
+
return t == null && r == null ? { tail: [] } : e === "sqlserver" || e === "oracle" ? e === "sqlserver" && !r && t != null ? { top: `TOP ${t} `, tail: [] } : { tail: [
|
|
279
|
+
...e === "sqlserver" && !n ? ["ORDER BY (SELECT NULL)"] : [],
|
|
280
|
+
`OFFSET ${r ?? 0} ROWS`,
|
|
281
|
+
...t != null ? [`FETCH NEXT ${t} ROWS ONLY`] : []
|
|
282
|
+
] } : t == null ? e === "postgresql" ? { tail: [`OFFSET ${r}`] } : {
|
|
283
|
+
tail: [`LIMIT ${e === "mysql" ? "18446744073709551615" : "-1"} OFFSET ${r}`]
|
|
284
|
+
} : { tail: [`LIMIT ${t}${r ? ` OFFSET ${r}` : ""}`] };
|
|
285
|
+
}
|
|
286
|
+
function de(e, t) {
|
|
287
|
+
return new Set(
|
|
288
|
+
e.tables.filter((r) => (se(e, r.id)?.id ?? void 0) === t?.id).map((r) => r.id)
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
function fe(e, t, r) {
|
|
292
|
+
const n = [], s = /* @__PURE__ */ new Set([t]);
|
|
293
|
+
let a = !0;
|
|
294
|
+
for (; a; ) {
|
|
295
|
+
a = !1;
|
|
296
|
+
for (const l of e.joins)
|
|
297
|
+
n.includes(l) || l.nest === "list" || !r.has(l.rightTableId) || s.has(l.leftTableId) && (n.push(l), s.add(l.rightTableId), a = !0);
|
|
298
|
+
}
|
|
299
|
+
return n;
|
|
300
|
+
}
|
|
301
|
+
function he(e, t) {
|
|
302
|
+
return [{ leftColumn: t.leftColumn, rightColumn: t.rightColumn }, ...t.pairs ?? []].map(
|
|
303
|
+
(n) => `${h(e, t.leftTableId, n.leftColumn)} = ${h(e, t.rightTableId, n.rightColumn)}`
|
|
304
|
+
).join(" AND ");
|
|
305
|
+
}
|
|
306
|
+
function k(e, t, r, n) {
|
|
307
|
+
const { model: s, d: a } = e, l = de(s, r), u = b(s, t), i = (o) => o.slice(u.length), T = ne(s).filter((o) => o.tableId ? l.has(o.tableId) : !r), f = new Map(s.groupBy.map((o) => [`${o.tableId}|${o.column}`, o])), g = T.some((o) => o.aggregate), m = [], d = [], C = [];
|
|
308
|
+
for (const o of T) {
|
|
309
|
+
let c;
|
|
310
|
+
if (o.computedId) {
|
|
311
|
+
const R = s.computed.find((x) => x.id === o.computedId);
|
|
312
|
+
c = J(e, R);
|
|
313
|
+
} else {
|
|
314
|
+
c = h(e, o.tableId, o.column);
|
|
315
|
+
const R = f.get(`${o.tableId}|${o.column}`);
|
|
316
|
+
R?.datePart && (c = P(c, R.datePart, a));
|
|
317
|
+
}
|
|
318
|
+
o.aggregate ? c = V(o.aggregate, c) : (g || f.size) && d.push(c);
|
|
319
|
+
const p = i(o.path), N = [...p, o.name].join(".");
|
|
320
|
+
m.push(`${c} AS ${q(N, a)}`), C.push({ ...o, path: p, name: o.name });
|
|
321
|
+
}
|
|
322
|
+
for (const o of s.groupBy) {
|
|
323
|
+
if (!l.has(o.tableId))
|
|
324
|
+
continue;
|
|
325
|
+
let c = h(e, o.tableId, o.column);
|
|
326
|
+
o.datePart && (c = P(c, o.datePart, a)), d.includes(c) || d.push(c);
|
|
327
|
+
}
|
|
328
|
+
const U = [];
|
|
329
|
+
if (s.joins.filter((o) => o.nest === "list" && l.has(o.leftTableId)).forEach((o, c) => {
|
|
330
|
+
const p = `__key${c + 1}`, N = h(e, o.leftTableId, o.leftColumn);
|
|
331
|
+
m.push(`${N} AS ${q(p, a)}`), d.length && !d.includes(N) && d.push(N), U.push({ join: o, parentKey: p });
|
|
332
|
+
}), r) {
|
|
333
|
+
const o = h(e, r.rightTableId, r.rightColumn);
|
|
334
|
+
m.push(`${o} AS ${q(L, a)}`), d.length && !d.includes(o) && d.push(o);
|
|
335
|
+
}
|
|
336
|
+
const X = e.byId.get(t), z = !r && n === "object", D = s.sorts.filter((o) => l.has(o.tableId)).map((o) => `${h(e, o.tableId, o.column)} ${o.direction}`), v = Te(
|
|
337
|
+
a,
|
|
338
|
+
z ? 1 : r ? void 0 : s.limit,
|
|
339
|
+
r ? void 0 : s.offset,
|
|
340
|
+
D.length > 0
|
|
341
|
+
), E = [], Z = s.distinct ? "DISTINCT " : "";
|
|
342
|
+
E.push(
|
|
343
|
+
`SELECT ${v.top ?? ""}${Z}${m.length ? `
|
|
344
|
+
${m.join(`,
|
|
345
|
+
`)}` : "*"}`
|
|
346
|
+
), E.push(`FROM ${_(e, X)}`);
|
|
347
|
+
for (const o of fe(s, t, l)) {
|
|
348
|
+
const c = e.byId.get(o.rightTableId);
|
|
349
|
+
c && E.push(`${o.type} JOIN ${_(e, c)} ON ${he(e, o)}`);
|
|
350
|
+
}
|
|
351
|
+
const Y = [
|
|
352
|
+
...s.filter ? [O(e, s.filter, l)] : r ? [] : [$e(e, l)],
|
|
353
|
+
...r ? [
|
|
354
|
+
`${h(e, r.rightTableId, r.rightColumn)} IN (${H(K, a)})`
|
|
355
|
+
] : []
|
|
356
|
+
].filter(Boolean);
|
|
357
|
+
Y.length && E.push(`WHERE ${Y.join(`
|
|
358
|
+
AND `)}`), d.length && E.push(`GROUP BY ${d.join(", ")}`);
|
|
359
|
+
const w = s.having ? O(e, s.having, l) : "";
|
|
360
|
+
return w && d.length + (g ? 1 : 0) > 0 && E.push(`HAVING ${w}`), D.length && E.push(`ORDER BY ${D.join(", ")}`), E.push(...v.tail), { sql: E.join(`
|
|
361
|
+
`), columns: C, lists: U };
|
|
362
|
+
}
|
|
363
|
+
function Ee(e, t) {
|
|
364
|
+
return t === "flat" ? {
|
|
365
|
+
...e,
|
|
366
|
+
joins: e.joins.map(
|
|
367
|
+
(r) => r.nest && r.nest !== "flat" ? { ...r, nest: "flat" } : r
|
|
368
|
+
)
|
|
369
|
+
} : e;
|
|
370
|
+
}
|
|
371
|
+
function ge(e, t = {}) {
|
|
372
|
+
const r = t.shape ?? "list", n = Ee(e, r), s = {
|
|
373
|
+
model: n,
|
|
374
|
+
d: t.dialect ?? "postgresql",
|
|
375
|
+
byId: new Map(n.tables.map((i) => [i.id, i])),
|
|
376
|
+
sources: t.sources ?? {}
|
|
377
|
+
}, a = ee(n);
|
|
378
|
+
if (!a)
|
|
379
|
+
return { sql: "", parameters: [], columns: [], lists: [] };
|
|
380
|
+
const l = (i, $) => i.map(({ join: T, parentKey: f }) => {
|
|
381
|
+
const g = k(s, T.rightTableId, T, r), m = b(n, $), d = s.byId.get(T.rightTableId);
|
|
382
|
+
return {
|
|
383
|
+
path: [
|
|
384
|
+
...b(n, T.leftTableId).slice(m.length),
|
|
385
|
+
re(T, d)
|
|
386
|
+
],
|
|
387
|
+
parentKey: f,
|
|
388
|
+
sql: g.sql,
|
|
389
|
+
columns: g.columns,
|
|
390
|
+
lists: l(g.lists, T.rightTableId)
|
|
391
|
+
};
|
|
392
|
+
}), u = k(s, a, void 0, r);
|
|
393
|
+
return {
|
|
394
|
+
sql: u.sql,
|
|
395
|
+
parameters: te(n),
|
|
396
|
+
columns: u.columns,
|
|
397
|
+
lists: l(u.lists, a)
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
function Ne(e, t = {}) {
|
|
401
|
+
return ge(e, t).sql;
|
|
402
|
+
}
|
|
403
|
+
function Se(e) {
|
|
404
|
+
const t = [e.sql], r = (n, s) => {
|
|
405
|
+
for (const a of n) {
|
|
406
|
+
const l = [...s, ...a.path];
|
|
407
|
+
t.push(`-- ${l.join(".")} (${K}: ${a.parentKey})
|
|
408
|
+
${a.sql}`), r(a.lists, l);
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
return r(e.lists, []), t.join(`
|
|
412
|
+
|
|
413
|
+
`);
|
|
414
|
+
}
|
|
415
|
+
function me(e) {
|
|
416
|
+
const t = {}, r = /* @__PURE__ */ new Map();
|
|
417
|
+
for (const [s, a] of Object.entries(e)) {
|
|
418
|
+
const l = s.split(".");
|
|
419
|
+
if (l.length === 1) {
|
|
420
|
+
t[s] = a;
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
let u = t;
|
|
424
|
+
for (let i = 0; i < l.length - 1; i++) {
|
|
425
|
+
const $ = l[i];
|
|
426
|
+
(!u[$] || typeof u[$] != "object") && (u[$] = {}, r.set(l.slice(0, i + 1).join("."), u[$])), u = u[$];
|
|
427
|
+
}
|
|
428
|
+
u[l[l.length - 1]] = a;
|
|
429
|
+
}
|
|
430
|
+
const n = (s) => Object.values(s).every(
|
|
431
|
+
(a) => a == null || typeof a == "object" && !Array.isArray(a) && n(a)
|
|
432
|
+
);
|
|
433
|
+
for (const [s, a] of [...r.entries()].sort((l, u) => u[0].length - l[0].length))
|
|
434
|
+
if (n(a)) {
|
|
435
|
+
const l = s.split(".");
|
|
436
|
+
let u = t;
|
|
437
|
+
for (const i of l.slice(0, -1))
|
|
438
|
+
u = u[i];
|
|
439
|
+
u[l[l.length - 1]] = null;
|
|
440
|
+
}
|
|
441
|
+
return t;
|
|
442
|
+
}
|
|
443
|
+
function Ae(e, t, r) {
|
|
444
|
+
let n = e;
|
|
445
|
+
for (const s of t.slice(0, -1))
|
|
446
|
+
(!n[s] || typeof n[s] != "object") && (n[s] = {}), n = n[s];
|
|
447
|
+
n[t[t.length - 1]] = r;
|
|
448
|
+
}
|
|
449
|
+
function Re(e, t, r) {
|
|
450
|
+
const n = (s, a) => {
|
|
451
|
+
const l = a.map((u) => {
|
|
452
|
+
const i = /* @__PURE__ */ new Map();
|
|
453
|
+
for (const $ of n(r(u), u.lists)) {
|
|
454
|
+
const T = String($[L]);
|
|
455
|
+
delete $[L], i.set(T, [...i.get(T) ?? [], $]);
|
|
456
|
+
}
|
|
457
|
+
return { l: u, byParent: i };
|
|
458
|
+
});
|
|
459
|
+
return s.map((u) => {
|
|
460
|
+
const i = new Map(l.map(({ l: f }) => [f, u[f.parentKey]])), $ = { ...u };
|
|
461
|
+
for (const { l: f } of l)
|
|
462
|
+
delete $[f.parentKey];
|
|
463
|
+
const T = me($);
|
|
464
|
+
for (const { l: f, byParent: g } of l)
|
|
465
|
+
Ae(T, f.path, g.get(String(i.get(f))) ?? []);
|
|
466
|
+
return T;
|
|
467
|
+
});
|
|
468
|
+
};
|
|
469
|
+
return n(t, e.lists);
|
|
470
|
+
}
|
|
471
|
+
export {
|
|
472
|
+
K as PARENT_KEYS_PARAMETER,
|
|
473
|
+
L as PARENT_KEY_COLUMN,
|
|
474
|
+
Re as assembleQueryRows,
|
|
475
|
+
P as datePartSql,
|
|
476
|
+
Q as functionSql,
|
|
477
|
+
Ne as generateQuerySql,
|
|
478
|
+
ge as planQuerySql,
|
|
479
|
+
Se as planSqlText,
|
|
480
|
+
q as quoteSqlName
|
|
481
|
+
};
|
package/dist/editors.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./no-code-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./no-code-B1jzfUF5.cjs"),i=require("./NiceForm-BWb4LTQJ.cjs"),e=require("./NiceMention-CYRqPKGU.cjs"),o=require("./pickerCommons-CwcCc8Qi.cjs"),N=require("./NiceColorPicker-BLwYNSXJ.cjs"),t=require("./NiceHtmlEditor-BzECmDO3.cjs"),r=require("./NiceCodeEditor-DhdjnDLV.cjs");exports.NiceCheckbox=c.NiceCheckbox;exports.NiceNumberInput=c.NiceNumberInput;exports.NiceSelect=c.NiceSelect;exports.NiceTextInput=c.NiceTextInput;exports.MASK_PRESETS=i.MASK_PRESETS;exports.NiceAutocomplete=i.NiceAutocomplete;exports.NiceCalendar=i.NiceCalendar;exports.NiceCountryPicker=i.NiceCountryPicker;exports.NiceDateTimePicker=i.NiceDateTimePicker;exports.NiceForm=i.NiceForm;exports.NiceMaskedInput=i.NiceMaskedInput;exports.NicePasswordInput=i.NicePasswordInput;exports.NiceRadioGroup=i.NiceRadioGroup;exports.NiceRating=i.NiceRating;exports.NiceSlider=i.NiceSlider;exports.NiceTagBox=i.NiceTagBox;exports.NiceTextArea=i.NiceTextArea;exports.NiceUpload=i.NiceUpload;exports.NICE_COLOR_PRESET_KEYS=e.NICE_COLOR_PRESET_KEYS;exports.NiceAccountPicker=e.NiceAccountPicker;exports.NiceAddressInput=e.NiceAddressInput;exports.NiceCodeEditorAI=e.NiceCodeEditorAI;exports.NiceColorPalette=e.NiceColorPalette;exports.NiceContactPicker=e.NiceContactPicker;exports.NiceCropEditor=e.NiceCropEditor;exports.NiceDateRangeBox=e.NiceDateRangeBox;exports.NiceDocumentEditor=e.NiceDocumentEditor;exports.NiceDropDownBox=e.NiceDropDownBox;exports.NiceEmojiPicker=e.NiceEmojiPicker;exports.NiceGradientPicker=e.NiceGradientPicker;exports.NiceHtmlEditorAI=e.NiceHtmlEditorAI;exports.NiceImageAnnotator=e.NiceImageAnnotator;exports.NiceImageEditor=e.NiceImageEditor;exports.NiceInputOtp=e.NiceInputOtp;exports.NiceInvoiceLineEditor=e.NiceInvoiceLineEditor;exports.NiceKeyValueEditor=e.NiceKeyValueEditor;exports.NiceKnob=e.NiceKnob;exports.NiceLogConsole=e.NiceLogConsole;exports.NiceLookup=e.NiceLookup;exports.NiceMarkdownEditor=e.NiceMarkdownEditor;exports.NiceMention=e.NiceMention;exports.NicePDFAnnotationEditor=e.NicePDFAnnotationEditor;exports.NicePickList=e.NicePickList;exports.NiceRangeSlider=e.NiceRangeSlider;exports.NiceScannerControl=e.NiceScannerControl;exports.NiceScriptRunner=e.NiceScriptRunner;exports.NiceSignature=e.NiceSignature;exports.NiceTreeSelect=e.NiceTreeSelect;exports.NiceWiki=e.NiceWiki;exports.NiceToggle=o.NiceToggle;exports.NiceColorPicker=N.NiceColorPicker;exports.NiceHtmlEditor=t.NiceHtmlEditor;exports.NiceCodeEditor=r.NiceCodeEditor;
|