@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.
- package/dist/array/difference.d.mts +1 -1
- package/dist/array/difference.mjs +3 -2
- package/dist/array/exists.d.mts +1 -1
- package/dist/array/exists.mjs +3 -2
- package/dist/array/filter.d.mts +1 -1
- package/dist/array/filter.mjs +1 -0
- package/dist/array/find.d.mts +1 -1
- package/dist/array/find.mjs +4 -3
- package/dist/array/first.d.mts +1 -1
- package/dist/array/flatten.d.mts +1 -1
- package/dist/array/group-by.d.mts +1 -1
- package/dist/array/index.d.mts +2 -2
- package/dist/array/insert.mjs +3 -2
- package/dist/array/intersection.mjs +3 -2
- package/dist/array/last.d.mts +1 -1
- package/dist/array/move.d.mts +1 -1
- package/dist/array/partition.d.mts +1 -1
- package/dist/array/partition.mjs +1 -0
- package/dist/array/push.mjs +3 -2
- package/dist/array/select.d.mts +10 -12
- package/dist/array/select.mjs +1 -0
- package/dist/array/single.d.mts +1 -1
- package/dist/array/single.mjs +1 -0
- package/dist/array/slice.d.mts +1 -1
- package/dist/array/slice.mjs +4 -5
- package/dist/array/sort.d.mts +4 -103
- package/dist/array/sort.mjs +6 -14
- package/dist/array/splice.mjs +3 -2
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/to-map.d.mts +1 -1
- package/dist/array/to-record.d.mts +1 -1
- package/dist/array/to-set.d.mts +1 -1
- package/dist/array/toggle.d.mts +1 -1
- package/dist/array/union.mjs +3 -2
- package/dist/array/unique.d.mts +1 -1
- package/dist/array/unique.mjs +3 -2
- package/dist/array/update.d.mts +1 -1
- package/dist/beacon.d.mts +6 -92
- package/dist/beacon.mjs +6 -16
- package/dist/color/constants.d.mts +2 -2
- package/dist/color/constants.mjs +1 -1
- package/dist/color/index.d.mts +1 -1
- package/dist/color/instance.d.mts +1 -1
- package/dist/color/instance.mjs +0 -1
- package/dist/color/misc/alpha.d.mts +1 -1
- package/dist/color/misc/format.d.mts +1 -1
- package/dist/color/misc/get.d.mts +1 -1
- package/dist/color/misc/is.d.mts +2 -2
- package/dist/color/misc/is.mjs +1 -0
- package/dist/color/misc/state.d.mts +1 -1
- package/dist/color/space/hex.d.mts +1 -1
- package/dist/color/space/hsl.d.mts +1 -1
- package/dist/color/space/hwb.d.mts +1 -1
- package/dist/color/space/rgb.d.mts +1 -1
- package/dist/function/limit.d.mts +2 -2
- package/dist/function/limit.mjs +2 -1
- package/dist/function/once.d.mts +7 -3
- package/dist/function/once.mjs +5 -10
- package/dist/function/retry.d.mts +4 -14
- package/dist/function/retry.mjs +3 -15
- package/dist/herald.d.mts +2 -2
- package/dist/index.d.mts +466 -351
- package/dist/index.mjs +491 -439
- package/dist/internal/aborter.d.mts +1 -6
- package/dist/internal/aborter.mjs +3 -4
- package/dist/internal/array/callbacks.d.mts +3 -7
- package/dist/internal/array/chunk.mjs +2 -2
- package/dist/internal/array/find.d.mts +5 -23
- package/dist/internal/array/find.mjs +5 -9
- package/dist/internal/array/get.d.mts +1 -1
- package/dist/internal/array/group.d.mts +1 -1
- package/dist/internal/array/index-of.d.mts +1 -1
- package/dist/internal/array/index-of.mjs +4 -3
- package/dist/internal/array/insert.d.mts +2 -5
- package/dist/internal/array/insert.mjs +2 -4
- package/dist/internal/array/match.d.mts +2 -5
- package/dist/internal/array/match.mjs +10 -20
- package/dist/internal/array/overlap.d.mts +2 -10
- package/dist/internal/array/sets.d.mts +2 -5
- package/dist/internal/array/sets.mjs +5 -7
- package/dist/internal/function/assert.d.mts +5 -12
- package/dist/internal/function/assert.mjs +2 -2
- package/dist/internal/function/limit.d.mts +2 -37
- package/dist/internal/function/limit.mjs +4 -15
- package/dist/internal/function/memoize.d.mts +5 -70
- package/dist/internal/function/memoize.mjs +2 -5
- package/dist/internal/function/work.d.mts +16 -22
- package/dist/internal/function/work.mjs +1 -8
- package/dist/internal/herald.d.mts +3 -3
- package/dist/internal/herald.mjs +2 -1
- package/dist/internal/is.d.mts +1 -1
- package/dist/internal/math/aggregate.d.mts +2 -14
- package/dist/internal/math/aggregate.mjs +2 -5
- package/dist/internal/number.mjs +4 -7
- package/dist/internal/result/attempt.d.mts +1 -1
- package/dist/internal/result/misc.d.mts +1 -1
- package/dist/internal/string/case.mjs +6 -16
- package/dist/internal/string/misc.mjs +1 -3
- package/dist/internal/subscription.d.mts +1 -100
- package/dist/internal/subscription.mjs +3 -9
- package/dist/internal/value/compare.d.mts +4 -4
- package/dist/internal/value/compare.mjs +1 -1
- package/dist/internal/value/equal.d.mts +6 -57
- package/dist/internal/value/equal.mjs +5 -10
- package/dist/internal/value/get.d.mts +1 -1
- package/dist/internal/value/handlers.d.mts +2 -21
- package/dist/internal/value/has.d.mts +2 -2
- package/dist/internal/value/misc.d.mts +1 -1
- package/dist/internal/value/misc.mjs +8 -14
- package/dist/internal/value/set.d.mts +1 -1
- package/dist/internal/value/set.mjs +2 -2
- package/dist/is.mjs +3 -3
- package/dist/logger.d.mts +3 -70
- package/dist/logger.mjs +2 -5
- package/dist/math.d.mts +1 -1
- package/dist/math.mjs +2 -1
- package/dist/models/aborter.model.d.mts +12 -0
- package/dist/models/aborter.model.mjs +5 -0
- package/dist/models/array/array.find.model.d.mts +22 -0
- package/dist/models/array/array.find.model.mjs +8 -0
- package/dist/models/array/array.match.model.d.mts +14 -0
- package/dist/models/array/array.match.model.mjs +14 -0
- package/dist/models/array/array.misc.model.d.mts +36 -0
- package/dist/models/array/array.misc.model.mjs +12 -0
- package/dist/models/array/array.sort.model.d.mts +122 -0
- package/dist/models/array/array.sort.model.mjs +12 -0
- package/dist/models/beacon.model.d.mts +119 -0
- package/dist/models/beacon.model.mjs +16 -0
- package/dist/{color/models.d.mts → models/color.model.d.mts} +4 -4
- package/dist/models/function/assert.model.d.mts +13 -0
- package/dist/models/function/assert.model.mjs +4 -0
- package/dist/models/function/limiter.model.d.mts +71 -0
- package/dist/models/function/limiter.model.mjs +15 -0
- package/dist/models/function/memoize.model.d.mts +88 -0
- package/dist/models/function/memoize.model.mjs +7 -0
- package/dist/models/function/once.model.d.mts +76 -0
- package/dist/models/function/once.model.mjs +9 -0
- package/dist/models/function/retry.model.d.mts +17 -0
- package/dist/models/function/retry.model.mjs +17 -0
- package/dist/models/function/work.model.d.mts +20 -0
- package/dist/models/function/work.model.mjs +11 -0
- package/dist/{internal/models → models}/herald.model.d.mts +3 -3
- package/dist/{internal/models → models}/herald.model.mjs +2 -2
- package/dist/{models.d.mts → models/index.d.mts} +8 -50
- package/dist/models/logger.model.d.mts +83 -0
- package/dist/models/logger.model.mjs +7 -0
- package/dist/models/math.model.d.mts +16 -0
- package/dist/models/math.model.mjs +7 -0
- package/dist/models/misc.model.d.mts +10 -0
- package/dist/models/misc.model.mjs +11 -0
- package/dist/{internal/models → models}/plan.model.d.mts +17 -15
- package/dist/{internal/models → models}/plan.model.mjs +1 -1
- package/dist/models/promise.model.d.mts +119 -0
- package/dist/models/promise.model.mjs +47 -0
- package/dist/models/query.model.d.mts +9 -0
- package/dist/models/query.model.mjs +14 -0
- package/dist/models/queue.model.d.mts +251 -0
- package/dist/models/queue.model.mjs +29 -0
- package/dist/models/random.model.d.mts +6 -0
- package/dist/models/random.model.mjs +7 -0
- package/dist/{internal/models → models}/result.model.d.mts +10 -2
- package/dist/models/string/string.case.model.d.mts +19 -0
- package/dist/models/string/string.case.model.mjs +14 -0
- package/dist/models/string/string.fuzzy.model.d.mts +108 -0
- package/dist/models/string/string.fuzzy.model.mjs +9 -0
- package/dist/models/string/string.misc.model.d.mts +13 -0
- package/dist/models/string/string.misc.model.mjs +13 -0
- package/dist/models/string/string.normalize.model.d.mts +85 -0
- package/dist/models/string/string.normalize.model.mjs +43 -0
- package/dist/models/string/string.template.model.d.mts +50 -0
- package/dist/models/string/string.template.model.mjs +5 -0
- package/dist/models/subscription.model.d.mts +127 -0
- package/dist/models/subscription.model.mjs +10 -0
- package/dist/models/value/value.clone.model.d.mts +56 -0
- package/dist/models/value/value.clone.model.mjs +24 -0
- package/dist/models/value/value.diff.model.d.mts +61 -0
- package/dist/models/value/value.diff.model.mjs +6 -0
- package/dist/models/value/value.equal.model.d.mts +76 -0
- package/dist/models/value/value.equal.model.mjs +9 -0
- package/dist/models/value/value.handler.model.d.mts +27 -0
- package/dist/models/value/value.handler.model.mjs +1 -0
- package/dist/models/value/value.merge.model.d.mts +82 -0
- package/dist/models/value/value.merge.model.mjs +5 -0
- package/dist/models/value/value.misc.model.d.mts +33 -0
- package/dist/models/value/value.misc.model.mjs +12 -0
- package/dist/models/value/value.transform.model.d.mts +28 -0
- package/dist/models/value/value.transform.model.mjs +4 -0
- package/dist/plan/generate.d.mts +3 -2
- package/dist/plan/generate.mjs +14 -10
- package/dist/plan/index.d.mts +1 -1
- package/dist/plan/index.mjs +2 -2
- package/dist/plan/is.d.mts +31 -2
- package/dist/plan/is.mjs +45 -1
- package/dist/plan/misc.d.mts +21 -2
- package/dist/plan/misc.mjs +32 -2
- package/dist/plan/models.d.mts +1 -1
- package/dist/plan/result.d.mts +7 -7
- package/dist/plan/result.mjs +6 -6
- package/dist/plan/run.d.mts +5 -5
- package/dist/plan/run.mjs +6 -6
- package/dist/promise/delay.d.mts +1 -1
- package/dist/promise/delay.mjs +2 -1
- package/dist/promise/helpers.d.mts +2 -2
- package/dist/promise/helpers.mjs +6 -6
- package/dist/promise/index.d.mts +2 -2
- package/dist/promise/index.mjs +1 -1
- package/dist/promise/misc.d.mts +3 -3
- package/dist/promise/misc.mjs +7 -4
- package/dist/promise/models.d.mts +2 -106
- package/dist/promise/models.mjs +1 -35
- package/dist/promise/timed.d.mts +2 -2
- package/dist/promise/timed.mjs +3 -3
- package/dist/query.d.mts +1 -1
- package/dist/query.mjs +5 -15
- package/dist/queue.d.mts +6 -200
- package/dist/queue.mjs +9 -34
- package/dist/random.mjs +2 -5
- package/dist/result/match.d.mts +1 -1
- package/dist/result/match.mjs +27 -15
- package/dist/result/misc.d.mts +1 -1
- package/dist/result/work/flow.d.mts +13 -21
- package/dist/result/work/flow.mjs +0 -1
- package/dist/result/work/pipe.d.mts +2 -2
- package/dist/result/work/pipe.mjs +0 -1
- package/dist/string/fuzzy.d.mts +5 -87
- package/dist/string/fuzzy.mjs +6 -11
- package/dist/string/index.mjs +6 -8
- package/dist/string/match.mjs +4 -6
- package/dist/string/normalize.d.mts +4 -40
- package/dist/string/normalize.mjs +9 -48
- package/dist/string/template.d.mts +5 -43
- package/dist/string/template.mjs +1 -2
- package/dist/subscription.d.mts +2 -1
- package/dist/value/clone.d.mts +6 -42
- package/dist/value/clone.mjs +10 -30
- package/dist/value/collection.mjs +2 -0
- package/dist/value/diff.d.mts +3 -44
- package/dist/value/diff.mjs +1 -3
- package/dist/value/freeze.d.mts +1 -5
- package/dist/value/index.d.mts +4 -3
- package/dist/value/merge.d.mts +6 -64
- package/dist/value/merge.mjs +8 -8
- package/dist/value/omit.d.mts +1 -1
- package/dist/value/pick.d.mts +1 -1
- package/dist/value/shake.d.mts +4 -6
- package/dist/value/smush.d.mts +4 -6
- package/dist/value/smush.mjs +2 -2
- package/dist/value/transform.d.mts +6 -22
- package/dist/value/transform.mjs +1 -1
- package/dist/value/unsmush.d.mts +4 -10
- package/package.json +12 -3
- package/dist/internal/plan.d.mts +0 -45
- package/dist/internal/plan.mjs +0 -70
- package/dist/promise/constants.d.mts +0 -17
- package/dist/promise/constants.mjs +0 -15
- /package/dist/{color/models.mjs → models/color.model.mjs} +0 -0
- /package/dist/{internal/models/result.model.mjs → models/index.mjs} +0 -0
- /package/dist/{models.mjs → models/result.model.mjs} +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Constructor } from "../index.mjs";
|
|
2
|
+
//#region src/models/value/value.equal.model.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Options for value equality comparison
|
|
5
|
+
*/
|
|
6
|
+
export type EqualOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* When `true`, strings are compared case-insensitively
|
|
9
|
+
*/
|
|
10
|
+
ignoreCase?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Keys _(or key expressions)_ to ignore when comparing objects
|
|
13
|
+
*/
|
|
14
|
+
ignoreKeys?: string | RegExp | Array<string | RegExp>;
|
|
15
|
+
/**
|
|
16
|
+
* Should `null` and `undefined` be considered equal?
|
|
17
|
+
*/
|
|
18
|
+
relaxedNullish?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* An equalizer function for comparing values for equality, with predefined options
|
|
22
|
+
*
|
|
23
|
+
* Can be used to compare values, and register or deregister equality comparison handlers for specific classes
|
|
24
|
+
*/
|
|
25
|
+
export type Equalizer = {
|
|
26
|
+
/**
|
|
27
|
+
* Are two strings equal?
|
|
28
|
+
*
|
|
29
|
+
* @param first First string
|
|
30
|
+
* @param second Second string
|
|
31
|
+
* @param ignoreCase If `true`, comparison will be case-insensitive
|
|
32
|
+
* @returns `true` if the strings are equal, otherwise `false`
|
|
33
|
+
*/
|
|
34
|
+
compare(first: string, second: string, ignoreCase?: boolean): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Are two values equal?
|
|
37
|
+
*
|
|
38
|
+
* @param first First value
|
|
39
|
+
* @param second Second value
|
|
40
|
+
* @returns `true` if the values are equal, otherwise `false`
|
|
41
|
+
*/
|
|
42
|
+
compare(first: unknown, second: unknown): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Deregister a equality comparison handler for a specific class
|
|
45
|
+
*
|
|
46
|
+
* @param constructor Class constructor
|
|
47
|
+
*/
|
|
48
|
+
deregister: <Instance>(constructor: Constructor<Instance>) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Register a equality comparison function for a specific class
|
|
51
|
+
*
|
|
52
|
+
* @param constructor Class constructor
|
|
53
|
+
* @param handler Comparison function
|
|
54
|
+
*/
|
|
55
|
+
register: <Instance>(constructor: Constructor<Instance>, handler: (first: Instance, second: Instance) => boolean) => void;
|
|
56
|
+
};
|
|
57
|
+
export type InternalEqualizer = {
|
|
58
|
+
[EQUAL_SYMBOL]: EqualizerOptions;
|
|
59
|
+
} & Equalizer;
|
|
60
|
+
export type EqualizerOptions = {
|
|
61
|
+
ignoreCase: boolean;
|
|
62
|
+
ignoreExpressions: EqualizerOptionsKeys<RegExp[]>;
|
|
63
|
+
ignoreKeys: EqualizerOptionsKeys<Set<string>>;
|
|
64
|
+
relaxedNullish: boolean;
|
|
65
|
+
};
|
|
66
|
+
type EqualizerOptionsKeys<Values> = {
|
|
67
|
+
enabled: boolean;
|
|
68
|
+
values: Values;
|
|
69
|
+
};
|
|
70
|
+
export declare const EQUAL_ARRAY_PEEK_PERCENTAGE = 10;
|
|
71
|
+
export declare const EQUAL_ARRAY_THRESHOLD = 100;
|
|
72
|
+
export declare const EQUAL_ERROR_PROPERTIES: string[];
|
|
73
|
+
export declare const EQUAL_EXPRESSION_PROPERTIES: string[];
|
|
74
|
+
export declare const EQUAL_MINIMUM_LENGTH_FOR_SET = 16;
|
|
75
|
+
export declare const EQUAL_SYMBOL: unique symbol;
|
|
76
|
+
//#endregion
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/models/value/value.equal.model.ts
|
|
2
|
+
const EQUAL_ARRAY_PEEK_PERCENTAGE = 10;
|
|
3
|
+
const EQUAL_ARRAY_THRESHOLD = 100;
|
|
4
|
+
const EQUAL_ERROR_PROPERTIES = ["name", "message"];
|
|
5
|
+
const EQUAL_EXPRESSION_PROPERTIES = ["source", "flags"];
|
|
6
|
+
const EQUAL_MINIMUM_LENGTH_FOR_SET = 16;
|
|
7
|
+
const EQUAL_SYMBOL = Symbol("equal");
|
|
8
|
+
//#endregion
|
|
9
|
+
export { EQUAL_ARRAY_PEEK_PERCENTAGE, EQUAL_ARRAY_THRESHOLD, EQUAL_ERROR_PROPERTIES, EQUAL_EXPRESSION_PROPERTIES, EQUAL_MINIMUM_LENGTH_FOR_SET, EQUAL_SYMBOL };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Constructor, GenericCallback } from "../index.mjs";
|
|
2
|
+
//#region src/models/value/value.handler.model.d.ts
|
|
3
|
+
export type BaseHandler = {
|
|
4
|
+
handlers: WeakMap<WeakKey, string | GenericCallback>;
|
|
5
|
+
options: BaseHandlerOptions;
|
|
6
|
+
owner: GenericCallback;
|
|
7
|
+
deregister(constructor: Constructor): void;
|
|
8
|
+
get(first: unknown, second: unknown): string | GenericCallback | undefined;
|
|
9
|
+
register(constructor: Constructor, handler?: string | GenericCallback): void;
|
|
10
|
+
};
|
|
11
|
+
export type BaseHandlerOptions = {
|
|
12
|
+
callback: GenericCallback;
|
|
13
|
+
method?: string;
|
|
14
|
+
};
|
|
15
|
+
export type CompareHandler<Value> = {
|
|
16
|
+
base: BaseHandler;
|
|
17
|
+
handle(first: unknown, second: unknown, ...parameters: unknown[]): Value;
|
|
18
|
+
};
|
|
19
|
+
export type Constructable = {
|
|
20
|
+
constructor: Constructor;
|
|
21
|
+
};
|
|
22
|
+
export type Handleable = Record<string, GenericCallback>;
|
|
23
|
+
export type ValueHandler = {
|
|
24
|
+
base: BaseHandler;
|
|
25
|
+
handle(value: unknown, ...parameters: unknown[]): unknown;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ArrayOrPlainObject, NestedPartial, PlainObject, UnionToIntersection } from "../index.mjs";
|
|
2
|
+
//#region src/models/value/value.merge.model.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Options for assigning values
|
|
5
|
+
*/
|
|
6
|
+
export type AssignOptions = BaseOptions;
|
|
7
|
+
type BaseOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Key _(or key epxressions)_ for values that should be replaced
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* merge([{items: [1, 2, 3]}, {items: [99]}]); // => {items: [99]}
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
replaceableObjects?: string | RegExp | Array<string | RegExp>;
|
|
16
|
+
/**
|
|
17
|
+
* Skip nullable values when merging objects?
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // => {a: 1, b: 2, c: 3}
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
skipNullableAny?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Skip nullable values when merging arrays?
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* merge([1, 2, 3], [null, null, 99]); // => [1, 2, 99]
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
skipNullableInArrays?: boolean;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* An assigner function for assigning values from one or more objects to the first one
|
|
35
|
+
*/
|
|
36
|
+
export type Assigner = {
|
|
37
|
+
/**
|
|
38
|
+
* Assign values from one or more objects to the first one
|
|
39
|
+
*
|
|
40
|
+
* @param to Value to assign to
|
|
41
|
+
* @param from Values to assign
|
|
42
|
+
* @returns Assigned value
|
|
43
|
+
*/
|
|
44
|
+
assign<To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From]): To & UnionToIntersection<From[number]>;
|
|
45
|
+
};
|
|
46
|
+
export type InternalAssigner = {
|
|
47
|
+
[MERGE_SYMBOL_ASSIGN]: MergingOptions;
|
|
48
|
+
} & Assigner;
|
|
49
|
+
export type InternalMerger = {
|
|
50
|
+
[MERGE_SYMBOL_MERGE]: MergingOptions;
|
|
51
|
+
} & Merger;
|
|
52
|
+
/**
|
|
53
|
+
* Options for merging values
|
|
54
|
+
*/
|
|
55
|
+
export type MergeOptions = {
|
|
56
|
+
/**
|
|
57
|
+
* Assign values to the first array or object instead of creating a new one?
|
|
58
|
+
*/
|
|
59
|
+
assignValues?: boolean;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A merger function for merging multiple arrays or objects into a single one
|
|
63
|
+
*/
|
|
64
|
+
export type Merger = {
|
|
65
|
+
/**
|
|
66
|
+
* Merge multiple arrays or objects into a single one
|
|
67
|
+
*
|
|
68
|
+
* @param values Values to merge
|
|
69
|
+
* @returns Merged value
|
|
70
|
+
*/
|
|
71
|
+
merge<Values extends ArrayOrPlainObject[]>(values: Array<NestedPartial<Values[number]>>): UnionToIntersection<Values[number]>;
|
|
72
|
+
};
|
|
73
|
+
export type MergeReplaceableObjectsCallback = (name: string) => boolean;
|
|
74
|
+
export type MergingOptions = {
|
|
75
|
+
assignValues: boolean;
|
|
76
|
+
replaceableObjects: MergeReplaceableObjectsCallback | undefined;
|
|
77
|
+
skipNullableAny: boolean;
|
|
78
|
+
skipNullableInArrays: boolean;
|
|
79
|
+
};
|
|
80
|
+
export declare const MERGE_SYMBOL_ASSIGN: unique symbol;
|
|
81
|
+
export declare const MERGE_SYMBOL_MERGE: unique symbol;
|
|
82
|
+
//#endregion
|
|
@@ -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
|
package/dist/plan/generate.d.mts
CHANGED
|
@@ -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(
|
|
3
|
-
export declare function generate(
|
|
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
|
package/dist/plan/generate.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { isError } from "../internal/result/misc.mjs";
|
|
1
|
+
import { isError, isOk } from "../internal/result/misc.mjs";
|
|
2
2
|
//#region src/plan/generate.ts
|
|
3
|
-
async function asyncGenerate(
|
|
4
|
-
|
|
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
|
|
11
|
-
|
|
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) {
|
|
|
18
20
|
lastValue = error;
|
|
19
21
|
success = false;
|
|
20
22
|
} finally {
|
|
21
|
-
await generator
|
|
23
|
+
await generator.return(lastValue);
|
|
22
24
|
}
|
|
23
|
-
if (success) return lastValue;
|
|
25
|
+
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
24
26
|
throw lastValue;
|
|
25
27
|
}
|
|
26
|
-
function generate(
|
|
27
|
-
|
|
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 {
|
|
@@ -43,7 +47,7 @@ function generate(callback, parameters) {
|
|
|
43
47
|
} finally {
|
|
44
48
|
generator.return(lastValue);
|
|
45
49
|
}
|
|
46
|
-
if (success) return lastValue;
|
|
50
|
+
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
47
51
|
throw lastValue;
|
|
48
52
|
}
|
|
49
53
|
//#endregion
|
package/dist/plan/index.d.mts
CHANGED
package/dist/plan/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PLAN_MESSAGE_PLAN_INPUT, PLAN_SYMBOL, PLAN_TYPE_PLAN_ASYNC, PLAN_TYPE_PLAN_SYNC } from "../
|
|
2
|
-
import { isAsyncGenerator, isGenerator } from "
|
|
1
|
+
import { PLAN_MESSAGE_PLAN_INPUT, PLAN_SYMBOL, PLAN_TYPE_PLAN_ASYNC, PLAN_TYPE_PLAN_SYNC } from "../models/plan.model.mjs";
|
|
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";
|
|
5
5
|
//#region src/plan/index.ts
|
package/dist/plan/is.d.mts
CHANGED
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AsyncPlan, Plan } from "../models/plan.model.mjs";
|
|
2
|
+
//#region src/plan/is.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Is the value an asynchronous generator function?
|
|
5
|
+
*
|
|
6
|
+
* @param value Value to check
|
|
7
|
+
* @returns `true` if the value is an asynchronous generator function, otherwise `false`
|
|
8
|
+
*/
|
|
9
|
+
export declare function isAsyncGenerator(value: unknown): value is () => AsyncGenerator;
|
|
10
|
+
/**
|
|
11
|
+
* Is the value an asynchronous plan?
|
|
12
|
+
*
|
|
13
|
+
* @param value Value to check
|
|
14
|
+
* @returns `true` if the value is an asynchronous plan, otherwise `false`
|
|
15
|
+
*/
|
|
16
|
+
export declare function isAsyncPlan<Yielded = unknown, Returned = unknown, Parameters extends unknown[] = unknown[]>(value: unknown): value is AsyncPlan<Yielded, Returned, Parameters>;
|
|
17
|
+
/**
|
|
18
|
+
* Is the value a generator function?
|
|
19
|
+
*
|
|
20
|
+
* @param value Value to check
|
|
21
|
+
* @returns `true` if the value is a generator function, otherwise `false`
|
|
22
|
+
*/
|
|
23
|
+
export declare function isGenerator(value: unknown): value is () => Generator;
|
|
24
|
+
/**
|
|
25
|
+
* Is the value a plan?
|
|
26
|
+
*
|
|
27
|
+
* @param value Value to check
|
|
28
|
+
* @returns `true` if the value is a plan, otherwise `false`
|
|
29
|
+
*/
|
|
30
|
+
export declare function isPlan<Yielded = unknown, Returned = unknown, Parameters extends unknown[] = unknown[]>(value: unknown): value is Plan<Yielded, Returned, Parameters>;
|
|
31
|
+
//#endregion
|
package/dist/plan/is.mjs
CHANGED
|
@@ -1,2 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GENERATOR_NAME_ASYNC, GENERATOR_NAME_SYNC, PLAN_SYMBOL, PLAN_TYPE_PLAN_ASYNC, PLAN_TYPE_PLAN_SYNC } from "../models/plan.model.mjs";
|
|
2
|
+
//#region src/plan/is.ts
|
|
3
|
+
/**
|
|
4
|
+
* Is the value an asynchronous generator function?
|
|
5
|
+
*
|
|
6
|
+
* @param value Value to check
|
|
7
|
+
* @returns `true` if the value is an asynchronous generator function, otherwise `false`
|
|
8
|
+
*/
|
|
9
|
+
function isAsyncGenerator(value) {
|
|
10
|
+
return isGeneratorInstance(GENERATOR_NAME_ASYNC, value);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Is the value an asynchronous plan?
|
|
14
|
+
*
|
|
15
|
+
* @param value Value to check
|
|
16
|
+
* @returns `true` if the value is an asynchronous plan, otherwise `false`
|
|
17
|
+
*/
|
|
18
|
+
function isAsyncPlan(value) {
|
|
19
|
+
return isPlanInstance(PLAN_TYPE_PLAN_ASYNC, value);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Is the value a generator function?
|
|
23
|
+
*
|
|
24
|
+
* @param value Value to check
|
|
25
|
+
* @returns `true` if the value is a generator function, otherwise `false`
|
|
26
|
+
*/
|
|
27
|
+
function isGenerator(value) {
|
|
28
|
+
return isGeneratorInstance(GENERATOR_NAME_SYNC, value);
|
|
29
|
+
}
|
|
30
|
+
function isGeneratorInstance(name, value) {
|
|
31
|
+
return typeof value === "function" && value !== null && value.constructor.name === name && typeof value.prototype.next === "function" && typeof value.prototype.return === "function" && typeof value.prototype.throw === "function";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Is the value a plan?
|
|
35
|
+
*
|
|
36
|
+
* @param value Value to check
|
|
37
|
+
* @returns `true` if the value is a plan, otherwise `false`
|
|
38
|
+
*/
|
|
39
|
+
function isPlan(value) {
|
|
40
|
+
return isPlanInstance(PLAN_TYPE_PLAN_SYNC, value);
|
|
41
|
+
}
|
|
42
|
+
function isPlanInstance(type, value) {
|
|
43
|
+
return typeof value === "object" && value !== null && PLAN_SYMBOL in value && value[PLAN_SYMBOL].type === type;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
2
46
|
export { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan };
|
package/dist/plan/misc.d.mts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Ok } from "../models/result.model.mjs";
|
|
2
|
+
//#region src/plan/misc.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create an immediately failing plan
|
|
5
|
+
*
|
|
6
|
+
* @param reason Failure reason
|
|
7
|
+
* @returns Plan failure
|
|
8
|
+
*/
|
|
9
|
+
export declare function fail<Reason>(reason: Reason): Generator<Reason, void>;
|
|
10
|
+
/**
|
|
11
|
+
* Create an immediately succeeding plan
|
|
12
|
+
*
|
|
13
|
+
* @param value Success value
|
|
14
|
+
* @returns Plan success
|
|
15
|
+
*/
|
|
16
|
+
export declare function succeed<Value>(value: Value): Generator<never, Value>;
|
|
17
|
+
export declare function succeedResult<Returned>(value: Returned): Generator<never, Ok<Returned>>;
|
|
18
|
+
export declare namespace succeed {
|
|
19
|
+
export var result: typeof succeedResult;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
package/dist/plan/misc.mjs
CHANGED
|
@@ -1,2 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ok } from "../internal/result/misc.mjs";
|
|
2
|
+
//#region src/plan/misc.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create an immediately failing plan
|
|
5
|
+
*
|
|
6
|
+
* @param reason Failure reason
|
|
7
|
+
* @returns Plan failure
|
|
8
|
+
*/
|
|
9
|
+
function fail(reason) {
|
|
10
|
+
return (function* () {
|
|
11
|
+
throw reason;
|
|
12
|
+
})();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create an immediately succeeding plan
|
|
16
|
+
*
|
|
17
|
+
* @param value Success value
|
|
18
|
+
* @returns Plan success
|
|
19
|
+
*/
|
|
20
|
+
function succeed(value) {
|
|
21
|
+
return (function* () {
|
|
22
|
+
return value;
|
|
23
|
+
})();
|
|
24
|
+
}
|
|
25
|
+
function succeedResult(value) {
|
|
26
|
+
return (function* () {
|
|
27
|
+
return ok(value);
|
|
28
|
+
})();
|
|
29
|
+
}
|
|
30
|
+
succeed.result = succeedResult;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { fail, succeed, succeedResult };
|
package/dist/plan/models.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AsyncPlan, Plan } from "../
|
|
1
|
+
import { AsyncPlan, Plan } from "../models/plan.model.mjs";
|
|
2
2
|
export type { AsyncPlan, Plan };
|
package/dist/plan/result.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Result } from "../
|
|
2
|
-
import { AsyncPlan, InternalPlan, Plan, PlanError,
|
|
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
|
|
@@ -8,7 +8,7 @@ import { AsyncPlan, InternalPlan, Plan, PlanError, PlanResult } from "../interna
|
|
|
8
8
|
*
|
|
9
9
|
* @returns Promised result
|
|
10
10
|
*/
|
|
11
|
-
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned
|
|
11
|
+
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>, ...parameters: Parameters): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
12
12
|
/**
|
|
13
13
|
* Attempt to run the plan to completion
|
|
14
14
|
*
|
|
@@ -16,7 +16,7 @@ export declare function asyncAttemptRun<Yielded, Returned, Parameters extends un
|
|
|
16
16
|
*
|
|
17
17
|
* @returns Promised result
|
|
18
18
|
*/
|
|
19
|
-
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, ...parameters: Parameters): Promise<Result<
|
|
19
|
+
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, ...parameters: Parameters): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
20
20
|
/**
|
|
21
21
|
* Attempt to run the generator to completion
|
|
22
22
|
*
|
|
@@ -24,7 +24,7 @@ export declare function asyncAttemptRun<Yielded, Returned, Parameters extends un
|
|
|
24
24
|
*
|
|
25
25
|
* @returns Result
|
|
26
26
|
*/
|
|
27
|
-
export declare function attemptRun<Yielded, Returned>(generator: () => Generator<Yielded, Returned
|
|
27
|
+
export declare function attemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned>, ...parameters: Parameters): Result<PlanOk<Returned>, PlanError<Yielded, Returned>>;
|
|
28
28
|
/**
|
|
29
29
|
* Attempt to run the plan to completion
|
|
30
30
|
*
|
|
@@ -32,8 +32,8 @@ export declare function attemptRun<Yielded, Returned>(generator: () => Generator
|
|
|
32
32
|
*
|
|
33
33
|
* @returns Result
|
|
34
34
|
*/
|
|
35
|
-
export declare function attemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): Result<
|
|
36
|
-
export declare function attemptRunAsyncPlan(this:
|
|
35
|
+
export declare function attemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): Result<PlanOk<Returned>, PlanError<Yielded, Returned>>;
|
|
36
|
+
export declare function attemptRunAsyncPlan(this: InternalAsyncPlan, ...parameters: unknown[]): Promise<unknown>;
|
|
37
37
|
export declare function attemptRunPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
38
38
|
export declare namespace attemptRun {
|
|
39
39
|
export var async: typeof asyncAttemptRun;
|
package/dist/plan/result.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { asyncAttempt, attempt } from "../internal/result/attempt.mjs";
|
|
2
|
-
import { PLAN_MESSAGE_RUN_INPUT } from "../
|
|
3
|
-
import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "
|
|
2
|
+
import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../models/plan.model.mjs";
|
|
3
|
+
import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "./is.mjs";
|
|
4
4
|
import { asyncGenerate, generate } from "./generate.mjs";
|
|
5
5
|
//#region src/plan/result.ts
|
|
6
6
|
function asyncAttemptRun(input, ...parameters) {
|
|
7
7
|
if (isAsyncPlan(input)) return input.attempt(...parameters);
|
|
8
|
-
if (isAsyncGenerator(input)) return asyncAttempt(() => asyncGenerate(input, parameters));
|
|
8
|
+
if (isAsyncGenerator(input)) return asyncAttempt(() => asyncGenerate(input, parameters, true));
|
|
9
9
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
10
10
|
}
|
|
11
11
|
function attemptRun(input, ...parameters) {
|
|
12
12
|
if (isPlan(input)) return input.attempt(...parameters);
|
|
13
|
-
if (isGenerator(input)) return attempt(() => generate(input, parameters));
|
|
13
|
+
if (isGenerator(input)) return attempt(() => generate(input, parameters, true));
|
|
14
14
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
15
15
|
}
|
|
16
16
|
function attemptRunAsyncPlan(...parameters) {
|
|
17
|
-
return asyncAttempt(() => this
|
|
17
|
+
return asyncAttempt(() => asyncGenerate(this[PLAN_SYMBOL], parameters, true));
|
|
18
18
|
}
|
|
19
19
|
function attemptRunPlan(...parameters) {
|
|
20
|
-
return attempt(() => this
|
|
20
|
+
return attempt(() => generate(this[PLAN_SYMBOL], parameters, true));
|
|
21
21
|
}
|
|
22
22
|
attemptRun.async = asyncAttemptRun;
|
|
23
23
|
//#endregion
|
package/dist/plan/run.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncPlan, InternalAsyncPlan, InternalPlan, Plan,
|
|
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
|
/**
|
|
@@ -7,28 +7,28 @@ import { asyncAttemptRun, attemptRun } from "./result.mjs";
|
|
|
7
7
|
* @param generator Generator to run
|
|
8
8
|
* @returns Result
|
|
9
9
|
*/
|
|
10
|
-
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned
|
|
10
|
+
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>, ...parameters: Parameters): Promise<PlanReturned<Returned>>;
|
|
11
11
|
/**
|
|
12
12
|
* Run an asynchronous plan to completion
|
|
13
13
|
*
|
|
14
14
|
* @param plan Plan to run
|
|
15
15
|
* @returns Result
|
|
16
16
|
*/
|
|
17
|
-
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, ...parameters: Parameters): Promise<
|
|
17
|
+
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, ...parameters: Parameters): Promise<PlanReturned<Returned>>;
|
|
18
18
|
/**
|
|
19
19
|
* Run a generator to completion
|
|
20
20
|
*
|
|
21
21
|
* @param generator Generator to run
|
|
22
22
|
* @returns Result
|
|
23
23
|
*/
|
|
24
|
-
export declare function run<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned
|
|
24
|
+
export declare function run<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned>, ...parameters: Parameters): PlanReturned<Returned>;
|
|
25
25
|
/**
|
|
26
26
|
* Run a plan to completion
|
|
27
27
|
*
|
|
28
28
|
* @param plan Plan to run
|
|
29
29
|
* @returns Result
|
|
30
30
|
*/
|
|
31
|
-
export declare function run<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters):
|
|
31
|
+
export declare function run<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): PlanReturned<Returned>;
|
|
32
32
|
export declare function runAsyncPlan(this: InternalAsyncPlan, ...parameters: unknown[]): Promise<unknown>;
|
|
33
33
|
export declare function runPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
34
34
|
export declare namespace asyncRun {
|