Frontend/25_02_24/node_modules/json-server/lib/observer.js

31 lines
648 B
JavaScript
Raw Normal View History

2025-02-25 08:55:29 +00:00
// 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();
}
}