From e0cd8c1609236492dd09fbf9eb265b56a418710d Mon Sep 17 00:00:00 2001 From: frogcjn Date: Fri, 24 Jun 2016 10:29:13 +0800 Subject: [PATCH 1/7] add details for hook methods --- mongoose/mongoose.d.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index ec785e4ffb..9ebcbedc48 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -269,14 +269,41 @@ declare module "mongoose" { path(path: string, constructor: any): Schema; pathType(path: string): string; plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Schema; - post(method: string, fn: Function): Schema; - pre(method: string, callback: Function): Schema; + + pre(method: string, fn: HookSyncCallback): Schema; + pre(method: string, fn: HookSyncCallback, errorCb: HookErrorCallback): Schema; + pre(method: string, isAsync: boolean, fn: HookAsyncCallback): Schema; + pre(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb: HookErrorCallback): Schema; + post(method: string, fn: HookSyncCallback): Schema; + post(method: string, fn: HookSyncCallback, errorCb: HookErrorCallback): Schema; + post(method: string, isAsync: boolean, fn: HookAsyncCallback): Schema; + post(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb: HookErrorCallback): Schema; + requiredPaths(): string[]; set(key: string, value: any): void; static(name: string, fn: Function): Schema; virtual(name: string, options?: Object): VirtualType; virtualpath(name: string): VirtualType; } + + // hook functions: https://github.com/vkarpov15/hooks-fixed + export interface HookSyncCallback { + (next: Function, ...hookArgs:any[]): any; + } + + export interface HookAsyncCallback { + (next: Function, done: Function, ...hookArgs:any[]): any; + } + + export interface HookErrorCallback { + (error: Error): any; + } + + export interface HookNextFunction { + (...hookArgs:any[]): any; + (error: Error): any; + } + export interface SchemaOption { autoIndex?: boolean; bufferCommands?: boolean; From 46098950dde8320d8521256ed38440d3427f8e8c Mon Sep 17 00:00:00 2001 From: frogcjn Date: Fri, 24 Jun 2016 10:45:53 +0800 Subject: [PATCH 2/7] add methods and statics --- mongoose/mongoose.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index 9ebcbedc48..74d3663a76 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -256,6 +256,10 @@ declare module "mongoose" { OId: Types.ObjectId; Mixed: any; }; + + methods: any; + statics: any; + constructor(schema?: Object, options?: Object); add(obj: Object, prefix?: string): void; @@ -284,6 +288,7 @@ declare module "mongoose" { static(name: string, fn: Function): Schema; virtual(name: string, options?: Object): VirtualType; virtualpath(name: string): VirtualType; + } // hook functions: https://github.com/vkarpov15/hooks-fixed From 8d887006013561328559fa513e6590cc634e889e Mon Sep 17 00:00:00 2001 From: frogcjn Date: Fri, 24 Jun 2016 10:56:29 +0800 Subject: [PATCH 3/7] fix errors in tests --- mongoose/mongoose-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoose/mongoose-tests.ts b/mongoose/mongoose-tests.ts index 2f6467437c..cd5f53c4d9 100644 --- a/mongoose/mongoose-tests.ts +++ b/mongoose/mongoose-tests.ts @@ -369,7 +369,7 @@ schema.path('name'); schema.path('name', Number); schema.pathType('name'); schema.plugin(function() {}); -schema.post('save', function(doc: IActor) {}); +schema.post('save', function(next: () => void, doc: IActor) {}); schema.pre('save', function(next: () => void) {}); schema.requiredPaths(); schema.static('findByName', function(name: string, callback: () => void) {}); From cb77aeaff243e6f0d13ae8ac4de2761ffc1a08f8 Mon Sep 17 00:00:00 2001 From: frogcjn Date: Fri, 24 Jun 2016 11:09:55 +0800 Subject: [PATCH 4/7] merge overloads for errorCb --- mongoose/mongoose.d.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index 74d3663a76..b0f3dcdacd 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -274,14 +274,10 @@ declare module "mongoose" { pathType(path: string): string; plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Schema; - pre(method: string, fn: HookSyncCallback): Schema; - pre(method: string, fn: HookSyncCallback, errorCb: HookErrorCallback): Schema; - pre(method: string, isAsync: boolean, fn: HookAsyncCallback): Schema; - pre(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb: HookErrorCallback): Schema; - post(method: string, fn: HookSyncCallback): Schema; - post(method: string, fn: HookSyncCallback, errorCb: HookErrorCallback): Schema; - post(method: string, isAsync: boolean, fn: HookAsyncCallback): Schema; - post(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb: HookErrorCallback): Schema; + pre(method: string, fn: HookSyncCallback, errorCb?: HookErrorCallback): Schema; + pre(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb?: HookErrorCallback): Schema; + post(method: string, fn: HookSyncCallback, errorCb?: HookErrorCallback): Schema; + post(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb?: HookErrorCallback): Schema; requiredPaths(): string[]; set(key: string, value: any): void; From 54b329f9da2618d55835a0f70680c7491cdc77a5 Mon Sep 17 00:00:00 2001 From: frogcjn Date: Fri, 24 Jun 2016 11:14:49 +0800 Subject: [PATCH 5/7] fix to mark HookNextFunction/HookDoneFunction --- mongoose/mongoose.d.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index b0f3dcdacd..bf9bbf64d2 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -289,11 +289,11 @@ declare module "mongoose" { // hook functions: https://github.com/vkarpov15/hooks-fixed export interface HookSyncCallback { - (next: Function, ...hookArgs:any[]): any; + (next: HookNextFunction, ...hookArgs:any[]): any; } export interface HookAsyncCallback { - (next: Function, done: Function, ...hookArgs:any[]): any; + (next: HookNextFunction, done: HookDoneFunction, ...hookArgs:any[]): any; } export interface HookErrorCallback { @@ -305,6 +305,11 @@ declare module "mongoose" { (error: Error): any; } + export interface HookDoneFunction { + (...hookArgs:any[]): any; + (error: Error): any; + } + export interface SchemaOption { autoIndex?: boolean; bufferCommands?: boolean; From a57dc402252259af32b8cf151192055ebc6980ec Mon Sep 17 00:00:00 2001 From: frogcjn Date: Fri, 24 Jun 2016 11:20:22 +0800 Subject: [PATCH 6/7] fix HookNext/HookDone --- mongoose/mongoose.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index bf9bbf64d2..8bdc14b537 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -305,7 +305,7 @@ declare module "mongoose" { (error: Error): any; } - export interface HookDoneFunction { + export interface HookDoneFunction { (...hookArgs:any[]): any; (error: Error): any; } From fc9c554c1ec02ea3da7877adb1bcd40736501ffd Mon Sep 17 00:00:00 2001 From: frogcjn Date: Fri, 24 Jun 2016 11:22:37 +0800 Subject: [PATCH 7/7] fix orders --- mongoose/mongoose.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index 8bdc14b537..6d74a0e4b1 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -289,25 +289,25 @@ declare module "mongoose" { // hook functions: https://github.com/vkarpov15/hooks-fixed export interface HookSyncCallback { - (next: HookNextFunction, ...hookArgs:any[]): any; + (next: HookNextFunction, ...hookArgs:any[]): any; } export interface HookAsyncCallback { - (next: HookNextFunction, done: HookDoneFunction, ...hookArgs:any[]): any; + (next: HookNextFunction, done: HookDoneFunction, ...hookArgs:any[]): any; } export interface HookErrorCallback { - (error: Error): any; + (error: Error): any; } export interface HookNextFunction { - (...hookArgs:any[]): any; - (error: Error): any; + (error: Error): any; + (...hookArgs:any[]): any; } export interface HookDoneFunction { - (...hookArgs:any[]): any; - (error: Error): any; + (error: Error): any; + (...hookArgs:any[]): any; } export interface SchemaOption {