@oscarpalmer/atoms 0.214.0 → 0.216.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/index.d.mts +79 -19
- package/dist/index.mjs +64 -48
- package/dist/models/plan.model.d.mts +37 -5
- package/dist/plan/generate.d.mts +1 -1
- package/dist/plan/generate.mjs +13 -5
- package/dist/plan/misc.d.mts +4 -8
- package/dist/plan/misc.mjs +22 -15
- package/dist/plan/models.d.mts +2 -2
- package/dist/plan/result.d.mts +20 -4
- package/dist/plan/result.mjs +13 -9
- package/dist/plan/run.d.mts +25 -3
- package/dist/plan/run.mjs +5 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4677,14 +4677,14 @@ type AsyncPlan<Yielded, Returned, Parameters extends unknown[]> = {
|
|
|
4677
4677
|
*
|
|
4678
4678
|
* @returns Attempted result
|
|
4679
4679
|
*/
|
|
4680
|
-
attempt(
|
|
4680
|
+
attempt: Parameters extends [infer _, ...(infer _)[]] ? (parameters: Parameters, signal?: AbortSignal) => Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>> : (signal?: AbortSignal) => Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
4681
4681
|
/**
|
|
4682
4682
|
* Run the plan to completion
|
|
4683
4683
|
*
|
|
4684
4684
|
* @throws {PlanError<Yielded, Returned>}
|
|
4685
4685
|
* @returns Result
|
|
4686
4686
|
*/
|
|
4687
|
-
run(
|
|
4687
|
+
run: Parameters extends [infer _, ...(infer _)[]] ? (parameters: Parameters, signal?: AbortSignal) => Promise<PlanReturned<Returned>> : (signal?: AbortSignal) => Promise<PlanReturned<Returned>>;
|
|
4688
4688
|
};
|
|
4689
4689
|
type AsyncPlanState = {
|
|
4690
4690
|
generator(...parameters: unknown[]): AsyncGenerator;
|
|
@@ -4724,16 +4724,42 @@ type Plan<Yielded, Returned, Parameters extends unknown[]> = {
|
|
|
4724
4724
|
*/
|
|
4725
4725
|
run(...parameters: Parameters): PlanReturned<Returned>;
|
|
4726
4726
|
};
|
|
4727
|
+
/**
|
|
4728
|
+
* An immediately failing plan
|
|
4729
|
+
*/
|
|
4730
|
+
type PlanFailure<E> = {
|
|
4731
|
+
/**
|
|
4732
|
+
* Get the generator for the failed plan
|
|
4733
|
+
*
|
|
4734
|
+
* @returns Generator
|
|
4735
|
+
*/
|
|
4736
|
+
[Symbol.iterator]: () => Generator<Err<E>, never>;
|
|
4737
|
+
};
|
|
4727
4738
|
type PlanOk<Returned> = Returned extends Error ? never : Returned extends Err<infer _> ? never : Returned extends Ok<infer Value> ? Value : Returned;
|
|
4728
4739
|
type PlanErrors<Yielded, Returned> = PlanErrorValues<Yielded> | PlanErrorValues<Returned>;
|
|
4729
|
-
type PlanError<Yielded, Returned> = [PlanErrors<Yielded, Returned>] extends [never] ? Error :
|
|
4730
|
-
type PlanErrorValues<Original> = Original extends Error ? Original : Original extends Err<infer
|
|
4740
|
+
type PlanError<Yielded, Returned> = [PlanErrors<Yielded, Returned>] extends [never] ? Error : PlanErrorValues<Yielded> | PlanErrorValues<Returned>;
|
|
4741
|
+
type PlanErrorValues<Original> = Original extends Error ? Original : Original extends Err<infer E> ? E : Original extends PlanFailure<infer E> ? E : never;
|
|
4731
4742
|
type PlanReturned<Returned> = Returned extends Error ? never : Returned extends Err<infer _> ? never : Returned;
|
|
4743
|
+
/**
|
|
4744
|
+
* An immediately successful or failing plan
|
|
4745
|
+
*/
|
|
4746
|
+
type PlanResult<Success, Failure> = PlanSuccess<Success> | PlanFailure<Failure>;
|
|
4732
4747
|
type PlanState = {
|
|
4733
4748
|
generator(...parameters: unknown[]): Generator;
|
|
4734
4749
|
} & BaseState<typeof PLAN_TYPE_PLAN_SYNC>;
|
|
4750
|
+
/**
|
|
4751
|
+
* An immediately successful plan
|
|
4752
|
+
*/
|
|
4753
|
+
type PlanSuccess<Value> = {
|
|
4754
|
+
/**
|
|
4755
|
+
* Get the generator for the successful plan
|
|
4756
|
+
*
|
|
4757
|
+
* @returns Generator
|
|
4758
|
+
*/
|
|
4759
|
+
[Symbol.iterator]: () => Generator<never, Value>;
|
|
4760
|
+
};
|
|
4735
4761
|
type PlanType = "asyncPlan" | "plan";
|
|
4736
|
-
declare const PLAN_SYMBOL: symbol;
|
|
4762
|
+
declare const PLAN_SYMBOL: unique symbol;
|
|
4737
4763
|
declare const PLAN_TYPE_PLAN_ASYNC: PlanType;
|
|
4738
4764
|
declare const PLAN_TYPE_PLAN_SYNC: PlanType;
|
|
4739
4765
|
//#endregion
|
|
@@ -4745,7 +4771,15 @@ declare const PLAN_TYPE_PLAN_SYNC: PlanType;
|
|
|
4745
4771
|
*
|
|
4746
4772
|
* @returns Promised result
|
|
4747
4773
|
*/
|
|
4748
|
-
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>,
|
|
4774
|
+
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>, parameters: Parameters, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
4775
|
+
/**
|
|
4776
|
+
* Attempt to run the generator to completion
|
|
4777
|
+
*
|
|
4778
|
+
* _Returns a promised {@link Result} instead of a raw value or throwing an error_
|
|
4779
|
+
*
|
|
4780
|
+
* @returns Promised result
|
|
4781
|
+
*/
|
|
4782
|
+
export declare function asyncAttemptRun<Yielded, Returned>(generator: () => AsyncGenerator<Yielded, Returned>, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
4749
4783
|
/**
|
|
4750
4784
|
* Attempt to run the plan to completion
|
|
4751
4785
|
*
|
|
@@ -4753,7 +4787,15 @@ export declare function asyncAttemptRun<Yielded, Returned, Parameters extends un
|
|
|
4753
4787
|
*
|
|
4754
4788
|
* @returns Promised result
|
|
4755
4789
|
*/
|
|
4756
|
-
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>,
|
|
4790
|
+
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, parameters: Parameters, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
4791
|
+
/**
|
|
4792
|
+
* Attempt to run the plan to completion
|
|
4793
|
+
*
|
|
4794
|
+
* _Returns a promised {@link Result} instead of a raw value or throwing an error_
|
|
4795
|
+
*
|
|
4796
|
+
* @returns Promised result
|
|
4797
|
+
*/
|
|
4798
|
+
export declare function asyncAttemptRun<Yielded, Returned>(plan: AsyncPlan<Yielded, Returned, []>, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
4757
4799
|
/**
|
|
4758
4800
|
* Attempt to run the generator to completion
|
|
4759
4801
|
*
|
|
@@ -4770,7 +4812,7 @@ export declare function attemptRun<Yielded, Returned, Parameters extends unknown
|
|
|
4770
4812
|
* @returns Result
|
|
4771
4813
|
*/
|
|
4772
4814
|
export declare function attemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): Result<PlanOk<Returned>, PlanError<Yielded, Returned>>;
|
|
4773
|
-
export declare function attemptRunAsyncPlan(this:
|
|
4815
|
+
export declare function attemptRunAsyncPlan(this: never, first: never, second: never): Promise<unknown>;
|
|
4774
4816
|
export declare function attemptRunPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
4775
4817
|
export declare namespace attemptRun {
|
|
4776
4818
|
export var async: typeof asyncAttemptRun;
|
|
@@ -4781,20 +4823,41 @@ export declare namespace attemptRun {
|
|
|
4781
4823
|
* Run an asynchronous generator to completion
|
|
4782
4824
|
*
|
|
4783
4825
|
* @param generator Generator to run
|
|
4826
|
+
* @param parameters Parameters for starting the run
|
|
4827
|
+
* @param signal Optional abort signal
|
|
4784
4828
|
* @returns Result
|
|
4785
4829
|
*/
|
|
4786
|
-
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>,
|
|
4830
|
+
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>, parameters: Parameters, signal?: AbortSignal): Promise<PlanReturned<Returned>>;
|
|
4831
|
+
/**
|
|
4832
|
+
* Run an asynchronous generator to completion
|
|
4833
|
+
*
|
|
4834
|
+
* @param generator Generator to run
|
|
4835
|
+
* @param signal Optional abort signal
|
|
4836
|
+
* @returns Result
|
|
4837
|
+
*/
|
|
4838
|
+
export declare function asyncRun<Yielded, Returned>(generator: () => AsyncGenerator<Yielded, Returned>, signal?: AbortSignal): Promise<PlanReturned<Returned>>;
|
|
4839
|
+
/**
|
|
4840
|
+
* Run an asynchronous plan to completion
|
|
4841
|
+
*
|
|
4842
|
+
* @param plan Plan to run
|
|
4843
|
+
* @param parameters Parameters for starting the run
|
|
4844
|
+
* @param signal Optional abort signal
|
|
4845
|
+
* @returns Result
|
|
4846
|
+
*/
|
|
4847
|
+
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, parameters: Parameters, signal?: AbortSignal): Promise<PlanReturned<Returned>>;
|
|
4787
4848
|
/**
|
|
4788
4849
|
* Run an asynchronous plan to completion
|
|
4789
4850
|
*
|
|
4790
4851
|
* @param plan Plan to run
|
|
4852
|
+
* @param signal Optional abort signal
|
|
4791
4853
|
* @returns Result
|
|
4792
4854
|
*/
|
|
4793
|
-
export declare function asyncRun<Yielded, Returned
|
|
4855
|
+
export declare function asyncRun<Yielded, Returned>(plan: AsyncPlan<Yielded, Returned, []>, signal?: AbortSignal): Promise<PlanReturned<Returned>>;
|
|
4794
4856
|
/**
|
|
4795
4857
|
* Run a generator to completion
|
|
4796
4858
|
*
|
|
4797
4859
|
* @param generator Generator to run
|
|
4860
|
+
* @param parameters Parameters for starting the run
|
|
4798
4861
|
* @returns Result
|
|
4799
4862
|
*/
|
|
4800
4863
|
export declare function run<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned>, ...parameters: Parameters): PlanReturned<Returned>;
|
|
@@ -4802,10 +4865,11 @@ export declare function run<Yielded, Returned, Parameters extends unknown[]>(gen
|
|
|
4802
4865
|
* Run a plan to completion
|
|
4803
4866
|
*
|
|
4804
4867
|
* @param plan Plan to run
|
|
4868
|
+
* @param parameters Parameters for starting the run
|
|
4805
4869
|
* @returns Result
|
|
4806
4870
|
*/
|
|
4807
4871
|
export declare function run<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): PlanReturned<Returned>;
|
|
4808
|
-
export declare function runAsyncPlan(this: InternalAsyncPlan,
|
|
4872
|
+
export declare function runAsyncPlan(this: InternalAsyncPlan, first: never, second: never): Promise<unknown>;
|
|
4809
4873
|
export declare function runPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
4810
4874
|
export declare namespace asyncRun {
|
|
4811
4875
|
export var attempt: typeof asyncAttemptRun;
|
|
@@ -4865,21 +4929,17 @@ export declare function isPlan<Yielded = unknown, Returned = unknown, Parameters
|
|
|
4865
4929
|
/**
|
|
4866
4930
|
* Create an immediately failing plan
|
|
4867
4931
|
*
|
|
4868
|
-
* @param
|
|
4932
|
+
* @param value Failure value
|
|
4869
4933
|
* @returns Plan failure
|
|
4870
4934
|
*/
|
|
4871
|
-
export declare function fail<
|
|
4935
|
+
export declare function fail<Value>(value: Value): PlanFailure<Value>;
|
|
4872
4936
|
/**
|
|
4873
4937
|
* Create an immediately succeeding plan
|
|
4874
4938
|
*
|
|
4875
4939
|
* @param value Success value
|
|
4876
4940
|
* @returns Plan success
|
|
4877
4941
|
*/
|
|
4878
|
-
export declare function succeed<Value>(value: Value):
|
|
4879
|
-
export declare function succeedResult<Returned>(value: Returned): Generator<never, Ok<Returned>>;
|
|
4880
|
-
export declare namespace succeed {
|
|
4881
|
-
export var result: typeof succeedResult;
|
|
4882
|
-
}
|
|
4942
|
+
export declare function succeed<Value>(value: Value): PlanSuccess<Value>;
|
|
4883
4943
|
//#endregion
|
|
4884
4944
|
//#region src/models/aborter.model.d.ts
|
|
4885
4945
|
type Aborter = {
|
|
@@ -8625,4 +8685,4 @@ export declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
8625
8685
|
get(value: Value, update?: boolean): Value | undefined;
|
|
8626
8686
|
}
|
|
8627
8687
|
//#endregion
|
|
8628
|
-
export { type ArrayComparisonSorter, type ArrayKeySorter, type ArrayKeySorters, type ArraySorter, type ArraySorters, type ArrayValueSorter, type Asserter, type AssignOptions, type Assigner, type AsyncFlow, type AsyncLimiter, type AsyncOnce, type AsyncPlan, type Beacon, type BeaconOptions, type CloneOptions, type Cloner, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type CompareCallback, type ComparisonSorter, type DiffOptions, type DiffResult, type EqualOptions, type Equalizer, type Flow, type FulfilledPromise, type Fuzzy, type FuzzyItem, type FuzzyOptions, type FuzzyResult, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, type Herald, type HeraldEvents, type HeraldOptions, Key$1 as Key, type KeyedQueue, type Limiter, Logger, type Memoized, type MemoizedOptions, type MergeOptions, type Merger, type NormalizeOptions, type Normalizer, type Observable, type Observer, type Once, type Plan, type PromiseOptions, type PromiseStrategy, type PromisesOptions, type Queue, type QueueOptions, type Queued, type RGBAColor, type RGBColor, type RejectedPromise, type Renderer, type Shaken, type Smushed, type SortDirection, type Sorter, type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, type TemplateOptions, type Templater, type TemplaterOptions, type TemplaterRenderer, type TimeLogger, type TransformCallback, type TransformCallbacks, type Transformer, type Unsmushed, push as append, filterAndMap as select, toPromise as fromResult, getRandomFloatingNumber as getRandomFloat, isLogger, isTimeLogger, mapAndFilter as reverseSelect };
|
|
8688
|
+
export { type ArrayComparisonSorter, type ArrayKeySorter, type ArrayKeySorters, type ArraySorter, type ArraySorters, type ArrayValueSorter, type Asserter, type AssignOptions, type Assigner, type AsyncFlow, type AsyncLimiter, type AsyncOnce, type AsyncPlan, type Beacon, type BeaconOptions, type CloneOptions, type Cloner, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type CompareCallback, type ComparisonSorter, type DiffOptions, type DiffResult, type EqualOptions, type Equalizer, type Flow, type FulfilledPromise, type Fuzzy, type FuzzyItem, type FuzzyOptions, type FuzzyResult, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, type Herald, type HeraldEvents, type HeraldOptions, Key$1 as Key, type KeyedQueue, type Limiter, Logger, type Memoized, type MemoizedOptions, type MergeOptions, type Merger, type NormalizeOptions, type Normalizer, type Observable, type Observer, type Once, type Plan, type PlanFailure, type PlanResult, type PlanSuccess, type PromiseOptions, type PromiseStrategy, type PromisesOptions, type Queue, type QueueOptions, type Queued, type RGBAColor, type RGBColor, type RejectedPromise, type Renderer, type Shaken, type Smushed, type SortDirection, type Sorter, type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, type TemplateOptions, type Templater, type TemplaterOptions, type TemplaterRenderer, type TimeLogger, type TransformCallback, type TransformCallbacks, type Transformer, type Unsmushed, push as append, filterAndMap as select, toPromise as fromResult, getRandomFloatingNumber as getRandomFloat, isLogger, isTimeLogger, mapAndFilter as reverseSelect };
|
package/dist/index.mjs
CHANGED
|
@@ -2820,8 +2820,26 @@ function isPlanInstance(type, value) {
|
|
|
2820
2820
|
return typeof value === "object" && value !== null && PLAN_SYMBOL in value && value[PLAN_SYMBOL].type === type;
|
|
2821
2821
|
}
|
|
2822
2822
|
//#endregion
|
|
2823
|
+
//#region src/models/aborter.model.ts
|
|
2824
|
+
const ABORTER_EVENT = "abort";
|
|
2825
|
+
const ABORTER_OPTIONS = { once: true };
|
|
2826
|
+
//#endregion
|
|
2827
|
+
//#region src/internal/aborter.ts
|
|
2828
|
+
function createAborter(value, onAbort) {
|
|
2829
|
+
if (!(value instanceof AbortSignal)) return;
|
|
2830
|
+
value.addEventListener(ABORTER_EVENT, onAbort, ABORTER_OPTIONS);
|
|
2831
|
+
return {
|
|
2832
|
+
callback: onAbort,
|
|
2833
|
+
signal: value,
|
|
2834
|
+
cancel: () => value.removeEventListener(ABORTER_EVENT, onAbort)
|
|
2835
|
+
};
|
|
2836
|
+
}
|
|
2837
|
+
//#endregion
|
|
2823
2838
|
//#region src/plan/generate.ts
|
|
2824
|
-
async function asyncGenerate(input,
|
|
2839
|
+
async function asyncGenerate(input, unwrap, first, second) {
|
|
2840
|
+
const aborter = createAborter(second ?? first, noop);
|
|
2841
|
+
if (aborter != null && aborter.signal.aborted) throw aborter.signal.reason;
|
|
2842
|
+
const parameters = Array.isArray(first) ? first : [];
|
|
2825
2843
|
let generator;
|
|
2826
2844
|
if (typeof input === "function") generator = input(...parameters);
|
|
2827
2845
|
else generator = input.generator(...parameters);
|
|
@@ -2829,11 +2847,12 @@ async function asyncGenerate(input, parameters, unwrap) {
|
|
|
2829
2847
|
let lastValue;
|
|
2830
2848
|
try {
|
|
2831
2849
|
while (true) {
|
|
2850
|
+
if (aborter != null && aborter.signal.aborted) await generator.throw(aborter.signal.reason);
|
|
2832
2851
|
const next = await generator.next(lastValue);
|
|
2833
2852
|
const done = next.done === true;
|
|
2834
2853
|
const { value } = next;
|
|
2835
|
-
if (value instanceof Error) throw
|
|
2836
|
-
if (isError(value)) throw
|
|
2854
|
+
if (value instanceof Error) await generator.throw(value);
|
|
2855
|
+
if (isError(value)) await generator.throw(value.error);
|
|
2837
2856
|
lastValue = value;
|
|
2838
2857
|
if (done === true) break;
|
|
2839
2858
|
}
|
|
@@ -2841,8 +2860,10 @@ async function asyncGenerate(input, parameters, unwrap) {
|
|
|
2841
2860
|
lastValue = error;
|
|
2842
2861
|
success = false;
|
|
2843
2862
|
} finally {
|
|
2863
|
+
aborter?.cancel();
|
|
2844
2864
|
await generator.return(lastValue);
|
|
2845
2865
|
}
|
|
2866
|
+
if (aborter != null && aborter.signal.aborted) throw aborter.signal.reason;
|
|
2846
2867
|
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
2847
2868
|
throw lastValue;
|
|
2848
2869
|
}
|
|
@@ -2857,8 +2878,8 @@ function generate(input, parameters, unwrap) {
|
|
|
2857
2878
|
const next = generator.next(lastValue);
|
|
2858
2879
|
const done = next.done === true;
|
|
2859
2880
|
const { value } = next;
|
|
2860
|
-
if (value instanceof Error) throw
|
|
2861
|
-
if (isError(value)) throw
|
|
2881
|
+
if (value instanceof Error) generator.throw(value);
|
|
2882
|
+
if (isError(value)) generator.throw(value.error);
|
|
2862
2883
|
lastValue = value;
|
|
2863
2884
|
if (done) break;
|
|
2864
2885
|
}
|
|
@@ -2873,18 +2894,22 @@ function generate(input, parameters, unwrap) {
|
|
|
2873
2894
|
}
|
|
2874
2895
|
//#endregion
|
|
2875
2896
|
//#region src/plan/result.ts
|
|
2876
|
-
function asyncAttemptRun(input,
|
|
2877
|
-
|
|
2878
|
-
if (
|
|
2879
|
-
|
|
2897
|
+
function asyncAttemptRun(input, first, second) {
|
|
2898
|
+
let generator;
|
|
2899
|
+
if (isAsyncPlan(input)) generator = input[PLAN_SYMBOL];
|
|
2900
|
+
else if (isAsyncGenerator(input)) generator = input;
|
|
2901
|
+
if (generator == null) throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2902
|
+
return asyncAttempt(() => asyncGenerate(generator, true, first, second));
|
|
2880
2903
|
}
|
|
2881
2904
|
function attemptRun(input, ...parameters) {
|
|
2882
|
-
|
|
2883
|
-
if (
|
|
2884
|
-
|
|
2905
|
+
let generator;
|
|
2906
|
+
if (isPlan(input)) generator = input[PLAN_SYMBOL];
|
|
2907
|
+
else if (isGenerator(input)) generator = input;
|
|
2908
|
+
if (generator == null) throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2909
|
+
return attempt(() => generate(generator, parameters, true));
|
|
2885
2910
|
}
|
|
2886
|
-
function attemptRunAsyncPlan(
|
|
2887
|
-
return
|
|
2911
|
+
function attemptRunAsyncPlan(first, second) {
|
|
2912
|
+
return asyncAttemptRun(this, first, second);
|
|
2888
2913
|
}
|
|
2889
2914
|
function attemptRunPlan(...parameters) {
|
|
2890
2915
|
return attempt(() => generate(this[PLAN_SYMBOL], parameters, true));
|
|
@@ -2892,9 +2917,9 @@ function attemptRunPlan(...parameters) {
|
|
|
2892
2917
|
attemptRun.async = asyncAttemptRun;
|
|
2893
2918
|
//#endregion
|
|
2894
2919
|
//#region src/plan/run.ts
|
|
2895
|
-
function asyncRun(input,
|
|
2896
|
-
if (isAsyncPlan(input)) return input
|
|
2897
|
-
if (isAsyncGenerator(input)) return asyncGenerate(input,
|
|
2920
|
+
function asyncRun(input, first, second) {
|
|
2921
|
+
if (isAsyncPlan(input)) return asyncGenerate(input[PLAN_SYMBOL], false, first, second);
|
|
2922
|
+
if (isAsyncGenerator(input)) return asyncGenerate(input, false, first, second);
|
|
2898
2923
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2899
2924
|
}
|
|
2900
2925
|
function run(input, ...parameters) {
|
|
@@ -2902,8 +2927,8 @@ function run(input, ...parameters) {
|
|
|
2902
2927
|
if (isGenerator(input)) return generate(input, parameters, false);
|
|
2903
2928
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2904
2929
|
}
|
|
2905
|
-
function runAsyncPlan(
|
|
2906
|
-
return asyncGenerate(this[PLAN_SYMBOL],
|
|
2930
|
+
function runAsyncPlan(first, second) {
|
|
2931
|
+
return asyncGenerate(this[PLAN_SYMBOL], false, first, second);
|
|
2907
2932
|
}
|
|
2908
2933
|
function runPlan(...parameters) {
|
|
2909
2934
|
return generate(this[PLAN_SYMBOL], parameters, false);
|
|
@@ -2942,16 +2967,28 @@ function plan(generator) {
|
|
|
2942
2967
|
}
|
|
2943
2968
|
//#endregion
|
|
2944
2969
|
//#region src/plan/misc.ts
|
|
2970
|
+
function PlanFailure(generator) {
|
|
2971
|
+
this[PLAN_SYMBOL] = { generator };
|
|
2972
|
+
}
|
|
2973
|
+
PlanFailure.prototype[Symbol.iterator] = function() {
|
|
2974
|
+
return this[PLAN_SYMBOL].generator();
|
|
2975
|
+
};
|
|
2976
|
+
function PlanSuccess(generator) {
|
|
2977
|
+
this[PLAN_SYMBOL] = { generator };
|
|
2978
|
+
}
|
|
2979
|
+
PlanSuccess.prototype[Symbol.iterator] = function() {
|
|
2980
|
+
return this[PLAN_SYMBOL].generator();
|
|
2981
|
+
};
|
|
2945
2982
|
/**
|
|
2946
2983
|
* Create an immediately failing plan
|
|
2947
2984
|
*
|
|
2948
|
-
* @param
|
|
2985
|
+
* @param value Failure value
|
|
2949
2986
|
* @returns Plan failure
|
|
2950
2987
|
*/
|
|
2951
|
-
function fail(
|
|
2952
|
-
return (function* () {
|
|
2953
|
-
|
|
2954
|
-
})
|
|
2988
|
+
function fail(value) {
|
|
2989
|
+
return new PlanFailure(function* () {
|
|
2990
|
+
yield error(value);
|
|
2991
|
+
});
|
|
2955
2992
|
}
|
|
2956
2993
|
/**
|
|
2957
2994
|
* Create an immediately succeeding plan
|
|
@@ -2960,30 +2997,9 @@ function fail(reason) {
|
|
|
2960
2997
|
* @returns Plan success
|
|
2961
2998
|
*/
|
|
2962
2999
|
function succeed(value) {
|
|
2963
|
-
return (function* () {
|
|
3000
|
+
return new PlanSuccess(function* () {
|
|
2964
3001
|
return value;
|
|
2965
|
-
})
|
|
2966
|
-
}
|
|
2967
|
-
function succeedResult(value) {
|
|
2968
|
-
return (function* () {
|
|
2969
|
-
return ok(value);
|
|
2970
|
-
})();
|
|
2971
|
-
}
|
|
2972
|
-
succeed.result = succeedResult;
|
|
2973
|
-
//#endregion
|
|
2974
|
-
//#region src/models/aborter.model.ts
|
|
2975
|
-
const ABORTER_EVENT = "abort";
|
|
2976
|
-
const ABORTER_OPTIONS = { once: true };
|
|
2977
|
-
//#endregion
|
|
2978
|
-
//#region src/internal/aborter.ts
|
|
2979
|
-
function createAborter(value, onAbort) {
|
|
2980
|
-
if (!(value instanceof AbortSignal)) return;
|
|
2981
|
-
value.addEventListener(ABORTER_EVENT, onAbort, ABORTER_OPTIONS);
|
|
2982
|
-
return {
|
|
2983
|
-
callback: onAbort,
|
|
2984
|
-
signal: value,
|
|
2985
|
-
cancel: () => value.removeEventListener(ABORTER_EVENT, onAbort)
|
|
2986
|
-
};
|
|
3002
|
+
});
|
|
2987
3003
|
}
|
|
2988
3004
|
//#endregion
|
|
2989
3005
|
//#region src/models/promise.model.ts
|
|
@@ -7095,4 +7111,4 @@ var SizedSet = class extends Set {
|
|
|
7095
7111
|
}
|
|
7096
7112
|
};
|
|
7097
7113
|
//#endregion
|
|
7098
|
-
export { CancelablePromise, Logger, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, push as append, push, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncAttemptRun, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncRun, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, attemptRun, attemptRunAsyncPlan, attemptRunPlan, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, fail, filter, filterAndMap, filterAndMap as select, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isAsyncGenerator, isAsyncOnce, isAsyncPlan, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isFuzzy, isGenerator, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isOnce, isPlainObject, isPlan, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isSubscriptions, isTemplateStringsArray, isTimeLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, mapAndFilter, mapAndFilter as reverseSelect, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, plan, promises, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, run, runAsyncPlan, runPlan, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, succeed,
|
|
7114
|
+
export { CancelablePromise, Logger, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, push as append, push, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncAttemptRun, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncRun, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, attemptRun, attemptRunAsyncPlan, attemptRunPlan, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, fail, filter, filterAndMap, filterAndMap as select, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isAsyncGenerator, isAsyncOnce, isAsyncPlan, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isFuzzy, isGenerator, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isOnce, isPlainObject, isPlan, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isSubscriptions, isTemplateStringsArray, isTimeLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, mapAndFilter, mapAndFilter as reverseSelect, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, plan, promises, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, run, runAsyncPlan, runPlan, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, succeed, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
@@ -17,14 +17,14 @@ export type AsyncPlan<Yielded, Returned, Parameters extends unknown[]> = {
|
|
|
17
17
|
*
|
|
18
18
|
* @returns Attempted result
|
|
19
19
|
*/
|
|
20
|
-
attempt(
|
|
20
|
+
attempt: Parameters extends [infer _, ...(infer _)[]] ? (parameters: Parameters, signal?: AbortSignal) => Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>> : (signal?: AbortSignal) => 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(
|
|
27
|
+
run: Parameters extends [infer _, ...(infer _)[]] ? (parameters: Parameters, signal?: AbortSignal) => Promise<PlanReturned<Returned>> : (signal?: AbortSignal) => Promise<PlanReturned<Returned>>;
|
|
28
28
|
};
|
|
29
29
|
export type AsyncPlanState = {
|
|
30
30
|
generator(...parameters: unknown[]): AsyncGenerator;
|
|
@@ -38,6 +38,9 @@ export type InternalAsyncPlan = {
|
|
|
38
38
|
export type InternalPlan = {
|
|
39
39
|
[PLAN_SYMBOL]: PlanState;
|
|
40
40
|
} & Plan<never, never, unknown[]>;
|
|
41
|
+
export type InternalPlanHelper = {
|
|
42
|
+
[PLAN_SYMBOL]: PlanHelperState;
|
|
43
|
+
};
|
|
41
44
|
/**
|
|
42
45
|
* A plan of execution that can yield intermediate results and eventually return a result
|
|
43
46
|
*/
|
|
@@ -64,20 +67,49 @@ export type Plan<Yielded, Returned, Parameters extends unknown[]> = {
|
|
|
64
67
|
*/
|
|
65
68
|
run(...parameters: Parameters): PlanReturned<Returned>;
|
|
66
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* An immediately failing plan
|
|
72
|
+
*/
|
|
73
|
+
export type PlanFailure<E> = {
|
|
74
|
+
/**
|
|
75
|
+
* Get the generator for the failed plan
|
|
76
|
+
*
|
|
77
|
+
* @returns Generator
|
|
78
|
+
*/
|
|
79
|
+
[Symbol.iterator]: () => Generator<Err<E>, never>;
|
|
80
|
+
};
|
|
67
81
|
export type PlanOk<Returned> = Returned extends Error ? never : Returned extends Err<infer _> ? never : Returned extends Ok<infer Value> ? Value : Returned;
|
|
68
82
|
type PlanErrors<Yielded, Returned> = PlanErrorValues<Yielded> | PlanErrorValues<Returned>;
|
|
69
|
-
export type PlanError<Yielded, Returned> = [PlanErrors<Yielded, Returned>] extends [never] ? Error :
|
|
70
|
-
type PlanErrorValues<Original> = Original extends Error ? Original : Original extends Err<infer
|
|
83
|
+
export type PlanError<Yielded, Returned> = [PlanErrors<Yielded, Returned>] extends [never] ? Error : PlanErrorValues<Yielded> | PlanErrorValues<Returned>;
|
|
84
|
+
type PlanErrorValues<Original> = Original extends Error ? Original : Original extends Err<infer E> ? E : Original extends PlanFailure<infer E> ? E : never;
|
|
85
|
+
type PlanHelperState = {
|
|
86
|
+
generator: () => Generator;
|
|
87
|
+
};
|
|
71
88
|
export type PlanReturned<Returned> = Returned extends Error ? never : Returned extends Err<infer _> ? never : Returned;
|
|
89
|
+
/**
|
|
90
|
+
* An immediately successful or failing plan
|
|
91
|
+
*/
|
|
92
|
+
export type PlanResult<Success, Failure> = PlanSuccess<Success> | PlanFailure<Failure>;
|
|
72
93
|
export type PlanState = {
|
|
73
94
|
generator(...parameters: unknown[]): Generator;
|
|
74
95
|
} & BaseState<typeof PLAN_TYPE_PLAN_SYNC>;
|
|
96
|
+
/**
|
|
97
|
+
* An immediately successful plan
|
|
98
|
+
*/
|
|
99
|
+
export type PlanSuccess<Value> = {
|
|
100
|
+
/**
|
|
101
|
+
* Get the generator for the successful plan
|
|
102
|
+
*
|
|
103
|
+
* @returns Generator
|
|
104
|
+
*/
|
|
105
|
+
[Symbol.iterator]: () => Generator<never, Value>;
|
|
106
|
+
};
|
|
75
107
|
export type PlanType = "asyncPlan" | "plan";
|
|
76
108
|
export declare const GENERATOR_NAME_ASYNC = "AsyncGeneratorFunction";
|
|
77
109
|
export declare const GENERATOR_NAME_SYNC = "GeneratorFunction";
|
|
78
110
|
export declare const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
|
|
79
111
|
export declare const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
|
|
80
|
-
export declare const PLAN_SYMBOL: symbol;
|
|
112
|
+
export declare const PLAN_SYMBOL: unique symbol;
|
|
81
113
|
export declare const PLAN_TYPE_PLAN_ASYNC: PlanType;
|
|
82
114
|
export declare const PLAN_TYPE_PLAN_SYNC: PlanType;
|
|
83
115
|
//#endregion
|
package/dist/plan/generate.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncPlanState, PlanState } from "../models/plan.model.mjs";
|
|
2
2
|
//#region src/plan/generate.d.ts
|
|
3
|
-
export declare function asyncGenerate(input: AsyncPlanState | ((...
|
|
3
|
+
export declare function asyncGenerate(input: AsyncPlanState | ((...args: unknown[]) => AsyncGenerator), unwrap: boolean, first?: unknown, second?: unknown): Promise<unknown>;
|
|
4
4
|
export declare function generate(input: PlanState | ((...parameters: unknown[]) => Generator), parameters: unknown[], unwrap: boolean): unknown;
|
|
5
5
|
//#endregion
|
package/dist/plan/generate.mjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { noop } from "../internal/function/misc.mjs";
|
|
2
|
+
import { createAborter } from "../internal/aborter.mjs";
|
|
1
3
|
import { isError, isOk } from "../internal/result/misc.mjs";
|
|
2
4
|
//#region src/plan/generate.ts
|
|
3
|
-
async function asyncGenerate(input,
|
|
5
|
+
async function asyncGenerate(input, unwrap, first, second) {
|
|
6
|
+
const aborter = createAborter(second ?? first, noop);
|
|
7
|
+
if (aborter != null && aborter.signal.aborted) throw aborter.signal.reason;
|
|
8
|
+
const parameters = Array.isArray(first) ? first : [];
|
|
4
9
|
let generator;
|
|
5
10
|
if (typeof input === "function") generator = input(...parameters);
|
|
6
11
|
else generator = input.generator(...parameters);
|
|
@@ -8,11 +13,12 @@ async function asyncGenerate(input, parameters, unwrap) {
|
|
|
8
13
|
let lastValue;
|
|
9
14
|
try {
|
|
10
15
|
while (true) {
|
|
16
|
+
if (aborter != null && aborter.signal.aborted) await generator.throw(aborter.signal.reason);
|
|
11
17
|
const next = await generator.next(lastValue);
|
|
12
18
|
const done = next.done === true;
|
|
13
19
|
const { value } = next;
|
|
14
|
-
if (value instanceof Error) throw
|
|
15
|
-
if (isError(value)) throw
|
|
20
|
+
if (value instanceof Error) await generator.throw(value);
|
|
21
|
+
if (isError(value)) await generator.throw(value.error);
|
|
16
22
|
lastValue = value;
|
|
17
23
|
if (done === true) break;
|
|
18
24
|
}
|
|
@@ -20,8 +26,10 @@ async function asyncGenerate(input, parameters, unwrap) {
|
|
|
20
26
|
lastValue = error;
|
|
21
27
|
success = false;
|
|
22
28
|
} finally {
|
|
29
|
+
aborter?.cancel();
|
|
23
30
|
await generator.return(lastValue);
|
|
24
31
|
}
|
|
32
|
+
if (aborter != null && aborter.signal.aborted) throw aborter.signal.reason;
|
|
25
33
|
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
26
34
|
throw lastValue;
|
|
27
35
|
}
|
|
@@ -36,8 +44,8 @@ function generate(input, parameters, unwrap) {
|
|
|
36
44
|
const next = generator.next(lastValue);
|
|
37
45
|
const done = next.done === true;
|
|
38
46
|
const { value } = next;
|
|
39
|
-
if (value instanceof Error) throw
|
|
40
|
-
if (isError(value)) throw
|
|
47
|
+
if (value instanceof Error) generator.throw(value);
|
|
48
|
+
if (isError(value)) generator.throw(value.error);
|
|
41
49
|
lastValue = value;
|
|
42
50
|
if (done) break;
|
|
43
51
|
}
|
package/dist/plan/misc.d.mts
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PlanFailure, PlanSuccess } from "../models/plan.model.mjs";
|
|
2
2
|
//#region src/plan/misc.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Create an immediately failing plan
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param value Failure value
|
|
7
7
|
* @returns Plan failure
|
|
8
8
|
*/
|
|
9
|
-
export declare function fail<
|
|
9
|
+
export declare function fail<Value>(value: Value): PlanFailure<Value>;
|
|
10
10
|
/**
|
|
11
11
|
* Create an immediately succeeding plan
|
|
12
12
|
*
|
|
13
13
|
* @param value Success value
|
|
14
14
|
* @returns Plan success
|
|
15
15
|
*/
|
|
16
|
-
export declare function succeed<Value>(value: 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
|
-
}
|
|
16
|
+
export declare function succeed<Value>(value: Value): PlanSuccess<Value>;
|
|
21
17
|
//#endregion
|
package/dist/plan/misc.mjs
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { error } from "../internal/result/misc.mjs";
|
|
2
|
+
import { PLAN_SYMBOL } from "../models/plan.model.mjs";
|
|
2
3
|
//#region src/plan/misc.ts
|
|
4
|
+
function PlanFailure(generator) {
|
|
5
|
+
this[PLAN_SYMBOL] = { generator };
|
|
6
|
+
}
|
|
7
|
+
PlanFailure.prototype[Symbol.iterator] = function() {
|
|
8
|
+
return this[PLAN_SYMBOL].generator();
|
|
9
|
+
};
|
|
10
|
+
function PlanSuccess(generator) {
|
|
11
|
+
this[PLAN_SYMBOL] = { generator };
|
|
12
|
+
}
|
|
13
|
+
PlanSuccess.prototype[Symbol.iterator] = function() {
|
|
14
|
+
return this[PLAN_SYMBOL].generator();
|
|
15
|
+
};
|
|
3
16
|
/**
|
|
4
17
|
* Create an immediately failing plan
|
|
5
18
|
*
|
|
6
|
-
* @param
|
|
19
|
+
* @param value Failure value
|
|
7
20
|
* @returns Plan failure
|
|
8
21
|
*/
|
|
9
|
-
function fail(
|
|
10
|
-
return (function* () {
|
|
11
|
-
|
|
12
|
-
})
|
|
22
|
+
function fail(value) {
|
|
23
|
+
return new PlanFailure(function* () {
|
|
24
|
+
yield error(value);
|
|
25
|
+
});
|
|
13
26
|
}
|
|
14
27
|
/**
|
|
15
28
|
* Create an immediately succeeding plan
|
|
@@ -18,15 +31,9 @@ function fail(reason) {
|
|
|
18
31
|
* @returns Plan success
|
|
19
32
|
*/
|
|
20
33
|
function succeed(value) {
|
|
21
|
-
return (function* () {
|
|
34
|
+
return new PlanSuccess(function* () {
|
|
22
35
|
return value;
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
function succeedResult(value) {
|
|
26
|
-
return (function* () {
|
|
27
|
-
return ok(value);
|
|
28
|
-
})();
|
|
36
|
+
});
|
|
29
37
|
}
|
|
30
|
-
succeed.result = succeedResult;
|
|
31
38
|
//#endregion
|
|
32
|
-
export { fail, succeed
|
|
39
|
+
export { fail, succeed };
|
package/dist/plan/models.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AsyncPlan, Plan } from "../models/plan.model.mjs";
|
|
2
|
-
export type { AsyncPlan, Plan };
|
|
1
|
+
import { AsyncPlan, Plan, PlanFailure, PlanResult, PlanSuccess } from "../models/plan.model.mjs";
|
|
2
|
+
export type { AsyncPlan, Plan, PlanFailure, PlanResult, PlanSuccess };
|
package/dist/plan/result.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Result } from "../models/result.model.mjs";
|
|
2
|
-
import { AsyncPlan,
|
|
2
|
+
import { AsyncPlan, 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,23 @@ import { AsyncPlan, InternalAsyncPlan, InternalPlan, Plan, PlanError, PlanOk } f
|
|
|
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, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
12
|
+
/**
|
|
13
|
+
* Attempt to run the generator to completion
|
|
14
|
+
*
|
|
15
|
+
* _Returns a promised {@link Result} instead of a raw value or throwing an error_
|
|
16
|
+
*
|
|
17
|
+
* @returns Promised result
|
|
18
|
+
*/
|
|
19
|
+
export declare function asyncAttemptRun<Yielded, Returned>(generator: () => AsyncGenerator<Yielded, Returned>, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
20
|
+
/**
|
|
21
|
+
* Attempt to run the plan to completion
|
|
22
|
+
*
|
|
23
|
+
* _Returns a promised {@link Result} instead of a raw value or throwing an error_
|
|
24
|
+
*
|
|
25
|
+
* @returns Promised result
|
|
26
|
+
*/
|
|
27
|
+
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, parameters: Parameters, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
12
28
|
/**
|
|
13
29
|
* Attempt to run the plan to completion
|
|
14
30
|
*
|
|
@@ -16,7 +32,7 @@ export declare function asyncAttemptRun<Yielded, Returned, Parameters extends un
|
|
|
16
32
|
*
|
|
17
33
|
* @returns Promised result
|
|
18
34
|
*/
|
|
19
|
-
export declare function asyncAttemptRun<Yielded, Returned
|
|
35
|
+
export declare function asyncAttemptRun<Yielded, Returned>(plan: AsyncPlan<Yielded, Returned, []>, signal?: AbortSignal): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
20
36
|
/**
|
|
21
37
|
* Attempt to run the generator to completion
|
|
22
38
|
*
|
|
@@ -33,7 +49,7 @@ export declare function attemptRun<Yielded, Returned, Parameters extends unknown
|
|
|
33
49
|
* @returns Result
|
|
34
50
|
*/
|
|
35
51
|
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:
|
|
52
|
+
export declare function attemptRunAsyncPlan(this: never, first: never, second: never): Promise<unknown>;
|
|
37
53
|
export declare function attemptRunPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
38
54
|
export declare namespace attemptRun {
|
|
39
55
|
export var async: typeof asyncAttemptRun;
|
package/dist/plan/result.mjs
CHANGED
|
@@ -3,18 +3,22 @@ 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
|
|
6
|
-
function asyncAttemptRun(input,
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
6
|
+
function asyncAttemptRun(input, first, second) {
|
|
7
|
+
let generator;
|
|
8
|
+
if (isAsyncPlan(input)) generator = input[PLAN_SYMBOL];
|
|
9
|
+
else if (isAsyncGenerator(input)) generator = input;
|
|
10
|
+
if (generator == null) throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
11
|
+
return asyncAttempt(() => asyncGenerate(generator, true, first, second));
|
|
10
12
|
}
|
|
11
13
|
function attemptRun(input, ...parameters) {
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
14
|
+
let generator;
|
|
15
|
+
if (isPlan(input)) generator = input[PLAN_SYMBOL];
|
|
16
|
+
else if (isGenerator(input)) generator = input;
|
|
17
|
+
if (generator == null) throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
18
|
+
return attempt(() => generate(generator, parameters, true));
|
|
15
19
|
}
|
|
16
|
-
function attemptRunAsyncPlan(
|
|
17
|
-
return
|
|
20
|
+
function attemptRunAsyncPlan(first, second) {
|
|
21
|
+
return asyncAttemptRun(this, first, second);
|
|
18
22
|
}
|
|
19
23
|
function attemptRunPlan(...parameters) {
|
|
20
24
|
return attempt(() => generate(this[PLAN_SYMBOL], parameters, true));
|
package/dist/plan/run.d.mts
CHANGED
|
@@ -5,20 +5,41 @@ import { asyncAttemptRun, attemptRun } from "./result.mjs";
|
|
|
5
5
|
* Run an asynchronous generator to completion
|
|
6
6
|
*
|
|
7
7
|
* @param generator Generator to run
|
|
8
|
+
* @param parameters Parameters for starting the run
|
|
9
|
+
* @param signal Optional abort signal
|
|
8
10
|
* @returns Result
|
|
9
11
|
*/
|
|
10
|
-
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>,
|
|
12
|
+
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>, parameters: Parameters, signal?: AbortSignal): Promise<PlanReturned<Returned>>;
|
|
13
|
+
/**
|
|
14
|
+
* Run an asynchronous generator to completion
|
|
15
|
+
*
|
|
16
|
+
* @param generator Generator to run
|
|
17
|
+
* @param signal Optional abort signal
|
|
18
|
+
* @returns Result
|
|
19
|
+
*/
|
|
20
|
+
export declare function asyncRun<Yielded, Returned>(generator: () => AsyncGenerator<Yielded, Returned>, signal?: AbortSignal): Promise<PlanReturned<Returned>>;
|
|
21
|
+
/**
|
|
22
|
+
* Run an asynchronous plan to completion
|
|
23
|
+
*
|
|
24
|
+
* @param plan Plan to run
|
|
25
|
+
* @param parameters Parameters for starting the run
|
|
26
|
+
* @param signal Optional abort signal
|
|
27
|
+
* @returns Result
|
|
28
|
+
*/
|
|
29
|
+
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, parameters: Parameters, signal?: AbortSignal): Promise<PlanReturned<Returned>>;
|
|
11
30
|
/**
|
|
12
31
|
* Run an asynchronous plan to completion
|
|
13
32
|
*
|
|
14
33
|
* @param plan Plan to run
|
|
34
|
+
* @param signal Optional abort signal
|
|
15
35
|
* @returns Result
|
|
16
36
|
*/
|
|
17
|
-
export declare function asyncRun<Yielded, Returned
|
|
37
|
+
export declare function asyncRun<Yielded, Returned>(plan: AsyncPlan<Yielded, Returned, []>, signal?: AbortSignal): Promise<PlanReturned<Returned>>;
|
|
18
38
|
/**
|
|
19
39
|
* Run a generator to completion
|
|
20
40
|
*
|
|
21
41
|
* @param generator Generator to run
|
|
42
|
+
* @param parameters Parameters for starting the run
|
|
22
43
|
* @returns Result
|
|
23
44
|
*/
|
|
24
45
|
export declare function run<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned>, ...parameters: Parameters): PlanReturned<Returned>;
|
|
@@ -26,10 +47,11 @@ export declare function run<Yielded, Returned, Parameters extends unknown[]>(gen
|
|
|
26
47
|
* Run a plan to completion
|
|
27
48
|
*
|
|
28
49
|
* @param plan Plan to run
|
|
50
|
+
* @param parameters Parameters for starting the run
|
|
29
51
|
* @returns Result
|
|
30
52
|
*/
|
|
31
53
|
export declare function run<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): PlanReturned<Returned>;
|
|
32
|
-
export declare function runAsyncPlan(this: InternalAsyncPlan,
|
|
54
|
+
export declare function runAsyncPlan(this: InternalAsyncPlan, first: never, second: never): Promise<unknown>;
|
|
33
55
|
export declare function runPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
34
56
|
export declare namespace asyncRun {
|
|
35
57
|
export var attempt: typeof asyncAttemptRun;
|
package/dist/plan/run.mjs
CHANGED
|
@@ -3,9 +3,9 @@ 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
|
-
function asyncRun(input,
|
|
7
|
-
if (isAsyncPlan(input)) return input
|
|
8
|
-
if (isAsyncGenerator(input)) return asyncGenerate(input,
|
|
6
|
+
function asyncRun(input, first, second) {
|
|
7
|
+
if (isAsyncPlan(input)) return asyncGenerate(input[PLAN_SYMBOL], false, first, second);
|
|
8
|
+
if (isAsyncGenerator(input)) return asyncGenerate(input, false, first, second);
|
|
9
9
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
10
10
|
}
|
|
11
11
|
function run(input, ...parameters) {
|
|
@@ -13,8 +13,8 @@ function run(input, ...parameters) {
|
|
|
13
13
|
if (isGenerator(input)) return generate(input, parameters, false);
|
|
14
14
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
15
15
|
}
|
|
16
|
-
function runAsyncPlan(
|
|
17
|
-
return asyncGenerate(this[PLAN_SYMBOL],
|
|
16
|
+
function runAsyncPlan(first, second) {
|
|
17
|
+
return asyncGenerate(this[PLAN_SYMBOL], false, first, second);
|
|
18
18
|
}
|
|
19
19
|
function runPlan(...parameters) {
|
|
20
20
|
return generate(this[PLAN_SYMBOL], parameters, false);
|