phecda-core 4.2.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/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +33 -0
- package/dist/index.mjs +32 -0
- package/package.json +1 -1
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
|
|
|
@@ -121,4 +122,4 @@ declare abstract class Base {
|
|
|
121
122
|
private _unmount;
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
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
|
|
|
@@ -121,4 +122,4 @@ declare abstract class Base {
|
|
|
121
122
|
private _unmount;
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
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,6 +116,8 @@ 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)
|
|
@@ -351,6 +354,35 @@ function omit(classFn, ...properties) {
|
|
|
351
354
|
});
|
|
352
355
|
return newClass;
|
|
353
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
|
+
}
|
|
354
386
|
function partial(classFn, ...properties) {
|
|
355
387
|
const newClass = class extends classFn {
|
|
356
388
|
};
|
|
@@ -604,6 +636,7 @@ Base = __decorateClass([
|
|
|
604
636
|
omit,
|
|
605
637
|
override,
|
|
606
638
|
partial,
|
|
639
|
+
pick,
|
|
607
640
|
set,
|
|
608
641
|
setInject,
|
|
609
642
|
setMeta,
|
package/dist/index.mjs
CHANGED
|
@@ -38,6 +38,8 @@ 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)
|
|
@@ -274,6 +276,35 @@ function omit(classFn, ...properties) {
|
|
|
274
276
|
});
|
|
275
277
|
return newClass;
|
|
276
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
|
+
}
|
|
277
308
|
function partial(classFn, ...properties) {
|
|
278
309
|
const newClass = class extends classFn {
|
|
279
310
|
};
|
|
@@ -526,6 +557,7 @@ export {
|
|
|
526
557
|
omit,
|
|
527
558
|
override,
|
|
528
559
|
partial,
|
|
560
|
+
pick,
|
|
529
561
|
set,
|
|
530
562
|
setInject,
|
|
531
563
|
setMeta,
|