phecda-core 3.0.0-beta.13 → 3.0.0-beta.14
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 -10
- package/dist/index.js +27 -27
- package/dist/index.mjs +27 -27
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
|
|
|
4
4
|
declare function Ignore(proto: any, key: PropertyKey): void;
|
|
5
5
|
declare function Clear(proto: any, key: PropertyKey): void;
|
|
6
6
|
declare function Expose(proto: any, key: PropertyKey): void;
|
|
7
|
-
declare function Empty(
|
|
7
|
+
declare function Empty(model: any): void;
|
|
8
8
|
|
|
9
9
|
declare const SHARE_KEY: unique symbol;
|
|
10
10
|
declare const PHECDA_KEY: unique symbol;
|
|
11
|
-
declare function isPhecda(
|
|
11
|
+
declare function isPhecda(model: any): model is Construct;
|
|
12
12
|
declare function init(proto: Phecda): void;
|
|
13
13
|
declare function setStateVar(proto: Phecda, key: PropertyKey): void;
|
|
14
14
|
declare function setExposeKey(proto: Phecda, key: PropertyKey): void;
|
|
@@ -24,7 +24,7 @@ declare function getOwnHandler(target: any, key: PropertyKey): Handler[];
|
|
|
24
24
|
declare function getHandler(target: any, key: PropertyKey): any[];
|
|
25
25
|
declare function getState(target: any, key: PropertyKey): any;
|
|
26
26
|
declare function getOwnState(target: any, key: PropertyKey): Record<string, any>;
|
|
27
|
-
declare function invokeHandler(event: string,
|
|
27
|
+
declare function invokeHandler(event: string, module: Phecda): Promise<any[]>;
|
|
28
28
|
declare function set(proto: Phecda, key: string, value: any): void;
|
|
29
29
|
declare function get(proto: Phecda, key: string): any;
|
|
30
30
|
|
|
@@ -56,11 +56,11 @@ type ClassValue<I> = {
|
|
|
56
56
|
interface Events {
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
declare function Isolate(
|
|
60
|
-
declare function Tag(tag: PropertyKey): (
|
|
61
|
-
declare function Unique(desc?: string): (
|
|
62
|
-
declare function Assign(cb: (instance?: any) => any): (
|
|
63
|
-
declare function Global(
|
|
59
|
+
declare function Isolate(model: any): void;
|
|
60
|
+
declare function Tag(tag: PropertyKey): (model: any) => void;
|
|
61
|
+
declare function Unique(desc?: string): (model: any) => void;
|
|
62
|
+
declare function Assign(cb: (instance?: any) => any): (model: any) => void;
|
|
63
|
+
declare function Global(model: any): void;
|
|
64
64
|
declare function To(...callbacks: ((arg: any, instance: any, key: string) => any)[]): (proto: any, key: PropertyKey) => void;
|
|
65
65
|
declare function Rule(cb: ((arg: any) => boolean | Promise<boolean>), info: string | (() => string)): (proto: any, key: PropertyKey) => void;
|
|
66
66
|
declare function Err(cb: (e: Error | any, instance: any, key: string) => void, isCatch?: boolean): (proto: any, key: PropertyKey) => void;
|
|
@@ -90,8 +90,8 @@ declare function Storage({ key: storeKey, toJSON, toString }?: {
|
|
|
90
90
|
}): (proto: any, key?: PropertyKey) => void;
|
|
91
91
|
|
|
92
92
|
declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
|
|
93
|
-
declare function getBind<M extends Construct | AbConstruct>(
|
|
94
|
-
declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(
|
|
93
|
+
declare function getBind<M extends Construct | AbConstruct>(model: M): any;
|
|
94
|
+
declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(model: M, input: Data): InstanceType<M>;
|
|
95
95
|
declare function transformInstance<M extends Construct>(instance: InstanceType<M>, force?: boolean): string[];
|
|
96
96
|
declare function transformInstanceAsync<M extends Construct>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
|
|
97
97
|
declare function transformProperty<M extends Construct>(instance: InstanceType<M>, property: keyof InstanceType<M>, force?: boolean): string[];
|
package/dist/index.js
CHANGED
|
@@ -84,9 +84,9 @@ module.exports = __toCommonJS(src_exports);
|
|
|
84
84
|
// src/core.ts
|
|
85
85
|
var SHARE_KEY = Symbol("phecda");
|
|
86
86
|
var PHECDA_KEY = Symbol("phecda");
|
|
87
|
-
function isPhecda(
|
|
88
|
-
if (typeof
|
|
89
|
-
return !!
|
|
87
|
+
function isPhecda(model) {
|
|
88
|
+
if (typeof model === "function")
|
|
89
|
+
return !!model.prototype[PHECDA_KEY];
|
|
90
90
|
return false;
|
|
91
91
|
}
|
|
92
92
|
__name(isPhecda, "isPhecda");
|
|
@@ -228,10 +228,10 @@ function getOwnState(target, key) {
|
|
|
228
228
|
return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
|
|
229
229
|
}
|
|
230
230
|
__name(getOwnState, "getOwnState");
|
|
231
|
-
function invokeHandler(event,
|
|
232
|
-
const stateVars = getExposeKey(
|
|
231
|
+
function invokeHandler(event, module2) {
|
|
232
|
+
const stateVars = getExposeKey(module2);
|
|
233
233
|
const initHandlers = stateVars.map((item) => {
|
|
234
|
-
return getHandler(
|
|
234
|
+
return getHandler(module2, item).filter((h) => !!h[event]).map((h) => h[event](module2));
|
|
235
235
|
}).flat();
|
|
236
236
|
return Promise.all(initHandlers);
|
|
237
237
|
}
|
|
@@ -291,8 +291,8 @@ function Expose(proto, key) {
|
|
|
291
291
|
setExposeKey(proto, key);
|
|
292
292
|
}
|
|
293
293
|
__name(Expose, "Expose");
|
|
294
|
-
function Empty(
|
|
295
|
-
init(
|
|
294
|
+
function Empty(model) {
|
|
295
|
+
init(model.prototype);
|
|
296
296
|
}
|
|
297
297
|
__name(Empty, "Empty");
|
|
298
298
|
|
|
@@ -303,8 +303,8 @@ function getTag(moduleOrInstance) {
|
|
|
303
303
|
return moduleOrInstance.prototype[PHECDA_KEY]?.__TAG__ || moduleOrInstance.name;
|
|
304
304
|
}
|
|
305
305
|
__name(getTag, "getTag");
|
|
306
|
-
function getBind(
|
|
307
|
-
const instance = new
|
|
306
|
+
function getBind(model) {
|
|
307
|
+
const instance = new model();
|
|
308
308
|
const keys = getStateVars(instance);
|
|
309
309
|
const ret = {};
|
|
310
310
|
for (const item of keys) {
|
|
@@ -315,8 +315,8 @@ function getBind(module2) {
|
|
|
315
315
|
return ret;
|
|
316
316
|
}
|
|
317
317
|
__name(getBind, "getBind");
|
|
318
|
-
function plainToClass(
|
|
319
|
-
const instance = new
|
|
318
|
+
function plainToClass(model, input) {
|
|
319
|
+
const instance = new model();
|
|
320
320
|
const keys = getExposeKey(instance);
|
|
321
321
|
for (const item of keys)
|
|
322
322
|
instance[item] = input[item];
|
|
@@ -460,28 +460,28 @@ function getKey(key) {
|
|
|
460
460
|
__name(getKey, "getKey");
|
|
461
461
|
|
|
462
462
|
// src/decorators/function.ts
|
|
463
|
-
function Isolate(
|
|
464
|
-
set(
|
|
465
|
-
|
|
463
|
+
function Isolate(model) {
|
|
464
|
+
set(model.prototype, "isolate", true);
|
|
465
|
+
model.prototype[PHECDA_KEY].__ISOLATE__ = true;
|
|
466
466
|
}
|
|
467
467
|
__name(Isolate, "Isolate");
|
|
468
468
|
function Tag(tag) {
|
|
469
|
-
return (
|
|
470
|
-
set(
|
|
469
|
+
return (model) => {
|
|
470
|
+
set(model.prototype, "tag", tag);
|
|
471
471
|
};
|
|
472
472
|
}
|
|
473
473
|
__name(Tag, "Tag");
|
|
474
474
|
function Unique(desc) {
|
|
475
|
-
return (
|
|
476
|
-
set(
|
|
475
|
+
return (model) => {
|
|
476
|
+
set(model.prototype, "tag", Symbol(desc || model.name));
|
|
477
477
|
};
|
|
478
478
|
}
|
|
479
479
|
__name(Unique, "Unique");
|
|
480
480
|
function Assign(cb) {
|
|
481
|
-
return (
|
|
482
|
-
init(
|
|
483
|
-
setStateVar(
|
|
484
|
-
setHandler(
|
|
481
|
+
return (model) => {
|
|
482
|
+
init(model.prototype);
|
|
483
|
+
setStateVar(model.prototype, SHARE_KEY);
|
|
484
|
+
setHandler(model.prototype, SHARE_KEY, {
|
|
485
485
|
init: async (instance) => {
|
|
486
486
|
const value = await cb(instance);
|
|
487
487
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -493,10 +493,10 @@ function Assign(cb) {
|
|
|
493
493
|
};
|
|
494
494
|
}
|
|
495
495
|
__name(Assign, "Assign");
|
|
496
|
-
function Global(
|
|
497
|
-
init(
|
|
498
|
-
setStateVar(
|
|
499
|
-
setHandler(
|
|
496
|
+
function Global(model) {
|
|
497
|
+
init(model.prototype);
|
|
498
|
+
setStateVar(model.prototype, SHARE_KEY);
|
|
499
|
+
setHandler(model.prototype, SHARE_KEY, {
|
|
500
500
|
init: async (instance) => {
|
|
501
501
|
const tag = instance[PHECDA_KEY].__TAG__;
|
|
502
502
|
if (!tag)
|
package/dist/index.mjs
CHANGED
|
@@ -4,9 +4,9 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/core.ts
|
|
5
5
|
var SHARE_KEY = Symbol("phecda");
|
|
6
6
|
var PHECDA_KEY = Symbol("phecda");
|
|
7
|
-
function isPhecda(
|
|
8
|
-
if (typeof
|
|
9
|
-
return !!
|
|
7
|
+
function isPhecda(model) {
|
|
8
|
+
if (typeof model === "function")
|
|
9
|
+
return !!model.prototype[PHECDA_KEY];
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
12
|
__name(isPhecda, "isPhecda");
|
|
@@ -148,10 +148,10 @@ function getOwnState(target, key) {
|
|
|
148
148
|
return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
|
|
149
149
|
}
|
|
150
150
|
__name(getOwnState, "getOwnState");
|
|
151
|
-
function invokeHandler(event,
|
|
152
|
-
const stateVars = getExposeKey(
|
|
151
|
+
function invokeHandler(event, module) {
|
|
152
|
+
const stateVars = getExposeKey(module);
|
|
153
153
|
const initHandlers = stateVars.map((item) => {
|
|
154
|
-
return getHandler(
|
|
154
|
+
return getHandler(module, item).filter((h) => !!h[event]).map((h) => h[event](module));
|
|
155
155
|
}).flat();
|
|
156
156
|
return Promise.all(initHandlers);
|
|
157
157
|
}
|
|
@@ -211,8 +211,8 @@ function Expose(proto, key) {
|
|
|
211
211
|
setExposeKey(proto, key);
|
|
212
212
|
}
|
|
213
213
|
__name(Expose, "Expose");
|
|
214
|
-
function Empty(
|
|
215
|
-
init(
|
|
214
|
+
function Empty(model) {
|
|
215
|
+
init(model.prototype);
|
|
216
216
|
}
|
|
217
217
|
__name(Empty, "Empty");
|
|
218
218
|
|
|
@@ -223,8 +223,8 @@ function getTag(moduleOrInstance) {
|
|
|
223
223
|
return moduleOrInstance.prototype[PHECDA_KEY]?.__TAG__ || moduleOrInstance.name;
|
|
224
224
|
}
|
|
225
225
|
__name(getTag, "getTag");
|
|
226
|
-
function getBind(
|
|
227
|
-
const instance = new
|
|
226
|
+
function getBind(model) {
|
|
227
|
+
const instance = new model();
|
|
228
228
|
const keys = getStateVars(instance);
|
|
229
229
|
const ret = {};
|
|
230
230
|
for (const item of keys) {
|
|
@@ -235,8 +235,8 @@ function getBind(module) {
|
|
|
235
235
|
return ret;
|
|
236
236
|
}
|
|
237
237
|
__name(getBind, "getBind");
|
|
238
|
-
function plainToClass(
|
|
239
|
-
const instance = new
|
|
238
|
+
function plainToClass(model, input) {
|
|
239
|
+
const instance = new model();
|
|
240
240
|
const keys = getExposeKey(instance);
|
|
241
241
|
for (const item of keys)
|
|
242
242
|
instance[item] = input[item];
|
|
@@ -380,28 +380,28 @@ function getKey(key) {
|
|
|
380
380
|
__name(getKey, "getKey");
|
|
381
381
|
|
|
382
382
|
// src/decorators/function.ts
|
|
383
|
-
function Isolate(
|
|
384
|
-
set(
|
|
385
|
-
|
|
383
|
+
function Isolate(model) {
|
|
384
|
+
set(model.prototype, "isolate", true);
|
|
385
|
+
model.prototype[PHECDA_KEY].__ISOLATE__ = true;
|
|
386
386
|
}
|
|
387
387
|
__name(Isolate, "Isolate");
|
|
388
388
|
function Tag(tag) {
|
|
389
|
-
return (
|
|
390
|
-
set(
|
|
389
|
+
return (model) => {
|
|
390
|
+
set(model.prototype, "tag", tag);
|
|
391
391
|
};
|
|
392
392
|
}
|
|
393
393
|
__name(Tag, "Tag");
|
|
394
394
|
function Unique(desc) {
|
|
395
|
-
return (
|
|
396
|
-
set(
|
|
395
|
+
return (model) => {
|
|
396
|
+
set(model.prototype, "tag", Symbol(desc || model.name));
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
399
|
__name(Unique, "Unique");
|
|
400
400
|
function Assign(cb) {
|
|
401
|
-
return (
|
|
402
|
-
init(
|
|
403
|
-
setStateVar(
|
|
404
|
-
setHandler(
|
|
401
|
+
return (model) => {
|
|
402
|
+
init(model.prototype);
|
|
403
|
+
setStateVar(model.prototype, SHARE_KEY);
|
|
404
|
+
setHandler(model.prototype, SHARE_KEY, {
|
|
405
405
|
init: async (instance) => {
|
|
406
406
|
const value = await cb(instance);
|
|
407
407
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -413,10 +413,10 @@ function Assign(cb) {
|
|
|
413
413
|
};
|
|
414
414
|
}
|
|
415
415
|
__name(Assign, "Assign");
|
|
416
|
-
function Global(
|
|
417
|
-
init(
|
|
418
|
-
setStateVar(
|
|
419
|
-
setHandler(
|
|
416
|
+
function Global(model) {
|
|
417
|
+
init(model.prototype);
|
|
418
|
+
setStateVar(model.prototype, SHARE_KEY);
|
|
419
|
+
setHandler(model.prototype, SHARE_KEY, {
|
|
420
420
|
init: async (instance) => {
|
|
421
421
|
const tag = instance[PHECDA_KEY].__TAG__;
|
|
422
422
|
if (!tag)
|