From b4d966ed9cd7087da9ada933be536cb1d30c10b0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 16 Dec 2025 19:07:01 -0800 Subject: [PATCH] Added compose pipe function to handle pipable type erors --- src/index.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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<