UNPKG

tinycoll

Version:

A minimal reactive document store with Mongo-like querying, reactivity, TTL support, and optional persistence.

25 lines (24 loc) 654 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileStorage = void 0; // file-storage.ts const promises_1 = require("fs/promises"); class FileStorage { #filePath; constructor(options) { this.#filePath = options.filePath; } async get() { try { const text = await (0, promises_1.readFile)(this.#filePath, 'utf-8'); return JSON.parse(text); } catch { return []; } } async set(_, value) { await (0, promises_1.writeFile)(this.#filePath, JSON.stringify(value, null, 2)); } } exports.FileStorage = FileStorage;