@dudousxd/nestjs-codegen 0.6.0 → 0.7.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 +23 -0
- package/dist/cli/main.cjs +21 -8
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +21 -8
- 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-_qRai4M3.d.cts → index-DgIAN5k5.d.cts} +16 -1
- package/dist/{index-_qRai4M3.d.ts → index-DgIAN5k5.d.ts} +16 -1
- package/dist/index.cjs +21 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -6
- package/dist/index.d.ts +13 -6
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +20 -7
- 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 +20 -7
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/nest/index.cjs
CHANGED
|
@@ -150,6 +150,7 @@ function applyDefaults(userConfig, cwd) {
|
|
|
150
150
|
},
|
|
151
151
|
app,
|
|
152
152
|
fetcher: userConfig.fetcher ?? null,
|
|
153
|
+
serialization: userConfig.serialization ?? "json",
|
|
153
154
|
forms: {
|
|
154
155
|
enabled: userConfig.forms?.enabled ?? true,
|
|
155
156
|
watch: userConfig.forms?.watch ?? "src/**/*.dto.ts",
|
|
@@ -2814,7 +2815,11 @@ function emitFilterQueryTypeArgs(c) {
|
|
|
2814
2815
|
function emitFilterQueryType(c) {
|
|
2815
2816
|
return `import('@dudousxd/nestjs-filter-client').TypedFilterQuery<${emitFilterQueryTypeArgs(c)}>`;
|
|
2816
2817
|
}
|
|
2817
|
-
function buildResponseType(c, outDir) {
|
|
2818
|
+
function buildResponseType(c, outDir, serialization) {
|
|
2819
|
+
const raw = rawResponseType(c, outDir);
|
|
2820
|
+
return serialization === "json" ? `Jsonify<${raw}>` : raw;
|
|
2821
|
+
}
|
|
2822
|
+
function rawResponseType(c, outDir) {
|
|
2818
2823
|
const respRef = c.contractSource.responseRef;
|
|
2819
2824
|
if (c.contractSource.stream) {
|
|
2820
2825
|
if (respRef) return respRef.isArray ? `Array<${respRef.name}>` : respRef.name;
|
|
@@ -2837,7 +2842,7 @@ function buildErrorType(c) {
|
|
|
2837
2842
|
}
|
|
2838
2843
|
return c.contractSource.error ?? "unknown";
|
|
2839
2844
|
}
|
|
2840
|
-
function emitRouterTypeBlock(tree, indent, outDir) {
|
|
2845
|
+
function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
2841
2846
|
const pad = " ".repeat(indent);
|
|
2842
2847
|
const lines = [];
|
|
2843
2848
|
for (const [key, node] of tree) {
|
|
@@ -2850,7 +2855,7 @@ function emitRouterTypeBlock(tree, indent, outDir) {
|
|
|
2850
2855
|
const query = queryRef ? queryRef.isArray ? `Array<${queryRef.name}>` : queryRef.name : isFilterQuery ? emitFilterQueryType(c) : c.contractSource.query ?? "never";
|
|
2851
2856
|
const bodyRef = c.contractSource.bodyRef;
|
|
2852
2857
|
const body = method === "GET" ? "never" : bodyRef ? bodyRef.isArray ? `Array<${bodyRef.name}>` : bodyRef.name : c.contractSource.body ?? "never";
|
|
2853
|
-
const response = buildResponseType(c, outDir);
|
|
2858
|
+
const response = buildResponseType(c, outDir, serialization);
|
|
2854
2859
|
const error = buildErrorType(c);
|
|
2855
2860
|
const params = buildParamsType(c.params);
|
|
2856
2861
|
const safeMethod = JSON.stringify(method);
|
|
@@ -2862,7 +2867,7 @@ function emitRouterTypeBlock(tree, indent, outDir) {
|
|
|
2862
2867
|
);
|
|
2863
2868
|
} else {
|
|
2864
2869
|
lines.push(`${pad}${objKey}: {`);
|
|
2865
|
-
lines.push(...emitRouterTypeBlock(node.children, indent + 2, outDir));
|
|
2870
|
+
lines.push(...emitRouterTypeBlock(node.children, indent + 2, outDir, serialization));
|
|
2866
2871
|
lines.push(`${pad}};`);
|
|
2867
2872
|
}
|
|
2868
2873
|
}
|
|
@@ -3067,6 +3072,7 @@ var EMPTY_PATH_NAMESPACE = [
|
|
|
3067
3072
|
];
|
|
3068
3073
|
function buildApiFile(routes, outDir, opts = {}) {
|
|
3069
3074
|
const fetcherImportPath = opts.fetcherImportPath;
|
|
3075
|
+
const serialization = opts.serialization ?? "json";
|
|
3070
3076
|
const extensions = opts.extensions ?? [];
|
|
3071
3077
|
const { layer } = resolveApiSlots(extensions);
|
|
3072
3078
|
const memberExts = extensions.filter((e) => e.apiMembers);
|
|
@@ -3123,6 +3129,9 @@ function buildApiFile(routes, outDir, opts = {}) {
|
|
|
3123
3129
|
);
|
|
3124
3130
|
const runtimeImport = fetcherImportPath ?? "@dudousxd/nestjs-client";
|
|
3125
3131
|
lines.push(`import type { Fetcher } from '${runtimeImport}';`);
|
|
3132
|
+
if (serialization === "json" && contracted.length > 0) {
|
|
3133
|
+
lines.push(`import type { Jsonify } from '${runtimeImport}';`);
|
|
3134
|
+
}
|
|
3126
3135
|
if (importsByFile.size > 0 && outDir) {
|
|
3127
3136
|
lines.push("");
|
|
3128
3137
|
const emittedNames = /* @__PURE__ */ new Set();
|
|
@@ -3182,7 +3191,7 @@ function buildApiFile(routes, outDir, opts = {}) {
|
|
|
3182
3191
|
insertIntoTree(tree, segments, leaf, name);
|
|
3183
3192
|
}
|
|
3184
3193
|
lines.push("export type ApiRouter = {");
|
|
3185
|
-
lines.push(...emitRouterTypeBlock(tree, 2, outDir ?? ""));
|
|
3194
|
+
lines.push(...emitRouterTypeBlock(tree, 2, outDir ?? "", serialization));
|
|
3186
3195
|
lines.push("};");
|
|
3187
3196
|
lines.push("");
|
|
3188
3197
|
lines.push(...emitReqHelper());
|
|
@@ -4200,6 +4209,7 @@ async function generate(config, inputRoutes = []) {
|
|
|
4200
4209
|
if (hasContracts) {
|
|
4201
4210
|
await emitApi(routes, config.codegen.outDir, {
|
|
4202
4211
|
...config.fetcher?.importPath ? { fetcherImportPath: config.fetcher.importPath } : {},
|
|
4212
|
+
serialization: config.serialization,
|
|
4203
4213
|
extensions,
|
|
4204
4214
|
ctx
|
|
4205
4215
|
});
|
|
@@ -4299,6 +4309,7 @@ async function watch(config, onChange) {
|
|
|
4299
4309
|
return NO_OP_WATCHER;
|
|
4300
4310
|
}
|
|
4301
4311
|
let discovery = null;
|
|
4312
|
+
let lastRoutes = [];
|
|
4302
4313
|
async function getDiscovery() {
|
|
4303
4314
|
if (discovery === null) {
|
|
4304
4315
|
discovery = await PersistentDiscovery.create({
|
|
@@ -4312,13 +4323,14 @@ async function watch(config, onChange) {
|
|
|
4312
4323
|
}
|
|
4313
4324
|
try {
|
|
4314
4325
|
const initialRoutes = (await getDiscovery()).discover();
|
|
4326
|
+
lastRoutes = initialRoutes;
|
|
4315
4327
|
await generate(config, initialRoutes);
|
|
4316
4328
|
} catch (err) {
|
|
4317
4329
|
console.warn(
|
|
4318
4330
|
`[nestjs-codegen] Initial route discovery failed, falling back to pages-only: ${err instanceof Error ? err.message : String(err)}`
|
|
4319
4331
|
);
|
|
4320
4332
|
try {
|
|
4321
|
-
await generate(config);
|
|
4333
|
+
await generate(config, lastRoutes);
|
|
4322
4334
|
} catch {
|
|
4323
4335
|
}
|
|
4324
4336
|
}
|
|
@@ -4336,7 +4348,7 @@ async function watch(config, onChange) {
|
|
|
4336
4348
|
pagesDebounceTimer = setTimeout(async () => {
|
|
4337
4349
|
pagesDebounceTimer = void 0;
|
|
4338
4350
|
try {
|
|
4339
|
-
await generate(config);
|
|
4351
|
+
await generate(config, lastRoutes);
|
|
4340
4352
|
} catch (err) {
|
|
4341
4353
|
console.error(
|
|
4342
4354
|
"[nestjs-codegen] Pages generation failed:",
|
|
@@ -4367,6 +4379,7 @@ async function watch(config, onChange) {
|
|
|
4367
4379
|
pendingChangedPaths.clear();
|
|
4368
4380
|
try {
|
|
4369
4381
|
const routes = await (await getDiscovery()).rediscover(changed);
|
|
4382
|
+
lastRoutes = routes;
|
|
4370
4383
|
await generate(config, routes);
|
|
4371
4384
|
} catch (err) {
|
|
4372
4385
|
console.error(
|