@trpc/server 11.0.0-alpha-tmp-issues-5851-take-two.499 → 11.0.0-alpha-tmp-subscription-connection-state.486
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.
- package/dist/adapters/ws.js +6 -6
- package/dist/adapters/ws.mjs +6 -6
- package/dist/bundle-analysis.json +61 -61
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +5 -2
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +5 -2
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +4 -1
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rpc/codes.js +4 -1
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +4 -1
- package/package.json +2 -2
- package/src/adapters/ws.ts +7 -7
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +4 -1
- package/src/unstable-core-do-not-import/rpc/codes.ts +6 -3
package/dist/adapters/ws.js
CHANGED
|
@@ -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
|
|
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
|
-
(
|
|
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' ?
|
|
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 ===
|
|
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 !==
|
|
317
|
+
if (ctxPromise !== unsetContextPromiseSymbol) {
|
|
318
318
|
// prevent unhandled promise rejection errors
|
|
319
319
|
await ctxPromise.catch(()=>null);
|
|
320
320
|
}
|
package/dist/adapters/ws.mjs
CHANGED
|
@@ -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
|
|
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
|
-
(
|
|
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' ?
|
|
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 ===
|
|
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 !==
|
|
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":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 27.
|
|
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,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.
|
|
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.
|
|
34
|
+
"percent": 13.03,
|
|
35
35
|
"reduction": 0
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
"id": "/src/adapters/ws.ts",
|
|
39
|
-
"size":
|
|
40
|
-
"origSize":
|
|
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.
|
|
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.
|
|
64
|
+
"percent": 5.84,
|
|
65
65
|
"reduction": 0
|
|
66
66
|
},
|
|
67
67
|
{
|
|
@@ -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.
|
|
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.
|
|
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.
|
|
180
|
+
"percent": 2.09,
|
|
181
181
|
"reduction": 0
|
|
182
182
|
},
|
|
183
183
|
{
|
|
@@ -193,11 +193,11 @@
|
|
|
193
193
|
"removedExports": [],
|
|
194
194
|
"dependents": [
|
|
195
195
|
"/src/unstable-core-do-not-import.ts",
|
|
196
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
196
197
|
"/src/unstable-core-do-not-import/initTRPC.ts",
|
|
197
|
-
"/src/unstable-core-do-not-import/router.ts"
|
|
198
|
-
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
198
|
+
"/src/unstable-core-do-not-import/router.ts"
|
|
199
199
|
],
|
|
200
|
-
"percent": 2.
|
|
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.
|
|
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.
|
|
278
|
+
"percent": 1.71,
|
|
279
279
|
"reduction": 2.17
|
|
280
280
|
},
|
|
281
281
|
{
|
|
@@ -319,11 +319,11 @@
|
|
|
319
319
|
"removedExports": [],
|
|
320
320
|
"dependents": [
|
|
321
321
|
"/src/unstable-core-do-not-import.ts",
|
|
322
|
+
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
323
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
322
324
|
"/src/unstable-core-do-not-import/stream/sse.ts",
|
|
323
325
|
"/src/unstable-core-do-not-import/middleware.ts",
|
|
324
326
|
"/src/unstable-core-do-not-import/router.ts",
|
|
325
|
-
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
326
|
-
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
327
327
|
"/src/unstable-core-do-not-import/http/contentType.ts",
|
|
328
328
|
"/src/unstable-core-do-not-import/procedureBuilder.ts",
|
|
329
329
|
"/src/unstable-core-do-not-import/stream/jsonl.ts"
|
|
@@ -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":
|
|
388
|
-
"origSize":
|
|
387
|
+
"size": 1365,
|
|
388
|
+
"origSize": 1655,
|
|
389
389
|
"renderedExports": [
|
|
390
390
|
"getHTTPStatusCode",
|
|
391
391
|
"getHTTPStatusCodeFromError"
|
|
@@ -393,11 +393,11 @@
|
|
|
393
393
|
"removedExports": [],
|
|
394
394
|
"dependents": [
|
|
395
395
|
"/src/unstable-core-do-not-import.ts",
|
|
396
|
-
"/src/unstable-core-do-not-import/
|
|
397
|
-
"/src/unstable-core-do-not-import/
|
|
396
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
397
|
+
"/src/unstable-core-do-not-import/error/getErrorShape.ts"
|
|
398
398
|
],
|
|
399
|
-
"percent":
|
|
400
|
-
"reduction":
|
|
399
|
+
"percent": 1.04,
|
|
400
|
+
"reduction": 17.52
|
|
401
401
|
},
|
|
402
402
|
{
|
|
403
403
|
"id": "/src/unstable-core-do-not-import/utils.ts",
|
|
@@ -415,17 +415,17 @@
|
|
|
415
415
|
"removedExports": [],
|
|
416
416
|
"dependents": [
|
|
417
417
|
"/src/unstable-core-do-not-import.ts",
|
|
418
|
+
"/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
|
|
419
|
+
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
420
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
418
421
|
"/src/unstable-core-do-not-import/error/TRPCError.ts",
|
|
419
422
|
"/src/unstable-core-do-not-import/stream/sse.ts",
|
|
420
423
|
"/src/unstable-core-do-not-import/transformer.ts",
|
|
421
424
|
"/src/unstable-core-do-not-import/middleware.ts",
|
|
422
425
|
"/src/unstable-core-do-not-import/router.ts",
|
|
423
|
-
"/src/unstable-core-do-not-import/
|
|
424
|
-
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
425
|
-
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
426
|
+
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
426
427
|
"/src/unstable-core-do-not-import/http/contentType.ts",
|
|
427
428
|
"/src/unstable-core-do-not-import/procedureBuilder.ts",
|
|
428
|
-
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
429
429
|
"/src/unstable-core-do-not-import/stream/jsonl.ts"
|
|
430
430
|
],
|
|
431
431
|
"percent": 0.91,
|
|
@@ -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.
|
|
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.
|
|
595
|
+
"percent": 0.39,
|
|
596
596
|
"reduction": 67.09
|
|
597
597
|
},
|
|
598
598
|
{
|
|
@@ -710,37 +710,34 @@
|
|
|
710
710
|
"reduction": 93.8
|
|
711
711
|
},
|
|
712
712
|
{
|
|
713
|
-
"id": "/src/
|
|
713
|
+
"id": "/src/http.ts",
|
|
714
714
|
"size": 0,
|
|
715
|
-
"origSize":
|
|
715
|
+
"origSize": 37,
|
|
716
716
|
"renderedExports": [],
|
|
717
717
|
"removedExports": [],
|
|
718
|
-
"dependents": [
|
|
718
|
+
"dependents": [
|
|
719
|
+
"/src/adapters/ws.ts"
|
|
720
|
+
],
|
|
719
721
|
"percent": 0,
|
|
720
722
|
"reduction": 100
|
|
721
723
|
},
|
|
722
724
|
{
|
|
723
|
-
"id": "/src/
|
|
725
|
+
"id": "/src/index.ts",
|
|
724
726
|
"size": 0,
|
|
725
|
-
"origSize":
|
|
727
|
+
"origSize": 32,
|
|
726
728
|
"renderedExports": [],
|
|
727
729
|
"removedExports": [],
|
|
728
|
-
"dependents": [
|
|
729
|
-
"/src/adapters/ws.ts"
|
|
730
|
-
],
|
|
730
|
+
"dependents": [],
|
|
731
731
|
"percent": 0,
|
|
732
732
|
"reduction": 100
|
|
733
733
|
},
|
|
734
734
|
{
|
|
735
|
-
"id": "/src/
|
|
735
|
+
"id": "/src/rpc.ts",
|
|
736
736
|
"size": 0,
|
|
737
|
-
"origSize":
|
|
737
|
+
"origSize": 36,
|
|
738
738
|
"renderedExports": [],
|
|
739
739
|
"removedExports": [],
|
|
740
|
-
"dependents": [
|
|
741
|
-
"/src/adapters/ws.ts",
|
|
742
|
-
"/src/adapters/next-app-dir/nextAppDirCaller.ts"
|
|
743
|
-
],
|
|
740
|
+
"dependents": [],
|
|
744
741
|
"percent": 0,
|
|
745
742
|
"reduction": 100
|
|
746
743
|
},
|
|
@@ -755,12 +752,15 @@
|
|
|
755
752
|
"reduction": 100
|
|
756
753
|
},
|
|
757
754
|
{
|
|
758
|
-
"id": "/src/
|
|
755
|
+
"id": "/src/unstable-core-do-not-import.ts",
|
|
759
756
|
"size": 0,
|
|
760
|
-
"origSize":
|
|
757
|
+
"origSize": 2244,
|
|
761
758
|
"renderedExports": [],
|
|
762
759
|
"removedExports": [],
|
|
763
|
-
"dependents": [
|
|
760
|
+
"dependents": [
|
|
761
|
+
"/src/adapters/ws.ts",
|
|
762
|
+
"/src/adapters/next-app-dir/nextAppDirCaller.ts"
|
|
763
|
+
],
|
|
764
764
|
"percent": 0,
|
|
765
765
|
"reduction": 100
|
|
766
766
|
},
|
|
@@ -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" | "
|
|
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,
|
|
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;
|
|
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
|
|
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-
|
|
3
|
+
"version": "11.0.0-alpha-tmp-subscription-connection-state.486+fb825f371",
|
|
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": "
|
|
152
|
+
"gitHead": "fb825f371eeffc9b17a3621fcd4acf9990913d8f"
|
|
153
153
|
}
|
package/src/adapters/ws.ts
CHANGED
|
@@ -88,7 +88,7 @@ export type WSSHandlerOptions<TRouter extends AnyRouter> =
|
|
|
88
88
|
};
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
const
|
|
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
|
-
(
|
|
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
|
-
?
|
|
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 ===
|
|
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 !==
|
|
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
|