@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
113 lines • 3.21 kB
TypeScript
/**
* @module runtime/handler-worker
* @description Handler Worker execution engine for stateless handler invocation
*/
import type { Handler } from './types/handler.js';
import type { Request } from './types/request.js';
import type { Response } from './types/response.js';
import type { GlobalContext, HealthStatus } from './types/context.js';
import { type HookOrchestratorConfig } from './hook-orchestrator.js';
/**
* Handler Worker configuration
*/
export interface HandlerWorkerConfig {
/**
* Default timeout for handler execution (milliseconds)
* @default 30000
*/
defaultTimeout?: number;
/**
* Enable metrics tracking
* @default true
*/
enableMetrics?: boolean;
/**
* Enable health check
* @default true
*/
enableHealthCheck?: boolean;
/**
* Hook orchestrator configuration
*/
orchestratorConfig?: HookOrchestratorConfig;
}
/**
* Handler Worker - Stateless execution engine for handlers
*
* @example
* ```typescript
* const worker = new HandlerWorker(gctx);
*
* worker.registerHandler('getUser', async (req, res, gctx, lctx) => {
* const user = await gctx.modules['db'].users.findById(req.params.id);
* res.json({ user });
* });
*
* await worker.executeHandler('getUser', req, res);
* ```
*/
export declare class HandlerWorker {
private handlers;
private orchestrator;
private gctx;
private config;
private startTime;
private requestCount;
private errorCount;
constructor(gctx: GlobalContext, config?: HandlerWorkerConfig);
/**
* Register a handler
*
* @param id - Unique handler identifier
* @param handler - Handler function with signature (req, res, gctx, lctx)
* @throws {Error} If handler ID is invalid, handler is not a function, or has wrong parameter count
*
* @example
* ```typescript
* worker.registerHandler('getUser', (req, res, gctx, lctx) => {
* res.json({ id: req.params.id });
* });
* ```
*/
registerHandler(id: string, handler: Handler): void;
/**
* Unregister a handler
*
* @param id - Handler identifier
* @returns true if handler was removed, false if not found
*/
unregisterHandler(id: string): boolean;
/**
* Get number of registered handlers
*
* @returns Handler count
*/
getHandlerCount(): number;
/**
* Execute a handler with stateless execution
*
* @param handlerId - Handler identifier
* @param req - Request object
* @param res - Response object
* @throws {Error} If handler not found or execution fails
*
* @example
* ```typescript
* await worker.executeHandler('getUser', req, res);
* ```
*/
executeHandler(handlerId: string, req: Request, res: Response): Promise<void>;
/**
* Get health status
*
* @returns Health status with checks
*
* @example
* ```typescript
* const status = worker.getHealthStatus();
* console.log(status.status); // 'healthy' | 'degraded' | 'unhealthy'
* ```
*/
getHealthStatus(): HealthStatus;
}
//# sourceMappingURL=handler-worker.d.ts.map