@langchain/langgraph-sdk 0.1.10 → 1.0.0
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/CHANGELOG.md +6 -0
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/auth/error.cjs +76 -86
- package/dist/auth/error.cjs.map +1 -0
- package/dist/auth/error.d.cts +13 -0
- package/dist/auth/error.d.cts.map +1 -0
- package/dist/auth/error.d.ts +12 -8
- package/dist/auth/error.d.ts.map +1 -0
- package/dist/auth/error.js +76 -83
- package/dist/auth/error.js.map +1 -0
- package/dist/auth/index.cjs +36 -44
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +31 -0
- package/dist/auth/index.d.cts.map +1 -0
- package/dist/auth/index.d.ts +20 -15
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +35 -39
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.cts +294 -0
- package/dist/auth/types.d.cts.map +1 -0
- package/dist/auth/types.d.ts +162 -165
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/client.cjs +1108 -1294
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +688 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.ts +647 -639
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1099 -1281
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +6 -8
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +4 -2
- package/dist/logging/index.cjs +30 -31
- package/dist/logging/index.cjs.map +1 -0
- package/dist/logging/index.d.cts +47 -0
- package/dist/logging/index.d.cts.map +1 -0
- package/dist/logging/index.d.ts +20 -16
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +31 -29
- package/dist/logging/index.js.map +1 -0
- package/dist/react/index.cjs +5 -7
- package/dist/react/index.d.cts +4 -0
- package/dist/react/index.d.ts +4 -3
- package/dist/react/index.js +4 -2
- package/dist/react/stream.cjs +14 -15
- package/dist/react/stream.cjs.map +1 -0
- package/dist/react/stream.custom.cjs +126 -145
- package/dist/react/stream.custom.cjs.map +1 -0
- package/dist/react/stream.custom.d.cts +39 -0
- package/dist/react/stream.custom.d.cts.map +1 -0
- package/dist/react/stream.custom.d.ts +35 -37
- package/dist/react/stream.custom.d.ts.map +1 -0
- package/dist/react/stream.custom.js +122 -137
- package/dist/react/stream.custom.js.map +1 -0
- package/dist/react/stream.d.cts +73 -0
- package/dist/react/stream.d.cts.map +1 -0
- package/dist/react/stream.d.ts +21 -15
- package/dist/react/stream.d.ts.map +1 -0
- package/dist/react/stream.js +12 -11
- package/dist/react/stream.js.map +1 -0
- package/dist/react/stream.lgp.cjs +438 -498
- package/dist/react/stream.lgp.cjs.map +1 -0
- package/dist/react/stream.lgp.js +433 -490
- package/dist/react/stream.lgp.js.map +1 -0
- package/dist/react/thread.cjs +18 -15
- package/dist/react/thread.cjs.map +1 -0
- package/dist/react/thread.js +19 -13
- package/dist/react/thread.js.map +1 -0
- package/dist/react/types.d.cts +355 -0
- package/dist/react/types.d.cts.map +1 -0
- package/dist/react/types.d.ts +333 -329
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react-ui/client.cjs +123 -184
- package/dist/react-ui/client.cjs.map +1 -0
- package/dist/react-ui/client.d.cts +90 -0
- package/dist/react-ui/client.d.cts.map +1 -0
- package/dist/react-ui/client.d.ts +67 -51
- package/dist/react-ui/client.d.ts.map +1 -0
- package/dist/react-ui/client.js +118 -143
- package/dist/react-ui/client.js.map +1 -0
- package/dist/react-ui/index.cjs +14 -13
- package/dist/react-ui/index.cjs.map +1 -0
- package/dist/react-ui/index.d.cts +3 -0
- package/dist/react-ui/index.d.ts +3 -2
- package/dist/react-ui/index.js +8 -3
- package/dist/react-ui/index.js.map +1 -0
- package/dist/react-ui/server/index.cjs +5 -7
- package/dist/react-ui/server/index.d.cts +3 -0
- package/dist/react-ui/server/index.d.ts +3 -2
- package/dist/react-ui/server/index.js +4 -2
- package/dist/react-ui/server/server.cjs +53 -44
- package/dist/react-ui/server/server.cjs.map +1 -0
- package/dist/react-ui/server/server.d.cts +55 -0
- package/dist/react-ui/server/server.d.cts.map +1 -0
- package/dist/react-ui/server/server.d.ts +43 -39
- package/dist/react-ui/server/server.d.ts.map +1 -0
- package/dist/react-ui/server/server.js +54 -42
- package/dist/react-ui/server/server.js.map +1 -0
- package/dist/react-ui/types.cjs +32 -36
- package/dist/react-ui/types.cjs.map +1 -0
- package/dist/react-ui/types.d.cts +25 -0
- package/dist/react-ui/types.d.cts.map +1 -0
- package/dist/react-ui/types.d.ts +23 -19
- package/dist/react-ui/types.d.ts.map +1 -0
- package/dist/react-ui/types.js +32 -34
- package/dist/react-ui/types.js.map +1 -0
- package/dist/schema.d.cts +277 -0
- package/dist/schema.d.cts.map +1 -0
- package/dist/schema.d.ts +249 -242
- package/dist/schema.d.ts.map +1 -0
- package/dist/singletons/fetch.cjs +16 -20
- package/dist/singletons/fetch.cjs.map +1 -0
- package/dist/singletons/fetch.d.cts +14 -0
- package/dist/singletons/fetch.d.cts.map +1 -0
- package/dist/singletons/fetch.d.ts +5 -2
- package/dist/singletons/fetch.d.ts.map +1 -0
- package/dist/singletons/fetch.js +16 -17
- package/dist/singletons/fetch.js.map +1 -0
- package/dist/types.d.cts +187 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +178 -173
- package/dist/types.d.ts.map +1 -0
- package/dist/types.messages.d.cts +91 -0
- package/dist/types.messages.d.cts.map +1 -0
- package/dist/types.messages.d.ts +71 -66
- package/dist/types.messages.d.ts.map +1 -0
- package/dist/types.stream.d.cts +235 -0
- package/dist/types.stream.d.cts.map +1 -0
- package/dist/types.stream.d.ts +149 -142
- package/dist/types.stream.d.ts.map +1 -0
- package/dist/ui/branching.cjs +145 -141
- package/dist/ui/branching.cjs.map +1 -0
- package/dist/ui/branching.d.cts +22 -0
- package/dist/ui/branching.d.cts.map +1 -0
- package/dist/ui/branching.d.ts +17 -30
- package/dist/ui/branching.d.ts.map +1 -0
- package/dist/ui/branching.js +147 -139
- package/dist/ui/branching.js.map +1 -0
- package/dist/ui/errors.cjs +14 -12
- package/dist/ui/errors.cjs.map +1 -0
- package/dist/ui/errors.js +14 -9
- package/dist/ui/errors.js.map +1 -0
- package/dist/ui/manager.cjs +156 -232
- package/dist/ui/manager.cjs.map +1 -0
- package/dist/ui/manager.js +156 -228
- package/dist/ui/manager.js.map +1 -0
- package/dist/ui/messages.cjs +55 -69
- package/dist/ui/messages.cjs.map +1 -0
- package/dist/ui/messages.js +55 -66
- package/dist/ui/messages.js.map +1 -0
- package/dist/ui/utils.cjs +10 -10
- package/dist/ui/utils.cjs.map +1 -0
- package/dist/ui/utils.js +10 -8
- package/dist/ui/utils.js.map +1 -0
- package/dist/utils/async_caller.cjs +103 -185
- package/dist/utils/async_caller.cjs.map +1 -0
- package/dist/utils/async_caller.d.cts +53 -0
- package/dist/utils/async_caller.d.cts.map +1 -0
- package/dist/utils/async_caller.d.ts +36 -31
- package/dist/utils/async_caller.d.ts.map +1 -0
- package/dist/utils/async_caller.js +101 -177
- package/dist/utils/async_caller.js.map +1 -0
- package/dist/utils/env.cjs +11 -13
- package/dist/utils/env.cjs.map +1 -0
- package/dist/utils/env.js +11 -11
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/signals.cjs +18 -19
- package/dist/utils/signals.cjs.map +1 -0
- package/dist/utils/signals.js +18 -17
- package/dist/utils/signals.js.map +1 -0
- package/dist/utils/sse.cjs +110 -140
- package/dist/utils/sse.cjs.map +1 -0
- package/dist/utils/sse.js +110 -138
- package/dist/utils/sse.js.map +1 -0
- package/dist/utils/stream.cjs +90 -114
- package/dist/utils/stream.cjs.map +1 -0
- package/dist/utils/stream.js +90 -111
- package/dist/utils/stream.js.map +1 -0
- package/package.json +72 -80
- package/auth.cjs +0 -1
- package/auth.d.cts +0 -1
- package/auth.d.ts +0 -1
- package/auth.js +0 -1
- package/client.cjs +0 -1
- package/client.d.cts +0 -1
- package/client.d.ts +0 -1
- package/client.js +0 -1
- package/dist/auth/types.cjs +0 -2
- package/dist/auth/types.js +0 -1
- package/dist/react/stream.lgp.d.ts +0 -7
- package/dist/react/thread.d.ts +0 -4
- package/dist/react/types.cjs +0 -2
- package/dist/react/types.js +0 -1
- package/dist/schema.cjs +0 -2
- package/dist/schema.js +0 -1
- package/dist/types.cjs +0 -2
- package/dist/types.js +0 -1
- package/dist/types.messages.cjs +0 -2
- package/dist/types.messages.js +0 -1
- package/dist/types.stream.cjs +0 -2
- package/dist/types.stream.js +0 -1
- package/dist/ui/branching.test.cjs +0 -370
- package/dist/ui/branching.test.d.ts +0 -1
- package/dist/ui/branching.test.js +0 -368
- package/dist/ui/errors.d.ts +0 -12
- package/dist/ui/manager.d.ts +0 -87
- package/dist/ui/messages.d.ts +0 -18
- package/dist/ui/utils.d.ts +0 -2
- package/dist/utils/env.d.ts +0 -1
- package/dist/utils/signals.d.ts +0 -1
- package/dist/utils/sse.d.ts +0 -8
- package/dist/utils/stream.d.ts +0 -13
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/logging.cjs +0 -1
- package/logging.d.cts +0 -1
- package/logging.d.ts +0 -1
- package/logging.js +0 -1
- package/react-ui/server.cjs +0 -1
- package/react-ui/server.d.cts +0 -1
- package/react-ui/server.d.ts +0 -1
- package/react-ui/server.js +0 -1
- package/react-ui.cjs +0 -1
- package/react-ui.d.cts +0 -1
- package/react-ui.d.ts +0 -1
- package/react-ui.js +0 -1
- package/react.cjs +0 -1
- package/react.d.cts +0 -1
- package/react.d.ts +0 -1
- package/react.js +0 -1
|
@@ -1,25 +1,26 @@
|
|
|
1
|
+
//#region src/utils/async_caller.d.ts
|
|
1
2
|
type ResponseCallback = (response?: Response) => Promise<boolean>;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
interface AsyncCallerParams {
|
|
4
|
+
/**
|
|
5
|
+
* The maximum number of concurrent calls that can be made.
|
|
6
|
+
* Defaults to `Infinity`, which means no limit.
|
|
7
|
+
*/
|
|
8
|
+
maxConcurrency?: number;
|
|
9
|
+
/**
|
|
10
|
+
* The maximum number of retries that can be made for a single call,
|
|
11
|
+
* with an exponential backoff between each attempt. Defaults to 6.
|
|
12
|
+
*/
|
|
13
|
+
maxRetries?: number;
|
|
14
|
+
onFailedResponseHook?: ResponseCallback;
|
|
15
|
+
/**
|
|
16
|
+
* Specify a custom fetch implementation.
|
|
17
|
+
*
|
|
18
|
+
* By default we expect the `fetch` is available in the global scope.
|
|
19
|
+
*/
|
|
20
|
+
fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
interface AsyncCallerCallOptions {
|
|
23
|
+
signal?: AbortSignal;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* A class that can be used to make async calls with concurrency and retry logic.
|
|
@@ -34,15 +35,19 @@ export interface AsyncCallerCallOptions {
|
|
|
34
35
|
* means that by default, each call will be retried up to 5 times, with an
|
|
35
36
|
* exponential backoff between each attempt.
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
declare class AsyncCaller {
|
|
39
|
+
protected maxConcurrency: AsyncCallerParams["maxConcurrency"];
|
|
40
|
+
protected maxRetries: AsyncCallerParams["maxRetries"];
|
|
41
|
+
private queue;
|
|
42
|
+
private onFailedResponseHook?;
|
|
43
|
+
private customFetch?;
|
|
44
|
+
constructor(params: AsyncCallerParams);
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
49
|
+
fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
export { AsyncCaller, AsyncCallerParams };
|
|
53
|
+
//# sourceMappingURL=async_caller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async_caller.d.ts","names":["ResponseCallback","Response","Promise","AsyncCallerParams","fetch","AsyncCallerCallOptions","AbortSignal","AsyncCaller","A","T","Parameters","ReturnType","Awaited"],"sources":["../../src/utils/async_caller.d.ts"],"sourcesContent":["type ResponseCallback = (response?: Response) => Promise<boolean>;\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n onFailedResponseHook?: ResponseCallback;\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n}\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 5. This\n * means that by default, each call will be retried up to 5 times, with an\n * exponential backoff between each attempt.\n */\nexport declare class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n private queue;\n private onFailedResponseHook?;\n private customFetch?;\n constructor(params: AsyncCallerParams);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;\n}\nexport {};\n"],"mappings":";KAAKA,gBAAAA,eAA+BC,aAAaC;AAA5CF,UACYG,iBAAAA,CADI;EAAA;;;;EACJA,cAAAA,CAAAA,EAAAA,MAAiB;EAAA;;;;EAmBjBE,UAAAA,CAAAA,EAAAA,MAAAA;EAgBIE,oBAAW,CAAA,EAxBLP,gBAwBK;EAAA;;;;;OAQoBE,CAAAA,EAAAA,OA1BjCE,KA0BiCF,GAAAA,CAAAA,CAAAA,GAAAA,IAAAA,EAAAA,GAAAA,EAAAA,EAAAA,GAAAA,GAAAA,CAAAA,CAAAA,CAAAA;;AAA+CO,UAxBlFJ,sBAAAA,CAwBkFI;QAAXC,CAAAA,EAvB3EJ,WAuB2EI;;;;;;;;;;;;;;;AAGnDN,cAXhBG,WAAAA,CAWgBH;YAAlBM,cAAAA,EAVWP,iBAUXO,CAAAA,gBAAAA,CAAAA;YAA6CN,UAAAA,EATtCD,iBASsCC,CAAAA,YAAAA,CAAAA;UAAlBO,KAAAA;;;sBALtBR;;4CAEsBK,MAAMN,wBAAwBO,YAAYC,WAAWD,KAAKP,QAAQU,QAAQD,WAAWF;;uDAE1ED,MAAMN,uBAAuBG,kCAAkCI,YAAYC,WAAWD,KAAKP,QAAQU,QAAQD,WAAWF;iBAC5JC,kBAAkBN,SAASO,kBAAkBP"}
|
|
@@ -1,186 +1,110 @@
|
|
|
1
|
+
import { _getFetchImplementation } from "../singletons/fetch.js";
|
|
1
2
|
import pRetry from "p-retry";
|
|
2
3
|
import PQueueMod from "p-queue";
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
//#region src/utils/async_caller.ts
|
|
4
6
|
const STATUS_NO_RETRY = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
400,
|
|
8
|
+
401,
|
|
9
|
+
402,
|
|
10
|
+
403,
|
|
11
|
+
404,
|
|
12
|
+
405,
|
|
13
|
+
406,
|
|
14
|
+
407,
|
|
15
|
+
408,
|
|
16
|
+
409,
|
|
17
|
+
422
|
|
16
18
|
];
|
|
17
19
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
* Do not rely on globalThis.Response, rather just
|
|
21
|
+
* do duck typing
|
|
22
|
+
*/
|
|
21
23
|
function isResponse(x) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return "status" in x && "statusText" in x && "text" in x;
|
|
24
|
+
if (x == null || typeof x !== "object") return false;
|
|
25
|
+
return "status" in x && "statusText" in x && "text" in x;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class HTTPError extends Error {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
writable: true,
|
|
48
|
-
value: void 0
|
|
49
|
-
});
|
|
50
|
-
this.status = status;
|
|
51
|
-
this.text = message;
|
|
52
|
-
this.response = response;
|
|
53
|
-
}
|
|
54
|
-
static async fromResponse(response, options) {
|
|
55
|
-
try {
|
|
56
|
-
return new HTTPError(response.status, await response.text(), options?.includeResponse ? response : undefined);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
return new HTTPError(response.status, response.statusText, options?.includeResponse ? response : undefined);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
28
|
+
* Utility error to properly handle failed requests
|
|
29
|
+
*/
|
|
30
|
+
var HTTPError = class HTTPError extends Error {
|
|
31
|
+
status;
|
|
32
|
+
text;
|
|
33
|
+
response;
|
|
34
|
+
constructor(status, message, response) {
|
|
35
|
+
super(`HTTP ${status}: ${message}`);
|
|
36
|
+
this.status = status;
|
|
37
|
+
this.text = message;
|
|
38
|
+
this.response = response;
|
|
39
|
+
}
|
|
40
|
+
static async fromResponse(response, options) {
|
|
41
|
+
try {
|
|
42
|
+
return new HTTPError(response.status, await response.text(), options?.includeResponse ? response : void 0);
|
|
43
|
+
} catch {
|
|
44
|
+
return new HTTPError(response.status, response.statusText, options?.includeResponse ? response : void 0);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
63
48
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return this.queue.add(() => pRetry(() => callable(...args).catch(async (error) => {
|
|
127
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
128
|
-
if (error instanceof Error) {
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
else if (isResponse(error)) {
|
|
132
|
-
throw await HTTPError.fromResponse(error, {
|
|
133
|
-
includeResponse: !!onFailedResponseHook,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
throw new Error(error);
|
|
138
|
-
}
|
|
139
|
-
}), {
|
|
140
|
-
async onFailedAttempt(error) {
|
|
141
|
-
if (error.message.startsWith("Cancel") ||
|
|
142
|
-
error.message.startsWith("TimeoutError") ||
|
|
143
|
-
error.message.startsWith("AbortError")) {
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
147
|
-
if (error?.code === "ECONNABORTED") {
|
|
148
|
-
throw error;
|
|
149
|
-
}
|
|
150
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
151
|
-
if (error instanceof HTTPError) {
|
|
152
|
-
if (STATUS_NO_RETRY.includes(error.status)) {
|
|
153
|
-
throw error;
|
|
154
|
-
}
|
|
155
|
-
if (onFailedResponseHook && error.response) {
|
|
156
|
-
await onFailedResponseHook(error.response);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
// If needed we can change some of the defaults here,
|
|
161
|
-
// but they're quite sensible.
|
|
162
|
-
retries: this.maxRetries,
|
|
163
|
-
randomize: true,
|
|
164
|
-
}), { throwOnTimeout: true });
|
|
165
|
-
}
|
|
166
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
|
-
callWithOptions(options, callable, ...args) {
|
|
168
|
-
// Note this doesn't cancel the underlying request,
|
|
169
|
-
// when available prefer to use the signal option of the underlying call
|
|
170
|
-
if (options.signal) {
|
|
171
|
-
return Promise.race([
|
|
172
|
-
this.call(callable, ...args),
|
|
173
|
-
new Promise((_, reject) => {
|
|
174
|
-
options.signal?.addEventListener("abort", () => {
|
|
175
|
-
reject(new Error("AbortError"));
|
|
176
|
-
});
|
|
177
|
-
}),
|
|
178
|
-
]);
|
|
179
|
-
}
|
|
180
|
-
return this.call(callable, ...args);
|
|
181
|
-
}
|
|
182
|
-
fetch(...args) {
|
|
183
|
-
const fetchFn = this.customFetch ?? _getFetchImplementation();
|
|
184
|
-
return this.call(() => fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res))));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
49
|
+
* A class that can be used to make async calls with concurrency and retry logic.
|
|
50
|
+
*
|
|
51
|
+
* This is useful for making calls to any kind of "expensive" external resource,
|
|
52
|
+
* be it because it's rate-limited, subject to network issues, etc.
|
|
53
|
+
*
|
|
54
|
+
* Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
|
|
55
|
+
* to `Infinity`. This means that by default, all calls will be made in parallel.
|
|
56
|
+
*
|
|
57
|
+
* Retries are limited by the `maxRetries` parameter, which defaults to 5. This
|
|
58
|
+
* means that by default, each call will be retried up to 5 times, with an
|
|
59
|
+
* exponential backoff between each attempt.
|
|
60
|
+
*/
|
|
61
|
+
var AsyncCaller = class {
|
|
62
|
+
maxConcurrency;
|
|
63
|
+
maxRetries;
|
|
64
|
+
queue;
|
|
65
|
+
onFailedResponseHook;
|
|
66
|
+
customFetch;
|
|
67
|
+
constructor(params) {
|
|
68
|
+
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
69
|
+
this.maxRetries = params.maxRetries ?? 4;
|
|
70
|
+
if ("default" in PQueueMod) this.queue = new PQueueMod.default({ concurrency: this.maxConcurrency });
|
|
71
|
+
else this.queue = new PQueueMod({ concurrency: this.maxConcurrency });
|
|
72
|
+
this.onFailedResponseHook = params?.onFailedResponseHook;
|
|
73
|
+
this.customFetch = params.fetch;
|
|
74
|
+
}
|
|
75
|
+
call(callable, ...args) {
|
|
76
|
+
const { onFailedResponseHook } = this;
|
|
77
|
+
return this.queue.add(() => pRetry(() => callable(...args).catch(async (error) => {
|
|
78
|
+
if (error instanceof Error) throw error;
|
|
79
|
+
else if (isResponse(error)) throw await HTTPError.fromResponse(error, { includeResponse: !!onFailedResponseHook });
|
|
80
|
+
else throw new Error(error);
|
|
81
|
+
}), {
|
|
82
|
+
async onFailedAttempt(error) {
|
|
83
|
+
if (error.message.startsWith("Cancel") || error.message.startsWith("TimeoutError") || error.message.startsWith("AbortError")) throw error;
|
|
84
|
+
if (error?.code === "ECONNABORTED") throw error;
|
|
85
|
+
if (error instanceof HTTPError) {
|
|
86
|
+
if (STATUS_NO_RETRY.includes(error.status)) throw error;
|
|
87
|
+
if (onFailedResponseHook && error.response) await onFailedResponseHook(error.response);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
retries: this.maxRetries,
|
|
91
|
+
randomize: true
|
|
92
|
+
}), { throwOnTimeout: true });
|
|
93
|
+
}
|
|
94
|
+
callWithOptions(options, callable, ...args) {
|
|
95
|
+
if (options.signal) return Promise.race([this.call(callable, ...args), new Promise((_, reject) => {
|
|
96
|
+
options.signal?.addEventListener("abort", () => {
|
|
97
|
+
reject(/* @__PURE__ */ new Error("AbortError"));
|
|
98
|
+
});
|
|
99
|
+
})]);
|
|
100
|
+
return this.call(callable, ...args);
|
|
101
|
+
}
|
|
102
|
+
fetch(...args) {
|
|
103
|
+
const fetchFn = this.customFetch ?? _getFetchImplementation();
|
|
104
|
+
return this.call(() => fetchFn(...args).then((res) => res.ok ? res : Promise.reject(res)));
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
export { AsyncCaller };
|
|
110
|
+
//# sourceMappingURL=async_caller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async_caller.js","names":[],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\nimport { _getFetchImplementation } from \"../singletons/fetch.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 408, // Request Timeout\n 409, // Conflict\n 422, // Unprocessable Entity\n];\n\ntype ResponseCallback = (response?: Response) => Promise<boolean>;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n\n onFailedResponseHook?: ResponseCallback;\n\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Do not rely on globalThis.Response, rather just\n * do duck typing\n */\nfunction isResponse(x: unknown): x is Response {\n if (x == null || typeof x !== \"object\") return false;\n return \"status\" in x && \"statusText\" in x && \"text\" in x;\n}\n\n/**\n * Utility error to properly handle failed requests\n */\nclass HTTPError extends Error {\n status: number;\n\n text: string;\n\n response?: Response;\n\n constructor(status: number, message: string, response?: Response) {\n super(`HTTP ${status}: ${message}`);\n this.status = status;\n this.text = message;\n this.response = response;\n }\n\n static async fromResponse(\n response: Response,\n options?: { includeResponse?: boolean }\n ): Promise<HTTPError> {\n try {\n return new HTTPError(\n response.status,\n await response.text(),\n options?.includeResponse ? response : undefined\n );\n } catch {\n return new HTTPError(\n response.status,\n response.statusText,\n options?.includeResponse ? response : undefined\n );\n }\n }\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 5. This\n * means that by default, each call will be retried up to 5 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n private onFailedResponseHook?: ResponseCallback;\n\n private customFetch?: typeof fetch;\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 4;\n\n if (\"default\" in PQueueMod) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod.default as any)({\n concurrency: this.maxConcurrency,\n });\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod as any)({ concurrency: this.maxConcurrency });\n }\n this.onFailedResponseHook = params?.onFailedResponseHook;\n this.customFetch = params.fetch;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n const { onFailedResponseHook } = this;\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...(args as Parameters<T>)).catch(async (error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else if (isResponse(error)) {\n throw await HTTPError.fromResponse(error, {\n includeResponse: !!onFailedResponseHook,\n });\n } else {\n throw new Error(error);\n }\n }),\n {\n async onFailedAttempt(error) {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"TimeoutError\") ||\n error.message.startsWith(\"AbortError\")\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof HTTPError) {\n if (STATUS_NO_RETRY.includes(error.status)) {\n throw error;\n }\n if (onFailedResponseHook && error.response) {\n await onFailedResponseHook(error.response);\n }\n }\n },\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n retries: this.maxRetries,\n randomize: true,\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n options.signal?.addEventListener(\"abort\", () => {\n reject(new Error(\"AbortError\"));\n });\n }),\n ]);\n }\n return this.call<A, T>(callable, ...args);\n }\n\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {\n const fetchFn =\n this.customFetch ?? (_getFetchImplementation() as typeof fetch);\n return this.call(() =>\n fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res)))\n );\n }\n}\n"],"mappings":";;;;;AAIA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;AAmCF,SAAS,WAAW,GAA2B;AAC7C,KAAI,KAAK,QAAQ,OAAO,MAAM,SAAU,QAAO;AAC/C,QAAO,YAAY,KAAK,gBAAgB,KAAK,UAAU;;;;;AAMzD,IAAM,YAAN,MAAM,kBAAkB,MAAM;CAC5B;CAEA;CAEA;CAEA,YAAY,QAAgB,SAAiB,UAAqB;AAChE,QAAM,QAAQ,OAAO,IAAI;AACzB,OAAK,SAAS;AACd,OAAK,OAAO;AACZ,OAAK,WAAW;;CAGlB,aAAa,aACX,UACA,SACoB;AACpB,MAAI;AACF,UAAO,IAAI,UACT,SAAS,QACT,MAAM,SAAS,QACf,SAAS,kBAAkB,WAAW;UAElC;AACN,UAAO,IAAI,UACT,SAAS,QACT,SAAS,YACT,SAAS,kBAAkB,WAAW;;;;;;;;;;;;;;;;;AAmB9C,IAAa,cAAb,MAAyB;CACvB,AAAU;CAEV,AAAU;CAEV,AAAQ;CAER,AAAQ;CAER,AAAQ;CAER,YAAY,QAA2B;AACrC,OAAK,iBAAiB,OAAO,kBAAkB;AAC/C,OAAK,aAAa,OAAO,cAAc;AAEvC,MAAI,aAAa,UAEf,MAAK,QAAQ,IAAK,UAAU,QAAgB,EAC1C,aAAa,KAAK;MAIpB,MAAK,QAAQ,IAAK,UAAkB,EAAE,aAAa,KAAK;AAE1D,OAAK,uBAAuB,QAAQ;AACpC,OAAK,cAAc,OAAO;;CAI5B,KACE,UACA,GAAG,MAC8B;EACjC,MAAM,EAAE,yBAAyB;AACjC,SAAO,KAAK,MAAM,UAEd,aAEI,SAAS,GAAI,MAAwB,MAAM,OAAO,UAAU;AAE1D,OAAI,iBAAiB,MACnB,OAAM;YACG,WAAW,OACpB,OAAM,MAAM,UAAU,aAAa,OAAO,EACxC,iBAAiB,CAAC,CAAC;OAGrB,OAAM,IAAI,MAAM;MAGtB;GACE,MAAM,gBAAgB,OAAO;AAC3B,QACE,MAAM,QAAQ,WAAW,aACzB,MAAM,QAAQ,WAAW,mBACzB,MAAM,QAAQ,WAAW,cAEzB,OAAM;AAGR,QAAK,OAAe,SAAS,eAC3B,OAAM;AAIR,QAAI,iBAAiB,WAAW;AAC9B,SAAI,gBAAgB,SAAS,MAAM,QACjC,OAAM;AAER,SAAI,wBAAwB,MAAM,SAChC,OAAM,qBAAqB,MAAM;;;GAMvC,SAAS,KAAK;GACd,WAAW;MAGjB,EAAE,gBAAgB;;CAKtB,gBACE,SACA,UACA,GAAG,MAC8B;AAGjC,MAAI,QAAQ,OACV,QAAO,QAAQ,KAAK,CAClB,KAAK,KAAW,UAAU,GAAG,OAC7B,IAAI,SAAgB,GAAG,WAAW;AAChC,WAAQ,QAAQ,iBAAiB,eAAe;AAC9C,2BAAO,IAAI,MAAM;;;AAKzB,SAAO,KAAK,KAAW,UAAU,GAAG;;CAGtC,MAAM,GAAG,MAA0D;EACjE,MAAM,UACJ,KAAK,eAAgB;AACvB,SAAO,KAAK,WACV,QAAQ,GAAG,MAAM,MAAM,QAAS,IAAI,KAAK,MAAM,QAAQ,OAAO"}
|
package/dist/utils/env.cjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getEnvironmentVariable = getEnvironmentVariable;
|
|
1
|
+
|
|
2
|
+
//#region src/utils/env.ts
|
|
4
3
|
function getEnvironmentVariable(name) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
: undefined;
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
4
|
+
try {
|
|
5
|
+
return typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
6
|
+
} catch (e) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
15
9
|
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.getEnvironmentVariable = getEnvironmentVariable;
|
|
13
|
+
//# sourceMappingURL=env.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.cjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["export function getEnvironmentVariable(name: string): string | undefined {\n // Certain setups (Deno, frontend) will throw an error if you try to access environment variables\n try {\n return typeof process !== \"undefined\"\n ? // eslint-disable-next-line no-process-env\n process.env?.[name]\n : undefined;\n } catch (e) {\n return undefined;\n }\n}\n"],"mappings":";;AAAA,SAAgB,uBAAuB,MAAkC;AAEvE,KAAI;AACF,SAAO,OAAO,YAAY,cAEtB,QAAQ,MAAM,QACd;UACG,GAAG;AACV,SAAO"}
|
package/dist/utils/env.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
catch (e) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
1
|
+
//#region src/utils/env.ts
|
|
2
|
+
function getEnvironmentVariable(name) {
|
|
3
|
+
try {
|
|
4
|
+
return typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
5
|
+
} catch (e) {
|
|
6
|
+
return void 0;
|
|
7
|
+
}
|
|
12
8
|
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getEnvironmentVariable };
|
|
12
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["export function getEnvironmentVariable(name: string): string | undefined {\n // Certain setups (Deno, frontend) will throw an error if you try to access environment variables\n try {\n return typeof process !== \"undefined\"\n ? // eslint-disable-next-line no-process-env\n process.env?.[name]\n : undefined;\n } catch (e) {\n return undefined;\n }\n}\n"],"mappings":";AAAA,SAAgB,uBAAuB,MAAkC;AAEvE,KAAI;AACF,SAAO,OAAO,YAAY,cAEtB,QAAQ,MAAM,QACd;UACG,GAAG;AACV,SAAO"}
|
package/dist/utils/signals.cjs
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.mergeSignals = mergeSignals;
|
|
1
|
+
|
|
2
|
+
//#region src/utils/signals.ts
|
|
4
3
|
function mergeSignals(...signals) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
once: true,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return controller.signal;
|
|
4
|
+
const nonZeroSignals = signals.filter((signal) => signal != null);
|
|
5
|
+
if (nonZeroSignals.length === 0) return void 0;
|
|
6
|
+
if (nonZeroSignals.length === 1) return nonZeroSignals[0];
|
|
7
|
+
const controller = new AbortController();
|
|
8
|
+
for (const signal of signals) {
|
|
9
|
+
if (signal?.aborted) {
|
|
10
|
+
controller.abort(signal.reason);
|
|
11
|
+
return controller.signal;
|
|
12
|
+
}
|
|
13
|
+
signal?.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
|
|
14
|
+
}
|
|
15
|
+
return controller.signal;
|
|
21
16
|
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.mergeSignals = mergeSignals;
|
|
20
|
+
//# sourceMappingURL=signals.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.cjs","names":[],"sources":["../../src/utils/signals.ts"],"sourcesContent":["export function mergeSignals(...signals: (AbortSignal | null | undefined)[]) {\n const nonZeroSignals = signals.filter(\n (signal): signal is AbortSignal => signal != null\n );\n\n if (nonZeroSignals.length === 0) return undefined;\n if (nonZeroSignals.length === 1) return nonZeroSignals[0];\n\n const controller = new AbortController();\n for (const signal of signals) {\n if (signal?.aborted) {\n controller.abort(signal.reason);\n return controller.signal;\n }\n\n signal?.addEventListener(\"abort\", () => controller.abort(signal.reason), {\n once: true,\n });\n }\n\n return controller.signal;\n}\n"],"mappings":";;AAAA,SAAgB,aAAa,GAAG,SAA6C;CAC3E,MAAM,iBAAiB,QAAQ,QAC5B,WAAkC,UAAU;AAG/C,KAAI,eAAe,WAAW,EAAG,QAAO;AACxC,KAAI,eAAe,WAAW,EAAG,QAAO,eAAe;CAEvD,MAAM,aAAa,IAAI;AACvB,MAAK,MAAM,UAAU,SAAS;AAC5B,MAAI,QAAQ,SAAS;AACnB,cAAW,MAAM,OAAO;AACxB,UAAO,WAAW;;AAGpB,UAAQ,iBAAiB,eAAe,WAAW,MAAM,OAAO,SAAS,EACvE,MAAM;;AAIV,QAAO,WAAW"}
|
package/dist/utils/signals.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return controller.signal;
|
|
1
|
+
//#region src/utils/signals.ts
|
|
2
|
+
function mergeSignals(...signals) {
|
|
3
|
+
const nonZeroSignals = signals.filter((signal) => signal != null);
|
|
4
|
+
if (nonZeroSignals.length === 0) return void 0;
|
|
5
|
+
if (nonZeroSignals.length === 1) return nonZeroSignals[0];
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
for (const signal of signals) {
|
|
8
|
+
if (signal?.aborted) {
|
|
9
|
+
controller.abort(signal.reason);
|
|
10
|
+
return controller.signal;
|
|
11
|
+
}
|
|
12
|
+
signal?.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
|
|
13
|
+
}
|
|
14
|
+
return controller.signal;
|
|
18
15
|
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { mergeSignals };
|
|
19
|
+
//# sourceMappingURL=signals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.js","names":[],"sources":["../../src/utils/signals.ts"],"sourcesContent":["export function mergeSignals(...signals: (AbortSignal | null | undefined)[]) {\n const nonZeroSignals = signals.filter(\n (signal): signal is AbortSignal => signal != null\n );\n\n if (nonZeroSignals.length === 0) return undefined;\n if (nonZeroSignals.length === 1) return nonZeroSignals[0];\n\n const controller = new AbortController();\n for (const signal of signals) {\n if (signal?.aborted) {\n controller.abort(signal.reason);\n return controller.signal;\n }\n\n signal?.addEventListener(\"abort\", () => controller.abort(signal.reason), {\n once: true,\n });\n }\n\n return controller.signal;\n}\n"],"mappings":";AAAA,SAAgB,aAAa,GAAG,SAA6C;CAC3E,MAAM,iBAAiB,QAAQ,QAC5B,WAAkC,UAAU;AAG/C,KAAI,eAAe,WAAW,EAAG,QAAO;AACxC,KAAI,eAAe,WAAW,EAAG,QAAO,eAAe;CAEvD,MAAM,aAAa,IAAI;AACvB,MAAK,MAAM,UAAU,SAAS;AAC5B,MAAI,QAAQ,SAAS;AACnB,cAAW,MAAM,OAAO;AACxB,UAAO,WAAW;;AAGpB,UAAQ,iBAAiB,eAAe,WAAW,MAAM,OAAO,SAAS,EACvE,MAAM;;AAIV,QAAO,WAAW"}
|