@aztec/foundation 0.0.0-test.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 (736) hide show
  1. package/README.md +1 -0
  2. package/dest/array/array.d.ts +71 -0
  3. package/dest/array/array.d.ts.map +1 -0
  4. package/dest/array/array.js +100 -0
  5. package/dest/array/index.d.ts +2 -0
  6. package/dest/array/index.d.ts.map +1 -0
  7. package/dest/array/index.js +1 -0
  8. package/dest/async-map/index.d.ts +13 -0
  9. package/dest/async-map/index.d.ts.map +1 -0
  10. package/dest/async-map/index.js +17 -0
  11. package/dest/async-pool/index.d.ts +3 -0
  12. package/dest/async-pool/index.d.ts.map +1 -0
  13. package/dest/async-pool/index.js +47 -0
  14. package/dest/bigint-buffer/index.d.ts +42 -0
  15. package/dest/bigint-buffer/index.d.ts.map +1 -0
  16. package/dest/bigint-buffer/index.js +76 -0
  17. package/dest/buffer/buffer32.d.ts +91 -0
  18. package/dest/buffer/buffer32.d.ts.map +1 -0
  19. package/dest/buffer/buffer32.js +115 -0
  20. package/dest/buffer/index.d.ts +2 -0
  21. package/dest/buffer/index.d.ts.map +1 -0
  22. package/dest/buffer/index.js +1 -0
  23. package/dest/collection/array.d.ts +101 -0
  24. package/dest/collection/array.d.ts.map +1 -0
  25. package/dest/collection/array.js +164 -0
  26. package/dest/collection/index.d.ts +3 -0
  27. package/dest/collection/index.d.ts.map +1 -0
  28. package/dest/collection/index.js +2 -0
  29. package/dest/collection/object.d.ts +14 -0
  30. package/dest/collection/object.d.ts.map +1 -0
  31. package/dest/collection/object.js +32 -0
  32. package/dest/committable/committable.d.ts +28 -0
  33. package/dest/committable/committable.d.ts.map +1 -0
  34. package/dest/committable/committable.js +36 -0
  35. package/dest/committable/index.d.ts +2 -0
  36. package/dest/committable/index.d.ts.map +1 -0
  37. package/dest/committable/index.js +1 -0
  38. package/dest/config/env_var.d.ts +2 -0
  39. package/dest/config/env_var.d.ts.map +1 -0
  40. package/dest/config/env_var.js +1 -0
  41. package/dest/config/index.d.ts +66 -0
  42. package/dest/config/index.d.ts.map +1 -0
  43. package/dest/config/index.js +125 -0
  44. package/dest/crypto/aes128/index.d.ts +34 -0
  45. package/dest/crypto/aes128/index.d.ts.map +1 -0
  46. package/dest/crypto/aes128/index.js +49 -0
  47. package/dest/crypto/ecdsa/index.d.ts +39 -0
  48. package/dest/crypto/ecdsa/index.d.ts.map +1 -0
  49. package/dest/crypto/ecdsa/index.js +88 -0
  50. package/dest/crypto/ecdsa/signature.d.ts +71 -0
  51. package/dest/crypto/ecdsa/signature.d.ts.map +1 -0
  52. package/dest/crypto/ecdsa/signature.js +92 -0
  53. package/dest/crypto/grumpkin/index.d.ts +47 -0
  54. package/dest/crypto/grumpkin/index.d.ts.map +1 -0
  55. package/dest/crypto/grumpkin/index.js +154 -0
  56. package/dest/crypto/index.d.ts +15 -0
  57. package/dest/crypto/index.d.ts.map +1 -0
  58. package/dest/crypto/index.js +14 -0
  59. package/dest/crypto/keccak/index.d.ts +28 -0
  60. package/dest/crypto/keccak/index.d.ts.map +1 -0
  61. package/dest/crypto/keccak/index.js +248 -0
  62. package/dest/crypto/keys/index.d.ts +5 -0
  63. package/dest/crypto/keys/index.d.ts.map +1 -0
  64. package/dest/crypto/keys/index.js +7 -0
  65. package/dest/crypto/pedersen/index.d.ts +2 -0
  66. package/dest/crypto/pedersen/index.d.ts.map +1 -0
  67. package/dest/crypto/pedersen/index.js +1 -0
  68. package/dest/crypto/pedersen/pedersen.elliptic.d.ts +13 -0
  69. package/dest/crypto/pedersen/pedersen.elliptic.d.ts.map +1 -0
  70. package/dest/crypto/pedersen/pedersen.elliptic.js +582 -0
  71. package/dest/crypto/pedersen/pedersen.noble.d.ts +11 -0
  72. package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -0
  73. package/dest/crypto/pedersen/pedersen.noble.js +558 -0
  74. package/dest/crypto/pedersen/pedersen.wasm.d.ts +21 -0
  75. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -0
  76. package/dest/crypto/pedersen/pedersen.wasm.js +41 -0
  77. package/dest/crypto/poseidon/index.d.ts +26 -0
  78. package/dest/crypto/poseidon/index.d.ts.map +1 -0
  79. package/dest/crypto/poseidon/index.js +58 -0
  80. package/dest/crypto/random/index.d.ts +25 -0
  81. package/dest/crypto/random/index.d.ts.map +1 -0
  82. package/dest/crypto/random/index.js +70 -0
  83. package/dest/crypto/random/randomness_singleton.d.ts +25 -0
  84. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -0
  85. package/dest/crypto/random/randomness_singleton.js +55 -0
  86. package/dest/crypto/schnorr/index.d.ts +30 -0
  87. package/dest/crypto/schnorr/index.d.ts.map +1 -0
  88. package/dest/crypto/schnorr/index.js +68 -0
  89. package/dest/crypto/schnorr/signature.d.ts +70 -0
  90. package/dest/crypto/schnorr/signature.d.ts.map +1 -0
  91. package/dest/crypto/schnorr/signature.js +93 -0
  92. package/dest/crypto/secp256k1/index.d.ts +32 -0
  93. package/dest/crypto/secp256k1/index.d.ts.map +1 -0
  94. package/dest/crypto/secp256k1/index.js +116 -0
  95. package/dest/crypto/secp256k1-signer/index.d.ts +3 -0
  96. package/dest/crypto/secp256k1-signer/index.d.ts.map +1 -0
  97. package/dest/crypto/secp256k1-signer/index.js +2 -0
  98. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +24 -0
  99. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -0
  100. package/dest/crypto/secp256k1-signer/secp256k1_signer.js +30 -0
  101. package/dest/crypto/secp256k1-signer/utils.d.ts +40 -0
  102. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -0
  103. package/dest/crypto/secp256k1-signer/utils.js +84 -0
  104. package/dest/crypto/serialize.d.ts +53 -0
  105. package/dest/crypto/serialize.d.ts.map +1 -0
  106. package/dest/crypto/serialize.js +68 -0
  107. package/dest/crypto/sha256/index.d.ts +20 -0
  108. package/dest/crypto/sha256/index.d.ts.map +1 -0
  109. package/dest/crypto/sha256/index.js +166 -0
  110. package/dest/crypto/sha512/index.d.ts +11 -0
  111. package/dest/crypto/sha512/index.d.ts.map +1 -0
  112. package/dest/crypto/sha512/index.js +12 -0
  113. package/dest/crypto/signature/index.d.ts +19 -0
  114. package/dest/crypto/signature/index.d.ts.map +1 -0
  115. package/dest/crypto/signature/index.js +3 -0
  116. package/dest/crypto/sync/index.d.ts +3 -0
  117. package/dest/crypto/sync/index.d.ts.map +1 -0
  118. package/dest/crypto/sync/index.js +4 -0
  119. package/dest/crypto/sync/pedersen/index.d.ts +21 -0
  120. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -0
  121. package/dest/crypto/sync/pedersen/index.js +38 -0
  122. package/dest/crypto/sync/poseidon/index.d.ts +26 -0
  123. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -0
  124. package/dest/crypto/sync/poseidon/index.js +53 -0
  125. package/dest/decorators/index.d.ts +2 -0
  126. package/dest/decorators/index.d.ts.map +1 -0
  127. package/dest/decorators/index.js +1 -0
  128. package/dest/decorators/memoize.d.ts +2 -0
  129. package/dest/decorators/memoize.d.ts.map +1 -0
  130. package/dest/decorators/memoize.js +11 -0
  131. package/dest/error/index.d.ts +21 -0
  132. package/dest/error/index.d.ts.map +1 -0
  133. package/dest/error/index.js +17 -0
  134. package/dest/eth-address/index.d.ts +134 -0
  135. package/dest/eth-address/index.d.ts.map +1 -0
  136. package/dest/eth-address/index.js +198 -0
  137. package/dest/eth-signature/eth_signature.d.ts +62 -0
  138. package/dest/eth-signature/eth_signature.d.ts.map +1 -0
  139. package/dest/eth-signature/eth_signature.js +91 -0
  140. package/dest/eth-signature/index.d.ts +2 -0
  141. package/dest/eth-signature/index.d.ts.map +1 -0
  142. package/dest/eth-signature/index.js +1 -0
  143. package/dest/fields/coordinate.d.ts +68 -0
  144. package/dest/fields/coordinate.d.ts.map +1 -0
  145. package/dest/fields/coordinate.js +96 -0
  146. package/dest/fields/fields.d.ts +176 -0
  147. package/dest/fields/fields.d.ts.map +1 -0
  148. package/dest/fields/fields.js +383 -0
  149. package/dest/fields/index.d.ts +4 -0
  150. package/dest/fields/index.d.ts.map +1 -0
  151. package/dest/fields/index.js +3 -0
  152. package/dest/fields/point.d.ts +175 -0
  153. package/dest/fields/point.d.ts.map +1 -0
  154. package/dest/fields/point.js +260 -0
  155. package/dest/fs/index.d.ts +2 -0
  156. package/dest/fs/index.d.ts.map +1 -0
  157. package/dest/fs/index.js +1 -0
  158. package/dest/fs/run_in_dir.d.ts +2 -0
  159. package/dest/fs/run_in_dir.d.ts.map +1 -0
  160. package/dest/fs/run_in_dir.js +31 -0
  161. package/dest/index.d.ts +31 -0
  162. package/dest/index.d.ts.map +1 -0
  163. package/dest/index.js +31 -0
  164. package/dest/iterable/all.d.ts +9 -0
  165. package/dest/iterable/all.d.ts.map +1 -0
  166. package/dest/iterable/all.js +18 -0
  167. package/dest/iterable/filter.d.ts +10 -0
  168. package/dest/iterable/filter.d.ts.map +1 -0
  169. package/dest/iterable/filter.js +48 -0
  170. package/dest/iterable/index.d.ts +8 -0
  171. package/dest/iterable/index.d.ts.map +1 -0
  172. package/dest/iterable/index.js +7 -0
  173. package/dest/iterable/isAsyncIt.d.ts +7 -0
  174. package/dest/iterable/isAsyncIt.d.ts.map +1 -0
  175. package/dest/iterable/isAsyncIt.js +7 -0
  176. package/dest/iterable/map.d.ts +12 -0
  177. package/dest/iterable/map.d.ts.map +1 -0
  178. package/dest/iterable/map.js +36 -0
  179. package/dest/iterable/peek.d.ts +19 -0
  180. package/dest/iterable/peek.d.ts.map +1 -0
  181. package/dest/iterable/peek.js +33 -0
  182. package/dest/iterable/sort.d.ts +14 -0
  183. package/dest/iterable/sort.d.ts.map +1 -0
  184. package/dest/iterable/sort.js +15 -0
  185. package/dest/iterable/take.d.ts +10 -0
  186. package/dest/iterable/take.d.ts.map +1 -0
  187. package/dest/iterable/take.js +32 -0
  188. package/dest/iterable/toArray.d.ts +2 -0
  189. package/dest/iterable/toArray.d.ts.map +1 -0
  190. package/dest/iterable/toArray.js +7 -0
  191. package/dest/jest/setup.js +7 -0
  192. package/dest/json-rpc/client/fetch.d.ts +32 -0
  193. package/dest/json-rpc/client/fetch.d.ts.map +1 -0
  194. package/dest/json-rpc/client/fetch.js +77 -0
  195. package/dest/json-rpc/client/index.d.ts +3 -0
  196. package/dest/json-rpc/client/index.d.ts.map +1 -0
  197. package/dest/json-rpc/client/index.js +2 -0
  198. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +26 -0
  199. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -0
  200. package/dest/json-rpc/client/safe_json_rpc_client.js +57 -0
  201. package/dest/json-rpc/client/undici.d.ts +5 -0
  202. package/dest/json-rpc/client/undici.d.ts.map +1 -0
  203. package/dest/json-rpc/client/undici.js +63 -0
  204. package/dest/json-rpc/convert.d.ts +27 -0
  205. package/dest/json-rpc/convert.d.ts.map +1 -0
  206. package/dest/json-rpc/convert.js +48 -0
  207. package/dest/json-rpc/fixtures/class_a.d.ts +11 -0
  208. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -0
  209. package/dest/json-rpc/fixtures/class_a.js +20 -0
  210. package/dest/json-rpc/fixtures/class_b.d.ts +11 -0
  211. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -0
  212. package/dest/json-rpc/fixtures/class_b.js +20 -0
  213. package/dest/json-rpc/fixtures/test_state.d.ts +89 -0
  214. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -0
  215. package/dest/json-rpc/fixtures/test_state.js +131 -0
  216. package/dest/json-rpc/index.d.ts +2 -0
  217. package/dest/json-rpc/index.d.ts.map +1 -0
  218. package/dest/json-rpc/index.js +1 -0
  219. package/dest/json-rpc/js_utils.d.ts +13 -0
  220. package/dest/json-rpc/js_utils.d.ts.map +1 -0
  221. package/dest/json-rpc/js_utils.js +16 -0
  222. package/dest/json-rpc/server/index.d.ts +2 -0
  223. package/dest/json-rpc/server/index.d.ts.map +1 -0
  224. package/dest/json-rpc/server/index.js +1 -0
  225. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +140 -0
  226. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -0
  227. package/dest/json-rpc/server/safe_json_rpc_server.js +346 -0
  228. package/dest/json-rpc/server/telemetry.d.ts +2 -0
  229. package/dest/json-rpc/server/telemetry.d.ts.map +1 -0
  230. package/dest/json-rpc/server/telemetry.js +0 -0
  231. package/dest/json-rpc/test/index.d.ts +2 -0
  232. package/dest/json-rpc/test/index.d.ts.map +1 -0
  233. package/dest/json-rpc/test/index.js +1 -0
  234. package/dest/json-rpc/test/integration.d.ts +15 -0
  235. package/dest/json-rpc/test/integration.d.ts.map +1 -0
  236. package/dest/json-rpc/test/integration.js +21 -0
  237. package/dest/log/console.d.ts +11 -0
  238. package/dest/log/console.d.ts.map +1 -0
  239. package/dest/log/console.js +36 -0
  240. package/dest/log/debug.d.ts +56 -0
  241. package/dest/log/debug.d.ts.map +1 -0
  242. package/dest/log/debug.js +75 -0
  243. package/dest/log/gcloud-logger-config.d.ts +14 -0
  244. package/dest/log/gcloud-logger-config.d.ts.map +1 -0
  245. package/dest/log/gcloud-logger-config.js +66 -0
  246. package/dest/log/index.d.ts +7 -0
  247. package/dest/log/index.d.ts.map +1 -0
  248. package/dest/log/index.js +6 -0
  249. package/dest/log/libp2p_logger.d.ts +7 -0
  250. package/dest/log/libp2p_logger.d.ts.map +1 -0
  251. package/dest/log/libp2p_logger.js +55 -0
  252. package/dest/log/log-filters.d.ts +7 -0
  253. package/dest/log/log-filters.d.ts.map +1 -0
  254. package/dest/log/log-filters.js +59 -0
  255. package/dest/log/log-levels.d.ts +3 -0
  256. package/dest/log/log-levels.d.ts.map +1 -0
  257. package/dest/log/log-levels.js +10 -0
  258. package/dest/log/log_fn.d.ts +7 -0
  259. package/dest/log/log_fn.d.ts.map +1 -0
  260. package/dest/log/log_fn.js +1 -0
  261. package/dest/log/log_history.d.ts +31 -0
  262. package/dest/log/log_history.d.ts.map +1 -0
  263. package/dest/log/log_history.js +38 -0
  264. package/dest/log/pino-logger.d.ts +57 -0
  265. package/dest/log/pino-logger.d.ts.map +1 -0
  266. package/dest/log/pino-logger.js +207 -0
  267. package/dest/message/index.d.ts +32 -0
  268. package/dest/message/index.d.ts.map +1 -0
  269. package/dest/message/index.js +27 -0
  270. package/dest/mutex/index.d.ts +53 -0
  271. package/dest/mutex/index.d.ts.map +1 -0
  272. package/dest/mutex/index.js +78 -0
  273. package/dest/mutex/mutex_database.d.ts +10 -0
  274. package/dest/mutex/mutex_database.d.ts.map +1 -0
  275. package/dest/mutex/mutex_database.js +4 -0
  276. package/dest/noir/index.d.ts +2 -0
  277. package/dest/noir/index.d.ts.map +1 -0
  278. package/dest/noir/index.js +1 -0
  279. package/dest/noir/noir_package_config.d.ts +129 -0
  280. package/dest/noir/noir_package_config.d.ts.map +1 -0
  281. package/dest/noir/noir_package_config.js +36 -0
  282. package/dest/promise/index.d.ts +3 -0
  283. package/dest/promise/index.d.ts.map +1 -0
  284. package/dest/promise/index.js +2 -0
  285. package/dest/promise/running-promise.d.ts +47 -0
  286. package/dest/promise/running-promise.d.ts.map +1 -0
  287. package/dest/promise/running-promise.js +110 -0
  288. package/dest/promise/utils.d.ts +12 -0
  289. package/dest/promise/utils.d.ts.map +1 -0
  290. package/dest/promise/utils.js +20 -0
  291. package/dest/queue/base_memory_queue.d.ts +65 -0
  292. package/dest/queue/base_memory_queue.d.ts.map +1 -0
  293. package/dest/queue/base_memory_queue.js +116 -0
  294. package/dest/queue/batch_queue.d.ts +47 -0
  295. package/dest/queue/batch_queue.d.ts.map +1 -0
  296. package/dest/queue/batch_queue.js +105 -0
  297. package/dest/queue/bounded_serial_queue.d.ts +56 -0
  298. package/dest/queue/bounded_serial_queue.d.ts.map +1 -0
  299. package/dest/queue/bounded_serial_queue.js +84 -0
  300. package/dest/queue/fifo_memory_queue.d.ts +21 -0
  301. package/dest/queue/fifo_memory_queue.d.ts.map +1 -0
  302. package/dest/queue/fifo_memory_queue.js +29 -0
  303. package/dest/queue/index.d.ts +7 -0
  304. package/dest/queue/index.d.ts.map +1 -0
  305. package/dest/queue/index.js +6 -0
  306. package/dest/queue/priority_memory_queue.d.ts +13 -0
  307. package/dest/queue/priority_memory_queue.d.ts.map +1 -0
  308. package/dest/queue/priority_memory_queue.js +16 -0
  309. package/dest/queue/priority_queue.d.ts +14 -0
  310. package/dest/queue/priority_queue.d.ts.map +1 -0
  311. package/dest/queue/priority_queue.js +29 -0
  312. package/dest/queue/semaphore.d.ts +23 -0
  313. package/dest/queue/semaphore.d.ts.map +1 -0
  314. package/dest/queue/semaphore.js +26 -0
  315. package/dest/queue/serial_queue.d.ts +49 -0
  316. package/dest/queue/serial_queue.d.ts.map +1 -0
  317. package/dest/queue/serial_queue.js +72 -0
  318. package/dest/retry/index.d.ts +44 -0
  319. package/dest/retry/index.d.ts.map +1 -0
  320. package/dest/retry/index.js +93 -0
  321. package/dest/running-promise/index.d.ts +2 -0
  322. package/dest/running-promise/index.d.ts.map +1 -0
  323. package/dest/running-promise/index.js +1 -0
  324. package/dest/schemas/api.d.ts +21 -0
  325. package/dest/schemas/api.d.ts.map +1 -0
  326. package/dest/schemas/api.js +3 -0
  327. package/dest/schemas/index.d.ts +6 -0
  328. package/dest/schemas/index.d.ts.map +1 -0
  329. package/dest/schemas/index.js +5 -0
  330. package/dest/schemas/parse.d.ts +9 -0
  331. package/dest/schemas/parse.d.ts.map +1 -0
  332. package/dest/schemas/parse.js +22 -0
  333. package/dest/schemas/schemas.d.ts +45 -0
  334. package/dest/schemas/schemas.d.ts.map +1 -0
  335. package/dest/schemas/schemas.js +38 -0
  336. package/dest/schemas/types.d.ts +3 -0
  337. package/dest/schemas/types.d.ts.map +1 -0
  338. package/dest/schemas/types.js +1 -0
  339. package/dest/schemas/utils.d.ts +53 -0
  340. package/dest/schemas/utils.d.ts.map +1 -0
  341. package/dest/schemas/utils.js +60 -0
  342. package/dest/serialize/buffer_reader.d.ts +239 -0
  343. package/dest/serialize/buffer_reader.d.ts.map +1 -0
  344. package/dest/serialize/buffer_reader.js +290 -0
  345. package/dest/serialize/field_reader.d.ts +112 -0
  346. package/dest/serialize/field_reader.d.ts.map +1 -0
  347. package/dest/serialize/field_reader.js +147 -0
  348. package/dest/serialize/free_funcs.d.ts +105 -0
  349. package/dest/serialize/free_funcs.d.ts.map +1 -0
  350. package/dest/serialize/free_funcs.js +189 -0
  351. package/dest/serialize/index.d.ts +7 -0
  352. package/dest/serialize/index.d.ts.map +1 -0
  353. package/dest/serialize/index.js +6 -0
  354. package/dest/serialize/serialize.d.ts +182 -0
  355. package/dest/serialize/serialize.d.ts.map +1 -0
  356. package/dest/serialize/serialize.js +248 -0
  357. package/dest/serialize/type_registry.d.ts +23 -0
  358. package/dest/serialize/type_registry.d.ts.map +1 -0
  359. package/dest/serialize/type_registry.js +61 -0
  360. package/dest/serialize/types.d.ts +33 -0
  361. package/dest/serialize/types.d.ts.map +1 -0
  362. package/dest/serialize/types.js +21 -0
  363. package/dest/sleep/index.d.ts +51 -0
  364. package/dest/sleep/index.d.ts.map +1 -0
  365. package/dest/sleep/index.js +67 -0
  366. package/dest/string/index.d.ts +11 -0
  367. package/dest/string/index.d.ts.map +1 -0
  368. package/dest/string/index.js +24 -0
  369. package/dest/testing/files/index.d.ts +20 -0
  370. package/dest/testing/files/index.d.ts.map +1 -0
  371. package/dest/testing/files/index.js +58 -0
  372. package/dest/testing/index.d.ts +4 -0
  373. package/dest/testing/index.d.ts.map +1 -0
  374. package/dest/testing/index.js +3 -0
  375. package/dest/testing/port_allocator.d.ts +10 -0
  376. package/dest/testing/port_allocator.d.ts.map +1 -0
  377. package/dest/testing/port_allocator.js +29 -0
  378. package/dest/testing/snapshot_serializer.d.ts +5 -0
  379. package/dest/testing/snapshot_serializer.d.ts.map +1 -0
  380. package/dest/testing/snapshot_serializer.js +32 -0
  381. package/dest/testing/test_data.d.ts +7 -0
  382. package/dest/testing/test_data.d.ts.map +1 -0
  383. package/dest/testing/test_data.js +29 -0
  384. package/dest/timer/date.d.ts +13 -0
  385. package/dest/timer/date.d.ts.map +1 -0
  386. package/dest/timer/date.js +24 -0
  387. package/dest/timer/elapsed.d.ts +13 -0
  388. package/dest/timer/elapsed.d.ts.map +1 -0
  389. package/dest/timer/elapsed.js +25 -0
  390. package/dest/timer/index.d.ts +5 -0
  391. package/dest/timer/index.d.ts.map +1 -0
  392. package/dest/timer/index.js +4 -0
  393. package/dest/timer/timeout.d.ts +41 -0
  394. package/dest/timer/timeout.d.ts.map +1 -0
  395. package/dest/timer/timeout.js +66 -0
  396. package/dest/timer/timer.d.ts +37 -0
  397. package/dest/timer/timer.d.ts.map +1 -0
  398. package/dest/timer/timer.js +40 -0
  399. package/dest/transport/browser/index.d.ts +5 -0
  400. package/dest/transport/browser/index.d.ts.map +1 -0
  401. package/dest/transport/browser/index.js +4 -0
  402. package/dest/transport/browser/message_port_socket.d.ts +37 -0
  403. package/dest/transport/browser/message_port_socket.d.ts.map +1 -0
  404. package/dest/transport/browser/message_port_socket.js +42 -0
  405. package/dest/transport/browser/shared_worker_connector.d.ts +19 -0
  406. package/dest/transport/browser/shared_worker_connector.d.ts.map +1 -0
  407. package/dest/transport/browser/shared_worker_connector.js +19 -0
  408. package/dest/transport/browser/shared_worker_listener.d.ts +38 -0
  409. package/dest/transport/browser/shared_worker_listener.d.ts.map +1 -0
  410. package/dest/transport/browser/shared_worker_listener.js +33 -0
  411. package/dest/transport/browser/worker_connector.d.ts +26 -0
  412. package/dest/transport/browser/worker_connector.d.ts.map +1 -0
  413. package/dest/transport/browser/worker_connector.js +30 -0
  414. package/dest/transport/browser/worker_listener.d.ts +39 -0
  415. package/dest/transport/browser/worker_listener.d.ts.map +1 -0
  416. package/dest/transport/browser/worker_listener.js +35 -0
  417. package/dest/transport/dispatch/create_dispatch_fn.d.ts +25 -0
  418. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -0
  419. package/dest/transport/dispatch/create_dispatch_fn.js +17 -0
  420. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +102 -0
  421. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -0
  422. package/dest/transport/dispatch/create_dispatch_proxy.js +59 -0
  423. package/dest/transport/dispatch/messages.d.ts +52 -0
  424. package/dest/transport/dispatch/messages.d.ts.map +1 -0
  425. package/dest/transport/dispatch/messages.js +13 -0
  426. package/dest/transport/index.d.ts +12 -0
  427. package/dest/transport/index.d.ts.map +1 -0
  428. package/dest/transport/index.js +11 -0
  429. package/dest/transport/interface/connector.d.ts +8 -0
  430. package/dest/transport/interface/connector.d.ts.map +1 -0
  431. package/dest/transport/interface/connector.js +3 -0
  432. package/dest/transport/interface/listener.d.ts +13 -0
  433. package/dest/transport/interface/listener.d.ts.map +1 -0
  434. package/dest/transport/interface/listener.js +4 -0
  435. package/dest/transport/interface/socket.d.ts +13 -0
  436. package/dest/transport/interface/socket.d.ts.map +1 -0
  437. package/dest/transport/interface/socket.js +7 -0
  438. package/dest/transport/interface/transferable.d.ts +68 -0
  439. package/dest/transport/interface/transferable.d.ts.map +1 -0
  440. package/dest/transport/interface/transferable.js +63 -0
  441. package/dest/transport/node/index.d.ts +3 -0
  442. package/dest/transport/node/index.d.ts.map +1 -0
  443. package/dest/transport/node/index.js +2 -0
  444. package/dest/transport/node/node_connector.d.ts +28 -0
  445. package/dest/transport/node/node_connector.d.ts.map +1 -0
  446. package/dest/transport/node/node_connector.js +26 -0
  447. package/dest/transport/node/node_connector_socket.d.ts +42 -0
  448. package/dest/transport/node/node_connector_socket.d.ts.map +1 -0
  449. package/dest/transport/node/node_connector_socket.js +44 -0
  450. package/dest/transport/node/node_listener.d.ts +26 -0
  451. package/dest/transport/node/node_listener.d.ts.map +1 -0
  452. package/dest/transport/node/node_listener.js +26 -0
  453. package/dest/transport/node/node_listener_socket.d.ts +37 -0
  454. package/dest/transport/node/node_listener_socket.d.ts.map +1 -0
  455. package/dest/transport/node/node_listener_socket.js +40 -0
  456. package/dest/transport/transport_client.d.ts +61 -0
  457. package/dest/transport/transport_client.d.ts.map +1 -0
  458. package/dest/transport/transport_client.js +96 -0
  459. package/dest/transport/transport_server.d.ts +56 -0
  460. package/dest/transport/transport_server.d.ts.map +1 -0
  461. package/dest/transport/transport_server.js +114 -0
  462. package/dest/trees/hasher.d.ts +39 -0
  463. package/dest/trees/hasher.d.ts.map +1 -0
  464. package/dest/trees/hasher.js +5 -0
  465. package/dest/trees/index.d.ts +11 -0
  466. package/dest/trees/index.d.ts.map +1 -0
  467. package/dest/trees/index.js +10 -0
  468. package/dest/trees/indexed_merkle_tree.d.ts +13 -0
  469. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -0
  470. package/dest/trees/indexed_merkle_tree.js +27 -0
  471. package/dest/trees/indexed_merkle_tree_calculator.d.ts +23 -0
  472. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -0
  473. package/dest/trees/indexed_merkle_tree_calculator.js +83 -0
  474. package/dest/trees/indexed_tree_leaf.d.ts +57 -0
  475. package/dest/trees/indexed_tree_leaf.d.ts.map +1 -0
  476. package/dest/trees/indexed_tree_leaf.js +5 -0
  477. package/dest/trees/membership_witness.d.ts +62 -0
  478. package/dest/trees/membership_witness.d.ts.map +1 -0
  479. package/dest/trees/membership_witness.js +70 -0
  480. package/dest/trees/merkle_tree.d.ts +18 -0
  481. package/dest/trees/merkle_tree.d.ts.map +1 -0
  482. package/dest/trees/merkle_tree.js +58 -0
  483. package/dest/trees/merkle_tree_calculator.d.ts +16 -0
  484. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -0
  485. package/dest/trees/merkle_tree_calculator.js +61 -0
  486. package/dest/trees/sibling_path.d.ts +132 -0
  487. package/dest/trees/sibling_path.d.ts.map +1 -0
  488. package/dest/trees/sibling_path.js +144 -0
  489. package/dest/trees/unbalanced_merkle_tree.d.ts +17 -0
  490. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -0
  491. package/dest/trees/unbalanced_merkle_tree.js +100 -0
  492. package/dest/trees/unbalanced_tree_store.d.ts +19 -0
  493. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -0
  494. package/dest/trees/unbalanced_tree_store.js +94 -0
  495. package/dest/types/index.d.ts +19 -0
  496. package/dest/types/index.d.ts.map +1 -0
  497. package/dest/types/index.js +3 -0
  498. package/dest/url/index.d.ts +9 -0
  499. package/dest/url/index.d.ts.map +1 -0
  500. package/dest/url/index.js +62 -0
  501. package/dest/validation/index.d.ts +9 -0
  502. package/dest/validation/index.d.ts.map +1 -0
  503. package/dest/validation/index.js +15 -0
  504. package/dest/wasm/empty_wasi_sdk.d.ts +130 -0
  505. package/dest/wasm/empty_wasi_sdk.d.ts.map +1 -0
  506. package/dest/wasm/empty_wasi_sdk.js +148 -0
  507. package/dest/wasm/index.d.ts +2 -0
  508. package/dest/wasm/index.d.ts.map +1 -0
  509. package/dest/wasm/index.js +1 -0
  510. package/dest/wasm/wasm_module.d.ts +136 -0
  511. package/dest/wasm/wasm_module.d.ts.map +1 -0
  512. package/dest/wasm/wasm_module.js +196 -0
  513. package/dest/worker/browser/index.d.ts +3 -0
  514. package/dest/worker/browser/index.d.ts.map +1 -0
  515. package/dest/worker/browser/index.js +2 -0
  516. package/dest/worker/browser/start_web_module.d.ts +7 -0
  517. package/dest/worker/browser/start_web_module.d.ts.map +1 -0
  518. package/dest/worker/browser/start_web_module.js +27 -0
  519. package/dest/worker/browser/web_data_store.d.ts +24 -0
  520. package/dest/worker/browser/web_data_store.d.ts.map +1 -0
  521. package/dest/worker/browser/web_data_store.js +29 -0
  522. package/dest/worker/browser/web_worker.d.ts +10 -0
  523. package/dest/worker/browser/web_worker.d.ts.map +1 -0
  524. package/dest/worker/browser/web_worker.js +25 -0
  525. package/dest/worker/data_store.d.ts +21 -0
  526. package/dest/worker/data_store.d.ts.map +1 -0
  527. package/dest/worker/data_store.js +3 -0
  528. package/dest/worker/index.d.ts +3 -0
  529. package/dest/worker/index.d.ts.map +1 -0
  530. package/dest/worker/index.js +1 -0
  531. package/dest/worker/node/index.d.ts +3 -0
  532. package/dest/worker/node/index.d.ts.map +1 -0
  533. package/dest/worker/node/index.js +2 -0
  534. package/dest/worker/node/node_data_store.d.ts +13 -0
  535. package/dest/worker/node/node_data_store.d.ts.map +1 -0
  536. package/dest/worker/node/node_data_store.js +20 -0
  537. package/dest/worker/node/node_worker.d.ts +6 -0
  538. package/dest/worker/node/node_worker.d.ts.map +1 -0
  539. package/dest/worker/node/node_worker.js +22 -0
  540. package/dest/worker/node/start_node_module.d.ts +7 -0
  541. package/dest/worker/node/start_node_module.d.ts.map +1 -0
  542. package/dest/worker/node/start_node_module.js +31 -0
  543. package/dest/worker/wasm_worker.d.ts +9 -0
  544. package/dest/worker/wasm_worker.d.ts.map +1 -0
  545. package/dest/worker/wasm_worker.js +3 -0
  546. package/dest/worker/worker_pool.d.ts +40 -0
  547. package/dest/worker/worker_pool.d.ts.map +1 -0
  548. package/dest/worker/worker_pool.js +51 -0
  549. package/package.json +176 -0
  550. package/src/array/array.ts +150 -0
  551. package/src/array/index.ts +1 -0
  552. package/src/async-map/index.ts +18 -0
  553. package/src/async-pool/index.ts +50 -0
  554. package/src/bigint-buffer/index.ts +87 -0
  555. package/src/buffer/buffer32.ts +144 -0
  556. package/src/buffer/index.ts +1 -0
  557. package/src/collection/array.ts +203 -0
  558. package/src/collection/index.ts +2 -0
  559. package/src/collection/object.ts +52 -0
  560. package/src/committable/committable.ts +46 -0
  561. package/src/committable/index.ts +1 -0
  562. package/src/config/env_var.ts +207 -0
  563. package/src/config/index.ts +167 -0
  564. package/src/crypto/aes128/index.ts +59 -0
  565. package/src/crypto/ecdsa/index.ts +70 -0
  566. package/src/crypto/ecdsa/signature.ts +100 -0
  567. package/src/crypto/grumpkin/index.ts +97 -0
  568. package/src/crypto/index.ts +14 -0
  569. package/src/crypto/keccak/index.ts +283 -0
  570. package/src/crypto/keys/index.ts +10 -0
  571. package/src/crypto/pedersen/index.ts +1 -0
  572. package/src/crypto/pedersen/pedersen.elliptic.ts +584 -0
  573. package/src/crypto/pedersen/pedersen.noble.ts +573 -0
  574. package/src/crypto/pedersen/pedersen.wasm.ts +48 -0
  575. package/src/crypto/poseidon/index.ts +77 -0
  576. package/src/crypto/random/index.ts +85 -0
  577. package/src/crypto/random/randomness_singleton.ts +62 -0
  578. package/src/crypto/schnorr/index.ts +55 -0
  579. package/src/crypto/schnorr/signature.ts +116 -0
  580. package/src/crypto/secp256k1/index.ts +57 -0
  581. package/src/crypto/secp256k1-signer/index.ts +2 -0
  582. package/src/crypto/secp256k1-signer/secp256k1_signer.ts +38 -0
  583. package/src/crypto/secp256k1-signer/utils.ts +99 -0
  584. package/src/crypto/serialize.ts +85 -0
  585. package/src/crypto/sha256/index.ts +147 -0
  586. package/src/crypto/sha512/index.ts +16 -0
  587. package/src/crypto/signature/index.ts +17 -0
  588. package/src/crypto/sync/index.ts +6 -0
  589. package/src/crypto/sync/pedersen/index.ts +45 -0
  590. package/src/crypto/sync/poseidon/index.ts +76 -0
  591. package/src/decorators/index.ts +1 -0
  592. package/src/decorators/memoize.ts +11 -0
  593. package/src/error/index.ts +22 -0
  594. package/src/eth-address/index.ts +241 -0
  595. package/src/eth-signature/eth_signature.ts +128 -0
  596. package/src/eth-signature/index.ts +1 -0
  597. package/src/fields/coordinate.ts +104 -0
  598. package/src/fields/fields.ts +505 -0
  599. package/src/fields/index.ts +3 -0
  600. package/src/fields/point.ts +300 -0
  601. package/src/fs/index.ts +1 -0
  602. package/src/fs/run_in_dir.ts +33 -0
  603. package/src/index.ts +31 -0
  604. package/src/iterable/all.ts +32 -0
  605. package/src/iterable/filter.ts +77 -0
  606. package/src/iterable/index.ts +7 -0
  607. package/src/iterable/isAsyncIt.ts +8 -0
  608. package/src/iterable/map.ts +66 -0
  609. package/src/iterable/peek.ts +58 -0
  610. package/src/iterable/sort.ts +39 -0
  611. package/src/iterable/take.ts +54 -0
  612. package/src/iterable/toArray.ts +9 -0
  613. package/src/jest/setup.mjs +9 -0
  614. package/src/json-rpc/README.md +55 -0
  615. package/src/json-rpc/client/fetch.ts +103 -0
  616. package/src/json-rpc/client/index.ts +2 -0
  617. package/src/json-rpc/client/safe_json_rpc_client.ts +67 -0
  618. package/src/json-rpc/client/undici.ts +75 -0
  619. package/src/json-rpc/convert.ts +61 -0
  620. package/src/json-rpc/fixtures/class_a.ts +15 -0
  621. package/src/json-rpc/fixtures/class_b.ts +15 -0
  622. package/src/json-rpc/fixtures/test_state.ts +143 -0
  623. package/src/json-rpc/index.ts +1 -0
  624. package/src/json-rpc/js_utils.ts +21 -0
  625. package/src/json-rpc/server/index.ts +1 -0
  626. package/src/json-rpc/server/safe_json_rpc_server.ts +376 -0
  627. package/src/json-rpc/server/telemetry.ts +0 -0
  628. package/src/json-rpc/test/index.ts +1 -0
  629. package/src/json-rpc/test/integration.ts +35 -0
  630. package/src/log/console.ts +39 -0
  631. package/src/log/debug.ts +104 -0
  632. package/src/log/gcloud-logger-config.ts +71 -0
  633. package/src/log/index.ts +6 -0
  634. package/src/log/libp2p_logger.ts +67 -0
  635. package/src/log/log-filters.ts +63 -0
  636. package/src/log/log-levels.ts +3 -0
  637. package/src/log/log_fn.ts +5 -0
  638. package/src/log/log_history.ts +44 -0
  639. package/src/log/pino-logger.ts +243 -0
  640. package/src/message/index.ts +43 -0
  641. package/src/mutex/index.ts +84 -0
  642. package/src/mutex/mutex_database.ts +12 -0
  643. package/src/noir/index.ts +1 -0
  644. package/src/noir/noir_package_config.ts +54 -0
  645. package/src/promise/index.ts +2 -0
  646. package/src/promise/running-promise.ts +125 -0
  647. package/src/promise/utils.ts +29 -0
  648. package/src/queue/base_memory_queue.ts +138 -0
  649. package/src/queue/batch_queue.ts +120 -0
  650. package/src/queue/bounded_serial_queue.ts +100 -0
  651. package/src/queue/fifo_memory_queue.ts +39 -0
  652. package/src/queue/index.ts +6 -0
  653. package/src/queue/priority_memory_queue.ts +20 -0
  654. package/src/queue/priority_queue.ts +34 -0
  655. package/src/queue/semaphore.ts +33 -0
  656. package/src/queue/serial_queue.ts +86 -0
  657. package/src/retry/index.ts +100 -0
  658. package/src/running-promise/index.ts +1 -0
  659. package/src/schemas/api.ts +47 -0
  660. package/src/schemas/index.ts +5 -0
  661. package/src/schemas/parse.ts +29 -0
  662. package/src/schemas/schemas.ts +64 -0
  663. package/src/schemas/types.ts +3 -0
  664. package/src/schemas/utils.ts +112 -0
  665. package/src/serialize/buffer_reader.ts +383 -0
  666. package/src/serialize/field_reader.ts +184 -0
  667. package/src/serialize/free_funcs.ts +204 -0
  668. package/src/serialize/index.ts +6 -0
  669. package/src/serialize/serialize.ts +336 -0
  670. package/src/serialize/type_registry.ts +75 -0
  671. package/src/serialize/types.ts +40 -0
  672. package/src/sleep/index.ts +75 -0
  673. package/src/string/index.ts +31 -0
  674. package/src/testing/files/index.ts +69 -0
  675. package/src/testing/index.ts +3 -0
  676. package/src/testing/port_allocator.ts +31 -0
  677. package/src/testing/snapshot_serializer.ts +33 -0
  678. package/src/testing/test_data.ts +36 -0
  679. package/src/timer/date.ts +24 -0
  680. package/src/timer/elapsed.ts +23 -0
  681. package/src/timer/index.ts +4 -0
  682. package/src/timer/timeout.ts +70 -0
  683. package/src/timer/timer.ts +48 -0
  684. package/src/transport/browser/index.ts +4 -0
  685. package/src/transport/browser/message_port_socket.ts +48 -0
  686. package/src/transport/browser/shared_worker_connector.ts +21 -0
  687. package/src/transport/browser/shared_worker_listener.ts +53 -0
  688. package/src/transport/browser/worker_connector.ts +30 -0
  689. package/src/transport/browser/worker_listener.ts +54 -0
  690. package/src/transport/dispatch/create_dispatch_fn.ts +35 -0
  691. package/src/transport/dispatch/create_dispatch_proxy.ts +141 -0
  692. package/src/transport/dispatch/messages.ts +58 -0
  693. package/src/transport/index.ts +11 -0
  694. package/src/transport/interface/connector.ts +9 -0
  695. package/src/transport/interface/listener.ts +16 -0
  696. package/src/transport/interface/socket.ts +15 -0
  697. package/src/transport/interface/transferable.ts +125 -0
  698. package/src/transport/node/index.ts +2 -0
  699. package/src/transport/node/node_connector.ts +30 -0
  700. package/src/transport/node/node_connector_socket.ts +52 -0
  701. package/src/transport/node/node_listener.ts +34 -0
  702. package/src/transport/node/node_listener_socket.ts +48 -0
  703. package/src/transport/transport_client.ts +131 -0
  704. package/src/transport/transport_server.ts +108 -0
  705. package/src/trees/hasher.ts +39 -0
  706. package/src/trees/index.ts +10 -0
  707. package/src/trees/indexed_merkle_tree.ts +36 -0
  708. package/src/trees/indexed_merkle_tree_calculator.ts +94 -0
  709. package/src/trees/indexed_tree_leaf.ts +56 -0
  710. package/src/trees/membership_witness.ts +99 -0
  711. package/src/trees/merkle_tree.ts +72 -0
  712. package/src/trees/merkle_tree_calculator.ts +67 -0
  713. package/src/trees/sibling_path.ts +183 -0
  714. package/src/trees/unbalanced_merkle_tree.ts +103 -0
  715. package/src/trees/unbalanced_tree_store.ts +102 -0
  716. package/src/types/index.ts +25 -0
  717. package/src/url/index.ts +73 -0
  718. package/src/validation/index.ts +18 -0
  719. package/src/wasm/README.md +6 -0
  720. package/src/wasm/empty_wasi_sdk.ts +166 -0
  721. package/src/wasm/fixtures/gcd.wasm +0 -0
  722. package/src/wasm/fixtures/gcd.wat +27 -0
  723. package/src/wasm/index.ts +1 -0
  724. package/src/wasm/wasm_module.ts +260 -0
  725. package/src/worker/browser/index.ts +2 -0
  726. package/src/worker/browser/start_web_module.ts +24 -0
  727. package/src/worker/browser/web_data_store.ts +38 -0
  728. package/src/worker/browser/web_worker.ts +25 -0
  729. package/src/worker/data_store.ts +19 -0
  730. package/src/worker/index.ts +2 -0
  731. package/src/worker/node/index.ts +2 -0
  732. package/src/worker/node/node_data_store.ts +27 -0
  733. package/src/worker/node/node_worker.ts +23 -0
  734. package/src/worker/node/start_node_module.ts +30 -0
  735. package/src/worker/wasm_worker.ts +7 -0
  736. package/src/worker/worker_pool.ts +73 -0
@@ -0,0 +1,84 @@
1
+ import { createLogger } from '../log/index.js';
2
+ import { Semaphore } from './semaphore.js';
3
+ import { SerialQueue } from './serial_queue.js';
4
+ /**
5
+ * Leverages the unbounded SerialQueue and Semaphore to create a SerialQueue that will block when putting an item
6
+ * if the queue size = maxQueueSize.
7
+ */ export class BoundedSerialQueue {
8
+ log;
9
+ queue;
10
+ semaphore;
11
+ constructor(maxQueueSize, log = createLogger('foundation:bounded_serial_queue')){
12
+ this.log = log;
13
+ this.queue = new SerialQueue();
14
+ this.semaphore = new Semaphore(maxQueueSize);
15
+ }
16
+ /**
17
+ * Initializes the underlying SerialQueue instance, allowing items to be processed from the queue.
18
+ * The start method should be called before using the BoundedSerialQueue to ensure proper functionality.
19
+ */ start() {
20
+ this.queue.start();
21
+ }
22
+ /**
23
+ * Returns the current number of items in the queue.
24
+ * This is useful for monitoring the size of BoundedSerialQueue and understanding its utilization.
25
+ *
26
+ * @returns The length of the queue as an integer value.
27
+ */ length() {
28
+ return this.queue.length();
29
+ }
30
+ /**
31
+ * Cancels the current operation in the SerialQueue, if any, and clears the queue.
32
+ * Any pending tasks in the queue will not be executed, and the queue will be emptied.
33
+ * This method is useful for cleaning up resources and stopping ongoing processes when they are no longer needed.
34
+ * @returns A promise, resolved once cancelled.
35
+ */ cancel() {
36
+ return this.queue.cancel();
37
+ }
38
+ /**
39
+ * Ends the queue processing gracefully, preventing new items from being added.
40
+ * The currently executing item, if any, will complete and remaining queued items
41
+ * will be processed in order. Once all items have been processed, the queue becomes
42
+ * permanently unusable.
43
+ *
44
+ * @returns A promise that resolves when all items in the queue have been processed.
45
+ */ end() {
46
+ return this.queue.end();
47
+ }
48
+ /**
49
+ * The caller will block until fn is successfully enqueued.
50
+ * The fn itself is execute asynchronously and its result discarded.
51
+ * TODO(AD) do we need this if we have exec()?
52
+ * @param fn - The function to call once unblocked.
53
+ */ async put(fn) {
54
+ await this.semaphore.acquire();
55
+ this.queue.put(async ()=>{
56
+ try {
57
+ await fn();
58
+ } finally{
59
+ this.semaphore.release();
60
+ }
61
+ }).catch((err)=>{
62
+ this.log.error('BoundedSerialQueue handler exception:', err);
63
+ });
64
+ }
65
+ /**
66
+ * The caller will block until fn is successfully executed, and it's result returned.
67
+ * @param fn - The function.
68
+ * @returns A promise that resolves with the result once executed.
69
+ */ async exec(fn) {
70
+ await this.semaphore.acquire();
71
+ return this.queue.put(async ()=>{
72
+ try {
73
+ return await fn();
74
+ } finally{
75
+ this.semaphore.release();
76
+ }
77
+ });
78
+ }
79
+ /**
80
+ * Awaiting this ensures the queue is empty before resuming.
81
+ */ async syncPoint() {
82
+ await this.queue.syncPoint();
83
+ }
84
+ }
@@ -0,0 +1,21 @@
1
+ import type { Logger } from '../log/index.js';
2
+ import { BaseMemoryQueue } from './base_memory_queue.js';
3
+ /**
4
+ * A simple fifo queue. It can grow unbounded. It can have multiple producers and consumers.
5
+ * Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
6
+ * the item being pushed is simply discarded.
7
+ */
8
+ export declare class FifoMemoryQueue<T> extends BaseMemoryQueue<T> {
9
+ private container;
10
+ constructor(log?: Logger);
11
+ protected get items(): FifoQueue<T>;
12
+ }
13
+ declare class FifoQueue<T> {
14
+ private items;
15
+ put(item: T): void;
16
+ get(): T | undefined;
17
+ get length(): number;
18
+ clear(): void;
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=fifo_memory_queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fifo_memory_queue.d.ts","sourceRoot":"","sources":["../../src/queue/fifo_memory_queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;;;GAIG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;IACxD,OAAO,CAAC,SAAS,CAAsB;gBAE3B,GAAG,CAAC,EAAE,MAAM;IAIxB,cAAuB,KAAK,iBAE3B;CACF;AAED,cAAM,SAAS,CAAC,CAAC;IACf,OAAO,CAAC,KAAK,CAAW;IAEjB,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAIlB,GAAG,IAAI,CAAC,GAAG,SAAS;IAI3B,IAAW,MAAM,IAAI,MAAM,CAE1B;IAEM,KAAK;CAGb"}
@@ -0,0 +1,29 @@
1
+ import { BaseMemoryQueue } from './base_memory_queue.js';
2
+ /**
3
+ * A simple fifo queue. It can grow unbounded. It can have multiple producers and consumers.
4
+ * Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
5
+ * the item being pushed is simply discarded.
6
+ */ export class FifoMemoryQueue extends BaseMemoryQueue {
7
+ container = new FifoQueue();
8
+ constructor(log){
9
+ super(log);
10
+ }
11
+ get items() {
12
+ return this.container;
13
+ }
14
+ }
15
+ class FifoQueue {
16
+ items = [];
17
+ put(item) {
18
+ this.items.push(item);
19
+ }
20
+ get() {
21
+ return this.items.shift();
22
+ }
23
+ get length() {
24
+ return this.items.length;
25
+ }
26
+ clear() {
27
+ this.items = [];
28
+ }
29
+ }
@@ -0,0 +1,7 @@
1
+ export * from './fifo_memory_queue.js';
2
+ export * from './priority_memory_queue.js';
3
+ export * from './serial_queue.js';
4
+ export * from './bounded_serial_queue.js';
5
+ export * from './semaphore.js';
6
+ export * from './batch_queue.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/queue/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './fifo_memory_queue.js';
2
+ export * from './priority_memory_queue.js';
3
+ export * from './serial_queue.js';
4
+ export * from './bounded_serial_queue.js';
5
+ export * from './semaphore.js';
6
+ export * from './batch_queue.js';
@@ -0,0 +1,13 @@
1
+ import { BaseMemoryQueue } from './base_memory_queue.js';
2
+ import { PriorityQueue } from './priority_queue.js';
3
+ /**
4
+ * A priority queue. It can grow unbounded. It can have multiple producers and consumers.
5
+ * Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
6
+ * the item being pushed is simply discarded.
7
+ */
8
+ export declare class PriorityMemoryQueue<T> extends BaseMemoryQueue<T> {
9
+ private container;
10
+ constructor(comparator: (a: T, b: T) => number);
11
+ protected get items(): PriorityQueue<T>;
12
+ }
13
+ //# sourceMappingURL=priority_memory_queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priority_memory_queue.d.ts","sourceRoot":"","sources":["../../src/queue/priority_memory_queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;GAIG;AACH,qBAAa,mBAAmB,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,SAAS,CAAmB;gBAExB,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM;IAK9C,cAAuB,KAAK,qBAE3B;CACF"}
@@ -0,0 +1,16 @@
1
+ import { BaseMemoryQueue } from './base_memory_queue.js';
2
+ import { PriorityQueue } from './priority_queue.js';
3
+ /**
4
+ * A priority queue. It can grow unbounded. It can have multiple producers and consumers.
5
+ * Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
6
+ * the item being pushed is simply discarded.
7
+ */ export class PriorityMemoryQueue extends BaseMemoryQueue {
8
+ container;
9
+ constructor(comparator){
10
+ super();
11
+ this.container = new PriorityQueue(comparator);
12
+ }
13
+ get items() {
14
+ return this.container;
15
+ }
16
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Priority queue implementation based on a custom comparator.
3
+ */
4
+ export declare class PriorityQueue<T> {
5
+ private comparator;
6
+ private items;
7
+ constructor(comparator: (a: T, b: T) => number);
8
+ put(item: T): void;
9
+ get(): T | undefined;
10
+ peek(): T | undefined;
11
+ clear(): void;
12
+ get length(): number;
13
+ }
14
+ //# sourceMappingURL=priority_queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priority_queue.d.ts","sourceRoot":"","sources":["../../src/queue/priority_queue.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAa,CAAC,CAAC;IAGd,OAAO,CAAC,UAAU;IAF9B,OAAO,CAAC,KAAK,CAAM;gBAEC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM;IAI/C,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAQlB,GAAG,IAAI,CAAC,GAAG,SAAS;IAIpB,IAAI,IAAI,CAAC,GAAG,SAAS;IAIrB,KAAK;IAIZ,IAAW,MAAM,IAAI,MAAM,CAE1B;CACF"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Priority queue implementation based on a custom comparator.
3
+ */ export class PriorityQueue {
4
+ comparator;
5
+ items;
6
+ constructor(comparator){
7
+ this.comparator = comparator;
8
+ this.items = [];
9
+ }
10
+ put(item) {
11
+ let i = 0;
12
+ while(i < this.items.length && this.comparator(item, this.items[i]) >= 0){
13
+ i++;
14
+ }
15
+ this.items.splice(i, 0, item);
16
+ }
17
+ get() {
18
+ return this.items.shift();
19
+ }
20
+ peek() {
21
+ return this.items[0];
22
+ }
23
+ clear() {
24
+ this.items = [];
25
+ }
26
+ get length() {
27
+ return this.items.length;
28
+ }
29
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Allows the acquiring of up to `size` tokens before calls to acquire block, waiting for a call to release().
3
+ */
4
+ export declare class Semaphore {
5
+ private readonly queue;
6
+ constructor(size: number);
7
+ /**
8
+ * Acquires a token from the Semaphore, allowing access to a limited resource.
9
+ * If no tokens are available, the call will block and wait until a token is released.
10
+ * Use in conjunction with the release() method to manage access to resources with limited capacity.
11
+ *
12
+ * @returns A Promise that resolves when a token is acquired.
13
+ */
14
+ acquire(): Promise<void>;
15
+ /**
16
+ * Releases a token back into the semaphore, allowing another acquire call to proceed.
17
+ * If there are any pending calls to acquire(), one of them will be unblocked and allowed to proceed.
18
+ * This method should only be called by the holder of the acquired token to ensure proper functionality
19
+ * and avoid unexpected behavior.
20
+ */
21
+ release(): void;
22
+ }
23
+ //# sourceMappingURL=semaphore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semaphore.d.ts","sourceRoot":"","sources":["../../src/queue/semaphore.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkC;gBAE5C,IAAI,EAAE,MAAM;IAIxB;;;;;;OAMG;IACU,OAAO;IAIpB;;;;;OAKG;IACI,OAAO;CAGf"}
@@ -0,0 +1,26 @@
1
+ import { FifoMemoryQueue } from './fifo_memory_queue.js';
2
+ /**
3
+ * Allows the acquiring of up to `size` tokens before calls to acquire block, waiting for a call to release().
4
+ */ export class Semaphore {
5
+ queue = new FifoMemoryQueue();
6
+ constructor(size){
7
+ new Array(size).fill(true).map(()=>this.queue.put(true));
8
+ }
9
+ /**
10
+ * Acquires a token from the Semaphore, allowing access to a limited resource.
11
+ * If no tokens are available, the call will block and wait until a token is released.
12
+ * Use in conjunction with the release() method to manage access to resources with limited capacity.
13
+ *
14
+ * @returns A Promise that resolves when a token is acquired.
15
+ */ async acquire() {
16
+ await this.queue.get();
17
+ }
18
+ /**
19
+ * Releases a token back into the semaphore, allowing another acquire call to proceed.
20
+ * If there are any pending calls to acquire(), one of them will be unblocked and allowed to proceed.
21
+ * This method should only be called by the holder of the acquired token to ensure proper functionality
22
+ * and avoid unexpected behavior.
23
+ */ release() {
24
+ this.queue.put(true);
25
+ }
26
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * A more specialized fifo queue that enqueues functions to execute. Enqueued functions are executed in serial.
3
+ */
4
+ export declare class SerialQueue {
5
+ private readonly queue;
6
+ private runningPromise;
7
+ private started;
8
+ /**
9
+ * Initializes the execution of enqueued functions in the serial queue.
10
+ * Functions are executed in the order they were added to the queue, with each function
11
+ * waiting for the completion of the previous one before starting its execution.
12
+ * This method should be called once to start processing the queue.
13
+ */
14
+ start(): void;
15
+ /**
16
+ * Returns the current number of enqueued functions in the serial queue.
17
+ * This provides a way to check the size of the queue and monitor its progress.
18
+ *
19
+ * @returns The length of the serial queue as a number.
20
+ */
21
+ length(): number;
22
+ /**
23
+ * Cancels the processing of the remaining functions in the serial queue and resolves the running promise.
24
+ * Any enqueued functions that have not yet been executed will be discarded. The queue can still accept new
25
+ * functions after cancellation, but the previously enqueued functions will not be re-processed.
26
+ *
27
+ * @returns The running promise which resolves when the current executing function (if any) completes.
28
+ */
29
+ cancel(): Promise<void>;
30
+ /**
31
+ * Signals the SerialQueue that it should finish processing its current task and stop accepting new tasks.
32
+ * The returned Promise resolves when all enqueued tasks have completed execution.
33
+ *
34
+ * @returns A Promise that resolves when the queue is completely emptied and no new tasks are allowed.
35
+ */
36
+ end(): Promise<void>;
37
+ /**
38
+ * Enqueues fn for execution on the serial queue.
39
+ * Returns the result of the function after execution.
40
+ * @param fn - The function to enqueue.
41
+ * @returns A resolution promise. Rejects if the function does, or if the function could not be enqueued.
42
+ */
43
+ put<T>(fn: () => T | Promise<T>): Promise<Awaited<T>>;
44
+ /**
45
+ * Awaiting this ensures the queue is empty before resuming.
46
+ */
47
+ syncPoint(): Promise<void>;
48
+ }
49
+ //# sourceMappingURL=serial_queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serial_queue.d.ts","sourceRoot":"","sources":["../../src/queue/serial_queue.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA8C;IACpE,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,OAAO,CAAS;IAExB;;;;;OAKG;IACI,KAAK;IAQZ;;;;;OAKG;IACI,MAAM;IAIb;;;;;;OAMG;IACI,MAAM;IAKb;;;;;OAKG;IACI,GAAG;IAKV;;;;;OAKG;IACI,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAgB5D;;OAEG;IACU,SAAS;CAGvB"}
@@ -0,0 +1,72 @@
1
+ import { FifoMemoryQueue } from './fifo_memory_queue.js';
2
+ /**
3
+ * A more specialized fifo queue that enqueues functions to execute. Enqueued functions are executed in serial.
4
+ */ export class SerialQueue {
5
+ queue = new FifoMemoryQueue();
6
+ runningPromise;
7
+ started = false;
8
+ /**
9
+ * Initializes the execution of enqueued functions in the serial queue.
10
+ * Functions are executed in the order they were added to the queue, with each function
11
+ * waiting for the completion of the previous one before starting its execution.
12
+ * This method should be called once to start processing the queue.
13
+ */ start() {
14
+ if (this.started) {
15
+ return;
16
+ }
17
+ this.runningPromise = this.queue.process((fn)=>fn());
18
+ this.started = true;
19
+ }
20
+ /**
21
+ * Returns the current number of enqueued functions in the serial queue.
22
+ * This provides a way to check the size of the queue and monitor its progress.
23
+ *
24
+ * @returns The length of the serial queue as a number.
25
+ */ length() {
26
+ return this.queue.length();
27
+ }
28
+ /**
29
+ * Cancels the processing of the remaining functions in the serial queue and resolves the running promise.
30
+ * Any enqueued functions that have not yet been executed will be discarded. The queue can still accept new
31
+ * functions after cancellation, but the previously enqueued functions will not be re-processed.
32
+ *
33
+ * @returns The running promise which resolves when the current executing function (if any) completes.
34
+ */ cancel() {
35
+ this.queue.cancel();
36
+ return this.runningPromise;
37
+ }
38
+ /**
39
+ * Signals the SerialQueue that it should finish processing its current task and stop accepting new tasks.
40
+ * The returned Promise resolves when all enqueued tasks have completed execution.
41
+ *
42
+ * @returns A Promise that resolves when the queue is completely emptied and no new tasks are allowed.
43
+ */ end() {
44
+ this.queue.end();
45
+ return this.runningPromise;
46
+ }
47
+ /**
48
+ * Enqueues fn for execution on the serial queue.
49
+ * Returns the result of the function after execution.
50
+ * @param fn - The function to enqueue.
51
+ * @returns A resolution promise. Rejects if the function does, or if the function could not be enqueued.
52
+ */ put(fn) {
53
+ return new Promise((resolve, reject)=>{
54
+ const accepted = this.queue.put(async ()=>{
55
+ try {
56
+ const res = await fn();
57
+ resolve(res);
58
+ } catch (e) {
59
+ reject(e);
60
+ }
61
+ });
62
+ if (!accepted) {
63
+ reject(new Error('Could not enqueue function'));
64
+ }
65
+ });
66
+ }
67
+ /**
68
+ * Awaiting this ensures the queue is empty before resuming.
69
+ */ async syncPoint() {
70
+ await this.put(async ()=>{});
71
+ }
72
+ }
@@ -0,0 +1,44 @@
1
+ /** An error that indicates that the operation should not be retried. */
2
+ export declare class NoRetryError extends Error {
3
+ }
4
+ /**
5
+ * Generates a backoff sequence for retrying operations with an increasing delay.
6
+ * The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
7
+ * This generator can be used in combination with the `retry` function to perform
8
+ * retries with exponential backoff and capped at 64 seconds between attempts.
9
+ *
10
+ * @returns A generator that yields the next backoff value in seconds as an integer.
11
+ */
12
+ export declare function backoffGenerator(): Generator<number, void, unknown>;
13
+ /**
14
+ * Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
15
+ * @param retries - Intervals to retry (in seconds).
16
+ * @returns A generator sequence.
17
+ */
18
+ export declare function makeBackoff(retries: number[]): Generator<number, void, unknown>;
19
+ /**
20
+ * Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
21
+ * It logs the error and retry interval in case an error is caught. The function can be named for better log output.
22
+ *
23
+ * @param fn - The asynchronous function to be retried.
24
+ * @param name - The optional name of the operation, used for logging purposes.
25
+ * @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
26
+ * @param log - Logger to use for logging.
27
+ * @param failSilently - Do not log errors while retrying.
28
+ * @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
29
+ * @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
30
+ */
31
+ export declare function retry<Result>(fn: () => Promise<Result>, name?: string, backoff?: Generator<number, void, unknown>, log?: import("../log/pino-logger.js").Logger, failSilently?: boolean): Promise<Result>;
32
+ /**
33
+ * Retry an asynchronous function until it returns a truthy value or the specified timeout is exceeded.
34
+ * The function is retried periodically with a fixed interval between attempts. The operation can be named for better error messages.
35
+ * Will never timeout if the value is 0.
36
+ *
37
+ * @param fn - The asynchronous function to be retried, which should return a truthy value upon success or undefined otherwise.
38
+ * @param name - The optional name of the operation, used for generating timeout error message.
39
+ * @param timeout - The optional maximum time, in seconds, to keep retrying before throwing a timeout error. Defaults to 0 (never timeout).
40
+ * @param interval - The optional interval, in seconds, between retry attempts. Defaults to 1 second.
41
+ * @returns A Promise that resolves with the successful (truthy) result of the provided function, or rejects if timeout is exceeded.
42
+ */
43
+ export declare function retryUntil<T>(fn: () => Promise<T | undefined>, name?: string, timeout?: number, interval?: number): Promise<NonNullable<Awaited<T>>>;
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/retry/index.ts"],"names":[],"mappings":"AAKA,wEAAwE;AACxE,qBAAa,YAAa,SAAQ,KAAK;CAAG;AAE1C;;;;;;;GAOG;AACH,wBAAiB,gBAAgB,qCAMhC;AAED;;;;GAIG;AACH,wBAAiB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oCAI7C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAChC,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACzB,IAAI,SAAc,EAClB,OAAO,mCAAqB,EAC5B,GAAG,yCAAmC,EACtC,YAAY,UAAQ,mBAoBrB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,IAAI,SAAK,EAAE,OAAO,SAAI,EAAE,QAAQ,SAAI,oCAczG"}
@@ -0,0 +1,93 @@
1
+ import { TimeoutError } from '../error/index.js';
2
+ import { createLogger } from '../log/index.js';
3
+ import { sleep } from '../sleep/index.js';
4
+ import { Timer } from '../timer/index.js';
5
+ /** An error that indicates that the operation should not be retried. */ export class NoRetryError extends Error {
6
+ }
7
+ /**
8
+ * Generates a backoff sequence for retrying operations with an increasing delay.
9
+ * The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
10
+ * This generator can be used in combination with the `retry` function to perform
11
+ * retries with exponential backoff and capped at 64 seconds between attempts.
12
+ *
13
+ * @returns A generator that yields the next backoff value in seconds as an integer.
14
+ */ export function* backoffGenerator() {
15
+ const v = [
16
+ 1,
17
+ 1,
18
+ 1,
19
+ 2,
20
+ 4,
21
+ 8,
22
+ 16,
23
+ 32,
24
+ 64
25
+ ];
26
+ let i = 0;
27
+ while(true){
28
+ yield v[Math.min(i++, v.length - 1)];
29
+ }
30
+ }
31
+ /**
32
+ * Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
33
+ * @param retries - Intervals to retry (in seconds).
34
+ * @returns A generator sequence.
35
+ */ export function* makeBackoff(retries) {
36
+ for (const retry of retries){
37
+ yield retry;
38
+ }
39
+ }
40
+ /**
41
+ * Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
42
+ * It logs the error and retry interval in case an error is caught. The function can be named for better log output.
43
+ *
44
+ * @param fn - The asynchronous function to be retried.
45
+ * @param name - The optional name of the operation, used for logging purposes.
46
+ * @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
47
+ * @param log - Logger to use for logging.
48
+ * @param failSilently - Do not log errors while retrying.
49
+ * @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
50
+ * @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
51
+ */ export async function retry(fn, name = 'Operation', backoff = backoffGenerator(), log = createLogger('foundation:retry'), failSilently = false) {
52
+ while(true){
53
+ try {
54
+ return await fn();
55
+ } catch (err) {
56
+ if (err instanceof NoRetryError) {
57
+ // A special error that indicates that the operation should not be retried. Rethrow it.
58
+ throw err;
59
+ }
60
+ const s = backoff.next().value;
61
+ if (s === undefined) {
62
+ throw err;
63
+ }
64
+ log.verbose(`${name} failed. Will retry in ${s}s...`);
65
+ !failSilently && log.error(`Error while retrying ${name}`, err);
66
+ await sleep(s * 1000);
67
+ continue;
68
+ }
69
+ }
70
+ }
71
+ /**
72
+ * Retry an asynchronous function until it returns a truthy value or the specified timeout is exceeded.
73
+ * The function is retried periodically with a fixed interval between attempts. The operation can be named for better error messages.
74
+ * Will never timeout if the value is 0.
75
+ *
76
+ * @param fn - The asynchronous function to be retried, which should return a truthy value upon success or undefined otherwise.
77
+ * @param name - The optional name of the operation, used for generating timeout error message.
78
+ * @param timeout - The optional maximum time, in seconds, to keep retrying before throwing a timeout error. Defaults to 0 (never timeout).
79
+ * @param interval - The optional interval, in seconds, between retry attempts. Defaults to 1 second.
80
+ * @returns A Promise that resolves with the successful (truthy) result of the provided function, or rejects if timeout is exceeded.
81
+ */ export async function retryUntil(fn, name = '', timeout = 0, interval = 1) {
82
+ const timer = new Timer();
83
+ while(true){
84
+ const result = await fn();
85
+ if (result) {
86
+ return result;
87
+ }
88
+ await sleep(interval * 1000);
89
+ if (timeout && timer.s() > timeout) {
90
+ throw new TimeoutError(name ? `Timeout awaiting ${name}` : 'Timeout');
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,2 @@
1
+ export * from '../promise/running-promise.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/running-promise/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1 @@
1
+ export * from '../promise/running-promise.js';
@@ -0,0 +1,21 @@
1
+ import type { z } from 'zod';
2
+ import type { ZodNullableOptional } from './utils.js';
3
+ type ZodParameterTypeFor<T> = undefined extends T ? ZodNullableOptional<z.ZodType<T, z.ZodTypeDef, any>> : z.ZodType<T, z.ZodTypeDef, any>;
4
+ type ZodReturnTypeFor<T> = z.ZodType<T, z.ZodTypeDef, any>;
5
+ type ZodMapParameterTypes<T> = T extends [] ? [] : T extends [item: infer Head, ...infer Rest] ? [ZodParameterTypeFor<Head>, ...{
6
+ [K in keyof Rest]: ZodParameterTypeFor<Rest[K]>;
7
+ }] : T extends [item?: infer Head, ...infer Rest] ? [ZodNullableOptional<ZodParameterTypeFor<Head>>, ...{
8
+ [K in keyof Rest]: ZodParameterTypeFor<Rest[K]>;
9
+ }] : never;
10
+ /** Maps all functions in an interface to their schema representation. */
11
+ export type ApiSchemaFor<T> = {
12
+ [K in keyof T]: T[K] extends (...args: infer Args) => Promise<infer Ret> ? z.ZodFunction<z.ZodTuple<ZodMapParameterTypes<Args>, z.ZodUnknown>, ZodReturnTypeFor<Ret>> : never;
13
+ };
14
+ /** Generic Api schema not bounded to a specific implementation. */
15
+ export type ApiSchema = {
16
+ [key: string]: z.ZodFunction<z.ZodTuple<any, any>, z.ZodTypeAny>;
17
+ };
18
+ /** Return whether an API schema defines a valid function schema for a given method name. */
19
+ export declare function schemaHasMethod(schema: ApiSchema, methodName: string): boolean;
20
+ export {};
21
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/schemas/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGtD,KAAK,mBAAmB,CAAC,CAAC,IAAI,SAAS,SAAS,CAAC,GAC7C,mBAAmB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,GACpD,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AAEpC,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AAS3D,KAAK,oBAAoB,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,GACvC,EAAE,GACF,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GAC3C,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,GAAG;KAAG,CAAC,IAAI,MAAM,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,GACnF,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GAC5C,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG;KAAG,CAAC,IAAI,MAAM,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,GACxG,KAAK,CAAC;AAEV,yEAAyE;AACzE,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;KAC3B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,IAAI,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,GACpE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,GAC1F,KAAK;CACV,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,SAAS,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;CAClE,CAAC;AAEF,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAOpE"}
@@ -0,0 +1,3 @@
1
+ /** Return whether an API schema defines a valid function schema for a given method name. */ export function schemaHasMethod(schema, methodName) {
2
+ return typeof methodName === 'string' && Object.hasOwn(schema, methodName) && typeof schema[methodName].parameters === 'function' && typeof schema[methodName].returnType === 'function';
3
+ }
@@ -0,0 +1,6 @@
1
+ export * from './api.js';
2
+ export * from './parse.js';
3
+ export * from './utils.js';
4
+ export * from './types.js';
5
+ export * from './schemas.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './api.js';
2
+ export * from './parse.js';
3
+ export * from './utils.js';
4
+ export * from './types.js';
5
+ export * from './schemas.js';
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ /** Parses the given arguments using a tuple from the provided schemas. */
3
+ export declare function parse<T extends [] | [z.ZodTypeAny, ...z.ZodTypeAny[]]>(args: IArguments, ...schemas: T): z.AssertArray<{ [k in keyof T]: T[k] extends z.ZodType<any, any, any> ? T[k]["_output"] : never; }>;
4
+ /**
5
+ * Parses the given arguments against a tuple, allowing empty for optional items.
6
+ * @dev Zod doesn't like tuplues with optional items. See https://github.com/colinhacks/zod/discussions/949.
7
+ */
8
+ export declare function parseWithOptionals<T extends z.AnyZodTuple>(args: any[], schema: T): Promise<T['_output']>;
9
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/schemas/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,0EAA0E;AAC1E,wBAAgB,KAAK,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC,uGAEtG;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAMzG"}