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

Amplify/Categories/DataStore/Model/Schema/AuthRule.swift renamed to Amplify/Categories/DataStore/Model/Internal/Schema/AuthRule.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
9+
/// by host applications. The behavior of this may change without warning.
810
public enum AuthStrategy {
911
case owner
1012
case groups
1113
case `private`
1214
case `public`
1315
}
1416

17+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
18+
/// by host applications. The behavior of this may change without warning.
1519
public enum ModelOperation {
1620
case create
1721
case update
1822
case delete
1923
case read
2024
}
2125

26+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
27+
/// by host applications. The behavior of this may change without warning.
2228
public typealias AuthRules = [AuthRule]
2329

30+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
31+
/// by host applications. The behavior of this may change without warning.
2432
public struct AuthRule {
2533
public let allow: AuthStrategy
2634
public let ownerField: String?

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

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

1010
extension 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 static var schema: ModelSchema {
1315
// TODO load schema from JSON when this it not overridden by specific models
1416
ModelSchema(name: modelName, fields: [:])
1517
}
1618

19+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
20+
/// by host applications. The behavior of this may change without warning.
1721
public var schema: ModelSchema {
1822
type(of: self).schema
1923
}
@@ -36,6 +40,8 @@ extension Model {
3640
/// - attributes: model attributes (aka "directives" or "annotations")
3741
/// - define: the closure used to define the model attributes and fields
3842
/// - Returns: a valid `ModelSchema` instance
43+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
44+
/// by host applications. The behavior of this may change without warning.
3945
public static func defineSchema(name: String? = nil,
4046
attributes: ModelAttribute...,
4147
define: (inout ModelSchemaDefinition) -> Void) -> ModelSchema {
@@ -45,6 +51,8 @@ extension Model {
4551
return definition.build()
4652
}
4753

54+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
55+
/// by host applications. The behavior of this may change without warning.
4856
public static func rule(allow: AuthStrategy,
4957
ownerField: String? = nil,
5058
identityClaim: String? = nil,

Amplify/Categories/DataStore/Model/Schema/ModelField+Association.swift renamed to Amplify/Categories/DataStore/Model/Internal/Schema/ModelField+Association.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ import Foundation
8484
/// }
8585
/// ```
8686
///
87+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
88+
/// by host applications. The behavior of this may change without warning.
8789
public enum ModelAssociation {
8890
case hasMany(associatedWith: CodingKey?)
8991
case hasOne(associatedWith: CodingKey?)
@@ -99,13 +101,17 @@ public enum ModelAssociation {
99101

100102
extension ModelField {
101103

104+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
105+
/// by host applications. The behavior of this may change without warning.
102106
public var hasAssociation: Bool {
103107
return association != nil
104108
}
105109

106110
/// If the field represents an association returns the `Model.Type`.
107111
/// - seealso: `ModelFieldType`
108112
/// - seealso: `ModelFieldAssociation`
113+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
114+
/// by host applications. The behavior of this may change without warning.
109115
public var associatedModel: Model.Type? {
110116
switch type {
111117
case .model(let type), .collection(let type):
@@ -122,6 +128,8 @@ extension ModelField {
122128
///
123129
/// - Note: as a maintainer, make sure you use this computed property only when context
124130
/// allows (i.e. the field is a valid relationship, such as foreign keys).
131+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
132+
/// by host applications. The behavior of this may change without warning.
125133
public var requiredAssociatedModel: Model.Type {
126134
guard let modelType = associatedModel else {
127135
preconditionFailure("""
@@ -132,13 +140,17 @@ extension ModelField {
132140
return modelType
133141
}
134142

143+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
144+
/// by host applications. The behavior of this may change without warning.
135145
public var isAssociationOwner: Bool {
136146
guard case .belongsTo = association else {
137147
return false
138148
}
139149
return true
140150
}
141151

152+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
153+
/// by host applications. The behavior of this may change without warning.
142154
public var associatedField: ModelField? {
143155
if hasAssociation {
144156
let associatedModel = requiredAssociatedModel
@@ -159,6 +171,8 @@ extension ModelField {
159171
return nil
160172
}
161173

174+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
175+
/// by host applications. The behavior of this may change without warning.
162176
public var isOneToOne: Bool {
163177
if case .hasOne = association {
164178
return true
@@ -169,20 +183,26 @@ extension ModelField {
169183
return false
170184
}
171185

186+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
187+
/// by host applications. The behavior of this may change without warning.
172188
public var isOneToMany: Bool {
173189
if case .hasMany = association, case .belongsTo = associatedField?.association {
174190
return true
175191
}
176192
return false
177193
}
178194

195+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
196+
/// by host applications. The behavior of this may change without warning.
179197
public var isManyToOne: Bool {
180198
if case .belongsTo = association, case .hasMany = associatedField?.association {
181199
return true
182200
}
183201
return false
184202
}
185203

204+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
205+
/// by host applications. The behavior of this may change without warning.
186206
public var embeddedType: Embeddable.Type? {
187207
switch type {
188208
case .embedded(let type), .embeddedCollection(let type):
@@ -195,6 +215,8 @@ extension ModelField {
195215
}
196216
}
197217

218+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
219+
/// by host applications. The behavior of this may change without warning.
198220
public var isEmbeddedType: Bool {
199221
switch type {
200222
case .embedded, .embeddedCollection:

Amplify/Categories/DataStore/Model/Schema/ModelSchema+Definition.swift renamed to Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift

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

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

1315
case string
@@ -79,6 +81,8 @@ public enum ModelFieldType {
7981
}
8082
}
8183

84+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
85+
/// by host applications. The behavior of this may change without warning.
8286
public enum ModelFieldNullability {
8387
case optional
8488
case required
@@ -93,6 +97,8 @@ public enum ModelFieldNullability {
9397
}
9498
}
9599

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

98104
internal let name: String
@@ -132,6 +138,8 @@ public struct ModelSchemaDefinition {
132138
}
133139
}
134140

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

137145
case field(name: String,

Amplify/Categories/DataStore/Model/Schema/ModelSchema.swift renamed to Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

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

1012
/// Represents a database index, often used for frequent query optimizations.
@@ -14,10 +16,14 @@ public enum ModelAttribute {
1416
case isSystem
1517
}
1618

19+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
20+
/// by host applications. The behavior of this may change without warning.
1721
public enum ModelFieldAttribute {
1822
case primaryKey
1923
}
2024

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

2329
public let name: String
@@ -49,8 +55,12 @@ public struct ModelField {
4955
}
5056
}
5157

58+
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
59+
/// by host applications. The behavior of this may change without warning.
5260
public typealias ModelFields = [String: ModelField]
5361

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

5666
public let name: String

0 commit comments

Comments
 (0)