nestjs-trpc 1.3.2 → 1.3.4

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":"procedure.factory.d.ts","sourceRoot":"","sources":["../../lib/factories/procedure.factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,SAAS,EAAE,MAAM,cAAc,CAAC;AAO1D,OAAO,EACL,wBAAwB,EAGxB,mBAAmB,EAEpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAoB,MAAM,eAAe,CAAC;AAGjE,qBACa,gBAAgB;IAOf,OAAO,CAAC,SAAS;IAL7B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAG/C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmB;gBAE/B,SAAS,EAAE,SAAS;IAExC,aAAa,CACX,QAAQ,EAAE,OAAO,EACjB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAClC,KAAK,CAAC,wBAAwB,CAAC;IAMlC,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,wBAAwB;IAuBhC,mBAAmB,CACjB,UAAU,EAAE,KAAK,CAAC,wBAAwB,CAAC,EAC3C,QAAQ,EAAE,GAAG,EACb,oBAAoB,EAAE,MAAM,EAC5B,gBAAgB,EAAE,mBAAmB,EACrC,iBAAiB,EAAE,cAAc,GAAG,SAAS,GAC5C,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAiCtB,OAAO,CAAC,uBAAuB;IAgB/B,OAAO,CAAC,6BAA6B;IAYrC,OAAO,CAAC,wBAAwB;IA2BhC,OAAO,CAAC,yBAAyB;CA4BlC"}
1
+ {"version":3,"file":"procedure.factory.d.ts","sourceRoot":"","sources":["../../lib/factories/procedure.factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,SAAS,EAAE,MAAM,cAAc,CAAC;AAO1D,OAAO,EACL,wBAAwB,EAGxB,mBAAmB,EAEpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAoB,MAAM,eAAe,CAAC;AAIjE,qBACa,gBAAgB;IAOf,OAAO,CAAC,SAAS;IAL7B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAG/C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmB;gBAE/B,SAAS,EAAE,SAAS;IAExC,aAAa,CACX,QAAQ,EAAE,OAAO,EACjB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAClC,KAAK,CAAC,wBAAwB,CAAC;IAMlC,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,wBAAwB;IAuBhC,mBAAmB,CACjB,UAAU,EAAE,KAAK,CAAC,wBAAwB,CAAC,EAC3C,QAAQ,EAAE,GAAG,EACb,oBAAoB,EAAE,MAAM,EAC5B,gBAAgB,EAAE,mBAAmB,EACrC,iBAAiB,EAAE,cAAc,GAAG,SAAS,GAC5C,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAiCtB,OAAO,CAAC,uBAAuB;IAgB/B,OAAO,CAAC,6BAA6B;IAYrC,OAAO,CAAC,wBAAwB;IA4BhC,OAAO,CAAC,yBAAyB;CA0BlC"}
@@ -6,6 +6,7 @@ const common_1 = require("@nestjs/common");
6
6
  const core_1 = require("@nestjs/core");
7
7
  const trpc_constants_1 = require("../trpc.constants");
8
8
  const factory_interface_1 = require("../interfaces/factory.interface");
9
+ const trpc_enum_1 = require("../trpc.enum");
9
10
  let ProcedureFactory = class ProcedureFactory {
10
11
  constructor(moduleRef) {
11
12
  this.moduleRef = moduleRef;
@@ -56,7 +57,7 @@ let ProcedureFactory = class ProcedureFactory {
56
57
  createCustomProcedureInstance(procedure, def) {
57
58
  const customProcedureInstance = this.moduleRef.get(def, { strict: false });
58
59
  if (typeof customProcedureInstance.use === 'function') {
59
- //@ts-ignore
60
+ //@ts-expect-error this is expected since the type is correct.
60
61
  return procedure.use((opts) => customProcedureInstance.use(opts));
61
62
  }
62
63
  return procedure;
@@ -73,8 +74,9 @@ let ProcedureFactory = class ProcedureFactory {
73
74
  return undefined;
74
75
  }
75
76
  if (param.type === factory_interface_1.ProcedureParamDecoratorType.Input) {
76
- //@ts-ignore
77
- return param.key != null ? opts[param.type]?.[param.key] : opts[param.type];
77
+ return param['key'] != null
78
+ ? opts[param.type]?.[param['key']]
79
+ : opts[param.type];
78
80
  }
79
81
  if (param.type === factory_interface_1.ProcedureParamDecoratorType.Options) {
80
82
  return opts;
@@ -93,11 +95,9 @@ let ProcedureFactory = class ProcedureFactory {
93
95
  const procedureInvocation = (opts) => {
94
96
  return routerInstance[procedureName](...this.serializeProcedureParams(opts, params));
95
97
  };
96
- return type === 'mutation'
97
- ? //@ts-ignore
98
- procedureWithOutput.mutation(procedureInvocation)
99
- : //@ts-ignore
100
- procedureWithOutput.query(procedureInvocation);
98
+ return type === trpc_enum_1.ProcedureType.Mutation
99
+ ? procedureWithOutput.mutation(procedureInvocation)
100
+ : procedureWithOutput.query(procedureInvocation);
101
101
  }
102
102
  };
103
103
  exports.ProcedureFactory = ProcedureFactory;
@@ -1 +1 @@
1
- {"version":3,"file":"router.factory.d.ts","sourceRoot":"","sources":["../../lib/factories/router.factory.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,UAAU,EACX,MAAM,iCAAiC,CAAC;AAIzC,qBACa,aAAa;IAExB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAG/C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IAGrD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IAErD,UAAU,IAAI,KAAK,CAAC,cAAc,CAAC;IAenC,OAAO,CAAC,wBAAwB;IA0BhC,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAkCzF"}
1
+ {"version":3,"file":"router.factory.d.ts","sourceRoot":"","sources":["../../lib/factories/router.factory.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,UAAU,EACX,MAAM,iCAAiC,CAAC;AAIzC,qBACa,aAAa;IAExB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAG/C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IAGrD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IAErD,UAAU,IAAI,KAAK,CAAC,cAAc,CAAC;IAenC,OAAO,CAAC,wBAAwB;IA0BhC,eAAe,CACb,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,mBAAmB,GAC7B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAiCvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"trpc.generator.d.ts","sourceRoot":"","sources":["../../lib/generators/trpc.generator.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,YAAY,EACb,MAAM,gBAAgB,CAAC;AAYxB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAMvC,qBACa,aAAc,YAAW,YAAY;IAChD,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAe;IACtD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAc;IACvD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAiC;IAG1E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAG/C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAuB;IAGzD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoB;IAGnD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAGrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAG/C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IAGrD,OAAO,CAAC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AAC;IAGrD,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAG,WAAW,CAAC;IAG7C,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAG,aAAa,CAAC;IAGjD,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAG,aAAa,CAAC;gBAE7B,SAAS,EAAE,SAAS;IAE3B,KAAK,CAAC,OAAO,EAAE,iBAAiB;CAsD9C"}
@@ -20,7 +20,7 @@ let TRPCDriver = class TRPCDriver {
20
20
  throw new Error(`No support for current HttpAdapter: ${platformName}`);
21
21
  }
22
22
  const app = httpAdapter.getInstance();
23
- //@ts-ignore Ignoring typescript here since it's the same type, yet it still isn't able to infer it.
23
+ //@ts-expect-error Ignoring typescript here since it's the same type, yet it still isn't able to infer it.
24
24
  const { procedure, router } = server_1.initTRPC.context().create({
25
25
  ...(options.transformer != null
26
26
  ? { transformer: options.transformer }
@@ -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
  }
@@ -1,33 +1,35 @@
1
1
  import { ConsoleLogger, Inject, Injectable, Type } from '@nestjs/common';
2
2
  import { MetadataScanner, ModuleRef } from '@nestjs/core';
3
3
  import {
4
- PROCEDURE_METADATA_KEY,
5
- PROCEDURE_TYPE_KEY,
6
4
  MIDDLEWARE_KEY,
5
+ PROCEDURE_METADATA_KEY,
7
6
  PROCEDURE_PARAM_METADATA_KEY,
7
+ PROCEDURE_TYPE_KEY,
8
8
  } from '../trpc.constants';
9
9
  import {
10
10
  ProcedureFactoryMetadata,
11
+ ProcedureImplementation,
11
12
  ProcedureParamDecorator,
12
13
  ProcedureParamDecoratorType,
13
14
  TRPCPublicProcedure,
14
- ProcedureImplementation,
15
15
  } from '../interfaces/factory.interface';
16
- import { TRPCMiddleware, ProcedureOptions } from '../interfaces';
16
+ import { ProcedureOptions, TRPCMiddleware } from '../interfaces';
17
17
  import type { Class } from 'type-fest';
18
+ import { ProcedureType } from '../trpc.enum';
18
19
 
19
20
  @Injectable()
20
21
  export class ProcedureFactory {
21
22
  @Inject(ConsoleLogger)
22
23
  private readonly consoleLogger!: ConsoleLogger;
23
-
24
+
24
25
  @Inject(MetadataScanner)
25
26
  private readonly metadataScanner!: MetadataScanner;
26
27
 
27
28
  constructor(private moduleRef: ModuleRef) {}
28
-
29
+
29
30
  getProcedures(
30
31
  instance: unknown,
32
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
31
33
  prototype: Record<string, Function>,
32
34
  ): Array<ProcedureFactoryMetadata> {
33
35
  return this.metadataScanner.scanFromPrototype(instance, prototype, (name) =>
@@ -44,6 +46,7 @@ export class ProcedureFactory {
44
46
 
45
47
  private extractProcedureMetadata(
46
48
  name: string,
49
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
47
50
  prototype: Record<string, Function>,
48
51
  ): ProcedureFactoryMetadata {
49
52
  const callback = prototype[name] as ProcedureImplementation;
@@ -126,7 +129,7 @@ export class ProcedureFactory {
126
129
  ): TRPCPublicProcedure {
127
130
  const customProcedureInstance = this.moduleRef.get(def, { strict: false });
128
131
  if (typeof customProcedureInstance.use === 'function') {
129
- //@ts-ignore
132
+ //@ts-expect-error this is expected since the type is correct.
130
133
  return procedure.use((opts) => customProcedureInstance.use(opts));
131
134
  }
132
135
  return procedure;
@@ -136,10 +139,10 @@ export class ProcedureFactory {
136
139
  opts: ProcedureOptions,
137
140
  params: Array<ProcedureParamDecorator> | undefined,
138
141
  ): Array<undefined | unknown> {
139
- if(params == null) {
142
+ if (params == null) {
140
143
  return [];
141
144
  }
142
- const args = new Array(Math.max(...params.map((val) => val.index)) + 1)
145
+ return new Array(Math.max(...params.map((val) => val.index)) + 1)
143
146
  .fill(undefined)
144
147
  .map((_val, idx) => {
145
148
  const param = params.find((param) => param.index === idx);
@@ -147,16 +150,15 @@ export class ProcedureFactory {
147
150
  return undefined;
148
151
  }
149
152
  if (param.type === ProcedureParamDecoratorType.Input) {
150
- //@ts-ignore
151
- return param.key != null ? opts[param.type]?.[param.key] : opts[param.type];
153
+ return param['key'] != null
154
+ ? opts[param.type]?.[param['key']]
155
+ : opts[param.type];
152
156
  }
153
157
  if (param.type === ProcedureParamDecoratorType.Options) {
154
158
  return opts;
155
159
  }
156
160
  return opts[param.type];
157
161
  });
158
-
159
- return args;
160
162
  }
161
163
 
162
164
  private createSerializedProcedure(
@@ -181,10 +183,8 @@ export class ProcedureFactory {
181
183
  );
182
184
  };
183
185
 
184
- return type === 'mutation'
185
- ? //@ts-ignore
186
- procedureWithOutput.mutation(procedureInvocation)
187
- : //@ts-ignore
188
- procedureWithOutput.query(procedureInvocation);
186
+ return type === ProcedureType.Mutation
187
+ ? procedureWithOutput.mutation(procedureInvocation as any)
188
+ : procedureWithOutput.query(procedureInvocation as any);
189
189
  }
190
190
  }
@@ -63,7 +63,10 @@ export class RouterFactory {
63
63
  return { name, instance, alias: router.alias, middlewares };
64
64
  }
65
65
 
66
- serializeRoutes(router: TRPCRouter, procedure: TRPCPublicProcedure): Record<string, any> {
66
+ serializeRoutes(
67
+ router: TRPCRouter,
68
+ procedure: TRPCPublicProcedure,
69
+ ): Record<string, any> {
67
70
  const routers = this.getRouters();
68
71
  const routerSchema = Object.create({});
69
72
 
@@ -92,7 +95,6 @@ export class RouterFactory {
92
95
 
93
96
  // TODO: To get this working with `trpc` v11, we need to remove the `router()` method from here.
94
97
  routerSchema[camelCasedRouterName] = router(routerProcedures);
95
-
96
98
  });
97
99
 
98
100
  return routerSchema;
@@ -5,12 +5,7 @@ import {
5
5
  Injectable,
6
6
  OnModuleInit,
7
7
  } from '@nestjs/common';
8
- import {
9
- Project,
10
- CompilerOptions,
11
- ScriptTarget,
12
- ModuleKind,
13
- } from 'ts-morph';
8
+ import { Project, CompilerOptions, ScriptTarget, ModuleKind } from 'ts-morph';
14
9
  import {
15
10
  generateStaticDeclaration,
16
11
  saveOrOverrideFile,
@@ -144,15 +139,15 @@ export class TRPCGenerator implements OnModuleInit {
144
139
  middleware,
145
140
  this.project,
146
141
  );
147
-
148
- if(middlewareInterface != null) {
149
- helperTypesSourceFile.addInterface({
150
- isExported: true,
151
- name: `${middlewareInterface.name}Context`,
152
- extends: ['Context'],
153
- properties: middlewareInterface.properties,
154
- });
155
- }
142
+
143
+ if (middlewareInterface != null) {
144
+ helperTypesSourceFile.addInterface({
145
+ isExported: true,
146
+ name: `${middlewareInterface.name}Context`,
147
+ extends: ['Context'],
148
+ properties: middlewareInterface.properties,
149
+ });
150
+ }
156
151
  }
157
152
 
158
153
  await saveOrOverrideFile(helperTypesSourceFile);
@@ -37,7 +37,7 @@ export class TRPCDriver<
37
37
 
38
38
  const app = httpAdapter.getInstance<ExpressApplication>();
39
39
 
40
- //@ts-ignore Ignoring typescript here since it's the same type, yet it still isn't able to infer it.
40
+ //@ts-expect-error Ignoring typescript here since it's the same type, yet it still isn't able to infer it.
41
41
  const { procedure, router } = initTRPC.context().create({
42
42
  ...(options.transformer != null
43
43
  ? { transformer: options.transformer }
@@ -58,7 +58,6 @@ export class TRPCDriver<
58
58
  })
59
59
  : null;
60
60
 
61
-
62
61
  app.use(
63
62
  options.basePath ?? '/trpc',
64
63
  trpcExpress.createExpressMiddleware({
@@ -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.4",
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",