@burojs/pocketbase
v0.2.0
Published
Buro: PocketBase data provider and auth provider
Readme
@burojs/pocketbase
A PocketBase data provider and auth provider for buro.
Install
pnpm add @burojs/pocketbase @burojs/coreUsage
import { createPocketbaseAuthProvider, createPocketbaseDataProvider } from '@burojs/pocketbase';
const authProvider = createPocketbaseAuthProvider({ baseUrl: pbUrl });
const dataProvider = createPocketbaseDataProvider({
baseUrl: pbUrl,
getToken: authProvider.getToken,
});createPocketbaseDataProvider({ baseUrl, getToken, fetchImpl? })
A DataProvider over PocketBase's REST API: list/one/many queries and
createOne/updateOne/deleteOne mutations. Portable filter and sort
descriptors are translated to PocketBase's own filter string syntax; offset
pagination only — cursor pagination is refused with a capability error.
filterExpression (the filter-string translator) is also exported on its own,
for callers that need to build the same string without the rest of the
provider. It returns undefined for a filter that matches every record —
send no filter argument for that — and a real expression string for
everything else, including a filter that matches nothing. A branchless
combinator ({and: []}, {or: []}) and an empty-set test (in: [],
hasAny: [], notIn: [], hasAll: []) carry truth values and are folded, not
dropped; PocketBase's grammar has no boolean literal, so the one constant that
survives folding — FALSE — is emitted as the contradiction (id="" && id!="").
createPocketbaseAuthProvider({ baseUrl, fetchImpl?, storageKey? })
Password auth against a PocketBase users collection, with the session kept
in localStorage. Returns an AuthProvider plus a getToken(): string | null
escape hatch, which is how the data provider above learns the current token.
Deliberately small: this exists to demonstrate the data/auth provider ports,
not to be a complete auth reference.
License
MIT
