Skip to content

Commit

Permalink
Merge development into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertix committed May 9, 2021
2 parents 1526787 + b42cdae commit 5c55203
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 69 deletions.
56 changes: 6 additions & 50 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import PackageDescription
let package = Package(
name: "ComposableRequest",
// Supported versions.
platforms: [.iOS(.v9),
.macOS(.v10_10),
.tvOS(.v9),
.watchOS(.v2)],
platforms: [.iOS("13.0"),
.macOS("10.15"),
.tvOS("13.0"),
.watchOS("6.0")],
// Exposed libraries.
products: [.library(name: "Requests",
targets: ["ComposableRequest"]),
Expand All @@ -20,13 +20,10 @@ let package = Package(
.library(name: "StorageCrypto",
targets: ["ComposableStorageCrypto"])],
// Package dependencies.
dependencies: [.package(url: "https://github.com/cx-org/CombineX",
.upToNextMinor(from: "0.3.0")),
.package(url: "https://github.com/sbertix/Swiftchain.git",
dependencies: [.package(url: "https://github.com/sbertix/Swiftchain.git",
.upToNextMinor(from: "1.0.0"))],
// All targets.
targets: [.target(name: "ComposableRequest",
dependencies: [.product(name: "CXShim", package: "CombineX")]),
targets: [.target(name: "ComposableRequest"),
.target(name: "ComposableStorage",
dependencies: []),
.target(name: "ComposableStorageCrypto",
Expand All @@ -35,48 +32,7 @@ let package = Package(
dependencies: ["ComposableRequest", "ComposableStorage", "ComposableStorageCrypto"])]
)

enum CombineImplementation {
/// Apple **Combine**.
case combine
/// **cx-org/CombineX**.
case combineX

/// Default implementation.
/// If available, Apple **Combine** is always preferred.
static var `default`: CombineImplementation {
#if canImport(Combine)
return .combine
#else
return .combineX
#endif
}

/// Optional init.
///
/// - parameter description: A valid `String`.
init?(_ description: String) {
let desc = description.lowercased().filter { $0.isLetter }
switch desc {
case "combine": self = .combine
case "combinex": self = .combineX
default: return nil
}
}
}

extension ProcessInfo {
/// The selected combine implementation. Defaults to `.default`.
var combineImplementation: CombineImplementation {
return environment["CX_COMBINE_IMPLEMENTATION"].flatMap(CombineImplementation.init) ?? .default
}
}

// MARK: Adjustments

if ProcessInfo.processInfo.environment["TARGETING_WATCHOS"] == "true" {
// #workaround(xcodebuild -version 11.6, Test targets don’t work on watchOS.) @exempt(from: unicode)
package.targets.removeAll(where: { $0.isTest })
}
if ProcessInfo.processInfo.combineImplementation == .combine {
package.platforms = [.macOS("10.15"), .iOS("13.0"), .tvOS("13.0"), .watchOS("6.0")]
}
2 changes: 1 addition & 1 deletion Sources/ComposableRequest/Extensions/@_exported.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// Created by Stefano Bertagno on 10/03/21.
//

@_exported import CXShim
@_exported import Combine
4 changes: 2 additions & 2 deletions Sources/ComposableRequest/Publishers/Pager/Pager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public extension Publishers {
iteration.stream
.collect()
.flatMap { [count, generator] outputs -> AnyPublisher<Output, Failure> in
Publishers.Sequence(sequence: outputs.map(Just.init))
.flatMap(maxPublishers: .max(1)) { $0 }
Publishers.Sequence(sequence: outputs.map { Just($0).setFailureType(to: Failure.self) })
.flatMap(maxPublishers: Subscribers.Demand.max(1)) { $0 }
.append(iteration.offset(outputs).flatMap { Pager(count-1, offset: $0, generator: generator) }?.eraseToAnyPublisher()
?? Empty().eraseToAnyPublisher())
.eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public extension Request {
}
// Return the actual stream.
let logger = input.logger ?? Logger.default
return (input.session.cx as CXWrappers.URLSession)
return input.session
.dataTaskPublisher(for: request)
.retry(max(input.retries, 0))
.map(Request.Response.init)
Expand Down
12 changes: 7 additions & 5 deletions Tests/ComposableRequestTests/ObservableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Stefano Bertagno on 06/05/2020.
//

import Combine
import XCTest

@testable import ComposableRequest
Expand Down Expand Up @@ -51,7 +52,7 @@ final class ObservableTests: XCTestCase {
.compactMap { $0["string"].string() }
.assertBackgroundThread()
}
.receive(on: RunLoop.main.cx)
.receive(on: RunLoop.main)
.assertMainThread()
}
.unlock(with: url)
Expand All @@ -74,8 +75,9 @@ final class ObservableTests: XCTestCase {
func testRemoteFuture() {
let expectations = ["output", "completion"].map(XCTestExpectation.init)
Just(url)
.setFailureType(to: Error.self)
.assertMainThread()
.receive(on: RunLoop.main.cx)
.receive(on: RunLoop.main)
.assertMainThread()
.flatMap {
Request($0)
Expand All @@ -85,7 +87,7 @@ final class ObservableTests: XCTestCase {
.wrap()
.compactMap { $0["string"].string() }
}
.subscribe(on: RunLoop.main.cx)
.subscribe(on: RunLoop.main)
.sink(
receiveCompletion: {
if case .failure(let error) = $0 { XCTFail(error.localizedDescription) }
Expand Down Expand Up @@ -119,7 +121,7 @@ final class ObservableTests: XCTestCase {
}
}
.pages(languages.count, offset: 0)
.receive(on: RunLoop.main.cx)
.receive(on: RunLoop.main)
.assertMainThread()
.sink(
receiveCompletion: {
Expand Down Expand Up @@ -206,7 +208,7 @@ final class ObservableTests: XCTestCase {
Request(url)
.publish(session: .shared)
.map(\.response)
.receive(on: RunLoop.main.cx)
.receive(on: RunLoop.main)
.sink(
receiveCompletion: { _ in XCTFail("This should not complete") },
receiveValue: { _ in XCTFail("This should not output") }
Expand Down
3 changes: 1 addition & 2 deletions Tests/ComposableRequestTests/Shared/Publisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
// Created by Stefano Bertagno on 10/03/21.
//

import Combine
import Foundation
import XCTest

import CXShim

extension Publisher {
/// Assert main thread.
func assertMainThread() -> Publishers.HandleEvents<Self> {
Expand Down
13 changes: 5 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
[![Swift](https://img.shields.io/badge/Swift-5.2-%23DE5C43?style=flat&logo=swift)](https://swift.org)
[![codecov](https://codecov.io/gh/sbertix/ComposableRequest/branch/main/graph/badge.svg)](https://codecov.io/gh/sbertix/Swiftagram)
<br />
![iOS](https://img.shields.io/badge/iOS-9.0-8CFF96)
![macOS](https://img.shields.io/badge/macOS-10.10-8CFF96)
![tvOS](https://img.shields.io/badge/tvOS-9.0-8CFF96)
![watchOS](https://img.shields.io/badge/watchOS-2.0-8CFF96)
![iOS](https://img.shields.io/badge/iOS-13.0-8CFF96)
![macOS](https://img.shields.io/badge/macOS-10.15-8CFF96)
![tvOS](https://img.shields.io/badge/tvOS-13.0-8CFF96)
![watchOS](https://img.shields.io/badge/watchOS-6.0-8CFF96)

<br />

**ComposableRequest** is a networking layer based on a declarative interface, written in (modern) **Swift**.

It abstracts away `URLSession` implementation, in order to provide concise and powerful endpoint representations, thanks to the power of **Combine** `Publisher`s.
Compatibilty for older versions of **iOS**, **macOS**, **tvOS** and **watchOS** is provided through **CombineX**'s **CXShim**, learn more [here](https://github.com/cx-org/CombineX/wiki/Combine-Compatible-Package).

It comes with `Storage` (inside of **ComposableStorage**), a way of caching `Storable` items, and related concrete implementations (e.g. `UserDefaultsStorage`, `KeychainStorage` – for which you're gonna need to add **ComposableStorageCrypto**, depending on [**Swiftchain**](https://github.com/sbertix/Swiftchain), together with the ability to provide the final user of your API wrapper to inject code through `Provider`s.

Expand Down Expand Up @@ -51,9 +50,7 @@ Furthermore, with the integration of the **Swift Package Manager** in **Xcode 11
<details><summary><strong>Targets</strong></summary>
<p>

- **ComposableRequest**, an HTTP client originally integrated in **Swiftagram**, the core library.\
It depends on [**CombineX**](https://github.com/cx-org/CombineX/)'s [**CXShim**](https://github.com/cx-org/CombineX/wiki/Combine-Compatible-Package) to provide **Combine** support on all platforms, reguardless of their minum deployment version.

- **ComposableRequest**, an HTTP client originally integrated in **Swiftagram**, the core library.
- **ComposableStorage**, can be imported together with **ComposableRequest** to extend its functionality.
</p>
</details>
Expand Down

0 comments on commit 5c55203

Please sign in to comment.