This commit is contained in:
Vladimir Djukic
2017-08-28 13:57:04 +02:00
parent b84df2925f
commit 2242224e3c
2 changed files with 168 additions and 0 deletions

157
types/nats-hemera/index.d.ts vendored Normal file
View 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
}

View 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"
}