/** * Multi-Tenant Store - Memory Isolation with Shared Pool (CX-008) * * Provides tenant isolation for multi-tenant deployments with: * - Per-tenant data isolation via namespace prefixing * - Opt-in shared pattern pool for cross-tenant learning * - Usage tracking and attribution * - Tenant lifecycle management */ import type { EmbeddedStore } from './embedded-store.js'; /** * Configuration for a tenant */ export interface TenantConfig { /** Unique tenant identifier */ tenantId: string; /** Whether this tenant contributes patterns to the shared pool */ sharePatterns: boolean; /** Whether this tenant consumes patterns from the shared pool */ consumeShared: boolean; /** Optional display name */ displayName?: string; /** Tenant creation timestamp */ createdAt: number; /** Last activity timestamp */ lastActiveAt: number; } /** * Default tenant configuration */ export declare const DEFAULT_TENANT_CONFIG: Omit; /** * Shared pattern metadata */ export interface SharedPattern { /** Pattern data */ data: T; /** Tenant that contributed this pattern */ contributedBy: string; /** Contribution timestamp */ contributedAt: number; /** Number of tenants using this pattern */ usageCount: number; /** Tenants that have used this pattern */ usedBy: string[]; /** Last used timestamp */ lastUsedAt: number | null; /** Pattern domain (for filtering) */ domain?: string; /** Pattern category (for organization) */ category?: string; } /** * Usage record for shared patterns */ export interface PatternUsageRecord { patternId: string; tenantId: string; usedAt: number; success: boolean; } /** * Statistics for the shared pool */ export interface SharedPoolStats { /** Total patterns in the pool */ totalPatterns: number; /** Patterns by category */ patternsByCategory: Record; /** Patterns by contributing tenant */ patternsByContributor: Record; /** Total usage count across all patterns */ totalUsageCount: number; /** Most used patterns (top 10) */ mostUsedPatterns: Array<{ patternId: string; usageCount: number; }>; /** Number of unique contributors */ uniqueContributors: number; /** Number of unique consumers */ uniqueConsumers: number; } /** * TenantStore - Wraps EmbeddedStore with tenant isolation * * All namespaces are automatically prefixed with the tenant ID * to ensure complete data isolation between tenants. */ export declare class TenantStore { private store; private tenantId; private config; private log; constructor(store: EmbeddedStore, config: TenantConfig); /** * Get the tenant-prefixed namespace */ private getNamespace; /** * Get a value from the tenant's store */ get(namespace: string, key: string): T | null; /** * Set a value in the tenant's store */ set(namespace: string, key: string, value: T): void; /** * Delete a value from the tenant's store */ delete(namespace: string, key: string): boolean; /** * Check if a key exists in the tenant's store */ has(namespace: string, key: string): boolean; /** * Get all keys in a namespace for this tenant */ keys(namespace: string): string[]; /** * Get all entries in a namespace for this tenant */ getAll(namespace: string): Map; /** * Clear all entries in a namespace for this tenant */ clear(namespace: string): void; /** * Count entries in a namespace for this tenant */ count(namespace: string): number; /** * Run operations in a transaction */ transaction(fn: () => T): T; /** * Get the tenant ID */ getTenantId(): string; /** * Get the tenant configuration */ getConfig(): TenantConfig; /** * Update tenant configuration */ updateConfig(updates: Partial>): void; /** * Check if this tenant shares patterns */ sharesPatterns(): boolean; /** * Check if this tenant consumes shared patterns */ consumesShared(): boolean; /** * Update last active timestamp */ private updateLastActive; } /** * SharedPatternPool - Manages patterns shared across tenants * * Patterns can be contributed by tenants who opt-in to sharing, * and consumed by tenants who opt-in to using shared data. */ export declare class SharedPatternPool { private store; private log; constructor(store: EmbeddedStore); /** * Contribute a pattern to the shared pool */ contributePattern(tenantId: string, patternId: string, data: T, options?: { domain?: string; category?: string; }): void; /** * Get a shared pattern by ID */ getPattern(patternId: string): SharedPattern | null; /** * Get all shared patterns */ getAllPatterns(): Map>; /** * Get shared patterns filtered by domain */ getPatternsByDomain(domain: string): Map>; /** * Get shared patterns filtered by category */ getPatternsByCategory(category: string): Map>; /** * Record pattern usage by a tenant */ recordUsage(tenantId: string, patternId: string, success?: boolean): void; /** * Remove a pattern from the shared pool */ removePattern(patternId: string): boolean; /** * Get statistics about the shared pool */ getStats(): SharedPoolStats; /** * Clear all patterns from the shared pool */ clear(): void; } /** * MultiTenantStore - Manages multiple tenant stores with shared pool * * This is the main entry point for multi-tenant storage operations. * It provides: * - Tenant lifecycle management (create, get, delete) * - Access to tenant-specific stores * - Access to the shared pattern pool * - Cross-tenant statistics */ export declare class MultiTenantStore { private store; private tenantStores; private sharedPool; private log; constructor(store: EmbeddedStore); /** * Get or create a tenant store */ getTenant(tenantId: string, options?: Partial>): TenantStore; /** * Check if a tenant exists */ hasTenant(tenantId: string): boolean; /** * Get tenant configuration without creating the tenant */ getTenantConfig(tenantId: string): TenantConfig | null; /** * Update tenant configuration */ updateTenantConfig(tenantId: string, updates: Partial>): void; /** * Delete a tenant and all its data */ deleteTenant(tenantId: string): boolean; /** * Purge all data for a tenant * This is a more thorough cleanup that removes all tenant namespaces */ purgeTenantData(tenantId: string, namespaces: string[]): void; /** * List all tenant IDs */ listTenants(): string[]; /** * Get all tenant configurations */ getAllTenantConfigs(): Map; /** * Get the shared pattern pool */ getSharedPool(): SharedPatternPool; /** * Contribute a pattern from a tenant to the shared pool * * Only works if the tenant has sharePatterns enabled */ contributeToSharedPool(tenantId: string, patternId: string, data: T, options?: { domain?: string; category?: string; }): boolean; /** * Get a pattern from the shared pool for a tenant * * Only works if the tenant has consumeShared enabled * Automatically records usage */ getFromSharedPool(tenantId: string, patternId: string): T | null; /** * Get all shared patterns available to a tenant * * Only returns patterns if the tenant has consumeShared enabled */ getAvailableSharedPatterns(tenantId: string, filter?: { domain?: string; category?: string; }): Map; /** * Get multi-tenant statistics */ getStats(): { totalTenants: number; activeTenants: number; sharingTenants: number; consumingTenants: number; sharedPool: SharedPoolStats; }; /** * Get the underlying embedded store */ getBaseStore(): EmbeddedStore; } /** * Create a default tenant ID from environment or generate one */ export declare function getDefaultTenantId(): string; /** * Namespace utilities */ export declare const TenantNamespaces: { readonly SHARED_POOL: "__shared_pool__"; readonly TENANT_REGISTRY: "__tenant_registry__"; readonly SHARED_USAGE: "__shared_usage__"; }; //# sourceMappingURL=tenant-store.d.ts.map