UNPKG

@noony-serverless/core

Version:

A Middy base framework compatible with Firebase and GCP Cloud Functions with TypeScript

101 lines 3.96 kB
/** * Plain Permission Resolver * * Fastest permission resolver using direct O(1) set membership checks. * Optimized for high-performance scenarios where sub-millisecond permission * checks are critical. No pattern matching or complex logic - just pure * set-based lookups for maximum speed. * * Use Cases: * - High-traffic API endpoints requiring maximum performance * - Simple permission models without wildcards or expressions * - Scenarios where all required permissions are known at compile time * - Serverless functions with strict latency requirements * * Performance Characteristics: * - Time Complexity: O(1) for permission lookup * - Space Complexity: O(n) where n is the number of user permissions * - Cache Utilization: None (no caching needed due to speed) * - Memory Footprint: Minimal (uses JavaScript Set) * * @author Noony Framework Team * @version 1.0.0 */ import { PermissionResolver, PermissionResolverType, PerformanceCharacteristics, PermissionCheckResult } from './PermissionResolver'; /** * Plain permission resolver for direct O(1) permission checks * * This resolver performs the simplest and fastest permission checks by * using JavaScript Set's has() method for O(1) membership testing. * It checks if the user has ANY of the required permissions (OR logic). */ export declare class PlainPermissionResolver extends PermissionResolver<string[]> { private checkCount; private totalResolutionTimeUs; /** * Check if user has any of the required permissions * * Uses OR logic: user needs only ONE of the required permissions * to pass the check. This is the most common permission pattern. * * @param userPermissions - Set of user's permissions for O(1) lookup * @param requiredPermissions - Array of required permissions (OR logic) * @returns Promise resolving to true if user has any required permission */ check(userPermissions: Set<string>, requiredPermissions: string[]): Promise<boolean>; /** * Check permissions with detailed result information * * Provides additional metadata about the permission check for * debugging, monitoring, and audit purposes. * * @param userPermissions - Set of user's permissions * @param requiredPermissions - Array of required permissions * @returns Detailed permission check result */ checkWithResult(userPermissions: Set<string>, requiredPermissions: string[]): Promise<PermissionCheckResult>; /** * Check if user has ALL required permissions (AND logic) * * Alternative method for scenarios requiring ALL permissions * instead of ANY permission. Less commonly used but available * for completeness. * * @param userPermissions - Set of user's permissions * @param requiredPermissions - Array of ALL required permissions * @returns Promise resolving to true if user has ALL permissions */ checkAllRequired(userPermissions: Set<string>, requiredPermissions: string[]): Promise<boolean>; /** * Get resolver type for identification */ getType(): PermissionResolverType; /** * Get performance characteristics for monitoring */ getPerformanceCharacteristics(): PerformanceCharacteristics; /** * Get performance statistics for monitoring */ getStats(): { checkCount: number; averageResolutionTimeUs: number; totalResolutionTimeUs: number; }; /** * Reset performance statistics */ resetStats(): void; /** * Get resolver name for debugging */ getName(): string; /** * Check if this resolver can handle the given requirement type * * @param requirement - The requirement to check * @returns true if this resolver can handle the requirement */ canHandle(requirement: any): requirement is string[]; } //# sourceMappingURL=PlainPermissionResolver.d.ts.map