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
|
//===----------------------------------------------------------------------===//
//
// 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 Basics
public protocol PackageCollectionsSourcesStorage {
/// Lists all `PackageCollectionSource`s.
///
/// - Parameters:
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func list(callback: @escaping (Result<[PackageCollectionsModel.CollectionSource], Error>) -> Void)
/// Adds the given source.
///
/// - Parameters:
/// - source: The `PackageCollectionSource` to add
/// - order: Optional. The order that the source should take after being added.
/// By default the new source is appended to the end (i.e., the least relevant order).
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func add(source: PackageCollectionsModel.CollectionSource,
order: Int?,
callback: @escaping (Result<Void, Error>) -> Void)
/// Removes the given source.
///
/// - Parameters:
/// - source: The `PackageCollectionSource` to remove
/// - profile: The `Profile` to remove source
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func remove(source: PackageCollectionsModel.CollectionSource,
callback: @escaping (Result<Void, Error>) -> Void)
/// Moves source to a different order.
///
/// - Parameters:
/// - source: The `PackageCollectionSource` to move
/// - order: The order that the source should take.
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func move(source: PackageCollectionsModel.CollectionSource,
to order: Int,
callback: @escaping (Result<Void, Error>) -> Void)
/// Checks if a source has already been added.
///
/// - Parameters:
/// - source: The `PackageCollectionSource`
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func exists(source: PackageCollectionsModel.CollectionSource,
callback: @escaping (Result<Bool, Error>) -> Void)
/// Updates the given source.
///
/// - Parameters:
/// - source: The `PackageCollectionSource` to update
/// - callback: The closure to invoke when result becomes available
@available(*, noasync, message: "Use the async alternative")
func update(source: PackageCollectionsModel.CollectionSource,
callback: @escaping (Result<Void, Error>) -> Void)
}
public extension PackageCollectionsSourcesStorage {
func list() async throws -> [PackageCollectionsModel.CollectionSource] {
try await safe_async {
self.list(callback: $0)
}
}
func add(source: PackageCollectionsModel.CollectionSource,
order: Int? = nil) async throws {
try await safe_async {
self.add(source: source, order: order, callback: $0)
}
}
func remove(source: PackageCollectionsModel.CollectionSource) async throws {
try await safe_async {
self.remove(source: source, callback: $0)
}
}
func move(source: PackageCollectionsModel.CollectionSource, to order: Int) async throws {
try await safe_async {
self.move(source: source, to:order, callback: $0)
}
}
func exists(source: PackageCollectionsModel.CollectionSource) async throws -> Bool {
try await safe_async {
self.exists(source: source, callback: $0)
}
}
func update(source: PackageCollectionsModel.CollectionSource) async throws {
try await safe_async {
self.update(source: source, callback: $0)
}
}
}
|