phecda-core 4.1.0-alpha.2 → 4.1.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,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;
@@ -114,4 +120,4 @@ declare abstract class Base {
114
120
  private _unmount;
115
121
  }
116
122
 
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 };
123
+ 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;
@@ -114,4 +120,4 @@ declare abstract class Base {
114
120
  private _unmount;
115
121
  }
116
122
 
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 };
123
+ 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,
@@ -345,6 +350,18 @@ function omit(classFn, ...properties) {
345
350
  });
346
351
  return newClass;
347
352
  }
353
+ function partial(classFn, ...properties) {
354
+ const newClass = class extends classFn {
355
+ };
356
+ getMetaKey(classFn).forEach((k) => {
357
+ if (properties.includes(k))
358
+ addDecoToClass(newClass, k, Optional);
359
+ });
360
+ return newClass;
361
+ }
362
+ function override(classFn, ...properties) {
363
+ return classFn;
364
+ }
348
365
 
349
366
  // src/di.ts
350
367
  var DataMap = {};
@@ -480,6 +497,19 @@ function Storage({ key, json, stringify } = {}) {
480
497
  };
481
498
  }
482
499
 
500
+ // src/decorators/rule.ts
501
+ function Rule(...rules) {
502
+ return (target, property) => {
503
+ setMeta(target, property, void 0, { rules });
504
+ };
505
+ }
506
+ function Required(target, property) {
507
+ setMeta(target, property, void 0, { required: true });
508
+ }
509
+ function Optional(target, property) {
510
+ setMeta(target, property, void 0, { required: false });
511
+ }
512
+
483
513
  // src/base.ts
484
514
  var Base = class {
485
515
  constructor() {
@@ -532,9 +562,12 @@ Base = __decorateClass([
532
562
  Inject,
533
563
  Injectable,
534
564
  Isolate,
565
+ Optional,
535
566
  PHECDA_KEY,
536
567
  Pipeline,
537
568
  Provide,
569
+ Required,
570
+ Rule,
538
571
  SHARE_KEY,
539
572
  Storage,
540
573
  Tag,
@@ -563,6 +596,8 @@ Base = __decorateClass([
563
596
  isPhecda,
564
597
  objectToClass,
565
598
  omit,
599
+ override,
600
+ partial,
566
601
  set,
567
602
  setInject,
568
603
  setMeta,
package/dist/index.mjs CHANGED
@@ -273,6 +273,18 @@ function omit(classFn, ...properties) {
273
273
  });
274
274
  return newClass;
275
275
  }
276
+ function partial(classFn, ...properties) {
277
+ const newClass = class extends classFn {
278
+ };
279
+ getMetaKey(classFn).forEach((k) => {
280
+ if (properties.includes(k))
281
+ addDecoToClass(newClass, k, Optional);
282
+ });
283
+ return newClass;
284
+ }
285
+ function override(classFn, ...properties) {
286
+ return classFn;
287
+ }
276
288
 
277
289
  // src/di.ts
278
290
  var DataMap = {};
@@ -408,6 +420,19 @@ function Storage({ key, json, stringify } = {}) {
408
420
  };
409
421
  }
410
422
 
423
+ // src/decorators/rule.ts
424
+ function Rule(...rules) {
425
+ return (target, property) => {
426
+ setMeta(target, property, void 0, { rules });
427
+ };
428
+ }
429
+ function Required(target, property) {
430
+ setMeta(target, property, void 0, { required: true });
431
+ }
432
+ function Optional(target, property) {
433
+ setMeta(target, property, void 0, { required: false });
434
+ }
435
+
411
436
  // src/base.ts
412
437
  var Base = class {
413
438
  constructor() {
@@ -459,9 +484,12 @@ export {
459
484
  Inject,
460
485
  Injectable,
461
486
  Isolate,
487
+ Optional,
462
488
  PHECDA_KEY,
463
489
  Pipeline,
464
490
  Provide,
491
+ Required,
492
+ Rule,
465
493
  SHARE_KEY,
466
494
  Storage,
467
495
  Tag,
@@ -490,6 +518,8 @@ export {
490
518
  isPhecda,
491
519
  objectToClass,
492
520
  omit,
521
+ override,
522
+ partial,
493
523
  set,
494
524
  setInject,
495
525
  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.1.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')