phecda-core 3.1.0 → 4.0.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 CHANGED
@@ -1,33 +1,25 @@
1
- declare function Init(proto: any, key: PropertyKey): void;
2
- declare function Unmount(proto: any, key: PropertyKey): void;
3
- declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
4
- declare function Ignore(proto: any, key?: PropertyKey): void;
5
- declare function Clear(proto: any, key?: PropertyKey): void;
6
- declare function Expose(proto: any, key: PropertyKey): void;
1
+ declare function Init(proto: any, property: PropertyKey): void;
2
+ declare function Unmount(proto: any, property: PropertyKey): void;
3
+ declare function Expose(proto: any, property?: PropertyKey, index?: any): void;
7
4
  declare function Empty(model: any): void;
5
+ declare function Clear(proto: any, property?: PropertyKey, index?: any): void;
6
+ declare function Injectable(): (target: any) => void;
8
7
 
9
8
  declare const SHARE_KEY: unique symbol;
9
+ declare const CLEAR_KEY: unique symbol;
10
10
  declare const PHECDA_KEY: unique symbol;
11
11
  declare function isPhecda(model: any): model is Construct;
12
12
  declare function init(proto: Phecda): void;
13
13
  declare function getPhecdaFromTarget(target: any): any;
14
- declare function setStateKey(proto: Phecda, key?: PropertyKey): void;
15
- declare function setExposeKey(proto: Phecda, key?: PropertyKey): void;
16
- declare function setIgnoreKey(proto: Phecda, key?: PropertyKey): void;
17
- declare function setHandler(proto: Phecda, key: PropertyKey | undefined, handler: Handler): void;
18
- declare function setState(proto: Phecda, key: PropertyKey | undefined, state: Record<string, any>): void;
19
- declare function getOwnStateKey(target: any): string[];
20
- declare function getStateKey(target: any): PropertyKey[];
21
- declare function getOwnExposeKey(target: any): string[];
22
- declare function getExposeKey(target: any): PropertyKey[];
23
- declare function getOwnIgnoreKey(target: any): string[];
24
- declare function getOwnHandler(target: any, key: PropertyKey): Handler[];
25
- declare function getHandler(target: any, key: PropertyKey): any[];
26
- declare function getState(target: any, key?: PropertyKey): any;
27
- declare function getOwnState(target: any, key?: PropertyKey): Record<string, any>;
28
- declare function invokeHandler(event: string, module: Phecda): Promise<any[]>;
29
- declare function set(proto: any, key: string, value: any): void;
30
- declare function get(proto: any, key: string): any;
14
+ declare function setMeta(proto: Phecda, property: PropertyKey | undefined, index: number | undefined, meta: Record<string, any>): void;
15
+ declare function getOwnMetaKey(target: any): PropertyKey[];
16
+ declare function getMetaKey(target: any): PropertyKey[];
17
+ declare function getOwnMetaParams(target: any, key?: PropertyKey): number[];
18
+ declare function getMetaParams(target: any, key?: PropertyKey): number[];
19
+ declare function getMeta(target: any, property?: PropertyKey, index?: number): any[];
20
+ declare function getOwnMeta(target: any, property?: PropertyKey, index?: number): any[];
21
+ declare function set(proto: any, property: string, value: any): void;
22
+ declare function get(proto: any, property: string): any;
31
23
 
32
24
  interface NameSpace {
33
25
  [name: string]: Phecda;
@@ -37,19 +29,14 @@ interface InjectData {
37
29
  }
38
30
  type Construct<T = any> = new (...args: any[]) => T;
39
31
  type AbConstruct<T = any> = abstract new (...args: any[]) => T;
40
- interface Handler {
41
- [key: string]: any;
42
- }
43
32
  interface Phecda {
44
33
  prototype: any;
45
34
  __PROMISE_SYMBOL__: Promise<any>;
46
35
  [PHECDA_KEY]: {
47
- __EXPOSE_KEY: Set<PropertyKey>;
48
- __IGNORE_KEY: Set<PropertyKey>;
49
- __CLEAR_KEY: Set<PropertyKey>;
50
- __STATE_KEY: Set<PropertyKey>;
51
- __STATE_HANDLER__: Map<PropertyKey, Handler[]>;
52
- __STATE_NAMESPACE__: Map<PropertyKey, Object>;
36
+ __META__: Map<PropertyKey, {
37
+ data: any[];
38
+ params: Map<number, any>;
39
+ }>;
53
40
  };
54
41
  }
55
42
  type ClassValue<I> = {
@@ -63,18 +50,16 @@ declare function Tag(tag: PropertyKey): (model: any) => void;
63
50
  declare function Unique(desc?: string): (model: any) => void;
64
51
  declare function Assign(cb: (instance?: any) => any): (model: any) => void;
65
52
  declare function Global(model: any): void;
66
- declare function To(...callbacks: ((arg: any, instance: any, key: string) => any)[]): (proto: any, key: PropertyKey) => void;
67
- declare function Rule(cb: ((arg: any) => boolean | Promise<boolean>), info: string | (() => string)): (proto: any, key: PropertyKey) => void;
68
- declare function Err(cb: (e: Error | any, instance: any, key: string) => void, isCatch?: boolean): (proto: any, key: PropertyKey) => void;
53
+ declare function Err(cb: (e: Error | any, instance: any, property: string) => void, isCatch?: boolean): (proto: any, property: PropertyKey) => void;
69
54
  interface StorageParam {
70
- key: PropertyKey;
55
+ property: PropertyKey;
71
56
  instance: any;
72
57
  tag: string;
73
58
  toJSON: (str: string) => any;
74
59
  toString: (arg: any) => string;
75
60
  }
76
61
  interface WatcherParam {
77
- key: string;
62
+ property: string;
78
63
  instance: any;
79
64
  eventName: string;
80
65
  options?: {
@@ -83,36 +68,26 @@ interface WatcherParam {
83
68
  }
84
69
  declare function Watcher(eventName: keyof Events, options?: {
85
70
  once?: boolean;
86
- }): (proto: any, key: string) => void;
87
- declare function Effect(cb: (value: any, instance: any, key: string) => void): (proto: any, key: string) => void;
88
- declare function Storage({ key: storeKey, json, stringify }?: {
71
+ }): (proto: any, property: string) => void;
72
+ declare function Effect(cb: (value: any, instance: any, property: string) => void): (proto: any, property: string) => void;
73
+ declare function Storage({ key, json, stringify }?: {
89
74
  json?: (str: string) => any;
90
75
  stringify?: (arg: any) => string;
91
76
  key?: string;
92
- }): (proto: any, key?: PropertyKey) => void;
93
- declare function If(value: Boolean, ...decorators: (ClassDecorator[]) | (PropertyDecorator[]) | (ParameterDecorator[])): (...args: any[]) => void;
77
+ }): (proto: any, property?: PropertyKey) => void;
94
78
 
95
79
  declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
96
- declare function getBind<M extends Construct | AbConstruct>(model: M): any;
97
- declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(model: M, input: Data): InstanceType<M>;
98
- declare function transformInstance<M extends Construct>(instance: InstanceType<M>, force?: boolean): string[];
99
- declare function transformInstanceAsync<M extends Construct>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
100
- declare function transformProperty<M extends Construct>(instance: InstanceType<M>, property: keyof InstanceType<M>, force?: boolean): string[];
101
- declare function transformPropertyAsync<M extends Construct>(instance: InstanceType<M>, property: keyof InstanceType<M>, force?: boolean): Promise<string[]>;
102
- declare function classToPlain<M>(instance: M): ClassValue<M>;
103
- declare function snapShot<T extends Construct>(data: InstanceType<T>): {
104
- data: InstanceType<T>;
105
- clear(): void;
106
- apply(): void;
107
- };
108
80
  /**
109
81
  * add decorator to a class by function
110
82
  */
111
83
  declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> | PropertyKey | undefined, handler: PropertyDecorator | ClassDecorator): void;
112
84
  declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
113
85
  declare function isAsyncFunc(fn: Function): boolean;
114
- declare function setPropertyState(target: any, k: undefined | PropertyKey, setter: (state: Record<string, any>) => void): void;
115
- declare function getShareState<State>(target: any, getter: (state: Record<string, any>) => State): State;
86
+ declare function invoke(instance: any, key: string, ...params: any): Promise<PromiseSettledResult<any>[]>;
87
+ declare function invokeInit(instance: any): Promise<PromiseSettledResult<any>[]>;
88
+ declare function invokeUnmount(instance: any): Promise<PromiseSettledResult<any>[]>;
89
+ declare function If(value: Boolean, ...decorators: (ClassDecorator[]) | (PropertyDecorator[]) | (ParameterDecorator[])): (...args: any[]) => void;
90
+ declare function getMergedMeta(target: any, property?: PropertyKey, index?: number, merger?: (prev: any, cur: any) => any): any;
116
91
 
117
92
  declare const DataMap: InjectData;
118
93
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
@@ -135,4 +110,4 @@ declare abstract class Base {
135
110
  private _unmount;
136
111
  }
137
112
 
138
- export { type AbConstruct, Assign, Base, Bind, type ClassValue, Clear, type Construct, DataMap, Effect, Empty, Err, type Events, Expose, Global, type Handler, If, Ignore, Init, Inject, type InjectData, Isolate, type NameSpace, PHECDA_KEY, type Phecda, Pipeline, Provide, Rule, SHARE_KEY, Storage, type StorageParam, Tag, To, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, classToPlain, get, getBind, getExposeKey, getHandler, getInject, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateKey, getPhecdaFromTarget, getShareState, getState, getStateKey, getTag, init, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setInject, setPropertyState, setState, setStateKey, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
113
+ export { type AbConstruct, Assign, Base, CLEAR_KEY, type ClassValue, Clear, type Construct, DataMap, Effect, Empty, Err, type Events, Expose, Global, If, Init, Inject, type InjectData, Injectable, Isolate, type NameSpace, PHECDA_KEY, type Phecda, Pipeline, Provide, SHARE_KEY, Storage, type StorageParam, Tag, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, get, getInject, getMergedMeta, getMeta, getMetaKey, getMetaParams, getOwnMeta, getOwnMetaKey, getOwnMetaParams, getPhecdaFromTarget, getTag, init, invoke, invokeInit, invokeUnmount, isAsyncFunc, isPhecda, set, setInject, setMeta };
package/dist/index.d.ts CHANGED
@@ -1,33 +1,25 @@
1
- declare function Init(proto: any, key: PropertyKey): void;
2
- declare function Unmount(proto: any, key: PropertyKey): void;
3
- declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
4
- declare function Ignore(proto: any, key?: PropertyKey): void;
5
- declare function Clear(proto: any, key?: PropertyKey): void;
6
- declare function Expose(proto: any, key: PropertyKey): void;
1
+ declare function Init(proto: any, property: PropertyKey): void;
2
+ declare function Unmount(proto: any, property: PropertyKey): void;
3
+ declare function Expose(proto: any, property?: PropertyKey, index?: any): void;
7
4
  declare function Empty(model: any): void;
5
+ declare function Clear(proto: any, property?: PropertyKey, index?: any): void;
6
+ declare function Injectable(): (target: any) => void;
8
7
 
9
8
  declare const SHARE_KEY: unique symbol;
9
+ declare const CLEAR_KEY: unique symbol;
10
10
  declare const PHECDA_KEY: unique symbol;
11
11
  declare function isPhecda(model: any): model is Construct;
12
12
  declare function init(proto: Phecda): void;
13
13
  declare function getPhecdaFromTarget(target: any): any;
14
- declare function setStateKey(proto: Phecda, key?: PropertyKey): void;
15
- declare function setExposeKey(proto: Phecda, key?: PropertyKey): void;
16
- declare function setIgnoreKey(proto: Phecda, key?: PropertyKey): void;
17
- declare function setHandler(proto: Phecda, key: PropertyKey | undefined, handler: Handler): void;
18
- declare function setState(proto: Phecda, key: PropertyKey | undefined, state: Record<string, any>): void;
19
- declare function getOwnStateKey(target: any): string[];
20
- declare function getStateKey(target: any): PropertyKey[];
21
- declare function getOwnExposeKey(target: any): string[];
22
- declare function getExposeKey(target: any): PropertyKey[];
23
- declare function getOwnIgnoreKey(target: any): string[];
24
- declare function getOwnHandler(target: any, key: PropertyKey): Handler[];
25
- declare function getHandler(target: any, key: PropertyKey): any[];
26
- declare function getState(target: any, key?: PropertyKey): any;
27
- declare function getOwnState(target: any, key?: PropertyKey): Record<string, any>;
28
- declare function invokeHandler(event: string, module: Phecda): Promise<any[]>;
29
- declare function set(proto: any, key: string, value: any): void;
30
- declare function get(proto: any, key: string): any;
14
+ declare function setMeta(proto: Phecda, property: PropertyKey | undefined, index: number | undefined, meta: Record<string, any>): void;
15
+ declare function getOwnMetaKey(target: any): PropertyKey[];
16
+ declare function getMetaKey(target: any): PropertyKey[];
17
+ declare function getOwnMetaParams(target: any, key?: PropertyKey): number[];
18
+ declare function getMetaParams(target: any, key?: PropertyKey): number[];
19
+ declare function getMeta(target: any, property?: PropertyKey, index?: number): any[];
20
+ declare function getOwnMeta(target: any, property?: PropertyKey, index?: number): any[];
21
+ declare function set(proto: any, property: string, value: any): void;
22
+ declare function get(proto: any, property: string): any;
31
23
 
32
24
  interface NameSpace {
33
25
  [name: string]: Phecda;
@@ -37,19 +29,14 @@ interface InjectData {
37
29
  }
38
30
  type Construct<T = any> = new (...args: any[]) => T;
39
31
  type AbConstruct<T = any> = abstract new (...args: any[]) => T;
40
- interface Handler {
41
- [key: string]: any;
42
- }
43
32
  interface Phecda {
44
33
  prototype: any;
45
34
  __PROMISE_SYMBOL__: Promise<any>;
46
35
  [PHECDA_KEY]: {
47
- __EXPOSE_KEY: Set<PropertyKey>;
48
- __IGNORE_KEY: Set<PropertyKey>;
49
- __CLEAR_KEY: Set<PropertyKey>;
50
- __STATE_KEY: Set<PropertyKey>;
51
- __STATE_HANDLER__: Map<PropertyKey, Handler[]>;
52
- __STATE_NAMESPACE__: Map<PropertyKey, Object>;
36
+ __META__: Map<PropertyKey, {
37
+ data: any[];
38
+ params: Map<number, any>;
39
+ }>;
53
40
  };
54
41
  }
55
42
  type ClassValue<I> = {
@@ -63,18 +50,16 @@ declare function Tag(tag: PropertyKey): (model: any) => void;
63
50
  declare function Unique(desc?: string): (model: any) => void;
64
51
  declare function Assign(cb: (instance?: any) => any): (model: any) => void;
65
52
  declare function Global(model: any): void;
66
- declare function To(...callbacks: ((arg: any, instance: any, key: string) => any)[]): (proto: any, key: PropertyKey) => void;
67
- declare function Rule(cb: ((arg: any) => boolean | Promise<boolean>), info: string | (() => string)): (proto: any, key: PropertyKey) => void;
68
- declare function Err(cb: (e: Error | any, instance: any, key: string) => void, isCatch?: boolean): (proto: any, key: PropertyKey) => void;
53
+ declare function Err(cb: (e: Error | any, instance: any, property: string) => void, isCatch?: boolean): (proto: any, property: PropertyKey) => void;
69
54
  interface StorageParam {
70
- key: PropertyKey;
55
+ property: PropertyKey;
71
56
  instance: any;
72
57
  tag: string;
73
58
  toJSON: (str: string) => any;
74
59
  toString: (arg: any) => string;
75
60
  }
76
61
  interface WatcherParam {
77
- key: string;
62
+ property: string;
78
63
  instance: any;
79
64
  eventName: string;
80
65
  options?: {
@@ -83,36 +68,26 @@ interface WatcherParam {
83
68
  }
84
69
  declare function Watcher(eventName: keyof Events, options?: {
85
70
  once?: boolean;
86
- }): (proto: any, key: string) => void;
87
- declare function Effect(cb: (value: any, instance: any, key: string) => void): (proto: any, key: string) => void;
88
- declare function Storage({ key: storeKey, json, stringify }?: {
71
+ }): (proto: any, property: string) => void;
72
+ declare function Effect(cb: (value: any, instance: any, property: string) => void): (proto: any, property: string) => void;
73
+ declare function Storage({ key, json, stringify }?: {
89
74
  json?: (str: string) => any;
90
75
  stringify?: (arg: any) => string;
91
76
  key?: string;
92
- }): (proto: any, key?: PropertyKey) => void;
93
- declare function If(value: Boolean, ...decorators: (ClassDecorator[]) | (PropertyDecorator[]) | (ParameterDecorator[])): (...args: any[]) => void;
77
+ }): (proto: any, property?: PropertyKey) => void;
94
78
 
95
79
  declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
96
- declare function getBind<M extends Construct | AbConstruct>(model: M): any;
97
- declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(model: M, input: Data): InstanceType<M>;
98
- declare function transformInstance<M extends Construct>(instance: InstanceType<M>, force?: boolean): string[];
99
- declare function transformInstanceAsync<M extends Construct>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
100
- declare function transformProperty<M extends Construct>(instance: InstanceType<M>, property: keyof InstanceType<M>, force?: boolean): string[];
101
- declare function transformPropertyAsync<M extends Construct>(instance: InstanceType<M>, property: keyof InstanceType<M>, force?: boolean): Promise<string[]>;
102
- declare function classToPlain<M>(instance: M): ClassValue<M>;
103
- declare function snapShot<T extends Construct>(data: InstanceType<T>): {
104
- data: InstanceType<T>;
105
- clear(): void;
106
- apply(): void;
107
- };
108
80
  /**
109
81
  * add decorator to a class by function
110
82
  */
111
83
  declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> | PropertyKey | undefined, handler: PropertyDecorator | ClassDecorator): void;
112
84
  declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
113
85
  declare function isAsyncFunc(fn: Function): boolean;
114
- declare function setPropertyState(target: any, k: undefined | PropertyKey, setter: (state: Record<string, any>) => void): void;
115
- declare function getShareState<State>(target: any, getter: (state: Record<string, any>) => State): State;
86
+ declare function invoke(instance: any, key: string, ...params: any): Promise<PromiseSettledResult<any>[]>;
87
+ declare function invokeInit(instance: any): Promise<PromiseSettledResult<any>[]>;
88
+ declare function invokeUnmount(instance: any): Promise<PromiseSettledResult<any>[]>;
89
+ declare function If(value: Boolean, ...decorators: (ClassDecorator[]) | (PropertyDecorator[]) | (ParameterDecorator[])): (...args: any[]) => void;
90
+ declare function getMergedMeta(target: any, property?: PropertyKey, index?: number, merger?: (prev: any, cur: any) => any): any;
116
91
 
117
92
  declare const DataMap: InjectData;
118
93
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
@@ -135,4 +110,4 @@ declare abstract class Base {
135
110
  private _unmount;
136
111
  }
137
112
 
138
- export { type AbConstruct, Assign, Base, Bind, type ClassValue, Clear, type Construct, DataMap, Effect, Empty, Err, type Events, Expose, Global, type Handler, If, Ignore, Init, Inject, type InjectData, Isolate, type NameSpace, PHECDA_KEY, type Phecda, Pipeline, Provide, Rule, SHARE_KEY, Storage, type StorageParam, Tag, To, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, classToPlain, get, getBind, getExposeKey, getHandler, getInject, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateKey, getPhecdaFromTarget, getShareState, getState, getStateKey, getTag, init, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setInject, setPropertyState, setState, setStateKey, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
113
+ export { type AbConstruct, Assign, Base, CLEAR_KEY, type ClassValue, Clear, type Construct, DataMap, Effect, Empty, Err, type Events, Expose, Global, If, Init, Inject, type InjectData, Injectable, Isolate, type NameSpace, PHECDA_KEY, type Phecda, Pipeline, Provide, SHARE_KEY, Storage, type StorageParam, Tag, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, get, getInject, getMergedMeta, getMeta, getMetaKey, getMetaParams, getOwnMeta, getOwnMetaKey, getOwnMetaParams, getPhecdaFromTarget, getTag, init, invoke, invokeInit, invokeUnmount, isAsyncFunc, isPhecda, set, setInject, setMeta };