Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Sources/MongoSwift/APM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public struct CommandSucceededEvent: MongoSwiftEvent, CommandEventProtocol {
}

/// The execution time of the event, in microseconds.
public let duration: Int64
public let duration: Int

/// The command reply.
public let reply: Document
Expand All @@ -186,7 +186,8 @@ public struct CommandSucceededEvent: MongoSwiftEvent, CommandEventProtocol {
public let serverAddress: Address

fileprivate init(mongocEvent: MongocCommandSucceededEvent) {
self.duration = mongoc_apm_command_succeeded_get_duration(mongocEvent.ptr)
// TODO: SWIFT-349 add logging to check and warn of unlikely int size issues
self.duration = Int(mongoc_apm_command_succeeded_get_duration(mongocEvent.ptr))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess technically this can fail if we're on a 32 bit system and a command lasts longer than 35 minutes... probably not gonna happen though

// we have to copy because libmongoc owns the pointer.
self.reply = Document(copying: mongoc_apm_command_succeeded_get_reply(mongocEvent.ptr))
self.commandName = String(cString: mongoc_apm_command_succeeded_get_command_name(mongocEvent.ptr))
Expand Down Expand Up @@ -216,7 +217,7 @@ public struct CommandFailedEvent: MongoSwiftEvent, CommandEventProtocol {
}

/// The execution time of the event, in microseconds.
public let duration: Int64
public let duration: Int

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

fileprivate init(mongocEvent: MongocCommandFailedEvent) {
self.duration = mongoc_apm_command_failed_get_duration(mongocEvent.ptr)
self.duration = Int(mongoc_apm_command_failed_get_duration(mongocEvent.ptr))
self.commandName = String(cString: mongoc_apm_command_failed_get_command_name(mongocEvent.ptr))
var error = bson_error_t()
mongoc_apm_command_failed_get_error(mongocEvent.ptr, &error)
Expand Down Expand Up @@ -548,7 +549,7 @@ public struct ServerHeartbeatSucceededEvent: MongoSwiftEvent {
}

/// The execution time of the event, in microseconds.
public let duration: Int64
public let duration: Int

/// The command reply.
public let reply: Document
Expand All @@ -557,7 +558,7 @@ public struct ServerHeartbeatSucceededEvent: MongoSwiftEvent {
public let serverAddress: Address

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

/// The execution time of the event, in microseconds.
public let duration: Int64
public let duration: Int

/// The failure.
public let failure: MongoError
Expand All @@ -593,7 +594,7 @@ public struct ServerHeartbeatFailedEvent: MongoSwiftEvent {
public let serverAddress: Address

fileprivate init(mongocEvent: MongocServerHeartbeatFailedEvent) {
self.duration = mongoc_apm_server_heartbeat_failed_get_duration(mongocEvent.ptr)
self.duration = Int(mongoc_apm_server_heartbeat_failed_get_duration(mongocEvent.ptr))
var error = bson_error_t()
mongoc_apm_server_heartbeat_failed_get_error(mongocEvent.ptr, &error)
self.failure = extractMongoError(error: error)
Expand Down
8 changes: 4 additions & 4 deletions Sources/MongoSwift/ChangeStreamOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum FullDocument: RawRepresentable, Codable {
public struct ChangeStreamOptions: Codable {
/// The number of documents to return per batch. If omitted, the server will use its default batch size.
/// - SeeAlso: https://docs.mongodb.com/manual/reference/command/aggregate
public var batchSize: Int32?
public var batchSize: Int?

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

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

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

/// Initializes a `ChangeStreamOptions`.
public init(
batchSize: Int32? = nil,
batchSize: Int? = nil,
collation: Document? = nil,
fullDocument: FullDocument? = nil,
maxAwaitTimeMS: Int64? = nil,
maxAwaitTimeMS: Int? = nil,
resumeAfter: ResumeToken? = nil,
startAtOperationTime: Timestamp? = nil
) {
Expand Down
12 changes: 6 additions & 6 deletions Sources/MongoSwift/MongoCollection+FindAndModify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodabl
public var collation: Document?

/// The maximum amount of time to allow the query to run.
public var maxTimeMS: Int64?
public var maxTimeMS: Int?

/// Limits the fields to return for the matching document.
public var projection: Document?
Expand All @@ -172,7 +172,7 @@ public struct FindOneAndDeleteOptions: FindAndModifyOptionsConvertible, Decodabl
/// Convenience initializer allowing any/all parameters to be omitted/optional
public init(
collation: Document? = nil,
maxTimeMS: Int64? = nil,
maxTimeMS: Int? = nil,
projection: Document? = nil,
sort: Document? = nil,
writeConcern: WriteConcern? = nil
Expand All @@ -194,7 +194,7 @@ public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodab
public var collation: Document?

/// The maximum amount of time to allow the query to run.
public var maxTimeMS: Int64?
public var maxTimeMS: Int?

/// Limits the fields to return for the matching document.
public var projection: Document?
Expand Down Expand Up @@ -228,7 +228,7 @@ public struct FindOneAndReplaceOptions: FindAndModifyOptionsConvertible, Decodab
public init(
bypassDocumentValidation: Bool? = nil,
collation: Document? = nil,
maxTimeMS: Int64? = nil,
maxTimeMS: Int? = nil,
projection: Document? = nil,
returnDocument: ReturnDocument? = nil,
sort: Document? = nil,
Expand Down Expand Up @@ -258,7 +258,7 @@ public struct FindOneAndUpdateOptions: FindAndModifyOptionsConvertible, Decodabl
public var collation: Document?

/// The maximum amount of time to allow the query to run.
public var maxTimeMS: Int64?
public var maxTimeMS: Int?

/// Limits the fields to return for the matching document.
public var projection: Document?
Expand Down Expand Up @@ -294,7 +294,7 @@ public struct FindOneAndUpdateOptions: FindAndModifyOptionsConvertible, Decodabl
arrayFilters: [Document]? = nil,
bypassDocumentValidation: Bool? = nil,
collation: Document? = nil,
maxTimeMS: Int64? = nil,
maxTimeMS: Int? = nil,
projection: Document? = nil,
returnDocument: ReturnDocument? = nil,
sort: Document? = nil,
Expand Down
24 changes: 12 additions & 12 deletions Sources/MongoSwift/MongoCollection+Indexes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public struct IndexOptions: Codable {
public var background: Bool?

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

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

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

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

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

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

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

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

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

/// Optionally specifies the index version number, either 0 or 1.
public var version: Int32?
public var version: Int?

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

/// Convenience initializer allowing any/all parameters to be omitted.
public init(
background: Bool? = nil,
bits: Int32? = nil,
bucketSize: Int32? = nil,
bits: Int? = nil,
bucketSize: Int? = nil,
collation: Document? = nil,
defaultLanguage: String? = nil,
expireAfterSeconds: Int32? = nil,
expireAfterSeconds: Int? = nil,
languageOverride: String? = nil,
max: Double? = nil,
min: Double? = nil,
name: String? = nil,
partialFilterExpression: Document? = nil,
sparse: Bool? = nil,
sphereIndexVersion: Int32? = nil,
sphereIndexVersion: Int? = nil,
storageEngine: Document? = nil,
textIndexVersion: Int32? = nil,
textIndexVersion: Int? = nil,
unique: Bool? = nil,
version: Int32? = nil,
version: Int? = nil,
weights: Document? = nil
) {
self.background = background
Expand Down
8 changes: 4 additions & 4 deletions Sources/MongoSwift/Operations/AggregateOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public struct AggregateOptions: Codable {
public var allowDiskUse: Bool?

/// The number of `Document`s to return per batch.
public var batchSize: Int32?
public var batchSize: Int?

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

/// The maximum amount of time to allow the query to run.
public var maxTimeMS: Int64?
public var maxTimeMS: Int?

/// A `ReadConcern` to use in read stages of this operation.
public var readConcern: ReadConcern?
Expand All @@ -41,12 +41,12 @@ public struct AggregateOptions: Codable {
/// Convenience initializer allowing any/all parameters to be omitted or optional.
public init(
allowDiskUse: Bool? = nil,
batchSize: Int32? = nil,
batchSize: Int? = nil,
bypassDocumentValidation: Bool? = nil,
collation: Document? = nil,
comment: String? = nil,
hint: Hint? = nil,
maxTimeMS: Int64? = nil,
maxTimeMS: Int? = nil,
readConcern: ReadConcern? = nil,
readPreference: ReadPreference? = nil,
writeConcern: WriteConcern? = nil
Expand Down
12 changes: 6 additions & 6 deletions Sources/MongoSwift/Operations/CountDocumentsOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public struct CountDocumentsOptions: Codable {
public var hint: Hint?

/// The maximum number of documents to count.
public var limit: Int64?
public var limit: Int?

/// The maximum amount of time to allow the query to run.
public var maxTimeMS: Int64?
public var maxTimeMS: Int?

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

/// The number of documents to skip before counting.
public var skip: Int64?
public var skip: Int?

/// Convenience initializer allowing any/all parameters to be optional
public init(
collation: Document? = nil,
hint: Hint? = nil,
limit: Int64? = nil,
maxTimeMS: Int64? = nil,
limit: Int? = nil,
maxTimeMS: Int? = nil,
readConcern: ReadConcern? = nil,
readPreference: ReadPreference? = nil,
skip: Int64? = nil
skip: Int? = nil
) {
self.collation = collation
self.hint = hint
Expand Down
8 changes: 4 additions & 4 deletions Sources/MongoSwift/Operations/CreateCollectionOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public struct CreateCollectionOptions: Codable, CodingStrategyProvider {
public var indexOptionDefaults: Document?

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

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

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

/// Specifies storage engine configuration for this collection.
public var storageEngine: Document?
Expand Down Expand Up @@ -73,9 +73,9 @@ public struct CreateCollectionOptions: Codable, CodingStrategyProvider {
dataCodingStrategy: DataCodingStrategy? = nil,
dateCodingStrategy: DateCodingStrategy? = nil,
indexOptionDefaults: Document? = nil,
max: Int64? = nil,
max: Int? = nil,
pipeline: [Document]? = nil,
size: Int64? = nil,
size: Int? = nil,
storageEngine: Document? = nil,
uuidCodingStrategy: UUIDCodingStrategy? = nil,
validationAction: String? = nil,
Expand Down
4 changes: 2 additions & 2 deletions Sources/MongoSwift/Operations/CreateIndexesOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import CLibMongoC
/// Options to use when creating a new index on a `MongoCollection`.
public struct CreateIndexOptions: Encodable {
/// The maximum amount of time to allow the query to run - enforced server-side.
public var maxTimeMS: Int64?
public var maxTimeMS: Int?

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

/// Initializer allowing any/all parameters to be omitted.
public init(maxTimeMS: Int64? = nil, writeConcern: WriteConcern? = nil) {
public init(maxTimeMS: Int? = nil, writeConcern: WriteConcern? = nil) {
self.maxTimeMS = maxTimeMS
self.writeConcern = writeConcern
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/MongoSwift/Operations/DistinctOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct DistinctOptions: Codable {
public var collation: Document?

/// The maximum amount of time to allow the query to run.
public var maxTimeMS: Int64?
public var maxTimeMS: Int?

/// A ReadConcern to use for this operation.
public var readConcern: ReadConcern?
Expand All @@ -19,7 +19,7 @@ public struct DistinctOptions: Codable {
/// Convenience initializer allowing any/all parameters to be optional
public init(
collation: Document? = nil,
maxTimeMS: Int64? = nil,
maxTimeMS: Int? = nil,
readConcern: ReadConcern? = nil,
readPreference: ReadPreference? = nil
) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/MongoSwift/Operations/DropIndexesOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import CLibMongoC
/// Options to use when dropping an index from a `MongoCollection`.
public struct DropIndexOptions: Encodable {
/// The maximum amount of time to allow the query to run - enforced server-side.
public var maxTimeMS: Int64?
public var maxTimeMS: Int?

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

/// Initializer allowing any/all parameters to be omitted.
public init(maxTimeMS: Int64? = nil, writeConcern: WriteConcern? = nil) {
public init(maxTimeMS: Int? = nil, writeConcern: WriteConcern? = nil) {
self.maxTimeMS = maxTimeMS
self.writeConcern = writeConcern
}
Expand Down
Loading