Something went wrong. Try again.
[READ ONLY MIRROR] Spark Social AppView Server github.com/sprksocial/server
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105import { mapDefined } from "@atp/common";import { Server } from "@atp/xrpc-server";
import { AppContext } from "../../../../context.ts";import { HydrateCtx, Hydrator } from "../../../../hydration/index.ts";import { $Params } from "../../../../lex/so/sprk/graph/getBlocks.ts";import * as so from "../../../../lex/so.ts";import { createPipeline, HydrationFnInput, mapSkeletonList, PresentationFnInput, SkeletonFnInput,} from "../../../../pipeline.ts";import { Views } from "../../../../views/index.ts";import { clearlyBadCursor, createHydrateCtxFromAuth, resHeaders,} from "../../../util.ts";
export default function (server: Server, ctx: AppContext) { const getBlocks = createPipeline({ skeleton, hydration, presentation, }); server.add(so.sprk.graph.getBlocks, { auth: ctx.authVerifier.standard, handler: async ({ params, auth, req }) => { const viewer = auth.credentials.iss; const hydrateCtx = await createHydrateCtxFromAuth( ctx, req, auth, { viewer }, ); const result = await getBlocks( { ...params, hydrateCtx: hydrateCtx.copy({ viewer }) }, ctx, ); return { encoding: "application/json", body: result, headers: resHeaders({ labelers: hydrateCtx.labelers }), }; }, });}
const skeleton = async (input: SkeletonFnInput<Context, Params>) => { const { params, ctx } = input; if (clearlyBadCursor(params.cursor)) { return { blockedDids: [] }; } const { blockUris, cursor } = await ctx.hydrator.dataplane.blocks.getBlocks( params.hydrateCtx.viewer, params.limit, params.cursor, ); const blocks = await ctx.hydrator.graph.getBlocks(blockUris); const blockedDids = mapDefined( blockUris, (uri) => blocks.get(uri)?.record.subject, ); return { blockedDids, cursor: cursor || undefined, };};
const hydration = ( input: HydrationFnInput<Context, Params, SkeletonState>,) => { const { ctx, params, skeleton } = input; return ctx.hydrator.hydrateProfiles(skeleton.blockedDids, params.hydrateCtx);};
const presentation = ( input: PresentationFnInput<Context, Params, SkeletonState>,) => { const { ctx, hydration, skeleton } = input; const { cursor } = skeleton; const blocks = mapSkeletonList( skeleton, "blockedDids", (did) => ctx.views.profile(did, hydration), ); return { blocks, cursor };};
type Context = { hydrator: Hydrator; views: Views;};
type Params = $Params & { hydrateCtx: HydrateCtx & { viewer: string };};
type SkeletonState = { blockedDids: string[]; cursor?: string;};