@syncular/typegen 0.1.3 → 0.2.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 (99) hide show
  1. package/README.md +436 -94
  2. package/dist/cli.d.ts +1 -2
  3. package/dist/cli.js +159 -73
  4. package/dist/emit-dart.d.ts +17 -0
  5. package/dist/emit-dart.js +201 -0
  6. package/dist/emit-kotlin.d.ts +16 -0
  7. package/dist/emit-kotlin.js +201 -0
  8. package/dist/emit-queries-dart.d.ts +2 -0
  9. package/dist/emit-queries-dart.js +160 -0
  10. package/dist/emit-queries-kotlin.d.ts +2 -0
  11. package/dist/emit-queries-kotlin.js +162 -0
  12. package/dist/emit-queries-swift.d.ts +2 -0
  13. package/dist/emit-queries-swift.js +146 -0
  14. package/dist/emit-queries.d.ts +2 -0
  15. package/dist/emit-queries.js +129 -0
  16. package/dist/emit-swift.d.ts +18 -0
  17. package/dist/emit-swift.js +235 -0
  18. package/dist/emit.d.ts +16 -0
  19. package/dist/emit.js +191 -0
  20. package/dist/errors.d.ts +6 -0
  21. package/dist/errors.js +10 -0
  22. package/dist/generate.d.ts +53 -18
  23. package/dist/generate.js +391 -77
  24. package/dist/index.d.ts +17 -14
  25. package/dist/index.js +16 -13
  26. package/dist/init.d.ts +12 -0
  27. package/dist/init.js +85 -0
  28. package/dist/ir.d.ts +90 -0
  29. package/dist/ir.js +94 -0
  30. package/dist/manifest.d.ts +76 -0
  31. package/dist/manifest.js +303 -0
  32. package/dist/query.d.ts +96 -0
  33. package/dist/query.js +719 -0
  34. package/dist/sql.d.ts +13 -0
  35. package/dist/sql.js +440 -0
  36. package/package.json +14 -34
  37. package/src/cli.ts +161 -82
  38. package/src/emit-dart.ts +245 -0
  39. package/src/emit-kotlin.ts +257 -0
  40. package/src/emit-queries-dart.ts +203 -0
  41. package/src/emit-queries-kotlin.ts +209 -0
  42. package/src/emit-queries-swift.ts +198 -0
  43. package/src/emit-queries.ts +183 -0
  44. package/src/emit-swift.ts +295 -0
  45. package/src/emit.ts +239 -0
  46. package/src/errors.ts +11 -0
  47. package/src/generate.ts +574 -105
  48. package/src/index.ts +16 -13
  49. package/src/init.ts +100 -0
  50. package/src/ir.ts +197 -0
  51. package/src/manifest.ts +445 -0
  52. package/src/query.ts +918 -0
  53. package/src/sql.ts +533 -0
  54. package/dist/app-contract.d.ts +0 -154
  55. package/dist/app-contract.d.ts.map +0 -1
  56. package/dist/app-contract.js +0 -250
  57. package/dist/app-contract.js.map +0 -1
  58. package/dist/checksums.d.ts +0 -6
  59. package/dist/checksums.d.ts.map +0 -1
  60. package/dist/checksums.js +0 -173
  61. package/dist/checksums.js.map +0 -1
  62. package/dist/cli.d.ts.map +0 -1
  63. package/dist/cli.js.map +0 -1
  64. package/dist/generate.d.ts.map +0 -1
  65. package/dist/generate.js.map +0 -1
  66. package/dist/index.d.ts.map +0 -1
  67. package/dist/index.js.map +0 -1
  68. package/dist/introspect-postgres.d.ts +0 -8
  69. package/dist/introspect-postgres.d.ts.map +0 -1
  70. package/dist/introspect-postgres.js +0 -94
  71. package/dist/introspect-postgres.js.map +0 -1
  72. package/dist/introspect-sqlite.d.ts +0 -10
  73. package/dist/introspect-sqlite.d.ts.map +0 -1
  74. package/dist/introspect-sqlite.js +0 -97
  75. package/dist/introspect-sqlite.js.map +0 -1
  76. package/dist/introspect.d.ts +0 -8
  77. package/dist/introspect.d.ts.map +0 -1
  78. package/dist/introspect.js +0 -18
  79. package/dist/introspect.js.map +0 -1
  80. package/dist/map-types.d.ts +0 -20
  81. package/dist/map-types.d.ts.map +0 -1
  82. package/dist/map-types.js +0 -151
  83. package/dist/map-types.js.map +0 -1
  84. package/dist/render.d.ts +0 -23
  85. package/dist/render.d.ts.map +0 -1
  86. package/dist/render.js +0 -140
  87. package/dist/render.js.map +0 -1
  88. package/dist/types.d.ts +0 -122
  89. package/dist/types.d.ts.map +0 -1
  90. package/dist/types.js +0 -5
  91. package/dist/types.js.map +0 -1
  92. package/src/app-contract.ts +0 -531
  93. package/src/checksums.ts +0 -257
  94. package/src/introspect-postgres.ts +0 -149
  95. package/src/introspect-sqlite.ts +0 -156
  96. package/src/introspect.ts +0 -36
  97. package/src/map-types.ts +0 -189
  98. package/src/render.ts +0 -196
  99. package/src/types.ts +0 -137
@@ -0,0 +1,96 @@
1
+ import type { IrColumnType, IrDocument } from './ir.js';
2
+ /** A param type is one of the §2.4 types (the columns params compare to). */
3
+ export type QueryParamType = IrColumnType;
4
+ export interface QueryParam {
5
+ readonly name: string;
6
+ readonly type: QueryParamType;
7
+ /** How the type was resolved — for the docs/tests, not emitted. */
8
+ readonly source: 'inferred' | 'comment';
9
+ }
10
+ export interface QueryColumn {
11
+ readonly name: string;
12
+ readonly type: IrColumnType;
13
+ readonly nullable: boolean;
14
+ /** `exact` = resolved to an IR column (plain ref); `fallback` = a computed
15
+ * expression typed by the documented honest fallback. */
16
+ readonly fidelity: 'exact' | 'fallback';
17
+ }
18
+ export interface AnalyzedQuery {
19
+ /** camelCase function name (path-derived, or a `-- name:` override). */
20
+ readonly name: string;
21
+ /** Source location for errors, e.g. `billing/list.sql` (or `list.sql#2`
22
+ * for the 2nd statement of a multi-statement file). */
23
+ readonly file: string;
24
+ /** The SQL as written (named `:params`), trimmed. */
25
+ readonly sql: string;
26
+ /** The SQL with `:name` rewritten to positional `?` (wrapper surface). */
27
+ readonly positionalSql: string;
28
+ /** Params in first-occurrence (positional) order. */
29
+ readonly params: readonly QueryParam[];
30
+ /** Result columns in SELECT order. */
31
+ readonly columns: readonly QueryColumn[];
32
+ /** IR tables this query reads (the useSyncQuery `{tables}` set), sorted. */
33
+ readonly tables: readonly string[];
34
+ }
35
+ /**
36
+ * Path-relative default name. `billing/invoices/list.sql` → `billingInvoicesList`;
37
+ * a flat `list-todos.sql` → `listTodos` (unchanged). Every folder segment AND
38
+ * the filename stem must be lowercase kebab-case — rejects loudly, naming the
39
+ * offending segment, so a stray `List.sql` or `Billing/` fails at generate time.
40
+ */
41
+ export declare function queryNameFromPath(relPath: string): string;
42
+ /** Back-compat flat-file helper: `list-todos.sql` → `listTodos`. Rejects a
43
+ * path with folders (use {@link queryNameFromPath} for nested queries). */
44
+ export declare function queryNameFromFile(file: string): string;
45
+ /** Validate a `-- name:` override is a camelCase identifier (loud otherwise). */
46
+ export declare function validateOverrideName(name: string, location: string): string;
47
+ export interface SplitStatement {
48
+ /** The raw statement text (leading comment block + SQL), as written. */
49
+ readonly text: string;
50
+ /** 1-based line number of the statement's first character in the file. */
51
+ readonly startLine: number;
52
+ }
53
+ /** Split file content into statements on top-level `;` (string/comment-aware).
54
+ * Blank/comment-only tails are dropped; each statement keeps its own leading
55
+ * comment block (everything between the previous `;` and this SQL). */
56
+ export declare function splitStatements(content: string): SplitStatement[];
57
+ /** The `-- name:` override in a statement's leading comment block, or null. */
58
+ export declare function parseStatementName(statementText: string, location: string): string | null;
59
+ export interface QueryDb {
60
+ /** Prepare + return the result columns / declared types / param count.
61
+ * Throws (with SQLite's message) when the SQL is invalid against the DDL. */
62
+ analyze(sql: string): {
63
+ columnNames: readonly string[];
64
+ declaredTypes: readonly (string | null)[];
65
+ paramsCount: number;
66
+ };
67
+ }
68
+ /** Synthesize the schema DDL from the IR (the reverse of the migration
69
+ * parser): a `CREATE TABLE` per IR table with each column's declared SQLite
70
+ * type + NOT NULL, so `prepare()` validates references and decltype resolves.
71
+ * This is exported so the generator can build one in-memory DB per run. */
72
+ export declare function synthesizeDdl(ir: IrDocument): string;
73
+ /**
74
+ * Analyze ONE already-split statement against the IR + a prepared-DDL DB. The
75
+ * name is pre-resolved (path-derived or a `-- name:` override) by the caller;
76
+ * `statementText` is a single statement's leading comment block + SQL (no
77
+ * top-level `;`). This is the per-statement core; {@link analyzeQueryFile}
78
+ * splits a file and drives it.
79
+ */
80
+ export declare function analyzeStatement(name: string, location: string, statementText: string, ir: IrDocument, db: QueryDb): AnalyzedQuery;
81
+ /**
82
+ * Analyze a whole query FILE: split into statements, resolve each statement's
83
+ * name (path-derived default, or a `-- name:` override), enforce the
84
+ * multi-statement contract, and analyze each. `relPath` is the file's path
85
+ * relative to the queries root (drives the default name + error locations).
86
+ *
87
+ * Rules (agreed 2026-07-04):
88
+ * - A file with ONE statement may omit `-- name:` → the path-derived default.
89
+ * - A file with MULTIPLE statements requires `-- name:` on EVERY statement; a
90
+ * missing one errors, naming the file + the statement's position/first line.
91
+ */
92
+ export declare function analyzeQueryFile(relPath: string, content: string, ir: IrDocument, db: QueryDb): AnalyzedQuery[];
93
+ /** Back-compat single-statement analyzer: resolve the name from the file path
94
+ * (or a `-- name:` override) and analyze. Rejects a `;`-separated file loudly
95
+ * — use {@link analyzeQueryFile} for the multi-statement contract. */
96
+ export declare function analyzeQuery(file: string, raw: string, ir: IrDocument, db: QueryDb): AnalyzedQuery;