phecda-core 4.1.0-alpha.2 → 4.2.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/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # phecda-core
2
- provide base function and abstract limit to other phecda module
3
-
1
+ # phecda-core
2
+ provide base function and abstract limit to other phecda module
3
+
package/dist/index.d.mts CHANGED
@@ -76,6 +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;
82
+
79
83
  declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
80
84
  /**
81
85
  * add decorator to a class by function
@@ -92,6 +96,8 @@ declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
92
96
  declare function objectToClass<Obj extends Record<string, any>>(obj: Obj): new () => Obj;
93
97
  declare function functionToClass<Func extends (...args: any) => object>(fn: Func): new (...args: Parameters<Func>) => ReturnType<Func>;
94
98
  declare function omit<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
99
+ 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
+ declare function override<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
95
101
 
96
102
  declare const DataMap: InjectData;
97
103
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
@@ -106,6 +112,7 @@ declare abstract class Base {
106
112
  abstract emitter: any;
107
113
  constructor();
108
114
  get tag(): PropertyKey;
115
+ init(): void;
109
116
  then(cb: () => void, reject?: (e: any) => void): Promise<void>;
110
117
  on<Key extends keyof Events>(type: Key, handler: (arg: Events[Key]) => void): void;
111
118
  emit<Key extends keyof Events>(type: Key, param: Events[Key]): void;
@@ -114,4 +121,4 @@ declare abstract class Base {
114
121
  private _unmount;
115
122
  }
116
123
 
117
- 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, PHECDA_KEY, type Phecda, Pipeline, Provide, 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, set, setInject, setMeta, wait };
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 };
package/dist/index.d.ts CHANGED
@@ -76,6 +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;
82
+
79
83
  declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
80
84
  /**
81
85
  * add decorator to a class by function
@@ -92,6 +96,8 @@ declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
92
96
  declare function objectToClass<Obj extends Record<string, any>>(obj: Obj): new () => Obj;
93
97
  declare function functionToClass<Func extends (...args: any) => object>(fn: Func): new (...args: Parameters<Func>) => ReturnType<Func>;
94
98
  declare function omit<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
99
+ 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
+ declare function override<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
95
101
 
96
102
  declare const DataMap: InjectData;
97
103
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
@@ -106,6 +112,7 @@ declare abstract class Base {
106
112
  abstract emitter: any;
107
113
  constructor();
108
114
  get tag(): PropertyKey;
115
+ init(): void;
109
116
  then(cb: () => void, reject?: (e: any) => void): Promise<void>;
110
117
  on<Key extends keyof Events>(type: Key, handler: (arg: Events[Key]) => void): void;
111
118
  emit<Key extends keyof Events>(type: Key, param: Events[Key]): void;
@@ -114,4 +121,4 @@ declare abstract class Base {
114
121
  private _unmount;
115
122
  }
116
123
 
117
- 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, PHECDA_KEY, type Phecda, Pipeline, Provide, 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, set, setInject, setMeta, wait };
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 };
package/dist/index.js CHANGED
@@ -43,9 +43,12 @@ __export(index_exports, {
43
43
  Inject: () => Inject,
44
44
  Injectable: () => Injectable,
45
45
  Isolate: () => Isolate,
46
+ Optional: () => Optional,
46
47
  PHECDA_KEY: () => PHECDA_KEY,
47
48
  Pipeline: () => Pipeline,
48
49
  Provide: () => Provide,
50
+ Required: () => Required,
51
+ Rule: () => Rule,
49
52
  SHARE_KEY: () => SHARE_KEY,
50
53
  Storage: () => Storage,
51
54
  Tag: () => Tag,
@@ -74,6 +77,8 @@ __export(index_exports, {
74
77
  isPhecda: () => isPhecda,
75
78
  objectToClass: () => objectToClass,
76
79
  omit: () => omit,
80
+ override: () => override,
81
+ partial: () => partial,
77
82
  set: () => set,
78
83
  setInject: () => setInject,
79
84
  setMeta: () => setMeta,
@@ -112,7 +117,8 @@ function getPhecdaFromTarget(target) {
112
117
  function setMeta(proto, property, index, meta) {
113
118
  if (!property) {
114
119
  property = SHARE_KEY;
115
- proto = proto.prototype;
120
+ if (proto.prototype)
121
+ proto = proto.prototype;
116
122
  }
117
123
  init(proto);
118
124
  if (!proto[PHECDA_KEY].__META__.has(property))
@@ -345,6 +351,18 @@ function omit(classFn, ...properties) {
345
351
  });
346
352
  return newClass;
347
353
  }
354
+ function partial(classFn, ...properties) {
355
+ const newClass = class extends classFn {
356
+ };
357
+ getMetaKey(classFn).forEach((k) => {
358
+ if (properties.includes(k))
359
+ addDecoToClass(newClass, k, Optional);
360
+ });
361
+ return newClass;
362
+ }
363
+ function override(classFn, ...properties) {
364
+ return classFn;
365
+ }
348
366
 
349
367
  // src/di.ts
350
368
  var DataMap = {};
@@ -480,6 +498,19 @@ function Storage({ key, json, stringify } = {}) {
480
498
  };
481
499
  }
482
500
 
501
+ // src/decorators/rule.ts
502
+ function Rule(...rules) {
503
+ return (target, property) => {
504
+ setMeta(target, property, void 0, { rules });
505
+ };
506
+ }
507
+ function Required(target, property) {
508
+ setMeta(target, property, void 0, { required: true });
509
+ }
510
+ function Optional(target, property) {
511
+ setMeta(target, property, void 0, { required: false });
512
+ }
513
+
483
514
  // src/base.ts
484
515
  var Base = class {
485
516
  constructor() {
@@ -488,6 +519,8 @@ var Base = class {
488
519
  get tag() {
489
520
  return getTag(this);
490
521
  }
522
+ init() {
523
+ }
491
524
  then(cb, reject) {
492
525
  return this.__PROMISE_SYMBOL__.then(cb, reject);
493
526
  }
@@ -509,6 +542,9 @@ var Base = class {
509
542
  return Promise.all(this.__UNMOUNT_SYMBOL__.map((fn) => fn()));
510
543
  }
511
544
  };
545
+ __decorateClass([
546
+ Init
547
+ ], Base.prototype, "init", 1);
512
548
  __decorateClass([
513
549
  Unmount
514
550
  ], Base.prototype, "_unmount", 1);
@@ -532,9 +568,12 @@ Base = __decorateClass([
532
568
  Inject,
533
569
  Injectable,
534
570
  Isolate,
571
+ Optional,
535
572
  PHECDA_KEY,
536
573
  Pipeline,
537
574
  Provide,
575
+ Required,
576
+ Rule,
538
577
  SHARE_KEY,
539
578
  Storage,
540
579
  Tag,
@@ -563,6 +602,8 @@ Base = __decorateClass([
563
602
  isPhecda,
564
603
  objectToClass,
565
604
  omit,
605
+ override,
606
+ partial,
566
607
  set,
567
608
  setInject,
568
609
  setMeta,
package/dist/index.mjs CHANGED
@@ -40,7 +40,8 @@ function getPhecdaFromTarget(target) {
40
40
  function setMeta(proto, property, index, meta) {
41
41
  if (!property) {
42
42
  property = SHARE_KEY;
43
- proto = proto.prototype;
43
+ if (proto.prototype)
44
+ proto = proto.prototype;
44
45
  }
45
46
  init(proto);
46
47
  if (!proto[PHECDA_KEY].__META__.has(property))
@@ -273,6 +274,18 @@ function omit(classFn, ...properties) {
273
274
  });
274
275
  return newClass;
275
276
  }
277
+ function partial(classFn, ...properties) {
278
+ const newClass = class extends classFn {
279
+ };
280
+ getMetaKey(classFn).forEach((k) => {
281
+ if (properties.includes(k))
282
+ addDecoToClass(newClass, k, Optional);
283
+ });
284
+ return newClass;
285
+ }
286
+ function override(classFn, ...properties) {
287
+ return classFn;
288
+ }
276
289
 
277
290
  // src/di.ts
278
291
  var DataMap = {};
@@ -408,6 +421,19 @@ function Storage({ key, json, stringify } = {}) {
408
421
  };
409
422
  }
410
423
 
424
+ // src/decorators/rule.ts
425
+ function Rule(...rules) {
426
+ return (target, property) => {
427
+ setMeta(target, property, void 0, { rules });
428
+ };
429
+ }
430
+ function Required(target, property) {
431
+ setMeta(target, property, void 0, { required: true });
432
+ }
433
+ function Optional(target, property) {
434
+ setMeta(target, property, void 0, { required: false });
435
+ }
436
+
411
437
  // src/base.ts
412
438
  var Base = class {
413
439
  constructor() {
@@ -416,6 +442,8 @@ var Base = class {
416
442
  get tag() {
417
443
  return getTag(this);
418
444
  }
445
+ init() {
446
+ }
419
447
  then(cb, reject) {
420
448
  return this.__PROMISE_SYMBOL__.then(cb, reject);
421
449
  }
@@ -437,6 +465,9 @@ var Base = class {
437
465
  return Promise.all(this.__UNMOUNT_SYMBOL__.map((fn) => fn()));
438
466
  }
439
467
  };
468
+ __decorateClass([
469
+ Init
470
+ ], Base.prototype, "init", 1);
440
471
  __decorateClass([
441
472
  Unmount
442
473
  ], Base.prototype, "_unmount", 1);
@@ -459,9 +490,12 @@ export {
459
490
  Inject,
460
491
  Injectable,
461
492
  Isolate,
493
+ Optional,
462
494
  PHECDA_KEY,
463
495
  Pipeline,
464
496
  Provide,
497
+ Required,
498
+ Rule,
465
499
  SHARE_KEY,
466
500
  Storage,
467
501
  Tag,
@@ -490,6 +524,8 @@ export {
490
524
  isPhecda,
491
525
  objectToClass,
492
526
  omit,
527
+ override,
528
+ partial,
493
529
  set,
494
530
  setInject,
495
531
  setMeta,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "4.1.0-alpha.2",
3
+ "version": "4.2.0",
4
4
  "description": "provide base function and abstract limit to other phecda module ",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",
package/dist/a.ts DELETED
@@ -1,17 +0,0 @@
1
- export function Pick<T extends object, K extends keyof T>(obj: T, ...args: K[]): Pick<T, K> {
2
- const result = {} as Pick<T, K>
3
- for (const key of args) {
4
- if (obj.hasOwnProperty(key)) {
5
- result[key] = obj[key]
6
- }
7
- }
8
- return result
9
- }
10
-
11
- const a = {
12
- b: 1,
13
- c: 1
14
- }
15
-
16
-
17
- const x = Pick(a, 'b', 'c')