From 581d7b90b88820d393c0a25d467df679a4e24506 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 26 May 2020 12:27:30 -0400 Subject: [PATCH 1/2] fix: ChangeStreamOptions as struct --- .../Docs/Sources/AsyncExamples/main.swift | 2 +- Sources/MongoSwift/ChangeStreamOptions.swift | 27 ++++++------------- Sources/MongoSwiftSync/Exports.swift | 4 +-- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/Examples/Docs/Sources/AsyncExamples/main.swift b/Examples/Docs/Sources/AsyncExamples/main.swift index 6c114efe2..132453ebf 100644 --- a/Examples/Docs/Sources/AsyncExamples/main.swift +++ b/Examples/Docs/Sources/AsyncExamples/main.swift @@ -86,7 +86,7 @@ private func changeStreams() throws { let inventory = db.collection("inventory") // Option 1: use next() to iterate - let next = inventory.watch(options: ChangeStreamOptions(fullDocument: .updateLookup)) + let next = inventory.watch(options: ChangeStreamOptions(fullDocument: .other("blah"))) .flatMap { changeStream in changeStream.next() } diff --git a/Sources/MongoSwift/ChangeStreamOptions.swift b/Sources/MongoSwift/ChangeStreamOptions.swift index 29f6a68ec..5e2b8abec 100644 --- a/Sources/MongoSwift/ChangeStreamOptions.swift +++ b/Sources/MongoSwift/ChangeStreamOptions.swift @@ -1,29 +1,18 @@ /// Describes the modes for configuring the fullDocument field of a change stream document. -public enum FullDocument: RawRepresentable, Codable { +public struct FullDocument: RawRepresentable, Codable { /// Specifies that the `fullDocument` field of an update event will contain a copy of the entire document that /// was changed from some time after the change occurred. If the document was deleted since the updated happened, /// it will be nil. - case updateLookup + public static let updateLookup = FullDocument("updateLookup") /// For an unknown value. For forwards compatibility, no error will be thrown when an unknown value is provided. - case other(String) - - public var rawValue: String { - switch self { - case .updateLookup: - return "updateLookup" - case let .other(v): - return v - } + public static func other(_ value: String) -> FullDocument { + FullDocument(value) } - public init?(rawValue: String) { - switch rawValue { - case "updateLookup": - self = .updateLookup - default: - self = .other(rawValue) - } - } + public var rawValue: String + + public init?(rawValue: String) { self.rawValue = rawValue } + internal init(_ value: String) { self.rawValue = value } } /// Options to use when creating a `ChangeStream`. diff --git a/Sources/MongoSwiftSync/Exports.swift b/Sources/MongoSwiftSync/Exports.swift index 43e169666..93f1e4f66 100644 --- a/Sources/MongoSwiftSync/Exports.swift +++ b/Sources/MongoSwiftSync/Exports.swift @@ -1,4 +1,4 @@ -// Generated using Sourcery 0.16.1 — https://github.com/krzysztofzablocki/Sourcery +// Generated using Sourcery 0.18.0 — https://github.com/krzysztofzablocki/Sourcery // DO NOT EDIT @@ -63,7 +63,7 @@ @_exported import struct MongoSwift.FindOneAndUpdateOptions @_exported import struct MongoSwift.FindOneOptions @_exported import struct MongoSwift.FindOptions -@_exported import enum MongoSwift.FullDocument +@_exported import struct MongoSwift.FullDocument @_exported import enum MongoSwift.IndexHint @_exported import struct MongoSwift.IndexModel @_exported import struct MongoSwift.IndexOptions From c008df74411f9eec9217bd248b7116d03bb532f8 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 27 May 2020 14:23:42 -0400 Subject: [PATCH 2/2] fix: docs --- Examples/Docs/Sources/AsyncExamples/main.swift | 2 +- Sources/MongoSwift/ChangeStreamOptions.swift | 1 + Sources/MongoSwiftSync/Exports.swift | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Examples/Docs/Sources/AsyncExamples/main.swift b/Examples/Docs/Sources/AsyncExamples/main.swift index 132453ebf..6c114efe2 100644 --- a/Examples/Docs/Sources/AsyncExamples/main.swift +++ b/Examples/Docs/Sources/AsyncExamples/main.swift @@ -86,7 +86,7 @@ private func changeStreams() throws { let inventory = db.collection("inventory") // Option 1: use next() to iterate - let next = inventory.watch(options: ChangeStreamOptions(fullDocument: .other("blah"))) + let next = inventory.watch(options: ChangeStreamOptions(fullDocument: .updateLookup)) .flatMap { changeStream in changeStream.next() } diff --git a/Sources/MongoSwift/ChangeStreamOptions.swift b/Sources/MongoSwift/ChangeStreamOptions.swift index 5e2b8abec..52b6fc4d5 100644 --- a/Sources/MongoSwift/ChangeStreamOptions.swift +++ b/Sources/MongoSwift/ChangeStreamOptions.swift @@ -11,6 +11,7 @@ public struct FullDocument: RawRepresentable, Codable { public var rawValue: String + /// Creates a `FullDocument`. Never returns nil. public init?(rawValue: String) { self.rawValue = rawValue } internal init(_ value: String) { self.rawValue = value } } diff --git a/Sources/MongoSwiftSync/Exports.swift b/Sources/MongoSwiftSync/Exports.swift index 93f1e4f66..a90f0100c 100644 --- a/Sources/MongoSwiftSync/Exports.swift +++ b/Sources/MongoSwiftSync/Exports.swift @@ -1,4 +1,4 @@ -// Generated using Sourcery 0.18.0 — https://github.com/krzysztofzablocki/Sourcery +// Generated using Sourcery 0.16.1 — https://github.com/krzysztofzablocki/Sourcery // DO NOT EDIT