@oscarpalmer/atoms 0.215.0 → 0.217.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/swap.d.mts +2 -1
- package/dist/color/constants.d.mts +2 -1
- package/dist/color/space/rgb.d.mts +1 -0
- package/dist/function/index.mjs +1 -2
- package/dist/herald.mjs +1 -2
- package/dist/index.d.mts +253 -40
- package/dist/index.mjs +262 -102
- package/dist/internal/plan/index.d.mts +7 -0
- package/dist/internal/plan/index.mjs +18 -0
- package/dist/{plan/generate.d.mts → internal/plan/plan.generate.d.mts} +2 -2
- package/dist/{plan/generate.mjs → internal/plan/plan.generate.mjs} +4 -4
- package/dist/models/color.model.d.mts +2 -1
- package/dist/models/function/once.model.d.mts +2 -1
- package/dist/models/index.d.mts +2 -1
- package/dist/models/plan.model.d.mts +158 -29
- package/dist/models/plan.model.mjs +13 -5
- package/dist/models/queue.model.d.mts +2 -1
- package/dist/models/result.model.d.mts +2 -1
- package/dist/models/value/value.equal.model.d.mts +2 -1
- package/dist/models/value/value.merge.model.d.mts +2 -1
- package/dist/models/value/value.misc.model.d.mts +2 -1
- package/dist/number.mjs +1 -2
- package/dist/plan/index.mjs +14 -14
- package/dist/plan/is.d.mts +59 -3
- package/dist/plan/is.mjs +82 -10
- package/dist/plan/misc.d.mts +51 -3
- package/dist/plan/misc.mjs +47 -30
- package/dist/plan/models.d.mts +2 -2
- package/dist/plan/result.d.mts +15 -3
- package/dist/plan/result.mjs +5 -11
- package/dist/plan/run.d.mts +1 -3
- package/dist/plan/run.mjs +5 -11
- package/dist/plan/use.d.mts +36 -0
- package/dist/plan/use.mjs +69 -0
- package/dist/promise/models.mjs +1 -2
- package/dist/result/index.mjs +1 -2
- package/dist/result/work/pipe.d.mts +2 -1
- package/dist/subscription.mjs +1 -2
- package/package.json +8 -10
package/dist/index.mjs
CHANGED
|
@@ -2768,57 +2768,21 @@ function setValue(data, path, value, ignoreCase) {
|
|
|
2768
2768
|
}
|
|
2769
2769
|
//#endregion
|
|
2770
2770
|
//#region src/models/plan.model.ts
|
|
2771
|
-
const
|
|
2772
|
-
const
|
|
2771
|
+
const GENERATOR_FUNCTION_TYPE_ASYNC = "[object AsyncGeneratorFunction]";
|
|
2772
|
+
const GENERATOR_FUNCTION_TYPE_SYNC = "[object GeneratorFunction]";
|
|
2773
|
+
const GENERATOR_TYPE_ASYNC = "[object AsyncGenerator]";
|
|
2774
|
+
const GENERATOR_TYPE_SYNC = "[object Generator]";
|
|
2775
|
+
const PLAN_FAILURE_ASYNC = "asyncFailure";
|
|
2776
|
+
const PLAN_FAILURE_SYNC = "failure";
|
|
2773
2777
|
const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
|
|
2774
2778
|
const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
|
|
2779
|
+
const PLAN_STEP_ASYNC = "asyncStep";
|
|
2780
|
+
const PLAN_STEP_SYNC = "step";
|
|
2781
|
+
const PLAN_SUCCESS_ASYNC = "asyncSuccess";
|
|
2782
|
+
const PLAN_SUCCESS_SYNC = "success";
|
|
2775
2783
|
const PLAN_SYMBOL = Symbol("plan");
|
|
2776
|
-
const
|
|
2777
|
-
const
|
|
2778
|
-
//#endregion
|
|
2779
|
-
//#region src/plan/is.ts
|
|
2780
|
-
/**
|
|
2781
|
-
* Is the value an asynchronous generator function?
|
|
2782
|
-
*
|
|
2783
|
-
* @param value Value to check
|
|
2784
|
-
* @returns `true` if the value is an asynchronous generator function, otherwise `false`
|
|
2785
|
-
*/
|
|
2786
|
-
function isAsyncGenerator(value) {
|
|
2787
|
-
return isGeneratorInstance(GENERATOR_NAME_ASYNC, value);
|
|
2788
|
-
}
|
|
2789
|
-
/**
|
|
2790
|
-
* Is the value an asynchronous plan?
|
|
2791
|
-
*
|
|
2792
|
-
* @param value Value to check
|
|
2793
|
-
* @returns `true` if the value is an asynchronous plan, otherwise `false`
|
|
2794
|
-
*/
|
|
2795
|
-
function isAsyncPlan(value) {
|
|
2796
|
-
return isPlanInstance(PLAN_TYPE_PLAN_ASYNC, value);
|
|
2797
|
-
}
|
|
2798
|
-
/**
|
|
2799
|
-
* Is the value a generator function?
|
|
2800
|
-
*
|
|
2801
|
-
* @param value Value to check
|
|
2802
|
-
* @returns `true` if the value is a generator function, otherwise `false`
|
|
2803
|
-
*/
|
|
2804
|
-
function isGenerator(value) {
|
|
2805
|
-
return isGeneratorInstance(GENERATOR_NAME_SYNC, value);
|
|
2806
|
-
}
|
|
2807
|
-
function isGeneratorInstance(name, value) {
|
|
2808
|
-
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";
|
|
2809
|
-
}
|
|
2810
|
-
/**
|
|
2811
|
-
* Is the value a plan?
|
|
2812
|
-
*
|
|
2813
|
-
* @param value Value to check
|
|
2814
|
-
* @returns `true` if the value is a plan, otherwise `false`
|
|
2815
|
-
*/
|
|
2816
|
-
function isPlan(value) {
|
|
2817
|
-
return isPlanInstance(PLAN_TYPE_PLAN_SYNC, value);
|
|
2818
|
-
}
|
|
2819
|
-
function isPlanInstance(type, value) {
|
|
2820
|
-
return typeof value === "object" && value !== null && PLAN_SYMBOL in value && value[PLAN_SYMBOL].type === type;
|
|
2821
|
-
}
|
|
2784
|
+
const PLAN_TYPE_ASYNC = "asyncPlan";
|
|
2785
|
+
const PLAN_TYPE_SYNC = "plan";
|
|
2822
2786
|
//#endregion
|
|
2823
2787
|
//#region src/models/aborter.model.ts
|
|
2824
2788
|
const ABORTER_EVENT = "abort";
|
|
@@ -2835,7 +2799,7 @@ function createAborter(value, onAbort) {
|
|
|
2835
2799
|
};
|
|
2836
2800
|
}
|
|
2837
2801
|
//#endregion
|
|
2838
|
-
//#region src/plan/generate.ts
|
|
2802
|
+
//#region src/internal/plan/plan.generate.ts
|
|
2839
2803
|
async function asyncGenerate(input, unwrap, first, second) {
|
|
2840
2804
|
const aborter = createAborter(second ?? first, noop);
|
|
2841
2805
|
if (aborter != null && aborter.signal.aborted) throw aborter.signal.reason;
|
|
@@ -2893,46 +2857,164 @@ function generate(input, parameters, unwrap) {
|
|
|
2893
2857
|
throw lastValue;
|
|
2894
2858
|
}
|
|
2895
2859
|
//#endregion
|
|
2860
|
+
//#region src/internal/plan/index.ts
|
|
2861
|
+
function attemptRunPlan(...parameters) {
|
|
2862
|
+
return attempt(() => generate(this[PLAN_SYMBOL], parameters, true));
|
|
2863
|
+
}
|
|
2864
|
+
function getGenerator() {
|
|
2865
|
+
return this[PLAN_SYMBOL].generator();
|
|
2866
|
+
}
|
|
2867
|
+
function runAsyncPlan(first, second) {
|
|
2868
|
+
return asyncGenerate(this[PLAN_SYMBOL], false, first, second);
|
|
2869
|
+
}
|
|
2870
|
+
function runPlan(...parameters) {
|
|
2871
|
+
return generate(this[PLAN_SYMBOL], parameters, false);
|
|
2872
|
+
}
|
|
2873
|
+
//#endregion
|
|
2874
|
+
//#region src/plan/is.ts
|
|
2875
|
+
/**
|
|
2876
|
+
* Is the value an asynchronous, immediately failing plan?
|
|
2877
|
+
*
|
|
2878
|
+
* @param value Value to check
|
|
2879
|
+
* @returns `true` if the value is an asynchronous, immediately failing plan, otherwise `false`
|
|
2880
|
+
*/
|
|
2881
|
+
function isAsyncFailure(value) {
|
|
2882
|
+
return isPlanInstance(PLAN_FAILURE_ASYNC, value);
|
|
2883
|
+
}
|
|
2884
|
+
/**
|
|
2885
|
+
* Is the value an asynchronous generator?
|
|
2886
|
+
*
|
|
2887
|
+
* @param value Value to check
|
|
2888
|
+
* @returns `true` if the value is an asynchronous generator, otherwise `false`
|
|
2889
|
+
*/
|
|
2890
|
+
function isAsyncGenerator(value) {
|
|
2891
|
+
return isGeneratorInstance(GENERATOR_TYPE_ASYNC, value);
|
|
2892
|
+
}
|
|
2893
|
+
/**
|
|
2894
|
+
* Is the value an asynchronous generator function?
|
|
2895
|
+
*
|
|
2896
|
+
* @param value Value to check
|
|
2897
|
+
* @returns `true` if the value is an asynchronous generator function, otherwise `false`
|
|
2898
|
+
*/
|
|
2899
|
+
function isAsyncGeneratorFunction(value) {
|
|
2900
|
+
return isGeneratorInstance(GENERATOR_FUNCTION_TYPE_ASYNC, value);
|
|
2901
|
+
}
|
|
2902
|
+
/**
|
|
2903
|
+
* Is the value an asynchronous plan?
|
|
2904
|
+
*
|
|
2905
|
+
* @param value Value to check
|
|
2906
|
+
* @returns `true` if the value is an asynchronous plan, otherwise `false`
|
|
2907
|
+
*/
|
|
2908
|
+
function isAsyncPlan(value) {
|
|
2909
|
+
return isPlanInstance(PLAN_TYPE_ASYNC, value);
|
|
2910
|
+
}
|
|
2911
|
+
/**
|
|
2912
|
+
* Is the value an asynchronous step?
|
|
2913
|
+
*
|
|
2914
|
+
* @param value Value to check
|
|
2915
|
+
* @returns `true` if the value is an asynchronous step, otherwise `false`
|
|
2916
|
+
*/
|
|
2917
|
+
function isAsyncStep(value) {
|
|
2918
|
+
return isPlanInstance(PLAN_STEP_ASYNC, value);
|
|
2919
|
+
}
|
|
2920
|
+
/**
|
|
2921
|
+
* Is the value an asynchronous, immediately successful plan?
|
|
2922
|
+
*
|
|
2923
|
+
* @param value Value to check
|
|
2924
|
+
* @returns `true` if the value is an asynchronous, immediately successful plan, otherwise `false`
|
|
2925
|
+
*/
|
|
2926
|
+
function isAsyncSuccess(value) {
|
|
2927
|
+
return isPlanInstance(PLAN_SUCCESS_ASYNC, value);
|
|
2928
|
+
}
|
|
2929
|
+
/**
|
|
2930
|
+
* Is the value an immediately failing plan?
|
|
2931
|
+
*
|
|
2932
|
+
* @param value Value to check
|
|
2933
|
+
* @returns `true` if the value is an immediately failing plan, otherwise `false`
|
|
2934
|
+
*/
|
|
2935
|
+
function isFailure(value) {
|
|
2936
|
+
return isPlanInstance(PLAN_FAILURE_SYNC, value);
|
|
2937
|
+
}
|
|
2938
|
+
/**
|
|
2939
|
+
* Is the value a generator?
|
|
2940
|
+
*
|
|
2941
|
+
* @param value Value to check
|
|
2942
|
+
* @returns `true` if the value is a generator, otherwise `false`
|
|
2943
|
+
*/
|
|
2944
|
+
function isGenerator(value) {
|
|
2945
|
+
return isGeneratorInstance(GENERATOR_TYPE_SYNC, value);
|
|
2946
|
+
}
|
|
2947
|
+
/**
|
|
2948
|
+
* Is the value a generator function?
|
|
2949
|
+
*
|
|
2950
|
+
* @param value Value to check
|
|
2951
|
+
* @returns `true` if the value is a generator function, otherwise `false`
|
|
2952
|
+
*/
|
|
2953
|
+
function isGeneratorFunction(value) {
|
|
2954
|
+
return isGeneratorInstance(GENERATOR_FUNCTION_TYPE_SYNC, value);
|
|
2955
|
+
}
|
|
2956
|
+
function isGeneratorInstance(type, value) {
|
|
2957
|
+
return Object.prototype.toString.call(value) === type;
|
|
2958
|
+
}
|
|
2959
|
+
/**
|
|
2960
|
+
* Is the value a plan?
|
|
2961
|
+
*
|
|
2962
|
+
* @param value Value to check
|
|
2963
|
+
* @returns `true` if the value is a plan, otherwise `false`
|
|
2964
|
+
*/
|
|
2965
|
+
function isPlan(value) {
|
|
2966
|
+
return isPlanInstance(PLAN_TYPE_SYNC, value);
|
|
2967
|
+
}
|
|
2968
|
+
function isPlanInstance(type, value) {
|
|
2969
|
+
return typeof value === "object" && value !== null && PLAN_SYMBOL in value && value[PLAN_SYMBOL].type === type;
|
|
2970
|
+
}
|
|
2971
|
+
/**
|
|
2972
|
+
* Is the value a step?
|
|
2973
|
+
*
|
|
2974
|
+
* @param value Value to check
|
|
2975
|
+
* @returns `true` if the value is a step, otherwise `false`
|
|
2976
|
+
*/
|
|
2977
|
+
function isStep(value) {
|
|
2978
|
+
return isPlanInstance(PLAN_STEP_SYNC, value);
|
|
2979
|
+
}
|
|
2980
|
+
/**
|
|
2981
|
+
* Is the value an immediately successful plan?
|
|
2982
|
+
*
|
|
2983
|
+
* @param value Value to check
|
|
2984
|
+
* @returns `true` if the value is an immediately successful plan, otherwise `false`
|
|
2985
|
+
*/
|
|
2986
|
+
function isSuccess(value) {
|
|
2987
|
+
return isPlanInstance(PLAN_SUCCESS_SYNC, value);
|
|
2988
|
+
}
|
|
2989
|
+
//#endregion
|
|
2896
2990
|
//#region src/plan/result.ts
|
|
2897
2991
|
function asyncAttemptRun(input, first, second) {
|
|
2898
2992
|
let generator;
|
|
2899
2993
|
if (isAsyncPlan(input)) generator = input[PLAN_SYMBOL];
|
|
2900
|
-
else if (
|
|
2994
|
+
else if (isAsyncGeneratorFunction(input)) generator = input;
|
|
2901
2995
|
if (generator == null) throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2902
2996
|
return asyncAttempt(() => asyncGenerate(generator, true, first, second));
|
|
2903
2997
|
}
|
|
2904
2998
|
function attemptRun(input, ...parameters) {
|
|
2905
2999
|
let generator;
|
|
2906
3000
|
if (isPlan(input)) generator = input[PLAN_SYMBOL];
|
|
2907
|
-
else if (
|
|
3001
|
+
else if (isGeneratorFunction(input)) generator = input;
|
|
2908
3002
|
if (generator == null) throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2909
3003
|
return attempt(() => generate(generator, parameters, true));
|
|
2910
3004
|
}
|
|
2911
|
-
function attemptRunAsyncPlan(first, second) {
|
|
2912
|
-
return asyncAttemptRun(this, first, second);
|
|
2913
|
-
}
|
|
2914
|
-
function attemptRunPlan(...parameters) {
|
|
2915
|
-
return attempt(() => generate(this[PLAN_SYMBOL], parameters, true));
|
|
2916
|
-
}
|
|
2917
3005
|
attemptRun.async = asyncAttemptRun;
|
|
2918
3006
|
//#endregion
|
|
2919
3007
|
//#region src/plan/run.ts
|
|
2920
3008
|
function asyncRun(input, first, second) {
|
|
2921
3009
|
if (isAsyncPlan(input)) return asyncGenerate(input[PLAN_SYMBOL], false, first, second);
|
|
2922
|
-
if (
|
|
3010
|
+
if (isAsyncGeneratorFunction(input)) return asyncGenerate(input, false, first, second);
|
|
2923
3011
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2924
3012
|
}
|
|
2925
3013
|
function run(input, ...parameters) {
|
|
2926
3014
|
if (isPlan(input)) return input.run(...parameters);
|
|
2927
|
-
if (
|
|
3015
|
+
if (isGeneratorFunction(input)) return generate(input, parameters, false);
|
|
2928
3016
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2929
3017
|
}
|
|
2930
|
-
function runAsyncPlan(first, second) {
|
|
2931
|
-
return asyncGenerate(this[PLAN_SYMBOL], false, first, second);
|
|
2932
|
-
}
|
|
2933
|
-
function runPlan(...parameters) {
|
|
2934
|
-
return generate(this[PLAN_SYMBOL], parameters, false);
|
|
2935
|
-
}
|
|
2936
3018
|
asyncRun.attempt = asyncAttemptRun;
|
|
2937
3019
|
run.async = asyncRun;
|
|
2938
3020
|
run.attempt = attemptRun;
|
|
@@ -2941,66 +3023,144 @@ run.attempt = attemptRun;
|
|
|
2941
3023
|
function AsyncPlan(generator) {
|
|
2942
3024
|
this[PLAN_SYMBOL] = {
|
|
2943
3025
|
generator,
|
|
2944
|
-
type:
|
|
3026
|
+
type: PLAN_TYPE_ASYNC
|
|
2945
3027
|
};
|
|
2946
3028
|
}
|
|
2947
|
-
AsyncPlan.prototype[Symbol.asyncIterator] =
|
|
2948
|
-
return this[PLAN_SYMBOL].generator();
|
|
2949
|
-
};
|
|
3029
|
+
AsyncPlan.prototype[Symbol.asyncIterator] = getGenerator;
|
|
2950
3030
|
AsyncPlan.prototype.attempt = attemptRunAsyncPlan;
|
|
2951
3031
|
AsyncPlan.prototype.run = runAsyncPlan;
|
|
2952
3032
|
function Plan(generator) {
|
|
2953
3033
|
this[PLAN_SYMBOL] = {
|
|
2954
3034
|
generator,
|
|
2955
|
-
type:
|
|
3035
|
+
type: PLAN_TYPE_SYNC
|
|
2956
3036
|
};
|
|
2957
3037
|
}
|
|
2958
|
-
Plan.prototype[Symbol.iterator] =
|
|
2959
|
-
return this[PLAN_SYMBOL].generator();
|
|
2960
|
-
};
|
|
3038
|
+
Plan.prototype[Symbol.iterator] = getGenerator;
|
|
2961
3039
|
Plan.prototype.attempt = attemptRunPlan;
|
|
2962
3040
|
Plan.prototype.run = runPlan;
|
|
3041
|
+
function attemptRunAsyncPlan(first, second) {
|
|
3042
|
+
return asyncAttemptRun(this, first, second);
|
|
3043
|
+
}
|
|
2963
3044
|
function plan(generator) {
|
|
2964
|
-
if (
|
|
2965
|
-
if (
|
|
3045
|
+
if (isAsyncGeneratorFunction(generator)) return new AsyncPlan(generator);
|
|
3046
|
+
if (isGeneratorFunction(generator)) return new Plan(generator);
|
|
2966
3047
|
throw new Error(PLAN_MESSAGE_PLAN_INPUT);
|
|
2967
3048
|
}
|
|
2968
3049
|
//#endregion
|
|
2969
3050
|
//#region src/plan/misc.ts
|
|
2970
|
-
function
|
|
2971
|
-
this[PLAN_SYMBOL] = {
|
|
3051
|
+
function AsyncFailure(generator) {
|
|
3052
|
+
this[PLAN_SYMBOL] = {
|
|
3053
|
+
generator,
|
|
3054
|
+
type: PLAN_FAILURE_ASYNC
|
|
3055
|
+
};
|
|
2972
3056
|
}
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
3057
|
+
AsyncFailure.prototype[Symbol.asyncIterator] = getGenerator;
|
|
3058
|
+
function AsyncSuccess(generator) {
|
|
3059
|
+
this[PLAN_SYMBOL] = {
|
|
3060
|
+
generator,
|
|
3061
|
+
type: PLAN_SUCCESS_ASYNC
|
|
3062
|
+
};
|
|
3063
|
+
}
|
|
3064
|
+
AsyncSuccess.prototype[Symbol.asyncIterator] = getGenerator;
|
|
3065
|
+
function Failure(generator) {
|
|
3066
|
+
this[PLAN_SYMBOL] = {
|
|
3067
|
+
generator,
|
|
3068
|
+
type: PLAN_FAILURE_SYNC
|
|
3069
|
+
};
|
|
3070
|
+
}
|
|
3071
|
+
Failure.prototype[Symbol.iterator] = getGenerator;
|
|
3072
|
+
function Success(generator) {
|
|
3073
|
+
this[PLAN_SYMBOL] = {
|
|
3074
|
+
generator,
|
|
3075
|
+
type: PLAN_SUCCESS_SYNC
|
|
3076
|
+
};
|
|
3077
|
+
}
|
|
3078
|
+
Success.prototype[Symbol.iterator] = getGenerator;
|
|
3079
|
+
function asyncFail(value) {
|
|
3080
|
+
return new AsyncFailure(async function* () {
|
|
3081
|
+
yield error(await (typeof value === "function" ? value() : value));
|
|
3082
|
+
});
|
|
3083
|
+
}
|
|
3084
|
+
function asyncSucceed(value) {
|
|
3085
|
+
return new AsyncSuccess(async function* () {
|
|
3086
|
+
return typeof value === "function" ? value() : value;
|
|
3087
|
+
});
|
|
2978
3088
|
}
|
|
2979
|
-
PlanSuccess.prototype[Symbol.iterator] = function() {
|
|
2980
|
-
return this[PLAN_SYMBOL].generator();
|
|
2981
|
-
};
|
|
2982
|
-
/**
|
|
2983
|
-
* Create an immediately failing plan
|
|
2984
|
-
*
|
|
2985
|
-
* @param value Failure value
|
|
2986
|
-
* @returns Plan failure
|
|
2987
|
-
*/
|
|
2988
3089
|
function fail(value) {
|
|
2989
|
-
return new
|
|
2990
|
-
yield error(value);
|
|
3090
|
+
return new Failure(function* () {
|
|
3091
|
+
yield error(typeof value === "function" ? value() : value);
|
|
2991
3092
|
});
|
|
2992
3093
|
}
|
|
2993
|
-
/**
|
|
2994
|
-
* Create an immediately succeeding plan
|
|
2995
|
-
*
|
|
2996
|
-
* @param value Success value
|
|
2997
|
-
* @returns Plan success
|
|
2998
|
-
*/
|
|
2999
3094
|
function succeed(value) {
|
|
3000
|
-
return new
|
|
3001
|
-
return value;
|
|
3095
|
+
return new Success(function* () {
|
|
3096
|
+
return typeof value === "function" ? value() : value;
|
|
3097
|
+
});
|
|
3098
|
+
}
|
|
3099
|
+
fail.async = asyncFail;
|
|
3100
|
+
succeed.async = asyncSucceed;
|
|
3101
|
+
//#endregion
|
|
3102
|
+
//#region src/plan/use.ts
|
|
3103
|
+
function AsyncStep(generator) {
|
|
3104
|
+
this[PLAN_SYMBOL] = {
|
|
3105
|
+
generator,
|
|
3106
|
+
type: PLAN_STEP_ASYNC
|
|
3107
|
+
};
|
|
3108
|
+
}
|
|
3109
|
+
AsyncStep.prototype[Symbol.asyncIterator] = getGenerator;
|
|
3110
|
+
function Step(generator) {
|
|
3111
|
+
this[PLAN_SYMBOL] = {
|
|
3112
|
+
generator,
|
|
3113
|
+
type: PLAN_STEP_SYNC
|
|
3114
|
+
};
|
|
3115
|
+
}
|
|
3116
|
+
Step.prototype[Symbol.iterator] = getGenerator;
|
|
3117
|
+
function asyncUse(value) {
|
|
3118
|
+
return new AsyncStep(async function* () {
|
|
3119
|
+
let actual = value;
|
|
3120
|
+
if (typeof actual === "function") actual = actual();
|
|
3121
|
+
actual = await actual;
|
|
3122
|
+
if (typeof actual === "function") throw new Error();
|
|
3123
|
+
if (typeof actual === "object" && actual !== null && PLAN_SYMBOL in actual) return yield* actual;
|
|
3124
|
+
if (isAsyncGenerator(actual) || isGenerator(actual)) return yield* actual;
|
|
3125
|
+
if (isError(actual)) {
|
|
3126
|
+
yield* fail(actual.error);
|
|
3127
|
+
return;
|
|
3128
|
+
}
|
|
3129
|
+
if (isOk(actual)) return actual.value;
|
|
3130
|
+
if (actual instanceof Error) {
|
|
3131
|
+
yield* fail(actual);
|
|
3132
|
+
return;
|
|
3133
|
+
}
|
|
3134
|
+
return actual;
|
|
3002
3135
|
});
|
|
3003
3136
|
}
|
|
3137
|
+
function use(value) {
|
|
3138
|
+
validateUseInput(value, false);
|
|
3139
|
+
return new Step(function* () {
|
|
3140
|
+
let actual = value;
|
|
3141
|
+
if (typeof actual === "function") {
|
|
3142
|
+
actual = actual();
|
|
3143
|
+
validateUseInput(actual, true);
|
|
3144
|
+
}
|
|
3145
|
+
if (typeof actual === "object" && actual !== null && PLAN_SYMBOL in actual) return yield* actual;
|
|
3146
|
+
if (isGenerator(actual)) return yield* actual;
|
|
3147
|
+
if (isError(actual)) {
|
|
3148
|
+
yield* fail(actual.error);
|
|
3149
|
+
return;
|
|
3150
|
+
}
|
|
3151
|
+
if (isOk(actual)) return actual.value;
|
|
3152
|
+
if (actual instanceof Error) {
|
|
3153
|
+
yield* fail(actual);
|
|
3154
|
+
return;
|
|
3155
|
+
}
|
|
3156
|
+
return actual;
|
|
3157
|
+
});
|
|
3158
|
+
}
|
|
3159
|
+
function validateUseInput(value, resolved) {
|
|
3160
|
+
if (value instanceof Promise || isAsyncFailure(value) || isAsyncGenerator(value) || isAsyncGeneratorFunction(value) || isAsyncPlan(value) || isAsyncStep(value) || isAsyncSuccess(value)) throw new Error();
|
|
3161
|
+
if (resolved && typeof value === "function") throw new Error();
|
|
3162
|
+
}
|
|
3163
|
+
use.async = asyncUse;
|
|
3004
3164
|
//#endregion
|
|
3005
3165
|
//#region src/models/promise.model.ts
|
|
3006
3166
|
/**
|
|
@@ -7111,4 +7271,4 @@ var SizedSet = class extends Set {
|
|
|
7111
7271
|
}
|
|
7112
7272
|
};
|
|
7113
7273
|
//#endregion
|
|
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,
|
|
7274
|
+
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, asyncFail, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncRun, asyncSucceed, asyncThrottle, asyncUse, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, attemptRun, 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, isAsyncFailure, isAsyncGenerator, isAsyncGeneratorFunction, isAsyncOnce, isAsyncPlan, isAsyncStep, isAsyncSuccess, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFailure, isFrozen, isFulfilled, isFuzzy, isGenerator, isGeneratorFunction, 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, isStep, isSubscription, isSubscriptions, isSuccess, 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, 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, use, words };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GenericPlanItem, InternalAsyncPlan, InternalPlan } from "../../models/plan.model.mjs";
|
|
2
|
+
//#region src/internal/plan/index.d.ts
|
|
3
|
+
export declare function attemptRunPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
4
|
+
export declare function getGenerator(this: GenericPlanItem): AsyncGenerator | Generator;
|
|
5
|
+
export declare function runAsyncPlan(this: InternalAsyncPlan, first: never, second: never): Promise<unknown>;
|
|
6
|
+
export declare function runPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
7
|
+
//#endregion
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { attempt } from "../result/attempt.mjs";
|
|
2
|
+
import { PLAN_SYMBOL } from "../../models/plan.model.mjs";
|
|
3
|
+
import { asyncGenerate, generate } from "./plan.generate.mjs";
|
|
4
|
+
//#region src/internal/plan/index.ts
|
|
5
|
+
function attemptRunPlan(...parameters) {
|
|
6
|
+
return attempt(() => generate(this[PLAN_SYMBOL], parameters, true));
|
|
7
|
+
}
|
|
8
|
+
function getGenerator() {
|
|
9
|
+
return this[PLAN_SYMBOL].generator();
|
|
10
|
+
}
|
|
11
|
+
function runAsyncPlan(first, second) {
|
|
12
|
+
return asyncGenerate(this[PLAN_SYMBOL], false, first, second);
|
|
13
|
+
}
|
|
14
|
+
function runPlan(...parameters) {
|
|
15
|
+
return generate(this[PLAN_SYMBOL], parameters, false);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { attemptRunPlan, getGenerator, runAsyncPlan, runPlan };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AsyncPlanState, PlanState } from "
|
|
2
|
-
//#region src/plan/generate.d.ts
|
|
1
|
+
import { AsyncPlanState, PlanState } from "../../models/plan.model.mjs";
|
|
2
|
+
//#region src/internal/plan/plan.generate.d.ts
|
|
3
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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { noop } from "../
|
|
2
|
-
import { createAborter } from "../
|
|
3
|
-
import { isError, isOk } from "../
|
|
4
|
-
//#region src/plan/generate.ts
|
|
1
|
+
import { noop } from "../function/misc.mjs";
|
|
2
|
+
import { createAborter } from "../aborter.mjs";
|
|
3
|
+
import { isError, isOk } from "../result/misc.mjs";
|
|
4
|
+
//#region src/internal/plan/plan.generate.ts
|
|
5
5
|
async function asyncGenerate(input, unwrap, first, second) {
|
|
6
6
|
const aborter = createAborter(second ?? first, noop);
|
|
7
7
|
if (aborter != null && aborter.signal.aborted) throw aborter.signal.reason;
|
|
@@ -73,4 +73,5 @@ export declare const ONCE_PROPERTY = "$once";
|
|
|
73
73
|
export declare const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
74
74
|
export declare const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
75
75
|
export declare const ONCE_SYMBOL: unique symbol;
|
|
76
|
-
//#endregion
|
|
76
|
+
//#endregion
|
|
77
|
+
export {};
|
package/dist/models/index.d.mts
CHANGED