zinfer 0.0.1 → 0.1.2

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.
Files changed (79) hide show
  1. package/README.md +477 -28
  2. package/bin/zinfer +2 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +486 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/core/brand-detector.d.ts +32 -0
  8. package/dist/core/brand-detector.d.ts.map +1 -0
  9. package/dist/core/brand-detector.js +121 -0
  10. package/dist/core/brand-detector.js.map +1 -0
  11. package/dist/core/config-loader.d.ts +87 -0
  12. package/dist/core/config-loader.d.ts.map +1 -0
  13. package/dist/core/config-loader.js +105 -0
  14. package/dist/core/config-loader.js.map +1 -0
  15. package/dist/core/description-extractor.d.ts +54 -0
  16. package/dist/core/description-extractor.d.ts.map +1 -0
  17. package/dist/core/description-extractor.js +180 -0
  18. package/dist/core/description-extractor.js.map +1 -0
  19. package/dist/core/errors.d.ts +35 -0
  20. package/dist/core/errors.d.ts.map +1 -0
  21. package/dist/core/errors.js +96 -0
  22. package/dist/core/errors.js.map +1 -0
  23. package/dist/core/extractor.d.ts +121 -0
  24. package/dist/core/extractor.d.ts.map +1 -0
  25. package/dist/core/extractor.js +504 -0
  26. package/dist/core/extractor.js.map +1 -0
  27. package/dist/core/file-resolver.d.ts +41 -0
  28. package/dist/core/file-resolver.d.ts.map +1 -0
  29. package/dist/core/file-resolver.js +95 -0
  30. package/dist/core/file-resolver.js.map +1 -0
  31. package/dist/core/getter-resolver.d.ts +67 -0
  32. package/dist/core/getter-resolver.d.ts.map +1 -0
  33. package/dist/core/getter-resolver.js +234 -0
  34. package/dist/core/getter-resolver.js.map +1 -0
  35. package/dist/core/import-resolver.d.ts +51 -0
  36. package/dist/core/import-resolver.d.ts.map +1 -0
  37. package/dist/core/import-resolver.js +158 -0
  38. package/dist/core/import-resolver.js.map +1 -0
  39. package/dist/core/index.d.ts +14 -0
  40. package/dist/core/index.d.ts.map +1 -0
  41. package/dist/core/index.js +13 -0
  42. package/dist/core/index.js.map +1 -0
  43. package/dist/core/logger.d.ts +20 -0
  44. package/dist/core/logger.d.ts.map +1 -0
  45. package/dist/core/logger.js +36 -0
  46. package/dist/core/logger.js.map +1 -0
  47. package/dist/core/name-mapper.d.ts +45 -0
  48. package/dist/core/name-mapper.d.ts.map +1 -0
  49. package/dist/core/name-mapper.js +82 -0
  50. package/dist/core/name-mapper.js.map +1 -0
  51. package/dist/core/normalizer.d.ts +24 -0
  52. package/dist/core/normalizer.d.ts.map +1 -0
  53. package/dist/core/normalizer.js +50 -0
  54. package/dist/core/normalizer.js.map +1 -0
  55. package/dist/core/schema-detector.d.ts +49 -0
  56. package/dist/core/schema-detector.d.ts.map +1 -0
  57. package/dist/core/schema-detector.js +272 -0
  58. package/dist/core/schema-detector.js.map +1 -0
  59. package/dist/core/schema-reference-analyzer.d.ts +77 -0
  60. package/dist/core/schema-reference-analyzer.d.ts.map +1 -0
  61. package/dist/core/schema-reference-analyzer.js +269 -0
  62. package/dist/core/schema-reference-analyzer.js.map +1 -0
  63. package/dist/core/test-generator.d.ts +97 -0
  64. package/dist/core/test-generator.d.ts.map +1 -0
  65. package/dist/core/test-generator.js +177 -0
  66. package/dist/core/test-generator.js.map +1 -0
  67. package/dist/core/type-printer.d.ts +46 -0
  68. package/dist/core/type-printer.d.ts.map +1 -0
  69. package/dist/core/type-printer.js +519 -0
  70. package/dist/core/type-printer.js.map +1 -0
  71. package/dist/core/types.d.ts +124 -0
  72. package/dist/core/types.d.ts.map +1 -0
  73. package/dist/core/types.js +5 -0
  74. package/dist/core/types.js.map +1 -0
  75. package/dist/index.d.ts +66 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +79 -0
  78. package/dist/index.js.map +1 -0
  79. package/package.json +63 -7
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Shared type definitions for zinfer.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,66 @@
1
+ export { ZodTypeExtractor, type ExtractOptions, formatResult, formatInputOnly, formatOutputOnly, formatAsDeclaration, formatMultipleAsDeclarations, generateDeclarationFile, type PrintOptions, SchemaDetector, NameMapper, createNameMapper, FileResolver, defineConfig, type ZinferConfig, TestGenerator, generateTypeTests, generateImportPrefix, createTestSchemaInfo, toPascalCase, type TestSchemaInfo, type TestFileInfo, type TestGeneratorOptions, } from "./core/index.js";
2
+ export type { ExtractResult, FileExtractResult, DetectedSchema, MappedTypeName, NameMappingOptions, OutputOptions, GeneratedFile, DeclarationOptions, } from "./core/index.js";
3
+ import { type ExtractResult, type NameMappingOptions, type DeclarationOptions } from "./core/index.js";
4
+ /**
5
+ * Simple API to extract input and output types from a Zod schema.
6
+ *
7
+ * @param filePath - Path to the TypeScript file containing the Zod schema
8
+ * @param schemaName - Name of the exported Zod schema
9
+ * @param tsconfigPath - Optional path to tsconfig.json
10
+ * @returns Object containing input and output type strings
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { extractZodTypes } from 'zinfer';
15
+ *
16
+ * const { input, output } = extractZodTypes('./schemas.ts', 'UserSchema');
17
+ * console.log('Input:', input);
18
+ * console.log('Output:', output);
19
+ * ```
20
+ */
21
+ export declare function extractZodTypes(filePath: string, schemaName: string, tsconfigPath?: string): {
22
+ input: string;
23
+ output: string;
24
+ };
25
+ /**
26
+ * Extracts types and returns a formatted string ready for console output.
27
+ *
28
+ * @param filePath - Path to the TypeScript file containing the Zod schema
29
+ * @param schemaName - Name of the exported Zod schema
30
+ * @param tsconfigPath - Optional path to tsconfig.json
31
+ * @returns Formatted string with input and output types
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { extractAndFormat } from 'zinfer';
36
+ *
37
+ * console.log(extractAndFormat('./schemas.ts', 'UserSchema'));
38
+ * // Output:
39
+ * // // input
40
+ * // { id: string; name: string; }
41
+ * //
42
+ * // // output
43
+ * // { id: string; name: string; }
44
+ * ```
45
+ */
46
+ export declare function extractAndFormat(filePath: string, schemaName: string, tsconfigPath?: string): string;
47
+ /**
48
+ * Extracts all schemas from a file.
49
+ *
50
+ * @param filePath - Path to the TypeScript file
51
+ * @param tsconfigPath - Optional path to tsconfig.json
52
+ * @returns Array of extraction results
53
+ */
54
+ export declare function extractAllSchemas(filePath: string, tsconfigPath?: string): ExtractResult[];
55
+ /**
56
+ * Generates TypeScript type declarations from extraction results.
57
+ *
58
+ * @param results - Array of extraction results
59
+ * @param options - Generation options
60
+ * @returns TypeScript declaration file content
61
+ */
62
+ export declare function generateTypeDeclarations(results: ExtractResult[], options?: {
63
+ nameMapping?: NameMappingOptions;
64
+ declaration?: DeclarationOptions;
65
+ }): string;
66
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,KAAK,cAAc,EACnB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,4BAA4B,EAC5B,uBAAuB,EACvB,KAAK,YAAY,EACjB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,KAAK,YAAY,EAEjB,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,oBAAoB,GAC1B,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM,GACpB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAOnC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAIR;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,aAAa,EAAE,CAG1F;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,aAAa,EAAE,EACxB,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAC7B,GACL,MAAM,CAGR"}
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ // Core exports
2
+ export { ZodTypeExtractor, formatResult, formatInputOnly, formatOutputOnly, formatAsDeclaration, formatMultipleAsDeclarations, generateDeclarationFile, SchemaDetector, NameMapper, createNameMapper, FileResolver, defineConfig,
3
+ // Test generation
4
+ TestGenerator, generateTypeTests, generateImportPrefix, createTestSchemaInfo, toPascalCase, } from "./core/index.js";
5
+ import { ZodTypeExtractor, generateDeclarationFile, NameMapper, formatResult, } from "./core/index.js";
6
+ /**
7
+ * Simple API to extract input and output types from a Zod schema.
8
+ *
9
+ * @param filePath - Path to the TypeScript file containing the Zod schema
10
+ * @param schemaName - Name of the exported Zod schema
11
+ * @param tsconfigPath - Optional path to tsconfig.json
12
+ * @returns Object containing input and output type strings
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { extractZodTypes } from 'zinfer';
17
+ *
18
+ * const { input, output } = extractZodTypes('./schemas.ts', 'UserSchema');
19
+ * console.log('Input:', input);
20
+ * console.log('Output:', output);
21
+ * ```
22
+ */
23
+ export function extractZodTypes(filePath, schemaName, tsconfigPath) {
24
+ const extractor = new ZodTypeExtractor(tsconfigPath);
25
+ const result = extractor.extract({ filePath, schemaName });
26
+ return {
27
+ input: result.input,
28
+ output: result.output,
29
+ };
30
+ }
31
+ /**
32
+ * Extracts types and returns a formatted string ready for console output.
33
+ *
34
+ * @param filePath - Path to the TypeScript file containing the Zod schema
35
+ * @param schemaName - Name of the exported Zod schema
36
+ * @param tsconfigPath - Optional path to tsconfig.json
37
+ * @returns Formatted string with input and output types
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * import { extractAndFormat } from 'zinfer';
42
+ *
43
+ * console.log(extractAndFormat('./schemas.ts', 'UserSchema'));
44
+ * // Output:
45
+ * // // input
46
+ * // { id: string; name: string; }
47
+ * //
48
+ * // // output
49
+ * // { id: string; name: string; }
50
+ * ```
51
+ */
52
+ export function extractAndFormat(filePath, schemaName, tsconfigPath) {
53
+ const extractor = new ZodTypeExtractor(tsconfigPath);
54
+ const result = extractor.extract({ filePath, schemaName });
55
+ return formatResult(result);
56
+ }
57
+ /**
58
+ * Extracts all schemas from a file.
59
+ *
60
+ * @param filePath - Path to the TypeScript file
61
+ * @param tsconfigPath - Optional path to tsconfig.json
62
+ * @returns Array of extraction results
63
+ */
64
+ export function extractAllSchemas(filePath, tsconfigPath) {
65
+ const extractor = new ZodTypeExtractor(tsconfigPath);
66
+ return extractor.extractAll(filePath);
67
+ }
68
+ /**
69
+ * Generates TypeScript type declarations from extraction results.
70
+ *
71
+ * @param results - Array of extraction results
72
+ * @param options - Generation options
73
+ * @returns TypeScript declaration file content
74
+ */
75
+ export function generateTypeDeclarations(results, options = {}) {
76
+ const mapper = new NameMapper(options.nameMapping || {});
77
+ return generateDeclarationFile(results, mapper.createMapFunction(), options.declaration || {});
78
+ }
79
+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AS,GAAG,IAAI,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACrD,OAAO,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAwB,EACxB,UAGI,EAAE;IAEN,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IACzD,OAAO,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,iBAAiB,EAAE,EAAE,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;AACjG,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,66 @@
1
1
  {
2
2
  "name": "zinfer",
3
- "version": "0.0.1",
4
- "description": "OIDC trusted publishing setup package for zinfer",
3
+ "version": "0.1.2",
4
+ "description": "Extract input/output types from Zod schemas",
5
5
  "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
10
- }
6
+ "schema",
7
+ "type-extraction",
8
+ "typescript",
9
+ "zod"
10
+ ],
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/toiroakr/zinfer.git"
15
+ },
16
+ "bin": {
17
+ "zinfer": "./bin/zinfer"
18
+ },
19
+ "files": [
20
+ "bin",
21
+ "dist"
22
+ ],
23
+ "type": "module",
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "provenance": true
29
+ },
30
+ "dependencies": {
31
+ "commander": "^14.0.2",
32
+ "glob": "^13.0.0",
33
+ "pathe": "^2.0.3",
34
+ "ts-morph": "^27.0.2"
35
+ },
36
+ "devDependencies": {
37
+ "@changesets/cli": "2.29.8",
38
+ "@types/node": "25.3.3",
39
+ "@typescript/native-preview": "7.0.0-dev.20260228.1",
40
+ "knip": "5.85.0",
41
+ "lefthook": "2.1.1",
42
+ "oxfmt": "0.35.0",
43
+ "oxlint": "1.50.0",
44
+ "typescript": "5.9.3",
45
+ "vitest": "4.0.18",
46
+ "zod": "4.3.6"
47
+ },
48
+ "peerDependencies": {
49
+ "typescript": ">=5.0.0",
50
+ "zod": ">=3.0.0"
51
+ },
52
+ "scripts": {
53
+ "build": "tsc",
54
+ "test": "vitest run",
55
+ "test:watch": "vitest",
56
+ "typecheck": "tsgo --noEmit",
57
+ "typecheck:tsc": "tsc --noEmit",
58
+ "lint": "oxlint",
59
+ "format": "oxfmt --write .",
60
+ "format:check": "oxfmt --check .",
61
+ "knip": "knip",
62
+ "changeset": "changeset",
63
+ "release": "pnpm build && changeset publish",
64
+ "generate:type-tests": "node ./dist/cli.js 'tests/fixtures/*.ts' --outDir tests/__file_snapshots__ --outPattern '[name].ts' --generate-tests --suffix Schema"
65
+ }
66
+ }