@trpc/server 11.0.0-alpha-tmp-subscription-connection-state.489 → 11.0.0-alpha-tmp-12-06-react.665
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/@trpc/server/http.d.ts +1 -1
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/index.d.ts +1 -1
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.js +2 -2
- package/dist/adapters/aws-lambda/getPlanner.mjs +2 -2
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +2 -0
- package/dist/adapters/aws-lambda/index.mjs +2 -0
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +27 -7
- package/dist/adapters/express.mjs +27 -7
- package/dist/adapters/fastify/fastifyRequestHandler.js +3 -1
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +3 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +9 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +10 -3
- package/dist/adapters/fetch/fetchRequestHandler.js +9 -8
- package/dist/adapters/fetch/fetchRequestHandler.mjs +9 -8
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +10 -5
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +10 -5
- package/dist/adapters/next-app-dir/notFound.js +2 -0
- package/dist/adapters/next-app-dir/notFound.mjs +2 -0
- package/dist/adapters/next-app-dir/redirect.js +16 -1
- package/dist/adapters/next-app-dir/redirect.mjs +16 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.js +4 -3
- package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +4 -3
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +23 -30
- package/dist/adapters/next.mjs +24 -31
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +2 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +83 -40
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +83 -41
- package/dist/adapters/node-http/index.js +2 -0
- package/dist/adapters/node-http/index.mjs +2 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +7 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +70 -58
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +70 -59
- package/dist/adapters/node-http/writeResponse.d.ts +18 -0
- package/dist/adapters/node-http/writeResponse.d.ts.map +1 -0
- package/dist/adapters/node-http/writeResponse.js +82 -0
- package/dist/adapters/node-http/writeResponse.mjs +79 -0
- package/dist/adapters/standalone.d.ts +5 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +25 -13
- package/dist/adapters/standalone.mjs +26 -14
- package/dist/adapters/ws.d.ts +14 -4
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +217 -101
- package/dist/adapters/ws.mjs +217 -102
- package/dist/bundle-analysis.json +412 -310
- package/dist/http.js +2 -4
- package/dist/http.mjs +2 -2
- package/dist/index.js +3 -0
- package/dist/index.mjs +3 -1
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.1_rollup@4.27.4_tslib@2.8.1_typescript@5.7.2/node_modules/tslib/tslib.es6.js +73 -0
- 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 +5 -0
- package/dist/observable/index.mjs +3 -2
- package/dist/observable/observable.d.ts +2 -1
- package/dist/observable/observable.d.ts.map +1 -1
- package/dist/observable/observable.js +31 -8
- package/dist/observable/observable.mjs +31 -8
- 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/rpc.js +2 -0
- package/dist/rpc.mjs +2 -0
- package/dist/shared.js +2 -0
- package/dist/shared.mjs +2 -0
- package/dist/unstable-core-do-not-import/clientish/inference.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/clientish/inferrable.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/clientish/serialize.d.ts +2 -2
- package/dist/unstable-core-do-not-import/clientish/serialize.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/createProxy.js +1 -1
- package/dist/unstable-core-do-not-import/createProxy.mjs +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.js +16 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +16 -1
- package/dist/unstable-core-do-not-import/error/formatter.js +1 -1
- package/dist/unstable-core-do-not-import/error/formatter.mjs +1 -1
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +2 -2
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +2 -2
- package/dist/unstable-core-do-not-import/http/contentType.js +3 -3
- package/dist/unstable-core-do-not-import/http/contentType.mjs +3 -3
- 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 +28 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +25 -1
- package/dist/unstable-core-do-not-import/http/isAbortError.d.ts +4 -0
- package/dist/unstable-core-do-not-import/http/isAbortError.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/isAbortError.js +9 -0
- package/dist/unstable-core-do-not-import/http/isAbortError.mjs +7 -0
- package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.js +180 -96
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +182 -98
- package/dist/unstable-core-do-not-import/http/types.d.ts +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +11 -11
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.js +11 -11
- package/dist/unstable-core-do-not-import/initTRPC.mjs +11 -11
- package/dist/unstable-core-do-not-import/middleware.d.ts +2 -1
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/middleware.js +2 -2
- package/dist/unstable-core-do-not-import/middleware.mjs +2 -2
- package/dist/unstable-core-do-not-import/parser.d.ts +5 -1
- package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/parser.js +4 -0
- package/dist/unstable-core-do-not-import/parser.mjs +4 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts +8 -2
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +31 -12
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +33 -39
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +33 -39
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +17 -17
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.d.ts +4 -3
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +6 -5
- package/dist/unstable-core-do-not-import/router.mjs +6 -5
- 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/rpc/envelopes.d.ts +7 -10
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +2 -2
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +2 -2
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +25 -14
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.js +439 -318
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +439 -318
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +58 -18
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +297 -122
- package/dist/unstable-core-do-not-import/stream/sse.mjs +298 -123
- 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/tracked.d.ts +2 -2
- package/dist/unstable-core-do-not-import/stream/tracked.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/tracked.js +1 -1
- package/dist/unstable-core-do-not-import/stream/tracked.mjs +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +17 -0
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +171 -0
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +167 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts +0 -11
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.js +0 -29
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.mjs +1 -29
- package/dist/unstable-core-do-not-import/stream/utils/disposable.d.ts +17 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.js +44 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.mjs +41 -0
- package/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.d.ts +8 -0
- package/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.js +25 -0
- package/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.mjs +23 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts +5 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.js +26 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.mjs +23 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts +7 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.js +130 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +127 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +2 -5
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/transformer.js +1 -1
- package/dist/unstable-core-do-not-import/transformer.mjs +1 -1
- package/dist/unstable-core-do-not-import/types.d.ts +26 -3
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +15 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +49 -1
- package/dist/unstable-core-do-not-import/utils.mjs +45 -2
- package/dist/unstable-core-do-not-import.d.ts +3 -2
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +14 -7
- package/dist/unstable-core-do-not-import.mjs +5 -6
- package/dist/vendor/unpromise/index.d.ts +3 -0
- package/dist/vendor/unpromise/index.d.ts.map +1 -0
- package/dist/vendor/unpromise/types.d.ts +28 -0
- package/dist/vendor/unpromise/types.d.ts.map +1 -0
- package/dist/vendor/unpromise/unpromise.d.ts +121 -0
- package/dist/vendor/unpromise/unpromise.d.ts.map +1 -0
- package/dist/vendor/unpromise/unpromise.js +292 -0
- package/dist/vendor/unpromise/unpromise.mjs +289 -0
- package/package.json +20 -17
- package/src/@trpc/server/http.ts +0 -2
- package/src/@trpc/server/index.ts +2 -0
- package/src/adapters/aws-lambda/getPlanner.ts +2 -2
- package/src/adapters/aws-lambda/index.ts +5 -6
- package/src/adapters/express.ts +21 -9
- package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +16 -5
- package/src/adapters/fetch/fetchRequestHandler.ts +2 -2
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +3 -0
- package/src/adapters/next-app-dir/rethrowNextErrors.ts +3 -2
- package/src/adapters/next.ts +29 -34
- package/src/adapters/node-http/incomingMessageToRequest.ts +110 -40
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +85 -63
- package/src/adapters/node-http/writeResponse.ts +94 -0
- package/src/adapters/standalone.ts +35 -18
- package/src/adapters/ws.ts +111 -57
- package/src/observable/behaviorSubject.ts +55 -0
- package/src/observable/index.ts +22 -3
- package/src/observable/observable.ts +32 -14
- package/src/observable/operators.ts +47 -0
- package/src/unstable-core-do-not-import/clientish/inference.ts +4 -4
- package/src/unstable-core-do-not-import/clientish/inferrable.ts +6 -6
- package/src/unstable-core-do-not-import/clientish/serialize.ts +5 -5
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +37 -4
- package/src/unstable-core-do-not-import/http/isAbortError.ts +7 -0
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +185 -90
- package/src/unstable-core-do-not-import/http/types.ts +1 -1
- package/src/unstable-core-do-not-import/initTRPC.ts +14 -20
- package/src/unstable-core-do-not-import/middleware.ts +5 -4
- package/src/unstable-core-do-not-import/parser.ts +17 -6
- package/src/unstable-core-do-not-import/procedure.ts +17 -2
- package/src/unstable-core-do-not-import/procedureBuilder.ts +137 -122
- package/src/unstable-core-do-not-import/rootConfig.ts +20 -20
- package/src/unstable-core-do-not-import/router.ts +15 -16
- package/src/unstable-core-do-not-import/rpc/codes.ts +2 -10
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +7 -12
- package/src/unstable-core-do-not-import/stream/jsonl.ts +287 -296
- package/src/unstable-core-do-not-import/stream/sse.ts +338 -171
- package/src/unstable-core-do-not-import/stream/sse.types.ts +44 -0
- package/src/unstable-core-do-not-import/stream/tracked.ts +5 -11
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +89 -0
- package/src/unstable-core-do-not-import/stream/utils/createDeferred.ts +0 -36
- package/src/unstable-core-do-not-import/stream/utils/disposable.ts +52 -0
- package/src/unstable-core-do-not-import/stream/utils/readableStreamFrom.ts +28 -0
- package/src/unstable-core-do-not-import/stream/utils/timerResource.ts +29 -0
- package/src/unstable-core-do-not-import/stream/utils/withPing.ts +47 -0
- package/src/unstable-core-do-not-import/transformer.ts +1 -1
- package/src/unstable-core-do-not-import/types.ts +35 -10
- package/src/unstable-core-do-not-import/utils.ts +56 -1
- package/src/unstable-core-do-not-import.ts +3 -2
- package/src/vendor/unpromise/ATTRIBUTION.txt +1 -0
- package/src/vendor/unpromise/LICENSE +20 -0
- package/src/vendor/unpromise/index.ts +7 -0
- package/src/vendor/unpromise/types.ts +55 -0
- package/src/vendor/unpromise/unpromise.ts +380 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +0 -32
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +0 -30
- package/dist/unstable-core-do-not-import/http/toURL.d.ts +0 -2
- package/dist/unstable-core-do-not-import/http/toURL.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/toURL.js +0 -8
- package/dist/unstable-core-do-not-import/http/toURL.mjs +0 -6
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts +0 -10
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.js +0 -31
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.mjs +0 -29
- 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/types.js +0 -11
- package/dist/unstable-core-do-not-import/types.mjs +0 -9
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
- package/src/unstable-core-do-not-import/http/toURL.ts +0 -7
- package/src/unstable-core-do-not-import/stream/utils/createReadableStream.ts +0 -31
- package/src/unstable-core-do-not-import/stream/utils/createServer.ts +0 -44
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Unpromise } from '../../../vendor/unpromise';
|
|
2
|
+
import { makeAsyncResource } from './disposable';
|
|
3
|
+
import { disposablePromiseTimerResult, timerResource } from './timerResource';
|
|
4
|
+
|
|
5
|
+
export function iteratorResource<TYield, TReturn, TNext>(
|
|
6
|
+
iterable: AsyncIterable<TYield, TReturn, TNext>,
|
|
7
|
+
): AsyncIterator<TYield, TReturn, TNext> & AsyncDisposable {
|
|
8
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
9
|
+
|
|
10
|
+
return makeAsyncResource(iterator, async () => {
|
|
11
|
+
await iterator.return?.();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
16
|
+
*/
|
|
17
|
+
export async function* withMaxDuration<T>(
|
|
18
|
+
iterable: AsyncIterable<T>,
|
|
19
|
+
opts: { maxDurationMs: number },
|
|
20
|
+
): AsyncGenerator<T> {
|
|
21
|
+
await using iterator = iteratorResource(iterable);
|
|
22
|
+
|
|
23
|
+
using timer = timerResource(opts.maxDurationMs);
|
|
24
|
+
|
|
25
|
+
const timerPromise = timer.start();
|
|
26
|
+
|
|
27
|
+
// declaration outside the loop for garbage collection reasons
|
|
28
|
+
let result: null | IteratorResult<T> | typeof disposablePromiseTimerResult;
|
|
29
|
+
|
|
30
|
+
while (true) {
|
|
31
|
+
result = await Unpromise.race([iterator.next(), timerPromise]);
|
|
32
|
+
if (result === disposablePromiseTimerResult) {
|
|
33
|
+
// cancelled due to timeout
|
|
34
|
+
|
|
35
|
+
const res = await iterator.return?.();
|
|
36
|
+
return res?.value;
|
|
37
|
+
}
|
|
38
|
+
if (result.done) {
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
yield result.value;
|
|
42
|
+
// free up reference for garbage collection
|
|
43
|
+
result = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
49
|
+
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
50
|
+
* values may still come through. After this period, the generator stops.
|
|
51
|
+
*/
|
|
52
|
+
export async function* takeWithGrace<T>(
|
|
53
|
+
iterable: AsyncIterable<T>,
|
|
54
|
+
opts: {
|
|
55
|
+
count: number;
|
|
56
|
+
gracePeriodMs: number;
|
|
57
|
+
},
|
|
58
|
+
): AsyncGenerator<T> {
|
|
59
|
+
await using iterator = iteratorResource(iterable);
|
|
60
|
+
|
|
61
|
+
// declaration outside the loop for garbage collection reasons
|
|
62
|
+
let result: null | IteratorResult<T> | typeof disposablePromiseTimerResult;
|
|
63
|
+
|
|
64
|
+
using timer = timerResource(opts.gracePeriodMs);
|
|
65
|
+
|
|
66
|
+
let count = opts.count;
|
|
67
|
+
|
|
68
|
+
let timerPromise = new Promise<typeof disposablePromiseTimerResult>(() => {
|
|
69
|
+
// never resolves
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
while (true) {
|
|
73
|
+
result = await Unpromise.race([iterator.next(), timerPromise]);
|
|
74
|
+
if (result === disposablePromiseTimerResult) {
|
|
75
|
+
// cancelled
|
|
76
|
+
const res = await iterator.return?.();
|
|
77
|
+
return res?.value;
|
|
78
|
+
}
|
|
79
|
+
if (result.done) {
|
|
80
|
+
return result.value;
|
|
81
|
+
}
|
|
82
|
+
yield result.value;
|
|
83
|
+
if (--count === 0) {
|
|
84
|
+
timerPromise = timer.start();
|
|
85
|
+
}
|
|
86
|
+
// free up reference for garbage collection
|
|
87
|
+
result = null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -10,39 +10,3 @@ export function createDeferred<TValue>() {
|
|
|
10
10
|
return { promise, resolve: resolve!, reject: reject! };
|
|
11
11
|
}
|
|
12
12
|
export type Deferred<TValue> = ReturnType<typeof createDeferred<TValue>>;
|
|
13
|
-
|
|
14
|
-
export const createTimeoutPromise = <TValue>(
|
|
15
|
-
timeoutMs: number,
|
|
16
|
-
value: TValue,
|
|
17
|
-
) => {
|
|
18
|
-
let deferred = createDeferred<TValue>();
|
|
19
|
-
deferred = deferred as typeof deferred & { clear: () => void };
|
|
20
|
-
|
|
21
|
-
let timeout: ReturnType<typeof setTimeout> | null = null;
|
|
22
|
-
const clear = () => {
|
|
23
|
-
if (timeout) {
|
|
24
|
-
clearTimeout(timeout);
|
|
25
|
-
timeout = null;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const resolve = () => {
|
|
29
|
-
deferred.resolve(value);
|
|
30
|
-
clear();
|
|
31
|
-
};
|
|
32
|
-
if (timeoutMs !== Infinity) {
|
|
33
|
-
timeout = setTimeout(resolve, timeoutMs);
|
|
34
|
-
timeout.unref?.();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
promise: deferred.promise,
|
|
39
|
-
/**
|
|
40
|
-
* Clear the timeout without resolving the promise
|
|
41
|
-
*/
|
|
42
|
-
clear,
|
|
43
|
-
/**
|
|
44
|
-
* Resolve the promise with the value
|
|
45
|
-
*/
|
|
46
|
-
resolve,
|
|
47
|
-
};
|
|
48
|
-
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// @ts-expect-error - polyfilling symbol
|
|
2
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
3
|
+
Symbol.dispose ??= Symbol();
|
|
4
|
+
|
|
5
|
+
// @ts-expect-error - polyfilling symbol
|
|
6
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
7
|
+
Symbol.asyncDispose ??= Symbol();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Takes a value and a dispose function and returns a new object that implements the Disposable interface.
|
|
11
|
+
* The returned object is the original value augmented with a Symbol.dispose method.
|
|
12
|
+
* @param thing The value to make disposable
|
|
13
|
+
* @param dispose Function to call when disposing the resource
|
|
14
|
+
* @returns The original value with Symbol.dispose method added
|
|
15
|
+
*/
|
|
16
|
+
export function makeResource<T>(thing: T, dispose: () => void): T & Disposable {
|
|
17
|
+
const it = thing as T & Disposable;
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
20
|
+
if (it[Symbol.dispose]) {
|
|
21
|
+
throw new Error('Symbol.dispose already exists');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
25
|
+
it[Symbol.dispose] = dispose;
|
|
26
|
+
|
|
27
|
+
return it;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Takes a value and an async dispose function and returns a new object that implements the AsyncDisposable interface.
|
|
32
|
+
* The returned object is the original value augmented with a Symbol.asyncDispose method.
|
|
33
|
+
* @param thing The value to make async disposable
|
|
34
|
+
* @param dispose Async function to call when disposing the resource
|
|
35
|
+
* @returns The original value with Symbol.asyncDispose method added
|
|
36
|
+
*/
|
|
37
|
+
export function makeAsyncResource<T>(
|
|
38
|
+
thing: T,
|
|
39
|
+
dispose: () => Promise<void>,
|
|
40
|
+
): T & AsyncDisposable {
|
|
41
|
+
const it = thing as T & AsyncDisposable;
|
|
42
|
+
|
|
43
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
44
|
+
if (it[Symbol.asyncDispose]) {
|
|
45
|
+
throw new Error('Symbol.asyncDispose already exists');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
49
|
+
it[Symbol.asyncDispose] = dispose;
|
|
50
|
+
|
|
51
|
+
return it;
|
|
52
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a ReadableStream from an AsyncIterable.
|
|
3
|
+
*
|
|
4
|
+
* @param iterable - The source AsyncIterable to stream from
|
|
5
|
+
* @returns A ReadableStream that yields values from the AsyncIterable
|
|
6
|
+
*/
|
|
7
|
+
export function readableStreamFrom<TYield>(
|
|
8
|
+
iterable: AsyncIterable<TYield, void>,
|
|
9
|
+
): ReadableStream<TYield> {
|
|
10
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
11
|
+
|
|
12
|
+
return new ReadableStream({
|
|
13
|
+
async cancel() {
|
|
14
|
+
await iterator.return?.();
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
async pull(controller) {
|
|
18
|
+
const result = await iterator.next();
|
|
19
|
+
|
|
20
|
+
if (result.done) {
|
|
21
|
+
controller.close();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
controller.enqueue(result.value);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { makeResource } from './disposable';
|
|
2
|
+
|
|
3
|
+
export const disposablePromiseTimerResult = Symbol();
|
|
4
|
+
|
|
5
|
+
export function timerResource(ms: number) {
|
|
6
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
7
|
+
|
|
8
|
+
return makeResource(
|
|
9
|
+
{
|
|
10
|
+
start() {
|
|
11
|
+
if (timer) {
|
|
12
|
+
throw new Error('Timer already started');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const promise = new Promise<typeof disposablePromiseTimerResult>(
|
|
16
|
+
(resolve) => {
|
|
17
|
+
timer = setTimeout(() => resolve(disposablePromiseTimerResult), ms);
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
return promise;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
() => {
|
|
24
|
+
if (timer) {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Unpromise } from '../../../vendor/unpromise';
|
|
2
|
+
import { iteratorResource } from './asyncIterable';
|
|
3
|
+
import { disposablePromiseTimerResult, timerResource } from './timerResource';
|
|
4
|
+
|
|
5
|
+
export const PING_SYM = Symbol('ping');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields {@link PING_SYM}
|
|
9
|
+
* whenever no value has been yielded for {@link pingIntervalMs}.
|
|
10
|
+
*/
|
|
11
|
+
export async function* withPing<TValue>(
|
|
12
|
+
iterable: AsyncIterable<TValue>,
|
|
13
|
+
pingIntervalMs: number,
|
|
14
|
+
): AsyncGenerator<TValue | typeof PING_SYM> {
|
|
15
|
+
await using iterator = iteratorResource(iterable);
|
|
16
|
+
|
|
17
|
+
// declaration outside the loop for garbage collection reasons
|
|
18
|
+
let result:
|
|
19
|
+
| null
|
|
20
|
+
| IteratorResult<TValue>
|
|
21
|
+
| typeof disposablePromiseTimerResult;
|
|
22
|
+
|
|
23
|
+
let nextPromise = iterator.next();
|
|
24
|
+
|
|
25
|
+
while (true) {
|
|
26
|
+
using pingPromise = timerResource(pingIntervalMs);
|
|
27
|
+
|
|
28
|
+
result = await Unpromise.race([nextPromise, pingPromise.start()]);
|
|
29
|
+
|
|
30
|
+
if (result === disposablePromiseTimerResult) {
|
|
31
|
+
// cancelled
|
|
32
|
+
|
|
33
|
+
yield PING_SYM;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (result.done) {
|
|
38
|
+
return result.value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
nextPromise = iterator.next();
|
|
42
|
+
yield result.value;
|
|
43
|
+
|
|
44
|
+
// free up reference for garbage collection
|
|
45
|
+
result = null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -175,7 +175,7 @@ export function transformResult<TRouter extends AnyRouter, TOutput>(
|
|
|
175
175
|
try {
|
|
176
176
|
// Use the data transformers on the JSON-response
|
|
177
177
|
result = transformResultInner(response, transformer);
|
|
178
|
-
} catch
|
|
178
|
+
} catch {
|
|
179
179
|
throw new TransformResultError();
|
|
180
180
|
}
|
|
181
181
|
|
|
@@ -11,7 +11,7 @@ export type Maybe<TType> = TType | null | undefined;
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @internal
|
|
14
|
-
* @
|
|
14
|
+
* @see https://github.com/ianstormtaylor/superstruct/blob/7973400cd04d8ad92bbdc2b6f35acbfb3c934079/src/utils.ts#L323-L325
|
|
15
15
|
*/
|
|
16
16
|
export type Simplify<TType> = TType extends any[] | Date
|
|
17
17
|
? TType
|
|
@@ -31,6 +31,13 @@ export type FilterKeys<TObj extends object, TFilter> = {
|
|
|
31
31
|
[TKey in keyof TObj]: TObj[TKey] extends TFilter ? TKey : never;
|
|
32
32
|
}[keyof TObj];
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export type Result<TType, TErr = unknown> =
|
|
38
|
+
| { ok: true; value: TType }
|
|
39
|
+
| { ok: false; error: TErr };
|
|
40
|
+
|
|
34
41
|
/**
|
|
35
42
|
* @internal
|
|
36
43
|
*/
|
|
@@ -76,8 +83,8 @@ export type WithoutIndexSignature<TObj> = {
|
|
|
76
83
|
[K in keyof TObj as string extends K
|
|
77
84
|
? never
|
|
78
85
|
: number extends K
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
? never
|
|
87
|
+
: K]: TObj[K];
|
|
81
88
|
};
|
|
82
89
|
|
|
83
90
|
/**
|
|
@@ -94,14 +101,13 @@ export type Overwrite<TType, TWith> = TWith extends any
|
|
|
94
101
|
| keyof WithoutIndexSignature<TWith>]: K extends keyof TWith
|
|
95
102
|
? TWith[K]
|
|
96
103
|
: K extends keyof TType
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
? TType[K]
|
|
105
|
+
: never;
|
|
99
106
|
} & (string extends keyof TWith // Handle cases with an index signature
|
|
100
107
|
? { [key: string]: TWith[string] }
|
|
101
108
|
: number extends keyof TWith
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
{})
|
|
109
|
+
? { [key: number]: TWith[number] }
|
|
110
|
+
: {})
|
|
105
111
|
: TWith
|
|
106
112
|
: never;
|
|
107
113
|
|
|
@@ -124,6 +130,17 @@ export type PickFirstDefined<TType, TPick> = undefined extends TType
|
|
|
124
130
|
: TPick
|
|
125
131
|
: TType;
|
|
126
132
|
|
|
133
|
+
export type KeyFromValue<
|
|
134
|
+
TValue,
|
|
135
|
+
TType extends Record<PropertyKey, PropertyKey>,
|
|
136
|
+
> = {
|
|
137
|
+
[K in keyof TType]: TValue extends TType[K] ? K : never;
|
|
138
|
+
}[keyof TType];
|
|
139
|
+
|
|
140
|
+
export type InvertKeyValue<TType extends Record<PropertyKey, PropertyKey>> = {
|
|
141
|
+
[TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
|
|
142
|
+
};
|
|
143
|
+
|
|
127
144
|
/**
|
|
128
145
|
* ================================
|
|
129
146
|
* tRPC specific types
|
|
@@ -150,8 +167,16 @@ export type ProtectedIntersection<TType, TWith> = keyof TType &
|
|
|
150
167
|
*/
|
|
151
168
|
export type GetRawInputFn = () => Promise<unknown>;
|
|
152
169
|
|
|
153
|
-
|
|
170
|
+
const _errorSymbol = Symbol();
|
|
171
|
+
export type ErrorSymbol = typeof _errorSymbol;
|
|
154
172
|
export type TypeError<TMessage extends string> = TMessage & {
|
|
155
|
-
_: typeof
|
|
173
|
+
_: typeof _errorSymbol;
|
|
156
174
|
};
|
|
157
175
|
export type ValueOf<TObj> = TObj[keyof TObj];
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @internal
|
|
179
|
+
* Infers the type of the value yielded by an async iterable
|
|
180
|
+
*/
|
|
181
|
+
export type inferAsyncIterableYield<T> =
|
|
182
|
+
T extends AsyncIterable<infer U> ? U : T;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const unsetMarker = Symbol(
|
|
2
|
+
export const unsetMarker = Symbol();
|
|
3
3
|
export type UnsetMarker = typeof unsetMarker;
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -61,3 +61,58 @@ export function isAsyncIterable<TValue>(
|
|
|
61
61
|
* Run an IIFE
|
|
62
62
|
*/
|
|
63
63
|
export const run = <TValue>(fn: () => TValue): TValue => fn();
|
|
64
|
+
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
66
|
+
export function noop(): void {}
|
|
67
|
+
|
|
68
|
+
export function identity<T>(it: T): T {
|
|
69
|
+
return it;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Generic runtime assertion function. Throws, if the condition is not `true`.
|
|
74
|
+
*
|
|
75
|
+
* Can be used as a slightly less dangerous variant of type assertions. Code
|
|
76
|
+
* mistakes would be revealed at runtime then (hopefully during testing).
|
|
77
|
+
*/
|
|
78
|
+
export function assert(
|
|
79
|
+
condition: boolean,
|
|
80
|
+
msg = 'no additional info',
|
|
81
|
+
): asserts condition {
|
|
82
|
+
if (!condition) {
|
|
83
|
+
throw new Error(`AssertionError: ${msg}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function sleep(ms = 0): Promise<void> {
|
|
88
|
+
return new Promise<void>((res) => setTimeout(res, ms));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Ponyfill for
|
|
93
|
+
* [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
|
|
94
|
+
*/
|
|
95
|
+
export function abortSignalsAnyPonyfill(signals: AbortSignal[]): AbortSignal {
|
|
96
|
+
if (typeof AbortSignal.any === 'function') {
|
|
97
|
+
return AbortSignal.any(signals);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const ac = new AbortController();
|
|
101
|
+
|
|
102
|
+
for (const signal of signals) {
|
|
103
|
+
if (signal.aborted) {
|
|
104
|
+
trigger();
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
signal.addEventListener('abort', trigger, { once: true });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return ac.signal;
|
|
111
|
+
|
|
112
|
+
function trigger() {
|
|
113
|
+
ac.abort();
|
|
114
|
+
for (const signal of signals) {
|
|
115
|
+
signal.removeEventListener('abort', trigger);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -15,14 +15,13 @@ export * from './unstable-core-do-not-import/createProxy';
|
|
|
15
15
|
export * from './unstable-core-do-not-import/error/formatter';
|
|
16
16
|
export * from './unstable-core-do-not-import/error/getErrorShape';
|
|
17
17
|
export * from './unstable-core-do-not-import/error/TRPCError';
|
|
18
|
-
export * from './unstable-core-do-not-import/http/batchStreamFormatter';
|
|
19
18
|
export * from './unstable-core-do-not-import/http/contentType';
|
|
20
19
|
export * from './unstable-core-do-not-import/http/contentTypeParsers';
|
|
21
20
|
export * from './unstable-core-do-not-import/http/formDataToObject';
|
|
22
21
|
export * from './unstable-core-do-not-import/http/getHTTPStatusCode';
|
|
22
|
+
export * from './unstable-core-do-not-import/http/isAbortError';
|
|
23
23
|
export * from './unstable-core-do-not-import/http/parseConnectionParams';
|
|
24
24
|
export * from './unstable-core-do-not-import/http/resolveResponse';
|
|
25
|
-
export * from './unstable-core-do-not-import/http/toURL';
|
|
26
25
|
export * from './unstable-core-do-not-import/http/types';
|
|
27
26
|
export * from './unstable-core-do-not-import/initTRPC';
|
|
28
27
|
export * from './unstable-core-do-not-import/middleware';
|
|
@@ -33,9 +32,11 @@ export * from './unstable-core-do-not-import/rootConfig';
|
|
|
33
32
|
export * from './unstable-core-do-not-import/router';
|
|
34
33
|
export * from './unstable-core-do-not-import/rpc';
|
|
35
34
|
export * from './unstable-core-do-not-import/stream/jsonl';
|
|
35
|
+
export * from './unstable-core-do-not-import/stream/sse.types';
|
|
36
36
|
export * from './unstable-core-do-not-import/stream/sse';
|
|
37
37
|
export * from './unstable-core-do-not-import/stream/tracked';
|
|
38
38
|
export * from './unstable-core-do-not-import/stream/utils/createDeferred';
|
|
39
|
+
export * from './unstable-core-do-not-import/stream/utils/disposable';
|
|
39
40
|
export * from './unstable-core-do-not-import/transformer';
|
|
40
41
|
export * from './unstable-core-do-not-import/types';
|
|
41
42
|
export * from './unstable-core-do-not-import/utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Origin source: https://github.com/cefn/watchable/tree/main/packages/unpromise
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2023 Cefn Hoile
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** TYPES */
|
|
2
|
+
|
|
3
|
+
/** A promise that exploits a single, memory-safe upstream subscription
|
|
4
|
+
* to a single re-used Unpromise that persists for the VM lifetime of a
|
|
5
|
+
* Promise.
|
|
6
|
+
*
|
|
7
|
+
* Calling unsubscribe() removes the subscription, eliminating
|
|
8
|
+
* all references to the SubscribedPromise. */
|
|
9
|
+
export interface SubscribedPromise<T> extends Promise<T> {
|
|
10
|
+
unsubscribe: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Duplicate of Promise interface, except each call returns SubscribedPromise */
|
|
14
|
+
export interface ProxyPromise<T> extends Promise<T> {
|
|
15
|
+
subscribe: () => SubscribedPromise<T>;
|
|
16
|
+
|
|
17
|
+
then: <TResult1 = T, TResult2 = never>(
|
|
18
|
+
onfulfilled?:
|
|
19
|
+
| ((value: T) => TResult1 | PromiseLike<TResult1>)
|
|
20
|
+
| null
|
|
21
|
+
,
|
|
22
|
+
onrejected?:
|
|
23
|
+
| ((reason: any) => TResult2 | PromiseLike<TResult2>)
|
|
24
|
+
| null
|
|
25
|
+
|
|
26
|
+
) => SubscribedPromise<TResult1 | TResult2>;
|
|
27
|
+
|
|
28
|
+
catch: <TResult = never>(
|
|
29
|
+
onrejected?:
|
|
30
|
+
| ((reason: any) => TResult | PromiseLike<TResult>)
|
|
31
|
+
| null
|
|
32
|
+
|
|
33
|
+
) => SubscribedPromise<T | TResult>;
|
|
34
|
+
|
|
35
|
+
finally: (
|
|
36
|
+
onfinally?: (() => void) | null
|
|
37
|
+
) => SubscribedPromise<T>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type PromiseExecutor<T> = (
|
|
41
|
+
resolve: (value: T | PromiseLike<T>) => void,
|
|
42
|
+
reject: (reason?: any) => void
|
|
43
|
+
) => void;
|
|
44
|
+
|
|
45
|
+
/** A standard pattern for a resolvable, rejectable Promise, based
|
|
46
|
+
* on the emerging ES2023 standard. Type ported from
|
|
47
|
+
* https://github.com/microsoft/TypeScript/pull/56593 */
|
|
48
|
+
export interface PromiseWithResolvers<T> {
|
|
49
|
+
promise: Promise<T>;
|
|
50
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
51
|
+
reject: (reason?: any) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Given an array, this is the union of its members' types. */
|
|
55
|
+
// export type MemberOf<Arr extends readonly unknown[]> = Arr[number];
|