@syncular/typegen 0.57.0 → 0.59.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.
Files changed (60) hide show
  1. package/README.md +43 -25
  2. package/dist/cli.js +8 -3
  3. package/dist/emit-dart.d.ts +4 -3
  4. package/dist/emit-dart.js +39 -88
  5. package/dist/emit-kotlin.d.ts +3 -3
  6. package/dist/emit-kotlin.js +39 -86
  7. package/dist/emit-queries-dart.d.ts +1 -1
  8. package/dist/emit-queries-dart.js +17 -26
  9. package/dist/emit-queries-kotlin.d.ts +1 -1
  10. package/dist/emit-queries-kotlin.js +15 -24
  11. package/dist/emit-queries-rust.d.ts +1 -1
  12. package/dist/emit-queries-rust.js +1 -6
  13. package/dist/emit-queries-swift.d.ts +1 -1
  14. package/dist/emit-queries-swift.js +22 -26
  15. package/dist/emit-queries.d.ts +1 -1
  16. package/dist/emit-queries.js +1 -6
  17. package/dist/emit-swift.d.ts +3 -3
  18. package/dist/emit-swift.js +41 -89
  19. package/dist/emit.d.ts +1 -1
  20. package/dist/emit.js +33 -98
  21. package/dist/errors.d.ts +6 -2
  22. package/dist/errors.js +10 -2
  23. package/dist/generate.d.ts +4 -3
  24. package/dist/generate.js +32 -49
  25. package/dist/init.js +1 -1
  26. package/dist/ir.d.ts +11 -0
  27. package/dist/ir.js +66 -47
  28. package/dist/lower.d.ts +0 -7
  29. package/dist/lower.js +0 -62
  30. package/dist/migration-lock.d.ts +32 -23
  31. package/dist/migration-lock.js +115 -92
  32. package/dist/naming.d.ts +25 -0
  33. package/dist/naming.js +92 -0
  34. package/dist/query.d.ts +54 -14
  35. package/dist/query.js +484 -462
  36. package/dist/sql.js +18 -3
  37. package/dist/syql-lowering.js +10 -1
  38. package/dist/syql-validator.js +13 -220
  39. package/package.json +3 -3
  40. package/src/cli.ts +9 -3
  41. package/src/emit-dart.ts +41 -102
  42. package/src/emit-kotlin.ts +38 -102
  43. package/src/emit-queries-dart.ts +23 -32
  44. package/src/emit-queries-kotlin.ts +20 -30
  45. package/src/emit-queries-rust.ts +7 -12
  46. package/src/emit-queries-swift.ts +26 -32
  47. package/src/emit-queries.ts +5 -11
  48. package/src/emit-swift.ts +42 -104
  49. package/src/emit.ts +33 -116
  50. package/src/errors.ts +13 -2
  51. package/src/generate.ts +74 -76
  52. package/src/init.ts +4 -1
  53. package/src/ir.ts +87 -50
  54. package/src/lower.ts +0 -53
  55. package/src/migration-lock.ts +192 -137
  56. package/src/naming.ts +154 -0
  57. package/src/query.ts +615 -504
  58. package/src/sql.ts +30 -3
  59. package/src/syql-lowering.ts +15 -1
  60. package/src/syql-validator.ts +21 -279
@@ -1,4 +1,5 @@
1
1
  import { snakeToCamel } from './naming.js';
2
+ import { syqlInput, } from './query.js';
2
3
  const DART_TYPE = {
3
4
  string: 'String',
4
5
  integer: 'int',
@@ -16,10 +17,6 @@ function pascalCase(name) {
16
17
  .map((p) => p.charAt(0).toUpperCase() + p.slice(1))
17
18
  .join('');
18
19
  }
19
- /** Language-facing field name — the pinned §12 naming map. */
20
- function camelCase(name) {
21
- return snakeToCamel(name);
22
- }
23
20
  function typeName(name) {
24
21
  return name.charAt(0).toUpperCase() + name.slice(1);
25
22
  }
@@ -65,18 +62,12 @@ function optionalParamValue(type, name) {
65
62
  return name;
66
63
  }
67
64
  }
68
- function syqlInput(query, name) {
69
- const input = query.syql?.inputs.find((candidate) => candidate.name === name);
70
- if (input === undefined)
71
- throw new Error(`unknown SYQL input ${name}`);
72
- return input;
73
- }
74
65
  function syqlDartType(type, nullable) {
75
66
  return `${DART_TYPE[type]}${nullable ? '?' : ''}`;
76
67
  }
77
68
  function syqlControlActive(query, name) {
78
69
  const input = syqlInput(query, name);
79
- const access = camelCase(input.langName);
70
+ const access = snakeToCamel(input.langName);
80
71
  if (input.kind === 'value' && input.default === false)
81
72
  return access;
82
73
  if (input.kind === 'value' && input.nullable)
@@ -93,7 +84,7 @@ function syqlBindExpr(query, bind) {
93
84
  .join(' && ');
94
85
  }
95
86
  const input = syqlInput(query, bind.input);
96
- const access = camelCase(input.langName);
87
+ const access = snakeToCamel(input.langName);
97
88
  if (bind.kind === 'limit')
98
89
  return `effective${typeName(access)}`;
99
90
  if (bind.kind === 'group-member') {
@@ -102,7 +93,7 @@ function syqlBindExpr(query, bind) {
102
93
  const member = input.members.find((candidate) => candidate.name === bind.member);
103
94
  if (member === undefined)
104
95
  throw new Error(`unknown group member ${bind.member}`);
105
- const memberAccess = `${access}.${camelCase(member.langName)}`;
96
+ const memberAccess = `${access}.${snakeToCamel(member.langName)}`;
106
97
  const value = member.nullable
107
98
  ? optionalParamValue(member.type, memberAccess)
108
99
  : paramValue(member.type, memberAccess);
@@ -128,16 +119,16 @@ function emitSyqlDartTypes(query) {
128
119
  const name = `${typeName(query.name)}${typeName(input.langName)}`;
129
120
  lines.push(`class ${name} {`);
130
121
  for (const member of input.members) {
131
- lines.push(` final ${syqlDartType(member.type, member.nullable)} ${camelCase(member.langName)};`);
122
+ lines.push(` final ${syqlDartType(member.type, member.nullable)} ${snakeToCamel(member.langName)};`);
132
123
  }
133
124
  const args = input.members
134
- .map((member) => `required this.${camelCase(member.langName)}`)
125
+ .map((member) => `required this.${snakeToCamel(member.langName)}`)
135
126
  .join(', ');
136
127
  lines.push(` const ${name}({${args}});`, '}', '');
137
128
  }
138
129
  else if (input.kind === 'sort') {
139
130
  const name = `${typeName(query.name)}${typeName(input.langName)}`;
140
- lines.push(`enum ${name} { ${input.profiles.map((profile) => camelCase(profile.langName)).join(', ')} }`, '');
131
+ lines.push(`enum ${name} { ${input.profiles.map((profile) => snakeToCamel(profile.langName)).join(', ')} }`, '');
141
132
  }
142
133
  }
143
134
  if (lines[lines.length - 1] === '')
@@ -154,7 +145,7 @@ function emitSyqlDartRunner(query) {
154
145
  lines.push(`/// Tables the ${query.name} query reads (exact invalidation set).`, `const List<String> syncular${Pascal}QueryTables = [${query.tables.map(quote).join(', ')}];`, '', `/// Run the ${query.name} revision-1 SYQL query.`);
155
146
  const args = [];
156
147
  for (const input of metadata.inputs) {
157
- const name = camelCase(input.langName);
148
+ const name = snakeToCamel(input.langName);
158
149
  if (input.kind === 'value') {
159
150
  const type = syqlDartType(input.type, input.nullable);
160
151
  if (input.required)
@@ -174,7 +165,7 @@ function emitSyqlDartRunner(query) {
174
165
  const defaultCase = input.profiles.find((profile) => profile.name === input.defaultProfile)
175
166
  ?.langName ?? input.defaultProfile;
176
167
  const type = `${typeName(query.name)}${typeName(input.langName)}`;
177
- args.push(`${type} ${name} = ${type}.${camelCase(defaultCase)}`);
168
+ args.push(`${type} ${name} = ${type}.${snakeToCamel(defaultCase)}`);
178
169
  }
179
170
  else {
180
171
  args.push(`int? ${name}`);
@@ -184,7 +175,7 @@ function emitSyqlDartRunner(query) {
184
175
  lines.push(`List<${Row}> syncular${Pascal}Query(SyncularClient client${argsClause}) {`);
185
176
  const page = metadata.inputs.find((input) => input.kind === 'limit');
186
177
  if (page?.kind === 'limit') {
187
- const name = camelCase(page.langName);
178
+ const name = snakeToCamel(page.langName);
188
179
  lines.push(` final effective${typeName(name)} = ${name} ?? ${page.defaultSize};`, ` if (effective${typeName(name)} < 1 || effective${typeName(name)} > ${page.maxSize}) {`, ` throw SyqlQueryInputException('SYQL_RUNTIME_INVALID_LIMIT', ${quote(`${query.name}: invalid limit`)});`, ' }');
189
180
  }
190
181
  if (metadata.plan.backend === 'variants') {
@@ -195,7 +186,7 @@ function emitSyqlDartRunner(query) {
195
186
  }
196
187
  const sort = metadata.inputs.find((input) => input.kind === 'sort');
197
188
  const profileCount = sort?.kind === 'sort' ? sort.profiles.length : 1;
198
- const sortIndex = sort?.kind === 'sort' ? `${camelCase(sort.langName)}.index` : '0';
189
+ const sortIndex = sort?.kind === 'sort' ? `${snakeToCamel(sort.langName)}.index` : '0';
199
190
  const index = metadata.plan.backend === 'variants'
200
191
  ? `activationMask * ${profileCount} + ${sortIndex}`
201
192
  : sortIndex;
@@ -216,25 +207,25 @@ function emitClass(query) {
216
207
  lines.push(`class ${Row} {`);
217
208
  for (const column of query.columns) {
218
209
  const opt = column.nullable ? '?' : '';
219
- lines.push(` final ${DART_TYPE[column.type]}${opt} ${camelCase(column.langName)};`);
210
+ lines.push(` final ${DART_TYPE[column.type]}${opt} ${snakeToCamel(column.langName)};`);
220
211
  }
221
212
  lines.push('');
222
213
  const ctorParams = query.columns
223
- .map((c) => `${c.nullable ? '' : 'required '}this.${camelCase(c.langName)}`)
214
+ .map((c) => `${c.nullable ? '' : 'required '}this.${snakeToCamel(c.langName)}`)
224
215
  .join(', ');
225
216
  lines.push(` const ${Row}({${ctorParams}});`);
226
217
  lines.push('');
227
218
  lines.push(` static ${Row}? fromRow(Map<String, Object?> row) {`);
228
219
  for (const column of query.columns) {
229
220
  if (!column.nullable) {
230
- const name = camelCase(column.langName);
221
+ const name = snakeToCamel(column.langName);
231
222
  lines.push(` final ${name} = ${rowAccessor(column)};`);
232
223
  lines.push(` if (${name} == null) return null;`);
233
224
  }
234
225
  }
235
226
  const args = query.columns
236
227
  .map((c) => {
237
- const name = camelCase(c.langName);
228
+ const name = snakeToCamel(c.langName);
238
229
  return c.nullable ? `${name}: ${rowAccessor(c)}` : `${name}: ${name}`;
239
230
  })
240
231
  .join(', ');
@@ -257,7 +248,7 @@ function emitRunner(query) {
257
248
  lines.push(`/// Run the ${query.name} named query (SELECT-only).`);
258
249
  const args = [];
259
250
  for (const p of query.params) {
260
- const name = camelCase(p.langName);
251
+ const name = snakeToCamel(p.langName);
261
252
  args.push(`required ${DART_TYPE[p.type]} ${name}`);
262
253
  }
263
254
  const argsClause = args.length > 0 ? `, {${args.join(', ')}}` : '';
@@ -266,7 +257,7 @@ function emitRunner(query) {
266
257
  if (query.params.length > 0) {
267
258
  const binds = query.params
268
259
  .map((p) => {
269
- const name = camelCase(p.langName);
260
+ const name = snakeToCamel(p.langName);
270
261
  return paramValue(p.type, name);
271
262
  })
272
263
  .join(', ');
@@ -1,2 +1,2 @@
1
- import type { AnalyzedQuery } from './query.js';
1
+ import { type AnalyzedQuery } from './query.js';
2
2
  export declare function emitQueriesKotlinModule(queries: readonly AnalyzedQuery[], hash: string, irVersion: number, packageName: string, objectName: string): string;
@@ -1,4 +1,5 @@
1
1
  import { snakeToCamel } from './naming.js';
2
+ import { syqlInput, } from './query.js';
2
3
  const KOTLIN_TYPE = {
3
4
  string: 'String',
4
5
  integer: 'Long',
@@ -9,10 +10,6 @@ const KOTLIN_TYPE = {
9
10
  blob_ref: 'String',
10
11
  crdt: 'ByteArray',
11
12
  };
12
- /** Language-facing field name — the pinned §12 naming map. */
13
- function camelCase(name) {
14
- return snakeToCamel(name);
15
- }
16
13
  function typeName(name) {
17
14
  return name.charAt(0).toUpperCase() + name.slice(1);
18
15
  }
@@ -66,18 +63,12 @@ function optionalParamValue(type, name) {
66
63
  return `${name}?.let { JsonValue.of(it) } ?: JsonValue.Null`;
67
64
  }
68
65
  }
69
- function syqlInput(query, name) {
70
- const input = query.syql?.inputs.find((candidate) => candidate.name === name);
71
- if (input === undefined)
72
- throw new Error(`unknown SYQL input ${name}`);
73
- return input;
74
- }
75
66
  function syqlKotlinType(type, nullable) {
76
67
  return `${KOTLIN_TYPE[type]}${nullable ? '?' : ''}`;
77
68
  }
78
69
  function syqlControlActive(query, name) {
79
70
  const input = syqlInput(query, name);
80
- const access = camelCase(input.langName);
71
+ const access = snakeToCamel(input.langName);
81
72
  if (input.kind === 'value' && input.default === false)
82
73
  return access;
83
74
  if (input.kind === 'value' && input.nullable) {
@@ -99,7 +90,7 @@ function syqlBindExpr(query, bind) {
99
90
  return `JsonValue.of(${active})`;
100
91
  }
101
92
  const input = syqlInput(query, bind.input);
102
- const access = camelCase(input.langName);
93
+ const access = snakeToCamel(input.langName);
103
94
  if (bind.kind === 'limit')
104
95
  return `JsonValue.of(effective${typeName(access)}.toDouble())`;
105
96
  if (bind.kind === 'group-member') {
@@ -108,7 +99,7 @@ function syqlBindExpr(query, bind) {
108
99
  const member = input.members.find((candidate) => candidate.name === bind.member);
109
100
  if (member === undefined)
110
101
  throw new Error(`unknown group member ${bind.member}`);
111
- const memberName = camelCase(member.langName);
102
+ const memberName = snakeToCamel(member.langName);
112
103
  const present = member.nullable
113
104
  ? optionalParamValue(member.type, `value.${memberName}`)
114
105
  : paramValue(member.type, `value.${memberName}`);
@@ -134,7 +125,7 @@ function emitSyqlKotlinTypes(query) {
134
125
  const name = `${typeName(query.name)}${typeName(input.langName)}`;
135
126
  lines.push(`data class ${name}(`);
136
127
  for (const member of input.members) {
137
- lines.push(` val ${camelCase(member.langName)}: ${syqlKotlinType(member.type, member.nullable)},`);
128
+ lines.push(` val ${snakeToCamel(member.langName)}: ${syqlKotlinType(member.type, member.nullable)},`);
138
129
  }
139
130
  lines.push(')', '');
140
131
  }
@@ -142,7 +133,7 @@ function emitSyqlKotlinTypes(query) {
142
133
  const name = `${typeName(query.name)}${typeName(input.langName)}`;
143
134
  lines.push(`enum class ${name}(val index: Int) {`);
144
135
  lines.push(`${input.profiles
145
- .map((profile, index) => ` ${camelCase(profile.langName)}(${index})`)
136
+ .map((profile, index) => ` ${snakeToCamel(profile.langName)}(${index})`)
146
137
  .join(',\n')};`);
147
138
  lines.push('}', '');
148
139
  }
@@ -160,7 +151,7 @@ function emitSyqlKotlinRunner(query) {
160
151
  lines.push(` val ${query.name}Tables = listOf(${query.tables.map(quote).join(', ')})`, '', ` /** Run the ${query.name} revision-1 SYQL query. */`);
161
152
  const args = ['client: SyncularClient'];
162
153
  for (const input of metadata.inputs) {
163
- const name = camelCase(input.langName);
154
+ const name = snakeToCamel(input.langName);
164
155
  if (input.kind === 'value') {
165
156
  const type = syqlKotlinType(input.type, input.nullable);
166
157
  if (input.required)
@@ -180,7 +171,7 @@ function emitSyqlKotlinRunner(query) {
180
171
  const defaultCase = input.profiles.find((profile) => profile.name === input.defaultProfile)
181
172
  ?.langName ?? input.defaultProfile;
182
173
  const type = `${typeName(query.name)}${typeName(input.langName)}`;
183
- args.push(`${name}: ${type} = ${type}.${camelCase(defaultCase)}`);
174
+ args.push(`${name}: ${type} = ${type}.${snakeToCamel(defaultCase)}`);
184
175
  }
185
176
  else {
186
177
  args.push(`${name}: Long? = null`);
@@ -189,7 +180,7 @@ function emitSyqlKotlinRunner(query) {
189
180
  lines.push(` fun ${query.name}(${args.join(', ')}): List<${Row}> {`);
190
181
  const page = metadata.inputs.find((input) => input.kind === 'limit');
191
182
  if (page?.kind === 'limit') {
192
- const name = camelCase(page.langName);
183
+ const name = snakeToCamel(page.langName);
193
184
  lines.push(` val effective${typeName(name)} = ${name} ?: ${page.defaultSize}L`, ` if (effective${typeName(name)} < 1L || effective${typeName(name)} > ${page.maxSize}L) {`, ` throw SyncularQueryInputException("SYQL_RUNTIME_INVALID_LIMIT", ${quote(`${query.name}: invalid limit`)})`, ' }');
194
185
  }
195
186
  if (metadata.plan.backend === 'variants') {
@@ -200,7 +191,7 @@ function emitSyqlKotlinRunner(query) {
200
191
  }
201
192
  const sort = metadata.inputs.find((input) => input.kind === 'sort');
202
193
  const profileCount = sort?.kind === 'sort' ? sort.profiles.length : 1;
203
- const sortIndex = sort?.kind === 'sort' ? `${camelCase(sort.langName)}.index` : '0';
194
+ const sortIndex = sort?.kind === 'sort' ? `${snakeToCamel(sort.langName)}.index` : '0';
204
195
  const index = metadata.plan.backend === 'variants'
205
196
  ? `activationMask * ${profileCount} + ${sortIndex}`
206
197
  : sortIndex;
@@ -221,13 +212,13 @@ function emitDataClass(query) {
221
212
  lines.push(`data class ${Row}(`);
222
213
  for (const column of query.columns) {
223
214
  const opt = column.nullable ? '?' : '';
224
- lines.push(` val ${camelCase(column.langName)}: ${KOTLIN_TYPE[column.type]}${opt},`);
215
+ lines.push(` val ${snakeToCamel(column.langName)}: ${KOTLIN_TYPE[column.type]}${opt},`);
225
216
  }
226
217
  lines.push(') {');
227
218
  lines.push(' companion object {');
228
219
  lines.push(` fun fromRow(row: JsonValue): ${Row}? {`);
229
220
  for (const column of query.columns) {
230
- const name = camelCase(column.langName);
221
+ const name = snakeToCamel(column.langName);
231
222
  const accessor = rowAccessor(column);
232
223
  if (column.nullable) {
233
224
  lines.push(` val ${name} = ${accessor}`);
@@ -236,7 +227,7 @@ function emitDataClass(query) {
236
227
  lines.push(` val ${name} = ${accessor} ?: return null`);
237
228
  }
238
229
  }
239
- const args = query.columns.map((c) => camelCase(c.langName)).join(', ');
230
+ const args = query.columns.map((c) => snakeToCamel(c.langName)).join(', ');
240
231
  lines.push(` return ${Row}(${args})`);
241
232
  lines.push(' }');
242
233
  lines.push(' }');
@@ -254,7 +245,7 @@ function emitRunner(query) {
254
245
  lines.push(` /** Run the ${query.name} named query (SELECT-only). */`);
255
246
  const args = [];
256
247
  for (const p of query.params) {
257
- const name = camelCase(p.langName);
248
+ const name = snakeToCamel(p.langName);
258
249
  args.push(`${name}: ${KOTLIN_TYPE[p.type]}`);
259
250
  }
260
251
  const signature = args.length > 0
@@ -265,7 +256,7 @@ function emitRunner(query) {
265
256
  if (query.params.length > 0) {
266
257
  const binds = query.params
267
258
  .map((p) => {
268
- const name = camelCase(p.langName);
259
+ const name = snakeToCamel(p.langName);
269
260
  return paramValue(p.type, name);
270
261
  })
271
262
  .join(', ');
@@ -1,2 +1,2 @@
1
- import type { AnalyzedQuery } from './query.js';
1
+ import { type AnalyzedQuery } from './query.js';
2
2
  export declare function emitQueriesRustModule(queries: readonly AnalyzedQuery[], hash: string, irVersion: number, clientCrate?: string): string;
@@ -1,4 +1,5 @@
1
1
  import { buildRustNamingMap, rustPascalCase, rustSnakeCase } from './naming.js';
2
+ import { syqlInput, } from './query.js';
2
3
  const RUST_TYPE = {
3
4
  string: 'String',
4
5
  integer: 'i64',
@@ -43,12 +44,6 @@ function rustType(type, nullable = false) {
43
44
  const base = RUST_TYPE[type];
44
45
  return nullable ? `Option<${base}>` : base;
45
46
  }
46
- function syqlInput(query, name) {
47
- const input = query.syql?.inputs.find((candidate) => candidate.name === name);
48
- if (input === undefined)
49
- throw new Error(`unknown SYQL input ${name}`);
50
- return input;
51
- }
52
47
  function validateQueryNames(query) {
53
48
  buildRustNamingMap([query.name], query.file, 'query module');
54
49
  buildRustNamingMap(query.columns.map((column) => column.langName), query.file, `query ${query.name} projection`);
@@ -1,2 +1,2 @@
1
- import type { AnalyzedQuery } from './query.js';
1
+ import { type AnalyzedQuery } from './query.js';
2
2
  export declare function emitQueriesSwiftModule(queries: readonly AnalyzedQuery[], hash: string, irVersion: number, enumName: string): string;
@@ -1,4 +1,5 @@
1
1
  import { snakeToCamel } from './naming.js';
2
+ import { syqlInput, } from './query.js';
2
3
  const SWIFT_TYPE = {
3
4
  string: 'String',
4
5
  integer: 'Int',
@@ -13,10 +14,6 @@ const SYQL_SWIFT_TYPE = {
13
14
  ...SWIFT_TYPE,
14
15
  integer: 'Int64',
15
16
  };
16
- /** Language-facing field name — the pinned §12 naming map. */
17
- function camelCase(name) {
18
- return snakeToCamel(name);
19
- }
20
17
  /** The query function/type name: already camelCase; PascalCase for the type. */
21
18
  function typeName(name) {
22
19
  return name.charAt(0).toUpperCase() + name.slice(1);
@@ -73,22 +70,16 @@ function optionalParamValue(type, name) {
73
70
  return `${name}.map { JSONValue.string($0) } ?? .null`;
74
71
  }
75
72
  }
76
- function syqlInput(query, name) {
77
- const input = query.syql?.inputs.find((candidate) => candidate.name === name);
78
- if (input === undefined)
79
- throw new Error(`unknown SYQL input ${name}`);
80
- return input;
81
- }
82
73
  function syqlSwiftType(type, nullable) {
83
74
  return `${SYQL_SWIFT_TYPE[type]}${nullable ? '?' : ''}`;
84
75
  }
85
76
  function syqlControlActive(query, name) {
86
77
  const input = syqlInput(query, name);
87
- const access = camelCase(input.langName);
78
+ const access = snakeToCamel(input.langName);
88
79
  if (input.kind === 'value' && input.default === false)
89
80
  return access;
90
81
  if (input.kind === 'value' && input.nullable) {
91
- return `{ if case .present = ${access} { return true }; return false }()`;
82
+ return `${access}.isPresent`;
92
83
  }
93
84
  if (input.kind === 'value' || input.kind === 'group') {
94
85
  return `${access} != nil`;
@@ -106,7 +97,7 @@ function syqlBindExpr(query, bind) {
106
97
  return `.bool(${active})`;
107
98
  }
108
99
  const input = syqlInput(query, bind.input);
109
- const access = camelCase(input.langName);
100
+ const access = snakeToCamel(input.langName);
110
101
  if (bind.kind === 'limit')
111
102
  return `.number(Double(effective${typeName(access)}))`;
112
103
  if (bind.kind === 'group-member') {
@@ -115,7 +106,7 @@ function syqlBindExpr(query, bind) {
115
106
  const member = input.members.find((candidate) => candidate.name === bind.member);
116
107
  if (member === undefined)
117
108
  throw new Error(`unknown group member ${bind.member}`);
118
- const memberName = camelCase(member.langName);
109
+ const memberName = snakeToCamel(member.langName);
119
110
  const present = member.nullable
120
111
  ? optionalParamValue(member.type, `value.${memberName}`)
121
112
  : paramValue(member.type, `value.${memberName}`);
@@ -141,14 +132,14 @@ function emitSyqlSwiftTypes(query) {
141
132
  const name = `${typeName(query.name)}${typeName(input.langName)}`;
142
133
  lines.push(`public struct ${name}: Sendable {`);
143
134
  for (const member of input.members) {
144
- lines.push(` public let ${camelCase(member.langName)}: ${syqlSwiftType(member.type, member.nullable)}`);
135
+ lines.push(` public let ${snakeToCamel(member.langName)}: ${syqlSwiftType(member.type, member.nullable)}`);
145
136
  }
146
137
  const args = input.members
147
- .map((member) => `${camelCase(member.langName)}: ${syqlSwiftType(member.type, member.nullable)}`)
138
+ .map((member) => `${snakeToCamel(member.langName)}: ${syqlSwiftType(member.type, member.nullable)}`)
148
139
  .join(', ');
149
140
  lines.push(` public init(${args}) {`);
150
141
  for (const member of input.members) {
151
- const name = camelCase(member.langName);
142
+ const name = snakeToCamel(member.langName);
152
143
  lines.push(` self.${name} = ${name}`);
153
144
  }
154
145
  lines.push(' }', '}', '');
@@ -157,7 +148,7 @@ function emitSyqlSwiftTypes(query) {
157
148
  const name = `${typeName(query.name)}${typeName(input.langName)}`;
158
149
  lines.push(`public enum ${name}: Int, Sendable {`);
159
150
  input.profiles.forEach((profile, index) => {
160
- lines.push(` case ${camelCase(profile.langName)} = ${index}`);
151
+ lines.push(` case ${snakeToCamel(profile.langName)} = ${index}`);
161
152
  });
162
153
  lines.push('}', '');
163
154
  }
@@ -175,7 +166,7 @@ function emitSyqlSwiftRunner(query) {
175
166
  lines.push(` public static let ${query.name}Tables = [${query.tables.map(quote).join(', ')}]`, '', ` /// Run the ${query.name} revision-1 SYQL query.`);
176
167
  const args = ['client: SyncularClient'];
177
168
  for (const input of metadata.inputs) {
178
- const name = camelCase(input.langName);
169
+ const name = snakeToCamel(input.langName);
179
170
  if (input.kind === 'value') {
180
171
  const type = syqlSwiftType(input.type, input.nullable);
181
172
  if (input.required)
@@ -193,7 +184,7 @@ function emitSyqlSwiftRunner(query) {
193
184
  else if (input.kind === 'sort') {
194
185
  const defaultCase = input.profiles.find((profile) => profile.name === input.defaultProfile)
195
186
  ?.langName ?? input.defaultProfile;
196
- args.push(`${name}: ${typeName(query.name)}${typeName(input.langName)} = .${camelCase(defaultCase)}`);
187
+ args.push(`${name}: ${typeName(query.name)}${typeName(input.langName)} = .${snakeToCamel(defaultCase)}`);
197
188
  }
198
189
  else {
199
190
  args.push(`${name}: Int? = nil`);
@@ -202,7 +193,7 @@ function emitSyqlSwiftRunner(query) {
202
193
  lines.push(` public static func ${query.name}(${args.join(', ')}) throws -> [${Row}] {`);
203
194
  const page = metadata.inputs.find((input) => input.kind === 'limit');
204
195
  if (page?.kind === 'limit') {
205
- const name = camelCase(page.langName);
196
+ const name = snakeToCamel(page.langName);
206
197
  lines.push(` let effective${typeName(name)} = ${name} ?? ${page.defaultSize}`, ` guard effective${typeName(name)} >= 1 && effective${typeName(name)} <= ${page.maxSize} else {`, ` throw SyncularQueryInputError(code: "SYQL_RUNTIME_INVALID_LIMIT", message: ${quote(`${query.name}: invalid limit`)})`, ' }');
207
198
  }
208
199
  if (metadata.plan.backend === 'variants') {
@@ -213,7 +204,7 @@ function emitSyqlSwiftRunner(query) {
213
204
  }
214
205
  const sort = metadata.inputs.find((input) => input.kind === 'sort');
215
206
  const profileCount = sort?.kind === 'sort' ? sort.profiles.length : 1;
216
- const sortIndex = sort?.kind === 'sort' ? `${camelCase(sort.langName)}.rawValue` : '0';
207
+ const sortIndex = sort?.kind === 'sort' ? `${snakeToCamel(sort.langName)}.rawValue` : '0';
217
208
  const index = metadata.plan.backend === 'variants'
218
209
  ? `activationMask * ${profileCount} + ${sortIndex}`
219
210
  : sortIndex;
@@ -234,12 +225,12 @@ function emitRowStruct(query) {
234
225
  lines.push(`public struct ${Row}: Sendable, Equatable {`);
235
226
  for (const column of query.columns) {
236
227
  const opt = column.nullable ? '?' : '';
237
- lines.push(` public let ${camelCase(column.langName)}: ${SWIFT_TYPE[column.type]}${opt}`);
228
+ lines.push(` public let ${snakeToCamel(column.langName)}: ${SWIFT_TYPE[column.type]}${opt}`);
238
229
  }
239
230
  lines.push('');
240
231
  lines.push(' public init?(row: [String: JSONValue]) {');
241
232
  for (const column of query.columns) {
242
- const name = camelCase(column.langName);
233
+ const name = snakeToCamel(column.langName);
243
234
  const accessor = rowAccessor(column);
244
235
  if (column.nullable) {
245
236
  lines.push(` self.${name} = ${accessor}`);
@@ -264,7 +255,7 @@ function emitRunner(query) {
264
255
  lines.push(` /// Run the ${query.name} named query (SELECT-only).`);
265
256
  const args = [];
266
257
  for (const p of query.params) {
267
- const name = camelCase(p.langName);
258
+ const name = snakeToCamel(p.langName);
268
259
  args.push(`${name}: ${SWIFT_TYPE[p.type]}`);
269
260
  }
270
261
  const signature = args.length > 0
@@ -275,7 +266,7 @@ function emitRunner(query) {
275
266
  if (query.params.length > 0) {
276
267
  const binds = query.params
277
268
  .map((p) => {
278
- const name = camelCase(p.langName);
269
+ const name = snakeToCamel(p.langName);
279
270
  return paramValue(p.type, name);
280
271
  })
281
272
  .join(', ');
@@ -306,6 +297,11 @@ export function emitQueriesSwiftModule(queries, hash, irVersion, enumName) {
306
297
  'public enum SyncularQueryPresence<Value: Sendable>: Sendable {',
307
298
  ' case absent',
308
299
  ' case present(Value)',
300
+ '',
301
+ ' public var isPresent: Bool {',
302
+ ' if case .present = self { return true }',
303
+ ' return false',
304
+ ' }',
309
305
  '}',
310
306
  '',
311
307
  'public struct SyncularQueryInputError: Error, Sendable {',
@@ -1,2 +1,2 @@
1
- import type { AnalyzedQuery } from './query.js';
1
+ import { type AnalyzedQuery } from './query.js';
2
2
  export declare function emitQueriesModule(queries: readonly AnalyzedQuery[], hash: string, irVersion: number): string;
@@ -1,3 +1,4 @@
1
+ import { syqlInput, } from './query.js';
1
2
  const TS_TYPE = {
2
3
  string: 'string',
3
4
  integer: 'number',
@@ -61,12 +62,6 @@ function reactiveParam(query, name) {
61
62
  throw new Error(`unknown reactive param ${name}`);
62
63
  return `String(params.${propertyKey(param.langName)})`;
63
64
  }
64
- function syqlInput(query, name) {
65
- const input = query.syql?.inputs.find((candidate) => candidate.name === name);
66
- if (input === undefined)
67
- throw new Error(`unknown SYQL input ${name}`);
68
- return input;
69
- }
70
65
  function syqlTsValueType(type, nullable) {
71
66
  return `${SYQL_PARAM_TS_TYPE[type]}${nullable ? ' | null' : ''}`;
72
67
  }
@@ -2,8 +2,8 @@
2
2
  * Swift emitter: neutral IR → one standalone `.swift` file exporting
3
3
  *
4
4
  * - `enum <EnumName> { static let schema: JSONValue }` — the ServerSchema
5
- * object, built from the IR with byte-stable ordering (fed straight into
6
- * `SyncularClient(schema:)`),
5
+ * object: the exact `serializeSchema` JSON the TS module embeds, parsed
6
+ * from a string literal (fed straight into `SyncularClient(schema:)`),
7
7
  * - one `struct` per table with typed properties (per the six §2.4 column
8
8
  * types, plus blob_ref/crdt in their honest Swift shapes) and a
9
9
  * `init?(row:)` from a `[String: JSONValue]` (the shape `query`/`readRows`
@@ -14,5 +14,5 @@
14
14
  * IR hash so `--check` verifies freshness byte-exactly, exactly like the TS
15
15
  * emitter.
16
16
  */
17
- import type { IrDocument } from './ir.js';
17
+ import { type IrDocument } from './ir.js';
18
18
  export declare function emitSwiftModule(ir: IrDocument, hash: string, enumName: string): string;