phecda-core 4.2.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -76,9 +76,10 @@ declare function Storage({ key, json, stringify }?: {
76
76
  key?: string;
77
77
  }): (proto: any, property?: PropertyKey) => void;
78
78
 
79
- declare function Rule(...rules: ((value: any) => void | string | Promise<void | string>)[]): (target: any, property: PropertyKey) => void;
80
- declare function Required(target: any, property: PropertyKey): void;
81
- declare function Optional(target: any, property: PropertyKey): void;
79
+ declare function Rule(...rules: ((value: any) => void | string | boolean | Promise<void | string | boolean>)[]): (target: any, property: PropertyKey, index?: any) => void;
80
+ declare function Required(target: any, property: PropertyKey, index?: any): void;
81
+ declare function Optional(target: any, property: PropertyKey, index?: any): void;
82
+ declare function Doc(doc: string): (target: any, property: PropertyKey, index?: any) => void;
82
83
 
83
84
  declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
84
85
  /**
@@ -96,6 +97,7 @@ declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
96
97
  declare function objectToClass<Obj extends Record<string, any>>(obj: Obj): new () => Obj;
97
98
  declare function functionToClass<Func extends (...args: any) => object>(fn: Func): new (...args: Parameters<Func>) => ReturnType<Func>;
98
99
  declare function omit<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
100
+ declare function pick<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Pick<InstanceType<Class>, Key>>;
99
101
  declare function partial<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Partial<Pick<InstanceType<Class>, Key>> & Omit<InstanceType<Class>, Key>>;
100
102
  declare function override<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
101
103
 
@@ -121,4 +123,4 @@ declare abstract class Base {
121
123
  private _unmount;
122
124
  }
123
125
 
124
- export { type AbConstruct, Assign, Base, CLEAR_KEY, type ClassValue, Clear, type Construct, DataMap, Effect, Empty, Err, type Events, Expose, Global, If, Init, Inject, type InjectData, Injectable, Isolate, type NameSpace, Optional, PHECDA_KEY, type Phecda, Pipeline, Provide, Required, Rule, SHARE_KEY, Storage, type StorageParam, Tag, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, functionToClass, get, getInject, getMergedMeta, getMeta, getMetaKey, getMetaParams, getOwnMeta, getOwnMetaKey, getOwnMetaParams, getPhecdaFromTarget, getTag, init, invoke, invokeInit, invokeUnmount, isAsyncFunc, isPhecda, objectToClass, omit, override, partial, set, setInject, setMeta, wait };
126
+ export { type AbConstruct, Assign, Base, CLEAR_KEY, type ClassValue, Clear, type Construct, DataMap, Doc, Effect, Empty, Err, type Events, Expose, Global, If, Init, Inject, type InjectData, Injectable, Isolate, type NameSpace, Optional, PHECDA_KEY, type Phecda, Pipeline, Provide, Required, Rule, SHARE_KEY, Storage, type StorageParam, Tag, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, functionToClass, get, getInject, getMergedMeta, getMeta, getMetaKey, getMetaParams, getOwnMeta, getOwnMetaKey, getOwnMetaParams, getPhecdaFromTarget, getTag, init, invoke, invokeInit, invokeUnmount, isAsyncFunc, isPhecda, objectToClass, omit, override, partial, pick, set, setInject, setMeta, wait };
package/dist/index.d.ts CHANGED
@@ -76,9 +76,10 @@ declare function Storage({ key, json, stringify }?: {
76
76
  key?: string;
77
77
  }): (proto: any, property?: PropertyKey) => void;
78
78
 
79
- declare function Rule(...rules: ((value: any) => void | string | Promise<void | string>)[]): (target: any, property: PropertyKey) => void;
80
- declare function Required(target: any, property: PropertyKey): void;
81
- declare function Optional(target: any, property: PropertyKey): void;
79
+ declare function Rule(...rules: ((value: any) => void | string | boolean | Promise<void | string | boolean>)[]): (target: any, property: PropertyKey, index?: any) => void;
80
+ declare function Required(target: any, property: PropertyKey, index?: any): void;
81
+ declare function Optional(target: any, property: PropertyKey, index?: any): void;
82
+ declare function Doc(doc: string): (target: any, property: PropertyKey, index?: any) => void;
82
83
 
83
84
  declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
84
85
  /**
@@ -96,6 +97,7 @@ declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
96
97
  declare function objectToClass<Obj extends Record<string, any>>(obj: Obj): new () => Obj;
97
98
  declare function functionToClass<Func extends (...args: any) => object>(fn: Func): new (...args: Parameters<Func>) => ReturnType<Func>;
98
99
  declare function omit<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
100
+ declare function pick<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Pick<InstanceType<Class>, Key>>;
99
101
  declare function partial<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Partial<Pick<InstanceType<Class>, Key>> & Omit<InstanceType<Class>, Key>>;
100
102
  declare function override<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
101
103
 
@@ -121,4 +123,4 @@ declare abstract class Base {
121
123
  private _unmount;
122
124
  }
123
125
 
124
- export { type AbConstruct, Assign, Base, CLEAR_KEY, type ClassValue, Clear, type Construct, DataMap, Effect, Empty, Err, type Events, Expose, Global, If, Init, Inject, type InjectData, Injectable, Isolate, type NameSpace, Optional, PHECDA_KEY, type Phecda, Pipeline, Provide, Required, Rule, SHARE_KEY, Storage, type StorageParam, Tag, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, functionToClass, get, getInject, getMergedMeta, getMeta, getMetaKey, getMetaParams, getOwnMeta, getOwnMetaKey, getOwnMetaParams, getPhecdaFromTarget, getTag, init, invoke, invokeInit, invokeUnmount, isAsyncFunc, isPhecda, objectToClass, omit, override, partial, set, setInject, setMeta, wait };
126
+ export { type AbConstruct, Assign, Base, CLEAR_KEY, type ClassValue, Clear, type Construct, DataMap, Doc, Effect, Empty, Err, type Events, Expose, Global, If, Init, Inject, type InjectData, Injectable, Isolate, type NameSpace, Optional, PHECDA_KEY, type Phecda, Pipeline, Provide, Required, Rule, SHARE_KEY, Storage, type StorageParam, Tag, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, functionToClass, get, getInject, getMergedMeta, getMeta, getMetaKey, getMetaParams, getOwnMeta, getOwnMetaKey, getOwnMetaParams, getPhecdaFromTarget, getTag, init, invoke, invokeInit, invokeUnmount, isAsyncFunc, isPhecda, objectToClass, omit, override, partial, pick, set, setInject, setMeta, wait };
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  CLEAR_KEY: () => CLEAR_KEY,
34
34
  Clear: () => Clear,
35
35
  DataMap: () => DataMap,
36
+ Doc: () => Doc,
36
37
  Effect: () => Effect,
37
38
  Empty: () => Empty,
38
39
  Err: () => Err,
@@ -79,6 +80,7 @@ __export(index_exports, {
79
80
  omit: () => omit,
80
81
  override: () => override,
81
82
  partial: () => partial,
83
+ pick: () => pick,
82
84
  set: () => set,
83
85
  setInject: () => setInject,
84
86
  setMeta: () => setMeta,
@@ -115,6 +117,8 @@ function getPhecdaFromTarget(target) {
115
117
  return Object.getPrototypeOf(target);
116
118
  }
117
119
  function setMeta(proto, property, index, meta) {
120
+ if (typeof proto === "function" && proto.prototype)
121
+ proto = proto.prototype;
118
122
  if (!property) {
119
123
  property = SHARE_KEY;
120
124
  if (proto.prototype)
@@ -351,6 +355,35 @@ function omit(classFn, ...properties) {
351
355
  });
352
356
  return newClass;
353
357
  }
358
+ function pick(classFn, ...properties) {
359
+ const newClass = class {
360
+ constructor(...args) {
361
+ const instance = new classFn(...args);
362
+ properties.forEach((prop) => {
363
+ Object.defineProperty(this, prop, {
364
+ get() {
365
+ const data = instance[prop];
366
+ if (typeof data === "function")
367
+ return data.bind(this);
368
+ return data;
369
+ },
370
+ set(val) {
371
+ instance[prop] = val;
372
+ }
373
+ });
374
+ });
375
+ }
376
+ };
377
+ getMetaKey(classFn).forEach((k) => {
378
+ if (properties.includes(k)) {
379
+ setMeta(newClass, k, void 0, getMergedMeta(classFn, k));
380
+ getMetaParams(classFn, k).forEach((index) => {
381
+ setMeta(newClass, k, index, getMergedMeta(classFn, k, index));
382
+ });
383
+ }
384
+ });
385
+ return newClass;
386
+ }
354
387
  function partial(classFn, ...properties) {
355
388
  const newClass = class extends classFn {
356
389
  };
@@ -498,17 +531,22 @@ function Storage({ key, json, stringify } = {}) {
498
531
  };
499
532
  }
500
533
 
501
- // src/decorators/rule.ts
534
+ // src/decorators/other.ts
502
535
  function Rule(...rules) {
503
- return (target, property) => {
504
- setMeta(target, property, void 0, { rules });
536
+ return (target, property, index) => {
537
+ setMeta(target, property, index, { rules });
505
538
  };
506
539
  }
507
- function Required(target, property) {
508
- setMeta(target, property, void 0, { required: true });
540
+ function Required(target, property, index) {
541
+ setMeta(target, property, index, { required: true });
509
542
  }
510
- function Optional(target, property) {
511
- setMeta(target, property, void 0, { required: false });
543
+ function Optional(target, property, index) {
544
+ setMeta(target, property, index, { required: false });
545
+ }
546
+ function Doc(doc) {
547
+ return (target, property, index) => {
548
+ setMeta(target, property, index, { doc });
549
+ };
512
550
  }
513
551
 
514
552
  // src/base.ts
@@ -558,6 +596,7 @@ Base = __decorateClass([
558
596
  CLEAR_KEY,
559
597
  Clear,
560
598
  DataMap,
599
+ Doc,
561
600
  Effect,
562
601
  Empty,
563
602
  Err,
@@ -604,6 +643,7 @@ Base = __decorateClass([
604
643
  omit,
605
644
  override,
606
645
  partial,
646
+ pick,
607
647
  set,
608
648
  setInject,
609
649
  setMeta,
package/dist/index.mjs CHANGED
@@ -38,6 +38,8 @@ function getPhecdaFromTarget(target) {
38
38
  return Object.getPrototypeOf(target);
39
39
  }
40
40
  function setMeta(proto, property, index, meta) {
41
+ if (typeof proto === "function" && proto.prototype)
42
+ proto = proto.prototype;
41
43
  if (!property) {
42
44
  property = SHARE_KEY;
43
45
  if (proto.prototype)
@@ -274,6 +276,35 @@ function omit(classFn, ...properties) {
274
276
  });
275
277
  return newClass;
276
278
  }
279
+ function pick(classFn, ...properties) {
280
+ const newClass = class {
281
+ constructor(...args) {
282
+ const instance = new classFn(...args);
283
+ properties.forEach((prop) => {
284
+ Object.defineProperty(this, prop, {
285
+ get() {
286
+ const data = instance[prop];
287
+ if (typeof data === "function")
288
+ return data.bind(this);
289
+ return data;
290
+ },
291
+ set(val) {
292
+ instance[prop] = val;
293
+ }
294
+ });
295
+ });
296
+ }
297
+ };
298
+ getMetaKey(classFn).forEach((k) => {
299
+ if (properties.includes(k)) {
300
+ setMeta(newClass, k, void 0, getMergedMeta(classFn, k));
301
+ getMetaParams(classFn, k).forEach((index) => {
302
+ setMeta(newClass, k, index, getMergedMeta(classFn, k, index));
303
+ });
304
+ }
305
+ });
306
+ return newClass;
307
+ }
277
308
  function partial(classFn, ...properties) {
278
309
  const newClass = class extends classFn {
279
310
  };
@@ -421,17 +452,22 @@ function Storage({ key, json, stringify } = {}) {
421
452
  };
422
453
  }
423
454
 
424
- // src/decorators/rule.ts
455
+ // src/decorators/other.ts
425
456
  function Rule(...rules) {
426
- return (target, property) => {
427
- setMeta(target, property, void 0, { rules });
457
+ return (target, property, index) => {
458
+ setMeta(target, property, index, { rules });
428
459
  };
429
460
  }
430
- function Required(target, property) {
431
- setMeta(target, property, void 0, { required: true });
461
+ function Required(target, property, index) {
462
+ setMeta(target, property, index, { required: true });
432
463
  }
433
- function Optional(target, property) {
434
- setMeta(target, property, void 0, { required: false });
464
+ function Optional(target, property, index) {
465
+ setMeta(target, property, index, { required: false });
466
+ }
467
+ function Doc(doc) {
468
+ return (target, property, index) => {
469
+ setMeta(target, property, index, { doc });
470
+ };
435
471
  }
436
472
 
437
473
  // src/base.ts
@@ -480,6 +516,7 @@ export {
480
516
  CLEAR_KEY,
481
517
  Clear,
482
518
  DataMap,
519
+ Doc,
483
520
  Effect,
484
521
  Empty,
485
522
  Err,
@@ -526,6 +563,7 @@ export {
526
563
  omit,
527
564
  override,
528
565
  partial,
566
+ pick,
529
567
  set,
530
568
  setInject,
531
569
  setMeta,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "4.2.0",
3
+ "version": "4.4.0",
4
4
  "description": "provide base function and abstract limit to other phecda module ",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",