nestjs-trpc 1.3.2 → 1.3.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"type.util.d.ts","sourceRoot":"","sources":["../../lib/utils/type.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,0BAA0B,EAE3B,MAAM,mCAAmC,CAAC;AAG3C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAKjE;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,0BAA0B,GACpC,MAAM,CAeR;AAsCD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,CAiGR"}
1
+ {"version":3,"file":"type.util.d.ts","sourceRoot":"","sources":["../../lib/utils/type.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,0BAA0B,EAE3B,MAAM,mCAAmC,CAAC;AAE3C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAKjE;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,0BAA0B,GACpC,MAAM,CAeR;AA2FD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,CAiGR"}
@@ -4,7 +4,6 @@ exports.findCtxOutProperty = findCtxOutProperty;
4
4
  exports.generateProcedureString = generateProcedureString;
5
5
  exports.flattenZodSchema = flattenZodSchema;
6
6
  const ts_morph_1 = require("ts-morph");
7
- const path = require("node:path");
8
7
  function findCtxOutProperty(type) {
9
8
  const typeText = type.getText();
10
9
  const ctxOutMatch = typeText.match(/_ctx_out:\s*{([^}]*)}/);
@@ -12,7 +11,7 @@ function findCtxOutProperty(type) {
12
11
  }
13
12
  function generateProcedureString(procedure) {
14
13
  const { name, decorators } = procedure;
15
- const decorator = decorators.find((d) => d.name === 'Mutation' || d.name === 'Query');
14
+ const decorator = decorators.find((decorator) => decorator.name === 'Mutation' || decorator.name === 'Query');
16
15
  if (!decorator) {
17
16
  return '';
18
17
  }
@@ -21,6 +20,44 @@ function generateProcedureString(procedure) {
21
20
  .join('');
22
21
  return `${name}: publicProcedure${decoratorArgumentsArray}.${decorator.name.toLowerCase()}(async () => "PLACEHOLDER_DO_NOT_REMOVE" as any )`;
23
22
  }
23
+ /**
24
+ * https://github.com/dsherret/ts-morph/issues/327
25
+ * Note that if the module resolution of the compiler is Classic then it won't resolve those implicit index.ts module specifiers.
26
+ * So for example, if the moduleResolution compiler option isn't explicitly set then setting the module
27
+ * compiler option to anything but ModuleKind.CommonJS will cause the module resolution kind to resolve to Classic.
28
+ * Additionally, if moduleResolution and the module compiler option isn't set,
29
+ * then a script target of ES2015 and above will also use Classic module resolution.
30
+ */
31
+ function resolveBarrelFileImport(barrelSourceFile, name, project) {
32
+ // Traverse through export declarations to find the actual source of the named import
33
+ for (const exportDeclaration of barrelSourceFile.getExportDeclarations()) {
34
+ const exportedSourceFile = exportDeclaration.getModuleSpecifierSourceFile();
35
+ if (exportedSourceFile == null)
36
+ continue;
37
+ // Check if the named export is explicitly re-exported
38
+ const namedExports = exportDeclaration.getNamedExports();
39
+ if (namedExports.length > 0) {
40
+ const matchingExport = namedExports.find((e) => e.getName() === name);
41
+ if (matchingExport) {
42
+ return exportedSourceFile;
43
+ }
44
+ }
45
+ else {
46
+ // Handle `export * from ...` case: recursively resolve the export
47
+ const schemaVariable = exportedSourceFile.getVariableDeclaration(name);
48
+ if (schemaVariable) {
49
+ return exportedSourceFile;
50
+ }
51
+ else {
52
+ // Continue resolving if it's another barrel file
53
+ const baseSourceFile = resolveBarrelFileImport(exportedSourceFile, name, project);
54
+ if (baseSourceFile)
55
+ return baseSourceFile;
56
+ }
57
+ }
58
+ }
59
+ return undefined;
60
+ }
24
61
  function buildSourceFileImportsMap(sourceFile, project) {
25
62
  const sourceFileImportsMap = new Map();
26
63
  const importDeclarations = sourceFile.getImportDeclarations();
@@ -28,18 +65,24 @@ function buildSourceFileImportsMap(sourceFile, project) {
28
65
  const namedImports = importDeclaration.getNamedImports();
29
66
  for (const namedImport of namedImports) {
30
67
  const name = namedImport.getName();
31
- const moduleSpecifier = importDeclaration.getModuleSpecifierValue();
32
- const resolvedPath = path.resolve(path.dirname(sourceFile.getFilePath()), moduleSpecifier + '.ts');
33
- const importedSourceFile = project.addSourceFileAtPathIfExists(resolvedPath);
34
- if (!importedSourceFile)
68
+ const importedSourceFile = importDeclaration.getModuleSpecifierSourceFile();
69
+ if (importedSourceFile == null) {
35
70
  continue;
36
- const schemaVariable = importedSourceFile.getVariableDeclaration(name);
37
- if (schemaVariable) {
71
+ }
72
+ const resolvedSourceFile = importedSourceFile.getFilePath().endsWith('index.ts') &&
73
+ importedSourceFile.getVariableDeclaration(name) == null
74
+ ? resolveBarrelFileImport(importedSourceFile, name, project)
75
+ : importedSourceFile;
76
+ if (resolvedSourceFile == null) {
77
+ continue;
78
+ }
79
+ const schemaVariable = resolvedSourceFile.getVariableDeclaration(name);
80
+ if (schemaVariable != null) {
38
81
  const initializer = schemaVariable.getInitializer();
39
82
  if (initializer) {
40
83
  sourceFileImportsMap.set(name, {
41
84
  initializer,
42
- sourceFile: importedSourceFile,
85
+ sourceFile: resolvedSourceFile,
43
86
  });
44
87
  }
45
88
  }
@@ -3,7 +3,6 @@ import {
3
3
  ProcedureGeneratorMetadata,
4
4
  SourceFileImportsMap,
5
5
  } from '../interfaces/generator.interface';
6
- import * as path from 'node:path';
7
6
 
8
7
  export function findCtxOutProperty(type: Type): string | undefined {
9
8
  const typeText = type.getText();
@@ -17,7 +16,7 @@ export function generateProcedureString(
17
16
  ): string {
18
17
  const { name, decorators } = procedure;
19
18
  const decorator = decorators.find(
20
- (d) => d.name === 'Mutation' || d.name === 'Query',
19
+ (decorator) => decorator.name === 'Mutation' || decorator.name === 'Query',
21
20
  );
22
21
 
23
22
  if (!decorator) {
@@ -31,6 +30,51 @@ export function generateProcedureString(
31
30
  return `${name}: publicProcedure${decoratorArgumentsArray}.${decorator.name.toLowerCase()}(async () => "PLACEHOLDER_DO_NOT_REMOVE" as any )`;
32
31
  }
33
32
 
33
+ /**
34
+ * https://github.com/dsherret/ts-morph/issues/327
35
+ * Note that if the module resolution of the compiler is Classic then it won't resolve those implicit index.ts module specifiers.
36
+ * So for example, if the moduleResolution compiler option isn't explicitly set then setting the module
37
+ * compiler option to anything but ModuleKind.CommonJS will cause the module resolution kind to resolve to Classic.
38
+ * Additionally, if moduleResolution and the module compiler option isn't set,
39
+ * then a script target of ES2015 and above will also use Classic module resolution.
40
+ */
41
+ function resolveBarrelFileImport(
42
+ barrelSourceFile: SourceFile,
43
+ name: string,
44
+ project: Project,
45
+ ): SourceFile | undefined {
46
+ // Traverse through export declarations to find the actual source of the named import
47
+ for (const exportDeclaration of barrelSourceFile.getExportDeclarations()) {
48
+ const exportedSourceFile = exportDeclaration.getModuleSpecifierSourceFile();
49
+ if (exportedSourceFile == null) continue;
50
+
51
+ // Check if the named export is explicitly re-exported
52
+ const namedExports = exportDeclaration.getNamedExports();
53
+ if (namedExports.length > 0) {
54
+ const matchingExport = namedExports.find((e) => e.getName() === name);
55
+ if (matchingExport) {
56
+ return exportedSourceFile;
57
+ }
58
+ } else {
59
+ // Handle `export * from ...` case: recursively resolve the export
60
+ const schemaVariable = exportedSourceFile.getVariableDeclaration(name);
61
+ if (schemaVariable) {
62
+ return exportedSourceFile;
63
+ } else {
64
+ // Continue resolving if it's another barrel file
65
+ const baseSourceFile = resolveBarrelFileImport(
66
+ exportedSourceFile,
67
+ name,
68
+ project,
69
+ );
70
+ if (baseSourceFile) return baseSourceFile;
71
+ }
72
+ }
73
+ }
74
+
75
+ return undefined;
76
+ }
77
+
34
78
  function buildSourceFileImportsMap(
35
79
  sourceFile: SourceFile,
36
80
  project: Project,
@@ -42,22 +86,30 @@ function buildSourceFileImportsMap(
42
86
  const namedImports = importDeclaration.getNamedImports();
43
87
  for (const namedImport of namedImports) {
44
88
  const name = namedImport.getName();
45
- const moduleSpecifier = importDeclaration.getModuleSpecifierValue();
46
- const resolvedPath = path.resolve(
47
- path.dirname(sourceFile.getFilePath()),
48
- moduleSpecifier + '.ts',
49
- );
50
89
  const importedSourceFile =
51
- project.addSourceFileAtPathIfExists(resolvedPath);
52
- if (!importedSourceFile) continue;
90
+ importDeclaration.getModuleSpecifierSourceFile();
53
91
 
54
- const schemaVariable = importedSourceFile.getVariableDeclaration(name);
55
- if (schemaVariable) {
92
+ if (importedSourceFile == null) {
93
+ continue;
94
+ }
95
+
96
+ const resolvedSourceFile =
97
+ importedSourceFile.getFilePath().endsWith('index.ts') &&
98
+ importedSourceFile.getVariableDeclaration(name) == null
99
+ ? resolveBarrelFileImport(importedSourceFile, name, project)
100
+ : importedSourceFile;
101
+
102
+ if (resolvedSourceFile == null) {
103
+ continue;
104
+ }
105
+
106
+ const schemaVariable = resolvedSourceFile.getVariableDeclaration(name);
107
+ if (schemaVariable != null) {
56
108
  const initializer = schemaVariable.getInitializer();
57
109
  if (initializer) {
58
110
  sourceFileImportsMap.set(name, {
59
111
  initializer,
60
- sourceFile: importedSourceFile,
112
+ sourceFile: resolvedSourceFile,
61
113
  });
62
114
  }
63
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-trpc",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "homepage": "https://nestjs-trpc.io",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./lib/index.ts",
@@ -42,7 +42,7 @@
42
42
  "peerDependencies": {
43
43
  "@nestjs/common": "^9.3.8 || ^10.0.0",
44
44
  "@nestjs/core": "^9.3.8 || ^10.0.0",
45
- "@trpc/server": "^10.18.0",
45
+ "@trpc/server": "^10.0.0",
46
46
  "reflect-metadata": "^0.1.13 || ^0.2.0",
47
47
  "rxjs": "7.8.1",
48
48
  "zod": "^3.14.0"
@@ -64,7 +64,7 @@
64
64
  "tsconfig-paths": "^4.2.0",
65
65
  "type-fest": "^4.21.0",
66
66
  "typescript": "5.5.3",
67
- "zod": "^3.14.0"
67
+ "zod": "^3.14.4"
68
68
  },
69
69
  "dependencies": {
70
70
  "func-loc": "^0.1.16",