diff --git a/src/index.ts b/src/index.ts index e7cad96..7935acd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,8 @@ import { } from './lifecycle-functions'; import { AllStageKeys, + HasAllNotRequireds, + HasAllRequireds, HasAttachData, HasDoWork, HasFinalAuthorize, @@ -1393,6 +1395,25 @@ export function HTPipe(...objs: any[]) { return objs.reduce((prev: any, curr: any) => HTPipe(prev, curr), {}); } +/** + * A pipeable object is any object that has one or more lifecycle stage functions. + * This type represents the union of all possible stage configurations. + */ +type Pipeable = OptionallyHasInitPreContext & + OptionallyHasSanitizeParams & + OptionallyHasSanitizeQueryParams & + OptionallyHasSanitizeBody & + MightHavePreAuthorize & + OptionallyHasAttachData & + MightHaveFinalAuthorize & + OptionallyHasDoWork & + MightHaveRespond & + MightHaveSanitizeResponse; + +export function composePipes(...pipes: Pipeable[]): HasAllNotRequireds & HasAllRequireds { + return pipes.reduce((prev, curr) => HTPipe(prev, curr), {} as Pipeable) as HasAllNotRequireds & HasAllRequireds; +} + // left has attachData AND right has attachData AND left's return keys that exist in right's parameters are assignable to right's correspondingly export function HTPipeAttachData< TLeft extends HasAttachData<