-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
deployments.get
endpoint (#74)
* Fix Codable implementation for Account * Add support for deployments.get endpoint
- Loading branch information
Showing
5 changed files
with
151 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,95 @@ | ||
import struct Foundation.Date | ||
|
||
/// A deployment of a model on Replicate. | ||
public enum Deployment { | ||
/// A deployment identifier. | ||
public struct ID: Hashable { | ||
/// The owner of the deployment. | ||
public let owner: String | ||
|
||
/// The name of the deployment. | ||
public let name: String | ||
public struct Deployment: Hashable { | ||
/// The owner of the deployment. | ||
public let owner: String | ||
|
||
/// The name of the deployment. | ||
public let name: String | ||
|
||
/// A release of a deployment. | ||
public struct Release: Hashable { | ||
/// The release number. | ||
let number: Int | ||
|
||
/// The model. | ||
let model: Model.ID | ||
|
||
/// The model version. | ||
let version: Model.Version.ID | ||
|
||
/// The time at which the release was created. | ||
let createdAt: Date | ||
|
||
/// The account that created the release | ||
let createdBy: Account | ||
|
||
/// The configuration of a deployment. | ||
public struct Configuration: Hashable { | ||
/// The configured hardware SKU. | ||
public let hardware: Hardware.ID | ||
|
||
/// A scaling configuration for a deployment. | ||
public struct Scaling: Hashable { | ||
/// The maximum number of instances. | ||
public let maxInstances: Int | ||
|
||
/// The minimum number of instances. | ||
public let minInstances: Int | ||
} | ||
|
||
/// The scaling configuration for the deployment. | ||
public let scaling: Scaling | ||
} | ||
|
||
/// The deployment configuration. | ||
public let configuration: Configuration | ||
} | ||
|
||
public let currentRelease: Release? | ||
} | ||
|
||
// MARK: - CustomStringConvertible | ||
// MARK: - Identifiable | ||
|
||
extension Deployment.ID: CustomStringConvertible { | ||
public var description: String { | ||
return "\(owner)/\(name)" | ||
} | ||
extension Deployment: Identifiable { | ||
public typealias ID = String | ||
|
||
/// The ID of the model. | ||
public var id: ID { "\(owner)/\(name)" } | ||
} | ||
|
||
// MARK: - ExpressibleByStringLiteral | ||
// MARK: - Codable | ||
|
||
extension Deployment.ID: ExpressibleByStringLiteral { | ||
public init(stringLiteral value: StringLiteralType) { | ||
let components = value.split(separator: "/") | ||
guard components.count == 2 else { fatalError("Invalid deployment ID: \(value)") } | ||
self.init(owner: String(components[0]), name: String(components[1])) | ||
extension Deployment: Codable { | ||
public enum CodingKeys: String, CodingKey { | ||
case owner | ||
case name | ||
case currentRelease = "current_release" | ||
} | ||
} | ||
|
||
// MARK: - Codable | ||
extension Deployment.Release: Codable { | ||
public enum CodingKeys: String, CodingKey { | ||
case number | ||
case model | ||
case version | ||
case createdAt = "created_at" | ||
case createdBy = "created_by" | ||
case configuration | ||
} | ||
} | ||
|
||
extension Deployment.ID: Codable { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let value = try container.decode(String.self) | ||
self.init(stringLiteral: value) | ||
extension Deployment.Release.Configuration: Codable { | ||
public enum CodingKeys: String, CodingKey { | ||
case hardware | ||
case scaling | ||
} | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
try container.encode(description) | ||
extension Deployment.Release.Configuration.Scaling: Codable { | ||
public enum CodingKeys: String, CodingKey { | ||
case minInstances = "min_instances" | ||
case maxInstances = "max_instances" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters