Skip to content

Commit db3f4ab

Browse files
authored
fix(postgrest): drop Sendable requirements in generic types (#798)
1 parent 010e6db commit db3f4ab

File tree

6 files changed

+58
-30
lines changed

6 files changed

+58
-30
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ permissions:
4141
contents: read
4242

4343
jobs:
44-
xcodebuild-latest:
45-
name: xcodebuild (16.3)
44+
macos:
45+
name: xcodebuild (macOS latest)
4646
runs-on: macos-15
4747
strategy:
4848
matrix:
4949
command: [test, ""]
5050
platform: [IOS, MACOS]
51-
xcode: ["16.3"]
51+
xcode: ["26.0", "16.4"]
5252
include:
5353
- { command: test, skip_release: 1 }
5454
steps:
@@ -67,20 +67,20 @@ jobs:
6767
if: matrix.skip_release != '1'
6868
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Release PLATFORM="${{ matrix.platform }}" xcodebuild
6969
- name: Install lcov
70-
if: matrix.command == 'test' && matrix.platform == 'IOS'
70+
if: matrix.command == 'test' && matrix.platform == 'IOS' && matrix.xcode == '26.0'
7171
run: brew install lcov
7272
- name: Export code coverage
7373
id: coverage
74-
if: matrix.command == 'test' && matrix.platform == 'IOS'
74+
if: matrix.command == 'test' && matrix.platform == 'IOS' && matrix.xcode == '26.0'
7575
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Debug PLATFORM="${{ matrix.platform }}" coverage
7676
- uses: coverallsapp/[email protected]
7777
if: steps.coverage.outcome == 'success'
7878
with:
7979
github-token: ${{ secrets.GITHUB_TOKEN }}
8080
file: lcov.info
8181

82-
xcodebuild-legacy:
83-
name: xcodebuild (15.4)
82+
macos-legacy:
83+
name: xcodebuild (macOS legacy)
8484
runs-on: macos-14
8585
strategy:
8686
matrix:
@@ -114,6 +114,21 @@ jobs:
114114
if: matrix.skip_release != '1'
115115
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Release PLATFORM="${{ matrix.platform }}" xcodebuild
116116

117+
spm:
118+
runs-on: macos-15
119+
strategy:
120+
matrix:
121+
config: [debug, release]
122+
steps:
123+
- uses: actions/checkout@v5
124+
- uses: actions/cache@v4
125+
with:
126+
path: .build
127+
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
128+
restore-keys: |
129+
${{ runner.os }}-spm-
130+
- run: swift build -c ${{ matrix.config }}
131+
117132
linux:
118133
name: Linux
119134
runs-on: ubuntu-latest

Examples/Examples.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@
655655
ONLY_ACTIVE_ARCH = YES;
656656
SDKROOT = iphoneos;
657657
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
658+
SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor;
658659
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
659660
SWIFT_STRICT_CONCURRENCY = complete;
660661
SWIFT_VERSION = 5.0;
@@ -721,6 +722,7 @@
721722
MTL_FAST_MATH = YES;
722723
SDKROOT = iphoneos;
723724
SWIFT_COMPILATION_MODE = wholemodule;
725+
SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor;
724726
SWIFT_OPTIMIZATION_LEVEL = "-O";
725727
SWIFT_STRICT_CONCURRENCY = complete;
726728
SWIFT_VERSION = 5.0;

Examples/Examples/AddTodoListView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct AddTodoListView: View {
2222

2323
func saveButtonTapped() async {
2424
do {
25-
let createdTodo: Todo = try await supabase.database.from("todos")
25+
let createdTodo: Todo = try await supabase.from("todos")
2626
.insert(request, returning: .representation)
2727
.single()
2828
.execute()

Sources/PostgREST/PostgrestClient.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import HTTPTypes
88

99
/// PostgREST client.
1010
public final class PostgrestClient: Sendable {
11-
public typealias FetchHandler = @Sendable (_ request: URLRequest) async throws -> (
12-
Data, URLResponse
13-
)
11+
public typealias FetchHandler =
12+
@Sendable (_ request: URLRequest) async throws -> (
13+
Data, URLResponse
14+
)
1415

1516
/// The configuration struct for the PostgREST client.
1617
public struct Configuration: Sendable {
@@ -144,7 +145,8 @@ public final class PostgrestClient: Sendable {
144145

145146
guard let json = try JSONSerialization.jsonObject(with: bodyData) as? [String: Any] else {
146147
throw PostgrestError(
147-
message: "Params should be a key-value type when using `GET` or `HEAD` options.")
148+
message: "Params should be a key-value type when using `GET` or `HEAD` options."
149+
)
148150
}
149151

150152
for (key, value) in json {

Sources/PostgREST/PostgrestQueryBuilder.swift

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
4747
/// - values: The values to insert. Pass an object to insert a single row or an array to insert multiple rows.
4848
/// - count: Count algorithm to use to count inserted rows.
4949
public func insert(
50-
_ values: some Encodable & Sendable,
50+
_ values: some Encodable,
5151
returning: PostgrestReturningOptions? = nil,
5252
count: CountOption? = nil
5353
) throws -> PostgrestFilterBuilder {
54+
let body = try configuration.encoder.encode(values)
55+
5456
try mutableState.withValue {
5557
$0.request.method = .post
5658
var prefersHeaders: [String] = []
5759
if let returning {
5860
prefersHeaders.append("return=\(returning.rawValue)")
5961
}
60-
$0.request.body = try configuration.encoder.encode(values)
62+
$0.request.body = body
6163
if let count {
6264
prefersHeaders.append("count=\(count.rawValue)")
6365
}
@@ -68,14 +70,16 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
6870
$0.request.headers[.prefer] = prefersHeaders.joined(separator: ",")
6971
}
7072
if let body = $0.request.body,
71-
let jsonObject = try JSONSerialization.jsonObject(with: body) as? [[String: Any]]
73+
let jsonObject = try JSONSerialization.jsonObject(with: body) as? [[String: Any]]
7274
{
7375
let allKeys = jsonObject.flatMap(\.keys)
7476
let uniqueKeys = Set(allKeys).sorted()
75-
$0.request.query.appendOrUpdate(URLQueryItem(
76-
name: "columns",
77-
value: uniqueKeys.joined(separator: ",")
78-
))
77+
$0.request.query.appendOrUpdate(
78+
URLQueryItem(
79+
name: "columns",
80+
value: uniqueKeys.joined(separator: ",")
81+
)
82+
)
7983
}
8084
}
8185

@@ -94,12 +98,14 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
9498
/// - count: Count algorithm to use to count upserted rows.
9599
/// - ignoreDuplicates: If `true`, duplicate rows are ignored. If `false`, duplicate rows are merged with existing rows.
96100
public func upsert(
97-
_ values: some Encodable & Sendable,
101+
_ values: some Encodable,
98102
onConflict: String? = nil,
99103
returning: PostgrestReturningOptions = .representation,
100104
count: CountOption? = nil,
101105
ignoreDuplicates: Bool = false
102106
) throws -> PostgrestFilterBuilder {
107+
let body = try configuration.encoder.encode(values)
108+
103109
try mutableState.withValue {
104110
$0.request.method = .post
105111
var prefersHeaders = [
@@ -109,7 +115,7 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
109115
if let onConflict {
110116
$0.request.query.appendOrUpdate(URLQueryItem(name: "on_conflict", value: onConflict))
111117
}
112-
$0.request.body = try configuration.encoder.encode(values)
118+
$0.request.body = body
113119
if let count {
114120
prefersHeaders.append("count=\(count.rawValue)")
115121
}
@@ -121,14 +127,16 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
121127
}
122128

123129
if let body = $0.request.body,
124-
let jsonObject = try JSONSerialization.jsonObject(with: body) as? [[String: Any]]
130+
let jsonObject = try JSONSerialization.jsonObject(with: body) as? [[String: Any]]
125131
{
126132
let allKeys = jsonObject.flatMap(\.keys)
127133
let uniqueKeys = Set(allKeys).sorted()
128-
$0.request.query.appendOrUpdate(URLQueryItem(
129-
name: "columns",
130-
value: uniqueKeys.joined(separator: ",")
131-
))
134+
$0.request.query.appendOrUpdate(
135+
URLQueryItem(
136+
name: "columns",
137+
value: uniqueKeys.joined(separator: ",")
138+
)
139+
)
132140
}
133141
}
134142
return PostgrestFilterBuilder(self)
@@ -142,14 +150,15 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
142150
/// - values: The values to update with.
143151
/// - count: Count algorithm to use to count rows in a table.
144152
public func update(
145-
_ values: some Encodable & Sendable,
153+
_ values: some Encodable,
146154
returning: PostgrestReturningOptions = .representation,
147155
count: CountOption? = nil
148156
) throws -> PostgrestFilterBuilder {
149-
try mutableState.withValue {
157+
let body = try configuration.encoder.encode(values)
158+
mutableState.withValue {
150159
$0.request.method = .patch
151160
var preferHeaders = ["return=\(returning.rawValue)"]
152-
$0.request.body = try configuration.encoder.encode(values)
161+
$0.request.body = body
153162
if let count {
154163
preferHeaders.append("count=\(count.rawValue)")
155164
}

Sources/PostgREST/Types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Foundation
44
import FoundationNetworking
55
#endif
66

7-
public struct PostgrestResponse<T: Sendable>: Sendable {
7+
public struct PostgrestResponse<T> {
88
public let data: Data
99
public let response: HTTPURLResponse
1010
public let count: Int?

0 commit comments

Comments
 (0)