@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.d.cts CHANGED
@@ -200,14 +200,14 @@ export declare interface BlacPluginWithInit extends BlacPlugin {
200
200
  * @template TBloc - The StateContainer instance type
201
201
  */
202
202
  export declare type BlocConstructor<TBloc extends StateContainer<any, any>> = (new (...args: any[]) => TBloc) & {
203
- resolve(instanceKey?: string, ...args: any[]): TBloc;
204
- get(instanceKey?: string): TBloc;
205
- getSafe(instanceKey?: string): {
203
+ resolve<S = never>(instanceKey?: string, ...args: any[]): StateOverride<TBloc, S>;
204
+ get<S = never>(instanceKey?: string): StateOverride<TBloc, S>;
205
+ getSafe<S = never>(instanceKey?: string): {
206
206
  error: Error;
207
207
  instance: null;
208
208
  } | {
209
209
  error: null;
210
- instance: TBloc;
210
+ instance: StateOverride<TBloc, S>;
211
211
  };
212
212
  release(instanceKey?: string): void;
213
213
  isolated?: boolean;
@@ -923,59 +923,67 @@ export declare abstract class StateContainer<S, P = undefined> {
923
923
  /**
924
924
  * Resolve an instance with ref counting (ownership semantics).
925
925
  * Creates a new instance if one doesn't exist, or returns existing and increments ref count.
926
+ * @template S - Optional state type override for generic StateContainers
927
+ * @template T - The StateContainer type (inferred from class)
926
928
  * @param instanceKey - Optional instance key (defaults to 'default')
927
929
  * @param constructorArgs - Arguments to pass to constructor if creating new instance
928
930
  * @returns The state container instance
929
931
  */
930
- static resolve<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
932
+ static resolve<S = never, T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): StateOverride<T, S>;
931
933
  /**
932
934
  * Get an existing instance without incrementing ref count (borrowing semantics).
935
+ * @template S - Optional state type override for generic StateContainers
936
+ * @template T - The StateContainer type (inferred from class)
933
937
  * @param instanceKey - Optional instance key (defaults to 'default')
934
938
  * @returns The state container instance
935
939
  * @throws Error if instance doesn't exist
936
940
  */
937
- static get<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): T;
941
+ static get<S = never, T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): StateOverride<T, S>;
938
942
  /**
939
943
  * Safely get an existing instance with error handling.
944
+ * @template S - Optional state type override for generic StateContainers
945
+ * @template T - The StateContainer type (inferred from class)
940
946
  * @param instanceKey - Optional instance key (defaults to 'default')
941
947
  * @returns Discriminated union with either the instance or an error
942
948
  */
943
- static getSafe<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): {
949
+ static getSafe<S = never, T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): {
944
950
  error: Error;
945
951
  instance: null;
946
952
  } | {
947
953
  error: null;
948
- instance: T;
954
+ instance: StateOverride<T, S>;
949
955
  };
950
956
  /**
951
957
  * Connect to an instance for bloc-to-bloc communication (borrowing semantics).
952
958
  * Gets or creates instance without incrementing ref count.
959
+ * @template S - Optional state type override for generic StateContainers
960
+ * @template T - The StateContainer type (inferred from class)
953
961
  * @param instanceKey - Optional instance key (defaults to 'default')
954
962
  * @param constructorArgs - Arguments to pass to constructor if creating new instance
955
963
  * @returns The state container instance
956
964
  */
957
- static connect<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
965
+ static connect<S = never, T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): StateOverride<T, S>;
958
966
  /**
959
967
  * Release a reference to an instance.
960
968
  * Decrements ref count and disposes when it reaches 0 (unless keepAlive).
961
969
  * @param instanceKey - Optional instance key (defaults to 'default')
962
970
  * @param forceDispose - Force immediate disposal regardless of ref count
963
971
  */
964
- static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, forceDispose?: boolean): void;
972
+ static release<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, forceDispose?: boolean): void;
965
973
  /**
966
974
  * Get all instances of this class
967
975
  * @returns Array of all instances
968
976
  */
969
- static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
977
+ static getAll<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T): T[];
970
978
  /**
971
979
  * Iterate over all instances of this class
972
980
  * @param callback - Function to call for each instance
973
981
  */
974
- static forEach<T extends StateContainer<any>>(this: new (...args: any[]) => T, callback: (instance: T) => void): void;
982
+ static forEach<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, callback: (instance: T) => void): void;
975
983
  /**
976
984
  * Clear all instances of this class (disposes them)
977
985
  */
978
- static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
986
+ static clear<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T): void;
979
987
  /**
980
988
  * Clear all instances from all registered types
981
989
  */
@@ -994,13 +1002,13 @@ export declare abstract class StateContainer<S, P = undefined> {
994
1002
  * @param instanceKey - Optional instance key (defaults to 'default')
995
1003
  * @returns Current ref count (0 if instance doesn't exist)
996
1004
  */
997
- static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): number;
1005
+ static getRefCount<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): number;
998
1006
  /**
999
1007
  * Check if an instance exists
1000
1008
  * @param instanceKey - Optional instance key (defaults to 'default')
1001
1009
  * @returns true if instance exists
1002
1010
  */
1003
- static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): boolean;
1011
+ static hasInstance<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): boolean;
1004
1012
  private _state;
1005
1013
  private readonly listeners;
1006
1014
  private _disposed;
@@ -1211,6 +1219,25 @@ export declare class StateContainerRegistry {
1211
1219
 
1212
1220
  /* Excluded from this release type: StateListener */
1213
1221
 
1222
+ /**
1223
+ * Conditionally override the state type of a StateContainer.
1224
+ * When S is `never`, returns T unchanged (inferred state type).
1225
+ * When S is provided, replaces the state type while preserving all other properties.
1226
+ *
1227
+ * @template T - The StateContainer type
1228
+ * @template S - The state type override (defaults to never)
1229
+ *
1230
+ * @example
1231
+ * // Without override - returns original type
1232
+ * type Result1 = StateOverride<MyBloc>; // MyBloc
1233
+ *
1234
+ * // With override - replaces state type
1235
+ * type Result2 = StateOverride<MyBloc, CustomState>; // Omit<MyBloc, 'state'> & { readonly state: CustomState }
1236
+ */
1237
+ export declare type StateOverride<T extends StateContainer<any, any>, S = never> = [S] extends [never] ? T : Omit<T, 'state'> & {
1238
+ readonly state: S;
1239
+ };
1240
+
1214
1241
  /* Excluded from this release type: stopProxyTracking */
1215
1242
 
1216
1243
  /**
package/dist/index.d.ts CHANGED
@@ -200,14 +200,14 @@ export declare interface BlacPluginWithInit extends BlacPlugin {
200
200
  * @template TBloc - The StateContainer instance type
201
201
  */
202
202
  export declare type BlocConstructor<TBloc extends StateContainer<any, any>> = (new (...args: any[]) => TBloc) & {
203
- resolve(instanceKey?: string, ...args: any[]): TBloc;
204
- get(instanceKey?: string): TBloc;
205
- getSafe(instanceKey?: string): {
203
+ resolve<S = never>(instanceKey?: string, ...args: any[]): StateOverride<TBloc, S>;
204
+ get<S = never>(instanceKey?: string): StateOverride<TBloc, S>;
205
+ getSafe<S = never>(instanceKey?: string): {
206
206
  error: Error;
207
207
  instance: null;
208
208
  } | {
209
209
  error: null;
210
- instance: TBloc;
210
+ instance: StateOverride<TBloc, S>;
211
211
  };
212
212
  release(instanceKey?: string): void;
213
213
  isolated?: boolean;
@@ -923,59 +923,67 @@ export declare abstract class StateContainer<S, P = undefined> {
923
923
  /**
924
924
  * Resolve an instance with ref counting (ownership semantics).
925
925
  * Creates a new instance if one doesn't exist, or returns existing and increments ref count.
926
+ * @template S - Optional state type override for generic StateContainers
927
+ * @template T - The StateContainer type (inferred from class)
926
928
  * @param instanceKey - Optional instance key (defaults to 'default')
927
929
  * @param constructorArgs - Arguments to pass to constructor if creating new instance
928
930
  * @returns The state container instance
929
931
  */
930
- static resolve<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
932
+ static resolve<S = never, T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): StateOverride<T, S>;
931
933
  /**
932
934
  * Get an existing instance without incrementing ref count (borrowing semantics).
935
+ * @template S - Optional state type override for generic StateContainers
936
+ * @template T - The StateContainer type (inferred from class)
933
937
  * @param instanceKey - Optional instance key (defaults to 'default')
934
938
  * @returns The state container instance
935
939
  * @throws Error if instance doesn't exist
936
940
  */
937
- static get<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): T;
941
+ static get<S = never, T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): StateOverride<T, S>;
938
942
  /**
939
943
  * Safely get an existing instance with error handling.
944
+ * @template S - Optional state type override for generic StateContainers
945
+ * @template T - The StateContainer type (inferred from class)
940
946
  * @param instanceKey - Optional instance key (defaults to 'default')
941
947
  * @returns Discriminated union with either the instance or an error
942
948
  */
943
- static getSafe<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): {
949
+ static getSafe<S = never, T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): {
944
950
  error: Error;
945
951
  instance: null;
946
952
  } | {
947
953
  error: null;
948
- instance: T;
954
+ instance: StateOverride<T, S>;
949
955
  };
950
956
  /**
951
957
  * Connect to an instance for bloc-to-bloc communication (borrowing semantics).
952
958
  * Gets or creates instance without incrementing ref count.
959
+ * @template S - Optional state type override for generic StateContainers
960
+ * @template T - The StateContainer type (inferred from class)
953
961
  * @param instanceKey - Optional instance key (defaults to 'default')
954
962
  * @param constructorArgs - Arguments to pass to constructor if creating new instance
955
963
  * @returns The state container instance
956
964
  */
957
- static connect<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
965
+ static connect<S = never, T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): StateOverride<T, S>;
958
966
  /**
959
967
  * Release a reference to an instance.
960
968
  * Decrements ref count and disposes when it reaches 0 (unless keepAlive).
961
969
  * @param instanceKey - Optional instance key (defaults to 'default')
962
970
  * @param forceDispose - Force immediate disposal regardless of ref count
963
971
  */
964
- static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, forceDispose?: boolean): void;
972
+ static release<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, forceDispose?: boolean): void;
965
973
  /**
966
974
  * Get all instances of this class
967
975
  * @returns Array of all instances
968
976
  */
969
- static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
977
+ static getAll<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T): T[];
970
978
  /**
971
979
  * Iterate over all instances of this class
972
980
  * @param callback - Function to call for each instance
973
981
  */
974
- static forEach<T extends StateContainer<any>>(this: new (...args: any[]) => T, callback: (instance: T) => void): void;
982
+ static forEach<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, callback: (instance: T) => void): void;
975
983
  /**
976
984
  * Clear all instances of this class (disposes them)
977
985
  */
978
- static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
986
+ static clear<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T): void;
979
987
  /**
980
988
  * Clear all instances from all registered types
981
989
  */
@@ -994,13 +1002,13 @@ export declare abstract class StateContainer<S, P = undefined> {
994
1002
  * @param instanceKey - Optional instance key (defaults to 'default')
995
1003
  * @returns Current ref count (0 if instance doesn't exist)
996
1004
  */
997
- static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): number;
1005
+ static getRefCount<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): number;
998
1006
  /**
999
1007
  * Check if an instance exists
1000
1008
  * @param instanceKey - Optional instance key (defaults to 'default')
1001
1009
  * @returns true if instance exists
1002
1010
  */
1003
- static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): boolean;
1011
+ static hasInstance<T extends StateContainer<any> = StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): boolean;
1004
1012
  private _state;
1005
1013
  private readonly listeners;
1006
1014
  private _disposed;
@@ -1211,6 +1219,25 @@ export declare class StateContainerRegistry {
1211
1219
 
1212
1220
  /* Excluded from this release type: StateListener */
1213
1221
 
1222
+ /**
1223
+ * Conditionally override the state type of a StateContainer.
1224
+ * When S is `never`, returns T unchanged (inferred state type).
1225
+ * When S is provided, replaces the state type while preserving all other properties.
1226
+ *
1227
+ * @template T - The StateContainer type
1228
+ * @template S - The state type override (defaults to never)
1229
+ *
1230
+ * @example
1231
+ * // Without override - returns original type
1232
+ * type Result1 = StateOverride<MyBloc>; // MyBloc
1233
+ *
1234
+ * // With override - replaces state type
1235
+ * type Result2 = StateOverride<MyBloc, CustomState>; // Omit<MyBloc, 'state'> & { readonly state: CustomState }
1236
+ */
1237
+ export declare type StateOverride<T extends StateContainer<any, any>, S = never> = [S] extends [never] ? T : Omit<T, 'state'> & {
1238
+ readonly state: S;
1239
+ };
1240
+
1214
1241
  /* Excluded from this release type: stopProxyTracking */
1215
1242
 
1216
1243
  /**
package/dist/index.js CHANGED
@@ -886,6 +886,8 @@ var StateContainer = class StateContainer {
886
886
  /**
887
887
  * Resolve an instance with ref counting (ownership semantics).
888
888
  * Creates a new instance if one doesn't exist, or returns existing and increments ref count.
889
+ * @template S - Optional state type override for generic StateContainers
890
+ * @template T - The StateContainer type (inferred from class)
889
891
  * @param instanceKey - Optional instance key (defaults to 'default')
890
892
  * @param constructorArgs - Arguments to pass to constructor if creating new instance
891
893
  * @returns The state container instance
@@ -895,6 +897,8 @@ var StateContainer = class StateContainer {
895
897
  }
896
898
  /**
897
899
  * Get an existing instance without incrementing ref count (borrowing semantics).
900
+ * @template S - Optional state type override for generic StateContainers
901
+ * @template T - The StateContainer type (inferred from class)
898
902
  * @param instanceKey - Optional instance key (defaults to 'default')
899
903
  * @returns The state container instance
900
904
  * @throws Error if instance doesn't exist
@@ -904,6 +908,8 @@ var StateContainer = class StateContainer {
904
908
  }
905
909
  /**
906
910
  * Safely get an existing instance with error handling.
911
+ * @template S - Optional state type override for generic StateContainers
912
+ * @template T - The StateContainer type (inferred from class)
907
913
  * @param instanceKey - Optional instance key (defaults to 'default')
908
914
  * @returns Discriminated union with either the instance or an error
909
915
  */
@@ -913,6 +919,8 @@ var StateContainer = class StateContainer {
913
919
  /**
914
920
  * Connect to an instance for bloc-to-bloc communication (borrowing semantics).
915
921
  * Gets or creates instance without incrementing ref count.
922
+ * @template S - Optional state type override for generic StateContainers
923
+ * @template T - The StateContainer type (inferred from class)
916
924
  * @param instanceKey - Optional instance key (defaults to 'default')
917
925
  * @param constructorArgs - Arguments to pass to constructor if creating new instance
918
926
  * @returns The state container instance