@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/cli/main.js CHANGED
@@ -44,18 +44,23 @@ async function fileExists(filePath) {
44
44
  }
45
45
  }
46
46
  async function importTs(filePath) {
47
- let tsImport;
47
+ const fileUrl = pathToFileURL(filePath).href;
48
48
  try {
49
- const tsxEsm = await import("tsx/esm/api");
50
- tsImport = tsxEsm.tsImport;
51
- } catch {
52
- throw new ConfigError(
53
- "Failed to load config: `tsx` is required for loading TypeScript config files. Install it as a dev dependency: pnpm add -D tsx"
54
- );
49
+ return await import(fileUrl);
50
+ } catch (nativeError) {
51
+ let tsImport;
52
+ try {
53
+ const tsxEsm = await import("tsx/esm/api");
54
+ tsImport = tsxEsm.tsImport;
55
+ } catch {
56
+ throw new ConfigError(
57
+ "Failed to load config: `tsx` is required for loading TypeScript config files. Install it as a dev dependency: pnpm add -D tsx",
58
+ { cause: nativeError }
59
+ );
60
+ }
61
+ const parentURL = pathToFileURL(`${filePath}__parent__`).href;
62
+ return tsImport(fileUrl, { parentURL });
55
63
  }
56
- const parentURL = pathToFileURL(`${filePath}__parent__`).href;
57
- const fileUrl = pathToFileURL(filePath).href;
58
- return tsImport(fileUrl, { parentURL });
59
64
  }
60
65
  function resolveAbsolute(cwd, p) {
61
66
  if (isAbsolute(p)) return p;
@@ -3512,14 +3517,33 @@ function extractQueryType(method, sourceFile, project) {
3512
3517
  for (const param of method.getParameters()) {
3513
3518
  const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
3514
3519
  if (!queryDecorator) continue;
3515
- const queryArgs = queryDecorator.getArguments();
3516
- if (queryArgs.length > 0) continue;
3520
+ if (queryDecorator.getArguments().length > 0) continue;
3517
3521
  const typeNode = param.getTypeNode();
3518
3522
  if (typeNode) {
3519
3523
  return resolveTypeNodeToString(typeNode, sourceFile, project, 3);
3520
3524
  }
3521
3525
  }
3522
- return null;
3526
+ const entries = [];
3527
+ for (const param of method.getParameters()) {
3528
+ const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
3529
+ if (!queryDecorator) continue;
3530
+ const queryArgs = queryDecorator.getArguments();
3531
+ const nameArg = queryArgs[0];
3532
+ if (!nameArg || !Node6.isStringLiteral(nameArg)) continue;
3533
+ const queryName = nameArg.getLiteralValue();
3534
+ const typeNode = param.getTypeNode();
3535
+ const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
3536
+ entries.push(`${queryName}${isParamOptional(param) ? "?" : ""}: ${queryType}`);
3537
+ }
3538
+ return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
3539
+ }
3540
+ function isParamOptional(param) {
3541
+ if (param.hasQuestionToken() || param.hasInitializer()) return true;
3542
+ const typeNode = param.getTypeNode();
3543
+ if (typeNode && Node6.isUnionTypeNode(typeNode)) {
3544
+ return typeNode.getTypeNodes().some((t) => t.getKind() === SyntaxKind3.UndefinedKeyword);
3545
+ }
3546
+ return false;
3523
3547
  }
3524
3548
  function extractParamsType(method, sourceFile, project) {
3525
3549
  const entries = [];
@@ -4457,7 +4481,7 @@ async function watch(config, onChange) {
4457
4481
  }
4458
4482
 
4459
4483
  // src/index.ts
4460
- var VERSION = "0.7.0";
4484
+ var VERSION = "0.8.0";
4461
4485
 
4462
4486
  // src/cli/codegen.ts
4463
4487
  async function runCodegen(opts = {}) {