Skip to content

Commit

Permalink
Update package for Swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
rocxteady committed Oct 21, 2024
1 parent 998bf97 commit 9acab78
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 96 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/rocxteady/Resting.git",
"state" : {
"revision" : "667c7e7903e41ccd4ab8a39f4df0570a29f49ead",
"version" : "0.0.9"
"revision" : "d0e2284183fd85a820f915b33f08ce323e2d2823",
"version" : "1.0.0-beta.1"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -14,7 +14,7 @@ let package = Package(
targets: ["WPSwift"]),
],
dependencies: [
.package(url: "https://github.com/rocxteady/Resting.git", .upToNextMajor(from: "0.0.9")),
.package(url: "https://github.com/rocxteady/Resting.git", .upToNextMajor(from: "1.0.0-beta.1")),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand Down
4 changes: 2 additions & 2 deletions Sources/WPSwift/API/WPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import Combine
import Resting

public enum NetworkError: LocalizedError {
public enum NetworkError: LocalizedError, Sendable {
case urlMalformed
case api(Error)
case unknown
Expand All @@ -26,7 +26,7 @@ public enum NetworkError: LocalizedError {
}
}

public struct WPClient<RequestModel: Encodable, Response: Decodable> {
public struct WPClient<RequestModel: Encodable, Response: Decodable>: Sendable {
private let restClient: RestClient
private let requestConfig: RequestConfiguration

Expand Down
18 changes: 9 additions & 9 deletions Sources/WPSwift/API/WPClientConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import Foundation
import Resting

struct WPClientConfiguration {
enum ParameterType {
case object([String: Any])
case model(Encodable)
struct WPClientConfiguration: Sendable {
enum ParameterType: Sendable {
case object([String: any Sendable])
case model(Encodable & Sendable)
}

enum EndpointType {
enum EndpointType: Sendable {
case base(baseURL: String, endpoint: String)
case endpoint(String)
}
Expand All @@ -24,7 +24,7 @@ struct WPClientConfiguration {
let headers: [String: String]?
let parameterType: ParameterType?

init(endpoint: String, method: HTTPMethod = .get, parameters: [String : Any]?, encoding: HTTPEncoding = .urlEncoded, headers: [String: String]? = nil) {
init(endpoint: String, method: HTTPMethod = .get, parameters: [String : any Sendable]?, encoding: HTTPEncoding = .urlEncoded, headers: [String: String]? = nil) {
self.endpointType = .endpoint(endpoint)
self.method = method
self.encoding = encoding
Expand All @@ -36,7 +36,7 @@ struct WPClientConfiguration {
self.headers = headers
}

init(endpoint: String, method: HTTPMethod = .post, requestModel: Encodable?, encoding: HTTPEncoding = .json, headers: [String: String]? = nil) {
init(endpoint: String, method: HTTPMethod = .post, requestModel: (Encodable & Sendable)?, encoding: HTTPEncoding = .json, headers: [String: String]? = nil) {
self.endpointType = .endpoint(endpoint)
self.method = method
self.encoding = encoding
Expand All @@ -48,7 +48,7 @@ struct WPClientConfiguration {
self.headers = headers
}

init(baseURL: String, endpoint: String, method: HTTPMethod = .get, parameters: [String : Any]?, encoding: HTTPEncoding = .urlEncoded, headers: [String: String]? = nil) {
init(baseURL: String, endpoint: String, method: HTTPMethod = .get, parameters: [String : any Sendable]?, encoding: HTTPEncoding = .urlEncoded, headers: [String: String]? = nil) {
self.endpointType = .base(baseURL: baseURL, endpoint: endpoint)
self.method = method
self.encoding = encoding
Expand All @@ -60,7 +60,7 @@ struct WPClientConfiguration {
self.headers = headers
}

init(baseURL: String, endpoint: String, method: HTTPMethod = .post, requestModel: Encodable?, encoding: HTTPEncoding = .json, headers: [String: String]? = nil) {
init(baseURL: String, endpoint: String, method: HTTPMethod = .post, requestModel: (Encodable & Sendable)?, encoding: HTTPEncoding = .json, headers: [String: String]? = nil) {
self.endpointType = .base(baseURL: baseURL, endpoint: endpoint)
self.method = method
self.encoding = encoding
Expand Down
6 changes: 3 additions & 3 deletions Sources/WPSwift/API/WPEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import Foundation

enum WPEndpoint {
enum Posts {
enum WPEndpoint: Sendable {
enum Posts: Sendable {
case posts
case post(id: Int)
case search
Expand All @@ -25,7 +25,7 @@ enum WPEndpoint {
}
}

enum Categories {
enum Categories: Sendable {
case categories
case category(id: Int)

Expand Down
2 changes: 1 addition & 1 deletion Sources/WPSwift/Models/APIInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct APIInfo: Decodable {
public struct APIInfo: Decodable, Sendable {
public let name: String
public let description: String?
public let url: String?
Expand Down
2 changes: 1 addition & 1 deletion Sources/WPSwift/Models/AnyCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

// Because the WordPress API can return meta data with different value types,
// we can use the following general-purpose Codable struct:
public enum AnyCodable: Codable {
public enum AnyCodable: Codable, Sendable {
case double(Double)
case string(String)
case bool(Bool)
Expand Down
2 changes: 1 addition & 1 deletion Sources/WPSwift/Models/Author.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Author: Decodable {
public struct Author: Decodable, Sendable {
public let id: Int
public let name: String
public let description: String
Expand Down
6 changes: 3 additions & 3 deletions Sources/WPSwift/Models/Category.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct PostCategory: Decodable {
public struct PostCategory: Decodable, Sendable {
public let id: Int
public let count: Int
public let description: String
Expand All @@ -25,7 +25,7 @@ public struct PostCategory: Decodable {
}
}

public struct PostCategoryToCreate: Encodable {
public struct PostCategoryToCreate: Encodable, Sendable {
public let description: String
public let name: String
public let parent: Int
Expand All @@ -37,7 +37,7 @@ public struct PostCategoryToCreate: Encodable {
}
}

public struct PostCategoryToUpdate: Encodable {
public struct PostCategoryToUpdate: Encodable, Sendable {
public let id: Int
public let description: String
public let name: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/WPSwift/Models/EmbeddedContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct EmbeddedContent: Decodable {
public struct EmbeddedContent: Decodable, Sendable {
public var author: Author? {
_author?.first
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/WPSwift/Models/EmptyModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import Foundation

public struct EmptyModel: Encodable {
public struct EmptyModel: Encodable, Sendable {
public init() {}
}
6 changes: 3 additions & 3 deletions Sources/WPSwift/Models/FeaturedMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct FeaturedMedia: Codable {
public struct FeaturedMedia: Codable, Sendable {
public let id: Int
public let title: RenderedContent
public let caption: RenderedContent
Expand Down Expand Up @@ -36,7 +36,7 @@ public struct FeaturedMedia: Codable {
}
}

public struct MediaDetails: Codable {
public struct MediaDetails: Codable, Sendable {
public let width:Int
public let height: Int
public let sizes: [String: Size]
Expand All @@ -53,7 +53,7 @@ public struct MediaDetails: Codable {
}

// MARK: - Size
public struct Size: Codable {
public struct Size: Codable, Sendable {
public let width: Int
public let height: Int
public let sourceURL: String
Expand Down
18 changes: 9 additions & 9 deletions Sources/WPSwift/Models/Params.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

import Foundation

public enum OrderType: String, Decodable {
public enum OrderType: String, Decodable, Sendable {
case ascending = "asc"
case descending = "desc"
}

extension [String: Any] {
static func createParamsForPost(categories: [Int] = [], categoriesToExclude: [Int] = [], tags: [Int] = [], tagsToExclude: [Int] = []) -> [String: Any] {
extension [String: any Sendable] {
static func createParamsForPost(categories: [Int] = [], categoriesToExclude: [Int] = [], tags: [Int] = [], tagsToExclude: [Int] = []) -> [String: any Sendable] {
let categories = categories.map { "\($0)" }.joined(separator: ",")
let categoriesToExclude = categoriesToExclude.map { "\($0)" }.joined(separator: ",")
let tags = tags.map { "\($0)" }.joined(separator: ",")
let tagsToExclude = tagsToExclude.map { "\($0)" }.joined(separator: ",")
var params: [String: Any] = [
var params: [String: any Sendable] = [
"_embed": "",
"_fields":"id,date_gmt,modified_gmt,status,title,content,contentHTML,excerpt,author,featured_media,comment_status,categories,tags,link,_links"
]
Expand All @@ -37,13 +37,13 @@ extension [String: Any] {
return params
}

static func createParamsForPosts(page: Int = 1, perPage: Int = 10, order: OrderType = .descending, categories: [Int]? = nil, categoriesToExclude: [Int]? = nil, tags: [Int]? = nil, tagsToExclude: [Int]? = nil, include: [Int]? = nil) -> [String: Any] {
static func createParamsForPosts(page: Int = 1, perPage: Int = 10, order: OrderType = .descending, categories: [Int]? = nil, categoriesToExclude: [Int]? = nil, tags: [Int]? = nil, tagsToExclude: [Int]? = nil, include: [Int]? = nil) -> [String: any Sendable] {
let categories = categories?.map { "\($0)" }.joined(separator: ",")
let categoriesToExclude = categoriesToExclude?.map { "\($0)" }.joined(separator: ",")
let tags = tags?.map { "\($0)" }.joined(separator: ",")
let tagsToExclude = tagsToExclude?.map { "\($0)" }.joined(separator: ",")
let include = include?.map { "\($0)" }.joined(separator: ",")
var params: [String: Any] = [
var params: [String: any Sendable] = [
"page": page,
"per_page": perPage,
"order": order.rawValue,
Expand All @@ -68,7 +68,7 @@ extension [String: Any] {
return params
}

static func createParamsForSearchPosts(term: String, page: Int = 1, perPage: Int = 10) -> [String: Any] {
static func createParamsForSearchPosts(term: String, page: Int = 1, perPage: Int = 10) -> [String: any Sendable] {
[
"search": term,
"page": page,
Expand All @@ -78,7 +78,7 @@ extension [String: Any] {
]
}

static func createParamsForCategories(page: Int = 1, perPage: Int = 100, order: OrderType = .descending) -> [String: Any] {
static func createParamsForCategories(page: Int = 1, perPage: Int = 100, order: OrderType = .descending) -> [String: any Sendable] {
[
"page": page,
"per_page": perPage,
Expand All @@ -89,7 +89,7 @@ extension [String: Any] {
]
}

static func createParamsForCategory() -> [String: Any] {
static func createParamsForCategory() -> [String: any Sendable] {
[
"_fields":"id,count,description,link,name,parent"
]
Expand Down
22 changes: 11 additions & 11 deletions Sources/WPSwift/Models/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public enum CommentStatus: String, Decodable {
public enum CommentStatus: String, Codable, Sendable {
case `open`
case closed
case close
Expand All @@ -17,7 +17,7 @@ public enum CommentStatus: String, Decodable {
}
}

public struct Post: Decodable {
public struct Post: Decodable, Sendable {
public let id: Int
public let date: Date?
public let modified: Date?
Expand Down Expand Up @@ -107,35 +107,35 @@ public struct Post: Decodable {
}
}

public struct PostToCreate: Encodable {
public struct PostToCreate: Encodable, Sendable {
public let title: RenderedContent
public let content: RenderedContent
public let format: String?
public let sticky: Bool?
public let excerpt: RenderedContent?
public let status: String?
public let password: String?
public let comment_status: String?
public let commentStatus: CommentStatus?
public let ping_status: String?
public let categories: [Int]
public let tags: [Int]

public init(title: RenderedContent, content: RenderedContent, format: String? = nil, sticky: Bool? = nil, excerpt: RenderedContent? = nil, status: String? = nil, password: String? = nil, comment_status: String? = nil, ping_status: String? = nil, categories: [Int], tags: [Int]) {
public init(title: RenderedContent, content: RenderedContent, format: String? = nil, sticky: Bool? = nil, excerpt: RenderedContent? = nil, status: String? = nil, password: String? = nil, commentStatus: CommentStatus? = nil, ping_status: String? = nil, categories: [Int], tags: [Int]) {
self.title = title
self.content = content
self.format = format
self.sticky = sticky
self.excerpt = excerpt
self.status = status
self.password = password
self.comment_status = comment_status
self.commentStatus = commentStatus
self.ping_status = ping_status
self.categories = categories
self.tags = tags
}
}

public struct PostToUpdate: Encodable {
public struct PostToUpdate: Encodable, Sendable {
public let id: Int
public let title: RenderedContent
public let content: RenderedContent
Expand All @@ -144,12 +144,12 @@ public struct PostToUpdate: Encodable {
public let excerpt: RenderedContent?
public let status: String?
public let password: String?
public let comment_status: String?
public let commentStatus: CommentStatus?
public let ping_status: String?
public let categories: [Int]
public let tags: [Int]

public init(id: Int, title: RenderedContent, content: RenderedContent, format: String? = nil, sticky: Bool? = nil, excerpt: RenderedContent? = nil, status: String? = nil, password: String? = nil, comment_status: String? = nil, ping_status: String? = nil, categories: [Int], tags: [Int]) {
public init(id: Int, title: RenderedContent, content: RenderedContent, format: String? = nil, sticky: Bool? = nil, excerpt: RenderedContent? = nil, status: String? = nil, password: String? = nil, commentStatus: CommentStatus? = nil, ping_status: String? = nil, categories: [Int], tags: [Int]) {
self.id = id
self.title = title
self.content = content
Expand All @@ -158,14 +158,14 @@ public struct PostToUpdate: Encodable {
self.excerpt = excerpt
self.status = status
self.password = password
self.comment_status = comment_status
self.commentStatus = commentStatus
self.ping_status = ping_status
self.categories = categories
self.tags = tags
}
}

public struct RenderedContent: Codable {
public struct RenderedContent: Codable, Sendable {
public let rendered: String
public let protected: Bool

Expand Down
2 changes: 1 addition & 1 deletion Sources/WPSwift/Models/SimplePost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct SimplePost: Decodable {
public struct SimplePost: Decodable, Sendable {
public let id: Int
public let title: String
public let link: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/WPSwift/Repositories/APIInfoRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import Resting

public struct APIInfoRepository {
public struct APIInfoRepository: Sendable {
public init() {}

public func getAPIInfo(route: String? = nil) async throws -> APIInfo {
Expand Down
Loading

0 comments on commit 9acab78

Please sign in to comment.