๐Ÿ€ ATproto library for gleam
atproto library gleam
35

Configure Feed

Select the types of activity you want to include in your feed.

possum: add more examples to the new modules

kacaii.dev (Jul 11, 2026, 7:43 PM -0300) fbe14839 c941d027

+82 -6
+44 -6
src/possum/at_uri.gleam
··· 3 3 //// 4 4 //// AT URIs are not content-addressed, so the contents of the record they 5 5 //// refer to may also change over time. 6 + //// 7 + //// Documentation: [AT URI Scheme](https://atproto.com/specs/at-uri-scheme) 6 8 7 9 import gleam/result 8 10 import gleam/string ··· 12 14 pub type ParseError { 13 15 /// Only "at://" is supported 14 16 InvalidScheme(value: String) 17 + /// Scheme is missing from the URI 18 + MissingScheme 15 19 /// Authority not a valid Handle 16 20 InvalidHandleAuthority(reason: handle.ParseError) 17 21 /// Authority not a valid DID ··· 47 51 ) 48 52 } 49 53 50 - // Return the authority part of the Uri 54 + /// Return the authority part of the Uri 55 + /// 56 + /// ## Examples 57 + /// 58 + /// ```gleam 59 + /// import possum/at_uri 60 + /// 61 + /// let string = "at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g" 62 + /// let assert Ok(at_uri) = at_uri.parse(string) 63 + /// 64 + /// assert at_uri.authority(at_uri) == "did:plc:vwzwgnygau7ed7b7wt5ux7y2" 65 + /// ``` 51 66 pub fn authority(self: AtUri) -> Authority { 52 67 self.authority 53 68 } 54 69 55 - // Return the collecion part of the Uri 70 + /// Return the collecion part of the Uri 71 + /// 72 + /// ## Examples 73 + /// 74 + /// ```gleam 75 + /// import possum/at_uri 76 + /// 77 + /// let string = "at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g" 78 + /// let assert Ok(at_uri) = at_uri.parse(string) 79 + /// 80 + /// assert at_uri.collection(at_uri) == "app.bsky.feed.post" 81 + /// ``` 56 82 pub fn collection(self: AtUri) -> String { 57 83 self.collection 58 84 } 59 85 60 - // Return the rkey part of the Uri 86 + /// Return the rkey part of the Uri 87 + /// 88 + /// ## Examples 89 + /// 90 + /// ```gleam 91 + /// import possum/at_uri 92 + /// 93 + /// let string = "at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g" 94 + /// let assert Ok(at_uri) = at_uri.parse(string) 95 + /// 96 + /// assert at_uri.rkey(at_uri) == "3k5nobkf2w72g" 97 + /// ``` 61 98 pub fn rkey(self: AtUri) -> String { 62 99 self.rkey 63 100 } ··· 74 111 /// 75 112 /// let string = "at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g" 76 113 /// let assert Ok(at_uri) = at_uri.parse(string) 114 + /// ``` 77 115 pub fn parse(content: String) -> Result(AtUri, ParseError) { 78 116 use value <- result.try(case content { 79 117 "at://" <> rest -> Ok(rest) ··· 82 120 _ -> 83 121 case string.split_once(content, on: "://") { 84 122 Ok(scheme) -> Error(InvalidScheme(value: scheme.0)) 85 - Error(_) -> Error(InvalidScheme(value: "")) 123 + Error(_) -> Error(MissingScheme) 86 124 } 87 125 }) 88 126 ··· 124 162 Error(reason) -> Error(InvalidDidAuthority(reason:)) 125 163 } 126 164 127 - _handle -> 165 + string -> 128 166 case handle.parse(string) { 129 167 Ok(value) -> Ok(Handle(value:)) 130 168 Error(reason) -> Error(InvalidHandleAuthority(reason:)) ··· 143 181 /// "at://did:plc:vwzwgnygau7ed7b7wt5ux7y2/app.bsky.feed.post/3k5nobkf2w72g" 144 182 /// 145 183 /// let assert Ok(at_uri) = at_uri.parse(string) 146 - /// assert at.to_string(at_uri) == string 184 + /// assert at_uri.to_string(at_uri) == string 147 185 /// ``` 148 186 pub fn to_string(self: AtUri) -> String { 149 187 let host = case self.authority {
+23
src/possum/handle.gleam
··· 2 2 //// but they can be opaque and unfriendly for human use. Handles are mutable 3 3 //// and human-friendly account usernames, in the form of a DNS hostname. 4 4 //// For example, "user.example.com". 5 + //// 6 + //// Documentation: [Handle](https://atproto.com/specs/handle) 5 7 6 8 import gleam/list 7 9 import gleam/regexp ··· 39 41 Handle(value: String) 40 42 } 41 43 44 + /// Convert a handle into a String 45 + /// 46 + /// ## Examples 47 + /// 48 + /// ```gleam 49 + /// import possum/handle 50 + /// 51 + /// let string = "gleam.run" 52 + /// let assert Ok(handle) = handle.parse(string) 53 + /// 54 + /// assert handle.to_string(handle) == "gleam.run" 55 + /// ``` 42 56 pub fn to_string(handle: Handle) -> String { 43 57 handle.value 44 58 } 45 59 46 60 /// Parse a string into a valid `Handle` type 47 61 /// If the value is not a valid string then an error is returned. 62 + /// 63 + /// ## Examples 64 + /// 65 + /// ```gleam 66 + /// import possum/handle 67 + /// 68 + /// let string = "gleam.run" 69 + /// let assert Ok(handle) = handle.parse(string) 70 + /// ``` 48 71 pub fn parse(content: String) -> Result(Handle, ParseError) { 49 72 use with <- result.try( 50 73 regexp.from_string(pattern)
+15
src/possum/nsid.gleam
··· 4 4 //// The basic structure and semantics of an NSID are a fully-qualified hostname 5 5 //// in reverse domain-name order, followed by an additional name segment. 6 6 //// The hostname part is the **domain authority**, and the final segment is the **name**. 7 + //// 8 + //// Documentation: [Namespaced Identifiers](https://atproto.com/specs/nsid) 7 9 8 10 import gleam/regexp 9 11 import gleam/result 10 12 13 + /// Available on: https://atproto.com/specs/nsid#nsid-syntax 11 14 const pattern = "^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$" 12 15 13 16 pub type ParseError { ··· 22 25 Nsid(value: String) 23 26 } 24 27 28 + /// Convert a NSID into a String 29 + /// 30 + /// ## Examples 31 + /// 32 + /// ```gleam 33 + /// import possum/nsid 34 + /// 35 + /// let string = "com.atproto.sync.getRecord" 36 + /// 37 + /// let assert Ok(nsid) = nsid.parse(string) 38 + /// assert nsid.to_string(nsid) == string 39 + /// ``` 25 40 pub fn to_string(nsid: Nsid) -> String { 26 41 nsid.value 27 42 }