UNPKG

@eang/core

Version:

eang - model driven enterprise event processing

136 lines (135 loc) 4.25 kB
import { IFunctionStartContext, IFunctionStopContext } from './context.js'; import { FunctionInstanceObj, ProcessInstanceObj } from './objects.js'; import { Prettify } from './types.js'; export type IEntity = IObj | ICnx; export interface UserSessionEntityUpdates { created?: IEntity[]; updated?: IEntity[]; deleted?: string[]; } interface IEntityBase { entityType: 'obj' | 'cnx'; id: string; key: string; typeOf: string; name?: string; instanceOf?: string; childOf?: string; description?: string; data?: Record<string, unknown>; tags: { [key: string]: string; }; attributes: { [key: string]: string | number | boolean | object; }; createdBy?: string; createdAt: number; updatedBy?: string; updatedAt?: number; displayName: string; } export interface IObj extends IEntityBase { entityType: 'obj'; } export interface ICnx extends IEntityBase { entityType: 'cnx'; fromObjId: string; fromObjKey: string; fromObjTypeOf: string; fromObjInstanceOf?: string; toObjId: string; toObjKey: string; toObjTypeOf: string; toObjInstanceOf?: string; } declare abstract class Entity implements IEntityBase { abstract readonly entityType: 'obj' | 'cnx'; readonly id: string; readonly key: string; readonly typeOf: string; instanceOf?: string; name?: string; childOf?: string; description?: string; data?: Record<string, unknown>; tags: { [key: string]: string; }; attributes: { [key: string]: string | number | boolean | object; }; createdBy?: string; createdAt: number; updatedBy?: string; updatedAt?: number; get displayName(): string; constructor(entityOpts: Prettify<Partial<IEntityBase> & { id: string; key: string; typeOf: string; }>); } export declare abstract class Obj<T extends string = string> extends Entity implements IObj { readonly entityType: "obj"; abstract readonly typeOf: T; constructor(objOpts: Prettify<Partial<IObj> & { typeOf: string; }>); } export declare class Cnx extends Entity implements ICnx { readonly entityType = "cnx"; readonly typeOf: string; fromObjId: string; fromObjKey: string; fromObjTypeOf: string; fromObjInstanceOf?: string; toObjId: string; toObjKey: string; toObjTypeOf: string; toObjInstanceOf?: string; constructor(cnxOpts: Prettify<(Partial<ICnx> & { id: string; }) | (Partial<ICnx> & { typeOf: string; })>); } export type EangEventTypes = (typeof EangEventType)[keyof typeof EangEventType]; export declare const EangEventType: { readonly create: "create"; readonly update: "update"; readonly delete: "delete"; readonly start: "start"; readonly stop: "stop"; }; export interface EntityEventOptions { tenant: string; organizationalUnit: string; user: string; } export declare class EntityEvent { entity: Obj | Cnx; eventType: EangEventTypes; context?: any; tenant?: string; organizationalUnit?: string; user?: string; private constructor(); static parse(entity: Obj | Cnx, eventType: EangEventTypes, context?: any, options?: EntityEventOptions): EntityEvent; static create<T extends IEntity>(entity: T, options?: EntityEventOptions): EntityEvent; static update<T extends IEntity>(entity: T, context: any, options?: EntityEventOptions): EntityEvent; static delete<T extends IEntity>(entity: T, options?: EntityEventOptions): EntityEvent; static start(entity: FunctionInstanceObj | ProcessInstanceObj, context?: IFunctionStartContext, options?: EntityEventOptions): EntityEvent; static stop(entity: ProcessInstanceObj | FunctionInstanceObj, context?: IFunctionStopContext, options?: EntityEventOptions): EntityEvent; } export declare function parseCombinedId(id: string): { typeOf: string; key: string; }; /** * Converts an entity (Obj or Cnx) to ArangoDB document format * @param entity The entity to convert * @returns ArangoDB document with proper _key, _from, _to fields */ export declare function toArangoDoc(entity: Obj | Cnx): Record<string, unknown>; export {};