@memberjunction/core
Advanced tools
Comparing version 2.18.2 to 2.18.3
import { BaseSingleton, MJEvent } from "@memberjunction/global"; | ||
import { BehaviorSubject } from "rxjs"; | ||
import { UserInfo } from "./securityInfo"; | ||
import { DatasetItemFilterType, RunViewResult } from "./interfaces"; | ||
import { DatasetItemFilterType, IMetadataProvider, IRunViewProvider, RunViewResult } from "./interfaces"; | ||
import { BaseInfo } from "./baseInfo"; | ||
@@ -76,3 +76,17 @@ import { BaseEntityEvent } from "./baseEntity"; | ||
private _entityEventSubjects; | ||
private _provider; | ||
/** | ||
* While the BaseEngine class is a singleton, normally, it is possible to have multiple instances of the class in an application if the class is used in multiple contexts that have different providers. | ||
*/ | ||
constructor(); | ||
/** | ||
* Returns the metadata provider to use for the engine. If a provider is set via the Config method, that provider will be used, otherwise the default provider will be used. | ||
*/ | ||
get ProviderToUse(): IMetadataProvider; | ||
/** | ||
* Returns the RunView provider to use for the engine. This is the same underlying object as the @property ProviderTouse, but cast to IRunViewProvider. | ||
* If a provider is set via the Config method, that provider will be used, otherwise the default provider will be used. | ||
*/ | ||
get RunViewProviderToUse(): IRunViewProvider; | ||
/** | ||
* Returns a COPY of the metadata configs array for the engine. This is a copy so you can't modify the original configs by modifying this array. | ||
@@ -84,3 +98,3 @@ */ | ||
*/ | ||
abstract Config(forceRefresh?: boolean, contextUser?: UserInfo): any; | ||
abstract Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): any; | ||
/** | ||
@@ -93,3 +107,20 @@ * This method should be called by sub-classes to load up their specific metadata requirements. For more complex metadata | ||
*/ | ||
protected Load(configs: Partial<BaseEnginePropertyConfig>[], forceRefresh?: boolean, contextUser?: UserInfo): Promise<void>; | ||
protected Load(configs: Partial<BaseEnginePropertyConfig>[], provider: IMetadataProvider, forceRefresh?: boolean, contextUser?: UserInfo): Promise<void>; | ||
/********************************************************************** | ||
* This section is for handling caching of multiple instances when needed | ||
* We use the primary singleton as the instance to store a cache of instances | ||
* that are tied to specific providers. This is useful when we have multiple | ||
* providers in a given app going to different connections. | ||
*********************************************************************/ | ||
private static _providerInstances; | ||
private static get ProviderInstances(); | ||
/** | ||
* This method will check for the existence of an instance of this engine class that is tied to a specific provider. If one exists, it will return it, otherwise it will create a new instance | ||
*/ | ||
static GetProviderInstance<T>(provider: IMetadataProvider, subclassConstructor: new () => BaseEngine<T>): BaseEngine<T>; | ||
/** | ||
* Internal method to set the provider when an engine is loaded | ||
* @param provider | ||
*/ | ||
protected SetProvider(provider: IMetadataProvider): void; | ||
private _eventListener; | ||
@@ -96,0 +127,0 @@ /** |
@@ -48,4 +48,7 @@ "use strict"; | ||
class BaseEngine extends global_1.BaseSingleton { | ||
/** | ||
* While the BaseEngine class is a singleton, normally, it is possible to have multiple instances of the class in an application if the class is used in multiple contexts that have different providers. | ||
*/ | ||
constructor() { | ||
super(...arguments); | ||
super(); | ||
this._loaded = false; | ||
@@ -61,2 +64,15 @@ this._loadingSubject = new rxjs_1.BehaviorSubject(false); | ||
/** | ||
* Returns the metadata provider to use for the engine. If a provider is set via the Config method, that provider will be used, otherwise the default provider will be used. | ||
*/ | ||
get ProviderToUse() { | ||
return this._provider || metadata_1.Metadata.Provider; | ||
} | ||
/** | ||
* Returns the RunView provider to use for the engine. This is the same underlying object as the @property ProviderTouse, but cast to IRunViewProvider. | ||
* If a provider is set via the Config method, that provider will be used, otherwise the default provider will be used. | ||
*/ | ||
get RunViewProviderToUse() { | ||
return this.ProviderToUse; | ||
} | ||
/** | ||
* Returns a COPY of the metadata configs array for the engine. This is a copy so you can't modify the original configs by modifying this array. | ||
@@ -75,3 +91,3 @@ */ | ||
*/ | ||
async Load(configs, forceRefresh = false, contextUser) { | ||
async Load(configs, provider, forceRefresh = false, contextUser) { | ||
if (metadata_1.Metadata.Provider.ProviderType === interfaces_1.ProviderType.Database && !contextUser) | ||
@@ -106,3 +122,28 @@ throw new Error('For server-side use of all engine classes, you must provide the contextUser parameter'); | ||
} | ||
static get ProviderInstances() { | ||
return BaseEngine._providerInstances; | ||
} | ||
/** | ||
* This method will check for the existence of an instance of this engine class that is tied to a specific provider. If one exists, it will return it, otherwise it will create a new instance | ||
*/ | ||
static GetProviderInstance(provider, subclassConstructor) { | ||
if (BaseEngine.ProviderInstances.has(provider)) { | ||
return BaseEngine.ProviderInstances.get(provider); | ||
} | ||
else { | ||
// we don't have an existing instance for this provider, so we need to create one | ||
const newInstance = new subclassConstructor(); // (new (this.constructor())) as BaseEngine<T>; | ||
BaseEngine.ProviderInstances.set(provider, newInstance); | ||
return newInstance; | ||
} | ||
} | ||
/** | ||
* Internal method to set the provider when an engine is loaded | ||
* @param provider | ||
*/ | ||
SetProvider(provider) { | ||
this._provider = provider; | ||
BaseEngine.ProviderInstances.set(this.ProviderToUse /*use default provider if one wasn't provided to use*/, this); | ||
} | ||
/** | ||
* This method is responsible for registering for MJGlobal events and listening for BaseEntity events where those | ||
@@ -325,4 +366,4 @@ * BaseEntity are related to the engine's configuration metadata. The idea is to auto-refresh the releated configs | ||
async LoadSingleDatasetConfig(config, contextUser) { | ||
const md = new metadata_1.Metadata(); | ||
const result = await md.GetAndCacheDatasetByName(config.DatasetName, config.DatasetItemFilters); | ||
const p = this.ProviderToUse; | ||
const result = await p.GetAndCacheDatasetByName(config.DatasetName, config.DatasetItemFilters); | ||
if (result.Success) { | ||
@@ -337,3 +378,3 @@ if (config.AddToObject !== false) { | ||
for (const entityData of item.Results) { | ||
const entity = await md.GetEntityObject(item.EntityName, contextUser); | ||
const entity = await p.GetEntityObject(item.EntityName, contextUser); | ||
entity.SetMany(entityData); | ||
@@ -443,2 +484,9 @@ entities.push(entity); | ||
exports.BaseEngine = BaseEngine; | ||
/********************************************************************** | ||
* This section is for handling caching of multiple instances when needed | ||
* We use the primary singleton as the instance to store a cache of instances | ||
* that are tied to specific providers. This is useful when we have multiple | ||
* providers in a given app going to different connections. | ||
*********************************************************************/ | ||
BaseEngine._providerInstances = new Map(); | ||
//# sourceMappingURL=baseEngine.js.map |
@@ -191,3 +191,3 @@ import { BaseEntity } from "./baseEntity"; | ||
/** | ||
* Creates a key for the given datasetName and itemFilters combination | ||
* Creates a unique key for the given datasetName and itemFilters combination coupled with the instance connection string to ensure uniqueness when 2+ connections exist | ||
* @param datasetName | ||
@@ -198,2 +198,7 @@ * @param itemFilters | ||
GetDatasetCacheKey(datasetName: string, itemFilters?: DatasetItemFilterType[]): string; | ||
/** | ||
* This property is implemented by each sub-class of ProviderBase and is intended to return a unique string that identifies the instance of the provider for the connection it is making. For example | ||
* for network connections, the URL including a TCP port would be a good connection string, whereas on database connections the database host url/instance/port would be a good connection string. | ||
*/ | ||
abstract get InstanceConnectionString(): string; | ||
protected ConvertItemFiltersToUniqueKey(itemFilters: DatasetItemFilterType[]): string; | ||
@@ -200,0 +205,0 @@ /** |
@@ -463,3 +463,3 @@ "use strict"; | ||
/** | ||
* Creates a key for the given datasetName and itemFilters combination | ||
* Creates a unique key for the given datasetName and itemFilters combination coupled with the instance connection string to ensure uniqueness when 2+ connections exist | ||
* @param datasetName | ||
@@ -470,3 +470,3 @@ * @param itemFilters | ||
GetDatasetCacheKey(datasetName, itemFilters) { | ||
return this.LocalStoragePrefix + _a.localStorageRootKey + '__DATASET__' + datasetName + this.ConvertItemFiltersToUniqueKey(itemFilters); | ||
return this.LocalStoragePrefix + _a.localStorageRootKey + this.InstanceConnectionString + '__DATASET__' + datasetName + this.ConvertItemFiltersToUniqueKey(itemFilters); | ||
} | ||
@@ -473,0 +473,0 @@ ConvertItemFiltersToUniqueKey(itemFilters) { |
{ | ||
"name": "@memberjunction/core", | ||
"version": "2.18.2", | ||
"version": "2.18.3", | ||
"description": "MemberJunction: Core Library including Metadata, Application, Entity Retrieval and Manipulation, and Utilities", | ||
@@ -22,3 +22,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@memberjunction/global": "2.18.2", | ||
"@memberjunction/global": "2.18.3", | ||
"rxjs": "^7.8.1", | ||
@@ -25,0 +25,0 @@ "zod": "^3.23.8" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
615325
8874
+ Added@memberjunction/global@2.18.3(transitive)
- Removed@memberjunction/global@2.18.2(transitive)