This repository has no description
0

Configure Feed

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

core / web / src / lib / api / records.ts
5.3 kB 147 lines
1import type { BobbinContext, XrpcRequestInit } from "./client"; 2import { jsonGet } from "./_request"; 3import type * as ShTangledActorProfile from "./lexicons/types/sh/tangled/actor/profile"; 4import type * as ShTangledFeedComment from "./lexicons/types/sh/tangled/feed/comment"; 5import type * as ShTangledFeedReaction from "./lexicons/types/sh/tangled/feed/reaction"; 6import type * as ShTangledRepo from "./lexicons/types/sh/tangled/repo"; 7import type * as ShTangledRepoIssue from "./lexicons/types/sh/tangled/repo/issue"; 8import type * as ShTangledRepoIssueState from "./lexicons/types/sh/tangled/repo/issue/state"; 9import type * as ShTangledRepoPull from "./lexicons/types/sh/tangled/repo/pull"; 10import type * as ShTangledString from "./lexicons/types/sh/tangled/string"; 11 12export interface RecordView<V> { 13 uri: string; 14 cid?: string; 15 value: V; 16} 17 18export interface RecordList<V> { 19 items: RecordView<V>[]; 20} 21 22export type RepoRecord = ShTangledRepo.Main; 23export type ProfileRecord = ShTangledActorProfile.Main; 24export type IssueRecord = ShTangledRepoIssue.Main; 25export type IssueStateRecord = ShTangledRepoIssueState.Main; 26export type PullRecord = ShTangledRepoPull.Main; 27export type StringRecord = ShTangledString.Main; 28export type CommentRecord = ShTangledFeedComment.Main; 29export type ReactionRecord = ShTangledFeedReaction.Main; 30 31export const BULK_LIMIT = 50; 32 33export const getRepo = (ctx: BobbinContext, repo: string, init?: XrpcRequestInit) => 34 jsonGet<RecordView<RepoRecord>>(ctx, "sh.tangled.repo.getRepo", { repo }, init); 35 36export const getRepoByRepoDid = (ctx: BobbinContext, repoDid: string, init?: XrpcRequestInit) => 37 jsonGet<RecordView<RepoRecord>>(ctx, "sh.tangled.repo.getRepoByRepoDid", { repoDid }, init); 38 39export const getRepoByName = ( 40 ctx: BobbinContext, 41 owner: string, 42 name: string, 43 init?: XrpcRequestInit 44) => jsonGet<RecordView<RepoRecord>>(ctx, "sh.tangled.repo.getRepoByName", { owner, name }, init); 45 46export const getProfile = (ctx: BobbinContext, did: string, init?: XrpcRequestInit) => 47 jsonGet<RecordView<ProfileRecord>>( 48 ctx, 49 "sh.tangled.actor.getProfile", 50 { actor: `at://${did}/sh.tangled.actor.profile/self` }, 51 init 52 ); 53 54export const getIssue = (ctx: BobbinContext, issue: string, init?: XrpcRequestInit) => 55 jsonGet<RecordView<IssueRecord>>(ctx, "sh.tangled.repo.getIssue", { issue }, init); 56 57export type IssueState = "open" | "closed"; 58 59// a listIssues row: the embedded issue record plus bobbin-derived state/counts. 60export interface IssueListItem { 61 cid?: string; 62 commentCount: number; 63 state: string; 64 stateUpdatedAt?: string; 65 uri: string; 66 value: IssueRecord; 67} 68 69export interface IssueListPage { 70 cursor?: string | null; 71 items: IssueListItem[]; 72} 73 74export interface ListIssuesFilter { 75 state?: IssueState; 76 author?: string; 77 limit?: number; 78 cursor?: string; 79 order?: "asc" | "desc"; 80} 81 82export const listIssues = ( 83 ctx: BobbinContext, 84 subject: string, 85 filter: ListIssuesFilter = {}, 86 init?: XrpcRequestInit 87) => jsonGet<IssueListPage>(ctx, "sh.tangled.repo.listIssues", { subject, ...filter }, init); 88 89export interface IssueStateList { 90 cursor?: string | null; 91 items: RecordView<IssueStateRecord>[]; 92} 93 94export const listIssueStates = ( 95 ctx: BobbinContext, 96 subject: string, 97 filter: { limit?: number; cursor?: string; order?: "asc" | "desc" } = {}, 98 init?: XrpcRequestInit 99) => jsonGet<IssueStateList>(ctx, "sh.tangled.repo.issue.listStates", { subject, ...filter }, init); 100 101export interface CommentListPage { 102 cursor?: string | null; 103 items: RecordView<CommentRecord>[]; 104} 105 106export const listComments = ( 107 ctx: BobbinContext, 108 subject: string, 109 filter: { limit?: number; cursor?: string; order?: "asc" | "desc" } = {}, 110 init?: XrpcRequestInit 111) => jsonGet<CommentListPage>(ctx, "sh.tangled.feed.listComments", { subject, ...filter }, init); 112 113export interface ReactionListPage { 114 cursor?: string | null; 115 items: RecordView<ReactionRecord>[]; 116} 117 118export const listReactions = ( 119 ctx: BobbinContext, 120 subject: string, 121 filter: { limit?: number; cursor?: string; order?: "asc" | "desc" } = {}, 122 init?: XrpcRequestInit 123) => jsonGet<ReactionListPage>(ctx, "sh.tangled.feed.listReactions", { subject, ...filter }, init); 124 125export const getPull = (ctx: BobbinContext, pull: string, init?: XrpcRequestInit) => 126 jsonGet<RecordView<PullRecord>>(ctx, "sh.tangled.repo.getPull", { pull }, init); 127 128export const getRepos = (ctx: BobbinContext, repos: readonly string[], init?: XrpcRequestInit) => 129 jsonGet<RecordList<RepoRecord>>(ctx, "sh.tangled.repo.getRepos", { repos }, init); 130 131export const getReposByRepoDids = ( 132 ctx: BobbinContext, 133 dids: readonly string[], 134 init?: XrpcRequestInit 135) => jsonGet<RecordList<RepoRecord>>(ctx, "sh.tangled.repo.getReposByRepoDids", { dids }, init); 136 137export const getProfiles = ( 138 ctx: BobbinContext, 139 actors: readonly string[], 140 init?: XrpcRequestInit 141) => jsonGet<RecordList<ProfileRecord>>(ctx, "sh.tangled.actor.getProfiles", { actors }, init); 142 143export const getIssues = (ctx: BobbinContext, issues: readonly string[], init?: XrpcRequestInit) => 144 jsonGet<RecordList<IssueRecord>>(ctx, "sh.tangled.repo.getIssues", { issues }, init); 145 146export const getPulls = (ctx: BobbinContext, pulls: readonly string[], init?: XrpcRequestInit) => 147 jsonGet<RecordList<PullRecord>>(ctx, "sh.tangled.repo.getPulls", { pulls }, init);