@adaas/a-concept 0.3.5 → 0.3.7

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.
@@ -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
  *
@@ -2978,6 +2987,15 @@ type A_TYPES_ScopeDependentComponents = A_Component | A_Entity | A_Fragment | A_
2978
2987
  type A_TYPES_ScopeIndependentComponents = A_Error | A_Scope | A_Caller;
2979
2988
 
2980
2989
  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[]> {
2990
+ /**
2991
+ * Auto-incrementing counter for generating unique scope IDs.
2992
+ */
2993
+ private static _nextUid;
2994
+ /**
2995
+ * Unique numeric ID for this scope instance. Used as a cache key discriminator
2996
+ * to prevent collisions between scopes with the same name or version.
2997
+ */
2998
+ readonly uid: number;
2981
2999
  /**
2982
3000
  * Scope Name uses for identification and logging purposes
2983
3001
  */
@@ -2992,6 +3010,20 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
2992
3010
  * throughout the execution pipeline or within running containers.
2993
3011
  */
2994
3012
  protected _meta: A_Meta<_MetaItems>;
3013
+ /**
3014
+ * Monotonically increasing version counter. Incremented on every mutation
3015
+ * (register, deregister, import, deimport, inherit, destroy) so that
3016
+ * external caches (e.g. A_Context feature-extension cache) can detect
3017
+ * staleness cheaply via numeric comparison.
3018
+ */
3019
+ protected _version: number;
3020
+ /**
3021
+ * Cache for resolveConstructor results (both positive and negative).
3022
+ * Key = constructor name (string) or constructor reference toString.
3023
+ * Value = resolved constructor or `null` for negative results.
3024
+ * Invalidated by incrementing _version (cache is cleared on bump).
3025
+ */
3026
+ protected _resolveConstructorCache: Map<string | Function, Function | null>;
2995
3027
  /**
2996
3028
  * A set of allowed components, A set of constructors that are allowed in the scope
2997
3029
  *
@@ -3053,6 +3085,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3053
3085
  * Returns a list of Constructors for A-Errors that are available in the scope
3054
3086
  */
3055
3087
  get allowedErrors(): Set<_ErrorType[number]>;
3088
+ /**
3089
+ * Returns the current version of the scope. Each mutation increments the version,
3090
+ * allowing external caches to detect staleness via numeric comparison.
3091
+ */
3092
+ get version(): number;
3056
3093
  /**
3057
3094
  * Returns an Array of entities registered in the scope
3058
3095
  *
@@ -3089,6 +3126,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3089
3126
  * @returns
3090
3127
  */
3091
3128
  get parent(): A_Scope | undefined;
3129
+ /**
3130
+ * Increments the scope version and clears internal caches.
3131
+ * Must be called on every scope mutation (register, deregister, import, deimport, inherit, destroy).
3132
+ */
3133
+ protected bumpVersion(): void;
3092
3134
  /**
3093
3135
  * 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
3136
  * It refers to the visibility and accessibility of :
@@ -3388,6 +3430,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3388
3430
  */
3389
3431
  error: A_TYPES__Ctor<T>): A_TYPES__Error_Constructor<T> | undefined;
3390
3432
  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;
3433
+ /**
3434
+ * Internal uncached implementation of resolveConstructor for string names.
3435
+ * Separated to allow the public method to wrap with caching.
3436
+ */
3437
+ private _resolveConstructorUncached;
3391
3438
  /**
3392
3439
  * This method should resolve all instances of the components, or entities within the scope, by provided parent class
3393
3440
  * So in case of providing a base class it should return all instances that extends this base class
@@ -4151,6 +4198,23 @@ declare class A_Context {
4151
4198
  * Meta provides to store extra information about the class behavior and configuration.
4152
4199
  */
4153
4200
  protected _metaStorage: Map<A_TYPES__MetaLinkedComponentConstructors, A_Meta>;
4201
+ /**
4202
+ * Monotonically increasing version counter for _metaStorage.
4203
+ * Incremented whenever a new entry is added to _metaStorage so that
4204
+ * caches depending on meta content can detect staleness.
4205
+ */
4206
+ protected _metaVersion: number;
4207
+ /**
4208
+ * Cache for featureExtensions results.
4209
+ * Key format: `${featureName}::${componentConstructorName}::${scopeVersion}::${metaVersion}`
4210
+ * Automatically invalidated when scope version or meta version changes.
4211
+ */
4212
+ protected _featureExtensionsCache: Map<string, Array<A_TYPES__A_StageStep>>;
4213
+ /**
4214
+ * Maximum number of entries in the featureExtensions cache.
4215
+ * When exceeded, the entire cache is cleared to prevent unbounded growth.
4216
+ */
4217
+ protected static readonly FEATURE_EXTENSIONS_CACHE_MAX_SIZE = 1024;
4154
4218
  protected _globals: Map<string, any>;
4155
4219
  /**
4156
4220
  * Private constructor to enforce singleton pattern.
@@ -4408,6 +4472,10 @@ declare class A_Context {
4408
4472
  /**
4409
4473
  * method helps to filter steps in a way that only the most derived classes are kept.
4410
4474
  *
4475
+ * Optimized: Uses a pre-built constructor→class map and single-pass prototype chain
4476
+ * walk to eliminate parent classes in O(n·d) where d is inheritance depth,
4477
+ * instead of the previous O(n²) with isPrototypeOf checks.
4478
+ *
4411
4479
  * @param scope
4412
4480
  * @param items
4413
4481
  * @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.
@@ -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
  *
@@ -2978,6 +2987,15 @@ type A_TYPES_ScopeDependentComponents = A_Component | A_Entity | A_Fragment | A_
2978
2987
  type A_TYPES_ScopeIndependentComponents = A_Error | A_Scope | A_Caller;
2979
2988
 
2980
2989
  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[]> {
2990
+ /**
2991
+ * Auto-incrementing counter for generating unique scope IDs.
2992
+ */
2993
+ private static _nextUid;
2994
+ /**
2995
+ * Unique numeric ID for this scope instance. Used as a cache key discriminator
2996
+ * to prevent collisions between scopes with the same name or version.
2997
+ */
2998
+ readonly uid: number;
2981
2999
  /**
2982
3000
  * Scope Name uses for identification and logging purposes
2983
3001
  */
@@ -2992,6 +3010,20 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
2992
3010
  * throughout the execution pipeline or within running containers.
2993
3011
  */
2994
3012
  protected _meta: A_Meta<_MetaItems>;
3013
+ /**
3014
+ * Monotonically increasing version counter. Incremented on every mutation
3015
+ * (register, deregister, import, deimport, inherit, destroy) so that
3016
+ * external caches (e.g. A_Context feature-extension cache) can detect
3017
+ * staleness cheaply via numeric comparison.
3018
+ */
3019
+ protected _version: number;
3020
+ /**
3021
+ * Cache for resolveConstructor results (both positive and negative).
3022
+ * Key = constructor name (string) or constructor reference toString.
3023
+ * Value = resolved constructor or `null` for negative results.
3024
+ * Invalidated by incrementing _version (cache is cleared on bump).
3025
+ */
3026
+ protected _resolveConstructorCache: Map<string | Function, Function | null>;
2995
3027
  /**
2996
3028
  * A set of allowed components, A set of constructors that are allowed in the scope
2997
3029
  *
@@ -3053,6 +3085,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3053
3085
  * Returns a list of Constructors for A-Errors that are available in the scope
3054
3086
  */
3055
3087
  get allowedErrors(): Set<_ErrorType[number]>;
3088
+ /**
3089
+ * Returns the current version of the scope. Each mutation increments the version,
3090
+ * allowing external caches to detect staleness via numeric comparison.
3091
+ */
3092
+ get version(): number;
3056
3093
  /**
3057
3094
  * Returns an Array of entities registered in the scope
3058
3095
  *
@@ -3089,6 +3126,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3089
3126
  * @returns
3090
3127
  */
3091
3128
  get parent(): A_Scope | undefined;
3129
+ /**
3130
+ * Increments the scope version and clears internal caches.
3131
+ * Must be called on every scope mutation (register, deregister, import, deimport, inherit, destroy).
3132
+ */
3133
+ protected bumpVersion(): void;
3092
3134
  /**
3093
3135
  * 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
3136
  * It refers to the visibility and accessibility of :
@@ -3388,6 +3430,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
3388
3430
  */
3389
3431
  error: A_TYPES__Ctor<T>): A_TYPES__Error_Constructor<T> | undefined;
3390
3432
  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;
3433
+ /**
3434
+ * Internal uncached implementation of resolveConstructor for string names.
3435
+ * Separated to allow the public method to wrap with caching.
3436
+ */
3437
+ private _resolveConstructorUncached;
3391
3438
  /**
3392
3439
  * This method should resolve all instances of the components, or entities within the scope, by provided parent class
3393
3440
  * So in case of providing a base class it should return all instances that extends this base class
@@ -4151,6 +4198,23 @@ declare class A_Context {
4151
4198
  * Meta provides to store extra information about the class behavior and configuration.
4152
4199
  */
4153
4200
  protected _metaStorage: Map<A_TYPES__MetaLinkedComponentConstructors, A_Meta>;
4201
+ /**
4202
+ * Monotonically increasing version counter for _metaStorage.
4203
+ * Incremented whenever a new entry is added to _metaStorage so that
4204
+ * caches depending on meta content can detect staleness.
4205
+ */
4206
+ protected _metaVersion: number;
4207
+ /**
4208
+ * Cache for featureExtensions results.
4209
+ * Key format: `${featureName}::${componentConstructorName}::${scopeVersion}::${metaVersion}`
4210
+ * Automatically invalidated when scope version or meta version changes.
4211
+ */
4212
+ protected _featureExtensionsCache: Map<string, Array<A_TYPES__A_StageStep>>;
4213
+ /**
4214
+ * Maximum number of entries in the featureExtensions cache.
4215
+ * When exceeded, the entire cache is cleared to prevent unbounded growth.
4216
+ */
4217
+ protected static readonly FEATURE_EXTENSIONS_CACHE_MAX_SIZE = 1024;
4154
4218
  protected _globals: Map<string, any>;
4155
4219
  /**
4156
4220
  * Private constructor to enforce singleton pattern.
@@ -4408,6 +4472,10 @@ declare class A_Context {
4408
4472
  /**
4409
4473
  * method helps to filter steps in a way that only the most derived classes are kept.
4410
4474
  *
4475
+ * Optimized: Uses a pre-built constructor→class map and single-pass prototype chain
4476
+ * walk to eliminate parent classes in O(n·d) where d is inheritance depth,
4477
+ * instead of the previous O(n²) with isPrototypeOf checks.
4478
+ *
4411
4479
  * @param scope
4412
4480
  * @param items
4413
4481
  * @returns