@trpc/server 11.0.0-rc.455 → 11.0.0-rc.458

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.
@@ -15,7 +15,7 @@ var router = require('../unstable-core-do-not-import/router.js');
15
15
  * Importing ws causes a build error
16
16
  * @link https://github.com/trpc/trpc/pull/5279
17
17
  */ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
18
- const unsetContextSymbol = Symbol('unsetContext');
18
+ const unsetContextPromiseSymbol = Symbol('unsetContextPromise');
19
19
  function getWSConnectionHandler(opts) {
20
20
  const { createContext , router: router$1 } = opts;
21
21
  const { transformer: transformer$1 } = router$1._def._config;
@@ -68,13 +68,13 @@ function getWSConnectionHandler(opts) {
68
68
  throw error;
69
69
  });
70
70
  }
71
+ let ctx = undefined;
71
72
  /**
72
73
  * promise for initializing the context
73
74
  *
74
75
  * - the context promise will be created immediately on connection if no connectionParams are expected
75
76
  * - if connection params are expected, they will be created once received
76
- */ let ctxPromise = toURL.toURL(req.url ?? '').searchParams.get('connectionParams') === '1' ? unsetContextSymbol : createCtxPromise(()=>null);
77
- let ctx = undefined;
77
+ */ let ctxPromise = toURL.toURL(req.url ?? '').searchParams.get('connectionParams') === '1' ? unsetContextPromiseSymbol : createCtxPromise(()=>null);
78
78
  async function handleRequest(msg) {
79
79
  const { id , jsonrpc } = msg;
80
80
  /* istanbul ignore next -- @preserve */ if (id === null) {
@@ -247,7 +247,7 @@ function getWSConnectionHandler(opts) {
247
247
  }
248
248
  }
249
249
  client.on('message', async (message)=>{
250
- if (ctxPromise === unsetContextSymbol) {
250
+ if (ctxPromise === unsetContextPromiseSymbol) {
251
251
  // If the ctxPromise wasn't created immediately, we're expecting the first message to be a TRPCConnectionParamsMessage
252
252
  ctxPromise = createCtxPromise(()=>{
253
253
  let msg;
@@ -314,7 +314,7 @@ function getWSConnectionHandler(opts) {
314
314
  clientSubscriptions.clear();
315
315
  abortController.abort();
316
316
  });
317
- if (ctxPromise !== unsetContextSymbol) {
317
+ if (ctxPromise !== unsetContextPromiseSymbol) {
318
318
  // prevent unhandled promise rejection errors
319
319
  await ctxPromise.catch(()=>null);
320
320
  }
@@ -13,7 +13,7 @@ import { callProcedure } from '../unstable-core-do-not-import/router.mjs';
13
13
  * Importing ws causes a build error
14
14
  * @link https://github.com/trpc/trpc/pull/5279
15
15
  */ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
16
- const unsetContextSymbol = Symbol('unsetContext');
16
+ const unsetContextPromiseSymbol = Symbol('unsetContextPromise');
17
17
  function getWSConnectionHandler(opts) {
18
18
  const { createContext , router } = opts;
19
19
  const { transformer } = router._def._config;
@@ -66,13 +66,13 @@ function getWSConnectionHandler(opts) {
66
66
  throw error;
67
67
  });
68
68
  }
69
+ let ctx = undefined;
69
70
  /**
70
71
  * promise for initializing the context
71
72
  *
72
73
  * - the context promise will be created immediately on connection if no connectionParams are expected
73
74
  * - if connection params are expected, they will be created once received
74
- */ let ctxPromise = toURL(req.url ?? '').searchParams.get('connectionParams') === '1' ? unsetContextSymbol : createCtxPromise(()=>null);
75
- let ctx = undefined;
75
+ */ let ctxPromise = toURL(req.url ?? '').searchParams.get('connectionParams') === '1' ? unsetContextPromiseSymbol : createCtxPromise(()=>null);
76
76
  async function handleRequest(msg) {
77
77
  const { id , jsonrpc } = msg;
78
78
  /* istanbul ignore next -- @preserve */ if (id === null) {
@@ -245,7 +245,7 @@ function getWSConnectionHandler(opts) {
245
245
  }
246
246
  }
247
247
  client.on('message', async (message)=>{
248
- if (ctxPromise === unsetContextSymbol) {
248
+ if (ctxPromise === unsetContextPromiseSymbol) {
249
249
  // If the ctxPromise wasn't created immediately, we're expecting the first message to be a TRPCConnectionParamsMessage
250
250
  ctxPromise = createCtxPromise(()=>{
251
251
  let msg;
@@ -312,7 +312,7 @@ function getWSConnectionHandler(opts) {
312
312
  clientSubscriptions.clear();
313
313
  abortController.abort();
314
314
  });
315
- if (ctxPromise !== unsetContextSymbol) {
315
+ if (ctxPromise !== unsetContextPromiseSymbol) {
316
316
  // prevent unhandled promise rejection errors
317
317
  await ctxPromise.catch(()=>null);
318
318
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 131453,
3
- "bundleOrigSize": 180819,
4
- "bundleReduction": 27.3,
2
+ "bundleSize": 131653,
3
+ "bundleOrigSize": 181042,
4
+ "bundleReduction": 27.28,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/unstable-core-do-not-import/stream/jsonl.ts",
@@ -17,7 +17,7 @@
17
17
  "/src/unstable-core-do-not-import.ts",
18
18
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
19
19
  ],
20
- "percent": 13.19,
20
+ "percent": 13.17,
21
21
  "reduction": 4.22
22
22
  },
23
23
  {
@@ -31,13 +31,13 @@
31
31
  "dependents": [
32
32
  "/src/unstable-core-do-not-import.ts"
33
33
  ],
34
- "percent": 13.05,
34
+ "percent": 13.03,
35
35
  "reduction": 0
36
36
  },
37
37
  {
38
38
  "id": "/src/adapters/ws.ts",
39
- "size": 14422,
40
- "origSize": 13640,
39
+ "size": 14457,
40
+ "origSize": 13675,
41
41
  "renderedExports": [
42
42
  "getWSConnectionHandler",
43
43
  "applyWSSHandler"
@@ -46,7 +46,7 @@
46
46
  "dependents": [
47
47
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
48
48
  ],
49
- "percent": 10.97,
49
+ "percent": 10.98,
50
50
  "reduction": 0
51
51
  },
52
52
  {
@@ -61,7 +61,7 @@
61
61
  "/src/unstable-core-do-not-import.ts",
62
62
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
63
63
  ],
64
- "percent": 5.85,
64
+ "percent": 5.84,
65
65
  "reduction": 0
66
66
  },
67
67
  {
@@ -113,7 +113,7 @@
113
113
  "/src/unstable-core-do-not-import.ts",
114
114
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
115
115
  ],
116
- "percent": 4.29,
116
+ "percent": 4.28,
117
117
  "reduction": 24.48
118
118
  },
119
119
  {
@@ -177,7 +177,7 @@
177
177
  "dependents": [
178
178
  "/src/observable/index.ts"
179
179
  ],
180
- "percent": 2.1,
180
+ "percent": 2.09,
181
181
  "reduction": 0
182
182
  },
183
183
  {
@@ -197,7 +197,7 @@
197
197
  "/src/unstable-core-do-not-import/initTRPC.ts",
198
198
  "/src/unstable-core-do-not-import/router.ts"
199
199
  ],
200
- "percent": 2.09,
200
+ "percent": 2.08,
201
201
  "reduction": 45.94
202
202
  },
203
203
  {
@@ -225,7 +225,7 @@
225
225
  "dependents": [
226
226
  "/src/unstable-core-do-not-import.ts"
227
227
  ],
228
- "percent": 2.06,
228
+ "percent": 2.05,
229
229
  "reduction": 40.91
230
230
  },
231
231
  {
@@ -275,7 +275,7 @@
275
275
  "dependents": [
276
276
  "/src/adapters/fetch/index.ts"
277
277
  ],
278
- "percent": 1.72,
278
+ "percent": 1.71,
279
279
  "reduction": 2.17
280
280
  },
281
281
  {
@@ -331,6 +331,19 @@
331
331
  "percent": 1.32,
332
332
  "reduction": 19.47
333
333
  },
334
+ {
335
+ "id": "/src/unstable-core-do-not-import/rpc/codes.ts",
336
+ "size": 1611,
337
+ "origSize": 2221,
338
+ "renderedExports": [
339
+ "TRPC_ERROR_CODES_BY_KEY",
340
+ "TRPC_ERROR_CODES_BY_NUMBER"
341
+ ],
342
+ "removedExports": [],
343
+ "dependents": [],
344
+ "percent": 1.22,
345
+ "reduction": 27.47
346
+ },
334
347
  {
335
348
  "id": "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
336
349
  "size": 1580,
@@ -355,19 +368,6 @@
355
368
  "percent": 1.17,
356
369
  "reduction": 26.94
357
370
  },
358
- {
359
- "id": "/src/unstable-core-do-not-import/rpc/codes.ts",
360
- "size": 1524,
361
- "origSize": 2105,
362
- "renderedExports": [
363
- "TRPC_ERROR_CODES_BY_KEY",
364
- "TRPC_ERROR_CODES_BY_NUMBER"
365
- ],
366
- "removedExports": [],
367
- "dependents": [],
368
- "percent": 1.16,
369
- "reduction": 27.6
370
- },
371
371
  {
372
372
  "id": "/src/adapters/fastify/fastifyTRPCPlugin.ts",
373
373
  "size": 1500,
@@ -384,8 +384,8 @@
384
384
  },
385
385
  {
386
386
  "id": "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
387
- "size": 1287,
388
- "origSize": 1583,
387
+ "size": 1365,
388
+ "origSize": 1655,
389
389
  "renderedExports": [
390
390
  "getHTTPStatusCode",
391
391
  "getHTTPStatusCodeFromError"
@@ -396,8 +396,8 @@
396
396
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
397
397
  "/src/unstable-core-do-not-import/error/getErrorShape.ts"
398
398
  ],
399
- "percent": 0.98,
400
- "reduction": 18.7
399
+ "percent": 1.04,
400
+ "reduction": 17.52
401
401
  },
402
402
  {
403
403
  "id": "/src/unstable-core-do-not-import/utils.ts",
@@ -564,7 +564,7 @@
564
564
  "/src/unstable-core-do-not-import.ts",
565
565
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
566
566
  ],
567
- "percent": 0.48,
567
+ "percent": 0.47,
568
568
  "reduction": 43.49
569
569
  },
570
570
  {
@@ -592,7 +592,7 @@
592
592
  ],
593
593
  "removedExports": [],
594
594
  "dependents": [],
595
- "percent": 0.4,
595
+ "percent": 0.39,
596
596
  "reduction": 67.09
597
597
  },
598
598
  {
@@ -732,9 +732,9 @@
732
732
  "reduction": 100
733
733
  },
734
734
  {
735
- "id": "/src/rpc.ts",
735
+ "id": "/src/shared.ts",
736
736
  "size": 0,
737
- "origSize": 36,
737
+ "origSize": 653,
738
738
  "renderedExports": [],
739
739
  "removedExports": [],
740
740
  "dependents": [],
@@ -742,9 +742,9 @@
742
742
  "reduction": 100
743
743
  },
744
744
  {
745
- "id": "/src/shared.ts",
745
+ "id": "/src/rpc.ts",
746
746
  "size": 0,
747
- "origSize": 653,
747
+ "origSize": 36,
748
748
  "renderedExports": [],
749
749
  "removedExports": [],
750
750
  "dependents": [],
@@ -796,16 +796,6 @@
796
796
  "percent": 0,
797
797
  "reduction": 100
798
798
  },
799
- {
800
- "id": "/src/adapters/fetch/index.ts",
801
- "size": 0,
802
- "origSize": 64,
803
- "renderedExports": [],
804
- "removedExports": [],
805
- "dependents": [],
806
- "percent": 0,
807
- "reduction": 100
808
- },
809
799
  {
810
800
  "id": "/src/adapters/node-http/index.ts",
811
801
  "size": 0,
@@ -820,6 +810,16 @@
820
810
  ],
821
811
  "percent": 0,
822
812
  "reduction": 100
813
+ },
814
+ {
815
+ "id": "/src/adapters/fetch/index.ts",
816
+ "size": 0,
817
+ "origSize": 64,
818
+ "renderedExports": [],
819
+ "removedExports": [],
820
+ "dependents": [],
821
+ "percent": 0,
822
+ "reduction": 100
823
823
  }
824
824
  ],
825
825
  "moduleCount": 55
@@ -3,7 +3,7 @@ export declare function getCauseFromUnknown(cause: unknown): Error | undefined;
3
3
  export declare function getTRPCErrorFromUnknown(cause: unknown): TRPCError;
4
4
  export declare class TRPCError extends Error {
5
5
  readonly cause?: Error;
6
- readonly code: "INTERNAL_SERVER_ERROR" | "PARSE_ERROR" | "BAD_REQUEST" | "NOT_IMPLEMENTED" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_SUPPORTED" | "TIMEOUT" | "CONFLICT" | "PRECONDITION_FAILED" | "UNSUPPORTED_MEDIA_TYPE" | "PAYLOAD_TOO_LARGE" | "UNPROCESSABLE_CONTENT" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST";
6
+ readonly code: "INTERNAL_SERVER_ERROR" | "PARSE_ERROR" | "BAD_REQUEST" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_SUPPORTED" | "TIMEOUT" | "CONFLICT" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "UNSUPPORTED_MEDIA_TYPE" | "UNPROCESSABLE_CONTENT" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST";
7
7
  constructor(opts: {
8
8
  message?: string;
9
9
  code: TRPC_ERROR_CODE_KEY;
@@ -1 +1 @@
1
- {"version":3,"file":"TRPCError.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/TRPCError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAMxD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CAyBrE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAoBjE;AAED,qBAAa,SAAU,SAAQ,KAAK;IAGlC,SAAyB,KAAK,CAAC,EAAE,KAAK,CAAC;IACvC,SAAgB,IAAI,gUAAC;gBAET,IAAI,EAAE;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,mBAAmB,CAAC;QAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAgBF"}
1
+ {"version":3,"file":"TRPCError.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/TRPCError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAMxD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CAyBrE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAoBjE;AAED,qBAAa,SAAU,SAAQ,KAAK;IAGlC,SAAyB,KAAK,CAAC,EAAE,KAAK,CAAC;IACvC,SAAgB,IAAI,4XAAC;gBAET,IAAI,EAAE;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,mBAAmB,CAAC;QAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAgBF"}
@@ -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;AA8BpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,MAAM,CAsB7E;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,EAA2B,YAAY,EAAE,MAAM,QAAQ,CAAC;AAiCpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,MAAM,CAsB7E;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,UAE1D"}
@@ -7,8 +7,8 @@ const JSONRPC2_TO_HTTP_CODE = {
7
7
  PARSE_ERROR: 400,
8
8
  BAD_REQUEST: 400,
9
9
  UNAUTHORIZED: 401,
10
- NOT_FOUND: 404,
11
10
  FORBIDDEN: 403,
11
+ NOT_FOUND: 404,
12
12
  METHOD_NOT_SUPPORTED: 405,
13
13
  TIMEOUT: 408,
14
14
  CONFLICT: 409,
@@ -19,7 +19,10 @@ const JSONRPC2_TO_HTTP_CODE = {
19
19
  TOO_MANY_REQUESTS: 429,
20
20
  CLIENT_CLOSED_REQUEST: 499,
21
21
  INTERNAL_SERVER_ERROR: 500,
22
- NOT_IMPLEMENTED: 501
22
+ NOT_IMPLEMENTED: 501,
23
+ BAD_GATEWAY: 502,
24
+ SERVICE_UNAVAILABLE: 503,
25
+ GATEWAY_TIMEOUT: 504
23
26
  };
24
27
  function getStatusCodeFromKey(code) {
25
28
  return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
@@ -5,8 +5,8 @@ const JSONRPC2_TO_HTTP_CODE = {
5
5
  PARSE_ERROR: 400,
6
6
  BAD_REQUEST: 400,
7
7
  UNAUTHORIZED: 401,
8
- NOT_FOUND: 404,
9
8
  FORBIDDEN: 403,
9
+ NOT_FOUND: 404,
10
10
  METHOD_NOT_SUPPORTED: 405,
11
11
  TIMEOUT: 408,
12
12
  CONFLICT: 409,
@@ -17,7 +17,10 @@ const JSONRPC2_TO_HTTP_CODE = {
17
17
  TOO_MANY_REQUESTS: 429,
18
18
  CLIENT_CLOSED_REQUEST: 499,
19
19
  INTERNAL_SERVER_ERROR: 500,
20
- NOT_IMPLEMENTED: 501
20
+ NOT_IMPLEMENTED: 501,
21
+ BAD_GATEWAY: 502,
22
+ SERVICE_UNAVAILABLE: 503,
23
+ GATEWAY_TIMEOUT: 504
21
24
  };
22
25
  function getStatusCodeFromKey(code) {
23
26
  return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
@@ -17,6 +17,9 @@ export declare const TRPC_ERROR_CODES_BY_KEY: {
17
17
  readonly BAD_REQUEST: -32600;
18
18
  readonly INTERNAL_SERVER_ERROR: -32603;
19
19
  readonly NOT_IMPLEMENTED: -32603;
20
+ readonly BAD_GATEWAY: -32603;
21
+ readonly SERVICE_UNAVAILABLE: -32603;
22
+ readonly GATEWAY_TIMEOUT: -32603;
20
23
  readonly UNAUTHORIZED: -32001;
21
24
  readonly FORBIDDEN: -32003;
22
25
  readonly NOT_FOUND: -32004;
@@ -24,8 +27,8 @@ export declare const TRPC_ERROR_CODES_BY_KEY: {
24
27
  readonly TIMEOUT: -32008;
25
28
  readonly CONFLICT: -32009;
26
29
  readonly PRECONDITION_FAILED: -32012;
27
- readonly UNSUPPORTED_MEDIA_TYPE: -32015;
28
30
  readonly PAYLOAD_TOO_LARGE: -32013;
31
+ readonly UNSUPPORTED_MEDIA_TYPE: -32015;
29
32
  readonly UNPROCESSABLE_CONTENT: -32022;
30
33
  readonly TOO_MANY_REQUESTS: -32029;
31
34
  readonly CLIENT_CLOSED_REQUEST: -32099;
@@ -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;;;;;;;;;;;;;;;;CAoBK,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,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"}
@@ -17,6 +17,9 @@
17
17
  // Internal JSON-RPC error
18
18
  INTERNAL_SERVER_ERROR: -32603,
19
19
  NOT_IMPLEMENTED: -32603,
20
+ BAD_GATEWAY: -32603,
21
+ SERVICE_UNAVAILABLE: -32603,
22
+ GATEWAY_TIMEOUT: -32603,
20
23
  // Implementation specific errors
21
24
  UNAUTHORIZED: -32001,
22
25
  FORBIDDEN: -32003,
@@ -25,8 +28,8 @@
25
28
  TIMEOUT: -32008,
26
29
  CONFLICT: -32009,
27
30
  PRECONDITION_FAILED: -32012,
28
- UNSUPPORTED_MEDIA_TYPE: -32015,
29
31
  PAYLOAD_TOO_LARGE: -32013,
32
+ UNSUPPORTED_MEDIA_TYPE: -32015,
30
33
  UNPROCESSABLE_CONTENT: -32022,
31
34
  TOO_MANY_REQUESTS: -32029,
32
35
  CLIENT_CLOSED_REQUEST: -32099
@@ -15,6 +15,9 @@
15
15
  // Internal JSON-RPC error
16
16
  INTERNAL_SERVER_ERROR: -32603,
17
17
  NOT_IMPLEMENTED: -32603,
18
+ BAD_GATEWAY: -32603,
19
+ SERVICE_UNAVAILABLE: -32603,
20
+ GATEWAY_TIMEOUT: -32603,
18
21
  // Implementation specific errors
19
22
  UNAUTHORIZED: -32001,
20
23
  FORBIDDEN: -32003,
@@ -23,8 +26,8 @@
23
26
  TIMEOUT: -32008,
24
27
  CONFLICT: -32009,
25
28
  PRECONDITION_FAILED: -32012,
26
- UNSUPPORTED_MEDIA_TYPE: -32015,
27
29
  PAYLOAD_TOO_LARGE: -32013,
30
+ UNSUPPORTED_MEDIA_TYPE: -32015,
28
31
  UNPROCESSABLE_CONTENT: -32022,
29
32
  TOO_MANY_REQUESTS: -32029,
30
33
  CLIENT_CLOSED_REQUEST: -32099
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.455+244538dd3",
3
+ "version": "11.0.0-rc.458+46c7eea82",
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": "244538dd3d42c0df05c7a491def21562e3cce253"
152
+ "gitHead": "46c7eea8285542a1115c9dada7b45e9b07f7c23d"
153
153
  }
@@ -88,7 +88,7 @@ export type WSSHandlerOptions<TRouter extends AnyRouter> =
88
88
  };
89
89
  };
90
90
 
91
- const unsetContextSymbol = Symbol('unsetContext');
91
+ const unsetContextPromiseSymbol = Symbol('unsetContextPromise');
92
92
  export function getWSConnectionHandler<TRouter extends AnyRouter>(
93
93
  opts: WSConnectionHandlerOptions<TRouter>,
94
94
  ) {
@@ -156,6 +156,8 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
156
156
  });
157
157
  }
158
158
 
159
+ let ctx: inferRouterContext<TRouter> | undefined = undefined;
160
+
159
161
  /**
160
162
  * promise for initializing the context
161
163
  *
@@ -164,11 +166,9 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
164
166
  */
165
167
  let ctxPromise =
166
168
  toURL(req.url ?? '').searchParams.get('connectionParams') === '1'
167
- ? unsetContextSymbol
169
+ ? unsetContextPromiseSymbol
168
170
  : createCtxPromise(() => null);
169
171
 
170
- let ctx: inferRouterContext<TRouter> | undefined = undefined;
171
-
172
172
  async function handleRequest(msg: TRPCClientOutgoingMessage) {
173
173
  const { id, jsonrpc } = msg;
174
174
  /* istanbul ignore next -- @preserve */
@@ -341,7 +341,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
341
341
  }
342
342
  }
343
343
  client.on('message', async (message) => {
344
- if (ctxPromise === unsetContextSymbol) {
344
+ if (ctxPromise === unsetContextPromiseSymbol) {
345
345
  // If the ctxPromise wasn't created immediately, we're expecting the first message to be a TRPCConnectionParamsMessage
346
346
  ctxPromise = createCtxPromise(() => {
347
347
  let msg;
@@ -415,7 +415,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
415
415
  abortController.abort();
416
416
  });
417
417
 
418
- if (ctxPromise !== unsetContextSymbol) {
418
+ if (ctxPromise !== unsetContextPromiseSymbol) {
419
419
  // prevent unhandled promise rejection errors
420
420
  await ctxPromise.catch(() => null);
421
421
  }
@@ -10,8 +10,8 @@ const JSONRPC2_TO_HTTP_CODE: Record<
10
10
  PARSE_ERROR: 400,
11
11
  BAD_REQUEST: 400,
12
12
  UNAUTHORIZED: 401,
13
- NOT_FOUND: 404,
14
13
  FORBIDDEN: 403,
14
+ NOT_FOUND: 404,
15
15
  METHOD_NOT_SUPPORTED: 405,
16
16
  TIMEOUT: 408,
17
17
  CONFLICT: 409,
@@ -23,6 +23,9 @@ const JSONRPC2_TO_HTTP_CODE: Record<
23
23
  CLIENT_CLOSED_REQUEST: 499,
24
24
  INTERNAL_SERVER_ERROR: 500,
25
25
  NOT_IMPLEMENTED: 501,
26
+ BAD_GATEWAY: 502,
27
+ SERVICE_UNAVAILABLE: 503,
28
+ GATEWAY_TIMEOUT: 504,
26
29
  };
27
30
 
28
31
  function getStatusCodeFromKey(code: keyof typeof TRPC_ERROR_CODES_BY_KEY) {
@@ -20,8 +20,11 @@ export const TRPC_ERROR_CODES_BY_KEY = {
20
20
  BAD_REQUEST: -32600, // 400
21
21
 
22
22
  // Internal JSON-RPC error
23
- INTERNAL_SERVER_ERROR: -32603,
24
- NOT_IMPLEMENTED: -32603,
23
+ INTERNAL_SERVER_ERROR: -32603, // 500
24
+ NOT_IMPLEMENTED: -32603, // 501
25
+ BAD_GATEWAY: -32603, // 502
26
+ SERVICE_UNAVAILABLE: -32603, // 503
27
+ GATEWAY_TIMEOUT: -32603, // 504
25
28
 
26
29
  // Implementation specific errors
27
30
  UNAUTHORIZED: -32001, // 401
@@ -31,8 +34,8 @@ export const TRPC_ERROR_CODES_BY_KEY = {
31
34
  TIMEOUT: -32008, // 408
32
35
  CONFLICT: -32009, // 409
33
36
  PRECONDITION_FAILED: -32012, // 412
34
- UNSUPPORTED_MEDIA_TYPE: -32015, // 415
35
37
  PAYLOAD_TOO_LARGE: -32013, // 413
38
+ UNSUPPORTED_MEDIA_TYPE: -32015, // 415
36
39
  UNPROCESSABLE_CONTENT: -32022, // 422
37
40
  TOO_MANY_REQUESTS: -32029, // 429
38
41
  CLIENT_CLOSED_REQUEST: -32099, // 499