UNPKG

odious

Version:

Odious fundamentally revolutionizes the software development paradigm by seamlessly integrating deployment considerations into the development process, thus empowering developers of all skill levels to create and deploy applications with unprecedented eas

61 lines (48 loc) 1.5 kB
import memory from '../memory/memory.js'; export default class Settings { #storageApi; #objectId; #defaultValues; constructor(storageApi, objectId, defaultValues){ this.#storageApi = storageApi; this.#objectId = objectId; this.#defaultValues = defaultValues; } #started = false; get started(){return this.#started;} async start(defaults){ if (this.#started) throw new Error('already started'); if(!memory.started) await memory.start(this.#storageApi); for( const [categoryId, columns] of Object.entries(this.#defaultValues) ){ for( const [columnId, defaultValue] of Object.entries(columns) ){ const pathKey = this.keyOf(categoryId, columnId); if(!memory.has(pathKey)){ memory.set(pathKey, defaultValue); } } } this.#started = true; } async stop(){ await memory.stop(); } has(categoryId, columnId){ const pathKey = this.keyOf(categoryId, columnId); return memory.has(pathKey); } signal(categoryId, columnId){ const pathKey = this.keyOf(categoryId, columnId); return memory.get(pathKey); } get(categoryId, columnId){ const pathKey = this.keyOf(categoryId, columnId); return memory.get(pathKey).value; } set(categoryId, columnId, value){ const pathKey = this.keyOf(categoryId, columnId); memory.set(pathKey, value); } keyOf(categoryId, columnId){ return [ this.#storageApi, this.#objectId, categoryId, columnId, 'data' ].join(':'); } }