UNPKG

@envelop/persisted-operations

Version:

This plugin allow you to enforce execution of persisted (hashed) operation, using a custom store.

21 lines (20 loc) 613 B
import { readFileSync, promises } from 'fs'; export class JsonFileStore { constructor() { this.storeData = null; } get(operationId) { if (!this.storeData) { return undefined; } return this.storeData.get(operationId) || undefined; } loadFromFileSync(path) { const data = JSON.parse(readFileSync(path, 'utf-8')); this.storeData = new Map(Object.entries(data)); } async loadFromFile(path) { const data = JSON.parse(await promises.readFile(path, 'utf-8')); this.storeData = new Map(Object.entries(data)); } }