@trpc/server 10.0.0-proxy-beta.11 → 10.0.0-proxy-beta.13

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.
Files changed (52) hide show
  1. package/dist/adapters/aws-lambda/index.js +3 -3
  2. package/dist/adapters/aws-lambda/index.mjs +3 -3
  3. package/dist/adapters/express.js +3 -3
  4. package/dist/adapters/express.mjs +3 -3
  5. package/dist/adapters/fastify/index.js +2 -2
  6. package/dist/adapters/fastify/index.mjs +2 -2
  7. package/dist/adapters/fetch/index.js +2 -2
  8. package/dist/adapters/fetch/index.mjs +2 -2
  9. package/dist/adapters/next.js +3 -3
  10. package/dist/adapters/next.mjs +3 -3
  11. package/dist/adapters/node-http/index.js +3 -3
  12. package/dist/adapters/node-http/index.mjs +3 -3
  13. package/dist/adapters/standalone.js +3 -3
  14. package/dist/adapters/standalone.mjs +3 -3
  15. package/dist/core/index.d.ts +1 -1
  16. package/dist/core/index.d.ts.map +1 -1
  17. package/dist/core/initTRPC.d.ts +6 -1
  18. package/dist/core/initTRPC.d.ts.map +1 -1
  19. package/dist/core/internals/procedureBuilder.d.ts +24 -24
  20. package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
  21. package/dist/core/procedure.d.ts +7 -15
  22. package/dist/core/procedure.d.ts.map +1 -1
  23. package/dist/core/router.d.ts +8 -3
  24. package/dist/core/router.d.ts.map +1 -1
  25. package/dist/deprecated/interop.d.ts +2 -2
  26. package/dist/deprecated/interop.d.ts.map +1 -1
  27. package/dist/index-5a6a2e91.mjs +48 -0
  28. package/dist/index-62d46c97.js +51 -0
  29. package/dist/index.js +3 -3
  30. package/dist/index.mjs +5 -5
  31. package/dist/internals.d.ts +1 -2
  32. package/dist/internals.d.ts.map +1 -1
  33. package/dist/{nodeHTTPRequestHandler-4062f93e.mjs → nodeHTTPRequestHandler-1bf460cc.mjs} +1 -1
  34. package/dist/{nodeHTTPRequestHandler-7b588236.js → nodeHTTPRequestHandler-71717219.js} +1 -1
  35. package/dist/{resolveHTTPResponse-3af47381.js → resolveHTTPResponse-c6e31b55.js} +2 -3
  36. package/dist/{resolveHTTPResponse-8b09a709.mjs → resolveHTTPResponse-f2b378b6.mjs} +2 -3
  37. package/dist/{router-9960eb02.js → router-15f9618e.js} +1 -1
  38. package/dist/{router-dabfef7f.mjs → router-28a2c129.mjs} +1 -1
  39. package/dist/shared/createProxy/index.d.ts +6 -4
  40. package/dist/shared/createProxy/index.d.ts.map +1 -1
  41. package/dist/shared/index.js +3 -2
  42. package/dist/shared/index.mjs +1 -1
  43. package/package.json +6 -6
  44. package/src/core/index.ts +1 -0
  45. package/src/core/internals/procedureBuilder.ts +38 -47
  46. package/src/core/procedure.ts +7 -18
  47. package/src/core/router.ts +22 -15
  48. package/src/deprecated/interop.ts +2 -12
  49. package/src/internals.ts +4 -6
  50. package/src/shared/createProxy/index.ts +40 -33
  51. package/dist/index-354358bb.mjs +0 -39
  52. package/dist/index-b8627db5.js +0 -41
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { m as mergeWithoutOverrides, d as defaultFormatter, a as defaultTransformer, c as createRouterFactory, g as getDataTransformer } from './resolveHTTPResponse-8b09a709.mjs';
2
- export { b as assertNotBrowser, e as callProcedure, a as defaultTransformer, g as getDataTransformer, p as procedureTypes, r as resolveHTTPResponse } from './resolveHTTPResponse-8b09a709.mjs';
3
- import { c as createBuilder, a as createMiddlewareFactory } from './router-dabfef7f.mjs';
4
- export { b as createInputMiddleware, d as createOutputMiddleware, r as router } from './router-dabfef7f.mjs';
1
+ import { m as mergeWithoutOverrides, d as defaultFormatter, a as defaultTransformer, c as createRouterFactory, g as getDataTransformer } from './resolveHTTPResponse-f2b378b6.mjs';
2
+ export { b as assertNotBrowser, e as callProcedure, a as defaultTransformer, g as getDataTransformer, p as procedureTypes, r as resolveHTTPResponse } from './resolveHTTPResponse-f2b378b6.mjs';
3
+ import { c as createBuilder, a as createMiddlewareFactory } from './router-28a2c129.mjs';
4
+ export { b as createInputMiddleware, d as createOutputMiddleware, r as router } from './router-28a2c129.mjs';
5
5
  export { T as TRPCError } from './TRPCError-281ac25a.mjs';
6
6
  import './codes-7d21f749.mjs';
7
- import './index-354358bb.mjs';
7
+ import './index-5a6a2e91.mjs';
8
8
  import './transformTRPCResponse-c8138d5f.mjs';
9
9
 
10
10
  function mergeRouters(...routerList) {
@@ -3,9 +3,8 @@
3
3
  */
4
4
  export type { DefaultErrorShape } from './error/formatter';
5
5
  export type { mergeRoutersGeneric } from './core/internals/__generated__/mergeRoutersGeneric';
6
- export type { ProcedureBuilder } from './core/internals/procedureBuilder';
6
+ export type { ProcedureBuilder, BuildProcedure, } from './core/internals/procedureBuilder';
7
7
  export type { Overwrite, unsetMarker } from './core/internals/utils';
8
8
  export type { MiddlewareFunction } from './core/middleware';
9
9
  export type { Router, RouterDef } from './core/router';
10
- export type { MutationProcedure, QueryProcedure, SubscriptionProcedure, } from './core/procedure';
11
10
  //# sourceMappingURL=internals.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internals.d.ts","sourceRoot":"","sources":["../src/internals.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,YAAY,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AAC9F,YAAY,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACvD,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,qBAAqB,GACtB,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"internals.d.ts","sourceRoot":"","sources":["../src/internals.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,YAAY,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AAC9F,YAAY,EACV,gBAAgB,EAChB,cAAc,GACf,MAAM,mCAAmC,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC"}
@@ -1,4 +1,4 @@
1
- import { b as assertNotBrowser, r as resolveHTTPResponse } from './resolveHTTPResponse-8b09a709.mjs';
1
+ import { b as assertNotBrowser, r as resolveHTTPResponse } from './resolveHTTPResponse-f2b378b6.mjs';
2
2
  import { T as TRPCError } from './TRPCError-281ac25a.mjs';
3
3
 
4
4
  async function getPostBody({ req , maxBodySize }) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var resolveHTTPResponse = require('./resolveHTTPResponse-3af47381.js');
3
+ var resolveHTTPResponse = require('./resolveHTTPResponse-c6e31b55.js');
4
4
  var TRPCError = require('./TRPCError-fe9113e5.js');
5
5
 
6
6
  async function getPostBody({ req , maxBodySize }) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  var TRPCError = require('./TRPCError-fe9113e5.js');
4
4
  var codes = require('./codes-76c38a34.js');
5
- var index = require('./index-b8627db5.js');
5
+ var index = require('./index-62d46c97.js');
6
6
  var transformTRPCResponse = require('./transformTRPCResponse-11ac69cc.js');
7
7
 
8
8
  /* istanbul ignore file */ function assertNotBrowser() {
@@ -137,7 +137,6 @@ const emptyRouter = {
137
137
  */ 'then'
138
138
  ];
139
139
  /**
140
- *
141
140
  * @internal
142
141
  */ function createRouterFactory(defaults) {
143
142
  return function createRouterInner(opts) {
@@ -188,7 +187,7 @@ const emptyRouter = {
188
187
  transformer: _def.transformer,
189
188
  errorFormatter: _def.errorFormatter,
190
189
  createCaller (ctx) {
191
- const proxy = index.createProxy(({ path , args })=>{
190
+ const proxy = index.createRecursiveProxy(({ path , args })=>{
192
191
  // interop mode
193
192
  if (path.length === 1 && procedureTypes.includes(path[0])) {
194
193
  return callProcedure({
@@ -1,6 +1,6 @@
1
1
  import { T as TRPCError, g as getTRPCErrorFromUnknown, a as getCauseFromUnknown } from './TRPCError-281ac25a.mjs';
2
2
  import { i as invert, T as TRPC_ERROR_CODES_BY_KEY } from './codes-7d21f749.mjs';
3
- import { c as createProxy } from './index-354358bb.mjs';
3
+ import { c as createRecursiveProxy } from './index-5a6a2e91.mjs';
4
4
  import { t as transformTRPCResponse } from './transformTRPCResponse-c8138d5f.mjs';
5
5
 
6
6
  /* istanbul ignore file */ function assertNotBrowser() {
@@ -135,7 +135,6 @@ const emptyRouter = {
135
135
  */ 'then'
136
136
  ];
137
137
  /**
138
- *
139
138
  * @internal
140
139
  */ function createRouterFactory(defaults) {
141
140
  return function createRouterInner(opts) {
@@ -186,7 +185,7 @@ const emptyRouter = {
186
185
  transformer: _def.transformer,
187
186
  errorFormatter: _def.errorFormatter,
188
187
  createCaller (ctx) {
189
- const proxy = createProxy(({ path , args })=>{
188
+ const proxy = createRecursiveProxy(({ path , args })=>{
190
189
  // interop mode
191
190
  if (path.length === 1 && procedureTypes.includes(path[0])) {
192
191
  return callProcedure({
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var resolveHTTPResponse = require('./resolveHTTPResponse-3af47381.js');
3
+ var resolveHTTPResponse = require('./resolveHTTPResponse-c6e31b55.js');
4
4
  var codes = require('./codes-76c38a34.js');
5
5
  var TRPCError = require('./TRPCError-fe9113e5.js');
6
6
 
@@ -1,4 +1,4 @@
1
- import { m as mergeWithoutOverrides, b as assertNotBrowser, c as createRouterFactory, d as defaultFormatter, f as getHTTPStatusCodeFromError, a as defaultTransformer } from './resolveHTTPResponse-8b09a709.mjs';
1
+ import { m as mergeWithoutOverrides, b as assertNotBrowser, c as createRouterFactory, d as defaultFormatter, f as getHTTPStatusCodeFromError, a as defaultTransformer } from './resolveHTTPResponse-f2b378b6.mjs';
2
2
  import { T as TRPC_ERROR_CODES_BY_KEY } from './codes-7d21f749.mjs';
3
3
  import { T as TRPCError, a as getCauseFromUnknown, g as getTRPCErrorFromUnknown } from './TRPCError-281ac25a.mjs';
4
4
 
@@ -6,12 +6,14 @@ declare type ProxyCallback = (opts: ProxyCallbackOptions) => unknown;
6
6
  /**
7
7
  * Creates a proxy that calls the callback with the path and arguments
8
8
  *
9
- * @remarks
10
- * This has a special handling to manage if it's accidentally treated like
11
- * a PromiseLike.
9
+ * @internal
10
+ */
11
+ export declare const createRecursiveProxy: (callback: ProxyCallback) => unknown;
12
+ /**
13
+ * Used in place of `new Proxy` where each handler will map 1 level deep to another value.
12
14
  *
13
15
  * @internal
14
16
  */
15
- export declare const createProxy: (callback: ProxyCallback) => unknown;
17
+ export declare const createFlatProxy: <TFaux>(callback: (path: keyof TFaux & string) => any) => TFaux;
16
18
  export {};
17
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/server/src/shared/createProxy/index.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AACD,aAAK,aAAa,GAAG,CAAC,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC;AAoC7D;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,aAAc,aAAa,YACvB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/server/src/shared/createProxy/index.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AACD,aAAK,aAAa,GAAG,CAAC,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC;AA2B7D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,aAAc,aAAa,YAC5B,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,eAAe,oDACgB,GAAG,UAY9C,CAAC"}
@@ -2,8 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../index-b8627db5.js');
5
+ var index = require('../index-62d46c97.js');
6
6
 
7
7
 
8
8
 
9
- exports.createProxy = index.createProxy;
9
+ exports.createFlatProxy = index.createFlatProxy;
10
+ exports.createRecursiveProxy = index.createRecursiveProxy;
@@ -1 +1 @@
1
- export { c as createProxy } from '../index-354358bb.mjs';
1
+ export { a as createFlatProxy, c as createRecursiveProxy } from '../index-5a6a2e91.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "10.0.0-proxy-beta.11",
3
+ "version": "10.0.0-proxy-beta.13",
4
4
  "description": "tRPC Server",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -122,10 +122,10 @@
122
122
  "@testing-library/jest-dom": "^5.16.5",
123
123
  "@testing-library/react": "^13.4.0",
124
124
  "@testing-library/user-event": "^14.4.3",
125
- "@trpc/client": "10.0.0-proxy-beta.11",
126
- "@trpc/next": "10.0.0-proxy-beta.11",
127
- "@trpc/react": "10.0.0-proxy-beta.11",
128
- "@trpc/server": "10.0.0-proxy-beta.11",
125
+ "@trpc/client": "10.0.0-proxy-beta.13",
126
+ "@trpc/next": "10.0.0-proxy-beta.13",
127
+ "@trpc/react": "10.0.0-proxy-beta.13",
128
+ "@trpc/server": "10.0.0-proxy-beta.13",
129
129
  "@types/aws-lambda": "^8.10.97",
130
130
  "@types/express": "^4.17.12",
131
131
  "@types/hash-sum": "^1.0.0",
@@ -161,5 +161,5 @@
161
161
  "yup": "^0.32.8",
162
162
  "zod": "^3.0.0"
163
163
  },
164
- "gitHead": "d6196218c3ed0857a2f8624f150c6be187176665"
164
+ "gitHead": "017ac71d5b0cc37d6c1fa22d03377a99a17b6dde"
165
165
  }
package/src/core/index.ts CHANGED
@@ -2,6 +2,7 @@ export type {
2
2
  AnyRouter,
3
3
  ProcedureRecord,
4
4
  ProcedureRouterRecord,
5
+ CreateRouterInner,
5
6
  } from './router';
6
7
  export { callProcedure } from './router';
7
8
  export type {
@@ -13,10 +13,8 @@ import {
13
13
  AnyProcedure,
14
14
  AnyQueryProcedure,
15
15
  AnySubscriptionProcedure,
16
- MutationProcedure,
16
+ Procedure,
17
17
  ProcedureParams,
18
- QueryProcedure,
19
- SubscriptionProcedure,
20
18
  } from '../procedure';
21
19
  import { ProcedureType } from '../types';
22
20
  import { RootConfig } from './config';
@@ -44,12 +42,45 @@ type CreateProcedureReturnInput<
44
42
  _output_out: FallbackValue<TNext['_output_out'], TPrev['_output_out']>;
45
43
  }>;
46
44
 
45
+ /**
46
+ * @internal
47
+ */
48
+ export interface BuildProcedure<
49
+ TType extends ProcedureType,
50
+ TParams extends ProcedureParams,
51
+ TOutput,
52
+ > extends Procedure<
53
+ TType,
54
+ UnsetMarker extends TParams['_output_out']
55
+ ? OverwriteKnown<
56
+ TParams,
57
+ {
58
+ _output_in: TOutput;
59
+ _output_out: TOutput;
60
+ }
61
+ >
62
+ : TParams
63
+ > {}
64
+
47
65
  type OverwriteIfDefined<TType, TWith> = UnsetMarker extends TType
48
66
  ? TWith
49
67
  : FlatOverwrite<TType, TWith>;
50
68
 
51
69
  type ErrorMessage<TMessage extends string> = TMessage;
52
70
 
71
+ export type ProcedureBuilderDef<TParams extends ProcedureParams> = {
72
+ inputs: Parser[];
73
+ output?: Parser;
74
+ meta?: TParams['_meta'];
75
+ resolver?: ProcedureBuilderResolver;
76
+ middlewares: ProcedureBuilderMiddleware[];
77
+ mutation?: boolean;
78
+ query?: boolean;
79
+ subscription?: boolean;
80
+ };
81
+
82
+ export type AnyProcedureBuilderDef = ProcedureBuilderDef<any>;
83
+
53
84
  export interface ProcedureBuilder<TParams extends ProcedureParams> {
54
85
  /**
55
86
  * Add an input parser to the procedure.
@@ -119,17 +150,7 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
119
150
  resolver: (
120
151
  opts: ResolveOptions<TParams>,
121
152
  ) => MaybePromise<FallbackValue<TParams['_output_in'], TOutput>>,
122
- ): UnsetMarker extends TParams['_output_out']
123
- ? QueryProcedure<
124
- OverwriteKnown<
125
- TParams,
126
- {
127
- _output_in: TOutput;
128
- _output_out: TOutput;
129
- }
130
- >
131
- >
132
- : QueryProcedure<TParams>;
153
+ ): BuildProcedure<'query', TParams, TOutput>;
133
154
 
134
155
  /**
135
156
  * Mutation procedure
@@ -138,17 +159,7 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
138
159
  resolver: (
139
160
  opts: ResolveOptions<TParams>,
140
161
  ) => MaybePromise<FallbackValue<TParams['_output_in'], TOutput>>,
141
- ): UnsetMarker extends TParams['_output_out']
142
- ? MutationProcedure<
143
- OverwriteKnown<
144
- TParams,
145
- {
146
- _output_in: TOutput;
147
- _output_out: TOutput;
148
- }
149
- >
150
- >
151
- : MutationProcedure<TParams>;
162
+ ): BuildProcedure<'mutation', TParams, TOutput>;
152
163
 
153
164
  /**
154
165
  * Mutation procedure
@@ -157,34 +168,14 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
157
168
  resolver: (
158
169
  opts: ResolveOptions<TParams>,
159
170
  ) => MaybePromise<FallbackValue<TParams['_output_in'], TOutput>>,
160
- ): UnsetMarker extends TParams['_output_out']
161
- ? SubscriptionProcedure<
162
- OverwriteKnown<
163
- TParams,
164
- {
165
- _output_in: TOutput;
166
- _output_out: TOutput;
167
- }
168
- >
169
- >
170
- : SubscriptionProcedure<TParams>;
171
+ ): BuildProcedure<'subscription', TParams, TOutput>;
171
172
  /**
172
173
  * @internal
173
174
  */
174
- _def: {
175
- inputs: Parser[];
176
- output?: Parser;
177
- meta?: TParams['_meta'];
178
- resolver?: ProcedureBuilderResolver;
179
- middlewares: ProcedureBuilderMiddleware[];
180
- mutation?: boolean;
181
- query?: boolean;
182
- subscription?: boolean;
183
- };
175
+ _def: ProcedureBuilderDef<TParams>;
184
176
  }
185
177
 
186
178
  type AnyProcedureBuilder = ProcedureBuilder<any>;
187
- export type AnyProcedureBuilderDef = AnyProcedureBuilder['_def'];
188
179
 
189
180
  export type ProcedureBuilderMiddleware = MiddlewareFunction<any, any>;
190
181
 
@@ -2,7 +2,7 @@ import { DefaultErrorShape } from '../error/formatter';
2
2
  import { CombinedDataTransformer } from '../transformer';
3
3
  import { RootConfig } from './internals/config';
4
4
  import {
5
- ProcedureBuilder,
5
+ ProcedureBuilderDef,
6
6
  ProcedureCallOptions,
7
7
  } from './internals/procedureBuilder';
8
8
  import { UnsetMarker } from './internals/utils';
@@ -86,12 +86,12 @@ export type ProcedureArgs<TParams extends ProcedureParams> =
86
86
  *
87
87
  * @internal
88
88
  */
89
- export interface ProcedureBase<
89
+ export interface Procedure<
90
90
  TType extends ProcedureType,
91
91
  TParams extends ProcedureParams,
92
92
  > {
93
93
  _type: TType;
94
- _def: TParams & ProcedureBuilder<TParams>['_def'];
94
+ _def: TParams & ProcedureBuilderDef<TParams>;
95
95
  /**
96
96
  * @deprecated use `._def.meta` instead
97
97
  */
@@ -103,18 +103,7 @@ export interface ProcedureBase<
103
103
  (opts: ProcedureCallOptions): Promise<unknown>;
104
104
  }
105
105
 
106
- export interface QueryProcedure<TParams extends ProcedureParams>
107
- extends ProcedureBase<'query', TParams> {}
108
- export type AnyQueryProcedure = QueryProcedure<any>;
109
-
110
- export interface MutationProcedure<TParams extends ProcedureParams>
111
- extends ProcedureBase<'mutation', TParams> {}
112
- export type AnyMutationProcedure = MutationProcedure<any>;
113
-
114
- export interface SubscriptionProcedure<TParams extends ProcedureParams>
115
- extends ProcedureBase<'subscription', TParams> {}
116
- export type AnySubscriptionProcedure = SubscriptionProcedure<any>;
117
-
118
- export interface Procedure<TParams extends ProcedureParams>
119
- extends ProcedureBase<ProcedureType, TParams> {}
120
- export type AnyProcedure = Procedure<any>;
106
+ export type AnyQueryProcedure = Procedure<'query', any>;
107
+ export type AnyMutationProcedure = Procedure<'mutation', any>;
108
+ export type AnySubscriptionProcedure = Procedure<'subscription', any>;
109
+ export type AnyProcedure = Procedure<ProcedureType, any>;
@@ -6,7 +6,7 @@ import {
6
6
  } from '../error/formatter';
7
7
  import { getHTTPStatusCodeFromError } from '../http/internals/getHTTPStatusCode';
8
8
  import { TRPCErrorShape, TRPC_ERROR_CODES_BY_KEY } from '../rpc';
9
- import { createProxy } from '../shared';
9
+ import { createRecursiveProxy } from '../shared';
10
10
  import { CombinedDataTransformer, defaultTransformer } from '../transformer';
11
11
  import { RootConfig } from './internals/config';
12
12
  import { mergeWithoutOverrides } from './internals/mergeWithoutOverrides';
@@ -29,7 +29,9 @@ import {
29
29
  /** @internal **/
30
30
  export type ProcedureRecord = Record<string, AnyProcedure>;
31
31
 
32
- export type ProcedureRouterRecord = Record<string, AnyProcedure | AnyRouter>;
32
+ export interface ProcedureRouterRecord {
33
+ [key: string]: AnyProcedure | AnyRouter;
34
+ }
33
35
 
34
36
  export interface ProcedureStructure {
35
37
  queries: Record<string, AnyQueryProcedure>;
@@ -188,7 +190,22 @@ const reservedWords = [
188
190
  ];
189
191
 
190
192
  /**
191
- *
193
+ * @internal
194
+ */
195
+ export type CreateRouterInner<
196
+ TConfig extends RootConfig,
197
+ TProcRouterRecord extends ProcedureRouterRecord,
198
+ > = Router<
199
+ RouterDef<
200
+ TConfig['ctx'],
201
+ TConfig['errorShape'],
202
+ TConfig['meta'],
203
+ TProcRouterRecord
204
+ >
205
+ > &
206
+ TProcRouterRecord;
207
+
208
+ /**
192
209
  * @internal
193
210
  */
194
211
  export function createRouterFactory<TConfig extends RootConfig>(
@@ -196,17 +213,7 @@ export function createRouterFactory<TConfig extends RootConfig>(
196
213
  ) {
197
214
  return function createRouterInner<
198
215
  TProcRouterRecord extends ProcedureRouterRecord,
199
- >(
200
- opts: TProcRouterRecord,
201
- ): Router<
202
- RouterDef<
203
- TConfig['ctx'],
204
- TConfig['errorShape'],
205
- TConfig['meta'],
206
- TProcRouterRecord
207
- >
208
- > &
209
- TProcRouterRecord {
216
+ >(opts: TProcRouterRecord): CreateRouterInner<TConfig, TProcRouterRecord> {
210
217
  const reservedWordsUsed = new Set(
211
218
  Object.keys(opts).filter((v) => reservedWords.includes(v)),
212
219
  );
@@ -266,7 +273,7 @@ export function createRouterFactory<TConfig extends RootConfig>(
266
273
  transformer: _def.transformer,
267
274
  errorFormatter: _def.errorFormatter,
268
275
  createCaller(ctx) {
269
- const proxy = createProxy(({ path, args }) => {
276
+ const proxy = createRecursiveProxy(({ path, args }) => {
270
277
  // interop mode
271
278
  if (
272
279
  path.length === 1 &&
@@ -7,11 +7,7 @@ import {
7
7
  createInputMiddleware,
8
8
  createOutputMiddleware,
9
9
  } from '../core/middleware';
10
- import {
11
- MutationProcedure,
12
- QueryProcedure,
13
- SubscriptionProcedure,
14
- } from '../core/procedure';
10
+ import { Procedure } from '../core/procedure';
15
11
  import {
16
12
  ProcedureRecord as NewProcedureRecord,
17
13
  Router as NewRouter,
@@ -57,13 +53,7 @@ type MigrateProcedure<
57
53
  TConfig extends RootConfig,
58
54
  TProcedure extends AnyOldProcedure,
59
55
  TType extends ProcedureType,
60
- > = TType extends 'query'
61
- ? QueryProcedure<convertProcedureParams<TConfig, TProcedure>>
62
- : TType extends 'mutation'
63
- ? MutationProcedure<convertProcedureParams<TConfig, TProcedure>>
64
- : TType extends 'subscription'
65
- ? SubscriptionProcedure<convertProcedureParams<TConfig, TProcedure>>
66
- : never;
56
+ > = Procedure<TType, convertProcedureParams<TConfig, TProcedure>>;
67
57
 
68
58
  export type MigrateProcedureRecord<
69
59
  TConfig extends RootConfig,
package/src/internals.ts CHANGED
@@ -3,12 +3,10 @@
3
3
  */
4
4
  export type { DefaultErrorShape } from './error/formatter';
5
5
  export type { mergeRoutersGeneric } from './core/internals/__generated__/mergeRoutersGeneric';
6
- export type { ProcedureBuilder } from './core/internals/procedureBuilder';
6
+ export type {
7
+ ProcedureBuilder,
8
+ BuildProcedure,
9
+ } from './core/internals/procedureBuilder';
7
10
  export type { Overwrite, unsetMarker } from './core/internals/utils';
8
11
  export type { MiddlewareFunction } from './core/middleware';
9
12
  export type { Router, RouterDef } from './core/router';
10
- export type {
11
- MutationProcedure,
12
- QueryProcedure,
13
- SubscriptionProcedure,
14
- } from './core/procedure';
@@ -4,36 +4,27 @@ interface ProxyCallbackOptions {
4
4
  }
5
5
  type ProxyCallback = (opts: ProxyCallbackOptions) => unknown;
6
6
 
7
- function createProxyInner(callback: ProxyCallback, ...path: string[]) {
8
- const proxy: unknown = new Proxy(
9
- () => {
10
- // noop
11
- },
12
- {
13
- get(_obj, name) {
14
- if (name === 'then') {
15
- return undefined;
16
- }
17
- if (typeof name === 'string') {
18
- if (name === 'then') {
19
- // special case for if the proxy is accidentally treated
20
- // like a PromiseLike (like in `Promise.resolve(proxy)`)
21
- return undefined;
22
- }
23
- return createProxyInner(callback, ...path, name);
24
- }
7
+ const noop = () => {
8
+ // noop
9
+ };
25
10
 
26
- throw new Error('Not supported');
27
- },
28
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
- apply(_1, _2, args) {
30
- return callback({
31
- args,
32
- path,
33
- });
34
- },
11
+ function createInnerProxy(callback: ProxyCallback, path: string[]) {
12
+ const proxy: unknown = new Proxy(noop, {
13
+ get(_obj, key) {
14
+ if (typeof key !== 'string' || key === 'then') {
15
+ // special case for if the proxy is accidentally treated
16
+ // like a PromiseLike (like in `Promise.resolve(proxy)`)
17
+ return undefined;
18
+ }
19
+ return createInnerProxy(callback, [...path, key]);
20
+ },
21
+ apply(_1, _2, args) {
22
+ return callback({
23
+ args,
24
+ path,
25
+ });
35
26
  },
36
- );
27
+ });
37
28
 
38
29
  return proxy;
39
30
  }
@@ -41,11 +32,27 @@ function createProxyInner(callback: ProxyCallback, ...path: string[]) {
41
32
  /**
42
33
  * Creates a proxy that calls the callback with the path and arguments
43
34
  *
44
- * @remarks
45
- * This has a special handling to manage if it's accidentally treated like
46
- * a PromiseLike.
35
+ * @internal
36
+ */
37
+ export const createRecursiveProxy = (callback: ProxyCallback) =>
38
+ createInnerProxy(callback, []);
39
+
40
+ /**
41
+ * Used in place of `new Proxy` where each handler will map 1 level deep to another value.
47
42
  *
48
43
  * @internal
49
44
  */
50
- export const createProxy = (callback: ProxyCallback) =>
51
- createProxyInner(callback);
45
+ export const createFlatProxy = <TFaux>(
46
+ callback: (path: keyof TFaux & string) => any,
47
+ ): TFaux => {
48
+ return new Proxy(noop, {
49
+ get(_obj, name) {
50
+ if (typeof name !== 'string' || name === 'then') {
51
+ // special case for if the proxy is accidentally treated
52
+ // like a PromiseLike (like in `Promise.resolve(proxy)`)
53
+ return undefined;
54
+ }
55
+ return callback(name as any);
56
+ },
57
+ }) as TFaux;
58
+ };
@@ -1,39 +0,0 @@
1
- function createProxyInner(callback, ...path) {
2
- const proxy = new Proxy(()=>{
3
- // noop
4
- }, {
5
- get (_obj, name) {
6
- if (name === 'then') {
7
- return undefined;
8
- }
9
- if (typeof name === 'string') {
10
- if (name === 'then') {
11
- // special case for if the proxy is accidentally treated
12
- // like a PromiseLike (like in `Promise.resolve(proxy)`)
13
- return undefined;
14
- }
15
- return createProxyInner(callback, ...path, name);
16
- }
17
- throw new Error('Not supported');
18
- },
19
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
20
- apply (_1, _2, args) {
21
- return callback({
22
- args,
23
- path
24
- });
25
- }
26
- });
27
- return proxy;
28
- }
29
- /**
30
- * Creates a proxy that calls the callback with the path and arguments
31
- *
32
- * @remarks
33
- * This has a special handling to manage if it's accidentally treated like
34
- * a PromiseLike.
35
- *
36
- * @internal
37
- */ const createProxy = (callback)=>createProxyInner(callback);
38
-
39
- export { createProxy as c };