@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.
Files changed (56) hide show
  1. package/README.md +79 -32
  2. package/dist/cli.js +40 -17
  3. package/dist/emit-queries-dart.js +168 -55
  4. package/dist/emit-queries-kotlin.js +167 -55
  5. package/dist/emit-queries-swift.js +183 -57
  6. package/dist/emit-queries.js +286 -123
  7. package/dist/fmt.d.ts +2 -2
  8. package/dist/fmt.js +348 -316
  9. package/dist/generate.d.ts +1 -1
  10. package/dist/generate.js +28 -9
  11. package/dist/index.d.ts +3 -1
  12. package/dist/index.js +3 -1
  13. package/dist/lsp.d.ts +1 -3
  14. package/dist/lsp.js +349 -187
  15. package/dist/manifest.d.ts +1 -3
  16. package/dist/manifest.js +1 -1
  17. package/dist/query-ir.js +53 -42
  18. package/dist/query.d.ts +110 -63
  19. package/dist/query.js +89 -11
  20. package/dist/syql-ast.d.ts +12 -13
  21. package/dist/syql-ast.js +26 -20
  22. package/dist/syql-lexer.d.ts +2 -0
  23. package/dist/syql-lexer.js +9 -2
  24. package/dist/syql-lowering.d.ts +22 -0
  25. package/dist/syql-lowering.js +434 -0
  26. package/dist/syql-parser.d.ts +19 -18
  27. package/dist/syql-parser.js +341 -93
  28. package/dist/syql-semantics.d.ts +73 -0
  29. package/dist/syql-semantics.js +607 -0
  30. package/dist/syql-template-parser.d.ts +5 -20
  31. package/dist/syql-template-parser.js +116 -109
  32. package/dist/syql-validator.d.ts +35 -0
  33. package/dist/syql-validator.js +993 -0
  34. package/package.json +3 -3
  35. package/src/cli.ts +49 -21
  36. package/src/emit-queries-dart.ts +195 -69
  37. package/src/emit-queries-kotlin.ts +197 -69
  38. package/src/emit-queries-swift.ts +224 -68
  39. package/src/emit-queries.ts +410 -165
  40. package/src/fmt.ts +405 -303
  41. package/src/generate.ts +43 -9
  42. package/src/index.ts +3 -1
  43. package/src/lsp.ts +414 -216
  44. package/src/manifest.ts +2 -4
  45. package/src/query-ir.ts +52 -42
  46. package/src/query.ts +229 -79
  47. package/src/syql-ast.ts +38 -34
  48. package/src/syql-lexer.ts +12 -1
  49. package/src/syql-lowering.ts +664 -0
  50. package/src/syql-parser.ts +472 -134
  51. package/src/syql-semantics.ts +930 -0
  52. package/src/syql-template-parser.ts +119 -163
  53. package/src/syql-validator.ts +1486 -0
  54. package/dist/syql.d.ts +0 -102
  55. package/dist/syql.js +0 -1141
  56. 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: 'switch';
54
+ readonly kind: 'range';
62
55
  readonly name: string;
63
- readonly optional: true;
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 sql: SyqlSemanticTemplate;
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 page?: {
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 === 'switch') {
139
- return { kind: 'switch', name: parameter.name, optional: true };
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
- sql: semanticTemplate(declaration.sql.body),
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.page === undefined
255
+ ...(declaration.limit === undefined
249
256
  ? {}
250
257
  : {
251
- page: {
252
- control: declaration.page.control,
253
- defaultSize: declaration.page.defaultSize,
254
- maxSize: declaration.page.maxSize,
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
+ }