Current section
Files
Jump to
Current section
Files
src/possum.erl
-module(possum).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/possum.gleam").
-export([get_plc_data/2, resolve_well_known_did/2, resolve_handle/2, create_session/5, authorized/2, refresh_session/2, get_session_info/1, describe_repository/2, create_record/7, get_record/5, list_records/6, delete_record/6, put_record/8]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" ## PDS (Personal Data Server)\n"
"\n"
" A PDS, or Personal Data Server, is a server that hosts a user, it will\n"
" always store the user's data repo and signing keys. It may also assign\n"
" the user a handle and a DID. Many PDSes will host multiple users.\n"
"\n"
" A PDS doesn't typically run any applications itself, though it will have\n"
" general account management interfaces such as the OAuth login screen.\n"
" PDSes actively sync their data repos with Relays.\n"
"\n"
" ## Lexicon\n"
"\n"
" Lexicon is a schema language. It's used in the Atmosphere to describe data\n"
" records and HTTP APIs. Functionally it's very similar to JSON-Schema and OpenAPI.\n"
" Lexicon's sole purpose is to help developers build compatible software.\n"
"\n"
" ## Record Keys\n"
"\n"
" A record key (sometimes shortened to \"rkey\") is used to name and reference an individual\n"
" record within the same collection of an atproto repository.\n"
" It ends up as a segment in AT URIs, and in the repo MST path.\n"
"\n"
" ## CID (Content ID)\n"
"\n"
" CIDs, or Content Identifiers, are cryptographic hashes of records.\n"
" They are used to track specific versions of records.\n"
"\n"
" CIDs include a metadata code which indicates whether it links to a node\n"
" or arbitrary binary data. In atproto, object nodes often include a string\n"
" field `$type` that specifies their Lexicon schema. \n"
).
-file("src/possum.gleam", 99).
?DOC(
" Get current PLC Data for the indicated DID,\n"
" this returns information about a Decentralized Identifier (DID),\n"
" including their handle and service endpoint.\n"
"\n"
" PLC is a persistent global identifier system, stands for\n"
" \"Public Ledger of Credentials\".\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/did\n"
" import possum\n"
"\n"
" let assert Ok(did) = did.parse(\"did:plc:z72i7hdynmk6r22z27h6tvur\")\n"
"\n"
" let request =\n"
" request.new()\n"
" |> possum.get_plc_data(did)\n"
"\n"
" // You can use this decoder to extract the server endpoint\n"
" let decoder = decode.at([\"services\", \"atproto_pds\", \"endpoint\"], decode.string)\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"did\": \"string\",\n"
" \"verificationMethods\": {\n"
" \"atproto\": \"string\"\n"
" },\n"
" \"rotationKeys\": [\n"
" \"string\",\n"
" \"string\"\n"
" ],\n"
" \"alsoKnownAs\": [\n"
" \"string\"\n"
" ],\n"
" \"services\": {\n"
" \"atproto_pds\": {\n"
" \"type\": \"string\",\n"
" \"endpoint\": \"string\"\n"
" }\n"
" }\n"
" ```\n"
"\n"
" Documentation: [DID PLC Directory](https://web.plc.directory/)\n"
).
-spec get_plc_data(gleam@http@request:request(EVB), possum@did:did()) -> gleam@http@request:request(EVB).
get_plc_data(Request, Did) ->
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:set_host(_pipe@1, <<"plc.directory"/utf8>>),
_pipe@3 = gleam@http@request:set_method(_pipe@2, get),
gleam@http@request:set_path(
_pipe@3,
<<(possum@did:to_string(Did))/binary, "/data"/utf8>>
).
-file("src/possum.gleam", 133).
?DOC(
" Resolves a handle to a DID using a HTTPS `/.well-known/` URL path,\n"
" it looks for a file called \"atproto-did\" that contains the user DID.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/handle\n"
" import possum\n"
"\n"
" let assert Ok(handle) = handle.parse(\"gleam.run\")\n"
"\n"
" request.new()\n"
" |> possum.resolve_well_known_did(handle)\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```txt\n"
" did:plc:k5vecqzf4d5mdvkcu3mx6l5g\n"
" ```\n"
"\n"
" Documentation: [HTTPS well-known Method](https://atproto.com/specs/handle#https-well-known-method)\n"
).
-spec resolve_well_known_did(gleam@http@request:request(EVF), binary()) -> gleam@http@request:request(EVF).
resolve_well_known_did(Request, Host) ->
_pipe = Request,
_pipe@1 = gleam@http@request:set_host(_pipe, Host),
_pipe@2 = gleam@http@request:set_method(_pipe@1, get),
gleam@http@request:set_path(_pipe@2, <<".well-known/atproto-did"/utf8>>).
-file("src/possum.gleam", 173).
?DOC(
" Resolves an atproto handle (hostname) to a DID.\n"
" Does not necessarily bi-directionally verify against the the DID document.\n"
"\n"
" You can use projects like [Slingshot](https://slingshot.microcosm.blue)\n"
" for easy access to cached data.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/handle\n"
" import possum\n"
"\n"
" let assert Ok(handle) = handle.parse(\"gleam.run\")\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"slingshot.microcosm.blue\")\n"
" |> possum.resolve_handle(handle)\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"did\": \"string\"\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.identity.resolveHandle](https://endpoints.bsky.app/#bluesky-app/tag/comatprotoidentity/GET/xrpc/com.atproto.identity.resolveHandle)\n"
).
-spec resolve_handle(gleam@http@request:request(EVJ), possum@handle:handle()) -> gleam@http@request:request(EVJ).
resolve_handle(Request, Handle) ->
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:set_method(_pipe@1, get),
_pipe@3 = gleam@http@request:set_path(
_pipe@2,
<<"xrpc/com.atproto.identity"/utf8, ".resolveHandle"/utf8>>
),
gleam@http@request:set_query(
_pipe@3,
[{<<"handle"/utf8>>, possum@handle:to_string(Handle)}]
).
-file("src/possum.gleam", 233).
?DOC(
" Create an authentication session.\n"
" An **App Password** can be generated in your Bluesky settings.\n"
"\n"
" ## Body\n"
"\n"
" - **password**: App password\n"
" - **allowTakendown**: When true, instead of throwing error for takendown accounts,\n"
" a valid response with a narrow scoped token will be returned\n"
" - **authFactorToken**: Used during the authentication process to handle\n"
" Two-Factor Authentication\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/did\n"
" import possum\n"
"\n"
" let assert Ok(did) = did.parse(\"did:plc:ewvi7nxzyoun6zhxrhs64oiz\")\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"personal.data-server.pds\")\n"
" |> possum.create_session(\n"
" did,\n"
" app_password: \"bsky-app-password\",\n"
" allow_takendown: option.None,\n"
" auth_factor_token: option.None\n"
" )\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"did\": \"string\",\n"
" \"email\": \"string\",\n"
" \"active\": true,\n"
" \"didDoc\": null,\n"
" \"handle\": \"string\",\n"
" \"status\": \"takendown\",\n"
" \"accessJwt\": \"string\",\n"
" \"refreshJwt\": \"string\",\n"
" \"emailConfirmed\": true,\n"
" \"emailAuthFactor\": true\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.server.createSession](https://endpoints.bsky.app/#bluesky-app/tag/comatprotoserver/POST/xrpc/com.atproto.server.createSession)\n"
).
-spec create_session(
gleam@http@request:request(any()),
possum@did:did(),
binary(),
gleam@option:option(boolean()),
gleam@option:option(binary())
) -> gleam@http@request:request(binary()).
create_session(Request, Did, App_password, Allow_takendown, Auth_factor_token) ->
Values = [{<<"identifier"/utf8>>,
gleam@json:string(possum@did:to_string(Did))},
{<<"password"/utf8>>, gleam@json:string(App_password)}],
Values@1 = case Allow_takendown of
{some, Value} ->
[{<<"allowTakendown"/utf8>>, gleam@json:bool(Value)} | Values];
none ->
Values
end,
Values@2 = case Auth_factor_token of
{some, Value@1} ->
[{<<"authFactorToken"/utf8>>, gleam@json:string(Value@1)} |
Values@1];
none ->
Values@1
end,
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:prepend_header(
_pipe@1,
<<"content-type"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@3 = gleam@http@request:set_body(
_pipe@2,
gleam@json:to_string(gleam@json:object(Values@2))
),
_pipe@4 = gleam@http@request:set_method(_pipe@3, post),
gleam@http@request:set_path(
_pipe@4,
<<"xrpc/com.atproto.server"/utf8, ".createSession"/utf8>>
).
-file("src/possum.gleam", 361).
?DOC(
" Include a access token in the request's headers.\n"
" Tokens can be acquired with `create_session`.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"personal.data-server.pds\")\n"
" |> possum.authorized(\"access-token\")\n"
" ```\n"
).
-spec authorized(gleam@http@request:request(EWB), binary()) -> gleam@http@request:request(EWB).
authorized(Request, Token) ->
gleam@http@request:prepend_header(
Request,
<<"authorization"/utf8>>,
<<"bearer "/utf8, Token/binary>>
).
-file("src/possum.gleam", 296).
?DOC(
" Refresh an authentication session.\n"
" Requires auth using the 'refreshJwt' (not the 'accessJwt').\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"personal.data-server.pds\")\n"
" |> possum.refresh_session(\"refresh-token\")\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"did\": \"string\",\n"
" \"email\": \"string\",\n"
" \"active\": true,\n"
" \"didDoc\": null,\n"
" \"handle\": \"string\",\n"
" \"status\": \"takendown\",\n"
" \"accessJwt\": \"string\",\n"
" \"refreshJwt\": \"string\",\n"
" \"emailConfirmed\": true,\n"
" \"emailAuthFactor\": true\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.server.refreshSession](https://endpoints.bsky.app/#bluesky-app/tag/comatprotoserver/POST/xrpc/com.atproto.server.refreshSession)\n"
).
-spec refresh_session(gleam@http@request:request(EVT), binary()) -> gleam@http@request:request(EVT).
refresh_session(Request, Token) ->
_pipe = Request,
_pipe@1 = authorized(_pipe, Token),
_pipe@2 = gleam@http@request:prepend_header(
_pipe@1,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@3 = gleam@http@request:set_method(_pipe@2, post),
gleam@http@request:set_path(
_pipe@3,
<<"xrpc/com.atproto.server"/utf8, ".refreshSession"/utf8>>
).
-file("src/possum.gleam", 339).
?DOC(
" Get information about the current auth session.\n"
" Requires auth.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"personal.data-server.pds\")\n"
" |> possum.authorized(\"access-token\")\n"
" |> possum.get_session_info\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"did\": \"string\",\n"
" \"email\": \"string\",\n"
" \"active\": true,\n"
" \"didDoc\": null,\n"
" \"handle\": \"string\",\n"
" \"status\": \"takendown\",\n"
" \"emailConfirmed\": true,\n"
" \"emailAuthFactor\": true\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.server.getSession](https://endpoints.bsky.app/#bluesky-app/tag/comatprotoserver/POST/xrpc/com.atproto.server.getSession)\n"
).
-spec get_session_info(gleam@http@request:request(EVX)) -> gleam@http@request:request(EVX).
get_session_info(Request) ->
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:set_method(_pipe@1, get),
gleam@http@request:set_path(
_pipe@2,
<<"xrpc/com.atproto.server"/utf8, ".getSession"/utf8>>
).
-file("src/possum.gleam", 400).
?DOC(
" Get information about an account and repository, including the list of collections.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/did\n"
" import possum\n"
"\n"
" let assert Ok(did) = did.parse(\"did:plc:ewvi7nxzyoun6zhxrhs64oiz\")\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"personal.data-server.pds\")\n"
" |> possum.describe_repository(did)\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"did\": \"string\",\n"
" \"didDoc\": null,\n"
" \"handle\": \"string\",\n"
" \"collections\": [\n"
" \"string\"\n"
" ],\n"
" \"handleIsCorrect\": true\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.repo.describeRepo](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/GET/xrpc/com.atproto.repo.describeRepo)\n"
).
-spec describe_repository(gleam@http@request:request(EWF), possum@did:did()) -> gleam@http@request:request(EWF).
describe_repository(Request, Did) ->
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:set_method(_pipe@1, get),
_pipe@3 = gleam@http@request:set_path(
_pipe@2,
<<"xrpc/com.atproto.repo"/utf8, ".describeRepo"/utf8>>
),
gleam@http@request:set_query(
_pipe@3,
[{<<"repo"/utf8>>, possum@did:to_string(Did)}]
).
-file("src/possum.gleam", 464).
?DOC(
" Create a single new repository record.\n"
" Requires auth, implemented by PDS.\n"
" \n"
" ## Body\n"
" \n"
" - **collection**: The NSID of the record collection.\n"
" - **repo**: The handle or DID of the repo (aka, current account).\n"
" - **rkey**: The Record Key.\n"
" - **swapCommit**: Compare and swap with the previous commit by CID.\n"
" - **validate**: Can be set to 'false' to skip Lexicon schema validation\n"
" of record data, 'true' to require it, or leave unset to validate\n"
" only for known Lexicons.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/nsid\n"
" import possum/did\n"
" import possum\n"
"\n"
" let assert Ok(did) = did.parse(\"did:plc:k5vecqzf4d5mdvkcu3mx6l5g\")\n"
" let assert Ok(collection) = nsid.parse(\"wibble.wobble.woo\")\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"personal.data-server.pds\")\n"
" |> possum.authorized(\"access-token\")\n"
" |> possum.create_record(\n"
" did,\n"
" collection:,\n"
" rkey: \"wibble\",\n"
" record: [],\n"
" swap_commit: option.None,\n"
" validate: option.None,\n"
" )\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"cid\": \"string\",\n"
" \"uri\": \"string\",\n"
" \"commit\": {\n"
" \"cid\": \"string\",\n"
" \"rev\": \"string\"\n"
" },\n"
" \"validationStatus\": \"valid\"\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.repo.createRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/POST/xrpc/com.atproto.repo.createRecord)\n"
).
-spec create_record(
gleam@http@request:request(any()),
possum@did:did(),
possum@nsid:nsid(),
gleam@option:option(binary()),
list({binary(), gleam@json:json()}),
gleam@option:option(binary()),
gleam@option:option(boolean())
) -> gleam@http@request:request(binary()).
create_record(Request, Did, Nsid, Rkey, Record, Swap_commit, Validate) ->
Body = [{<<"collection"/utf8>>,
gleam@json:string(possum@nsid:to_string(Nsid))},
{<<"record"/utf8>>, gleam@json:object(Record)},
{<<"repo"/utf8>>, gleam@json:string(possum@did:to_string(Did))}],
Body@1 = case Rkey of
{some, Value} ->
[{<<"rkey"/utf8>>, gleam@json:string(Value)} | Body];
none ->
Body
end,
Body@2 = case Swap_commit of
{some, Value@1} ->
[{<<"swapCommit"/utf8>>, gleam@json:string(Value@1)} | Body@1];
none ->
Body@1
end,
Body@3 = case Validate of
{some, Value@2} ->
[{<<"validate"/utf8>>, gleam@json:bool(Value@2)} | Body@2];
none ->
Body@2
end,
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:prepend_header(
_pipe@1,
<<"content-type"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@3 = gleam@http@request:set_body(
_pipe@2,
gleam@json:to_string(gleam@json:object(Body@3))
),
_pipe@4 = gleam@http@request:set_method(_pipe@3, post),
gleam@http@request:set_path(
_pipe@4,
<<"xrpc/com.atproto.repo"/utf8, ".createRecord"/utf8>>
).
-file("src/possum.gleam", 543).
?DOC(
" Get a single record from a repository. Does not require auth.\n"
"\n"
" A **record key** (rkey) is used to name and reference an individual record\n"
" withing the same collection of an repository.\n"
"\n"
" You can use projects like [Slingshot](https://slingshot.microcosm.blue)\n"
" for easy access to cached data.\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/did\n"
" import possum/nsid\n"
" import possum\n"
"\n"
" let assert Ok(did) = did.parse(\"did:plc:k5vecqzf4d5mdvkcu3mx6l5g\")\n"
" let assert Ok(collection) = nsid.parse(\"site.standard.document\")\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"slingshot.microcosm.blue\") \n"
" |> possum.get_record(\n"
" did,\n"
" collection:,\n"
" rkey: \"mn6n3lvibc2b\",\n"
" cursor: option.None,\n"
" cid: option.None,\n"
" )\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"cid\": \"string\",\n"
" \"uri\": \"string\",\n"
" \"value\": null\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.repo.getRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/GET/xrpc/com.atproto.repo.getRecord)\n"
" Documentation: [atproto.com](https://atproto.com/specs/record-key)\n"
).
-spec get_record(
gleam@http@request:request(EWR),
possum@did:did(),
possum@nsid:nsid(),
binary(),
gleam@option:option(binary())
) -> gleam@http@request:request(EWR).
get_record(Request, Did, Nsid, Rkey, Cid) ->
Query = [{<<"repo"/utf8>>, possum@did:to_string(Did)},
{<<"rkey"/utf8>>, Rkey},
{<<"collection"/utf8>>, possum@nsid:to_string(Nsid)}],
Query@1 = case Cid of
{some, Cid@1} ->
[{<<"cid"/utf8>>, Cid@1} | Query];
none ->
Query
end,
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:set_method(_pipe@1, get),
_pipe@3 = gleam@http@request:set_path(
_pipe@2,
<<"xrpc/com.atproto.repo"/utf8, ".getRecord"/utf8>>
),
gleam@http@request:set_query(_pipe@3, Query@1).
-file("src/possum.gleam", 609).
?DOC(
" List a range of records in a repository, matching a specific collection.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/did\n"
" import possum/nsid\n"
" import possum\n"
"\n"
" let assert Ok(did) = did.parse(\"did:plc:ewvi7nxzyoun6zhxrhs64oiz\")\n"
" let assert Ok(collection) = nsid.parse(\"site.standard.document\")\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"personal.data-server.pds\")\n"
" |> possum.list_records(\n"
" did,\n"
" collection:,\n"
" limit: option.Some(3),\n"
" cursor: option.None,\n"
" reverse: option.None,\n"
" )\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"cursor\": \"string\",\n"
" \"records\": [\n"
" {\n"
" \"cid\": \"string\",\n"
" \"uri\": \"string\",\n"
" \"value\": null\n"
" }\n"
" ]\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.repo.listRecords](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/GET/xrpc/com.atproto.repo.listRecords)\n"
).
-spec list_records(
gleam@http@request:request(EWW),
possum@did:did(),
possum@nsid:nsid(),
gleam@option:option(integer()),
gleam@option:option(binary()),
gleam@option:option(boolean())
) -> gleam@http@request:request(EWW).
list_records(Request, Did, Nsid, Limit, Cursor, Reverse) ->
Query = [{<<"repo"/utf8>>, possum@did:to_string(Did)},
{<<"collection"/utf8>>, possum@nsid:to_string(Nsid)}],
Query@1 = case Limit of
{some, Value} ->
[{<<"limit"/utf8>>, erlang:integer_to_binary(Value)} | Query];
none ->
Query
end,
Query@2 = case Cursor of
{some, Value@1} ->
[{<<"cursor"/utf8>>, Value@1} | Query@1];
none ->
Query@1
end,
Query@3 = case Reverse of
{some, Value@2} ->
[{<<"reverse"/utf8>>, gleam@bool:to_string(Value@2)} | Query@2];
none ->
Query@2
end,
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:set_method(_pipe@1, get),
_pipe@3 = gleam@http@request:set_path(
_pipe@2,
<<"xrpc/com.atproto.repo"/utf8, ".listRecords"/utf8>>
),
gleam@http@request:set_query(_pipe@3, Query@3).
-file("src/possum.gleam", 689).
?DOC(
" Delete a repository record, or ensure it doesn't exist.\n"
" Requires auth, implemented by PDS.\n"
"\n"
" - **collection**: The NSID of the record collection.\n"
" - **repo**: The handle or DID of the repo (aka, current account).\n"
" - **rkey**: The Record Key.\n"
" - **swapCommit**: Compare and swap with the previous commit by CID.\n"
" - **swapRecord**: Compare and swap with the previous record by CID.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/did\n"
" import possum/nsid\n"
" import possum\n"
" \n"
" let assert Ok(did) = did.parse(\"did:plc:k5vecqzf4d5mdvkcu3mx6l5g\")\n"
" let assert Ok(collection) = nsid.parse(\"wibble.wobble.woo\")\n"
" \n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"personal.data-server.pds\")\n"
" |> possum.authorized(\"access-token\")\n"
" |> possum.delete_record(\n"
" did,\n"
" collection:,\n"
" rkey: \"wibble-wobble\",\n"
" swap_commit: option.None,\n"
" swap_record: option.None,\n"
" )\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"commit\": {\n"
" \"cid\": \"string\",\n"
" \"rev\": \"string\"\n"
" }\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.repo.deleteRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/POST/xrpc/com.atproto.repo.deleteRecord)\n"
).
-spec delete_record(
gleam@http@request:request(any()),
possum@did:did(),
possum@nsid:nsid(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary())
) -> gleam@http@request:request(binary()).
delete_record(Request, Did, Nsid, Rkey, Swap_commit, Swap_record) ->
Body = [{<<"repo"/utf8>>, gleam@json:string(possum@did:to_string(Did))},
{<<"collection"/utf8>>, gleam@json:string(possum@nsid:to_string(Nsid))},
{<<"rkey"/utf8>>, gleam@json:string(Rkey)}],
Body@1 = case Swap_commit of
{some, Value} ->
[{<<"swapCommit"/utf8>>, gleam@json:string(Value)} | Body];
none ->
Body
end,
Body@2 = case Swap_record of
{some, Value@1} ->
[{<<"swapRecord"/utf8>>, gleam@json:string(Value@1)} | Body@1];
none ->
Body@1
end,
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:prepend_header(
_pipe@1,
<<"content-type"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@3 = gleam@http@request:set_body(
_pipe@2,
gleam@json:to_string(gleam@json:object(Body@2))
),
_pipe@4 = gleam@http@request:set_method(_pipe@3, post),
gleam@http@request:set_path(
_pipe@4,
<<"xrpc/com.atproto.repo"/utf8, ".deleteRecord"/utf8>>
).
-file("src/possum.gleam", 778).
?DOC(
" Write a repository record, creating or updating it as needed.\n"
" Requires auth, implemented by PDS.\n"
"\n"
" ## Body\n"
" \n"
" - **collection**: The NSID of the record collection.\n"
" - **record**\n"
" - **repo**: The handle or DID of the repo (aka, current account).\n"
" - **rkey**: The Record Key.\n"
" - **swapCommit**: Compare and swap with the previous commit by CID.\n"
" - **swapRecord**: Compare and swap with the previous record by CID.\n"
" WARNING: nullable and optional field;\n"
" - **validate**: Can be set to `false` to skip Lexicon schema validation\n"
" of record data, 'true' to require it, or leave unset to validate only\n"
" for known Lexicons.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import gleam/http/request\n"
" import possum/did\n"
" import possum/nsid\n"
" import possum\n"
" \n"
" let assert Ok(did) = did.parse(\"did:plc:k5vecqzf4d5mdvkcu3mx6l5g\")\n"
" let assert Ok(collection) = nsid.parse(\"target.collection.data\")\n"
"\n"
" let request =\n"
" request.new()\n"
" |> request.set_host(\"personal.data-server.pds\")\n"
" |> possum.authorized(\"access-token\")\n"
" |> possum.put_record(\n"
" did,\n"
" collection:,\n"
" rkey: \"wibble-wobble\",\n"
" record: [],\n"
" swap_commit: option.None,\n"
" swap_record: option.None,\n"
" validate: option.None,\n"
" )\n"
" ```\n"
"\n"
" ## Response\n"
"\n"
" ```json\n"
" {\n"
" \"cid\": \"string\",\n"
" \"uri\": \"string\",\n"
" \"commit\": {\n"
" \"cid\": \"string\",\n"
" \"rev\": \"string\"\n"
" },\n"
" \"validationStatus\": \"valid\"\n"
" }\n"
" ```\n"
"\n"
" Endpoint Docs: [/xrpc/com.atproto.repo.putRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/POST/xrpc/com.atproto.repo.putRecord)\n"
).
-spec put_record(
gleam@http@request:request(any()),
possum@did:did(),
possum@nsid:nsid(),
binary(),
list({binary(), gleam@json:json()}),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(boolean())
) -> gleam@http@request:request(binary()).
put_record(Request, Did, Nsid, Rkey, Record, Swap_commit, Swap_record, Validate) ->
Body = [{<<"collection"/utf8>>,
gleam@json:string(possum@nsid:to_string(Nsid))},
{<<"record"/utf8>>, gleam@json:object(Record)},
{<<"repo"/utf8>>, gleam@json:string(possum@did:to_string(Did))},
{<<"rkey"/utf8>>, gleam@json:string(Rkey)}],
Body@1 = case Swap_commit of
{some, Value} ->
[{<<"swapCommit"/utf8>>, gleam@json:string(Value)} | Body];
none ->
Body
end,
Body@2 = case Swap_record of
{some, Value@1} ->
[{<<"swapRecord"/utf8>>, gleam@json:string(Value@1)} | Body@1];
none ->
Body@1
end,
Body@3 = case Validate of
{some, Value@2} ->
[{<<"validate"/utf8>>, gleam@json:bool(Value@2)} | Body@2];
none ->
Body@2
end,
_pipe = Request,
_pipe@1 = gleam@http@request:prepend_header(
_pipe,
<<"accept"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@2 = gleam@http@request:prepend_header(
_pipe@1,
<<"content-type"/utf8>>,
<<"application/json"/utf8>>
),
_pipe@3 = gleam@http@request:set_body(
_pipe@2,
gleam@json:to_string(gleam@json:object(Body@3))
),
_pipe@4 = gleam@http@request:set_method(_pipe@3, post),
gleam@http@request:set_path(
_pipe@4,
<<"xrpc/com.atproto.repo"/utf8, ".putRecord"/utf8>>
).