Skip to content

Commit

Permalink
fix: export registerEndpoints and registerEndpoint types
Browse files Browse the repository at this point in the history
  • Loading branch information
Junmin Liu committed Feb 25, 2022
1 parent 17e0fd4 commit 79e4cf4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/typedefs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@ type BodyMethods = {
stream(): ReadableStream;
};

type Callback = (...args: any[]) => void;

type FetchResponse = Promise<IncomingMessage & BodyMethods> & 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 },
Expand All @@ -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;
Expand Down

0 comments on commit 79e4cf4

Please sign in to comment.