Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-api-guidelines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@germ-network/atprotoclient": minor
---

Adopt Swift naming conventions in XRPC query parameters, CID string access, and optional unwrapping. Pin AtprotoTypes to the merged API update and GermConvenience to 0.15.0. See the upstream dependency changesets for the new names and compatibility period.
10 changes: 5 additions & 5 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/germ-network/AtprotoTypes.git",
// 0.8.0: Atproto.RecordSwap, for putRecord's explicit-null swapRecord.
from: "0.8.0"
// 0.11.0 includes the Swift API naming updates.
from: "0.11.0"
),
.package(
url: "https://github.com/germ-network/GermConvenience.git",
// 0.14.0: RedirectRefusingHTTPFetcher, required by the resolvers that
// screen a host once before fetching. 0.13.0 moved the URLSession
// conformers into GermConvenienceURLSession, so the portable targets
// here no longer reach URLSession.
from: "0.14.0"
from: "0.15.0"
),
.package(
url: "https://github.com/apple/swift-crypto.git",
Expand Down Expand Up @@ -64,7 +60,9 @@ let package = Package(
dependencies: [
"AtprotoClient", "AtprotoClientMocks",
.product(name: "GermConvenienceHTTP", package: "GermConvenience"),
.product(name: "GermConvenienceURLSession", package: "GermConvenience"),
.product(
name: "GermConvenienceURLSession",
package: "GermConvenience"),
]
),
]
Expand Down
4 changes: 2 additions & 2 deletions Sources/AtprotoClient/Agent/Agents/BskyAppAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public struct BskyAppViewAgent {

public static func blackskyAppView(resourceFetcher: HTTPFetcher) throws -> Self {
try .init(
serviceUrl: try URL(string: "https://api.blacksky.community").tryUnwrap,
serviceUrl: try URL(string: "https://api.blacksky.community").unwrapped,
resourceFetcher: resourceFetcher
)
}

public static func blueskyAppView(resourceFetcher: HTTPFetcher) throws -> Self {
try .init(
serviceUrl: try URL(string: "https://public.api.bsky.app").tryUnwrap,
serviceUrl: try URL(string: "https://public.api.bsky.app").unwrapped,
resourceFetcher: resourceFetcher
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Atproto.XRPC.ProxyCallable {
) async throws -> X.Output {
var request = try constructRequest(request, parameters: parameters)

request.headers[try .atprotoProxy.tryUnwrap] = proxy.headerValue
request.headers[try .atprotoProxy.unwrapped] = proxy.headerValue

return try await response(request)
.parse(X.self)
Expand All @@ -39,7 +39,7 @@ extension Atproto.XRPC.ProxyCallable {
input: input
)

request.headers[try .atprotoProxy.tryUnwrap] = proxy.headerValue
request.headers[try .atprotoProxy.unwrapped] = proxy.headerValue

return try await response(request)
.parse(X.self)
Expand Down
4 changes: 2 additions & 2 deletions Sources/AtprotoClient/Agent/XRPCRequestComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct XRPCRequestComponents: Sendable {
var components = try URLComponents(
url: serviceUrl,
resolvingAgainstBaseURL: false
).tryUnwrap
).unwrapped

//xrpc path must be top-level, not below a prefix
//https://atproto.com/specs/xrpc
Expand All @@ -47,7 +47,7 @@ public struct XRPCRequestComponents: Sendable {

return try .init(
method: method,
url: components.url.tryUnwrap,
url: components.url.unwrapped,
headerFields: headers,
body: body
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/AtprotoClient/BskyCDN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension Atproto {
// set through `percentEncodedPath` instead, on an already-escaped
// string.
built.percentEncodedPath =
"/img/\(kind.rawValue)/plain/\(try Self.pathSegment(did.rawValue))/\(try Self.pathSegment(blob.ref.link.string))@jpeg"
"/img/\(kind.rawValue)/plain/\(try Self.pathSegment(did.rawValue))/\(try Self.pathSegment(blob.ref.link.rawValue))@jpeg"
guard let url = built.url else {
throw Errors.invalidHost
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension Lexicon.App.Bsky.Actor {
self.actor = actor
}

public func asQueryItems() -> [URLQueryItem] {
public var queryItems: [URLQueryItem] {
[.init(name: "actor", value: actor.rawValue)]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension Lexicon.App.Bsky.Actor {
self.actor = actor
}

public func asQueryItems() -> [URLQueryItem] {
public var queryItems: [URLQueryItem] {
[.init(name: "actor", value: actor.rawValue)]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension Lexicon.App.Bsky.Graph {
}
}

public func asQueryItems() -> [URLQueryItem] {
public var queryItems: [URLQueryItem] {
var base: [URLQueryItem] = []
if let limit {
base.append(.init(name: "limit", value: limit.description))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension Lexicon.App.Bsky.Graph {
}
}

public func asQueryItems() -> [URLQueryItem] {
public var queryItems: [URLQueryItem] {
var base: [URLQueryItem] = [
.init(name: "actor", value: actor.rawValue)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension Lexicon.App.Bsky.Graph {
}
}

public func asQueryItems() -> [URLQueryItem] {
public var queryItems: [URLQueryItem] {
var base: [URLQueryItem] = [
.init(name: "actor", value: actor.rawValue)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension Lexicon.App.Bsky.Graph {
}
}

public func asQueryItems() -> [URLQueryItem] {
public var queryItems: [URLQueryItem] {
var base: [URLQueryItem] = [
.init(name: "actor", value: actor.rawValue)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension Lexicon.App.Bsky.Graph {
self.others = others
}

public func asQueryItems() -> [URLQueryItem] {
public var queryItems: [URLQueryItem] {
[URLQueryItem(name: "actor", value: actor.rawValue)]
+ (others ?? [])
.map {
Expand Down
4 changes: 2 additions & 2 deletions Sources/AtprotoClient/Resolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension Atproto.Resolver {
}

//if a did doc doesn't resolve it's an error
return try await resolve(did: did).tryUnwrap
return try await resolve(did: did).unwrapped
.verified(expecting: handle, did: did)
}

Expand All @@ -52,7 +52,7 @@ extension Atproto.Resolver {
try await resolve(did: did)?
.verified { unverifiedHandle in
try await resolve(handle: unverifiedHandle)
.tryUnwrap
.unwrapped
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/AtprotoClient/XRPC/Procedure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension Atproto.XRPC.Callable {

return .init(
relativePath: "/xrpc/" + X.Id.nsid.rawValue,
queryItems: queryParams.asQueryItems(),
queryItems: queryParams.queryItems,
headers: headerFields,
method: .post,
body: try X.Input.encode(input.schema)
Expand Down
2 changes: 1 addition & 1 deletion Sources/AtprotoClient/XRPC/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension Atproto.XRPC.Callable {
) throws -> XRPCRequestComponents {
.init(
relativePath: "/xrpc/" + X.Id.nsid.rawValue,
queryItems: parameters.asQueryItems(),
queryItems: parameters.queryItems,
headers: .init(
dictionaryLiteral: (.accept, X.outputEncoding.rawValue)
),
Expand Down
Loading
Loading