this repo has no description
2
fork

Configure Feed

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

update to use latest CoreAtProtocol:

+69 -45
+13 -4
Package.resolved
··· 7 7 "location" : "https://tangled.org/@sparrowtek.com/CoreATProtocol", 8 8 "state" : { 9 9 "branch" : "main", 10 - "revision" : "903399247010bfff10d55177a9f1195f8717b710" 10 + "revision" : "d50e4c6a1c92a5e777fe5c642173be03b14116e5" 11 11 } 12 12 }, 13 13 { ··· 20 20 } 21 21 }, 22 22 { 23 + "identity" : "networkingkit", 24 + "kind" : "remoteSourceControl", 25 + "location" : "https://github.com/SparrowTek/NetworkingKit.git", 26 + "state" : { 27 + "branch" : "main", 28 + "revision" : "15378e3cb097b485a20a1ddc705fea1455568354" 29 + } 30 + }, 31 + { 23 32 "identity" : "oauthenticator", 24 33 "kind" : "remoteSourceControl", 25 34 "location" : "https://github.com/radmakr/OAuthenticator.git", 26 35 "state" : { 27 36 "branch" : "CoreAtProtocol", 28 - "revision" : "e382a28c7f7dbdb36ec358b1324e0d2320249c70" 37 + "revision" : "e7ccc64a121cd6435137040535ca70b3fb1e1edb" 29 38 } 30 39 }, 31 40 { ··· 42 51 "kind" : "remoteSourceControl", 43 52 "location" : "https://github.com/apple/swift-certificates.git", 44 53 "state" : { 45 - "revision" : "7d5f6124c91a2d06fb63a811695a3400d15a100e", 46 - "version" : "1.17.1" 54 + "revision" : "24ccdeeeed4dfaae7955fcac9dbf5489ed4f1a25", 55 + "version" : "1.18.0" 47 56 } 48 57 }, 49 58 {
+7 -11
Sources/bskyKit/BskyAPI.swift
··· 7 7 8 8 import Foundation 9 9 import CoreATProtocol 10 - 11 - struct SendableAny: @unchecked Sendable { 12 - let value: Any 13 - } 10 + import NetworkingKit 14 11 15 12 enum BskyAPI { 16 13 // Actor endpoints ··· 70 67 case updateSeen(seenAt: Date) 71 68 72 69 // Generic endpoints for newer/less-common lexicons. 73 - case xrpcQuery(id: String, parameters: [String: SendableAny]) 74 - case xrpcProcedure(id: String, body: [String: SendableAny]?) 70 + case xrpcQuery(id: String, parameters: Parameters) 71 + case xrpcProcedure(id: String, body: Parameters?) 75 72 case xrpcDataProcedure(id: String, data: Data, contentType: String, accept: String?) 76 73 } 77 74 78 75 extension BskyAPI: EndpointType { 79 - public var baseURL: URL { 76 + public var baseURL: URL? { 80 77 get async { 81 78 guard let host = await APEnvironment.current.host, 82 79 let url = URL(string: host) else { 83 - return URL(string: "https://invalid.invalid")! 80 + return nil 84 81 } 85 82 return url 86 83 } ··· 322 319 ])) 323 320 324 321 case .xrpcQuery(_, let parameters): 325 - let unboxed = parameters.mapValues(\.value) 326 322 if parameters.isEmpty { 327 323 return .request 328 324 } 329 - return .requestParameters(encoding: .urlEncoding(parameters: unboxed)) 325 + return .requestParameters(encoding: .urlEncoding(parameters: parameters)) 330 326 331 327 case .xrpcProcedure(_, let body): 332 328 guard let body else { return .request } 333 - return .requestParameters(encoding: .jsonEncoding(parameters: body.mapValues(\.value))) 329 + return .requestParameters(encoding: .jsonEncoding(parameters: body)) 334 330 335 331 case .xrpcDataProcedure(_, let data, _, _): 336 332 return .requestParameters(encoding: .jsonDataEncoding(data: data))
+13 -20
Sources/bskyKit/BskyService.swift
··· 7 7 8 8 import Foundation 9 9 import CoreATProtocol 10 + import NetworkingKit 10 11 11 12 /// The main service for reading Bluesky social data. 12 13 /// ··· 60 61 /// - ``updateSeen(at:)`` 61 62 @APActor 62 63 public struct BskyService: Sendable { 63 - private let router: NetworkRouter<BskyAPI> = { 64 - let router = NetworkRouter<BskyAPI>(decoder: .atDecoder) 65 - router.delegate = APEnvironment.current.routerDelegate 66 - return router 67 - }() 68 64 69 65 /// Creates a new BskyService instance. 70 66 /// ··· 72 68 /// `setup(hostURL:accessJWT:refreshJWT:)`. 73 69 public init() {} 74 70 75 - private func execute<T: Decodable>(_ endpoint: BskyAPI) async throws -> T { 71 + private func execute<T: Decodable & Sendable>(_ endpoint: BskyAPI) async throws -> T { 76 72 try ensureHostConfigured() 77 - return try await router.execute(endpoint) 73 + let delegate = APEnvironment.current.routerDelegate 74 + return try await RouterCache.bsky(delegate: delegate).execute(endpoint) 78 75 } 79 76 80 - private func executeQuery<T: Decodable>( 77 + private func executeQuery<T: Decodable & Sendable>( 81 78 _ id: String, 82 79 parameters: Parameters = [:] 83 80 ) async throws -> T { 84 - try await execute(.xrpcQuery(id: id, parameters: box(parameters))) 81 + try await execute(.xrpcQuery(id: id, parameters: parameters)) 85 82 } 86 83 87 - private func executeProcedure<T: Decodable>( 84 + private func executeProcedure<T: Decodable & Sendable>( 88 85 _ id: String, 89 86 body: Parameters? = nil 90 87 ) async throws -> T { 91 - try await execute(.xrpcProcedure(id: id, body: body.map(box))) 88 + try await execute(.xrpcProcedure(id: id, body: body)) 92 89 } 93 90 94 - private func executeDataProcedure<T: Decodable>( 91 + private func executeDataProcedure<T: Decodable & Sendable>( 95 92 _ id: String, 96 93 data: Data, 97 94 contentType: String, ··· 103 100 contentType: contentType, 104 101 accept: accept 105 102 )) 106 - } 107 - 108 - private func box(_ parameters: Parameters) -> [String: SendableAny] { 109 - parameters.mapValues { SendableAny(value: $0) } 110 103 } 111 104 112 105 // MARK: - Actor ··· 417 410 // MARK: - Priority 2: Account, Bookmark, and Graph Collections 418 411 419 412 /// Updates actor preferences payload. 420 - public func putPreferences(_ preferences: [String: Any]) async throws { 413 + public func putPreferences(_ preferences: [String: any Sendable]) async throws { 421 414 let _: EmptyResponse = try await executeProcedure( 422 415 "app.bsky.actor.putPreferences", 423 416 body: ["preferences": preferences] ··· 460 453 } 461 454 462 455 /// Sends interaction signals to ranking services. 463 - public func sendInteractions(_ interactions: [[String: Any]]) async throws { 456 + public func sendInteractions(_ interactions: [[String: any Sendable]]) async throws { 464 457 let _: EmptyResponse = try await executeProcedure( 465 458 "app.bsky.feed.sendInteractions", 466 459 body: ["interactions": interactions] ··· 579 572 } 580 573 581 574 /// Upserts an activity subscription for a subject. 582 - public func putActivitySubscription(subject: String, activitySubscription: [String: Any]) async throws -> JSONValue { 575 + public func putActivitySubscription(subject: String, activitySubscription: [String: any Sendable]) async throws -> JSONValue { 583 576 try await executeProcedure( 584 577 "app.bsky.notification.putActivitySubscription", 585 578 body: [ ··· 598 591 } 599 592 600 593 /// Updates v2 notification preference payload. 601 - public func putNotificationPreferencesV2(_ preferences: [String: Any]) async throws -> JSONValue { 594 + public func putNotificationPreferencesV2(_ preferences: [String: any Sendable]) async throws -> JSONValue { 602 595 try await executeProcedure("app.bsky.notification.putPreferencesV2", body: preferences) 603 596 } 604 597
+29
Sources/bskyKit/Configuration.swift
··· 1 1 import Foundation 2 2 import CoreATProtocol 3 + import NetworkingKit 3 4 4 5 public enum BskyKitConfigurationError: Error, LocalizedError, Sendable { 5 6 case hostNotConfigured ··· 24 25 throw BskyKitConfigurationError.invalidHostURL(host) 25 26 } 26 27 } 28 + 29 + @NetworkingKitActor 30 + enum RouterCache { 31 + private static var _bskyRouter: NetworkRouter<BskyAPI>? 32 + private static var _repoRouter: NetworkRouter<RepoAPI>? 33 + 34 + static func bsky(delegate: NetworkRouterDelegate) -> NetworkRouter<BskyAPI> { 35 + if let router = _bskyRouter { 36 + router.delegate = delegate 37 + return router 38 + } 39 + let router = NetworkRouter<BskyAPI>(decoder: .atDecoder) 40 + router.delegate = delegate 41 + _bskyRouter = router 42 + return router 43 + } 44 + 45 + static func repo(delegate: NetworkRouterDelegate) -> NetworkRouter<RepoAPI> { 46 + if let router = _repoRouter { 47 + router.delegate = delegate 48 + return router 49 + } 50 + let router = NetworkRouter<RepoAPI>(decoder: .atDecoder) 51 + router.delegate = delegate 52 + _repoRouter = router 53 + return router 54 + } 55 + }
+3 -2
Sources/bskyKit/RepoAPI.swift
··· 7 7 8 8 import Foundation 9 9 import CoreATProtocol 10 + import NetworkingKit 10 11 11 12 /// API endpoints for com.atproto.repo.* lexicons 12 13 enum RepoAPI: Sendable { ··· 23 24 } 24 25 25 26 extension RepoAPI: EndpointType { 26 - public var baseURL: URL { 27 + public var baseURL: URL? { 27 28 get async { 28 29 guard let host = await APEnvironment.current.host, 29 30 let url = URL(string: host) else { 30 - return URL(string: "https://invalid.invalid")! 31 + return nil 31 32 } 32 33 return url 33 34 }
+4 -8
Sources/bskyKit/RepoService.swift
··· 7 7 8 8 import Foundation 9 9 import CoreATProtocol 10 + import NetworkingKit 10 11 11 12 /// Service for repository operations (create, delete, update records) 12 13 @APActor 13 14 public struct RepoService: Sendable { 14 - private let router: NetworkRouter<RepoAPI> = { 15 - let router = NetworkRouter<RepoAPI>(decoder: .atDecoder) 16 - router.delegate = APEnvironment.current.routerDelegate 17 - return router 18 - }() 19 - 20 15 public init() {} 21 16 22 - private func execute<T: Decodable>(_ endpoint: RepoAPI) async throws -> T { 17 + private func execute<T: Decodable & Sendable>(_ endpoint: RepoAPI) async throws -> T { 23 18 try ensureHostConfigured() 24 - return try await router.execute(endpoint) 19 + let delegate = APEnvironment.current.routerDelegate 20 + return try await RouterCache.repo(delegate: delegate).execute(endpoint) 25 21 } 26 22 27 23 // MARK: - Record Operations