Skip to content

Commit

Permalink
Merge pull request #15 from MFB-Technologies-Inc/feature/upcoming-fea…
Browse files Browse the repository at this point in the history
…tures

Feature/upcoming features
  • Loading branch information
r-jarvis authored Feb 22, 2024
2 parents 16abd6d + d33158d commit 546d9b3
Show file tree
Hide file tree
Showing 29 changed files with 131 additions and 109 deletions.
37 changes: 24 additions & 13 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,52 @@ extension Product {

extension Target {
static let targets: [Target] = [
.target(name: "NetworkService"),
.target(
name: "NetworkService",
swiftSettings: .swiftSix
),
.testTarget(
name: "NetworkServiceTests",
dependencies: [
"NetworkService",
.product(name: "OHHTTPStubs", package: "OHHTTPStubs"),
.product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs"),
]
],
swiftSettings: .swiftSix
),
.target(
name: "NetworkServiceTestHelper",
dependencies: [
"NetworkService",
.product(name: "CombineSchedulers", package: "combine-schedulers"),
]
],
swiftSettings: .swiftSix
),
.testTarget(
name: "NetworkServiceTestHelperTests",
dependencies: [
"NetworkServiceTestHelper",
.product(name: "CombineSchedulers", package: "combine-schedulers"),
]
],
swiftSettings: .swiftSix
),
]
}

package.targets.strictConcurrency()

extension Array where Element == Target {
func strictConcurrency() {
forEach { target in
target.swiftSettings = (target.swiftSettings ?? [])
+ [.enableUpcomingFeature("StrictConcurrency")]
}
}
extension [SwiftSetting] {
static let swiftSix: [SwiftSetting] = [
.enableUpcomingFeature("BareSlashRegexLiterals"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("FullTypedThrows"),
.enableUpcomingFeature("ImplicitOpenExistentials"),
.enableUpcomingFeature("ImportObjcForwardDeclarations"),
.enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("IsolatedDefaultValues"),
.enableUpcomingFeature("StrictConcurrency"),
]
}

extension Package.Dependency {
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/HTTPURLResponse+StatusCode.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// HTTPURLResponse+StatusCode.swift
// NetworkService
//
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
// Copyright © 2024 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkService/NetworkService.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkService.swift
// NetworkService
//
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
// Copyright © 2024 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
9 changes: 5 additions & 4 deletions Sources/NetworkService/NetworkServiceClient+Delete.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Delete.swift
// NetworkService
//
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
// Copyright © 2024 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand All @@ -17,7 +17,7 @@ extension NetworkServiceClient {
/// - Returns: Type erased publisher with `Data` output and `NetworkService`'s error domain for failure
public func delete(
_ url: URL,
headers: [HTTPHeader] = []
headers: [any HTTPHeader] = []
) async -> Result<Data, Failure> {
let request = URLRequest.build(url: url, headers: headers, method: .DELETE)
return await start(request)
Expand All @@ -36,7 +36,7 @@ extension NetworkServiceClient {
/// - Returns: Type erased publisher with decoded output and `NetworkService`'s error domain for failure
public func delete<ResponseBody, Decoder>(
_ url: URL,
headers: [HTTPHeader] = [],
headers: [any HTTPHeader] = [],
decoder: Decoder
) async -> Result<ResponseBody, Failure>
where ResponseBody: Decodable, Decoder: TopLevelDecoder, Decoder.Input == Data
Expand All @@ -52,7 +52,8 @@ extension NetworkServiceClient {
/// - headers: HTTP headers for the request
/// - Returns: Type erased publisher with `TopLevelDecodable` output and `NetworkService`'s error domain for
/// failure
public func delete<ResponseBody>(_ url: URL, headers: [HTTPHeader] = []) async -> Result<ResponseBody, Failure>
public func delete<ResponseBody>(_ url: URL,
headers: [any HTTPHeader] = []) async -> Result<ResponseBody, Failure>
where ResponseBody: TopLevelDecodable
{
await delete(url, headers: headers, decoder: ResponseBody.decoder)
Expand Down
9 changes: 5 additions & 4 deletions Sources/NetworkService/NetworkServiceClient+Get.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Get.swift
// NetworkService
//
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
// Copyright © 2024 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand All @@ -17,7 +17,7 @@ extension NetworkServiceClient {
/// - Returns: Type erased publisher with `Data` output and `NetworkService`'s error domain for failure
public func get(
_ url: URL,
headers: [HTTPHeader] = []
headers: [any HTTPHeader] = []
) async -> Result<Data, Failure> {
let request = URLRequest.build(url: url, headers: headers, method: .GET)
return await start(request)
Expand All @@ -26,6 +26,7 @@ extension NetworkServiceClient {

#if canImport(Combine)
import Combine

extension NetworkServiceClient {
/// Send a get request to a `URL`
/// - Parameters:
Expand All @@ -35,7 +36,7 @@ extension NetworkServiceClient {
/// - Returns: Type erased publisher with decoded output and `NetworkService`'s error domain for failure
public func get<ResponseBody, Decoder>(
_ url: URL,
headers: [HTTPHeader] = [],
headers: [any HTTPHeader] = [],
decoder: Decoder
) async -> Result<ResponseBody, Failure>
where ResponseBody: Decodable, Decoder: TopLevelDecoder, Decoder.Input == Data
Expand All @@ -51,7 +52,7 @@ extension NetworkServiceClient {
/// - headers: HTTP headers for the request
/// - Returns: Type erased publisher with `TopLevelDecodable` output and `NetworkService`'s error domain for
/// failure
public func get<ResponseBody>(_ url: URL, headers: [HTTPHeader] = []) async -> Result<ResponseBody, Failure>
public func get<ResponseBody>(_ url: URL, headers: [any HTTPHeader] = []) async -> Result<ResponseBody, Failure>
where ResponseBody: TopLevelDecodable
{
await get(url, headers: headers, decoder: ResponseBody.decoder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+GetSession.swift
// NetworkService
//
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
// Copyright © 2024 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand Down
17 changes: 9 additions & 8 deletions Sources/NetworkService/NetworkServiceClient+Post.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Post.swift
// NetworkService
//
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
// Copyright © 2024 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand All @@ -19,7 +19,7 @@ extension NetworkServiceClient {
public func post(
_ body: Data,
to url: URL,
headers: [HTTPHeader] = []
headers: [any HTTPHeader] = []
) async -> Result<Data, Failure> {
let request = URLRequest.build(url: url, body: body, headers: headers, method: .POST)
return await start(request)
Expand All @@ -28,6 +28,7 @@ extension NetworkServiceClient {

#if canImport(Combine)
import Combine

extension NetworkServiceClient {
/// - Parameters:
/// - body: The body of the request as `Encodable`
Expand All @@ -38,7 +39,7 @@ extension NetworkServiceClient {
public func post<RequestBody, Encoder>(
_ body: RequestBody,
to url: URL,
headers: [HTTPHeader],
headers: [any HTTPHeader],
encoder: Encoder
) async -> Result<Data, Failure>
where RequestBody: Encodable,
Expand All @@ -61,7 +62,7 @@ extension NetworkServiceClient {
public func post<RequestBody>(
_ body: RequestBody,
to url: URL,
headers: [HTTPHeader]
headers: [any HTTPHeader]
) async -> Result<Data, Failure>
where RequestBody: TopLevelEncodable
{
Expand All @@ -85,7 +86,7 @@ extension NetworkServiceClient {
public func post<ResponseBody, Decoder>(
_ body: Data,
to url: URL,
headers: [HTTPHeader] = [],
headers: [any HTTPHeader] = [],
decoder: Decoder
) async -> Result<ResponseBody, Failure>
where ResponseBody: Decodable, Decoder: TopLevelDecoder, Decoder.Input == Data
Expand All @@ -106,7 +107,7 @@ extension NetworkServiceClient {
public func post<ResponseBody>(
_ body: Data,
to url: URL,
headers: [HTTPHeader] = []
headers: [any HTTPHeader] = []
) async -> Result<ResponseBody, Failure>
where ResponseBody: TopLevelDecodable
{
Expand All @@ -124,7 +125,7 @@ extension NetworkServiceClient {
public func post<RequestBody, ResponseBody, Encoder, Decoder>(
_ body: RequestBody,
to url: URL,
headers: [HTTPHeader] = [],
headers: [any HTTPHeader] = [],
encoder: Encoder,
decoder: Decoder
) async -> Result<ResponseBody, Failure>
Expand Down Expand Up @@ -155,7 +156,7 @@ extension NetworkServiceClient {
public func post<RequestBody, ResponseBody>(
_ body: RequestBody,
to url: URL,
headers: [HTTPHeader] = []
headers: [any HTTPHeader] = []
) async -> Result<ResponseBody, Failure>
where RequestBody: TopLevelEncodable,
ResponseBody: TopLevelDecodable
Expand Down
17 changes: 9 additions & 8 deletions Sources/NetworkService/NetworkServiceClient+Put.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Put.swift
// NetworkService
//
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
// Copyright © 2024 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand All @@ -19,7 +19,7 @@ extension NetworkServiceClient {
public func put(
_ body: Data,
to url: URL,
headers: [HTTPHeader] = []
headers: [any HTTPHeader] = []
) async -> Result<Data, Failure> {
let request = URLRequest.build(url: url, body: body, headers: headers, method: .PUT)
return await start(request)
Expand All @@ -28,6 +28,7 @@ extension NetworkServiceClient {

#if canImport(Combine)
import Combine

extension NetworkServiceClient {
/// - Parameters:
/// - body: The body of the request as `Encodable`
Expand All @@ -38,7 +39,7 @@ extension NetworkServiceClient {
public func put<RequestBody, Encoder>(
_ body: RequestBody,
to url: URL,
headers: [HTTPHeader],
headers: [any HTTPHeader],
encoder: Encoder
) async -> Result<Data, Failure>
where RequestBody: Encodable,
Expand All @@ -63,7 +64,7 @@ extension NetworkServiceClient {
public func put<RequestBody>(
_ body: RequestBody,
to url: URL,
headers: [HTTPHeader]
headers: [any HTTPHeader]
) async -> Result<Data, Failure>
where RequestBody: TopLevelEncodable
{
Expand All @@ -87,7 +88,7 @@ extension NetworkServiceClient {
public func put<ResponseBody, Decoder>(
_ body: Data,
to url: URL,
headers: [HTTPHeader] = [],
headers: [any HTTPHeader] = [],
decoder: Decoder
) async -> Result<ResponseBody, Failure>
where ResponseBody: Decodable, Decoder: TopLevelDecoder, Decoder.Input == Data
Expand All @@ -106,7 +107,7 @@ extension NetworkServiceClient {
public func put<ResponseBody>(
_ body: Data,
to url: URL,
headers: [HTTPHeader] = []
headers: [any HTTPHeader] = []
) async -> Result<ResponseBody, Failure>
where ResponseBody: TopLevelDecodable
{
Expand All @@ -124,7 +125,7 @@ extension NetworkServiceClient {
public func put<RequestBody, ResponseBody, Encoder, Decoder>(
_ body: RequestBody,
to url: URL,
headers: [HTTPHeader] = [],
headers: [any HTTPHeader] = [],
encoder: Encoder,
decoder: Decoder
) async -> Result<ResponseBody, Failure>
Expand Down Expand Up @@ -154,7 +155,7 @@ extension NetworkServiceClient {
public func put<RequestBody, ResponseBody>(
_ body: RequestBody,
to url: URL,
headers: [HTTPHeader] = []
headers: [any HTTPHeader] = []
) async -> Result<ResponseBody, Failure>
where RequestBody: TopLevelEncodable,
ResponseBody: TopLevelDecodable
Expand Down
5 changes: 3 additions & 2 deletions Sources/NetworkService/NetworkServiceClient+Start.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NetworkServiceClient+Start.swift
// NetworkService
//
// Copyright © 2023 MFB Technologies, Inc. All rights reserved.
// Copyright © 2024 MFB Technologies, Inc. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
Expand All @@ -13,7 +13,7 @@ extension NetworkServiceClient {
/// - Parameter request: The request as a `URLRequest`
/// - Returns: Type erased publisher with output as `Data` and `NetworkService`'s error domain for failure
public func start(_ request: URLRequest) async -> Result<Data, Failure> {
let result: Result<(Data, URLResponse), Error>
let result: Result<(Data, URLResponse), any Error>
do {
let response: (Data, URLResponse) = try await response(request)
result = .success(response)
Expand Down Expand Up @@ -65,6 +65,7 @@ private final class TaskIdBox {

#if canImport(Combine)
import Combine

extension NetworkServiceClient {
/// Start a `URLRequest`
/// - Parameter request: The request as a `URLRequest`
Expand Down
Loading

0 comments on commit 546d9b3

Please sign in to comment.