···1616 InvalidHandleAuthority(reason: handle.ParseError)
1717 /// Authority not a valid DID
1818 InvalidDidAuthority(reason: did.ParseError)
1919+ /// Something else went wrong
2020+ InvalidFormat(value: String)
1921}
20222123pub type Authority {
···7375/// let string = "at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g"
7476/// let assert Ok(at_uri) = at_uri.parse(string)
7577pub fn parse(content: String) -> Result(AtUri, ParseError) {
7676- use rest <- result.try(case content {
7878+ use value <- result.try(case content {
7779 "at://" <> rest -> Ok(rest)
78807981 // Other schemes like "HTTP" and "HTTPS"
8082 _ ->
8183 case string.split_once(content, on: "://") {
8282- Ok(scheme) -> Error(InvalidScheme(scheme.0))
8383- Error(_) -> Error(InvalidScheme(""))
8484+ Ok(scheme) -> Error(InvalidScheme(value: scheme.0))
8585+ Error(_) -> Error(InvalidScheme(value: ""))
8486 }
8587 })
86888787- case string.split_once(rest, "/") {
8989+ case string.split(value, on: "/") {
9090+ // Honestly I dont know how this one could happen.
9191+ [] -> Error(InvalidFormat(value:))
9292+8893 // Contains only authority (DID or handle)
8994 // ex: at://kacaii.dev
9090- Error(_) | Ok(#(_, "")) -> {
9191- use authority <- result.map(parse_authority(rest))
9595+ // ^^ authority
9696+ [authority] -> {
9797+ use authority <- result.map(parse_authority(authority))
9298 AtUri(authority:, collection: "", rkey: "")
9399 }
9410095101 // Contains at least authority and collection
96102 // ex: at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post
9797- Ok(#(authority, rest)) -> {
103103+ // ^^ authority ^^ collection
104104+ [authority, collection] -> {
98105 use authority <- result.map(parse_authority(authority))
9999-100100- case string.split_once(rest, "/") {
101101- // Contains only collection
102102- // ex: at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post
103103- Error(_) -> AtUri(authority:, collection: rest, rkey: "")
106106+ AtUri(authority:, collection:, rkey: "")
107107+ }
104108105105- // Contains collection and rkey
106106- // ex: at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g
107107- Ok(#(collection, rkey)) -> AtUri(authority:, collection:, rkey:)
108108- }
109109+ // Contains authority, collection and rkey
110110+ // ex: at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g
111111+ // ^^ authority ^^ collection ^^ rkey
112112+ [authority, collection, rkey, ..] -> {
113113+ use authority <- result.map(parse_authority(authority))
114114+ AtUri(authority:, collection:, rkey:)
109115 }
110116 }
111117}
···114120 case string {
115121 "did:" <> _rest ->
116122 case did.parse(string) {
117117- Ok(value) -> Ok(Did(value))
123123+ Ok(value) -> Ok(Did(value:))
118124 Error(reason) -> Error(InvalidDidAuthority(reason:))
119125 }
120126121127 _handle ->
122128 case handle.parse(string) {
123123- Ok(value) -> Ok(Handle(value))
129129+ Ok(value) -> Ok(Handle(value:))
124130 Error(reason) -> Error(InvalidHandleAuthority(reason:))
125131 }
126132 }
···148154 let path = case self.collection, self.rkey {
149155 "", _ -> ""
150156 collection, "" -> "/" <> collection
151151- collection, rkey -> "/" <> string.join([collection, rkey], "/")
157157+ collection, rkey -> "/" <> collection <> "/" <> rkey
152158 }
153159154160 "at://" <> host <> path
+1-1
src/possum/nsid.gleam
···11//// Namespaced Identifiers (NSIDs) are used to reference Lexicon schemas for
22-//// records, XRPC endpoints, and more. For example, com.atproto.sync.getRecord.
22+//// records, XRPC endpoints, and more. For example, `com.atproto.sync.getRecord`.
33////
44//// The basic structure and semantics of an NSID are a fully-qualified hostname
55//// in reverse domain-name order, followed by an additional name segment.
+2-2
test/possum_test/at_uri_test.gleam
···1313 "at://foo.com/com.example.foo/123"
1414 |> at_uri.parse
15151616- let assert Error(at_uri.InvalidHandleAuthority(_)) =
1717- "at://example.com:3000"
1616+ let assert Error(at_uri.InvalidDidAuthority(_)) =
1717+ "at://did:wibblewobble.com:3000"
1818 |> at_uri.parse
19192020 let assert Error(at_uri.InvalidHandleAuthority(_)) =