@nongt/visql 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +916 -2
- package/dist/PipelineEditor-DNZkDSaY.js +10042 -0
- package/dist/calendarDate-CYlr9TvX.js +43 -0
- package/dist/core-api-CBN6rAQG.js +1052 -0
- package/dist/core.js +80 -0
- package/dist/fixtures.js +7 -0
- package/dist/index.js +145 -0
- package/dist/issueLocation-Cw5sttQL.js +3183 -0
- package/dist/mui-date-pickers.js +117 -0
- package/dist/mui.js +510 -0
- package/dist/schema-z95dxLxu.js +839 -0
- package/dist/sql-import.js +1366 -0
- package/dist/style.css +1 -0
- package/dist/tokens-BTaVMSOx.js +95 -0
- package/dist/types/adapters/mui/MuiDatePicker.d.ts +12 -0
- package/dist/types/adapters/mui/MuiDateTimePicker.d.ts +10 -0
- package/dist/types/adapters/mui/MuiListInput.d.ts +9 -0
- package/dist/types/adapters/mui/MuiTimePicker.d.ts +10 -0
- package/dist/types/adapters/mui/QueryBuilder.d.ts +12 -0
- package/dist/types/adapters/mui/components.d.ts +16 -0
- package/dist/types/adapters/mui/index.d.ts +6 -0
- package/dist/types/adapters/mui/muiPickers.d.ts +6 -0
- package/dist/types/adapters/mui/pickerStyles.d.ts +28 -0
- package/dist/types/adapters/mui/theme.d.ts +11 -0
- package/dist/types/core/BetweenOnTextContext.d.ts +11 -0
- package/dist/types/core/DialectContext.d.ts +10 -0
- package/dist/types/core/DrillDownContext.d.ts +22 -0
- package/dist/types/core/ExistsContext.d.ts +29 -0
- package/dist/types/core/FlowDirectionContext.d.ts +8 -0
- package/dist/types/core/FlowOrientationContext.d.ts +6 -0
- package/dist/types/core/FunctionsContext.d.ts +25 -0
- package/dist/types/core/GroupKeysContext.d.ts +18 -0
- package/dist/types/core/MeasureLockContext.d.ts +12 -0
- package/dist/types/core/ReadOnlyContext.d.ts +6 -0
- package/dist/types/core/SchemaContext.d.ts +8 -0
- package/dist/types/core/SubqueryContext.d.ts +16 -0
- package/dist/types/core/UnionBranchContext.d.ts +6 -0
- package/dist/types/core/ValueInputContext.d.ts +24 -0
- package/dist/types/core/absolutePath.d.ts +57 -0
- package/dist/types/core/ast.d.ts +154 -0
- package/dist/types/core/astChildren.d.ts +4 -0
- package/dist/types/core/astEqual.d.ts +4 -0
- package/dist/types/core/astMap.d.ts +21 -0
- package/dist/types/core/calendarDate.d.ts +21 -0
- package/dist/types/core/columnFormats.d.ts +23 -0
- package/dist/types/core/components/BoolPicker.d.ts +8 -0
- package/dist/types/core/components/NumberInput.d.ts +8 -0
- package/dist/types/core/components/ReadOnlyPart.d.ts +10 -0
- package/dist/types/core/components/TextInput.d.ts +8 -0
- package/dist/types/core/components/expression/BinaryView.d.ts +10 -0
- package/dist/types/core/components/expression/ExprSummary.d.ts +12 -0
- package/dist/types/core/components/expression/ExpressionTypeSelector.d.ts +35 -0
- package/dist/types/core/components/expression/ExpressionView.d.ts +30 -0
- package/dist/types/core/components/expression/FieldView.d.ts +15 -0
- package/dist/types/core/components/expression/FormulaPeek.d.ts +14 -0
- package/dist/types/core/components/expression/FunctionArgInput.d.ts +22 -0
- package/dist/types/core/components/expression/FunctionView.d.ts +7 -0
- package/dist/types/core/components/expression/ListView.d.ts +20 -0
- package/dist/types/core/components/expression/LiteralView.d.ts +23 -0
- package/dist/types/core/components/expression/LogicalView.d.ts +9 -0
- package/dist/types/core/components/expression/MeasureMenu.d.ts +21 -0
- package/dist/types/core/components/expression/ParamView.d.ts +13 -0
- package/dist/types/core/components/expression/RelativeDateView.d.ts +15 -0
- package/dist/types/core/components/expression/SubqueryView.d.ts +8 -0
- package/dist/types/core/components/expression/formulaClasses.d.ts +8 -0
- package/dist/types/core/components/flow/CaseBranchFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/CaseElseFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/CaseFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/ConditionFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/CreateConditionFlowNode.d.ts +14 -0
- package/dist/types/core/components/flow/CreateHavingFlowNode.d.ts +11 -0
- package/dist/types/core/components/flow/DistinctToggle.d.ts +10 -0
- package/dist/types/core/components/flow/ExistsFlowNode.d.ts +9 -0
- package/dist/types/core/components/flow/FromFlowNode.d.ts +110 -0
- package/dist/types/core/components/flow/FunctionArgFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/FunctionCallFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/FunctionSortKeys.d.ts +10 -0
- package/dist/types/core/components/flow/GroupBgNode.d.ts +14 -0
- package/dist/types/core/components/flow/GroupByFlowNode.d.ts +29 -0
- package/dist/types/core/components/flow/IfElseFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/IfFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/IfThenFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/LeafConditionFrame.d.ts +19 -0
- package/dist/types/core/components/flow/LogicalFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/MoveTooltip.d.ts +19 -0
- package/dist/types/core/components/flow/NotFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/OrderByFlowNode.d.ts +32 -0
- package/dist/types/core/components/flow/SectionLabelFlowNode.d.ts +7 -0
- package/dist/types/core/components/flow/SelectFlowNode.d.ts +49 -0
- package/dist/types/core/components/flow/SharedQueriesFlowNode.d.ts +39 -0
- package/dist/types/core/components/flow/SummaryPill.d.ts +12 -0
- package/dist/types/core/components/flow/WarningNote.d.ts +9 -0
- package/dist/types/core/components/flow/chainSides.d.ts +18 -0
- package/dist/types/core/components/flow/dragContext.d.ts +12 -0
- package/dist/types/core/components/flow/moveTooltipHysteresis.d.ts +18 -0
- package/dist/types/core/components/flow/useRowDrag.d.ts +34 -0
- package/dist/types/core/components/flow/useRowReorderFlip.d.ts +30 -0
- package/dist/types/core/derivedTables.d.ts +98 -0
- package/dist/types/core/distinctSort.d.ts +7 -0
- package/dist/types/core/drillPath.d.ts +11 -0
- package/dist/types/core/exists.d.ts +7 -0
- package/dist/types/core/existsMenu.d.ts +61 -0
- package/dist/types/core/expressionFlow.d.ts +428 -0
- package/dist/types/core/fanOut.d.ts +58 -0
- package/dist/types/core/findParts.d.ts +19 -0
- package/dist/types/core/flowTrees.d.ts +20 -0
- package/dist/types/core/focusKey.d.ts +10 -0
- package/dist/types/core/formula.d.ts +24 -0
- package/dist/types/core/formulaPeek.d.ts +16 -0
- package/dist/types/core/functionRegistry.d.ts +117 -0
- package/dist/types/core/grouping.d.ts +58 -0
- package/dist/types/core/history.d.ts +25 -0
- package/dist/types/core/i18n/defaultMessages.d.ts +367 -0
- package/dist/types/core/i18n/messages.d.ts +273 -0
- package/dist/types/core/i18n/relativeDateWords.d.ts +3 -0
- package/dist/types/core/id.d.ts +5 -0
- package/dist/types/core/issueAnchor.d.ts +29 -0
- package/dist/types/core/issueLocation.d.ts +105 -0
- package/dist/types/core/limits.d.ts +17 -0
- package/dist/types/core/measures.d.ts +51 -0
- package/dist/types/core/params.d.ts +30 -0
- package/dist/types/core/pipelineAnchor.d.ts +118 -0
- package/dist/types/core/pipelineFlow.d.ts +271 -0
- package/dist/types/core/queryAst.d.ts +201 -0
- package/dist/types/core/queryHelpers.d.ts +113 -0
- package/dist/types/core/queryValidation.d.ts +206 -0
- package/dist/types/core/relativeDates.d.ts +11 -0
- package/dist/types/core/resolveNames.d.ts +17 -0
- package/dist/types/core/rowRange.d.ts +3 -0
- package/dist/types/core/schema.d.ts +119 -0
- package/dist/types/core/scopeQuery.d.ts +45 -0
- package/dist/types/core/selectColumns.d.ts +23 -0
- package/dist/types/core/settleQuery.d.ts +11 -0
- package/dist/types/core/sharedQueries.d.ts +66 -0
- package/dist/types/core/sqlGen.d.ts +102 -0
- package/dist/types/core/sqlOffsets.d.ts +5 -0
- package/dist/types/core/sqlSpans.d.ts +33 -0
- package/dist/types/core/storedQuery.d.ts +43 -0
- package/dist/types/core/summarize.d.ts +3 -0
- package/dist/types/core/theme/tokens.d.ts +74 -0
- package/dist/types/core/ui/UIContext.d.ts +6 -0
- package/dist/types/core/ui/index.d.ts +12 -0
- package/dist/types/core/ui/types.d.ts +264 -0
- package/dist/types/core/unionTables.d.ts +121 -0
- package/dist/types/core/useValueTypes.d.ts +12 -0
- package/dist/types/core/valueTypes.d.ts +54 -0
- package/dist/types/core-api.d.ts +20 -0
- package/dist/types/features/queryEditor/ExpressionFlowCanvas.d.ts +10 -0
- package/dist/types/features/queryEditor/FindBox.d.ts +12 -0
- package/dist/types/features/queryEditor/FlowCanvas.d.ts +96 -0
- package/dist/types/features/queryEditor/FocusPulse.d.ts +10 -0
- package/dist/types/features/queryEditor/IssuesButton.d.ts +16 -0
- package/dist/types/features/queryEditor/PipelineEditor.d.ts +210 -0
- package/dist/types/features/queryEditor/QueryOutline.d.ts +16 -0
- package/dist/types/features/queryEditor/ResultsPanel.d.ts +11 -0
- package/dist/types/features/queryEditor/RunButton.d.ts +11 -0
- package/dist/types/features/queryEditor/SubFlowPanel.d.ts +24 -0
- package/dist/types/features/queryEditor/UndoRedoToast.d.ts +6 -0
- package/dist/types/features/queryEditor/canvasPositioning.d.ts +81 -0
- package/dist/types/features/queryEditor/findKeys.d.ts +3 -0
- package/dist/types/features/queryEditor/flowDragUtils.d.ts +16 -0
- package/dist/types/features/queryEditor/focusContext.d.ts +24 -0
- package/dist/types/features/queryEditor/hoveredPart.d.ts +32 -0
- package/dist/types/features/queryEditor/issueFocusParts.d.ts +9 -0
- package/dist/types/features/queryEditor/issueLocationText.d.ts +7 -0
- package/dist/types/features/queryEditor/issueText.d.ts +11 -0
- package/dist/types/features/queryEditor/outlineSections.d.ts +23 -0
- package/dist/types/features/queryEditor/run.d.ts +36 -0
- package/dist/types/features/queryEditor/sectionLabels.d.ts +15 -0
- package/dist/types/features/queryEditor/treeScopeContext.d.ts +14 -0
- package/dist/types/features/queryEditor/useRemeasureOnDirectionChange.d.ts +7 -0
- package/dist/types/features/queryEditor/useRevealNewNodes.d.ts +35 -0
- package/dist/types/features/queryEditor/withTreeScope.d.ts +10 -0
- package/dist/types/fixtures.d.ts +44 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/mui-date-pickers.d.ts +3 -0
- package/dist/types/mui.d.ts +2 -0
- package/dist/types/sql-import.d.ts +3 -0
- package/dist/types/sqlImport/context.d.ts +71 -0
- package/dist/types/sqlImport/expressions.d.ts +11 -0
- package/dist/types/sqlImport/importSql.d.ts +28 -0
- package/dist/types/sqlImport/parse.d.ts +6 -0
- package/dist/types/sqlImport/syntax.d.ts +245 -0
- package/dist/types/sqlImport/tokenize.d.ts +26 -0
- package/package.json +164 -3
|
@@ -0,0 +1,839 @@
|
|
|
1
|
+
function b(e) {
|
|
2
|
+
switch (e.type) {
|
|
3
|
+
case "function":
|
|
4
|
+
return e.orderBy ? [...e.args, ...e.orderBy.map((t) => t.expression)] : e.args;
|
|
5
|
+
case "binary":
|
|
6
|
+
return e.right ? [e.left, e.right] : [e.left];
|
|
7
|
+
case "logical":
|
|
8
|
+
return e.operands;
|
|
9
|
+
case "list":
|
|
10
|
+
return e.items;
|
|
11
|
+
case "not":
|
|
12
|
+
return [e.operand];
|
|
13
|
+
case "if":
|
|
14
|
+
return [e.condition, e.then, e.else].filter((t) => t !== void 0);
|
|
15
|
+
case "case":
|
|
16
|
+
return [
|
|
17
|
+
...e.subject ? [e.subject] : [],
|
|
18
|
+
...e.branches.flatMap((t) => [t.when, t.then]),
|
|
19
|
+
...e.else ? [e.else] : []
|
|
20
|
+
];
|
|
21
|
+
// In the order its SQL writes them: joins, then WHERE <link> AND <where>.
|
|
22
|
+
case "exists":
|
|
23
|
+
return [
|
|
24
|
+
...e.query.joins.flatMap((t) => t.on ? [t.on] : []),
|
|
25
|
+
e.link,
|
|
26
|
+
...e.query.where ? [e.query.where] : []
|
|
27
|
+
];
|
|
28
|
+
// A sub query (IN's right side) is another query: nothing under it
|
|
29
|
+
// belongs to this one (see SubqueryNode).
|
|
30
|
+
default:
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const W = ["inner", "left", "right", "full", "cross"];
|
|
35
|
+
function v(e) {
|
|
36
|
+
return "union" in e;
|
|
37
|
+
}
|
|
38
|
+
function X(e) {
|
|
39
|
+
return v(e) ? e.union : [e];
|
|
40
|
+
}
|
|
41
|
+
function Q(e) {
|
|
42
|
+
return v(e) ? e.union[0] : e;
|
|
43
|
+
}
|
|
44
|
+
function T(e, t) {
|
|
45
|
+
if (!v(e)) return t(e, 0);
|
|
46
|
+
const r = e.union.map((a, u) => t(a, u));
|
|
47
|
+
return r.every((a, u) => a === e.union[u]) ? e : { ...e, union: r };
|
|
48
|
+
}
|
|
49
|
+
function K(e, t) {
|
|
50
|
+
if (!e.shared) return e;
|
|
51
|
+
let r = !1;
|
|
52
|
+
const a = e.shared.map((u) => {
|
|
53
|
+
const n = t(u.query, u);
|
|
54
|
+
return n === u.query ? u : (r = !0, { ...u, query: n });
|
|
55
|
+
});
|
|
56
|
+
return r ? { ...e, shared: a } : e;
|
|
57
|
+
}
|
|
58
|
+
function J(e) {
|
|
59
|
+
return "from" in e;
|
|
60
|
+
}
|
|
61
|
+
const z = 63;
|
|
62
|
+
function I(e) {
|
|
63
|
+
return e.alias || e.table || "";
|
|
64
|
+
}
|
|
65
|
+
function Z(e) {
|
|
66
|
+
return e.alias ? e.alias : e.expression.type === "field" ? e.expression.column : void 0;
|
|
67
|
+
}
|
|
68
|
+
function y(e) {
|
|
69
|
+
return [e.from, ...e.joins];
|
|
70
|
+
}
|
|
71
|
+
function q(e) {
|
|
72
|
+
return y(e).flatMap((t) => t.table === void 0 ? [] : [t.table]);
|
|
73
|
+
}
|
|
74
|
+
function R(e, t) {
|
|
75
|
+
const r = t;
|
|
76
|
+
switch (e.type) {
|
|
77
|
+
case "function":
|
|
78
|
+
return {
|
|
79
|
+
...e,
|
|
80
|
+
args: e.args.map(r),
|
|
81
|
+
...e.orderBy ? { orderBy: e.orderBy.map((a) => ({ ...a, expression: r(a.expression) })) } : {}
|
|
82
|
+
};
|
|
83
|
+
case "binary":
|
|
84
|
+
return {
|
|
85
|
+
...e,
|
|
86
|
+
left: r(e.left),
|
|
87
|
+
...e.right ? { right: r(e.right) } : {}
|
|
88
|
+
};
|
|
89
|
+
case "logical":
|
|
90
|
+
return { ...e, operands: e.operands.map(r) };
|
|
91
|
+
case "list":
|
|
92
|
+
return { ...e, items: e.items.map(r) };
|
|
93
|
+
case "not":
|
|
94
|
+
return { ...e, operand: r(e.operand) };
|
|
95
|
+
case "if":
|
|
96
|
+
return {
|
|
97
|
+
...e,
|
|
98
|
+
condition: e.condition && r(e.condition),
|
|
99
|
+
then: e.then && r(e.then),
|
|
100
|
+
else: e.else && r(e.else)
|
|
101
|
+
};
|
|
102
|
+
case "case":
|
|
103
|
+
return {
|
|
104
|
+
...e,
|
|
105
|
+
subject: e.subject && r(e.subject),
|
|
106
|
+
branches: e.branches.map((a) => ({ when: r(a.when), then: r(a.then) })),
|
|
107
|
+
else: e.else && r(e.else)
|
|
108
|
+
};
|
|
109
|
+
case "exists":
|
|
110
|
+
return {
|
|
111
|
+
...e,
|
|
112
|
+
link: r(e.link),
|
|
113
|
+
query: {
|
|
114
|
+
...e.query,
|
|
115
|
+
joins: e.query.joins.map((a) => a.on ? { ...a, on: r(a.on) } : a),
|
|
116
|
+
...e.query.where ? { where: r(e.query.where) } : {}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
default:
|
|
120
|
+
return e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function C(e, t) {
|
|
124
|
+
const r = R(e, (a) => C(a, t));
|
|
125
|
+
return r === e ? t(e) : r;
|
|
126
|
+
}
|
|
127
|
+
function ee(e) {
|
|
128
|
+
return [
|
|
129
|
+
...e.where ? [e.where] : [],
|
|
130
|
+
...e.joins.flatMap((t) => t.on ? [t.on] : []),
|
|
131
|
+
...e.select.map((t) => t.expression),
|
|
132
|
+
...(e.groupBy ?? []).map((t) => t.expression),
|
|
133
|
+
...e.having ? [e.having] : [],
|
|
134
|
+
...(e.orderBy ?? []).map((t) => t.expression)
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
function S(e, t, r = (a) => S(a, t)) {
|
|
138
|
+
var n, l;
|
|
139
|
+
const a = t, { shared: u } = e;
|
|
140
|
+
return {
|
|
141
|
+
...e,
|
|
142
|
+
...u ? {
|
|
143
|
+
shared: u.map((s) => ({ ...s, query: T(s.query, r) }))
|
|
144
|
+
} : {},
|
|
145
|
+
from: e.from.query ? { ...e.from, query: T(e.from.query, r) } : e.from,
|
|
146
|
+
where: e.where && a(e.where),
|
|
147
|
+
joins: e.joins.map((s) => s.query ? { ...s, on: s.on && a(s.on), query: T(s.query, r) } : { ...s, on: s.on && a(s.on) }),
|
|
148
|
+
select: e.select.map((s) => ({ ...s, expression: a(s.expression) })),
|
|
149
|
+
groupBy: (n = e.groupBy) == null ? void 0 : n.map((s) => ({ ...s, expression: a(s.expression) })),
|
|
150
|
+
having: e.having && a(e.having),
|
|
151
|
+
orderBy: (l = e.orderBy) == null ? void 0 : l.map((s) => ({ ...s, expression: a(s.expression) }))
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function w(e, t) {
|
|
155
|
+
const r = (a) => a.type === "subquery" ? { ...a, query: w(a.query, t) } : R(a, r);
|
|
156
|
+
return S(e, (a) => C(r(a), t));
|
|
157
|
+
}
|
|
158
|
+
function B(e) {
|
|
159
|
+
return new Set([e.from, ...e.joins].map(I));
|
|
160
|
+
}
|
|
161
|
+
function L(e) {
|
|
162
|
+
return e !== void 0 && (e.type === "exists" || b(e).some(L));
|
|
163
|
+
}
|
|
164
|
+
function G(e) {
|
|
165
|
+
const t = B(e.query), r = (a) => a.type === "field" ? [a] : b(a).flatMap(r);
|
|
166
|
+
return r(e.link).filter((a) => a.table !== void 0 && !t.has(a.table));
|
|
167
|
+
}
|
|
168
|
+
const te = {
|
|
169
|
+
"date-expr": ["date", "dateTime"],
|
|
170
|
+
"num-expr": ["integer", "decimal"],
|
|
171
|
+
"str-expr": ["varchar"]
|
|
172
|
+
}, i = { type: "field" }, Y = [
|
|
173
|
+
"YEAR",
|
|
174
|
+
"QUARTER",
|
|
175
|
+
"MONTH",
|
|
176
|
+
"WEEK",
|
|
177
|
+
"DAY",
|
|
178
|
+
"HOUR",
|
|
179
|
+
"MINUTE",
|
|
180
|
+
"SECOND",
|
|
181
|
+
"MILLISECOND"
|
|
182
|
+
];
|
|
183
|
+
function re(e, t) {
|
|
184
|
+
if (t < e.args.length) return e.args[t];
|
|
185
|
+
const r = e.args[e.args.length - 1];
|
|
186
|
+
return r != null && r.variadic ? r : void 0;
|
|
187
|
+
}
|
|
188
|
+
function ae(e) {
|
|
189
|
+
return e.args.map((t) => t.default ?? { type: "literal", value: "" });
|
|
190
|
+
}
|
|
191
|
+
const d = (e, t = "DAY") => ({
|
|
192
|
+
label: e,
|
|
193
|
+
kind: "unit",
|
|
194
|
+
choices: Y,
|
|
195
|
+
default: { type: "literal", value: t }
|
|
196
|
+
}), h = {
|
|
197
|
+
// ---- Aggregate ----
|
|
198
|
+
// COUNT with no argument is COUNT(*), and `distinct` on the call makes it
|
|
199
|
+
// COUNT(DISTINCT x) — see the function sub-canvas's count choice.
|
|
200
|
+
COUNT: {
|
|
201
|
+
name: "COUNT",
|
|
202
|
+
returns: "integer",
|
|
203
|
+
aggregate: !0,
|
|
204
|
+
args: [{
|
|
205
|
+
label: "value",
|
|
206
|
+
kind: "expr",
|
|
207
|
+
optional: !0,
|
|
208
|
+
default: i
|
|
209
|
+
}]
|
|
210
|
+
},
|
|
211
|
+
SUM: {
|
|
212
|
+
name: "SUM",
|
|
213
|
+
returns: "number",
|
|
214
|
+
aggregate: !0,
|
|
215
|
+
args: [{ label: "value", kind: "num-expr", default: i }]
|
|
216
|
+
},
|
|
217
|
+
AVG: {
|
|
218
|
+
name: "AVG",
|
|
219
|
+
returns: "number",
|
|
220
|
+
aggregate: !0,
|
|
221
|
+
args: [{ label: "value", kind: "num-expr", default: i }]
|
|
222
|
+
},
|
|
223
|
+
MIN: {
|
|
224
|
+
name: "MIN",
|
|
225
|
+
returns: "arg",
|
|
226
|
+
aggregate: !0,
|
|
227
|
+
args: [{ label: "value", kind: "expr", default: i }]
|
|
228
|
+
},
|
|
229
|
+
MAX: {
|
|
230
|
+
name: "MAX",
|
|
231
|
+
returns: "arg",
|
|
232
|
+
aggregate: !0,
|
|
233
|
+
args: [{ label: "value", kind: "expr", default: i }]
|
|
234
|
+
},
|
|
235
|
+
// A group's values joined into one text (issue 137). Written in each
|
|
236
|
+
// dialect's own form (see sqlGen); `distinct` on the call joins the
|
|
237
|
+
// different values only, which SQL Server can't. MySQL cuts the text at
|
|
238
|
+
// group_concat_max_len (1024 bytes by default).
|
|
239
|
+
STRING_AGG: {
|
|
240
|
+
name: "STRING_AGG",
|
|
241
|
+
returns: "text",
|
|
242
|
+
aggregate: !0,
|
|
243
|
+
aliases: ["GROUP_CONCAT", "LISTAGG"],
|
|
244
|
+
args: [
|
|
245
|
+
{ label: "value", kind: "expr", default: i },
|
|
246
|
+
{
|
|
247
|
+
label: "separator",
|
|
248
|
+
kind: "fixed-text",
|
|
249
|
+
optional: !0,
|
|
250
|
+
default: { type: "literal", value: ", " }
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
},
|
|
254
|
+
// ---- Date arithmetic ----
|
|
255
|
+
DATE_ADD: {
|
|
256
|
+
name: "DATE_ADD",
|
|
257
|
+
returns: "arg",
|
|
258
|
+
args: [
|
|
259
|
+
{ label: "date", kind: "date-expr", default: i },
|
|
260
|
+
{ label: "amount", kind: "num-expr", default: { type: "literal", value: 1 } },
|
|
261
|
+
d("unit")
|
|
262
|
+
]
|
|
263
|
+
},
|
|
264
|
+
DATE_SUB: {
|
|
265
|
+
name: "DATE_SUB",
|
|
266
|
+
returns: "arg",
|
|
267
|
+
args: [
|
|
268
|
+
{ label: "date", kind: "date-expr", default: i },
|
|
269
|
+
{ label: "amount", kind: "num-expr", default: { type: "literal", value: 1 } },
|
|
270
|
+
d("unit")
|
|
271
|
+
]
|
|
272
|
+
},
|
|
273
|
+
// ---- Date diff ----
|
|
274
|
+
DATEDIFF: {
|
|
275
|
+
name: "DATEDIFF",
|
|
276
|
+
returns: "integer",
|
|
277
|
+
args: [
|
|
278
|
+
{ label: "start", kind: "date-expr", default: i },
|
|
279
|
+
{ label: "end", kind: "date-expr", default: i },
|
|
280
|
+
d("unit")
|
|
281
|
+
]
|
|
282
|
+
},
|
|
283
|
+
// ---- Date extract / trunc ----
|
|
284
|
+
EXTRACT: {
|
|
285
|
+
name: "EXTRACT",
|
|
286
|
+
returns: "integer",
|
|
287
|
+
args: [
|
|
288
|
+
{ label: "date", kind: "date-expr", default: i },
|
|
289
|
+
d("unit", "YEAR")
|
|
290
|
+
]
|
|
291
|
+
},
|
|
292
|
+
DATE_TRUNC: {
|
|
293
|
+
name: "DATE_TRUNC",
|
|
294
|
+
returns: "arg",
|
|
295
|
+
args: [
|
|
296
|
+
{ label: "date", kind: "date-expr", default: i },
|
|
297
|
+
d("unit")
|
|
298
|
+
]
|
|
299
|
+
},
|
|
300
|
+
// ---- Type cast ----
|
|
301
|
+
CAST: {
|
|
302
|
+
name: "CAST",
|
|
303
|
+
args: [
|
|
304
|
+
{ label: "value", kind: "expr", default: i },
|
|
305
|
+
{
|
|
306
|
+
label: "type",
|
|
307
|
+
kind: "type-name",
|
|
308
|
+
default: { type: "literal", value: "INTEGER" }
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
},
|
|
312
|
+
// ---- Null handling ----
|
|
313
|
+
COALESCE: {
|
|
314
|
+
name: "COALESCE",
|
|
315
|
+
returns: "arg",
|
|
316
|
+
args: [
|
|
317
|
+
{
|
|
318
|
+
label: "value",
|
|
319
|
+
kind: "expr",
|
|
320
|
+
variadic: !0,
|
|
321
|
+
default: i
|
|
322
|
+
}
|
|
323
|
+
]
|
|
324
|
+
},
|
|
325
|
+
IFNULL: {
|
|
326
|
+
name: "IFNULL",
|
|
327
|
+
returns: "arg",
|
|
328
|
+
args: [
|
|
329
|
+
{ label: "value", kind: "expr", default: i },
|
|
330
|
+
{ label: "fallback", kind: "expr", default: { type: "literal", value: null } }
|
|
331
|
+
]
|
|
332
|
+
},
|
|
333
|
+
NULLIF: {
|
|
334
|
+
name: "NULLIF",
|
|
335
|
+
returns: "arg",
|
|
336
|
+
args: [
|
|
337
|
+
{ label: "value", kind: "expr", default: i },
|
|
338
|
+
{ label: "compare", kind: "expr", default: { type: "literal", value: "" } }
|
|
339
|
+
]
|
|
340
|
+
},
|
|
341
|
+
// ---- String ----
|
|
342
|
+
CONCAT: {
|
|
343
|
+
name: "CONCAT",
|
|
344
|
+
returns: "text",
|
|
345
|
+
args: [
|
|
346
|
+
{
|
|
347
|
+
label: "value",
|
|
348
|
+
kind: "str-expr",
|
|
349
|
+
variadic: !0,
|
|
350
|
+
default: i
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
},
|
|
354
|
+
SUBSTR: {
|
|
355
|
+
name: "SUBSTR",
|
|
356
|
+
returns: "text",
|
|
357
|
+
args: [
|
|
358
|
+
{ label: "string", kind: "str-expr", default: i },
|
|
359
|
+
{ label: "start", kind: "num-expr", default: { type: "literal", value: 1 } },
|
|
360
|
+
{
|
|
361
|
+
label: "length",
|
|
362
|
+
kind: "num-expr",
|
|
363
|
+
optional: !0,
|
|
364
|
+
default: { type: "literal", value: 1 }
|
|
365
|
+
}
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
REPLACE: {
|
|
369
|
+
name: "REPLACE",
|
|
370
|
+
returns: "text",
|
|
371
|
+
args: [
|
|
372
|
+
{ label: "string", kind: "str-expr", default: i },
|
|
373
|
+
{ label: "find", kind: "str-expr", default: { type: "literal", value: "" } },
|
|
374
|
+
{ label: "replace", kind: "str-expr", default: { type: "literal", value: "" } }
|
|
375
|
+
]
|
|
376
|
+
},
|
|
377
|
+
// ---- Numeric ----
|
|
378
|
+
ROUND: {
|
|
379
|
+
name: "ROUND",
|
|
380
|
+
returns: "number",
|
|
381
|
+
args: [
|
|
382
|
+
{ label: "value", kind: "num-expr", default: i },
|
|
383
|
+
{
|
|
384
|
+
label: "decimals",
|
|
385
|
+
kind: "num-expr",
|
|
386
|
+
optional: !0,
|
|
387
|
+
default: { type: "literal", value: 0 }
|
|
388
|
+
}
|
|
389
|
+
]
|
|
390
|
+
},
|
|
391
|
+
MOD: {
|
|
392
|
+
name: "MOD",
|
|
393
|
+
returns: "number",
|
|
394
|
+
args: [
|
|
395
|
+
{ label: "value", kind: "num-expr", default: i },
|
|
396
|
+
{ label: "divisor", kind: "num-expr", default: { type: "literal", value: 1 } }
|
|
397
|
+
]
|
|
398
|
+
},
|
|
399
|
+
// ---- Numeric (single-arg) ----
|
|
400
|
+
ABS: {
|
|
401
|
+
name: "ABS",
|
|
402
|
+
returns: "arg",
|
|
403
|
+
args: [
|
|
404
|
+
{ label: "value", kind: "num-expr", default: i }
|
|
405
|
+
]
|
|
406
|
+
},
|
|
407
|
+
CEIL: {
|
|
408
|
+
name: "CEIL",
|
|
409
|
+
returns: "integer",
|
|
410
|
+
args: [
|
|
411
|
+
{ label: "value", kind: "num-expr", default: i }
|
|
412
|
+
]
|
|
413
|
+
},
|
|
414
|
+
FLOOR: {
|
|
415
|
+
name: "FLOOR",
|
|
416
|
+
returns: "integer",
|
|
417
|
+
args: [
|
|
418
|
+
{ label: "value", kind: "num-expr", default: i }
|
|
419
|
+
]
|
|
420
|
+
},
|
|
421
|
+
// ---- String (single-arg) ----
|
|
422
|
+
LENGTH: {
|
|
423
|
+
name: "LENGTH",
|
|
424
|
+
returns: "integer",
|
|
425
|
+
args: [
|
|
426
|
+
{ label: "string", kind: "str-expr", default: i }
|
|
427
|
+
]
|
|
428
|
+
},
|
|
429
|
+
LOWER: {
|
|
430
|
+
name: "LOWER",
|
|
431
|
+
returns: "text",
|
|
432
|
+
args: [
|
|
433
|
+
{ label: "string", kind: "str-expr", default: i }
|
|
434
|
+
]
|
|
435
|
+
},
|
|
436
|
+
UPPER: {
|
|
437
|
+
name: "UPPER",
|
|
438
|
+
returns: "text",
|
|
439
|
+
args: [
|
|
440
|
+
{ label: "string", kind: "str-expr", default: i }
|
|
441
|
+
]
|
|
442
|
+
},
|
|
443
|
+
LTRIM: {
|
|
444
|
+
name: "LTRIM",
|
|
445
|
+
returns: "text",
|
|
446
|
+
args: [
|
|
447
|
+
{ label: "string", kind: "str-expr", default: i }
|
|
448
|
+
]
|
|
449
|
+
},
|
|
450
|
+
RTRIM: {
|
|
451
|
+
name: "RTRIM",
|
|
452
|
+
returns: "text",
|
|
453
|
+
args: [
|
|
454
|
+
{ label: "string", kind: "str-expr", default: i }
|
|
455
|
+
]
|
|
456
|
+
},
|
|
457
|
+
TRIM: {
|
|
458
|
+
name: "TRIM",
|
|
459
|
+
returns: "text",
|
|
460
|
+
args: [
|
|
461
|
+
{ label: "string", kind: "str-expr", default: i }
|
|
462
|
+
]
|
|
463
|
+
},
|
|
464
|
+
// ---- String (multi-arg) ----
|
|
465
|
+
INSTR: {
|
|
466
|
+
name: "INSTR",
|
|
467
|
+
returns: "integer",
|
|
468
|
+
args: [
|
|
469
|
+
{ label: "string", kind: "str-expr", default: i },
|
|
470
|
+
{ label: "substring", kind: "str-expr", default: { type: "literal", value: "" } }
|
|
471
|
+
]
|
|
472
|
+
},
|
|
473
|
+
LEFT: {
|
|
474
|
+
name: "LEFT",
|
|
475
|
+
returns: "text",
|
|
476
|
+
args: [
|
|
477
|
+
{ label: "string", kind: "str-expr", default: i },
|
|
478
|
+
{ label: "length", kind: "num-expr", default: { type: "literal", value: 1 } }
|
|
479
|
+
]
|
|
480
|
+
},
|
|
481
|
+
RIGHT: {
|
|
482
|
+
name: "RIGHT",
|
|
483
|
+
returns: "text",
|
|
484
|
+
args: [
|
|
485
|
+
{ label: "string", kind: "str-expr", default: i },
|
|
486
|
+
{ label: "length", kind: "num-expr", default: { type: "literal", value: 1 } }
|
|
487
|
+
]
|
|
488
|
+
},
|
|
489
|
+
SUBSTRING: {
|
|
490
|
+
name: "SUBSTRING",
|
|
491
|
+
returns: "text",
|
|
492
|
+
args: [
|
|
493
|
+
{ label: "string", kind: "str-expr", default: i },
|
|
494
|
+
{ label: "start", kind: "num-expr", default: { type: "literal", value: 1 } },
|
|
495
|
+
{
|
|
496
|
+
label: "length",
|
|
497
|
+
kind: "num-expr",
|
|
498
|
+
optional: !0,
|
|
499
|
+
default: { type: "literal", value: 1 }
|
|
500
|
+
}
|
|
501
|
+
]
|
|
502
|
+
},
|
|
503
|
+
// ---- Type conversion ----
|
|
504
|
+
CONVERT: {
|
|
505
|
+
name: "CONVERT",
|
|
506
|
+
args: [
|
|
507
|
+
{ label: "value", kind: "expr", default: i },
|
|
508
|
+
{ label: "type", kind: "type-name", default: { type: "literal", value: "INTEGER" } }
|
|
509
|
+
]
|
|
510
|
+
},
|
|
511
|
+
// ---- Date: no-arg ----
|
|
512
|
+
CURDATE: {
|
|
513
|
+
name: "CURDATE",
|
|
514
|
+
returns: "date",
|
|
515
|
+
args: []
|
|
516
|
+
},
|
|
517
|
+
NOW: {
|
|
518
|
+
name: "NOW",
|
|
519
|
+
returns: "dateTime",
|
|
520
|
+
args: []
|
|
521
|
+
},
|
|
522
|
+
// ---- Date: extract parts ----
|
|
523
|
+
DATE: {
|
|
524
|
+
name: "DATE",
|
|
525
|
+
returns: "date",
|
|
526
|
+
args: [
|
|
527
|
+
{ label: "expr", kind: "date-expr", default: i }
|
|
528
|
+
]
|
|
529
|
+
},
|
|
530
|
+
TIME: {
|
|
531
|
+
name: "TIME",
|
|
532
|
+
returns: "time",
|
|
533
|
+
args: [
|
|
534
|
+
{ label: "expr", kind: "date-expr", default: i }
|
|
535
|
+
]
|
|
536
|
+
},
|
|
537
|
+
DAY: {
|
|
538
|
+
name: "DAY",
|
|
539
|
+
returns: "integer",
|
|
540
|
+
args: [
|
|
541
|
+
{ label: "date", kind: "date-expr", default: i }
|
|
542
|
+
]
|
|
543
|
+
},
|
|
544
|
+
MONTH: {
|
|
545
|
+
name: "MONTH",
|
|
546
|
+
returns: "integer",
|
|
547
|
+
args: [
|
|
548
|
+
{ label: "date", kind: "date-expr", default: i }
|
|
549
|
+
]
|
|
550
|
+
},
|
|
551
|
+
YEAR: {
|
|
552
|
+
name: "YEAR",
|
|
553
|
+
returns: "integer",
|
|
554
|
+
args: [
|
|
555
|
+
{ label: "date", kind: "date-expr", default: i }
|
|
556
|
+
]
|
|
557
|
+
},
|
|
558
|
+
HOUR: {
|
|
559
|
+
name: "HOUR",
|
|
560
|
+
returns: "integer",
|
|
561
|
+
args: [
|
|
562
|
+
{ label: "time", kind: "date-expr", default: i }
|
|
563
|
+
]
|
|
564
|
+
},
|
|
565
|
+
MINUTE: {
|
|
566
|
+
name: "MINUTE",
|
|
567
|
+
returns: "integer",
|
|
568
|
+
args: [
|
|
569
|
+
{ label: "time", kind: "date-expr", default: i }
|
|
570
|
+
]
|
|
571
|
+
},
|
|
572
|
+
SECOND: {
|
|
573
|
+
name: "SECOND",
|
|
574
|
+
returns: "integer",
|
|
575
|
+
args: [
|
|
576
|
+
{ label: "time", kind: "date-expr", default: i }
|
|
577
|
+
]
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
function k(e, t = h) {
|
|
581
|
+
return t[e.toUpperCase()];
|
|
582
|
+
}
|
|
583
|
+
function ne(e, t) {
|
|
584
|
+
const r = e.toUpperCase();
|
|
585
|
+
return k(e, t) ?? Object.values(t).find((a) => {
|
|
586
|
+
var u;
|
|
587
|
+
return (u = a.aliases) == null ? void 0 : u.some((n) => n.toUpperCase() === r);
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
function j(e = h) {
|
|
591
|
+
return Object.keys(e).sort();
|
|
592
|
+
}
|
|
593
|
+
j(h);
|
|
594
|
+
const se = h;
|
|
595
|
+
function le(e) {
|
|
596
|
+
return Object.fromEntries(Object.values(e).map((t) => {
|
|
597
|
+
const r = t.name.toUpperCase();
|
|
598
|
+
return [r, { ...t, name: r }];
|
|
599
|
+
}));
|
|
600
|
+
}
|
|
601
|
+
function ie(e) {
|
|
602
|
+
return Object.fromEntries(Object.entries(e).filter(([, t]) => !t.aggregate));
|
|
603
|
+
}
|
|
604
|
+
function ue(e, t) {
|
|
605
|
+
return Object.fromEntries(Object.entries(e).filter(([, r]) => !r.dialects || r.dialects.includes(t)));
|
|
606
|
+
}
|
|
607
|
+
function E(e, t) {
|
|
608
|
+
if (e === t) return !0;
|
|
609
|
+
if (e instanceof Date && t instanceof Date) return e.getTime() === t.getTime();
|
|
610
|
+
if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
|
|
611
|
+
const r = e, a = t, u = Object.keys(r).filter((l) => r[l] !== void 0), n = Object.keys(a).filter((l) => a[l] !== void 0);
|
|
612
|
+
return u.length === n.length && u.every((l) => E(r[l], a[l]));
|
|
613
|
+
}
|
|
614
|
+
function F() {
|
|
615
|
+
const e = globalThis.crypto.getRandomValues(new Uint8Array(12));
|
|
616
|
+
return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
|
|
617
|
+
}
|
|
618
|
+
function N(e, t) {
|
|
619
|
+
var r;
|
|
620
|
+
return e.type === "function" && ((r = k(e.name, t)) == null ? void 0 : r.aggregate) === !0;
|
|
621
|
+
}
|
|
622
|
+
function p(e, t) {
|
|
623
|
+
return e ? N(e, t) || b(e).some((r) => p(r, t)) : !1;
|
|
624
|
+
}
|
|
625
|
+
function O(e, t) {
|
|
626
|
+
return e.type === "function" && e.name.trim() !== "" && k(e.name, t) === void 0;
|
|
627
|
+
}
|
|
628
|
+
function D(e, t) {
|
|
629
|
+
return e ? O(e, t) || b(e).some((r) => D(r, t)) : !1;
|
|
630
|
+
}
|
|
631
|
+
function g(e, t, r) {
|
|
632
|
+
return t.some((a) => E(a, e)) ? !0 : e.type === "field" ? !e.column : e.type === "exists" ? G(e).every((a) => g(a, t, r)) : N(e, r) || O(e, r) ? !0 : b(e).every((a) => g(a, t, r));
|
|
633
|
+
}
|
|
634
|
+
function M(e, t) {
|
|
635
|
+
return (e.groupBy ?? []).length > 0 || e.having !== void 0 || [...e.select, ...e.orderBy ?? []].some((r) => p(r.expression, t));
|
|
636
|
+
}
|
|
637
|
+
function oe(e, t) {
|
|
638
|
+
if (M(e, t))
|
|
639
|
+
return (e.groupBy ?? []).flatMap(({ expression: r }) => r.type === "field" && r.table && r.column ? [`${r.table}.${r.column}`] : []);
|
|
640
|
+
}
|
|
641
|
+
function H(e, t) {
|
|
642
|
+
return p(e.having, t) || [...e.select, ...e.orderBy ?? []].some((r) => p(r.expression, t));
|
|
643
|
+
}
|
|
644
|
+
function fe(e, t) {
|
|
645
|
+
return e.select.some((r) => p(r.expression, t));
|
|
646
|
+
}
|
|
647
|
+
function ce(e, t) {
|
|
648
|
+
const r = e.groupBy ?? [], a = r.filter((o) => o.fromSelect === void 0), u = H(e, t), n = a.map((o) => o.expression), l = u ? e.select.filter((o) => p(o.expression, t) || D(o.expression, t) || g(o.expression, n, t) ? !1 : (n.push(o.expression), !0)) : [], s = new Map(r.filter((o) => o.fromSelect !== void 0).map((o) => [o.fromSelect, o])), f = [];
|
|
649
|
+
r.forEach((o) => {
|
|
650
|
+
if (o.fromSelect === void 0) {
|
|
651
|
+
f.push(o);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const m = l.find((U) => U.id === o.fromSelect);
|
|
655
|
+
m && f.push(E(o.expression, m.expression) ? o : { ...o, expression: m.expression });
|
|
656
|
+
});
|
|
657
|
+
const c = l.filter((o) => !s.has(o.id)).map((o) => ({
|
|
658
|
+
id: F(),
|
|
659
|
+
expression: o.expression,
|
|
660
|
+
fromSelect: o.id
|
|
661
|
+
})), x = [...f, ...c];
|
|
662
|
+
return x.length === r.length && x.every((o, m) => o === r[m]) ? e : { ...e, groupBy: x };
|
|
663
|
+
}
|
|
664
|
+
function pe(e, t) {
|
|
665
|
+
const r = (e.groupBy ?? []).map((n) => n.expression), a = e.orderBy ?? [];
|
|
666
|
+
if (!M(e, t))
|
|
667
|
+
return {
|
|
668
|
+
select: [],
|
|
669
|
+
selectAll: !1,
|
|
670
|
+
orderBy: [],
|
|
671
|
+
having: !1
|
|
672
|
+
};
|
|
673
|
+
const u = (n) => n.filter((l) => !g(l.expression, r, t)).map((l) => l.id);
|
|
674
|
+
return {
|
|
675
|
+
select: u(e.select),
|
|
676
|
+
selectAll: e.select.length === 0,
|
|
677
|
+
orderBy: u(a),
|
|
678
|
+
having: e.having !== void 0 && !g(e.having, r, t)
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
const me = { tables: [], relations: [] };
|
|
682
|
+
function de(e, t, r) {
|
|
683
|
+
if (!t && !r) return e;
|
|
684
|
+
const a = e.tables.filter((n) => !t || t(n)).map((n) => r ? { ...n, columns: n.columns.filter((l) => r(n, l)) } : n), u = new Set(a.map((n) => n.name));
|
|
685
|
+
return {
|
|
686
|
+
tables: a,
|
|
687
|
+
relations: e.relations.filter((n) => u.has(n.fromTable) && u.has(n.toTable))
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
function ge(e) {
|
|
691
|
+
return [...e.tables].sort((t, r) => t.label.localeCompare(r.label));
|
|
692
|
+
}
|
|
693
|
+
function _(e, t) {
|
|
694
|
+
return e.tables.find((r) => r.name === t);
|
|
695
|
+
}
|
|
696
|
+
function $(e, t, r) {
|
|
697
|
+
return e.relations.find((a) => a.fromTable === t && a.toTable === r || a.fromTable === r && a.toTable === t);
|
|
698
|
+
}
|
|
699
|
+
function be(e, t, r) {
|
|
700
|
+
if (t.includes(r)) return [];
|
|
701
|
+
const a = /* @__PURE__ */ new Map(), u = new Set(t), n = [...t];
|
|
702
|
+
for (; n.length > 0 && !u.has(r); ) {
|
|
703
|
+
const f = n.shift();
|
|
704
|
+
e.relations.filter((c) => c.fromTable === f || c.toTable === f).map((c) => c.fromTable === f ? c.toTable : c.fromTable).forEach((c) => {
|
|
705
|
+
u.has(c) || (u.add(c), a.set(c, f), n.push(c));
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
if (!u.has(r)) return;
|
|
709
|
+
const l = [];
|
|
710
|
+
let s = r;
|
|
711
|
+
for (; !t.includes(s); )
|
|
712
|
+
l.unshift(s), s = a.get(s);
|
|
713
|
+
return l;
|
|
714
|
+
}
|
|
715
|
+
function he(e, t) {
|
|
716
|
+
const r = /* @__PURE__ */ new Map(), a = (l, s) => r.set(l, [...r.get(l) ?? [], s]);
|
|
717
|
+
e.relations.forEach((l) => {
|
|
718
|
+
a(l.fromTable, l.toTable), a(l.toTable, l.fromTable);
|
|
719
|
+
});
|
|
720
|
+
const u = new Set(t), n = [...t];
|
|
721
|
+
for (let l = n.shift(); l !== void 0; l = n.shift())
|
|
722
|
+
(r.get(l) ?? []).forEach((s) => {
|
|
723
|
+
u.has(s) || (u.add(s), n.push(s));
|
|
724
|
+
});
|
|
725
|
+
return u;
|
|
726
|
+
}
|
|
727
|
+
function xe(e, t, r) {
|
|
728
|
+
var s;
|
|
729
|
+
const a = t.map((f) => $(e, f, r)).find((f) => f !== void 0);
|
|
730
|
+
if (!a) return;
|
|
731
|
+
const u = (s = _(e, a.fromTable)) == null ? void 0 : s.columns.find((f) => f.name === a.fromColumn), n = u != null && u.nullable ? "left" : "inner", l = {
|
|
732
|
+
type: "binary",
|
|
733
|
+
operator: "=",
|
|
734
|
+
left: { type: "field", table: a.fromTable, column: a.fromColumn },
|
|
735
|
+
right: { type: "field", table: a.toTable, column: a.toColumn }
|
|
736
|
+
};
|
|
737
|
+
return { joinType: n, on: l };
|
|
738
|
+
}
|
|
739
|
+
const A = (e, t) => `${e}.${t}`;
|
|
740
|
+
function P({ type: e, format: t }) {
|
|
741
|
+
if (t === void 0) return;
|
|
742
|
+
if (e !== "date" && e !== "dateTime" && e !== "time")
|
|
743
|
+
return `a format is for a date, date-and-time or time column, not ${e}`;
|
|
744
|
+
const r = t.match(/YYYY|MM|DD|HH|mm|ss/g) ?? [];
|
|
745
|
+
if (r.length === 0) return `format "${t}" has none of YYYY, MM, DD, HH, mm, ss`;
|
|
746
|
+
if (e === "time" && r.some((a) => a === "YYYY" || a === "MM" || a === "DD"))
|
|
747
|
+
return `a time has no day: format "${t}" can't be written from one`;
|
|
748
|
+
}
|
|
749
|
+
function Te(e) {
|
|
750
|
+
const t = [], r = /* @__PURE__ */ new Map();
|
|
751
|
+
e.tables.forEach((n) => {
|
|
752
|
+
r.has(n.name) && t.push({
|
|
753
|
+
kind: "duplicateTable",
|
|
754
|
+
message: `Table "${n.name}" is declared more than once`
|
|
755
|
+
}), r.set(n.name, n);
|
|
756
|
+
const l = /* @__PURE__ */ new Set();
|
|
757
|
+
n.columns.forEach((s) => {
|
|
758
|
+
l.has(s.name) && t.push({
|
|
759
|
+
kind: "duplicateColumn",
|
|
760
|
+
message: `Column "${n.name}.${s.name}" is declared more than once`
|
|
761
|
+
}), l.add(s.name);
|
|
762
|
+
const f = P(s);
|
|
763
|
+
f && t.push({
|
|
764
|
+
kind: "invalidFormat",
|
|
765
|
+
message: `Column "${n.name}.${s.name}": ${f}`
|
|
766
|
+
});
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
const a = (n, l) => {
|
|
770
|
+
const s = r.get(n);
|
|
771
|
+
s ? s.columns.some((f) => f.name === l) || t.push({
|
|
772
|
+
kind: "unknownColumn",
|
|
773
|
+
message: `Relation references unknown column "${n}.${l}"`
|
|
774
|
+
}) : t.push({
|
|
775
|
+
kind: "unknownTable",
|
|
776
|
+
message: `Relation references unknown table "${n}"`
|
|
777
|
+
});
|
|
778
|
+
}, u = /* @__PURE__ */ new Set();
|
|
779
|
+
return e.relations.forEach((n) => {
|
|
780
|
+
a(n.fromTable, n.fromColumn), a(n.toTable, n.toColumn);
|
|
781
|
+
const l = A(n.fromTable, n.fromColumn), s = A(n.toTable, n.toColumn), f = [l, s].sort().join(" <-> ");
|
|
782
|
+
u.has(f) && t.push({
|
|
783
|
+
kind: "duplicateRelation",
|
|
784
|
+
message: `Relation ${l} -> ${s} is declared more than once (declare each foreign key once)`
|
|
785
|
+
}), u.add(f);
|
|
786
|
+
}), t;
|
|
787
|
+
}
|
|
788
|
+
export {
|
|
789
|
+
ge as A,
|
|
790
|
+
q as B,
|
|
791
|
+
he as C,
|
|
792
|
+
se as D,
|
|
793
|
+
me as E,
|
|
794
|
+
be as F,
|
|
795
|
+
xe as G,
|
|
796
|
+
T as H,
|
|
797
|
+
C as I,
|
|
798
|
+
k as J,
|
|
799
|
+
w as K,
|
|
800
|
+
le as L,
|
|
801
|
+
z as M,
|
|
802
|
+
M as N,
|
|
803
|
+
W as O,
|
|
804
|
+
re as P,
|
|
805
|
+
D as Q,
|
|
806
|
+
ie as R,
|
|
807
|
+
j as S,
|
|
808
|
+
te as T,
|
|
809
|
+
ae as U,
|
|
810
|
+
N as V,
|
|
811
|
+
oe as W,
|
|
812
|
+
fe as X,
|
|
813
|
+
ue as a,
|
|
814
|
+
X as b,
|
|
815
|
+
Y as c,
|
|
816
|
+
F as d,
|
|
817
|
+
Q as e,
|
|
818
|
+
de as f,
|
|
819
|
+
E as g,
|
|
820
|
+
J as h,
|
|
821
|
+
v as i,
|
|
822
|
+
Z as j,
|
|
823
|
+
_ as k,
|
|
824
|
+
p as l,
|
|
825
|
+
H as m,
|
|
826
|
+
ce as n,
|
|
827
|
+
R as o,
|
|
828
|
+
ne as p,
|
|
829
|
+
y as q,
|
|
830
|
+
b as r,
|
|
831
|
+
ee as s,
|
|
832
|
+
I as t,
|
|
833
|
+
pe as u,
|
|
834
|
+
Te as v,
|
|
835
|
+
S as w,
|
|
836
|
+
K as x,
|
|
837
|
+
B as y,
|
|
838
|
+
L as z
|
|
839
|
+
};
|