diff --git a/web/src/lib/api/records.ts b/web/src/lib/api/records.ts index 01d91151..06bd8120 100644 --- a/web/src/lib/api/records.ts +++ b/web/src/lib/api/records.ts @@ -4,6 +4,7 @@ import type * as ShTangledActorProfile from "./lexicons/types/sh/tangled/actor/p import type * as ShTangledRepo from "./lexicons/types/sh/tangled/repo"; import type * as ShTangledRepoIssue from "./lexicons/types/sh/tangled/repo/issue"; import type * as ShTangledRepoPull from "./lexicons/types/sh/tangled/repo/pull"; +import type * as ShTangledString from "./lexicons/types/sh/tangled/string"; export interface RecordView { uri: string; @@ -19,6 +20,7 @@ export type RepoRecord = ShTangledRepo.Main; export type ProfileRecord = ShTangledActorProfile.Main; export type IssueRecord = ShTangledRepoIssue.Main; export type PullRecord = ShTangledRepoPull.Main; +export type StringRecord = ShTangledString.Main; export const BULK_LIMIT = 50; diff --git a/web/src/lib/api/strings.ts b/web/src/lib/api/strings.ts new file mode 100644 index 00000000..460c45ee --- /dev/null +++ b/web/src/lib/api/strings.ts @@ -0,0 +1,27 @@ +import { ok } from "@atcute/client"; +import { mainSchema as putRecordSchema } from "@atcute/atproto/types/repo/putRecord"; +import type { Nsid, RecordKey } from "@atcute/lexicons/syntax"; +import type { OAuthUserAgent } from "@atcute/oauth-browser-client"; +import { createClient } from "$lib/auth/agent"; +import type { StringRecord } from "./records"; + +const STRING_COLLECTION = "sh.tangled.string" as Nsid; + +// strings live at a generated tid rkey; put upserts the record at `rkey`. +export const putString = async ( + agent: OAuthUserAgent, + rkey: string, + record: StringRecord +): Promise => { + const rpc = createClient(agent); + await ok( + rpc.call(putRecordSchema, { + input: { + repo: agent.sub, + collection: STRING_COLLECTION, + rkey: rkey as RecordKey, + record + } + }) + ); +};