import type { IModule } from '@omnitron-dev/titan/nexus'; import type { EventEmitter } from '@omnitron-dev/eventemitter'; export interface IProcessOptions { name?: string; version?: string; description?: string; allMethodsPublic?: boolean; dependencies?: Record; env?: Record; cwd?: string; netron?: { port?: number | 'auto'; transport?: 'tcp' | 'unix' | 'websocket' | 'http'; host?: string; discoveryUrl?: string; }; scaling?: { min?: number; max?: number; strategy?: 'cpu' | 'memory' | 'custom'; metrics?: IScalingMetrics; }; health?: { enabled?: boolean; interval?: number; timeout?: number; retries?: number; }; startupTimeout?: number; memory?: { limit?: string; alert?: string; shared?: boolean; gc?: { interval?: number; aggressive?: boolean; }; }; security?: { isolation?: 'none' | 'vm' | 'container'; sandbox?: ISandboxOptions; permissions?: IPermissions; }; observability?: { metrics?: boolean | IMetricsOptions; tracing?: boolean | ITracingOptions; logs?: boolean | ILoggingOptions; }; cluster?: boolean | IClusterOptions; multiTenant?: boolean | IMultiTenantOptions; mesh?: IServiceMeshOptions; geo?: IGeoOptions; cost?: ICostOptions; selfHealing?: ISelfHealingOptions; debug?: IDebugOptions; execArgv?: string[]; } export interface IProcessMetadata extends IProcessOptions { target: any; isProcess: true; methods?: Map; } export interface IProcessMethodMetadata { name: string; descriptor: PropertyDescriptor; public?: boolean; rateLimit?: IRateLimitOptions; cache?: ICacheOptions; validate?: IValidationOptions; trace?: boolean; metrics?: boolean; } export interface IProcessInfo { id: string; name: string; pid?: number; status: ProcessStatus; startTime: number; endTime?: number; restartCount: number; metrics?: IProcessMetrics; health?: IHealthStatus; errors?: Error[]; } export declare enum ProcessStatus { PENDING = "pending", STARTING = "starting", RUNNING = "running", STOPPING = "stopping", STOPPED = "stopped", FAILED = "failed", CRASHED = "crashed" } export type ServiceProxy = { [K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise> : T[K] extends AsyncIterable ? AsyncIterable : never; } & IServiceProxyControl; export interface IServiceProxyControl { __processId: string; __destroy(): Promise; __getMetrics(): Promise; __getHealth(): Promise; } export interface IProcessPoolOptions { size?: number | 'auto'; strategy?: PoolStrategy; metrics?: boolean; recycleAfter?: number; maxLifetime?: number; idleTimeout?: number; warmup?: boolean; maxQueueSize?: number; requestTimeout?: number; replaceUnhealthy?: boolean; maxConcurrency?: number; spawnOptions?: Partial; spawnOptionsFactory?: (workerIndex: number) => Partial; memoryLimit?: string | number; memoryWarningThreshold?: number; heartbeat?: { enabled?: boolean; interval?: number; timeout?: number; maxMissed?: number; }; healthCheck?: { enabled?: boolean; interval?: number; unhealthyThreshold?: number; }; autoScale?: { enabled?: boolean; min?: number; max?: number; cpuThreshold?: number; targetCPU?: number; targetMemory?: number; queueThreshold?: number; checkInterval?: number; scaleDownDelay?: number; scaleUpThreshold?: number; scaleDownThreshold?: number; cooldownPeriod?: number; }; circuitBreaker?: { enabled?: boolean; threshold?: number; timeout?: number; halfOpenRequests?: number; }; } export declare enum PoolStrategy { ROUND_ROBIN = "round-robin", LEAST_LOADED = "least-loaded", LEAST_CONNECTIONS = "least-connections", WEIGHTED_ROUND_ROBIN = "weighted-round-robin", LEAST_RESPONSE_TIME = "least-response-time", IP_HASH = "ip-hash", RANDOM = "random", WEIGHTED = "weighted", ADAPTIVE = "adaptive", CONSISTENT_HASH = "consistent-hash", LATENCY = "latency", POWER_OF_TWO = "power-of-two" } export type IProcessPool = ServiceProxy & { size: number; active: number; pending: number; metrics: IPoolMetrics; scale(size: number): Promise; drain(): Promise; destroy(): Promise; getWorkerIds(): string[]; on(event: string, listener: (...args: any[]) => void): void; off(event: string, listener: (...args: any[]) => void): void; }; export interface ISupervisorOptions { strategy?: SupervisionStrategy; maxRestarts?: number; window?: number; backoff?: IBackoffOptions; } export declare enum SupervisionStrategy { ONE_FOR_ONE = "one-for-one", ONE_FOR_ALL = "one-for-all", REST_FOR_ONE = "rest-for-one", SIMPLE_ONE_FOR_ONE = "simple-one-for-one" } export interface ISupervisorChild { name: string; processClass: any; options?: IProcessOptions; critical?: boolean; pool?: IProcessPoolOptions; optional?: boolean; propertyKey?: string; shutdownTimeout?: number; } export interface ISupervisorConfig { strategy?: SupervisionStrategy; maxRestarts?: number; window?: number; backoff?: IBackoffOptions; children: ISupervisorChildConfig[]; onChildCrash?: (child: ISupervisorChild, error: Error) => Promise; } export interface ISupervisorChildConfig { name: string; process: string | (new (...args: any[]) => any); spawnOptions?: Partial; poolOptions?: IProcessPoolOptions; critical?: boolean; optional?: boolean; shutdownTimeout?: number; } export declare enum RestartDecision { RESTART = "restart", IGNORE = "ignore", ESCALATE = "escalate", SHUTDOWN = "shutdown" } export interface IWorkflowStage { name: string; handler: (...args: any[]) => Promise; parallel?: boolean; dependsOn?: string | string[]; timeout?: number; retries?: number; } export interface IWorkflowContext { id: string; stages: Map; state: any; metadata: any; } export interface IStageResult { stage: string; status: 'pending' | 'running' | 'completed' | 'failed'; result?: any; error?: Error; startTime?: number; endTime?: number; } export interface IProcessEvents { 'process:spawn': (info: IProcessInfo) => void; 'process:ready': (info: IProcessInfo) => void; 'process:crash': (info: IProcessInfo, error: Error) => void; 'process:restart': (info: IProcessInfo, attempt: number) => void; 'process:stop': (info: IProcessInfo) => void; 'pool:scale': (pool: string, oldSize: number, newSize: number) => void; 'health:change': (processId: string, health: IHealthStatus) => void; } export interface IProcessMetrics { cpu: number; memory: number; requests?: number; errors?: number; latency?: ILatencyMetrics; custom?: Record; } export interface IPoolMetrics extends IProcessMetrics { queueSize: number; activeWorkers: number; totalWorkers: number; idleWorkers?: number; healthyWorkers?: number; unhealthyWorkers?: number; totalRequests: number; successfulRequests?: number; failedRequests?: number; totalErrors?: number; avgResponseTime: number; errorRate?: number; throughput?: number; saturation?: number; } export interface ILatencyMetrics { p50: number; p75: number; p90: number; p95: number; p99: number; mean: number; } export interface IHealthStatus { status: 'healthy' | 'degraded' | 'unhealthy'; checks: IHealthCheck[]; timestamp: number; } export interface IHealthCheck { name: string; status: 'pass' | 'warn' | 'fail'; message?: string; details?: any; } export interface IScalingMetrics { cpu?: { target: number; }; memory?: { target: number; }; queueSize?: { target: number; }; responseTime?: { target: number; }; custom?: (metrics: IProcessMetrics) => boolean; } export interface ISandboxOptions { allowedModules?: string[]; timeout?: number; memory?: string; } export interface IPermissions { network?: boolean; filesystem?: 'none' | 'read-only' | 'read-write'; env?: boolean; spawn?: boolean; } export interface IMetricsOptions { enabled?: boolean; export?: 'prometheus' | 'statsd' | 'custom'; interval?: number; labels?: Record; } export interface ITracingOptions { enabled?: boolean; sampler?: number; propagator?: 'w3c' | 'jaeger' | 'zipkin'; exporter?: string; } export interface ILoggingOptions { enabled?: boolean; level?: string; format?: 'json' | 'text'; output?: 'console' | 'file' | 'remote'; } export interface IClusterOptions { nodes?: number; replication?: number; sharding?: IShardingOptions; } export interface IShardingOptions { strategy?: 'consistent-hash' | 'range' | 'custom'; replicas?: number; } export interface IMultiTenantOptions { isolation?: 'strict' | 'shared'; dataPartitioning?: boolean; } export interface IServiceMeshOptions { tracing?: boolean; metrics?: boolean; mtls?: boolean; rateLimit?: IRateLimitOptions; circuitBreaker?: ICircuitBreakerOptions; retry?: IRetryOptions; timeout?: number; bulkhead?: IBulkheadOptions; } export interface IRateLimitOptions { rps?: number; burst?: number; strategy?: 'token-bucket' | 'sliding-window' | 'fixed-window'; key?: string; } export interface ICircuitBreakerOptions { threshold?: number; timeout?: number; fallback?: string; } export interface IRetryOptions { attempts?: number; backoff?: 'exponential' | 'linear' | 'fixed'; maxDelay?: number; } export interface IBulkheadOptions { maxConcurrent?: number; maxQueue?: number; } export interface IGeoOptions { regions?: string[] | 'all'; replication?: 'active-active' | 'active-passive'; consistency?: 'strong' | 'eventual'; conflictResolution?: 'lww' | 'crdt' | 'custom'; cdn?: boolean; } export interface ICostOptions { budget?: { monthly?: number; alert?: number; }; optimization?: ICostOptimizationOptions; } export interface ICostOptimizationOptions { spotInstances?: boolean; autoScaleDown?: 'conservative' | 'balanced' | 'aggressive'; idleShutdown?: string; serverless?: boolean; } export interface ISelfHealingOptions { enabled?: boolean; ml?: boolean; playbooks?: string[]; actions?: ISelfHealAction[]; } export interface ISelfHealAction { symptoms: string[]; action: 'restart' | 'scale' | 'migrate' | 'custom'; cooldown?: string; handler?: () => Promise; } export interface IDebugOptions { recordState?: boolean; maxSnapshots?: number; breakpoints?: boolean; profiling?: boolean; } export interface ICacheOptions { ttl?: number; key?: string | ((args: any[]) => string); condition?: (result: any) => boolean; } export interface IValidationOptions { schema?: any; validator?: (value: any) => boolean | Promise; } export interface IBackoffOptions { type?: 'exponential' | 'linear' | 'fixed'; initial?: number; max?: number; factor?: number; } export interface IProcessManager extends EventEmitter { spawn(processPathOrClass: string | (new (...args: any[]) => T), options?: IProcessOptions): Promise>; pool(processPathOrClass: string | (new (...args: any[]) => T), options?: IProcessPoolOptions): Promise>; discover(serviceName: string): Promise | null>; workflow(WorkflowPathOrClass: string | (new () => T)): Promise; supervisor(classOrConfig: (new () => any) | ISupervisorConfig, options?: ISupervisorOptions): Promise; createSupervisor(classOrConfig: (new () => any) | ISupervisorConfig, options?: ISupervisorOptions): any; getProcess(processId: string): IProcessInfo | undefined; listProcesses(): IProcessInfo[]; kill(processId: string, signal?: string): Promise; getMetrics(processId: string): Promise; getHealth(processId: string): Promise; getWorkerHandle(processId: string): IWorkerHandle | undefined; shutdown(options?: { timeout?: number; force?: boolean; }): Promise; } export interface IProcessSpawner { spawn(processPathOrClass: string | (new (...args: any[]) => T), options?: ISpawnOptions): Promise; cleanup?(): Promise; } export interface IWorkerExitInfo { workerId: string; serviceName: string; code: number | null; signal: NodeJS.Signals | null; expected: boolean; } export interface IWorkerHandle { id: string; transportUrl: string; serviceName: string; serviceVersion: string; pid?: number; terminate(): Promise; isAlive(): boolean; send?(message: any): Promise; onMessage?(handler: (data: any) => void): void; onLog?(handler: (line: string, stream: 'stdout' | 'stderr') => void): void; onExit?(handler: (info: IWorkerExitInfo) => void): () => void; status?: ProcessStatus; proxy?: any; worker?: any; netronClient?: any; } export interface ISpawnOptions { processId?: string; name?: string; version?: string; config?: any; dependencies?: Record; env?: Record; discovery?: { enabled?: boolean; }; transport?: 'tcp' | 'unix' | 'ws'; host?: string; isolation?: 'none' | 'vm' | 'container'; execArgv?: string[]; startupTimeout?: number; } export interface IProcessManagerConfig { isolation?: 'none' | 'worker' | 'child'; transport?: 'unix' | 'tcp' | 'ws'; restartPolicy?: IRestartPolicy; livenessSweepIntervalMs?: number; resources?: { maxMemory?: string; maxCpu?: number; timeout?: number; }; monitoring?: { healthCheck?: boolean | { interval?: number; timeout?: number; }; metrics?: boolean; tracing?: boolean; }; testing?: { useMockSpawner?: boolean; }; handleSignals?: boolean; advanced?: { tempDir?: string; gracefulShutdownTimeout?: number; }; } export interface IRestartPolicy { enabled?: boolean; maxRestarts?: number; window?: number; delay?: number; backoff?: IBackoffOptions; } export interface IProcessManagerModule extends IModule { getManager(): IProcessManager; } //# sourceMappingURL=types.d.ts.map