UNPKG

@satoshibits/cache-keys

Version:
78 lines 2.77 kB
import type { CacheKeyFactory } from './types.mjs'; /** * Create an invalidation pattern from a key factory and partial arguments * * @param factory The key factory to use * @param prefixArgs Partial arguments to create a prefix pattern * @returns A pattern string for matching keys * * @example * // Invalidate all campaign keys for an account * const pattern = createInvalidationPattern(campaignKeys.list, accountId); * // Returns: "campaign:list:507f1f77bcf86cd799439011:*" */ export declare function createInvalidationPattern(factory: CacheKeyFactory, ...prefixArgs: unknown[]): string; /** * Match keys against a pattern * * @param keys Array of cache keys * @param pattern Pattern to match against (supports * wildcard) * @returns Array of matching keys */ export declare function matchKeys(keys: string[], pattern: string): string[]; /** * Create a pattern that matches any of the given prefixes * * @param prefixes Array of key prefixes * @returns A regex pattern for matching */ export declare function createMultiPattern(prefixes: string[]): RegExp; /** * Extract the namespace from a cache key * * @param key The cache key * @param separator The separator used in the key * @returns The namespace or null if invalid */ export declare function extractNamespace(key: string, separator?: string): string | null; /** * Extract namespace and type from a cache key * * @param key The cache key * @param separator The separator used in the key * @returns Object with namespace and type or null if invalid */ export declare function extractKeyType(key: string, separator?: string): { namespace: string; type: string; } | null; /** * Group keys by their namespace * * @param keys Array of cache keys * @param separator The separator used in keys * @returns Map of namespace to keys */ export declare function groupKeysByNamespace(keys: string[], separator?: string): Map<string, string[]>; /** * Create a hierarchical pattern for invalidation * Useful for invalidating parent and child keys together * * @param parts Hierarchical parts of the key * @param separator The separator to use * @returns Array of patterns from most specific to least specific * * @example * createHierarchicalPatterns(['user', '123', 'posts']) * // Returns: ['user:123:posts:*', 'user:123:*', 'user:*'] */ export declare function createHierarchicalPatterns(parts: string[], separator?: string): string[]; /** * Check if a key matches any of the provided patterns * * @param key The key to check * @param patterns Array of patterns to match against * @returns true if the key matches any pattern */ export declare function matchesAnyPattern(key: string, patterns: string[]): boolean; //# sourceMappingURL=patterns.d.mts.map