{"_id":"@alekstar79/reactive-event-system","_rev":"2-1d5cb307f28c2e43d3119bf4b4e2cd0e","name":"@alekstar79/reactive-event-system","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@alekstar79/reactive-event-system","version":"1.0.0","keywords":["event-bus","event-emitter","reactive","reactivity","typescript","middleware","streaming","batched-updates","event-driven"],"author":{"name":"Alekstar79"},"license":"MIT","_id":"@alekstar79/reactive-event-system@1.0.0","maintainers":[{"name":"alekstar79","email":"alekstar79@yandex.ru"}],"homepage":"https://github.com/alekstar79/reactive-event-system#readme","bugs":{"url":"https://github.com/alekstar79/reactive-event-system/issues"},"dist":{"shasum":"814f5a1c36014da8287ad8ca770f2119c52bf792","tarball":"https://registry.npmjs.org/@alekstar79/reactive-event-system/-/reactive-event-system-1.0.0.tgz","fileCount":11,"integrity":"sha512-PhDmZFyIchBeM/1bF4ev3trZJnUtZIM7tIthQISLLNfVSoyc9Eo1iD0XO0Fkp9GMvFbzB3OhHB90NjnrsPBSrw==","signatures":[{"sig":"MEQCIAUIyF06yQJaD/29Rua/doBc/+FwWqK9a3q07OY1w7/hAiAvtBOuv/zM9Tfjwv1hlYJYxL04mKKGcVMKwMfmj1sSvQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":125182},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"d9338164dcf50de5352a85b6e190908e259b6467","private":false,"scripts":{"dev":"vite","lint":"eslint src --ext .ts","test":"vitest --silent","build":"vite build && yarn build:types","prepare":"npm run build","release":"npm run test && npm run build && npm publish --access public","test:ui":"vitest --ui","coverage":"vitest run --coverage","pub:beta":"npm run build:lib && npm publish --tag beta","test:run":"vitest run --silent","pub:major":"npm version major && npm run build && npm publish --access public","pub:minor":"npm version minor && npm run build && npm publish --access public","pub:patch":"npm version patch && npm run build && npm publish --access public","type-check":"tsc --noEmit","build:types":"tsc --declaration --emitDeclarationOnly --outDir dist","pub:dry-run":"npm run build && npm publish --dry-run","prepublishOnly":"npm run build && npm run test:run"},"_npmUser":{"name":"alekstar79","email":"alekstar79@yandex.ru"},"repository":{"url":"git+https://github.com/alekstar79/reactive-event-system.git","type":"git"},"_npmVersion":"10.7.0","description":"High-performance reactive event system with batched updates, middleware support, and streaming capabilities","directories":{},"_nodeVersion":"18.20.3","dependencies":{"@alekstar79/reactivity":"^1.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^5.0.0","eslint":"^9.39.1","vitest":"^4.0.10","typescript":"^5.3.0","@types/node":"^20.0.0","@vitest/coverage-v8":"^4.0.10","eslint-define-config":"^2.1.0","vite-plugin-static-copy":"^3.1.4","@typescript-eslint/parser":"^8.47.0","@typescript-eslint/eslint-plugin":"^8.47.0"},"_npmOperationalInternal":{"tmp":"tmp/reactive-event-system_1.0.0_1763641305074_0.9114515621360786","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@alekstar79/reactive-event-system","version":"1.0.1","description":"High-performance reactive event system with batched updates, middleware support, and streaming capabilities","type":"module","main":"./dist/reactive-event-system.js","types":"./dist/index.d.ts","private":false,"exports":{".":{"import":"./dist/reactive-event-system.js","require":"./dist/reactive-event-system.cjs","types":"./dist/index.d.ts"}},"keywords":["event-bus","event-emitter","reactive","reactivity","typescript","middleware","streaming","batched-updates","event-driven"],"author":{"name":"Alekstar79"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/alekstar79/reactive-event-system.git"},"bugs":{"url":"https://github.com/alekstar79/reactive-event-system/issues"},"homepage":"https://github.com/alekstar79/reactive-event-system#readme","dependencies":{"@alekstar79/reactivity":"^1.0.0"},"devDependencies":{"@types/node":"^20.0.0","@typescript-eslint/eslint-plugin":"^8.47.0","@typescript-eslint/parser":"^8.47.0","@vitest/coverage-v8":"^4.0.10","eslint":"^9.39.1","eslint-define-config":"^2.1.0","typescript":"^5.3.0","vite":"^5.0.0","vite-plugin-static-copy":"^3.1.4","vitest":"^4.0.10"},"scripts":{"dev":"vite","build":"vite build && yarn build:types","build:types":"tsc --declaration --emitDeclarationOnly --outDir dist","type-check":"tsc --noEmit","test":"vitest --silent","test:ui":"vitest --ui","test:run":"vitest run --silent","coverage":"vitest run --coverage","lint":"eslint src --ext .ts","prepare":"npm run build","prepublishOnly":"npm run build && npm run test:run","pub:dry-run":"npm run build && npm publish --dry-run","pub:beta":"npm run build:lib && npm publish --tag beta","pub:patch":"npm version patch && npm run build && npm publish --access public","pub:minor":"npm version minor && npm run build && npm publish --access public","pub:major":"npm version major && npm run build && npm publish --access public","release":"npm run test && npm run build && npm publish --access public"},"publishConfig":{"access":"public"},"_id":"@alekstar79/reactive-event-system@1.0.1","gitHead":"0a6b4ad5bb354e8e703edb0c82310b80f8be0e2f","_nodeVersion":"18.20.3","_npmVersion":"10.7.0","dist":{"integrity":"sha512-++L2H6W5Uc6/FO1MWimqbTgKakZfXl40nibcCEkBkMV/bns06c+ZO4Ukl2k837exCUTuLvwTShGIsAPJDT+Mqg==","shasum":"674dc6ad9196b3f06e746f3d4c5a09485cfbb48d","tarball":"https://registry.npmjs.org/@alekstar79/reactive-event-system/-/reactive-event-system-1.0.1.tgz","fileCount":11,"unpackedSize":125278,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDbq1QCpyUuUKiLpjSkGfDY/fxZO8DYhwUSg4xmGe2jvgIhAOgYBFct0P7FAShymLpsHzTEWsrhg6wca6OvxNrFET2G"}]},"_npmUser":{"name":"alekstar79","email":"alekstar79@yandex.ru"},"directories":{},"maintainers":[{"name":"alekstar79","email":"alekstar79@yandex.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/reactive-event-system_1.0.1_1763645660069_0.8643125296221499"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-20T12:21:44.925Z","modified":"2025-11-20T13:34:20.436Z","1.0.0":"2025-11-20T12:21:45.270Z","1.0.1":"2025-11-20T13:34:20.266Z"},"bugs":{"url":"https://github.com/alekstar79/reactive-event-system/issues"},"author":{"name":"Alekstar79"},"license":"MIT","homepage":"https://github.com/alekstar79/reactive-event-system#readme","keywords":["event-bus","event-emitter","reactive","reactivity","typescript","middleware","streaming","batched-updates","event-driven"],"repository":{"type":"git","url":"git+https://github.com/alekstar79/reactive-event-system.git"},"description":"High-performance reactive event system with batched updates, middleware support, and streaming capabilities","maintainers":[{"name":"alekstar79","email":"alekstar79@yandex.ru"}],"readme":"# Reactive Event System\n\n[![NPM](https://img.shields.io/npm/v/@alekstar79/reactive-event-system.svg)](https://www.npmjs.com/package/@alekstar79/reactive-event-system)\n[![GitHub repo](https://img.shields.io/badge/github-repo-green.svg?style=flat)](https://github.com/alekstar79/reactive-event-system)\n[![Typescript](https://img.shields.io/badge/TypeScript-Ready-blue?logo=typescript)]()\n[![License](https://img.shields.io/badge/License-MIT-green)]()\n[![Version](https://img.shields.io/badge/Version-1.0.0-orange)]()\n[![Coverage](https://img.shields.io/badge/Coverage-87.7%25-green)]()\n\nHigh-performance reactive event bus with batched updates, middleware support, and streaming capabilities. Built for TypeScript with full type safety and ES2024 compatibility.\n\n![Reactive Event System](reactive-banner.svg)\n\n<!-- TOC -->\n* [Reactive Event System](#reactive-event-system)\n  * [Features](#features)\n  * [Installation](#installation)\n    * [npm](#npm)\n    * [yarn](#yarn)\n    * [pnpm](#pnpm)\n  * [Quick Start](#quick-start)\n    * [Basic Usage](#basic-usage)\n    * [One-time Events](#one-time-events)\n    * [Promise-based Event Waiting](#promise-based-event-waiting)\n    * [Reactive Streams](#reactive-streams)\n    * [Middleware Pipeline](#middleware-pipeline)\n    * [Event Piping](#event-piping)\n    * [Metrics and Monitoring](#metrics-and-monitoring)\n    * [Error Handling](#error-handling)\n    * [Utility Methods](#utility-methods)\n  * [Typed Events](#typed-events)\n  * [API Reference](#api-reference)\n    * [ReactiveEventSystem](#reactiveeventsystem)\n      * [Constructor](#constructor)\n      * [Methods](#methods)\n  * [TypeScript Support](#typescript-support)\n  * [Browser Support](#browser-support)\n  * [Performance](#performance)\n  * [Testing](#testing)\n  * [📊 Test Coverage](#-test-coverage)\n  * [Contributing](#contributing)\n  * [License](#license)\n  * [Related Projects](#related-projects)\n  * [Changelog](#changelog)\n  * [Security](#security)\n<!-- TOC -->\n\n## Features\n\n- 🚀 **High Performance**: Batched reactive updates for minimal re-renders\n- 🔄 **Reactive**: Seamless integration with reactive state management\n- 🔗 **Middleware Pipeline**: Flexible event processing with global and event-specific middleware\n- 📡 **Event Streaming**: Convert events to reactive streams with built-in metrics\n- ⏱️ **Promise-based**: `waitFor()` method for async event handling with timeout support\n- 🔀 **Event Piping**: Route events from one bus to another with optional transformation\n- 📊 **Metrics**: Built-in monitoring with reactive metrics tracking\n- 📦 **Tree-shakeable**: Fully modular, ES2022+ compatible\n- 💪 **Type Safe**: Complete TypeScript support with generics\n\n## Installation\n\n### npm\n\n```bash\nnpm install @alekstar79/reactive-event-system\n```\n\n### yarn\n\n```bash\nyarn add @alekstar79/reactive-event-system\n```\n\n### pnpm\n\n```bash\npnpm add @alekstar79/reactive-event-system\n```\n\n## Quick Start\n\n### Basic Usage\n\n```typescript\nimport ReactiveEventSystem from '@alekstar79/reactive-event-system'\n\n// Create a bus instance\nconst bus = new ReactiveEventSystem()\n\n// Subscribe to events\nbus.on('message', (data) => {\n  console.log('Message received:', data)\n})\n\n// Emit events\nbus.emit('message', { text: 'Hello, World!' })\n\n// Unsubscribe (automatic)\nconst unsubscribe = bus.on('message', (data) => {\n  console.log('Handler 1:', data)\n})\nunsubscribe()\n```\n\n### One-time Events\n\n```typescript\n// Listen for event only once\nbus.once('connected', (data) => {\n  console.log('Connected:', data)\n})\n\n// Alternatively, with unsubscribe function\nconst unsubscribe = bus.once('connected', (data) => {\n  console.log('Connected:', data)\n})\n```\n\n### Promise-based Event Waiting\n\n```typescript\n// Wait for specific event with timeout\ntry {\n  const user = await bus.waitFor('authComplete', 5000)\n  console.log('Authenticated:', user)\n} catch (error) {\n  console.log('Auth timeout')\n}\n\n// Wait without timeout\nconst data = await bus.waitFor('dataLoaded')\n```\n\n### Reactive Streams\n\n```typescript\nimport { effect } from '@alekstar79/reactive-event-system'\n\n// Create a stream from events\nconst messageStream = bus.stream('messages')\n\n// React to stream updates\neffect(() => {\n  console.log('Latest message:', messageStream.state.value)\n  console.log('Total messages:', messageStream.state.count)\n})\n\n// Subscribe to stream\nconst unsubscribe = messageStream.subscribe((msg) => {\n  console.log('Stream listener:', msg)\n})\n\n// Cleanup\nmessageStream.destroy()\n```\n\n### Middleware Pipeline\n\n```typescript\n// Global middleware (all events)\nbus.use('*', (data, event) => {\n  console.log(`Event: ${event}`, data)\n  return data\n})\n\n// Event-specific middleware\nbus.use('userAction', (data, event) => {\n  if (!data.userId) {\n    throw new Error('userId is required')\n  }\n  // Transform data\n  return {\n    ...data,\n    timestamp: Date.now(),\n    processed: true\n  }\n})\n\n// Multiple middleware chains\nconst unsubscribe = bus.use('userAction', (data) => {\n  return { ...data, validated: true }\n})\n```\n\n### Event Piping\n\n```typescript\nconst sourceBus = new ReactiveEventSystem()\nconst targetBus = new ReactiveEventSystem()\n\n// Pipe events from source to target\nconst unpipe = sourceBus.pipe('data', targetBus)\n\n// Pipe with event name transformation\nconst unpipeRenamed = sourceBus.pipe('input', targetBus, 'processedInput')\n\n// Stop piping\nunpipe()\n```\n\n### Metrics and Monitoring\n\n```typescript\nimport ReactiveEventSystem, { effect } from '@alekstar79/reactive-event-system'\n\n// Enable metrics on initialization\nconst bus = new ReactiveEventSystem({ enableMetrics: true })\n\n// Get metrics object\nconst metrics = bus.getMetrics()\n\n// Monitor metrics reactively\neffect(() => {\n  console.log('Total events emitted:', metrics.state.totalEventsEmitted)\n  console.log('Last event:', metrics.state.lastEmittedEvent)\n  console.log('Active listeners:', metrics.state.activeListeners)\n  console.log('Total listeners:', metrics.totalListeners())\n  console.log('Event names:', metrics.events())\n})\n```\n\n### Error Handling\n\n```typescript\n// Custom error handler\nconst bus = new EventBusReactiveEventSystem({\n  errorHandler: (error, event, listener) => {\n    console.error(`Error in listener for \"${event}\":`, error.message)\n    // Custom error reporting, logging, etc.\n  }\n})\n\n// Listen for events\nbus.on('test', () => {\n  throw new Error('Something went wrong')\n})\n\n// Event is still emitted, error is handled\nbus.emit('test', {})\n```\n\n### Utility Methods\n\n```typescript\n// Check listener count\nconst count = bus.listenerCount('message')\nconsole.log('Listeners:', count)\n\n// Check if event has listeners\nif (bus.hasListeners('message')) {\n  bus.emit('message', { text: 'Someone is listening' })\n}\n\n// Get all event names\nconst eventNames = bus.eventNames()\nconsole.log('Events:', eventNames)\n\n// Remove all listeners for specific event\nbus.removeAllListeners('message')\n\n// Remove all listeners for all events\nbus.removeAllListeners()\n\n// Cleanup resources\nbus.destroy()\n```\n\n## Typed Events\n\n```typescript\ninterface UserEventData {\n  userId: string\n  username: string\n  email: string\n}\n\n// Create typed bus\nconst userBus = new ReactiveEventSystem<UserEventData>()\n\n// TypeScript enforces correct data structure\nuserBus.on('userCreated', (data) => {\n  console.log(data.userId) // ✓ OK\n  console.log(data.username) // ✓ OK\n  // console.log(data.unknown) // ✗ Error: Property 'unknown' does not exist\n})\n\nuserBus.emit('userCreated', {\n  userId: '123',\n  username: 'john',\n  email: 'john@example.com'\n})\n```\n\n## API Reference\n\n### ReactiveEventSystem\n\nMain class for event bus functionality.\n\n#### Constructor\n\n```typescript\nconstructor(options?: {\n  enableMetrics?: boolean\n  errorHandler?: (error: Error, event: string, listener: Function) => void\n})\n```\n\n#### Methods\n\n- `on(event, listener, options?)`: Subscribe to event\n- `once(event, listener, options?)`: Subscribe to event once\n- `off(event, listener)`: Unsubscribe from event\n- `emit(event, data)`: Emit event to all listeners\n- `listenerCount(event)`: Get listener count for event\n- `removeAllListeners(event?)`: Remove all listeners\n- `eventNames()`: Get all event names\n- `hasListeners(event)`: Check if event has listeners\n- `use(event, middleware)`: Add middleware\n- `stream(event)`: Create reactive stream\n- `getMetrics()`: Get metrics object\n- `waitFor(event, timeout?)`: Wait for event (Promise)\n- `pipe(fromEvent, toEmitter, toEvent?)`: Pipe events\n- `destroy()`: Cleanup resources\n\n## TypeScript Support\n\nFull TypeScript support with complete type definitions included.\n\n```typescript\nimport ReactiveEventSystem, { EventSystemMetrics, EventStream, EventMiddleware } from '@alekstar79/reactive-event-system'\n\ninterface AppEvents {\n  ready: { timestamp: number }\n  error: { message: string }\n  data: { value: string }\n}\n\ntype AppBus = ReactiveEventSystem<AppEvents>\n```\n\n## Browser Support\n\n- Chrome: ✓ Latest\n- Firefox: ✓ Latest\n- Safari: ✓ Latest\n- Edge: ✓ Latest\n\nRequires ES2024 support or transpilation.\n\n## Performance\n\n- Batched reactive updates minimize re-renders\n- WeakMap-based cleanup prevents memory leaks\n- Set-based listener storage for O(1) operations\n- Minimal overhead for event emission\n\n## Testing\n\n```bash\nnpm test\nnpm run test:coverage\nnpm run test:ui\n```\n\n## 📊 Test Coverage\n\n| File      | % Stmts | % Branch | % Funcs | % Lines |\n|-----------|---------|----------|---------|---------|\n| All files | 79.31   | 75       | 69.09   | 80.48   |\n| index.ts  | 79.31   | 75       | 69.09   | 80.48   |\n\n## Contributing\n\nContributions are welcome! Please read our contributing guidelines first.\n\n## License\n\nMIT © 2025 @alekstar79\n\n## Related Projects\n\n- [@alekstar79/reactivity](https://github.com/alekstar79/reactivity) - Reactive state management\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for release history.\n\n## Security\n\nFor security issues, please email instead of using the issue tracker.\n","readmeFilename":"README.md"}