@oscarpalmer/atoms 0.212.0 → 0.214.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 (258) hide show
  1. package/dist/array/difference.d.mts +1 -1
  2. package/dist/array/difference.mjs +3 -2
  3. package/dist/array/exists.d.mts +1 -1
  4. package/dist/array/exists.mjs +3 -2
  5. package/dist/array/filter.d.mts +1 -1
  6. package/dist/array/filter.mjs +1 -0
  7. package/dist/array/find.d.mts +1 -1
  8. package/dist/array/find.mjs +4 -3
  9. package/dist/array/first.d.mts +1 -1
  10. package/dist/array/flatten.d.mts +1 -1
  11. package/dist/array/group-by.d.mts +1 -1
  12. package/dist/array/index.d.mts +2 -2
  13. package/dist/array/insert.mjs +3 -2
  14. package/dist/array/intersection.mjs +3 -2
  15. package/dist/array/last.d.mts +1 -1
  16. package/dist/array/move.d.mts +1 -1
  17. package/dist/array/partition.d.mts +1 -1
  18. package/dist/array/partition.mjs +1 -0
  19. package/dist/array/push.mjs +3 -2
  20. package/dist/array/select.d.mts +10 -12
  21. package/dist/array/select.mjs +1 -0
  22. package/dist/array/single.d.mts +1 -1
  23. package/dist/array/single.mjs +1 -0
  24. package/dist/array/slice.d.mts +1 -1
  25. package/dist/array/slice.mjs +4 -5
  26. package/dist/array/sort.d.mts +4 -103
  27. package/dist/array/sort.mjs +6 -14
  28. package/dist/array/splice.mjs +3 -2
  29. package/dist/array/swap.d.mts +1 -1
  30. package/dist/array/to-map.d.mts +1 -1
  31. package/dist/array/to-record.d.mts +1 -1
  32. package/dist/array/to-set.d.mts +1 -1
  33. package/dist/array/toggle.d.mts +1 -1
  34. package/dist/array/union.mjs +3 -2
  35. package/dist/array/unique.d.mts +1 -1
  36. package/dist/array/unique.mjs +3 -2
  37. package/dist/array/update.d.mts +1 -1
  38. package/dist/beacon.d.mts +6 -92
  39. package/dist/beacon.mjs +6 -16
  40. package/dist/color/constants.d.mts +2 -2
  41. package/dist/color/constants.mjs +1 -1
  42. package/dist/color/index.d.mts +1 -1
  43. package/dist/color/instance.d.mts +1 -1
  44. package/dist/color/instance.mjs +0 -1
  45. package/dist/color/misc/alpha.d.mts +1 -1
  46. package/dist/color/misc/format.d.mts +1 -1
  47. package/dist/color/misc/get.d.mts +1 -1
  48. package/dist/color/misc/is.d.mts +2 -2
  49. package/dist/color/misc/is.mjs +1 -0
  50. package/dist/color/misc/state.d.mts +1 -1
  51. package/dist/color/space/hex.d.mts +1 -1
  52. package/dist/color/space/hsl.d.mts +1 -1
  53. package/dist/color/space/hwb.d.mts +1 -1
  54. package/dist/color/space/rgb.d.mts +1 -1
  55. package/dist/function/limit.d.mts +2 -2
  56. package/dist/function/limit.mjs +2 -1
  57. package/dist/function/once.d.mts +7 -3
  58. package/dist/function/once.mjs +5 -10
  59. package/dist/function/retry.d.mts +4 -14
  60. package/dist/function/retry.mjs +3 -15
  61. package/dist/herald.d.mts +2 -2
  62. package/dist/index.d.mts +466 -351
  63. package/dist/index.mjs +491 -439
  64. package/dist/internal/aborter.d.mts +1 -6
  65. package/dist/internal/aborter.mjs +3 -4
  66. package/dist/internal/array/callbacks.d.mts +3 -7
  67. package/dist/internal/array/chunk.mjs +2 -2
  68. package/dist/internal/array/find.d.mts +5 -23
  69. package/dist/internal/array/find.mjs +5 -9
  70. package/dist/internal/array/get.d.mts +1 -1
  71. package/dist/internal/array/group.d.mts +1 -1
  72. package/dist/internal/array/index-of.d.mts +1 -1
  73. package/dist/internal/array/index-of.mjs +4 -3
  74. package/dist/internal/array/insert.d.mts +2 -5
  75. package/dist/internal/array/insert.mjs +2 -4
  76. package/dist/internal/array/match.d.mts +2 -5
  77. package/dist/internal/array/match.mjs +10 -20
  78. package/dist/internal/array/overlap.d.mts +2 -10
  79. package/dist/internal/array/sets.d.mts +2 -5
  80. package/dist/internal/array/sets.mjs +5 -7
  81. package/dist/internal/function/assert.d.mts +5 -12
  82. package/dist/internal/function/assert.mjs +2 -2
  83. package/dist/internal/function/limit.d.mts +2 -37
  84. package/dist/internal/function/limit.mjs +4 -15
  85. package/dist/internal/function/memoize.d.mts +5 -70
  86. package/dist/internal/function/memoize.mjs +2 -5
  87. package/dist/internal/function/work.d.mts +16 -22
  88. package/dist/internal/function/work.mjs +1 -8
  89. package/dist/internal/herald.d.mts +3 -3
  90. package/dist/internal/herald.mjs +2 -1
  91. package/dist/internal/is.d.mts +1 -1
  92. package/dist/internal/math/aggregate.d.mts +2 -14
  93. package/dist/internal/math/aggregate.mjs +2 -5
  94. package/dist/internal/number.mjs +4 -7
  95. package/dist/internal/result/attempt.d.mts +1 -1
  96. package/dist/internal/result/misc.d.mts +1 -1
  97. package/dist/internal/string/case.mjs +6 -16
  98. package/dist/internal/string/misc.mjs +1 -3
  99. package/dist/internal/subscription.d.mts +1 -100
  100. package/dist/internal/subscription.mjs +3 -9
  101. package/dist/internal/value/compare.d.mts +4 -4
  102. package/dist/internal/value/compare.mjs +1 -1
  103. package/dist/internal/value/equal.d.mts +6 -57
  104. package/dist/internal/value/equal.mjs +5 -10
  105. package/dist/internal/value/get.d.mts +1 -1
  106. package/dist/internal/value/handlers.d.mts +2 -21
  107. package/dist/internal/value/has.d.mts +2 -2
  108. package/dist/internal/value/misc.d.mts +1 -1
  109. package/dist/internal/value/misc.mjs +8 -14
  110. package/dist/internal/value/set.d.mts +1 -1
  111. package/dist/internal/value/set.mjs +2 -2
  112. package/dist/is.mjs +3 -3
  113. package/dist/logger.d.mts +3 -70
  114. package/dist/logger.mjs +2 -5
  115. package/dist/math.d.mts +1 -1
  116. package/dist/math.mjs +2 -1
  117. package/dist/models/aborter.model.d.mts +12 -0
  118. package/dist/models/aborter.model.mjs +5 -0
  119. package/dist/models/array/array.find.model.d.mts +22 -0
  120. package/dist/models/array/array.find.model.mjs +8 -0
  121. package/dist/models/array/array.match.model.d.mts +14 -0
  122. package/dist/models/array/array.match.model.mjs +14 -0
  123. package/dist/models/array/array.misc.model.d.mts +36 -0
  124. package/dist/models/array/array.misc.model.mjs +12 -0
  125. package/dist/models/array/array.sort.model.d.mts +122 -0
  126. package/dist/models/array/array.sort.model.mjs +12 -0
  127. package/dist/models/beacon.model.d.mts +119 -0
  128. package/dist/models/beacon.model.mjs +16 -0
  129. package/dist/{color/models.d.mts → models/color.model.d.mts} +4 -4
  130. package/dist/models/function/assert.model.d.mts +13 -0
  131. package/dist/models/function/assert.model.mjs +4 -0
  132. package/dist/models/function/limiter.model.d.mts +71 -0
  133. package/dist/models/function/limiter.model.mjs +15 -0
  134. package/dist/models/function/memoize.model.d.mts +88 -0
  135. package/dist/models/function/memoize.model.mjs +7 -0
  136. package/dist/models/function/once.model.d.mts +76 -0
  137. package/dist/models/function/once.model.mjs +9 -0
  138. package/dist/models/function/retry.model.d.mts +17 -0
  139. package/dist/models/function/retry.model.mjs +17 -0
  140. package/dist/models/function/work.model.d.mts +20 -0
  141. package/dist/models/function/work.model.mjs +11 -0
  142. package/dist/{internal/models → models}/herald.model.d.mts +3 -3
  143. package/dist/{internal/models → models}/herald.model.mjs +2 -2
  144. package/dist/{models.d.mts → models/index.d.mts} +8 -50
  145. package/dist/models/logger.model.d.mts +83 -0
  146. package/dist/models/logger.model.mjs +7 -0
  147. package/dist/models/math.model.d.mts +16 -0
  148. package/dist/models/math.model.mjs +7 -0
  149. package/dist/models/misc.model.d.mts +10 -0
  150. package/dist/models/misc.model.mjs +11 -0
  151. package/dist/{internal/models → models}/plan.model.d.mts +17 -15
  152. package/dist/{internal/models → models}/plan.model.mjs +1 -1
  153. package/dist/models/promise.model.d.mts +119 -0
  154. package/dist/models/promise.model.mjs +47 -0
  155. package/dist/models/query.model.d.mts +9 -0
  156. package/dist/models/query.model.mjs +14 -0
  157. package/dist/models/queue.model.d.mts +251 -0
  158. package/dist/models/queue.model.mjs +29 -0
  159. package/dist/models/random.model.d.mts +6 -0
  160. package/dist/models/random.model.mjs +7 -0
  161. package/dist/{internal/models → models}/result.model.d.mts +10 -2
  162. package/dist/models/string/string.case.model.d.mts +19 -0
  163. package/dist/models/string/string.case.model.mjs +14 -0
  164. package/dist/models/string/string.fuzzy.model.d.mts +108 -0
  165. package/dist/models/string/string.fuzzy.model.mjs +9 -0
  166. package/dist/models/string/string.misc.model.d.mts +13 -0
  167. package/dist/models/string/string.misc.model.mjs +13 -0
  168. package/dist/models/string/string.normalize.model.d.mts +85 -0
  169. package/dist/models/string/string.normalize.model.mjs +43 -0
  170. package/dist/models/string/string.template.model.d.mts +50 -0
  171. package/dist/models/string/string.template.model.mjs +5 -0
  172. package/dist/models/subscription.model.d.mts +127 -0
  173. package/dist/models/subscription.model.mjs +10 -0
  174. package/dist/models/value/value.clone.model.d.mts +56 -0
  175. package/dist/models/value/value.clone.model.mjs +24 -0
  176. package/dist/models/value/value.diff.model.d.mts +61 -0
  177. package/dist/models/value/value.diff.model.mjs +6 -0
  178. package/dist/models/value/value.equal.model.d.mts +76 -0
  179. package/dist/models/value/value.equal.model.mjs +9 -0
  180. package/dist/models/value/value.handler.model.d.mts +27 -0
  181. package/dist/models/value/value.handler.model.mjs +1 -0
  182. package/dist/models/value/value.merge.model.d.mts +82 -0
  183. package/dist/models/value/value.merge.model.mjs +5 -0
  184. package/dist/models/value/value.misc.model.d.mts +33 -0
  185. package/dist/models/value/value.misc.model.mjs +12 -0
  186. package/dist/models/value/value.transform.model.d.mts +28 -0
  187. package/dist/models/value/value.transform.model.mjs +4 -0
  188. package/dist/plan/generate.d.mts +3 -2
  189. package/dist/plan/generate.mjs +14 -10
  190. package/dist/plan/index.d.mts +1 -1
  191. package/dist/plan/index.mjs +2 -2
  192. package/dist/plan/is.d.mts +31 -2
  193. package/dist/plan/is.mjs +45 -1
  194. package/dist/plan/misc.d.mts +21 -2
  195. package/dist/plan/misc.mjs +32 -2
  196. package/dist/plan/models.d.mts +1 -1
  197. package/dist/plan/result.d.mts +7 -7
  198. package/dist/plan/result.mjs +6 -6
  199. package/dist/plan/run.d.mts +5 -5
  200. package/dist/plan/run.mjs +6 -6
  201. package/dist/promise/delay.d.mts +1 -1
  202. package/dist/promise/delay.mjs +2 -1
  203. package/dist/promise/helpers.d.mts +2 -2
  204. package/dist/promise/helpers.mjs +6 -6
  205. package/dist/promise/index.d.mts +2 -2
  206. package/dist/promise/index.mjs +1 -1
  207. package/dist/promise/misc.d.mts +3 -3
  208. package/dist/promise/misc.mjs +7 -4
  209. package/dist/promise/models.d.mts +2 -106
  210. package/dist/promise/models.mjs +1 -35
  211. package/dist/promise/timed.d.mts +2 -2
  212. package/dist/promise/timed.mjs +3 -3
  213. package/dist/query.d.mts +1 -1
  214. package/dist/query.mjs +5 -15
  215. package/dist/queue.d.mts +6 -200
  216. package/dist/queue.mjs +9 -34
  217. package/dist/random.mjs +2 -5
  218. package/dist/result/match.d.mts +1 -1
  219. package/dist/result/match.mjs +27 -15
  220. package/dist/result/misc.d.mts +1 -1
  221. package/dist/result/work/flow.d.mts +13 -21
  222. package/dist/result/work/flow.mjs +0 -1
  223. package/dist/result/work/pipe.d.mts +2 -2
  224. package/dist/result/work/pipe.mjs +0 -1
  225. package/dist/string/fuzzy.d.mts +5 -87
  226. package/dist/string/fuzzy.mjs +6 -11
  227. package/dist/string/index.mjs +6 -8
  228. package/dist/string/match.mjs +4 -6
  229. package/dist/string/normalize.d.mts +4 -40
  230. package/dist/string/normalize.mjs +9 -48
  231. package/dist/string/template.d.mts +5 -43
  232. package/dist/string/template.mjs +1 -2
  233. package/dist/subscription.d.mts +2 -1
  234. package/dist/value/clone.d.mts +6 -42
  235. package/dist/value/clone.mjs +10 -30
  236. package/dist/value/collection.mjs +2 -0
  237. package/dist/value/diff.d.mts +3 -44
  238. package/dist/value/diff.mjs +1 -3
  239. package/dist/value/freeze.d.mts +1 -5
  240. package/dist/value/index.d.mts +4 -3
  241. package/dist/value/merge.d.mts +6 -64
  242. package/dist/value/merge.mjs +8 -8
  243. package/dist/value/omit.d.mts +1 -1
  244. package/dist/value/pick.d.mts +1 -1
  245. package/dist/value/shake.d.mts +4 -6
  246. package/dist/value/smush.d.mts +4 -6
  247. package/dist/value/smush.mjs +2 -2
  248. package/dist/value/transform.d.mts +6 -22
  249. package/dist/value/transform.mjs +1 -1
  250. package/dist/value/unsmush.d.mts +4 -10
  251. package/package.json +12 -3
  252. package/dist/internal/plan.d.mts +0 -45
  253. package/dist/internal/plan.mjs +0 -70
  254. package/dist/promise/constants.d.mts +0 -17
  255. package/dist/promise/constants.mjs +0 -15
  256. /package/dist/{color/models.mjs → models/color.model.mjs} +0 -0
  257. /package/dist/{internal/models/result.model.mjs → models/index.mjs} +0 -0
  258. /package/dist/{models.mjs → models/result.model.mjs} +0 -0
package/dist/plan/run.mjs CHANGED
@@ -1,23 +1,23 @@
1
- import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../internal/models/plan.model.mjs";
2
- import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "../internal/plan.mjs";
1
+ import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../models/plan.model.mjs";
2
+ import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "./is.mjs";
3
3
  import { asyncGenerate, generate } from "./generate.mjs";
4
4
  import { asyncAttemptRun, attemptRun } from "./result.mjs";
5
5
  //#region src/plan/run.ts
6
6
  function asyncRun(input, ...parameters) {
7
7
  if (isAsyncPlan(input)) return input.run(...parameters);
8
- if (isAsyncGenerator(input)) return asyncGenerate(input, parameters);
8
+ if (isAsyncGenerator(input)) return asyncGenerate(input, parameters, false);
9
9
  throw new Error(PLAN_MESSAGE_RUN_INPUT);
10
10
  }
11
11
  function run(input, ...parameters) {
12
12
  if (isPlan(input)) return input.run(...parameters);
13
- if (isGenerator(input)) return generate(input, parameters);
13
+ if (isGenerator(input)) return generate(input, parameters, false);
14
14
  throw new Error(PLAN_MESSAGE_RUN_INPUT);
15
15
  }
16
16
  function runAsyncPlan(...parameters) {
17
- return asyncGenerate(this[PLAN_SYMBOL].generator, parameters);
17
+ return asyncGenerate(this[PLAN_SYMBOL], parameters, false);
18
18
  }
19
19
  function runPlan(...parameters) {
20
- return generate(this[PLAN_SYMBOL].generator, parameters);
20
+ return generate(this[PLAN_SYMBOL], parameters, false);
21
21
  }
22
22
  asyncRun.attempt = asyncAttemptRun;
23
23
  run.async = asyncRun;
@@ -1,4 +1,4 @@
1
- import { PromiseOptions } from "./models.mjs";
1
+ import { PromiseOptions } from "../models/promise.model.mjs";
2
2
  //#region src/promise/delay.d.ts
3
3
  /**
4
4
  * Create a delayed promise that resolves after a certain amount of time, or rejects if aborted
@@ -1,5 +1,6 @@
1
1
  import { createAborter } from "../internal/aborter.mjs";
2
- import { LIMITER_WAIT, getLimiter } from "../internal/function/limit.mjs";
2
+ import { LIMITER_WAIT } from "../models/function/limiter.model.mjs";
3
+ import { getLimiter } from "../internal/function/limit.mjs";
3
4
  import { createPromiseOptions } from "./helpers.mjs";
4
5
  import { settlePromise } from "./misc.mjs";
5
6
  //#region src/promise/delay.ts
@@ -1,5 +1,5 @@
1
- import { RequiredKeys } from "../models.mjs";
2
- import { FulfilledPromise, PromiseOptions, PromiseStrategy, PromisesOptions, PromisesValue, RejectedPromise } from "./models.mjs";
1
+ import { RequiredKeys } from "../models/index.mjs";
2
+ import { FulfilledPromise, PromiseOptions, PromiseStrategy, PromisesOptions, PromisesValue, RejectedPromise } from "../models/promise.model.mjs";
3
3
  //#region src/promise/helpers.d.ts
4
4
  export declare function createPromiseOptions(input: unknown): RequiredKeys<PromiseOptions, "time">;
5
5
  export declare function createPromisesOptions(input: unknown): RequiredKeys<PromisesOptions, "strategy">;
@@ -1,7 +1,7 @@
1
1
  import { isPlainObject } from "../internal/is.mjs";
2
2
  import { error, ok } from "../internal/result/misc.mjs";
3
3
  import { getNumberOrDefault } from "../internal/defaults.mjs";
4
- import { PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
4
+ import { PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "../models/promise.model.mjs";
5
5
  //#region src/promise/helpers.ts
6
6
  function createPromiseOptions(input) {
7
7
  if (typeof input === "number") return { time: getNumberOrDefault(input, 0) };
@@ -48,7 +48,10 @@ function getStrategyOrDefault(value) {
48
48
  * @returns `true` if the value is a fulfilled _Promise_ result, otherwise `false`
49
49
  */
50
50
  function isFulfilled(value) {
51
- return isType(value, PROMISE_TYPE_FULFILLED);
51
+ return isPromiseResult(value, PROMISE_TYPE_FULFILLED);
52
+ }
53
+ function isPromiseResult(value, type) {
54
+ return isPlainObject(value) && "status" in value && value.status === type;
52
55
  }
53
56
  /**
54
57
  * Is the value a rejected _Promise_ result?
@@ -57,10 +60,7 @@ function isFulfilled(value) {
57
60
  * @returns `true` if the value is a rejected _Promise_ result, otherwise `false`
58
61
  */
59
62
  function isRejected(value) {
60
- return isType(value, PROMISE_TYPE_REJECTED);
61
- }
62
- function isType(value, type) {
63
- return isPlainObject(value) && "status" in value && value.status === type;
63
+ return isPromiseResult(value, PROMISE_TYPE_REJECTED);
64
64
  }
65
65
  //#endregion
66
66
  export { createPromiseOptions, createPromisesOptions, getResultsFromPromises, getStrategyOrDefault, isFulfilled, isRejected };
@@ -1,5 +1,5 @@
1
- import { PlainObject } from "../models.mjs";
2
- import { PromiseOptions, PromiseStrategy, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValues } from "./models.mjs";
1
+ import { PlainObject } from "../models/index.mjs";
2
+ import { PromiseOptions, PromiseStrategy, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValues } from "../models/promise.model.mjs";
3
3
  //#region src/promise/index.d.ts
4
4
  /**
5
5
  * Wrap a _Promise_ with safety handlers
@@ -1,7 +1,7 @@
1
1
  import { isArrayOrPlainObject } from "../internal/is.mjs";
2
2
  import { createAborter } from "../internal/aborter.mjs";
3
3
  import { asyncAttempt } from "../internal/result/attempt.mjs";
4
- import { PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
4
+ import { PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "../models/promise.model.mjs";
5
5
  import { createPromiseOptions, createPromisesOptions, getResultsFromPromises } from "./helpers.mjs";
6
6
  import { handleResult, settlePromise } from "./misc.mjs";
7
7
  import { getTimedPromise } from "./timed.mjs";
@@ -1,6 +1,6 @@
1
- import { Result } from "../internal/models/result.model.mjs";
2
- import { Aborter } from "../internal/aborter.mjs";
3
- import { CancelablePromise, PromiseParameters } from "./models.mjs";
1
+ import { Aborter } from "../models/aborter.model.mjs";
2
+ import { Result } from "../models/result.model.mjs";
3
+ import { CancelablePromise, PromiseParameters } from "../models/promise.model.mjs";
4
4
  import { toPromise } from "../result/misc.mjs";
5
5
  import { isFulfilled, isRejected } from "./helpers.mjs";
6
6
  //#region src/promise/misc.d.ts
@@ -1,7 +1,6 @@
1
1
  import { error, ok } from "../internal/result/misc.mjs";
2
2
  import { toPromise } from "../result/misc.mjs";
3
- import { PROMISE_MESSAGE_EXPECTATION_RESULT } from "./constants.mjs";
4
- import { CancelablePromise } from "./models.mjs";
3
+ import { CancelablePromise, PROMISE_MESSAGE_EXPECTATION_RESULT } from "../models/promise.model.mjs";
5
4
  import { isFulfilled, isRejected } from "./helpers.mjs";
6
5
  //#region src/promise/misc.ts
7
6
  /**
@@ -17,7 +16,8 @@ function handleResult(status, parameters) {
17
16
  const { aborter, complete, data, handlers, index, key, value } = parameters;
18
17
  if (aborter?.signal.aborted ?? false) return;
19
18
  if (!complete && status === "rejected") {
20
- settlePromise(handlers.reject, value, aborter);
19
+ aborter?.cancel();
20
+ handlers.reject(value);
21
21
  return;
22
22
  }
23
23
  data.result[key] = !complete ? value : status === "fulfilled" ? {
@@ -27,7 +27,10 @@ function handleResult(status, parameters) {
27
27
  status,
28
28
  reason: value
29
29
  };
30
- if (index === data.last) settlePromise(handlers.resolve, data.result, aborter);
30
+ if (index === data.last) {
31
+ aborter?.cancel();
32
+ handlers.resolve(data.result);
33
+ }
31
34
  }
32
35
  function settlePromise(settler, value, aborter) {
33
36
  aborter?.cancel();
@@ -1,106 +1,2 @@
1
- import { ArrayOrPlainObject, GenericCallback, Key } from "../models.mjs";
2
- import { Result } from "../internal/models/result.model.mjs";
3
- import { Aborter } from "../internal/aborter.mjs";
4
- import { PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
5
- //#region src/promise/models.d.ts
6
- /**
7
- * A _Promise_ that can be canceled
8
- */
9
- export declare class CancelablePromise<Value = void> extends Promise<Value> {
10
- #private;
11
- constructor(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void);
12
- /**
13
- * Cancel the _Promise_, rejecting it with an optional reason
14
- *
15
- * @param reason Optional reason for canceling the _Promise_
16
- */
17
- cancel(reason?: unknown): void;
18
- }
19
- /**
20
- * A _Promise_ that was fulfilled
21
- */
22
- export type FulfilledPromise<Value> = {
23
- /**
24
- * Status of the _Promise_
25
- */
26
- status: typeof PROMISE_TYPE_FULFILLED;
27
- /**
28
- * Value of the _Promise_
29
- */
30
- value: Awaited<Value>;
31
- };
32
- export type PromiseData = {
33
- last: number;
34
- result: ArrayOrPlainObject;
35
- };
36
- export type PromiseHandlers = {
37
- resolve(value: unknown[]): void;
38
- reject(reason: unknown): void;
39
- };
40
- /**
41
- * Options for a _Promise_-handling function
42
- */
43
- export type PromiseOptions = {
44
- /**
45
- * AbortSignal for aborting the _Promise_; when aborted, the _Promise_ will reject with the reason of the signal
46
- */
47
- signal?: AbortSignal;
48
- /**
49
- * How long to wait for _(in milliseconds; defaults to `0`)_
50
- */
51
- time?: number;
52
- };
53
- export type PromiseParameters = {
54
- aborter?: Aborter;
55
- complete: boolean;
56
- data: PromiseData;
57
- handlers: PromiseHandlers;
58
- index: number;
59
- key: Key;
60
- value?: unknown;
61
- };
62
- /**
63
- * _Promise_ handling strategy
64
- *
65
- * - `complete`: wait for all _Promises_ to settle, then return the results, as an array of fulfilled and/or rejected results
66
- * - `first`: rejects on the first rejected _Promise_, and returns an array of values
67
- */
68
- export type PromiseStrategy = "complete" | "first";
69
- /**
70
- * An error thrown when a promise times out
71
- */
72
- export declare class PromiseTimeoutError extends Error {
73
- constructor();
74
- }
75
- export type PromisesItems<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Promise<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Promise<Value> : Promise<Items[ItemsKey]>; };
76
- /**
77
- * Options for handling multiple _Promises_
78
- */
79
- export type PromisesOptions = {
80
- /**
81
- * AbortSignal for aborting the _Promises_; when aborted, the _Promises_ will reject with the reason of the signal
82
- */
83
- signal?: AbortSignal;
84
- /**
85
- * Strategy for handling the _Promises_; defaults to `complete`
86
- */
87
- strategy?: PromiseStrategy;
88
- };
89
- export type PromisesResult<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? Result<Awaited<Value>> : never; };
90
- export type PromisesUnwrapped<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Awaited<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Awaited<Value> : never; };
91
- export type PromisesValue<Value> = FulfilledPromise<Value> | RejectedPromise;
92
- export type PromisesValues<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never; };
93
- /**
94
- * A _Promise_ that was rejected
95
- */
96
- export type RejectedPromise = {
97
- /**
98
- * Status of the _Promise_
99
- */
100
- status: typeof PROMISE_TYPE_REJECTED;
101
- /**
102
- * Reason for the rejection
103
- */
104
- reason: unknown;
105
- };
106
- //#endregion
1
+ import { CancelablePromise, FulfilledPromise, PromiseOptions, PromiseStrategy, PromiseTimeoutError, PromisesOptions, RejectedPromise } from "../models/promise.model.mjs";
2
+ export { CancelablePromise, type FulfilledPromise, type PromiseOptions, type PromiseStrategy, PromiseTimeoutError, type PromisesOptions, type RejectedPromise };
@@ -1,36 +1,2 @@
1
- import { PROMISE_ERROR_NAME, PROMISE_MESSAGE_TIMEOUT } from "./constants.mjs";
2
- //#region src/promise/models.ts
3
- /**
4
- * A _Promise_ that can be canceled
5
- */
6
- var CancelablePromise = class extends Promise {
7
- #rejector;
8
- constructor(executor) {
9
- let rejector;
10
- super((resolve, reject) => {
11
- rejector = reject;
12
- executor(resolve, reject);
13
- });
14
- this.#rejector = rejector;
15
- }
16
- /**
17
- * Cancel the _Promise_, rejecting it with an optional reason
18
- *
19
- * @param reason Optional reason for canceling the _Promise_
20
- */
21
- cancel(reason) {
22
- this.#rejector?.(reason);
23
- this.#rejector = void 0;
24
- }
25
- };
26
- /**
27
- * An error thrown when a promise times out
28
- */
29
- var PromiseTimeoutError = class extends Error {
30
- constructor() {
31
- super(PROMISE_MESSAGE_TIMEOUT);
32
- this.name = PROMISE_ERROR_NAME;
33
- }
34
- };
35
- //#endregion
1
+ import { CancelablePromise, PromiseTimeoutError } from "../models/promise.model.mjs";
36
2
  export { CancelablePromise, PromiseTimeoutError };
@@ -1,5 +1,5 @@
1
- import { RequiredKeys } from "../models.mjs";
2
- import { PromiseOptions } from "./models.mjs";
1
+ import { RequiredKeys } from "../models/index.mjs";
2
+ import { PromiseOptions } from "../models/promise.model.mjs";
3
3
  //#region src/promise/timed.d.ts
4
4
  export declare function getTimedPromise<Value>(promise: Promise<Value>, time: number, signal?: AbortSignal): Promise<Value>;
5
5
  /**
@@ -1,7 +1,7 @@
1
1
  import { createAborter } from "../internal/aborter.mjs";
2
- import { LIMITER_WAIT, getLimiter } from "../internal/function/limit.mjs";
3
- import { PROMISE_MESSAGE_EXPECTATION_TIMED } from "./constants.mjs";
4
- import { PromiseTimeoutError } from "./models.mjs";
2
+ import { LIMITER_WAIT } from "../models/function/limiter.model.mjs";
3
+ import { getLimiter } from "../internal/function/limit.mjs";
4
+ import { PROMISE_MESSAGE_EXPECTATION_TIMED, PromiseTimeoutError } from "../models/promise.model.mjs";
5
5
  import { createPromiseOptions } from "./helpers.mjs";
6
6
  import { settlePromise } from "./misc.mjs";
7
7
  //#region src/promise/timed.ts
package/dist/query.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { PlainObject } from "./models.mjs";
1
+ import { PlainObject } from "./models/index.mjs";
2
2
  //#region src/query.d.ts
3
3
  /**
4
4
  * Convert a query string to a plain _(nested)_ object
package/dist/query.mjs CHANGED
@@ -2,6 +2,7 @@ import { isPlainObject } from "./internal/is.mjs";
2
2
  import { getString, ignoreKey, join, tryDecode, tryEncode } from "./internal/string/misc.mjs";
3
3
  import { getNumber } from "./internal/number.mjs";
4
4
  import { setValue } from "./internal/value/set.mjs";
5
+ import { QUERY_EXPRESSION_ARRAY_SUFFIX, QUERY_EXPRESSION_BOOLEAN, QUERY_TRUE, QUERY_TYPES } from "./models/query.model.mjs";
5
6
  //#region src/query.ts
6
7
  /**
7
8
  * Convert a query string to a plain _(nested)_ object
@@ -11,7 +12,7 @@ import { setValue } from "./internal/value/set.mjs";
11
12
  */
12
13
  function fromQuery(query) {
13
14
  if (typeof query !== "string" || query.trim().length === 0) return {};
14
- const parts = query.split(QUERY_AMPERSAND).map((part) => part.split(QUERY_EQUAL).map(tryDecode)).sort(([first], [second]) => first.localeCompare(second));
15
+ const parts = query.split("&").map((part) => part.split("=").map(tryDecode)).sort(([first], [second]) => first.localeCompare(second));
15
16
  const { length } = parts;
16
17
  const parameters = {};
17
18
  let position = 0;
@@ -41,9 +42,9 @@ function getParts(value, fromArray, prefix) {
41
42
  for (let index = 0; index < length; index += 1) {
42
43
  const key = keys[index];
43
44
  const val = value[key];
44
- const fullKey = join([prefix, fromArray ? void 0 : key], QUERY_DOT);
45
+ const fullKey = join([prefix, fromArray ? void 0 : key], ".");
45
46
  const encodedKey = getString(tryEncode(fullKey));
46
- const prefixedKey = fromArray ? join([encodedKey, index], QUERY_DOT) : encodedKey;
47
+ const prefixedKey = fromArray ? join([encodedKey, index], ".") : encodedKey;
47
48
  if (Array.isArray(val)) parts.push(...getParts(val, true, fullKey));
48
49
  else if (isPlainObject(val)) parts.push(...getParts(val, false, fullKey));
49
50
  else if (isDecodable(val)) parts.push(`${prefixedKey}=${getString(tryEncode(val))}`);
@@ -70,18 +71,7 @@ function isDecodable(value) {
70
71
  * @returns Query string representation of the object
71
72
  */
72
73
  function toQuery(parameters) {
73
- return isPlainObject(parameters) ? join(getParts(parameters, false).filter((part) => part.length > 0), QUERY_AMPERSAND) : "";
74
+ return isPlainObject(parameters) ? join(getParts(parameters, false).filter((part) => part.length > 0), "&") : "";
74
75
  }
75
- const QUERY_AMPERSAND = "&";
76
- const QUERY_DOT = ".";
77
- const QUERY_EQUAL = "=";
78
- const QUERY_EXPRESSION_ARRAY_SUFFIX = /\[\]$/;
79
- const QUERY_EXPRESSION_BOOLEAN = /^(false|true)$/;
80
- const QUERY_TRUE = "true";
81
- const QUERY_TYPES = /* @__PURE__ */ new Set([
82
- "boolean",
83
- "number",
84
- "string"
85
- ]);
86
76
  //#endregion
87
77
  export { fromQuery, toQuery };
package/dist/queue.d.mts CHANGED
@@ -1,203 +1,8 @@
1
- import { GenericAsyncCallback, GenericCallback } from "./models.mjs";
1
+ import { GenericAsyncCallback, GenericCallback } from "./models/index.mjs";
2
+ import { KeyedQueue, Queue, QueueOptions, Queued } from "./models/queue.model.mjs";
2
3
  //#region src/queue.d.ts
3
- /**
4
- * A queue that can be used to manage (a)synchronous tasks with a specific key
5
- */
6
- export type KeyedQueue<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
7
- /**
8
- * Get keys of all active queues
9
- */
10
- get active(): string[];
11
- /**
12
- * Does the queue automatically start when the first item is added?
13
- */
14
- get autostart(): boolean;
15
- /**
16
- * Maximum number of runners to process the queue concurrently
17
- */
18
- get concurrency(): number;
19
- /**
20
- * Get keys of all empty queues
21
- */
22
- get empty(): string[];
23
- /**
24
- * Get keys of all full queues
25
- */
26
- get full(): string[];
27
- /**
28
- * Number of items in all queues
29
- */
30
- get items(): Record<string, number>;
31
- /**
32
- * Keys of all queues
33
- */
34
- get keys(): string[];
35
- /**
36
- * Maximum number of items allowed in the queue
37
- */
38
- get maximum(): number;
39
- /**
40
- * Are all queues paused?
41
- */
42
- get paused(): string[];
43
- /**
44
- * Number of queues
45
- */
46
- get queues(): number;
47
- /**
48
- * Queue an item for a specific key
49
- *
50
- * @param key Key to queue the item for
51
- * @param parameters Parameters to use when item runs
52
- * @param signal Optional signal to abort the item
53
- * @returns Queued item
54
- */
55
- add(key: string, parameters: Tail<CallbackParameters>, signal?: AbortSignal): Queued<ReturnType<Callback>>;
56
- /**
57
- * Clear all items for a specific key _(or all items for all keys, if no key is provided)_
58
- *
59
- * @param key Optional key to clear the queue for
60
- */
61
- clear(key?: string): void;
62
- /**
63
- * Get the queue for a specific key
64
- *
65
- * @param key Key to get the queue for
66
- * @returns Queue for the key, or `undefined` if it doesn't exist
67
- */
68
- get(key: string): Queue<Callback, Tail<CallbackParameters>> | undefined;
69
- /**
70
- * Pause the queue for a specific key _(or all queues, if no key is provided)_
71
- *
72
- * @param key Optional key to pause the queue for
73
- */
74
- pause(key?: string): void;
75
- /**
76
- * Remove a specific item for a specific key
77
- *
78
- * @param key Key to remove the item for
79
- * @param id ID of the item to remove
80
- */
81
- remove(key: string, id: number): void;
82
- /**
83
- * Remove a queue and its items for a specific key
84
- *
85
- * _(To remove all items for a specific key, use `clear()` instead)_
86
- *
87
- * @param key Key to remove the queue for
88
- */
89
- remove(key: string): void;
90
- /**
91
- * Remove all queues and their items
92
- */
93
- remove(): void;
94
- /**
95
- * Resume the queue for a specific key _(or all queues, if no key is provided)_
96
- *
97
- * @param key Optional key to resume the queue for
98
- */
99
- resume(key?: string): void;
100
- };
101
- /**
102
- * A queue that can be used to manage (a)synchronous tasks
103
- */
104
- export type Queue<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
105
- /**
106
- * Is the queue active?
107
- */
108
- get active(): boolean;
109
- /**
110
- * Does the queue automatically start when the first item is added?
111
- */
112
- get autostart(): boolean;
113
- /**
114
- * Maximum number of runners to process the queue concurrently
115
- */
116
- get concurrency(): number;
117
- /**
118
- * Is the queue empty?
119
- */
120
- get empty(): boolean;
121
- /**
122
- * Is the queue full?
123
- */
124
- get full(): boolean;
125
- /**
126
- * Maximum number of items allowed in the queue
127
- */
128
- get maximum(): number;
129
- /**
130
- * Is the queue paused?
131
- */
132
- get paused(): boolean;
133
- /**
134
- * Number of items in the queue
135
- */
136
- get size(): number;
137
- /**
138
- * Add an item to the queue
139
- *
140
- * @param parameters Parameters to use when item runs
141
- * @param signal Optional signal to abort the item
142
- * @returns Queued item
143
- */
144
- add(parameters: CallbackParameters, signal?: AbortSignal): Queued<ReturnType<Callback>>;
145
- /**
146
- * Remove and reject all items in the queue
147
- */
148
- clear(): void;
149
- /**
150
- * Pause the queue
151
- *
152
- * - Currently running items will not be stopped
153
- * - New added items will not run until the queue is resumed
154
- */
155
- pause(): void;
156
- /**
157
- * Remove and reject a specific item in the queue
158
- *
159
- * @param id ID of queued item
160
- */
161
- remove(id: number): void;
162
- /**
163
- * Resume the queue
164
- */
165
- resume(): void;
166
- };
167
- /**
168
- * An error thrown by the Queue when an operation fails
169
- */
170
- export declare class QueueError extends Error {
171
- constructor(message: string);
172
- }
173
- export type QueueOptions = {
174
- /**
175
- * Automatically start processing the queue when the first item is added _(defaults to `true`)_
176
- */
177
- autostart?: boolean;
178
- /**
179
- * Number of runners to process the queue concurrently _(defaults to `1`)_
180
- */
181
- concurrency?: number;
182
- /**
183
- * Maximum number of items allowed in the queue _(defaults to `0`, which means no limit)_
184
- */
185
- maximum?: number;
186
- };
187
- /**
188
- * A queued item
189
- */
190
- export type Queued<Value> = {
191
- /**
192
- * ID of the queued item _(can be used to remove it from the queue)_
193
- */
194
- readonly id: number;
195
- /**
196
- * Queued promise
197
- */
198
- readonly promise: Promise<Value extends Promise<infer Result> ? Result : Value>;
199
- };
200
- type Tail<Values extends any[]> = Values extends [infer _, ...infer Rest] ? Rest : never;
4
+ declare function KeyedQueue(this: any, callback: GenericAsyncCallback, options: Required<QueueOptions>): void;
5
+ declare function Queue(this: any, callback: GenericAsyncCallback, options: Required<QueueOptions>, key?: string): void;
201
6
  /**
202
7
  * Is the value keyed queue?
203
8
  *
@@ -250,4 +55,5 @@ export declare function queue<Callback extends GenericCallback>(callback: Callba
250
55
  export declare namespace queue {
251
56
  export var keyed: typeof keyedQueue;
252
57
  }
253
- //#endregion
58
+ //#endregion
59
+ export type { KeyedQueue, Queue, QueueOptions, Queued };
package/dist/queue.mjs CHANGED
@@ -2,19 +2,8 @@ import { createAborter } from "./internal/aborter.mjs";
2
2
  import { min } from "./internal/math/aggregate.mjs";
3
3
  import { asyncAttempt } from "./internal/result/attempt.mjs";
4
4
  import { getBooleanOrDefault, getNumberOrDefault } from "./internal/defaults.mjs";
5
+ import { QUEUE_HANDLE_CLEAR, QUEUE_HANDLE_PAUSE, QUEUE_HANDLE_RESUME, QUEUE_MESSAGE_CALLBACK, QUEUE_MESSAGE_CLEAR, QUEUE_MESSAGE_KEY, QUEUE_MESSAGE_MAXIMUM, QUEUE_MESSAGE_REMOVE, QUEUE_NAME_KEYED, QUEUE_NAME_QUEUE, QUEUE_PROPERTY, QUEUE_STATUS_ACTIVE, QUEUE_STATUS_EMPTY, QUEUE_STATUS_FULL, QUEUE_STATUS_PAUSED, QUEUE_SYMBOL, QueueError } from "./models/queue.model.mjs";
5
6
  //#region src/queue.ts
6
- const QUEUE_NAME_KEYED = "keyedQueue";
7
- const QUEUE_NAME_QUEUE = "queue";
8
- const QUEUE_PROPERTY = "$queue";
9
- /**
10
- * An error thrown by the Queue when an operation fails
11
- */
12
- var QueueError = class extends Error {
13
- constructor(message) {
14
- super(message);
15
- this.name = QUEUE_ERROR_NAME;
16
- }
17
- };
18
7
  function KeyedQueue(callback, options) {
19
8
  this[QUEUE_SYMBOL] = {
20
9
  callback,
@@ -158,9 +147,9 @@ function clearQueue() {
158
147
  const items = this[QUEUE_SYMBOL].items.splice(0);
159
148
  const { length } = items;
160
149
  for (let index = 0; index < length; index += 1) {
161
- const { aborter, reject } = items[index];
162
- aborter?.cancel();
163
- reject(new QueueError(QUEUE_MESSAGE_CLEAR));
150
+ const item = items[index];
151
+ item.aborter?.cancel();
152
+ item.reject(new QueueError(QUEUE_MESSAGE_CLEAR));
164
153
  }
165
154
  }
166
155
  function clearQueues(key) {
@@ -287,7 +276,7 @@ function isQueue(value) {
287
276
  return isQueueInstance(QUEUE_NAME_QUEUE, value);
288
277
  }
289
278
  function isQueueInstance(name, value) {
290
- return typeof value === "object" && value != null && QUEUE_PROPERTY in value && value[QUEUE_PROPERTY] === name;
279
+ return typeof value === "object" && value != null && "$queue" in value && value["$queue"] === name;
291
280
  }
292
281
  function keyedQueue(callback, options) {
293
282
  if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
@@ -322,9 +311,9 @@ function removeQueued(id) {
322
311
  const state = this[QUEUE_SYMBOL];
323
312
  const index = state.items.findIndex((item) => item.id === id);
324
313
  if (index > -1) {
325
- const { aborter, reject } = state.items.splice(index, 1)[0];
326
- aborter?.cancel();
327
- reject(new QueueError(QUEUE_MESSAGE_REMOVE));
314
+ const item = state.items.splice(index, 1)[0];
315
+ item.aborter?.cancel();
316
+ item.reject(new QueueError(QUEUE_MESSAGE_REMOVE));
328
317
  }
329
318
  }
330
319
  function resumeQueue() {
@@ -370,20 +359,6 @@ async function run(state) {
370
359
  }
371
360
  state.runners -= 1;
372
361
  }
373
- const QUEUE_ERROR_NAME = "QueueError";
374
- const QUEUE_HANDLE_CLEAR = "clear";
375
- const QUEUE_HANDLE_PAUSE = "pause";
376
- const QUEUE_HANDLE_RESUME = "resume";
377
- const QUEUE_MESSAGE_CALLBACK = "A Queue requires a callback function";
378
- const QUEUE_MESSAGE_CLEAR = "Queue was cleared";
379
- const QUEUE_MESSAGE_KEY = "Key must be a non-empty string";
380
- const QUEUE_MESSAGE_MAXIMUM = "Queue has reached its maximum size";
381
- const QUEUE_MESSAGE_REMOVE = "Item removed from queue";
382
- const QUEUE_STATUS_ACTIVE = "active";
383
- const QUEUE_STATUS_EMPTY = "empty";
384
- const QUEUE_STATUS_FULL = "full";
385
- const QUEUE_STATUS_PAUSED = "paused";
386
- const QUEUE_SYMBOL = Symbol(QUEUE_PROPERTY);
387
362
  queue.keyed = keyedQueue;
388
363
  //#endregion
389
- export { QueueError, isKeyedQueue, isQueue, isQueueInstance, keyedQueue, queue };
364
+ export { isKeyedQueue, isQueue, isQueueInstance, keyedQueue, queue };