Skip to content

refactor(functions): migrate Functions to HTTPRuntime#1116

Draft
grdsdev wants to merge 13 commits into
claude/httpruntime-target-085a05from
claude/httpruntime-target-isolation-085a05
Draft

refactor(functions): migrate Functions to HTTPRuntime#1116
grdsdev wants to merge 13 commits into
claude/httpruntime-target-085a05from
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)

@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 10 commits July 11, 2026 13:49
…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
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