@blac/core 2.0.0-rc.5 → 2.0.0-rc.8
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/adapter/framework-adapter.d.ts +114 -0
- package/dist/adapter/framework-adapter.d.ts.map +1 -0
- package/dist/adapter/index.d.ts +8 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/constants.d.ts +82 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core/Cubit.d.ts +82 -0
- package/dist/core/Cubit.d.ts.map +1 -0
- package/dist/core/StateContainer.d.ts +200 -0
- package/dist/core/StateContainer.d.ts.map +1 -0
- package/dist/core/StateContainerRegistry.d.ts +176 -0
- package/dist/core/StateContainerRegistry.d.ts.map +1 -0
- package/dist/core/Vertex.d.ts +113 -0
- package/dist/core/Vertex.d.ts.map +1 -0
- package/dist/index.cjs +1158 -326
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -885
- package/dist/index.d.ts +19 -884
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1122 -327
- package/dist/index.js.map +1 -1
- package/dist/logging/Logger.d.ts +57 -0
- package/dist/logging/Logger.d.ts.map +1 -0
- package/dist/plugin/BlacPlugin.d.ts +115 -0
- package/dist/plugin/BlacPlugin.d.ts.map +1 -0
- package/dist/plugin/PluginManager.d.ts +63 -0
- package/dist/plugin/PluginManager.d.ts.map +1 -0
- package/dist/proxy/ProxyTracker.d.ts +71 -0
- package/dist/proxy/ProxyTracker.d.ts.map +1 -0
- package/dist/registry/index.d.ts +20 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +43 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/tracking/dependency-tracker.d.ts +21 -0
- package/dist/tracking/dependency-tracker.d.ts.map +1 -0
- package/dist/tracking/getter-tracker.d.ts +31 -0
- package/dist/tracking/getter-tracker.d.ts.map +1 -0
- package/dist/tracking/index.d.ts +38 -0
- package/dist/tracking/index.d.ts.map +1 -0
- package/dist/tracking/path-utils.d.ts +39 -0
- package/dist/tracking/path-utils.d.ts.map +1 -0
- package/dist/tracking/proxy-tracker.d.ts +88 -0
- package/dist/tracking/proxy-tracker.d.ts.map +1 -0
- package/dist/types/branded.d.ts +9 -0
- package/dist/types/branded.d.ts.map +1 -0
- package/dist/types/events.d.ts +13 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/utilities.d.ts +18 -0
- package/dist/types/utilities.d.ts.map +1 -0
- package/dist/utils/equality.d.ts +9 -0
- package/dist/utils/equality.d.ts.map +1 -0
- package/dist/utils/idGenerator.d.ts +76 -0
- package/dist/utils/idGenerator.d.ts.map +1 -0
- package/dist/utils/immutable.d.ts +16 -0
- package/dist/utils/immutable.d.ts.map +1 -0
- package/dist/utils/stack-trace.d.ts +19 -0
- package/dist/utils/stack-trace.d.ts.map +1 -0
- package/dist/utils/static-props.d.ts +29 -0
- package/dist/utils/static-props.d.ts.map +1 -0
- package/package.json +17 -4
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StateContainerRegistry - Centralized instance and lifecycle management
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Instance storage and management (WeakMap per constructor)
|
|
6
|
+
* - Type registration and tracking
|
|
7
|
+
* - Lifecycle event notifications (plugin system)
|
|
8
|
+
* - Global operations (clearAllInstances)
|
|
9
|
+
*/
|
|
10
|
+
import type { StateContainer } from './StateContainer';
|
|
11
|
+
import type { Vertex } from './Vertex';
|
|
12
|
+
/**
|
|
13
|
+
* Internal entry for instance storage
|
|
14
|
+
* Each entry tracks an instance and its reference count
|
|
15
|
+
*/
|
|
16
|
+
export interface InstanceEntry<T = any> {
|
|
17
|
+
instance: T;
|
|
18
|
+
refCount: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Lifecycle events that can be observed
|
|
22
|
+
*/
|
|
23
|
+
export type LifecycleEvent = 'created' | 'stateChanged' | 'eventAdded' | 'disposed';
|
|
24
|
+
/**
|
|
25
|
+
* Listener function types for each lifecycle event
|
|
26
|
+
*/
|
|
27
|
+
export type LifecycleListener<E extends LifecycleEvent> = E extends 'created' ? (container: StateContainer<any>) => void : E extends 'stateChanged' ? (container: StateContainer<any>, previousState: any, currentState: any, callstack?: string) => void : E extends 'eventAdded' ? (container: Vertex<any, any>, event: any) => void : E extends 'disposed' ? (container: StateContainer<any>) => void : never;
|
|
28
|
+
/**
|
|
29
|
+
* Registry for coordinating StateContainer lifecycle and managing instances
|
|
30
|
+
*
|
|
31
|
+
* Centralizes all instance management using WeakMap to ensure proper isolation.
|
|
32
|
+
*/
|
|
33
|
+
export declare class StateContainerRegistry {
|
|
34
|
+
/**
|
|
35
|
+
* Global storage for all instance Maps, keyed by constructor
|
|
36
|
+
*
|
|
37
|
+
* IMPORTANT: JavaScript/TypeScript static properties are inherited by reference,
|
|
38
|
+
* meaning all subclasses would share the same Map. To ensure each subclass has
|
|
39
|
+
* its own instance storage, we use a WeakMap keyed by the constructor function.
|
|
40
|
+
*
|
|
41
|
+
* This approach guarantees:
|
|
42
|
+
* - CounterBloc instances are separate from UserBloc instances
|
|
43
|
+
* - Each class owns and manages its own instances
|
|
44
|
+
* - Automatic garbage collection when classes are no longer referenced
|
|
45
|
+
*/
|
|
46
|
+
private readonly instancesByConstructor;
|
|
47
|
+
/**
|
|
48
|
+
* Strong Set for tracking all registered types
|
|
49
|
+
* Used for clearAllInstances() and getStats()
|
|
50
|
+
*/
|
|
51
|
+
private readonly types;
|
|
52
|
+
/**
|
|
53
|
+
* Type configurations (isolated flag)
|
|
54
|
+
*/
|
|
55
|
+
private readonly typeConfigs;
|
|
56
|
+
/**
|
|
57
|
+
* Lifecycle event listeners
|
|
58
|
+
*/
|
|
59
|
+
private readonly listeners;
|
|
60
|
+
/**
|
|
61
|
+
* Register a type for tracking
|
|
62
|
+
* Called automatically on first instance creation
|
|
63
|
+
*/
|
|
64
|
+
registerType<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): void;
|
|
65
|
+
/**
|
|
66
|
+
* Register a type with isolation mode (explicit registration)
|
|
67
|
+
*/
|
|
68
|
+
register<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, isolated?: boolean): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get the instances Map for a specific class
|
|
71
|
+
* Creates a new Map on first access.
|
|
72
|
+
*/
|
|
73
|
+
private ensureInstancesMap;
|
|
74
|
+
/**
|
|
75
|
+
* Get the instances Map for a specific class (public API for stats/debugging)
|
|
76
|
+
*/
|
|
77
|
+
getInstancesMap<T extends StateContainer<any>>(Type: new (...args: any[]) => T): Map<string, InstanceEntry>;
|
|
78
|
+
/**
|
|
79
|
+
* Resolve an instance with ref counting (ownership semantics)
|
|
80
|
+
*/
|
|
81
|
+
resolve<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
82
|
+
/**
|
|
83
|
+
* Get an existing instance without ref counting (borrowing semantics)
|
|
84
|
+
* @throws Error if instance doesn't exist
|
|
85
|
+
*/
|
|
86
|
+
get<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): T;
|
|
87
|
+
/**
|
|
88
|
+
* Safely get an existing instance (borrowing semantics with error handling)
|
|
89
|
+
* Returns discriminated union for type-safe conditional access
|
|
90
|
+
*/
|
|
91
|
+
getSafe<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): {
|
|
92
|
+
error: Error;
|
|
93
|
+
instance: null;
|
|
94
|
+
} | {
|
|
95
|
+
error: null;
|
|
96
|
+
instance: T;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Connect to an instance with borrowing semantics (for B2B communication)
|
|
100
|
+
* Gets existing instance OR creates it if it doesn't exist, without incrementing ref count.
|
|
101
|
+
* Tracks cross-bloc dependency for reactive updates.
|
|
102
|
+
*
|
|
103
|
+
* Use this in bloc-to-bloc communication when you need to ensure an instance exists
|
|
104
|
+
* but don't want to claim ownership (no ref count increment).
|
|
105
|
+
*
|
|
106
|
+
* @param Type - The bloc class constructor
|
|
107
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
108
|
+
* @param constructorArgs - Constructor arguments (only used if creating new instance)
|
|
109
|
+
* @returns The bloc instance
|
|
110
|
+
*/
|
|
111
|
+
connect<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
112
|
+
/**
|
|
113
|
+
* Release a reference to an instance
|
|
114
|
+
*/
|
|
115
|
+
release<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string, forceDispose?: boolean): void;
|
|
116
|
+
/**
|
|
117
|
+
* Get all instances of a specific type
|
|
118
|
+
*/
|
|
119
|
+
getAll<T extends StateContainer<any>>(Type: new (...args: any[]) => T): T[];
|
|
120
|
+
/**
|
|
121
|
+
* Safely iterate over all instances of a type
|
|
122
|
+
*/
|
|
123
|
+
forEach<T extends StateContainer<any>>(Type: new (...args: any[]) => T, callback: (instance: T) => void): void;
|
|
124
|
+
/**
|
|
125
|
+
* Clear all instances of a specific type
|
|
126
|
+
*/
|
|
127
|
+
clear<T extends StateContainer<any>>(Type: new (...args: any[]) => T): void;
|
|
128
|
+
/**
|
|
129
|
+
* Get reference count for an instance
|
|
130
|
+
*/
|
|
131
|
+
getRefCount<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): number;
|
|
132
|
+
/**
|
|
133
|
+
* Check if an instance exists
|
|
134
|
+
*/
|
|
135
|
+
hasInstance<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Clear all instances from all types (for testing)
|
|
138
|
+
*
|
|
139
|
+
* Iterates all registered types and clears their instances.
|
|
140
|
+
* Also clears type tracking to reset the registry state.
|
|
141
|
+
*/
|
|
142
|
+
clearAll(): void;
|
|
143
|
+
/**
|
|
144
|
+
* Get registry statistics (for debugging)
|
|
145
|
+
*/
|
|
146
|
+
getStats(): {
|
|
147
|
+
registeredTypes: number;
|
|
148
|
+
totalInstances: number;
|
|
149
|
+
typeBreakdown: Record<string, number>;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Get all registered types (for plugin system)
|
|
153
|
+
*/
|
|
154
|
+
getTypes(): Array<new (...args: any[]) => StateContainer<any>>;
|
|
155
|
+
/**
|
|
156
|
+
* Subscribe to lifecycle events
|
|
157
|
+
* @param event - The lifecycle event to listen for
|
|
158
|
+
* @param listener - The listener function to call when the event occurs
|
|
159
|
+
* @returns Unsubscribe function
|
|
160
|
+
*/
|
|
161
|
+
on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
|
|
162
|
+
/**
|
|
163
|
+
* Emit lifecycle event to all listeners
|
|
164
|
+
* @internal - Called by StateContainer/Vertex lifecycle methods
|
|
165
|
+
*/
|
|
166
|
+
emit(event: LifecycleEvent, ...args: any[]): void;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Global default registry instance
|
|
170
|
+
*/
|
|
171
|
+
export declare const globalRegistry: StateContainerRegistry;
|
|
172
|
+
/**
|
|
173
|
+
* Get the global plugin manager
|
|
174
|
+
*/
|
|
175
|
+
export declare function getPluginManager(): any;
|
|
176
|
+
//# sourceMappingURL=StateContainerRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StateContainerRegistry.d.ts","sourceRoot":"","sources":["../../src/core/StateContainerRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAwB,MAAM,kBAAkB,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAUvC;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,GAAG;IACpC,QAAQ,EAAE,CAAC,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,M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C,SAAS,cAAc,EACzB,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,MAAM,IAAI;IAYb;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;CAelD;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,wBAA+B,CAAC;AAO3D;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,GAAG,CAKtC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vertex - Event-driven state container (Bloc pattern)
|
|
3
|
+
*
|
|
4
|
+
* Simplified version that includes its own event handling,
|
|
5
|
+
* since events are only needed for the Vertex pattern.
|
|
6
|
+
*/
|
|
7
|
+
import { StateContainer } from './StateContainer';
|
|
8
|
+
import { BaseEvent } from '../types/events';
|
|
9
|
+
/**
|
|
10
|
+
* Event handler signature (synchronous only)
|
|
11
|
+
*/
|
|
12
|
+
export type EventHandler<E extends BaseEvent, S> = (event: E, emit: (state: S) => void) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Type-safe event constructor
|
|
15
|
+
*/
|
|
16
|
+
export type EventConstructor<T extends BaseEvent = BaseEvent> = new (...args: never[]) => T;
|
|
17
|
+
/**
|
|
18
|
+
* Vertex is an event-driven state container (Bloc pattern)
|
|
19
|
+
*
|
|
20
|
+
* Includes its own simple event system since events are only needed
|
|
21
|
+
* for the Vertex pattern, not for the base StateContainer.
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class Vertex<S, E extends BaseEvent = BaseEvent> extends StateContainer<S> {
|
|
24
|
+
private eventHandlers;
|
|
25
|
+
private isProcessing;
|
|
26
|
+
private eventQueue;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new Vertex
|
|
29
|
+
* @param initialState Initial state value
|
|
30
|
+
*/
|
|
31
|
+
constructor(initialState: S);
|
|
32
|
+
/**
|
|
33
|
+
* Register an event handler
|
|
34
|
+
* Arrow function to maintain correct 'this' binding
|
|
35
|
+
*/
|
|
36
|
+
protected on: <T extends E>(EventClass: EventConstructor<T>, handler: EventHandler<T, S>) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Add an event to be processed
|
|
39
|
+
* Arrow function to maintain correct 'this' binding in React
|
|
40
|
+
*/
|
|
41
|
+
add: (event: E) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Process an event (synchronously)
|
|
44
|
+
*/
|
|
45
|
+
private processEvent;
|
|
46
|
+
/**
|
|
47
|
+
* Handle a single event (synchronously)
|
|
48
|
+
*/
|
|
49
|
+
private handleEvent;
|
|
50
|
+
/**
|
|
51
|
+
* Hook for handling event processing errors
|
|
52
|
+
*/
|
|
53
|
+
protected onEventError(_event: E, _error: Error): void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Example: Counter Events
|
|
57
|
+
*/
|
|
58
|
+
export declare class IncrementEvent implements BaseEvent {
|
|
59
|
+
readonly amount: number;
|
|
60
|
+
readonly type = "increment";
|
|
61
|
+
readonly timestamp: number;
|
|
62
|
+
constructor(amount?: number);
|
|
63
|
+
}
|
|
64
|
+
export declare class DecrementEvent implements BaseEvent {
|
|
65
|
+
readonly amount: number;
|
|
66
|
+
readonly type = "decrement";
|
|
67
|
+
readonly timestamp: number;
|
|
68
|
+
constructor(amount?: number);
|
|
69
|
+
}
|
|
70
|
+
export declare class ResetEvent implements BaseEvent {
|
|
71
|
+
readonly type = "reset";
|
|
72
|
+
readonly timestamp: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Example: Counter Vertex
|
|
76
|
+
* Demonstrates proper typing and event handling
|
|
77
|
+
*/
|
|
78
|
+
export declare class CounterVertex extends Vertex<number> {
|
|
79
|
+
constructor();
|
|
80
|
+
increment: (amount?: number) => void;
|
|
81
|
+
decrement: (amount?: number) => void;
|
|
82
|
+
reset: () => void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Auth State and Events for testing async handlers
|
|
86
|
+
*/
|
|
87
|
+
export interface AuthState {
|
|
88
|
+
isAuthenticated: boolean;
|
|
89
|
+
isLoading: boolean;
|
|
90
|
+
user: {
|
|
91
|
+
id: string;
|
|
92
|
+
name: string;
|
|
93
|
+
email: string;
|
|
94
|
+
} | null;
|
|
95
|
+
error: string | null;
|
|
96
|
+
}
|
|
97
|
+
export declare class LoginEvent implements BaseEvent {
|
|
98
|
+
readonly email: string;
|
|
99
|
+
readonly password: string;
|
|
100
|
+
readonly type = "login";
|
|
101
|
+
readonly timestamp: number;
|
|
102
|
+
constructor(email: string, password: string);
|
|
103
|
+
}
|
|
104
|
+
export declare class LogoutEvent implements BaseEvent {
|
|
105
|
+
readonly type = "logout";
|
|
106
|
+
readonly timestamp: number;
|
|
107
|
+
}
|
|
108
|
+
export declare class AuthVertex extends Vertex<AuthState> {
|
|
109
|
+
constructor();
|
|
110
|
+
login: (email: string, password: string) => void;
|
|
111
|
+
logout: () => void;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=Vertex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Vertex.d.ts","sourceRoot":"","sources":["../../src/core/Vertex.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,IAAI,CACjD,KAAK,EAAE,CAAC,EACR,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KACrB,IAAI,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,KAC9D,GAAG,IAAI,EAAE,KAAK,EAAE,KACb,CAAC,CAAC;AAUP;;;;;GAKG;AACH,8BAAsB,MAAM,CAC1B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