@coorax/react 0.0.0-canary.0 → 0.0.0-canary.10

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.
Files changed (198) hide show
  1. package/dist/components/commons/button.d.ts +8 -0
  2. package/dist/components/commons/youtube.d.ts +2 -0
  3. package/dist/components/corax-context-provider.d.ts +11 -0
  4. package/dist/components/corax-flow.d.ts +6 -0
  5. package/dist/components/errors/iframe.error.d.ts +2 -0
  6. package/dist/components/errors/image.error.d.ts +2 -0
  7. package/dist/components/errors/video.errors.d.ts +2 -0
  8. package/dist/components/fallbacks/iframe.fallback.d.ts +2 -0
  9. package/dist/components/fallbacks/image.fallback.d.ts +2 -0
  10. package/dist/components/fallbacks/link.fallback.d.ts +2 -0
  11. package/dist/components/fallbacks/video.fallback.d.ts +2 -0
  12. package/dist/components/slots/buttons/block-actions-button.d.ts +3 -0
  13. package/dist/components/slots/buttons/caption-button.d.ts +3 -0
  14. package/dist/components/slots/buttons/code-theme-button.d.ts +3 -0
  15. package/dist/components/slots/buttons/delete-button.d.ts +3 -0
  16. package/dist/components/slots/buttons/divider-style-button.d.ts +3 -0
  17. package/dist/components/slots/buttons/divider-width-button.d.ts +3 -0
  18. package/dist/components/slots/buttons/iframe-playback-button.d.ts +3 -0
  19. package/dist/components/slots/buttons/image-width-button.d.ts +3 -0
  20. package/dist/components/slots/buttons/paragraph-theme-button.d.ts +3 -0
  21. package/dist/components/slots/buttons/toolbar-button.d.ts +3 -0
  22. package/dist/components/slots/maps/block-actions.d.ts +1 -0
  23. package/dist/components/slots/maps/overlays.d.ts +1 -0
  24. package/dist/components/slots/maps/text-inspector.d.ts +2 -0
  25. package/dist/components/slots/maps/toolbar.d.ts +1 -0
  26. package/dist/components/slots/overlays/focus-overlay.d.ts +3 -0
  27. package/dist/components/slots/overlays/hover-overlay.d.ts +3 -0
  28. package/dist/components/slots/overlays/selection-overlay.d.ts +3 -0
  29. package/dist/components/slots/slot-button.d.ts +6 -0
  30. package/dist/components/slots/slot-component.d.ts +5 -0
  31. package/dist/components/slots/slots.d.ts +4 -0
  32. package/dist/constants/field.constants.d.ts +2 -0
  33. package/dist/hooks/custom/use-custom-ref.d.ts +1 -0
  34. package/dist/hooks/custom/use-isomorphic-layout-effect.d.ts +2 -0
  35. package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -0
  36. package/dist/hooks/use-block-entry.d.ts +2 -0
  37. package/dist/hooks/use-block.d.ts +2 -0
  38. package/dist/hooks/use-flow.d.ts +17 -0
  39. package/dist/hooks/use-is-selected.d.ts +2 -0
  40. package/dist/hooks/use-keyboard.d.ts +10 -0
  41. package/dist/hooks/use-registry.d.ts +3 -0
  42. package/dist/hooks/use-renderer.d.ts +2 -0
  43. package/dist/hooks/use-slice.d.ts +2 -0
  44. package/dist/hooks/use-slots.d.ts +2 -0
  45. package/dist/hooks/use-tasks.d.ts +7 -0
  46. package/dist/hooks/use-text-input.d.ts +2 -0
  47. package/dist/hooks/use-ui-context.d.ts +2 -0
  48. package/dist/hooks/useSelection.d.ts +2 -0
  49. package/{src/index.ts → dist/index.d.ts} +8 -4
  50. package/dist/index.js +3575 -0
  51. package/dist/lib/comp.utils.d.ts +8 -0
  52. package/dist/lib/func.utils.d.ts +3 -0
  53. package/dist/lib/index.d.ts +4 -0
  54. package/dist/lib/selection.utils.d.ts +5 -0
  55. package/dist/lib/slots.utils.d.ts +4 -0
  56. package/dist/lifecycle/fields/common/focus.events/onblur.d.ts +3 -0
  57. package/dist/lifecycle/fields/common/focus.events/onfocus.d.ts +3 -0
  58. package/dist/lifecycle/fields/common/handlers.d.ts +13 -0
  59. package/dist/lifecycle/fields/common/mouse.events/onclick.d.ts +3 -0
  60. package/dist/lifecycle/fields/common/mouse.events/onmouseenter.d.ts +3 -0
  61. package/dist/lifecycle/fields/common/mouse.events/onmouseleave.d.ts +3 -0
  62. package/dist/lifecycle/fields/divider/handlers.d.ts +7 -0
  63. package/dist/lifecycle/fields/divider/keyboard.events/onkeydown.d.ts +3 -0
  64. package/dist/lifecycle/fields/editable/focus.events/onbeforeinput.d.ts +3 -0
  65. package/dist/lifecycle/fields/editable/handlers.d.ts +7 -0
  66. package/dist/lifecycle/fields/editable/keyboard.events/onkeydown.d.ts +3 -0
  67. package/dist/lifecycle/fields/editable/mouse.events/ondoubleclick.d.ts +4 -0
  68. package/dist/lifecycle/fields/editable/synthetic.events/onselect.d.ts +3 -0
  69. package/dist/lifecycle/fields/handlers.registry.d.ts +12 -0
  70. package/dist/lifecycle/fields/lifecycle.fields.d.ts +10 -0
  71. package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +4 -0
  72. package/dist/lifecycle/fields/lifecycle.utils.d.ts +8 -0
  73. package/dist/lifecycle/fields/media/common/handlers.d.ts +7 -0
  74. package/dist/lifecycle/fields/media/common/keyboard.events/onkeydown.d.ts +3 -0
  75. package/dist/lifecycle/fields/media/common/synthetic.events/onerror.d.ts +3 -0
  76. package/dist/lifecycle/fields/media/iframe/handlers.d.ts +7 -0
  77. package/dist/lifecycle/fields/media/iframe/synthetic.events/onload.d.ts +3 -0
  78. package/dist/lifecycle/fields/media/image/handlers.d.ts +7 -0
  79. package/dist/lifecycle/fields/media/image/synthetic.events/onload.d.ts +3 -0
  80. package/dist/lifecycle/fields/media/video/handlers.d.ts +7 -0
  81. package/dist/lifecycle/fields/media/video/mouse.events/ondoubleclick.d.ts +4 -0
  82. package/dist/lifecycle/fields/media/video/synthetic.events/oncanplaythrough.d.ts +3 -0
  83. package/dist/lifecycle/index.d.ts +3 -0
  84. package/dist/modules/autosave.module.d.ts +41 -0
  85. package/dist/modules/errors.module.d.ts +7 -0
  86. package/dist/modules/fallbacks.module.d.ts +7 -0
  87. package/dist/modules/slots.module.d.ts +7 -0
  88. package/dist/modules/ui-primitives.module.d.ts +7 -0
  89. package/dist/primitives/fields/field.primitives.d.ts +2 -0
  90. package/dist/primitives/index.d.ts +3 -0
  91. package/dist/registry/index.d.ts +4 -0
  92. package/dist/registry/slots.registry.d.ts +4 -0
  93. package/{src/registry/ui.primitives.registry.tsx → dist/registry/ui.primitives.registry.d.ts} +4 -5
  94. package/dist/services/index.d.ts +2 -0
  95. package/dist/services/localdb/db/db.d.ts +78 -0
  96. package/dist/services/localdb/db/db.test.d.ts +1 -0
  97. package/dist/services/localdb/dbtest.d.ts +1 -0
  98. package/dist/services/localdb/lexer/lexer.d.ts +14 -0
  99. package/dist/services/localdb/lexer/lexer.test.d.ts +1 -0
  100. package/dist/services/localdb/lexer/lexer.types.d.ts +5 -0
  101. package/dist/services/localdb/operator/operator.d.ts +10 -0
  102. package/dist/services/localdb/parser/parser.constants.d.ts +3 -0
  103. package/dist/services/localdb/parser/parser.d.ts +15 -0
  104. package/dist/services/localdb/parser/parser.test.d.ts +1 -0
  105. package/dist/services/localdb/parser/parser.types.d.ts +49 -0
  106. package/dist/services/localdb/sheet/sheet.constants.d.ts +3 -0
  107. package/dist/services/localdb/sheet/sheet.d.ts +14 -0
  108. package/dist/services/localdb/sheet/sheet.types.d.ts +13 -0
  109. package/dist/styles.css +2 -0
  110. package/package.json +38 -15
  111. package/styles.css +2 -1
  112. package/.oxlintrc.json +0 -8
  113. package/src/components/commons/button.tsx +0 -59
  114. package/src/components/corax-context-provider.tsx +0 -47
  115. package/src/components/corax-flow.tsx +0 -44
  116. package/src/components/fallbacks/image.fallback.tsx +0 -23
  117. package/src/components/slots/buttons/block-actions-button.tsx +0 -85
  118. package/src/components/slots/buttons/toolbar-button.tsx +0 -40
  119. package/src/components/slots/maps/block-actions.tsx +0 -84
  120. package/src/components/slots/maps/overlays.tsx +0 -9
  121. package/src/components/slots/maps/text-inspector.tsx +0 -5
  122. package/src/components/slots/maps/toolbar.tsx +0 -79
  123. package/src/components/slots/overlays/focus-overlay.tsx +0 -30
  124. package/src/components/slots/overlays/hover-overlay.tsx +0 -18
  125. package/src/components/slots/overlays/selection-overlay.tsx +0 -20
  126. package/src/components/slots/slot-button.tsx +0 -20
  127. package/src/components/slots/slot-component.tsx +0 -17
  128. package/src/components/slots/slots.tsx +0 -29
  129. package/src/constants/field.constants.ts +0 -3
  130. package/src/hooks/custom/use-custom-ref.ts +0 -11
  131. package/src/hooks/use-block-entry.ts +0 -44
  132. package/src/hooks/use-block.ts +0 -11
  133. package/src/hooks/use-flow.ts +0 -83
  134. package/src/hooks/use-keyboard.ts +0 -66
  135. package/src/hooks/use-registry.ts +0 -18
  136. package/src/hooks/use-renderer.ts +0 -8
  137. package/src/hooks/use-slice.ts +0 -13
  138. package/src/hooks/use-slots.ts +0 -13
  139. package/src/hooks/use-tasks.ts +0 -33
  140. package/src/hooks/use-text-input.ts +0 -83
  141. package/src/hooks/use-ui-context.ts +0 -16
  142. package/src/hooks/useSelection.ts +0 -27
  143. package/src/lib/comp.utils.tsx +0 -44
  144. package/src/lib/func.utils.ts +0 -15
  145. package/src/lib/selection.utils.ts +0 -33
  146. package/src/lib/slots.utils.tsx +0 -23
  147. package/src/lifecycle/fields/focus.events/onbeforeinput.ts +0 -21
  148. package/src/lifecycle/fields/focus.events/onblur.ts +0 -19
  149. package/src/lifecycle/fields/focus.events/onfocus.ts +0 -16
  150. package/src/lifecycle/fields/keyboard.events/onkeydown.ts +0 -128
  151. package/src/lifecycle/fields/lifecycle.fields.ts +0 -116
  152. package/src/lifecycle/fields/lifecycle.fields.types.ts +0 -33
  153. package/src/lifecycle/fields/lifecycle.utils.ts +0 -26
  154. package/src/lifecycle/fields/mouse.events/onclick.ts +0 -79
  155. package/src/lifecycle/fields/mouse.events/ondoubleclick.ts +0 -27
  156. package/src/lifecycle/fields/mouse.events/onmouseenter.ts +0 -27
  157. package/src/lifecycle/fields/mouse.events/onmouseleave.ts +0 -21
  158. package/src/lifecycle/fields/synthetic.events/onload.ts +0 -16
  159. package/src/lifecycle/fields/synthetic.events/onselect.ts +0 -57
  160. package/src/lifecycle/index.ts +0 -1
  161. package/src/modules/autosave.module.ts +0 -238
  162. package/src/modules/fallbacks.module.tsx +0 -19
  163. package/src/modules/slots.module.tsx +0 -28
  164. package/src/modules/ui-primitives.module.tsx +0 -20
  165. package/src/primitives/fields/field.primitives.tsx +0 -86
  166. package/src/primitives/index.ts +0 -8
  167. package/src/registry/fallbacks.registry.tsx +0 -9
  168. package/src/registry/index.ts +0 -5
  169. package/src/registry/primitives.registry.tsx +0 -57
  170. package/src/registry/registry.ts +0 -44
  171. package/src/registry/slots.registry.tsx +0 -6
  172. package/src/renderer/renderer.test.ts +0 -34
  173. package/src/renderer/renderer.tsx +0 -164
  174. package/src/renderer/renderer.types.ts +0 -3
  175. package/src/renderer/renderer.utils.tsx +0 -139
  176. package/src/renderer/utils/divider.renderer.utils.tsx +0 -53
  177. package/src/services/localdb/db/db.test.ts +0 -351
  178. package/src/services/localdb/db/db.ts +0 -628
  179. package/src/services/localdb/lexer/lexer.test.ts +0 -123
  180. package/src/services/localdb/lexer/lexer.ts +0 -173
  181. package/src/services/localdb/lexer/lexer.types.ts +0 -34
  182. package/src/services/localdb/operator/operator.ts +0 -16
  183. package/src/services/localdb/parser/parser.constants.ts +0 -23
  184. package/src/services/localdb/parser/parser.test.ts +0 -172
  185. package/src/services/localdb/parser/parser.ts +0 -427
  186. package/src/services/localdb/parser/parser.types.ts +0 -56
  187. package/src/services/localdb/sheet/sheet.constants.ts +0 -32
  188. package/src/services/localdb/sheet/sheet.ts +0 -47
  189. package/src/services/localdb/sheet/sheet.types.ts +0 -38
  190. package/tsconfig.app.json +0 -26
  191. package/tsconfig.json +0 -9
  192. package/tsconfig.node.json +0 -9
  193. package/tsconfig.tsbuildinfo +0 -1
  194. package/vite.config.ts +0 -9
  195. /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
  196. /package/{src/components/slots/index.ts → dist/components/slots/index.d.ts} +0 -0
  197. /package/{src/components/slots/maps/index.ts → dist/components/slots/maps/index.d.ts} +0 -0
  198. /package/{src/modules/index.ts → dist/modules/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
@@ -1,9 +0,0 @@
1
- {
2
- "files": [],
3
- "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }],
4
- "compilerOptions": {
5
- "composite": true,
6
- "jsx": "preserve",
7
- "types": ["vite/client"]
8
- }
9
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.node.json",
3
- "compilerOptions": {
4
- "composite": true,
5
- "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
6
- "types": ["node"]
7
- },
8
- "include": ["vite.config.ts"]
9
- }
@@ -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
- });