phecda-core 4.1.0 → 4.3.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 +3 -3
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +40 -1
- package/dist/index.mjs +39 -1
- package/package.json +1 -1
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
|
@@ -96,6 +96,7 @@ declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
|
|
|
96
96
|
declare function objectToClass<Obj extends Record<string, any>>(obj: Obj): new () => Obj;
|
|
97
97
|
declare function functionToClass<Func extends (...args: any) => object>(fn: Func): new (...args: Parameters<Func>) => ReturnType<Func>;
|
|
98
98
|
declare function omit<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
|
|
99
|
+
declare function pick<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Pick<InstanceType<Class>, Key>>;
|
|
99
100
|
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
101
|
declare function override<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
|
|
101
102
|
|
|
@@ -112,6 +113,7 @@ declare abstract class Base {
|
|
|
112
113
|
abstract emitter: any;
|
|
113
114
|
constructor();
|
|
114
115
|
get tag(): PropertyKey;
|
|
116
|
+
init(): void;
|
|
115
117
|
then(cb: () => void, reject?: (e: any) => void): Promise<void>;
|
|
116
118
|
on<Key extends keyof Events>(type: Key, handler: (arg: Events[Key]) => void): void;
|
|
117
119
|
emit<Key extends keyof Events>(type: Key, param: Events[Key]): void;
|
|
@@ -120,4 +122,4 @@ declare abstract class Base {
|
|
|
120
122
|
private _unmount;
|
|
121
123
|
}
|
|
122
124
|
|
|
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 };
|
|
125
|
+
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, pick, set, setInject, setMeta, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -96,6 +96,7 @@ declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
|
|
|
96
96
|
declare function objectToClass<Obj extends Record<string, any>>(obj: Obj): new () => Obj;
|
|
97
97
|
declare function functionToClass<Func extends (...args: any) => object>(fn: Func): new (...args: Parameters<Func>) => ReturnType<Func>;
|
|
98
98
|
declare function omit<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
|
|
99
|
+
declare function pick<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Pick<InstanceType<Class>, Key>>;
|
|
99
100
|
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
101
|
declare function override<Class extends Construct, Key extends keyof InstanceType<Class>>(classFn: Class, ...properties: Key[]): Construct<Omit<InstanceType<Class>, Key>>;
|
|
101
102
|
|
|
@@ -112,6 +113,7 @@ declare abstract class Base {
|
|
|
112
113
|
abstract emitter: any;
|
|
113
114
|
constructor();
|
|
114
115
|
get tag(): PropertyKey;
|
|
116
|
+
init(): void;
|
|
115
117
|
then(cb: () => void, reject?: (e: any) => void): Promise<void>;
|
|
116
118
|
on<Key extends keyof Events>(type: Key, handler: (arg: Events[Key]) => void): void;
|
|
117
119
|
emit<Key extends keyof Events>(type: Key, param: Events[Key]): void;
|
|
@@ -120,4 +122,4 @@ declare abstract class Base {
|
|
|
120
122
|
private _unmount;
|
|
121
123
|
}
|
|
122
124
|
|
|
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 };
|
|
125
|
+
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, pick, set, setInject, setMeta, wait };
|
package/dist/index.js
CHANGED
|
@@ -79,6 +79,7 @@ __export(index_exports, {
|
|
|
79
79
|
omit: () => omit,
|
|
80
80
|
override: () => override,
|
|
81
81
|
partial: () => partial,
|
|
82
|
+
pick: () => pick,
|
|
82
83
|
set: () => set,
|
|
83
84
|
setInject: () => setInject,
|
|
84
85
|
setMeta: () => setMeta,
|
|
@@ -115,9 +116,12 @@ function getPhecdaFromTarget(target) {
|
|
|
115
116
|
return Object.getPrototypeOf(target);
|
|
116
117
|
}
|
|
117
118
|
function setMeta(proto, property, index, meta) {
|
|
119
|
+
if (typeof proto === "function" && proto.prototype)
|
|
120
|
+
proto = proto.prototype;
|
|
118
121
|
if (!property) {
|
|
119
122
|
property = SHARE_KEY;
|
|
120
|
-
|
|
123
|
+
if (proto.prototype)
|
|
124
|
+
proto = proto.prototype;
|
|
121
125
|
}
|
|
122
126
|
init(proto);
|
|
123
127
|
if (!proto[PHECDA_KEY].__META__.has(property))
|
|
@@ -350,6 +354,35 @@ function omit(classFn, ...properties) {
|
|
|
350
354
|
});
|
|
351
355
|
return newClass;
|
|
352
356
|
}
|
|
357
|
+
function pick(classFn, ...properties) {
|
|
358
|
+
const newClass = class {
|
|
359
|
+
constructor(...args) {
|
|
360
|
+
const instance = new classFn(...args);
|
|
361
|
+
properties.forEach((prop) => {
|
|
362
|
+
Object.defineProperty(this, prop, {
|
|
363
|
+
get() {
|
|
364
|
+
const data = instance[prop];
|
|
365
|
+
if (typeof data === "function")
|
|
366
|
+
return data.bind(this);
|
|
367
|
+
return data;
|
|
368
|
+
},
|
|
369
|
+
set(val) {
|
|
370
|
+
instance[prop] = val;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
getMetaKey(classFn).forEach((k) => {
|
|
377
|
+
if (properties.includes(k)) {
|
|
378
|
+
setMeta(newClass, k, void 0, getMergedMeta(classFn, k));
|
|
379
|
+
getMetaParams(classFn, k).forEach((index) => {
|
|
380
|
+
setMeta(newClass, k, index, getMergedMeta(classFn, k, index));
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
return newClass;
|
|
385
|
+
}
|
|
353
386
|
function partial(classFn, ...properties) {
|
|
354
387
|
const newClass = class extends classFn {
|
|
355
388
|
};
|
|
@@ -518,6 +551,8 @@ var Base = class {
|
|
|
518
551
|
get tag() {
|
|
519
552
|
return getTag(this);
|
|
520
553
|
}
|
|
554
|
+
init() {
|
|
555
|
+
}
|
|
521
556
|
then(cb, reject) {
|
|
522
557
|
return this.__PROMISE_SYMBOL__.then(cb, reject);
|
|
523
558
|
}
|
|
@@ -539,6 +574,9 @@ var Base = class {
|
|
|
539
574
|
return Promise.all(this.__UNMOUNT_SYMBOL__.map((fn) => fn()));
|
|
540
575
|
}
|
|
541
576
|
};
|
|
577
|
+
__decorateClass([
|
|
578
|
+
Init
|
|
579
|
+
], Base.prototype, "init", 1);
|
|
542
580
|
__decorateClass([
|
|
543
581
|
Unmount
|
|
544
582
|
], Base.prototype, "_unmount", 1);
|
|
@@ -598,6 +636,7 @@ Base = __decorateClass([
|
|
|
598
636
|
omit,
|
|
599
637
|
override,
|
|
600
638
|
partial,
|
|
639
|
+
pick,
|
|
601
640
|
set,
|
|
602
641
|
setInject,
|
|
603
642
|
setMeta,
|
package/dist/index.mjs
CHANGED
|
@@ -38,9 +38,12 @@ function getPhecdaFromTarget(target) {
|
|
|
38
38
|
return Object.getPrototypeOf(target);
|
|
39
39
|
}
|
|
40
40
|
function setMeta(proto, property, index, meta) {
|
|
41
|
+
if (typeof proto === "function" && proto.prototype)
|
|
42
|
+
proto = proto.prototype;
|
|
41
43
|
if (!property) {
|
|
42
44
|
property = SHARE_KEY;
|
|
43
|
-
|
|
45
|
+
if (proto.prototype)
|
|
46
|
+
proto = proto.prototype;
|
|
44
47
|
}
|
|
45
48
|
init(proto);
|
|
46
49
|
if (!proto[PHECDA_KEY].__META__.has(property))
|
|
@@ -273,6 +276,35 @@ function omit(classFn, ...properties) {
|
|
|
273
276
|
});
|
|
274
277
|
return newClass;
|
|
275
278
|
}
|
|
279
|
+
function pick(classFn, ...properties) {
|
|
280
|
+
const newClass = class {
|
|
281
|
+
constructor(...args) {
|
|
282
|
+
const instance = new classFn(...args);
|
|
283
|
+
properties.forEach((prop) => {
|
|
284
|
+
Object.defineProperty(this, prop, {
|
|
285
|
+
get() {
|
|
286
|
+
const data = instance[prop];
|
|
287
|
+
if (typeof data === "function")
|
|
288
|
+
return data.bind(this);
|
|
289
|
+
return data;
|
|
290
|
+
},
|
|
291
|
+
set(val) {
|
|
292
|
+
instance[prop] = val;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
getMetaKey(classFn).forEach((k) => {
|
|
299
|
+
if (properties.includes(k)) {
|
|
300
|
+
setMeta(newClass, k, void 0, getMergedMeta(classFn, k));
|
|
301
|
+
getMetaParams(classFn, k).forEach((index) => {
|
|
302
|
+
setMeta(newClass, k, index, getMergedMeta(classFn, k, index));
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
return newClass;
|
|
307
|
+
}
|
|
276
308
|
function partial(classFn, ...properties) {
|
|
277
309
|
const newClass = class extends classFn {
|
|
278
310
|
};
|
|
@@ -441,6 +473,8 @@ var Base = class {
|
|
|
441
473
|
get tag() {
|
|
442
474
|
return getTag(this);
|
|
443
475
|
}
|
|
476
|
+
init() {
|
|
477
|
+
}
|
|
444
478
|
then(cb, reject) {
|
|
445
479
|
return this.__PROMISE_SYMBOL__.then(cb, reject);
|
|
446
480
|
}
|
|
@@ -462,6 +496,9 @@ var Base = class {
|
|
|
462
496
|
return Promise.all(this.__UNMOUNT_SYMBOL__.map((fn) => fn()));
|
|
463
497
|
}
|
|
464
498
|
};
|
|
499
|
+
__decorateClass([
|
|
500
|
+
Init
|
|
501
|
+
], Base.prototype, "init", 1);
|
|
465
502
|
__decorateClass([
|
|
466
503
|
Unmount
|
|
467
504
|
], Base.prototype, "_unmount", 1);
|
|
@@ -520,6 +557,7 @@ export {
|
|
|
520
557
|
omit,
|
|
521
558
|
override,
|
|
522
559
|
partial,
|
|
560
|
+
pick,
|
|
523
561
|
set,
|
|
524
562
|
setInject,
|
|
525
563
|
setMeta,
|