@dudousxd/nestjs-codegen 0.8.0 → 0.10.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 +39 -0
- package/README.md +7 -3
- package/dist/cli/main.cjs +16 -5
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +16 -5
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/{index-DgIAN5k5.d.cts → index-CxkGbILp.d.cts} +23 -3
- package/dist/{index-DgIAN5k5.d.ts → index-CxkGbILp.d.ts} +23 -3
- package/dist/index.cjs +16 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +15 -4
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +1 -1
- package/dist/nest/index.d.ts +1 -1
- package/dist/nest/index.js +15 -4
- package/dist/nest/index.js.map +1 -1
- package/package.json +6 -2
- package/skills/codegen-serialization-output/SKILL.md +148 -0
- package/skills/codegen-setup/SKILL.md +159 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-
|
|
1
|
+
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-CxkGbILp.cjs';
|
|
2
2
|
import 'ts-morph';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-
|
|
1
|
+
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-CxkGbILp.js';
|
|
2
2
|
import 'ts-morph';
|
|
@@ -189,21 +189,40 @@ interface ValidationAdapter {
|
|
|
189
189
|
inferType(schemaConst: string): string;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
/**
|
|
193
|
-
|
|
192
|
+
/**
|
|
193
|
+
* A validation adapter instance. No adapter is bundled in core — import one from
|
|
194
|
+
* its own package (`zodAdapter`/`valibotAdapter`/`arktypeAdapter`) or pass a custom
|
|
195
|
+
* object. String shortcuts (`'zod'` etc.) are intentionally not part of this type:
|
|
196
|
+
* they always threw at runtime, so the type guides you to an imported instance.
|
|
197
|
+
*/
|
|
198
|
+
type ValidationOption = ValidationAdapter;
|
|
194
199
|
/**
|
|
195
200
|
* Resolve a `validation` config value to a {@link ValidationAdapter}. No adapter is
|
|
196
201
|
* bundled in core — the zod/valibot/arktype adapters ship as their own packages.
|
|
197
202
|
* Import the adapter instance and pass it directly (it passes through here). A
|
|
198
203
|
* custom adapter object also passes through.
|
|
199
204
|
*
|
|
205
|
+
* The parameter also accepts a `string` so the runtime guard still fires for JS
|
|
206
|
+
* callers / untyped configs that pass a removed string shortcut (e.g. `'zod'`):
|
|
207
|
+
* those throw a helpful error pointing at the adapter package. TypeScript users
|
|
208
|
+
* are steered away from strings by the narrowed {@link ValidationOption} type.
|
|
209
|
+
*
|
|
200
210
|
* @example
|
|
201
211
|
* import { zodAdapter } from '@dudousxd/nestjs-codegen-zod';
|
|
202
212
|
* defineConfig({ validation: zodAdapter });
|
|
203
213
|
*/
|
|
204
|
-
declare function resolveAdapter(option: ValidationOption): ValidationAdapter;
|
|
214
|
+
declare function resolveAdapter(option: ValidationOption | string): ValidationAdapter;
|
|
205
215
|
|
|
206
216
|
interface UserConfig {
|
|
217
|
+
/**
|
|
218
|
+
* Print schema-translation advisories to the terminal (e.g. "@X is not
|
|
219
|
+
* translatable to a client validation schema", "T is a recursive type"). These
|
|
220
|
+
* are always preserved in generated output as `// warning:` comments regardless;
|
|
221
|
+
* this only controls the duplicate terminal chatter, which is off by default.
|
|
222
|
+
*
|
|
223
|
+
* @default false
|
|
224
|
+
*/
|
|
225
|
+
debug?: boolean;
|
|
207
226
|
/**
|
|
208
227
|
* Codegen extensions, applied in order. Each may augment the route IR
|
|
209
228
|
* (`transformRoutes`), contribute extra output files (`emitFiles`), and — once a
|
|
@@ -356,6 +375,7 @@ interface ResolvedMocksConfig {
|
|
|
356
375
|
baseUrl: string;
|
|
357
376
|
}
|
|
358
377
|
interface ResolvedConfig {
|
|
378
|
+
debug: boolean;
|
|
359
379
|
extensions: CodegenExtension[];
|
|
360
380
|
validation: ValidationAdapter;
|
|
361
381
|
pages: ResolvedPagesConfig | null;
|
|
@@ -189,21 +189,40 @@ interface ValidationAdapter {
|
|
|
189
189
|
inferType(schemaConst: string): string;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
/**
|
|
193
|
-
|
|
192
|
+
/**
|
|
193
|
+
* A validation adapter instance. No adapter is bundled in core — import one from
|
|
194
|
+
* its own package (`zodAdapter`/`valibotAdapter`/`arktypeAdapter`) or pass a custom
|
|
195
|
+
* object. String shortcuts (`'zod'` etc.) are intentionally not part of this type:
|
|
196
|
+
* they always threw at runtime, so the type guides you to an imported instance.
|
|
197
|
+
*/
|
|
198
|
+
type ValidationOption = ValidationAdapter;
|
|
194
199
|
/**
|
|
195
200
|
* Resolve a `validation` config value to a {@link ValidationAdapter}. No adapter is
|
|
196
201
|
* bundled in core — the zod/valibot/arktype adapters ship as their own packages.
|
|
197
202
|
* Import the adapter instance and pass it directly (it passes through here). A
|
|
198
203
|
* custom adapter object also passes through.
|
|
199
204
|
*
|
|
205
|
+
* The parameter also accepts a `string` so the runtime guard still fires for JS
|
|
206
|
+
* callers / untyped configs that pass a removed string shortcut (e.g. `'zod'`):
|
|
207
|
+
* those throw a helpful error pointing at the adapter package. TypeScript users
|
|
208
|
+
* are steered away from strings by the narrowed {@link ValidationOption} type.
|
|
209
|
+
*
|
|
200
210
|
* @example
|
|
201
211
|
* import { zodAdapter } from '@dudousxd/nestjs-codegen-zod';
|
|
202
212
|
* defineConfig({ validation: zodAdapter });
|
|
203
213
|
*/
|
|
204
|
-
declare function resolveAdapter(option: ValidationOption): ValidationAdapter;
|
|
214
|
+
declare function resolveAdapter(option: ValidationOption | string): ValidationAdapter;
|
|
205
215
|
|
|
206
216
|
interface UserConfig {
|
|
217
|
+
/**
|
|
218
|
+
* Print schema-translation advisories to the terminal (e.g. "@X is not
|
|
219
|
+
* translatable to a client validation schema", "T is a recursive type"). These
|
|
220
|
+
* are always preserved in generated output as `// warning:` comments regardless;
|
|
221
|
+
* this only controls the duplicate terminal chatter, which is off by default.
|
|
222
|
+
*
|
|
223
|
+
* @default false
|
|
224
|
+
*/
|
|
225
|
+
debug?: boolean;
|
|
207
226
|
/**
|
|
208
227
|
* Codegen extensions, applied in order. Each may augment the route IR
|
|
209
228
|
* (`transformRoutes`), contribute extra output files (`emitFiles`), and — once a
|
|
@@ -356,6 +375,7 @@ interface ResolvedMocksConfig {
|
|
|
356
375
|
baseUrl: string;
|
|
357
376
|
}
|
|
358
377
|
interface ResolvedConfig {
|
|
378
|
+
debug: boolean;
|
|
359
379
|
extensions: CodegenExtension[];
|
|
360
380
|
validation: ValidationAdapter;
|
|
361
381
|
pages: ResolvedPagesConfig | null;
|
package/dist/index.cjs
CHANGED
|
@@ -173,6 +173,7 @@ function applyDefaults(userConfig, cwd) {
|
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
return {
|
|
176
|
+
debug: userConfig.debug ?? false,
|
|
176
177
|
extensions: userConfig.extensions ?? [],
|
|
177
178
|
// Non-null: validateUserConfig() above throws when `validation` is absent.
|
|
178
179
|
validation: resolveAdapter(userConfig.validation),
|
|
@@ -2142,8 +2143,18 @@ function buildEmpty() {
|
|
|
2142
2143
|
].join("\n");
|
|
2143
2144
|
}
|
|
2144
2145
|
|
|
2146
|
+
// src/util/debug-log.ts
|
|
2147
|
+
var debugEnabled = false;
|
|
2148
|
+
function setCodegenDebug(enabled) {
|
|
2149
|
+
debugEnabled = enabled;
|
|
2150
|
+
}
|
|
2151
|
+
function debugWarn(message) {
|
|
2152
|
+
if (debugEnabled) console.warn(`[nestjs-codegen] ${message}`);
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2145
2155
|
// src/generate.ts
|
|
2146
2156
|
async function generate(config, inputRoutes = []) {
|
|
2157
|
+
setCodegenDebug(config.debug);
|
|
2147
2158
|
const extensions = config.extensions ?? [];
|
|
2148
2159
|
let routes = inputRoutes;
|
|
2149
2160
|
const ctx = createExtensionContext(config, () => routes);
|
|
@@ -2739,7 +2750,7 @@ function buildProperty(prop, classFile, ctx) {
|
|
|
2739
2750
|
ctx.warnedDecorators.add(name);
|
|
2740
2751
|
const msg = `@${name} is not translatable to a client validation schema and was skipped (server-only validation).`;
|
|
2741
2752
|
ctx.warnings.push(msg);
|
|
2742
|
-
|
|
2753
|
+
debugWarn(msg);
|
|
2743
2754
|
}
|
|
2744
2755
|
}
|
|
2745
2756
|
}
|
|
@@ -2790,7 +2801,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2790
2801
|
ctx.warnedDecorators.add(`recursive:${reserved}`);
|
|
2791
2802
|
const msg = `${className} is a recursive type; the generated schema validates it via a lazy self-reference.`;
|
|
2792
2803
|
ctx.warnings.push(msg);
|
|
2793
|
-
|
|
2804
|
+
debugWarn(msg);
|
|
2794
2805
|
}
|
|
2795
2806
|
return { kind: "lazyRef", name: reserved };
|
|
2796
2807
|
}
|
|
@@ -2799,7 +2810,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2799
2810
|
ctx.warnedDecorators.add(`deep:${className}`);
|
|
2800
2811
|
const msg = `${className} nesting is too deep to expand; the generated schema uses unknown for it.`;
|
|
2801
2812
|
ctx.warnings.push(msg);
|
|
2802
|
-
|
|
2813
|
+
debugWarn(msg);
|
|
2803
2814
|
}
|
|
2804
2815
|
return { kind: "unknown", note: "nesting too deep \u2014 not expanded" };
|
|
2805
2816
|
}
|
|
@@ -2940,7 +2951,7 @@ function enumSchemaFromDecorator(decorator, classFile, ctx) {
|
|
|
2940
2951
|
if (!ctx.warnedDecorators.has(`IsEnum:${name}`)) {
|
|
2941
2952
|
ctx.warnedDecorators.add(`IsEnum:${name}`);
|
|
2942
2953
|
ctx.warnings.push(msg);
|
|
2943
|
-
|
|
2954
|
+
debugWarn(msg);
|
|
2944
2955
|
}
|
|
2945
2956
|
return { kind: "unknown", note: `@IsEnum(${name}): enum not resolvable to literals` };
|
|
2946
2957
|
}
|
|
@@ -4617,7 +4628,7 @@ function createChainModuleRenderer(opts) {
|
|
|
4617
4628
|
}
|
|
4618
4629
|
|
|
4619
4630
|
// src/index.ts
|
|
4620
|
-
var VERSION = "0.
|
|
4631
|
+
var VERSION = "0.10.0";
|
|
4621
4632
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4622
4633
|
0 && (module.exports = {
|
|
4623
4634
|
CodegenError,
|