@trpc/server 11.0.0-alpha-tmp-export-from-main-nuke-core.215 → 11.0.0-alpha-tmp-export-from-main.211

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 (207) hide show
  1. package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +9 -0
  2. package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +1 -0
  3. package/dist/@trpc-server/http.d.ts +1 -1
  4. package/dist/@trpc-server/http.d.ts.map +1 -1
  5. package/dist/@trpc-server.d.ts +3 -3
  6. package/dist/@trpc-server.d.ts.map +1 -1
  7. package/dist/adapters/aws-lambda/index.d.ts +1 -1
  8. package/dist/adapters/aws-lambda/index.js +7 -12
  9. package/dist/adapters/aws-lambda/index.mjs +3 -8
  10. package/dist/adapters/aws-lambda/utils.d.ts +1 -1
  11. package/dist/adapters/express.d.ts +1 -1
  12. package/dist/adapters/express.d.ts.map +1 -1
  13. package/dist/adapters/express.js +2 -8
  14. package/dist/adapters/express.mjs +2 -8
  15. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
  16. package/dist/adapters/fastify/index.js +4 -12
  17. package/dist/adapters/fastify/index.mjs +2 -10
  18. package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -1
  19. package/dist/adapters/fetch/index.js +4 -10
  20. package/dist/adapters/fetch/index.mjs +2 -8
  21. package/dist/adapters/fetch/types.d.ts +1 -1
  22. package/dist/adapters/next.d.ts +1 -1
  23. package/dist/adapters/next.js +5 -11
  24. package/dist/adapters/next.mjs +3 -9
  25. package/dist/adapters/node-http/content-type/json/index.js +3 -5
  26. package/dist/adapters/node-http/content-type/json/index.mjs +1 -3
  27. package/dist/adapters/node-http/index.js +2 -8
  28. package/dist/adapters/node-http/index.mjs +2 -8
  29. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
  30. package/dist/adapters/node-http/types.d.ts +2 -2
  31. package/dist/adapters/node-http/types.d.ts.map +1 -1
  32. package/dist/adapters/standalone.d.ts +1 -1
  33. package/dist/adapters/standalone.js +2 -8
  34. package/dist/adapters/standalone.mjs +2 -8
  35. package/dist/adapters/ws.d.ts +1 -2
  36. package/dist/adapters/ws.d.ts.map +1 -1
  37. package/dist/adapters/ws.js +26 -31
  38. package/dist/adapters/ws.mjs +1 -6
  39. package/dist/http.d.ts +6 -6
  40. package/dist/http.d.ts.map +1 -1
  41. package/dist/http.js +21 -12
  42. package/dist/http.mjs +1 -7
  43. package/dist/index.js +41 -15
  44. package/dist/index.mjs +1 -5
  45. package/dist/{nodeHTTPRequestHandler-257a3b5f.mjs → nodeHTTPRequestHandler-2d5c8791.mjs} +2 -4
  46. package/dist/{nodeHTTPRequestHandler-f4b7e374.js → nodeHTTPRequestHandler-55f05150.js} +4 -6
  47. package/dist/{nodeHTTPRequestHandler-29178135.js → nodeHTTPRequestHandler-7691fc79.js} +1 -3
  48. package/dist/observable.d.ts +2 -2
  49. package/dist/observable.d.ts.map +1 -1
  50. package/dist/observable.js +25 -9
  51. package/dist/observable.mjs +1 -3
  52. package/dist/rpc.d.ts +2 -2
  53. package/dist/rpc.d.ts.map +1 -1
  54. package/dist/rpc.js +13 -5
  55. package/dist/rpc.mjs +1 -2
  56. package/dist/shared.js +9 -4
  57. package/dist/shared.mjs +1 -2
  58. package/package.json +125 -53
  59. package/src/@trpc-core-unstable-do-not-import-this-please.ts +9 -0
  60. package/src/@trpc-server/http.ts +1 -2
  61. package/src/@trpc-server.ts +3 -3
  62. package/src/adapters/aws-lambda/index.ts +1 -1
  63. package/src/adapters/aws-lambda/utils.ts +1 -1
  64. package/src/adapters/express.ts +2 -1
  65. package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
  66. package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
  67. package/src/adapters/fetch/fetchRequestHandler.ts +1 -1
  68. package/src/adapters/fetch/types.ts +1 -1
  69. package/src/adapters/next.ts +1 -1
  70. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +1 -1
  71. package/src/adapters/node-http/types.ts +3 -2
  72. package/src/adapters/standalone.ts +1 -1
  73. package/src/adapters/ws.ts +10 -9
  74. package/src/http.ts +6 -6
  75. package/src/observable.ts +2 -2
  76. package/src/rpc.ts +2 -2
  77. package/dist/TRPCError-10da405a.js +0 -61
  78. package/dist/TRPCError-14edcf88.mjs +0 -63
  79. package/dist/TRPCError-e2c8eb77.js +0 -67
  80. package/dist/batchStreamFormatter-1971db27.js +0 -32
  81. package/dist/batchStreamFormatter-378277dc.mjs +0 -30
  82. package/dist/batchStreamFormatter-4375dc8b.js +0 -31
  83. package/dist/bundle-analysis.json +0 -767
  84. package/dist/contentType-2ed02bef.mjs +0 -52
  85. package/dist/contentType-3a829011.js +0 -54
  86. package/dist/contentType-e4a2373e.js +0 -59
  87. package/dist/createProxy-0306dcaa.mjs +0 -121
  88. package/dist/createProxy-7e413449.js +0 -127
  89. package/dist/createProxy-dce0c414.js +0 -116
  90. package/dist/initTRPC-2cef03ab.js +0 -384
  91. package/dist/initTRPC-38faa18f.js +0 -371
  92. package/dist/initTRPC-fa1b3d57.mjs +0 -376
  93. package/dist/observable-2a5a96d5.js +0 -125
  94. package/dist/observable-62674916.js +0 -125
  95. package/dist/observable-6d025a37.mjs +0 -121
  96. package/dist/operators-0cc4956a.js +0 -99
  97. package/dist/operators-b08617cb.js +0 -103
  98. package/dist/operators-d0c3e794.mjs +0 -99
  99. package/dist/parseTRPCMessage-6e6c204e.js +0 -65
  100. package/dist/parseTRPCMessage-8eb0bbe9.mjs +0 -62
  101. package/dist/parseTRPCMessage-ebdfe3ca.js +0 -67
  102. package/dist/resolveHTTPResponse-833ca2b8.js +0 -265
  103. package/dist/resolveHTTPResponse-9322334c.mjs +0 -291
  104. package/dist/resolveHTTPResponse-d64c48e1.js +0 -293
  105. package/dist/rootConfig-3371c473.js +0 -89
  106. package/dist/rootConfig-571c9267.js +0 -94
  107. package/dist/rootConfig-6b04a6b8.mjs +0 -81
  108. package/dist/router-3344b52a.js +0 -262
  109. package/dist/router-919c37eb.js +0 -259
  110. package/dist/router-d6789e4b.mjs +0 -252
  111. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +0 -6
  112. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +0 -1
  113. package/dist/unstable-core-do-not-import/createProxy.d.ts +0 -19
  114. package/dist/unstable-core-do-not-import/createProxy.d.ts.map +0 -1
  115. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +0 -13
  116. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +0 -1
  117. package/dist/unstable-core-do-not-import/error/formatter.d.ts +0 -33
  118. package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +0 -1
  119. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +0 -15
  120. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +0 -1
  121. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
  122. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
  123. package/dist/unstable-core-do-not-import/http/contentType.d.ts +0 -29
  124. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +0 -1
  125. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +0 -5
  126. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +0 -1
  127. package/dist/unstable-core-do-not-import/http/index.d.ts +0 -7
  128. package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
  129. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
  130. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
  131. package/dist/unstable-core-do-not-import/http/types.d.ts +0 -96
  132. package/dist/unstable-core-do-not-import/http/types.d.ts.map +0 -1
  133. package/dist/unstable-core-do-not-import/index.d.ts +0 -35
  134. package/dist/unstable-core-do-not-import/index.d.ts.map +0 -1
  135. package/dist/unstable-core-do-not-import/index.js +0 -51
  136. package/dist/unstable-core-do-not-import/index.mjs +0 -11
  137. package/dist/unstable-core-do-not-import/initTRPC.d.ts +0 -96
  138. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +0 -1
  139. package/dist/unstable-core-do-not-import/middleware.d.ts +0 -105
  140. package/dist/unstable-core-do-not-import/middleware.d.ts.map +0 -1
  141. package/dist/unstable-core-do-not-import/observable/index.d.ts +0 -5
  142. package/dist/unstable-core-do-not-import/observable/index.d.ts.map +0 -1
  143. package/dist/unstable-core-do-not-import/observable/observable.d.ts +0 -13
  144. package/dist/unstable-core-do-not-import/observable/observable.d.ts.map +0 -1
  145. package/dist/unstable-core-do-not-import/observable/operators.d.ts +0 -8
  146. package/dist/unstable-core-do-not-import/observable/operators.d.ts.map +0 -1
  147. package/dist/unstable-core-do-not-import/observable/types.d.ts +0 -26
  148. package/dist/unstable-core-do-not-import/observable/types.d.ts.map +0 -1
  149. package/dist/unstable-core-do-not-import/parser.d.ts +0 -30
  150. package/dist/unstable-core-do-not-import/parser.d.ts.map +0 -1
  151. package/dist/unstable-core-do-not-import/procedure.d.ts +0 -72
  152. package/dist/unstable-core-do-not-import/procedure.d.ts.map +0 -1
  153. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +0 -101
  154. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +0 -1
  155. package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -75
  156. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +0 -1
  157. package/dist/unstable-core-do-not-import/router.d.ts +0 -85
  158. package/dist/unstable-core-do-not-import/router.d.ts.map +0 -1
  159. package/dist/unstable-core-do-not-import/rpc/codes.d.ts +0 -51
  160. package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +0 -1
  161. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +0 -97
  162. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +0 -1
  163. package/dist/unstable-core-do-not-import/rpc/index.d.ts +0 -5
  164. package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +0 -1
  165. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +0 -5
  166. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +0 -1
  167. package/dist/unstable-core-do-not-import/serialize.d.ts +0 -62
  168. package/dist/unstable-core-do-not-import/serialize.d.ts.map +0 -1
  169. package/dist/unstable-core-do-not-import/transformer.d.ts +0 -107
  170. package/dist/unstable-core-do-not-import/transformer.d.ts.map +0 -1
  171. package/dist/unstable-core-do-not-import/types.d.ts +0 -98
  172. package/dist/unstable-core-do-not-import/types.d.ts.map +0 -1
  173. package/dist/unstable-core-do-not-import/utils.d.ts +0 -31
  174. package/dist/unstable-core-do-not-import/utils.d.ts.map +0 -1
  175. package/src/unstable-core-do-not-import/TRPCInferrable.ts +0 -9
  176. package/src/unstable-core-do-not-import/createProxy.ts +0 -59
  177. package/src/unstable-core-do-not-import/error/TRPCError.ts +0 -82
  178. package/src/unstable-core-do-not-import/error/formatter.ts +0 -51
  179. package/src/unstable-core-do-not-import/error/getErrorShape.ts +0 -36
  180. package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
  181. package/src/unstable-core-do-not-import/http/contentType.ts +0 -99
  182. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +0 -57
  183. package/src/unstable-core-do-not-import/http/index.ts +0 -23
  184. package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -458
  185. package/src/unstable-core-do-not-import/http/types.ts +0 -111
  186. package/src/unstable-core-do-not-import/index.ts +0 -108
  187. package/src/unstable-core-do-not-import/initTRPC.ts +0 -206
  188. package/src/unstable-core-do-not-import/middleware.ts +0 -233
  189. package/src/unstable-core-do-not-import/observable/index.ts +0 -10
  190. package/src/unstable-core-do-not-import/observable/observable.ts +0 -155
  191. package/src/unstable-core-do-not-import/observable/operators.ts +0 -119
  192. package/src/unstable-core-do-not-import/observable/types.ts +0 -76
  193. package/src/unstable-core-do-not-import/parser.ts +0 -94
  194. package/src/unstable-core-do-not-import/procedure.ts +0 -108
  195. package/src/unstable-core-do-not-import/procedureBuilder.ts +0 -458
  196. package/src/unstable-core-do-not-import/rootConfig.ts +0 -90
  197. package/src/unstable-core-do-not-import/router.ts +0 -370
  198. package/src/unstable-core-do-not-import/rpc/codes.ts +0 -44
  199. package/src/unstable-core-do-not-import/rpc/envelopes.ts +0 -136
  200. package/src/unstable-core-do-not-import/rpc/index.ts +0 -21
  201. package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +0 -85
  202. package/src/unstable-core-do-not-import/serialize.ts +0 -122
  203. package/src/unstable-core-do-not-import/transformer.ts +0 -202
  204. package/src/unstable-core-do-not-import/types.ts +0 -151
  205. package/src/unstable-core-do-not-import/utils.ts +0 -66
  206. package/unstable-core-do-not-import/index.d.ts +0 -1
  207. package/unstable-core-do-not-import/index.js +0 -1
@@ -1,458 +0,0 @@
1
- import { getTRPCErrorFromUnknown, TRPCError } from './error/TRPCError';
2
- import type {
3
- AnyMiddlewareFunction,
4
- MiddlewareBuilder,
5
- MiddlewareFunction,
6
- MiddlewareResult,
7
- } from './middleware';
8
- import {
9
- createInputMiddleware,
10
- createOutputMiddleware,
11
- middlewareMarker,
12
- } from './middleware';
13
- import { getParseFn } from './parser';
14
- import type { inferParser, Parser } from './parser';
15
- import type {
16
- AnyMutationProcedure,
17
- AnyProcedure,
18
- AnyQueryProcedure,
19
- AnySubscriptionProcedure,
20
- MutationProcedure,
21
- ProcedureType,
22
- QueryProcedure,
23
- SubscriptionProcedure,
24
- } from './procedure';
25
- import type { GetRawInputFn, MaybePromise, Overwrite, Simplify } from './types';
26
- import { mergeWithoutOverrides } from './utils';
27
-
28
- type IntersectIfDefined<TType, TWith> = TType extends UnsetMarker
29
- ? TWith
30
- : Simplify<TType & TWith>;
31
-
32
- type ErrorMessage<TMessage extends string> = TMessage;
33
-
34
- /** @internal */
35
- export const unsetMarker = Symbol('unsetMarker');
36
- type UnsetMarker = typeof unsetMarker;
37
- type DefaultValue<TValue, TFallback> = TValue extends UnsetMarker
38
- ? TFallback
39
- : TValue;
40
-
41
- type ProcedureBuilderDef<TMeta> = {
42
- procedure: true;
43
- inputs: Parser[];
44
- output?: Parser;
45
- meta?: TMeta;
46
- resolver?: ProcedureBuilderResolver;
47
- middlewares: AnyMiddlewareFunction[];
48
- mutation?: boolean;
49
- query?: boolean;
50
- subscription?: boolean;
51
- };
52
-
53
- type AnyProcedureBuilderDef = ProcedureBuilderDef<any>;
54
-
55
- /**
56
- * Procedure resolver options
57
- * @internal
58
- */
59
- interface ResolverOptions<TContext, _TMeta, TContextOverridesIn, TInputOut> {
60
- ctx: Simplify<Overwrite<TContext, TContextOverridesIn>>;
61
- input: TInputOut extends UnsetMarker ? undefined : TInputOut;
62
- }
63
-
64
- /**
65
- * A procedure resolver
66
- */
67
- type ProcedureResolver<
68
- TContext,
69
- _TMeta,
70
- TContextOverrides,
71
- TInputOut,
72
- TOutputIn,
73
- TOutputOut,
74
- > = (opts: {
75
- ctx: Simplify<Overwrite<TContext, TContextOverrides>>;
76
- input: TInputOut extends UnsetMarker ? undefined : TInputOut;
77
- }) => MaybePromise<DefaultValue<TOutputIn, TOutputOut>>;
78
-
79
- type AnyResolver = ProcedureResolver<any, any, any, any, any, any>;
80
- export interface ProcedureBuilder<
81
- TContext,
82
- TMeta,
83
- TContextOverrides,
84
- TInputIn,
85
- TInputOut,
86
- TOutputIn,
87
- TOutputOut,
88
- > {
89
- /**
90
- * Add an input parser to the procedure.
91
- * @link https://trpc.io/docs/v11/server/validators
92
- */
93
- input<$Parser extends Parser>(
94
- schema: TInputOut extends UnsetMarker
95
- ? $Parser
96
- : inferParser<$Parser>['out'] extends Record<string, unknown> | undefined
97
- ? TInputOut extends Record<string, unknown> | undefined
98
- ? undefined extends inferParser<$Parser>['out'] // if current is optional the previous must be too
99
- ? undefined extends TInputOut
100
- ? $Parser
101
- : ErrorMessage<'Cannot chain an optional parser to a required parser'>
102
- : $Parser
103
- : ErrorMessage<'All input parsers did not resolve to an object'>
104
- : ErrorMessage<'All input parsers did not resolve to an object'>,
105
- ): ProcedureBuilder<
106
- TContext,
107
- TMeta,
108
- TContextOverrides,
109
- IntersectIfDefined<TInputIn, inferParser<$Parser>['in']>,
110
- IntersectIfDefined<TInputOut, inferParser<$Parser>['out']>,
111
- TOutputIn,
112
- TOutputOut
113
- >;
114
- /**
115
- * Add an output parser to the procedure.
116
- * @link https://trpc.io/docs/v11/server/validators
117
- */
118
- output<$Parser extends Parser>(
119
- schema: $Parser,
120
- ): ProcedureBuilder<
121
- TContext,
122
- TMeta,
123
- TContextOverrides,
124
- TInputIn,
125
- TInputOut,
126
- IntersectIfDefined<TOutputIn, inferParser<$Parser>['in']>,
127
- IntersectIfDefined<TOutputOut, inferParser<$Parser>['out']>
128
- >;
129
- /**
130
- * Add a meta data to the procedure.
131
- * @link https://trpc.io/docs/v11/server/metadata
132
- */
133
- meta(
134
- meta: TMeta,
135
- ): ProcedureBuilder<
136
- TContext,
137
- TMeta,
138
- TContextOverrides,
139
- TInputIn,
140
- TInputOut,
141
- TOutputIn,
142
- TOutputOut
143
- >;
144
- /**
145
- * Add a middleware to the procedure.
146
- * @link https://trpc.io/docs/v11/server/middlewares
147
- */
148
- use<$ContextOverridesOut>(
149
- fn:
150
- | MiddlewareBuilder<
151
- Overwrite<TContext, TContextOverrides>,
152
- TMeta,
153
- $ContextOverridesOut,
154
- TInputIn
155
- >
156
- | MiddlewareFunction<
157
- TContext,
158
- TMeta,
159
- TContextOverrides,
160
- $ContextOverridesOut,
161
- TInputIn
162
- >,
163
- ): ProcedureBuilder<
164
- TContext,
165
- TMeta,
166
- Overwrite<TContextOverrides, $ContextOverridesOut>,
167
- TInputIn,
168
- TInputOut,
169
- TOutputIn,
170
- TOutputOut
171
- >;
172
- /**
173
- * Query procedure
174
- * @link https://trpc.io/docs/v11/concepts#vocabulary
175
- */
176
- query<$Output>(
177
- resolver: ProcedureResolver<
178
- TContext,
179
- TMeta,
180
- TContextOverrides,
181
- TInputOut,
182
- TOutputIn,
183
- $Output
184
- >,
185
- ): QueryProcedure<{
186
- input: DefaultValue<TInputIn, void>;
187
- output: DefaultValue<TOutputOut, $Output>;
188
- }>;
189
-
190
- /**
191
- * Mutation procedure
192
- * @link https://trpc.io/docs/v11/concepts#vocabulary
193
- */
194
- mutation<$Output>(
195
- resolver: ProcedureResolver<
196
- TContext,
197
- TMeta,
198
- TContextOverrides,
199
- TInputOut,
200
- TOutputIn,
201
- $Output
202
- >,
203
- ): MutationProcedure<{
204
- input: DefaultValue<TInputIn, void>;
205
- output: DefaultValue<TOutputOut, $Output>;
206
- }>;
207
-
208
- /**
209
- * Subscription procedure
210
- * @link https://trpc.io/docs/v11/concepts#vocabulary
211
- */
212
- subscription<$Output>(
213
- resolver: ProcedureResolver<
214
- TContext,
215
- TMeta,
216
- TContextOverrides,
217
- TInputOut,
218
- TOutputIn,
219
- $Output
220
- >,
221
- ): SubscriptionProcedure<{
222
- input: DefaultValue<TInputIn, void>;
223
- output: DefaultValue<TOutputOut, $Output>;
224
- }>;
225
- /**
226
- * @internal
227
- */
228
- _def: ProcedureBuilderDef<TMeta>;
229
- }
230
-
231
- type AnyProcedureBuilder = ProcedureBuilder<any, any, any, any, any, any, any>;
232
- type ProcedureBuilderResolver = (
233
- opts: ResolverOptions<any, any, any, any>,
234
- ) => Promise<unknown>;
235
-
236
- function createNewBuilder(
237
- def1: AnyProcedureBuilderDef,
238
- def2: Partial<AnyProcedureBuilderDef>,
239
- ): AnyProcedureBuilder {
240
- const { middlewares = [], inputs, meta, ...rest } = def2;
241
-
242
- // TODO: maybe have a fn here to warn about calls
243
- return createBuilder({
244
- ...mergeWithoutOverrides(def1, rest),
245
- inputs: [...def1.inputs, ...(inputs ?? [])],
246
- middlewares: [...def1.middlewares, ...middlewares],
247
- meta: def1.meta && meta ? { ...def1.meta, ...meta } : meta ?? def1.meta,
248
- });
249
- }
250
-
251
- export function createBuilder<TContext, TMeta>(
252
- initDef: Partial<AnyProcedureBuilderDef> = {},
253
- ): ProcedureBuilder<
254
- TContext,
255
- TMeta,
256
- object,
257
- UnsetMarker,
258
- UnsetMarker,
259
- UnsetMarker,
260
- UnsetMarker
261
- > {
262
- const _def: AnyProcedureBuilderDef = {
263
- procedure: true,
264
- inputs: [],
265
- middlewares: [],
266
- ...initDef,
267
- };
268
-
269
- type AnyProcedureBuilder = ProcedureBuilder<
270
- any,
271
- any,
272
- any,
273
- any,
274
- any,
275
- any,
276
- any
277
- >;
278
-
279
- const builder: AnyProcedureBuilder = {
280
- _def,
281
- input(input) {
282
- const parser = getParseFn(input as Parser);
283
- return createNewBuilder(_def, {
284
- inputs: [input as Parser],
285
- middlewares: [createInputMiddleware(parser)],
286
- });
287
- },
288
- output(output: Parser) {
289
- const parser = getParseFn(output);
290
- return createNewBuilder(_def, {
291
- output,
292
- middlewares: [createOutputMiddleware(parser)],
293
- });
294
- },
295
- meta(meta) {
296
- return createNewBuilder(_def, {
297
- meta,
298
- });
299
- },
300
- use(middlewareBuilderOrFn) {
301
- // Distinguish between a middleware builder and a middleware function
302
- const middlewares =
303
- '_middlewares' in middlewareBuilderOrFn
304
- ? middlewareBuilderOrFn._middlewares
305
- : [middlewareBuilderOrFn];
306
-
307
- return createNewBuilder(_def, {
308
- middlewares: middlewares,
309
- });
310
- },
311
- query(resolver) {
312
- return createResolver(
313
- { ..._def, type: 'query' },
314
- resolver,
315
- ) as AnyQueryProcedure;
316
- },
317
- mutation(resolver) {
318
- return createResolver(
319
- { ..._def, type: 'mutation' },
320
- resolver,
321
- ) as AnyMutationProcedure;
322
- },
323
- subscription(resolver) {
324
- return createResolver(
325
- { ..._def, type: 'subscription' },
326
- resolver,
327
- ) as AnySubscriptionProcedure;
328
- },
329
- };
330
-
331
- return builder;
332
- }
333
-
334
- function createResolver(
335
- _def: AnyProcedureBuilderDef & { type: ProcedureType },
336
- resolver: AnyResolver,
337
- ) {
338
- const finalBuilder = createNewBuilder(_def, {
339
- resolver,
340
- middlewares: [
341
- async function resolveMiddleware(opts) {
342
- const data = await resolver(opts);
343
- return {
344
- marker: middlewareMarker,
345
- ok: true,
346
- data,
347
- ctx: opts.ctx,
348
- } as const;
349
- },
350
- ],
351
- });
352
-
353
- return createProcedureCaller(finalBuilder._def);
354
- }
355
-
356
- /**
357
- * @internal
358
- */
359
- export interface ProcedureCallOptions {
360
- ctx: unknown;
361
- getRawInput: GetRawInputFn;
362
- input?: unknown;
363
- path: string;
364
- type: ProcedureType;
365
- }
366
-
367
- const codeblock = `
368
- This is a client-only function.
369
- If you want to call this function on the server, see https://trpc.io/docs/v11/server/server-side-calls
370
- `.trim();
371
-
372
- function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure {
373
- async function procedure(opts: ProcedureCallOptions) {
374
- // is direct server-side call
375
- if (!opts || !('getRawInput' in opts)) {
376
- throw new Error(codeblock);
377
- }
378
-
379
- // run the middlewares recursively with the resolver as the last one
380
- async function callRecursive(
381
- callOpts: {
382
- ctx: any;
383
- index: number;
384
- input?: unknown;
385
- getRawInput?: GetRawInputFn;
386
- } = {
387
- index: 0,
388
- ctx: opts.ctx,
389
- },
390
- ): Promise<MiddlewareResult<any>> {
391
- try {
392
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
393
- const middleware = _def.middlewares[callOpts.index]!;
394
- const result = await middleware({
395
- ctx: callOpts.ctx,
396
- type: opts.type,
397
- path: opts.path,
398
- getRawInput: callOpts.getRawInput ?? opts.getRawInput,
399
- meta: _def.meta,
400
- input: callOpts.input,
401
- next(_nextOpts?: any) {
402
- const nextOpts = _nextOpts as
403
- | {
404
- ctx?: Record<string, unknown>;
405
- input?: unknown;
406
- getRawInput?: GetRawInputFn;
407
- }
408
- | undefined;
409
-
410
- return callRecursive({
411
- index: callOpts.index + 1,
412
- ctx:
413
- nextOpts && 'ctx' in nextOpts
414
- ? { ...callOpts.ctx, ...nextOpts.ctx }
415
- : callOpts.ctx,
416
- input:
417
- nextOpts && 'input' in nextOpts
418
- ? nextOpts.input
419
- : callOpts.input,
420
- getRawInput:
421
- nextOpts && 'getRawInput' in nextOpts
422
- ? nextOpts.getRawInput
423
- : callOpts.getRawInput,
424
- });
425
- },
426
- });
427
- return result;
428
- } catch (cause) {
429
- return {
430
- ok: false,
431
- error: getTRPCErrorFromUnknown(cause),
432
- marker: middlewareMarker,
433
- };
434
- }
435
- }
436
-
437
- // there's always at least one "next" since we wrap this.resolver in a middleware
438
- const result = await callRecursive();
439
-
440
- if (!result) {
441
- throw new TRPCError({
442
- code: 'INTERNAL_SERVER_ERROR',
443
- message:
444
- 'No result from middlewares - did you forget to `return next()`?',
445
- });
446
- }
447
- if (!result.ok) {
448
- // re-throw original error
449
- throw result.error;
450
- }
451
- return result.data;
452
- }
453
-
454
- procedure._def = _def;
455
-
456
- // FIXME typecast shouldn't be needed - fixittt
457
- return procedure as unknown as AnyProcedure;
458
- }
@@ -1,90 +0,0 @@
1
- import type { ErrorFormatter } from './error/formatter';
2
- import type { TRPCErrorShape } from './rpc';
3
-
4
- /**
5
- * The initial generics that are used in the init function
6
- * @internal
7
- */
8
- export interface RootConfigTypes {
9
- ctx: object;
10
- meta: object;
11
- errorShape: unknown;
12
- transformer: unknown;
13
- }
14
-
15
- /**
16
- * The default check to see if we're in a server
17
- */
18
- export const isServerDefault: boolean =
19
- typeof window === 'undefined' ||
20
- 'Deno' in window ||
21
- // eslint-disable-next-line @typescript-eslint/dot-notation
22
- globalThis.process?.env?.['NODE_ENV'] === 'test' ||
23
- !!globalThis.process?.env?.['JEST_WORKER_ID'] ||
24
- !!globalThis.process?.env?.['VITEST_WORKER_ID'];
25
-
26
- /**
27
- * The runtime config that are used and actually represents real values underneath
28
- * @internal
29
- */
30
- export interface RuntimeConfig<TTypes extends RootConfigTypes> {
31
- /**
32
- * Use a data transformer
33
- * @link https://trpc.io/docs/v11/data-transformers
34
- */
35
- transformer: TTypes['transformer'];
36
- /**
37
- * Use custom error formatting
38
- * @link https://trpc.io/docs/v11/error-formatting
39
- */
40
- errorFormatter: ErrorFormatter<
41
- TTypes['ctx'],
42
- TRPCErrorShape<number> & { [key: string]: any }
43
- >;
44
- /**
45
- * Allow `@trpc/server` to run in non-server environments
46
- * @warning **Use with caution**, this should likely mainly be used within testing.
47
- * @default false
48
- */
49
- allowOutsideOfServer: boolean;
50
- /**
51
- * Is this a server environment?
52
- * @warning **Use with caution**, this should likely mainly be used within testing.
53
- * @default typeof window === 'undefined' || 'Deno' in window || process.env.NODE_ENV === 'test'
54
- */
55
- isServer: boolean;
56
- /**
57
- * Is this development?
58
- * Will be used to decide if the API should return stack traces
59
- * @default process.env.NODE_ENV !== 'production'
60
- */
61
- isDev: boolean;
62
-
63
- defaultMeta?: TTypes['meta'] extends object ? TTypes['meta'] : never;
64
- }
65
-
66
- /**
67
- * @internal
68
- */
69
- export type CreateRootConfigTypes<TGenerics extends RootConfigTypes> =
70
- TGenerics;
71
-
72
- /**
73
- * The config that is resolved after `initTRPC.create()` has been called
74
- * Combination of `InitTOptions` + `InitGenerics`
75
- * @internal
76
- */
77
- export interface RootConfig<TGenerics extends RootConfigTypes>
78
- extends RuntimeConfig<TGenerics> {
79
- $types: TGenerics;
80
- }
81
-
82
- /**
83
- * @internal
84
- */
85
- export type AnyRootConfig = RootConfig<{
86
- ctx: any;
87
- meta: any;
88
- errorShape: any;
89
- transformer: any;
90
- }>;