phecda-core 4.0.1 → 4.1.0-alpha.1

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 CHANGED
@@ -89,6 +89,8 @@ declare function invokeUnmount(instance: any): Promise<PromiseSettledResult<any>
89
89
  declare function If(value: Boolean, ...decorators: (ClassDecorator[]) | (PropertyDecorator[]) | (ParameterDecorator[])): (...args: any[]) => void;
90
90
  declare function getMergedMeta(target: any, property?: PropertyKey, index?: number, merger?: (prev: any, cur: any) => any): any;
91
91
  declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
92
+ declare function objectToClass<Obj extends Record<string, any>>(obj: Obj): new () => Obj;
93
+ declare function functionToClass<Func extends (...args: any) => object>(fn: Func): new (...args: Parameters<Func>) => ReturnType<Func>;
92
94
 
93
95
  declare const DataMap: InjectData;
94
96
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
@@ -111,4 +113,4 @@ declare abstract class Base {
111
113
  private _unmount;
112
114
  }
113
115
 
114
- 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, PHECDA_KEY, type Phecda, Pipeline, Provide, SHARE_KEY, Storage, type StorageParam, Tag, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, get, getInject, getMergedMeta, getMeta, getMetaKey, getMetaParams, getOwnMeta, getOwnMetaKey, getOwnMetaParams, getPhecdaFromTarget, getTag, init, invoke, invokeInit, invokeUnmount, isAsyncFunc, isPhecda, set, setInject, setMeta, wait };
116
+ 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, PHECDA_KEY, type Phecda, Pipeline, Provide, 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, set, setInject, setMeta, wait };
package/dist/index.d.ts CHANGED
@@ -89,6 +89,8 @@ declare function invokeUnmount(instance: any): Promise<PromiseSettledResult<any>
89
89
  declare function If(value: Boolean, ...decorators: (ClassDecorator[]) | (PropertyDecorator[]) | (ParameterDecorator[])): (...args: any[]) => void;
90
90
  declare function getMergedMeta(target: any, property?: PropertyKey, index?: number, merger?: (prev: any, cur: any) => any): any;
91
91
  declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
92
+ declare function objectToClass<Obj extends Record<string, any>>(obj: Obj): new () => Obj;
93
+ declare function functionToClass<Func extends (...args: any) => object>(fn: Func): new (...args: Parameters<Func>) => ReturnType<Func>;
92
94
 
93
95
  declare const DataMap: InjectData;
94
96
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
@@ -111,4 +113,4 @@ declare abstract class Base {
111
113
  private _unmount;
112
114
  }
113
115
 
114
- 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, PHECDA_KEY, type Phecda, Pipeline, Provide, SHARE_KEY, Storage, type StorageParam, Tag, Unique, Unmount, Watcher, type WatcherParam, activeInstance, addDecoToClass, get, getInject, getMergedMeta, getMeta, getMetaKey, getMetaParams, getOwnMeta, getOwnMetaKey, getOwnMetaParams, getPhecdaFromTarget, getTag, init, invoke, invokeInit, invokeUnmount, isAsyncFunc, isPhecda, set, setInject, setMeta, wait };
116
+ 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, PHECDA_KEY, type Phecda, Pipeline, Provide, 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, set, setInject, setMeta, wait };
package/dist/index.js CHANGED
@@ -26,8 +26,8 @@ var __decorateClass = (decorators, target, key, kind) => {
26
26
  };
27
27
 
28
28
  // src/index.ts
29
- var src_exports = {};
30
- __export(src_exports, {
29
+ var index_exports = {};
30
+ __export(index_exports, {
31
31
  Assign: () => Assign,
32
32
  Base: () => Base,
33
33
  CLEAR_KEY: () => CLEAR_KEY,
@@ -54,6 +54,7 @@ __export(src_exports, {
54
54
  Watcher: () => Watcher,
55
55
  activeInstance: () => activeInstance,
56
56
  addDecoToClass: () => addDecoToClass,
57
+ functionToClass: () => functionToClass,
57
58
  get: () => get,
58
59
  getInject: () => getInject,
59
60
  getMergedMeta: () => getMergedMeta,
@@ -71,12 +72,13 @@ __export(src_exports, {
71
72
  invokeUnmount: () => invokeUnmount,
72
73
  isAsyncFunc: () => isAsyncFunc,
73
74
  isPhecda: () => isPhecda,
75
+ objectToClass: () => objectToClass,
74
76
  set: () => set,
75
77
  setInject: () => setInject,
76
78
  setMeta: () => setMeta,
77
79
  wait: () => wait
78
80
  });
79
- module.exports = __toCommonJS(src_exports);
81
+ module.exports = __toCommonJS(index_exports);
80
82
 
81
83
  // src/core.ts
82
84
  var SHARE_KEY = Symbol("phecda[share]");
@@ -253,7 +255,12 @@ function invoke(instance, key, ...params) {
253
255
  const metaKeys = getMetaKey(instance);
254
256
  return Promise.allSettled(metaKeys.map((k) => {
255
257
  return getMeta(instance, k);
256
- }).flat().filter((item) => typeof item[key] === "function").map((item) => item[key](instance, ...params)));
258
+ }).flat().filter((item) => typeof item[key] === "function").map((item) => item[key](instance, ...params))).then((res) => {
259
+ res.filter((item) => item.status === "rejected").forEach((item) => {
260
+ console.error(item.reason);
261
+ });
262
+ return res;
263
+ });
257
264
  }
258
265
  function invokeInit(instance) {
259
266
  return instance.__PROMISE_SYMBOL__ = invoke(instance, "init");
@@ -308,6 +315,20 @@ function defaultMerger(prev, cur) {
308
315
  function wait(...instances) {
309
316
  return Promise.all(instances.map((i) => i.__PROMISE_SYMBOL__));
310
317
  }
318
+ function objectToClass(obj) {
319
+ return class {
320
+ constructor() {
321
+ Object.assign(this, obj);
322
+ }
323
+ };
324
+ }
325
+ function functionToClass(fn) {
326
+ return class {
327
+ constructor(...args) {
328
+ Object.setPrototypeOf(this, fn(...args));
329
+ }
330
+ };
331
+ }
311
332
 
312
333
  // src/di.ts
313
334
  var DataMap = {};
@@ -506,6 +527,7 @@ Base = __decorateClass([
506
527
  Watcher,
507
528
  activeInstance,
508
529
  addDecoToClass,
530
+ functionToClass,
509
531
  get,
510
532
  getInject,
511
533
  getMergedMeta,
@@ -523,6 +545,7 @@ Base = __decorateClass([
523
545
  invokeUnmount,
524
546
  isAsyncFunc,
525
547
  isPhecda,
548
+ objectToClass,
526
549
  set,
527
550
  setInject,
528
551
  setMeta,
package/dist/index.mjs CHANGED
@@ -184,7 +184,12 @@ function invoke(instance, key, ...params) {
184
184
  const metaKeys = getMetaKey(instance);
185
185
  return Promise.allSettled(metaKeys.map((k) => {
186
186
  return getMeta(instance, k);
187
- }).flat().filter((item) => typeof item[key] === "function").map((item) => item[key](instance, ...params)));
187
+ }).flat().filter((item) => typeof item[key] === "function").map((item) => item[key](instance, ...params))).then((res) => {
188
+ res.filter((item) => item.status === "rejected").forEach((item) => {
189
+ console.error(item.reason);
190
+ });
191
+ return res;
192
+ });
188
193
  }
189
194
  function invokeInit(instance) {
190
195
  return instance.__PROMISE_SYMBOL__ = invoke(instance, "init");
@@ -239,6 +244,20 @@ function defaultMerger(prev, cur) {
239
244
  function wait(...instances) {
240
245
  return Promise.all(instances.map((i) => i.__PROMISE_SYMBOL__));
241
246
  }
247
+ function objectToClass(obj) {
248
+ return class {
249
+ constructor() {
250
+ Object.assign(this, obj);
251
+ }
252
+ };
253
+ }
254
+ function functionToClass(fn) {
255
+ return class {
256
+ constructor(...args) {
257
+ Object.setPrototypeOf(this, fn(...args));
258
+ }
259
+ };
260
+ }
242
261
 
243
262
  // src/di.ts
244
263
  var DataMap = {};
@@ -436,6 +455,7 @@ export {
436
455
  Watcher,
437
456
  activeInstance,
438
457
  addDecoToClass,
458
+ functionToClass,
439
459
  get,
440
460
  getInject,
441
461
  getMergedMeta,
@@ -453,6 +473,7 @@ export {
453
473
  invokeUnmount,
454
474
  isAsyncFunc,
455
475
  isPhecda,
476
+ objectToClass,
456
477
  set,
457
478
  setInject,
458
479
  setMeta,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "4.0.1",
3
+ "version": "4.1.0-alpha.1",
4
4
  "description": "provide base function and abstract limit to other phecda module ",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",