From d3e78b1417db5487fbd4e690cd11ac33be557d0c Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 1 Mar 2024 15:54:13 -0500 Subject: [PATCH 1/3] add typescript types --- index.d.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..0ba3e87 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,28 @@ +export default class Kareem { + static skipWrappedFunction(): SkipWrappedFunction; + static overwriteMiddlewareResult(): OverwriteMiddlewareResult; + + pre(name: string | RegExp, fn: Function): this; + pre(name: string | RegExp, options: Record, fn: Function, error?: any, unshift?: boolean): this; + post(name: string | RegExp, fn: Function): this; + post(name: string | RegExp, options: Record, fn: Function, unshift?: boolean): this; + + clone(): this; + merge(other: Kareem, clone?: boolean): Kareem; + + createWrapper(name: string, fn: Function, context?: any, options?: any): Function; + createWrapperSync(name: string, fn: Function): Function; + hasHooks(name: string): boolean; + filter(fn: Function): Kareem; + + wrap(name: string, fn: Function, context: any, args: any[], options?: any): Function; + + execPostSync(name: string, context: any, args: any[]): any; + execPost(name: string, context: any, args: any[], options?: any, callback?: Function): void; + execPreSync(name: string, context: any, args: any[]): any; + execPre(name: string, context: any, args: any[], callback?: Function): void; +} + +class SkipWrappedFunction {} +class OverwriteMiddlewareResult {} + From 3bfa755b6a035f43022c59236ed8617a88e03d9d Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 4 Mar 2024 11:46:19 -0500 Subject: [PATCH 2/3] add declare and fix other issues with typescript types --- index.d.ts | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/index.d.ts b/index.d.ts index 0ba3e87..65855f5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,28 +1,29 @@ -export default class Kareem { - static skipWrappedFunction(): SkipWrappedFunction; - static overwriteMiddlewareResult(): OverwriteMiddlewareResult; +declare module "kareem" { + export default class Kareem { + static skipWrappedFunction(): SkipWrappedFunction; + static overwriteMiddlewareResult(): OverwriteMiddlewareResult; - pre(name: string | RegExp, fn: Function): this; - pre(name: string | RegExp, options: Record, fn: Function, error?: any, unshift?: boolean): this; - post(name: string | RegExp, fn: Function): this; - post(name: string | RegExp, options: Record, fn: Function, unshift?: boolean): this; + pre(name: string | RegExp, fn: Function): this; + pre(name: string | RegExp, options: Record, fn: Function, error?: any, unshift?: boolean): this; + post(name: string | RegExp, fn: Function): this; + post(name: string | RegExp, options: Record, fn: Function, unshift?: boolean): this; - clone(): this; - merge(other: Kareem, clone?: boolean): Kareem; + clone(): Kareem; + merge(other: Kareem, clone?: boolean): this; - createWrapper(name: string, fn: Function, context?: any, options?: any): Function; - createWrapperSync(name: string, fn: Function): Function; - hasHooks(name: string): boolean; - filter(fn: Function): Kareem; + createWrapper(name: string, fn: Function, context?: any, options?: any): Function; + createWrapperSync(name: string, fn: Function): Function; + hasHooks(name: string): boolean; + filter(fn: Function): Kareem; - wrap(name: string, fn: Function, context: any, args: any[], options?: any): Function; + wrap(name: string, fn: Function, context: any, args: any[], options?: any): Function; - execPostSync(name: string, context: any, args: any[]): any; - execPost(name: string, context: any, args: any[], options?: any, callback?: Function): void; - execPreSync(name: string, context: any, args: any[]): any; - execPre(name: string, context: any, args: any[], callback?: Function): void; -} - -class SkipWrappedFunction {} -class OverwriteMiddlewareResult {} + execPostSync(name: string, context: any, args: any[]): any; + execPost(name: string, context: any, args: any[], options?: any, callback?: Function): void; + execPreSync(name: string, context: any, args: any[]): any; + execPre(name: string, context: any, args: any[], callback?: Function): void; + } + class SkipWrappedFunction {} + class OverwriteMiddlewareResult {} +} From 20bb65256faaf9d5ebde2c265a264946bc5824af Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 4 Mar 2024 12:40:02 -0500 Subject: [PATCH 3/3] improve typings for options --- index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 65855f5..cc9247d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,15 +11,15 @@ declare module "kareem" { clone(): Kareem; merge(other: Kareem, clone?: boolean): this; - createWrapper(name: string, fn: Function, context?: any, options?: any): Function; + createWrapper(name: string, fn: Function, context?: any, options?: Record): Function; createWrapperSync(name: string, fn: Function): Function; hasHooks(name: string): boolean; filter(fn: Function): Kareem; - wrap(name: string, fn: Function, context: any, args: any[], options?: any): Function; + wrap(name: string, fn: Function, context: any, args: any[], options?: Record): Function; execPostSync(name: string, context: any, args: any[]): any; - execPost(name: string, context: any, args: any[], options?: any, callback?: Function): void; + execPost(name: string, context: any, args: any[], options?: Record, callback?: Function): void; execPreSync(name: string, context: any, args: any[]): any; execPre(name: string, context: any, args: any[], callback?: Function): void; }