@trpc/server 11.0.0-rc.590 → 11.0.0-rc.592

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,7 +1,7 @@
1
1
  {
2
- "bundleSize": 147003,
3
- "bundleOrigSize": 194022,
4
- "bundleReduction": 24.23,
2
+ "bundleSize": 147618,
3
+ "bundleOrigSize": 194570,
4
+ "bundleReduction": 24.13,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/unstable-core-do-not-import/http/resolveResponse.ts",
@@ -14,7 +14,7 @@
14
14
  "dependents": [
15
15
  "/src/unstable-core-do-not-import.ts"
16
16
  ],
17
- "percent": 13.04,
17
+ "percent": 12.98,
18
18
  "reduction": 0
19
19
  },
20
20
  {
@@ -31,7 +31,7 @@
31
31
  "/src/unstable-core-do-not-import.ts",
32
32
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
33
33
  ],
34
- "percent": 11.95,
34
+ "percent": 11.9,
35
35
  "reduction": 4.86
36
36
  },
37
37
  {
@@ -47,7 +47,7 @@
47
47
  "dependents": [
48
48
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
49
49
  ],
50
- "percent": 11.08,
50
+ "percent": 11.03,
51
51
  "reduction": 0
52
52
  },
53
53
  {
@@ -64,7 +64,7 @@
64
64
  "/src/unstable-core-do-not-import.ts",
65
65
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
66
66
  ],
67
- "percent": 6.19,
67
+ "percent": 6.16,
68
68
  "reduction": 14.8
69
69
  },
70
70
  {
@@ -79,7 +79,7 @@
79
79
  "/src/unstable-core-do-not-import.ts",
80
80
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
81
81
  ],
82
- "percent": 5.23,
82
+ "percent": 5.21,
83
83
  "reduction": 0
84
84
  },
85
85
  {
@@ -97,7 +97,7 @@
97
97
  "/src/unstable-core-do-not-import.ts",
98
98
  "/src/unstable-core-do-not-import/initTRPC.ts"
99
99
  ],
100
- "percent": 4.37,
100
+ "percent": 4.35,
101
101
  "reduction": 40.09
102
102
  },
103
103
  {
@@ -112,7 +112,7 @@
112
112
  "/src/unstable-core-do-not-import.ts",
113
113
  "/src/unstable-core-do-not-import/initTRPC.ts"
114
114
  ],
115
- "percent": 3.94,
115
+ "percent": 3.93,
116
116
  "reduction": 64.74
117
117
  },
118
118
  {
@@ -126,7 +126,7 @@
126
126
  "dependents": [
127
127
  "/src/adapters/aws-lambda/index.ts"
128
128
  ],
129
- "percent": 3.69,
129
+ "percent": 3.67,
130
130
  "reduction": 11.38
131
131
  },
132
132
  {
@@ -145,7 +145,7 @@
145
145
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
146
146
  "/src/observable/operators.ts"
147
147
  ],
148
- "percent": 3.05,
148
+ "percent": 3.03,
149
149
  "reduction": 0
150
150
  },
151
151
  {
@@ -160,7 +160,7 @@
160
160
  "dependents": [
161
161
  "/src/adapters/node-http/index.ts"
162
162
  ],
163
- "percent": 3.04,
163
+ "percent": 3.02,
164
164
  "reduction": 2.49
165
165
  },
166
166
  {
@@ -174,7 +174,7 @@
174
174
  "dependents": [
175
175
  "/src/adapters/next-app-dir.ts"
176
176
  ],
177
- "percent": 2.19,
177
+ "percent": 2.18,
178
178
  "reduction": 22.57
179
179
  },
180
180
  {
@@ -206,11 +206,11 @@
206
206
  "removedExports": [],
207
207
  "dependents": [
208
208
  "/src/unstable-core-do-not-import.ts",
209
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts",
209
210
  "/src/unstable-core-do-not-import/initTRPC.ts",
210
- "/src/unstable-core-do-not-import/router.ts",
211
- "/src/unstable-core-do-not-import/http/resolveResponse.ts"
211
+ "/src/unstable-core-do-not-import/router.ts"
212
212
  ],
213
- "percent": 1.87,
213
+ "percent": 1.86,
214
214
  "reduction": 45.94
215
215
  },
216
216
  {
@@ -244,13 +244,13 @@
244
244
  "/src/unstable-core-do-not-import/initTRPC.ts",
245
245
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
246
246
  ],
247
- "percent": 1.79,
247
+ "percent": 1.78,
248
248
  "reduction": 55.78
249
249
  },
250
250
  {
251
251
  "id": "/src/unstable-core-do-not-import/utils.ts",
252
- "size": 2494,
253
- "origSize": 3008,
252
+ "size": 2460,
253
+ "origSize": 2982,
254
254
  "renderedExports": [
255
255
  "unsetMarker",
256
256
  "mergeWithoutOverrides",
@@ -268,13 +268,13 @@
268
268
  "removedExports": [],
269
269
  "dependents": [
270
270
  "/src/unstable-core-do-not-import.ts",
271
+ "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
272
+ "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
273
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts",
271
274
  "/src/unstable-core-do-not-import/error/TRPCError.ts",
272
275
  "/src/unstable-core-do-not-import/transformer.ts",
273
276
  "/src/unstable-core-do-not-import/middleware.ts",
274
277
  "/src/unstable-core-do-not-import/router.ts",
275
- "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
276
- "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
277
- "/src/unstable-core-do-not-import/http/resolveResponse.ts",
278
278
  "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
279
279
  "/src/unstable-core-do-not-import/http/contentType.ts",
280
280
  "/src/unstable-core-do-not-import/procedureBuilder.ts",
@@ -282,8 +282,8 @@
282
282
  "/src/unstable-core-do-not-import/stream/sse.ts",
283
283
  "/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts"
284
284
  ],
285
- "percent": 1.7,
286
- "reduction": 17.09
285
+ "percent": 1.67,
286
+ "reduction": 17.51
287
287
  },
288
288
  {
289
289
  "id": "/src/unstable-core-do-not-import/createProxy.ts",
@@ -330,6 +330,27 @@
330
330
  "percent": 1.5,
331
331
  "reduction": 14.72
332
332
  },
333
+ {
334
+ "id": "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
335
+ "size": 2087,
336
+ "origSize": 2562,
337
+ "renderedExports": [
338
+ "JSONRPC2_TO_HTTP_CODE",
339
+ "HTTP_CODE_TO_JSONRPC2",
340
+ "getStatusCodeFromKey",
341
+ "getStatusKeyFromCode",
342
+ "getHTTPStatusCode",
343
+ "getHTTPStatusCodeFromError"
344
+ ],
345
+ "removedExports": [],
346
+ "dependents": [
347
+ "/src/unstable-core-do-not-import.ts",
348
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts",
349
+ "/src/unstable-core-do-not-import/error/getErrorShape.ts"
350
+ ],
351
+ "percent": 1.41,
352
+ "reduction": 18.54
353
+ },
333
354
  {
334
355
  "id": "/src/adapters/next-app-dir/rethrowNextErrors.ts",
335
356
  "size": 2050,
@@ -370,17 +391,17 @@
370
391
  "removedExports": [],
371
392
  "dependents": [
372
393
  "/src/unstable-core-do-not-import.ts",
373
- "/src/unstable-core-do-not-import/middleware.ts",
374
- "/src/unstable-core-do-not-import/router.ts",
375
394
  "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
376
395
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
377
396
  "/src/unstable-core-do-not-import/http/toURL.ts",
397
+ "/src/unstable-core-do-not-import/middleware.ts",
398
+ "/src/unstable-core-do-not-import/router.ts",
378
399
  "/src/unstable-core-do-not-import/http/contentType.ts",
379
400
  "/src/unstable-core-do-not-import/procedureBuilder.ts",
380
401
  "/src/unstable-core-do-not-import/stream/jsonl.ts",
381
402
  "/src/unstable-core-do-not-import/stream/sse.ts"
382
403
  ],
383
- "percent": 1.18,
404
+ "percent": 1.17,
384
405
  "reduction": 19.47
385
406
  },
386
407
  {
@@ -392,7 +413,7 @@
392
413
  ],
393
414
  "removedExports": [],
394
415
  "dependents": [],
395
- "percent": 1.16,
416
+ "percent": 1.15,
396
417
  "reduction": 19.29
397
418
  },
398
419
  {
@@ -407,38 +428,21 @@
407
428
  "dependents": [
408
429
  "/src/unstable-core-do-not-import/stream/sse.ts"
409
430
  ],
410
- "percent": 1.13,
431
+ "percent": 1.12,
411
432
  "reduction": 4.61
412
433
  },
413
434
  {
414
435
  "id": "/src/unstable-core-do-not-import/rpc/codes.ts",
415
436
  "size": 1611,
416
- "origSize": 2221,
437
+ "origSize": 1960,
417
438
  "renderedExports": [
418
439
  "TRPC_ERROR_CODES_BY_KEY",
419
440
  "TRPC_ERROR_CODES_BY_NUMBER"
420
441
  ],
421
442
  "removedExports": [],
422
443
  "dependents": [],
423
- "percent": 1.1,
424
- "reduction": 27.47
425
- },
426
- {
427
- "id": "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
428
- "size": 1438,
429
- "origSize": 1727,
430
- "renderedExports": [
431
- "getHTTPStatusCode",
432
- "getHTTPStatusCodeFromError"
433
- ],
434
- "removedExports": [],
435
- "dependents": [
436
- "/src/unstable-core-do-not-import.ts",
437
- "/src/unstable-core-do-not-import/error/getErrorShape.ts",
438
- "/src/unstable-core-do-not-import/http/resolveResponse.ts"
439
- ],
440
- "percent": 0.98,
441
- "reduction": 16.73
444
+ "percent": 1.09,
445
+ "reduction": 17.81
442
446
  },
443
447
  {
444
448
  "id": "/src/adapters/next.ts",
@@ -582,7 +586,7 @@
582
586
  ],
583
587
  "removedExports": [],
584
588
  "dependents": [],
585
- "percent": 0.52,
589
+ "percent": 0.51,
586
590
  "reduction": 66.9
587
591
  },
588
592
  {
@@ -656,37 +660,37 @@
656
660
  "/src/unstable-core-do-not-import.ts",
657
661
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
658
662
  ],
659
- "percent": 0.43,
663
+ "percent": 0.42,
660
664
  "reduction": 43.49
661
665
  },
662
666
  {
663
- "id": "/src/unstable-core-do-not-import/rootConfig.ts",
667
+ "id": "/src/unstable-core-do-not-import/http/toURL.ts",
664
668
  "size": 343,
665
- "origSize": 3267,
669
+ "origSize": 377,
666
670
  "renderedExports": [
667
- "isServerDefault"
671
+ "toURL"
668
672
  ],
669
673
  "removedExports": [],
670
674
  "dependents": [
671
- "/src/unstable-core-do-not-import.ts",
672
- "/src/unstable-core-do-not-import/initTRPC.ts"
675
+ "/src/unstable-core-do-not-import.ts"
673
676
  ],
674
677
  "percent": 0.23,
675
- "reduction": 89.5
678
+ "reduction": 9.02
676
679
  },
677
680
  {
678
- "id": "/src/unstable-core-do-not-import/http/toURL.ts",
681
+ "id": "/src/unstable-core-do-not-import/rootConfig.ts",
679
682
  "size": 343,
680
- "origSize": 377,
683
+ "origSize": 3267,
681
684
  "renderedExports": [
682
- "toURL"
685
+ "isServerDefault"
683
686
  ],
684
687
  "removedExports": [],
685
688
  "dependents": [
686
- "/src/unstable-core-do-not-import.ts"
689
+ "/src/unstable-core-do-not-import.ts",
690
+ "/src/unstable-core-do-not-import/initTRPC.ts"
687
691
  ],
688
692
  "percent": 0.23,
689
- "reduction": 9.02
693
+ "reduction": 89.5
690
694
  },
691
695
  {
692
696
  "id": "/src/unstable-core-do-not-import/stream/utils/createDeferred.ts",
@@ -766,25 +770,25 @@
766
770
  "reduction": 93.8
767
771
  },
768
772
  {
769
- "id": "/src/index.ts",
773
+ "id": "/src/http.ts",
770
774
  "size": 0,
771
- "origSize": 32,
775
+ "origSize": 37,
772
776
  "renderedExports": [],
773
777
  "removedExports": [],
774
- "dependents": [],
778
+ "dependents": [
779
+ "/src/adapters/ws.ts",
780
+ "/src/adapters/node-http/incomingMessageToRequest.ts"
781
+ ],
775
782
  "percent": 0,
776
783
  "reduction": 100
777
784
  },
778
785
  {
779
- "id": "/src/http.ts",
786
+ "id": "/src/index.ts",
780
787
  "size": 0,
781
- "origSize": 37,
788
+ "origSize": 32,
782
789
  "renderedExports": [],
783
790
  "removedExports": [],
784
- "dependents": [
785
- "/src/adapters/ws.ts",
786
- "/src/adapters/node-http/incomingMessageToRequest.ts"
787
- ],
791
+ "dependents": [],
788
792
  "percent": 0,
789
793
  "reduction": 100
790
794
  },
@@ -1,5 +1,10 @@
1
1
  import type { TRPCError } from '../error/TRPCError';
2
- import type { TRPCResponse } from '../rpc';
2
+ import type { TRPC_ERROR_CODES_BY_KEY, TRPCResponse } from '../rpc';
3
+ import type { InvertKeyValue, ValueOf } from '../types';
4
+ export declare const JSONRPC2_TO_HTTP_CODE: Record<keyof typeof TRPC_ERROR_CODES_BY_KEY, number>;
5
+ export declare const HTTP_CODE_TO_JSONRPC2: InvertKeyValue<typeof JSONRPC2_TO_HTTP_CODE>;
6
+ export declare function getStatusCodeFromKey(code: keyof typeof TRPC_ERROR_CODES_BY_KEY): number;
7
+ export declare function getStatusKeyFromCode(code: keyof typeof HTTP_CODE_TO_JSONRPC2): ValueOf<typeof HTTP_CODE_TO_JSONRPC2>;
3
8
  export declare function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]): number;
4
9
  export declare function getHTTPStatusCodeFromError(error: TRPCError): number;
5
10
  //# sourceMappingURL=getHTTPStatusCode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getHTTPStatusCode.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/getHTTPStatusCode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,QAAQ,CAAC;AAiCpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,MAAM,CAuB7E;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,UAE1D"}
1
+ {"version":3,"file":"getHTTPStatusCode.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/getHTTPStatusCode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEpE,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGxD,eAAO,MAAM,qBAAqB,EAAE,MAAM,CACxC,MAAM,OAAO,uBAAuB,EACpC,MAAM,CAqBP,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAChD,OAAO,qBAAqB,CAoBpB,CAAC;AAEX,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,OAAO,uBAAuB,UAG3C;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,OAAO,qBAAqB,GACvC,OAAO,CAAC,OAAO,qBAAqB,CAAC,CAEvC;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,UAuBpE;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,UAE1D"}
@@ -24,9 +24,32 @@ const JSONRPC2_TO_HTTP_CODE = {
24
24
  SERVICE_UNAVAILABLE: 503,
25
25
  GATEWAY_TIMEOUT: 504
26
26
  };
27
+ const HTTP_CODE_TO_JSONRPC2 = {
28
+ 400: 'BAD_REQUEST',
29
+ 401: 'UNAUTHORIZED',
30
+ 403: 'FORBIDDEN',
31
+ 404: 'NOT_FOUND',
32
+ 405: 'METHOD_NOT_SUPPORTED',
33
+ 408: 'TIMEOUT',
34
+ 409: 'CONFLICT',
35
+ 412: 'PRECONDITION_FAILED',
36
+ 413: 'PAYLOAD_TOO_LARGE',
37
+ 415: 'UNSUPPORTED_MEDIA_TYPE',
38
+ 422: 'UNPROCESSABLE_CONTENT',
39
+ 429: 'TOO_MANY_REQUESTS',
40
+ 499: 'CLIENT_CLOSED_REQUEST',
41
+ 500: 'INTERNAL_SERVER_ERROR',
42
+ 501: 'NOT_IMPLEMENTED',
43
+ 502: 'BAD_GATEWAY',
44
+ 503: 'SERVICE_UNAVAILABLE',
45
+ 504: 'GATEWAY_TIMEOUT'
46
+ };
27
47
  function getStatusCodeFromKey(code) {
28
48
  return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
29
49
  }
50
+ function getStatusKeyFromCode(code) {
51
+ return HTTP_CODE_TO_JSONRPC2[code] ?? 'INTERNAL_SERVER_ERROR';
52
+ }
30
53
  function getHTTPStatusCode(json) {
31
54
  const arr = Array.isArray(json) ? json : [
32
55
  json
@@ -52,5 +75,9 @@ function getHTTPStatusCodeFromError(error) {
52
75
  return getStatusCodeFromKey(error.code);
53
76
  }
54
77
 
78
+ exports.HTTP_CODE_TO_JSONRPC2 = HTTP_CODE_TO_JSONRPC2;
79
+ exports.JSONRPC2_TO_HTTP_CODE = JSONRPC2_TO_HTTP_CODE;
55
80
  exports.getHTTPStatusCode = getHTTPStatusCode;
56
81
  exports.getHTTPStatusCodeFromError = getHTTPStatusCodeFromError;
82
+ exports.getStatusCodeFromKey = getStatusCodeFromKey;
83
+ exports.getStatusKeyFromCode = getStatusKeyFromCode;
@@ -22,9 +22,32 @@ const JSONRPC2_TO_HTTP_CODE = {
22
22
  SERVICE_UNAVAILABLE: 503,
23
23
  GATEWAY_TIMEOUT: 504
24
24
  };
25
+ const HTTP_CODE_TO_JSONRPC2 = {
26
+ 400: 'BAD_REQUEST',
27
+ 401: 'UNAUTHORIZED',
28
+ 403: 'FORBIDDEN',
29
+ 404: 'NOT_FOUND',
30
+ 405: 'METHOD_NOT_SUPPORTED',
31
+ 408: 'TIMEOUT',
32
+ 409: 'CONFLICT',
33
+ 412: 'PRECONDITION_FAILED',
34
+ 413: 'PAYLOAD_TOO_LARGE',
35
+ 415: 'UNSUPPORTED_MEDIA_TYPE',
36
+ 422: 'UNPROCESSABLE_CONTENT',
37
+ 429: 'TOO_MANY_REQUESTS',
38
+ 499: 'CLIENT_CLOSED_REQUEST',
39
+ 500: 'INTERNAL_SERVER_ERROR',
40
+ 501: 'NOT_IMPLEMENTED',
41
+ 502: 'BAD_GATEWAY',
42
+ 503: 'SERVICE_UNAVAILABLE',
43
+ 504: 'GATEWAY_TIMEOUT'
44
+ };
25
45
  function getStatusCodeFromKey(code) {
26
46
  return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
27
47
  }
48
+ function getStatusKeyFromCode(code) {
49
+ return HTTP_CODE_TO_JSONRPC2[code] ?? 'INTERNAL_SERVER_ERROR';
50
+ }
28
51
  function getHTTPStatusCode(json) {
29
52
  const arr = Array.isArray(json) ? json : [
30
53
  json
@@ -50,4 +73,4 @@ function getHTTPStatusCodeFromError(error) {
50
73
  return getStatusCodeFromKey(error.code);
51
74
  }
52
75
 
53
- export { getHTTPStatusCode, getHTTPStatusCodeFromError };
76
+ export { HTTP_CODE_TO_JSONRPC2, JSONRPC2_TO_HTTP_CODE, getHTTPStatusCode, getHTTPStatusCodeFromError, getStatusCodeFromKey, getStatusKeyFromCode };
@@ -1,4 +1,4 @@
1
- import type { ValueOf } from '../types';
1
+ import type { InvertKeyValue, ValueOf } from '../types';
2
2
  /**
3
3
  * JSON-RPC 2.0 Error codes
4
4
  *
@@ -33,14 +33,7 @@ export declare const TRPC_ERROR_CODES_BY_KEY: {
33
33
  readonly TOO_MANY_REQUESTS: -32029;
34
34
  readonly CLIENT_CLOSED_REQUEST: -32099;
35
35
  };
36
- type KeyFromValue<TValue, TType extends Record<PropertyKey, PropertyKey>> = {
37
- [K in keyof TType]: TValue extends TType[K] ? K : never;
38
- }[keyof TType];
39
- type Invert<TType extends Record<PropertyKey, PropertyKey>> = {
40
- [TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
41
- };
42
- export declare const TRPC_ERROR_CODES_BY_NUMBER: Invert<typeof TRPC_ERROR_CODES_BY_KEY>;
36
+ export declare const TRPC_ERROR_CODES_BY_NUMBER: InvertKeyValue<typeof TRPC_ERROR_CODES_BY_KEY>;
43
37
  export type TRPC_ERROR_CODE_NUMBER = ValueOf<typeof TRPC_ERROR_CODES_BY_KEY>;
44
38
  export type TRPC_ERROR_CODE_KEY = keyof typeof TRPC_ERROR_CODES_BY_KEY;
45
- export {};
46
39
  //# sourceMappingURL=codes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/rpc/codes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAIxC;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;IAClC;;;OAGG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;CAuBK,CAAC;AAEX,KAAK,YAAY,CAAC,MAAM,EAAE,KAAK,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI;KACzE,CAAC,IAAI,MAAM,KAAK,GAAG,MAAM,SAAS,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACxD,CAAC,MAAM,KAAK,CAAC,CAAC;AAEf,KAAK,MAAM,CAAC,KAAK,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI;KAC3D,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;CAC5D,CAAC;AAGF,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAC7C,OAAO,uBAAuB,CAiB/B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC7E,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,uBAAuB,CAAC"}
1
+ {"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/rpc/codes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAIxD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;IAClC;;;OAGG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;CAuBK,CAAC;AAGX,eAAO,MAAM,0BAA0B,EAAE,cAAc,CACrD,OAAO,uBAAuB,CAiB/B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC7E,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,uBAAuB,CAAC"}
@@ -87,6 +87,12 @@ export type ValidateShape<TActualShape, TExpectedShape> = TActualShape extends T
87
87
  * @internal
88
88
  */
89
89
  export type PickFirstDefined<TType, TPick> = undefined extends TType ? undefined extends TPick ? never : TPick : TType;
90
+ export type KeyFromValue<TValue, TType extends Record<PropertyKey, PropertyKey>> = {
91
+ [K in keyof TType]: TValue extends TType[K] ? K : never;
92
+ }[keyof TType];
93
+ export type InvertKeyValue<TType extends Record<PropertyKey, PropertyKey>> = {
94
+ [TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
95
+ };
90
96
  /**
91
97
  * ================================
92
98
  * tRPC specific types
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI,KAAK,SAAS,GAAG,EAAE,GAAG,IAAI,GACpD,KAAK,GACL;KAAG,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;CAAE,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;AAEzD,MAAM,MAAM,UAAU,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,IAAI;KACpD,IAAI,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,IAAI,GAAG,KAAK;CAChE,CAAC,MAAM,IAAI,CAAC,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO,IACpC;IAAE,EAAE,EAAE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SAAS,KAAK,GACvB,KAAK,GAAG,KAAK,GACb,iBAAiB,CAAC,MAAM,GAAG,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAEnD,QAAA,MAAM,WAAW,eAAW,CAAC;AAC7B,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC;AAC7C,MAAM,MAAM,SAAS,CAAC,QAAQ,SAAS,MAAM,IAAI,QAAQ,GAAG;IAC1D,CAAC,EAAE,OAAO,WAAW,CAAC;CACvB,CAAC;AACF,MAAM,MAAM,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC"}
@@ -67,11 +67,11 @@ function sleep(ms = 0) {
67
67
  for (const signal of signals){
68
68
  if (signal.aborted) {
69
69
  trigger();
70
- } else if (!ac.signal.aborted) {
71
- signal.addEventListener('abort', trigger, {
72
- once: true
73
- });
70
+ break;
74
71
  }
72
+ signal.addEventListener('abort', trigger, {
73
+ once: true
74
+ });
75
75
  }
76
76
  return ac.signal;
77
77
  function trigger() {
@@ -65,11 +65,11 @@ function sleep(ms = 0) {
65
65
  for (const signal of signals){
66
66
  if (signal.aborted) {
67
67
  trigger();
68
- } else if (!ac.signal.aborted) {
69
- signal.addEventListener('abort', trigger, {
70
- once: true
71
- });
68
+ break;
72
69
  }
70
+ signal.addEventListener('abort', trigger, {
71
+ once: true
72
+ });
73
73
  }
74
74
  return ac.signal;
75
75
  function trigger() {
@@ -41,8 +41,12 @@ exports.getBatchStreamFormatter = batchStreamFormatter.getBatchStreamFormatter;
41
41
  exports.getRequestInfo = contentType.getRequestInfo;
42
42
  exports.octetInputParser = contentTypeParsers.octetInputParser;
43
43
  exports.formDataToObject = formDataToObject.formDataToObject;
44
+ exports.HTTP_CODE_TO_JSONRPC2 = getHTTPStatusCode.HTTP_CODE_TO_JSONRPC2;
45
+ exports.JSONRPC2_TO_HTTP_CODE = getHTTPStatusCode.JSONRPC2_TO_HTTP_CODE;
44
46
  exports.getHTTPStatusCode = getHTTPStatusCode.getHTTPStatusCode;
45
47
  exports.getHTTPStatusCodeFromError = getHTTPStatusCode.getHTTPStatusCodeFromError;
48
+ exports.getStatusCodeFromKey = getHTTPStatusCode.getStatusCodeFromKey;
49
+ exports.getStatusKeyFromCode = getHTTPStatusCode.getStatusKeyFromCode;
46
50
  exports.parseConnectionParamsFromString = parseConnectionParams.parseConnectionParamsFromString;
47
51
  exports.parseConnectionParamsFromUnknown = parseConnectionParams.parseConnectionParamsFromUnknown;
48
52
  exports.resolveResponse = resolveResponse.resolveResponse;
@@ -6,7 +6,7 @@ export { getBatchStreamFormatter } from './unstable-core-do-not-import/http/batc
6
6
  export { getRequestInfo } from './unstable-core-do-not-import/http/contentType.mjs';
7
7
  export { octetInputParser } from './unstable-core-do-not-import/http/contentTypeParsers.mjs';
8
8
  export { formDataToObject } from './unstable-core-do-not-import/http/formDataToObject.mjs';
9
- export { getHTTPStatusCode, getHTTPStatusCodeFromError } from './unstable-core-do-not-import/http/getHTTPStatusCode.mjs';
9
+ export { HTTP_CODE_TO_JSONRPC2, JSONRPC2_TO_HTTP_CODE, getHTTPStatusCode, getHTTPStatusCodeFromError, getStatusCodeFromKey, getStatusKeyFromCode } from './unstable-core-do-not-import/http/getHTTPStatusCode.mjs';
10
10
  export { parseConnectionParamsFromString, parseConnectionParamsFromUnknown } from './unstable-core-do-not-import/http/parseConnectionParams.mjs';
11
11
  export { resolveResponse } from './unstable-core-do-not-import/http/resolveResponse.mjs';
12
12
  export { toURL } from './unstable-core-do-not-import/http/toURL.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.590+3621497e1",
3
+ "version": "11.0.0-rc.592+4744c0612",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -149,5 +149,5 @@
149
149
  "funding": [
150
150
  "https://trpc.io/sponsor"
151
151
  ],
152
- "gitHead": "3621497e1a831537d3c864074656a09527cefba5"
152
+ "gitHead": "4744c0612c2e6dcf6d9fd3a30fd57621962ac439"
153
153
  }
@@ -1,9 +1,10 @@
1
1
  import type { TRPCError } from '../error/TRPCError';
2
2
  import type { TRPC_ERROR_CODES_BY_KEY, TRPCResponse } from '../rpc';
3
3
  import { TRPC_ERROR_CODES_BY_NUMBER } from '../rpc';
4
+ import type { InvertKeyValue, ValueOf } from '../types';
4
5
  import { isObject } from '../utils';
5
6
 
6
- const JSONRPC2_TO_HTTP_CODE: Record<
7
+ export const JSONRPC2_TO_HTTP_CODE: Record<
7
8
  keyof typeof TRPC_ERROR_CODES_BY_KEY,
8
9
  number
9
10
  > = {
@@ -28,11 +29,42 @@ const JSONRPC2_TO_HTTP_CODE: Record<
28
29
  GATEWAY_TIMEOUT: 504,
29
30
  };
30
31
 
31
- function getStatusCodeFromKey(code: keyof typeof TRPC_ERROR_CODES_BY_KEY) {
32
+ export const HTTP_CODE_TO_JSONRPC2: InvertKeyValue<
33
+ typeof JSONRPC2_TO_HTTP_CODE
34
+ > = {
35
+ 400: 'BAD_REQUEST',
36
+ 401: 'UNAUTHORIZED',
37
+ 403: 'FORBIDDEN',
38
+ 404: 'NOT_FOUND',
39
+ 405: 'METHOD_NOT_SUPPORTED',
40
+ 408: 'TIMEOUT',
41
+ 409: 'CONFLICT',
42
+ 412: 'PRECONDITION_FAILED',
43
+ 413: 'PAYLOAD_TOO_LARGE',
44
+ 415: 'UNSUPPORTED_MEDIA_TYPE',
45
+ 422: 'UNPROCESSABLE_CONTENT',
46
+ 429: 'TOO_MANY_REQUESTS',
47
+ 499: 'CLIENT_CLOSED_REQUEST',
48
+ 500: 'INTERNAL_SERVER_ERROR',
49
+ 501: 'NOT_IMPLEMENTED',
50
+ 502: 'BAD_GATEWAY',
51
+ 503: 'SERVICE_UNAVAILABLE',
52
+ 504: 'GATEWAY_TIMEOUT',
53
+ } as const;
54
+
55
+ export function getStatusCodeFromKey(
56
+ code: keyof typeof TRPC_ERROR_CODES_BY_KEY,
57
+ ) {
32
58
  return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
33
59
  }
34
60
 
35
- export function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]): number {
61
+ export function getStatusKeyFromCode(
62
+ code: keyof typeof HTTP_CODE_TO_JSONRPC2,
63
+ ): ValueOf<typeof HTTP_CODE_TO_JSONRPC2> {
64
+ return HTTP_CODE_TO_JSONRPC2[code] ?? 'INTERNAL_SERVER_ERROR';
65
+ }
66
+
67
+ export function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]) {
36
68
  const arr = Array.isArray(json) ? json : [json];
37
69
  const httpStatuses = new Set<number>(
38
70
  arr.map((res) => {
@@ -1,4 +1,4 @@
1
- import type { ValueOf } from '../types';
1
+ import type { InvertKeyValue, ValueOf } from '../types';
2
2
 
3
3
  // reference: https://www.jsonrpc.org/specification
4
4
 
@@ -41,16 +41,8 @@ export const TRPC_ERROR_CODES_BY_KEY = {
41
41
  CLIENT_CLOSED_REQUEST: -32099, // 499
42
42
  } as const;
43
43
 
44
- type KeyFromValue<TValue, TType extends Record<PropertyKey, PropertyKey>> = {
45
- [K in keyof TType]: TValue extends TType[K] ? K : never;
46
- }[keyof TType];
47
-
48
- type Invert<TType extends Record<PropertyKey, PropertyKey>> = {
49
- [TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
50
- };
51
-
52
44
  // pure
53
- export const TRPC_ERROR_CODES_BY_NUMBER: Invert<
45
+ export const TRPC_ERROR_CODES_BY_NUMBER: InvertKeyValue<
54
46
  typeof TRPC_ERROR_CODES_BY_KEY
55
47
  > = {
56
48
  [-32700]: 'PARSE_ERROR',
@@ -131,6 +131,17 @@ export type PickFirstDefined<TType, TPick> = undefined extends TType
131
131
  : TPick
132
132
  : TType;
133
133
 
134
+ export type KeyFromValue<
135
+ TValue,
136
+ TType extends Record<PropertyKey, PropertyKey>,
137
+ > = {
138
+ [K in keyof TType]: TValue extends TType[K] ? K : never;
139
+ }[keyof TType];
140
+
141
+ export type InvertKeyValue<TType extends Record<PropertyKey, PropertyKey>> = {
142
+ [TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
143
+ };
144
+
134
145
  /**
135
146
  * ================================
136
147
  * tRPC specific types
@@ -102,9 +102,9 @@ export function abortSignalsAnyPonyfill(signals: AbortSignal[]): AbortSignal {
102
102
  for (const signal of signals) {
103
103
  if (signal.aborted) {
104
104
  trigger();
105
- } else if (!ac.signal.aborted) {
106
- signal.addEventListener('abort', trigger, { once: true });
105
+ break;
107
106
  }
107
+ signal.addEventListener('abort', trigger, { once: true });
108
108
  }
109
109
 
110
110
  return ac.signal;