@typokit/transform-native 0.1.4
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/dist/index.d.ts +148 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +290 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
- package/src/env.d.ts +40 -0
- package/src/index.d.ts +135 -0
- package/src/index.test.ts +878 -0
- package/src/index.ts +437 -0
- package/src/lib.rs +388 -0
- package/src/openapi_generator.rs +525 -0
- package/src/output_pipeline.rs +234 -0
- package/src/parser.rs +105 -0
- package/src/route_compiler.rs +615 -0
- package/src/schema_differ.rs +393 -0
- package/src/test_stub_generator.rs +318 -0
- package/src/type_extractor.rs +370 -0
- package/src/typia_bridge.rs +179 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { SchemaTypeMap } from "@typokit/types";
|
|
2
|
+
interface JsPropertyMetadata {
|
|
3
|
+
type: string;
|
|
4
|
+
optional: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface JsSchemaChange {
|
|
7
|
+
type: string;
|
|
8
|
+
entity: string;
|
|
9
|
+
field?: string;
|
|
10
|
+
details?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
interface JsMigrationDraft {
|
|
13
|
+
name: string;
|
|
14
|
+
sql: string;
|
|
15
|
+
destructive: boolean;
|
|
16
|
+
changes: JsSchemaChange[];
|
|
17
|
+
}
|
|
18
|
+
interface JsTypeValidatorInput {
|
|
19
|
+
name: string;
|
|
20
|
+
properties: Record<string, JsPropertyMetadata>;
|
|
21
|
+
}
|
|
22
|
+
/** Options for the output pipeline */
|
|
23
|
+
export interface PipelineOptions {
|
|
24
|
+
/** Paths to TypeScript files containing type definitions */
|
|
25
|
+
typeFiles: string[];
|
|
26
|
+
/** Paths to TypeScript files containing route contracts */
|
|
27
|
+
routeFiles: string[];
|
|
28
|
+
/** Output directory (defaults to ".typokit") */
|
|
29
|
+
outputDir?: string;
|
|
30
|
+
/** Optional validator callback — receives type inputs, returns [name, code] pairs */
|
|
31
|
+
validatorCallback?: (inputs: JsTypeValidatorInput[]) => Promise<[string, string][]> | [string, string][];
|
|
32
|
+
/** Path to cache hash file (defaults to ".typokit/.cache-hash") */
|
|
33
|
+
cacheFile?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Result of a full pipeline run */
|
|
36
|
+
export interface PipelineOutput {
|
|
37
|
+
/** Whether outputs were regenerated (false = cache hit) */
|
|
38
|
+
regenerated: boolean;
|
|
39
|
+
/** Content hash of source files */
|
|
40
|
+
contentHash: string;
|
|
41
|
+
/** Extracted type metadata */
|
|
42
|
+
types: SchemaTypeMap;
|
|
43
|
+
/** Files written to outputDir */
|
|
44
|
+
filesWritten: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parse TypeScript source files and extract type metadata.
|
|
48
|
+
*
|
|
49
|
+
* Uses the Rust-native SWC parser for high-performance AST parsing and
|
|
50
|
+
* type extraction. Extracts interface definitions including JSDoc tags
|
|
51
|
+
* (@table, @id, @generated, @format, @unique, @minLength, @maxLength,
|
|
52
|
+
* @default, @onUpdate).
|
|
53
|
+
*
|
|
54
|
+
* @param filePaths - Array of file paths to parse
|
|
55
|
+
* @returns SchemaTypeMap mapping type names to their metadata
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseAndExtractTypes(filePaths: string[]): Promise<SchemaTypeMap>;
|
|
58
|
+
/**
|
|
59
|
+
* Compile route contracts from TypeScript files into a radix tree.
|
|
60
|
+
*
|
|
61
|
+
* Parses interfaces with route contract keys (e.g., "GET /users") and
|
|
62
|
+
* builds a compiled radix tree serialized as TypeScript source code.
|
|
63
|
+
*
|
|
64
|
+
* @param filePaths - Array of file paths containing route contract interfaces
|
|
65
|
+
* @returns TypeScript source code for the compiled route table
|
|
66
|
+
*/
|
|
67
|
+
export declare function compileRoutes(filePaths: string[]): Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Generate an OpenAPI 3.1.0 specification from route contracts and type definitions.
|
|
70
|
+
*
|
|
71
|
+
* @param routeFilePaths - Array of file paths containing route contract interfaces
|
|
72
|
+
* @param typeFilePaths - Array of file paths containing type definitions
|
|
73
|
+
* @returns OpenAPI 3.1.0 specification as a JSON string
|
|
74
|
+
*/
|
|
75
|
+
export declare function generateOpenApi(routeFilePaths: string[], typeFilePaths: string[]): Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Diff two schema versions and produce a migration draft.
|
|
78
|
+
*
|
|
79
|
+
* Compares old types against new types to detect added, removed, and
|
|
80
|
+
* modified entities and fields. Generates SQL DDL stubs for the changes.
|
|
81
|
+
*
|
|
82
|
+
* @param oldTypes - Previous schema version
|
|
83
|
+
* @param newTypes - New schema version
|
|
84
|
+
* @param migrationName - Name for the migration draft
|
|
85
|
+
* @returns MigrationDraft with SQL, changes, and destructive flag
|
|
86
|
+
*/
|
|
87
|
+
export declare function diffSchemas(oldTypes: SchemaTypeMap, newTypes: SchemaTypeMap, migrationName: string): Promise<JsMigrationDraft>;
|
|
88
|
+
/**
|
|
89
|
+
* Generate contract test scaffolding from route contract files.
|
|
90
|
+
*
|
|
91
|
+
* Parses route contracts and generates TypeScript test stubs with
|
|
92
|
+
* describe/it blocks for each route.
|
|
93
|
+
*
|
|
94
|
+
* @param filePaths - Array of file paths containing route contract interfaces
|
|
95
|
+
* @returns TypeScript test code string
|
|
96
|
+
*/
|
|
97
|
+
export declare function generateTestStubs(filePaths: string[]): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Prepare type metadata for Typia validator generation.
|
|
100
|
+
*
|
|
101
|
+
* Converts parsed type metadata into a format suitable for passing
|
|
102
|
+
* to the @typokit/transform-typia bridge callback.
|
|
103
|
+
*
|
|
104
|
+
* @param typeFilePaths - Array of file paths containing type definitions
|
|
105
|
+
* @returns Array of type validator inputs
|
|
106
|
+
*/
|
|
107
|
+
export declare function prepareValidatorInputs(typeFilePaths: string[]): Promise<JsTypeValidatorInput[]>;
|
|
108
|
+
/**
|
|
109
|
+
* Collect validator code results into a file path map.
|
|
110
|
+
*
|
|
111
|
+
* Maps type names and their generated code to output file paths
|
|
112
|
+
* under .typokit/validators/.
|
|
113
|
+
*
|
|
114
|
+
* @param results - Array of [typeName, code] pairs
|
|
115
|
+
* @returns Map of file paths to validator code
|
|
116
|
+
*/
|
|
117
|
+
export declare function collectValidatorOutputs(results: [string, string][]): Promise<Record<string, string>>;
|
|
118
|
+
/**
|
|
119
|
+
* Compute a SHA-256 content hash of source files.
|
|
120
|
+
*
|
|
121
|
+
* Used for cache invalidation: if the hash matches a previous build,
|
|
122
|
+
* outputs can be reused without regeneration.
|
|
123
|
+
*
|
|
124
|
+
* @param filePaths - Array of file paths to hash
|
|
125
|
+
* @returns Hex-encoded SHA-256 hash string
|
|
126
|
+
*/
|
|
127
|
+
export declare function computeContentHash(filePaths: string[]): Promise<string>;
|
|
128
|
+
/**
|
|
129
|
+
* Run the full output pipeline with content-hash caching.
|
|
130
|
+
*
|
|
131
|
+
* Orchestrates all transform steps: parse types, compile routes, generate
|
|
132
|
+
* OpenAPI spec, generate test stubs, and prepare validator inputs. Writes
|
|
133
|
+
* all outputs to the `.typokit/` directory structure:
|
|
134
|
+
*
|
|
135
|
+
* - `.typokit/routes/compiled-router.ts` — Compiled radix tree
|
|
136
|
+
* - `.typokit/schemas/openapi.json` — OpenAPI 3.1.0 spec
|
|
137
|
+
* - `.typokit/tests/contract.test.ts` — Contract test stubs
|
|
138
|
+
* - `.typokit/validators/*.ts` — Typia validators (if callback provided)
|
|
139
|
+
*
|
|
140
|
+
* Content-hash caching: If the hash of all source files matches the cached
|
|
141
|
+
* hash, no outputs are regenerated. Force a rebuild by deleting `.typokit/.cache-hash`.
|
|
142
|
+
*
|
|
143
|
+
* @param options - Pipeline configuration
|
|
144
|
+
* @returns Pipeline output with metadata about what was generated
|
|
145
|
+
*/
|
|
146
|
+
export declare function buildPipeline(options: PipelineOptions): Promise<PipelineOutput>;
|
|
147
|
+
export {};
|
|
148
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAOD,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAED,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CAChD;AA8BD,sCAAsC;AACtC,MAAM,WAAW,eAAe;IAC9B,4DAA4D;IAC5D,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,2DAA2D;IAC3D,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,iBAAiB,CAAC,EAAE,CAClB,MAAM,EAAE,oBAAoB,EAAE,KAC3B,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACtD,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,oCAAoC;AACpC,MAAM,WAAW,cAAc;IAC7B,2DAA2D;IAC3D,WA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C,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,cAAc,CAAC,CA4GzB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
// Load the platform-specific native addon
|
|
2
|
+
async function loadNativeAddon() {
|
|
3
|
+
const g = globalThis;
|
|
4
|
+
const proc = g["process"];
|
|
5
|
+
const platform = proc?.platform ?? "unknown";
|
|
6
|
+
const arch = proc?.arch ?? "unknown";
|
|
7
|
+
const triples = {
|
|
8
|
+
win32: { x64: "win32-x64-msvc" },
|
|
9
|
+
darwin: { x64: "darwin-x64", arm64: "darwin-arm64" },
|
|
10
|
+
linux: { x64: "linux-x64-gnu", arm64: "linux-arm64-gnu" },
|
|
11
|
+
};
|
|
12
|
+
const triple = triples[platform]?.[arch];
|
|
13
|
+
if (!triple) {
|
|
14
|
+
throw new Error(`@typokit/transform-native: unsupported platform ${platform}-${arch}`);
|
|
15
|
+
}
|
|
16
|
+
// In ESM, require() is not global. Use createRequire from 'module' built-in.
|
|
17
|
+
const { createRequire } = (await import(/* @vite-ignore */ "module"));
|
|
18
|
+
const req = createRequire(import.meta.url);
|
|
19
|
+
// Try loading the platform-specific native addon
|
|
20
|
+
try {
|
|
21
|
+
return req(`../index.${triple}.node`);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
try {
|
|
25
|
+
return req(`@typokit/transform-native-${triple}`);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new Error(`@typokit/transform-native: failed to load native addon for ${triple}. ` +
|
|
29
|
+
`Make sure the native addon is built.`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let _native;
|
|
34
|
+
let _loading;
|
|
35
|
+
async function getNative() {
|
|
36
|
+
if (_native)
|
|
37
|
+
return _native;
|
|
38
|
+
if (!_loading) {
|
|
39
|
+
_loading = loadNativeAddon().then((n) => {
|
|
40
|
+
_native = n;
|
|
41
|
+
return n;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return _loading;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parse TypeScript source files and extract type metadata.
|
|
48
|
+
*
|
|
49
|
+
* Uses the Rust-native SWC parser for high-performance AST parsing and
|
|
50
|
+
* type extraction. Extracts interface definitions including JSDoc tags
|
|
51
|
+
* (@table, @id, @generated, @format, @unique, @minLength, @maxLength,
|
|
52
|
+
* @default, @onUpdate).
|
|
53
|
+
*
|
|
54
|
+
* @param filePaths - Array of file paths to parse
|
|
55
|
+
* @returns SchemaTypeMap mapping type names to their metadata
|
|
56
|
+
*/
|
|
57
|
+
export async function parseAndExtractTypes(filePaths) {
|
|
58
|
+
const native = await getNative();
|
|
59
|
+
const raw = native.parseAndExtractTypes(filePaths);
|
|
60
|
+
// Convert JsTypeMetadata to TypeMetadata (compatible shape)
|
|
61
|
+
const result = {};
|
|
62
|
+
for (const [name, meta] of Object.entries(raw)) {
|
|
63
|
+
result[name] = {
|
|
64
|
+
name: meta.name,
|
|
65
|
+
properties: {},
|
|
66
|
+
};
|
|
67
|
+
for (const [propName, prop] of Object.entries(meta.properties)) {
|
|
68
|
+
result[name].properties[propName] = {
|
|
69
|
+
type: prop.type,
|
|
70
|
+
optional: prop.optional,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Compile route contracts from TypeScript files into a radix tree.
|
|
78
|
+
*
|
|
79
|
+
* Parses interfaces with route contract keys (e.g., "GET /users") and
|
|
80
|
+
* builds a compiled radix tree serialized as TypeScript source code.
|
|
81
|
+
*
|
|
82
|
+
* @param filePaths - Array of file paths containing route contract interfaces
|
|
83
|
+
* @returns TypeScript source code for the compiled route table
|
|
84
|
+
*/
|
|
85
|
+
export async function compileRoutes(filePaths) {
|
|
86
|
+
const native = await getNative();
|
|
87
|
+
return native.compileRoutes(filePaths);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Generate an OpenAPI 3.1.0 specification from route contracts and type definitions.
|
|
91
|
+
*
|
|
92
|
+
* @param routeFilePaths - Array of file paths containing route contract interfaces
|
|
93
|
+
* @param typeFilePaths - Array of file paths containing type definitions
|
|
94
|
+
* @returns OpenAPI 3.1.0 specification as a JSON string
|
|
95
|
+
*/
|
|
96
|
+
export async function generateOpenApi(routeFilePaths, typeFilePaths) {
|
|
97
|
+
const native = await getNative();
|
|
98
|
+
return native.generateOpenApi(routeFilePaths, typeFilePaths);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Diff two schema versions and produce a migration draft.
|
|
102
|
+
*
|
|
103
|
+
* Compares old types against new types to detect added, removed, and
|
|
104
|
+
* modified entities and fields. Generates SQL DDL stubs for the changes.
|
|
105
|
+
*
|
|
106
|
+
* @param oldTypes - Previous schema version
|
|
107
|
+
* @param newTypes - New schema version
|
|
108
|
+
* @param migrationName - Name for the migration draft
|
|
109
|
+
* @returns MigrationDraft with SQL, changes, and destructive flag
|
|
110
|
+
*/
|
|
111
|
+
export async function diffSchemas(oldTypes, newTypes, migrationName) {
|
|
112
|
+
const native = await getNative();
|
|
113
|
+
const oldJs = schemaTypeMapToJs(oldTypes);
|
|
114
|
+
const newJs = schemaTypeMapToJs(newTypes);
|
|
115
|
+
return native.diffSchemas(oldJs, newJs, migrationName);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Generate contract test scaffolding from route contract files.
|
|
119
|
+
*
|
|
120
|
+
* Parses route contracts and generates TypeScript test stubs with
|
|
121
|
+
* describe/it blocks for each route.
|
|
122
|
+
*
|
|
123
|
+
* @param filePaths - Array of file paths containing route contract interfaces
|
|
124
|
+
* @returns TypeScript test code string
|
|
125
|
+
*/
|
|
126
|
+
export async function generateTestStubs(filePaths) {
|
|
127
|
+
const native = await getNative();
|
|
128
|
+
return native.generateTestStubs(filePaths);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Prepare type metadata for Typia validator generation.
|
|
132
|
+
*
|
|
133
|
+
* Converts parsed type metadata into a format suitable for passing
|
|
134
|
+
* to the @typokit/transform-typia bridge callback.
|
|
135
|
+
*
|
|
136
|
+
* @param typeFilePaths - Array of file paths containing type definitions
|
|
137
|
+
* @returns Array of type validator inputs
|
|
138
|
+
*/
|
|
139
|
+
export async function prepareValidatorInputs(typeFilePaths) {
|
|
140
|
+
const native = await getNative();
|
|
141
|
+
return native.prepareValidatorInputs(typeFilePaths);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Collect validator code results into a file path map.
|
|
145
|
+
*
|
|
146
|
+
* Maps type names and their generated code to output file paths
|
|
147
|
+
* under .typokit/validators/.
|
|
148
|
+
*
|
|
149
|
+
* @param results - Array of [typeName, code] pairs
|
|
150
|
+
* @returns Map of file paths to validator code
|
|
151
|
+
*/
|
|
152
|
+
export async function collectValidatorOutputs(results) {
|
|
153
|
+
const native = await getNative();
|
|
154
|
+
return native.collectValidatorOutputs(results);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Compute a SHA-256 content hash of source files.
|
|
158
|
+
*
|
|
159
|
+
* Used for cache invalidation: if the hash matches a previous build,
|
|
160
|
+
* outputs can be reused without regeneration.
|
|
161
|
+
*
|
|
162
|
+
* @param filePaths - Array of file paths to hash
|
|
163
|
+
* @returns Hex-encoded SHA-256 hash string
|
|
164
|
+
*/
|
|
165
|
+
export async function computeContentHash(filePaths) {
|
|
166
|
+
const native = await getNative();
|
|
167
|
+
return native.computeContentHash(filePaths);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Run the full output pipeline with content-hash caching.
|
|
171
|
+
*
|
|
172
|
+
* Orchestrates all transform steps: parse types, compile routes, generate
|
|
173
|
+
* OpenAPI spec, generate test stubs, and prepare validator inputs. Writes
|
|
174
|
+
* all outputs to the `.typokit/` directory structure:
|
|
175
|
+
*
|
|
176
|
+
* - `.typokit/routes/compiled-router.ts` — Compiled radix tree
|
|
177
|
+
* - `.typokit/schemas/openapi.json` — OpenAPI 3.1.0 spec
|
|
178
|
+
* - `.typokit/tests/contract.test.ts` — Contract test stubs
|
|
179
|
+
* - `.typokit/validators/*.ts` — Typia validators (if callback provided)
|
|
180
|
+
*
|
|
181
|
+
* Content-hash caching: If the hash of all source files matches the cached
|
|
182
|
+
* hash, no outputs are regenerated. Force a rebuild by deleting `.typokit/.cache-hash`.
|
|
183
|
+
*
|
|
184
|
+
* @param options - Pipeline configuration
|
|
185
|
+
* @returns Pipeline output with metadata about what was generated
|
|
186
|
+
*/
|
|
187
|
+
export async function buildPipeline(options) {
|
|
188
|
+
const { join, dirname } = (await import(/* @vite-ignore */ "path"));
|
|
189
|
+
const nodeFs = (await import(/* @vite-ignore */ "fs"));
|
|
190
|
+
const native = await getNative();
|
|
191
|
+
const outputDir = options.outputDir ?? ".typokit";
|
|
192
|
+
const cacheFile = options.cacheFile ?? join(outputDir, ".cache-hash");
|
|
193
|
+
// 1. Compute content hash of all input files
|
|
194
|
+
const allPaths = [...options.typeFiles, ...options.routeFiles];
|
|
195
|
+
const contentHash = native.computeContentHash(allPaths);
|
|
196
|
+
// 2. Check cache
|
|
197
|
+
if (nodeFs.existsSync(cacheFile)) {
|
|
198
|
+
const cachedHash = nodeFs.readFileSync(cacheFile, "utf-8").trim();
|
|
199
|
+
if (cachedHash === contentHash) {
|
|
200
|
+
return {
|
|
201
|
+
regenerated: false,
|
|
202
|
+
contentHash,
|
|
203
|
+
types: {},
|
|
204
|
+
filesWritten: [],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// 3. Run native pipeline
|
|
209
|
+
const result = native.runPipeline(options.typeFiles, options.routeFiles);
|
|
210
|
+
// 4. Ensure output directories exist
|
|
211
|
+
const dirs = [
|
|
212
|
+
join(outputDir, "routes"),
|
|
213
|
+
join(outputDir, "schemas"),
|
|
214
|
+
join(outputDir, "tests"),
|
|
215
|
+
join(outputDir, "validators"),
|
|
216
|
+
join(outputDir, "client"),
|
|
217
|
+
];
|
|
218
|
+
for (const dir of dirs) {
|
|
219
|
+
nodeFs.mkdirSync(dir, { recursive: true });
|
|
220
|
+
}
|
|
221
|
+
const filesWritten = [];
|
|
222
|
+
// 5. Write compiled routes
|
|
223
|
+
const routesPath = join(outputDir, "routes", "compiled-router.ts");
|
|
224
|
+
nodeFs.writeFileSync(routesPath, result.compiledRoutes, "utf-8");
|
|
225
|
+
filesWritten.push(routesPath);
|
|
226
|
+
// 6. Write OpenAPI spec
|
|
227
|
+
const openapiPath = join(outputDir, "schemas", "openapi.json");
|
|
228
|
+
nodeFs.writeFileSync(openapiPath, result.openapiSpec, "utf-8");
|
|
229
|
+
filesWritten.push(openapiPath);
|
|
230
|
+
// 7. Write test stubs
|
|
231
|
+
const testsPath = join(outputDir, "tests", "contract.test.ts");
|
|
232
|
+
nodeFs.writeFileSync(testsPath, result.testStubs, "utf-8");
|
|
233
|
+
filesWritten.push(testsPath);
|
|
234
|
+
// 8. Generate and write validators (if callback provided)
|
|
235
|
+
if (options.validatorCallback && result.validatorInputs.length > 0) {
|
|
236
|
+
const validatorResults = await options.validatorCallback(result.validatorInputs);
|
|
237
|
+
const validatorOutputs = native.collectValidatorOutputs(validatorResults);
|
|
238
|
+
for (const [filePath, code] of Object.entries(validatorOutputs)) {
|
|
239
|
+
const fullPath = filePath.startsWith(outputDir)
|
|
240
|
+
? filePath
|
|
241
|
+
: join(outputDir, filePath.replace(/^\.typokit\//, ""));
|
|
242
|
+
const dir = dirname(fullPath);
|
|
243
|
+
nodeFs.mkdirSync(dir, { recursive: true });
|
|
244
|
+
nodeFs.writeFileSync(fullPath, code, "utf-8");
|
|
245
|
+
filesWritten.push(fullPath);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// 9. Write cache hash
|
|
249
|
+
nodeFs.mkdirSync(dirname(cacheFile), { recursive: true });
|
|
250
|
+
nodeFs.writeFileSync(cacheFile, contentHash, "utf-8");
|
|
251
|
+
filesWritten.push(cacheFile);
|
|
252
|
+
// 10. Convert types to SchemaTypeMap
|
|
253
|
+
const types = {};
|
|
254
|
+
for (const [name, meta] of Object.entries(result.types)) {
|
|
255
|
+
types[name] = {
|
|
256
|
+
name: meta.name,
|
|
257
|
+
properties: {},
|
|
258
|
+
};
|
|
259
|
+
for (const [propName, prop] of Object.entries(meta.properties)) {
|
|
260
|
+
types[name].properties[propName] = {
|
|
261
|
+
type: prop.type,
|
|
262
|
+
optional: prop.optional,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
regenerated: true,
|
|
268
|
+
contentHash,
|
|
269
|
+
types,
|
|
270
|
+
filesWritten,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/** Convert SchemaTypeMap to JsTypeMetadata format for native binding */
|
|
274
|
+
function schemaTypeMapToJs(types) {
|
|
275
|
+
const result = {};
|
|
276
|
+
for (const [name, meta] of Object.entries(types)) {
|
|
277
|
+
result[name] = {
|
|
278
|
+
name: meta.name,
|
|
279
|
+
properties: {},
|
|
280
|
+
};
|
|
281
|
+
for (const [propName, prop] of Object.entries(meta.properties)) {
|
|
282
|
+
result[name].properties[propName] = {
|
|
283
|
+
type: prop.type,
|
|
284
|
+
optional: prop.optional,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwFA,0CAA0C;AAC1C,KAAK,UAAU,eAAe;IAC5B,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,MAAM,IAAI,GAAG,CAAC,CAAC,SAAS,CAAmD,CAAC;IAC5E,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,SAAS,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,EAAE,IAAI,IAAI,SAAS,CA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AQ,CAAC,GAAG;gBACjC,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,WAAW,EAAE,IAAI;QACjB,WAAW;QACX,KAAK;QACL,YAAY;KACb,CAAC;AACJ,CAAC;AAED,wEAAwE;AACxE,SAAS,iBAAiB,CACxB,KAAoB;IAEpB,MAAM,MAAM,GAAmC,EAAE,CAAC;IAClD,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,MAAM,CAAC,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,EAAE;SACf,CAAC;QACF,KAAK,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/D,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG;gBAClC,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typokit/transform-native",
|
|
3
|
+
"exports": {
|
|
4
|
+
".": {
|
|
5
|
+
"import": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"version": "0.1.4",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"src",
|
|
14
|
+
"*.node"
|
|
15
|
+
],
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@typokit/types": "0.1.4"
|
|
20
|
+
},
|
|
21
|
+
"napi": {
|
|
22
|
+
"binaryName": "index",
|
|
23
|
+
"targets": [
|
|
24
|
+
"x86_64-pc-windows-msvc",
|
|
25
|
+
"x86_64-apple-darwin",
|
|
26
|
+
"aarch64-apple-darwin",
|
|
27
|
+
"x86_64-unknown-linux-gnu",
|
|
28
|
+
"aarch64-unknown-linux-gnu",
|
|
29
|
+
"x86_64-unknown-linux-musl"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/KyleBastien/typokit",
|
|
35
|
+
"directory": "packages/transform-native"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"test": "rstest run --passWithNoTests",
|
|
39
|
+
"build:native": "napi build --platform --dts src/index.d.ts --js false",
|
|
40
|
+
"build:native:release": "napi build --platform --release --dts src/index.d.ts --js false"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/env.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Minimal type declarations for Node.js APIs used by transform-native
|
|
2
|
+
// Avoids adding @types/node as a dependency
|
|
3
|
+
|
|
4
|
+
declare module "module" {
|
|
5
|
+
export function createRequire(url: string | URL): (id: string) => unknown;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module "path" {
|
|
9
|
+
export function join(...paths: string[]): string;
|
|
10
|
+
export function dirname(p: string): string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module "fs" {
|
|
14
|
+
export function existsSync(path: string): boolean;
|
|
15
|
+
export function mkdirSync(
|
|
16
|
+
path: string,
|
|
17
|
+
options?: { recursive?: boolean },
|
|
18
|
+
): void;
|
|
19
|
+
export function readFileSync(path: string, encoding: string): string;
|
|
20
|
+
export function writeFileSync(
|
|
21
|
+
path: string,
|
|
22
|
+
data: string,
|
|
23
|
+
encoding?: string,
|
|
24
|
+
): void;
|
|
25
|
+
export function unlinkSync(path: string): void;
|
|
26
|
+
export function rmSync(
|
|
27
|
+
path: string,
|
|
28
|
+
options?: { recursive?: boolean; force?: boolean },
|
|
29
|
+
): void;
|
|
30
|
+
export function readdirSync(path: string): string[];
|
|
31
|
+
export function statSync(path: string): { isDirectory(): boolean };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module "os" {
|
|
35
|
+
export function tmpdir(): string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ImportMeta {
|
|
39
|
+
url: string;
|
|
40
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/**
|
|
3
|
+
* Collect validator code results into a file path map.
|
|
4
|
+
*
|
|
5
|
+
* Maps type names to their output file paths under .typokit/validators/.
|
|
6
|
+
*/
|
|
7
|
+
export declare function collectValidatorOutputs(
|
|
8
|
+
results: Array<Array<string>>,
|
|
9
|
+
): Record<string, string>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Compile route contracts from TypeScript files into a radix tree.
|
|
13
|
+
* Returns TypeScript source code for the compiled route table.
|
|
14
|
+
*/
|
|
15
|
+
export declare function compileRoutes(filePaths: Array<string>): string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Compute a SHA-256 content hash of the given file paths and their contents.
|
|
19
|
+
*
|
|
20
|
+
* Used for cache invalidation: if the hash matches a previous build, outputs
|
|
21
|
+
* can be reused without regeneration.
|
|
22
|
+
*/
|
|
23
|
+
export declare function computeContentHash(filePaths: Array<string>): string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Diff two schema versions and produce a migration draft.
|
|
27
|
+
*
|
|
28
|
+
* Compares old_types against new_types to detect added/removed/modified
|
|
29
|
+
* entities and fields. Generates SQL DDL stubs for the changes.
|
|
30
|
+
*/
|
|
31
|
+
export declare function diffSchemas(
|
|
32
|
+
oldTypes: Record<string, JsTypeMetadata>,
|
|
33
|
+
newTypes: Record<string, JsTypeMetadata>,
|
|
34
|
+
migrationName: string,
|
|
35
|
+
): JsMigrationDraft;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generate an OpenAPI 3.1.0 specification from route contracts and type definitions.
|
|
39
|
+
* Returns the OpenAPI spec as a JSON string.
|
|
40
|
+
*/
|
|
41
|
+
export declare function generateOpenApi(
|
|
42
|
+
routeFilePaths: Array<string>,
|
|
43
|
+
typeFilePaths: Array<string>,
|
|
44
|
+
): string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Generate contract test scaffolding from route contract files.
|
|
48
|
+
*
|
|
49
|
+
* Parses route contracts from the given files and generates TypeScript
|
|
50
|
+
* test stubs with describe/it blocks for each route.
|
|
51
|
+
*/
|
|
52
|
+
export declare function generateTestStubs(filePaths: Array<string>): string;
|
|
53
|
+
|
|
54
|
+
/** A migration draft (matches @typokit/types MigrationDraft) */
|
|
55
|
+
export interface JsMigrationDraft {
|
|
56
|
+
name: string;
|
|
57
|
+
sql: string;
|
|
58
|
+
destructive: boolean;
|
|
59
|
+
changes: Array<JsSchemaChange>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Result of running the full output pipeline */
|
|
63
|
+
export interface JsPipelineResult {
|
|
64
|
+
/** SHA-256 content hash of all input source files */
|
|
65
|
+
contentHash: string;
|
|
66
|
+
/** Extracted type metadata (SchemaTypeMap-compatible) */
|
|
67
|
+
types: Record<string, JsTypeMetadata>;
|
|
68
|
+
/** Compiled route table as TypeScript source */
|
|
69
|
+
compiledRoutes: string;
|
|
70
|
+
/** OpenAPI 3.1.0 spec as JSON string */
|
|
71
|
+
openapiSpec: string;
|
|
72
|
+
/** Generated contract test stubs as TypeScript source */
|
|
73
|
+
testStubs: string;
|
|
74
|
+
/** Validator inputs ready for Typia bridge callback */
|
|
75
|
+
validatorInputs: Array<JsTypeValidatorInput>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Property metadata matching @typokit/types PropertyMetadata shape */
|
|
79
|
+
export interface JsPropertyMetadata {
|
|
80
|
+
type: string;
|
|
81
|
+
optional: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A single schema change (matches @typokit/types SchemaChange) */
|
|
85
|
+
export interface JsSchemaChange {
|
|
86
|
+
type: string;
|
|
87
|
+
entity: string;
|
|
88
|
+
field?: string;
|
|
89
|
+
details?: Record<string, string>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Type metadata matching @typokit/types TypeMetadata shape */
|
|
93
|
+
export interface JsTypeMetadata {
|
|
94
|
+
name: string;
|
|
95
|
+
properties: Record<string, JsPropertyMetadata>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Validator input for a single type (passed to Typia bridge callback) */
|
|
99
|
+
export interface JsTypeValidatorInput {
|
|
100
|
+
name: string;
|
|
101
|
+
properties: Record<string, JsPropertyMetadata>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Parse TypeScript source files and extract type metadata.
|
|
106
|
+
*
|
|
107
|
+
* Returns a SchemaTypeMap (Record<string, TypeMetadata>) mapping type names
|
|
108
|
+
* to their extracted metadata including property types, optionality, and JSDoc tags.
|
|
109
|
+
*/
|
|
110
|
+
export declare function parseAndExtractTypes(
|
|
111
|
+
filePaths: Array<string>,
|
|
112
|
+
): Record<string, JsTypeMetadata>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Prepare type metadata for Typia validator generation.
|
|
116
|
+
*
|
|
117
|
+
* Converts parsed type metadata into a format suitable for passing
|
|
118
|
+
* to the @typokit/transform-typia bridge callback.
|
|
119
|
+
*/
|
|
120
|
+
export declare function prepareValidatorInputs(
|
|
121
|
+
typeFilePaths: Array<string>,
|
|
122
|
+
): Array<JsTypeValidatorInput>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Run the full output pipeline: parse types, compile routes, generate OpenAPI,
|
|
126
|
+
* generate test stubs, and prepare validator inputs.
|
|
127
|
+
*
|
|
128
|
+
* Returns all generated outputs plus a content hash for caching.
|
|
129
|
+
* Validators are returned as inputs — the caller should pass them to
|
|
130
|
+
* the Typia bridge callback and then call collectValidatorOutputs.
|
|
131
|
+
*/
|
|
132
|
+
export declare function runPipeline(
|
|
133
|
+
typeFilePaths: Array<string>,
|
|
134
|
+
routeFilePaths: Array<string>,
|
|
135
|
+
): JsPipelineResult;
|