Skip to content

Commit

Permalink
Merge pull request #111 from tayloraswift/0.10.0
Browse files Browse the repository at this point in the history
0.10.0
  • Loading branch information
tayloraswift authored Dec 27, 2023
2 parents 1bd5663 + 198f320 commit b448b6b
Show file tree
Hide file tree
Showing 254 changed files with 1,066 additions and 970 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307",
"version" : "1.0.5"
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192",
"version" : "1.0.6"
}
},
{
Expand Down
40 changes: 21 additions & 19 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ let package:Package = .init(name: "swift-mongodb",
[
.library(name: "BSON", targets: ["BSON"]),
.library(name: "BSONReflection", targets: ["BSONReflection"]),
.library(name: "BSONDecoding", targets: ["BSONDecoding"]),
.library(name: "BSONEncoding", targets: ["BSONEncoding"]),
.library(name: "BSONTesting", targets: ["BSONTesting"]),
.library(name: "BSONABI", targets: ["BSONABI"]),

Expand Down Expand Up @@ -151,19 +149,6 @@ let package:Package = .init(name: "swift-mongodb",
]),


.target(name: "MongoDB",
dependencies:
[
.target(name: "MongoLibrary"),
]),

.target(name: "MongoQL",
dependencies:
[
.target(name: "MongoBuiltins"),
]),


.target(name: "Mongo"),

.target(name: "MongoABI",
Expand All @@ -188,6 +173,13 @@ let package:Package = .init(name: "swift-mongodb",
.product(name: "TraceableErrors", package: "swift-grammar"),
]),

.target(name: "MongoCommands",
dependencies:
[
.target(name: "Durations"),
.target(name: "MongoABI"),
]),

.target(name: "MongoConfiguration",
dependencies:
[
Expand All @@ -196,14 +188,21 @@ let package:Package = .init(name: "swift-mongodb",
.product(name: "NIOCore", package: "swift-nio"),
]),

.target(name: "MongoDB",
dependencies:
[
.target(name: "MongoQL"),
.target(name: "MongoDriver"),
]),

.target(name: "MongoDriver",
dependencies:
[
.target(name: "BSON_Durations"),
.target(name: "BSON_OrderedCollections"),
.target(name: "BSON_UUID"),
.target(name: "Durations_Atomics"),
.target(name: "MongoABI"),
.target(name: "MongoCommands"),
.target(name: "MongoConfiguration"),
.target(name: "MongoExecutor"),
.target(name: "OnlineCDF"),
Expand All @@ -228,14 +227,17 @@ let package:Package = .init(name: "swift-mongodb",
.product(name: "NIOCore", package: "swift-nio"),
]),

.target(name: "MongoLibrary",
.target(name: "MongoQL",
dependencies:
[
.target(name: "BSON"),
.target(name: "BSONReflection"),
.target(name: "MongoDriver"),
.target(name: "MongoQL"),
.target(name: "BSON_UUID"),
.target(name: "MongoBuiltins"),
.target(name: "MongoCommands"),
]),


.target(name: "MongoTesting",
dependencies:
[
Expand Down
14 changes: 12 additions & 2 deletions Sources/BSONABI/Views/BSON.DocumentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ extension BSON.DocumentView

extension BSON.DocumentView<[UInt8]>
{
/// Stores the output buffer of the given document into
/// an instance of this type.
/// Wraps the storage buffer of the given document into an instance of this type.
///
/// > Complexity: O(1).
@inlinable public
Expand All @@ -85,6 +84,17 @@ extension BSON.DocumentView<[UInt8]>
self.init(slice: document.bytes)
}
}
extension BSON.DocumentView<ArraySlice<UInt8>>
{
/// Wraps the **entire** storage buffer of the given document into an instance of this type.
///
/// > Complexity: O(1).
@inlinable public
init(_ document:BSON.Document)
{
self.init(slice: document.bytes[...])
}
}

extension BSON.DocumentView
{
Expand Down
14 changes: 12 additions & 2 deletions Sources/BSONABI/Views/BSON.ListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ extension BSON.ListView

extension BSON.ListView<[UInt8]>
{
/// Stores the output buffer of the given list into
/// an instance of this type.
/// Wraps the storage buffer of the given list into an instance of this type.
///
/// > Complexity: O(1).
@inlinable public
Expand All @@ -86,6 +85,17 @@ extension BSON.ListView<[UInt8]>
self.init(slice: list.bytes)
}
}
extension BSON.ListView<ArraySlice<UInt8>>
{
/// Wraps the **entire** storage buffer of the given list in an instance of this type.
///
/// > Complexity: O(1).
@inlinable public
init(_ list:BSON.List)
{
self.init(slice: list.bytes[...])
}
}

extension BSON.ListView
{
Expand Down
2 changes: 1 addition & 1 deletion Sources/BSONEncoding/Encoding/BSON.Document (ext).swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extension BSON.Document:BSONEncodable
@inlinable public
func encode(to field:inout BSON.FieldEncoder)
{
field.encode(document: .init(self))
field.encode(document: BSON.DocumentView<[UInt8]>.init(self))
}
}
extension BSON.Document
Expand Down
2 changes: 1 addition & 1 deletion Sources/BSONEncoding/Encoding/BSON.List (ext).swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ extension BSON.List:BSONEncodable
@inlinable public
func encode(to field:inout BSON.FieldEncoder)
{
field.encode(list: .init(self))
field.encode(list: BSON.ListView<[UInt8]>.init(self))
}
}
4 changes: 2 additions & 2 deletions Sources/BSONIntegrationTests/Main.EnumeratedCodingKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extension Main.EnumeratedCodingKeys:TestBattery

tests.do
{
let original:BSON.DocumentView = .init(bson)
let original:BSON.DocumentView<[UInt8]> = .init(bson)
let decoded:Codable = try .init(bson: original)

tests.expect(decoded ==? expected)
Expand All @@ -69,7 +69,7 @@ extension Main.EnumeratedCodingKeys:TestBattery

tests.expect(true: encoded.bytes.count < original.slice.count)

let redecoded:Codable = try .init(bson: .init(encoded))
let redecoded:Codable = try .init(bson: BSON.DocumentView<[UInt8]>.init(encoded))

tests.expect(redecoded ==? expected)

Expand Down
2 changes: 1 addition & 1 deletion Sources/BSONTesting/TestGroup (ext).swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension TestGroup
let encoded:BSON.Document = .init(encoding: codable)
let decoded:Codable? = self.do(function: function, file: file, line: line)
{
try .init(bson: .init(encoded))
try .init(bson: BSON.DocumentView<[UInt8]>.init(encoded))
}
if let decoded,
let self:TestGroup = self / "Comparison"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,3 @@ extension Mongo
case linearizable
}
}
extension Mongo.ReadConcern
{
var level:Level
{
.ratification(self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Mongo.WriteConcern
extension Mongo.WriteConcern.Acknowledgement
{
/// Same as ``votes(_:)``, but traps if the argument is zero or negative.
static
@inlinable internal static
func acknowledged(by votes:Int) -> Self
{
if 0 < votes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ extension Mongo
@frozen public
struct WriteConcern:Hashable, Sendable
{
public
let acknowledgement:Acknowledgement

public
let journaled:Bool?

private
@inlinable internal
init(acknowledgement:Acknowledgement, journaled:Bool? = nil)
{
self.acknowledgement = acknowledgement
Expand All @@ -23,20 +24,20 @@ extension Mongo.WriteConcern
{
.majority(journaled: nil)
}
public static

@inlinable public static
func majority(journaled:Bool?) -> Self
{
.init(acknowledgement: .mode("majority"), journaled: journaled)
}

public static
@inlinable public static
func custom(mode:String, journaled:Bool? = nil) -> Self
{
.init(acknowledgement: .mode(mode), journaled: journaled)
}

public static
@inlinable public static
func acknowledged(by votes:Int, journaled:Bool? = nil) -> Self
{
.init(acknowledgement: .acknowledged(by: votes), journaled: journaled)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import BSON
import MongoABI

extension Mongo.Cursor
extension Mongo
{
@frozen public
struct Batch:Sendable
struct CursorBatch<Element>:Sendable where Element:BSONDecodable & Sendable
{
public
let namespace:Mongo.Namespaced<Mongo.Collection>
public
let elements:[BatchElement]
let elements:[Element]
public
let position:Int64

@inlinable public
init(namespace:Mongo.Namespaced<Mongo.Collection>,
elements:[BatchElement],
elements:[Element],
position:Int64)
{
self.namespace = namespace
Expand All @@ -24,27 +24,26 @@ extension Mongo.Cursor
}
}
}
extension Mongo.Cursor.Batch:Equatable where BatchElement:Equatable
extension Mongo.CursorBatch:Equatable where Element:Equatable
{
}
extension Mongo.Cursor.Batch
extension Mongo.CursorBatch
{
@inlinable public
var id:Mongo.CursorIdentifier?
{
.init(rawValue: self.position)
}
}
extension Mongo.Cursor.Batch:BSONDecodable, BSONDocumentDecodable
extension Mongo.CursorBatch:BSONDecodable, BSONDocumentDecodable
{
@inlinable public
init<Bytes>(bson:BSON.DocumentDecoder<BSON.Key, Bytes>) throws
{
self = try bson["cursor"].decode()
{
.init(namespace: try $0["ns"].decode(to: Mongo.Namespaced<Mongo.Collection>.self),
elements: try ($0["firstBatch"] ?? $0["nextBatch"]).decode(
to: [BatchElement].self),
elements: try ($0["firstBatch"] ?? $0["nextBatch"]).decode(to: [Element].self),
position: try $0["id"].decode(to: Int64.self))
}
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/MongoCommands/Databases/Mongo.Database (ext).swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extension Mongo.Database:Mongo.DatabaseType
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ extension Mongo.Database
case admin
}
}
extension Mongo.Database.Admin:MongoCommandDatabase
extension Mongo.Database.Admin:Mongo.DatabaseType
{
@inlinable public
var name:String
{
"admin"
}
var name:String { "admin" }
}
16 changes: 16 additions & 0 deletions Sources/MongoCommands/Databases/Mongo.DatabaseType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extension Mongo
{
/// The type of database a ``Mongo.Command`` can be run against.
public
typealias DatabaseType = _MongoDatabaseType
}

@available(*, deprecated, renamed: "Mongo.DatabaseType")
public
typealias MongoCommandDatabase = Mongo.DatabaseType

public
protocol _MongoDatabaseType
{
var name:String { get }
}
Loading

0 comments on commit b448b6b

Please sign in to comment.