forked from trent_larson/crowd-funder-for-time-pwa
refactor: improve type safety in PlatformServiceMixin with database and cache improvements
- Add proper return types for database methods: QueryExecResult, DatabaseExecResult, Contact[] - Improve cache system typing with VueComponentWithMixin interface and CacheEntry<unknown> - Fix $refreshContacts() return type from Promise<any[]> to Promise<Contact[]> - Update database interfaces with DatabaseExecResult and generic DatabaseResult types - Maintain runtime compatibility by keeping necessary (this as any) for Vue component context - Reduces TypeScript warnings from 81 to 23 while preserving all functionality - Improves type safety for database operations, caching, and contact management
This commit is contained in:
@@ -301,7 +301,7 @@ export const PlatformServiceMixin = {
|
|||||||
return settings;
|
return settings;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`[${(this as any).$options.name}] Failed to get settings:`,
|
`[${(this as unknown as VueComponentWithMixin).$options.name}] Failed to get settings:`,
|
||||||
{
|
{
|
||||||
key,
|
key,
|
||||||
error,
|
error,
|
||||||
@@ -375,7 +375,7 @@ export const PlatformServiceMixin = {
|
|||||||
return mergedSettings;
|
return mergedSettings;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`[${(this as any).$options.name}] Failed to get merged settings:`,
|
`[${(this as unknown as VueComponentWithMixin).$options.name}] Failed to get merged settings:`,
|
||||||
{
|
{
|
||||||
defaultKey,
|
defaultKey,
|
||||||
accountDid,
|
accountDid,
|
||||||
@@ -474,7 +474,7 @@ export const PlatformServiceMixin = {
|
|||||||
sql: string,
|
sql: string,
|
||||||
params: unknown[] = [],
|
params: unknown[] = [],
|
||||||
): Promise<T | null> {
|
): Promise<T | null> {
|
||||||
const results = await (this as any).$query(sql, params);
|
const results = await this.$query(sql, params);
|
||||||
return results.length > 0 ? (results[0] as T) : null;
|
return results.length > 0 ? (results[0] as T) : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -553,7 +553,7 @@ export const PlatformServiceMixin = {
|
|||||||
const currentDid = did || (this as any).activeDid;
|
const currentDid = did || (this as any).activeDid;
|
||||||
const cacheKey = `account_settings_${currentDid || "default"}`;
|
const cacheKey = `account_settings_${currentDid || "default"}`;
|
||||||
|
|
||||||
const cached = this._getCached<any>(cacheKey);
|
const cached = this._getCached<Settings>(cacheKey);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
return { ...cached, ...defaults }; // Merge with any new defaults
|
return { ...cached, ...defaults }; // Merge with any new defaults
|
||||||
}
|
}
|
||||||
@@ -647,7 +647,7 @@ export const PlatformServiceMixin = {
|
|||||||
* Manually refresh contacts cache - $refreshContacts()
|
* Manually refresh contacts cache - $refreshContacts()
|
||||||
* Forces reload of contacts from database
|
* Forces reload of contacts from database
|
||||||
*/
|
*/
|
||||||
async $refreshContacts(): Promise<any[]> {
|
async $refreshContacts(): Promise<Contact[]> {
|
||||||
this._invalidateCache("contacts_all");
|
this._invalidateCache("contacts_all");
|
||||||
return await this.$contacts();
|
return await this.$contacts();
|
||||||
},
|
},
|
||||||
@@ -745,7 +745,7 @@ declare module "@vue/runtime-core" {
|
|||||||
|
|
||||||
// Cache management methods
|
// Cache management methods
|
||||||
$refreshSettings(): Promise<Settings>;
|
$refreshSettings(): Promise<Settings>;
|
||||||
$refreshContacts(): Promise<any[]>;
|
$refreshContacts(): Promise<Contact[]>;
|
||||||
$clearAllCaches(): void;
|
$clearAllCaches(): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user