zod-codegen 1.2.2 → 1.4.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/.claude/settings.local.json +43 -0
- package/.github/workflows/ci.yml +4 -4
- package/.github/workflows/release.yml +1 -1
- package/CHANGELOG.md +17 -0
- package/README.md +61 -9
- package/dist/scripts/update-manifest.d.ts +14 -0
- package/dist/scripts/update-manifest.d.ts.map +1 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +31 -2
- package/dist/src/generator.d.ts +23 -0
- package/dist/src/generator.d.ts.map +1 -0
- package/dist/src/generator.js +3 -2
- package/dist/src/http/fetch-client.d.ts +15 -0
- package/dist/src/http/fetch-client.d.ts.map +1 -0
- package/dist/src/interfaces/code-generator.d.ts +20 -0
- package/dist/src/interfaces/code-generator.d.ts.map +1 -0
- package/dist/src/interfaces/file-reader.d.ts +13 -0
- package/dist/src/interfaces/file-reader.d.ts.map +1 -0
- package/dist/src/polyfills/fetch.d.ts +5 -0
- package/dist/src/polyfills/fetch.d.ts.map +1 -0
- package/dist/src/services/code-generator.service.d.ts +57 -0
- package/dist/src/services/code-generator.service.d.ts.map +1 -0
- package/dist/src/services/code-generator.service.js +43 -6
- package/dist/src/services/file-reader.service.d.ts +9 -0
- package/dist/src/services/file-reader.service.d.ts.map +1 -0
- package/dist/src/services/file-writer.service.d.ts +10 -0
- package/dist/src/services/file-writer.service.d.ts.map +1 -0
- package/dist/src/services/import-builder.service.d.ts +14 -0
- package/dist/src/services/import-builder.service.d.ts.map +1 -0
- package/dist/src/services/type-builder.service.d.ts +12 -0
- package/dist/src/services/type-builder.service.d.ts.map +1 -0
- package/dist/src/types/generator-options.d.ts +59 -0
- package/dist/src/types/generator-options.d.ts.map +1 -0
- package/dist/src/types/generator-options.js +1 -0
- package/dist/src/types/http.d.ts +25 -0
- package/dist/src/types/http.d.ts.map +1 -0
- package/dist/src/types/openapi.d.ts +1120 -0
- package/dist/src/types/openapi.d.ts.map +1 -0
- package/dist/src/utils/error-handler.d.ts +3 -0
- package/dist/src/utils/error-handler.d.ts.map +1 -0
- package/dist/src/utils/error-handler.js +2 -2
- package/dist/src/utils/execution-time.d.ts +2 -0
- package/dist/src/utils/execution-time.d.ts.map +1 -0
- package/dist/src/utils/manifest.d.ts +8 -0
- package/dist/src/utils/manifest.d.ts.map +1 -0
- package/dist/src/utils/naming-convention.d.ts +80 -0
- package/dist/src/utils/naming-convention.d.ts.map +1 -0
- package/dist/src/utils/naming-convention.js +135 -0
- package/dist/src/utils/reporter.d.ts +7 -0
- package/dist/src/utils/reporter.d.ts.map +1 -0
- package/dist/src/utils/signal-handler.d.ts +3 -0
- package/dist/src/utils/signal-handler.d.ts.map +1 -0
- package/dist/src/utils/signal-handler.js +2 -2
- package/dist/src/utils/tty.d.ts +2 -0
- package/dist/src/utils/tty.d.ts.map +1 -0
- package/dist/tests/integration/cli.test.d.ts +2 -0
- package/dist/tests/integration/cli.test.d.ts.map +1 -0
- package/dist/tests/integration/cli.test.js +2 -2
- package/dist/tests/unit/code-generator.test.d.ts +2 -0
- package/dist/tests/unit/code-generator.test.d.ts.map +1 -0
- package/dist/tests/unit/code-generator.test.js +170 -1
- package/dist/tests/unit/file-reader.test.d.ts +2 -0
- package/dist/tests/unit/file-reader.test.d.ts.map +1 -0
- package/dist/tests/unit/generator.test.d.ts +2 -0
- package/dist/tests/unit/generator.test.d.ts.map +1 -0
- package/dist/tests/unit/naming-convention.test.d.ts +2 -0
- package/dist/tests/unit/naming-convention.test.d.ts.map +1 -0
- package/dist/tests/unit/naming-convention.test.js +231 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/package.json +12 -7
- package/scripts/republish-versions.sh +94 -0
- package/src/cli.ts +34 -3
- package/src/generator.ts +8 -1
- package/src/services/code-generator.service.ts +74 -7
- package/src/types/generator-options.ts +60 -0
- package/src/utils/error-handler.ts +2 -2
- package/src/utils/naming-convention.ts +214 -0
- package/src/utils/signal-handler.ts +2 -2
- package/tests/integration/cli.test.ts +2 -2
- package/tests/unit/code-generator.test.ts +189 -1
- package/tests/unit/naming-convention.test.ts +263 -0
- package/tsconfig.json +2 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import type { TypeBuilder } from '../interfaces/code-generator.js';
|
|
3
|
+
export declare class TypeScriptTypeBuilderService implements TypeBuilder {
|
|
4
|
+
buildType(type: string): ts.TypeNode;
|
|
5
|
+
createProperty(name: string, type: string, isReadonly?: boolean): ts.PropertyDeclaration;
|
|
6
|
+
createParameter(name: string, type?: string | ts.TypeNode, defaultValue?: ts.Expression, isOptional?: boolean): ts.ParameterDeclaration;
|
|
7
|
+
createGenericType(name: string): ts.TypeParameterDeclaration;
|
|
8
|
+
sanitizeIdentifier(name: string): string;
|
|
9
|
+
toCamelCase(word: string): string;
|
|
10
|
+
toPascalCase(word: string): string;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=type-builder.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-builder.service.d.ts","sourceRoot":"","sources":["../../../src/services/type-builder.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,iCAAiC,CAAC;AAEjE,qBAAa,4BAA6B,YAAW,WAAW;IAC9D,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,QAAQ;IA6BpC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,EAAE,CAAC,mBAAmB;IAYtF,eAAe,CACb,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC,QAAQ,EAC3B,YAAY,CAAC,EAAE,EAAE,CAAC,UAAU,EAC5B,UAAU,UAAQ,GACjB,EAAE,CAAC,oBAAoB;IAW1B,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,wBAAwB;IAS5D,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMxC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIjC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAGnC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { NamingConvention, OperationNameTransformer } from '../utils/naming-convention.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the Generator class.
|
|
4
|
+
*
|
|
5
|
+
* These options control how operation IDs are transformed during code generation.
|
|
6
|
+
* You can either use a predefined naming convention or provide a custom transformer function.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Using a naming convention
|
|
11
|
+
* const generator = new Generator(..., {
|
|
12
|
+
* namingConvention: 'camelCase'
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Using a custom transformer
|
|
16
|
+
* const generator = new Generator(..., {
|
|
17
|
+
* operationNameTransformer: (details) => {
|
|
18
|
+
* return `${details.method}_${details.operationId}`;
|
|
19
|
+
* }
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export interface GeneratorOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Naming convention to apply to operation IDs.
|
|
26
|
+
*
|
|
27
|
+
* If provided, all operation IDs will be transformed according to the specified convention.
|
|
28
|
+
* This is useful when OpenAPI specs have inconsistent or poorly named operation IDs.
|
|
29
|
+
*
|
|
30
|
+
* **Note:** If `operationNameTransformer` is also provided, it takes precedence.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* { namingConvention: 'camelCase' } // Transforms 'get_user_by_id' → 'getUserById'
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
namingConvention?: NamingConvention;
|
|
38
|
+
/**
|
|
39
|
+
* Custom transformer function for operation names.
|
|
40
|
+
*
|
|
41
|
+
* If provided, this function will be called for each operation with full operation details.
|
|
42
|
+
* This allows for advanced customization based on HTTP method, path, tags, etc.
|
|
43
|
+
*
|
|
44
|
+
* **Note:** This takes precedence over `namingConvention` if both are provided.
|
|
45
|
+
* The returned name will be sanitized to ensure it's a valid TypeScript identifier.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* {
|
|
50
|
+
* operationNameTransformer: (details) => {
|
|
51
|
+
* const tag = details.tags?.[0] || 'default';
|
|
52
|
+
* return `${details.method.toUpperCase()}_${tag}_${details.operationId}`;
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
operationNameTransformer?: OperationNameTransformer;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=generator-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator-options.d.ts","sourceRoot":"","sources":["../../../src/types/generator-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,wBAAwB,EAAC,MAAM,+BAA+B,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;OAYG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;;;;;;;;;;;;;;;;OAkBG;IACH,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;CACrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface HttpRequestConfig<TData = unknown> {
|
|
2
|
+
readonly url: string;
|
|
3
|
+
readonly method: HttpMethod;
|
|
4
|
+
readonly headers?: Record<string, string>;
|
|
5
|
+
readonly params?: Record<string, string | number | boolean>;
|
|
6
|
+
readonly data?: TData;
|
|
7
|
+
readonly timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface HttpResponse<TData = unknown> {
|
|
10
|
+
readonly data: TData;
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly statusText: string;
|
|
13
|
+
readonly headers: Record<string, string>;
|
|
14
|
+
readonly url: string;
|
|
15
|
+
}
|
|
16
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
17
|
+
export interface HttpClient {
|
|
18
|
+
request<TResponse = unknown, TRequest = unknown>(config: HttpRequestConfig<TRequest>): Promise<HttpResponse<TResponse>>;
|
|
19
|
+
}
|
|
20
|
+
export declare class HttpError extends Error {
|
|
21
|
+
readonly status: number;
|
|
22
|
+
readonly response?: HttpResponse | undefined;
|
|
23
|
+
constructor(message: string, status: number, response?: HttpResponse | undefined);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/types/http.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB,CAAC,KAAK,GAAG,OAAO;IAChD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY,CAAC,KAAK,GAAG,OAAO;IAC3C,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1F,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,SAAS,GAAG,OAAO,EAAE,QAAQ,GAAG,OAAO,EAC7C,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,GAClC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;CACrC;AAED,qBAAa,SAAU,SAAQ,KAAK;aAGhB,MAAM,EAAE,MAAM;aACd,QAAQ,CAAC,EAAE,YAAY;gBAFvC,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,YAAY,YAAA;CAK1C"}
|