@trpc/client 11.0.0-rc.630 → 11.0.0-rc.633
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 +51 -36
- package/dist/createTRPCClient.d.ts +1 -1
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/internals/TRPCUntypedClient.js +1 -1
- package/dist/internals/TRPCUntypedClient.mjs +1 -1
- package/dist/internals/inputWithTrackedEventId.d.ts +2 -0
- package/dist/internals/inputWithTrackedEventId.d.ts.map +1 -0
- package/dist/internals/inputWithTrackedEventId.js +16 -0
- package/dist/internals/inputWithTrackedEventId.mjs +14 -0
- package/dist/links/httpSubscriptionLink.d.ts +4 -0
- package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
- package/dist/links/httpSubscriptionLink.js +29 -7
- package/dist/links/httpSubscriptionLink.mjs +29 -7
- package/dist/links/{internals/retryLink.d.ts → retryLink.d.ts} +2 -2
- package/dist/links/retryLink.d.ts.map +1 -0
- package/dist/links/{internals/retryLink.js → retryLink.js} +22 -4
- package/dist/links/{internals/retryLink.mjs → retryLink.mjs} +22 -4
- package/dist/links.d.ts +1 -1
- package/dist/links.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/createTRPCClient.ts +1 -1
- package/src/internals/TRPCUntypedClient.ts +1 -1
- package/src/internals/inputWithTrackedEventId.ts +15 -0
- package/src/links/httpSubscriptionLink.ts +39 -7
- package/src/links/{internals/retryLink.ts → retryLink.ts} +32 -6
- package/src/links.ts +1 -1
- package/dist/links/internals/retryLink.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 21.
|
|
2
|
+
"bundleSize": 65771,
|
|
3
|
+
"bundleOrigSize": 83372,
|
|
4
|
+
"bundleReduction": 21.11,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/links/wsLink.ts",
|
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
],
|
|
14
14
|
"removedExports": [],
|
|
15
15
|
"dependents": [],
|
|
16
|
-
"percent":
|
|
16
|
+
"percent": 27.39,
|
|
17
17
|
"reduction": 10.3
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
"id": "/src/links/httpSubscriptionLink.ts",
|
|
21
|
-
"size":
|
|
22
|
-
"origSize":
|
|
21
|
+
"size": 7889,
|
|
22
|
+
"origSize": 7756,
|
|
23
23
|
"renderedExports": [
|
|
24
24
|
"unstable_httpSubscriptionLink"
|
|
25
25
|
],
|
|
26
26
|
"removedExports": [],
|
|
27
27
|
"dependents": [],
|
|
28
|
-
"percent":
|
|
28
|
+
"percent": 11.99,
|
|
29
29
|
"reduction": 0
|
|
30
30
|
},
|
|
31
31
|
{
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
],
|
|
38
38
|
"removedExports": [],
|
|
39
39
|
"dependents": [],
|
|
40
|
-
"percent": 9.
|
|
40
|
+
"percent": 9.13,
|
|
41
41
|
"reduction": 4.42
|
|
42
42
|
},
|
|
43
43
|
{
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"removedExports": [],
|
|
51
51
|
"dependents": [],
|
|
52
|
-
"percent": 8.
|
|
52
|
+
"percent": 8.51,
|
|
53
53
|
"reduction": 19.44
|
|
54
54
|
},
|
|
55
55
|
{
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"/src/links/httpBatchLink.ts",
|
|
65
65
|
"/src/links/httpBatchStreamLink.ts"
|
|
66
66
|
],
|
|
67
|
-
"percent": 6.
|
|
67
|
+
"percent": 6.21,
|
|
68
68
|
"reduction": 5.64
|
|
69
69
|
},
|
|
70
70
|
{
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
],
|
|
77
77
|
"removedExports": [],
|
|
78
78
|
"dependents": [],
|
|
79
|
-
"percent":
|
|
79
|
+
"percent": 5.99,
|
|
80
80
|
"reduction": 5.59
|
|
81
81
|
},
|
|
82
82
|
{
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"/src/links/httpBatchStreamLink.ts",
|
|
100
100
|
"/src/links/httpSubscriptionLink.ts"
|
|
101
101
|
],
|
|
102
|
-
"percent": 5.
|
|
102
|
+
"percent": 5.61,
|
|
103
103
|
"reduction": 37.14
|
|
104
104
|
},
|
|
105
105
|
{
|
|
@@ -111,13 +111,13 @@
|
|
|
111
111
|
],
|
|
112
112
|
"removedExports": [],
|
|
113
113
|
"dependents": [],
|
|
114
|
-
"percent":
|
|
114
|
+
"percent": 4.83,
|
|
115
115
|
"reduction": 14.24
|
|
116
116
|
},
|
|
117
117
|
{
|
|
118
118
|
"id": "/src/internals/TRPCUntypedClient.ts",
|
|
119
|
-
"size":
|
|
120
|
-
"origSize":
|
|
119
|
+
"size": 2865,
|
|
120
|
+
"origSize": 4578,
|
|
121
121
|
"renderedExports": [
|
|
122
122
|
"TRPCUntypedClient"
|
|
123
123
|
],
|
|
@@ -126,8 +126,8 @@
|
|
|
126
126
|
"/src/createTRPCUntypedClient.ts",
|
|
127
127
|
"/src/createTRPCClient.ts"
|
|
128
128
|
],
|
|
129
|
-
"percent": 4.
|
|
130
|
-
"reduction": 37.
|
|
129
|
+
"percent": 4.36,
|
|
130
|
+
"reduction": 37.42
|
|
131
131
|
},
|
|
132
132
|
{
|
|
133
133
|
"id": "/src/TRPCClientError.ts",
|
|
@@ -146,20 +146,20 @@
|
|
|
146
146
|
"/src/links/httpSubscriptionLink.ts",
|
|
147
147
|
"/src/internals/TRPCUntypedClient.ts"
|
|
148
148
|
],
|
|
149
|
-
"percent": 3.
|
|
149
|
+
"percent": 3.79,
|
|
150
150
|
"reduction": 29.97
|
|
151
151
|
},
|
|
152
152
|
{
|
|
153
|
-
"id": "/src/links/
|
|
154
|
-
"size":
|
|
155
|
-
"origSize":
|
|
153
|
+
"id": "/src/links/retryLink.ts",
|
|
154
|
+
"size": 2194,
|
|
155
|
+
"origSize": 2702,
|
|
156
156
|
"renderedExports": [
|
|
157
157
|
"retryLink"
|
|
158
158
|
],
|
|
159
159
|
"removedExports": [],
|
|
160
160
|
"dependents": [],
|
|
161
|
-
"percent":
|
|
162
|
-
"reduction":
|
|
161
|
+
"percent": 3.34,
|
|
162
|
+
"reduction": 18.8
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
165
|
"id": "/src/internals/signals.ts",
|
|
@@ -175,13 +175,13 @@
|
|
|
175
175
|
"/src/links/httpBatchStreamLink.ts",
|
|
176
176
|
"/src/links/httpSubscriptionLink.ts"
|
|
177
177
|
],
|
|
178
|
-
"percent": 1.
|
|
178
|
+
"percent": 1.81,
|
|
179
179
|
"reduction": 3.88
|
|
180
180
|
},
|
|
181
181
|
{
|
|
182
182
|
"id": "/src/createTRPCClient.ts",
|
|
183
183
|
"size": 1185,
|
|
184
|
-
"origSize":
|
|
184
|
+
"origSize": 4477,
|
|
185
185
|
"renderedExports": [
|
|
186
186
|
"clientCallTypeToProcedureType",
|
|
187
187
|
"createTRPCClientProxy",
|
|
@@ -192,8 +192,8 @@
|
|
|
192
192
|
"dependents": [
|
|
193
193
|
"/src/index.ts"
|
|
194
194
|
],
|
|
195
|
-
"percent": 1.
|
|
196
|
-
"reduction": 73.
|
|
195
|
+
"percent": 1.8,
|
|
196
|
+
"reduction": 73.53
|
|
197
197
|
},
|
|
198
198
|
{
|
|
199
199
|
"id": "/src/links/internals/createChain.ts",
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
"/src/links/splitLink.ts",
|
|
208
208
|
"/src/internals/TRPCUntypedClient.ts"
|
|
209
209
|
],
|
|
210
|
-
"percent": 1.
|
|
210
|
+
"percent": 1.05,
|
|
211
211
|
"reduction": 32.75
|
|
212
212
|
},
|
|
213
213
|
{
|
|
@@ -219,7 +219,7 @@
|
|
|
219
219
|
],
|
|
220
220
|
"removedExports": [],
|
|
221
221
|
"dependents": [],
|
|
222
|
-
"percent": 0.
|
|
222
|
+
"percent": 0.93,
|
|
223
223
|
"reduction": 44.95
|
|
224
224
|
},
|
|
225
225
|
{
|
|
@@ -233,7 +233,7 @@
|
|
|
233
233
|
"dependents": [
|
|
234
234
|
"/src/unstable-internals.ts"
|
|
235
235
|
],
|
|
236
|
-
"percent": 0.
|
|
236
|
+
"percent": 0.86,
|
|
237
237
|
"reduction": 66.71
|
|
238
238
|
},
|
|
239
239
|
{
|
|
@@ -248,7 +248,7 @@
|
|
|
248
248
|
"/src/index.ts",
|
|
249
249
|
"/src/links/internals/httpUtils.ts"
|
|
250
250
|
],
|
|
251
|
-
"percent": 0.
|
|
251
|
+
"percent": 0.65,
|
|
252
252
|
"reduction": 33.54
|
|
253
253
|
},
|
|
254
254
|
{
|
|
@@ -262,9 +262,24 @@
|
|
|
262
262
|
],
|
|
263
263
|
"removedExports": [],
|
|
264
264
|
"dependents": [],
|
|
265
|
-
"percent": 0.
|
|
265
|
+
"percent": 0.5,
|
|
266
266
|
"reduction": 15.17
|
|
267
267
|
},
|
|
268
|
+
{
|
|
269
|
+
"id": "/src/internals/inputWithTrackedEventId.ts",
|
|
270
|
+
"size": 254,
|
|
271
|
+
"origSize": 273,
|
|
272
|
+
"renderedExports": [
|
|
273
|
+
"inputWithTrackedEventId"
|
|
274
|
+
],
|
|
275
|
+
"removedExports": [],
|
|
276
|
+
"dependents": [
|
|
277
|
+
"/src/links/httpSubscriptionLink.ts",
|
|
278
|
+
"/src/links/retryLink.ts"
|
|
279
|
+
],
|
|
280
|
+
"percent": 0.39,
|
|
281
|
+
"reduction": 6.96
|
|
282
|
+
},
|
|
268
283
|
{
|
|
269
284
|
"id": "/src/links/internals/urlWithConnectionParams.ts",
|
|
270
285
|
"size": 240,
|
|
@@ -277,7 +292,7 @@
|
|
|
277
292
|
"/src/links/wsLink.ts",
|
|
278
293
|
"/src/links/httpSubscriptionLink.ts"
|
|
279
294
|
],
|
|
280
|
-
"percent": 0.
|
|
295
|
+
"percent": 0.36,
|
|
281
296
|
"reduction": 76.38
|
|
282
297
|
},
|
|
283
298
|
{
|
|
@@ -292,7 +307,7 @@
|
|
|
292
307
|
"/src/TRPCClientError.ts",
|
|
293
308
|
"/src/internals/TRPCUntypedClient.ts"
|
|
294
309
|
],
|
|
295
|
-
"percent": 0.
|
|
310
|
+
"percent": 0.35,
|
|
296
311
|
"reduction": 13.36
|
|
297
312
|
},
|
|
298
313
|
{
|
|
@@ -306,7 +321,7 @@
|
|
|
306
321
|
"dependents": [
|
|
307
322
|
"/src/index.ts"
|
|
308
323
|
],
|
|
309
|
-
"percent": 0.
|
|
324
|
+
"percent": 0.15,
|
|
310
325
|
"reduction": 82.58
|
|
311
326
|
},
|
|
312
327
|
{
|
|
@@ -334,5 +349,5 @@
|
|
|
334
349
|
"reduction": 100
|
|
335
350
|
}
|
|
336
351
|
],
|
|
337
|
-
"moduleCount":
|
|
352
|
+
"moduleCount": 24
|
|
338
353
|
}
|
|
@@ -16,7 +16,7 @@ type ResolverDef = {
|
|
|
16
16
|
};
|
|
17
17
|
/** @internal */
|
|
18
18
|
export type Resolver<TDef extends ResolverDef> = (input: TDef['input'], opts?: ProcedureOptions) => Promise<TDef['output']>;
|
|
19
|
-
type SubscriptionResolver<TDef extends ResolverDef> = (input: TDef['input'], opts
|
|
19
|
+
type SubscriptionResolver<TDef extends ResolverDef> = (input: TDef['input'], opts: Partial<TRPCSubscriptionObserver<TDef['output'], TRPCClientError<TDef>>> & ProcedureOptions) => Unsubscribable;
|
|
20
20
|
type DecorateProcedure<TType extends ProcedureType, TDef extends ResolverDef> = TType extends 'query' ? {
|
|
21
21
|
query: Resolver<TDef>;
|
|
22
22
|
} : TType extends 'mutation' ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"","sources":["../src/createTRPCClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBA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,EAC7D,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,gBAAgB,CAAC,OAAO,CAAC,CAoB3B;AAED,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,GACrC,gBAAgB,CAAC,OAAO,CAAC,CAI3B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,iBAAiB,CAAC,OAAO,CAAC,CAE5B"}
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var loggerLink = require('./links/loggerLink.js');
|
|
|
12
12
|
var splitLink = require('./links/splitLink.js');
|
|
13
13
|
var wsLink = require('./links/wsLink.js');
|
|
14
14
|
var httpSubscriptionLink = require('./links/httpSubscriptionLink.js');
|
|
15
|
-
var retryLink = require('./links/
|
|
15
|
+
var retryLink = require('./links/retryLink.js');
|
|
16
16
|
var TRPCUntypedClient = require('./internals/TRPCUntypedClient.js');
|
|
17
17
|
|
|
18
18
|
|
package/dist/index.mjs
CHANGED
|
@@ -10,5 +10,5 @@ export { loggerLink } from './links/loggerLink.mjs';
|
|
|
10
10
|
export { splitLink } from './links/splitLink.mjs';
|
|
11
11
|
export { createWSClient, wsLink } from './links/wsLink.mjs';
|
|
12
12
|
export { unstable_httpSubscriptionLink } from './links/httpSubscriptionLink.mjs';
|
|
13
|
-
export { retryLink } from './links/
|
|
13
|
+
export { retryLink } from './links/retryLink.mjs';
|
|
14
14
|
export { TRPCUntypedClient } from './internals/TRPCUntypedClient.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputWithTrackedEventId.d.ts","sourceRoot":"","sources":["../../src/internals/inputWithTrackedEventId.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,MAAM,GAAG,SAAS,WAYhC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function inputWithTrackedEventId(input, lastEventId) {
|
|
4
|
+
if (!lastEventId) {
|
|
5
|
+
return input;
|
|
6
|
+
}
|
|
7
|
+
if (input != null && typeof input !== 'object') {
|
|
8
|
+
return input;
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
...input ?? {},
|
|
12
|
+
lastEventId
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.inputWithTrackedEventId = inputWithTrackedEventId;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function inputWithTrackedEventId(input, lastEventId) {
|
|
2
|
+
if (!lastEventId) {
|
|
3
|
+
return input;
|
|
4
|
+
}
|
|
5
|
+
if (input != null && typeof input !== 'object') {
|
|
6
|
+
return input;
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
...input ?? {},
|
|
10
|
+
lastEventId
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { inputWithTrackedEventId };
|
|
@@ -13,6 +13,10 @@ type HTTPSubscriptionLinkOptions<TRoot extends AnyClientTypes, TEventSource exte
|
|
|
13
13
|
eventSourceOptions?: EventSourceLike.InitDictOf<TEventSource> | ((opts: {
|
|
14
14
|
op: Operation;
|
|
15
15
|
}) => EventSourceLike.InitDictOf<TEventSource> | Promise<EventSourceLike.InitDictOf<TEventSource>>);
|
|
16
|
+
/**
|
|
17
|
+
* Timeout after inactivity in milliseconds
|
|
18
|
+
*/
|
|
19
|
+
reconnectAfterInactivityMs?: number;
|
|
16
20
|
} & TransformerOptions<TRoot> & UrlOptionsWithConnectionParams;
|
|
17
21
|
/**
|
|
18
22
|
* @see https://trpc.io/docs/client/links/httpSubscriptionLink
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpSubscriptionLink.d.ts","sourceRoot":"","sources":["../../src/links/httpSubscriptionLink.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"httpSubscriptionLink.d.ts","sourceRoot":"","sources":["../../src/links/httpSubscriptionLink.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,0CAA0C,CAAC;AASlD,OAAO,EAAkB,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAiBnD,KAAK,2BAA2B,CAC9B,KAAK,SAAS,cAAc,EAC5B,YAAY,SAAS,eAAe,CAAC,cAAc,GAAG,OAAO,WAAW,IACtE;IACF;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,kBAAkB,CAAC,EACf,eAAe,CAAC,UAAU,CAAC,YAAY,CAAC,GACxC,CAAC,CAAC,IAAI,EAAE;QACN,EAAE,EAAE,SAAS,CAAC;KACf,KACG,eAAe,CAAC,UAAU,CAAC,YAAY,CAAC,GACxC,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3D;;OAEG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAC3B,8BAA8B,CAAC;AAajC;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,SAAS,qBAAqB,EACzC,YAAY,SAAS,eAAe,CAAC,cAAc,EAEnD,IAAI,EAAE,2BAA2B,CAC/B,gBAAgB,CAAC,WAAW,CAAC,EAC7B,YAAY,CACb,GACA,QAAQ,CAAC,WAAW,CAAC,CAoKvB"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var observable = require('@trpc/server/observable');
|
|
4
4
|
var rpc = require('@trpc/server/rpc');
|
|
5
5
|
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
6
|
+
var inputWithTrackedEventId = require('../internals/inputWithTrackedEventId.js');
|
|
6
7
|
var signals = require('../internals/signals.js');
|
|
7
8
|
var TRPCClientError = require('../TRPCClientError.js');
|
|
8
9
|
var transformer = require('../internals/transformer.js');
|
|
@@ -38,13 +39,14 @@ async function urlWithConnectionParams(opts) {
|
|
|
38
39
|
/* istanbul ignore if -- @preserve */ if (type !== 'subscription') {
|
|
39
40
|
throw new Error('httpSubscriptionLink only supports subscriptions');
|
|
40
41
|
}
|
|
42
|
+
let lastEventId = undefined;
|
|
41
43
|
const ac = new AbortController();
|
|
42
44
|
const signal = signals.raceAbortSignals(op.signal, ac.signal);
|
|
43
45
|
const eventSourceStream = unstableCoreDoNotImport.sseStreamConsumer({
|
|
44
46
|
url: async ()=>httpUtils.getUrl({
|
|
45
47
|
transformer: transformer$1,
|
|
46
48
|
url: await urlWithConnectionParams(opts),
|
|
47
|
-
input,
|
|
49
|
+
input: inputWithTrackedEventId.inputWithTrackedEventId(input, lastEventId),
|
|
48
50
|
path,
|
|
49
51
|
type,
|
|
50
52
|
signal: null
|
|
@@ -54,7 +56,8 @@ async function urlWithConnectionParams(opts) {
|
|
|
54
56
|
}),
|
|
55
57
|
signal,
|
|
56
58
|
deserialize: transformer$1.output.deserialize,
|
|
57
|
-
EventSource: opts.EventSource ?? globalThis.EventSource
|
|
59
|
+
EventSource: opts.EventSource ?? globalThis.EventSource,
|
|
60
|
+
reconnectAfterInactivityMs: opts.reconnectAfterInactivityMs
|
|
58
61
|
});
|
|
59
62
|
const connectionState = observable.behaviorSubject({
|
|
60
63
|
type: 'state',
|
|
@@ -71,14 +74,25 @@ async function urlWithConnectionParams(opts) {
|
|
|
71
74
|
unstableCoreDoNotImport.run(async ()=>{
|
|
72
75
|
for await (const chunk of eventSourceStream){
|
|
73
76
|
switch(chunk.type){
|
|
77
|
+
case 'ping':
|
|
78
|
+
break;
|
|
74
79
|
case 'data':
|
|
75
80
|
const chunkData = chunk.data;
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
let result;
|
|
82
|
+
if (chunkData.id) {
|
|
83
|
+
// if the `tracked()`-helper is used, we always have an `id` field
|
|
84
|
+
lastEventId = chunkData.id;
|
|
85
|
+
result = {
|
|
86
|
+
id: chunkData.id,
|
|
87
|
+
data: chunkData
|
|
88
|
+
};
|
|
89
|
+
} else {
|
|
90
|
+
result = {
|
|
91
|
+
data: chunkData.data
|
|
92
|
+
};
|
|
93
|
+
}
|
|
78
94
|
observer.next({
|
|
79
|
-
result
|
|
80
|
-
data
|
|
81
|
-
},
|
|
95
|
+
result,
|
|
82
96
|
context: {
|
|
83
97
|
eventSource: chunk.eventSource
|
|
84
98
|
}
|
|
@@ -133,6 +147,14 @@ async function urlWithConnectionParams(opts) {
|
|
|
133
147
|
});
|
|
134
148
|
break;
|
|
135
149
|
}
|
|
150
|
+
case 'timeout':
|
|
151
|
+
{
|
|
152
|
+
connectionState.next({
|
|
153
|
+
type: 'state',
|
|
154
|
+
state: 'connecting',
|
|
155
|
+
error: new TRPCClientError.TRPCClientError(`Timeout of ${opts.reconnectAfterInactivityMs}ms reached while waiting for a response`)
|
|
156
|
+
});
|
|
157
|
+
}
|
|
136
158
|
}
|
|
137
159
|
}
|
|
138
160
|
observer.next({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { observable, behaviorSubject } from '@trpc/server/observable';
|
|
2
2
|
import { TRPC_ERROR_CODES_BY_KEY } from '@trpc/server/rpc';
|
|
3
3
|
import { sseStreamConsumer, run } from '@trpc/server/unstable-core-do-not-import';
|
|
4
|
+
import { inputWithTrackedEventId } from '../internals/inputWithTrackedEventId.mjs';
|
|
4
5
|
import { raceAbortSignals } from '../internals/signals.mjs';
|
|
5
6
|
import { TRPCClientError } from '../TRPCClientError.mjs';
|
|
6
7
|
import { getTransformer } from '../internals/transformer.mjs';
|
|
@@ -36,13 +37,14 @@ async function urlWithConnectionParams(opts) {
|
|
|
36
37
|
/* istanbul ignore if -- @preserve */ if (type !== 'subscription') {
|
|
37
38
|
throw new Error('httpSubscriptionLink only supports subscriptions');
|
|
38
39
|
}
|
|
40
|
+
let lastEventId = undefined;
|
|
39
41
|
const ac = new AbortController();
|
|
40
42
|
const signal = raceAbortSignals(op.signal, ac.signal);
|
|
41
43
|
const eventSourceStream = sseStreamConsumer({
|
|
42
44
|
url: async ()=>getUrl({
|
|
43
45
|
transformer,
|
|
44
46
|
url: await urlWithConnectionParams(opts),
|
|
45
|
-
input,
|
|
47
|
+
input: inputWithTrackedEventId(input, lastEventId),
|
|
46
48
|
path,
|
|
47
49
|
type,
|
|
48
50
|
signal: null
|
|
@@ -52,7 +54,8 @@ async function urlWithConnectionParams(opts) {
|
|
|
52
54
|
}),
|
|
53
55
|
signal,
|
|
54
56
|
deserialize: transformer.output.deserialize,
|
|
55
|
-
EventSource: opts.EventSource ?? globalThis.EventSource
|
|
57
|
+
EventSource: opts.EventSource ?? globalThis.EventSource,
|
|
58
|
+
reconnectAfterInactivityMs: opts.reconnectAfterInactivityMs
|
|
56
59
|
});
|
|
57
60
|
const connectionState = behaviorSubject({
|
|
58
61
|
type: 'state',
|
|
@@ -69,14 +72,25 @@ async function urlWithConnectionParams(opts) {
|
|
|
69
72
|
run(async ()=>{
|
|
70
73
|
for await (const chunk of eventSourceStream){
|
|
71
74
|
switch(chunk.type){
|
|
75
|
+
case 'ping':
|
|
76
|
+
break;
|
|
72
77
|
case 'data':
|
|
73
78
|
const chunkData = chunk.data;
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
let result;
|
|
80
|
+
if (chunkData.id) {
|
|
81
|
+
// if the `tracked()`-helper is used, we always have an `id` field
|
|
82
|
+
lastEventId = chunkData.id;
|
|
83
|
+
result = {
|
|
84
|
+
id: chunkData.id,
|
|
85
|
+
data: chunkData
|
|
86
|
+
};
|
|
87
|
+
} else {
|
|
88
|
+
result = {
|
|
89
|
+
data: chunkData.data
|
|
90
|
+
};
|
|
91
|
+
}
|
|
76
92
|
observer.next({
|
|
77
|
-
result
|
|
78
|
-
data
|
|
79
|
-
},
|
|
93
|
+
result,
|
|
80
94
|
context: {
|
|
81
95
|
eventSource: chunk.eventSource
|
|
82
96
|
}
|
|
@@ -131,6 +145,14 @@ async function urlWithConnectionParams(opts) {
|
|
|
131
145
|
});
|
|
132
146
|
break;
|
|
133
147
|
}
|
|
148
|
+
case 'timeout':
|
|
149
|
+
{
|
|
150
|
+
connectionState.next({
|
|
151
|
+
type: 'state',
|
|
152
|
+
state: 'connecting',
|
|
153
|
+
error: new TRPCClientError(`Timeout of ${opts.reconnectAfterInactivityMs}ms reached while waiting for a response`)
|
|
154
|
+
});
|
|
155
|
+
}
|
|
134
156
|
}
|
|
135
157
|
}
|
|
136
158
|
observer.next({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { InferrableClientTypes } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
-
import type { TRPCClientError } from '
|
|
3
|
-
import type { Operation, TRPCLink } from '
|
|
2
|
+
import type { TRPCClientError } from '../TRPCClientError';
|
|
3
|
+
import type { Operation, TRPCLink } from './types';
|
|
4
4
|
interface RetryLinkOptions<TInferrable extends InferrableClientTypes> {
|
|
5
5
|
/**
|
|
6
6
|
* The retry function
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryLink.d.ts","sourceRoot":"","sources":["../../src/links/retryLink.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAEtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnD,UAAU,gBAAgB,CAAC,WAAW,SAAS,qBAAqB;IAClE;;OAEG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,WAAW,CAAC,KAAK,OAAO,CAAC;CACvD;AAED,UAAU,cAAc,CAAC,WAAW,SAAS,qBAAqB;IAChE;;OAEG;IACH,EAAE,EAAE,SAAS,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC;IACpC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,WAAW,SAAS,qBAAqB,EACjE,IAAI,EAAE,gBAAgB,CAAC,WAAW,CAAC,GAClC,QAAQ,CAAC,WAAW,CAAC,CAgEvB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var observable = require('@trpc/server/observable');
|
|
4
|
+
var inputWithTrackedEventId = require('../internals/inputWithTrackedEventId.js');
|
|
4
5
|
|
|
5
6
|
/* istanbul ignore file -- @preserve */ // We're not actually exporting this link
|
|
6
7
|
/**
|
|
@@ -9,13 +10,25 @@ var observable = require('@trpc/server/observable');
|
|
|
9
10
|
// initialized config
|
|
10
11
|
return ()=>{
|
|
11
12
|
// initialized in app
|
|
12
|
-
return (
|
|
13
|
+
return (callOpts)=>{
|
|
13
14
|
// initialized for request
|
|
14
15
|
return observable.observable((observer)=>{
|
|
15
16
|
let next$;
|
|
17
|
+
let lastEventId = undefined;
|
|
16
18
|
attempt(1);
|
|
19
|
+
function opWithLastEventId() {
|
|
20
|
+
const op = callOpts.op;
|
|
21
|
+
if (!lastEventId) {
|
|
22
|
+
return op;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
...op,
|
|
26
|
+
input: inputWithTrackedEventId.inputWithTrackedEventId(op.input, lastEventId)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
17
29
|
function attempt(attempts) {
|
|
18
|
-
|
|
30
|
+
const op = opWithLastEventId();
|
|
31
|
+
next$ = callOpts.next(op).subscribe({
|
|
19
32
|
error (error) {
|
|
20
33
|
const shouldRetry = opts.retry({
|
|
21
34
|
op,
|
|
@@ -28,8 +41,13 @@ var observable = require('@trpc/server/observable');
|
|
|
28
41
|
observer.error(error);
|
|
29
42
|
}
|
|
30
43
|
},
|
|
31
|
-
next (
|
|
32
|
-
|
|
44
|
+
next (envelope) {
|
|
45
|
+
//
|
|
46
|
+
if ((!envelope.result.type || envelope.result.type === 'data') && envelope.result.id) {
|
|
47
|
+
//
|
|
48
|
+
lastEventId = envelope.result.id;
|
|
49
|
+
}
|
|
50
|
+
observer.next(envelope);
|
|
33
51
|
},
|
|
34
52
|
complete () {
|
|
35
53
|
observer.complete();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { observable } from '@trpc/server/observable';
|
|
2
|
+
import { inputWithTrackedEventId } from '../internals/inputWithTrackedEventId.mjs';
|
|
2
3
|
|
|
3
4
|
/* istanbul ignore file -- @preserve */ // We're not actually exporting this link
|
|
4
5
|
/**
|
|
@@ -7,13 +8,25 @@ import { observable } from '@trpc/server/observable';
|
|
|
7
8
|
// initialized config
|
|
8
9
|
return ()=>{
|
|
9
10
|
// initialized in app
|
|
10
|
-
return (
|
|
11
|
+
return (callOpts)=>{
|
|
11
12
|
// initialized for request
|
|
12
13
|
return observable((observer)=>{
|
|
13
14
|
let next$;
|
|
15
|
+
let lastEventId = undefined;
|
|
14
16
|
attempt(1);
|
|
17
|
+
function opWithLastEventId() {
|
|
18
|
+
const op = callOpts.op;
|
|
19
|
+
if (!lastEventId) {
|
|
20
|
+
return op;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
...op,
|
|
24
|
+
input: inputWithTrackedEventId(op.input, lastEventId)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
15
27
|
function attempt(attempts) {
|
|
16
|
-
|
|
28
|
+
const op = opWithLastEventId();
|
|
29
|
+
next$ = callOpts.next(op).subscribe({
|
|
17
30
|
error (error) {
|
|
18
31
|
const shouldRetry = opts.retry({
|
|
19
32
|
op,
|
|
@@ -26,8 +39,13 @@ import { observable } from '@trpc/server/observable';
|
|
|
26
39
|
observer.error(error);
|
|
27
40
|
}
|
|
28
41
|
},
|
|
29
|
-
next (
|
|
30
|
-
|
|
42
|
+
next (envelope) {
|
|
43
|
+
//
|
|
44
|
+
if ((!envelope.result.type || envelope.result.type === 'data') && envelope.result.id) {
|
|
45
|
+
//
|
|
46
|
+
lastEventId = envelope.result.id;
|
|
47
|
+
}
|
|
48
|
+
observer.next(envelope);
|
|
31
49
|
},
|
|
32
50
|
complete () {
|
|
33
51
|
observer.complete();
|
package/dist/links.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export * from './links/loggerLink';
|
|
|
7
7
|
export * from './links/splitLink';
|
|
8
8
|
export * from './links/wsLink';
|
|
9
9
|
export * from './links/httpSubscriptionLink';
|
|
10
|
-
export * from './links/
|
|
10
|
+
export * from './links/retryLink';
|
|
11
11
|
//# sourceMappingURL=links.d.ts.map
|
package/dist/links.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "11.0.0-rc.
|
|
3
|
+
"version": "11.0.0-rc.633+55512768a",
|
|
4
4
|
"description": "The tRPC client library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,17 +76,17 @@
|
|
|
76
76
|
"!**/*.test.*"
|
|
77
77
|
],
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@trpc/server": "11.0.0-rc.
|
|
79
|
+
"@trpc/server": "11.0.0-rc.633+55512768a"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@trpc/server": "11.0.0-rc.
|
|
82
|
+
"@trpc/server": "11.0.0-rc.633+55512768a",
|
|
83
83
|
"@types/isomorphic-fetch": "^0.0.39",
|
|
84
84
|
"@types/node": "^22.9.0",
|
|
85
85
|
"eslint": "^9.13.0",
|
|
86
86
|
"isomorphic-fetch": "^3.0.0",
|
|
87
87
|
"node-fetch": "^3.3.0",
|
|
88
88
|
"rollup": "^4.24.4",
|
|
89
|
-
"tslib": "^2.
|
|
89
|
+
"tslib": "^2.8.1",
|
|
90
90
|
"tsx": "^4.0.0",
|
|
91
91
|
"undici": "^6.0.1"
|
|
92
92
|
},
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"funding": [
|
|
97
97
|
"https://trpc.io/sponsor"
|
|
98
98
|
],
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "55512768ac9e57c472c9b03d8e39f606a8c1e1c6"
|
|
100
100
|
}
|
package/src/createTRPCClient.ts
CHANGED
|
@@ -44,7 +44,7 @@ export type Resolver<TDef extends ResolverDef> = (
|
|
|
44
44
|
|
|
45
45
|
type SubscriptionResolver<TDef extends ResolverDef> = (
|
|
46
46
|
input: TDef['input'],
|
|
47
|
-
opts
|
|
47
|
+
opts: Partial<
|
|
48
48
|
TRPCSubscriptionObserver<TDef['output'], TRPCClientError<TDef>>
|
|
49
49
|
> &
|
|
50
50
|
ProcedureOptions,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function inputWithTrackedEventId(
|
|
2
|
+
input: unknown,
|
|
3
|
+
lastEventId: string | undefined,
|
|
4
|
+
) {
|
|
5
|
+
if (!lastEventId) {
|
|
6
|
+
return input;
|
|
7
|
+
}
|
|
8
|
+
if (input != null && typeof input !== 'object') {
|
|
9
|
+
return input;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
...(input ?? {}),
|
|
13
|
+
lastEventId,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { behaviorSubject, observable } from '@trpc/server/observable';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
TRPC_ERROR_CODE_NUMBER,
|
|
4
|
+
TRPCErrorShape,
|
|
5
|
+
TRPCResult,
|
|
6
|
+
} from '@trpc/server/rpc';
|
|
3
7
|
import { TRPC_ERROR_CODES_BY_KEY } from '@trpc/server/rpc';
|
|
4
8
|
import type {
|
|
5
9
|
AnyClientTypes,
|
|
@@ -11,6 +15,7 @@ import {
|
|
|
11
15
|
run,
|
|
12
16
|
sseStreamConsumer,
|
|
13
17
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
18
|
+
import { inputWithTrackedEventId } from '../internals/inputWithTrackedEventId';
|
|
14
19
|
import { raceAbortSignals } from '../internals/signals';
|
|
15
20
|
import { TRPCClientError } from '../TRPCClientError';
|
|
16
21
|
import type { TRPCConnectionState } from '../unstable-internals';
|
|
@@ -55,6 +60,10 @@ type HTTPSubscriptionLinkOptions<
|
|
|
55
60
|
}) =>
|
|
56
61
|
| EventSourceLike.InitDictOf<TEventSource>
|
|
57
62
|
| Promise<EventSourceLike.InitDictOf<TEventSource>>);
|
|
63
|
+
/**
|
|
64
|
+
* Timeout after inactivity in milliseconds
|
|
65
|
+
*/
|
|
66
|
+
reconnectAfterInactivityMs?: number;
|
|
58
67
|
} & TransformerOptions<TRoot> &
|
|
59
68
|
UrlOptionsWithConnectionParams;
|
|
60
69
|
|
|
@@ -93,6 +102,7 @@ export function unstable_httpSubscriptionLink<
|
|
|
93
102
|
throw new Error('httpSubscriptionLink only supports subscriptions');
|
|
94
103
|
}
|
|
95
104
|
|
|
105
|
+
let lastEventId: string | undefined = undefined;
|
|
96
106
|
const ac = new AbortController();
|
|
97
107
|
const signal = raceAbortSignals(op.signal, ac.signal);
|
|
98
108
|
const eventSourceStream = sseStreamConsumer<{
|
|
@@ -107,7 +117,7 @@ export function unstable_httpSubscriptionLink<
|
|
|
107
117
|
getUrl({
|
|
108
118
|
transformer,
|
|
109
119
|
url: await urlWithConnectionParams(opts),
|
|
110
|
-
input,
|
|
120
|
+
input: inputWithTrackedEventId(input, lastEventId),
|
|
111
121
|
path,
|
|
112
122
|
type,
|
|
113
123
|
signal: null,
|
|
@@ -118,6 +128,7 @@ export function unstable_httpSubscriptionLink<
|
|
|
118
128
|
EventSource:
|
|
119
129
|
opts.EventSource ??
|
|
120
130
|
(globalThis.EventSource as never as TEventSource),
|
|
131
|
+
reconnectAfterInactivityMs: opts.reconnectAfterInactivityMs,
|
|
121
132
|
});
|
|
122
133
|
|
|
123
134
|
const connectionState = behaviorSubject<
|
|
@@ -138,16 +149,28 @@ export function unstable_httpSubscriptionLink<
|
|
|
138
149
|
run(async () => {
|
|
139
150
|
for await (const chunk of eventSourceStream) {
|
|
140
151
|
switch (chunk.type) {
|
|
152
|
+
case 'ping':
|
|
153
|
+
// do nothing
|
|
154
|
+
break;
|
|
141
155
|
case 'data':
|
|
142
156
|
const chunkData = chunk.data;
|
|
143
157
|
|
|
144
|
-
|
|
145
|
-
|
|
158
|
+
let result: TRPCResult<unknown>;
|
|
159
|
+
if (chunkData.id) {
|
|
160
|
+
// if the `tracked()`-helper is used, we always have an `id` field
|
|
161
|
+
lastEventId = chunkData.id;
|
|
162
|
+
result = {
|
|
163
|
+
id: chunkData.id,
|
|
164
|
+
data: chunkData,
|
|
165
|
+
};
|
|
166
|
+
} else {
|
|
167
|
+
result = {
|
|
168
|
+
data: chunkData.data,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
146
171
|
|
|
147
172
|
observer.next({
|
|
148
|
-
result
|
|
149
|
-
data,
|
|
150
|
-
},
|
|
173
|
+
result,
|
|
151
174
|
context: {
|
|
152
175
|
eventSource: chunk.eventSource,
|
|
153
176
|
},
|
|
@@ -200,6 +223,15 @@ export function unstable_httpSubscriptionLink<
|
|
|
200
223
|
});
|
|
201
224
|
break;
|
|
202
225
|
}
|
|
226
|
+
case 'timeout': {
|
|
227
|
+
connectionState.next({
|
|
228
|
+
type: 'state',
|
|
229
|
+
state: 'connecting',
|
|
230
|
+
error: new TRPCClientError(
|
|
231
|
+
`Timeout of ${opts.reconnectAfterInactivityMs}ms reached while waiting for a response`,
|
|
232
|
+
),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
203
235
|
}
|
|
204
236
|
}
|
|
205
237
|
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
import type { Unsubscribable } from '@trpc/server/observable';
|
|
4
4
|
import { observable } from '@trpc/server/observable';
|
|
5
5
|
import type { InferrableClientTypes } from '@trpc/server/unstable-core-do-not-import';
|
|
6
|
-
import
|
|
7
|
-
import type {
|
|
6
|
+
import { inputWithTrackedEventId } from '../internals/inputWithTrackedEventId';
|
|
7
|
+
import type { TRPCClientError } from '../TRPCClientError';
|
|
8
|
+
import type { Operation, TRPCLink } from './types';
|
|
8
9
|
|
|
9
10
|
interface RetryLinkOptions<TInferrable extends InferrableClientTypes> {
|
|
10
11
|
/**
|
|
@@ -37,15 +38,31 @@ export function retryLink<TInferrable extends InferrableClientTypes>(
|
|
|
37
38
|
// initialized config
|
|
38
39
|
return () => {
|
|
39
40
|
// initialized in app
|
|
40
|
-
return (
|
|
41
|
+
return (callOpts) => {
|
|
41
42
|
// initialized for request
|
|
42
43
|
return observable((observer) => {
|
|
43
44
|
let next$: Unsubscribable;
|
|
44
45
|
|
|
46
|
+
let lastEventId: string | undefined = undefined;
|
|
47
|
+
|
|
45
48
|
attempt(1);
|
|
46
49
|
|
|
50
|
+
function opWithLastEventId() {
|
|
51
|
+
const op = callOpts.op;
|
|
52
|
+
if (!lastEventId) {
|
|
53
|
+
return op;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
...op,
|
|
58
|
+
input: inputWithTrackedEventId(op.input, lastEventId),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
47
62
|
function attempt(attempts: number) {
|
|
48
|
-
|
|
63
|
+
const op = opWithLastEventId();
|
|
64
|
+
|
|
65
|
+
next$ = callOpts.next(op).subscribe({
|
|
49
66
|
error(error) {
|
|
50
67
|
const shouldRetry = opts.retry({
|
|
51
68
|
op,
|
|
@@ -58,8 +75,17 @@ export function retryLink<TInferrable extends InferrableClientTypes>(
|
|
|
58
75
|
observer.error(error);
|
|
59
76
|
}
|
|
60
77
|
},
|
|
61
|
-
next(
|
|
62
|
-
|
|
78
|
+
next(envelope) {
|
|
79
|
+
//
|
|
80
|
+
if (
|
|
81
|
+
(!envelope.result.type || envelope.result.type === 'data') &&
|
|
82
|
+
envelope.result.id
|
|
83
|
+
) {
|
|
84
|
+
//
|
|
85
|
+
lastEventId = envelope.result.id;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
observer.next(envelope);
|
|
63
89
|
},
|
|
64
90
|
complete() {
|
|
65
91
|
observer.complete();
|
package/src/links.ts
CHANGED
|
@@ -8,7 +8,7 @@ export * from './links/loggerLink';
|
|
|
8
8
|
export * from './links/splitLink';
|
|
9
9
|
export * from './links/wsLink';
|
|
10
10
|
export * from './links/httpSubscriptionLink';
|
|
11
|
-
export * from './links/
|
|
11
|
+
export * from './links/retryLink';
|
|
12
12
|
|
|
13
13
|
// These are not public (yet) as we get this functionality from tanstack query
|
|
14
14
|
// export * from './links/internals/dedupeLink';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retryLink.d.ts","sourceRoot":"","sources":["../../../src/links/internals/retryLink.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpD,UAAU,gBAAgB,CAAC,WAAW,SAAS,qBAAqB;IAClE;;OAEG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,WAAW,CAAC,KAAK,OAAO,CAAC;CACvD;AAED,UAAU,cAAc,CAAC,WAAW,SAAS,qBAAqB;IAChE;;OAEG;IACH,EAAE,EAAE,SAAS,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC;IACpC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,WAAW,SAAS,qBAAqB,EACjE,IAAI,EAAE,gBAAgB,CAAC,WAAW,CAAC,GAClC,QAAQ,CAAC,WAAW,CAAC,CAuCvB"}
|