@trpc/server 11.0.0-rc.553 → 11.0.0-rc.560

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.
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 136392,
3
- "bundleOrigSize": 182813,
4
- "bundleReduction": 25.39,
2
+ "bundleSize": 136868,
3
+ "bundleOrigSize": 183401,
4
+ "bundleReduction": 25.37,
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": 13.52,
17
+ "percent": 13.47,
18
18
  "reduction": 0
19
19
  },
20
20
  {
@@ -31,7 +31,7 @@
31
31
  "/src/unstable-core-do-not-import.ts",
32
32
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
33
33
  ],
34
- "percent": 12.88,
34
+ "percent": 12.83,
35
35
  "reduction": 4.31
36
36
  },
37
37
  {
@@ -47,7 +47,7 @@
47
47
  "dependents": [
48
48
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
49
49
  ],
50
- "percent": 11.94,
50
+ "percent": 11.9,
51
51
  "reduction": 0
52
52
  },
53
53
  {
@@ -62,7 +62,7 @@
62
62
  "/src/unstable-core-do-not-import.ts",
63
63
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
64
64
  ],
65
- "percent": 5.64,
65
+ "percent": 5.62,
66
66
  "reduction": 0
67
67
  },
68
68
  {
@@ -80,13 +80,13 @@
80
80
  "/src/unstable-core-do-not-import.ts",
81
81
  "/src/unstable-core-do-not-import/initTRPC.ts"
82
82
  ],
83
- "percent": 4.71,
83
+ "percent": 4.69,
84
84
  "reduction": 40.09
85
85
  },
86
86
  {
87
87
  "id": "/src/unstable-core-do-not-import/stream/sse.ts",
88
- "size": 5910,
89
- "origSize": 6971,
88
+ "size": 6386,
89
+ "origSize": 7559,
90
90
  "renderedExports": [
91
91
  "sseStreamProducer",
92
92
  "sseStreamConsumer",
@@ -97,8 +97,8 @@
97
97
  "/src/unstable-core-do-not-import.ts",
98
98
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
99
99
  ],
100
- "percent": 4.33,
101
- "reduction": 15.22
100
+ "percent": 4.67,
101
+ "reduction": 15.52
102
102
  },
103
103
  {
104
104
  "id": "/src/unstable-core-do-not-import/procedureBuilder.ts",
@@ -112,7 +112,7 @@
112
112
  "/src/unstable-core-do-not-import.ts",
113
113
  "/src/unstable-core-do-not-import/initTRPC.ts"
114
114
  ],
115
- "percent": 4.25,
115
+ "percent": 4.23,
116
116
  "reduction": 64.74
117
117
  },
118
118
  {
@@ -126,7 +126,7 @@
126
126
  "dependents": [
127
127
  "/src/adapters/aws-lambda/index.ts"
128
128
  ],
129
- "percent": 3.97,
129
+ "percent": 3.96,
130
130
  "reduction": 11.38
131
131
  },
132
132
  {
@@ -146,7 +146,7 @@
146
146
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
147
147
  "/src/observable/operators.ts"
148
148
  ],
149
- "percent": 3.02,
149
+ "percent": 3.01,
150
150
  "reduction": 0
151
151
  },
152
152
  {
@@ -160,7 +160,7 @@
160
160
  "dependents": [
161
161
  "/src/adapters/next-app-dir.ts"
162
162
  ],
163
- "percent": 2.36,
163
+ "percent": 2.35,
164
164
  "reduction": 22.57
165
165
  },
166
166
  {
@@ -174,7 +174,7 @@
174
174
  "dependents": [
175
175
  "/src/adapters/node-http/index.ts"
176
176
  ],
177
- "percent": 2.1,
177
+ "percent": 2.09,
178
178
  "reduction": 6.07
179
179
  },
180
180
  {
@@ -190,7 +190,7 @@
190
190
  "dependents": [
191
191
  "/src/observable/index.ts"
192
192
  ],
193
- "percent": 2.02,
193
+ "percent": 2.01,
194
194
  "reduction": 0
195
195
  },
196
196
  {
@@ -210,7 +210,7 @@
210
210
  "/src/unstable-core-do-not-import/initTRPC.ts",
211
211
  "/src/unstable-core-do-not-import/router.ts"
212
212
  ],
213
- "percent": 2.01,
213
+ "percent": 2,
214
214
  "reduction": 45.94
215
215
  },
216
216
  {
@@ -224,7 +224,7 @@
224
224
  "dependents": [
225
225
  "/src/unstable-core-do-not-import.ts"
226
226
  ],
227
- "percent": 1.98,
227
+ "percent": 1.97,
228
228
  "reduction": 40.98
229
229
  },
230
230
  {
@@ -244,7 +244,7 @@
244
244
  "/src/unstable-core-do-not-import/initTRPC.ts",
245
245
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
246
246
  ],
247
- "percent": 1.93,
247
+ "percent": 1.92,
248
248
  "reduction": 55.78
249
249
  },
250
250
  {
@@ -260,7 +260,7 @@
260
260
  "/src/unstable-core-do-not-import.ts",
261
261
  "/src/unstable-core-do-not-import/router.ts"
262
262
  ],
263
- "percent": 1.71,
263
+ "percent": 1.7,
264
264
  "reduction": 0
265
265
  },
266
266
  {
@@ -289,7 +289,7 @@
289
289
  "/src/adapters/node-http/index.ts",
290
290
  "/src/adapters/node-http/nodeHTTPRequestHandler.ts"
291
291
  ],
292
- "percent": 1.61,
292
+ "percent": 1.6,
293
293
  "reduction": 13.79
294
294
  },
295
295
  {
@@ -353,7 +353,7 @@
353
353
  ],
354
354
  "removedExports": [],
355
355
  "dependents": [],
356
- "percent": 1.25,
356
+ "percent": 1.24,
357
357
  "reduction": 19.29
358
358
  },
359
359
  {
@@ -432,11 +432,11 @@
432
432
  "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
433
433
  "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
434
434
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
435
+ "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
435
436
  "/src/unstable-core-do-not-import/error/TRPCError.ts",
436
437
  "/src/unstable-core-do-not-import/transformer.ts",
437
438
  "/src/unstable-core-do-not-import/middleware.ts",
438
439
  "/src/unstable-core-do-not-import/router.ts",
439
- "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
440
440
  "/src/unstable-core-do-not-import/http/contentType.ts",
441
441
  "/src/unstable-core-do-not-import/procedureBuilder.ts",
442
442
  "/src/unstable-core-do-not-import/stream/jsonl.ts",
@@ -487,7 +487,7 @@
487
487
  "dependents": [
488
488
  "/src/unstable-core-do-not-import.ts"
489
489
  ],
490
- "percent": 0.78,
490
+ "percent": 0.77,
491
491
  "reduction": 0
492
492
  },
493
493
  {
@@ -551,7 +551,7 @@
551
551
  ],
552
552
  "removedExports": [],
553
553
  "dependents": [],
554
- "percent": 0.56,
554
+ "percent": 0.55,
555
555
  "reduction": 66.9
556
556
  },
557
557
  {
@@ -636,7 +636,7 @@
636
636
  ],
637
637
  "removedExports": [],
638
638
  "dependents": [],
639
- "percent": 0.21,
639
+ "percent": 0.2,
640
640
  "reduction": 72.92
641
641
  },
642
642
  {
@@ -725,9 +725,9 @@
725
725
  "reduction": 100
726
726
  },
727
727
  {
728
- "id": "/src/index.ts",
728
+ "id": "/src/rpc.ts",
729
729
  "size": 0,
730
- "origSize": 32,
730
+ "origSize": 36,
731
731
  "renderedExports": [],
732
732
  "removedExports": [],
733
733
  "dependents": [],
@@ -735,9 +735,9 @@
735
735
  "reduction": 100
736
736
  },
737
737
  {
738
- "id": "/src/shared.ts",
738
+ "id": "/src/index.ts",
739
739
  "size": 0,
740
- "origSize": 653,
740
+ "origSize": 32,
741
741
  "renderedExports": [],
742
742
  "removedExports": [],
743
743
  "dependents": [],
@@ -745,9 +745,9 @@
745
745
  "reduction": 100
746
746
  },
747
747
  {
748
- "id": "/src/rpc.ts",
748
+ "id": "/src/shared.ts",
749
749
  "size": 0,
750
- "origSize": 36,
750
+ "origSize": 653,
751
751
  "renderedExports": [],
752
752
  "removedExports": [],
753
753
  "dependents": [],
@@ -789,6 +789,16 @@
789
789
  "percent": 0,
790
790
  "reduction": 100
791
791
  },
792
+ {
793
+ "id": "/src/adapters/fastify/index.ts",
794
+ "size": 0,
795
+ "origSize": 78,
796
+ "renderedExports": [],
797
+ "removedExports": [],
798
+ "dependents": [],
799
+ "percent": 0,
800
+ "reduction": 100
801
+ },
792
802
  {
793
803
  "id": "/src/adapters/fetch/index.ts",
794
804
  "size": 0,
@@ -813,16 +823,6 @@
813
823
  ],
814
824
  "percent": 0,
815
825
  "reduction": 100
816
- },
817
- {
818
- "id": "/src/adapters/fastify/index.ts",
819
- "size": 0,
820
- "origSize": 78,
821
- "renderedExports": [],
822
- "removedExports": [],
823
- "dependents": [],
824
- "percent": 0,
825
- "reduction": 100
826
826
  }
827
827
  ],
828
828
  "moduleCount": 55
@@ -54,9 +54,10 @@ type ConsumerStreamResult<TData> = {
54
54
  * @see https://html.spec.whatwg.org/multipage/server-sent-events.html
55
55
  */
56
56
  export declare function sseStreamConsumer<TData>(opts: {
57
- from: EventSource;
57
+ from: Pick<EventSource, 'addEventListener' | 'readyState'>;
58
58
  onError?: ConsumerOnError;
59
59
  deserialize?: Deserialize;
60
+ tryHandleError?: (error: Event) => Promise<boolean>;
60
61
  }): AsyncIterable<ConsumerStreamResult<TData>>;
61
62
  export declare const sseHeaders: {
62
63
  readonly 'Content-Type': "text/event-stream";
@@ -1 +1 @@
1
- {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/sse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAKpD,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AACrC,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,I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  });
132
132
  }
133
133
  });
134
+ let errorLock = undefined;
134
135
  eventSource.addEventListener('message', (msg)=>{
135
136
  stream.controller.enqueue(msg);
136
137
  });
137
138
  eventSource.addEventListener(SERIALIZED_ERROR_EVENT, (msg)=>{
138
139
  stream.controller.enqueue(msg);
139
140
  });
140
- eventSource.addEventListener('error', (cause)=>{
141
+ eventSource.addEventListener('error', async (cause)=>{
142
+ // We prevent more than 1 error handler from waiting at the same time
143
+ const result = await errorLock;
144
+ if (result === 'CANCEL_ALL') {
145
+ return;
146
+ }
147
+ const resolvable = createDeferred.createDeferred();
148
+ errorLock = resolvable.promise;
149
+ const handled = await opts.tryHandleError?.(cause);
150
+ resolvable.resolve();
151
+ if (handled === true) {
152
+ return;
153
+ }
141
154
  if (eventSource.readyState === EventSource.CLOSED) {
142
155
  stream.controller.error(cause);
143
156
  }
@@ -1,7 +1,7 @@
1
1
  import { getTRPCErrorFromUnknown } from '../error/TRPCError.mjs';
2
2
  import { run } from '../utils.mjs';
3
3
  import { isTrackedEnvelope } from './tracked.mjs';
4
- import { createTimeoutPromise } from './utils/createDeferred.mjs';
4
+ import { createTimeoutPromise, createDeferred } from './utils/createDeferred.mjs';
5
5
  import { createReadableStream } from './utils/createReadableStream.mjs';
6
6
 
7
7
  const SERIALIZED_ERROR_EVENT = 'serialized-error';
@@ -129,13 +129,26 @@ const SERIALIZED_ERROR_EVENT = 'serialized-error';
129
129
  });
130
130
  }
131
131
  });
132
+ let errorLock = undefined;
132
133
  eventSource.addEventListener('message', (msg)=>{
133
134
  stream.controller.enqueue(msg);
134
135
  });
135
136
  eventSource.addEventListener(SERIALIZED_ERROR_EVENT, (msg)=>{
136
137
  stream.controller.enqueue(msg);
137
138
  });
138
- eventSource.addEventListener('error', (cause)=>{
139
+ eventSource.addEventListener('error', async (cause)=>{
140
+ // We prevent more than 1 error handler from waiting at the same time
141
+ const result = await errorLock;
142
+ if (result === 'CANCEL_ALL') {
143
+ return;
144
+ }
145
+ const resolvable = createDeferred();
146
+ errorLock = resolvable.promise;
147
+ const handled = await opts.tryHandleError?.(cause);
148
+ resolvable.resolve();
149
+ if (handled === true) {
150
+ return;
151
+ }
139
152
  if (eventSource.readyState === EventSource.CLOSED) {
140
153
  stream.controller.error(cause);
141
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.553+9b629cc67",
3
+ "version": "11.0.0-rc.560+137b085f8",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -149,5 +149,5 @@
149
149
  "funding": [
150
150
  "https://trpc.io/sponsor"
151
151
  ],
152
- "gitHead": "9b629cc672aad7908af1d5355e3f2dd8f03f048d"
152
+ "gitHead": "137b085f86cb4ceb397b29c69ccbe38a93dbe79a"
153
153
  }
@@ -3,7 +3,7 @@ import { run } from '../utils';
3
3
  import type { ConsumerOnError } from './jsonl';
4
4
  import type { inferTrackedOutput } from './tracked';
5
5
  import { isTrackedEnvelope } from './tracked';
6
- import { createTimeoutPromise } from './utils/createDeferred';
6
+ import { createDeferred, createTimeoutPromise } from './utils/createDeferred';
7
7
  import { createReadableStream } from './utils/createReadableStream';
8
8
 
9
9
  type Serialize = (value: any) => any;
@@ -189,9 +189,10 @@ type ConsumerStreamResult<TData> =
189
189
  * @see https://html.spec.whatwg.org/multipage/server-sent-events.html
190
190
  */
191
191
  export function sseStreamConsumer<TData>(opts: {
192
- from: EventSource;
192
+ from: Pick<EventSource, 'addEventListener' | 'readyState'>;
193
193
  onError?: ConsumerOnError;
194
194
  deserialize?: Deserialize;
195
+ tryHandleError?: (error: Event) => Promise<boolean>;
195
196
  }): AsyncIterable<ConsumerStreamResult<TData>> {
196
197
  const { deserialize = (v) => v } = opts;
197
198
  const eventSource = opts.from;
@@ -227,19 +228,38 @@ export function sseStreamConsumer<TData>(opts: {
227
228
  },
228
229
  });
229
230
 
231
+ let errorLock: Promise<void | 'CANCEL_ALL'> | undefined = undefined;
230
232
  eventSource.addEventListener('message', (msg) => {
231
233
  stream.controller.enqueue(msg);
232
234
  });
233
235
  eventSource.addEventListener(SERIALIZED_ERROR_EVENT, (msg) => {
234
236
  stream.controller.enqueue(msg);
235
237
  });
236
- eventSource.addEventListener('error', (cause) => {
238
+ eventSource.addEventListener('error', async (cause) => {
239
+ // We prevent more than 1 error handler from waiting at the same time
240
+ const result = await errorLock;
241
+ if (result === 'CANCEL_ALL') {
242
+ return;
243
+ }
244
+
245
+ const resolvable = createDeferred<void | 'CANCEL_ALL'>();
246
+ errorLock = resolvable.promise;
247
+
248
+ const handled = await opts.tryHandleError?.(cause);
249
+
250
+ resolvable.resolve();
251
+
252
+ if (handled === true) {
253
+ return;
254
+ }
255
+
237
256
  if (eventSource.readyState === EventSource.CLOSED) {
238
257
  stream.controller.error(cause);
239
258
  }
240
259
  });
241
260
 
242
261
  const readable = stream.readable.pipeThrough(transform);
262
+
243
263
  return {
244
264
  [Symbol.asyncIterator]() {
245
265
  const reader = readable.getReader();