@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/dist/index.cjs CHANGED
@@ -106,18 +106,23 @@ async function fileExists(filePath) {
106
106
  }
107
107
  }
108
108
  async function importTs(filePath) {
109
- let tsImport;
109
+ const fileUrl = (0, import_node_url.pathToFileURL)(filePath).href;
110
110
  try {
111
- const tsxEsm = await import("tsx/esm/api");
112
- tsImport = tsxEsm.tsImport;
113
- } catch {
114
- throw new ConfigError(
115
- "Failed to load config: `tsx` is required for loading TypeScript config files. Install it as a dev dependency: pnpm add -D tsx"
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
- const queryArgs = queryDecorator.getArguments();
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
- return null;
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.7.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,