@langchain/langgraph-sdk 0.1.10 → 1.0.1

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 (235) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +11 -0
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/auth/error.cjs +76 -86
  5. package/dist/auth/error.cjs.map +1 -0
  6. package/dist/auth/error.d.cts +13 -0
  7. package/dist/auth/error.d.cts.map +1 -0
  8. package/dist/auth/error.d.ts +12 -8
  9. package/dist/auth/error.d.ts.map +1 -0
  10. package/dist/auth/error.js +76 -83
  11. package/dist/auth/error.js.map +1 -0
  12. package/dist/auth/index.cjs +36 -44
  13. package/dist/auth/index.cjs.map +1 -0
  14. package/dist/auth/index.d.cts +31 -0
  15. package/dist/auth/index.d.cts.map +1 -0
  16. package/dist/auth/index.d.ts +20 -15
  17. package/dist/auth/index.d.ts.map +1 -0
  18. package/dist/auth/index.js +35 -39
  19. package/dist/auth/index.js.map +1 -0
  20. package/dist/auth/types.d.cts +294 -0
  21. package/dist/auth/types.d.cts.map +1 -0
  22. package/dist/auth/types.d.ts +162 -165
  23. package/dist/auth/types.d.ts.map +1 -0
  24. package/dist/client.cjs +1110 -1294
  25. package/dist/client.cjs.map +1 -0
  26. package/dist/client.d.cts +697 -0
  27. package/dist/client.d.cts.map +1 -0
  28. package/dist/client.d.ts +656 -639
  29. package/dist/client.d.ts.map +1 -0
  30. package/dist/client.js +1101 -1281
  31. package/dist/client.js.map +1 -0
  32. package/dist/index.cjs +6 -8
  33. package/dist/index.d.cts +7 -0
  34. package/dist/index.d.ts +7 -7
  35. package/dist/index.js +4 -2
  36. package/dist/logging/index.cjs +30 -31
  37. package/dist/logging/index.cjs.map +1 -0
  38. package/dist/logging/index.d.cts +47 -0
  39. package/dist/logging/index.d.cts.map +1 -0
  40. package/dist/logging/index.d.ts +20 -16
  41. package/dist/logging/index.d.ts.map +1 -0
  42. package/dist/logging/index.js +31 -29
  43. package/dist/logging/index.js.map +1 -0
  44. package/dist/react/index.cjs +5 -7
  45. package/dist/react/index.d.cts +4 -0
  46. package/dist/react/index.d.ts +4 -3
  47. package/dist/react/index.js +4 -2
  48. package/dist/react/stream.cjs +14 -15
  49. package/dist/react/stream.cjs.map +1 -0
  50. package/dist/react/stream.custom.cjs +126 -145
  51. package/dist/react/stream.custom.cjs.map +1 -0
  52. package/dist/react/stream.custom.d.cts +39 -0
  53. package/dist/react/stream.custom.d.cts.map +1 -0
  54. package/dist/react/stream.custom.d.ts +35 -37
  55. package/dist/react/stream.custom.d.ts.map +1 -0
  56. package/dist/react/stream.custom.js +122 -137
  57. package/dist/react/stream.custom.js.map +1 -0
  58. package/dist/react/stream.d.cts +73 -0
  59. package/dist/react/stream.d.cts.map +1 -0
  60. package/dist/react/stream.d.ts +21 -15
  61. package/dist/react/stream.d.ts.map +1 -0
  62. package/dist/react/stream.js +12 -11
  63. package/dist/react/stream.js.map +1 -0
  64. package/dist/react/stream.lgp.cjs +438 -498
  65. package/dist/react/stream.lgp.cjs.map +1 -0
  66. package/dist/react/stream.lgp.js +433 -490
  67. package/dist/react/stream.lgp.js.map +1 -0
  68. package/dist/react/thread.cjs +18 -15
  69. package/dist/react/thread.cjs.map +1 -0
  70. package/dist/react/thread.js +19 -13
  71. package/dist/react/thread.js.map +1 -0
  72. package/dist/react/types.d.cts +356 -0
  73. package/dist/react/types.d.cts.map +1 -0
  74. package/dist/react/types.d.ts +334 -329
  75. package/dist/react/types.d.ts.map +1 -0
  76. package/dist/react-ui/client.cjs +123 -184
  77. package/dist/react-ui/client.cjs.map +1 -0
  78. package/dist/react-ui/client.d.cts +90 -0
  79. package/dist/react-ui/client.d.cts.map +1 -0
  80. package/dist/react-ui/client.d.ts +67 -51
  81. package/dist/react-ui/client.d.ts.map +1 -0
  82. package/dist/react-ui/client.js +118 -143
  83. package/dist/react-ui/client.js.map +1 -0
  84. package/dist/react-ui/index.cjs +14 -13
  85. package/dist/react-ui/index.cjs.map +1 -0
  86. package/dist/react-ui/index.d.cts +3 -0
  87. package/dist/react-ui/index.d.ts +3 -2
  88. package/dist/react-ui/index.js +8 -3
  89. package/dist/react-ui/index.js.map +1 -0
  90. package/dist/react-ui/server/index.cjs +5 -7
  91. package/dist/react-ui/server/index.d.cts +3 -0
  92. package/dist/react-ui/server/index.d.ts +3 -2
  93. package/dist/react-ui/server/index.js +4 -2
  94. package/dist/react-ui/server/server.cjs +53 -44
  95. package/dist/react-ui/server/server.cjs.map +1 -0
  96. package/dist/react-ui/server/server.d.cts +55 -0
  97. package/dist/react-ui/server/server.d.cts.map +1 -0
  98. package/dist/react-ui/server/server.d.ts +43 -39
  99. package/dist/react-ui/server/server.d.ts.map +1 -0
  100. package/dist/react-ui/server/server.js +54 -42
  101. package/dist/react-ui/server/server.js.map +1 -0
  102. package/dist/react-ui/types.cjs +32 -36
  103. package/dist/react-ui/types.cjs.map +1 -0
  104. package/dist/react-ui/types.d.cts +25 -0
  105. package/dist/react-ui/types.d.cts.map +1 -0
  106. package/dist/react-ui/types.d.ts +23 -19
  107. package/dist/react-ui/types.d.ts.map +1 -0
  108. package/dist/react-ui/types.js +32 -34
  109. package/dist/react-ui/types.js.map +1 -0
  110. package/dist/schema.d.cts +278 -0
  111. package/dist/schema.d.cts.map +1 -0
  112. package/dist/schema.d.ts +250 -242
  113. package/dist/schema.d.ts.map +1 -0
  114. package/dist/singletons/fetch.cjs +16 -20
  115. package/dist/singletons/fetch.cjs.map +1 -0
  116. package/dist/singletons/fetch.d.cts +14 -0
  117. package/dist/singletons/fetch.d.cts.map +1 -0
  118. package/dist/singletons/fetch.d.ts +5 -2
  119. package/dist/singletons/fetch.d.ts.map +1 -0
  120. package/dist/singletons/fetch.js +16 -17
  121. package/dist/singletons/fetch.js.map +1 -0
  122. package/dist/types.d.cts +187 -0
  123. package/dist/types.d.cts.map +1 -0
  124. package/dist/types.d.ts +178 -173
  125. package/dist/types.d.ts.map +1 -0
  126. package/dist/types.messages.d.cts +91 -0
  127. package/dist/types.messages.d.cts.map +1 -0
  128. package/dist/types.messages.d.ts +71 -66
  129. package/dist/types.messages.d.ts.map +1 -0
  130. package/dist/types.stream.d.cts +235 -0
  131. package/dist/types.stream.d.cts.map +1 -0
  132. package/dist/types.stream.d.ts +149 -142
  133. package/dist/types.stream.d.ts.map +1 -0
  134. package/dist/ui/branching.cjs +145 -141
  135. package/dist/ui/branching.cjs.map +1 -0
  136. package/dist/ui/branching.d.cts +22 -0
  137. package/dist/ui/branching.d.cts.map +1 -0
  138. package/dist/ui/branching.d.ts +17 -30
  139. package/dist/ui/branching.d.ts.map +1 -0
  140. package/dist/ui/branching.js +147 -139
  141. package/dist/ui/branching.js.map +1 -0
  142. package/dist/ui/errors.cjs +14 -12
  143. package/dist/ui/errors.cjs.map +1 -0
  144. package/dist/ui/errors.js +14 -9
  145. package/dist/ui/errors.js.map +1 -0
  146. package/dist/ui/manager.cjs +156 -232
  147. package/dist/ui/manager.cjs.map +1 -0
  148. package/dist/ui/manager.js +156 -228
  149. package/dist/ui/manager.js.map +1 -0
  150. package/dist/ui/messages.cjs +55 -69
  151. package/dist/ui/messages.cjs.map +1 -0
  152. package/dist/ui/messages.js +55 -66
  153. package/dist/ui/messages.js.map +1 -0
  154. package/dist/ui/utils.cjs +10 -10
  155. package/dist/ui/utils.cjs.map +1 -0
  156. package/dist/ui/utils.js +10 -8
  157. package/dist/ui/utils.js.map +1 -0
  158. package/dist/utils/async_caller.cjs +103 -185
  159. package/dist/utils/async_caller.cjs.map +1 -0
  160. package/dist/utils/async_caller.d.cts +53 -0
  161. package/dist/utils/async_caller.d.cts.map +1 -0
  162. package/dist/utils/async_caller.d.ts +36 -31
  163. package/dist/utils/async_caller.d.ts.map +1 -0
  164. package/dist/utils/async_caller.js +101 -177
  165. package/dist/utils/async_caller.js.map +1 -0
  166. package/dist/utils/env.cjs +11 -13
  167. package/dist/utils/env.cjs.map +1 -0
  168. package/dist/utils/env.js +11 -11
  169. package/dist/utils/env.js.map +1 -0
  170. package/dist/utils/signals.cjs +18 -19
  171. package/dist/utils/signals.cjs.map +1 -0
  172. package/dist/utils/signals.js +18 -17
  173. package/dist/utils/signals.js.map +1 -0
  174. package/dist/utils/sse.cjs +110 -140
  175. package/dist/utils/sse.cjs.map +1 -0
  176. package/dist/utils/sse.js +110 -138
  177. package/dist/utils/sse.js.map +1 -0
  178. package/dist/utils/stream.cjs +90 -114
  179. package/dist/utils/stream.cjs.map +1 -0
  180. package/dist/utils/stream.js +90 -111
  181. package/dist/utils/stream.js.map +1 -0
  182. package/package.json +73 -81
  183. package/auth.cjs +0 -1
  184. package/auth.d.cts +0 -1
  185. package/auth.d.ts +0 -1
  186. package/auth.js +0 -1
  187. package/client.cjs +0 -1
  188. package/client.d.cts +0 -1
  189. package/client.d.ts +0 -1
  190. package/client.js +0 -1
  191. package/dist/auth/types.cjs +0 -2
  192. package/dist/auth/types.js +0 -1
  193. package/dist/react/stream.lgp.d.ts +0 -7
  194. package/dist/react/thread.d.ts +0 -4
  195. package/dist/react/types.cjs +0 -2
  196. package/dist/react/types.js +0 -1
  197. package/dist/schema.cjs +0 -2
  198. package/dist/schema.js +0 -1
  199. package/dist/types.cjs +0 -2
  200. package/dist/types.js +0 -1
  201. package/dist/types.messages.cjs +0 -2
  202. package/dist/types.messages.js +0 -1
  203. package/dist/types.stream.cjs +0 -2
  204. package/dist/types.stream.js +0 -1
  205. package/dist/ui/branching.test.cjs +0 -370
  206. package/dist/ui/branching.test.d.ts +0 -1
  207. package/dist/ui/branching.test.js +0 -368
  208. package/dist/ui/errors.d.ts +0 -12
  209. package/dist/ui/manager.d.ts +0 -87
  210. package/dist/ui/messages.d.ts +0 -18
  211. package/dist/ui/utils.d.ts +0 -2
  212. package/dist/utils/env.d.ts +0 -1
  213. package/dist/utils/signals.d.ts +0 -1
  214. package/dist/utils/sse.d.ts +0 -8
  215. package/dist/utils/stream.d.ts +0 -13
  216. package/index.cjs +0 -1
  217. package/index.d.cts +0 -1
  218. package/index.d.ts +0 -1
  219. package/index.js +0 -1
  220. package/logging.cjs +0 -1
  221. package/logging.d.cts +0 -1
  222. package/logging.d.ts +0 -1
  223. package/logging.js +0 -1
  224. package/react-ui/server.cjs +0 -1
  225. package/react-ui/server.d.cts +0 -1
  226. package/react-ui/server.d.ts +0 -1
  227. package/react-ui/server.js +0 -1
  228. package/react-ui.cjs +0 -1
  229. package/react-ui.d.cts +0 -1
  230. package/react-ui.d.ts +0 -1
  231. package/react-ui.js +0 -1
  232. package/react.cjs +0 -1
  233. package/react.d.cts +0 -1
  234. package/react.d.ts +0 -1
  235. package/react.js +0 -1
@@ -1,71 +1,60 @@
1
- import { RemoveMessage, convertToChunk, coerceMessageLikeToMessage, isBaseMessageChunk, } from "@langchain/core/messages";
1
+ import { RemoveMessage, coerceMessageLikeToMessage, convertToChunk, isBaseMessageChunk } from "@langchain/core/messages";
2
+
3
+ //#region src/ui/messages.ts
2
4
  function tryConvertToChunk(message) {
3
- try {
4
- return convertToChunk(message);
5
- }
6
- catch {
7
- return null;
8
- }
5
+ try {
6
+ return convertToChunk(message);
7
+ } catch {
8
+ return null;
9
+ }
9
10
  }
10
11
  function tryCoerceMessageLikeToMessage(message) {
11
- // TODO: this is unnecessary with https://github.com/langchain-ai/langchainjs/pull/8941
12
- if (message.type === "remove" && message.id != null) {
13
- return new RemoveMessage({ ...message, id: message.id });
14
- }
15
- return coerceMessageLikeToMessage(message);
12
+ if (message.type === "remove" && message.id != null) return new RemoveMessage({
13
+ ...message,
14
+ id: message.id
15
+ });
16
+ return coerceMessageLikeToMessage(message);
16
17
  }
17
- export class MessageTupleManager {
18
- constructor() {
19
- Object.defineProperty(this, "chunks", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: {}
24
- });
25
- this.chunks = {};
26
- }
27
- add(serialized, metadata) {
28
- // TODO: this is sometimes sent from the API
29
- // figure out how to prevent this or move this to LC.js
30
- if (serialized.type.endsWith("MessageChunk")) {
31
- // eslint-disable-next-line no-param-reassign
32
- serialized.type = serialized.type
33
- .slice(0, -"MessageChunk".length)
34
- .toLowerCase();
35
- }
36
- const message = tryCoerceMessageLikeToMessage(serialized);
37
- const chunk = tryConvertToChunk(message);
38
- const { id } = chunk ?? message;
39
- if (!id) {
40
- console.warn("No message ID found for chunk, ignoring in state", serialized);
41
- return null;
42
- }
43
- this.chunks[id] ??= {};
44
- this.chunks[id].metadata = metadata ?? this.chunks[id].metadata;
45
- if (chunk) {
46
- const prev = this.chunks[id].chunk;
47
- this.chunks[id].chunk =
48
- (isBaseMessageChunk(prev) ? prev : null)?.concat(chunk) ?? chunk;
49
- }
50
- else {
51
- this.chunks[id].chunk = message;
52
- }
53
- return id;
54
- }
55
- clear() {
56
- this.chunks = {};
57
- }
58
- get(id, defaultIndex) {
59
- if (id == null)
60
- return null;
61
- if (this.chunks[id] == null)
62
- return null;
63
- if (defaultIndex != null)
64
- this.chunks[id].index ??= defaultIndex;
65
- return this.chunks[id];
66
- }
67
- }
68
- export const toMessageDict = (chunk) => {
69
- const { type, data } = chunk.toDict();
70
- return { ...data, type };
18
+ var MessageTupleManager = class {
19
+ chunks = {};
20
+ constructor() {
21
+ this.chunks = {};
22
+ }
23
+ add(serialized, metadata) {
24
+ if (serialized.type.endsWith("MessageChunk")) serialized.type = serialized.type.slice(0, -12).toLowerCase();
25
+ const message = tryCoerceMessageLikeToMessage(serialized);
26
+ const chunk = tryConvertToChunk(message);
27
+ const { id } = chunk ?? message;
28
+ if (!id) {
29
+ console.warn("No message ID found for chunk, ignoring in state", serialized);
30
+ return null;
31
+ }
32
+ this.chunks[id] ??= {};
33
+ this.chunks[id].metadata = metadata ?? this.chunks[id].metadata;
34
+ if (chunk) {
35
+ const prev = this.chunks[id].chunk;
36
+ this.chunks[id].chunk = (isBaseMessageChunk(prev) ? prev : null)?.concat(chunk) ?? chunk;
37
+ } else this.chunks[id].chunk = message;
38
+ return id;
39
+ }
40
+ clear() {
41
+ this.chunks = {};
42
+ }
43
+ get(id, defaultIndex) {
44
+ if (id == null) return null;
45
+ if (this.chunks[id] == null) return null;
46
+ if (defaultIndex != null) this.chunks[id].index ??= defaultIndex;
47
+ return this.chunks[id];
48
+ }
49
+ };
50
+ const toMessageDict = (chunk) => {
51
+ const { type, data } = chunk.toDict();
52
+ return {
53
+ ...data,
54
+ type
55
+ };
71
56
  };
57
+
58
+ //#endregion
59
+ export { MessageTupleManager, toMessageDict };
60
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","names":[],"sources":["../../src/ui/messages.ts"],"sourcesContent":["import {\n type BaseMessage,\n type BaseMessageChunk,\n RemoveMessage,\n convertToChunk,\n coerceMessageLikeToMessage,\n isBaseMessageChunk,\n} from \"@langchain/core/messages\";\n\nimport type { Message } from \"../types.messages.js\";\n\nfunction tryConvertToChunk(message: BaseMessage): BaseMessageChunk | null {\n try {\n return convertToChunk(message);\n } catch {\n return null;\n }\n}\n\nfunction tryCoerceMessageLikeToMessage(message: Message): BaseMessage {\n // TODO: this is unnecessary with https://github.com/langchain-ai/langchainjs/pull/8941\n if (message.type === \"remove\" && message.id != null) {\n return new RemoveMessage({ ...message, id: message.id });\n }\n\n return coerceMessageLikeToMessage(message);\n}\n\nexport class MessageTupleManager {\n chunks: Record<\n string,\n {\n chunk?: BaseMessageChunk | BaseMessage;\n metadata?: Record<string, unknown>;\n index?: number;\n }\n > = {};\n\n constructor() {\n this.chunks = {};\n }\n\n add(\n serialized: Message,\n metadata: Record<string, unknown> | undefined\n ): string | null {\n // TODO: this is sometimes sent from the API\n // figure out how to prevent this or move this to LC.js\n if (serialized.type.endsWith(\"MessageChunk\")) {\n // eslint-disable-next-line no-param-reassign\n serialized.type = serialized.type\n .slice(0, -\"MessageChunk\".length)\n .toLowerCase() as Message[\"type\"];\n }\n\n const message = tryCoerceMessageLikeToMessage(serialized);\n const chunk = tryConvertToChunk(message);\n\n const { id } = chunk ?? message;\n if (!id) {\n console.warn(\n \"No message ID found for chunk, ignoring in state\",\n serialized\n );\n return null;\n }\n\n this.chunks[id] ??= {};\n this.chunks[id].metadata = metadata ?? this.chunks[id].metadata;\n if (chunk) {\n const prev = this.chunks[id].chunk;\n this.chunks[id].chunk =\n (isBaseMessageChunk(prev) ? prev : null)?.concat(chunk) ?? chunk;\n } else {\n this.chunks[id].chunk = message;\n }\n\n return id;\n }\n\n clear() {\n this.chunks = {};\n }\n\n get(id: string | null | undefined, defaultIndex?: number) {\n if (id == null) return null;\n if (this.chunks[id] == null) return null;\n if (defaultIndex != null) this.chunks[id].index ??= defaultIndex;\n return this.chunks[id];\n }\n}\n\nexport const toMessageDict = (chunk: BaseMessage): Message => {\n const { type, data } = chunk.toDict();\n return { ...data, type } as Message;\n};\n"],"mappings":";;;AAWA,SAAS,kBAAkB,SAA+C;AACxE,KAAI;AACF,SAAO,eAAe;SAChB;AACN,SAAO;;;AAIX,SAAS,8BAA8B,SAA+B;AAEpE,KAAI,QAAQ,SAAS,YAAY,QAAQ,MAAM,KAC7C,QAAO,IAAI,cAAc;EAAE,GAAG;EAAS,IAAI,QAAQ;;AAGrD,QAAO,2BAA2B;;AAGpC,IAAa,sBAAb,MAAiC;CAC/B,SAOI;CAEJ,cAAc;AACZ,OAAK,SAAS;;CAGhB,IACE,YACA,UACe;AAGf,MAAI,WAAW,KAAK,SAAS,gBAE3B,YAAW,OAAO,WAAW,KAC1B,MAAM,GAAG,KACT;EAGL,MAAM,UAAU,8BAA8B;EAC9C,MAAM,QAAQ,kBAAkB;EAEhC,MAAM,EAAE,OAAO,SAAS;AACxB,MAAI,CAAC,IAAI;AACP,WAAQ,KACN,oDACA;AAEF,UAAO;;AAGT,OAAK,OAAO,QAAQ;AACpB,OAAK,OAAO,IAAI,WAAW,YAAY,KAAK,OAAO,IAAI;AACvD,MAAI,OAAO;GACT,MAAM,OAAO,KAAK,OAAO,IAAI;AAC7B,QAAK,OAAO,IAAI,SACb,mBAAmB,QAAQ,OAAO,OAAO,OAAO,UAAU;QAE7D,MAAK,OAAO,IAAI,QAAQ;AAG1B,SAAO;;CAGT,QAAQ;AACN,OAAK,SAAS;;CAGhB,IAAI,IAA+B,cAAuB;AACxD,MAAI,MAAM,KAAM,QAAO;AACvB,MAAI,KAAK,OAAO,OAAO,KAAM,QAAO;AACpC,MAAI,gBAAgB,KAAM,MAAK,OAAO,IAAI,UAAU;AACpD,SAAO,KAAK,OAAO;;;AAIvB,MAAa,iBAAiB,UAAgC;CAC5D,MAAM,EAAE,MAAM,SAAS,MAAM;AAC7B,QAAO;EAAE,GAAG;EAAM"}
package/dist/ui/utils.cjs CHANGED
@@ -1,14 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unique = unique;
4
- exports.findLast = findLast;
1
+
2
+ //#region src/ui/utils.ts
5
3
  function unique(array) {
6
- return [...new Set(array)];
4
+ return [...new Set(array)];
7
5
  }
8
6
  function findLast(array, predicate) {
9
- for (let i = array.length - 1; i >= 0; i -= 1) {
10
- if (predicate(array[i]))
11
- return array[i];
12
- }
13
- return undefined;
7
+ for (let i = array.length - 1; i >= 0; i -= 1) if (predicate(array[i])) return array[i];
8
+ return void 0;
14
9
  }
10
+
11
+ //#endregion
12
+ exports.findLast = findLast;
13
+ exports.unique = unique;
14
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","names":[],"sources":["../../src/ui/utils.ts"],"sourcesContent":["export function unique<T>(array: T[]) {\n return [...new Set(array)] as T[];\n}\n\nexport function findLast<T>(array: T[], predicate: (item: T) => boolean) {\n for (let i = array.length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) return array[i];\n }\n return undefined;\n}\n"],"mappings":";;AAAA,SAAgB,OAAU,OAAY;AACpC,QAAO,CAAC,GAAG,IAAI,IAAI;;AAGrB,SAAgB,SAAY,OAAY,WAAiC;AACvE,MAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,EAC1C,KAAI,UAAU,MAAM,IAAK,QAAO,MAAM;AAExC,QAAO"}
package/dist/ui/utils.js CHANGED
@@ -1,10 +1,12 @@
1
- export function unique(array) {
2
- return [...new Set(array)];
1
+ //#region src/ui/utils.ts
2
+ function unique(array) {
3
+ return [...new Set(array)];
3
4
  }
4
- export function findLast(array, predicate) {
5
- for (let i = array.length - 1; i >= 0; i -= 1) {
6
- if (predicate(array[i]))
7
- return array[i];
8
- }
9
- return undefined;
5
+ function findLast(array, predicate) {
6
+ for (let i = array.length - 1; i >= 0; i -= 1) if (predicate(array[i])) return array[i];
7
+ return void 0;
10
8
  }
9
+
10
+ //#endregion
11
+ export { findLast, unique };
12
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../src/ui/utils.ts"],"sourcesContent":["export function unique<T>(array: T[]) {\n return [...new Set(array)] as T[];\n}\n\nexport function findLast<T>(array: T[], predicate: (item: T) => boolean) {\n for (let i = array.length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) return array[i];\n }\n return undefined;\n}\n"],"mappings":";AAAA,SAAgB,OAAU,OAAY;AACpC,QAAO,CAAC,GAAG,IAAI,IAAI;;AAGrB,SAAgB,SAAY,OAAY,WAAiC;AACvE,MAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,EAC1C,KAAI,UAAU,MAAM,IAAK,QAAO,MAAM;AAExC,QAAO"}
@@ -1,193 +1,111 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AsyncCaller = void 0;
7
- const p_retry_1 = __importDefault(require("p-retry"));
8
- const p_queue_1 = __importDefault(require("p-queue"));
9
- const fetch_js_1 = require("../singletons/fetch.cjs");
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_fetch = require('../singletons/fetch.cjs');
3
+ const p_retry = require_rolldown_runtime.__toESM(require("p-retry"));
4
+ const p_queue = require_rolldown_runtime.__toESM(require("p-queue"));
5
+
6
+ //#region src/utils/async_caller.ts
10
7
  const STATUS_NO_RETRY = [
11
- 400, // Bad Request
12
- 401, // Unauthorized
13
- 402, // Payment required
14
- 403, // Forbidden
15
- 404, // Not Found
16
- 405, // Method Not Allowed
17
- 406, // Not Acceptable
18
- 407, // Proxy Authentication Required
19
- 408, // Request Timeout
20
- 409, // Conflict
21
- 422, // Unprocessable Entity
8
+ 400,
9
+ 401,
10
+ 402,
11
+ 403,
12
+ 404,
13
+ 405,
14
+ 406,
15
+ 407,
16
+ 408,
17
+ 409,
18
+ 422
22
19
  ];
23
20
  /**
24
- * Do not rely on globalThis.Response, rather just
25
- * do duck typing
26
- */
21
+ * Do not rely on globalThis.Response, rather just
22
+ * do duck typing
23
+ */
27
24
  function isResponse(x) {
28
- if (x == null || typeof x !== "object")
29
- return false;
30
- return "status" in x && "statusText" in x && "text" in x;
25
+ if (x == null || typeof x !== "object") return false;
26
+ return "status" in x && "statusText" in x && "text" in x;
31
27
  }
32
28
  /**
33
- * Utility error to properly handle failed requests
34
- */
35
- class HTTPError extends Error {
36
- constructor(status, message, response) {
37
- super(`HTTP ${status}: ${message}`);
38
- Object.defineProperty(this, "status", {
39
- enumerable: true,
40
- configurable: true,
41
- writable: true,
42
- value: void 0
43
- });
44
- Object.defineProperty(this, "text", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: void 0
49
- });
50
- Object.defineProperty(this, "response", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: void 0
55
- });
56
- this.status = status;
57
- this.text = message;
58
- this.response = response;
59
- }
60
- static async fromResponse(response, options) {
61
- try {
62
- return new HTTPError(response.status, await response.text(), options?.includeResponse ? response : undefined);
63
- }
64
- catch {
65
- return new HTTPError(response.status, response.statusText, options?.includeResponse ? response : undefined);
66
- }
67
- }
68
- }
29
+ * Utility error to properly handle failed requests
30
+ */
31
+ var HTTPError = class HTTPError extends Error {
32
+ status;
33
+ text;
34
+ response;
35
+ constructor(status, message, response) {
36
+ super(`HTTP ${status}: ${message}`);
37
+ this.status = status;
38
+ this.text = message;
39
+ this.response = response;
40
+ }
41
+ static async fromResponse(response, options) {
42
+ try {
43
+ return new HTTPError(response.status, await response.text(), options?.includeResponse ? response : void 0);
44
+ } catch {
45
+ return new HTTPError(response.status, response.statusText, options?.includeResponse ? response : void 0);
46
+ }
47
+ }
48
+ };
69
49
  /**
70
- * A class that can be used to make async calls with concurrency and retry logic.
71
- *
72
- * This is useful for making calls to any kind of "expensive" external resource,
73
- * be it because it's rate-limited, subject to network issues, etc.
74
- *
75
- * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
76
- * to `Infinity`. This means that by default, all calls will be made in parallel.
77
- *
78
- * Retries are limited by the `maxRetries` parameter, which defaults to 5. This
79
- * means that by default, each call will be retried up to 5 times, with an
80
- * exponential backoff between each attempt.
81
- */
82
- class AsyncCaller {
83
- constructor(params) {
84
- Object.defineProperty(this, "maxConcurrency", {
85
- enumerable: true,
86
- configurable: true,
87
- writable: true,
88
- value: void 0
89
- });
90
- Object.defineProperty(this, "maxRetries", {
91
- enumerable: true,
92
- configurable: true,
93
- writable: true,
94
- value: void 0
95
- });
96
- Object.defineProperty(this, "queue", {
97
- enumerable: true,
98
- configurable: true,
99
- writable: true,
100
- value: void 0
101
- });
102
- Object.defineProperty(this, "onFailedResponseHook", {
103
- enumerable: true,
104
- configurable: true,
105
- writable: true,
106
- value: void 0
107
- });
108
- Object.defineProperty(this, "customFetch", {
109
- enumerable: true,
110
- configurable: true,
111
- writable: true,
112
- value: void 0
113
- });
114
- this.maxConcurrency = params.maxConcurrency ?? Infinity;
115
- this.maxRetries = params.maxRetries ?? 4;
116
- if ("default" in p_queue_1.default) {
117
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- this.queue = new p_queue_1.default.default({
119
- concurrency: this.maxConcurrency,
120
- });
121
- }
122
- else {
123
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
- this.queue = new p_queue_1.default({ concurrency: this.maxConcurrency });
125
- }
126
- this.onFailedResponseHook = params?.onFailedResponseHook;
127
- this.customFetch = params.fetch;
128
- }
129
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
- call(callable, ...args) {
131
- const { onFailedResponseHook } = this;
132
- return this.queue.add(() => (0, p_retry_1.default)(() => callable(...args).catch(async (error) => {
133
- // eslint-disable-next-line no-instanceof/no-instanceof
134
- if (error instanceof Error) {
135
- throw error;
136
- }
137
- else if (isResponse(error)) {
138
- throw await HTTPError.fromResponse(error, {
139
- includeResponse: !!onFailedResponseHook,
140
- });
141
- }
142
- else {
143
- throw new Error(error);
144
- }
145
- }), {
146
- async onFailedAttempt(error) {
147
- if (error.message.startsWith("Cancel") ||
148
- error.message.startsWith("TimeoutError") ||
149
- error.message.startsWith("AbortError")) {
150
- throw error;
151
- }
152
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
153
- if (error?.code === "ECONNABORTED") {
154
- throw error;
155
- }
156
- // eslint-disable-next-line no-instanceof/no-instanceof
157
- if (error instanceof HTTPError) {
158
- if (STATUS_NO_RETRY.includes(error.status)) {
159
- throw error;
160
- }
161
- if (onFailedResponseHook && error.response) {
162
- await onFailedResponseHook(error.response);
163
- }
164
- }
165
- },
166
- // If needed we can change some of the defaults here,
167
- // but they're quite sensible.
168
- retries: this.maxRetries,
169
- randomize: true,
170
- }), { throwOnTimeout: true });
171
- }
172
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
173
- callWithOptions(options, callable, ...args) {
174
- // Note this doesn't cancel the underlying request,
175
- // when available prefer to use the signal option of the underlying call
176
- if (options.signal) {
177
- return Promise.race([
178
- this.call(callable, ...args),
179
- new Promise((_, reject) => {
180
- options.signal?.addEventListener("abort", () => {
181
- reject(new Error("AbortError"));
182
- });
183
- }),
184
- ]);
185
- }
186
- return this.call(callable, ...args);
187
- }
188
- fetch(...args) {
189
- const fetchFn = this.customFetch ?? (0, fetch_js_1._getFetchImplementation)();
190
- return this.call(() => fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res))));
191
- }
192
- }
50
+ * A class that can be used to make async calls with concurrency and retry logic.
51
+ *
52
+ * This is useful for making calls to any kind of "expensive" external resource,
53
+ * be it because it's rate-limited, subject to network issues, etc.
54
+ *
55
+ * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
56
+ * to `Infinity`. This means that by default, all calls will be made in parallel.
57
+ *
58
+ * Retries are limited by the `maxRetries` parameter, which defaults to 5. This
59
+ * means that by default, each call will be retried up to 5 times, with an
60
+ * exponential backoff between each attempt.
61
+ */
62
+ var AsyncCaller = class {
63
+ maxConcurrency;
64
+ maxRetries;
65
+ queue;
66
+ onFailedResponseHook;
67
+ customFetch;
68
+ constructor(params) {
69
+ this.maxConcurrency = params.maxConcurrency ?? Infinity;
70
+ this.maxRetries = params.maxRetries ?? 4;
71
+ if ("default" in p_queue.default) this.queue = new p_queue.default.default({ concurrency: this.maxConcurrency });
72
+ else this.queue = new p_queue.default({ concurrency: this.maxConcurrency });
73
+ this.onFailedResponseHook = params?.onFailedResponseHook;
74
+ this.customFetch = params.fetch;
75
+ }
76
+ call(callable, ...args) {
77
+ const { onFailedResponseHook } = this;
78
+ return this.queue.add(() => (0, p_retry.default)(() => callable(...args).catch(async (error) => {
79
+ if (error instanceof Error) throw error;
80
+ else if (isResponse(error)) throw await HTTPError.fromResponse(error, { includeResponse: !!onFailedResponseHook });
81
+ else throw new Error(error);
82
+ }), {
83
+ async onFailedAttempt(error) {
84
+ if (error.message.startsWith("Cancel") || error.message.startsWith("TimeoutError") || error.message.startsWith("AbortError")) throw error;
85
+ if (error?.code === "ECONNABORTED") throw error;
86
+ if (error instanceof HTTPError) {
87
+ if (STATUS_NO_RETRY.includes(error.status)) throw error;
88
+ if (onFailedResponseHook && error.response) await onFailedResponseHook(error.response);
89
+ }
90
+ },
91
+ retries: this.maxRetries,
92
+ randomize: true
93
+ }), { throwOnTimeout: true });
94
+ }
95
+ callWithOptions(options, callable, ...args) {
96
+ if (options.signal) return Promise.race([this.call(callable, ...args), new Promise((_, reject) => {
97
+ options.signal?.addEventListener("abort", () => {
98
+ reject(/* @__PURE__ */ new Error("AbortError"));
99
+ });
100
+ })]);
101
+ return this.call(callable, ...args);
102
+ }
103
+ fetch(...args) {
104
+ const fetchFn = this.customFetch ?? require_fetch._getFetchImplementation();
105
+ return this.call(() => fetchFn(...args).then((res) => res.ok ? res : Promise.reject(res)));
106
+ }
107
+ };
108
+
109
+ //#endregion
193
110
  exports.AsyncCaller = AsyncCaller;
111
+ //# sourceMappingURL=async_caller.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async_caller.cjs","names":["PQueueMod","_getFetchImplementation"],"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,aAAaA,gBAEf,MAAK,QAAQ,IAAKA,gBAAU,QAAgB,EAC1C,aAAa,KAAK;MAIpB,MAAK,QAAQ,IAAKA,gBAAkB,EAAE,aAAa,KAAK;AAE1D,OAAK,uBAAuB,QAAQ;AACpC,OAAK,cAAc,OAAO;;CAI5B,KACE,UACA,GAAG,MAC8B;EACjC,MAAM,EAAE,yBAAyB;AACjC,SAAO,KAAK,MAAM,qCAIV,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,eAAgBC;AACvB,SAAO,KAAK,WACV,QAAQ,GAAG,MAAM,MAAM,QAAS,IAAI,KAAK,MAAM,QAAQ,OAAO"}
@@ -0,0 +1,53 @@
1
+ //#region src/utils/async_caller.d.ts
2
+ type ResponseCallback = (response?: Response) => Promise<boolean>;
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
21
+ }
22
+ interface AsyncCallerCallOptions {
23
+ signal?: AbortSignal;
24
+ }
25
+ /**
26
+ * A class that can be used to make async calls with concurrency and retry logic.
27
+ *
28
+ * This is useful for making calls to any kind of "expensive" external resource,
29
+ * be it because it's rate-limited, subject to network issues, etc.
30
+ *
31
+ * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
32
+ * to `Infinity`. This means that by default, all calls will be made in parallel.
33
+ *
34
+ * Retries are limited by the `maxRetries` parameter, which defaults to 5. This
35
+ * means that by default, each call will be retried up to 5 times, with an
36
+ * exponential backoff between each attempt.
37
+ */
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>;
50
+ }
51
+ //#endregion
52
+ export { AsyncCaller, AsyncCallerParams };
53
+ //# sourceMappingURL=async_caller.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async_caller.d.cts","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"}