@trpc/server 11.0.0-rc.637 → 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/adapters/aws-lambda/index.js +1 -1
- package/dist/adapters/aws-lambda/index.mjs +1 -1
- package/dist/adapters/express.js +1 -1
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.mjs +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +1 -1
- package/dist/adapters/next-app-dir/notFound.js +1 -1
- package/dist/adapters/next-app-dir/notFound.mjs +1 -1
- package/dist/adapters/next-app-dir/redirect.js +1 -1
- package/dist/adapters/next-app-dir/redirect.mjs +1 -1
- package/dist/adapters/next.js +1 -1
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +1 -1
- package/dist/adapters/node-http/writeResponse.js +1 -1
- package/dist/adapters/node-http/writeResponse.mjs +1 -1
- package/dist/adapters/standalone.js +1 -1
- package/dist/adapters/standalone.mjs +1 -1
- package/dist/adapters/ws.js +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/bundle-analysis.json +107 -107
- package/dist/http.js +1 -1
- package/dist/http.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/rpc.js +1 -1
- package/dist/rpc.mjs +1 -1
- package/dist/shared.js +1 -1
- package/dist/shared.mjs +1 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.js +0 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +0 -1
- 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/jsonl.d.ts +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.js +73 -47
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +73 -47
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +20 -12
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +22 -11
- package/dist/unstable-core-do-not-import/stream/sse.mjs +22 -11
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +0 -2
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +5 -8
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +3 -6
- package/dist/unstable-core-do-not-import/stream/utils/{disposablePromiseTimer.d.ts → timerResource.d.ts} +2 -2
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/{disposablePromiseTimer.js → timerResource.js} +2 -2
- package/dist/unstable-core-do-not-import/stream/utils/{disposablePromiseTimer.mjs → timerResource.mjs} +2 -2
- package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/withPing.js +3 -3
- package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +2 -2
- package/package.json +7 -3
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +0 -1
- package/src/unstable-core-do-not-import/rootConfig.ts +1 -1
- package/src/unstable-core-do-not-import/stream/jsonl.ts +81 -51
- package/src/unstable-core-do-not-import/stream/sse.ts +56 -24
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +5 -11
- package/src/unstable-core-do-not-import/stream/utils/{disposablePromiseTimer.ts → timerResource.ts} +1 -1
- package/src/unstable-core-do-not-import/stream/utils/withPing.ts +2 -5
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts +0 -7
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts.map +0 -1
- package/src/unstable-core-do-not-import/stream/utils/createServer.ts +0 -44
|
@@ -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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K,GAAG,IACvC,SAAS,CACX,MAAM,SAAS,QAAQ,GAAG,IAAI,GAAG,KAAK,EACtC;IACE;;QAEI;IACJ,aAAa,EAAE,SAAS,CAAC;CAC1B,CACF,CAAC"}
|
|
@@ -102,7 +102,7 @@ export declare function jsonlStreamConsumer<THead>(opts: {
|
|
|
102
102
|
*/
|
|
103
103
|
abortController: AbortController;
|
|
104
104
|
}): Promise<readonly [Awaited<THead>, {
|
|
105
|
-
readonly controllers:
|
|
105
|
+
readonly controllers: Map<ChunkIndex, ReadableStreamDefaultController<ChunkData | StreamInterruptedError>>;
|
|
106
106
|
}]>;
|
|
107
107
|
export {};
|
|
108
108
|
//# sourceMappingURL=jsonl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonl.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/jsonl.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CACA,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACjC,yBAAyB,CAAC;CAC9B,CAAC;AAGF,QAAA,MAAM,wBAAwB,IAAI,CAAC;AACnC,KAAK,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAChE,QAAA,MAAM,+BAA+B,IAAI,CAAC;AAC1C,KAAK,+BAA+B,GAAG,OAAO,+BAA+B,CAAC;AAE9E,QAAA,MAAM,wBAAwB,IAAI,CAAC;AACnC,KAAK,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAChE,QAAA,MAAM,uBAAuB,IAAI,CAAC;AAClC,KAAK,uBAAuB,GAAG,OAAO,uBAAuB,CAAC;AAE9D,QAAA,MAAM,4BAA4B,IA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,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,CAAC;IAC1C,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,SAAS,CAAA;KAAE,KAAK,OAAO,CAAC;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAiKD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,8BA2BxD;AAED,cAAM,sBAAuB,SAAQ,KAAK;gBAC5B,KAAK,CAAC,EAAE,OAAO;CAK5B;AAMD,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,CAAC;AAgFjE;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE;IACrD,IAAI,EAAE,yBAAyB,GAAG,sBAAsB,CAAC;IACzD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,KAAK,CAAC;IAClD;;OAEG;IACH,eAAe,EAAE,eAAe,CAAC;CAClC;;IA0NA"}
|
|
@@ -318,13 +318,27 @@ function createConsumerStream(from) {
|
|
|
318
318
|
}));
|
|
319
319
|
}
|
|
320
320
|
let headDeferred = createDeferred.createDeferred();
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
/**
|
|
322
|
+
* This is needed as new values can come in before the controller has read the chunk
|
|
323
|
+
* Not pretty, could likely be refactored and omitted somehow
|
|
324
|
+
*/ const chunkDeferred = new Map();
|
|
325
|
+
const controllers = new Map();
|
|
326
|
+
const maybeAbort = ()=>{
|
|
327
|
+
if (chunkDeferred.size === 0 && controllers.size === 0) {
|
|
328
|
+
// nothing is listening to the stream anymore
|
|
329
|
+
opts.abortController?.abort();
|
|
330
|
+
}
|
|
331
|
+
};
|
|
324
332
|
function decodeChunkDefinition(value) {
|
|
325
333
|
const [_path, type, chunkId] = value;
|
|
326
334
|
const stream = createReadableStream.createReadableStream();
|
|
327
335
|
controllers.set(chunkId, stream.controller);
|
|
336
|
+
// resolve chunk deferred if it exists
|
|
337
|
+
const deferred = chunkDeferred.get(chunkId);
|
|
338
|
+
if (deferred) {
|
|
339
|
+
deferred.resolve(stream.controller);
|
|
340
|
+
chunkDeferred.delete(chunkId);
|
|
341
|
+
}
|
|
328
342
|
switch(type){
|
|
329
343
|
case CHUNK_VALUE_TYPE_PROMISE:
|
|
330
344
|
{
|
|
@@ -354,58 +368,61 @@ function createConsumerStream(from) {
|
|
|
354
368
|
}
|
|
355
369
|
}).catch(reject).finally(()=>{
|
|
356
370
|
controllers.delete(chunkId);
|
|
371
|
+
maybeAbort();
|
|
357
372
|
});
|
|
358
373
|
});
|
|
359
374
|
}
|
|
360
375
|
case CHUNK_VALUE_TYPE_ASYNC_ITERABLE:
|
|
361
376
|
{
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
case ASYNC_ITERABLE_STATUS_RETURN:
|
|
386
|
-
controllers.delete(chunkId);
|
|
387
|
-
return {
|
|
388
|
-
done: true,
|
|
389
|
-
value: decode(data)
|
|
390
|
-
};
|
|
391
|
-
case ASYNC_ITERABLE_STATUS_ERROR:
|
|
392
|
-
controllers.delete(chunkId);
|
|
393
|
-
throw opts.formatError?.({
|
|
394
|
-
error: data
|
|
395
|
-
}) ?? new AsyncError(data);
|
|
396
|
-
}
|
|
397
|
-
},
|
|
398
|
-
return: async ()=>{
|
|
377
|
+
const reader = stream.readable.getReader();
|
|
378
|
+
const iterator = {
|
|
379
|
+
next: async ()=>{
|
|
380
|
+
const { done, value } = await reader.read();
|
|
381
|
+
if (value instanceof StreamInterruptedError) {
|
|
382
|
+
throw value;
|
|
383
|
+
}
|
|
384
|
+
if (done) {
|
|
385
|
+
controllers.delete(chunkId);
|
|
386
|
+
maybeAbort();
|
|
387
|
+
return {
|
|
388
|
+
done: true,
|
|
389
|
+
value: undefined
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
const [_chunkId, status, data] = value;
|
|
393
|
+
switch(status){
|
|
394
|
+
case ASYNC_ITERABLE_STATUS_VALUE:
|
|
395
|
+
return {
|
|
396
|
+
done: false,
|
|
397
|
+
value: decode(data)
|
|
398
|
+
};
|
|
399
|
+
case ASYNC_ITERABLE_STATUS_RETURN:
|
|
399
400
|
controllers.delete(chunkId);
|
|
401
|
+
maybeAbort();
|
|
400
402
|
return {
|
|
401
403
|
done: true,
|
|
402
|
-
value:
|
|
404
|
+
value: decode(data)
|
|
403
405
|
};
|
|
404
|
-
|
|
406
|
+
case ASYNC_ITERABLE_STATUS_ERROR:
|
|
407
|
+
controllers.delete(chunkId);
|
|
408
|
+
maybeAbort();
|
|
409
|
+
throw opts.formatError?.({
|
|
410
|
+
error: data
|
|
411
|
+
}) ?? new AsyncError(data);
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
return: async ()=>{
|
|
415
|
+
controllers.delete(chunkId);
|
|
416
|
+
maybeAbort();
|
|
417
|
+
return {
|
|
418
|
+
done: true,
|
|
419
|
+
value: undefined
|
|
405
420
|
};
|
|
406
|
-
return iterator;
|
|
407
421
|
}
|
|
408
422
|
};
|
|
423
|
+
return {
|
|
424
|
+
[Symbol.asyncIterator]: ()=>iterator
|
|
425
|
+
};
|
|
409
426
|
}
|
|
410
427
|
}
|
|
411
428
|
}
|
|
@@ -440,18 +457,27 @@ function createConsumerStream(from) {
|
|
|
440
457
|
}
|
|
441
458
|
headDeferred.resolve(head);
|
|
442
459
|
headDeferred = null;
|
|
443
|
-
controllers.activate();
|
|
444
460
|
return;
|
|
445
461
|
}
|
|
446
462
|
const chunk = chunkOrHead;
|
|
447
463
|
const [idx] = chunk;
|
|
448
464
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
449
|
-
|
|
450
|
-
|
|
465
|
+
let readController = controllers.get(idx);
|
|
466
|
+
if (!readController) {
|
|
467
|
+
let deferred = chunkDeferred.get(idx);
|
|
468
|
+
if (!deferred) {
|
|
469
|
+
deferred = createDeferred.createDeferred();
|
|
470
|
+
chunkDeferred.set(idx, deferred);
|
|
471
|
+
}
|
|
472
|
+
readController = await deferred.promise;
|
|
473
|
+
}
|
|
474
|
+
readController.enqueue(chunk);
|
|
451
475
|
},
|
|
452
476
|
close: closeOrAbort,
|
|
453
477
|
abort: closeOrAbort
|
|
454
|
-
})
|
|
478
|
+
}), {
|
|
479
|
+
signal: opts.abortController.signal
|
|
480
|
+
}).catch((error)=>{
|
|
455
481
|
opts.onError?.({
|
|
456
482
|
error
|
|
457
483
|
});
|
|
@@ -316,13 +316,27 @@ function createConsumerStream(from) {
|
|
|
316
316
|
}));
|
|
317
317
|
}
|
|
318
318
|
let headDeferred = createDeferred();
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
319
|
+
/**
|
|
320
|
+
* This is needed as new values can come in before the controller has read the chunk
|
|
321
|
+
* Not pretty, could likely be refactored and omitted somehow
|
|
322
|
+
*/ const chunkDeferred = new Map();
|
|
323
|
+
const controllers = new Map();
|
|
324
|
+
const maybeAbort = ()=>{
|
|
325
|
+
if (chunkDeferred.size === 0 && controllers.size === 0) {
|
|
326
|
+
// nothing is listening to the stream anymore
|
|
327
|
+
opts.abortController?.abort();
|
|
328
|
+
}
|
|
329
|
+
};
|
|
322
330
|
function decodeChunkDefinition(value) {
|
|
323
331
|
const [_path, type, chunkId] = value;
|
|
324
332
|
const stream = createReadableStream();
|
|
325
333
|
controllers.set(chunkId, stream.controller);
|
|
334
|
+
// resolve chunk deferred if it exists
|
|
335
|
+
const deferred = chunkDeferred.get(chunkId);
|
|
336
|
+
if (deferred) {
|
|
337
|
+
deferred.resolve(stream.controller);
|
|
338
|
+
chunkDeferred.delete(chunkId);
|
|
339
|
+
}
|
|
326
340
|
switch(type){
|
|
327
341
|
case CHUNK_VALUE_TYPE_PROMISE:
|
|
328
342
|
{
|
|
@@ -352,58 +366,61 @@ function createConsumerStream(from) {
|
|
|
352
366
|
}
|
|
353
367
|
}).catch(reject).finally(()=>{
|
|
354
368
|
controllers.delete(chunkId);
|
|
369
|
+
maybeAbort();
|
|
355
370
|
});
|
|
356
371
|
});
|
|
357
372
|
}
|
|
358
373
|
case CHUNK_VALUE_TYPE_ASYNC_ITERABLE:
|
|
359
374
|
{
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
case ASYNC_ITERABLE_STATUS_RETURN:
|
|
384
|
-
controllers.delete(chunkId);
|
|
385
|
-
return {
|
|
386
|
-
done: true,
|
|
387
|
-
value: decode(data)
|
|
388
|
-
};
|
|
389
|
-
case ASYNC_ITERABLE_STATUS_ERROR:
|
|
390
|
-
controllers.delete(chunkId);
|
|
391
|
-
throw opts.formatError?.({
|
|
392
|
-
error: data
|
|
393
|
-
}) ?? new AsyncError(data);
|
|
394
|
-
}
|
|
395
|
-
},
|
|
396
|
-
return: async ()=>{
|
|
375
|
+
const reader = stream.readable.getReader();
|
|
376
|
+
const iterator = {
|
|
377
|
+
next: async ()=>{
|
|
378
|
+
const { done, value } = await reader.read();
|
|
379
|
+
if (value instanceof StreamInterruptedError) {
|
|
380
|
+
throw value;
|
|
381
|
+
}
|
|
382
|
+
if (done) {
|
|
383
|
+
controllers.delete(chunkId);
|
|
384
|
+
maybeAbort();
|
|
385
|
+
return {
|
|
386
|
+
done: true,
|
|
387
|
+
value: undefined
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
const [_chunkId, status, data] = value;
|
|
391
|
+
switch(status){
|
|
392
|
+
case ASYNC_ITERABLE_STATUS_VALUE:
|
|
393
|
+
return {
|
|
394
|
+
done: false,
|
|
395
|
+
value: decode(data)
|
|
396
|
+
};
|
|
397
|
+
case ASYNC_ITERABLE_STATUS_RETURN:
|
|
397
398
|
controllers.delete(chunkId);
|
|
399
|
+
maybeAbort();
|
|
398
400
|
return {
|
|
399
401
|
done: true,
|
|
400
|
-
value:
|
|
402
|
+
value: decode(data)
|
|
401
403
|
};
|
|
402
|
-
|
|
404
|
+
case ASYNC_ITERABLE_STATUS_ERROR:
|
|
405
|
+
controllers.delete(chunkId);
|
|
406
|
+
maybeAbort();
|
|
407
|
+
throw opts.formatError?.({
|
|
408
|
+
error: data
|
|
409
|
+
}) ?? new AsyncError(data);
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
return: async ()=>{
|
|
413
|
+
controllers.delete(chunkId);
|
|
414
|
+
maybeAbort();
|
|
415
|
+
return {
|
|
416
|
+
done: true,
|
|
417
|
+
value: undefined
|
|
403
418
|
};
|
|
404
|
-
return iterator;
|
|
405
419
|
}
|
|
406
420
|
};
|
|
421
|
+
return {
|
|
422
|
+
[Symbol.asyncIterator]: ()=>iterator
|
|
423
|
+
};
|
|
407
424
|
}
|
|
408
425
|
}
|
|
409
426
|
}
|
|
@@ -438,18 +455,27 @@ function createConsumerStream(from) {
|
|
|
438
455
|
}
|
|
439
456
|
headDeferred.resolve(head);
|
|
440
457
|
headDeferred = null;
|
|
441
|
-
controllers.activate();
|
|
442
458
|
return;
|
|
443
459
|
}
|
|
444
460
|
const chunk = chunkOrHead;
|
|
445
461
|
const [idx] = chunk;
|
|
446
462
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
447
|
-
|
|
448
|
-
|
|
463
|
+
let readController = controllers.get(idx);
|
|
464
|
+
if (!readController) {
|
|
465
|
+
let deferred = chunkDeferred.get(idx);
|
|
466
|
+
if (!deferred) {
|
|
467
|
+
deferred = createDeferred();
|
|
468
|
+
chunkDeferred.set(idx, deferred);
|
|
469
|
+
}
|
|
470
|
+
readController = await deferred.promise;
|
|
471
|
+
}
|
|
472
|
+
readController.enqueue(chunk);
|
|
449
473
|
},
|
|
450
474
|
close: closeOrAbort,
|
|
451
475
|
abort: closeOrAbort
|
|
452
|
-
})
|
|
476
|
+
}), {
|
|
477
|
+
signal: opts.abortController.signal
|
|
478
|
+
}).catch((error)=>{
|
|
453
479
|
opts.onError?.({
|
|
454
480
|
error
|
|
455
481
|
});
|
|
@@ -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,15 +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
|
-
abortCtrl: AbortController;
|
|
25
31
|
maxDepth?: number;
|
|
26
|
-
ping?:
|
|
32
|
+
ping?: SSEPingOptions;
|
|
27
33
|
/**
|
|
28
34
|
* Maximum duration in milliseconds for the request before ending the stream
|
|
29
|
-
* Only useful for serverless runtimes
|
|
30
35
|
* @default undefined
|
|
31
36
|
*/
|
|
32
37
|
maxDurationMs?: number;
|
|
@@ -39,6 +44,11 @@ export interface SSEStreamProducerOptions<TValue = unknown> {
|
|
|
39
44
|
formatError?: (opts: {
|
|
40
45
|
error: unknown;
|
|
41
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;
|
|
42
52
|
}
|
|
43
53
|
/**
|
|
44
54
|
*
|
|
@@ -56,30 +66,28 @@ interface ConsumerStreamResultError<TConfig extends ConsumerConfig> extends Cons
|
|
|
56
66
|
type: 'serialized-error';
|
|
57
67
|
error: TConfig['error'];
|
|
58
68
|
}
|
|
59
|
-
interface ConsumerStreamResultOpened<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
60
|
-
type: 'opened';
|
|
61
|
-
}
|
|
62
69
|
interface ConsumerStreamResultConnecting<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
63
70
|
type: 'connecting';
|
|
64
71
|
event: EventSourceLike.EventOf<TConfig['EventSource']> | null;
|
|
65
72
|
}
|
|
66
73
|
interface ConsumerStreamResultTimeout<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
67
74
|
type: 'timeout';
|
|
75
|
+
ms: number;
|
|
68
76
|
}
|
|
69
77
|
interface ConsumerStreamResultPing<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
70
78
|
type: 'ping';
|
|
71
79
|
}
|
|
72
|
-
|
|
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>;
|
|
73
85
|
export interface SSEStreamConsumerOptions<TConfig extends ConsumerConfig> {
|
|
74
86
|
url: () => MaybePromise<string>;
|
|
75
87
|
init: () => MaybePromise<EventSourceLike.InitDictOf<TConfig['EventSource']>> | undefined;
|
|
76
88
|
signal: AbortSignal;
|
|
77
89
|
deserialize?: Deserialize;
|
|
78
90
|
EventSource: TConfig['EventSource'];
|
|
79
|
-
/**
|
|
80
|
-
* Reconnect after inactivity in milliseconds
|
|
81
|
-
*/
|
|
82
|
-
reconnectAfterInactivityMs?: number;
|
|
83
91
|
}
|
|
84
92
|
interface ConsumerConfig {
|
|
85
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,GAAG,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,
|
|
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,U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E,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,32 +11,36 @@ 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) {
|
|
30
36
|
iterable = asyncIterable.takeWithGrace(iterable, {
|
|
31
37
|
count: 1,
|
|
32
|
-
gracePeriodMs: 1
|
|
33
|
-
abortCtrl: opts.abortCtrl
|
|
38
|
+
gracePeriodMs: 1
|
|
34
39
|
});
|
|
35
40
|
}
|
|
36
41
|
if (opts.maxDurationMs && opts.maxDurationMs > 0 && opts.maxDurationMs !== Infinity) {
|
|
37
42
|
iterable = asyncIterable.withMaxDuration(iterable, {
|
|
38
|
-
maxDurationMs: opts.maxDurationMs
|
|
39
|
-
abortCtrl: opts.abortCtrl
|
|
43
|
+
maxDurationMs: opts.maxDurationMs
|
|
40
44
|
});
|
|
41
45
|
}
|
|
42
46
|
if (ping.enabled && ping.intervalMs !== Infinity && ping.intervalMs > 0) {
|
|
@@ -139,6 +143,7 @@ async function withTimeout(opts) {
|
|
|
139
143
|
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
140
144
|
*/ function sseStreamConsumer(opts) {
|
|
141
145
|
const { deserialize = (v)=>v } = opts;
|
|
146
|
+
let clientOptions = {};
|
|
142
147
|
const signal = opts.signal;
|
|
143
148
|
let _es = null;
|
|
144
149
|
const createStream = ()=>new ReadableStream({
|
|
@@ -153,9 +158,13 @@ async function withTimeout(opts) {
|
|
|
153
158
|
eventSource: _es,
|
|
154
159
|
event: null
|
|
155
160
|
});
|
|
156
|
-
eventSource.addEventListener(
|
|
161
|
+
eventSource.addEventListener(CONNECTED_EVENT, (_msg)=>{
|
|
162
|
+
const msg = _msg;
|
|
163
|
+
const options = JSON.parse(msg.data);
|
|
164
|
+
clientOptions = options;
|
|
157
165
|
controller.enqueue({
|
|
158
|
-
type: '
|
|
166
|
+
type: 'connected',
|
|
167
|
+
options,
|
|
159
168
|
eventSource
|
|
160
169
|
});
|
|
161
170
|
});
|
|
@@ -230,10 +239,11 @@ async function withTimeout(opts) {
|
|
|
230
239
|
const iterator = {
|
|
231
240
|
async next () {
|
|
232
241
|
let promise = stream.reader.read();
|
|
233
|
-
|
|
242
|
+
const timeoutMs = clientOptions.reconnectAfterInactivityMs;
|
|
243
|
+
if (timeoutMs) {
|
|
234
244
|
promise = withTimeout({
|
|
235
245
|
promise,
|
|
236
|
-
timeoutMs
|
|
246
|
+
timeoutMs,
|
|
237
247
|
onTimeout: async ()=>{
|
|
238
248
|
// Close and release old reader
|
|
239
249
|
await stream.cancel();
|
|
@@ -242,6 +252,7 @@ async function withTimeout(opts) {
|
|
|
242
252
|
return {
|
|
243
253
|
value: {
|
|
244
254
|
type: 'timeout',
|
|
255
|
+
ms: timeoutMs,
|
|
245
256
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
246
257
|
eventSource: _es
|
|
247
258
|
},
|
|
@@ -9,32 +9,36 @@ 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) {
|
|
28
34
|
iterable = takeWithGrace(iterable, {
|
|
29
35
|
count: 1,
|
|
30
|
-
gracePeriodMs: 1
|
|
31
|
-
abortCtrl: opts.abortCtrl
|
|
36
|
+
gracePeriodMs: 1
|
|
32
37
|
});
|
|
33
38
|
}
|
|
34
39
|
if (opts.maxDurationMs && opts.maxDurationMs > 0 && opts.maxDurationMs !== Infinity) {
|
|
35
40
|
iterable = withMaxDuration(iterable, {
|
|
36
|
-
maxDurationMs: opts.maxDurationMs
|
|
37
|
-
abortCtrl: opts.abortCtrl
|
|
41
|
+
maxDurationMs: opts.maxDurationMs
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
44
|
if (ping.enabled && ping.intervalMs !== Infinity && ping.intervalMs > 0) {
|
|
@@ -137,6 +141,7 @@ async function withTimeout(opts) {
|
|
|
137
141
|
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
138
142
|
*/ function sseStreamConsumer(opts) {
|
|
139
143
|
const { deserialize = (v)=>v } = opts;
|
|
144
|
+
let clientOptions = {};
|
|
140
145
|
const signal = opts.signal;
|
|
141
146
|
let _es = null;
|
|
142
147
|
const createStream = ()=>new ReadableStream({
|
|
@@ -151,9 +156,13 @@ async function withTimeout(opts) {
|
|
|
151
156
|
eventSource: _es,
|
|
152
157
|
event: null
|
|
153
158
|
});
|
|
154
|
-
eventSource.addEventListener(
|
|
159
|
+
eventSource.addEventListener(CONNECTED_EVENT, (_msg)=>{
|
|
160
|
+
const msg = _msg;
|
|
161
|
+
const options = JSON.parse(msg.data);
|
|
162
|
+
clientOptions = options;
|
|
155
163
|
controller.enqueue({
|
|
156
|
-
type: '
|
|
164
|
+
type: 'connected',
|
|
165
|
+
options,
|
|
157
166
|
eventSource
|
|
158
167
|
});
|
|
159
168
|
});
|
|
@@ -228,10 +237,11 @@ async function withTimeout(opts) {
|
|
|
228
237
|
const iterator = {
|
|
229
238
|
async next () {
|
|
230
239
|
let promise = stream.reader.read();
|
|
231
|
-
|
|
240
|
+
const timeoutMs = clientOptions.reconnectAfterInactivityMs;
|
|
241
|
+
if (timeoutMs) {
|
|
232
242
|
promise = withTimeout({
|
|
233
243
|
promise,
|
|
234
|
-
timeoutMs
|
|
244
|
+
timeoutMs,
|
|
235
245
|
onTimeout: async ()=>{
|
|
236
246
|
// Close and release old reader
|
|
237
247
|
await stream.cancel();
|
|
@@ -240,6 +250,7 @@ async function withTimeout(opts) {
|
|
|
240
250
|
return {
|
|
241
251
|
value: {
|
|
242
252
|
type: 'timeout',
|
|
253
|
+
ms: timeoutMs,
|
|
243
254
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
244
255
|
eventSource: _es
|
|
245
256
|
},
|