phecda-core 2.0.0-alpha.2 → 2.0.0-alpha.4

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.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { i as isArray, a as isBoolean, j as isCnName, l as isDate, k as isEnName, n as isHexColor, h as isIdCard, f as isLandline, g as isMailBox, e as isMobile, b as isNumber, d as isObject, o as isPostalCode, c as isString, m as isWechat, t as toNumber, p as toString } from './pipe-6da589ab.js';
1
+ export { a as isArray, b as isBoolean, k as isCnName, m as isDate, l as isEnName, o as isHexColor, j as isIdCard, g as isLandline, h as isMailBox, f as isMobile, c as isNumber, e as isObject, i as isOption, p as isPostalCode, d as isString, n as isWechat, t as toNumber, q as toString } from './pipe-5d060247.js';
2
2
 
3
3
  interface NameSpace {
4
4
  [name: string]: Phecda;
@@ -7,10 +7,10 @@ interface UsePipeOptions {
7
7
  transform?: boolean;
8
8
  collectError?: boolean;
9
9
  }
10
- interface PhecdaInjectData {
10
+ interface InjectData {
11
11
  [key: string]: any;
12
12
  }
13
- interface PhecdaHandler {
13
+ interface Handler {
14
14
  [key: string]: any;
15
15
  }
16
16
  interface Phecda {
@@ -20,7 +20,7 @@ interface Phecda {
20
20
  __EXPOSE_VAR__: Set<PropertyKey>;
21
21
  __IGNORE_VAR__: Set<PropertyKey>;
22
22
  __STATE_VAR__: Set<PropertyKey>;
23
- __STATE_HANDLER__: Map<PropertyKey, PhecdaHandler[]>;
23
+ __STATE_HANDLER__: Map<PropertyKey, Handler[]>;
24
24
  __STATE_NAMESPACE__: Map<PropertyKey, Object>;
25
25
  };
26
26
  }
@@ -79,7 +79,7 @@ declare function addDecoToClass<M extends new (...args: any) => any>(c: M, key:
79
79
 
80
80
  declare function Init(target: any, key: PropertyKey): void;
81
81
  declare function Bind(value: any): (target: any, k: PropertyKey) => void;
82
- declare function Rule(rule: RegExp | string | Function | number, info: string | ((k: string) => string), meta?: any): (obj: any, key: PropertyKey) => void;
82
+ declare function Rule(rule: RegExp | string | ((arg: any) => boolean | 'ok') | number, info: string | ((k: string) => string), meta?: any): (obj: any, key: PropertyKey) => void;
83
83
  declare function Ignore(target: any, key: PropertyKey): void;
84
84
  declare function Clear(target: any, key: PropertyKey): void;
85
85
  declare function Err<Fn extends (...args: any) => any>(cb: Fn): (target: any, key: PropertyKey) => void;
@@ -89,9 +89,9 @@ declare function Tag(tag: string): (target: any) => void;
89
89
  declare function Assign(cb: (instance?: any) => any): (target: any) => void;
90
90
  declare function Global(target: any): void;
91
91
  declare function Empty(_target: any): void;
92
- declare const DataMap: PhecdaInjectData;
93
- declare function Provide<K extends keyof PhecdaInjectData>(key: K, value: PhecdaInjectData[K]): void;
94
- declare function Inject<K extends keyof PhecdaInjectData>(key: K): PhecdaInjectData[K];
92
+ declare const DataMap: InjectData;
93
+ declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
94
+ declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
95
95
 
96
96
  declare function validate(p: RegExp | string | Function | Object | Number, v: any): Promise<any>;
97
97
  declare function getTag<M extends new (...args: any) => any>(Model: M): any;
@@ -109,8 +109,8 @@ declare function getModelState(target: Phecda): PropertyKey[];
109
109
  declare function getOwnExposeKey(target: Phecda): string[];
110
110
  declare function getExposeKey(target: Phecda): PropertyKey[];
111
111
  declare function getOwnIgnoreKey(target: Phecda): string[];
112
- declare function regisHandler(target: Phecda, key: PropertyKey, handler: PhecdaHandler): void;
113
- declare function getOwnHandler(target: Phecda, key: PropertyKey): PhecdaHandler[];
112
+ declare function regisHandler(target: Phecda, key: PropertyKey, handler: Handler): void;
113
+ declare function getOwnHandler(target: Phecda, key: PropertyKey): Handler[];
114
114
  declare function getHandler(target: Phecda, key: PropertyKey): any[];
115
115
  declare function setState(target: Phecda, key: PropertyKey, state: Record<string, any>): void;
116
116
  declare function getOwnState(target: Phecda, key: PropertyKey): Object;
@@ -128,4 +128,4 @@ declare function Watcher(eventName: keyof Events, options?: {
128
128
  declare function Effect(eventName: string, options?: any): (obj: any, key: string) => void;
129
129
  declare function Storage(storeKey?: string): (target: any, key?: PropertyKey) => void;
130
130
 
131
- export { Assign, Bind, ClassValue, Clear, DataMap, Effect, Empty, Err, Events, Expose, Global, Ignore, Init, Inject, NameSpace, Phecda, PhecdaHandler, PhecdaInjectData, Pipe, Provide, Rule, Storage, Tag, UsePipeOptions, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getInitEvent, getModelState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnInitEvent, getOwnModelState, getOwnState, getProperty, getState, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModelVar, setState, snapShot, to, validate };
131
+ export { Assign, Bind, ClassValue, Clear, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, NameSpace, Phecda, Pipe, Provide, Rule, Storage, Tag, UsePipeOptions, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getInitEvent, getModelState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnInitEvent, getOwnModelState, getOwnState, getProperty, getState, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModelVar, setState, snapShot, to, validate };
@@ -71,6 +71,7 @@ var Phecda = (() => {
71
71
  isMobile: () => isMobile,
72
72
  isNumber: () => isNumber,
73
73
  isObject: () => isObject,
74
+ isOption: () => isOption,
74
75
  isPhecda: () => isPhecda,
75
76
  isPostalCode: () => isPostalCode,
76
77
  isString: () => isString,
@@ -366,11 +367,18 @@ var Phecda = (() => {
366
367
  }
367
368
  __name(Assign, "Assign");
368
369
  function Global(target) {
369
- if (!globalThis.__PHECDA__)
370
- globalThis.__PHECDA__ = {};
371
370
  const tag = target.prototype.__TAG__;
372
- if (tag)
373
- globalThis.__PHECDA__[tag] = target;
371
+ if (tag) {
372
+ init(target.prototype);
373
+ setModelVar(target.prototype, "__CLASS");
374
+ regisHandler(target.prototype, "__CLASS", {
375
+ init: async () => {
376
+ if (!globalThis.__PHECDA__)
377
+ globalThis.__PHECDA__ = {};
378
+ globalThis.__PHECDA__[tag] = target;
379
+ }
380
+ });
381
+ }
374
382
  }
375
383
  __name(Global, "Global");
376
384
  function Empty(_target) {
@@ -428,7 +436,10 @@ var Phecda = (() => {
428
436
  if (options.collectError !== false) {
429
437
  for (const handler of handlers) {
430
438
  const rule = handler.rule;
431
- if (rule && !await validate(rule, data[item])) {
439
+ const ret = await validate(rule, data[item]);
440
+ if (ret === "ok")
441
+ break;
442
+ if (rule && !ret) {
432
443
  err.push(typeof handler.info === "function" ? handler.info(item) : handler.info);
433
444
  if (!options.collectError)
434
445
  break;
@@ -583,6 +594,10 @@ var Phecda = (() => {
583
594
  __name(Storage, "Storage");
584
595
 
585
596
  // src/preset/rule.ts
597
+ function isOption() {
598
+ return Rule((param) => param === void 0 ? "ok" : true, "");
599
+ }
600
+ __name(isOption, "isOption");
586
601
  function isArray(info) {
587
602
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
588
603
  }
package/dist/index.js CHANGED
@@ -70,6 +70,7 @@ __export(src_exports, {
70
70
  isMobile: () => isMobile,
71
71
  isNumber: () => isNumber,
72
72
  isObject: () => isObject,
73
+ isOption: () => isOption,
73
74
  isPhecda: () => isPhecda,
74
75
  isPostalCode: () => isPostalCode,
75
76
  isString: () => isString,
@@ -366,11 +367,18 @@ function Assign(cb) {
366
367
  }
367
368
  __name(Assign, "Assign");
368
369
  function Global(target) {
369
- if (!globalThis.__PHECDA__)
370
- globalThis.__PHECDA__ = {};
371
370
  const tag = target.prototype.__TAG__;
372
- if (tag)
373
- globalThis.__PHECDA__[tag] = target;
371
+ if (tag) {
372
+ init(target.prototype);
373
+ setModelVar(target.prototype, "__CLASS");
374
+ regisHandler(target.prototype, "__CLASS", {
375
+ init: async () => {
376
+ if (!globalThis.__PHECDA__)
377
+ globalThis.__PHECDA__ = {};
378
+ globalThis.__PHECDA__[tag] = target;
379
+ }
380
+ });
381
+ }
374
382
  }
375
383
  __name(Global, "Global");
376
384
  function Empty(_target) {
@@ -428,7 +436,10 @@ async function plainToClass(Model, input, options = {}) {
428
436
  if (options.collectError !== false) {
429
437
  for (const handler of handlers) {
430
438
  const rule = handler.rule;
431
- if (rule && !await validate(rule, data[item])) {
439
+ const ret = await validate(rule, data[item]);
440
+ if (ret === "ok")
441
+ break;
442
+ if (rule && !ret) {
432
443
  err.push(typeof handler.info === "function" ? handler.info(item) : handler.info);
433
444
  if (!options.collectError)
434
445
  break;
@@ -583,6 +594,10 @@ function Storage(storeKey) {
583
594
  __name(Storage, "Storage");
584
595
 
585
596
  // src/preset/rule.ts
597
+ function isOption() {
598
+ return Rule((param) => param === void 0 ? "ok" : true, "");
599
+ }
600
+ __name(isOption, "isOption");
586
601
  function isArray(info) {
587
602
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
588
603
  }
@@ -709,6 +724,7 @@ __name(toString, "toString");
709
724
  isMobile,
710
725
  isNumber,
711
726
  isObject,
727
+ isOption,
712
728
  isPhecda,
713
729
  isPostalCode,
714
730
  isString,
package/dist/index.mjs CHANGED
@@ -276,11 +276,18 @@ function Assign(cb) {
276
276
  }
277
277
  __name(Assign, "Assign");
278
278
  function Global(target) {
279
- if (!globalThis.__PHECDA__)
280
- globalThis.__PHECDA__ = {};
281
279
  const tag = target.prototype.__TAG__;
282
- if (tag)
283
- globalThis.__PHECDA__[tag] = target;
280
+ if (tag) {
281
+ init(target.prototype);
282
+ setModelVar(target.prototype, "__CLASS");
283
+ regisHandler(target.prototype, "__CLASS", {
284
+ init: async () => {
285
+ if (!globalThis.__PHECDA__)
286
+ globalThis.__PHECDA__ = {};
287
+ globalThis.__PHECDA__[tag] = target;
288
+ }
289
+ });
290
+ }
284
291
  }
285
292
  __name(Global, "Global");
286
293
  function Empty(_target) {
@@ -338,7 +345,10 @@ async function plainToClass(Model, input, options = {}) {
338
345
  if (options.collectError !== false) {
339
346
  for (const handler of handlers) {
340
347
  const rule = handler.rule;
341
- if (rule && !await validate(rule, data[item])) {
348
+ const ret = await validate(rule, data[item]);
349
+ if (ret === "ok")
350
+ break;
351
+ if (rule && !ret) {
342
352
  err.push(typeof handler.info === "function" ? handler.info(item) : handler.info);
343
353
  if (!options.collectError)
344
354
  break;
@@ -493,6 +503,10 @@ function Storage(storeKey) {
493
503
  __name(Storage, "Storage");
494
504
 
495
505
  // src/preset/rule.ts
506
+ function isOption() {
507
+ return Rule((param) => param === void 0 ? "ok" : true, "");
508
+ }
509
+ __name(isOption, "isOption");
496
510
  function isArray(info) {
497
511
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
498
512
  }
@@ -618,6 +632,7 @@ export {
618
632
  isMobile,
619
633
  isNumber,
620
634
  isObject,
635
+ isOption,
621
636
  isPhecda,
622
637
  isPostalCode,
623
638
  isString,
@@ -1,3 +1,4 @@
1
+ declare function isOption(): (obj: any, key: PropertyKey) => void;
1
2
  declare function isArray(info?: string): (obj: any, key: PropertyKey) => void;
2
3
  declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
3
4
  declare function isNumber(info?: string): (obj: any, key: PropertyKey) => void;
@@ -17,4 +18,4 @@ declare function isPostalCode(info?: string): (obj: any, key: PropertyKey) => vo
17
18
  declare function toNumber(): (obj: any, key: PropertyKey) => void;
18
19
  declare function toString(): (obj: any, key: PropertyKey) => void;
19
20
 
20
- export { isBoolean as a, isNumber as b, isString as c, isObject as d, isMobile as e, isLandline as f, isMailBox as g, isIdCard as h, isArray as i, isCnName as j, isEnName as k, isDate as l, isWechat as m, isHexColor as n, isPostalCode as o, toString as p, toNumber as t };
21
+ export { isArray as a, isBoolean as b, isNumber as c, isString as d, isObject as e, isMobile as f, isLandline as g, isMailBox as h, isOption as i, isIdCard as j, isCnName as k, isEnName as l, isDate as m, isWechat as n, isHexColor as o, isPostalCode as p, toString as q, toNumber as t };
@@ -1 +1 @@
1
- export { i as isArray, a as isBoolean, j as isCnName, l as isDate, k as isEnName, n as isHexColor, h as isIdCard, f as isLandline, g as isMailBox, e as isMobile, b as isNumber, d as isObject, o as isPostalCode, c as isString, m as isWechat, t as toNumber, p as toString } from '../pipe-6da589ab.js';
1
+ export { a as isArray, b as isBoolean, k as isCnName, m as isDate, l as isEnName, o as isHexColor, j as isIdCard, g as isLandline, h as isMailBox, f as isMobile, c as isNumber, e as isObject, i as isOption, p as isPostalCode, d as isString, n as isWechat, t as toNumber, q as toString } from '../pipe-5d060247.js';
@@ -34,6 +34,7 @@ var Phecda = (() => {
34
34
  isMobile: () => isMobile,
35
35
  isNumber: () => isNumber,
36
36
  isObject: () => isObject,
37
+ isOption: () => isOption,
37
38
  isPostalCode: () => isPostalCode,
38
39
  isString: () => isString,
39
40
  isWechat: () => isWechat,
@@ -106,6 +107,10 @@ var Phecda = (() => {
106
107
  __name(Pipe, "Pipe");
107
108
 
108
109
  // src/preset/rule.ts
110
+ function isOption() {
111
+ return Rule((param) => param === void 0 ? "ok" : true, "");
112
+ }
113
+ __name(isOption, "isOption");
109
114
  function isArray(info) {
110
115
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
111
116
  }
@@ -33,6 +33,7 @@ __export(preset_exports, {
33
33
  isMobile: () => isMobile,
34
34
  isNumber: () => isNumber,
35
35
  isObject: () => isObject,
36
+ isOption: () => isOption,
36
37
  isPostalCode: () => isPostalCode,
37
38
  isString: () => isString,
38
39
  isWechat: () => isWechat,
@@ -106,6 +107,10 @@ function Pipe(v) {
106
107
  __name(Pipe, "Pipe");
107
108
 
108
109
  // src/preset/rule.ts
110
+ function isOption() {
111
+ return Rule((param) => param === void 0 ? "ok" : true, "");
112
+ }
113
+ __name(isOption, "isOption");
109
114
  function isArray(info) {
110
115
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
111
116
  }
@@ -206,6 +211,7 @@ __name(toString, "toString");
206
211
  isMobile,
207
212
  isNumber,
208
213
  isObject,
214
+ isOption,
209
215
  isPostalCode,
210
216
  isString,
211
217
  isWechat,
@@ -66,6 +66,10 @@ function Pipe(v) {
66
66
  __name(Pipe, "Pipe");
67
67
 
68
68
  // src/preset/rule.ts
69
+ function isOption() {
70
+ return Rule((param) => param === void 0 ? "ok" : true, "");
71
+ }
72
+ __name(isOption, "isOption");
69
73
  function isArray(info) {
70
74
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
71
75
  }
@@ -165,6 +169,7 @@ export {
165
169
  isMobile,
166
170
  isNumber,
167
171
  isObject,
172
+ isOption,
168
173
  isPostalCode,
169
174
  isString,
170
175
  isWechat,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.4",
4
4
  "description": "provide base function and abstract limit to other phecda module ",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",