@syncular/typegen 0.1.2 → 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.
- package/README.md +436 -94
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +159 -73
- package/dist/emit-dart.d.ts +17 -0
- package/dist/emit-dart.js +201 -0
- package/dist/emit-kotlin.d.ts +16 -0
- package/dist/emit-kotlin.js +201 -0
- package/dist/emit-queries-dart.d.ts +2 -0
- package/dist/emit-queries-dart.js +160 -0
- package/dist/emit-queries-kotlin.d.ts +2 -0
- package/dist/emit-queries-kotlin.js +162 -0
- package/dist/emit-queries-swift.d.ts +2 -0
- package/dist/emit-queries-swift.js +146 -0
- package/dist/emit-queries.d.ts +2 -0
- package/dist/emit-queries.js +129 -0
- package/dist/emit-swift.d.ts +18 -0
- package/dist/emit-swift.js +235 -0
- package/dist/emit.d.ts +16 -0
- package/dist/emit.js +191 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +10 -0
- package/dist/generate.d.ts +53 -18
- package/dist/generate.js +391 -77
- package/dist/index.d.ts +17 -14
- package/dist/index.js +16 -13
- package/dist/init.d.ts +12 -0
- package/dist/init.js +85 -0
- package/dist/ir.d.ts +90 -0
- package/dist/ir.js +94 -0
- package/dist/manifest.d.ts +76 -0
- package/dist/manifest.js +303 -0
- package/dist/query.d.ts +96 -0
- package/dist/query.js +719 -0
- package/dist/sql.d.ts +13 -0
- package/dist/sql.js +440 -0
- package/package.json +14 -34
- package/src/cli.ts +161 -82
- package/src/emit-dart.ts +245 -0
- package/src/emit-kotlin.ts +257 -0
- package/src/emit-queries-dart.ts +203 -0
- package/src/emit-queries-kotlin.ts +209 -0
- package/src/emit-queries-swift.ts +198 -0
- package/src/emit-queries.ts +183 -0
- package/src/emit-swift.ts +295 -0
- package/src/emit.ts +239 -0
- package/src/errors.ts +11 -0
- package/src/generate.ts +574 -105
- package/src/index.ts +16 -13
- package/src/init.ts +100 -0
- package/src/ir.ts +197 -0
- package/src/manifest.ts +445 -0
- package/src/query.ts +918 -0
- package/src/sql.ts +533 -0
- package/dist/app-contract.d.ts +0 -154
- package/dist/app-contract.d.ts.map +0 -1
- package/dist/app-contract.js +0 -250
- package/dist/app-contract.js.map +0 -1
- package/dist/checksums.d.ts +0 -6
- package/dist/checksums.d.ts.map +0 -1
- package/dist/checksums.js +0 -173
- package/dist/checksums.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/generate.d.ts.map +0 -1
- package/dist/generate.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/introspect-postgres.d.ts +0 -8
- package/dist/introspect-postgres.d.ts.map +0 -1
- package/dist/introspect-postgres.js +0 -94
- package/dist/introspect-postgres.js.map +0 -1
- package/dist/introspect-sqlite.d.ts +0 -10
- package/dist/introspect-sqlite.d.ts.map +0 -1
- package/dist/introspect-sqlite.js +0 -97
- package/dist/introspect-sqlite.js.map +0 -1
- package/dist/introspect.d.ts +0 -8
- package/dist/introspect.d.ts.map +0 -1
- package/dist/introspect.js +0 -18
- package/dist/introspect.js.map +0 -1
- package/dist/map-types.d.ts +0 -20
- package/dist/map-types.d.ts.map +0 -1
- package/dist/map-types.js +0 -151
- package/dist/map-types.js.map +0 -1
- package/dist/render.d.ts +0 -23
- package/dist/render.d.ts.map +0 -1
- package/dist/render.js +0 -140
- package/dist/render.js.map +0 -1
- package/dist/types.d.ts +0 -122
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/src/app-contract.ts +0 -531
- package/src/checksums.ts +0 -257
- package/src/introspect-postgres.ts +0 -149
- package/src/introspect-sqlite.ts +0 -156
- package/src/introspect.ts +0 -36
- package/src/map-types.ts +0 -189
- package/src/render.ts +0 -196
- package/src/types.ts +0 -137
package/dist/query.d.ts
ADDED
|
@@ -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;
|