@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
@@ -0,0 +1,5 @@
1
+ //#region src/models/value/value.merge.model.ts
2
+ const MERGE_SYMBOL_ASSIGN = Symbol("assign");
3
+ const MERGE_SYMBOL_MERGE = Symbol("merge");
4
+ //#endregion
5
+ export { MERGE_SYMBOL_ASSIGN, MERGE_SYMBOL_MERGE };
@@ -0,0 +1,33 @@
1
+ import { NestedKeys, NestedValue, PlainObject, Simplify, ToString, UnionToIntersection } from "../index.mjs";
2
+ //#region src/models/value/value.misc.model.d.ts
3
+ export type ComparisonHandler<Value = any> = (first: Value, second: Value) => number;
4
+ /**
5
+ * Thanks, type-fest!
6
+ */
7
+ type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
8
+ /**
9
+ * A shaken object, without any `undefined` values
10
+ */
11
+ export type Shaken<Value extends PlainObject> = Simplify<{ [Key in keyof Value as undefined extends Value[Key] ? never : Key]: Value[Key]; } & { [Key in keyof Value as undefined extends Value[Key] ? [Value[Key]] extends [undefined] ? never : Key : never]?: Exclude<Value[Key], undefined>; }>;
12
+ /**
13
+ * A smushed object, with all nested objects flattened into a single level, using dot notation keys
14
+ */
15
+ export type Smushed<Value extends PlainObject> = Simplify<{ [NestedKey in NestedKeys<Value>]: NestedValue<Value, ToString<NestedKey>>; }>;
16
+ /**
17
+ * An unsmushed object, with all dot notation keys turned into nested keys
18
+ */
19
+ export type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [UnionKey in KeysOfUnion<Value>]: Value[UnionKey]; }, `${string}.${string}`>>;
20
+ export type UnsmushedKey = {
21
+ order: number;
22
+ value: string;
23
+ };
24
+ export declare const COMPARE_NAME: string;
25
+ export declare const VALUE_MISC_EXPRESSION_BRACKET: RegExp;
26
+ export declare const VALUE_MISC_EXPRESSION_DOTS: RegExp;
27
+ export declare const VALUE_MISC_EXPRESSION_NESTED: RegExp;
28
+ export declare const VALUE_MISC_NESTED_MESSAGE_INPUT = "Expected data to be an object";
29
+ export declare const VALUE_MISC_NESTED_MESSAGE_MISSING = "Expected property to exist in object";
30
+ export declare const VALUE_MISC_NESTED_MESSAGE_PATH = "Expected path to be a string";
31
+ export declare const VALUE_MISC_NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed";
32
+ export declare const SMUSH_MAX_DEPTH = 100;
33
+ //#endregion
@@ -0,0 +1,12 @@
1
+ //#region src/models/value/value.misc.model.ts
2
+ const COMPARE_NAME = "compare";
3
+ const VALUE_MISC_EXPRESSION_BRACKET = /\[(\w+)\]/g;
4
+ const VALUE_MISC_EXPRESSION_DOTS = /^\.|\.$/g;
5
+ const VALUE_MISC_EXPRESSION_NESTED = /\.|\[\w+\]/;
6
+ const VALUE_MISC_NESTED_MESSAGE_INPUT = "Expected data to be an object";
7
+ const VALUE_MISC_NESTED_MESSAGE_MISSING = "Expected property to exist in object";
8
+ const VALUE_MISC_NESTED_MESSAGE_PATH = "Expected path to be a string";
9
+ const VALUE_MISC_NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed";
10
+ const SMUSH_MAX_DEPTH = 100;
11
+ //#endregion
12
+ export { COMPARE_NAME, SMUSH_MAX_DEPTH, VALUE_MISC_EXPRESSION_BRACKET, VALUE_MISC_EXPRESSION_DOTS, VALUE_MISC_EXPRESSION_NESTED, VALUE_MISC_NESTED_MESSAGE_INPUT, VALUE_MISC_NESTED_MESSAGE_MISSING, VALUE_MISC_NESTED_MESSAGE_PATH, VALUE_MISC_NESTED_MESSAGE_UNSAFE };
@@ -0,0 +1,28 @@
1
+ import { PlainObject } from "../index.mjs";
2
+ //#region src/models/value/value.transform.model.d.ts
3
+ export type InternalTransformer<Value extends PlainObject> = {
4
+ [TRANSFORM_SYMBOL]: TransformHandler<Value>;
5
+ } & Transformer<Value>;
6
+ /**
7
+ * A callback transform an object's properties
8
+ */
9
+ export type TransformCallback<Value extends PlainObject, Key extends keyof Value> = (key: Key, value: Value[Key]) => Value[Key];
10
+ /**
11
+ * A collection of keyed callbacks to transform an object's properties
12
+ */
13
+ export type TransformCallbacks<Value extends PlainObject> = Partial<{ [Key in keyof Value]: (value: Value[Key]) => Value[Key]; }>;
14
+ export type TransformHandler<Value extends PlainObject> = TransformCallback<Value, keyof Value> | TransformCallbacks<Value>;
15
+ /**
16
+ * A transformer for an object, with predefined callbacks for transforming its properties
17
+ */
18
+ export type Transformer<Value extends PlainObject> = {
19
+ /**
20
+ * Transform an object's properties
21
+ *
22
+ * @param value Object to transform
23
+ * @returns Transformed object
24
+ */
25
+ transform(value: Value): Value;
26
+ };
27
+ export declare const TRANSFORM_SYMBOL: unique symbol;
28
+ //#endregion
@@ -0,0 +1,4 @@
1
+ //#region src/models/value/value.transform.model.ts
2
+ const TRANSFORM_SYMBOL = Symbol("transform");
3
+ //#endregion
4
+ export { TRANSFORM_SYMBOL };
@@ -1,4 +1,5 @@
1
+ import { AsyncPlanState, PlanState } from "../models/plan.model.mjs";
1
2
  //#region src/plan/generate.d.ts
2
- export declare function asyncGenerate(callback: (...parameters: unknown[]) => AsyncGenerator, parameters: unknown[], unwrap: boolean): Promise<unknown>;
3
- export declare function generate(callback: (...parameters: unknown[]) => Generator, parameters: unknown[], unwrap: boolean): unknown;
3
+ export declare function asyncGenerate(input: AsyncPlanState | ((...parameters: unknown[]) => AsyncGenerator), parameters: unknown[], unwrap: boolean): Promise<unknown>;
4
+ export declare function generate(input: PlanState | ((...parameters: unknown[]) => Generator), parameters: unknown[], unwrap: boolean): unknown;
4
5
  //#endregion
@@ -1,14 +1,16 @@
1
1
  import { isError, isOk } from "../internal/result/misc.mjs";
2
2
  //#region src/plan/generate.ts
3
- async function asyncGenerate(callback, parameters, unwrap) {
4
- const generator = callback(...parameters);
3
+ async function asyncGenerate(input, parameters, unwrap) {
4
+ let generator;
5
+ if (typeof input === "function") generator = input(...parameters);
6
+ else generator = input.generator(...parameters);
5
7
  let success = true;
6
8
  let lastValue;
7
9
  try {
8
10
  while (true) {
9
11
  const next = await generator.next(lastValue);
10
- const { done } = next;
11
- let { value } = next;
12
+ const done = next.done === true;
13
+ const { value } = next;
12
14
  if (value instanceof Error) throw value;
13
15
  if (isError(value)) throw value.error;
14
16
  lastValue = value;
@@ -18,13 +20,15 @@ async function asyncGenerate(callback, parameters, unwrap) {
18
20
  lastValue = error;
19
21
  success = false;
20
22
  } finally {
21
- await generator?.return(lastValue);
23
+ await generator.return(lastValue);
22
24
  }
23
25
  if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
24
26
  throw lastValue;
25
27
  }
26
- function generate(callback, parameters, unwrap) {
27
- const generator = callback(...parameters);
28
+ function generate(input, parameters, unwrap) {
29
+ let generator;
30
+ if (typeof input === "function") generator = input(...parameters);
31
+ else generator = input.generator(...parameters);
28
32
  let success = true;
29
33
  let lastValue;
30
34
  try {
@@ -1,4 +1,4 @@
1
- import { AsyncPlan, Plan } from "../internal/models/plan.model.mjs";
1
+ import { AsyncPlan, Plan } from "../models/plan.model.mjs";
2
2
  import { asyncAttemptRun, attemptRun } from "./result.mjs";
3
3
  import { asyncRun, run } from "./run.mjs";
4
4
  //#region src/plan/index.d.ts
@@ -1,4 +1,4 @@
1
- import { PLAN_MESSAGE_PLAN_INPUT, PLAN_SYMBOL, PLAN_TYPE_PLAN_ASYNC, PLAN_TYPE_PLAN_SYNC } from "../internal/models/plan.model.mjs";
1
+ import { PLAN_MESSAGE_PLAN_INPUT, PLAN_SYMBOL, PLAN_TYPE_PLAN_ASYNC, PLAN_TYPE_PLAN_SYNC } from "../models/plan.model.mjs";
2
2
  import { isAsyncGenerator, isGenerator } from "./is.mjs";
3
3
  import { asyncAttemptRun, attemptRun, attemptRunAsyncPlan, attemptRunPlan } from "./result.mjs";
4
4
  import { asyncRun, run, runAsyncPlan, runPlan } from "./run.mjs";
@@ -1,4 +1,4 @@
1
- import { AsyncPlan, Plan } from "../internal/models/plan.model.mjs";
1
+ import { AsyncPlan, Plan } from "../models/plan.model.mjs";
2
2
  //#region src/plan/is.d.ts
3
3
  /**
4
4
  * Is the value an asynchronous generator function?
package/dist/plan/is.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { GENERATOR_NAME_ASYNC, GENERATOR_NAME_SYNC, PLAN_SYMBOL, PLAN_TYPE_PLAN_ASYNC, PLAN_TYPE_PLAN_SYNC } from "../internal/models/plan.model.mjs";
1
+ import { GENERATOR_NAME_ASYNC, GENERATOR_NAME_SYNC, PLAN_SYMBOL, PLAN_TYPE_PLAN_ASYNC, PLAN_TYPE_PLAN_SYNC } from "../models/plan.model.mjs";
2
2
  //#region src/plan/is.ts
3
3
  /**
4
4
  * Is the value an asynchronous generator function?
@@ -1,4 +1,4 @@
1
- import { Ok } from "../internal/models/result.model.mjs";
1
+ import { Ok } from "../models/result.model.mjs";
2
2
  //#region src/plan/misc.d.ts
3
3
  /**
4
4
  * Create an immediately failing plan
@@ -1,2 +1,2 @@
1
- import { AsyncPlan, Plan } from "../internal/models/plan.model.mjs";
1
+ import { AsyncPlan, Plan } from "../models/plan.model.mjs";
2
2
  export type { AsyncPlan, Plan };
@@ -1,5 +1,5 @@
1
- import { Result } from "../internal/models/result.model.mjs";
2
- import { AsyncPlan, InternalAsyncPlan, InternalPlan, Plan, PlanError, PlanOk } from "../internal/models/plan.model.mjs";
1
+ import { Result } from "../models/result.model.mjs";
2
+ import { AsyncPlan, InternalAsyncPlan, InternalPlan, Plan, PlanError, PlanOk } from "../models/plan.model.mjs";
3
3
  //#region src/plan/result.d.ts
4
4
  /**
5
5
  * Attempt to run the generator to completion
@@ -1,5 +1,5 @@
1
1
  import { asyncAttempt, attempt } from "../internal/result/attempt.mjs";
2
- import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../internal/models/plan.model.mjs";
2
+ import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../models/plan.model.mjs";
3
3
  import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "./is.mjs";
4
4
  import { asyncGenerate, generate } from "./generate.mjs";
5
5
  //#region src/plan/result.ts
@@ -14,10 +14,10 @@ function attemptRun(input, ...parameters) {
14
14
  throw new Error(PLAN_MESSAGE_RUN_INPUT);
15
15
  }
16
16
  function attemptRunAsyncPlan(...parameters) {
17
- return asyncAttempt(() => asyncGenerate(this[PLAN_SYMBOL].generator, parameters, true));
17
+ return asyncAttempt(() => asyncGenerate(this[PLAN_SYMBOL], parameters, true));
18
18
  }
19
19
  function attemptRunPlan(...parameters) {
20
- return attempt(() => generate(this[PLAN_SYMBOL].generator, parameters, true));
20
+ return attempt(() => generate(this[PLAN_SYMBOL], parameters, true));
21
21
  }
22
22
  attemptRun.async = asyncAttemptRun;
23
23
  //#endregion
@@ -1,4 +1,4 @@
1
- import { AsyncPlan, InternalAsyncPlan, InternalPlan, Plan, PlanReturned } from "../internal/models/plan.model.mjs";
1
+ import { AsyncPlan, InternalAsyncPlan, InternalPlan, Plan, PlanReturned } from "../models/plan.model.mjs";
2
2
  import { asyncAttemptRun, attemptRun } from "./result.mjs";
3
3
  //#region src/plan/run.d.ts
4
4
  /**
package/dist/plan/run.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../internal/models/plan.model.mjs";
1
+ import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../models/plan.model.mjs";
2
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";
@@ -14,10 +14,10 @@ function run(input, ...parameters) {
14
14
  throw new Error(PLAN_MESSAGE_RUN_INPUT);
15
15
  }
16
16
  function runAsyncPlan(...parameters) {
17
- return asyncGenerate(this[PLAN_SYMBOL].generator, parameters, false);
17
+ return asyncGenerate(this[PLAN_SYMBOL], parameters, false);
18
18
  }
19
19
  function runPlan(...parameters) {
20
- return generate(this[PLAN_SYMBOL].generator, parameters, false);
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]>; } extends (infer Result) ? Result : never;
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; } extends (infer Result) ? Result : 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; } extends (infer Result) ? Result : 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 };