@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.
- package/dist/components/commons/button.d.ts +8 -0
- package/dist/components/commons/youtube.d.ts +2 -0
- package/dist/components/corax-context-provider.d.ts +11 -0
- package/dist/components/corax-flow.d.ts +6 -0
- package/dist/components/errors/iframe.error.d.ts +2 -0
- package/dist/components/errors/image.error.d.ts +2 -0
- package/dist/components/errors/video.errors.d.ts +2 -0
- package/dist/components/fallbacks/iframe.fallback.d.ts +2 -0
- package/dist/components/fallbacks/image.fallback.d.ts +2 -0
- package/dist/components/fallbacks/link.fallback.d.ts +2 -0
- package/dist/components/fallbacks/video.fallback.d.ts +2 -0
- package/dist/components/slots/buttons/block-actions-button.d.ts +3 -0
- package/dist/components/slots/buttons/caption-button.d.ts +3 -0
- package/dist/components/slots/buttons/code-theme-button.d.ts +3 -0
- package/dist/components/slots/buttons/delete-button.d.ts +3 -0
- package/dist/components/slots/buttons/divider-style-button.d.ts +3 -0
- package/dist/components/slots/buttons/divider-width-button.d.ts +3 -0
- package/dist/components/slots/buttons/iframe-playback-button.d.ts +3 -0
- package/dist/components/slots/buttons/image-width-button.d.ts +3 -0
- package/dist/components/slots/buttons/paragraph-theme-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-is-selected.d.ts +2 -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} +8 -4
- package/dist/index.js +3575 -0
- package/dist/lib/comp.utils.d.ts +8 -0
- package/dist/lib/func.utils.d.ts +3 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/selection.utils.d.ts +5 -0
- package/dist/lib/slots.utils.d.ts +4 -0
- package/dist/lifecycle/fields/common/focus.events/onblur.d.ts +3 -0
- package/dist/lifecycle/fields/common/focus.events/onfocus.d.ts +3 -0
- package/dist/lifecycle/fields/common/handlers.d.ts +13 -0
- package/dist/lifecycle/fields/common/mouse.events/onclick.d.ts +3 -0
- package/dist/lifecycle/fields/common/mouse.events/onmouseenter.d.ts +3 -0
- package/dist/lifecycle/fields/common/mouse.events/onmouseleave.d.ts +3 -0
- package/dist/lifecycle/fields/divider/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/divider/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/editable/focus.events/onbeforeinput.d.ts +3 -0
- package/dist/lifecycle/fields/editable/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/editable/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/editable/mouse.events/ondoubleclick.d.ts +4 -0
- package/dist/lifecycle/fields/editable/synthetic.events/onselect.d.ts +3 -0
- package/dist/lifecycle/fields/handlers.registry.d.ts +12 -0
- package/dist/lifecycle/fields/lifecycle.fields.d.ts +10 -0
- package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +4 -0
- package/dist/lifecycle/fields/lifecycle.utils.d.ts +8 -0
- package/dist/lifecycle/fields/media/common/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/media/common/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/media/common/synthetic.events/onerror.d.ts +3 -0
- package/dist/lifecycle/fields/media/iframe/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/media/iframe/synthetic.events/onload.d.ts +3 -0
- package/dist/lifecycle/fields/media/image/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/media/image/synthetic.events/onload.d.ts +3 -0
- package/dist/lifecycle/fields/media/video/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/media/video/mouse.events/ondoubleclick.d.ts +4 -0
- package/dist/lifecycle/fields/media/video/synthetic.events/oncanplaythrough.d.ts +3 -0
- package/dist/lifecycle/index.d.ts +3 -0
- package/dist/modules/autosave.module.d.ts +41 -0
- package/dist/modules/errors.module.d.ts +7 -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/dist/registry/index.d.ts +4 -0
- package/dist/registry/slots.registry.d.ts +4 -0
- package/{src/registry/ui.primitives.registry.tsx → dist/registry/ui.primitives.registry.d.ts} +4 -5
- package/dist/services/index.d.ts +2 -0
- package/dist/services/localdb/db/db.d.ts +78 -0
- package/dist/services/localdb/db/db.test.d.ts +1 -0
- package/dist/services/localdb/dbtest.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 +15 -0
- package/dist/services/localdb/parser/parser.test.d.ts +1 -0
- package/dist/services/localdb/parser/parser.types.d.ts +49 -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 +2 -0
- package/package.json +38 -15
- package/styles.css +2 -1
- 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/fallbacks.registry.tsx +0 -9
- package/src/registry/index.ts +0 -5
- 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.types.ts +0 -3
- 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
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { Lexer } from "./lexer";
|
|
3
|
-
|
|
4
|
-
describe("Lexer", () => {
|
|
5
|
-
test("Should parse * select request", () => {
|
|
6
|
-
const query = "select * from users;";
|
|
7
|
-
const expectOutput = [
|
|
8
|
-
{ type: "SELECT", value: "SELECT" },
|
|
9
|
-
{ type: "STAR", value: "*" },
|
|
10
|
-
{ type: "FROM", value: "FROM" },
|
|
11
|
-
{ type: "IDENTIFIER", value: "users" },
|
|
12
|
-
{ type: "SEMICOLON", value: ";" },
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
const lexer = new Lexer();
|
|
16
|
-
const result = lexer.lex(query);
|
|
17
|
-
|
|
18
|
-
expect(result.length).toBe(expectOutput.length);
|
|
19
|
-
expect(result[0]?.type).toBe(expectOutput[0]?.type);
|
|
20
|
-
expect(result[4]?.type).toBe(expectOutput[4]?.type);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test("Should parse fields select request", () => {
|
|
24
|
-
const query = "select name, email, pwd from users;";
|
|
25
|
-
const expectOutput = [
|
|
26
|
-
{ type: "SELECT", value: "SELECT" },
|
|
27
|
-
{ type: "IDENTIFIER", value: "name" },
|
|
28
|
-
{ type: "COMMA", value: "," },
|
|
29
|
-
{ type: "IDENTIFIER", value: "email" },
|
|
30
|
-
{ type: "COMMA", value: "," },
|
|
31
|
-
{ type: "IDENTIFIER", value: "pwd" },
|
|
32
|
-
{ type: "FROM", value: "FROM" },
|
|
33
|
-
{ type: "IDENTIFIER", value: "users" },
|
|
34
|
-
{ type: "SEMICOLON", value: ";" },
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
const lexer = new Lexer();
|
|
38
|
-
const result = lexer.lex(query);
|
|
39
|
-
|
|
40
|
-
expect(result.length).toBe(expectOutput.length);
|
|
41
|
-
expect(result[0]?.type).toBe(expectOutput[0]?.type);
|
|
42
|
-
expect(result[4]?.type).toBe(expectOutput[4]?.type);
|
|
43
|
-
expect(result[8]?.type).toBe(expectOutput[8]?.type);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test("Should lex JOIN and ON tokens", () => {
|
|
47
|
-
const query = "SELECT * FROM documents JOIN fields ON documents.id = fields.document_id;";
|
|
48
|
-
const lexer = new Lexer();
|
|
49
|
-
const tokens = lexer.lex(query);
|
|
50
|
-
|
|
51
|
-
expect(tokens.map((t) => t.type)).toEqual([
|
|
52
|
-
"SELECT",
|
|
53
|
-
"STAR",
|
|
54
|
-
"FROM",
|
|
55
|
-
"IDENTIFIER",
|
|
56
|
-
"JOIN",
|
|
57
|
-
"IDENTIFIER",
|
|
58
|
-
"ON",
|
|
59
|
-
"IDENTIFIER",
|
|
60
|
-
"EQUALS",
|
|
61
|
-
"IDENTIFIER",
|
|
62
|
-
"SEMICOLON",
|
|
63
|
-
]);
|
|
64
|
-
|
|
65
|
-
expect(tokens[4]?.value).toBe("JOIN");
|
|
66
|
-
expect(tokens[5]?.value).toBe("fields");
|
|
67
|
-
expect(tokens[6]?.value).toBe("ON");
|
|
68
|
-
expect(tokens[7]?.value).toBe("documents.id");
|
|
69
|
-
expect(tokens[8]?.value).toBe("=");
|
|
70
|
-
expect(tokens[9]?.value).toBe("fields.document_id");
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test("Should lex LEFT JOIN and WHERE tokens", () => {
|
|
74
|
-
const query =
|
|
75
|
-
"SELECT * FROM documents LEFT JOIN medias ON documents.id = medias.document_id WHERE id = 'root';";
|
|
76
|
-
const lexer = new Lexer();
|
|
77
|
-
const tokens = lexer.lex(query);
|
|
78
|
-
|
|
79
|
-
expect(tokens.map((t) => t.type)).toEqual([
|
|
80
|
-
"SELECT",
|
|
81
|
-
"STAR",
|
|
82
|
-
"FROM",
|
|
83
|
-
"IDENTIFIER",
|
|
84
|
-
"LEFT",
|
|
85
|
-
"JOIN",
|
|
86
|
-
"IDENTIFIER",
|
|
87
|
-
"ON",
|
|
88
|
-
"IDENTIFIER",
|
|
89
|
-
"EQUALS",
|
|
90
|
-
"IDENTIFIER",
|
|
91
|
-
"WHERE",
|
|
92
|
-
"IDENTIFIER",
|
|
93
|
-
"EQUALS",
|
|
94
|
-
"STRING",
|
|
95
|
-
"SEMICOLON",
|
|
96
|
-
]);
|
|
97
|
-
|
|
98
|
-
expect(tokens[14]?.value).toBe("root");
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test("Should lex string literals with commas and spaces", () => {
|
|
102
|
-
const query = "INSERT INTO users VALUES ('Hello, world!', 42, ?);";
|
|
103
|
-
const lexer = new Lexer();
|
|
104
|
-
const tokens = lexer.lex(query);
|
|
105
|
-
|
|
106
|
-
expect(tokens.map((t) => t.type)).toEqual([
|
|
107
|
-
"INSERT",
|
|
108
|
-
"INTO",
|
|
109
|
-
"IDENTIFIER",
|
|
110
|
-
"VALUES",
|
|
111
|
-
"BRACKETS",
|
|
112
|
-
"STRING",
|
|
113
|
-
"COMMA",
|
|
114
|
-
"IDENTIFIER",
|
|
115
|
-
"COMMA",
|
|
116
|
-
"QUESTION_MARK",
|
|
117
|
-
"BRACKETS",
|
|
118
|
-
"SEMICOLON",
|
|
119
|
-
]);
|
|
120
|
-
|
|
121
|
-
expect(tokens[5]?.value).toBe("Hello, world!");
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import type { Token, TokenType } from "./lexer.types";
|
|
2
|
-
|
|
3
|
-
interface Lex {
|
|
4
|
-
lex: (sqlString: string) => Token[];
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export class Lexer implements Lex {
|
|
8
|
-
private pos = 0;
|
|
9
|
-
private word: string[] = [];
|
|
10
|
-
private tokensTypes: TokenType[] = [
|
|
11
|
-
"SELECT",
|
|
12
|
-
"FROM",
|
|
13
|
-
"WHERE",
|
|
14
|
-
"JOIN",
|
|
15
|
-
"INNER",
|
|
16
|
-
"LEFT",
|
|
17
|
-
"RIGHT",
|
|
18
|
-
"FULL",
|
|
19
|
-
"CROSS",
|
|
20
|
-
"ON",
|
|
21
|
-
"AND",
|
|
22
|
-
"OR",
|
|
23
|
-
"AS",
|
|
24
|
-
"INSERT",
|
|
25
|
-
"INTO",
|
|
26
|
-
"VALUES",
|
|
27
|
-
"CREATE",
|
|
28
|
-
"TABLE",
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
private cleanWord() {
|
|
32
|
-
this.word = [];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private bumpPos() {
|
|
36
|
-
this.pos++;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private flushWord(tokens: Token[]) {
|
|
40
|
-
if (this.word.length === 0) return;
|
|
41
|
-
const currentWord = this.word.join("");
|
|
42
|
-
const upper = currentWord.toUpperCase();
|
|
43
|
-
|
|
44
|
-
if (this.tokensTypes.includes(upper as TokenType)) {
|
|
45
|
-
tokens.push({
|
|
46
|
-
type: upper as TokenType,
|
|
47
|
-
value: upper,
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
tokens.push({
|
|
51
|
-
type: "IDENTIFIER",
|
|
52
|
-
value: currentWord,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
this.cleanWord();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
lex(sql: string): Token[] {
|
|
59
|
-
const sqlString = sql.replace(/[\r\n]+/g, " ").trim();
|
|
60
|
-
const tokens: Token[] = [];
|
|
61
|
-
|
|
62
|
-
if (!sqlString.endsWith(";")) {
|
|
63
|
-
throw new Error(`Failed to execute sql. ';' missing at the end`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.pos = 0;
|
|
67
|
-
this.cleanWord();
|
|
68
|
-
|
|
69
|
-
while (this.pos < sqlString.length) {
|
|
70
|
-
const currentChar = sqlString[this.pos]!;
|
|
71
|
-
|
|
72
|
-
// Handle strings '...' or "..."
|
|
73
|
-
if (currentChar === "'" || currentChar === '"') {
|
|
74
|
-
this.flushWord(tokens);
|
|
75
|
-
const quoteChar = currentChar;
|
|
76
|
-
this.bumpPos();
|
|
77
|
-
const strChars: string[] = [];
|
|
78
|
-
let closed = false;
|
|
79
|
-
|
|
80
|
-
while (this.pos < sqlString.length) {
|
|
81
|
-
const char = sqlString[this.pos]!;
|
|
82
|
-
if (char === "\\") {
|
|
83
|
-
this.bumpPos();
|
|
84
|
-
if (this.pos < sqlString.length) {
|
|
85
|
-
strChars.push(sqlString[this.pos]!);
|
|
86
|
-
this.bumpPos();
|
|
87
|
-
}
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (char === quoteChar) {
|
|
91
|
-
this.bumpPos();
|
|
92
|
-
closed = true;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
strChars.push(char);
|
|
96
|
-
this.bumpPos();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (!closed) {
|
|
100
|
-
throw new Error(`Unterminated string literal at ${this.pos}`);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
tokens.push({
|
|
104
|
-
type: "STRING",
|
|
105
|
-
value: strChars.join(""),
|
|
106
|
-
});
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Handle whitespace
|
|
111
|
-
if (currentChar === " " || currentChar === "\t") {
|
|
112
|
-
this.flushWord(tokens);
|
|
113
|
-
this.bumpPos();
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Handle single character delimiters/operators
|
|
118
|
-
switch (currentChar) {
|
|
119
|
-
case ",":
|
|
120
|
-
this.flushWord(tokens);
|
|
121
|
-
tokens.push({ type: "COMMA", value: "," });
|
|
122
|
-
this.bumpPos();
|
|
123
|
-
continue;
|
|
124
|
-
|
|
125
|
-
case ";":
|
|
126
|
-
this.flushWord(tokens);
|
|
127
|
-
tokens.push({ type: "SEMICOLON", value: ";" });
|
|
128
|
-
this.bumpPos();
|
|
129
|
-
continue;
|
|
130
|
-
|
|
131
|
-
case "(":
|
|
132
|
-
this.flushWord(tokens);
|
|
133
|
-
tokens.push({ type: "BRACKETS", value: "(" });
|
|
134
|
-
this.bumpPos();
|
|
135
|
-
continue;
|
|
136
|
-
|
|
137
|
-
case ")":
|
|
138
|
-
this.flushWord(tokens);
|
|
139
|
-
tokens.push({ type: "BRACKETS", value: ")" });
|
|
140
|
-
this.bumpPos();
|
|
141
|
-
continue;
|
|
142
|
-
|
|
143
|
-
case "*":
|
|
144
|
-
this.flushWord(tokens);
|
|
145
|
-
tokens.push({ type: "STAR", value: "*" });
|
|
146
|
-
this.bumpPos();
|
|
147
|
-
continue;
|
|
148
|
-
|
|
149
|
-
case "=":
|
|
150
|
-
this.flushWord(tokens);
|
|
151
|
-
tokens.push({ type: "EQUALS", value: "=" });
|
|
152
|
-
this.bumpPos();
|
|
153
|
-
continue;
|
|
154
|
-
|
|
155
|
-
case "?":
|
|
156
|
-
this.flushWord(tokens);
|
|
157
|
-
tokens.push({ type: "QUESTION_MARK", value: "?" });
|
|
158
|
-
this.bumpPos();
|
|
159
|
-
continue;
|
|
160
|
-
|
|
161
|
-
default:
|
|
162
|
-
this.word.push(currentChar);
|
|
163
|
-
this.bumpPos();
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
this.flushWord(tokens);
|
|
169
|
-
this.pos = 0;
|
|
170
|
-
this.cleanWord();
|
|
171
|
-
return tokens;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export type TokenType =
|
|
2
|
-
| "SELECT"
|
|
3
|
-
| "FROM"
|
|
4
|
-
| "WHERE"
|
|
5
|
-
| "JOIN"
|
|
6
|
-
| "INNER"
|
|
7
|
-
| "LEFT"
|
|
8
|
-
| "RIGHT"
|
|
9
|
-
| "FULL"
|
|
10
|
-
| "CROSS"
|
|
11
|
-
| "ON"
|
|
12
|
-
| "AND"
|
|
13
|
-
| "OR"
|
|
14
|
-
| "AS"
|
|
15
|
-
| "IDENTIFIER"
|
|
16
|
-
| "COMMA"
|
|
17
|
-
| "SEMICOLON"
|
|
18
|
-
| "STAR"
|
|
19
|
-
| "INSERT"
|
|
20
|
-
| "INTO"
|
|
21
|
-
| "VALUES"
|
|
22
|
-
| "BRACKETS"
|
|
23
|
-
| "CREATE"
|
|
24
|
-
| "TABLE"
|
|
25
|
-
| "EQUALS"
|
|
26
|
-
| "DOT"
|
|
27
|
-
| "STRING"
|
|
28
|
-
| "NUMBER"
|
|
29
|
-
| "QUESTION_MARK";
|
|
30
|
-
|
|
31
|
-
export type Token = {
|
|
32
|
-
type: TokenType;
|
|
33
|
-
value: string;
|
|
34
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Lexer } from "../lexer/lexer";
|
|
2
|
-
import { Parser } from "../parser/parser";
|
|
3
|
-
import type { Statement } from "../parser/parser.types";
|
|
4
|
-
|
|
5
|
-
interface Client {
|
|
6
|
-
NewRequest(query: string, params?: any[]): Statement[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class DBClient implements Client {
|
|
10
|
-
private lexer = new Lexer();
|
|
11
|
-
private parser = new Parser();
|
|
12
|
-
|
|
13
|
-
NewRequest(query: string, params?: any[]): Statement[] {
|
|
14
|
-
return this.parser.parse(this.lexer.lex(query), params);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { LocalDBType } from "../sheet/sheet.types";
|
|
2
|
-
|
|
3
|
-
export const TYPES_DEFS = [
|
|
4
|
-
"TEXT",
|
|
5
|
-
"DATETIME",
|
|
6
|
-
"INTEGER",
|
|
7
|
-
"UUID",
|
|
8
|
-
"OBJECT",
|
|
9
|
-
"ARRAY[STRING]",
|
|
10
|
-
"FILE",
|
|
11
|
-
"BLOB",
|
|
12
|
-
] as const;
|
|
13
|
-
|
|
14
|
-
export const TYPES_DEFS_MAPPING: Record<(typeof TYPES_DEFS)[number], LocalDBType> = {
|
|
15
|
-
TEXT: "string",
|
|
16
|
-
INTEGER: "number",
|
|
17
|
-
DATETIME: "number",
|
|
18
|
-
UUID: "uuid",
|
|
19
|
-
OBJECT: "object",
|
|
20
|
-
"ARRAY[STRING]": "array.string",
|
|
21
|
-
FILE: "file",
|
|
22
|
-
BLOB: "blob",
|
|
23
|
-
};
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { Lexer } from "../lexer/lexer";
|
|
3
|
-
import { Parser } from "./parser";
|
|
4
|
-
import type { CreateStatement, InsertStatement, SelectStatement } from "./parser.types";
|
|
5
|
-
|
|
6
|
-
describe("Parser", () => {
|
|
7
|
-
const lexer = new Lexer();
|
|
8
|
-
const parser = new Parser();
|
|
9
|
-
|
|
10
|
-
test("Should parse simple SELECT query", () => {
|
|
11
|
-
const query = "SELECT * FROM documents;";
|
|
12
|
-
const statements = parser.parse<"SELECT">(lexer.lex(query));
|
|
13
|
-
|
|
14
|
-
expect(statements.length).toBe(1);
|
|
15
|
-
expect(statements[0]).toEqual({
|
|
16
|
-
type: "SELECT",
|
|
17
|
-
columns: ["*"],
|
|
18
|
-
table: "documents",
|
|
19
|
-
alias: undefined,
|
|
20
|
-
joins: undefined,
|
|
21
|
-
where: undefined,
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("Should parse SELECT with columns", () => {
|
|
26
|
-
const query = "SELECT id, version FROM documents;";
|
|
27
|
-
const statements = parser.parse<"SELECT">(lexer.lex(query));
|
|
28
|
-
|
|
29
|
-
expect(statements.length).toBe(1);
|
|
30
|
-
expect(statements[0]?.columns).toEqual(["id", "version"]);
|
|
31
|
-
expect(statements[0]?.table).toBe("documents");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("Should parse SELECT with JOIN and ON clause", () => {
|
|
35
|
-
const query = "SELECT * FROM documents JOIN fields ON documents.id = fields.document_id;";
|
|
36
|
-
const statements = parser.parse<"SELECT">(lexer.lex(query));
|
|
37
|
-
|
|
38
|
-
expect(statements.length).toBe(1);
|
|
39
|
-
const stmt = statements[0] as SelectStatement;
|
|
40
|
-
expect(stmt.type).toBe("SELECT");
|
|
41
|
-
expect(stmt.table).toBe("documents");
|
|
42
|
-
expect(stmt.joins?.length).toBe(1);
|
|
43
|
-
|
|
44
|
-
expect(stmt.joins![0]).toEqual({
|
|
45
|
-
type: "JOIN",
|
|
46
|
-
table: "fields",
|
|
47
|
-
alias: undefined,
|
|
48
|
-
on: {
|
|
49
|
-
leftTable: "documents",
|
|
50
|
-
leftColumn: "id",
|
|
51
|
-
operator: "=",
|
|
52
|
-
rightTable: "fields",
|
|
53
|
-
rightColumn: "document_id",
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("Should parse SELECT with multiple JOINs and WHERE clause", () => {
|
|
59
|
-
const query = `
|
|
60
|
-
SELECT * FROM documents
|
|
61
|
-
JOIN fields ON documents.id = fields.document_id
|
|
62
|
-
JOIN containers ON documents.id = containers.document_id
|
|
63
|
-
JOIN components ON documents.id = components.document_id
|
|
64
|
-
LEFT JOIN medias ON documents.id = medias.document_id
|
|
65
|
-
WHERE documents.id = 'root';
|
|
66
|
-
`;
|
|
67
|
-
const statements = parser.parse<"SELECT">(lexer.lex(query));
|
|
68
|
-
|
|
69
|
-
expect(statements.length).toBe(1);
|
|
70
|
-
const stmt = statements[0] as SelectStatement;
|
|
71
|
-
expect(stmt.table).toBe("documents");
|
|
72
|
-
expect(stmt.columns).toEqual(["*"]);
|
|
73
|
-
expect(stmt.joins?.length).toBe(4);
|
|
74
|
-
|
|
75
|
-
expect(stmt.joins![0]?.table).toBe("fields");
|
|
76
|
-
expect(stmt.joins![0]?.type).toBe("JOIN");
|
|
77
|
-
expect(stmt.joins![0]?.on?.leftColumn).toBe("id");
|
|
78
|
-
expect(stmt.joins![0]?.on?.rightColumn).toBe("document_id");
|
|
79
|
-
|
|
80
|
-
expect(stmt.joins![1]?.table).toBe("containers");
|
|
81
|
-
expect(stmt.joins![2]?.table).toBe("components");
|
|
82
|
-
|
|
83
|
-
expect(stmt.joins![3]?.table).toBe("medias");
|
|
84
|
-
expect(stmt.joins![3]?.type).toBe("LEFT");
|
|
85
|
-
expect(stmt.joins![3]?.on?.leftColumn).toBe("id");
|
|
86
|
-
expect(stmt.joins![3]?.on?.rightColumn).toBe("document_id");
|
|
87
|
-
|
|
88
|
-
expect(stmt.where?.length).toBe(1);
|
|
89
|
-
expect(stmt.where![0]).toEqual({
|
|
90
|
-
table: "documents",
|
|
91
|
-
column: "id",
|
|
92
|
-
operator: "=",
|
|
93
|
-
value: "root",
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("Should parse INSERT statement with values", () => {
|
|
98
|
-
const query = "INSERT INTO documents VALUES ('doc-1', '1.0.0', '[]', 100);";
|
|
99
|
-
const statements = parser.parse<"INSERT">(lexer.lex(query));
|
|
100
|
-
|
|
101
|
-
expect(statements.length).toBe(1);
|
|
102
|
-
const stmt = statements[0] as InsertStatement;
|
|
103
|
-
expect(stmt.type).toBe("INSERT");
|
|
104
|
-
expect(stmt.table).toBe("documents");
|
|
105
|
-
expect(stmt.values).toEqual(["doc-1", "1.0.0", "[]", 100]);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("Should parse parameterized INSERT statement", () => {
|
|
109
|
-
const query = "INSERT INTO documents (id, version, order, created_at) VALUES (?, ?, ?, ?);";
|
|
110
|
-
const params = ["doc-123", "0.0.1", ["block-1"], 1700000000];
|
|
111
|
-
const statements = parser.parse<"INSERT">(lexer.lex(query), params);
|
|
112
|
-
|
|
113
|
-
expect(statements.length).toBe(1);
|
|
114
|
-
const stmt = statements[0] as InsertStatement;
|
|
115
|
-
expect(stmt.table).toBe("documents");
|
|
116
|
-
expect(stmt.fields).toEqual(["id", "version", "order", "created_at"]);
|
|
117
|
-
expect(stmt.values).toEqual(params);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test("Should parse multiple CREATE TABLE statements including FILE and BLOB types", () => {
|
|
121
|
-
const query = `
|
|
122
|
-
CREATE TABLE documents (
|
|
123
|
-
id TEXT,
|
|
124
|
-
version TEXT,
|
|
125
|
-
order ARRAY[STRING],
|
|
126
|
-
created_at DATETIME
|
|
127
|
-
);
|
|
128
|
-
CREATE TABLE fields (
|
|
129
|
-
id TEXT,
|
|
130
|
-
document_id TEXT,
|
|
131
|
-
name TEXT,
|
|
132
|
-
props OBJECT
|
|
133
|
-
);
|
|
134
|
-
CREATE TABLE medias (
|
|
135
|
-
id TEXT,
|
|
136
|
-
document_id TEXT,
|
|
137
|
-
data FILE,
|
|
138
|
-
blob_data BLOB
|
|
139
|
-
);
|
|
140
|
-
`;
|
|
141
|
-
const statements = parser.parse<"CREATE">(lexer.lex(query));
|
|
142
|
-
|
|
143
|
-
expect(statements.length).toBe(3);
|
|
144
|
-
|
|
145
|
-
const docStmt = statements[0] as CreateStatement;
|
|
146
|
-
expect(docStmt.table).toBe("documents");
|
|
147
|
-
expect(docStmt.columns).toEqual([
|
|
148
|
-
"id:string",
|
|
149
|
-
"version:string",
|
|
150
|
-
"order:array.string",
|
|
151
|
-
"created_at:number",
|
|
152
|
-
]);
|
|
153
|
-
|
|
154
|
-
const fieldsStmt = statements[1] as CreateStatement;
|
|
155
|
-
expect(fieldsStmt.table).toBe("fields");
|
|
156
|
-
expect(fieldsStmt.columns).toEqual([
|
|
157
|
-
"id:string",
|
|
158
|
-
"document_id:string",
|
|
159
|
-
"name:string",
|
|
160
|
-
"props:object",
|
|
161
|
-
]);
|
|
162
|
-
|
|
163
|
-
const mediasStmt = statements[2] as CreateStatement;
|
|
164
|
-
expect(mediasStmt.table).toBe("medias");
|
|
165
|
-
expect(mediasStmt.columns).toEqual([
|
|
166
|
-
"id:string",
|
|
167
|
-
"document_id:string",
|
|
168
|
-
"data:file",
|
|
169
|
-
"blob_data:blob",
|
|
170
|
-
]);
|
|
171
|
-
});
|
|
172
|
-
});
|