phecda-core 3.0.2 → 3.1.1

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
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
6
  var __export = (target, all) => {
8
7
  for (var name in all)
9
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
17
16
  return to;
18
17
  };
19
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __decorateClass = (decorators, target, key, kind) => {
20
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
+ if (decorator = decorators[i])
23
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
+ if (kind && result) __defProp(target, key, result);
25
+ return result;
26
+ };
20
27
 
21
28
  // src/index.ts
22
29
  var src_exports = {};
@@ -35,6 +42,7 @@ __export(src_exports, {
35
42
  Ignore: () => Ignore,
36
43
  Init: () => Init,
37
44
  Inject: () => Inject,
45
+ Injectable: () => Injectable,
38
46
  Isolate: () => Isolate,
39
47
  PHECDA_KEY: () => PHECDA_KEY,
40
48
  Pipeline: () => Pipeline,
@@ -90,52 +98,53 @@ module.exports = __toCommonJS(src_exports);
90
98
  var SHARE_KEY = Symbol("phecda");
91
99
  var PHECDA_KEY = Symbol("phecda");
92
100
  function isPhecda(model) {
93
- if (typeof model === "function") return !!model.prototype[PHECDA_KEY];
101
+ if (typeof model === "function")
102
+ return !!model.prototype[PHECDA_KEY];
94
103
  return false;
95
104
  }
96
- __name(isPhecda, "isPhecda");
97
105
  function init(proto) {
98
- if (!proto) return;
106
+ if (!proto)
107
+ return;
99
108
  if (!proto.hasOwnProperty(PHECDA_KEY)) {
100
109
  proto[PHECDA_KEY] = {
101
110
  /**
102
- * 暴露的变量,
103
- * 只要属性上存在至少一个装饰器,该属性就会被捕捉到
104
- */
111
+ * 暴露的变量,
112
+ * 只要属性上存在至少一个装饰器,该属性就会被捕捉到
113
+ */
105
114
  __EXPOSE_KEY: /* @__PURE__ */ new Set(),
106
115
  /**
107
- * @Ignore 绑定的属性,
108
- * 某属性即使被捕捉,可被强行忽略,优先级最高
109
- */
116
+ * @Ignore 绑定的属性,
117
+ * 某属性即使被捕捉,可被强行忽略,优先级最高
118
+ */
110
119
  __IGNORE_KEY: /* @__PURE__ */ new Set(),
111
120
  /**
112
- * @Clear 绑定的属性,
113
- * 消除父类在该key上的state/handler, 但export key 和 state
114
- */
121
+ * @Clear 绑定的属性,
122
+ * 消除父类在该key上的state/handler, 但export key 和 state
123
+ */
115
124
  __CLEAR_KEY: /* @__PURE__ */ new Set(),
116
125
  /**
117
- * 存在状态的变量
118
- * @deprecated
119
- */
126
+ * 存在状态的变量
127
+ * @deprecated
128
+ */
120
129
  __STATE_KEY: /* @__PURE__ */ new Set(),
121
130
  /**
122
- * 状态变量的处理器
123
- */
131
+ * 状态变量的处理器
132
+ */
124
133
  __STATE_HANDLER__: /* @__PURE__ */ new Map(),
125
134
  /**
126
- * 状态变量的共有状态
127
- */
135
+ * 状态变量的共有状态
136
+ */
128
137
  __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
129
138
  };
130
139
  }
131
140
  }
132
- __name(init, "init");
133
141
  function getPhecdaFromTarget(target) {
134
- if (typeof target === "function") return target.prototype;
135
- if (target.hasOwnProperty(PHECDA_KEY)) return target;
142
+ if (typeof target === "function")
143
+ return target.prototype;
144
+ if (target.hasOwnProperty(PHECDA_KEY))
145
+ return target;
136
146
  return Object.getPrototypeOf(target);
137
147
  }
138
- __name(getPhecdaFromTarget, "getPhecdaFromTarget");
139
148
  function setStateKey(proto, key) {
140
149
  if (!key) {
141
150
  key = SHARE_KEY;
@@ -145,7 +154,6 @@ function setStateKey(proto, key) {
145
154
  proto[PHECDA_KEY].__STATE_KEY.add(key);
146
155
  setExposeKey(proto, key);
147
156
  }
148
- __name(setStateKey, "setStateKey");
149
157
  function setExposeKey(proto, key) {
150
158
  if (!key) {
151
159
  key = SHARE_KEY;
@@ -154,7 +162,6 @@ function setExposeKey(proto, key) {
154
162
  init(proto);
155
163
  proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
156
164
  }
157
- __name(setExposeKey, "setExposeKey");
158
165
  function setIgnoreKey(proto, key) {
159
166
  if (!key) {
160
167
  key = SHARE_KEY;
@@ -163,19 +170,17 @@ function setIgnoreKey(proto, key) {
163
170
  init(proto);
164
171
  proto[PHECDA_KEY].__IGNORE_KEY.add(key);
165
172
  }
166
- __name(setIgnoreKey, "setIgnoreKey");
167
173
  function setHandler(proto, key, handler) {
168
174
  if (!key) {
169
175
  key = SHARE_KEY;
170
176
  proto = proto.prototype;
171
177
  }
172
178
  init(proto);
173
- if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key)) proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [
174
- handler
175
- ]);
176
- else proto[PHECDA_KEY].__STATE_HANDLER__.get(key).push(handler);
179
+ if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
180
+ proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [handler]);
181
+ else
182
+ proto[PHECDA_KEY].__STATE_HANDLER__.get(key).push(handler);
177
183
  }
178
- __name(setHandler, "setHandler");
179
184
  function setState(proto, key, state) {
180
185
  if (!key) {
181
186
  key = SHARE_KEY;
@@ -185,114 +190,89 @@ function setState(proto, key, state) {
185
190
  const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
186
191
  namespace.set(key, state);
187
192
  }
188
- __name(setState, "setState");
189
193
  function getOwnStateKey(target) {
190
194
  const proto = getPhecdaFromTarget(target);
191
- return [
192
- ...proto[PHECDA_KEY].__STATE_KEY
193
- ];
195
+ return [...proto[PHECDA_KEY].__STATE_KEY];
194
196
  }
195
- __name(getOwnStateKey, "getOwnStateKey");
196
197
  function getStateKey(target) {
197
198
  let proto = getPhecdaFromTarget(target);
198
199
  const set2 = /* @__PURE__ */ new Set();
199
200
  while (proto?.[PHECDA_KEY]) {
200
- if (proto.hasOwnProperty(PHECDA_KEY)) proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
201
+ if (proto.hasOwnProperty(PHECDA_KEY))
202
+ proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
201
203
  proto = Object.getPrototypeOf(proto);
202
204
  }
203
- return [
204
- ...set2
205
- ];
205
+ return [...set2];
206
206
  }
207
- __name(getStateKey, "getStateKey");
208
207
  function getOwnExposeKey(target) {
209
208
  const proto = getPhecdaFromTarget(target);
210
- return [
211
- ...proto[PHECDA_KEY].__EXPOSE_KEY
212
- ].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
209
+ return [...proto[PHECDA_KEY].__EXPOSE_KEY].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
213
210
  }
214
- __name(getOwnExposeKey, "getOwnExposeKey");
215
211
  function getExposeKey(target) {
216
212
  let proto = getPhecdaFromTarget(target);
217
213
  const set2 = /* @__PURE__ */ new Set();
218
214
  const origin = proto;
219
215
  while (proto?.[PHECDA_KEY]) {
220
- if (proto.hasOwnProperty(PHECDA_KEY)) [
221
- ...proto[PHECDA_KEY].__EXPOSE_KEY
222
- ].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
216
+ if (proto.hasOwnProperty(PHECDA_KEY))
217
+ [...proto[PHECDA_KEY].__EXPOSE_KEY].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
223
218
  proto = Object.getPrototypeOf(proto);
224
219
  }
225
- return [
226
- ...set2
227
- ];
220
+ return [...set2];
228
221
  }
229
- __name(getExposeKey, "getExposeKey");
230
222
  function getOwnIgnoreKey(target) {
231
223
  const proto = getPhecdaFromTarget(target);
232
- return [
233
- ...proto[PHECDA_KEY]?.__IGNORE_KEY
234
- ];
224
+ return [...proto[PHECDA_KEY]?.__IGNORE_KEY];
235
225
  }
236
- __name(getOwnIgnoreKey, "getOwnIgnoreKey");
237
226
  function getOwnHandler(target, key) {
238
227
  const proto = getPhecdaFromTarget(target);
239
228
  return proto[PHECDA_KEY]?.__STATE_HANDLER__.get(key) || [];
240
229
  }
241
- __name(getOwnHandler, "getOwnHandler");
242
230
  function getHandler(target, key) {
243
231
  let proto = getPhecdaFromTarget(target);
244
232
  const set2 = /* @__PURE__ */ new Set();
245
233
  while (proto?.[PHECDA_KEY]) {
246
234
  if (proto.hasOwnProperty(PHECDA_KEY)) {
247
235
  proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
248
- if (proto[PHECDA_KEY].__CLEAR_KEY.has(key)) break;
236
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
237
+ break;
249
238
  }
250
239
  proto = Object.getPrototypeOf(proto);
251
240
  }
252
- return [
253
- ...set2
254
- ];
241
+ return [...set2];
255
242
  }
256
- __name(getHandler, "getHandler");
257
243
  function getState(target, key = SHARE_KEY) {
258
244
  let proto = getPhecdaFromTarget(target);
259
245
  let ret = {};
260
246
  while (proto?.[PHECDA_KEY]) {
261
247
  if (proto.hasOwnProperty(PHECDA_KEY)) {
262
248
  const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
263
- if (state) ret = {
264
- ...state,
265
- ...ret
266
- };
267
- if (proto[PHECDA_KEY].__CLEAR_KEY.has(key)) break;
249
+ if (state)
250
+ ret = { ...state, ...ret };
251
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
252
+ break;
268
253
  }
269
254
  proto = Object.getPrototypeOf(proto);
270
255
  }
271
256
  return ret;
272
257
  }
273
- __name(getState, "getState");
274
258
  function getOwnState(target, key = SHARE_KEY) {
275
259
  const proto = getPhecdaFromTarget(target);
276
260
  return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
277
261
  }
278
- __name(getOwnState, "getOwnState");
279
262
  function invokeHandler(event, module2) {
280
263
  const stateVars = getExposeKey(module2);
281
264
  const initHandlers = stateVars.map((item) => {
282
265
  return getHandler(module2, item).filter((h) => !!h[event]).map((h) => h[event](module2));
283
266
  }).flat();
284
- return Promise.all(initHandlers);
267
+ return module2.__PROMISE_SYMBOL__ = Promise.all(initHandlers);
285
268
  }
286
- __name(invokeHandler, "invokeHandler");
287
269
  function set(proto, key, value) {
288
270
  init(proto);
289
271
  proto[`__${key.toUpperCase()}__`] = value;
290
272
  }
291
- __name(set, "set");
292
273
  function get(proto, key) {
293
274
  return proto[`__${key.toUpperCase()}__`];
294
275
  }
295
- __name(get, "get");
296
276
 
297
277
  // src/decorators/core.ts
298
278
  function Init(proto, key) {
@@ -303,7 +283,6 @@ function Init(proto, key) {
303
283
  }
304
284
  });
305
285
  }
306
- __name(Init, "Init");
307
286
  function Unmount(proto, key) {
308
287
  setStateKey(proto, key);
309
288
  setHandler(proto, key, {
@@ -312,7 +291,6 @@ function Unmount(proto, key) {
312
291
  }
313
292
  });
314
293
  }
315
- __name(Unmount, "Unmount");
316
294
  function Bind(value) {
317
295
  return (proto, k) => {
318
296
  setStateKey(proto, k);
@@ -321,57 +299,57 @@ function Bind(value) {
321
299
  });
322
300
  };
323
301
  }
324
- __name(Bind, "Bind");
325
302
  function Ignore(proto, key) {
326
303
  if (!key) {
327
304
  proto = proto.prototype;
328
305
  key = SHARE_KEY;
329
306
  }
307
+ ;
330
308
  setIgnoreKey(proto, key);
331
309
  }
332
- __name(Ignore, "Ignore");
333
310
  function Clear(proto, key) {
334
311
  if (!key) {
335
312
  proto = proto.prototype;
336
313
  key = SHARE_KEY;
337
314
  }
315
+ ;
338
316
  init(proto);
339
317
  proto[PHECDA_KEY].__CLEAR_KEY.add(key);
340
318
  }
341
- __name(Clear, "Clear");
342
319
  function Expose(proto, key) {
343
320
  setExposeKey(proto, key);
344
321
  }
345
- __name(Expose, "Expose");
346
322
  function Empty(model) {
347
323
  init(model.prototype);
348
324
  }
349
- __name(Empty, "Empty");
325
+ function Injectable() {
326
+ return (target) => Empty(target);
327
+ }
350
328
 
351
329
  // src/helper.ts
352
330
  function getTag(moduleOrInstance) {
353
- if (typeof moduleOrInstance === "object") moduleOrInstance = moduleOrInstance.constructor;
331
+ if (typeof moduleOrInstance === "object")
332
+ moduleOrInstance = moduleOrInstance.constructor;
354
333
  return get(moduleOrInstance.prototype, "tag") || moduleOrInstance.name;
355
334
  }
356
- __name(getTag, "getTag");
357
335
  function getBind(model) {
358
336
  const instance = new model();
359
337
  const keys = getStateKey(instance);
360
338
  const ret = {};
361
339
  for (const item of keys) {
362
340
  const state = getState(instance, item);
363
- if (state.value) ret[item] = state.value;
341
+ if (state.value)
342
+ ret[item] = state.value;
364
343
  }
365
344
  return ret;
366
345
  }
367
- __name(getBind, "getBind");
368
346
  function plainToClass(model, input) {
369
347
  const instance = new model();
370
348
  const keys = getExposeKey(instance);
371
- for (const item of keys) instance[item] = input[item];
349
+ for (const item of keys)
350
+ instance[item] = input[item];
372
351
  return instance;
373
352
  }
374
- __name(plainToClass, "plainToClass");
375
353
  function transformInstance(instance, force = false) {
376
354
  const err = [];
377
355
  const keys = getExposeKey(instance);
@@ -381,15 +359,16 @@ function transformInstance(instance, force = false) {
381
359
  if (handlers) {
382
360
  for (const handler of handlers) {
383
361
  const pipe = handler.pipe;
384
- if (!pipe) continue;
362
+ if (!pipe)
363
+ continue;
385
364
  pipe(instance, addError);
386
- if (err.length && !force) return err;
365
+ if (err.length && !force)
366
+ return err;
387
367
  }
388
368
  }
389
369
  }
390
370
  return err;
391
371
  }
392
- __name(transformInstance, "transformInstance");
393
372
  async function transformInstanceAsync(instance, force = false) {
394
373
  const err = [];
395
374
  const keys = getExposeKey(instance);
@@ -399,15 +378,16 @@ async function transformInstanceAsync(instance, force = false) {
399
378
  if (handlers) {
400
379
  for (const handler of handlers) {
401
380
  const pipe = handler.pipe;
402
- if (!pipe) continue;
381
+ if (!pipe)
382
+ continue;
403
383
  await pipe(instance, addError);
404
- if (err.length && !force) return err;
384
+ if (err.length && !force)
385
+ return err;
405
386
  }
406
387
  }
407
388
  }
408
389
  return err;
409
390
  }
410
- __name(transformInstanceAsync, "transformInstanceAsync");
411
391
  function transformProperty(instance, property, force = false) {
412
392
  const err = [];
413
393
  const handlers = getHandler(instance, property);
@@ -415,14 +395,15 @@ function transformProperty(instance, property, force = false) {
415
395
  if (handlers) {
416
396
  for (const handler of handlers) {
417
397
  const pipe = handler.pipe;
418
- if (!pipe) continue;
398
+ if (!pipe)
399
+ continue;
419
400
  pipe(instance, addError);
420
- if (err.length && !force) return err;
401
+ if (err.length && !force)
402
+ return err;
421
403
  }
422
404
  }
423
405
  return err;
424
406
  }
425
- __name(transformProperty, "transformProperty");
426
407
  async function transformPropertyAsync(instance, property, force = false) {
427
408
  const err = [];
428
409
  const handlers = getHandler(instance, property);
@@ -430,125 +411,117 @@ async function transformPropertyAsync(instance, property, force = false) {
430
411
  if (handlers) {
431
412
  for (const handler of handlers) {
432
413
  const pipe = handler.pipe;
433
- if (!pipe) continue;
414
+ if (!pipe)
415
+ continue;
434
416
  await pipe(instance, addError);
435
- if (err.length && !force) return err;
417
+ if (err.length && !force)
418
+ return err;
436
419
  }
437
420
  }
438
421
  return err;
439
422
  }
440
- __name(transformPropertyAsync, "transformPropertyAsync");
441
423
  function classToPlain(instance) {
442
424
  const data = {};
443
425
  const exposeVars = getExposeKey(instance);
444
- for (const item of exposeVars) data[item] = instance[item];
426
+ for (const item of exposeVars)
427
+ data[item] = instance[item];
445
428
  return JSON.parse(JSON.stringify(data));
446
429
  }
447
- __name(classToPlain, "classToPlain");
448
430
  function snapShot(data) {
449
431
  const snap = {};
450
- for (const i in data) snap[i] = data[i];
432
+ for (const i in data)
433
+ snap[i] = data[i];
451
434
  return {
452
435
  data,
453
436
  clear() {
454
- for (const i in snap) delete data[i];
437
+ for (const i in snap)
438
+ delete data[i];
455
439
  },
456
440
  apply() {
457
- for (const i in snap) data[i] = snap[i];
441
+ for (const i in snap)
442
+ data[i] = snap[i];
458
443
  }
459
444
  };
460
445
  }
461
- __name(snapShot, "snapShot");
462
446
  function addDecoToClass(c, key, handler) {
463
447
  handler(key ? c.prototype : c, key);
464
448
  }
465
- __name(addDecoToClass, "addDecoToClass");
466
449
  function Pipeline(...decos) {
467
450
  return (...args) => {
468
- for (const d of decos) d(...args);
451
+ for (const d of decos)
452
+ d(...args);
469
453
  };
470
454
  }
471
- __name(Pipeline, "Pipeline");
472
455
  function isAsyncFunc(fn) {
473
456
  return fn[Symbol.toStringTag] === "AsyncFunction";
474
457
  }
475
- __name(isAsyncFunc, "isAsyncFunc");
476
458
  function setPropertyState(target, k, setter) {
477
459
  setStateKey(target, k);
478
460
  const state = getOwnState(target, k) || {};
479
461
  setter(state);
480
462
  setState(target, k, state);
481
463
  }
482
- __name(setPropertyState, "setPropertyState");
483
464
  function getShareState(target, getter) {
484
465
  const state = getOwnState(target, SHARE_KEY) || {};
485
466
  return getter(state);
486
467
  }
487
- __name(getShareState, "getShareState");
488
468
 
489
469
  // src/di.ts
490
470
  var DataMap = {};
491
471
  function Provide(key, value) {
492
472
  DataMap[key] = value;
493
473
  }
494
- __name(Provide, "Provide");
495
474
  function Inject(key) {
496
475
  return DataMap[key];
497
476
  }
498
- __name(Inject, "Inject");
499
477
  var activeInstance = {};
500
478
  function setInject(key, value) {
501
479
  activeInstance[key] = value;
502
480
  return activeInstance;
503
481
  }
504
- __name(setInject, "setInject");
505
482
  function getInject(key) {
506
483
  return activeInstance[key];
507
484
  }
508
- __name(getInject, "getInject");
509
485
 
510
486
  // src/decorators/function.ts
511
487
  function Isolate(model) {
512
488
  set(model.prototype, "isolate", true);
513
489
  }
514
- __name(Isolate, "Isolate");
515
490
  function Tag(tag) {
516
491
  return (model) => {
517
492
  set(model.prototype, "tag", tag);
518
493
  };
519
494
  }
520
- __name(Tag, "Tag");
521
495
  function Unique(desc) {
522
496
  return (model) => {
523
497
  set(model.prototype, "tag", Symbol(desc || model.name));
524
498
  };
525
499
  }
526
- __name(Unique, "Unique");
527
500
  function Assign(cb) {
528
501
  return (model) => {
529
502
  setStateKey(model);
530
503
  setHandler(model, void 0, {
531
- init: /* @__PURE__ */ __name(async (instance) => {
504
+ init: async (instance) => {
532
505
  const value = await cb(instance);
533
506
  if (value && typeof value === "object" && !Array.isArray(value)) {
534
- for (const i in value) instance[i] = value[i];
507
+ for (const i in value)
508
+ instance[i] = value[i];
535
509
  }
536
- }, "init")
510
+ }
537
511
  });
538
512
  };
539
513
  }
540
- __name(Assign, "Assign");
541
514
  function Global(model) {
542
515
  setStateKey(model);
543
516
  setHandler(model, void 0, {
544
- init: /* @__PURE__ */ __name(async (instance) => {
517
+ init: async (instance) => {
545
518
  const tag = getTag(instance);
546
- if (!globalThis.__PHECDA__) globalThis.__PHECDA__ = {};
519
+ if (!globalThis.__PHECDA__)
520
+ globalThis.__PHECDA__ = {};
547
521
  globalThis.__PHECDA__[tag] = instance.constructor;
548
- }, "init")
522
+ }
549
523
  });
550
524
  }
551
- __name(Global, "Global");
552
525
  function To(...callbacks) {
553
526
  return (proto, key) => {
554
527
  setStateKey(proto, key);
@@ -556,8 +529,10 @@ function To(...callbacks) {
556
529
  async pipe(instance, addError) {
557
530
  for (const cb of callbacks) {
558
531
  try {
559
- if (isAsyncFunc(cb)) instance[key] = await cb(instance[key], instance, key);
560
- else instance[key] = cb(instance[key], instance, key);
532
+ if (isAsyncFunc(cb))
533
+ instance[key] = await cb(instance[key], instance, key);
534
+ else
535
+ instance[key] = cb(instance[key], instance, key);
561
536
  } catch (e) {
562
537
  addError(e.message);
563
538
  }
@@ -566,29 +541,31 @@ function To(...callbacks) {
566
541
  });
567
542
  };
568
543
  }
569
- __name(To, "To");
570
544
  function Rule(cb, info) {
571
545
  return (proto, key) => {
572
546
  setStateKey(proto, key);
573
547
  setHandler(proto, key, {
574
548
  async pipe(instance, addError) {
575
549
  let ret;
576
- if (isAsyncFunc(cb)) ret = await cb(instance[key]);
577
- else ret = cb(instance[key]);
550
+ if (isAsyncFunc(cb))
551
+ ret = await cb(instance[key]);
552
+ else
553
+ ret = cb(instance[key]);
578
554
  if (!ret) {
579
- if (typeof info === "string") addError(info);
580
- else addError(info());
555
+ if (typeof info === "string")
556
+ addError(info);
557
+ else
558
+ addError(info());
581
559
  }
582
560
  }
583
561
  });
584
562
  };
585
563
  }
586
- __name(Rule, "Rule");
587
564
  function Err(cb, isCatch = false) {
588
565
  return (proto, key) => {
589
566
  setStateKey(proto, key);
590
567
  setHandler(proto, key, {
591
- init: /* @__PURE__ */ __name((instance) => {
568
+ init: (instance) => {
592
569
  if (typeof instance[key] === "function") {
593
570
  const oldFn = instance[key].bind(instance);
594
571
  if (isAsyncFunc(oldFn)) {
@@ -597,7 +574,8 @@ function Err(cb, isCatch = false) {
597
574
  await oldFn(...args);
598
575
  } catch (e) {
599
576
  cb(e, instance, key);
600
- if (!isCatch) throw e;
577
+ if (!isCatch)
578
+ throw e;
601
579
  }
602
580
  };
603
581
  } else {
@@ -606,28 +584,23 @@ function Err(cb, isCatch = false) {
606
584
  oldFn(...args);
607
585
  } catch (e) {
608
586
  cb(e, instance, key);
609
- if (!isCatch) throw e;
587
+ if (!isCatch)
588
+ throw e;
610
589
  }
611
590
  };
612
591
  }
613
592
  }
614
- }, "init")
593
+ }
615
594
  });
616
595
  };
617
596
  }
618
- __name(Err, "Err");
619
597
  function Watcher(eventName, options) {
620
598
  let cb;
621
599
  return (proto, key) => {
622
600
  setStateKey(proto, key);
623
601
  setHandler(proto, key, {
624
602
  init(instance) {
625
- return cb = getInject("watcher")?.({
626
- eventName,
627
- instance,
628
- key,
629
- options
630
- });
603
+ return cb = getInject("watcher")?.({ eventName, instance, key, options });
631
604
  },
632
605
  unmount() {
633
606
  return cb?.();
@@ -635,7 +608,6 @@ function Watcher(eventName, options) {
635
608
  });
636
609
  };
637
610
  }
638
- __name(Watcher, "Watcher");
639
611
  function Effect(cb) {
640
612
  return (proto, key) => {
641
613
  setStateKey(proto, key);
@@ -656,28 +628,22 @@ function Effect(cb) {
656
628
  });
657
629
  };
658
630
  }
659
- __name(Effect, "Effect");
660
631
  function Storage({ key: storeKey, json, stringify } = {}) {
661
- if (!json) json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
662
- if (!stringify) stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
632
+ if (!json)
633
+ json = (v) => JSON.parse(v);
634
+ if (!stringify)
635
+ stringify = (v) => JSON.stringify(v);
663
636
  return (proto, key) => {
664
637
  const tag = storeKey || getTag(proto);
665
638
  init(proto);
666
639
  setStateKey(proto, key);
667
640
  setHandler(proto, key, {
668
- init: /* @__PURE__ */ __name((instance) => {
669
- return getInject("storage")?.({
670
- instance,
671
- key,
672
- tag,
673
- toJSON: json,
674
- toString: stringify
675
- });
676
- }, "init")
641
+ init: (instance) => {
642
+ return getInject("storage")?.({ instance, key, tag, toJSON: json, toString: stringify });
643
+ }
677
644
  });
678
645
  };
679
646
  }
680
- __name(Storage, "Storage");
681
647
  function If(value, ...decorators) {
682
648
  if (value) {
683
649
  return (...args) => {
@@ -687,27 +653,11 @@ function If(value, ...decorators) {
687
653
  return () => {
688
654
  };
689
655
  }
690
- __name(If, "If");
691
656
 
692
657
  // src/base.ts
693
- function _ts_decorate(decorators, target, key, desc) {
694
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
695
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
696
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
697
- return c > 3 && r && Object.defineProperty(target, key, r), r;
698
- }
699
- __name(_ts_decorate, "_ts_decorate");
700
- function _ts_metadata(k, v) {
701
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
702
- }
703
- __name(_ts_metadata, "_ts_metadata");
704
658
  var Base = class {
705
- static {
706
- __name(this, "Base");
707
- }
708
- __UNMOUNT_SYMBOL__ = [];
709
- __PROMISE_SYMBOL__;
710
659
  constructor() {
660
+ this.__UNMOUNT_SYMBOL__ = [];
711
661
  }
712
662
  get tag() {
713
663
  return getTag(this);
@@ -728,16 +678,17 @@ var Base = class {
728
678
  onUnmount(cb) {
729
679
  this.__UNMOUNT_SYMBOL__.push(cb);
730
680
  }
681
+ // @ts-expect-error for internal
731
682
  _unmount() {
732
683
  return Promise.all(this.__UNMOUNT_SYMBOL__.map((fn) => fn()));
733
684
  }
734
685
  };
735
- _ts_decorate([
736
- Unmount,
737
- _ts_metadata("design:type", Function),
738
- _ts_metadata("design:paramtypes", []),
739
- _ts_metadata("design:returntype", void 0)
740
- ], Base.prototype, "_unmount", null);
686
+ __decorateClass([
687
+ Unmount
688
+ ], Base.prototype, "_unmount", 1);
689
+ Base = __decorateClass([
690
+ Empty
691
+ ], Base);
741
692
  // Annotate the CommonJS export names for ESM import in node:
742
693
  0 && (module.exports = {
743
694
  Assign,
@@ -754,6 +705,7 @@ _ts_decorate([
754
705
  Ignore,
755
706
  Init,
756
707
  Inject,
708
+ Injectable,
757
709
  Isolate,
758
710
  PHECDA_KEY,
759
711
  Pipeline,