phecda-core 3.0.0-beta.16 → 3.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.ts CHANGED
@@ -11,11 +11,11 @@ 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, handler: Handler): void;
18
- declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
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
19
  declare function getOwnStateKey(target: any): string[];
20
20
  declare function getStateKey(target: any): PropertyKey[];
21
21
  declare function getOwnExposeKey(target: any): string[];
@@ -23,8 +23,8 @@ declare function getExposeKey(target: any): PropertyKey[];
23
23
  declare function getOwnIgnoreKey(target: any): string[];
24
24
  declare function getOwnHandler(target: any, key: PropertyKey): Handler[];
25
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>;
26
+ declare function getState(target: any, key?: PropertyKey): any;
27
+ declare function getOwnState(target: any, key?: PropertyKey): Record<string, any>;
28
28
  declare function invokeHandler(event: string, module: Phecda): Promise<any[]>;
29
29
  declare function set(proto: any, key: string, value: any): void;
30
30
  declare function get(proto: any, key: string): any;
@@ -103,9 +103,11 @@ declare function snapShot<T extends Construct>(data: InstanceType<T>): {
103
103
  clear(): void;
104
104
  apply(): void;
105
105
  };
106
- declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> | PropertyKey, handler: PropertyDecorator | ClassDecorator): void;
106
+ declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> | PropertyKey | undefined, handler: PropertyDecorator | ClassDecorator): void;
107
107
  declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
108
108
  declare function isAsyncFunc(fn: Function): boolean;
109
+ declare function setPropertyState(target: any, k: undefined | PropertyKey, setter: (state: Record<string, any>) => void): void;
110
+ declare function getShareState<State>(target: any, getter: (state: Record<string, any>) => State): State;
109
111
 
110
112
  declare const DataMap: InjectData;
111
113
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
@@ -114,4 +116,4 @@ declare const activeInstance: Record<string, any>;
114
116
  declare function setInject(key: string, value: any): Record<string, any>;
115
117
  declare function getInject(key: string): any;
116
118
 
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, getInject, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateKey, getPhecdaFromTarget, getState, getStateKey, getTag, init, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setInject, setState, setStateKey, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
119
+ 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, 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 };
package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ __export(src_exports, {
59
59
  getOwnState: () => getOwnState,
60
60
  getOwnStateKey: () => getOwnStateKey,
61
61
  getPhecdaFromTarget: () => getPhecdaFromTarget,
62
+ getShareState: () => getShareState,
62
63
  getState: () => getState,
63
64
  getStateKey: () => getStateKey,
64
65
  getTag: () => getTag,
@@ -72,6 +73,7 @@ __export(src_exports, {
72
73
  setHandler: () => setHandler,
73
74
  setIgnoreKey: () => setIgnoreKey,
74
75
  setInject: () => setInject,
76
+ setPropertyState: () => setPropertyState,
75
77
  setState: () => setState,
76
78
  setStateKey: () => setStateKey,
77
79
  snapShot: () => snapShot,
@@ -115,22 +117,38 @@ function getPhecdaFromTarget(target) {
115
117
  }
116
118
  __name(getPhecdaFromTarget, "getPhecdaFromTarget");
117
119
  function setStateKey(proto, key) {
120
+ if (!key) {
121
+ key = SHARE_KEY;
122
+ proto = proto.prototype;
123
+ }
118
124
  init(proto);
119
125
  proto[PHECDA_KEY].__STATE_KEY.add(key);
120
126
  setExposeKey(proto, key);
121
127
  }
122
128
  __name(setStateKey, "setStateKey");
123
129
  function setExposeKey(proto, key) {
130
+ if (!key) {
131
+ key = SHARE_KEY;
132
+ proto = proto.prototype;
133
+ }
124
134
  init(proto);
125
135
  proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
126
136
  }
127
137
  __name(setExposeKey, "setExposeKey");
128
138
  function setIgnoreKey(proto, key) {
139
+ if (!key) {
140
+ key = SHARE_KEY;
141
+ proto = proto.prototype;
142
+ }
129
143
  init(proto);
130
144
  proto[PHECDA_KEY].__IGNORE_KEY.add(key);
131
145
  }
132
146
  __name(setIgnoreKey, "setIgnoreKey");
133
147
  function setHandler(proto, key, handler) {
148
+ if (!key) {
149
+ key = SHARE_KEY;
150
+ proto = proto.prototype;
151
+ }
134
152
  init(proto);
135
153
  if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
136
154
  proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [
@@ -141,6 +159,10 @@ function setHandler(proto, key, handler) {
141
159
  }
142
160
  __name(setHandler, "setHandler");
143
161
  function setState(proto, key, state) {
162
+ if (!key) {
163
+ key = SHARE_KEY;
164
+ proto = proto.prototype;
165
+ }
144
166
  init(proto);
145
167
  const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
146
168
  namespace.set(key, state);
@@ -217,7 +239,7 @@ function getHandler(target, key) {
217
239
  ];
218
240
  }
219
241
  __name(getHandler, "getHandler");
220
- function getState(target, key) {
242
+ function getState(target, key = SHARE_KEY) {
221
243
  let proto = getPhecdaFromTarget(target);
222
244
  let ret = {};
223
245
  while (proto?.[PHECDA_KEY]) {
@@ -236,7 +258,7 @@ function getState(target, key) {
236
258
  return ret;
237
259
  }
238
260
  __name(getState, "getState");
239
- function getOwnState(target, key) {
261
+ function getOwnState(target, key = SHARE_KEY) {
240
262
  const proto = getPhecdaFromTarget(target);
241
263
  return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
242
264
  }
@@ -287,11 +309,19 @@ function Bind(value) {
287
309
  };
288
310
  }
289
311
  __name(Bind, "Bind");
290
- function Ignore(proto, key = SHARE_KEY) {
312
+ function Ignore(proto, key) {
313
+ if (!key) {
314
+ proto = proto.prototype;
315
+ key = SHARE_KEY;
316
+ }
291
317
  setIgnoreKey(proto, key);
292
318
  }
293
319
  __name(Ignore, "Ignore");
294
- function Clear(proto, key = SHARE_KEY) {
320
+ function Clear(proto, key) {
321
+ if (!key) {
322
+ proto = proto.prototype;
323
+ key = SHARE_KEY;
324
+ }
295
325
  init(proto);
296
326
  proto[PHECDA_KEY].__CLEAR_KEY.add(key);
297
327
  }
@@ -432,7 +462,7 @@ function snapShot(data) {
432
462
  }
433
463
  __name(snapShot, "snapShot");
434
464
  function addDecoToClass(c, key, handler) {
435
- handler(key === SHARE_KEY ? c : c.prototype, key);
465
+ handler(key ? c.prototype : c, key);
436
466
  }
437
467
  __name(addDecoToClass, "addDecoToClass");
438
468
  function Pipeline(...decos) {
@@ -446,6 +476,18 @@ function isAsyncFunc(fn) {
446
476
  return fn[Symbol.toStringTag] === "AsyncFunction";
447
477
  }
448
478
  __name(isAsyncFunc, "isAsyncFunc");
479
+ function setPropertyState(target, k, setter) {
480
+ setStateKey(target, k);
481
+ const state = getOwnState(target, k) || {};
482
+ setter(state);
483
+ setState(target, k, state);
484
+ }
485
+ __name(setPropertyState, "setPropertyState");
486
+ function getShareState(target, getter) {
487
+ const state = getOwnState(target, SHARE_KEY) || {};
488
+ return getter(state);
489
+ }
490
+ __name(getShareState, "getShareState");
449
491
 
450
492
  // src/di.ts
451
493
  var DataMap = {};
@@ -488,9 +530,8 @@ function Unique(desc) {
488
530
  __name(Unique, "Unique");
489
531
  function Assign(cb) {
490
532
  return (model) => {
491
- init(model.prototype);
492
- setStateKey(model.prototype, SHARE_KEY);
493
- setHandler(model.prototype, SHARE_KEY, {
533
+ setStateKey(model);
534
+ setHandler(model, void 0, {
494
535
  init: async (instance) => {
495
536
  const value = await cb(instance);
496
537
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -503,9 +544,8 @@ function Assign(cb) {
503
544
  }
504
545
  __name(Assign, "Assign");
505
546
  function Global(model) {
506
- init(model.prototype);
507
- setStateKey(model.prototype, SHARE_KEY);
508
- setHandler(model.prototype, SHARE_KEY, {
547
+ setStateKey(model);
548
+ setHandler(model, void 0, {
509
549
  init: async (instance) => {
510
550
  const tag = instance[PHECDA_KEY].__TAG__;
511
551
  if (!tag)
@@ -638,9 +678,7 @@ function Storage({ key: storeKey, json, stringify } = {}) {
638
678
  json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
639
679
  if (!stringify)
640
680
  stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
641
- return (proto, key = SHARE_KEY) => {
642
- if (typeof proto === "function")
643
- proto = proto.prototype;
681
+ return (proto, key) => {
644
682
  const tag = storeKey || getTag(proto);
645
683
  init(proto);
646
684
  setStateKey(proto, key);
@@ -698,6 +736,7 @@ __name(Storage, "Storage");
698
736
  getOwnState,
699
737
  getOwnStateKey,
700
738
  getPhecdaFromTarget,
739
+ getShareState,
701
740
  getState,
702
741
  getStateKey,
703
742
  getTag,
@@ -711,6 +750,7 @@ __name(Storage, "Storage");
711
750
  setHandler,
712
751
  setIgnoreKey,
713
752
  setInject,
753
+ setPropertyState,
714
754
  setState,
715
755
  setStateKey,
716
756
  snapShot,
package/dist/index.mjs CHANGED
@@ -34,22 +34,38 @@ function getPhecdaFromTarget(target) {
34
34
  }
35
35
  __name(getPhecdaFromTarget, "getPhecdaFromTarget");
36
36
  function setStateKey(proto, key) {
37
+ if (!key) {
38
+ key = SHARE_KEY;
39
+ proto = proto.prototype;
40
+ }
37
41
  init(proto);
38
42
  proto[PHECDA_KEY].__STATE_KEY.add(key);
39
43
  setExposeKey(proto, key);
40
44
  }
41
45
  __name(setStateKey, "setStateKey");
42
46
  function setExposeKey(proto, key) {
47
+ if (!key) {
48
+ key = SHARE_KEY;
49
+ proto = proto.prototype;
50
+ }
43
51
  init(proto);
44
52
  proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
45
53
  }
46
54
  __name(setExposeKey, "setExposeKey");
47
55
  function setIgnoreKey(proto, key) {
56
+ if (!key) {
57
+ key = SHARE_KEY;
58
+ proto = proto.prototype;
59
+ }
48
60
  init(proto);
49
61
  proto[PHECDA_KEY].__IGNORE_KEY.add(key);
50
62
  }
51
63
  __name(setIgnoreKey, "setIgnoreKey");
52
64
  function setHandler(proto, key, handler) {
65
+ if (!key) {
66
+ key = SHARE_KEY;
67
+ proto = proto.prototype;
68
+ }
53
69
  init(proto);
54
70
  if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
55
71
  proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [
@@ -60,6 +76,10 @@ function setHandler(proto, key, handler) {
60
76
  }
61
77
  __name(setHandler, "setHandler");
62
78
  function setState(proto, key, state) {
79
+ if (!key) {
80
+ key = SHARE_KEY;
81
+ proto = proto.prototype;
82
+ }
63
83
  init(proto);
64
84
  const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
65
85
  namespace.set(key, state);
@@ -136,7 +156,7 @@ function getHandler(target, key) {
136
156
  ];
137
157
  }
138
158
  __name(getHandler, "getHandler");
139
- function getState(target, key) {
159
+ function getState(target, key = SHARE_KEY) {
140
160
  let proto = getPhecdaFromTarget(target);
141
161
  let ret = {};
142
162
  while (proto?.[PHECDA_KEY]) {
@@ -155,7 +175,7 @@ function getState(target, key) {
155
175
  return ret;
156
176
  }
157
177
  __name(getState, "getState");
158
- function getOwnState(target, key) {
178
+ function getOwnState(target, key = SHARE_KEY) {
159
179
  const proto = getPhecdaFromTarget(target);
160
180
  return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
161
181
  }
@@ -206,11 +226,19 @@ function Bind(value) {
206
226
  };
207
227
  }
208
228
  __name(Bind, "Bind");
209
- function Ignore(proto, key = SHARE_KEY) {
229
+ function Ignore(proto, key) {
230
+ if (!key) {
231
+ proto = proto.prototype;
232
+ key = SHARE_KEY;
233
+ }
210
234
  setIgnoreKey(proto, key);
211
235
  }
212
236
  __name(Ignore, "Ignore");
213
- function Clear(proto, key = SHARE_KEY) {
237
+ function Clear(proto, key) {
238
+ if (!key) {
239
+ proto = proto.prototype;
240
+ key = SHARE_KEY;
241
+ }
214
242
  init(proto);
215
243
  proto[PHECDA_KEY].__CLEAR_KEY.add(key);
216
244
  }
@@ -351,7 +379,7 @@ function snapShot(data) {
351
379
  }
352
380
  __name(snapShot, "snapShot");
353
381
  function addDecoToClass(c, key, handler) {
354
- handler(key === SHARE_KEY ? c : c.prototype, key);
382
+ handler(key ? c.prototype : c, key);
355
383
  }
356
384
  __name(addDecoToClass, "addDecoToClass");
357
385
  function Pipeline(...decos) {
@@ -365,6 +393,18 @@ function isAsyncFunc(fn) {
365
393
  return fn[Symbol.toStringTag] === "AsyncFunction";
366
394
  }
367
395
  __name(isAsyncFunc, "isAsyncFunc");
396
+ function setPropertyState(target, k, setter) {
397
+ setStateKey(target, k);
398
+ const state = getOwnState(target, k) || {};
399
+ setter(state);
400
+ setState(target, k, state);
401
+ }
402
+ __name(setPropertyState, "setPropertyState");
403
+ function getShareState(target, getter) {
404
+ const state = getOwnState(target, SHARE_KEY) || {};
405
+ return getter(state);
406
+ }
407
+ __name(getShareState, "getShareState");
368
408
 
369
409
  // src/di.ts
370
410
  var DataMap = {};
@@ -407,9 +447,8 @@ function Unique(desc) {
407
447
  __name(Unique, "Unique");
408
448
  function Assign(cb) {
409
449
  return (model) => {
410
- init(model.prototype);
411
- setStateKey(model.prototype, SHARE_KEY);
412
- setHandler(model.prototype, SHARE_KEY, {
450
+ setStateKey(model);
451
+ setHandler(model, void 0, {
413
452
  init: async (instance) => {
414
453
  const value = await cb(instance);
415
454
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -422,9 +461,8 @@ function Assign(cb) {
422
461
  }
423
462
  __name(Assign, "Assign");
424
463
  function Global(model) {
425
- init(model.prototype);
426
- setStateKey(model.prototype, SHARE_KEY);
427
- setHandler(model.prototype, SHARE_KEY, {
464
+ setStateKey(model);
465
+ setHandler(model, void 0, {
428
466
  init: async (instance) => {
429
467
  const tag = instance[PHECDA_KEY].__TAG__;
430
468
  if (!tag)
@@ -557,9 +595,7 @@ function Storage({ key: storeKey, json, stringify } = {}) {
557
595
  json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
558
596
  if (!stringify)
559
597
  stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
560
- return (proto, key = SHARE_KEY) => {
561
- if (typeof proto === "function")
562
- proto = proto.prototype;
598
+ return (proto, key) => {
563
599
  const tag = storeKey || getTag(proto);
564
600
  init(proto);
565
601
  setStateKey(proto, key);
@@ -616,6 +652,7 @@ export {
616
652
  getOwnState,
617
653
  getOwnStateKey,
618
654
  getPhecdaFromTarget,
655
+ getShareState,
619
656
  getState,
620
657
  getStateKey,
621
658
  getTag,
@@ -629,6 +666,7 @@ export {
629
666
  setHandler,
630
667
  setIgnoreKey,
631
668
  setInject,
669
+ setPropertyState,
632
670
  setState,
633
671
  setStateKey,
634
672
  snapShot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "3.0.0-beta.16",
3
+ "version": "3.0.0",
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",