UNPKG

prisma-zod-generator

Version:

Prisma 2+ generator to emit Zod schemas from your Prisma schema

105 lines (104 loc) 3.54 kB
/** * DoS Protection Utilities * * Comprehensive protection against resource exhaustion and DoS attacks * for PZG Pro features */ export interface ResourceLimits { maxFileSize: number; maxMemoryUsage: number; maxExecutionTime: number; maxIterations: number; maxRecursionDepth: number; maxArrayLength: number; maxStringLength: number; maxJSONDepth: number; maxJSONSize: number; maxConcurrentOperations: number; } export declare const DEFAULT_LIMITS: ResourceLimits; export declare class ResourceExhaustionError extends Error { readonly resourceType: string; constructor(message: string, resourceType: string); } export declare class ExecutionTimeoutError extends Error { readonly timeoutMs: number; constructor(message: string, timeoutMs: number); } /** * DoS Protection Manager */ export declare class DoSProtection { private limits; private rateLimiter; private activeOperations; private startTime; constructor(limits?: Partial<ResourceLimits>); /** * Execute operation with resource limits */ executeWithLimits<T>(operation: () => Promise<T> | T, operationName: string, customLimits?: Partial<ResourceLimits>): Promise<T>; /** * Safe JSON parsing with limits */ safeJSONParse<T = any>(jsonString: string, operationName?: string): T; /** * Safe array operation with size limits */ safeArrayOperation<T, R>(array: T[], operation: (item: T, index: number) => R, operationName: string): R[]; /** * Safe string operation with length limits */ safeStringOperation(input: string, _operationName: string): string; /** * Safe regex execution with timeout protection */ safeRegexExec(regex: RegExp, input: string, operationName: string): RegExpExecArray | null; /** * Safe file size validation */ validateFileSize(size: number, _operationName: string): void; /** * Safe loop execution with iteration limits */ safeLoop<T>(iterable: Iterable<T>, operation: (item: T, index: number) => void | Promise<void>, operationName: string): Promise<void>; /** * Get system resource usage */ getResourceUsage(): { memory: NodeJS.MemoryUsage; uptime: number; activeOperations: number; cpuUsage?: NodeJS.CpuUsage; }; /** * Reset DoS protection state */ reset(): void; private getObjectDepth; private executeWithTimeout; } /** * Global DoS protection instance */ export declare const dosProtection: DoSProtection; /** * Decorator for protecting methods against DoS */ export declare function dosProtect(operationName?: string, limits?: Partial<ResourceLimits>): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; /** * Safe array chunker to prevent memory exhaustion */ export declare function safeChunker<T>(array: T[], chunkSize: number, maxChunks?: number): Generator<T[], void, unknown>; /** * Safe map operation with limits */ export declare function safeMap<T, R>(array: T[], mapper: (item: T, index: number) => R, operationName?: string): R[]; /** * Safe filter operation with limits */ export declare function safeFilter<T>(array: T[], predicate: (item: T, index: number) => boolean, operationName?: string): T[]; /** * Safe forEach operation with limits */ export declare function safeForEach<T>(array: T[], operation: (item: T, index: number) => void | Promise<void>, operationName?: string): Promise<void>;