Skip to content

Commit

Permalink
0.9 (#108)
Browse files Browse the repository at this point in the history
* update deps

* simplify representation of network errors and remove some useless adapter types, fix a potential crash when resuming a CheckedThrowingContinuation more than once

* format and lint

* mark Mongo.NamespaceError as deprecated

* setup swiftformat

* format redundant return

* sort imports

* linebreak overlong doccoments

* migrate the MongoWire module to the Mongo namespace

* turn BSON.AnyType into its own type instead of overloading the namespace

* modernize BSONTests

* modernize BSONEncodingTests

* modernize BSONDecodingTests

* consolidate the various BSON modules under the BSON umbrella module

* rename BSON.Field -> BSON.FieldEncoder

* introduce the better-typed Mongo.InsertEncoder, Mongo.UpdateEncoder, and Mongo.DeleteEncoder types

* add a typed encoding API to Mongo.InsertEncoder

* add PAT to MongoMasterCodingModel

* upgrade dep requirements

* modernize the last test (OnlineCDFTests)

* fix most of the documentation warnings

* curate the BSONABI types
  • Loading branch information
tayloraswift authored Dec 10, 2023
1 parent 7c07cf7 commit 7b75d55
Show file tree
Hide file tree
Showing 432 changed files with 4,802 additions and 4,424 deletions.
4 changes: 4 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--rules braces,redundantSelf,duplicateImports,linebreakAtEndOfFile,redundantReturn,sortImports
--swiftversion 5.9.1
--allman true
--self insert
16 changes: 8 additions & 8 deletions Benchmarks/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "6c89474e62719ddcc1e9614989fff2f68208fe10",
"version" : "1.1.0"
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
"revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307",
"version" : "1.0.5"
}
},
{
Expand Down Expand Up @@ -95,17 +95,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "2d8e6ca36fe3e8ed74b0883f593757a45463c34d",
"version" : "2.53.0"
"revision" : "702cd7c56d5d44eeba73fdf83918339b26dc855c",
"version" : "2.62.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "e866a626e105042a6a72a870c88b4c531ba05f83",
"version" : "2.24.0"
"revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9",
"version" : "2.25.0"
}
},
{
Expand Down
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tayloraswift/swift-grammar",
"state" : {
"revision" : "163ce5d4d88db7d94f2f4ca1cabcb2ae65af8af7",
"version" : "0.3.3"
"revision" : "6db3dd8912fc7acb821021cd96677b2e0eeb09f0",
"version" : "0.3.4"
}
},
{
Expand All @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "3db5c4aeee8100d2db6f1eaf3864afdad5dc68fd",
"version" : "2.59.0"
"revision" : "702cd7c56d5d44eeba73fdf83918339b26dc855c",
"version" : "2.62.0"
}
},
{
Expand Down
90 changes: 45 additions & 45 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package:Package = .init(name: "swift-mongodb",
.library(name: "BSONDecoding", targets: ["BSONDecoding"]),
.library(name: "BSONEncoding", targets: ["BSONEncoding"]),
.library(name: "BSONTesting", targets: ["BSONTesting"]),
.library(name: "BSONTypes", targets: ["BSONTypes"]),
.library(name: "BSONABI", targets: ["BSONABI"]),

.library(name: "BSON_Durations", targets: ["BSON_Durations"]),
.library(name: "BSON_OrderedCollections", targets: ["BSON_OrderedCollections"]),
Expand All @@ -25,7 +25,6 @@ let package:Package = .init(name: "swift-mongodb",
.library(name: "Durations", targets: ["Durations"]),
.library(name: "Durations_Atomics", targets: ["Durations_Atomics"]),

.library(name: "Mongo", targets: ["Mongo"]),
.library(name: "MongoDB", targets: ["MongoDB"]),
.library(name: "MongoQL", targets: ["MongoQL"]),
.library(name: "MongoTesting", targets: ["MongoTesting"]),
Expand All @@ -36,7 +35,7 @@ let package:Package = .init(name: "swift-mongodb",
dependencies:
[
.package(url: "https://github.com/tayloraswift/swift-grammar", .upToNextMinor(
from: "0.3.2")),
from: "0.3.4")),
.package(url: "https://github.com/tayloraswift/swift-hash", .upToNextMinor(
from: "0.5.0")),

Expand All @@ -47,7 +46,7 @@ let package:Package = .init(name: "swift-mongodb",

/// swift-nio has a low rate of breakage, and can be trusted with a major-only
/// version requirement.
.package(url: "https://github.com/apple/swift-nio.git", from: "2.59.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.62.0"),
/// swift-nio-ssl has a low rate of breakage, and can be trusted with a
/// major-only version requirement.
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.25.0"),
Expand All @@ -63,21 +62,39 @@ let package:Package = .init(name: "swift-mongodb",
.target(name: "BSON",
dependencies:
[
.target(name: "BSONStreaming"),
.target(name: "BSONDecoding"),
.target(name: "BSONEncoding"),
],
exclude:
[
"README.md",
]),

.target(name: "BSONTraversal"),
.target(name: "BSONABI",
exclude:
[
"README.md",
]),

.target(name: "BSONTypes",
.target(name: "BSONDecoding",
dependencies:
[
.target(name: "BSONTraversal"),
.target(name: "BSONABI"),
.product(name: "TraceableErrors", package: "swift-grammar"),
],
exclude:
[
"README.md",
]),

.target(name: "BSONStreaming",
.target(name: "BSONEncoding",
dependencies:
[
.target(name: "BSONTypes"),
.target(name: "BSONABI"),
],
exclude:
[
"README.md",
]),


Expand All @@ -87,48 +104,31 @@ let package:Package = .init(name: "swift-mongodb",
.target(name: "BSON"),
]),

.target(name: "BSONDecoding",
dependencies:
[
.target(name: "BSON"),
.product(name: "TraceableErrors", package: "swift-grammar"),
]),

.target(name: "BSONEncoding",
dependencies:
[
.target(name: "BSON"),
]),

.target(name: "BSONTesting",
dependencies:
[
.target(name: "BSONEncoding"),
.target(name: "BSONDecoding"),
.target(name: "BSON"),
.product(name: "Testing", package: "swift-grammar"),
]),

.target(name: "BSON_UUID",
dependencies:
[
.target(name: "BSONDecoding"),
.target(name: "BSONEncoding"),
.target(name: "BSON"),
.target(name: "UUID"),
]),

.target(name: "BSON_Durations",
dependencies:
[
.target(name: "BSONDecoding"),
.target(name: "BSONEncoding"),
.target(name: "BSON"),
.target(name: "Durations"),
]),

.target(name: "BSON_OrderedCollections",
dependencies:
[
.target(name: "BSONDecoding"),
.target(name: "BSONEncoding"),
.target(name: "BSON"),
.product(name: "OrderedCollections", package: "swift-collections"),
]),

Expand Down Expand Up @@ -166,17 +166,23 @@ let package:Package = .init(name: "swift-mongodb",

.target(name: "Mongo"),

.target(name: "MongoABI",
dependencies:
[
.target(name: "BSON"),
.target(name: "Mongo"),
]),

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

.target(name: "MongoClusters",
dependencies:
[
.target(name: "BSONDecoding"),
.target(name: "BSONEncoding"),
.target(name: "BSON"),
.target(name: "Durations"),
.target(name: "Mongo"),
.product(name: "TraceableErrors", package: "swift-grammar"),
Expand All @@ -186,7 +192,7 @@ let package:Package = .init(name: "swift-mongodb",
dependencies:
[
.target(name: "MongoClusters"),
.target(name: "MongoSchema"),
.target(name: "MongoABI"),
.product(name: "NIOCore", package: "swift-nio"),
]),

Expand All @@ -197,6 +203,7 @@ let package:Package = .init(name: "swift-mongodb",
.target(name: "BSON_OrderedCollections"),
.target(name: "BSON_UUID"),
.target(name: "Durations_Atomics"),
.target(name: "MongoABI"),
.target(name: "MongoConfiguration"),
.target(name: "MongoExecutor"),
.target(name: "OnlineCDF"),
Expand All @@ -216,6 +223,7 @@ let package:Package = .init(name: "swift-mongodb",
.target(name: "MongoIO",
dependencies:
[
.target(name: "Mongo"),
.target(name: "MongoWire"),
.product(name: "NIOCore", package: "swift-nio"),
]),
Expand All @@ -228,14 +236,6 @@ let package:Package = .init(name: "swift-mongodb",
.target(name: "MongoQL"),
]),

.target(name: "MongoSchema",
dependencies:
[
.target(name: "BSONDecoding"),
.target(name: "BSONEncoding"),
.target(name: "Mongo"),
]),

.target(name: "MongoTesting",
dependencies:
[
Expand All @@ -249,6 +249,7 @@ let package:Package = .init(name: "swift-mongodb",
dependencies:
[
.target(name: "BSON"),
.target(name: "Mongo"),
.product(name: "CRC", package: "swift-hash"),
]),

Expand Down Expand Up @@ -277,9 +278,8 @@ let package:Package = .init(name: "swift-mongodb",
.executableTarget(name: "BSONIntegrationTests",
dependencies:
[
.target(name: "BSON"),
.target(name: "BSONReflection"),
.target(name: "BSONDecoding"),
.target(name: "BSONEncoding"),
.product(name: "Testing", package: "swift-grammar"),
]),

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

***`mongodb`***<br>`0.8`
***`mongodb`***<br>`0.9`

[![ci status](https://github.com/tayloraswift/swift-mongodb/actions/workflows/build.yml/badge.svg)](https://github.com/tayloraswift/swift-mongodb/actions/workflows/build.yml)

Expand Down
9 changes: 9 additions & 0 deletions Sources/BSON/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ``/BSON``

An umbrella module providing a BSON parser, encoder, and decoder.

## Linking the BSON libraries

This module re-exports the ``BSONABI``, ``BSONEncoding``, and ``BSONDecoding`` modules. Importing them directly is discouraged.

Some BSON modules (currently ``BSONReflection`` and ``BSONTesting``) are considered ancillary and are not included in this umbrella module.
5 changes: 3 additions & 2 deletions Sources/BSON/exports.swift
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@_exported import BSONStreaming
@_exported import BSONTypes
@_exported import BSONABI
@_exported import BSONDecoding
@_exported import BSONEncoding
63 changes: 36 additions & 27 deletions Sources/BSONTypes/BSON.swift → Sources/BSONABI/BSON.AnyType.swift
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
/// A BSON metatype. This enumeration also serves as a namespace for all
/// other types in this module. The raw value of this enumeration is the
/// type code of the associated case in BSON’s ABI.
@frozen public
enum BSON:UInt8
extension BSON
{
case double = 0x01
case string = 0x02
case document = 0x03
case list = 0x04
case binary = 0x05

case id = 0x07
case bool = 0x08
case millisecond = 0x09
case null = 0x0A
case regex = 0x0B
case pointer = 0x0C
case javascript = 0x0D
/// A BSON metatype. The raw value of this enumeration is the type code of the associated
/// case in BSON’s ABI.
@frozen public
enum AnyType:UInt8, Equatable, Hashable, Sendable
{
case double = 0x01
case string = 0x02
case document = 0x03
case list = 0x04
case binary = 0x05

case javascriptScope = 0x0F
case int32 = 0x10
case uint64 = 0x11
case int64 = 0x12
case decimal128 = 0x13
case id = 0x07
case bool = 0x08
case millisecond = 0x09
case null = 0x0A
case regex = 0x0B
case pointer = 0x0C
case javascript = 0x0D

case min = 0xFF
case max = 0x7F
case javascriptScope = 0x0F
case int32 = 0x10
case uint64 = 0x11
case int64 = 0x12
case decimal128 = 0x13

case min = 0xFF
case max = 0x7F
}
}
extension BSON.AnyType
{
/// Calls ``init(rawValue:)``, but throws a ``TypeError`` instead of returning
/// [`nil`]().
/// nil.
@inlinable public
init(code:UInt8) throws
{
Expand All @@ -38,7 +42,7 @@ enum BSON:UInt8
}
else
{
throw TypeError.init(invalid: code)
throw BSON.TypeError.init(invalid: code)
}
}
/// Converts the given type code to a variant type. This function will canonicalize
Expand Down Expand Up @@ -75,3 +79,8 @@ enum BSON:UInt8
}
}
}
extension BSON.AnyType:Comparable
{
@inlinable public
static func < (a:Self, b:Self) -> Bool { a.rawValue < b.rawValue }
}
Loading

0 comments on commit 7b75d55

Please sign in to comment.