@trpc/server 11.0.0-rc.592 → 11.0.0-rc.593
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 +106 -90
- package/dist/observable/behaviorSubject.d.ts +15 -0
- package/dist/observable/behaviorSubject.d.ts.map +1 -0
- package/dist/observable/behaviorSubject.js +40 -0
- package/dist/observable/behaviorSubject.mjs +38 -0
- package/dist/observable/index.d.ts +3 -3
- package/dist/observable/index.d.ts.map +1 -1
- package/dist/observable/index.js +4 -0
- package/dist/observable/index.mjs +2 -1
- package/dist/observable/operators.d.ts +2 -0
- package/dist/observable/operators.d.ts.map +1 -1
- package/dist/observable/operators.js +35 -0
- package/dist/observable/operators.mjs +34 -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 +143 -77
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +145 -79
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +21 -20
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +46 -110
- package/dist/unstable-core-do-not-import/stream/sse.mjs +46 -110
- package/dist/unstable-core-do-not-import/stream/sse.types.d.ts +31 -0
- package/dist/unstable-core-do-not-import/stream/sse.types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/types.d.ts +5 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.d.ts +1 -0
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/observable/behaviorSubject.ts +55 -0
- package/src/observable/index.ts +22 -3
- package/src/observable/operators.ts +47 -0
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +169 -97
- package/src/unstable-core-do-not-import/stream/sse.ts +87 -152
- package/src/unstable-core-do-not-import/stream/sse.types.ts +44 -0
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +1 -1
- package/src/unstable-core-do-not-import/types.ts +8 -0
- package/src/unstable-core-do-not-import.ts +1 -0
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { isObservable, observableToAsyncIterable } from '../../observable/observable.mjs';
|
|
2
2
|
import { getErrorShape } from '../error/getErrorShape.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { getTRPCErrorFromUnknown, TRPCError } from '../error/TRPCError.mjs';
|
|
4
4
|
import { jsonlStreamProducer, isPromise } from '../stream/jsonl.mjs';
|
|
5
5
|
import { sseStreamProducer, sseHeaders } from '../stream/sse.mjs';
|
|
6
6
|
import { transformTRPCResponse } from '../transformer.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import { run, abortSignalsAnyPonyfill, isAsyncIterable, isObject } from '../utils.mjs';
|
|
8
8
|
import { getRequestInfo } from './contentType.mjs';
|
|
9
9
|
import { getHTTPStatusCode } from './getHTTPStatusCode.mjs';
|
|
10
10
|
|
|
11
|
+
function errorToAsyncIterable(err) {
|
|
12
|
+
return {
|
|
13
|
+
[Symbol.asyncIterator]: ()=>{
|
|
14
|
+
return {
|
|
15
|
+
next () {
|
|
16
|
+
throw err;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
11
22
|
const TYPE_ACCEPTED_METHOD_MAP = {
|
|
12
23
|
mutation: [
|
|
13
24
|
'POST'
|
|
@@ -135,8 +146,62 @@ async function resolveResponse(opts) {
|
|
|
135
146
|
}
|
|
136
147
|
const allowBatching = opts.allowBatching ?? opts.batching?.enabled ?? true;
|
|
137
148
|
const allowMethodOverride = (opts.allowMethodOverride ?? false) && req.method === 'POST';
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
const infoTuple = run(()=>{
|
|
150
|
+
try {
|
|
151
|
+
return [
|
|
152
|
+
undefined,
|
|
153
|
+
getRequestInfo({
|
|
154
|
+
req,
|
|
155
|
+
path: decodeURIComponent(opts.path),
|
|
156
|
+
router,
|
|
157
|
+
searchParams: url.searchParams,
|
|
158
|
+
headers: opts.req.headers
|
|
159
|
+
})
|
|
160
|
+
];
|
|
161
|
+
} catch (cause) {
|
|
162
|
+
return [
|
|
163
|
+
getTRPCErrorFromUnknown(cause),
|
|
164
|
+
undefined
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
const ctxManager = run(()=>{
|
|
169
|
+
let result = undefined;
|
|
170
|
+
return {
|
|
171
|
+
valueOrUndefined: ()=>{
|
|
172
|
+
if (!result) {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
return result[1];
|
|
176
|
+
},
|
|
177
|
+
value: ()=>{
|
|
178
|
+
const [err, ctx] = result;
|
|
179
|
+
if (err) {
|
|
180
|
+
throw err;
|
|
181
|
+
}
|
|
182
|
+
return ctx;
|
|
183
|
+
},
|
|
184
|
+
create: async (info)=>{
|
|
185
|
+
if (result) {
|
|
186
|
+
throw new Error('This should only be called once - report a bug in tRPC');
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const ctx = await opts.createContext({
|
|
190
|
+
info
|
|
191
|
+
});
|
|
192
|
+
result = [
|
|
193
|
+
undefined,
|
|
194
|
+
ctx
|
|
195
|
+
];
|
|
196
|
+
} catch (cause) {
|
|
197
|
+
result = [
|
|
198
|
+
getTRPCErrorFromUnknown(cause),
|
|
199
|
+
undefined
|
|
200
|
+
];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
});
|
|
140
205
|
const methodMapper = allowMethodOverride ? TYPE_ACCEPTED_METHOD_MAP_WITH_METHOD_OVERRIDE : TYPE_ACCEPTED_METHOD_MAP;
|
|
141
206
|
/**
|
|
142
207
|
* @deprecated
|
|
@@ -144,19 +209,9 @@ async function resolveResponse(opts) {
|
|
|
144
209
|
const experimentalIterablesAndDeferreds = router._def._config.experimental?.iterablesAndDeferreds ?? true;
|
|
145
210
|
const experimentalSSE = router._def._config.experimental?.sseSubscriptions?.enabled ?? true;
|
|
146
211
|
try {
|
|
147
|
-
info =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
router,
|
|
151
|
-
searchParams: url.searchParams,
|
|
152
|
-
headers: opts.req.headers
|
|
153
|
-
});
|
|
154
|
-
// we create context early so that error handlers may access context information
|
|
155
|
-
ctx = await opts.createContext({
|
|
156
|
-
info
|
|
157
|
-
});
|
|
158
|
-
if (opts.error) {
|
|
159
|
-
throw opts.error;
|
|
212
|
+
const [infoError, info] = infoTuple;
|
|
213
|
+
if (infoError) {
|
|
214
|
+
throw infoError;
|
|
160
215
|
}
|
|
161
216
|
if (info.isBatchCall && !allowBatching) {
|
|
162
217
|
throw new TRPCError({
|
|
@@ -170,9 +225,13 @@ async function resolveResponse(opts) {
|
|
|
170
225
|
code: 'BAD_REQUEST'
|
|
171
226
|
});
|
|
172
227
|
}
|
|
228
|
+
await ctxManager.create(info);
|
|
173
229
|
const rpcCalls = info.calls.map(async (call)=>{
|
|
174
230
|
const proc = call.procedure;
|
|
175
231
|
try {
|
|
232
|
+
if (opts.error) {
|
|
233
|
+
throw opts.error;
|
|
234
|
+
}
|
|
176
235
|
if (!proc) {
|
|
177
236
|
throw new TRPCError({
|
|
178
237
|
code: 'NOT_FOUND',
|
|
@@ -185,7 +244,6 @@ async function resolveResponse(opts) {
|
|
|
185
244
|
message: `Unsupported ${req.method}-request to ${proc._def.type} procedure at path "${call.path}"`
|
|
186
245
|
});
|
|
187
246
|
}
|
|
188
|
-
let abortCtrl;
|
|
189
247
|
if (proc._def.type === 'subscription') {
|
|
190
248
|
/* istanbul ignore if -- @preserve */ if (info.isBatchCall) {
|
|
191
249
|
throw new TRPCError({
|
|
@@ -193,19 +251,20 @@ async function resolveResponse(opts) {
|
|
|
193
251
|
message: `Cannot batch subscription calls`
|
|
194
252
|
});
|
|
195
253
|
}
|
|
196
|
-
abortCtrl = new AbortController();
|
|
197
254
|
}
|
|
255
|
+
const abortCtrl = new AbortController();
|
|
198
256
|
const data = await proc({
|
|
199
257
|
path: call.path,
|
|
200
258
|
getRawInput: call.getRawInput,
|
|
201
|
-
ctx,
|
|
259
|
+
ctx: ctxManager.value(),
|
|
202
260
|
type: proc._def.type,
|
|
203
|
-
signal:
|
|
261
|
+
signal: abortSignalsAnyPonyfill([
|
|
204
262
|
opts.req.signal,
|
|
205
263
|
abortCtrl.signal
|
|
206
|
-
])
|
|
264
|
+
])
|
|
207
265
|
});
|
|
208
266
|
return [
|
|
267
|
+
undefined,
|
|
209
268
|
{
|
|
210
269
|
data,
|
|
211
270
|
abortCtrl
|
|
@@ -218,20 +277,20 @@ async function resolveResponse(opts) {
|
|
|
218
277
|
error,
|
|
219
278
|
path: call.path,
|
|
220
279
|
input,
|
|
221
|
-
ctx,
|
|
280
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
222
281
|
type: call.procedure?._def.type ?? 'unknown',
|
|
223
282
|
req: opts.req
|
|
224
283
|
});
|
|
225
284
|
return [
|
|
226
|
-
|
|
227
|
-
|
|
285
|
+
error,
|
|
286
|
+
undefined
|
|
228
287
|
];
|
|
229
288
|
}
|
|
230
289
|
});
|
|
231
290
|
// ----------- response handlers -----------
|
|
232
291
|
if (!info.isBatchCall) {
|
|
233
292
|
const [call] = info.calls;
|
|
234
|
-
const [
|
|
293
|
+
const [error, result] = await rpcCalls[0];
|
|
235
294
|
switch(info.type){
|
|
236
295
|
case 'unknown':
|
|
237
296
|
case 'mutation':
|
|
@@ -248,7 +307,7 @@ async function resolveResponse(opts) {
|
|
|
248
307
|
const res = error ? {
|
|
249
308
|
error: getErrorShape({
|
|
250
309
|
config,
|
|
251
|
-
ctx,
|
|
310
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
252
311
|
error,
|
|
253
312
|
input: call.result(),
|
|
254
313
|
path: call.path,
|
|
@@ -260,7 +319,7 @@ async function resolveResponse(opts) {
|
|
|
260
319
|
}
|
|
261
320
|
};
|
|
262
321
|
const headResponse = initResponse({
|
|
263
|
-
ctx,
|
|
322
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
264
323
|
info,
|
|
265
324
|
responseMeta: opts.responseMeta,
|
|
266
325
|
errors: error ? [
|
|
@@ -279,48 +338,49 @@ async function resolveResponse(opts) {
|
|
|
279
338
|
case 'subscription':
|
|
280
339
|
{
|
|
281
340
|
// httpSubscriptionLink
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
341
|
+
const iterable = run(()=>{
|
|
342
|
+
if (error) {
|
|
343
|
+
return errorToAsyncIterable(error);
|
|
344
|
+
}
|
|
345
|
+
if (!experimentalSSE) {
|
|
346
|
+
return errorToAsyncIterable(new TRPCError({
|
|
347
|
+
code: 'METHOD_NOT_SUPPORTED',
|
|
348
|
+
message: 'Missing experimental flag "sseSubscriptions"'
|
|
349
|
+
}));
|
|
350
|
+
}
|
|
351
|
+
if (!isObservable(result.data) && !isAsyncIterable(result.data)) {
|
|
352
|
+
return errorToAsyncIterable(new TRPCError({
|
|
353
|
+
message: `Subscription ${call.path} did not return an observable or a AsyncGenerator`,
|
|
354
|
+
code: 'INTERNAL_SERVER_ERROR'
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
357
|
+
const dataAsIterable = isObservable(result.data) ? observableToAsyncIterable(result.data) : result.data;
|
|
358
|
+
return dataAsIterable;
|
|
359
|
+
});
|
|
300
360
|
const stream = sseStreamProducer({
|
|
301
361
|
...config.experimental?.sseSubscriptions,
|
|
302
|
-
data:
|
|
303
|
-
abortCtrl,
|
|
362
|
+
data: iterable,
|
|
363
|
+
abortCtrl: result?.abortCtrl ?? new AbortController(),
|
|
304
364
|
serialize: (v)=>config.transformer.output.serialize(v),
|
|
305
365
|
formatError (errorOpts) {
|
|
306
366
|
const error = getTRPCErrorFromUnknown(errorOpts.error);
|
|
307
367
|
const input = call?.result();
|
|
308
368
|
const path = call?.path;
|
|
309
369
|
const type = call?.procedure?._def.type ?? 'unknown';
|
|
310
|
-
|
|
311
|
-
config,
|
|
312
|
-
ctx,
|
|
370
|
+
opts.onError?.({
|
|
313
371
|
error,
|
|
314
|
-
input,
|
|
315
372
|
path,
|
|
373
|
+
input,
|
|
374
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
375
|
+
req: opts.req,
|
|
316
376
|
type
|
|
317
377
|
});
|
|
318
|
-
|
|
378
|
+
const shape = getErrorShape({
|
|
379
|
+
config,
|
|
380
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
319
381
|
error,
|
|
320
|
-
path,
|
|
321
382
|
input,
|
|
322
|
-
|
|
323
|
-
req: opts.req,
|
|
383
|
+
path,
|
|
324
384
|
type
|
|
325
385
|
});
|
|
326
386
|
return shape;
|
|
@@ -330,7 +390,7 @@ async function resolveResponse(opts) {
|
|
|
330
390
|
headers.set(key, value);
|
|
331
391
|
}
|
|
332
392
|
const headResponse1 = initResponse({
|
|
333
|
-
ctx,
|
|
393
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
334
394
|
info,
|
|
335
395
|
responseMeta: opts.responseMeta,
|
|
336
396
|
errors: [],
|
|
@@ -350,7 +410,7 @@ async function resolveResponse(opts) {
|
|
|
350
410
|
headers.set('content-type', 'application/json');
|
|
351
411
|
headers.set('transfer-encoding', 'chunked');
|
|
352
412
|
const headResponse2 = initResponse({
|
|
353
|
-
ctx,
|
|
413
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
354
414
|
info,
|
|
355
415
|
responseMeta: opts.responseMeta,
|
|
356
416
|
errors: [],
|
|
@@ -372,13 +432,13 @@ async function resolveResponse(opts) {
|
|
|
372
432
|
* }
|
|
373
433
|
*/ maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
|
|
374
434
|
data: rpcCalls.map(async (res)=>{
|
|
375
|
-
const [
|
|
435
|
+
const [error, result] = await res;
|
|
376
436
|
const call = info.calls[0];
|
|
377
437
|
if (error) {
|
|
378
438
|
return {
|
|
379
439
|
error: getErrorShape({
|
|
380
440
|
config,
|
|
381
|
-
ctx,
|
|
441
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
382
442
|
error,
|
|
383
443
|
input: call.result(),
|
|
384
444
|
path: call.path,
|
|
@@ -386,14 +446,13 @@ async function resolveResponse(opts) {
|
|
|
386
446
|
})
|
|
387
447
|
};
|
|
388
448
|
}
|
|
389
|
-
const { data } = result;
|
|
390
449
|
/**
|
|
391
450
|
* Not very pretty, but we need to wrap nested data in promises
|
|
392
451
|
* Our stream producer will only resolve top-level async values or async values that are directly nested in another async value
|
|
393
|
-
*/ const
|
|
452
|
+
*/ const iterable = isObservable(result.data) ? observableToAsyncIterable(result.data) : Promise.resolve(result.data);
|
|
394
453
|
return {
|
|
395
454
|
result: Promise.resolve({
|
|
396
|
-
data:
|
|
455
|
+
data: iterable
|
|
397
456
|
})
|
|
398
457
|
};
|
|
399
458
|
}),
|
|
@@ -403,20 +462,25 @@ async function resolveResponse(opts) {
|
|
|
403
462
|
error: getTRPCErrorFromUnknown(cause),
|
|
404
463
|
path: undefined,
|
|
405
464
|
input: undefined,
|
|
406
|
-
ctx,
|
|
465
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
407
466
|
req: opts.req,
|
|
408
467
|
type: info?.type ?? 'unknown'
|
|
409
468
|
});
|
|
410
469
|
},
|
|
411
470
|
formatError (errorOpts) {
|
|
412
471
|
const call = info?.calls[errorOpts.path[0]];
|
|
472
|
+
const error = getTRPCErrorFromUnknown(errorOpts.error);
|
|
473
|
+
const input = call?.result();
|
|
474
|
+
const path = call?.path;
|
|
475
|
+
const type = call?.procedure?._def.type ?? 'unknown';
|
|
476
|
+
// no need to call `onError` here as it will be propagated through the stream itself
|
|
413
477
|
const shape = getErrorShape({
|
|
414
478
|
config,
|
|
415
|
-
ctx,
|
|
416
|
-
error
|
|
417
|
-
input
|
|
418
|
-
path
|
|
419
|
-
type
|
|
479
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
480
|
+
error,
|
|
481
|
+
input,
|
|
482
|
+
path,
|
|
483
|
+
type
|
|
420
484
|
});
|
|
421
485
|
return shape;
|
|
422
486
|
}
|
|
@@ -434,28 +498,28 @@ async function resolveResponse(opts) {
|
|
|
434
498
|
* - return a complete HTTPResponse
|
|
435
499
|
*/ headers.set('content-type', 'application/json');
|
|
436
500
|
const results = (await Promise.all(rpcCalls)).map((res)=>{
|
|
437
|
-
const [
|
|
501
|
+
const [error, result] = res;
|
|
438
502
|
if (error) {
|
|
439
503
|
return res;
|
|
440
504
|
}
|
|
441
505
|
if (isDataStream(result.data)) {
|
|
442
506
|
return [
|
|
443
|
-
null,
|
|
444
507
|
new TRPCError({
|
|
445
508
|
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
446
509
|
message: 'Cannot use stream-like response in non-streaming request - use httpBatchStreamLink'
|
|
447
|
-
})
|
|
510
|
+
}),
|
|
511
|
+
undefined
|
|
448
512
|
];
|
|
449
513
|
}
|
|
450
514
|
return res;
|
|
451
515
|
});
|
|
452
|
-
const resultAsRPCResponse = results.map(([
|
|
516
|
+
const resultAsRPCResponse = results.map(([error, result], index)=>{
|
|
453
517
|
const call = info.calls[index];
|
|
454
518
|
if (error) {
|
|
455
519
|
return {
|
|
456
520
|
error: getErrorShape({
|
|
457
521
|
config,
|
|
458
|
-
ctx,
|
|
522
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
459
523
|
error,
|
|
460
524
|
input: call.result(),
|
|
461
525
|
path: call.path,
|
|
@@ -469,9 +533,9 @@ async function resolveResponse(opts) {
|
|
|
469
533
|
}
|
|
470
534
|
};
|
|
471
535
|
});
|
|
472
|
-
const errors = results.map(([
|
|
536
|
+
const errors = results.map(([error])=>error).filter(Boolean);
|
|
473
537
|
const headResponse3 = initResponse({
|
|
474
|
-
ctx,
|
|
538
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
475
539
|
info,
|
|
476
540
|
responseMeta: opts.responseMeta,
|
|
477
541
|
untransformedJSON: resultAsRPCResponse,
|
|
@@ -483,6 +547,8 @@ async function resolveResponse(opts) {
|
|
|
483
547
|
headers
|
|
484
548
|
});
|
|
485
549
|
} catch (cause) {
|
|
550
|
+
const [_infoError, info1] = infoTuple;
|
|
551
|
+
const ctx = ctxManager.valueOrUndefined();
|
|
486
552
|
// we get here if
|
|
487
553
|
// - batching is called when it's not enabled
|
|
488
554
|
// - `createContext()` throws
|
|
@@ -492,12 +558,12 @@ async function resolveResponse(opts) {
|
|
|
492
558
|
// - `errorFormatter` return value is malformed
|
|
493
559
|
const { error: error1 , untransformedJSON , body } = caughtErrorToData(cause, {
|
|
494
560
|
opts,
|
|
495
|
-
ctx,
|
|
496
|
-
type:
|
|
561
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
562
|
+
type: info1?.type ?? 'unknown'
|
|
497
563
|
});
|
|
498
564
|
const headResponse4 = initResponse({
|
|
499
565
|
ctx,
|
|
500
|
-
info,
|
|
566
|
+
info: info1,
|
|
501
567
|
responseMeta: opts.responseMeta,
|
|
502
568
|
untransformedJSON,
|
|
503
569
|
errors: [
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MaybePromise } from '../types';
|
|
2
|
+
import type { EventSourceLike } from './sse.types';
|
|
2
3
|
import type { inferTrackedOutput } from './tracked';
|
|
3
4
|
type Serialize = (value: any) => any;
|
|
4
5
|
type Deserialize = (value: any) => any;
|
|
@@ -44,41 +45,41 @@ export interface SSEStreamProducerOptions<TValue = unknown> {
|
|
|
44
45
|
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
45
46
|
*/
|
|
46
47
|
export declare function sseStreamProducer<TValue = unknown>(opts: SSEStreamProducerOptions<TValue>): ReadableStream<string>;
|
|
47
|
-
interface ConsumerStreamResultBase {
|
|
48
|
-
eventSource: EventSource
|
|
48
|
+
interface ConsumerStreamResultBase<TConfig extends ConsumerConfig> {
|
|
49
|
+
eventSource: InstanceType<TConfig['EventSource']>;
|
|
49
50
|
}
|
|
50
|
-
interface ConsumerStreamResultData<
|
|
51
|
+
interface ConsumerStreamResultData<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
51
52
|
type: 'data';
|
|
52
|
-
data: inferTrackedOutput<
|
|
53
|
+
data: inferTrackedOutput<TConfig['data']>;
|
|
53
54
|
}
|
|
54
|
-
interface ConsumerStreamResultError extends ConsumerStreamResultBase {
|
|
55
|
-
type: 'error';
|
|
56
|
-
error:
|
|
55
|
+
interface ConsumerStreamResultError<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
56
|
+
type: 'serialized-error';
|
|
57
|
+
error: TConfig['error'];
|
|
57
58
|
}
|
|
58
|
-
interface ConsumerStreamResultOpened extends ConsumerStreamResultBase {
|
|
59
|
+
interface ConsumerStreamResultOpened<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
59
60
|
type: 'opened';
|
|
60
61
|
}
|
|
61
|
-
interface ConsumerStreamResultConnecting extends ConsumerStreamResultBase {
|
|
62
|
+
interface ConsumerStreamResultConnecting<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
|
|
62
63
|
type: 'connecting';
|
|
64
|
+
event: EventSourceLike.EventOf<TConfig['EventSource']> | null;
|
|
63
65
|
}
|
|
64
|
-
type ConsumerStreamResult<
|
|
65
|
-
export interface SSEStreamConsumerOptions {
|
|
66
|
+
type ConsumerStreamResult<TConfig extends ConsumerConfig> = ConsumerStreamResultData<TConfig> | ConsumerStreamResultError<TConfig> | ConsumerStreamResultOpened<TConfig> | ConsumerStreamResultConnecting<TConfig>;
|
|
67
|
+
export interface SSEStreamConsumerOptions<TConfig extends ConsumerConfig> {
|
|
66
68
|
url: () => MaybePromise<string>;
|
|
67
|
-
init: () => MaybePromise<
|
|
69
|
+
init: () => MaybePromise<EventSourceLike.InitDictOf<TConfig['EventSource']>> | undefined;
|
|
68
70
|
signal: AbortSignal;
|
|
69
|
-
shouldRecreateOnError?: (opts: {
|
|
70
|
-
type: 'event';
|
|
71
|
-
event: Event;
|
|
72
|
-
} | {
|
|
73
|
-
type: 'serialized-error';
|
|
74
|
-
error: unknown;
|
|
75
|
-
}) => boolean | Promise<boolean>;
|
|
76
71
|
deserialize?: Deserialize;
|
|
72
|
+
EventSource: TConfig['EventSource'];
|
|
73
|
+
}
|
|
74
|
+
interface ConsumerConfig {
|
|
75
|
+
data: unknown;
|
|
76
|
+
error: unknown;
|
|
77
|
+
EventSource: EventSourceLike.AnyConstructor;
|
|
77
78
|
}
|
|
78
79
|
/**
|
|
79
80
|
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
80
81
|
*/
|
|
81
|
-
export declare function sseStreamConsumer<
|
|
82
|
+
export declare function sseStreamConsumer<TConfig extends ConsumerConfig>(opts: SSEStreamConsumerOptions<TConfig>): AsyncIterable<ConsumerStreamResult<TConfig>>;
|
|
82
83
|
export declare const sseHeaders: {
|
|
83
84
|
readonly 'Content-Type': "text/event-stream";
|
|
84
85
|
readonly 'Cache-Control': "no-cache, no-transform";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/sse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/sse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EAAE,eAA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