UNPKG

@riddance/host

Version:

76 lines (75 loc) 2.71 kB
export type Environment = { readonly [key: string]: string; }; export type Logger = { enrich(fields: object): Logger; trace(message: string, error?: unknown, fields?: object): void; debug(message: string, error?: unknown, fields?: object): void; info(message: string, error?: unknown, fields?: object): void; warn(message: string, error?: unknown, fields?: object): void; error(message: string, error?: unknown, fields?: object): void; fatal(message: string, error?: unknown, fields?: object): void; }; export type MutableJson = null | boolean | number | string | MutableJson[] | { [key: string]: MutableJson; }; export type Json = null | boolean | number | string | readonly Json[] | { readonly [key: string]: Json; }; export declare function objectSpreadable(json?: Json): { readonly [key: string]: Json; }; export declare function arraySpreadable(json?: Json): readonly Json[]; export type HandlerConfiguration = { /** * An indication of CPU usage of the handler. * @default 'low' */ readonly compute?: 'high' | 'low'; /** * An indication of memory usage of the handler. * @default 'low' */ readonly memory?: 'high' | 'low'; /** * A boolean indicating whether to enrich the log with the body of events, requests or responses. Set to false if the body is large or contain very sensitive data. * @default false */ readonly excludeBodyFromLogs?: boolean; /** * The level below which log entries will be discarded. * @default 'trace' */ readonly minimumLogLevel?: 'trace' | 'debug' | 'info' | 'warning' | 'error' | 'fatal'; /** * The number of seconds the function is expected to finish executing in. */ readonly timeout?: number; }; export type Context = { readonly env: Environment; readonly log: Logger; readonly signal: AbortSignal; now(): Date; readonly operationId?: string; readonly client?: { readonly id?: string; readonly ip?: string; readonly port?: number; readonly userAgent?: string; }; readonly meta?: { readonly packageName: string; readonly fileName: string; readonly revision?: string; }; emit(topic: string, type: string, subject: string, data?: Json, messageId?: string): void; eventBarrier(): Promise<void>; onSuccess(fn: () => Promise<void> | void): void; }; export declare function httpRequestHeaders(context: Context): { [key: string]: string; }; export declare function measure<T>(logger: { trace: (message: string, _: undefined, f: object) => void; }, name: string, fn: () => Promise<T> | T, fields?: object): Promise<T>;