import { HttpMethod } from '../types'; import { GeneratedEndpoint, OpenAPIDocument, OpenAPIInfo, OpenAPIServer, JSONSchemaLike } from './api-generator'; import { RBACIntegration, RBACCheckResult, PermissionCheckContext } from './rbac-integration'; /** * Registry event types */ export type RegistryEventType = 'endpoint_registered' | 'endpoint_unregistered' | 'endpoint_updated' | 'batch_registered' | 'registry_cleared' | 'access_checked'; /** * Registry event */ export interface RegistryEvent { /** Event type */ readonly type: RegistryEventType; /** Event timestamp */ readonly timestamp: number; /** Event payload */ readonly payload: RegistryEventPayload; } /** * Registry event payload */ export type RegistryEventPayload = { endpoint: GeneratedEndpoint; } | { endpointId: string; } | { endpoints: GeneratedEndpoint[]; } | { endpointId: string; userId: string; result: RBACCheckResult; } | Record; /** * Registry event listener */ export type RegistryListener = (event: RegistryEvent) => void; /** * Path matcher for URL routing */ export interface PathMatcher { /** Original path pattern */ readonly pattern: string; /** Compiled regex */ readonly regex: RegExp; /** Parameter names in order */ readonly paramNames: readonly string[]; /** Static prefix for fast filtering */ readonly staticPrefix: string; /** Number of segments */ readonly segmentCount: number; } /** * Path match result */ export interface PathMatchResult { /** Whether path matched */ readonly matched: boolean; /** Extracted parameters */ readonly params: Record; /** Match score (higher = better match) */ readonly score: number; } /** * Endpoint lookup result */ export interface EndpointLookupResult { /** Found endpoint */ readonly endpoint: GeneratedEndpoint; /** Extracted path parameters */ readonly params: Record; /** Match score */ readonly score: number; } /** * Registry configuration */ export interface EndpointRegistryConfig { /** RBAC integration for access control */ readonly rbacIntegration?: RBACIntegration; /** Enable path matching cache */ readonly enablePathCache: boolean; /** Path cache TTL in milliseconds */ readonly pathCacheTtl: number; /** Maximum cache size */ readonly maxCacheSize: number; /** Enable event emission */ readonly enableEvents: boolean; /** Case sensitive path matching */ readonly caseSensitive: boolean; /** Strict trailing slash matching */ readonly strictTrailingSlash: boolean; } /** * Default registry configuration */ export declare const DEFAULT_REGISTRY_CONFIG: EndpointRegistryConfig; /** * Registry statistics */ export interface RegistryStats { /** Total registered endpoints */ readonly totalEndpoints: number; /** Endpoints by HTTP method */ readonly byMethod: Record; /** Endpoints by tag */ readonly byTag: Record; /** Public endpoints */ readonly publicEndpoints: number; /** Protected endpoints */ readonly protectedEndpoints: number; /** Path cache size */ readonly pathCacheSize: number; /** Last update timestamp */ readonly lastUpdated: number | null; } /** * Compile path pattern to regex */ export declare function compilePath(pattern: string): PathMatcher; /** * Match path against pattern */ export declare function matchPath(path: string, matcher: PathMatcher, caseSensitive?: boolean): PathMatchResult; /** * Centralized API endpoint registry */ export declare class EndpointRegistry { private readonly config; private readonly endpoints; private readonly pathMatchers; private readonly pathCache; private readonly listeners; private lastUpdated; constructor(config?: Partial); /** * Get endpoint count */ get size(): number; /** * Register an endpoint */ register(endpoint: GeneratedEndpoint): void; /** * Register multiple endpoints */ registerBatch(endpoints: GeneratedEndpoint[]): void; /** * Unregister an endpoint */ unregister(endpointId: string): boolean; /** * Update an endpoint */ update(endpoint: GeneratedEndpoint): boolean; /** * Clear all endpoints */ clear(): void; /** * Get endpoint by ID */ getById(id: string): GeneratedEndpoint | undefined; /** * Get endpoint by path and method */ getByPath(path: string, method: HttpMethod): EndpointLookupResult | undefined; /** * Get all endpoints for a path (all methods) */ getByPathAllMethods(path: string): EndpointLookupResult[]; /** * Get endpoints by resource name */ getByResource(resource: string): GeneratedEndpoint[]; /** * Get endpoints by tag */ getByTag(tag: string): GeneratedEndpoint[]; /** * Get all endpoints */ getAll(): GeneratedEndpoint[]; /** * Get all endpoint IDs */ getAllIds(): string[]; /** * Check if endpoint exists */ has(id: string): boolean; /** * Check access to endpoint */ checkAccess(endpointId: string, user: unknown | undefined, context?: PermissionCheckContext): Promise; /** * Check access by path and method */ checkAccessByPath(path: string, method: HttpMethod, user: unknown | undefined): Promise; }>; /** * Get required permissions for endpoint */ getRequiredPermissions(endpointId: string): readonly string[]; /** * Get required roles for endpoint */ getRequiredRoles(endpointId: string): readonly string[]; /** * Generate OpenAPI specification */ generateOpenAPISpec(info: OpenAPIInfo, servers?: readonly OpenAPIServer[]): OpenAPIDocument; /** * Get schema for endpoint */ getSchemaForEndpoint(endpointId: string): { request?: JSONSchemaLike; response?: JSONSchemaLike; } | undefined; /** * Subscribe to registry events */ subscribe(listener: RegistryListener): () => void; /** * Get registry statistics */ getStats(): RegistryStats; /** * Iterate over endpoints */ [Symbol.iterator](): Iterator; /** * Iterate over endpoint entries */ entries(): IterableIterator<[string, GeneratedEndpoint]>; /** * Iterate over endpoint IDs */ keys(): IterableIterator; /** * Iterate over endpoints */ values(): IterableIterator; /** * ForEach over endpoints */ forEach(callback: (endpoint: GeneratedEndpoint, id: string) => void): void; /** * Emit registry event */ private emit; /** * Get endpoint key for path matcher storage */ private getEndpointKey; /** * Invalidate path cache entries matching pattern */ private invalidatePathCache; /** * Quick check if path might match pattern */ private pathMightMatch; /** * Prune cache if it exceeds max size */ private pruneCache; } /** * Create endpoint registry instance */ export declare function createEndpointRegistry(config?: Partial): EndpointRegistry; export declare function getGlobalRegistry(): EndpointRegistry; export declare function setGlobalRegistry(registry: EndpointRegistry): void; export declare function clearGlobalRegistry(): void; /** * Filter endpoints by predicate */ export declare function filterEndpoints(registry: EndpointRegistry, predicate: (endpoint: GeneratedEndpoint) => boolean): GeneratedEndpoint[]; /** * Find endpoint by predicate */ export declare function findEndpoint(registry: EndpointRegistry, predicate: (endpoint: GeneratedEndpoint) => boolean): GeneratedEndpoint | undefined; /** * Group endpoints by custom key */ export declare function groupEndpointsBy(registry: EndpointRegistry, keyFn: (endpoint: GeneratedEndpoint) => K): Record; /** * Sort endpoints by custom comparator */ export declare function sortEndpoints(registry: EndpointRegistry, compareFn: (a: GeneratedEndpoint, b: GeneratedEndpoint) => number): GeneratedEndpoint[]; /** * Get allowed methods for path */ export declare function getAllowedMethods(registry: EndpointRegistry, path: string): HttpMethod[]; /** * Check if path exists in registry */ export declare function pathExists(registry: EndpointRegistry, path: string): boolean; /** * Type guard for EndpointLookupResult */ export declare function isEndpointLookupResult(value: unknown): value is EndpointLookupResult; /** * Type guard for PathMatcher */ export declare function isPathMatcher(value: unknown): value is PathMatcher; /** * Type guard for RegistryEvent */ export declare function isRegistryEvent(value: unknown): value is RegistryEvent; /** * Hot reload handler for development */ export interface HotReloadHandler { /** Handle added endpoints */ onAdded: (endpoints: GeneratedEndpoint[]) => void; /** Handle removed endpoints */ onRemoved: (endpointIds: string[]) => void; /** Handle updated endpoints */ onUpdated: (endpoints: GeneratedEndpoint[]) => void; } /** * Create hot reload integration */ export declare function createHotReloadIntegration(registry: EndpointRegistry, handler?: Partial): () => void; /** * Diff two sets of endpoints for hot reload */ export declare function diffEndpoints(oldEndpoints: GeneratedEndpoint[], newEndpoints: GeneratedEndpoint[]): { added: GeneratedEndpoint[]; removed: GeneratedEndpoint[]; updated: GeneratedEndpoint[]; }; /** * Apply diff to registry */ export declare function applyEndpointDiff(registry: EndpointRegistry, diff: { added: GeneratedEndpoint[]; removed: GeneratedEndpoint[]; updated: GeneratedEndpoint[]; }): void;