UNPKG

@hotmeshio/hotmesh

Version:

Serverless Workflow

129 lines (128 loc) 4.03 kB
"use strict"; /** * The Cache is a key/value store and used to store commonly accessed Redis metadata * (mainly the execution rules for the app) to save time accessing them as they * are immutable per verison. Rules are only ejected when a new version * (a new distributed executable) is deployed to the quorum * and the cache is invalidated/cleared of the prior version. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Cache = void 0; class Cache { /** * The cache is ALWAYS initialized with HotMeshSettings. The other parameters are optional. * @param settings * @param apps * @param schemas * @param subscriptions * @param transitions * @param hookRules */ constructor(appId, settings, apps = {}, schemas = {}, subscriptions = {}, symbols = {}, symvals = {}, transitions = {}, hookRules = {}, workItems = {}) { this.appId = appId; this.settings = settings; this.apps = apps; this.schemas = schemas; this.subscriptions = subscriptions; this.symbols = symbols; this.symvals = symvals; this.transitions = transitions; this.hookRules = hookRules; this.workItems = workItems; } /** * invalidate the cache; settings are not invalidated! */ invalidate() { this.apps = {}; this.schemas = {}; this.subscriptions = {}; this.transitions = {}; this.hookRules = {}; } getSettings() { return this.settings; } setSettings(settings) { this.settings = settings; } getApps() { return this.apps; } getApp(appId) { return this.apps[appId]; } setApps(apps) { this.apps = apps; } setApp(appId, app) { this.apps[appId] = app; } getSchemas(appId, version) { return this.schemas[`${appId}/${version}`]; } getSchema(appId, version, activityId) { return this.schemas?.[`${appId}/${version}`]?.[activityId]; } setSchemas(appId, version, schemas) { this.schemas[`${appId}/${version}`] = schemas; } setSchema(appId, version, activityId, schema) { this.schemas[`${appId}/${version}`][activityId] = schema; } getSubscriptions(appId, version) { return this.subscriptions[`${appId}/${version}`]; } getSubscription(appId, version, topic) { return this.subscriptions?.[`${appId}/${version}`]?.[topic]; } setSubscriptions(appId, version, subscriptions) { this.subscriptions[`${appId}/${version}`] = subscriptions; } getSymbols(appId, targetEntityId) { return this.symbols[`${appId}/${targetEntityId}`]; } setSymbols(appId, targetEntityId, symbols) { this.symbols[`${appId}/${targetEntityId}`] = symbols; } deleteSymbols(appId, targetEntityId) { delete this.symbols[`${appId}/${targetEntityId}`]; } getSymbolValues(appId) { return this.symvals[`${appId}`]; } setSymbolValues(appId, symvals) { this.symvals[`${appId}`] = symvals; } deleteSymbolValues(appId) { delete this.symvals[`${appId}`]; } getTransitions(appId, version) { return this.transitions[`${appId}/${version}`]; } setTransitions(appId, version, transitions) { this.transitions[`${appId}/${version}`] = transitions; } getHookRules(appId) { return this.hookRules[`${appId}`]; } setHookRules(appId, hookRules) { this.hookRules[`${appId}`] = hookRules; } getSignals(appId, version) { throw new Error('SIGNAL (getHooks) is not supported'); } setSignals(appId, version) { throw new Error('SIGNAL (setHook) is not supported'); } getActiveTaskQueue(appId) { return this.workItems[appId]; } setWorkItem(appId, workItem) { this.workItems[appId] = workItem; } removeWorkItem(appId) { delete this.workItems[appId]; } } exports.Cache = Cache;