UNPKG

json-server

Version:

[![Node.js CI](https://github.com/typicode/json-server/actions/workflows/node.js.yml/badge.svg)](https://github.com/typicode/json-server/actions/workflows/node.js.yml)

31 lines (30 loc) 648 B
// Lowdb adapter to observe read/write events export class Observer { #adapter; onReadStart = function () { return; }; onReadEnd = function () { return; }; onWriteStart = function () { return; }; onWriteEnd = function () { return; }; constructor(adapter) { this.#adapter = adapter; } async read() { this.onReadStart(); const data = await this.#adapter.read(); this.onReadEnd(data); return data; } async write(arg) { this.onWriteStart(); await this.#adapter.write(arg); this.onWriteEnd(); } }