@blac/core 2.0.0-rc.15 → 2.0.0-rc.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,32 +1,51 @@
1
1
  /* Excluded from this release type: __resetIdCounters */
2
2
 
3
+ export declare function acquire<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string, options?: AcquireOptions<T>): InstanceType<T>;
4
+
5
+ export declare interface AcquireOptions<T extends StateContainerConstructor> {
6
+ props?: ExtractProps<T>;
7
+ }
8
+
3
9
  /**
4
10
  * Internal state for framework adapters, holding tracking and caching data.
5
11
  * @template TBloc - The state container type
6
12
  */
7
13
  export declare interface AdapterState<TBloc extends StateContainerConstructor> {
8
- /** Proxy tracker for state property access tracking */
9
- tracker: TrackerState<ExtractState<TBloc>> | null;
14
+ /** Dependency tracker for state property access tracking */
15
+ dependencyState: DependencyState<ExtractState<TBloc>> | null;
10
16
  /** Cached manual dependencies for comparison */
11
17
  manualDepsCache: unknown[] | null;
12
- /** Getter tracker for computed property tracking */
13
- getterTracker: GetterTrackerState | null;
18
+ /** Getter state for computed property tracking */
19
+ getterState: GetterState | null;
14
20
  /** Proxied bloc instance for auto-tracking */
15
21
  proxiedBloc: InstanceState<TBloc> | null;
16
22
  }
17
23
 
18
24
  /**
19
- * Base event interface
20
- * Used by Vertex for event-driven state management
25
+ * Initialize adapter state for auto-tracking mode.
26
+ * Creates getter tracker and proxied bloc instance.
27
+ * @param instance - The state container instance
28
+ * @returns Initialized adapter state
21
29
  */
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;
29
- }
30
+ export declare function autoTrackInit<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
31
+
32
+ /**
33
+ * Create a snapshot function for auto-tracking mode.
34
+ * Returns a proxied state that tracks property access.
35
+ * @param instance - The state container instance
36
+ * @param adapterState - The adapter state for tracking
37
+ * @returns Snapshot function for use with useSyncExternalStore
38
+ */
39
+ export declare function autoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
40
+
41
+ /**
42
+ * Create a subscribe function for auto-tracking mode.
43
+ * Only triggers callback when tracked properties change.
44
+ * @param instance - The state container instance
45
+ * @param adapterState - The adapter state for tracking
46
+ * @returns Subscribe function for use with useSyncExternalStore
47
+ */
48
+ export declare function autoTrackSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SubscribeFunction;
30
49
 
31
50
  /**
32
51
  * Decorator to configure StateContainer classes.
@@ -132,6 +151,16 @@ export declare const BLAC_STATIC_PROPS: {
132
151
  readonly EXCLUDE_FROM_DEVTOOLS: "__excludeFromDevTools";
133
152
  };
134
153
 
154
+ /**
155
+ * Global configuration for @blac/core
156
+ */
157
+ export declare interface BlacConfig {
158
+ /** Enable development mode (enables additional warnings and checks) */
159
+ devMode: boolean;
160
+ /** Logger configuration */
161
+ logger: Partial<LogConfig>;
162
+ }
163
+
135
164
  /**
136
165
  * Configuration options for the @blac decorator.
137
166
  * Only one option can be specified at a time (union type).
@@ -177,7 +206,7 @@ export declare interface BlacPlugin {
177
206
  /**
178
207
  * Called when an event is added to a Vertex instance
179
208
  */
180
- onEventAdded?<E extends BaseEvent>(vertex: Vertex<any, E>, event: E, context: PluginContext): void;
209
+ onEventAdded?<E extends DiscriminatedEvent>(vertex: Vertex<any, E>, event: EventWithMetadata<E>, context: PluginContext): void;
181
210
  /**
182
211
  * Called when a state container instance is disposed
183
212
  */
@@ -194,32 +223,56 @@ export declare interface BlacPluginWithInit extends BlacPlugin {
194
223
  onInstall(context: PluginContext): void;
195
224
  }
196
225
 
226
+ declare const BLOC_REF_MARKER: unique symbol;
227
+
197
228
  /**
198
229
  * Constructor type for StateContainer classes with static registry methods.
199
230
  * Used for type-safe hook parameters.
200
231
  * @template TBloc - The StateContainer instance type
201
232
  */
202
233
  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
- resolve(instanceKey?: string, ...args: any[]): InstanceType<T>;
204
- get(instanceKey?: string, ...args: any[]): InstanceType<T> | null;
205
- getSafe(instanceKey?: string, ...args: any[]): {
234
+ acquire(instanceKey?: string, ...args: any[]): InstanceType<T>;
235
+ borrow(instanceKey?: string, ...args: any[]): InstanceType<T> | null;
236
+ borrowSafe(instanceKey?: string, ...args: any[]): {
206
237
  error: Error;
207
238
  instance: null;
208
239
  } | {
209
240
  error: null;
210
241
  instance: InstanceType<T>;
211
242
  };
243
+ ensure(instanceKey?: string): InstanceType<T>;
212
244
  release(instanceKey?: string): void;
213
245
  isolated?: boolean;
214
246
  keepAlive?: boolean;
215
247
  };
216
248
 
249
+ declare type BlocInput = StateContainerConstructor | BlocRef<StateContainerConstructor>;
250
+
217
251
  /**
218
252
  * Extract instance type from an abstract class constructor
219
253
  * @template T - The abstract class constructor type
220
254
  */
221
255
  export declare type BlocInstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;
222
256
 
257
+ /**
258
+ * Reference to a specific bloc instance by class and instance ID.
259
+ */
260
+ export declare interface BlocRef<T extends StateContainerConstructor> {
261
+ [BLOC_REF_MARKER]: true;
262
+ blocClass: T;
263
+ instanceId: string;
264
+ }
265
+
266
+ export declare function borrow<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): InstanceType<T>;
267
+
268
+ export declare function borrowSafe<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): {
269
+ error: Error;
270
+ instance: null;
271
+ } | {
272
+ error: null;
273
+ instance: InstanceType<T>;
274
+ };
275
+
223
276
  /**
224
277
  * Utility type for creating branded/nominal types.
225
278
  * Prevents accidental type confusion between similar primitive types.
@@ -238,14 +291,38 @@ declare const brand: unique symbol;
238
291
  */
239
292
  export declare type BrandedId<B> = Brand<string, B>;
240
293
 
241
- /* Excluded from this release type: captureTrackedPaths */
294
+ /* Excluded from this release type: capturePaths */
295
+
296
+ export declare function clear<T extends StateContainerConstructor>(BlocClass: T): void;
242
297
 
243
298
  /* Excluded from this release type: clearActiveTracker */
244
299
 
300
+ export declare function clearAll(): void;
301
+
245
302
  /* Excluded from this release type: clearExternalDependencies */
246
303
 
247
304
  /* Excluded from this release type: commitTrackedGetters */
248
305
 
306
+ /**
307
+ * Configure global defaults for @blac/core.
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * import { configureBlac, LogLevel } from '@blac/core';
312
+ *
313
+ * configureBlac({
314
+ * devMode: true,
315
+ * logger: {
316
+ * enabled: true,
317
+ * level: LogLevel.DEBUG
318
+ * }
319
+ * });
320
+ * ```
321
+ *
322
+ * @param config - Partial configuration to merge with defaults
323
+ */
324
+ export declare function configureBlac(config: Partial<BlacConfig>): void;
325
+
249
326
  /**
250
327
  * Configuration function that recreates the default logger
251
328
  *
@@ -260,27 +337,15 @@ export declare function configureLogger(opts: Partial<LogConfig>): void;
260
337
 
261
338
  /* Excluded from this release type: createArrayProxy */
262
339
 
263
- /**
264
- * Create a snapshot function for auto-tracking mode.
265
- * Returns a proxied state that tracks property access.
266
- * @param instance - The state container instance
267
- * @param adapterState - The adapter state for tracking
268
- * @returns Snapshot function for use with useSyncExternalStore
269
- */
270
- export declare function createAutoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
340
+ /* Excluded from this release type: createBlocProxy */
271
341
 
272
- /**
273
- * Create a subscribe function for auto-tracking mode.
274
- * Only triggers callback when tracked properties change.
275
- * @param instance - The state container instance
276
- * @param adapterState - The adapter state for tracking
277
- * @returns Subscribe function for use with useSyncExternalStore
278
- */
279
- export declare function createAutoTrackSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SubscribeFunction;
342
+ /* Excluded from this release type: createDependencyProxy */
280
343
 
281
- /* Excluded from this release type: createBlocProxy */
344
+ /* Excluded from this release type: createDependencyState */
345
+
346
+ /* Excluded from this release type: createForTarget */
282
347
 
283
- /* Excluded from this release type: createGetterTracker */
348
+ /* Excluded from this release type: createGetterState */
284
349
 
285
350
  /**
286
351
  * Centralized ID Generation
@@ -307,6 +372,8 @@ export declare function createIdGenerator(prefix: string): {
307
372
  reset: () => void;
308
373
  };
309
374
 
375
+ /* Excluded from this release type: createInternal */
376
+
310
377
  /**
311
378
  * Creates a logger instance with given configuration
312
379
  *
@@ -332,57 +399,29 @@ export declare function createLogger(config: LogConfig): {
332
399
  };
333
400
 
334
401
  /**
335
- * Create a snapshot function for manual dependency tracking mode.
336
- * Caches dependencies for comparison on next render.
337
- * @param instance - The state container instance
338
- * @param adapterState - The adapter state for caching
339
- * @param config - Configuration with dependencies function
340
- * @returns Snapshot function for use with useSyncExternalStore
402
+ * Create a plugin manager instance
403
+ * @param registry - The StateContainerRegistry to monitor for lifecycle events
404
+ * @returns A new PluginManager instance
341
405
  */
342
- export declare function createManualDepsSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
406
+ export declare function createPluginManager(registry: StateContainerRegistry): PluginManager;
343
407
 
344
- /**
345
- * Create a subscribe function for manual dependency tracking mode.
346
- * Only triggers callback when dependencies array changes.
347
- * @param instance - The state container instance
348
- * @param adapterState - The adapter state for caching
349
- * @param config - Configuration with dependencies function
350
- * @returns Subscribe function for use with useSyncExternalStore
351
- */
352
- export declare function createManualDepsSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
408
+ /* Excluded from this release type: createProxyState */
353
409
 
354
410
  /**
355
- * Create a snapshot function for no-tracking mode.
356
- * Returns the raw state directly.
357
- * @param instance - The state container instance
358
- * @returns Snapshot function for use with useSyncExternalStore
411
+ * Create a new tracked context for manual control over tracking.
359
412
  */
360
- export declare function createNoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
413
+ export declare function createTrackedContext(): TrackedContext;
361
414
 
362
415
  /**
363
- * Create a subscribe function for no-tracking mode.
364
- * Triggers callback on every state change.
365
- * @param instance - The state container instance
366
- * @returns Subscribe function for use with useSyncExternalStore
416
+ * Create a tracking proxy for a bloc instance.
417
+ * Tracks both state property access and getter access.
367
418
  */
368
- export declare function createNoTrackSubscribe<TBloc extends StateContainerInstance>(instance: TBloc): SubscribeFunction;
419
+ export declare function createTrackingProxy<T extends StateContainerInstance>(bloc: T, tracker: TrackingProxyState): T;
369
420
 
370
421
  /**
371
- * Create a plugin manager instance
372
- * @param registry - The StateContainerRegistry to monitor for lifecycle events
373
- * @returns A new PluginManager instance
422
+ * Create a new tracking proxy state.
374
423
  */
375
- export declare function createPluginManager(registry: StateContainerRegistry): PluginManager;
376
-
377
- /* Excluded from this release type: createProxy */
378
-
379
- /* Excluded from this release type: createProxyForTarget */
380
-
381
- /* Excluded from this release type: createProxyInternal */
382
-
383
- /* Excluded from this release type: createProxyTrackerState */
384
-
385
- /* Excluded from this release type: createTrackerState */
424
+ export declare function createTrackingProxyState(): TrackingProxyState;
386
425
 
387
426
  /**
388
427
  * Simple state container with direct state emission.
@@ -417,6 +456,45 @@ export declare abstract class Cubit<S extends object = any, P = undefined> exten
417
456
  */
418
457
  export declare const debug: (context: string, message: string, data?: any) => void;
419
458
 
459
+ /**
460
+ * Manages subscriptions to state container dependencies.
461
+ * Provides efficient sync mechanism to add/remove subscriptions
462
+ * as dependencies change between callback invocations.
463
+ */
464
+ export declare class DependencyManager {
465
+ private subscriptions;
466
+ private currentDeps;
467
+ /**
468
+ * Sync subscriptions with a new set of dependencies.
469
+ * Adds subscriptions for new deps, removes subscriptions for stale deps.
470
+ *
471
+ * @param newDeps - The new set of dependencies to subscribe to
472
+ * @param onChange - Callback to invoke when any dependency changes
473
+ * @param exclude - Optional instance to exclude from subscriptions (e.g., primary bloc)
474
+ * @returns true if the dependency set changed, false if unchanged
475
+ */
476
+ sync(newDeps: Set<StateContainerInstance>, onChange: () => void, exclude?: StateContainerInstance): boolean;
477
+ /**
478
+ * Add a single dependency subscription.
479
+ */
480
+ add(dep: StateContainerInstance, onChange: () => void): void;
481
+ /**
482
+ * Check if a dependency is currently subscribed.
483
+ */
484
+ has(dep: StateContainerInstance): boolean;
485
+ /**
486
+ * Get the current set of dependencies.
487
+ */
488
+ getDependencies(): Set<StateContainerInstance>;
489
+ /**
490
+ * Clean up all active subscriptions.
491
+ */
492
+ cleanup(): void;
493
+ private areSetsEqual;
494
+ }
495
+
496
+ /* Excluded from this release type: DependencyState */
497
+
420
498
  /**
421
499
  * Disable getter tracking after render phase completes.
422
500
  * Clears the active tracker to prevent tracking outside of render.
@@ -425,6 +503,27 @@ export declare const debug: (context: string, message: string, data?: any) => vo
425
503
  */
426
504
  export declare function disableGetterTracking<TBloc extends StateContainerConstructor>(adapterState: AdapterState<TBloc>, rawInstance: InstanceState<TBloc>): void;
427
505
 
506
+ /**
507
+ * Base type for discriminated union events.
508
+ * All events must have a `type` property as the discriminator.
509
+ *
510
+ * @example
511
+ * ```typescript
512
+ * type MyEvent =
513
+ * | { type: 'increment'; amount: number }
514
+ * | { type: 'decrement' };
515
+ * ```
516
+ */
517
+ export declare interface DiscriminatedEvent {
518
+ readonly type: string;
519
+ }
520
+
521
+ /* Excluded from this release type: EmptyState */
522
+
523
+ /* Excluded from this release type: EmptyState_2 */
524
+
525
+ export declare function ensure<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): InstanceType<T>;
526
+
428
527
  /**
429
528
  * Log an error message (tree-shakeable export)
430
529
  * @param context - Context identifier (module or component name)
@@ -434,29 +533,56 @@ export declare function disableGetterTracking<TBloc extends StateContainerConstr
434
533
  export declare const error: (context: string, message: string, data?: any) => void;
435
534
 
436
535
  /**
437
- * Constructor type for event classes
438
- * @template T - Event type
536
+ * Map of event handlers requiring exhaustive coverage.
537
+ * TypeScript enforces that every event type in the union has a handler.
538
+ *
539
+ * @template E - The discriminated event union type
540
+ * @template S - The state type
541
+ *
542
+ * @example
543
+ * ```typescript
544
+ * type CounterEvent =
545
+ * | { type: 'increment'; amount: number }
546
+ * | { type: 'reset' };
547
+ *
548
+ * // All event types must be handled:
549
+ * const handlers: EventHandlerMap<CounterEvent, { count: number }> = {
550
+ * increment: (event, emit) => emit({ count: event.amount }),
551
+ * reset: (_, emit) => emit({ count: 0 }),
552
+ * };
553
+ * ```
439
554
  */
440
- export declare type EventConstructor<T extends BaseEvent = BaseEvent> = new (...args: never[]) => T;
555
+ export declare type EventHandlerMap<E extends DiscriminatedEvent, S extends object> = {
556
+ [K in EventType<E>]: VertexEventHandler<ExtractEvent<E, K>, S>;
557
+ };
558
+
559
+ /* Excluded from this release type: EventMetadata */
441
560
 
442
561
  /**
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
562
+ * Extract the `type` literal union from a discriminated event union.
563
+ *
564
+ * @template E - The discriminated event union type
565
+ *
566
+ * @example
567
+ * ```typescript
568
+ * type MyEvent = { type: 'a' } | { type: 'b' };
569
+ * type Types = EventType<MyEvent>; // 'a' | 'b'
570
+ * ```
448
571
  */
449
- export declare type EventHandler<E extends BaseEvent, S> = (event: E, emit: (state: S) => void) => void;
572
+ export declare type EventType<E extends DiscriminatedEvent> = E['type'];
573
+
574
+ /* Excluded from this release type: EventWithMetadata */
450
575
 
451
576
  /**
452
577
  * Manages subscriptions to external bloc dependencies for getter tracking.
453
578
  * When a getter accesses another bloc's state, this manager ensures
454
579
  * re-renders occur when those external dependencies change.
580
+ *
581
+ * @deprecated Use DependencyManager from tracking module instead.
582
+ * This class is kept for backward compatibility.
455
583
  */
456
- export declare class ExternalDependencyManager {
457
- private subscriptions;
458
- private previousDeps;
459
- private areDependenciesEqual;
584
+ export declare class ExternalDepsManager {
585
+ private manager;
460
586
  /**
461
587
  * Update subscriptions to external bloc dependencies.
462
588
  * Creates subscriptions to blocs accessed via getters.
@@ -465,7 +591,7 @@ export declare class ExternalDependencyManager {
465
591
  * @param onGetterChange - Callback to invoke when external dependency changes
466
592
  * @returns true if subscriptions were updated, false if unchanged
467
593
  */
468
- updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance: StateContainerInstance, onGetterChange: () => void): boolean;
594
+ updateSubscriptions(getterState: GetterState | null, rawInstance: StateContainerInstance, onGetterChange: () => void): boolean;
469
595
  /**
470
596
  * Clean up all active subscriptions
471
597
  */
@@ -478,6 +604,28 @@ export declare class ExternalDependencyManager {
478
604
  */
479
605
  export declare type ExtractConstructorArgs<T> = T extends new (...args: infer P) => any ? P : never[];
480
606
 
607
+ /**
608
+ * Extract a specific event variant from a union by its type.
609
+ *
610
+ * @template E - The discriminated event union type
611
+ * @template T - The type literal to extract
612
+ *
613
+ * @example
614
+ * ```typescript
615
+ * type MyEvent = { type: 'a'; value: number } | { type: 'b' };
616
+ * type EventA = ExtractEvent<MyEvent, 'a'>; // { type: 'a'; value: number }
617
+ * ```
618
+ */
619
+ export declare type ExtractEvent<E extends DiscriminatedEvent, T extends EventType<E>> = Extract<E, {
620
+ type: T;
621
+ }>;
622
+
623
+ declare type ExtractInstance<T> = T extends BlocRef<infer C> ? InstanceType<C> : T extends StateContainerConstructor ? InstanceType<T> : never;
624
+
625
+ declare type ExtractInstances<T extends readonly BlocInput[]> = {
626
+ [K in keyof T]: ExtractInstance<T[K]>;
627
+ };
628
+
481
629
  /**
482
630
  * Extract the props type from a StateContainer
483
631
  * @template T - The StateContainer type
@@ -490,8 +638,16 @@ export declare type ExtractProps<T> = T extends StateContainerConstructor<any, i
490
638
  */
491
639
  export declare type ExtractState<T> = T extends StateContainerConstructor<infer S, any> ? Readonly<S> : never;
492
640
 
641
+ /**
642
+ * Constrain a type to extract state only from stateful containers.
643
+ * Returns `never` for stateless containers.
644
+ */
645
+ export declare type ExtractStatefulState<T extends StateContainerConstructor> = IsStatelessContainer<T> extends true ? never : ExtractState<T>;
646
+
493
647
  export declare type ExtractStateMutable<T> = T extends StateContainerConstructor<infer S, any> ? S : never;
494
648
 
649
+ export declare function forEach<T extends StateContainerConstructor>(BlocClass: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
650
+
495
651
  /**
496
652
  * Generate ID with timestamp, counter, and random suffix (tree-shakeable)
497
653
  *
@@ -535,6 +691,10 @@ export declare function generateSimpleId(prefix: string, affix?: string): string
535
691
 
536
692
  /* Excluded from this release type: getActiveTracker */
537
693
 
694
+ export declare function getAll<T extends StateContainerConstructor>(BlocClass: T): InstanceReadonlyState<T>[];
695
+
696
+ /* Excluded from this release type: getBlacConfig */
697
+
538
698
  /* Excluded from this release type: getDescriptor */
539
699
 
540
700
  /* Excluded from this release type: getGetterExecutionContext */
@@ -544,6 +704,10 @@ export declare function generateSimpleId(prefix: string, affix?: string): string
544
704
  */
545
705
  export declare function getPluginManager(): any;
546
706
 
707
+ export declare function getRefCount<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): number;
708
+
709
+ export declare function getRegistry(): StateContainerRegistry;
710
+
547
711
  /**
548
712
  * Get a static property from a class constructor
549
713
  * Type-safe helper that avoids (Type as any) casts
@@ -555,14 +719,20 @@ export declare function getPluginManager(): any;
555
719
  */
556
720
  export declare function getStaticProp<V, T extends StateContainerConstructor = StateContainerConstructor>(Type: T, propName: string, defaultValue?: V): V | undefined;
557
721
 
722
+ export declare function getStats(): {
723
+ registeredTypes: number;
724
+ totalInstances: number;
725
+ typeBreakdown: Record<string, number>;
726
+ };
727
+
558
728
  declare interface GetterExecutionContext {
559
- tracker: GetterTrackerState | null;
729
+ tracker: GetterState | null;
560
730
  currentBloc: StateContainerInstance | null;
561
731
  depth: number;
562
732
  visitedBlocs: Set<StateContainerInstance>;
563
733
  }
564
734
 
565
- /* Excluded from this release type: GetterTrackerState */
735
+ /* Excluded from this release type: GetterState */
566
736
 
567
737
  /* Excluded from this release type: getValueAtPath */
568
738
 
@@ -571,7 +741,7 @@ declare interface GetterExecutionContext {
571
741
  */
572
742
  export declare const globalRegistry: StateContainerRegistry;
573
743
 
574
- /* Excluded from this release type: hasChanges */
744
+ /* Excluded from this release type: hasDependencyChanges */
575
745
 
576
746
  /* Excluded from this release type: hasGetterChanges */
577
747
 
@@ -582,8 +752,15 @@ export declare const globalRegistry: StateContainerRegistry;
582
752
  */
583
753
  export declare function hasInitHook(plugin: BlacPlugin): plugin is BlacPluginWithInit;
584
754
 
755
+ export declare function hasInstance<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): boolean;
756
+
585
757
  /* Excluded from this release type: hasTrackedData */
586
758
 
759
+ /**
760
+ * Check if tracked state or getters have changed.
761
+ */
762
+ export declare function hasTrackingProxyChanges(tracker: TrackingProxyState, bloc: StateContainerInstance): boolean;
763
+
587
764
  /**
588
765
  * Log an info message (tree-shakeable export)
589
766
  * @param context - Context identifier (module or component name)
@@ -593,28 +770,16 @@ export declare function hasInitHook(plugin: BlacPlugin): plugin is BlacPluginWit
593
770
  export declare const info: (context: string, message: string, data?: any) => void;
594
771
 
595
772
  /**
596
- * Initialize adapter state for auto-tracking mode.
597
- * Creates getter tracker and proxied bloc instance.
598
- * @param instance - The state container instance
599
- * @returns Initialized adapter state
600
- */
601
- export declare function initAutoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
602
-
603
- /**
604
- * Initialize adapter state for manual dependency tracking mode.
605
- * No proxy is created; bloc is used directly.
606
- * @param instance - The state container instance
607
- * @returns Initialized adapter state
608
- */
609
- export declare function initManualDepsState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
610
-
611
- /**
612
- * Initialize adapter state for no-tracking mode.
613
- * No tracking or proxy is created.
614
- * @param instance - The state container instance
615
- * @returns Initialized adapter state
773
+ * Create a reference to a specific bloc instance.
774
+ *
775
+ * @example
776
+ * ```ts
777
+ * watch(instance(UserBloc, 'user-123'), (userBloc) => {
778
+ * console.log(userBloc.state.name);
779
+ * });
780
+ * ```
616
781
  */
617
- export declare function initNoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
782
+ export declare function instance<T extends StateContainerConstructor>(BlocClass: T, instanceId: string): BlocRef<T>;
618
783
 
619
784
  /**
620
785
  * Entry in the instance registry, tracking the instance and its reference count
@@ -670,6 +835,11 @@ export declare type InstanceState<T extends StateContainerConstructor = any> = O
670
835
 
671
836
  /* Excluded from this release type: invalidateRenderCache */
672
837
 
838
+ /**
839
+ * Check if development mode is enabled.
840
+ */
841
+ export declare function isDevMode(): boolean;
842
+
673
843
  /**
674
844
  * Check if a class should be excluded from DevTools.
675
845
  * Used to prevent infinite loops when DevTools tracks itself.
@@ -705,6 +875,22 @@ export declare function isKeepAliveClass<T extends StateContainerConstructor>(Ty
705
875
 
706
876
  /* Excluded from this release type: isProxyable */
707
877
 
878
+ /**
879
+ * Check if a class is a stateless container (StatelessCubit or StatelessVertex).
880
+ * Stateless containers don't have state, emit, update, or subscribe methods.
881
+ * @param Type - The class constructor to check
882
+ * @returns true if the class is a stateless container
883
+ */
884
+ export declare function isStatelessClass<T extends StateContainerConstructor>(Type: T): boolean;
885
+
886
+ /**
887
+ * Check if a StateContainer constructor is a stateless container.
888
+ * Returns true for StatelessCubit and StatelessVertex classes.
889
+ */
890
+ export declare type IsStatelessContainer<T> = T extends {
891
+ readonly [STATELESS_MARKER]: true;
892
+ } ? true : false;
893
+
708
894
  /**
709
895
  * Lifecycle events emitted by the registry
710
896
  */
@@ -767,6 +953,58 @@ export declare interface ManualDepsConfig<TBloc extends StateContainerConstructo
767
953
  dependencies: (state: ExtractState<TBloc>, bloc: InstanceState<TBloc>) => any[];
768
954
  }
769
955
 
956
+ /**
957
+ * Initialize adapter state for manual dependency tracking mode.
958
+ * No proxy is created; bloc is used directly.
959
+ * @param instance - The state container instance
960
+ * @returns Initialized adapter state
961
+ */
962
+ export declare function manualDepsInit<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
963
+
964
+ /**
965
+ * Create a snapshot function for manual dependency tracking mode.
966
+ * Caches dependencies for comparison on next render.
967
+ * @param instance - The state container instance
968
+ * @param adapterState - The adapter state for caching
969
+ * @param config - Configuration with dependencies function
970
+ * @returns Snapshot function for use with useSyncExternalStore
971
+ */
972
+ export declare function manualDepsSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
973
+
974
+ /**
975
+ * Create a subscribe function for manual dependency tracking mode.
976
+ * Only triggers callback when dependencies array changes.
977
+ * @param instance - The state container instance
978
+ * @param adapterState - The adapter state for caching
979
+ * @param config - Configuration with dependencies function
980
+ * @returns Subscribe function for use with useSyncExternalStore
981
+ */
982
+ export declare function manualDepsSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
983
+
984
+ /**
985
+ * Initialize adapter state for no-tracking mode.
986
+ * No tracking or proxy is created.
987
+ * @param instance - The state container instance
988
+ * @returns Initialized adapter state
989
+ */
990
+ export declare function noTrackInit<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
991
+
992
+ /**
993
+ * Create a snapshot function for no-tracking mode.
994
+ * Returns the raw state directly.
995
+ * @param instance - The state container instance
996
+ * @returns Snapshot function for use with useSyncExternalStore
997
+ */
998
+ export declare function noTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
999
+
1000
+ /**
1001
+ * Create a subscribe function for no-tracking mode.
1002
+ * Triggers callback on every state change.
1003
+ * @param instance - The state container instance
1004
+ * @returns Subscribe function for use with useSyncExternalStore
1005
+ */
1006
+ export declare function noTrackSubscribe<TBloc extends StateContainerInstance>(instance: TBloc): SubscribeFunction;
1007
+
770
1008
  /* Excluded from this release type: parsePath */
771
1009
 
772
1010
  /* Excluded from this release type: PathInfo */
@@ -885,12 +1123,20 @@ export declare class PluginManager {
885
1123
  private getCurrentEnvironment;
886
1124
  }
887
1125
 
888
- /* Excluded from this release type: ProxyTrackerState */
1126
+ /* Excluded from this release type: ProxyState */
1127
+
1128
+ export declare function register<T extends StateContainerConstructor>(BlocClass: T, isolated?: boolean): void;
1129
+
1130
+ export declare function release<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string, forceDispose?: boolean): void;
889
1131
 
890
- /* Excluded from this release type: resetGetterTracker */
1132
+ /* Excluded from this release type: resetBlacConfig */
1133
+
1134
+ /* Excluded from this release type: resetGetterState */
891
1135
 
892
1136
  /* Excluded from this release type: setActiveTracker */
893
1137
 
1138
+ export declare function setRegistry(registry: StateContainerRegistry): void;
1139
+
894
1140
  /* Excluded from this release type: shallowEqual */
895
1141
 
896
1142
  /**
@@ -899,9 +1145,14 @@ export declare class PluginManager {
899
1145
  */
900
1146
  export declare type SnapshotFunction<TState> = () => TState;
901
1147
 
902
- /* Excluded from this release type: startProxyTracking */
1148
+ /* Excluded from this release type: startDependency */
903
1149
 
904
- /* Excluded from this release type: startTracking */
1150
+ /* Excluded from this release type: startProxy */
1151
+
1152
+ /**
1153
+ * Start tracking on a tracking proxy.
1154
+ */
1155
+ export declare function startTrackingProxy(tracker: TrackingProxyState): void;
905
1156
 
906
1157
  /**
907
1158
  * Abstract base class for all state containers in BlaC.
@@ -924,117 +1175,8 @@ export declare type SnapshotFunction<TState> = () => TState;
924
1175
  * ```
925
1176
  */
926
1177
  export declare abstract class StateContainer<S extends object = any, P = any> {
927
- /* Excluded from this release type: __excludeFromDevTools */
928
- /* Excluded from this release type: _registry */
929
- /**
930
- * Get the global StateContainerRegistry
931
- * @returns The registry managing all state container instances
932
- */
933
- static getRegistry(): StateContainerRegistry;
934
- /**
935
- * Replace the global registry (clears existing instances)
936
- * @param registry - The new registry to use
937
- */
938
- static setRegistry(registry: StateContainerRegistry): void;
939
- /**
940
- * Register this class with the global registry
941
- * @param isolated - Whether instances should be isolated (component-scoped)
942
- */
943
- static register<T extends StateContainerConstructor>(this: T, isolated?: boolean): void;
944
- /**
945
- * Resolve an instance with ref counting (ownership semantics).
946
- * Creates a new instance if one doesn't exist, or returns existing and increments ref count.
947
- * @template S - Optional state type override for generic StateContainers
948
- * @template T - The StateContainer type (inferred from class)
949
- * @param instanceKey - Optional instance key (defaults to 'default')
950
- * @param options - Resolution options (canCreate, countRef, props, trackExecutionContext)
951
- * @returns The state container instance
952
- */
953
- static resolve<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string, options?: {
954
- canCreate?: boolean;
955
- countRef?: boolean;
956
- props?: ExtractProps<T>;
957
- trackExecutionContext?: boolean;
958
- }): InstanceType<T>;
959
- /**
960
- * Get an existing instance without incrementing ref count (borrowing semantics).
961
- * @template S - Optional state type override for generic StateContainers
962
- * @template T - The StateContainer type (inferred from class)
963
- * @param instanceKey - Optional instance key (defaults to 'default')
964
- * @returns The state container instance
965
- * @throws Error if instance doesn't exist
966
- */
967
- static get<T extends StateContainerConstructor<any> = StateContainerConstructor<any>>(this: T, instanceKey?: string): InstanceType<T>;
968
- /**
969
- * Safely get an existing instance with error handling.
970
- * @template S - Optional state type override for generic StateContainers
971
- * @template T - The StateContainer type (inferred from class)
972
- * @param instanceKey - Optional instance key (defaults to 'default')
973
- * @returns Discriminated union with either the instance or an error
974
- */
975
- static getSafe<T extends StateContainerConstructor<any> = StateContainerConstructor<any>>(this: T, instanceKey?: string): {
976
- error: Error;
977
- instance: null;
978
- } | {
979
- error: null;
980
- instance: InstanceType<T>;
981
- };
982
- /**
983
- * Connect to an instance for bloc-to-bloc communication (borrowing semantics).
984
- * Gets or creates instance without incrementing ref count.
985
- * Tracks cross-bloc dependency for reactive updates.
986
- * @template S - Optional state type override for generic StateContainers
987
- * @template T - The StateContainer type (inferred from class)
988
- * @param instanceKey - Optional instance key (defaults to 'default')
989
- * @returns The state container instance
990
- */
991
- static connect<T extends StateContainerConstructor<any> = StateContainerConstructor<any>>(this: T, instanceKey?: string): InstanceType<T>;
992
- /**
993
- * Release a reference to an instance.
994
- * Decrements ref count and disposes when it reaches 0 (unless keepAlive).
995
- * @param instanceKey - Optional instance key (defaults to 'default')
996
- * @param forceDispose - Force immediate disposal regardless of ref count
997
- */
998
- static release<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string, forceDispose?: boolean): void;
999
- /**
1000
- * Get all instances of this class
1001
- * @returns Array of all instances
1002
- */
1003
- static getAll<T extends StateContainerConstructor = StateContainerConstructor>(this: T): InstanceReadonlyState<T>[];
1004
- /**
1005
- * Iterate over all instances of this class
1006
- * @param callback - Function to call for each instance
1007
- */
1008
- static forEach<T extends StateContainerConstructor = StateContainerConstructor>(this: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
1009
- /**
1010
- * Clear all instances of this class (disposes them)
1011
- */
1012
- static clear<T extends StateContainerConstructor = StateContainerConstructor>(this: T): void;
1013
- /**
1014
- * Clear all instances from all registered types
1015
- */
1016
- static clearAllInstances(): void;
1017
- /**
1018
- * Get registry statistics for debugging
1019
- * @returns Object with registeredTypes, totalInstances, and typeBreakdown
1020
- */
1021
- static getStats(): {
1022
- registeredTypes: number;
1023
- totalInstances: number;
1024
- typeBreakdown: Record<string, number>;
1025
- };
1026
- /**
1027
- * Get reference count for an instance
1028
- * @param instanceKey - Optional instance key (defaults to 'default')
1029
- * @returns Current ref count (0 if instance doesn't exist)
1030
- */
1031
- static getRefCount<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string): number;
1032
- /**
1033
- * Check if an instance exists
1034
- * @param instanceKey - Optional instance key (defaults to 'default')
1035
- * @returns true if instance exists
1036
- */
1037
- static hasInstance<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string): boolean;
1178
+ static __excludeFromDevTools: boolean;
1179
+ static enableStackTrace: boolean;
1038
1180
  private _state;
1039
1181
  private readonly listeners;
1040
1182
  private _disposed;
@@ -1079,8 +1221,6 @@ export declare abstract class StateContainer<S extends object = any, P = any> {
1079
1221
  * @protected
1080
1222
  */
1081
1223
  protected emit(newState: S): void;
1082
- /** Whether to capture stack traces on state changes (disabled in production) */
1083
- static enableStackTrace: boolean;
1084
1224
  private captureStackTrace;
1085
1225
  private formatStackLine;
1086
1226
  private cleanFilePath;
@@ -1139,7 +1279,8 @@ export declare type StateContainerInstance<S extends object = any, P = any> = Om
1139
1279
  * @example
1140
1280
  * ```ts
1141
1281
  * const registry = new StateContainerRegistry();
1142
- * const instance = registry.resolve(MyBloc);
1282
+ * const instance = registry.acquire(MyBloc); // ownership, must release
1283
+ * const other = registry.ensure(OtherBloc); // no ownership, bloc-to-bloc
1143
1284
  * registry.on('stateChanged', (container, prev, next) => {
1144
1285
  * console.log('State changed:', prev, '->', next);
1145
1286
  * });
@@ -1169,40 +1310,41 @@ export declare class StateContainerRegistry {
1169
1310
  getInstancesMap<T extends StateContainerConstructor>(Type: T): Map<string, InstanceEntry>;
1170
1311
  private trackExecutionContext;
1171
1312
  /**
1172
- * Resolve an instance with ref counting (ownership semantics).
1313
+ * Acquire an instance with ref counting (ownership semantics).
1173
1314
  * Creates a new instance if one doesn't exist, or returns existing and increments ref count.
1315
+ * You must call `release()` when done to decrement the ref count.
1174
1316
  * @param Type - The StateContainer class constructor
1175
1317
  * @param instanceKey - Instance key (defaults to 'default')
1176
- * @param options - Resolution options
1318
+ * @param options - Acquisition options
1177
1319
  * @param options.canCreate - Whether to create new instance if not found (default: true)
1178
1320
  * @param options.countRef - Whether to increment ref count (default: true)
1179
1321
  * @param options.props - Props to pass to constructor if creating new instance
1180
1322
  * @param options.trackExecutionContext - Whether to track cross-bloc dependency (default: false)
1181
1323
  * @returns The state container instance
1182
1324
  */
1183
- resolve<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string, options?: {
1325
+ acquire<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string, options?: {
1184
1326
  canCreate?: boolean;
1185
1327
  countRef?: boolean;
1186
1328
  props?: ExtractProps<T>;
1187
1329
  trackExecutionContext?: boolean;
1188
1330
  }): InstanceType<T>;
1189
1331
  /**
1190
- * Get an existing instance without incrementing ref count (borrowing semantics).
1332
+ * Borrow an existing instance without incrementing ref count (borrowing semantics).
1191
1333
  * Tracks cross-bloc dependency for reactive updates.
1192
1334
  * @param Type - The StateContainer class constructor
1193
1335
  * @param instanceKey - Instance key (defaults to 'default')
1194
1336
  * @returns The state container instance
1195
1337
  * @throws Error if instance doesn't exist
1196
1338
  */
1197
- get<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
1339
+ borrow<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
1198
1340
  /**
1199
- * Safely get an existing instance (borrowing semantics with error handling).
1341
+ * Safely borrow an existing instance (borrowing semantics with error handling).
1200
1342
  * Returns discriminated union for type-safe conditional access.
1201
1343
  * @param Type - The StateContainer class constructor
1202
1344
  * @param instanceKey - Instance key (defaults to 'default')
1203
1345
  * @returns Discriminated union with either the instance or an error
1204
1346
  */
1205
- getSafe<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): {
1347
+ borrowSafe<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): {
1206
1348
  error: Error;
1207
1349
  instance: null;
1208
1350
  } | {
@@ -1210,7 +1352,7 @@ export declare class StateContainerRegistry {
1210
1352
  instance: InstanceType<T>;
1211
1353
  };
1212
1354
  /**
1213
- * Connect to an instance with borrowing semantics (for B2B communication).
1355
+ * Ensure an instance exists without taking ownership (for bloc-to-bloc communication).
1214
1356
  * Gets existing instance OR creates it if it doesn't exist, without incrementing ref count.
1215
1357
  * Tracks cross-bloc dependency for reactive updates.
1216
1358
  *
@@ -1220,7 +1362,7 @@ export declare class StateContainerRegistry {
1220
1362
  * @param instanceKey - Instance key (defaults to 'default')
1221
1363
  * @returns The state container instance
1222
1364
  */
1223
- connect<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
1365
+ ensure<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
1224
1366
  /**
1225
1367
  * Release a reference to an instance.
1226
1368
  * Decrements ref count and disposes when it reaches 0 (unless keepAlive).
@@ -1292,9 +1434,195 @@ export declare class StateContainerRegistry {
1292
1434
  /* Excluded from this release type: emit */
1293
1435
  }
1294
1436
 
1437
+ /**
1438
+ * Constrain a type to only accept stateful containers (not StatelessCubit/StatelessVertex).
1439
+ * Use this to reject stateless containers at the type level.
1440
+ */
1441
+ export declare type StatefulContainerOnly<T extends StateContainerConstructor> = IsStatelessContainer<T> extends true ? never : T;
1442
+
1443
+ /**
1444
+ * Marker symbol to identify stateless containers at the type level.
1445
+ * Used by React hooks to prevent `useBloc` from accepting stateless containers.
1446
+ */
1447
+ export declare const STATELESS_MARKER: unique symbol;
1448
+
1449
+ /**
1450
+ * A Cubit without state management capabilities.
1451
+ * Use this for action-only containers that don't need to manage or emit state.
1452
+ *
1453
+ * StatelessCubit:
1454
+ * - Has no `emit()`, `update()`, or `patch()` methods
1455
+ * - Has no accessible `state` property
1456
+ * - Cannot be subscribed to (throws error)
1457
+ * - Is rejected by `useBloc` hook (use `useBlocActions` instead)
1458
+ *
1459
+ * @template P - Props type (optional)
1460
+ *
1461
+ * @example
1462
+ * ```typescript
1463
+ * class AnalyticsService extends StatelessCubit {
1464
+ * trackPageView(page: string) {
1465
+ * analytics.track('page_view', { page });
1466
+ * }
1467
+ *
1468
+ * trackClick(element: string) {
1469
+ * analytics.track('click', { element });
1470
+ * }
1471
+ * }
1472
+ *
1473
+ * // In React component:
1474
+ * const analytics = useBlocActions(AnalyticsService);
1475
+ * analytics.trackPageView('/home');
1476
+ * ```
1477
+ */
1478
+ export declare abstract class StatelessCubit<P = undefined> extends Cubit<EmptyState, P> {
1479
+ /* Excluded from this release type: [STATELESS_MARKER] */
1480
+ constructor();
1481
+ /**
1482
+ * State is not available on StatelessCubit.
1483
+ * @throws Always throws an error when accessed.
1484
+ */
1485
+ get state(): never;
1486
+ /**
1487
+ * Subscriptions are not available on StatelessCubit.
1488
+ * @throws Always throws an error when called.
1489
+ */
1490
+ subscribe(_listener: (state: EmptyState) => void): never;
1491
+ /**
1492
+ * emit() is not available on StatelessCubit.
1493
+ * TypeScript will show an error if you try to call this method.
1494
+ */
1495
+ emit(_newState: never): never;
1496
+ /**
1497
+ * update() is not available on StatelessCubit.
1498
+ * TypeScript will show an error if you try to call this method.
1499
+ */
1500
+ update(_updater: never): never;
1501
+ /**
1502
+ * patch() is not available on StatelessCubit.
1503
+ * @throws Error always - StatelessCubit does not support state changes
1504
+ */
1505
+ patch: (_partial: Partial<EmptyState>) => void;
1506
+ }
1507
+
1508
+ /**
1509
+ * Event handler for StatelessVertex that receives only the event (no emit function).
1510
+ * Use for side-effect-only event processing.
1511
+ */
1512
+ export declare type StatelessEventHandler<E extends DiscriminatedEvent> = (event: EventWithMetadata<E>) => void;
1513
+
1514
+ /**
1515
+ * Map of event types to their handlers for StatelessVertex.
1516
+ * Enforces exhaustive handling of all event types in the union.
1517
+ */
1518
+ export declare type StatelessEventHandlerMap<E extends DiscriminatedEvent> = {
1519
+ [K in E['type']]: StatelessEventHandler<Extract<E, {
1520
+ type: K;
1521
+ }>>;
1522
+ };
1523
+
1524
+ /**
1525
+ * An event-driven container without state management capabilities.
1526
+ * Use this for event processing that only produces side effects (logging, analytics, etc).
1527
+ *
1528
+ * StatelessVertex:
1529
+ * - Processes events via `add()` method
1530
+ * - Handlers receive only the event (no `emit` function)
1531
+ * - Has no accessible `state` property
1532
+ * - Cannot be subscribed to (throws error)
1533
+ * - Is rejected by `useBloc` hook (use `useBlocActions` instead)
1534
+ *
1535
+ * @template E - Event union type (discriminated by 'type' property)
1536
+ * @template P - Props type (optional)
1537
+ *
1538
+ * @example
1539
+ * ```typescript
1540
+ * type LogEvent =
1541
+ * | { type: 'info'; message: string }
1542
+ * | { type: 'error'; message: string; error: Error }
1543
+ * | { type: 'warn'; message: string };
1544
+ *
1545
+ * class LoggingVertex extends StatelessVertex<LogEvent> {
1546
+ * constructor() {
1547
+ * super();
1548
+ * this.createHandlers({
1549
+ * info: (event) => console.log('[INFO]', event.message),
1550
+ * error: (event) => console.error('[ERROR]', event.message, event.error),
1551
+ * warn: (event) => console.warn('[WARN]', event.message),
1552
+ * });
1553
+ * }
1554
+ *
1555
+ * info = (message: string) => this.add({ type: 'info', message });
1556
+ * error = (message: string, error: Error) => this.add({ type: 'error', message, error });
1557
+ * warn = (message: string) => this.add({ type: 'warn', message });
1558
+ * }
1559
+ *
1560
+ * // In React component:
1561
+ * const logger = useBlocActions(LoggingVertex);
1562
+ * logger.info('Page loaded');
1563
+ * ```
1564
+ */
1565
+ export declare abstract class StatelessVertex<E extends DiscriminatedEvent = DiscriminatedEvent, P = undefined> extends StateContainer<EmptyState_2, P> {
1566
+ /* Excluded from this release type: [STATELESS_MARKER] */
1567
+ /* Excluded from this release type: handlers */
1568
+ /* Excluded from this release type: isProcessing */
1569
+ /* Excluded from this release type: eventQueue */
1570
+ constructor();
1571
+ /**
1572
+ * State is not available on StatelessVertex.
1573
+ * @throws Always throws an error when accessed.
1574
+ */
1575
+ get state(): never;
1576
+ /**
1577
+ * Subscriptions are not available on StatelessVertex.
1578
+ * @throws Always throws an error when called.
1579
+ */
1580
+ subscribe(_listener: (state: EmptyState_2) => void): never;
1581
+ /**
1582
+ * Register all event handlers with exhaustive type checking.
1583
+ * TypeScript will error if any event type from the union is missing.
1584
+ *
1585
+ * Unlike regular Vertex, handlers do NOT receive an emit function
1586
+ * since StatelessVertex cannot emit state.
1587
+ *
1588
+ * @param handlers - Map of event type to handler function
1589
+ */
1590
+ protected createHandlers(handlers: StatelessEventHandlerMap<E>): void;
1591
+ /**
1592
+ * Dispatch an event for processing.
1593
+ * Events are processed synchronously; if called during processing,
1594
+ * the event is queued and processed after the current event completes.
1595
+ *
1596
+ * @param event - The event to process (must match the event union type)
1597
+ */
1598
+ add: (event: E) => void;
1599
+ /* Excluded from this release type: enrichEvent */
1600
+ /* Excluded from this release type: processEvent */
1601
+ /* Excluded from this release type: handleEvent */
1602
+ /**
1603
+ * Called when an error occurs during event processing.
1604
+ * Override to implement custom error handling.
1605
+ *
1606
+ * @param _event - The event that caused the error
1607
+ * @param _error - The error that occurred
1608
+ */
1609
+ protected onEventError(_event: EventWithMetadata<E>, _error: Error): void;
1610
+ /* Excluded from this release type: emit */
1611
+ /* Excluded from this release type: update */
1612
+ }
1613
+
1295
1614
  /* Excluded from this release type: StateListener */
1296
1615
 
1297
- /* Excluded from this release type: stopProxyTracking */
1616
+ declare const STOP: unique symbol;
1617
+
1618
+ /* Excluded from this release type: stopProxy */
1619
+
1620
+ declare type StopSymbol = typeof STOP;
1621
+
1622
+ /**
1623
+ * Stop tracking and collect all dependencies.
1624
+ */
1625
+ export declare function stopTrackingProxy(tracker: TrackingProxyState, bloc: StateContainerInstance): Set<StateContainerInstance>;
1298
1626
 
1299
1627
  /**
1300
1628
  * Function that subscribes to state changes and returns an unsubscribe function
@@ -1333,41 +1661,210 @@ export declare interface SystemEventPayloads<S, P> {
1333
1661
  dispose: void;
1334
1662
  }
1335
1663
 
1336
- /* Excluded from this release type: TrackerState */
1664
+ /**
1665
+ * Run a callback while tracking all bloc dependencies accessed.
1666
+ * Returns both the result and the set of discovered dependencies.
1667
+ *
1668
+ * @example
1669
+ * ```ts
1670
+ * const { result, dependencies } = tracked(() => {
1671
+ * const user = ensure(UserBloc);
1672
+ * return user.fullName; // getter that may access other blocs
1673
+ * });
1674
+ * // dependencies contains UserBloc + any blocs accessed in fullName getter
1675
+ * ```
1676
+ */
1677
+ export declare function tracked<T>(callback: () => T, options?: TrackedOptions): TrackedResult<T>;
1678
+
1679
+ /**
1680
+ * Context for running tracked callbacks with bloc proxies.
1681
+ * Provides methods to create proxies and check for changes.
1682
+ */
1683
+ export declare class TrackedContext {
1684
+ private tracker;
1685
+ private proxiedBlocs;
1686
+ private primaryBlocs;
1687
+ constructor();
1688
+ /**
1689
+ * Get a tracking proxy for a bloc instance.
1690
+ * The proxy will track state and getter accesses.
1691
+ */
1692
+ proxy<T extends StateContainerInstance>(bloc: T): T;
1693
+ /**
1694
+ * Start tracking for a new callback execution.
1695
+ */
1696
+ start(): void;
1697
+ /**
1698
+ * Stop tracking and get discovered dependencies.
1699
+ * Excludes primary blocs (those explicitly proxied via proxy()).
1700
+ */
1701
+ stop(): Set<StateContainerInstance>;
1702
+ /**
1703
+ * Check if any tracked state or getters have changed.
1704
+ */
1705
+ changed(): boolean;
1706
+ /**
1707
+ * Get all primary blocs (those explicitly proxied).
1708
+ */
1709
+ getPrimaryBlocs(): Set<StateContainerInstance>;
1710
+ /**
1711
+ * Reset the context for reuse.
1712
+ */
1713
+ reset(): void;
1714
+ }
1337
1715
 
1338
1716
  /**
1339
- * Event-driven state container that processes events to update state.
1340
- * Use with event handlers registered via the on() method.
1717
+ * Options for the tracked() function.
1718
+ */
1719
+ export declare interface TrackedOptions {
1720
+ exclude?: StateContainerInstance;
1721
+ }
1722
+
1723
+ /**
1724
+ * Result of running a tracked callback.
1725
+ */
1726
+ export declare interface TrackedResult<T> {
1727
+ result: T;
1728
+ dependencies: Set<StateContainerInstance>;
1729
+ }
1730
+
1731
+ /**
1732
+ * State for tracking both state property access and getter access.
1733
+ */
1734
+ export declare interface TrackingProxyState {
1735
+ dependencyState: DependencyState<any>;
1736
+ getterState: GetterState;
1737
+ dependencies: Set<StateContainerInstance>;
1738
+ isTracking: boolean;
1739
+ }
1740
+
1741
+ /**
1742
+ * Event-driven state container using discriminated union events.
1743
+ * Extends StateContainer with event-based state transitions and
1744
+ * compile-time exhaustive checking for event handlers.
1341
1745
  *
1342
- * @template S - State type
1343
- * @template E - Event type (extends BaseEvent)
1746
+ * @template S - State type (must be an object)
1747
+ * @template E - Event union type (discriminated by 'type' property)
1344
1748
  * @template P - Props type (optional)
1749
+ *
1750
+ * @example
1751
+ * ```typescript
1752
+ * type CounterEvent =
1753
+ * | { type: 'increment'; amount: number }
1754
+ * | { type: 'decrement' }
1755
+ * | { type: 'reset' };
1756
+ *
1757
+ * class CounterVertex extends Vertex<{ count: number }, CounterEvent> {
1758
+ * constructor() {
1759
+ * super({ count: 0 });
1760
+ * this.createHandlers({
1761
+ * increment: (event, emit) => {
1762
+ * emit({ count: this.state.count + event.amount });
1763
+ * },
1764
+ * decrement: (_, emit) => {
1765
+ * emit({ count: this.state.count - 1 });
1766
+ * },
1767
+ * reset: (_, emit) => {
1768
+ * emit({ count: 0 });
1769
+ * },
1770
+ * });
1771
+ * }
1772
+ *
1773
+ * increment = (amount = 1) => this.add({ type: 'increment', amount });
1774
+ * }
1775
+ * ```
1345
1776
  */
1346
- export declare abstract class Vertex<S extends object = any, E extends BaseEvent = BaseEvent, P = undefined> extends StateContainer<S, P> {
1347
- private eventHandlers;
1348
- private isProcessing;
1349
- private eventQueue;
1777
+ export declare abstract class Vertex<S extends object = object, E extends DiscriminatedEvent = DiscriminatedEvent, P = undefined> extends StateContainer<S, P> {
1778
+ /* Excluded from this release type: handlers */
1779
+ /* Excluded from this release type: isProcessing */
1780
+ /* Excluded from this release type: eventQueue */
1350
1781
  constructor(initialState: S);
1351
1782
  /**
1352
- * Register a handler for a specific event type
1353
- * @param EventClass - The event class constructor
1354
- * @param handler - Function to handle events of this type
1783
+ * Register all event handlers with exhaustive type checking.
1784
+ * TypeScript will error if any event type from the union is missing.
1785
+ *
1786
+ * @param handlers - Map of event type to handler function
1355
1787
  */
1356
- protected on: <T extends E>(EventClass: EventConstructor<T>, handler: EventHandler<T, S>) => void;
1788
+ protected createHandlers(handlers: EventHandlerMap<E, S>): void;
1357
1789
  /**
1358
- * Add an event to the event stream for processing
1359
- * @param event - The event to process
1790
+ * Dispatch an event for processing.
1791
+ * Events are processed synchronously; if called during processing,
1792
+ * the event is queued and processed after the current event completes.
1793
+ *
1794
+ * @param event - The event to process (must match the event union type)
1360
1795
  */
1361
1796
  add: (event: E) => void;
1362
- private processEvent;
1363
- private handleEvent;
1797
+ /* Excluded from this release type: enrichEvent */
1798
+ /* Excluded from this release type: processEvent */
1799
+ /* Excluded from this release type: handleEvent */
1364
1800
  /**
1365
- * Handle errors that occur during event processing.
1366
- * Override this method to implement custom error handling.
1801
+ * Called when an error occurs during event processing.
1802
+ * Override to implement custom error handling.
1803
+ *
1367
1804
  * @param _event - The event that caused the error
1368
1805
  * @param _error - The error that occurred
1369
1806
  */
1370
- protected onEventError(_event: E, _error: Error): void;
1807
+ protected onEventError(_event: EventWithMetadata<E>, _error: Error): void;
1808
+ }
1809
+
1810
+ /* Excluded from this release type: VertexEventHandler */
1811
+
1812
+ /**
1813
+ * Wait until a condition is met on a bloc instance.
1814
+ * Returns the bloc instance when the predicate returns true.
1815
+ * Automatically tracks dependencies accessed in the predicate.
1816
+ *
1817
+ * @example
1818
+ * ```ts
1819
+ * // Wait for bloc state to be ready
1820
+ * const userBloc = await waitUntil(UserBloc, (bloc) => bloc.state.isAuthenticated);
1821
+ *
1822
+ * // Wait using a getter
1823
+ * const userBloc = await waitUntil(UserBloc, (bloc) => bloc.isReady);
1824
+ * ```
1825
+ */
1826
+ export declare function waitUntil<T extends StateContainerConstructor>(BlocClass: T, predicate: (bloc: InstanceType<T>) => boolean, options?: WaitUntilOptions): Promise<InstanceType<T>>;
1827
+
1828
+ /**
1829
+ * Wait until a condition is met on a selected value from a bloc.
1830
+ * Returns the selected value when the predicate returns true.
1831
+ * Automatically tracks dependencies accessed in selector and predicate.
1832
+ *
1833
+ * @example
1834
+ * ```ts
1835
+ * // Wait for layout to be set and get it directly
1836
+ * const layout = await waitUntil(
1837
+ * LayoutBloc,
1838
+ * (bloc) => bloc.state.currentLayout,
1839
+ * (layout) => layout !== null
1840
+ * );
1841
+ *
1842
+ * // Using a getter as selector
1843
+ * const user = await waitUntil(
1844
+ * UserBloc,
1845
+ * (bloc) => bloc.currentUser,
1846
+ * (user) => user !== null
1847
+ * );
1848
+ * ```
1849
+ */
1850
+ export declare function waitUntil<T extends StateContainerConstructor, TSelected>(BlocClass: T, selector: (bloc: InstanceType<T>) => TSelected, predicate: (selected: TSelected) => boolean, options?: WaitUntilOptions): Promise<TSelected>;
1851
+
1852
+ export declare class WaitUntilAbortedError extends Error {
1853
+ constructor();
1854
+ }
1855
+
1856
+ export declare class WaitUntilDisposedError extends Error {
1857
+ constructor(blocName: string);
1858
+ }
1859
+
1860
+ export declare interface WaitUntilOptions {
1861
+ instanceId?: string;
1862
+ timeout?: number;
1863
+ signal?: AbortSignal;
1864
+ }
1865
+
1866
+ export declare class WaitUntilTimeoutError extends Error {
1867
+ constructor(timeout: number);
1371
1868
  }
1372
1869
 
1373
1870
  /**
@@ -1378,4 +1875,21 @@ export declare abstract class Vertex<S extends object = any, E extends BaseEvent
1378
1875
  */
1379
1876
  export declare const warn: (context: string, message: string, data?: any) => void;
1380
1877
 
1878
+ export declare const watch: WatchFn;
1879
+
1880
+ /**
1881
+ * Combined watch function type.
1882
+ */
1883
+ export declare interface WatchFn extends WatchSingleFn {
1884
+ <T extends readonly BlocInput[]>(blocs: T, callback: (blocs: ExtractInstances<T>) => void | StopSymbol): () => void;
1885
+ }
1886
+
1887
+ /**
1888
+ * Watch function signature for single bloc.
1889
+ */
1890
+ declare interface WatchSingleFn {
1891
+ <T extends StateContainerConstructor>(bloc: T | BlocRef<T>, callback: (bloc: InstanceType<T>) => void | StopSymbol): () => void;
1892
+ STOP: StopSymbol;
1893
+ }
1894
+
1381
1895
  export { }