Skip to content

Commit 2116628

Browse files
committed
remove profile
motivation: reduce complexity changes: remove profile model and update API and storage accordingly
1 parent fa7a6cd commit 2116628

10 files changed

+243
-562
lines changed

Sources/PackageCollections/API.swift

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ import PackageModel
1212
import SourceControl
1313

1414
public protocol PackageCollectionsProtocol {
15-
// MARK: - Package collection profile APIs
16-
17-
/// Lists package collection profiles.
18-
///
19-
/// The result of this API does not include `PackageCollection` data. All other APIs in this
20-
/// protocol require the context of a profile. Implementations should support a "default"
21-
/// profile such that the `profile` API parameter can be optional.
22-
///
23-
/// - Parameters:
24-
/// - callback: The closure to invoke when result becomes available
25-
func listProfiles(callback: @escaping (Result<[PackageCollectionsModel.Profile], Error>) -> Void)
26-
2715
// MARK: - Package set APIs
2816

2917
/// Returns packages organized into collections.
@@ -33,48 +21,38 @@ public protocol PackageCollectionsProtocol {
3321
///
3422
/// - Parameters:
3523
/// - identifiers: Optional. If specified, only `PackageCollection`s with matching identifiers will be returned.
36-
/// - profile: Optional. The `PackageCollectionProfile` context. By default the `default` profile is used.
3724
/// - callback: The closure to invoke when result becomes available
3825
func listCollections(
3926
identifiers: Set<PackageCollectionsModel.CollectionIdentifier>?,
40-
in profile: PackageCollectionsModel.Profile?,
4127
callback: @escaping (Result<[PackageCollectionsModel.Collection], Error>) -> Void
4228
)
4329

4430
/// Refreshes all configured package collections.
4531
///
4632
/// - Parameters:
47-
/// - profile: Optional. The `PackageCollectionProfile` context. By default the `default` profile is used.
4833
/// - callback: The closure to invoke after triggering a refresh for the configured package collections.
49-
func refreshCollections(
50-
in profile: PackageCollectionsModel.Profile?,
51-
callback: @escaping (Result<[PackageCollectionsModel.CollectionSource], Error>) -> Void
52-
)
34+
func refreshCollections(callback: @escaping (Result<[PackageCollectionsModel.CollectionSource], Error>) -> Void)
5335

5436
/// Adds a package collection.
5537
///
5638
/// - Parameters:
5739
/// - source: The package collection's source
5840
/// - order: Optional. The order that the `PackageCollection` should take after being added to the list.
5941
/// By default the new collection is appended to the end (i.e., the least relevant order).
60-
/// - profile: Optional. The `PackageCollectionProfile` context. By default the `default` profile is used.
6142
/// - callback: The closure to invoke with the updated `PackageCollection`s
6243
func addCollection(
6344
_ source: PackageCollectionsModel.CollectionSource,
6445
order: Int?,
65-
to profile: PackageCollectionsModel.Profile?,
6646
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void
6747
)
6848

6949
/// Removes a package collection.
7050
///
7151
/// - Parameters:
7252
/// - source: The package collection's source
73-
/// - profile: Optional. The `PackageCollectionProfile` context. By default the `default` profile is used.
7453
/// - callback: The closure to invoke with the updated `PackageCollection`s
7554
func removeCollection(
7655
_ source: PackageCollectionsModel.CollectionSource,
77-
from profile: PackageCollectionsModel.Profile?,
7856
callback: @escaping (Result<Void, Error>) -> Void
7957
)
8058

@@ -83,12 +61,10 @@ public protocol PackageCollectionsProtocol {
8361
/// - Parameters:
8462
/// - id: The identifier of the `PackageCollection` to be moved
8563
/// - order: The new order that the `PackageCollection` should be positioned after the move
86-
/// - profile: Optional. The `PackageCollectionProfile` context. By default the `default` profile is used.
8764
/// - callback: The closure to invoke with the updated `PackageCollection`s
8865
func moveCollection(
8966
_ source: PackageCollectionsModel.CollectionSource,
9067
to order: Int,
91-
in profile: PackageCollectionsModel.Profile?,
9268
callback: @escaping (Result<Void, Error>) -> Void
9369
)
9470

@@ -112,11 +88,9 @@ public protocol PackageCollectionsProtocol {
11288
///
11389
/// - Parameters:
11490
/// - reference: The package reference
115-
/// - profile: Optional. The `PackageCollectionProfile` context. By default the `default` profile is used.
11691
/// - callback: The closure to invoke when result becomes available
11792
func getPackageMetadata(
11893
_ reference: PackageReference,
119-
profile: PackageCollectionsModel.Profile?,
12094
callback: @escaping (Result<PackageCollectionsModel.PackageMetadata, Error>) -> Void
12195
)
12296

@@ -130,11 +104,9 @@ public protocol PackageCollectionsProtocol {
130104
///
131105
/// - Parameters:
132106
/// - collections: Optional. If specified, only list targets within these collections.
133-
/// - profile: Optional. The `PackageCollectionProfile` context. By default the `default` profile is used.
134107
/// - callback: The closure to invoke when result becomes available
135108
func listTargets(
136109
collections: Set<PackageCollectionsModel.CollectionIdentifier>?,
137-
in profile: PackageCollectionsModel.Profile?,
138110
callback: @escaping (Result<PackageCollectionsModel.TargetListResult, Error>) -> Void
139111
)
140112

@@ -148,12 +120,10 @@ public protocol PackageCollectionsProtocol {
148120
/// - Parameters:
149121
/// - query: The search query
150122
/// - collections: Optional. If specified, only search within these collections.
151-
/// - profile: Optional. The `PackageCollectionProfile` context. By default the `default` profile is used.
152123
/// - callback: The closure to invoke when result becomes available
153124
func findPackages(
154125
_ query: String,
155126
collections: Set<PackageCollectionsModel.CollectionIdentifier>?,
156-
profile: PackageCollectionsModel.Profile?,
157127
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult, Error>) -> Void
158128
)
159129

@@ -167,13 +137,11 @@ public protocol PackageCollectionsProtocol {
167137
/// - searchType: Optional. Target names must either match exactly or contain the prefix.
168138
/// For more flexibility, use the `findPackages` API instead.
169139
/// - collections: Optional. If specified, only search within these collections.
170-
/// - profile: Optional. The `PackageCollectionProfile` context. By default the `default` profile is used.
171140
/// - callback: The closure to invoke when result becomes available
172141
func findTargets(
173142
_ query: String,
174143
searchType: PackageCollectionsModel.TargetSearchType?,
175144
collections: Set<PackageCollectionsModel.CollectionIdentifier>?,
176-
profile: PackageCollectionsModel.Profile?,
177145
callback: @escaping (Result<PackageCollectionsModel.TargetSearchResult, Error>) -> Void
178146
)
179147
}

Sources/PackageCollections/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ add_library(PackageCollections
1111
Model/Collection.swift
1212
Model/License.swift
1313
Model/Package.swift
14-
Model/Profile.swift
1514
Model/Search.swift
1615
Model/TargetListResult.swift
1716
Providers/GitHubPackageMetadataProvider.swift
1817
Providers/JSONPackageCollectionProvider.swift
1918
Providers/PackageCollectionProvider.swift
2019
Providers/PackageMetadataProvider.swift
21-
Storage/PackageCollectionsProfileStorage.swift
20+
Storage/PackageCollectionsSourcesStorage.swift
2221
Storage/PackageCollectionsStorage.swift
2322
API.swift
2423
PackageCollections.swift

Sources/PackageCollections/Model/Profile.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/PackageCollections/PackageCollections+Storage.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import TSCBasic
1212

1313
extension PackageCollections {
1414
public struct Storage: Closable {
15-
let collectionsProfiles: PackageCollectionsProfileStorage
15+
let sources: PackageCollectionsSourcesStorage
1616
let collections: PackageCollectionsStorage
1717

18-
public init(collectionsProfiles: PackageCollectionsProfileStorage, collections: PackageCollectionsStorage) {
19-
self.collectionsProfiles = collectionsProfiles
18+
public init(sources: PackageCollectionsSourcesStorage, collections: PackageCollectionsStorage) {
19+
self.sources = sources
2020
self.collections = collections
2121
}
2222
}
@@ -36,7 +36,7 @@ extension PackageCollections.Storage {
3636
}
3737
}
3838

39-
tryClose(self.collectionsProfiles)
39+
tryClose(self.sources)
4040
tryClose(self.collections)
4141

4242
if !errors.isEmpty {

Sources/PackageCollections/PackageCollections.swift

Lines changed: 15 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,11 @@ public struct PackageCollections: PackageCollectionsProtocol {
2828
self.metadataProvider = metadataProvider
2929
}
3030

31-
// MARK: - Profiles
32-
33-
public func listProfiles(callback: @escaping (Result<[PackageCollectionsModel.Profile], Error>) -> Void) {
34-
self.storage.collectionsProfiles.listProfiles(callback: callback)
35-
}
36-
3731
// MARK: - Collections
3832

3933
public func listCollections(identifiers: Set<PackageCollectionsModel.CollectionIdentifier>? = nil,
40-
in profile: PackageCollectionsModel.Profile? = nil,
4134
callback: @escaping (Result<[PackageCollectionsModel.Collection], Error>) -> Void) {
42-
let profile = profile ?? .default
43-
44-
self.storage.collectionsProfiles.listSources(in: profile) { result in
35+
self.storage.sources.list { result in
4536
switch result {
4637
case .failure(let error):
4738
callback(.failure(error))
@@ -69,11 +60,8 @@ public struct PackageCollections: PackageCollectionsProtocol {
6960
}
7061
}
7162

72-
public func refreshCollections(in profile: PackageCollectionsModel.Profile? = nil,
73-
callback: @escaping (Result<[PackageCollectionsModel.CollectionSource], Error>) -> Void) {
74-
let profile = profile ?? .default
75-
76-
self.storage.collectionsProfiles.listSources(in: profile) { result in
63+
public func refreshCollections(callback: @escaping (Result<[PackageCollectionsModel.CollectionSource], Error>) -> Void) {
64+
self.storage.sources.list { result in
7765
switch result {
7866
case .failure(let error):
7967
callback(.failure(error))
@@ -84,7 +72,7 @@ public struct PackageCollections: PackageCollectionsProtocol {
8472
let lock = Lock()
8573
var refreshResults = [Result<PackageCollectionsModel.Collection, Error>]()
8674
sources.forEach { source in
87-
self.refreshCollectionFromSource(source: source, profile: profile) { refreshResult in
75+
self.refreshCollectionFromSource(source: source) { refreshResult in
8876
lock.withLock { refreshResults.append(refreshResult) }
8977
if refreshResults.count == (lock.withLock { sources.count }) {
9078
let errors = refreshResults.compactMap { $0.failure }
@@ -98,60 +86,39 @@ public struct PackageCollections: PackageCollectionsProtocol {
9886

9987
public func addCollection(_ source: PackageCollectionsModel.CollectionSource,
10088
order: Int? = nil,
101-
to profile: PackageCollectionsModel.Profile? = nil,
10289
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void) {
103-
let profile = profile ?? .default
104-
10590
if let errors = source.validate() {
10691
return callback(.failure(MultipleErrors(errors)))
10792
}
10893

10994
// first record the registration
110-
self.storage.collectionsProfiles.add(source: source, order: order, to: profile) { result in
95+
self.storage.sources.add(source: source, order: order) { result in
11196
switch result {
11297
case .failure(let error):
11398
callback(.failure(error))
11499
case .success:
115100
// next try to fetch the collection from the network and store it locally so future operations dont need to access the network
116-
self.refreshCollectionFromSource(source: source, order: order, profile: profile, callback: callback)
101+
self.refreshCollectionFromSource(source: source, order: order, callback: callback)
117102
}
118103
}
119104
}
120105

121106
public func removeCollection(_ source: PackageCollectionsModel.CollectionSource,
122-
from profile: PackageCollectionsModel.Profile? = nil,
123107
callback: @escaping (Result<Void, Error>) -> Void) {
124-
let profile = profile ?? .default
125-
126-
self.storage.collectionsProfiles.remove(source: source, from: profile) { result in
108+
self.storage.sources.remove(source: source) { result in
127109
switch result {
128110
case .failure(let error):
129111
callback(.failure(error))
130112
case .success:
131-
// check to see if the collection is used in some other profile,
132-
// if not delete it from storage to reduce disk space
133-
self.storage.collectionsProfiles.exists(source: source, in: nil) { result in
134-
switch result {
135-
case .failure(let error):
136-
callback(.failure(error))
137-
case .success(let exists):
138-
if exists {
139-
callback(.success(()))
140-
} else {
141-
self.storage.collections.remove(identifier: .init(from: source), callback: callback)
142-
}
143-
}
144-
}
113+
self.storage.collections.remove(identifier: .init(from: source), callback: callback)
145114
}
146115
}
147116
}
148117

149118
public func moveCollection(_ source: PackageCollectionsModel.CollectionSource,
150-
to order: Int, in profile: PackageCollectionsModel.Profile? = nil,
119+
to order: Int,
151120
callback: @escaping (Result<Void, Error>) -> Void) {
152-
let profile = profile ?? .default
153-
154-
self.storage.collectionsProfiles.move(source: source, to: order, in: profile, callback: callback)
121+
self.storage.sources.move(source: source, to: order, callback: callback)
155122
}
156123

157124
// Returns information about a package collection.
@@ -181,12 +148,9 @@ public struct PackageCollections: PackageCollectionsProtocol {
181148
public func findPackages(
182149
_ query: String,
183150
collections: Set<PackageCollectionsModel.CollectionIdentifier>? = nil,
184-
profile: PackageCollectionsModel.Profile? = nil,
185151
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult, Error>) -> Void
186152
) {
187-
let profile = profile ?? .default
188-
189-
self.storage.collectionsProfiles.listSources(in: profile) { result in
153+
self.storage.sources.list { result in
190154
switch result {
191155
case .failure(let error):
192156
callback(.failure(error))
@@ -203,12 +167,9 @@ public struct PackageCollections: PackageCollectionsProtocol {
203167
// MARK: - Package Metadata
204168

205169
public func getPackageMetadata(_ reference: PackageReference,
206-
profile: PackageCollectionsModel.Profile? = nil,
207170
callback: @escaping (Result<PackageCollectionsModel.PackageMetadata, Error>) -> Void) {
208-
let profile = profile ?? .default
209-
210171
// first find in storage
211-
self.findPackage(identifier: reference.identity, profile: profile) { result in
172+
self.findPackage(identifier: reference.identity) { result in
212173
switch result {
213174
case .failure(let error):
214175
callback(.failure(error))
@@ -241,10 +202,9 @@ public struct PackageCollections: PackageCollectionsProtocol {
241202

242203
public func listTargets(
243204
collections: Set<PackageCollectionsModel.CollectionIdentifier>? = nil,
244-
in profile: PackageCollectionsModel.Profile? = nil,
245205
callback: @escaping (Result<PackageCollectionsModel.TargetListResult, Error>) -> Void
246206
) {
247-
self.listCollections(identifiers: collections, in: profile) { result in
207+
self.listCollections(identifiers: collections) { result in
248208
switch result {
249209
case .failure(let error):
250210
callback(.failure(error))
@@ -259,13 +219,11 @@ public struct PackageCollections: PackageCollectionsProtocol {
259219
_ query: String,
260220
searchType: PackageCollectionsModel.TargetSearchType? = nil,
261221
collections: Set<PackageCollectionsModel.CollectionIdentifier>? = nil,
262-
profile: PackageCollectionsModel.Profile? = nil,
263222
callback: @escaping (Result<PackageCollectionsModel.TargetSearchResult, Error>) -> Void
264223
) {
265-
let profile = profile ?? .default
266224
let searchType = searchType ?? .exactMatch
267225

268-
self.storage.collectionsProfiles.listSources(in: profile) { result in
226+
self.storage.sources.list { result in
269227
switch result {
270228
case .failure(let error):
271229
callback(.failure(error))
@@ -285,7 +243,6 @@ public struct PackageCollections: PackageCollectionsProtocol {
285243
// This helps avoid network access in normal operations
286244
private func refreshCollectionFromSource(source: PackageCollectionsModel.CollectionSource,
287245
order _: Int? = nil,
288-
profile _: PackageCollectionsModel.Profile? = nil,
289246
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void) {
290247
if let errors = source.validate() {
291248
return callback(.failure(MultipleErrors(errors)))
@@ -305,12 +262,9 @@ public struct PackageCollections: PackageCollectionsProtocol {
305262

306263
func findPackage(
307264
identifier: PackageIdentity,
308-
profile: PackageCollectionsModel.Profile? = nil,
309265
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult.Item, Error>) -> Void
310266
) {
311-
let profile = profile ?? .default
312-
313-
self.storage.collectionsProfiles.listSources(in: profile) { result in
267+
self.storage.sources.list { result in
314268
switch result {
315269
case .failure(let error):
316270
callback(.failure(error))

0 commit comments

Comments
 (0)