/** * Active Identity Table Definition * * Manages the currently active identity/DID for the application. * Replaces the activeDid field from the settings table to improve * data normalization and reduce cache drift. * * @author Matthew Raymer * @date 2025-08-21 */ /** * Active Identity record structure */ export interface ActiveIdentity { /** Primary key */ id?: number; /** The currently active DID - foreign key to accounts.did */ active_did: string; /** Last update timestamp in ISO format */ updated_at?: string; } /** * Database schema for the active_identity table */ export const ActiveIdentitySchema = { active_identity: "++id, active_did, updated_at", }; /** * Default values for ActiveIdentity records */ export const ActiveIdentityDefaults = { updated_at: new Date().toISOString(), }; /** * Validation function for DID format */ export function isValidDid(did: string): boolean { return typeof did === "string" && did.length > 0; } /** * Create a new ActiveIdentity record */ export function createActiveIdentity( activeDid: string, ): ActiveIdentity { if (!isValidDid(activeDid)) { throw new Error(`Invalid DID format: ${activeDid}`); } return { active_did: activeDid, updated_at: new Date().toISOString(), }; }