/** * Tenant-Scoped Class Registry * * Tracks which classes are tenant-scoped and their configuration. * Used by the interceptor to determine how to handle operations. * * This registry supports two patterns: * 1. @TenantScoped() decorator + tenantId field (original pattern) * 2. @smrt({ tenantScoped: true }) in smrt-core (Issue #688 pattern) * * Both patterns are automatically recognized by the interceptor. * * @see https://github.com/happyvertical/smrt/issues/675 * @see https://github.com/happyvertical/smrt/issues/688 */ /** * Resolved tenancy configuration for a single class, as stored in the registry. * * Every field has a concrete (non-optional) value — defaults are applied by * `registerTenantScopedClass()` when the class is registered via `@TenantScoped()`. * * @see TenantScopedOptions * @see registerTenantScopedClass */ export interface TenantScopedConfig { /** * Tenancy mode for this class * - 'required': Must have tenant context for all operations * - 'optional': Works with or without tenant context * @default 'required' */ mode: 'required' | 'optional'; /** * Field name containing tenant ID * @default 'tenantId' */ field: string; /** * Auto-filter all queries by tenant * @default true */ autoFilter: boolean; /** * Auto-populate tenant ID from context on create * @default true */ autoPopulate: boolean; /** * Allow super admin bypass for this class * @default false */ allowSuperAdminBypass: boolean; } /** * Register a class as tenant-scoped with the given configuration. * * Called automatically by the `@TenantScoped()` decorator. You can also call * this directly when you cannot use decorators (e.g., third-party classes or * plain objects in tests). Defaults from `DEFAULT_CONFIG` are merged over any * omitted options. * * Calling this again for the same `className` overwrites the previous entry. * * @param className - The class's `name` property (e.g., `'Document'`). * @param config - Partial tenancy configuration; omitted fields receive defaults. * * @example * ```typescript * // Manually register a class (e.g., for testing) * registerTenantScopedClass('Document', { mode: 'optional' }); * ``` * * @see TenantScoped * @see unregisterTenantScopedClass */ export declare function registerTenantScopedClass(className: string, config?: Partial): void; /** * Remove a class from the tenant-scoped registry. * * Primarily intended for test teardown — use `clearTenantScopedRegistry()` to * reset the entire registry at once. * * @param className - The class name to remove (e.g., `'Document'`). * * @see clearTenantScopedRegistry * @see registerTenantScopedClass */ export declare function unregisterTenantScopedClass(className: string): void; /** * Retrieve the resolved tenancy configuration for a class. * * Resolution order: * 1. The class's OWN declaration — local `@TenantScoped()` registry first, then * the core `@smrt({ tenantScoped: true })` registry. * 2. STI inheritance — the nearest tenant-scoped ancestor's config (#1596). * * A class that declares its own tenancy never reaches step 2, so an explicit * child `@TenantScoped` always overrides the inherited base config. * * @param className - The class name to look up. * @returns The `TenantScopedConfig` if the class is tenant-scoped directly or * by inheritance, or `undefined` if it is not. * * @see isTenantScopedClass * @see getAllTenantScopedClasses */ export declare function getTenantScopedConfig(className: string): TenantScopedConfig | undefined; /** * Return `true` if the named class is tenant-scoped — directly (via * `@TenantScoped()` / `@smrt({ tenantScoped: true })`) or by inheriting from a * tenant-scoped STI ancestor (#1596). * * @param className - The class name to look up (e.g., `'Document'`). * @returns `true` if the class is tenant-scoped by any mechanism. * * @see getTenantScopedConfig * @see registerTenantScopedClass */ export declare function isTenantScopedClass(className: string): boolean; /** * Return a snapshot of all classes registered via `@TenantScoped()`. * * Returns a new `Map` so mutations to the returned value do not affect the * internal registry. Note that classes registered only through the core * `ObjectRegistry` (`@smrt({ tenantScoped: true })`) are **not** included in * this map. * * @returns A copy of the local tenant-scoped class registry, keyed by class name. * * @see isTenantScopedClass * @see getTenantScopedConfig */ export declare function getAllTenantScopedClasses(): Map; /** * Remove all entries from the local tenant-scoped class registry. * * Intended for test teardown via `resetTenancy()`. Does not affect * registrations held by the core `ObjectRegistry`. * * @see resetTenancy * @see unregisterTenantScopedClass */ export declare function clearTenantScopedRegistry(): void; //# sourceMappingURL=registry.d.ts.map