@@ -6,36 +6,53 @@ import Foundation
66 import Core
77#endif
88
9- public enum DestinationInput : Codable , JSONEncodable , AbstractEncodable {
10- case destinationIndexName( DestinationIndexName )
9+ public struct DestinationInput : Codable , JSONEncodable {
10+ /// Algolia index name (case-sensitive).
11+ public var indexName : String
12+ public var recordType : RecordType ?
13+ /// Attributes from your source to exclude from Algolia records. Not all your data attributes will be useful for
14+ /// searching. Keeping your Algolia records small increases indexing and search performance. - Exclude nested
15+ /// attributes with `.` notation. For example, `foo.bar` indexes the `foo` attribute and all its children **except**
16+ /// the `bar` attribute. - Exclude attributes from arrays with `[i]`, where `i` is the index of the array element.
17+ /// For example, `foo.[0].bar` only excludes the `bar` attribute from the first element of the `foo` array, but
18+ /// indexes the complete `foo` attribute for all other elements. Use `*` as wildcard: `foo.[*].bar` excludes `bar`
19+ /// from all elements of the `foo` array.
20+ public var attributesToExclude : [ String ] ?
1121
12- public func encode( to encoder: Encoder ) throws {
13- var container = encoder. singleValueContainer ( )
14- switch self {
15- case let . destinationIndexName( value) :
16- try container. encode ( value)
17- }
22+ public init ( indexName: String , recordType: RecordType ? = nil , attributesToExclude: [ String ] ? = nil ) {
23+ self . indexName = indexName
24+ self . recordType = recordType
25+ self . attributesToExclude = attributesToExclude
26+ }
27+
28+ public enum CodingKeys : String , CodingKey , CaseIterable {
29+ case indexName
30+ case recordType
31+ case attributesToExclude
1832 }
1933
20- public init ( from decoder: Decoder ) throws {
21- let container = try decoder. singleValueContainer ( )
22- if let value = try ? container. decode ( DestinationIndexName . self) {
23- self = . destinationIndexName( value)
24- } else {
25- throw DecodingError . typeMismatch (
26- Self . Type. self,
27- . init( codingPath: decoder. codingPath, debugDescription: " Unable to decode instance of DestinationInput " )
28- )
29- }
34+ // Encodable protocol methods
35+
36+ public func encode( to encoder: Encoder ) throws {
37+ var container = encoder. container ( keyedBy: CodingKeys . self)
38+ try container. encode ( self . indexName, forKey: . indexName)
39+ try container. encodeIfPresent ( self . recordType, forKey: . recordType)
40+ try container. encodeIfPresent ( self . attributesToExclude, forKey: . attributesToExclude)
3041 }
42+ }
3143
32- public func GetActualInstance ( ) -> Encodable {
33- switch self {
34- case let . destinationIndexName ( value ) :
35- value as DestinationIndexName
36- }
44+ extension DestinationInput : Equatable {
45+ public static func == ( lhs : DestinationInput , rhs : DestinationInput ) -> Bool {
46+ lhs . indexName == rhs . indexName &&
47+ lhs . recordType == rhs . recordType &&
48+ lhs . attributesToExclude == rhs . attributesToExclude
3749 }
3850}
3951
40- extension DestinationInput : Equatable { }
41- extension DestinationInput : Hashable { }
52+ extension DestinationInput : Hashable {
53+ public func hash( into hasher: inout Hasher ) {
54+ hasher. combine ( self . indexName. hashValue)
55+ hasher. combine ( self . recordType? . hashValue)
56+ hasher. combine ( self . attributesToExclude? . hashValue)
57+ }
58+ }
0 commit comments