import { combineMiddlewares } from '@marblejs/core' ; import { IxBuilder , ichainCurry } from '@marblejs/core/dist/+internal/fp/IxBuilder' ; import { HttpMiddlewareEffect , HttpEffect } from '../effects/http.effects.interface' ; import { HttpMethod } from '../http.interface' ; import { RouteEffect , RouteMeta } from './http.router.interface' ; type Ready = 'Ready' ; type Empty = 'Empty' ; type PathApplied = 'PathApplied' ; type TypeApplied = 'TypeApplied' ; type MiddlewareApplied = 'MiddlewareApplied' ; type EffectApplied = 'EffectApplied' ; type MetaApplied = 'MetaApplied' ; type RouteEffectSpec = Partial < RouteEffect > ; type Arity < A , B > = ( a : A ) => B ; const route = new IxBuilder < Ready , Empty , RouteEffectSpec > ( { } ) ; const matchPath = ( path ) => ichainCurry ( ( spec ) => new IxBuilder < Empty | MetaApplied , PathApplied , RouteEffectSpec > ( { ... spec , path } ) ) ; const matchType = ( method ) => ichainCurry ( ( spec ) => new IxBuilder < PathApplied , TypeApplied , RouteEffectSpec > ( { ... spec , method } ) ) ; const use = ( middleware ) => ichainCurry ( ( spec ) => new IxBuilder < TypeApplied | MiddlewareApplied , MiddlewareApplied , RouteEffectSpec > ( { ... spec , middleware : spec . middleware ? combineMiddlewares ( spec . middleware , middleware ) : middleware } ) ) ; const useEffect = ( effect ) => ichainCurry ( ( spec ) => new IxBuilder < TypeApplied | MiddlewareApplied , EffectApplied , RouteEffectSpec > ( { ... spec , effect } ) ) ; const applyMeta = ( meta ) => ichainCurry ( ( spec ) => new IxBuilder < EffectApplied | MetaApplied , MetaApplied , RouteEffectSpec > ( { ... spec , meta : { ... spec . meta , ... meta } , } ) ) ; function pipe < A , B > ( f1 ) ; function pipe < A , B , C > ( f1 , f2 ) ; function pipe < A , B , C , D > ( f1 , f2 , f3 ) ; function pipe < A , B , C , D , E > ( f1 , f2 , f3 , f4 ) ; function pipe < A , B , C , D , E , F > ( f1 , f2 , f3 , f4 , f5 ) ; function pipe < A , B , C , D , E , F , G > ( f1 , f2 , f3 , f4 , f5 , f6 ) ; function pipe < A , B , C , D , E , F , G , H > ( f1 , f2 , f3 , f4 , f5 , f6 , f7 ) ; function pipe < A , B , C , D , E , F , G , H , I > ( f1 , f2 , f3 , f4 , f5 , f6 , f7 , f8 ) ; function pipe < A , B , C , D , E , F , G , H , I , J > ( f1 , f2 , f3 , f4 , f5 , f6 , f7 , f8 , f9 ) ; function pipe < A , B , C , D , E , F , G , H , I , J , K > ( f1 , f2 , f3 , f4 , f5 , f6 , f7 , f8 , f9 , f10 ) ; function pipe ( ... fns ) { return fns . reduce ( ( prevFn , nextFn ) => value => nextFn ( prevFn ( value ) ) , value => value ) ( route ) . run ( ) ; } export const r = { matchPath , matchType , use , useEffect , applyMeta , pipe } ;