@zeltjs/eventbus 0.8.1 → 0.8.2-canary.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/adaptor-memory/index.cjs +8 -0
- package/dist/adaptor-memory/index.d.cts +2 -0
- package/dist/adaptor-memory-Obg3l9mF.cjs +37 -0
- package/dist/adaptor-redis/index.cjs +65 -0
- package/dist/adaptor-redis/index.d.cts +20 -0
- package/dist/adaptor-redis/index.d.cts.map +1 -0
- package/dist/eventbus.types-kl1yXTK8.d.cts +10 -0
- package/dist/eventbus.types-kl1yXTK8.d.cts.map +1 -0
- package/dist/index-qecFavvB.d.cts +12 -0
- package/dist/index-qecFavvB.d.cts.map +1 -0
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -0
- package/dist/mitt-CVu_Fg1r.cjs +29 -0
- package/package.json +30 -11
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_adaptor_memory = require("../adaptor-memory-Obg3l9mF.cjs");
|
|
3
|
+
Object.defineProperty(exports, "MemoryEventBusAdaptor", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return require_adaptor_memory.MemoryEventBusAdaptor;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const require_mitt = require("./mitt-CVu_Fg1r.cjs");
|
|
2
|
+
let _zeltjs_core = require("@zeltjs/core");
|
|
3
|
+
//#region src/adaptor-memory/memory-event-bus.adaptor.ts
|
|
4
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
}
|
|
10
|
+
var MemoryEventBusAdaptor = class {
|
|
11
|
+
async emit(event, data) {
|
|
12
|
+
this.emitter.emit(event, data);
|
|
13
|
+
}
|
|
14
|
+
on(event, handler) {
|
|
15
|
+
this.emitter.on(event, handler);
|
|
16
|
+
return () => this.emitter.off(event, handler);
|
|
17
|
+
}
|
|
18
|
+
once(event, handler) {
|
|
19
|
+
const wrappedHandler = (data) => {
|
|
20
|
+
unsubscribe();
|
|
21
|
+
handler(data);
|
|
22
|
+
};
|
|
23
|
+
const unsubscribe = this.on(event, wrappedHandler);
|
|
24
|
+
return unsubscribe;
|
|
25
|
+
}
|
|
26
|
+
constructor() {
|
|
27
|
+
this.emitter = require_mitt.mitt_default();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
MemoryEventBusAdaptor = _ts_decorate([(0, _zeltjs_core.Injectable)()], MemoryEventBusAdaptor);
|
|
31
|
+
//#endregion
|
|
32
|
+
Object.defineProperty(exports, "MemoryEventBusAdaptor", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function() {
|
|
35
|
+
return MemoryEventBusAdaptor;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_mitt = require("../mitt-CVu_Fg1r.cjs");
|
|
3
|
+
let _zeltjs_core = require("@zeltjs/core");
|
|
4
|
+
let _zeltjs_redis = require("@zeltjs/redis");
|
|
5
|
+
//#region src/adaptor-redis/redis-event-bus.adaptor.ts
|
|
6
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
7
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11
|
+
}
|
|
12
|
+
function _ts_metadata(k, v) {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14
|
+
}
|
|
15
|
+
var RedisEventBusAdaptor = class {
|
|
16
|
+
async startup() {}
|
|
17
|
+
async shutdown() {
|
|
18
|
+
this.sub.disconnect();
|
|
19
|
+
}
|
|
20
|
+
async emit(event, data) {
|
|
21
|
+
await this.pub.publish(event, JSON.stringify(data));
|
|
22
|
+
}
|
|
23
|
+
on(event, handler) {
|
|
24
|
+
if (!this.subscriptions.has(event)) {
|
|
25
|
+
this.subscriptions.add(event);
|
|
26
|
+
this.sub.subscribe(event);
|
|
27
|
+
}
|
|
28
|
+
this.localEmitter.on(event, handler);
|
|
29
|
+
return () => {
|
|
30
|
+
this.localEmitter.off(event, handler);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
once(event, handler) {
|
|
34
|
+
const wrappedHandler = (data) => {
|
|
35
|
+
unsubscribe();
|
|
36
|
+
handler(data);
|
|
37
|
+
};
|
|
38
|
+
const unsubscribe = this.on(event, wrappedHandler);
|
|
39
|
+
return unsubscribe;
|
|
40
|
+
}
|
|
41
|
+
constructor(redis = (0, _zeltjs_core.inject)(_zeltjs_redis.RedisService), lifecycle = (0, _zeltjs_core.inject)(_zeltjs_core.LifecycleManager)) {
|
|
42
|
+
this.localEmitter = require_mitt.mitt_default();
|
|
43
|
+
this.subscriptions = /* @__PURE__ */ new Set();
|
|
44
|
+
this.pub = redis.client;
|
|
45
|
+
this.sub = redis.client.duplicate();
|
|
46
|
+
lifecycle.register(this);
|
|
47
|
+
this.sub.on("message", (channel, message) => {
|
|
48
|
+
if (!this.subscriptions.has(channel)) return;
|
|
49
|
+
const data = JSON.parse(message);
|
|
50
|
+
this.localEmitter.emit(channel, data);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
RedisEventBusAdaptor = _ts_decorate([
|
|
55
|
+
(0, _zeltjs_core.Injectable)(),
|
|
56
|
+
_ts_metadata("design:type", Function),
|
|
57
|
+
_ts_metadata("design:paramtypes", [void 0, void 0])
|
|
58
|
+
], RedisEventBusAdaptor);
|
|
59
|
+
//#endregion
|
|
60
|
+
Object.defineProperty(exports, "RedisEventBusAdaptor", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function() {
|
|
63
|
+
return RedisEventBusAdaptor;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { n as EventBusSchema, t as EventBusAdaptor } from "../eventbus.types-kl1yXTK8.cjs";
|
|
2
|
+
import { Lifecycle, LifecycleManager } from "@zeltjs/core";
|
|
3
|
+
import { RedisService } from "@zeltjs/redis";
|
|
4
|
+
|
|
5
|
+
//#region src/adaptor-redis/redis-event-bus.adaptor.d.ts
|
|
6
|
+
declare class RedisEventBusAdaptor implements EventBusAdaptor, Lifecycle {
|
|
7
|
+
private readonly pub;
|
|
8
|
+
private readonly sub;
|
|
9
|
+
private readonly localEmitter;
|
|
10
|
+
private readonly subscriptions;
|
|
11
|
+
constructor(redis?: RedisService, lifecycle?: LifecycleManager);
|
|
12
|
+
startup(): Promise<void>;
|
|
13
|
+
shutdown(): Promise<void>;
|
|
14
|
+
emit<K extends string & keyof EventBusSchema>(event: K, data: EventBusSchema[K]): Promise<void>;
|
|
15
|
+
on<K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
|
|
16
|
+
once<K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { RedisEventBusAdaptor };
|
|
20
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/adaptor-redis/redis-event-bus.adaptor.ts"],"mappings":";;;;;cASa,oBAAA,YAAgC,eAAA,EAAiB,SAAA;EAAA,iBAC3C,GAAA;EAAA,iBACA,GAAA;EAAA,iBACA,YAAA;EAAA,iBACA,aAAA;cAEL,KAAA,GAAK,YAAA,EAAyB,SAAA,GAAS,gBAAA;EAY7C,OAAA,CAAA,GAAW,OAAA;EAEX,QAAA,CAAA,GAAY,OAAA;EAIZ,IAAA,0BAA8B,cAAA,CAAA,CAClC,KAAA,EAAO,CAAA,EACP,IAAA,EAAM,cAAA,CAAe,CAAA,IACpB,OAAA;EAIH,EAAA,0BAA4B,cAAA,CAAA,CAC1B,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;EAajC,IAAA,0BAA8B,cAAA,CAAA,CAC5B,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;AAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/eventbus.types.d.ts
|
|
2
|
+
interface EventBusSchema extends Record<string, unknown> {}
|
|
3
|
+
interface EventBusAdaptor {
|
|
4
|
+
emit<K extends string & keyof EventBusSchema>(event: K, data: EventBusSchema[K]): Promise<void>;
|
|
5
|
+
on<K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
|
|
6
|
+
once<K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { EventBusSchema as n, EventBusAdaptor as t };
|
|
10
|
+
//# sourceMappingURL=eventbus.types-kl1yXTK8.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventbus.types-kl1yXTK8.d.cts","names":[],"sources":["../src/eventbus.types.ts"],"mappings":";UACiB,cAAA,SAAuB,MAAA;AAAA,UAEvB,eAAA;EACf,IAAA,0BAA8B,cAAA,EAAgB,KAAA,EAAO,CAAA,EAAG,IAAA,EAAM,cAAA,CAAe,CAAA,IAAK,OAAA;EAClF,EAAA,0BAA4B,cAAA,EAC1B,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;EAEjC,IAAA,0BAA8B,cAAA,EAC5B,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;AAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { n as EventBusSchema, t as EventBusAdaptor } from "./eventbus.types-kl1yXTK8.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/adaptor-memory/memory-event-bus.adaptor.d.ts
|
|
4
|
+
declare class MemoryEventBusAdaptor implements EventBusAdaptor {
|
|
5
|
+
private readonly emitter;
|
|
6
|
+
emit<K extends string & keyof EventBusSchema>(event: K, data: EventBusSchema[K]): Promise<void>;
|
|
7
|
+
on<K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
|
|
8
|
+
once<K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { MemoryEventBusAdaptor as t };
|
|
12
|
+
//# sourceMappingURL=index-qecFavvB.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-qecFavvB.d.cts","names":[],"sources":["../src/adaptor-memory/memory-event-bus.adaptor.ts"],"mappings":";;;cAMa,qBAAA,YAAiC,eAAA;EAAA,iBAC3B,OAAA;EAEX,IAAA,0BAA8B,cAAA,CAAA,CAClC,KAAA,EAAO,CAAA,EACP,IAAA,EAAM,cAAA,CAAe,CAAA,IACpB,OAAA;EAIH,EAAA,0BAA4B,cAAA,CAAA,CAC1B,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;EAMjC,IAAA,0BAA8B,cAAA,CAAA,CAC5B,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;AAAA"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_adaptor_memory = require("./adaptor-memory-Obg3l9mF.cjs");
|
|
3
|
+
//#region src/eventbus.feature.ts
|
|
4
|
+
const eventbus = (opts) => ({
|
|
5
|
+
key: "eventbus",
|
|
6
|
+
featureClasses: () => [opts.adaptor, ...opts.handlers ?? []],
|
|
7
|
+
staticCapabilities: () => ({}),
|
|
8
|
+
createCapabilities: async (runtime) => {
|
|
9
|
+
for (const handler of opts.handlers ?? []) await runtime.get(handler);
|
|
10
|
+
const adaptor = await runtime.get(opts.adaptor);
|
|
11
|
+
return {
|
|
12
|
+
emit: (event, data) => adaptor.emit(event, data),
|
|
13
|
+
on: (event, handler) => adaptor.on(event, handler),
|
|
14
|
+
once: (event, handler) => adaptor.once(event, handler)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
//#endregion
|
|
19
|
+
Object.defineProperty(exports, "MemoryEventBusAdaptor", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function() {
|
|
22
|
+
return require_adaptor_memory.MemoryEventBusAdaptor;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
exports.eventbus = eventbus;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { n as EventBusSchema, t as EventBusAdaptor } from "./eventbus.types-kl1yXTK8.cjs";
|
|
2
|
+
import { t as MemoryEventBusAdaptor } from "./index-qecFavvB.cjs";
|
|
3
|
+
import { ConfiguredFeature } from "@zeltjs/core";
|
|
4
|
+
|
|
5
|
+
//#region src/eventbus.feature.d.ts
|
|
6
|
+
type EventBusHandlerClass = new (...args: never[]) => object;
|
|
7
|
+
type EventBusOptions = {
|
|
8
|
+
readonly adaptor: new (...args: never[]) => EventBusAdaptor;
|
|
9
|
+
readonly handlers?: readonly EventBusHandlerClass[];
|
|
10
|
+
};
|
|
11
|
+
type EventBusCapabilities = {
|
|
12
|
+
readonly emit: <K extends string & keyof EventBusSchema>(event: K, data: EventBusSchema[K]) => Promise<void>;
|
|
13
|
+
readonly on: <K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void) => () => void;
|
|
14
|
+
readonly once: <K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void) => () => void;
|
|
15
|
+
};
|
|
16
|
+
declare const eventbus: (opts: EventBusOptions) => ConfiguredFeature<"eventbus", EventBusCapabilities>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { type EventBusAdaptor, type EventBusCapabilities, type EventBusSchema, MemoryEventBusAdaptor, eventbus };
|
|
19
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/eventbus.feature.ts"],"mappings":";;;;;KAIK,oBAAA,WAA+B,IAAA;AAAA,KAE/B,eAAA;EAAA,SACM,OAAA,UAAiB,IAAA,cAAkB,eAAA;EAAA,SACnC,QAAA,YAAoB,oBAAA;AAAA;AAAA,KAGnB,oBAAA;EAAA,SACD,IAAA,4BAAgC,cAAA,EACvC,KAAA,EAAO,CAAA,EACP,IAAA,EAAM,cAAA,CAAe,CAAA,MAClB,OAAA;EAAA,SACI,EAAA,4BAA8B,cAAA,EACrC,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;EAAA,SAExB,IAAA,4BAAgC,cAAA,EACvC,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;AAAA;AAAA,cAItB,QAAA,GACX,IAAA,EAAM,eAAA,KACL,iBAAA,aAA8B,oBAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import { n as EventBusSchema, t as EventBusAdaptor } from "./eventbus.types-Cn8xuI2B.js";
|
|
2
2
|
import { t as MemoryEventBusAdaptor } from "./index-Buq5DkB1.js";
|
|
3
|
-
|
|
3
|
+
import { ConfiguredFeature } from "@zeltjs/core";
|
|
4
|
+
|
|
5
|
+
//#region src/eventbus.feature.d.ts
|
|
6
|
+
type EventBusHandlerClass = new (...args: never[]) => object;
|
|
7
|
+
type EventBusOptions = {
|
|
8
|
+
readonly adaptor: new (...args: never[]) => EventBusAdaptor;
|
|
9
|
+
readonly handlers?: readonly EventBusHandlerClass[];
|
|
10
|
+
};
|
|
11
|
+
type EventBusCapabilities = {
|
|
12
|
+
readonly emit: <K extends string & keyof EventBusSchema>(event: K, data: EventBusSchema[K]) => Promise<void>;
|
|
13
|
+
readonly on: <K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void) => () => void;
|
|
14
|
+
readonly once: <K extends string & keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void) => () => void;
|
|
15
|
+
};
|
|
16
|
+
declare const eventbus: (opts: EventBusOptions) => ConfiguredFeature<"eventbus", EventBusCapabilities>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { type EventBusAdaptor, type EventBusCapabilities, type EventBusSchema, MemoryEventBusAdaptor, eventbus };
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/eventbus.feature.ts"],"mappings":";;;;;KAIK,oBAAA,WAA+B,IAAA;AAAA,KAE/B,eAAA;EAAA,SACM,OAAA,UAAiB,IAAA,cAAkB,eAAA;EAAA,SACnC,QAAA,YAAoB,oBAAA;AAAA;AAAA,KAGnB,oBAAA;EAAA,SACD,IAAA,4BAAgC,cAAA,EACvC,KAAA,EAAO,CAAA,EACP,IAAA,EAAM,cAAA,CAAe,CAAA,MAClB,OAAA;EAAA,SACI,EAAA,4BAA8B,cAAA,EACrC,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;EAAA,SAExB,IAAA,4BAAgC,cAAA,EACvC,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;AAAA;AAAA,cAItB,QAAA,GACX,IAAA,EAAM,eAAA,KACL,iBAAA,aAA8B,oBAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
1
|
import { t as MemoryEventBusAdaptor } from "./adaptor-memory-BG1Xyr7_.js";
|
|
2
|
-
|
|
2
|
+
//#region src/eventbus.feature.ts
|
|
3
|
+
const eventbus = (opts) => ({
|
|
4
|
+
key: "eventbus",
|
|
5
|
+
featureClasses: () => [opts.adaptor, ...opts.handlers ?? []],
|
|
6
|
+
staticCapabilities: () => ({}),
|
|
7
|
+
createCapabilities: async (runtime) => {
|
|
8
|
+
for (const handler of opts.handlers ?? []) await runtime.get(handler);
|
|
9
|
+
const adaptor = await runtime.get(opts.adaptor);
|
|
10
|
+
return {
|
|
11
|
+
emit: (event, data) => adaptor.emit(event, data),
|
|
12
|
+
on: (event, handler) => adaptor.on(event, handler),
|
|
13
|
+
once: (event, handler) => adaptor.once(event, handler)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
//#endregion
|
|
18
|
+
export { MemoryEventBusAdaptor, eventbus };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["eventbus","opts","key","featureClasses","adaptor","handlers","staticCapabilities","createCapabilities","runtime","handler","get","emit","event","data","on","once"],"sources":["../src/eventbus.feature.ts"],"sourcesContent":["import type { ConfiguredFeature } from '@zeltjs/core';\n\nimport type { EventBusAdaptor, EventBusSchema } from './eventbus.types';\n\ntype EventBusHandlerClass = new (...args: never[]) => object;\n\ntype EventBusOptions = {\n readonly adaptor: new (...args: never[]) => EventBusAdaptor;\n readonly handlers?: readonly EventBusHandlerClass[];\n};\n\nexport type EventBusCapabilities = {\n readonly emit: <K extends string & keyof EventBusSchema>(\n event: K,\n data: EventBusSchema[K],\n ) => Promise<void>;\n readonly on: <K extends string & keyof EventBusSchema>(\n event: K,\n handler: (data: EventBusSchema[K]) => void,\n ) => () => void;\n readonly once: <K extends string & keyof EventBusSchema>(\n event: K,\n handler: (data: EventBusSchema[K]) => void,\n ) => () => void;\n};\n\nexport const eventbus = (\n opts: EventBusOptions,\n): ConfiguredFeature<'eventbus', EventBusCapabilities> => ({\n key: 'eventbus',\n featureClasses: () => [opts.adaptor, ...(opts.handlers ?? [])],\n staticCapabilities: () => ({}),\n createCapabilities: async (runtime) => {\n for (const handler of opts.handlers ?? []) {\n await runtime.get(handler);\n }\n\n const adaptor = await runtime.get(opts.adaptor);\n return {\n emit: (event, data) => adaptor.emit(event, data),\n on: (event, handler) => adaptor.on(event, handler),\n once: (event, handler) => adaptor.once(event, handler),\n };\n },\n});\n"],"mappings":";;AA0BA,MAAaA,YACXC,UACyD;CACzDC,KAAK;CACLC,sBAAsB,CAACF,KAAKG,SAAAA,GAAaH,KAAKI,YAAY,EAAE,CAAE;CAC9DC,2BAA2B,EAAC;CAC5BC,oBAAoB,OAAOC,YAAAA;AACzB,OAAK,MAAMC,WAAWR,KAAKI,YAAY,EAAE,CACvC,OAAMG,QAAQE,IAAID,QAAAA;EAGpB,MAAML,UAAU,MAAMI,QAAQE,IAAIT,KAAKG,QAAO;AAC9C,SAAO;GACLO,OAAOC,OAAOC,SAAST,QAAQO,KAAKC,OAAOC,KAAAA;GAC3CC,KAAKF,OAAOH,YAAYL,QAAQU,GAAGF,OAAOH,QAAAA;GAC1CM,OAAOH,OAAOH,YAAYL,QAAQW,KAAKH,OAAOH,QAAAA;GAChD;;CAEJ"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
|
|
2
|
+
function mitt_default(n) {
|
|
3
|
+
return {
|
|
4
|
+
all: n = n || /* @__PURE__ */ new Map(),
|
|
5
|
+
on: function(t, e) {
|
|
6
|
+
var i = n.get(t);
|
|
7
|
+
i ? i.push(e) : n.set(t, [e]);
|
|
8
|
+
},
|
|
9
|
+
off: function(t, e) {
|
|
10
|
+
var i = n.get(t);
|
|
11
|
+
i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : n.set(t, []));
|
|
12
|
+
},
|
|
13
|
+
emit: function(t, e) {
|
|
14
|
+
var i = n.get(t);
|
|
15
|
+
i && i.slice().map(function(n) {
|
|
16
|
+
n(e);
|
|
17
|
+
}), (i = n.get("*")) && i.slice().map(function(n) {
|
|
18
|
+
n(t, e);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
Object.defineProperty(exports, "mitt_default", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function() {
|
|
27
|
+
return mitt_default;
|
|
28
|
+
}
|
|
29
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeltjs/eventbus",
|
|
3
|
-
"version": "0.8.1",
|
|
3
|
+
"version": "0.8.2-canary.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -13,24 +13,42 @@
|
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
|
-
"
|
|
17
|
-
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"types": "./dist/index.d.cts",
|
|
22
|
+
"default": "./dist/index.cjs"
|
|
23
|
+
}
|
|
18
24
|
},
|
|
19
25
|
"./adaptor-memory": {
|
|
20
|
-
"
|
|
21
|
-
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/adaptor-memory/index.d.ts",
|
|
28
|
+
"default": "./dist/adaptor-memory/index.js"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./dist/adaptor-memory/index.d.cts",
|
|
32
|
+
"default": "./dist/adaptor-memory/index.cjs"
|
|
33
|
+
}
|
|
22
34
|
},
|
|
23
35
|
"./adaptor-redis": {
|
|
24
|
-
"
|
|
25
|
-
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./dist/adaptor-redis/index.d.ts",
|
|
38
|
+
"default": "./dist/adaptor-redis/index.js"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./dist/adaptor-redis/index.d.cts",
|
|
42
|
+
"default": "./dist/adaptor-redis/index.cjs"
|
|
43
|
+
}
|
|
26
44
|
}
|
|
27
45
|
},
|
|
28
46
|
"files": [
|
|
29
47
|
"dist"
|
|
30
48
|
],
|
|
31
49
|
"peerDependencies": {
|
|
32
|
-
"@zeltjs/
|
|
33
|
-
"@zeltjs/
|
|
50
|
+
"@zeltjs/redis": "0.8.2-canary.1",
|
|
51
|
+
"@zeltjs/core": "0.8.2-canary.1"
|
|
34
52
|
},
|
|
35
53
|
"peerDependenciesMeta": {
|
|
36
54
|
"@zeltjs/redis": {
|
|
@@ -41,12 +59,13 @@
|
|
|
41
59
|
"@types/node": "22.19.17",
|
|
42
60
|
"ioredis": "5.10.1",
|
|
43
61
|
"mitt": "3.0.1",
|
|
44
|
-
"@zeltjs/core": "0.8.1",
|
|
45
|
-
"@zeltjs/redis": "0.8.1"
|
|
62
|
+
"@zeltjs/core": "0.8.2-canary.1",
|
|
63
|
+
"@zeltjs/redis": "0.8.2-canary.1"
|
|
46
64
|
},
|
|
47
65
|
"volta": {
|
|
48
66
|
"extends": "../../package.json"
|
|
49
67
|
},
|
|
68
|
+
"main": "./dist/index.cjs",
|
|
50
69
|
"scripts": {
|
|
51
70
|
"build": "tsdown",
|
|
52
71
|
"test": "vitest run",
|