mount public data from the atmosphere to a virtual filesystem (macos only) pdfs.at
0
fork

Configure Feed

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

feat(atproto): add getRecord typed endpoint

+55
+21
Packages/ATProto/Sources/ATProto/XRPC/GetRecordOutput.swift
··· 1 + import Foundation 2 + 3 + public struct GetRecordOutput: Decodable, Sendable { 4 + public let uri: String 5 + public let cid: String? 6 + /// Pretty-printed, sorted-keys JSON bytes of the record value. 7 + public let value: Data 8 + 9 + enum CodingKeys: String, CodingKey { case uri, cid, value } 10 + 11 + public init(from decoder: Decoder) throws { 12 + let c = try decoder.container(keyedBy: CodingKeys.self) 13 + uri = try c.decode(String.self, forKey: .uri) 14 + cid = try c.decodeIfPresent(String.self, forKey: .cid) 15 + let any = try c.decode(AnyDecodable.self, forKey: .value) 16 + value = try JSONSerialization.data( 17 + withJSONObject: any.value, 18 + options: [.prettyPrinted, .sortedKeys] 19 + ) 20 + } 21 + }
+15
Packages/ATProto/Sources/ATProto/XRPC/XRPCEndpoints.swift
··· 25 25 return try await get(nsid: "com.atproto.repo.listRecords", params: params) 26 26 } 27 27 } 28 + 29 + // MARK: - getRecord 30 + 31 + public extension XRPCClient { 32 + func getRecord( 33 + repo: String, 34 + collection: String, 35 + rkey: String, 36 + cid: String? = nil 37 + ) async throws -> GetRecordOutput { 38 + var params: [String: String] = ["repo": repo, "collection": collection, "rkey": rkey] 39 + if let cid { params["cid"] = cid } 40 + return try await get(nsid: "com.atproto.repo.getRecord", params: params) 41 + } 42 + }
+19
Packages/ATProto/Tests/ATProtoTests/XRPCEndpointsTests.swift
··· 52 52 #expect(out.records[0].uri == "at://did:plc:abc/app.bsky.feed.post/3l5xq2abc") 53 53 #expect(out.cursor == "next-page") 54 54 } 55 + 56 + @Test("getRecord returns uri + cid + pretty value bytes") 57 + func getRecord() async throws { 58 + let (client, session) = makeClient { request in 59 + #expect(request.url?.path == "/xrpc/com.atproto.repo.getRecord") 60 + return .json(#"{"uri":"at://did:plc:abc/app.bsky.feed.post/3l5xq2abc","cid":"bafyreibyvxuebctujncksacu3qfxsv6pzm7z67vfrftndn6pzhknf7g5me","value":{"$type":"app.bsky.feed.post","text":"hello","createdAt":"2026-04-17T00:00:00Z"}}"#) 61 + } 62 + defer { URLProtocolStub.reset(session: session) } 63 + 64 + let out = try await client.getRecord( 65 + repo: "did:plc:abc", 66 + collection: "app.bsky.feed.post", 67 + rkey: "3l5xq2abc", 68 + cid: nil 69 + ) 70 + #expect(out.uri == "at://did:plc:abc/app.bsky.feed.post/3l5xq2abc") 71 + let pretty = String(data: out.value, encoding: .utf8)! 72 + #expect(pretty.contains("\"hello\"")) 73 + } 55 74 }