@trpc/server 11.0.0-alpha-tmp-12-06-react.674 → 11.0.0-alpha-tmp-issues-6374.696

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.
Files changed (30) hide show
  1. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  2. package/dist/adapters/node-http/incomingMessageToRequest.d.ts +10 -3
  3. package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
  4. package/dist/adapters/node-http/incomingMessageToRequest.js +8 -6
  5. package/dist/adapters/node-http/incomingMessageToRequest.mjs +8 -6
  6. package/dist/adapters/ws.js +1 -1
  7. package/dist/adapters/ws.mjs +1 -1
  8. package/dist/bundle-analysis.json +128 -112
  9. package/dist/unstable-core-do-not-import/createProxy.d.ts +1 -1
  10. package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -1
  11. package/dist/unstable-core-do-not-import/createProxy.js +2 -1
  12. package/dist/unstable-core-do-not-import/createProxy.mjs +2 -1
  13. package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
  14. package/dist/unstable-core-do-not-import/stream/jsonl.js +154 -188
  15. package/dist/unstable-core-do-not-import/stream/jsonl.mjs +156 -190
  16. package/dist/unstable-core-do-not-import/stream/sse.d.ts +1 -1
  17. package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
  18. package/dist/unstable-core-do-not-import/stream/sse.js +7 -3
  19. package/dist/unstable-core-do-not-import/stream/sse.mjs +7 -3
  20. package/dist/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.d.ts +17 -0
  21. package/dist/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.d.ts.map +1 -0
  22. package/dist/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.js +241 -0
  23. package/dist/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.mjs +239 -0
  24. package/package.json +7 -7
  25. package/src/adapters/fastify/fastifyRequestHandler.ts +2 -2
  26. package/src/adapters/node-http/incomingMessageToRequest.ts +19 -11
  27. package/src/unstable-core-do-not-import/createProxy.ts +3 -2
  28. package/src/unstable-core-do-not-import/stream/jsonl.ts +14 -46
  29. package/src/unstable-core-do-not-import/stream/sse.ts +28 -21
  30. package/src/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.ts +193 -0
@@ -1,8 +1,8 @@
1
- import { Unpromise } from '../../vendor/unpromise/unpromise.mjs';
2
- import { isObject, isFunction, isAsyncIterable, run } from '../utils.mjs';
1
+ import { isObject, isFunction, run, isAsyncIterable } from '../utils.mjs';
3
2
  import { iteratorResource } from './utils/asyncIterable.mjs';
4
3
  import { createDeferred } from './utils/createDeferred.mjs';
5
- import { makeAsyncResource, makeResource } from './utils/disposable.mjs';
4
+ import { makeResource } from './utils/disposable.mjs';
5
+ import { mergeAsyncIterables } from './utils/mergeAsyncIterables.mjs';
6
6
  import { readableStreamFrom } from './utils/readableStreamFrom.mjs';
7
7
 
8
8
  function _define_property(obj, key, value) {
@@ -101,223 +101,189 @@ class MaxDepthError extends Error {
101
101
  }
102
102
  }
103
103
  async function* createBatchStreamProducer(opts) {
104
- const env = {
105
- stack: [],
106
- error: void 0,
107
- hasError: false
108
- };
109
- try {
110
- const { data } = opts;
111
- let counter = 0;
112
- const placeholder = 0;
113
- const queue = _ts_add_disposable_resource(env, makeAsyncResource(new Set(), async ()=>{
114
- await Promise.all(Array.from(queue).map((it)=>it.iterator.return?.()));
115
- }), true);
116
- ;
117
- function registerAsync(callback) {
118
- const idx = counter++;
119
- const iterator = callback(idx)[Symbol.asyncIterator]();
120
- const nextPromise = iterator.next();
121
- nextPromise.catch(()=>{
122
- // prevent unhandled promise rejection
123
- });
124
- queue.add({
125
- iterator,
126
- nextPromise
127
- });
128
- return idx;
129
- }
130
- function encodePromise(promise, path) {
131
- return registerAsync(async function*(idx) {
104
+ const { data } = opts;
105
+ let counter = 0;
106
+ const placeholder = 0;
107
+ const mergedIterables = mergeAsyncIterables();
108
+ function registerAsync(callback) {
109
+ const idx = counter++;
110
+ const iterable = callback(idx);
111
+ mergedIterables.add(iterable);
112
+ return idx;
113
+ }
114
+ function encodePromise(promise, path) {
115
+ return registerAsync(async function*(idx) {
116
+ const error = checkMaxDepth(path);
117
+ if (error) {
118
+ // Catch any errors from the original promise to ensure they're reported
119
+ promise.catch((cause)=>{
120
+ opts.onError?.({
121
+ error: cause,
122
+ path
123
+ });
124
+ });
125
+ // Replace the promise with a rejected one containing the max depth error
126
+ promise = Promise.reject(error);
127
+ }
128
+ try {
129
+ const next = await promise;
130
+ yield [
131
+ idx,
132
+ PROMISE_STATUS_FULFILLED,
133
+ encode(next, path)
134
+ ];
135
+ } catch (cause) {
136
+ opts.onError?.({
137
+ error: cause,
138
+ path
139
+ });
140
+ yield [
141
+ idx,
142
+ PROMISE_STATUS_REJECTED,
143
+ opts.formatError?.({
144
+ error: cause,
145
+ path
146
+ })
147
+ ];
148
+ }
149
+ });
150
+ }
151
+ function encodeAsyncIterable(iterable, path) {
152
+ return registerAsync(async function*(idx) {
153
+ const env = {
154
+ stack: [],
155
+ error: void 0,
156
+ hasError: false
157
+ };
158
+ try {
132
159
  const error = checkMaxDepth(path);
133
160
  if (error) {
134
- // Catch any errors from the original promise to ensure they're reported
135
- promise.catch((cause)=>{
136
- opts.onError?.({
137
- error: cause,
138
- path
139
- });
140
- });
141
- // Replace the promise with a rejected one containing the max depth error
142
- promise = Promise.reject(error);
161
+ throw error;
143
162
  }
163
+ const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
164
+ ;
144
165
  try {
145
- const next = await promise;
146
- return [
147
- idx,
148
- PROMISE_STATUS_FULFILLED,
149
- encode(next, path)
150
- ];
166
+ while(true){
167
+ const next = await iterator.next();
168
+ if (next.done) {
169
+ yield [
170
+ idx,
171
+ ASYNC_ITERABLE_STATUS_RETURN,
172
+ encode(next.value, path)
173
+ ];
174
+ break;
175
+ }
176
+ yield [
177
+ idx,
178
+ ASYNC_ITERABLE_STATUS_YIELD,
179
+ encode(next.value, path)
180
+ ];
181
+ }
151
182
  } catch (cause) {
152
183
  opts.onError?.({
153
184
  error: cause,
154
185
  path
155
186
  });
156
- return [
187
+ yield [
157
188
  idx,
158
- PROMISE_STATUS_REJECTED,
189
+ ASYNC_ITERABLE_STATUS_ERROR,
159
190
  opts.formatError?.({
160
191
  error: cause,
161
192
  path
162
193
  })
163
194
  ];
164
195
  }
165
- });
196
+ } catch (e) {
197
+ env.error = e;
198
+ env.hasError = true;
199
+ } finally{
200
+ const result = _ts_dispose_resources(env);
201
+ if (result) await result;
202
+ }
203
+ });
204
+ }
205
+ function checkMaxDepth(path) {
206
+ if (opts.maxDepth && path.length > opts.maxDepth) {
207
+ return new MaxDepthError(path);
166
208
  }
167
- function encodeAsyncIterable(iterable, path) {
168
- return registerAsync(async function*(idx) {
169
- const env = {
170
- stack: [],
171
- error: void 0,
172
- hasError: false
173
- };
174
- try {
175
- const error = checkMaxDepth(path);
176
- if (error) {
177
- throw error;
178
- }
179
- const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
180
- ;
181
- try {
182
- while(true){
183
- const next = await iterator.next();
184
- if (next.done) {
185
- return [
186
- idx,
187
- ASYNC_ITERABLE_STATUS_RETURN,
188
- encode(next.value, path)
189
- ];
190
- }
191
- yield [
192
- idx,
193
- ASYNC_ITERABLE_STATUS_YIELD,
194
- encode(next.value, path)
195
- ];
196
- }
197
- } catch (cause) {
198
- opts.onError?.({
199
- error: cause,
200
- path
201
- });
202
- return [
203
- idx,
204
- ASYNC_ITERABLE_STATUS_ERROR,
205
- opts.formatError?.({
206
- error: cause,
207
- path
208
- })
209
- ];
210
- }
211
- } catch (e) {
212
- env.error = e;
213
- env.hasError = true;
214
- } finally{
215
- const result = _ts_dispose_resources(env);
216
- if (result) await result;
217
- }
218
- });
209
+ return null;
210
+ }
211
+ function encodeAsync(value, path) {
212
+ if (isPromise(value)) {
213
+ return [
214
+ CHUNK_VALUE_TYPE_PROMISE,
215
+ encodePromise(value, path)
216
+ ];
219
217
  }
220
- function checkMaxDepth(path) {
221
- if (opts.maxDepth && path.length > opts.maxDepth) {
222
- return new MaxDepthError(path);
218
+ if (isAsyncIterable(value)) {
219
+ if (opts.maxDepth && path.length >= opts.maxDepth) {
220
+ throw new Error('Max depth reached');
223
221
  }
224
- return null;
222
+ return [
223
+ CHUNK_VALUE_TYPE_ASYNC_ITERABLE,
224
+ encodeAsyncIterable(value, path)
225
+ ];
225
226
  }
226
- function encodeAsync(value, path) {
227
- if (isPromise(value)) {
228
- return [
229
- CHUNK_VALUE_TYPE_PROMISE,
230
- encodePromise(value, path)
231
- ];
232
- }
233
- if (isAsyncIterable(value)) {
234
- if (opts.maxDepth && path.length >= opts.maxDepth) {
235
- throw new Error('Max depth reached');
236
- }
237
- return [
238
- CHUNK_VALUE_TYPE_ASYNC_ITERABLE,
239
- encodeAsyncIterable(value, path)
240
- ];
241
- }
242
- return null;
227
+ return null;
228
+ }
229
+ function encode(value, path) {
230
+ if (value === undefined) {
231
+ return [
232
+ []
233
+ ];
243
234
  }
244
- function encode(value, path) {
245
- if (value === undefined) {
246
- return [
247
- []
248
- ];
249
- }
250
- if (!isObject(value)) {
251
- return [
252
- [
253
- value
254
- ]
255
- ];
256
- }
257
- const reg = encodeAsync(value, path);
258
- if (reg) {
259
- return [
260
- [
261
- placeholder
262
- ],
263
- [
264
- null,
265
- ...reg
266
- ]
267
- ];
268
- }
269
- const newObj = {};
270
- const asyncValues = [];
271
- for (const [key, item] of Object.entries(value)){
272
- const transformed = encodeAsync(item, [
273
- ...path,
274
- key
275
- ]);
276
- if (!transformed) {
277
- newObj[key] = item;
278
- continue;
279
- }
280
- newObj[key] = placeholder;
281
- asyncValues.push([
282
- key,
283
- ...transformed
284
- ]);
285
- }
235
+ if (!isObject(value)) {
236
+ return [
237
+ [
238
+ value
239
+ ]
240
+ ];
241
+ }
242
+ const reg = encodeAsync(value, path);
243
+ if (reg) {
286
244
  return [
287
245
  [
288
- newObj
246
+ placeholder
289
247
  ],
290
- ...asyncValues
248
+ [
249
+ null,
250
+ ...reg
251
+ ]
291
252
  ];
292
253
  }
293
- const newHead = {};
294
- for (const [key, item] of Object.entries(data)){
295
- newHead[key] = encode(item, [
254
+ const newObj = {};
255
+ const asyncValues = [];
256
+ for (const [key, item] of Object.entries(value)){
257
+ const transformed = encodeAsync(item, [
258
+ ...path,
296
259
  key
297
260
  ]);
298
- }
299
- yield newHead;
300
- // Process all async iterables in parallel by racing their next values
301
- while(queue.size > 0){
302
- // Race all iterators to get the next value from any of them
303
- const [entry, res] = await Unpromise.race(Array.from(queue).map(async (it)=>[
304
- it,
305
- await it.nextPromise
306
- ]));
307
- yield res.value;
308
- // Remove current iterator and re-add if not done
309
- queue.delete(entry);
310
- if (!res.done) {
311
- entry.nextPromise = entry.iterator.next();
312
- queue.add(entry);
261
+ if (!transformed) {
262
+ newObj[key] = item;
263
+ continue;
313
264
  }
265
+ newObj[key] = placeholder;
266
+ asyncValues.push([
267
+ key,
268
+ ...transformed
269
+ ]);
314
270
  }
315
- } catch (e) {
316
- env.error = e;
317
- env.hasError = true;
318
- } finally{
319
- const result = _ts_dispose_resources(env);
320
- if (result) await result;
271
+ return [
272
+ [
273
+ newObj
274
+ ],
275
+ ...asyncValues
276
+ ];
277
+ }
278
+ const newHead = {};
279
+ for (const [key, item] of Object.entries(data)){
280
+ newHead[key] = encode(item, [
281
+ key
282
+ ]);
283
+ }
284
+ yield newHead;
285
+ for await (const value of mergedIterables){
286
+ yield value;
321
287
  }
322
288
  }
323
289
  /**
@@ -54,7 +54,7 @@ export interface SSEStreamProducerOptions<TValue = unknown> {
54
54
  *
55
55
  * @see https://html.spec.whatwg.org/multipage/server-sent-events.html
56
56
  */
57
- export declare function sseStreamProducer<TValue = unknown>(opts: SSEStreamProducerOptions<TValue>): ReadableStream<string>;
57
+ export declare function sseStreamProducer<TValue = unknown>(opts: SSEStreamProducerOptions<TValue>): ReadableStream<Uint8Array<ArrayBufferLike>>;
58
58
  interface ConsumerStreamResultBase<TConfig extends ConsumerConfig> {
59
59
  eventSource: InstanceType<TConfig['EventSource']> | null;
60
60
  }
@@ -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;AAWpD,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,cAAc;IAC7B;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,wBAAwB,CAAC,MAAM,GAAG,OAAO;IACxD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAE5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC;IACpD;;;OAGG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAYD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,GAAG,OAAO,EAChD,IAAI,EAAE,wBA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,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;AAgBD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,cAAc,EAC9D,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACtC,aAAa,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAiK9C;AAED,eAAO,MAAM,UAAU;;;;;CAKb,CAAC"}
@@ -174,7 +174,7 @@ const CONNECTED_EVENT = 'connected';
174
174
  }
175
175
  controller.enqueue('\n\n');
176
176
  }
177
- }));
177
+ })).pipeThrough(new TextEncoderStream());
178
178
  }
179
179
  async function withTimeout(opts) {
180
180
  const env = {
@@ -270,8 +270,12 @@ async function withTimeout(opts) {
270
270
  });
271
271
  });
272
272
  const onAbort = ()=>{
273
- controller.close();
274
- eventSource.close();
273
+ try {
274
+ eventSource.close();
275
+ controller.close();
276
+ } catch {
277
+ // ignore errors in case the controller is already closed
278
+ }
275
279
  };
276
280
  if (signal.aborted) {
277
281
  onAbort();
@@ -172,7 +172,7 @@ const CONNECTED_EVENT = 'connected';
172
172
  }
173
173
  controller.enqueue('\n\n');
174
174
  }
175
- }));
175
+ })).pipeThrough(new TextEncoderStream());
176
176
  }
177
177
  async function withTimeout(opts) {
178
178
  const env = {
@@ -268,8 +268,12 @@ async function withTimeout(opts) {
268
268
  });
269
269
  });
270
270
  const onAbort = ()=>{
271
- controller.close();
272
- eventSource.close();
271
+ try {
272
+ eventSource.close();
273
+ controller.close();
274
+ } catch {
275
+ // ignore errors in case the controller is already closed
276
+ }
273
277
  };
274
278
  if (signal.aborted) {
275
279
  onAbort();
@@ -0,0 +1,17 @@
1
+ interface MergedAsyncIterables<TYield> extends AsyncIterable<TYield, void, unknown> {
2
+ add(iterable: AsyncIterable<TYield>): void;
3
+ }
4
+ /**
5
+ * Creates a new async iterable that merges multiple async iterables into a single stream.
6
+ * Values from the input iterables are yielded in the order they resolve, similar to Promise.race().
7
+ *
8
+ * New iterables can be added dynamically using the returned {@link MergedAsyncIterables.add} method, even after iteration has started.
9
+ *
10
+ * If any of the input iterables throws an error, that error will be propagated through the merged stream.
11
+ * Other iterables will not continue to be processed.
12
+ *
13
+ * @template TYield The type of values yielded by the input iterables
14
+ */
15
+ export declare function mergeAsyncIterables<TYield>(): MergedAsyncIterables<TYield>;
16
+ export {};
17
+ //# sourceMappingURL=mergeAsyncIterables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeAsyncIterables.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.ts"],"names":[],"mappings":"AAyDA,UAAU,oBAAoB,CAAC,MAAM,CACnC,SAAQ,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;IAC5C,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,KAAK,oBAAoB,CAAC,MAAM,CAAC,CAuH1E"}