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

Configure Feed

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

possum: functions now take `nsid.Nsid` and `handle.Handle` as parameters instead of String

kacaii.dev (Jul 11, 2026, 12:17 PM -0300) f19bbb6d 7fa1586c

+54 -22
+9 -1
CHANGELOG.md
··· 13 13 - `at_uri` module for validating at-uris 14 14 - `handle` module for validating atproto handles 15 15 16 + ### Removed 17 + 18 + - `list_standard_documents` was removed, its functionality can be replace by 19 + calling `list_records` and passing the nsid as "standard.site.document" 20 + 16 21 ### Changed 17 22 18 23 - All functions now use `prepend_header` instead of `set_header`. 19 24 - Renamed `did.DidError` to `did.ParseError` 20 25 - Rename `did.InvalidFormat` to `did.InvalidSyntax` 21 26 - Rename `handle.InvalidFormat` to `handle.InvalidSyntax` 22 - - `resolve_handle` now takes a `handle.Handle` as parameter instead of a string 27 + - `resolve_handle` and `resolve_well_known_did` now take a `handle.Handle` as 28 + parameter instead of a regular `String` 29 + - `resolve_handle` now takes a `handle.Handle` as parameter instead of a `String` 30 + - Functions now take a parsed `nsid.Nsid` as the `collection` parameter
+43 -20
src/possum.gleam
··· 37 37 import gleam/option 38 38 import possum/did 39 39 import possum/handle 40 + import possum/nsid 40 41 41 42 /// Documentation: [/xrpc/com.atproto.repo](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo) 42 43 const com_atproto_repo = "xrpc/com.atproto.repo" ··· 112 113 /// 113 114 /// ```gleam 114 115 /// import gleam/http/request 116 + /// import possum/handle 115 117 /// import possum 118 + /// 119 + /// let assert Ok(handle) = handle.parse("gleam.run") 116 120 /// 117 121 /// request.new() 118 - /// |> possum.resolve_well_known_did("gleam.run") 122 + /// |> possum.resolve_well_known_did(handle) 119 123 /// ``` 120 124 /// 121 125 /// ## Response ··· 127 131 /// Documentation: [HTTPS well-known Method](https://atproto.com/specs/handle#https-well-known-method) 128 132 pub fn resolve_well_known_did( 129 133 request: request.Request(_), 130 - host host: String, 134 + handle: handle.Handle, 131 135 ) -> request.Request(_) { 132 136 request 133 - |> request.set_host(host) 137 + |> request.set_host(handle.to_string(handle)) 134 138 |> request.set_method(http.Get) 135 139 |> request.set_path(".well-known/atproto-did") 136 140 } ··· 145 149 /// 146 150 /// ```gleam 147 151 /// import gleam/http/request 152 + /// import possum/handle 148 153 /// import possum 154 + /// 155 + /// let assert Ok(handle) = handle.parse("gleam.run") 149 156 /// 150 157 /// let request = 151 158 /// request.new() 152 159 /// |> request.set_host("slingshot.microcosm.blue") 153 - /// |> possum.resolve_handle("gleam.run") 160 + /// |> possum.resolve_handle(handle) 154 161 /// ``` 155 162 /// 156 163 /// ## Response ··· 411 418 /// 412 419 /// ```gleam 413 420 /// import gleam/http/request 421 + /// import possum/nsid 422 + /// import possum/did 414 423 /// import possum 415 424 /// 425 + /// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") 426 + /// let assert Ok(collection) = nsid.parse("wibble.wobble.woo") 427 + /// 416 428 /// let request = 417 429 /// request.new() 418 430 /// |> request.set_host("personal.data-server.pds") 419 431 /// |> possum.authorized("access-token") 420 432 /// |> possum.create_record( 421 433 /// did, 434 + /// collection:, 422 435 /// rkey: "wibble", 423 - /// collection: "wibble.wobble.woo", 424 436 /// record: [], 425 437 /// swap_commit: option.None, 426 438 /// validate: option.None, ··· 445 457 pub fn create_record( 446 458 request: request.Request(_), 447 459 did: did.Did, 448 - collection collection: String, 460 + collection nsid: nsid.Nsid, 449 461 rkey rkey: option.Option(String), 450 462 record record: List(#(String, json.Json)), 451 463 swap_commit swap_commit: option.Option(String), 452 464 validate validate: option.Option(Bool), 453 465 ) -> request.Request(_) { 454 466 let body = [ 455 - #("collection", json.string(collection)), 467 + #("collection", json.string(nsid.to_string(nsid))), 456 468 #("record", json.object(record)), 457 469 #("repo", json.string(did.to_string(did))), 458 470 ] ··· 492 504 /// import gleam/http/request 493 505 /// import possum 494 506 /// 507 + /// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") 508 + /// let assert Ok(collection) = nsid.parse("site.standard.document") 509 + /// 495 510 /// let request = 496 511 /// request.new() 497 512 /// |> request.set_host("slingshot.microcosm.blue") 498 513 /// |> possum.get_record( 499 514 /// did, 500 - /// rkey: "3mn6n3lvibc2b", 501 - /// collection: "site.standard.document", 515 + /// collection:, 516 + /// rkey: "mn6n3lvibc2b", 502 517 /// cursor: option.None, 503 518 /// cid: option.None, 504 519 /// ) ··· 519 534 pub fn get_record( 520 535 request: request.Request(_), 521 536 did: did.Did, 522 - collection collection: String, 537 + collection nsid: nsid.Nsid, 523 538 rkey rkey: String, 524 539 cid cid: option.Option(String), 525 540 ) -> request.Request(_) { 526 541 let query = [ 527 542 #("repo", did.to_string(did)), 528 543 #("rkey", rkey), 529 - #("collection", collection), 544 + #("collection", nsid.to_string(nsid)), 530 545 ] 531 546 532 547 let query = case cid { ··· 549 564 /// import gleam/http/request 550 565 /// import possum 551 566 /// 567 + /// let assert Ok(collection) = nsid.parse("site.standard.document") 568 + /// 552 569 /// let request = 553 570 /// request.new() 554 571 /// |> request.set_host("personal.data-server.pds") 555 572 /// |> possum.list_records( 556 573 /// did, 557 - /// collection: "site.standard.document", 574 + /// collection:, 558 575 /// limit: option.Some(3), 559 576 /// cursor: option.None, 560 577 /// reverse: option.None, ··· 580 597 pub fn list_records( 581 598 request: request.Request(_), 582 599 did: did.Did, 583 - collection collection: String, 600 + collection nsid: nsid.Nsid, 584 601 limit limit: option.Option(Int), 585 602 cursor cursor: option.Option(String), 586 603 reverse reverse: option.Option(Bool), 587 604 ) -> request.Request(_) { 588 605 let query = [ 589 606 #("repo", did.to_string(did)), 590 - #("collection", collection), 607 + #("collection", nsid.to_string(nsid)), 591 608 ] 592 609 593 610 let query = case limit { ··· 626 643 /// ```gleam 627 644 /// import gleam/http/request 628 645 /// import possum 646 + /// 647 + /// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") 648 + /// let assert Ok(collection) = nsid.parse("wibble.wobble.woo") 629 649 /// 630 650 /// let request = 631 651 /// request.new() ··· 633 653 /// |> possum.authorized("access-token") 634 654 /// |> possum.delete_record( 635 655 /// did, 636 - /// collection: "target.collection.data", 656 + /// collection:, 637 657 /// rkey: "wibble-wobble", 638 658 /// swap_commit: option.None, 639 659 /// swap_record: option.None, ··· 655 675 pub fn delete_record( 656 676 request: request.Request(_), 657 677 did: did.Did, 658 - collection collection: String, 678 + collection nsid: nsid.Nsid, 659 679 rkey rkey: String, 660 680 swap_commit swap_commit: option.Option(String), 661 681 swap_record swap_record: option.Option(String), 662 682 ) -> request.Request(_) { 663 683 let body = [ 664 684 #("repo", json.string(did.to_string(did))), 665 - #("collection", json.string(collection)), 685 + #("collection", json.string(nsid.to_string(nsid))), 666 686 #("rkey", json.string(rkey)), 667 687 ] 668 688 ··· 706 726 /// import gleam/http/request 707 727 /// import possum 708 728 /// 729 + /// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") 730 + /// let assert Ok(collection) = nsid.parse("target.collection.data") 731 + /// 709 732 /// let request = 710 733 /// request.new() 711 734 /// |> request.set_host("personal.data-server.pds") 712 735 /// |> possum.authorized("access-token") 713 736 /// |> possum.put_record( 714 737 /// did, 715 - /// collection: "target.collection.data", 738 + /// collection:, 716 739 /// rkey: "wibble-wobble", 717 740 /// record: [], 718 741 /// swap_commit: option.None, ··· 739 762 pub fn put_record( 740 763 request: request.Request(_), 741 764 did: did.Did, 742 - collection collection: String, 765 + collection nsid: nsid.Nsid, 743 766 rkey rkey: String, 744 767 record record: List(#(String, json.Json)), 745 768 swap_commit swap_commit: option.Option(String), ··· 747 770 validate validate: option.Option(Bool), 748 771 ) -> request.Request(_) { 749 772 let body = [ 750 - #("collection", json.string(collection)), 773 + #("collection", json.string(nsid.to_string(nsid))), 751 774 #("record", json.object(record)), 752 775 #("repo", json.string(did.to_string(did))), 753 776 #("rkey", json.string(rkey)),
+2 -1
test/possum_test.gleam
··· 13 13 import possum 14 14 import possum/did 15 15 import possum/handle 16 + import possum/nsid 16 17 17 18 pub fn main() -> Nil { 18 19 gleeunit.main() ··· 138 139 139 140 pub fn get_record_test() -> Nil { 140 141 let context = global_data() 141 - let collection = "app.bsky.actor.profile" 142 + let assert Ok(collection) = nsid.parse("app.bsky.actor.profile") 142 143 143 144 let assert Ok(response) = 144 145 request.new()