@oscarpalmer/atoms 0.211.0 → 0.213.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/color/instance.mjs +0 -1
- package/dist/color/models.d.mts +1 -1
- package/dist/herald.d.mts +2 -1
- package/dist/index.d.mts +79 -69
- package/dist/index.mjs +57 -49
- package/dist/internal/herald.d.mts +2 -38
- package/dist/internal/herald.mjs +4 -14
- package/dist/internal/models/herald.model.d.mts +60 -0
- package/dist/internal/models/herald.model.mjs +15 -0
- package/dist/internal/models/plan.model.d.mts +14 -12
- package/dist/internal/string/misc.mjs +0 -1
- package/dist/models.d.mts +3 -3
- package/dist/plan/generate.d.mts +2 -2
- package/dist/plan/generate.mjs +5 -5
- package/dist/plan/index.mjs +1 -1
- 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/result.d.mts +6 -6
- package/dist/plan/result.mjs +6 -6
- package/dist/plan/run.d.mts +5 -5
- package/dist/plan/run.mjs +5 -5
- package/dist/promise/models.d.mts +4 -4
- package/dist/result/work/flow.mjs +0 -1
- package/dist/result/work/pipe.mjs +0 -1
- package/dist/value/shake.d.mts +2 -2
- package/package.json +2 -1
- package/dist/internal/plan.d.mts +0 -45
- package/dist/internal/plan.mjs +0 -70
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { GenericCallback } from "../../models.mjs";
|
|
2
|
+
import { Subscription, SubscriptionProperty, Subscriptions } from "../subscription.mjs";
|
|
3
|
+
//#region src/internal/models/herald.model.d.ts
|
|
4
|
+
export type Herald<Events extends Record<string, GenericCallback>> = {
|
|
5
|
+
readonly events: HeraldEvents<Events>;
|
|
6
|
+
/**
|
|
7
|
+
* Remove all event subscribers
|
|
8
|
+
*/
|
|
9
|
+
clear(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Emit an event with parameters
|
|
12
|
+
*
|
|
13
|
+
* @param event Event name
|
|
14
|
+
* @param parameters Event parameters
|
|
15
|
+
*/
|
|
16
|
+
emit<Event extends keyof Events>(event: Event, ...parameters: Parameters<Events[Event]>): void;
|
|
17
|
+
/**
|
|
18
|
+
* Is the event observed by any subscribers?
|
|
19
|
+
*
|
|
20
|
+
* @param event Event name
|
|
21
|
+
* @returns `true` if the event is observed, otherwise `false`
|
|
22
|
+
*/
|
|
23
|
+
observed<Event extends keyof Events>(event: Event): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Subscribe to an event with a callback
|
|
26
|
+
*
|
|
27
|
+
* @param event Event name
|
|
28
|
+
* @param callback Callback function
|
|
29
|
+
* @param signal Optional abort signal to cancel the subscription
|
|
30
|
+
* @returns Subscription instance
|
|
31
|
+
*/
|
|
32
|
+
subscribe<Event extends keyof Events>(event: Event, callback: Events[Event], signal?: AbortSignal): Subscription;
|
|
33
|
+
};
|
|
34
|
+
export type HeraldEvents<Events extends Record<string, GenericCallback>> = { [Key in keyof Events]: Key extends "*" ? never : (callback: Events[Key], signal?: AbortSignal) => void; };
|
|
35
|
+
export type HeraldOnCreate<Events extends Record<string, GenericCallback>> = <Event extends keyof Events>(event: Event, callback: Events[Event], subscription: Subscription) => void;
|
|
36
|
+
export type HeraldOptions<Events extends Record<string, GenericCallback>> = {
|
|
37
|
+
names: Array<keyof Events>;
|
|
38
|
+
property?: SubscriptionProperty;
|
|
39
|
+
onCreate?: HeraldOnCreate<Events>;
|
|
40
|
+
};
|
|
41
|
+
export type HeraldState = {
|
|
42
|
+
keys: Set<string>;
|
|
43
|
+
store: Subscriptions<GenericCallback>;
|
|
44
|
+
onCreate?: HeraldOnCreate<Record<string, GenericCallback>>;
|
|
45
|
+
};
|
|
46
|
+
export type InternalHerald = {
|
|
47
|
+
[HERALD_SYMBOL]: {
|
|
48
|
+
events: HeraldEvents<Record<string, GenericCallback>>;
|
|
49
|
+
state: HeraldState;
|
|
50
|
+
};
|
|
51
|
+
} & Herald<Record<string, GenericCallback>>;
|
|
52
|
+
export declare const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
53
|
+
export declare const HERALD_MESSAGE_ONCREATE = "Herald requires a valid onCreate callback for subscription creation";
|
|
54
|
+
export declare const HERALD_MESSAGE_PROPERTY = "Herald requires valid property information for subscription identification";
|
|
55
|
+
export declare const HERALD_NAME_EVENTS = "events";
|
|
56
|
+
export declare const HERALD_NAME_HERALD = "herald";
|
|
57
|
+
export declare const HERALD_PROPERTY = "$herald";
|
|
58
|
+
export declare const HERALD_SYMBOL: unique symbol;
|
|
59
|
+
export declare const heraldSubscription: SubscriptionProperty;
|
|
60
|
+
//#endregion
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SUBSCRIPTION_NAME } from "../subscription.mjs";
|
|
2
|
+
//#region src/internal/models/herald.model.ts
|
|
3
|
+
const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
4
|
+
const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
|
|
5
|
+
const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
|
|
6
|
+
const HERALD_NAME_EVENTS = "events";
|
|
7
|
+
const HERALD_NAME_HERALD = "herald";
|
|
8
|
+
const HERALD_PROPERTY = "$herald";
|
|
9
|
+
const HERALD_SYMBOL = Symbol(HERALD_PROPERTY);
|
|
10
|
+
const heraldSubscription = {
|
|
11
|
+
key: HERALD_PROPERTY,
|
|
12
|
+
value: SUBSCRIPTION_NAME
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { HERALD_MESSAGE_ARRAY, HERALD_MESSAGE_ONCREATE, HERALD_MESSAGE_PROPERTY, HERALD_NAME_EVENTS, HERALD_NAME_HERALD, HERALD_PROPERTY, HERALD_SYMBOL, heraldSubscription };
|
|
@@ -9,22 +9,22 @@ export type AsyncPlan<Yielded, Returned, Parameters extends unknown[]> = {
|
|
|
9
9
|
*
|
|
10
10
|
* @returns Asynchronous generator
|
|
11
11
|
*/
|
|
12
|
-
[Symbol.asyncIterator]: () => AsyncGenerator<Yielded, Returned
|
|
12
|
+
[Symbol.asyncIterator]: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>;
|
|
13
13
|
/**
|
|
14
14
|
* Attempt to run the plan to completion
|
|
15
15
|
*
|
|
16
16
|
* _Returns a promised {@link Result} instead of a raw value or throwing an error_
|
|
17
17
|
*
|
|
18
|
-
* @returns
|
|
18
|
+
* @returns Attempted result
|
|
19
19
|
*/
|
|
20
|
-
attempt(...parameters: Parameters): Promise<Result<
|
|
20
|
+
attempt(...parameters: Parameters): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
21
21
|
/**
|
|
22
22
|
* Run the plan to completion
|
|
23
23
|
*
|
|
24
24
|
* @throws {PlanError<Yielded, Returned>}
|
|
25
25
|
* @returns Result
|
|
26
26
|
*/
|
|
27
|
-
run(...parameters: Parameters): Promise<
|
|
27
|
+
run(...parameters: Parameters): Promise<PlanReturned<Returned>>;
|
|
28
28
|
};
|
|
29
29
|
type AsyncPlanState = {
|
|
30
30
|
generator(...parameters: unknown[]): AsyncGenerator;
|
|
@@ -47,30 +47,32 @@ export type Plan<Yielded, Returned, Parameters extends unknown[]> = {
|
|
|
47
47
|
*
|
|
48
48
|
* @returns Generator
|
|
49
49
|
*/
|
|
50
|
-
[Symbol.iterator]: () => Generator<Yielded, Returned
|
|
50
|
+
[Symbol.iterator]: (...parameters: Parameters) => Generator<Yielded, Returned>;
|
|
51
51
|
/**
|
|
52
52
|
* Attempt to run the plan to completion
|
|
53
53
|
*
|
|
54
54
|
* _Returns a {@link Result} instead of a raw value or throwing an error_
|
|
55
55
|
*
|
|
56
|
-
* @returns
|
|
56
|
+
* @returns Attempted result
|
|
57
57
|
*/
|
|
58
|
-
attempt(...parameters: Parameters): Result<
|
|
58
|
+
attempt(...parameters: Parameters): Result<PlanOk<Returned>, PlanError<Yielded, Returned>>;
|
|
59
59
|
/**
|
|
60
60
|
* Run the plan to completion
|
|
61
61
|
*
|
|
62
62
|
* @throws {PlanError<Yielded, Returned>}
|
|
63
63
|
* @returns Result
|
|
64
64
|
*/
|
|
65
|
-
run(...parameters: Parameters):
|
|
65
|
+
run(...parameters: Parameters): PlanReturned<Returned>;
|
|
66
66
|
};
|
|
67
|
-
type
|
|
68
|
-
|
|
69
|
-
export type
|
|
67
|
+
export type PlanOk<Returned> = Returned extends Error ? never : Returned extends Err<infer _> ? never : Returned extends Ok<infer Value> ? Value : Returned;
|
|
68
|
+
type PlanErrors<Yielded, Returned> = PlanErrorValues<Yielded> | PlanErrorValues<Returned>;
|
|
69
|
+
export type PlanError<Yielded, Returned> = [PlanErrors<Yielded, Returned>] extends [never] ? Error : PlanErrors<Yielded, Returned>;
|
|
70
|
+
type PlanErrorValues<Original> = Original extends Error ? Original : Original extends Err<infer Error> ? Error : never;
|
|
71
|
+
export type PlanReturned<Returned> = Returned extends Error ? never : Returned extends Err<infer _> ? never : Returned;
|
|
70
72
|
type PlanState = {
|
|
71
73
|
generator(...parameters: unknown[]): Generator;
|
|
72
74
|
} & BaseState<typeof PLAN_TYPE_PLAN_SYNC>;
|
|
73
|
-
export type PlanType = "asyncPlan" | "plan"
|
|
75
|
+
export type PlanType = "asyncPlan" | "plan";
|
|
74
76
|
export declare const GENERATOR_NAME_ASYNC = "AsyncGeneratorFunction";
|
|
75
77
|
export declare const GENERATOR_NAME_SYNC = "GeneratorFunction";
|
|
76
78
|
export declare const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
|
package/dist/models.d.mts
CHANGED
|
@@ -63,7 +63,7 @@ type _NestedValue<Value, Path extends string> = Path extends `${infer ItemKey}.$
|
|
|
63
63
|
/**
|
|
64
64
|
* The nested _(keyed)_ values of an object _(up to 5 levels deep)_
|
|
65
65
|
*/
|
|
66
|
-
export type NestedValues<Value extends PlainObject> = { [Path in NestedKeys<Value>]: NestedValue<Value, Path>; }
|
|
66
|
+
export type NestedValues<Value extends PlainObject> = Simplify<{ [Path in NestedKeys<Value>]: NestedValue<Value, Path>; }>;
|
|
67
67
|
/**
|
|
68
68
|
* The numerical keys of an object
|
|
69
69
|
*/
|
|
@@ -71,7 +71,7 @@ export type NumericalKeys<Value> = { [ItemKey in keyof Value]: ItemKey extends n
|
|
|
71
71
|
/**
|
|
72
72
|
* The numerical values of an object
|
|
73
73
|
*/
|
|
74
|
-
export type NumericalValues<Item extends PlainObject> = { [ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey]; }
|
|
74
|
+
export type NumericalValues<Item extends PlainObject> = Simplify<{ [ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey]; }>;
|
|
75
75
|
/**
|
|
76
76
|
* An asynchronous function that can only be called once, returning the same value on subsequent calls
|
|
77
77
|
*/
|
|
@@ -131,7 +131,7 @@ export type Primitive = null | undefined | string | number | boolean | symbol |
|
|
|
131
131
|
/**
|
|
132
132
|
* Set required keys for a type
|
|
133
133
|
*/
|
|
134
|
-
export type RequiredKeys<Model extends object, Keys extends keyof Model> = Required<Pick<Model, Keys>> & Omit<Model, Keys
|
|
134
|
+
export type RequiredKeys<Model extends object, Keys extends keyof Model> = Simplify<Required<Pick<Model, Keys>> & Omit<Model, Keys>>;
|
|
135
135
|
/**
|
|
136
136
|
* Flattens the type to improve type hints in IDEs
|
|
137
137
|
*
|
package/dist/plan/generate.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
//#region src/plan/generate.d.ts
|
|
2
|
-
export declare function asyncGenerate(callback: (...parameters: unknown[]) => AsyncGenerator, parameters: unknown[]): Promise<unknown>;
|
|
3
|
-
export declare function generate(callback: (...parameters: unknown[]) => Generator, parameters: unknown[]): unknown;
|
|
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;
|
|
4
4
|
//#endregion
|
package/dist/plan/generate.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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(callback, parameters) {
|
|
3
|
+
async function asyncGenerate(callback, parameters, unwrap) {
|
|
4
4
|
const generator = callback(...parameters);
|
|
5
5
|
let success = true;
|
|
6
6
|
let lastValue;
|
|
@@ -20,10 +20,10 @@ async function asyncGenerate(callback, parameters) {
|
|
|
20
20
|
} finally {
|
|
21
21
|
await generator?.return(lastValue);
|
|
22
22
|
}
|
|
23
|
-
if (success) return lastValue;
|
|
23
|
+
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
24
24
|
throw lastValue;
|
|
25
25
|
}
|
|
26
|
-
function generate(callback, parameters) {
|
|
26
|
+
function generate(callback, parameters, unwrap) {
|
|
27
27
|
const generator = callback(...parameters);
|
|
28
28
|
let success = true;
|
|
29
29
|
let lastValue;
|
|
@@ -43,7 +43,7 @@ function generate(callback, parameters) {
|
|
|
43
43
|
} finally {
|
|
44
44
|
generator.return(lastValue);
|
|
45
45
|
}
|
|
46
|
-
if (success) return lastValue;
|
|
46
|
+
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
47
47
|
throw lastValue;
|
|
48
48
|
}
|
|
49
49
|
//#endregion
|
package/dist/plan/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PLAN_MESSAGE_PLAN_INPUT, PLAN_SYMBOL, PLAN_TYPE_PLAN_ASYNC, PLAN_TYPE_PLAN_SYNC } from "../internal/models/plan.model.mjs";
|
|
2
|
-
import { isAsyncGenerator, isGenerator } from "
|
|
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 "../internal/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 "../internal/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 "../internal/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/result.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Result } from "../internal/models/result.model.mjs";
|
|
2
|
-
import { AsyncPlan, InternalPlan, Plan, PlanError,
|
|
2
|
+
import { AsyncPlan, InternalAsyncPlan, InternalPlan, Plan, PlanError, PlanOk } from "../internal/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 "../internal/models/plan.model.mjs";
|
|
3
|
-
import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "
|
|
2
|
+
import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../internal/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].generator, parameters, true));
|
|
18
18
|
}
|
|
19
19
|
function attemptRunPlan(...parameters) {
|
|
20
|
-
return attempt(() => this.
|
|
20
|
+
return attempt(() => generate(this[PLAN_SYMBOL].generator, 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 "../internal/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 {
|
package/dist/plan/run.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../internal/models/plan.model.mjs";
|
|
2
|
-
import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "
|
|
2
|
+
import { isAsyncGenerator, isAsyncPlan, isGenerator, isPlan } from "./is.mjs";
|
|
3
3
|
import { asyncGenerate, generate } from "./generate.mjs";
|
|
4
4
|
import { asyncAttemptRun, attemptRun } from "./result.mjs";
|
|
5
5
|
//#region src/plan/run.ts
|
|
6
6
|
function asyncRun(input, ...parameters) {
|
|
7
7
|
if (isAsyncPlan(input)) return input.run(...parameters);
|
|
8
|
-
if (isAsyncGenerator(input)) return asyncGenerate(input, parameters);
|
|
8
|
+
if (isAsyncGenerator(input)) return asyncGenerate(input, parameters, false);
|
|
9
9
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
10
10
|
}
|
|
11
11
|
function run(input, ...parameters) {
|
|
12
12
|
if (isPlan(input)) return input.run(...parameters);
|
|
13
|
-
if (isGenerator(input)) return generate(input, parameters);
|
|
13
|
+
if (isGenerator(input)) return generate(input, parameters, false);
|
|
14
14
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
15
15
|
}
|
|
16
16
|
function runAsyncPlan(...parameters) {
|
|
17
|
-
return asyncGenerate(this[PLAN_SYMBOL].generator, parameters);
|
|
17
|
+
return asyncGenerate(this[PLAN_SYMBOL].generator, parameters, false);
|
|
18
18
|
}
|
|
19
19
|
function runPlan(...parameters) {
|
|
20
|
-
return generate(this[PLAN_SYMBOL].generator, parameters);
|
|
20
|
+
return generate(this[PLAN_SYMBOL].generator, parameters, false);
|
|
21
21
|
}
|
|
22
22
|
asyncRun.attempt = asyncAttemptRun;
|
|
23
23
|
run.async = asyncRun;
|
|
@@ -72,7 +72,7 @@ export type PromiseStrategy = "complete" | "first";
|
|
|
72
72
|
export declare class PromiseTimeoutError extends Error {
|
|
73
73
|
constructor();
|
|
74
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]>; };
|
|
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
76
|
/**
|
|
77
77
|
* Options for handling multiple _Promises_
|
|
78
78
|
*/
|
|
@@ -87,9 +87,9 @@ export type PromisesOptions = {
|
|
|
87
87
|
strategy?: PromiseStrategy;
|
|
88
88
|
};
|
|
89
89
|
export type PromisesResult<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? Result<Awaited<Value>> : never; };
|
|
90
|
-
export type PromisesUnwrapped<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Awaited<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Awaited<Value> : never; };
|
|
91
|
-
export type PromisesValue<Value> = FulfilledPromise<Value> | RejectedPromise;
|
|
92
|
-
export type PromisesValues<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never; };
|
|
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
93
|
/**
|
|
94
94
|
* A _Promise_ that was rejected
|
|
95
95
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isError, isOk } from "../../internal/result/misc.mjs";
|
|
2
2
|
import { asyncAttempt, attempt } from "../../internal/result/attempt.mjs";
|
|
3
3
|
import { asyncFlow, flow } from "../../internal/function/work.mjs";
|
|
4
|
-
import "../index.mjs";
|
|
5
4
|
//#region src/result/work/flow.ts
|
|
6
5
|
function attemptAsyncFlow(...fns) {
|
|
7
6
|
let Flow;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isError, isOk } from "../../internal/result/misc.mjs";
|
|
2
2
|
import { asyncAttempt, attempt } from "../../internal/result/attempt.mjs";
|
|
3
3
|
import { asyncPipe, pipe } from "../../internal/function/work.mjs";
|
|
4
|
-
import "../index.mjs";
|
|
5
4
|
//#region src/result/work/pipe.ts
|
|
6
5
|
async function attemptAsyncPipe(initial, first, ...seconds) {
|
|
7
6
|
return asyncAttempt(() => {
|
package/dist/value/shake.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { PlainObject } from "../models.mjs";
|
|
1
|
+
import { PlainObject, Simplify } from "../models.mjs";
|
|
2
2
|
//#region src/value/shake.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* A shaken object, without any `undefined` values
|
|
5
5
|
*/
|
|
6
|
-
export type Shaken<Value extends PlainObject> = { [Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key]
|
|
6
|
+
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>; }>;
|
|
7
7
|
/**
|
|
8
8
|
* Shake an object, removing all keys with `undefined` values
|
|
9
9
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/atoms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.213.0",
|
|
4
4
|
"description": "Atomic utilities for making your JavaScript better.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -295,6 +295,7 @@
|
|
|
295
295
|
"default": "./dist/value/transform.mjs"
|
|
296
296
|
}
|
|
297
297
|
},
|
|
298
|
+
"sideEffects": false,
|
|
298
299
|
"scripts": {
|
|
299
300
|
"build": "npx vp pack && npm run tsdown:build",
|
|
300
301
|
"tsdown:build": "npx tsdown -c ./tsdown.config.ts",
|
package/dist/internal/plan.d.mts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { AsyncPlan, Plan } from "./models/plan.model.mjs";
|
|
2
|
-
//#region src/internal/plan.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Create an immediately failing generator
|
|
5
|
-
*
|
|
6
|
-
* @param reason Failure reason
|
|
7
|
-
* @returns Failing generator
|
|
8
|
-
*/
|
|
9
|
-
export declare function fail<Reason>(reason: Reason): Generator<unknown, never>;
|
|
10
|
-
/**
|
|
11
|
-
* Is the value an asynchronous generator function?
|
|
12
|
-
*
|
|
13
|
-
* @param value Value to check
|
|
14
|
-
* @returns `true` if the value is an asynchronous generator function, otherwise `false`
|
|
15
|
-
*/
|
|
16
|
-
export declare function isAsyncGenerator(value: unknown): value is () => AsyncGenerator;
|
|
17
|
-
/**
|
|
18
|
-
* Is the value an asynchronous plan?
|
|
19
|
-
*
|
|
20
|
-
* @param value Value to check
|
|
21
|
-
* @returns `true` if the value is an asynchronous plan, otherwise `false`
|
|
22
|
-
*/
|
|
23
|
-
export declare function isAsyncPlan<Yielded = unknown, Returned = unknown, Parameters extends unknown[] = unknown[]>(value: unknown): value is AsyncPlan<Yielded, Returned, Parameters>;
|
|
24
|
-
/**
|
|
25
|
-
* Is the value a generator function?
|
|
26
|
-
*
|
|
27
|
-
* @param value Value to check
|
|
28
|
-
* @returns `true` if the value is a generator function, otherwise `false`
|
|
29
|
-
*/
|
|
30
|
-
export declare function isGenerator(value: unknown): value is () => Generator;
|
|
31
|
-
/**
|
|
32
|
-
* Is the value a plan?
|
|
33
|
-
*
|
|
34
|
-
* @param value Value to check
|
|
35
|
-
* @returns `true` if the value is a plan, otherwise `false`
|
|
36
|
-
*/
|
|
37
|
-
export declare function isPlan<Yielded = unknown, Returned = unknown, Parameters extends unknown[] = unknown[]>(value: unknown): value is Plan<Yielded, Returned, Parameters>;
|
|
38
|
-
/**
|
|
39
|
-
* Create an immediately succeeding generator
|
|
40
|
-
*
|
|
41
|
-
* @param value Success value
|
|
42
|
-
* @returns Succeeding generator
|
|
43
|
-
*/
|
|
44
|
-
export declare function succeed<Value>(value: Value): Generator<unknown, Value>;
|
|
45
|
-
//#endregion
|