phecda-core 1.0.7 → 1.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.ts +4 -3
- package/dist/index.js +27 -19
- package/dist/index.mjs +24 -17
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -74,11 +74,11 @@ declare function Rule(rule: RegExp | string | Function | number, info: string, m
|
|
|
74
74
|
declare function Ignore(target: any, key: PropertyKey): void;
|
|
75
75
|
declare function Clear(target: any, key: PropertyKey): void;
|
|
76
76
|
declare function Err<Fn extends (...args: any) => any>(cb: Fn): (target: any, key: PropertyKey) => void;
|
|
77
|
-
declare function
|
|
77
|
+
declare function P(target: any, key: PropertyKey): void;
|
|
78
78
|
declare function Pipe(v: ReturnType<typeof to>): (obj: any, key: PropertyKey) => void;
|
|
79
79
|
declare function Tag(tag: string): (target: any) => void;
|
|
80
80
|
declare function Storage(target: any): void;
|
|
81
|
-
declare function
|
|
81
|
+
declare function Global(target: any): void;
|
|
82
82
|
|
|
83
83
|
declare function validate(p: RegExp | string | Function | Object | Number, v: any): Promise<any>;
|
|
84
84
|
declare function getTag<M extends new (...args: any) => any>(Model: M): any;
|
|
@@ -99,6 +99,7 @@ declare function getHandler(target: Phecda, key: PropertyKey): PhecdaHandler[];
|
|
|
99
99
|
declare function mergeState(target: Phecda, key: PropertyKey, state: any): void;
|
|
100
100
|
declare function getState(target: Phecda, key: PropertyKey): Object | undefined;
|
|
101
101
|
declare function register(instance: Phecda): void;
|
|
102
|
+
declare function registerAsync(instance: Phecda): Promise<void>;
|
|
102
103
|
|
|
103
104
|
declare function isArray(info?: string): (obj: any, key: PropertyKey) => void;
|
|
104
105
|
declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
|
|
@@ -125,4 +126,4 @@ declare function getProperty(key: string): any;
|
|
|
125
126
|
|
|
126
127
|
declare function Watcher(eventName: string): (obj: any, key: string) => void;
|
|
127
128
|
|
|
128
|
-
export { ClassValue, Clear, Err,
|
|
129
|
+
export { ClassValue, Clear, Err, Global, Ignore, Init, P, Phecda, PhecdaHandler, PhecdaNameSpace, Pipe, Rule, Storage, Tag, UsePipeOptions, Watcher, activeInstance, addDecoToClass, classToValue, getExposeKey, getHandler, getIgnoreKey, getInitEvent, getModelState, getProperty, getState, getTag, init, injectProperty, isArray, isBoolean, isCnName, isDate, isEnName, isHexColor, isIdCard, isLandline, isMailBox, isMobile, isNumber, isObject, isPhecda, isPostalCode, isString, isWechat, mergeOptions, mergeState, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModalVar, snapShot, to, toNumber, toString, validate };
|
package/dist/index.js
CHANGED
|
@@ -23,15 +23,15 @@ var src_exports = {};
|
|
|
23
23
|
__export(src_exports, {
|
|
24
24
|
Clear: () => Clear,
|
|
25
25
|
Err: () => Err,
|
|
26
|
-
|
|
26
|
+
Global: () => Global,
|
|
27
27
|
Ignore: () => Ignore,
|
|
28
28
|
Init: () => Init,
|
|
29
|
+
P: () => P,
|
|
29
30
|
Pipe: () => Pipe,
|
|
30
31
|
Rule: () => Rule,
|
|
31
32
|
Storage: () => Storage,
|
|
32
33
|
Tag: () => Tag,
|
|
33
34
|
Watcher: () => Watcher,
|
|
34
|
-
Window: () => Window,
|
|
35
35
|
activeInstance: () => activeInstance,
|
|
36
36
|
addDecoToClass: () => addDecoToClass,
|
|
37
37
|
classToValue: () => classToValue,
|
|
@@ -67,6 +67,7 @@ __export(src_exports, {
|
|
|
67
67
|
regisHandler: () => regisHandler,
|
|
68
68
|
regisInitEvent: () => regisInitEvent,
|
|
69
69
|
register: () => register,
|
|
70
|
+
registerAsync: () => registerAsync,
|
|
70
71
|
setExposeKey: () => setExposeKey,
|
|
71
72
|
setIgnoreKey: () => setIgnoreKey,
|
|
72
73
|
setModalVar: () => setModalVar,
|
|
@@ -175,7 +176,7 @@ function getExposeKey(target) {
|
|
|
175
176
|
init(target);
|
|
176
177
|
return [
|
|
177
178
|
...target._namespace.__EXPOSE_VAR__
|
|
178
|
-
];
|
|
179
|
+
].filter((item) => !target._namespace.__IGNORE_VAR__.has(item));
|
|
179
180
|
}
|
|
180
181
|
__name(getExposeKey, "getExposeKey");
|
|
181
182
|
function getIgnoreKey(target) {
|
|
@@ -214,7 +215,7 @@ function getState(target, key) {
|
|
|
214
215
|
}
|
|
215
216
|
__name(getState, "getState");
|
|
216
217
|
function register(instance) {
|
|
217
|
-
const stateVars =
|
|
218
|
+
const stateVars = getExposeKey(instance);
|
|
218
219
|
for (const item of stateVars) {
|
|
219
220
|
const handlers = getHandler(instance, item);
|
|
220
221
|
for (const hanlder of handlers)
|
|
@@ -222,6 +223,15 @@ function register(instance) {
|
|
|
222
223
|
}
|
|
223
224
|
}
|
|
224
225
|
__name(register, "register");
|
|
226
|
+
async function registerAsync(instance) {
|
|
227
|
+
const stateVars = getExposeKey(instance);
|
|
228
|
+
for (const item of stateVars) {
|
|
229
|
+
const handlers = getHandler(instance, item);
|
|
230
|
+
for (const hanlder of handlers)
|
|
231
|
+
await hanlder.init?.(instance);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
__name(registerAsync, "registerAsync");
|
|
225
235
|
|
|
226
236
|
// src/decorators.ts
|
|
227
237
|
function Init(target, key) {
|
|
@@ -255,6 +265,7 @@ function Clear(target, key) {
|
|
|
255
265
|
target._namespace.__IGNORE_VAR__.delete(key);
|
|
256
266
|
target._namespace.__STATE_VAR__.delete(key);
|
|
257
267
|
target._namespace.__STATE_HANDLER__.delete(key);
|
|
268
|
+
target._namespace.__STATE_NAMESPACE__.delete(key);
|
|
258
269
|
}
|
|
259
270
|
__name(Clear, "Clear");
|
|
260
271
|
function Err(cb) {
|
|
@@ -266,10 +277,10 @@ function Err(cb) {
|
|
|
266
277
|
};
|
|
267
278
|
}
|
|
268
279
|
__name(Err, "Err");
|
|
269
|
-
function
|
|
280
|
+
function P(target, key) {
|
|
270
281
|
setExposeKey(target, key);
|
|
271
282
|
}
|
|
272
|
-
__name(
|
|
283
|
+
__name(P, "P");
|
|
273
284
|
function Pipe(v) {
|
|
274
285
|
return (obj, key) => {
|
|
275
286
|
setModalVar(obj, key);
|
|
@@ -300,7 +311,7 @@ function Storage(target) {
|
|
|
300
311
|
regisHandler(target.prototype, uniTag, {
|
|
301
312
|
init: (instance) => {
|
|
302
313
|
const { state } = instance;
|
|
303
|
-
|
|
314
|
+
globalThis.addEventListener("beforeunload", () => {
|
|
304
315
|
localStorage.setItem(`_phecda_${tag}`, JSON.stringify(state));
|
|
305
316
|
});
|
|
306
317
|
const lastObjStr = localStorage.getItem(`_phecda_${tag}`);
|
|
@@ -313,14 +324,14 @@ function Storage(target) {
|
|
|
313
324
|
});
|
|
314
325
|
}
|
|
315
326
|
__name(Storage, "Storage");
|
|
316
|
-
function
|
|
317
|
-
if (!
|
|
318
|
-
|
|
327
|
+
function Global(target) {
|
|
328
|
+
if (!globalThis.__PHECDA__)
|
|
329
|
+
globalThis.__PHECDA__ = {};
|
|
319
330
|
const tag = target.prototype._namespace.__TAG__;
|
|
320
331
|
if (tag)
|
|
321
|
-
|
|
332
|
+
globalThis.__PHECDA__[tag] = target;
|
|
322
333
|
}
|
|
323
|
-
__name(
|
|
334
|
+
__name(Global, "Global");
|
|
324
335
|
|
|
325
336
|
// src/helper.ts
|
|
326
337
|
async function plainToClass(Model, input, options = {}) {
|
|
@@ -361,12 +372,8 @@ __name(plainToClass, "plainToClass");
|
|
|
361
372
|
function classToValue(instance) {
|
|
362
373
|
const data = {};
|
|
363
374
|
const exposeVar = getExposeKey(instance);
|
|
364
|
-
const
|
|
365
|
-
for (const item of exposeVar) {
|
|
366
|
-
if (ignoreVars.includes(item))
|
|
367
|
-
continue;
|
|
375
|
+
for (const item of exposeVar)
|
|
368
376
|
data[item] = instance[item];
|
|
369
|
-
}
|
|
370
377
|
return data;
|
|
371
378
|
}
|
|
372
379
|
__name(classToValue, "classToValue");
|
|
@@ -510,15 +517,15 @@ __name(Watcher, "Watcher");
|
|
|
510
517
|
0 && (module.exports = {
|
|
511
518
|
Clear,
|
|
512
519
|
Err,
|
|
513
|
-
|
|
520
|
+
Global,
|
|
514
521
|
Ignore,
|
|
515
522
|
Init,
|
|
523
|
+
P,
|
|
516
524
|
Pipe,
|
|
517
525
|
Rule,
|
|
518
526
|
Storage,
|
|
519
527
|
Tag,
|
|
520
528
|
Watcher,
|
|
521
|
-
Window,
|
|
522
529
|
activeInstance,
|
|
523
530
|
addDecoToClass,
|
|
524
531
|
classToValue,
|
|
@@ -554,6 +561,7 @@ __name(Watcher, "Watcher");
|
|
|
554
561
|
regisHandler,
|
|
555
562
|
regisInitEvent,
|
|
556
563
|
register,
|
|
564
|
+
registerAsync,
|
|
557
565
|
setExposeKey,
|
|
558
566
|
setIgnoreKey,
|
|
559
567
|
setModalVar,
|
package/dist/index.mjs
CHANGED
|
@@ -98,7 +98,7 @@ function getExposeKey(target) {
|
|
|
98
98
|
init(target);
|
|
99
99
|
return [
|
|
100
100
|
...target._namespace.__EXPOSE_VAR__
|
|
101
|
-
];
|
|
101
|
+
].filter((item) => !target._namespace.__IGNORE_VAR__.has(item));
|
|
102
102
|
}
|
|
103
103
|
__name(getExposeKey, "getExposeKey");
|
|
104
104
|
function getIgnoreKey(target) {
|
|
@@ -137,7 +137,7 @@ function getState(target, key) {
|
|
|
137
137
|
}
|
|
138
138
|
__name(getState, "getState");
|
|
139
139
|
function register(instance) {
|
|
140
|
-
const stateVars =
|
|
140
|
+
const stateVars = getExposeKey(instance);
|
|
141
141
|
for (const item of stateVars) {
|
|
142
142
|
const handlers = getHandler(instance, item);
|
|
143
143
|
for (const hanlder of handlers)
|
|
@@ -145,6 +145,15 @@ function register(instance) {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
__name(register, "register");
|
|
148
|
+
async function registerAsync(instance) {
|
|
149
|
+
const stateVars = getExposeKey(instance);
|
|
150
|
+
for (const item of stateVars) {
|
|
151
|
+
const handlers = getHandler(instance, item);
|
|
152
|
+
for (const hanlder of handlers)
|
|
153
|
+
await hanlder.init?.(instance);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
__name(registerAsync, "registerAsync");
|
|
148
157
|
|
|
149
158
|
// src/decorators.ts
|
|
150
159
|
function Init(target, key) {
|
|
@@ -178,6 +187,7 @@ function Clear(target, key) {
|
|
|
178
187
|
target._namespace.__IGNORE_VAR__.delete(key);
|
|
179
188
|
target._namespace.__STATE_VAR__.delete(key);
|
|
180
189
|
target._namespace.__STATE_HANDLER__.delete(key);
|
|
190
|
+
target._namespace.__STATE_NAMESPACE__.delete(key);
|
|
181
191
|
}
|
|
182
192
|
__name(Clear, "Clear");
|
|
183
193
|
function Err(cb) {
|
|
@@ -189,10 +199,10 @@ function Err(cb) {
|
|
|
189
199
|
};
|
|
190
200
|
}
|
|
191
201
|
__name(Err, "Err");
|
|
192
|
-
function
|
|
202
|
+
function P(target, key) {
|
|
193
203
|
setExposeKey(target, key);
|
|
194
204
|
}
|
|
195
|
-
__name(
|
|
205
|
+
__name(P, "P");
|
|
196
206
|
function Pipe(v) {
|
|
197
207
|
return (obj, key) => {
|
|
198
208
|
setModalVar(obj, key);
|
|
@@ -223,7 +233,7 @@ function Storage(target) {
|
|
|
223
233
|
regisHandler(target.prototype, uniTag, {
|
|
224
234
|
init: (instance) => {
|
|
225
235
|
const { state } = instance;
|
|
226
|
-
|
|
236
|
+
globalThis.addEventListener("beforeunload", () => {
|
|
227
237
|
localStorage.setItem(`_phecda_${tag}`, JSON.stringify(state));
|
|
228
238
|
});
|
|
229
239
|
const lastObjStr = localStorage.getItem(`_phecda_${tag}`);
|
|
@@ -236,14 +246,14 @@ function Storage(target) {
|
|
|
236
246
|
});
|
|
237
247
|
}
|
|
238
248
|
__name(Storage, "Storage");
|
|
239
|
-
function
|
|
240
|
-
if (!
|
|
241
|
-
|
|
249
|
+
function Global(target) {
|
|
250
|
+
if (!globalThis.__PHECDA__)
|
|
251
|
+
globalThis.__PHECDA__ = {};
|
|
242
252
|
const tag = target.prototype._namespace.__TAG__;
|
|
243
253
|
if (tag)
|
|
244
|
-
|
|
254
|
+
globalThis.__PHECDA__[tag] = target;
|
|
245
255
|
}
|
|
246
|
-
__name(
|
|
256
|
+
__name(Global, "Global");
|
|
247
257
|
|
|
248
258
|
// src/helper.ts
|
|
249
259
|
async function plainToClass(Model, input, options = {}) {
|
|
@@ -284,12 +294,8 @@ __name(plainToClass, "plainToClass");
|
|
|
284
294
|
function classToValue(instance) {
|
|
285
295
|
const data = {};
|
|
286
296
|
const exposeVar = getExposeKey(instance);
|
|
287
|
-
const
|
|
288
|
-
for (const item of exposeVar) {
|
|
289
|
-
if (ignoreVars.includes(item))
|
|
290
|
-
continue;
|
|
297
|
+
for (const item of exposeVar)
|
|
291
298
|
data[item] = instance[item];
|
|
292
|
-
}
|
|
293
299
|
return data;
|
|
294
300
|
}
|
|
295
301
|
__name(classToValue, "classToValue");
|
|
@@ -432,15 +438,15 @@ __name(Watcher, "Watcher");
|
|
|
432
438
|
export {
|
|
433
439
|
Clear,
|
|
434
440
|
Err,
|
|
435
|
-
|
|
441
|
+
Global,
|
|
436
442
|
Ignore,
|
|
437
443
|
Init,
|
|
444
|
+
P,
|
|
438
445
|
Pipe,
|
|
439
446
|
Rule,
|
|
440
447
|
Storage,
|
|
441
448
|
Tag,
|
|
442
449
|
Watcher,
|
|
443
|
-
Window,
|
|
444
450
|
activeInstance,
|
|
445
451
|
addDecoToClass,
|
|
446
452
|
classToValue,
|
|
@@ -476,6 +482,7 @@ export {
|
|
|
476
482
|
regisHandler,
|
|
477
483
|
regisInitEvent,
|
|
478
484
|
register,
|
|
485
|
+
registerAsync,
|
|
479
486
|
setExposeKey,
|
|
480
487
|
setIgnoreKey,
|
|
481
488
|
setModalVar,
|