Conversation
75ff0dd to
12450c4
Compare
Contributor
|
12450c4 to
40b2460
Compare
f4571e7 to
743bc8e
Compare
…dy params Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…unctions - Replace HTTPClientType/HTTPClient/FetchHandler with _HTTPClient - FunctionInvokeOptions.headers and query now use [String: String] - _invokeWithStreamedResponse is now async throws - SupabaseClient passes session + tokenProvider to FunctionsClient - Remove RequestTests.swift (covered by inline snapshots in FunctionsClientTests) - Add package access modifiers to _HTTPClient types Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ming API - Convert FunctionsClient from Sendable class with LockIsolated to actor - Replace _invokeWithStreamedResponse (URLSessionDataDelegate-based) with invokeStream returning AsyncThrowingStream<UInt8, any Error> via _HTTPClient - fetchStream now async throws and returns (stream, HTTPURLResponse) tuple, allowing pre-stream validation (errors thrown before stream is returned) - Remove StreamResponseDelegate class - Set session timeout via configuration instead of per-request - Fix relay error header name typo (x-relay -> x-relay-error) - Update FunctionsClientTests and SupabaseClient for actor isolation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…n rawInvoke _HTTPClient.fetchData now throws HTTPClientError.responseError on non-2xx responses. FunctionsClient.rawInvoke catches it and converts to the public FunctionsError.httpError type. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace options-struct overloads with a single configure-closure pattern. `invoke`, `invokeDecodable`, and `invokeStream` now accept `(inout FunctionInvokeOptions) -> Void` instead of `FunctionInvokeOptions`. `invokeDecodable` returns `(T, HTTPURLResponse)` and `invokeStream` returns `(AsyncThrowingStream<UInt8, Error>, HTTPURLResponse)`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…gion overloads - FunctionsClient package init takes FunctionRegion? instead of String? - Remove public convenience init (replaced by public designated init) - FunctionsOptions.region is now FunctionRegion? (was String?) - Remove @_disfavoredOverload String? init from FunctionsOptions - Update tests to use FunctionRegion enum values and actor-safe access patterns Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ove String? overloads - FunctionInvokeOptions.region is now FunctionRegion? (was String?) - Remove duplicate extension inits that delegated with region?.rawValue - Remove @_disfavoredOverload attributes (no longer needed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add 19 comprehensive tests for FunctionsClient using Replay library: - Basic invocation tests (default, JSON body, arrays, text, binary) - HTTP method tests (GET, PUT, PATCH, DELETE) - Custom headers and content-type overrides - Complex scenarios with nested JSON - Decode tests with custom decoders - Authentication token tests - Response metadata validation Created echo edge function at supabase/functions/echo/ that: - Accepts any HTTP method and echoes back request details - Sorts query parameters alphabetically for deterministic testing - Handles JSON, plain text, and binary data Test suite uses .serialized and .playbackIsolated for deterministic replay testing with 19 HAR files stored in Tests/FunctionsTests/Replays/ Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Replace invoke(options: FunctionInvokeOptions) with builder closure style - Replace invoke<T: Decodable> with invokeDecodable returning (T, HTTPURLResponse) - Update invokeStream callers to unpack (stream, response) tuple - FunctionsTests.swift: migrate all invoke/coercion calls to invokeDecodable Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add public init() to FunctionInvokeOptions (memberwise init is internal) - Update FunctionInvokeOptionsTests to test var properties directly - Convert remaining FunctionInvokeOptions(body:) calls to manual Data encoding - Set Content-Type explicitly when encoding body in test closures Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
743bc8e to
504ec11
Compare
This was referenced Apr 28, 2026
…th nil tokenProvider Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…oder on client - Convert FunctionRegion from enum to RawRepresentable struct with ExpressibleByStringLiteral so callers can pass custom region strings - Add optional decoder property to FunctionsClient, used as fallback in invokeDecodable - Update tests to use Bundle.module for replay URLs and await actor-isolated decoder property Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… closure Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ionsClient Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…in init parameters Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…les to public API Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… new Functions API Add missing `#if canImport(FoundationNetworking)` guard to `_HTTPClient.swift` so the Linux build finds `HTTPURLResponse`, `URLSession`, and `URLRequest`. Update `FunctionsExamplesView.swift` to use the new `invokeDecodable` closure-based API introduced by the functions v3 rewrite. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
URLSession.bytes(for:) is not available on Linux. Wrap fetchStream in _HTTPClient and invokeStream in FunctionsClient with #if canImport(Darwin) so the Linux build compiles cleanly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests calling invokeStream failed to compile on Linux because the method is Darwin-only. Wrap the three streaming test functions in #if canImport(Darwin). Also re-run swift-format on _HTTPClient.swift and FunctionsClient.swift to fix the indentation of the #if blocks inside the actor/class body. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… T.Type parameter Update DocC symbol links to reflect the as: parameter label and add `as _: T.Type = T.self` to invokeDecodable for more ergonomic call sites. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Bundle.module.resourceURL?.appendingPathComponent("Replays") uses direct
path concatenation, bypassing bundle.url(forResource:withExtension:subdirectory:)
which is broken on Linux swift-corelibs-foundation for subdirectory lookups.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
TestScoping for suite-level traits does not reliably propagate ReplayTestDefaults to individual tests on Linux, causing all tests to resolve the wrong archive via the broken Bundle.url(forResource:subdirectory:) fallback. Fix: provide an explicit rootURL to each ReplayTrait so getArchiveURL uses the direct URL path (step 1) on both platforms, bypassing TestScoping and bundle resource lookup entirely. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
FunctionsClient is an actor; passing (inout FunctionInvokeOptions) -> Void from @mainactor callers crosses an isolation boundary. Swift 6 strict concurrency requires the closure to be @sendable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eters Use the `sending` ownership modifier instead of `@Sendable` for the `options` closure parameters in invoke, invokeDecodable, and invokeStream, aligning with Swift 6 concurrency conventions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
grdsdev
added a commit
that referenced
this pull request
Apr 28, 2026
* feat(helpers): add _HTTPClient with RequestBody and separate query/body params
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(helpers): add TokenProvider support to _HTTPClient
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(helpers): stream UInt8 bytes instead of single-byte Data chunks
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(functions): migrate to _HTTPClient, remove old HTTP layer from Functions
- Replace HTTPClientType/HTTPClient/FetchHandler with _HTTPClient
- FunctionInvokeOptions.headers and query now use [String: String]
- _invokeWithStreamedResponse is now async throws
- SupabaseClient passes session + tokenProvider to FunctionsClient
- Remove RequestTests.swift (covered by inline snapshots in FunctionsClientTests)
- Add package access modifiers to _HTTPClient types
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(functions): convert FunctionsClient to actor, simplify streaming API
- Convert FunctionsClient from Sendable class with LockIsolated to actor
- Replace _invokeWithStreamedResponse (URLSessionDataDelegate-based) with
invokeStream returning AsyncThrowingStream<UInt8, any Error> via _HTTPClient
- fetchStream now async throws and returns (stream, HTTPURLResponse) tuple,
allowing pre-stream validation (errors thrown before stream is returned)
- Remove StreamResponseDelegate class
- Set session timeout via configuration instead of per-request
- Fix relay error header name typo (x-relay -> x-relay-error)
- Update FunctionsClientTests and SupabaseClient for actor isolation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(functions): catch HTTPClientError and convert to FunctionsError in rawInvoke
_HTTPClient.fetchData now throws HTTPClientError.responseError on non-2xx
responses. FunctionsClient.rawInvoke catches it and converts to the
public FunctionsError.httpError type.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(functions): add builder-pattern invoke API
Replace options-struct overloads with a single configure-closure
pattern. `invoke`, `invokeDecodable`, and `invokeStream` now accept
`(inout FunctionInvokeOptions) -> Void` instead of
`FunctionInvokeOptions`. `invokeDecodable` returns `(T, HTTPURLResponse)`
and `invokeStream` returns `(AsyncThrowingStream<UInt8, Error>, HTTPURLResponse)`.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(functions): use FunctionRegion everywhere, remove String? region overloads
- FunctionsClient package init takes FunctionRegion? instead of String?
- Remove public convenience init (replaced by public designated init)
- FunctionsOptions.region is now FunctionRegion? (was String?)
- Remove @_disfavoredOverload String? init from FunctionsOptions
- Update tests to use FunctionRegion enum values and actor-safe access patterns
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(functions): use FunctionRegion in FunctionInvokeOptions, remove String? overloads
- FunctionInvokeOptions.region is now FunctionRegion? (was String?)
- Remove duplicate extension inits that delegated with region?.rawValue
- Remove @_disfavoredOverload attributes (no longer needed)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test(functions): add comprehensive tests with echo edge function
Add 19 comprehensive tests for FunctionsClient using Replay library:
- Basic invocation tests (default, JSON body, arrays, text, binary)
- HTTP method tests (GET, PUT, PATCH, DELETE)
- Custom headers and content-type overrides
- Complex scenarios with nested JSON
- Decode tests with custom decoders
- Authentication token tests
- Response metadata validation
Created echo edge function at supabase/functions/echo/ that:
- Accepts any HTTP method and echoes back request details
- Sorts query parameters alphabetically for deterministic testing
- Handles JSON, plain text, and binary data
Test suite uses .serialized and .playbackIsolated for deterministic
replay testing with 19 HAR files stored in Tests/FunctionsTests/Replays/
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* test(functions): update tests for v3 builder-pattern invoke API
- Replace invoke(options: FunctionInvokeOptions) with builder closure style
- Replace invoke<T: Decodable> with invokeDecodable returning (T, HTTPURLResponse)
- Update invokeStream callers to unpack (stream, response) tuple
- FunctionsTests.swift: migrate all invoke/coercion calls to invokeDecodable
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test(functions): fix tests for builder-pattern API and public init
- Add public init() to FunctionInvokeOptions (memberwise init is internal)
- Update FunctionInvokeOptionsTests to test var properties directly
- Convert remaining FunctionInvokeOptions(body:) calls to manual Data encoding
- Set Content-Type explicitly when encoding body in test closures
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(functions): unify public init to delegate to package init with nil tokenProvider
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(functions): make FunctionRegion an open struct and store decoder on client
- Convert FunctionRegion from enum to RawRepresentable struct with ExpressibleByStringLiteral so callers can pass custom region strings
- Add optional decoder property to FunctionsClient, used as fallback in invokeDecodable
- Update tests to use Bundle.module for replay URLs and await actor-isolated decoder property
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(supabase): propagate global URLSession to RealtimeClient as fetch closure
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(functions): make decoder a public non-optional property on FunctionsClient
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(functions): use non-optional JSONDecoder with default value in init parameters
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* docs(functions): add comprehensive DocC documentation and usage examples to public API
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* docs(functions): trim verbose doc comments per linter suggestions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(helpers): add FoundationNetworking import and update examples for new Functions API
Add missing `#if canImport(FoundationNetworking)` guard to `_HTTPClient.swift` so
the Linux build finds `HTTPURLResponse`, `URLSession`, and `URLRequest`. Update
`FunctionsExamplesView.swift` to use the new `invokeDecodable` closure-based API
introduced by the functions v3 rewrite.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: gate stream methods behind #if canImport(Darwin)
URLSession.bytes(for:) is not available on Linux. Wrap fetchStream in
_HTTPClient and invokeStream in FunctionsClient with #if canImport(Darwin)
so the Linux build compiles cleanly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: gate invokeStream tests behind canImport(Darwin) and fix formatting
Tests calling invokeStream failed to compile on Linux because the method is
Darwin-only. Wrap the three streaming test functions in #if canImport(Darwin).
Also re-run swift-format on _HTTPClient.swift and FunctionsClient.swift to
fix the indentation of the #if blocks inside the actor/class body.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* docs(functions): update invokeDecodable doc comments and add explicit T.Type parameter
Update DocC symbol links to reflect the as: parameter label and add
`as _: T.Type = T.self` to invokeDecodable for more ergonomic call sites.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(functions): use replaysRootURL for cross-platform HAR archive lookup
Bundle.module.resourceURL?.appendingPathComponent("Replays") uses direct
path concatenation, bypassing bundle.url(forResource:withExtension:subdirectory:)
which is broken on Linux swift-corelibs-foundation for subdirectory lookups.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(functions): pass rootURL per-test to fix HAR resolution on Linux
TestScoping for suite-level traits does not reliably propagate ReplayTestDefaults
to individual tests on Linux, causing all tests to resolve the wrong archive via
the broken Bundle.url(forResource:subdirectory:) fallback.
Fix: provide an explicit rootURL to each ReplayTrait so getArchiveURL uses the
direct URL path (step 1) on both platforms, bypassing TestScoping and bundle
resource lookup entirely.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(functions): mark invoke options closure as @sendable
FunctionsClient is an actor; passing (inout FunctionInvokeOptions) -> Void
from @mainactor callers crosses an isolation boundary. Swift 6 strict
concurrency requires the closure to be @sendable.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(functions): replace @sendable with sending for closure parameters
Use the `sending` ownership modifier instead of `@Sendable` for the
`options` closure parameters in invoke, invokeDecodable, and invokeStream,
aligning with Swift 6 concurrency conventions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Rewrite of
FunctionsClienton top of a new shared_HTTPClienthelper, with a new builder-pattern invocation API and various cleanups.Changes
New
_HTTPClient(Sources/Helpers/_HTTPClient.swift)Package-internal HTTP client intended for use across modules:
fetch<T: Decodable>— perform a request and decode the JSON responsefetchData— perform a request and return rawDatafetchStream— stream response bytes viaAsyncThrowingStream<UInt8, Error>usingURLSession.bytes(Darwin only —#if canImport(Darwin))TokenProviderclosure injected into every request as anAuthorization: BearerheaderRequestBodyenum:.encodable,.json,.dataHTTPClientErrorwith.responseError(HTTPURLResponse, data:)and.decodingError(HTTPURLResponse, detail:)cases#if canImport(FoundationNetworking)import for Linux builds;fetchStreamexcluded on Linux sinceURLSession.bytesis unavailable thereFunctionsClientrewrite_HTTPClient, removing the oldURLSessionDataDelegate-based streaming implementationactorfor safe concurrent access without manual lockingFunctionInvokeOptionsvalue directly:FunctionRegionis now aRawRepresentablestruct withExpressibleByStringLiteral, replacing the enum — custom region strings are now supportedFunctionInvokeOptions.regionisFunctionRegion?(wasString?);String?overloads removeddecoderis a public stored property (non-optional, defaults toJSONDecoder()), used as fallback ininvokeDecodableHTTPClientError→FunctionsErrorconversion: non-2xx responses are caught and re-thrown asFunctionsError.httpError(code:data:)x-relay, now correctly checksx-relay-errorSupabaseClientpropagates the globalURLSessionand aTokenProviderintoFunctionsClientTests
FunctionsTests.swiftusing theReplaylibrary with recorded HAR fixtures (invoke_default,invoke_get_method,invoke_put_method)Tests/FunctionsTests/supabase/for integration testingFunctionsClientTests.swiftandSupabaseClientTests.swiftfor the new actor-isolated APIRequestTests.swift(coverage now handled by inline snapshot tests)Example app
Updated
FunctionsExamplesView.swiftto useinvokeDecodablewith the new closure-based API.