import type { BobbinContext, XrpcRequestInit } from "$lib/api/client"; import { jsonGet } from "$lib/api/_request"; import type * as ShTangledActorGetProfileActivity from "$lib/api/lexicons/types/sh/tangled/actor/getProfileActivity"; import type * as ShTangledActorProfile from "$lib/api/lexicons/types/sh/tangled/actor/profile"; import type * as ShTangledPullGetPullView from "$lib/api/lexicons/types/sh/tangled/pull/getPullView"; import type * as ShTangledFeedStar from "$lib/api/lexicons/types/sh/tangled/feed/star"; import type * as ShTangledGraphVouch from "$lib/api/lexicons/types/sh/tangled/graph/vouch"; import type * as ShTangledRepo from "$lib/api/lexicons/types/sh/tangled/repo"; import type * as ShTangledRepoPull from "$lib/api/lexicons/types/sh/tangled/repo/pull"; import type * as ShTangledRepoPullStatus from "$lib/api/lexicons/types/sh/tangled/repo/pull/status"; import type * as ShTangledString from "$lib/api/lexicons/types/sh/tangled/string"; export interface RecordView { uri: string; cid?: string; value: V; } export interface RecordList { items: RecordView[]; } export type RepoRecord = ShTangledRepo.Main; export type ProfileRecord = ShTangledActorProfile.Main; export type PullRecord = ShTangledRepoPull.Main; export type PullStatusRecord = ShTangledRepoPullStatus.Main; export type StringRecord = ShTangledString.Main; export type StarRecord = ShTangledFeedStar.Main; export type VouchRecord = ShTangledGraphVouch.Main; export type ProfileActivityOutput = ShTangledActorGetProfileActivity.$output; export type ProfileActivityRepoRef = ShTangledActorGetProfileActivity.RepoRef; export const BULK_LIMIT = 50; export const getRepo = (ctx: BobbinContext, repo: string, init?: XrpcRequestInit) => jsonGet>(ctx, "sh.tangled.repo.getRepo", { repo }, init); export const getRepoByRepoDid = (ctx: BobbinContext, repoDid: string, init?: XrpcRequestInit) => jsonGet>(ctx, "sh.tangled.repo.getRepoByRepoDid", { repoDid }, init); export const getRepoByName = ( ctx: BobbinContext, owner: string, name: string, init?: XrpcRequestInit ) => jsonGet>(ctx, "sh.tangled.repo.getRepoByName", { owner, name }, init); export interface RepoListPage { cursor?: string | null; items: RecordView[]; } export const listRepos = ( ctx: BobbinContext, subject: string, filter: { limit?: number; cursor?: string; order?: "asc" | "desc" } = {}, init?: XrpcRequestInit ) => jsonGet(ctx, "sh.tangled.repo.listRepos", { subject, ...filter }, init); export const getProfile = (ctx: BobbinContext, did: string, init?: XrpcRequestInit) => jsonGet>( ctx, "sh.tangled.actor.getProfile", { actor: `at://${did}/sh.tangled.actor.profile/self` }, init ); export const getPull = (ctx: BobbinContext, pull: string, init?: XrpcRequestInit) => jsonGet>(ctx, "sh.tangled.repo.getPull", { pull }, init); export type PullViewDetailed = ShTangledPullGetPullView.$output; export const getPullView = (ctx: BobbinContext, uri: string, init?: XrpcRequestInit) => jsonGet(ctx, "sh.tangled.pull.getPullView", { uri }, init); export type PullState = "open" | "closed" | "merged"; export interface PullListItem { cid?: string; commentCount: number; state: string; stateUpdatedAt?: string; uri: string; value: PullRecord; } export interface PullListPage { cursor?: string | null; total?: number; items: PullListItem[]; } export interface ListPullsFilter { status?: PullState; author?: string; limit?: number; cursor?: string; order?: "asc" | "desc"; } export const listPulls = ( ctx: BobbinContext, subject: string, filter: ListPullsFilter = {}, init?: XrpcRequestInit ) => jsonGet(ctx, "sh.tangled.repo.listPulls", { subject, ...filter }, init); export const getRepos = (ctx: BobbinContext, repos: readonly string[], init?: XrpcRequestInit) => jsonGet>(ctx, "sh.tangled.repo.getRepos", { repos }, init); export const getReposByRepoDids = ( ctx: BobbinContext, dids: readonly string[], init?: XrpcRequestInit ) => jsonGet>(ctx, "sh.tangled.repo.getReposByRepoDids", { dids }, init); export const getProfileActivity = ( ctx: BobbinContext, actor: string, months = 7, init?: XrpcRequestInit ) => jsonGet( ctx, "sh.tangled.actor.getProfileActivity", { actor, months }, init ); export const getProfiles = ( ctx: BobbinContext, actors: readonly string[], init?: XrpcRequestInit ) => jsonGet>(ctx, "sh.tangled.actor.getProfiles", { actors }, init); export const getPulls = (ctx: BobbinContext, pulls: readonly string[], init?: XrpcRequestInit) => jsonGet>(ctx, "sh.tangled.repo.getPulls", { pulls }, init); export interface StarListPage { cursor?: string | null; total?: number; items: RecordView[]; } export const listStars = ( ctx: BobbinContext, subject: string, filter: { limit?: number; cursor?: string; offset?: number; order?: "asc" | "desc" } = {}, init?: XrpcRequestInit ) => jsonGet(ctx, "sh.tangled.feed.listStars", { subject, ...filter }, init); export const getString = (ctx: BobbinContext, uri: string, init?: XrpcRequestInit) => jsonGet>(ctx, "sh.tangled.string.getString", { uri }, init);