amplifyquery
Version:
131 lines (130 loc) • 3.93 kB
TypeScript
import { AmplifyDataService, ModelHook, BaseModel } from "./types";
/**
* Set the base URL for the app
* @param url Base URL for the app
*/
export declare function setAppUrl(url: string): void;
/**
* Get the base URL for the app
* @returns Configured app URL or empty string
*/
export declare function getAppUrl(): string;
/**
* Utility functions
*/
export declare const Utils: {
/**
* Get the ID of the currently logged-in user.
*/
getUserId: () => Promise<string>;
/**
* Timestamp formatting function
*/
formatTimestamp: (date?: Date) => string;
/**
* Extract YYYY-MM-DD format from date string
*/
getDateString: (dateStr: string | undefined) => string;
/**
* Utility function to remove the owner field and print a warning
* @param data Data object to process
* @param operation Operation being performed (create or update)
* @returns Data object with owner field removed
*/
removeOwnerField: <T extends Record<string, any>>(data: T, operation: "create" | "update" | "upsert") => Omit<T, "owner">;
};
/**
* Storage related utilities
*/
export declare const StorageService: {
_types: {
Item: {
url: string;
expiresAt: number;
};
CacheData: {
[key: string]: {
url: string;
expiresAt: number;
};
};
};
_urlCache: Map<string, {
url: string;
expiresAt: number;
}>;
_CACHE_KEY: string;
_initialized: boolean;
/**
* Initialize the memory cache.
* Loads URL cache from MMKV storage.
*/
_initCache: () => void;
/**
* Save cache to MMKV storage.
*/
_saveCache: () => void;
/**
* Upload an image file to Storage.
* @param file File to upload (Blob or File object)
* @param key Path and filename to save as (auto-generated if not specified)
* @returns Key of the uploaded file
*/
uploadImage: (file: Blob | File, key?: string) => Promise<string>;
/**
* Get the URL of a stored file. (Auto-caching)
* @param key File key
* @param options Caching options (forceRefresh: ignore cache and fetch new URL)
* @returns File URL
*/
getFileUrl: (key: string, options?: {
forceRefresh?: boolean;
}) => Promise<string>;
/**
* Delete a stored file.
* @param key Key of the file to delete
*/
deleteFile: (key: string) => Promise<void>;
/**
* Clear the URL cache.
*/
clearUrlCache: () => void;
/**
* Remove a specific key's URL cache.
* @param key Key of the URL to remove
*/
clearUrlCacheForKey: (key: string) => void;
/**
* Remove only expired URL caches.
*/
clearExpiredUrlCache: () => void;
/**
* Download an audio file.
* @param audioKey Key of the audio file to download
* @returns Local file system path of the downloaded file
*/
downloadAudioFile: (audioKey: string) => Promise<string>;
};
/**
* Authentication related utilities
*/
export declare const AuthService: {
/**
* Get information about the currently logged-in user.
*/
getCurrentUserInfo: () => Promise<{
userId: string;
username: string;
}>;
};
/**
* Utility to create a relational query hook.
* Creates a hook to query related items based on a specific foreign key.
*
* @param service Base service object
* @param relationName Name of the relation (e.g., Daily, User)
* @param queryName API query name (e.g., listMissionsByDaily)
* @param idParamName ID parameter name (e.g., dailyId, userId)
* @returns Relational query hook function
*/
export declare function createRelationalHook<T extends BaseModel, R extends BaseModel = any>(service: AmplifyDataService<T>, relationName: string, queryName: string, idParamName?: string): (id: string) => ModelHook<T>;