@zeltjs/eventbus 0.0.1 → 0.5.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 9wick / Kohei Kido
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,33 @@
1
1
  # @zeltjs/eventbus
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ [![Documentation](https://img.shields.io/badge/docs-zeltjs.com-blue)](https://zeltjs.com)
4
4
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
5
+ Event bus abstraction for Zelt applications.
6
6
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
7
+ **[Read the Documentation](https://zeltjs.com)**
8
8
 
9
- ## Purpose
9
+ ## Installation
10
10
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@zeltjs/eventbus`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
11
+ ```bash
12
+ npm install @zeltjs/eventbus @zeltjs/core
13
+ ```
15
14
 
16
- ## What is OIDC Trusted Publishing?
15
+ ## Usage
17
16
 
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
17
+ ```typescript
18
+ import { MemoryEventBusAdaptor } from '@zeltjs/eventbus';
19
+ import type { EventBusSchema } from '@zeltjs/eventbus';
19
20
 
20
- ## Setup Instructions
21
+ type MyEvents = EventBusSchema<{
22
+ 'user.created': { id: string; name: string };
23
+ 'user.deleted': { id: string };
24
+ }>;
21
25
 
22
- To properly configure OIDC trusted publishing for this package:
26
+ const eventbus = new MemoryEventBusAdaptor<MyEvents>();
23
27
 
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
+ eventbus.on('user.created', (data) => {
29
+ console.log('User created:', data.name);
30
+ });
28
31
 
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
32
+ eventbus.emit('user.created', { id: '1', name: 'Alice' });
33
+ ```
@@ -0,0 +1,2 @@
1
+ import { t as MemoryEventBusAdaptor } from "../index-CmcsSQcu.js";
2
+ export { MemoryEventBusAdaptor };
@@ -0,0 +1,2 @@
1
+ import { t as MemoryEventBusAdaptor } from "../adaptor-memory-_pl2McN_.js";
2
+ export { MemoryEventBusAdaptor };
@@ -0,0 +1,23 @@
1
+ import { EventEmitter } from "node:events";
2
+ import { Injectable } from "@zeltjs/core";
3
+ //#region src/adaptor-memory/memory-event-bus.adaptor.ts
4
+ var MemoryEventBusAdaptor = @Injectable() class {
5
+ constructor() {
6
+ this.emitter = new EventEmitter();
7
+ }
8
+ async emit(event, data) {
9
+ this.emitter.emit(event, data);
10
+ }
11
+ on(event, handler) {
12
+ this.emitter.on(event, handler);
13
+ return () => this.emitter.off(event, handler);
14
+ }
15
+ once(event, handler) {
16
+ this.emitter.once(event, handler);
17
+ return () => this.emitter.off(event, handler);
18
+ }
19
+ };
20
+ //#endregion
21
+ export { MemoryEventBusAdaptor as t };
22
+
23
+ //# sourceMappingURL=adaptor-memory-_pl2McN_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adaptor-memory-_pl2McN_.js","names":[],"sources":["../src/adaptor-memory/memory-event-bus.adaptor.ts"],"sourcesContent":["import { EventEmitter } from 'node:events';\nimport { Injectable } from '@zeltjs/core';\n\nimport type { EventBusAdaptor, EventBusSchema } from '../types';\n\n@Injectable()\nexport class MemoryEventBusAdaptor implements EventBusAdaptor {\n private readonly emitter = new EventEmitter();\n\n async emit<K extends keyof EventBusSchema>(event: K, data: EventBusSchema[K]): Promise<void> {\n this.emitter.emit(event as string, data);\n }\n\n on<K extends keyof EventBusSchema>(\n event: K,\n handler: (data: EventBusSchema[K]) => void,\n ): () => void {\n this.emitter.on(event as string, handler);\n return () => this.emitter.off(event as string, handler);\n }\n\n once<K extends keyof EventBusSchema>(\n event: K,\n handler: (data: EventBusSchema[K]) => void,\n ): () => void {\n this.emitter.once(event as string, handler);\n return () => this.emitter.off(event as string, handler);\n }\n}\n"],"mappings":";;;AAMA,IAAa,wBADb,CAAC,YAAY,CAAb,MAC8D;;iBACjC,IAAI,cAAc;;CAE7C,MAAM,KAAqC,OAAU,MAAwC;AAC3F,OAAK,QAAQ,KAAK,OAAiB,KAAK;;CAG1C,GACE,OACA,SACY;AACZ,OAAK,QAAQ,GAAG,OAAiB,QAAQ;AACzC,eAAa,KAAK,QAAQ,IAAI,OAAiB,QAAQ;;CAGzD,KACE,OACA,SACY;AACZ,OAAK,QAAQ,KAAK,OAAiB,QAAQ;AAC3C,eAAa,KAAK,QAAQ,IAAI,OAAiB,QAAQ"}
@@ -0,0 +1,19 @@
1
+ import { n as EventBusSchema, t as EventBusAdaptor } from "../types-CLqE_rki.js";
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 handlers;
10
+ constructor(redis?: RedisService, lifecycle?: LifecycleManager);
11
+ startup(): Promise<void>;
12
+ shutdown(): Promise<void>;
13
+ emit<K extends keyof EventBusSchema>(event: K, data: EventBusSchema[K]): Promise<void>;
14
+ on<K extends keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
15
+ once<K extends keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
16
+ }
17
+ //#endregion
18
+ export { RedisEventBusAdaptor };
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","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,QAAA;cAEL,KAAA,GAAK,YAAA,EAAyB,SAAA,GAAS,gBAAA;EAe7C,OAAA,CAAA,GAAW,OAAA;EAEX,QAAA,CAAA,GAAY,OAAA;EAIZ,IAAA,iBAAqB,cAAA,CAAA,CAAgB,KAAA,EAAO,CAAA,EAAG,IAAA,EAAM,cAAA,CAAe,CAAA,IAAK,OAAA;EAI/E,EAAA,iBAAmB,cAAA,CAAA,CACjB,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;EAoBjC,IAAA,iBAAqB,cAAA,CAAA,CACnB,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;AAAA"}
@@ -0,0 +1,53 @@
1
+ import { LifecycleManager, inject } from "@zeltjs/core";
2
+ import { RedisService } from "@zeltjs/redis";
3
+ //#region src/adaptor-redis/redis-event-bus.adaptor.ts
4
+ var RedisEventBusAdaptor = class {
5
+ constructor(redis = inject(RedisService), lifecycle = inject(LifecycleManager)) {
6
+ this.handlers = /* @__PURE__ */ new Map();
7
+ this.pub = redis.client;
8
+ this.sub = redis.client.duplicate();
9
+ lifecycle.register(this);
10
+ this.sub.on("message", (channel, message) => {
11
+ const eventHandlers = this.handlers.get(channel);
12
+ if (!eventHandlers) return;
13
+ const data = JSON.parse(message);
14
+ for (const handler of eventHandlers) handler(data);
15
+ });
16
+ }
17
+ async startup() {}
18
+ async shutdown() {
19
+ this.sub.disconnect();
20
+ }
21
+ async emit(event, data) {
22
+ await this.pub.publish(event, JSON.stringify(data));
23
+ }
24
+ on(event, handler) {
25
+ const channel = event;
26
+ let handlers = this.handlers.get(channel);
27
+ if (!handlers) {
28
+ handlers = /* @__PURE__ */ new Set();
29
+ this.handlers.set(channel, handlers);
30
+ this.sub.subscribe(channel);
31
+ }
32
+ handlers.add(handler);
33
+ return () => {
34
+ handlers.delete(handler);
35
+ if (handlers.size === 0) {
36
+ this.handlers.delete(channel);
37
+ this.sub.unsubscribe(channel);
38
+ }
39
+ };
40
+ }
41
+ once(event, handler) {
42
+ const wrappedHandler = (data) => {
43
+ unsubscribe();
44
+ handler(data);
45
+ };
46
+ const unsubscribe = this.on(event, wrappedHandler);
47
+ return unsubscribe;
48
+ }
49
+ };
50
+ //#endregion
51
+ export { RedisEventBusAdaptor };
52
+
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/adaptor-redis/redis-event-bus.adaptor.ts"],"sourcesContent":["import type { Lifecycle } from '@zeltjs/core';\nimport { inject, LifecycleManager } from '@zeltjs/core';\nimport { RedisService } from '@zeltjs/redis';\nimport type Redis from 'ioredis';\n\nimport type { EventBusAdaptor, EventBusSchema } from '../types';\n\ntype Handler = (data: unknown) => void;\n\nexport class RedisEventBusAdaptor implements EventBusAdaptor, Lifecycle {\n private readonly pub: Redis;\n private readonly sub: Redis;\n private readonly handlers = new Map<string, Set<Handler>>();\n\n constructor(redis = inject(RedisService), lifecycle = inject(LifecycleManager)) {\n this.pub = redis.client;\n this.sub = redis.client.duplicate();\n lifecycle.register(this);\n\n this.sub.on('message', (channel: string, message: string) => {\n const eventHandlers = this.handlers.get(channel);\n if (!eventHandlers) return;\n const data: unknown = JSON.parse(message);\n for (const handler of eventHandlers) {\n handler(data);\n }\n });\n }\n\n async startup(): Promise<void> {}\n\n async shutdown(): Promise<void> {\n this.sub.disconnect();\n }\n\n async emit<K extends keyof EventBusSchema>(event: K, data: EventBusSchema[K]): Promise<void> {\n await this.pub.publish(event as string, JSON.stringify(data));\n }\n\n on<K extends keyof EventBusSchema>(\n event: K,\n handler: (data: EventBusSchema[K]) => void,\n ): () => void {\n const channel = event as string;\n let handlers = this.handlers.get(channel);\n if (!handlers) {\n handlers = new Set();\n this.handlers.set(channel, handlers);\n void this.sub.subscribe(channel);\n }\n handlers.add(handler as Handler);\n\n return () => {\n handlers.delete(handler as Handler);\n if (handlers.size === 0) {\n this.handlers.delete(channel);\n void this.sub.unsubscribe(channel);\n }\n };\n }\n\n once<K extends keyof EventBusSchema>(\n event: K,\n handler: (data: EventBusSchema[K]) => void,\n ): () => void {\n const wrappedHandler = (data: EventBusSchema[K]) => {\n unsubscribe();\n handler(data);\n };\n const unsubscribe = this.on(event, wrappedHandler);\n return unsubscribe;\n }\n}\n"],"mappings":";;;AASA,IAAa,uBAAb,MAAwE;CAKtE,YAAY,QAAQ,OAAO,aAAa,EAAE,YAAY,OAAO,iBAAiB,EAAE;kCAFpD,IAAI,KAA2B;AAGzD,OAAK,MAAM,MAAM;AACjB,OAAK,MAAM,MAAM,OAAO,WAAW;AACnC,YAAU,SAAS,KAAK;AAExB,OAAK,IAAI,GAAG,YAAY,SAAiB,YAAoB;GAC3D,MAAM,gBAAgB,KAAK,SAAS,IAAI,QAAQ;AAChD,OAAI,CAAC,cAAe;GACpB,MAAM,OAAgB,KAAK,MAAM,QAAQ;AACzC,QAAK,MAAM,WAAW,cACpB,SAAQ,KAAK;IAEf;;CAGJ,MAAM,UAAyB;CAE/B,MAAM,WAA0B;AAC9B,OAAK,IAAI,YAAY;;CAGvB,MAAM,KAAqC,OAAU,MAAwC;AAC3F,QAAM,KAAK,IAAI,QAAQ,OAAiB,KAAK,UAAU,KAAK,CAAC;;CAG/D,GACE,OACA,SACY;EACZ,MAAM,UAAU;EAChB,IAAI,WAAW,KAAK,SAAS,IAAI,QAAQ;AACzC,MAAI,CAAC,UAAU;AACb,8BAAW,IAAI,KAAK;AACpB,QAAK,SAAS,IAAI,SAAS,SAAS;AAC/B,QAAK,IAAI,UAAU,QAAQ;;AAElC,WAAS,IAAI,QAAmB;AAEhC,eAAa;AACX,YAAS,OAAO,QAAmB;AACnC,OAAI,SAAS,SAAS,GAAG;AACvB,SAAK,SAAS,OAAO,QAAQ;AACxB,SAAK,IAAI,YAAY,QAAQ;;;;CAKxC,KACE,OACA,SACY;EACZ,MAAM,kBAAkB,SAA4B;AAClD,gBAAa;AACb,WAAQ,KAAK;;EAEf,MAAM,cAAc,KAAK,GAAG,OAAO,eAAe;AAClD,SAAO"}
@@ -0,0 +1,12 @@
1
+ import { n as EventBusSchema, t as EventBusAdaptor } from "./types-CLqE_rki.js";
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 keyof EventBusSchema>(event: K, data: EventBusSchema[K]): Promise<void>;
7
+ on<K extends keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
8
+ once<K extends keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
9
+ }
10
+ //#endregion
11
+ export { MemoryEventBusAdaptor as t };
12
+ //# sourceMappingURL=index-CmcsSQcu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CmcsSQcu.d.ts","names":[],"sources":["../src/adaptor-memory/memory-event-bus.adaptor.ts"],"mappings":";;;cAMa,qBAAA,YAAiC,eAAA;EAAA,iBAC3B,OAAA;EAEX,IAAA,iBAAqB,cAAA,CAAA,CAAgB,KAAA,EAAO,CAAA,EAAG,IAAA,EAAM,cAAA,CAAe,CAAA,IAAK,OAAA;EAI/E,EAAA,iBAAmB,cAAA,CAAA,CACjB,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;EAMjC,IAAA,iBAAqB,cAAA,CAAA,CACnB,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;AAAA"}
@@ -0,0 +1,3 @@
1
+ import { n as EventBusSchema, t as EventBusAdaptor } from "./types-CLqE_rki.js";
2
+ import { t as MemoryEventBusAdaptor } from "./index-CmcsSQcu.js";
3
+ export { type EventBusAdaptor, type EventBusSchema, MemoryEventBusAdaptor };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { t as MemoryEventBusAdaptor } from "./adaptor-memory-_pl2McN_.js";
2
+ export { MemoryEventBusAdaptor };
@@ -0,0 +1,10 @@
1
+ //#region src/types.d.ts
2
+ interface EventBusSchema {}
3
+ interface EventBusAdaptor {
4
+ emit<K extends keyof EventBusSchema>(event: K, data: EventBusSchema[K]): Promise<void>;
5
+ on<K extends keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
6
+ once<K extends keyof EventBusSchema>(event: K, handler: (data: EventBusSchema[K]) => void): () => void;
7
+ }
8
+ //#endregion
9
+ export { EventBusSchema as n, EventBusAdaptor as t };
10
+ //# sourceMappingURL=types-CLqE_rki.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CLqE_rki.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";UACiB,cAAA;AAAA,UAEA,eAAA;EACf,IAAA,iBAAqB,cAAA,EAAgB,KAAA,EAAO,CAAA,EAAG,IAAA,EAAM,cAAA,CAAe,CAAA,IAAK,OAAA;EACzE,EAAA,iBAAmB,cAAA,EACjB,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;EAEjC,IAAA,iBAAqB,cAAA,EACnB,KAAA,EAAO,CAAA,EACP,OAAA,GAAU,IAAA,EAAM,cAAA,CAAe,CAAA;AAAA"}
package/package.json CHANGED
@@ -1,10 +1,54 @@
1
1
  {
2
2
  "name": "@zeltjs/eventbus",
3
- "version": "0.0.1",
4
- "description": "OIDC trusted publishing setup package for @zeltjs/eventbus",
5
- "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
10
- }
3
+ "version": "0.5.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/zeltjs/zelt.git",
9
+ "directory": "packages/eventbus"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./adaptor-memory": {
20
+ "types": "./dist/adaptor-memory/index.d.ts",
21
+ "import": "./dist/adaptor-memory/index.js"
22
+ },
23
+ "./adaptor-redis": {
24
+ "types": "./dist/adaptor-redis/index.d.ts",
25
+ "import": "./dist/adaptor-redis/index.js"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "peerDependencies": {
32
+ "@zeltjs/core": "0.5.0",
33
+ "@zeltjs/redis": "0.5.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@zeltjs/redis": {
37
+ "optional": true
38
+ }
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "22.19.17",
42
+ "ioredis": "5.10.1",
43
+ "@zeltjs/core": "0.5.0",
44
+ "@zeltjs/redis": "0.5.0"
45
+ },
46
+ "volta": {
47
+ "extends": "../../package.json"
48
+ },
49
+ "scripts": {
50
+ "build": "tsdown",
51
+ "test": "vitest run",
52
+ "typecheck": "tsc -b"
53
+ }
54
+ }