From 653d9ba56924543509e821a7aaf67884fdc364d5 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 30 Sep 2025 17:02:18 -0300 Subject: [PATCH 1/2] feat(functions): add region as forceFunctionRegion query parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated FunctionsClient to add region as both x-region header and forceFunctionRegion query param - Updated tests to verify both header and query parameter functionality - Maintains backward compatibility with existing x-region header Ported from supabase/functions-js#100 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- Sources/Functions/FunctionsClient.swift | 5 ++++- Tests/FunctionsTests/FunctionsClientTests.swift | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/Functions/FunctionsClient.swift b/Sources/Functions/FunctionsClient.swift index 214c208c7..fa6dc135d 100644 --- a/Sources/Functions/FunctionsClient.swift +++ b/Sources/Functions/FunctionsClient.swift @@ -246,10 +246,11 @@ public final class FunctionsClient: Sendable { private func buildRequest(functionName: String, options: FunctionInvokeOptions) -> Helpers.HTTPRequest { + var query = options.query var request = HTTPRequest( url: url.appendingPathComponent(functionName), method: FunctionInvokeOptions.httpMethod(options.method) ?? .post, - query: options.query, + query: query, headers: mutableState.headers.merging(with: options.headers), body: options.body, timeoutInterval: FunctionsClient.requestIdleTimeout @@ -257,6 +258,8 @@ public final class FunctionsClient: Sendable { if let region = options.region ?? region { request.headers[.xRegion] = region + query.appendOrUpdate(URLQueryItem(name: "forceFunctionRegion", value: region)) + request.query = query } return request diff --git a/Tests/FunctionsTests/FunctionsClientTests.swift b/Tests/FunctionsTests/FunctionsClientTests.swift index 2d19c5d29..652a1a9f8 100644 --- a/Tests/FunctionsTests/FunctionsClientTests.swift +++ b/Tests/FunctionsTests/FunctionsClientTests.swift @@ -164,6 +164,7 @@ final class FunctionsClientTests: XCTestCase { Mock( url: url.appendingPathComponent("hello-world"), + ignoreQuery: true, statusCode: 200, data: [.post: Data()] ) @@ -174,7 +175,7 @@ final class FunctionsClientTests: XCTestCase { --header "X-Client-Info: functions-swift/0.0.0" \ --header "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0" \ --header "x-region: ca-central-1" \ - "http://localhost:5432/functions/v1/hello-world" + "http://localhost:5432/functions/v1/hello-world?forceFunctionRegion=ca-central-1" """# } .register() @@ -185,6 +186,7 @@ final class FunctionsClientTests: XCTestCase { func testInvokeWithRegion() async throws { Mock( url: url.appendingPathComponent("hello-world"), + ignoreQuery: true, statusCode: 200, data: [.post: Data()] ) @@ -195,7 +197,7 @@ final class FunctionsClientTests: XCTestCase { --header "X-Client-Info: functions-swift/0.0.0" \ --header "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0" \ --header "x-region: ca-central-1" \ - "http://localhost:5432/functions/v1/hello-world" + "http://localhost:5432/functions/v1/hello-world?forceFunctionRegion=ca-central-1" """# } .register() From fb6e957cdf95e8463bd3b86ef68c709885b70191 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 30 Sep 2025 17:12:47 -0300 Subject: [PATCH 2/2] test: update snapshot --- .../__Snapshots__/RequestTests/testInvokeWithCustomRegion.1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/FunctionsTests/__Snapshots__/RequestTests/testInvokeWithCustomRegion.1.txt b/Tests/FunctionsTests/__Snapshots__/RequestTests/testInvokeWithCustomRegion.1.txt index b7ebf5c70..72ba071c2 100644 --- a/Tests/FunctionsTests/__Snapshots__/RequestTests/testInvokeWithCustomRegion.1.txt +++ b/Tests/FunctionsTests/__Snapshots__/RequestTests/testInvokeWithCustomRegion.1.txt @@ -3,4 +3,4 @@ curl \ --header "apikey: supabase.anon.key" \ --header "x-client-info: functions-swift/x.y.z" \ --header "x-region: ap-northeast-1" \ - "http://localhost:5432/functions/v1/hello-world" \ No newline at end of file + "http://localhost:5432/functions/v1/hello-world?forceFunctionRegion=ap-northeast-1" \ No newline at end of file