mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-30 10:35:22 +08:00
Add typing for https://github.com/hemerajs/hemera
This commit is contained in:
157
types/nats-hemera/index.d.ts
vendored
Normal file
157
types/nats-hemera/index.d.ts
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
declare module "nats-hemera" {
|
||||
type LogLevel =
|
||||
'fatal' |
|
||||
'error' |
|
||||
'warn' |
|
||||
'info' |
|
||||
'debug' |
|
||||
'trace' |
|
||||
'silent'
|
||||
|
||||
interface ErrioConfig {
|
||||
recursive?: boolean;
|
||||
inherited?: boolean;
|
||||
stack?: boolean;
|
||||
private?: boolean;
|
||||
exclude?: Array<string>;
|
||||
include?: Array<string>;
|
||||
}
|
||||
|
||||
interface BloomrunConfig {
|
||||
indexing: 'insertion' | 'depth';
|
||||
lookupBeforeAdd: boolean;
|
||||
}
|
||||
|
||||
interface Config {
|
||||
timeout?: number;
|
||||
pluginTimeout?: number;
|
||||
tag?: string;
|
||||
prettyLog?: boolean;
|
||||
name?: string;
|
||||
crashOnFatal?: boolean;
|
||||
logLevel?: LogLevel;
|
||||
childLogger?: boolean;
|
||||
maxRecursion?: number;
|
||||
logger?: any;
|
||||
errio?: ErrioConfig;
|
||||
bloomrun?: BloomrunConfig;
|
||||
load?: LoadConfig;
|
||||
circuitBreaker?: CircuitBreakerConfig;
|
||||
}
|
||||
|
||||
interface CircuitBreakerConfig {
|
||||
enabled?: boolean;
|
||||
minSuccesses?: number;
|
||||
halfOpenTime?: number;
|
||||
resetIntervalTime?: number;
|
||||
maxFailures?: number;
|
||||
}
|
||||
|
||||
interface LoadConfig {
|
||||
checkPolicy?: boolean;
|
||||
shouldCrash?: boolean;
|
||||
process?: LoadProcessConfig;
|
||||
policy?: LoadPolicyConfig;
|
||||
}
|
||||
|
||||
interface LoadPolicyConfig {
|
||||
maxHeapUsedBytes?: number;
|
||||
maxRssBytes?: number;
|
||||
maxEventLoopDelay?: number;
|
||||
}
|
||||
|
||||
|
||||
interface LoadProcessConfig {
|
||||
sampleInterval?: number;
|
||||
}
|
||||
|
||||
|
||||
interface Hemera {
|
||||
(transport: object, ): CB;
|
||||
}
|
||||
|
||||
interface Pattern {
|
||||
topic: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
type ClientResult = any;
|
||||
|
||||
type ActHandler = (this: Hemera, error: Error, response: ClientResult) => void;
|
||||
|
||||
interface PluginDefinitionAttributes {
|
||||
name: string;
|
||||
description: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
interface PluginDefinition {
|
||||
register: Function;
|
||||
attributes: PluginDefinitionAttributes;
|
||||
options: any;
|
||||
parentPluginName: string;
|
||||
}
|
||||
|
||||
interface AddMeta {
|
||||
schema: any;
|
||||
pattern: Pattern;
|
||||
action: Function;
|
||||
plugin: PluginDefinition;
|
||||
use(handler: AddMetaMiddleware): AddMeta;
|
||||
end(cb: Function): void;
|
||||
}
|
||||
|
||||
type AddMetaMiddleware = (request: ServerRequest, response: ServerResponse, next: Function) => void;
|
||||
|
||||
interface ServerRequest {
|
||||
payload: any;
|
||||
error: any;
|
||||
locals: any;
|
||||
}
|
||||
|
||||
interface ServerResponse {
|
||||
payload: any;
|
||||
error: any;
|
||||
}
|
||||
|
||||
type AddHandler = (this: Hemera, request: Pattern, reply?: any) => void;
|
||||
|
||||
type HemeraEvents =
|
||||
'error' |
|
||||
'clientPreRequest' |
|
||||
'clientPostRequest' |
|
||||
'serverPreHandler' |
|
||||
'serverPreRequest' |
|
||||
'serverPreResponse'
|
||||
|
||||
type ExtensionType =
|
||||
'onClientPreRequest' |
|
||||
'onClientPostRequest' |
|
||||
'onServerPreHandler' |
|
||||
'onServerPreRequest' |
|
||||
'onServerPreResponse'
|
||||
|
||||
type ExtensionHandler = (ctx: Hemera, request: any, response: any, next?: ExtensionNextHandler) => void;
|
||||
type ExtensionNextHandler = (error: Error) => void;
|
||||
|
||||
interface CB {
|
||||
ready(callback: Function): void;
|
||||
act(pattern: string | Pattern, handler?: ActHandler): Promise<any>;
|
||||
add(pattern: string | Pattern, handler: AddHandler): AddMeta;
|
||||
use(params: PluginDefinition, options?: any): void;
|
||||
createError(name: string): any;
|
||||
decorate(prop: string, value: any): void;
|
||||
remove(topic: string, maxMessages: number): boolean;
|
||||
list(Pattern: any, options: any): any;
|
||||
close(callback?: Function): void;
|
||||
fatal(): void;
|
||||
expose(key: string, object: any): void;
|
||||
ext(type: ExtensionType, handler: ExtensionHandler): void;
|
||||
setConfig(key: string, value: any): void;
|
||||
setOption(key: string, value: any): void;
|
||||
on(event: HemeraEvents, handler: Function): any;
|
||||
removeAll(): any;
|
||||
}
|
||||
|
||||
export const Hemera: Hemera
|
||||
}
|
||||
11
types/nats-hemera/package.json
Normal file
11
types/nats-hemera/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "nats-hemera",
|
||||
"version": "1.0.0",
|
||||
"description": "typing typescript nats hemera",
|
||||
"main": "index.d.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Vladimir Djukic",
|
||||
"license": "ISC"
|
||||
}
|
||||
Reference in New Issue
Block a user