Skip to content

Commit fb0b1a3

Browse files
authored
chore: kickoff v1 release
2 parents 6ed4fc3 + 27be191 commit fb0b1a3

17 files changed

+184
-96
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ struct PersistableHelper {
6565
return lhs == rhs
6666
case let (lhs, rhs) as (String, String):
6767
return lhs == rhs
68+
case let (lhs, rhs) as (any EnumPersistable, String):
69+
return lhs.rawValue == rhs
70+
case let (lhs, rhs) as (String, any EnumPersistable):
71+
return lhs == rhs.rawValue
72+
case let (lhs, rhs) as (any EnumPersistable, any EnumPersistable):
73+
return lhs.rawValue == rhs.rawValue
6874
default:
6975
return false
7076
}
@@ -95,6 +101,12 @@ struct PersistableHelper {
95101
return lhs == Double(rhs)
96102
case let (lhs, rhs) as (String, String):
97103
return lhs == rhs
104+
case let (lhs, rhs) as (any EnumPersistable, String):
105+
return lhs.rawValue == rhs
106+
case let (lhs, rhs) as (String, any EnumPersistable):
107+
return lhs == rhs.rawValue
108+
case let (lhs, rhs) as (any EnumPersistable, any EnumPersistable):
109+
return lhs.rawValue == rhs.rawValue
98110
default:
99111
return false
100112
}
@@ -123,6 +135,12 @@ struct PersistableHelper {
123135
return lhs <= Double(rhs)
124136
case let (lhs, rhs) as (String, String):
125137
return lhs <= rhs
138+
case let (lhs, rhs) as (any EnumPersistable, String):
139+
return lhs.rawValue <= rhs
140+
case let (lhs, rhs) as (String, any EnumPersistable):
141+
return lhs <= rhs.rawValue
142+
case let (lhs, rhs) as (any EnumPersistable, any EnumPersistable):
143+
return lhs.rawValue <= rhs.rawValue
126144
default:
127145
return false
128146
}
@@ -151,6 +169,12 @@ struct PersistableHelper {
151169
return lhs < Double(rhs)
152170
case let (lhs, rhs) as (String, String):
153171
return lhs < rhs
172+
case let (lhs, rhs) as (any EnumPersistable, String):
173+
return lhs.rawValue < rhs
174+
case let (lhs, rhs) as (String, any EnumPersistable):
175+
return lhs < rhs.rawValue
176+
case let (lhs, rhs) as (any EnumPersistable, any EnumPersistable):
177+
return lhs.rawValue < rhs.rawValue
154178
default:
155179
return false
156180
}
@@ -179,6 +203,12 @@ struct PersistableHelper {
179203
return lhs >= Double(rhs)
180204
case let (lhs, rhs) as (String, String):
181205
return lhs >= rhs
206+
case let (lhs, rhs) as (any EnumPersistable, String):
207+
return lhs.rawValue >= rhs
208+
case let (lhs, rhs) as (String, any EnumPersistable):
209+
return lhs >= rhs.rawValue
210+
case let (lhs, rhs) as (any EnumPersistable, any EnumPersistable):
211+
return lhs.rawValue >= rhs.rawValue
182212
default:
183213
return false
184214
}
@@ -207,6 +237,12 @@ struct PersistableHelper {
207237
return Double(lhs) > rhs
208238
case let (lhs, rhs) as (String, String):
209239
return lhs > rhs
240+
case let (lhs, rhs) as (any EnumPersistable, String):
241+
return lhs.rawValue > rhs
242+
case let (lhs, rhs) as (String, any EnumPersistable):
243+
return lhs > rhs.rawValue
244+
case let (lhs, rhs) as (any EnumPersistable, any EnumPersistable):
245+
return lhs.rawValue > rhs.rawValue
210246
default:
211247
return false
212248
}

Amplify/Categories/DataStore/Query/QueryOperator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public enum QueryOperator {
1919
case beginsWith(_ value: String)
2020

2121
// swiftlint:disable:next cyclomatic_complexity
22-
public func evaluate(target: Any) -> Bool {
22+
public func evaluate(target: Any?) -> Bool {
2323
switch self {
2424
case .notEqual(let predicateValue):
2525
return !PersistableHelper.isEqual(target, predicateValue)
@@ -34,14 +34,14 @@ public enum QueryOperator {
3434
case .greaterThan(let predicateValue):
3535
return PersistableHelper.isGreaterThan(target, predicateValue)
3636
case .contains(let predicateString):
37-
if let targetString = target as? String {
37+
if let targetString = target.flatMap({ $0 as? String }) {
3838
return targetString.contains(predicateString)
3939
}
4040
return false
4141
case .between(let start, let end):
4242
return PersistableHelper.isBetween(start, end, target)
4343
case .beginsWith(let predicateValue):
44-
if let targetString = target as? String {
44+
if let targetString = target.flatMap({ $0 as? String }) {
4545
return targetString.starts(with: predicateValue)
4646
}
4747
}

Amplify/Categories/DataStore/Query/QueryPredicate.swift

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -127,34 +127,6 @@ public class QueryPredicateOperation: QueryPredicate {
127127
}
128128

129129
public func evaluate(target: Model) -> Bool {
130-
guard let fieldValue = target[field] else {
131-
return false
132-
}
133-
134-
guard let value = fieldValue else {
135-
return false
136-
}
137-
138-
if let booleanValue = value as? Bool {
139-
return self.operator.evaluate(target: booleanValue)
140-
}
141-
142-
if let doubleValue = value as? Double {
143-
return self.operator.evaluate(target: doubleValue)
144-
}
145-
146-
if let intValue = value as? Int {
147-
return self.operator.evaluate(target: intValue)
148-
}
149-
150-
if let timeValue = value as? Temporal.Time {
151-
return self.operator.evaluate(target: timeValue)
152-
}
153-
154-
if let enumValue = value as? EnumPersistable {
155-
return self.operator.evaluate(target: enumValue.rawValue)
156-
}
157-
158-
return self.operator.evaluate(target: value)
130+
return self.operator.evaluate(target: target[field]?.flatMap { $0 })
159131
}
160132
}

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthenticationProviderTests/AuthenticationProviderConfirmSignupTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AuthenticationProviderConfirmSignupTests: BaseAuthenticationProviderTest {
2626
///
2727
func testSuccessfulConfirmSignUp() {
2828

29-
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil)
29+
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil, userSub: nil)
3030
mockAWSMobileClient?.confirmSignUpMockResult = .success(mockSignupResult)
3131

3232
let resultExpectation = expectation(description: "Should receive a result")
@@ -60,7 +60,7 @@ class AuthenticationProviderConfirmSignupTests: BaseAuthenticationProviderTest {
6060
///
6161
func testConfirmSignUpWithEmptyUserName() {
6262

63-
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil)
63+
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil, userSub: nil)
6464
mockAWSMobileClient?.confirmSignUpMockResult = .success(mockSignupResult)
6565

6666
let resultExpectation = expectation(description: "Should receive a result")

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthenticationProviderTests/AuthenticationProviderResendSignupCodeTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AuthenticationProviderResendSignupCodeTests: BaseAuthenticationProviderTes
3131
destination: nil,
3232
attributeName: nil)
3333
let mockResendSignUpCodeResult = SignUpResult(signUpState: .confirmed,
34-
codeDeliveryDetails: codeDelieveryDetails)
34+
codeDeliveryDetails: codeDelieveryDetails, userSub: nil)
3535
mockAWSMobileClient?.resendSignUpCodeMockResult = .success(mockResendSignUpCodeResult)
3636
let resultExpectation = expectation(description: "Should receive a result")
3737
_ = plugin.resendSignUpCode(for: "username") { result in
@@ -66,7 +66,8 @@ class AuthenticationProviderResendSignupCodeTests: BaseAuthenticationProviderTes
6666
destination: nil,
6767
attributeName: nil)
6868
let mockResendSignUpCodeResult = SignUpResult(signUpState: .confirmed,
69-
codeDeliveryDetails: codeDelieveryDetails)
69+
codeDeliveryDetails: codeDelieveryDetails,
70+
userSub: nil)
7071
mockAWSMobileClient?.resendSignUpCodeMockResult = .success(mockResendSignUpCodeResult)
7172
let resultExpectation = expectation(description: "Should receive a result")
7273
_ = plugin.resendSignUpCode(for: "") { result in

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthenticationProviderTests/AuthenticationProviderSignupTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AuthenticationProviderSignupTests: BaseAuthenticationProviderTest {
2626
///
2727
func testSignupWithSuccess() {
2828

29-
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil)
29+
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil, userSub: nil)
3030
mockAWSMobileClient?.signupMockResult = .success(mockSignupResult)
3131

3232
let emailAttribute = AuthUserAttribute(.email, value: "email")
@@ -61,7 +61,7 @@ class AuthenticationProviderSignupTests: BaseAuthenticationProviderTest {
6161
///
6262
func testSignupWithEmptyUserName() {
6363

64-
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil)
64+
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil, userSub: nil)
6565
mockAWSMobileClient?.signupMockResult = .success(mockSignupResult)
6666

6767
let emailAttribute = AuthUserAttribute(.email, value: "email")
@@ -96,7 +96,7 @@ class AuthenticationProviderSignupTests: BaseAuthenticationProviderTest {
9696
///
9797
func testSignupWithEmptyPassword() {
9898

99-
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil)
99+
let mockSignupResult = SignUpResult(signUpState: .confirmed, codeDeliveryDetails: nil, userSub: nil)
100100
mockAWSMobileClient?.signupMockResult = .success(mockSignupResult)
101101

102102
let emailAttribute = AuthUserAttribute(.email, value: "email")
@@ -138,7 +138,11 @@ class AuthenticationProviderSignupTests: BaseAuthenticationProviderTest {
138138
let mockCodeDelivery = UserCodeDeliveryDetails(deliveryMedium: .email,
139139
destination: mockEmail,
140140
attributeName: "email")
141-
let mockSignupResult = SignUpResult(signUpState: .unconfirmed, codeDeliveryDetails: mockCodeDelivery)
141+
let mockSignupResult = SignUpResult(
142+
signUpState: .unconfirmed,
143+
codeDeliveryDetails: mockCodeDelivery,
144+
userSub: nil
145+
)
142146
mockAWSMobileClient?.signupMockResult = .success(mockSignupResult)
143147

144148
let resultExpectation = expectation(description: "Should receive a result")

AmplifyPlugins/Auth/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ SPEC CHECKSUMS:
9999

100100
PODFILE CHECKSUM: 371cf67fe35ebb5167d0880bad12b01618a0fb0e
101101

102-
COCOAPODS: 1.11.3
102+
COCOAPODS: 1.14.3

AmplifyPlugins/Core/AWSPluginsCoreTests/Query/QueryPredicateEvaluateGeneratedBoolTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class QueryPredicateEvaluateGeneratedBoolTests: XCTestCase {
4141

4242
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
4343

44-
XCTAssertFalse(evaluation)
44+
XCTAssertTrue(evaluation)
4545
}
4646

4747
func testBoolfalsenotEqualBooltrue() throws {
@@ -70,7 +70,7 @@ class QueryPredicateEvaluateGeneratedBoolTests: XCTestCase {
7070

7171
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
7272

73-
XCTAssertFalse(evaluation)
73+
XCTAssertTrue(evaluation)
7474
}
7575

7676
func testBooltrueequalsBooltrue() throws {

AmplifyPlugins/Core/AWSPluginsCoreTests/Query/QueryPredicateEvaluateGeneratedDateTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class QueryPredicateEvaluateGeneratedDateTests: XCTestCase {
6060

6161
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
6262

63-
XCTAssertFalse(evaluation)
63+
XCTAssertTrue(evaluation)
6464
}
6565

6666
func testTemporalDateTemporal_Date_now_addvalue1to_daynotEqualTemporalDateTemporal_Date_now() throws {
@@ -109,7 +109,7 @@ class QueryPredicateEvaluateGeneratedDateTests: XCTestCase {
109109

110110
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
111111

112-
XCTAssertFalse(evaluation)
112+
XCTAssertTrue(evaluation)
113113
}
114114

115115
func testTemporalDateTemporal_Date_now_addvalue2to_daynotEqualTemporalDateTemporal_Date_now() throws {
@@ -158,7 +158,7 @@ class QueryPredicateEvaluateGeneratedDateTests: XCTestCase {
158158

159159
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
160160

161-
XCTAssertFalse(evaluation)
161+
XCTAssertTrue(evaluation)
162162
}
163163

164164
func testTemporalDateTemporal_Date_now_addvalue3to_daynotEqualTemporalDateTemporal_Date_now() throws {
@@ -207,7 +207,7 @@ class QueryPredicateEvaluateGeneratedDateTests: XCTestCase {
207207

208208
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
209209

210-
XCTAssertFalse(evaluation)
210+
XCTAssertTrue(evaluation)
211211
}
212212

213213
func testTemporalDateTemporal_Date_nowequalsTemporalDateTemporal_Date_now() throws {

AmplifyPlugins/Core/AWSPluginsCoreTests/Query/QueryPredicateEvaluateGeneratedDateTimeTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class QueryPredicateEvaluateGeneratedDateTimeTests: XCTestCase {
6666

6767
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
6868

69-
XCTAssertFalse(evaluation)
69+
XCTAssertTrue(evaluation)
7070
}
7171

7272
func testTemporalDateTimeTemporal_DateTime_now_addvalue1to_hournotEqualTemporalDateTimeTemporal_DateTime_now() throws {
@@ -120,7 +120,7 @@ class QueryPredicateEvaluateGeneratedDateTimeTests: XCTestCase {
120120

121121
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
122122

123-
XCTAssertFalse(evaluation)
123+
XCTAssertTrue(evaluation)
124124
}
125125

126126
func testTemporalDateTimeTemporal_DateTime_now_addvalue2to_hournotEqualTemporalDateTimeTemporal_DateTime_now() throws {
@@ -174,7 +174,7 @@ class QueryPredicateEvaluateGeneratedDateTimeTests: XCTestCase {
174174

175175
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
176176

177-
XCTAssertFalse(evaluation)
177+
XCTAssertTrue(evaluation)
178178
}
179179

180180
func testTemporalDateTimeTemporal_DateTime_now_addvalue3to_hournotEqualTemporalDateTimeTemporal_DateTime_now() throws {
@@ -228,7 +228,7 @@ class QueryPredicateEvaluateGeneratedDateTimeTests: XCTestCase {
228228

229229
let evaluation = try predicate.evaluate(target: instance.eraseToAnyModel().instance)
230230

231-
XCTAssertFalse(evaluation)
231+
XCTAssertTrue(evaluation)
232232
}
233233

234234
func testTemporalDateTimeTemporal_DateTime_nowequalsTemporalDateTimeTemporal_DateTime_now() throws {

0 commit comments

Comments
 (0)