@heojeongbo/calque-dexie
v0.3.0
Published
Dexie/IndexedDB backend runtime for calque-generated ORM code.
Maintainers
Readme
@heojeongbo/calque-dexie
The Dexie adapter for code generated by calque.
npm install @heojeongbo/calque-dexie dexie @bufbuild/protobuf @connectrpc/connectThis is the specifier generated code imports. It re-exports
@heojeongbo/calque-runtime
in full, so a generated file needs one import line rather than two.
Using it
calque emits a schemas() per proto package. Hand it to Dexie:
import Dexie from "dexie"
import { schemas, DbService, type Db } from "./gen/apptest/db.g"
const db = new Dexie("app") as Db
db.version(1).stores(schemas())and construct the tables:
const user = new DbService["apptest.User"](db)
const u = await user.get({ ref: { key: { case: "id", value: id } } })API
TableBase<Desc>
The base class every generated TableService extends. It holds the Dexie
handle and the message descriptor, and provides:
| | |
|---|---|
| _query(fn) | run a Dexie query and throw NotFound if it returns nothing |
| _insert(v) | dehydrate and add |
| _reconcile(v) | compare against what is stored and keep the newer |
| _compare(a, b) | version comparison; the generated subclass overrides it when the entity has a version field |
| _clone(v), _err(msg, code) | |
_dehydrate and _hydrate are abstract in effect — the base throws, and the
generated subclass overrides both.
_reconcilechanged in v0.2.0. It now returns whether it actually wrote:falsemeans the stored value was newer or the same and nothing happened. Until v0.2.0 it resolvedtruewhatever the comparison decided, so a caller writingif (!ok) continuehad a branch that never ran — and now does. That is why this is a minor bump and not a patch. It was conformance item 5.
Types
type ValueOf<Desc> // the decoded message
type EntityOf<Desc> // what is actually stored — the message minus $typeName and $unknown
type DbOf<Desc> // Dexie, plus this entity's table under its full proto namePlus everything from the runtime package: Key, uuid, unsafe,
QueryDescOf, QueryDesc, InputOf, OutputOf, RefOf.
Peer dependencies
dexie ^4.0.0, @bufbuild/protobuf ^2.10.0, @connectrpc/connect
^2.1.0. Node 20 or later.
They are peers rather than dependencies because your application already has them, and the generated code has to agree with the copy it has.
License
MIT
