before-after-hook
Advanced tools
Comparing version 2.0.1 to 2.1.0
211
index.d.ts
@@ -1,135 +0,96 @@ | ||
declare module "before-after-hook" { | ||
export interface HookCollection { | ||
/** | ||
* Invoke before and after hooks. | ||
*/ | ||
(name: string | string[], method: (options: any) => Promise<any> | any): Promise<any> | ||
/** | ||
* Invoke before and after hooks. | ||
*/ | ||
(name: string | string[], method: (options: any) => Promise<any> | any, options: any): Promise<any> | ||
/** | ||
* Add before hook for given name. Returns `hook` instance for chaining. | ||
*/ | ||
before (name: string, method: (options: any) => Promise<any> | any): HookCollection | ||
/** | ||
* Add error hook for given name. Returns `hook` instance for chaining. | ||
*/ | ||
error (name: string, method: (options: any) => Promise<any> | any): HookCollection | ||
/** | ||
* Add after hook for given name. Returns `hook` instance for chaining. | ||
*/ | ||
after (name: string, method: (options: any) => Promise<any> | any): HookCollection | ||
/** | ||
* Add wrap hook for given name. Returns `hook` instance for chaining. | ||
*/ | ||
wrap (name: string, method: (options: any) => Promise<any> | any): HookCollection | ||
/** | ||
* Removes hook for given name. Returns `hook` instance for chaining. | ||
*/ | ||
remove (name: string, beforeHookMethod: (options: any) => Promise<any> | any): HookCollection | ||
} | ||
type HookMethod<O, R> = (options: O) => R | Promise<R> | ||
export interface HookSingular<T> { | ||
/** | ||
* Invoke before and after hooks without options | ||
*/ | ||
(method: (options: T) => T | null | void): Promise<T> | ||
/** | ||
* Invoke before and after hooks without options | ||
*/ | ||
(method: (options: T) => Promise<T | null | void>): Promise<T> | ||
/** | ||
* Invoke before and after hooks with options | ||
*/ | ||
(method: (options: T) => T | null | void, options: T): Promise<T> | ||
/** | ||
* Invoke before and after hooks with options | ||
*/ | ||
(method: (options: T) => Promise<T | null | void>, options: T): Promise<T> | ||
type BeforeHook<O> = (options: O) => void | ||
type ErrorHook<O, E> = (error: E, options: O) => void | ||
type AfterHook<O, R> = (result: R, options: O) => void | ||
type WrapHook<O, R> = ( | ||
hookMethod: HookMethod<O, R>, | ||
options: O | ||
) => R | Promise<R> | ||
/** | ||
* Add before hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
before( | ||
beforeFn: (options: T) => T | null | void | ||
): HookSingular<T>; | ||
/** | ||
* Add before hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
before( | ||
beforeFn: (options: T) => Promise<T | null | void> | ||
): HookSingular<T>; | ||
type AnyHook<O, R, E> = | ||
| BeforeHook<O> | ||
| ErrorHook<O, E> | ||
| AfterHook<O, R> | ||
| WrapHook<O, R> | ||
/** | ||
* Add error hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
error( | ||
errorFn: (options: T) => T | null | void | ||
): HookSingular<T>; | ||
/** | ||
* Add error hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
error( | ||
errorFn: (options: T) => Promise<T | null | void> | ||
): HookSingular<T>; | ||
export interface HookCollection { | ||
/** | ||
* Invoke before and after hooks | ||
*/ | ||
( | ||
name: string | string[], | ||
hookMethod: HookMethod<any, any>, | ||
options?: any | ||
): Promise<any> | ||
/** | ||
* Add `before` hook for given `name` | ||
*/ | ||
before(name: string, beforeHook: BeforeHook<any>): void | ||
/** | ||
* Add `error` hook for given `name` | ||
*/ | ||
error(name: string, errorHook: ErrorHook<any, any>): void | ||
/** | ||
* Add `after` hook for given `name` | ||
*/ | ||
after(name: string, afterHook: AfterHook<any, any>): void | ||
/** | ||
* Add `wrap` hook for given `name` | ||
*/ | ||
wrap(name: string, wrapHook: WrapHook<any, any>): void | ||
/** | ||
* Remove added hook for given `name` | ||
*/ | ||
remove(name: string, hook: AnyHook<any, any, any>): void | ||
} | ||
/** | ||
* Add after hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
after( | ||
afterFn: (options: T) => T | null | void | ||
): HookSingular<T>; | ||
/** | ||
* Add after hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
after( | ||
afterFn: (options: T) => Promise<T | null | void> | ||
): HookSingular<T>; | ||
export interface HookSingular<O, R, E> { | ||
/** | ||
* Invoke before and after hooks | ||
*/ | ||
(hookMethod: HookMethod<O, R>, options?: O): Promise<R> | ||
/** | ||
* Add `before` hook | ||
*/ | ||
before(beforeHook: BeforeHook<O>): void | ||
/** | ||
* Add `error` hook | ||
*/ | ||
error(errorHook: ErrorHook<O, E>): void | ||
/** | ||
* Add `after` hook | ||
*/ | ||
after(afterHook: AfterHook<O, R>): void | ||
/** | ||
* Add `wrap` hook | ||
*/ | ||
wrap(wrapHook: WrapHook<O, R>): void | ||
/** | ||
* Remove added hook | ||
*/ | ||
remove(hook: AnyHook<O, R, E>): void | ||
} | ||
/** | ||
* Add wrap hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
wrap( | ||
wrapFn: (options: T) => T | null | void | ||
): HookSingular<T>; | ||
/** | ||
* Add wrap hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
wrap( | ||
wrapFn: (options: T) => Promise<T | null | void> | ||
): HookSingular<T>; | ||
type Collection = new () => HookCollection | ||
type Singular = new <O = any, R = any, E = any>() => HookSingular<O, R, E> | ||
/** | ||
* Removes hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
remove( | ||
beforeHookMethod: (options: T) => T | null | void | ||
): HookSingular<T>; | ||
/** | ||
* Removes hook. Returns `UnnamedHook` instance for chaining. | ||
*/ | ||
remove( | ||
beforeHookMethod: (options: T) => Promise<T | null | void> | ||
): HookSingular<T>; | ||
} | ||
interface Hook { | ||
new (): HookCollection | ||
export const Hook: { | ||
new (): HookCollection | ||
/** | ||
* Creates a collection of hooks | ||
*/ | ||
Collection: Collection | ||
/** | ||
* Creates a nameless hook that allows passing down typings for the options | ||
*/ | ||
Singular: {new <T>(): HookSingular<T>} | ||
/** | ||
* Creates a nameless hook that supports strict typings | ||
*/ | ||
Singular: Singular | ||
} | ||
/** | ||
* Creates a hook collection | ||
*/ | ||
Collection: {new (): HookCollection} | ||
} | ||
export const Hook: Hook | ||
export const Collection: Collection | ||
export const Singular: Singular | ||
export const Singular: {new <T>(): HookSingular<T>} | ||
export const Collection: {new (): HookCollection} | ||
export = Hook | ||
} | ||
export default Hook |
{ | ||
"name": "before-after-hook", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "asynchronous before/error/after hooks for internal functionality", | ||
@@ -17,2 +17,3 @@ "files": [ | ||
"test": "npm run -s test:node | tap-spec", | ||
"posttest": "npm run validate:ts", | ||
"test:node": "node test", | ||
@@ -22,2 +23,4 @@ "test:watch": "gaze 'clear && node test | tap-min' 'test/**/*.js' 'index.js' 'lib/**/*.js'", | ||
"test:coverage:upload": "istanbul-coveralls", | ||
"validate:ts": "tsc --strict --target es6 index.d.ts", | ||
"postvalidate:ts": "tsc --noEmit --strict --target es6 test/typescript-validate.ts", | ||
"presemantic-release": "npm run build", | ||
@@ -51,6 +54,7 @@ "semantic-release": "semantic-release" | ||
"simple-mock": "^0.8.0", | ||
"standard": "^12.0.1", | ||
"standard": "^13.0.1", | ||
"tap-min": "^2.0.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.2.2", | ||
"typescript": "^3.5.3", | ||
"uglify-js": "^3.0.0" | ||
@@ -57,0 +61,0 @@ }, |
@@ -274,3 +274,3 @@ # before-after-hook | ||
Add before hook for given name. Returns `hookCollection` instance for chaining. | ||
Add before hook for given name. | ||
@@ -320,3 +320,3 @@ ```js | ||
Add error hook for given name. Returns `hookCollection` instance for chaining. | ||
Add error hook for given name. | ||
@@ -367,3 +367,3 @@ ```js | ||
Add after hook for given name. Returns `hook` instance for chaining. | ||
Add after hook for given name. | ||
@@ -414,3 +414,3 @@ ```js | ||
Add wrap hook for given name. Returns `hookCollection` instance for chaining. | ||
Add wrap hook for given name. | ||
@@ -475,3 +475,3 @@ ```js | ||
Removes hook for given name. Returns `hookCollection` instance for chaining. | ||
Removes hook for given name. | ||
@@ -478,0 +478,0 @@ ```js |
33143
14
210