phecda-core 1.4.1 → 1.6.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 +10 -1
- package/dist/index.global.js +39 -0
- package/dist/index.js +45 -0
- package/dist/index.mjs +39 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ interface UsePipeOptions {
|
|
|
5
5
|
transform?: boolean;
|
|
6
6
|
collectError?: boolean;
|
|
7
7
|
}
|
|
8
|
+
interface PhecdaInjectData {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
8
11
|
interface PhecdaHandler {
|
|
9
12
|
[key: string]: any;
|
|
10
13
|
}
|
|
@@ -24,6 +27,7 @@ type ClassValue<I> = {
|
|
|
24
27
|
interface Events {
|
|
25
28
|
}
|
|
26
29
|
|
|
30
|
+
declare function getBind<M extends new (...args: any) => any>(Model: M): any;
|
|
27
31
|
declare function plainToClass<M extends new (...args: any) => any, Data extends Record<PropertyKey, any>>(Model: M, input: Data, options?: UsePipeOptions): Promise<{
|
|
28
32
|
err: string[];
|
|
29
33
|
data: InstanceType<M>;
|
|
@@ -71,6 +75,7 @@ declare function snapShot<T extends new (...args: any) => any>(data: InstanceTyp
|
|
|
71
75
|
declare function addDecoToClass<M extends new (...args: any) => any>(c: M, key: keyof InstanceType<M> | string, handler: ((target: any, key: PropertyKey) => void), type?: 'static' | 'class' | 'normal'): void;
|
|
72
76
|
|
|
73
77
|
declare function Init(target: any, key: PropertyKey): void;
|
|
78
|
+
declare function Bind(value: any): (target: any, k: PropertyKey) => void;
|
|
74
79
|
declare function Rule(rule: RegExp | string | Function | number, info: string, meta?: any): (obj: any, key: PropertyKey) => void;
|
|
75
80
|
declare function Ignore(target: any, key: PropertyKey): void;
|
|
76
81
|
declare function Clear(target: any, key: PropertyKey): void;
|
|
@@ -80,6 +85,10 @@ declare function Pipe(v: ReturnType<typeof to>): (obj: any, key: PropertyKey) =>
|
|
|
80
85
|
declare function Tag(tag: string): (target: any) => void;
|
|
81
86
|
declare function Assign(cb: (instance?: any) => any): (target: any) => void;
|
|
82
87
|
declare function Global(target: any): void;
|
|
88
|
+
declare function Empty(_target: any): void;
|
|
89
|
+
declare const DataMap: PhecdaInjectData;
|
|
90
|
+
declare function Provide<K extends keyof PhecdaInjectData>(key: K, value: PhecdaInjectData[K]): void;
|
|
91
|
+
declare function Inject<K extends keyof PhecdaInjectData>(key: K): PhecdaInjectData[K];
|
|
83
92
|
|
|
84
93
|
declare function validate(p: RegExp | string | Function | Object | Number, v: any): Promise<any>;
|
|
85
94
|
declare function getTag<M extends new (...args: any) => any>(Model: M): any;
|
|
@@ -111,4 +120,4 @@ declare function Watcher(eventName: keyof Events, options?: {
|
|
|
111
120
|
}): (obj: any, key: string) => void;
|
|
112
121
|
declare function Storage(storeKey?: string): (target: any, key?: PropertyKey) => void;
|
|
113
122
|
|
|
114
|
-
export { Assign, ClassValue, Clear, Err, Events, Expose, Global, Ignore, Init, NameSpace, Phecda, PhecdaHandler, Pipe, Rule, Storage, Tag, UsePipeOptions, Watcher, activeInstance, addDecoToClass, classToValue, getExposeKey, getHandler, getIgnoreKey, getInitEvent, getModelState, getProperty, getState, getTag, init, injectProperty, isPhecda, mergeOptions, mergeState, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModalVar, snapShot, to, validate };
|
|
123
|
+
export { Assign, Bind, ClassValue, Clear, DataMap, 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, getIgnoreKey, getInitEvent, getModelState, getProperty, getState, getTag, init, injectProperty, isPhecda, mergeOptions, mergeState, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModalVar, snapShot, to, validate };
|
package/dist/index.global.js
CHANGED
|
@@ -23,13 +23,18 @@ var Phecda = (() => {
|
|
|
23
23
|
var src_exports = {};
|
|
24
24
|
__export(src_exports, {
|
|
25
25
|
Assign: () => Assign,
|
|
26
|
+
Bind: () => Bind,
|
|
26
27
|
Clear: () => Clear,
|
|
28
|
+
DataMap: () => DataMap,
|
|
29
|
+
Empty: () => Empty,
|
|
27
30
|
Err: () => Err,
|
|
28
31
|
Expose: () => Expose,
|
|
29
32
|
Global: () => Global,
|
|
30
33
|
Ignore: () => Ignore,
|
|
31
34
|
Init: () => Init,
|
|
35
|
+
Inject: () => Inject,
|
|
32
36
|
Pipe: () => Pipe,
|
|
37
|
+
Provide: () => Provide,
|
|
33
38
|
Rule: () => Rule,
|
|
34
39
|
Storage: () => Storage,
|
|
35
40
|
Tag: () => Tag,
|
|
@@ -37,6 +42,7 @@ var Phecda = (() => {
|
|
|
37
42
|
activeInstance: () => activeInstance,
|
|
38
43
|
addDecoToClass: () => addDecoToClass,
|
|
39
44
|
classToValue: () => classToValue,
|
|
45
|
+
getBind: () => getBind,
|
|
40
46
|
getExposeKey: () => getExposeKey,
|
|
41
47
|
getHandler: () => getHandler,
|
|
42
48
|
getIgnoreKey: () => getIgnoreKey,
|
|
@@ -226,6 +232,15 @@ var Phecda = (() => {
|
|
|
226
232
|
});
|
|
227
233
|
}
|
|
228
234
|
__name(Init, "Init");
|
|
235
|
+
function Bind(value) {
|
|
236
|
+
return (target, k) => {
|
|
237
|
+
setModalVar(target, k);
|
|
238
|
+
mergeState(target, k, {
|
|
239
|
+
value
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
__name(Bind, "Bind");
|
|
229
244
|
function Rule(rule, info, meta) {
|
|
230
245
|
return (obj, key) => {
|
|
231
246
|
setModalVar(obj, key);
|
|
@@ -307,8 +322,32 @@ var Phecda = (() => {
|
|
|
307
322
|
globalThis.__PHECDA__[tag] = target;
|
|
308
323
|
}
|
|
309
324
|
__name(Global, "Global");
|
|
325
|
+
function Empty(_target) {
|
|
326
|
+
}
|
|
327
|
+
__name(Empty, "Empty");
|
|
328
|
+
var DataMap = {};
|
|
329
|
+
function Provide(key, value) {
|
|
330
|
+
DataMap[key] = value;
|
|
331
|
+
}
|
|
332
|
+
__name(Provide, "Provide");
|
|
333
|
+
function Inject(key) {
|
|
334
|
+
return DataMap[key] || (() => Empty);
|
|
335
|
+
}
|
|
336
|
+
__name(Inject, "Inject");
|
|
310
337
|
|
|
311
338
|
// src/helper.ts
|
|
339
|
+
function getBind(Model) {
|
|
340
|
+
const instance = new Model();
|
|
341
|
+
const keys = getModelState(instance);
|
|
342
|
+
const ret = {};
|
|
343
|
+
for (const item of keys) {
|
|
344
|
+
const state = getState(instance, item);
|
|
345
|
+
if (state.value)
|
|
346
|
+
ret[item] = state.value;
|
|
347
|
+
}
|
|
348
|
+
return ret;
|
|
349
|
+
}
|
|
350
|
+
__name(getBind, "getBind");
|
|
312
351
|
async function plainToClass(Model, input, options = {}) {
|
|
313
352
|
const data = new Model();
|
|
314
353
|
const err = [];
|
package/dist/index.js
CHANGED
|
@@ -22,13 +22,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var src_exports = {};
|
|
23
23
|
__export(src_exports, {
|
|
24
24
|
Assign: () => Assign,
|
|
25
|
+
Bind: () => Bind,
|
|
25
26
|
Clear: () => Clear,
|
|
27
|
+
DataMap: () => DataMap,
|
|
28
|
+
Empty: () => Empty,
|
|
26
29
|
Err: () => Err,
|
|
27
30
|
Expose: () => Expose,
|
|
28
31
|
Global: () => Global,
|
|
29
32
|
Ignore: () => Ignore,
|
|
30
33
|
Init: () => Init,
|
|
34
|
+
Inject: () => Inject,
|
|
31
35
|
Pipe: () => Pipe,
|
|
36
|
+
Provide: () => Provide,
|
|
32
37
|
Rule: () => Rule,
|
|
33
38
|
Storage: () => Storage,
|
|
34
39
|
Tag: () => Tag,
|
|
@@ -36,6 +41,7 @@ __export(src_exports, {
|
|
|
36
41
|
activeInstance: () => activeInstance,
|
|
37
42
|
addDecoToClass: () => addDecoToClass,
|
|
38
43
|
classToValue: () => classToValue,
|
|
44
|
+
getBind: () => getBind,
|
|
39
45
|
getExposeKey: () => getExposeKey,
|
|
40
46
|
getHandler: () => getHandler,
|
|
41
47
|
getIgnoreKey: () => getIgnoreKey,
|
|
@@ -226,6 +232,15 @@ function Init(target, key) {
|
|
|
226
232
|
});
|
|
227
233
|
}
|
|
228
234
|
__name(Init, "Init");
|
|
235
|
+
function Bind(value) {
|
|
236
|
+
return (target, k) => {
|
|
237
|
+
setModalVar(target, k);
|
|
238
|
+
mergeState(target, k, {
|
|
239
|
+
value
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
__name(Bind, "Bind");
|
|
229
244
|
function Rule(rule, info, meta) {
|
|
230
245
|
return (obj, key) => {
|
|
231
246
|
setModalVar(obj, key);
|
|
@@ -307,8 +322,32 @@ function Global(target) {
|
|
|
307
322
|
globalThis.__PHECDA__[tag] = target;
|
|
308
323
|
}
|
|
309
324
|
__name(Global, "Global");
|
|
325
|
+
function Empty(_target) {
|
|
326
|
+
}
|
|
327
|
+
__name(Empty, "Empty");
|
|
328
|
+
var DataMap = {};
|
|
329
|
+
function Provide(key, value) {
|
|
330
|
+
DataMap[key] = value;
|
|
331
|
+
}
|
|
332
|
+
__name(Provide, "Provide");
|
|
333
|
+
function Inject(key) {
|
|
334
|
+
return DataMap[key] || (() => Empty);
|
|
335
|
+
}
|
|
336
|
+
__name(Inject, "Inject");
|
|
310
337
|
|
|
311
338
|
// src/helper.ts
|
|
339
|
+
function getBind(Model) {
|
|
340
|
+
const instance = new Model();
|
|
341
|
+
const keys = getModelState(instance);
|
|
342
|
+
const ret = {};
|
|
343
|
+
for (const item of keys) {
|
|
344
|
+
const state = getState(instance, item);
|
|
345
|
+
if (state.value)
|
|
346
|
+
ret[item] = state.value;
|
|
347
|
+
}
|
|
348
|
+
return ret;
|
|
349
|
+
}
|
|
350
|
+
__name(getBind, "getBind");
|
|
312
351
|
async function plainToClass(Model, input, options = {}) {
|
|
313
352
|
const data = new Model();
|
|
314
353
|
const err = [];
|
|
@@ -450,13 +489,18 @@ __name(Storage, "Storage");
|
|
|
450
489
|
// Annotate the CommonJS export names for ESM import in node:
|
|
451
490
|
0 && (module.exports = {
|
|
452
491
|
Assign,
|
|
492
|
+
Bind,
|
|
453
493
|
Clear,
|
|
494
|
+
DataMap,
|
|
495
|
+
Empty,
|
|
454
496
|
Err,
|
|
455
497
|
Expose,
|
|
456
498
|
Global,
|
|
457
499
|
Ignore,
|
|
458
500
|
Init,
|
|
501
|
+
Inject,
|
|
459
502
|
Pipe,
|
|
503
|
+
Provide,
|
|
460
504
|
Rule,
|
|
461
505
|
Storage,
|
|
462
506
|
Tag,
|
|
@@ -464,6 +508,7 @@ __name(Storage, "Storage");
|
|
|
464
508
|
activeInstance,
|
|
465
509
|
addDecoToClass,
|
|
466
510
|
classToValue,
|
|
511
|
+
getBind,
|
|
467
512
|
getExposeKey,
|
|
468
513
|
getHandler,
|
|
469
514
|
getIgnoreKey,
|
package/dist/index.mjs
CHANGED
|
@@ -164,6 +164,15 @@ function Init(target, key) {
|
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
__name(Init, "Init");
|
|
167
|
+
function Bind(value) {
|
|
168
|
+
return (target, k) => {
|
|
169
|
+
setModalVar(target, k);
|
|
170
|
+
mergeState(target, k, {
|
|
171
|
+
value
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
__name(Bind, "Bind");
|
|
167
176
|
function Rule(rule, info, meta) {
|
|
168
177
|
return (obj, key) => {
|
|
169
178
|
setModalVar(obj, key);
|
|
@@ -245,8 +254,32 @@ function Global(target) {
|
|
|
245
254
|
globalThis.__PHECDA__[tag] = target;
|
|
246
255
|
}
|
|
247
256
|
__name(Global, "Global");
|
|
257
|
+
function Empty(_target) {
|
|
258
|
+
}
|
|
259
|
+
__name(Empty, "Empty");
|
|
260
|
+
var DataMap = {};
|
|
261
|
+
function Provide(key, value) {
|
|
262
|
+
DataMap[key] = value;
|
|
263
|
+
}
|
|
264
|
+
__name(Provide, "Provide");
|
|
265
|
+
function Inject(key) {
|
|
266
|
+
return DataMap[key] || (() => Empty);
|
|
267
|
+
}
|
|
268
|
+
__name(Inject, "Inject");
|
|
248
269
|
|
|
249
270
|
// src/helper.ts
|
|
271
|
+
function getBind(Model) {
|
|
272
|
+
const instance = new Model();
|
|
273
|
+
const keys = getModelState(instance);
|
|
274
|
+
const ret = {};
|
|
275
|
+
for (const item of keys) {
|
|
276
|
+
const state = getState(instance, item);
|
|
277
|
+
if (state.value)
|
|
278
|
+
ret[item] = state.value;
|
|
279
|
+
}
|
|
280
|
+
return ret;
|
|
281
|
+
}
|
|
282
|
+
__name(getBind, "getBind");
|
|
250
283
|
async function plainToClass(Model, input, options = {}) {
|
|
251
284
|
const data = new Model();
|
|
252
285
|
const err = [];
|
|
@@ -387,13 +420,18 @@ function Storage(storeKey) {
|
|
|
387
420
|
__name(Storage, "Storage");
|
|
388
421
|
export {
|
|
389
422
|
Assign,
|
|
423
|
+
Bind,
|
|
390
424
|
Clear,
|
|
425
|
+
DataMap,
|
|
426
|
+
Empty,
|
|
391
427
|
Err,
|
|
392
428
|
Expose,
|
|
393
429
|
Global,
|
|
394
430
|
Ignore,
|
|
395
431
|
Init,
|
|
432
|
+
Inject,
|
|
396
433
|
Pipe,
|
|
434
|
+
Provide,
|
|
397
435
|
Rule,
|
|
398
436
|
Storage,
|
|
399
437
|
Tag,
|
|
@@ -401,6 +439,7 @@ export {
|
|
|
401
439
|
activeInstance,
|
|
402
440
|
addDecoToClass,
|
|
403
441
|
classToValue,
|
|
442
|
+
getBind,
|
|
404
443
|
getExposeKey,
|
|
405
444
|
getHandler,
|
|
406
445
|
getIgnoreKey,
|