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, Swift on Server released a new version of async-http-client that includes a new implementation of the client singleton. Now it's HTTPClient.shared, so I've updated the CouchDB library to adopt that change. This also means that you no longer need to call httpClient.syncShutdown() if the singleton is used. Additionally, they've bumped the minimum Swift version to 5.8 (which I aslo did in version 1.4.0 of the CouchDB client library). So, I'm keeping the library up to date.
Changelog:
- Bumped the minimum version of async-http-client to the new 1.21.0. If you can't use it in your project, you can still stay on 1.4.0.
- The library will now 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 commentsSwift CouchDB client 1.4.0
A new version of CouchDB Client has been released:
- The library migrated from HTTPClient.Response to HTTPClientResponse, which is similar to HTTPClient.Response but used for the Swift Concurrency API. It also migrated from HTTPClient.Body to HTTPClientRequest.Body. These changes impact the get and find methods. Old methods are marked as deprecated, please refer to the documentation for the updated methods.
- The minimum Swift version is now 5.8.
- The CouchDBRepresentable protocol is now marked as Codable.
-
Additionally, a new data model called RowsResponse has been added. It accepts a generic CouchDBRepresentable type, making it easier to retrieve rows from a database. For example:
let decodeResponse = try JSONDecoder().decode(RowsResponse<MyApp>.self, from: data)
- Lastly, there have been small improvements in the documentation and tutorials.
CouchDB Client on GitHub | Documentation with examples and tutorials.
comment commentsA middleware for Vapor 4 routing to trim a slash in url path
It’s a common thing for a website or a backend to allow URLs like mySite.com/webpage and mySite.Com/webpage/ for the same page. These pages are different URLs for a search engine. If you want to avoid duplicates, you can add a simple middleware to trim the ending slash and redirect a user.
Here’s an example code for such a middleware class for Vapor 4:
final class TrimSlashInPathMiddleware: Middleware {
func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
if request.url.path.count > 1, request.url.path.hasSuffix("/") {
let newPath = String(request.url.path.trimmingSuffix(while: { $0 == "/" }))
let response = request.redirect(to: newPath, redirectType: .permanent)
return request.eventLoop.makeSucceededFuture(response)
}
return next.respond(to: request)
}
}
Just add it to configure.swift file:
import Vapor
public func configure(_ app: Application) throws {
app.middleware.use(TrimSlashInPathMiddleware())
app.http.server.configuration.port = 8081
try routes(app)
}
Works with Vapor 4.92.5.
comment commentsМодульбанк информер 1.3
Выпустил небольшое обновление для Модульбанк инфомера. Обновил иконку в статусбаре (тепер узнаваемая), и добавил чекбокс для скрытия счетов с нулевым балансом. Ну и немного рефакторинга.
Исходный код на GitHub: https://github.com/makoni/ModulbankInformer
Скачать можно тут: https://github.com/makoni/ModulbankInformer/releases
How to get selected text inside of TextEditor in SwiftUI on macOS
TextEditor in SwiftUI still doesn’t have any API to get user selection. But since it’s using NSTextView internally we can subscribe to its notifications.
Here’s an example of getting a substring from user selection:
comment commentsSwift CouchDB client 1.3.2
Recently, there have been a couple of new releases for my Swift CouchDB library. Here are the recent changes:
- dateDecodingStrategy and dateEncodingStrategy can now be passed as parameters for get, update and insert methods.
- Added a check to handle expired authentication cookies.
- Comparing the set-cookie header in the response as lowercased.
- Introduced new methods to utilize the _find API, allowing you to find documents using a declarative JSON querying syntax
- Fixed an issue where the update method didn’t use dateEncodingStrategy parameter.
CouchDB Client on GitHub | Documentation with examples and tutorials.
comment commentsAppMetric 1.8
Обновил AppMetric для macOS - клиент для сервиса AppMetrica от Яндекса. Предыдущая версия, увы, уже перестала работать, т.к. они изменили формат ответа.
Судя по дошедшей до меня информации, я использовал что-то незадокументированное из их ответа. И, судя по текущим ответам их API - это было количество крэшей. Увы, пришлось выпилить и заменить на количество устройств.
Решил, что раз уж руки дошли, надо осовременить. Переделал всё на SwiftUI, но пришлось сам попап обернуть в старый добрый NSPopover, т.к. MenuBarExtra из SwiftUI уж больно ограничен. Может быть, дойдут руки написать пост об этом. Заодно перевёл всё на Swift Concurrency и графику из SF Symbols. Правда, теперь всё это работает на macOS 13+, но, думаю, те, кому оно полезно, обновляют макось тоже. Ну и, естственно, наконец-то нативная работа на Apple Silicon.
Обновление сегодня прошло ревью и доступно для скачивания. Планирую в будущем добавить всё-таки графики по дням/неделям.
comment comments