@oscarpalmer/atoms 0.213.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 (252) 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/misc/alpha.d.mts +1 -1
  45. package/dist/color/misc/format.d.mts +1 -1
  46. package/dist/color/misc/get.d.mts +1 -1
  47. package/dist/color/misc/is.d.mts +2 -2
  48. package/dist/color/misc/is.mjs +1 -0
  49. package/dist/color/misc/state.d.mts +1 -1
  50. package/dist/color/space/hex.d.mts +1 -1
  51. package/dist/color/space/hsl.d.mts +1 -1
  52. package/dist/color/space/hwb.d.mts +1 -1
  53. package/dist/color/space/rgb.d.mts +1 -1
  54. package/dist/function/limit.d.mts +2 -2
  55. package/dist/function/limit.mjs +2 -1
  56. package/dist/function/once.d.mts +7 -3
  57. package/dist/function/once.mjs +5 -10
  58. package/dist/function/retry.d.mts +4 -14
  59. package/dist/function/retry.mjs +3 -15
  60. package/dist/herald.d.mts +2 -2
  61. package/dist/index.d.mts +425 -318
  62. package/dist/index.mjs +454 -408
  63. package/dist/internal/aborter.d.mts +1 -6
  64. package/dist/internal/aborter.mjs +3 -4
  65. package/dist/internal/array/callbacks.d.mts +3 -7
  66. package/dist/internal/array/chunk.mjs +2 -2
  67. package/dist/internal/array/find.d.mts +5 -23
  68. package/dist/internal/array/find.mjs +5 -9
  69. package/dist/internal/array/get.d.mts +1 -1
  70. package/dist/internal/array/group.d.mts +1 -1
  71. package/dist/internal/array/index-of.d.mts +1 -1
  72. package/dist/internal/array/index-of.mjs +4 -3
  73. package/dist/internal/array/insert.d.mts +2 -5
  74. package/dist/internal/array/insert.mjs +2 -4
  75. package/dist/internal/array/match.d.mts +2 -5
  76. package/dist/internal/array/match.mjs +10 -20
  77. package/dist/internal/array/overlap.d.mts +2 -10
  78. package/dist/internal/array/sets.d.mts +2 -5
  79. package/dist/internal/array/sets.mjs +5 -7
  80. package/dist/internal/function/assert.d.mts +5 -12
  81. package/dist/internal/function/assert.mjs +2 -2
  82. package/dist/internal/function/limit.d.mts +2 -37
  83. package/dist/internal/function/limit.mjs +4 -15
  84. package/dist/internal/function/memoize.d.mts +5 -70
  85. package/dist/internal/function/memoize.mjs +2 -5
  86. package/dist/internal/function/work.d.mts +16 -22
  87. package/dist/internal/function/work.mjs +1 -8
  88. package/dist/internal/herald.d.mts +3 -3
  89. package/dist/internal/herald.mjs +2 -1
  90. package/dist/internal/is.d.mts +1 -1
  91. package/dist/internal/math/aggregate.d.mts +2 -14
  92. package/dist/internal/math/aggregate.mjs +2 -5
  93. package/dist/internal/number.mjs +4 -7
  94. package/dist/internal/result/attempt.d.mts +1 -1
  95. package/dist/internal/result/misc.d.mts +1 -1
  96. package/dist/internal/string/case.mjs +6 -16
  97. package/dist/internal/string/misc.mjs +1 -2
  98. package/dist/internal/subscription.d.mts +1 -100
  99. package/dist/internal/subscription.mjs +3 -9
  100. package/dist/internal/value/compare.d.mts +4 -4
  101. package/dist/internal/value/compare.mjs +1 -1
  102. package/dist/internal/value/equal.d.mts +6 -57
  103. package/dist/internal/value/equal.mjs +5 -10
  104. package/dist/internal/value/get.d.mts +1 -1
  105. package/dist/internal/value/handlers.d.mts +2 -21
  106. package/dist/internal/value/has.d.mts +2 -2
  107. package/dist/internal/value/misc.d.mts +1 -1
  108. package/dist/internal/value/misc.mjs +8 -14
  109. package/dist/internal/value/set.d.mts +1 -1
  110. package/dist/internal/value/set.mjs +2 -2
  111. package/dist/is.mjs +3 -3
  112. package/dist/logger.d.mts +3 -70
  113. package/dist/logger.mjs +2 -5
  114. package/dist/math.d.mts +1 -1
  115. package/dist/math.mjs +2 -1
  116. package/dist/models/aborter.model.d.mts +12 -0
  117. package/dist/models/aborter.model.mjs +5 -0
  118. package/dist/models/array/array.find.model.d.mts +22 -0
  119. package/dist/models/array/array.find.model.mjs +8 -0
  120. package/dist/models/array/array.match.model.d.mts +14 -0
  121. package/dist/models/array/array.match.model.mjs +14 -0
  122. package/dist/models/array/array.misc.model.d.mts +36 -0
  123. package/dist/models/array/array.misc.model.mjs +12 -0
  124. package/dist/models/array/array.sort.model.d.mts +122 -0
  125. package/dist/models/array/array.sort.model.mjs +12 -0
  126. package/dist/models/beacon.model.d.mts +119 -0
  127. package/dist/models/beacon.model.mjs +16 -0
  128. package/dist/{color/models.d.mts → models/color.model.d.mts} +4 -4
  129. package/dist/models/function/assert.model.d.mts +13 -0
  130. package/dist/models/function/assert.model.mjs +4 -0
  131. package/dist/models/function/limiter.model.d.mts +71 -0
  132. package/dist/models/function/limiter.model.mjs +15 -0
  133. package/dist/models/function/memoize.model.d.mts +88 -0
  134. package/dist/models/function/memoize.model.mjs +7 -0
  135. package/dist/models/function/once.model.d.mts +76 -0
  136. package/dist/models/function/once.model.mjs +9 -0
  137. package/dist/models/function/retry.model.d.mts +17 -0
  138. package/dist/models/function/retry.model.mjs +17 -0
  139. package/dist/models/function/work.model.d.mts +20 -0
  140. package/dist/models/function/work.model.mjs +11 -0
  141. package/dist/{internal/models → models}/herald.model.d.mts +3 -3
  142. package/dist/{internal/models → models}/herald.model.mjs +2 -2
  143. package/dist/{models.d.mts → models/index.d.mts} +5 -47
  144. package/dist/models/logger.model.d.mts +83 -0
  145. package/dist/models/logger.model.mjs +7 -0
  146. package/dist/models/math.model.d.mts +16 -0
  147. package/dist/models/math.model.mjs +7 -0
  148. package/dist/models/misc.model.d.mts +10 -0
  149. package/dist/models/misc.model.mjs +11 -0
  150. package/dist/{internal/models → models}/plan.model.d.mts +3 -3
  151. package/dist/{internal/models → models}/plan.model.mjs +1 -1
  152. package/dist/models/promise.model.d.mts +119 -0
  153. package/dist/models/promise.model.mjs +47 -0
  154. package/dist/models/query.model.d.mts +9 -0
  155. package/dist/models/query.model.mjs +14 -0
  156. package/dist/models/queue.model.d.mts +251 -0
  157. package/dist/models/queue.model.mjs +29 -0
  158. package/dist/models/random.model.d.mts +6 -0
  159. package/dist/models/random.model.mjs +7 -0
  160. package/dist/{internal/models → models}/result.model.d.mts +10 -2
  161. package/dist/models/string/string.case.model.d.mts +19 -0
  162. package/dist/models/string/string.case.model.mjs +14 -0
  163. package/dist/models/string/string.fuzzy.model.d.mts +108 -0
  164. package/dist/models/string/string.fuzzy.model.mjs +9 -0
  165. package/dist/models/string/string.misc.model.d.mts +13 -0
  166. package/dist/models/string/string.misc.model.mjs +13 -0
  167. package/dist/models/string/string.normalize.model.d.mts +85 -0
  168. package/dist/models/string/string.normalize.model.mjs +43 -0
  169. package/dist/models/string/string.template.model.d.mts +50 -0
  170. package/dist/models/string/string.template.model.mjs +5 -0
  171. package/dist/models/subscription.model.d.mts +127 -0
  172. package/dist/models/subscription.model.mjs +10 -0
  173. package/dist/models/value/value.clone.model.d.mts +56 -0
  174. package/dist/models/value/value.clone.model.mjs +24 -0
  175. package/dist/models/value/value.diff.model.d.mts +61 -0
  176. package/dist/models/value/value.diff.model.mjs +6 -0
  177. package/dist/models/value/value.equal.model.d.mts +76 -0
  178. package/dist/models/value/value.equal.model.mjs +9 -0
  179. package/dist/models/value/value.handler.model.d.mts +27 -0
  180. package/dist/models/value/value.handler.model.mjs +1 -0
  181. package/dist/models/value/value.merge.model.d.mts +82 -0
  182. package/dist/models/value/value.merge.model.mjs +5 -0
  183. package/dist/models/value/value.misc.model.d.mts +33 -0
  184. package/dist/models/value/value.misc.model.mjs +12 -0
  185. package/dist/models/value/value.transform.model.d.mts +28 -0
  186. package/dist/models/value/value.transform.model.mjs +4 -0
  187. package/dist/plan/generate.d.mts +3 -2
  188. package/dist/plan/generate.mjs +11 -7
  189. package/dist/plan/index.d.mts +1 -1
  190. package/dist/plan/index.mjs +1 -1
  191. package/dist/plan/is.d.mts +1 -1
  192. package/dist/plan/is.mjs +1 -1
  193. package/dist/plan/misc.d.mts +1 -1
  194. package/dist/plan/models.d.mts +1 -1
  195. package/dist/plan/result.d.mts +2 -2
  196. package/dist/plan/result.mjs +3 -3
  197. package/dist/plan/run.d.mts +1 -1
  198. package/dist/plan/run.mjs +3 -3
  199. package/dist/promise/delay.d.mts +1 -1
  200. package/dist/promise/delay.mjs +2 -1
  201. package/dist/promise/helpers.d.mts +2 -2
  202. package/dist/promise/helpers.mjs +6 -6
  203. package/dist/promise/index.d.mts +2 -2
  204. package/dist/promise/index.mjs +1 -1
  205. package/dist/promise/misc.d.mts +3 -3
  206. package/dist/promise/misc.mjs +7 -4
  207. package/dist/promise/models.d.mts +2 -106
  208. package/dist/promise/models.mjs +1 -35
  209. package/dist/promise/timed.d.mts +2 -2
  210. package/dist/promise/timed.mjs +3 -3
  211. package/dist/query.d.mts +1 -1
  212. package/dist/query.mjs +5 -15
  213. package/dist/queue.d.mts +6 -200
  214. package/dist/queue.mjs +9 -34
  215. package/dist/random.mjs +2 -5
  216. package/dist/result/match.d.mts +1 -1
  217. package/dist/result/match.mjs +27 -15
  218. package/dist/result/misc.d.mts +1 -1
  219. package/dist/result/work/flow.d.mts +13 -21
  220. package/dist/result/work/pipe.d.mts +2 -2
  221. package/dist/string/fuzzy.d.mts +5 -87
  222. package/dist/string/fuzzy.mjs +6 -11
  223. package/dist/string/index.mjs +6 -8
  224. package/dist/string/match.mjs +4 -6
  225. package/dist/string/normalize.d.mts +4 -40
  226. package/dist/string/normalize.mjs +9 -48
  227. package/dist/string/template.d.mts +5 -43
  228. package/dist/string/template.mjs +1 -2
  229. package/dist/subscription.d.mts +2 -1
  230. package/dist/value/clone.d.mts +6 -42
  231. package/dist/value/clone.mjs +10 -30
  232. package/dist/value/collection.mjs +2 -0
  233. package/dist/value/diff.d.mts +3 -44
  234. package/dist/value/diff.mjs +1 -3
  235. package/dist/value/freeze.d.mts +1 -5
  236. package/dist/value/index.d.mts +4 -3
  237. package/dist/value/merge.d.mts +6 -64
  238. package/dist/value/merge.mjs +8 -8
  239. package/dist/value/omit.d.mts +1 -1
  240. package/dist/value/pick.d.mts +1 -1
  241. package/dist/value/shake.d.mts +4 -6
  242. package/dist/value/smush.d.mts +4 -6
  243. package/dist/value/smush.mjs +2 -2
  244. package/dist/value/transform.d.mts +6 -22
  245. package/dist/value/transform.mjs +1 -1
  246. package/dist/value/unsmush.d.mts +4 -10
  247. package/package.json +12 -4
  248. package/dist/promise/constants.d.mts +0 -17
  249. package/dist/promise/constants.mjs +0 -15
  250. /package/dist/{color/models.mjs → models/color.model.mjs} +0 -0
  251. /package/dist/{internal/models/result.model.mjs → models/index.mjs} +0 -0
  252. /package/dist/{models.mjs → models/result.model.mjs} +0 -0
@@ -1,7 +1,7 @@
1
- import { Subscription } from "../internal/subscription.mjs";
2
- import { Herald, HeraldEvents } from "../internal/models/herald.model.mjs";
3
- import { COLOR_SYMBOL } from "./constants.mjs";
4
- //#region src/color/models.d.ts
1
+ import { Subscription } from "./subscription.model.mjs";
2
+ import { Herald, HeraldEvents } from "./herald.model.mjs";
3
+ import { COLOR_SYMBOL } from "../color/constants.mjs";
4
+ //#region src/models/color.model.d.ts
5
5
  export type Alpha = {
6
6
  hex: string;
7
7
  value: number;
@@ -0,0 +1,13 @@
1
+ import { NestedKeys, PlainObject } from "../index.mjs";
2
+ //#region src/models/function/assert.model.d.ts
3
+ export type AssertNestedPick<Value, Path extends string> = Value extends PlainObject ? Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Value ? { [Key in Head]: AssertNestedPick<Value[Key], Rest>; } : never : Path extends keyof Value ? { [Key in Path]: Value[Key]; } : never : never;
4
+ /**
5
+ * Asserter for a property of a value
6
+ */
7
+ export type AssertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, Asserted extends AssertNestedPick<Value, Path> = AssertNestedPick<Value, Path>> = Asserter<Asserted>;
8
+ /**
9
+ * A function that asserts a value is of a specific type, throwing an error if it is not
10
+ */
11
+ export type Asserter<Value> = (value: unknown) => asserts value is Value;
12
+ export declare const ASSERT_MESSAGE_VALUE_DEFINED = "Expected value to be defined";
13
+ //#endregion
@@ -0,0 +1,4 @@
1
+ //#region src/models/function/assert.model.ts
2
+ const ASSERT_MESSAGE_VALUE_DEFINED = "Expected value to be defined";
3
+ //#endregion
4
+ export { ASSERT_MESSAGE_VALUE_DEFINED };
@@ -0,0 +1,71 @@
1
+ import { GenericAsyncCallback, GenericCallback } from "../index.mjs";
2
+ //#region src/models/function/limiter.model.d.ts
3
+ export type AsyncLimiterItem = {
4
+ parameters: unknown[];
5
+ promise: Promise<unknown>;
6
+ reject(reason?: unknown): void;
7
+ resolve(value?: unknown): void;
8
+ running: boolean;
9
+ };
10
+ /**
11
+ * An asynchronous function that can be cancelled
12
+ */
13
+ export type AsyncLimiter<Callback extends GenericAsyncCallback> = {
14
+ /**
15
+ * Cancel the function
16
+ */
17
+ cancel(): void;
18
+ /**
19
+ * Call the function
20
+ *
21
+ * @param parameters Function parameters
22
+ * @returns Function result
23
+ */
24
+ run(...parameters: Parameters<Callback>): Promise<ReturnType<Callback>>;
25
+ };
26
+ export type AsyncLimiterState = {
27
+ last?: AsyncLimiterItem;
28
+ } & LimiterState<GenericAsyncCallback>;
29
+ export type InternalAsyncLimiter = {
30
+ [LIMITER_SYMBOL]: AsyncLimiterState;
31
+ } & AsyncLimiter<GenericAsyncCallback>;
32
+ export type InternalLimiter = {
33
+ [LIMITER_SYMBOL]: LimiterState;
34
+ } & Limiter<GenericCallback>;
35
+ /**
36
+ * A function that can be cancelled
37
+ */
38
+ export type Limiter<Callback extends GenericCallback> = {
39
+ /**
40
+ * Cancel the function
41
+ */
42
+ cancel(): void;
43
+ /**
44
+ * Call the function
45
+ *
46
+ * @param parameters Function parameters
47
+ * @returns Function result
48
+ */
49
+ run(...parameters: Parameters<Callback>): ReturnType<Callback>;
50
+ };
51
+ export type LimiterState<Callback = GenericCallback> = {
52
+ callback: Callback;
53
+ interval: number;
54
+ parameters: unknown[];
55
+ start?: number;
56
+ throttle: boolean;
57
+ timer?: number;
58
+ type: LimiterType;
59
+ };
60
+ export type LimiterType = "debounce" | "throttle" | "wait";
61
+ export declare const LIMITER_DEBOUNCE: LimiterType;
62
+ export declare const LIMITER_NAME_ASYNC = "asyncLimiter";
63
+ export declare const LIMITER_NAME_SYNC = "limiter";
64
+ export declare const LIMITER_PROPERTY = "$limiter";
65
+ export declare const LIMITER_OFFSET = 5;
66
+ export declare const LIMITER_SYMBOL: unique symbol;
67
+ export declare const LIMITER_THROTTLE: LimiterType;
68
+ export declare const LIMITER_WAIT: LimiterType;
69
+ export declare const clearTimer: (handle: number) => void;
70
+ export declare const startTimer: (callback: FrameRequestCallback) => number;
71
+ //#endregion
@@ -0,0 +1,15 @@
1
+ //#region src/models/function/limiter.model.ts
2
+ const LIMITER_DEBOUNCE = "debounce";
3
+ const LIMITER_NAME_ASYNC = "asyncLimiter";
4
+ const LIMITER_NAME_SYNC = "limiter";
5
+ const LIMITER_PROPERTY = "$limiter";
6
+ const LIMITER_OFFSET = 5;
7
+ const LIMITER_SYMBOL = Symbol("limiter");
8
+ const LIMITER_THROTTLE = "throttle";
9
+ const LIMITER_WAIT = "wait";
10
+ // istanbul ignore next
11
+ const clearTimer = typeof cancelAnimationFrame === "function" ? cancelAnimationFrame : clearTimeout;
12
+ // istanbul ignore next
13
+ const startTimer = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout;
14
+ //#endregion
15
+ export { LIMITER_DEBOUNCE, LIMITER_NAME_ASYNC, LIMITER_NAME_SYNC, LIMITER_OFFSET, LIMITER_PROPERTY, LIMITER_SYMBOL, LIMITER_THROTTLE, LIMITER_WAIT, clearTimer, startTimer };
@@ -0,0 +1,88 @@
1
+ import { GenericCallback } from "../index.mjs";
2
+ import { SizedMap } from "../../internal/sized/map.mjs";
3
+ //#region src/models/function/memoize.model.d.ts
4
+ export type InternalMemoized = {
5
+ [MEMOIZED_SYMBOL]: MemoizedState;
6
+ } & Memoized<GenericCallback>;
7
+ /**
8
+ * A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_
9
+ */
10
+ export type Memoized<Callback extends GenericCallback> = {
11
+ /**
12
+ * Maximum cache size
13
+ *
14
+ * @returns Maximum cache size _(or `Number.NaN` if the instance has been destroyed)_
15
+ */
16
+ get maximum(): number;
17
+ /**
18
+ * Current cache size
19
+ *
20
+ * @returns Current cache size _(or `Number.NaN` if the instance has been destroyed)_
21
+ */
22
+ get size(): number;
23
+ /**
24
+ * Clear the cache
25
+ */
26
+ clear(): void;
27
+ /**
28
+ * Delete a result from the cache
29
+ *
30
+ * @param key Key to delete
31
+ * @returns `true` if the key existed and was removed, otherwise `false`
32
+ */
33
+ delete(key: unknown): boolean;
34
+ /**
35
+ * Destroy the instance
36
+ *
37
+ * _(When a Memoized instance is destroyed, its cache and callback are removed, and calls to `run` will throw an error)_
38
+ */
39
+ destroy(): void;
40
+ /**
41
+ * Get a result from the cache
42
+ *
43
+ * @param key Key to get
44
+ * @returns Cached result or `undefined` if it does not exist
45
+ */
46
+ get(key: unknown): ReturnType<Callback> | undefined;
47
+ /**
48
+ * Does the result exist?
49
+ *
50
+ * @param key Key to check
51
+ * @returns `true` if the result exists, otherwise `false`
52
+ */
53
+ has(key: unknown): boolean;
54
+ /**
55
+ * Run the callback with the provided parameters
56
+ *
57
+ * @param parameters Parameters to pass to the callback
58
+ * @returns Cached or computed _(then cached)_ result
59
+ */
60
+ run(...parameters: Parameters<Callback>): ReturnType<Callback>;
61
+ };
62
+ /**
63
+ * Options for a _Memoized_ function
64
+ */
65
+ export type MemoizedOptions<Callback extends GenericCallback> = {
66
+ /**
67
+ * Callback for getting a cache key for the provided parameters
68
+ */
69
+ cacheKey?: (...parameters: Parameters<Callback>) => unknown;
70
+ /**
71
+ * Size of the cache
72
+ */
73
+ cacheSize?: number;
74
+ };
75
+ export type MemoizedState = {
76
+ cache: SizedMap<unknown, unknown>;
77
+ getter: GenericCallback;
78
+ options: MemoizedStateOptions;
79
+ };
80
+ export type MemoizedStateOptions = {
81
+ cacheKey?: GenericCallback;
82
+ cacheSize: number;
83
+ };
84
+ export declare const MEMOIZED_CACHE_SIZE_DEFAULT = 1024;
85
+ export declare const MEMOIZED_CALLBACK = "Memoized requires a callback function";
86
+ export declare const MEMOIZED_KEY_SEPARATOR = "_";
87
+ export declare const MEMOIZED_SYMBOL: unique symbol;
88
+ //#endregion
@@ -0,0 +1,7 @@
1
+ //#region src/models/function/memoize.model.ts
2
+ const MEMOIZED_CACHE_SIZE_DEFAULT = 1024;
3
+ const MEMOIZED_CALLBACK = "Memoized requires a callback function";
4
+ const MEMOIZED_KEY_SEPARATOR = "_";
5
+ const MEMOIZED_SYMBOL = Symbol("memoized");
6
+ //#endregion
7
+ export { MEMOIZED_CACHE_SIZE_DEFAULT, MEMOIZED_CALLBACK, MEMOIZED_KEY_SEPARATOR, MEMOIZED_SYMBOL };
@@ -0,0 +1,76 @@
1
+ import { GenericAsyncCallback, GenericCallback } from "../index.mjs";
2
+ //#region src/models/function/once.model.d.ts
3
+ /**
4
+ * An asynchronous function that can only be called once, returning the same value on subsequent calls
5
+ */
6
+ export type AsyncOnce<Callback extends GenericAsyncCallback> = {
7
+ /**
8
+ * Did the callback's promise reject?
9
+ */
10
+ readonly error: boolean;
11
+ /**
12
+ * Has the callback finished?
13
+ */
14
+ readonly finished: boolean;
15
+ /**
16
+ * Run the callback
17
+ *
18
+ * @param parameters Callback parameters
19
+ * @returns Call result
20
+ */
21
+ run(...parameters: Parameters<Callback>): ReturnType<Callback>;
22
+ } & OnceProperties;
23
+ export type AsyncOnceItem<Value> = {
24
+ reject(reason?: unknown): void;
25
+ resolve(value: Value): void;
26
+ };
27
+ export type AsyncOnceState<Value> = {
28
+ error: boolean;
29
+ finished: boolean;
30
+ items: Array<AsyncOnceItem<Value>>;
31
+ } & OnceState<Value, GenericAsyncCallback>;
32
+ export type InternalAsyncOnce = {
33
+ [ONCE_SYMBOL]: AsyncOnceState<unknown>;
34
+ } & AsyncOnce<GenericAsyncCallback>;
35
+ export type InternalOnce = {
36
+ [ONCE_SYMBOL]: OnceState<unknown>;
37
+ } & Once<GenericCallback>;
38
+ /**
39
+ * A callback function that can only be called once, returning the same value on subsequent calls
40
+ */
41
+ export type Once<Callback extends GenericCallback> = {
42
+ /**
43
+ * Run the callback
44
+ *
45
+ * @param parameters Callback parameters
46
+ * @returns Call result
47
+ */
48
+ run(...parameters: Parameters<Callback>): ReturnType<Callback>;
49
+ } & OnceProperties;
50
+ type OnceProperties = {
51
+ /**
52
+ * Has the callback been called?
53
+ */
54
+ readonly called: boolean;
55
+ /**
56
+ * Has the callback's value been cleared?
57
+ */
58
+ readonly cleared: boolean;
59
+ /**
60
+ * Clear the callback's cached value
61
+ */
62
+ clear(): void;
63
+ };
64
+ export type OnceState<Value, Callback = GenericCallback> = {
65
+ callback: Callback;
66
+ called: boolean;
67
+ cleared: boolean;
68
+ value: Value;
69
+ };
70
+ export declare const ONCE_NAME_ASYNC = "asyncOnce";
71
+ export declare const ONCE_NAME_SYNC = "once";
72
+ export declare const ONCE_PROPERTY = "$once";
73
+ export declare const ONCE_MESSAGE_CLEARED = "Once has been cleared";
74
+ export declare const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
75
+ export declare const ONCE_SYMBOL: unique symbol;
76
+ //#endregion
@@ -0,0 +1,9 @@
1
+ //#region src/models/function/once.model.ts
2
+ const ONCE_NAME_ASYNC = "asyncOnce";
3
+ const ONCE_NAME_SYNC = "once";
4
+ const ONCE_PROPERTY = "$once";
5
+ const ONCE_MESSAGE_CLEARED = "Once has been cleared";
6
+ const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
7
+ const ONCE_SYMBOL = Symbol(ONCE_PROPERTY);
8
+ //#endregion
9
+ export { ONCE_MESSAGE_CLEARED, ONCE_MESSAGE_EXPECTATION, ONCE_NAME_ASYNC, ONCE_NAME_SYNC, ONCE_PROPERTY, ONCE_SYMBOL };
@@ -0,0 +1,17 @@
1
+ //#region src/models/function/retry.model.d.ts
2
+ /**
3
+ * An error thrown when a retry fails
4
+ */
5
+ export declare class RetryError extends Error {
6
+ readonly original: unknown;
7
+ constructor(message: string, original: unknown);
8
+ }
9
+ export type RetryOptions = {
10
+ delay?: number;
11
+ times?: number;
12
+ when?: (error: unknown) => boolean;
13
+ };
14
+ export declare const RETRY_ERROR_NAME = "RetryError";
15
+ export declare const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
16
+ export declare const RETRY_MESSAGE_FAILED = "Retry failed";
17
+ //#endregion
@@ -0,0 +1,17 @@
1
+ //#region src/models/function/retry.model.ts
2
+ /**
3
+ * An error thrown when a retry fails
4
+ */
5
+ var RetryError = class extends Error {
6
+ original;
7
+ constructor(message, original) {
8
+ super(message);
9
+ this.original = original;
10
+ this.name = RETRY_ERROR_NAME;
11
+ }
12
+ };
13
+ const RETRY_ERROR_NAME = "RetryError";
14
+ const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
15
+ const RETRY_MESSAGE_FAILED = "Retry failed";
16
+ //#endregion
17
+ export { RETRY_ERROR_NAME, RETRY_MESSAGE_EXPECTATION, RETRY_MESSAGE_FAILED, RetryError };
@@ -0,0 +1,20 @@
1
+ import { GenericCallback } from "../index.mjs";
2
+ import { Asserter } from "./assert.model.mjs";
3
+ import { UnwrapValue } from "../result.model.mjs";
4
+ //#region src/models/function/work.model.d.ts
5
+ /**
6
+ * An asynchronous _Flow_, a function that pipes a value through a series of functions
7
+ */
8
+ export type AsyncFlow<Callback extends GenericCallback, Value> = (...args: Parameters<Callback>) => Promise<UnwrapValue<Value>>;
9
+ /**
10
+ * A synchronous _Flow_, a function that pipe a value through a series of functions
11
+ */
12
+ export type Flow<Callback extends GenericCallback, Value> = (...args: Parameters<Callback>) => UnwrapValue<Value>;
13
+ export declare const WORK_MESSAGE_FLOW_ARRAY = "Flow expected to receive an array of functions";
14
+ export declare const WORK_MESSAGE_FLOW_PROMISE = "Synchronous Flow received a promise. Use `flow.async` instead.";
15
+ export declare const WORK_MESSAGE_NESTING = "Return values are too deeply nested.";
16
+ export declare const WORK_MESSAGE_PIPE_ARRAY = "Pipe expected to receive an array of functions";
17
+ export declare const WORK_MESSAGE_PIPE_PROMISE = "Synchronous Pipe received a promise. Use `pipe.async` instead.";
18
+ export declare const assertFlowFunctions: Asserter<Function[]>;
19
+ export declare const assertPipeFunctions: Asserter<Function[]>;
20
+ //#endregion
@@ -0,0 +1,11 @@
1
+ import { assert } from "../../internal/function/assert.mjs";
2
+ //#region src/models/function/work.model.ts
3
+ const WORK_MESSAGE_FLOW_ARRAY = "Flow expected to receive an array of functions";
4
+ const WORK_MESSAGE_FLOW_PROMISE = "Synchronous Flow received a promise. Use `flow.async` instead.";
5
+ const WORK_MESSAGE_NESTING = "Return values are too deeply nested.";
6
+ const WORK_MESSAGE_PIPE_ARRAY = "Pipe expected to receive an array of functions";
7
+ const WORK_MESSAGE_PIPE_PROMISE = "Synchronous Pipe received a promise. Use `pipe.async` instead.";
8
+ const assertFlowFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), WORK_MESSAGE_FLOW_ARRAY, TypeError);
9
+ const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), WORK_MESSAGE_PIPE_ARRAY, TypeError);
10
+ //#endregion
11
+ export { WORK_MESSAGE_FLOW_ARRAY, WORK_MESSAGE_FLOW_PROMISE, WORK_MESSAGE_NESTING, WORK_MESSAGE_PIPE_ARRAY, WORK_MESSAGE_PIPE_PROMISE, assertFlowFunctions, assertPipeFunctions };
@@ -1,6 +1,6 @@
1
- import { GenericCallback } from "../../models.mjs";
2
- import { Subscription, SubscriptionProperty, Subscriptions } from "../subscription.mjs";
3
- //#region src/internal/models/herald.model.d.ts
1
+ import { GenericCallback } from "./index.mjs";
2
+ import { Subscription, SubscriptionProperty, Subscriptions } from "./subscription.model.mjs";
3
+ //#region src/models/herald.model.d.ts
4
4
  export type Herald<Events extends Record<string, GenericCallback>> = {
5
5
  readonly events: HeraldEvents<Events>;
6
6
  /**
@@ -1,5 +1,5 @@
1
- import { SUBSCRIPTION_NAME } from "../subscription.mjs";
2
- //#region src/internal/models/herald.model.ts
1
+ import { SUBSCRIPTION_NAME } from "./subscription.model.mjs";
2
+ //#region src/models/herald.model.ts
3
3
  const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
4
4
  const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
5
5
  const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
@@ -1,4 +1,4 @@
1
- //#region src/models.d.ts
1
+ //#region src/models/index.d.ts
2
2
  /**
3
3
  * A generic array or object
4
4
  */
@@ -13,6 +13,10 @@ export type BuiltIns = void | Date | Primitive | RegExp;
13
13
  * A generic class constructor
14
14
  */
15
15
  export type Constructor<Instance = unknown> = new (...args: any[]) => Instance;
16
+ /**
17
+ * A frozen value with readonly properties _(going as deep as possible)_
18
+ */
19
+ export type Frozen<Value> = Value extends unknown[] ? Readonly<Value> : Value extends PlainObject ? { readonly [Key in keyof Value]: Frozen<Value[Key]>; } : Value extends Map<infer Key, infer Value> ? ReadonlyMap<Key, Frozen<Value>> : Value extends Set<infer Item> ? ReadonlySet<Frozen<Item>> : Readonly<Value>;
16
20
  /**
17
21
  * A generic async callback function
18
22
  */
@@ -72,52 +76,6 @@ export type NumericalKeys<Value> = { [ItemKey in keyof Value]: ItemKey extends n
72
76
  * The numerical values of an object
73
77
  */
74
78
  export type NumericalValues<Item extends PlainObject> = Simplify<{ [ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey]; }>;
75
- /**
76
- * An asynchronous function that can only be called once, returning the same value on subsequent calls
77
- */
78
- export type OnceAsync<Callback extends GenericAsyncCallback> = {
79
- /**
80
- * Did the callback's promise reject?
81
- */
82
- readonly error: boolean;
83
- /**
84
- * Has the callback finished?
85
- */
86
- readonly finished: boolean;
87
- /**
88
- * Run the callback
89
- *
90
- * @param parameters Callback parameters
91
- * @returns Call result
92
- */
93
- run(...parameters: Parameters<Callback>): ReturnType<Callback>;
94
- } & OnceProperties;
95
- /**
96
- * A callback function that can only be called once, returning the same value on subsequent calls
97
- */
98
- export type Once<Callback extends GenericCallback> = {
99
- /**
100
- * Run the callback
101
- *
102
- * @param parameters Callback parameters
103
- * @returns Call result
104
- */
105
- run(...parameters: Parameters<Callback>): ReturnType<Callback>;
106
- } & OnceProperties;
107
- type OnceProperties = {
108
- /**
109
- * Has the callback been called?
110
- */
111
- readonly called: boolean;
112
- /**
113
- * Has the callback's value been cleared?
114
- */
115
- readonly cleared: boolean;
116
- /**
117
- * Clear the callback's cached value
118
- */
119
- clear(): void;
120
- };
121
79
  /**
122
80
  * A generic object
123
81
  */
@@ -0,0 +1,83 @@
1
+ //#region src/models/logger.model.d.ts
2
+ export type InternalTimeLogger = {
3
+ [LOGGER_SYMBOL]: TimeLoggerState;
4
+ } & TimeLogger;
5
+ export type Lumberjack = {
6
+ /**
7
+ * Log any number of values at the "debug" log level
8
+ */
9
+ get debug(): typeof console.debug;
10
+ /**
11
+ * Log the value and shows all its properties
12
+ */
13
+ get dir(): typeof console.dir;
14
+ /**
15
+ * Is logging to the console enabled? _(defaults to `true`)_
16
+ */
17
+ get enabled(): boolean;
18
+ /**
19
+ * Enable or disable logging to the console
20
+ */
21
+ set enabled(value: boolean);
22
+ /**
23
+ * Log any number of values at the "error" log level
24
+ */
25
+ get error(): typeof console.error;
26
+ /**
27
+ * Log any number of values at the "info" log level
28
+ */
29
+ get info(): typeof console.info;
30
+ /**
31
+ * Log any number of values at the "log" log level
32
+ */
33
+ get log(): typeof console.log;
34
+ /**
35
+ * Log data as a table, with optional properties to use as columns
36
+ */
37
+ get table(): typeof console.table;
38
+ /**
39
+ * Log any number of values together with a trace from where it was called
40
+ */
41
+ get trace(): typeof console.trace;
42
+ /**
43
+ * Log any number of values at the "warn" log level
44
+ */
45
+ get warn(): typeof console.warn;
46
+ /**
47
+ * Start a timed logger with a label
48
+ *
49
+ * @param label Label for the logger
50
+ * @returns _TimedLogger_ instance
51
+ */
52
+ time(label: string): TimeLogger;
53
+ };
54
+ /**
55
+ * A named timer that can be used to log durations to the console
56
+ */
57
+ export type TimeLogger = {
58
+ /**
59
+ * Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
60
+ */
61
+ get active(): boolean;
62
+ /**
63
+ * Log the current duration of the timer _(ignored if logging is disabled)_
64
+ */
65
+ get log(): () => void;
66
+ /**
67
+ * Stop the timer and logs the total duration
68
+ *
69
+ * _(Will always log the total duration, even if logging is disabled)_
70
+ */
71
+ get stop(): () => void;
72
+ };
73
+ export type TimeLoggerState = {
74
+ isActive(): boolean;
75
+ label: string;
76
+ started: boolean;
77
+ stopped: boolean;
78
+ };
79
+ export declare const LOGGER_NAME = "Logger";
80
+ export declare const LOGGER_NAME_TIMED = "TimedLogger";
81
+ export declare const LOGGER_PROPERTY = "$logger";
82
+ export declare const LOGGER_SYMBOL: unique symbol;
83
+ //#endregion
@@ -0,0 +1,7 @@
1
+ //#region src/models/logger.model.ts
2
+ const LOGGER_NAME = "Logger";
3
+ const LOGGER_NAME_TIMED = "TimedLogger";
4
+ const LOGGER_PROPERTY = "$logger";
5
+ const LOGGER_SYMBOL = Symbol(LOGGER_PROPERTY);
6
+ //#endregion
7
+ export { LOGGER_NAME, LOGGER_NAME_TIMED, LOGGER_PROPERTY, LOGGER_SYMBOL };
@@ -0,0 +1,16 @@
1
+ //#region src/models/math.model.d.ts
2
+ export type Aggregation = {
3
+ array: boolean;
4
+ count: number;
5
+ first: boolean;
6
+ items?: Record<number, unknown[]>;
7
+ value: number;
8
+ };
9
+ export type AggregationCallback = (aggregation: Aggregation, value: number, notNumber: boolean, item?: unknown) => number;
10
+ export type AggregationType = "average" | "max" | "min" | "sum";
11
+ export type NonAverageAggregationType = "max" | "min" | "sum";
12
+ export declare const AGGREGATION_AVERAGE = "average";
13
+ export declare const AGGREGATION_MAX = "max";
14
+ export declare const AGGREGATION_MIN = "min";
15
+ export declare const AGGREGATION_SUM = "sum";
16
+ //#endregion
@@ -0,0 +1,7 @@
1
+ //#region src/models/math.model.ts
2
+ const AGGREGATION_AVERAGE = "average";
3
+ const AGGREGATION_MAX = "max";
4
+ const AGGREGATION_MIN = "min";
5
+ const AGGREGATION_SUM = "sum";
6
+ //#endregion
7
+ export { AGGREGATION_AVERAGE, AGGREGATION_MAX, AGGREGATION_MIN, AGGREGATION_SUM };
@@ -0,0 +1,10 @@
1
+ //#region src/models/misc.model.d.ts
2
+ export declare const EXPRESSION_INTEGER: RegExp;
3
+ export declare const EXPRESSION_NUMBER_BINARY: RegExp;
4
+ export declare const EXPRESSION_NUMBER_OCTAL: RegExp;
5
+ export declare const EXPRESSION_NUMBER_ZEROISH: RegExp;
6
+ export declare const EXPRESSION_NUMERICAL_PREFIX: RegExp;
7
+ export declare const EXPRESSION_WHITESPACE_MULTIPLE: RegExp;
8
+ export declare const EXPRESSION_WHITESPACE_ONLY: RegExp;
9
+ export declare const NUMBER_OCTAL_VALUE = 8;
10
+ //#endregion
@@ -0,0 +1,11 @@
1
+ //#region src/models/misc.model.ts
2
+ const EXPRESSION_INTEGER = /^\d+$/;
3
+ const EXPRESSION_NUMBER_BINARY = /^0b[01]+$/i;
4
+ const EXPRESSION_NUMBER_OCTAL = /^0o[0-7]+$/i;
5
+ const EXPRESSION_NUMBER_ZEROISH = /^\s*0+\s*$/;
6
+ const EXPRESSION_NUMERICAL_PREFIX = /^\d/;
7
+ const EXPRESSION_WHITESPACE_MULTIPLE = /\s+/g;
8
+ const EXPRESSION_WHITESPACE_ONLY = /^\s*$/;
9
+ const NUMBER_OCTAL_VALUE = 8;
10
+ //#endregion
11
+ export { EXPRESSION_INTEGER, EXPRESSION_NUMBER_BINARY, EXPRESSION_NUMBER_OCTAL, EXPRESSION_NUMBER_ZEROISH, EXPRESSION_NUMERICAL_PREFIX, EXPRESSION_WHITESPACE_MULTIPLE, EXPRESSION_WHITESPACE_ONLY, NUMBER_OCTAL_VALUE };
@@ -1,5 +1,5 @@
1
1
  import { Err, Ok, Result } from "./result.model.mjs";
2
- //#region src/internal/models/plan.model.d.ts
2
+ //#region src/models/plan.model.d.ts
3
3
  /**
4
4
  * An asynchronous plan of execution that can yield intermediate results and eventually return a result
5
5
  */
@@ -26,7 +26,7 @@ export type AsyncPlan<Yielded, Returned, Parameters extends unknown[]> = {
26
26
  */
27
27
  run(...parameters: Parameters): Promise<PlanReturned<Returned>>;
28
28
  };
29
- type AsyncPlanState = {
29
+ export type AsyncPlanState = {
30
30
  generator(...parameters: unknown[]): AsyncGenerator;
31
31
  } & BaseState<typeof PLAN_TYPE_PLAN_ASYNC>;
32
32
  type BaseState<Type extends PlanType> = {
@@ -69,7 +69,7 @@ type PlanErrors<Yielded, Returned> = PlanErrorValues<Yielded> | PlanErrorValues<
69
69
  export type PlanError<Yielded, Returned> = [PlanErrors<Yielded, Returned>] extends [never] ? Error : PlanErrors<Yielded, Returned>;
70
70
  type PlanErrorValues<Original> = Original extends Error ? Original : Original extends Err<infer Error> ? Error : never;
71
71
  export type PlanReturned<Returned> = Returned extends Error ? never : Returned extends Err<infer _> ? never : Returned;
72
- type PlanState = {
72
+ export type PlanState = {
73
73
  generator(...parameters: unknown[]): Generator;
74
74
  } & BaseState<typeof PLAN_TYPE_PLAN_SYNC>;
75
75
  export type PlanType = "asyncPlan" | "plan";
@@ -1,4 +1,4 @@
1
- //#region src/internal/models/plan.model.ts
1
+ //#region src/models/plan.model.ts
2
2
  const GENERATOR_NAME_ASYNC = "AsyncGeneratorFunction";
3
3
  const GENERATOR_NAME_SYNC = "GeneratorFunction";
4
4
  const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";