UNPKG

@acurast/cli

Version:

A cli to interact with the Acurast Cloud.

40 lines 1.22 kB
import * as fs from 'fs'; import { ensureDirectoryExistence } from '../acurast/storeDeployment.js'; import { ACURAST_BASE_PATH } from '../constants.js'; export class LocalStorage { constructor(fileName = 'keys.json') { this.filePath = `${ACURAST_BASE_PATH}/${fileName}`; this.ensureFile(); } ensureFile() { ensureDirectoryExistence(this.filePath); if (!fs.existsSync(this.filePath)) { fs.writeFileSync(this.filePath, '{}', 'utf8'); } } readStorage() { const data = fs.readFileSync(this.filePath, 'utf8'); return JSON.parse(data); } writeStorage(storage) { fs.writeFileSync(this.filePath, JSON.stringify(storage, null, 2), 'utf8'); } getItem(key) { const storage = this.readStorage(); return storage[key] || null; } setItem(key, value) { const storage = this.readStorage(); storage[key] = value; this.writeStorage(storage); } removeItem(key) { const storage = this.readStorage(); delete storage[key]; this.writeStorage(storage); } clear() { this.writeStorage({}); } } //# sourceMappingURL=LocalStorage.js.map