@blac/core 2.0.0-rc.14 → 2.0.0-rc.16

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.cts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Internal state for framework adapters, holding tracking and caching data.
5
5
  * @template TBloc - The state container type
6
6
  */
7
- export declare interface AdapterState<TBloc extends StateContainer<any>> {
7
+ export declare interface AdapterState<TBloc extends StateContainerConstructor> {
8
8
  /** Proxy tracker for state property access tracking */
9
9
  tracker: TrackerState<ExtractState<TBloc>> | null;
10
10
  /** Cached manual dependencies for comparison */
@@ -12,20 +12,7 @@ export declare interface AdapterState<TBloc extends StateContainer<any>> {
12
12
  /** Getter tracker for computed property tracking */
13
13
  getterTracker: GetterTrackerState | null;
14
14
  /** Proxied bloc instance for auto-tracking */
15
- proxiedBloc: TBloc | null;
16
- }
17
-
18
- /**
19
- * Base event interface
20
- * Used by Vertex for event-driven state management
21
- */
22
- export declare interface BaseEvent {
23
- /** Event type identifier (typically the class name) */
24
- readonly type: string;
25
- /** Unix timestamp when the event was created */
26
- readonly timestamp: number;
27
- /** Optional source identifier for debugging */
28
- readonly source?: string;
15
+ proxiedBloc: InstanceState<TBloc> | null;
29
16
  }
30
17
 
31
18
  /**
@@ -132,6 +119,16 @@ export declare const BLAC_STATIC_PROPS: {
132
119
  readonly EXCLUDE_FROM_DEVTOOLS: "__excludeFromDevTools";
133
120
  };
134
121
 
122
+ /**
123
+ * Global configuration for @blac/core
124
+ */
125
+ export declare interface BlacConfig {
126
+ /** Enable development mode (enables additional warnings and checks) */
127
+ devMode: boolean;
128
+ /** Logger configuration */
129
+ logger: Partial<LogConfig>;
130
+ }
131
+
135
132
  /**
136
133
  * Configuration options for the @blac decorator.
137
134
  * Only one option can be specified at a time (union type).
@@ -173,11 +170,11 @@ export declare interface BlacPlugin {
173
170
  /**
174
171
  * Called when state changes in a container instance
175
172
  */
176
- onStateChanged?<S>(instance: StateContainer<S>, previousState: S, currentState: S, callstack: string | undefined, context: PluginContext): void;
173
+ onStateChanged?<S extends object = any>(instance: StateContainer<S>, previousState: S, currentState: S, callstack: string | undefined, context: PluginContext): void;
177
174
  /**
178
175
  * Called when an event is added to a Vertex instance
179
176
  */
180
- onEventAdded?<E extends BaseEvent>(vertex: Vertex<any, E>, event: E, context: PluginContext): void;
177
+ onEventAdded?<E extends DiscriminatedEvent>(vertex: Vertex<any, E>, event: EventWithMetadata<E>, context: PluginContext): void;
181
178
  /**
182
179
  * Called when a state container instance is disposed
183
180
  */
@@ -199,7 +196,7 @@ export declare interface BlacPluginWithInit extends BlacPlugin {
199
196
  * Used for type-safe hook parameters.
200
197
  * @template TBloc - The StateContainer instance type
201
198
  */
202
- export declare type BlocConstructor<S = any, T extends new (...args: any[]) => StateContainer<S, any> = new (...args: any[]) => StateContainer<S, any>> = (new (...args: any[]) => InstanceType<T>) & {
199
+ export declare type BlocConstructor<S extends object = any, T extends new (...args: any[]) => StateContainer<S, any> = new (...args: any[]) => StateContainer<S, any>> = (new (...args: any[]) => InstanceType<T>) & {
203
200
  resolve(instanceKey?: string, ...args: any[]): InstanceType<T>;
204
201
  get(instanceKey?: string, ...args: any[]): InstanceType<T> | null;
205
202
  getSafe(instanceKey?: string, ...args: any[]): {
@@ -246,6 +243,26 @@ export declare type BrandedId<B> = Brand<string, B>;
246
243
 
247
244
  /* Excluded from this release type: commitTrackedGetters */
248
245
 
246
+ /**
247
+ * Configure global defaults for @blac/core.
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * import { configureBlac, LogLevel } from '@blac/core';
252
+ *
253
+ * configureBlac({
254
+ * devMode: true,
255
+ * logger: {
256
+ * enabled: true,
257
+ * level: LogLevel.DEBUG
258
+ * }
259
+ * });
260
+ * ```
261
+ *
262
+ * @param config - Partial configuration to merge with defaults
263
+ */
264
+ export declare function configureBlac(config: Partial<BlacConfig>): void;
265
+
249
266
  /**
250
267
  * Configuration function that recreates the default logger
251
268
  *
@@ -267,7 +284,7 @@ export declare function configureLogger(opts: Partial<LogConfig>): void;
267
284
  * @param adapterState - The adapter state for tracking
268
285
  * @returns Snapshot function for use with useSyncExternalStore
269
286
  */
270
- export declare function createAutoTrackSnapshot<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
287
+ export declare function createAutoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
271
288
 
272
289
  /**
273
290
  * Create a subscribe function for auto-tracking mode.
@@ -276,7 +293,7 @@ export declare function createAutoTrackSnapshot<TBloc extends StateContainer<any
276
293
  * @param adapterState - The adapter state for tracking
277
294
  * @returns Subscribe function for use with useSyncExternalStore
278
295
  */
279
- export declare function createAutoTrackSubscribe<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>): SubscribeFunction;
296
+ export declare function createAutoTrackSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SubscribeFunction;
280
297
 
281
298
  /* Excluded from this release type: createBlocProxy */
282
299
 
@@ -339,7 +356,7 @@ export declare function createLogger(config: LogConfig): {
339
356
  * @param config - Configuration with dependencies function
340
357
  * @returns Snapshot function for use with useSyncExternalStore
341
358
  */
342
- export declare function createManualDepsSnapshot<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SnapshotFunction<ExtractState<StateContainerConstructor>>;
359
+ export declare function createManualDepsSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
343
360
 
344
361
  /**
345
362
  * Create a subscribe function for manual dependency tracking mode.
@@ -349,7 +366,7 @@ export declare function createManualDepsSnapshot<TBloc extends StateContainer<an
349
366
  * @param config - Configuration with dependencies function
350
367
  * @returns Subscribe function for use with useSyncExternalStore
351
368
  */
352
- export declare function createManualDepsSubscribe<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
369
+ export declare function createManualDepsSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
353
370
 
354
371
  /**
355
372
  * Create a snapshot function for no-tracking mode.
@@ -357,7 +374,7 @@ export declare function createManualDepsSubscribe<TBloc extends StateContainer<a
357
374
  * @param instance - The state container instance
358
375
  * @returns Snapshot function for use with useSyncExternalStore
359
376
  */
360
- export declare function createNoTrackSnapshot<TBloc extends StateContainer<any, any>>(instance: TBloc): SnapshotFunction<ExtractState<TBloc>>;
377
+ export declare function createNoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
361
378
 
362
379
  /**
363
380
  * Create a subscribe function for no-tracking mode.
@@ -365,7 +382,7 @@ export declare function createNoTrackSnapshot<TBloc extends StateContainer<any,
365
382
  * @param instance - The state container instance
366
383
  * @returns Subscribe function for use with useSyncExternalStore
367
384
  */
368
- export declare function createNoTrackSubscribe<TBloc extends StateContainer<any, any>>(instance: TBloc): SubscribeFunction;
385
+ export declare function createNoTrackSubscribe<TBloc extends StateContainerInstance>(instance: TBloc): SubscribeFunction;
369
386
 
370
387
  /**
371
388
  * Create a plugin manager instance
@@ -391,7 +408,7 @@ export declare function createPluginManager(registry: StateContainerRegistry): P
391
408
  * @template S - State type
392
409
  * @template P - Props type (optional)
393
410
  */
394
- export declare abstract class Cubit<S, P = undefined> extends StateContainer<S, P> {
411
+ export declare abstract class Cubit<S extends object = any, P = undefined> extends StateContainer<S, P> {
395
412
  constructor(initialState: S);
396
413
  /**
397
414
  * Replace state with a new value and notify all listeners
@@ -423,7 +440,22 @@ export declare const debug: (context: string, message: string, data?: any) => vo
423
440
  * @param adapterState - The adapter state
424
441
  * @param rawInstance - The raw bloc instance
425
442
  */
426
- export declare function disableGetterTracking<TBloc extends StateContainer<any, any>>(adapterState: AdapterState<TBloc>, rawInstance: TBloc): void;
443
+ export declare function disableGetterTracking<TBloc extends StateContainerConstructor>(adapterState: AdapterState<TBloc>, rawInstance: InstanceState<TBloc>): void;
444
+
445
+ /**
446
+ * Base type for discriminated union events.
447
+ * All events must have a `type` property as the discriminator.
448
+ *
449
+ * @example
450
+ * ```typescript
451
+ * type MyEvent =
452
+ * | { type: 'increment'; amount: number }
453
+ * | { type: 'decrement' };
454
+ * ```
455
+ */
456
+ export declare interface DiscriminatedEvent {
457
+ readonly type: string;
458
+ }
427
459
 
428
460
  /**
429
461
  * Log an error message (tree-shakeable export)
@@ -434,19 +466,45 @@ export declare function disableGetterTracking<TBloc extends StateContainer<any,
434
466
  export declare const error: (context: string, message: string, data?: any) => void;
435
467
 
436
468
  /**
437
- * Constructor type for event classes
438
- * @template T - Event type
469
+ * Map of event handlers requiring exhaustive coverage.
470
+ * TypeScript enforces that every event type in the union has a handler.
471
+ *
472
+ * @template E - The discriminated event union type
473
+ * @template S - The state type
474
+ *
475
+ * @example
476
+ * ```typescript
477
+ * type CounterEvent =
478
+ * | { type: 'increment'; amount: number }
479
+ * | { type: 'reset' };
480
+ *
481
+ * // All event types must be handled:
482
+ * const handlers: EventHandlerMap<CounterEvent, { count: number }> = {
483
+ * increment: (event, emit) => emit({ count: event.amount }),
484
+ * reset: (_, emit) => emit({ count: 0 }),
485
+ * };
486
+ * ```
439
487
  */
440
- export declare type EventConstructor<T extends BaseEvent = BaseEvent> = new (...args: never[]) => T;
488
+ export declare type EventHandlerMap<E extends DiscriminatedEvent, S extends object> = {
489
+ [K in EventType<E>]: VertexEventHandler<ExtractEvent<E, K>, S>;
490
+ };
491
+
492
+ /* Excluded from this release type: EventMetadata */
441
493
 
442
494
  /**
443
- * Handler function for processing events in Vertex
444
- * @template E - Event type
445
- * @template S - State type
446
- * @param event - The event being handled
447
- * @param emit - Function to emit new state
495
+ * Extract the `type` literal union from a discriminated event union.
496
+ *
497
+ * @template E - The discriminated event union type
498
+ *
499
+ * @example
500
+ * ```typescript
501
+ * type MyEvent = { type: 'a' } | { type: 'b' };
502
+ * type Types = EventType<MyEvent>; // 'a' | 'b'
503
+ * ```
448
504
  */
449
- export declare type EventHandler<E extends BaseEvent, S> = (event: E, emit: (state: S) => void) => void;
505
+ export declare type EventType<E extends DiscriminatedEvent> = E['type'];
506
+
507
+ /* Excluded from this release type: EventWithMetadata */
450
508
 
451
509
  /**
452
510
  * Manages subscriptions to external bloc dependencies for getter tracking.
@@ -465,7 +523,7 @@ export declare class ExternalDependencyManager {
465
523
  * @param onGetterChange - Callback to invoke when external dependency changes
466
524
  * @returns true if subscriptions were updated, false if unchanged
467
525
  */
468
- updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance: StateContainer<any, any>, onGetterChange: () => void): boolean;
526
+ updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance: StateContainerInstance, onGetterChange: () => void): boolean;
469
527
  /**
470
528
  * Clean up all active subscriptions
471
529
  */
@@ -478,6 +536,22 @@ export declare class ExternalDependencyManager {
478
536
  */
479
537
  export declare type ExtractConstructorArgs<T> = T extends new (...args: infer P) => any ? P : never[];
480
538
 
539
+ /**
540
+ * Extract a specific event variant from a union by its type.
541
+ *
542
+ * @template E - The discriminated event union type
543
+ * @template T - The type literal to extract
544
+ *
545
+ * @example
546
+ * ```typescript
547
+ * type MyEvent = { type: 'a'; value: number } | { type: 'b' };
548
+ * type EventA = ExtractEvent<MyEvent, 'a'>; // { type: 'a'; value: number }
549
+ * ```
550
+ */
551
+ export declare type ExtractEvent<E extends DiscriminatedEvent, T extends EventType<E>> = Extract<E, {
552
+ type: T;
553
+ }>;
554
+
481
555
  /**
482
556
  * Extract the props type from a StateContainer
483
557
  * @template T - The StateContainer type
@@ -488,7 +562,9 @@ export declare type ExtractProps<T> = T extends StateContainerConstructor<any, i
488
562
  * Extract the state type from a StateContainer
489
563
  * @template T - The StateContainer type
490
564
  */
491
- export declare type ExtractState<T> = T extends StateContainerConstructor<infer S, any> ? S : never;
565
+ export declare type ExtractState<T> = T extends StateContainerConstructor<infer S, any> ? Readonly<S> : never;
566
+
567
+ export declare type ExtractStateMutable<T> = T extends StateContainerConstructor<infer S, any> ? S : never;
492
568
 
493
569
  /**
494
570
  * Generate ID with timestamp, counter, and random suffix (tree-shakeable)
@@ -533,6 +609,8 @@ export declare function generateSimpleId(prefix: string, affix?: string): string
533
609
 
534
610
  /* Excluded from this release type: getActiveTracker */
535
611
 
612
+ /* Excluded from this release type: getBlacConfig */
613
+
536
614
  /* Excluded from this release type: getDescriptor */
537
615
 
538
616
  /* Excluded from this release type: getGetterExecutionContext */
@@ -555,9 +633,9 @@ export declare function getStaticProp<V, T extends StateContainerConstructor = S
555
633
 
556
634
  declare interface GetterExecutionContext {
557
635
  tracker: GetterTrackerState | null;
558
- currentBloc: StateContainer<any> | null;
636
+ currentBloc: StateContainerInstance | null;
559
637
  depth: number;
560
- visitedBlocs: Set<StateContainer<any>>;
638
+ visitedBlocs: Set<StateContainerInstance>;
561
639
  }
562
640
 
563
641
  /* Excluded from this release type: GetterTrackerState */
@@ -596,7 +674,7 @@ export declare const info: (context: string, message: string, data?: any) => voi
596
674
  * @param instance - The state container instance
597
675
  * @returns Initialized adapter state
598
676
  */
599
- export declare function initAutoTrackState<TBloc extends StateContainer<any, any>>(instance: TBloc): AdapterState<TBloc>;
677
+ export declare function initAutoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
600
678
 
601
679
  /**
602
680
  * Initialize adapter state for manual dependency tracking mode.
@@ -604,7 +682,7 @@ export declare function initAutoTrackState<TBloc extends StateContainer<any, any
604
682
  * @param instance - The state container instance
605
683
  * @returns Initialized adapter state
606
684
  */
607
- export declare function initManualDepsState<TBloc extends StateContainer<any, any>>(instance: TBloc): AdapterState<TBloc>;
685
+ export declare function initManualDepsState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
608
686
 
609
687
  /**
610
688
  * Initialize adapter state for no-tracking mode.
@@ -612,7 +690,7 @@ export declare function initManualDepsState<TBloc extends StateContainer<any, an
612
690
  * @param instance - The state container instance
613
691
  * @returns Initialized adapter state
614
692
  */
615
- export declare function initNoTrackState<TBloc extends StateContainer<any, any>>(instance: TBloc): AdapterState<TBloc>;
693
+ export declare function initNoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
616
694
 
617
695
  /**
618
696
  * Entry in the instance registry, tracking the instance and its reference count
@@ -658,8 +736,21 @@ export declare interface InstanceMetadata {
658
736
  currentState?: any;
659
737
  }
660
738
 
739
+ export declare type InstanceReadonlyState<T extends StateContainerConstructor = any> = Omit<InstanceType<T>, 'state'> & {
740
+ state: ExtractState<T>;
741
+ };
742
+
743
+ export declare type InstanceState<T extends StateContainerConstructor = any> = Omit<InstanceType<T>, 'state'> & {
744
+ state: ExtractStateMutable<T>;
745
+ };
746
+
661
747
  /* Excluded from this release type: invalidateRenderCache */
662
748
 
749
+ /**
750
+ * Check if development mode is enabled.
751
+ */
752
+ export declare function isDevMode(): boolean;
753
+
663
754
  /**
664
755
  * Check if a class should be excluded from DevTools.
665
756
  * Used to prevent infinite loops when DevTools tracks itself.
@@ -752,9 +843,9 @@ export declare enum LogLevel {
752
843
  * Configuration for manual dependency tracking mode
753
844
  * @template TBloc - The state container type
754
845
  */
755
- export declare interface ManualDepsConfig<TBloc extends StateContainer<any>> {
846
+ export declare interface ManualDepsConfig<TBloc extends StateContainerConstructor> {
756
847
  /** Function that returns dependency array from state and bloc */
757
- dependencies: (state: any, bloc: TBloc) => any[];
848
+ dependencies: (state: ExtractState<TBloc>, bloc: InstanceState<TBloc>) => any[];
758
849
  }
759
850
 
760
851
  /* Excluded from this release type: parsePath */
@@ -782,7 +873,7 @@ export declare interface PluginContext {
782
873
  /**
783
874
  * Get current state from a container
784
875
  */
785
- getState<S>(instance: StateContainer<S>): S;
876
+ getState<S extends object = any>(instance: StateContainer<S>): S;
786
877
  /**
787
878
  * Get all instances of a specific type
788
879
  */
@@ -877,6 +968,8 @@ export declare class PluginManager {
877
968
 
878
969
  /* Excluded from this release type: ProxyTrackerState */
879
970
 
971
+ /* Excluded from this release type: resetBlacConfig */
972
+
880
973
  /* Excluded from this release type: resetGetterTracker */
881
974
 
882
975
  /* Excluded from this release type: setActiveTracker */
@@ -903,17 +996,17 @@ export declare type SnapshotFunction<TState> = () => TState;
903
996
  *
904
997
  * @example
905
998
  * ```ts
906
- * class CounterBloc extends StateContainer<number> {
999
+ * class CounterBloc extends StateContainer<{ count: number }> {
907
1000
  * constructor() {
908
- * super(0);
1001
+ * super({ count: 0 });
909
1002
  * }
910
1003
  * increment() {
911
- * this.emit(this.state + 1);
1004
+ * this.emit({ count: this.state.count + 1 });
912
1005
  * }
913
1006
  * }
914
1007
  * ```
915
1008
  */
916
- export declare abstract class StateContainer<S = any, P = any> {
1009
+ export declare abstract class StateContainer<S extends object = any, P = any> {
917
1010
  /* Excluded from this release type: __excludeFromDevTools */
918
1011
  /* Excluded from this release type: _registry */
919
1012
  /**
@@ -990,12 +1083,12 @@ export declare abstract class StateContainer<S = any, P = any> {
990
1083
  * Get all instances of this class
991
1084
  * @returns Array of all instances
992
1085
  */
993
- static getAll<T extends StateContainerConstructor = StateContainerConstructor>(this: T): InstanceType<T>[];
1086
+ static getAll<T extends StateContainerConstructor = StateContainerConstructor>(this: T): InstanceReadonlyState<T>[];
994
1087
  /**
995
1088
  * Iterate over all instances of this class
996
1089
  * @param callback - Function to call for each instance
997
1090
  */
998
- static forEach<T extends StateContainerConstructor = StateContainerConstructor>(this: T, callback: (instance: InstanceType<T>) => void): void;
1091
+ static forEach<T extends StateContainerConstructor = StateContainerConstructor>(this: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
999
1092
  /**
1000
1093
  * Clear all instances of this class (disposes them)
1001
1094
  */
@@ -1049,7 +1142,7 @@ export declare abstract class StateContainer<S = any, P = any> {
1049
1142
  */
1050
1143
  initConfig(config: StateContainerConfig): void;
1051
1144
  /** Current state value */
1052
- get state(): S;
1145
+ get state(): Readonly<S>;
1053
1146
  /** Whether this instance has been disposed */
1054
1147
  get isDisposed(): boolean;
1055
1148
  /**
@@ -1116,7 +1209,11 @@ export declare interface StateContainerConfig {
1116
1209
  * @template S - State type managed by the container
1117
1210
  * @template P - Props type passed to the container
1118
1211
  */
1119
- export declare type StateContainerConstructor<S = any, P = any> = new (...args: any[]) => StateContainer<S, P>;
1212
+ export declare type StateContainerConstructor<S extends object = any, P = any> = new (...args: any[]) => StateContainer<S, P>;
1213
+
1214
+ export declare type StateContainerInstance<S extends object = any, P = any> = Omit<StateContainer<S, P>, 'state'> & {
1215
+ state: Readonly<S>;
1216
+ };
1120
1217
 
1121
1218
  /**
1122
1219
  * Central registry for managing StateContainer instances.
@@ -1220,14 +1317,14 @@ export declare class StateContainerRegistry {
1220
1317
  * @param Type - The StateContainer class constructor
1221
1318
  * @returns Array of all instances
1222
1319
  */
1223
- getAll<T extends StateContainerConstructor>(Type: T): InstanceType<T>[];
1320
+ getAll<T extends StateContainerConstructor>(Type: T): InstanceReadonlyState<T>[];
1224
1321
  /**
1225
1322
  * Safely iterate over all instances of a type.
1226
1323
  * Skips disposed instances and catches callback errors.
1227
1324
  * @param Type - The StateContainer class constructor
1228
1325
  * @param callback - Function to call for each instance
1229
1326
  */
1230
- forEach<T extends StateContainerConstructor>(Type: T, callback: (instance: InstanceType<T>) => void): void;
1327
+ forEach<T extends StateContainerConstructor>(Type: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
1231
1328
  /**
1232
1329
  * Clear all instances of a specific type (disposes them).
1233
1330
  * @param Type - The StateContainer class constructor
@@ -1322,40 +1419,76 @@ export declare interface SystemEventPayloads<S, P> {
1322
1419
  /* Excluded from this release type: TrackerState */
1323
1420
 
1324
1421
  /**
1325
- * Event-driven state container that processes events to update state.
1326
- * Use with event handlers registered via the on() method.
1422
+ * Event-driven state container using discriminated union events.
1423
+ * Extends StateContainer with event-based state transitions and
1424
+ * compile-time exhaustive checking for event handlers.
1327
1425
  *
1328
- * @template S - State type
1329
- * @template E - Event type (extends BaseEvent)
1426
+ * @template S - State type (must be an object)
1427
+ * @template E - Event union type (discriminated by 'type' property)
1330
1428
  * @template P - Props type (optional)
1429
+ *
1430
+ * @example
1431
+ * ```typescript
1432
+ * type CounterEvent =
1433
+ * | { type: 'increment'; amount: number }
1434
+ * | { type: 'decrement' }
1435
+ * | { type: 'reset' };
1436
+ *
1437
+ * class CounterVertex extends Vertex<{ count: number }, CounterEvent> {
1438
+ * constructor() {
1439
+ * super({ count: 0 });
1440
+ * this.createHandlers({
1441
+ * increment: (event, emit) => {
1442
+ * emit({ count: this.state.count + event.amount });
1443
+ * },
1444
+ * decrement: (_, emit) => {
1445
+ * emit({ count: this.state.count - 1 });
1446
+ * },
1447
+ * reset: (_, emit) => {
1448
+ * emit({ count: 0 });
1449
+ * },
1450
+ * });
1451
+ * }
1452
+ *
1453
+ * increment = (amount = 1) => this.add({ type: 'increment', amount });
1454
+ * }
1455
+ * ```
1331
1456
  */
1332
- export declare abstract class Vertex<S, E extends BaseEvent = BaseEvent, P = undefined> extends StateContainer<S, P> {
1333
- private eventHandlers;
1334
- private isProcessing;
1335
- private eventQueue;
1457
+ export declare abstract class Vertex<S extends object = object, E extends DiscriminatedEvent = DiscriminatedEvent, P = undefined> extends StateContainer<S, P> {
1458
+ /* Excluded from this release type: handlers */
1459
+ /* Excluded from this release type: isProcessing */
1460
+ /* Excluded from this release type: eventQueue */
1336
1461
  constructor(initialState: S);
1337
1462
  /**
1338
- * Register a handler for a specific event type
1339
- * @param EventClass - The event class constructor
1340
- * @param handler - Function to handle events of this type
1463
+ * Register all event handlers with exhaustive type checking.
1464
+ * TypeScript will error if any event type from the union is missing.
1465
+ *
1466
+ * @param handlers - Map of event type to handler function
1341
1467
  */
1342
- protected on: <T extends E>(EventClass: EventConstructor<T>, handler: EventHandler<T, S>) => void;
1468
+ protected createHandlers(handlers: EventHandlerMap<E, S>): void;
1343
1469
  /**
1344
- * Add an event to the event stream for processing
1345
- * @param event - The event to process
1470
+ * Dispatch an event for processing.
1471
+ * Events are processed synchronously; if called during processing,
1472
+ * the event is queued and processed after the current event completes.
1473
+ *
1474
+ * @param event - The event to process (must match the event union type)
1346
1475
  */
1347
1476
  add: (event: E) => void;
1348
- private processEvent;
1349
- private handleEvent;
1477
+ /* Excluded from this release type: enrichEvent */
1478
+ /* Excluded from this release type: processEvent */
1479
+ /* Excluded from this release type: handleEvent */
1350
1480
  /**
1351
- * Handle errors that occur during event processing.
1352
- * Override this method to implement custom error handling.
1481
+ * Called when an error occurs during event processing.
1482
+ * Override to implement custom error handling.
1483
+ *
1353
1484
  * @param _event - The event that caused the error
1354
1485
  * @param _error - The error that occurred
1355
1486
  */
1356
- protected onEventError(_event: E, _error: Error): void;
1487
+ protected onEventError(_event: EventWithMetadata<E>, _error: Error): void;
1357
1488
  }
1358
1489
 
1490
+ /* Excluded from this release type: VertexEventHandler */
1491
+
1359
1492
  /**
1360
1493
  * Log a warning message (tree-shakeable export)
1361
1494
  * @param context - Context identifier (module or component name)