@@ -27,30 +27,20 @@ public protocol PackageCollectionsProtocol {
27
27
///
28
28
/// - Parameters:
29
29
/// - identifiers: Optional. If specified, only `PackageCollection`s with matching identifiers will be returned.
30
- /// - callback: The closure to invoke when result becomes available
31
- @available ( * , noasync, message: " Use the async alternative " )
32
30
func listCollections(
33
- identifiers: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
34
- callback: @escaping ( Result < [ PackageCollectionsModel . Collection ] , Error > ) -> Void
35
- )
31
+ identifiers: Set < PackageCollectionsModel . CollectionIdentifier > ?
32
+ ) async throws -> [ PackageCollectionsModel . Collection ]
36
33
37
34
/// Refreshes all configured package collections.
38
- ///
39
- /// - Parameters:
40
- /// - callback: The closure to invoke after triggering a refresh for the configured package collections.
41
- @available ( * , noasync, message: " Use the async alternative " )
42
- func refreshCollections( callback: @escaping ( Result < [ PackageCollectionsModel . CollectionSource ] , Error > ) -> Void )
35
+ func refreshCollections( ) async throws -> [ PackageCollectionsModel . CollectionSource ]
43
36
44
37
/// Refreshes a package collection.
45
38
///
46
39
/// - Parameters:
47
40
/// - source: The package collection to be refreshed
48
- /// - callback: The closure to invoke with the refreshed `PackageCollection`
49
- @available ( * , noasync, message: " Use the async alternative " )
50
41
func refreshCollection(
51
- _ source: PackageCollectionsModel . CollectionSource ,
52
- callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
53
- )
42
+ _ source: PackageCollectionsModel . CollectionSource
43
+ ) async throws -> PackageCollectionsModel . Collection
54
44
55
45
/// Adds a package collection.
56
46
///
@@ -59,77 +49,46 @@ public protocol PackageCollectionsProtocol {
59
49
/// - order: Optional. The order that the `PackageCollection` should take after being added to the list.
60
50
/// By default the new collection is appended to the end (i.e., the least relevant order).
61
51
/// - trustConfirmationProvider: The closure to invoke when the collection is not signed and user confirmation is required to proceed
62
- /// - callback: The closure to invoke with the newly added `PackageCollection`
63
- @available ( * , noasync, message: " Use the async alternative " )
64
52
func addCollection(
65
53
_ source: PackageCollectionsModel . CollectionSource ,
66
54
order: Int ? ,
67
- trustConfirmationProvider: ( ( PackageCollectionsModel . Collection , @escaping ( Bool ) -> Void ) -> Void ) ? ,
68
- callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
69
- )
55
+ trustConfirmationProvider: ( ( PackageCollectionsModel . Collection , @escaping ( Bool ) -> Void ) -> Void ) ?
56
+ ) async throws -> PackageCollectionsModel . Collection
70
57
71
58
/// Removes a package collection.
72
59
///
73
60
/// - Parameters:
74
61
/// - source: The package collection's source
75
- /// - callback: The closure to invoke with the result becomes available
76
- @available ( * , noasync, message: " Use the async alternative " )
77
62
func removeCollection(
78
- _ source: PackageCollectionsModel . CollectionSource ,
79
- callback: @escaping ( Result < Void , Error > ) -> Void
80
- )
63
+ _ source: PackageCollectionsModel . CollectionSource
64
+ ) async throws
81
65
82
66
/// Moves a package collection to a different order.
83
67
///
84
68
/// - Parameters:
85
69
/// - source: The source of the `PackageCollection` to be reordered
86
70
/// - order: The new order that the `PackageCollection` should be positioned after the move
87
- /// - callback: The closure to invoke with the result becomes available
88
- @available ( * , noasync, message: " Use the async alternative " )
89
71
func moveCollection(
90
72
_ source: PackageCollectionsModel . CollectionSource ,
91
- to order: Int ,
92
- callback: @escaping ( Result < Void , Error > ) -> Void
93
- )
73
+ to order: Int
74
+ ) async throws
94
75
95
76
/// Updates settings of a `PackageCollection` source (e.g., if it is trusted or not).
96
77
///
97
78
/// - Parameters:
98
79
/// - source: The `PackageCollection` source to be updated
99
- /// - callback: The closure to invoke when result becomes available
100
- @available ( * , noasync, message: " Use the async alternative " )
101
80
func updateCollection(
102
- _ source: PackageCollectionsModel . CollectionSource ,
103
- callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
104
- )
81
+ _ source: PackageCollectionsModel . CollectionSource
82
+ ) async throws -> PackageCollectionsModel . Collection
105
83
106
84
/// Returns information about a package collection. The collection is not required to be in the configured list. If
107
85
/// not found locally, the collection will be fetched from the source.
108
86
///
109
87
/// - Parameters:
110
88
/// - source: The package collection's source
111
- /// - callback: The closure to invoke with the `PackageCollection`
112
- @available ( * , noasync, message: " Use the async alternative " )
113
89
func getCollection(
114
- _ source: PackageCollectionsModel . CollectionSource ,
115
- callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
116
- )
117
-
118
- /// Returns metadata for the package identified by the given `PackageIdentity`, along with the
119
- /// identifiers of `PackageCollection`s where the package is found.
120
- ///
121
- /// A failure is returned if the package is not found.
122
- ///
123
- /// - Parameters:
124
- /// - identity: The package identity
125
- /// - location: The package location (optional for deduplication)
126
- /// - callback: The closure to invoke when result becomes available
127
- @available ( * , noasync, message: " Use the async alternative " )
128
- func getPackageMetadata(
129
- identity: PackageIdentity ,
130
- location: String ? ,
131
- callback: @escaping ( Result < PackageCollectionsModel . PackageMetadata , Error > ) -> Void
132
- )
90
+ _ source: PackageCollectionsModel . CollectionSource
91
+ ) async throws -> PackageCollectionsModel . Collection
133
92
134
93
/// Returns metadata for the package identified by the given `PackageIdentity`, along with the
135
94
/// identifiers of `PackageCollection`s where the package is found.
@@ -141,25 +100,19 @@ public protocol PackageCollectionsProtocol {
141
100
/// - location: The package location (optional for deduplication)
142
101
/// - collections: Optional. If specified, only look for package in these collections. Data from the most recently
143
102
/// processed collection will be used.
144
- /// - callback: The closure to invoke when result becomes available
145
- @available ( * , noasync, message: " Use the async alternative " )
146
103
func getPackageMetadata(
147
104
identity: PackageIdentity ,
148
105
location: String ? ,
149
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
150
- callback: @escaping ( Result < PackageCollectionsModel . PackageMetadata , Error > ) -> Void
151
- )
106
+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ?
107
+ ) async throws -> PackageCollectionsModel . PackageMetadata
152
108
153
109
/// Lists packages from the specified collections.
154
110
///
155
111
/// - Parameters:
156
112
/// - collections: Optional. If specified, only packages in these collections are included.
157
- /// - callback: The closure to invoke when result becomes available
158
- @available ( * , noasync, message: " Use the async alternative " )
159
113
func listPackages(
160
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
161
- callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void
162
- )
114
+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ?
115
+ ) async throws -> PackageCollectionsModel . PackageSearchResult
163
116
164
117
// MARK: - Target (Module) APIs
165
118
@@ -171,12 +124,9 @@ public protocol PackageCollectionsProtocol {
171
124
///
172
125
/// - Parameters:
173
126
/// - collections: Optional. If specified, only list targets within these collections.
174
- /// - callback: The closure to invoke when result becomes available
175
- @available ( * , noasync, message: " Use the async alternative " )
176
127
func listTargets(
177
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
178
- callback: @escaping ( Result < PackageCollectionsModel . TargetListResult , Error > ) -> Void
179
- )
128
+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ?
129
+ ) async throws -> PackageCollectionsModel . TargetListResult
180
130
181
131
// MARK: - Search APIs
182
132
@@ -188,13 +138,10 @@ public protocol PackageCollectionsProtocol {
188
138
/// - Parameters:
189
139
/// - query: The search query
190
140
/// - collections: Optional. If specified, only search within these collections.
191
- /// - callback: The closure to invoke when result becomes available
192
- @available ( * , noasync, message: " Use the async alternative " )
193
141
func findPackages(
194
142
_ query: String ,
195
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
196
- callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void
197
- )
143
+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ?
144
+ ) async throws -> PackageCollectionsModel . PackageSearchResult
198
145
199
146
/// Finds targets by name and returns the corresponding packages.
200
147
///
@@ -206,168 +153,13 @@ public protocol PackageCollectionsProtocol {
206
153
/// - searchType: Optional. Target names must either match exactly or contain the prefix.
207
154
/// For more flexibility, use the `findPackages` API instead.
208
155
/// - collections: Optional. If specified, only search within these collections.
209
- /// - callback: The closure to invoke when result becomes available
210
- @available ( * , noasync, message: " Use the async alternative " )
211
156
func findTargets(
212
157
_ query: String ,
213
158
searchType: PackageCollectionsModel . TargetSearchType ? ,
214
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
215
- callback: @escaping ( Result < PackageCollectionsModel . TargetSearchResult , Error > ) -> Void
216
- )
159
+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ?
160
+ ) async throws -> PackageCollectionsModel . TargetSearchResult
217
161
}
218
162
219
- public extension PackageCollectionsProtocol {
220
- func listCollections(
221
- identifiers: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
222
- ) async throws -> [ PackageCollectionsModel . Collection ] {
223
- try await safe_async {
224
- self . listCollections ( identifiers: identifiers, callback: $0)
225
- }
226
- }
227
-
228
- func refreshCollections( ) async throws -> [ PackageCollectionsModel . CollectionSource ] {
229
- try await safe_async {
230
- self . refreshCollections ( callback: $0)
231
- }
232
- }
233
-
234
- func refreshCollection(
235
- _ source: PackageCollectionsModel . CollectionSource
236
- ) async throws -> PackageCollectionsModel . Collection {
237
- try await safe_async {
238
- self . refreshCollection (
239
- source,
240
- callback: $0
241
- )
242
- }
243
- }
244
-
245
- func addCollection(
246
- _ source: PackageCollectionsModel . CollectionSource ,
247
- order: Int ? = nil ,
248
- trustConfirmationProvider: ( ( PackageCollectionsModel . Collection , @escaping ( Bool ) -> Void ) -> Void ) ? = nil
249
- ) async throws -> PackageCollectionsModel . Collection {
250
- try await safe_async {
251
- self . addCollection (
252
- source,
253
- order: order,
254
- trustConfirmationProvider: trustConfirmationProvider,
255
- callback: $0
256
- )
257
- }
258
- }
259
-
260
- func removeCollection(
261
- _ source: PackageCollectionsModel . CollectionSource
262
- ) async throws {
263
- try await safe_async {
264
- self . removeCollection (
265
- source,
266
- callback: $0
267
- )
268
- }
269
- }
270
-
271
- func moveCollection(
272
- _ source: PackageCollectionsModel . CollectionSource ,
273
- to order: Int
274
- ) async throws {
275
- try await safe_async {
276
- self . moveCollection (
277
- source,
278
- to: order,
279
- callback: $0
280
- )
281
- }
282
- }
283
-
284
- func updateCollection(
285
- _ source: PackageCollectionsModel . CollectionSource
286
- ) async throws -> PackageCollectionsModel . Collection {
287
- try await safe_async {
288
- self . updateCollection (
289
- source,
290
- callback: $0
291
- )
292
- }
293
- }
294
-
295
- func getCollection(
296
- _ source: PackageCollectionsModel . CollectionSource
297
- ) async throws -> PackageCollectionsModel . Collection {
298
- try await safe_async {
299
- self . getCollection (
300
- source,
301
- callback: $0
302
- )
303
- }
304
- }
305
-
306
- func getPackageMetadata(
307
- identity: PackageIdentity ,
308
- location: String ? = nil ,
309
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
310
- ) async throws -> PackageCollectionsModel . PackageMetadata {
311
- try await safe_async {
312
- self . getPackageMetadata (
313
- identity: identity,
314
- location: location,
315
- collections: collections,
316
- callback: $0
317
- )
318
- }
319
- }
320
-
321
- func listPackages(
322
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
323
- ) async throws -> PackageCollectionsModel . PackageSearchResult {
324
- try await safe_async {
325
- self . listPackages (
326
- collections: collections,
327
- callback: $0
328
- )
329
- }
330
- }
331
-
332
- func listTargets(
333
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
334
- ) async throws -> PackageCollectionsModel . TargetListResult {
335
- try await safe_async {
336
- self . listTargets (
337
- collections: collections,
338
- callback: $0
339
- )
340
- }
341
- }
342
-
343
- func findPackages(
344
- _ query: String ,
345
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
346
- ) async throws -> PackageCollectionsModel . PackageSearchResult {
347
- try await safe_async {
348
- self . findPackages (
349
- query,
350
- collections: collections,
351
- callback: $0
352
- )
353
- }
354
- }
355
-
356
- func findTargets(
357
- _ query: String ,
358
- searchType: PackageCollectionsModel . TargetSearchType ? = nil ,
359
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
360
- ) async throws -> PackageCollectionsModel . TargetSearchResult {
361
- try await safe_async {
362
- self . findTargets (
363
- query,
364
- searchType: searchType,
365
- collections: collections,
366
- callback: $0
367
- )
368
- }
369
- }
370
- }
371
163
372
164
public enum PackageCollectionError : Equatable , Error {
373
165
/// Package collection is not signed and there is no record of user's trust selection
0 commit comments