@oscarpalmer/atoms 0.206.0 → 0.207.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 +52 -2
- package/dist/index.mjs +65 -4
- package/dist/internal/function/work.d.mts +1 -1
- package/dist/internal/models/plan.model.d.mts +23 -0
- package/dist/internal/models/plan.model.mjs +7 -0
- package/dist/internal/{result/models.d.mts → models/result.model.d.mts} +1 -1
- package/dist/internal/result/attempt.d.mts +1 -1
- package/dist/internal/result/misc.d.mts +1 -1
- package/dist/internal/value/has.d.mts +1 -1
- package/dist/internal/value/misc.d.mts +1 -1
- package/dist/plan/index.d.mts +38 -0
- package/dist/plan/index.mjs +61 -0
- package/dist/plan/models.d.mts +2 -0
- package/dist/plan/models.mjs +1 -0
- package/dist/promise/misc.d.mts +1 -1
- package/dist/promise/models.d.mts +1 -1
- package/dist/result/match.d.mts +1 -1
- package/dist/result/misc.d.mts +1 -1
- package/dist/result/work/flow.d.mts +1 -1
- package/dist/result/work/pipe.d.mts +1 -1
- package/package.json +9 -4
- /package/dist/internal/{result/models.mjs → models/result.model.mjs} +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -3667,7 +3667,7 @@ export type MemoizedOptions<Callback extends GenericCallback> = {
|
|
|
3667
3667
|
*/
|
|
3668
3668
|
export declare function memoize<Callback extends GenericCallback>(callback: Callback, options?: MemoizedOptions<Callback>): Memoized<Callback>;
|
|
3669
3669
|
//#endregion
|
|
3670
|
-
//#region src/internal/result
|
|
3670
|
+
//#region src/internal/models/result.model.d.ts
|
|
3671
3671
|
/**
|
|
3672
3672
|
* An unknown result
|
|
3673
3673
|
*/
|
|
@@ -4587,6 +4587,56 @@ export declare function setValue<Data extends PlainObject, Path extends NestedKe
|
|
|
4587
4587
|
*/
|
|
4588
4588
|
export declare function setValue<Data extends PlainObject>(data: Data, path: string, value: unknown, ignoreCase?: boolean): Data;
|
|
4589
4589
|
//#endregion
|
|
4590
|
+
//#region src/internal/models/plan.model.d.ts
|
|
4591
|
+
/**
|
|
4592
|
+
* A plan of execution that can yield intermediate results and eventually return a value or an error.
|
|
4593
|
+
*/
|
|
4594
|
+
type Plan<out Value, out Error = unknown> = {
|
|
4595
|
+
/**
|
|
4596
|
+
* Run the plan to completion
|
|
4597
|
+
*
|
|
4598
|
+
* @returns Final result, or an error
|
|
4599
|
+
*/
|
|
4600
|
+
run: () => Error | Value;
|
|
4601
|
+
};
|
|
4602
|
+
//#endregion
|
|
4603
|
+
//#region src/plan/index.d.ts
|
|
4604
|
+
/**
|
|
4605
|
+
* Is the value a generator function?
|
|
4606
|
+
*
|
|
4607
|
+
* @param value Value to check
|
|
4608
|
+
* @returns `true` if the value is a generator function, otherwise `false`
|
|
4609
|
+
*/
|
|
4610
|
+
export declare function isGenerator(value: unknown): value is () => Generator;
|
|
4611
|
+
/**
|
|
4612
|
+
* Is the value a plan?
|
|
4613
|
+
*
|
|
4614
|
+
* @param value Value to check
|
|
4615
|
+
* @returns `true` if the value is a plan, otherwise `false`
|
|
4616
|
+
*/
|
|
4617
|
+
export declare function isPlan<Value = unknown, Error = unknown>(value: unknown): value is Plan<Value, Error>;
|
|
4618
|
+
/**
|
|
4619
|
+
* Create a plan for a generator function
|
|
4620
|
+
*
|
|
4621
|
+
* @param generator Generator to plan for
|
|
4622
|
+
* @returns Generator plan
|
|
4623
|
+
*/
|
|
4624
|
+
export declare function plan<Value = unknown, Error = unknown>(generator: () => Generator<unknown, Value, Error>): Plan<Value, Error>;
|
|
4625
|
+
/**
|
|
4626
|
+
* Run a generator to completion
|
|
4627
|
+
*
|
|
4628
|
+
* @param generator Generator to run
|
|
4629
|
+
* @returns Final result, or an error
|
|
4630
|
+
*/
|
|
4631
|
+
export declare function run<Value = unknown, Error = unknown>(generator: () => Generator<unknown, Value, unknown>): Error | Value;
|
|
4632
|
+
/**
|
|
4633
|
+
* Run a plan to completion
|
|
4634
|
+
*
|
|
4635
|
+
* @param plan Plan to run
|
|
4636
|
+
* @returns Final result, or an error
|
|
4637
|
+
*/
|
|
4638
|
+
export declare function run<Value = unknown, Error = unknown>(plan: Plan<Value, Error>): Error | Value;
|
|
4639
|
+
//#endregion
|
|
4590
4640
|
//#region src/internal/aborter.d.ts
|
|
4591
4641
|
type Aborter = {
|
|
4592
4642
|
callback: GenericCallback;
|
|
@@ -8317,4 +8367,4 @@ export declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
8317
8367
|
get(value: Value, update?: boolean): Value | undefined;
|
|
8318
8368
|
}
|
|
8319
8369
|
//#endregion
|
|
8320
|
-
export { type AsyncLimiter, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, Key$1 as Key, type Limiter, Logger, type RGBAColor, type RGBColor, type Shaken, type Smushed, type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, type TimeLogger, type Unsmushed, push as append, filterAndMap as select, toPromise as fromResult, getRandomFloatingNumber as getRandomFloat, isLogger, isTimeLogger, mapAndFilter as reverseSelect };
|
|
8370
|
+
export { type AsyncLimiter, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, Key$1 as Key, type Limiter, Logger, type Plan, type RGBAColor, type RGBColor, type Shaken, type Smushed, type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, type TimeLogger, type Unsmushed, push as append, filterAndMap as select, toPromise as fromResult, getRandomFloatingNumber as getRandomFloat, isLogger, isTimeLogger, mapAndFilter as reverseSelect };
|
package/dist/index.mjs
CHANGED
|
@@ -2746,6 +2746,67 @@ function setValue(data, path, value, ignoreCase) {
|
|
|
2746
2746
|
return data;
|
|
2747
2747
|
}
|
|
2748
2748
|
const SET_EXPRESSION_INDEX = /^\d+$/;
|
|
2749
|
+
const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
|
|
2750
|
+
const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
|
|
2751
|
+
const PLAN_SYMBOL = Symbol("plan");
|
|
2752
|
+
//#endregion
|
|
2753
|
+
//#region src/plan/index.ts
|
|
2754
|
+
function Plan(generator) {
|
|
2755
|
+
this[PLAN_SYMBOL] = { generator };
|
|
2756
|
+
}
|
|
2757
|
+
Plan.prototype.run = runPlan;
|
|
2758
|
+
function execute(callback) {
|
|
2759
|
+
const result = attempt(() => {
|
|
2760
|
+
const generator = callback();
|
|
2761
|
+
let lastValue;
|
|
2762
|
+
while (true) {
|
|
2763
|
+
const next = generator.next();
|
|
2764
|
+
const { done } = next;
|
|
2765
|
+
let { value } = next;
|
|
2766
|
+
if (value instanceof Error) throw value;
|
|
2767
|
+
lastValue = value;
|
|
2768
|
+
if (done === true) break;
|
|
2769
|
+
}
|
|
2770
|
+
return lastValue;
|
|
2771
|
+
});
|
|
2772
|
+
return result.ok ? result.value : result.error;
|
|
2773
|
+
}
|
|
2774
|
+
/**
|
|
2775
|
+
* Is the value a generator function?
|
|
2776
|
+
*
|
|
2777
|
+
* @param value Value to check
|
|
2778
|
+
* @returns `true` if the value is a generator function, otherwise `false`
|
|
2779
|
+
*/
|
|
2780
|
+
function isGenerator(value) {
|
|
2781
|
+
return typeof value === "function" && value.constructor.name === "GeneratorFunction" && typeof value.prototype.next === "function" && typeof value.prototype.return === "function" && typeof value.prototype.throw === "function";
|
|
2782
|
+
}
|
|
2783
|
+
/**
|
|
2784
|
+
* Is the value a plan?
|
|
2785
|
+
*
|
|
2786
|
+
* @param value Value to check
|
|
2787
|
+
* @returns `true` if the value is a plan, otherwise `false`
|
|
2788
|
+
*/
|
|
2789
|
+
function isPlan(value) {
|
|
2790
|
+
return typeof value === "object" && value !== null && PLAN_SYMBOL in value;
|
|
2791
|
+
}
|
|
2792
|
+
/**
|
|
2793
|
+
* Create a plan for a generator function
|
|
2794
|
+
*
|
|
2795
|
+
* @param generator Generator to plan for
|
|
2796
|
+
* @returns Generator plan
|
|
2797
|
+
*/
|
|
2798
|
+
function plan(generator) {
|
|
2799
|
+
if (!isGenerator(generator)) throw new Error(PLAN_MESSAGE_PLAN_INPUT);
|
|
2800
|
+
return new Plan(generator);
|
|
2801
|
+
}
|
|
2802
|
+
function run(input) {
|
|
2803
|
+
if (isPlan(input)) return input.run();
|
|
2804
|
+
if (!isGenerator(input)) throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2805
|
+
return execute(input);
|
|
2806
|
+
}
|
|
2807
|
+
function runPlan() {
|
|
2808
|
+
return execute(this[PLAN_SYMBOL].generator);
|
|
2809
|
+
}
|
|
2749
2810
|
//#endregion
|
|
2750
2811
|
//#region src/internal/aborter.ts
|
|
2751
2812
|
function createAborter(value, onAbort) {
|
|
@@ -6493,7 +6554,7 @@ function addToQueue(parameters, signal) {
|
|
|
6493
6554
|
reject: rejector,
|
|
6494
6555
|
resolve: resolver
|
|
6495
6556
|
});
|
|
6496
|
-
if (state.options.autostart) run(state);
|
|
6557
|
+
if (state.options.autostart) run$1(state);
|
|
6497
6558
|
return {
|
|
6498
6559
|
id,
|
|
6499
6560
|
promise
|
|
@@ -6681,12 +6742,12 @@ function resumeQueue() {
|
|
|
6681
6742
|
}
|
|
6682
6743
|
state.paused = false;
|
|
6683
6744
|
const length = min([state.options.concurrency, state.items.length]);
|
|
6684
|
-
for (let index = 0; index < length; index += 1) run(state);
|
|
6745
|
+
for (let index = 0; index < length; index += 1) run$1(state);
|
|
6685
6746
|
}
|
|
6686
6747
|
function resumeQueues(key) {
|
|
6687
6748
|
handleQueues(this, QUEUE_HANDLE_RESUME, key);
|
|
6688
6749
|
}
|
|
6689
|
-
async function run(state) {
|
|
6750
|
+
async function run$1(state) {
|
|
6690
6751
|
if (state.paused || state.runners >= state.options.concurrency) return;
|
|
6691
6752
|
state.runners += 1;
|
|
6692
6753
|
let item = state.items.shift();
|
|
@@ -6847,4 +6908,4 @@ var SizedSet = class extends Set {
|
|
|
6847
6908
|
}
|
|
6848
6909
|
};
|
|
6849
6910
|
//#endregion
|
|
6850
|
-
export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, push as append, push, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, 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, 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, isAsyncOnce, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isFuzzy, 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, 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, promises, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, 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 };
|
|
6911
|
+
export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, push as append, push, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, 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, 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, isAsyncOnce, 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, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, 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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GenericCallback } from "../../models.mjs";
|
|
2
|
-
import { UnwrapValue } from "../result
|
|
2
|
+
import { UnwrapValue } from "../models/result.model.mjs";
|
|
3
3
|
//#region src/internal/function/work.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* A synchronous _Flow_, a function that pipe a value through a series of functions
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/internal/models/plan.model.d.ts
|
|
2
|
+
export type InternalPlan = {
|
|
3
|
+
[PLAN_SYMBOL]: PlanState;
|
|
4
|
+
} & Plan<never, never>;
|
|
5
|
+
/**
|
|
6
|
+
* A plan of execution that can yield intermediate results and eventually return a value or an error.
|
|
7
|
+
*/
|
|
8
|
+
export type Plan<out Value, out Error = unknown> = {
|
|
9
|
+
/**
|
|
10
|
+
* Run the plan to completion
|
|
11
|
+
*
|
|
12
|
+
* @returns Final result, or an error
|
|
13
|
+
*/
|
|
14
|
+
run: () => Error | Value;
|
|
15
|
+
};
|
|
16
|
+
type PlanState = {
|
|
17
|
+
generator: () => Generator;
|
|
18
|
+
};
|
|
19
|
+
export declare const GENERATOR_NAME = "GeneratorFunction";
|
|
20
|
+
export declare const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
|
|
21
|
+
export declare const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
|
|
22
|
+
export declare const PLAN_SYMBOL: symbol;
|
|
23
|
+
//#endregion
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/internal/models/plan.model.ts
|
|
2
|
+
const GENERATOR_NAME = "GeneratorFunction";
|
|
3
|
+
const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
|
|
4
|
+
const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
|
|
5
|
+
const PLAN_SYMBOL = Symbol("plan");
|
|
6
|
+
//#endregion
|
|
7
|
+
export { GENERATOR_NAME, PLAN_MESSAGE_PLAN_INPUT, PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NestedKeys, NestedValue, PlainObject, ToString } from "../../models.mjs";
|
|
2
|
-
import { Result } from "../result
|
|
2
|
+
import { Result } from "../models/result.model.mjs";
|
|
3
3
|
//#region src/internal/value/has.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Check if a property is defined in an object
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Result } from "../result
|
|
1
|
+
import { Result } from "../models/result.model.mjs";
|
|
2
2
|
//#region src/internal/value/misc.d.ts
|
|
3
3
|
export declare function findKey(needle: string, haystack: object): string;
|
|
4
4
|
export declare function getNestedValue(data: object, path: string, ignoreCase: boolean): Result<unknown, string>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Plan } from "../internal/models/plan.model.mjs";
|
|
2
|
+
//#region src/plan/index.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Is the value a generator function?
|
|
5
|
+
*
|
|
6
|
+
* @param value Value to check
|
|
7
|
+
* @returns `true` if the value is a generator function, otherwise `false`
|
|
8
|
+
*/
|
|
9
|
+
export declare function isGenerator(value: unknown): value is () => Generator;
|
|
10
|
+
/**
|
|
11
|
+
* Is the value a plan?
|
|
12
|
+
*
|
|
13
|
+
* @param value Value to check
|
|
14
|
+
* @returns `true` if the value is a plan, otherwise `false`
|
|
15
|
+
*/
|
|
16
|
+
export declare function isPlan<Value = unknown, Error = unknown>(value: unknown): value is Plan<Value, Error>;
|
|
17
|
+
/**
|
|
18
|
+
* Create a plan for a generator function
|
|
19
|
+
*
|
|
20
|
+
* @param generator Generator to plan for
|
|
21
|
+
* @returns Generator plan
|
|
22
|
+
*/
|
|
23
|
+
export declare function plan<Value = unknown, Error = unknown>(generator: () => Generator<unknown, Value, Error>): Plan<Value, Error>;
|
|
24
|
+
/**
|
|
25
|
+
* Run a generator to completion
|
|
26
|
+
*
|
|
27
|
+
* @param generator Generator to run
|
|
28
|
+
* @returns Final result, or an error
|
|
29
|
+
*/
|
|
30
|
+
export declare function run<Value = unknown, Error = unknown>(generator: () => Generator<unknown, Value, unknown>): Error | Value;
|
|
31
|
+
/**
|
|
32
|
+
* Run a plan to completion
|
|
33
|
+
*
|
|
34
|
+
* @param plan Plan to run
|
|
35
|
+
* @returns Final result, or an error
|
|
36
|
+
*/
|
|
37
|
+
export declare function run<Value = unknown, Error = unknown>(plan: Plan<Value, Error>): Error | Value;
|
|
38
|
+
//#endregion
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { attempt } from "../internal/result/attempt.mjs";
|
|
2
|
+
import { PLAN_MESSAGE_PLAN_INPUT, PLAN_MESSAGE_RUN_INPUT, PLAN_SYMBOL } from "../internal/models/plan.model.mjs";
|
|
3
|
+
//#region src/plan/index.ts
|
|
4
|
+
function Plan(generator) {
|
|
5
|
+
this[PLAN_SYMBOL] = { generator };
|
|
6
|
+
}
|
|
7
|
+
Plan.prototype.run = runPlan;
|
|
8
|
+
function execute(callback) {
|
|
9
|
+
const result = attempt(() => {
|
|
10
|
+
const generator = callback();
|
|
11
|
+
let lastValue;
|
|
12
|
+
while (true) {
|
|
13
|
+
const next = generator.next();
|
|
14
|
+
const { done } = next;
|
|
15
|
+
let { value } = next;
|
|
16
|
+
if (value instanceof Error) throw value;
|
|
17
|
+
lastValue = value;
|
|
18
|
+
if (done === true) break;
|
|
19
|
+
}
|
|
20
|
+
return lastValue;
|
|
21
|
+
});
|
|
22
|
+
return result.ok ? result.value : result.error;
|
|
23
|
+
}
|
|
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
|
+
function isGenerator(value) {
|
|
31
|
+
return typeof value === "function" && value.constructor.name === "GeneratorFunction" && 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 typeof value === "object" && value !== null && PLAN_SYMBOL in value;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a plan for a generator function
|
|
44
|
+
*
|
|
45
|
+
* @param generator Generator to plan for
|
|
46
|
+
* @returns Generator plan
|
|
47
|
+
*/
|
|
48
|
+
function plan(generator) {
|
|
49
|
+
if (!isGenerator(generator)) throw new Error(PLAN_MESSAGE_PLAN_INPUT);
|
|
50
|
+
return new Plan(generator);
|
|
51
|
+
}
|
|
52
|
+
function run(input) {
|
|
53
|
+
if (isPlan(input)) return input.run();
|
|
54
|
+
if (!isGenerator(input)) throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
55
|
+
return execute(input);
|
|
56
|
+
}
|
|
57
|
+
function runPlan() {
|
|
58
|
+
return execute(this[PLAN_SYMBOL].generator);
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { isGenerator, isPlan, plan, run };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/promise/misc.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Result } from "../internal/result
|
|
1
|
+
import { Result } from "../internal/models/result.model.mjs";
|
|
2
2
|
import { Aborter } from "../internal/aborter.mjs";
|
|
3
3
|
import { CancelablePromise, PromiseParameters } from "./models.mjs";
|
|
4
4
|
import { toPromise } from "../result/misc.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArrayOrPlainObject, GenericCallback, Key } from "../models.mjs";
|
|
2
|
-
import { Result } from "../internal/result
|
|
2
|
+
import { Result } from "../internal/models/result.model.mjs";
|
|
3
3
|
import { Aborter } from "../internal/aborter.mjs";
|
|
4
4
|
import { PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
|
|
5
5
|
//#region src/promise/models.d.ts
|
package/dist/result/match.d.mts
CHANGED
package/dist/result/misc.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GenericCallback } from "../../models.mjs";
|
|
2
|
-
import { Result, UnwrapValue } from "../../internal/result
|
|
2
|
+
import { Result, UnwrapValue } from "../../internal/models/result.model.mjs";
|
|
3
3
|
//#region src/result/work/flow.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* A synchronous _Flow_, a function that attempts to pipe values through a series of functions
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GenericCallback } from "../../models.mjs";
|
|
2
|
-
import { Result, UnwrapValue } from "../../internal/result
|
|
2
|
+
import { Result, UnwrapValue } from "../../internal/models/result.model.mjs";
|
|
3
3
|
//#region src/result/work/pipe.d.ts
|
|
4
4
|
type WrapValue<Value> = Result<UnwrapValue<Value>>;
|
|
5
5
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/atoms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.207.0",
|
|
4
4
|
"description": "Atomic utilities for making your JavaScript better.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -149,6 +149,13 @@
|
|
|
149
149
|
"types": "./dist/number.d.mts",
|
|
150
150
|
"default": "./dist/number.mjs"
|
|
151
151
|
},
|
|
152
|
+
"./plan": {
|
|
153
|
+
"types": "./dist/plan/index.d.mts",
|
|
154
|
+
"default": "./dist/plan/index.mjs"
|
|
155
|
+
},
|
|
156
|
+
"./plan/models": {
|
|
157
|
+
"default": "./dist/plan/models.mjs"
|
|
158
|
+
},
|
|
152
159
|
"./promise": {
|
|
153
160
|
"types": "./dist/promise/index.d.mts",
|
|
154
161
|
"default": "./dist/promise/index.mjs"
|
|
@@ -162,7 +169,6 @@
|
|
|
162
169
|
"default": "./dist/promise/misc.mjs"
|
|
163
170
|
},
|
|
164
171
|
"./promise/models": {
|
|
165
|
-
"types": "./dist/promise/models.d.mts",
|
|
166
172
|
"default": "./dist/promise/models.mjs"
|
|
167
173
|
},
|
|
168
174
|
"./promise/timed": {
|
|
@@ -198,8 +204,7 @@
|
|
|
198
204
|
"default": "./dist/result/misc.mjs"
|
|
199
205
|
},
|
|
200
206
|
"./result/models": {
|
|
201
|
-
"
|
|
202
|
-
"default": "./dist/internal/result/models.mjs"
|
|
207
|
+
"default": "./dist/internal/models/result.model.mjs"
|
|
203
208
|
},
|
|
204
209
|
"./result/pipe": {
|
|
205
210
|
"types": "./dist/result/work/pipe.d.mts",
|
|
File without changes
|