@syncular/typegen 0.0.1-98 → 0.0.2-126
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 +51 -0
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +9 -6
- package/dist/generate.js.map +1 -1
- package/dist/map-types.d.ts +5 -5
- package/dist/map-types.d.ts.map +1 -1
- package/dist/map-types.js +15 -19
- package/dist/map-types.js.map +1 -1
- package/dist/render.d.ts +3 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +15 -2
- package/dist/render.js.map +1 -1
- package/dist/types.d.ts +33 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/generate.ts +18 -17
- package/src/map-types.ts +16 -20
- package/src/render.ts +34 -4
- package/src/types.ts +45 -5
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @syncular/typegen
|
|
2
|
+
|
|
3
|
+
Generate TypeScript database types from your migrations.
|
|
4
|
+
|
|
5
|
+
Supports SQLite and Postgres introspection with column-level codec type overrides via `columnCodecs`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @syncular/typegen
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { codecs } from '@syncular/core';
|
|
17
|
+
import { generateTypes } from '@syncular/typegen';
|
|
18
|
+
import { migrations } from './migrations';
|
|
19
|
+
|
|
20
|
+
await generateTypes({
|
|
21
|
+
migrations,
|
|
22
|
+
output: './src/db.generated.ts',
|
|
23
|
+
dialect: 'postgres',
|
|
24
|
+
columnCodecs: (col) => {
|
|
25
|
+
if (col.table === 'events' && col.column === 'payload') {
|
|
26
|
+
return codecs.stringJson({
|
|
27
|
+
import: { name: 'EventPayload', from: './domain' },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (
|
|
31
|
+
col.table === 'events' &&
|
|
32
|
+
col.column === 'is_active' &&
|
|
33
|
+
col.sqlType?.toLowerCase().includes('int')
|
|
34
|
+
) {
|
|
35
|
+
return codecs.numberBoolean();
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
- Typegen (in migrations guide): https://syncular.dev/docs/build/migrations#type-generation-with-synculartypegen
|
|
45
|
+
|
|
46
|
+
## Links
|
|
47
|
+
|
|
48
|
+
- GitHub: https://github.com/syncular/syncular
|
|
49
|
+
- Issues: https://github.com/syncular/syncular/issues
|
|
50
|
+
|
|
51
|
+
> Status: Alpha. APIs and storage layouts may change between releases.
|
package/dist/generate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAEV,oBAAoB,EACpB,mBAAmB,EAGpB,MAAM,SAAS,CAAC;AA4CjB;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CAAC,EAAE,EACpC,OAAO,EAAE,oBAAoB,CAAC,EAAE,CAAC,GAChC,OAAO,CAAC,mBAAmB,CAAC,CAmD9B"}
|
package/dist/generate.js
CHANGED
|
@@ -10,14 +10,14 @@ import { renderTypes } from './render.js';
|
|
|
10
10
|
* Apply type mapping to all columns in the schemas.
|
|
11
11
|
* Returns the schemas with tsType filled in and any custom imports collected.
|
|
12
12
|
*/
|
|
13
|
-
function applyTypeMappings(schemas, dialect,
|
|
13
|
+
function applyTypeMappings(schemas, dialect, columnCodecs) {
|
|
14
14
|
const allImports = [];
|
|
15
15
|
const mapped = schemas.map((schema) => ({
|
|
16
16
|
...schema,
|
|
17
17
|
tables: schema.tables.map((table) => ({
|
|
18
18
|
...table,
|
|
19
19
|
columns: table.columns.map((col) => {
|
|
20
|
-
const
|
|
20
|
+
const columnInfo = {
|
|
21
21
|
table: table.name,
|
|
22
22
|
column: col.name,
|
|
23
23
|
sqlType: col.sqlType,
|
|
@@ -25,7 +25,9 @@ function applyTypeMappings(schemas, dialect, resolveType) {
|
|
|
25
25
|
isPrimaryKey: col.isPrimaryKey,
|
|
26
26
|
hasDefault: col.hasDefault,
|
|
27
27
|
dialect,
|
|
28
|
-
}
|
|
28
|
+
};
|
|
29
|
+
const codec = columnCodecs?.(columnInfo);
|
|
30
|
+
const resolved = resolveColumnType(columnInfo, codec?.ts);
|
|
29
31
|
allImports.push(...resolved.imports);
|
|
30
32
|
return {
|
|
31
33
|
...col,
|
|
@@ -52,7 +54,7 @@ function applyTypeMappings(schemas, dialect, resolveType) {
|
|
|
52
54
|
* ```
|
|
53
55
|
*/
|
|
54
56
|
export async function generateTypes(options) {
|
|
55
|
-
const { migrations, output, extendsSyncClientDb, includeVersionHistory, tables, dialect = 'sqlite',
|
|
57
|
+
const { migrations, output, extendsSyncClientDb, syncularImportType, includeVersionHistory, tables, dialect = 'sqlite', columnCodecs, } = options;
|
|
56
58
|
// Introspect schemas (raw SQL types, no TS mapping yet)
|
|
57
59
|
let rawSchemas;
|
|
58
60
|
if (includeVersionHistory) {
|
|
@@ -62,12 +64,13 @@ export async function generateTypes(options) {
|
|
|
62
64
|
const current = await introspectCurrentSchema(migrations, dialect, tables);
|
|
63
65
|
rawSchemas = [current];
|
|
64
66
|
}
|
|
65
|
-
// Apply type mapping (default +
|
|
66
|
-
const { schemas, customImports } = applyTypeMappings(rawSchemas, dialect,
|
|
67
|
+
// Apply type mapping (default + column codec overrides)
|
|
68
|
+
const { schemas, customImports } = applyTypeMappings(rawSchemas, dialect, columnCodecs);
|
|
67
69
|
// Render TypeScript code
|
|
68
70
|
const code = renderTypes({
|
|
69
71
|
schemas,
|
|
70
72
|
extendsSyncClientDb,
|
|
73
|
+
syncularImportType,
|
|
71
74
|
includeVersionHistory,
|
|
72
75
|
customImports,
|
|
73
76
|
});
|
package/dist/generate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AASvC;;;GAGG;AACH,SAAS,iBAAiB,CACxB,OAA0B,EAC1B,OAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AASvC;;;GAGG;AACH,SAAS,iBAAiB,CACxB,OAA0B,EAC1B,OAAuB,EACvB,YAAkC,EAIlC;IACA,MAAM,UAAU,GAA0C,EAAE,CAAC;IAE7D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACtC,GAAG,MAAM;QACT,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,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SAAM,CAAC;QACN,MAAM,OAAO,GAAG,MAAM,uBAAuB,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3E,UAAU,GAAG,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,wDAAwD;IACxD,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,iBAAiB,CAClD,UAAU,EACV,OAAO,EACP,YAAY,CACb,CAAC;IAEF,yBAAyB;IACzB,MAAM,IAAI,GAAG,WAAW,CAAC;QACvB,OAAO;QACP,mBAAmB;QACnB,kBAAkB;QAClB,qBAAqB;QACrB,aAAa;KACd,CAAC,CAAC;IAEH,iCAAiC;IACjC,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAElD,iBAAiB;IACjB,MAAM,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAEvC,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEjD,OAAO;QACL,UAAU,EAAE,MAAM;QAClB,cAAc,EAAE,UAAU,CAAC,cAAc;QACzC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC;QAC5C,IAAI;KACL,CAAC;AAAA,CACH"}
|
package/dist/map-types.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @syncular/typegen - Type mapping
|
|
3
3
|
*
|
|
4
4
|
* Maps SQL types to TypeScript types for each dialect,
|
|
5
|
-
* with support for
|
|
5
|
+
* with support for column codec type overrides.
|
|
6
6
|
*/
|
|
7
|
-
import type { ColumnInfo,
|
|
7
|
+
import type { ColumnInfo, TypeOverride } from './types';
|
|
8
8
|
export interface ResolvedType {
|
|
9
9
|
tsType: string;
|
|
10
10
|
imports: Array<{
|
|
@@ -13,8 +13,8 @@ export interface ResolvedType {
|
|
|
13
13
|
}>;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Resolve the TypeScript type for a column, applying
|
|
17
|
-
* and falling back to the default dialect mapping.
|
|
16
|
+
* Resolve the TypeScript type for a column, applying an optional override
|
|
17
|
+
* first and falling back to the default dialect mapping.
|
|
18
18
|
*/
|
|
19
|
-
export declare function resolveColumnType(col: ColumnInfo,
|
|
19
|
+
export declare function resolveColumnType(col: ColumnInfo, override?: TypeOverride): ResolvedType;
|
|
20
20
|
//# sourceMappingURL=map-types.d.ts.map
|
package/dist/map-types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-types.d.ts","sourceRoot":"","sources":["../src/map-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"map-types.d.ts","sourceRoot":"","sources":["../src/map-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAC;AAExE,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AA6ID;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,UAAU,EACf,QAAQ,CAAC,EAAE,YAAY,GACtB,YAAY,CA4Bd"}
|
package/dist/map-types.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @syncular/typegen - Type mapping
|
|
3
3
|
*
|
|
4
4
|
* Maps SQL types to TypeScript types for each dialect,
|
|
5
|
-
* with support for
|
|
5
|
+
* with support for column codec type overrides.
|
|
6
6
|
*/
|
|
7
7
|
function mapSqliteType(sqlType) {
|
|
8
8
|
const upper = sqlType.toUpperCase();
|
|
@@ -118,31 +118,27 @@ function defaultMapper(dialect) {
|
|
|
118
118
|
return dialect === 'postgres' ? mapPostgresType : mapSqliteType;
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
|
-
* Resolve the TypeScript type for a column, applying
|
|
122
|
-
* and falling back to the default dialect mapping.
|
|
121
|
+
* Resolve the TypeScript type for a column, applying an optional override
|
|
122
|
+
* first and falling back to the default dialect mapping.
|
|
123
123
|
*/
|
|
124
|
-
export function resolveColumnType(col,
|
|
124
|
+
export function resolveColumnType(col, override) {
|
|
125
125
|
const imports = [];
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (override !== undefined) {
|
|
130
|
-
if (typeof override === 'string') {
|
|
131
|
-
const baseType = override;
|
|
132
|
-
return {
|
|
133
|
-
tsType: col.nullable ? `${baseType} | null` : baseType,
|
|
134
|
-
imports,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
if (override.import) {
|
|
138
|
-
imports.push(override.import);
|
|
139
|
-
}
|
|
140
|
-
const baseType = override.type;
|
|
126
|
+
if (override !== undefined) {
|
|
127
|
+
if (typeof override === 'string') {
|
|
128
|
+
const baseType = override;
|
|
141
129
|
return {
|
|
142
130
|
tsType: col.nullable ? `${baseType} | null` : baseType,
|
|
143
131
|
imports,
|
|
144
132
|
};
|
|
145
133
|
}
|
|
134
|
+
if (override.import) {
|
|
135
|
+
imports.push(override.import);
|
|
136
|
+
}
|
|
137
|
+
const baseType = override.type;
|
|
138
|
+
return {
|
|
139
|
+
tsType: col.nullable ? `${baseType} | null` : baseType,
|
|
140
|
+
imports,
|
|
141
|
+
};
|
|
146
142
|
}
|
|
147
143
|
// Default mapping
|
|
148
144
|
const mapper = defaultMapper(col.dialect);
|
package/dist/map-types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-types.js","sourceRoot":"","sources":["../src/map-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,SAAS,aAAa,CAAC,OAAe,EAAU;IAC9C,MAAM,KAAK,GAAG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CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC/B,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,SAAS,CAAC,CAAC,CAAC,QAAQ;YACtD,OAAO;SACR,CAAC;IACJ,CAAC;IAED,kBAAkB;IAClB,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,SAAS,CAAC,CAAC,CAAC,QAAQ;QACtD,OAAO;KACR,CAAC;AAAA,CACH"}
|
package/dist/render.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @syncular/typegen - TypeScript code generation
|
|
3
3
|
*/
|
|
4
|
-
import type { VersionedSchema } from './types';
|
|
4
|
+
import type { SyncularImportType, VersionedSchema } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* Options for rendering types.
|
|
7
7
|
*/
|
|
@@ -10,6 +10,8 @@ export interface RenderOptions {
|
|
|
10
10
|
schemas: VersionedSchema[];
|
|
11
11
|
/** Whether to extend SyncClientDb */
|
|
12
12
|
extendsSyncClientDb?: boolean;
|
|
13
|
+
/** Controls package import style for SyncClientDb (default: 'scoped') */
|
|
14
|
+
syncularImportType?: SyncularImportType;
|
|
13
15
|
/** Generate versioned interfaces */
|
|
14
16
|
includeVersionHistory?: boolean;
|
|
15
17
|
/** Custom imports collected from resolver results */
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAEV,kBAAkB,EAElB,eAAe,EAChB,MAAM,SAAS,CAAC;AAiDjB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,qCAAqC;IACrC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,yEAAyE;IACzE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,oCAAoC;IACpC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,qDAAqD;IACrD,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvD;AAkBD;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAuH1D"}
|
package/dist/render.js
CHANGED
|
@@ -36,11 +36,24 @@ function renderDbInterface(schema, interfaceName, extendsType) {
|
|
|
36
36
|
.join('\n');
|
|
37
37
|
return `export interface ${interfaceName}${extendsClause} {\n${tableEntries}\n}`;
|
|
38
38
|
}
|
|
39
|
+
function resolveSyncClientImportPath(importType) {
|
|
40
|
+
if (importType === 'umbrella') {
|
|
41
|
+
return 'syncular/client';
|
|
42
|
+
}
|
|
43
|
+
if (importType === 'scoped') {
|
|
44
|
+
return '@syncular/client';
|
|
45
|
+
}
|
|
46
|
+
const clientImportPath = importType.client.trim();
|
|
47
|
+
if (clientImportPath.length === 0) {
|
|
48
|
+
throw new Error('syncularImportType.client must be a non-empty package import path');
|
|
49
|
+
}
|
|
50
|
+
return clientImportPath;
|
|
51
|
+
}
|
|
39
52
|
/**
|
|
40
53
|
* Render complete TypeScript type definitions.
|
|
41
54
|
*/
|
|
42
55
|
export function renderTypes(options) {
|
|
43
|
-
const { schemas, extendsSyncClientDb, includeVersionHistory, customImports } = options;
|
|
56
|
+
const { schemas, extendsSyncClientDb, syncularImportType = 'scoped', includeVersionHistory, customImports, } = options;
|
|
44
57
|
const lines = [];
|
|
45
58
|
// Header
|
|
46
59
|
lines.push('/**');
|
|
@@ -50,7 +63,7 @@ export function renderTypes(options) {
|
|
|
50
63
|
lines.push('');
|
|
51
64
|
// Import SyncClientDb if extending
|
|
52
65
|
if (extendsSyncClientDb) {
|
|
53
|
-
lines.push(
|
|
66
|
+
lines.push(`import type { SyncClientDb } from '${resolveSyncClientImportPath(syncularImportType)}';`);
|
|
54
67
|
lines.push('');
|
|
55
68
|
}
|
|
56
69
|
const usesGenerated = schemas.some((schema) => schema.tables.some((table) => table.columns.some((column) => column.hasDefault)));
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH;;GAEG;AACH,SAAS,YAAY,CAAC,GAAW,EAAU;IACzC,OAAO,GAAG;SACP,KAAK,CAAC,MAAM,CAAC;SACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;SACzE,IAAI,CAAC,EAAE,CAAC,CAAC;AAAA,CACb;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,MAAoB,EAAU;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU;QAC9B,CAAC,CAAC,aAAa,MAAM,CAAC,MAAM,GAAG;QAC/B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IAClB,OAAO,KAAK,MAAM,CAAC,IAAI,KAAK,MAAM,GAAG,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/types.d.ts
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { DefinedMigrations } from '@syncular/migrations';
|
|
5
5
|
export type TypegenDialect = 'sqlite' | 'postgres';
|
|
6
|
+
export type SyncularImportType = 'scoped' | 'umbrella' | {
|
|
7
|
+
client: string;
|
|
8
|
+
[packageName: string]: string;
|
|
9
|
+
};
|
|
6
10
|
/**
|
|
7
|
-
* Column information
|
|
11
|
+
* Column information for a schema column.
|
|
8
12
|
*/
|
|
9
13
|
export interface ColumnInfo {
|
|
10
14
|
table: string;
|
|
@@ -26,9 +30,23 @@ export type TypeOverride = string | {
|
|
|
26
30
|
};
|
|
27
31
|
};
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
33
|
+
* Column codec definition shared across runtime and typegen.
|
|
34
|
+
* Typegen only consumes the `ts` field, but a full codec object can be
|
|
35
|
+
* provided as a single source of truth.
|
|
36
|
+
*/
|
|
37
|
+
export interface ColumnCodec<App, Db> {
|
|
38
|
+
ts: TypeOverride;
|
|
39
|
+
toDb(value: App): Db;
|
|
40
|
+
fromDb(value: Db): App;
|
|
41
|
+
dialects?: Partial<Record<TypegenDialect, {
|
|
42
|
+
toDb?(value: App): Db;
|
|
43
|
+
fromDb?(value: Db): App;
|
|
44
|
+
}>>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Column codec resolver for a column.
|
|
30
48
|
*/
|
|
31
|
-
export type
|
|
49
|
+
export type ColumnCodecResolver = (column: ColumnInfo) => ColumnCodec<unknown, unknown> | undefined;
|
|
32
50
|
/**
|
|
33
51
|
* Parsed table schema.
|
|
34
52
|
*/
|
|
@@ -66,12 +84,22 @@ export interface GenerateTypesOptions<DB = unknown> {
|
|
|
66
84
|
dialect?: TypegenDialect;
|
|
67
85
|
/** Whether to extend SyncClientDb interface (adds sync infrastructure types) */
|
|
68
86
|
extendsSyncClientDb?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Controls how syncular package imports are rendered in generated output.
|
|
89
|
+
* - 'scoped' (default): '@syncular/client'
|
|
90
|
+
* - 'umbrella': 'syncular/client'
|
|
91
|
+
* - object: explicit package mapping (must include `client`)
|
|
92
|
+
*/
|
|
93
|
+
syncularImportType?: SyncularImportType;
|
|
69
94
|
/** Generate versioned interfaces (ClientDbV1, ClientDbV2, etc.) */
|
|
70
95
|
includeVersionHistory?: boolean;
|
|
71
96
|
/** Only generate types for these tables (default: all tables) */
|
|
72
97
|
tables?: string[];
|
|
73
|
-
/**
|
|
74
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Optional column codec resolver for per-column type overrides.
|
|
100
|
+
* Receives full column metadata (table, column, sqlType, dialect, etc.).
|
|
101
|
+
*/
|
|
102
|
+
columnCodecs?: ColumnCodecResolver;
|
|
75
103
|
}
|
|
76
104
|
/**
|
|
77
105
|
* Result of type generation.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,cAAc,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,MAAM,GACN;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAE9D
|
|
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AM,CAAC;CACd"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/typegen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-126",
|
|
4
4
|
"description": "TypeScript type generator for Syncular schemas",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@electric-sql/pglite": "^0.3.15",
|
|
47
|
-
"@syncular/migrations": "0.0.
|
|
47
|
+
"@syncular/migrations": "0.0.2-126",
|
|
48
48
|
"better-sqlite3": "^12.6.2",
|
|
49
49
|
"kysely-bun-sqlite": "^0.4.0",
|
|
50
50
|
"kysely-pglite-dialect": "^1.2.0"
|
package/src/generate.ts
CHANGED
|
@@ -8,9 +8,9 @@ import { introspectAllVersions, introspectCurrentSchema } from './introspect';
|
|
|
8
8
|
import { resolveColumnType } from './map-types';
|
|
9
9
|
import { renderTypes } from './render';
|
|
10
10
|
import type {
|
|
11
|
+
ColumnCodecResolver,
|
|
11
12
|
GenerateTypesOptions,
|
|
12
13
|
GenerateTypesResult,
|
|
13
|
-
ResolveTypeFn,
|
|
14
14
|
TypegenDialect,
|
|
15
15
|
VersionedSchema,
|
|
16
16
|
} from './types';
|
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
function applyTypeMappings(
|
|
23
23
|
schemas: VersionedSchema[],
|
|
24
24
|
dialect: TypegenDialect,
|
|
25
|
-
|
|
25
|
+
columnCodecs?: ColumnCodecResolver
|
|
26
26
|
): {
|
|
27
27
|
schemas: VersionedSchema[];
|
|
28
28
|
customImports: Array<{ name: string; from: string }>;
|
|
@@ -34,18 +34,17 @@ function applyTypeMappings(
|
|
|
34
34
|
tables: schema.tables.map((table) => ({
|
|
35
35
|
...table,
|
|
36
36
|
columns: table.columns.map((col) => {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
);
|
|
37
|
+
const columnInfo = {
|
|
38
|
+
table: table.name,
|
|
39
|
+
column: col.name,
|
|
40
|
+
sqlType: col.sqlType,
|
|
41
|
+
nullable: col.nullable,
|
|
42
|
+
isPrimaryKey: col.isPrimaryKey,
|
|
43
|
+
hasDefault: col.hasDefault,
|
|
44
|
+
dialect,
|
|
45
|
+
} as const;
|
|
46
|
+
const codec = columnCodecs?.(columnInfo);
|
|
47
|
+
const resolved = resolveColumnType(columnInfo, codec?.ts);
|
|
49
48
|
allImports.push(...resolved.imports);
|
|
50
49
|
return {
|
|
51
50
|
...col,
|
|
@@ -80,10 +79,11 @@ export async function generateTypes<DB>(
|
|
|
80
79
|
migrations,
|
|
81
80
|
output,
|
|
82
81
|
extendsSyncClientDb,
|
|
82
|
+
syncularImportType,
|
|
83
83
|
includeVersionHistory,
|
|
84
84
|
tables,
|
|
85
85
|
dialect = 'sqlite',
|
|
86
|
-
|
|
86
|
+
columnCodecs,
|
|
87
87
|
} = options;
|
|
88
88
|
|
|
89
89
|
// Introspect schemas (raw SQL types, no TS mapping yet)
|
|
@@ -95,17 +95,18 @@ export async function generateTypes<DB>(
|
|
|
95
95
|
rawSchemas = [current];
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
// Apply type mapping (default +
|
|
98
|
+
// Apply type mapping (default + column codec overrides)
|
|
99
99
|
const { schemas, customImports } = applyTypeMappings(
|
|
100
100
|
rawSchemas,
|
|
101
101
|
dialect,
|
|
102
|
-
|
|
102
|
+
columnCodecs
|
|
103
103
|
);
|
|
104
104
|
|
|
105
105
|
// Render TypeScript code
|
|
106
106
|
const code = renderTypes({
|
|
107
107
|
schemas,
|
|
108
108
|
extendsSyncClientDb,
|
|
109
|
+
syncularImportType,
|
|
109
110
|
includeVersionHistory,
|
|
110
111
|
customImports,
|
|
111
112
|
});
|
package/src/map-types.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @syncular/typegen - Type mapping
|
|
3
3
|
*
|
|
4
4
|
* Maps SQL types to TypeScript types for each dialect,
|
|
5
|
-
* with support for
|
|
5
|
+
* with support for column codec type overrides.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { ColumnInfo,
|
|
8
|
+
import type { ColumnInfo, TypegenDialect, TypeOverride } from './types';
|
|
9
9
|
|
|
10
10
|
export interface ResolvedType {
|
|
11
11
|
tsType: string;
|
|
@@ -152,35 +152,31 @@ function defaultMapper(dialect: TypegenDialect): (sqlType: string) => string {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
|
-
* Resolve the TypeScript type for a column, applying
|
|
156
|
-
* and falling back to the default dialect mapping.
|
|
155
|
+
* Resolve the TypeScript type for a column, applying an optional override
|
|
156
|
+
* first and falling back to the default dialect mapping.
|
|
157
157
|
*/
|
|
158
158
|
export function resolveColumnType(
|
|
159
159
|
col: ColumnInfo,
|
|
160
|
-
|
|
160
|
+
override?: TypeOverride
|
|
161
161
|
): ResolvedType {
|
|
162
162
|
const imports: Array<{ name: string; from: string }> = [];
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (override !== undefined) {
|
|
168
|
-
if (typeof override === 'string') {
|
|
169
|
-
const baseType = override;
|
|
170
|
-
return {
|
|
171
|
-
tsType: col.nullable ? `${baseType} | null` : baseType,
|
|
172
|
-
imports,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
if (override.import) {
|
|
176
|
-
imports.push(override.import);
|
|
177
|
-
}
|
|
178
|
-
const baseType = override.type;
|
|
164
|
+
if (override !== undefined) {
|
|
165
|
+
if (typeof override === 'string') {
|
|
166
|
+
const baseType = override;
|
|
179
167
|
return {
|
|
180
168
|
tsType: col.nullable ? `${baseType} | null` : baseType,
|
|
181
169
|
imports,
|
|
182
170
|
};
|
|
183
171
|
}
|
|
172
|
+
if (override.import) {
|
|
173
|
+
imports.push(override.import);
|
|
174
|
+
}
|
|
175
|
+
const baseType = override.type;
|
|
176
|
+
return {
|
|
177
|
+
tsType: col.nullable ? `${baseType} | null` : baseType,
|
|
178
|
+
imports,
|
|
179
|
+
};
|
|
184
180
|
}
|
|
185
181
|
|
|
186
182
|
// Default mapping
|
package/src/render.ts
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
* @syncular/typegen - TypeScript code generation
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
ColumnSchema,
|
|
7
|
+
SyncularImportType,
|
|
8
|
+
TableSchema,
|
|
9
|
+
VersionedSchema,
|
|
10
|
+
} from './types';
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Convert a snake_case table/column name to PascalCase.
|
|
@@ -59,18 +64,41 @@ export interface RenderOptions {
|
|
|
59
64
|
schemas: VersionedSchema[];
|
|
60
65
|
/** Whether to extend SyncClientDb */
|
|
61
66
|
extendsSyncClientDb?: boolean;
|
|
67
|
+
/** Controls package import style for SyncClientDb (default: 'scoped') */
|
|
68
|
+
syncularImportType?: SyncularImportType;
|
|
62
69
|
/** Generate versioned interfaces */
|
|
63
70
|
includeVersionHistory?: boolean;
|
|
64
71
|
/** Custom imports collected from resolver results */
|
|
65
72
|
customImports?: Array<{ name: string; from: string }>;
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
function resolveSyncClientImportPath(importType: SyncularImportType): string {
|
|
76
|
+
if (importType === 'umbrella') {
|
|
77
|
+
return 'syncular/client';
|
|
78
|
+
}
|
|
79
|
+
if (importType === 'scoped') {
|
|
80
|
+
return '@syncular/client';
|
|
81
|
+
}
|
|
82
|
+
const clientImportPath = importType.client.trim();
|
|
83
|
+
if (clientImportPath.length === 0) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
'syncularImportType.client must be a non-empty package import path'
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return clientImportPath;
|
|
89
|
+
}
|
|
90
|
+
|
|
68
91
|
/**
|
|
69
92
|
* Render complete TypeScript type definitions.
|
|
70
93
|
*/
|
|
71
94
|
export function renderTypes(options: RenderOptions): string {
|
|
72
|
-
const {
|
|
73
|
-
|
|
95
|
+
const {
|
|
96
|
+
schemas,
|
|
97
|
+
extendsSyncClientDb,
|
|
98
|
+
syncularImportType = 'scoped',
|
|
99
|
+
includeVersionHistory,
|
|
100
|
+
customImports,
|
|
101
|
+
} = options;
|
|
74
102
|
const lines: string[] = [];
|
|
75
103
|
|
|
76
104
|
// Header
|
|
@@ -82,7 +110,9 @@ export function renderTypes(options: RenderOptions): string {
|
|
|
82
110
|
|
|
83
111
|
// Import SyncClientDb if extending
|
|
84
112
|
if (extendsSyncClientDb) {
|
|
85
|
-
lines.push(
|
|
113
|
+
lines.push(
|
|
114
|
+
`import type { SyncClientDb } from '${resolveSyncClientImportPath(syncularImportType)}';`
|
|
115
|
+
);
|
|
86
116
|
lines.push('');
|
|
87
117
|
}
|
|
88
118
|
|
package/src/types.ts
CHANGED
|
@@ -6,8 +6,16 @@ import type { DefinedMigrations } from '@syncular/migrations';
|
|
|
6
6
|
|
|
7
7
|
export type TypegenDialect = 'sqlite' | 'postgres';
|
|
8
8
|
|
|
9
|
+
export type SyncularImportType =
|
|
10
|
+
| 'scoped'
|
|
11
|
+
| 'umbrella'
|
|
12
|
+
| {
|
|
13
|
+
client: string;
|
|
14
|
+
[packageName: string]: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
9
17
|
/**
|
|
10
|
-
* Column information
|
|
18
|
+
* Column information for a schema column.
|
|
11
19
|
*/
|
|
12
20
|
export interface ColumnInfo {
|
|
13
21
|
table: string;
|
|
@@ -27,9 +35,31 @@ export type TypeOverride =
|
|
|
27
35
|
| { type: string; import?: { name: string; from: string } };
|
|
28
36
|
|
|
29
37
|
/**
|
|
30
|
-
*
|
|
38
|
+
* Column codec definition shared across runtime and typegen.
|
|
39
|
+
* Typegen only consumes the `ts` field, but a full codec object can be
|
|
40
|
+
* provided as a single source of truth.
|
|
41
|
+
*/
|
|
42
|
+
export interface ColumnCodec<App, Db> {
|
|
43
|
+
ts: TypeOverride;
|
|
44
|
+
toDb(value: App): Db;
|
|
45
|
+
fromDb(value: Db): App;
|
|
46
|
+
dialects?: Partial<
|
|
47
|
+
Record<
|
|
48
|
+
TypegenDialect,
|
|
49
|
+
{
|
|
50
|
+
toDb?(value: App): Db;
|
|
51
|
+
fromDb?(value: Db): App;
|
|
52
|
+
}
|
|
53
|
+
>
|
|
54
|
+
>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Column codec resolver for a column.
|
|
31
59
|
*/
|
|
32
|
-
export type
|
|
60
|
+
export type ColumnCodecResolver = (
|
|
61
|
+
column: ColumnInfo
|
|
62
|
+
) => ColumnCodec<unknown, unknown> | undefined;
|
|
33
63
|
|
|
34
64
|
/**
|
|
35
65
|
* Parsed table schema.
|
|
@@ -71,12 +101,22 @@ export interface GenerateTypesOptions<DB = unknown> {
|
|
|
71
101
|
dialect?: TypegenDialect;
|
|
72
102
|
/** Whether to extend SyncClientDb interface (adds sync infrastructure types) */
|
|
73
103
|
extendsSyncClientDb?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Controls how syncular package imports are rendered in generated output.
|
|
106
|
+
* - 'scoped' (default): '@syncular/client'
|
|
107
|
+
* - 'umbrella': 'syncular/client'
|
|
108
|
+
* - object: explicit package mapping (must include `client`)
|
|
109
|
+
*/
|
|
110
|
+
syncularImportType?: SyncularImportType;
|
|
74
111
|
/** Generate versioned interfaces (ClientDbV1, ClientDbV2, etc.) */
|
|
75
112
|
includeVersionHistory?: boolean;
|
|
76
113
|
/** Only generate types for these tables (default: all tables) */
|
|
77
114
|
tables?: string[];
|
|
78
|
-
/**
|
|
79
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Optional column codec resolver for per-column type overrides.
|
|
117
|
+
* Receives full column metadata (table, column, sqlType, dialect, etc.).
|
|
118
|
+
*/
|
|
119
|
+
columnCodecs?: ColumnCodecResolver;
|
|
80
120
|
}
|
|
81
121
|
|
|
82
122
|
/**
|