Skip to content

Commit 468e885

Browse files
authored
Refactor: Move DataStore Model schema to Internal directory (#563)
* Move Model schema related to Internal directory structure * Move AnyModel to AWSPluginsCore * PR comment and move AnyModel unit tests * comment update * adding warning comment to all public symbols in Internal directory * remove old comment * move Model and ModelName out of Internal
1 parent 27342fe commit 468e885

29 files changed

+159
-34
lines changed

Amplify.xcodeproj/project.pbxproj

Lines changed: 45 additions & 29 deletions
Large diffs are not rendered by default.

Amplify/Categories/DataStore/Model/Embedded.swift renamed to Amplify/Categories/DataStore/Model/Internal/Embedded.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import Foundation
1313
/// `embedded(type:)` or `embeddedCollection(of:)` must comform to the `Embeddable` protocol except for Swift's Basic
1414
/// types embedded as a collection. A collection of String can be embedded in the `Model` as
1515
/// `embeddedCollection(of: String.self)` without needing to conform to Embeddable.
16+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
17+
/// by host applications. The behavior of this may change without warning.
1618
public protocol Embeddable: Codable {
1719

1820
/// A reference to the `ModelSchema` associated with this embedded type.

Amplify/Categories/DataStore/Model/Model+Array.swift renamed to Amplify/Categories/DataStore/Model/Internal/Model+Array.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Foundation
99

1010
extension Array where Element: Model {
1111

12+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
13+
/// by host applications. The behavior of this may change without warning.
1214
public func unique() throws -> Element? {
1315
guard (0 ... 1).contains(count) else {
1416
throw DataStoreError.nonUniqueResult(model: Element.modelName, count: count)
@@ -18,6 +20,9 @@ extension Array where Element: Model {
1820
}
1921

2022
extension Array where Element == Model {
23+
24+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
25+
/// by host applications. The behavior of this may change without warning.
2126
public func unique() throws -> Element? {
2227
guard (0 ... 1).contains(count) else {
2328
let firstModelName = self[0].modelName

Amplify/Categories/DataStore/Model/Model+Codable.swift renamed to Amplify/Categories/DataStore/Model/Internal/Model+Codable.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ extension Model where Self: Codable {
2020
/// - Returns: an instance of the concrete type conforming to `Model`
2121
/// - Throws: `DecodingError.dataCorrupted` in case data is not a valid JSON or any
2222
/// other decoding specific error that `JSONDecoder.decode()` might throw.
23+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
24+
/// by host applications. The behavior of this may change without warning.
2325
public static func from(json: String,
2426
decoder: JSONDecoder? = nil) throws -> Self {
2527
let resolvedDecoder: JSONDecoder
@@ -46,6 +48,8 @@ extension Model where Self: Codable {
4648
/// - Returns: an instance of the concrete type conforming to `Model`
4749
/// - Throws: `DecodingError.dataCorrupted` in case data is not a valid JSON or any
4850
/// other decoding specific error that `JSONDecoder.decode()` might throw.
51+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
52+
/// by host applications. The behavior of this may change without warning.
4953
public static func from(dictionary: [String: Any]) throws -> Self {
5054
let data = try JSONSerialization.data(withJSONObject: dictionary)
5155
let decoder = JSONDecoder(dateDecodingStrategy: ModelDateFormatting.decodingStrategy)
@@ -58,6 +62,8 @@ extension Model where Self: Codable {
5862
/// custom date formatter that encodes ISO8601 dates with fractional seconds
5963
/// - Returns: the JSON representation of the `Model`
6064
/// - seealso: https://developer.apple.com/documentation/foundation/jsonencoder/2895034-encode
65+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
66+
/// by host applications. The behavior of this may change without warning.
6167
public func toJSON(encoder: JSONEncoder? = nil) throws -> String {
6268
let resolvedEncoder: JSONEncoder
6369
if let encoder = encoder {

Amplify/Categories/DataStore/Model/Model+DateFormatting.swift renamed to Amplify/Categories/DataStore/Model/Internal/Model+DateFormatting.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import Foundation
99

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

1214
public static let decodingStrategy: JSONDecoder.DateDecodingStrategy = {
@@ -31,13 +33,19 @@ public struct ModelDateFormatting {
3133
}
3234

3335
public extension JSONDecoder {
36+
37+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
38+
/// by host applications. The behavior of this may change without warning.
3439
convenience init(dateDecodingStrategy: JSONDecoder.DateDecodingStrategy) {
3540
self.init()
3641
self.dateDecodingStrategy = dateDecodingStrategy
3742
}
3843
}
3944

4045
public extension JSONEncoder {
46+
47+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
48+
/// by host applications. The behavior of this may change without warning.
4149
convenience init(dateEncodingStrategy: JSONEncoder.DateEncodingStrategy) {
4250
self.init()
4351
self.dateEncodingStrategy = dateEncodingStrategy

Amplify/Categories/DataStore/Model/Model+Enum.swift renamed to Amplify/Categories/DataStore/Model/Internal/Model+Enum.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import Foundation
1010
/// Protocol that represents a `Codable` Enum that can be persisted and easily
1111
/// integrate with remote APIs since it must have a raw `String` value.
1212
///
13-
/// That means only simple enums (i.e. the ones that don't have arguments) can be used
14-
/// as model properties.
13+
/// That means only enums without associated values can be used as model properties.
1514
///
1615
/// - Example:
1716
///
@@ -21,6 +20,8 @@ import Foundation
2120
/// case published
2221
/// }
2322
/// ```
23+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
24+
/// by host applications. The behavior of this may change without warning.
2425
public protocol EnumPersistable: Codable {
2526

2627
var rawValue: String { get }

Amplify/Categories/DataStore/Model/Model+Subscript.swift renamed to Amplify/Categories/DataStore/Model/Internal/Model+Subscript.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
/// let id = model["id"]
1212
/// ```
1313
extension Model {
14+
15+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
16+
/// by host applications. The behavior of this may change without warning.
1417
public subscript(_ key: String) -> Any?? {
1518
let mirror = Mirror(reflecting: self)
1619
let firstChild = mirror.children.first { $0.label == key }

Amplify/Categories/DataStore/Model/ModelRegistry+Syncable.swift renamed to Amplify/Categories/DataStore/Model/Internal/ModelRegistry+Syncable.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77

88
public extension ModelRegistry {
9+
10+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
11+
/// by host applications. The behavior of this may change without warning.
912
static var hasSyncableModels: Bool {
1013
if #available(iOS 13.0, *) {
1114
return models.contains { !$0.schema.isSystem }

Amplify/Categories/DataStore/Model/ModelRegistry.swift renamed to Amplify/Categories/DataStore/Model/Internal/ModelRegistry.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import Foundation
99

10+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
11+
/// by host applications. The behavior of this may change without warning.
1012
public struct ModelRegistry {
1113
private static let concurrencyQueue = DispatchQueue(label: "com.amazonaws.ModelRegistry.concurrency",
1214
target: DispatchQueue.global())

Amplify/Categories/DataStore/Model/Persistable.swift renamed to Amplify/Categories/DataStore/Model/Internal/Persistable.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import Foundation
1818
/// - `Temporal.Date`
1919
/// - `Temporal.DateTime`
2020
/// - `Temporal.Time`
21+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
22+
/// by host applications. The behavior of this may change without warning.
2123
public protocol Persistable {}
2224

2325
extension Bool: Persistable {}
@@ -40,6 +42,8 @@ struct PersistableHelper {
4042
/// - lhs: a reference to a Persistable object
4143
/// - rhs: another reference
4244
/// - Returns: `true` in case both values are equal or `false` otherwise
45+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
46+
/// by host applications. The behavior of this may change without warning.
4347
public static func isEqual(_ lhs: Persistable?, _ rhs: Persistable?) -> Bool {
4448
if lhs == nil && rhs == nil {
4549
return true

0 commit comments

Comments
 (0)