zinfer 0.2.6 → 1.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/brand-detector.d.ts +2 -21
- package/dist/core/brand-detector.d.ts.map +1 -1
- package/dist/core/brand-detector.js +40 -67
- package/dist/core/brand-detector.js.map +1 -1
- package/dist/core/config-loader.d.ts.map +1 -1
- package/dist/core/description-extractor.d.ts +0 -14
- package/dist/core/description-extractor.d.ts.map +1 -1
- package/dist/core/description-extractor.js +7 -71
- package/dist/core/description-extractor.js.map +1 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +1 -28
- package/dist/core/errors.js.map +1 -1
- package/dist/core/extractor.d.ts +3 -37
- package/dist/core/extractor.d.ts.map +1 -1
- package/dist/core/extractor.js +42 -178
- package/dist/core/extractor.js.map +1 -1
- package/dist/core/file-resolver.d.ts.map +1 -1
- package/dist/core/file-resolver.js.map +1 -1
- package/dist/core/getter-resolver.d.ts +2 -46
- package/dist/core/getter-resolver.d.ts.map +1 -1
- package/dist/core/getter-resolver.js +33 -85
- package/dist/core/getter-resolver.js.map +1 -1
- package/dist/core/import-resolver.d.ts +10 -30
- package/dist/core/import-resolver.d.ts.map +1 -1
- package/dist/core/import-resolver.js +59 -112
- package/dist/core/import-resolver.js.map +1 -1
- package/dist/core/index.d.ts +0 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +0 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/name-mapper.d.ts.map +1 -1
- package/dist/core/name-mapper.js.map +1 -1
- package/dist/core/schema-detector.d.ts +10 -30
- package/dist/core/schema-detector.d.ts.map +1 -1
- package/dist/core/schema-detector.js +60 -82
- package/dist/core/schema-detector.js.map +1 -1
- package/dist/core/schema-reference-analyzer.d.ts +2 -56
- package/dist/core/schema-reference-analyzer.d.ts.map +1 -1
- package/dist/core/schema-reference-analyzer.js +89 -137
- package/dist/core/schema-reference-analyzer.js.map +1 -1
- package/dist/core/test-generator.d.ts.map +1 -1
- package/dist/core/test-generator.js.map +1 -1
- package/dist/core/ts-host.d.ts +38 -0
- package/dist/core/ts-host.d.ts.map +1 -0
- package/dist/core/ts-host.js +2 -0
- package/dist/core/ts-host.js.map +1 -0
- package/dist/core/tsgo-ast-utils.d.ts +12 -0
- package/dist/core/tsgo-ast-utils.d.ts.map +1 -0
- package/dist/core/tsgo-ast-utils.js +43 -0
- package/dist/core/tsgo-ast-utils.js.map +1 -0
- package/dist/core/tsgo-host.d.ts +54 -0
- package/dist/core/tsgo-host.d.ts.map +1 -0
- package/dist/core/tsgo-host.js +267 -0
- package/dist/core/tsgo-host.js.map +1 -0
- package/dist/core/type-printer.d.ts.map +1 -1
- package/dist/core/type-printer.js +8 -13
- package/dist/core/type-printer.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
package/dist/core/index.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
export { NORMALIZE_TYPE_DEFINITION, createTempTypeAlias } from "./normalizer.js";
|
|
2
2
|
export { ZodTypeExtractor, type ExtractOptions } from "./extractor.js";
|
|
3
3
|
export { formatResult, formatInputOnly, formatOutputOnly, formatAsDeclaration, formatMultipleAsDeclarations, generateDeclarationFile, relativizeImportPaths, type PrintOptions, } from "./type-printer.js";
|
|
4
|
-
export { SchemaDetector } from "./schema-detector.js";
|
|
5
4
|
export { NameMapper, createNameMapper } from "./name-mapper.js";
|
|
6
5
|
export { FileResolver } from "./file-resolver.js";
|
|
7
6
|
export { DescriptionExtractor } from "./description-extractor.js";
|
|
8
7
|
export { ZinferError, NoSchemasFoundError, NoFilesMatchedError, InvalidOptionError, formatError, } from "./errors.js";
|
|
9
8
|
export { setVerbose, logVerbose, logDebugError, logProgress } from "./logger.js";
|
|
10
9
|
export { ConfigLoader, defineConfig, type ZinferConfig, type ConfigLoadResult, } from "./config-loader.js";
|
|
11
|
-
export { BrandDetector, type SchemaBrandMap } from "./brand-detector.js";
|
|
12
10
|
export { TestGenerator, generateTypeTests, generateImportPrefix, createTestSchemaInfo, toPascalCase, type TestSchemaInfo, type TestFileInfo, type TestGeneratorOptions, } from "./test-generator.js";
|
|
13
11
|
export type { ExtractResult, FileExtractResult, DetectedSchema, MappedTypeName, NameMappingOptions, OutputOptions, GeneratedFile, DeclarationOptions, FieldDescription, BrandInfo, } from "./types.js";
|
|
14
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EACL,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,4BAA4B,EAC5B,uBAAuB,EACvB,qBAAqB,EACrB,KAAK,YAAY,GAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EACL,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,4BAA4B,EAC5B,uBAAuB,EACvB,qBAAqB,EACrB,KAAK,YAAY,GAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEjF,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,gBAAgB,GACtB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,oBAAoB,GAC1B,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,GACV,MAAM,YAAY,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
export { NORMALIZE_TYPE_DEFINITION, createTempTypeAlias } from "./normalizer.js";
|
|
2
2
|
export { ZodTypeExtractor } from "./extractor.js";
|
|
3
3
|
export { formatResult, formatInputOnly, formatOutputOnly, formatAsDeclaration, formatMultipleAsDeclarations, generateDeclarationFile, relativizeImportPaths, } from "./type-printer.js";
|
|
4
|
-
export { SchemaDetector } from "./schema-detector.js";
|
|
5
4
|
export { NameMapper, createNameMapper } from "./name-mapper.js";
|
|
6
5
|
export { FileResolver } from "./file-resolver.js";
|
|
7
6
|
export { DescriptionExtractor } from "./description-extractor.js";
|
|
8
7
|
export { ZinferError, NoSchemasFoundError, NoFilesMatchedError, InvalidOptionError, formatError, } from "./errors.js";
|
|
9
8
|
export { setVerbose, logVerbose, logDebugError, logProgress } from "./logger.js";
|
|
10
9
|
export { ConfigLoader, defineConfig, } from "./config-loader.js";
|
|
11
|
-
export { BrandDetector } from "./brand-detector.js";
|
|
12
10
|
export { TestGenerator, generateTypeTests, generateImportPrefix, createTestSchemaInfo, toPascalCase, } from "./test-generator.js";
|
|
13
11
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAuB,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EACL,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,4BAA4B,EAC5B,uBAAuB,EACvB,qBAAqB,GAEtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAuB,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EACL,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,4BAA4B,EAC5B,uBAAuB,EACvB,qBAAqB,GAEtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEjF,OAAO,EACL,YAAY,EACZ,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,GAIb,MAAM,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name-mapper.d.ts","sourceRoot":"","sources":["../../src/core/name-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAUrE;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAqB;IAEpC;;;;OAIG;
|
|
1
|
+
{"version":3,"file":"name-mapper.d.ts","sourceRoot":"","sources":["../../src/core/name-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAUrE;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAqB;IAEpC;;;;OAIG;gBACS,OAAO,GAAE,kBAAuB;IAO5C;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc;IAgBvC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAYzB;;;;OAIG;IACH,iBAAiB,IAAI,CAAC,UAAU,EAAE,MAAM,KAAK,cAAc;CAG5D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,kBAAuB,GAC/B,CAAC,UAAU,EAAE,MAAM,KAAK,cAAc,CAGxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name-mapper.js","sourceRoot":"","sources":["../../src/core/name-mapper.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,eAAe,GAAqE;IACxF,WAAW,EAAE,OAAO;IAC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WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,eAAe,CAAC,WAAW,CAAC;QAC5E,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,eAAe,CAAC,YAAY,CAAC;QAE/E,OAAO;YACL,YAAY;YACZ,SAAS,EAAE,QAAQ,GAAG,WAAW;YACjC,UAAU,EAAE,QAAQ,GAAG,YAAY;YACnC,WAAW,EAAE,QAAQ;SACtB,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,iBAAiB;QACf,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAA8B,EAAE;IAEhC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,CAAC,UAAkB,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -1,50 +1,30 @@
|
|
|
1
|
-
import { SourceFile } from "
|
|
1
|
+
import type { SourceFile } from "@typescript/native-preview/unstable/ast";
|
|
2
2
|
import type { DetectedSchema } from "./types.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* SchemaDetector, implemented against the tsgo/Corsa `ast` API instead of
|
|
5
|
+
* ts-morph. Purely syntactic (never touches the checker), so it operates
|
|
6
|
+
* directly on a Corsa `SourceFile` node tree. See issue #200.
|
|
5
7
|
*/
|
|
6
8
|
export declare class SchemaDetector {
|
|
7
|
-
private cache;
|
|
8
9
|
/**
|
|
9
10
|
* Detects all Zod schemas in a source file.
|
|
10
11
|
*
|
|
11
|
-
* @param sourceFile - The
|
|
12
|
+
* @param sourceFile - The tsgo SourceFile to analyze
|
|
12
13
|
* @returns Array of detected schema information (including non-exported schemas)
|
|
13
14
|
*/
|
|
14
15
|
detectExportedSchemas(sourceFile: SourceFile): DetectedSchema[];
|
|
15
|
-
/**
|
|
16
|
-
* Known Zod schema builder functions that follow the z. prefix.
|
|
17
|
-
*/
|
|
18
|
-
private static readonly ZOD_SCHEMA_BUILDERS;
|
|
19
|
-
/**
|
|
20
|
-
* Checks if a variable declaration is a Zod schema.
|
|
21
|
-
*
|
|
22
|
-
* @param declaration - The variable declaration to check
|
|
23
|
-
* @returns true if the declaration is a Zod schema
|
|
24
|
-
*/
|
|
25
|
-
private isZodSchema;
|
|
26
16
|
/**
|
|
27
17
|
* Gets all schema names from a source file.
|
|
28
|
-
*
|
|
29
|
-
* @param sourceFile - The ts-morph SourceFile to analyze
|
|
30
|
-
* @returns Array of schema names
|
|
31
18
|
*/
|
|
32
19
|
getSchemaNames(sourceFile: SourceFile): string[];
|
|
20
|
+
private getStartLine;
|
|
21
|
+
private findVariableDeclaration;
|
|
33
22
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @param declaration - The variable declaration to check
|
|
37
|
-
* @returns The explicit type string if found, undefined otherwise
|
|
23
|
+
* Known Zod schema builder functions that follow the z. prefix.
|
|
38
24
|
*/
|
|
25
|
+
private static readonly ZOD_SCHEMA_BUILDERS;
|
|
26
|
+
private isZodSchema;
|
|
39
27
|
private extractExplicitType;
|
|
40
|
-
/**
|
|
41
|
-
* Extracts the first type parameter from a generic type string.
|
|
42
|
-
* Handles nested brackets properly.
|
|
43
|
-
*
|
|
44
|
-
* @param typeText - The full type text (e.g., "ZodType<{ a: string }, ZodTypeDef>")
|
|
45
|
-
* @param startIdx - The index after the opening "<"
|
|
46
|
-
* @returns The first type parameter, or undefined if parsing fails
|
|
47
|
-
*/
|
|
48
28
|
private extractFirstTypeParameter;
|
|
49
29
|
}
|
|
50
30
|
//# sourceMappingURL=schema-detector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-detector.d.ts","sourceRoot":"","sources":["../../src/core/schema-detector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema-detector.d.ts","sourceRoot":"","sources":["../../src/core/schema-detector.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,UAAU,EAGX,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;GAIG;AACH,qBAAa,cAAc;IACzB;;;;;OAKG;IACH,qBAAqB,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc,EAAE;IA+D/D;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE;IAIhD,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,uBAAuB;IAkB/B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAwCxC;IAEH,OAAO,CAAC,WAAW;IA4DnB,OAAO,CAAC,mBAAmB;IAoC3B,OAAO,CAAC,yBAAyB;CAuClC"}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
+
import { ModifierFlags, SyntaxKind } from "@typescript/native-preview/unstable/ast";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* SchemaDetector, implemented against the tsgo/Corsa `ast` API instead of
|
|
4
|
+
* ts-morph. Purely syntactic (never touches the checker), so it operates
|
|
5
|
+
* directly on a Corsa `SourceFile` node tree. See issue #200.
|
|
3
6
|
*/
|
|
4
7
|
export class SchemaDetector {
|
|
5
|
-
cache = new Map();
|
|
6
8
|
/**
|
|
7
9
|
* Detects all Zod schemas in a source file.
|
|
8
10
|
*
|
|
9
|
-
* @param sourceFile - The
|
|
11
|
+
* @param sourceFile - The tsgo SourceFile to analyze
|
|
10
12
|
* @returns Array of detected schema information (including non-exported schemas)
|
|
11
13
|
*/
|
|
12
14
|
detectExportedSchemas(sourceFile) {
|
|
13
|
-
const filePath = sourceFile.getFilePath();
|
|
14
|
-
const cached = this.cache.get(filePath);
|
|
15
|
-
if (cached)
|
|
16
|
-
return cached;
|
|
17
15
|
const schemas = [];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
for (const statement of sourceFile.statements) {
|
|
17
|
+
if (statement.kind !== SyntaxKind.VariableStatement)
|
|
18
|
+
continue;
|
|
19
|
+
const variableStatement = statement;
|
|
20
|
+
const isExported = (variableStatement.modifierFlags & ModifierFlags.Export) !== 0;
|
|
21
|
+
for (const declaration of variableStatement.declarationList.declarations) {
|
|
22
|
+
if (this.isZodSchema(declaration, sourceFile)) {
|
|
24
23
|
schemas.push({
|
|
25
|
-
name: declaration.
|
|
24
|
+
name: declaration.name.getText(sourceFile),
|
|
26
25
|
isExported,
|
|
27
|
-
line:
|
|
28
|
-
explicitType: this.extractExplicitType(declaration),
|
|
26
|
+
line: this.getStartLine(declaration, sourceFile),
|
|
27
|
+
explicitType: this.extractExplicitType(declaration, sourceFile),
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
// Also check for re-exports: export { X as Y }
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
for (const statement of sourceFile.statements) {
|
|
34
|
+
if (statement.kind !== SyntaxKind.ExportDeclaration)
|
|
35
|
+
continue;
|
|
36
|
+
const exportDecl = statement;
|
|
37
|
+
if (!exportDecl.exportClause || exportDecl.exportClause.kind !== SyntaxKind.NamedExports)
|
|
38
|
+
continue;
|
|
39
|
+
for (const namedExport of exportDecl.exportClause.elements) {
|
|
40
|
+
const exportedName = namedExport.name.getText(sourceFile);
|
|
41
|
+
const originalName = namedExport.propertyName
|
|
42
|
+
? namedExport.propertyName.getText(sourceFile)
|
|
43
|
+
: exportedName;
|
|
44
|
+
const originalDecl = this.findVariableDeclaration(sourceFile, originalName);
|
|
45
|
+
if (originalDecl && this.isZodSchema(originalDecl, sourceFile)) {
|
|
45
46
|
if (exportedName !== originalName) {
|
|
46
47
|
if (!schemas.some((s) => s.name === exportedName)) {
|
|
47
48
|
schemas.push({
|
|
48
49
|
name: exportedName,
|
|
49
50
|
isExported: true,
|
|
50
|
-
line:
|
|
51
|
+
line: this.getStartLine(namedExport, sourceFile),
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
else {
|
|
55
|
-
// Same name re-export: update existing schema to mark as exported
|
|
56
56
|
const existing = schemas.find((s) => s.name === originalName);
|
|
57
57
|
if (existing) {
|
|
58
58
|
existing.isExported = true;
|
|
@@ -61,18 +61,37 @@ export class SchemaDetector {
|
|
|
61
61
|
schemas.push({
|
|
62
62
|
name: exportedName,
|
|
63
63
|
isExported: true,
|
|
64
|
-
line:
|
|
64
|
+
line: this.getStartLine(namedExport, sourceFile),
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
// Return all schemas (both exported and non-exported)
|
|
72
|
-
// The isExported flag is used by the type printer to control export keyword
|
|
73
|
-
this.cache.set(filePath, schemas);
|
|
74
71
|
return schemas;
|
|
75
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets all schema names from a source file.
|
|
75
|
+
*/
|
|
76
|
+
getSchemaNames(sourceFile) {
|
|
77
|
+
return this.detectExportedSchemas(sourceFile).map((s) => s.name);
|
|
78
|
+
}
|
|
79
|
+
getStartLine(node, sourceFile) {
|
|
80
|
+
return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|
|
81
|
+
}
|
|
82
|
+
findVariableDeclaration(sourceFile, name) {
|
|
83
|
+
for (const statement of sourceFile.statements) {
|
|
84
|
+
if (statement.kind !== SyntaxKind.VariableStatement)
|
|
85
|
+
continue;
|
|
86
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
87
|
+
if (declaration.name.kind === SyntaxKind.Identifier &&
|
|
88
|
+
declaration.name.getText(sourceFile) === name) {
|
|
89
|
+
return declaration;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
76
95
|
/**
|
|
77
96
|
* Known Zod schema builder functions that follow the z. prefix.
|
|
78
97
|
*/
|
|
@@ -117,37 +136,25 @@ export class SchemaDetector {
|
|
|
117
136
|
"strictObject",
|
|
118
137
|
"looseObject",
|
|
119
138
|
]);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
*
|
|
123
|
-
* @param declaration - The variable declaration to check
|
|
124
|
-
* @returns true if the declaration is a Zod schema
|
|
125
|
-
*/
|
|
126
|
-
isZodSchema(declaration) {
|
|
127
|
-
// Check for explicit Zod type annotation (z.ZodType<T>, z.ZodSchema<T>, etc.)
|
|
128
|
-
const typeNode = declaration.getTypeNode();
|
|
139
|
+
isZodSchema(declaration, sourceFile) {
|
|
140
|
+
const typeNode = declaration.type;
|
|
129
141
|
if (typeNode) {
|
|
130
|
-
const typeText = typeNode.getText();
|
|
142
|
+
const typeText = typeNode.getText(sourceFile);
|
|
131
143
|
if (typeText.includes("ZodType") ||
|
|
132
144
|
typeText.includes("ZodSchema") ||
|
|
133
145
|
typeText.includes("ZodEffects")) {
|
|
134
146
|
return true;
|
|
135
147
|
}
|
|
136
148
|
}
|
|
137
|
-
const initializer = declaration.
|
|
149
|
+
const initializer = declaration.initializer;
|
|
138
150
|
if (!initializer) {
|
|
139
151
|
return false;
|
|
140
152
|
}
|
|
141
|
-
const initText = initializer.getText();
|
|
142
|
-
// Check if it starts with z. followed by a known Zod schema builder.
|
|
143
|
-
// Whitespace is allowed around the dot: formatters break long chains
|
|
144
|
-
// into multiple lines (e.g. `z\n .union([...])\n .describe(...)`).
|
|
153
|
+
const initText = initializer.getText(sourceFile);
|
|
145
154
|
const builderMatch = initText.match(/^z\s*\.\s*([A-Za-z_$][A-Za-z0-9_$]*)/);
|
|
146
155
|
if (builderMatch && SchemaDetector.ZOD_SCHEMA_BUILDERS.has(builderMatch[1])) {
|
|
147
156
|
return true;
|
|
148
157
|
}
|
|
149
|
-
// Check if it's a method chain on another schema variable
|
|
150
|
-
// e.g., SomeSchema.pick({...}), SomeSchema.merge(...)
|
|
151
158
|
const zodMethods = [
|
|
152
159
|
".pick(",
|
|
153
160
|
".omit(",
|
|
@@ -174,35 +181,17 @@ export class SchemaDetector {
|
|
|
174
181
|
return true;
|
|
175
182
|
}
|
|
176
183
|
}
|
|
177
|
-
// Check for z.lazy() pattern (recursive schemas), tolerating
|
|
178
|
-
// formatter-inserted whitespace around the dot
|
|
179
184
|
if (/\bz\s*\.\s*lazy\s*\(/.test(initText)) {
|
|
180
185
|
return true;
|
|
181
186
|
}
|
|
182
187
|
return false;
|
|
183
188
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
*
|
|
187
|
-
* @param sourceFile - The ts-morph SourceFile to analyze
|
|
188
|
-
* @returns Array of schema names
|
|
189
|
-
*/
|
|
190
|
-
getSchemaNames(sourceFile) {
|
|
191
|
-
return this.detectExportedSchemas(sourceFile).map((s) => s.name);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Extracts explicit type annotation from z.ZodType<T> or z.ZodSchema<T>.
|
|
195
|
-
*
|
|
196
|
-
* @param declaration - The variable declaration to check
|
|
197
|
-
* @returns The explicit type string if found, undefined otherwise
|
|
198
|
-
*/
|
|
199
|
-
extractExplicitType(declaration) {
|
|
200
|
-
const typeNode = declaration.getTypeNode();
|
|
189
|
+
extractExplicitType(declaration, sourceFile) {
|
|
190
|
+
const typeNode = declaration.type;
|
|
201
191
|
if (!typeNode) {
|
|
202
192
|
return undefined;
|
|
203
193
|
}
|
|
204
|
-
const typeText = typeNode.getText();
|
|
205
|
-
// Check if it matches Zod type patterns
|
|
194
|
+
const typeText = typeNode.getText(sourceFile);
|
|
206
195
|
const zodTypePatterns = [
|
|
207
196
|
"z.ZodType<",
|
|
208
197
|
"z.ZodSchema<",
|
|
@@ -221,18 +210,9 @@ export class SchemaDetector {
|
|
|
221
210
|
if (!matchedPattern) {
|
|
222
211
|
return undefined;
|
|
223
212
|
}
|
|
224
|
-
// Extract the first type parameter using bracket counting
|
|
225
213
|
const startIdx = matchedPattern.length;
|
|
226
214
|
return this.extractFirstTypeParameter(typeText, startIdx);
|
|
227
215
|
}
|
|
228
|
-
/**
|
|
229
|
-
* Extracts the first type parameter from a generic type string.
|
|
230
|
-
* Handles nested brackets properly.
|
|
231
|
-
*
|
|
232
|
-
* @param typeText - The full type text (e.g., "ZodType<{ a: string }, ZodTypeDef>")
|
|
233
|
-
* @param startIdx - The index after the opening "<"
|
|
234
|
-
* @returns The first type parameter, or undefined if parsing fails
|
|
235
|
-
*/
|
|
236
216
|
extractFirstTypeParameter(typeText, startIdx) {
|
|
237
217
|
let depth = 1;
|
|
238
218
|
let endIdx = startIdx;
|
|
@@ -241,7 +221,6 @@ export class SchemaDetector {
|
|
|
241
221
|
while (endIdx < typeText.length && depth > 0) {
|
|
242
222
|
const char = typeText[endIdx];
|
|
243
223
|
const prevChar = typeText[endIdx - 1];
|
|
244
|
-
// Track string literals
|
|
245
224
|
if ((char === '"' || char === "'" || char === "`") && prevChar !== "\\") {
|
|
246
225
|
if (!inString) {
|
|
247
226
|
inString = true;
|
|
@@ -262,7 +241,6 @@ export class SchemaDetector {
|
|
|
262
241
|
break;
|
|
263
242
|
}
|
|
264
243
|
else if (char === "," && depth === 1) {
|
|
265
|
-
// Found the comma separating type parameters at depth 1
|
|
266
244
|
break;
|
|
267
245
|
}
|
|
268
246
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-detector.js","sourceRoot":"","sources":["../../src/core/schema-detector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema-detector.js","sourceRoot":"","sources":["../../src/core/schema-detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AASpF;;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|
|
1
|
+
import type { SourceFile } from "@typescript/native-preview/unstable/ast";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* SchemaReferenceAnalyzer, implemented against the tsgo/Corsa `ast` API. See issue #200.
|
|
4
4
|
*/
|
|
5
5
|
export interface SchemaReferenceInfo {
|
|
6
|
-
/** The field path where the reference occurs (e.g., "output", "input") */
|
|
7
6
|
fieldPath: string;
|
|
8
|
-
/** The referenced schema name */
|
|
9
7
|
refSchema: string;
|
|
10
|
-
/** Whether wrapped in z.array() */
|
|
11
8
|
isArray: boolean;
|
|
12
|
-
/** Whether wrapped in z.record() */
|
|
13
9
|
isRecord: boolean;
|
|
14
|
-
/** Whether optional */
|
|
15
10
|
isOptional: boolean;
|
|
16
11
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Information about union member references.
|
|
19
|
-
*/
|
|
20
12
|
export interface UnionReferenceInfo {
|
|
21
|
-
/** The referenced schema names (members of the union) */
|
|
22
13
|
memberSchemas: string[];
|
|
23
|
-
/** Whether the union also contains members that are not named schema references */
|
|
24
14
|
hasInlineMembers: boolean;
|
|
25
|
-
/** Whether this is a discriminated union */
|
|
26
15
|
isDiscriminated: boolean;
|
|
27
|
-
/** The discriminator key for discriminated unions */
|
|
28
16
|
discriminatorKey?: string;
|
|
29
17
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Map of schema name to its references to other schemas.
|
|
32
|
-
*/
|
|
33
18
|
export type SchemaReferenceMap = Map<string, SchemaReferenceInfo[]>;
|
|
34
|
-
/**
|
|
35
|
-
* Map of schema name to its union member references.
|
|
36
|
-
*/
|
|
37
19
|
export type UnionReferenceMap = Map<string, UnionReferenceInfo>;
|
|
38
|
-
/**
|
|
39
|
-
* Analyzes schema references to detect cross-schema dependencies.
|
|
40
|
-
*/
|
|
41
20
|
export declare class SchemaReferenceAnalyzer {
|
|
42
21
|
private static readonly OBJECT_BUILDERS;
|
|
43
|
-
/**
|
|
44
|
-
* Zod methods that return `this` without changing the schema's input/output
|
|
45
|
-
* types. References wrapped in these calls are still references to the same
|
|
46
|
-
* schema, so they are unwrapped transparently during analysis.
|
|
47
|
-
*/
|
|
48
22
|
private static readonly TYPE_PRESERVING_METHODS;
|
|
49
|
-
/**
|
|
50
|
-
* Analyzes a source file to find all schema references and union references in a single pass.
|
|
51
|
-
*/
|
|
52
23
|
analyzeAllReferences(sourceFile: SourceFile, schemaNames: Set<string>): {
|
|
53
24
|
references: SchemaReferenceMap;
|
|
54
25
|
unionReferences: UnionReferenceMap;
|
|
55
26
|
};
|
|
56
|
-
/**
|
|
57
|
-
* Finds union references in a schema definition.
|
|
58
|
-
*/
|
|
59
27
|
private findUnionReference;
|
|
60
|
-
/**
|
|
61
|
-
* Parses a z.discriminatedUnion() call.
|
|
62
|
-
*/
|
|
63
28
|
private parseDiscriminatedUnion;
|
|
64
|
-
/**
|
|
65
|
-
* Parses a z.union() call.
|
|
66
|
-
*/
|
|
67
29
|
private parseUnion;
|
|
68
|
-
/**
|
|
69
|
-
* Extracts schema names from an array expression.
|
|
70
|
-
*/
|
|
71
30
|
private extractSchemaArrayMembers;
|
|
72
|
-
/**
|
|
73
|
-
* Finds all references to other schemas within a schema definition.
|
|
74
|
-
*/
|
|
75
31
|
private findSchemaReferences;
|
|
76
|
-
/**
|
|
77
|
-
* Finds schema references in an object shape, including same-file object-literal spreads.
|
|
78
|
-
* Later properties override earlier spread entries, matching JavaScript object semantics.
|
|
79
|
-
*/
|
|
80
32
|
private findObjectLiteralReferences;
|
|
81
|
-
/**
|
|
82
|
-
* Finds all Zod object calls in a node (including the node itself).
|
|
83
|
-
*/
|
|
84
33
|
private findZodObjectCalls;
|
|
85
|
-
/**
|
|
86
|
-
* Analyzes a field value to detect schema references.
|
|
87
|
-
*/
|
|
88
34
|
private analyzeFieldValue;
|
|
89
35
|
}
|
|
90
36
|
//# sourceMappingURL=schema-reference-analyzer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-reference-analyzer.d.ts","sourceRoot":"","sources":["../../src/core/schema-reference-analyzer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema-reference-analyzer.d.ts","sourceRoot":"","sources":["../../src/core/schema-reference-analyzer.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAGV,UAAU,EAEX,MAAM,yCAAyC,CAAC;AAGjD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;AACpE,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAEhE,qBAAa,uBAAuB;IAClC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAsD;IAC7F,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAK5C;IAEH,oBAAoB,CAClB,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,GACvB;QAAE,UAAU,EAAE,kBAAkB,CAAC;QAAC,eAAe,EAAE,iBAAiB,CAAA;KAAE;IA4BzE,OAAO,CAAC,kBAAkB;IA6C1B,OAAO,CAAC,uBAAuB;IAqC/B,OAAO,CAAC,UAAU;IA8BlB,OAAO,CAAC,yBAAyB;IA0BjC,OAAO,CAAC,oBAAoB;IA8B5B,OAAO,CAAC,2BAA2B;IA4EnC,OAAO,CAAC,kBAAkB;IA0B1B,OAAO,CAAC,iBAAiB;CAyF1B"}
|