@zeltjs/eventbus 0.8.0 → 0.8.2-canary.0

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 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
- export { type EventBusAdaptor, type EventBusSchema, MemoryEventBusAdaptor };
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,29 @@
1
1
  import { t as MemoryEventBusAdaptor } from "./adaptor-memory-BG1Xyr7_.js";
2
- export { MemoryEventBusAdaptor };
2
+ //#region src/eventbus.feature.ts
3
+ const eventbus = (opts) => ({
4
+ key: "eventbus",
5
+ bind: (container) => {
6
+ container.bind({
7
+ provide: opts.adaptor,
8
+ useClass: opts.adaptor
9
+ });
10
+ for (const handler of opts.handlers ?? []) container.bind({
11
+ provide: handler,
12
+ useClass: handler
13
+ });
14
+ },
15
+ staticCapabilities: () => ({}),
16
+ createCapabilities: async (runtime) => {
17
+ for (const handler of opts.handlers ?? []) await runtime.get(handler);
18
+ const adaptor = await runtime.get(opts.adaptor);
19
+ return {
20
+ emit: (event, data) => adaptor.emit(event, data),
21
+ on: (event, handler) => adaptor.on(event, handler),
22
+ once: (event, handler) => adaptor.once(event, handler)
23
+ };
24
+ }
25
+ });
26
+ //#endregion
27
+ export { MemoryEventBusAdaptor, eventbus };
28
+
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["eventbus","opts","key","bind","container","provide","adaptor","useClass","handler","handlers","staticCapabilities","createCapabilities","runtime","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 bind: (container) => {\n container.bind({ provide: opts.adaptor, useClass: opts.adaptor });\n for (const handler of opts.handlers ?? []) {\n container.bind({ provide: handler, useClass: handler });\n }\n },\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,OAAOC,cAAAA;AACLA,YAAUD,KAAK;GAAEE,SAASJ,KAAKK;GAASC,UAAUN,KAAKK;GAAQ,CAAA;AAC/D,OAAK,MAAME,WAAWP,KAAKQ,YAAY,EAAE,CACvCL,WAAUD,KAAK;GAAEE,SAASG;GAASD,UAAUC;GAAQ,CAAA;;CAGzDE,2BAA2B,EAAC;CAC5BC,oBAAoB,OAAOC,YAAAA;AACzB,OAAK,MAAMJ,WAAWP,KAAKQ,YAAY,EAAE,CACvC,OAAMG,QAAQC,IAAIL,QAAAA;EAGpB,MAAMF,UAAU,MAAMM,QAAQC,IAAIZ,KAAKK,QAAO;AAC9C,SAAO;GACLQ,OAAOC,OAAOC,SAASV,QAAQQ,KAAKC,OAAOC,KAAAA;GAC3CC,KAAKF,OAAOP,YAAYF,QAAQW,GAAGF,OAAOP,QAAAA;GAC1CU,OAAOH,OAAOP,YAAYF,QAAQY,KAAKH,OAAOP,QAAAA;GAChD;;CAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeltjs/eventbus",
3
- "version": "0.8.0",
3
+ "version": "0.8.2-canary.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,8 +29,8 @@
29
29
  "dist"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@zeltjs/core": "0.8.0",
33
- "@zeltjs/redis": "0.8.0"
32
+ "@zeltjs/core": "0.8.2-canary.0",
33
+ "@zeltjs/redis": "0.8.2-canary.0"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@zeltjs/redis": {
@@ -38,11 +38,12 @@
38
38
  }
39
39
  },
40
40
  "devDependencies": {
41
+ "@needle-di/core": "1.1.2",
41
42
  "@types/node": "22.19.17",
42
43
  "ioredis": "5.10.1",
43
44
  "mitt": "3.0.1",
44
- "@zeltjs/redis": "0.8.0",
45
- "@zeltjs/core": "0.8.0"
45
+ "@zeltjs/core": "0.8.2-canary.0",
46
+ "@zeltjs/redis": "0.8.2-canary.0"
46
47
  },
47
48
  "volta": {
48
49
  "extends": "../../package.json"