Skip to content

Commit 940d90d

Browse files
authored
SWIFT-754: Use Int in public API as much as possible (#455)
1 parent b8a3726 commit 940d90d

22 files changed

+107
-105
lines changed

Package.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"repositoryURL": "https://github.com/apple/swift-nio",
1616
"state": {
1717
"branch": null,
18-
"revision": "a27a07719ca785bcaca019a5b9fe1814b981b4a2",
19-
"version": "2.15.0"
18+
"revision": "e876fb37410e0036b98b5361bb18e6854739572b",
19+
"version": "2.16.0"
2020
}
2121
}
2222
]

Sources/MongoSwift/APM.swift

+9-8
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public struct CommandSucceededEvent: MongoSwiftEvent, CommandEventProtocol {
167167
}
168168

169169
/// The execution time of the event, in microseconds.
170-
public let duration: Int64
170+
public let duration: Int
171171

172172
/// The command reply.
173173
public let reply: Document
@@ -186,7 +186,8 @@ public struct CommandSucceededEvent: MongoSwiftEvent, CommandEventProtocol {
186186
public let serverAddress: Address
187187

188188
fileprivate init(mongocEvent: MongocCommandSucceededEvent) {
189-
self.duration = mongoc_apm_command_succeeded_get_duration(mongocEvent.ptr)
189+
// TODO: SWIFT-349 add logging to check and warn of unlikely int size issues
190+
self.duration = Int(mongoc_apm_command_succeeded_get_duration(mongocEvent.ptr))
190191
// we have to copy because libmongoc owns the pointer.
191192
self.reply = Document(copying: mongoc_apm_command_succeeded_get_reply(mongocEvent.ptr))
192193
self.commandName = String(cString: mongoc_apm_command_succeeded_get_command_name(mongocEvent.ptr))
@@ -216,7 +217,7 @@ public struct CommandFailedEvent: MongoSwiftEvent, CommandEventProtocol {
216217
}
217218

218219
/// The execution time of the event, in microseconds.
219-
public let duration: Int64
220+
public let duration: Int
220221

221222
/// The command name.
222223
public let commandName: String
@@ -235,7 +236,7 @@ public struct CommandFailedEvent: MongoSwiftEvent, CommandEventProtocol {
235236
public let serverAddress: Address
236237

237238
fileprivate init(mongocEvent: MongocCommandFailedEvent) {
238-
self.duration = mongoc_apm_command_failed_get_duration(mongocEvent.ptr)
239+
self.duration = Int(mongoc_apm_command_failed_get_duration(mongocEvent.ptr))
239240
self.commandName = String(cString: mongoc_apm_command_failed_get_command_name(mongocEvent.ptr))
240241
var error = bson_error_t()
241242
mongoc_apm_command_failed_get_error(mongocEvent.ptr, &error)
@@ -548,7 +549,7 @@ public struct ServerHeartbeatSucceededEvent: MongoSwiftEvent {
548549
}
549550

550551
/// The execution time of the event, in microseconds.
551-
public let duration: Int64
552+
public let duration: Int
552553

553554
/// The command reply.
554555
public let reply: Document
@@ -557,7 +558,7 @@ public struct ServerHeartbeatSucceededEvent: MongoSwiftEvent {
557558
public let serverAddress: Address
558559

559560
fileprivate init(mongocEvent: MongocServerHeartbeatSucceededEvent) {
560-
self.duration = mongoc_apm_server_heartbeat_succeeded_get_duration(mongocEvent.ptr)
561+
self.duration = Int(mongoc_apm_server_heartbeat_succeeded_get_duration(mongocEvent.ptr))
561562
// we have to copy because libmongoc owns the pointer.
562563
self.reply = Document(copying: mongoc_apm_server_heartbeat_succeeded_get_reply(mongocEvent.ptr))
563564
self.serverAddress = Address(mongoc_apm_server_heartbeat_succeeded_get_host(mongocEvent.ptr))
@@ -584,7 +585,7 @@ public struct ServerHeartbeatFailedEvent: MongoSwiftEvent {
584585
}
585586

586587
/// The execution time of the event, in microseconds.
587-
public let duration: Int64
588+
public let duration: Int
588589

589590
/// The failure.
590591
public let failure: MongoError
@@ -593,7 +594,7 @@ public struct ServerHeartbeatFailedEvent: MongoSwiftEvent {
593594
public let serverAddress: Address
594595

595596
fileprivate init(mongocEvent: MongocServerHeartbeatFailedEvent) {
596-
self.duration = mongoc_apm_server_heartbeat_failed_get_duration(mongocEvent.ptr)
597+
self.duration = Int(mongoc_apm_server_heartbeat_failed_get_duration(mongocEvent.ptr))
597598
var error = bson_error_t()
598599
mongoc_apm_server_heartbeat_failed_get_error(mongocEvent.ptr, &error)
599600
self.failure = extractMongoError(error: error)

Sources/MongoSwift/ChangeStreamOptions.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public enum FullDocument: RawRepresentable, Codable {
3030
public struct ChangeStreamOptions: Codable {
3131
/// The number of documents to return per batch. If omitted, the server will use its default batch size.
3232
/// - SeeAlso: https://docs.mongodb.com/manual/reference/command/aggregate
33-
public var batchSize: Int32?
33+
public var batchSize: Int?
3434

3535
/// Specifies a collation.
3636
/// - SeeAlso: https://docs.mongodb.com/manual/reference/command/aggregate
@@ -46,7 +46,7 @@ public struct ChangeStreamOptions: Codable {
4646

4747
/// The maximum amount of time in milliseconds for the server to wait on new documents to satisfy a
4848
/// change stream query. If omitted, the server will use its default timeout.
49-
public var maxAwaitTimeMS: Int64?
49+
public var maxAwaitTimeMS: Int?
5050

5151
/**
5252
* A `ResumeToken` that manually specifies the logical starting point for the new change stream.
@@ -75,10 +75,10 @@ public struct ChangeStreamOptions: Codable {
7575

7676
/// Initializes a `ChangeStreamOptions`.
7777
public init(
78-
batchSize: Int32? = nil,
78+
batchSize: Int? = nil,
7979
collation: Document? = nil,
8080
fullDocument: FullDocument? = nil,
81-
maxAwaitTimeMS: Int64? = nil,
81+
maxAwaitTimeMS: Int? = nil,
8282
resumeAfter: ResumeToken? = nil,
8383
startAtOperationTime: Timestamp? = nil
8484
) {

Sources/MongoSwift/MongoCollection+FindAndModify.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodabl
147147
public var collation: Document?
148148

149149
/// The maximum amount of time to allow the query to run.
150-
public var maxTimeMS: Int64?
150+
public var maxTimeMS: Int?
151151

152152
/// Limits the fields to return for the matching document.
153153
public var projection: Document?
@@ -172,7 +172,7 @@ public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodabl
172172
/// Convenience initializer allowing any/all parameters to be omitted/optional
173173
public init(
174174
collation: Document? = nil,
175-
maxTimeMS: Int64? = nil,
175+
maxTimeMS: Int? = nil,
176176
projection: Document? = nil,
177177
sort: Document? = nil,
178178
writeConcern: WriteConcern? = nil
@@ -194,7 +194,7 @@ public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodab
194194
public var collation: Document?
195195

196196
/// The maximum amount of time to allow the query to run.
197-
public var maxTimeMS: Int64?
197+
public var maxTimeMS: Int?
198198

199199
/// Limits the fields to return for the matching document.
200200
public var projection: Document?
@@ -228,7 +228,7 @@ public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodab
228228
public init(
229229
bypassDocumentValidation: Bool? = nil,
230230
collation: Document? = nil,
231-
maxTimeMS: Int64? = nil,
231+
maxTimeMS: Int? = nil,
232232
projection: Document? = nil,
233233
returnDocument: ReturnDocument? = nil,
234234
sort: Document? = nil,
@@ -258,7 +258,7 @@ public struct FindOneAndUpdateOptions: FindAndModifyOptionsConvertible, Decodabl
258258
public var collation: Document?
259259

260260
/// The maximum amount of time to allow the query to run.
261-
public var maxTimeMS: Int64?
261+
public var maxTimeMS: Int?
262262

263263
/// Limits the fields to return for the matching document.
264264
public var projection: Document?
@@ -294,7 +294,7 @@ public struct FindOneAndUpdateOptions: FindAndModifyOptionsConvertible, Decodabl
294294
arrayFilters: [Document]? = nil,
295295
bypassDocumentValidation: Bool? = nil,
296296
collation: Document? = nil,
297-
maxTimeMS: Int64? = nil,
297+
maxTimeMS: Int? = nil,
298298
projection: Document? = nil,
299299
returnDocument: ReturnDocument? = nil,
300300
sort: Document? = nil,

Sources/MongoSwift/MongoCollection+Indexes.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ public struct IndexOptions: Codable {
4444
public var background: Bool?
4545

4646
/// Optionally specifies the precision of the stored geo hash in the 2d index, from 1 to 32.
47-
public var bits: Int32?
47+
public var bits: Int?
4848

4949
/// Optionally specifies the number of units within which to group the location values in a geo haystack index.
50-
public var bucketSize: Int32?
50+
public var bucketSize: Int?
5151

5252
/// Optionally specifies a collation to use for the index in MongoDB 3.4 and higher. If not specified, no collation
5353
/// is sent and the default collation of the collection server-side is used.
@@ -57,7 +57,7 @@ public struct IndexOptions: Codable {
5757
public var defaultLanguage: String?
5858

5959
/// Optionally specifies the length in time, in seconds, for documents to remain in a collection.
60-
public var expireAfterSeconds: Int32?
60+
public var expireAfterSeconds: Int?
6161

6262
/// Optionally specifies the field in the document to override the language.
6363
public var languageOverride: String?
@@ -88,44 +88,44 @@ public struct IndexOptions: Codable {
8888

8989
/// Optionally specifies the 2dsphere index version number. MongoDB 2.4 can only support version 1. MongoDB 2.6 and
9090
/// higher may support version 1 or 2.
91-
public var sphereIndexVersion: Int32?
91+
public var sphereIndexVersion: Int?
9292

9393
/// Optionally used only in MongoDB 3.0.0 and higher. Allows users to configure the storage engine on a per-index
9494
/// basis when creating an index.
9595
public var storageEngine: Document?
9696

9797
/// Optionally provides the text index version number. MongoDB 2.4 can only support version 1. MongoDB 2.6 and
9898
/// higher may support version 1 or 2.
99-
public var textIndexVersion: Int32?
99+
public var textIndexVersion: Int?
100100

101101
/// Optionally forces the index to be unique.
102102
public var unique: Bool?
103103

104104
/// Optionally specifies the index version number, either 0 or 1.
105-
public var version: Int32?
105+
public var version: Int?
106106

107107
/// Optionally specifies fields in the index and their corresponding weight values.
108108
public var weights: Document?
109109

110110
/// Convenience initializer allowing any/all parameters to be omitted.
111111
public init(
112112
background: Bool? = nil,
113-
bits: Int32? = nil,
114-
bucketSize: Int32? = nil,
113+
bits: Int? = nil,
114+
bucketSize: Int? = nil,
115115
collation: Document? = nil,
116116
defaultLanguage: String? = nil,
117-
expireAfterSeconds: Int32? = nil,
117+
expireAfterSeconds: Int? = nil,
118118
languageOverride: String? = nil,
119119
max: Double? = nil,
120120
min: Double? = nil,
121121
name: String? = nil,
122122
partialFilterExpression: Document? = nil,
123123
sparse: Bool? = nil,
124-
sphereIndexVersion: Int32? = nil,
124+
sphereIndexVersion: Int? = nil,
125125
storageEngine: Document? = nil,
126-
textIndexVersion: Int32? = nil,
126+
textIndexVersion: Int? = nil,
127127
unique: Bool? = nil,
128-
version: Int32? = nil,
128+
version: Int? = nil,
129129
weights: Document? = nil
130130
) {
131131
self.background = background

Sources/MongoSwift/Operations/AggregateOperation.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public struct AggregateOptions: Codable {
88
public var allowDiskUse: Bool?
99

1010
/// The number of `Document`s to return per batch.
11-
public var batchSize: Int32?
11+
public var batchSize: Int?
1212

1313
/// If true, allows the write to opt-out of document level validation. This only applies
1414
/// when the $out stage is specified.
@@ -25,7 +25,7 @@ public struct AggregateOptions: Codable {
2525
public var hint: Hint?
2626

2727
/// The maximum amount of time to allow the query to run.
28-
public var maxTimeMS: Int64?
28+
public var maxTimeMS: Int?
2929

3030
/// A `ReadConcern` to use in read stages of this operation.
3131
public var readConcern: ReadConcern?
@@ -41,12 +41,12 @@ public struct AggregateOptions: Codable {
4141
/// Convenience initializer allowing any/all parameters to be omitted or optional.
4242
public init(
4343
allowDiskUse: Bool? = nil,
44-
batchSize: Int32? = nil,
44+
batchSize: Int? = nil,
4545
bypassDocumentValidation: Bool? = nil,
4646
collation: Document? = nil,
4747
comment: String? = nil,
4848
hint: Hint? = nil,
49-
maxTimeMS: Int64? = nil,
49+
maxTimeMS: Int? = nil,
5050
readConcern: ReadConcern? = nil,
5151
readPreference: ReadPreference? = nil,
5252
writeConcern: WriteConcern? = nil

Sources/MongoSwift/Operations/CountDocumentsOperation.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public struct CountDocumentsOptions: Codable {
99
public var hint: Hint?
1010

1111
/// The maximum number of documents to count.
12-
public var limit: Int64?
12+
public var limit: Int?
1313

1414
/// The maximum amount of time to allow the query to run.
15-
public var maxTimeMS: Int64?
15+
public var maxTimeMS: Int?
1616

1717
/// A ReadConcern to use for this operation.
1818
public var readConcern: ReadConcern?
@@ -23,17 +23,17 @@ public struct CountDocumentsOptions: Codable {
2323
// swiftlint:enable redundant_optional_initialization
2424

2525
/// The number of documents to skip before counting.
26-
public var skip: Int64?
26+
public var skip: Int?
2727

2828
/// Convenience initializer allowing any/all parameters to be optional
2929
public init(
3030
collation: Document? = nil,
3131
hint: Hint? = nil,
32-
limit: Int64? = nil,
33-
maxTimeMS: Int64? = nil,
32+
limit: Int? = nil,
33+
maxTimeMS: Int? = nil,
3434
readConcern: ReadConcern? = nil,
3535
readPreference: ReadPreference? = nil,
36-
skip: Int64? = nil
36+
skip: Int? = nil
3737
) {
3838
self.collation = collation
3939
self.hint = hint

Sources/MongoSwift/Operations/CreateCollectionOperation.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public struct CreateCollectionOptions: Codable, CodingStrategyProvider {
2525
public var indexOptionDefaults: Document?
2626

2727
/// Maximum number of documents allowed in the collection (if capped).
28-
public var max: Int64?
28+
public var max: Int?
2929

3030
/// An array consisting of aggregation pipeline stages. When used with `viewOn`, will create the view by applying
3131
/// this pipeline to the source collection or view.
3232
public var pipeline: [Document]?
3333

3434
/// Maximum size, in bytes, of this collection (if capped).
35-
public var size: Int64?
35+
public var size: Int?
3636

3737
/// Specifies storage engine configuration for this collection.
3838
public var storageEngine: Document?
@@ -73,9 +73,9 @@ public struct CreateCollectionOptions: Codable, CodingStrategyProvider {
7373
dataCodingStrategy: DataCodingStrategy? = nil,
7474
dateCodingStrategy: DateCodingStrategy? = nil,
7575
indexOptionDefaults: Document? = nil,
76-
max: Int64? = nil,
76+
max: Int? = nil,
7777
pipeline: [Document]? = nil,
78-
size: Int64? = nil,
78+
size: Int? = nil,
7979
storageEngine: Document? = nil,
8080
uuidCodingStrategy: UUIDCodingStrategy? = nil,
8181
validationAction: String? = nil,

Sources/MongoSwift/Operations/CreateIndexesOperation.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import CLibMongoC
33
/// Options to use when creating a new index on a `MongoCollection`.
44
public struct CreateIndexOptions: Encodable {
55
/// The maximum amount of time to allow the query to run - enforced server-side.
6-
public var maxTimeMS: Int64?
6+
public var maxTimeMS: Int?
77

88
/// An optional `WriteConcern` to use for the command.
99
public var writeConcern: WriteConcern?
1010

1111
/// Initializer allowing any/all parameters to be omitted.
12-
public init(maxTimeMS: Int64? = nil, writeConcern: WriteConcern? = nil) {
12+
public init(maxTimeMS: Int? = nil, writeConcern: WriteConcern? = nil) {
1313
self.maxTimeMS = maxTimeMS
1414
self.writeConcern = writeConcern
1515
}

Sources/MongoSwift/Operations/DistinctOperation.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public struct DistinctOptions: Codable {
66
public var collation: Document?
77

88
/// The maximum amount of time to allow the query to run.
9-
public var maxTimeMS: Int64?
9+
public var maxTimeMS: Int?
1010

1111
/// A ReadConcern to use for this operation.
1212
public var readConcern: ReadConcern?
@@ -19,7 +19,7 @@ public struct DistinctOptions: Codable {
1919
/// Convenience initializer allowing any/all parameters to be optional
2020
public init(
2121
collation: Document? = nil,
22-
maxTimeMS: Int64? = nil,
22+
maxTimeMS: Int? = nil,
2323
readConcern: ReadConcern? = nil,
2424
readPreference: ReadPreference? = nil
2525
) {

Sources/MongoSwift/Operations/DropIndexesOperation.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import CLibMongoC
33
/// Options to use when dropping an index from a `MongoCollection`.
44
public struct DropIndexOptions: Encodable {
55
/// The maximum amount of time to allow the query to run - enforced server-side.
6-
public var maxTimeMS: Int64?
6+
public var maxTimeMS: Int?
77

88
/// An optional `WriteConcern` to use for the command.
99
public var writeConcern: WriteConcern?
1010

1111
/// Initializer allowing any/all parameters to be omitted.
12-
public init(maxTimeMS: Int64? = nil, writeConcern: WriteConcern? = nil) {
12+
public init(maxTimeMS: Int? = nil, writeConcern: WriteConcern? = nil) {
1313
self.maxTimeMS = maxTimeMS
1414
self.writeConcern = writeConcern
1515
}

0 commit comments

Comments
 (0)