Skip to content

Commit 1f416b0

Browse files
makonigevartosky
andauthored
2.1.0 (#31)
* swift-docc-plugin 1.3.0 * async-http-client 1.19.0 * replaced deprecated .createNew with the new .singleton * Adding _find capability. (#13) * docs * tabs * renames * added test for find method with body * docs added * findError added * tests renamed * added test for find method with generic type * docs * README updated * updated dependencies * docs updated * try Swift 5.7.1 * Update build-ubuntu.yml * Swift 5.7.3 * Revert "Swift 5.7.3" This reverts commit ab8f67a. * updated dependencies * Docs updated * Delete .github/workflows/CodeQL.yml * dependencies updated * fixed when update method didn’t use passed dateEncodingStrategy * noData error added * migrating to new HTTPClientRequest from HTTPClient.Request wip * migrating to new HTTPClientRequest from HTTPClient.Request wip * migrating to new HTTPClientRequest from HTTPClient.Request wip * migrating to new HTTPClientRequest from HTTPClient.Request wip * migrating to new HTTPClientRequest from HTTPClient.Request wip * migrating to new HTTPClientRequest from HTTPClient.Request wip * … * migrating to new HTTPClientRequest from HTTPClient.Request wip * rename * tests updated * auth fixed * collect body bytes before returning response * param renamed to make keep backward compatibility with old methods * marking old find as deprecated * private * deprecated message * renames * moved deprecations * docs * docs * added Codable to CouchDBRepresentable protocol * added RowsResponse model * docs * Vapor tutorial updated * docs * docs and refactoring * docs and refactoring * Tutorials updated * docs * platforms list updated * minimum swift version 5.8 * workflow updated * Update build-ubuntu.yml * Update build-macos.yml * import NIOFoundationCompat to fix building on Ubuntu * using async-http-client from 1.21.0. Not calling http * Using HTTPClient.shared if eventLoopGroup not provided. No more calls httpClient.syncShutdown() if using shared singleton * docs updated * docs updated * Vapor tutorial updated * A SwiftUI tutorial * tutorial fixed * updated dependencies * Package.resolved * docs updated * userName param is now required for CouchDB init * cleanup * docs * docs * docs * docs * docs * docs * docs * docs * docs * docs * docs * docs * docs * docs * docs * docs * dependencices updated * updated swift-docc-plugin URL. Updated dependencies to latest versions. * Update build-ubuntu.yml * dependencies updated * deleted deprecated methods * Sendable conformance * swift-format added * formatting * formatting * revert sendable * updated dependencies * Sensable conformance * updated CouchDBRepresentable protocol * Sendable conformance * Strict concurrency implemented * Swift 6 * docs updated * errors and docs * docs * docs * docs wip * docs * wip * wip * docs * docs * get only _rev * tutorials updated * docs * Update README.md * Update README.md * updated GitHub actions configs * dependencies updated * updated docs * code formatting * refactoring * localized error messages * Added error messages translations * More translations * fixes for Linux * docs * create HTTPClient if not provided in init * new test added * use FoundationEssentials if possible * tests updated * dependencies updated * added shutdown method * formatting * added tutorial for Hummingbird * tutorials * tutorial * tutorials * docs * renamed couchdb-vapor to couchdb-swift * docs * try to use FoundationEssentials everywhere and Dispatch * removed FoundationEssentials usage, can’t use Bundle with it --------- Co-authored-by: Gregório Gevartosky Torrezan <[email protected]>
1 parent 7554fde commit 1f416b0

25 files changed

+980
-384
lines changed

Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "couchdb-vapor",
7+
name: "couchdb-swift",
88
defaultLocalization: "en",
99
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
1010
products: [

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# CouchDB Client for Swift
22

33
<p align="center">
4-
<a href="https://github.com/makoni/couchdb-vapor">
4+
<a href="https://github.com/makoni/couchdb-swift">
55
<img src="https://spaceinbox.me/images/appicons/5cff134d1bb4a2e90faea5cf4e0002a2.svg?31-a992eba6ad7e189f4b3e0988936056ca" height="200">
66
</a>
77
</p>
88

9-
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmakoni%2Fcouchdb-vapor%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/makoni/couchdb-vapor)
10-
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmakoni%2Fcouchdb-vapor%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/makoni/couchdb-vapor)
9+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmakoni%2Fcouchdb-swift%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/makoni/couchdb-swift)
10+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmakoni%2Fcouchdb-swift%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/makoni/couchdb-swift)
1111
[![Vapor 4](https://img.shields.io/badge/vapor-4-blue.svg?style=flat)](https://vapor.codes)
1212

13-
[![Build on macOS](https://github.com/makoni/couchdb-vapor/actions/workflows/build-macos.yml/badge.svg?branch=master)](https://github.com/makoni/couchdb-vapor/actions/workflows/build-macos.yml)
14-
[![Build on Ubuntu](https://github.com/makoni/couchdb-vapor/actions/workflows/build-ubuntu.yml/badge.svg?branch=master)](https://github.com/makoni/couchdb-vapor/actions/workflows/build-ubuntu.yml)
15-
[![Test on Ubuntu](https://github.com/makoni/couchdb-vapor/actions/workflows/test-ubuntu.yml/badge.svg?branch=master)](https://github.com/makoni/couchdb-vapor/actions/workflows/test-ubuntu.yml)
13+
[![Build on macOS](https://github.com/makoni/couchdb-swift/actions/workflows/build-macos.yml/badge.svg?branch=master)](https://github.com/makoni/couchdb-swift/actions/workflows/build-macos.yml)
14+
[![Build on Ubuntu](https://github.com/makoni/couchdb-swift/actions/workflows/build-ubuntu.yml/badge.svg?branch=master)](https://github.com/makoni/couchdb-swift/actions/workflows/build-ubuntu.yml)
15+
[![Test on Ubuntu](https://github.com/makoni/couchdb-swift/actions/workflows/test-ubuntu.yml/badge.svg?branch=master)](https://github.com/makoni/couchdb-swift/actions/workflows/test-ubuntu.yml)
1616

1717

1818

@@ -41,7 +41,7 @@ Add the following to the `dependencies` section of your `Package.swift`:
4141

4242
```swift
4343
dependencies: [
44-
.package(url: "https://github.com/makoni/couchdb-vapor.git", from: "1.6.0"),
44+
.package(url: "https://github.com/makoni/couchdb-swift.git", from: "1.6.0"),
4545
]
4646

4747
---

Sources/CouchDBClient/CouchDBClient.docc/CouchDBClient.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
11
# ``CouchDBClient``
22

3-
A simple CouchDB client written in Swift.
3+
A lightweight and powerful CouchDB client written in Swift.
44

55
## Overview
66

7-
Source code is available on [GitHub](https://github.com/makoni/couchdb-vapor).
7+
The source code is available on [GitHub](https://github.com/makoni/couchdb-swift).
88

9-
CouchDBClient allows you to make simple requests to CouchDB. It's using Swift Concurrency (async/await) and supports Linux, iOS 13+, iPadOS 13+, tvOS 13+, watchOS 6+, visionOS 1.0+ and macOS 10.15+.
9+
`CouchDBClient` simplifies interactions with CouchDB by providing an easy-to-use API built with Swift Concurrency (`async/await`). It supports a wide range of platforms, including:
1010

11-
It's using [AsyncHTTPClient](https://github.com/swift-server/async-http-client) which makes it easy to use CouchDBClient for server-side development with Vapor 4. But it's easy to use it with any iOS or macOS app. Check the Essentials section for examples.
11+
- **Linux**
12+
- **iOS 13+**
13+
- **iPadOS 13+**
14+
- **tvOS 13+**
15+
- **watchOS 6+**
16+
- **visionOS 1.0+**
17+
- **macOS 10.15+**
1218

13-
Currently CouchDBClient supports:
14-
- Check if DB exists.
15-
- Create DB.
16-
- Delete DB.
17-
- Get databases list.
18-
- Get a document by id or documents using a view.
19-
- Insert/update documents.
20-
- Find documents by selector.
21-
- Delete documents.
22-
- CouchDB authorization.
19+
Built on top of [AsyncHTTPClient](https://github.com/swift-server/async-http-client), `CouchDBClient` is ideal for server-side development with Vapor and Hummingbird but is equally suitable for iOS and macOS applications. Check the **Essentials** section for usage examples.
20+
21+
### Features
22+
23+
`CouchDBClient` currently supports the following operations:
24+
25+
- **Database Management**:
26+
- Check if a database exists.
27+
- Create a database.
28+
- Delete a database.
29+
- Retrieve a list of all databases.
30+
31+
- **Document Operations**:
32+
- Get a document by ID or retrieve documents using a view.
33+
- Insert or update documents.
34+
- Find documents using a selector.
35+
- Delete documents.
36+
37+
- **Authorization**:
38+
- Authenticate with CouchDB.
2339

2440
## Topics
2541

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
# ``CouchDBClient/CouchDBClient``
22

3-
CouchDB client.
3+
A powerful and flexible CouchDB client for Swift, designed to simplify database interactions using Swift Concurrency.
44

55
## Overview
66

7-
A CouchDB client class with methods using Swift Concurrency.
7+
`CouchDBClient` provides a robust set of tools for interacting with CouchDB databases. It supports common database operations such as creating, deleting, and querying databases and documents. Built with Swift Concurrency, it ensures efficient and modern asynchronous programming.
8+
9+
This client is fully compatible with SwiftNIO, making it ideal for both server-side and client-side Swift applications.
810

911
## Topics
1012

11-
### Initializer
12-
- ``init(config:)``
13-
14-
### Methods for databases
15-
- ``getAllDBs(eventLoopGroup:)``
16-
- ``createDB(_:eventLoopGroup:)``
17-
- ``deleteDB(_:eventLoopGroup:)``
18-
- ``dbExists(_:eventLoopGroup:)``
19-
20-
### Requests to a database
21-
- ``createDB(_:eventLoopGroup:)``
22-
- ``deleteDB(_:eventLoopGroup:)``
23-
- ``dbExists(_:eventLoopGroup:)``
24-
- ``get(fromDB:uri:queryItems:eventLoopGroup:)``
25-
- ``get(fromDB:uri:queryItems:dateDecodingStrategy:eventLoopGroup:)``
26-
- ``insert(dbName:body:eventLoopGroup:)``
27-
- ``insert(dbName:doc:dateEncodingStrategy:eventLoopGroup:)``
28-
- ``update(dbName:doc:dateEncodingStrategy:eventLoopGroup:)``
29-
- ``update(dbName:uri:body:eventLoopGroup:)``
30-
- ``find(inDB:body:eventLoopGroup:)``
31-
- ``find(inDB:selector:dateDecodingStrategy:eventLoopGroup:)``
32-
- ``delete(fromDb:doc:eventLoopGroup:)``
33-
- ``delete(fromDb:uri:rev:eventLoopGroup:)``
13+
### Initialization
14+
- ``init(config:httpClient:)``
15+
16+
### Database Management
17+
- ``getAllDBs(eventLoopGroup:)``
18+
- ``createDB(_:eventLoopGroup:)``
19+
- ``deleteDB(_:eventLoopGroup:)``
20+
- ``dbExists(_:eventLoopGroup:)``
21+
22+
### Document Operations
23+
- ``insert(dbName:body:eventLoopGroup:)``
24+
- ``insert(dbName:doc:dateEncodingStrategy:eventLoopGroup:)``
25+
- ``update(dbName:doc:dateEncodingStrategy:eventLoopGroup:)``
26+
- ``update(dbName:uri:body:eventLoopGroup:)``
27+
- ``delete(fromDb:doc:eventLoopGroup:)``
28+
- ``delete(fromDb:uri:rev:eventLoopGroup:)``
29+
30+
### Querying and Fetching
31+
- ``get(fromDB:uri:queryItems:eventLoopGroup:)``
32+
- ``get(fromDB:uri:queryItems:dateDecodingStrategy:eventLoopGroup:)``
33+
- ``find(inDB:body:eventLoopGroup:)``
34+
- ``find(inDB:selector:dateDecodingStrategy:eventLoopGroup:)``
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
@Tutorial(time: 3) {
2-
@Intro(title: "Handling CouchDB errors") {
3-
Use CouchDBClient in a macOS app
4-
5-
@Image(source: errors.svg, alt: "Application icon")
6-
}
7-
8-
@Section(title: "Catching errors") {
9-
@ContentAndMedia {
10-
Use CouchDBClient in a macOS app
11-
12-
@Image(source: errors.svg, alt: "Error icon")
13-
}
14-
15-
@Steps {
16-
@Step {
17-
`CouchDBClient` has an Error enum `CouchDBClientError`. Some enum values have nested errors of `CouchDBError` type that represent error messages from CouchDB.
18-
19-
@Code(name: "main.swift", file: ErrorsHandlingTutorial-1.swift)
20-
}
21-
22-
@Step {
23-
You can wrap your code in a do-catch block to catch a CouchDB error during insert operation.
24-
25-
@Code(name: "main.swift", file: ErrorsHandlingTutorial-2.swift)
26-
}
27-
28-
@Step {
29-
Same for updates to find out what's wrong.
30-
31-
@Code(name: "main.swift", file: ErrorsHandlingTutorial-3.swift)
32-
}
33-
34-
@Step {
35-
And same for a get operation. CouchDB will return an error message if the username or password is incorrect for example.
36-
37-
@Code(name: "main.swift", file: ErrorsHandlingTutorial-4.swift)
38-
}
39-
}
40-
}
2+
@Intro(title: "Handling CouchDB Errors") {
3+
Learn how to handle errors effectively when using `CouchDBClient` in your applications.
4+
5+
@Image(source: errors.svg, alt: "Error handling illustration")
6+
}
7+
8+
@Section(title: "Catching Errors") {
9+
@ContentAndMedia {
10+
`CouchDBClient` provides robust error handling mechanisms to help you debug and resolve issues efficiently.
11+
12+
@Image(source: errors.svg, alt: "Error icon")
13+
}
14+
15+
@Steps {
16+
@Step {
17+
The `CouchDBClient` library includes an error enum called `CouchDBClientError`. Some of its cases contain nested errors of type `CouchDBError`, which represent error messages returned by CouchDB.
18+
19+
@Code(name: "main.swift", file: ErrorsHandlingTutorial-1.swift)
20+
}
21+
22+
@Step {
23+
Wrap your code in a `do-catch` block to handle errors during an insert operation. This allows you to catch and process any errors that occur.
24+
25+
@Code(name: "main.swift", file: ErrorsHandlingTutorial-2.swift)
26+
}
27+
28+
@Step {
29+
Similarly, use a `do-catch` block for update operations to identify and resolve issues.
30+
31+
@Code(name: "main.swift", file: ErrorsHandlingTutorial-3.swift)
32+
}
33+
34+
@Step {
35+
You can also handle errors during a `get` operation. For example, CouchDB will return an error message if the username or password is incorrect.
36+
37+
@Code(name: "main.swift", file: ErrorsHandlingTutorial-4.swift)
38+
}
39+
}
40+
}
4141
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import Hummingbird
2+
import Logging
3+
4+
/// Application arguments protocol. We use a protocol so we can call
5+
/// `buildApplication` inside Tests as well as in the App executable.
6+
/// Any variables added here also have to be added to `App` in App.swift and
7+
/// `TestArguments` in AppTest.swift
8+
public protocol AppArguments {
9+
var hostname: String { get }
10+
var port: Int { get }
11+
var logLevel: Logger.Level? { get }
12+
}
13+
14+
/// Build application
15+
/// - Parameter arguments: application arguments
16+
public func buildApplication(_ arguments: some AppArguments) async throws -> some ApplicationProtocol {
17+
let environment = Environment()
18+
let logger = {
19+
var logger = Logger(label: "HBTest")
20+
logger.logLevel =
21+
arguments.logLevel ?? environment.get("LOG_LEVEL").flatMap { Logger.Level(rawValue: $0) } ?? .info
22+
return logger
23+
}()
24+
let router = buildRouter()
25+
26+
let app = Application(
27+
router: router,
28+
configuration: .init(
29+
address: .hostname(arguments.hostname, port: arguments.port),
30+
serverName: "HBTest"
31+
),
32+
services: [],
33+
logger: logger
34+
)
35+
return app
36+
}
37+
38+
// Request context used by application
39+
typealias AppRequestContext = BasicRequestContext
40+
41+
/// Build router
42+
func buildRouter() -> Router<AppRequestContext> {
43+
let router = Router(context: AppRequestContext.self)
44+
// Add middleware
45+
router.addMiddleware {
46+
// logging middleware
47+
LogRequestsMiddleware(.info)
48+
}
49+
// Add default endpoint
50+
router.get("/") { _, _ in
51+
return "Hello!"
52+
}
53+
return router
54+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import Hummingbird
2+
import Logging
3+
import ServiceLifecycle
4+
import CouchDBClient
5+
6+
/// Application arguments protocol. We use a protocol so we can call
7+
/// `buildApplication` inside Tests as well as in the App executable.
8+
/// Any variables added here also have to be added to `App` in App.swift and
9+
/// `TestArguments` in AppTest.swift
10+
public protocol AppArguments {
11+
var hostname: String { get }
12+
var port: Int { get }
13+
var logLevel: Logger.Level? { get }
14+
}
15+
16+
/// Build application
17+
/// - Parameter arguments: application arguments
18+
public func buildApplication(_ arguments: some AppArguments) async throws -> some ApplicationProtocol {
19+
let environment = Environment()
20+
let logger = {
21+
var logger = Logger(label: "HBTest")
22+
logger.logLevel =
23+
arguments.logLevel ?? environment.get("LOG_LEVEL").flatMap { Logger.Level(rawValue: $0) } ?? .info
24+
return logger
25+
}()
26+
let router = buildRouter()
27+
28+
let app = Application(
29+
router: router,
30+
configuration: .init(
31+
address: .hostname(arguments.hostname, port: arguments.port),
32+
serverName: "HBTest"
33+
),
34+
services: [],
35+
logger: logger
36+
)
37+
return app
38+
}
39+
40+
// Request context used by application
41+
typealias AppRequestContext = BasicRequestContext
42+
43+
/// Build router
44+
func buildRouter() -> Router<AppRequestContext> {
45+
let router = Router(context: AppRequestContext.self)
46+
// Add middleware
47+
router.addMiddleware {
48+
// logging middleware
49+
LogRequestsMiddleware(.info)
50+
}
51+
// Add default endpoint
52+
router.get("/") { _, _ in
53+
return "Hello!"
54+
}
55+
return router
56+
}

0 commit comments

Comments
 (0)