@adviser/cement 0.4.61 → 0.4.63

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 (448) hide show
  1. package/cjs/app-context.cjs.map +1 -1
  2. package/cjs/app-context.d.ts.map +1 -1
  3. package/cjs/base-sys-abstraction.cjs.map +1 -1
  4. package/cjs/base-sys-abstraction.d.ts.map +1 -1
  5. package/cjs/bin2text.cjs.map +1 -1
  6. package/cjs/bin2text.d.ts.map +1 -1
  7. package/cjs/coerce-binary.cjs.map +1 -1
  8. package/cjs/coerce-binary.d.ts.map +1 -1
  9. package/cjs/crypto.cjs.map +1 -1
  10. package/cjs/crypto.d.ts.map +1 -1
  11. package/cjs/future.cjs.map +1 -1
  12. package/cjs/future.d.ts.map +1 -1
  13. package/cjs/http_header.cjs.map +1 -1
  14. package/cjs/http_header.d.ts.map +1 -1
  15. package/cjs/index.cjs +1 -0
  16. package/cjs/index.cjs.map +1 -1
  17. package/cjs/index.d.ts +1 -0
  18. package/cjs/index.d.ts.map +1 -1
  19. package/cjs/is-json.cjs.map +1 -1
  20. package/cjs/is-json.d.ts.map +1 -1
  21. package/cjs/is-promise.cjs.map +1 -1
  22. package/cjs/is-promise.d.ts.map +1 -1
  23. package/cjs/lru-map-set.cjs.map +1 -1
  24. package/cjs/lru-map-set.d.ts.map +1 -1
  25. package/cjs/on-func.cjs.map +1 -1
  26. package/cjs/on-func.d.ts.map +1 -1
  27. package/cjs/on-func.test.cjs +1 -1
  28. package/cjs/on-func.test.cjs.map +1 -1
  29. package/cjs/option.cjs.map +1 -1
  30. package/cjs/option.d.ts.map +1 -1
  31. package/cjs/poller.cjs +9 -4
  32. package/cjs/poller.cjs.map +1 -1
  33. package/cjs/poller.d.ts +9 -2
  34. package/cjs/poller.d.ts.map +1 -1
  35. package/cjs/poller.test.cjs +1 -1
  36. package/cjs/poller.test.cjs.map +1 -1
  37. package/cjs/{utils/promise-sleep.cjs → promise-sleep.cjs} +1 -1
  38. package/cjs/promise-sleep.cjs.map +1 -0
  39. package/cjs/promise-sleep.d.ts.map +1 -0
  40. package/cjs/promise-sleep.test.cjs.map +1 -0
  41. package/cjs/promise-sleep.test.d.ts.map +1 -0
  42. package/cjs/resolve-once.cjs +84 -6
  43. package/cjs/resolve-once.cjs.map +1 -1
  44. package/cjs/resolve-once.d.ts +36 -3
  45. package/cjs/resolve-once.d.ts.map +1 -1
  46. package/cjs/result.cjs.map +1 -1
  47. package/cjs/result.d.ts.map +1 -1
  48. package/cjs/runtime.cjs.map +1 -1
  49. package/cjs/runtime.d.ts.map +1 -1
  50. package/cjs/sys-env.cjs.map +1 -1
  51. package/cjs/sys-env.d.ts.map +1 -1
  52. package/cjs/timeouted.cjs +1 -1
  53. package/cjs/timeouted.cjs.map +1 -1
  54. package/cjs/timeouted.d.ts.map +1 -1
  55. package/cjs/tracer.cjs.map +1 -1
  56. package/cjs/tracer.d.ts.map +1 -1
  57. package/cjs/txt-en-decoder.cjs +2 -5
  58. package/cjs/txt-en-decoder.cjs.map +1 -1
  59. package/cjs/txt-en-decoder.d.ts +1 -1
  60. package/cjs/txt-en-decoder.d.ts.map +1 -1
  61. package/cjs/uri.cjs.map +1 -1
  62. package/cjs/uri.d.ts.map +1 -1
  63. package/cjs/utils/coerce-uint8.cjs.map +1 -1
  64. package/cjs/utils/coerce-uint8.d.ts.map +1 -1
  65. package/cjs/utils/console-write-stream.cjs.map +1 -1
  66. package/cjs/utils/console-write-stream.d.ts.map +1 -1
  67. package/cjs/utils/consume.cjs.map +1 -1
  68. package/cjs/utils/consume.d.ts.map +1 -1
  69. package/cjs/utils/fanout-write-stream.cjs.map +1 -1
  70. package/cjs/utils/fanout-write-stream.d.ts.map +1 -1
  71. package/cjs/utils/get-params-result.cjs.map +1 -1
  72. package/cjs/utils/get-params-result.d.ts.map +1 -1
  73. package/cjs/utils/index.cjs +0 -1
  74. package/cjs/utils/index.cjs.map +1 -1
  75. package/cjs/utils/index.d.ts +0 -1
  76. package/cjs/utils/index.d.ts.map +1 -1
  77. package/cjs/utils/rebuffer.cjs.map +1 -1
  78. package/cjs/utils/rebuffer.d.ts.map +1 -1
  79. package/cjs/utils/relative-path.cjs.map +1 -1
  80. package/cjs/utils/relative-path.d.ts.map +1 -1
  81. package/cjs/utils/sorted-object.cjs.map +1 -1
  82. package/cjs/utils/sorted-object.d.ts.map +1 -1
  83. package/cjs/utils/stream-map.cjs.map +1 -1
  84. package/cjs/utils/stream-map.d.ts.map +1 -1
  85. package/cjs/utils/stream2string.cjs.map +1 -1
  86. package/cjs/utils/stream2string.d.ts.map +1 -1
  87. package/cjs/utils/string2stream.cjs.map +1 -1
  88. package/cjs/utils/string2stream.d.ts.map +1 -1
  89. package/cjs/utils/stripper.cjs.map +1 -1
  90. package/cjs/utils/stripper.d.ts.map +1 -1
  91. package/cjs/utils/to-sorted.cjs.map +1 -1
  92. package/cjs/utils/to-sorted.d.ts.map +1 -1
  93. package/cjs/utils/uint8array-equal.cjs.map +1 -1
  94. package/cjs/utils/uint8array-equal.d.ts.map +1 -1
  95. package/cjs/version.cjs +1 -1
  96. package/deno.json +1 -1
  97. package/esm/app-context.d.ts.map +1 -1
  98. package/esm/app-context.js.map +1 -1
  99. package/esm/base-sys-abstraction.d.ts.map +1 -1
  100. package/esm/base-sys-abstraction.js.map +1 -1
  101. package/esm/bin2text.d.ts.map +1 -1
  102. package/esm/bin2text.js.map +1 -1
  103. package/esm/coerce-binary.d.ts.map +1 -1
  104. package/esm/coerce-binary.js.map +1 -1
  105. package/esm/crypto.d.ts.map +1 -1
  106. package/esm/crypto.js.map +1 -1
  107. package/esm/future.d.ts.map +1 -1
  108. package/esm/future.js.map +1 -1
  109. package/esm/http_header.d.ts.map +1 -1
  110. package/esm/http_header.js.map +1 -1
  111. package/esm/index.d.ts +1 -0
  112. package/esm/index.d.ts.map +1 -1
  113. package/esm/index.js +1 -0
  114. package/esm/index.js.map +1 -1
  115. package/esm/is-json.d.ts.map +1 -1
  116. package/esm/is-json.js.map +1 -1
  117. package/esm/is-promise.d.ts.map +1 -1
  118. package/esm/is-promise.js.map +1 -1
  119. package/esm/lru-map-set.d.ts.map +1 -1
  120. package/esm/lru-map-set.js.map +1 -1
  121. package/esm/on-func.d.ts.map +1 -1
  122. package/esm/on-func.js.map +1 -1
  123. package/esm/on-func.test.js +1 -1
  124. package/esm/on-func.test.js.map +1 -1
  125. package/esm/option.d.ts.map +1 -1
  126. package/esm/option.js.map +1 -1
  127. package/esm/poller.d.ts +9 -2
  128. package/esm/poller.d.ts.map +1 -1
  129. package/esm/poller.js +9 -4
  130. package/esm/poller.js.map +1 -1
  131. package/esm/poller.test.js +1 -1
  132. package/esm/poller.test.js.map +1 -1
  133. package/esm/promise-sleep.d.ts.map +1 -0
  134. package/{ts/esm/utils → esm}/promise-sleep.js +1 -1
  135. package/esm/promise-sleep.js.map +1 -0
  136. package/esm/promise-sleep.test.d.ts.map +1 -0
  137. package/esm/promise-sleep.test.js.map +1 -0
  138. package/esm/resolve-once.d.ts +36 -3
  139. package/esm/resolve-once.d.ts.map +1 -1
  140. package/esm/resolve-once.js +84 -6
  141. package/esm/resolve-once.js.map +1 -1
  142. package/esm/result.d.ts.map +1 -1
  143. package/esm/result.js.map +1 -1
  144. package/esm/runtime.d.ts.map +1 -1
  145. package/esm/runtime.js.map +1 -1
  146. package/esm/sys-env.d.ts.map +1 -1
  147. package/esm/sys-env.js.map +1 -1
  148. package/esm/timeouted.d.ts.map +1 -1
  149. package/esm/timeouted.js +1 -1
  150. package/esm/timeouted.js.map +1 -1
  151. package/esm/tracer.d.ts.map +1 -1
  152. package/esm/tracer.js.map +1 -1
  153. package/esm/txt-en-decoder.d.ts +1 -1
  154. package/esm/txt-en-decoder.d.ts.map +1 -1
  155. package/esm/txt-en-decoder.js +2 -5
  156. package/esm/txt-en-decoder.js.map +1 -1
  157. package/esm/uri.d.ts.map +1 -1
  158. package/esm/uri.js.map +1 -1
  159. package/esm/utils/coerce-uint8.d.ts.map +1 -1
  160. package/esm/utils/coerce-uint8.js.map +1 -1
  161. package/esm/utils/console-write-stream.d.ts.map +1 -1
  162. package/esm/utils/console-write-stream.js.map +1 -1
  163. package/esm/utils/consume.d.ts.map +1 -1
  164. package/esm/utils/consume.js.map +1 -1
  165. package/esm/utils/fanout-write-stream.d.ts.map +1 -1
  166. package/esm/utils/fanout-write-stream.js.map +1 -1
  167. package/esm/utils/get-params-result.d.ts.map +1 -1
  168. package/esm/utils/get-params-result.js.map +1 -1
  169. package/esm/utils/index.d.ts +0 -1
  170. package/esm/utils/index.d.ts.map +1 -1
  171. package/esm/utils/index.js +0 -1
  172. package/esm/utils/index.js.map +1 -1
  173. package/esm/utils/rebuffer.d.ts.map +1 -1
  174. package/esm/utils/rebuffer.js.map +1 -1
  175. package/esm/utils/relative-path.d.ts.map +1 -1
  176. package/esm/utils/relative-path.js.map +1 -1
  177. package/esm/utils/sorted-object.d.ts.map +1 -1
  178. package/esm/utils/sorted-object.js.map +1 -1
  179. package/esm/utils/stream-map.d.ts.map +1 -1
  180. package/esm/utils/stream-map.js.map +1 -1
  181. package/esm/utils/stream2string.d.ts.map +1 -1
  182. package/esm/utils/stream2string.js.map +1 -1
  183. package/esm/utils/string2stream.d.ts.map +1 -1
  184. package/esm/utils/string2stream.js.map +1 -1
  185. package/esm/utils/stripper.d.ts.map +1 -1
  186. package/esm/utils/stripper.js.map +1 -1
  187. package/esm/utils/to-sorted.d.ts.map +1 -1
  188. package/esm/utils/to-sorted.js.map +1 -1
  189. package/esm/utils/uint8array-equal.d.ts.map +1 -1
  190. package/esm/utils/uint8array-equal.js.map +1 -1
  191. package/esm/version.js +1 -1
  192. package/package.json +5 -2
  193. package/src/app-context.ts +111 -5
  194. package/src/base-sys-abstraction.ts +244 -0
  195. package/src/bin2text.ts +37 -0
  196. package/src/coerce-binary.ts +41 -0
  197. package/src/crypto.ts +35 -0
  198. package/src/future.ts +45 -1
  199. package/src/http_header.ts +277 -1
  200. package/src/index.ts +2 -4
  201. package/src/is-json.ts +21 -0
  202. package/src/is-promise.ts +26 -0
  203. package/src/lru-map-set.ts +46 -0
  204. package/src/on-func.ts +38 -0
  205. package/src/option.ts +27 -0
  206. package/src/poller.ts +66 -18
  207. package/src/{utils/promise-sleep.ts → promise-sleep.ts} +33 -5
  208. package/src/resolve-once.ts +588 -42
  209. package/src/result.ts +50 -0
  210. package/src/runtime.ts +75 -2
  211. package/src/sys-env.ts +57 -0
  212. package/src/timeouted.ts +93 -1
  213. package/src/tracer.ts +41 -0
  214. package/src/txt-en-decoder.ts +2 -5
  215. package/src/uri.ts +76 -4
  216. package/src/utils/coerce-uint8.ts +60 -0
  217. package/src/utils/console-write-stream.ts +34 -0
  218. package/src/utils/consume.ts +106 -0
  219. package/src/utils/fanout-write-stream.ts +45 -0
  220. package/src/utils/get-params-result.ts +37 -0
  221. package/src/utils/index.ts +0 -1
  222. package/src/utils/rebuffer.ts +42 -0
  223. package/src/utils/relative-path.ts +108 -0
  224. package/src/utils/sorted-object.ts +50 -0
  225. package/src/utils/stream-map.ts +90 -0
  226. package/src/utils/stream2string.ts +35 -0
  227. package/src/utils/string2stream.ts +30 -0
  228. package/src/utils/stripper.ts +34 -0
  229. package/src/utils/to-sorted.ts +34 -0
  230. package/src/utils/uint8array-equal.ts +20 -0
  231. package/ts/cjs/app-context.d.ts.map +1 -1
  232. package/ts/cjs/app-context.js.map +1 -1
  233. package/ts/cjs/base-sys-abstraction.d.ts.map +1 -1
  234. package/ts/cjs/base-sys-abstraction.js.map +1 -1
  235. package/ts/cjs/bin2text.d.ts.map +1 -1
  236. package/ts/cjs/bin2text.js.map +1 -1
  237. package/ts/cjs/coerce-binary.d.ts.map +1 -1
  238. package/ts/cjs/coerce-binary.js.map +1 -1
  239. package/ts/cjs/crypto.d.ts.map +1 -1
  240. package/ts/cjs/crypto.js.map +1 -1
  241. package/ts/cjs/future.d.ts.map +1 -1
  242. package/ts/cjs/future.js.map +1 -1
  243. package/ts/cjs/http_header.d.ts.map +1 -1
  244. package/ts/cjs/http_header.js.map +1 -1
  245. package/ts/cjs/index.d.ts +1 -0
  246. package/ts/cjs/index.d.ts.map +1 -1
  247. package/ts/cjs/index.js +1 -0
  248. package/ts/cjs/index.js.map +1 -1
  249. package/ts/cjs/is-json.d.ts.map +1 -1
  250. package/ts/cjs/is-json.js.map +1 -1
  251. package/ts/cjs/is-promise.d.ts.map +1 -1
  252. package/ts/cjs/is-promise.js.map +1 -1
  253. package/ts/cjs/lru-map-set.d.ts.map +1 -1
  254. package/ts/cjs/lru-map-set.js.map +1 -1
  255. package/ts/cjs/on-func.d.ts.map +1 -1
  256. package/ts/cjs/on-func.js.map +1 -1
  257. package/ts/cjs/on-func.test.js +1 -1
  258. package/ts/cjs/on-func.test.js.map +1 -1
  259. package/ts/cjs/option.d.ts.map +1 -1
  260. package/ts/cjs/option.js.map +1 -1
  261. package/ts/cjs/poller.d.ts +9 -2
  262. package/ts/cjs/poller.d.ts.map +1 -1
  263. package/ts/cjs/poller.js +9 -4
  264. package/ts/cjs/poller.js.map +1 -1
  265. package/ts/cjs/poller.test.js +1 -1
  266. package/ts/cjs/poller.test.js.map +1 -1
  267. package/ts/cjs/promise-sleep.d.ts.map +1 -0
  268. package/ts/cjs/{utils/promise-sleep.js → promise-sleep.js} +1 -1
  269. package/ts/cjs/promise-sleep.js.map +1 -0
  270. package/ts/cjs/promise-sleep.test.d.ts.map +1 -0
  271. package/ts/cjs/promise-sleep.test.js.map +1 -0
  272. package/ts/cjs/resolve-once.d.ts +36 -3
  273. package/ts/cjs/resolve-once.d.ts.map +1 -1
  274. package/ts/cjs/resolve-once.js +84 -6
  275. package/ts/cjs/resolve-once.js.map +1 -1
  276. package/ts/cjs/result.d.ts.map +1 -1
  277. package/ts/cjs/result.js.map +1 -1
  278. package/ts/cjs/runtime.d.ts.map +1 -1
  279. package/ts/cjs/runtime.js.map +1 -1
  280. package/ts/cjs/sys-env.d.ts.map +1 -1
  281. package/ts/cjs/sys-env.js.map +1 -1
  282. package/ts/cjs/timeouted.d.ts.map +1 -1
  283. package/ts/cjs/timeouted.js +1 -1
  284. package/ts/cjs/timeouted.js.map +1 -1
  285. package/ts/cjs/tracer.d.ts.map +1 -1
  286. package/ts/cjs/tracer.js.map +1 -1
  287. package/ts/cjs/txt-en-decoder.d.ts +1 -1
  288. package/ts/cjs/txt-en-decoder.d.ts.map +1 -1
  289. package/ts/cjs/txt-en-decoder.js +2 -5
  290. package/ts/cjs/txt-en-decoder.js.map +1 -1
  291. package/ts/cjs/uri.d.ts.map +1 -1
  292. package/ts/cjs/uri.js.map +1 -1
  293. package/ts/cjs/utils/coerce-uint8.d.ts.map +1 -1
  294. package/ts/cjs/utils/coerce-uint8.js.map +1 -1
  295. package/ts/cjs/utils/console-write-stream.d.ts.map +1 -1
  296. package/ts/cjs/utils/console-write-stream.js.map +1 -1
  297. package/ts/cjs/utils/consume.d.ts.map +1 -1
  298. package/ts/cjs/utils/consume.js.map +1 -1
  299. package/ts/cjs/utils/fanout-write-stream.d.ts.map +1 -1
  300. package/ts/cjs/utils/fanout-write-stream.js.map +1 -1
  301. package/ts/cjs/utils/get-params-result.d.ts.map +1 -1
  302. package/ts/cjs/utils/get-params-result.js.map +1 -1
  303. package/ts/cjs/utils/index.d.ts +0 -1
  304. package/ts/cjs/utils/index.d.ts.map +1 -1
  305. package/ts/cjs/utils/index.js +0 -1
  306. package/ts/cjs/utils/index.js.map +1 -1
  307. package/ts/cjs/utils/rebuffer.d.ts.map +1 -1
  308. package/ts/cjs/utils/rebuffer.js.map +1 -1
  309. package/ts/cjs/utils/relative-path.d.ts.map +1 -1
  310. package/ts/cjs/utils/relative-path.js.map +1 -1
  311. package/ts/cjs/utils/sorted-object.d.ts.map +1 -1
  312. package/ts/cjs/utils/sorted-object.js.map +1 -1
  313. package/ts/cjs/utils/stream-map.d.ts.map +1 -1
  314. package/ts/cjs/utils/stream-map.js.map +1 -1
  315. package/ts/cjs/utils/stream2string.d.ts.map +1 -1
  316. package/ts/cjs/utils/stream2string.js.map +1 -1
  317. package/ts/cjs/utils/string2stream.d.ts.map +1 -1
  318. package/ts/cjs/utils/string2stream.js.map +1 -1
  319. package/ts/cjs/utils/stripper.d.ts.map +1 -1
  320. package/ts/cjs/utils/stripper.js.map +1 -1
  321. package/ts/cjs/utils/to-sorted.d.ts.map +1 -1
  322. package/ts/cjs/utils/to-sorted.js.map +1 -1
  323. package/ts/cjs/utils/uint8array-equal.d.ts.map +1 -1
  324. package/ts/cjs/utils/uint8array-equal.js.map +1 -1
  325. package/ts/cjs/version.js +1 -1
  326. package/ts/esm/app-context.d.ts.map +1 -1
  327. package/ts/esm/app-context.js.map +1 -1
  328. package/ts/esm/base-sys-abstraction.d.ts.map +1 -1
  329. package/ts/esm/base-sys-abstraction.js.map +1 -1
  330. package/ts/esm/bin2text.d.ts.map +1 -1
  331. package/ts/esm/bin2text.js.map +1 -1
  332. package/ts/esm/coerce-binary.d.ts.map +1 -1
  333. package/ts/esm/coerce-binary.js.map +1 -1
  334. package/ts/esm/crypto.d.ts.map +1 -1
  335. package/ts/esm/crypto.js.map +1 -1
  336. package/ts/esm/future.d.ts.map +1 -1
  337. package/ts/esm/future.js.map +1 -1
  338. package/ts/esm/http_header.d.ts.map +1 -1
  339. package/ts/esm/http_header.js.map +1 -1
  340. package/ts/esm/index.d.ts +1 -0
  341. package/ts/esm/index.d.ts.map +1 -1
  342. package/ts/esm/index.js +1 -0
  343. package/ts/esm/index.js.map +1 -1
  344. package/ts/esm/is-json.d.ts.map +1 -1
  345. package/ts/esm/is-json.js.map +1 -1
  346. package/ts/esm/is-promise.d.ts.map +1 -1
  347. package/ts/esm/is-promise.js.map +1 -1
  348. package/ts/esm/lru-map-set.d.ts.map +1 -1
  349. package/ts/esm/lru-map-set.js.map +1 -1
  350. package/ts/esm/on-func.d.ts.map +1 -1
  351. package/ts/esm/on-func.js.map +1 -1
  352. package/ts/esm/on-func.test.js +1 -1
  353. package/ts/esm/on-func.test.js.map +1 -1
  354. package/ts/esm/option.d.ts.map +1 -1
  355. package/ts/esm/option.js.map +1 -1
  356. package/ts/esm/poller.d.ts +9 -2
  357. package/ts/esm/poller.d.ts.map +1 -1
  358. package/ts/esm/poller.js +9 -4
  359. package/ts/esm/poller.js.map +1 -1
  360. package/ts/esm/poller.test.js +1 -1
  361. package/ts/esm/poller.test.js.map +1 -1
  362. package/ts/esm/promise-sleep.d.ts.map +1 -0
  363. package/{esm/utils → ts/esm}/promise-sleep.js +1 -1
  364. package/ts/esm/promise-sleep.js.map +1 -0
  365. package/ts/esm/promise-sleep.test.d.ts.map +1 -0
  366. package/ts/esm/promise-sleep.test.js.map +1 -0
  367. package/ts/esm/resolve-once.d.ts +36 -3
  368. package/ts/esm/resolve-once.d.ts.map +1 -1
  369. package/ts/esm/resolve-once.js +84 -6
  370. package/ts/esm/resolve-once.js.map +1 -1
  371. package/ts/esm/result.d.ts.map +1 -1
  372. package/ts/esm/result.js.map +1 -1
  373. package/ts/esm/runtime.d.ts.map +1 -1
  374. package/ts/esm/runtime.js.map +1 -1
  375. package/ts/esm/sys-env.d.ts.map +1 -1
  376. package/ts/esm/sys-env.js.map +1 -1
  377. package/ts/esm/timeouted.d.ts.map +1 -1
  378. package/ts/esm/timeouted.js +1 -1
  379. package/ts/esm/timeouted.js.map +1 -1
  380. package/ts/esm/tracer.d.ts.map +1 -1
  381. package/ts/esm/tracer.js.map +1 -1
  382. package/ts/esm/txt-en-decoder.d.ts +1 -1
  383. package/ts/esm/txt-en-decoder.d.ts.map +1 -1
  384. package/ts/esm/txt-en-decoder.js +2 -5
  385. package/ts/esm/txt-en-decoder.js.map +1 -1
  386. package/ts/esm/uri.d.ts.map +1 -1
  387. package/ts/esm/uri.js.map +1 -1
  388. package/ts/esm/utils/coerce-uint8.d.ts.map +1 -1
  389. package/ts/esm/utils/coerce-uint8.js.map +1 -1
  390. package/ts/esm/utils/console-write-stream.d.ts.map +1 -1
  391. package/ts/esm/utils/console-write-stream.js.map +1 -1
  392. package/ts/esm/utils/consume.d.ts.map +1 -1
  393. package/ts/esm/utils/consume.js.map +1 -1
  394. package/ts/esm/utils/fanout-write-stream.d.ts.map +1 -1
  395. package/ts/esm/utils/fanout-write-stream.js.map +1 -1
  396. package/ts/esm/utils/get-params-result.d.ts.map +1 -1
  397. package/ts/esm/utils/get-params-result.js.map +1 -1
  398. package/ts/esm/utils/index.d.ts +0 -1
  399. package/ts/esm/utils/index.d.ts.map +1 -1
  400. package/ts/esm/utils/index.js +0 -1
  401. package/ts/esm/utils/index.js.map +1 -1
  402. package/ts/esm/utils/rebuffer.d.ts.map +1 -1
  403. package/ts/esm/utils/rebuffer.js.map +1 -1
  404. package/ts/esm/utils/relative-path.d.ts.map +1 -1
  405. package/ts/esm/utils/relative-path.js.map +1 -1
  406. package/ts/esm/utils/sorted-object.d.ts.map +1 -1
  407. package/ts/esm/utils/sorted-object.js.map +1 -1
  408. package/ts/esm/utils/stream-map.d.ts.map +1 -1
  409. package/ts/esm/utils/stream-map.js.map +1 -1
  410. package/ts/esm/utils/stream2string.d.ts.map +1 -1
  411. package/ts/esm/utils/stream2string.js.map +1 -1
  412. package/ts/esm/utils/string2stream.d.ts.map +1 -1
  413. package/ts/esm/utils/string2stream.js.map +1 -1
  414. package/ts/esm/utils/stripper.d.ts.map +1 -1
  415. package/ts/esm/utils/stripper.js.map +1 -1
  416. package/ts/esm/utils/to-sorted.d.ts.map +1 -1
  417. package/ts/esm/utils/to-sorted.js.map +1 -1
  418. package/ts/esm/utils/uint8array-equal.d.ts.map +1 -1
  419. package/ts/esm/utils/uint8array-equal.js.map +1 -1
  420. package/ts/esm/version.js +1 -1
  421. package/cjs/utils/promise-sleep.cjs.map +0 -1
  422. package/cjs/utils/promise-sleep.d.ts.map +0 -1
  423. package/cjs/utils/promise-sleep.test.cjs.map +0 -1
  424. package/cjs/utils/promise-sleep.test.d.ts.map +0 -1
  425. package/esm/utils/promise-sleep.d.ts.map +0 -1
  426. package/esm/utils/promise-sleep.js.map +0 -1
  427. package/esm/utils/promise-sleep.test.d.ts.map +0 -1
  428. package/esm/utils/promise-sleep.test.js.map +0 -1
  429. package/ts/cjs/utils/promise-sleep.d.ts.map +0 -1
  430. package/ts/cjs/utils/promise-sleep.js.map +0 -1
  431. package/ts/cjs/utils/promise-sleep.test.d.ts.map +0 -1
  432. package/ts/cjs/utils/promise-sleep.test.js.map +0 -1
  433. package/ts/esm/utils/promise-sleep.d.ts.map +0 -1
  434. package/ts/esm/utils/promise-sleep.js.map +0 -1
  435. package/ts/esm/utils/promise-sleep.test.d.ts.map +0 -1
  436. package/ts/esm/utils/promise-sleep.test.js.map +0 -1
  437. /package/cjs/{utils/promise-sleep.d.ts → promise-sleep.d.ts} +0 -0
  438. /package/cjs/{utils/promise-sleep.test.cjs → promise-sleep.test.cjs} +0 -0
  439. /package/cjs/{utils/promise-sleep.test.d.ts → promise-sleep.test.d.ts} +0 -0
  440. /package/esm/{utils/promise-sleep.d.ts → promise-sleep.d.ts} +0 -0
  441. /package/esm/{utils/promise-sleep.test.d.ts → promise-sleep.test.d.ts} +0 -0
  442. /package/esm/{utils/promise-sleep.test.js → promise-sleep.test.js} +0 -0
  443. /package/ts/cjs/{utils/promise-sleep.d.ts → promise-sleep.d.ts} +0 -0
  444. /package/ts/cjs/{utils/promise-sleep.test.d.ts → promise-sleep.test.d.ts} +0 -0
  445. /package/ts/cjs/{utils/promise-sleep.test.js → promise-sleep.test.js} +0 -0
  446. /package/ts/esm/{utils/promise-sleep.d.ts → promise-sleep.d.ts} +0 -0
  447. /package/ts/esm/{utils/promise-sleep.test.d.ts → promise-sleep.test.d.ts} +0 -0
  448. /package/ts/esm/{utils/promise-sleep.test.js → promise-sleep.test.js} +0 -0
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Utilities for executing functions once and caching results, with support for both
3
+ * synchronous and asynchronous operations, sequential execution, and keyed collections.
4
+ *
5
+ * ## Main Classes
6
+ *
7
+ * - **ResolveOnce**: Ensures a function executes only once, automatically handling sync/async
8
+ * - **ResolveSeq**: Executes functions sequentially, maintaining order even with concurrent calls
9
+ * - **Keyed**: Base class for managing keyed instances with LRU caching
10
+ * - **KeyedResolveOnce**: Map of ResolveOnce instances indexed by keys
11
+ * - **KeyedResolveSeq**: Map of ResolveSeq instances indexed by keys
12
+ * - **Lazy**: Function wrapper that executes once and caches the result
13
+ *
14
+ * @module resolve-once
15
+ */
16
+
1
17
  import { Future } from "./future.js";
2
18
  import { UnPromisify } from "./is-promise.js";
3
19
  import { isPromise } from "./is-promise.js";
@@ -5,13 +21,39 @@ import { LRUMap, LRUParam, UnregFn } from "./lru-map-set.js";
5
21
  import { Result } from "./result.js";
6
22
  import { Option } from "./option.js";
7
23
 
8
- // interface ResolveSeqItem<C, R extends NonPromise<X>, X = string | number | boolean | symbol | object> {
24
+ /**
25
+ * Internal item representing a queued function in a ResolveSeq sequence.
26
+ * @internal
27
+ */
9
28
  interface ResolveSeqItem<C, T, R> {
10
29
  readonly future: Future<T>;
11
30
  readonly fn: (c: C) => R;
12
31
  readonly id?: number;
13
32
  }
14
33
 
34
+ /**
35
+ * Executes functions sequentially, one at a time, ensuring order of execution.
36
+ *
37
+ * ResolveSeq maintains a queue of functions and executes them in order, waiting for each
38
+ * to complete before starting the next. This is useful when you need to ensure operations
39
+ * happen in a specific sequence, even when multiple operations are queued concurrently.
40
+ *
41
+ * @template T - The return type of the functions
42
+ * @template CTX - Optional context type passed to each function
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const seq = new ResolveSeq<number>();
47
+ *
48
+ * // Multiple calls are queued and executed in order
49
+ * const p1 = seq.add(() => asyncOperation1());
50
+ * const p2 = seq.add(() => asyncOperation2());
51
+ * const p3 = seq.add(() => asyncOperation3());
52
+ *
53
+ * // Operations execute sequentially: op1 -> op2 -> op3
54
+ * await Promise.all([p1, p2, p3]);
55
+ * ```
56
+ */
15
57
  export class ResolveSeq<T, CTX extends NonNullable<object> = object> {
16
58
  readonly ctx?: CTX;
17
59
  readonly _seqFutures: ResolveSeqItem<CTX, T, unknown>[] = [];
@@ -19,11 +61,21 @@ export class ResolveSeq<T, CTX extends NonNullable<object> = object> {
19
61
  constructor(ctx?: CTX) {
20
62
  this.ctx = ctx;
21
63
  }
64
+
65
+ /**
66
+ * Resets the sequence (currently a no-op).
67
+ */
22
68
  reset(): void {
23
69
  /* noop */
24
70
  }
25
71
 
26
72
  readonly _flushWaiting: Future<void>[] = [];
73
+
74
+ /**
75
+ * Returns a promise that resolves when all currently queued items complete.
76
+ *
77
+ * @returns A promise that resolves when the queue is empty
78
+ */
27
79
  flush(): Promise<void> {
28
80
  if (this._seqFutures.length > 0) {
29
81
  const waitForFlush = new Future<void>();
@@ -32,6 +84,11 @@ export class ResolveSeq<T, CTX extends NonNullable<object> = object> {
32
84
  }
33
85
  return Promise.resolve();
34
86
  }
87
+
88
+ /**
89
+ * Internal method to process items in the queue sequentially.
90
+ * @internal
91
+ */
35
92
  async _step(item?: ResolveSeqItem<CTX, T, Promise<T> | T>): Promise<void> {
36
93
  if (!item) {
37
94
  // done
@@ -55,6 +112,17 @@ export class ResolveSeq<T, CTX extends NonNullable<object> = object> {
55
112
  }
56
113
  return this._step(this._seqFutures[0] as ResolveSeqItem<CTX, T, Promise<T> | T>);
57
114
  }
115
+
116
+ /**
117
+ * Adds a function to the sequence queue for sequential execution.
118
+ *
119
+ * The function will be executed after all previously queued functions complete.
120
+ * Returns a promise that resolves with the function's result.
121
+ *
122
+ * @param fn - The function to execute
123
+ * @param id - Optional identifier for tracking
124
+ * @returns A promise that resolves with the function's result
125
+ */
58
126
  add<R extends Promise<T> | T>(fn: (c: CTX) => R, id?: number): R {
59
127
  const future = new Future<T>();
60
128
  this._seqFutures.push({ future, fn, id });
@@ -65,22 +133,33 @@ export class ResolveSeq<T, CTX extends NonNullable<object> = object> {
65
133
  }
66
134
  }
67
135
 
68
- // readonly _onceFutures: Future<T>[] = [];
69
- // _onceDone = false;
70
- // _onceOk = false;
71
- // _onceValue?: T;
72
- // _onceError?: Error;
73
- // _isPromise = false;
74
- // _inProgress?: Future<T>;
75
-
76
- // ResolveOnce
77
- // cases SyncMode, AsyncMode
78
-
136
+ /**
137
+ * Represents the current state of a resolve operation.
138
+ * - `initial`: Not yet started
139
+ * - `processed`: Completed
140
+ * - `waiting`: Waiting for async operation
141
+ * - `processing`: Currently executing
142
+ */
79
143
  type ResolveState = "initial" | "processed" | "waiting" | "processing";
80
144
 
81
- // export type VoidEqualUndefined<T> = T extends undefined ? void : T
145
+ /**
146
+ * Type helper that unwraps Promise types to their resolved value type.
147
+ *
148
+ * @template R - The type to unwrap
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * type A = ResultOnce<Promise<number>>; // Promise<number>
153
+ * type B = ResultOnce<string>; // string
154
+ * ```
155
+ */
82
156
  export type ResultOnce<R> = R extends Promise<infer T> ? Promise<T> : R;
83
157
 
158
+ /**
159
+ * Interface defining the contract for ResolveOnce-like objects.
160
+ * @template R - The return type
161
+ * @template CTX - Optional context type
162
+ */
84
163
  export interface ResolveOnceIf<R, CTX = void> {
85
164
  get ready(): boolean;
86
165
  get value(): UnPromisify<R> | undefined;
@@ -91,6 +170,16 @@ export interface ResolveOnceIf<R, CTX = void> {
91
170
  reset<R>(fn?: (c?: CTX) => R): ResultOnce<R>;
92
171
  }
93
172
 
173
+ /**
174
+ * Synchronous version of ResolveOnce for functions that return non-promise values.
175
+ *
176
+ * This class is used internally by ResolveOnce when it detects a synchronous function.
177
+ * It executes the function once and caches the result or error for subsequent calls.
178
+ *
179
+ * @template T - The return type
180
+ * @template CTX - Optional context type
181
+ * @internal
182
+ */
94
183
  export class SyncResolveOnce<T, CTX = void> {
95
184
  state: ResolveState = "initial";
96
185
 
@@ -99,14 +188,23 @@ export class SyncResolveOnce<T, CTX = void> {
99
188
 
100
189
  readonly queueLength = 0;
101
190
 
191
+ /**
192
+ * Gets the cached value if available.
193
+ */
102
194
  get value(): T | undefined {
103
195
  return this.#value;
104
196
  }
105
197
 
198
+ /**
199
+ * Gets the cached error if one occurred.
200
+ */
106
201
  get error(): Error | undefined {
107
202
  return this.#error;
108
203
  }
109
204
 
205
+ /**
206
+ * Returns true if the function has been executed.
207
+ */
110
208
  get ready(): boolean {
111
209
  return this.state === "processed";
112
210
  }
@@ -116,6 +214,14 @@ export class SyncResolveOnce<T, CTX = void> {
116
214
  this.#ctx = ctx;
117
215
  }
118
216
 
217
+ /**
218
+ * Executes the function once and caches the result.
219
+ * Subsequent calls return the cached value without re-executing.
220
+ *
221
+ * @param fn - The function to execute
222
+ * @returns The result of the function
223
+ * @throws Error if the function returned a promise (use AsyncResolveOnce instead)
224
+ */
119
225
  resolve(fn: (ctx?: CTX) => T): T {
120
226
  if (this.state === "initial") {
121
227
  this.state = "processed";
@@ -134,6 +240,12 @@ export class SyncResolveOnce<T, CTX = void> {
134
240
  return this.#value as T;
135
241
  }
136
242
 
243
+ /**
244
+ * Resets the cached state, allowing the function to be executed again.
245
+ *
246
+ * @param fn - Optional function to execute immediately after reset
247
+ * @returns The result if fn provided, undefined otherwise
248
+ */
137
249
  reset(fn?: (c?: CTX) => T): T | undefined {
138
250
  this.state = "initial";
139
251
  this.#value = undefined;
@@ -145,6 +257,11 @@ export class SyncResolveOnce<T, CTX = void> {
145
257
  }
146
258
  }
147
259
 
260
+ /**
261
+ * Internal helper for AsyncResolveOnce that manages a single async resolution.
262
+ * Handles queuing of multiple concurrent requests for the same async operation.
263
+ * @internal
264
+ */
148
265
  class AsyncResolveItem<T> {
149
266
  readonly id = Math.random();
150
267
  #state: ResolveState = "initial";
@@ -170,6 +287,9 @@ class AsyncResolveItem<T> {
170
287
  return this.#queue.length;
171
288
  }
172
289
 
290
+ /**
291
+ * Returns true if this item has completed and has no pending futures.
292
+ */
173
293
  isDisposable(): boolean {
174
294
  return this.#state === "processed" && this.#queue.length === 0;
175
295
  }
@@ -197,11 +317,13 @@ class AsyncResolveItem<T> {
197
317
  throw new Error("AsyncResolveItem.#promiseResult impossible");
198
318
  }
199
319
 
320
+ /**
321
+ * Resolves the async operation, queuing the request if already in progress.
322
+ */
200
323
  resolve(): T {
201
324
  if (this.#state === "initial") {
202
325
  this.#state = "waiting";
203
326
  const future = new Future<UnPromisify<T>>();
204
- // console.log("asyncItem addQueue#initial", this.id, this.#queue.length);
205
327
  this.#queue.push(future);
206
328
  this.#toResolve
207
329
  .then((value) => {
@@ -223,7 +345,6 @@ class AsyncResolveItem<T> {
223
345
  }
224
346
  if (this.#state === "waiting") {
225
347
  const future = new Future<UnPromisify<T>>();
226
- // console.log("asyncItem addQueue#waiting", this.id, this.#queue.length);
227
348
  this.#queue.push(future);
228
349
  return future.asPromise() as T;
229
350
  }
@@ -231,8 +352,18 @@ class AsyncResolveItem<T> {
231
352
  }
232
353
  }
233
354
 
355
+ /**
356
+ * Asynchronous version of ResolveOnce for functions that return promises.
357
+ *
358
+ * This class is used internally by ResolveOnce when it detects an async function.
359
+ * It executes the async function once and caches the result for subsequent calls.
360
+ * Multiple concurrent calls while waiting will all receive the same promise result.
361
+ *
362
+ * @template T - The return type (Promise or value)
363
+ * @template CTX - Optional context type
364
+ * @internal
365
+ */
234
366
  export class AsyncResolveOnce<T, CTX = void> {
235
- // readonly id = Math.random();
236
367
  state: ResolveState = "initial";
237
368
 
238
369
  readonly #queue: AsyncResolveItem<T>[] = [];
@@ -250,13 +381,23 @@ export class AsyncResolveOnce<T, CTX = void> {
250
381
  return r;
251
382
  }
252
383
 
384
+ /**
385
+ * Returns the total number of queued futures across all items.
386
+ */
253
387
  get queueLength(): number {
254
388
  return this.#queue.reduce((acc, r) => acc + r.queuelength, this.#queue.length);
255
389
  }
256
390
 
391
+ /**
392
+ * Returns true if the async operation has started.
393
+ */
257
394
  get ready(): boolean {
258
395
  return this.state !== "initial";
259
396
  }
397
+
398
+ /**
399
+ * Gets the cached resolved value if available.
400
+ */
260
401
  get value(): UnPromisify<T> | undefined {
261
402
  if (this.state === "initial") {
262
403
  return undefined;
@@ -264,6 +405,9 @@ export class AsyncResolveOnce<T, CTX = void> {
264
405
  return this.#active().value;
265
406
  }
266
407
 
408
+ /**
409
+ * Gets the cached error if one occurred.
410
+ */
267
411
  get error(): Error | undefined {
268
412
  if (this.state === "initial") {
269
413
  return undefined;
@@ -271,6 +415,13 @@ export class AsyncResolveOnce<T, CTX = void> {
271
415
  return this.#active().error;
272
416
  }
273
417
 
418
+ /**
419
+ * Executes the async function once and caches the result.
420
+ * Subsequent calls return the cached promise without re-executing.
421
+ *
422
+ * @param fn - The async function to execute
423
+ * @returns A promise that resolves to the function's result
424
+ */
274
425
  resolve(fn: (ctx?: CTX) => T): T {
275
426
  if (this.state === "initial") {
276
427
  this.state = "waiting";
@@ -285,7 +436,6 @@ export class AsyncResolveOnce<T, CTX = void> {
285
436
  } catch (e) {
286
437
  promiseResult = Promise.reject(e as Error);
287
438
  }
288
- // console.log("asyncOnce addQueue#initial", this.id, this.#queue.length);
289
439
  this.#queue.push(new AsyncResolveItem(promiseResult));
290
440
  }
291
441
  // remove all disposable items
@@ -299,6 +449,12 @@ export class AsyncResolveOnce<T, CTX = void> {
299
449
  return this.#active().resolve();
300
450
  }
301
451
 
452
+ /**
453
+ * Resets the cached state, allowing the function to be executed again.
454
+ *
455
+ * @param fn - Optional function to execute immediately after reset
456
+ * @returns The result if fn provided, undefined otherwise
457
+ */
302
458
  reset(fn?: (c?: CTX) => T): T {
303
459
  this.state = "initial";
304
460
  if (fn) {
@@ -308,6 +464,30 @@ export class AsyncResolveOnce<T, CTX = void> {
308
464
  }
309
465
  }
310
466
 
467
+ /**
468
+ * Ensures a function is executed only once, caching and returning the result for subsequent calls.
469
+ *
470
+ * ResolveOnce automatically detects whether the function returns a synchronous value or a Promise,
471
+ * and handles both cases appropriately. All subsequent calls will receive the same cached result.
472
+ * Supports optional context parameter and can be reset to allow re-execution.
473
+ *
474
+ * @template T - The return type of the function (can be synchronous or Promise)
475
+ * @template CTX - Optional context type passed to the function
476
+ *
477
+ * @example
478
+ * ```typescript
479
+ * const expensiveOp = new ResolveOnce<number>();
480
+ *
481
+ * // First call executes the function
482
+ * const result1 = expensiveOp.once(() => computeExpensiveValue());
483
+ *
484
+ * // Subsequent calls return cached result
485
+ * const result2 = expensiveOp.once(() => computeExpensiveValue()); // Not executed
486
+ *
487
+ * // Reset to allow re-execution
488
+ * expensiveOp.reset();
489
+ * ```
490
+ */
311
491
  export class ResolveOnce<T, CTX = void> implements ResolveOnceIf<T, CTX> {
312
492
  #state: ResolveState = "initial";
313
493
 
@@ -393,15 +573,142 @@ export class ResolveOnce<T, CTX = void> implements ResolveOnceIf<T, CTX> {
393
573
  }
394
574
  }
395
575
 
576
+ /**
577
+ * Configuration parameters for Keyed instances.
578
+ * @template K - The key type
579
+ * @template V - The value type
580
+ */
396
581
  export interface KeyedParam<K, V> {
397
582
  readonly lru: Partial<LRUParam<V, K>>;
398
583
  }
399
584
 
585
+ /**
586
+ * Extended configuration that includes context.
587
+ * @template K - The key type
588
+ * @template V - The value type
589
+ * @template CTX - The context type
590
+ */
400
591
  export type AddKeyedParam<K, V, CTX extends NonNullable<object>> = KeyedParam<K, V> & { readonly ctx: CTX };
401
592
 
402
- export class Keyed<T extends { reset: () => void }, K = string, CTX extends NonNullable<object> = object> {
593
+ export interface KeyedIf<T extends { reset: () => void }, K = string> {
594
+ /**
595
+ * Registers a callback that fires when a new entry is added to the map.
596
+ *
597
+ * @param fn - Callback function receiving key and value
598
+ * @returns Unregister function to remove the callback
599
+ */
600
+ onSet(fn: (key: K, value: T) => void): UnregFn;
601
+
602
+ /**
603
+ * Registers a callback that fires when an entry is deleted from the map.
604
+ *
605
+ * @param fn - Callback function receiving key and value
606
+ * @returns Unregister function to remove the callback
607
+ */
608
+ onDelete(fn: (key: K, value: T) => void): UnregFn;
609
+
610
+ /**
611
+ * Updates the LRU parameters of the underlying map.
612
+ *
613
+ * @param params - New parameters to apply
614
+ */
615
+ setParam(params: KeyedParam<K, T>): void;
616
+
617
+ /**
618
+ * Async variant of get() that accepts a function returning a promise for the key.
619
+ *
620
+ * @param key - Function that returns a promise resolving to the key
621
+ * @returns Promise resolving to the value
622
+ */
623
+ asyncGet(key: () => Promise<K>): Promise<T>;
624
+
625
+ /**
626
+ * Gets or creates a value for the given key.
627
+ *
628
+ * If the key doesn't exist, creates a new instance using the factory function.
629
+ *
630
+ * @param key - The key or function returning the key
631
+ * @returns The value associated with the key
632
+ */
633
+ get(key: K | (() => K)): T;
634
+
635
+ /**
636
+ * Checks if a key exists in the map.
637
+ *
638
+ * @param key - The key or function returning the key
639
+ * @returns True if the key exists
640
+ */
641
+ has(key: K | (() => K)): boolean;
642
+
643
+ /**
644
+ * Deletes an entry from the map.
645
+ *
646
+ * @param key - The key to delete
647
+ */
648
+ delete(key: K): void;
649
+
650
+ /**
651
+ * Resets and deletes an entry from the map.
652
+ *
653
+ * Calls the value's reset() method before removing it.
654
+ *
655
+ * @param key - The key to reset and delete
656
+ */
657
+ unget(key: K): void;
658
+
659
+ /**
660
+ * Resets all entries and clears the map.
661
+ *
662
+ * Calls reset() on all values before clearing.
663
+ */
664
+ reset(): void;
665
+
666
+ /**
667
+ * Returns all values in the map.
668
+ *
669
+ * @returns Array of all values
670
+ */
671
+ values(): T[];
672
+
673
+ /**
674
+ * Returns all keys in the map.
675
+ *
676
+ * @returns Array of all keys
677
+ */
678
+ keys(): K[];
679
+
680
+ /**
681
+ * Iterates over all entries in the map.
682
+ *
683
+ * @yields Key-value pairs
684
+ */
685
+ forEach(fn: (k: K, v: T, idx: number) => void): void;
686
+
687
+ entries(): Iterable<[K, T]>;
688
+ }
689
+
690
+ /**
691
+ * Base class for managing keyed instances with LRU caching.
692
+ *
693
+ * Keyed provides a map-like interface where values are lazily created via a factory function
694
+ * and cached with optional LRU eviction. Values must have a `reset()` method for cleanup.
695
+ *
696
+ * @template T - The value type (must have a reset method)
697
+ * @template K - The key type
698
+ * @template CTX - Optional context type passed to the factory
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * const keyed = new Keyed(
703
+ * (ctx) => new ResolveOnce(ctx),
704
+ * { lru: { maxEntries: 100 } }
705
+ * );
706
+ *
707
+ * const instance = keyed.get('myKey');
708
+ * ```
709
+ */
710
+ export class Keyed<T extends { reset: () => void }, K = string, CTX extends NonNullable<object> = object> implements KeyedIf<T, K> {
403
711
  protected readonly _map: LRUMap<K, T>;
404
- // #lock = new ResolveSeq<T, K>();
405
712
  readonly #ctx: CTX;
406
713
 
407
714
  readonly factory: (ctx: AddKey<CTX, K>) => T;
@@ -412,22 +719,53 @@ export class Keyed<T extends { reset: () => void }, K = string, CTX extends NonN
412
719
  this._map = new LRUMap<K, T>(ctx?.lru ?? ({ maxEntries: -1 } as LRUParam<T, K>));
413
720
  }
414
721
 
722
+ /**
723
+ * Registers a callback that fires when a new entry is added to the map.
724
+ *
725
+ * @param fn - Callback function receiving key and value
726
+ * @returns Unregister function to remove the callback
727
+ */
415
728
  onSet(fn: (key: K, value: T) => void): UnregFn {
416
729
  return this._map.onSet(fn);
417
730
  }
418
731
 
732
+ /**
733
+ * Registers a callback that fires when an entry is deleted from the map.
734
+ *
735
+ * @param fn - Callback function receiving key and value
736
+ * @returns Unregister function to remove the callback
737
+ */
419
738
  onDelete(fn: (key: K, value: T) => void): UnregFn {
420
739
  return this._map.onDelete(fn);
421
740
  }
422
741
 
742
+ /**
743
+ * Updates the LRU parameters of the underlying map.
744
+ *
745
+ * @param params - New parameters to apply
746
+ */
423
747
  setParam(params: KeyedParam<K, T>): void {
424
748
  this._map.setParam(params.lru);
425
749
  }
426
750
 
751
+ /**
752
+ * Async variant of get() that accepts a function returning a promise for the key.
753
+ *
754
+ * @param key - Function that returns a promise resolving to the key
755
+ * @returns Promise resolving to the value
756
+ */
427
757
  async asyncGet(key: () => Promise<K>): Promise<T> {
428
758
  return this.get(await key());
429
759
  }
430
760
 
761
+ /**
762
+ * Gets or creates a value for the given key.
763
+ *
764
+ * If the key doesn't exist, creates a new instance using the factory function.
765
+ *
766
+ * @param key - The key or function returning the key
767
+ * @returns The value associated with the key
768
+ */
431
769
  get(key: K | (() => K)): T {
432
770
  if (typeof key === "function") {
433
771
  key = (key as () => K)();
@@ -440,6 +778,12 @@ export class Keyed<T extends { reset: () => void }, K = string, CTX extends NonN
440
778
  return keyed;
441
779
  }
442
780
 
781
+ /**
782
+ * Checks if a key exists in the map.
783
+ *
784
+ * @param key - The key or function returning the key
785
+ * @returns True if the key exists
786
+ */
443
787
  has(key: K | (() => K)): boolean {
444
788
  if (typeof key === "function") {
445
789
  key = (key as () => K)();
@@ -447,66 +791,243 @@ export class Keyed<T extends { reset: () => void }, K = string, CTX extends NonN
447
791
  return this._map.has(key);
448
792
  }
449
793
 
450
- // lock<R extends Promisable<T>>(fn: (map: LRUMap<K, T>) => R): Promise<UnPromisify<R>> {
451
- // return this.#lock.add(() => fn(this._map));
452
- // }
453
-
794
+ /**
795
+ * Deletes an entry from the map.
796
+ *
797
+ * @param key - The key to delete
798
+ */
454
799
  delete(key: K): void {
455
800
  this._map.delete(key);
456
801
  }
457
802
 
803
+ /**
804
+ * Resets and deletes an entry from the map.
805
+ *
806
+ * Calls the value's reset() method before removing it.
807
+ *
808
+ * @param key - The key to reset and delete
809
+ */
458
810
  unget(key: K): void {
459
811
  const keyed = this._map.get(key);
460
812
  keyed?.reset();
461
813
  this._map.delete(key);
462
814
  }
463
815
 
816
+ /**
817
+ * Resets all entries and clears the map.
818
+ *
819
+ * Calls reset() on all values before clearing.
820
+ */
464
821
  reset(): void {
465
822
  this._map.forEach((keyed) => keyed.reset());
466
823
  this._map.clear();
467
824
  }
825
+
826
+ /**
827
+ * Returns all values in the map.
828
+ *
829
+ * @returns Array of all values
830
+ */
831
+ values(): T[] {
832
+ const results: T[] = [];
833
+ this.forEach((_, v) => {
834
+ results.push(v);
835
+ });
836
+ return results;
837
+ }
838
+
839
+ /**
840
+ * Returns all keys in the map.
841
+ *
842
+ * @returns Array of all keys
843
+ */
844
+ keys(): K[] {
845
+ const results: K[] = [];
846
+ this.forEach((k) => {
847
+ results.push(k);
848
+ });
849
+ return results;
850
+ }
851
+
852
+ /**
853
+ * Iterates over all entries in the map.
854
+ *
855
+ * @yields Key-value pairs
856
+ */
857
+ forEach(fn: (k: K, v: T, idx: number) => void): void {
858
+ let idx = 0;
859
+ for (const [k, v] of this._map.entries()) {
860
+ fn(k, v, idx++);
861
+ }
862
+ }
863
+
864
+ *entries(): Iterable<[K, T]> {
865
+ for (const [k, v] of this._map.entries()) {
866
+ yield [k, v];
867
+ }
868
+ }
468
869
  }
469
870
 
871
+ /**
872
+ * Represents a key-value pair where the value is wrapped in a Result.
873
+ * @template K - The key type
874
+ * @template V - The value type
875
+ */
470
876
  export interface KeyItem<K, V> {
471
877
  readonly key: K;
472
878
  readonly value: Result<V>;
473
879
  }
474
880
 
475
- export class KeyedResolvOnce<T, K = string, CTX extends NonNullable<object> = object> extends Keyed<
476
- ResolveOnce<T, AddKey<CTX, K>>,
477
- K,
478
- CTX
479
- > {
881
+ /**
882
+ * Keyed collection of ResolveOnce instances.
883
+ *
884
+ * Manages a map of ResolveOnce instances indexed by keys, with optional LRU caching.
885
+ * Each key gets its own ResolveOnce instance that can be accessed and manipulated independently.
886
+ *
887
+ * @template T - The return type of the ResolveOnce instances
888
+ * @template K - The key type
889
+ * @template CTX - Optional context type
890
+ *
891
+ * @example
892
+ * ```typescript
893
+ * const cache = new KeyedResolvOnce<number, string>();
894
+ *
895
+ * // Each key gets its own ResolveOnce
896
+ * const result1 = cache.get('key1').once(() => expensiveCalc1());
897
+ * const result2 = cache.get('key2').once(() => expensiveCalc2());
898
+ * ```
899
+ */
900
+ export class KeyedResolvOnce<T, K = string, CTX extends NonNullable<object> = object>
901
+ implements Omit<KeyedIf<ResolveOnce<T, AddKey<CTX, K>>, K>, "forEach" | "keys" | "values" | "entries">
902
+ {
903
+ readonly _keyed: KeyedIf<ResolveOnce<T, AddKey<CTX, K>>, K>;
480
904
  constructor(kp: Partial<AddKeyedParam<K, ResolveOnce<T, CTX>, CTX>> = {}) {
481
- // need the upcast we add to ResolvOnce CTX the Key
482
- super((ctx) => new ResolveOnce<T, AddKey<CTX, K>>(ctx), kp as AddKeyedParam<K, ResolveOnce<T, AddKey<CTX, K>>, CTX>);
905
+ this._keyed = new Keyed(
906
+ (ctx) => new ResolveOnce<T, AddKey<CTX, K>>(ctx),
907
+ kp as AddKeyedParam<K, ResolveOnce<T, AddKey<CTX, K>>, CTX>,
908
+ );
909
+ }
910
+ keys(): K[] {
911
+ const results: K[] = [];
912
+ this.forEach((k) => {
913
+ results.push(k.key);
914
+ });
915
+ return results;
916
+ }
917
+ values(): KeyItem<K, T>[] {
918
+ const results: KeyItem<K, T>[] = [];
919
+ this.forEach((v) => {
920
+ results.push(v);
921
+ });
922
+ return results;
923
+ }
924
+ onSet(fn: (key: K, value: ResolveOnce<T, AddKey<CTX, K>>) => void): UnregFn {
925
+ return this._keyed.onSet(fn);
926
+ }
927
+ onDelete(fn: (key: K, value: ResolveOnce<T, AddKey<CTX, K>>) => void): UnregFn {
928
+ return this._keyed.onDelete(fn);
929
+ }
930
+ setParam(params: KeyedParam<K, ResolveOnce<T, AddKey<CTX, K>>>): void {
931
+ this._keyed.setParam(params);
932
+ }
933
+ asyncGet(key: () => Promise<K>): Promise<ResolveOnce<T, AddKey<CTX, K>>> {
934
+ return this._keyed.asyncGet(key);
935
+ }
936
+ get(key: K | (() => K)): ResolveOnce<T, AddKey<CTX, K>> {
937
+ return this._keyed.get(key);
938
+ }
939
+ has(key: K | (() => K)): boolean {
940
+ return this._keyed.has(key);
941
+ }
942
+ delete(key: K): void {
943
+ this._keyed.delete(key);
944
+ }
945
+ unget(key: K): void {
946
+ this._keyed.unget(key);
947
+ }
948
+ reset(): void {
949
+ this._keyed.reset();
483
950
  }
484
951
 
485
- *entries(): IterableIterator<KeyItem<K, T>> {
486
- for (const [k, v] of this._map.entries()) {
952
+ /**
953
+ * Iterates over all completed entries, yielding key-result pairs.
954
+ *
955
+ * Only yields entries that have been resolved (ready state).
956
+ * Values are wrapped in Result to distinguish success from error.
957
+ *
958
+ * @yields Key-result pairs for completed entries
959
+ */
960
+ forEach(fn: (ki: KeyItem<K, T>, idx: number) => void): void {
961
+ let idx = 0;
962
+ for (const [k, v] of this._keyed.entries()) {
487
963
  if (!v.ready) {
488
964
  continue;
489
965
  }
490
966
  if (v.error) {
491
- yield { key: k, value: Result.Err<T>(v.error) };
967
+ fn({ key: k, value: Result.Err<T>(v.error) }, idx++);
492
968
  } else {
493
- yield { key: k, value: Result.Ok<T>(v.value as T) };
969
+ fn({ key: k, value: Result.Ok<T>(v.value as T) }, idx++);
494
970
  }
495
971
  }
496
972
  }
497
973
 
498
- /**
499
- *
500
- * @returns The values of the resolved keys
501
- */
502
- values(): KeyItem<K, T>[] {
503
- return Array.from(this.entries());
974
+ *entries(): Iterable<KeyItem<K, T>> {
975
+ /* this is not optimal, but sufficient for now */
976
+ for (const [k, v] of this._keyed.entries()) {
977
+ if (!v.ready) {
978
+ continue;
979
+ }
980
+ if (v.error) {
981
+ yield { key: k, value: Result.Err<T>(v.error) };
982
+ } else {
983
+ yield { key: k, value: Result.Ok<T>(v.value as T) };
984
+ }
985
+ }
504
986
  }
505
987
  }
506
988
 
989
+ /**
990
+ * Type helper that adds a key property to a context object.
991
+ *
992
+ * Used by keyed collections to provide the current key to factory functions and callbacks.
993
+ *
994
+ * @template X - The context type
995
+ * @template K - The key type
996
+ *
997
+ * @example
998
+ * ```typescript
999
+ * type MyContext = { userId: string };
1000
+ * type WithKey = AddKey<MyContext, number>;
1001
+ * // Result: { userId: string, key: number }
1002
+ * ```
1003
+ */
507
1004
  export type AddKey<X extends NonNullable<object>, K> = X & { key: K };
1005
+
1006
+ /**
1007
+ * Configuration type for KeyedResolvSeq.
1008
+ * @internal
1009
+ */
508
1010
  type WithCTX<K, T, CTX extends NonNullable<object>> = KeyedParam<K, ResolveSeq<T, AddKey<CTX, K>>> & { readonly ctx: CTX };
509
1011
 
1012
+ /**
1013
+ * Keyed collection of ResolveSeq instances.
1014
+ *
1015
+ * Manages a map of ResolveSeq instances indexed by keys, with optional LRU caching.
1016
+ * Each key gets its own ResolveSeq instance for sequential execution of operations.
1017
+ *
1018
+ * @template T - The return type of the ResolveSeq instances
1019
+ * @template K - The key type
1020
+ * @template CTX - Optional context type
1021
+ *
1022
+ * @example
1023
+ * ```typescript
1024
+ * const sequences = new KeyedResolvSeq<number, string>();
1025
+ *
1026
+ * // Each key gets its own sequential executor
1027
+ * sequences.get('user1').add(() => updateUser1());
1028
+ * sequences.get('user2').add(() => updateUser2());
1029
+ * ```
1030
+ */
510
1031
  export class KeyedResolvSeq<T extends NonNullable<unknown>, K = string, CTX extends NonNullable<object> = object> extends Keyed<
511
1032
  ResolveSeq<T, AddKey<CTX, K>>,
512
1033
  K,
@@ -517,6 +1038,10 @@ export class KeyedResolvSeq<T extends NonNullable<unknown>, K = string, CTX exte
517
1038
  }
518
1039
  }
519
1040
 
1041
+ /**
1042
+ * Internal helper class for the Lazy function.
1043
+ * @internal
1044
+ */
520
1045
  class LazyContainer<T> {
521
1046
  readonly resolveOnce = new ResolveOnce<T>();
522
1047
 
@@ -526,8 +1051,29 @@ class LazyContainer<T> {
526
1051
  }
527
1052
  }
528
1053
 
529
- // T extends (...args: infer P) => any
530
- // export function Lazy<R extends (...args: infer P) => infer X >(fn: R): (...args: P) =>infer
1054
+ /**
1055
+ * Creates a lazy-evaluated version of a function that executes only once and caches the result.
1056
+ *
1057
+ * The returned function will execute the original function on first call and return
1058
+ * the cached result for all subsequent calls, regardless of arguments. This is useful
1059
+ * for expensive computations or resource initialization.
1060
+ *
1061
+ * @template Args - The argument types of the function
1062
+ * @template Return - The return type of the function
1063
+ * @param fn - The function to make lazy
1064
+ * @returns A wrapped function that executes once and caches the result
1065
+ *
1066
+ * @example
1067
+ * ```typescript
1068
+ * const getConfig = Lazy(() => {
1069
+ * console.log('Loading config...');
1070
+ * return { apiKey: 'secret' };
1071
+ * });
1072
+ *
1073
+ * getConfig(); // Logs "Loading config..." and returns config
1074
+ * getConfig(); // Returns cached config without logging
1075
+ * ```
1076
+ */
531
1077
  export function Lazy<Args extends readonly unknown[], Return>(fn: (...args: Args) => Return): (...args: Args) => Return {
532
1078
  const lazy = new LazyContainer<Return>();
533
1079
  return lazy.call(fn);