You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
61 lines
1.3 KiB
/**
|
|
* 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(),
|
|
};
|
|
}
|
|
|