phecda-core 4.1.0-alpha.1 → 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/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
@@ -91,6 +95,9 @@ declare function getMergedMeta(target: any, property?: PropertyKey, index?: numb
91
95
  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>;
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>>;
94
101
 
95
102
  declare const DataMap: InjectData;
96
103
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
@@ -113,4 +120,4 @@ declare abstract class Base {
113
120
  private _unmount;
114
121
  }
115
122
 
116
- 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, 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
@@ -91,6 +95,9 @@ declare function getMergedMeta(target: any, property?: PropertyKey, index?: numb
91
95
  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>;
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>>;
94
101
 
95
102
  declare const DataMap: InjectData;
96
103
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
@@ -113,4 +120,4 @@ declare abstract class Base {
113
120
  private _unmount;
114
121
  }
115
122
 
116
- 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, 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,
@@ -73,6 +76,9 @@ __export(index_exports, {
73
76
  isAsyncFunc: () => isAsyncFunc,
74
77
  isPhecda: () => isPhecda,
75
78
  objectToClass: () => objectToClass,
79
+ omit: () => omit,
80
+ override: () => override,
81
+ partial: () => partial,
76
82
  set: () => set,
77
83
  setInject: () => setInject,
78
84
  setMeta: () => setMeta,
@@ -329,6 +335,33 @@ function functionToClass(fn) {
329
335
  }
330
336
  };
331
337
  }
338
+ function omit(classFn, ...properties) {
339
+ const newClass = class extends classFn {
340
+ constructor(...args) {
341
+ super(...args);
342
+ properties.forEach((k) => {
343
+ delete this[k];
344
+ });
345
+ }
346
+ };
347
+ getMetaKey(classFn).forEach((k) => {
348
+ if (properties.includes(k))
349
+ addDecoToClass(newClass, k, Clear);
350
+ });
351
+ return newClass;
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
+ }
332
365
 
333
366
  // src/di.ts
334
367
  var DataMap = {};
@@ -464,6 +497,19 @@ function Storage({ key, json, stringify } = {}) {
464
497
  };
465
498
  }
466
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
+
467
513
  // src/base.ts
468
514
  var Base = class {
469
515
  constructor() {
@@ -516,9 +562,12 @@ Base = __decorateClass([
516
562
  Inject,
517
563
  Injectable,
518
564
  Isolate,
565
+ Optional,
519
566
  PHECDA_KEY,
520
567
  Pipeline,
521
568
  Provide,
569
+ Required,
570
+ Rule,
522
571
  SHARE_KEY,
523
572
  Storage,
524
573
  Tag,
@@ -546,6 +595,9 @@ Base = __decorateClass([
546
595
  isAsyncFunc,
547
596
  isPhecda,
548
597
  objectToClass,
598
+ omit,
599
+ override,
600
+ partial,
549
601
  set,
550
602
  setInject,
551
603
  setMeta,
package/dist/index.mjs CHANGED
@@ -258,6 +258,33 @@ function functionToClass(fn) {
258
258
  }
259
259
  };
260
260
  }
261
+ function omit(classFn, ...properties) {
262
+ const newClass = class extends classFn {
263
+ constructor(...args) {
264
+ super(...args);
265
+ properties.forEach((k) => {
266
+ delete this[k];
267
+ });
268
+ }
269
+ };
270
+ getMetaKey(classFn).forEach((k) => {
271
+ if (properties.includes(k))
272
+ addDecoToClass(newClass, k, Clear);
273
+ });
274
+ return newClass;
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
+ }
261
288
 
262
289
  // src/di.ts
263
290
  var DataMap = {};
@@ -393,6 +420,19 @@ function Storage({ key, json, stringify } = {}) {
393
420
  };
394
421
  }
395
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
+
396
436
  // src/base.ts
397
437
  var Base = class {
398
438
  constructor() {
@@ -444,9 +484,12 @@ export {
444
484
  Inject,
445
485
  Injectable,
446
486
  Isolate,
487
+ Optional,
447
488
  PHECDA_KEY,
448
489
  Pipeline,
449
490
  Provide,
491
+ Required,
492
+ Rule,
450
493
  SHARE_KEY,
451
494
  Storage,
452
495
  Tag,
@@ -474,6 +517,9 @@ export {
474
517
  isAsyncFunc,
475
518
  isPhecda,
476
519
  objectToClass,
520
+ omit,
521
+ override,
522
+ partial,
477
523
  set,
478
524
  setInject,
479
525
  setMeta,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "4.1.0-alpha.1",
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",