@syncular/typegen 0.58.0 → 0.60.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 +96 -43
- package/dist/cli.js +8 -3
- package/dist/emit-dart.d.ts +4 -3
- package/dist/emit-dart.js +40 -100
- package/dist/emit-kotlin.d.ts +4 -4
- package/dist/emit-kotlin.js +41 -99
- package/dist/emit-queries-dart.d.ts +1 -1
- package/dist/emit-queries-dart.js +17 -26
- package/dist/emit-queries-kotlin.d.ts +1 -1
- package/dist/emit-queries-kotlin.js +15 -24
- package/dist/emit-queries-rust.d.ts +1 -1
- package/dist/emit-queries-rust.js +18 -19
- package/dist/emit-queries-swift.d.ts +1 -1
- package/dist/emit-queries-swift.js +22 -26
- package/dist/emit-queries.d.ts +1 -1
- package/dist/emit-queries.js +18 -27
- package/dist/emit-swift.d.ts +4 -4
- package/dist/emit-swift.js +43 -102
- package/dist/emit.d.ts +3 -3
- package/dist/emit.js +37 -113
- package/dist/errors.d.ts +6 -2
- package/dist/errors.js +10 -2
- package/dist/fmt.js +11 -2
- package/dist/generate.d.ts +4 -3
- package/dist/generate.js +61 -73
- package/dist/init.js +5 -6
- package/dist/ir.d.ts +14 -2
- package/dist/ir.js +67 -49
- package/dist/lower.d.ts +0 -7
- package/dist/lower.js +0 -62
- package/dist/lsp.js +6 -1
- package/dist/manifest.d.ts +1 -2
- package/dist/manifest.js +13 -12
- package/dist/migration-lock.d.ts +32 -23
- package/dist/migration-lock.js +115 -92
- package/dist/naming.d.ts +25 -0
- package/dist/naming.js +92 -0
- package/dist/query.d.ts +94 -14
- package/dist/query.js +642 -461
- package/dist/sql.js +18 -3
- package/dist/syql-ast.d.ts +2 -0
- package/dist/syql-ast.js +7 -1
- package/dist/syql-browser.js +7 -6
- package/dist/syql-diagnostics.d.ts +1 -0
- package/dist/syql-diagnostics.js +1 -0
- package/dist/syql-lowering.js +11 -1
- package/dist/syql-parser.d.ts +4 -1
- package/dist/syql-parser.js +42 -5
- package/dist/syql-validator.js +13 -220
- package/package.json +3 -3
- package/src/cli.ts +9 -3
- package/src/emit-dart.ts +44 -116
- package/src/emit-kotlin.ts +41 -118
- package/src/emit-queries-dart.ts +23 -32
- package/src/emit-queries-kotlin.ts +20 -30
- package/src/emit-queries-rust.ts +29 -31
- package/src/emit-queries-swift.ts +26 -32
- package/src/emit-queries.ts +26 -47
- package/src/emit-swift.ts +49 -120
- package/src/emit.ts +45 -135
- package/src/errors.ts +13 -2
- package/src/fmt.ts +10 -2
- package/src/generate.ts +113 -107
- package/src/init.ts +8 -6
- package/src/ir.ts +91 -54
- package/src/lower.ts +0 -53
- package/src/lsp.ts +11 -4
- package/src/manifest.ts +22 -18
- package/src/migration-lock.ts +192 -137
- package/src/naming.ts +154 -0
- package/src/query.ts +864 -502
- package/src/sql.ts +30 -3
- package/src/syql-ast.ts +9 -0
- package/src/syql-browser.ts +8 -7
- package/src/syql-diagnostics.ts +2 -0
- package/src/syql-lowering.ts +16 -1
- package/src/syql-parser.ts +73 -8
- package/src/syql-validator.ts +21 -279
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { IrColumnType } from './ir';
|
|
15
15
|
import { snakeToCamel } from './naming';
|
|
16
|
-
import
|
|
17
|
-
AnalyzedQuery,
|
|
18
|
-
QueryColumn,
|
|
19
|
-
QuerySyqlPlanBind,
|
|
20
|
-
|
|
16
|
+
import {
|
|
17
|
+
type AnalyzedQuery,
|
|
18
|
+
type QueryColumn,
|
|
19
|
+
type QuerySyqlPlanBind,
|
|
20
|
+
syqlInput,
|
|
21
21
|
} from './query';
|
|
22
22
|
|
|
23
23
|
const KOTLIN_TYPE: Readonly<Record<IrColumnType, string>> = {
|
|
@@ -31,11 +31,6 @@ const KOTLIN_TYPE: Readonly<Record<IrColumnType, string>> = {
|
|
|
31
31
|
crdt: 'ByteArray',
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
/** Language-facing field name — the pinned §12 naming map. */
|
|
35
|
-
function camelCase(name: string): string {
|
|
36
|
-
return snakeToCamel(name);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
34
|
function typeName(name: string): string {
|
|
40
35
|
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
41
36
|
}
|
|
@@ -94,19 +89,13 @@ function optionalParamValue(type: IrColumnType, name: string): string {
|
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
91
|
|
|
97
|
-
function syqlInput(query: AnalyzedQuery, name: string): QuerySyqlPublicInput {
|
|
98
|
-
const input = query.syql?.inputs.find((candidate) => candidate.name === name);
|
|
99
|
-
if (input === undefined) throw new Error(`unknown SYQL input ${name}`);
|
|
100
|
-
return input;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
92
|
function syqlKotlinType(type: IrColumnType, nullable: boolean): string {
|
|
104
93
|
return `${KOTLIN_TYPE[type]}${nullable ? '?' : ''}`;
|
|
105
94
|
}
|
|
106
95
|
|
|
107
96
|
function syqlControlActive(query: AnalyzedQuery, name: string): string {
|
|
108
97
|
const input = syqlInput(query, name);
|
|
109
|
-
const access =
|
|
98
|
+
const access = snakeToCamel(input.langName);
|
|
110
99
|
if (input.kind === 'value' && input.default === false) return access;
|
|
111
100
|
if (input.kind === 'value' && input.nullable) {
|
|
112
101
|
return `${access} is SyncularQueryPresence.Present`;
|
|
@@ -129,7 +118,7 @@ function syqlBindExpr(query: AnalyzedQuery, bind: QuerySyqlPlanBind): string {
|
|
|
129
118
|
return `JsonValue.of(${active})`;
|
|
130
119
|
}
|
|
131
120
|
const input = syqlInput(query, bind.input);
|
|
132
|
-
const access =
|
|
121
|
+
const access = snakeToCamel(input.langName);
|
|
133
122
|
if (bind.kind === 'limit')
|
|
134
123
|
return `JsonValue.of(effective${typeName(access)}.toDouble())`;
|
|
135
124
|
if (bind.kind === 'group-member') {
|
|
@@ -139,7 +128,7 @@ function syqlBindExpr(query: AnalyzedQuery, bind: QuerySyqlPlanBind): string {
|
|
|
139
128
|
);
|
|
140
129
|
if (member === undefined)
|
|
141
130
|
throw new Error(`unknown group member ${bind.member}`);
|
|
142
|
-
const memberName =
|
|
131
|
+
const memberName = snakeToCamel(member.langName);
|
|
143
132
|
const present = member.nullable
|
|
144
133
|
? optionalParamValue(member.type, `value.${memberName}`)
|
|
145
134
|
: paramValue(member.type, `value.${memberName}`);
|
|
@@ -165,7 +154,7 @@ function emitSyqlKotlinTypes(query: AnalyzedQuery): string[] {
|
|
|
165
154
|
lines.push(`data class ${name}(`);
|
|
166
155
|
for (const member of input.members) {
|
|
167
156
|
lines.push(
|
|
168
|
-
` val ${
|
|
157
|
+
` val ${snakeToCamel(member.langName)}: ${syqlKotlinType(member.type, member.nullable)},`,
|
|
169
158
|
);
|
|
170
159
|
}
|
|
171
160
|
lines.push(')', '');
|
|
@@ -175,7 +164,8 @@ function emitSyqlKotlinTypes(query: AnalyzedQuery): string[] {
|
|
|
175
164
|
lines.push(
|
|
176
165
|
`${input.profiles
|
|
177
166
|
.map(
|
|
178
|
-
(profile, index) =>
|
|
167
|
+
(profile, index) =>
|
|
168
|
+
` ${snakeToCamel(profile.langName)}(${index})`,
|
|
179
169
|
)
|
|
180
170
|
.join(',\n')};`,
|
|
181
171
|
);
|
|
@@ -198,7 +188,7 @@ function emitSyqlKotlinRunner(query: AnalyzedQuery): string[] {
|
|
|
198
188
|
);
|
|
199
189
|
const args = ['client: SyncularClient'];
|
|
200
190
|
for (const input of metadata.inputs) {
|
|
201
|
-
const name =
|
|
191
|
+
const name = snakeToCamel(input.langName);
|
|
202
192
|
if (input.kind === 'value') {
|
|
203
193
|
const type = syqlKotlinType(input.type, input.nullable);
|
|
204
194
|
if (input.required) args.push(`${name}: ${type}`);
|
|
@@ -217,7 +207,7 @@ function emitSyqlKotlinRunner(query: AnalyzedQuery): string[] {
|
|
|
217
207
|
input.profiles.find((profile) => profile.name === input.defaultProfile)
|
|
218
208
|
?.langName ?? input.defaultProfile;
|
|
219
209
|
const type = `${typeName(query.name)}${typeName(input.langName)}`;
|
|
220
|
-
args.push(`${name}: ${type} = ${type}.${
|
|
210
|
+
args.push(`${name}: ${type} = ${type}.${snakeToCamel(defaultCase)}`);
|
|
221
211
|
} else {
|
|
222
212
|
args.push(`${name}: Long? = null`);
|
|
223
213
|
}
|
|
@@ -225,7 +215,7 @@ function emitSyqlKotlinRunner(query: AnalyzedQuery): string[] {
|
|
|
225
215
|
lines.push(` fun ${query.name}(${args.join(', ')}): List<${Row}> {`);
|
|
226
216
|
const page = metadata.inputs.find((input) => input.kind === 'limit');
|
|
227
217
|
if (page?.kind === 'limit') {
|
|
228
|
-
const name =
|
|
218
|
+
const name = snakeToCamel(page.langName);
|
|
229
219
|
lines.push(
|
|
230
220
|
` val effective${typeName(name)} = ${name} ?: ${page.defaultSize}L`,
|
|
231
221
|
` if (effective${typeName(name)} < 1L || effective${typeName(name)} > ${page.maxSize}L) {`,
|
|
@@ -244,7 +234,7 @@ function emitSyqlKotlinRunner(query: AnalyzedQuery): string[] {
|
|
|
244
234
|
const sort = metadata.inputs.find((input) => input.kind === 'sort');
|
|
245
235
|
const profileCount = sort?.kind === 'sort' ? sort.profiles.length : 1;
|
|
246
236
|
const sortIndex =
|
|
247
|
-
sort?.kind === 'sort' ? `${
|
|
237
|
+
sort?.kind === 'sort' ? `${snakeToCamel(sort.langName)}.index` : '0';
|
|
248
238
|
const index =
|
|
249
239
|
metadata.plan.backend === 'variants'
|
|
250
240
|
? `activationMask * ${profileCount} + ${sortIndex}`
|
|
@@ -278,14 +268,14 @@ function emitDataClass(query: AnalyzedQuery): string[] {
|
|
|
278
268
|
for (const column of query.columns) {
|
|
279
269
|
const opt = column.nullable ? '?' : '';
|
|
280
270
|
lines.push(
|
|
281
|
-
` val ${
|
|
271
|
+
` val ${snakeToCamel(column.langName)}: ${KOTLIN_TYPE[column.type]}${opt},`,
|
|
282
272
|
);
|
|
283
273
|
}
|
|
284
274
|
lines.push(') {');
|
|
285
275
|
lines.push(' companion object {');
|
|
286
276
|
lines.push(` fun fromRow(row: JsonValue): ${Row}? {`);
|
|
287
277
|
for (const column of query.columns) {
|
|
288
|
-
const name =
|
|
278
|
+
const name = snakeToCamel(column.langName);
|
|
289
279
|
const accessor = rowAccessor(column);
|
|
290
280
|
if (column.nullable) {
|
|
291
281
|
lines.push(` val ${name} = ${accessor}`);
|
|
@@ -293,7 +283,7 @@ function emitDataClass(query: AnalyzedQuery): string[] {
|
|
|
293
283
|
lines.push(` val ${name} = ${accessor} ?: return null`);
|
|
294
284
|
}
|
|
295
285
|
}
|
|
296
|
-
const args = query.columns.map((c) =>
|
|
286
|
+
const args = query.columns.map((c) => snakeToCamel(c.langName)).join(', ');
|
|
297
287
|
lines.push(` return ${Row}(${args})`);
|
|
298
288
|
lines.push(' }');
|
|
299
289
|
lines.push(' }');
|
|
@@ -315,7 +305,7 @@ function emitRunner(query: AnalyzedQuery): string[] {
|
|
|
315
305
|
lines.push(` /** Run the ${query.name} named query (SELECT-only). */`);
|
|
316
306
|
const args: string[] = [];
|
|
317
307
|
for (const p of query.params) {
|
|
318
|
-
const name =
|
|
308
|
+
const name = snakeToCamel(p.langName);
|
|
319
309
|
args.push(`${name}: ${KOTLIN_TYPE[p.type]}`);
|
|
320
310
|
}
|
|
321
311
|
const signature =
|
|
@@ -327,7 +317,7 @@ function emitRunner(query: AnalyzedQuery): string[] {
|
|
|
327
317
|
if (query.params.length > 0) {
|
|
328
318
|
const binds = query.params
|
|
329
319
|
.map((p) => {
|
|
330
|
-
const name =
|
|
320
|
+
const name = snakeToCamel(p.langName);
|
|
331
321
|
return paramValue(p.type, name);
|
|
332
322
|
})
|
|
333
323
|
.join(', ');
|
package/src/emit-queries-rust.ts
CHANGED
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { IrColumnType } from './ir';
|
|
8
8
|
import { buildRustNamingMap, rustPascalCase, rustSnakeCase } from './naming';
|
|
9
|
-
import
|
|
10
|
-
AnalyzedQuery,
|
|
11
|
-
QueryColumn,
|
|
12
|
-
QueryParam,
|
|
13
|
-
QuerySyqlPlanBind,
|
|
14
|
-
QuerySyqlPublicInput,
|
|
9
|
+
import {
|
|
10
|
+
type AnalyzedQuery,
|
|
11
|
+
type QueryColumn,
|
|
12
|
+
type QueryParam,
|
|
13
|
+
type QuerySyqlPlanBind,
|
|
14
|
+
type QuerySyqlPublicInput,
|
|
15
|
+
syqlInput,
|
|
16
|
+
windowBases,
|
|
15
17
|
} from './query';
|
|
16
18
|
|
|
17
19
|
const RUST_TYPE: Readonly<Record<IrColumnType, string>> = {
|
|
@@ -58,12 +60,6 @@ function rustType(type: IrColumnType, nullable = false): string {
|
|
|
58
60
|
return nullable ? `Option<${base}>` : base;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
function syqlInput(query: AnalyzedQuery, name: string): QuerySyqlPublicInput {
|
|
62
|
-
const input = query.syql?.inputs.find((candidate) => candidate.name === name);
|
|
63
|
-
if (input === undefined) throw new Error(`unknown SYQL input ${name}`);
|
|
64
|
-
return input;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
63
|
function validateQueryNames(query: AnalyzedQuery): void {
|
|
68
64
|
buildRustNamingMap([query.name], query.file, 'query module');
|
|
69
65
|
buildRustNamingMap(
|
|
@@ -531,32 +527,33 @@ function emitDependencies(query: AnalyzedQuery): string[] {
|
|
|
531
527
|
}
|
|
532
528
|
|
|
533
529
|
function emitCoverage(query: AnalyzedQuery): string[] {
|
|
534
|
-
const
|
|
535
|
-
(coverage) =>
|
|
536
|
-
coverage.units.length > 0 ||
|
|
537
|
-
coverage.fixedScopes.some((scope) => scope.params.length > 0),
|
|
538
|
-
);
|
|
530
|
+
const coverage = windowBases(query.reactive.coverage);
|
|
539
531
|
const lines = [
|
|
540
|
-
` pub fn coverage(${
|
|
532
|
+
` pub fn coverage(${coverage.length > 0 ? 'params' : '_params'}: &Params) -> Vec<WindowCoverage> {`,
|
|
541
533
|
' vec![',
|
|
542
534
|
];
|
|
543
|
-
for (const
|
|
544
|
-
const fixed =
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
});
|
|
550
|
-
const units = coverage.units
|
|
535
|
+
for (const entry of coverage) {
|
|
536
|
+
const fixed = entry.fixedScopes.map(
|
|
537
|
+
(scope) =>
|
|
538
|
+
`(${quote(scope.variable)}.to_owned(), ${reactiveParam(query, scope.param)})`,
|
|
539
|
+
);
|
|
540
|
+
const units = entry.units
|
|
551
541
|
.map((param) => reactiveParam(query, param))
|
|
552
542
|
.join(', ');
|
|
543
|
+
const fixedLine = ` fixed_scopes: UnitScopes::from([${fixed.join(', ')}]),`;
|
|
553
544
|
lines.push(
|
|
554
545
|
' WindowCoverage {',
|
|
555
546
|
' base: WindowBase {',
|
|
556
|
-
`
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
547
|
+
` variable: ${quote(entry.variable)}.to_owned(),`,
|
|
548
|
+
...(fixed.length === 0
|
|
549
|
+
? [' fixed_scopes: UnitScopes::new(),']
|
|
550
|
+
: fixedLine.length <= 100
|
|
551
|
+
? [fixedLine]
|
|
552
|
+
: [
|
|
553
|
+
' fixed_scopes: UnitScopes::from([',
|
|
554
|
+
...fixed.map((pair) => ` ${pair},`),
|
|
555
|
+
' ]),',
|
|
556
|
+
]),
|
|
560
557
|
' },',
|
|
561
558
|
` units: vec![${units}],`,
|
|
562
559
|
' },',
|
|
@@ -720,7 +717,8 @@ function emitSupport(clientCrate: string): string {
|
|
|
720
717
|
'use std::error::Error;',
|
|
721
718
|
'use std::fmt;',
|
|
722
719
|
`use ${clientCrate}::{`,
|
|
723
|
-
' CoverageSnapshot, QueryOwner, QueryRow, QueryValue, SyncClient,
|
|
720
|
+
' CoverageSnapshot, QueryOwner, QueryRow, QueryValue, SyncClient, UnitScopes, WindowBase,',
|
|
721
|
+
' WindowCoverage,',
|
|
724
722
|
'};',
|
|
725
723
|
'',
|
|
726
724
|
'#[derive(Debug, Clone, PartialEq, Eq, Default)]',
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import type { IrColumnType } from './ir';
|
|
16
16
|
import { snakeToCamel } from './naming';
|
|
17
|
-
import
|
|
18
|
-
AnalyzedQuery,
|
|
19
|
-
QueryColumn,
|
|
20
|
-
QuerySyqlPlanBind,
|
|
21
|
-
|
|
17
|
+
import {
|
|
18
|
+
type AnalyzedQuery,
|
|
19
|
+
type QueryColumn,
|
|
20
|
+
type QuerySyqlPlanBind,
|
|
21
|
+
syqlInput,
|
|
22
22
|
} from './query';
|
|
23
23
|
|
|
24
24
|
const SWIFT_TYPE: Readonly<Record<IrColumnType, string>> = {
|
|
@@ -36,11 +36,6 @@ const SYQL_SWIFT_TYPE: Readonly<Record<IrColumnType, string>> = {
|
|
|
36
36
|
integer: 'Int64',
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
/** Language-facing field name — the pinned §12 naming map. */
|
|
40
|
-
function camelCase(name: string): string {
|
|
41
|
-
return snakeToCamel(name);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
39
|
/** The query function/type name: already camelCase; PascalCase for the type. */
|
|
45
40
|
function typeName(name: string): string {
|
|
46
41
|
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
@@ -102,22 +97,16 @@ function optionalParamValue(type: IrColumnType, name: string): string {
|
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
|
|
105
|
-
function syqlInput(query: AnalyzedQuery, name: string): QuerySyqlPublicInput {
|
|
106
|
-
const input = query.syql?.inputs.find((candidate) => candidate.name === name);
|
|
107
|
-
if (input === undefined) throw new Error(`unknown SYQL input ${name}`);
|
|
108
|
-
return input;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
100
|
function syqlSwiftType(type: IrColumnType, nullable: boolean): string {
|
|
112
101
|
return `${SYQL_SWIFT_TYPE[type]}${nullable ? '?' : ''}`;
|
|
113
102
|
}
|
|
114
103
|
|
|
115
104
|
function syqlControlActive(query: AnalyzedQuery, name: string): string {
|
|
116
105
|
const input = syqlInput(query, name);
|
|
117
|
-
const access =
|
|
106
|
+
const access = snakeToCamel(input.langName);
|
|
118
107
|
if (input.kind === 'value' && input.default === false) return access;
|
|
119
108
|
if (input.kind === 'value' && input.nullable) {
|
|
120
|
-
return
|
|
109
|
+
return `${access}.isPresent`;
|
|
121
110
|
}
|
|
122
111
|
if (input.kind === 'value' || input.kind === 'group') {
|
|
123
112
|
return `${access} != nil`;
|
|
@@ -137,7 +126,7 @@ function syqlBindExpr(query: AnalyzedQuery, bind: QuerySyqlPlanBind): string {
|
|
|
137
126
|
return `.bool(${active})`;
|
|
138
127
|
}
|
|
139
128
|
const input = syqlInput(query, bind.input);
|
|
140
|
-
const access =
|
|
129
|
+
const access = snakeToCamel(input.langName);
|
|
141
130
|
if (bind.kind === 'limit')
|
|
142
131
|
return `.number(Double(effective${typeName(access)}))`;
|
|
143
132
|
if (bind.kind === 'group-member') {
|
|
@@ -147,7 +136,7 @@ function syqlBindExpr(query: AnalyzedQuery, bind: QuerySyqlPlanBind): string {
|
|
|
147
136
|
);
|
|
148
137
|
if (member === undefined)
|
|
149
138
|
throw new Error(`unknown group member ${bind.member}`);
|
|
150
|
-
const memberName =
|
|
139
|
+
const memberName = snakeToCamel(member.langName);
|
|
151
140
|
const present = member.nullable
|
|
152
141
|
? optionalParamValue(member.type, `value.${memberName}`)
|
|
153
142
|
: paramValue(member.type, `value.${memberName}`);
|
|
@@ -173,18 +162,18 @@ function emitSyqlSwiftTypes(query: AnalyzedQuery): string[] {
|
|
|
173
162
|
lines.push(`public struct ${name}: Sendable {`);
|
|
174
163
|
for (const member of input.members) {
|
|
175
164
|
lines.push(
|
|
176
|
-
` public let ${
|
|
165
|
+
` public let ${snakeToCamel(member.langName)}: ${syqlSwiftType(member.type, member.nullable)}`,
|
|
177
166
|
);
|
|
178
167
|
}
|
|
179
168
|
const args = input.members
|
|
180
169
|
.map(
|
|
181
170
|
(member) =>
|
|
182
|
-
`${
|
|
171
|
+
`${snakeToCamel(member.langName)}: ${syqlSwiftType(member.type, member.nullable)}`,
|
|
183
172
|
)
|
|
184
173
|
.join(', ');
|
|
185
174
|
lines.push(` public init(${args}) {`);
|
|
186
175
|
for (const member of input.members) {
|
|
187
|
-
const name =
|
|
176
|
+
const name = snakeToCamel(member.langName);
|
|
188
177
|
lines.push(` self.${name} = ${name}`);
|
|
189
178
|
}
|
|
190
179
|
lines.push(' }', '}', '');
|
|
@@ -192,7 +181,7 @@ function emitSyqlSwiftTypes(query: AnalyzedQuery): string[] {
|
|
|
192
181
|
const name = `${typeName(query.name)}${typeName(input.langName)}`;
|
|
193
182
|
lines.push(`public enum ${name}: Int, Sendable {`);
|
|
194
183
|
input.profiles.forEach((profile, index) => {
|
|
195
|
-
lines.push(` case ${
|
|
184
|
+
lines.push(` case ${snakeToCamel(profile.langName)} = ${index}`);
|
|
196
185
|
});
|
|
197
186
|
lines.push('}', '');
|
|
198
187
|
}
|
|
@@ -213,7 +202,7 @@ function emitSyqlSwiftRunner(query: AnalyzedQuery): string[] {
|
|
|
213
202
|
);
|
|
214
203
|
const args = ['client: SyncularClient'];
|
|
215
204
|
for (const input of metadata.inputs) {
|
|
216
|
-
const name =
|
|
205
|
+
const name = snakeToCamel(input.langName);
|
|
217
206
|
if (input.kind === 'value') {
|
|
218
207
|
const type = syqlSwiftType(input.type, input.nullable);
|
|
219
208
|
if (input.required) args.push(`${name}: ${type}`);
|
|
@@ -230,7 +219,7 @@ function emitSyqlSwiftRunner(query: AnalyzedQuery): string[] {
|
|
|
230
219
|
input.profiles.find((profile) => profile.name === input.defaultProfile)
|
|
231
220
|
?.langName ?? input.defaultProfile;
|
|
232
221
|
args.push(
|
|
233
|
-
`${name}: ${typeName(query.name)}${typeName(input.langName)} = .${
|
|
222
|
+
`${name}: ${typeName(query.name)}${typeName(input.langName)} = .${snakeToCamel(defaultCase)}`,
|
|
234
223
|
);
|
|
235
224
|
} else {
|
|
236
225
|
args.push(`${name}: Int? = nil`);
|
|
@@ -241,7 +230,7 @@ function emitSyqlSwiftRunner(query: AnalyzedQuery): string[] {
|
|
|
241
230
|
);
|
|
242
231
|
const page = metadata.inputs.find((input) => input.kind === 'limit');
|
|
243
232
|
if (page?.kind === 'limit') {
|
|
244
|
-
const name =
|
|
233
|
+
const name = snakeToCamel(page.langName);
|
|
245
234
|
lines.push(
|
|
246
235
|
` let effective${typeName(name)} = ${name} ?? ${page.defaultSize}`,
|
|
247
236
|
` guard effective${typeName(name)} >= 1 && effective${typeName(name)} <= ${page.maxSize} else {`,
|
|
@@ -260,7 +249,7 @@ function emitSyqlSwiftRunner(query: AnalyzedQuery): string[] {
|
|
|
260
249
|
const sort = metadata.inputs.find((input) => input.kind === 'sort');
|
|
261
250
|
const profileCount = sort?.kind === 'sort' ? sort.profiles.length : 1;
|
|
262
251
|
const sortIndex =
|
|
263
|
-
sort?.kind === 'sort' ? `${
|
|
252
|
+
sort?.kind === 'sort' ? `${snakeToCamel(sort.langName)}.rawValue` : '0';
|
|
264
253
|
const index =
|
|
265
254
|
metadata.plan.backend === 'variants'
|
|
266
255
|
? `activationMask * ${profileCount} + ${sortIndex}`
|
|
@@ -298,13 +287,13 @@ function emitRowStruct(query: AnalyzedQuery): string[] {
|
|
|
298
287
|
for (const column of query.columns) {
|
|
299
288
|
const opt = column.nullable ? '?' : '';
|
|
300
289
|
lines.push(
|
|
301
|
-
` public let ${
|
|
290
|
+
` public let ${snakeToCamel(column.langName)}: ${SWIFT_TYPE[column.type]}${opt}`,
|
|
302
291
|
);
|
|
303
292
|
}
|
|
304
293
|
lines.push('');
|
|
305
294
|
lines.push(' public init?(row: [String: JSONValue]) {');
|
|
306
295
|
for (const column of query.columns) {
|
|
307
|
-
const name =
|
|
296
|
+
const name = snakeToCamel(column.langName);
|
|
308
297
|
const accessor = rowAccessor(column);
|
|
309
298
|
if (column.nullable) {
|
|
310
299
|
lines.push(` self.${name} = ${accessor}`);
|
|
@@ -332,7 +321,7 @@ function emitRunner(query: AnalyzedQuery): string[] {
|
|
|
332
321
|
lines.push(` /// Run the ${query.name} named query (SELECT-only).`);
|
|
333
322
|
const args: string[] = [];
|
|
334
323
|
for (const p of query.params) {
|
|
335
|
-
const name =
|
|
324
|
+
const name = snakeToCamel(p.langName);
|
|
336
325
|
args.push(`${name}: ${SWIFT_TYPE[p.type]}`);
|
|
337
326
|
}
|
|
338
327
|
const signature =
|
|
@@ -346,7 +335,7 @@ function emitRunner(query: AnalyzedQuery): string[] {
|
|
|
346
335
|
if (query.params.length > 0) {
|
|
347
336
|
const binds = query.params
|
|
348
337
|
.map((p) => {
|
|
349
|
-
const name =
|
|
338
|
+
const name = snakeToCamel(p.langName);
|
|
350
339
|
return paramValue(p.type, name);
|
|
351
340
|
})
|
|
352
341
|
.join(', ');
|
|
@@ -392,6 +381,11 @@ export function emitQueriesSwiftModule(
|
|
|
392
381
|
'public enum SyncularQueryPresence<Value: Sendable>: Sendable {',
|
|
393
382
|
' case absent',
|
|
394
383
|
' case present(Value)',
|
|
384
|
+
'',
|
|
385
|
+
' public var isPresent: Bool {',
|
|
386
|
+
' if case .present = self { return true }',
|
|
387
|
+
' return false',
|
|
388
|
+
' }',
|
|
395
389
|
'}',
|
|
396
390
|
'',
|
|
397
391
|
'public struct SyncularQueryInputError: Error, Sendable {',
|
package/src/emit-queries.ts
CHANGED
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
* `--check` gates freshness byte-exactly, like every other emitter.
|
|
19
19
|
*/
|
|
20
20
|
import type { IrColumnType } from './ir';
|
|
21
|
-
import
|
|
22
|
-
AnalyzedQuery,
|
|
23
|
-
QueryParam,
|
|
24
|
-
QuerySyqlPlanBind,
|
|
25
|
-
|
|
21
|
+
import {
|
|
22
|
+
type AnalyzedQuery,
|
|
23
|
+
type QueryParam,
|
|
24
|
+
type QuerySyqlPlanBind,
|
|
25
|
+
syqlInput,
|
|
26
|
+
windowBases,
|
|
26
27
|
} from './query';
|
|
27
28
|
|
|
28
29
|
const TS_TYPE: Readonly<Record<IrColumnType, string>> = {
|
|
@@ -98,10 +99,22 @@ function reactiveParam(query: AnalyzedQuery, name: string): string {
|
|
|
98
99
|
return `String(params.${propertyKey(param.langName)})`;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return
|
|
102
|
+
/** The `coverage` member's opening line and one line per window base. */
|
|
103
|
+
function emitCoverage(query: AnalyzedQuery): string[] {
|
|
104
|
+
const coverage = windowBases(query.reactive.coverage);
|
|
105
|
+
return [
|
|
106
|
+
` coverage: (${coverage.length > 0 ? 'params' : ''}) => [`,
|
|
107
|
+
...coverage.map((entry) => {
|
|
108
|
+
const fixed = entry.fixedScopes
|
|
109
|
+
.map(
|
|
110
|
+
(scope) =>
|
|
111
|
+
`${propertyKey(scope.variable)}: ${reactiveParam(query, scope.param)}`,
|
|
112
|
+
)
|
|
113
|
+
.join(', ');
|
|
114
|
+
const fixedPart = fixed.length > 0 ? `, fixedScopes: { ${fixed} }` : '';
|
|
115
|
+
return ` { base: { variable: ${quote(entry.variable)}${fixedPart} }, units: [${entry.units.map((param) => reactiveParam(query, param)).join(', ')}] },`;
|
|
116
|
+
}),
|
|
117
|
+
];
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
function syqlTsValueType(type: IrColumnType, nullable: boolean): string {
|
|
@@ -418,23 +431,7 @@ function emitSyqlQuery(query: AnalyzedQuery, hash: string): string {
|
|
|
418
431
|
);
|
|
419
432
|
}
|
|
420
433
|
lines.push(' ],');
|
|
421
|
-
|
|
422
|
-
(coverage) =>
|
|
423
|
-
coverage.units.length > 0 ||
|
|
424
|
-
coverage.fixedScopes.some((scope) => scope.params.length > 0),
|
|
425
|
-
);
|
|
426
|
-
lines.push(` coverage: (${coverageUsesParams ? 'params' : ''}) => [`);
|
|
427
|
-
for (const coverage of query.reactive.coverage) {
|
|
428
|
-
const fixed = coverage.fixedScopes
|
|
429
|
-
.map(
|
|
430
|
-
(scope) =>
|
|
431
|
-
`${propertyKey(scope.variable)}: [${scope.params.map((param) => reactiveParam(query, param)).join(', ')}]`,
|
|
432
|
-
)
|
|
433
|
-
.join(', ');
|
|
434
|
-
lines.push(
|
|
435
|
-
` { base: { table: ${quote(coverage.table)}, variable: ${quote(coverage.variable)}${fixed.length > 0 ? `, fixedScopes: { ${fixed} }` : ''} }, units: [${coverage.units.map((param) => reactiveParam(query, param)).join(', ')}] },`,
|
|
436
|
-
);
|
|
437
|
-
}
|
|
434
|
+
lines.push(...emitCoverage(query));
|
|
438
435
|
lines.push(
|
|
439
436
|
' ],',
|
|
440
437
|
hasParams
|
|
@@ -562,24 +559,7 @@ function emitQuery(query: AnalyzedQuery, hash: string): string {
|
|
|
562
559
|
);
|
|
563
560
|
}
|
|
564
561
|
lines.push(' ],');
|
|
565
|
-
|
|
566
|
-
(coverage) =>
|
|
567
|
-
coverage.units.length > 0 ||
|
|
568
|
-
coverage.fixedScopes.some((scope) => scope.params.length > 0),
|
|
569
|
-
);
|
|
570
|
-
lines.push(` coverage: (${coverageUsesParams ? 'params' : ''}) => [`);
|
|
571
|
-
for (const coverage of query.reactive.coverage) {
|
|
572
|
-
const fixed = coverage.fixedScopes
|
|
573
|
-
.map(
|
|
574
|
-
(scope) =>
|
|
575
|
-
`${propertyKey(scope.variable)}: [${scope.params.map((param) => reactiveParam(query, param)).join(', ')}]`,
|
|
576
|
-
)
|
|
577
|
-
.join(', ');
|
|
578
|
-
const fixedPart = fixed.length > 0 ? `, fixedScopes: { ${fixed} }` : '';
|
|
579
|
-
lines.push(
|
|
580
|
-
` { base: { table: ${quote(coverage.table)}, variable: ${quote(coverage.variable)}${fixedPart} }, units: [${coverage.units.map((param) => reactiveParam(query, param)).join(', ')}] },`,
|
|
581
|
-
);
|
|
582
|
-
}
|
|
562
|
+
lines.push(...emitCoverage(query));
|
|
583
563
|
lines.push(' ],');
|
|
584
564
|
if (hasParams) {
|
|
585
565
|
lines.push(` bind: (params: ${Params}) => ${positional},`);
|
|
@@ -720,12 +700,11 @@ export function emitQueriesModule(
|
|
|
720
700
|
' readonly nullable: boolean;',
|
|
721
701
|
'}',
|
|
722
702
|
'',
|
|
703
|
+
'/** A window base (SPEC §4.8) and the unit values a query reads. */',
|
|
723
704
|
'export interface WindowCoverage {',
|
|
724
705
|
' readonly base: {',
|
|
725
|
-
' readonly table: string;',
|
|
726
706
|
' readonly variable: string;',
|
|
727
|
-
' readonly fixedScopes?: Readonly<Record<string,
|
|
728
|
-
' readonly params?: string;',
|
|
707
|
+
' readonly fixedScopes?: Readonly<Record<string, string>>;',
|
|
729
708
|
' };',
|
|
730
709
|
' readonly units: readonly string[];',
|
|
731
710
|
'}',
|