mirror of
https://github.com/outline/outline.git
synced 2026-12-01 09:22:14 +03:00
* 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>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type Model from "../base/Model";
|
|
|
|
const fields = new Map<string, (string | number | symbol)[]>();
|
|
|
|
/**
|
|
* Returns the keys recorded as serializable fields on a model.
|
|
*
|
|
* @param target the model to inspect.
|
|
* @returns the keys decorated with @Field.
|
|
*/
|
|
export const getFieldsForModel = <T extends Model>(target: T) =>
|
|
getFieldsForModelClass(target.constructor);
|
|
|
|
/**
|
|
* Returns the keys recorded as serializable fields on a model class.
|
|
*
|
|
* @param model the model class to inspect.
|
|
* @returns the keys decorated with @Field.
|
|
*/
|
|
export function getFieldsForModelClass(model: { name: string }) {
|
|
return fields.get(model.name) ?? [];
|
|
}
|
|
|
|
/**
|
|
* A decorator that records this key as a serializable field on the model.
|
|
* Properties decorated with @Field will be included in API requests by default.
|
|
*
|
|
* @param target the model the property is defined on.
|
|
* @param propertyKey the key to record as a field.
|
|
*/
|
|
const Field = (target: Model, propertyKey: string | symbol) => {
|
|
const className = target.constructor.name;
|
|
fields.set(className, [...(fields.get(className) ?? []), propertyKey]);
|
|
};
|
|
|
|
export default Field;
|