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

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 (234) hide show
  1. package/dist/@trpc/server/http.d.ts +7 -0
  2. package/dist/@trpc/server/http.d.ts.map +1 -0
  3. package/dist/{@trpc-server.d.ts → @trpc/server/index.d.ts} +4 -4
  4. package/dist/@trpc/server/index.d.ts.map +1 -0
  5. package/dist/@trpc/server/rpc.d.ts +3 -0
  6. package/dist/@trpc/server/rpc.d.ts.map +1 -0
  7. package/dist/TRPCError-54f51dec.mjs +63 -0
  8. package/dist/TRPCError-6f02e18d.js +67 -0
  9. package/dist/TRPCError-792b0901.js +61 -0
  10. package/dist/adapters/aws-lambda/index.d.ts +1 -2
  11. package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
  12. package/dist/adapters/aws-lambda/index.js +10 -7
  13. package/dist/adapters/aws-lambda/index.mjs +6 -3
  14. package/dist/adapters/aws-lambda/utils.d.ts +2 -3
  15. package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
  16. package/dist/adapters/express.d.ts +1 -2
  17. package/dist/adapters/express.d.ts.map +1 -1
  18. package/dist/adapters/express.js +8 -2
  19. package/dist/adapters/express.mjs +8 -2
  20. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
  21. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  22. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -2
  23. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
  24. package/dist/adapters/fastify/index.js +11 -4
  25. package/dist/adapters/fastify/index.mjs +9 -2
  26. package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -2
  27. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  28. package/dist/adapters/fetch/index.js +9 -4
  29. package/dist/adapters/fetch/index.mjs +7 -2
  30. package/dist/adapters/fetch/types.d.ts +2 -3
  31. package/dist/adapters/fetch/types.d.ts.map +1 -1
  32. package/dist/adapters/next.d.ts +1 -2
  33. package/dist/adapters/next.d.ts.map +1 -1
  34. package/dist/adapters/next.js +10 -5
  35. package/dist/adapters/next.mjs +8 -3
  36. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +1 -1
  37. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
  38. package/dist/adapters/node-http/content-type/json/index.js +5 -3
  39. package/dist/adapters/node-http/content-type/json/index.mjs +3 -1
  40. package/dist/adapters/node-http/index.js +8 -2
  41. package/dist/adapters/node-http/index.mjs +8 -2
  42. package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
  43. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -2
  44. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  45. package/dist/adapters/node-http/types.d.ts +3 -4
  46. package/dist/adapters/node-http/types.d.ts.map +1 -1
  47. package/dist/adapters/standalone.d.ts +1 -2
  48. package/dist/adapters/standalone.d.ts.map +1 -1
  49. package/dist/adapters/standalone.js +9 -2
  50. package/dist/adapters/standalone.mjs +9 -2
  51. package/dist/adapters/ws.d.ts +3 -2
  52. package/dist/adapters/ws.d.ts.map +1 -1
  53. package/dist/adapters/ws.js +31 -26
  54. package/dist/adapters/ws.mjs +6 -1
  55. package/dist/batchStreamFormatter-1971db27.js +32 -0
  56. package/dist/batchStreamFormatter-378277dc.mjs +30 -0
  57. package/dist/batchStreamFormatter-4375dc8b.js +31 -0
  58. package/dist/bundle-analysis.json +757 -0
  59. package/dist/contentType-19471015.js +59 -0
  60. package/dist/contentType-2e62862d.mjs +52 -0
  61. package/dist/contentType-4cd0be82.js +54 -0
  62. package/dist/createProxy-562377d3.js +127 -0
  63. package/dist/createProxy-72161f42.js +116 -0
  64. package/dist/createProxy-f7ba8b4d.mjs +121 -0
  65. package/dist/http.d.ts +1 -6
  66. package/dist/http.d.ts.map +1 -1
  67. package/dist/http.js +12 -21
  68. package/dist/http.mjs +7 -1
  69. package/dist/index.d.ts +1 -1
  70. package/dist/index.js +15 -41
  71. package/dist/index.mjs +5 -1
  72. package/dist/initTRPC-12d9099b.js +371 -0
  73. package/dist/initTRPC-69a60dfb.js +384 -0
  74. package/dist/initTRPC-dcdfb896.mjs +376 -0
  75. package/dist/{nodeHTTPRequestHandler-55f05150.js → nodeHTTPRequestHandler-71a3f758.js} +5 -4
  76. package/dist/{nodeHTTPRequestHandler-2d5c8791.mjs → nodeHTTPRequestHandler-c5d1d163.mjs} +3 -2
  77. package/dist/{nodeHTTPRequestHandler-7691fc79.js → nodeHTTPRequestHandler-f60f0b99.js} +3 -1
  78. package/dist/observable/index.d.ts +5 -0
  79. package/dist/observable/index.d.ts.map +1 -0
  80. package/dist/observable/index.js +110 -0
  81. package/dist/observable/index.mjs +101 -0
  82. package/dist/observable/observable.d.ts +13 -0
  83. package/dist/observable/observable.d.ts.map +1 -0
  84. package/dist/observable/operators.d.ts +8 -0
  85. package/dist/observable/operators.d.ts.map +1 -0
  86. package/dist/observable/types.d.ts +26 -0
  87. package/dist/observable/types.d.ts.map +1 -0
  88. package/dist/observable-25f4098f.js +126 -0
  89. package/dist/observable-bf75028f.mjs +122 -0
  90. package/dist/observable-e837fe43.js +126 -0
  91. package/dist/parseTRPCMessage-aeb00dbd.js +67 -0
  92. package/dist/parseTRPCMessage-ddbcc719.mjs +62 -0
  93. package/dist/parseTRPCMessage-ee50b281.js +65 -0
  94. package/dist/resolveHTTPResponse-104460bf.js +293 -0
  95. package/dist/resolveHTTPResponse-6a85f0a7.js +265 -0
  96. package/dist/resolveHTTPResponse-eb29e5cf.mjs +291 -0
  97. package/dist/rootConfig-52aed7d7.js +88 -0
  98. package/dist/rootConfig-7d3e1fc8.mjs +76 -0
  99. package/dist/rootConfig-ccd626d6.js +83 -0
  100. package/dist/router-5a3e1181.mjs +252 -0
  101. package/dist/router-5e93cd14.js +259 -0
  102. package/dist/router-d9e22315.js +262 -0
  103. package/dist/rpc.d.ts +1 -2
  104. package/dist/rpc.d.ts.map +1 -1
  105. package/dist/rpc.js +5 -13
  106. package/dist/rpc.mjs +2 -1
  107. package/dist/shared.d.ts +1 -1
  108. package/dist/shared.js +4 -9
  109. package/dist/shared.mjs +2 -1
  110. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +6 -0
  111. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -0
  112. package/dist/unstable-core-do-not-import/createProxy.d.ts +19 -0
  113. package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
  114. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +13 -0
  115. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
  116. package/dist/unstable-core-do-not-import/error/formatter.d.ts +33 -0
  117. package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
  118. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
  119. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
  120. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +24 -0
  121. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
  122. package/dist/unstable-core-do-not-import/http/contentType.d.ts +29 -0
  123. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
  124. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
  125. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
  126. package/dist/unstable-core-do-not-import/http/index.d.ts +7 -0
  127. package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
  128. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +51 -0
  129. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
  130. package/dist/unstable-core-do-not-import/http/types.d.ts +96 -0
  131. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
  132. package/dist/unstable-core-do-not-import/index.d.ts +37 -0
  133. package/dist/unstable-core-do-not-import/index.d.ts.map +1 -0
  134. package/dist/unstable-core-do-not-import/index.js +43 -0
  135. package/dist/unstable-core-do-not-import/index.mjs +9 -0
  136. package/dist/unstable-core-do-not-import/initTRPC.d.ts +96 -0
  137. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
  138. package/dist/unstable-core-do-not-import/middleware.d.ts +105 -0
  139. package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
  140. package/dist/unstable-core-do-not-import/parser.d.ts +30 -0
  141. package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
  142. package/dist/unstable-core-do-not-import/procedure.d.ts +72 -0
  143. package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
  144. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +101 -0
  145. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
  146. package/dist/unstable-core-do-not-import/rootConfig.d.ts +75 -0
  147. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
  148. package/dist/unstable-core-do-not-import/router.d.ts +85 -0
  149. package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
  150. package/dist/unstable-core-do-not-import/rpc/codes.d.ts +51 -0
  151. package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
  152. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +97 -0
  153. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
  154. package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
  155. package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
  156. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +5 -0
  157. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
  158. package/dist/unstable-core-do-not-import/serialize.d.ts +62 -0
  159. package/dist/unstable-core-do-not-import/serialize.d.ts.map +1 -0
  160. package/dist/unstable-core-do-not-import/transformer.d.ts +107 -0
  161. package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
  162. package/dist/unstable-core-do-not-import/types.d.ts +98 -0
  163. package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
  164. package/dist/unstable-core-do-not-import/utils.d.ts +27 -0
  165. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
  166. package/package.json +53 -125
  167. package/src/@trpc/server/http.ts +26 -0
  168. package/src/{@trpc-server.ts → @trpc/server/index.ts} +3 -3
  169. package/src/@trpc/server/rpc.ts +26 -0
  170. package/src/adapters/aws-lambda/index.ts +4 -5
  171. package/src/adapters/aws-lambda/utils.ts +3 -4
  172. package/src/adapters/express.ts +1 -3
  173. package/src/adapters/fastify/fastifyRequestHandler.ts +6 -4
  174. package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -2
  175. package/src/adapters/fetch/fetchRequestHandler.ts +6 -4
  176. package/src/adapters/fetch/types.ts +2 -3
  177. package/src/adapters/next.ts +2 -3
  178. package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
  179. package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
  180. package/src/adapters/node-http/content-type/json/index.ts +1 -1
  181. package/src/adapters/node-http/internals/contentType.ts +2 -2
  182. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +6 -4
  183. package/src/adapters/node-http/types.ts +4 -5
  184. package/src/adapters/standalone.ts +2 -2
  185. package/src/adapters/ws.ts +14 -13
  186. package/src/http.ts +1 -26
  187. package/src/index.ts +1 -1
  188. package/src/observable/index.ts +10 -0
  189. package/src/observable/observable.ts +158 -0
  190. package/src/observable/operators.ts +119 -0
  191. package/src/observable/types.ts +76 -0
  192. package/src/rpc.ts +1 -26
  193. package/src/shared.ts +1 -1
  194. package/src/unstable-core-do-not-import/TRPCInferrable.ts +9 -0
  195. package/src/unstable-core-do-not-import/createProxy.ts +59 -0
  196. package/src/unstable-core-do-not-import/error/TRPCError.ts +82 -0
  197. package/src/unstable-core-do-not-import/error/formatter.ts +51 -0
  198. package/src/unstable-core-do-not-import/error/getErrorShape.ts +36 -0
  199. package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +29 -0
  200. package/src/unstable-core-do-not-import/http/contentType.ts +99 -0
  201. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +57 -0
  202. package/src/unstable-core-do-not-import/http/index.ts +23 -0
  203. package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +458 -0
  204. package/src/unstable-core-do-not-import/http/types.ts +111 -0
  205. package/src/unstable-core-do-not-import/index.ts +110 -0
  206. package/src/unstable-core-do-not-import/initTRPC.ts +206 -0
  207. package/src/unstable-core-do-not-import/middleware.ts +233 -0
  208. package/src/unstable-core-do-not-import/parser.ts +94 -0
  209. package/src/unstable-core-do-not-import/procedure.ts +108 -0
  210. package/src/unstable-core-do-not-import/procedureBuilder.ts +458 -0
  211. package/src/unstable-core-do-not-import/rootConfig.ts +90 -0
  212. package/src/unstable-core-do-not-import/router.ts +370 -0
  213. package/src/unstable-core-do-not-import/rpc/codes.ts +44 -0
  214. package/src/unstable-core-do-not-import/rpc/envelopes.ts +136 -0
  215. package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
  216. package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +85 -0
  217. package/src/unstable-core-do-not-import/serialize.ts +122 -0
  218. package/src/unstable-core-do-not-import/transformer.ts +202 -0
  219. package/src/unstable-core-do-not-import/types.ts +151 -0
  220. package/src/unstable-core-do-not-import/utils.ts +59 -0
  221. package/unstable-core-do-not-import/index.d.ts +1 -0
  222. package/unstable-core-do-not-import/index.js +1 -0
  223. package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +0 -9
  224. package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +0 -1
  225. package/dist/@trpc-server/http.d.ts +0 -2
  226. package/dist/@trpc-server/http.d.ts.map +0 -1
  227. package/dist/@trpc-server.d.ts.map +0 -1
  228. package/dist/observable.d.ts +0 -3
  229. package/dist/observable.d.ts.map +0 -1
  230. package/dist/observable.js +0 -32
  231. package/dist/observable.mjs +0 -1
  232. package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -9
  233. package/src/@trpc-server/http.ts +0 -2
  234. package/src/observable.ts +0 -16
@@ -0,0 +1,291 @@
1
+ import { g as getHTTPStatusCode, a as getErrorShape } from './createProxy-f7ba8b4d.mjs';
2
+ import { T as TRPCError, g as getTRPCErrorFromUnknown } from './TRPCError-54f51dec.mjs';
3
+ import { t as transformTRPCResponse, c as callProcedure } from './router-5a3e1181.mjs';
4
+ import { g as getJsonContentTypeInputs } from './contentType-2e62862d.mjs';
5
+
6
+ const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
7
+ GET: 'query',
8
+ POST: 'mutation'
9
+ };
10
+ const fallbackContentTypeHandler = {
11
+ getInputs: getJsonContentTypeInputs
12
+ };
13
+ function initResponse(initOpts) {
14
+ const { ctx , paths , type , responseMeta , untransformedJSON , errors =[] , } = initOpts;
15
+ let status = untransformedJSON ? getHTTPStatusCode(untransformedJSON) : 200;
16
+ const headers = {
17
+ 'Content-Type': 'application/json'
18
+ };
19
+ const eagerGeneration = !untransformedJSON;
20
+ const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [
21
+ untransformedJSON
22
+ ];
23
+ const meta = responseMeta?.({
24
+ ctx,
25
+ paths,
26
+ type,
27
+ data,
28
+ errors,
29
+ eagerGeneration
30
+ }) ?? {};
31
+ for (const [key, value] of Object.entries(meta.headers ?? {})){
32
+ headers[key] = value;
33
+ }
34
+ if (meta.status) {
35
+ status = meta.status;
36
+ }
37
+ return {
38
+ status,
39
+ headers
40
+ };
41
+ }
42
+ async function inputToProcedureCall(procedureOpts) {
43
+ const { opts , ctx , type , input , path } = procedureOpts;
44
+ try {
45
+ const data = await callProcedure({
46
+ procedures: opts.router._def.procedures,
47
+ path,
48
+ getRawInput: async ()=>input,
49
+ ctx,
50
+ type
51
+ });
52
+ return {
53
+ result: {
54
+ data
55
+ }
56
+ };
57
+ } catch (cause) {
58
+ const error = getTRPCErrorFromUnknown(cause);
59
+ opts.onError?.({
60
+ error,
61
+ path,
62
+ input,
63
+ ctx,
64
+ type: type,
65
+ req: opts.req
66
+ });
67
+ return {
68
+ error: getErrorShape({
69
+ config: opts.router._def._config,
70
+ error,
71
+ type,
72
+ path,
73
+ input,
74
+ ctx
75
+ })
76
+ };
77
+ }
78
+ }
79
+ function caughtErrorToData(cause, errorOpts) {
80
+ const { router , req , onError } = errorOpts.opts;
81
+ const error = getTRPCErrorFromUnknown(cause);
82
+ onError?.({
83
+ error,
84
+ path: errorOpts.path,
85
+ input: errorOpts.input,
86
+ ctx: errorOpts.ctx,
87
+ type: errorOpts.type,
88
+ req
89
+ });
90
+ const untransformedJSON = {
91
+ error: getErrorShape({
92
+ config: router._def._config,
93
+ error,
94
+ type: errorOpts.type,
95
+ path: errorOpts.path,
96
+ input: errorOpts.input,
97
+ ctx: errorOpts.ctx
98
+ })
99
+ };
100
+ const transformedJSON = transformTRPCResponse(router._def._config, untransformedJSON);
101
+ const body = JSON.stringify(transformedJSON);
102
+ return {
103
+ error,
104
+ untransformedJSON,
105
+ body
106
+ };
107
+ }
108
+ // implementation
109
+ async function resolveHTTPResponse(opts) {
110
+ const { router , req , unstable_onHead , unstable_onChunk } = opts;
111
+ if (req.method === 'HEAD') {
112
+ // can be used for lambda warmup
113
+ const headResponse = {
114
+ status: 204
115
+ };
116
+ unstable_onHead?.(headResponse, false);
117
+ unstable_onChunk?.([
118
+ -1,
119
+ ''
120
+ ]);
121
+ return headResponse;
122
+ }
123
+ const contentTypeHandler = opts.contentTypeHandler ?? fallbackContentTypeHandler;
124
+ const batchingEnabled = opts.batching?.enabled ?? true;
125
+ const type = HTTP_METHOD_PROCEDURE_TYPE_MAP[req.method] ?? 'unknown';
126
+ let ctx = undefined;
127
+ let paths;
128
+ const isBatchCall = !!req.query.get('batch');
129
+ const isStreamCall = isBatchCall && unstable_onHead && unstable_onChunk && req.headers['trpc-batch-mode'] === 'stream';
130
+ try {
131
+ if (opts.error) {
132
+ throw opts.error;
133
+ }
134
+ if (isBatchCall && !batchingEnabled) {
135
+ throw new Error(`Batching is not enabled on the server`);
136
+ }
137
+ /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
138
+ throw new TRPCError({
139
+ message: 'Subscriptions should use wsLink',
140
+ code: 'METHOD_NOT_SUPPORTED'
141
+ });
142
+ }
143
+ if (type === 'unknown') {
144
+ throw new TRPCError({
145
+ message: `Unexpected request method ${req.method}`,
146
+ code: 'METHOD_NOT_SUPPORTED'
147
+ });
148
+ }
149
+ const inputs = await contentTypeHandler.getInputs({
150
+ isBatchCall,
151
+ req,
152
+ router,
153
+ preprocessedBody: opts.preprocessedBody ?? false
154
+ });
155
+ paths = isBatchCall ? decodeURIComponent(opts.path).split(',') : [
156
+ opts.path
157
+ ];
158
+ const info = {
159
+ isBatchCall,
160
+ calls: paths.map((path, idx)=>({
161
+ path,
162
+ type,
163
+ input: inputs[idx] ?? undefined
164
+ }))
165
+ };
166
+ ctx = await opts.createContext({
167
+ info
168
+ });
169
+ const promises = paths.map((path, index)=>inputToProcedureCall({
170
+ opts,
171
+ ctx,
172
+ type,
173
+ input: inputs[index],
174
+ path
175
+ }));
176
+ if (!isStreamCall) {
177
+ /**
178
+ * Non-streaming response:
179
+ * - await all responses in parallel, blocking on the slowest one
180
+ * - create headers with known response body
181
+ * - return a complete HTTPResponse
182
+ */ const untransformedJSON = await Promise.all(promises);
183
+ const errors = untransformedJSON.flatMap((response)=>'error' in response ? [
184
+ response.error
185
+ ] : []);
186
+ const headResponse1 = initResponse({
187
+ ctx,
188
+ paths,
189
+ type,
190
+ responseMeta: opts.responseMeta,
191
+ untransformedJSON,
192
+ errors
193
+ });
194
+ unstable_onHead?.(headResponse1, false);
195
+ // return body stuff
196
+ const result = isBatchCall ? untransformedJSON : untransformedJSON[0]; // eslint-disable-line @typescript-eslint/no-non-null-assertion -- `untransformedJSON` should be the length of `paths` which should be at least 1 otherwise there wouldn't be a request at all
197
+ const transformedJSON = transformTRPCResponse(router._def._config, result);
198
+ const body = JSON.stringify(transformedJSON);
199
+ unstable_onChunk?.([
200
+ -1,
201
+ body
202
+ ]);
203
+ return {
204
+ status: headResponse1.status,
205
+ headers: headResponse1.headers,
206
+ body
207
+ };
208
+ }
209
+ /**
210
+ * Streaming response:
211
+ * - block on none, call `onChunk` as soon as each response is ready
212
+ * - create headers with minimal data (cannot know the response body in advance)
213
+ * - return void
214
+ */ const headResponse2 = initResponse({
215
+ ctx,
216
+ paths,
217
+ type,
218
+ responseMeta: opts.responseMeta
219
+ });
220
+ unstable_onHead(headResponse2, true);
221
+ const indexedPromises = new Map(promises.map((promise, index)=>[
222
+ index,
223
+ promise.then((r)=>[
224
+ index,
225
+ r
226
+ ])
227
+ ]));
228
+ for (const _ of paths){
229
+ const [index, untransformedJSON1] = await Promise.race(indexedPromises.values());
230
+ indexedPromises.delete(index);
231
+ try {
232
+ const transformedJSON1 = transformTRPCResponse(router._def._config, untransformedJSON1);
233
+ const body1 = JSON.stringify(transformedJSON1);
234
+ unstable_onChunk([
235
+ index,
236
+ body1
237
+ ]);
238
+ } catch (cause) {
239
+ const path = paths[index];
240
+ const input = inputs[index];
241
+ const { body: body2 } = caughtErrorToData(cause, {
242
+ opts,
243
+ ctx,
244
+ type,
245
+ path,
246
+ input
247
+ });
248
+ unstable_onChunk([
249
+ index,
250
+ body2
251
+ ]);
252
+ }
253
+ }
254
+ return;
255
+ } catch (cause1) {
256
+ // we get here if
257
+ // - batching is called when it's not enabled
258
+ // - `createContext()` throws
259
+ // - `router._def._config.transformer.output.serialize()` throws
260
+ // - post body is too large
261
+ // - input deserialization fails
262
+ // - `errorFormatter` return value is malformed
263
+ const { error , untransformedJSON: untransformedJSON2 , body: body3 } = caughtErrorToData(cause1, {
264
+ opts,
265
+ ctx,
266
+ type
267
+ });
268
+ const headResponse3 = initResponse({
269
+ ctx,
270
+ paths,
271
+ type,
272
+ responseMeta: opts.responseMeta,
273
+ untransformedJSON: untransformedJSON2,
274
+ errors: [
275
+ error
276
+ ]
277
+ });
278
+ unstable_onHead?.(headResponse3, false);
279
+ unstable_onChunk?.([
280
+ -1,
281
+ body3
282
+ ]);
283
+ return {
284
+ status: headResponse3.status,
285
+ headers: headResponse3.headers,
286
+ body: body3
287
+ };
288
+ }
289
+ }
290
+
291
+ export { resolveHTTPResponse as r };
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ function invert(obj) {
5
+ const newObj = Object.create(null);
6
+ for (const key in obj) {
7
+ const v = obj[key];
8
+ newObj[v] = key;
9
+ }
10
+ return newObj;
11
+ }
12
+ /**
13
+ * Ensures there are no duplicate keys when building a procedure.
14
+ * @internal
15
+ */
16
+ function mergeWithoutOverrides(obj1, ...objs) {
17
+ const newObj = Object.assign(Object.create(null), obj1);
18
+ for (const overrides of objs) {
19
+ for (const key in overrides) {
20
+ if (key in newObj && newObj[key] !== overrides[key]) {
21
+ throw new Error(`Duplicate key ${key}`);
22
+ }
23
+ newObj[key] = overrides[key];
24
+ }
25
+ }
26
+ return newObj;
27
+ }
28
+ /**
29
+ * Check that value is object
30
+ * @internal
31
+ */
32
+ function isObject(value) {
33
+ return !!value && !Array.isArray(value) && typeof value === 'object';
34
+ }
35
+ /**
36
+ * Create an object without inheriting anything from `Object.prototype`
37
+ * @internal
38
+ */
39
+ function omitPrototype(obj) {
40
+ return Object.assign(Object.create(null), obj);
41
+ }
42
+
43
+ // reference: https://www.jsonrpc.org/specification
44
+ /**
45
+ * JSON-RPC 2.0 Error codes
46
+ *
47
+ * `-32000` to `-32099` are reserved for implementation-defined server-errors.
48
+ * For tRPC we're copying the last digits of HTTP 4XX errors.
49
+ */
50
+ const TRPC_ERROR_CODES_BY_KEY = {
51
+ /**
52
+ * Invalid JSON was received by the server.
53
+ * An error occurred on the server while parsing the JSON text.
54
+ */
55
+ PARSE_ERROR: -32700,
56
+ /**
57
+ * The JSON sent is not a valid Request object.
58
+ */
59
+ BAD_REQUEST: -32600, // 400
60
+ // Internal JSON-RPC error
61
+ INTERNAL_SERVER_ERROR: -32603,
62
+ NOT_IMPLEMENTED: -32603,
63
+ // Implementation specific errors
64
+ UNAUTHORIZED: -32001, // 401
65
+ FORBIDDEN: -32003, // 403
66
+ NOT_FOUND: -32004, // 404
67
+ METHOD_NOT_SUPPORTED: -32005, // 405
68
+ TIMEOUT: -32008, // 408
69
+ CONFLICT: -32009, // 409
70
+ PRECONDITION_FAILED: -32012, // 412
71
+ PAYLOAD_TOO_LARGE: -32013, // 413
72
+ UNPROCESSABLE_CONTENT: -32022, // 422
73
+ TOO_MANY_REQUESTS: -32029, // 429
74
+ CLIENT_CLOSED_REQUEST: -32099, // 499
75
+ };
76
+ const TRPC_ERROR_CODES_BY_NUMBER = invert(TRPC_ERROR_CODES_BY_KEY);
77
+
78
+ /**
79
+ * The default check to see if we're in a server
80
+ */
81
+ const isServerDefault = typeof window === 'undefined' ||
82
+ 'Deno' in window ||
83
+ // eslint-disable-next-line @typescript-eslint/dot-notation
84
+ globalThis.process?.env?.['NODE_ENV'] === 'test' ||
85
+ !!globalThis.process?.env?.['JEST_WORKER_ID'] ||
86
+ !!globalThis.process?.env?.['VITEST_WORKER_ID'];
87
+
88
+ export { TRPC_ERROR_CODES_BY_NUMBER as T, TRPC_ERROR_CODES_BY_KEY as a, isServerDefault as b, isObject as i, mergeWithoutOverrides as m, omitPrototype as o };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @internal
3
+ */ function invert(obj) {
4
+ const newObj = Object.create(null);
5
+ for(const key in obj){
6
+ const v = obj[key];
7
+ newObj[v] = key;
8
+ }
9
+ return newObj;
10
+ }
11
+ /**
12
+ * Ensures there are no duplicate keys when building a procedure.
13
+ * @internal
14
+ */ function mergeWithoutOverrides(obj1, ...objs) {
15
+ const newObj = Object.assign(Object.create(null), obj1);
16
+ for (const overrides of objs){
17
+ for(const key in overrides){
18
+ if (key in newObj && newObj[key] !== overrides[key]) {
19
+ throw new Error(`Duplicate key ${key}`);
20
+ }
21
+ newObj[key] = overrides[key];
22
+ }
23
+ }
24
+ return newObj;
25
+ }
26
+ /**
27
+ * Check that value is object
28
+ * @internal
29
+ */ function isObject(value) {
30
+ return !!value && !Array.isArray(value) && typeof value === 'object';
31
+ }
32
+ /**
33
+ * Create an object without inheriting anything from `Object.prototype`
34
+ * @internal
35
+ */ function omitPrototype(obj) {
36
+ return Object.assign(Object.create(null), obj);
37
+ }
38
+
39
+ // reference: https://www.jsonrpc.org/specification
40
+ /**
41
+ * JSON-RPC 2.0 Error codes
42
+ *
43
+ * `-32000` to `-32099` are reserved for implementation-defined server-errors.
44
+ * For tRPC we're copying the last digits of HTTP 4XX errors.
45
+ */ const TRPC_ERROR_CODES_BY_KEY = {
46
+ /**
47
+ * Invalid JSON was received by the server.
48
+ * An error occurred on the server while parsing the JSON text.
49
+ */ PARSE_ERROR: -32700,
50
+ /**
51
+ * The JSON sent is not a valid Request object.
52
+ */ BAD_REQUEST: -32600,
53
+ // Internal JSON-RPC error
54
+ INTERNAL_SERVER_ERROR: -32603,
55
+ NOT_IMPLEMENTED: -32603,
56
+ // Implementation specific errors
57
+ UNAUTHORIZED: -32001,
58
+ FORBIDDEN: -32003,
59
+ NOT_FOUND: -32004,
60
+ METHOD_NOT_SUPPORTED: -32005,
61
+ TIMEOUT: -32008,
62
+ CONFLICT: -32009,
63
+ PRECONDITION_FAILED: -32012,
64
+ PAYLOAD_TOO_LARGE: -32013,
65
+ UNPROCESSABLE_CONTENT: -32022,
66
+ TOO_MANY_REQUESTS: -32029,
67
+ CLIENT_CLOSED_REQUEST: -32099
68
+ };
69
+ const TRPC_ERROR_CODES_BY_NUMBER = invert(TRPC_ERROR_CODES_BY_KEY);
70
+
71
+ /**
72
+ * The default check to see if we're in a server
73
+ */ const isServerDefault = typeof window === 'undefined' || 'Deno' in window || // eslint-disable-next-line @typescript-eslint/dot-notation
74
+ globalThis.process?.env?.['NODE_ENV'] === 'test' || !!globalThis.process?.env?.['JEST_WORKER_ID'] || !!globalThis.process?.env?.['VITEST_WORKER_ID'];
75
+
76
+ export { TRPC_ERROR_CODES_BY_NUMBER as T, TRPC_ERROR_CODES_BY_KEY as a, isServerDefault as b, isObject as i, mergeWithoutOverrides as m, omitPrototype as o };
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @internal
5
+ */ function invert(obj) {
6
+ const newObj = Object.create(null);
7
+ for(const key in obj){
8
+ const v = obj[key];
9
+ newObj[v] = key;
10
+ }
11
+ return newObj;
12
+ }
13
+ /**
14
+ * Ensures there are no duplicate keys when building a procedure.
15
+ * @internal
16
+ */ function mergeWithoutOverrides(obj1, ...objs) {
17
+ const newObj = Object.assign(Object.create(null), obj1);
18
+ for (const overrides of objs){
19
+ for(const key in overrides){
20
+ if (key in newObj && newObj[key] !== overrides[key]) {
21
+ throw new Error(`Duplicate key ${key}`);
22
+ }
23
+ newObj[key] = overrides[key];
24
+ }
25
+ }
26
+ return newObj;
27
+ }
28
+ /**
29
+ * Check that value is object
30
+ * @internal
31
+ */ function isObject(value) {
32
+ return !!value && !Array.isArray(value) && typeof value === 'object';
33
+ }
34
+ /**
35
+ * Create an object without inheriting anything from `Object.prototype`
36
+ * @internal
37
+ */ function omitPrototype(obj) {
38
+ return Object.assign(Object.create(null), obj);
39
+ }
40
+
41
+ // reference: https://www.jsonrpc.org/specification
42
+ /**
43
+ * JSON-RPC 2.0 Error codes
44
+ *
45
+ * `-32000` to `-32099` are reserved for implementation-defined server-errors.
46
+ * For tRPC we're copying the last digits of HTTP 4XX errors.
47
+ */ const TRPC_ERROR_CODES_BY_KEY = {
48
+ /**
49
+ * Invalid JSON was received by the server.
50
+ * An error occurred on the server while parsing the JSON text.
51
+ */ PARSE_ERROR: -32700,
52
+ /**
53
+ * The JSON sent is not a valid Request object.
54
+ */ BAD_REQUEST: -32600,
55
+ // Internal JSON-RPC error
56
+ INTERNAL_SERVER_ERROR: -32603,
57
+ NOT_IMPLEMENTED: -32603,
58
+ // Implementation specific errors
59
+ UNAUTHORIZED: -32001,
60
+ FORBIDDEN: -32003,
61
+ NOT_FOUND: -32004,
62
+ METHOD_NOT_SUPPORTED: -32005,
63
+ TIMEOUT: -32008,
64
+ CONFLICT: -32009,
65
+ PRECONDITION_FAILED: -32012,
66
+ PAYLOAD_TOO_LARGE: -32013,
67
+ UNPROCESSABLE_CONTENT: -32022,
68
+ TOO_MANY_REQUESTS: -32029,
69
+ CLIENT_CLOSED_REQUEST: -32099
70
+ };
71
+ const TRPC_ERROR_CODES_BY_NUMBER = invert(TRPC_ERROR_CODES_BY_KEY);
72
+
73
+ /**
74
+ * The default check to see if we're in a server
75
+ */ const isServerDefault = typeof window === 'undefined' || 'Deno' in window || // eslint-disable-next-line @typescript-eslint/dot-notation
76
+ globalThis.process?.env?.['NODE_ENV'] === 'test' || !!globalThis.process?.env?.['JEST_WORKER_ID'] || !!globalThis.process?.env?.['VITEST_WORKER_ID'];
77
+
78
+ exports.TRPC_ERROR_CODES_BY_KEY = TRPC_ERROR_CODES_BY_KEY;
79
+ exports.TRPC_ERROR_CODES_BY_NUMBER = TRPC_ERROR_CODES_BY_NUMBER;
80
+ exports.isObject = isObject;
81
+ exports.isServerDefault = isServerDefault;
82
+ exports.mergeWithoutOverrides = mergeWithoutOverrides;
83
+ exports.omitPrototype = omitPrototype;