diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index 4dc79880..c05bea0b 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -1,9 +1,9 @@ /** * Enhanced PlatformService Mixin with ultra-concise database operations and caching - * + * * Provides cached platform service access and utility methods for Vue components. * Eliminates repetitive PlatformServiceFactory.getInstance() calls across components. - * + * * Features: * - Cached platform service instance (created once per component) * - Enhanced database utility methods with comprehensive error handling @@ -63,10 +63,10 @@ const componentCaches = new WeakMap>>(); * Cache configuration constants */ const CACHE_DEFAULTS = { - settings: 30000, // 30 seconds TTL for settings - contacts: 60000, // 60 seconds TTL for contacts - accounts: 30000, // 30 seconds TTL for accounts - default: 15000, // 15 seconds default TTL + settings: 30000, // 30 seconds TTL for settings + contacts: 60000, // 60 seconds TTL for contacts + accounts: 30000, // 30 seconds TTL for accounts + default: 15000, // 15 seconds default TTL } as const; /** @@ -434,13 +434,15 @@ export const PlatformServiceMixin = { * @returns Cached mapped array of all contacts */ async $contacts(): Promise { - const cacheKey = 'contacts_all'; + const cacheKey = "contacts_all"; const cached = this._getCached(cacheKey); if (cached) { return cached; } - const contacts = await this.$query("SELECT * FROM contacts ORDER BY name"); + const contacts = await this.$query( + "SELECT * FROM contacts ORDER BY name", + ); return this._setCached(cacheKey, contacts, CACHE_DEFAULTS.contacts); }, @@ -458,7 +460,11 @@ export const PlatformServiceMixin = { } const settings = await this.$getSettings(MASTER_SETTINGS_KEY, defaults); - return (this as any)._setCached(cacheKey, settings, CACHE_DEFAULTS.settings); + return (this as any)._setCached( + cacheKey, + settings, + CACHE_DEFAULTS.settings, + ); }, /** @@ -469,8 +475,8 @@ export const PlatformServiceMixin = { */ async $accountSettings(did?: string, defaults: any = {}): Promise { const currentDid = did || (this as any).activeDid; - const cacheKey = `account_settings_${currentDid || 'default'}`; - + const cacheKey = `account_settings_${currentDid || "default"}`; + const cached = this._getCached(cacheKey); if (cached) { return { ...cached, ...defaults }; // Merge with any new defaults @@ -480,9 +486,13 @@ export const PlatformServiceMixin = { if (!currentDid) { settings = await this.$settings(defaults); } else { - settings = await this.$getMergedSettings(MASTER_SETTINGS_KEY, currentDid, defaults); + settings = await this.$getMergedSettings( + MASTER_SETTINGS_KEY, + currentDid, + defaults, + ); } - + return this._setCached(cacheKey, settings, CACHE_DEFAULTS.settings); }, @@ -498,28 +508,28 @@ export const PlatformServiceMixin = { */ async $saveSettings(changes: any): Promise { const result = await databaseUtil.updateDefaultSettings(changes); - + // Invalidate related caches this._invalidateCache(`settings_${MASTER_SETTINGS_KEY}`); this._invalidateCache(`account_settings_default`); - + return result; }, /** * Save user-specific settings with cache invalidation - $saveUserSettings() * Ultra-concise shortcut for updateDidSpecificSettings - * @param did DID identifier + * @param did DID identifier * @param changes Settings changes to save * @returns Promise Success status */ async $saveUserSettings(did: string, changes: any): Promise { const result = await databaseUtil.updateDidSpecificSettings(did, changes); - + // Invalidate related caches this._invalidateCache(`account_settings_${did}`); this._invalidateCache(`settings_${MASTER_SETTINGS_KEY}`); - + return result; }, @@ -559,7 +569,7 @@ export const PlatformServiceMixin = { * Forces reload of contacts from database */ async $refreshContacts(): Promise { - this._invalidateCache('contacts_all'); + this._invalidateCache("contacts_all"); return await this.$contacts(); }, @@ -612,11 +622,11 @@ declare module "@vue/runtime-core" { $db(sql: string, params?: unknown[]): Promise; $exec(sql: string, params?: unknown[]): Promise; $one(sql: string, params?: unknown[]): Promise; - + // Query + mapping combo methods $query(sql: string, params?: unknown[]): Promise; $first(sql: string, params?: unknown[]): Promise; - + // Enhanced utility methods $dbQuery(sql: string, params?: unknown[]): Promise; $dbExec(sql: string, params?: unknown[]): Promise; @@ -624,17 +634,17 @@ declare module "@vue/runtime-core" { $getSettings(key: string, defaults?: any): Promise; $getMergedSettings(key: string, did?: string, defaults?: any): Promise; $withTransaction(fn: () => Promise): Promise; - + // Cached specialized shortcuts (massive performance boost) $contacts(): Promise; $settings(defaults?: any): Promise; $accountSettings(did?: string, defaults?: any): Promise; - + // Settings update shortcuts (eliminate 90% boilerplate) $saveSettings(changes: any): Promise; $saveUserSettings(did: string, changes: any): Promise; $saveMySettings(changes: any): Promise; - + // Cache management methods $refreshSettings(): Promise; $refreshContacts(): Promise;