@syncular/typegen 0.5.1 → 0.7.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/README.md +79 -32
- package/dist/cli.js +40 -17
- package/dist/emit-queries-dart.js +168 -55
- package/dist/emit-queries-kotlin.js +167 -55
- package/dist/emit-queries-swift.js +183 -57
- package/dist/emit-queries.js +286 -123
- package/dist/fmt.d.ts +2 -2
- package/dist/fmt.js +348 -316
- package/dist/generate.d.ts +1 -1
- package/dist/generate.js +28 -9
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/lsp.d.ts +1 -3
- package/dist/lsp.js +349 -187
- package/dist/manifest.d.ts +1 -3
- package/dist/manifest.js +1 -1
- package/dist/query-ir.js +53 -42
- package/dist/query.d.ts +110 -63
- package/dist/query.js +89 -11
- package/dist/syql-ast.d.ts +12 -13
- package/dist/syql-ast.js +26 -20
- package/dist/syql-lexer.d.ts +2 -0
- package/dist/syql-lexer.js +9 -2
- package/dist/syql-lowering.d.ts +22 -0
- package/dist/syql-lowering.js +434 -0
- package/dist/syql-parser.d.ts +19 -18
- package/dist/syql-parser.js +341 -93
- package/dist/syql-semantics.d.ts +73 -0
- package/dist/syql-semantics.js +607 -0
- package/dist/syql-template-parser.d.ts +5 -20
- package/dist/syql-template-parser.js +116 -109
- package/dist/syql-validator.d.ts +35 -0
- package/dist/syql-validator.js +993 -0
- package/package.json +3 -3
- package/src/cli.ts +49 -21
- package/src/emit-queries-dart.ts +195 -69
- package/src/emit-queries-kotlin.ts +197 -69
- package/src/emit-queries-swift.ts +224 -68
- package/src/emit-queries.ts +410 -165
- package/src/fmt.ts +405 -303
- package/src/generate.ts +43 -9
- package/src/index.ts +3 -1
- package/src/lsp.ts +414 -216
- package/src/manifest.ts +2 -4
- package/src/query-ir.ts +52 -42
- package/src/query.ts +229 -79
- package/src/syql-ast.ts +38 -34
- package/src/syql-lexer.ts +12 -1
- package/src/syql-lowering.ts +664 -0
- package/src/syql-parser.ts +472 -134
- package/src/syql-semantics.ts +930 -0
- package/src/syql-template-parser.ts +119 -163
- package/src/syql-validator.ts +1486 -0
- package/dist/syql.d.ts +0 -102
- package/dist/syql.js +0 -1141
- package/src/syql.ts +0 -1470
package/src/syql-ast.ts
CHANGED
|
@@ -33,16 +33,8 @@ export type SyqlSemanticTemplateNode =
|
|
|
33
33
|
| {
|
|
34
34
|
readonly kind: 'when';
|
|
35
35
|
readonly controls: readonly string[];
|
|
36
|
+
readonly explicitPresence: readonly boolean[];
|
|
36
37
|
readonly body: readonly SyqlSemanticTemplateNode[];
|
|
37
|
-
}
|
|
38
|
-
| {
|
|
39
|
-
readonly kind: 'scope' | 'cover';
|
|
40
|
-
readonly bindings: readonly {
|
|
41
|
-
readonly qualifier: string;
|
|
42
|
-
readonly column: string;
|
|
43
|
-
readonly operator: 'equal' | 'in';
|
|
44
|
-
readonly values: readonly string[];
|
|
45
|
-
}[];
|
|
46
38
|
};
|
|
47
39
|
|
|
48
40
|
export interface SyqlSemanticTemplate {
|
|
@@ -56,11 +48,13 @@ export type SyqlSemanticQueryParameter =
|
|
|
56
48
|
readonly name: string;
|
|
57
49
|
readonly optional: boolean;
|
|
58
50
|
readonly type?: SyqlSemanticType;
|
|
51
|
+
readonly default?: false;
|
|
59
52
|
}
|
|
60
53
|
| {
|
|
61
|
-
readonly kind: '
|
|
54
|
+
readonly kind: 'range';
|
|
62
55
|
readonly name: string;
|
|
63
|
-
readonly optional:
|
|
56
|
+
readonly optional: boolean;
|
|
57
|
+
readonly type?: SyqlSemanticType;
|
|
64
58
|
}
|
|
65
59
|
| {
|
|
66
60
|
readonly kind: 'group';
|
|
@@ -85,8 +79,13 @@ export type SyqlSemanticDeclaration =
|
|
|
85
79
|
| {
|
|
86
80
|
readonly kind: 'query';
|
|
87
81
|
readonly name: string;
|
|
82
|
+
readonly sync: boolean;
|
|
83
|
+
readonly syncBy?: {
|
|
84
|
+
readonly qualifier: string;
|
|
85
|
+
readonly column: string;
|
|
86
|
+
};
|
|
88
87
|
readonly parameters: readonly SyqlSemanticQueryParameter[];
|
|
89
|
-
readonly
|
|
88
|
+
readonly statement: SyqlSemanticTemplate;
|
|
90
89
|
readonly sort?: {
|
|
91
90
|
readonly control: string;
|
|
92
91
|
readonly defaultProfile: string;
|
|
@@ -95,12 +94,11 @@ export type SyqlSemanticDeclaration =
|
|
|
95
94
|
readonly order: SyqlSemanticTemplate;
|
|
96
95
|
}[];
|
|
97
96
|
};
|
|
98
|
-
readonly
|
|
97
|
+
readonly limit?: {
|
|
99
98
|
readonly control: string;
|
|
100
99
|
readonly defaultSize: number;
|
|
101
100
|
readonly maxSize: number;
|
|
102
101
|
};
|
|
103
|
-
readonly identity?: readonly string[];
|
|
104
102
|
};
|
|
105
103
|
|
|
106
104
|
export interface SyqlSemanticFile {
|
|
@@ -135,8 +133,14 @@ function semanticMember(member: SyqlGroupMember): {
|
|
|
135
133
|
function semanticParameter(
|
|
136
134
|
parameter: SyqlQueryParameter,
|
|
137
135
|
): SyqlSemanticQueryParameter {
|
|
138
|
-
if (parameter.kind === '
|
|
139
|
-
|
|
136
|
+
if (parameter.kind === 'range') {
|
|
137
|
+
const type = semanticType(parameter.type);
|
|
138
|
+
return {
|
|
139
|
+
kind: 'range',
|
|
140
|
+
name: parameter.name,
|
|
141
|
+
optional: parameter.optional,
|
|
142
|
+
...(type === undefined ? {} : { type }),
|
|
143
|
+
};
|
|
140
144
|
}
|
|
141
145
|
if (parameter.kind === 'group') {
|
|
142
146
|
return {
|
|
@@ -152,6 +156,7 @@ function semanticParameter(
|
|
|
152
156
|
name: parameter.name,
|
|
153
157
|
optional: parameter.optional,
|
|
154
158
|
...(type === undefined ? {} : { type }),
|
|
159
|
+
...(parameter.default === undefined ? {} : { default: parameter.default }),
|
|
155
160
|
};
|
|
156
161
|
}
|
|
157
162
|
|
|
@@ -181,18 +186,11 @@ function semanticNode(
|
|
|
181
186
|
return {
|
|
182
187
|
kind: 'when',
|
|
183
188
|
controls: node.controls,
|
|
189
|
+
explicitPresence: node.explicitPresence,
|
|
184
190
|
body: semanticNodes(node.body.nodes),
|
|
185
191
|
};
|
|
186
192
|
}
|
|
187
|
-
return
|
|
188
|
-
kind: node.kind,
|
|
189
|
-
bindings: node.bindings.map((binding) => ({
|
|
190
|
-
qualifier: binding.column.qualifier,
|
|
191
|
-
column: binding.column.name,
|
|
192
|
-
operator: binding.operator,
|
|
193
|
-
values: binding.values.map((value) => value.name),
|
|
194
|
-
})),
|
|
195
|
-
};
|
|
193
|
+
return undefined;
|
|
196
194
|
}
|
|
197
195
|
|
|
198
196
|
function semanticNodes(
|
|
@@ -231,8 +229,17 @@ function semanticDeclaration(
|
|
|
231
229
|
return {
|
|
232
230
|
kind: 'query',
|
|
233
231
|
name: declaration.name,
|
|
232
|
+
sync: declaration.sync,
|
|
233
|
+
...(declaration.syncBy === undefined
|
|
234
|
+
? {}
|
|
235
|
+
: {
|
|
236
|
+
syncBy: {
|
|
237
|
+
qualifier: declaration.syncBy.qualifier,
|
|
238
|
+
column: declaration.syncBy.column,
|
|
239
|
+
},
|
|
240
|
+
}),
|
|
234
241
|
parameters: declaration.parameters.map(semanticParameter),
|
|
235
|
-
|
|
242
|
+
statement: semanticTemplate(declaration.statement),
|
|
236
243
|
...(declaration.sort === undefined
|
|
237
244
|
? {}
|
|
238
245
|
: {
|
|
@@ -245,18 +252,15 @@ function semanticDeclaration(
|
|
|
245
252
|
})),
|
|
246
253
|
},
|
|
247
254
|
}),
|
|
248
|
-
...(declaration.
|
|
255
|
+
...(declaration.limit === undefined
|
|
249
256
|
? {}
|
|
250
257
|
: {
|
|
251
|
-
|
|
252
|
-
control: declaration.
|
|
253
|
-
defaultSize: declaration.
|
|
254
|
-
maxSize: declaration.
|
|
258
|
+
limit: {
|
|
259
|
+
control: declaration.limit.control,
|
|
260
|
+
defaultSize: declaration.limit.defaultSize,
|
|
261
|
+
maxSize: declaration.limit.maxSize,
|
|
255
262
|
},
|
|
256
263
|
}),
|
|
257
|
-
...(declaration.identity === undefined
|
|
258
|
-
? {}
|
|
259
|
-
: { identity: declaration.identity.fields }),
|
|
260
264
|
};
|
|
261
265
|
}
|
|
262
266
|
|
package/src/syql-lexer.ts
CHANGED
|
@@ -163,10 +163,12 @@ class Lexer {
|
|
|
163
163
|
#column = 1;
|
|
164
164
|
#braceDepth = 0;
|
|
165
165
|
#expectImportPath = false;
|
|
166
|
+
readonly #recognizeImportPaths: boolean;
|
|
166
167
|
|
|
167
|
-
constructor(file: string, source: string) {
|
|
168
|
+
constructor(file: string, source: string, recognizeImportPaths = true) {
|
|
168
169
|
this.#file = file;
|
|
169
170
|
this.#source = source;
|
|
171
|
+
this.#recognizeImportPaths = recognizeImportPaths;
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
lex(): readonly SyqlToken[] {
|
|
@@ -237,6 +239,7 @@ class Lexer {
|
|
|
237
239
|
}
|
|
238
240
|
|
|
239
241
|
if (
|
|
242
|
+
this.#recognizeImportPaths &&
|
|
240
243
|
token.kind === 'identifier' &&
|
|
241
244
|
token.text === 'from' &&
|
|
242
245
|
this.#braceDepth === 0
|
|
@@ -512,3 +515,11 @@ export function lexSyqlSource(
|
|
|
512
515
|
): readonly SyqlToken[] {
|
|
513
516
|
return new Lexer(file, source).lex();
|
|
514
517
|
}
|
|
518
|
+
|
|
519
|
+
/** Lex an isolated SQL/template string without import-path contextual rules. */
|
|
520
|
+
export function lexSyqlSqlSource(
|
|
521
|
+
file: string,
|
|
522
|
+
source: string,
|
|
523
|
+
): readonly SyqlToken[] {
|
|
524
|
+
return new Lexer(file, source, false).lex();
|
|
525
|
+
}
|