@trpc/client 11.0.0-alpha-tmp-issues-5851-take-two.496 → 11.0.0-alpha-tmp-subscription-connection-state.485
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle-analysis.json +80 -63
- package/dist/index.js +6 -4
- package/dist/index.mjs +2 -1
- package/dist/internals/TRPCUntypedClient.d.ts +2 -1
- package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
- package/dist/internals/TRPCUntypedClient.js +2 -0
- package/dist/internals/TRPCUntypedClient.mjs +2 -0
- package/dist/links/httpSubscriptionLink.d.ts +3 -2
- package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
- package/dist/links/httpSubscriptionLink.js +53 -3
- package/dist/links/httpSubscriptionLink.mjs +53 -3
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/links/internals/httpUtils.js +28 -1
- package/dist/links/internals/httpUtils.mjs +28 -1
- package/dist/links/internals/urlWithConnectionParams.d.ts +1 -2
- package/dist/links/internals/urlWithConnectionParams.d.ts.map +1 -1
- package/dist/links/types.d.ts +23 -3
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/types.js +7 -0
- package/dist/links/types.mjs +5 -0
- package/dist/links/wsLink.d.ts +5 -3
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +86 -17
- package/dist/links/wsLink.mjs +86 -17
- package/package.json +4 -4
- package/src/internals/TRPCUntypedClient.ts +4 -0
- package/src/links/httpSubscriptionLink.ts +70 -5
- package/src/links/internals/httpUtils.ts +35 -1
- package/src/links/internals/urlWithConnectionParams.ts +1 -1
- package/src/links/types.ts +48 -2
- package/src/links/wsLink.ts +108 -21
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 25.
|
|
2
|
+
"bundleSize": 57149,
|
|
3
|
+
"bundleOrigSize": 76725,
|
|
4
|
+
"bundleReduction": 25.51,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/links/wsLink.ts",
|
|
8
|
-
"size":
|
|
9
|
-
"origSize":
|
|
8
|
+
"size": 16017,
|
|
9
|
+
"origSize": 17038,
|
|
10
10
|
"renderedExports": [
|
|
11
11
|
"createWSClient",
|
|
12
12
|
"wsLink"
|
|
13
13
|
],
|
|
14
14
|
"removedExports": [],
|
|
15
15
|
"dependents": [],
|
|
16
|
-
"percent":
|
|
17
|
-
"reduction":
|
|
16
|
+
"percent": 28.03,
|
|
17
|
+
"reduction": 5.99
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
"id": "/src/links/httpBatchStreamLink.ts",
|
|
@@ -25,52 +25,37 @@
|
|
|
25
25
|
],
|
|
26
26
|
"removedExports": [],
|
|
27
27
|
"dependents": [],
|
|
28
|
-
"percent":
|
|
28
|
+
"percent": 10.26,
|
|
29
29
|
"reduction": 3.51
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
|
-
"id": "/src/links/
|
|
33
|
-
"size":
|
|
34
|
-
"origSize":
|
|
32
|
+
"id": "/src/links/httpSubscriptionLink.ts",
|
|
33
|
+
"size": 5727,
|
|
34
|
+
"origSize": 5459,
|
|
35
35
|
"renderedExports": [
|
|
36
|
-
"
|
|
36
|
+
"unstable_httpSubscriptionLink"
|
|
37
37
|
],
|
|
38
38
|
"removedExports": [],
|
|
39
39
|
"dependents": [],
|
|
40
|
-
"percent": 10.
|
|
41
|
-
"reduction":
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"id": "/src/internals/dataLoader.ts",
|
|
45
|
-
"size": 4084,
|
|
46
|
-
"origSize": 4328,
|
|
47
|
-
"renderedExports": [
|
|
48
|
-
"dataLoader"
|
|
49
|
-
],
|
|
50
|
-
"removedExports": [],
|
|
51
|
-
"dependents": [
|
|
52
|
-
"/src/links/httpBatchLink.ts",
|
|
53
|
-
"/src/links/httpBatchStreamLink.ts"
|
|
54
|
-
],
|
|
55
|
-
"percent": 8.01,
|
|
56
|
-
"reduction": 5.64
|
|
40
|
+
"percent": 10.02,
|
|
41
|
+
"reduction": 0
|
|
57
42
|
},
|
|
58
43
|
{
|
|
59
|
-
"id": "/src/links/
|
|
60
|
-
"size":
|
|
61
|
-
"origSize":
|
|
44
|
+
"id": "/src/links/loggerLink.ts",
|
|
45
|
+
"size": 5457,
|
|
46
|
+
"origSize": 6694,
|
|
62
47
|
"renderedExports": [
|
|
63
|
-
"
|
|
48
|
+
"loggerLink"
|
|
64
49
|
],
|
|
65
50
|
"removedExports": [],
|
|
66
51
|
"dependents": [],
|
|
67
|
-
"percent":
|
|
68
|
-
"reduction":
|
|
52
|
+
"percent": 9.55,
|
|
53
|
+
"reduction": 18.48
|
|
69
54
|
},
|
|
70
55
|
{
|
|
71
56
|
"id": "/src/links/internals/httpUtils.ts",
|
|
72
|
-
"size":
|
|
73
|
-
"origSize":
|
|
57
|
+
"size": 4465,
|
|
58
|
+
"origSize": 6646,
|
|
74
59
|
"renderedExports": [
|
|
75
60
|
"resolveHTTPLinkOptions",
|
|
76
61
|
"getInput",
|
|
@@ -88,20 +73,35 @@
|
|
|
88
73
|
"/src/links/httpBatchStreamLink.ts",
|
|
89
74
|
"/src/links/httpSubscriptionLink.ts"
|
|
90
75
|
],
|
|
91
|
-
"percent": 7.
|
|
92
|
-
"reduction":
|
|
76
|
+
"percent": 7.81,
|
|
77
|
+
"reduction": 32.82
|
|
93
78
|
},
|
|
94
79
|
{
|
|
95
|
-
"id": "/src/
|
|
96
|
-
"size":
|
|
97
|
-
"origSize":
|
|
80
|
+
"id": "/src/internals/dataLoader.ts",
|
|
81
|
+
"size": 4084,
|
|
82
|
+
"origSize": 4328,
|
|
98
83
|
"renderedExports": [
|
|
99
|
-
"
|
|
84
|
+
"dataLoader"
|
|
85
|
+
],
|
|
86
|
+
"removedExports": [],
|
|
87
|
+
"dependents": [
|
|
88
|
+
"/src/links/httpBatchLink.ts",
|
|
89
|
+
"/src/links/httpBatchStreamLink.ts"
|
|
90
|
+
],
|
|
91
|
+
"percent": 7.15,
|
|
92
|
+
"reduction": 5.64
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"id": "/src/links/httpBatchLink.ts",
|
|
96
|
+
"size": 3925,
|
|
97
|
+
"origSize": 4118,
|
|
98
|
+
"renderedExports": [
|
|
99
|
+
"httpBatchLink"
|
|
100
100
|
],
|
|
101
101
|
"removedExports": [],
|
|
102
102
|
"dependents": [],
|
|
103
|
-
"percent": 6.
|
|
104
|
-
"reduction":
|
|
103
|
+
"percent": 6.87,
|
|
104
|
+
"reduction": 4.69
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
107
|
"id": "/src/links/httpLink.ts",
|
|
@@ -112,13 +112,13 @@
|
|
|
112
112
|
],
|
|
113
113
|
"removedExports": [],
|
|
114
114
|
"dependents": [],
|
|
115
|
-
"percent":
|
|
115
|
+
"percent": 5.57,
|
|
116
116
|
"reduction": 14.15
|
|
117
117
|
},
|
|
118
118
|
{
|
|
119
119
|
"id": "/src/internals/TRPCUntypedClient.ts",
|
|
120
|
-
"size":
|
|
121
|
-
"origSize":
|
|
120
|
+
"size": 2284,
|
|
121
|
+
"origSize": 4330,
|
|
122
122
|
"renderedExports": [
|
|
123
123
|
"TRPCUntypedClient"
|
|
124
124
|
],
|
|
@@ -127,8 +127,8 @@
|
|
|
127
127
|
"/src/createTRPCUntypedClient.ts",
|
|
128
128
|
"/src/createTRPCClient.ts"
|
|
129
129
|
],
|
|
130
|
-
"percent": 4
|
|
131
|
-
"reduction": 47.
|
|
130
|
+
"percent": 4,
|
|
131
|
+
"reduction": 47.25
|
|
132
132
|
},
|
|
133
133
|
{
|
|
134
134
|
"id": "/src/TRPCClientError.ts",
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
"/src/links/httpSubscriptionLink.ts",
|
|
148
148
|
"/src/internals/TRPCUntypedClient.ts"
|
|
149
149
|
],
|
|
150
|
-
"percent": 3.
|
|
150
|
+
"percent": 3.39,
|
|
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.08,
|
|
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.21,
|
|
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.07,
|
|
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":
|
|
208
|
+
"percent": 0.99,
|
|
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.75,
|
|
224
224
|
"reduction": 33.54
|
|
225
225
|
},
|
|
226
226
|
{
|
|
@@ -233,14 +233,16 @@
|
|
|
233
233
|
"isNonJsonSerializable"
|
|
234
234
|
],
|
|
235
235
|
"removedExports": [],
|
|
236
|
-
"dependents": [
|
|
237
|
-
|
|
236
|
+
"dependents": [
|
|
237
|
+
"/src/links/types.ts"
|
|
238
|
+
],
|
|
239
|
+
"percent": 0.58,
|
|
238
240
|
"reduction": 15.17
|
|
239
241
|
},
|
|
240
242
|
{
|
|
241
243
|
"id": "/src/links/internals/urlWithConnectionParams.ts",
|
|
242
244
|
"size": 158,
|
|
243
|
-
"origSize":
|
|
245
|
+
"origSize": 864,
|
|
244
246
|
"renderedExports": [
|
|
245
247
|
"resultOf"
|
|
246
248
|
],
|
|
@@ -249,8 +251,23 @@
|
|
|
249
251
|
"/src/links/wsLink.ts",
|
|
250
252
|
"/src/links/httpSubscriptionLink.ts"
|
|
251
253
|
],
|
|
252
|
-
"percent": 0.
|
|
253
|
-
"reduction": 81.
|
|
254
|
+
"percent": 0.28,
|
|
255
|
+
"reduction": 81.71
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"id": "/src/links/types.ts",
|
|
259
|
+
"size": 137,
|
|
260
|
+
"origSize": 3413,
|
|
261
|
+
"renderedExports": [
|
|
262
|
+
"isConnectionStateMessage"
|
|
263
|
+
],
|
|
264
|
+
"removedExports": [],
|
|
265
|
+
"dependents": [
|
|
266
|
+
"/src/links/httpLink.ts",
|
|
267
|
+
"/src/links/wsLink.ts"
|
|
268
|
+
],
|
|
269
|
+
"percent": 0.24,
|
|
270
|
+
"reduction": 95.99
|
|
254
271
|
},
|
|
255
272
|
{
|
|
256
273
|
"id": "/src/createTRPCUntypedClient.ts",
|
|
@@ -263,7 +280,7 @@
|
|
|
263
280
|
"dependents": [
|
|
264
281
|
"/src/index.ts"
|
|
265
282
|
],
|
|
266
|
-
"percent": 0.
|
|
283
|
+
"percent": 0.17,
|
|
267
284
|
"reduction": 82.58
|
|
268
285
|
},
|
|
269
286
|
{
|
|
@@ -291,5 +308,5 @@
|
|
|
291
308
|
"reduction": 100
|
|
292
309
|
}
|
|
293
310
|
],
|
|
294
|
-
"moduleCount":
|
|
311
|
+
"moduleCount": 21
|
|
295
312
|
}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var createTRPCUntypedClient = require('./createTRPCUntypedClient.js');
|
|
|
4
4
|
var createTRPCClient = require('./createTRPCClient.js');
|
|
5
5
|
var getFetch = require('./getFetch.js');
|
|
6
6
|
var TRPCClientError = require('./TRPCClientError.js');
|
|
7
|
-
var
|
|
7
|
+
var types = require('./links/types.js');
|
|
8
8
|
var httpBatchLink = require('./links/httpBatchLink.js');
|
|
9
9
|
var httpBatchStreamLink = require('./links/httpBatchStreamLink.js');
|
|
10
10
|
var httpLink = require('./links/httpLink.js');
|
|
@@ -13,6 +13,7 @@ var splitLink = require('./links/splitLink.js');
|
|
|
13
13
|
var wsLink = require('./links/wsLink.js');
|
|
14
14
|
var httpSubscriptionLink = require('./links/httpSubscriptionLink.js');
|
|
15
15
|
var TRPCUntypedClient = require('./internals/TRPCUntypedClient.js');
|
|
16
|
+
var contentTypes = require('./links/internals/contentTypes.js');
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
|
|
@@ -24,9 +25,7 @@ exports.createTRPCProxyClient = createTRPCClient.createTRPCClient;
|
|
|
24
25
|
exports.getUntypedClient = createTRPCClient.getUntypedClient;
|
|
25
26
|
exports.getFetch = getFetch.getFetch;
|
|
26
27
|
exports.TRPCClientError = TRPCClientError.TRPCClientError;
|
|
27
|
-
exports.
|
|
28
|
-
exports.isNonJsonSerializable = contentTypes.isNonJsonSerializable;
|
|
29
|
-
exports.isOctetType = contentTypes.isOctetType;
|
|
28
|
+
exports.isConnectionStateMessage = types.isConnectionStateMessage;
|
|
30
29
|
exports.httpBatchLink = httpBatchLink.httpBatchLink;
|
|
31
30
|
exports.unstable_httpBatchStreamLink = httpBatchStreamLink.unstable_httpBatchStreamLink;
|
|
32
31
|
exports.httpLink = httpLink.httpLink;
|
|
@@ -36,3 +35,6 @@ exports.createWSClient = wsLink.createWSClient;
|
|
|
36
35
|
exports.wsLink = wsLink.wsLink;
|
|
37
36
|
exports.unstable_httpSubscriptionLink = httpSubscriptionLink.unstable_httpSubscriptionLink;
|
|
38
37
|
exports.TRPCUntypedClient = TRPCUntypedClient.TRPCUntypedClient;
|
|
38
|
+
exports.isFormData = contentTypes.isFormData;
|
|
39
|
+
exports.isNonJsonSerializable = contentTypes.isNonJsonSerializable;
|
|
40
|
+
exports.isOctetType = contentTypes.isOctetType;
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ export { createTRPCUntypedClient } from './createTRPCUntypedClient.mjs';
|
|
|
2
2
|
export { clientCallTypeToProcedureType, createTRPCClient, createTRPCClientProxy, createTRPCClient as createTRPCProxyClient, getUntypedClient } from './createTRPCClient.mjs';
|
|
3
3
|
export { getFetch } from './getFetch.mjs';
|
|
4
4
|
export { TRPCClientError } from './TRPCClientError.mjs';
|
|
5
|
-
export {
|
|
5
|
+
export { isConnectionStateMessage } from './links/types.mjs';
|
|
6
6
|
export { httpBatchLink } from './links/httpBatchLink.mjs';
|
|
7
7
|
export { unstable_httpBatchStreamLink } from './links/httpBatchStreamLink.mjs';
|
|
8
8
|
export { httpLink } from './links/httpLink.mjs';
|
|
@@ -11,3 +11,4 @@ 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
13
|
export { TRPCUntypedClient } from './internals/TRPCUntypedClient.mjs';
|
|
14
|
+
export { isFormData, isNonJsonSerializable, isOctetType } from './links/internals/contentTypes.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Unsubscribable } from '@trpc/server/observable';
|
|
2
2
|
import type { AnyRouter, InferrableClientTypes, TypeError } from '@trpc/server/unstable-core-do-not-import';
|
|
3
|
-
import type { OperationContext, TRPCClientRuntime, TRPCLink } from '../links/types';
|
|
3
|
+
import type { OperationContext, TRPCClientRuntime, TRPCConnectionStateMessage, TRPCLink } from '../links/types';
|
|
4
4
|
import { TRPCClientError } from '../TRPCClientError';
|
|
5
5
|
export interface TRPCRequestOptions {
|
|
6
6
|
/**
|
|
@@ -17,6 +17,7 @@ export interface TRPCSubscriptionObserver<TValue, TError> {
|
|
|
17
17
|
onError: (err: TError) => void;
|
|
18
18
|
onStopped: () => void;
|
|
19
19
|
onComplete: () => void;
|
|
20
|
+
onStateChange: (state: TRPCConnectionStateMessage<TError>) => void;
|
|
20
21
|
}
|
|
21
22
|
/** @internal */
|
|
22
23
|
export type CreateTRPCClientOptions<TRouter extends InferrableClientTypes> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TRPCUntypedClient.d.ts","sourceRoot":"","sources":["../../src/internals/TRPCUntypedClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EAErB,SAAS,EACV,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EACV,gBAAgB,EAEhB,iBAAiB,EACjB,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB,CAAC,MAAM,EAAE,MAAM;IACtD,SAAS,EAAE,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAAA;KAAE,KAAK,IAAI,CAAC;IACrE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"TRPCUntypedClient.d.ts","sourceRoot":"","sources":["../../src/internals/TRPCUntypedClient.ts"],"names":[],"mappings":"AAAA,OAA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AAC,QAAQ,CAAC,KAAK,CAA6B;IACnD,SAAgB,OAAO,EAAE,iBAAiB,CAAC;IAC3C,OAAO,CAAC,SAAS,CAAS;gBAEd,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC;IASlD,OAAO,CAAC,QAAQ;YAkBF,gBAAgB;IAkBvB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,kBAAkB;IAS9D,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,kBAAkB;IASjE,YAAY,CACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,OAAO,CACX,wBAAwB,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAC9D,GACC,kBAAkB,GACnB,cAAc;CA8BlB"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { AnyClientTypes, inferClientTypes, InferrableClientTypes } from '@trpc/server/unstable-core-do-not-import';
|
|
2
2
|
import { type TransformerOptions } from '../unstable-internals';
|
|
3
|
+
import type { CallbackOrValue } from './internals/urlWithConnectionParams';
|
|
3
4
|
import { type UrlOptionsWithConnectionParams } from './internals/urlWithConnectionParams';
|
|
4
5
|
import type { TRPCLink } from './types';
|
|
5
6
|
type HTTPSubscriptionLinkOptions<TRoot extends AnyClientTypes> = {
|
|
6
7
|
/**
|
|
7
|
-
* EventSource options
|
|
8
|
+
* EventSource options or a callback that returns them
|
|
8
9
|
*/
|
|
9
|
-
eventSourceOptions?: EventSourceInit
|
|
10
|
+
eventSourceOptions?: CallbackOrValue<EventSourceInit>;
|
|
10
11
|
} & TransformerOptions<TRoot> & UrlOptionsWithConnectionParams;
|
|
11
12
|
/**
|
|
12
13
|
* @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":"AACA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EAEtB,MAAM,0CAA0C,CAAC;AAMlD,OAAO,EAAkB,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,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;
|
|
1
|
+
{"version":3,"file":"httpSubscriptionLink.d.ts","sourceRoot":"","sources":["../../src/links/httpSubscriptionLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EAEtB,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,CA8IvB"}
|
|
@@ -38,11 +38,19 @@ async function urlWithConnectionParams(opts) {
|
|
|
38
38
|
type,
|
|
39
39
|
signal: null
|
|
40
40
|
});
|
|
41
|
+
const eventSourceOptions = await urlWithConnectionParams$1.resultOf(opts.eventSourceOptions);
|
|
41
42
|
/* istanbul ignore if -- @preserve */ if (unsubscribed) {
|
|
42
43
|
// already unsubscribed - rare race condition
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
|
-
eventSource = new EventSource(url,
|
|
46
|
+
eventSource = new EventSource(url, eventSourceOptions);
|
|
47
|
+
observer.next({
|
|
48
|
+
result: {
|
|
49
|
+
type: 'state',
|
|
50
|
+
state: 'connecting',
|
|
51
|
+
data: null
|
|
52
|
+
}
|
|
53
|
+
});
|
|
46
54
|
const onStarted = ()=>{
|
|
47
55
|
observer.next({
|
|
48
56
|
result: {
|
|
@@ -57,9 +65,31 @@ async function urlWithConnectionParams(opts) {
|
|
|
57
65
|
};
|
|
58
66
|
// console.log('starting', new Date());
|
|
59
67
|
eventSource.addEventListener('open', onStarted);
|
|
68
|
+
eventSource.addEventListener('open', ()=>{
|
|
69
|
+
observer.next({
|
|
70
|
+
result: {
|
|
71
|
+
type: 'state',
|
|
72
|
+
state: 'pending'
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
eventSource.addEventListener('error', (event)=>{
|
|
77
|
+
// sseStreamConsumer handles this already
|
|
78
|
+
if (eventSource?.readyState === EventSource.CLOSED) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const error = event instanceof ErrorEvent ? TRPCClientError.TRPCClientError.from(event.error) : TRPCClientError.TRPCClientError.from(new Error(`Unknown EventSource error`));
|
|
82
|
+
observer.next({
|
|
83
|
+
result: {
|
|
84
|
+
type: 'state',
|
|
85
|
+
state: 'connecting',
|
|
86
|
+
data: error
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
60
90
|
const iterable = unstableCoreDoNotImport.sseStreamConsumer({
|
|
61
91
|
from: eventSource,
|
|
62
|
-
deserialize: transformer$1.
|
|
92
|
+
deserialize: transformer$1.output.deserialize
|
|
63
93
|
});
|
|
64
94
|
for await (const chunk of iterable){
|
|
65
95
|
// if the `sse({})`-helper is used, we always have an `id` field
|
|
@@ -76,11 +106,31 @@ async function urlWithConnectionParams(opts) {
|
|
|
76
106
|
}
|
|
77
107
|
});
|
|
78
108
|
observer.complete();
|
|
109
|
+
observer.next({
|
|
110
|
+
result: {
|
|
111
|
+
type: 'state',
|
|
112
|
+
state: 'idle'
|
|
113
|
+
}
|
|
114
|
+
});
|
|
79
115
|
}).catch((error)=>{
|
|
80
|
-
|
|
116
|
+
const trpcError = TRPCClientError.TRPCClientError.from(error);
|
|
117
|
+
observer.error(trpcError);
|
|
118
|
+
observer.next({
|
|
119
|
+
result: {
|
|
120
|
+
type: 'state',
|
|
121
|
+
state: 'error',
|
|
122
|
+
data: TRPCClientError.TRPCClientError.from(trpcError)
|
|
123
|
+
}
|
|
124
|
+
});
|
|
81
125
|
});
|
|
82
126
|
return ()=>{
|
|
83
127
|
observer.complete();
|
|
128
|
+
observer.next({
|
|
129
|
+
result: {
|
|
130
|
+
type: 'state',
|
|
131
|
+
state: 'idle'
|
|
132
|
+
}
|
|
133
|
+
});
|
|
84
134
|
eventSource?.close();
|
|
85
135
|
unsubscribed = true;
|
|
86
136
|
};
|
|
@@ -36,11 +36,19 @@ async function urlWithConnectionParams(opts) {
|
|
|
36
36
|
type,
|
|
37
37
|
signal: null
|
|
38
38
|
});
|
|
39
|
+
const eventSourceOptions = await resultOf(opts.eventSourceOptions);
|
|
39
40
|
/* istanbul ignore if -- @preserve */ if (unsubscribed) {
|
|
40
41
|
// already unsubscribed - rare race condition
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
|
-
eventSource = new EventSource(url,
|
|
44
|
+
eventSource = new EventSource(url, eventSourceOptions);
|
|
45
|
+
observer.next({
|
|
46
|
+
result: {
|
|
47
|
+
type: 'state',
|
|
48
|
+
state: 'connecting',
|
|
49
|
+
data: null
|
|
50
|
+
}
|
|
51
|
+
});
|
|
44
52
|
const onStarted = ()=>{
|
|
45
53
|
observer.next({
|
|
46
54
|
result: {
|
|
@@ -55,9 +63,31 @@ async function urlWithConnectionParams(opts) {
|
|
|
55
63
|
};
|
|
56
64
|
// console.log('starting', new Date());
|
|
57
65
|
eventSource.addEventListener('open', onStarted);
|
|
66
|
+
eventSource.addEventListener('open', ()=>{
|
|
67
|
+
observer.next({
|
|
68
|
+
result: {
|
|
69
|
+
type: 'state',
|
|
70
|
+
state: 'pending'
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
eventSource.addEventListener('error', (event)=>{
|
|
75
|
+
// sseStreamConsumer handles this already
|
|
76
|
+
if (eventSource?.readyState === EventSource.CLOSED) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const error = event instanceof ErrorEvent ? TRPCClientError.from(event.error) : TRPCClientError.from(new Error(`Unknown EventSource error`));
|
|
80
|
+
observer.next({
|
|
81
|
+
result: {
|
|
82
|
+
type: 'state',
|
|
83
|
+
state: 'connecting',
|
|
84
|
+
data: error
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
58
88
|
const iterable = sseStreamConsumer({
|
|
59
89
|
from: eventSource,
|
|
60
|
-
deserialize: transformer.
|
|
90
|
+
deserialize: transformer.output.deserialize
|
|
61
91
|
});
|
|
62
92
|
for await (const chunk of iterable){
|
|
63
93
|
// if the `sse({})`-helper is used, we always have an `id` field
|
|
@@ -74,11 +104,31 @@ async function urlWithConnectionParams(opts) {
|
|
|
74
104
|
}
|
|
75
105
|
});
|
|
76
106
|
observer.complete();
|
|
107
|
+
observer.next({
|
|
108
|
+
result: {
|
|
109
|
+
type: 'state',
|
|
110
|
+
state: 'idle'
|
|
111
|
+
}
|
|
112
|
+
});
|
|
77
113
|
}).catch((error)=>{
|
|
78
|
-
|
|
114
|
+
const trpcError = TRPCClientError.from(error);
|
|
115
|
+
observer.error(trpcError);
|
|
116
|
+
observer.next({
|
|
117
|
+
result: {
|
|
118
|
+
type: 'state',
|
|
119
|
+
state: 'error',
|
|
120
|
+
data: TRPCClientError.from(trpcError)
|
|
121
|
+
}
|
|
122
|
+
});
|
|
79
123
|
});
|
|
80
124
|
return ()=>{
|
|
81
125
|
observer.complete();
|
|
126
|
+
observer.next({
|
|
127
|
+
result: {
|
|
128
|
+
type: 'state',
|
|
129
|
+
state: 'idle'
|
|
130
|
+
}
|
|
131
|
+
});
|
|
82
132
|
eventSource?.close();
|
|
83
133
|
unsubscribed = true;
|
|
84
134
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACvB,KAAK,EACL,aAAa,EACb,gBAAgB,EAChB,YAAY,EACb,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,KAAK,SAAS,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,IAC/C;IACF,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAE9B,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,WAAW,EAAE,uBAAuB,CAAC;IACrC,cAAc,CAAC,EAAE,MAAM,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E,kBAAkB,GACvB,OAAO,CAAC,UAAU,CAAC,CAcrB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE;IACJ,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;CAC5B,EAAE,GACF,eAAe,CA8BjB"}
|
|
@@ -65,8 +65,35 @@ const jsonHttpRequester = (opts)=>{
|
|
|
65
65
|
getBody
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Polyfill for DOMException with AbortError name
|
|
70
|
+
*/ class AbortError extends Error {
|
|
71
|
+
constructor(){
|
|
72
|
+
const name = 'AbortError';
|
|
73
|
+
super(name);
|
|
74
|
+
this.name = name;
|
|
75
|
+
this.message = name;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Polyfill for `signal.throwIfAborted()`
|
|
80
|
+
*
|
|
81
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted
|
|
82
|
+
*/ const throwIfAborted = (signal)=>{
|
|
83
|
+
if (!signal?.aborted) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// If available, use the native implementation
|
|
87
|
+
signal.throwIfAborted?.();
|
|
88
|
+
// If we have `DOMException`, use it
|
|
89
|
+
if (typeof DOMException !== 'undefined') {
|
|
90
|
+
throw new DOMException('AbortError', 'AbortError');
|
|
91
|
+
}
|
|
92
|
+
// Otherwise, use our own implementation
|
|
93
|
+
throw new AbortError();
|
|
94
|
+
};
|
|
68
95
|
async function fetchHTTPResponse(opts) {
|
|
69
|
-
opts.signal
|
|
96
|
+
throwIfAborted(opts.signal);
|
|
70
97
|
const url = opts.getUrl(opts);
|
|
71
98
|
const body = opts.getBody(opts);
|
|
72
99
|
const { type } = opts;
|
|
@@ -63,8 +63,35 @@ const jsonHttpRequester = (opts)=>{
|
|
|
63
63
|
getBody
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Polyfill for DOMException with AbortError name
|
|
68
|
+
*/ class AbortError extends Error {
|
|
69
|
+
constructor(){
|
|
70
|
+
const name = 'AbortError';
|
|
71
|
+
super(name);
|
|
72
|
+
this.name = name;
|
|
73
|
+
this.message = name;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Polyfill for `signal.throwIfAborted()`
|
|
78
|
+
*
|
|
79
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted
|
|
80
|
+
*/ const throwIfAborted = (signal)=>{
|
|
81
|
+
if (!signal?.aborted) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// If available, use the native implementation
|
|
85
|
+
signal.throwIfAborted?.();
|
|
86
|
+
// If we have `DOMException`, use it
|
|
87
|
+
if (typeof DOMException !== 'undefined') {
|
|
88
|
+
throw new DOMException('AbortError', 'AbortError');
|
|
89
|
+
}
|
|
90
|
+
// Otherwise, use our own implementation
|
|
91
|
+
throw new AbortError();
|
|
92
|
+
};
|
|
66
93
|
async function fetchHTTPResponse(opts) {
|
|
67
|
-
opts.signal
|
|
94
|
+
throwIfAborted(opts.signal);
|
|
68
95
|
const url = opts.getUrl(opts);
|
|
69
96
|
const body = opts.getBody(opts);
|
|
70
97
|
const { type } = opts;
|