@orpc/shared 2.0.0-beta.49 → 2.0.0-beta.50
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/args.d.ts +1 -1
- package/dist/args.js +4 -2
- package/dist/array.d.ts +4 -1
- package/dist/array.js +11 -5
- package/dist/bigint.d.ts +1 -1
- package/dist/bigint.js +12 -16
- package/dist/buffer.d.ts +4 -4
- package/dist/buffer.js +44 -67
- package/dist/compare.d.ts +1 -1
- package/dist/compare.js +23 -42
- package/dist/consts.d.ts +1 -1
- package/dist/consts.js +3 -1
- package/dist/error.d.ts +1 -1
- package/dist/error.js +4 -2
- package/dist/function.d.ts +1 -1
- package/dist/function.js +27 -32
- package/dist/http.d.ts +29 -0
- package/dist/http.js +128 -94
- package/dist/id.d.ts +1 -1
- package/dist/id.js +11 -11
- package/dist/index.d.ts +26 -34
- package/dist/index.js +23 -32
- package/dist/interceptor.d.ts +17 -17
- package/dist/interceptor.js +106 -126
- package/dist/iterator.d.ts +41 -41
- package/dist/iterator.js +136 -152
- package/dist/object.d.ts +10 -8
- package/dist/object.js +176 -227
- package/dist/plugin.d.ts +7 -7
- package/dist/plugin.js +41 -57
- package/dist/promise.d.ts +4 -4
- package/dist/promise.js +28 -28
- package/dist/proxy.d.ts +2 -2
- package/dist/proxy.js +23 -22
- package/dist/queue.d.ts +13 -13
- package/dist/queue.js +64 -79
- package/dist/regex.d.ts +9 -0
- package/dist/regex.js +11 -0
- package/dist/signal.d.ts +7 -2
- package/dist/signal.js +83 -80
- package/dist/stream.d.ts +23 -23
- package/dist/stream.js +118 -144
- package/dist/tracing.d.ts +50 -50
- package/dist/tracing.js +60 -85
- package/dist/types.d.ts +7 -10
- package/dist/value.d.ts +1 -1
- package/dist/value.js +5 -5
- package/package.json +2 -2
- package/dist/types.js +0 -1
package/dist/promise.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
+
// src/promise.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
* Creates a promise together with its associated `resolve` and `reject`
|
|
4
|
+
* functions.
|
|
5
|
+
*
|
|
6
|
+
* Equivalent to `Promise.withResolvers()`, but works in environments
|
|
7
|
+
* where that API is not yet available.
|
|
8
|
+
*/
|
|
9
|
+
function promiseWithResolvers() {
|
|
10
|
+
const result = {};
|
|
11
|
+
result.promise = new Promise((resolve, reject) => {
|
|
12
|
+
result.resolve = resolve;
|
|
13
|
+
result.reject = reject;
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return result;
|
|
31
|
-
};
|
|
18
|
+
* Captures the current async context (such as AsyncLocalStorage) through a promise reaction, so no runtime API is needed.
|
|
19
|
+
* The returned function runs a callback inside it once; later calls reject.
|
|
20
|
+
*/
|
|
21
|
+
function captureAsyncContext() {
|
|
22
|
+
const { promise, resolve } = promiseWithResolvers();
|
|
23
|
+
const result = promise.then((callback) => callback());
|
|
24
|
+
let called = false;
|
|
25
|
+
return (callback) => {
|
|
26
|
+
if (called) return Promise.reject(/* @__PURE__ */ new Error("A captured async context can be run only once."));
|
|
27
|
+
called = true;
|
|
28
|
+
resolve(callback);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
32
31
|
}
|
|
32
|
+
export { captureAsyncContext, promiseWithResolvers };
|
package/dist/proxy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Value } from "./value.js";
|
|
2
2
|
/**
|
|
3
3
|
* Creates a proxy that overlays a `partial` object on top of a `target`.
|
|
4
4
|
*
|
|
@@ -9,4 +9,4 @@ import type { Value } from './value.ts';
|
|
|
9
9
|
* Useful for overriding specific properties of an object while delegating
|
|
10
10
|
* all other access to the original target without needing to know its full structure.
|
|
11
11
|
*/
|
|
12
|
-
export declare function override<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
|
|
12
|
+
export declare function override<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
|
package/dist/proxy.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { value } from "./value.js";
|
|
2
|
+
import { getOrBind } from "@standard-server/shared";
|
|
3
|
+
// src/proxy.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return proxy;
|
|
5
|
+
* Creates a proxy that overlays a `partial` object on top of a `target`.
|
|
6
|
+
*
|
|
7
|
+
* - Properties from `partial` take precedence.
|
|
8
|
+
* - Properties not present in `partial` fall back to the resolved `target`.
|
|
9
|
+
* - Methods are bound to the proxy to ensure a consistent `this` context.
|
|
10
|
+
*
|
|
11
|
+
* Useful for overriding specific properties of an object while delegating
|
|
12
|
+
* all other access to the original target without needing to know its full structure.
|
|
13
|
+
*/
|
|
14
|
+
function override(target, partial) {
|
|
15
|
+
return new Proxy(typeof target === "function" ? partial : target, {
|
|
16
|
+
get(_, prop) {
|
|
17
|
+
const targetValue = prop in partial ? partial : value(target);
|
|
18
|
+
return getOrBind(targetValue, prop);
|
|
19
|
+
},
|
|
20
|
+
has(_, prop) {
|
|
21
|
+
return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
24
|
}
|
|
25
|
+
export { override };
|
package/dist/queue.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export interface AsyncIdQueueCloseOptions {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
id?: string | undefined;
|
|
3
|
+
reason?: unknown;
|
|
4
4
|
}
|
|
5
5
|
export declare class AsyncIdQueue<T> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
6
|
+
private readonly openIds;
|
|
7
|
+
private readonly queues;
|
|
8
|
+
private readonly waiters;
|
|
9
|
+
get size(): number;
|
|
10
|
+
open(id: string): void;
|
|
11
|
+
isOpen(id: string): boolean;
|
|
12
|
+
push(id: string, item: T): void;
|
|
13
|
+
pull(id: string): Promise<T>;
|
|
14
|
+
close({ id, reason }?: AsyncIdQueueCloseOptions): void;
|
|
15
|
+
private assertOpen;
|
|
16
|
+
}
|
package/dist/queue.js
CHANGED
|
@@ -1,79 +1,64 @@
|
|
|
1
|
-
import { AbortError } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const error = reason ??
|
|
68
|
-
new AbortError(`[AsyncIdQueue] Queue[${id}] was closed or aborted while waiting for pulling.`);
|
|
69
|
-
this.waiters.get(id)?.forEach(([, reject]) => reject(error));
|
|
70
|
-
this.waiters.delete(id);
|
|
71
|
-
this.openIds.delete(id);
|
|
72
|
-
this.queues.delete(id);
|
|
73
|
-
}
|
|
74
|
-
assertOpen(id) {
|
|
75
|
-
if (!this.isOpen(id)) {
|
|
76
|
-
throw new Error(`[AsyncIdQueue] Cannot access queue[${id}] because it is not open or aborted.`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
1
|
+
import { AbortError } from "@standard-server/shared";
|
|
2
|
+
// src/queue.ts
|
|
3
|
+
var AsyncIdQueue = class {
|
|
4
|
+
openIds = /* @__PURE__ */ new Set();
|
|
5
|
+
queues = /* @__PURE__ */ new Map();
|
|
6
|
+
waiters = /* @__PURE__ */ new Map();
|
|
7
|
+
get size() {
|
|
8
|
+
return this.openIds.size;
|
|
9
|
+
}
|
|
10
|
+
open(id) {
|
|
11
|
+
this.openIds.add(id);
|
|
12
|
+
}
|
|
13
|
+
isOpen(id) {
|
|
14
|
+
return this.openIds.has(id);
|
|
15
|
+
}
|
|
16
|
+
push(id, item) {
|
|
17
|
+
this.assertOpen(id);
|
|
18
|
+
const pending = this.waiters.get(id);
|
|
19
|
+
if (pending?.length) {
|
|
20
|
+
pending.shift()[0](item);
|
|
21
|
+
if (pending.length === 0) this.waiters.delete(id);
|
|
22
|
+
} else {
|
|
23
|
+
const items = this.queues.get(id);
|
|
24
|
+
if (items) items.push(item);
|
|
25
|
+
else this.queues.set(id, [item]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async pull(id) {
|
|
29
|
+
this.assertOpen(id);
|
|
30
|
+
const items = this.queues.get(id);
|
|
31
|
+
if (items?.length) {
|
|
32
|
+
const item = items.shift();
|
|
33
|
+
if (items.length === 0) this.queues.delete(id);
|
|
34
|
+
return item;
|
|
35
|
+
}
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const waitingPulls = this.waiters.get(id);
|
|
38
|
+
const pending = [resolve, reject];
|
|
39
|
+
if (waitingPulls) waitingPulls.push(pending);
|
|
40
|
+
else this.waiters.set(id, [pending]);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
close({ id, reason } = {}) {
|
|
44
|
+
if (id === void 0) {
|
|
45
|
+
this.waiters.forEach((pendingPulls, id) => {
|
|
46
|
+
const error = reason ?? new AbortError(`[AsyncIdQueue] Queue[${id}] was closed or aborted while waiting for pulling.`);
|
|
47
|
+
pendingPulls.forEach(([, reject]) => reject(error));
|
|
48
|
+
});
|
|
49
|
+
this.waiters.clear();
|
|
50
|
+
this.openIds.clear();
|
|
51
|
+
this.queues.clear();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const error = reason ?? new AbortError(`[AsyncIdQueue] Queue[${id}] was closed or aborted while waiting for pulling.`);
|
|
55
|
+
this.waiters.get(id)?.forEach(([, reject]) => reject(error));
|
|
56
|
+
this.waiters.delete(id);
|
|
57
|
+
this.openIds.delete(id);
|
|
58
|
+
this.queues.delete(id);
|
|
59
|
+
}
|
|
60
|
+
assertOpen(id) {
|
|
61
|
+
if (!this.isOpen(id)) throw new Error(`[AsyncIdQueue] Cannot access queue[${id}] because it is not open or aborted.`);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export { AsyncIdQueue };
|
package/dist/regex.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches an integer string: an optional `-`, then digits without leading zeros (`007` is rejected).
|
|
3
|
+
* Note that `-0` is accepted.
|
|
4
|
+
*/
|
|
5
|
+
export declare const INTEGER_REGEX: RegExp;
|
|
6
|
+
/**
|
|
7
|
+
* Matches a non-negative integer string without leading zeros, such as an array index.
|
|
8
|
+
*/
|
|
9
|
+
export declare const NON_NEGATIVE_INTEGER_REGEX: RegExp;
|
package/dist/regex.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/regex.ts
|
|
2
|
+
/**
|
|
3
|
+
* Matches an integer string: an optional `-`, then digits without leading zeros (`007` is rejected).
|
|
4
|
+
* Note that `-0` is accepted.
|
|
5
|
+
*/
|
|
6
|
+
const INTEGER_REGEX = /^-?(?:0|[1-9]\d*)$/;
|
|
7
|
+
/**
|
|
8
|
+
* Matches a non-negative integer string without leading zeros, such as an array index.
|
|
9
|
+
*/
|
|
10
|
+
const NON_NEGATIVE_INTEGER_REGEX = /^(?:0|[1-9]\d*)$/;
|
|
11
|
+
export { INTEGER_REGEX, NON_NEGATIVE_INTEGER_REGEX };
|
package/dist/signal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface DisposableAllAbortSignal {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
signal: AbortSignal | undefined;
|
|
3
|
+
dispose: () => void;
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* Returns a signal that aborts only after all provided signals are aborted,
|
|
@@ -16,3 +16,8 @@ export declare function disposableAllAbortSignal(signals: readonly (AbortSignal
|
|
|
16
16
|
*/
|
|
17
17
|
export declare function anyAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
|
18
18
|
export declare function runWithSignal<T>(signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Calls `onAbort` with the abort reason once the signal aborts, or synchronously, before returning,
|
|
21
|
+
* if it is already aborted. Does nothing without a signal. Returns a function that removes the listener.
|
|
22
|
+
*/
|
|
23
|
+
export declare function listenAbort(signal: AbortSignal | undefined, onAbort: (reason: unknown) => void): () => void;
|
package/dist/signal.js
CHANGED
|
@@ -1,85 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { promiseWithResolvers } from "./promise.js";
|
|
2
|
+
import { throwIfAborted } from "@standard-server/shared";
|
|
3
|
+
// src/signal.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
* Returns a signal that aborts only after all provided signals are aborted,
|
|
6
|
+
* and a `dispose` function that removes the listeners added to the input signals.
|
|
7
|
+
*/
|
|
8
|
+
function disposableAllAbortSignal(signals) {
|
|
9
|
+
const realSignals = signals.filter((signal) => signal !== void 0);
|
|
10
|
+
if (realSignals.length === 0 || realSignals.length !== signals.length) return {
|
|
11
|
+
signal: void 0,
|
|
12
|
+
dispose: () => {}
|
|
13
|
+
};
|
|
14
|
+
const controller = new AbortController();
|
|
15
|
+
const listenersController = new AbortController();
|
|
16
|
+
const dispose = () => listenersController.abort();
|
|
17
|
+
const abortIfAllAborted = () => {
|
|
18
|
+
if (realSignals.every((signal) => signal.aborted)) {
|
|
19
|
+
controller.abort();
|
|
20
|
+
dispose();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
abortIfAllAborted();
|
|
24
|
+
for (const signal of realSignals) signal.addEventListener("abort", abortIfAllAborted, {
|
|
25
|
+
once: true,
|
|
26
|
+
signal: listenersController.signal
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
signal: controller.signal,
|
|
30
|
+
dispose
|
|
31
|
+
};
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
signal.addEventListener('abort', () => {
|
|
57
|
-
controller.abort(signal.reason);
|
|
58
|
-
}, {
|
|
59
|
-
once: true,
|
|
60
|
-
signal: controller.signal,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return controller.signal;
|
|
34
|
+
* Returns a signal that aborts as soon as any of the provided signals aborts,
|
|
35
|
+
* with the same abort reason.
|
|
36
|
+
*
|
|
37
|
+
* Prefers the native `AbortSignal.any` when available, and falls back to a manual
|
|
38
|
+
* implementation otherwise, including in runtimes without the `AbortSignal` global.
|
|
39
|
+
*/
|
|
40
|
+
function anyAbortSignal(signals) {
|
|
41
|
+
const realSignals = signals.filter((signal) => signal !== void 0);
|
|
42
|
+
if (realSignals.length === 0) return;
|
|
43
|
+
if (realSignals.length === 1) return realSignals[0];
|
|
44
|
+
if (typeof AbortSignal !== "undefined" && typeof AbortSignal.any === "function") return AbortSignal.any(realSignals);
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
for (const signal of realSignals) {
|
|
47
|
+
if (signal.aborted) {
|
|
48
|
+
controller.abort(signal.reason);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
signal.addEventListener("abort", () => {
|
|
52
|
+
controller.abort(signal.reason);
|
|
53
|
+
}, {
|
|
54
|
+
once: true,
|
|
55
|
+
signal: controller.signal
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return controller.signal;
|
|
64
59
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
finally {
|
|
81
|
-
if (abortListener) {
|
|
82
|
-
signal.removeEventListener('abort', abortListener);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
60
|
+
async function runWithSignal(signal, fn) {
|
|
61
|
+
if (!signal) return fn();
|
|
62
|
+
throwIfAborted(signal);
|
|
63
|
+
const { promise, reject, resolve } = promiseWithResolvers();
|
|
64
|
+
let abortListener;
|
|
65
|
+
signal.addEventListener("abort", abortListener = () => {
|
|
66
|
+
reject(signal.reason);
|
|
67
|
+
abortListener = void 0;
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
fn().then(resolve, reject);
|
|
71
|
+
return await promise;
|
|
72
|
+
} finally {
|
|
73
|
+
if (abortListener) signal.removeEventListener("abort", abortListener);
|
|
74
|
+
}
|
|
85
75
|
}
|
|
76
|
+
const noop = () => {};
|
|
77
|
+
/**
|
|
78
|
+
* Calls `onAbort` with the abort reason once the signal aborts, or synchronously, before returning,
|
|
79
|
+
* if it is already aborted. Does nothing without a signal. Returns a function that removes the listener.
|
|
80
|
+
*/
|
|
81
|
+
function listenAbort(signal, onAbort) {
|
|
82
|
+
if (!signal) return noop;
|
|
83
|
+
const listener = () => onAbort(signal.reason);
|
|
84
|
+
if (signal.aborted) listener();
|
|
85
|
+
else signal.addEventListener("abort", listener, { once: true });
|
|
86
|
+
return () => signal.removeEventListener("abort", listener);
|
|
87
|
+
}
|
|
88
|
+
export { anyAbortSignal, disposableAllAbortSignal, listenAbort, runWithSignal };
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { StartSpanOptions } from "./tracing.js";
|
|
2
|
+
import { ThrowableError } from "./types.js";
|
|
3
|
+
import { AsyncIteratorClass } from "@standard-server/shared";
|
|
4
|
+
import { Promisable } from "type-fest";
|
|
5
5
|
export declare function replicateReadableStream<T>(stream: ReadableStream<T>, count: number): ReadableStream<T>[];
|
|
6
6
|
export type ReadableStreamReadResult<T> = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
done: false;
|
|
8
|
+
value: T;
|
|
9
9
|
} | {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
done: true;
|
|
11
|
+
value?: T | undefined;
|
|
12
12
|
};
|
|
13
13
|
export interface WrapReadableStreamOptions<T, TMapped> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Any call to the original stream reader will be executed inside this function.
|
|
16
|
+
* Useful when you want execution to happen within a specific context,
|
|
17
|
+
* such as AsyncLocalStorage.
|
|
18
|
+
*/
|
|
19
|
+
runWith?: (<T>(run: () => Promise<T>) => Promisable<T>) | undefined;
|
|
20
|
+
mapResult?: ((result: ReadableStreamReadResult<T>) => Promisable<ReadableStreamReadResult<TMapped>>) | undefined;
|
|
21
|
+
mapError?: ((error: ThrowableError) => Promisable<ThrowableError>) | undefined;
|
|
22
|
+
onError?: ((error: ThrowableError) => Promisable<void>) | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Guaranteed to execute exactly once after the stream finishes or is cancelled.
|
|
25
|
+
*/
|
|
26
|
+
onFinish?: (() => Promisable<void>) | undefined;
|
|
27
27
|
}
|
|
28
28
|
export declare function wrapReadableStream<T, TMapped = T>(stream: ReadableStream<T>, { runWith, mapResult, mapError, onError, onFinish }: WrapReadableStreamOptions<T, TMapped>): NoInfer<ReadableStream<TMapped>>;
|
|
29
29
|
export declare function traceReadableStream<T>(options: StartSpanOptions | string, stream: ReadableStream<T>): ReadableStream<T>;
|
|
@@ -33,7 +33,7 @@ export declare function traceReadableStream<T>(options: StartSpanOptions | strin
|
|
|
33
33
|
* @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration}
|
|
34
34
|
*/
|
|
35
35
|
export declare function streamToAsyncIteratorObject<T>(stream: ReadableStream<T>, { signal }?: {
|
|
36
|
-
|
|
36
|
+
signal?: AbortSignal | undefined;
|
|
37
37
|
}): AsyncIteratorClass<T>;
|
|
38
38
|
/**
|
|
39
39
|
* Converts an `AsyncIterator` into a `ReadableStream`.
|
|
@@ -45,4 +45,4 @@ export declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): Re
|
|
|
45
45
|
*
|
|
46
46
|
* @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration}
|
|
47
47
|
*/
|
|
48
|
-
export declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
48
|
+
export declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|