13
13
import struct Foundation. URL
14
14
import PackageModel
15
15
import SourceControl
16
+ import Basics
16
17
17
18
// MARK: - Package collection
18
19
@@ -27,6 +28,7 @@ public protocol PackageCollectionsProtocol {
27
28
/// - Parameters:
28
29
/// - identifiers: Optional. If specified, only `PackageCollection`s with matching identifiers will be returned.
29
30
/// - callback: The closure to invoke when result becomes available
31
+ @available ( * , noasync, message: " Use the async alternative " )
30
32
func listCollections(
31
33
identifiers: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
32
34
callback: @escaping ( Result < [ PackageCollectionsModel . Collection ] , Error > ) -> Void
@@ -36,13 +38,15 @@ public protocol PackageCollectionsProtocol {
36
38
///
37
39
/// - Parameters:
38
40
/// - callback: The closure to invoke after triggering a refresh for the configured package collections.
41
+ @available ( * , noasync, message: " Use the async alternative " )
39
42
func refreshCollections( callback: @escaping ( Result < [ PackageCollectionsModel . CollectionSource ] , Error > ) -> Void )
40
43
41
44
/// Refreshes a package collection.
42
45
///
43
46
/// - Parameters:
44
47
/// - source: The package collection to be refreshed
45
48
/// - callback: The closure to invoke with the refreshed `PackageCollection`
49
+ @available ( * , noasync, message: " Use the async alternative " )
46
50
func refreshCollection(
47
51
_ source: PackageCollectionsModel . CollectionSource ,
48
52
callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
@@ -56,6 +60,7 @@ public protocol PackageCollectionsProtocol {
56
60
/// By default the new collection is appended to the end (i.e., the least relevant order).
57
61
/// - trustConfirmationProvider: The closure to invoke when the collection is not signed and user confirmation is required to proceed
58
62
/// - callback: The closure to invoke with the newly added `PackageCollection`
63
+ @available ( * , noasync, message: " Use the async alternative " )
59
64
func addCollection(
60
65
_ source: PackageCollectionsModel . CollectionSource ,
61
66
order: Int ? ,
@@ -68,6 +73,7 @@ public protocol PackageCollectionsProtocol {
68
73
/// - Parameters:
69
74
/// - source: The package collection's source
70
75
/// - callback: The closure to invoke with the result becomes available
76
+ @available ( * , noasync, message: " Use the async alternative " )
71
77
func removeCollection(
72
78
_ source: PackageCollectionsModel . CollectionSource ,
73
79
callback: @escaping ( Result < Void , Error > ) -> Void
@@ -79,6 +85,7 @@ public protocol PackageCollectionsProtocol {
79
85
/// - source: The source of the `PackageCollection` to be reordered
80
86
/// - order: The new order that the `PackageCollection` should be positioned after the move
81
87
/// - callback: The closure to invoke with the result becomes available
88
+ @available ( * , noasync, message: " Use the async alternative " )
82
89
func moveCollection(
83
90
_ source: PackageCollectionsModel . CollectionSource ,
84
91
to order: Int ,
@@ -90,6 +97,7 @@ public protocol PackageCollectionsProtocol {
90
97
/// - Parameters:
91
98
/// - source: The `PackageCollection` source to be updated
92
99
/// - callback: The closure to invoke when result becomes available
100
+ @available ( * , noasync, message: " Use the async alternative " )
93
101
func updateCollection(
94
102
_ source: PackageCollectionsModel . CollectionSource ,
95
103
callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
@@ -101,6 +109,7 @@ public protocol PackageCollectionsProtocol {
101
109
/// - Parameters:
102
110
/// - source: The package collection's source
103
111
/// - callback: The closure to invoke with the `PackageCollection`
112
+ @available ( * , noasync, message: " Use the async alternative " )
104
113
func getCollection(
105
114
_ source: PackageCollectionsModel . CollectionSource ,
106
115
callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
@@ -115,6 +124,7 @@ public protocol PackageCollectionsProtocol {
115
124
/// - identity: The package identity
116
125
/// - location: The package location (optional for deduplication)
117
126
/// - callback: The closure to invoke when result becomes available
127
+ @available ( * , noasync, message: " Use the async alternative " )
118
128
func getPackageMetadata(
119
129
identity: PackageIdentity ,
120
130
location: String ? ,
@@ -132,6 +142,7 @@ public protocol PackageCollectionsProtocol {
132
142
/// - collections: Optional. If specified, only look for package in these collections. Data from the most recently
133
143
/// processed collection will be used.
134
144
/// - callback: The closure to invoke when result becomes available
145
+ @available ( * , noasync, message: " Use the async alternative " )
135
146
func getPackageMetadata(
136
147
identity: PackageIdentity ,
137
148
location: String ? ,
@@ -144,6 +155,7 @@ public protocol PackageCollectionsProtocol {
144
155
/// - Parameters:
145
156
/// - collections: Optional. If specified, only packages in these collections are included.
146
157
/// - callback: The closure to invoke when result becomes available
158
+ @available ( * , noasync, message: " Use the async alternative " )
147
159
func listPackages(
148
160
collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
149
161
callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void
@@ -160,6 +172,7 @@ public protocol PackageCollectionsProtocol {
160
172
/// - Parameters:
161
173
/// - collections: Optional. If specified, only list targets within these collections.
162
174
/// - callback: The closure to invoke when result becomes available
175
+ @available ( * , noasync, message: " Use the async alternative " )
163
176
func listTargets(
164
177
collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
165
178
callback: @escaping ( Result < PackageCollectionsModel . TargetListResult , Error > ) -> Void
@@ -176,6 +189,7 @@ public protocol PackageCollectionsProtocol {
176
189
/// - query: The search query
177
190
/// - collections: Optional. If specified, only search within these collections.
178
191
/// - callback: The closure to invoke when result becomes available
192
+ @available ( * , noasync, message: " Use the async alternative " )
179
193
func findPackages(
180
194
_ query: String ,
181
195
collections: Set < PackageCollectionsModel . CollectionIdentifier > ? ,
@@ -193,6 +207,7 @@ public protocol PackageCollectionsProtocol {
193
207
/// For more flexibility, use the `findPackages` API instead.
194
208
/// - collections: Optional. If specified, only search within these collections.
195
209
/// - callback: The closure to invoke when result becomes available
210
+ @available ( * , noasync, message: " Use the async alternative " )
196
211
func findTargets(
197
212
_ query: String ,
198
213
searchType: PackageCollectionsModel . TargetSearchType ? ,
@@ -201,6 +216,159 @@ public protocol PackageCollectionsProtocol {
201
216
)
202
217
}
203
218
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
+
204
372
public enum PackageCollectionError : Equatable , Error {
205
373
/// Package collection is not signed and there is no record of user's trust selection
206
374
case trustConfirmationRequired
@@ -233,6 +401,7 @@ public protocol PackageIndexProtocol {
233
401
/// - identity: The package identity
234
402
/// - location: The package location (optional for deduplication)
235
403
/// - callback: The closure to invoke when result becomes available
404
+ @available ( * , noasync, message: " Use the async alternative " )
236
405
func getPackageMetadata(
237
406
identity: PackageIdentity ,
238
407
location: String ? ,
@@ -244,6 +413,7 @@ public protocol PackageIndexProtocol {
244
413
/// - Parameters:
245
414
/// - query: The search query
246
415
/// - callback: The closure to invoke when result becomes available
416
+ @available ( * , noasync, message: " Use the async alternative " )
247
417
func findPackages(
248
418
_ query: String ,
249
419
callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void
@@ -255,13 +425,61 @@ public protocol PackageIndexProtocol {
255
425
/// - offset: Offset of the first item in the result
256
426
/// - limit: Number of items to return in the result. Implementations might impose a threshold for this.
257
427
/// - callback: The closure to invoke when result becomes available
428
+ @available ( * , noasync, message: " Use the async alternative " )
258
429
func listPackages(
259
430
offset: Int ,
260
431
limit: Int ,
261
432
callback: @escaping ( Result < PackageCollectionsModel . PaginatedPackageList , Error > ) -> Void
262
433
)
263
434
}
264
435
436
+ public extension PackageIndexProtocol {
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
+
265
483
public enum PackageIndexError : Equatable , Error {
266
484
/// Package index support is disabled
267
485
case featureDisabled
0 commit comments