@adaas/a-concept 0.3.6 → 0.3.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.
@@ -783,6 +783,11 @@ declare class A_Meta<_StorageItems extends Record<any, any> = any, _SerializedTy
783
783
  * @param key
784
784
  * @returns
785
785
  */
786
+ /**
787
+ * Cache for compiled RegExp instances keyed by their string source.
788
+ * Avoids re-compiling the same regex pattern on every find() call.
789
+ */
790
+ private _regExpCache?;
786
791
  private convertToRegExp;
787
792
  /**
788
793
  * Method to find values in the map by name.
@@ -1079,7 +1084,7 @@ declare class A_Entity<_ConstructorType extends A_TYPES__Entity_Init = A_TYPES__
1079
1084
  * @param lifecycleMethod
1080
1085
  * @param args
1081
1086
  */
1082
- call(feature: string, scope?: A_Scope): any;
1087
+ call(feature: string, scope?: A_Scope): Promise<any> | void;
1083
1088
  /**
1084
1089
  * The default method that can be called and extended to load entity data.
1085
1090
  */
@@ -1487,8 +1492,10 @@ type A_TYPES__FeatureAvailableComponents = InstanceType<A_TYPES__FeatureAvailabl
1487
1492
  type A_TYPES__FeatureAvailableConstructors = A_TYPES__Component_Constructor | A_TYPES__Entity_Constructor | A_TYPES__Container_Constructor;
1488
1493
  /**
1489
1494
  * Indicates a type of Feature Define decorator
1495
+ *
1496
+ * [!] Uses a single generic descriptor to support both sync and async methods
1490
1497
  */
1491
- type A_TYPES__FeatureDefineDecoratorDescriptor = TypedPropertyDescriptor<(...args: any[]) => any> | TypedPropertyDescriptor<(...args: any[]) => any> | TypedPropertyDescriptor<(...args: any[]) => Promise<any>> | TypedPropertyDescriptor<(...args: any[]) => Promise<any>>;
1498
+ type A_TYPES__FeatureDefineDecoratorDescriptor = TypedPropertyDescriptor<(...args: any[]) => any>;
1492
1499
  /**
1493
1500
  * Describes additional configuration properties to be used in Feature Define decorator
1494
1501
  */
@@ -1549,8 +1556,10 @@ type A_TYPES__FeatureDefineDecoratorMeta = {
1549
1556
  };
1550
1557
  /**
1551
1558
  * Descriptor type for A_Extend decorator
1559
+ *
1560
+ * [!] Uses a single generic descriptor to support both sync and async methods
1552
1561
  */
1553
- type A_TYPES__FeatureExtendDecoratorDescriptor = TypedPropertyDescriptor<() => any> | TypedPropertyDescriptor<(...args: any[]) => any> | TypedPropertyDescriptor<(...args: any[]) => Promise<any>> | TypedPropertyDescriptor<() => Promise<any>>;
1562
+ type A_TYPES__FeatureExtendDecoratorDescriptor = TypedPropertyDescriptor<(...args: any[]) => any>;
1554
1563
  /**
1555
1564
  * Target type for A_Extend decorator
1556
1565
  *
@@ -2004,6 +2013,7 @@ declare class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES_
2004
2013
  * Process stages one by one, ensuring each stage completes before starting the next
2005
2014
  */
2006
2015
  private processStagesSequentially;
2016
+ private createStageError;
2007
2017
  /**
2008
2018
  * This method moves the feature to the next stage
2009
2019
  *
@@ -2978,6 +2988,15 @@ type A_TYPES_ScopeDependentComponents = A_Component | A_Entity | A_Fragment | A_
2978
2988
  type A_TYPES_ScopeIndependentComponents = A_Error | A_Scope | A_Caller;
2979
2989
 
2980
2990
  declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentType extends A_TYPES__Component_Constructor[] = A_TYPES__Component_Constructor[], _ErrorType extends A_TYPES__Error_Constructor[] = A_TYPES__Error_Constructor[], _EntityType extends A_TYPES__Entity_Constructor[] = A_TYPES__Entity_Constructor[], _FragmentType extends A_Fragment[] = A_Fragment[]> {
2991
+ /**
2992
+ * Auto-incrementing counter for generating unique scope IDs.
2993
+ */
2994
+ private static _nextUid;
2995
+ /**
2996
+ * Unique numeric ID for this scope instance. Used as a cache key discriminator
2997
+ * to prevent collisions between scopes with the same name or version.
2998
+ */
2999
+ readonly uid: number;
2981
3000
  /**
2982
3001
  * Scope Name uses for identification and logging purposes
2983
3002
  */
@@ -2992,6 +3011,20 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
2992
3011
  * throughout the execution pipeline or within running containers.
2993
3012
  */
2994
3013
  protected _meta: A_Meta<_MetaItems>;
3014
+ /**
3015
+ * Monotonically increasing version counter. Incremented on every mutation
3016
+ * (register, deregister, import, deimport, inherit, destroy) so that
3017
+ * external caches (e.g. A_Context feature-extension cache) can detect
3018
+ * staleness cheaply via numeric comparison.
3019
+ */
3020
+ protected _version: number;
3021
+ /**
3022
+ * Cache for resolveConstructor results (both positive and negative).
3023
+ * Key = constructor name (string) or constructor reference toString.
3024
+ * Value = resolved constructor or `null` for negative results.
3025
+ * Invalidated by incrementing _version (cache is cleared on bump).
3026
+ */
3027
+ protected _resolveConstructorCache: Map<string | Function, Function | null>;
2995
3028
  /**
2996
3029
  * A set of allowed components, A set of constructors that are allowed in the scope
2997
3030
  *
@@ -3053,6 +3086,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3053
3086
  * Returns a list of Constructors for A-Errors that are available in the scope
3054
3087
  */
3055
3088
  get allowedErrors(): Set<_ErrorType[number]>;
3089
+ /**
3090
+ * Returns the current version of the scope. Each mutation increments the version,
3091
+ * allowing external caches to detect staleness via numeric comparison.
3092
+ */
3093
+ get version(): number;
3056
3094
  /**
3057
3095
  * Returns an Array of entities registered in the scope
3058
3096
  *
@@ -3089,6 +3127,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3089
3127
  * @returns
3090
3128
  */
3091
3129
  get parent(): A_Scope | undefined;
3130
+ /**
3131
+ * Increments the scope version and clears internal caches.
3132
+ * Must be called on every scope mutation (register, deregister, import, deimport, inherit, destroy).
3133
+ */
3134
+ protected bumpVersion(): void;
3092
3135
  /**
3093
3136
  * A_Scope is a unique A-Concept Structure that allows to operate with A-Concept Primitives and Models in a specific context and with specific rules.
3094
3137
  * It refers to the visibility and accessibility of :
@@ -3388,6 +3431,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3388
3431
  */
3389
3432
  error: A_TYPES__Ctor<T>): A_TYPES__Error_Constructor<T> | undefined;
3390
3433
  resolveConstructor<T extends A_TYPES__A_DependencyInjectable>(name: string | A_TYPES__Ctor<T>): A_TYPES__Entity_Constructor<T> | A_TYPES__Component_Constructor<T> | A_TYPES__Fragment_Constructor<T> | undefined;
3434
+ /**
3435
+ * Internal uncached implementation of resolveConstructor for string names.
3436
+ * Separated to allow the public method to wrap with caching.
3437
+ */
3438
+ private _resolveConstructorUncached;
3391
3439
  /**
3392
3440
  * This method should resolve all instances of the components, or entities within the scope, by provided parent class
3393
3441
  * So in case of providing a base class it should return all instances that extends this base class
@@ -4151,6 +4199,23 @@ declare class A_Context {
4151
4199
  * Meta provides to store extra information about the class behavior and configuration.
4152
4200
  */
4153
4201
  protected _metaStorage: Map<A_TYPES__MetaLinkedComponentConstructors, A_Meta>;
4202
+ /**
4203
+ * Monotonically increasing version counter for _metaStorage.
4204
+ * Incremented whenever a new entry is added to _metaStorage so that
4205
+ * caches depending on meta content can detect staleness.
4206
+ */
4207
+ protected _metaVersion: number;
4208
+ /**
4209
+ * Cache for featureExtensions results.
4210
+ * Key format: `${featureName}::${componentConstructorName}::${scopeVersion}::${metaVersion}`
4211
+ * Automatically invalidated when scope version or meta version changes.
4212
+ */
4213
+ protected _featureExtensionsCache: Map<string, Array<A_TYPES__A_StageStep>>;
4214
+ /**
4215
+ * Maximum number of entries in the featureExtensions cache.
4216
+ * When exceeded, the entire cache is cleared to prevent unbounded growth.
4217
+ */
4218
+ protected static readonly FEATURE_EXTENSIONS_CACHE_MAX_SIZE = 1024;
4154
4219
  protected _globals: Map<string, any>;
4155
4220
  /**
4156
4221
  * Private constructor to enforce singleton pattern.
@@ -4408,6 +4473,10 @@ declare class A_Context {
4408
4473
  /**
4409
4474
  * method helps to filter steps in a way that only the most derived classes are kept.
4410
4475
  *
4476
+ * Optimized: Uses a pre-built constructor→class map and single-pass prototype chain
4477
+ * walk to eliminate parent classes in O(n·d) where d is inheritance depth,
4478
+ * instead of the previous O(n²) with isPrototypeOf checks.
4479
+ *
4411
4480
  * @param scope
4412
4481
  * @param items
4413
4482
  * @returns
@@ -783,6 +783,11 @@ declare class A_Meta<_StorageItems extends Record<any, any> = any, _SerializedTy
783
783
  * @param key
784
784
  * @returns
785
785
  */
786
+ /**
787
+ * Cache for compiled RegExp instances keyed by their string source.
788
+ * Avoids re-compiling the same regex pattern on every find() call.
789
+ */
790
+ private _regExpCache?;
786
791
  private convertToRegExp;
787
792
  /**
788
793
  * Method to find values in the map by name.
@@ -1079,7 +1084,7 @@ declare class A_Entity<_ConstructorType extends A_TYPES__Entity_Init = A_TYPES__
1079
1084
  * @param lifecycleMethod
1080
1085
  * @param args
1081
1086
  */
1082
- call(feature: string, scope?: A_Scope): any;
1087
+ call(feature: string, scope?: A_Scope): Promise<any> | void;
1083
1088
  /**
1084
1089
  * The default method that can be called and extended to load entity data.
1085
1090
  */
@@ -1487,8 +1492,10 @@ type A_TYPES__FeatureAvailableComponents = InstanceType<A_TYPES__FeatureAvailabl
1487
1492
  type A_TYPES__FeatureAvailableConstructors = A_TYPES__Component_Constructor | A_TYPES__Entity_Constructor | A_TYPES__Container_Constructor;
1488
1493
  /**
1489
1494
  * Indicates a type of Feature Define decorator
1495
+ *
1496
+ * [!] Uses a single generic descriptor to support both sync and async methods
1490
1497
  */
1491
- type A_TYPES__FeatureDefineDecoratorDescriptor = TypedPropertyDescriptor<(...args: any[]) => any> | TypedPropertyDescriptor<(...args: any[]) => any> | TypedPropertyDescriptor<(...args: any[]) => Promise<any>> | TypedPropertyDescriptor<(...args: any[]) => Promise<any>>;
1498
+ type A_TYPES__FeatureDefineDecoratorDescriptor = TypedPropertyDescriptor<(...args: any[]) => any>;
1492
1499
  /**
1493
1500
  * Describes additional configuration properties to be used in Feature Define decorator
1494
1501
  */
@@ -1549,8 +1556,10 @@ type A_TYPES__FeatureDefineDecoratorMeta = {
1549
1556
  };
1550
1557
  /**
1551
1558
  * Descriptor type for A_Extend decorator
1559
+ *
1560
+ * [!] Uses a single generic descriptor to support both sync and async methods
1552
1561
  */
1553
- type A_TYPES__FeatureExtendDecoratorDescriptor = TypedPropertyDescriptor<() => any> | TypedPropertyDescriptor<(...args: any[]) => any> | TypedPropertyDescriptor<(...args: any[]) => Promise<any>> | TypedPropertyDescriptor<() => Promise<any>>;
1562
+ type A_TYPES__FeatureExtendDecoratorDescriptor = TypedPropertyDescriptor<(...args: any[]) => any>;
1554
1563
  /**
1555
1564
  * Target type for A_Extend decorator
1556
1565
  *
@@ -2004,6 +2013,7 @@ declare class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES_
2004
2013
  * Process stages one by one, ensuring each stage completes before starting the next
2005
2014
  */
2006
2015
  private processStagesSequentially;
2016
+ private createStageError;
2007
2017
  /**
2008
2018
  * This method moves the feature to the next stage
2009
2019
  *
@@ -2978,6 +2988,15 @@ type A_TYPES_ScopeDependentComponents = A_Component | A_Entity | A_Fragment | A_
2978
2988
  type A_TYPES_ScopeIndependentComponents = A_Error | A_Scope | A_Caller;
2979
2989
 
2980
2990
  declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentType extends A_TYPES__Component_Constructor[] = A_TYPES__Component_Constructor[], _ErrorType extends A_TYPES__Error_Constructor[] = A_TYPES__Error_Constructor[], _EntityType extends A_TYPES__Entity_Constructor[] = A_TYPES__Entity_Constructor[], _FragmentType extends A_Fragment[] = A_Fragment[]> {
2991
+ /**
2992
+ * Auto-incrementing counter for generating unique scope IDs.
2993
+ */
2994
+ private static _nextUid;
2995
+ /**
2996
+ * Unique numeric ID for this scope instance. Used as a cache key discriminator
2997
+ * to prevent collisions between scopes with the same name or version.
2998
+ */
2999
+ readonly uid: number;
2981
3000
  /**
2982
3001
  * Scope Name uses for identification and logging purposes
2983
3002
  */
@@ -2992,6 +3011,20 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
2992
3011
  * throughout the execution pipeline or within running containers.
2993
3012
  */
2994
3013
  protected _meta: A_Meta<_MetaItems>;
3014
+ /**
3015
+ * Monotonically increasing version counter. Incremented on every mutation
3016
+ * (register, deregister, import, deimport, inherit, destroy) so that
3017
+ * external caches (e.g. A_Context feature-extension cache) can detect
3018
+ * staleness cheaply via numeric comparison.
3019
+ */
3020
+ protected _version: number;
3021
+ /**
3022
+ * Cache for resolveConstructor results (both positive and negative).
3023
+ * Key = constructor name (string) or constructor reference toString.
3024
+ * Value = resolved constructor or `null` for negative results.
3025
+ * Invalidated by incrementing _version (cache is cleared on bump).
3026
+ */
3027
+ protected _resolveConstructorCache: Map<string | Function, Function | null>;
2995
3028
  /**
2996
3029
  * A set of allowed components, A set of constructors that are allowed in the scope
2997
3030
  *
@@ -3053,6 +3086,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3053
3086
  * Returns a list of Constructors for A-Errors that are available in the scope
3054
3087
  */
3055
3088
  get allowedErrors(): Set<_ErrorType[number]>;
3089
+ /**
3090
+ * Returns the current version of the scope. Each mutation increments the version,
3091
+ * allowing external caches to detect staleness via numeric comparison.
3092
+ */
3093
+ get version(): number;
3056
3094
  /**
3057
3095
  * Returns an Array of entities registered in the scope
3058
3096
  *
@@ -3089,6 +3127,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3089
3127
  * @returns
3090
3128
  */
3091
3129
  get parent(): A_Scope | undefined;
3130
+ /**
3131
+ * Increments the scope version and clears internal caches.
3132
+ * Must be called on every scope mutation (register, deregister, import, deimport, inherit, destroy).
3133
+ */
3134
+ protected bumpVersion(): void;
3092
3135
  /**
3093
3136
  * A_Scope is a unique A-Concept Structure that allows to operate with A-Concept Primitives and Models in a specific context and with specific rules.
3094
3137
  * It refers to the visibility and accessibility of :
@@ -3388,6 +3431,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3388
3431
  */
3389
3432
  error: A_TYPES__Ctor<T>): A_TYPES__Error_Constructor<T> | undefined;
3390
3433
  resolveConstructor<T extends A_TYPES__A_DependencyInjectable>(name: string | A_TYPES__Ctor<T>): A_TYPES__Entity_Constructor<T> | A_TYPES__Component_Constructor<T> | A_TYPES__Fragment_Constructor<T> | undefined;
3434
+ /**
3435
+ * Internal uncached implementation of resolveConstructor for string names.
3436
+ * Separated to allow the public method to wrap with caching.
3437
+ */
3438
+ private _resolveConstructorUncached;
3391
3439
  /**
3392
3440
  * This method should resolve all instances of the components, or entities within the scope, by provided parent class
3393
3441
  * So in case of providing a base class it should return all instances that extends this base class
@@ -4151,6 +4199,23 @@ declare class A_Context {
4151
4199
  * Meta provides to store extra information about the class behavior and configuration.
4152
4200
  */
4153
4201
  protected _metaStorage: Map<A_TYPES__MetaLinkedComponentConstructors, A_Meta>;
4202
+ /**
4203
+ * Monotonically increasing version counter for _metaStorage.
4204
+ * Incremented whenever a new entry is added to _metaStorage so that
4205
+ * caches depending on meta content can detect staleness.
4206
+ */
4207
+ protected _metaVersion: number;
4208
+ /**
4209
+ * Cache for featureExtensions results.
4210
+ * Key format: `${featureName}::${componentConstructorName}::${scopeVersion}::${metaVersion}`
4211
+ * Automatically invalidated when scope version or meta version changes.
4212
+ */
4213
+ protected _featureExtensionsCache: Map<string, Array<A_TYPES__A_StageStep>>;
4214
+ /**
4215
+ * Maximum number of entries in the featureExtensions cache.
4216
+ * When exceeded, the entire cache is cleared to prevent unbounded growth.
4217
+ */
4218
+ protected static readonly FEATURE_EXTENSIONS_CACHE_MAX_SIZE = 1024;
4154
4219
  protected _globals: Map<string, any>;
4155
4220
  /**
4156
4221
  * Private constructor to enforce singleton pattern.
@@ -4408,6 +4473,10 @@ declare class A_Context {
4408
4473
  /**
4409
4474
  * method helps to filter steps in a way that only the most derived classes are kept.
4410
4475
  *
4476
+ * Optimized: Uses a pre-built constructor→class map and single-pass prototype chain
4477
+ * walk to eliminate parent classes in O(n·d) where d is inheritance depth,
4478
+ * instead of the previous O(n²) with isPrototypeOf checks.
4479
+ *
4411
4480
  * @param scope
4412
4481
  * @param items
4413
4482
  * @returns