@medusajs/http-types-generator 2.13.6-preview-20260402101111
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 +135 -0
- package/dist/__tests__/compatibility-checker.spec.d.ts +2 -0
- package/dist/__tests__/compatibility-checker.spec.d.ts.map +1 -0
- package/dist/__tests__/compatibility-checker.spec.js +231 -0
- package/dist/__tests__/compatibility-checker.spec.js.map +1 -0
- package/dist/__tests__/config.spec.d.ts +2 -0
- package/dist/__tests__/config.spec.d.ts.map +1 -0
- package/dist/__tests__/config.spec.js +78 -0
- package/dist/__tests__/config.spec.js.map +1 -0
- package/dist/__tests__/import-tracker.spec.d.ts +2 -0
- package/dist/__tests__/import-tracker.spec.d.ts.map +1 -0
- package/dist/__tests__/import-tracker.spec.js +25 -0
- package/dist/__tests__/import-tracker.spec.js.map +1 -0
- package/dist/__tests__/name-classifier.spec.d.ts +2 -0
- package/dist/__tests__/name-classifier.spec.d.ts.map +1 -0
- package/dist/__tests__/name-classifier.spec.js +77 -0
- package/dist/__tests__/name-classifier.spec.js.map +1 -0
- package/dist/__tests__/name-registry.spec.d.ts +2 -0
- package/dist/__tests__/name-registry.spec.d.ts.map +1 -0
- package/dist/__tests__/name-registry.spec.js +67 -0
- package/dist/__tests__/name-registry.spec.js.map +1 -0
- package/dist/__tests__/path-mapper.spec.d.ts +2 -0
- package/dist/__tests__/path-mapper.spec.d.ts.map +1 -0
- package/dist/__tests__/path-mapper.spec.js +98 -0
- package/dist/__tests__/path-mapper.spec.js.map +1 -0
- package/dist/__tests__/type-emitter.spec.d.ts +2 -0
- package/dist/__tests__/type-emitter.spec.d.ts.map +1 -0
- package/dist/__tests__/type-emitter.spec.js +173 -0
- package/dist/__tests__/type-emitter.spec.js.map +1 -0
- package/dist/__tests__/type-pipeline.spec.d.ts +2 -0
- package/dist/__tests__/type-pipeline.spec.d.ts.map +1 -0
- package/dist/__tests__/type-pipeline.spec.js +239 -0
- package/dist/__tests__/type-pipeline.spec.js.map +1 -0
- package/dist/__tests__/utils/ts-utils.d.ts +22 -0
- package/dist/__tests__/utils/ts-utils.d.ts.map +1 -0
- package/dist/__tests__/utils/ts-utils.js +66 -0
- package/dist/__tests__/utils/ts-utils.js.map +1 -0
- package/dist/commands/generate.d.ts +10 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +215 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/validate.d.ts +14 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +201 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/config/index.d.ts +52 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +119 -0
- package/dist/config/index.js.map +1 -0
- package/dist/core/compatibility-checker.d.ts +92 -0
- package/dist/core/compatibility-checker.d.ts.map +1 -0
- package/dist/core/compatibility-checker.js +415 -0
- package/dist/core/compatibility-checker.js.map +1 -0
- package/dist/core/import-tracker.d.ts +11 -0
- package/dist/core/import-tracker.d.ts.map +1 -0
- package/dist/core/import-tracker.js +17 -0
- package/dist/core/import-tracker.js.map +1 -0
- package/dist/core/program-factory.d.ts +23 -0
- package/dist/core/program-factory.d.ts.map +1 -0
- package/dist/core/program-factory.js +80 -0
- package/dist/core/program-factory.js.map +1 -0
- package/dist/core/schema-extractor.d.ts +73 -0
- package/dist/core/schema-extractor.d.ts.map +1 -0
- package/dist/core/schema-extractor.js +205 -0
- package/dist/core/schema-extractor.js.map +1 -0
- package/dist/core/type-emitter.d.ts +73 -0
- package/dist/core/type-emitter.d.ts.map +1 -0
- package/dist/core/type-emitter.js +246 -0
- package/dist/core/type-emitter.js.map +1 -0
- package/dist/core/type-resolver.d.ts +64 -0
- package/dist/core/type-resolver.d.ts.map +1 -0
- package/dist/core/type-resolver.js +163 -0
- package/dist/core/type-resolver.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/mapping/name-classifier.d.ts +34 -0
- package/dist/mapping/name-classifier.d.ts.map +1 -0
- package/dist/mapping/name-classifier.js +72 -0
- package/dist/mapping/name-classifier.js.map +1 -0
- package/dist/mapping/name-registry.d.ts +54 -0
- package/dist/mapping/name-registry.d.ts.map +1 -0
- package/dist/mapping/name-registry.js +251 -0
- package/dist/mapping/name-registry.js.map +1 -0
- package/dist/mapping/path-mapper.d.ts +62 -0
- package/dist/mapping/path-mapper.d.ts.map +1 -0
- package/dist/mapping/path-mapper.js +116 -0
- package/dist/mapping/path-mapper.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/file-merger.d.ts +47 -0
- package/dist/utils/file-merger.d.ts.map +1 -0
- package/dist/utils/file-merger.js +164 -0
- package/dist/utils/file-merger.js.map +1 -0
- package/dist/utils/formatter.d.ts +12 -0
- package/dist/utils/formatter.d.ts.map +1 -0
- package/dist/utils/formatter.js +31 -0
- package/dist/utils/formatter.js.map +1 -0
- package/dist/utils/fs-helpers.d.ts +21 -0
- package/dist/utils/fs-helpers.d.ts.map +1 -0
- package/dist/utils/fs-helpers.js +42 -0
- package/dist/utils/fs-helpers.js.map +1 -0
- package/dist/utils/index-manager.d.ts +24 -0
- package/dist/utils/index-manager.d.ts.map +1 -0
- package/dist/utils/index-manager.js +95 -0
- package/dist/utils/index-manager.js.map +1 -0
- package/dist/utils/ts-helpers.d.ts +87 -0
- package/dist/utils/ts-helpers.d.ts.map +1 -0
- package/dist/utils/ts-helpers.js +216 -0
- package/dist/utils/ts-helpers.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-tracker.d.ts","sourceRoot":"","sources":["../../src/core/import-tracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,aAAa;IACxB,eAAe,UAAQ;IACvB,iBAAiB,UAAQ;IACzB,mBAAmB,UAAQ;IAC3B,gBAAgB,UAAQ;CACzB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportTracker = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Tracks which external types are referenced in the emitted interfaces,
|
|
6
|
+
* so we can generate the correct import statements for the output file.
|
|
7
|
+
*/
|
|
8
|
+
class ImportTracker {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.needsFindParams = false;
|
|
11
|
+
this.needsSelectParams = false;
|
|
12
|
+
this.needsBaseFilterable = false;
|
|
13
|
+
this.needsOperatorMap = false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ImportTracker = ImportTracker;
|
|
17
|
+
//# sourceMappingURL=import-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-tracker.js","sourceRoot":"","sources":["../../src/core/import-tracker.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,aAAa;IAA1B;QACE,oBAAe,GAAG,KAAK,CAAA;QACvB,sBAAiB,GAAG,KAAK,CAAA;QACzB,wBAAmB,GAAG,KAAK,CAAA;QAC3B,qBAAgB,GAAG,KAAK,CAAA;IAC1B,CAAC;CAAA;AALD,sCAKC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export interface ProgramContext {
|
|
3
|
+
program: ts.Program;
|
|
4
|
+
checker: ts.TypeChecker;
|
|
5
|
+
}
|
|
6
|
+
export declare class ProgramFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Reads and parses the project's TypeScript compiler options from the
|
|
9
|
+
* tsconfig file specified in config (defaults to `tsconfig.json`).
|
|
10
|
+
*/
|
|
11
|
+
private static getBaseCompilerOptions;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a TypeScript program and type checker from a list of source files.
|
|
14
|
+
* All files are included in a single program to share one TypeChecker instance,
|
|
15
|
+
* which is the most expensive part of TypeScript compilation.
|
|
16
|
+
*
|
|
17
|
+
* @param rootFiles - Absolute paths to all files to include as root files.
|
|
18
|
+
* @param virtualFiles - Optional in-memory files (filename → content) for
|
|
19
|
+
* validation assertions without writing to disk.
|
|
20
|
+
*/
|
|
21
|
+
static create(rootFiles: string[], virtualFiles?: Map<string, string>): ProgramContext;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=program-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program-factory.d.ts","sourceRoot":"","sources":["../../src/core/program-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAK3B,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,EAAE,CAAC,OAAO,CAAA;IACnB,OAAO,EAAE,EAAE,CAAC,WAAW,CAAA;CACxB;AAED,qBAAa,cAAc;IACzB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAkCrC;;;;;;;;OAQG;IACH,MAAM,CAAC,MAAM,CACX,SAAS,EAAE,MAAM,EAAE,EACnB,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,cAAc;CA0ClB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ProgramFactory = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_helpers_1 = require("../utils/fs-helpers");
|
|
10
|
+
const config_1 = require("../config");
|
|
11
|
+
class ProgramFactory {
|
|
12
|
+
/**
|
|
13
|
+
* Reads and parses the project's TypeScript compiler options from the
|
|
14
|
+
* tsconfig file specified in config (defaults to `tsconfig.json`).
|
|
15
|
+
*/
|
|
16
|
+
static getBaseCompilerOptions() {
|
|
17
|
+
const projectRoot = fs_helpers_1.FsHelpers.getProjectRoot();
|
|
18
|
+
const tsconfigBasePath = path_1.default.join(projectRoot, config_1.Config.get().tsconfig);
|
|
19
|
+
const configStr = typescript_1.default.sys.readFile(tsconfigBasePath);
|
|
20
|
+
if (!configStr) {
|
|
21
|
+
console.warn(`Warning: could not read ${tsconfigBasePath}, using default compiler options`);
|
|
22
|
+
return {
|
|
23
|
+
target: typescript_1.default.ScriptTarget.ES2021,
|
|
24
|
+
module: typescript_1.default.ModuleKind.Node16,
|
|
25
|
+
moduleResolution: typescript_1.default.ModuleResolutionKind.Node16,
|
|
26
|
+
esModuleInterop: true,
|
|
27
|
+
skipLibCheck: true,
|
|
28
|
+
strictNullChecks: true,
|
|
29
|
+
resolveJsonModule: true,
|
|
30
|
+
allowJs: true,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const parsed = typescript_1.default.parseJsonConfigFileContent(JSON.parse(configStr), typescript_1.default.sys, projectRoot);
|
|
34
|
+
return {
|
|
35
|
+
...parsed.options,
|
|
36
|
+
noEmit: true,
|
|
37
|
+
skipLibCheck: true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a TypeScript program and type checker from a list of source files.
|
|
42
|
+
* All files are included in a single program to share one TypeChecker instance,
|
|
43
|
+
* which is the most expensive part of TypeScript compilation.
|
|
44
|
+
*
|
|
45
|
+
* @param rootFiles - Absolute paths to all files to include as root files.
|
|
46
|
+
* @param virtualFiles - Optional in-memory files (filename → content) for
|
|
47
|
+
* validation assertions without writing to disk.
|
|
48
|
+
*/
|
|
49
|
+
static create(rootFiles, virtualFiles) {
|
|
50
|
+
const compilerOptions = ProgramFactory.getBaseCompilerOptions();
|
|
51
|
+
let program;
|
|
52
|
+
if (virtualFiles && virtualFiles.size > 0) {
|
|
53
|
+
const defaultHost = typescript_1.default.createCompilerHost(compilerOptions);
|
|
54
|
+
const customHost = {
|
|
55
|
+
...defaultHost,
|
|
56
|
+
getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile) {
|
|
57
|
+
if (virtualFiles.has(fileName)) {
|
|
58
|
+
return typescript_1.default.createSourceFile(fileName, virtualFiles.get(fileName), languageVersion);
|
|
59
|
+
}
|
|
60
|
+
return defaultHost.getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
|
|
61
|
+
},
|
|
62
|
+
fileExists(fileName) {
|
|
63
|
+
return virtualFiles.has(fileName) || defaultHost.fileExists(fileName);
|
|
64
|
+
},
|
|
65
|
+
readFile(fileName) {
|
|
66
|
+
return virtualFiles.get(fileName) ?? defaultHost.readFile(fileName);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
const allFiles = [...rootFiles, ...virtualFiles.keys()];
|
|
70
|
+
program = typescript_1.default.createProgram(allFiles, compilerOptions, customHost);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
program = typescript_1.default.createProgram(rootFiles, compilerOptions);
|
|
74
|
+
}
|
|
75
|
+
const checker = program.getTypeChecker();
|
|
76
|
+
return { program, checker };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.ProgramFactory = ProgramFactory;
|
|
80
|
+
//# sourceMappingURL=program-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program-factory.js","sourceRoot":"","sources":["../../src/core/program-factory.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA2B;AAC3B,gDAAuB;AACvB,oDAA+C;AAC/C,sCAAkC;AAOlC,MAAa,cAAc;IACzB;;;OAGG;IACK,MAAM,CAAC,sBAAsB;QACnC,MAAM,WAAW,GAAG,sBAAS,CAAC,cAAc,EAAE,CAAA;QAC9C,MAAM,gBAAgB,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,eAAM,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAA;QAEtE,MAAM,SAAS,GAAG,oBAA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,EACR,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAE,EAC3B,eAAe,CAChB,CAAA;oBACH,CAAC;oBACD,OAAO,WAAW,CAAC,aAAa,CAC9B,QAAQ,EACR,eAAe,EACf,OAAO,EACP,yBAAyB,CAC1B,CAAA;gBACH,CAAC;gBACD,UAAU,CAAC,QAAQ;oBACjB,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;gBACvE,CAAC;gBACD,QAAQ,CAAC,QAAQ;oBACf,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;gBACrE,CAAC;aACF,CAAA;YAED,MAAM,QAAQ,GAAG,CAAC,GAAG,SAAS,EAAE,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,CAAA;YACvD,OAAO,GAAG,oBAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,eAAe,EAAE,UAAU,CAAC,CAAA;QACnE,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,oBAAE,CAAC,aAAa,CAAC,SAAS,EAAE,eAAe,CAAC,CAAA;QACxD,CAAC;QAED,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAA;QACxC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;IAC7B,CAAC;CACF;AA7FD,wCA6FC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export interface ExtractedSchema {
|
|
3
|
+
/** The export name from the validator file (e.g., "AdminCreateCustomer") */
|
|
4
|
+
exportName: string;
|
|
5
|
+
/**
|
|
6
|
+
* The HTTP type name to use in the output file. Defaults to `exportName`
|
|
7
|
+
* unless overridden by a `@http-type-name` tag or the name registry.
|
|
8
|
+
*/
|
|
9
|
+
httpTypeName: string;
|
|
10
|
+
/** The Zod schema TypeScript type (the variable's declared type) */
|
|
11
|
+
zodType: ts.Type;
|
|
12
|
+
/**
|
|
13
|
+
* For `WithAdditionalData`-wrapped schemas, this is the inner schema's
|
|
14
|
+
* type (the first argument passed to `WithAdditionalData`).
|
|
15
|
+
* When present, use this for type resolution instead of `zodType`.
|
|
16
|
+
*/
|
|
17
|
+
innerSchemaType?: ts.Type;
|
|
18
|
+
/** Whether the schema has a `.transform()` applied (ZodEffects) */
|
|
19
|
+
hasTransform: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* For schemas that use `applyAndAndOrOperators(baseFieldsSchema)`, this is
|
|
22
|
+
* the resolved type of `baseFieldsSchema`. The circular lazy types in
|
|
23
|
+
* `applyAndAndOrOperators` break TypeScript's type resolution for the
|
|
24
|
+
* merged schema, so we fall back to using the base fields schema's type.
|
|
25
|
+
*/
|
|
26
|
+
baseFieldsType?: ts.Type;
|
|
27
|
+
/** Whether the schema's call chain includes `createFindParams()` */
|
|
28
|
+
hasFindParamsInChain: boolean;
|
|
29
|
+
/** Whether the schema's call chain includes `createSelectParams()` (but NOT createFindParams) */
|
|
30
|
+
hasSelectParamsInChain: boolean;
|
|
31
|
+
/** The source node for diagnostic reporting */
|
|
32
|
+
node: ts.VariableDeclaration;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extracts exported Zod schemas from TypeScript source files.
|
|
36
|
+
*/
|
|
37
|
+
export declare class SchemaExtractor {
|
|
38
|
+
private readonly checker;
|
|
39
|
+
/**
|
|
40
|
+
* Names of wrapper/utility functions that produce function types rather than
|
|
41
|
+
* Zod schema types directly.
|
|
42
|
+
*/
|
|
43
|
+
private static readonly ADDITIONAL_DATA_WRAPPERS;
|
|
44
|
+
constructor(checker: ts.TypeChecker);
|
|
45
|
+
/**
|
|
46
|
+
* Extracts all exported Zod schemas from a TypeScript source file.
|
|
47
|
+
*
|
|
48
|
+
* Handles the following patterns:
|
|
49
|
+
* - `export const AdminCreateCustomer = z.object({...})`
|
|
50
|
+
* - `export const AdminCreateCustomer = WithAdditionalData(CreateCustomer)`
|
|
51
|
+
* - `export const AdminGetProductsParams = createFindParams().merge(...).transform(...)`
|
|
52
|
+
*/
|
|
53
|
+
extract(sourceFile: ts.SourceFile): ExtractedSchema[];
|
|
54
|
+
/**
|
|
55
|
+
* Builds a symbol table of all variable declarations in this file.
|
|
56
|
+
*/
|
|
57
|
+
private buildLocalSymbolTypes;
|
|
58
|
+
/**
|
|
59
|
+
* Builds a map from WithAdditionalData binding name → its resolved inner schema type.
|
|
60
|
+
*/
|
|
61
|
+
private buildLocalInnerSchemaTypes;
|
|
62
|
+
/**
|
|
63
|
+
* Determines whether the initializer of a variable declaration calls a
|
|
64
|
+
* `WithAdditionalData`-style wrapper function.
|
|
65
|
+
*/
|
|
66
|
+
private isAdditionalDataWrapper;
|
|
67
|
+
/**
|
|
68
|
+
* Finds the first argument name passed to `applyAndAndOrOperators(...)` anywhere
|
|
69
|
+
* in the call chain of the given initializer node.
|
|
70
|
+
*/
|
|
71
|
+
private findApplyAndAndOrOperatorsArg;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=schema-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-extractor.d.ts","sourceRoot":"","sources":["../../src/core/schema-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAI3B,MAAM,WAAW,eAAe;IAC9B,4EAA4E;IAC5E,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB,oEAAoE;IACpE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAA;IAChB;;;;OAIG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC,IAAI,CAAA;IACzB,mEAAmE;IACnE,YAAY,EAAE,OAAO,CAAA;IACrB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,EAAE,CAAC,IAAI,CAAA;IACxB,oEAAoE;IACpE,oBAAoB,EAAE,OAAO,CAAA;IAC7B,iGAAiG;IACjG,sBAAsB,EAAE,OAAO,CAAA;IAC/B,+CAA+C;IAC/C,IAAI,EAAE,EAAE,CAAC,mBAAmB,CAAA;CAC7B;AAED;;GAEG;AACH,qBAAa,eAAe;IASd,OAAO,CAAC,QAAQ,CAAC,OAAO;IARpC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAE9C;gBAE2B,OAAO,EAAE,EAAE,CAAC,WAAW;IAEpD;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,eAAe,EAAE;IA0HrD;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAqB7B;;OAEG;IACH,OAAO,CAAC,0BAA0B;IA4BlC;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAU/B;;;OAGG;IACH,OAAO,CAAC,6BAA6B;CA6BtC"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SchemaExtractor = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const ts_helpers_1 = require("../utils/ts-helpers");
|
|
9
|
+
const name_classifier_1 = require("../mapping/name-classifier");
|
|
10
|
+
/**
|
|
11
|
+
* Extracts exported Zod schemas from TypeScript source files.
|
|
12
|
+
*/
|
|
13
|
+
class SchemaExtractor {
|
|
14
|
+
constructor(checker) {
|
|
15
|
+
this.checker = checker;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extracts all exported Zod schemas from a TypeScript source file.
|
|
19
|
+
*
|
|
20
|
+
* Handles the following patterns:
|
|
21
|
+
* - `export const AdminCreateCustomer = z.object({...})`
|
|
22
|
+
* - `export const AdminCreateCustomer = WithAdditionalData(CreateCustomer)`
|
|
23
|
+
* - `export const AdminGetProductsParams = createFindParams().merge(...).transform(...)`
|
|
24
|
+
*/
|
|
25
|
+
extract(sourceFile) {
|
|
26
|
+
const results = [];
|
|
27
|
+
const localSymbolTypes = this.buildLocalSymbolTypes(sourceFile);
|
|
28
|
+
const localInnerSchemaTypes = this.buildLocalInnerSchemaTypes(sourceFile, localSymbolTypes);
|
|
29
|
+
typescript_1.default.forEachChild(sourceFile, (node) => {
|
|
30
|
+
if (!typescript_1.default.isVariableStatement(node) || !ts_helpers_1.TsHelpers.isExported(node)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const decl = ts_helpers_1.TsHelpers.getVariableDeclaration(node);
|
|
34
|
+
if (!decl || !typescript_1.default.isIdentifier(decl.name)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const exportName = decl.name.text;
|
|
38
|
+
if (name_classifier_1.NameClassifier.classify(exportName) === "skip") {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const httpTypeNameOverride = ts_helpers_1.TsHelpers.readHttpTypeNameTag(node, sourceFile);
|
|
42
|
+
const httpTypeName = httpTypeNameOverride ?? exportName;
|
|
43
|
+
const zodType = this.checker.getTypeAtLocation(decl);
|
|
44
|
+
// Case 1: WithAdditionalData wrapper → resolve the inner schema
|
|
45
|
+
if (this.isAdditionalDataWrapper(decl)) {
|
|
46
|
+
const innerName = ts_helpers_1.TsHelpers.getFirstCallArgName(decl);
|
|
47
|
+
const innerType = innerName
|
|
48
|
+
? localSymbolTypes.get(innerName)
|
|
49
|
+
: undefined;
|
|
50
|
+
if (innerType && ts_helpers_1.TsHelpers.isZodType(innerType)) {
|
|
51
|
+
results.push({
|
|
52
|
+
exportName,
|
|
53
|
+
httpTypeName,
|
|
54
|
+
zodType: innerType,
|
|
55
|
+
innerSchemaType: innerType,
|
|
56
|
+
hasTransform: false,
|
|
57
|
+
hasFindParamsInChain: false,
|
|
58
|
+
hasSelectParamsInChain: false,
|
|
59
|
+
node: decl,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Case 2: Function type — either an alias of a WithAdditionalData result
|
|
65
|
+
// or some other non-schema export.
|
|
66
|
+
if (ts_helpers_1.TsHelpers.isFunctionType(zodType)) {
|
|
67
|
+
if (decl.initializer && typescript_1.default.isIdentifier(decl.initializer)) {
|
|
68
|
+
const innerType = localInnerSchemaTypes.get(decl.initializer.text);
|
|
69
|
+
if (innerType) {
|
|
70
|
+
results.push({
|
|
71
|
+
exportName,
|
|
72
|
+
httpTypeName,
|
|
73
|
+
zodType: innerType,
|
|
74
|
+
innerSchemaType: innerType,
|
|
75
|
+
hasTransform: false,
|
|
76
|
+
hasFindParamsInChain: false,
|
|
77
|
+
hasSelectParamsInChain: false,
|
|
78
|
+
node: decl,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Case 3: Standard Zod schema
|
|
85
|
+
if (!ts_helpers_1.TsHelpers.isZodType(zodType)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const hasTransform = ts_helpers_1.TsHelpers.isZodEffects(this.checker, zodType);
|
|
89
|
+
let baseFieldsType;
|
|
90
|
+
let hasFindParamsInChain = false;
|
|
91
|
+
let hasSelectParamsInChain = false;
|
|
92
|
+
if (decl.initializer) {
|
|
93
|
+
hasFindParamsInChain = ts_helpers_1.TsHelpers.callChainIncludes(decl.initializer, "createFindParams");
|
|
94
|
+
hasSelectParamsInChain =
|
|
95
|
+
!hasFindParamsInChain &&
|
|
96
|
+
ts_helpers_1.TsHelpers.callChainIncludes(decl.initializer, "createSelectParams");
|
|
97
|
+
const baseFieldsName = this.findApplyAndAndOrOperatorsArg(decl.initializer);
|
|
98
|
+
if (baseFieldsName) {
|
|
99
|
+
baseFieldsType = localSymbolTypes.get(baseFieldsName);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
results.push({
|
|
103
|
+
exportName,
|
|
104
|
+
httpTypeName,
|
|
105
|
+
zodType,
|
|
106
|
+
hasTransform,
|
|
107
|
+
baseFieldsType,
|
|
108
|
+
hasFindParamsInChain,
|
|
109
|
+
hasSelectParamsInChain,
|
|
110
|
+
node: decl,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
return results;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Builds a symbol table of all variable declarations in this file.
|
|
117
|
+
*/
|
|
118
|
+
buildLocalSymbolTypes(sourceFile) {
|
|
119
|
+
const localSymbolTypes = new Map();
|
|
120
|
+
typescript_1.default.forEachChild(sourceFile, (node) => {
|
|
121
|
+
if (typescript_1.default.isVariableStatement(node) &&
|
|
122
|
+
node.declarationList.declarations.length > 0) {
|
|
123
|
+
const decl = node.declarationList.declarations[0];
|
|
124
|
+
if (typescript_1.default.isIdentifier(decl.name)) {
|
|
125
|
+
const type = this.checker.getTypeAtLocation(decl);
|
|
126
|
+
localSymbolTypes.set(decl.name.text, type);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return localSymbolTypes;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Builds a map from WithAdditionalData binding name → its resolved inner schema type.
|
|
134
|
+
*/
|
|
135
|
+
buildLocalInnerSchemaTypes(sourceFile, localSymbolTypes) {
|
|
136
|
+
const localInnerSchemaTypes = new Map();
|
|
137
|
+
typescript_1.default.forEachChild(sourceFile, (node) => {
|
|
138
|
+
if (typescript_1.default.isVariableStatement(node) &&
|
|
139
|
+
node.declarationList.declarations.length > 0) {
|
|
140
|
+
const decl = node.declarationList.declarations[0];
|
|
141
|
+
if (!typescript_1.default.isIdentifier(decl.name))
|
|
142
|
+
return;
|
|
143
|
+
if (!this.isAdditionalDataWrapper(decl))
|
|
144
|
+
return;
|
|
145
|
+
const innerName = ts_helpers_1.TsHelpers.getFirstCallArgName(decl);
|
|
146
|
+
const innerType = innerName
|
|
147
|
+
? localSymbolTypes.get(innerName)
|
|
148
|
+
: undefined;
|
|
149
|
+
if (innerType && ts_helpers_1.TsHelpers.isZodType(innerType)) {
|
|
150
|
+
localInnerSchemaTypes.set(decl.name.text, innerType);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return localInnerSchemaTypes;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Determines whether the initializer of a variable declaration calls a
|
|
158
|
+
* `WithAdditionalData`-style wrapper function.
|
|
159
|
+
*/
|
|
160
|
+
isAdditionalDataWrapper(node) {
|
|
161
|
+
const initializer = node.initializer;
|
|
162
|
+
if (!initializer || !typescript_1.default.isCallExpression(initializer)) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
const callee = initializer.expression;
|
|
166
|
+
const calleeName = typescript_1.default.isIdentifier(callee) ? callee.text : "";
|
|
167
|
+
return SchemaExtractor.ADDITIONAL_DATA_WRAPPERS.has(calleeName);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Finds the first argument name passed to `applyAndAndOrOperators(...)` anywhere
|
|
171
|
+
* in the call chain of the given initializer node.
|
|
172
|
+
*/
|
|
173
|
+
findApplyAndAndOrOperatorsArg(node, depth = 0) {
|
|
174
|
+
if (depth > 10 || !typescript_1.default.isCallExpression(node)) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
const expr = node.expression;
|
|
178
|
+
if (typescript_1.default.isIdentifier(expr) && expr.text === "applyAndAndOrOperators") {
|
|
179
|
+
const firstArg = node.arguments[0];
|
|
180
|
+
if (firstArg && typescript_1.default.isIdentifier(firstArg)) {
|
|
181
|
+
return firstArg.text;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const fromCallee = typescript_1.default.isPropertyAccessExpression(expr)
|
|
185
|
+
? this.findApplyAndAndOrOperatorsArg(expr.expression, depth + 1)
|
|
186
|
+
: this.findApplyAndAndOrOperatorsArg(expr, depth + 1);
|
|
187
|
+
if (fromCallee)
|
|
188
|
+
return fromCallee;
|
|
189
|
+
for (const arg of node.arguments) {
|
|
190
|
+
const fromArg = this.findApplyAndAndOrOperatorsArg(arg, depth + 1);
|
|
191
|
+
if (fromArg)
|
|
192
|
+
return fromArg;
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.SchemaExtractor = SchemaExtractor;
|
|
198
|
+
/**
|
|
199
|
+
* Names of wrapper/utility functions that produce function types rather than
|
|
200
|
+
* Zod schema types directly.
|
|
201
|
+
*/
|
|
202
|
+
SchemaExtractor.ADDITIONAL_DATA_WRAPPERS = new Set([
|
|
203
|
+
"WithAdditionalData",
|
|
204
|
+
]);
|
|
205
|
+
//# sourceMappingURL=schema-extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-extractor.js","sourceRoot":"","sources":["../../src/core/schema-extractor.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA2B;AAC3B,oDAA+C;AAC/C,gEAA2D;AAmC3D;;GAEG;AACH,MAAa,eAAe;IAS1B,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;IAAG,CAAC;IAExD;;;;;;;OAOG;IACH,OAAO,CAAC,UAAyB;QAC/B,MAAM,OAAO,GAAsB,EAAE,CAAA;QAErC,MAAM,gBAAgB,GAAG,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAA;QAC/D,MAAM,qBAAqB,GAAG,IAAI,CAAC,0BAA0B,CAC3D,UAAU,EACV,gBAAgB,CACjB,CAAA;QAED,oBAAE,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;YACnC,IAAI,CAAC,oBAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjE,OAAM;YACR,CAAC;YAED,MAAM,IAAI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from "./import-tracker";
|
|
4
|
+
export interface EmittedInterface {
|
|
5
|
+
name: string;
|
|
6
|
+
code: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Emits TypeScript interface declarations from resolved Zod schema types and
|
|
10
|
+
* assembles complete output files with the correct import statements.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TypeEmitter {
|
|
13
|
+
private readonly checker;
|
|
14
|
+
constructor(checker: ts.TypeChecker);
|
|
15
|
+
/**
|
|
16
|
+
* Emits a TypeScript interface declaration as a string from a resolved schema type.
|
|
17
|
+
*
|
|
18
|
+
* @param interfaceName - The name for the generated interface
|
|
19
|
+
* @param resolved - The resolved schema type info
|
|
20
|
+
* @param importTracker - Mutable tracker that records which imports are needed
|
|
21
|
+
*/
|
|
22
|
+
emitInterface(interfaceName: string, resolved: ResolvedSchemaType, importTracker: ImportTracker): string;
|
|
23
|
+
/**
|
|
24
|
+
* Assembles a complete TypeScript file from a list of emitted interfaces.
|
|
25
|
+
*
|
|
26
|
+
* @param interfaces - The interfaces to include
|
|
27
|
+
* @param importTracker - What imports are needed
|
|
28
|
+
* @param outputFile - Absolute path to the file being written (used to compute relative imports)
|
|
29
|
+
*/
|
|
30
|
+
static assembleFile(interfaces: EmittedInterface[], importTracker: ImportTracker, outputFile: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a `ts.PropertySignature` for an interface member from a `PropertyInfo`.
|
|
33
|
+
*/
|
|
34
|
+
private createPropertySignature;
|
|
35
|
+
/**
|
|
36
|
+
* Converts a TypeScript `ts.Type` to a `ts.TypeNode` using the type checker.
|
|
37
|
+
* Falls back to `any` if conversion fails.
|
|
38
|
+
*/
|
|
39
|
+
private typeToTypeNode;
|
|
40
|
+
/**
|
|
41
|
+
* Resolves an import source to an import specifier string.
|
|
42
|
+
* If `target` is a bare package name (starts with `@` or contains no `/` after
|
|
43
|
+
* stripping scope), it is returned as-is. Otherwise it is treated as a
|
|
44
|
+
* project-root-relative path and converted to a relative import path.
|
|
45
|
+
*/
|
|
46
|
+
private static resolveImportPath;
|
|
47
|
+
private static createPrinter;
|
|
48
|
+
private static createDummySourceFile;
|
|
49
|
+
/**
|
|
50
|
+
* Generates a `ts.TypeNode` for an OperatorMap field.
|
|
51
|
+
*/
|
|
52
|
+
private static makeOperatorMapTypeNode;
|
|
53
|
+
/**
|
|
54
|
+
* Creates heritage clauses (extends ...) for an interface declaration.
|
|
55
|
+
*/
|
|
56
|
+
private static createHeritageClauses;
|
|
57
|
+
/**
|
|
58
|
+
* Generates the import statements for a file based on what types were referenced.
|
|
59
|
+
*/
|
|
60
|
+
private static generateImports;
|
|
61
|
+
/**
|
|
62
|
+
* Walks up the directory tree from `startPath` to find the nearest `package.json`
|
|
63
|
+
* and returns its `name` field, or `undefined` if none is found.
|
|
64
|
+
*/
|
|
65
|
+
private static findPackageName;
|
|
66
|
+
/**
|
|
67
|
+
* Scans `content` for inline TypeScript import expressions, extracts them,
|
|
68
|
+
* and replaces each with just the type name. Returns the cleaned content plus
|
|
69
|
+
* a map of importSource → Set<typeName> for import statements to prepend.
|
|
70
|
+
*/
|
|
71
|
+
private static hoistInlineImports;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=type-emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-emitter.d.ts","sourceRoot":"","sources":["../../src/core/type-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,iBAAiB,CAAA;AAIvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED;;;GAGG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,EAAE,CAAC,WAAW;IAEpD;;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