-
Notifications
You must be signed in to change notification settings - Fork 1.4k
implement package-collections business logic #3028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This source file is part of the Swift.org open source project | ||
# | ||
# Copyright (c) 2020 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 Swift project authors | ||
|
||
add_library(PackageCollections | ||
Model/CVE.swift | ||
Model/Collection.swift | ||
Model/License.swift | ||
Model/Package.swift | ||
Model/Profile.swift | ||
Model/Search.swift | ||
Model/TargetListResult.swift | ||
PackageCollectionProvider.swift | ||
PackageCollections+Configuration.swift | ||
PackageCollections+Storage.swift | ||
PackageCollections+Vallidation.swift | ||
PackageCollections.swift | ||
Storage/PackageCollectionsProfileStorage.swift | ||
Storage/PackageCollectionsStorage.swift | ||
Utility.swift) | ||
target_link_libraries(PackageCollections PUBLIC | ||
TSCBasic | ||
TSCUtility | ||
PackageModel | ||
SourceControl) | ||
# NOTE(compnerd) workaround for CMake not setting up include flags yet | ||
set_target_properties(PackageCollections PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) | ||
|
||
if(USE_CMAKE_INSTALL) | ||
install(TARGETS PackageCollections | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib | ||
RUNTIME DESTINATION bin) | ||
endif() | ||
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageCollections) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,9 @@ public enum PackageCollectionsModel {} | |
|
||
extension PackageCollectionsModel { | ||
/// A `PackageCollection` is a collection of packages. | ||
public struct PackageCollection: Codable { | ||
public typealias Identifier = PackageCollectionIdentifier | ||
public typealias Source = PackageCollectionSource | ||
public struct Collection: Equatable, Codable { | ||
public typealias Identifier = CollectionIdentifier | ||
public typealias Source = CollectionSource | ||
|
||
/// The identifier of the group | ||
public let identifier: Identifier | ||
|
@@ -57,7 +57,7 @@ extension PackageCollectionsModel { | |
createdAt: Date, | ||
lastProcessedAt: Date = Date() | ||
) { | ||
self.identifier = .init(source: source) | ||
self.identifier = .init(from: source) | ||
self.source = source | ||
self.name = name | ||
self.description = description | ||
|
@@ -71,52 +71,69 @@ extension PackageCollectionsModel { | |
|
||
extension PackageCollectionsModel { | ||
/// Represents the source of a `PackageCollection` | ||
public enum PackageCollectionSource: Equatable { | ||
/// Package feed at URL | ||
case feed(URL) | ||
public struct CollectionSource: Equatable, Hashable, Codable { | ||
/// Source type | ||
public let type: CollectionSourceType | ||
|
||
/// URL of the source file | ||
public let url: URL | ||
tomerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public init(type: CollectionSourceType, url: URL) { | ||
self.type = type | ||
self.url = url | ||
} | ||
} | ||
} | ||
|
||
extension PackageCollectionsModel.PackageCollectionSource: Codable { | ||
public enum DiscriminatorKeys: String, Codable { | ||
/// Represents the source type of a `PackageCollection` | ||
public enum CollectionSourceType: Equatable, CaseIterable { | ||
case feed | ||
} | ||
} | ||
|
||
extension PackageCollectionsModel.CollectionSourceType: Codable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the whole purpose of this just to be able to throw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yim-lee are you asking about the purpose of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use synthesized conformance and remove this extension block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I dont believe enums synthesize conformance. am I missing anything? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could if |
||
public enum CodingKeys: CodingKey { | ||
case _case | ||
case url | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
switch try container.decode(DiscriminatorKeys.self, forKey: ._case) { | ||
case .feed: | ||
let url = try container.decode(URL.self, forKey: .url) | ||
self = .feed(url) | ||
let value = try container.decode(String.self, forKey: ._case) | ||
switch value { | ||
case "feed": | ||
self = .feed | ||
default: | ||
throw UnknownType(value) | ||
} | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
switch self { | ||
case .feed(let url): | ||
try container.encode(DiscriminatorKeys.feed, forKey: ._case) | ||
try container.encode(url, forKey: .url) | ||
case .feed: | ||
try container.encode("feed", forKey: ._case) | ||
} | ||
} | ||
|
||
struct UnknownType: Error { | ||
let type: String | ||
|
||
init(_ type: String) { | ||
self.type = type | ||
} | ||
} | ||
} | ||
|
||
extension PackageCollectionsModel { | ||
/// Represents the identifier of a `PackageCollection` | ||
public enum PackageCollectionIdentifier: Hashable, Comparable { | ||
public enum CollectionIdentifier: Hashable, Comparable { | ||
/// Package feed at URL | ||
case feed(URL) | ||
|
||
/// Creates an `Identifier` from `Source` | ||
init(source: PackageCollectionSource) { | ||
switch source { | ||
case .feed(let url): | ||
self = .feed(url) | ||
init(from source: CollectionSource) { | ||
switch source.type { | ||
case .feed: | ||
self = .feed(source.url) | ||
} | ||
} | ||
|
||
|
@@ -129,7 +146,7 @@ extension PackageCollectionsModel { | |
} | ||
} | ||
|
||
extension PackageCollectionsModel.PackageCollection.Identifier: Codable { | ||
extension PackageCollectionsModel.CollectionIdentifier: Codable { | ||
public enum DiscriminatorKeys: String, Codable { | ||
case feed | ||
} | ||
|
@@ -158,9 +175,9 @@ extension PackageCollectionsModel.PackageCollection.Identifier: Codable { | |
} | ||
} | ||
|
||
extension PackageCollectionsModel.PackageCollection { | ||
extension PackageCollectionsModel.Collection { | ||
/// A representation of package metadata | ||
public struct Package: Codable { | ||
public struct Package: Equatable, Codable { | ||
public typealias Version = PackageVersion | ||
|
||
/// Package reference | ||
|
@@ -194,9 +211,9 @@ extension PackageCollectionsModel.PackageCollection { | |
} | ||
} | ||
|
||
extension PackageCollectionsModel.PackageCollection { | ||
extension PackageCollectionsModel.Collection { | ||
/// A representation of package version | ||
public struct PackageVersion: Codable { | ||
public struct PackageVersion: Equatable, Codable { | ||
public typealias Target = PackageCollectionsModel.PackageTarget | ||
public typealias Product = PackageCollectionsModel.PackageProduct | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.