@trpc/server 11.0.0-rc.638 → 11.0.0-rc.642
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 +65 -65
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +1 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +20 -11
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +20 -7
- package/dist/unstable-core-do-not-import/stream/sse.mjs +20 -7
- package/package.json +5 -2
- package/src/unstable-core-do-not-import/rootConfig.ts +1 -1
- package/src/unstable-core-do-not-import/stream/sse.ts +55 -21
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 23.
|
|
2
|
+
"bundleSize": 168625,
|
|
3
|
+
"bundleOrigSize": 220107,
|
|
4
|
+
"bundleReduction": 23.39,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dependents": [
|
|
15
15
|
"/src/unstable-core-do-not-import.ts"
|
|
16
16
|
],
|
|
17
|
-
"percent": 12.
|
|
17
|
+
"percent": 12.7,
|
|
18
18
|
"reduction": 0
|
|
19
19
|
},
|
|
20
20
|
{
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependents": [
|
|
31
31
|
"/src/adapters/fastify/fastifyTRPCPlugin.ts"
|
|
32
32
|
],
|
|
33
|
-
"percent": 9.
|
|
33
|
+
"percent": 9.95,
|
|
34
34
|
"reduction": 0
|
|
35
35
|
},
|
|
36
36
|
{
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"/src/unstable-core-do-not-import.ts",
|
|
48
48
|
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
49
49
|
],
|
|
50
|
-
"percent": 9.
|
|
50
|
+
"percent": 9.73,
|
|
51
51
|
"reduction": 6.09
|
|
52
52
|
},
|
|
53
53
|
{
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
],
|
|
61
61
|
"removedExports": [],
|
|
62
62
|
"dependents": [],
|
|
63
|
-
"percent": 7
|
|
63
|
+
"percent": 7,
|
|
64
64
|
"reduction": 14.14
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
"id": "/src/unstable-core-do-not-import/stream/sse.ts",
|
|
68
|
-
"size":
|
|
69
|
-
"origSize":
|
|
68
|
+
"size": 10408,
|
|
69
|
+
"origSize": 12991,
|
|
70
70
|
"renderedExports": [
|
|
71
71
|
"sseStreamProducer",
|
|
72
72
|
"sseStreamConsumer",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"/src/unstable-core-do-not-import.ts",
|
|
78
78
|
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
79
79
|
],
|
|
80
|
-
"percent":
|
|
81
|
-
"reduction": 19.
|
|
80
|
+
"percent": 6.17,
|
|
81
|
+
"reduction": 19.88
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
84
|
"id": "/src/unstable-core-do-not-import/http/contentType.ts",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"/src/unstable-core-do-not-import.ts",
|
|
93
93
|
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
94
94
|
],
|
|
95
|
-
"percent": 4.
|
|
95
|
+
"percent": 4.56,
|
|
96
96
|
"reduction": 0
|
|
97
97
|
},
|
|
98
98
|
{
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"/src/unstable-core-do-not-import.ts",
|
|
111
111
|
"/src/unstable-core-do-not-import/initTRPC.ts"
|
|
112
112
|
],
|
|
113
|
-
"percent": 3.
|
|
113
|
+
"percent": 3.81,
|
|
114
114
|
"reduction": 39.89
|
|
115
115
|
},
|
|
116
116
|
{
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"/src/unstable-core-do-not-import.ts",
|
|
126
126
|
"/src/unstable-core-do-not-import/initTRPC.ts"
|
|
127
127
|
],
|
|
128
|
-
"percent": 3.
|
|
128
|
+
"percent": 3.44,
|
|
129
129
|
"reduction": 65.01
|
|
130
130
|
},
|
|
131
131
|
{
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
"dependents": [
|
|
140
140
|
"/src/adapters/aws-lambda/index.ts"
|
|
141
141
|
],
|
|
142
|
-
"percent": 3.
|
|
142
|
+
"percent": 3.21,
|
|
143
143
|
"reduction": 11.51
|
|
144
144
|
},
|
|
145
145
|
{
|
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
"/src/observable/operators.ts",
|
|
160
160
|
"/src/observable/behaviorSubject.ts"
|
|
161
161
|
],
|
|
162
|
-
"percent": 2.
|
|
162
|
+
"percent": 2.66,
|
|
163
163
|
"reduction": 0
|
|
164
164
|
},
|
|
165
165
|
{
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
"dependents": [
|
|
178
178
|
"/src/observable/index.ts"
|
|
179
179
|
],
|
|
180
|
-
"percent": 2.
|
|
180
|
+
"percent": 2.32,
|
|
181
181
|
"reduction": 1.66
|
|
182
182
|
},
|
|
183
183
|
{
|
|
@@ -193,7 +193,7 @@
|
|
|
193
193
|
"/src/adapters/node-http/index.ts",
|
|
194
194
|
"/src/adapters/node-http/nodeHTTPRequestHandler.ts"
|
|
195
195
|
],
|
|
196
|
-
"percent": 2.
|
|
196
|
+
"percent": 2.28,
|
|
197
197
|
"reduction": 11.87
|
|
198
198
|
},
|
|
199
199
|
{
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
"dependents": [
|
|
208
208
|
"/src/adapters/next-app-dir.ts"
|
|
209
209
|
],
|
|
210
|
-
"percent": 1.
|
|
210
|
+
"percent": 1.92,
|
|
211
211
|
"reduction": 22.52
|
|
212
212
|
},
|
|
213
213
|
{
|
|
@@ -238,11 +238,11 @@
|
|
|
238
238
|
"removedExports": [],
|
|
239
239
|
"dependents": [
|
|
240
240
|
"/src/unstable-core-do-not-import.ts",
|
|
241
|
-
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
242
241
|
"/src/unstable-core-do-not-import/initTRPC.ts",
|
|
243
|
-
"/src/unstable-core-do-not-import/router.ts"
|
|
242
|
+
"/src/unstable-core-do-not-import/router.ts",
|
|
243
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
244
244
|
],
|
|
245
|
-
"percent": 1.
|
|
245
|
+
"percent": 1.62,
|
|
246
246
|
"reduction": 45.98
|
|
247
247
|
},
|
|
248
248
|
{
|
|
@@ -256,7 +256,7 @@
|
|
|
256
256
|
"dependents": [
|
|
257
257
|
"/src/unstable-core-do-not-import.ts"
|
|
258
258
|
],
|
|
259
|
-
"percent": 1.
|
|
259
|
+
"percent": 1.58,
|
|
260
260
|
"reduction": 40.81
|
|
261
261
|
},
|
|
262
262
|
{
|
|
@@ -291,7 +291,7 @@
|
|
|
291
291
|
"dependents": [
|
|
292
292
|
"/src/unstable-core-do-not-import/stream/sse.ts"
|
|
293
293
|
],
|
|
294
|
-
"percent": 1.
|
|
294
|
+
"percent": 1.5,
|
|
295
295
|
"reduction": 2.91
|
|
296
296
|
},
|
|
297
297
|
{
|
|
@@ -315,13 +315,13 @@
|
|
|
315
315
|
"removedExports": [],
|
|
316
316
|
"dependents": [
|
|
317
317
|
"/src/unstable-core-do-not-import.ts",
|
|
318
|
-
"/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
|
|
319
|
-
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
320
|
-
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
321
318
|
"/src/unstable-core-do-not-import/error/TRPCError.ts",
|
|
322
319
|
"/src/unstable-core-do-not-import/transformer.ts",
|
|
323
320
|
"/src/unstable-core-do-not-import/middleware.ts",
|
|
324
321
|
"/src/unstable-core-do-not-import/router.ts",
|
|
322
|
+
"/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
|
|
323
|
+
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
324
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
325
325
|
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
326
326
|
"/src/unstable-core-do-not-import/http/contentType.ts",
|
|
327
327
|
"/src/unstable-core-do-not-import/http/isAbortError.ts",
|
|
@@ -329,7 +329,7 @@
|
|
|
329
329
|
"/src/unstable-core-do-not-import/stream/jsonl.ts",
|
|
330
330
|
"/src/unstable-core-do-not-import/stream/sse.ts"
|
|
331
331
|
],
|
|
332
|
-
"percent": 1.
|
|
332
|
+
"percent": 1.46,
|
|
333
333
|
"reduction": 17.51
|
|
334
334
|
},
|
|
335
335
|
{
|
|
@@ -345,7 +345,7 @@
|
|
|
345
345
|
"/src/unstable-core-do-not-import.ts",
|
|
346
346
|
"/src/unstable-core-do-not-import/router.ts"
|
|
347
347
|
],
|
|
348
|
-
"percent": 1.
|
|
348
|
+
"percent": 1.38,
|
|
349
349
|
"reduction": 0
|
|
350
350
|
},
|
|
351
351
|
{
|
|
@@ -359,7 +359,7 @@
|
|
|
359
359
|
"dependents": [
|
|
360
360
|
"/src/adapters/fetch/index.ts"
|
|
361
361
|
],
|
|
362
|
-
"percent": 1.
|
|
362
|
+
"percent": 1.33,
|
|
363
363
|
"reduction": 2.48
|
|
364
364
|
},
|
|
365
365
|
{
|
|
@@ -391,8 +391,8 @@
|
|
|
391
391
|
"removedExports": [],
|
|
392
392
|
"dependents": [
|
|
393
393
|
"/src/unstable-core-do-not-import.ts",
|
|
394
|
-
"/src/unstable-core-do-not-import/
|
|
395
|
-
"/src/unstable-core-do-not-import/
|
|
394
|
+
"/src/unstable-core-do-not-import/error/getErrorShape.ts",
|
|
395
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
396
396
|
],
|
|
397
397
|
"percent": 1.24,
|
|
398
398
|
"reduction": 18.54
|
|
@@ -409,15 +409,15 @@
|
|
|
409
409
|
"removedExports": [],
|
|
410
410
|
"dependents": [
|
|
411
411
|
"/src/unstable-core-do-not-import.ts",
|
|
412
|
-
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
413
|
-
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
414
412
|
"/src/unstable-core-do-not-import/middleware.ts",
|
|
415
413
|
"/src/unstable-core-do-not-import/router.ts",
|
|
414
|
+
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
415
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
416
416
|
"/src/unstable-core-do-not-import/http/contentType.ts",
|
|
417
417
|
"/src/unstable-core-do-not-import/procedureBuilder.ts",
|
|
418
418
|
"/src/unstable-core-do-not-import/stream/sse.ts"
|
|
419
419
|
],
|
|
420
|
-
"percent": 1.
|
|
420
|
+
"percent": 1.22,
|
|
421
421
|
"reduction": 4.23
|
|
422
422
|
},
|
|
423
423
|
{
|
|
@@ -432,7 +432,7 @@
|
|
|
432
432
|
"dependents": [
|
|
433
433
|
"/src/adapters/node-http/nodeHTTPRequestHandler.ts"
|
|
434
434
|
],
|
|
435
|
-
"percent": 1.
|
|
435
|
+
"percent": 1.14,
|
|
436
436
|
"reduction": 4.03
|
|
437
437
|
},
|
|
438
438
|
{
|
|
@@ -446,7 +446,7 @@
|
|
|
446
446
|
"dependents": [
|
|
447
447
|
"/src/unstable-core-do-not-import/stream/jsonl.ts"
|
|
448
448
|
],
|
|
449
|
-
"percent": 1.
|
|
449
|
+
"percent": 1.1,
|
|
450
450
|
"reduction": 27.46
|
|
451
451
|
},
|
|
452
452
|
{
|
|
@@ -460,7 +460,7 @@
|
|
|
460
460
|
"dependents": [
|
|
461
461
|
"/src/adapters/fastify/index.ts"
|
|
462
462
|
],
|
|
463
|
-
"percent": 1.
|
|
463
|
+
"percent": 1.05,
|
|
464
464
|
"reduction": 30.2
|
|
465
465
|
},
|
|
466
466
|
{
|
|
@@ -472,7 +472,7 @@
|
|
|
472
472
|
],
|
|
473
473
|
"removedExports": [],
|
|
474
474
|
"dependents": [],
|
|
475
|
-
"percent": 1
|
|
475
|
+
"percent": 1,
|
|
476
476
|
"reduction": 19.62
|
|
477
477
|
},
|
|
478
478
|
{
|
|
@@ -558,7 +558,7 @@
|
|
|
558
558
|
"/src/unstable-core-do-not-import.ts",
|
|
559
559
|
"/src/unstable-core-do-not-import/http/contentType.ts"
|
|
560
560
|
],
|
|
561
|
-
"percent": 0.
|
|
561
|
+
"percent": 0.65,
|
|
562
562
|
"reduction": 15.08
|
|
563
563
|
},
|
|
564
564
|
{
|
|
@@ -603,7 +603,7 @@
|
|
|
603
603
|
"dependents": [
|
|
604
604
|
"/src/observable/index.ts"
|
|
605
605
|
],
|
|
606
|
-
"percent": 0.
|
|
606
|
+
"percent": 0.57,
|
|
607
607
|
"reduction": 32.89
|
|
608
608
|
},
|
|
609
609
|
{
|
|
@@ -645,7 +645,7 @@
|
|
|
645
645
|
],
|
|
646
646
|
"removedExports": [],
|
|
647
647
|
"dependents": [],
|
|
648
|
-
"percent": 0.
|
|
648
|
+
"percent": 0.45,
|
|
649
649
|
"reduction": 56.66
|
|
650
650
|
},
|
|
651
651
|
{
|
|
@@ -709,7 +709,7 @@
|
|
|
709
709
|
{
|
|
710
710
|
"id": "/src/unstable-core-do-not-import/rootConfig.ts",
|
|
711
711
|
"size": 343,
|
|
712
|
-
"origSize":
|
|
712
|
+
"origSize": 3284,
|
|
713
713
|
"renderedExports": [
|
|
714
714
|
"isServerDefault"
|
|
715
715
|
],
|
|
@@ -719,7 +719,7 @@
|
|
|
719
719
|
"/src/unstable-core-do-not-import/initTRPC.ts"
|
|
720
720
|
],
|
|
721
721
|
"percent": 0.2,
|
|
722
|
-
"reduction": 89.
|
|
722
|
+
"reduction": 89.56
|
|
723
723
|
},
|
|
724
724
|
{
|
|
725
725
|
"id": "/src/unstable-core-do-not-import/stream/utils/createDeferred.ts",
|
|
@@ -747,7 +747,7 @@
|
|
|
747
747
|
"dependents": [
|
|
748
748
|
"/src/unstable-core-do-not-import.ts"
|
|
749
749
|
],
|
|
750
|
-
"percent": 0.
|
|
750
|
+
"percent": 0.16,
|
|
751
751
|
"reduction": 68.45
|
|
752
752
|
},
|
|
753
753
|
{
|
|
@@ -759,12 +759,12 @@
|
|
|
759
759
|
],
|
|
760
760
|
"removedExports": [],
|
|
761
761
|
"dependents": [
|
|
762
|
-
"/src/vendor/unpromise/unpromise.ts",
|
|
763
762
|
"/src/unstable-core-do-not-import/error/TRPCError.ts",
|
|
763
|
+
"/src/vendor/unpromise/unpromise.ts",
|
|
764
764
|
"/src/unstable-core-do-not-import/stream/jsonl.ts",
|
|
765
765
|
"/src/adapters/next-app-dir/redirect.ts"
|
|
766
766
|
],
|
|
767
|
-
"percent": 0.
|
|
767
|
+
"percent": 0.13,
|
|
768
768
|
"reduction": 13.36
|
|
769
769
|
},
|
|
770
770
|
{
|
|
@@ -827,18 +827,6 @@
|
|
|
827
827
|
"percent": 0.04,
|
|
828
828
|
"reduction": 93.9
|
|
829
829
|
},
|
|
830
|
-
{
|
|
831
|
-
"id": "/src/http.ts",
|
|
832
|
-
"size": 0,
|
|
833
|
-
"origSize": 37,
|
|
834
|
-
"renderedExports": [],
|
|
835
|
-
"removedExports": [],
|
|
836
|
-
"dependents": [
|
|
837
|
-
"/src/adapters/ws.ts"
|
|
838
|
-
],
|
|
839
|
-
"percent": 0,
|
|
840
|
-
"reduction": 100
|
|
841
|
-
},
|
|
842
830
|
{
|
|
843
831
|
"id": "/src/index.ts",
|
|
844
832
|
"size": 0,
|
|
@@ -850,19 +838,21 @@
|
|
|
850
838
|
"reduction": 100
|
|
851
839
|
},
|
|
852
840
|
{
|
|
853
|
-
"id": "/src/
|
|
841
|
+
"id": "/src/http.ts",
|
|
854
842
|
"size": 0,
|
|
855
|
-
"origSize":
|
|
843
|
+
"origSize": 37,
|
|
856
844
|
"renderedExports": [],
|
|
857
845
|
"removedExports": [],
|
|
858
|
-
"dependents": [
|
|
846
|
+
"dependents": [
|
|
847
|
+
"/src/adapters/ws.ts"
|
|
848
|
+
],
|
|
859
849
|
"percent": 0,
|
|
860
850
|
"reduction": 100
|
|
861
851
|
},
|
|
862
852
|
{
|
|
863
|
-
"id": "/src/
|
|
853
|
+
"id": "/src/rpc.ts",
|
|
864
854
|
"size": 0,
|
|
865
|
-
"origSize":
|
|
855
|
+
"origSize": 36,
|
|
866
856
|
"renderedExports": [],
|
|
867
857
|
"removedExports": [],
|
|
868
858
|
"dependents": [],
|
|
@@ -880,13 +870,23 @@
|
|
|
880
870
|
"/src/adapters/next.ts",
|
|
881
871
|
"/src/adapters/standalone.ts",
|
|
882
872
|
"/src/adapters/ws.ts",
|
|
883
|
-
"/src/adapters/next-app-dir/nextAppDirCaller.ts",
|
|
884
873
|
"/src/adapters/node-http/nodeHTTPRequestHandler.ts",
|
|
874
|
+
"/src/adapters/next-app-dir/nextAppDirCaller.ts",
|
|
885
875
|
"/src/adapters/node-http/writeResponse.ts"
|
|
886
876
|
],
|
|
887
877
|
"percent": 0,
|
|
888
878
|
"reduction": 100
|
|
889
879
|
},
|
|
880
|
+
{
|
|
881
|
+
"id": "/src/shared.ts",
|
|
882
|
+
"size": 0,
|
|
883
|
+
"origSize": 653,
|
|
884
|
+
"renderedExports": [],
|
|
885
|
+
"removedExports": [],
|
|
886
|
+
"dependents": [],
|
|
887
|
+
"percent": 0,
|
|
888
|
+
"reduction": 100
|
|
889
|
+
},
|
|
890
890
|
{
|
|
891
891
|
"id": "/src/adapters/next-app-dir.ts",
|
|
892
892
|
"size": 0,
|
|
@@ -69,7 +69,7 @@ export interface RootConfig<TTypes extends RootTypes> {
|
|
|
69
69
|
* @default true
|
|
70
70
|
*/
|
|
71
71
|
enabled?: boolean;
|
|
72
|
-
} & Pick<SSEStreamProducerOptions, 'ping' | 'emitAndEndImmediately' | 'maxDurationMs'>;
|
|
72
|
+
} & Pick<SSEStreamProducerOptions, 'ping' | 'emitAndEndImmediately' | 'maxDurationMs' | 'client'>;
|
|
73
73
|
experimental?: {};
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rootConfig.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/rootConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAE7D;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,iBAAiB,CAAC;IAC9B,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,OAMmB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,UAAU,CAAC,MAAM,SAAS,SAAS;IAClD;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,EAAE,uBAAuB,CAAC;IACrC;;;OAGG;IACH,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IACpE;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;IAErE;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IACh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;IACH,GAAG,CAAC,EAAE;QACJ;;;WAGG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,GAAG,IAAI,CACN,wBAAwB,EACxB,MAAM,GAAG,uBAAuB,GAAG,eAAe,GAAG,QAAQ,CAC9D,CAAC;IACF,YAAY,CAAC,EAAE,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,SAAS,SAAS,SAAS,IAAI,SAAS,CAAC;AAErE,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;IACzC,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,GAAG,CAAC;IACV,UAAU,EAAE,GAAG,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC,CAAC;AAEH,KAAK,SAAS,CAAC,UAAU,SAAS,OAAO,EAAE,KAAK,IAAI,UAAU,SAAS,IAAI,GACvE,OAAO,CAAC,KAAK,CAAC,GACd,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAC/B,QAAQ,EACR,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IACvC,SAAS,CACX,MAAM,SAAS,QAAQ,GAAG,IAAI,GAAG,KAAK,EACtC;IACE;;QAEI;IACJ,aAAa,EAAE,SAAS,CAAC;CAC1B,CACF,CAAC"}
|
|
@@ -6,7 +6,7 @@ type Deserialize = (value: any) => any;
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
export interface
|
|
9
|
+
export interface SSEPingOptions {
|
|
10
10
|
/**
|
|
11
11
|
* Enable ping comments sent from the server
|
|
12
12
|
* @default false
|
|
@@ -18,14 +18,20 @@ export interface PingOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
intervalMs?: number;
|
|
20
20
|
}
|
|
21
|
+
export interface SSEClientOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Timeout and reconnect after inactivity in milliseconds
|
|
24
|
+
* @default undefined
|
|
25
|
+
*/
|
|
26
|
+
reconnectAfterInactivityMs?: number;
|
|
27
|
+
}
|
|
21
28
|
export interface SSEStreamProducerOptions<TValue = unknown> {
|
|
22
29
|
serialize?: Serialize;
|
|
23
30
|
data: AsyncIterable<TValue>;
|
|
24
31
|
maxDepth?: number;
|
|
25
|
-
ping?:
|
|
32
|
+
ping?: SSEPingOptions;
|
|
26
33
|
/**
|
|
27
34
|
* Maximum duration in milliseconds for the request before ending the stream
|
|
28
|
-
* Only useful for serverless runtimes
|
|
29
35
|
* @default undefined
|
|
30
36
|
*/
|
|
31
37
|
maxDurationMs?: number;
|
|
@@ -38,6 +44,11 @@ export interface SSEStreamProducerOptions<TValue = unknown> {
|
|
|
38
44
|
formatError?: (opts: {
|
|
39
45
|
error: unknown;
|
|
40
46
|
}) => unknown;
|
|
47
|
+
/**
|
|
48
|
+
* Client-specific options - these will be sent to the client as part of the first message
|
|
49
|
+
* @default {}
|
|
50
|
+
*/
|
|
51
|
+
client?: SSEClientOptions;
|
|
41
52
|
}
|
|
42
53
|
/**
|
|
43
54
|
*
|
|
@@ -55,30 +66,28 @@ interface ConsumerStreamResultError<TConfig extends ConsumerConfig> extends Cons
|
|
|
55
66
|
type: 'serialized-error';
|
|
56
67
|
error: TConfig['error'];
|
|
57
68
|
}
|
|
58
|
-
interface ConsumerStreamResultOpened<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
59
|
-
type: 'opened';
|
|
60
|
-
}
|
|
61
69
|
interface ConsumerStreamResultConnecting<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
62
70
|
type: 'connecting';
|
|
63
71
|
event: EventSourceLike.EventOf<TConfig['EventSource']> | null;
|
|
64
72
|
}
|
|
65
73
|
interface ConsumerStreamResultTimeout<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
66
74
|
type: 'timeout';
|
|
75
|
+
ms: number;
|
|
67
76
|
}
|
|
68
77
|
interface ConsumerStreamResultPing<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
69
78
|
type: 'ping';
|
|
70
79
|
}
|
|
71
|
-
|
|
80
|
+
interface ConsumerStreamResultConnected<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
81
|
+
type: 'connected';
|
|
82
|
+
options: SSEClientOptions;
|
|
83
|
+
}
|
|
84
|
+
type ConsumerStreamResult<TConfig extends ConsumerConfig> = ConsumerStreamResultData<TConfig> | ConsumerStreamResultError<TConfig> | ConsumerStreamResultConnecting<TConfig> | ConsumerStreamResultTimeout<TConfig> | ConsumerStreamResultPing<TConfig> | ConsumerStreamResultConnected<TConfig>;
|
|
72
85
|
export interface SSEStreamConsumerOptions<TConfig extends ConsumerConfig> {
|
|
73
86
|
url: () => MaybePromise<string>;
|
|
74
87
|
init: () => MaybePromise<EventSourceLike.InitDictOf<TConfig['EventSource']>> | undefined;
|
|
75
88
|
signal: AbortSignal;
|
|
76
89
|
deserialize?: Deserialize;
|
|
77
90
|
EventSource: TConfig['EventSource'];
|
|
78
|
-
/**
|
|
79
|
-
* Reconnect after inactivity in milliseconds
|
|
80
|
-
*/
|
|
81
|
-
reconnectAfterInactivityMs?: number;
|
|
82
91
|
}
|
|
83
92
|
interface ConsumerConfig {
|
|
84
93
|
data: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/sse.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAMpD,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AACrC,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAA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B,CAAC,OAAO,CAAC,GACvC,2BAA2B,CAAC,OAAO,CAAC,GACpC,wBAAwB,CAAC,OAAO,CAAC,GACjC,6BAA6B,CAAC,OAAO,CAAC,CAAC;AAE3C,MAAM,WAAW,wBAAwB,CAAC,OAAO,SAAS,cAAc;IACtE,GAAG,EAAE,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MACF,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,GAChE,SAAS,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,eAAe,CAAC,cAAc,CAAC;CAC7C;AA2BD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,cAAc,EAC9D,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACtC,aAAa,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAqK9C;AAED,eAAO,MAAM,UAAU;;;;;CAKb,CAAC"}
|
|
@@ -11,19 +11,25 @@ var withPing = require('./utils/withPing.js');
|
|
|
11
11
|
|
|
12
12
|
const PING_EVENT = 'ping';
|
|
13
13
|
const SERIALIZED_ERROR_EVENT = 'serialized-error';
|
|
14
|
+
const CONNECTED_EVENT = 'connected';
|
|
14
15
|
/**
|
|
15
16
|
*
|
|
16
17
|
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
17
18
|
*/ function sseStreamProducer(opts) {
|
|
18
19
|
const stream = createReadableStream.createReadableStream();
|
|
19
|
-
stream.controller.enqueue({
|
|
20
|
-
comment: 'connected'
|
|
21
|
-
});
|
|
22
20
|
const { serialize = utils.identity } = opts;
|
|
23
21
|
const ping = {
|
|
24
22
|
enabled: opts.ping?.enabled ?? false,
|
|
25
23
|
intervalMs: opts.ping?.intervalMs ?? 1000
|
|
26
24
|
};
|
|
25
|
+
const client = opts.client ?? {};
|
|
26
|
+
stream.controller.enqueue({
|
|
27
|
+
event: CONNECTED_EVENT,
|
|
28
|
+
data: JSON.stringify(client)
|
|
29
|
+
});
|
|
30
|
+
if (ping.enabled && client.reconnectAfterInactivityMs && ping.intervalMs > client.reconnectAfterInactivityMs) {
|
|
31
|
+
throw new Error(`Ping interval must be less than client reconnect interval to prevent unnecessary reconnection - ping.intervalMs: ${ping.intervalMs} client.reconnectAfterInactivityMs: ${client.reconnectAfterInactivityMs}`);
|
|
32
|
+
}
|
|
27
33
|
utils.run(async ()=>{
|
|
28
34
|
let iterable = opts.data;
|
|
29
35
|
if (opts.emitAndEndImmediately) {
|
|
@@ -137,6 +143,7 @@ async function withTimeout(opts) {
|
|
|
137
143
|
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
138
144
|
*/ function sseStreamConsumer(opts) {
|
|
139
145
|
const { deserialize = (v)=>v } = opts;
|
|
146
|
+
let clientOptions = {};
|
|
140
147
|
const signal = opts.signal;
|
|
141
148
|
let _es = null;
|
|
142
149
|
const createStream = ()=>new ReadableStream({
|
|
@@ -151,9 +158,13 @@ async function withTimeout(opts) {
|
|
|
151
158
|
eventSource: _es,
|
|
152
159
|
event: null
|
|
153
160
|
});
|
|
154
|
-
eventSource.addEventListener(
|
|
161
|
+
eventSource.addEventListener(CONNECTED_EVENT, (_msg)=>{
|
|
162
|
+
const msg = _msg;
|
|
163
|
+
const options = JSON.parse(msg.data);
|
|
164
|
+
clientOptions = options;
|
|
155
165
|
controller.enqueue({
|
|
156
|
-
type: '
|
|
166
|
+
type: 'connected',
|
|
167
|
+
options,
|
|
157
168
|
eventSource
|
|
158
169
|
});
|
|
159
170
|
});
|
|
@@ -228,10 +239,11 @@ async function withTimeout(opts) {
|
|
|
228
239
|
const iterator = {
|
|
229
240
|
async next () {
|
|
230
241
|
let promise = stream.reader.read();
|
|
231
|
-
|
|
242
|
+
const timeoutMs = clientOptions.reconnectAfterInactivityMs;
|
|
243
|
+
if (timeoutMs) {
|
|
232
244
|
promise = withTimeout({
|
|
233
245
|
promise,
|
|
234
|
-
timeoutMs
|
|
246
|
+
timeoutMs,
|
|
235
247
|
onTimeout: async ()=>{
|
|
236
248
|
// Close and release old reader
|
|
237
249
|
await stream.cancel();
|
|
@@ -240,6 +252,7 @@ async function withTimeout(opts) {
|
|
|
240
252
|
return {
|
|
241
253
|
value: {
|
|
242
254
|
type: 'timeout',
|
|
255
|
+
ms: timeoutMs,
|
|
243
256
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
244
257
|
eventSource: _es
|
|
245
258
|
},
|
|
@@ -9,19 +9,25 @@ import { withPing, PING_SYM } from './utils/withPing.mjs';
|
|
|
9
9
|
|
|
10
10
|
const PING_EVENT = 'ping';
|
|
11
11
|
const SERIALIZED_ERROR_EVENT = 'serialized-error';
|
|
12
|
+
const CONNECTED_EVENT = 'connected';
|
|
12
13
|
/**
|
|
13
14
|
*
|
|
14
15
|
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
15
16
|
*/ function sseStreamProducer(opts) {
|
|
16
17
|
const stream = createReadableStream();
|
|
17
|
-
stream.controller.enqueue({
|
|
18
|
-
comment: 'connected'
|
|
19
|
-
});
|
|
20
18
|
const { serialize = identity } = opts;
|
|
21
19
|
const ping = {
|
|
22
20
|
enabled: opts.ping?.enabled ?? false,
|
|
23
21
|
intervalMs: opts.ping?.intervalMs ?? 1000
|
|
24
22
|
};
|
|
23
|
+
const client = opts.client ?? {};
|
|
24
|
+
stream.controller.enqueue({
|
|
25
|
+
event: CONNECTED_EVENT,
|
|
26
|
+
data: JSON.stringify(client)
|
|
27
|
+
});
|
|
28
|
+
if (ping.enabled && client.reconnectAfterInactivityMs && ping.intervalMs > client.reconnectAfterInactivityMs) {
|
|
29
|
+
throw new Error(`Ping interval must be less than client reconnect interval to prevent unnecessary reconnection - ping.intervalMs: ${ping.intervalMs} client.reconnectAfterInactivityMs: ${client.reconnectAfterInactivityMs}`);
|
|
30
|
+
}
|
|
25
31
|
run(async ()=>{
|
|
26
32
|
let iterable = opts.data;
|
|
27
33
|
if (opts.emitAndEndImmediately) {
|
|
@@ -135,6 +141,7 @@ async function withTimeout(opts) {
|
|
|
135
141
|
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
136
142
|
*/ function sseStreamConsumer(opts) {
|
|
137
143
|
const { deserialize = (v)=>v } = opts;
|
|
144
|
+
let clientOptions = {};
|
|
138
145
|
const signal = opts.signal;
|
|
139
146
|
let _es = null;
|
|
140
147
|
const createStream = ()=>new ReadableStream({
|
|
@@ -149,9 +156,13 @@ async function withTimeout(opts) {
|
|
|
149
156
|
eventSource: _es,
|
|
150
157
|
event: null
|
|
151
158
|
});
|
|
152
|
-
eventSource.addEventListener(
|
|
159
|
+
eventSource.addEventListener(CONNECTED_EVENT, (_msg)=>{
|
|
160
|
+
const msg = _msg;
|
|
161
|
+
const options = JSON.parse(msg.data);
|
|
162
|
+
clientOptions = options;
|
|
153
163
|
controller.enqueue({
|
|
154
|
-
type: '
|
|
164
|
+
type: 'connected',
|
|
165
|
+
options,
|
|
155
166
|
eventSource
|
|
156
167
|
});
|
|
157
168
|
});
|
|
@@ -226,10 +237,11 @@ async function withTimeout(opts) {
|
|
|
226
237
|
const iterator = {
|
|
227
238
|
async next () {
|
|
228
239
|
let promise = stream.reader.read();
|
|
229
|
-
|
|
240
|
+
const timeoutMs = clientOptions.reconnectAfterInactivityMs;
|
|
241
|
+
if (timeoutMs) {
|
|
230
242
|
promise = withTimeout({
|
|
231
243
|
promise,
|
|
232
|
-
timeoutMs
|
|
244
|
+
timeoutMs,
|
|
233
245
|
onTimeout: async ()=>{
|
|
234
246
|
// Close and release old reader
|
|
235
247
|
await stream.cancel();
|
|
@@ -238,6 +250,7 @@ async function withTimeout(opts) {
|
|
|
238
250
|
return {
|
|
239
251
|
value: {
|
|
240
252
|
type: 'timeout',
|
|
253
|
+
ms: timeoutMs,
|
|
241
254
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
242
255
|
eventSource: _es
|
|
243
256
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "11.0.0-rc.
|
|
3
|
+
"version": "11.0.0-rc.642+5c904587e",
|
|
4
4
|
"description": "The tRPC server library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -157,5 +157,8 @@
|
|
|
157
157
|
"next": "*",
|
|
158
158
|
"ws": "*"
|
|
159
159
|
},
|
|
160
|
-
"
|
|
160
|
+
"peerDependencies": {
|
|
161
|
+
"typescript": ">=5.6.2"
|
|
162
|
+
},
|
|
163
|
+
"gitHead": "5c904587e6f3e3eaadb1bbd80d6aa38d20c00800"
|
|
161
164
|
}
|
|
@@ -82,7 +82,7 @@ export interface RootConfig<TTypes extends RootTypes> {
|
|
|
82
82
|
enabled?: boolean;
|
|
83
83
|
} & Pick<
|
|
84
84
|
SSEStreamProducerOptions,
|
|
85
|
-
'ping' | 'emitAndEndImmediately' | 'maxDurationMs'
|
|
85
|
+
'ping' | 'emitAndEndImmediately' | 'maxDurationMs' | 'client'
|
|
86
86
|
>;
|
|
87
87
|
experimental?: {};
|
|
88
88
|
}
|
|
@@ -16,7 +16,7 @@ type Deserialize = (value: any) => any;
|
|
|
16
16
|
/**
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
|
-
export interface
|
|
19
|
+
export interface SSEPingOptions {
|
|
20
20
|
/**
|
|
21
21
|
* Enable ping comments sent from the server
|
|
22
22
|
* @default false
|
|
@@ -29,15 +29,22 @@ export interface PingOptions {
|
|
|
29
29
|
intervalMs?: number;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
export interface SSEClientOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Timeout and reconnect after inactivity in milliseconds
|
|
35
|
+
* @default undefined
|
|
36
|
+
*/
|
|
37
|
+
reconnectAfterInactivityMs?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
export interface SSEStreamProducerOptions<TValue = unknown> {
|
|
33
41
|
serialize?: Serialize;
|
|
34
42
|
data: AsyncIterable<TValue>;
|
|
35
43
|
|
|
36
44
|
maxDepth?: number;
|
|
37
|
-
ping?:
|
|
45
|
+
ping?: SSEPingOptions;
|
|
38
46
|
/**
|
|
39
47
|
* Maximum duration in milliseconds for the request before ending the stream
|
|
40
|
-
* Only useful for serverless runtimes
|
|
41
48
|
* @default undefined
|
|
42
49
|
*/
|
|
43
50
|
maxDurationMs?: number;
|
|
@@ -48,10 +55,16 @@ export interface SSEStreamProducerOptions<TValue = unknown> {
|
|
|
48
55
|
*/
|
|
49
56
|
emitAndEndImmediately?: boolean;
|
|
50
57
|
formatError?: (opts: { error: unknown }) => unknown;
|
|
58
|
+
/**
|
|
59
|
+
* Client-specific options - these will be sent to the client as part of the first message
|
|
60
|
+
* @default {}
|
|
61
|
+
*/
|
|
62
|
+
client?: SSEClientOptions;
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
const PING_EVENT = 'ping';
|
|
54
66
|
const SERIALIZED_ERROR_EVENT = 'serialized-error';
|
|
67
|
+
const CONNECTED_EVENT = 'connected';
|
|
55
68
|
|
|
56
69
|
type SSEvent = Partial<{
|
|
57
70
|
id: string;
|
|
@@ -67,14 +80,28 @@ export function sseStreamProducer<TValue = unknown>(
|
|
|
67
80
|
opts: SSEStreamProducerOptions<TValue>,
|
|
68
81
|
) {
|
|
69
82
|
const stream = createReadableStream<SSEvent>();
|
|
70
|
-
stream.controller.enqueue({ comment: 'connected' });
|
|
71
83
|
|
|
72
84
|
const { serialize = identity } = opts;
|
|
73
85
|
|
|
74
|
-
const ping: Required<
|
|
86
|
+
const ping: Required<SSEPingOptions> = {
|
|
75
87
|
enabled: opts.ping?.enabled ?? false,
|
|
76
88
|
intervalMs: opts.ping?.intervalMs ?? 1000,
|
|
77
89
|
};
|
|
90
|
+
const client: SSEClientOptions = opts.client ?? {};
|
|
91
|
+
|
|
92
|
+
stream.controller.enqueue({
|
|
93
|
+
event: CONNECTED_EVENT,
|
|
94
|
+
data: JSON.stringify(client),
|
|
95
|
+
});
|
|
96
|
+
if (
|
|
97
|
+
ping.enabled &&
|
|
98
|
+
client.reconnectAfterInactivityMs &&
|
|
99
|
+
ping.intervalMs > client.reconnectAfterInactivityMs
|
|
100
|
+
) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Ping interval must be less than client reconnect interval to prevent unnecessary reconnection - ping.intervalMs: ${ping.intervalMs} client.reconnectAfterInactivityMs: ${client.reconnectAfterInactivityMs}`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
78
105
|
|
|
79
106
|
run(async () => {
|
|
80
107
|
type TIteratorValue = Awaited<TValue> | typeof PING_SYM;
|
|
@@ -189,11 +216,6 @@ interface ConsumerStreamResultError<TConfig extends ConsumerConfig>
|
|
|
189
216
|
error: TConfig['error'];
|
|
190
217
|
}
|
|
191
218
|
|
|
192
|
-
interface ConsumerStreamResultOpened<TConfig extends ConsumerConfig>
|
|
193
|
-
extends ConsumerStreamResultBase<TConfig> {
|
|
194
|
-
type: 'opened';
|
|
195
|
-
}
|
|
196
|
-
|
|
197
219
|
interface ConsumerStreamResultConnecting<TConfig extends ConsumerConfig>
|
|
198
220
|
extends ConsumerStreamResultBase<TConfig> {
|
|
199
221
|
type: 'connecting';
|
|
@@ -202,20 +224,26 @@ interface ConsumerStreamResultConnecting<TConfig extends ConsumerConfig>
|
|
|
202
224
|
interface ConsumerStreamResultTimeout<TConfig extends ConsumerConfig>
|
|
203
225
|
extends ConsumerStreamResultBase<TConfig> {
|
|
204
226
|
type: 'timeout';
|
|
227
|
+
ms: number;
|
|
205
228
|
}
|
|
206
|
-
|
|
207
229
|
interface ConsumerStreamResultPing<TConfig extends ConsumerConfig>
|
|
208
230
|
extends ConsumerStreamResultBase<TConfig> {
|
|
209
231
|
type: 'ping';
|
|
210
232
|
}
|
|
211
233
|
|
|
234
|
+
interface ConsumerStreamResultConnected<TConfig extends ConsumerConfig>
|
|
235
|
+
extends ConsumerStreamResultBase<TConfig> {
|
|
236
|
+
type: 'connected';
|
|
237
|
+
options: SSEClientOptions;
|
|
238
|
+
}
|
|
239
|
+
|
|
212
240
|
type ConsumerStreamResult<TConfig extends ConsumerConfig> =
|
|
213
241
|
| ConsumerStreamResultData<TConfig>
|
|
214
242
|
| ConsumerStreamResultError<TConfig>
|
|
215
|
-
| ConsumerStreamResultOpened<TConfig>
|
|
216
243
|
| ConsumerStreamResultConnecting<TConfig>
|
|
217
244
|
| ConsumerStreamResultTimeout<TConfig>
|
|
218
|
-
| ConsumerStreamResultPing<TConfig
|
|
245
|
+
| ConsumerStreamResultPing<TConfig>
|
|
246
|
+
| ConsumerStreamResultConnected<TConfig>;
|
|
219
247
|
|
|
220
248
|
export interface SSEStreamConsumerOptions<TConfig extends ConsumerConfig> {
|
|
221
249
|
url: () => MaybePromise<string>;
|
|
@@ -225,10 +253,6 @@ export interface SSEStreamConsumerOptions<TConfig extends ConsumerConfig> {
|
|
|
225
253
|
signal: AbortSignal;
|
|
226
254
|
deserialize?: Deserialize;
|
|
227
255
|
EventSource: TConfig['EventSource'];
|
|
228
|
-
/**
|
|
229
|
-
* Reconnect after inactivity in milliseconds
|
|
230
|
-
*/
|
|
231
|
-
reconnectAfterInactivityMs?: number;
|
|
232
256
|
}
|
|
233
257
|
|
|
234
258
|
interface ConsumerConfig {
|
|
@@ -270,6 +294,8 @@ export function sseStreamConsumer<TConfig extends ConsumerConfig>(
|
|
|
270
294
|
): AsyncIterable<ConsumerStreamResult<TConfig>> {
|
|
271
295
|
const { deserialize = (v) => v } = opts;
|
|
272
296
|
|
|
297
|
+
let clientOptions: SSEClientOptions = {};
|
|
298
|
+
|
|
273
299
|
const signal = opts.signal;
|
|
274
300
|
|
|
275
301
|
let _es: InstanceType<TConfig['EventSource']> | null = null;
|
|
@@ -288,9 +314,15 @@ export function sseStreamConsumer<TConfig extends ConsumerConfig>(
|
|
|
288
314
|
eventSource: _es,
|
|
289
315
|
event: null,
|
|
290
316
|
});
|
|
291
|
-
|
|
317
|
+
|
|
318
|
+
eventSource.addEventListener(CONNECTED_EVENT, (_msg) => {
|
|
319
|
+
const msg = _msg as EventSourceLike.MessageEvent;
|
|
320
|
+
const options: SSEClientOptions = JSON.parse(msg.data);
|
|
321
|
+
|
|
322
|
+
clientOptions = options;
|
|
292
323
|
controller.enqueue({
|
|
293
|
-
type: '
|
|
324
|
+
type: 'connected',
|
|
325
|
+
options,
|
|
294
326
|
eventSource,
|
|
295
327
|
});
|
|
296
328
|
});
|
|
@@ -374,10 +406,11 @@ export function sseStreamConsumer<TConfig extends ConsumerConfig>(
|
|
|
374
406
|
async next() {
|
|
375
407
|
let promise = stream.reader.read();
|
|
376
408
|
|
|
377
|
-
|
|
409
|
+
const timeoutMs = clientOptions.reconnectAfterInactivityMs;
|
|
410
|
+
if (timeoutMs) {
|
|
378
411
|
promise = withTimeout({
|
|
379
412
|
promise,
|
|
380
|
-
timeoutMs
|
|
413
|
+
timeoutMs,
|
|
381
414
|
onTimeout: async () => {
|
|
382
415
|
// Close and release old reader
|
|
383
416
|
await stream.cancel();
|
|
@@ -388,6 +421,7 @@ export function sseStreamConsumer<TConfig extends ConsumerConfig>(
|
|
|
388
421
|
return {
|
|
389
422
|
value: {
|
|
390
423
|
type: 'timeout',
|
|
424
|
+
ms: timeoutMs,
|
|
391
425
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
392
426
|
eventSource: _es!,
|
|
393
427
|
},
|