@avstantso/concepts 1.1.0 → 1.2.2

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/_global/async-tasks.d.ts +134 -0
  3. package/dist/_global/classic-enum.d.ts +29 -0
  4. package/dist/_global/compare/_register.d.ts +32 -0
  5. package/dist/_global/compare/combination.d.ts +41 -0
  6. package/dist/_global/compare/compare.d.ts +39 -0
  7. package/dist/_global/compare/index.d.ts +4 -0
  8. package/dist/_global/compare/structures.d.ts +10 -0
  9. package/dist/_global/conveyor.d.ts +18 -0
  10. package/dist/_global/equality/_register.d.ts +35 -0
  11. package/dist/_global/equality/equality.d.ts +32 -0
  12. package/dist/_global/equality/index.d.ts +2 -0
  13. package/dist/_global/extend/_register.d.ts +76 -0
  14. package/dist/_global/extend/index.d.ts +1 -0
  15. package/dist/_global/index.d.ts +15 -0
  16. package/dist/_global/mapping/_register.d.ts +59 -0
  17. package/dist/_global/mapping/index.d.ts +2 -0
  18. package/dist/_global/mapping/mapping.d.ts +138 -0
  19. package/dist/_global/mock.d.ts +11 -0
  20. package/dist/_global/override.d.ts +50 -0
  21. package/dist/_global/perform/_register.d.ts +107 -0
  22. package/dist/_global/perform/index.d.ts +1 -0
  23. package/dist/_global/provider/_register.d.ts +16 -0
  24. package/dist/_global/provider/combination.d.ts +96 -0
  25. package/dist/_global/provider/compare.d.ts +47 -0
  26. package/dist/_global/provider/extract.d.ts +36 -0
  27. package/dist/_global/provider/force.d.ts +35 -0
  28. package/dist/_global/provider/index.d.ts +10 -0
  29. package/dist/_global/provider/is.d.ts +38 -0
  30. package/dist/_global/provider/provider.d.ts +85 -0
  31. package/dist/_global/provider/strict.d.ts +29 -0
  32. package/dist/_global/provider/union.d.ts +29 -0
  33. package/dist/_global/provider/value.d.ts +26 -0
  34. package/dist/_global/stub.d.ts +40 -0
  35. package/dist/_global/switch/_register.d.ts +45 -0
  36. package/dist/_global/switch/index.d.ts +2 -0
  37. package/dist/_global/switch/switch.d.ts +13 -0
  38. package/dist/_global/transition.d.ts +62 -0
  39. package/dist/_global/value-wrap.d.ts +12 -0
  40. package/dist/_std-ext/abort-controller.d.ts +7 -0
  41. package/dist/_std-ext/index.d.ts +1 -0
  42. package/dist/export.d.ts +16 -0
  43. package/dist/index.d.ts +5 -0
  44. package/dist/index.js +699 -0
  45. package/dist/index.js.map +1 -0
  46. package/package.json +6 -6
@@ -0,0 +1,85 @@
1
+ declare namespace AVStantso {
2
+ /**
3
+ * @summary `Provider` metadata of key
4
+ * @template K Key
5
+ */
6
+ export type ProviderMeta<K extends TS.Key = TS.Key> = {
7
+ __KEY__?: K;
8
+ };
9
+ type _Provider<K extends TS.Key, V> = ProviderMeta<K> & Record<K, V>;
10
+ /**
11
+ * @summary Create structural type with specified field and value.\
12
+ * Add optional metadata field `__KEY__`
13
+ * @template F First param
14
+ * @template S Second param
15
+ * @returns
16
+ * • If `F` is `TS.Key` — `S` will be interpret as value ⇒ `{[F]:TS.Resolve<S>}`
17
+ *
18
+ * • If `F` is `TS.Type.KLD` — `S` will be ignored ⇒ `{[F[0]]:TS.Resolve<F[1]>}`
19
+ *
20
+ * • If `F` is other array ⇒ `never`
21
+ *
22
+ * • If `F` is `TS.Type.KeyDef` — `S` will be ignored ⇒ `{[F['K']]:TS.Resolve<F>}`
23
+ *
24
+ * • If `F` is other object — `S` will be interpret as `keyof F` ⇒ `Peek<F,S>` or `never` if `S` is bad key
25
+ * @example
26
+ * type R = { id: string; };
27
+ *
28
+ * type key_value = CheckType<Provider<'id', string>, R>;
29
+ *
30
+ * type bad_array = CheckType<Provider<[1, 2, 3, 4]>, never>;
31
+ * type good_array = CheckType<Provider<['id', 'string']>, R>;
32
+ *
33
+ * type keydef_l = CheckType<Provider<{ K: 'id'; L: 'string' }>, R>;
34
+ * type keydef_t = CheckType<Provider<{ K: 'id'; T: string }>, R>;
35
+ *
36
+ * type Obj = { id: string; name: string; active?: boolean };
37
+ *
38
+ * type bad_obj_field = CheckType<Provider<Obj, 'id1'>, never>;
39
+ * type good_obj_field = CheckType<Provider<Obj, 'id'>, R>;
40
+ */
41
+ export type Provider<F extends Provider.First, S = undefined> = F extends TS.Key ? {
42
+ [K in keyof _Provider<F, TS.Resolve<S>>]: _Provider<F, TS.Resolve<S>>[K];
43
+ } : F extends object ? F extends TS.ArrR ? F extends TS.Type.KLD<infer K, infer L> ? Provider<K, L> : never : F extends TS.Type.KeyDef ? Provider<F['K'], F> : S extends keyof F ? Provider<S, F[S]> : never : never;
44
+ export namespace Provider {
45
+ /**
46
+ * @summary `Provider` metadata of key
47
+ * @template K Key
48
+ */
49
+ type Meta<K extends TS.Key = TS.Key> = ProviderMeta<K>;
50
+ /**
51
+ * @summary `Provider` of metadata or `never`
52
+ * @template T Tested type
53
+ * @example
54
+ * type p = Provider<'id', string>;
55
+ *
56
+ * type provider = CheckType<Of<p>, p>;
57
+ * type not_provider = CheckType<Of<{ id: string; }>, never>;
58
+ */
59
+ type Of<T> = T extends ProviderMeta<infer K> ? T extends Record<K, unknown> ? T : never : never;
60
+ /**
61
+ * @summary `Provider` `F` type parameter constraint
62
+ */
63
+ type First = object | TS.Key;
64
+ /**
65
+ * @summary Constraint for type parameter extends `Provider`
66
+ */
67
+ type Constraint = ProviderMeta;
68
+ /**
69
+ * @summary Array of constraints for type parameter extends `Provider`
70
+ */
71
+ type Constraints = readonly Constraint[];
72
+ /**
73
+ * @summary Dry provider without `__KEY__` and extended fields
74
+ * @example(@Provider.Dry)
75
+ */
76
+ type Dry<P extends Constraint> = {
77
+ [K in globalThis.Extract<P[__KEY__], keyof P>]: P[K];
78
+ };
79
+ namespace Of {
80
+ }
81
+ namespace Dry {
82
+ }
83
+ }
84
+ export {};
85
+ }
@@ -0,0 +1,29 @@
1
+ declare namespace AVStantso.Provider {
2
+ /**
3
+ * @summary Stricted `Provider` constructors
4
+ */
5
+ namespace Strict {
6
+ /**
7
+ * @summary Create `Provider` by key `K` and value `V`
8
+ */
9
+ type KeyValue<K extends TS.Key, V> = Provider<K, V>;
10
+ /**
11
+ * @summary Create `Provider` by `TS.Type.KLD`
12
+ */
13
+ type KLD<A extends TS.Type.KLD> = Provider<A>;
14
+ /**
15
+ * @summary Create `Provider` by `TS.Type.KeyDef`
16
+ */
17
+ type KeyDef<KD extends TS.Type.KeyDef> = Provider<KD>;
18
+ /**
19
+ * @summary Create `Provider` by structure `O` and strict key `K`
20
+ */
21
+ type Structure<O extends object, K extends keyof O> = Provider<O, K>;
22
+ namespace Structure {
23
+ /**
24
+ * @summary Create `Provider` by structure `O` and NOT strict key `K`
25
+ */
26
+ type Raw<O extends object, K extends TS.Key> = Provider<O, K>;
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,29 @@
1
+ declare namespace AVStantso.Provider {
2
+ /**
3
+ * @summary Union: `Provider | Value<Provider>`
4
+ * @template P `Provider` (expected)
5
+ * @returns Union or `never`, if `P` is NOT a `Provider`
6
+ * @see Provider type
7
+ * @example
8
+ * type u_key_value = CheckType<Union<Provider<'id', string>>, string | { id: string; }>;
9
+ *
10
+ * //@ts-expect-error Type '{ id: string; }' has no properties in common with type 'Constraint'.
11
+ * type not_provider = CheckType<Union<{ id: string }>, never>;
12
+ */
13
+ type Union<P extends Provider.Constraint> = {
14
+ [K in keyof P as K extends __KEY__ ? never : K]: P[K];
15
+ } | P[Exclude<keyof P, __KEY__>];
16
+ namespace Union {
17
+ /**
18
+ * @summary Make union `Provider | Value<Provider>` from `Provider` params
19
+ * @template F First `Provider` param
20
+ * @template S Second `Provider` param
21
+ * @see Provider type
22
+ * @example
23
+ * type u_key_value = CheckType<Union.Make<'id', string>, string | { id: string; }>;
24
+ * type u_kld = CheckType<Union.Make<['id', 'string']>, string | { id: string; }>;
25
+ * type u_obj = CheckType<Union.Make<{ id: string; x: null; }, 'id'>, string | { id: string; }>;
26
+ */
27
+ type Make<F extends First, S = undefined> = Union<Provider<F, S>>;
28
+ }
29
+ }
@@ -0,0 +1,26 @@
1
+ declare namespace AVStantso.Provider {
2
+ /**
3
+ * @summary Value from `Provider.Union`
4
+ * @template U `Provider.Union`
5
+ * @template P `Provider`
6
+ * @returns Value from `U`
7
+ * @see Provider type
8
+ * @example
9
+ * type p = Provider<'id', string>;
10
+ * type v_key_value_u1 = CheckType<Value<'abc', p>, 'abc'>;
11
+ * type v_key_value_u2 = CheckType<Value<{ id: 'defg' }, p>, 'defg'>;
12
+ */
13
+ type Value<U extends Union<P>, P extends Constraint> = U extends Record<P[__KEY__], infer V> ? V : U;
14
+ namespace Value {
15
+ /**
16
+ * @summary Make value from `Provider.Union` created by `Provider` params
17
+ * @template U `Union` for extract value
18
+ * @template F First `Provider` param
19
+ * @template S Second `Provider` param
20
+ * @see Provider type
21
+ * @example
22
+ * type u_key_value = CheckType<Value.Make<{ id: 'abc' }, 'id', string>, 'abc'>;
23
+ */
24
+ type Make<U extends Union<Provider<F, S>>, F extends First, S = unknown> = Value<U, Provider<F, S>>;
25
+ }
26
+ }
@@ -0,0 +1,40 @@
1
+ declare namespace AVStantso {
2
+ /**
3
+ * @summary Stub functions to prevent call undefined
4
+ */
5
+ namespace Stub {
6
+ /**
7
+ * @summary Stub function to prevent call undefined
8
+ * @param func Original function for call
9
+ * @returns func or stub
10
+ */
11
+ type One = <TFunc extends Function>(func: TFunc) => TFunc;
12
+ /**
13
+ * @summary Stub functions to prevent call undefined
14
+ * @param funcs Original functions for call
15
+ * @returns (func or stub)[]
16
+ */
17
+ type Multiple = <TFuncs extends Function[]>(...funcs: TFuncs) => TFuncs;
18
+ }
19
+ namespace Code {
20
+ namespace Stub {
21
+ type Overload = AVStantso.Stub.One & AVStantso.Stub.Multiple;
22
+ }
23
+ /**
24
+ * @summary Stub functions to prevent call undefined
25
+ */
26
+ interface Stub extends Stub.Overload {
27
+ /**
28
+ * @summary Stub by custom function
29
+ */
30
+ Custom(stub: AVStantso.Stub.One): Stub.Overload;
31
+ }
32
+ }
33
+ interface Code {
34
+ /**
35
+ * @summary Stub functions to prevent call undefined
36
+ */
37
+ Stub: Code.Stub;
38
+ }
39
+ const Stub: Code.Stub;
40
+ }
@@ -0,0 +1,45 @@
1
+ declare namespace AVStantso {
2
+ namespace Code {
3
+ /**
4
+ * @summary Switch helpers utility
5
+ */
6
+ namespace Switch {
7
+ /**
8
+ * @summary Switch factory overload
9
+ */
10
+ interface Overload<TKey extends AVStantso.TS.Key, TOptions extends AVStantso.Switch.Options & {
11
+ Value?: unknown;
12
+ } = {}> {
13
+ /**
14
+ * @summary Switch method. `value` first
15
+ */
16
+ <TCase, TKnownCases extends {} = Record<TKey, TCase>>(value: TOptions['Value'], cases: AVStantso.Switch.Cases<TKey, TOptions & {
17
+ Case: TCase;
18
+ KnownCases: TKnownCases;
19
+ }>): TCase;
20
+ /**
21
+ * @summary Switch method. `cases` first
22
+ */
23
+ reversed<TCase, TKnownCases extends {} = Record<TKey, TCase>>(cases: AVStantso.Switch.Cases<TKey, TOptions & {
24
+ Case: TCase;
25
+ KnownCases: TKnownCases;
26
+ }>, value: TOptions['Value']): TCase;
27
+ }
28
+ }
29
+ /**
30
+ * @summary Switch helpers utility
31
+ */
32
+ interface Switch {
33
+ <TKey extends AVStantso.TS.Key, TOptions extends AVStantso.Switch.Options & {
34
+ Value?: unknown;
35
+ } = {}>(getKey: (value: TOptions['Value']) => TKey | string): Switch.Overload<TKey, TOptions>;
36
+ }
37
+ }
38
+ interface Code {
39
+ /**
40
+ * @summary Switch helpers utility
41
+ */
42
+ Switch: Code.Switch;
43
+ }
44
+ const Switch: Code.Switch;
45
+ }
@@ -0,0 +1,2 @@
1
+ import './_register';
2
+ import './switch';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @summary Switch case by key of value or default
3
+ */
4
+ declare namespace AVStantso.Switch {
5
+ export type StdKeys = 'undefined' | 'null' | 'default';
6
+ export type Options = {
7
+ Case?: unknown;
8
+ KnownCases?: unknown;
9
+ };
10
+ type _Cases<TKey extends TS.Key, TOptions extends Options, Case = TOptions['Case'], KnownCases = TS.IfNotOverrided<Options['KnownCases'], TOptions['KnownCases'], Record<TKey, Case>>> = Partial<KnownCases & Record<StdKeys, Case>>;
11
+ export type Cases<TKey extends TS.Key, TOptions extends Options = {}> = _Cases<TKey, TOptions>;
12
+ export {};
13
+ }
@@ -0,0 +1,62 @@
1
+ declare namespace AVStantso {
2
+ /**
3
+ * @summary Set `state` to `begin` -> await `action` -> `state` to `end`
4
+ */
5
+ namespace Transition {
6
+ /**
7
+ * @summary Transition action defalt template
8
+ */
9
+ type Action = Perform.Promise.Sync<TS.Type.Not.Function>;
10
+ /**
11
+ * @summary Set state function. ~Like `React`
12
+ */
13
+ type SetState<TState> = (newState: TState) => unknown;
14
+ /**
15
+ * @summary Transition props
16
+ */
17
+ type Props<TState> = {
18
+ state: Transition.SetState<TState>;
19
+ begin?: TState;
20
+ end: TState;
21
+ };
22
+ /**
23
+ * @summary Create transition overload
24
+ */
25
+ type Overload<TMetaDefaultAction extends Action = Action> = {
26
+ /**
27
+ * @summary Create transition
28
+ * @returns Transition object
29
+ */
30
+ <TState, TDefaultAction extends TMetaDefaultAction = TMetaDefaultAction>(state: SetState<TState>, end: TState): Transition<TDefaultAction>;
31
+ /**
32
+ * @summary Create transition
33
+ * @returns Transition object
34
+ */
35
+ <TState, TDefaultAction extends TMetaDefaultAction = TMetaDefaultAction>(state: SetState<TState>, begin: TState, end: TState): Transition<TDefaultAction>;
36
+ /**
37
+ * @summary Create transition
38
+ * @returns Transition object
39
+ */
40
+ <TState, TDefaultAction extends TMetaDefaultAction = TMetaDefaultAction>(props: Props<TState>): Transition<TDefaultAction>;
41
+ };
42
+ /**
43
+ * @summary Internal definition of transition
44
+ */
45
+ type Execute<TDefaultAction extends Action = Action> = {
46
+ <TAction extends Action = TDefaultAction>(action: TAction): Promise<Perform.Promise.Sync.Result<TAction>>;
47
+ /**
48
+ * @summary Nested transition factory
49
+ */
50
+ Nest: Overload<TDefaultAction>;
51
+ };
52
+ }
53
+ type Transition<TDefaultAction extends Transition.Action = Transition.Action> = Transition.Execute<TDefaultAction>;
54
+ interface Code {
55
+ /**
56
+ * @summary Transition factory.\
57
+ * Set `state` to `begin` -> await `action` -> `state` to `end`
58
+ */
59
+ Transition: AVStantso.Transition.Overload;
60
+ }
61
+ const Transition: Code['Transition'];
62
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @summary Object wrap around value
3
+ */
4
+ declare class AVStantso_ValueWrap<TValue = unknown> {
5
+ #private;
6
+ constructor(value: TValue);
7
+ protected static Clone<TThis extends typeof AVStantso_ValueWrap>(this: TThis, source: InstanceType<TThis>): InstanceType<TThis>;
8
+ protected toString(): string;
9
+ protected valueOf(): TValue;
10
+ get value(): TValue;
11
+ }
12
+ declare namespace AVStantso_ValueWrap { }
@@ -0,0 +1,7 @@
1
+ interface AbortSignal {
2
+ /**
3
+ * @summary Stub for func/funcs if `aborted`
4
+ * @returns Stub for func/funcs. This stub prevent func call if `aborted`
5
+ */
6
+ Safe: AVStantso.Stub.One & AVStantso.Stub.Multiple;
7
+ }
@@ -0,0 +1 @@
1
+ import './abort-controller';
@@ -0,0 +1,16 @@
1
+ import Perform = AVStantso.Perform;
2
+ import Provider = AVStantso.Provider;
3
+ import Compare = AVStantso.Compare;
4
+ import Equality = AVStantso.Equality;
5
+ import Extend = AVStantso.Extend;
6
+ import Switch = AVStantso.Switch;
7
+ import Stub = AVStantso.Stub;
8
+ import Mock = AVStantso.Mock;
9
+ import Mapping = AVStantso.Mapping;
10
+ import Conveyor = AVStantso.Conveyor;
11
+ import Override = AVStantso.Override;
12
+ import Transition = AVStantso.Transition;
13
+ import AsyncTasksManager = AVStantso.AsyncTasksManager;
14
+ import ClassicEnum = AVStantso.ClassicEnum;
15
+ import ValueWrap = AVStantso_ValueWrap;
16
+ export { Perform, Provider, Compare, Equality, Extend, Switch, Stub, Mock, Mapping, Conveyor, Override, Transition, AsyncTasksManager, ClassicEnum, ValueWrap };
@@ -0,0 +1,5 @@
1
+ import '@avstantso/errors';
2
+ import '@avstantso/js';
3
+ import './_global';
4
+ import './_std-ext';
5
+ export * from './export';