@trpc/server 11.0.0-rc.589 → 11.0.0-rc.591
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 +154 -147
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +6 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +27 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +24 -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 +30 -16
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +31 -17
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +2 -9
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +1 -0
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +3 -2
- package/dist/unstable-core-do-not-import/stream/sse.mjs +3 -2
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +2 -1
- 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 +2 -2
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +2 -2
- package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.js +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.mjs +1 -1
- package/dist/unstable-core-do-not-import/types.d.ts +6 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +13 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +41 -0
- package/dist/unstable-core-do-not-import/utils.mjs +39 -1
- package/dist/unstable-core-do-not-import.js +7 -0
- package/dist/unstable-core-do-not-import.mjs +2 -2
- package/package.json +2 -2
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +35 -3
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +39 -21
- package/src/unstable-core-do-not-import/rpc/codes.ts +2 -10
- package/src/unstable-core-do-not-import/stream/sse.ts +14 -4
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +3 -2
- package/src/unstable-core-do-not-import/stream/utils/promiseTimer.ts +1 -1
- package/src/unstable-core-do-not-import/types.ts +11 -0
- package/src/unstable-core-do-not-import/utils.ts +48 -0
|
@@ -24,9 +24,32 @@ const JSONRPC2_TO_HTTP_CODE = {
|
|
|
24
24
|
SERVICE_UNAVAILABLE: 503,
|
|
25
25
|
GATEWAY_TIMEOUT: 504
|
|
26
26
|
};
|
|
27
|
+
const HTTP_CODE_TO_JSONRPC2 = {
|
|
28
|
+
400: 'BAD_REQUEST',
|
|
29
|
+
401: 'UNAUTHORIZED',
|
|
30
|
+
403: 'FORBIDDEN',
|
|
31
|
+
404: 'NOT_FOUND',
|
|
32
|
+
405: 'METHOD_NOT_SUPPORTED',
|
|
33
|
+
408: 'TIMEOUT',
|
|
34
|
+
409: 'CONFLICT',
|
|
35
|
+
412: 'PRECONDITION_FAILED',
|
|
36
|
+
413: 'PAYLOAD_TOO_LARGE',
|
|
37
|
+
415: 'UNSUPPORTED_MEDIA_TYPE',
|
|
38
|
+
422: 'UNPROCESSABLE_CONTENT',
|
|
39
|
+
429: 'TOO_MANY_REQUESTS',
|
|
40
|
+
499: 'CLIENT_CLOSED_REQUEST',
|
|
41
|
+
500: 'INTERNAL_SERVER_ERROR',
|
|
42
|
+
501: 'NOT_IMPLEMENTED',
|
|
43
|
+
502: 'BAD_GATEWAY',
|
|
44
|
+
503: 'SERVICE_UNAVAILABLE',
|
|
45
|
+
504: 'GATEWAY_TIMEOUT'
|
|
46
|
+
};
|
|
27
47
|
function getStatusCodeFromKey(code) {
|
|
28
48
|
return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
|
|
29
49
|
}
|
|
50
|
+
function getStatusKeyFromCode(code) {
|
|
51
|
+
return HTTP_CODE_TO_JSONRPC2[code] ?? 'INTERNAL_SERVER_ERROR';
|
|
52
|
+
}
|
|
30
53
|
function getHTTPStatusCode(json) {
|
|
31
54
|
const arr = Array.isArray(json) ? json : [
|
|
32
55
|
json
|
|
@@ -52,5 +75,9 @@ function getHTTPStatusCodeFromError(error) {
|
|
|
52
75
|
return getStatusCodeFromKey(error.code);
|
|
53
76
|
}
|
|
54
77
|
|
|
78
|
+
exports.HTTP_CODE_TO_JSONRPC2 = HTTP_CODE_TO_JSONRPC2;
|
|
79
|
+
exports.JSONRPC2_TO_HTTP_CODE = JSONRPC2_TO_HTTP_CODE;
|
|
55
80
|
exports.getHTTPStatusCode = getHTTPStatusCode;
|
|
56
81
|
exports.getHTTPStatusCodeFromError = getHTTPStatusCodeFromError;
|
|
82
|
+
exports.getStatusCodeFromKey = getStatusCodeFromKey;
|
|
83
|
+
exports.getStatusKeyFromCode = getStatusKeyFromCode;
|
|
@@ -22,9 +22,32 @@ const JSONRPC2_TO_HTTP_CODE = {
|
|
|
22
22
|
SERVICE_UNAVAILABLE: 503,
|
|
23
23
|
GATEWAY_TIMEOUT: 504
|
|
24
24
|
};
|
|
25
|
+
const HTTP_CODE_TO_JSONRPC2 = {
|
|
26
|
+
400: 'BAD_REQUEST',
|
|
27
|
+
401: 'UNAUTHORIZED',
|
|
28
|
+
403: 'FORBIDDEN',
|
|
29
|
+
404: 'NOT_FOUND',
|
|
30
|
+
405: 'METHOD_NOT_SUPPORTED',
|
|
31
|
+
408: 'TIMEOUT',
|
|
32
|
+
409: 'CONFLICT',
|
|
33
|
+
412: 'PRECONDITION_FAILED',
|
|
34
|
+
413: 'PAYLOAD_TOO_LARGE',
|
|
35
|
+
415: 'UNSUPPORTED_MEDIA_TYPE',
|
|
36
|
+
422: 'UNPROCESSABLE_CONTENT',
|
|
37
|
+
429: 'TOO_MANY_REQUESTS',
|
|
38
|
+
499: 'CLIENT_CLOSED_REQUEST',
|
|
39
|
+
500: 'INTERNAL_SERVER_ERROR',
|
|
40
|
+
501: 'NOT_IMPLEMENTED',
|
|
41
|
+
502: 'BAD_GATEWAY',
|
|
42
|
+
503: 'SERVICE_UNAVAILABLE',
|
|
43
|
+
504: 'GATEWAY_TIMEOUT'
|
|
44
|
+
};
|
|
25
45
|
function getStatusCodeFromKey(code) {
|
|
26
46
|
return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
|
|
27
47
|
}
|
|
48
|
+
function getStatusKeyFromCode(code) {
|
|
49
|
+
return HTTP_CODE_TO_JSONRPC2[code] ?? 'INTERNAL_SERVER_ERROR';
|
|
50
|
+
}
|
|
28
51
|
function getHTTPStatusCode(json) {
|
|
29
52
|
const arr = Array.isArray(json) ? json : [
|
|
30
53
|
json
|
|
@@ -50,4 +73,4 @@ function getHTTPStatusCodeFromError(error) {
|
|
|
50
73
|
return getStatusCodeFromKey(error.code);
|
|
51
74
|
}
|
|
52
75
|
|
|
53
|
-
export { getHTTPStatusCode, getHTTPStatusCodeFromError };
|
|
76
|
+
export { HTTP_CODE_TO_JSONRPC2, JSONRPC2_TO_HTTP_CODE, getHTTPStatusCode, getHTTPStatusCodeFromError, getStatusCodeFromKey, getStatusKeyFromCode };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAQnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AA0BjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAyID,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAQnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AA0BjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAyID,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CAmcnB"}
|
|
@@ -187,21 +187,31 @@ async function resolveResponse(opts) {
|
|
|
187
187
|
message: `Unsupported ${req.method}-request to ${proc._def.type} procedure at path "${call.path}"`
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
let abortCtrl;
|
|
191
|
+
if (proc._def.type === 'subscription') {
|
|
192
|
+
/* istanbul ignore if -- @preserve */ if (info.isBatchCall) {
|
|
193
|
+
throw new TRPCError.TRPCError({
|
|
194
|
+
code: 'BAD_REQUEST',
|
|
195
|
+
message: `Cannot batch subscription calls`
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
abortCtrl = new AbortController();
|
|
195
199
|
}
|
|
196
200
|
const data = await proc({
|
|
197
201
|
path: call.path,
|
|
198
202
|
getRawInput: call.getRawInput,
|
|
199
203
|
ctx,
|
|
200
204
|
type: proc._def.type,
|
|
201
|
-
signal:
|
|
205
|
+
signal: abortCtrl ? utils.abortSignalsAnyPonyfill([
|
|
206
|
+
opts.req.signal,
|
|
207
|
+
abortCtrl.signal
|
|
208
|
+
]) : opts.req.signal
|
|
202
209
|
});
|
|
203
210
|
return [
|
|
204
|
-
|
|
211
|
+
{
|
|
212
|
+
data,
|
|
213
|
+
abortCtrl
|
|
214
|
+
}
|
|
205
215
|
];
|
|
206
216
|
} catch (cause) {
|
|
207
217
|
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
@@ -223,7 +233,7 @@ async function resolveResponse(opts) {
|
|
|
223
233
|
// ----------- response handlers -----------
|
|
224
234
|
if (!info.isBatchCall) {
|
|
225
235
|
const [call] = info.calls;
|
|
226
|
-
const [
|
|
236
|
+
const [result, error] = await rpcCalls[0];
|
|
227
237
|
switch(info.type){
|
|
228
238
|
case 'unknown':
|
|
229
239
|
case 'mutation':
|
|
@@ -231,7 +241,7 @@ async function resolveResponse(opts) {
|
|
|
231
241
|
{
|
|
232
242
|
// httpLink
|
|
233
243
|
headers.set('content-type', 'application/json');
|
|
234
|
-
if (isDataStream(data)) {
|
|
244
|
+
if (isDataStream(result?.data)) {
|
|
235
245
|
throw new TRPCError.TRPCError({
|
|
236
246
|
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
237
247
|
message: 'Cannot use stream-like response in non-streaming request - use httpBatchStreamLink'
|
|
@@ -248,7 +258,7 @@ async function resolveResponse(opts) {
|
|
|
248
258
|
})
|
|
249
259
|
} : {
|
|
250
260
|
result: {
|
|
251
|
-
data
|
|
261
|
+
data: result.data
|
|
252
262
|
}
|
|
253
263
|
};
|
|
254
264
|
const headResponse = initResponse({
|
|
@@ -280,6 +290,8 @@ async function resolveResponse(opts) {
|
|
|
280
290
|
if (error) {
|
|
281
291
|
throw error;
|
|
282
292
|
}
|
|
293
|
+
const { data , abortCtrl } = result;
|
|
294
|
+
utils.assert(abortCtrl !== undefined, 'subscription type must have an AbortController');
|
|
283
295
|
if (!observable.isObservable(data) && !utils.isAsyncIterable(data)) {
|
|
284
296
|
throw new TRPCError.TRPCError({
|
|
285
297
|
message: `Subscription ${call.path} did not return an observable or a AsyncGenerator`,
|
|
@@ -290,6 +302,7 @@ async function resolveResponse(opts) {
|
|
|
290
302
|
const stream = sse.sseStreamProducer({
|
|
291
303
|
...config.experimental?.sseSubscriptions,
|
|
292
304
|
data: dataAsIterable,
|
|
305
|
+
abortCtrl,
|
|
293
306
|
serialize: (v)=>config.transformer.output.serialize(v),
|
|
294
307
|
formatError (errorOpts) {
|
|
295
308
|
const error = TRPCError.getTRPCErrorFromUnknown(errorOpts.error);
|
|
@@ -375,13 +388,14 @@ async function resolveResponse(opts) {
|
|
|
375
388
|
})
|
|
376
389
|
};
|
|
377
390
|
}
|
|
391
|
+
const { data } = result;
|
|
378
392
|
/**
|
|
379
393
|
* Not very pretty, but we need to wrap nested data in promises
|
|
380
394
|
* Our stream producer will only resolve top-level async values or async values that are directly nested in another async value
|
|
381
|
-
*/ const
|
|
395
|
+
*/ const dataAsPromiseOrIterable = observable.isObservable(data) ? observable.observableToAsyncIterable(data) : Promise.resolve(data);
|
|
382
396
|
return {
|
|
383
397
|
result: Promise.resolve({
|
|
384
|
-
data
|
|
398
|
+
data: dataAsPromiseOrIterable
|
|
385
399
|
})
|
|
386
400
|
};
|
|
387
401
|
}),
|
|
@@ -422,11 +436,11 @@ async function resolveResponse(opts) {
|
|
|
422
436
|
* - return a complete HTTPResponse
|
|
423
437
|
*/ headers.set('content-type', 'application/json');
|
|
424
438
|
const results = (await Promise.all(rpcCalls)).map((res)=>{
|
|
425
|
-
const [
|
|
439
|
+
const [result, error] = res;
|
|
426
440
|
if (error) {
|
|
427
441
|
return res;
|
|
428
442
|
}
|
|
429
|
-
if (isDataStream(data)) {
|
|
443
|
+
if (isDataStream(result.data)) {
|
|
430
444
|
return [
|
|
431
445
|
null,
|
|
432
446
|
new TRPCError.TRPCError({
|
|
@@ -437,7 +451,7 @@ async function resolveResponse(opts) {
|
|
|
437
451
|
}
|
|
438
452
|
return res;
|
|
439
453
|
});
|
|
440
|
-
const resultAsRPCResponse = results.map(([
|
|
454
|
+
const resultAsRPCResponse = results.map(([result, error], index)=>{
|
|
441
455
|
const call = info.calls[index];
|
|
442
456
|
if (error) {
|
|
443
457
|
return {
|
|
@@ -453,7 +467,7 @@ async function resolveResponse(opts) {
|
|
|
453
467
|
}
|
|
454
468
|
return {
|
|
455
469
|
result: {
|
|
456
|
-
data
|
|
470
|
+
data: result.data
|
|
457
471
|
}
|
|
458
472
|
};
|
|
459
473
|
});
|
|
@@ -4,7 +4,7 @@ import { TRPCError, getTRPCErrorFromUnknown } 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 { isAsyncIterable, isObject } from '../utils.mjs';
|
|
7
|
+
import { abortSignalsAnyPonyfill, assert, isAsyncIterable, isObject } from '../utils.mjs';
|
|
8
8
|
import { getRequestInfo } from './contentType.mjs';
|
|
9
9
|
import { getHTTPStatusCode } from './getHTTPStatusCode.mjs';
|
|
10
10
|
|
|
@@ -185,21 +185,31 @@ async function resolveResponse(opts) {
|
|
|
185
185
|
message: `Unsupported ${req.method}-request to ${proc._def.type} procedure at path "${call.path}"`
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
let abortCtrl;
|
|
189
|
+
if (proc._def.type === 'subscription') {
|
|
190
|
+
/* istanbul ignore if -- @preserve */ if (info.isBatchCall) {
|
|
191
|
+
throw new TRPCError({
|
|
192
|
+
code: 'BAD_REQUEST',
|
|
193
|
+
message: `Cannot batch subscription calls`
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
abortCtrl = new AbortController();
|
|
193
197
|
}
|
|
194
198
|
const data = await proc({
|
|
195
199
|
path: call.path,
|
|
196
200
|
getRawInput: call.getRawInput,
|
|
197
201
|
ctx,
|
|
198
202
|
type: proc._def.type,
|
|
199
|
-
signal:
|
|
203
|
+
signal: abortCtrl ? abortSignalsAnyPonyfill([
|
|
204
|
+
opts.req.signal,
|
|
205
|
+
abortCtrl.signal
|
|
206
|
+
]) : opts.req.signal
|
|
200
207
|
});
|
|
201
208
|
return [
|
|
202
|
-
|
|
209
|
+
{
|
|
210
|
+
data,
|
|
211
|
+
abortCtrl
|
|
212
|
+
}
|
|
203
213
|
];
|
|
204
214
|
} catch (cause) {
|
|
205
215
|
const error = getTRPCErrorFromUnknown(cause);
|
|
@@ -221,7 +231,7 @@ async function resolveResponse(opts) {
|
|
|
221
231
|
// ----------- response handlers -----------
|
|
222
232
|
if (!info.isBatchCall) {
|
|
223
233
|
const [call] = info.calls;
|
|
224
|
-
const [
|
|
234
|
+
const [result, error] = await rpcCalls[0];
|
|
225
235
|
switch(info.type){
|
|
226
236
|
case 'unknown':
|
|
227
237
|
case 'mutation':
|
|
@@ -229,7 +239,7 @@ async function resolveResponse(opts) {
|
|
|
229
239
|
{
|
|
230
240
|
// httpLink
|
|
231
241
|
headers.set('content-type', 'application/json');
|
|
232
|
-
if (isDataStream(data)) {
|
|
242
|
+
if (isDataStream(result?.data)) {
|
|
233
243
|
throw new TRPCError({
|
|
234
244
|
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
235
245
|
message: 'Cannot use stream-like response in non-streaming request - use httpBatchStreamLink'
|
|
@@ -246,7 +256,7 @@ async function resolveResponse(opts) {
|
|
|
246
256
|
})
|
|
247
257
|
} : {
|
|
248
258
|
result: {
|
|
249
|
-
data
|
|
259
|
+
data: result.data
|
|
250
260
|
}
|
|
251
261
|
};
|
|
252
262
|
const headResponse = initResponse({
|
|
@@ -278,6 +288,8 @@ async function resolveResponse(opts) {
|
|
|
278
288
|
if (error) {
|
|
279
289
|
throw error;
|
|
280
290
|
}
|
|
291
|
+
const { data , abortCtrl } = result;
|
|
292
|
+
assert(abortCtrl !== undefined, 'subscription type must have an AbortController');
|
|
281
293
|
if (!isObservable(data) && !isAsyncIterable(data)) {
|
|
282
294
|
throw new TRPCError({
|
|
283
295
|
message: `Subscription ${call.path} did not return an observable or a AsyncGenerator`,
|
|
@@ -288,6 +300,7 @@ async function resolveResponse(opts) {
|
|
|
288
300
|
const stream = sseStreamProducer({
|
|
289
301
|
...config.experimental?.sseSubscriptions,
|
|
290
302
|
data: dataAsIterable,
|
|
303
|
+
abortCtrl,
|
|
291
304
|
serialize: (v)=>config.transformer.output.serialize(v),
|
|
292
305
|
formatError (errorOpts) {
|
|
293
306
|
const error = getTRPCErrorFromUnknown(errorOpts.error);
|
|
@@ -373,13 +386,14 @@ async function resolveResponse(opts) {
|
|
|
373
386
|
})
|
|
374
387
|
};
|
|
375
388
|
}
|
|
389
|
+
const { data } = result;
|
|
376
390
|
/**
|
|
377
391
|
* Not very pretty, but we need to wrap nested data in promises
|
|
378
392
|
* Our stream producer will only resolve top-level async values or async values that are directly nested in another async value
|
|
379
|
-
*/ const
|
|
393
|
+
*/ const dataAsPromiseOrIterable = isObservable(data) ? observableToAsyncIterable(data) : Promise.resolve(data);
|
|
380
394
|
return {
|
|
381
395
|
result: Promise.resolve({
|
|
382
|
-
data
|
|
396
|
+
data: dataAsPromiseOrIterable
|
|
383
397
|
})
|
|
384
398
|
};
|
|
385
399
|
}),
|
|
@@ -420,11 +434,11 @@ async function resolveResponse(opts) {
|
|
|
420
434
|
* - return a complete HTTPResponse
|
|
421
435
|
*/ headers.set('content-type', 'application/json');
|
|
422
436
|
const results = (await Promise.all(rpcCalls)).map((res)=>{
|
|
423
|
-
const [
|
|
437
|
+
const [result, error] = res;
|
|
424
438
|
if (error) {
|
|
425
439
|
return res;
|
|
426
440
|
}
|
|
427
|
-
if (isDataStream(data)) {
|
|
441
|
+
if (isDataStream(result.data)) {
|
|
428
442
|
return [
|
|
429
443
|
null,
|
|
430
444
|
new TRPCError({
|
|
@@ -435,7 +449,7 @@ async function resolveResponse(opts) {
|
|
|
435
449
|
}
|
|
436
450
|
return res;
|
|
437
451
|
});
|
|
438
|
-
const resultAsRPCResponse = results.map(([
|
|
452
|
+
const resultAsRPCResponse = results.map(([result, error], index)=>{
|
|
439
453
|
const call = info.calls[index];
|
|
440
454
|
if (error) {
|
|
441
455
|
return {
|
|
@@ -451,7 +465,7 @@ async function resolveResponse(opts) {
|
|
|
451
465
|
}
|
|
452
466
|
return {
|
|
453
467
|
result: {
|
|
454
|
-
data
|
|
468
|
+
data: result.data
|
|
455
469
|
}
|
|
456
470
|
};
|
|
457
471
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ValueOf } from '../types';
|
|
1
|
+
import type { InvertKeyValue, ValueOf } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* JSON-RPC 2.0 Error codes
|
|
4
4
|
*
|
|
@@ -33,14 +33,7 @@ export declare const TRPC_ERROR_CODES_BY_KEY: {
|
|
|
33
33
|
readonly TOO_MANY_REQUESTS: -32029;
|
|
34
34
|
readonly CLIENT_CLOSED_REQUEST: -32099;
|
|
35
35
|
};
|
|
36
|
-
|
|
37
|
-
[K in keyof TType]: TValue extends TType[K] ? K : never;
|
|
38
|
-
}[keyof TType];
|
|
39
|
-
type Invert<TType extends Record<PropertyKey, PropertyKey>> = {
|
|
40
|
-
[TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
|
|
41
|
-
};
|
|
42
|
-
export declare const TRPC_ERROR_CODES_BY_NUMBER: Invert<typeof TRPC_ERROR_CODES_BY_KEY>;
|
|
36
|
+
export declare const TRPC_ERROR_CODES_BY_NUMBER: InvertKeyValue<typeof TRPC_ERROR_CODES_BY_KEY>;
|
|
43
37
|
export type TRPC_ERROR_CODE_NUMBER = ValueOf<typeof TRPC_ERROR_CODES_BY_KEY>;
|
|
44
38
|
export type TRPC_ERROR_CODE_KEY = keyof typeof TRPC_ERROR_CODES_BY_KEY;
|
|
45
|
-
export {};
|
|
46
39
|
//# sourceMappingURL=codes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/rpc/codes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/rpc/codes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAIxD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;IAClC;;;OAGG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;CAuBK,CAAC;AAGX,eAAO,MAAM,0BAA0B,EAAE,cAAc,CACrD,OAAO,uBAAuB,CAiB/B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC7E,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,uBAAuB,CAAC"}
|
|
@@ -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,O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;IAChC,IAAI,EAAE,MAAM,YAAY,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;IACtD,MAAM,EAAE,WAAW,CAAC;IACpB,qBAAqB,CAAC,EAAE,CACtB,IAAI,EACA;QACE,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EAAE,KAAK,CAAC;KACd,GACD;QACE,IAAI,EAAE,kBAAkB,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC;KAChB,KACF,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AACD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EACrC,IAAI,EAAE,wBAAwB,GAC7B,aAAa,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAkL5C;AAED,eAAO,MAAM,UAAU;;;;;CAKb,CAAC"}
|
|
@@ -29,13 +29,14 @@ const SERIALIZED_ERROR_EVENT = 'serialized-error';
|
|
|
29
29
|
if (opts.emitAndEndImmediately) {
|
|
30
30
|
iterable = asyncIterable.takeWithGrace(iterable, {
|
|
31
31
|
count: 1,
|
|
32
|
-
gracePeriodMs: 1
|
|
32
|
+
gracePeriodMs: 1,
|
|
33
|
+
onCancel: ()=>opts.abortCtrl.abort()
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
let maxDurationTimer = null;
|
|
36
37
|
if (opts.maxDurationMs != null && opts.maxDurationMs > 0 && opts.maxDurationMs !== Infinity) {
|
|
37
38
|
maxDurationTimer = promiseTimer.createPromiseTimer(opts.maxDurationMs).start();
|
|
38
|
-
iterable = asyncIterable.withCancel(iterable, maxDurationTimer.promise);
|
|
39
|
+
iterable = asyncIterable.withCancel(iterable, maxDurationTimer.promise.then(()=>opts.abortCtrl.abort()));
|
|
39
40
|
}
|
|
40
41
|
if (ping.enabled && ping.intervalMs !== Infinity && ping.intervalMs > 0) {
|
|
41
42
|
iterable = withPing.withPing(iterable, ping.intervalMs);
|
|
@@ -27,13 +27,14 @@ const SERIALIZED_ERROR_EVENT = 'serialized-error';
|
|
|
27
27
|
if (opts.emitAndEndImmediately) {
|
|
28
28
|
iterable = takeWithGrace(iterable, {
|
|
29
29
|
count: 1,
|
|
30
|
-
gracePeriodMs: 1
|
|
30
|
+
gracePeriodMs: 1,
|
|
31
|
+
onCancel: ()=>opts.abortCtrl.abort()
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
let maxDurationTimer = null;
|
|
34
35
|
if (opts.maxDurationMs != null && opts.maxDurationMs > 0 && opts.maxDurationMs !== Infinity) {
|
|
35
36
|
maxDurationTimer = createPromiseTimer(opts.maxDurationMs).start();
|
|
36
|
-
iterable = withCancel(iterable, maxDurationTimer.promise);
|
|
37
|
+
iterable = withCancel(iterable, maxDurationTimer.promise.then(()=>opts.abortCtrl.abort()));
|
|
37
38
|
}
|
|
38
39
|
if (ping.enabled && ping.intervalMs !== Infinity && ping.intervalMs > 0) {
|
|
39
40
|
iterable = withPing(iterable, ping.intervalMs);
|
|
@@ -6,12 +6,13 @@ export declare function withCancel<T>(iterable: AsyncIterable<T>, cancel: Promis
|
|
|
6
6
|
interface TakeWithGraceOptions {
|
|
7
7
|
count: number;
|
|
8
8
|
gracePeriodMs: number;
|
|
9
|
+
onCancel?: () => void;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
12
13
|
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
13
14
|
* values may still come through. After this period, the generator stops.
|
|
14
15
|
*/
|
|
15
|
-
export declare function takeWithGrace<T>(iterable: AsyncIterable<T>, { count, gracePeriodMs }: TakeWithGraceOptions): AsyncGenerator<T>;
|
|
16
|
+
export declare function takeWithGrace<T>(iterable: AsyncIterable<T>, { count, gracePeriodMs, onCancel }: TakeWithGraceOptions): AsyncGenerator<T>;
|
|
16
17
|
export {};
|
|
17
18
|
//# sourceMappingURL=asyncIterable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncIterable.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/asyncIterable.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAuB,UAAU,CAAC,CAAC,EACjC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,GACvB,cAAc,CAAC,CAAC,CAAC,CAcnB;AAED,UAAU,oBAAoB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAuB,aAAa,CAAC,CAAC,EACpC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"asyncIterable.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/asyncIterable.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAuB,UAAU,CAAC,CAAC,EACjC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,GACvB,cAAc,CAAC,CAAC,CAAC,CAcnB;AAED,UAAU,oBAAoB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAuB,aAAa,CAAC,CAAC,EACpC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE,oBAAoB,GACvD,cAAc,CAAC,CAAC,CAAC,CAsBnB"}
|
|
@@ -28,7 +28,7 @@ var promiseTimer = require('./promiseTimer.js');
|
|
|
28
28
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
29
29
|
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
30
30
|
* values may still come through. After this period, the generator stops.
|
|
31
|
-
*/ async function* takeWithGrace(iterable, { count , gracePeriodMs }) {
|
|
31
|
+
*/ async function* takeWithGrace(iterable, { count , gracePeriodMs , onCancel }) {
|
|
32
32
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
33
33
|
const timer = promiseTimer.createPromiseTimer(gracePeriodMs);
|
|
34
34
|
try {
|
|
@@ -47,7 +47,7 @@ var promiseTimer = require('./promiseTimer.js');
|
|
|
47
47
|
}
|
|
48
48
|
yield result.value;
|
|
49
49
|
if (--count === 0) {
|
|
50
|
-
timer.start();
|
|
50
|
+
timer.start().promise.then(onCancel, utils.noop);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
} finally{
|
|
@@ -26,7 +26,7 @@ import { createPromiseTimer } from './promiseTimer.mjs';
|
|
|
26
26
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
27
27
|
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
28
28
|
* values may still come through. After this period, the generator stops.
|
|
29
|
-
*/ async function* takeWithGrace(iterable, { count , gracePeriodMs }) {
|
|
29
|
+
*/ async function* takeWithGrace(iterable, { count , gracePeriodMs , onCancel }) {
|
|
30
30
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
31
31
|
const timer = createPromiseTimer(gracePeriodMs);
|
|
32
32
|
try {
|
|
@@ -45,7 +45,7 @@ import { createPromiseTimer } from './promiseTimer.mjs';
|
|
|
45
45
|
}
|
|
46
46
|
yield result.value;
|
|
47
47
|
if (--count === 0) {
|
|
48
|
-
timer.start();
|
|
48
|
+
timer.start().promise.then(onCancel, noop);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
} finally{
|
|
@@ -16,7 +16,7 @@ function createPromiseTimer(ms) {
|
|
|
16
16
|
return timer;
|
|
17
17
|
function start() {
|
|
18
18
|
if (timeout != null) {
|
|
19
|
-
throw new Error(
|
|
19
|
+
throw new Error('PromiseTimer already started.');
|
|
20
20
|
}
|
|
21
21
|
timeout = setTimeout(deferred.resolve, ms);
|
|
22
22
|
return timer;
|
|
@@ -14,7 +14,7 @@ function createPromiseTimer(ms) {
|
|
|
14
14
|
return timer;
|
|
15
15
|
function start() {
|
|
16
16
|
if (timeout != null) {
|
|
17
|
-
throw new Error(
|
|
17
|
+
throw new Error('PromiseTimer already started.');
|
|
18
18
|
}
|
|
19
19
|
timeout = setTimeout(deferred.resolve, ms);
|
|
20
20
|
return timer;
|
|
@@ -87,6 +87,12 @@ export type ValidateShape<TActualShape, TExpectedShape> = TActualShape extends T
|
|
|
87
87
|
* @internal
|
|
88
88
|
*/
|
|
89
89
|
export type PickFirstDefined<TType, TPick> = undefined extends TType ? undefined extends TPick ? never : TPick : TType;
|
|
90
|
+
export type KeyFromValue<TValue, TType extends Record<PropertyKey, PropertyKey>> = {
|
|
91
|
+
[K in keyof TType]: TValue extends TType[K] ? K : never;
|
|
92
|
+
}[keyof TType];
|
|
93
|
+
export type InvertKeyValue<TType extends Record<PropertyKey, PropertyKey>> = {
|
|
94
|
+
[TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
|
|
95
|
+
};
|
|
90
96
|
/**
|
|
91
97
|
* ================================
|
|
92
98
|
* tRPC specific types
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI,KAAK,SAAS,GAAG,EAAE,GAAG,IAAI,GACpD,KAAK,GACL;KAAG,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;CAAE,CAA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AK,GAAG,MAAM,SAAS,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACxD,CAAC,MAAM,KAAK,CAAC,CAAC;AAEf,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI;KAC1E,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;CAC5D,CAAC;AAEF;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,MAAM,IAC/C,iBAAiB,IAAI,oGAAoG,CAAC;AAE5H;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,KAAK,EAAE,KAAK,IAAI,MAAM,KAAK,GAC3D,MAAM,KAAK,SAAS,KAAK,GACvB,KAAK,GAAG,KAAK,GACb,iBAAiB,CAAC,MAAM,GAAG,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAEnD,QAAA,MAAM,WAAW,eAAW,CAAC;AAC7B,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC;AAC7C,MAAM,MAAM,SAAS,CAAC,QAAQ,SAAS,MAAM,IAAI,QAAQ,GAAG;IAC1D,CAAC,EAAE,OAAO,WAAW,CAAC;CACvB,CAAC;AACF,MAAM,MAAM,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC"}
|
|
@@ -25,5 +25,18 @@ export declare function isAsyncIterable<TValue>(value: unknown): value is AsyncI
|
|
|
25
25
|
export declare const run: <TValue>(fn: () => TValue) => TValue;
|
|
26
26
|
export declare function noop(): void;
|
|
27
27
|
export declare function identity<T>(it: T): T;
|
|
28
|
+
/**
|
|
29
|
+
* Generic runtime assertion function. Throws, if the condition is not `true`.
|
|
30
|
+
*
|
|
31
|
+
* Can be used as a slightly less dangerous variant of type assertions. Code
|
|
32
|
+
* mistakes would be revealed at runtime then (hopefully during testing).
|
|
33
|
+
*/
|
|
34
|
+
export declare function assert(condition: boolean, msg?: string): asserts condition;
|
|
35
|
+
export declare function sleep(ms?: number): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Ponyfill for
|
|
38
|
+
* [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
|
|
39
|
+
*/
|
|
40
|
+
export declare function abortSignalsAnyPonyfill(signals: AbortSignal[]): AbortSignal;
|
|
28
41
|
export {};
|
|
29
42
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/utils.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,eAAO,MAAM,WAAW,eAAW,CAAC;AACpC,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzE,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,GACxB,KAAK,CAYP;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,KAAK,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,EAAE,OAAO,CAAC,CAAC;AACxE,wBAAgB,UAAU,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,KAAK,CAEnD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC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AE,OAAO,GACb,KAAK,IAAI,aAAa,CAAC,MAAM,CAAC,CAIhC;AAED;;GAEG;AACH,eAAO,MAAM,GAAG,GAAI,MAAM,MAAM,MAAM,MAAM,KAAG,MAAc,CAAC;AAG9D,wBAAgB,IAAI,IAAI,IAAI,CAAG;AAE/B,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAEpC;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE,OAAO,EAClB,GAAG,SAAuB,GACzB,OAAO,CAAC,SAAS,CAInB;AAED,wBAAgB,KAAK,CAAC,EAAE,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3C;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,WAAW,CAuB3E"}
|
|
@@ -43,7 +43,47 @@ function noop() {}
|
|
|
43
43
|
function identity(it) {
|
|
44
44
|
return it;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Generic runtime assertion function. Throws, if the condition is not `true`.
|
|
48
|
+
*
|
|
49
|
+
* Can be used as a slightly less dangerous variant of type assertions. Code
|
|
50
|
+
* mistakes would be revealed at runtime then (hopefully during testing).
|
|
51
|
+
*/ function assert(condition, msg = 'no additional info') {
|
|
52
|
+
if (!condition) {
|
|
53
|
+
throw new Error(`AssertionError: ${msg}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function sleep(ms = 0) {
|
|
57
|
+
return new Promise((res)=>setTimeout(res, ms));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Ponyfill for
|
|
61
|
+
* [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
|
|
62
|
+
*/ function abortSignalsAnyPonyfill(signals) {
|
|
63
|
+
if (typeof AbortSignal.any === 'function') {
|
|
64
|
+
return AbortSignal.any(signals);
|
|
65
|
+
}
|
|
66
|
+
const ac = new AbortController();
|
|
67
|
+
for (const signal of signals){
|
|
68
|
+
if (signal.aborted) {
|
|
69
|
+
trigger();
|
|
70
|
+
} else if (!ac.signal.aborted) {
|
|
71
|
+
signal.addEventListener('abort', trigger, {
|
|
72
|
+
once: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return ac.signal;
|
|
77
|
+
function trigger() {
|
|
78
|
+
ac.abort();
|
|
79
|
+
for (const signal of signals){
|
|
80
|
+
signal.removeEventListener('abort', trigger);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
46
84
|
|
|
85
|
+
exports.abortSignalsAnyPonyfill = abortSignalsAnyPonyfill;
|
|
86
|
+
exports.assert = assert;
|
|
47
87
|
exports.identity = identity;
|
|
48
88
|
exports.isAsyncIterable = isAsyncIterable;
|
|
49
89
|
exports.isFunction = isFunction;
|
|
@@ -52,4 +92,5 @@ exports.mergeWithoutOverrides = mergeWithoutOverrides;
|
|
|
52
92
|
exports.noop = noop;
|
|
53
93
|
exports.omitPrototype = omitPrototype;
|
|
54
94
|
exports.run = run;
|
|
95
|
+
exports.sleep = sleep;
|
|
55
96
|
exports.unsetMarker = unsetMarker;
|