CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB Recovery Status: - Successfully recovered brainy.ts from compiled JavaScript - All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.) - Neural subsystem intact (562KB embedded patterns, NLP working) - Augmentation pipeline operational (20+ augmentations) - HNSW clustering system complete - Triple Intelligence compiled (needs constructor fix) - Test suite validates functionality Changes preserved: - 898 files with changes from last 3 days - 144,475 insertions - All augmentation improvements - All test coverage enhancements - Complete v3.0 feature set This is a LOCAL checkpoint only - contains recovered work after corruption incident. Created backup in .backups/brainy-full-20250910-151314.tar.gz Branch: recovery-checkpoint-20250910-151433 Date: Wed Sep 10 03:18:04 PM PDT 2025
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
/**
|
|
* Rate Limiting Augmentation
|
|
* Provides configurable rate limiting for Brainy operations
|
|
*/
|
|
import { BaseAugmentation } from './brainyAugmentation.js';
|
|
import { AugmentationManifest } from './manifest.js';
|
|
export interface RateLimitConfig {
|
|
enabled?: boolean;
|
|
limits?: {
|
|
searches?: number;
|
|
writes?: number;
|
|
reads?: number;
|
|
deletes?: number;
|
|
};
|
|
windowMs?: number;
|
|
skipSuccessfulRequests?: boolean;
|
|
skipFailedRequests?: boolean;
|
|
keyGenerator?: (context: any) => string;
|
|
}
|
|
/**
|
|
* Rate Limit Augmentation
|
|
*/
|
|
export declare class RateLimitAugmentation extends BaseAugmentation {
|
|
readonly name = "rateLimiter";
|
|
readonly timing: "before";
|
|
readonly metadata: "none";
|
|
operations: any;
|
|
readonly priority = 10;
|
|
readonly category: "core";
|
|
readonly description = "Provides rate limiting for Brainy operations";
|
|
private limiters;
|
|
private windowMs;
|
|
constructor(config?: RateLimitConfig);
|
|
getManifest(): AugmentationManifest;
|
|
/**
|
|
* Initialize rate limiters for each operation type
|
|
*/
|
|
private initializeLimiters;
|
|
/**
|
|
* Default key generator (could be IP, user ID, etc.)
|
|
*/
|
|
private defaultKeyGenerator;
|
|
/**
|
|
* Check if request should be rate limited
|
|
*/
|
|
private checkRateLimit;
|
|
/**
|
|
* Get remaining requests for an operation
|
|
*/
|
|
private getRemainingRequests;
|
|
/**
|
|
* Get time until reset
|
|
*/
|
|
private getResetTime;
|
|
protected onInitialize(): Promise<void>;
|
|
protected onShutdown(): Promise<void>;
|
|
/**
|
|
* Execute augmentation - apply rate limiting
|
|
*/
|
|
execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
|
|
/**
|
|
* Get rate limit statistics
|
|
*/
|
|
getStats(): {
|
|
operations: Record<string, {
|
|
activeKeys: number;
|
|
totalRequests: number;
|
|
}>;
|
|
};
|
|
/**
|
|
* Clear all rate limit entries
|
|
*/
|
|
clear(): void;
|
|
/**
|
|
* Clear expired entries (cleanup)
|
|
*/
|
|
cleanup(): void;
|
|
}
|
|
/**
|
|
* Create rate limit augmentation
|
|
*/
|
|
export declare function createRateLimitAugmentation(config?: RateLimitConfig): RateLimitAugmentation;
|