@satoshibits/cache-keys
Version:
Type-safe cache key generation with zero dependencies
46 lines • 2.38 kB
text/typescript
import type { CacheKeyFactory } from './types.mjs';
/**
* Create a type-safe cache key factory
*
* @param namespace The namespace for this key type (e.g., 'user', 'account')
* @param type The specific type within the namespace (e.g., 'profile', 'settings')
* @param formatter Function to format the key suffix from arguments
* @param parser Optional function to parse the key back into components
* @returns A cache key factory
*/
export declare function createKeyFactory<T extends string, TArgs extends readonly unknown[] = unknown[]>(namespace: string, type: string, formatter: (...args: TArgs) => string, parser?: (suffix: string) => Record<string, string> | null): CacheKeyFactory<T, TArgs>;
/**
* Create a simple key factory for single ID keys
*
* @param namespace The namespace for this key type
* @param type The specific type within the namespace
* @returns A cache key factory for single ID keys
*/
export declare function createSimpleKeyFactory<T extends string>(namespace: string, type: string): CacheKeyFactory<T, [id: string | number]>;
/**
* Create a key factory for keys with two IDs
*
* @param namespace The namespace for this key type
* @param type The specific type within the namespace
* @param id1Name Name for the first ID in parsed result
* @param id2Name Name for the second ID in parsed result
* @returns A cache key factory for dual ID keys
*/
export declare function createDualKeyFactory<T extends string>(namespace: string, type: string, id1Name?: string, id2Name?: string): CacheKeyFactory<T, [id1: string | number, id2: string | number]>;
/**
* Create a key factory for paginated lists
*
* @param namespace The namespace for this key type
* @param type The specific type within the namespace
* @returns A cache key factory for paginated keys
*/
export declare function createPaginatedKeyFactory<T extends string>(namespace: string, type: string): CacheKeyFactory<T, [id: string | number, page: number, limit: number]>;
/**
* Create a versioned key factory
*
* @param namespace The namespace for this key type
* @param type The specific type within the namespace
* @returns A cache key factory for versioned keys
*/
export declare function createVersionedKeyFactory<T extends string>(namespace: string, type: string): CacheKeyFactory<T, [id: string | number, version: number]>;
//# sourceMappingURL=factory.d.mts.map