@xbg.solutions/bpsk-utils-event-bus 1.2.3

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.
Files changed (37) hide show
  1. package/lib/index.d.ts +8 -0
  2. package/lib/index.d.ts.map +1 -0
  3. package/lib/index.js +11 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/services/events/event-bus.d.ts +84 -0
  6. package/lib/services/events/event-bus.d.ts.map +1 -0
  7. package/lib/services/events/event-bus.js +278 -0
  8. package/lib/services/events/event-bus.js.map +1 -0
  9. package/lib/services/events/index.d.ts +14 -0
  10. package/lib/services/events/index.d.ts.map +1 -0
  11. package/lib/services/events/index.js +16 -0
  12. package/lib/services/events/index.js.map +1 -0
  13. package/lib/services/events/pub-sub.d.ts +79 -0
  14. package/lib/services/events/pub-sub.d.ts.map +1 -0
  15. package/lib/services/events/pub-sub.js +117 -0
  16. package/lib/services/events/pub-sub.js.map +1 -0
  17. package/lib/stores/event-bus.d.ts +16 -0
  18. package/lib/stores/event-bus.d.ts.map +1 -0
  19. package/lib/stores/event-bus.js +28 -0
  20. package/lib/stores/event-bus.js.map +1 -0
  21. package/lib/stores/event.store.d.ts +55 -0
  22. package/lib/stores/event.store.d.ts.map +1 -0
  23. package/lib/stores/event.store.js +99 -0
  24. package/lib/stores/event.store.js.map +1 -0
  25. package/lib/stores/pub-sub.d.ts +11 -0
  26. package/lib/stores/pub-sub.d.ts.map +1 -0
  27. package/lib/stores/pub-sub.js +25 -0
  28. package/lib/stores/pub-sub.js.map +1 -0
  29. package/lib/types/event.types.d.ts +148 -0
  30. package/lib/types/event.types.d.ts.map +1 -0
  31. package/lib/types/event.types.js +42 -0
  32. package/lib/types/event.types.js.map +1 -0
  33. package/lib/types/events.interfaces.d.ts +154 -0
  34. package/lib/types/events.interfaces.d.ts.map +1 -0
  35. package/lib/types/events.interfaces.js +9 -0
  36. package/lib/types/events.interfaces.js.map +1 -0
  37. package/package.json +27 -0
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { EventError, eventBus, eventBusStore as eventBusServiceStore, publish, subscribe, createEventBus } from './services/events/event-bus';
2
+ export { createPubSubService, pubSubStore as pubSubServiceStore, pubSubService as pubSubServiceInstance } from './services/events/pub-sub';
3
+ export { type EventBusState, eventBusStore, eventBusService } from './stores/event-bus';
4
+ export * from './stores/event.store';
5
+ export { type PubSubState, pubSubStore, pubSubService } from './stores/pub-sub';
6
+ export type * from './types/event.types';
7
+ export type * from './types/events.interfaces';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,UAAU,EACV,QAAQ,EACR,aAAa,IAAI,oBAAoB,EACrC,OAAO,EACP,SAAS,EACT,cAAc,EACf,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,mBAAmB,EACnB,WAAW,IAAI,kBAAkB,EACjC,aAAa,IAAI,qBAAqB,EACvC,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,KAAK,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACxF,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,KAAK,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGhF,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,2BAA2B,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,11 @@
1
+ // Event bus package barrel exports
2
+ // Uses explicit re-exports to resolve naming conflicts between services and stores
3
+ // Services — event-bus (core event system)
4
+ export { EventError, eventBus, eventBusStore as eventBusServiceStore, publish, subscribe, createEventBus } from './services/events/event-bus';
5
+ // Services — pub-sub (higher-level pub/sub)
6
+ export { createPubSubService, pubSubStore as pubSubServiceStore, pubSubService as pubSubServiceInstance } from './services/events/pub-sub';
7
+ // Stores
8
+ export { eventBusStore, eventBusService } from './stores/event-bus';
9
+ export * from './stores/event.store';
10
+ export { pubSubStore, pubSubService } from './stores/pub-sub';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,mFAAmF;AAEnF,2CAA2C;AAC3C,OAAO,EACL,UAAU,EACV,QAAQ,EACR,aAAa,IAAI,oBAAoB,EACrC,OAAO,EACP,SAAS,EACT,cAAc,EACf,MAAM,6BAA6B,CAAC;AAErC,4CAA4C;AAC5C,OAAO,EACL,mBAAmB,EACnB,WAAW,IAAI,kBAAkB,EACjC,aAAa,IAAI,qBAAqB,EACvC,MAAM,2BAA2B,CAAC;AAEnC,SAAS;AACT,OAAO,EAAsB,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACxF,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAoB,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * src/lib/services/events/event-bus.ts
3
+ * Core event bus implementation - FIXED VERSION
4
+ */
5
+ import { AppError } from '@xbg.solutions/bpsk-core';
6
+ import type { IEventBus } from '../../types/events.interfaces';
7
+ import type { AppEvent, EventHandler, Subscription, EventDispatchOptions } from '../../types/event.types';
8
+ /**
9
+ * Error class for event-related errors
10
+ */
11
+ export declare class EventError extends AppError {
12
+ eventType?: string;
13
+ constructor(message: string, options?: {
14
+ eventType?: string;
15
+ [key: string]: any;
16
+ });
17
+ }
18
+ /**
19
+ * EventBus class for managing application events
20
+ * Implements the IEventBus interface
21
+ */
22
+ declare class EventBus implements IEventBus {
23
+ /** Map of event types to sets of handlers */
24
+ private handlers;
25
+ /** Map of prefixes to sets of handlers for pattern matching */
26
+ private prefixHandlers;
27
+ /** Whether debug mode is enabled */
28
+ private debugMode;
29
+ /**
30
+ * Subscribe to event(s)
31
+ *
32
+ * @param eventType Event type string or array of event types
33
+ * @param handler Function to be called when the event is published
34
+ * @returns Function that can be called to unsubscribe
35
+ */
36
+ on<T = any>(eventType: string | string[], handler: EventHandler<T>): Subscription;
37
+ /**
38
+ * Publish an event to all subscribers
39
+ *
40
+ * @param event Event object to publish
41
+ * @param options Additional options for event dispatch
42
+ */
43
+ publish<T = any>(event: AppEvent<T>, options?: EventDispatchOptions): Promise<void>;
44
+ /**
45
+ * Check if there are subscribers for a given event type
46
+ *
47
+ * @param eventType Event type to check
48
+ * @returns Boolean indicating if there are subscribers
49
+ */
50
+ hasSubscribers(eventType: string): boolean;
51
+ /**
52
+ * Enable or disable debug mode
53
+ *
54
+ * @param enabled Whether debug mode should be enabled
55
+ */
56
+ setDebugMode(enabled: boolean): void;
57
+ /**
58
+ * Get the current debug mode status
59
+ *
60
+ * @returns Whether debug mode is enabled
61
+ */
62
+ isDebugMode(): boolean;
63
+ /**
64
+ * Get subscription statistics
65
+ *
66
+ * @returns Object with subscription counts
67
+ */
68
+ getStats(): {
69
+ subscribers: number;
70
+ eventTypes: number;
71
+ prefixSubscribers: number;
72
+ };
73
+ /**
74
+ * Clear all event subscriptions
75
+ */
76
+ clear(): void;
77
+ }
78
+ export declare const eventBus: EventBus;
79
+ export declare const eventBusStore: import("svelte/store").Writable<IEventBus>;
80
+ export declare function publish<T = any>(eventType: string, payload?: T, source?: string): Promise<void>;
81
+ export declare function subscribe<T = any>(eventType: string | string[], handler: EventHandler<T>): Subscription;
82
+ export declare const createEventBus: () => EventBus;
83
+ export {};
84
+ //# sourceMappingURL=event-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../../src/services/events/event-bus.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,QAAQ,EAAkB,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAEV,QAAQ,EACR,YAAY,EACZ,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C7B,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,CAAW,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAOf;AAGD,wBAAgB,SAAS,CAAC,CAAC,GAAG,GAAG,EAC/B,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAC5B,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GACvB,YAAY,CAEd;AAGD,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
@@ -0,0 +1,278 @@
1
+ /**
2
+ * src/lib/services/events/event-bus.ts
3
+ * Core event bus implementation - FIXED VERSION
4
+ */
5
+ import { writable } from 'svelte/store';
6
+ import { loggerService } from '@xbg.solutions/bpsk-core';
7
+ import { mutexService } from '@xbg.solutions/bpsk-utils-mutex';
8
+ import { AppError, normalizeError } from '@xbg.solutions/bpsk-core';
9
+ // Create a context-aware logger
10
+ const eventLogger = loggerService.withContext('EventBus');
11
+ /**
12
+ * Error class for event-related errors
13
+ */
14
+ export class EventError extends AppError {
15
+ constructor(message, options = {}) {
16
+ super(message, {
17
+ category: 'event',
18
+ ...options
19
+ });
20
+ this.eventType = options.eventType;
21
+ }
22
+ }
23
+ /**
24
+ * EventBus class for managing application events
25
+ * Implements the IEventBus interface
26
+ */
27
+ class EventBus {
28
+ constructor() {
29
+ /** Map of event types to sets of handlers */
30
+ this.handlers = new Map();
31
+ /** Map of prefixes to sets of handlers for pattern matching */
32
+ this.prefixHandlers = new Map();
33
+ /** Whether debug mode is enabled */
34
+ this.debugMode = import.meta.env.DEV;
35
+ }
36
+ /**
37
+ * Subscribe to event(s)
38
+ *
39
+ * @param eventType Event type string or array of event types
40
+ * @param handler Function to be called when the event is published
41
+ * @returns Function that can be called to unsubscribe
42
+ */
43
+ on(eventType, handler) {
44
+ const types = Array.isArray(eventType) ? eventType : [eventType];
45
+ // Log the subscription if in debug mode
46
+ if (this.debugMode) {
47
+ eventLogger.info(`Subscribing to event(s): ${types.join(', ')}`, {
48
+ eventTypes: types,
49
+ handlerFunction: handler.name || 'anonymous'
50
+ });
51
+ }
52
+ // Add the handler to each event type's set
53
+ types.forEach(type => {
54
+ // Handle prefix subscriptions (e.g., "auth:*")
55
+ if (type.endsWith('*')) {
56
+ const prefix = type.slice(0, -1);
57
+ if (!this.prefixHandlers.has(prefix)) {
58
+ this.prefixHandlers.set(prefix, new Set());
59
+ }
60
+ this.prefixHandlers.get(prefix).add(handler);
61
+ }
62
+ else {
63
+ // Regular event subscription
64
+ if (!this.handlers.has(type)) {
65
+ this.handlers.set(type, new Set());
66
+ }
67
+ this.handlers.get(type).add(handler);
68
+ }
69
+ });
70
+ // Return unsubscribe function
71
+ return () => {
72
+ if (this.debugMode) {
73
+ eventLogger.info(`Unsubscribing from event(s): ${types.join(', ')}`, {
74
+ eventTypes: types,
75
+ handlerFunction: handler.name || 'anonymous'
76
+ });
77
+ }
78
+ types.forEach(type => {
79
+ if (type.endsWith('*')) {
80
+ const prefix = type.slice(0, -1);
81
+ const handlers = this.prefixHandlers.get(prefix);
82
+ if (handlers) {
83
+ handlers.delete(handler);
84
+ // Clean up empty sets
85
+ if (handlers.size === 0) {
86
+ this.prefixHandlers.delete(prefix);
87
+ }
88
+ }
89
+ }
90
+ else {
91
+ const handlers = this.handlers.get(type);
92
+ if (handlers) {
93
+ handlers.delete(handler);
94
+ // Clean up empty sets
95
+ if (handlers.size === 0) {
96
+ this.handlers.delete(type);
97
+ }
98
+ }
99
+ }
100
+ });
101
+ };
102
+ }
103
+ /**
104
+ * Publish an event to all subscribers
105
+ *
106
+ * @param event Event object to publish
107
+ * @param options Additional options for event dispatch
108
+ */
109
+ async publish(event, options = {}) {
110
+ try {
111
+ // Use mutex to ensure event publications are processed in order
112
+ await mutexService.withLock('event-publish', async () => {
113
+ // Defer execution to next microtask if requested
114
+ if (options.defer) {
115
+ await Promise.resolve();
116
+ }
117
+ // Ensure event has a timestamp
118
+ const eventWithTime = {
119
+ ...event,
120
+ timestamp: event.timestamp || Date.now()
121
+ };
122
+ // Log the event publication if in debug mode
123
+ if (this.debugMode) {
124
+ eventLogger.info(`Event published: ${event.type}`, {
125
+ eventType: event.type,
126
+ source: event.source,
127
+ payload: event.payload
128
+ });
129
+ }
130
+ // Get handlers for this specific event type
131
+ const eventHandlers = this.handlers.get(event.type) || new Set();
132
+ // Get prefix handlers that match this event
133
+ const matchingPrefixHandlers = new Set();
134
+ for (const [prefix, handlers] of this.prefixHandlers.entries()) {
135
+ if (event.type.startsWith(prefix)) {
136
+ handlers.forEach(handler => matchingPrefixHandlers.add(handler));
137
+ }
138
+ }
139
+ // Count of handlers for metrics
140
+ const handlersCount = eventHandlers.size + matchingPrefixHandlers.size;
141
+ if (handlersCount === 0 && this.debugMode) {
142
+ eventLogger.warn(`Event published with no subscribers: ${event.type}`, {
143
+ eventType: event.type
144
+ });
145
+ }
146
+ // Execute all matching handlers
147
+ const allHandlers = [...eventHandlers, ...matchingPrefixHandlers];
148
+ let successCount = 0;
149
+ let errorCount = 0;
150
+ for (const handler of allHandlers) {
151
+ try {
152
+ await handler(eventWithTime);
153
+ successCount++;
154
+ }
155
+ catch (error) {
156
+ errorCount++;
157
+ const normalizedError = normalizeError(error, `Error in event handler for "${event.type}"`, {
158
+ context: {
159
+ eventType: event.type,
160
+ source: event.source
161
+ },
162
+ category: 'event'
163
+ });
164
+ eventLogger.error(`Error in event handler for "${event.type}"`, normalizedError, {
165
+ eventType: event.type,
166
+ source: event.source,
167
+ handlerFunction: handler.name || 'anonymous'
168
+ });
169
+ }
170
+ }
171
+ // Log metrics in debug mode
172
+ if (this.debugMode && handlersCount > 0) {
173
+ eventLogger.info(`Event ${event.type} processed by ${successCount} handlers (${errorCount} errors)`, {
174
+ eventType: event.type,
175
+ handlersCount,
176
+ successCount,
177
+ errorCount
178
+ });
179
+ }
180
+ });
181
+ }
182
+ catch (error) {
183
+ eventLogger.error(`Failed to publish event "${event.type}"`, error instanceof Error ? error : new Error(String(error)), { eventType: event.type });
184
+ }
185
+ }
186
+ /**
187
+ * Check if there are subscribers for a given event type
188
+ *
189
+ * @param eventType Event type to check
190
+ * @returns Boolean indicating if there are subscribers
191
+ */
192
+ hasSubscribers(eventType) {
193
+ // Check direct subscribers
194
+ if (this.handlers.has(eventType) && this.handlers.get(eventType).size > 0) {
195
+ return true;
196
+ }
197
+ // Check prefix subscribers
198
+ for (const [prefix, handlers] of this.prefixHandlers.entries()) {
199
+ if (eventType.startsWith(prefix) && handlers.size > 0) {
200
+ return true;
201
+ }
202
+ }
203
+ return false;
204
+ }
205
+ /**
206
+ * Enable or disable debug mode
207
+ *
208
+ * @param enabled Whether debug mode should be enabled
209
+ */
210
+ setDebugMode(enabled) {
211
+ this.debugMode = enabled;
212
+ eventLogger.info(`Event bus debug mode ${enabled ? 'enabled' : 'disabled'}`);
213
+ }
214
+ /**
215
+ * Get the current debug mode status
216
+ *
217
+ * @returns Whether debug mode is enabled
218
+ */
219
+ isDebugMode() {
220
+ return this.debugMode;
221
+ }
222
+ /**
223
+ * Get subscription statistics
224
+ *
225
+ * @returns Object with subscription counts
226
+ */
227
+ getStats() {
228
+ let subscribers = 0;
229
+ // Count direct subscribers
230
+ for (const handlers of this.handlers.values()) {
231
+ subscribers += handlers.size;
232
+ }
233
+ // Count prefix subscribers
234
+ let prefixSubscribers = 0;
235
+ for (const handlers of this.prefixHandlers.values()) {
236
+ prefixSubscribers += handlers.size;
237
+ }
238
+ return {
239
+ subscribers: subscribers + prefixSubscribers,
240
+ eventTypes: this.handlers.size,
241
+ prefixSubscribers
242
+ };
243
+ }
244
+ /**
245
+ * Clear all event subscriptions
246
+ */
247
+ clear() {
248
+ if (this.debugMode) {
249
+ const stats = this.getStats();
250
+ eventLogger.warn(`Clearing all event subscriptions`, {
251
+ eventTypes: stats.eventTypes,
252
+ subscribers: stats.subscribers
253
+ });
254
+ }
255
+ this.handlers.clear();
256
+ this.prefixHandlers.clear();
257
+ }
258
+ }
259
+ // Create a singleton instance for the event bus
260
+ export const eventBus = new EventBus();
261
+ // Create a Svelte store for backwards compatibility
262
+ export const eventBusStore = writable(eventBus);
263
+ // Export a convenience function to access the eventBus for publishing events
264
+ export function publish(eventType, payload = {}, source) {
265
+ return eventBus.publish({
266
+ type: eventType,
267
+ payload,
268
+ source,
269
+ timestamp: Date.now() // Added timestamp to fix the TypeScript error
270
+ });
271
+ }
272
+ // Export a convenience function to subscribe to events
273
+ export function subscribe(eventType, handler) {
274
+ return eventBus.on(eventType, handler);
275
+ }
276
+ // Export a factory function that creates a new EventBus instance
277
+ export const createEventBus = () => new EventBus();
278
+ //# sourceMappingURL=event-bus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../../src/services/events/event-bus.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAUpE,gCAAgC;AAChC,MAAM,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,QAAQ;IAGtC,YAAY,OAAe,EAAE,UAGzB,EAAE;QACJ,KAAK,CAAC,OAAO,EAAE;YACb,QAAQ,EAAE,OAAO;YACjB,GAAG,OAAO;SACX,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACrC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,QAAQ;IAAd;QACE,6CAA6C;QACrC,aAAQ,GAAmC,IAAI,GAAG,EAAE,CAAC;QAE7D,+DAA+D;QACvD,mBAAc,GAAmC,IAAI,GAAG,EAAE,CAAC;QAEnE,oCAAoC;QAC5B,cAAS,GAAY,MAAM,CAAC,IAAI,CAAC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,CAAC,CAAC;AAE3D,6EAA6E;AAC7E,MAAM,UAAU,OAAO,CACrB,SAAiB,EACjB,UAAa,EAAO,EACpB,MAAe;IAEf,OAAO,QAAQ,CAAC,OAAO,CAAC;QACtB,IAAI,EAAE,SAAS;QACf,OAAO;QACP,MAAM;QACN,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,8CAA8C;KACrE,CAAC,CAAC;AACL,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,SAAS,CACvB,SAA4B,EAC5B,OAAwB;IAExB,OAAO,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,iEAAiE;AACjE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,IAAI,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * src/lib/services/events/index.ts
3
+ * Central export file for the event system
4
+ *
5
+ * Provides a single import point for all event-related functionality.
6
+ * This follows the architectural best practice of providing a clean,
7
+ * consistent API for the event system.
8
+ */
9
+ export { eventBus, eventBusStore, createEventBus, EventError } from './event-bus';
10
+ export { pubSubService, pubSubStore, createPubSubService, publish, subscribe, once, hasSubscribers, setDebugMode, clear, getSubscriptionStats } from './pub-sub';
11
+ export { eventStore, eventDerived, connectStoreToEvents } from '../../stores/event.store';
12
+ export type { Subscription, EventHandler, AppEvent, BaseEvent, EventDispatchOptions } from '../../types/event.types';
13
+ export { CoreEventType } from '../../types/event.types';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACH,QAAQ,EACR,aAAa,EACb,cAAc,EACd,UAAU,EACX,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,OAAO,EACP,SAAS,EACT,IAAI,EACJ,cAAc,EACd,YAAY,EACZ,KAAK,EACL,oBAAoB,EACrB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,UAAU,EACV,YAAY,EACZ,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAGlC,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * src/lib/services/events/index.ts
3
+ * Central export file for the event system
4
+ *
5
+ * Provides a single import point for all event-related functionality.
6
+ * This follows the architectural best practice of providing a clean,
7
+ * consistent API for the event system.
8
+ */
9
+ // Core event bus
10
+ export { eventBus, eventBusStore, createEventBus, EventError } from './event-bus';
11
+ // PubSub service (higher-level API)
12
+ export { pubSubService, pubSubStore, createPubSubService, publish, subscribe, once, hasSubscribers, setDebugMode, clear, getSubscriptionStats } from './pub-sub';
13
+ // Event-connected stores
14
+ export { eventStore, eventDerived, connectStoreToEvents } from '../../stores/event.store';
15
+ export { CoreEventType } from '../../types/event.types';
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,iBAAiB;AACjB,OAAO,EACH,QAAQ,EACR,aAAa,EACb,cAAc,EACd,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,oCAAoC;AACpC,OAAO,EACL,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,OAAO,EACP,SAAS,EACT,IAAI,EACJ,cAAc,EACd,YAAY,EACZ,KAAK,EACL,oBAAoB,EACrB,MAAM,WAAW,CAAC;AAEnB,yBAAyB;AACzB,OAAO,EACL,UAAU,EACV,YAAY,EACZ,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAWlC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * src/lib/services/events/pub-sub.ts
3
+ * Higher-level API for the event bus system
4
+ *
5
+ * Provides a simplified interface for publishing and subscribing
6
+ * to events with convenient payload handling and additional features
7
+ * such as once() for one-time subscriptions.
8
+ */
9
+ import type { IPubSubService } from '../../types/events.interfaces';
10
+ import type { AppEvent, Subscription, EventDispatchOptions } from '../../types/event.types';
11
+ /**
12
+ * PubSub service class that implements the IPubSubService interface
13
+ */
14
+ declare class PubSubService implements IPubSubService {
15
+ /**
16
+ * Publish an event to all subscribers
17
+ *
18
+ * @param eventType Event type identifier
19
+ * @param payload Event data payload
20
+ * @param source Optional source identifier (component/service name)
21
+ * @param options Additional options for event dispatch
22
+ */
23
+ publish<T = any>(eventType: string, payload: T, source?: string, options?: EventDispatchOptions): void;
24
+ /**
25
+ * Subscribe to one or more event types
26
+ *
27
+ * @param eventType Event type string or array of event types
28
+ * @param handler Function to handle the event
29
+ * @param context Optional 'this' context for the handler
30
+ * @returns Function to unsubscribe
31
+ */
32
+ subscribe<T = any>(eventType: string | string[], handler: (payload: T, event: AppEvent<T>) => void, context?: any): Subscription;
33
+ /**
34
+ * Subscribe to an event only for the first occurrence
35
+ *
36
+ * @param eventType Event type to listen for
37
+ * @param handler Function to handle the event
38
+ * @param context Optional 'this' context for the handler
39
+ * @returns Function to unsubscribe if needed before the event fires
40
+ */
41
+ once<T = any>(eventType: string, handler: (payload: T, event: AppEvent<T>) => void, context?: any): Subscription;
42
+ /**
43
+ * Check if an event type has subscribers
44
+ *
45
+ * @param eventType Event type to check
46
+ * @returns Boolean indicating if there are subscribers
47
+ */
48
+ hasSubscribers(eventType: string): boolean;
49
+ /**
50
+ * Set the event bus debug mode
51
+ *
52
+ * @param enabled Whether debug mode should be enabled
53
+ */
54
+ setDebugMode(enabled: boolean): void;
55
+ /**
56
+ * Clear all event subscriptions
57
+ */
58
+ clearAllSubscriptions(): void;
59
+ /**
60
+ * Get statistics about event subscriptions
61
+ *
62
+ * @returns Object with subscription counts
63
+ */
64
+ getSubscriptionStats(): {
65
+ subscribers: number;
66
+ eventTypes: number;
67
+ prefixSubscribers: number;
68
+ };
69
+ }
70
+ export declare const createPubSubService: () => PubSubService;
71
+ export declare const pubSubStore: import("svelte/store").Writable<IPubSubService>;
72
+ export declare const pubSubService: IPubSubService;
73
+ export declare const publish: <T = any>(eventType: string, payload: T, source?: string, options?: EventDispatchOptions) => void, subscribe: <T = any>(eventType: string | string[], handler: (payload: T, event: AppEvent<T>) => void, context?: any) => Subscription, once: <T = any>(eventType: string, handler: (payload: T, event: AppEvent<T>) => void, context?: any) => Subscription, hasSubscribers: (eventType: string) => boolean, setDebugMode: (enabled: boolean) => void, clear: () => void, getSubscriptionStats: () => {
74
+ subscribers: number;
75
+ eventTypes: number;
76
+ prefixSubscribers: number;
77
+ };
78
+ export {};
79
+ //# sourceMappingURL=pub-sub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pub-sub.d.ts","sourceRoot":"","sources":["../../../src/services/events/pub-sub.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE5F;;GAEG;AACH,cAAM,aAAc,YAAW,cAAc;IAC3C;;;;;;;OAOG;IACH,OAAO,CAAC,CAAC,GAAG,GAAG,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,CAAC,EACV,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,oBAAoB,GAC7B,IAAI;IAUP;;;;;;;OAOG;IACH,SAAS,CAAC,CAAC,GAAG,GAAG,EACf,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAC5B,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,EACjD,OAAO,CAAC,EAAE,GAAG,GACZ,YAAY;IASf;;;;;;;OAOG;IACH,IAAI,CAAC,CAAC,GAAG,GAAG,EACV,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,EACjD,OAAO,CAAC,EAAE,GAAG,GACZ,YAAY;IA2Bf;;;;;OAKG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAI1C;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIpC;;OAEG;IACH,qBAAqB,IAAI,IAAI;IAI7B;;;;OAIG;IACH,oBAAoB,IAAI;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAA;KAAE;CAG/F;AAGD,eAAO,MAAM,mBAAmB,qBAA4B,CAAC;AAG7D,eAAO,MAAM,WAAW,iDAAkD,CAAC;AAG3E,eAAO,MAAM,aAAa,gBAAmB,CAAC;AAG9C,eAAO,MACL,OAAO,qGACP,SAAS,6HACT,IAAI,kHACJ,cAAc,kCACd,YAAY,8BACW,KAAK,cAC5B,oBAAoB;;;;CACL,CAAC"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * src/lib/services/events/pub-sub.ts
3
+ * Higher-level API for the event bus system
4
+ *
5
+ * Provides a simplified interface for publishing and subscribing
6
+ * to events with convenient payload handling and additional features
7
+ * such as once() for one-time subscriptions.
8
+ */
9
+ import { writable, get } from 'svelte/store';
10
+ import { eventBus } from './event-bus';
11
+ /**
12
+ * PubSub service class that implements the IPubSubService interface
13
+ */
14
+ class PubSubService {
15
+ /**
16
+ * Publish an event to all subscribers
17
+ *
18
+ * @param eventType Event type identifier
19
+ * @param payload Event data payload
20
+ * @param source Optional source identifier (component/service name)
21
+ * @param options Additional options for event dispatch
22
+ */
23
+ publish(eventType, payload, source, options) {
24
+ console.log(`[PubSub] Publishing event: ${eventType}, payload:`, payload);
25
+ eventBus.publish({
26
+ type: eventType,
27
+ timestamp: Date.now(),
28
+ source,
29
+ payload
30
+ }, options);
31
+ }
32
+ /**
33
+ * Subscribe to one or more event types
34
+ *
35
+ * @param eventType Event type string or array of event types
36
+ * @param handler Function to handle the event
37
+ * @param context Optional 'this' context for the handler
38
+ * @returns Function to unsubscribe
39
+ */
40
+ subscribe(eventType, handler, context) {
41
+ // Create a wrapper that extracts the payload for convenience
42
+ const wrappedHandler = (event) => {
43
+ handler.call(context, event.payload, event);
44
+ };
45
+ return eventBus.on(eventType, wrappedHandler);
46
+ }
47
+ /**
48
+ * Subscribe to an event only for the first occurrence
49
+ *
50
+ * @param eventType Event type to listen for
51
+ * @param handler Function to handle the event
52
+ * @param context Optional 'this' context for the handler
53
+ * @returns Function to unsubscribe if needed before the event fires
54
+ */
55
+ once(eventType, handler, context) {
56
+ let unsubscribe = null;
57
+ // Create a self-removing handler
58
+ const onceHandler = (event) => {
59
+ // Unsubscribe immediately
60
+ if (unsubscribe) {
61
+ unsubscribe();
62
+ unsubscribe = null;
63
+ }
64
+ // Call the original handler with the payload and event
65
+ handler.call(context, event.payload, event);
66
+ };
67
+ // Subscribe with our wrapper
68
+ unsubscribe = eventBus.on(eventType, onceHandler);
69
+ // Return a function to unsubscribe early if needed
70
+ return () => {
71
+ if (unsubscribe) {
72
+ unsubscribe();
73
+ unsubscribe = null;
74
+ }
75
+ };
76
+ }
77
+ /**
78
+ * Check if an event type has subscribers
79
+ *
80
+ * @param eventType Event type to check
81
+ * @returns Boolean indicating if there are subscribers
82
+ */
83
+ hasSubscribers(eventType) {
84
+ return eventBus.hasSubscribers(eventType);
85
+ }
86
+ /**
87
+ * Set the event bus debug mode
88
+ *
89
+ * @param enabled Whether debug mode should be enabled
90
+ */
91
+ setDebugMode(enabled) {
92
+ eventBus.setDebugMode(enabled);
93
+ }
94
+ /**
95
+ * Clear all event subscriptions
96
+ */
97
+ clearAllSubscriptions() {
98
+ eventBus.clear();
99
+ }
100
+ /**
101
+ * Get statistics about event subscriptions
102
+ *
103
+ * @returns Object with subscription counts
104
+ */
105
+ getSubscriptionStats() {
106
+ return eventBus.getStats();
107
+ }
108
+ }
109
+ // Create a factory function for the PubSub service
110
+ export const createPubSubService = () => new PubSubService();
111
+ // Create a Svelte store for the PubSub service (following architectural guidelines)
112
+ export const pubSubStore = writable(createPubSubService());
113
+ // Export a convenience instance for direct use without store subscription
114
+ export const pubSubService = get(pubSubStore);
115
+ // Export individual functions for easier usage
116
+ export const { publish, subscribe, once, hasSubscribers, setDebugMode, clearAllSubscriptions: clear, getSubscriptionStats } = pubSubService;
117
+ //# sourceMappingURL=pub-sub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pub-sub.js","sourceRoot":"","sources":["../../../src/services/events/pub-sub.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AAItD;;GAEG;AACH,MAAM,aAAa;IACjB;;;;;;;OAOG;IACH,OAAO,CACL,SAAiB,EACjB,OAAU,EACV,MAAe,EACf,OAA8B;QAE9B,OAAO,CAAC,GAAG,CAAC,8BAA8B,SAAS,YAAY,EAAE,OAAO,CAAC,CAAC;QAC1E,QAAQ,CAAC,OAAO,CAAC;YACf,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,MAAM;YACN,OAAO;SACR,EAAE,OAAO,CAAC,CAAC;IACd,CAAC;IAED;;;;;;;OAOG;IACH,SAAS,CACP,SAA4B,EAC5B,OAAiD,EACjD,OAAa;QAEb,6DAA6D;QAC7D,MAAM,cAAc,GAAG,CAAC,KAAkB,EAAE,EAAE;YAC5C,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EA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