@eggjs/eventbus-plugin 4.0.0-beta.35 → 4.0.0-beta.36
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/app/extend/application.unittest.d.ts +9 -5
- package/dist/app/extend/application.unittest.js +17 -15
- package/dist/app/extend/context.d.ts +7 -3
- package/dist/app/extend/context.js +13 -11
- package/dist/app.d.ts +14 -10
- package/dist/app.js +30 -26
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/lib/EggContextEventBus.d.ts +14 -10
- package/dist/lib/EggContextEventBus.js +39 -35
- package/dist/lib/EggEventContext.d.ts +9 -6
- package/dist/lib/EggEventContext.js +24 -28
- package/dist/lib/EventHandlerProtoManager.d.ts +13 -9
- package/dist/lib/EventHandlerProtoManager.js +27 -26
- package/dist/lib/EventbusLoadUnitHook.d.ts +8 -4
- package/dist/lib/EventbusLoadUnitHook.js +22 -20
- package/dist/lib/EventbusProtoHook.d.ts +11 -7
- package/dist/lib/EventbusProtoHook.js +17 -16
- package/dist/types.d.ts +20 -18
- package/dist/types.js +3 -2
- package/package.json +46 -50
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { EventBus, EventWaiter } from "@eggjs/eventbus-decorator";
|
|
2
|
+
import { Application } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/application.unittest.d.ts
|
|
5
|
+
declare class EventBusApplicationUnittest {
|
|
6
|
+
getEventbus(this: Application): Promise<EventBus>;
|
|
7
|
+
getEventWaiter(this: Application): Promise<EventWaiter>;
|
|
6
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { EventBusApplicationUnittest as default };
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { PrototypeUtil } from
|
|
2
|
-
import { SingletonEventBus } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
1
|
+
import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
2
|
+
import { SingletonEventBus } from "@eggjs/eventbus-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/application.unittest.ts
|
|
5
|
+
var EventBusApplicationUnittest = class {
|
|
6
|
+
async getEventbus() {
|
|
7
|
+
const proto = PrototypeUtil.getClazzProto(SingletonEventBus);
|
|
8
|
+
return (await this.eggContainerFactory.getOrCreateEggObject(proto, proto.name)).obj;
|
|
9
|
+
}
|
|
10
|
+
async getEventWaiter() {
|
|
11
|
+
const proto = PrototypeUtil.getClazzProto(SingletonEventBus);
|
|
12
|
+
return (await this.eggContainerFactory.getOrCreateEggObject(proto, proto.name)).obj;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { EventBusApplicationUnittest as default };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { EggContextEventBus } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { EggContextEventBus } from "../../lib/EggContextEventBus.js";
|
|
2
|
+
|
|
3
|
+
//#region src/app/extend/context.d.ts
|
|
4
|
+
declare class EventBusContext {
|
|
5
|
+
get eventBus(): EggContextEventBus;
|
|
4
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { EventBusContext as default };
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { EggContextEventBus } from "../../lib/EggContextEventBus.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/app/extend/context.ts
|
|
4
|
+
const EVENT_BUS = Symbol.for("context#eventBus");
|
|
5
|
+
var EventBusContext = class {
|
|
6
|
+
get eventBus() {
|
|
7
|
+
const ctx = this;
|
|
8
|
+
if (!ctx[EVENT_BUS]) ctx[EVENT_BUS] = new EggContextEventBus(ctx);
|
|
9
|
+
return ctx[EVENT_BUS];
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { EventBusContext as default };
|
package/dist/app.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Application, ILifecycleBoot } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/app.d.ts
|
|
4
|
+
declare class EventbusAppHook implements ILifecycleBoot {
|
|
5
|
+
private readonly app;
|
|
6
|
+
private readonly eventHandlerProtoManager;
|
|
7
|
+
private readonly eventbusLoadUnitHook;
|
|
8
|
+
private readonly eventbusProtoHook;
|
|
9
|
+
constructor(app: Application);
|
|
10
|
+
configDidLoad(): void;
|
|
11
|
+
didLoad(): Promise<void>;
|
|
12
|
+
beforeClose(): Promise<void>;
|
|
11
13
|
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { EventbusAppHook as default };
|
package/dist/app.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import { EventbusLoadUnitHook } from "./lib/EventbusLoadUnitHook.js";
|
|
2
|
-
import { EventbusProtoHook } from "./lib/EventbusProtoHook.js";
|
|
3
2
|
import { EventHandlerProtoManager } from "./lib/EventHandlerProtoManager.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
3
|
+
import { EventbusProtoHook } from "./lib/EventbusProtoHook.js";
|
|
4
|
+
|
|
5
|
+
//#region src/app.ts
|
|
6
|
+
var EventbusAppHook = class {
|
|
7
|
+
app;
|
|
8
|
+
eventHandlerProtoManager;
|
|
9
|
+
eventbusLoadUnitHook;
|
|
10
|
+
eventbusProtoHook;
|
|
11
|
+
constructor(app) {
|
|
12
|
+
this.app = app;
|
|
13
|
+
this.eventHandlerProtoManager = new EventHandlerProtoManager(app);
|
|
14
|
+
this.eventbusLoadUnitHook = new EventbusLoadUnitHook();
|
|
15
|
+
this.eventbusProtoHook = new EventbusProtoHook(this.eventHandlerProtoManager);
|
|
16
|
+
}
|
|
17
|
+
configDidLoad() {
|
|
18
|
+
this.app.eggPrototypeLifecycleUtil.registerLifecycle(this.eventbusProtoHook);
|
|
19
|
+
this.app.loadUnitLifecycleUtil.registerLifecycle(this.eventbusLoadUnitHook);
|
|
20
|
+
}
|
|
21
|
+
async didLoad() {
|
|
22
|
+
await this.app.moduleHandler.ready();
|
|
23
|
+
await this.eventHandlerProtoManager.register();
|
|
24
|
+
}
|
|
25
|
+
async beforeClose() {
|
|
26
|
+
this.app.eggPrototypeLifecycleUtil.deleteLifecycle(this.eventbusProtoHook);
|
|
27
|
+
this.app.loadUnitLifecycleUtil.deleteLifecycle(this.eventbusLoadUnitHook);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { EventbusAppHook as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Arguments, ContextEventBus, Events } from "@eggjs/eventbus-decorator";
|
|
2
|
+
import { Context } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/EggContextEventBus.d.ts
|
|
5
|
+
declare class EggContextEventBus implements ContextEventBus {
|
|
6
|
+
private readonly eventBus;
|
|
7
|
+
private readonly context;
|
|
8
|
+
private corkId?;
|
|
9
|
+
constructor(ctx: Context);
|
|
10
|
+
cork(): void;
|
|
11
|
+
uncork(): boolean;
|
|
12
|
+
emit<E extends keyof Events>(event: E, ...args: Arguments<Events[E]>): boolean;
|
|
11
13
|
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { EggContextEventBus };
|
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { CORK_ID } from
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
2
|
+
import { SingletonEventBus } from "@eggjs/eventbus-runtime";
|
|
3
|
+
import { CORK_ID } from "@eggjs/eventbus-decorator";
|
|
4
|
+
import { ContextHandler } from "@eggjs/tegg-runtime";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/EggContextEventBus.ts
|
|
8
|
+
var EggContextEventBus = class {
|
|
9
|
+
eventBus;
|
|
10
|
+
context;
|
|
11
|
+
corkId;
|
|
12
|
+
constructor(ctx) {
|
|
13
|
+
const proto = PrototypeUtil.getClazzProto(SingletonEventBus);
|
|
14
|
+
const eggObject = ctx.app.eggContainerFactory.getEggObject(proto, proto.name);
|
|
15
|
+
this.context = ContextHandler.getContext();
|
|
16
|
+
this.eventBus = eggObject.obj;
|
|
17
|
+
}
|
|
18
|
+
cork() {
|
|
19
|
+
if (!this.corkId) {
|
|
20
|
+
this.corkId = this.eventBus.generateCorkId();
|
|
21
|
+
this.context.set(CORK_ID, this.corkId);
|
|
22
|
+
}
|
|
23
|
+
this.eventBus.cork(this.corkId);
|
|
24
|
+
}
|
|
25
|
+
uncork() {
|
|
26
|
+
assert(this.corkId, "eventbus uncork without cork");
|
|
27
|
+
if (this.eventBus.uncork(this.corkId)) {
|
|
28
|
+
this.context.set(CORK_ID, null);
|
|
29
|
+
this.corkId = void 0;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
emit(event, ...args) {
|
|
34
|
+
return this.eventBus.emitWithContext(this.context, event, args);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { EggContextEventBus };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { IdenticalUtil } from
|
|
3
|
-
import { AbstractEggContext } from
|
|
4
|
-
import
|
|
1
|
+
import { ContextCreator } from "@eggjs/eventbus-runtime";
|
|
2
|
+
import { IdenticalUtil } from "@eggjs/lifecycle";
|
|
3
|
+
import { AbstractEggContext } from "@eggjs/tegg-runtime";
|
|
4
|
+
import { Application } from "egg";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/EggEventContext.d.ts
|
|
5
7
|
type CreateContextFactory = (app: Application) => ContextCreator;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
declare function eggEventContextFactory(AbstractEggContextClazz: typeof AbstractEggContext, identicalUtil: typeof IdenticalUtil): CreateContextFactory;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { eggEventContextFactory };
|
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
import { IdenticalUtil } from
|
|
2
|
-
import { EGG_CONTEXT, TEGG_CONTEXT } from
|
|
3
|
-
import { AbstractEggContext } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const eggCtx = app.createAnonymousContext();
|
|
23
|
-
return new EggEventContext(eggCtx);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return EggEventContext.createContextFactory;
|
|
1
|
+
import { IdenticalUtil } from "@eggjs/lifecycle";
|
|
2
|
+
import { EGG_CONTEXT, TEGG_CONTEXT } from "@eggjs/module-common";
|
|
3
|
+
import { AbstractEggContext } from "@eggjs/tegg-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/EggEventContext.ts
|
|
6
|
+
function eggEventContextFactory(AbstractEggContextClazz, identicalUtil) {
|
|
7
|
+
class EggEventContext extends AbstractEggContextClazz {
|
|
8
|
+
id;
|
|
9
|
+
constructor(context) {
|
|
10
|
+
super();
|
|
11
|
+
this.set(EGG_CONTEXT, context);
|
|
12
|
+
context[TEGG_CONTEXT] = this;
|
|
13
|
+
this.id = identicalUtil.createContextId(context.tracer?.traceId);
|
|
14
|
+
}
|
|
15
|
+
static createContextFactory(app) {
|
|
16
|
+
return () => {
|
|
17
|
+
return new EggEventContext(app.createAnonymousContext());
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return EggEventContext.createContextFactory;
|
|
28
22
|
}
|
|
29
|
-
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { eggEventContextFactory };
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { EggPrototype } from "@eggjs/metadata";
|
|
2
|
+
import { Application } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/EventHandlerProtoManager.d.ts
|
|
5
|
+
declare class EventHandlerProtoManager {
|
|
6
|
+
private readonly protos;
|
|
7
|
+
private readonly app;
|
|
8
|
+
constructor(app: Application);
|
|
9
|
+
addProto(proto: EggPrototype): void;
|
|
10
|
+
register(): Promise<void>;
|
|
11
|
+
getProtos(): EggPrototype[];
|
|
10
12
|
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { EventHandlerProtoManager };
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import { EVENT_NAME } from '@eggjs/eventbus-decorator';
|
|
2
|
-
import { EventContextFactory, EventHandlerFactory } from '@eggjs/eventbus-runtime';
|
|
3
1
|
import { eggEventContextFactory } from "./EggEventContext.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
2
|
+
import { EventContextFactory, EventHandlerFactory } from "@eggjs/eventbus-runtime";
|
|
3
|
+
import { EVENT_NAME } from "@eggjs/eventbus-decorator";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/EventHandlerProtoManager.ts
|
|
6
|
+
var EventHandlerProtoManager = class {
|
|
7
|
+
protos = /* @__PURE__ */ new Set();
|
|
8
|
+
app;
|
|
9
|
+
constructor(app) {
|
|
10
|
+
this.app = app;
|
|
11
|
+
}
|
|
12
|
+
addProto(proto) {
|
|
13
|
+
this.protos.add(proto);
|
|
14
|
+
}
|
|
15
|
+
async register() {
|
|
16
|
+
const eventHandlerFactory = await this.app.getEggObject(EventHandlerFactory);
|
|
17
|
+
for (const proto of this.protos) (proto.getMetaData(EVENT_NAME) ?? []).forEach((event) => eventHandlerFactory.registerHandler(event, proto));
|
|
18
|
+
const eventFactory = await this.app.getEggObject(EventContextFactory);
|
|
19
|
+
const createContextFactory = eggEventContextFactory(this.app.abstractEggContext, this.app.identicalUtil);
|
|
20
|
+
eventFactory.registerContextCreator(createContextFactory(this.app));
|
|
21
|
+
}
|
|
22
|
+
getProtos() {
|
|
23
|
+
return Array.from(this.protos);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { EventHandlerProtoManager };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { LoadUnit, LoadUnitLifecycleContext } from "@eggjs/metadata";
|
|
2
|
+
import { LifecycleHook } from "@eggjs/lifecycle";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/EventbusLoadUnitHook.d.ts
|
|
5
|
+
declare class EventbusLoadUnitHook implements LifecycleHook<LoadUnitLifecycleContext, LoadUnit> {
|
|
6
|
+
postCreate(_ctx: LoadUnitLifecycleContext, loadUnit: LoadUnit): Promise<void>;
|
|
5
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { EventbusLoadUnitHook };
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EventContextFactory, EventHandlerFactory, SingletonEventBus } from
|
|
3
|
-
import { EggLoadUnitType, EggPrototypeCreatorFactory, EggPrototypeFactory
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
1
|
+
import { EggQualifierAttribute, EggType, QualifierUtil } from "@eggjs/core-decorator";
|
|
2
|
+
import { EventContextFactory, EventHandlerFactory, SingletonEventBus } from "@eggjs/eventbus-runtime";
|
|
3
|
+
import { EggLoadUnitType, EggPrototypeCreatorFactory, EggPrototypeFactory } from "@eggjs/metadata";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/EventbusLoadUnitHook.ts
|
|
6
|
+
const REGISTER_CLAZZ = [
|
|
7
|
+
EventHandlerFactory,
|
|
8
|
+
EventContextFactory,
|
|
9
|
+
SingletonEventBus
|
|
10
|
+
];
|
|
11
|
+
QualifierUtil.addProperQualifier(SingletonEventBus, "logger", EggQualifierAttribute, EggType.APP);
|
|
12
|
+
var EventbusLoadUnitHook = class {
|
|
13
|
+
async postCreate(_ctx, loadUnit) {
|
|
14
|
+
if (loadUnit.type === EggLoadUnitType.APP) for (const clazz of REGISTER_CLAZZ) {
|
|
15
|
+
const protos = await EggPrototypeCreatorFactory.createProto(clazz, loadUnit);
|
|
16
|
+
for (const proto of protos) EggPrototypeFactory.instance.registerPrototype(proto, loadUnit);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { EventbusLoadUnitHook };
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { EventHandlerProtoManager } from "./EventHandlerProtoManager.js";
|
|
2
|
+
import { EggPrototype, EggPrototypeLifecycleContext } from "@eggjs/metadata";
|
|
3
|
+
import { LifecycleHook } from "@eggjs/lifecycle";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/EventbusProtoHook.d.ts
|
|
6
|
+
declare class EventbusProtoHook implements LifecycleHook<EggPrototypeLifecycleContext, EggPrototype> {
|
|
7
|
+
private eventHandlerProtoManager;
|
|
8
|
+
constructor(eventHandlerProtoManager: EventHandlerProtoManager);
|
|
9
|
+
postCreate(_ctx: EggPrototypeLifecycleContext, obj: EggPrototype): Promise<void>;
|
|
8
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { EventbusProtoHook };
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//#
|
|
1
|
+
import "./EventHandlerProtoManager.js";
|
|
2
|
+
import { EVENT_NAME } from "@eggjs/eventbus-decorator";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/EventbusProtoHook.ts
|
|
5
|
+
var EventbusProtoHook = class {
|
|
6
|
+
eventHandlerProtoManager;
|
|
7
|
+
constructor(eventHandlerProtoManager) {
|
|
8
|
+
this.eventHandlerProtoManager = eventHandlerProtoManager;
|
|
9
|
+
}
|
|
10
|
+
async postCreate(_ctx, obj) {
|
|
11
|
+
if (!obj.getMetaData(EVENT_NAME)) return;
|
|
12
|
+
this.eventHandlerProtoManager.addProto(obj);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { EventbusProtoHook };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { EggContextEventBus } from "./lib/EggContextEventBus.js";
|
|
2
|
+
import { EventBus, EventWaiter } from "@eggjs/eventbus-decorator";
|
|
3
|
+
import "@eggjs/tegg-plugin/types";
|
|
4
|
+
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
declare module "egg" {
|
|
7
|
+
interface Application {
|
|
8
|
+
/**
|
|
9
|
+
* Get the event bus, only for unittest
|
|
10
|
+
*/
|
|
11
|
+
getEventbus(): Promise<EventBus>;
|
|
12
|
+
/**
|
|
13
|
+
* Get the event waiter, only for unittest
|
|
14
|
+
*/
|
|
15
|
+
getEventWaiter(): Promise<EventWaiter>;
|
|
16
|
+
}
|
|
17
|
+
interface Context {
|
|
18
|
+
get eventBus(): EggContextEventBus;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "@eggjs/tegg-plugin/types";
|
|
2
|
+
|
|
3
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/eventbus-plugin",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
4
|
-
"eggPlugin": {
|
|
5
|
-
"name": "teggEventbus",
|
|
6
|
-
"dependencies": [
|
|
7
|
-
"tegg"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
3
|
+
"version": "4.0.0-beta.36",
|
|
10
4
|
"description": "tegg event plugin",
|
|
11
5
|
"keywords": [
|
|
12
|
-
"egg",
|
|
13
|
-
"typescript",
|
|
14
6
|
"decorator",
|
|
7
|
+
"egg",
|
|
15
8
|
"eventbus",
|
|
16
|
-
"tegg"
|
|
9
|
+
"tegg",
|
|
10
|
+
"typescript"
|
|
17
11
|
],
|
|
12
|
+
"homepage": "https://github.com/eggjs/egg/tree/next/tegg/plugin/eventbus",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/eggjs/egg/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/eggjs/egg.git",
|
|
19
|
+
"directory": "tegg/plugin/eventbus"
|
|
20
|
+
},
|
|
18
21
|
"files": [
|
|
19
22
|
"dist"
|
|
20
23
|
],
|
|
21
24
|
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
22
28
|
"exports": {
|
|
23
29
|
".": "./dist/index.js",
|
|
24
30
|
"./app": "./dist/app.js",
|
|
@@ -32,53 +38,43 @@
|
|
|
32
38
|
"./types": "./dist/types.js",
|
|
33
39
|
"./package.json": "./package.json"
|
|
34
40
|
},
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
"url": "https://github.com/eggjs/egg/issues"
|
|
38
|
-
},
|
|
39
|
-
"repository": {
|
|
40
|
-
"type": "git",
|
|
41
|
-
"url": "git+https://github.com/eggjs/egg.git",
|
|
42
|
-
"directory": "tegg/plugin/eventbus"
|
|
43
|
-
},
|
|
44
|
-
"engines": {
|
|
45
|
-
"node": ">=22.18.0"
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
46
43
|
},
|
|
47
44
|
"dependencies": {
|
|
48
|
-
"@eggjs/core-decorator": "4.0.0-beta.
|
|
49
|
-
"@eggjs/
|
|
50
|
-
"@eggjs/eventbus-
|
|
51
|
-
"@eggjs/
|
|
52
|
-
"@eggjs/
|
|
53
|
-
"@eggjs/
|
|
54
|
-
"@eggjs/tegg-runtime": "4.0.0-beta.
|
|
55
|
-
},
|
|
56
|
-
"peerDependencies": {
|
|
57
|
-
"@eggjs/tegg-plugin": "4.0.0-beta.35",
|
|
58
|
-
"egg": "4.1.0-beta.35"
|
|
45
|
+
"@eggjs/core-decorator": "4.0.0-beta.36",
|
|
46
|
+
"@eggjs/lifecycle": "4.0.0-beta.36",
|
|
47
|
+
"@eggjs/eventbus-runtime": "4.0.0-beta.36",
|
|
48
|
+
"@eggjs/metadata": "4.0.0-beta.36",
|
|
49
|
+
"@eggjs/eventbus-decorator": "4.0.0-beta.36",
|
|
50
|
+
"@eggjs/module-common": "4.0.0-beta.36",
|
|
51
|
+
"@eggjs/tegg-runtime": "4.0.0-beta.36"
|
|
59
52
|
},
|
|
60
53
|
"devDependencies": {
|
|
61
|
-
"@types/node": "^24.10.
|
|
62
|
-
"tsdown": "^0.17.0",
|
|
54
|
+
"@types/node": "^24.10.2",
|
|
63
55
|
"typescript": "^5.9.3",
|
|
64
|
-
"
|
|
65
|
-
"@eggjs/
|
|
66
|
-
"@eggjs/tegg": "4.0.0-beta.
|
|
67
|
-
"@eggjs/tegg
|
|
68
|
-
"@eggjs/tegg-
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"@eggjs/tegg-common-util": "4.0.0-beta.35"
|
|
56
|
+
"@eggjs/mock": "7.0.0-beta.36",
|
|
57
|
+
"@eggjs/tegg-common-util": "4.0.0-beta.36",
|
|
58
|
+
"@eggjs/tegg-plugin": "4.0.0-beta.36",
|
|
59
|
+
"@eggjs/tegg": "4.0.0-beta.36",
|
|
60
|
+
"@eggjs/tegg-config": "4.0.0-beta.36",
|
|
61
|
+
"@eggjs/tracer": "4.0.0-beta.36",
|
|
62
|
+
"egg": "4.1.0-beta.36"
|
|
72
63
|
},
|
|
73
|
-
"
|
|
74
|
-
"
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@eggjs/tegg-plugin": "4.0.0-beta.36",
|
|
66
|
+
"egg": "4.1.0-beta.36"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=22.18.0"
|
|
70
|
+
},
|
|
71
|
+
"eggPlugin": {
|
|
72
|
+
"name": "teggEventbus",
|
|
73
|
+
"dependencies": [
|
|
74
|
+
"tegg"
|
|
75
|
+
]
|
|
75
76
|
},
|
|
76
|
-
"main": "./dist/index.js",
|
|
77
|
-
"module": "./dist/index.js",
|
|
78
|
-
"types": "./dist/index.d.ts",
|
|
79
77
|
"scripts": {
|
|
80
|
-
"
|
|
81
|
-
"build": "tsdown && npm run clean && tsc -p tsconfig.build.json",
|
|
82
|
-
"typecheck": "tsc --noEmit"
|
|
78
|
+
"typecheck": "tsgo --noEmit"
|
|
83
79
|
}
|
|
84
80
|
}
|