Skip to content

refactor(functions): migrate Functions to HTTPRuntime - #1116

Draft
grdsdev wants to merge 35 commits into
mainfrom
claude/httpruntime-target-isolation-085a05
Draft

refactor(functions): migrate Functions to HTTPRuntime#1116
grdsdev wants to merge 35 commits into
mainfrom
claude/httpruntime-target-isolation-085a05

Conversation

@grdsdev

@grdsdev grdsdev commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Stacked on #1121. Migrates Sources/Functions to use the new HTTPRuntime target internally instead of URLSession directly, and reworks FunctionsClient's public construction API around an injectable HTTPTransport.

  • Buffered invoke/streaming paths route through HTTPTransport.send/stream (backed by HTTPRuntime.URLSessionTransport by default).
  • New FunctionsClientOptions (headers/region/logger/decoder/session) plus FunctionsClient.init(url:options:) become the primary public construction API.
  • The old flat-parameter fetch:-closure initializers move to Sources/Functions/Deprecated.swift as @available(*, deprecated) back-compat shims, adapted to HTTPTransport via FetchHandlerTransport (buffered send goes through the custom fetch: closure; streaming falls back to a plain URLSessionTransport, since a fetch: closure can't stream).
  • HTTPRequest gains a generic timeout field (consumed by URLSessionTransport.makeURLRequest) so FunctionsClient.requestIdleTimeout (150s) applies uniformly across every transport/path, instead of only the deprecated fetch-closure path.
  • _invokeWithStreamedResponse's returned body stream unwraps HTTPError.transport on mid-stream failures, matching the buffered path's error surface instead of leaking a package-internal error type.

Test plan

  • swift build
  • swift test --filter FunctionsClientTests (16 tests)
  • swift test (full suite, 124 tests, 0 failures)
  • ./scripts/format.sh (no changes)

grdsdev added 8 commits July 11, 2026 07:36
…e deleted SSE parser after the package-scoping edit

The manual public->package access-control pass left HTTPRuntime non-compiling:
checkStatus still referenced HTTPResponse's now-removed bare status/isSuccess
(now only on .head), MultipartFormData's new builder API members defaulted to
internal instead of package, and ServerSentEvents.swift was deleted outright
rather than rescoped, breaking SSE stream parsing entirely.
Follow-up to the HTTPRuntime target isolation: registers the test
target in the shared Xcode scheme, adds its spell-check terms, and
updates Package.resolved to drop dependencies no longer pulled in by
this trimmed-down package graph.
…ase, add addHeader

- HTTPTransport.send/stream now throw typed HTTPError instead of any Error;
  URLSessionTransport already only ever threw HTTPError.transport, so this
  just tightens the contract. Dropped the redundant `throws` on the private
  makeURLRequest helper, which never actually threw.
- Removed HTTPBody.multipart: callers now build the multipart body themselves
  via MultipartFormData.buildToTempFile(), set Content-Type, and pass .file.
  Keeps HTTPTransport from needing to know about multipart assembly.
- Added HTTPRequestBuilder.addHeader(_:value:), which merges into an existing
  header (joined with "; ") instead of replacing it, for repeated directives
  like Prefer. Both setHeader and addHeader resolve the target key
  case-insensitively so differently-cased calls merge into one header
  instead of creating duplicates.
Supabase's own clients don't need it; downstream consumers can parse
the raw streamed chunks themselves if they want SSE framing.
@coveralls

coveralls commented Jul 11, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 29159794086

Coverage decreased (-0.03%) to 83.524%

Details

  • Coverage decreased (-0.03%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 3 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

3 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
Sources/Helpers/AnyJSON/AnyJSON.swift 3 97.35%

Coverage Stats

Coverage Status
Relevant Lines: 9511
Covered Lines: 7944
Line Coverage: 83.52%
Coverage Strength: 38.09 hits per line

💛 - Coveralls

grdsdev added 21 commits July 11, 2026 10:00
…sed doc references

- checkStatus now requires a catch-all APIError type instead of falling
  back to a bare unexpectedStatus(status:body:) case, and reports decode
  failures as unexpectedResponse(response:underlyingError:) with the full
  response attached.
- Commented out the still-unused HTTPError.encoding case.
- Dropped doc comments referencing the (now removed) OpenAPI codegen tool.
…uild

- TransferProgress/ProgressHandler were left `public` when the rest of
  HTTPRuntime was scoped down to `package`; the capability-matrix CI
  check flagged them as new, unregistered public API. Scope them to
  `package` like everything else in this target.
- FoundationNetworking (swift-corelibs-foundation on Linux) has no
  async byte-streaming API (`bytes(for:)`/`AsyncBytes`), so
  URLSessionTransport.stream() failed to compile on Linux. Branch on
  `canImport(FoundationNetworking)`: Linux buffers the full response
  via `data(for:)` and yields it as a single chunk instead of
  streaming incrementally; Apple platforms keep the existing
  incremental byte-stream implementation.
…e and dictionary

Adds HTTPRuntimeTestHelpersTests to the shared Xcode scheme in alphabetical order between HelpersTests and HTTPRuntimeTests. Includes dictionary.txt entries for Xcode-related terms and formatting fixes to HTTPRuntimeTestHelpers source files.
grdsdev added 3 commits July 11, 2026 15:30
…Runtime

Switches Functions off Helpers.HTTPClient/HTTPRequest/HTTPResponse and onto
HTTPRuntime for headers (HTTPFields -> [String: String]) and the buffered
invoke/invoke(decode:)/invoke(decoder:) path, via a private
FetchHandlerTransport adapter wrapping the existing fetch: closure as an
HTTPTransport. Also fixes client.functions.headers.dictionary in
SupabaseClientTests (now already [String: String]) to keep the package
building. Streaming (_invokeWithStreamedResponse) gets a one-line stopgap
and is fully migrated in a follow-up.
…ientOptions + HTTPTransport

Introduce FunctionsClientOptions and an injectable HTTPTransport as the
primary construction path, moving the legacy fetch:-closure initializers
to deprecated back-compat shims in Deprecated.swift. FetchHandlerTransport's
stream() now delegates to a real URLSessionTransport instead of being
unreachable.
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Potential Breaking API Changes Detected

This PR appears to contain breaking API changes. Please review the changes below:

API Check Output
  💔 API breakage: func FunctionsClient._invokeWithStreamedResponse(_:options:) is now throwing

If this is intentional, please update your PR title or commit message to include:

  • ! after the type (e.g., feat!: remove deprecated method)
  • Or include BREAKING CHANGE: in the commit body

If this is a false positive, you can safely ignore this warning.

grdsdev added 3 commits July 13, 2026 06:22
test(functions): fix FunctionsClientTests for new options/transport API

Adds missing DocC comments on FunctionsClientOptions and the primary
init(url:options:), and updates the Topics outline to reference the
current public API instead of the initializer now in Deprecated.swift.

Test fixes: drop the removed sessionConfiguration: argument in favor of
the transport-based init, add missing try await on
_invokeWithStreamedResponse call sites, and fix two relay-error tests
that mocked a 2xx status — relay-error detection only runs on non-2xx
responses by design, so those mocks now use a non-2xx status code.
…tIssue

Un-reverts the FetchHandlerTransport change from the docs pass: send/stream
use plain throws (no HTTPError.transport re-wrapping), and send reports an
issue when uploadProgress is set, since the fetch: closure has no way to
honor it.
Whole-branch review turned up regressions from the HTTPRuntime migration:

- HTTPRequest gains a generic `timeout` field, applied by
  URLSessionTransport.makeURLRequest. FunctionsClient.buildRequest sets it
  to requestIdleTimeout on every request, so the 150s gateway timeout
  applies uniformly again (previously only the deprecated
  FetchHandlerTransport path set it, so the new init(url:options:) path
  silently fell back to URLSession's default ~60s timeout). This also lets
  FetchHandlerTransport drop its duplicate makeURLRequest override.
- _invokeWithStreamedResponse now wraps the returned body stream so
  mid-stream transport failures unwrap HTTPError.transport to the
  underlying error, matching the buffered rawInvoke path instead of
  leaking a package-internal error type to callers.
- Deprecated.swift gets the standard file header used by every sibling
  file in Sources/Functions and Sources/HTTPRuntime.
- Fixes a stale doc comment claiming the package init(url:options:transport:)
  is used by SupabaseClient (it still uses the deprecated initializer).
@grdsdev
grdsdev changed the base branch from main to claude/httpruntime-target-085a05 July 13, 2026 09:38
@grdsdev grdsdev changed the title feat(runtime): isolate HTTPRuntime target refactor(functions): migrate Functions to HTTPRuntime Jul 13, 2026
Base automatically changed from claude/httpruntime-target-085a05 to main July 28, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants