cube-ms
Version:
Production-ready microservice framework with health monitoring, validation, error handling, and Docker Swarm support
85 lines (77 loc) • 2.15 kB
TypeScript
// index.d.ts
import { Request, Response, NextFunction } from "express";
import { Logger } from "./db_logger";
import { Got } from "got";
import { WebSocket } from "ws";
export interface CreateServiceOptions {
port: number;
appName?: string;
serviceName?: string;
containerName?: string;
no_console?: boolean;
}
export interface StartJobOptions {
state: any;
loopCallback: (
state: any,
updateInterval: (interval: number) => void
) => Promise<void>;
exceptionCallback: (
error: Error,
updateInterval: (interval: number) => void
) => void;
processInterval?: number;
}
export interface Middleware {
validateApiKey: (req: Request, res: Response, next: NextFunction) => void;
validateServiceID: (req: Request, res: Response, next: NextFunction) => void;
whitelist: (req: Request, res: Response, next: NextFunction) => void;
}
export interface ConsoleLog {
start: (filters?: string[]) => Promise<void>;
stop: () => Promise<void>;
update: (filters?: string[]) => Promise<void>;
}
export interface Service {
MIDDLEWARES: Middleware;
startJob: (
state: any,
loopCallback: (
state: any,
updateInterval: (interval: number) => void
) => Promise<void>,
exceptionCallback: (
error: Error,
updateInterval: (interval: number) => void
) => void,
processInterval?: number
) => { abort: () => void };
use: (
middleware: (req: Request, res: Response, next: NextFunction) => void
) => void;
consoleLog: ConsoleLog;
addRoute: (
method: string,
path: string,
handler: (
req: Request,
res: Response,
logger: Logger,
getService: (depServiceName: string) => Got
) => void,
middlewares?: any[]
) => void;
onCommand: (callback: (command: string) => void) => void;
getService: (serviceUrl: string) => Got;
getStore: (dbUrl: string) => any;
getStream: (dbUrl: string) => any;
setupChannel: (
channelName: string,
sourceObj: any,
dbName: string,
collectionName: string,
filter: any
) => void;
logger: Logger;
}
export function CreateService(options: CreateServiceOptions): Service;