@dudousxd/nestjs-codegen 0.2.1 → 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/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 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: 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,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 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.
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` 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.
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?: ResolvedFormsConfig, adapter?: ValidationAdapter): Promise<boolean>;
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; an `apiTransport` changes how requests are issued; `apiMembers` add handle
96
- * members; `apiHeader` contributes top-level imports/statements.
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.2.1";
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, zodAdapter };
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, 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 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: 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,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 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.
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` 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.
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?: ResolvedFormsConfig, adapter?: ValidationAdapter): Promise<boolean>;
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; an `apiTransport` changes how requests are issued; `apiMembers` add handle
96
- * members; `apiHeader` contributes top-level imports/statements.
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.2.1";
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, zodAdapter };
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 };