This repository has no description
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 ShTangledRepo from "./lexicons/types/sh/tangled/repo";
6import type * as ShTangledRepoIssue from "./lexicons/types/sh/tangled/repo/issue";
7import type * as ShTangledRepoIssueState from "./lexicons/types/sh/tangled/repo/issue/state";
8import type * as ShTangledRepoPull from "./lexicons/types/sh/tangled/repo/pull";
9import type * as ShTangledString from "./lexicons/types/sh/tangled/string";
10
11export interface RecordView<V> {
12 uri: string;
13 cid?: string;
14 value: V;
15}
16
17export interface RecordList<V> {
18 items: RecordView<V>[];
19}
20
21export type RepoRecord = ShTangledRepo.Main;
22export type ProfileRecord = ShTangledActorProfile.Main;
23export type IssueRecord = ShTangledRepoIssue.Main;
24export type IssueStateRecord = ShTangledRepoIssueState.Main;
25export type PullRecord = ShTangledRepoPull.Main;
26export type StringRecord = ShTangledString.Main;
27export type CommentRecord = ShTangledFeedComment.Main;
28
29export const BULK_LIMIT = 50;
30
31export const getRepo = (ctx: BobbinContext, repo: string, init?: XrpcRequestInit) =>
32 jsonGet<RecordView<RepoRecord>>(ctx, "sh.tangled.repo.getRepo", { repo }, init);
33
34export const getRepoByRepoDid = (ctx: BobbinContext, repoDid: string, init?: XrpcRequestInit) =>
35 jsonGet<RecordView<RepoRecord>>(ctx, "sh.tangled.repo.getRepoByRepoDid", { repoDid }, init);
36
37export const getRepoByName = (
38 ctx: BobbinContext,
39 owner: string,
40 name: string,
41 init?: XrpcRequestInit
42) => jsonGet<RecordView<RepoRecord>>(ctx, "sh.tangled.repo.getRepoByName", { owner, name }, init);
43
44export const getProfile = (ctx: BobbinContext, did: string, init?: XrpcRequestInit) =>
45 jsonGet<RecordView<ProfileRecord>>(
46 ctx,
47 "sh.tangled.actor.getProfile",
48 { actor: `at://${did}/sh.tangled.actor.profile/self` },
49 init
50 );
51
52export const getIssue = (ctx: BobbinContext, issue: string, init?: XrpcRequestInit) =>
53 jsonGet<RecordView<IssueRecord>>(ctx, "sh.tangled.repo.getIssue", { issue }, init);
54
55export type IssueState = "open" | "closed";
56
57// a listIssues row: the embedded issue record plus bobbin-derived state/counts.
58export interface IssueListItem {
59 cid?: string;
60 commentCount: number;
61 state: string;
62 stateUpdatedAt?: string;
63 uri: string;
64 value: IssueRecord;
65}
66
67export interface IssueListPage {
68 cursor?: string | null;
69 items: IssueListItem[];
70}
71
72export interface ListIssuesFilter {
73 state?: IssueState;
74 author?: string;
75 limit?: number;
76 cursor?: string;
77 order?: "asc" | "desc";
78}
79
80export const listIssues = (
81 ctx: BobbinContext,
82 subject: string,
83 filter: ListIssuesFilter = {},
84 init?: XrpcRequestInit
85) => jsonGet<IssueListPage>(ctx, "sh.tangled.repo.listIssues", { subject, ...filter }, init);
86
87// getIssue returns the raw record only; the derived open/closed state lives in
88// separate sh.tangled.repo.issue.state records, latest-wins.
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
101// comments on any record (issue/pull/string) are flat sh.tangled.feed.comment records;
102// threading is derived client-side from each comment's optional replyTo strongRef.
103export interface CommentListPage {
104 cursor?: string | null;
105 items: RecordView<CommentRecord>[];
106}
107
108export const listComments = (
109 ctx: BobbinContext,
110 subject: string,
111 filter: { limit?: number; cursor?: string; order?: "asc" | "desc" } = {},
112 init?: XrpcRequestInit
113) => jsonGet<CommentListPage>(ctx, "sh.tangled.feed.listComments", { subject, ...filter }, init);
114
115export const getPull = (ctx: BobbinContext, pull: string, init?: XrpcRequestInit) =>
116 jsonGet<RecordView<PullRecord>>(ctx, "sh.tangled.repo.getPull", { pull }, init);
117
118export const getRepos = (ctx: BobbinContext, repos: readonly string[], init?: XrpcRequestInit) =>
119 jsonGet<RecordList<RepoRecord>>(ctx, "sh.tangled.repo.getRepos", { repos }, init);
120
121export const getReposByRepoDids = (
122 ctx: BobbinContext,
123 dids: readonly string[],
124 init?: XrpcRequestInit
125) => jsonGet<RecordList<RepoRecord>>(ctx, "sh.tangled.repo.getReposByRepoDids", { dids }, init);
126
127export const getProfiles = (
128 ctx: BobbinContext,
129 actors: readonly string[],
130 init?: XrpcRequestInit
131) => jsonGet<RecordList<ProfileRecord>>(ctx, "sh.tangled.actor.getProfiles", { actors }, init);
132
133export const getIssues = (ctx: BobbinContext, issues: readonly string[], init?: XrpcRequestInit) =>
134 jsonGet<RecordList<IssueRecord>>(ctx, "sh.tangled.repo.getIssues", { issues }, init);
135
136export const getPulls = (ctx: BobbinContext, pulls: readonly string[], init?: XrpcRequestInit) =>
137 jsonGet<RecordList<PullRecord>>(ctx, "sh.tangled.repo.getPulls", { pulls }, init);