phecda-core 3.0.0-alpha.8 → 3.0.0-beta.13

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.js CHANGED
@@ -34,9 +34,10 @@ __export(src_exports, {
34
34
  Init: () => Init,
35
35
  Inject: () => Inject,
36
36
  Isolate: () => Isolate,
37
- Nested: () => Nested,
37
+ PHECDA_KEY: () => PHECDA_KEY,
38
38
  Pipeline: () => Pipeline,
39
39
  Provide: () => Provide,
40
+ Rule: () => Rule,
40
41
  SHARE_KEY: () => SHARE_KEY,
41
42
  Storage: () => Storage,
42
43
  Tag: () => Tag,
@@ -46,49 +47,54 @@ __export(src_exports, {
46
47
  Watcher: () => Watcher,
47
48
  activeInstance: () => activeInstance,
48
49
  addDecoToClass: () => addDecoToClass,
49
- classToValue: () => classToValue,
50
+ classToPlain: () => classToPlain,
51
+ get: () => get,
50
52
  getBind: () => getBind,
51
53
  getExposeKey: () => getExposeKey,
52
54
  getHandler: () => getHandler,
53
- getModuleState: () => getModuleState,
55
+ getKey: () => getKey,
54
56
  getOwnExposeKey: () => getOwnExposeKey,
55
57
  getOwnHandler: () => getOwnHandler,
56
58
  getOwnIgnoreKey: () => getOwnIgnoreKey,
57
- getOwnModuleState: () => getOwnModuleState,
58
59
  getOwnState: () => getOwnState,
59
- getProperty: () => getProperty,
60
+ getOwnStateVars: () => getOwnStateVars,
60
61
  getState: () => getState,
62
+ getStateVars: () => getStateVars,
61
63
  getTag: () => getTag,
62
64
  init: () => init,
63
- injectProperty: () => injectProperty,
65
+ injectKey: () => injectKey,
66
+ invokeHandler: () => invokeHandler,
67
+ isAsyncFunc: () => isAsyncFunc,
64
68
  isPhecda: () => isPhecda,
65
69
  plainToClass: () => plainToClass,
66
- regisHandler: () => regisHandler,
67
- registerParallel: () => registerParallel,
68
- registerSerial: () => registerSerial,
70
+ set: () => set,
69
71
  setExposeKey: () => setExposeKey,
72
+ setHandler: () => setHandler,
70
73
  setIgnoreKey: () => setIgnoreKey,
71
74
  setState: () => setState,
72
- setVar: () => setVar,
75
+ setStateVar: () => setStateVar,
73
76
  snapShot: () => snapShot,
74
- transformClass: () => transformClass,
75
- unmountParallel: () => unmountParallel
77
+ transformInstance: () => transformInstance,
78
+ transformInstanceAsync: () => transformInstanceAsync,
79
+ transformProperty: () => transformProperty,
80
+ transformPropertyAsync: () => transformPropertyAsync
76
81
  });
77
82
  module.exports = __toCommonJS(src_exports);
78
83
 
79
84
  // src/core.ts
85
+ var SHARE_KEY = Symbol("phecda");
86
+ var PHECDA_KEY = Symbol("phecda");
80
87
  function isPhecda(module2) {
81
88
  if (typeof module2 === "function")
82
- return !!module2.prototype?._namespace;
89
+ return !!module2.prototype[PHECDA_KEY];
83
90
  return false;
84
91
  }
85
92
  __name(isPhecda, "isPhecda");
86
- var SHARE_KEY = Symbol("phecda-core");
87
93
  function init(proto) {
88
94
  if (!proto)
89
95
  return;
90
- if (!proto.hasOwnProperty("_namespace")) {
91
- proto._namespace = {
96
+ if (!proto.hasOwnProperty(PHECDA_KEY)) {
97
+ proto[PHECDA_KEY] = {
92
98
  __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
93
99
  __IGNORE_VAR__: /* @__PURE__ */ new Set(),
94
100
  __STATE_VAR__: /* @__PURE__ */ new Set(),
@@ -98,114 +104,115 @@ function init(proto) {
98
104
  }
99
105
  }
100
106
  __name(init, "init");
101
- function setVar(proto, key) {
107
+ function getPhecdaFromTarget(target) {
108
+ if (typeof target === "function")
109
+ return target.prototype;
110
+ if (target.hasOwnProperty(PHECDA_KEY))
111
+ return target;
112
+ return Object.getPrototypeOf(target);
113
+ }
114
+ __name(getPhecdaFromTarget, "getPhecdaFromTarget");
115
+ function setStateVar(proto, key) {
102
116
  init(proto);
103
- proto._namespace.__STATE_VAR__.add(key);
117
+ proto[PHECDA_KEY].__STATE_VAR__.add(key);
104
118
  setExposeKey(proto, key);
105
119
  }
106
- __name(setVar, "setVar");
120
+ __name(setStateVar, "setStateVar");
107
121
  function setExposeKey(proto, key) {
108
122
  init(proto);
109
- proto._namespace.__EXPOSE_VAR__.add(key);
123
+ proto[PHECDA_KEY].__EXPOSE_VAR__.add(key);
110
124
  }
111
125
  __name(setExposeKey, "setExposeKey");
112
126
  function setIgnoreKey(proto, key) {
113
127
  init(proto);
114
- proto._namespace.__IGNORE_VAR__.add(key);
128
+ proto[PHECDA_KEY].__IGNORE_VAR__.add(key);
115
129
  }
116
130
  __name(setIgnoreKey, "setIgnoreKey");
117
- function getOwnModuleState(instance) {
118
- instance = Object.getPrototypeOf(instance);
131
+ function setHandler(proto, key, handler) {
132
+ init(proto);
133
+ if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
134
+ proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [
135
+ handler
136
+ ]);
137
+ else
138
+ proto[PHECDA_KEY].__STATE_HANDLER__.get(key).push(handler);
139
+ }
140
+ __name(setHandler, "setHandler");
141
+ function setState(proto, key, state) {
142
+ init(proto);
143
+ const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
144
+ namespace.set(key, state);
145
+ }
146
+ __name(setState, "setState");
147
+ function getOwnStateVars(target) {
148
+ const proto = getPhecdaFromTarget(target);
119
149
  return [
120
- ...instance._namespace.__STATE_VAR__
150
+ ...proto[PHECDA_KEY].__STATE_VAR__
121
151
  ];
122
152
  }
123
- __name(getOwnModuleState, "getOwnModuleState");
124
- function getModuleState(instance) {
125
- let proto = Object.getPrototypeOf(instance);
126
- const set = /* @__PURE__ */ new Set();
127
- while (proto?._namespace) {
128
- proto._namespace.__STATE_VAR__.forEach((item) => set.add(item));
153
+ __name(getOwnStateVars, "getOwnStateVars");
154
+ function getStateVars(target) {
155
+ let proto = getPhecdaFromTarget(target);
156
+ const set2 = /* @__PURE__ */ new Set();
157
+ while (proto?.[PHECDA_KEY]) {
158
+ proto[PHECDA_KEY].__STATE_VAR__.forEach((item) => set2.add(item));
129
159
  proto = Object.getPrototypeOf(proto);
130
160
  }
131
161
  return [
132
- ...set
162
+ ...set2
133
163
  ];
134
164
  }
135
- __name(getModuleState, "getModuleState");
136
- function getOwnExposeKey(instance) {
137
- instance = Object.getPrototypeOf(instance);
165
+ __name(getStateVars, "getStateVars");
166
+ function getOwnExposeKey(target) {
167
+ const proto = getPhecdaFromTarget(target);
138
168
  return [
139
- ...instance._namespace.__EXPOSE_VAR__
140
- ].filter((item) => !instance._namespace.__IGNORE_VAR__.has(item));
169
+ ...proto[PHECDA_KEY].__EXPOSE_VAR__
170
+ ].filter((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item));
141
171
  }
142
172
  __name(getOwnExposeKey, "getOwnExposeKey");
143
- function getExposeKey(instance) {
144
- let proto = Object.getPrototypeOf(instance);
145
- const set = /* @__PURE__ */ new Set();
146
- while (proto?._namespace) {
173
+ function getExposeKey(target) {
174
+ let proto = getPhecdaFromTarget(target);
175
+ const set2 = /* @__PURE__ */ new Set();
176
+ while (proto?.[PHECDA_KEY]) {
147
177
  [
148
- ...proto._namespace.__EXPOSE_VAR__
149
- ].forEach((item) => !proto._namespace.__IGNORE_VAR__.has(item) && set.add(item));
178
+ ...proto[PHECDA_KEY].__EXPOSE_VAR__
179
+ ].forEach((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item) && set2.add(item));
150
180
  proto = Object.getPrototypeOf(proto);
151
181
  }
152
182
  return [
153
- ...set
183
+ ...set2
154
184
  ];
155
185
  }
156
186
  __name(getExposeKey, "getExposeKey");
157
- function getOwnIgnoreKey(instance) {
158
- if (!instance?._namespace)
159
- return [];
187
+ function getOwnIgnoreKey(target) {
188
+ const proto = getPhecdaFromTarget(target);
160
189
  return [
161
- ...instance._namespace.__IGNORE_VAR__
190
+ ...proto[PHECDA_KEY]?.__IGNORE_VAR__
162
191
  ];
163
192
  }
164
193
  __name(getOwnIgnoreKey, "getOwnIgnoreKey");
165
- function regisHandler(proto, key, handler) {
166
- init(proto);
167
- if (!proto._namespace.__STATE_HANDLER__.has(key))
168
- proto._namespace.__STATE_HANDLER__.set(key, [
169
- handler
170
- ]);
171
- else
172
- proto._namespace.__STATE_HANDLER__.get(key).push(handler);
173
- }
174
- __name(regisHandler, "regisHandler");
175
- function getOwnHandler(instance, key) {
176
- if (!instance?._namespace)
177
- return [];
178
- return instance._namespace.__STATE_HANDLER__.get(key) || [];
194
+ function getOwnHandler(target, key) {
195
+ const proto = getPhecdaFromTarget(target);
196
+ return proto[PHECDA_KEY]?.__STATE_HANDLER__.get(key) || [];
179
197
  }
180
198
  __name(getOwnHandler, "getOwnHandler");
181
- function getHandler(instance, key) {
182
- let proto = Object.getPrototypeOf(instance);
183
- const set = /* @__PURE__ */ new Set();
184
- while (proto?._namespace) {
185
- proto._namespace.__STATE_HANDLER__.get(key)?.forEach((item) => set.add(item));
199
+ function getHandler(target, key) {
200
+ let proto = getPhecdaFromTarget(target);
201
+ const set2 = /* @__PURE__ */ new Set();
202
+ while (proto?.[PHECDA_KEY]) {
203
+ proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
186
204
  proto = Object.getPrototypeOf(proto);
187
205
  }
188
206
  return [
189
- ...set
207
+ ...set2
190
208
  ];
191
209
  }
192
210
  __name(getHandler, "getHandler");
193
- function setState(proto, key, state) {
194
- init(proto);
195
- const namespace = proto._namespace.__STATE_NAMESPACE__;
196
- namespace.set(key, state);
197
- }
198
- __name(setState, "setState");
199
- function getOwnState(instance, key) {
200
- instance = Object.getPrototypeOf(instance);
201
- return instance._namespace.__STATE_NAMESPACE__.get(key) || {};
202
- }
203
- __name(getOwnState, "getOwnState");
204
- function getState(instance, key) {
205
- let proto = Object.getPrototypeOf(instance);
211
+ function getState(target, key) {
212
+ let proto = getPhecdaFromTarget(target);
206
213
  let ret = {};
207
- while (proto?._namespace) {
208
- const state = proto._namespace.__STATE_NAMESPACE__.get(key);
214
+ while (proto?.[PHECDA_KEY]) {
215
+ const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
209
216
  if (state)
210
217
  ret = {
211
218
  ...state,
@@ -216,42 +223,89 @@ function getState(instance, key) {
216
223
  return ret;
217
224
  }
218
225
  __name(getState, "getState");
219
- function registerParallel(instance) {
226
+ function getOwnState(target, key) {
227
+ const proto = getPhecdaFromTarget(target);
228
+ return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
229
+ }
230
+ __name(getOwnState, "getOwnState");
231
+ function invokeHandler(event, instance) {
220
232
  const stateVars = getExposeKey(instance);
221
233
  const initHandlers = stateVars.map((item) => {
222
- return getHandler(instance, item).filter((h) => h.init).map((h) => h.init(instance));
234
+ return getHandler(instance, item).filter((h) => !!h[event]).map((h) => h[event](instance));
223
235
  }).flat();
224
236
  return Promise.all(initHandlers);
225
237
  }
226
- __name(registerParallel, "registerParallel");
227
- async function registerSerial(instance) {
228
- const stateVars = getExposeKey(instance);
229
- for (const item of stateVars) {
230
- const handlers = getHandler(instance, item);
231
- for (const hanlder of handlers)
232
- await hanlder.init?.(instance);
233
- }
238
+ __name(invokeHandler, "invokeHandler");
239
+ function set(proto, key, value) {
240
+ init(proto);
241
+ proto[PHECDA_KEY][`__${key.toUpperCase()}__`] = value;
234
242
  }
235
- __name(registerSerial, "registerSerial");
236
- function unmountParallel(instance) {
237
- const stateVars = getExposeKey(instance);
238
- const initHandlers = stateVars.map((item) => {
239
- return getHandler(instance, item).filter((h) => h.unmount).map((h) => h.init(instance));
240
- }).flat();
241
- return Promise.all(initHandlers);
243
+ __name(set, "set");
244
+ function get(proto, key) {
245
+ return proto[PHECDA_KEY]?.[`__${key.toUpperCase()}__`];
242
246
  }
243
- __name(unmountParallel, "unmountParallel");
247
+ __name(get, "get");
248
+
249
+ // src/decorators/core.ts
250
+ function Init(proto, key) {
251
+ setStateVar(proto, key);
252
+ setHandler(proto, key, {
253
+ async init(instance) {
254
+ return instance[key]();
255
+ }
256
+ });
257
+ }
258
+ __name(Init, "Init");
259
+ function Unmount(proto, key) {
260
+ setStateVar(proto, key);
261
+ setHandler(proto, key, {
262
+ async unmount(instance) {
263
+ return instance[key]();
264
+ }
265
+ });
266
+ }
267
+ __name(Unmount, "Unmount");
268
+ function Bind(value) {
269
+ return (proto, k) => {
270
+ setStateVar(proto, k);
271
+ setState(proto, k, {
272
+ value
273
+ });
274
+ };
275
+ }
276
+ __name(Bind, "Bind");
277
+ function Ignore(proto, key) {
278
+ setIgnoreKey(proto, key);
279
+ }
280
+ __name(Ignore, "Ignore");
281
+ function Clear(proto, key) {
282
+ 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);
288
+ }
289
+ __name(Clear, "Clear");
290
+ function Expose(proto, key) {
291
+ setExposeKey(proto, key);
292
+ }
293
+ __name(Expose, "Expose");
294
+ function Empty(module2) {
295
+ init(module2.prototype);
296
+ }
297
+ __name(Empty, "Empty");
244
298
 
245
299
  // src/helper.ts
246
300
  function getTag(moduleOrInstance) {
247
301
  if (typeof moduleOrInstance === "object")
248
302
  moduleOrInstance = moduleOrInstance.constructor;
249
- return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
303
+ return moduleOrInstance.prototype[PHECDA_KEY]?.__TAG__ || moduleOrInstance.name;
250
304
  }
251
305
  __name(getTag, "getTag");
252
306
  function getBind(module2) {
253
307
  const instance = new module2();
254
- const keys = getModuleState(instance);
308
+ const keys = getStateVars(instance);
255
309
  const ret = {};
256
310
  for (const item of keys) {
257
311
  const state = getState(instance, item);
@@ -269,35 +323,88 @@ function plainToClass(module2, input) {
269
323
  return instance;
270
324
  }
271
325
  __name(plainToClass, "plainToClass");
272
- async function transformClass(instance, force = false) {
326
+ function transformInstance(instance, force = false) {
327
+ const err = [];
328
+ const keys = getExposeKey(instance);
329
+ const addError = err.push.bind(err);
330
+ for (const item of keys) {
331
+ const handlers = getHandler(instance, item);
332
+ if (handlers) {
333
+ for (const handler of handlers) {
334
+ const pipe = handler.pipe;
335
+ if (!pipe)
336
+ continue;
337
+ pipe(instance, addError);
338
+ if (err.length && !force)
339
+ return err;
340
+ }
341
+ }
342
+ }
343
+ return err;
344
+ }
345
+ __name(transformInstance, "transformInstance");
346
+ async function transformInstanceAsync(instance, force = false) {
273
347
  const err = [];
274
- const stateVars = getModuleState(instance);
275
- for (const item of stateVars) {
348
+ const keys = getExposeKey(instance);
349
+ const addError = err.push.bind(err);
350
+ for (const item of keys) {
276
351
  const handlers = getHandler(instance, item);
277
352
  if (handlers) {
278
353
  for (const handler of handlers) {
279
354
  const pipe = handler.pipe;
280
- try {
281
- await pipe(instance);
282
- } catch (e) {
283
- err.push(e.message);
284
- if (!force)
285
- return err;
286
- }
355
+ if (!pipe)
356
+ continue;
357
+ await pipe(instance, addError);
358
+ if (err.length && !force)
359
+ return err;
287
360
  }
288
361
  }
289
362
  }
290
363
  return err;
291
364
  }
292
- __name(transformClass, "transformClass");
293
- function classToValue(instance) {
365
+ __name(transformInstanceAsync, "transformInstanceAsync");
366
+ function transformProperty(instance, property, force = false) {
367
+ const err = [];
368
+ const handlers = getHandler(instance, property);
369
+ const addError = err.push.bind(err);
370
+ if (handlers) {
371
+ for (const handler of handlers) {
372
+ const pipe = handler.pipe;
373
+ if (!pipe)
374
+ continue;
375
+ pipe(instance, addError);
376
+ if (err.length && !force)
377
+ return err;
378
+ }
379
+ }
380
+ return err;
381
+ }
382
+ __name(transformProperty, "transformProperty");
383
+ async function transformPropertyAsync(instance, property, force = false) {
384
+ const err = [];
385
+ const handlers = getHandler(instance, property);
386
+ const addError = err.push.bind(err);
387
+ if (handlers) {
388
+ for (const handler of handlers) {
389
+ const pipe = handler.pipe;
390
+ if (!pipe)
391
+ continue;
392
+ await pipe(instance, addError);
393
+ if (err.length && !force)
394
+ return err;
395
+ }
396
+ }
397
+ return err;
398
+ }
399
+ __name(transformPropertyAsync, "transformPropertyAsync");
400
+ function classToPlain(instance) {
294
401
  const data = {};
295
402
  const exposeVars = getExposeKey(instance);
296
403
  for (const item of exposeVars)
297
404
  data[item] = instance[item];
298
- return data;
405
+ return JSON.parse(JSON.stringify(data));
299
406
  }
300
- __name(classToValue, "classToValue");
407
+ __name(classToPlain, "classToPlain");
301
408
  function snapShot(data) {
302
409
  const snap = {};
303
410
  for (const i in data)
@@ -315,8 +422,8 @@ function snapShot(data) {
315
422
  };
316
423
  }
317
424
  __name(snapShot, "snapShot");
318
- function addDecoToClass(c, key, handler, type = "class") {
319
- handler(type === "class" ? c.prototype : c, key);
425
+ function addDecoToClass(c, key, handler) {
426
+ handler(key === SHARE_KEY ? c : c.prototype, key);
320
427
  }
321
428
  __name(addDecoToClass, "addDecoToClass");
322
429
  function Pipeline(...decos) {
@@ -326,92 +433,55 @@ function Pipeline(...decos) {
326
433
  };
327
434
  }
328
435
  __name(Pipeline, "Pipeline");
329
-
330
- // src/decorators.ts
331
- function Init(proto, key) {
332
- setVar(proto, key);
333
- regisHandler(proto, key, {
334
- async init(instance) {
335
- return instance[key]();
336
- }
337
- });
436
+ function isAsyncFunc(fn) {
437
+ return fn[Symbol.toStringTag] === "AsyncFunction";
338
438
  }
339
- __name(Init, "Init");
340
- function Unmount(proto, key) {
341
- setVar(proto, key);
342
- regisHandler(proto, key, {
343
- async unmount(instance) {
344
- return instance[key]();
345
- }
346
- });
347
- }
348
- __name(Unmount, "Unmount");
349
- function Bind(value) {
350
- return (proto, k) => {
351
- setVar(proto, k);
352
- setState(proto, k, {
353
- value
354
- });
355
- };
356
- }
357
- __name(Bind, "Bind");
358
- function Ignore(proto, key) {
359
- setIgnoreKey(proto, key);
439
+ __name(isAsyncFunc, "isAsyncFunc");
440
+
441
+ // src/di.ts
442
+ var DataMap = {};
443
+ function Provide(key, value) {
444
+ DataMap[key] = value;
360
445
  }
361
- __name(Ignore, "Ignore");
362
- function Clear(proto, key) {
363
- init(proto);
364
- proto._namespace.__EXPOSE_VAR__.delete(key);
365
- proto._namespace.__IGNORE_VAR__.delete(key);
366
- proto._namespace.__STATE_VAR__.delete(key);
367
- proto._namespace.__STATE_HANDLER__.delete(key);
368
- proto._namespace.__STATE_NAMESPACE__.delete(key);
446
+ __name(Provide, "Provide");
447
+ function Inject(key) {
448
+ return DataMap[key];
369
449
  }
370
- __name(Clear, "Clear");
371
- function Err(cb) {
372
- return (proto, key) => {
373
- setVar(proto, key);
374
- regisHandler(proto, key, {
375
- error: cb
376
- });
377
- };
450
+ __name(Inject, "Inject");
451
+ var activeInstance = {};
452
+ function injectKey(key, value) {
453
+ activeInstance[key] = value;
454
+ return activeInstance;
378
455
  }
379
- __name(Err, "Err");
380
- function Expose(proto, key) {
381
- setExposeKey(proto, key);
456
+ __name(injectKey, "injectKey");
457
+ function getKey(key) {
458
+ return activeInstance[key];
382
459
  }
383
- __name(Expose, "Expose");
384
- function To(...callbacks) {
385
- return (proto, key) => {
386
- setVar(proto, key);
387
- regisHandler(proto, key, {
388
- async pipe(instance) {
389
- for (const cb of callbacks)
390
- instance[key] = await cb(instance[key], instance, key);
391
- }
392
- });
393
- };
460
+ __name(getKey, "getKey");
461
+
462
+ // src/decorators/function.ts
463
+ function Isolate(module2) {
464
+ set(module2.prototype, "isolate", true);
465
+ module2.prototype[PHECDA_KEY].__ISOLATE__ = true;
394
466
  }
395
- __name(To, "To");
467
+ __name(Isolate, "Isolate");
396
468
  function Tag(tag) {
397
469
  return (module2) => {
398
- init(module2.prototype);
399
- module2.prototype.__TAG__ = tag;
470
+ set(module2.prototype, "tag", tag);
400
471
  };
401
472
  }
402
473
  __name(Tag, "Tag");
403
474
  function Unique(desc) {
404
475
  return (module2) => {
405
- init(module2.prototype);
406
- module2.prototype.__TAG__ = Symbol(desc || module2.name);
476
+ set(module2.prototype, "tag", Symbol(desc || module2.name));
407
477
  };
408
478
  }
409
479
  __name(Unique, "Unique");
410
480
  function Assign(cb) {
411
481
  return (module2) => {
412
482
  init(module2.prototype);
413
- setVar(module2.prototype, SHARE_KEY);
414
- regisHandler(module2.prototype, SHARE_KEY, {
483
+ setStateVar(module2.prototype, SHARE_KEY);
484
+ setHandler(module2.prototype, SHARE_KEY, {
415
485
  init: async (instance) => {
416
486
  const value = await cb(instance);
417
487
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -425,10 +495,10 @@ function Assign(cb) {
425
495
  __name(Assign, "Assign");
426
496
  function Global(module2) {
427
497
  init(module2.prototype);
428
- setVar(module2.prototype, SHARE_KEY);
429
- regisHandler(module2.prototype, SHARE_KEY, {
498
+ setStateVar(module2.prototype, SHARE_KEY);
499
+ setHandler(module2.prototype, SHARE_KEY, {
430
500
  init: async (instance) => {
431
- const tag = instance.__TAG__;
501
+ const tag = instance[PHECDA_KEY].__TAG__;
432
502
  if (!tag)
433
503
  return;
434
504
  if (!globalThis.__PHECDA__)
@@ -438,59 +508,88 @@ function Global(module2) {
438
508
  });
439
509
  }
440
510
  __name(Global, "Global");
441
- function Empty(module2) {
442
- init(module2.prototype);
443
- }
444
- __name(Empty, "Empty");
445
- var DataMap = {};
446
- function Provide(key, value) {
447
- DataMap[key] = value;
448
- }
449
- __name(Provide, "Provide");
450
- var EmptyProxy = new Proxy(Empty, {
451
- apply() {
452
- return EmptyProxy;
453
- }
454
- });
455
- function Inject(key) {
456
- return DataMap[key] || EmptyProxy;
457
- }
458
- __name(Inject, "Inject");
459
- function Nested(module2) {
460
- return To(async (property) => {
461
- const instance = plainToClass(module2, property);
462
- const err = await transformClass(instance);
463
- if (err.length > 0)
464
- throw new Error(err[0]);
465
- return instance;
466
- });
467
- }
468
- __name(Nested, "Nested");
469
- function Isolate() {
470
- return (target) => {
471
- target.prototype.__ISOLATE__ = true;
511
+ function To(...callbacks) {
512
+ return (proto, key) => {
513
+ setStateVar(proto, key);
514
+ setHandler(proto, key, {
515
+ async pipe(instance, addError) {
516
+ for (const cb of callbacks) {
517
+ try {
518
+ if (isAsyncFunc(cb))
519
+ instance[key] = await cb(instance[key], instance, key);
520
+ else
521
+ instance[key] = cb(instance[key], instance, key);
522
+ } catch (e) {
523
+ addError(e.message);
524
+ }
525
+ }
526
+ }
527
+ });
472
528
  };
473
529
  }
474
- __name(Isolate, "Isolate");
475
-
476
- // src/custom/decorator.ts
477
- var activeInstance = {};
478
- function injectProperty(key, value) {
479
- activeInstance[key] = value;
480
- return activeInstance;
530
+ __name(To, "To");
531
+ function Rule(cb, info) {
532
+ return (proto, key) => {
533
+ setStateVar(proto, key);
534
+ setHandler(proto, key, {
535
+ async pipe(instance, addError) {
536
+ let ret;
537
+ if (isAsyncFunc(cb))
538
+ ret = await cb(instance[key]);
539
+ else
540
+ ret = cb(instance[key]);
541
+ if (!ret) {
542
+ if (typeof info === "string")
543
+ addError(info);
544
+ else
545
+ addError(info());
546
+ }
547
+ }
548
+ });
549
+ };
481
550
  }
482
- __name(injectProperty, "injectProperty");
483
- function getProperty(key) {
484
- return activeInstance[key];
551
+ __name(Rule, "Rule");
552
+ function Err(cb, isCatch = false) {
553
+ return (proto, key) => {
554
+ setStateVar(proto, key);
555
+ setHandler(proto, key, {
556
+ init: (instance) => {
557
+ if (typeof instance[key] === "function") {
558
+ const oldFn = instance[key].bind(instance);
559
+ if (isAsyncFunc(oldFn)) {
560
+ instance[key] = async (...args) => {
561
+ try {
562
+ await oldFn(...args);
563
+ } catch (e) {
564
+ cb(e, instance, key);
565
+ if (!isCatch)
566
+ throw e;
567
+ }
568
+ };
569
+ } else {
570
+ instance[key] = (...args) => {
571
+ try {
572
+ oldFn(...args);
573
+ } catch (e) {
574
+ cb(e, instance, key);
575
+ if (!isCatch)
576
+ throw e;
577
+ }
578
+ };
579
+ }
580
+ }
581
+ }
582
+ });
583
+ };
485
584
  }
486
- __name(getProperty, "getProperty");
585
+ __name(Err, "Err");
487
586
  function Watcher(eventName, options) {
488
587
  let cb;
489
588
  return (proto, key) => {
490
- setVar(proto, key);
491
- regisHandler(proto, key, {
589
+ setStateVar(proto, key);
590
+ setHandler(proto, key, {
492
591
  init(instance) {
493
- return cb = getProperty("watcher")?.({
592
+ return cb = getKey("watcher")?.({
494
593
  eventName,
495
594
  instance,
496
595
  key,
@@ -504,10 +603,10 @@ function Watcher(eventName, options) {
504
603
  };
505
604
  }
506
605
  __name(Watcher, "Watcher");
507
- function Effect(eventName, options) {
606
+ function Effect(cb) {
508
607
  return (proto, key) => {
509
- setVar(proto, key);
510
- regisHandler(proto, key, {
608
+ setStateVar(proto, key);
609
+ setHandler(proto, key, {
511
610
  init(instance) {
512
611
  instance[`$_${key}`] = instance[key];
513
612
  Object.defineProperty(instance, key, {
@@ -516,12 +615,7 @@ function Effect(eventName, options) {
516
615
  },
517
616
  set(v) {
518
617
  instance[`$_${key}`] = v;
519
- getProperty(`effect-${eventName}`)?.({
520
- instance,
521
- key,
522
- value: v,
523
- options
524
- });
618
+ cb(v, instance, key);
525
619
  return true;
526
620
  }
527
621
  });
@@ -530,34 +624,40 @@ function Effect(eventName, options) {
530
624
  };
531
625
  }
532
626
  __name(Effect, "Effect");
533
- function Storage(storeKey) {
627
+ function Storage({ key: storeKey, toJSON, toString } = {}) {
628
+ if (!toJSON)
629
+ toJSON = /* @__PURE__ */ __name((v) => JSON.parse(v), "toJSON");
630
+ if (!toString)
631
+ toString = /* @__PURE__ */ __name((v) => JSON.stringify(v), "toString");
534
632
  return (proto, key) => {
535
633
  let tag;
536
634
  if (key) {
537
635
  init(proto);
538
- tag = storeKey || proto.__TAG__;
539
- const uniTag = Symbol(tag);
540
- setVar(proto, uniTag);
541
- regisHandler(proto, uniTag, {
636
+ tag = storeKey || `${getTag(proto)}_${key}`;
637
+ setStateVar(proto, key);
638
+ setHandler(proto, key, {
542
639
  init: (instance) => {
543
- return getProperty("storage")?.({
640
+ return getKey("storage")?.({
544
641
  instance,
545
642
  key,
546
- tag
643
+ tag,
644
+ toJSON,
645
+ toString
547
646
  });
548
647
  }
549
648
  });
550
649
  } else {
551
650
  init(proto.prototype);
552
- tag = storeKey || `${proto.prototype.__TAG__}_${key}`;
553
- const uniTag = Symbol(tag);
554
- setVar(proto.prototype, uniTag);
555
- regisHandler(proto.prototype, uniTag, {
651
+ tag = storeKey || getTag(proto);
652
+ setStateVar(proto.prototype, SHARE_KEY);
653
+ setHandler(proto.prototype, SHARE_KEY, {
556
654
  init: (instance) => {
557
- return getProperty("storage")?.({
655
+ return getKey("storage")?.({
558
656
  instance,
559
- key: "",
560
- tag
657
+ key,
658
+ tag,
659
+ toJSON,
660
+ toString
561
661
  });
562
662
  }
563
663
  });
@@ -580,9 +680,10 @@ __name(Storage, "Storage");
580
680
  Init,
581
681
  Inject,
582
682
  Isolate,
583
- Nested,
683
+ PHECDA_KEY,
584
684
  Pipeline,
585
685
  Provide,
686
+ Rule,
586
687
  SHARE_KEY,
587
688
  Storage,
588
689
  Tag,
@@ -592,31 +693,35 @@ __name(Storage, "Storage");
592
693
  Watcher,
593
694
  activeInstance,
594
695
  addDecoToClass,
595
- classToValue,
696
+ classToPlain,
697
+ get,
596
698
  getBind,
597
699
  getExposeKey,
598
700
  getHandler,
599
- getModuleState,
701
+ getKey,
600
702
  getOwnExposeKey,
601
703
  getOwnHandler,
602
704
  getOwnIgnoreKey,
603
- getOwnModuleState,
604
705
  getOwnState,
605
- getProperty,
706
+ getOwnStateVars,
606
707
  getState,
708
+ getStateVars,
607
709
  getTag,
608
710
  init,
609
- injectProperty,
711
+ injectKey,
712
+ invokeHandler,
713
+ isAsyncFunc,
610
714
  isPhecda,
611
715
  plainToClass,
612
- regisHandler,
613
- registerParallel,
614
- registerSerial,
716
+ set,
615
717
  setExposeKey,
718
+ setHandler,
616
719
  setIgnoreKey,
617
720
  setState,
618
- setVar,
721
+ setStateVar,
619
722
  snapShot,
620
- transformClass,
621
- unmountParallel
723
+ transformInstance,
724
+ transformInstanceAsync,
725
+ transformProperty,
726
+ transformPropertyAsync
622
727
  });