@dudousxd/nestjs-codegen 0.2.1 → 0.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/CHANGELOG.md +57 -0
- package/dist/cli/main.cjs +1229 -1612
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +1211 -1594
- 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-DA4uySjo.d.cts} +84 -41
- package/dist/{index-BwIRjOQA.d.ts → index-DA4uySjo.d.ts} +84 -41
- package/dist/index.cjs +1073 -1460
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -15
- package/dist/index.d.ts +56 -15
- package/dist/index.js +1043 -1430
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +934 -1365
- 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 +921 -1352
- 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,
|
|
1
|
+
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as SchemaModule, c as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-DA4uySjo.cjs';
|
|
2
|
+
export { A as AdapterUsage, d as ContractDescriptor, e as ContractSource, f as ControllerRef, N as NumberCheck, g as RenderContext, h as RenderedModule, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-DA4uySjo.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,68 @@ declare function acquireLock(outDir: string): Promise<{
|
|
|
64
73
|
release: () => Promise<void>;
|
|
65
74
|
} | null>;
|
|
66
75
|
|
|
67
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Renders the neutral {@link SchemaNode} IR to a TypeScript *type* expression
|
|
78
|
+
* (not a validation-lib schema). Used to synthesize the hoisted structural type
|
|
79
|
+
* that annotates a recursive zod/valibot const, breaking the implicit-any
|
|
80
|
+
* inference cycle (`type X = {...}` + `const XSchema: z.ZodType<X> = ...`).
|
|
81
|
+
*
|
|
82
|
+
* References to other named schemas resolve two ways:
|
|
83
|
+
* - a `ref`/`lazyRef` to a *recursive* schema → its type-alias name (so the
|
|
84
|
+
* emitted `type` aliases reference each other, terminating the recursion);
|
|
85
|
+
* - a `ref` to a *non-recursive* schema → inlined structurally (keeps the set
|
|
86
|
+
* of emitted `type` aliases limited to exactly the recursive cluster).
|
|
87
|
+
* Inlining always terminates: every reference cycle passes through a recursive
|
|
88
|
+
* name, which is rendered by alias rather than expanded.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
interface TsTypeContext {
|
|
92
|
+
/** All hoisted named schemas (for inlining non-recursive refs). */
|
|
93
|
+
named: Map<string, SchemaNode>;
|
|
94
|
+
/** Names that are genuinely recursive (rendered by alias, never inlined). */
|
|
95
|
+
recursive: Set<string>;
|
|
96
|
+
/** schema const name (e.g. `ColumnFilterSchema`) → TS type-alias name. */
|
|
97
|
+
typeNameFor: (schemaName: string) => string;
|
|
98
|
+
}
|
|
99
|
+
declare function renderTsType(node: SchemaNode, ctx: TsTypeContext): string;
|
|
68
100
|
|
|
69
101
|
/**
|
|
70
102
|
* Pure-AST translation of class-validator-decorated DTO classes into the neutral
|
|
71
103
|
* {@link SchemaModule} IR. Reads decorator names + literal args via ts-morph — it
|
|
72
104
|
* never imports class-validator at runtime. A `ValidationAdapter` renders the IR.
|
|
73
105
|
*
|
|
74
|
-
* This is the
|
|
75
|
-
*
|
|
76
|
-
*
|
|
106
|
+
* This is the sole DTO translator: it emits neutral `SchemaNode` IR (replacing
|
|
107
|
+
* the former `dto-to-zod.ts` text path). A `ValidationAdapter` renders the IR;
|
|
108
|
+
* the bundled zod adapter reproduces the original zod-text output byte-for-byte.
|
|
77
109
|
*/
|
|
78
110
|
|
|
79
111
|
declare function extractSchemaFromDto(classDecl: ClassDeclaration, sourceFile: SourceFile, project: Project): SchemaModule;
|
|
80
112
|
|
|
81
113
|
/**
|
|
82
|
-
* Emits `forms.ts` into `outDir
|
|
83
|
-
*
|
|
84
|
-
* `
|
|
114
|
+
* Emits `forms.ts` into `outDir`. Every validatable route is rendered through a
|
|
115
|
+
* single {@link ValidationAdapter} path (IR → `adapter.renderModule`). The adapter
|
|
116
|
+
* is required — `validation` is a mandatory config field.
|
|
117
|
+
*
|
|
118
|
+
* Two schema sources exist per route:
|
|
119
|
+
* - Neutral IR (`bodySchema`/`querySchema`) synthesized from class-validator
|
|
120
|
+
* DTOs — renderable through ANY adapter.
|
|
121
|
+
* - Hand-written zod from `defineContract` (`bodyZodText`/`queryZodText` raw
|
|
122
|
+
* source, or `bodyZodRef`/`queryZodRef` re-exports). This is genuine zod
|
|
123
|
+
* source with no IR; it passes through verbatim only when the adapter sets
|
|
124
|
+
* `acceptsRawZodSource` (the zod adapter), and is skipped with a warning
|
|
125
|
+
* under any other adapter.
|
|
85
126
|
*
|
|
86
127
|
* Returns `true` when a `forms.ts` was written (drives the index export).
|
|
87
128
|
*/
|
|
88
|
-
declare function emitForms(routes: RouteDescriptor[], outDir: string, config
|
|
129
|
+
declare function emitForms(routes: RouteDescriptor[], outDir: string, config: ResolvedFormsConfig | undefined, adapter: ValidationAdapter): Promise<boolean>;
|
|
89
130
|
|
|
90
131
|
/**
|
|
91
132
|
* Emits `api.ts` into `outDir` for all routes that carry a `.contract`.
|
|
92
133
|
*
|
|
93
134
|
* By default each leaf is a bare typed-fetch callable. Registered extensions shape the
|
|
94
135
|
* output: an `apiClientLayer` (e.g. `@dudousxd/nestjs-codegen-tanstack`) turns leaves into
|
|
95
|
-
* handles
|
|
96
|
-
*
|
|
136
|
+
* handles wrapping the neutral fetcher request; `apiMembers` add handle members; `apiHeader`
|
|
137
|
+
* contributes top-level imports/statements.
|
|
97
138
|
*/
|
|
98
139
|
interface ApiEmitOptions {
|
|
99
140
|
fetcherImportPath?: string;
|
|
@@ -123,6 +164,6 @@ interface FastDiscoveryOptions {
|
|
|
123
164
|
}
|
|
124
165
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
125
166
|
|
|
126
|
-
declare const VERSION = "0.
|
|
167
|
+
declare const VERSION = "0.4.0";
|
|
127
168
|
|
|
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
|
|
169
|
+
export { CodegenError, ConfigError, type FastDiscoveryOptions, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, defineConfig, discoverContractsFast, emitApi, emitForms, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, 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,
|
|
1
|
+
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as SchemaModule, c as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-DA4uySjo.js';
|
|
2
|
+
export { A as AdapterUsage, d as ContractDescriptor, e as ContractSource, f as ControllerRef, N as NumberCheck, g as RenderContext, h as RenderedModule, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-DA4uySjo.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,68 @@ declare function acquireLock(outDir: string): Promise<{
|
|
|
64
73
|
release: () => Promise<void>;
|
|
65
74
|
} | null>;
|
|
66
75
|
|
|
67
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Renders the neutral {@link SchemaNode} IR to a TypeScript *type* expression
|
|
78
|
+
* (not a validation-lib schema). Used to synthesize the hoisted structural type
|
|
79
|
+
* that annotates a recursive zod/valibot const, breaking the implicit-any
|
|
80
|
+
* inference cycle (`type X = {...}` + `const XSchema: z.ZodType<X> = ...`).
|
|
81
|
+
*
|
|
82
|
+
* References to other named schemas resolve two ways:
|
|
83
|
+
* - a `ref`/`lazyRef` to a *recursive* schema → its type-alias name (so the
|
|
84
|
+
* emitted `type` aliases reference each other, terminating the recursion);
|
|
85
|
+
* - a `ref` to a *non-recursive* schema → inlined structurally (keeps the set
|
|
86
|
+
* of emitted `type` aliases limited to exactly the recursive cluster).
|
|
87
|
+
* Inlining always terminates: every reference cycle passes through a recursive
|
|
88
|
+
* name, which is rendered by alias rather than expanded.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
interface TsTypeContext {
|
|
92
|
+
/** All hoisted named schemas (for inlining non-recursive refs). */
|
|
93
|
+
named: Map<string, SchemaNode>;
|
|
94
|
+
/** Names that are genuinely recursive (rendered by alias, never inlined). */
|
|
95
|
+
recursive: Set<string>;
|
|
96
|
+
/** schema const name (e.g. `ColumnFilterSchema`) → TS type-alias name. */
|
|
97
|
+
typeNameFor: (schemaName: string) => string;
|
|
98
|
+
}
|
|
99
|
+
declare function renderTsType(node: SchemaNode, ctx: TsTypeContext): string;
|
|
68
100
|
|
|
69
101
|
/**
|
|
70
102
|
* Pure-AST translation of class-validator-decorated DTO classes into the neutral
|
|
71
103
|
* {@link SchemaModule} IR. Reads decorator names + literal args via ts-morph — it
|
|
72
104
|
* never imports class-validator at runtime. A `ValidationAdapter` renders the IR.
|
|
73
105
|
*
|
|
74
|
-
* This is the
|
|
75
|
-
*
|
|
76
|
-
*
|
|
106
|
+
* This is the sole DTO translator: it emits neutral `SchemaNode` IR (replacing
|
|
107
|
+
* the former `dto-to-zod.ts` text path). A `ValidationAdapter` renders the IR;
|
|
108
|
+
* the bundled zod adapter reproduces the original zod-text output byte-for-byte.
|
|
77
109
|
*/
|
|
78
110
|
|
|
79
111
|
declare function extractSchemaFromDto(classDecl: ClassDeclaration, sourceFile: SourceFile, project: Project): SchemaModule;
|
|
80
112
|
|
|
81
113
|
/**
|
|
82
|
-
* Emits `forms.ts` into `outDir
|
|
83
|
-
*
|
|
84
|
-
* `
|
|
114
|
+
* Emits `forms.ts` into `outDir`. Every validatable route is rendered through a
|
|
115
|
+
* single {@link ValidationAdapter} path (IR → `adapter.renderModule`). The adapter
|
|
116
|
+
* is required — `validation` is a mandatory config field.
|
|
117
|
+
*
|
|
118
|
+
* Two schema sources exist per route:
|
|
119
|
+
* - Neutral IR (`bodySchema`/`querySchema`) synthesized from class-validator
|
|
120
|
+
* DTOs — renderable through ANY adapter.
|
|
121
|
+
* - Hand-written zod from `defineContract` (`bodyZodText`/`queryZodText` raw
|
|
122
|
+
* source, or `bodyZodRef`/`queryZodRef` re-exports). This is genuine zod
|
|
123
|
+
* source with no IR; it passes through verbatim only when the adapter sets
|
|
124
|
+
* `acceptsRawZodSource` (the zod adapter), and is skipped with a warning
|
|
125
|
+
* under any other adapter.
|
|
85
126
|
*
|
|
86
127
|
* Returns `true` when a `forms.ts` was written (drives the index export).
|
|
87
128
|
*/
|
|
88
|
-
declare function emitForms(routes: RouteDescriptor[], outDir: string, config
|
|
129
|
+
declare function emitForms(routes: RouteDescriptor[], outDir: string, config: ResolvedFormsConfig | undefined, adapter: ValidationAdapter): Promise<boolean>;
|
|
89
130
|
|
|
90
131
|
/**
|
|
91
132
|
* Emits `api.ts` into `outDir` for all routes that carry a `.contract`.
|
|
92
133
|
*
|
|
93
134
|
* By default each leaf is a bare typed-fetch callable. Registered extensions shape the
|
|
94
135
|
* output: an `apiClientLayer` (e.g. `@dudousxd/nestjs-codegen-tanstack`) turns leaves into
|
|
95
|
-
* handles
|
|
96
|
-
*
|
|
136
|
+
* handles wrapping the neutral fetcher request; `apiMembers` add handle members; `apiHeader`
|
|
137
|
+
* contributes top-level imports/statements.
|
|
97
138
|
*/
|
|
98
139
|
interface ApiEmitOptions {
|
|
99
140
|
fetcherImportPath?: string;
|
|
@@ -123,6 +164,6 @@ interface FastDiscoveryOptions {
|
|
|
123
164
|
}
|
|
124
165
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
125
166
|
|
|
126
|
-
declare const VERSION = "0.
|
|
167
|
+
declare const VERSION = "0.4.0";
|
|
127
168
|
|
|
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
|
|
169
|
+
export { CodegenError, ConfigError, type FastDiscoveryOptions, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, defineConfig, discoverContractsFast, emitApi, emitForms, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, watch };
|