Skip to content

Commit acd09e2

Browse files
authored
Updates Package (#15)
* Updates Package * Updates availability of Cached Co-authored-by: danthorpe <danthorpe@users.noreply.github.com>
1 parent 2545111 commit acd09e2

File tree

5 files changed

+222
-52
lines changed

5 files changed

+222
-52
lines changed

Package.resolved

Lines changed: 133 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,87 @@
11
// swift-tools-version: 5.7
2-
32
import PackageDescription
43

5-
let package = Package(
6-
name: "danthorpe-networking",
7-
platforms: [
8-
.macOS(.v12),
9-
.iOS(.v15),
10-
.tvOS(.v15),
11-
.watchOS(.v8)
12-
],
13-
products: [
14-
.library(name: "Networking", targets: ["Networking"]),
15-
],
16-
dependencies: [
17-
.package(url: "https://github.com/pointfreeco/swift-tagged", from: "0.7.0"),
18-
.package(url: "https://github.com/pointfreeco/swift-url-routing", branch: "main"),
19-
.package(url: "https://github.com/danthorpe/danthorpe-utilities", branch: "main"),
20-
.package(url: "https://github.com/danthorpe/danthorpe-plugins", branch: "main"),
21-
],
22-
targets: [
23-
.target(
24-
name: "Networking",
25-
dependencies: [
26-
.product(name: "Cache", package: "danthorpe-utilities"),
27-
.product(name: "ShortID", package: "danthorpe-utilities"),
28-
.product(name: "Tagged", package: "swift-tagged"),
29-
.product(name: "URLRouting", package: "swift-url-routing")
30-
],
31-
plugins: [
32-
.plugin(name: "SwiftLintPlugin", package: "danthorpe-plugins")
33-
]
34-
),
35-
.testTarget(name: "NetworkingTests", dependencies: ["Networking"]),
36-
]
37-
)
4+
var package = Package(name: "danthorpe-networking")
5+
6+
// MARK: - Platforms
7+
8+
package.platforms = [
9+
.macOS(.v12),
10+
.iOS(.v14),
11+
.tvOS(.v14),
12+
.watchOS(.v7)
13+
]
14+
15+
package.dependencies = [
16+
.package(url: "https://github.com/pointfreeco/swift-tagged", from: "0.7.0"),
17+
.package(url: "https://github.com/pointfreeco/swift-url-routing", branch: "main"),
18+
.package(url: "https://github.com/danthorpe/danthorpe-utilities", from: "0.2.0"),
19+
.package(url: "https://github.com/danthorpe/danthorpe-plugins", from: "0.2.0"),
20+
]
21+
22+
// MARK: - Names
23+
24+
let Networking = "Networking"
25+
26+
extension String {
27+
var tests: String { "\(self)Tests" }
28+
}
29+
30+
// MARK: - Products
31+
32+
package.products = [
33+
.library(name: Networking, targets: [Networking])
34+
]
35+
36+
// MARK: Targets
37+
38+
extension Target {
39+
static let networking: Target = .target(
40+
name: Networking,
41+
dependencies: [
42+
.cache, .shortID, .tagged, .URLRouting
43+
],
44+
plugins: [
45+
.swiftLint
46+
]
47+
)
48+
static let networkingTests: Target = .testTarget(
49+
name: Networking.tests,
50+
dependencies: [
51+
.networking
52+
]
53+
)
54+
}
55+
56+
package.targets = [
57+
.networking,
58+
.networkingTests
59+
]
60+
61+
// MARK: - Dependencies
62+
63+
extension Target.Dependency {
64+
static let networking: Target.Dependency = .target(
65+
name: Networking
66+
)
67+
static let cache: Target.Dependency = .product(
68+
name: "Cache", package: "danthorpe-utilities"
69+
)
70+
static let shortID: Target.Dependency = .product(
71+
name: "ShortID", package: "danthorpe-utilities"
72+
)
73+
static let tagged: Target.Dependency = .product(
74+
name: "Tagged", package: "swift-tagged"
75+
)
76+
static let URLRouting: Target.Dependency = .product(
77+
name: "URLRouting", package: "swift-url-routing"
78+
)
79+
}
80+
81+
// MARK: - Plugins
82+
83+
extension Target.PluginUsage {
84+
static let swiftLint: Target.PluginUsage = .plugin(
85+
name: "SwiftLint", package: "danthorpe-plugins"
86+
)
87+
}

Sources/Networking/NetworkStack.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ extension NetworkStack {
2020
let cancel: () -> Void = { dataTask?.cancel() }
2121

2222
return try await withTaskCancellationHandler(
23-
handler: { cancel() },
2423
operation: {
2524
try await withCheckedThrowingContinuation { continuation in
2625
dataTask = session.dataTask(with: request) { data, response, error in
@@ -40,6 +39,8 @@ extension NetworkStack {
4039
// Resume the data task
4140
dataTask?.resume()
4241
}
42+
}, onCancel: {
43+
cancel()
4344
}
4445
)
4546
}

Sources/Networking/Stack Components/Cached.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ public enum CacheOption {
1515

1616
// MARK: - Cached Network Stack
1717

18+
@available(iOS 15.0, *)
1819
public typealias NetworkCache = Cache<URLRequestData, URLResponseData>
1920

21+
@available(iOS 15.0, *)
2022
public struct Cached<Upstream: NetworkStackable>: NetworkStackable {
2123
private(set) var cache: NetworkCache
2224
public let upstream: Upstream
@@ -58,6 +60,7 @@ public struct Cached<Upstream: NetworkStackable>: NetworkStackable {
5860
}
5961
}
6062

63+
@available(iOS 15.0, *)
6164
public extension NetworkStackable {
6265

6366
func cached(size: Int = 100, fileName: String) -> Cached<Self> {

Sources/Networking/Stack Components/Throttled.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Concurrency
21
import Foundation
32
import os.log
43
import URLRouting

0 commit comments

Comments
 (0)