Skip to content

chore!: give each package's Constants class a package-specific name - #1677

Open
spydon wants to merge 2 commits into
mainfrom
chore/realtime-constants-internal
Open

chore!: give each package's Constants class a package-specific name#1677
spydon wants to merge 2 commits into
mainfrom
chore/realtime-constants-internal

Conversation

@spydon

@spydon spydon commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1673, addressing #1673 (comment).

Why

Six packages declared a class named Constants: functions_client, gotrue, realtime_client, storage_client, supabase and supabase_flutter. The capability matrix keys symbols by bare name, so an entry like Constants.defaultHeaders could not say which package it meant. The same ambiguity applies to anyone reading the code across packages.

What changed

Each class is named after its package, and the file declaring it is named to match:

Package Class File
functions_client FunctionsConstants src/functions_constants.dart
gotrue GoTrueConstants src/gotrue_constants.dart
realtime_client RealtimeConstants src/realtime_constants.dart
storage_client StorageConstants src/storage_constants.dart
supabase SupabaseConstants src/supabase_constants.dart
supabase_flutter SupabaseFlutterConstants src/supabase_flutter_constants.dart

gotrue and realtime_client keep a constants.dart, since both also declare enums there. Only the class moved out into its own file, so constants.dart now holds exactly the enums and, for gotrue, ApiVersions. gotrue.dart no longer needs hide Constants on its export as a result.

realtime_client holds the only public class of the six, so it changed the most:

  • The typedef RealtimeConstants = Constants is gone and the class carries that name directly. realtime_client.dart only ever exported the alias, so the name consumers write is unchanged.
  • defaultHeaders, defaultHeartbeatIntervalMs and wsCloseNormal are now @internal. Nothing outside the package reads them, and the other five packages' default header maps were already internal. This is the breaking part: code outside the package that reached for them will now get invalid_use_of_internal_member.
  • defaultTimeout and defaultConnectionCloseTimeout stay public, because supabase reads both when filling in unset RealtimeClientOptions.

In sdk-compliance.yaml, the three now-internal symbols are dropped, realtime.configuration.heartbeat_interval loses its supporting_symbols list along with them, the duplicated Constants and Constants.defaultTimeout pair is removed from the top-level list, and RealtimeConstants.defaultConnectionCloseTimeout and RealtimeConstants.defaultTimeout are registered under the new name.

Verification

  • dart analyze clean across all packages and examples.
  • Full suites pass against a local Supabase stack, at the --concurrency=1 the workflow uses: gotrue (479), realtime_client (205, integration included), storage_client (210), supabase (134), supabase_flutter (65), functions_client (48).
  • The compliance symbol, drift and schema checks pass locally against this branch's base.

Summary by CodeRabbit

  • New Features
    • GoTrue constants are now publicly accessible.
    • Realtime protocol, socket state, and log-level types are available through the public library interface.
  • Bug Fixes
    • Preserved default headers, timeouts, heartbeat settings, API-version handling, and session behavior across clients.
  • Refactor
    • Organized service-specific configuration for Functions, GoTrue, Realtime, Storage, Supabase, and Supabase Flutter to improve consistency and reduce naming conflicts.

@spydon
spydon requested a review from a team as a code owner August 10, 2026 08:00
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5eaac4f2-1494-486e-bc56-3fa6be687cb0

📥 Commits

Reviewing files that changed from the base of the PR and between 32d5ece and b6d993b.

📒 Files selected for processing (32)
  • packages/functions_client/lib/src/functions_client.dart
  • packages/functions_client/lib/src/functions_constants.dart
  • packages/gotrue/lib/gotrue.dart
  • packages/gotrue/lib/src/constants.dart
  • packages/gotrue/lib/src/fetch.dart
  • packages/gotrue/lib/src/gotrue_client.dart
  • packages/gotrue/lib/src/gotrue_constants.dart
  • packages/gotrue/lib/src/types/api_version.dart
  • packages/gotrue/lib/src/types/session.dart
  • packages/gotrue/test/api_version_test.dart
  • packages/gotrue/test/fetch_test.dart
  • packages/gotrue/test/otp_mock_test.dart
  • packages/gotrue/test/src/constants_test.dart
  • packages/gotrue/test/src/set_session_test.dart
  • packages/gotrue/test/src/types/session_test.dart
  • packages/realtime_client/lib/realtime_client.dart
  • packages/realtime_client/lib/src/constants.dart
  • packages/realtime_client/lib/src/push.dart
  • packages/realtime_client/lib/src/realtime_client.dart
  • packages/realtime_client/lib/src/realtime_constants.dart
  • packages/realtime_client/test/channel_test.dart
  • packages/realtime_client/test/mock_test.dart
  • packages/realtime_client/test/socket_test.dart
  • packages/storage_client/lib/src/storage_client.dart
  • packages/storage_client/lib/src/storage_constants.dart
  • packages/supabase/lib/src/supabase_client.dart
  • packages/supabase/lib/src/supabase_constants.dart
  • packages/supabase/test/utilities_test.dart
  • packages/supabase_flutter/lib/src/supabase.dart
  • packages/supabase_flutter/lib/src/supabase_flutter_constants.dart
  • packages/supabase_flutter/test/version_test.dart
  • sdk-compliance.yaml
💤 Files with no reviewable changes (2)
  • packages/realtime_client/lib/src/constants.dart
  • packages/gotrue/lib/src/constants.dart

📝 Walkthrough

Walkthrough

The change replaces shared Constants references with package-specific constant classes across client libraries. It adds GoTrueConstants and RealtimeConstants, updates exports and compliance metadata, and adjusts affected tests.

Changes

Client package constants

Layer / File(s) Summary
Package-specific constant references
packages/functions_client/..., packages/storage_client/..., packages/supabase/..., packages/supabase_flutter/...
Renamed internal constants classes and updated imports, header initialization, and tests.

GoTrue constants

Layer / File(s) Summary
GoTrue constants extraction
packages/gotrue/lib/...
Moved configuration values to GoTrueConstants and updated URL, header, storage, timing, API-version, and JWKS references.
GoTrue validation updates
packages/gotrue/test/...
Updated tests and comments to use GoTrueConstants. The barrel export now exposes Constants.

Realtime constants

Layer / File(s) Summary
Realtime constants extraction
packages/realtime_client/lib/...
Moved timeout, heartbeat, close-code, and header values to RealtimeConstants and updated public exports and runtime references.
Realtime validation and compliance
packages/realtime_client/test/..., sdk-compliance.yaml
Updated tests and capability-matrix symbols to use RealtimeConstants.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

Suggested labels: v3

Suggested reviewers: tr00d

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: renaming generic Constants classes to package-specific names.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/realtime-constants-internal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@spydon spydon changed the title chore(realtime)!: rename Constants to RealtimeConstants and hide the internal ones chore!: give each package's Constants class a package-specific name Aug 10, 2026

@QuintinWillison QuintinWillison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needing to rename an internal type to fit a downstream, external system smells wrong to me. 🤔

This raises questions:

  1. Should the symbols/identifiers being enumerated in your manifest include the package they're in also, so each package (as is ok in Flutter/Dart) can have its own Constants internal?
  2. But, actually, should internal symbols/identifiers even be enumerated in a public-facing manifest?

spydon added a commit that referenced this pull request Aug 10, 2026
## Why

Four different representations of an HTTP method coexisted across the
packages:

| Package | Representation | Values | Wire string |
|---|---|---|---|
| `functions_client` | public `enum HttpMethod` | get, post, put,
delete, patch | `method.name.toUpperCase()`, open-coded at two call
sites |
| `postgrest` | public `enum HttpMethod` | get, **head**, post, put,
patch, delete | `String get value => name.toUpperCase()` |
| `gotrue` | `@internal enum RequestMethodType` | get, post, put, patch,
delete | none, switches to `http.Client`'s `get` / `post` / … |
| `storage_client` | bare `String` | `'GET'`, `'POST'`, `'PUT'`,
`'DELETE'`, `'HEAD'` | the literal itself |

The two public enums shared a name while disagreeing on contents, which
forced `supabase.dart` to export postgrest with `hide HttpMethod`,
making postgrest's enum unreachable through the umbrella library. It
also confused the capability matrix, which keys symbols by bare name: it
registered `HttpMethod` for functions and `HttpMethod.value` for
postgrest as if they were one type.

The stringly-typed side had its own cost. `storage_client` compared
`method != 'GET'` to decide whether to set a JSON content type, in both
its `Fetch` helper and its Iceberg REST catalog.

## What changed

One `HttpMethod` in `supabase_common`, taking postgrest's shape: the six
methods plus the `value` getter that `functions_client` used to
open-code.

Public surface:

- `functions_client` and `postgrest` re-export the shared enum, so
callers of either library see no change.
- `supabase.dart` exports postgrest whole again.
- `functions.invocation.method_override` registers
`FunctionsClient.invoke`, since the shared enum lives in
`supabase_common`, which `.sdk-parse-ignore` excludes from the scanned
public API surface. A note records that the Dart enum also offers
`head`, which supabase-js does not expose for function invocation.
- The `edge_functions` example's "every HTTP method" test skips `head`,
whose response carries no body for the echo function to reflect, and
asserts against `method.value`.

Internal adoption, no public API change since both declarations were
`@internal`:

- `gotrue`: `RequestMethodType` is gone and its roughly 65 call sites
use the shared enum. `GotrueFetch`'s dispatch switch gains a `head`
branch to stay exhaustive over six values, wired to `http.Client.head`,
and now skips the JSON content type for `head` as well as for `get`. No
gotrue call site issues a HEAD today, so that branch is currently
unexercised.
- `storage_client`: `Fetch`'s private request helpers and the Iceberg
catalog's `_request` take an `HttpMethod` instead of a `String`, the
wire strings come from `.value`, and the content-type branch compares
enum values. The public wrapper method names (`get`, `post`, `head`, and
so on) are unchanged.

Every log line that interpolates a method uses `.value`, so they keep
printing `GET` rather than the enum's default `toString`.

The `supabase_common` pins stay at `0.1.2`; `melos version` rewrites
dependents' pins at release time.

## Merge order

This targets `main` directly and does not depend on #1673 or #1677,
though it came out of the same review thread. #1673 previously
registered `HttpMethod` and `HttpMethod.value`, which this PR makes
dangling; those registrations have been pruned on that branch, so the
two can merge in either order.

## Verification

- `dart analyze` clean across all packages and examples.
- `dcm analyze` reports no issues in any file this PR touches.
- Suites pass against a local Supabase stack, at the `--concurrency=1`
the workflow uses: `gotrue` (479), `storage_client` (210), `postgrest`
(196), `functions_client` (48).
- The compliance symbol, drift and schema checks pass locally with
`main` as the base.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Added a shared `HttpMethod` API covering GET, HEAD, POST, PUT, PATCH,
and DELETE.
  - Made `HttpMethod` available through the relevant client libraries.
  - Added explicit HEAD request support where applicable.

- **Bug Fixes**
  - Improved HTTP method serialization for requests.
  - Corrected request content handling for GET and HEAD calls.
- Updated integration coverage to accurately validate supported methods.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Base automatically changed from chore/register-remaining-symbols to main August 10, 2026 09:57
@spydon

spydon commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Needing to rename an internal type to fit a downstream, external system smells wrong to me. 🤔

The PR description is a little bit misdirecting, the main clean-up reason is that we shouldn't have classes named in a generic fashion like that in the repo, the class names should entail what they are for.

This raises questions:

  1. Should the symbols/identifiers being enumerated in your manifest include the package they're in also, so each package (as is ok in Flutter/Dart) can have its own Constants internal?

That would be a good improvement, but I don't think we need to do it until it becomes an actual problem.

  1. But, actually, should internal symbols/identifiers even be enumerated in a public-facing manifest?

They are not.

spydon added 2 commits August 10, 2026 14:26
…internal ones

The class was only ever exported under its RealtimeConstants alias, so
give it that name directly instead of the ambiguous Constants, which five
other packages also declare and which the capability matrix cannot tell
apart in its flat symbol registry.

defaultHeaders, defaultHeartbeatIntervalMs and wsCloseNormal are only used
inside realtime_client, so mark them @internal, matching the other
packages whose default header maps are already internal. defaultTimeout
and defaultConnectionCloseTimeout stay public since supabase reads them
when merging RealtimeClientOptions.
Six packages declared a class called Constants, so a symbol like
Constants.defaultHeaders said nothing about which package it belonged to,
in the capability matrix or when reading the code. Each is now named after
its package, and the file holding it is named to match.

The gotrue and realtime_client constants.dart files keep the enums they
also declared; only the class moved out into its own file.
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