clone

a deno framework for local-first web apps that open instantly, work offline and sync when users choose

feat/fix-sync-enrollment-startup
lofi / package / schema / shared-registry.ts
shared-registry.ts 1.7K
1/**2 * The shared-column registry: `s.sharedEncrypted*` constructors record their3 * configuration here at schema-definition time, and the runtime reads it at4 * boot to start the wrapped-key watcher and to seal writes with the right5 * scope. Module-level for the same reason the encrypted-column registry is —6 * schema definition happens before any runtime exists.7 *8 * @module9 */1011/** The wiring one shared column declares: where its group and keys live. */12export type SharedColumnConfig = {13 /** The column's cryptographic label, conventionally `"table.column"`. */14 label: string;15 /** How the runtime value serializes into the sealed plaintext. */16 kind: "text" | "json";17 /** The group table whose membership scopes the field key. */18 group: string;19 /** The sibling column on the row that references the group. */20 groupIdColumn: string;21 /** The wrapped-key table (declared with `sharedFieldKeyTable`). */22 keys: string;23 /** The key-directory table (declared with `sharedFieldDirectoryTable`). */24 directory: string;25};2627const configs = new Map<string, SharedColumnConfig>();2829/** Records one shared column's wiring; keyed by label. */30export function registerSharedColumn(config: SharedColumnConfig): void {31 configs.set(config.label, config);32}3334/** Every registered shared-column configuration. */35export function sharedColumnConfigs(): SharedColumnConfig[] {36 return [...configs.values()];37}3839/** The registered configuration for a label, if any. */40export function sharedColumnConfig(label: string): SharedColumnConfig | undefined {41 return configs.get(label);42}4344/** Empties the registry; tests call this between schemas. */45export function clearSharedColumnRegistry(): void {46 configs.clear();47}