UNPKG

@envelop/persisted-operations

Version:
24 lines (23 loc) 749 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JsonFileStore = void 0; const node_fs_1 = require("node:fs"); class JsonFileStore { storeData = null; get(operationId) { if (!this.storeData) { return undefined; } return this.storeData.get(operationId) || undefined; } loadFromFileSync(path) { const data = JSON.parse((0, node_fs_1.readFileSync)(path, 'utf-8')); this.storeData = new Map(Object.entries(data)); } loadFromFile(path) { return node_fs_1.promises.readFile(path, 'utf-8').then(data => { this.storeData = new Map(Object.entries(JSON.parse(data))); }); } } exports.JsonFileStore = JsonFileStore;