@barishnamazov/gsql 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts ADDED
@@ -0,0 +1,165 @@
1
+ /**
2
+ * AST Type Definitions for GSQL
3
+ *
4
+ * These types define the structure of the Abstract Syntax Tree
5
+ * produced by the parser.
6
+ */
7
+
8
+ // ============================================================================
9
+ // Core Position Types
10
+ // ============================================================================
11
+
12
+ export interface Position {
13
+ line: number;
14
+ column: number;
15
+ offset: number;
16
+ }
17
+
18
+ export interface SourceLocation {
19
+ start: Position;
20
+ end: Position;
21
+ }
22
+
23
+ // ============================================================================
24
+ // Base Node Type
25
+ // ============================================================================
26
+
27
+ interface BaseNode {
28
+ location?: SourceLocation;
29
+ }
30
+
31
+ // ============================================================================
32
+ // Top-Level Declarations
33
+ // ============================================================================
34
+
35
+ export type TopLevelDeclaration =
36
+ | ExtensionDecl
37
+ | FunctionDecl
38
+ | SchemaDecl
39
+ | ConceptDecl
40
+ | EnumDecl
41
+ | Instantiation
42
+ | PerInstanceIndex;
43
+
44
+ export interface GSQLProgram extends BaseNode {
45
+ type: "Program";
46
+ declarations: TopLevelDeclaration[];
47
+ }
48
+
49
+ export interface ExtensionDecl extends BaseNode {
50
+ type: "ExtensionDecl";
51
+ name: string;
52
+ }
53
+
54
+ export interface FunctionDecl extends BaseNode {
55
+ type: "FunctionDecl";
56
+ name: string;
57
+ returnType: string;
58
+ body: string;
59
+ }
60
+
61
+ export interface EnumDecl extends BaseNode {
62
+ type: "EnumDecl";
63
+ name: string;
64
+ values: string[];
65
+ conceptScope?: string;
66
+ }
67
+
68
+ export interface SchemaDecl extends BaseNode {
69
+ type: "SchemaDecl";
70
+ name: string;
71
+ mixins: string[];
72
+ members: SchemaBodyItem[];
73
+ conceptScope?: string;
74
+ }
75
+
76
+ export interface ConceptDecl extends BaseNode {
77
+ type: "ConceptDecl";
78
+ name: string;
79
+ typeParams: string[];
80
+ members: (SchemaDecl | EnumDecl)[];
81
+ }
82
+
83
+ export interface Instantiation extends BaseNode {
84
+ type: "Instantiation";
85
+ targets: InstantiationTarget[];
86
+ conceptName: string;
87
+ typeArgs: TypeArg[];
88
+ }
89
+
90
+ export interface InstantiationTarget {
91
+ tableName: string;
92
+ alias?: string;
93
+ }
94
+
95
+ export interface TypeArg {
96
+ tableName: string;
97
+ alias?: string;
98
+ }
99
+
100
+ export interface PerInstanceIndex extends BaseNode {
101
+ type: "PerInstanceIndex";
102
+ tableName: string;
103
+ columns: string[];
104
+ unique?: boolean;
105
+ using?: string;
106
+ }
107
+
108
+ // ============================================================================
109
+ // Schema Body Items
110
+ // ============================================================================
111
+
112
+ export type SchemaBodyItem = ColumnDef | IndexDef | CheckDef | TriggerDef;
113
+
114
+ export interface ColumnDef extends BaseNode {
115
+ type: "ColumnDef";
116
+ name: string;
117
+ dataType: string;
118
+ constraints: ColumnConstraint[];
119
+ }
120
+
121
+ export interface ColumnConstraint {
122
+ type: "PrimaryKey" | "NotNull" | "Unique" | "Default" | "Reference" | "Check" | "OnDelete";
123
+ value?: string;
124
+ table?: string;
125
+ column?: string;
126
+ action?: string;
127
+ }
128
+
129
+ export interface IndexDef extends BaseNode {
130
+ type: "IndexDef";
131
+ columns: string[];
132
+ unique?: boolean;
133
+ using?: string;
134
+ }
135
+
136
+ export interface CheckDef extends BaseNode {
137
+ type: "CheckDef";
138
+ expression: string;
139
+ }
140
+
141
+ export interface TriggerDef extends BaseNode {
142
+ type: "TriggerDef";
143
+ name: string;
144
+ timing: "before" | "after";
145
+ event: string;
146
+ forEach: "row" | "statement";
147
+ executeFunction: string;
148
+ }
149
+
150
+ // ============================================================================
151
+ // Compiler Types
152
+ // ============================================================================
153
+
154
+ export interface CompileError {
155
+ message: string;
156
+ location?: SourceLocation;
157
+ severity: "error" | "warning";
158
+ }
159
+
160
+ export interface CompileResult {
161
+ success: boolean;
162
+ sql?: string;
163
+ errors: CompileError[];
164
+ ast?: GSQLProgram;
165
+ }