@dudousxd/nestjs-codegen 0.7.0 → 0.8.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 +12 -0
- package/dist/cli/main.cjs +38 -14
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +38 -14
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +38 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +38 -14
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +22 -3
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +22 -3
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @dudousxd/nestjs-codegen
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 685583d: feat(core): synthesize the route `query` type from individual `@Query('name')` params. Handlers using named query params (e.g. `@Query('years') years?: number[]`, `@Query('q') q?: string | string[]`) now emit a typed `query` object — one property per param, keyed by the string-literal name, typed by the parameter annotation, optional when the param has `?` / a default / a `| undefined` type — instead of `query: never`. The existing whole-object `@Query() dto` form is unchanged and still wins when both forms appear on the same handler.
|
|
8
|
+
|
|
9
|
+
## 0.7.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b8a8ce4: fix(core): load the TypeScript config via Node's native type-stripping first, falling back to tsx — unblocks the codegen CLI on Node 25 where tsx 4.22.4's resolver appends a `?namespace=<ts>` query that Node 25's stricter `finalizeResolution` rejects with `ERR_MODULE_NOT_FOUND`. tsx remains the fallback for older Node versions without native type stripping.
|
|
14
|
+
|
|
3
15
|
## 0.7.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/cli/main.cjs
CHANGED
|
@@ -78,18 +78,23 @@ async function fileExists(filePath) {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
async function importTs(filePath) {
|
|
81
|
-
|
|
81
|
+
const fileUrl = (0, import_node_url.pathToFileURL)(filePath).href;
|
|
82
82
|
try {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
return await import(fileUrl);
|
|
84
|
+
} catch (nativeError) {
|
|
85
|
+
let tsImport;
|
|
86
|
+
try {
|
|
87
|
+
const tsxEsm = await import("tsx/esm/api");
|
|
88
|
+
tsImport = tsxEsm.tsImport;
|
|
89
|
+
} catch {
|
|
90
|
+
throw new ConfigError(
|
|
91
|
+
"Failed to load config: `tsx` is required for loading TypeScript config files. Install it as a dev dependency: pnpm add -D tsx",
|
|
92
|
+
{ cause: nativeError }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const parentURL = (0, import_node_url.pathToFileURL)(`${filePath}__parent__`).href;
|
|
96
|
+
return tsImport(fileUrl, { parentURL });
|
|
89
97
|
}
|
|
90
|
-
const parentURL = (0, import_node_url.pathToFileURL)(`${filePath}__parent__`).href;
|
|
91
|
-
const fileUrl = (0, import_node_url.pathToFileURL)(filePath).href;
|
|
92
|
-
return tsImport(fileUrl, { parentURL });
|
|
93
98
|
}
|
|
94
99
|
function resolveAbsolute(cwd, p) {
|
|
95
100
|
if ((0, import_node_path.isAbsolute)(p)) return p;
|
|
@@ -3531,14 +3536,33 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3531
3536
|
for (const param of method.getParameters()) {
|
|
3532
3537
|
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
3533
3538
|
if (!queryDecorator) continue;
|
|
3534
|
-
|
|
3535
|
-
if (queryArgs.length > 0) continue;
|
|
3539
|
+
if (queryDecorator.getArguments().length > 0) continue;
|
|
3536
3540
|
const typeNode = param.getTypeNode();
|
|
3537
3541
|
if (typeNode) {
|
|
3538
3542
|
return resolveTypeNodeToString(typeNode, sourceFile, project, 3);
|
|
3539
3543
|
}
|
|
3540
3544
|
}
|
|
3541
|
-
|
|
3545
|
+
const entries = [];
|
|
3546
|
+
for (const param of method.getParameters()) {
|
|
3547
|
+
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
3548
|
+
if (!queryDecorator) continue;
|
|
3549
|
+
const queryArgs = queryDecorator.getArguments();
|
|
3550
|
+
const nameArg = queryArgs[0];
|
|
3551
|
+
if (!nameArg || !import_ts_morph7.Node.isStringLiteral(nameArg)) continue;
|
|
3552
|
+
const queryName = nameArg.getLiteralValue();
|
|
3553
|
+
const typeNode = param.getTypeNode();
|
|
3554
|
+
const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
3555
|
+
entries.push(`${queryName}${isParamOptional(param) ? "?" : ""}: ${queryType}`);
|
|
3556
|
+
}
|
|
3557
|
+
return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
|
|
3558
|
+
}
|
|
3559
|
+
function isParamOptional(param) {
|
|
3560
|
+
if (param.hasQuestionToken() || param.hasInitializer()) return true;
|
|
3561
|
+
const typeNode = param.getTypeNode();
|
|
3562
|
+
if (typeNode && import_ts_morph7.Node.isUnionTypeNode(typeNode)) {
|
|
3563
|
+
return typeNode.getTypeNodes().some((t) => t.getKind() === import_ts_morph7.SyntaxKind.UndefinedKeyword);
|
|
3564
|
+
}
|
|
3565
|
+
return false;
|
|
3542
3566
|
}
|
|
3543
3567
|
function extractParamsType(method, sourceFile, project) {
|
|
3544
3568
|
const entries = [];
|
|
@@ -4476,7 +4500,7 @@ async function watch(config, onChange) {
|
|
|
4476
4500
|
}
|
|
4477
4501
|
|
|
4478
4502
|
// src/index.ts
|
|
4479
|
-
var VERSION = "0.
|
|
4503
|
+
var VERSION = "0.8.0";
|
|
4480
4504
|
|
|
4481
4505
|
// src/cli/codegen.ts
|
|
4482
4506
|
async function runCodegen(opts = {}) {
|