1313import struct Foundation. URL
1414import PackageModel
1515import SourceControl
16+ import Basics
1617
1718// MARK: - Package collection
1819
@@ -27,6 +28,7 @@ public protocol PackageCollectionsProtocol {
2728 /// - Parameters:
2829 /// - identifiers: Optional. If specified, only `PackageCollection`s with matching identifiers will be returned.
2930 /// - callback: The closure to invoke when result becomes available
31+ @available ( * , noasync, message: " Use the async alternative " )
3032 func listCollections(
3133 identifiers: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
3234 callback: @escaping ( Result < [ PackageCollectionsModel . Collection ] , Error > ) -> Void
@@ -36,13 +38,15 @@ public protocol PackageCollectionsProtocol {
3638 ///
3739 /// - Parameters:
3840 /// - callback: The closure to invoke after triggering a refresh for the configured package collections.
41+ @available ( * , noasync, message: " Use the async alternative " )
3942 func refreshCollections( callback: @escaping ( Result < [ PackageCollectionsModel . CollectionSource ] , Error > ) -> Void )
4043
4144 /// Refreshes a package collection.
4245 ///
4346 /// - Parameters:
4447 /// - source: The package collection to be refreshed
4548 /// - callback: The closure to invoke with the refreshed `PackageCollection`
49+ @available ( * , noasync, message: " Use the async alternative " )
4650 func refreshCollection(
4751 _ source: PackageCollectionsModel . CollectionSource ,
4852 callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
@@ -56,6 +60,7 @@ public protocol PackageCollectionsProtocol {
5660 /// By default the new collection is appended to the end (i.e., the least relevant order).
5761 /// - trustConfirmationProvider: The closure to invoke when the collection is not signed and user confirmation is required to proceed
5862 /// - callback: The closure to invoke with the newly added `PackageCollection`
63+ @available ( * , noasync, message: " Use the async alternative " )
5964 func addCollection(
6065 _ source: PackageCollectionsModel . CollectionSource ,
6166 order: Int ? ,
@@ -68,6 +73,7 @@ public protocol PackageCollectionsProtocol {
6873 /// - Parameters:
6974 /// - source: The package collection's source
7075 /// - callback: The closure to invoke with the result becomes available
76+ @available ( * , noasync, message: " Use the async alternative " )
7177 func removeCollection(
7278 _ source: PackageCollectionsModel . CollectionSource ,
7379 callback: @escaping ( Result < Void , Error > ) -> Void
@@ -79,6 +85,7 @@ public protocol PackageCollectionsProtocol {
7985 /// - source: The source of the `PackageCollection` to be reordered
8086 /// - order: The new order that the `PackageCollection` should be positioned after the move
8187 /// - callback: The closure to invoke with the result becomes available
88+ @available ( * , noasync, message: " Use the async alternative " )
8289 func moveCollection(
8390 _ source: PackageCollectionsModel . CollectionSource ,
8491 to order: Int ,
@@ -90,6 +97,7 @@ public protocol PackageCollectionsProtocol {
9097 /// - Parameters:
9198 /// - source: The `PackageCollection` source to be updated
9299 /// - callback: The closure to invoke when result becomes available
100+ @available ( * , noasync, message: " Use the async alternative " )
93101 func updateCollection(
94102 _ source: PackageCollectionsModel . CollectionSource ,
95103 callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
@@ -101,6 +109,7 @@ public protocol PackageCollectionsProtocol {
101109 /// - Parameters:
102110 /// - source: The package collection's source
103111 /// - callback: The closure to invoke with the `PackageCollection`
112+ @available ( * , noasync, message: " Use the async alternative " )
104113 func getCollection(
105114 _ source: PackageCollectionsModel . CollectionSource ,
106115 callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
@@ -115,6 +124,7 @@ public protocol PackageCollectionsProtocol {
115124 /// - identity: The package identity
116125 /// - location: The package location (optional for deduplication)
117126 /// - callback: The closure to invoke when result becomes available
127+ @available ( * , noasync, message: " Use the async alternative " )
118128 func getPackageMetadata(
119129 identity: PackageIdentity ,
120130 location: String ? ,
@@ -132,6 +142,7 @@ public protocol PackageCollectionsProtocol {
132142 /// - collections: Optional. If specified, only look for package in these collections. Data from the most recently
133143 /// processed collection will be used.
134144 /// - callback: The closure to invoke when result becomes available
145+ @available ( * , noasync, message: " Use the async alternative " )
135146 func getPackageMetadata(
136147 identity: PackageIdentity ,
137148 location: String ? ,
@@ -144,6 +155,7 @@ public protocol PackageCollectionsProtocol {
144155 /// - Parameters:
145156 /// - collections: Optional. If specified, only packages in these collections are included.
146157 /// - callback: The closure to invoke when result becomes available
158+ @available ( * , noasync, message: " Use the async alternative " )
147159 func listPackages(
148160 collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
149161 callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void
@@ -160,6 +172,7 @@ public protocol PackageCollectionsProtocol {
160172 /// - Parameters:
161173 /// - collections: Optional. If specified, only list targets within these collections.
162174 /// - callback: The closure to invoke when result becomes available
175+ @available ( * , noasync, message: " Use the async alternative " )
163176 func listTargets(
164177 collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
165178 callback: @escaping ( Result < PackageCollectionsModel . TargetListResult , Error > ) -> Void
@@ -176,6 +189,7 @@ public protocol PackageCollectionsProtocol {
176189 /// - query: The search query
177190 /// - collections: Optional. If specified, only search within these collections.
178191 /// - callback: The closure to invoke when result becomes available
192+ @available ( * , noasync, message: " Use the async alternative " )
179193 func findPackages(
180194 _ query: String ,
181195 collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
@@ -193,6 +207,7 @@ public protocol PackageCollectionsProtocol {
193207 /// For more flexibility, use the `findPackages` API instead.
194208 /// - collections: Optional. If specified, only search within these collections.
195209 /// - callback: The closure to invoke when result becomes available
210+ @available ( * , noasync, message: " Use the async alternative " )
196211 func findTargets(
197212 _ query: String ,
198213 searchType: PackageCollectionsModel . TargetSearchType ? ,
@@ -201,6 +216,158 @@ public protocol PackageCollectionsProtocol {
201216 )
202217}
203218
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+ func removeCollection(
260+ _ source: PackageCollectionsModel . CollectionSource
261+ ) async throws {
262+ try await safe_async {
263+ self . removeCollection (
264+ source,
265+ callback: $0
266+ )
267+ }
268+ }
269+
270+ func moveCollection(
271+ _ source: PackageCollectionsModel . CollectionSource ,
272+ to order: Int
273+ ) async throws {
274+ try await safe_async {
275+ self . moveCollection (
276+ source,
277+ to: order,
278+ callback: $0
279+ )
280+ }
281+ }
282+
283+ func updateCollection(
284+ _ source: PackageCollectionsModel . CollectionSource
285+ ) async throws -> PackageCollectionsModel . Collection {
286+ try await safe_async {
287+ self . updateCollection (
288+ source,
289+ callback: $0
290+ )
291+ }
292+ }
293+
294+ func getCollection(
295+ _ source: PackageCollectionsModel . CollectionSource
296+ ) async throws -> PackageCollectionsModel . Collection {
297+ try await safe_async {
298+ self . getCollection (
299+ source,
300+ callback: $0
301+ )
302+ }
303+ }
304+
305+ func getPackageMetadata(
306+ identity: PackageIdentity ,
307+ location: String ? = nil ,
308+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
309+ ) async throws -> PackageCollectionsModel . PackageMetadata {
310+ try await safe_async {
311+ self . getPackageMetadata (
312+ identity: identity,
313+ location: location,
314+ collections: collections,
315+ callback: $0
316+ )
317+ }
318+ }
319+
320+ func listPackages(
321+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
322+ ) async throws -> PackageCollectionsModel . PackageSearchResult {
323+ try await safe_async {
324+ self . listPackages (
325+ collections: collections,
326+ callback: $0
327+ )
328+ }
329+ }
330+
331+ func listTargets(
332+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
333+ ) async throws -> PackageCollectionsModel . TargetListResult {
334+ try await safe_async {
335+ self . listTargets (
336+ collections: collections,
337+ callback: $0
338+ )
339+ }
340+ }
341+
342+ func findPackages(
343+ _ query: String ,
344+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
345+ ) async throws -> PackageCollectionsModel . PackageSearchResult {
346+ try await safe_async {
347+ self . findPackages (
348+ query,
349+ collections: collections,
350+ callback: $0
351+ )
352+ }
353+ }
354+
355+ func findTargets(
356+ _ query: String ,
357+ searchType: PackageCollectionsModel . TargetSearchType ? = nil ,
358+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil
359+ ) async throws -> PackageCollectionsModel . TargetSearchResult {
360+ try await safe_async {
361+ self . findTargets (
362+ query,
363+ searchType: searchType,
364+ collections: collections,
365+ callback: $0
366+ )
367+ }
368+ }
369+ }
370+
204371public enum PackageCollectionError : Equatable , Error {
205372 /// Package collection is not signed and there is no record of user's trust selection
206373 case trustConfirmationRequired
@@ -233,6 +400,7 @@ public protocol PackageIndexProtocol {
233400 /// - identity: The package identity
234401 /// - location: The package location (optional for deduplication)
235402 /// - callback: The closure to invoke when result becomes available
403+ @available ( * , noasync, message: " Use the async alternative " )
236404 func getPackageMetadata(
237405 identity: PackageIdentity ,
238406 location: String ? ,
@@ -244,6 +412,7 @@ public protocol PackageIndexProtocol {
244412 /// - Parameters:
245413 /// - query: The search query
246414 /// - callback: The closure to invoke when result becomes available
415+ @available ( * , noasync, message: " Use the async alternative " )
247416 func findPackages(
248417 _ query: String ,
249418 callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void
@@ -255,13 +424,62 @@ public protocol PackageIndexProtocol {
255424 /// - offset: Offset of the first item in the result
256425 /// - limit: Number of items to return in the result. Implementations might impose a threshold for this.
257426 /// - callback: The closure to invoke when result becomes available
427+ @available ( * , noasync, message: " Use the async alternative " )
258428 func listPackages(
259429 offset: Int ,
260430 limit: Int ,
261431 callback: @escaping ( Result < PackageCollectionsModel . PaginatedPackageList , Error > ) -> Void
262432 )
263433}
264434
435+ public extension PackageIndexProtocol {
436+
437+ func getPackageMetadata(
438+ identity: PackageIdentity ,
439+ location: String ?
440+ ) async throws -> PackageCollectionsModel . PackageMetadata {
441+ try await safe_async {
442+ self . getPackageMetadata (
443+ identity: identity,
444+ location: location,
445+ callback: $0
446+ )
447+ }
448+ }
449+
450+ /// Finds and returns packages that match the query.
451+ ///
452+ /// - Parameters:
453+ /// - query: The search query
454+ /// - callback: The closure to invoke when result becomes available
455+ func findPackages(
456+ _ query: String
457+ ) async throws -> PackageCollectionsModel . PackageSearchResult {
458+ try await safe_async {
459+ self . findPackages ( query, callback: $0)
460+ }
461+ }
462+
463+ /// A paginated list of packages in the index.
464+ ///
465+ /// - Parameters:
466+ /// - offset: Offset of the first item in the result
467+ /// - limit: Number of items to return in the result. Implementations might impose a threshold for this.
468+ /// - callback: The closure to invoke when result becomes available
469+ func listPackages(
470+ offset: Int ,
471+ limit: Int
472+ ) async throws -> PackageCollectionsModel . PaginatedPackageList {
473+ try await safe_async {
474+ self . listPackages (
475+ offset: offset,
476+ limit: limit,
477+ callback: $0
478+ )
479+ }
480+ }
481+ }
482+
265483public enum PackageIndexError : Equatable , Error {
266484 /// Package index support is disabled
267485 case featureDisabled
0 commit comments