UNPKG

@goatlab/typesense

Version:

Modern TypeScript wrapper for Typesense search engine API

58 lines (57 loc) 2.23 kB
/** * Tenant utility functions for multitenancy support */ /** * Validates and sanitizes a tenant ID for use in collection names * - Enforces allowed characters: a-zA-Z0-9_- * - Converts to lowercase to avoid case-sensitivity issues * - Enforces max length of 128 characters * * @param tenantId - Raw tenant ID to validate * @returns Sanitized tenant ID * @throws Error if tenant ID is invalid */ export declare function sanitizeTenantId(tenantId: string): string; /** * Creates a fully qualified collection name by prepending tenant ID * Format: <tenantId>__<baseCollectionName> * * @param tenantId - Sanitized tenant ID * @param baseCollectionName - Base collection name without tenant prefix * @returns Fully qualified collection name */ export declare function createFQCN(tenantId: string, baseCollectionName: string): string; /** * Extracts tenant ID and base collection name from a fully qualified collection name * * @param fqcn - Fully qualified collection name * @returns Object with tenantId and baseCollectionName, or null if not a tenant collection */ export declare function parseFQCN(fqcn: string): { tenantId: string; baseCollectionName: string; } | null; /** * Checks if a collection name is tenant-prefixed * * @param collectionName - Collection name to check * @returns True if the collection has a tenant prefix */ export declare function isTenantCollection(collectionName: string): boolean; /** * Filters collections by tenant ID * * @param collections - Array of collection names * @param tenantId - Tenant ID to filter by * @returns Collections belonging to the specified tenant */ export declare function filterCollectionsByTenant(collections: string[], tenantId: string): string[]; /** * Creates a tenant-qualified resource name for aliases, synonyms, presets, etc. * This ensures tenant isolation for all Typesense resources, not just collections * * @param tenantId - Optional tenant ID (if not provided, returns the resource name as-is) * @param resourceName - Base resource name * @returns Tenant-qualified resource name or original name */ export declare function createTenantQualifiedName(tenantId: string | undefined, resourceName: string): string;