import { HydrationState } from './hydration/hydrator.js' export function createPipeline( skeletonFn: SkeletonFn, hydrationFn: HydrationFn, rulesFn: RulesFn, presentationFn: PresentationFn, ) { return async (params: Params, ctx: Context) => { const skeleton = await skeletonFn({ ctx, params }) const hydration = await hydrationFn({ ctx, params, skeleton }) const appliedRules = rulesFn({ ctx, params, skeleton, hydration }) return presentationFn({ ctx, params, skeleton: appliedRules, hydration }) } } export type SkeletonFn = ( input: SkeletonFnInput, ) => Promise export type SkeletonFnInput = { ctx: Context params: Params } export type HydrationFn = ( input: HydrationFnInput, ) => Promise export type HydrationFnInput = { ctx: Context params: Params skeleton: Skeleton } export type RulesFn = ( input: RulesFnInput, ) => Skeleton export type RulesFnInput = { ctx: Context params: Params skeleton: Skeleton hydration: HydrationState } export type PresentationFn = ( input: PresentationFnInput, ) => View export type PresentationFnInput = { ctx: Context params: Params skeleton: Skeleton hydration: HydrationState } export function noRules(input: { skeleton: S }) { return input.skeleton }