@coorax/react 0.0.0-canary.2 → 0.0.0-canary.3
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/dist/components/commons/button.d.ts +8 -0
- package/dist/components/corax-context-provider.d.ts +6 -0
- package/dist/components/corax-flow.d.ts +4 -0
- package/dist/components/fallbacks/image.fallback.d.ts +3 -0
- package/dist/components/slots/buttons/block-actions-button.d.ts +3 -0
- package/dist/components/slots/buttons/toolbar-button.d.ts +3 -0
- package/dist/components/slots/maps/block-actions.d.ts +1 -0
- package/dist/components/slots/maps/overlays.d.ts +1 -0
- package/dist/components/slots/maps/text-inspector.d.ts +2 -0
- package/dist/components/slots/maps/toolbar.d.ts +1 -0
- package/dist/components/slots/overlays/focus-overlay.d.ts +3 -0
- package/dist/components/slots/overlays/hover-overlay.d.ts +3 -0
- package/dist/components/slots/overlays/selection-overlay.d.ts +3 -0
- package/dist/components/slots/slot-button.d.ts +6 -0
- package/dist/components/slots/slot-component.d.ts +5 -0
- package/dist/components/slots/slots.d.ts +4 -0
- package/dist/constants/field.constants.d.ts +2 -0
- package/dist/hooks/custom/use-custom-ref.d.ts +1 -0
- package/dist/hooks/custom/use-isomorphic-layout-effect.d.ts +2 -0
- package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -0
- package/dist/hooks/use-block-entry.d.ts +2 -0
- package/dist/hooks/use-block.d.ts +2 -0
- package/dist/hooks/use-flow.d.ts +17 -0
- package/dist/hooks/use-keyboard.d.ts +10 -0
- package/dist/hooks/use-registry.d.ts +3 -0
- package/dist/hooks/use-renderer.d.ts +2 -0
- package/dist/hooks/use-slice.d.ts +2 -0
- package/dist/hooks/use-slots.d.ts +2 -0
- package/dist/hooks/use-tasks.d.ts +7 -0
- package/dist/hooks/use-text-input.d.ts +2 -0
- package/dist/hooks/use-ui-context.d.ts +2 -0
- package/dist/hooks/useSelection.d.ts +2 -0
- package/{src/index.ts → dist/index.d.ts} +3 -4
- package/dist/index.js +2751 -0
- package/dist/lib/comp.utils.d.ts +4 -0
- package/dist/lib/func.utils.d.ts +3 -0
- package/dist/lib/selection.utils.d.ts +5 -0
- package/dist/lib/slots.utils.d.ts +4 -0
- package/dist/lifecycle/fields/focus.events/onbeforeinput.d.ts +3 -0
- package/dist/lifecycle/fields/focus.events/onblur.d.ts +3 -0
- package/dist/lifecycle/fields/focus.events/onfocus.d.ts +3 -0
- package/dist/lifecycle/fields/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/lifecycle.fields.d.ts +12 -0
- package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +15 -0
- package/dist/lifecycle/fields/lifecycle.utils.d.ts +2 -0
- package/dist/lifecycle/fields/mouse.events/onclick.d.ts +3 -0
- package/dist/lifecycle/fields/mouse.events/ondoubleclick.d.ts +4 -0
- package/dist/lifecycle/fields/mouse.events/onmouseenter.d.ts +3 -0
- package/dist/lifecycle/fields/mouse.events/onmouseleave.d.ts +3 -0
- package/dist/lifecycle/fields/synthetic.events/onload.d.ts +3 -0
- package/dist/lifecycle/fields/synthetic.events/onselect.d.ts +3 -0
- package/dist/lifecycle/index.d.ts +1 -0
- package/dist/modules/autosave.module.d.ts +31 -0
- package/dist/modules/fallbacks.module.d.ts +7 -0
- package/dist/modules/slots.module.d.ts +7 -0
- package/dist/modules/ui-primitives.module.d.ts +7 -0
- package/dist/primitives/fields/field.primitives.d.ts +2 -0
- package/dist/primitives/index.d.ts +3 -0
- package/{src/registry/fallbacks.registry.tsx → dist/registry/fallbacks.registry.d.ts} +3 -4
- package/dist/registry/primitives.registry.d.ts +22 -0
- package/dist/registry/registry.d.ts +15 -0
- package/dist/registry/slots.registry.d.ts +4 -0
- package/{src/registry/ui.primitives.registry.tsx → dist/registry/ui.primitives.registry.d.ts} +3 -4
- package/dist/renderer/renderer.d.ts +23 -0
- package/dist/renderer/renderer.test.d.ts +1 -0
- package/{src/renderer/renderer.types.ts → dist/renderer/renderer.types.d.ts} +0 -1
- package/dist/renderer/renderer.utils.d.ts +14 -0
- package/dist/renderer/utils/divider.renderer.utils.d.ts +6 -0
- package/dist/services/localdb/db/db.d.ts +74 -0
- package/dist/services/localdb/db/db.test.d.ts +1 -0
- package/dist/services/localdb/lexer/lexer.d.ts +14 -0
- package/dist/services/localdb/lexer/lexer.test.d.ts +1 -0
- package/dist/services/localdb/lexer/lexer.types.d.ts +5 -0
- package/dist/services/localdb/operator/operator.d.ts +10 -0
- package/dist/services/localdb/parser/parser.constants.d.ts +3 -0
- package/dist/services/localdb/parser/parser.d.ts +14 -0
- package/dist/services/localdb/parser/parser.test.d.ts +1 -0
- package/dist/services/localdb/parser/parser.types.d.ts +43 -0
- package/dist/services/localdb/sheet/sheet.constants.d.ts +3 -0
- package/dist/services/localdb/sheet/sheet.d.ts +14 -0
- package/dist/services/localdb/sheet/sheet.types.d.ts +13 -0
- package/dist/styles.css +1094 -0
- package/package.json +29 -12
- package/.oxlintrc.json +0 -8
- package/src/components/commons/button.tsx +0 -59
- package/src/components/corax-context-provider.tsx +0 -47
- package/src/components/corax-flow.tsx +0 -44
- package/src/components/fallbacks/image.fallback.tsx +0 -23
- package/src/components/slots/buttons/block-actions-button.tsx +0 -85
- package/src/components/slots/buttons/toolbar-button.tsx +0 -40
- package/src/components/slots/maps/block-actions.tsx +0 -84
- package/src/components/slots/maps/overlays.tsx +0 -9
- package/src/components/slots/maps/text-inspector.tsx +0 -5
- package/src/components/slots/maps/toolbar.tsx +0 -79
- package/src/components/slots/overlays/focus-overlay.tsx +0 -30
- package/src/components/slots/overlays/hover-overlay.tsx +0 -18
- package/src/components/slots/overlays/selection-overlay.tsx +0 -20
- package/src/components/slots/slot-button.tsx +0 -20
- package/src/components/slots/slot-component.tsx +0 -17
- package/src/components/slots/slots.tsx +0 -29
- package/src/constants/field.constants.ts +0 -3
- package/src/hooks/custom/use-custom-ref.ts +0 -11
- package/src/hooks/use-block-entry.ts +0 -44
- package/src/hooks/use-block.ts +0 -11
- package/src/hooks/use-flow.ts +0 -83
- package/src/hooks/use-keyboard.ts +0 -66
- package/src/hooks/use-registry.ts +0 -18
- package/src/hooks/use-renderer.ts +0 -8
- package/src/hooks/use-slice.ts +0 -13
- package/src/hooks/use-slots.ts +0 -13
- package/src/hooks/use-tasks.ts +0 -33
- package/src/hooks/use-text-input.ts +0 -83
- package/src/hooks/use-ui-context.ts +0 -16
- package/src/hooks/useSelection.ts +0 -27
- package/src/lib/comp.utils.tsx +0 -44
- package/src/lib/func.utils.ts +0 -15
- package/src/lib/selection.utils.ts +0 -33
- package/src/lib/slots.utils.tsx +0 -23
- package/src/lifecycle/fields/focus.events/onbeforeinput.ts +0 -21
- package/src/lifecycle/fields/focus.events/onblur.ts +0 -19
- package/src/lifecycle/fields/focus.events/onfocus.ts +0 -16
- package/src/lifecycle/fields/keyboard.events/onkeydown.ts +0 -128
- package/src/lifecycle/fields/lifecycle.fields.ts +0 -116
- package/src/lifecycle/fields/lifecycle.fields.types.ts +0 -33
- package/src/lifecycle/fields/lifecycle.utils.ts +0 -26
- package/src/lifecycle/fields/mouse.events/onclick.ts +0 -79
- package/src/lifecycle/fields/mouse.events/ondoubleclick.ts +0 -27
- package/src/lifecycle/fields/mouse.events/onmouseenter.ts +0 -27
- package/src/lifecycle/fields/mouse.events/onmouseleave.ts +0 -21
- package/src/lifecycle/fields/synthetic.events/onload.ts +0 -16
- package/src/lifecycle/fields/synthetic.events/onselect.ts +0 -57
- package/src/lifecycle/index.ts +0 -1
- package/src/modules/autosave.module.ts +0 -238
- package/src/modules/fallbacks.module.tsx +0 -19
- package/src/modules/slots.module.tsx +0 -28
- package/src/modules/ui-primitives.module.tsx +0 -20
- package/src/primitives/fields/field.primitives.tsx +0 -86
- package/src/primitives/index.ts +0 -8
- package/src/registry/primitives.registry.tsx +0 -57
- package/src/registry/registry.ts +0 -44
- package/src/registry/slots.registry.tsx +0 -6
- package/src/renderer/renderer.test.ts +0 -34
- package/src/renderer/renderer.tsx +0 -164
- package/src/renderer/renderer.utils.tsx +0 -139
- package/src/renderer/utils/divider.renderer.utils.tsx +0 -53
- package/src/services/localdb/db/db.test.ts +0 -351
- package/src/services/localdb/db/db.ts +0 -628
- package/src/services/localdb/lexer/lexer.test.ts +0 -123
- package/src/services/localdb/lexer/lexer.ts +0 -173
- package/src/services/localdb/lexer/lexer.types.ts +0 -34
- package/src/services/localdb/operator/operator.ts +0 -16
- package/src/services/localdb/parser/parser.constants.ts +0 -23
- package/src/services/localdb/parser/parser.test.ts +0 -172
- package/src/services/localdb/parser/parser.ts +0 -427
- package/src/services/localdb/parser/parser.types.ts +0 -56
- package/src/services/localdb/sheet/sheet.constants.ts +0 -32
- package/src/services/localdb/sheet/sheet.ts +0 -47
- package/src/services/localdb/sheet/sheet.types.ts +0 -38
- package/tsconfig.app.json +0 -26
- package/tsconfig.json +0 -9
- package/tsconfig.node.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
- package/vite.config.ts +0 -9
- /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
- /package/{src/components/slots/index.ts → dist/components/slots/index.d.ts} +0 -0
- /package/{src/components/slots/maps/index.ts → dist/components/slots/maps/index.d.ts} +0 -0
- /package/{src/modules/index.ts → dist/modules/index.d.ts} +0 -0
- /package/{src/registry/index.ts → dist/registry/index.d.ts} +0 -0
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import type { Token } from "../lexer/lexer.types";
|
|
2
|
-
import { TYPES_DEFS, TYPES_DEFS_MAPPING } from "./parser.constants";
|
|
3
|
-
import type {
|
|
4
|
-
CreateStatement,
|
|
5
|
-
InsertStatement,
|
|
6
|
-
JoinClause,
|
|
7
|
-
JoinCondition,
|
|
8
|
-
JoinType,
|
|
9
|
-
SelectStatement,
|
|
10
|
-
Statement,
|
|
11
|
-
StatementType,
|
|
12
|
-
WhereCondition,
|
|
13
|
-
} from "./parser.types";
|
|
14
|
-
|
|
15
|
-
interface Parse {
|
|
16
|
-
parse<T extends StatementType>(tokens: Token[], params?: any[]): Statement<T>[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class Parser implements Parse {
|
|
20
|
-
private statementTypes: StatementType[] = ["SELECT", "INSERT", "CREATE"];
|
|
21
|
-
|
|
22
|
-
private foundTable(tokens: Token[]) {
|
|
23
|
-
return tokens.find((token, idx) => {
|
|
24
|
-
return (
|
|
25
|
-
token.type === "IDENTIFIER" &&
|
|
26
|
-
["FROM", "INTO", "TABLE"].includes(tokens[idx - 1]?.type as any)
|
|
27
|
-
);
|
|
28
|
-
})!;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private parseSelect(tokens: Token[]): SelectStatement {
|
|
32
|
-
const fromIndex = tokens.findIndex((t) => t.type === "FROM");
|
|
33
|
-
if (fromIndex === -1) {
|
|
34
|
-
throw new Error("Invalid SELECT statement: missing FROM clause");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const isAllFieldsWanted = tokens.slice(0, fromIndex).some((t) => t.type === "STAR");
|
|
38
|
-
const columns = isAllFieldsWanted
|
|
39
|
-
? ["*"]
|
|
40
|
-
: tokens
|
|
41
|
-
.slice(1, fromIndex)
|
|
42
|
-
.filter((t) => t.type === "IDENTIFIER" || t.type === "STRING")
|
|
43
|
-
.map((t) => t.value);
|
|
44
|
-
|
|
45
|
-
const tableToken = tokens[fromIndex + 1];
|
|
46
|
-
if (!tableToken || tableToken.type !== "IDENTIFIER") {
|
|
47
|
-
throw new Error("Invalid SELECT statement: missing table name after FROM");
|
|
48
|
-
}
|
|
49
|
-
const mainTable = tableToken.value;
|
|
50
|
-
|
|
51
|
-
let cursor = fromIndex + 2;
|
|
52
|
-
let mainAlias: string | undefined;
|
|
53
|
-
|
|
54
|
-
// Check for alias after main table
|
|
55
|
-
if (cursor < tokens.length) {
|
|
56
|
-
if (tokens[cursor]?.type === "AS" && tokens[cursor + 1]?.type === "IDENTIFIER") {
|
|
57
|
-
mainAlias = tokens[cursor + 1]!.value;
|
|
58
|
-
cursor += 2;
|
|
59
|
-
} else if (
|
|
60
|
-
tokens[cursor]?.type === "IDENTIFIER" &&
|
|
61
|
-
!["JOIN", "INNER", "LEFT", "RIGHT", "FULL", "CROSS", "WHERE", "SEMICOLON"].includes(
|
|
62
|
-
tokens[cursor]!.type,
|
|
63
|
-
)
|
|
64
|
-
) {
|
|
65
|
-
mainAlias = tokens[cursor]!.value;
|
|
66
|
-
cursor++;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const joins: JoinClause[] = [];
|
|
71
|
-
|
|
72
|
-
// Parse JOIN clauses
|
|
73
|
-
while (cursor < tokens.length) {
|
|
74
|
-
const currentToken = tokens[cursor];
|
|
75
|
-
if (!currentToken || currentToken.type === "SEMICOLON" || currentToken.type === "WHERE") {
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
let joinType: JoinType = "JOIN";
|
|
80
|
-
let hasJoin = false;
|
|
81
|
-
|
|
82
|
-
if (currentToken.type === "JOIN") {
|
|
83
|
-
joinType = "JOIN";
|
|
84
|
-
cursor++;
|
|
85
|
-
hasJoin = true;
|
|
86
|
-
} else if (
|
|
87
|
-
["INNER", "LEFT", "RIGHT", "FULL", "CROSS"].includes(currentToken.type) &&
|
|
88
|
-
tokens[cursor + 1]?.type === "JOIN"
|
|
89
|
-
) {
|
|
90
|
-
joinType = currentToken.type as JoinType;
|
|
91
|
-
cursor += 2;
|
|
92
|
-
hasJoin = true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (!hasJoin) {
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const joinTableToken = tokens[cursor];
|
|
100
|
-
if (!joinTableToken || joinTableToken.type !== "IDENTIFIER") {
|
|
101
|
-
throw new Error(`Expected table name after ${joinType} JOIN`);
|
|
102
|
-
}
|
|
103
|
-
const joinTable = joinTableToken.value;
|
|
104
|
-
cursor++;
|
|
105
|
-
|
|
106
|
-
let joinAlias: string | undefined;
|
|
107
|
-
if (cursor < tokens.length) {
|
|
108
|
-
if (tokens[cursor]?.type === "AS" && tokens[cursor + 1]?.type === "IDENTIFIER") {
|
|
109
|
-
joinAlias = tokens[cursor + 1]!.value;
|
|
110
|
-
cursor += 2;
|
|
111
|
-
} else if (
|
|
112
|
-
tokens[cursor]?.type === "IDENTIFIER" &&
|
|
113
|
-
tokens[cursor]!.value.toUpperCase() !== "ON" &&
|
|
114
|
-
!["JOIN", "INNER", "LEFT", "RIGHT", "FULL", "CROSS", "WHERE", "SEMICOLON"].includes(
|
|
115
|
-
tokens[cursor]!.type,
|
|
116
|
-
)
|
|
117
|
-
) {
|
|
118
|
-
joinAlias = tokens[cursor]!.value;
|
|
119
|
-
cursor++;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let joinCondition: JoinCondition | undefined;
|
|
124
|
-
|
|
125
|
-
if (tokens[cursor]?.type === "ON") {
|
|
126
|
-
cursor++; // skip ON
|
|
127
|
-
|
|
128
|
-
const leftToken = tokens[cursor];
|
|
129
|
-
cursor++;
|
|
130
|
-
const opToken = tokens[cursor];
|
|
131
|
-
cursor++;
|
|
132
|
-
const rightToken = tokens[cursor];
|
|
133
|
-
cursor++;
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
!leftToken ||
|
|
137
|
-
!opToken ||
|
|
138
|
-
!rightToken ||
|
|
139
|
-
(opToken.type !== "EQUALS" && opToken.value !== "=")
|
|
140
|
-
) {
|
|
141
|
-
throw new Error(`Invalid ON clause syntax in JOIN ${joinTable}`);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const leftParts = leftToken.value.split(".");
|
|
145
|
-
const rightParts = rightToken.value.split(".");
|
|
146
|
-
|
|
147
|
-
const leftTable = leftParts.length > 1 ? leftParts[0] : undefined;
|
|
148
|
-
const leftColumn = leftParts.length > 1 ? leftParts[1]! : leftParts[0]!;
|
|
149
|
-
|
|
150
|
-
const rightTable = rightParts.length > 1 ? rightParts[0] : undefined;
|
|
151
|
-
const rightColumn = rightParts.length > 1 ? rightParts[1]! : rightParts[0]!;
|
|
152
|
-
|
|
153
|
-
joinCondition = {
|
|
154
|
-
leftTable,
|
|
155
|
-
leftColumn,
|
|
156
|
-
operator: "=",
|
|
157
|
-
rightTable,
|
|
158
|
-
rightColumn,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
joins.push({
|
|
163
|
-
type: joinType,
|
|
164
|
-
table: joinTable,
|
|
165
|
-
alias: joinAlias,
|
|
166
|
-
on: joinCondition,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const where: WhereCondition[] = [];
|
|
171
|
-
|
|
172
|
-
// Parse optional WHERE clause
|
|
173
|
-
if (tokens[cursor]?.type === "WHERE") {
|
|
174
|
-
cursor++; // skip WHERE
|
|
175
|
-
|
|
176
|
-
while (cursor < tokens.length) {
|
|
177
|
-
const colToken = tokens[cursor];
|
|
178
|
-
if (!colToken || colToken.type === "SEMICOLON") break;
|
|
179
|
-
cursor++;
|
|
180
|
-
|
|
181
|
-
const opToken = tokens[cursor];
|
|
182
|
-
cursor++;
|
|
183
|
-
|
|
184
|
-
const valToken = tokens[cursor];
|
|
185
|
-
cursor++;
|
|
186
|
-
|
|
187
|
-
if (colToken && opToken && valToken) {
|
|
188
|
-
const colParts = colToken.value.split(".");
|
|
189
|
-
const table = colParts.length > 1 ? colParts[0] : undefined;
|
|
190
|
-
const column = colParts.length > 1 ? colParts[1]! : colParts[0]!;
|
|
191
|
-
|
|
192
|
-
where.push({
|
|
193
|
-
table,
|
|
194
|
-
column,
|
|
195
|
-
operator: (opToken.value as any) || "=",
|
|
196
|
-
value: valToken.value,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (tokens[cursor]?.type === "AND" || tokens[cursor]?.type === "OR") {
|
|
201
|
-
cursor++;
|
|
202
|
-
} else {
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
type: "SELECT",
|
|
210
|
-
columns,
|
|
211
|
-
table: mainTable,
|
|
212
|
-
alias: mainAlias,
|
|
213
|
-
joins: joins.length > 0 ? joins : undefined,
|
|
214
|
-
where: where.length > 0 ? where : undefined,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
private parseInsert(
|
|
219
|
-
tokens: Token[],
|
|
220
|
-
params?: any[],
|
|
221
|
-
paramState = { index: 0 },
|
|
222
|
-
): InsertStatement[] {
|
|
223
|
-
const intoIndex = tokens.findIndex((t) => t.type === "INTO");
|
|
224
|
-
if (intoIndex === -1) {
|
|
225
|
-
throw new Error("Invalid INSERT statement: missing INTO keyword");
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const tableToken = tokens[intoIndex + 1];
|
|
229
|
-
if (!tableToken || tableToken.type !== "IDENTIFIER") {
|
|
230
|
-
throw new Error("Invalid INSERT statement: missing table name");
|
|
231
|
-
}
|
|
232
|
-
const table = tableToken.value;
|
|
233
|
-
|
|
234
|
-
let cursor = intoIndex + 2;
|
|
235
|
-
let fields: string[] | undefined;
|
|
236
|
-
|
|
237
|
-
// Check if column names are specified: INSERT INTO table (col1, col2) ...
|
|
238
|
-
if (tokens[cursor]?.type === "BRACKETS" && tokens[cursor]?.value === "(") {
|
|
239
|
-
cursor++;
|
|
240
|
-
fields = [];
|
|
241
|
-
while (cursor < tokens.length) {
|
|
242
|
-
const t = tokens[cursor]!;
|
|
243
|
-
if (t.type === "BRACKETS" && t.value === ")") {
|
|
244
|
-
cursor++;
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
if (t.type === "IDENTIFIER") {
|
|
248
|
-
fields.push(t.value);
|
|
249
|
-
}
|
|
250
|
-
cursor++;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Expect VALUES keyword
|
|
255
|
-
const valuesIndex = tokens.slice(cursor).findIndex((t) => t.type === "VALUES");
|
|
256
|
-
if (valuesIndex === -1) {
|
|
257
|
-
throw new Error("Invalid INSERT statement: missing VALUES keyword");
|
|
258
|
-
}
|
|
259
|
-
cursor += valuesIndex + 1;
|
|
260
|
-
|
|
261
|
-
const statements: InsertStatement[] = [];
|
|
262
|
-
|
|
263
|
-
// Parse VALUES tuple(s): VALUES (...), (...)
|
|
264
|
-
while (cursor < tokens.length) {
|
|
265
|
-
if (tokens[cursor]?.type === "SEMICOLON") break;
|
|
266
|
-
|
|
267
|
-
if (tokens[cursor]?.type === "BRACKETS" && tokens[cursor]?.value === "(") {
|
|
268
|
-
cursor++;
|
|
269
|
-
const values: any[] = [];
|
|
270
|
-
|
|
271
|
-
while (cursor < tokens.length) {
|
|
272
|
-
const t = tokens[cursor]!;
|
|
273
|
-
if (t.type === "BRACKETS" && t.value === ")") {
|
|
274
|
-
cursor++;
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (t.type === "COMMA") {
|
|
279
|
-
cursor++;
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (t.type === "QUESTION_MARK") {
|
|
284
|
-
if (params && paramState.index < params.length) {
|
|
285
|
-
values.push(params[paramState.index++]);
|
|
286
|
-
} else {
|
|
287
|
-
values.push(null);
|
|
288
|
-
}
|
|
289
|
-
} else if (t.type === "STRING") {
|
|
290
|
-
values.push(t.value);
|
|
291
|
-
} else if (t.type === "NUMBER" || /^-?\d+(\.\d+)?$/.test(t.value)) {
|
|
292
|
-
values.push(Number(t.value));
|
|
293
|
-
} else {
|
|
294
|
-
values.push(t.value);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
cursor++;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
statements.push({
|
|
301
|
-
type: "INSERT",
|
|
302
|
-
table,
|
|
303
|
-
fields,
|
|
304
|
-
columns: values.map((v) => (typeof v === "object" ? JSON.stringify(v) : String(v ?? ""))),
|
|
305
|
-
values,
|
|
306
|
-
});
|
|
307
|
-
} else {
|
|
308
|
-
cursor++;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return statements;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
private parseCreate(tokens: Token[]): CreateStatement[] {
|
|
316
|
-
const statements: CreateStatement[] = [];
|
|
317
|
-
let cursor = 0;
|
|
318
|
-
|
|
319
|
-
while (cursor < tokens.length) {
|
|
320
|
-
const createIdx = tokens.slice(cursor).findIndex((t) => t.type === "CREATE");
|
|
321
|
-
if (createIdx === -1) break;
|
|
322
|
-
const startIdx = cursor + createIdx;
|
|
323
|
-
|
|
324
|
-
const semiIdx = tokens.slice(startIdx).findIndex((t) => t.type === "SEMICOLON");
|
|
325
|
-
if (semiIdx === -1) {
|
|
326
|
-
throw new Error("Invalid CREATE statement: missing ';' at end");
|
|
327
|
-
}
|
|
328
|
-
const currentTokens = tokens.slice(startIdx, startIdx + semiIdx + 1);
|
|
329
|
-
cursor = startIdx + semiIdx + 1;
|
|
330
|
-
|
|
331
|
-
const nextToken = currentTokens[1];
|
|
332
|
-
if (!nextToken || !["TABLE", "INDEX"].includes(nextToken.type)) {
|
|
333
|
-
throw new Error(`Invalid statement at near ${nextToken?.value}. Should be TABLE or INDEX!`);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const currentTable = this.foundTable(currentTokens);
|
|
337
|
-
if (!currentTable) {
|
|
338
|
-
throw new Error("Cannot find table name in CREATE TABLE statement");
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const openBracketIndex = currentTokens.findIndex(
|
|
342
|
-
(t) => t.type === "BRACKETS" && t.value === "(",
|
|
343
|
-
);
|
|
344
|
-
const closeBracketIndex = currentTokens.findIndex(
|
|
345
|
-
(t) => t.type === "BRACKETS" && t.value === ")",
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
if (openBracketIndex === -1 || closeBracketIndex === -1) {
|
|
349
|
-
throw new Error("Invalid statement. '(' or ')' is missing in CREATE TABLE!");
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const creationColumns: CreateStatement["columns"] = [];
|
|
353
|
-
const innerTokens = currentTokens.slice(openBracketIndex + 1, closeBracketIndex);
|
|
354
|
-
|
|
355
|
-
const isTypeDefOrDecorators = (token: Token) =>
|
|
356
|
-
TYPES_DEFS.includes(token.value.toUpperCase() as any) || token.type !== "IDENTIFIER";
|
|
357
|
-
|
|
358
|
-
for (let i = 0; i < innerTokens.length; i++) {
|
|
359
|
-
const token = innerTokens[i]!;
|
|
360
|
-
if (isTypeDefOrDecorators(token)) continue;
|
|
361
|
-
|
|
362
|
-
const tokenTypeDef = innerTokens[i + 1];
|
|
363
|
-
if (!tokenTypeDef) continue;
|
|
364
|
-
|
|
365
|
-
const mappedType =
|
|
366
|
-
TYPES_DEFS_MAPPING[tokenTypeDef.value.toUpperCase() as (typeof TYPES_DEFS)[number]];
|
|
367
|
-
if (!mappedType) {
|
|
368
|
-
throw new Error(`Unknown type at near ${tokenTypeDef.value}`);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
creationColumns.push(`${token.value}:${mappedType}`);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
statements.push({
|
|
375
|
-
type: "CREATE",
|
|
376
|
-
table: currentTable.value,
|
|
377
|
-
columns: creationColumns,
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
return statements;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
parse<T extends StatementType = StatementType>(tokens: Token[], params?: any[]): Statement<T>[] {
|
|
385
|
-
if (tokens.length < 5) {
|
|
386
|
-
throw new Error(`Invalid tokens array with missing elements!`);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
const firstStatement = tokens[0]!;
|
|
390
|
-
if (!this.statementTypes.includes(firstStatement.type as any)) {
|
|
391
|
-
throw new Error(`Invalid statement at near ${firstStatement.value}`);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const paramState = { index: 0 };
|
|
395
|
-
|
|
396
|
-
if (firstStatement.type === "CREATE") {
|
|
397
|
-
return this.parseCreate(tokens) as Statement<T>[];
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (firstStatement.type === "SELECT") {
|
|
401
|
-
return [this.parseSelect(tokens)] as Statement<T>[];
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (firstStatement.type === "INSERT") {
|
|
405
|
-
const stmtChunks: Token[][] = [];
|
|
406
|
-
let currentChunk: Token[] = [];
|
|
407
|
-
for (const t of tokens) {
|
|
408
|
-
currentChunk.push(t);
|
|
409
|
-
if (t.type === "SEMICOLON") {
|
|
410
|
-
stmtChunks.push(currentChunk);
|
|
411
|
-
currentChunk = [];
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
if (currentChunk.length > 0) stmtChunks.push(currentChunk);
|
|
415
|
-
|
|
416
|
-
const results: InsertStatement[] = [];
|
|
417
|
-
for (const chunk of stmtChunks) {
|
|
418
|
-
if (chunk.some((t) => t.type === "INSERT")) {
|
|
419
|
-
results.push(...this.parseInsert(chunk, params, paramState));
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return results as Statement<T>[];
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
throw new Error(`Unsupported statement type: ${firstStatement.type}`);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { LocalDBType } from "../sheet/sheet.types";
|
|
2
|
-
|
|
3
|
-
export type StatementType = "SELECT" | "INSERT" | "CREATE";
|
|
4
|
-
|
|
5
|
-
export type JoinType = "INNER" | "LEFT" | "RIGHT" | "FULL" | "CROSS" | "JOIN";
|
|
6
|
-
|
|
7
|
-
export type JoinCondition = {
|
|
8
|
-
leftTable?: string;
|
|
9
|
-
leftColumn: string;
|
|
10
|
-
operator: "=";
|
|
11
|
-
rightTable?: string;
|
|
12
|
-
rightColumn: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type JoinClause = {
|
|
16
|
-
type: JoinType;
|
|
17
|
-
table: string;
|
|
18
|
-
alias?: string;
|
|
19
|
-
on?: JoinCondition;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type WhereCondition = {
|
|
23
|
-
table?: string;
|
|
24
|
-
column: string;
|
|
25
|
-
operator: "=" | "!=" | ">" | "<" | ">=" | "<=";
|
|
26
|
-
value: any;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type SelectStatement = {
|
|
30
|
-
type: "SELECT";
|
|
31
|
-
columns: string[];
|
|
32
|
-
table: string;
|
|
33
|
-
alias?: string;
|
|
34
|
-
joins?: JoinClause[];
|
|
35
|
-
where?: WhereCondition[];
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type InsertStatement = {
|
|
39
|
-
type: "INSERT";
|
|
40
|
-
columns: string[];
|
|
41
|
-
table: string;
|
|
42
|
-
fields?: string[];
|
|
43
|
-
values?: any[];
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type CreateStatement = {
|
|
47
|
-
type: "CREATE";
|
|
48
|
-
columns: `${string}:${LocalDBType}`[];
|
|
49
|
-
table: string;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export type Statement<T extends StatementType = StatementType> = T extends "SELECT"
|
|
53
|
-
? SelectStatement
|
|
54
|
-
: T extends "INSERT"
|
|
55
|
-
? InsertStatement
|
|
56
|
-
: CreateStatement;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { LocalDBType } from "./sheet.types";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
|
|
4
|
-
export const DEFAULT_FIELDS_SCHEMA = new Map<LocalDBType, z.ZodType>([
|
|
5
|
-
["string", z.string()],
|
|
6
|
-
["number", z.number()],
|
|
7
|
-
["bigint", z.bigint()],
|
|
8
|
-
["symbol", z.symbol()],
|
|
9
|
-
["undefined", z.undefined()],
|
|
10
|
-
["boolean", z.boolean()],
|
|
11
|
-
["object", z.record(z.string(), z.any()).or(z.object({}))],
|
|
12
|
-
["uuid", z.string()],
|
|
13
|
-
["array.string", z.array(z.string())],
|
|
14
|
-
[
|
|
15
|
-
"file",
|
|
16
|
-
z.custom<any>((val) => {
|
|
17
|
-
if (typeof Blob !== "undefined" && val instanceof Blob) return true;
|
|
18
|
-
if (typeof File !== "undefined" && val instanceof File) return true;
|
|
19
|
-
if (typeof val === "object" && val !== null) return true;
|
|
20
|
-
return false;
|
|
21
|
-
}),
|
|
22
|
-
],
|
|
23
|
-
[
|
|
24
|
-
"blob",
|
|
25
|
-
z.custom<any>((val) => {
|
|
26
|
-
if (typeof Blob !== "undefined" && val instanceof Blob) return true;
|
|
27
|
-
if (typeof File !== "undefined" && val instanceof File) return true;
|
|
28
|
-
if (typeof val === "object" && val !== null) return true;
|
|
29
|
-
return false;
|
|
30
|
-
}),
|
|
31
|
-
],
|
|
32
|
-
] as const);
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Statement } from "../parser/parser.types";
|
|
2
|
-
import type { Field, FieldType, Table } from "./sheet.types";
|
|
3
|
-
|
|
4
|
-
interface Sheet {
|
|
5
|
-
RegisterSheet(...objects: object[]): Promise<Table[]>;
|
|
6
|
-
GetTables(): Table[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class TablesSheet implements Sheet {
|
|
10
|
-
private tables: Table[] = [];
|
|
11
|
-
|
|
12
|
-
constructor() {}
|
|
13
|
-
|
|
14
|
-
private statementToTable(stm: Statement<"CREATE">): Table {
|
|
15
|
-
const fields: Table["fields"] = {};
|
|
16
|
-
const order: string[] = [];
|
|
17
|
-
|
|
18
|
-
for (const [key, value] of stm.columns.map((cl) => cl.split(":"))) {
|
|
19
|
-
const fieldType = value as FieldType;
|
|
20
|
-
|
|
21
|
-
const newField: Field<typeof fieldType> = fieldType;
|
|
22
|
-
fields[key!] = newField;
|
|
23
|
-
|
|
24
|
-
if (order.includes(key!)) {
|
|
25
|
-
throw new Error(`Duplicate field at statement near ${key}`);
|
|
26
|
-
}
|
|
27
|
-
order.push(key!);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
name: stm.table,
|
|
32
|
-
fields,
|
|
33
|
-
order,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async RegisterSheet(statements: Statement<"CREATE">[]) {
|
|
38
|
-
const tables = statements.map((stm) => this.statementToTable(stm));
|
|
39
|
-
this.tables = tables;
|
|
40
|
-
|
|
41
|
-
return tables;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
GetTables(): Table[] {
|
|
45
|
-
return this.tables;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type LocalDBType =
|
|
2
|
-
| "string"
|
|
3
|
-
| "number"
|
|
4
|
-
| "bigint"
|
|
5
|
-
| "boolean"
|
|
6
|
-
| "symbol"
|
|
7
|
-
| "undefined"
|
|
8
|
-
| "object"
|
|
9
|
-
| "uuid"
|
|
10
|
-
| "array.string"
|
|
11
|
-
| "file"
|
|
12
|
-
| "blob";
|
|
13
|
-
|
|
14
|
-
export type LocalDBNativeType =
|
|
15
|
-
| string
|
|
16
|
-
| number
|
|
17
|
-
| bigint
|
|
18
|
-
| boolean
|
|
19
|
-
| symbol
|
|
20
|
-
| object
|
|
21
|
-
| Blob
|
|
22
|
-
| File
|
|
23
|
-
| null
|
|
24
|
-
| undefined;
|
|
25
|
-
|
|
26
|
-
export type Field<T extends LocalDBType = LocalDBType> = T;
|
|
27
|
-
export type FieldType = LocalDBType;
|
|
28
|
-
|
|
29
|
-
export interface LocalDBTableMap {
|
|
30
|
-
"__db.types": {};
|
|
31
|
-
}
|
|
32
|
-
export type LocalDBTableName = keyof LocalDBTableMap | string;
|
|
33
|
-
|
|
34
|
-
export type Table = {
|
|
35
|
-
name: LocalDBTableName;
|
|
36
|
-
fields: Record<string, Field>;
|
|
37
|
-
order: string[];
|
|
38
|
-
};
|
package/tsconfig.app.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.app.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"composite": true,
|
|
5
|
-
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
6
|
-
"target": "es2023",
|
|
7
|
-
"lib": ["ES2023", "DOM"],
|
|
8
|
-
"module": "esnext",
|
|
9
|
-
"types": ["vite/client"],
|
|
10
|
-
"allowArbitraryExtensions": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
|
|
13
|
-
/* Bundler mode */
|
|
14
|
-
"moduleResolution": "bundler",
|
|
15
|
-
"verbatimModuleSyntax": true,
|
|
16
|
-
"moduleDetection": "force",
|
|
17
|
-
"jsx": "react-jsx",
|
|
18
|
-
|
|
19
|
-
/* Linting */
|
|
20
|
-
"noUnusedLocals": true,
|
|
21
|
-
"noUnusedParameters": true,
|
|
22
|
-
"erasableSyntaxOnly": true,
|
|
23
|
-
"noFallthroughCasesInSwitch": true
|
|
24
|
-
},
|
|
25
|
-
"include": ["src"]
|
|
26
|
-
}
|
package/tsconfig.json
DELETED
package/tsconfig.node.json
DELETED
package/tsconfig.tsbuildinfo
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"fileNames":[],"fileInfos":[],"root":[],"options":{"composite":true,"jsx":1},"version":"6.0.3"}
|
package/vite.config.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
|
|
2
|
-
import babel from "@rolldown/plugin-babel";
|
|
3
|
-
import { defineConfig } from "vite";
|
|
4
|
-
import tailwindcss from "@tailwindcss/vite";
|
|
5
|
-
|
|
6
|
-
// https://vite.dev/config/
|
|
7
|
-
export default defineConfig({
|
|
8
|
-
plugins: [react(), tailwindcss(), babel({ presets: [reactCompilerPreset()] })],
|
|
9
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|