@dudousxd/nestjs-codegen 0.2.0 → 0.3.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/CHANGELOG.md +41 -0
- package/README.md +161 -0
- package/dist/cli/main.cjs +1214 -1613
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +1188 -1587
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.cjs +12 -2
- package/dist/extension/index.cjs.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.js +10 -1
- package/dist/extension/index.js.map +1 -1
- package/dist/{index-BwIRjOQA.d.cts → index-oH5t7x4G.d.cts} +56 -41
- package/dist/{index-BwIRjOQA.d.ts → index-oH5t7x4G.d.ts} +56 -41
- package/dist/index.cjs +1003 -1457
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -16
- package/dist/index.d.ts +32 -16
- package/dist/index.js +977 -1430
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +908 -1355
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +9 -2
- package/dist/nest/index.d.ts +9 -2
- package/dist/nest/index.js +893 -1340
- package/dist/nest/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor,
|
|
2
|
-
export { A as AdapterUsage, c as ContractDescriptor, d as ContractSource, e as ControllerRef, N as NumberCheck, f as RenderContext, g as RenderedModule, h as SchemaNode, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-
|
|
1
|
+
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaModule, b as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-oH5t7x4G.cjs';
|
|
2
|
+
export { A as AdapterUsage, c as ContractDescriptor, d as ContractSource, e as ControllerRef, N as NumberCheck, f as RenderContext, g as RenderedModule, h as SchemaNode, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-oH5t7x4G.cjs';
|
|
3
3
|
import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
|
|
4
4
|
|
|
5
5
|
declare function defineConfig(c: UserConfig): UserConfig;
|
|
@@ -12,7 +12,16 @@ declare function defineConfig(c: UserConfig): UserConfig;
|
|
|
12
12
|
* @param userConfig the raw user config (forRoot options minus module-only fields)
|
|
13
13
|
* @param cwd project root used to resolve globs / outDir. Defaults to `process.cwd()`.
|
|
14
14
|
*/
|
|
15
|
-
declare function resolveConfig(userConfig:
|
|
15
|
+
declare function resolveConfig(userConfig: UserConfigInput, cwd?: string): ResolvedConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Loosened {@link UserConfig} where `validation` may be absent. Both config entry
|
|
18
|
+
* points accept this shape and enforce `validation` at runtime (it throws a clear
|
|
19
|
+
* {@link ConfigError} when missing) — letting callers like the Nest module pass
|
|
20
|
+
* partial options without a compile-time `validation` requirement.
|
|
21
|
+
*/
|
|
22
|
+
type UserConfigInput = Omit<UserConfig, 'validation'> & {
|
|
23
|
+
validation?: UserConfig['validation'];
|
|
24
|
+
};
|
|
16
25
|
declare function loadConfig(cwd?: string): Promise<ResolvedConfig>;
|
|
17
26
|
|
|
18
27
|
declare class ConfigError extends Error {
|
|
@@ -64,36 +73,43 @@ declare function acquireLock(outDir: string): Promise<{
|
|
|
64
73
|
release: () => Promise<void>;
|
|
65
74
|
} | null>;
|
|
66
75
|
|
|
67
|
-
declare const zodAdapter: ValidationAdapter;
|
|
68
|
-
|
|
69
76
|
/**
|
|
70
77
|
* Pure-AST translation of class-validator-decorated DTO classes into the neutral
|
|
71
78
|
* {@link SchemaModule} IR. Reads decorator names + literal args via ts-morph — it
|
|
72
79
|
* never imports class-validator at runtime. A `ValidationAdapter` renders the IR.
|
|
73
80
|
*
|
|
74
|
-
* This is the
|
|
75
|
-
*
|
|
76
|
-
*
|
|
81
|
+
* This is the sole DTO translator: it emits neutral `SchemaNode` IR (replacing
|
|
82
|
+
* the former `dto-to-zod.ts` text path). A `ValidationAdapter` renders the IR;
|
|
83
|
+
* the bundled zod adapter reproduces the original zod-text output byte-for-byte.
|
|
77
84
|
*/
|
|
78
85
|
|
|
79
86
|
declare function extractSchemaFromDto(classDecl: ClassDeclaration, sourceFile: SourceFile, project: Project): SchemaModule;
|
|
80
87
|
|
|
81
88
|
/**
|
|
82
|
-
* Emits `forms.ts` into `outDir
|
|
83
|
-
*
|
|
84
|
-
* `
|
|
89
|
+
* Emits `forms.ts` into `outDir`. Every validatable route is rendered through a
|
|
90
|
+
* single {@link ValidationAdapter} path (IR → `adapter.renderModule`). The adapter
|
|
91
|
+
* is required — `validation` is a mandatory config field.
|
|
92
|
+
*
|
|
93
|
+
* Two schema sources exist per route:
|
|
94
|
+
* - Neutral IR (`bodySchema`/`querySchema`) synthesized from class-validator
|
|
95
|
+
* DTOs — renderable through ANY adapter.
|
|
96
|
+
* - Hand-written zod from `defineContract` (`bodyZodText`/`queryZodText` raw
|
|
97
|
+
* source, or `bodyZodRef`/`queryZodRef` re-exports). This is genuine zod
|
|
98
|
+
* source with no IR; it passes through verbatim only when the adapter sets
|
|
99
|
+
* `acceptsRawZodSource` (the zod adapter), and is skipped with a warning
|
|
100
|
+
* under any other adapter.
|
|
85
101
|
*
|
|
86
102
|
* Returns `true` when a `forms.ts` was written (drives the index export).
|
|
87
103
|
*/
|
|
88
|
-
declare function emitForms(routes: RouteDescriptor[], outDir: string, config
|
|
104
|
+
declare function emitForms(routes: RouteDescriptor[], outDir: string, config: ResolvedFormsConfig | undefined, adapter: ValidationAdapter): Promise<boolean>;
|
|
89
105
|
|
|
90
106
|
/**
|
|
91
107
|
* Emits `api.ts` into `outDir` for all routes that carry a `.contract`.
|
|
92
108
|
*
|
|
93
109
|
* By default each leaf is a bare typed-fetch callable. Registered extensions shape the
|
|
94
110
|
* output: an `apiClientLayer` (e.g. `@dudousxd/nestjs-codegen-tanstack`) turns leaves into
|
|
95
|
-
* handles
|
|
96
|
-
*
|
|
111
|
+
* handles wrapping the neutral fetcher request; `apiMembers` add handle members; `apiHeader`
|
|
112
|
+
* contributes top-level imports/statements.
|
|
97
113
|
*/
|
|
98
114
|
interface ApiEmitOptions {
|
|
99
115
|
fetcherImportPath?: string;
|
|
@@ -123,6 +139,6 @@ interface FastDiscoveryOptions {
|
|
|
123
139
|
}
|
|
124
140
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
125
141
|
|
|
126
|
-
declare const VERSION = "0.
|
|
142
|
+
declare const VERSION = "0.3.0";
|
|
127
143
|
|
|
128
|
-
export { CodegenError, ConfigError, type FastDiscoveryOptions, ResolvedConfig, RouteDescriptor, SchemaModule, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, defineConfig, discoverContractsFast, emitApi, emitForms, emitRoutes, extractSchemaFromDto, generate, loadConfig, resolveConfig, watch
|
|
144
|
+
export { CodegenError, ConfigError, type FastDiscoveryOptions, ResolvedConfig, RouteDescriptor, SchemaModule, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, defineConfig, discoverContractsFast, emitApi, emitForms, emitRoutes, extractSchemaFromDto, generate, loadConfig, resolveConfig, watch };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor,
|
|
2
|
-
export { A as AdapterUsage, c as ContractDescriptor, d as ContractSource, e as ControllerRef, N as NumberCheck, f as RenderContext, g as RenderedModule, h as SchemaNode, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-
|
|
1
|
+
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaModule, b as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-oH5t7x4G.js';
|
|
2
|
+
export { A as AdapterUsage, c as ContractDescriptor, d as ContractSource, e as ControllerRef, N as NumberCheck, f as RenderContext, g as RenderedModule, h as SchemaNode, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-oH5t7x4G.js';
|
|
3
3
|
import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
|
|
4
4
|
|
|
5
5
|
declare function defineConfig(c: UserConfig): UserConfig;
|
|
@@ -12,7 +12,16 @@ declare function defineConfig(c: UserConfig): UserConfig;
|
|
|
12
12
|
* @param userConfig the raw user config (forRoot options minus module-only fields)
|
|
13
13
|
* @param cwd project root used to resolve globs / outDir. Defaults to `process.cwd()`.
|
|
14
14
|
*/
|
|
15
|
-
declare function resolveConfig(userConfig:
|
|
15
|
+
declare function resolveConfig(userConfig: UserConfigInput, cwd?: string): ResolvedConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Loosened {@link UserConfig} where `validation` may be absent. Both config entry
|
|
18
|
+
* points accept this shape and enforce `validation` at runtime (it throws a clear
|
|
19
|
+
* {@link ConfigError} when missing) — letting callers like the Nest module pass
|
|
20
|
+
* partial options without a compile-time `validation` requirement.
|
|
21
|
+
*/
|
|
22
|
+
type UserConfigInput = Omit<UserConfig, 'validation'> & {
|
|
23
|
+
validation?: UserConfig['validation'];
|
|
24
|
+
};
|
|
16
25
|
declare function loadConfig(cwd?: string): Promise<ResolvedConfig>;
|
|
17
26
|
|
|
18
27
|
declare class ConfigError extends Error {
|
|
@@ -64,36 +73,43 @@ declare function acquireLock(outDir: string): Promise<{
|
|
|
64
73
|
release: () => Promise<void>;
|
|
65
74
|
} | null>;
|
|
66
75
|
|
|
67
|
-
declare const zodAdapter: ValidationAdapter;
|
|
68
|
-
|
|
69
76
|
/**
|
|
70
77
|
* Pure-AST translation of class-validator-decorated DTO classes into the neutral
|
|
71
78
|
* {@link SchemaModule} IR. Reads decorator names + literal args via ts-morph — it
|
|
72
79
|
* never imports class-validator at runtime. A `ValidationAdapter` renders the IR.
|
|
73
80
|
*
|
|
74
|
-
* This is the
|
|
75
|
-
*
|
|
76
|
-
*
|
|
81
|
+
* This is the sole DTO translator: it emits neutral `SchemaNode` IR (replacing
|
|
82
|
+
* the former `dto-to-zod.ts` text path). A `ValidationAdapter` renders the IR;
|
|
83
|
+
* the bundled zod adapter reproduces the original zod-text output byte-for-byte.
|
|
77
84
|
*/
|
|
78
85
|
|
|
79
86
|
declare function extractSchemaFromDto(classDecl: ClassDeclaration, sourceFile: SourceFile, project: Project): SchemaModule;
|
|
80
87
|
|
|
81
88
|
/**
|
|
82
|
-
* Emits `forms.ts` into `outDir
|
|
83
|
-
*
|
|
84
|
-
* `
|
|
89
|
+
* Emits `forms.ts` into `outDir`. Every validatable route is rendered through a
|
|
90
|
+
* single {@link ValidationAdapter} path (IR → `adapter.renderModule`). The adapter
|
|
91
|
+
* is required — `validation` is a mandatory config field.
|
|
92
|
+
*
|
|
93
|
+
* Two schema sources exist per route:
|
|
94
|
+
* - Neutral IR (`bodySchema`/`querySchema`) synthesized from class-validator
|
|
95
|
+
* DTOs — renderable through ANY adapter.
|
|
96
|
+
* - Hand-written zod from `defineContract` (`bodyZodText`/`queryZodText` raw
|
|
97
|
+
* source, or `bodyZodRef`/`queryZodRef` re-exports). This is genuine zod
|
|
98
|
+
* source with no IR; it passes through verbatim only when the adapter sets
|
|
99
|
+
* `acceptsRawZodSource` (the zod adapter), and is skipped with a warning
|
|
100
|
+
* under any other adapter.
|
|
85
101
|
*
|
|
86
102
|
* Returns `true` when a `forms.ts` was written (drives the index export).
|
|
87
103
|
*/
|
|
88
|
-
declare function emitForms(routes: RouteDescriptor[], outDir: string, config
|
|
104
|
+
declare function emitForms(routes: RouteDescriptor[], outDir: string, config: ResolvedFormsConfig | undefined, adapter: ValidationAdapter): Promise<boolean>;
|
|
89
105
|
|
|
90
106
|
/**
|
|
91
107
|
* Emits `api.ts` into `outDir` for all routes that carry a `.contract`.
|
|
92
108
|
*
|
|
93
109
|
* By default each leaf is a bare typed-fetch callable. Registered extensions shape the
|
|
94
110
|
* output: an `apiClientLayer` (e.g. `@dudousxd/nestjs-codegen-tanstack`) turns leaves into
|
|
95
|
-
* handles
|
|
96
|
-
*
|
|
111
|
+
* handles wrapping the neutral fetcher request; `apiMembers` add handle members; `apiHeader`
|
|
112
|
+
* contributes top-level imports/statements.
|
|
97
113
|
*/
|
|
98
114
|
interface ApiEmitOptions {
|
|
99
115
|
fetcherImportPath?: string;
|
|
@@ -123,6 +139,6 @@ interface FastDiscoveryOptions {
|
|
|
123
139
|
}
|
|
124
140
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
125
141
|
|
|
126
|
-
declare const VERSION = "0.
|
|
142
|
+
declare const VERSION = "0.3.0";
|
|
127
143
|
|
|
128
|
-
export { CodegenError, ConfigError, type FastDiscoveryOptions, ResolvedConfig, RouteDescriptor, SchemaModule, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, defineConfig, discoverContractsFast, emitApi, emitForms, emitRoutes, extractSchemaFromDto, generate, loadConfig, resolveConfig, watch
|
|
144
|
+
export { CodegenError, ConfigError, type FastDiscoveryOptions, ResolvedConfig, RouteDescriptor, SchemaModule, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, defineConfig, discoverContractsFast, emitApi, emitForms, emitRoutes, extractSchemaFromDto, generate, loadConfig, resolveConfig, watch };
|