@trpc/server 11.0.0-alpha-tmp-subscription-connection-state.488 → 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 +5 -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 +236 -90
- package/dist/adapters/ws.mjs +237 -92
- package/dist/bundle-analysis.json +411 -294
- package/dist/http.js +2 -4
- package/dist/http.mjs +2 -2
- package/dist/index.js +6 -2
- 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 +187 -92
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +189 -94
- 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 +32 -13
- 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 +11 -6
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +7 -3
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +7 -3
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +31 -16
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.js +440 -318
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +440 -318
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +63 -41
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +300 -119
- package/dist/unstable-core-do-not-import/stream/sse.mjs +302 -119
- 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 +31 -0
- package/dist/unstable-core-do-not-import/stream/tracked.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/tracked.js +29 -0
- package/dist/unstable-core-do-not-import/stream/tracked.mjs +25 -0
- 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 -4
- 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 +4 -2
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +18 -9
- package/dist/unstable-core-do-not-import.mjs +7 -7
- 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 +6 -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 +152 -62
- 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 +192 -85
- 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 +138 -123
- package/src/unstable-core-do-not-import/rootConfig.ts +20 -17
- 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 +18 -7
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +5 -1
- package/src/unstable-core-do-not-import/stream/jsonl.ts +293 -294
- package/src/unstable-core-do-not-import/stream/sse.ts +349 -191
- package/src/unstable-core-do-not-import/stream/sse.types.ts +44 -0
- package/src/unstable-core-do-not-import/stream/tracked.ts +49 -0
- 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 +4 -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,171 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var unpromise = require('../../../vendor/unpromise/unpromise.js');
|
|
4
|
+
var disposable = require('./disposable.js');
|
|
5
|
+
var timerResource = require('./timerResource.js');
|
|
6
|
+
|
|
7
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
8
|
+
if (value !== null && value !== void 0) {
|
|
9
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
10
|
+
var dispose, inner;
|
|
11
|
+
if (async) {
|
|
12
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
13
|
+
dispose = value[Symbol.asyncDispose];
|
|
14
|
+
}
|
|
15
|
+
if (dispose === void 0) {
|
|
16
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
17
|
+
dispose = value[Symbol.dispose];
|
|
18
|
+
if (async) inner = dispose;
|
|
19
|
+
}
|
|
20
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
21
|
+
if (inner) dispose = function() {
|
|
22
|
+
try {
|
|
23
|
+
inner.call(this);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
return Promise.reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
env.stack.push({
|
|
29
|
+
value: value,
|
|
30
|
+
dispose: dispose,
|
|
31
|
+
async: async
|
|
32
|
+
});
|
|
33
|
+
} else if (async) {
|
|
34
|
+
env.stack.push({
|
|
35
|
+
async: true
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
function _ts_dispose_resources(env) {
|
|
41
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
42
|
+
var e = new Error(message);
|
|
43
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
44
|
+
};
|
|
45
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
46
|
+
function fail(e) {
|
|
47
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
48
|
+
env.hasError = true;
|
|
49
|
+
}
|
|
50
|
+
var r, s = 0;
|
|
51
|
+
function next() {
|
|
52
|
+
while(r = env.stack.pop()){
|
|
53
|
+
try {
|
|
54
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
55
|
+
if (r.dispose) {
|
|
56
|
+
var result = r.dispose.call(r.value);
|
|
57
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
58
|
+
fail(e);
|
|
59
|
+
return next();
|
|
60
|
+
});
|
|
61
|
+
} else s |= 1;
|
|
62
|
+
} catch (e) {
|
|
63
|
+
fail(e);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
67
|
+
if (env.hasError) throw env.error;
|
|
68
|
+
}
|
|
69
|
+
return next();
|
|
70
|
+
})(env);
|
|
71
|
+
}
|
|
72
|
+
function iteratorResource(iterable) {
|
|
73
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
74
|
+
return disposable.makeAsyncResource(iterator, async ()=>{
|
|
75
|
+
await iterator.return?.();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
80
|
+
*/ async function* withMaxDuration(iterable, opts) {
|
|
81
|
+
const env = {
|
|
82
|
+
stack: [],
|
|
83
|
+
error: void 0,
|
|
84
|
+
hasError: false
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
|
|
88
|
+
;
|
|
89
|
+
const timer = _ts_add_disposable_resource(env, timerResource.timerResource(opts.maxDurationMs), false);
|
|
90
|
+
;
|
|
91
|
+
const timerPromise = timer.start();
|
|
92
|
+
// declaration outside the loop for garbage collection reasons
|
|
93
|
+
let result;
|
|
94
|
+
while(true){
|
|
95
|
+
result = await unpromise.Unpromise.race([
|
|
96
|
+
iterator.next(),
|
|
97
|
+
timerPromise
|
|
98
|
+
]);
|
|
99
|
+
if (result === timerResource.disposablePromiseTimerResult) {
|
|
100
|
+
// cancelled due to timeout
|
|
101
|
+
const res = await iterator.return?.();
|
|
102
|
+
return res?.value;
|
|
103
|
+
}
|
|
104
|
+
if (result.done) {
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
yield result.value;
|
|
108
|
+
// free up reference for garbage collection
|
|
109
|
+
result = null;
|
|
110
|
+
}
|
|
111
|
+
} catch (e) {
|
|
112
|
+
env.error = e;
|
|
113
|
+
env.hasError = true;
|
|
114
|
+
} finally{
|
|
115
|
+
const result = _ts_dispose_resources(env);
|
|
116
|
+
if (result) await result;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
121
|
+
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
122
|
+
* values may still come through. After this period, the generator stops.
|
|
123
|
+
*/ async function* takeWithGrace(iterable, opts) {
|
|
124
|
+
const env = {
|
|
125
|
+
stack: [],
|
|
126
|
+
error: void 0,
|
|
127
|
+
hasError: false
|
|
128
|
+
};
|
|
129
|
+
try {
|
|
130
|
+
const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
|
|
131
|
+
;
|
|
132
|
+
// declaration outside the loop for garbage collection reasons
|
|
133
|
+
let result;
|
|
134
|
+
const timer = _ts_add_disposable_resource(env, timerResource.timerResource(opts.gracePeriodMs), false);
|
|
135
|
+
;
|
|
136
|
+
let count = opts.count;
|
|
137
|
+
let timerPromise = new Promise(()=>{
|
|
138
|
+
// never resolves
|
|
139
|
+
});
|
|
140
|
+
while(true){
|
|
141
|
+
result = await unpromise.Unpromise.race([
|
|
142
|
+
iterator.next(),
|
|
143
|
+
timerPromise
|
|
144
|
+
]);
|
|
145
|
+
if (result === timerResource.disposablePromiseTimerResult) {
|
|
146
|
+
// cancelled
|
|
147
|
+
const res = await iterator.return?.();
|
|
148
|
+
return res?.value;
|
|
149
|
+
}
|
|
150
|
+
if (result.done) {
|
|
151
|
+
return result.value;
|
|
152
|
+
}
|
|
153
|
+
yield result.value;
|
|
154
|
+
if (--count === 0) {
|
|
155
|
+
timerPromise = timer.start();
|
|
156
|
+
}
|
|
157
|
+
// free up reference for garbage collection
|
|
158
|
+
result = null;
|
|
159
|
+
}
|
|
160
|
+
} catch (e) {
|
|
161
|
+
env.error = e;
|
|
162
|
+
env.hasError = true;
|
|
163
|
+
} finally{
|
|
164
|
+
const result = _ts_dispose_resources(env);
|
|
165
|
+
if (result) await result;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
exports.iteratorResource = iteratorResource;
|
|
170
|
+
exports.takeWithGrace = takeWithGrace;
|
|
171
|
+
exports.withMaxDuration = withMaxDuration;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Unpromise } from '../../../vendor/unpromise/unpromise.mjs';
|
|
2
|
+
import { makeAsyncResource } from './disposable.mjs';
|
|
3
|
+
import { timerResource, disposablePromiseTimerResult } from './timerResource.mjs';
|
|
4
|
+
|
|
5
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
6
|
+
if (value !== null && value !== void 0) {
|
|
7
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
8
|
+
var dispose, inner;
|
|
9
|
+
if (async) {
|
|
10
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.asyncDispose];
|
|
12
|
+
}
|
|
13
|
+
if (dispose === void 0) {
|
|
14
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
15
|
+
dispose = value[Symbol.dispose];
|
|
16
|
+
if (async) inner = dispose;
|
|
17
|
+
}
|
|
18
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
19
|
+
if (inner) dispose = function() {
|
|
20
|
+
try {
|
|
21
|
+
inner.call(this);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return Promise.reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
env.stack.push({
|
|
27
|
+
value: value,
|
|
28
|
+
dispose: dispose,
|
|
29
|
+
async: async
|
|
30
|
+
});
|
|
31
|
+
} else if (async) {
|
|
32
|
+
env.stack.push({
|
|
33
|
+
async: true
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function _ts_dispose_resources(env) {
|
|
39
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
40
|
+
var e = new Error(message);
|
|
41
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
42
|
+
};
|
|
43
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
44
|
+
function fail(e) {
|
|
45
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
46
|
+
env.hasError = true;
|
|
47
|
+
}
|
|
48
|
+
var r, s = 0;
|
|
49
|
+
function next() {
|
|
50
|
+
while(r = env.stack.pop()){
|
|
51
|
+
try {
|
|
52
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
53
|
+
if (r.dispose) {
|
|
54
|
+
var result = r.dispose.call(r.value);
|
|
55
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
56
|
+
fail(e);
|
|
57
|
+
return next();
|
|
58
|
+
});
|
|
59
|
+
} else s |= 1;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
fail(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
65
|
+
if (env.hasError) throw env.error;
|
|
66
|
+
}
|
|
67
|
+
return next();
|
|
68
|
+
})(env);
|
|
69
|
+
}
|
|
70
|
+
function iteratorResource(iterable) {
|
|
71
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
72
|
+
return makeAsyncResource(iterator, async ()=>{
|
|
73
|
+
await iterator.return?.();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
78
|
+
*/ async function* withMaxDuration(iterable, opts) {
|
|
79
|
+
const env = {
|
|
80
|
+
stack: [],
|
|
81
|
+
error: void 0,
|
|
82
|
+
hasError: false
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
|
|
86
|
+
;
|
|
87
|
+
const timer = _ts_add_disposable_resource(env, timerResource(opts.maxDurationMs), false);
|
|
88
|
+
;
|
|
89
|
+
const timerPromise = timer.start();
|
|
90
|
+
// declaration outside the loop for garbage collection reasons
|
|
91
|
+
let result;
|
|
92
|
+
while(true){
|
|
93
|
+
result = await Unpromise.race([
|
|
94
|
+
iterator.next(),
|
|
95
|
+
timerPromise
|
|
96
|
+
]);
|
|
97
|
+
if (result === disposablePromiseTimerResult) {
|
|
98
|
+
// cancelled due to timeout
|
|
99
|
+
const res = await iterator.return?.();
|
|
100
|
+
return res?.value;
|
|
101
|
+
}
|
|
102
|
+
if (result.done) {
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
yield result.value;
|
|
106
|
+
// free up reference for garbage collection
|
|
107
|
+
result = null;
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
env.error = e;
|
|
111
|
+
env.hasError = true;
|
|
112
|
+
} finally{
|
|
113
|
+
const result = _ts_dispose_resources(env);
|
|
114
|
+
if (result) await result;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
119
|
+
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
120
|
+
* values may still come through. After this period, the generator stops.
|
|
121
|
+
*/ async function* takeWithGrace(iterable, opts) {
|
|
122
|
+
const env = {
|
|
123
|
+
stack: [],
|
|
124
|
+
error: void 0,
|
|
125
|
+
hasError: false
|
|
126
|
+
};
|
|
127
|
+
try {
|
|
128
|
+
const iterator = _ts_add_disposable_resource(env, iteratorResource(iterable), true);
|
|
129
|
+
;
|
|
130
|
+
// declaration outside the loop for garbage collection reasons
|
|
131
|
+
let result;
|
|
132
|
+
const timer = _ts_add_disposable_resource(env, timerResource(opts.gracePeriodMs), false);
|
|
133
|
+
;
|
|
134
|
+
let count = opts.count;
|
|
135
|
+
let timerPromise = new Promise(()=>{
|
|
136
|
+
// never resolves
|
|
137
|
+
});
|
|
138
|
+
while(true){
|
|
139
|
+
result = await Unpromise.race([
|
|
140
|
+
iterator.next(),
|
|
141
|
+
timerPromise
|
|
142
|
+
]);
|
|
143
|
+
if (result === disposablePromiseTimerResult) {
|
|
144
|
+
// cancelled
|
|
145
|
+
const res = await iterator.return?.();
|
|
146
|
+
return res?.value;
|
|
147
|
+
}
|
|
148
|
+
if (result.done) {
|
|
149
|
+
return result.value;
|
|
150
|
+
}
|
|
151
|
+
yield result.value;
|
|
152
|
+
if (--count === 0) {
|
|
153
|
+
timerPromise = timer.start();
|
|
154
|
+
}
|
|
155
|
+
// free up reference for garbage collection
|
|
156
|
+
result = null;
|
|
157
|
+
}
|
|
158
|
+
} catch (e) {
|
|
159
|
+
env.error = e;
|
|
160
|
+
env.hasError = true;
|
|
161
|
+
} finally{
|
|
162
|
+
const result = _ts_dispose_resources(env);
|
|
163
|
+
if (result) await result;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { iteratorResource, takeWithGrace, withMaxDuration };
|
|
@@ -4,15 +4,4 @@ export declare function createDeferred<TValue>(): {
|
|
|
4
4
|
reject: (error: unknown) => void;
|
|
5
5
|
};
|
|
6
6
|
export type Deferred<TValue> = ReturnType<typeof createDeferred<TValue>>;
|
|
7
|
-
export declare const createTimeoutPromise: <TValue>(timeoutMs: number, value: TValue) => {
|
|
8
|
-
promise: Promise<TValue>;
|
|
9
|
-
/**
|
|
10
|
-
* Clear the timeout without resolving the promise
|
|
11
|
-
*/
|
|
12
|
-
clear: () => void;
|
|
13
|
-
/**
|
|
14
|
-
* Resolve the promise with the value
|
|
15
|
-
*/
|
|
16
|
-
resolve: () => void;
|
|
17
|
-
};
|
|
18
7
|
//# sourceMappingURL=createDeferred.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDeferred.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/createDeferred.ts"],"names":[],"mappings":"AACA,wBAAgB,cAAc,CAAC,MAAM;;qBACd,MAAM,KAAK,IAAI;oBAChB,OAAO,KAAK,IAAI;EAOrC;AACD,MAAM,MAAM,QAAQ,CAAC,MAAM,IAAI,UAAU,CAAC,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"createDeferred.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/createDeferred.ts"],"names":[],"mappings":"AACA,wBAAgB,cAAc,CAAC,MAAM;;qBACd,MAAM,KAAK,IAAI;oBAChB,OAAO,KAAK,IAAI;EAOrC;AACD,MAAM,MAAM,QAAQ,CAAC,MAAM,IAAI,UAAU,CAAC,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -13,34 +13,5 @@
|
|
|
13
13
|
reject: reject
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
const createTimeoutPromise = (timeoutMs, value)=>{
|
|
17
|
-
let deferred = createDeferred();
|
|
18
|
-
deferred = deferred;
|
|
19
|
-
let timeout = null;
|
|
20
|
-
const clear = ()=>{
|
|
21
|
-
if (timeout) {
|
|
22
|
-
clearTimeout(timeout);
|
|
23
|
-
timeout = null;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
const resolve = ()=>{
|
|
27
|
-
deferred.resolve(value);
|
|
28
|
-
clear();
|
|
29
|
-
};
|
|
30
|
-
if (timeoutMs !== Infinity) {
|
|
31
|
-
timeout = setTimeout(resolve, timeoutMs);
|
|
32
|
-
timeout.unref?.();
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
promise: deferred.promise,
|
|
36
|
-
/**
|
|
37
|
-
* Clear the timeout without resolving the promise
|
|
38
|
-
*/ clear,
|
|
39
|
-
/**
|
|
40
|
-
* Resolve the promise with the value
|
|
41
|
-
*/ resolve
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
16
|
|
|
45
17
|
exports.createDeferred = createDeferred;
|
|
46
|
-
exports.createTimeoutPromise = createTimeoutPromise;
|
|
@@ -11,33 +11,5 @@
|
|
|
11
11
|
reject: reject
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
const createTimeoutPromise = (timeoutMs, value)=>{
|
|
15
|
-
let deferred = createDeferred();
|
|
16
|
-
deferred = deferred;
|
|
17
|
-
let timeout = null;
|
|
18
|
-
const clear = ()=>{
|
|
19
|
-
if (timeout) {
|
|
20
|
-
clearTimeout(timeout);
|
|
21
|
-
timeout = null;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const resolve = ()=>{
|
|
25
|
-
deferred.resolve(value);
|
|
26
|
-
clear();
|
|
27
|
-
};
|
|
28
|
-
if (timeoutMs !== Infinity) {
|
|
29
|
-
timeout = setTimeout(resolve, timeoutMs);
|
|
30
|
-
timeout.unref?.();
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
promise: deferred.promise,
|
|
34
|
-
/**
|
|
35
|
-
* Clear the timeout without resolving the promise
|
|
36
|
-
*/ clear,
|
|
37
|
-
/**
|
|
38
|
-
* Resolve the promise with the value
|
|
39
|
-
*/ resolve
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
14
|
|
|
43
|
-
export { createDeferred
|
|
15
|
+
export { createDeferred };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes a value and a dispose function and returns a new object that implements the Disposable interface.
|
|
3
|
+
* The returned object is the original value augmented with a Symbol.dispose method.
|
|
4
|
+
* @param thing The value to make disposable
|
|
5
|
+
* @param dispose Function to call when disposing the resource
|
|
6
|
+
* @returns The original value with Symbol.dispose method added
|
|
7
|
+
*/
|
|
8
|
+
export declare function makeResource<T>(thing: T, dispose: () => void): T & Disposable;
|
|
9
|
+
/**
|
|
10
|
+
* Takes a value and an async dispose function and returns a new object that implements the AsyncDisposable interface.
|
|
11
|
+
* The returned object is the original value augmented with a Symbol.asyncDispose method.
|
|
12
|
+
* @param thing The value to make async disposable
|
|
13
|
+
* @param dispose Async function to call when disposing the resource
|
|
14
|
+
* @returns The original value with Symbol.asyncDispose method added
|
|
15
|
+
*/
|
|
16
|
+
export declare function makeAsyncResource<T>(thing: T, dispose: () => Promise<void>): T & AsyncDisposable;
|
|
17
|
+
//# sourceMappingURL=disposable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disposable.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/disposable.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,CAAC,GAAG,UAAU,CAY7E;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAC3B,CAAC,GAAG,eAAe,CAYrB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// @ts-expect-error - polyfilling symbol
|
|
4
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
5
|
+
var _Symbol, // @ts-expect-error - polyfilling symbol
|
|
6
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
7
|
+
_Symbol1;
|
|
8
|
+
(_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol());
|
|
9
|
+
(_Symbol1 = Symbol).asyncDispose ?? (_Symbol1.asyncDispose = Symbol());
|
|
10
|
+
/**
|
|
11
|
+
* Takes a value and a dispose function and returns a new object that implements the Disposable interface.
|
|
12
|
+
* The returned object is the original value augmented with a Symbol.dispose method.
|
|
13
|
+
* @param thing The value to make disposable
|
|
14
|
+
* @param dispose Function to call when disposing the resource
|
|
15
|
+
* @returns The original value with Symbol.dispose method added
|
|
16
|
+
*/ function makeResource(thing, dispose) {
|
|
17
|
+
const it = thing;
|
|
18
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
19
|
+
if (it[Symbol.dispose]) {
|
|
20
|
+
throw new Error('Symbol.dispose already exists');
|
|
21
|
+
}
|
|
22
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
23
|
+
it[Symbol.dispose] = dispose;
|
|
24
|
+
return it;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Takes a value and an async dispose function and returns a new object that implements the AsyncDisposable interface.
|
|
28
|
+
* The returned object is the original value augmented with a Symbol.asyncDispose method.
|
|
29
|
+
* @param thing The value to make async disposable
|
|
30
|
+
* @param dispose Async function to call when disposing the resource
|
|
31
|
+
* @returns The original value with Symbol.asyncDispose method added
|
|
32
|
+
*/ function makeAsyncResource(thing, dispose) {
|
|
33
|
+
const it = thing;
|
|
34
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
35
|
+
if (it[Symbol.asyncDispose]) {
|
|
36
|
+
throw new Error('Symbol.asyncDispose already exists');
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
39
|
+
it[Symbol.asyncDispose] = dispose;
|
|
40
|
+
return it;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.makeAsyncResource = makeAsyncResource;
|
|
44
|
+
exports.makeResource = makeResource;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @ts-expect-error - polyfilling symbol
|
|
2
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
3
|
+
var _Symbol, // @ts-expect-error - polyfilling symbol
|
|
4
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
5
|
+
_Symbol1;
|
|
6
|
+
(_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol());
|
|
7
|
+
(_Symbol1 = Symbol).asyncDispose ?? (_Symbol1.asyncDispose = Symbol());
|
|
8
|
+
/**
|
|
9
|
+
* Takes a value and a dispose function and returns a new object that implements the Disposable interface.
|
|
10
|
+
* The returned object is the original value augmented with a Symbol.dispose method.
|
|
11
|
+
* @param thing The value to make disposable
|
|
12
|
+
* @param dispose Function to call when disposing the resource
|
|
13
|
+
* @returns The original value with Symbol.dispose method added
|
|
14
|
+
*/ function makeResource(thing, dispose) {
|
|
15
|
+
const it = thing;
|
|
16
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
17
|
+
if (it[Symbol.dispose]) {
|
|
18
|
+
throw new Error('Symbol.dispose already exists');
|
|
19
|
+
}
|
|
20
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
21
|
+
it[Symbol.dispose] = dispose;
|
|
22
|
+
return it;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Takes a value and an async dispose function and returns a new object that implements the AsyncDisposable interface.
|
|
26
|
+
* The returned object is the original value augmented with a Symbol.asyncDispose method.
|
|
27
|
+
* @param thing The value to make async disposable
|
|
28
|
+
* @param dispose Async function to call when disposing the resource
|
|
29
|
+
* @returns The original value with Symbol.asyncDispose method added
|
|
30
|
+
*/ function makeAsyncResource(thing, dispose) {
|
|
31
|
+
const it = thing;
|
|
32
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
33
|
+
if (it[Symbol.asyncDispose]) {
|
|
34
|
+
throw new Error('Symbol.asyncDispose already exists');
|
|
35
|
+
}
|
|
36
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
37
|
+
it[Symbol.asyncDispose] = dispose;
|
|
38
|
+
return it;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { makeAsyncResource, makeResource };
|
|
@@ -0,0 +1,8 @@
|
|
|
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 declare function readableStreamFrom<TYield>(iterable: AsyncIterable<TYield, void>): ReadableStream<TYield>;
|
|
8
|
+
//# sourceMappingURL=readableStreamFrom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readableStreamFrom.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/readableStreamFrom.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EACvC,QAAQ,EAAE,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,GACpC,cAAc,CAAC,MAAM,CAAC,CAmBxB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a ReadableStream from an AsyncIterable.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable - The source AsyncIterable to stream from
|
|
7
|
+
* @returns A ReadableStream that yields values from the AsyncIterable
|
|
8
|
+
*/ function readableStreamFrom(iterable) {
|
|
9
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
10
|
+
return new ReadableStream({
|
|
11
|
+
async cancel () {
|
|
12
|
+
await iterator.return?.();
|
|
13
|
+
},
|
|
14
|
+
async pull (controller) {
|
|
15
|
+
const result = await iterator.next();
|
|
16
|
+
if (result.done) {
|
|
17
|
+
controller.close();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
controller.enqueue(result.value);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.readableStreamFrom = readableStreamFrom;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
*/ function readableStreamFrom(iterable) {
|
|
7
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
8
|
+
return new ReadableStream({
|
|
9
|
+
async cancel () {
|
|
10
|
+
await iterator.return?.();
|
|
11
|
+
},
|
|
12
|
+
async pull (controller) {
|
|
13
|
+
const result = await iterator.next();
|
|
14
|
+
if (result.done) {
|
|
15
|
+
controller.close();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
controller.enqueue(result.value);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { readableStreamFrom };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timerResource.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/timerResource.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,4BAA4B,eAAW,CAAC;AAErD,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM;;eAwBvC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var disposable = require('./disposable.js');
|
|
4
|
+
|
|
5
|
+
const disposablePromiseTimerResult = Symbol();
|
|
6
|
+
function timerResource(ms) {
|
|
7
|
+
let timer = null;
|
|
8
|
+
return disposable.makeResource({
|
|
9
|
+
start () {
|
|
10
|
+
if (timer) {
|
|
11
|
+
throw new Error('Timer already started');
|
|
12
|
+
}
|
|
13
|
+
const promise = new Promise((resolve)=>{
|
|
14
|
+
timer = setTimeout(()=>resolve(disposablePromiseTimerResult), ms);
|
|
15
|
+
});
|
|
16
|
+
return promise;
|
|
17
|
+
}
|
|
18
|
+
}, ()=>{
|
|
19
|
+
if (timer) {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.disposablePromiseTimerResult = disposablePromiseTimerResult;
|
|
26
|
+
exports.timerResource = timerResource;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { makeResource } from './disposable.mjs';
|
|
2
|
+
|
|
3
|
+
const disposablePromiseTimerResult = Symbol();
|
|
4
|
+
function timerResource(ms) {
|
|
5
|
+
let timer = null;
|
|
6
|
+
return makeResource({
|
|
7
|
+
start () {
|
|
8
|
+
if (timer) {
|
|
9
|
+
throw new Error('Timer already started');
|
|
10
|
+
}
|
|
11
|
+
const promise = new Promise((resolve)=>{
|
|
12
|
+
timer = setTimeout(()=>resolve(disposablePromiseTimerResult), ms);
|
|
13
|
+
});
|
|
14
|
+
return promise;
|
|
15
|
+
}
|
|
16
|
+
}, ()=>{
|
|
17
|
+
if (timer) {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { disposablePromiseTimerResult, timerResource };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const PING_SYM: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields {@link PING_SYM}
|
|
4
|
+
* whenever no value has been yielded for {@link pingIntervalMs}.
|
|
5
|
+
*/
|
|
6
|
+
export declare function withPing<TValue>(iterable: AsyncIterable<TValue>, pingIntervalMs: number): AsyncGenerator<TValue | typeof PING_SYM>;
|
|
7
|
+
//# sourceMappingURL=withPing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withPing.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/withPing.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,eAAiB,CAAC;AAEvC;;;GAGG;AACH,wBAAuB,QAAQ,CAAC,MAAM,EACpC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,EAC/B,cAAc,EAAE,MAAM,GACrB,cAAc,CAAC,MAAM,GAAG,OAAO,QAAQ,CAAC,CAiC1C"}
|