@eggjs/tegg-lifecycle 4.0.0-beta.7 → 4.0.0-beta.8
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 +46 -3
- package/dist/index.js +124 -3
- package/package.json +3 -3
- package/dist/IdenticalObject.d.ts +0 -15
- package/dist/IdenticalObject.js +0 -26
- package/dist/LifycycleUtil.d.ts +0 -26
- package/dist/LifycycleUtil.js +0 -75
- package/dist/decorator/index.d.ts +0 -12
- package/dist/decorator/index.js +0 -29
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { LifecycleDestroy, LifecycleInit, LifecyclePostConstruct, LifecyclePostInject, LifecyclePreDestroy, LifecyclePreInject, LifecyclePreLoad } from "./decorator/index.js";
|
|
1
|
+
import * as _eggjs_tegg_types0 from "@eggjs/tegg-types";
|
|
2
|
+
import { EggProtoImplClass, EggPrototype, Id, LifecycleContext, LifecycleHook, LifecycleHookName, LifecycleObject } from "@eggjs/tegg-types";
|
|
4
3
|
export * from "@eggjs/tegg-types/lifecycle";
|
|
4
|
+
|
|
5
|
+
//#region src/LifycycleUtil.d.ts
|
|
6
|
+
declare class LifecycleUtil<T extends LifecycleContext, R extends LifecycleObject<T>> {
|
|
7
|
+
private lifecycleSet;
|
|
8
|
+
private objLifecycleSet;
|
|
9
|
+
registerLifecycle(lifecycle: LifecycleHook<T, R>): void;
|
|
10
|
+
deleteLifecycle(lifecycle: LifecycleHook<T, R>): void;
|
|
11
|
+
getLifecycleList(): LifecycleHook<T, R>[];
|
|
12
|
+
registerObjectLifecycle(obj: R, lifecycle: LifecycleHook<T, R>): void;
|
|
13
|
+
deleteObjectLifecycle(obj: R, lifecycle: LifecycleHook<T, R>): void;
|
|
14
|
+
clearObjectLifecycle(obj: R): void;
|
|
15
|
+
getObjectLifecycleList(obj: R): LifecycleHook<T, R>[];
|
|
16
|
+
objectPreCreate(ctx: T, obj: R): Promise<void>;
|
|
17
|
+
objectPostCreate(ctx: T, obj: R): Promise<void>;
|
|
18
|
+
objectPreDestroy(ctx: T, obj: R): Promise<void>;
|
|
19
|
+
static callPreCreate<T extends LifecycleContext, R extends LifecycleObject<T>>(lifecycle: LifecycleHook<T, R> | undefined, ctx: T, obj: R): Promise<void>;
|
|
20
|
+
static callPostCreate<T extends LifecycleContext, R extends LifecycleObject<T>>(lifecycle: LifecycleHook<T, R> | undefined, ctx: T, obj: R): Promise<void>;
|
|
21
|
+
static callPreDestroy<T extends LifecycleContext, R extends LifecycleObject<T>>(lifecycle: LifecycleHook<T, R> | undefined, ctx: T, obj: R): Promise<void>;
|
|
22
|
+
static setLifecycleHook(method: string, hookName: LifecycleHookName, clazz: EggProtoImplClass): void;
|
|
23
|
+
getLifecycleHook(hookName: LifecycleHookName, proto: EggPrototype): keyof _eggjs_tegg_types0.EggObjectLifecycle;
|
|
24
|
+
static getStaticLifecycleHook(hookName: LifecycleHookName, clazz: EggProtoImplClass): string;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/IdenticalObject.d.ts
|
|
28
|
+
declare class IdenticalUtil {
|
|
29
|
+
private static objIndex;
|
|
30
|
+
private static protoIndex;
|
|
31
|
+
private static ctxIndex;
|
|
32
|
+
static createLoadUnitId(loadUnitName: string): Id;
|
|
33
|
+
static createProtoId(loadUnitId: Id, name: PropertyKey): Id;
|
|
34
|
+
static createLoadUnitInstanceId(loadUnitId: Id): Id;
|
|
35
|
+
static createContextId(traceId?: string): string;
|
|
36
|
+
static createObjectId(protoId: Id, ctxId?: Id): string;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/decorator/index.d.ts
|
|
40
|
+
declare const LifecyclePostConstruct: () => (target: object, methodName: string) => void;
|
|
41
|
+
declare const LifecyclePreInject: () => (target: object, methodName: string) => void;
|
|
42
|
+
declare const LifecyclePostInject: () => (target: object, methodName: string) => void;
|
|
43
|
+
declare const LifecycleInit: () => (target: object, methodName: string) => void;
|
|
44
|
+
declare const LifecyclePreDestroy: () => (target: object, methodName: string) => void;
|
|
45
|
+
declare const LifecycleDestroy: () => (target: object, methodName: string) => void;
|
|
46
|
+
declare const LifecyclePreLoad: () => (target: EggProtoImplClass, methodName: string) => void;
|
|
47
|
+
//#endregion
|
|
5
48
|
export { IdenticalUtil, LifecycleDestroy, LifecycleInit, LifecyclePostConstruct, LifecyclePostInject, LifecyclePreDestroy, LifecyclePreInject, LifecyclePreLoad, LifecycleUtil };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,128 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IdenticalUtil } from "./IdenticalObject.js";
|
|
3
|
-
import { LifecycleDestroy, LifecycleInit, LifecyclePostConstruct, LifecyclePostInject, LifecyclePreDestroy, LifecyclePreInject, LifecyclePreLoad } from "./decorator/index.js";
|
|
1
|
+
import { MetadataUtil } from "@eggjs/core-decorator";
|
|
4
2
|
|
|
5
3
|
export * from "@eggjs/tegg-types/lifecycle"
|
|
6
4
|
|
|
5
|
+
//#region src/LifycycleUtil.ts
|
|
6
|
+
var LifecycleUtil = class LifecycleUtil {
|
|
7
|
+
lifecycleSet = /* @__PURE__ */ new Set();
|
|
8
|
+
objLifecycleSet = /* @__PURE__ */ new Map();
|
|
9
|
+
registerLifecycle(lifecycle) {
|
|
10
|
+
this.lifecycleSet.add(lifecycle);
|
|
11
|
+
}
|
|
12
|
+
deleteLifecycle(lifecycle) {
|
|
13
|
+
this.lifecycleSet.delete(lifecycle);
|
|
14
|
+
}
|
|
15
|
+
getLifecycleList() {
|
|
16
|
+
return Array.from(this.lifecycleSet);
|
|
17
|
+
}
|
|
18
|
+
registerObjectLifecycle(obj, lifecycle) {
|
|
19
|
+
if (!this.objLifecycleSet.has(obj.id)) this.objLifecycleSet.set(obj.id, /* @__PURE__ */ new Set());
|
|
20
|
+
this.objLifecycleSet.get(obj.id).add(lifecycle);
|
|
21
|
+
}
|
|
22
|
+
deleteObjectLifecycle(obj, lifecycle) {
|
|
23
|
+
this.objLifecycleSet.get(obj.id)?.delete(lifecycle);
|
|
24
|
+
}
|
|
25
|
+
clearObjectLifecycle(obj) {
|
|
26
|
+
this.objLifecycleSet.delete(obj.id);
|
|
27
|
+
}
|
|
28
|
+
getObjectLifecycleList(obj) {
|
|
29
|
+
if (this.objLifecycleSet.has(obj.id)) return Array.from(this.objLifecycleSet.get(obj.id));
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
async objectPreCreate(ctx, obj) {
|
|
33
|
+
const globalLifecycleList = this.getLifecycleList();
|
|
34
|
+
const objLifecycleList = this.getObjectLifecycleList(obj);
|
|
35
|
+
await Promise.all(globalLifecycleList.map((lifecycle) => LifecycleUtil.callPreCreate(lifecycle, ctx, obj)));
|
|
36
|
+
await Promise.all(objLifecycleList.map((lifecycle) => LifecycleUtil.callPreCreate(lifecycle, ctx, obj)));
|
|
37
|
+
}
|
|
38
|
+
async objectPostCreate(ctx, obj) {
|
|
39
|
+
const lifecycleList = this.getLifecycleList();
|
|
40
|
+
const objLifecycleList = this.getObjectLifecycleList(obj);
|
|
41
|
+
await Promise.all(lifecycleList.map((lifecycle) => LifecycleUtil.callPostCreate(lifecycle, ctx, obj)));
|
|
42
|
+
await Promise.all(objLifecycleList.map((lifecycle) => LifecycleUtil.callPostCreate(lifecycle, ctx, obj)));
|
|
43
|
+
}
|
|
44
|
+
async objectPreDestroy(ctx, obj) {
|
|
45
|
+
const lifecycleList = this.getLifecycleList();
|
|
46
|
+
const objLifecycleList = this.getObjectLifecycleList(obj);
|
|
47
|
+
await Promise.all(lifecycleList.map((lifecycle) => LifecycleUtil.callPreDestroy(lifecycle, ctx, obj)));
|
|
48
|
+
await Promise.all(objLifecycleList.map((lifecycle) => LifecycleUtil.callPreDestroy(lifecycle, ctx, obj)));
|
|
49
|
+
}
|
|
50
|
+
static async callPreCreate(lifecycle, ctx, obj) {
|
|
51
|
+
if (!lifecycle || !lifecycle.preCreate) return;
|
|
52
|
+
await lifecycle.preCreate(ctx, obj);
|
|
53
|
+
}
|
|
54
|
+
static async callPostCreate(lifecycle, ctx, obj) {
|
|
55
|
+
if (!lifecycle || !lifecycle.postCreate) return;
|
|
56
|
+
await lifecycle.postCreate(ctx, obj);
|
|
57
|
+
}
|
|
58
|
+
static async callPreDestroy(lifecycle, ctx, obj) {
|
|
59
|
+
if (!lifecycle || !lifecycle.preDestroy) return;
|
|
60
|
+
await lifecycle.preDestroy(ctx, obj);
|
|
61
|
+
}
|
|
62
|
+
static setLifecycleHook(method, hookName, clazz) {
|
|
63
|
+
const LIFECYCLE_HOOK = Symbol.for(`EggPrototype#Lifecycle${hookName}`);
|
|
64
|
+
MetadataUtil.defineMetaData(LIFECYCLE_HOOK, method, clazz);
|
|
65
|
+
}
|
|
66
|
+
getLifecycleHook(hookName, proto) {
|
|
67
|
+
const LIFECYCLE_HOOK = Symbol.for(`EggPrototype#Lifecycle${hookName}`);
|
|
68
|
+
return proto.getMetaData(LIFECYCLE_HOOK);
|
|
69
|
+
}
|
|
70
|
+
static getStaticLifecycleHook(hookName, clazz) {
|
|
71
|
+
const LIFECYCLE_HOOK = Symbol.for(`EggPrototype#Lifecycle${hookName}`);
|
|
72
|
+
return MetadataUtil.getMetaData(LIFECYCLE_HOOK, clazz);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/IdenticalObject.ts
|
|
78
|
+
var IdenticalUtil = class {
|
|
79
|
+
static objIndex = 0;
|
|
80
|
+
static protoIndex = 0;
|
|
81
|
+
static ctxIndex = 0;
|
|
82
|
+
static createLoadUnitId(loadUnitName) {
|
|
83
|
+
return `LOAD_UNIT:${loadUnitName}`;
|
|
84
|
+
}
|
|
85
|
+
static createProtoId(loadUnitId, name) {
|
|
86
|
+
return `${loadUnitId}:PROTO:${this.protoIndex++}:${String(name)}`;
|
|
87
|
+
}
|
|
88
|
+
static createLoadUnitInstanceId(loadUnitId) {
|
|
89
|
+
return `${loadUnitId}:INSTANCE`;
|
|
90
|
+
}
|
|
91
|
+
static createContextId(traceId) {
|
|
92
|
+
if (traceId) return `CONTEXT:${traceId}:${this.ctxIndex++}`;
|
|
93
|
+
return `CONTEXT:${this.ctxIndex++}`;
|
|
94
|
+
}
|
|
95
|
+
static createObjectId(protoId, ctxId) {
|
|
96
|
+
if (ctxId) return `${protoId}:INSTANCE:${ctxId}`;
|
|
97
|
+
return `${protoId}:INSTANCE:${this.objIndex++}`;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/decorator/index.ts
|
|
103
|
+
function createLifecycle(hookName) {
|
|
104
|
+
return () => {
|
|
105
|
+
return function(target, methodName) {
|
|
106
|
+
const clazz = target.constructor;
|
|
107
|
+
LifecycleUtil.setLifecycleHook(methodName, hookName, clazz);
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function createStaticLifecycle(hookName) {
|
|
112
|
+
return () => {
|
|
113
|
+
return function(target, methodName) {
|
|
114
|
+
if (typeof target !== "function") throw new Error(`${hookName} must be a static function`);
|
|
115
|
+
LifecycleUtil.setLifecycleHook(methodName, hookName, target);
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const LifecyclePostConstruct = createLifecycle("postConstruct");
|
|
120
|
+
const LifecyclePreInject = createLifecycle("preInject");
|
|
121
|
+
const LifecyclePostInject = createLifecycle("postInject");
|
|
122
|
+
const LifecycleInit = createLifecycle("init");
|
|
123
|
+
const LifecyclePreDestroy = createLifecycle("preDestroy");
|
|
124
|
+
const LifecycleDestroy = createLifecycle("destroy");
|
|
125
|
+
const LifecyclePreLoad = createStaticLifecycle("preLoad");
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
7
128
|
export { IdenticalUtil, LifecycleDestroy, LifecycleInit, LifecyclePostConstruct, LifecyclePostInject, LifecyclePreDestroy, LifecyclePreInject, LifecyclePreLoad, LifecycleUtil };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/tegg-lifecycle",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"description": "tegg lifecycle definition",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"egg",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@eggjs/core-decorator": "4.0.0-beta.
|
|
38
|
-
"@eggjs/tegg-types": "4.0.0-beta.
|
|
37
|
+
"@eggjs/core-decorator": "4.0.0-beta.8",
|
|
38
|
+
"@eggjs/tegg-types": "4.0.0-beta.8"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^22.10.5",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Id } from "@eggjs/tegg-types";
|
|
2
|
-
|
|
3
|
-
//#region src/IdenticalObject.d.ts
|
|
4
|
-
declare class IdenticalUtil {
|
|
5
|
-
private static objIndex;
|
|
6
|
-
private static protoIndex;
|
|
7
|
-
private static ctxIndex;
|
|
8
|
-
static createLoadUnitId(loadUnitName: string): Id;
|
|
9
|
-
static createProtoId(loadUnitId: Id, name: PropertyKey): Id;
|
|
10
|
-
static createLoadUnitInstanceId(loadUnitId: Id): Id;
|
|
11
|
-
static createContextId(traceId?: string): string;
|
|
12
|
-
static createObjectId(protoId: Id, ctxId?: Id): string;
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
export { IdenticalUtil };
|
package/dist/IdenticalObject.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
//#region src/IdenticalObject.ts
|
|
2
|
-
var IdenticalUtil = class {
|
|
3
|
-
static objIndex = 0;
|
|
4
|
-
static protoIndex = 0;
|
|
5
|
-
static ctxIndex = 0;
|
|
6
|
-
static createLoadUnitId(loadUnitName) {
|
|
7
|
-
return `LOAD_UNIT:${loadUnitName}`;
|
|
8
|
-
}
|
|
9
|
-
static createProtoId(loadUnitId, name) {
|
|
10
|
-
return `${loadUnitId}:PROTO:${this.protoIndex++}:${String(name)}`;
|
|
11
|
-
}
|
|
12
|
-
static createLoadUnitInstanceId(loadUnitId) {
|
|
13
|
-
return `${loadUnitId}:INSTANCE`;
|
|
14
|
-
}
|
|
15
|
-
static createContextId(traceId) {
|
|
16
|
-
if (traceId) return `CONTEXT:${traceId}:${this.ctxIndex++}`;
|
|
17
|
-
return `CONTEXT:${this.ctxIndex++}`;
|
|
18
|
-
}
|
|
19
|
-
static createObjectId(protoId, ctxId) {
|
|
20
|
-
if (ctxId) return `${protoId}:INSTANCE:${ctxId}`;
|
|
21
|
-
return `${protoId}:INSTANCE:${this.objIndex++}`;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
export { IdenticalUtil };
|
package/dist/LifycycleUtil.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as _eggjs_tegg_types0 from "@eggjs/tegg-types";
|
|
2
|
-
import { EggProtoImplClass, EggPrototype, LifecycleContext, LifecycleHook, LifecycleHookName, LifecycleObject } from "@eggjs/tegg-types";
|
|
3
|
-
|
|
4
|
-
//#region src/LifycycleUtil.d.ts
|
|
5
|
-
declare class LifecycleUtil<T extends LifecycleContext, R extends LifecycleObject<T>> {
|
|
6
|
-
private lifecycleSet;
|
|
7
|
-
private objLifecycleSet;
|
|
8
|
-
registerLifecycle(lifecycle: LifecycleHook<T, R>): void;
|
|
9
|
-
deleteLifecycle(lifecycle: LifecycleHook<T, R>): void;
|
|
10
|
-
getLifecycleList(): LifecycleHook<T, R>[];
|
|
11
|
-
registerObjectLifecycle(obj: R, lifecycle: LifecycleHook<T, R>): void;
|
|
12
|
-
deleteObjectLifecycle(obj: R, lifecycle: LifecycleHook<T, R>): void;
|
|
13
|
-
clearObjectLifecycle(obj: R): void;
|
|
14
|
-
getObjectLifecycleList(obj: R): LifecycleHook<T, R>[];
|
|
15
|
-
objectPreCreate(ctx: T, obj: R): Promise<void>;
|
|
16
|
-
objectPostCreate(ctx: T, obj: R): Promise<void>;
|
|
17
|
-
objectPreDestroy(ctx: T, obj: R): Promise<void>;
|
|
18
|
-
static callPreCreate<T extends LifecycleContext, R extends LifecycleObject<T>>(lifecycle: LifecycleHook<T, R> | undefined, ctx: T, obj: R): Promise<void>;
|
|
19
|
-
static callPostCreate<T extends LifecycleContext, R extends LifecycleObject<T>>(lifecycle: LifecycleHook<T, R> | undefined, ctx: T, obj: R): Promise<void>;
|
|
20
|
-
static callPreDestroy<T extends LifecycleContext, R extends LifecycleObject<T>>(lifecycle: LifecycleHook<T, R> | undefined, ctx: T, obj: R): Promise<void>;
|
|
21
|
-
static setLifecycleHook(method: string, hookName: LifecycleHookName, clazz: EggProtoImplClass): void;
|
|
22
|
-
getLifecycleHook(hookName: LifecycleHookName, proto: EggPrototype): keyof _eggjs_tegg_types0.EggObjectLifecycle;
|
|
23
|
-
static getStaticLifecycleHook(hookName: LifecycleHookName, clazz: EggProtoImplClass): string;
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { LifecycleUtil };
|
package/dist/LifycycleUtil.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { MetadataUtil } from "@eggjs/core-decorator";
|
|
2
|
-
|
|
3
|
-
//#region src/LifycycleUtil.ts
|
|
4
|
-
var LifecycleUtil = class LifecycleUtil {
|
|
5
|
-
lifecycleSet = /* @__PURE__ */ new Set();
|
|
6
|
-
objLifecycleSet = /* @__PURE__ */ new Map();
|
|
7
|
-
registerLifecycle(lifecycle) {
|
|
8
|
-
this.lifecycleSet.add(lifecycle);
|
|
9
|
-
}
|
|
10
|
-
deleteLifecycle(lifecycle) {
|
|
11
|
-
this.lifecycleSet.delete(lifecycle);
|
|
12
|
-
}
|
|
13
|
-
getLifecycleList() {
|
|
14
|
-
return Array.from(this.lifecycleSet);
|
|
15
|
-
}
|
|
16
|
-
registerObjectLifecycle(obj, lifecycle) {
|
|
17
|
-
if (!this.objLifecycleSet.has(obj.id)) this.objLifecycleSet.set(obj.id, /* @__PURE__ */ new Set());
|
|
18
|
-
this.objLifecycleSet.get(obj.id).add(lifecycle);
|
|
19
|
-
}
|
|
20
|
-
deleteObjectLifecycle(obj, lifecycle) {
|
|
21
|
-
this.objLifecycleSet.get(obj.id)?.delete(lifecycle);
|
|
22
|
-
}
|
|
23
|
-
clearObjectLifecycle(obj) {
|
|
24
|
-
this.objLifecycleSet.delete(obj.id);
|
|
25
|
-
}
|
|
26
|
-
getObjectLifecycleList(obj) {
|
|
27
|
-
if (this.objLifecycleSet.has(obj.id)) return Array.from(this.objLifecycleSet.get(obj.id));
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
async objectPreCreate(ctx, obj) {
|
|
31
|
-
const globalLifecycleList = this.getLifecycleList();
|
|
32
|
-
const objLifecycleList = this.getObjectLifecycleList(obj);
|
|
33
|
-
await Promise.all(globalLifecycleList.map((lifecycle) => LifecycleUtil.callPreCreate(lifecycle, ctx, obj)));
|
|
34
|
-
await Promise.all(objLifecycleList.map((lifecycle) => LifecycleUtil.callPreCreate(lifecycle, ctx, obj)));
|
|
35
|
-
}
|
|
36
|
-
async objectPostCreate(ctx, obj) {
|
|
37
|
-
const lifecycleList = this.getLifecycleList();
|
|
38
|
-
const objLifecycleList = this.getObjectLifecycleList(obj);
|
|
39
|
-
await Promise.all(lifecycleList.map((lifecycle) => LifecycleUtil.callPostCreate(lifecycle, ctx, obj)));
|
|
40
|
-
await Promise.all(objLifecycleList.map((lifecycle) => LifecycleUtil.callPostCreate(lifecycle, ctx, obj)));
|
|
41
|
-
}
|
|
42
|
-
async objectPreDestroy(ctx, obj) {
|
|
43
|
-
const lifecycleList = this.getLifecycleList();
|
|
44
|
-
const objLifecycleList = this.getObjectLifecycleList(obj);
|
|
45
|
-
await Promise.all(lifecycleList.map((lifecycle) => LifecycleUtil.callPreDestroy(lifecycle, ctx, obj)));
|
|
46
|
-
await Promise.all(objLifecycleList.map((lifecycle) => LifecycleUtil.callPreDestroy(lifecycle, ctx, obj)));
|
|
47
|
-
}
|
|
48
|
-
static async callPreCreate(lifecycle, ctx, obj) {
|
|
49
|
-
if (!lifecycle || !lifecycle.preCreate) return;
|
|
50
|
-
await lifecycle.preCreate(ctx, obj);
|
|
51
|
-
}
|
|
52
|
-
static async callPostCreate(lifecycle, ctx, obj) {
|
|
53
|
-
if (!lifecycle || !lifecycle.postCreate) return;
|
|
54
|
-
await lifecycle.postCreate(ctx, obj);
|
|
55
|
-
}
|
|
56
|
-
static async callPreDestroy(lifecycle, ctx, obj) {
|
|
57
|
-
if (!lifecycle || !lifecycle.preDestroy) return;
|
|
58
|
-
await lifecycle.preDestroy(ctx, obj);
|
|
59
|
-
}
|
|
60
|
-
static setLifecycleHook(method, hookName, clazz) {
|
|
61
|
-
const LIFECYCLE_HOOK = Symbol.for(`EggPrototype#Lifecycle${hookName}`);
|
|
62
|
-
MetadataUtil.defineMetaData(LIFECYCLE_HOOK, method, clazz);
|
|
63
|
-
}
|
|
64
|
-
getLifecycleHook(hookName, proto) {
|
|
65
|
-
const LIFECYCLE_HOOK = Symbol.for(`EggPrototype#Lifecycle${hookName}`);
|
|
66
|
-
return proto.getMetaData(LIFECYCLE_HOOK);
|
|
67
|
-
}
|
|
68
|
-
static getStaticLifecycleHook(hookName, clazz) {
|
|
69
|
-
const LIFECYCLE_HOOK = Symbol.for(`EggPrototype#Lifecycle${hookName}`);
|
|
70
|
-
return MetadataUtil.getMetaData(LIFECYCLE_HOOK, clazz);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
//#endregion
|
|
75
|
-
export { LifecycleUtil };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { EggProtoImplClass } from "@eggjs/tegg-types";
|
|
2
|
-
|
|
3
|
-
//#region src/decorator/index.d.ts
|
|
4
|
-
declare const LifecyclePostConstruct: () => (target: object, methodName: string) => void;
|
|
5
|
-
declare const LifecyclePreInject: () => (target: object, methodName: string) => void;
|
|
6
|
-
declare const LifecyclePostInject: () => (target: object, methodName: string) => void;
|
|
7
|
-
declare const LifecycleInit: () => (target: object, methodName: string) => void;
|
|
8
|
-
declare const LifecyclePreDestroy: () => (target: object, methodName: string) => void;
|
|
9
|
-
declare const LifecycleDestroy: () => (target: object, methodName: string) => void;
|
|
10
|
-
declare const LifecyclePreLoad: () => (target: EggProtoImplClass, methodName: string) => void;
|
|
11
|
-
//#endregion
|
|
12
|
-
export { LifecycleDestroy, LifecycleInit, LifecyclePostConstruct, LifecyclePostInject, LifecyclePreDestroy, LifecyclePreInject, LifecyclePreLoad };
|
package/dist/decorator/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { LifecycleUtil } from "../LifycycleUtil.js";
|
|
2
|
-
|
|
3
|
-
//#region src/decorator/index.ts
|
|
4
|
-
function createLifecycle(hookName) {
|
|
5
|
-
return () => {
|
|
6
|
-
return function(target, methodName) {
|
|
7
|
-
const clazz = target.constructor;
|
|
8
|
-
LifecycleUtil.setLifecycleHook(methodName, hookName, clazz);
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function createStaticLifecycle(hookName) {
|
|
13
|
-
return () => {
|
|
14
|
-
return function(target, methodName) {
|
|
15
|
-
if (typeof target !== "function") throw new Error(`${hookName} must be a static function`);
|
|
16
|
-
LifecycleUtil.setLifecycleHook(methodName, hookName, target);
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
const LifecyclePostConstruct = createLifecycle("postConstruct");
|
|
21
|
-
const LifecyclePreInject = createLifecycle("preInject");
|
|
22
|
-
const LifecyclePostInject = createLifecycle("postInject");
|
|
23
|
-
const LifecycleInit = createLifecycle("init");
|
|
24
|
-
const LifecyclePreDestroy = createLifecycle("preDestroy");
|
|
25
|
-
const LifecycleDestroy = createLifecycle("destroy");
|
|
26
|
-
const LifecyclePreLoad = createStaticLifecycle("preLoad");
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
export { LifecycleDestroy, LifecycleInit, LifecyclePostConstruct, LifecyclePostInject, LifecyclePreDestroy, LifecyclePreInject, LifecyclePreLoad };
|