@memberjunction/global 2.63.0 → 2.64.0

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.
@@ -11,6 +11,7 @@
11
11
  export declare class ClassRegistration {
12
12
  BaseClass: any;
13
13
  SubClass: any;
14
+ RootClass: any;
14
15
  Key: string;
15
16
  Priority: number;
16
17
  }
@@ -27,10 +28,12 @@ export declare class ClassFactory {
27
28
  * @param key A key can be used to differentiate registrations for the same base class/sub-class combination. For example, in the case of BaseEntity and Entity object subclasses we'll have a LOT of entries and we want to get the highest priority registered sub-class for a specific key. In that case, the key is the entity name, but the key can be any value you want to use to differentiate registrations.
28
29
  * @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used. Finally, if you do NOT provide this setting, the order of registrations will increment the priority automatically so dependency injection will typically care care of this. That is, in order for Class B, a subclass of Class A, to be registered properly, Class A code has to already have been loaded and therefore Class A's RegisterClass decorator was run. In that scenario, if neither Class A or B has a priority setting, Class A would be 1 and Class B would be 2 automatically. For this reason, you only need to explicitly set priority if you want to do something atypical as this mechanism normally will solve for setting the priority correctly based on the furthest descendant class that is registered.
29
30
  * @param skipNullKeyWarning If true, will not print a warning if the key is null or undefined. This is useful for cases where you know that the key is not needed and you don't want to see the warning in the console.
31
+ * @param autoRegisterWithRootClass If true (default), will automatically register the subclass with the root class of the baseClass hierarchy. This ensures proper priority ordering when multiple subclasses are registered in a hierarchy.
30
32
  */
31
- Register(baseClass: any, subClass: any, key?: string, priority?: number, skipNullKeyWarning?: boolean): void;
33
+ Register(baseClass: any, subClass: any, key?: string, priority?: number, skipNullKeyWarning?: boolean, autoRegisterWithRootClass?: boolean): void;
32
34
  /**
33
- * Creates an instance of the class registered for the given base class and key. If no registration is found, will return an instance of the base class.
35
+ * Creates an instance of the class registered for the given base class and key.
36
+ * If no registration is found, will return an instance of the base class.
34
37
  */
35
38
  CreateInstance<T>(baseClass: any, key?: string, ...params: any[]): T | null;
36
39
  /**
@@ -44,5 +47,13 @@ export declare class ClassFactory {
44
47
  * Returns the registration with the highest priority for a given base class and key. If key is not provided, will return the registration with the highest priority for the base class.
45
48
  */
46
49
  GetRegistration(baseClass: any, key?: string): ClassRegistration;
50
+ /**
51
+ * Returns all registrations that have the specified root class, regardless of what base class was used in the registration.
52
+ * This is useful for finding all registrations in a class hierarchy.
53
+ * @param rootClass The root class to search for
54
+ * @param key Optional key to filter results
55
+ * @returns Array of matching registrations
56
+ */
57
+ GetRegistrationsByRootClass(rootClass: any, key?: string): ClassRegistration[];
47
58
  }
48
59
  //# sourceMappingURL=ClassFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClassFactory.d.ts","sourceRoot":"","sources":["../src/ClassFactory.ts"],"names":[],"mappings":"AAAA;;;;;;wGAMwG;AAExG;;GAEG;AACH,qBAAa,iBAAiB;IAC1B,SAAS,EAAE,GAAG,CAAA;IACd,QAAQ,EAAE,GAAG,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IAEX,QAAQ,EAAE,MAAM,CAAA;CACnB;AAGD;;;GAGG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,cAAc,CAA2B;IAEjD;;;;;;;OAOG;IACI,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,GAAE,MAAa,EAAE,QAAQ,GAAE,MAAU,EAAE,kBAAkB,GAAE,OAAe,GAAG,IAAI;IAuCnI;;OAEG;IACI,cAAc,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,GAAE,MAAa,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI;IAqBxF;;;;;OAKG;IACI,mBAAmB,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,GAAE,MAAkB,GAAG,iBAAiB,EAAE;IAWxF;;OAEG;IACI,eAAe,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,GAAE,MAAkB,GAAG,iBAAiB;CAmBrF"}
1
+ {"version":3,"file":"ClassFactory.d.ts","sourceRoot":"","sources":["../src/ClassFactory.ts"],"names":[],"mappings":"AAAA;;;;;;wGAMwG;AAIxG;;GAEG;AACH,qBAAa,iBAAiB;IAC1B,SAAS,EAAE,GAAG,CAAA;IACd,QAAQ,EAAE,GAAG,CAAA;IACb,SAAS,EAAE,GAAG,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IAEX,QAAQ,EAAE,MAAM,CAAA;CACnB;AAGD;;;GAGG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,cAAc,CAA2B;IAEjD;;;;;;;;OAQG;IACI,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,GAAE,MAAa,EAAE,QAAQ,GAAE,MAAU,EAAE,kBAAkB,GAAE,OAAe,EAAE,yBAAyB,GAAE,OAAc,GAAG,IAAI;IAmD9K;;;OAGG;IACI,cAAc,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,GAAE,MAAa,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI;IAqBxF;;;;;OAKG;IACI,mBAAmB,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,GAAE,MAAkB,GAAG,iBAAiB,EAAE;IAWxF;;OAEG;IACI,eAAe,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,GAAE,MAAkB,GAAG,iBAAiB;IAoBlF;;;;;;OAMG;IACI,2BAA2B,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,GAAE,MAAkB,GAAG,iBAAiB,EAAE;CASnG"}
@@ -8,6 +8,7 @@
8
8
  ******************************************************************************************************/
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.ClassFactory = exports.ClassRegistration = void 0;
11
+ const ClassUtils_1 = require("./ClassUtils");
11
12
  /**
12
13
  * Data structure to track the class registrations
13
14
  */
@@ -29,19 +30,28 @@ class ClassFactory {
29
30
  * @param key A key can be used to differentiate registrations for the same base class/sub-class combination. For example, in the case of BaseEntity and Entity object subclasses we'll have a LOT of entries and we want to get the highest priority registered sub-class for a specific key. In that case, the key is the entity name, but the key can be any value you want to use to differentiate registrations.
30
31
  * @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used. Finally, if you do NOT provide this setting, the order of registrations will increment the priority automatically so dependency injection will typically care care of this. That is, in order for Class B, a subclass of Class A, to be registered properly, Class A code has to already have been loaded and therefore Class A's RegisterClass decorator was run. In that scenario, if neither Class A or B has a priority setting, Class A would be 1 and Class B would be 2 automatically. For this reason, you only need to explicitly set priority if you want to do something atypical as this mechanism normally will solve for setting the priority correctly based on the furthest descendant class that is registered.
31
32
  * @param skipNullKeyWarning If true, will not print a warning if the key is null or undefined. This is useful for cases where you know that the key is not needed and you don't want to see the warning in the console.
33
+ * @param autoRegisterWithRootClass If true (default), will automatically register the subclass with the root class of the baseClass hierarchy. This ensures proper priority ordering when multiple subclasses are registered in a hierarchy.
32
34
  */
33
- Register(baseClass, subClass, key = null, priority = 0, skipNullKeyWarning = false) {
35
+ Register(baseClass, subClass, key = null, priority = 0, skipNullKeyWarning = false, autoRegisterWithRootClass = true) {
34
36
  if (baseClass && subClass) {
35
37
  if (key === undefined || key === null && !skipNullKeyWarning) {
36
38
  console.warn(`ClassFactory.GetAllRegistrations: Registration for base class ${baseClass.name} has no key set. This is not recommended and may lead to unintended behavior when trying to match registrations. Please set a key for this registration.`);
37
39
  }
38
- // get all of hte existing registrations for this baseClass and key
39
- const registrations = this.GetAllRegistrations(baseClass, key);
40
+ // Get the root class for this registration
41
+ const rootClass = (0, ClassUtils_1.GetRootClass)(baseClass);
42
+ // Determine which class to actually register against
43
+ const effectiveBaseClass = autoRegisterWithRootClass ? rootClass : baseClass;
44
+ // Log if we're auto-registering with root class
45
+ if (autoRegisterWithRootClass && effectiveBaseClass !== baseClass) {
46
+ console.info(`ClassFactory.Register: Auto-registering ${subClass.name} with root class ${rootClass.name} instead of ${baseClass.name}`);
47
+ }
48
+ // get all of the existing registrations for the effective base class and key
49
+ const registrations = this.GetAllRegistrations(effectiveBaseClass, key);
40
50
  if (priority > 0) {
41
- // validate to make sure that the comabination of base class and key for the provided priority # is not already registered, if it is, then print a warning
51
+ // validate to make sure that the combination of base class and key for the provided priority # is not already registered, if it is, then print a warning
42
52
  const existing = registrations.filter(r => r.Priority === priority);
43
53
  if (existing && existing.length > 0) {
44
- console.warn(`*** ClassFactory.Register: Registering class ${subClass.name} for base class ${baseClass.name} and key/priority ${key}/${priority}. ${existing.length} registrations already exist for that combination. While this is allowed it is not desired and when matching class requests occur, we will simply use the LAST registration we happen to have which can lead to unintended behavior. ***`);
54
+ console.warn(`*** ClassFactory.Register: Registering class ${subClass.name} for base class ${effectiveBaseClass.name} and key/priority ${key}/${priority}. ${existing.length} registrations already exist for that combination. While this is allowed it is not desired and when matching class requests occur, we will simply use the LAST registration we happen to have which can lead to unintended behavior. ***`);
45
55
  }
46
56
  }
47
57
  else if (priority === 0 || priority === null || priority === undefined) {
@@ -57,15 +67,17 @@ class ClassFactory {
57
67
  }
58
68
  // this combination of baseclass/key/priority is NOT already registered.
59
69
  let reg = new ClassRegistration();
60
- reg.BaseClass = baseClass;
70
+ reg.BaseClass = effectiveBaseClass;
61
71
  reg.SubClass = subClass;
72
+ reg.RootClass = rootClass;
62
73
  reg.Key = key;
63
74
  reg.Priority = priority;
64
75
  this._registrations.push(reg);
65
76
  }
66
77
  }
67
78
  /**
68
- * Creates an instance of the class registered for the given base class and key. If no registration is found, will return an instance of the base class.
79
+ * Creates an instance of the class registered for the given base class and key.
80
+ * If no registration is found, will return an instance of the base class.
69
81
  */
70
82
  CreateInstance(baseClass, key = null, ...params) {
71
83
  if (baseClass) {
@@ -120,6 +132,22 @@ class ClassFactory {
120
132
  }
121
133
  return null;
122
134
  }
135
+ /**
136
+ * Returns all registrations that have the specified root class, regardless of what base class was used in the registration.
137
+ * This is useful for finding all registrations in a class hierarchy.
138
+ * @param rootClass The root class to search for
139
+ * @param key Optional key to filter results
140
+ * @returns Array of matching registrations
141
+ */
142
+ GetRegistrationsByRootClass(rootClass, key = undefined) {
143
+ if (rootClass) {
144
+ return this._registrations.filter(r => {
145
+ return r.RootClass?.name === rootClass.name &&
146
+ (key === undefined || key === null ? true : r.Key?.trim().toLowerCase() === key.trim().toLowerCase());
147
+ });
148
+ }
149
+ return [];
150
+ }
123
151
  }
124
152
  exports.ClassFactory = ClassFactory;
125
153
  //# sourceMappingURL=ClassFactory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClassFactory.js","sourceRoot":"","sources":["../src/ClassFactory.ts"],"names":[],"mappings":";AAAA;;;;;;wGAMwG;;;AAExG;;GAEG;AACH,MAAa,iBAAiB;CAM7B;AAND,8CAMC;AAGD;;;GAGG;AACH,MAAa,YAAY;IAAzB;QACY,mBAAc,GAAwB,EAAE,CAAC;IAgHrD,CAAC;IA9GG;;;;;;;OAOG;IACI,QAAQ,CAAC,SAAc,EAAE,QAAa,EAAE,MAAc,IAAI,EAAE,WAAmB,CAAC,EAAE,qBAA8B,KAAK;QACxH,IAAI,SAAS,IAAI,QAAQ,EAAE,CAAC;YACxB,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBAC3D,OAAO,CAAC,IAAI,CAAC,iEAAiE,SAAS,CAAC,IAAI,0JAA0J,CAAC,CAAA;YAC3P,CAAC;YAED,mEAAmE;YACnE,MAAM,aAAa,GAAG,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;YAE/D,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;gBACf,0JAA0J;gBAC1J,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,C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AAE,CAAC;YACZ,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;gBAClC,OAAO,CAAC,CAAC,SAAS,EAAE,IAAI,KAAK,SAAS,CAAC,IAAI;oBACpC,CAAC,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA;YAChH,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AAhJD,oCAgJC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Utility functions for working with class hierarchies and reflection
3
+ */
4
+ export interface ClassInfo {
5
+ /**
6
+ * The name of the class
7
+ */
8
+ name: string;
9
+ /**
10
+ * Reference to the class constructor
11
+ */
12
+ reference: any;
13
+ }
14
+ /**
15
+ * Gets the immediate superclass of the given class
16
+ * @param ClassRef The class constructor reference
17
+ * @returns The superclass constructor or null if no superclass
18
+ */
19
+ export declare function GetSuperclass(ClassRef: any): any | null;
20
+ /**
21
+ * Gets the root class in the inheritance chain (the topmost user-defined class)
22
+ * @param ClassRef The class constructor reference
23
+ * @returns The root class constructor
24
+ */
25
+ export declare function GetRootClass(ClassRef: any): any;
26
+ /**
27
+ * Checks if a class is a subclass of another class (at any level in the inheritance hierarchy)
28
+ * Note: This checks the entire inheritance chain, not just the immediate parent
29
+ * @param PotentialSubclass The potential subclass constructor
30
+ * @param PotentialAncestor The potential ancestor class constructor
31
+ * @returns True if PotentialSubclass inherits from PotentialAncestor at any level
32
+ */
33
+ export declare function IsSubclassOf(PotentialSubclass: any, PotentialAncestor: any): boolean;
34
+ /**
35
+ * Checks if a class is a root class (has no user-defined superclass)
36
+ * @param ClassRef The class constructor reference
37
+ * @returns True if the class has no superclass
38
+ */
39
+ export declare function IsRootClass(ClassRef: any): boolean;
40
+ /**
41
+ * Checks if a class is a descendant of another class (at any level in the hierarchy)
42
+ * This is an alias for IsSubclassOf with a more descriptive name
43
+ * @param PotentialDescendant The potential descendant class constructor
44
+ * @param PotentialAncestor The potential ancestor class constructor
45
+ * @returns True if PotentialDescendant inherits from PotentialAncestor at any level
46
+ */
47
+ export declare function IsDescendantClassOf(PotentialDescendant: any, PotentialAncestor: any): boolean;
48
+ /**
49
+ * Gets the complete inheritance chain for a class
50
+ * @param ClassRef The class constructor reference
51
+ * @returns Array of ClassInfo objects, ordered from immediate superclass to root
52
+ */
53
+ export declare function GetClassInheritance(ClassRef: any): ClassInfo[];
54
+ /**
55
+ * Gets the complete class hierarchy including the class itself
56
+ * @param ClassRef The class constructor reference
57
+ * @returns Array of ClassInfo objects, ordered from the class itself up to root
58
+ */
59
+ export declare function GetFullClassHierarchy(ClassRef: any): ClassInfo[];
60
+ /**
61
+ * Checks if a value is a class constructor (not an instance)
62
+ * @param value The value to check
63
+ * @returns True if the value is a class constructor
64
+ */
65
+ export declare function IsClassConstructor(value: any): boolean;
66
+ /**
67
+ * Gets the class name safely, handling minification and anonymous classes
68
+ * @param ClassRef The class constructor reference
69
+ * @returns The class name or a fallback string
70
+ */
71
+ export declare function GetClassName(ClassRef: any): string;
72
+ //# sourceMappingURL=ClassUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassUtils.d.ts","sourceRoot":"","sources":["../src/ClassUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,SAAS;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,SAAS,EAAE,GAAG,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI,CAavD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,CAqB/C;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CA6BpF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAWlD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,mBAAmB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAE7F;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,GAAG,GAAG,SAAS,EAAE,CAwB9D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,GAAG,GAAG,SAAS,EAAE,CAwBhE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAqBtD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,GAAG,GAAG,MAAM,CAkBlD"}
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ /**
3
+ * Utility functions for working with class hierarchies and reflection
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GetClassName = exports.IsClassConstructor = exports.GetFullClassHierarchy = exports.GetClassInheritance = exports.IsDescendantClassOf = exports.IsRootClass = exports.IsSubclassOf = exports.GetRootClass = exports.GetSuperclass = void 0;
7
+ /**
8
+ * Gets the immediate superclass of the given class
9
+ * @param ClassRef The class constructor reference
10
+ * @returns The superclass constructor or null if no superclass
11
+ */
12
+ function GetSuperclass(ClassRef) {
13
+ if (!ClassRef || typeof ClassRef !== 'function') {
14
+ return null;
15
+ }
16
+ const superclass = Object.getPrototypeOf(ClassRef);
17
+ // Check if we've reached the top of the chain
18
+ if (!superclass || superclass === Function.prototype || superclass.constructor === Function) {
19
+ return null;
20
+ }
21
+ return superclass;
22
+ }
23
+ exports.GetSuperclass = GetSuperclass;
24
+ /**
25
+ * Gets the root class in the inheritance chain (the topmost user-defined class)
26
+ * @param ClassRef The class constructor reference
27
+ * @returns The root class constructor
28
+ */
29
+ function GetRootClass(ClassRef) {
30
+ if (!ClassRef || typeof ClassRef !== 'function') {
31
+ return ClassRef;
32
+ }
33
+ let current = ClassRef;
34
+ let previous = ClassRef;
35
+ while (current) {
36
+ const superclass = Object.getPrototypeOf(current);
37
+ // Stop when we reach built-in prototypes
38
+ if (!superclass || superclass === Function.prototype || superclass.constructor === Function) {
39
+ break;
40
+ }
41
+ previous = current;
42
+ current = superclass;
43
+ }
44
+ return previous;
45
+ }
46
+ exports.GetRootClass = GetRootClass;
47
+ /**
48
+ * Checks if a class is a subclass of another class (at any level in the inheritance hierarchy)
49
+ * Note: This checks the entire inheritance chain, not just the immediate parent
50
+ * @param PotentialSubclass The potential subclass constructor
51
+ * @param PotentialAncestor The potential ancestor class constructor
52
+ * @returns True if PotentialSubclass inherits from PotentialAncestor at any level
53
+ */
54
+ function IsSubclassOf(PotentialSubclass, PotentialAncestor) {
55
+ if (!PotentialSubclass || !PotentialAncestor ||
56
+ typeof PotentialSubclass !== 'function' ||
57
+ typeof PotentialAncestor !== 'function') {
58
+ return false;
59
+ }
60
+ // Check if they're the same class
61
+ if (PotentialSubclass === PotentialAncestor) {
62
+ return false; // A class is not a subclass of itself
63
+ }
64
+ // Walk up the prototype chain
65
+ let current = PotentialSubclass;
66
+ while (current) {
67
+ current = Object.getPrototypeOf(current);
68
+ if (current === PotentialAncestor) {
69
+ return true;
70
+ }
71
+ // Stop when we reach built-in prototypes
72
+ if (!current || current === Function.prototype || current.constructor === Function) {
73
+ break;
74
+ }
75
+ }
76
+ return false;
77
+ }
78
+ exports.IsSubclassOf = IsSubclassOf;
79
+ /**
80
+ * Checks if a class is a root class (has no user-defined superclass)
81
+ * @param ClassRef The class constructor reference
82
+ * @returns True if the class has no superclass
83
+ */
84
+ function IsRootClass(ClassRef) {
85
+ if (!ClassRef || typeof ClassRef !== 'function') {
86
+ return false;
87
+ }
88
+ const superclass = Object.getPrototypeOf(ClassRef);
89
+ // It's a root class if it has no superclass or only inherits from built-in prototypes
90
+ return !superclass ||
91
+ superclass === Function.prototype ||
92
+ superclass.constructor === Function;
93
+ }
94
+ exports.IsRootClass = IsRootClass;
95
+ /**
96
+ * Checks if a class is a descendant of another class (at any level in the hierarchy)
97
+ * This is an alias for IsSubclassOf with a more descriptive name
98
+ * @param PotentialDescendant The potential descendant class constructor
99
+ * @param PotentialAncestor The potential ancestor class constructor
100
+ * @returns True if PotentialDescendant inherits from PotentialAncestor at any level
101
+ */
102
+ function IsDescendantClassOf(PotentialDescendant, PotentialAncestor) {
103
+ return IsSubclassOf(PotentialDescendant, PotentialAncestor);
104
+ }
105
+ exports.IsDescendantClassOf = IsDescendantClassOf;
106
+ /**
107
+ * Gets the complete inheritance chain for a class
108
+ * @param ClassRef The class constructor reference
109
+ * @returns Array of ClassInfo objects, ordered from immediate superclass to root
110
+ */
111
+ function GetClassInheritance(ClassRef) {
112
+ const chain = [];
113
+ if (!ClassRef || typeof ClassRef !== 'function') {
114
+ return chain;
115
+ }
116
+ let current = Object.getPrototypeOf(ClassRef);
117
+ while (current) {
118
+ // Stop when we reach built-in prototypes
119
+ if (current === Function.prototype || current.constructor === Function) {
120
+ break;
121
+ }
122
+ chain.push({
123
+ name: current.name || 'Anonymous',
124
+ reference: current
125
+ });
126
+ current = Object.getPrototypeOf(current);
127
+ }
128
+ return chain;
129
+ }
130
+ exports.GetClassInheritance = GetClassInheritance;
131
+ /**
132
+ * Gets the complete class hierarchy including the class itself
133
+ * @param ClassRef The class constructor reference
134
+ * @returns Array of ClassInfo objects, ordered from the class itself up to root
135
+ */
136
+ function GetFullClassHierarchy(ClassRef) {
137
+ const chain = [];
138
+ if (!ClassRef || typeof ClassRef !== 'function') {
139
+ return chain;
140
+ }
141
+ let current = ClassRef;
142
+ while (current) {
143
+ // Stop when we reach built-in prototypes
144
+ if (current === Function.prototype || current.constructor === Function) {
145
+ break;
146
+ }
147
+ chain.push({
148
+ name: current.name || 'Anonymous',
149
+ reference: current
150
+ });
151
+ current = Object.getPrototypeOf(current);
152
+ }
153
+ return chain;
154
+ }
155
+ exports.GetFullClassHierarchy = GetFullClassHierarchy;
156
+ /**
157
+ * Checks if a value is a class constructor (not an instance)
158
+ * @param value The value to check
159
+ * @returns True if the value is a class constructor
160
+ */
161
+ function IsClassConstructor(value) {
162
+ if (typeof value !== 'function') {
163
+ return false;
164
+ }
165
+ // Check if it's a class by looking at its string representation
166
+ const fnString = value.toString();
167
+ // ES6 classes start with "class"
168
+ if (fnString.startsWith('class ')) {
169
+ return true;
170
+ }
171
+ // Check for constructor functions that might be transpiled classes
172
+ // They typically have a prototype with a constructor property
173
+ if (value.prototype && value.prototype.constructor === value) {
174
+ // Additional check: does it look like it's meant to be instantiated?
175
+ return fnString.includes('this.') || Object.getOwnPropertyNames(value.prototype).length > 1;
176
+ }
177
+ return false;
178
+ }
179
+ exports.IsClassConstructor = IsClassConstructor;
180
+ /**
181
+ * Gets the class name safely, handling minification and anonymous classes
182
+ * @param ClassRef The class constructor reference
183
+ * @returns The class name or a fallback string
184
+ */
185
+ function GetClassName(ClassRef) {
186
+ if (!ClassRef || typeof ClassRef !== 'function') {
187
+ return 'Unknown';
188
+ }
189
+ // Try to get the name property
190
+ if (ClassRef.name) {
191
+ return ClassRef.name;
192
+ }
193
+ // Try to extract from toString() as fallback
194
+ const fnString = ClassRef.toString();
195
+ const match = fnString.match(/^class\s+(\w+)/);
196
+ if (match && match[1]) {
197
+ return match[1];
198
+ }
199
+ return 'Anonymous';
200
+ }
201
+ exports.GetClassName = GetClassName;
202
+ //# sourceMappingURL=ClassUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassUtils.js","sourceRoot":"","sources":["../src/ClassUtils.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAaH;;;;GAIG;AACH,SAAgB,aAAa,CAAC,QAAa;IACvC,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK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E,CAAC;IAElC,iCAAiC;IACjC,IAAI,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,mEAAmE;IACnE,8DAA8D;IAC9D,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;QAC3D,qEAAqE;QACrE,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAChG,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AArBD,gDAqBC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,QAAa;IACtC,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC9C,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,+BAA+B;IAC/B,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,QAAQ,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,6CAA6C;IAC7C,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC/C,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC;AAlBD,oCAkBC"}
@@ -0,0 +1,51 @@
1
+ import * as MJ from './interface';
2
+ import { Observable } from 'rxjs';
3
+ import { ClassFactory } from './ClassFactory';
4
+ import { ObjectCache } from './ObjectCache';
5
+ import { BaseSingleton } from './BaseSingleton';
6
+ /**
7
+ * Global class used for coordinating events, creating class instances, and managing components across MemberJunction
8
+ */
9
+ export declare class MJGlobal extends BaseSingleton<MJGlobal> {
10
+ private _eventsSubject;
11
+ private _eventsReplaySubject;
12
+ private _events$;
13
+ private _eventsReplay$;
14
+ private _components;
15
+ private _classFactory;
16
+ private _properties;
17
+ /**
18
+ * Returns the global instance of the MJGlobal class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of MJGlobal, always use this method to get the instance.
19
+ */
20
+ static get Instance(): MJGlobal;
21
+ RegisterComponent(component: MJ.IMJComponent): void;
22
+ /**
23
+ * Resets the class to its initial state. Use very carefully and sparingly.
24
+ */
25
+ Reset(): void;
26
+ /**
27
+ * Use this method to raise an event to all component who are listening for the event.
28
+ * @param event
29
+ */
30
+ RaiseEvent(event: MJ.MJEvent): void;
31
+ /**
32
+ * Use this method to get an observable that will fire when an event is raised.
33
+ * @param withReplay
34
+ * @returns
35
+ */
36
+ GetEventListener(withReplay?: boolean): Observable<MJ.MJEvent>;
37
+ /**
38
+ * Returns the instance of ClassFactory you should use in your application. Access this via the MJGlobal.Instance.ClassFactory property.
39
+ */
40
+ get ClassFactory(): ClassFactory;
41
+ /**
42
+ * Global property bag
43
+ */
44
+ get Properties(): MJ.MJGlobalProperty[];
45
+ private _objectCache;
46
+ /**
47
+ * ObjectCache can be used to cache objects as needed by any application in memory. These objects are NOT persisted to disk or any other storage medium, so they are only good for the lifetime of the application
48
+ */
49
+ get ObjectCache(): ObjectCache;
50
+ }
51
+ //# sourceMappingURL=Global.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Global.d.ts","sourceRoot":"","sources":["../src/Global.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAA0B,UAAU,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,qBAAa,QAAS,SAAQ,aAAa,CAAC,QAAQ,CAAC;IAEjD,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,oBAAoB,CAAkD;IAG9E,OAAO,CAAC,QAAQ,CAA8D;IAC9E,OAAO,CAAC,cAAc,CAAoE;IAE1F,OAAO,CAAC,WAAW,CAAyB;IAE5C,OAAO,CAAC,aAAa,CAAoC;IAEzD,OAAO,CAAC,WAAW,CAA6B;IAEhD;;OAEG;IACH,WAAkB,QAAQ,IAAI,QAAQ,CAErC;IAEM,iBAAiB,CAAC,SAAS,EAAE,EAAE,CAAC,YAAY;IAInD;;OAEG;IACI,KAAK;IAWZ;;;OAGG;IACI,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO;IAKnC;;;;OAIG;IACI,gBAAgB,CAAC,UAAU,GAAE,OAAe,GAAG,UAAU,CAAC,EAAE,CAAC,OAAO,CAAC;IAI5E;;OAEG;IACH,IAAW,YAAY,IAAI,YAAY,CAEtC;IAED;;OAEG;IACH,IAAW,UAAU,IAAI,EAAE,CAAC,gBAAgB,EAAE,CAE7C;IAGD,OAAO,CAAC,YAAY,CAAkC;IACtD;;OAEG;IACH,IAAW,WAAW,IAAI,WAAW,CAEpC;CACJ"}
package/dist/Global.js ADDED
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MJGlobal = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const ClassFactory_1 = require("./ClassFactory");
6
+ const ObjectCache_1 = require("./ObjectCache");
7
+ const BaseSingleton_1 = require("./BaseSingleton");
8
+ /**
9
+ * Global class used for coordinating events, creating class instances, and managing components across MemberJunction
10
+ */
11
+ class MJGlobal extends BaseSingleton_1.BaseSingleton {
12
+ constructor() {
13
+ super(...arguments);
14
+ // subjects for observables to handle eventing
15
+ this._eventsSubject = new rxjs_1.Subject();
16
+ this._eventsReplaySubject = new rxjs_1.ReplaySubject();
17
+ // Convert the Subjects to Observables for public use.
18
+ this._events$ = this._eventsSubject.asObservable();
19
+ this._eventsReplay$ = this._eventsReplaySubject.asObservable();
20
+ this._components = [];
21
+ this._classFactory = new ClassFactory_1.ClassFactory();
22
+ this._properties = [];
23
+ this._objectCache = new ObjectCache_1.ObjectCache();
24
+ }
25
+ /**
26
+ * Returns the global instance of the MJGlobal class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of MJGlobal, always use this method to get the instance.
27
+ */
28
+ static get Instance() {
29
+ return super.getInstance();
30
+ }
31
+ RegisterComponent(component) {
32
+ this._components.push(component);
33
+ }
34
+ /**
35
+ * Resets the class to its initial state. Use very carefully and sparingly.
36
+ */
37
+ Reset() {
38
+ this._components = [];
39
+ this._eventsSubject = new rxjs_1.Subject();
40
+ this._eventsReplaySubject = new rxjs_1.ReplaySubject();
41
+ // Convert the Subjects to Observables for public use.
42
+ this._events$ = this._eventsSubject.asObservable();
43
+ this._eventsReplay$ = this._eventsReplaySubject.asObservable();
44
+ }
45
+ /**
46
+ * Use this method to raise an event to all component who are listening for the event.
47
+ * @param event
48
+ */
49
+ RaiseEvent(event) {
50
+ this._eventsSubject.next(event);
51
+ this._eventsReplaySubject.next(event);
52
+ }
53
+ /**
54
+ * Use this method to get an observable that will fire when an event is raised.
55
+ * @param withReplay
56
+ * @returns
57
+ */
58
+ GetEventListener(withReplay = false) {
59
+ return withReplay ? this._eventsReplay$ : this._events$;
60
+ }
61
+ /**
62
+ * Returns the instance of ClassFactory you should use in your application. Access this via the MJGlobal.Instance.ClassFactory property.
63
+ */
64
+ get ClassFactory() {
65
+ return this._classFactory;
66
+ }
67
+ /**
68
+ * Global property bag
69
+ */
70
+ get Properties() {
71
+ return this._properties;
72
+ }
73
+ /**
74
+ * ObjectCache can be used to cache objects as needed by any application in memory. These objects are NOT persisted to disk or any other storage medium, so they are only good for the lifetime of the application
75
+ */
76
+ get ObjectCache() {
77
+ return this._objectCache;
78
+ }
79
+ }
80
+ exports.MJGlobal = M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KAAiB;QAC/B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAC,aAAsB,KAAK;QAC/C,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAID;;OAEG;IACH,IAAW,WAAW;QAClB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ;AAhFD,4BAgFC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Decorate your class with this to register it with the MJGlobal class factory.
3
+ * @param baseClass
4
+ * @param key a string that is later used to retrieve a given registration - this should be unique for each baseClass/key combination, if multiple registrations exist for a given baseClass/key combination, the highest priority registration will be used to create class instances
5
+ * @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used. Finally, if you do NOT provide this setting, the order of registrations will increment the priority automatically so dependency injection will typically care care of this. That is, in order for Class B, a subclass of Class A, to be registered properly, Class A code has to already have been loaded and therefore Class A's RegisterClass decorator was run. In that scenario, if neither Class A or B has a priority setting, Class A would be 1 and Class B would be 2 automatically. For this reason, you only need to explicitly set priority if you want to do something atypical as this mechanism normally will solve for setting the priority correctly based on the furthest descendant class that is registered.
6
+ * @param skipNullKeyWarning If true, will not print a warning if the key is null or undefined. This is useful for cases where you know that the key is not needed and you don't want to see the warning in the console.
7
+ * @param autoRegisterWithRootClass If true (default), will automatically register the subclass with the root class of the baseClass hierarchy. This ensures proper priority ordering when multiple subclasses are registered in a hierarchy.
8
+ * @returns an instance of the class that was registered for the combination of baseClass/key (with highest priority if more than one)
9
+ */
10
+ export declare function RegisterClass(baseClass: any, key?: string, priority?: number, skipNullKeyWarning?: boolean, autoRegisterWithRootClass?: boolean): (constructor: Function) => void;
11
+ //# sourceMappingURL=RegisterClass.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegisterClass.d.ts","sourceRoot":"","sources":["../src/RegisterClass.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,GAAE,MAAa,EAAE,QAAQ,GAAE,MAAU,EAAE,kBAAkB,GAAE,OAAe,EAAE,yBAAyB,GAAE,OAAc,GAAG,CAAC,WAAW,EAAE,QAAQ,KAAK,IAAI,CAKvM"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegisterClass = void 0;
4
+ const Global_1 = require("./Global");
5
+ /**
6
+ * Decorate your class with this to register it with the MJGlobal class factory.
7
+ * @param baseClass
8
+ * @param key a string that is later used to retrieve a given registration - this should be unique for each baseClass/key combination, if multiple registrations exist for a given baseClass/key combination, the highest priority registration will be used to create class instances
9
+ * @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used. Finally, if you do NOT provide this setting, the order of registrations will increment the priority automatically so dependency injection will typically care care of this. That is, in order for Class B, a subclass of Class A, to be registered properly, Class A code has to already have been loaded and therefore Class A's RegisterClass decorator was run. In that scenario, if neither Class A or B has a priority setting, Class A would be 1 and Class B would be 2 automatically. For this reason, you only need to explicitly set priority if you want to do something atypical as this mechanism normally will solve for setting the priority correctly based on the furthest descendant class that is registered.
10
+ * @param skipNullKeyWarning If true, will not print a warning if the key is null or undefined. This is useful for cases where you know that the key is not needed and you don't want to see the warning in the console.
11
+ * @param autoRegisterWithRootClass If true (default), will automatically register the subclass with the root class of the baseClass hierarchy. This ensures proper priority ordering when multiple subclasses are registered in a hierarchy.
12
+ * @returns an instance of the class that was registered for the combination of baseClass/key (with highest priority if more than one)
13
+ */
14
+ function RegisterClass(baseClass, key = null, priority = 0, skipNullKeyWarning = false, autoRegisterWithRootClass = true) {
15
+ return function (constructor) {
16
+ // Invoke the registration method
17
+ Global_1.MJGlobal.Instance.ClassFactory.Register(baseClass, constructor, key, priority, skipNullKeyWarning, autoRegisterWithRootClass);
18
+ };
19
+ }
20
+ exports.RegisterClass = RegisterClass;
21
+ //# sourceMappingURL=RegisterClass.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegisterClass.js","sourceRoot":"","sources":["../src/RegisterClass.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,SAAc,EAAE,MAAc,IAAI,EAAE,WAAmB,CAAC,EAAE,qBAA8B,KAAK,EAAE,4BAAqC,IAAI;IAClK,OAAO,UAAU,WAAqB;QAClC,iCAAiC;QACjC,iBAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,kBAAkB,EAAE,yBAAyB,CAAC,CAAC;IAClI,CAAC,CAAA;AACL,CAAC;AALD,sCAKC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ClassUtils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassUtils.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/ClassUtils.test.ts"],"names":[],"mappings":""}