@satoshibits/cache-keys
Version:
Type-safe cache key generation with zero dependencies
58 lines • 2.88 kB
text/typescript
/**
* @satoshibits/cache-keys - Type-safe cache key generation
*
* A zero-dependency library for generating consistent, type-safe cache keys
* with built-in sanitization and pattern matching capabilities.
*/
export type { ID, CacheKeyFactory, KeyBuilderOptions, SanitizeOptions, } from "./types.mjs";
export { sanitizeKeyComponent, decodeKeyComponent, isValidKeyComponent, joinKeyComponents, splitKeyComponents, base64urlDecode, } from "./sanitizer.mjs";
export { createKeyFactory, createSimpleKeyFactory, createDualKeyFactory, createPaginatedKeyFactory, createVersionedKeyFactory, } from "./factory.mjs";
export { CacheKeyBuilder, fromTemplate, scopedBuilder } from "./builder.mjs";
export { createInvalidationPattern, matchKeys, createMultiPattern, extractNamespace, extractKeyType, groupKeysByNamespace, createHierarchicalPatterns, matchesAnyPattern, } from "./patterns.mjs";
export { accountKeys } from "./presets/account.mjs";
export { userKeys } from "./presets/user.mjs";
export { campaignKeys } from "./presets/campaign.mjs";
export { analyticsKeys } from "./presets/analytics.mjs";
import type { CacheKeyFactory as CKF } from "./types.mjs";
/**
* Utility function to create a new set of key factories for a domain
*
* This function serves as a type-safe helper for organizing cache key factories
* by domain. It ensures that all factories in a domain follow the correct type
* structure and provides a consistent way to group related cache keys.
*
* @param namespace The domain namespace (currently unused but reserved for future enhancements)
* @param factories Object containing cache key factories for the domain
* @returns The same factories object with type validation
*
* @example
* export const orderKeys = createDomainKeys('order', {
* details: createSimpleKeyFactory('order', 'details'),
* items: createPaginatedKeyFactory('order', 'items'),
* status: createKeyFactory('order', 'status',
* (orderId: string, status: string) => `${orderId}:${status}`
* )
* });
*/
export declare function createDomainKeys<T extends Record<string, CKF<string, unknown[]>>>(_namespace: string, factories: T): T;
export declare const commonPatterns: {
/**
* Invalidate all keys in a namespace
* @example commonPatterns.namespace('user')
* @returns 'user:*'
*/
readonly namespace: (namespace: string) => string;
/**
* Invalidate all keys of a specific type in a namespace
* @example commonPatterns.type('user', 'profile')
* @returns 'user:profile:*'
*/
readonly type: (namespace: string, type: string) => string;
/**
* Invalidate all keys for a specific ID across all types
* @example commonPatterns.allForId('user', '123')
* @returns 'user:*:123*'
*/
readonly allForId: (namespace: string, id: string | number) => string;
};
//# sourceMappingURL=index.d.mts.map