@blac/core 2.0.0-rc-10 → 2.0.0-rc-13

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,7 +1,13 @@
1
+ import { BlacPlugin as BlacPlugin_2 } from '../core/types';
2
+ import { BlocPlugin as BlocPlugin_2 } from '../core/types';
3
+ import { ErrorContext as ErrorContext_2 } from '../core/types';
4
+ import { PluginMetrics as PluginMetrics_2 } from '../core/types';
5
+ import { PluginRegistry as PluginRegistry_2 } from '../core/types';
6
+
1
7
  export declare interface AdapterOptions<B extends BlocBase<any>> {
2
8
  id?: string;
3
9
  dependencies?: (bloc: B) => unknown[];
4
- props?: InferPropsFromGeneric<B>;
10
+ props?: any;
5
11
  onMount?: (bloc: B) => void;
6
12
  onUnmount?: (bloc: B) => void;
7
13
  }
@@ -23,6 +29,16 @@ export declare class Blac {
23
29
  static get getAllBlocs(): <B extends BlocConstructor<any>>(blocClass: B, options?: {
24
30
  searchIsolated?: boolean;
25
31
  }) => InstanceType<B>[];
32
+ /** Private static configuration */
33
+ private static _config;
34
+ /** Get current configuration */
35
+ static get config(): Readonly<BlacConfig>;
36
+ /**
37
+ * Set or update Blac configuration
38
+ * @param config - Partial configuration to merge with existing config
39
+ * @throws Error if configuration is invalid
40
+ */
41
+ static setConfig(config: Partial<BlacConfig>): void;
26
42
  /** Map storing all registered bloc instances by their class name and ID */
27
43
  blocInstanceMap: Map<string, BlocBase<unknown>>;
28
44
  /** Map storing isolated bloc instances grouped by their constructor */
@@ -35,6 +51,8 @@ export declare class Blac {
35
51
  keepAliveBlocs: Set<BlocBase<unknown>>;
36
52
  /** Flag to control whether changes should be posted to document */
37
53
  postChangesToDocument: boolean;
54
+ /** System plugin registry */
55
+ readonly plugins: SystemPluginRegistry;
38
56
  /**
39
57
  * Creates a new Blac instance.
40
58
  * @param options - Configuration options including singleton control
@@ -211,6 +229,14 @@ export declare class Blac {
211
229
  */
212
230
  validateConsumers: () => void;
213
231
  static get validateConsumers(): () => void;
232
+ /**
233
+ * Bootstrap the Blac instance and all plugins
234
+ */
235
+ bootstrap(): void;
236
+ /**
237
+ * Shutdown the Blac instance and all plugins
238
+ */
239
+ shutdown(): void;
214
240
  }
215
241
 
216
242
  /**
@@ -225,6 +251,8 @@ export declare class BlacAdapter<B extends BlocConstructor<BlocBase<any>>> {
225
251
  };
226
252
  blocInstance: InstanceType<B>;
227
253
  private consumerTracker;
254
+ private static propsOwners;
255
+ private lastProps?;
228
256
  unmountTime: number;
229
257
  mountTime: number;
230
258
  private dependencyValues?;
@@ -258,6 +286,7 @@ export declare class BlacAdapter<B extends BlocConstructor<BlocBase<any>>> {
258
286
  getProxyState: (state: BlocState<InstanceType<B>>) => BlocState<InstanceType<B>>;
259
287
  getProxyBlocInstance: () => InstanceType<B>;
260
288
  get calledOnMount(): boolean;
289
+ updateProps(props: any): void;
261
290
  private hasDependencyValuesChanged;
262
291
  }
263
292
 
@@ -267,6 +296,12 @@ export declare class BlacAdapter<B extends BlocConstructor<BlocBase<any>>> {
267
296
  export declare interface BlacConfig {
268
297
  /** Whether to expose the Blac instance globally */
269
298
  exposeBlacInstance?: boolean;
299
+ /**
300
+ * Whether to enable proxy dependency tracking for automatic re-render optimization.
301
+ * When false, state changes always cause re-renders unless dependencies are manually specified.
302
+ * Default: true
303
+ */
304
+ proxyDependencyTracking?: boolean;
270
305
  }
271
306
 
272
307
  /**
@@ -342,6 +377,21 @@ export declare type BlacObserver<S> = {
342
377
  id: string;
343
378
  };
344
379
 
380
+ /**
381
+ * System-wide plugin that observes all blocs
382
+ */
383
+ export declare interface BlacPlugin extends Plugin_2 {
384
+ beforeBootstrap?(): void;
385
+ afterBootstrap?(): void;
386
+ beforeShutdown?(): void;
387
+ afterShutdown?(): void;
388
+ onBlocCreated?(bloc: BlocBase<any>): void;
389
+ onBlocDisposed?(bloc: BlocBase<any>): void;
390
+ onStateChanged?(bloc: BlocBase<any>, previousState: any, currentState: any): void;
391
+ onEventAdded?(bloc: Bloc<any, any>, event: any): void;
392
+ onError?(error: Error, bloc: BlocBase<unknown>, context: ErrorContext): void;
393
+ }
394
+
345
395
  export declare abstract class Bloc<S, // State type
346
396
  A extends BlocEventConstraint = BlocEventConstraint, // Base Action/Event type with proper constraints
347
397
  P = unknown> extends BlocBase<S, P> {
@@ -421,6 +471,10 @@ export declare abstract class BlocBase<S, P = unknown> {
421
471
  /* Excluded from this release type: _batchingLock */
422
472
  /* Excluded from this release type: _pendingUpdates */
423
473
  /* Excluded from this release type: _consumerRefs */
474
+ /**
475
+ * Plugin registry for this bloc instance
476
+ */
477
+ protected _plugins: BlocPluginRegistry<S, any>;
424
478
  /* Excluded from this release type: _validateConsumers */
425
479
  /**
426
480
  * Creates a new BlocBase instance with the given initial state.
@@ -454,11 +508,29 @@ export declare abstract class BlocBase<S, P = unknown> {
454
508
  lastUpdate: number;
455
509
  /* Excluded from this release type: _batchingEnabled */
456
510
  /* Excluded from this release type: _pushState */
511
+ /* Excluded from this release type: _notifyObservers */
457
512
  /**
458
513
  * Enables batching for multiple state updates
459
514
  * @param batchFn Function to execute with batching enabled
460
515
  */
461
516
  batch: <T>(batchFn: () => T) => T;
517
+ /**
518
+ * Add a plugin to this bloc instance
519
+ */
520
+ addPlugin(plugin: BlocPlugin<S, any>): void;
521
+ /**
522
+ * Remove a plugin from this bloc instance
523
+ */
524
+ removePlugin(pluginName: string): boolean;
525
+ /**
526
+ * Get a plugin by name
527
+ */
528
+ getPlugin(pluginName: string): BlocPlugin<S, any> | undefined;
529
+ /**
530
+ * Get all plugins
531
+ */
532
+ getPlugins(): ReadonlyArray<BlocPlugin<S, any>>;
533
+ /* Excluded from this release type: _activatePlugins */
462
534
  }
463
535
 
464
536
  /**
@@ -498,19 +570,10 @@ export declare interface BlocErrorBoundary<S, A extends BlocEventConstraint> {
498
570
  shouldRethrow?: (error: Error, event: A) => boolean;
499
571
  }
500
572
 
501
- /**
502
- * Base interface for all Bloc events
503
- * Events must be objects with a constructor to enable proper type matching
504
- */
505
- export declare interface BlocEvent {
506
- readonly type?: string;
507
- readonly timestamp?: number;
508
- }
509
-
510
573
  /**
511
574
  * Enhanced constraint for Bloc events - must be objects with proper constructor
512
575
  */
513
- export declare type BlocEventConstraint = BlocEvent & object;
576
+ export declare type BlocEventConstraint = object;
514
577
 
515
578
  /**
516
579
  * Function type for determining dependencies that trigger re-renders
@@ -537,6 +600,76 @@ export declare enum BlocLifecycleState {
537
600
  DISPOSED = "disposed"
538
601
  }
539
602
 
603
+ /**
604
+ * Bloc-specific plugin that can transform behavior
605
+ */
606
+ export declare interface BlocPlugin<TState = any, TEvent = never> extends Plugin_2 {
607
+ transformState?(previousState: TState, nextState: TState): TState;
608
+ transformEvent?(event: TEvent): TEvent | null;
609
+ onAttach?(bloc: BlocBase<TState, any>): void;
610
+ onDetach?(): void;
611
+ onStateChange?(previousState: TState, currentState: TState): void;
612
+ onEvent?(event: TEvent): void;
613
+ onError?(error: Error, context: ErrorContext): void;
614
+ }
615
+
616
+ /**
617
+ * Registry for bloc-specific plugins
618
+ */
619
+ export declare class BlocPluginRegistry<TState, TEvent = never> implements PluginRegistry_2<BlocPlugin_2<TState, TEvent>> {
620
+ private plugins;
621
+ private executionOrder;
622
+ private attached;
623
+ /**
624
+ * Add a bloc plugin
625
+ */
626
+ add(plugin: BlocPlugin_2<TState, TEvent>): void;
627
+ /**
628
+ * Remove a bloc plugin
629
+ */
630
+ remove(pluginName: string): boolean;
631
+ /**
632
+ * Get a plugin by name
633
+ */
634
+ get(pluginName: string): BlocPlugin_2<TState, TEvent> | undefined;
635
+ /**
636
+ * Get all plugins in execution order
637
+ */
638
+ getAll(): ReadonlyArray<BlocPlugin_2<TState, TEvent>>;
639
+ /**
640
+ * Clear all plugins
641
+ */
642
+ clear(): void;
643
+ /**
644
+ * Attach all plugins to a bloc
645
+ */
646
+ attach(bloc: any): void;
647
+ /**
648
+ * Transform state through all plugins
649
+ */
650
+ transformState(previousState: TState, nextState: TState): TState;
651
+ /**
652
+ * Transform event through all plugins
653
+ */
654
+ transformEvent(event: TEvent): TEvent | null;
655
+ /**
656
+ * Notify plugins of state change
657
+ */
658
+ notifyStateChange(previousState: TState, currentState: TState): void;
659
+ /**
660
+ * Notify plugins of event
661
+ */
662
+ notifyEvent(event: TEvent): void;
663
+ /**
664
+ * Notify plugins of error
665
+ */
666
+ notifyError(error: Error, context: ErrorContext_2): void;
667
+ private validateCapabilities;
668
+ private canReadState;
669
+ private canTransformState;
670
+ private canInterceptEvents;
671
+ }
672
+
540
673
  /**
541
674
  * Extracts the state type from either a Bloc or Cubit
542
675
  * @template T - The Bloc or Cubit type to extract the state from
@@ -620,6 +753,11 @@ declare interface ConsumerTracker_2 {
620
753
  * @template P - The type of parameters (optional, defaults to null)
621
754
  */
622
755
  export declare abstract class Cubit<S, P = null> extends BlocBase<S, P> {
756
+ /* Excluded from this release type: _updateProps */
757
+ /**
758
+ * Optional override for props handling
759
+ */
760
+ protected onPropsChanged?(oldProps: P | undefined, newProps: P): void;
623
761
  /**
624
762
  * Updates the current state and notifies all observers of the change.
625
763
  * If the new state is identical to the current state (using Object.is),
@@ -645,6 +783,15 @@ export declare interface DependencyArray {
645
783
 
646
784
  declare type DependencySelector<S> = (currentState: S, previousState: S | undefined, instance: any) => unknown[];
647
785
 
786
+ /**
787
+ * Error context provided to error handlers
788
+ */
789
+ export declare interface ErrorContext {
790
+ readonly phase: 'initialization' | 'state-change' | 'event-processing' | 'disposal';
791
+ readonly operation: string;
792
+ readonly metadata?: Record<string, unknown>;
793
+ }
794
+
648
795
  /**
649
796
  * Cross-platform UUID v4 generator that works in all environments including React Native/Hermes
650
797
  * Falls back to crypto.randomUUID() when available, otherwise uses Math.random()
@@ -728,6 +875,65 @@ export declare class MockCubit<S> extends Cubit<S> {
728
875
  clearStateHistory(): void;
729
876
  }
730
877
 
878
+ /**
879
+ * Base interface for all plugins
880
+ */
881
+ declare interface Plugin_2 {
882
+ readonly name: string;
883
+ readonly version: string;
884
+ readonly capabilities?: PluginCapabilities;
885
+ }
886
+ export { Plugin_2 as Plugin }
887
+
888
+ /**
889
+ * Plugin capabilities for security model
890
+ */
891
+ export declare interface PluginCapabilities {
892
+ readonly readState: boolean;
893
+ readonly transformState: boolean;
894
+ readonly interceptEvents: boolean;
895
+ readonly persistData: boolean;
896
+ readonly accessMetadata: boolean;
897
+ }
898
+
899
+ /**
900
+ * Plugin execution context for performance monitoring
901
+ */
902
+ export declare interface PluginExecutionContext {
903
+ readonly pluginName: string;
904
+ readonly hookName: string;
905
+ readonly startTime: number;
906
+ readonly blocName?: string;
907
+ readonly blocId?: string;
908
+ }
909
+
910
+ /**
911
+ * Plugin metrics for monitoring
912
+ */
913
+ export declare interface PluginMetrics {
914
+ readonly executionTime: number;
915
+ readonly executionCount: number;
916
+ readonly errorCount: number;
917
+ readonly lastError?: Error;
918
+ readonly lastExecutionTime?: number;
919
+ }
920
+
921
+ /**
922
+ * Plugin registry interface
923
+ */
924
+ export declare interface PluginRegistry<T extends Plugin_2> {
925
+ add(plugin: T): void;
926
+ remove(pluginName: string): boolean;
927
+ get(pluginName: string): T | undefined;
928
+ getAll(): ReadonlyArray<T>;
929
+ clear(): void;
930
+ }
931
+
932
+ export declare class PropsUpdated<P = any> {
933
+ readonly props: P;
934
+ constructor(props: P);
935
+ }
936
+
731
937
  export declare class ProxyFactory {
732
938
  static createStateProxy<T extends object>(options: {
733
939
  target: T;
@@ -772,6 +978,15 @@ export declare class ProxyFactory {
772
978
  */
773
979
  export declare function setBlacInstanceManager(manager: BlacInstanceManager): void;
774
980
 
981
+ /**
982
+ * Performs a shallow equality comparison between two values.
983
+ * For objects, it checks if all top-level properties are equal using Object.is.
984
+ * @param a First value to compare
985
+ * @param b Second value to compare
986
+ * @returns true if values are shallowly equal, false otherwise
987
+ */
988
+ export declare function shallowEqual(a: any, b: any): boolean;
989
+
775
990
  /**
776
991
  * Result of an atomic state transition operation
777
992
  */
@@ -781,6 +996,74 @@ export declare interface StateTransitionResult {
781
996
  previousState: BlocLifecycleState;
782
997
  }
783
998
 
999
+ /**
1000
+ * Registry for system-wide plugins
1001
+ */
1002
+ export declare class SystemPluginRegistry implements PluginRegistry_2<BlacPlugin_2> {
1003
+ private plugins;
1004
+ private metrics;
1005
+ private executionOrder;
1006
+ /**
1007
+ * Add a system plugin
1008
+ */
1009
+ add(plugin: BlacPlugin_2): void;
1010
+ /**
1011
+ * Remove a system plugin
1012
+ */
1013
+ remove(pluginName: string): boolean;
1014
+ /**
1015
+ * Get a plugin by name
1016
+ */
1017
+ get(pluginName: string): BlacPlugin_2 | undefined;
1018
+ /**
1019
+ * Get all plugins in execution order
1020
+ */
1021
+ getAll(): ReadonlyArray<BlacPlugin_2>;
1022
+ /**
1023
+ * Clear all plugins
1024
+ */
1025
+ clear(): void;
1026
+ /**
1027
+ * Execute a hook on all plugins
1028
+ */
1029
+ executeHook(hookName: keyof BlacPlugin_2, args: unknown[], errorHandler?: (error: Error, plugin: BlacPlugin_2) => void): void;
1030
+ /**
1031
+ * Bootstrap all plugins
1032
+ */
1033
+ bootstrap(): void;
1034
+ /**
1035
+ * Shutdown all plugins
1036
+ */
1037
+ shutdown(): void;
1038
+ /**
1039
+ * Notify plugins of bloc creation
1040
+ */
1041
+ notifyBlocCreated(bloc: BlocBase<any>): void;
1042
+ /**
1043
+ * Notify plugins of bloc disposal
1044
+ */
1045
+ notifyBlocDisposed(bloc: BlocBase<any>): void;
1046
+ /**
1047
+ * Notify plugins of state change
1048
+ */
1049
+ notifyStateChanged(bloc: BlocBase<any>, previousState: any, currentState: any): void;
1050
+ /**
1051
+ * Notify plugins of event addition
1052
+ */
1053
+ notifyEventAdded(bloc: Bloc<any, any>, event: any): void;
1054
+ /**
1055
+ * Notify plugins of errors
1056
+ */
1057
+ notifyError(error: Error, bloc: BlocBase<unknown>, context: ErrorContext_2): void;
1058
+ /**
1059
+ * Get metrics for a plugin
1060
+ */
1061
+ getMetrics(pluginName: string): Map<string, PluginMetrics_2> | undefined;
1062
+ private initializeMetrics;
1063
+ private recordSuccess;
1064
+ private recordError;
1065
+ }
1066
+
784
1067
  export declare interface TrackedValue {
785
1068
  value: any;
786
1069
  lastAccessTime: number;