@trpc/server 11.0.0-rc.621 → 11.0.0-rc.632
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/adapters/aws-lambda/getPlanner.js +2 -2
- package/dist/adapters/aws-lambda/getPlanner.mjs +2 -2
- package/dist/adapters/aws-lambda/index.js +2 -0
- package/dist/adapters/aws-lambda/index.mjs +2 -0
- package/dist/adapters/express.js +2 -0
- package/dist/adapters/express.mjs +2 -0
- package/dist/adapters/fastify/fastifyRequestHandler.js +3 -1
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +3 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +8 -6
- package/dist/adapters/fetch/fetchRequestHandler.mjs +8 -6
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +6 -4
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +6 -4
- 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 +4 -1
- package/dist/adapters/next-app-dir/redirect.mjs +4 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.js +1 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +1 -1
- package/dist/adapters/next.js +2 -0
- package/dist/adapters/next.mjs +2 -0
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +8 -5
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +8 -5
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +11 -43
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +11 -43
- 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 +85 -0
- package/dist/adapters/node-http/writeResponse.mjs +82 -0
- package/dist/adapters/standalone.js +2 -0
- package/dist/adapters/standalone.mjs +2 -0
- package/dist/adapters/ws.js +11 -10
- package/dist/adapters/ws.mjs +11 -10
- package/dist/bundle-analysis.json +230 -186
- package/dist/http.js +2 -2
- package/dist/http.mjs +2 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js +11 -0
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs +9 -0
- package/dist/observable/observable.js +1 -1
- package/dist/observable/observable.mjs +1 -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/createProxy.js +1 -1
- package/dist/unstable-core-do-not-import/createProxy.mjs +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.js +4 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +4 -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/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.js +24 -24
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +24 -24
- package/dist/unstable-core-do-not-import/middleware.js +1 -1
- package/dist/unstable-core-do-not-import/middleware.mjs +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -1
- package/dist/unstable-core-do-not-import/router.js +2 -2
- package/dist/unstable-core-do-not-import/router.mjs +2 -2
- 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 +6 -9
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.js +86 -136
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +87 -137
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +27 -23
- package/dist/unstable-core-do-not-import/stream/sse.mjs +28 -24
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +10 -10
- 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 +47 -34
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +47 -34
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts +0 -4
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.js +0 -11
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.mjs +1 -11
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts +6 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js +28 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs +25 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/withPing.js +17 -17
- package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +17 -17
- package/dist/unstable-core-do-not-import/stream/utils/withRefCount.d.ts +17 -0
- package/dist/unstable-core-do-not-import/stream/utils/withRefCount.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/withRefCount.js +59 -0
- package/dist/unstable-core-do-not-import/stream/utils/withRefCount.mjs +57 -0
- package/dist/unstable-core-do-not-import.d.ts +2 -2
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +2 -2
- package/dist/unstable-core-do-not-import.mjs +1 -1
- package/dist/vendor/unpromise/unpromise.js +21 -16
- package/dist/vendor/unpromise/unpromise.mjs +21 -16
- package/package.json +12 -5
- package/src/@trpc/server/http.ts +0 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
- package/src/adapters/node-http/incomingMessageToRequest.ts +8 -4
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +8 -46
- package/src/adapters/node-http/writeResponse.ts +96 -0
- package/src/unstable-core-do-not-import/http/isAbortError.ts +7 -0
- package/src/unstable-core-do-not-import/stream/jsonl.ts +85 -154
- package/src/unstable-core-do-not-import/stream/sse.ts +24 -25
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +58 -37
- package/src/unstable-core-do-not-import/stream/utils/createReadableStream.ts +0 -13
- package/src/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.ts +27 -0
- package/src/unstable-core-do-not-import/stream/utils/withPing.ts +31 -19
- package/src/unstable-core-do-not-import/stream/utils/withRefCount.ts +93 -0
- package/src/unstable-core-do-not-import.ts +2 -2
- 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/stream/utils/promiseTimer.d.ts +0 -8
- package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.js +0 -38
- package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.mjs +0 -36
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
- package/src/unstable-core-do-not-import/stream/utils/promiseTimer.ts +0 -40
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Derives a new {@link AsyncGenerator} based
|
|
3
|
-
* passed {@link cancel} promise.
|
|
2
|
+
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
4
3
|
*/
|
|
5
|
-
export declare function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
onCancel: () => void;
|
|
10
|
-
}
|
|
4
|
+
export declare function withMaxDuration<T>(iterable: AsyncIterable<T>, opts: {
|
|
5
|
+
maxDurationMs: number;
|
|
6
|
+
abortCtrl: AbortController;
|
|
7
|
+
}): AsyncGenerator<T>;
|
|
11
8
|
/**
|
|
12
9
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
13
10
|
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
14
11
|
* values may still come through. After this period, the generator stops.
|
|
15
12
|
*/
|
|
16
|
-
export declare function takeWithGrace<T>(iterable: AsyncIterable<T>,
|
|
17
|
-
|
|
13
|
+
export declare function takeWithGrace<T>(iterable: AsyncIterable<T>, opts: {
|
|
14
|
+
count: number;
|
|
15
|
+
gracePeriodMs: number;
|
|
16
|
+
abortCtrl: AbortController;
|
|
17
|
+
}): AsyncGenerator<T>;
|
|
18
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":"
|
|
1
|
+
{"version":3,"file":"asyncIterable.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/asyncIterable.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAuB,eAAe,CAAC,CAAC,EACtC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,IAAI,EAAE;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,eAAe,CAAA;CAAE,GAC1D,cAAc,CAAC,CAAC,CAAC,CA8BnB;AAED;;;;GAIG;AACH,wBAAuB,aAAa,CAAC,CAAC,EACpC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,IAAI,EAAE;IACJ,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,eAAe,CAAC;CAC5B,GACA,cAAc,CAAC,CAAC,CAAC,CAoCnB"}
|
|
@@ -1,68 +1,81 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var unpromise = require('../../../vendor/unpromise/unpromise.js');
|
|
4
|
-
var
|
|
5
|
-
var promiseTimer = require('./promiseTimer.js');
|
|
4
|
+
var disposablePromiseTimer = require('./disposablePromiseTimer.js');
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
|
-
* Derives a new {@link AsyncGenerator} based
|
|
9
|
-
*
|
|
10
|
-
*/ async function* withCancel(iterable, cancel) {
|
|
11
|
-
const cancelPromise = cancel.then(utils.noop);
|
|
7
|
+
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
8
|
+
*/ async function* withMaxDuration(iterable, opts) {
|
|
12
9
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
const timer = disposablePromiseTimer.disposablePromiseTimer(opts.maxDurationMs);
|
|
11
|
+
try {
|
|
12
|
+
const timerPromise = timer.start();
|
|
13
|
+
// declaration outside the loop for garbage collection reasons
|
|
14
|
+
let result;
|
|
15
|
+
while(true){
|
|
16
|
+
result = await unpromise.Unpromise.race([
|
|
17
|
+
iterator.next(),
|
|
18
|
+
timerPromise
|
|
19
|
+
]);
|
|
20
|
+
if (result === disposablePromiseTimer.disposablePromiseTimerResult) {
|
|
21
|
+
// cancelled due to timeout
|
|
22
|
+
opts.abortCtrl.abort();
|
|
23
|
+
const res = await iterator.return?.();
|
|
24
|
+
return res?.value;
|
|
25
|
+
}
|
|
26
|
+
if (result.done) {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
yield result.value;
|
|
30
|
+
// free up reference for garbage collection
|
|
31
|
+
result = null;
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
33
|
+
} finally{
|
|
34
|
+
// dispose timer
|
|
35
|
+
// Shouldn't be needed, but build breaks with `using` keyword
|
|
36
|
+
timer[Symbol.dispose]();
|
|
30
37
|
}
|
|
31
38
|
}
|
|
32
39
|
/**
|
|
33
40
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
34
41
|
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
35
42
|
* values may still come through. After this period, the generator stops.
|
|
36
|
-
*/ async function* takeWithGrace(iterable,
|
|
43
|
+
*/ async function* takeWithGrace(iterable, opts) {
|
|
37
44
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
38
|
-
|
|
45
|
+
// declaration outside the loop for garbage collection reasons
|
|
46
|
+
let result;
|
|
47
|
+
const timer = disposablePromiseTimer.disposablePromiseTimer(opts.gracePeriodMs);
|
|
39
48
|
try {
|
|
40
|
-
|
|
41
|
-
let
|
|
49
|
+
let count = opts.count;
|
|
50
|
+
let timerPromise = new Promise(()=>{
|
|
51
|
+
// never resolves
|
|
52
|
+
});
|
|
42
53
|
while(true){
|
|
43
54
|
result = await unpromise.Unpromise.race([
|
|
44
55
|
iterator.next(),
|
|
45
|
-
|
|
56
|
+
timerPromise
|
|
46
57
|
]);
|
|
47
|
-
if (result
|
|
58
|
+
if (result === disposablePromiseTimer.disposablePromiseTimerResult) {
|
|
48
59
|
// cancelled
|
|
49
|
-
await iterator.return?.();
|
|
50
|
-
|
|
60
|
+
const res = await iterator.return?.();
|
|
61
|
+
return res?.value;
|
|
51
62
|
}
|
|
52
63
|
if (result.done) {
|
|
53
|
-
|
|
64
|
+
return result.value;
|
|
54
65
|
}
|
|
55
66
|
yield result.value;
|
|
56
67
|
if (--count === 0) {
|
|
57
|
-
timer.start()
|
|
68
|
+
timerPromise = timer.start();
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
70
|
+
timerPromise.then(()=>opts.abortCtrl.abort());
|
|
58
71
|
}
|
|
59
72
|
// free up reference for garbage collection
|
|
60
73
|
result = null;
|
|
61
74
|
}
|
|
62
75
|
} finally{
|
|
63
|
-
timer.
|
|
76
|
+
timer[Symbol.dispose]();
|
|
64
77
|
}
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
exports.takeWithGrace = takeWithGrace;
|
|
68
|
-
exports.
|
|
81
|
+
exports.withMaxDuration = withMaxDuration;
|
|
@@ -1,65 +1,78 @@
|
|
|
1
1
|
import { Unpromise } from '../../../vendor/unpromise/unpromise.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import { createPromiseTimer } from './promiseTimer.mjs';
|
|
2
|
+
import { disposablePromiseTimerResult, disposablePromiseTimer } from './disposablePromiseTimer.mjs';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
* Derives a new {@link AsyncGenerator} based
|
|
7
|
-
*
|
|
8
|
-
*/ async function* withCancel(iterable, cancel) {
|
|
9
|
-
const cancelPromise = cancel.then(noop);
|
|
5
|
+
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
6
|
+
*/ async function* withMaxDuration(iterable, opts) {
|
|
10
7
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
const timer = disposablePromiseTimer(opts.maxDurationMs);
|
|
9
|
+
try {
|
|
10
|
+
const timerPromise = timer.start();
|
|
11
|
+
// declaration outside the loop for garbage collection reasons
|
|
12
|
+
let result;
|
|
13
|
+
while(true){
|
|
14
|
+
result = await Unpromise.race([
|
|
15
|
+
iterator.next(),
|
|
16
|
+
timerPromise
|
|
17
|
+
]);
|
|
18
|
+
if (result === disposablePromiseTimerResult) {
|
|
19
|
+
// cancelled due to timeout
|
|
20
|
+
opts.abortCtrl.abort();
|
|
21
|
+
const res = await iterator.return?.();
|
|
22
|
+
return res?.value;
|
|
23
|
+
}
|
|
24
|
+
if (result.done) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
yield result.value;
|
|
28
|
+
// free up reference for garbage collection
|
|
29
|
+
result = null;
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
|
|
31
|
+
} finally{
|
|
32
|
+
// dispose timer
|
|
33
|
+
// Shouldn't be needed, but build breaks with `using` keyword
|
|
34
|
+
timer[Symbol.dispose]();
|
|
28
35
|
}
|
|
29
36
|
}
|
|
30
37
|
/**
|
|
31
38
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
32
39
|
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
33
40
|
* values may still come through. After this period, the generator stops.
|
|
34
|
-
*/ async function* takeWithGrace(iterable,
|
|
41
|
+
*/ async function* takeWithGrace(iterable, opts) {
|
|
35
42
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
36
|
-
|
|
43
|
+
// declaration outside the loop for garbage collection reasons
|
|
44
|
+
let result;
|
|
45
|
+
const timer = disposablePromiseTimer(opts.gracePeriodMs);
|
|
37
46
|
try {
|
|
38
|
-
|
|
39
|
-
let
|
|
47
|
+
let count = opts.count;
|
|
48
|
+
let timerPromise = new Promise(()=>{
|
|
49
|
+
// never resolves
|
|
50
|
+
});
|
|
40
51
|
while(true){
|
|
41
52
|
result = await Unpromise.race([
|
|
42
53
|
iterator.next(),
|
|
43
|
-
|
|
54
|
+
timerPromise
|
|
44
55
|
]);
|
|
45
|
-
if (result
|
|
56
|
+
if (result === disposablePromiseTimerResult) {
|
|
46
57
|
// cancelled
|
|
47
|
-
await iterator.return?.();
|
|
48
|
-
|
|
58
|
+
const res = await iterator.return?.();
|
|
59
|
+
return res?.value;
|
|
49
60
|
}
|
|
50
61
|
if (result.done) {
|
|
51
|
-
|
|
62
|
+
return result.value;
|
|
52
63
|
}
|
|
53
64
|
yield result.value;
|
|
54
65
|
if (--count === 0) {
|
|
55
|
-
timer.start()
|
|
66
|
+
timerPromise = timer.start();
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
68
|
+
timerPromise.then(()=>opts.abortCtrl.abort());
|
|
56
69
|
}
|
|
57
70
|
// free up reference for garbage collection
|
|
58
71
|
result = null;
|
|
59
72
|
}
|
|
60
73
|
} finally{
|
|
61
|
-
timer.
|
|
74
|
+
timer[Symbol.dispose]();
|
|
62
75
|
}
|
|
63
76
|
}
|
|
64
77
|
|
|
65
|
-
export { takeWithGrace,
|
|
78
|
+
export { takeWithGrace, withMaxDuration };
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
declare const cancelledStreamSymbol: unique symbol;
|
|
2
1
|
/**
|
|
3
2
|
* One-off readable stream
|
|
4
3
|
*/
|
|
5
4
|
export declare function createReadableStream<TValue = unknown>(): {
|
|
6
5
|
readonly readable: ReadableStream<TValue>;
|
|
7
6
|
readonly controller: ReadableStreamDefaultController<TValue>;
|
|
8
|
-
readonly cancelledPromise: Promise<typeof cancelledStreamSymbol>;
|
|
9
7
|
readonly cancelled: () => boolean;
|
|
10
8
|
};
|
|
11
|
-
export declare function isCancelledStreamResult(v: unknown): v is typeof cancelledStreamSymbol;
|
|
12
|
-
export {};
|
|
13
9
|
//# sourceMappingURL=createReadableStream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReadableStream.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/createReadableStream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createReadableStream.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/createReadableStream.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,GAAG,OAAO;;;;EAqBpD"}
|
|
@@ -1,36 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createDeferred = require('./createDeferred.js');
|
|
4
|
-
|
|
5
|
-
// ---------- utils
|
|
6
|
-
const cancelledStreamSymbol = Symbol();
|
|
7
3
|
/**
|
|
8
4
|
* One-off readable stream
|
|
9
5
|
*/ function createReadableStream() {
|
|
10
6
|
let controller = null;
|
|
11
|
-
const deferred = createDeferred.createDeferred();
|
|
12
7
|
let cancelled = false;
|
|
13
8
|
const readable = new ReadableStream({
|
|
14
9
|
start (c) {
|
|
15
10
|
controller = c;
|
|
16
11
|
},
|
|
17
12
|
cancel () {
|
|
18
|
-
deferred.resolve(cancelledStreamSymbol);
|
|
19
13
|
cancelled = true;
|
|
20
14
|
}
|
|
21
15
|
});
|
|
22
16
|
return {
|
|
23
17
|
readable,
|
|
24
18
|
controller,
|
|
25
|
-
cancelledPromise: deferred.promise,
|
|
26
19
|
cancelled () {
|
|
27
20
|
return cancelled;
|
|
28
21
|
}
|
|
29
22
|
};
|
|
30
23
|
}
|
|
31
|
-
function isCancelledStreamResult(v) {
|
|
32
|
-
return v === cancelledStreamSymbol;
|
|
33
|
-
}
|
|
34
24
|
|
|
35
25
|
exports.createReadableStream = createReadableStream;
|
|
36
|
-
exports.isCancelledStreamResult = isCancelledStreamResult;
|
|
@@ -1,33 +1,23 @@
|
|
|
1
|
-
import { createDeferred } from './createDeferred.mjs';
|
|
2
|
-
|
|
3
|
-
// ---------- utils
|
|
4
|
-
const cancelledStreamSymbol = Symbol();
|
|
5
1
|
/**
|
|
6
2
|
* One-off readable stream
|
|
7
3
|
*/ function createReadableStream() {
|
|
8
4
|
let controller = null;
|
|
9
|
-
const deferred = createDeferred();
|
|
10
5
|
let cancelled = false;
|
|
11
6
|
const readable = new ReadableStream({
|
|
12
7
|
start (c) {
|
|
13
8
|
controller = c;
|
|
14
9
|
},
|
|
15
10
|
cancel () {
|
|
16
|
-
deferred.resolve(cancelledStreamSymbol);
|
|
17
11
|
cancelled = true;
|
|
18
12
|
}
|
|
19
13
|
});
|
|
20
14
|
return {
|
|
21
15
|
readable,
|
|
22
16
|
controller,
|
|
23
|
-
cancelledPromise: deferred.promise,
|
|
24
17
|
cancelled () {
|
|
25
18
|
return cancelled;
|
|
26
19
|
}
|
|
27
20
|
};
|
|
28
21
|
}
|
|
29
|
-
function isCancelledStreamResult(v) {
|
|
30
|
-
return v === cancelledStreamSymbol;
|
|
31
|
-
}
|
|
32
22
|
|
|
33
|
-
export { createReadableStream
|
|
23
|
+
export { createReadableStream };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const disposablePromiseTimerResult: unique symbol;
|
|
2
|
+
export declare function disposablePromiseTimer(ms: number): {
|
|
3
|
+
start(): Promise<typeof disposablePromiseTimerResult>;
|
|
4
|
+
[Symbol.dispose]: () => void;
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=disposablePromiseTimer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disposablePromiseTimer.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,4BAA4B,eAAW,CAAC;AACrD,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM;;;EAsBhD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// @ts-expect-error polyfill
|
|
4
|
+
var _Symbol;
|
|
5
|
+
(_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol());
|
|
6
|
+
const disposablePromiseTimerResult = Symbol();
|
|
7
|
+
function disposablePromiseTimer(ms) {
|
|
8
|
+
let timer = null;
|
|
9
|
+
return {
|
|
10
|
+
start () {
|
|
11
|
+
if (timer) {
|
|
12
|
+
throw new Error('Timer already started');
|
|
13
|
+
}
|
|
14
|
+
const promise = new Promise((resolve)=>{
|
|
15
|
+
timer = setTimeout(()=>resolve(disposablePromiseTimerResult), ms);
|
|
16
|
+
});
|
|
17
|
+
return promise;
|
|
18
|
+
},
|
|
19
|
+
[Symbol.dispose]: ()=>{
|
|
20
|
+
if (timer) {
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.disposablePromiseTimer = disposablePromiseTimer;
|
|
28
|
+
exports.disposablePromiseTimerResult = disposablePromiseTimerResult;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @ts-expect-error polyfill
|
|
2
|
+
var _Symbol;
|
|
3
|
+
(_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol());
|
|
4
|
+
const disposablePromiseTimerResult = Symbol();
|
|
5
|
+
function disposablePromiseTimer(ms) {
|
|
6
|
+
let timer = null;
|
|
7
|
+
return {
|
|
8
|
+
start () {
|
|
9
|
+
if (timer) {
|
|
10
|
+
throw new Error('Timer already started');
|
|
11
|
+
}
|
|
12
|
+
const promise = new Promise((resolve)=>{
|
|
13
|
+
timer = setTimeout(()=>resolve(disposablePromiseTimerResult), ms);
|
|
14
|
+
});
|
|
15
|
+
return promise;
|
|
16
|
+
},
|
|
17
|
+
[Symbol.dispose]: ()=>{
|
|
18
|
+
if (timer) {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { disposablePromiseTimer, disposablePromiseTimerResult };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withPing.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/withPing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withPing.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/withPing.ts"],"names":[],"mappings":"AAMA,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,CAmC1C"}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var unpromise = require('../../../vendor/unpromise/unpromise.js');
|
|
4
|
-
var
|
|
4
|
+
var disposablePromiseTimer = require('./disposablePromiseTimer.js');
|
|
5
5
|
|
|
6
6
|
const PING_SYM = Symbol('ping');
|
|
7
|
-
const PING_RESULT = {
|
|
8
|
-
value: PING_SYM,
|
|
9
|
-
done: false
|
|
10
|
-
};
|
|
11
7
|
/**
|
|
12
8
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields {@link PING_SYM}
|
|
13
9
|
* whenever no value has been yielded for {@link pingIntervalMs}.
|
|
14
10
|
*/ async function* withPing(iterable, pingIntervalMs) {
|
|
15
|
-
const timer = promiseTimer.createPromiseTimer(pingIntervalMs);
|
|
16
11
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
17
12
|
// declaration outside the loop for garbage collection reasons
|
|
18
13
|
let result;
|
|
14
|
+
let nextPromise = iterator.next();
|
|
19
15
|
while(true){
|
|
20
|
-
const
|
|
21
|
-
const pingPromise = timer.start().promise.then(()=>PING_RESULT);
|
|
16
|
+
const pingPromise = disposablePromiseTimer.disposablePromiseTimer(pingIntervalMs);
|
|
22
17
|
try {
|
|
23
18
|
result = await unpromise.Unpromise.race([
|
|
24
19
|
nextPromise,
|
|
25
|
-
pingPromise
|
|
20
|
+
pingPromise.start()
|
|
26
21
|
]);
|
|
22
|
+
if (result === disposablePromiseTimer.disposablePromiseTimerResult) {
|
|
23
|
+
// cancelled
|
|
24
|
+
yield PING_SYM;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (result.done) {
|
|
28
|
+
return result.value;
|
|
29
|
+
}
|
|
30
|
+
nextPromise = iterator.next();
|
|
31
|
+
yield result.value;
|
|
32
|
+
// free up reference for garbage collection
|
|
33
|
+
result = null;
|
|
27
34
|
} finally{
|
|
28
|
-
|
|
35
|
+
pingPromise[Symbol.dispose]();
|
|
29
36
|
}
|
|
30
|
-
if (result.done) {
|
|
31
|
-
return result.value;
|
|
32
|
-
}
|
|
33
|
-
yield result.value;
|
|
34
|
-
timer.reset();
|
|
35
|
-
// free up reference for garbage collection
|
|
36
|
-
result = null;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import { Unpromise } from '../../../vendor/unpromise/unpromise.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { disposablePromiseTimerResult, disposablePromiseTimer } from './disposablePromiseTimer.mjs';
|
|
3
3
|
|
|
4
4
|
const PING_SYM = Symbol('ping');
|
|
5
|
-
const PING_RESULT = {
|
|
6
|
-
value: PING_SYM,
|
|
7
|
-
done: false
|
|
8
|
-
};
|
|
9
5
|
/**
|
|
10
6
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields {@link PING_SYM}
|
|
11
7
|
* whenever no value has been yielded for {@link pingIntervalMs}.
|
|
12
8
|
*/ async function* withPing(iterable, pingIntervalMs) {
|
|
13
|
-
const timer = createPromiseTimer(pingIntervalMs);
|
|
14
9
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
15
10
|
// declaration outside the loop for garbage collection reasons
|
|
16
11
|
let result;
|
|
12
|
+
let nextPromise = iterator.next();
|
|
17
13
|
while(true){
|
|
18
|
-
const
|
|
19
|
-
const pingPromise = timer.start().promise.then(()=>PING_RESULT);
|
|
14
|
+
const pingPromise = disposablePromiseTimer(pingIntervalMs);
|
|
20
15
|
try {
|
|
21
16
|
result = await Unpromise.race([
|
|
22
17
|
nextPromise,
|
|
23
|
-
pingPromise
|
|
18
|
+
pingPromise.start()
|
|
24
19
|
]);
|
|
20
|
+
if (result === disposablePromiseTimerResult) {
|
|
21
|
+
// cancelled
|
|
22
|
+
yield PING_SYM;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (result.done) {
|
|
26
|
+
return result.value;
|
|
27
|
+
}
|
|
28
|
+
nextPromise = iterator.next();
|
|
29
|
+
yield result.value;
|
|
30
|
+
// free up reference for garbage collection
|
|
31
|
+
result = null;
|
|
25
32
|
} finally{
|
|
26
|
-
|
|
33
|
+
pingPromise[Symbol.dispose]();
|
|
27
34
|
}
|
|
28
|
-
if (result.done) {
|
|
29
|
-
return result.value;
|
|
30
|
-
}
|
|
31
|
-
yield result.value;
|
|
32
|
-
timer.reset();
|
|
33
|
-
// free up reference for garbage collection
|
|
34
|
-
result = null;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type OnDrain = () => void;
|
|
2
|
+
export interface RefCount {
|
|
3
|
+
activate(): void;
|
|
4
|
+
}
|
|
5
|
+
export interface RefCountMap<TKey, TValue> extends Map<TKey, TValue>, RefCount {
|
|
6
|
+
}
|
|
7
|
+
export interface RefCountSet<TValue> extends Set<TValue>, RefCount {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Adds reference counting capabilities to a Map or Set collection.
|
|
11
|
+
* The collection can be activated, after which it will trigger a drain callback when emptied.
|
|
12
|
+
* Once drained, the collection cannot be modified further.
|
|
13
|
+
*/
|
|
14
|
+
export declare function withRefCount<TKey, TValue>(map: Map<TKey, TValue>, onDrain: OnDrain): RefCountMap<TKey, TValue>;
|
|
15
|
+
export declare function withRefCount<TValue>(set: Set<TValue>, onDrain: OnDrain): RefCountSet<TValue>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=withRefCount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withRefCount.d.ts","sourceRoot":"","sources":["../../../../src/unstable-core-do-not-import/stream/utils/withRefCount.ts"],"names":[],"mappings":"AACA,KAAK,OAAO,GAAG,MAAM,IAAI,CAAC;AAG1B,MAAM,WAAW,QAAQ;IACvB,QAAQ,IAAI,IAAI,CAAC;CAClB;AAGD,MAAM,WAAW,WAAW,CAAC,IAAI,EAAE,MAAM,CACvC,SAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,EACvB,QAAQ;CAAG;AAGf,MAAM,WAAW,WAAW,CAAC,MAAM,CAAE,SAAQ,GAAG,CAAC,MAAM,CAAC,EAAE,QAAQ;CAAG;AAErE;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EACvC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,EACtB,OAAO,EAAE,OAAO,GACf,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC7B,wBAAgB,YAAY,CAAC,MAAM,EACjC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,EAChB,OAAO,EAAE,OAAO,GACf,WAAW,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Callback function type that is called when a collection is drained
|
|
4
|
+
function withRefCount(_obj, onDrain) {
|
|
5
|
+
const obj = _obj;
|
|
6
|
+
// Track whether the collection has been drained
|
|
7
|
+
let drained = false;
|
|
8
|
+
// Track whether the collection has been activated
|
|
9
|
+
let active = false;
|
|
10
|
+
// Check if collection should be drained (empty and active)
|
|
11
|
+
const checkDrain = ()=>{
|
|
12
|
+
if (!drained && active && obj.size === 0) {
|
|
13
|
+
onDrain();
|
|
14
|
+
drained = true;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
// Create proxy to intercept collection operations
|
|
18
|
+
return new Proxy(obj, {
|
|
19
|
+
get (_, prop) {
|
|
20
|
+
// Handle activation
|
|
21
|
+
if (prop === 'activate') {
|
|
22
|
+
return ()=>{
|
|
23
|
+
active = true;
|
|
24
|
+
checkDrain();
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// Handle adding items - prevent if already drained
|
|
28
|
+
if (prop === 'set' || prop === 'add') {
|
|
29
|
+
return (...args)=>{
|
|
30
|
+
if (drained) {
|
|
31
|
+
throw new Error('Already drained');
|
|
32
|
+
}
|
|
33
|
+
return obj[prop](...args);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Handle removing items - check if should drain after
|
|
37
|
+
if (prop === 'delete' || prop === 'clear') {
|
|
38
|
+
return (...args)=>{
|
|
39
|
+
try {
|
|
40
|
+
return obj[prop](...args);
|
|
41
|
+
} finally{
|
|
42
|
+
checkDrain();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Pass through other method calls
|
|
47
|
+
const target = obj[prop];
|
|
48
|
+
if (typeof target === 'function') {
|
|
49
|
+
return (...args)=>{
|
|
50
|
+
return obj[prop](...args);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Pass through property access
|
|
54
|
+
return target;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exports.withRefCount = withRefCount;
|