Skip to content

Commit 5136257

Browse files
committed
Add DependencyKey conformance and liveValue impl
1 parent 9b2293e commit 5136257

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Sources/App/Core/Constants.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum Constants {
2626

2727
static let packageListUri = URI(string: "https://raw.githubusercontent.com/SwiftPackageIndex/PackageList/main/packages.json")
2828
static let packageDenyListUri = URI(string: "https://raw.githubusercontent.com/SwiftPackageIndex/PackageList/main/denylist.json")
29+
static let customCollectionsUri = URI(string: "https://raw.githubusercontent.com/SwiftPackageIndex/PackageList/main/custom-package-collections.json.json")
2930

3031
// NB: the underlying materialised views also have a limit, this is just an additional
3132
// limit to ensure we don't spill too many rows onto the home page

Sources/App/Core/Dependencies/PackageListRepositoryClient.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ struct PackageListRepositoryClient {
2525
}
2626

2727

28+
extension PackageListRepositoryClient: DependencyKey {
29+
static var liveValue: PackageListRepositoryClient {
30+
.init(
31+
fetchCustomCollection: { client, url in
32+
try await client
33+
.get(URI(string: url.absoluteString))
34+
.content
35+
.decode([URL].self, using: JSONDecoder())
36+
},
37+
fetchCustomCollections: { client in
38+
try await client
39+
.get(Constants.customCollectionsUri)
40+
.content
41+
.decode([CustomCollection.DTO].self, using: JSONDecoder())
42+
}
43+
)
44+
}
45+
}
46+
47+
2848
extension PackageListRepositoryClient: Sendable, TestDependencyKey {
2949
static var testValue: Self { Self() }
3050
}

0 commit comments

Comments
 (0)