[READ ONLY MIRROR] Spark Social AppView Server github.com/sprksocial/server
atproto deno hono lexicon
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at b695298c5a188a4694bcb5b66e6c06f3755f79f0 50 lines 1.4 kB view raw
1import { HydrationState } from "./hydration/index.ts"; 2 3export function createPipeline<Params, Skeleton, View, Context>( 4 skeletonFn: ( 5 input: SkeletonFnInput<Context, Params>, 6 ) => Promise<Skeleton> | Skeleton, 7 hydrationFn: ( 8 input: HydrationFnInput<Context, Params, Skeleton>, 9 ) => Promise<HydrationState>, 10 rulesFn: (input: RulesFnInput<Context, Params, Skeleton>) => Skeleton, 11 presentationFn: ( 12 input: PresentationFnInput<Context, Params, Skeleton>, 13 ) => View, 14) { 15 return async (params: Params, ctx: Context) => { 16 const skeleton = await skeletonFn({ ctx, params }); 17 const hydration = await hydrationFn({ ctx, params, skeleton }); 18 const appliedRules = rulesFn({ ctx, params, skeleton, hydration }); 19 return presentationFn({ ctx, params, skeleton: appliedRules, hydration }); 20 }; 21} 22 23export type SkeletonFnInput<Context, Params> = { 24 ctx: Context; 25 params: Params; 26}; 27 28export type HydrationFnInput<Context, Params, Skeleton> = { 29 ctx: Context; 30 params: Params; 31 skeleton: Skeleton; 32}; 33 34export type RulesFnInput<Context, Params, Skeleton> = { 35 ctx: Context; 36 params: Params; 37 skeleton: Skeleton; 38 hydration: HydrationState; 39}; 40 41export type PresentationFnInput<Context, Params, Skeleton> = { 42 ctx: Context; 43 params: Params; 44 skeleton: Skeleton; 45 hydration: HydrationState; 46}; 47 48export function noRules<S>(input: { skeleton: S }) { 49 return input.skeleton; 50}