From 71abcd830b4a52618969c0f0c5e8fae667fa87c2 Mon Sep 17 00:00:00 2001 From: kenta okamura Date: Wed, 17 Jan 2024 21:19:48 +0900 Subject: [PATCH] Add options arg for custom coding --- Sources/D1Kit/D1Client.swift | 2 +- Sources/D1Kit/D1ParameterBindable.swift | 2 +- Sources/D1Kit/D1ParameterEncodingOptions.swift | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/D1Kit/D1Client.swift b/Sources/D1Kit/D1Client.swift index b6628b2..c75c27f 100644 --- a/Sources/D1Kit/D1Client.swift +++ b/Sources/D1Kit/D1Client.swift @@ -2,7 +2,7 @@ import Foundation import HTTPTypes public struct D1Client: Sendable { - public init(httpClient: HTTPClientProtocol, accountID: String, apiToken: String) { + public init(httpClient: any HTTPClientProtocol, accountID: String, apiToken: String) { precondition(accountID.isASCII) precondition(apiToken.isASCII) self.httpClient = httpClient diff --git a/Sources/D1Kit/D1ParameterBindable.swift b/Sources/D1Kit/D1ParameterBindable.swift index 7906a27..147c371 100644 --- a/Sources/D1Kit/D1ParameterBindable.swift +++ b/Sources/D1Kit/D1ParameterBindable.swift @@ -28,7 +28,7 @@ extension Date: D1ParameterBindable { case .formatted(let formatter): return formatter.string(from: self) case .custom(let custom): - return custom(self) + return custom(self, options) } } } diff --git a/Sources/D1Kit/D1ParameterEncodingOptions.swift b/Sources/D1Kit/D1ParameterEncodingOptions.swift index 452c533..f27ef2c 100644 --- a/Sources/D1Kit/D1ParameterEncodingOptions.swift +++ b/Sources/D1Kit/D1ParameterEncodingOptions.swift @@ -1,7 +1,7 @@ import Foundation public protocol D1ParameterEncodingOptionKey { - associatedtype Value + associatedtype Value: Sendable static var defaultValue: Self.Value { get } } @@ -30,7 +30,7 @@ public enum D1DateEncodingStrategy { case millisecondsSince1970 case iso8601 case formatted(DateFormatter) - @preconcurrency case custom(@Sendable (Date) -> String) + @preconcurrency case custom(@Sendable (Date, D1ParameterEncodingOptions) -> String) } public struct D1DateEncodingStrategyKey: D1ParameterEncodingOptionKey {