Skip to content

Commit

Permalink
ci: use Xcode 15.2
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Jan 20, 2024
1 parent c883682 commit 4e0d91f
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 92 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
name: Test Library (Darwin)
steps:
- uses: actions/checkout@v3
- name: Select Xcode 15.1
run: sudo xcode-select -s /Applications/Xcode_15.1.app
- name: Select Xcode 15.2
run: sudo xcode-select -s /Applications/Xcode_15.2.app
- name: Run tests
run: make test-library

Expand All @@ -29,8 +29,8 @@ jobs:
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- name: Select Xcode 15.1
run: sudo xcode-select -s /Applications/Xcode_15.1.app
- name: Select Xcode 15.2
run: sudo xcode-select -s /Applications/Xcode_15.2.app
- name: Build for library evolution
run: make build-for-library-evolution

Expand Down Expand Up @@ -66,8 +66,8 @@ jobs:
name: Build Examples
steps:
- uses: actions/checkout@v3
- name: Select Xcode 15.1
run: sudo xcode-select -s /Applications/Xcode_15.1.app
- name: Select Xcode 15.2
run: sudo xcode-select -s /Applications/Xcode_15.2.app
- name: Prepare Examples Project
run: cp Examples/Examples/_Secrets.swift Examples/Examples/Secrets.swift
- name: Build examples
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test-docs:
&& exit 1)

build-examples:
for scheme in Examples UserManagement; do \
for scheme in Examples UserManagement SlackClone; do \
xcodebuild build \
-skipMacroValidation \
-workspace supabase-swift.xcworkspace \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// _Push.swift
// PushV2.swift
//
//
// Created by Guilherme Souza on 02/01/24.
Expand All @@ -8,7 +8,7 @@
import Foundation
@_spi(Internal) import _Helpers

actor _Push {
actor PushV2 {
private weak var channel: RealtimeChannelV2?
let message: RealtimeMessageV2

Expand Down
4 changes: 2 additions & 2 deletions Sources/Realtime/V2/RealtimeChannelV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public actor RealtimeChannelV2 {

private var clientChanges: [PostgresJoinConfig] = []
private var joinRef: String?
private var pushes: [String: _Push] = [:]
private var pushes: [String: PushV2] = [:]

public private(set) var status: Status {
get { statusStream.lastElement }
Expand Down Expand Up @@ -466,7 +466,7 @@ public actor RealtimeChannelV2 {

@discardableResult
private func push(_ message: RealtimeMessageV2) async -> PushStatus {
let push = _Push(channel: self, message: message)
let push = PushV2(channel: self, message: message)
if let ref = message.ref {
pushes[ref] = push
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Realtime/V2/RealtimeClientV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking

let NSEC_PER_SEC: UInt64 = 1_000_000_000
let NSEC_PER_SEC: UInt64 = 1000000000
#endif

public actor RealtimeClientV2 {
Expand Down
90 changes: 90 additions & 0 deletions Sources/_Helpers/AnyJSON/AnyJSON+Codable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// AnyJSON+Codable.swift
//
//
// Created by Guilherme Souza on 20/01/24.
//

import Foundation

extension AnyJSON {
/// The decoder instance used for transforming AnyJSON to some Codable type.
public static let decoder: JSONDecoder = {
let decoder = JSONDecoder()
decoder.dataDecodingStrategy = .base64
decoder.dateDecodingStrategy = .custom { decoder in
let container = try decoder.singleValueContainer()
let dateString = try container.decode(String.self)

let date = DateFormatter.iso8601.date(from: dateString) ?? DateFormatter
.iso8601_noMilliseconds.date(from: dateString)

guard let decodedDate = date else {
throw DecodingError.typeMismatch(
Date.self,
DecodingError.Context(
codingPath: container.codingPath,
debugDescription: "String is not a valid Date"
)
)
}

return decodedDate
}
return decoder
}()

/// The encoder instance used for transforming AnyJSON to some Codable type.
public static let encoder: JSONEncoder = {
let encoder = JSONEncoder()
encoder.dataEncodingStrategy = .base64
encoder.dateEncodingStrategy = .formatted(DateFormatter.iso8601)
return encoder
}()
}

extension AnyJSON {
/// Initialize an ``AnyJSON`` from a ``Codable`` value.
public init(_ value: some Codable) throws {
if let value = value as? AnyJSON {
self = value
} else {
let data = try AnyJSON.encoder.encode(value)
self = try AnyJSON.decoder.decode(AnyJSON.self, from: data)
}
}

public func decode<T: Decodable>(_: T.Type, decoder: JSONDecoder = AnyJSON.decoder) throws -> T {
let data = try AnyJSON.encoder.encode(self)
return try decoder.decode(T.self, from: data)
}
}

extension JSONArray {
public func decode<T: Decodable>(
_: T.Type,
decoder: JSONDecoder = AnyJSON.decoder
) throws -> [T] {
try AnyJSON.array(self).decode([T].self, decoder: decoder)
}
}

extension JSONObject {
public func decode<T: Decodable>(_: T.Type, decoder: JSONDecoder = AnyJSON.decoder) throws -> T {
try AnyJSON.object(self).decode(T.self, decoder: decoder)
}

public init(_ value: some Codable) throws {
guard let object = try AnyJSON(value).objectValue else {
throw DecodingError.typeMismatch(
JSONObject.self,
DecodingError.Context(
codingPath: [],
debugDescription: "Expected to decode value to \(JSONObject.self)."
)
)
}

self = object
}
}
78 changes: 0 additions & 78 deletions Sources/_Helpers/AnyJSON/AnyJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,84 +122,6 @@ public enum AnyJSON: Sendable, Codable, Hashable {
case let .bool(val): try container.encode(val)
}
}

public func decode<T: Decodable>(_: T.Type, decoder: JSONDecoder = AnyJSON.decoder) throws -> T {
let data = try AnyJSON.encoder.encode(self)
return try decoder.decode(T.self, from: data)
}
}

extension JSONObject {
public func decode<T: Decodable>(_: T.Type, decoder: JSONDecoder = AnyJSON.decoder) throws -> T {
try AnyJSON.object(self).decode(T.self, decoder: decoder)
}

public init(_ value: some Codable) throws {
guard let object = try AnyJSON(value).objectValue else {
throw DecodingError.typeMismatch(
JSONObject.self,
DecodingError.Context(
codingPath: [],
debugDescription: "Expected to decode value to \(JSONObject.self)."
)
)
}

self = object
}
}

extension JSONArray {
public func decode<T: Decodable>(_: T.Type) throws -> [T] {
try AnyJSON.array(self).decode([T].self)
}
}

extension AnyJSON {
/// The decoder instance used for transforming AnyJSON to some Codable type.
public static let decoder: JSONDecoder = {
let decoder = JSONDecoder()
decoder.dataDecodingStrategy = .base64
decoder.dateDecodingStrategy = .custom { decoder in
let container = try decoder.singleValueContainer()
let dateString = try container.decode(String.self)

let date = DateFormatter.iso8601.date(from: dateString) ?? DateFormatter
.iso8601_noMilliseconds.date(from: dateString)

guard let decodedDate = date else {
throw DecodingError.typeMismatch(
Date.self,
DecodingError.Context(
codingPath: container.codingPath,
debugDescription: "String is not a valid Date"
)
)
}

return decodedDate
}
return decoder
}()

/// The encoder instance used for transforming AnyJSON to some Codable type.
public static let encoder: JSONEncoder = {
let encoder = JSONEncoder()
encoder.dataEncodingStrategy = .base64
encoder.dateEncodingStrategy = .formatted(DateFormatter.iso8601)
return encoder
}()
}

extension AnyJSON {
public init(_ value: some Codable) throws {
if let value = value as? AnyJSON {
self = value
} else {
let data = try AnyJSON.encoder.encode(value)
self = try AnyJSON.decoder.decode(AnyJSON.self, from: data)
}
}
}

extension AnyJSON: ExpressibleByNilLiteral {
Expand Down
4 changes: 2 additions & 2 deletions Tests/RealtimeTests/_PushTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class _PushTests: XCTestCase {
socket: socket,
logger: nil
)
let push = _Push(
let push = PushV2(
channel: channel,
message: RealtimeMessageV2(
joinRef: nil,
Expand All @@ -49,7 +49,7 @@ final class _PushTests: XCTestCase {
socket: socket,
logger: nil
)
let push = _Push(
let push = PushV2(
channel: channel,
message: RealtimeMessageV2(
joinRef: nil,
Expand Down

0 comments on commit 4e0d91f

Please sign in to comment.