@trpc/client 11.0.0-alpha-tmp-subscription-connection-state.487 → 11.0.0-alpha-tmp-subscription-connection-state.489
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/bundle-analysis.json +33 -33
- package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
- package/dist/links/httpSubscriptionLink.js +6 -2
- package/dist/links/httpSubscriptionLink.mjs +6 -2
- package/dist/links/wsLink.d.ts +5 -1
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +70 -56
- package/dist/links/wsLink.mjs +70 -56
- package/package.json +5 -5
- package/src/links/httpSubscriptionLink.ts +12 -4
- package/src/links/wsLink.ts +35 -12
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 25.
|
|
2
|
+
"bundleSize": 58110,
|
|
3
|
+
"bundleOrigSize": 77569,
|
|
4
|
+
"bundleReduction": 25.09,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/links/wsLink.ts",
|
|
8
|
-
"size":
|
|
9
|
-
"origSize":
|
|
8
|
+
"size": 16780,
|
|
9
|
+
"origSize": 17626,
|
|
10
10
|
"renderedExports": [
|
|
11
11
|
"createWSClient",
|
|
12
12
|
"wsLink"
|
|
13
13
|
],
|
|
14
14
|
"removedExports": [],
|
|
15
15
|
"dependents": [],
|
|
16
|
-
"percent": 28.
|
|
17
|
-
"reduction":
|
|
16
|
+
"percent": 28.88,
|
|
17
|
+
"reduction": 4.8
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
"id": "/src/links/
|
|
21
|
-
"size":
|
|
22
|
-
"origSize":
|
|
20
|
+
"id": "/src/links/httpSubscriptionLink.ts",
|
|
21
|
+
"size": 5925,
|
|
22
|
+
"origSize": 5715,
|
|
23
23
|
"renderedExports": [
|
|
24
|
-
"
|
|
24
|
+
"unstable_httpSubscriptionLink"
|
|
25
25
|
],
|
|
26
26
|
"removedExports": [],
|
|
27
27
|
"dependents": [],
|
|
28
|
-
"percent": 10.
|
|
29
|
-
"reduction":
|
|
28
|
+
"percent": 10.2,
|
|
29
|
+
"reduction": 0
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
|
-
"id": "/src/links/
|
|
33
|
-
"size":
|
|
34
|
-
"origSize":
|
|
32
|
+
"id": "/src/links/httpBatchStreamLink.ts",
|
|
33
|
+
"size": 5861,
|
|
34
|
+
"origSize": 6074,
|
|
35
35
|
"renderedExports": [
|
|
36
|
-
"
|
|
36
|
+
"unstable_httpBatchStreamLink"
|
|
37
37
|
],
|
|
38
38
|
"removedExports": [],
|
|
39
39
|
"dependents": [],
|
|
40
|
-
"percent": 10.
|
|
41
|
-
"reduction":
|
|
40
|
+
"percent": 10.09,
|
|
41
|
+
"reduction": 3.51
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
"id": "/src/links/loggerLink.ts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"removedExports": [],
|
|
51
51
|
"dependents": [],
|
|
52
|
-
"percent": 9.
|
|
52
|
+
"percent": 9.39,
|
|
53
53
|
"reduction": 18.48
|
|
54
54
|
},
|
|
55
55
|
{
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"/src/links/httpBatchStreamLink.ts",
|
|
74
74
|
"/src/links/httpSubscriptionLink.ts"
|
|
75
75
|
],
|
|
76
|
-
"percent": 7.
|
|
76
|
+
"percent": 7.68,
|
|
77
77
|
"reduction": 32.82
|
|
78
78
|
},
|
|
79
79
|
{
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"/src/links/httpBatchLink.ts",
|
|
89
89
|
"/src/links/httpBatchStreamLink.ts"
|
|
90
90
|
],
|
|
91
|
-
"percent": 7.
|
|
91
|
+
"percent": 7.03,
|
|
92
92
|
"reduction": 5.64
|
|
93
93
|
},
|
|
94
94
|
{
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
],
|
|
101
101
|
"removedExports": [],
|
|
102
102
|
"dependents": [],
|
|
103
|
-
"percent": 6.
|
|
103
|
+
"percent": 6.75,
|
|
104
104
|
"reduction": 4.69
|
|
105
105
|
},
|
|
106
106
|
{
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
],
|
|
113
113
|
"removedExports": [],
|
|
114
114
|
"dependents": [],
|
|
115
|
-
"percent": 5.
|
|
115
|
+
"percent": 5.48,
|
|
116
116
|
"reduction": 14.15
|
|
117
117
|
},
|
|
118
118
|
{
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"/src/createTRPCUntypedClient.ts",
|
|
128
128
|
"/src/createTRPCClient.ts"
|
|
129
129
|
],
|
|
130
|
-
"percent": 3.
|
|
130
|
+
"percent": 3.93,
|
|
131
131
|
"reduction": 47.25
|
|
132
132
|
},
|
|
133
133
|
{
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
"/src/links/httpSubscriptionLink.ts",
|
|
148
148
|
"/src/internals/TRPCUntypedClient.ts"
|
|
149
149
|
],
|
|
150
|
-
"percent": 3.
|
|
150
|
+
"percent": 3.34,
|
|
151
151
|
"reduction": 45.43
|
|
152
152
|
},
|
|
153
153
|
{
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
"dependents": [
|
|
165
165
|
"/src/index.ts"
|
|
166
166
|
],
|
|
167
|
-
"percent": 2.
|
|
167
|
+
"percent": 2.04,
|
|
168
168
|
"reduction": 73.19
|
|
169
169
|
},
|
|
170
170
|
{
|
|
@@ -179,7 +179,7 @@
|
|
|
179
179
|
"/src/links/splitLink.ts",
|
|
180
180
|
"/src/internals/TRPCUntypedClient.ts"
|
|
181
181
|
],
|
|
182
|
-
"percent": 1.
|
|
182
|
+
"percent": 1.19,
|
|
183
183
|
"reduction": 32.75
|
|
184
184
|
},
|
|
185
185
|
{
|
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
],
|
|
192
192
|
"removedExports": [],
|
|
193
193
|
"dependents": [],
|
|
194
|
-
"percent": 1.
|
|
194
|
+
"percent": 1.05,
|
|
195
195
|
"reduction": 44.95
|
|
196
196
|
},
|
|
197
197
|
{
|
|
@@ -205,7 +205,7 @@
|
|
|
205
205
|
"dependents": [
|
|
206
206
|
"/src/unstable-internals.ts"
|
|
207
207
|
],
|
|
208
|
-
"percent": 0.
|
|
208
|
+
"percent": 0.97,
|
|
209
209
|
"reduction": 66.75
|
|
210
210
|
},
|
|
211
211
|
{
|
|
@@ -220,7 +220,7 @@
|
|
|
220
220
|
"/src/index.ts",
|
|
221
221
|
"/src/links/internals/httpUtils.ts"
|
|
222
222
|
],
|
|
223
|
-
"percent": 0.
|
|
223
|
+
"percent": 0.74,
|
|
224
224
|
"reduction": 33.54
|
|
225
225
|
},
|
|
226
226
|
{
|
|
@@ -236,7 +236,7 @@
|
|
|
236
236
|
"dependents": [
|
|
237
237
|
"/src/links/types.ts"
|
|
238
238
|
],
|
|
239
|
-
"percent": 0.
|
|
239
|
+
"percent": 0.57,
|
|
240
240
|
"reduction": 15.17
|
|
241
241
|
},
|
|
242
242
|
{
|
|
@@ -251,7 +251,7 @@
|
|
|
251
251
|
"/src/links/wsLink.ts",
|
|
252
252
|
"/src/links/httpSubscriptionLink.ts"
|
|
253
253
|
],
|
|
254
|
-
"percent": 0.
|
|
254
|
+
"percent": 0.27,
|
|
255
255
|
"reduction": 81.71
|
|
256
256
|
},
|
|
257
257
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpSubscriptionLink.d.ts","sourceRoot":"","sources":["../../src/links/httpSubscriptionLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"httpSubscriptionLink.d.ts","sourceRoot":"","sources":["../../src/links/httpSubscriptionLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,0CAA0C,CAAC;AAMlD,OAAO,EAAkB,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAiBxC,KAAK,2BAA2B,CAAC,KAAK,SAAS,cAAc,IAAI;IAC/D;;OAEG;IACH,kBAAkB,CAAC,EAAE,eAAe,CAAC,eAAe,CAAC,CAAC;CACvD,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAC3B,8BAA8B,CAAC;AAEjC;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,SAAS,qBAAqB,EAEzC,IAAI,EAAE,2BAA2B,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,GAC/D,QAAQ,CAAC,WAAW,CAAC,CAuJvB"}
|
|
@@ -92,8 +92,12 @@ async function urlWithConnectionParams(opts) {
|
|
|
92
92
|
deserialize: transformer$1.output.deserialize
|
|
93
93
|
});
|
|
94
94
|
for await (const chunk of iterable){
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
if (!chunk.ok) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const chunkData = chunk.data;
|
|
99
|
+
// if the `tracked()`-helper is used, we always have an `id` field
|
|
100
|
+
const data = 'id' in chunkData ? chunkData : chunkData.data;
|
|
97
101
|
observer.next({
|
|
98
102
|
result: {
|
|
99
103
|
data
|
|
@@ -90,8 +90,12 @@ async function urlWithConnectionParams(opts) {
|
|
|
90
90
|
deserialize: transformer.output.deserialize
|
|
91
91
|
});
|
|
92
92
|
for await (const chunk of iterable){
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
if (!chunk.ok) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const chunkData = chunk.data;
|
|
97
|
+
// if the `tracked()`-helper is used, we always have an `id` field
|
|
98
|
+
const data = 'id' in chunkData ? chunkData : chunkData.data;
|
|
95
99
|
observer.next({
|
|
96
100
|
result: {
|
|
97
101
|
data
|
package/dist/links/wsLink.d.ts
CHANGED
|
@@ -47,7 +47,11 @@ export interface WebSocketClientOptions extends UrlOptionsWithConnectionParams {
|
|
|
47
47
|
}
|
|
48
48
|
export declare function createWSClient(opts: WebSocketClientOptions): {
|
|
49
49
|
close: () => void;
|
|
50
|
-
request: (
|
|
50
|
+
request: (opts: {
|
|
51
|
+
op: Operation;
|
|
52
|
+
callbacks: WSCallbackObserver<AnyRouter, unknown>;
|
|
53
|
+
lastEventId: string | undefined;
|
|
54
|
+
}) => UnsubscribeFn;
|
|
51
55
|
readonly connection: ({
|
|
52
56
|
id: number;
|
|
53
57
|
} & ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsLink.d.ts","sourceRoot":"","sources":["../../src/links/wsLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGvE,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAMhB,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,0BAA0B,EAC/B,KAAK,QAAQ,EACd,MAAM,SAAS,CAAC;AAIjB,KAAK,gBAAgB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,IACpD,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GACvD;IAAE,MAAM,EAAE,0BAA0B,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;uBAzTqB,KAAK,GAAG,IAAI;EA4TvC;AACD,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAEpE,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,SAAS,IAAI;IAC5D,MAAM,EAAE,mBAAmB,CAAC;CAC7B,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AASlD;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,SAAS,SAAS,EAC9C,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAClC,QAAQ,CAAC,OAAO,CAAC,CAoGnB"}
|
package/dist/links/wsLink.js
CHANGED
|
@@ -100,7 +100,11 @@ function createWSClient(opts) {
|
|
|
100
100
|
if (outgoing.some((r)=>r.id === req.op.id)) {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
|
-
request(
|
|
103
|
+
request({
|
|
104
|
+
op: req.op,
|
|
105
|
+
callbacks: req.callbacks,
|
|
106
|
+
lastEventId: req.lastEventId
|
|
107
|
+
});
|
|
104
108
|
}
|
|
105
109
|
const startLazyDisconnectTimer = ()=>{
|
|
106
110
|
if (!lazyOpts.enabled) {
|
|
@@ -217,6 +221,9 @@ function createWSClient(opts) {
|
|
|
217
221
|
req.connection = self;
|
|
218
222
|
oldConn && closeIfNoPending(oldConn);
|
|
219
223
|
}
|
|
224
|
+
if ('result' in data && data.result.type === 'data' && typeof data.result.id === 'string') {
|
|
225
|
+
req.lastEventId = data.result.id;
|
|
226
|
+
}
|
|
220
227
|
if ('result' in data && data.result.type === 'stopped' && activeConnection === self) {
|
|
221
228
|
req.callbacks.complete();
|
|
222
229
|
}
|
|
@@ -269,21 +276,24 @@ function createWSClient(opts) {
|
|
|
269
276
|
}).catch(onError);
|
|
270
277
|
return self;
|
|
271
278
|
}
|
|
272
|
-
function request(
|
|
279
|
+
function request(opts) {
|
|
280
|
+
const { op , callbacks , lastEventId } = opts;
|
|
273
281
|
const { type , input , path , id } = op;
|
|
274
282
|
const envelope = {
|
|
275
283
|
id,
|
|
276
284
|
method: type,
|
|
277
285
|
params: {
|
|
278
286
|
input,
|
|
279
|
-
path
|
|
287
|
+
path,
|
|
288
|
+
lastEventId
|
|
280
289
|
}
|
|
281
290
|
};
|
|
282
291
|
pendingRequests[id] = {
|
|
283
292
|
connection: null,
|
|
284
293
|
type,
|
|
285
294
|
callbacks,
|
|
286
|
-
op
|
|
295
|
+
op,
|
|
296
|
+
lastEventId
|
|
287
297
|
};
|
|
288
298
|
// enqueue message
|
|
289
299
|
outgoing.push(envelope);
|
|
@@ -346,69 +356,73 @@ class TRPCWebSocketClosedError extends Error {
|
|
|
346
356
|
const { type , path , id , context } = op;
|
|
347
357
|
const input = transformer$1.input.serialize(op.input);
|
|
348
358
|
const unsub = client.request({
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
error (err) {
|
|
357
|
-
observer.error(err);
|
|
358
|
-
observer.next({
|
|
359
|
-
result: {
|
|
360
|
-
type: 'state',
|
|
361
|
-
state: 'error',
|
|
362
|
-
data: err
|
|
363
|
-
},
|
|
364
|
-
context: context
|
|
365
|
-
});
|
|
366
|
-
unsub();
|
|
359
|
+
op: {
|
|
360
|
+
type,
|
|
361
|
+
path,
|
|
362
|
+
input,
|
|
363
|
+
id,
|
|
364
|
+
context,
|
|
365
|
+
signal: null
|
|
367
366
|
},
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
observer.next({
|
|
371
|
-
result: {
|
|
372
|
-
type: 'state',
|
|
373
|
-
state: 'idle'
|
|
374
|
-
},
|
|
375
|
-
context: context
|
|
376
|
-
});
|
|
377
|
-
},
|
|
378
|
-
next (message) {
|
|
379
|
-
if ('result' in message && types.isConnectionStateMessage(message.result)) {
|
|
380
|
-
message.result;
|
|
381
|
-
observer.next({
|
|
382
|
-
result: message.result,
|
|
383
|
-
context: context
|
|
384
|
-
});
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
if (!('id' in message)) return;
|
|
388
|
-
const transformed = unstableCoreDoNotImport.transformResult(message, transformer$1.output);
|
|
389
|
-
if (!transformed.ok) {
|
|
390
|
-
const error = TRPCClientError.TRPCClientError.from(transformed.error);
|
|
367
|
+
callbacks: {
|
|
368
|
+
error (err) {
|
|
391
369
|
observer.next({
|
|
392
370
|
result: {
|
|
393
371
|
type: 'state',
|
|
394
372
|
state: 'error',
|
|
395
|
-
data:
|
|
373
|
+
data: err
|
|
396
374
|
},
|
|
397
375
|
context: context
|
|
398
376
|
});
|
|
399
|
-
observer.error(
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
observer.next({
|
|
403
|
-
result: transformed.result,
|
|
404
|
-
context: context
|
|
405
|
-
});
|
|
406
|
-
if (op.type !== 'subscription') {
|
|
407
|
-
// if it isn't a subscription we don't care about next response
|
|
377
|
+
observer.error(err);
|
|
408
378
|
unsub();
|
|
379
|
+
},
|
|
380
|
+
complete () {
|
|
409
381
|
observer.complete();
|
|
382
|
+
observer.next({
|
|
383
|
+
result: {
|
|
384
|
+
type: 'state',
|
|
385
|
+
state: 'idle'
|
|
386
|
+
},
|
|
387
|
+
context: context
|
|
388
|
+
});
|
|
389
|
+
},
|
|
390
|
+
next (message) {
|
|
391
|
+
if ('result' in message && types.isConnectionStateMessage(message.result)) {
|
|
392
|
+
message.result;
|
|
393
|
+
observer.next({
|
|
394
|
+
result: message.result,
|
|
395
|
+
context: context
|
|
396
|
+
});
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (!('id' in message)) return;
|
|
400
|
+
const transformed = unstableCoreDoNotImport.transformResult(message, transformer$1.output);
|
|
401
|
+
if (!transformed.ok) {
|
|
402
|
+
const error = TRPCClientError.TRPCClientError.from(transformed.error);
|
|
403
|
+
observer.next({
|
|
404
|
+
result: {
|
|
405
|
+
type: 'state',
|
|
406
|
+
state: 'error',
|
|
407
|
+
data: error
|
|
408
|
+
},
|
|
409
|
+
context: context
|
|
410
|
+
});
|
|
411
|
+
observer.error(TRPCClientError.TRPCClientError.from(error));
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
observer.next({
|
|
415
|
+
result: transformed.result,
|
|
416
|
+
context: context
|
|
417
|
+
});
|
|
418
|
+
if (op.type !== 'subscription') {
|
|
419
|
+
// if it isn't a subscription we don't care about next response
|
|
420
|
+
unsub();
|
|
421
|
+
observer.complete();
|
|
422
|
+
}
|
|
410
423
|
}
|
|
411
|
-
}
|
|
424
|
+
},
|
|
425
|
+
lastEventId: undefined
|
|
412
426
|
});
|
|
413
427
|
return ()=>{
|
|
414
428
|
unsub();
|
package/dist/links/wsLink.mjs
CHANGED
|
@@ -98,7 +98,11 @@ function createWSClient(opts) {
|
|
|
98
98
|
if (outgoing.some((r)=>r.id === req.op.id)) {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
request(
|
|
101
|
+
request({
|
|
102
|
+
op: req.op,
|
|
103
|
+
callbacks: req.callbacks,
|
|
104
|
+
lastEventId: req.lastEventId
|
|
105
|
+
});
|
|
102
106
|
}
|
|
103
107
|
const startLazyDisconnectTimer = ()=>{
|
|
104
108
|
if (!lazyOpts.enabled) {
|
|
@@ -215,6 +219,9 @@ function createWSClient(opts) {
|
|
|
215
219
|
req.connection = self;
|
|
216
220
|
oldConn && closeIfNoPending(oldConn);
|
|
217
221
|
}
|
|
222
|
+
if ('result' in data && data.result.type === 'data' && typeof data.result.id === 'string') {
|
|
223
|
+
req.lastEventId = data.result.id;
|
|
224
|
+
}
|
|
218
225
|
if ('result' in data && data.result.type === 'stopped' && activeConnection === self) {
|
|
219
226
|
req.callbacks.complete();
|
|
220
227
|
}
|
|
@@ -267,21 +274,24 @@ function createWSClient(opts) {
|
|
|
267
274
|
}).catch(onError);
|
|
268
275
|
return self;
|
|
269
276
|
}
|
|
270
|
-
function request(
|
|
277
|
+
function request(opts) {
|
|
278
|
+
const { op , callbacks , lastEventId } = opts;
|
|
271
279
|
const { type , input , path , id } = op;
|
|
272
280
|
const envelope = {
|
|
273
281
|
id,
|
|
274
282
|
method: type,
|
|
275
283
|
params: {
|
|
276
284
|
input,
|
|
277
|
-
path
|
|
285
|
+
path,
|
|
286
|
+
lastEventId
|
|
278
287
|
}
|
|
279
288
|
};
|
|
280
289
|
pendingRequests[id] = {
|
|
281
290
|
connection: null,
|
|
282
291
|
type,
|
|
283
292
|
callbacks,
|
|
284
|
-
op
|
|
293
|
+
op,
|
|
294
|
+
lastEventId
|
|
285
295
|
};
|
|
286
296
|
// enqueue message
|
|
287
297
|
outgoing.push(envelope);
|
|
@@ -344,69 +354,73 @@ class TRPCWebSocketClosedError extends Error {
|
|
|
344
354
|
const { type , path , id , context } = op;
|
|
345
355
|
const input = transformer.input.serialize(op.input);
|
|
346
356
|
const unsub = client.request({
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
error (err) {
|
|
355
|
-
observer.error(err);
|
|
356
|
-
observer.next({
|
|
357
|
-
result: {
|
|
358
|
-
type: 'state',
|
|
359
|
-
state: 'error',
|
|
360
|
-
data: err
|
|
361
|
-
},
|
|
362
|
-
context: context
|
|
363
|
-
});
|
|
364
|
-
unsub();
|
|
357
|
+
op: {
|
|
358
|
+
type,
|
|
359
|
+
path,
|
|
360
|
+
input,
|
|
361
|
+
id,
|
|
362
|
+
context,
|
|
363
|
+
signal: null
|
|
365
364
|
},
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
observer.next({
|
|
369
|
-
result: {
|
|
370
|
-
type: 'state',
|
|
371
|
-
state: 'idle'
|
|
372
|
-
},
|
|
373
|
-
context: context
|
|
374
|
-
});
|
|
375
|
-
},
|
|
376
|
-
next (message) {
|
|
377
|
-
if ('result' in message && isConnectionStateMessage(message.result)) {
|
|
378
|
-
message.result;
|
|
379
|
-
observer.next({
|
|
380
|
-
result: message.result,
|
|
381
|
-
context: context
|
|
382
|
-
});
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
if (!('id' in message)) return;
|
|
386
|
-
const transformed = transformResult(message, transformer.output);
|
|
387
|
-
if (!transformed.ok) {
|
|
388
|
-
const error = TRPCClientError.from(transformed.error);
|
|
365
|
+
callbacks: {
|
|
366
|
+
error (err) {
|
|
389
367
|
observer.next({
|
|
390
368
|
result: {
|
|
391
369
|
type: 'state',
|
|
392
370
|
state: 'error',
|
|
393
|
-
data:
|
|
371
|
+
data: err
|
|
394
372
|
},
|
|
395
373
|
context: context
|
|
396
374
|
});
|
|
397
|
-
observer.error(
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
observer.next({
|
|
401
|
-
result: transformed.result,
|
|
402
|
-
context: context
|
|
403
|
-
});
|
|
404
|
-
if (op.type !== 'subscription') {
|
|
405
|
-
// if it isn't a subscription we don't care about next response
|
|
375
|
+
observer.error(err);
|
|
406
376
|
unsub();
|
|
377
|
+
},
|
|
378
|
+
complete () {
|
|
407
379
|
observer.complete();
|
|
380
|
+
observer.next({
|
|
381
|
+
result: {
|
|
382
|
+
type: 'state',
|
|
383
|
+
state: 'idle'
|
|
384
|
+
},
|
|
385
|
+
context: context
|
|
386
|
+
});
|
|
387
|
+
},
|
|
388
|
+
next (message) {
|
|
389
|
+
if ('result' in message && isConnectionStateMessage(message.result)) {
|
|
390
|
+
message.result;
|
|
391
|
+
observer.next({
|
|
392
|
+
result: message.result,
|
|
393
|
+
context: context
|
|
394
|
+
});
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (!('id' in message)) return;
|
|
398
|
+
const transformed = transformResult(message, transformer.output);
|
|
399
|
+
if (!transformed.ok) {
|
|
400
|
+
const error = TRPCClientError.from(transformed.error);
|
|
401
|
+
observer.next({
|
|
402
|
+
result: {
|
|
403
|
+
type: 'state',
|
|
404
|
+
state: 'error',
|
|
405
|
+
data: error
|
|
406
|
+
},
|
|
407
|
+
context: context
|
|
408
|
+
});
|
|
409
|
+
observer.error(TRPCClientError.from(error));
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
observer.next({
|
|
413
|
+
result: transformed.result,
|
|
414
|
+
context: context
|
|
415
|
+
});
|
|
416
|
+
if (op.type !== 'subscription') {
|
|
417
|
+
// if it isn't a subscription we don't care about next response
|
|
418
|
+
unsub();
|
|
419
|
+
observer.complete();
|
|
420
|
+
}
|
|
408
421
|
}
|
|
409
|
-
}
|
|
422
|
+
},
|
|
423
|
+
lastEventId: undefined
|
|
410
424
|
});
|
|
411
425
|
return ()=>{
|
|
412
426
|
unsub();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "11.0.0-alpha-tmp-subscription-connection-state.
|
|
3
|
+
"version": "11.0.0-alpha-tmp-subscription-connection-state.489+04c141d1b",
|
|
4
4
|
"description": "The tRPC client library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,13 +76,13 @@
|
|
|
76
76
|
"!**/*.test.*"
|
|
77
77
|
],
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.
|
|
79
|
+
"@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.489+04c141d1b"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.
|
|
82
|
+
"@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.489+04c141d1b",
|
|
83
83
|
"@types/isomorphic-fetch": "^0.0.39",
|
|
84
84
|
"@types/node": "^20.10.0",
|
|
85
|
-
"eslint": "^8.
|
|
85
|
+
"eslint": "^8.57.0",
|
|
86
86
|
"isomorphic-fetch": "^3.0.0",
|
|
87
87
|
"node-fetch": "^3.3.0",
|
|
88
88
|
"rollup": "^4.9.5",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"funding": [
|
|
97
97
|
"https://trpc.io/sponsor"
|
|
98
98
|
],
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "04c141d1b4bb50631826aa956a874ba1d363f492"
|
|
100
100
|
}
|
|
@@ -3,7 +3,6 @@ import type {
|
|
|
3
3
|
AnyClientTypes,
|
|
4
4
|
inferClientTypes,
|
|
5
5
|
InferrableClientTypes,
|
|
6
|
-
SSEMessage,
|
|
7
6
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
8
7
|
import {
|
|
9
8
|
run,
|
|
@@ -134,14 +133,23 @@ export function unstable_httpSubscriptionLink<
|
|
|
134
133
|
});
|
|
135
134
|
});
|
|
136
135
|
|
|
137
|
-
const iterable = sseStreamConsumer<
|
|
136
|
+
const iterable = sseStreamConsumer<{
|
|
137
|
+
id?: string;
|
|
138
|
+
data?: unknown;
|
|
139
|
+
}>({
|
|
138
140
|
from: eventSource,
|
|
139
141
|
deserialize: transformer.output.deserialize,
|
|
140
142
|
});
|
|
141
143
|
|
|
142
144
|
for await (const chunk of iterable) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
if (!chunk.ok) {
|
|
146
|
+
// TODO: handle in https://github.com/trpc/trpc/issues/5871
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const chunkData = chunk.data;
|
|
150
|
+
|
|
151
|
+
// if the `tracked()`-helper is used, we always have an `id` field
|
|
152
|
+
const data = 'id' in chunkData ? chunkData : chunkData.data;
|
|
145
153
|
observer.next({
|
|
146
154
|
result: {
|
|
147
155
|
data,
|
package/src/links/wsLink.ts
CHANGED
|
@@ -107,7 +107,7 @@ export function createWSClient(opts: WebSocketClientOptions) {
|
|
|
107
107
|
* pending outgoing requests that are awaiting callback
|
|
108
108
|
*/
|
|
109
109
|
type TCallbacks = WSCallbackObserver<AnyRouter, unknown>;
|
|
110
|
-
type
|
|
110
|
+
type WsRequest = {
|
|
111
111
|
/**
|
|
112
112
|
* Reference to the WebSocket instance this request was made to
|
|
113
113
|
*/
|
|
@@ -115,8 +115,12 @@ export function createWSClient(opts: WebSocketClientOptions) {
|
|
|
115
115
|
type: ProcedureType;
|
|
116
116
|
callbacks: TCallbacks;
|
|
117
117
|
op: Operation;
|
|
118
|
+
/**
|
|
119
|
+
* The last event id that the client has received
|
|
120
|
+
*/
|
|
121
|
+
lastEventId: string | undefined;
|
|
118
122
|
};
|
|
119
|
-
const pendingRequests: Record<number | string,
|
|
123
|
+
const pendingRequests: Record<number | string, WsRequest> =
|
|
120
124
|
Object.create(null);
|
|
121
125
|
let connectAttempt = 0;
|
|
122
126
|
let connectTimer: ReturnType<typeof setTimeout> | undefined = undefined;
|
|
@@ -214,11 +218,15 @@ export function createWSClient(opts: WebSocketClientOptions) {
|
|
|
214
218
|
conn.ws?.close();
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
|
-
function resumeSubscriptionOnReconnect(req:
|
|
221
|
+
function resumeSubscriptionOnReconnect(req: WsRequest) {
|
|
218
222
|
if (outgoing.some((r) => r.id === req.op.id)) {
|
|
219
223
|
return;
|
|
220
224
|
}
|
|
221
|
-
request(
|
|
225
|
+
request({
|
|
226
|
+
op: req.op,
|
|
227
|
+
callbacks: req.callbacks,
|
|
228
|
+
lastEventId: req.lastEventId,
|
|
229
|
+
});
|
|
222
230
|
}
|
|
223
231
|
|
|
224
232
|
const startLazyDisconnectTimer = () => {
|
|
@@ -356,6 +364,13 @@ export function createWSClient(opts: WebSocketClientOptions) {
|
|
|
356
364
|
oldConn && closeIfNoPending(oldConn);
|
|
357
365
|
}
|
|
358
366
|
|
|
367
|
+
if (
|
|
368
|
+
'result' in data &&
|
|
369
|
+
data.result.type === 'data' &&
|
|
370
|
+
typeof data.result.id === 'string'
|
|
371
|
+
) {
|
|
372
|
+
req.lastEventId = data.result.id;
|
|
373
|
+
}
|
|
359
374
|
if (
|
|
360
375
|
'result' in data &&
|
|
361
376
|
data.result.type === 'stopped' &&
|
|
@@ -421,7 +436,12 @@ export function createWSClient(opts: WebSocketClientOptions) {
|
|
|
421
436
|
return self;
|
|
422
437
|
}
|
|
423
438
|
|
|
424
|
-
function request(
|
|
439
|
+
function request(opts: {
|
|
440
|
+
op: Operation;
|
|
441
|
+
callbacks: TCallbacks;
|
|
442
|
+
lastEventId: string | undefined;
|
|
443
|
+
}): UnsubscribeFn {
|
|
444
|
+
const { op, callbacks, lastEventId } = opts;
|
|
425
445
|
const { type, input, path, id } = op;
|
|
426
446
|
const envelope: TRPCRequestMessage = {
|
|
427
447
|
id,
|
|
@@ -429,13 +449,16 @@ export function createWSClient(opts: WebSocketClientOptions) {
|
|
|
429
449
|
params: {
|
|
430
450
|
input,
|
|
431
451
|
path,
|
|
452
|
+
lastEventId,
|
|
432
453
|
},
|
|
433
454
|
};
|
|
455
|
+
|
|
434
456
|
pendingRequests[id] = {
|
|
435
457
|
connection: null,
|
|
436
458
|
type,
|
|
437
459
|
callbacks,
|
|
438
460
|
op,
|
|
461
|
+
lastEventId,
|
|
439
462
|
};
|
|
440
463
|
|
|
441
464
|
// enqueue message
|
|
@@ -518,12 +541,10 @@ export function wsLink<TRouter extends AnyRouter>(
|
|
|
518
541
|
|
|
519
542
|
const input = transformer.input.serialize(op.input);
|
|
520
543
|
|
|
521
|
-
const unsub = client.request(
|
|
522
|
-
{ type, path, input, id, context, signal: null },
|
|
523
|
-
{
|
|
544
|
+
const unsub = client.request({
|
|
545
|
+
op: { type, path, input, id, context, signal: null },
|
|
546
|
+
callbacks: {
|
|
524
547
|
error(err) {
|
|
525
|
-
observer.error(err as TRPCClientError<any>);
|
|
526
|
-
|
|
527
548
|
observer.next({
|
|
528
549
|
result: {
|
|
529
550
|
type: 'state',
|
|
@@ -532,6 +553,7 @@ export function wsLink<TRouter extends AnyRouter>(
|
|
|
532
553
|
},
|
|
533
554
|
context: context,
|
|
534
555
|
});
|
|
556
|
+
observer.error(err as TRPCClientError<any>);
|
|
535
557
|
|
|
536
558
|
unsub();
|
|
537
559
|
},
|
|
@@ -578,7 +600,7 @@ export function wsLink<TRouter extends AnyRouter>(
|
|
|
578
600
|
},
|
|
579
601
|
context: context,
|
|
580
602
|
});
|
|
581
|
-
observer.error(TRPCClientError.from(
|
|
603
|
+
observer.error(TRPCClientError.from(error));
|
|
582
604
|
return;
|
|
583
605
|
}
|
|
584
606
|
observer.next({
|
|
@@ -594,7 +616,8 @@ export function wsLink<TRouter extends AnyRouter>(
|
|
|
594
616
|
}
|
|
595
617
|
},
|
|
596
618
|
},
|
|
597
|
-
|
|
619
|
+
lastEventId: undefined,
|
|
620
|
+
});
|
|
598
621
|
return () => {
|
|
599
622
|
unsub();
|
|
600
623
|
observer.next({
|