Skip to content

Commit f5725f4

Browse files
authored
SWIFT-513 Standardize ordering of options parameters (#329)
1 parent 7dd208e commit f5725f4

18 files changed

+386
-331
lines changed

Sources/MongoSwift/BSON/CodingStrategies.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ public protocol CodingStrategyProvider {
1717

1818
/// Options struct used for configuring the coding strategies on `BSONEncoder` and `BSONDecoder`.
1919
public struct BSONCoderOptions: CodingStrategyProvider {
20+
public var dataCodingStrategy: DataCodingStrategy?
21+
2022
public var dateCodingStrategy: DateCodingStrategy?
2123

2224
public var uuidCodingStrategy: UUIDCodingStrategy?
2325

24-
public var dataCodingStrategy: DataCodingStrategy?
25-
2626
/// Initializes a new `BSONCoderOptions`.
27-
public init(dateCodingStrategy: DateCodingStrategy? = nil,
28-
uuidCodingStrategy: UUIDCodingStrategy? = nil,
29-
dataCodingStrategy: DataCodingStrategy? = nil) {
27+
public init(dataCodingStrategy: DataCodingStrategy? = nil,
28+
dateCodingStrategy: DateCodingStrategy? = nil,
29+
uuidCodingStrategy: UUIDCodingStrategy? = nil) {
30+
self.dataCodingStrategy = dataCodingStrategy
3031
self.dateCodingStrategy = dateCodingStrategy
3132
self.uuidCodingStrategy = uuidCodingStrategy
32-
self.dataCodingStrategy = dataCodingStrategy
3333
}
3434
}
3535

Sources/MongoSwift/ChangeStreamOptions.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public enum FullDocument: RawRepresentable, Codable {
2828

2929
/// Options to use when creating a `ChangeStream`.
3030
public struct ChangeStreamOptions: Codable {
31+
/// The number of documents to return per batch. If omitted, the server will use its default batch size.
32+
/// - SeeAlso: https://docs.mongodb.com/manual/reference/command/aggregate
33+
public var batchSize: Int32?
34+
35+
/// Specifies a collation.
36+
/// - SeeAlso: https://docs.mongodb.com/manual/reference/command/aggregate
37+
public var collation: Document?
38+
3139
/**
3240
* Indicates how the `fullDocument` field of a change stream document should be filled out by the server.
3341
* By default (indicated by a nil value for this option), the `fullDocument` field in the change stream document
@@ -36,6 +44,10 @@ public struct ChangeStreamOptions: Codable {
3644
*/
3745
public var fullDocument: FullDocument?
3846

47+
/// The maximum amount of time in milliseconds for the server to wait on new documents to satisfy a
48+
/// change stream query. If omitted, the server will use its default timeout.
49+
public var maxAwaitTimeMS: Int64?
50+
3951
/**
4052
* A `ResumeToken` that manually specifies the logical starting point for the new change stream.
4153
* The change stream will attempt to resume notifications starting after the operation associated with
@@ -45,23 +57,6 @@ public struct ChangeStreamOptions: Codable {
4557
*/
4658
public var resumeAfter: ResumeToken?
4759

48-
/// The maximum amount of time in milliseconds for the server to wait on new documents to satisfy a
49-
/// change stream query. If omitted, the server will use its default timeout.
50-
public var maxAwaitTimeMS: Int64?
51-
52-
/// The number of documents to return per batch. If omitted, the server will use its default batch size.
53-
/// - SeeAlso: https://docs.mongodb.com/manual/reference/command/aggregate
54-
public var batchSize: Int32?
55-
56-
/// Specifies a collation.
57-
/// - SeeAlso: https://docs.mongodb.com/manual/reference/command/aggregate
58-
public var collation: Document?
59-
60-
/// The change stream will only provide changes that occurred at or after the specified timestamp.
61-
/// Any command run against the server will return an operation time that can be used here.
62-
/// - SeeAlso: https://docs.mongodb.com/manual/reference/method/db.runCommand/
63-
public var startAtOperationTime: Timestamp?
64-
6560
/**
6661
* Similar to `resumeAfter`, this option takes a `ResumeToken` which will serve as the logical starting
6762
* point for the new change stream. This option differs from `resumeAfter` in that it will allow a change stream
@@ -73,19 +68,24 @@ public struct ChangeStreamOptions: Codable {
7368
// TODO: SWIFT-519 - Make this public when support is added for 4.2 change stream features.
7469
internal var startAfter: ResumeToken?
7570

71+
/// The change stream will only provide changes that occurred at or after the specified timestamp.
72+
/// Any command run against the server will return an operation time that can be used here.
73+
/// - SeeAlso: https://docs.mongodb.com/manual/reference/method/db.runCommand/
74+
public var startAtOperationTime: Timestamp?
75+
7676
/// Initializes a `ChangeStreamOptions`.
77-
public init(fullDocument: FullDocument? = nil,
78-
resumeAfter: ResumeToken? = nil,
79-
maxAwaitTimeMS: Int64? = nil,
80-
batchSize: Int32? = nil,
77+
public init(batchSize: Int32? = nil,
8178
collation: Document? = nil,
79+
fullDocument: FullDocument? = nil,
80+
maxAwaitTimeMS: Int64? = nil,
81+
resumeAfter: ResumeToken? = nil,
8282
startAtOperationTime: Timestamp? = nil) {
83-
self.fullDocument = fullDocument
84-
self.resumeAfter = resumeAfter
85-
self.maxAwaitTimeMS = maxAwaitTimeMS
8683
self.batchSize = batchSize
8784
self.collation = collation
88-
self.startAtOperationTime = startAtOperationTime
85+
self.fullDocument = fullDocument
86+
self.maxAwaitTimeMS = maxAwaitTimeMS
87+
self.resumeAfter = resumeAfter
8988
self.startAfter = nil
89+
self.startAtOperationTime = startAtOperationTime
9090
}
9191
}

Sources/MongoSwift/MongoClient.swift

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ import mongoc
33

44
/// Options to use when creating a `MongoClient`.
55
public 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`.
100100
public 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.
139139
public 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

Comments
 (0)