phecda-core 3.0.0-beta.13 → 3.0.0-beta.15

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.ts CHANGED
@@ -1,22 +1,23 @@
1
1
  declare function Init(proto: any, key: PropertyKey): void;
2
2
  declare function Unmount(proto: any, key: PropertyKey): void;
3
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;
4
+ declare function Ignore(proto: any, key?: PropertyKey): void;
5
+ declare function Clear(proto: any, key?: PropertyKey): void;
6
6
  declare function Expose(proto: any, key: PropertyKey): void;
7
- declare function Empty(module: any): void;
7
+ declare function Empty(model: any): void;
8
8
 
9
9
  declare const SHARE_KEY: unique symbol;
10
10
  declare const PHECDA_KEY: unique symbol;
11
- declare function isPhecda(module: any): module is Construct;
11
+ declare function isPhecda(model: any): model is Construct;
12
12
  declare function init(proto: Phecda): void;
13
- declare function setStateVar(proto: Phecda, key: PropertyKey): void;
13
+ declare function getPhecdaFromTarget(target: any): any;
14
+ declare function setStateKey(proto: Phecda, key: PropertyKey): void;
14
15
  declare function setExposeKey(proto: Phecda, key: PropertyKey): void;
15
16
  declare function setIgnoreKey(proto: Phecda, key: PropertyKey): void;
16
17
  declare function setHandler(proto: Phecda, key: PropertyKey, handler: Handler): void;
17
18
  declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
18
- declare function getOwnStateVars(target: any): string[];
19
- declare function getStateVars(target: any): PropertyKey[];
19
+ declare function getOwnStateKey(target: any): string[];
20
+ declare function getStateKey(target: any): PropertyKey[];
20
21
  declare function getOwnExposeKey(target: any): string[];
21
22
  declare function getExposeKey(target: any): PropertyKey[];
22
23
  declare function getOwnIgnoreKey(target: any): string[];
@@ -24,7 +25,7 @@ declare function getOwnHandler(target: any, key: PropertyKey): Handler[];
24
25
  declare function getHandler(target: any, key: PropertyKey): any[];
25
26
  declare function getState(target: any, key: PropertyKey): any;
26
27
  declare function getOwnState(target: any, key: PropertyKey): Record<string, any>;
27
- declare function invokeHandler(event: string, instance: Phecda): Promise<any[]>;
28
+ declare function invokeHandler(event: string, module: Phecda): Promise<any[]>;
28
29
  declare function set(proto: Phecda, key: string, value: any): void;
29
30
  declare function get(proto: Phecda, key: string): any;
30
31
 
@@ -42,12 +43,12 @@ interface Handler {
42
43
  interface Phecda {
43
44
  prototype: any;
44
45
  [PHECDA_KEY]: {
45
- __EXPOSE_VAR__: Set<PropertyKey>;
46
- __IGNORE_VAR__: Set<PropertyKey>;
47
- __STATE_VAR__: Set<PropertyKey>;
46
+ __EXPOSE_KEY: Set<PropertyKey>;
47
+ __IGNORE_KEY: Set<PropertyKey>;
48
+ __CLEAR_KEY: Set<PropertyKey>;
49
+ __STATE_KEY: Set<PropertyKey>;
48
50
  __STATE_HANDLER__: Map<PropertyKey, Handler[]>;
49
51
  __STATE_NAMESPACE__: Map<PropertyKey, Object>;
50
- [key: string]: any;
51
52
  };
52
53
  }
53
54
  type ClassValue<I> = {
@@ -56,11 +57,11 @@ type ClassValue<I> = {
56
57
  interface Events {
57
58
  }
58
59
 
59
- declare function Isolate(module: any): void;
60
- declare function Tag(tag: PropertyKey): (module: any) => void;
61
- declare function Unique(desc?: string): (module: any) => void;
62
- declare function Assign(cb: (instance?: any) => any): (module: any) => void;
63
- declare function Global(module: any): void;
60
+ declare function Isolate(model: any): void;
61
+ declare function Tag(tag: PropertyKey): (model: any) => void;
62
+ declare function Unique(desc?: string): (model: any) => void;
63
+ declare function Assign(cb: (instance?: any) => any): (model: any) => void;
64
+ declare function Global(model: any): void;
64
65
  declare function To(...callbacks: ((arg: any, instance: any, key: string) => any)[]): (proto: any, key: PropertyKey) => void;
65
66
  declare function Rule(cb: ((arg: any) => boolean | Promise<boolean>), info: string | (() => string)): (proto: any, key: PropertyKey) => void;
66
67
  declare function Err(cb: (e: Error | any, instance: any, key: string) => void, isCatch?: boolean): (proto: any, key: PropertyKey) => void;
@@ -90,8 +91,8 @@ declare function Storage({ key: storeKey, toJSON, toString }?: {
90
91
  }): (proto: any, key?: PropertyKey) => void;
91
92
 
92
93
  declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
93
- declare function getBind<M extends Construct | AbConstruct>(module: M): any;
94
- declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
94
+ declare function getBind<M extends Construct | AbConstruct>(model: M): any;
95
+ declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(model: M, input: Data): InstanceType<M>;
95
96
  declare function transformInstance<M extends Construct>(instance: InstanceType<M>, force?: boolean): string[];
96
97
  declare function transformInstanceAsync<M extends Construct>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
97
98
  declare function transformProperty<M extends Construct>(instance: InstanceType<M>, property: keyof InstanceType<M>, force?: boolean): string[];
@@ -113,4 +114,4 @@ declare const activeInstance: Record<string, any>;
113
114
  declare function injectKey(key: string, value: any): Record<string, any>;
114
115
  declare function getKey(key: string): any;
115
116
 
116
- export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, PHECDA_KEY, Phecda, Pipeline, Provide, Rule, SHARE_KEY, Storage, StorageParam, Tag, To, Unique, Unmount, Watcher, WatcherParam, activeInstance, addDecoToClass, classToPlain, get, getBind, getExposeKey, getHandler, getKey, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateVars, getState, getStateVars, getTag, init, injectKey, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setState, setStateVar, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
117
+ export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, PHECDA_KEY, Phecda, Pipeline, Provide, Rule, SHARE_KEY, Storage, StorageParam, Tag, To, Unique, Unmount, Watcher, WatcherParam, activeInstance, addDecoToClass, classToPlain, get, getBind, getExposeKey, getHandler, getKey, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateKey, getPhecdaFromTarget, getState, getStateKey, getTag, init, injectKey, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setState, setStateKey, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
package/dist/index.js CHANGED
@@ -57,9 +57,10 @@ __export(src_exports, {
57
57
  getOwnHandler: () => getOwnHandler,
58
58
  getOwnIgnoreKey: () => getOwnIgnoreKey,
59
59
  getOwnState: () => getOwnState,
60
- getOwnStateVars: () => getOwnStateVars,
60
+ getOwnStateKey: () => getOwnStateKey,
61
+ getPhecdaFromTarget: () => getPhecdaFromTarget,
61
62
  getState: () => getState,
62
- getStateVars: () => getStateVars,
63
+ getStateKey: () => getStateKey,
63
64
  getTag: () => getTag,
64
65
  init: () => init,
65
66
  injectKey: () => injectKey,
@@ -72,7 +73,7 @@ __export(src_exports, {
72
73
  setHandler: () => setHandler,
73
74
  setIgnoreKey: () => setIgnoreKey,
74
75
  setState: () => setState,
75
- setStateVar: () => setStateVar,
76
+ setStateKey: () => setStateKey,
76
77
  snapShot: () => snapShot,
77
78
  transformInstance: () => transformInstance,
78
79
  transformInstanceAsync: () => transformInstanceAsync,
@@ -84,9 +85,9 @@ module.exports = __toCommonJS(src_exports);
84
85
  // src/core.ts
85
86
  var SHARE_KEY = Symbol("phecda");
86
87
  var PHECDA_KEY = Symbol("phecda");
87
- function isPhecda(module2) {
88
- if (typeof module2 === "function")
89
- return !!module2.prototype[PHECDA_KEY];
88
+ function isPhecda(model) {
89
+ if (typeof model === "function")
90
+ return !!model.prototype[PHECDA_KEY];
90
91
  return false;
91
92
  }
92
93
  __name(isPhecda, "isPhecda");
@@ -95,9 +96,10 @@ function init(proto) {
95
96
  return;
96
97
  if (!proto.hasOwnProperty(PHECDA_KEY)) {
97
98
  proto[PHECDA_KEY] = {
98
- __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
99
- __IGNORE_VAR__: /* @__PURE__ */ new Set(),
100
- __STATE_VAR__: /* @__PURE__ */ new Set(),
99
+ __EXPOSE_KEY: /* @__PURE__ */ new Set(),
100
+ __IGNORE_KEY: /* @__PURE__ */ new Set(),
101
+ __CLEAR_KEY: /* @__PURE__ */ new Set(),
102
+ __STATE_KEY: /* @__PURE__ */ new Set(),
101
103
  __STATE_HANDLER__: /* @__PURE__ */ new Map(),
102
104
  __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
103
105
  };
@@ -112,20 +114,20 @@ function getPhecdaFromTarget(target) {
112
114
  return Object.getPrototypeOf(target);
113
115
  }
114
116
  __name(getPhecdaFromTarget, "getPhecdaFromTarget");
115
- function setStateVar(proto, key) {
117
+ function setStateKey(proto, key) {
116
118
  init(proto);
117
- proto[PHECDA_KEY].__STATE_VAR__.add(key);
119
+ proto[PHECDA_KEY].__STATE_KEY.add(key);
118
120
  setExposeKey(proto, key);
119
121
  }
120
- __name(setStateVar, "setStateVar");
122
+ __name(setStateKey, "setStateKey");
121
123
  function setExposeKey(proto, key) {
122
124
  init(proto);
123
- proto[PHECDA_KEY].__EXPOSE_VAR__.add(key);
125
+ proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
124
126
  }
125
127
  __name(setExposeKey, "setExposeKey");
126
128
  function setIgnoreKey(proto, key) {
127
129
  init(proto);
128
- proto[PHECDA_KEY].__IGNORE_VAR__.add(key);
130
+ proto[PHECDA_KEY].__IGNORE_KEY.add(key);
129
131
  }
130
132
  __name(setIgnoreKey, "setIgnoreKey");
131
133
  function setHandler(proto, key, handler) {
@@ -144,39 +146,42 @@ function setState(proto, key, state) {
144
146
  namespace.set(key, state);
145
147
  }
146
148
  __name(setState, "setState");
147
- function getOwnStateVars(target) {
149
+ function getOwnStateKey(target) {
148
150
  const proto = getPhecdaFromTarget(target);
149
151
  return [
150
- ...proto[PHECDA_KEY].__STATE_VAR__
152
+ ...proto[PHECDA_KEY].__STATE_KEY
151
153
  ];
152
154
  }
153
- __name(getOwnStateVars, "getOwnStateVars");
154
- function getStateVars(target) {
155
+ __name(getOwnStateKey, "getOwnStateKey");
156
+ function getStateKey(target) {
155
157
  let proto = getPhecdaFromTarget(target);
156
158
  const set2 = /* @__PURE__ */ new Set();
157
159
  while (proto?.[PHECDA_KEY]) {
158
- proto[PHECDA_KEY].__STATE_VAR__.forEach((item) => set2.add(item));
160
+ if (proto.hasOwnProperty(PHECDA_KEY))
161
+ proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
159
162
  proto = Object.getPrototypeOf(proto);
160
163
  }
161
164
  return [
162
165
  ...set2
163
166
  ];
164
167
  }
165
- __name(getStateVars, "getStateVars");
168
+ __name(getStateKey, "getStateKey");
166
169
  function getOwnExposeKey(target) {
167
170
  const proto = getPhecdaFromTarget(target);
168
171
  return [
169
- ...proto[PHECDA_KEY].__EXPOSE_VAR__
170
- ].filter((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item));
172
+ ...proto[PHECDA_KEY].__EXPOSE_KEY
173
+ ].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
171
174
  }
172
175
  __name(getOwnExposeKey, "getOwnExposeKey");
173
176
  function getExposeKey(target) {
174
177
  let proto = getPhecdaFromTarget(target);
175
178
  const set2 = /* @__PURE__ */ new Set();
179
+ const origin = proto;
176
180
  while (proto?.[PHECDA_KEY]) {
177
- [
178
- ...proto[PHECDA_KEY].__EXPOSE_VAR__
179
- ].forEach((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item) && set2.add(item));
181
+ if (proto.hasOwnProperty(PHECDA_KEY))
182
+ [
183
+ ...proto[PHECDA_KEY].__EXPOSE_KEY
184
+ ].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
180
185
  proto = Object.getPrototypeOf(proto);
181
186
  }
182
187
  return [
@@ -187,7 +192,7 @@ __name(getExposeKey, "getExposeKey");
187
192
  function getOwnIgnoreKey(target) {
188
193
  const proto = getPhecdaFromTarget(target);
189
194
  return [
190
- ...proto[PHECDA_KEY]?.__IGNORE_VAR__
195
+ ...proto[PHECDA_KEY]?.__IGNORE_KEY
191
196
  ];
192
197
  }
193
198
  __name(getOwnIgnoreKey, "getOwnIgnoreKey");
@@ -200,7 +205,11 @@ function getHandler(target, key) {
200
205
  let proto = getPhecdaFromTarget(target);
201
206
  const set2 = /* @__PURE__ */ new Set();
202
207
  while (proto?.[PHECDA_KEY]) {
203
- proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
208
+ if (proto.hasOwnProperty(PHECDA_KEY)) {
209
+ proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
210
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
211
+ break;
212
+ }
204
213
  proto = Object.getPrototypeOf(proto);
205
214
  }
206
215
  return [
@@ -212,12 +221,16 @@ function getState(target, key) {
212
221
  let proto = getPhecdaFromTarget(target);
213
222
  let ret = {};
214
223
  while (proto?.[PHECDA_KEY]) {
215
- const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
216
- if (state)
217
- ret = {
218
- ...state,
219
- ...ret
220
- };
224
+ if (proto.hasOwnProperty(PHECDA_KEY)) {
225
+ const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
226
+ if (state)
227
+ ret = {
228
+ ...state,
229
+ ...ret
230
+ };
231
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
232
+ break;
233
+ }
221
234
  proto = Object.getPrototypeOf(proto);
222
235
  }
223
236
  return ret;
@@ -228,27 +241,29 @@ function getOwnState(target, key) {
228
241
  return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
229
242
  }
230
243
  __name(getOwnState, "getOwnState");
231
- function invokeHandler(event, instance) {
232
- const stateVars = getExposeKey(instance);
244
+ function invokeHandler(event, module2) {
245
+ const stateVars = getExposeKey(module2);
233
246
  const initHandlers = stateVars.map((item) => {
234
- return getHandler(instance, item).filter((h) => !!h[event]).map((h) => h[event](instance));
247
+ return getHandler(module2, item).filter((h) => !!h[event]).map((h) => h[event](module2));
235
248
  }).flat();
236
249
  return Promise.all(initHandlers);
237
250
  }
238
251
  __name(invokeHandler, "invokeHandler");
239
252
  function set(proto, key, value) {
240
253
  init(proto);
241
- proto[PHECDA_KEY][`__${key.toUpperCase()}__`] = value;
254
+ setState(proto, SHARE_KEY, {
255
+ [`__${key.toUpperCase()}__`]: value
256
+ });
242
257
  }
243
258
  __name(set, "set");
244
259
  function get(proto, key) {
245
- return proto[PHECDA_KEY]?.[`__${key.toUpperCase()}__`];
260
+ return getState(proto, SHARE_KEY)[`__${key.toUpperCase()}__`];
246
261
  }
247
262
  __name(get, "get");
248
263
 
249
264
  // src/decorators/core.ts
250
265
  function Init(proto, key) {
251
- setStateVar(proto, key);
266
+ setStateKey(proto, key);
252
267
  setHandler(proto, key, {
253
268
  async init(instance) {
254
269
  return instance[key]();
@@ -257,7 +272,7 @@ function Init(proto, key) {
257
272
  }
258
273
  __name(Init, "Init");
259
274
  function Unmount(proto, key) {
260
- setStateVar(proto, key);
275
+ setStateKey(proto, key);
261
276
  setHandler(proto, key, {
262
277
  async unmount(instance) {
263
278
  return instance[key]();
@@ -267,32 +282,28 @@ function Unmount(proto, key) {
267
282
  __name(Unmount, "Unmount");
268
283
  function Bind(value) {
269
284
  return (proto, k) => {
270
- setStateVar(proto, k);
285
+ setStateKey(proto, k);
271
286
  setState(proto, k, {
272
287
  value
273
288
  });
274
289
  };
275
290
  }
276
291
  __name(Bind, "Bind");
277
- function Ignore(proto, key) {
292
+ function Ignore(proto, key = SHARE_KEY) {
278
293
  setIgnoreKey(proto, key);
279
294
  }
280
295
  __name(Ignore, "Ignore");
281
- function Clear(proto, key) {
296
+ function Clear(proto, key = SHARE_KEY) {
282
297
  init(proto);
283
- proto[PHECDA_KEY].__EXPOSE_VAR__.delete(key);
284
- proto[PHECDA_KEY].__IGNORE_VAR__.delete(key);
285
- proto[PHECDA_KEY].__STATE_VAR__.delete(key);
286
- proto[PHECDA_KEY].__STATE_HANDLER__.delete(key);
287
- proto[PHECDA_KEY].__STATE_NAMESPACE__.delete(key);
298
+ proto[PHECDA_KEY].__CLEAR_KEY.add(key);
288
299
  }
289
300
  __name(Clear, "Clear");
290
301
  function Expose(proto, key) {
291
302
  setExposeKey(proto, key);
292
303
  }
293
304
  __name(Expose, "Expose");
294
- function Empty(module2) {
295
- init(module2.prototype);
305
+ function Empty(model) {
306
+ init(model.prototype);
296
307
  }
297
308
  __name(Empty, "Empty");
298
309
 
@@ -300,12 +311,12 @@ __name(Empty, "Empty");
300
311
  function getTag(moduleOrInstance) {
301
312
  if (typeof moduleOrInstance === "object")
302
313
  moduleOrInstance = moduleOrInstance.constructor;
303
- return moduleOrInstance.prototype[PHECDA_KEY]?.__TAG__ || moduleOrInstance.name;
314
+ return get(moduleOrInstance.prototype, "tag") || moduleOrInstance.name;
304
315
  }
305
316
  __name(getTag, "getTag");
306
- function getBind(module2) {
307
- const instance = new module2();
308
- const keys = getStateVars(instance);
317
+ function getBind(model) {
318
+ const instance = new model();
319
+ const keys = getStateKey(instance);
309
320
  const ret = {};
310
321
  for (const item of keys) {
311
322
  const state = getState(instance, item);
@@ -315,8 +326,8 @@ function getBind(module2) {
315
326
  return ret;
316
327
  }
317
328
  __name(getBind, "getBind");
318
- function plainToClass(module2, input) {
319
- const instance = new module2();
329
+ function plainToClass(model, input) {
330
+ const instance = new model();
320
331
  const keys = getExposeKey(instance);
321
332
  for (const item of keys)
322
333
  instance[item] = input[item];
@@ -460,28 +471,28 @@ function getKey(key) {
460
471
  __name(getKey, "getKey");
461
472
 
462
473
  // src/decorators/function.ts
463
- function Isolate(module2) {
464
- set(module2.prototype, "isolate", true);
465
- module2.prototype[PHECDA_KEY].__ISOLATE__ = true;
474
+ function Isolate(model) {
475
+ set(model.prototype, "isolate", true);
476
+ model.prototype[PHECDA_KEY].__ISOLATE__ = true;
466
477
  }
467
478
  __name(Isolate, "Isolate");
468
479
  function Tag(tag) {
469
- return (module2) => {
470
- set(module2.prototype, "tag", tag);
480
+ return (model) => {
481
+ set(model.prototype, "tag", tag);
471
482
  };
472
483
  }
473
484
  __name(Tag, "Tag");
474
485
  function Unique(desc) {
475
- return (module2) => {
476
- set(module2.prototype, "tag", Symbol(desc || module2.name));
486
+ return (model) => {
487
+ set(model.prototype, "tag", Symbol(desc || model.name));
477
488
  };
478
489
  }
479
490
  __name(Unique, "Unique");
480
491
  function Assign(cb) {
481
- return (module2) => {
482
- init(module2.prototype);
483
- setStateVar(module2.prototype, SHARE_KEY);
484
- setHandler(module2.prototype, SHARE_KEY, {
492
+ return (model) => {
493
+ init(model.prototype);
494
+ setStateKey(model.prototype, SHARE_KEY);
495
+ setHandler(model.prototype, SHARE_KEY, {
485
496
  init: async (instance) => {
486
497
  const value = await cb(instance);
487
498
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -493,10 +504,10 @@ function Assign(cb) {
493
504
  };
494
505
  }
495
506
  __name(Assign, "Assign");
496
- function Global(module2) {
497
- init(module2.prototype);
498
- setStateVar(module2.prototype, SHARE_KEY);
499
- setHandler(module2.prototype, SHARE_KEY, {
507
+ function Global(model) {
508
+ init(model.prototype);
509
+ setStateKey(model.prototype, SHARE_KEY);
510
+ setHandler(model.prototype, SHARE_KEY, {
500
511
  init: async (instance) => {
501
512
  const tag = instance[PHECDA_KEY].__TAG__;
502
513
  if (!tag)
@@ -510,7 +521,7 @@ function Global(module2) {
510
521
  __name(Global, "Global");
511
522
  function To(...callbacks) {
512
523
  return (proto, key) => {
513
- setStateVar(proto, key);
524
+ setStateKey(proto, key);
514
525
  setHandler(proto, key, {
515
526
  async pipe(instance, addError) {
516
527
  for (const cb of callbacks) {
@@ -530,7 +541,7 @@ function To(...callbacks) {
530
541
  __name(To, "To");
531
542
  function Rule(cb, info) {
532
543
  return (proto, key) => {
533
- setStateVar(proto, key);
544
+ setStateKey(proto, key);
534
545
  setHandler(proto, key, {
535
546
  async pipe(instance, addError) {
536
547
  let ret;
@@ -551,7 +562,7 @@ function Rule(cb, info) {
551
562
  __name(Rule, "Rule");
552
563
  function Err(cb, isCatch = false) {
553
564
  return (proto, key) => {
554
- setStateVar(proto, key);
565
+ setStateKey(proto, key);
555
566
  setHandler(proto, key, {
556
567
  init: (instance) => {
557
568
  if (typeof instance[key] === "function") {
@@ -586,7 +597,7 @@ __name(Err, "Err");
586
597
  function Watcher(eventName, options) {
587
598
  let cb;
588
599
  return (proto, key) => {
589
- setStateVar(proto, key);
600
+ setStateKey(proto, key);
590
601
  setHandler(proto, key, {
591
602
  init(instance) {
592
603
  return cb = getKey("watcher")?.({
@@ -605,7 +616,7 @@ function Watcher(eventName, options) {
605
616
  __name(Watcher, "Watcher");
606
617
  function Effect(cb) {
607
618
  return (proto, key) => {
608
- setStateVar(proto, key);
619
+ setStateKey(proto, key);
609
620
  setHandler(proto, key, {
610
621
  init(instance) {
611
622
  instance[`$_${key}`] = instance[key];
@@ -634,7 +645,7 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
634
645
  if (key) {
635
646
  init(proto);
636
647
  tag = storeKey || `${getTag(proto)}_${key}`;
637
- setStateVar(proto, key);
648
+ setStateKey(proto, key);
638
649
  setHandler(proto, key, {
639
650
  init: (instance) => {
640
651
  return getKey("storage")?.({
@@ -649,7 +660,7 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
649
660
  } else {
650
661
  init(proto.prototype);
651
662
  tag = storeKey || getTag(proto);
652
- setStateVar(proto.prototype, SHARE_KEY);
663
+ setStateKey(proto.prototype, SHARE_KEY);
653
664
  setHandler(proto.prototype, SHARE_KEY, {
654
665
  init: (instance) => {
655
666
  return getKey("storage")?.({
@@ -703,9 +714,10 @@ __name(Storage, "Storage");
703
714
  getOwnHandler,
704
715
  getOwnIgnoreKey,
705
716
  getOwnState,
706
- getOwnStateVars,
717
+ getOwnStateKey,
718
+ getPhecdaFromTarget,
707
719
  getState,
708
- getStateVars,
720
+ getStateKey,
709
721
  getTag,
710
722
  init,
711
723
  injectKey,
@@ -718,7 +730,7 @@ __name(Storage, "Storage");
718
730
  setHandler,
719
731
  setIgnoreKey,
720
732
  setState,
721
- setStateVar,
733
+ setStateKey,
722
734
  snapShot,
723
735
  transformInstance,
724
736
  transformInstanceAsync,
package/dist/index.mjs CHANGED
@@ -4,9 +4,9 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
4
4
  // src/core.ts
5
5
  var SHARE_KEY = Symbol("phecda");
6
6
  var PHECDA_KEY = Symbol("phecda");
7
- function isPhecda(module) {
8
- if (typeof module === "function")
9
- return !!module.prototype[PHECDA_KEY];
7
+ function isPhecda(model) {
8
+ if (typeof model === "function")
9
+ return !!model.prototype[PHECDA_KEY];
10
10
  return false;
11
11
  }
12
12
  __name(isPhecda, "isPhecda");
@@ -15,9 +15,10 @@ function init(proto) {
15
15
  return;
16
16
  if (!proto.hasOwnProperty(PHECDA_KEY)) {
17
17
  proto[PHECDA_KEY] = {
18
- __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
19
- __IGNORE_VAR__: /* @__PURE__ */ new Set(),
20
- __STATE_VAR__: /* @__PURE__ */ new Set(),
18
+ __EXPOSE_KEY: /* @__PURE__ */ new Set(),
19
+ __IGNORE_KEY: /* @__PURE__ */ new Set(),
20
+ __CLEAR_KEY: /* @__PURE__ */ new Set(),
21
+ __STATE_KEY: /* @__PURE__ */ new Set(),
21
22
  __STATE_HANDLER__: /* @__PURE__ */ new Map(),
22
23
  __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
23
24
  };
@@ -32,20 +33,20 @@ function getPhecdaFromTarget(target) {
32
33
  return Object.getPrototypeOf(target);
33
34
  }
34
35
  __name(getPhecdaFromTarget, "getPhecdaFromTarget");
35
- function setStateVar(proto, key) {
36
+ function setStateKey(proto, key) {
36
37
  init(proto);
37
- proto[PHECDA_KEY].__STATE_VAR__.add(key);
38
+ proto[PHECDA_KEY].__STATE_KEY.add(key);
38
39
  setExposeKey(proto, key);
39
40
  }
40
- __name(setStateVar, "setStateVar");
41
+ __name(setStateKey, "setStateKey");
41
42
  function setExposeKey(proto, key) {
42
43
  init(proto);
43
- proto[PHECDA_KEY].__EXPOSE_VAR__.add(key);
44
+ proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
44
45
  }
45
46
  __name(setExposeKey, "setExposeKey");
46
47
  function setIgnoreKey(proto, key) {
47
48
  init(proto);
48
- proto[PHECDA_KEY].__IGNORE_VAR__.add(key);
49
+ proto[PHECDA_KEY].__IGNORE_KEY.add(key);
49
50
  }
50
51
  __name(setIgnoreKey, "setIgnoreKey");
51
52
  function setHandler(proto, key, handler) {
@@ -64,39 +65,42 @@ function setState(proto, key, state) {
64
65
  namespace.set(key, state);
65
66
  }
66
67
  __name(setState, "setState");
67
- function getOwnStateVars(target) {
68
+ function getOwnStateKey(target) {
68
69
  const proto = getPhecdaFromTarget(target);
69
70
  return [
70
- ...proto[PHECDA_KEY].__STATE_VAR__
71
+ ...proto[PHECDA_KEY].__STATE_KEY
71
72
  ];
72
73
  }
73
- __name(getOwnStateVars, "getOwnStateVars");
74
- function getStateVars(target) {
74
+ __name(getOwnStateKey, "getOwnStateKey");
75
+ function getStateKey(target) {
75
76
  let proto = getPhecdaFromTarget(target);
76
77
  const set2 = /* @__PURE__ */ new Set();
77
78
  while (proto?.[PHECDA_KEY]) {
78
- proto[PHECDA_KEY].__STATE_VAR__.forEach((item) => set2.add(item));
79
+ if (proto.hasOwnProperty(PHECDA_KEY))
80
+ proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
79
81
  proto = Object.getPrototypeOf(proto);
80
82
  }
81
83
  return [
82
84
  ...set2
83
85
  ];
84
86
  }
85
- __name(getStateVars, "getStateVars");
87
+ __name(getStateKey, "getStateKey");
86
88
  function getOwnExposeKey(target) {
87
89
  const proto = getPhecdaFromTarget(target);
88
90
  return [
89
- ...proto[PHECDA_KEY].__EXPOSE_VAR__
90
- ].filter((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item));
91
+ ...proto[PHECDA_KEY].__EXPOSE_KEY
92
+ ].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
91
93
  }
92
94
  __name(getOwnExposeKey, "getOwnExposeKey");
93
95
  function getExposeKey(target) {
94
96
  let proto = getPhecdaFromTarget(target);
95
97
  const set2 = /* @__PURE__ */ new Set();
98
+ const origin = proto;
96
99
  while (proto?.[PHECDA_KEY]) {
97
- [
98
- ...proto[PHECDA_KEY].__EXPOSE_VAR__
99
- ].forEach((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item) && set2.add(item));
100
+ if (proto.hasOwnProperty(PHECDA_KEY))
101
+ [
102
+ ...proto[PHECDA_KEY].__EXPOSE_KEY
103
+ ].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
100
104
  proto = Object.getPrototypeOf(proto);
101
105
  }
102
106
  return [
@@ -107,7 +111,7 @@ __name(getExposeKey, "getExposeKey");
107
111
  function getOwnIgnoreKey(target) {
108
112
  const proto = getPhecdaFromTarget(target);
109
113
  return [
110
- ...proto[PHECDA_KEY]?.__IGNORE_VAR__
114
+ ...proto[PHECDA_KEY]?.__IGNORE_KEY
111
115
  ];
112
116
  }
113
117
  __name(getOwnIgnoreKey, "getOwnIgnoreKey");
@@ -120,7 +124,11 @@ function getHandler(target, key) {
120
124
  let proto = getPhecdaFromTarget(target);
121
125
  const set2 = /* @__PURE__ */ new Set();
122
126
  while (proto?.[PHECDA_KEY]) {
123
- proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
127
+ if (proto.hasOwnProperty(PHECDA_KEY)) {
128
+ proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
129
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
130
+ break;
131
+ }
124
132
  proto = Object.getPrototypeOf(proto);
125
133
  }
126
134
  return [
@@ -132,12 +140,16 @@ function getState(target, key) {
132
140
  let proto = getPhecdaFromTarget(target);
133
141
  let ret = {};
134
142
  while (proto?.[PHECDA_KEY]) {
135
- const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
136
- if (state)
137
- ret = {
138
- ...state,
139
- ...ret
140
- };
143
+ if (proto.hasOwnProperty(PHECDA_KEY)) {
144
+ const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
145
+ if (state)
146
+ ret = {
147
+ ...state,
148
+ ...ret
149
+ };
150
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
151
+ break;
152
+ }
141
153
  proto = Object.getPrototypeOf(proto);
142
154
  }
143
155
  return ret;
@@ -148,27 +160,29 @@ function getOwnState(target, key) {
148
160
  return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
149
161
  }
150
162
  __name(getOwnState, "getOwnState");
151
- function invokeHandler(event, instance) {
152
- const stateVars = getExposeKey(instance);
163
+ function invokeHandler(event, module) {
164
+ const stateVars = getExposeKey(module);
153
165
  const initHandlers = stateVars.map((item) => {
154
- return getHandler(instance, item).filter((h) => !!h[event]).map((h) => h[event](instance));
166
+ return getHandler(module, item).filter((h) => !!h[event]).map((h) => h[event](module));
155
167
  }).flat();
156
168
  return Promise.all(initHandlers);
157
169
  }
158
170
  __name(invokeHandler, "invokeHandler");
159
171
  function set(proto, key, value) {
160
172
  init(proto);
161
- proto[PHECDA_KEY][`__${key.toUpperCase()}__`] = value;
173
+ setState(proto, SHARE_KEY, {
174
+ [`__${key.toUpperCase()}__`]: value
175
+ });
162
176
  }
163
177
  __name(set, "set");
164
178
  function get(proto, key) {
165
- return proto[PHECDA_KEY]?.[`__${key.toUpperCase()}__`];
179
+ return getState(proto, SHARE_KEY)[`__${key.toUpperCase()}__`];
166
180
  }
167
181
  __name(get, "get");
168
182
 
169
183
  // src/decorators/core.ts
170
184
  function Init(proto, key) {
171
- setStateVar(proto, key);
185
+ setStateKey(proto, key);
172
186
  setHandler(proto, key, {
173
187
  async init(instance) {
174
188
  return instance[key]();
@@ -177,7 +191,7 @@ function Init(proto, key) {
177
191
  }
178
192
  __name(Init, "Init");
179
193
  function Unmount(proto, key) {
180
- setStateVar(proto, key);
194
+ setStateKey(proto, key);
181
195
  setHandler(proto, key, {
182
196
  async unmount(instance) {
183
197
  return instance[key]();
@@ -187,32 +201,28 @@ function Unmount(proto, key) {
187
201
  __name(Unmount, "Unmount");
188
202
  function Bind(value) {
189
203
  return (proto, k) => {
190
- setStateVar(proto, k);
204
+ setStateKey(proto, k);
191
205
  setState(proto, k, {
192
206
  value
193
207
  });
194
208
  };
195
209
  }
196
210
  __name(Bind, "Bind");
197
- function Ignore(proto, key) {
211
+ function Ignore(proto, key = SHARE_KEY) {
198
212
  setIgnoreKey(proto, key);
199
213
  }
200
214
  __name(Ignore, "Ignore");
201
- function Clear(proto, key) {
215
+ function Clear(proto, key = SHARE_KEY) {
202
216
  init(proto);
203
- proto[PHECDA_KEY].__EXPOSE_VAR__.delete(key);
204
- proto[PHECDA_KEY].__IGNORE_VAR__.delete(key);
205
- proto[PHECDA_KEY].__STATE_VAR__.delete(key);
206
- proto[PHECDA_KEY].__STATE_HANDLER__.delete(key);
207
- proto[PHECDA_KEY].__STATE_NAMESPACE__.delete(key);
217
+ proto[PHECDA_KEY].__CLEAR_KEY.add(key);
208
218
  }
209
219
  __name(Clear, "Clear");
210
220
  function Expose(proto, key) {
211
221
  setExposeKey(proto, key);
212
222
  }
213
223
  __name(Expose, "Expose");
214
- function Empty(module) {
215
- init(module.prototype);
224
+ function Empty(model) {
225
+ init(model.prototype);
216
226
  }
217
227
  __name(Empty, "Empty");
218
228
 
@@ -220,12 +230,12 @@ __name(Empty, "Empty");
220
230
  function getTag(moduleOrInstance) {
221
231
  if (typeof moduleOrInstance === "object")
222
232
  moduleOrInstance = moduleOrInstance.constructor;
223
- return moduleOrInstance.prototype[PHECDA_KEY]?.__TAG__ || moduleOrInstance.name;
233
+ return get(moduleOrInstance.prototype, "tag") || moduleOrInstance.name;
224
234
  }
225
235
  __name(getTag, "getTag");
226
- function getBind(module) {
227
- const instance = new module();
228
- const keys = getStateVars(instance);
236
+ function getBind(model) {
237
+ const instance = new model();
238
+ const keys = getStateKey(instance);
229
239
  const ret = {};
230
240
  for (const item of keys) {
231
241
  const state = getState(instance, item);
@@ -235,8 +245,8 @@ function getBind(module) {
235
245
  return ret;
236
246
  }
237
247
  __name(getBind, "getBind");
238
- function plainToClass(module, input) {
239
- const instance = new module();
248
+ function plainToClass(model, input) {
249
+ const instance = new model();
240
250
  const keys = getExposeKey(instance);
241
251
  for (const item of keys)
242
252
  instance[item] = input[item];
@@ -380,28 +390,28 @@ function getKey(key) {
380
390
  __name(getKey, "getKey");
381
391
 
382
392
  // src/decorators/function.ts
383
- function Isolate(module) {
384
- set(module.prototype, "isolate", true);
385
- module.prototype[PHECDA_KEY].__ISOLATE__ = true;
393
+ function Isolate(model) {
394
+ set(model.prototype, "isolate", true);
395
+ model.prototype[PHECDA_KEY].__ISOLATE__ = true;
386
396
  }
387
397
  __name(Isolate, "Isolate");
388
398
  function Tag(tag) {
389
- return (module) => {
390
- set(module.prototype, "tag", tag);
399
+ return (model) => {
400
+ set(model.prototype, "tag", tag);
391
401
  };
392
402
  }
393
403
  __name(Tag, "Tag");
394
404
  function Unique(desc) {
395
- return (module) => {
396
- set(module.prototype, "tag", Symbol(desc || module.name));
405
+ return (model) => {
406
+ set(model.prototype, "tag", Symbol(desc || model.name));
397
407
  };
398
408
  }
399
409
  __name(Unique, "Unique");
400
410
  function Assign(cb) {
401
- return (module) => {
402
- init(module.prototype);
403
- setStateVar(module.prototype, SHARE_KEY);
404
- setHandler(module.prototype, SHARE_KEY, {
411
+ return (model) => {
412
+ init(model.prototype);
413
+ setStateKey(model.prototype, SHARE_KEY);
414
+ setHandler(model.prototype, SHARE_KEY, {
405
415
  init: async (instance) => {
406
416
  const value = await cb(instance);
407
417
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -413,10 +423,10 @@ function Assign(cb) {
413
423
  };
414
424
  }
415
425
  __name(Assign, "Assign");
416
- function Global(module) {
417
- init(module.prototype);
418
- setStateVar(module.prototype, SHARE_KEY);
419
- setHandler(module.prototype, SHARE_KEY, {
426
+ function Global(model) {
427
+ init(model.prototype);
428
+ setStateKey(model.prototype, SHARE_KEY);
429
+ setHandler(model.prototype, SHARE_KEY, {
420
430
  init: async (instance) => {
421
431
  const tag = instance[PHECDA_KEY].__TAG__;
422
432
  if (!tag)
@@ -430,7 +440,7 @@ function Global(module) {
430
440
  __name(Global, "Global");
431
441
  function To(...callbacks) {
432
442
  return (proto, key) => {
433
- setStateVar(proto, key);
443
+ setStateKey(proto, key);
434
444
  setHandler(proto, key, {
435
445
  async pipe(instance, addError) {
436
446
  for (const cb of callbacks) {
@@ -450,7 +460,7 @@ function To(...callbacks) {
450
460
  __name(To, "To");
451
461
  function Rule(cb, info) {
452
462
  return (proto, key) => {
453
- setStateVar(proto, key);
463
+ setStateKey(proto, key);
454
464
  setHandler(proto, key, {
455
465
  async pipe(instance, addError) {
456
466
  let ret;
@@ -471,7 +481,7 @@ function Rule(cb, info) {
471
481
  __name(Rule, "Rule");
472
482
  function Err(cb, isCatch = false) {
473
483
  return (proto, key) => {
474
- setStateVar(proto, key);
484
+ setStateKey(proto, key);
475
485
  setHandler(proto, key, {
476
486
  init: (instance) => {
477
487
  if (typeof instance[key] === "function") {
@@ -506,7 +516,7 @@ __name(Err, "Err");
506
516
  function Watcher(eventName, options) {
507
517
  let cb;
508
518
  return (proto, key) => {
509
- setStateVar(proto, key);
519
+ setStateKey(proto, key);
510
520
  setHandler(proto, key, {
511
521
  init(instance) {
512
522
  return cb = getKey("watcher")?.({
@@ -525,7 +535,7 @@ function Watcher(eventName, options) {
525
535
  __name(Watcher, "Watcher");
526
536
  function Effect(cb) {
527
537
  return (proto, key) => {
528
- setStateVar(proto, key);
538
+ setStateKey(proto, key);
529
539
  setHandler(proto, key, {
530
540
  init(instance) {
531
541
  instance[`$_${key}`] = instance[key];
@@ -554,7 +564,7 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
554
564
  if (key) {
555
565
  init(proto);
556
566
  tag = storeKey || `${getTag(proto)}_${key}`;
557
- setStateVar(proto, key);
567
+ setStateKey(proto, key);
558
568
  setHandler(proto, key, {
559
569
  init: (instance) => {
560
570
  return getKey("storage")?.({
@@ -569,7 +579,7 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
569
579
  } else {
570
580
  init(proto.prototype);
571
581
  tag = storeKey || getTag(proto);
572
- setStateVar(proto.prototype, SHARE_KEY);
582
+ setStateKey(proto.prototype, SHARE_KEY);
573
583
  setHandler(proto.prototype, SHARE_KEY, {
574
584
  init: (instance) => {
575
585
  return getKey("storage")?.({
@@ -622,9 +632,10 @@ export {
622
632
  getOwnHandler,
623
633
  getOwnIgnoreKey,
624
634
  getOwnState,
625
- getOwnStateVars,
635
+ getOwnStateKey,
636
+ getPhecdaFromTarget,
626
637
  getState,
627
- getStateVars,
638
+ getStateKey,
628
639
  getTag,
629
640
  init,
630
641
  injectKey,
@@ -637,7 +648,7 @@ export {
637
648
  setHandler,
638
649
  setIgnoreKey,
639
650
  setState,
640
- setStateVar,
651
+ setStateKey,
641
652
  snapShot,
642
653
  transformInstance,
643
654
  transformInstanceAsync,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "3.0.0-beta.13",
3
+ "version": "3.0.0-beta.15",
4
4
  "description": "provide base function and abstract limit to other phecda module ",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",