* fix: Recover from closed IndexedDB connections in store persistence
StorePersistence cached a single IDBDatabase forever, so once the browser
or another tab closed the connection every subsequent hydrate, flush and
clear threw against a dead handle.
- Close and forget the connection on versionchange, so another tab is
never blocked from deleting or upgrading the database
- Discard the cached connection on close, open error and blocked, and
retry once against a fresh connection when one was closed underneath us
- Close open connections before deleteAllDatabases removes them, which
also stops logout recreating the databases it just deleted
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix: Cancel pending writes when store persistence is disabled
A debounced flush scheduled before disabling would still fire, reopening
and recreating the database that deleteAllDatabases had just removed.
* feat: Persist policies to IndexedDB so abilities survive reload
Adds a StorePersistence layer that caches a store's models in IndexedDB
and hydrates them back at boot as stale data, revalidated by normal API
traffic. Enabled for the policies store, scoped per team, so cached
abilities are available immediately after a reload instead of every
policy needing a forced refetch.
- Persistence hooks in the base Store add/remove/clear methods, since
add() updates existing models in place and map observation would miss
those changes
- Enabled from RootStore construction (team read from localStorage) and
again after auth.info succeeds to cover the first session after login
- Store.clear() wipes the persisted records, covering both logout paths
- deleteAllDatabases() fallback removes the policies database on
browsers without indexedDB.databases()
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XisV6sRdexfnPSiehurKoV
* refactor: Opt stores into persistence via a persistable property
Stores now declare persistence with `persistable = true` and RootStore
sweeps all persistable stores, deriving each database name from the
store's apiEndpoint, instead of RootStore hard-coding the policies
store. The deleteAllDatabases fallback uses the same sweep.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XisV6sRdexfnPSiehurKoV
* refactor: Simplify store persistence enablement and clearing
- Move the persistable guard into Store.enablePersistence so RootStore
can call it unconditionally on every store
- StorePersistence derives its own database name from the store and
teamId rather than receiving a prebuilt name
- StorePersistence.clear returns a promise, making the test deterministic
instead of sleeping
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XisV6sRdexfnPSiehurKoV
* fix: Avoid re-persisting hydrated records, await clear transaction
Hydration called store.add() for every cached record, which now triggers
persist() and scheduled a flush that wrote the just-loaded data straight
back to IndexedDB at boot. Guard persist() with a hydrating flag.
clear() awaited the objectStore.clear() request rather than the enclosing
transaction, so it could resolve before commit and miss abort errors.
* lock
* iterate
---------
Co-authored-by: Claude <noreply@anthropic.com>
* chore: Replace lodash with es-toolkit
Migrate all direct lodash imports to es-toolkit/compat for a smaller,
faster, lodash-compatible utility library. Transitive lodash usage from
other packages remains unchanged.
* fix: Restore isPlainObject semantics in CanCan policy
The lodash migration aliased `isObject` to `lodash/isPlainObject` and
the codemod incorrectly mapped the local name to es-toolkit's `isObject`,
which also returns true for arrays and functions. This caused condition
objects in policy definitions to be skipped, breaking authorization
checks across the codebase.
* fix: Restore unicode-aware length counting in validators
es-toolkit/compat's size() returns string.length, while lodash's _.size()
counts unicode code points. Switch to [...value].length to preserve the
previous behavior so multi-byte characters like emoji count as one.
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.
closes#1282