From b3cac6233a16cf87f17a28d9f808215582bc1200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Thu, 11 Mar 2021 15:23:06 +0100 Subject: [PATCH] refactor MapFunction to be more reusable --- src/types.ts | 74 +++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/src/types.ts b/src/types.ts index 73d57cf3..5d27d7e6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -54,11 +54,11 @@ type NormalizeResponse = T & { data: GetResultsType }; type DataType = "data" extends keyof T ? T["data"] : unknown; -export interface MapFunction { - ( - response: OctokitTypes.OctokitResponse>, - done: () => void - ): R[]; +export interface MapFunction< + T = OctokitTypes.OctokitResponse>, + R = unknown[] +> { + (response: T, done: () => void): R; } export type PaginationResults = T[]; @@ -74,7 +74,7 @@ export interface PaginateInterface { */ ( options: OctokitTypes.EndpointOptions, - mapFn: MapFunction + mapFn: MapFunction>, R[]> ): Promise>; /** @@ -94,10 +94,7 @@ export interface PaginateInterface { */ ( route: R, - mapFn: ( - response: PaginatingEndpoints[R]["response"], - done: () => void - ) => MR + mapFn: MapFunction ): Promise; /** @@ -110,10 +107,7 @@ export interface PaginateInterface { ( route: R, parameters: PaginatingEndpoints[R]["parameters"], - mapFn: ( - response: PaginatingEndpoints[R]["response"], - done: () => void - ) => MR + mapFn: MapFunction ): Promise; /** @@ -159,12 +153,10 @@ export interface PaginateInterface { */ ( request: R, - mapFn: ( - response: NormalizeResponse< - OctokitTypes.GetResponseTypeFromEndpointMethod - >, - done: () => void - ) => MR + mapFn: MapFunction< + NormalizeResponse>, + MR + > ): Promise; /** @@ -177,12 +169,10 @@ export interface PaginateInterface { ( request: R, parameters: Parameters[0], - mapFn: ( - response: NormalizeResponse< - OctokitTypes.GetResponseTypeFromEndpointMethod - >, - done: () => void - ) => MR + mapFn: MapFunction< + NormalizeResponse>, + MR + > ): Promise; /** @@ -276,7 +266,7 @@ export interface ComposePaginateInterface { ( octokit: Octokit, options: OctokitTypes.EndpointOptions, - mapFn: MapFunction + mapFn: MapFunction>, R[]> ): Promise>; /** @@ -301,10 +291,7 @@ export interface ComposePaginateInterface { ( octokit: Octokit, route: R, - mapFn: ( - response: PaginatingEndpoints[R]["response"], - done: () => void - ) => MR + mapFn: MapFunction ): Promise; /** @@ -319,10 +306,7 @@ export interface ComposePaginateInterface { octokit: Octokit, route: R, parameters: PaginatingEndpoints[R]["parameters"], - mapFn: ( - response: PaginatingEndpoints[R]["response"], - done: () => void - ) => MR + mapFn: MapFunction ): Promise; /** @@ -374,12 +358,10 @@ export interface ComposePaginateInterface { ( octokit: Octokit, request: R, - mapFn: ( - response: NormalizeResponse< - OctokitTypes.GetResponseTypeFromEndpointMethod - >, - done: () => void - ) => MR + mapFn: MapFunction< + NormalizeResponse>, + MR + > ): Promise; /** @@ -394,12 +376,10 @@ export interface ComposePaginateInterface { octokit: Octokit, request: R, parameters: Parameters[0], - mapFn: ( - response: NormalizeResponse< - OctokitTypes.GetResponseTypeFromEndpointMethod - >, - done: () => void - ) => MR + mapFn: MapFunction< + NormalizeResponse>, + MR + > ): Promise; /**