From 79e4cf422045d4a398359bbc7f9df8f9f9beb512 Mon Sep 17 00:00:00 2001 From: Junmin Liu Date: Fri, 25 Feb 2022 16:40:08 -0600 Subject: [PATCH 1/4] fix: export registerEndpoints and registerEndpoint types --- lib/typedefs.d.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/typedefs.d.ts b/lib/typedefs.d.ts index fad8f56..f723508 100644 --- a/lib/typedefs.d.ts +++ b/lib/typedefs.d.ts @@ -8,8 +8,20 @@ type BodyMethods = { stream(): ReadableStream; }; +type Callback = (...args: any[]) => void; + type FetchResponse = Promise & BodyMethods; +type Fetch = (path: string, opts?: Gofer.FetchOpts) => FetchResponse; + +type EndpointFnReturn = + | ((cb?: Callback) => FetchResponse) + | { + [key: string]: (options: any, cb?: Callback) => FetchResponse; + }; + +type EndpointFn = (fetch: Fetch) => EndpointFnReturn; + declare class Gofer { constructor( config: { [name: string]: Gofer.Opts }, @@ -23,12 +35,14 @@ declare class Gofer { defaults?: Gofer.FetchOpts, options?: Gofer.FetchOpts ): Gofer.FetchOpts; + registerEndpoint(name: string, endpointFn: EndpointFn): this; + registerEndpoints(endpoints: { [name: string]: EndpointFn }): this; clone(): this; with(opts: Gofer.Opts): this; - fetch(path: string, opts?: Gofer.FetchOpts): FetchResponse; + fetch: Fetch; get(path: string, opts?: Gofer.FetchOpts): FetchResponse; post(path: string, opts?: Gofer.FetchOpts): FetchResponse; put(path: string, opts?: Gofer.FetchOpts): FetchResponse; From dedffe6407b3fa8dba11abe92bc675d0e46b3893 Mon Sep 17 00:00:00 2001 From: Junmin Liu Date: Fri, 25 Feb 2022 17:43:57 -0600 Subject: [PATCH 2/4] fix: fixed issue of the EndpointFnReturn type --- lib/typedefs.d.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/typedefs.d.ts b/lib/typedefs.d.ts index f723508..a040469 100644 --- a/lib/typedefs.d.ts +++ b/lib/typedefs.d.ts @@ -8,16 +8,14 @@ type BodyMethods = { stream(): ReadableStream; }; -type Callback = (...args: any[]) => void; - type FetchResponse = Promise & BodyMethods; type Fetch = (path: string, opts?: Gofer.FetchOpts) => FetchResponse; type EndpointFnReturn = - | ((cb?: Callback) => FetchResponse) + | ((...args: any[]) => FetchResponse) | { - [key: string]: (options: any, cb?: Callback) => FetchResponse; + [key: string]: (...args: any[]) => FetchResponse; }; type EndpointFn = (fetch: Fetch) => EndpointFnReturn; From a4fab91ab232d75675191b39c6df3cc9044c285d Mon Sep 17 00:00:00 2001 From: Junmin Liu Date: Fri, 25 Feb 2022 17:57:39 -0600 Subject: [PATCH 3/4] fix: export type EndpointFn --- lib/typedefs.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/typedefs.d.ts b/lib/typedefs.d.ts index a040469..7fece98 100644 --- a/lib/typedefs.d.ts +++ b/lib/typedefs.d.ts @@ -18,7 +18,7 @@ type EndpointFnReturn = [key: string]: (...args: any[]) => FetchResponse; }; -type EndpointFn = (fetch: Fetch) => EndpointFnReturn; +export type EndpointFn = (fetch: Fetch) => EndpointFnReturn; declare class Gofer { constructor( From 048b8099b28167c41ed9e86fe985eafe50595949 Mon Sep 17 00:00:00 2001 From: Junmin Liu Date: Fri, 25 Feb 2022 18:01:44 -0600 Subject: [PATCH 4/4] fix: add the 3rd optional param for Fetch function --- lib/typedefs.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/typedefs.d.ts b/lib/typedefs.d.ts index 7fece98..add518e 100644 --- a/lib/typedefs.d.ts +++ b/lib/typedefs.d.ts @@ -10,7 +10,7 @@ type BodyMethods = { type FetchResponse = Promise & BodyMethods; -type Fetch = (path: string, opts?: Gofer.FetchOpts) => FetchResponse; +type Fetch = (path: string, opts?: Gofer.FetchOpts, cb?: any) => FetchResponse; type EndpointFnReturn = | ((...args: any[]) => FetchResponse)