@blac/core 2.0.0-rc-11 → 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.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +254 -0
- package/dist/index.es.js +700 -296
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/src/Blac.ts +48 -2
- package/src/BlacObserver.ts +3 -0
- package/src/Bloc.ts +44 -1
- package/src/BlocBase.ts +107 -4
- package/src/__tests__/plugins.test.ts +454 -0
- package/src/index.ts +3 -0
- package/src/plugins/BlocPluginRegistry.ts +220 -0
- package/src/plugins/SystemPluginRegistry.ts +192 -0
- package/src/plugins/index.ts +8 -0
- package/src/plugins/types.ts +100 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
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[];
|
|
@@ -45,6 +51,8 @@ export declare class Blac {
|
|
|
45
51
|
keepAliveBlocs: Set<BlocBase<unknown>>;
|
|
46
52
|
/** Flag to control whether changes should be posted to document */
|
|
47
53
|
postChangesToDocument: boolean;
|
|
54
|
+
/** System plugin registry */
|
|
55
|
+
readonly plugins: SystemPluginRegistry;
|
|
48
56
|
/**
|
|
49
57
|
* Creates a new Blac instance.
|
|
50
58
|
* @param options - Configuration options including singleton control
|
|
@@ -221,6 +229,14 @@ export declare class Blac {
|
|
|
221
229
|
*/
|
|
222
230
|
validateConsumers: () => void;
|
|
223
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;
|
|
224
240
|
}
|
|
225
241
|
|
|
226
242
|
/**
|
|
@@ -361,6 +377,21 @@ export declare type BlacObserver<S> = {
|
|
|
361
377
|
id: string;
|
|
362
378
|
};
|
|
363
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
|
+
|
|
364
395
|
export declare abstract class Bloc<S, // State type
|
|
365
396
|
A extends BlocEventConstraint = BlocEventConstraint, // Base Action/Event type with proper constraints
|
|
366
397
|
P = unknown> extends BlocBase<S, P> {
|
|
@@ -440,6 +471,10 @@ export declare abstract class BlocBase<S, P = unknown> {
|
|
|
440
471
|
/* Excluded from this release type: _batchingLock */
|
|
441
472
|
/* Excluded from this release type: _pendingUpdates */
|
|
442
473
|
/* Excluded from this release type: _consumerRefs */
|
|
474
|
+
/**
|
|
475
|
+
* Plugin registry for this bloc instance
|
|
476
|
+
*/
|
|
477
|
+
protected _plugins: BlocPluginRegistry<S, any>;
|
|
443
478
|
/* Excluded from this release type: _validateConsumers */
|
|
444
479
|
/**
|
|
445
480
|
* Creates a new BlocBase instance with the given initial state.
|
|
@@ -473,11 +508,29 @@ export declare abstract class BlocBase<S, P = unknown> {
|
|
|
473
508
|
lastUpdate: number;
|
|
474
509
|
/* Excluded from this release type: _batchingEnabled */
|
|
475
510
|
/* Excluded from this release type: _pushState */
|
|
511
|
+
/* Excluded from this release type: _notifyObservers */
|
|
476
512
|
/**
|
|
477
513
|
* Enables batching for multiple state updates
|
|
478
514
|
* @param batchFn Function to execute with batching enabled
|
|
479
515
|
*/
|
|
480
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 */
|
|
481
534
|
}
|
|
482
535
|
|
|
483
536
|
/**
|
|
@@ -547,6 +600,76 @@ export declare enum BlocLifecycleState {
|
|
|
547
600
|
DISPOSED = "disposed"
|
|
548
601
|
}
|
|
549
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
|
+
|
|
550
673
|
/**
|
|
551
674
|
* Extracts the state type from either a Bloc or Cubit
|
|
552
675
|
* @template T - The Bloc or Cubit type to extract the state from
|
|
@@ -660,6 +783,15 @@ export declare interface DependencyArray {
|
|
|
660
783
|
|
|
661
784
|
declare type DependencySelector<S> = (currentState: S, previousState: S | undefined, instance: any) => unknown[];
|
|
662
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
|
+
|
|
663
795
|
/**
|
|
664
796
|
* Cross-platform UUID v4 generator that works in all environments including React Native/Hermes
|
|
665
797
|
* Falls back to crypto.randomUUID() when available, otherwise uses Math.random()
|
|
@@ -743,6 +875,60 @@ export declare class MockCubit<S> extends Cubit<S> {
|
|
|
743
875
|
clearStateHistory(): void;
|
|
744
876
|
}
|
|
745
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
|
+
|
|
746
932
|
export declare class PropsUpdated<P = any> {
|
|
747
933
|
readonly props: P;
|
|
748
934
|
constructor(props: P);
|
|
@@ -810,6 +996,74 @@ export declare interface StateTransitionResult {
|
|
|
810
996
|
previousState: BlocLifecycleState;
|
|
811
997
|
}
|
|
812
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
|
+
|
|
813
1067
|
export declare interface TrackedValue {
|
|
814
1068
|
value: any;
|
|
815
1069
|
lastAccessTime: number;
|