UNPKG

@yihuangdb/storage-object

Version:

A Node.js storage object layer library using Redis OM

225 lines 6.51 kB
/** * Redis Key Patterns Documentation * * This module documents all Redis key patterns used by the StorageObject library. * It serves as the single source of truth for Redis key naming conventions. */ /** * Core Redis key patterns used by StorageObject */ export declare const REDIS_KEY_PATTERNS: { /** * Main entity storage patterns * Format: {entityName}:{entityId} * Example: User:123, Product:abc-def * Type: JSON or Hash */ readonly ENTITY_DATA: "{entityName}:{entityId}"; /** * Entity with custom prefix * Format: {prefix}:{entityName}:{entityId} * Example: app:User:123, tenant1:Product:abc */ readonly ENTITY_DATA_WITH_PREFIX: "{prefix}:{entityName}:{entityId}"; /** * RediSearch index definition * Format: idx:{entityName} * Example: idx:User, idx:Product * Type: RediSearch Index */ readonly INDEX_DEFINITION: "idx:{entityName}"; /** * RediSearch index data * Format: idx:{entityName}:{field} * Example: idx:User:email, idx:Product:category * Type: Various (Set, Sorted Set, etc.) */ readonly INDEX_DATA: "idx:{entityName}:{field}"; /** * Field-level indexes (Redis OM specific) * Format: {entityName}#{field}:{value} * Example: User#email:john@example.com * Type: String (points to entity ID) */ readonly FIELD_INDEX: "{entityName}#{field}:{value}"; /** * Full-text search index * Format: ft:{entityName} * Example: ft:Article, ft:Product * Type: RediSearch FT Index */ readonly FT_INDEX: "ft:{entityName}"; /** * Full-text search data * Format: ft:{entityName}:{component} * Example: ft:Article:doc, ft:Product:terms */ readonly FT_INDEX_DATA: "ft:{entityName}:{component}"; /** * Alternative FT format (legacy) * Format: ft.{entityName} * Example: ft.Article, ft.Product */ readonly FT_INDEX_ALT: "ft.{entityName}"; /** * Schema metadata hash * Format: schema:{entityName} * Example: schema:User, schema:Product * Type: Hash * Fields: version, fields, indexes, dataStructure, entityCount, etc. */ readonly SCHEMA_METADATA: "schema:{entityName}"; /** * HyperLogLog for entity counting * Format: schema:{entityName}:hll * Example: schema:User:hll * Type: HyperLogLog * Purpose: Efficient approximate counting */ readonly SCHEMA_HLL: "schema:{entityName}:hll"; /** * Version history sorted set * Format: schema:{entityName}:versions * Example: schema:User:versions * Type: Sorted Set * Score: Timestamp, Value: v{version}:{reason} */ readonly SCHEMA_VERSIONS: "schema:{entityName}:versions"; /** * Redis OM metadata * Format: RedisOM:{entityName}:{type} * Example: RedisOM:User:Schema, RedisOM:User:DataStructure * Type: String/Hash */ readonly REDIS_OM_METADATA: "RedisOM:{entityName}:{type}"; /** * Custom metadata * Format: _meta:{entityName}:{key} * Example: _meta:User:config, _meta:Product:settings */ readonly CUSTOM_METADATA: "_meta:{entityName}:{key}"; /** * Schema registry * Format: registry:schemas * Type: Hash * Fields: {schemaName} -> version */ readonly REGISTRY_SCHEMAS: "registry:schemas"; /** * Registry metadata * Format: registry:metadata * Type: Hash */ readonly REGISTRY_METADATA: "registry:metadata"; /** * Temporary keys * Format: _tmp:{entityName}:{id} * Example: _tmp:User:import-123 * Type: Various (auto-expire) */ readonly TEMPORARY: "_tmp:{entityName}:{id}"; /** * Lock keys (not currently used - using WATCH/MULTI/EXEC instead) * Format: _lock:{entityName}:{resource} * Example: _lock:User:schema-update */ readonly LOCK: "_lock:{entityName}:{resource}"; /** * Batch operation tracking * Format: batch:{operationId} * Example: batch:import-2024-01-01 */ readonly BATCH_OPERATION: "batch:{operationId}"; /** * Rollback data * Format: rollback:{operationId}:{entityId} * Example: rollback:update-123:user-456 */ readonly ROLLBACK_DATA: "rollback:{operationId}:{entityId}"; }; /** * Pattern categories for documentation */ export declare enum PatternCategory { ENTITY = "Entity Data", INDEX = "Indexes", SEARCH = "Full-Text Search", SCHEMA = "Schema Versioning", METADATA = "Metadata", REGISTRY = "Registry", TEMPORARY = "Temporary", BATCH = "Batch Operations" } /** * Pattern documentation with examples */ export interface PatternDoc { pattern: string; category: PatternCategory; description: string; example: string; redisType: string; notes?: string; } /** * Complete pattern documentation */ export declare const PATTERN_DOCUMENTATION: PatternDoc[]; /** * Utility class for pattern operations */ export declare class RedisPatternUtils { /** * Generate actual key from pattern */ static generateKey(pattern: string, params: Record<string, string>): string; /** * Extract parameters from key using pattern */ static extractParams(key: string, pattern: string): Record<string, string> | null; /** * Check if key matches pattern */ static matchesPattern(key: string, pattern: string): boolean; /** * Get all patterns for an entity */ static getEntityPatterns(entityName: string, prefix?: string): string[]; /** * Categorize a key */ static categorizeKey(key: string): PatternCategory | null; /** * Generate pattern documentation as markdown */ static generateDocumentation(): string; } /** * Pattern validator for runtime checks */ export declare class PatternValidator { /** * Validate that a key follows naming conventions */ static validateKey(key: string): { valid: boolean; pattern?: string; error?: string; }; /** * Validate a set of keys */ static validateKeys(keys: string[]): { valid: string[]; invalid: Array<{ key: string; error: string; }>; stats: Record<string, number>; }; } /** * Export all patterns as a flat list for scanning */ export declare function getAllPatterns(entityName?: string): string[]; //# sourceMappingURL=redis-patterns.d.ts.map