diff --git a/CHANGELOG.md b/CHANGELOG.md index cb219d1..7f13209 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,10 +13,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `at_uri` module for validating at-uris - `handle` module for validating atproto handles +### Removed + +- `list_standard_documents` was removed, its functionality can be replace by + calling `list_records` and passing the nsid as "standard.site.document" + ### Changed - All functions now use `prepend_header` instead of `set_header`. - Renamed `did.DidError` to `did.ParseError` - Rename `did.InvalidFormat` to `did.InvalidSyntax` - Rename `handle.InvalidFormat` to `handle.InvalidSyntax` -- `resolve_handle` now takes a `handle.Handle` as parameter instead of a string +- `resolve_handle` and `resolve_well_known_did` now take a `handle.Handle` as + parameter instead of a regular `String` +- `resolve_handle` now takes a `handle.Handle` as parameter instead of a `String` +- Functions now take a parsed `nsid.Nsid` as the `collection` parameter diff --git a/src/possum.gleam b/src/possum.gleam index 47fa554..4534b14 100644 --- a/src/possum.gleam +++ b/src/possum.gleam @@ -37,6 +37,7 @@ import gleam/json import gleam/option import possum/did import possum/handle +import possum/nsid /// Documentation: [/xrpc/com.atproto.repo](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo) const com_atproto_repo = "xrpc/com.atproto.repo" @@ -112,10 +113,13 @@ pub fn get_plc_data( /// /// ```gleam /// import gleam/http/request +/// import possum/handle /// import possum /// +/// let assert Ok(handle) = handle.parse("gleam.run") +/// /// request.new() -/// |> possum.resolve_well_known_did("gleam.run") +/// |> possum.resolve_well_known_did(handle) /// ``` /// /// ## Response @@ -127,10 +131,10 @@ pub fn get_plc_data( /// Documentation: [HTTPS well-known Method](https://atproto.com/specs/handle#https-well-known-method) pub fn resolve_well_known_did( request: request.Request(_), - host host: String, + handle: handle.Handle, ) -> request.Request(_) { request - |> request.set_host(host) + |> request.set_host(handle.to_string(handle)) |> request.set_method(http.Get) |> request.set_path(".well-known/atproto-did") } @@ -145,12 +149,15 @@ pub fn resolve_well_known_did( /// /// ```gleam /// import gleam/http/request +/// import possum/handle /// import possum /// +/// let assert Ok(handle) = handle.parse("gleam.run") +/// /// let request = /// request.new() /// |> request.set_host("slingshot.microcosm.blue") -/// |> possum.resolve_handle("gleam.run") +/// |> possum.resolve_handle(handle) /// ``` /// /// ## Response @@ -411,16 +418,21 @@ pub fn describe_repository( /// /// ```gleam /// import gleam/http/request +/// import possum/nsid +/// import possum/did /// import possum /// +/// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") +/// let assert Ok(collection) = nsid.parse("wibble.wobble.woo") +/// /// let request = /// request.new() /// |> request.set_host("personal.data-server.pds") /// |> possum.authorized("access-token") /// |> possum.create_record( /// did, +/// collection:, /// rkey: "wibble", -/// collection: "wibble.wobble.woo", /// record: [], /// swap_commit: option.None, /// validate: option.None, @@ -445,14 +457,14 @@ pub fn describe_repository( pub fn create_record( request: request.Request(_), did: did.Did, - collection collection: String, + collection nsid: nsid.Nsid, rkey rkey: option.Option(String), record record: List(#(String, json.Json)), swap_commit swap_commit: option.Option(String), validate validate: option.Option(Bool), ) -> request.Request(_) { let body = [ - #("collection", json.string(collection)), + #("collection", json.string(nsid.to_string(nsid))), #("record", json.object(record)), #("repo", json.string(did.to_string(did))), ] @@ -492,13 +504,16 @@ pub fn create_record( /// import gleam/http/request /// import possum /// +/// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") +/// let assert Ok(collection) = nsid.parse("site.standard.document") +/// /// let request = /// request.new() /// |> request.set_host("slingshot.microcosm.blue") /// |> possum.get_record( /// did, -/// rkey: "3mn6n3lvibc2b", -/// collection: "site.standard.document", +/// collection:, +/// rkey: "mn6n3lvibc2b", /// cursor: option.None, /// cid: option.None, /// ) @@ -519,14 +534,14 @@ pub fn create_record( pub fn get_record( request: request.Request(_), did: did.Did, - collection collection: String, + collection nsid: nsid.Nsid, rkey rkey: String, cid cid: option.Option(String), ) -> request.Request(_) { let query = [ #("repo", did.to_string(did)), #("rkey", rkey), - #("collection", collection), + #("collection", nsid.to_string(nsid)), ] let query = case cid { @@ -549,12 +564,14 @@ pub fn get_record( /// import gleam/http/request /// import possum /// +/// let assert Ok(collection) = nsid.parse("site.standard.document") +/// /// let request = /// request.new() /// |> request.set_host("personal.data-server.pds") /// |> possum.list_records( /// did, -/// collection: "site.standard.document", +/// collection:, /// limit: option.Some(3), /// cursor: option.None, /// reverse: option.None, @@ -580,14 +597,14 @@ pub fn get_record( pub fn list_records( request: request.Request(_), did: did.Did, - collection collection: String, + collection nsid: nsid.Nsid, limit limit: option.Option(Int), cursor cursor: option.Option(String), reverse reverse: option.Option(Bool), ) -> request.Request(_) { let query = [ #("repo", did.to_string(did)), - #("collection", collection), + #("collection", nsid.to_string(nsid)), ] let query = case limit { @@ -627,13 +644,16 @@ pub fn list_records( /// import gleam/http/request /// import possum /// +/// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") +/// let assert Ok(collection) = nsid.parse("wibble.wobble.woo") +/// /// let request = /// request.new() /// |> request.set_host("personal.data-server.pds") /// |> possum.authorized("access-token") /// |> possum.delete_record( /// did, -/// collection: "target.collection.data", +/// collection:, /// rkey: "wibble-wobble", /// swap_commit: option.None, /// swap_record: option.None, @@ -655,14 +675,14 @@ pub fn list_records( pub fn delete_record( request: request.Request(_), did: did.Did, - collection collection: String, + collection nsid: nsid.Nsid, rkey rkey: String, swap_commit swap_commit: option.Option(String), swap_record swap_record: option.Option(String), ) -> request.Request(_) { let body = [ #("repo", json.string(did.to_string(did))), - #("collection", json.string(collection)), + #("collection", json.string(nsid.to_string(nsid))), #("rkey", json.string(rkey)), ] @@ -706,13 +726,16 @@ pub fn delete_record( /// import gleam/http/request /// import possum /// +/// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") +/// let assert Ok(collection) = nsid.parse("target.collection.data") +/// /// let request = /// request.new() /// |> request.set_host("personal.data-server.pds") /// |> possum.authorized("access-token") /// |> possum.put_record( /// did, -/// collection: "target.collection.data", +/// collection:, /// rkey: "wibble-wobble", /// record: [], /// swap_commit: option.None, @@ -739,7 +762,7 @@ pub fn delete_record( pub fn put_record( request: request.Request(_), did: did.Did, - collection collection: String, + collection nsid: nsid.Nsid, rkey rkey: String, record record: List(#(String, json.Json)), swap_commit swap_commit: option.Option(String), @@ -747,7 +770,7 @@ pub fn put_record( validate validate: option.Option(Bool), ) -> request.Request(_) { let body = [ - #("collection", json.string(collection)), + #("collection", json.string(nsid.to_string(nsid))), #("record", json.object(record)), #("repo", json.string(did.to_string(did))), #("rkey", json.string(rkey)), diff --git a/test/possum_test.gleam b/test/possum_test.gleam index 4f8497a..5a9ba01 100644 --- a/test/possum_test.gleam +++ b/test/possum_test.gleam @@ -13,6 +13,7 @@ import global_value import possum import possum/did import possum/handle +import possum/nsid pub fn main() -> Nil { gleeunit.main() @@ -138,7 +139,7 @@ pub fn authorized_test() -> Nil { pub fn get_record_test() -> Nil { let context = global_data() - let collection = "app.bsky.actor.profile" + let assert Ok(collection) = nsid.parse("app.bsky.actor.profile") let assert Ok(response) = request.new()