Files
json-server/src/observer.ts
typicode ada86ac596 feat: add _where filtering, use new op separator, drop _start, _end, _limit (#1696)
* feat: add _where filtering and new op separator

* Restore original README content above Query capabilities overview (#1697)

* test: refactor service tests to lightweight table cases

* chore: document underscore where operator compatibility

* refactor: clarify blank-string handling in where coercion

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
2026-02-14 13:34:05 +01:00

37 lines
651 B
JavaScript

import type { Adapter } from 'lowdb'
// Lowdb adapter to observe read/write events
export class Observer<T> {
#adapter: Adapter<T>
onReadStart = function () {
return
}
onReadEnd: (data: T | null) => void = function () {
return
}
onWriteStart = function () {
return
}
onWriteEnd = function () {
return
}
constructor(adapter: Adapter<T>) {
this.#adapter = adapter
}
async read() {
this.onReadStart()
const data = await this.#adapter.read()
this.onReadEnd(data)
return data
}
async write(arg: T) {
this.onWriteStart()
await this.#adapter.write(arg)
this.onWriteEnd()
}
}