@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/dist/index.cjs
CHANGED
|
@@ -106,18 +106,23 @@ async function fileExists(filePath) {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
async function importTs(filePath) {
|
|
109
|
-
|
|
109
|
+
const fileUrl = (0, import_node_url.pathToFileURL)(filePath).href;
|
|
110
110
|
try {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
return await import(fileUrl);
|
|
112
|
+
} catch (nativeError) {
|
|
113
|
+
let tsImport;
|
|
114
|
+
try {
|
|
115
|
+
const tsxEsm = await import("tsx/esm/api");
|
|
116
|
+
tsImport = tsxEsm.tsImport;
|
|
117
|
+
} catch {
|
|
118
|
+
throw new ConfigError(
|
|
119
|
+
"Failed to load config: `tsx` is required for loading TypeScript config files. Install it as a dev dependency: pnpm add -D tsx",
|
|
120
|
+
{ cause: nativeError }
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
const parentURL = (0, import_node_url.pathToFileURL)(`${filePath}__parent__`).href;
|
|
124
|
+
return tsImport(fileUrl, { parentURL });
|
|
117
125
|
}
|
|
118
|
-
const parentURL = (0, import_node_url.pathToFileURL)(`${filePath}__parent__`).href;
|
|
119
|
-
const fileUrl = (0, import_node_url.pathToFileURL)(filePath).href;
|
|
120
|
-
return tsImport(fileUrl, { parentURL });
|
|
121
126
|
}
|
|
122
127
|
function resolveAbsolute(cwd, p) {
|
|
123
128
|
if ((0, import_node_path.isAbsolute)(p)) return p;
|
|
@@ -3565,14 +3570,33 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3565
3570
|
for (const param of method.getParameters()) {
|
|
3566
3571
|
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
3567
3572
|
if (!queryDecorator) continue;
|
|
3568
|
-
|
|
3569
|
-
if (queryArgs.length > 0) continue;
|
|
3573
|
+
if (queryDecorator.getArguments().length > 0) continue;
|
|
3570
3574
|
const typeNode = param.getTypeNode();
|
|
3571
3575
|
if (typeNode) {
|
|
3572
3576
|
return resolveTypeNodeToString(typeNode, sourceFile, project, 3);
|
|
3573
3577
|
}
|
|
3574
3578
|
}
|
|
3575
|
-
|
|
3579
|
+
const entries = [];
|
|
3580
|
+
for (const param of method.getParameters()) {
|
|
3581
|
+
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
3582
|
+
if (!queryDecorator) continue;
|
|
3583
|
+
const queryArgs = queryDecorator.getArguments();
|
|
3584
|
+
const nameArg = queryArgs[0];
|
|
3585
|
+
if (!nameArg || !import_ts_morph7.Node.isStringLiteral(nameArg)) continue;
|
|
3586
|
+
const queryName = nameArg.getLiteralValue();
|
|
3587
|
+
const typeNode = param.getTypeNode();
|
|
3588
|
+
const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
3589
|
+
entries.push(`${queryName}${isParamOptional(param) ? "?" : ""}: ${queryType}`);
|
|
3590
|
+
}
|
|
3591
|
+
return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
|
|
3592
|
+
}
|
|
3593
|
+
function isParamOptional(param) {
|
|
3594
|
+
if (param.hasQuestionToken() || param.hasInitializer()) return true;
|
|
3595
|
+
const typeNode = param.getTypeNode();
|
|
3596
|
+
if (typeNode && import_ts_morph7.Node.isUnionTypeNode(typeNode)) {
|
|
3597
|
+
return typeNode.getTypeNodes().some((t) => t.getKind() === import_ts_morph7.SyntaxKind.UndefinedKeyword);
|
|
3598
|
+
}
|
|
3599
|
+
return false;
|
|
3576
3600
|
}
|
|
3577
3601
|
function extractParamsType(method, sourceFile, project) {
|
|
3578
3602
|
const entries = [];
|
|
@@ -4593,7 +4617,7 @@ function createChainModuleRenderer(opts) {
|
|
|
4593
4617
|
}
|
|
4594
4618
|
|
|
4595
4619
|
// src/index.ts
|
|
4596
|
-
var VERSION = "0.
|
|
4620
|
+
var VERSION = "0.8.0";
|
|
4597
4621
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4598
4622
|
0 && (module.exports = {
|
|
4599
4623
|
CodegenError,
|