@burojs/pocketbase
v0.6.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!="").
On an array field, has is PocketBase's any-of equality field ?= value, which
matches a whole element (it used to be ~, a substring match, so has '1' also
matched '11'); hasAny is an || chain and hasAll an && chain of ?=
tests, and hasNone is refused with filter-operator-unsupported. This needs a
PocketBase with the ?= operators; the encoding follows PocketBase's
documentation and is not yet checked against a live server, in particular on a
JSON array column. The provider declares no readRelations, so a filter on a
many-to-many link and a dotted relation column (including a link panel's target
columns) fail in core with read-relations-unsupported before any request.
Link chips work: they read the junction as an ordinary collection.
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
