@adaas/a-concept 0.3.7 → 0.3.9
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/benchmarks/feature-chaining.bench.ts +465 -0
- package/benchmarks/feature-optimize.bench.ts +280 -0
- package/dist/browser/index.d.mts +64 -13
- package/dist/browser/index.mjs +2 -2
- package/dist/browser/index.mjs.map +1 -1
- package/dist/node/index.cjs +329 -129
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.mts +64 -13
- package/dist/node/index.d.ts +64 -13
- package/dist/node/index.mjs +329 -129
- package/dist/node/index.mjs.map +1 -1
- package/package.json +3 -1
- package/src/lib/A-Context/A-Context.class.ts +214 -41
- package/src/lib/A-Entity/A-Entity.class.ts +3 -3
- package/src/lib/A-Feature/A-Feature.class.ts +64 -56
- package/src/lib/A-Scope/A-Scope.class.ts +143 -72
- package/tests/A-Feature.test.ts +101 -0
- package/tests/A-Meta.test.ts +46 -2
- package/tests/A-Scope.test.ts +188 -0
- package/tsconfig.json +1 -0
package/dist/node/index.d.mts
CHANGED
|
@@ -1084,7 +1084,7 @@ declare class A_Entity<_ConstructorType extends A_TYPES__Entity_Init = A_TYPES__
|
|
|
1084
1084
|
* @param lifecycleMethod
|
|
1085
1085
|
* @param args
|
|
1086
1086
|
*/
|
|
1087
|
-
call(feature: string, scope?: A_Scope): any;
|
|
1087
|
+
call(feature: string, scope?: A_Scope): Promise<any> | void;
|
|
1088
1088
|
/**
|
|
1089
1089
|
* The default method that can be called and extended to load entity data.
|
|
1090
1090
|
*/
|
|
@@ -2010,9 +2010,11 @@ declare class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES_
|
|
|
2010
2010
|
*/
|
|
2011
2011
|
scope?: A_Scope): Promise<void> | void;
|
|
2012
2012
|
/**
|
|
2013
|
-
*
|
|
2013
|
+
* Async continuation — processes remaining stages after the first async pivot.
|
|
2014
|
+
* Resumes from the current iterator position (this._index).
|
|
2014
2015
|
*/
|
|
2015
|
-
private
|
|
2016
|
+
private processRemainingStagesAsync;
|
|
2017
|
+
private createStageError;
|
|
2016
2018
|
/**
|
|
2017
2019
|
* This method moves the feature to the next stage
|
|
2018
2020
|
*
|
|
@@ -2987,15 +2989,6 @@ type A_TYPES_ScopeDependentComponents = A_Component | A_Entity | A_Fragment | A_
|
|
|
2987
2989
|
type A_TYPES_ScopeIndependentComponents = A_Error | A_Scope | A_Caller;
|
|
2988
2990
|
|
|
2989
2991
|
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;
|
|
2999
2992
|
/**
|
|
3000
2993
|
* Scope Name uses for identification and logging purposes
|
|
3001
2994
|
*/
|
|
@@ -3024,6 +3017,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
|
|
|
3024
3017
|
* Invalidated by incrementing _version (cache is cleared on bump).
|
|
3025
3018
|
*/
|
|
3026
3019
|
protected _resolveConstructorCache: Map<string | Function, Function | null>;
|
|
3020
|
+
/**
|
|
3021
|
+
* Cached fingerprint string. Invalidated on every bumpVersion() call.
|
|
3022
|
+
*/
|
|
3023
|
+
private _cachedFingerprint;
|
|
3024
|
+
private _cachedFingerprintVersion;
|
|
3027
3025
|
/**
|
|
3028
3026
|
* A set of allowed components, A set of constructors that are allowed in the scope
|
|
3029
3027
|
*
|
|
@@ -3090,6 +3088,12 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
|
|
|
3090
3088
|
* allowing external caches to detect staleness via numeric comparison.
|
|
3091
3089
|
*/
|
|
3092
3090
|
get version(): number;
|
|
3091
|
+
/**
|
|
3092
|
+
* Returns a content-addressable fingerprint of the scope.
|
|
3093
|
+
* Two scopes with identical content (components, entities, fragments, errors, imports, parent)
|
|
3094
|
+
* will produce the same fingerprint. Dynamically recomputed when scope content changes.
|
|
3095
|
+
*/
|
|
3096
|
+
get fingerprint(): string;
|
|
3093
3097
|
/**
|
|
3094
3098
|
* Returns an Array of entities registered in the scope
|
|
3095
3099
|
*
|
|
@@ -3131,6 +3135,16 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
|
|
|
3131
3135
|
* Must be called on every scope mutation (register, deregister, import, deimport, inherit, destroy).
|
|
3132
3136
|
*/
|
|
3133
3137
|
protected bumpVersion(): void;
|
|
3138
|
+
/**
|
|
3139
|
+
* Computes the aggregate version of this scope and all reachable scopes (parent + imports).
|
|
3140
|
+
* Used to detect when any transitive dependency has changed, so the fingerprint cache can be invalidated.
|
|
3141
|
+
*/
|
|
3142
|
+
private aggregateVersion;
|
|
3143
|
+
/**
|
|
3144
|
+
* Computes a deterministic content-addressable fingerprint string.
|
|
3145
|
+
* Includes components, entities, fragments, errors, parent, and imports.
|
|
3146
|
+
*/
|
|
3147
|
+
private computeFingerprint;
|
|
3134
3148
|
/**
|
|
3135
3149
|
* 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.
|
|
3136
3150
|
* It refers to the visibility and accessibility of :
|
|
@@ -4209,12 +4223,22 @@ declare class A_Context {
|
|
|
4209
4223
|
* Key format: `${featureName}::${componentConstructorName}::${scopeVersion}::${metaVersion}`
|
|
4210
4224
|
* Automatically invalidated when scope version or meta version changes.
|
|
4211
4225
|
*/
|
|
4212
|
-
protected
|
|
4226
|
+
protected _featureCache: Map<string, Array<A_TYPES__A_StageStep>>;
|
|
4213
4227
|
/**
|
|
4214
4228
|
* Maximum number of entries in the featureExtensions cache.
|
|
4215
4229
|
* When exceeded, the entire cache is cleared to prevent unbounded growth.
|
|
4216
4230
|
*/
|
|
4217
4231
|
protected static readonly FEATURE_EXTENSIONS_CACHE_MAX_SIZE = 1024;
|
|
4232
|
+
/**
|
|
4233
|
+
* For each indexed constructor, stores the set of all its ancestor constructors
|
|
4234
|
+
* (walking up the prototype chain). Enables O(1) isInheritedFrom checks.
|
|
4235
|
+
*/
|
|
4236
|
+
protected _ancestors: Map<Function, Set<Function>>;
|
|
4237
|
+
/**
|
|
4238
|
+
* For each constructor, stores the set of all known descendant constructors.
|
|
4239
|
+
* Enables O(1) "find a descendant in a Set" lookups.
|
|
4240
|
+
*/
|
|
4241
|
+
protected _descendants: Map<Function, Set<Function>>;
|
|
4218
4242
|
protected _globals: Map<string, any>;
|
|
4219
4243
|
/**
|
|
4220
4244
|
* Private constructor to enforce singleton pattern.
|
|
@@ -4530,6 +4554,33 @@ declare class A_Context {
|
|
|
4530
4554
|
* Resets the Context to its initial state.
|
|
4531
4555
|
*/
|
|
4532
4556
|
static reset(): void;
|
|
4557
|
+
/**
|
|
4558
|
+
* Index a constructor's full prototype chain into the inheritance graph.
|
|
4559
|
+
* Safe to call multiple times for the same constructor — it's a no-op if already indexed.
|
|
4560
|
+
*
|
|
4561
|
+
* After indexing, `A_Context.isIndexedInheritedFrom(child, parent)` becomes O(1).
|
|
4562
|
+
*/
|
|
4563
|
+
static indexConstructor(ctor: Function): void;
|
|
4564
|
+
/**
|
|
4565
|
+
* O(1) check whether `child` inherits from `parent` using the pre-built index.
|
|
4566
|
+
* Falls back to prototype chain walking if either is not yet indexed.
|
|
4567
|
+
*
|
|
4568
|
+
* [!] Handles the same-class case: returns true if child === parent.
|
|
4569
|
+
*/
|
|
4570
|
+
static isIndexedInheritedFrom(child: Function, parent: Function): boolean;
|
|
4571
|
+
/**
|
|
4572
|
+
* Find the first constructor in `candidates` that is a descendant of (or equal to) `parent`.
|
|
4573
|
+
* Returns undefined if none found.
|
|
4574
|
+
*
|
|
4575
|
+
* Uses the optimal strategy based on set sizes:
|
|
4576
|
+
* - If candidates is small, iterates candidates and checks ancestry (O(c))
|
|
4577
|
+
* - If descendants is small, iterates descendants and checks membership (O(d))
|
|
4578
|
+
*/
|
|
4579
|
+
static findDescendantIn<T extends Function>(parent: Function, candidates: Set<T> | Array<T>): T | undefined;
|
|
4580
|
+
/**
|
|
4581
|
+
* Returns the set of indexed ancestors for a constructor, or undefined if not indexed.
|
|
4582
|
+
*/
|
|
4583
|
+
static getAncestors(ctor: Function): Set<Function> | undefined;
|
|
4533
4584
|
/**
|
|
4534
4585
|
* Type guard to check if the param is allowed for scope allocation.
|
|
4535
4586
|
*
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1084,7 +1084,7 @@ declare class A_Entity<_ConstructorType extends A_TYPES__Entity_Init = A_TYPES__
|
|
|
1084
1084
|
* @param lifecycleMethod
|
|
1085
1085
|
* @param args
|
|
1086
1086
|
*/
|
|
1087
|
-
call(feature: string, scope?: A_Scope): any;
|
|
1087
|
+
call(feature: string, scope?: A_Scope): Promise<any> | void;
|
|
1088
1088
|
/**
|
|
1089
1089
|
* The default method that can be called and extended to load entity data.
|
|
1090
1090
|
*/
|
|
@@ -2010,9 +2010,11 @@ declare class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES_
|
|
|
2010
2010
|
*/
|
|
2011
2011
|
scope?: A_Scope): Promise<void> | void;
|
|
2012
2012
|
/**
|
|
2013
|
-
*
|
|
2013
|
+
* Async continuation — processes remaining stages after the first async pivot.
|
|
2014
|
+
* Resumes from the current iterator position (this._index).
|
|
2014
2015
|
*/
|
|
2015
|
-
private
|
|
2016
|
+
private processRemainingStagesAsync;
|
|
2017
|
+
private createStageError;
|
|
2016
2018
|
/**
|
|
2017
2019
|
* This method moves the feature to the next stage
|
|
2018
2020
|
*
|
|
@@ -2987,15 +2989,6 @@ type A_TYPES_ScopeDependentComponents = A_Component | A_Entity | A_Fragment | A_
|
|
|
2987
2989
|
type A_TYPES_ScopeIndependentComponents = A_Error | A_Scope | A_Caller;
|
|
2988
2990
|
|
|
2989
2991
|
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;
|
|
2999
2992
|
/**
|
|
3000
2993
|
* Scope Name uses for identification and logging purposes
|
|
3001
2994
|
*/
|
|
@@ -3024,6 +3017,11 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
|
|
|
3024
3017
|
* Invalidated by incrementing _version (cache is cleared on bump).
|
|
3025
3018
|
*/
|
|
3026
3019
|
protected _resolveConstructorCache: Map<string | Function, Function | null>;
|
|
3020
|
+
/**
|
|
3021
|
+
* Cached fingerprint string. Invalidated on every bumpVersion() call.
|
|
3022
|
+
*/
|
|
3023
|
+
private _cachedFingerprint;
|
|
3024
|
+
private _cachedFingerprintVersion;
|
|
3027
3025
|
/**
|
|
3028
3026
|
* A set of allowed components, A set of constructors that are allowed in the scope
|
|
3029
3027
|
*
|
|
@@ -3090,6 +3088,12 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
|
|
|
3090
3088
|
* allowing external caches to detect staleness via numeric comparison.
|
|
3091
3089
|
*/
|
|
3092
3090
|
get version(): number;
|
|
3091
|
+
/**
|
|
3092
|
+
* Returns a content-addressable fingerprint of the scope.
|
|
3093
|
+
* Two scopes with identical content (components, entities, fragments, errors, imports, parent)
|
|
3094
|
+
* will produce the same fingerprint. Dynamically recomputed when scope content changes.
|
|
3095
|
+
*/
|
|
3096
|
+
get fingerprint(): string;
|
|
3093
3097
|
/**
|
|
3094
3098
|
* Returns an Array of entities registered in the scope
|
|
3095
3099
|
*
|
|
@@ -3131,6 +3135,16 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
|
|
|
3131
3135
|
* Must be called on every scope mutation (register, deregister, import, deimport, inherit, destroy).
|
|
3132
3136
|
*/
|
|
3133
3137
|
protected bumpVersion(): void;
|
|
3138
|
+
/**
|
|
3139
|
+
* Computes the aggregate version of this scope and all reachable scopes (parent + imports).
|
|
3140
|
+
* Used to detect when any transitive dependency has changed, so the fingerprint cache can be invalidated.
|
|
3141
|
+
*/
|
|
3142
|
+
private aggregateVersion;
|
|
3143
|
+
/**
|
|
3144
|
+
* Computes a deterministic content-addressable fingerprint string.
|
|
3145
|
+
* Includes components, entities, fragments, errors, parent, and imports.
|
|
3146
|
+
*/
|
|
3147
|
+
private computeFingerprint;
|
|
3134
3148
|
/**
|
|
3135
3149
|
* 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.
|
|
3136
3150
|
* It refers to the visibility and accessibility of :
|
|
@@ -4209,12 +4223,22 @@ declare class A_Context {
|
|
|
4209
4223
|
* Key format: `${featureName}::${componentConstructorName}::${scopeVersion}::${metaVersion}`
|
|
4210
4224
|
* Automatically invalidated when scope version or meta version changes.
|
|
4211
4225
|
*/
|
|
4212
|
-
protected
|
|
4226
|
+
protected _featureCache: Map<string, Array<A_TYPES__A_StageStep>>;
|
|
4213
4227
|
/**
|
|
4214
4228
|
* Maximum number of entries in the featureExtensions cache.
|
|
4215
4229
|
* When exceeded, the entire cache is cleared to prevent unbounded growth.
|
|
4216
4230
|
*/
|
|
4217
4231
|
protected static readonly FEATURE_EXTENSIONS_CACHE_MAX_SIZE = 1024;
|
|
4232
|
+
/**
|
|
4233
|
+
* For each indexed constructor, stores the set of all its ancestor constructors
|
|
4234
|
+
* (walking up the prototype chain). Enables O(1) isInheritedFrom checks.
|
|
4235
|
+
*/
|
|
4236
|
+
protected _ancestors: Map<Function, Set<Function>>;
|
|
4237
|
+
/**
|
|
4238
|
+
* For each constructor, stores the set of all known descendant constructors.
|
|
4239
|
+
* Enables O(1) "find a descendant in a Set" lookups.
|
|
4240
|
+
*/
|
|
4241
|
+
protected _descendants: Map<Function, Set<Function>>;
|
|
4218
4242
|
protected _globals: Map<string, any>;
|
|
4219
4243
|
/**
|
|
4220
4244
|
* Private constructor to enforce singleton pattern.
|
|
@@ -4530,6 +4554,33 @@ declare class A_Context {
|
|
|
4530
4554
|
* Resets the Context to its initial state.
|
|
4531
4555
|
*/
|
|
4532
4556
|
static reset(): void;
|
|
4557
|
+
/**
|
|
4558
|
+
* Index a constructor's full prototype chain into the inheritance graph.
|
|
4559
|
+
* Safe to call multiple times for the same constructor — it's a no-op if already indexed.
|
|
4560
|
+
*
|
|
4561
|
+
* After indexing, `A_Context.isIndexedInheritedFrom(child, parent)` becomes O(1).
|
|
4562
|
+
*/
|
|
4563
|
+
static indexConstructor(ctor: Function): void;
|
|
4564
|
+
/**
|
|
4565
|
+
* O(1) check whether `child` inherits from `parent` using the pre-built index.
|
|
4566
|
+
* Falls back to prototype chain walking if either is not yet indexed.
|
|
4567
|
+
*
|
|
4568
|
+
* [!] Handles the same-class case: returns true if child === parent.
|
|
4569
|
+
*/
|
|
4570
|
+
static isIndexedInheritedFrom(child: Function, parent: Function): boolean;
|
|
4571
|
+
/**
|
|
4572
|
+
* Find the first constructor in `candidates` that is a descendant of (or equal to) `parent`.
|
|
4573
|
+
* Returns undefined if none found.
|
|
4574
|
+
*
|
|
4575
|
+
* Uses the optimal strategy based on set sizes:
|
|
4576
|
+
* - If candidates is small, iterates candidates and checks ancestry (O(c))
|
|
4577
|
+
* - If descendants is small, iterates descendants and checks membership (O(d))
|
|
4578
|
+
*/
|
|
4579
|
+
static findDescendantIn<T extends Function>(parent: Function, candidates: Set<T> | Array<T>): T | undefined;
|
|
4580
|
+
/**
|
|
4581
|
+
* Returns the set of indexed ancestors for a constructor, or undefined if not indexed.
|
|
4582
|
+
*/
|
|
4583
|
+
static getAncestors(ctor: Function): Set<Function> | undefined;
|
|
4533
4584
|
/**
|
|
4534
4585
|
* Type guard to check if the param is allowed for scope allocation.
|
|
4535
4586
|
*
|