Arm1.ru

Tag: «swift package»

Swift CouchDB client 1.5.0

Swift CouchDB client 1.5.0

And here we go, one more new version of the CouchDB client library. After the recent post about 1.4.0 the Swift on Server released a new version of async-http-client that has a new implementation of the client singleton. Now it's HTTPClient.shared, so I've updated the CouchDB library to adopt that. That also requires not to call httpClient.syncShutdown() if the singleton is used. Also they've bumped the minimum Swift version to 5.8 (I did the same in 1.4.0 for the CouchDB client library). So keeping the library up to date.

Changelog:

  • Bumped async-http-client minimum version to the new 1.21.0. If you can't use it in your project you can stay on 1.4.0.
  • The library will use HTTPClient.shared (new in async-http-client 1.21.0) internally for requests if no EventLoopGroup is provided.
  • No more internal calls for httpClient.syncShutdown() in case of HTTPClient.shared usage.

CouchDB Client on GitHub | Documentation with examples and tutorials.

comment comments

Swift CouchDB client 1.4.0

Swift CouchDB client

A new CouchDB Client version has been released:

  • The library migrated from HTTPClient.Response to HTTPClientResponse which is similar to HTTPClient.Response, but used for the Swift Concurrency API. Also it migrated from HTTPClient.Body to HTTPClientRequest.Body. These changes affect get and find methods. Old methods are marked as deprecated, check the docs for the updated methods.
  • Minimum Swift version is 5.8 now.
  • CouchDBRepresentable protocol is now marked as Codable.
  • Added a new RowsResponse data model that accepts a generic CouchDBRepresentable type which makes it easier to get rows from a database. Example:
    class="swift">let decodeResponse = try JSONDecoder().decode(RowsResponse<MyApp>.self, from: data)
  • Small improvements in the documentation and tutorials.

CouchDB Client on GitHub | Documentation with examples and tutorials.

comment comments

Swift CouchDB client 1.3.2

Swift CouchDB client

Recently there was a couple new releases of my Swift CouchDB library. Recent changes:

  • dateDecodingStrategy and dateEncodingStrategy can be passed as a param for get/update/insert methods.
  • Added a check if auth cookie expired.
  • Comparing set-cookie as lowercased in the response header.
  • Added new methods to use _find API method that allows to find documents using a declarative JSON querying syntax
  • Fixed when update method didn’t use dateEncodingStrategy param.

CouchDB Client on GitHub | Documentation with examples and tutorials.

comment comments

Swift CouchDB client 1.2.1

Swift CouchDB client 1.2.1

Just a small update for Swift CouchDB client lib with couple new methods that I needed by myself:

  • Added a new method to create a database [docs].
  • Added a new method to delete a database [docs].
  • Added a new method to check if a database exists [docs].
  • Every request handles unauthorised errors now.
  • CouchDBClientError model has a description text now.

CouchDB Client on GitHub | Documentation with examples and tutorials.

comment comments

Swift CouchDB client 1.2.0

Swift CouchDB client 1.2.0

Couple months ago I started learning Apple's DocC tool that generates documentation from your source code. I've decided to use as many features as possible so I took my small lib CouchDB Client and added docs to every method including usage examples that Xcode will show in the autocomplete popup. As it often happens, during adding docs and examples I found that many things in the library can be done in a much better way. So I've updated existing methods and added some more that can take a doc as a param and use generic types.

Next step was tutorials. Apple allows devs to create exactly the same tutorials as they have for SwiftUI on their own website. So I've added a couple. They're also part of the repo on GitHub.

Pretty sure that I've spent more time on the documentation than on the lib itself but I hope it's worth it.

CouchDB Client on GitHub | Documentation with examples and tutorials.

comment comments

Swift CouchDB client 1.0.0

Swift CouchDB client library

Finished new version of Swift CouchDB client. Now it's using only async-http-client as a dependency to make http/https requests. Can be used with Vapor 4.

Available on Github: https://github.com/makoni/couchdb-vapor

comment comments

Syntax sugar for JSON parsing in Swift

JSON decoding and encoding became easy after adding Codable protocol in Swift 4.0. But during coding I wanted to have something shorter and more elegant than Do-Catch statement that looks like this:

var myModel: MyModel?
let decoder = JSONDecoder()

do {
    myModel = try decoder.decode(MyModel.self, from: data)
} catch {
    print(error.localizedDescription)
}

Or like this:

let myModel: MyModel? = try? decoder.decode(MyModel.self, from: data)

So I wrote a protocol with default implementation that allows to do decoding just like that:

let myModel = MyModel.decodeFromData(data: data)

And the same for encoding:

let data = MyModel.encode(fromEncodable: myModel)

All you need is just to add protocol conformance:

extension MyModel: Parseable {
    typealias ParseableType = Self
}

It's available on GitHub as a Swift Package: https://github.com/makoni/parsable

comment comments