1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import PackageModel
import Basics
public protocol PackageCollectionsStorage {
/// Writes `PackageCollection` to storage.
///
/// - Parameters:
/// - collection: The `PackageCollection`
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func put(collection: PackageCollectionsModel.Collection,
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void)
/// Removes `PackageCollection` from storage.
///
/// - Parameters:
/// - identifier: The identifier of the `PackageCollection`
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func remove(identifier: PackageCollectionsModel.CollectionIdentifier,
callback: @escaping (Result<Void, Error>) -> Void)
/// Returns `PackageCollection` for the given identifier.
///
/// - Parameters:
/// - identifier: The identifier of the `PackageCollection`
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func get(identifier: PackageCollectionsModel.CollectionIdentifier,
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void)
/// Returns `PackageCollection`s for the given identifiers, or all if none specified.
///
/// - Parameters:
/// - identifiers: Optional. The identifiers of the `PackageCollection`
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func list(identifiers: [PackageCollectionsModel.CollectionIdentifier]?,
callback: @escaping (Result<[PackageCollectionsModel.Collection], Error>) -> Void)
/// Returns `PackageSearchResult` for the given search criteria.
///
/// - Parameters:
/// - identifiers: Optional. The identifiers of the `PackageCollection`s
/// - query: The search query expression
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func searchPackages(identifiers: [PackageCollectionsModel.CollectionIdentifier]?,
query: String,
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult, Error>) -> Void)
/// Returns packages for the given package identity.
///
/// Since a package identity can be associated with more than one repository URL, the result may contain multiple items.
///
/// - Parameters:
/// - identifier: The package identifier
/// - collectionIdentifiers: Optional. The identifiers of the `PackageCollection`s
/// - callback: The closure to invoke when result becomes available
func findPackage(identifier: PackageIdentity,
collectionIdentifiers: [PackageCollectionsModel.CollectionIdentifier]?,
callback: @escaping (Result<(packages: [PackageCollectionsModel.Package], collections: [PackageCollectionsModel.CollectionIdentifier]), Error>) -> Void)
/// Returns `TargetSearchResult` for the given search criteria.
///
/// - Parameters:
/// - identifiers: Optional. The identifiers of the `PackageCollection`
/// - query: The search query expression
/// - type: The search type
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func searchTargets(identifiers: [PackageCollectionsModel.CollectionIdentifier]?,
query: String,
type: PackageCollectionsModel.TargetSearchType,
callback: @escaping (Result<PackageCollectionsModel.TargetSearchResult, Error>) -> Void)
}
public extension PackageCollectionsStorage {
func put(collection: PackageCollectionsModel.Collection) async throws -> PackageCollectionsModel.Collection {
try await safe_async {
self.put(collection: collection, callback: $0)
}
}
func remove(identifier: PackageCollectionsModel.CollectionIdentifier) async throws {
try await safe_async {
self.remove(identifier: identifier, callback: $0)
}
}
func get(identifier: PackageCollectionsModel.CollectionIdentifier) async throws -> PackageCollectionsModel.Collection {
try await safe_async {
self.get(identifier: identifier, callback: $0)
}
}
func list(identifiers: [PackageCollectionsModel.CollectionIdentifier]? = nil) async throws -> [PackageCollectionsModel.Collection] {
try await safe_async {
self.list(identifiers: identifiers, callback: $0)
}
}
func searchTargets(
identifiers: [PackageCollectionsModel.CollectionIdentifier]? = nil,
query: String,
type: PackageCollectionsModel.TargetSearchType
) async throws -> PackageCollectionsModel.TargetSearchResult {
try await safe_async {
self.searchTargets(identifiers: identifiers, query: query, type: type, callback: $0)
}
}
}
|