@eggjs/tegg-eventbus-plugin 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/EggContextEventBus-0qWMQczd.d.ts +15 -0
- package/dist/EggContextEventBus-ByOmx8Y1.js +39 -0
- package/dist/EggEventContext-D9RVawts.js +28 -0
- package/dist/EventHandlerProtoManager-BVGrWszS.d.ts +14 -0
- package/dist/EventHandlerProtoManager-Bmih15Cg.js +30 -0
- package/dist/EventbusLoadUnitHook-CfXEHGf5.js +22 -0
- package/dist/EventbusProtoHook-Bd7ueHTv.js +17 -0
- package/dist/app/extend/application.unittest.d.ts +1 -21
- package/dist/app/extend/application.unittest.js +1 -17
- package/dist/app/extend/context.d.ts +2 -15
- package/dist/app/extend/context.js +2 -13
- package/dist/app.js +4 -3
- package/dist/application.unittest-B873w8gY.js +19 -0
- package/dist/application.unittest-DWoCWkVg.d.ts +22 -0
- package/dist/context-8tXiFqe9.js +15 -0
- package/dist/context-PVU6qyS4.d.ts +16 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/lib/EggContextEventBus.d.ts +1 -14
- package/dist/lib/EggContextEventBus.js +1 -37
- package/dist/lib/EggEventContext.js +1 -26
- package/dist/lib/EventHandlerProtoManager.d.ts +1 -13
- package/dist/lib/EventHandlerProtoManager.js +2 -28
- package/dist/lib/EventbusLoadUnitHook.js +1 -20
- package/dist/lib/EventbusProtoHook.d.ts +1 -1
- package/dist/lib/EventbusProtoHook.js +3 -16
- package/dist/types-CghFPt2v.d.ts +1 -0
- package/dist/types-Ct3xXZX7.js +3 -0
- package/dist/types.d.ts +4 -1
- package/dist/types.js +4 -3
- package/package.json +10 -10
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Context } from "egg";
|
|
2
|
+
import { Arguments, ContextEventBus, Events } from "@eggjs/tegg";
|
|
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;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { EggContextEventBus };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "@eggjs/tegg-metadata";
|
|
2
|
+
import { SingletonEventBus } from "@eggjs/tegg-eventbus-runtime";
|
|
3
|
+
import { CORK_ID, PrototypeUtil } from "@eggjs/tegg";
|
|
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 };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Application, Context } from "egg";
|
|
2
|
+
import "@eggjs/tegg-eventbus-runtime";
|
|
3
|
+
import { IdenticalUtil } from "@eggjs/tegg";
|
|
4
|
+
import { AbstractEggContext } from "@eggjs/tegg-runtime";
|
|
5
|
+
import { EGG_CONTEXT, TEGG_CONTEXT } from "@eggjs/egg-module-common";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/EggEventContext.ts
|
|
8
|
+
function eggEventContextFactory(AbstractEggContextClazz, identicalUtil) {
|
|
9
|
+
class EggEventContext extends AbstractEggContextClazz {
|
|
10
|
+
id;
|
|
11
|
+
constructor(context) {
|
|
12
|
+
super();
|
|
13
|
+
this.set(EGG_CONTEXT, context);
|
|
14
|
+
context[TEGG_CONTEXT] = this;
|
|
15
|
+
this.id = identicalUtil.createContextId(context.tracer?.traceId);
|
|
16
|
+
}
|
|
17
|
+
static createContextFactory(app) {
|
|
18
|
+
return () => {
|
|
19
|
+
const eggCtx = app.createAnonymousContext();
|
|
20
|
+
return new EggEventContext(eggCtx);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return EggEventContext.createContextFactory;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { eggEventContextFactory };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Application } from "egg";
|
|
2
|
+
import { EggPrototype } from "@eggjs/tegg-metadata";
|
|
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[];
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { EventHandlerProtoManager };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { eggEventContextFactory } from "./EggEventContext-D9RVawts.js";
|
|
2
|
+
import { Application } from "egg";
|
|
3
|
+
import "@eggjs/tegg-metadata";
|
|
4
|
+
import { EventContextFactory, EventHandlerFactory } from "@eggjs/tegg-eventbus-runtime";
|
|
5
|
+
import { EVENT_NAME } from "@eggjs/tegg";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/EventHandlerProtoManager.ts
|
|
8
|
+
var EventHandlerProtoManager = class {
|
|
9
|
+
protos = /* @__PURE__ */ new Set();
|
|
10
|
+
app;
|
|
11
|
+
constructor(app) {
|
|
12
|
+
this.app = app;
|
|
13
|
+
}
|
|
14
|
+
addProto(proto) {
|
|
15
|
+
this.protos.add(proto);
|
|
16
|
+
}
|
|
17
|
+
async register() {
|
|
18
|
+
const eventHandlerFactory = await this.app.getEggObject(EventHandlerFactory);
|
|
19
|
+
for (const proto of this.protos) (proto.getMetaData(EVENT_NAME) ?? []).forEach((event) => eventHandlerFactory.registerHandler(event, proto));
|
|
20
|
+
const eventFactory = await this.app.getEggObject(EventContextFactory);
|
|
21
|
+
const createContextFactory = eggEventContextFactory(this.app.abstractEggContext, this.app.identicalUtil);
|
|
22
|
+
eventFactory.registerContextCreator(createContextFactory(this.app));
|
|
23
|
+
}
|
|
24
|
+
getProtos() {
|
|
25
|
+
return Array.from(this.protos);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { EventHandlerProtoManager };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EggLoadUnitType, EggPrototypeCreatorFactory, EggPrototypeFactory } from "@eggjs/tegg-metadata";
|
|
2
|
+
import { EventContextFactory, EventHandlerFactory, SingletonEventBus } from "@eggjs/tegg-eventbus-runtime";
|
|
3
|
+
import { EggQualifierAttribute, EggType, QualifierUtil } from "@eggjs/tegg";
|
|
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 };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "@eggjs/tegg-metadata";
|
|
2
|
+
import { EVENT_NAME } from "@eggjs/tegg";
|
|
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 };
|
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EventBus, EventWaiter } from "@eggjs/tegg";
|
|
3
|
-
|
|
4
|
-
//#region src/app/extend/application.unittest.d.ts
|
|
5
|
-
declare class EventBusApplicationUnittest extends Application {
|
|
6
|
-
getEventbus(): Promise<EventBus>;
|
|
7
|
-
getEventWaiter(): Promise<EventWaiter>;
|
|
8
|
-
}
|
|
9
|
-
declare module 'egg' {
|
|
10
|
-
interface Application {
|
|
11
|
-
/**
|
|
12
|
-
* Get the event bus, only for unittest
|
|
13
|
-
*/
|
|
14
|
-
getEventbus(): Promise<EventBus>;
|
|
15
|
-
/**
|
|
16
|
-
* Get the event waiter, only for unittest
|
|
17
|
-
*/
|
|
18
|
-
getEventWaiter(): Promise<EventWaiter>;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
1
|
+
import { EventBusApplicationUnittest } from "../../application.unittest-DWoCWkVg.js";
|
|
22
2
|
export { EventBusApplicationUnittest as default };
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "@eggjs/tegg-metadata";
|
|
3
|
-
import { SingletonEventBus } from "@eggjs/tegg-eventbus-runtime";
|
|
4
|
-
import { PrototypeUtil } from "@eggjs/tegg";
|
|
1
|
+
import { EventBusApplicationUnittest } from "../../application.unittest-B873w8gY.js";
|
|
5
2
|
|
|
6
|
-
//#region src/app/extend/application.unittest.ts
|
|
7
|
-
var EventBusApplicationUnittest = class extends Application {
|
|
8
|
-
async getEventbus() {
|
|
9
|
-
const proto = PrototypeUtil.getClazzProto(SingletonEventBus);
|
|
10
|
-
return (await this.eggContainerFactory.getOrCreateEggObject(proto, proto.name)).obj;
|
|
11
|
-
}
|
|
12
|
-
async getEventWaiter() {
|
|
13
|
-
const proto = PrototypeUtil.getClazzProto(SingletonEventBus);
|
|
14
|
-
return (await this.eggContainerFactory.getOrCreateEggObject(proto, proto.name)).obj;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
3
|
export { EventBusApplicationUnittest as default };
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/app/extend/context.d.ts
|
|
5
|
-
declare const EVENT_BUS: unique symbol;
|
|
6
|
-
declare class EventBusContext extends Context {
|
|
7
|
-
[EVENT_BUS]: EggContextEventBus;
|
|
8
|
-
get eventBus(): EggContextEventBus;
|
|
9
|
-
}
|
|
10
|
-
declare module 'egg' {
|
|
11
|
-
interface Context {
|
|
12
|
-
get eventBus(): EggContextEventBus;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
1
|
+
import "../../EggContextEventBus-0qWMQczd.js";
|
|
2
|
+
import { EventBusContext } from "../../context-PVU6qyS4.js";
|
|
16
3
|
export { EventBusContext as default };
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import "../../EggContextEventBus-ByOmx8Y1.js";
|
|
2
|
+
import { EventBusContext } from "../../context-8tXiFqe9.js";
|
|
3
3
|
|
|
4
|
-
//#region src/app/extend/context.ts
|
|
5
|
-
const EVENT_BUS = Symbol.for("context#eventBus");
|
|
6
|
-
var EventBusContext = class extends Context {
|
|
7
|
-
[EVENT_BUS];
|
|
8
|
-
get eventBus() {
|
|
9
|
-
if (!this[EVENT_BUS]) this[EVENT_BUS] = new EggContextEventBus(this);
|
|
10
|
-
return this[EVENT_BUS];
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
4
|
export { EventBusContext as default };
|
package/dist/app.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import "./EggEventContext-D9RVawts.js";
|
|
2
|
+
import { EventHandlerProtoManager } from "./EventHandlerProtoManager-Bmih15Cg.js";
|
|
3
|
+
import { EventbusLoadUnitHook } from "./EventbusLoadUnitHook-CfXEHGf5.js";
|
|
4
|
+
import { EventbusProtoHook } from "./EventbusProtoHook-Bd7ueHTv.js";
|
|
4
5
|
import "egg";
|
|
5
6
|
|
|
6
7
|
//#region src/app.ts
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Application } from "egg";
|
|
2
|
+
import "@eggjs/tegg-metadata";
|
|
3
|
+
import { SingletonEventBus } from "@eggjs/tegg-eventbus-runtime";
|
|
4
|
+
import { PrototypeUtil } from "@eggjs/tegg";
|
|
5
|
+
|
|
6
|
+
//#region src/app/extend/application.unittest.ts
|
|
7
|
+
var EventBusApplicationUnittest = class extends Application {
|
|
8
|
+
async getEventbus() {
|
|
9
|
+
const proto = PrototypeUtil.getClazzProto(SingletonEventBus);
|
|
10
|
+
return (await this.eggContainerFactory.getOrCreateEggObject(proto, proto.name)).obj;
|
|
11
|
+
}
|
|
12
|
+
async getEventWaiter() {
|
|
13
|
+
const proto = PrototypeUtil.getClazzProto(SingletonEventBus);
|
|
14
|
+
return (await this.eggContainerFactory.getOrCreateEggObject(proto, proto.name)).obj;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { EventBusApplicationUnittest };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Application } from "egg";
|
|
2
|
+
import { EventBus, EventWaiter } from "@eggjs/tegg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/application.unittest.d.ts
|
|
5
|
+
declare class EventBusApplicationUnittest extends Application {
|
|
6
|
+
getEventbus(): Promise<EventBus>;
|
|
7
|
+
getEventWaiter(): Promise<EventWaiter>;
|
|
8
|
+
}
|
|
9
|
+
declare module 'egg' {
|
|
10
|
+
interface Application {
|
|
11
|
+
/**
|
|
12
|
+
* Get the event bus, only for unittest
|
|
13
|
+
*/
|
|
14
|
+
getEventbus(): Promise<EventBus>;
|
|
15
|
+
/**
|
|
16
|
+
* Get the event waiter, only for unittest
|
|
17
|
+
*/
|
|
18
|
+
getEventWaiter(): Promise<EventWaiter>;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { EventBusApplicationUnittest };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EggContextEventBus } from "./EggContextEventBus-ByOmx8Y1.js";
|
|
2
|
+
import { Context } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/context.ts
|
|
5
|
+
const EVENT_BUS = Symbol.for("context#eventBus");
|
|
6
|
+
var EventBusContext = class extends Context {
|
|
7
|
+
[EVENT_BUS];
|
|
8
|
+
get eventBus() {
|
|
9
|
+
if (!this[EVENT_BUS]) this[EVENT_BUS] = new EggContextEventBus(this);
|
|
10
|
+
return this[EVENT_BUS];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { EventBusContext };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EggContextEventBus } from "./EggContextEventBus-0qWMQczd.js";
|
|
2
|
+
import { Context } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/context.d.ts
|
|
5
|
+
declare const EVENT_BUS: unique symbol;
|
|
6
|
+
declare class EventBusContext extends Context {
|
|
7
|
+
[EVENT_BUS]: EggContextEventBus;
|
|
8
|
+
get eventBus(): EggContextEventBus;
|
|
9
|
+
}
|
|
10
|
+
declare module 'egg' {
|
|
11
|
+
interface Context {
|
|
12
|
+
get eventBus(): EggContextEventBus;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { EventBusContext };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Arguments, ContextEventBus, Events } from "@eggjs/tegg";
|
|
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;
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
1
|
+
import { EggContextEventBus } from "../EggContextEventBus-0qWMQczd.js";
|
|
15
2
|
export { EggContextEventBus };
|
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import { SingletonEventBus } from "@eggjs/tegg-eventbus-runtime";
|
|
3
|
-
import { CORK_ID, PrototypeUtil } from "@eggjs/tegg";
|
|
4
|
-
import { ContextHandler } from "@eggjs/tegg-runtime";
|
|
5
|
-
import assert from "node:assert/strict";
|
|
1
|
+
import { EggContextEventBus } from "../EggContextEventBus-ByOmx8Y1.js";
|
|
6
2
|
|
|
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
3
|
export { EggContextEventBus };
|
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "@eggjs/tegg-eventbus-runtime";
|
|
3
|
-
import { IdenticalUtil } from "@eggjs/tegg";
|
|
4
|
-
import { AbstractEggContext } from "@eggjs/tegg-runtime";
|
|
5
|
-
import { EGG_CONTEXT, TEGG_CONTEXT } from "@eggjs/egg-module-common";
|
|
1
|
+
import { eggEventContextFactory } from "../EggEventContext-D9RVawts.js";
|
|
6
2
|
|
|
7
|
-
//#region src/lib/EggEventContext.ts
|
|
8
|
-
function eggEventContextFactory(AbstractEggContextClazz, identicalUtil) {
|
|
9
|
-
class EggEventContext extends AbstractEggContextClazz {
|
|
10
|
-
id;
|
|
11
|
-
constructor(context) {
|
|
12
|
-
super();
|
|
13
|
-
this.set(EGG_CONTEXT, context);
|
|
14
|
-
context[TEGG_CONTEXT] = this;
|
|
15
|
-
this.id = identicalUtil.createContextId(context.tracer?.traceId);
|
|
16
|
-
}
|
|
17
|
-
static createContextFactory(app) {
|
|
18
|
-
return () => {
|
|
19
|
-
const eggCtx = app.createAnonymousContext();
|
|
20
|
-
return new EggEventContext(eggCtx);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return EggEventContext.createContextFactory;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
3
|
export { eggEventContextFactory };
|
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EggPrototype } from "@eggjs/tegg-metadata";
|
|
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[];
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
1
|
+
import { EventHandlerProtoManager } from "../EventHandlerProtoManager-BVGrWszS.js";
|
|
14
2
|
export { EventHandlerProtoManager };
|
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import "@eggjs/tegg-metadata";
|
|
4
|
-
import { EventContextFactory, EventHandlerFactory } from "@eggjs/tegg-eventbus-runtime";
|
|
5
|
-
import { EVENT_NAME } from "@eggjs/tegg";
|
|
1
|
+
import "../EggEventContext-D9RVawts.js";
|
|
2
|
+
import { EventHandlerProtoManager } from "../EventHandlerProtoManager-Bmih15Cg.js";
|
|
6
3
|
|
|
7
|
-
//#region src/lib/EventHandlerProtoManager.ts
|
|
8
|
-
var EventHandlerProtoManager = class {
|
|
9
|
-
protos = /* @__PURE__ */ new Set();
|
|
10
|
-
app;
|
|
11
|
-
constructor(app) {
|
|
12
|
-
this.app = app;
|
|
13
|
-
}
|
|
14
|
-
addProto(proto) {
|
|
15
|
-
this.protos.add(proto);
|
|
16
|
-
}
|
|
17
|
-
async register() {
|
|
18
|
-
const eventHandlerFactory = await this.app.getEggObject(EventHandlerFactory);
|
|
19
|
-
for (const proto of this.protos) (proto.getMetaData(EVENT_NAME) ?? []).forEach((event) => eventHandlerFactory.registerHandler(event, proto));
|
|
20
|
-
const eventFactory = await this.app.getEggObject(EventContextFactory);
|
|
21
|
-
const createContextFactory = eggEventContextFactory(this.app.abstractEggContext, this.app.identicalUtil);
|
|
22
|
-
eventFactory.registerContextCreator(createContextFactory(this.app));
|
|
23
|
-
}
|
|
24
|
-
getProtos() {
|
|
25
|
-
return Array.from(this.protos);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
4
|
export { EventHandlerProtoManager };
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EventContextFactory, EventHandlerFactory, SingletonEventBus } from "@eggjs/tegg-eventbus-runtime";
|
|
3
|
-
import { EggQualifierAttribute, EggType, QualifierUtil } from "@eggjs/tegg";
|
|
1
|
+
import { EventbusLoadUnitHook } from "../EventbusLoadUnitHook-CfXEHGf5.js";
|
|
4
2
|
|
|
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
3
|
export { EventbusLoadUnitHook };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventHandlerProtoManager } from "
|
|
1
|
+
import { EventHandlerProtoManager } from "../EventHandlerProtoManager-BVGrWszS.js";
|
|
2
2
|
import { EggPrototype, EggPrototypeLifecycleContext } from "@eggjs/tegg-metadata";
|
|
3
3
|
import { LifecycleHook } from "@eggjs/tegg";
|
|
4
4
|
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import {
|
|
1
|
+
import "../EggEventContext-D9RVawts.js";
|
|
2
|
+
import "../EventHandlerProtoManager-Bmih15Cg.js";
|
|
3
|
+
import { EventbusProtoHook } from "../EventbusProtoHook-Bd7ueHTv.js";
|
|
4
4
|
|
|
5
|
-
//#region src/lib/EventbusProtoHook.ts
|
|
6
|
-
var EventbusProtoHook = class {
|
|
7
|
-
eventHandlerProtoManager;
|
|
8
|
-
constructor(eventHandlerProtoManager) {
|
|
9
|
-
this.eventHandlerProtoManager = eventHandlerProtoManager;
|
|
10
|
-
}
|
|
11
|
-
async postCreate(_ctx, obj) {
|
|
12
|
-
if (!obj.getMetaData(EVENT_NAME)) return;
|
|
13
|
-
this.eventHandlerProtoManager.addProto(obj);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
5
|
export { EventbusProtoHook };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@eggjs/tegg-plugin/types";
|
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
import "
|
|
1
|
+
import "./application.unittest-B873w8gY.js";
|
|
2
|
+
import "./EggContextEventBus-ByOmx8Y1.js";
|
|
3
|
+
import "./context-8tXiFqe9.js";
|
|
4
|
+
import "./types-Ct3xXZX7.js";
|
|
4
5
|
|
|
5
6
|
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/tegg-eventbus-plugin",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"eggPlugin": {
|
|
5
5
|
"name": "eventbusModule",
|
|
6
6
|
"strict": false,
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
"node": ">=22.18.0"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@eggjs/egg-module-common": "4.0.0-beta.
|
|
50
|
-
"@eggjs/tegg": "4.0.0-beta.
|
|
51
|
-
"@eggjs/tegg
|
|
52
|
-
"@eggjs/tegg-runtime": "4.0.0-beta.
|
|
53
|
-
"@eggjs/tegg-
|
|
49
|
+
"@eggjs/egg-module-common": "4.0.0-beta.8",
|
|
50
|
+
"@eggjs/tegg-eventbus-runtime": "4.0.0-beta.8",
|
|
51
|
+
"@eggjs/tegg": "4.0.0-beta.8",
|
|
52
|
+
"@eggjs/tegg-runtime": "4.0.0-beta.8",
|
|
53
|
+
"@eggjs/tegg-metadata": "4.0.0-beta.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"egg": "beta",
|
|
57
|
-
"@eggjs/tegg-plugin": "4.0.0-beta.
|
|
57
|
+
"@eggjs/tegg-plugin": "4.0.0-beta.8"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@eggjs/bin": "beta",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"tsdown": "^0.15.6",
|
|
68
68
|
"typescript": "^5.9.3",
|
|
69
69
|
"unplugin-unused": "^0.5.3",
|
|
70
|
-
"@eggjs/tegg-
|
|
71
|
-
"@eggjs/tegg-
|
|
72
|
-
"@eggjs/tegg-plugin": "4.0.0-beta.
|
|
70
|
+
"@eggjs/tegg-config": "4.0.0-beta.8",
|
|
71
|
+
"@eggjs/tegg-common-util": "4.0.0-beta.8",
|
|
72
|
+
"@eggjs/tegg-plugin": "4.0.0-beta.8"
|
|
73
73
|
},
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public"
|