UNPKG

@satoshibits/cache-keys

Version:
82 lines 2.27 kB
import type { KeyBuilderOptions, ID } from './types.mjs'; /** * Fluent builder for creating complex cache keys */ export declare class CacheKeyBuilder { private parts; private options; constructor(options?: KeyBuilderOptions); /** * Create a new CacheKeyBuilder instance */ static create(options?: KeyBuilderOptions): CacheKeyBuilder; /** * Add a namespace component */ namespace(namespace: string): this; /** * Add a type component */ type(type: string): this; /** * Add an ID component */ id(id: ID): this; /** * Add a parameter with key-value format */ param(key: string, value: string | number): this; /** * Add a version component */ version(version: number): this; /** * Add a custom component */ add(component: string): this; /** * Add multiple components at once */ addAll(...components: string[]): this; /** * Build the final cache key */ build<T extends string = string>(): T; /** * Build a pattern for matching (adds wildcard at the end) */ pattern(): string; /** * Reset the builder */ reset(): this; /** * Clone the current builder state */ clone(): CacheKeyBuilder; /** * Get the current number of parts */ get length(): number; } /** * Create a cache key from a template string with replacements * * @param template Template string with placeholders like {id} * @param values Values to replace in the template * @param sanitize Whether to sanitize the values * @returns The formatted cache key * * @example * fromTemplate('user:{id}:profile', { id: '123' }) // 'user:123:profile' */ export declare function fromTemplate(template: string, values: Record<string, string | number | ID>, sanitize?: boolean): string; /** * Create a scoped key builder that always starts with specific components * * @param baseComponents Initial components for all keys * @param options Builder options * @returns A new key builder with the base components */ export declare function scopedBuilder(baseComponents: string[], options?: KeyBuilderOptions): CacheKeyBuilder; //# sourceMappingURL=builder.d.mts.map