Skip to content

Commit

Permalink
PR comment and move AnyModel unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha committed Jun 18, 2020
1 parent 4280acd commit 3223fed
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 26 deletions.
20 changes: 14 additions & 6 deletions Amplify.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
212CE70F23E9E991007D8E71 /* ModelDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 212CE70A23E9E991007D8E71 /* ModelDecorator.swift */; };
212CE71123E9EA6A007D8E71 /* ModelField+GraphQL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 212CE71023E9EA6A007D8E71 /* ModelField+GraphQL.swift */; };
212CE71323E9F2ED007D8E71 /* DirectiveNameDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 212CE71223E9F2ED007D8E71 /* DirectiveNameDecorator.swift */; };
213481D9242AFA62001966DE /* AnyModelTester.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213481D8242AFA62001966DE /* AnyModelTester.swift */; };
21409C552384C55D000A53C9 /* LabelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21409C542384C55D000A53C9 /* LabelType.swift */; };
21409C5A2384C57D000A53C9 /* GraphQLMutationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21409C572384C57D000A53C9 /* GraphQLMutationType.swift */; };
21409C5B2384C57D000A53C9 /* GraphQLQueryType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21409C582384C57D000A53C9 /* GraphQLQueryType.swift */; };
Expand Down Expand Up @@ -116,6 +115,8 @@
21AD424D249BF0E50016FE95 /* AnyModel+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE78223862DDB0097E4F1 /* AnyModel+Schema.swift */; };
21AD424E249BF0E90016FE95 /* AnyModel+Subscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE77E2386274A0097E4F1 /* AnyModel+Subscript.swift */; };
21AD424F249BF0EC0016FE95 /* Model+AnyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE77A2386271A0097E4F1 /* Model+AnyModel.swift */; };
21AD425A249C0D910016FE95 /* AnyModelTester.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213481D8242AFA62001966DE /* AnyModelTester.swift */; };
21AD425B249C0DBE0016FE95 /* AnyModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE772238621320097E4F1 /* AnyModelTests.swift */; };
21C395B3245729EC00597EA2 /* AppSyncErrorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */; };
21D79FDA237617C60057D00D /* SubscriptionEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FD9237617C60057D00D /* SubscriptionEvent.swift */; };
21D79FE32377F4120057D00D /* SubscriptionConnectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FE22377F4120057D00D /* SubscriptionConnectionState.swift */; };
Expand Down Expand Up @@ -412,7 +413,6 @@
FA6BC87F235F5DAE0001A882 /* APICategoryInterceptorBehavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6BC87E235F5DAE0001A882 /* APICategoryInterceptorBehavior.swift */; };
FA76A2D12342B1A600B91ADB /* StorageCategory+HubPayloadEventName.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA76A2D02342B1A600B91ADB /* StorageCategory+HubPayloadEventName.swift */; };
FA76A2D32342B47100B91ADB /* HubPayloadEventName.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA76A2D22342B47100B91ADB /* HubPayloadEventName.swift */; };
FA8EE773238621320097E4F1 /* AnyModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE772238621320097E4F1 /* AnyModelTests.swift */; };
FA8EE779238627040097E4F1 /* Model+ModelName.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE778238627040097E4F1 /* Model+ModelName.swift */; };
FA8EE77D238627350097E4F1 /* Model+Subscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE77C238627350097E4F1 /* Model+Subscript.swift */; };
FA8EE781238628490097E4F1 /* Persistable.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE780238628490097E4F1 /* Persistable.swift */; };
Expand Down Expand Up @@ -1495,6 +1495,7 @@
2129BE2223948085006363A1 /* Model */ = {
isa = PBXGroup;
children = (
21AD4259249C0D7C0016FE95 /* AnyModel */,
21A3FDAD24630D4200E76120 /* Decorator */,
2129BE262394828A006363A1 /* GraphQLDocument */,
2129BE302394828B006363A1 /* GraphQLRequest */,
Expand Down Expand Up @@ -1592,7 +1593,6 @@
213481D7242AFA58001966DE /* Support */ = {
isa = PBXGroup;
children = (
213481D8242AFA62001966DE /* AnyModelTester.swift */,
);
path = Support;
sourceTree = "<group>";
Expand Down Expand Up @@ -1690,6 +1690,15 @@
path = Internal;
sourceTree = "<group>";
};
21AD4259249C0D7C0016FE95 /* AnyModel */ = {
isa = PBXGroup;
children = (
FA8EE772238621320097E4F1 /* AnyModelTests.swift */,
213481D8242AFA62001966DE /* AnyModelTester.swift */,
);
path = AnyModel;
sourceTree = "<group>";
};
21C395B4245729F100597EA2 /* API */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3072,7 +3081,6 @@
FAD3937B23820CE200463F5E /* DataStore */ = {
isa = PBXGroup;
children = (
FA8EE772238621320097E4F1 /* AnyModelTests.swift */,
FAD3937923820CDB00463F5E /* DataStoreCategoryClientAPITests.swift */,
FAD3937C23820D0200463F5E /* DataStoreCategoryConfigurationTests.swift */,
FAE414602399A6A500CE94C2 /* ModelRegistryTests.swift */,
Expand Down Expand Up @@ -4032,8 +4040,10 @@
219A888723EB89C200BBC5F2 /* GraphQLRequestAnyModelWithSyncTests.swift in Sources */,
2183A56423EA4A7F00232880 /* GraphQLGetQueryTests.swift in Sources */,
6BBECD7423ADA9D100C8DFBE /* AmplifyAWSServiceConfigurationTests.swift in Sources */,
21AD425A249C0D910016FE95 /* AnyModelTester.swift in Sources */,
2129BE3C2394828B006363A1 /* GraphQLRequestModelTests.swift in Sources */,
2183A56523EA4A8400232880 /* GraphQLListQueryTests.swift in Sources */,
21AD425B249C0DBE0016FE95 /* AnyModelTests.swift in Sources */,
D83C5160248964780091548E /* ModelGraphQLTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -4405,7 +4415,6 @@
FACF520923298C1200646E10 /* AtomicDictionaryTests.swift in Sources */,
FA4B38AB238482B100E20DAB /* DefaultLoggingPluginTests.swift in Sources */,
FA6BC869235F52740001A882 /* APICategoryClientGraphQLTests.swift in Sources */,
FA8EE773238621320097E4F1 /* AnyModelTests.swift in Sources */,
FACD264C2386E8F10068FBE6 /* JSONValue+SubscriptTests.swift in Sources */,
FACD264D2386E8F10068FBE6 /* JSONValue+KeyPathTests.swift in Sources */,
FA9FB782232AA26500C04D32 /* DefaultHubPluginCustomChannelTests.swift in Sources */,
Expand All @@ -4432,7 +4441,6 @@
B4F3E9F824314E2B00F23296 /* AuthCategoryConfigurationTests.swift in Sources */,
FAC2356E227A056600424678 /* AnalyticsCategoryClientAPITests.swift in Sources */,
B4BD6B3323708C0000A1F0A7 /* PredictionsCategoryClientAPITests.swift in Sources */,
213481D9242AFA62001966DE /* AnyModelTester.swift in Sources */,
FA47B8382350C58B0031A0E3 /* AutoUnsubscribeHubListenToOperationTests.swift in Sources */,
FAC23574227A056B00424678 /* ConfigurationTests.swift in Sources */,
B9DCA263240F217C00075E22 /* AnyEncodableTests.swift in Sources */,
Expand Down
5 changes: 3 additions & 2 deletions Amplify/Categories/DataStore/Model/Internal/Embedded.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import Foundation

// MARK: - Embeddable

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// A `Embeddable` type can be used in a `Model` as an embedded type. All types embedded in a `Model` as an
/// `embedded(type:)` or `embeddedCollection(of:)` must comform to the `Embeddable` protocol except for Swift's Basic
/// types embedded as a collection. A collection of String can be embedded in the `Model` as
/// `embeddedCollection(of: String.self)` without needing to conform to Embeddable.
/// `embeddedCollection(of: String.self)` without needing to conform to Embeddable.
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public protocol Embeddable: Codable {

/// A reference to the `ModelSchema` associated with this embedded type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
extension Array where Element: Model {

public func unique() throws -> Element? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// Adds JSON serialization behavior to all types that conform to the `Model` protocol.
extension Model where Self: Codable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import Foundation

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public struct ModelDateFormatting {

public static let decodingStrategy: JSONDecoder.DateDecodingStrategy = {
Expand Down
3 changes: 2 additions & 1 deletion Amplify/Categories/DataStore/Model/Internal/Model+Enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// Protocol that represents a `Codable` Enum that can be persisted and easily
/// integrate with remote APIs since it must have a raw `String` value.
///
Expand All @@ -22,6 +21,8 @@ import Foundation
/// case published
/// }
/// ```
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public protocol EnumPersistable: Codable {

var rawValue: String { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: Apache-2.0
//

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
extension Model {
public static var modelName: String {
return String(describing: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: Apache-2.0
//

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// Implement dynamic access to properties of a `Model`.
///
/// ```swift
Expand Down
3 changes: 2 additions & 1 deletion Amplify/Categories/DataStore/Model/Internal/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import Foundation

// MARK: - Model

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// All persistent models should conform to the Model protocol.
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public protocol Model: Codable {

/// Alias of Model identifier (i.e. primary key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: Apache-2.0
//

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
public extension ModelRegistry {
static var hasSyncableModels: Bool {
if #available(iOS 13.0, *) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import Foundation

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public struct ModelRegistry {
private static let concurrencyQueue = DispatchQueue(label: "com.amazonaws.ModelRegistry.concurrency",
target: DispatchQueue.global())
Expand Down
2 changes: 2 additions & 0 deletions Amplify/Categories/DataStore/Model/Internal/Persistable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import Foundation
/// - `Temporal.Date`
/// - `Temporal.DateTime`
/// - `Temporal.Time`
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public protocol Persistable {}

extension Bool: Persistable {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum ModelOperation {

public typealias AuthRules = [AuthRule]

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public struct AuthRule {
public let allow: AuthStrategy
public let ownerField: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
extension Model {

public static var schema: ModelSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// Defines the association type between two models. The type of association is
/// important when defining how to store and query them. Each association have
/// its own rules depending on the storage mechanism.
Expand Down Expand Up @@ -85,6 +84,8 @@ import Foundation
/// }
/// ```
///
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public enum ModelAssociation {
case hasMany(associatedWith: CodingKey?)
case hasOne(associatedWith: CodingKey?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: Apache-2.0
//

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// Convenience getters for attributes
public extension ModelSchema {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import Foundation

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// Defines the type of a `Model` field.
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public enum ModelFieldType {

case string
Expand Down Expand Up @@ -72,6 +73,8 @@ public enum ModelFieldType {
}
}

/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public enum ModelFieldNullability {
case optional
case required
Expand All @@ -86,6 +89,8 @@ public enum ModelFieldNullability {
}
}

/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public struct ModelSchemaDefinition {

internal let name: String
Expand Down Expand Up @@ -125,6 +130,8 @@ public struct ModelSchemaDefinition {
}
}

/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public enum ModelFieldDefinition {

case field(name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public enum ModelFieldAttribute {
case primaryKey
}

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public struct ModelField {

public let name: String
Expand Down Expand Up @@ -52,7 +53,8 @@ public struct ModelField {

public typealias ModelFields = [String: ModelField]

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public struct ModelSchema {

public let name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Foundation

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
/// Establishes how `Model` fields should be converted to and from different targets (e.g. SQL and GraphQL).
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
/// by host applications. The behavior of this may change without warning.
public protocol ModelValueConverter {

/// The base type on the source (i.e. the `Model` property type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Amplify

/// Note that although this is public, it is intended for internal use and not consumed directly by host applications.
public extension Model {
func eraseToAnyModel() throws -> AnyModel {
AnyModel(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Amplify
import AWSPluginsCore
import Foundation

struct AnyModelTester: Model {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Amplify
import AWSPluginsCore
import XCTest

class AnyModelTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct StatementResult<M: Model>: Decodable {

let elements: [M]

public static func from(dictionary: ModelValues) throws -> Self {
static func from(dictionary: ModelValues) throws -> Self {
let data = try JSONSerialization.data(withJSONObject: dictionary)
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = ModelDateFormatting.decodingStrategy
Expand Down

0 comments on commit 3223fed

Please sign in to comment.