@envelop/persisted-operations
Version:
This plugin allow you to enforce execution of persisted (hashed) operation, using a custom store.
23 lines (22 loc) • 717 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonFileStore = void 0;
const fs_1 = require("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, fs_1.readFileSync)(path, 'utf-8'));
this.storeData = new Map(Object.entries(data));
}
async loadFromFile(path) {
const data = JSON.parse(await fs_1.promises.readFile(path, 'utf-8'));
this.storeData = new Map(Object.entries(data));
}
}
exports.JsonFileStore = JsonFileStore;