@langchain/langgraph-sdk 0.1.9 → 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.
Files changed (234) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  3. package/dist/auth/error.cjs +76 -86
  4. package/dist/auth/error.cjs.map +1 -0
  5. package/dist/auth/error.d.cts +13 -0
  6. package/dist/auth/error.d.cts.map +1 -0
  7. package/dist/auth/error.d.ts +12 -8
  8. package/dist/auth/error.d.ts.map +1 -0
  9. package/dist/auth/error.js +76 -83
  10. package/dist/auth/error.js.map +1 -0
  11. package/dist/auth/index.cjs +36 -44
  12. package/dist/auth/index.cjs.map +1 -0
  13. package/dist/auth/index.d.cts +31 -0
  14. package/dist/auth/index.d.cts.map +1 -0
  15. package/dist/auth/index.d.ts +20 -15
  16. package/dist/auth/index.d.ts.map +1 -0
  17. package/dist/auth/index.js +35 -39
  18. package/dist/auth/index.js.map +1 -0
  19. package/dist/auth/types.d.cts +294 -0
  20. package/dist/auth/types.d.cts.map +1 -0
  21. package/dist/auth/types.d.ts +162 -165
  22. package/dist/auth/types.d.ts.map +1 -0
  23. package/dist/client.cjs +1108 -1294
  24. package/dist/client.cjs.map +1 -0
  25. package/dist/client.d.cts +688 -0
  26. package/dist/client.d.cts.map +1 -0
  27. package/dist/client.d.ts +647 -639
  28. package/dist/client.d.ts.map +1 -0
  29. package/dist/client.js +1099 -1281
  30. package/dist/client.js.map +1 -0
  31. package/dist/index.cjs +6 -8
  32. package/dist/index.d.cts +7 -0
  33. package/dist/index.d.ts +7 -7
  34. package/dist/index.js +4 -2
  35. package/dist/logging/index.cjs +30 -31
  36. package/dist/logging/index.cjs.map +1 -0
  37. package/dist/logging/index.d.cts +47 -0
  38. package/dist/logging/index.d.cts.map +1 -0
  39. package/dist/logging/index.d.ts +20 -16
  40. package/dist/logging/index.d.ts.map +1 -0
  41. package/dist/logging/index.js +31 -29
  42. package/dist/logging/index.js.map +1 -0
  43. package/dist/react/index.cjs +5 -7
  44. package/dist/react/index.d.cts +4 -0
  45. package/dist/react/index.d.ts +4 -3
  46. package/dist/react/index.js +4 -2
  47. package/dist/react/stream.cjs +14 -15
  48. package/dist/react/stream.cjs.map +1 -0
  49. package/dist/react/stream.custom.cjs +126 -145
  50. package/dist/react/stream.custom.cjs.map +1 -0
  51. package/dist/react/stream.custom.d.cts +39 -0
  52. package/dist/react/stream.custom.d.cts.map +1 -0
  53. package/dist/react/stream.custom.d.ts +35 -37
  54. package/dist/react/stream.custom.d.ts.map +1 -0
  55. package/dist/react/stream.custom.js +122 -137
  56. package/dist/react/stream.custom.js.map +1 -0
  57. package/dist/react/stream.d.cts +73 -0
  58. package/dist/react/stream.d.cts.map +1 -0
  59. package/dist/react/stream.d.ts +21 -15
  60. package/dist/react/stream.d.ts.map +1 -0
  61. package/dist/react/stream.js +12 -11
  62. package/dist/react/stream.js.map +1 -0
  63. package/dist/react/stream.lgp.cjs +438 -495
  64. package/dist/react/stream.lgp.cjs.map +1 -0
  65. package/dist/react/stream.lgp.js +433 -487
  66. package/dist/react/stream.lgp.js.map +1 -0
  67. package/dist/react/thread.cjs +18 -15
  68. package/dist/react/thread.cjs.map +1 -0
  69. package/dist/react/thread.js +19 -13
  70. package/dist/react/thread.js.map +1 -0
  71. package/dist/react/types.d.cts +355 -0
  72. package/dist/react/types.d.cts.map +1 -0
  73. package/dist/react/types.d.ts +333 -329
  74. package/dist/react/types.d.ts.map +1 -0
  75. package/dist/react-ui/client.cjs +123 -184
  76. package/dist/react-ui/client.cjs.map +1 -0
  77. package/dist/react-ui/client.d.cts +90 -0
  78. package/dist/react-ui/client.d.cts.map +1 -0
  79. package/dist/react-ui/client.d.ts +67 -51
  80. package/dist/react-ui/client.d.ts.map +1 -0
  81. package/dist/react-ui/client.js +118 -143
  82. package/dist/react-ui/client.js.map +1 -0
  83. package/dist/react-ui/index.cjs +14 -13
  84. package/dist/react-ui/index.cjs.map +1 -0
  85. package/dist/react-ui/index.d.cts +3 -0
  86. package/dist/react-ui/index.d.ts +3 -2
  87. package/dist/react-ui/index.js +8 -3
  88. package/dist/react-ui/index.js.map +1 -0
  89. package/dist/react-ui/server/index.cjs +5 -7
  90. package/dist/react-ui/server/index.d.cts +3 -0
  91. package/dist/react-ui/server/index.d.ts +3 -2
  92. package/dist/react-ui/server/index.js +4 -2
  93. package/dist/react-ui/server/server.cjs +53 -44
  94. package/dist/react-ui/server/server.cjs.map +1 -0
  95. package/dist/react-ui/server/server.d.cts +55 -0
  96. package/dist/react-ui/server/server.d.cts.map +1 -0
  97. package/dist/react-ui/server/server.d.ts +43 -39
  98. package/dist/react-ui/server/server.d.ts.map +1 -0
  99. package/dist/react-ui/server/server.js +54 -42
  100. package/dist/react-ui/server/server.js.map +1 -0
  101. package/dist/react-ui/types.cjs +32 -36
  102. package/dist/react-ui/types.cjs.map +1 -0
  103. package/dist/react-ui/types.d.cts +25 -0
  104. package/dist/react-ui/types.d.cts.map +1 -0
  105. package/dist/react-ui/types.d.ts +23 -19
  106. package/dist/react-ui/types.d.ts.map +1 -0
  107. package/dist/react-ui/types.js +32 -34
  108. package/dist/react-ui/types.js.map +1 -0
  109. package/dist/schema.d.cts +277 -0
  110. package/dist/schema.d.cts.map +1 -0
  111. package/dist/schema.d.ts +249 -242
  112. package/dist/schema.d.ts.map +1 -0
  113. package/dist/singletons/fetch.cjs +16 -20
  114. package/dist/singletons/fetch.cjs.map +1 -0
  115. package/dist/singletons/fetch.d.cts +14 -0
  116. package/dist/singletons/fetch.d.cts.map +1 -0
  117. package/dist/singletons/fetch.d.ts +5 -2
  118. package/dist/singletons/fetch.d.ts.map +1 -0
  119. package/dist/singletons/fetch.js +16 -17
  120. package/dist/singletons/fetch.js.map +1 -0
  121. package/dist/types.d.cts +187 -0
  122. package/dist/types.d.cts.map +1 -0
  123. package/dist/types.d.ts +178 -173
  124. package/dist/types.d.ts.map +1 -0
  125. package/dist/types.messages.d.cts +91 -0
  126. package/dist/types.messages.d.cts.map +1 -0
  127. package/dist/types.messages.d.ts +71 -66
  128. package/dist/types.messages.d.ts.map +1 -0
  129. package/dist/types.stream.d.cts +235 -0
  130. package/dist/types.stream.d.cts.map +1 -0
  131. package/dist/types.stream.d.ts +149 -142
  132. package/dist/types.stream.d.ts.map +1 -0
  133. package/dist/ui/branching.cjs +145 -141
  134. package/dist/ui/branching.cjs.map +1 -0
  135. package/dist/ui/branching.d.cts +22 -0
  136. package/dist/ui/branching.d.cts.map +1 -0
  137. package/dist/ui/branching.d.ts +17 -30
  138. package/dist/ui/branching.d.ts.map +1 -0
  139. package/dist/ui/branching.js +147 -139
  140. package/dist/ui/branching.js.map +1 -0
  141. package/dist/ui/errors.cjs +14 -12
  142. package/dist/ui/errors.cjs.map +1 -0
  143. package/dist/ui/errors.js +14 -9
  144. package/dist/ui/errors.js.map +1 -0
  145. package/dist/ui/manager.cjs +156 -232
  146. package/dist/ui/manager.cjs.map +1 -0
  147. package/dist/ui/manager.js +156 -228
  148. package/dist/ui/manager.js.map +1 -0
  149. package/dist/ui/messages.cjs +55 -69
  150. package/dist/ui/messages.cjs.map +1 -0
  151. package/dist/ui/messages.js +55 -66
  152. package/dist/ui/messages.js.map +1 -0
  153. package/dist/ui/utils.cjs +10 -10
  154. package/dist/ui/utils.cjs.map +1 -0
  155. package/dist/ui/utils.js +10 -8
  156. package/dist/ui/utils.js.map +1 -0
  157. package/dist/utils/async_caller.cjs +103 -185
  158. package/dist/utils/async_caller.cjs.map +1 -0
  159. package/dist/utils/async_caller.d.cts +53 -0
  160. package/dist/utils/async_caller.d.cts.map +1 -0
  161. package/dist/utils/async_caller.d.ts +36 -31
  162. package/dist/utils/async_caller.d.ts.map +1 -0
  163. package/dist/utils/async_caller.js +101 -177
  164. package/dist/utils/async_caller.js.map +1 -0
  165. package/dist/utils/env.cjs +11 -13
  166. package/dist/utils/env.cjs.map +1 -0
  167. package/dist/utils/env.js +11 -11
  168. package/dist/utils/env.js.map +1 -0
  169. package/dist/utils/signals.cjs +18 -19
  170. package/dist/utils/signals.cjs.map +1 -0
  171. package/dist/utils/signals.js +18 -17
  172. package/dist/utils/signals.js.map +1 -0
  173. package/dist/utils/sse.cjs +110 -140
  174. package/dist/utils/sse.cjs.map +1 -0
  175. package/dist/utils/sse.js +110 -138
  176. package/dist/utils/sse.js.map +1 -0
  177. package/dist/utils/stream.cjs +90 -114
  178. package/dist/utils/stream.cjs.map +1 -0
  179. package/dist/utils/stream.js +90 -111
  180. package/dist/utils/stream.js.map +1 -0
  181. package/package.json +72 -80
  182. package/auth.cjs +0 -1
  183. package/auth.d.cts +0 -1
  184. package/auth.d.ts +0 -1
  185. package/auth.js +0 -1
  186. package/client.cjs +0 -1
  187. package/client.d.cts +0 -1
  188. package/client.d.ts +0 -1
  189. package/client.js +0 -1
  190. package/dist/auth/types.cjs +0 -2
  191. package/dist/auth/types.js +0 -1
  192. package/dist/react/stream.lgp.d.ts +0 -7
  193. package/dist/react/thread.d.ts +0 -4
  194. package/dist/react/types.cjs +0 -2
  195. package/dist/react/types.js +0 -1
  196. package/dist/schema.cjs +0 -2
  197. package/dist/schema.js +0 -1
  198. package/dist/types.cjs +0 -2
  199. package/dist/types.js +0 -1
  200. package/dist/types.messages.cjs +0 -2
  201. package/dist/types.messages.js +0 -1
  202. package/dist/types.stream.cjs +0 -2
  203. package/dist/types.stream.js +0 -1
  204. package/dist/ui/branching.test.cjs +0 -370
  205. package/dist/ui/branching.test.d.ts +0 -1
  206. package/dist/ui/branching.test.js +0 -368
  207. package/dist/ui/errors.d.ts +0 -12
  208. package/dist/ui/manager.d.ts +0 -87
  209. package/dist/ui/messages.d.ts +0 -18
  210. package/dist/ui/utils.d.ts +0 -2
  211. package/dist/utils/env.d.ts +0 -1
  212. package/dist/utils/signals.d.ts +0 -1
  213. package/dist/utils/sse.d.ts +0 -8
  214. package/dist/utils/stream.d.ts +0 -13
  215. package/index.cjs +0 -1
  216. package/index.d.cts +0 -1
  217. package/index.d.ts +0 -1
  218. package/index.js +0 -1
  219. package/logging.cjs +0 -1
  220. package/logging.d.cts +0 -1
  221. package/logging.d.ts +0 -1
  222. package/logging.js +0 -1
  223. package/react-ui/server.cjs +0 -1
  224. package/react-ui/server.d.cts +0 -1
  225. package/react-ui/server.d.ts +0 -1
  226. package/react-ui/server.js +0 -1
  227. package/react-ui.cjs +0 -1
  228. package/react-ui.d.cts +0 -1
  229. package/react-ui.d.ts +0 -1
  230. package/react-ui.js +0 -1
  231. package/react.cjs +0 -1
  232. package/react.d.cts +0 -1
  233. package/react.d.ts +0 -1
  234. 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
- export interface AsyncCallerParams {
3
- /**
4
- * The maximum number of concurrent calls that can be made.
5
- * Defaults to `Infinity`, which means no limit.
6
- */
7
- maxConcurrency?: number;
8
- /**
9
- * The maximum number of retries that can be made for a single call,
10
- * with an exponential backoff between each attempt. Defaults to 6.
11
- */
12
- maxRetries?: number;
13
- onFailedResponseHook?: ResponseCallback;
14
- /**
15
- * Specify a custom fetch implementation.
16
- *
17
- * By default we expect the `fetch` is available in the global scope.
18
- */
19
- fetch?: typeof fetch | ((...args: any[]) => any);
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
- export interface AsyncCallerCallOptions {
22
- signal?: AbortSignal;
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
- export declare class AsyncCaller {
38
- protected maxConcurrency: AsyncCallerParams["maxConcurrency"];
39
- protected maxRetries: AsyncCallerParams["maxRetries"];
40
- private queue;
41
- private onFailedResponseHook?;
42
- private customFetch?;
43
- constructor(params: AsyncCallerParams);
44
- call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
45
- callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
46
- fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
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
- export {};
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
- import { _getFetchImplementation } from "../singletons/fetch.js";
4
+
5
+ //#region src/utils/async_caller.ts
4
6
  const STATUS_NO_RETRY = [
5
- 400, // Bad Request
6
- 401, // Unauthorized
7
- 402, // Payment required
8
- 403, // Forbidden
9
- 404, // Not Found
10
- 405, // Method Not Allowed
11
- 406, // Not Acceptable
12
- 407, // Proxy Authentication Required
13
- 408, // Request Timeout
14
- 409, // Conflict
15
- 422, // Unprocessable Entity
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
- * Do not rely on globalThis.Response, rather just
19
- * do duck typing
20
- */
20
+ * Do not rely on globalThis.Response, rather just
21
+ * do duck typing
22
+ */
21
23
  function isResponse(x) {
22
- if (x == null || typeof x !== "object")
23
- return false;
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
- * Utility error to properly handle failed requests
28
- */
29
- class HTTPError extends Error {
30
- constructor(status, message, response) {
31
- super(`HTTP ${status}: ${message}`);
32
- Object.defineProperty(this, "status", {
33
- enumerable: true,
34
- configurable: true,
35
- writable: true,
36
- value: void 0
37
- });
38
- Object.defineProperty(this, "text", {
39
- enumerable: true,
40
- configurable: true,
41
- writable: true,
42
- value: void 0
43
- });
44
- Object.defineProperty(this, "response", {
45
- enumerable: true,
46
- configurable: true,
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
- * A class that can be used to make async calls with concurrency and retry logic.
65
- *
66
- * This is useful for making calls to any kind of "expensive" external resource,
67
- * be it because it's rate-limited, subject to network issues, etc.
68
- *
69
- * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
70
- * to `Infinity`. This means that by default, all calls will be made in parallel.
71
- *
72
- * Retries are limited by the `maxRetries` parameter, which defaults to 5. This
73
- * means that by default, each call will be retried up to 5 times, with an
74
- * exponential backoff between each attempt.
75
- */
76
- export class AsyncCaller {
77
- constructor(params) {
78
- Object.defineProperty(this, "maxConcurrency", {
79
- enumerable: true,
80
- configurable: true,
81
- writable: true,
82
- value: void 0
83
- });
84
- Object.defineProperty(this, "maxRetries", {
85
- enumerable: true,
86
- configurable: true,
87
- writable: true,
88
- value: void 0
89
- });
90
- Object.defineProperty(this, "queue", {
91
- enumerable: true,
92
- configurable: true,
93
- writable: true,
94
- value: void 0
95
- });
96
- Object.defineProperty(this, "onFailedResponseHook", {
97
- enumerable: true,
98
- configurable: true,
99
- writable: true,
100
- value: void 0
101
- });
102
- Object.defineProperty(this, "customFetch", {
103
- enumerable: true,
104
- configurable: true,
105
- writable: true,
106
- value: void 0
107
- });
108
- this.maxConcurrency = params.maxConcurrency ?? Infinity;
109
- this.maxRetries = params.maxRetries ?? 4;
110
- if ("default" in PQueueMod) {
111
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
- this.queue = new PQueueMod.default({
113
- concurrency: this.maxConcurrency,
114
- });
115
- }
116
- else {
117
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- this.queue = new PQueueMod({ concurrency: this.maxConcurrency });
119
- }
120
- this.onFailedResponseHook = params?.onFailedResponseHook;
121
- this.customFetch = params.fetch;
122
- }
123
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
- call(callable, ...args) {
125
- const { onFailedResponseHook } = this;
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"}
@@ -1,15 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEnvironmentVariable = getEnvironmentVariable;
1
+
2
+ //#region src/utils/env.ts
4
3
  function getEnvironmentVariable(name) {
5
- // Certain setups (Deno, frontend) will throw an error if you try to access environment variables
6
- try {
7
- return typeof process !== "undefined"
8
- ? // eslint-disable-next-line no-process-env
9
- process.env?.[name]
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
- export function getEnvironmentVariable(name) {
2
- // Certain setups (Deno, frontend) will throw an error if you try to access environment variables
3
- try {
4
- return typeof process !== "undefined"
5
- ? // eslint-disable-next-line no-process-env
6
- process.env?.[name]
7
- : undefined;
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"}
@@ -1,21 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeSignals = mergeSignals;
1
+
2
+ //#region src/utils/signals.ts
4
3
  function mergeSignals(...signals) {
5
- const nonZeroSignals = signals.filter((signal) => signal != null);
6
- if (nonZeroSignals.length === 0)
7
- return undefined;
8
- if (nonZeroSignals.length === 1)
9
- return nonZeroSignals[0];
10
- const controller = new AbortController();
11
- for (const signal of signals) {
12
- if (signal?.aborted) {
13
- controller.abort(signal.reason);
14
- return controller.signal;
15
- }
16
- signal?.addEventListener("abort", () => controller.abort(signal.reason), {
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"}
@@ -1,18 +1,19 @@
1
- export function mergeSignals(...signals) {
2
- const nonZeroSignals = signals.filter((signal) => signal != null);
3
- if (nonZeroSignals.length === 0)
4
- return undefined;
5
- if (nonZeroSignals.length === 1)
6
- 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), {
14
- once: true,
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"}