diff --git a/Package.resolved b/Package.resolved index 14532fc..da42549 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "c3e65bcdf275cab11159accb0efc9ac649418a02d521281bfe32fd24dd5884b0", + "originHash" : "69fb22e4ec8d46b7c22e5440a27556e8796a96b3d7617e8b91d8981bd71bea42", "pins" : [ { "identity" : "swift-atomics", @@ -15,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tayloraswift/swift-bson", "state" : { - "revision" : "0fa36cdaa0daa71d198cd0e0787959b664c098a2", - "version" : "0.3.1" + "revision" : "32814c943ab68fa50c01cc52fb8640a8f55cb3cd", + "version" : "0.4.0" } }, { diff --git a/Package.swift b/Package.swift index b851cc3..1cb4ba7 100644 --- a/Package.swift +++ b/Package.swift @@ -15,7 +15,7 @@ let package:Package = .init(name: "swift-mongodb", ], dependencies: [ .package(url: "https://github.com/tayloraswift/swift-bson", .upToNextMinor( - from: "0.3.0")), + from: "0.4.0")), .package(url: "https://github.com/tayloraswift/swift-grammar", .upToNextMinor( from: "0.4.0")), .package(url: "https://github.com/tayloraswift/swift-hash", .upToNextMinor( @@ -34,6 +34,12 @@ let package:Package = .init(name: "swift-mongodb", from: "2.28.0"), ], targets: [ + .target(name: "BSON_OrderedCollections", + dependencies: [ + .product(name: "BSON", package: "swift-bson"), + .product(name: "OrderedCollections", package: "swift-collections"), + ]), + .target(name: "OnlineCDF"), .target(name: "SCRAM", @@ -84,13 +90,13 @@ let package:Package = .init(name: "swift-mongodb", .target(name: "MongoDriver", dependencies: [ + .target(name: "BSON_OrderedCollections"), .target(name: "MongoCommands"), .target(name: "MongoConfiguration"), .target(name: "MongoExecutor"), .target(name: "MongoLogging"), .target(name: "SCRAM"), .target(name: "UnixTime_Atomics"), - .product(name: "BSON_OrderedCollections", package: "swift-bson"), .product(name: "BSON_UUID", package: "swift-bson"), .product(name: "Atomics", package: "swift-atomics"), .product(name: "SHA2", package: "swift-hash"), @@ -118,11 +124,11 @@ let package:Package = .init(name: "swift-mongodb", .target(name: "MongoQL", dependencies: [ + .target(name: "BSON_OrderedCollections"), .target(name: "MongoBuiltins"), .target(name: "MongoCommands"), .product(name: "BSON", package: "swift-bson"), .product(name: "BSONReflection", package: "swift-bson"), - .product(name: "BSON_OrderedCollections", package: "swift-bson"), .product(name: "BSON_UUID", package: "swift-bson"), ]), diff --git a/Sources/BSON_OrderedCollections/OrderedDictionary (ext).swift b/Sources/BSON_OrderedCollections/OrderedDictionary (ext).swift new file mode 100644 index 0000000..8439c33 --- /dev/null +++ b/Sources/BSON_OrderedCollections/OrderedDictionary (ext).swift @@ -0,0 +1,39 @@ +import BSON +import OrderedCollections + +extension OrderedDictionary:@retroactive BSONDecodable + where Key == BSON.Key, Value:BSONDecodable +{ + @inlinable public + init(bson:BSON.AnyValue) throws + { + try self.init(bson: try .init(bson: consume bson)) + } + @inlinable public + init(bson:BSON.Document) throws + { + self.init() + try bson.parse + { + (field:BSON.FieldDecoder) in + + if case _? = self.updateValue(try field.decode(to: Value.self), + forKey: field.key) + { + throw BSON.DocumentKeyError.duplicate(field.key) + } + } + } +} +extension OrderedDictionary:@retroactive BSONDocumentEncodable, @retroactive BSONEncodable + where Key == BSON.Key, Value:BSONEncodable +{ + @inlinable public + func encode(to bson:inout BSON.DocumentEncoder) + { + for (key, value):(Key, Value) in self.elements + { + bson[key] = value + } + } +}