@trpc/server 11.0.0-alpha-tmp-issues-5851-take-two.496 → 11.0.0-alpha-tmp-subscription-connection-state.485

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;
@@ -62,19 +62,19 @@ function getWSConnectionHandler(opts) {
62
62
  })
63
63
  });
64
64
  // close in next tick
65
- (global.setImmediate ?? global.setTimeout)(()=>{
65
+ (globalThis.setImmediate ?? globalThis.setTimeout)(()=>{
66
66
  client.close();
67
67
  });
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;
@@ -60,19 +60,19 @@ function getWSConnectionHandler(opts) {
60
60
  })
61
61
  });
62
62
  // close in next tick
63
- (global.setImmediate ?? global.setTimeout)(()=>{
63
+ (globalThis.setImmediate ?? globalThis.setTimeout)(()=>{
64
64
  client.close();
65
65
  });
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": 131370,
3
- "bundleOrigSize": 180752,
4
- "bundleReduction": 27.32,
2
+ "bundleSize": 131661,
3
+ "bundleOrigSize": 181050,
4
+ "bundleReduction": 27.28,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/unstable-core-do-not-import/stream/jsonl.ts",
@@ -17,13 +17,13 @@
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.2,
20
+ "percent": 13.17,
21
21
  "reduction": 4.22
22
22
  },
23
23
  {
24
24
  "id": "/src/unstable-core-do-not-import/http/resolveResponse.ts",
25
- "size": 17074,
26
- "origSize": 16227,
25
+ "size": 17157,
26
+ "origSize": 16294,
27
27
  "renderedExports": [
28
28
  "resolveResponse"
29
29
  ],
@@ -31,13 +31,13 @@
31
31
  "dependents": [
32
32
  "/src/unstable-core-do-not-import.ts"
33
33
  ],
34
- "percent": 13,
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": 14465,
40
+ "origSize": 13683,
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.98,
49
+ "percent": 10.99,
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
  {
@@ -79,7 +79,7 @@
79
79
  "/src/unstable-core-do-not-import.ts",
80
80
  "/src/unstable-core-do-not-import/initTRPC.ts"
81
81
  ],
82
- "percent": 4.86,
82
+ "percent": 4.85,
83
83
  "reduction": 39.77
84
84
  },
85
85
  {
@@ -94,7 +94,7 @@
94
94
  "/src/unstable-core-do-not-import.ts",
95
95
  "/src/unstable-core-do-not-import/initTRPC.ts"
96
96
  ],
97
- "percent": 4.82,
97
+ "percent": 4.8,
98
98
  "reduction": 60.06
99
99
  },
100
100
  {
@@ -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
  {
@@ -161,7 +161,7 @@
161
161
  "dependents": [
162
162
  "/src/adapters/next-app-dir.ts"
163
163
  ],
164
- "percent": 2.39,
164
+ "percent": 2.38,
165
165
  "reduction": 23.5
166
166
  },
167
167
  {
@@ -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",
@@ -418,12 +418,12 @@
418
418
  "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
419
419
  "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
420
420
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
421
- "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
422
421
  "/src/unstable-core-do-not-import/error/TRPCError.ts",
423
422
  "/src/unstable-core-do-not-import/stream/sse.ts",
424
423
  "/src/unstable-core-do-not-import/transformer.ts",
425
424
  "/src/unstable-core-do-not-import/middleware.ts",
426
425
  "/src/unstable-core-do-not-import/router.ts",
426
+ "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
427
427
  "/src/unstable-core-do-not-import/http/contentType.ts",
428
428
  "/src/unstable-core-do-not-import/procedureBuilder.ts",
429
429
  "/src/unstable-core-do-not-import/stream/jsonl.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
  {
@@ -722,9 +722,9 @@
722
722
  "reduction": 100
723
723
  },
724
724
  {
725
- "id": "/src/rpc.ts",
725
+ "id": "/src/index.ts",
726
726
  "size": 0,
727
- "origSize": 36,
727
+ "origSize": 32,
728
728
  "renderedExports": [],
729
729
  "removedExports": [],
730
730
  "dependents": [],
@@ -732,9 +732,9 @@
732
732
  "reduction": 100
733
733
  },
734
734
  {
735
- "id": "/src/index.ts",
735
+ "id": "/src/rpc.ts",
736
736
  "size": 0,
737
- "origSize": 32,
737
+ "origSize": 36,
738
738
  "renderedExports": [],
739
739
  "removedExports": [],
740
740
  "dependents": [],
@@ -814,8 +814,8 @@
814
814
  "removedExports": [],
815
815
  "dependents": [
816
816
  "/src/adapters/express.ts",
817
- "/src/adapters/next.ts",
818
817
  "/src/adapters/standalone.ts",
818
+ "/src/adapters/next.ts",
819
819
  "/src/adapters/fastify/fastifyRequestHandler.ts"
820
820
  ],
821
821
  "percent": 0,
@@ -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;
@@ -1 +1 @@
1
- {"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAQnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AA0BjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAyID,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CAgZnB"}
1
+ {"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAQnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AA0BjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAyID,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CAiZnB"}
@@ -284,6 +284,7 @@ async function resolveResponse(opts) {
284
284
  }
285
285
  const dataAsIterable = observable.isObservable(data) ? observable.observableToAsyncIterable(data) : data;
286
286
  const stream = sse.sseStreamProducer({
287
+ ...router._def._config.experimental?.sseSubscriptions,
287
288
  data: dataAsIterable,
288
289
  serialize: (v)=>config.transformer.output.serialize(v)
289
290
  });
@@ -282,6 +282,7 @@ async function resolveResponse(opts) {
282
282
  }
283
283
  const dataAsIterable = isObservable(data) ? observableToAsyncIterable(data) : data;
284
284
  const stream = sseStreamProducer({
285
+ ...router._def._config.experimental?.sseSubscriptions,
285
286
  data: dataAsIterable,
286
287
  serialize: (v)=>config.transformer.output.serialize(v)
287
288
  });
@@ -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-alpha-tmp-issues-5851-take-two.496+f0729daa3",
3
+ "version": "11.0.0-alpha-tmp-subscription-connection-state.485+386eae02c",
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": "f0729daa3e95b1f21cd082e04c21377b550f5625"
152
+ "gitHead": "386eae02c675ba0fe0feda78188b6975e56d0e49"
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
  ) {
@@ -148,7 +148,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
148
148
  });
149
149
 
150
150
  // close in next tick
151
- (global.setImmediate ?? global.setTimeout)(() => {
151
+ (globalThis.setImmediate ?? globalThis.setTimeout)(() => {
152
152
  client.close();
153
153
  });
154
154
 
@@ -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) {
@@ -380,6 +380,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
380
380
  ? observableToAsyncIterable(data)
381
381
  : data;
382
382
  const stream = sseStreamProducer({
383
+ ...router._def._config.experimental?.sseSubscriptions,
383
384
  data: dataAsIterable,
384
385
  serialize: (v) => config.transformer.output.serialize(v),
385
386
  });
@@ -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