@eang/core
Version:
eang - model driven enterprise event processing
67 lines • 2.52 kB
JavaScript
import { parseCombinedId } from '../entity.js';
import { EventInstanceObj, ErrorEventInstanceObj, EventObj, ErrorEventObj } from './events.js';
import { ProcessInstanceObj, FunctionInstanceObj, FunctionObj, ServiceObj, ProcessObj } from './runtime.js';
import { ItemObj } from './content.js';
import { GroupObj, OrganizationObj, PersonObj, ServiceAccountObj } from './organizational.js';
import { SystemObj } from './system.js';
import { FolderObj, PageObj } from './content.js';
import { SecurityPolicyObj, PolicyRuleObj } from './security.js';
export const typeOfToClassMap = {
Event: EventObj,
EventInstance: EventInstanceObj,
ErrorEvent: ErrorEventObj,
ErrorEventInstance: ErrorEventInstanceObj,
Process: ProcessObj,
ProcessInstance: ProcessInstanceObj,
FunctionInstance: FunctionInstanceObj,
Function: FunctionObj,
Service: ServiceObj,
Item: ItemObj,
Group: GroupObj,
System: SystemObj,
Folder: FolderObj,
Page: PageObj,
SecurityPolicy: SecurityPolicyObj,
PolicyRule: PolicyRuleObj,
Organization: OrganizationObj,
Person: PersonObj,
ServiceAccount: ServiceAccountObj
};
export function registerTypeOfClass(typeOf, cls) {
;
typeOfToClassMap[typeOf] =
cls;
}
export function createObj(data, typeOf, key) {
if (data.typeOf &&
typeof data.typeOf === 'string' &&
data.key &&
typeof data.key === 'string') {
// If data already has typeOf and key, use them directly
}
else if (data.typeOf && typeof data.typeOf === 'string' && !data.key) {
// If only typeOf is provided, key will be auto-generated by the Obj constructor
// No need to set data.key here
}
else if (typeOf && typeof typeOf === 'string' && key && typeof key === 'string') {
data.typeOf = typeOf;
data.key = key;
}
else if (typeOf && typeof typeOf === 'string' && !key) {
// If only typeOf is provided as parameter, key will be auto-generated
data.typeOf = typeOf;
}
else if (data.id && typeof data.id === 'string') {
const { key, typeOf } = parseCombinedId(data.id);
data.typeOf = typeOf;
data.key = key;
}
else {
throw new Error('Either id, or typeOf (with optional key) must be provided as strings to create an object');
}
const Cls = typeOfToClassMap[data.typeOf];
if (!Cls)
throw new Error(`Unknown typeOf: ${data.typeOf}`);
return new Cls(data);
}
//# sourceMappingURL=factory.js.map