@@ -3,13 +3,6 @@ import mongoc
33
44/// Options to use when creating a `MongoClient`.
55public struct ClientOptions : CodingStrategyProvider , Decodable {
6- /// Determines whether the client should retry supported read operations.
7- /// TODO SWIFT-587 make this public.
8- internal var retryReads : Bool ?
9-
10- /// Determines whether the client should retry supported write operations.
11- public var retryWrites : Bool ?
12-
136 /**
147 * Indicates whether this client should publish command monitoring events. If true, the following event types will
158 * be published, under the listed names (which are defined as static properties of `Notification.Name`):
@@ -19,6 +12,33 @@ public struct ClientOptions: CodingStrategyProvider, Decodable {
1912 */
2013 public var commandMonitoring : Bool = false
2114
15+ // swiftlint:disable redundant_optional_initialization
16+
17+ /// Specifies the `DataCodingStrategy` to use for BSON encoding/decoding operations performed by this client and any
18+ /// databases or collections that derive from it.
19+ public var dataCodingStrategy : DataCodingStrategy ? = nil
20+
21+ /// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this client and any
22+ /// databases or collections that derive from it.
23+ public var dateCodingStrategy : DateCodingStrategy ? = nil
24+
25+ /// If command and/or server monitoring is enabled, indicates the `NotificationCenter` events are posted to. If one
26+ /// is not specified, the application's default `NotificationCenter` will be used.
27+ public var notificationCenter : NotificationCenter ?
28+
29+ /// Specifies a ReadConcern to use for the client.
30+ public var readConcern : ReadConcern ?
31+
32+ /// Specifies a ReadPreference to use for the client.
33+ public var readPreference : ReadPreference ? = nil
34+
35+ /// Determines whether the client should retry supported read operations.
36+ /// TODO SWIFT-587 make this public.
37+ internal var retryReads : Bool ?
38+
39+ /// Determines whether the client should retry supported write operations.
40+ public var retryWrites : Bool ?
41+
2242 /**
2343 * Indicates whether this client should publish command monitoring events. If true, the following event types will
2444 * be published, under the listed names (which are defined as static properties of `Notification.Name`):
@@ -34,135 +54,115 @@ public struct ClientOptions: CodingStrategyProvider, Decodable {
3454 */
3555 public var serverMonitoring : Bool = false
3656
37- /// If command and/or server monitoring is enabled, indicates the `NotificationCenter` events are posted to. If one
38- /// is not specified, the application's default `NotificationCenter` will be used.
39- public var notificationCenter : NotificationCenter ?
40-
41- /// Specifies a ReadConcern to use for the client.
42- public var readConcern : ReadConcern ?
43-
44- /// Specifies a WriteConcern to use for the client.
45- public var writeConcern : WriteConcern ?
46-
47- // swiftlint:disable redundant_optional_initialization
48-
49- /// Specifies a ReadPreference to use for the client.
50- public var readPreference : ReadPreference ? = nil
51-
52- /// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this client and any
53- /// databases or collections that derive from it.
54- public var dateCodingStrategy : DateCodingStrategy ? = nil
57+ /// Specifies the TLS/SSL options to use for database connections.
58+ public var tlsOptions : TLSOptions ? = nil
5559
5660 /// Specifies the `UUIDCodingStrategy` to use for BSON encoding/decoding operations performed by this client and any
5761 /// databases or collections that derive from it.
5862 public var uuidCodingStrategy : UUIDCodingStrategy ? = nil
5963
60- /// Specifies the `DataCodingStrategy` to use for BSON encoding/decoding operations performed by this client and any
61- /// databases or collections that derive from it.
62- public var dataCodingStrategy : DataCodingStrategy ? = nil
63-
64- /// Specifies the TLS/SSL options to use for database connections.
65- public var tlsOptions : TLSOptions ? = nil
66-
6764 // swiftlint:enable redundant_optional_initialization
6865
66+ /// Specifies a WriteConcern to use for the client.
67+ public var writeConcern : WriteConcern ?
68+
6969 private enum CodingKeys : CodingKey {
7070 case retryWrites, readConcern, writeConcern
7171 }
7272
7373 /// Convenience initializer allowing any/all to be omitted or optional.
74- public init ( readConcern: ReadConcern ? = nil ,
74+ public init ( commandMonitoring: Bool = false ,
75+ dataCodingStrategy: DataCodingStrategy ? = nil ,
76+ dateCodingStrategy: DateCodingStrategy ? = nil ,
77+ notificationCenter: NotificationCenter ? = nil ,
78+ readConcern: ReadConcern ? = nil ,
7579 readPreference: ReadPreference ? = nil ,
7680 retryWrites: Bool ? = nil ,
77- writeConcern: WriteConcern ? = nil ,
78- commandMonitoring: Bool = false ,
7981 serverMonitoring: Bool = false ,
80- notificationCenter: NotificationCenter ? = nil ,
81- dateCodingStrategy: DateCodingStrategy ? = nil ,
82+ tlsOptions: TLSOptions ? = nil ,
8283 uuidCodingStrategy: UUIDCodingStrategy ? = nil ,
83- dataCodingStrategy: DataCodingStrategy ? = nil ,
84- tlsOptions: TLSOptions ? = nil ) {
85- self . retryWrites = retryWrites
84+ writeConcern: WriteConcern ? = nil ) {
8685 self . commandMonitoring = commandMonitoring
87- self . serverMonitoring = serverMonitoring
86+ self . dataCodingStrategy = dataCodingStrategy
87+ self . dateCodingStrategy = dateCodingStrategy
8888 self . notificationCenter = notificationCenter
8989 self . readConcern = readConcern
9090 self . readPreference = readPreference
91- self . writeConcern = writeConcern
92- self . dateCodingStrategy = dateCodingStrategy
93- self . uuidCodingStrategy = uuidCodingStrategy
94- self . dataCodingStrategy = dataCodingStrategy
91+ self . retryWrites = retryWrites
92+ self . serverMonitoring = serverMonitoring
9593 self . tlsOptions = tlsOptions
94+ self . uuidCodingStrategy = uuidCodingStrategy
95+ self . writeConcern = writeConcern
9696 }
9797}
9898
9999/// Options to use when retrieving a `MongoDatabase` from a `MongoClient`.
100100public struct DatabaseOptions : CodingStrategyProvider {
101+ /// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this database and
102+ /// any collections that derive from it.
103+ public var dataCodingStrategy : DataCodingStrategy ?
104+
105+ /// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this database and
106+ /// any collections that derive from it.
107+ public var dateCodingStrategy : DateCodingStrategy ?
108+
101109 /// A read concern to set on the retrieved database.
102110 public var readConcern : ReadConcern ?
103111
104112 /// A read preference to set on the retrieved database.
105113 public var readPreference : ReadPreference ?
106114
107- /// A write concern to set on the retrieved database.
108- public var writeConcern : WriteConcern ?
109-
110- /// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this database and
111- /// any collections that derive from it.
112- public var dateCodingStrategy : DateCodingStrategy ?
113-
114115 /// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this database and
115116 /// any collections that derive from it.
116117 public var uuidCodingStrategy : UUIDCodingStrategy ?
117118
118- /// Specifies the `DateCodingStrategy` to use for BSON encoding/decoding operations performed by this database and
119- /// any collections that derive from it.
120- public var dataCodingStrategy : DataCodingStrategy ?
119+ /// A write concern to set on the retrieved database.
120+ public var writeConcern : WriteConcern ?
121121
122122 /// Convenience initializer allowing any/all arguments to be omitted or optional.
123- public init ( readConcern: ReadConcern ? = nil ,
124- readPreference: ReadPreference ? = nil ,
125- writeConcern: WriteConcern ? = nil ,
123+ public init ( dataCodingStrategy: DataCodingStrategy ? = nil ,
126124 dateCodingStrategy: DateCodingStrategy ? = nil ,
125+ readConcern: ReadConcern ? = nil ,
126+ readPreference: ReadPreference ? = nil ,
127127 uuidCodingStrategy: UUIDCodingStrategy ? = nil ,
128- dataCodingStrategy: DataCodingStrategy ? = nil ) {
128+ writeConcern: WriteConcern ? = nil ) {
129+ self . dataCodingStrategy = dataCodingStrategy
130+ self . dateCodingStrategy = dateCodingStrategy
129131 self . readConcern = readConcern
130132 self . readPreference = readPreference
131- self . writeConcern = writeConcern
132- self . dateCodingStrategy = dateCodingStrategy
133133 self . uuidCodingStrategy = uuidCodingStrategy
134- self . dataCodingStrategy = dataCodingStrategy
134+ self . writeConcern = writeConcern
135135 }
136136}
137137
138138/// Options used to configure TLS/SSL connections to the database.
139139public struct TLSOptions {
140+ /// Indicates whether invalid hostnames are allowed. By default this is set to false.
141+ public var allowInvalidHostnames : Bool ?
142+
143+ /// Specifies the path to the certificate authority file.
144+ public var caFile : URL ?
145+
140146 /// Specifies the path to the client certificate key file.
141147 public var pemFile : URL ?
142148
143149 /// Specifies the client certificate key password.
144150 public var pemPassword : String ?
145151
146- /// Specifies the path to the certificate authority file.
147- public var caFile : URL ?
148-
149152 /// Indicates whether invalid certificates are allowed. By default this is set to false.
150153 public var weakCertValidation : Bool ?
151154
152- /// Indicates whether invalid hostnames are allowed. By default this is set to false.
153- public var allowInvalidHostnames : Bool ?
154-
155155 /// Convenience initializer allowing any/all arguments to be omitted or optional.
156- public init ( pemFile: URL ? = nil ,
157- pemPassword: String ? = nil ,
156+ public init ( allowInvalidHostnames: Bool ? = nil ,
158157 caFile: URL ? = nil ,
159- weakCertValidation: Bool ? = nil ,
160- allowInvalidHostnames: Bool ? = nil ) {
158+ pemFile: URL ? = nil ,
159+ pemPassword: String ? = nil ,
160+ weakCertValidation: Bool ? = nil ) {
161+ self . allowInvalidHostnames = allowInvalidHostnames
162+ self . caFile = caFile
161163 self . pemFile = pemFile
162164 self . pemPassword = pemPassword
163- self . caFile = caFile
164165 self . weakCertValidation = weakCertValidation
165- self . allowInvalidHostnames = allowInvalidHostnames
166166 }
167167}
168168
0 commit comments