@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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, V as ValidationAdapter, S as SchemaModule, b as ResolvedFormsConfig, C as CodegenExtension, E as ExtensionContext } from './index-BwIRjOQA.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-BwIRjOQA.cjs';
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: UserConfig, cwd?: string): ResolvedConfig;
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
- declare const zodAdapter: ValidationAdapter;
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 structural successor of `dto-to-zod.ts`: same control flow,
75
- * recursion guard, and warnings, but it emits `SchemaNode` values instead of zod
76
- * text. The zod adapter reproduces the previous output byte-for-byte.
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` re-exported (Path A) or inlined/synthesized
83
- * (Path A inline / Path B) zod schemas per validatable route, plus a
84
- * `formSchemas` name→schema map.
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?: ResolvedFormsConfig, adapter?: ValidationAdapter): Promise<boolean>;
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; an `apiTransport` changes how requests are issued; `apiMembers` add handle
96
- * members; `apiHeader` contributes top-level imports/statements.
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.2.1";
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, zodAdapter };
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, V as ValidationAdapter, S as SchemaModule, b as ResolvedFormsConfig, C as CodegenExtension, E as ExtensionContext } from './index-BwIRjOQA.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-BwIRjOQA.js';
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: UserConfig, cwd?: string): ResolvedConfig;
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
- declare const zodAdapter: ValidationAdapter;
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 structural successor of `dto-to-zod.ts`: same control flow,
75
- * recursion guard, and warnings, but it emits `SchemaNode` values instead of zod
76
- * text. The zod adapter reproduces the previous output byte-for-byte.
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` re-exported (Path A) or inlined/synthesized
83
- * (Path A inline / Path B) zod schemas per validatable route, plus a
84
- * `formSchemas` name→schema map.
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?: ResolvedFormsConfig, adapter?: ValidationAdapter): Promise<boolean>;
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; an `apiTransport` changes how requests are issued; `apiMembers` add handle
96
- * members; `apiHeader` contributes top-level imports/statements.
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.2.1";
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, zodAdapter };
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 };