@trpc/server 11.0.0-alpha-tmp-app-router-example.388 → 11.0.0-alpha-tmp-issues-5851-take-two.451
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/@trpc/server/http.d.ts +1 -2
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/index.d.ts +1 -1
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/@trpc/server/rpc.d.ts +1 -1
- package/dist/@trpc/server/rpc.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.js +19 -2
- package/dist/adapters/aws-lambda/getPlanner.mjs +19 -2
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +1 -1
- package/dist/adapters/next-app-dir/redirect.d.ts.map +1 -1
- package/dist/adapters/next.js +1 -1
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +0 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +3 -1
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +3 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +30 -7
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +30 -7
- package/dist/adapters/node-http/types.d.ts +0 -1
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +0 -1
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/ws.d.ts +3 -4
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +172 -114
- package/dist/adapters/ws.mjs +172 -114
- package/dist/bundle-analysis.json +235 -154
- package/dist/http.js +3 -0
- package/dist/http.mjs +1 -0
- package/dist/index.js +7 -5
- package/dist/index.mjs +3 -2
- package/dist/observable/observable.d.ts +1 -0
- package/dist/observable/observable.d.ts.map +1 -1
- package/dist/observable/observable.js +55 -0
- package/dist/observable/observable.mjs +55 -1
- package/dist/unstable-core-do-not-import/createProxy.d.ts +3 -3
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/createProxy.js +15 -6
- package/dist/unstable-core-do-not-import/createProxy.mjs +15 -6
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +7 -4
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +60 -17
- package/dist/unstable-core-do-not-import/http/contentType.mjs +61 -18
- package/dist/unstable-core-do-not-import/http/formDataToObject.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/formDataToObject.js +40 -0
- package/dist/unstable-core-do-not-import/http/formDataToObject.mjs +38 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +4 -4
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +4 -4
- package/dist/unstable-core-do-not-import/http/parseConnectionParams.d.ts +4 -0
- package/dist/unstable-core-do-not-import/http/parseConnectionParams.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/parseConnectionParams.js +42 -0
- package/dist/unstable-core-do-not-import/http/parseConnectionParams.mjs +39 -0
- package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.js +302 -149
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +301 -148
- package/dist/unstable-core-do-not-import/http/types.d.ts +26 -2
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +12 -12
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/middleware.d.ts +3 -3
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +3 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +12 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.d.ts +2 -2
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +7 -2
- package/dist/unstable-core-do-not-import/router.mjs +7 -2
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +7 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +1 -1
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/{stream.d.ts → jsonl.d.ts} +12 -8
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/{stream.js → jsonl.js} +158 -119
- package/dist/unstable-core-do-not-import/stream/{stream.mjs → jsonl.mjs} +157 -118
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +86 -0
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/sse.js +178 -0
- package/dist/unstable-core-do-not-import/stream/sse.mjs +172 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts +18 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.js +46 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.mjs +43 -0
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts +10 -0
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.js +31 -0
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.mjs +29 -0
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts +7 -0
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +5 -5
- package/dist/unstable-core-do-not-import/utils.d.ts +4 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +4 -0
- package/dist/unstable-core-do-not-import/utils.mjs +4 -1
- package/dist/unstable-core-do-not-import.d.ts +5 -2
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +19 -7
- package/dist/unstable-core-do-not-import.mjs +6 -3
- package/package.json +6 -6
- package/src/@trpc/server/http.ts +7 -2
- package/src/@trpc/server/index.ts +1 -0
- package/src/@trpc/server/rpc.ts +1 -0
- package/src/adapters/aws-lambda/getPlanner.ts +21 -2
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +2 -1
- package/src/adapters/node-http/incomingMessageToRequest.ts +3 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +32 -7
- package/src/adapters/ws.ts +193 -107
- package/src/observable/observable.ts +63 -0
- package/src/unstable-core-do-not-import/createProxy.ts +23 -8
- package/src/unstable-core-do-not-import/http/contentType.ts +83 -21
- package/src/{adapters/next-app-dir → unstable-core-do-not-import/http}/formDataToObject.ts +18 -10
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +4 -7
- package/src/unstable-core-do-not-import/http/parseConnectionParams.ts +49 -0
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +333 -164
- package/src/unstable-core-do-not-import/http/types.ts +31 -2
- package/src/unstable-core-do-not-import/procedureBuilder.ts +8 -1
- package/src/unstable-core-do-not-import/rootConfig.ts +12 -0
- package/src/unstable-core-do-not-import/router.ts +47 -35
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +9 -0
- package/src/unstable-core-do-not-import/rpc/index.ts +1 -0
- package/src/unstable-core-do-not-import/stream/{stream.ts → jsonl.ts} +186 -127
- package/src/unstable-core-do-not-import/stream/sse.ts +288 -0
- package/src/unstable-core-do-not-import/stream/utils/createDeferred.ts +48 -0
- package/src/unstable-core-do-not-import/stream/utils/createReadableStream.ts +31 -0
- package/src/unstable-core-do-not-import/stream/utils/createServer.ts +44 -0
- package/src/unstable-core-do-not-import/utils.ts +5 -0
- package/src/unstable-core-do-not-import.ts +5 -2
- package/dist/adapters/next-app-dir/formDataToObject.d.ts.map +0 -1
- package/dist/adapters/next-app-dir/formDataToObject.js +0 -34
- package/dist/adapters/next-app-dir/formDataToObject.mjs +0 -32
- package/dist/unstable-core-do-not-import/stream/stream.d.ts.map +0 -1
- /package/dist/{adapters/next-app-dir → unstable-core-do-not-import/http}/formDataToObject.d.ts +0 -0
package/dist/adapters/ws.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var TRPCError = require('../unstable-core-do-not-import/error/TRPCError.js');
|
|
4
3
|
var getErrorShape = require('../unstable-core-do-not-import/error/getErrorShape.js');
|
|
4
|
+
var TRPCError = require('../unstable-core-do-not-import/error/TRPCError.js');
|
|
5
|
+
var utils = require('../unstable-core-do-not-import/utils.js');
|
|
6
|
+
var parseConnectionParams = require('../unstable-core-do-not-import/http/parseConnectionParams.js');
|
|
5
7
|
var parseTRPCMessage = require('../unstable-core-do-not-import/rpc/parseTRPCMessage.js');
|
|
6
|
-
var
|
|
8
|
+
var observable = require('../observable/observable.js');
|
|
7
9
|
var transformer = require('../unstable-core-do-not-import/transformer.js');
|
|
10
|
+
var toURL = require('../unstable-core-do-not-import/http/toURL.js');
|
|
8
11
|
require('../unstable-core-do-not-import/rootConfig.js');
|
|
9
|
-
var
|
|
12
|
+
var router = require('../unstable-core-do-not-import/router.js');
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Importing ws causes a build error
|
|
13
16
|
* @link https://github.com/trpc/trpc/pull/5279
|
|
14
17
|
*/ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
|
|
18
|
+
const unsetContextSymbol = Symbol('unsetContext');
|
|
15
19
|
function getWSConnectionHandler(opts) {
|
|
16
20
|
const { createContext , router: router$1 } = opts;
|
|
17
21
|
const { transformer: transformer$1 } = router$1._def._config;
|
|
@@ -20,20 +24,54 @@ function getWSConnectionHandler(opts) {
|
|
|
20
24
|
function respond(untransformedJSON) {
|
|
21
25
|
client.send(JSON.stringify(transformer.transformTRPCResponse(router$1._def._config, untransformedJSON)));
|
|
22
26
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
function createCtxPromise(getConnectionParams) {
|
|
28
|
+
return utils.run(async ()=>{
|
|
29
|
+
ctx = await createContext?.({
|
|
30
|
+
req,
|
|
31
|
+
res: client,
|
|
32
|
+
info: {
|
|
33
|
+
connectionParams: getConnectionParams(),
|
|
34
|
+
calls: [],
|
|
35
|
+
isBatchCall: false,
|
|
36
|
+
accept: null,
|
|
37
|
+
type: 'unknown'
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return ctx;
|
|
41
|
+
}).catch((cause)=>{
|
|
42
|
+
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
43
|
+
opts.onError?.({
|
|
44
|
+
error,
|
|
45
|
+
path: undefined,
|
|
46
|
+
type: 'unknown',
|
|
47
|
+
ctx,
|
|
48
|
+
req,
|
|
49
|
+
input: undefined
|
|
50
|
+
});
|
|
51
|
+
respond({
|
|
52
|
+
id: null,
|
|
53
|
+
error: getErrorShape.getErrorShape({
|
|
54
|
+
config: router$1._def._config,
|
|
55
|
+
error,
|
|
56
|
+
type: 'unknown',
|
|
57
|
+
path: undefined,
|
|
58
|
+
input: undefined,
|
|
59
|
+
ctx
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
// close in next tick
|
|
63
|
+
(global.setImmediate ?? global.setTimeout)(()=>{
|
|
64
|
+
client.close();
|
|
65
|
+
});
|
|
66
|
+
throw error;
|
|
31
67
|
});
|
|
32
68
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
69
|
+
/**
|
|
70
|
+
* promise for initializing the context
|
|
71
|
+
*
|
|
72
|
+
* - the context promise will be created immediately on connection if no connectionParams are expected
|
|
73
|
+
* - if connection params are expected, they will be created once received
|
|
74
|
+
*/ let ctxPromise = toURL.toURL(req.url ?? '').searchParams.get('connectionParams') === '1' ? unsetContextSymbol : createCtxPromise(()=>null);
|
|
37
75
|
let ctx = undefined;
|
|
38
76
|
async function handleRequest(msg) {
|
|
39
77
|
const { id , jsonrpc } = msg;
|
|
@@ -44,14 +82,7 @@ function getWSConnectionHandler(opts) {
|
|
|
44
82
|
});
|
|
45
83
|
}
|
|
46
84
|
if (msg.method === 'subscription.stop') {
|
|
47
|
-
|
|
48
|
-
if (sub) {
|
|
49
|
-
stopSubscription(sub, {
|
|
50
|
-
id,
|
|
51
|
-
jsonrpc
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
clientSubscriptions.delete(id);
|
|
85
|
+
clientSubscriptions.get(id)?.abort();
|
|
55
86
|
return;
|
|
56
87
|
}
|
|
57
88
|
const { path , input } = msg.params;
|
|
@@ -65,14 +96,7 @@ function getWSConnectionHandler(opts) {
|
|
|
65
96
|
ctx,
|
|
66
97
|
type
|
|
67
98
|
});
|
|
68
|
-
if (type
|
|
69
|
-
if (!observable.isObservable(result)) {
|
|
70
|
-
throw new TRPCError.TRPCError({
|
|
71
|
-
message: `Subscription ${path} did not return an observable`,
|
|
72
|
-
code: 'INTERNAL_SERVER_ERROR'
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
99
|
+
if (type !== 'subscription') {
|
|
76
100
|
// send the value as data if the method is not a subscription
|
|
77
101
|
respond({
|
|
78
102
|
id,
|
|
@@ -84,69 +108,110 @@ function getWSConnectionHandler(opts) {
|
|
|
84
108
|
});
|
|
85
109
|
return;
|
|
86
110
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
result: {
|
|
94
|
-
type: 'data',
|
|
95
|
-
data
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
|
-
error (err) {
|
|
100
|
-
const error = TRPCError.getTRPCErrorFromUnknown(err);
|
|
101
|
-
opts.onError?.({
|
|
102
|
-
error,
|
|
103
|
-
path,
|
|
104
|
-
type,
|
|
105
|
-
ctx,
|
|
106
|
-
req,
|
|
107
|
-
input
|
|
108
|
-
});
|
|
109
|
-
respond({
|
|
110
|
-
id,
|
|
111
|
-
jsonrpc,
|
|
112
|
-
error: getErrorShape.getErrorShape({
|
|
113
|
-
config: router$1._def._config,
|
|
114
|
-
error,
|
|
115
|
-
type,
|
|
116
|
-
path,
|
|
117
|
-
input,
|
|
118
|
-
ctx
|
|
119
|
-
})
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
complete () {
|
|
123
|
-
respond({
|
|
124
|
-
id,
|
|
125
|
-
jsonrpc,
|
|
126
|
-
result: {
|
|
127
|
-
type: 'stopped'
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
});
|
|
111
|
+
if (!observable.isObservable(result) && !utils.isAsyncIterable(result)) {
|
|
112
|
+
throw new TRPCError.TRPCError({
|
|
113
|
+
message: `Subscription ${path} did not return an observable or a AsyncGenerator`,
|
|
114
|
+
code: 'INTERNAL_SERVER_ERROR'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
132
117
|
/* istanbul ignore next -- @preserve */ if (client.readyState !== WEBSOCKET_OPEN) {
|
|
133
118
|
// if the client got disconnected whilst initializing the subscription
|
|
134
119
|
// no need to send stopped message if the client is disconnected
|
|
135
|
-
sub1.unsubscribe();
|
|
136
120
|
return;
|
|
137
121
|
}
|
|
138
122
|
/* istanbul ignore next -- @preserve */ if (clientSubscriptions.has(id)) {
|
|
139
123
|
// duplicate request ids for client
|
|
140
|
-
stopSubscription(sub1, {
|
|
141
|
-
id,
|
|
142
|
-
jsonrpc
|
|
143
|
-
});
|
|
144
124
|
throw new TRPCError.TRPCError({
|
|
145
125
|
message: `Duplicate id ${id}`,
|
|
146
126
|
code: 'BAD_REQUEST'
|
|
147
127
|
});
|
|
148
128
|
}
|
|
149
|
-
|
|
129
|
+
const iterable = observable.isObservable(result) ? observable.observableToAsyncIterable(result) : result;
|
|
130
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
131
|
+
const abortController = new AbortController();
|
|
132
|
+
const abortPromise = new Promise((resolve)=>{
|
|
133
|
+
abortController.signal.onabort = ()=>resolve('abort');
|
|
134
|
+
});
|
|
135
|
+
utils.run(async ()=>{
|
|
136
|
+
while(true){
|
|
137
|
+
const next = await Promise.race([
|
|
138
|
+
iterator.next().catch(TRPCError.getTRPCErrorFromUnknown),
|
|
139
|
+
abortPromise
|
|
140
|
+
]);
|
|
141
|
+
if (next === 'abort') {
|
|
142
|
+
await iterator.return?.();
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
if (next instanceof Error) {
|
|
146
|
+
const error = TRPCError.getTRPCErrorFromUnknown(next);
|
|
147
|
+
opts.onError?.({
|
|
148
|
+
error,
|
|
149
|
+
path,
|
|
150
|
+
type,
|
|
151
|
+
ctx,
|
|
152
|
+
req,
|
|
153
|
+
input
|
|
154
|
+
});
|
|
155
|
+
respond({
|
|
156
|
+
id,
|
|
157
|
+
jsonrpc,
|
|
158
|
+
error: getErrorShape.getErrorShape({
|
|
159
|
+
config: router$1._def._config,
|
|
160
|
+
error,
|
|
161
|
+
type,
|
|
162
|
+
path,
|
|
163
|
+
input,
|
|
164
|
+
ctx
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
if (next.done) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
respond({
|
|
173
|
+
id,
|
|
174
|
+
jsonrpc,
|
|
175
|
+
result: {
|
|
176
|
+
type: 'data',
|
|
177
|
+
data: next.value
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
await iterator.return?.();
|
|
182
|
+
respond({
|
|
183
|
+
id,
|
|
184
|
+
jsonrpc,
|
|
185
|
+
result: {
|
|
186
|
+
type: 'stopped'
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
clientSubscriptions.delete(id);
|
|
190
|
+
}).catch((cause)=>{
|
|
191
|
+
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
192
|
+
opts.onError?.({
|
|
193
|
+
error,
|
|
194
|
+
path,
|
|
195
|
+
type,
|
|
196
|
+
ctx,
|
|
197
|
+
req,
|
|
198
|
+
input
|
|
199
|
+
});
|
|
200
|
+
respond({
|
|
201
|
+
id,
|
|
202
|
+
jsonrpc,
|
|
203
|
+
error: getErrorShape.getErrorShape({
|
|
204
|
+
config: router$1._def._config,
|
|
205
|
+
error,
|
|
206
|
+
type,
|
|
207
|
+
path,
|
|
208
|
+
input,
|
|
209
|
+
ctx
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
abortController.abort();
|
|
213
|
+
});
|
|
214
|
+
clientSubscriptions.set(id, abortController);
|
|
150
215
|
respond({
|
|
151
216
|
id,
|
|
152
217
|
jsonrpc,
|
|
@@ -180,8 +245,28 @@ function getWSConnectionHandler(opts) {
|
|
|
180
245
|
}
|
|
181
246
|
}
|
|
182
247
|
client.on('message', async (message)=>{
|
|
248
|
+
if (ctxPromise === unsetContextSymbol) {
|
|
249
|
+
// If the ctxPromise wasn't created immediately, we're expecting the first message to be a TRPCConnectionParamsMessage
|
|
250
|
+
ctxPromise = createCtxPromise(()=>{
|
|
251
|
+
let msg;
|
|
252
|
+
try {
|
|
253
|
+
msg = JSON.parse(message.toString());
|
|
254
|
+
if (!utils.isObject(msg)) {
|
|
255
|
+
throw new Error('Message was not an object');
|
|
256
|
+
}
|
|
257
|
+
} catch (cause) {
|
|
258
|
+
throw new TRPCError.TRPCError({
|
|
259
|
+
code: 'PARSE_ERROR',
|
|
260
|
+
message: `Malformed TRPCConnectionParamsMessage`,
|
|
261
|
+
cause
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
const connectionParams = parseConnectionParams.parseConnectionParamsFromUnknown(msg.data);
|
|
265
|
+
return connectionParams;
|
|
266
|
+
});
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
183
269
|
try {
|
|
184
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
185
270
|
const msgJSON = JSON.parse(message.toString());
|
|
186
271
|
const msgs = Array.isArray(msgJSON) ? msgJSON : [
|
|
187
272
|
msgJSON
|
|
@@ -222,41 +307,14 @@ function getWSConnectionHandler(opts) {
|
|
|
222
307
|
});
|
|
223
308
|
client.once('close', ()=>{
|
|
224
309
|
for (const sub of clientSubscriptions.values()){
|
|
225
|
-
sub.
|
|
310
|
+
sub.abort();
|
|
226
311
|
}
|
|
227
312
|
clientSubscriptions.clear();
|
|
228
313
|
});
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
} catch (cause) {
|
|
233
|
-
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
234
|
-
opts.onError?.({
|
|
235
|
-
error,
|
|
236
|
-
path: undefined,
|
|
237
|
-
type: 'unknown',
|
|
238
|
-
ctx,
|
|
239
|
-
req,
|
|
240
|
-
input: undefined
|
|
241
|
-
});
|
|
242
|
-
respond({
|
|
243
|
-
id: null,
|
|
244
|
-
error: getErrorShape.getErrorShape({
|
|
245
|
-
config: router$1._def._config,
|
|
246
|
-
error,
|
|
247
|
-
type: 'unknown',
|
|
248
|
-
path: undefined,
|
|
249
|
-
input: undefined,
|
|
250
|
-
ctx
|
|
251
|
-
})
|
|
252
|
-
});
|
|
253
|
-
// close in next tick
|
|
254
|
-
(global.setImmediate ?? global.setTimeout)(()=>{
|
|
255
|
-
client.close();
|
|
256
|
-
});
|
|
257
|
-
}
|
|
314
|
+
if (ctxPromise !== unsetContextSymbol) {
|
|
315
|
+
// prevent unhandled promise rejection errors
|
|
316
|
+
await ctxPromise.catch(()=>null);
|
|
258
317
|
}
|
|
259
|
-
await createContextAsync();
|
|
260
318
|
};
|
|
261
319
|
}
|
|
262
320
|
/**
|