@@ -17,4 +17,33 @@
Loading
17 17
    case contains(_ value: String)
18 18
    case between(start: Persistable, end: Persistable)
19 19
    case beginsWith(_ value: String)
20 +
21 +
    public func evaluate(target: Any) -> Bool {
22 +
        switch self {
23 +
        case .notEqual(let predicateValue):
24 +
            return !PersistableHelper.isEqual(target, predicateValue)
25 +
        case .equals(let predicateValue):
26 +
            return PersistableHelper.isEqual(target, predicateValue)
27 +
        case .lessOrEqual(let predicateValue):
28 +
            return PersistableHelper.isLessOrEqual(target, predicateValue)
29 +
        case .lessThan(let predicateValue):
30 +
            return PersistableHelper.isLessThan(target, predicateValue)
31 +
        case .greaterOrEqual(let predicateValue):
32 +
            return PersistableHelper.isGreaterOrEqual(target, predicateValue)
33 +
        case .greaterThan(let predicateValue):
34 +
            return PersistableHelper.isGreaterThan(target, predicateValue)
35 +
        case .contains(let predicateString):
36 +
            if let targetString = target as? String {
37 +
                return targetString.contains(predicateString)
38 +
            }
39 +
            return false
40 +
        case .between(let start, let end):
41 +
            return PersistableHelper.isBetween(start, end, target)
42 +
        case .beginsWith(let predicateValue):
43 +
            if let targetString = target as? String {
44 +
                return targetString.starts(with: predicateValue)
45 +
            }
46 +
        }
47 +
        return false
48 +
    }
20 49
}

@@ -0,0 +1,46 @@
Loading
1 +
//
2 +
// Copyright 2018-2020 Amazon.com,
3 +
// Inc. or its affiliates. All Rights Reserved.
4 +
//
5 +
// SPDX-License-Identifier: Apache-2.0
6 +
//
7 +
8 +
// swiftlint:disable all
9 +
import Amplify
10 +
import Foundation
11 +
12 +
extension QPredGen {
13 +
  // MARK: - CodingKeys
14 +
   public enum CodingKeys: String, ModelKey {
15 +
    case id
16 +
    case name
17 +
    case myBool
18 +
    case myDouble
19 +
    case myInt
20 +
    case myString
21 +
    case myDate
22 +
    case myDateTime
23 +
    case myTime
24 +
  }
25 +
26 +
  public static let keys = CodingKeys.self
27 +
  //  MARK: - ModelSchema
28 +
29 +
  public static let schema = defineSchema { model in
30 +
    let qPredGen = QPredGen.keys
31 +
32 +
    model.pluralName = "QPredGens"
33 +
34 +
    model.fields(
35 +
      .id(),
36 +
      .field(qPredGen.name, is: .required, ofType: .string),
37 +
      .field(qPredGen.myBool, is: .optional, ofType: .bool),
38 +
      .field(qPredGen.myDouble, is: .optional, ofType: .double),
39 +
      .field(qPredGen.myInt, is: .optional, ofType: .int),
40 +
      .field(qPredGen.myString, is: .optional, ofType: .string),
41 +
      .field(qPredGen.myDate, is: .optional, ofType: .date),
42 +
      .field(qPredGen.myDateTime, is: .optional, ofType: .dateTime),
43 +
      .field(qPredGen.myTime, is: .optional, ofType: .time)
44 +
    )
45 +
    }
46 +
}

@@ -0,0 +1,56 @@
Loading
1 +
//
2 +
// Copyright 2018-2020 Amazon.com,
3 +
// Inc. or its affiliates. All Rights Reserved.
4 +
//
5 +
// SPDX-License-Identifier: Apache-2.0
6 +
//
7 +
8 +
// swiftlint:disable all
9 +
import Amplify
10 +
import Foundation
11 +
/*
12 +
 Generated from:
13 +
14 +
 type QPredGen @model {
15 +
   id: ID!
16 +
   name: String!
17 +
   myBool: Boolean
18 +
   myDouble: Float
19 +
   myInt: Int
20 +
   myString: String
21 +
   myDate: AWSDate
22 +
   myDateTime: AWSDateTime
23 +
   myTime: AWSTime
24 +
 }
25 +
 */
26 +
public struct QPredGen: Model {
27 +
  public let id: String
28 +
  public var name: String
29 +
  public var myBool: Bool?
30 +
  public var myDouble: Double?
31 +
  public var myInt: Int?
32 +
  public var myString: String?
33 +
  public var myDate: Temporal.Date?
34 +
  public var myDateTime: Temporal.DateTime?
35 +
  public var myTime: Temporal.Time?
36 +
37 +
  public init(id: String = UUID().uuidString,
38 +
      name: String,
39 +
      myBool: Bool? = nil,
40 +
      myDouble: Double? = nil,
41 +
      myInt: Int? = nil,
42 +
      myString: String? = nil,
43 +
      myDate: Temporal.Date? = nil,
44 +
      myDateTime: Temporal.DateTime? = nil,
45 +
      myTime: Temporal.Time? = nil) {
46 +
      self.id = id
47 +
      self.name = name
48 +
      self.myBool = myBool
49 +
      self.myDouble = myDouble
50 +
      self.myInt = myInt
51 +
      self.myString = myString
52 +
      self.myDate = myDate
53 +
      self.myDateTime = myDateTime
54 +
      self.myTime = myTime
55 +
  }
56 +
}

@@ -8,7 +8,7 @@
Loading
8 8
import Foundation
9 9
10 10
/// Protocol that indicates concrete types conforming to it can be used a predicate member.
11 -
public protocol QueryPredicate {}
11 +
public protocol QueryPredicate: Evaluable {}
12 12
13 13
public enum QueryPredicateGroupType: String {
14 14
    case and
@@ -28,6 +28,9 @@
Loading
28 28
/// specify an action applies to an entire data set.
29 29
public enum QueryPredicateConstant: QueryPredicate {
30 30
    case all
31 +
    public func evaluate(target: Model) -> Bool {
32 +
        return true
33 +
    }
31 34
}
32 35
33 36
public class QueryPredicateGroup: QueryPredicate {
@@ -67,6 +70,28 @@
Loading
67 70
    public static prefix func ! (rhs: QueryPredicateGroup) -> QueryPredicateGroup {
68 71
        return not(rhs)
69 72
    }
73 +
74 +
    public func evaluate(target: Model) -> Bool {
75 +
        switch type {
76 +
        case .or:
77 +
            for predicate in predicates {
78 +
                if predicate.evaluate(target: target) {
79 +
                    return true
80 +
                }
81 +
            }
82 +
            return false
83 +
        case .and:
84 +
            for predicate in predicates {
85 +
                if !predicate.evaluate(target: target) {
86 +
                    return false
87 +
                }
88 +
            }
89 +
            return true
90 +
        case .not:
91 +
            let predicate = predicates[0]
92 +
            return !predicate.evaluate(target: target)
93 +
        }
94 +
    }
70 95
}
71 96
72 97
public class QueryPredicateOperation: QueryPredicate {
@@ -100,4 +125,30 @@
Loading
100 125
    public static prefix func ! (rhs: QueryPredicateOperation) -> QueryPredicateGroup {
101 126
        return not(rhs)
102 127
    }
128 +
129 +
    public func evaluate(target: Model) -> Bool {
130 +
        guard let fieldValue = target[field] else {
131 +
            return false
132 +
        }
133 +
        guard let value = fieldValue else {
134 +
            return false
135 +
        }
136 +
137 +
        if let booleanValue = value as? Bool {
138 +
            return self.operator.evaluate(target: booleanValue)
139 +
        }
140 +
141 +
        if let doubleValue = value as? Double {
142 +
            return self.operator.evaluate(target: doubleValue)
143 +
        }
144 +
145 +
        if let intValue = value as? Int {
146 +
            return self.operator.evaluate(target: intValue)
147 +
        }
148 +
        if let timeValue = value as? Temporal.Time {
149 +
            return self.operator.evaluate(target: timeValue)
150 +
        }
151 +
152 +
        return self.operator.evaluate(target: value)
153 +
    }
103 154
}

@@ -67,4 +67,152 @@
Loading
67 67
            return false
68 68
        }
69 69
    }
70 +
71 +
    //We are promoting Int to Double in the case where we are comparing these two types
72 +
    public static func isEqual(_ lhs: Any?, _ rhs: Persistable?) -> Bool {
73 +
        if lhs == nil && rhs == nil {
74 +
            return true
75 +
        }
76 +
        switch (lhs, rhs) {
77 +
        case let (lhs, rhs) as (Bool, Bool):
78 +
            return lhs == rhs
79 +
        case let (lhs, rhs) as (Temporal.Date, Temporal.Date):
80 +
            return lhs == rhs
81 +
        case let (lhs, rhs) as (Temporal.DateTime, Temporal.DateTime):
82 +
            return lhs == rhs
83 +
        case let (lhs, rhs) as (Temporal.Time, Temporal.Time):
84 +
            return lhs == rhs
85 +
        case let (lhs, rhs) as (Double, Double):
86 +
            return lhs == rhs
87 +
        case let (lhs, rhs) as (Int, Int):
88 +
            return lhs == rhs
89 +
        case let (lhs, rhs) as (Int, Double):
90 +
            return Double(lhs) == rhs
91 +
        case let (lhs, rhs) as (Double, Int):
92 +
            return lhs == Double(rhs)
93 +
        case let (lhs, rhs) as (String, String):
94 +
            return lhs == rhs
95 +
        default:
96 +
            return false
97 +
        }
98 +
    }
99 +
100 +
    //We are promoting Int to Double in the case where we are comparing these two types
101 +
    public static func isLessOrEqual(_ lhs: Any?, _ rhs: Persistable?) -> Bool {
102 +
        if lhs == nil && rhs == nil {
103 +
            return true
104 +
        }
105 +
        switch (lhs, rhs) {
106 +
        //case Bool Removed
107 +
        case let (lhs, rhs) as (Temporal.Date, Temporal.Date):
108 +
            return lhs <= rhs
109 +
        case let (lhs, rhs) as (Temporal.DateTime, Temporal.DateTime):
110 +
            return lhs <= rhs
111 +
        case let (lhs, rhs) as (Temporal.Time, Temporal.Time):
112 +
            return lhs <= rhs
113 +
        case let (lhs, rhs) as (Double, Double):
114 +
            return lhs <= rhs
115 +
        case let (lhs, rhs) as (Int, Int):
116 +
            return lhs <= rhs
117 +
        case let (lhs, rhs) as (Int, Double):
118 +
            return Double(lhs) <= rhs
119 +
        case let (lhs, rhs) as (Double, Int):
120 +
            return lhs <= Double(rhs)
121 +
        case let (lhs, rhs) as (String, String):
122 +
            return lhs <= rhs
123 +
        default:
124 +
            return false
125 +
        }
126 +
    }
127 +
128 +
    //We are promoting Int to Double in the case where we are comparing these two types
129 +
    public static func isLessThan(_ lhs: Any?, _ rhs: Persistable?) -> Bool {
130 +
        if lhs == nil && rhs == nil {
131 +
            return false
132 +
        }
133 +
        switch (lhs, rhs) {
134 +
        //case Bool Removed
135 +
        case let (lhs, rhs) as (Temporal.Date, Temporal.Date):
136 +
            return lhs < rhs
137 +
        case let (lhs, rhs) as (Temporal.DateTime, Temporal.DateTime):
138 +
            return lhs < rhs
139 +
        case let (lhs, rhs) as (Temporal.Time, Temporal.Time):
140 +
            return lhs < rhs
141 +
        case let (lhs, rhs) as (Double, Double):
142 +
            return lhs < rhs
143 +
        case let (lhs, rhs) as (Int, Int):
144 +
            return lhs < rhs
145 +
        case let (lhs, rhs) as (Int, Double):
146 +
            return Double(lhs) < rhs
147 +
        case let (lhs, rhs) as (Double, Int):
148 +
            return lhs < Double(rhs)
149 +
        case let (lhs, rhs) as (String, String):
150 +
            return lhs < rhs
151 +
        default:
152 +
            return false
153 +
        }
154 +
    }
155 +
156 +
    //We are promoting Int to Double in the case where we are comparing these two types
157 +
    public static func isGreaterOrEqual(_ lhs: Any?, _ rhs: Persistable?) -> Bool {
158 +
        if lhs == nil && rhs == nil {
159 +
            return true
160 +
        }
161 +
        switch (lhs, rhs) {
162 +
        //case Bool Removed
163 +
        case let (lhs, rhs) as (Temporal.Date, Temporal.Date):
164 +
            return lhs >= rhs
165 +
        case let (lhs, rhs) as (Temporal.DateTime, Temporal.DateTime):
166 +
            return lhs >= rhs
167 +
        case let (lhs, rhs) as (Temporal.Time, Temporal.Time):
168 +
            return lhs >= rhs
169 +
        case let (lhs, rhs) as (Double, Double):
170 +
            return lhs >= rhs
171 +
        case let (lhs, rhs) as (Int, Int):
172 +
            return lhs >= rhs
173 +
        case let (lhs, rhs) as (Int, Double):
174 +
            return Double(lhs) >= rhs
175 +
        case let (lhs, rhs) as (Double, Int):
176 +
            return lhs >= Double(rhs)
177 +
        case let (lhs, rhs) as (String, String):
178 +
            return lhs >= rhs
179 +
        default:
180 +
            return false
181 +
        }
182 +
    }
183 +
184 +
    //We are promoting Int to Double in the case where we are comparing these two types
185 +
    public static func isGreaterThan(_ lhs: Any?, _ rhs: Persistable?) -> Bool {
186 +
        if lhs == nil && rhs == nil {
187 +
            return false
188 +
        }
189 +
        switch (lhs, rhs) {
190 +
        //case Bool Removed
191 +
        case let (lhs, rhs) as (Temporal.Date, Temporal.Date):
192 +
            return lhs > rhs
193 +
        case let (lhs, rhs) as (Temporal.DateTime, Temporal.DateTime):
194 +
            return lhs > rhs
195 +
        case let (lhs, rhs) as (Temporal.Time, Temporal.Time):
196 +
            return lhs > rhs
197 +
        case let (lhs, rhs) as (Double, Double):
198 +
            return lhs > rhs
199 +
        case let (lhs, rhs) as (Int, Int):
200 +
            return lhs > rhs
201 +
        case let (lhs, rhs) as (Double, Int):
202 +
            return lhs > Double(rhs)
203 +
        case let (lhs, rhs) as (Int, Double):
204 +
            return Double(lhs) > rhs
205 +
        case let (lhs, rhs) as (String, String):
206 +
            return lhs > rhs
207 +
        default:
208 +
            return false
209 +
        }
210 +
    }
211 +
212 +
    public static func isBetween(_ start: Persistable, _ end: Persistable, _ value: Any?) -> Bool {
213 +
        if value == nil {
214 +
            return false
215 +
        }
216 +
        return isGreaterOrEqual(value, start) && isLessOrEqual(value, end)
217 +
    }
70 218
}
Files Coverage
Amplify 45.75%
AmplifyPlugins 67.12%
AmplifyTestApp 44.44%
AmplifyTestCommon 25.61%
AmplifyTests 91.38%
Project Totals (874 files) 66.00%
20158
Storage_plugin_unit_test
20156
Auth_plugin_unit_test
20157
build_test_amplify
20154
Predictions_plugin_unit_test
20153
API_plugin_unit_test
20159
DataStore_plugin_unit_test
20160
Analytics_plugin_unit_test
20155
Predictions_plugin_unit_test

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading