@oscarpalmer/atoms 0.211.0 → 0.213.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/color/instance.mjs +0 -1
- package/dist/color/models.d.mts +1 -1
- package/dist/herald.d.mts +2 -1
- package/dist/index.d.mts +79 -69
- package/dist/index.mjs +57 -49
- package/dist/internal/herald.d.mts +2 -38
- package/dist/internal/herald.mjs +4 -14
- package/dist/internal/models/herald.model.d.mts +60 -0
- package/dist/internal/models/herald.model.mjs +15 -0
- package/dist/internal/models/plan.model.d.mts +14 -12
- package/dist/internal/string/misc.mjs +0 -1
- package/dist/models.d.mts +3 -3
- package/dist/plan/generate.d.mts +2 -2
- package/dist/plan/generate.mjs +5 -5
- package/dist/plan/index.mjs +1 -1
- package/dist/plan/is.d.mts +31 -2
- package/dist/plan/is.mjs +45 -1
- package/dist/plan/misc.d.mts +21 -2
- package/dist/plan/misc.mjs +32 -2
- package/dist/plan/result.d.mts +6 -6
- package/dist/plan/result.mjs +6 -6
- package/dist/plan/run.d.mts +5 -5
- package/dist/plan/run.mjs +5 -5
- package/dist/promise/models.d.mts +4 -4
- package/dist/result/work/flow.mjs +0 -1
- package/dist/result/work/pipe.mjs +0 -1
- package/dist/value/shake.d.mts +2 -2
- package/package.json +2 -1
- package/dist/internal/plan.d.mts +0 -45
- package/dist/internal/plan.mjs +0 -70
package/dist/color/instance.mjs
CHANGED
package/dist/color/models.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Subscription } from "../internal/subscription.mjs";
|
|
2
|
-
import { Herald, HeraldEvents } from "../internal/herald.mjs";
|
|
2
|
+
import { Herald, HeraldEvents } from "../internal/models/herald.model.mjs";
|
|
3
3
|
import { COLOR_SYMBOL } from "./constants.mjs";
|
|
4
4
|
//#region src/color/models.d.ts
|
|
5
5
|
export type Alpha = {
|
package/dist/herald.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { Herald, HeraldEvents } from "./internal/models/herald.model.mjs";
|
|
1
2
|
import { herald, isHerald, isHeraldEvents, isHeraldSubscription } from "./internal/herald.mjs";
|
|
2
|
-
export { herald, isHerald, isHeraldEvents, isHeraldSubscription };
|
|
3
|
+
export { type Herald, type HeraldEvents, herald, isHerald, isHeraldEvents, isHeraldSubscription };
|
package/dist/index.d.mts
CHANGED
|
@@ -63,7 +63,7 @@ type _NestedValue<Value, Path extends string> = Path extends `${infer ItemKey}.$
|
|
|
63
63
|
/**
|
|
64
64
|
* The nested _(keyed)_ values of an object _(up to 5 levels deep)_
|
|
65
65
|
*/
|
|
66
|
-
export type NestedValues<Value extends PlainObject> = { [Path in NestedKeys<Value>]: NestedValue<Value, Path>; }
|
|
66
|
+
export type NestedValues<Value extends PlainObject> = Simplify<{ [Path in NestedKeys<Value>]: NestedValue<Value, Path>; }>;
|
|
67
67
|
/**
|
|
68
68
|
* The numerical keys of an object
|
|
69
69
|
*/
|
|
@@ -71,7 +71,7 @@ export type NumericalKeys<Value> = { [ItemKey in keyof Value]: ItemKey extends n
|
|
|
71
71
|
/**
|
|
72
72
|
* The numerical values of an object
|
|
73
73
|
*/
|
|
74
|
-
export type NumericalValues<Item extends PlainObject> = { [ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey]; }
|
|
74
|
+
export type NumericalValues<Item extends PlainObject> = Simplify<{ [ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey]; }>;
|
|
75
75
|
/**
|
|
76
76
|
* An asynchronous function that can only be called once, returning the same value on subsequent calls
|
|
77
77
|
*/
|
|
@@ -131,7 +131,7 @@ export type Primitive = null | undefined | string | number | boolean | symbol |
|
|
|
131
131
|
/**
|
|
132
132
|
* Set required keys for a type
|
|
133
133
|
*/
|
|
134
|
-
export type RequiredKeys<Model extends object, Keys extends keyof Model> = Required<Pick<Model, Keys>> & Omit<Model, Keys
|
|
134
|
+
export type RequiredKeys<Model extends object, Keys extends keyof Model> = Simplify<Required<Pick<Model, Keys>> & Omit<Model, Keys>>;
|
|
135
135
|
/**
|
|
136
136
|
* Flattens the type to improve type hints in IDEs
|
|
137
137
|
*
|
|
@@ -4597,22 +4597,22 @@ type AsyncPlan<Yielded, Returned, Parameters extends unknown[]> = {
|
|
|
4597
4597
|
*
|
|
4598
4598
|
* @returns Asynchronous generator
|
|
4599
4599
|
*/
|
|
4600
|
-
[Symbol.asyncIterator]: () => AsyncGenerator<Yielded, Returned
|
|
4600
|
+
[Symbol.asyncIterator]: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>;
|
|
4601
4601
|
/**
|
|
4602
4602
|
* Attempt to run the plan to completion
|
|
4603
4603
|
*
|
|
4604
4604
|
* _Returns a promised {@link Result} instead of a raw value or throwing an error_
|
|
4605
4605
|
*
|
|
4606
|
-
* @returns
|
|
4606
|
+
* @returns Attempted result
|
|
4607
4607
|
*/
|
|
4608
|
-
attempt(...parameters: Parameters): Promise<Result<
|
|
4608
|
+
attempt(...parameters: Parameters): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
4609
4609
|
/**
|
|
4610
4610
|
* Run the plan to completion
|
|
4611
4611
|
*
|
|
4612
4612
|
* @throws {PlanError<Yielded, Returned>}
|
|
4613
4613
|
* @returns Result
|
|
4614
4614
|
*/
|
|
4615
|
-
run(...parameters: Parameters): Promise<
|
|
4615
|
+
run(...parameters: Parameters): Promise<PlanReturned<Returned>>;
|
|
4616
4616
|
};
|
|
4617
4617
|
/**
|
|
4618
4618
|
* A plan of execution that can yield intermediate results and eventually return a result
|
|
@@ -4623,26 +4623,28 @@ type Plan<Yielded, Returned, Parameters extends unknown[]> = {
|
|
|
4623
4623
|
*
|
|
4624
4624
|
* @returns Generator
|
|
4625
4625
|
*/
|
|
4626
|
-
[Symbol.iterator]: () => Generator<Yielded, Returned
|
|
4626
|
+
[Symbol.iterator]: (...parameters: Parameters) => Generator<Yielded, Returned>;
|
|
4627
4627
|
/**
|
|
4628
4628
|
* Attempt to run the plan to completion
|
|
4629
4629
|
*
|
|
4630
4630
|
* _Returns a {@link Result} instead of a raw value or throwing an error_
|
|
4631
4631
|
*
|
|
4632
|
-
* @returns
|
|
4632
|
+
* @returns Attempted result
|
|
4633
4633
|
*/
|
|
4634
|
-
attempt(...parameters: Parameters): Result<
|
|
4634
|
+
attempt(...parameters: Parameters): Result<PlanOk<Returned>, PlanError<Yielded, Returned>>;
|
|
4635
4635
|
/**
|
|
4636
4636
|
* Run the plan to completion
|
|
4637
4637
|
*
|
|
4638
4638
|
* @throws {PlanError<Yielded, Returned>}
|
|
4639
4639
|
* @returns Result
|
|
4640
4640
|
*/
|
|
4641
|
-
run(...parameters: Parameters):
|
|
4641
|
+
run(...parameters: Parameters): PlanReturned<Returned>;
|
|
4642
4642
|
};
|
|
4643
|
-
type
|
|
4644
|
-
type
|
|
4645
|
-
type
|
|
4643
|
+
type PlanOk<Returned> = Returned extends Error ? never : Returned extends Err<infer _> ? never : Returned extends Ok<infer Value> ? Value : Returned;
|
|
4644
|
+
type PlanErrors<Yielded, Returned> = PlanErrorValues<Yielded> | PlanErrorValues<Returned>;
|
|
4645
|
+
type PlanError<Yielded, Returned> = [PlanErrors<Yielded, Returned>] extends [never] ? Error : PlanErrors<Yielded, Returned>;
|
|
4646
|
+
type PlanErrorValues<Original> = Original extends Error ? Original : Original extends Err<infer Error> ? Error : never;
|
|
4647
|
+
type PlanReturned<Returned> = Returned extends Error ? never : Returned extends Err<infer _> ? never : Returned;
|
|
4646
4648
|
//#endregion
|
|
4647
4649
|
//#region src/plan/result.d.ts
|
|
4648
4650
|
/**
|
|
@@ -4652,7 +4654,7 @@ type PlanResult<Returned> = Returned extends Error ? never : Returned extends Er
|
|
|
4652
4654
|
*
|
|
4653
4655
|
* @returns Promised result
|
|
4654
4656
|
*/
|
|
4655
|
-
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned
|
|
4657
|
+
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>, ...parameters: Parameters): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
4656
4658
|
/**
|
|
4657
4659
|
* Attempt to run the plan to completion
|
|
4658
4660
|
*
|
|
@@ -4660,7 +4662,7 @@ export declare function asyncAttemptRun<Yielded, Returned, Parameters extends un
|
|
|
4660
4662
|
*
|
|
4661
4663
|
* @returns Promised result
|
|
4662
4664
|
*/
|
|
4663
|
-
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, ...parameters: Parameters): Promise<Result<
|
|
4665
|
+
export declare function asyncAttemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, ...parameters: Parameters): Promise<Result<PlanOk<Returned>, PlanError<Yielded, Returned>>>;
|
|
4664
4666
|
/**
|
|
4665
4667
|
* Attempt to run the generator to completion
|
|
4666
4668
|
*
|
|
@@ -4668,7 +4670,7 @@ export declare function asyncAttemptRun<Yielded, Returned, Parameters extends un
|
|
|
4668
4670
|
*
|
|
4669
4671
|
* @returns Result
|
|
4670
4672
|
*/
|
|
4671
|
-
export declare function attemptRun<Yielded, Returned>(generator: () => Generator<Yielded, Returned
|
|
4673
|
+
export declare function attemptRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned>, ...parameters: Parameters): Result<PlanOk<Returned>, PlanError<Yielded, Returned>>;
|
|
4672
4674
|
/**
|
|
4673
4675
|
* Attempt to run the plan to completion
|
|
4674
4676
|
*
|
|
@@ -4676,7 +4678,7 @@ export declare function attemptRun<Yielded, Returned>(generator: () => Generator
|
|
|
4676
4678
|
*
|
|
4677
4679
|
* @returns Result
|
|
4678
4680
|
*/
|
|
4679
|
-
export declare function attemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): Result<
|
|
4681
|
+
export declare function attemptRun<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): Result<PlanOk<Returned>, PlanError<Yielded, Returned>>;
|
|
4680
4682
|
export declare namespace attemptRun {
|
|
4681
4683
|
export var async: typeof asyncAttemptRun;
|
|
4682
4684
|
}
|
|
@@ -4688,28 +4690,28 @@ export declare namespace attemptRun {
|
|
|
4688
4690
|
* @param generator Generator to run
|
|
4689
4691
|
* @returns Result
|
|
4690
4692
|
*/
|
|
4691
|
-
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned
|
|
4693
|
+
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => AsyncGenerator<Yielded, Returned>, ...parameters: Parameters): Promise<PlanReturned<Returned>>;
|
|
4692
4694
|
/**
|
|
4693
4695
|
* Run an asynchronous plan to completion
|
|
4694
4696
|
*
|
|
4695
4697
|
* @param plan Plan to run
|
|
4696
4698
|
* @returns Result
|
|
4697
4699
|
*/
|
|
4698
|
-
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, ...parameters: Parameters): Promise<
|
|
4700
|
+
export declare function asyncRun<Yielded, Returned, Parameters extends unknown[]>(plan: AsyncPlan<Yielded, Returned, Parameters>, ...parameters: Parameters): Promise<PlanReturned<Returned>>;
|
|
4699
4701
|
/**
|
|
4700
4702
|
* Run a generator to completion
|
|
4701
4703
|
*
|
|
4702
4704
|
* @param generator Generator to run
|
|
4703
4705
|
* @returns Result
|
|
4704
4706
|
*/
|
|
4705
|
-
export declare function run<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned
|
|
4707
|
+
export declare function run<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned>, ...parameters: Parameters): PlanReturned<Returned>;
|
|
4706
4708
|
/**
|
|
4707
4709
|
* Run a plan to completion
|
|
4708
4710
|
*
|
|
4709
4711
|
* @param plan Plan to run
|
|
4710
4712
|
* @returns Result
|
|
4711
4713
|
*/
|
|
4712
|
-
export declare function run<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters):
|
|
4714
|
+
export declare function run<Yielded, Returned, Parameters extends unknown[]>(plan: Plan<Yielded, Returned, Parameters>, ...parameters: Parameters): PlanReturned<Returned>;
|
|
4713
4715
|
export declare namespace asyncRun {
|
|
4714
4716
|
export var attempt: typeof asyncAttemptRun;
|
|
4715
4717
|
}
|
|
@@ -4734,14 +4736,7 @@ export declare function plan<Yielded, Returned, Parameters extends unknown[]>(ge
|
|
|
4734
4736
|
*/
|
|
4735
4737
|
export declare function plan<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned>): Plan<Yielded, Returned, Parameters>;
|
|
4736
4738
|
//#endregion
|
|
4737
|
-
//#region src/
|
|
4738
|
-
/**
|
|
4739
|
-
* Create an immediately failing generator
|
|
4740
|
-
*
|
|
4741
|
-
* @param reason Failure reason
|
|
4742
|
-
* @returns Failing generator
|
|
4743
|
-
*/
|
|
4744
|
-
export declare function fail<Reason>(reason: Reason): Generator<unknown, never>;
|
|
4739
|
+
//#region src/plan/is.d.ts
|
|
4745
4740
|
/**
|
|
4746
4741
|
* Is the value an asynchronous generator function?
|
|
4747
4742
|
*
|
|
@@ -4770,13 +4765,26 @@ export declare function isGenerator(value: unknown): value is () => Generator;
|
|
|
4770
4765
|
* @returns `true` if the value is a plan, otherwise `false`
|
|
4771
4766
|
*/
|
|
4772
4767
|
export declare function isPlan<Yielded = unknown, Returned = unknown, Parameters extends unknown[] = unknown[]>(value: unknown): value is Plan<Yielded, Returned, Parameters>;
|
|
4768
|
+
//#endregion
|
|
4769
|
+
//#region src/plan/misc.d.ts
|
|
4770
|
+
/**
|
|
4771
|
+
* Create an immediately failing plan
|
|
4772
|
+
*
|
|
4773
|
+
* @param reason Failure reason
|
|
4774
|
+
* @returns Plan failure
|
|
4775
|
+
*/
|
|
4776
|
+
export declare function fail<Reason>(reason: Reason): Generator<Reason, void>;
|
|
4773
4777
|
/**
|
|
4774
|
-
* Create an immediately succeeding
|
|
4778
|
+
* Create an immediately succeeding plan
|
|
4775
4779
|
*
|
|
4776
4780
|
* @param value Success value
|
|
4777
|
-
* @returns
|
|
4781
|
+
* @returns Plan success
|
|
4778
4782
|
*/
|
|
4779
|
-
export declare function succeed<Value>(value: Value): Generator<
|
|
4783
|
+
export declare function succeed<Value>(value: Value): Generator<never, Value>;
|
|
4784
|
+
export declare function succeedResult<Returned>(value: Returned): Generator<never, Ok<Returned>>;
|
|
4785
|
+
export declare namespace succeed {
|
|
4786
|
+
export var result: typeof succeedResult;
|
|
4787
|
+
}
|
|
4780
4788
|
//#endregion
|
|
4781
4789
|
//#region src/internal/aborter.d.ts
|
|
4782
4790
|
type Aborter = {
|
|
@@ -4859,7 +4867,7 @@ export type PromiseStrategy = "complete" | "first";
|
|
|
4859
4867
|
export declare class PromiseTimeoutError extends Error {
|
|
4860
4868
|
constructor();
|
|
4861
4869
|
}
|
|
4862
|
-
export type PromisesItems<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Promise<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Promise<Value> : Promise<Items[ItemsKey]>; };
|
|
4870
|
+
export type PromisesItems<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Promise<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Promise<Value> : Promise<Items[ItemsKey]>; } extends (infer Result) ? Result : never;
|
|
4863
4871
|
/**
|
|
4864
4872
|
* Options for handling multiple _Promises_
|
|
4865
4873
|
*/
|
|
@@ -4874,9 +4882,9 @@ export type PromisesOptions = {
|
|
|
4874
4882
|
strategy?: PromiseStrategy;
|
|
4875
4883
|
};
|
|
4876
4884
|
export type PromisesResult<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? Result<Awaited<Value>> : never; };
|
|
4877
|
-
export type PromisesUnwrapped<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Awaited<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Awaited<Value> : never; };
|
|
4878
|
-
export type PromisesValue<Value> = FulfilledPromise<Value> | RejectedPromise;
|
|
4879
|
-
export type PromisesValues<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never; };
|
|
4885
|
+
export type PromisesUnwrapped<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Awaited<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Awaited<Value> : never; } extends (infer Result) ? Result : never;
|
|
4886
|
+
export type PromisesValue<Value> = (FulfilledPromise<Value> | RejectedPromise);
|
|
4887
|
+
export type PromisesValues<Items extends ArrayOrPlainObject> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never; } extends (infer Result) ? Result : never;
|
|
4880
4888
|
/**
|
|
4881
4889
|
* A _Promise_ that was rejected
|
|
4882
4890
|
*/
|
|
@@ -6350,7 +6358,7 @@ export declare function pick<Value extends PlainObject, ValueKey extends keyof V
|
|
|
6350
6358
|
/**
|
|
6351
6359
|
* A shaken object, without any `undefined` values
|
|
6352
6360
|
*/
|
|
6353
|
-
type Shaken<Value extends PlainObject> = { [Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key]
|
|
6361
|
+
type Shaken<Value extends PlainObject> = Simplify<{ [Key in keyof Value as undefined extends Value[Key] ? never : Key]: Value[Key]; } & { [Key in keyof Value as undefined extends Value[Key] ? [Value[Key]] extends [undefined] ? never : Key : never]?: Exclude<Value[Key], undefined>; }>;
|
|
6354
6362
|
/**
|
|
6355
6363
|
* Shake an object, removing all keys with `undefined` values
|
|
6356
6364
|
*
|
|
@@ -6795,7 +6803,7 @@ export declare function isBeaconSubscription(value: unknown): value is Subscript
|
|
|
6795
6803
|
*/
|
|
6796
6804
|
export declare function isObservable<Value = unknown>(value: unknown): value is Observable<Value>;
|
|
6797
6805
|
//#endregion
|
|
6798
|
-
//#region src/internal/herald.d.ts
|
|
6806
|
+
//#region src/internal/models/herald.model.d.ts
|
|
6799
6807
|
type Herald<Events extends Record<string, GenericCallback>> = {
|
|
6800
6808
|
readonly events: HeraldEvents<Events>;
|
|
6801
6809
|
/**
|
|
@@ -6833,35 +6841,6 @@ type HeraldOptions<Events extends Record<string, GenericCallback>> = {
|
|
|
6833
6841
|
property?: SubscriptionProperty;
|
|
6834
6842
|
onCreate?: HeraldOnCreate<Events>;
|
|
6835
6843
|
};
|
|
6836
|
-
/**
|
|
6837
|
-
* Create a _Herald_ for announcing named events
|
|
6838
|
-
*
|
|
6839
|
-
* @param names Event names
|
|
6840
|
-
* @param property Optional property for subscription identification _(defaults to `$herald`)_
|
|
6841
|
-
* @returns _Herald_ instance
|
|
6842
|
-
*/
|
|
6843
|
-
export declare function herald<Events extends Record<string, GenericCallback>>(options: HeraldOptions<Events>): Herald<Events>;
|
|
6844
|
-
/**
|
|
6845
|
-
* Is the value a herald?
|
|
6846
|
-
*
|
|
6847
|
-
* @param value Value to check
|
|
6848
|
-
* @returns `true` if the value is a herald, otherwise `false`
|
|
6849
|
-
*/
|
|
6850
|
-
export declare function isHerald<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is Herald<Events>;
|
|
6851
|
-
/**
|
|
6852
|
-
* Is the value events for a herald?
|
|
6853
|
-
*
|
|
6854
|
-
* @param value Value to check
|
|
6855
|
-
* @returns `true` if the value is events for a herald, otherwise `false`
|
|
6856
|
-
*/
|
|
6857
|
-
export declare function isHeraldEvents<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is HeraldEvents<Events>;
|
|
6858
|
-
/**
|
|
6859
|
-
* Is the value a herald subscription?
|
|
6860
|
-
*
|
|
6861
|
-
* @param value Value to check
|
|
6862
|
-
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
6863
|
-
*/
|
|
6864
|
-
export declare function isHeraldSubscription(value: unknown): value is Subscription;
|
|
6865
6844
|
//#endregion
|
|
6866
6845
|
//#region src/color/models.d.ts
|
|
6867
6846
|
/**
|
|
@@ -7539,6 +7518,37 @@ export declare function rgbToHwba(rgb: RGBAColor | RGBColor): HWBAColor;
|
|
|
7539
7518
|
*/
|
|
7540
7519
|
export declare function getColor(value: unknown): Color;
|
|
7541
7520
|
//#endregion
|
|
7521
|
+
//#region src/internal/herald.d.ts
|
|
7522
|
+
/**
|
|
7523
|
+
* Create a _Herald_ for announcing named events
|
|
7524
|
+
*
|
|
7525
|
+
* @param names Event names
|
|
7526
|
+
* @param property Optional property for subscription identification _(defaults to `$herald`)_
|
|
7527
|
+
* @returns _Herald_ instance
|
|
7528
|
+
*/
|
|
7529
|
+
export declare function herald<Events extends Record<string, GenericCallback>>(options: HeraldOptions<Events>): Herald<Events>;
|
|
7530
|
+
/**
|
|
7531
|
+
* Is the value a herald?
|
|
7532
|
+
*
|
|
7533
|
+
* @param value Value to check
|
|
7534
|
+
* @returns `true` if the value is a herald, otherwise `false`
|
|
7535
|
+
*/
|
|
7536
|
+
export declare function isHerald<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is Herald<Events>;
|
|
7537
|
+
/**
|
|
7538
|
+
* Is the value events for a herald?
|
|
7539
|
+
*
|
|
7540
|
+
* @param value Value to check
|
|
7541
|
+
* @returns `true` if the value is events for a herald, otherwise `false`
|
|
7542
|
+
*/
|
|
7543
|
+
export declare function isHeraldEvents<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is HeraldEvents<Events>;
|
|
7544
|
+
/**
|
|
7545
|
+
* Is the value a herald subscription?
|
|
7546
|
+
*
|
|
7547
|
+
* @param value Value to check
|
|
7548
|
+
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
7549
|
+
*/
|
|
7550
|
+
export declare function isHeraldSubscription(value: unknown): value is Subscription;
|
|
7551
|
+
//#endregion
|
|
7542
7552
|
//#region src/internal/is.d.ts
|
|
7543
7553
|
/**
|
|
7544
7554
|
* Is the value an array or a plain object?
|
|
@@ -8508,4 +8518,4 @@ export declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
8508
8518
|
get(value: Value, update?: boolean): Value | undefined;
|
|
8509
8519
|
}
|
|
8510
8520
|
//#endregion
|
|
8511
|
-
export { type AsyncLimiter, type AsyncPlan, 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 };
|
|
8521
|
+
export { type AsyncLimiter, type AsyncPlan, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, type Herald, type HeraldEvents, 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
|
@@ -2756,19 +2756,7 @@ const PLAN_SYMBOL = Symbol("plan");
|
|
|
2756
2756
|
const PLAN_TYPE_PLAN_ASYNC = "asyncPlan";
|
|
2757
2757
|
const PLAN_TYPE_PLAN_SYNC = "plan";
|
|
2758
2758
|
//#endregion
|
|
2759
|
-
//#region src/
|
|
2760
|
-
/**
|
|
2761
|
-
* Create an immediately failing generator
|
|
2762
|
-
*
|
|
2763
|
-
* @param reason Failure reason
|
|
2764
|
-
* @returns Failing generator
|
|
2765
|
-
*/
|
|
2766
|
-
function fail(reason) {
|
|
2767
|
-
return (function* () {
|
|
2768
|
-
yield;
|
|
2769
|
-
throw reason;
|
|
2770
|
-
})();
|
|
2771
|
-
}
|
|
2759
|
+
//#region src/plan/is.ts
|
|
2772
2760
|
/**
|
|
2773
2761
|
* Is the value an asynchronous generator function?
|
|
2774
2762
|
*
|
|
@@ -2811,21 +2799,9 @@ function isPlan(value) {
|
|
|
2811
2799
|
function isPlanInstance(type, value) {
|
|
2812
2800
|
return typeof value === "object" && value !== null && PLAN_SYMBOL in value && value[PLAN_SYMBOL].type === type;
|
|
2813
2801
|
}
|
|
2814
|
-
/**
|
|
2815
|
-
* Create an immediately succeeding generator
|
|
2816
|
-
*
|
|
2817
|
-
* @param value Success value
|
|
2818
|
-
* @returns Succeeding generator
|
|
2819
|
-
*/
|
|
2820
|
-
function succeed(value) {
|
|
2821
|
-
return (function* () {
|
|
2822
|
-
yield;
|
|
2823
|
-
return value;
|
|
2824
|
-
})();
|
|
2825
|
-
}
|
|
2826
2802
|
//#endregion
|
|
2827
2803
|
//#region src/plan/generate.ts
|
|
2828
|
-
async function asyncGenerate(callback, parameters) {
|
|
2804
|
+
async function asyncGenerate(callback, parameters, unwrap) {
|
|
2829
2805
|
const generator = callback(...parameters);
|
|
2830
2806
|
let success = true;
|
|
2831
2807
|
let lastValue;
|
|
@@ -2845,10 +2821,10 @@ async function asyncGenerate(callback, parameters) {
|
|
|
2845
2821
|
} finally {
|
|
2846
2822
|
await generator?.return(lastValue);
|
|
2847
2823
|
}
|
|
2848
|
-
if (success) return lastValue;
|
|
2824
|
+
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
2849
2825
|
throw lastValue;
|
|
2850
2826
|
}
|
|
2851
|
-
function generate(callback, parameters) {
|
|
2827
|
+
function generate(callback, parameters, unwrap) {
|
|
2852
2828
|
const generator = callback(...parameters);
|
|
2853
2829
|
let success = true;
|
|
2854
2830
|
let lastValue;
|
|
@@ -2868,45 +2844,45 @@ function generate(callback, parameters) {
|
|
|
2868
2844
|
} finally {
|
|
2869
2845
|
generator.return(lastValue);
|
|
2870
2846
|
}
|
|
2871
|
-
if (success) return lastValue;
|
|
2847
|
+
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
2872
2848
|
throw lastValue;
|
|
2873
2849
|
}
|
|
2874
2850
|
//#endregion
|
|
2875
2851
|
//#region src/plan/result.ts
|
|
2876
2852
|
function asyncAttemptRun(input, ...parameters) {
|
|
2877
2853
|
if (isAsyncPlan(input)) return input.attempt(...parameters);
|
|
2878
|
-
if (isAsyncGenerator(input)) return asyncAttempt(() => asyncGenerate(input, parameters));
|
|
2854
|
+
if (isAsyncGenerator(input)) return asyncAttempt(() => asyncGenerate(input, parameters, true));
|
|
2879
2855
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2880
2856
|
}
|
|
2881
2857
|
function attemptRun(input, ...parameters) {
|
|
2882
2858
|
if (isPlan(input)) return input.attempt(...parameters);
|
|
2883
|
-
if (isGenerator(input)) return attempt(() => generate(input, parameters));
|
|
2859
|
+
if (isGenerator(input)) return attempt(() => generate(input, parameters, true));
|
|
2884
2860
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2885
2861
|
}
|
|
2886
2862
|
function attemptRunAsyncPlan(...parameters) {
|
|
2887
|
-
return asyncAttempt(() => this.
|
|
2863
|
+
return asyncAttempt(() => asyncGenerate(this[PLAN_SYMBOL].generator, parameters, true));
|
|
2888
2864
|
}
|
|
2889
2865
|
function attemptRunPlan(...parameters) {
|
|
2890
|
-
return attempt(() => this.
|
|
2866
|
+
return attempt(() => generate(this[PLAN_SYMBOL].generator, parameters, true));
|
|
2891
2867
|
}
|
|
2892
2868
|
attemptRun.async = asyncAttemptRun;
|
|
2893
2869
|
//#endregion
|
|
2894
2870
|
//#region src/plan/run.ts
|
|
2895
2871
|
function asyncRun(input, ...parameters) {
|
|
2896
2872
|
if (isAsyncPlan(input)) return input.run(...parameters);
|
|
2897
|
-
if (isAsyncGenerator(input)) return asyncGenerate(input, parameters);
|
|
2873
|
+
if (isAsyncGenerator(input)) return asyncGenerate(input, parameters, false);
|
|
2898
2874
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2899
2875
|
}
|
|
2900
2876
|
function run(input, ...parameters) {
|
|
2901
2877
|
if (isPlan(input)) return input.run(...parameters);
|
|
2902
|
-
if (isGenerator(input)) return generate(input, parameters);
|
|
2878
|
+
if (isGenerator(input)) return generate(input, parameters, false);
|
|
2903
2879
|
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2904
2880
|
}
|
|
2905
2881
|
function runAsyncPlan(...parameters) {
|
|
2906
|
-
return asyncGenerate(this[PLAN_SYMBOL].generator, parameters);
|
|
2882
|
+
return asyncGenerate(this[PLAN_SYMBOL].generator, parameters, false);
|
|
2907
2883
|
}
|
|
2908
2884
|
function runPlan(...parameters) {
|
|
2909
|
-
return generate(this[PLAN_SYMBOL].generator, parameters);
|
|
2885
|
+
return generate(this[PLAN_SYMBOL].generator, parameters, false);
|
|
2910
2886
|
}
|
|
2911
2887
|
asyncRun.attempt = asyncAttemptRun;
|
|
2912
2888
|
run.async = asyncRun;
|
|
@@ -2941,6 +2917,36 @@ function plan(generator) {
|
|
|
2941
2917
|
throw new Error(PLAN_MESSAGE_PLAN_INPUT);
|
|
2942
2918
|
}
|
|
2943
2919
|
//#endregion
|
|
2920
|
+
//#region src/plan/misc.ts
|
|
2921
|
+
/**
|
|
2922
|
+
* Create an immediately failing plan
|
|
2923
|
+
*
|
|
2924
|
+
* @param reason Failure reason
|
|
2925
|
+
* @returns Plan failure
|
|
2926
|
+
*/
|
|
2927
|
+
function fail(reason) {
|
|
2928
|
+
return (function* () {
|
|
2929
|
+
throw reason;
|
|
2930
|
+
})();
|
|
2931
|
+
}
|
|
2932
|
+
/**
|
|
2933
|
+
* Create an immediately succeeding plan
|
|
2934
|
+
*
|
|
2935
|
+
* @param value Success value
|
|
2936
|
+
* @returns Plan success
|
|
2937
|
+
*/
|
|
2938
|
+
function succeed(value) {
|
|
2939
|
+
return (function* () {
|
|
2940
|
+
return value;
|
|
2941
|
+
})();
|
|
2942
|
+
}
|
|
2943
|
+
function succeedResult(value) {
|
|
2944
|
+
return (function* () {
|
|
2945
|
+
return ok(value);
|
|
2946
|
+
})();
|
|
2947
|
+
}
|
|
2948
|
+
succeed.result = succeedResult;
|
|
2949
|
+
//#endregion
|
|
2944
2950
|
//#region src/internal/aborter.ts
|
|
2945
2951
|
function createAborter(value, onAbort) {
|
|
2946
2952
|
if (!(value instanceof AbortSignal)) return;
|
|
@@ -4847,10 +4853,20 @@ const beaconSubscription = {
|
|
|
4847
4853
|
value: SUBSCRIPTION_NAME
|
|
4848
4854
|
};
|
|
4849
4855
|
//#endregion
|
|
4850
|
-
//#region src/internal/herald.ts
|
|
4856
|
+
//#region src/internal/models/herald.model.ts
|
|
4857
|
+
const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
4858
|
+
const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
|
|
4859
|
+
const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
|
|
4851
4860
|
const HERALD_NAME_EVENTS = "events";
|
|
4852
4861
|
const HERALD_NAME_HERALD = "herald";
|
|
4853
4862
|
const HERALD_PROPERTY = "$herald";
|
|
4863
|
+
const HERALD_SYMBOL = Symbol(HERALD_PROPERTY);
|
|
4864
|
+
const heraldSubscription = {
|
|
4865
|
+
key: HERALD_PROPERTY,
|
|
4866
|
+
value: SUBSCRIPTION_NAME
|
|
4867
|
+
};
|
|
4868
|
+
//#endregion
|
|
4869
|
+
//#region src/internal/herald.ts
|
|
4854
4870
|
function Events(herald, state) {
|
|
4855
4871
|
for (const key of state.keys) Object.defineProperty(this, key, { value: (callback, signal) => herald.subscribe(key, callback, signal) });
|
|
4856
4872
|
}
|
|
@@ -4937,7 +4953,7 @@ function isHeraldEvents(value) {
|
|
|
4937
4953
|
return isHeraldInstance(HERALD_NAME_EVENTS, value);
|
|
4938
4954
|
}
|
|
4939
4955
|
function isHeraldInstance(name, value) {
|
|
4940
|
-
return typeof value === "object" && value !== null &&
|
|
4956
|
+
return typeof value === "object" && value !== null && "$herald" in value && value["$herald"] === name;
|
|
4941
4957
|
}
|
|
4942
4958
|
/**
|
|
4943
4959
|
* Is the value a herald subscription?
|
|
@@ -4946,7 +4962,7 @@ function isHeraldInstance(name, value) {
|
|
|
4946
4962
|
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
4947
4963
|
*/
|
|
4948
4964
|
function isHeraldSubscription(value) {
|
|
4949
|
-
return isSubscription(value) &&
|
|
4965
|
+
return isSubscription(value) && "$herald" in value && value["$herald"] === "subscription";
|
|
4950
4966
|
}
|
|
4951
4967
|
function subscribeToHerald(key, callback, signal) {
|
|
4952
4968
|
const { state } = this[HERALD_SYMBOL];
|
|
@@ -4958,14 +4974,6 @@ function subscribeToHerald(key, callback, signal) {
|
|
|
4958
4974
|
if (!existing) state.onCreate?.(key, callback, subscription);
|
|
4959
4975
|
return subscription;
|
|
4960
4976
|
}
|
|
4961
|
-
const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
4962
|
-
const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
|
|
4963
|
-
const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
|
|
4964
|
-
const HERALD_SYMBOL = Symbol(HERALD_PROPERTY);
|
|
4965
|
-
const heraldSubscription = {
|
|
4966
|
-
key: HERALD_PROPERTY,
|
|
4967
|
-
value: SUBSCRIPTION_NAME
|
|
4968
|
-
};
|
|
4969
4977
|
//#endregion
|
|
4970
4978
|
//#region src/color/constants.ts
|
|
4971
4979
|
const COLOR_ALPHA = {
|
|
@@ -7041,4 +7049,4 @@ var SizedSet = class extends Set {
|
|
|
7041
7049
|
}
|
|
7042
7050
|
};
|
|
7043
7051
|
//#endregion
|
|
7044
|
-
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, asyncAttemptRun, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncRun, asyncThrottle, 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, 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, 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 };
|
|
7052
|
+
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, asyncAttemptRun, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncRun, asyncThrottle, 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, 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, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, succeed, succeedResult, 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,43 +1,7 @@
|
|
|
1
1
|
import { GenericCallback } from "../models.mjs";
|
|
2
|
-
import { Subscription
|
|
2
|
+
import { Subscription } from "./subscription.mjs";
|
|
3
|
+
import { Herald, HeraldEvents, HeraldOptions } from "./models/herald.model.mjs";
|
|
3
4
|
//#region src/internal/herald.d.ts
|
|
4
|
-
export type Herald<Events extends Record<string, GenericCallback>> = {
|
|
5
|
-
readonly events: HeraldEvents<Events>;
|
|
6
|
-
/**
|
|
7
|
-
* Remove all event subscribers
|
|
8
|
-
*/
|
|
9
|
-
clear(): void;
|
|
10
|
-
/**
|
|
11
|
-
* Emit an event with parameters
|
|
12
|
-
*
|
|
13
|
-
* @param event Event name
|
|
14
|
-
* @param parameters Event parameters
|
|
15
|
-
*/
|
|
16
|
-
emit<Event extends keyof Events>(event: Event, ...parameters: Parameters<Events[Event]>): void;
|
|
17
|
-
/**
|
|
18
|
-
* Is the event observed by any subscribers?
|
|
19
|
-
*
|
|
20
|
-
* @param event Event name
|
|
21
|
-
* @returns `true` if the event is observed, otherwise `false`
|
|
22
|
-
*/
|
|
23
|
-
observed<Event extends keyof Events>(event: Event): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Subscribe to an event with a callback
|
|
26
|
-
*
|
|
27
|
-
* @param event Event name
|
|
28
|
-
* @param callback Callback function
|
|
29
|
-
* @param signal Optional abort signal to cancel the subscription
|
|
30
|
-
* @returns Subscription instance
|
|
31
|
-
*/
|
|
32
|
-
subscribe<Event extends keyof Events>(event: Event, callback: Events[Event], signal?: AbortSignal): Subscription;
|
|
33
|
-
};
|
|
34
|
-
export type HeraldEvents<Events extends Record<string, GenericCallback>> = { [Key in keyof Events]: Key extends "*" ? never : (callback: Events[Key], signal?: AbortSignal) => void; };
|
|
35
|
-
type HeraldOnCreate<Events extends Record<string, GenericCallback>> = <Event extends keyof Events>(event: Event, callback: Events[Event], subscription: Subscription) => void;
|
|
36
|
-
export type HeraldOptions<Events extends Record<string, GenericCallback>> = {
|
|
37
|
-
names: Array<keyof Events>;
|
|
38
|
-
property?: SubscriptionProperty;
|
|
39
|
-
onCreate?: HeraldOnCreate<Events>;
|
|
40
|
-
};
|
|
41
5
|
/**
|
|
42
6
|
* Create a _Herald_ for announcing named events
|
|
43
7
|
*
|
package/dist/internal/herald.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { isPlainObject } from "./is.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { isSubscription, subscriptions } from "./subscription.mjs";
|
|
3
|
+
import { HERALD_MESSAGE_ARRAY, HERALD_MESSAGE_ONCREATE, HERALD_MESSAGE_PROPERTY, HERALD_NAME_EVENTS, HERALD_NAME_HERALD, HERALD_PROPERTY, HERALD_SYMBOL, heraldSubscription } from "./models/herald.model.mjs";
|
|
3
4
|
//#region src/internal/herald.ts
|
|
4
|
-
const HERALD_NAME_EVENTS = "events";
|
|
5
|
-
const HERALD_NAME_HERALD = "herald";
|
|
6
|
-
const HERALD_PROPERTY = "$herald";
|
|
7
5
|
function Events(herald, state) {
|
|
8
6
|
for (const key of state.keys) Object.defineProperty(this, key, { value: (callback, signal) => herald.subscribe(key, callback, signal) });
|
|
9
7
|
}
|
|
@@ -91,7 +89,7 @@ function isHeraldEvents(value) {
|
|
|
91
89
|
return isHeraldInstance(HERALD_NAME_EVENTS, value);
|
|
92
90
|
}
|
|
93
91
|
function isHeraldInstance(name, value) {
|
|
94
|
-
return typeof value === "object" && value !== null &&
|
|
92
|
+
return typeof value === "object" && value !== null && "$herald" in value && value["$herald"] === name;
|
|
95
93
|
}
|
|
96
94
|
/**
|
|
97
95
|
* Is the value a herald subscription?
|
|
@@ -100,7 +98,7 @@ function isHeraldInstance(name, value) {
|
|
|
100
98
|
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
101
99
|
*/
|
|
102
100
|
function isHeraldSubscription(value) {
|
|
103
|
-
return isSubscription(value) &&
|
|
101
|
+
return isSubscription(value) && "$herald" in value && value["$herald"] === "subscription";
|
|
104
102
|
}
|
|
105
103
|
function subscribeToHerald(key, callback, signal) {
|
|
106
104
|
const { state } = this[HERALD_SYMBOL];
|
|
@@ -112,13 +110,5 @@ function subscribeToHerald(key, callback, signal) {
|
|
|
112
110
|
if (!existing) state.onCreate?.(key, callback, subscription);
|
|
113
111
|
return subscription;
|
|
114
112
|
}
|
|
115
|
-
const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
116
|
-
const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
|
|
117
|
-
const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
|
|
118
|
-
const HERALD_SYMBOL = Symbol(HERALD_PROPERTY);
|
|
119
|
-
const heraldSubscription = {
|
|
120
|
-
key: HERALD_PROPERTY,
|
|
121
|
-
value: SUBSCRIPTION_NAME
|
|
122
|
-
};
|
|
123
113
|
//#endregion
|
|
124
114
|
export { herald, isHerald, isHeraldEvents, isHeraldSubscription };
|