mirror of
https://github.com/typicode/json-server.git
synced 2026-03-13 09:35:37 +08:00
* 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>
37 lines
651 B
JavaScript
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()
|
|
}
|
|
}
|