Skip to content

Commit

Permalink
fix: concurrency warnings pre swift 6 support (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev authored Jun 28, 2024
1 parent 6588f13 commit bee6fa7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 32 deletions.
16 changes: 2 additions & 14 deletions Sources/Auth/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,13 @@ import Foundation
import Helpers

extension AuthClient.Configuration {
private static let dateFormatterWithFractionalSeconds = { () -> ISO8601DateFormatter in
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
return formatter
}()

private static let dateFormatter = { () -> ISO8601DateFormatter in
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime]
return formatter
}()

/// The default JSONEncoder instance used by the ``AuthClient``.
public static let jsonEncoder: JSONEncoder = {
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
encoder.dateEncodingStrategy = .custom { date, encoder in
var container = encoder.singleValueContainer()
let string = dateFormatterWithFractionalSeconds.string(from: date)
let string = DateFormatter.iso8601.string(from: date)
try container.encode(string)
}
return encoder
Expand All @@ -41,7 +29,7 @@ extension AuthClient.Configuration {
let container = try decoder.singleValueContainer()
let string = try container.decode(String.self)

let supportedFormatters = [dateFormatterWithFractionalSeconds, dateFormatter]
let supportedFormatters: [DateFormatter] = [.iso8601, .iso8601_noMilliseconds]

for formatter in supportedFormatters {
if let date = formatter.date(from: string) {
Expand Down
8 changes: 1 addition & 7 deletions Sources/Helpers/SupabaseLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public struct SupabaseLogMessage: Codable, CustomStringConvertible, Sendable {
}

public var description: String {
let date = iso8601Formatter.string(from: Date(timeIntervalSince1970: timestamp))
let date = DateFormatter.iso8601_noMilliseconds.string(from: Date(timeIntervalSince1970: timestamp))
let file = fileID.split(separator: ".", maxSplits: 1).first.map(String.init) ?? fileID
var description = "\(date) [\(level)] [\(system)] [\(file).\(function):\(line)] \(message)"
if !additionalContext.isEmpty {
Expand All @@ -65,12 +65,6 @@ public struct SupabaseLogMessage: Codable, CustomStringConvertible, Sendable {
}
}

private let iso8601Formatter: ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime]
return formatter
}()

public protocol SupabaseLogger: Sendable {
func log(message: SupabaseLogMessage)
}
Expand Down
14 changes: 3 additions & 11 deletions Sources/PostgREST/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,9 @@ import Helpers
let version = Helpers.version

extension PostgrestClient.Configuration {
private static let supportedDateFormatters: [ISO8601DateFormatter] = [
{ () -> ISO8601DateFormatter in
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
return formatter
}(),
{ () -> ISO8601DateFormatter in
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime]
return formatter
}(),
private static let supportedDateFormatters: [DateFormatter] = [
.iso8601,
.iso8601_noMilliseconds,
]

/// The default `JSONDecoder` instance for ``PostgrestClient`` responses.
Expand Down

0 comments on commit bee6fa7

Please sign in to comment.