import { SmrtCollection, SmrtCreateInput } from '@happyvertical/smrt-core'; import { Tenant } from '../models/Tenant.js'; import { TenantStatus } from '../types/index.js'; /** * Error thrown when tenant hierarchy operations fail */ export declare class TenantHierarchyError extends Error { readonly code: 'CIRCULAR_REFERENCE' | 'MAX_DEPTH_EXCEEDED' | 'PARENT_NOT_FOUND' | 'INVALID_OPERATION'; constructor(message: string, code: 'CIRCULAR_REFERENCE' | 'MAX_DEPTH_EXCEEDED' | 'PARENT_NOT_FOUND' | 'INVALID_OPERATION'); } /** * Options for creating a child tenant */ export interface CreateChildTenantOptions { name: string; slug?: string; description?: string; status?: TenantStatus; /** Override parent's cascade setting for this child. Default: true */ inheritPermissions?: boolean; /** Whether this child cascades permissions to its children. Default: true */ cascadePermissions?: boolean; } /** * Collection for managing Tenant objects with hierarchical support. * * Provides methods for: * - Basic CRUD operations * - Hierarchy management (parent/child relationships) * - Tree traversal (ancestors, descendants, siblings) * - Hierarchy path maintenance */ export declare class TenantCollection extends SmrtCollection { static readonly _itemClass: typeof Tenant; /** * Find tenants by status */ findByStatus(status: TenantStatus): Promise; /** * Find all active tenants */ findActive(): Promise; /** * Find tenant by slug */ findBySlug(slug: string): Promise; /** * Find all root tenants (tenants with no parent) */ findRoots(): Promise; /** * Find direct children of a tenant */ findChildren(parentTenantId: string): Promise; /** * Find the parent tenant of a given tenant */ findParent(tenantId: string): Promise; /** * Get all ancestors of a tenant, from immediate parent to root. * Uses the hierarchyPath for efficient lookup. */ getAncestors(tenantId: string): Promise; /** * Get all ancestors in order from root to immediate parent. * Reverse of getAncestors. */ getAncestorsFromRoot(tenantId: string): Promise; /** * Get all descendants of a tenant (all children, grandchildren, etc.) * Uses hierarchyPath prefix matching for efficient lookup. */ getDescendants(tenantId: string): Promise; /** * Get siblings of a tenant (other tenants with the same parent) */ getSiblings(tenantId: string): Promise; /** * Check if a tenant is an ancestor of another tenant */ isAncestorOf(potentialAncestorId: string, tenantId: string): Promise; /** * Check if a tenant is a descendant of another tenant */ isDescendantOf(potentialDescendantId: string, tenantId: string): Promise; /** * Create a child tenant under a parent. * Automatically sets hierarchyLevel and hierarchyPath. */ createChild(parentTenantId: string, options: CreateChildTenantOptions): Promise; /** * Move a tenant to a new parent. * Updates hierarchyLevel and hierarchyPath for the tenant and all descendants. */ moveToParent(tenantId: string, newParentId: string | null): Promise; /** * Make a tenant a root tenant (remove from hierarchy) */ makeRoot(tenantId: string): Promise; /** * Validate that a tenant hierarchy is consistent. * Returns validation errors if any. */ validateHierarchy(tenantId: string): Promise; /** * Get the full hierarchy tree starting from a tenant. * Returns a nested structure useful for UI rendering. */ getTree(rootTenantId?: string): Promise>; /** * Override create to automatically set hierarchy fields for new tenants. * Only calculates them when the caller hasn't already supplied * `hierarchyLevel`/`hierarchyPath` in the create input — an explicitly * provided value is preserved as-is. */ create(options: SmrtCreateInput): Promise; } //# sourceMappingURL=TenantCollection.d.ts.map