Skip to content

refactor: use URL type for manipulating urls #1417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2025
Merged

Conversation

grdsdev
Copy link
Contributor

@grdsdev grdsdev commented May 19, 2025

What kind of change does this PR introduce?

Bug fix, feature, docs update, ...

What is the current behavior?

Please link any relevant issues here.

What is the new behavior?

Feel free to include screenshots if it includes visual changes.

Additional context

Add any other context or screenshots.

@grdsdev grdsdev requested review from Copilot and hf May 19, 2025 14:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Refactors URL handling in SupabaseClient to use native URL objects and improves header merging in helper defaults.

  • Client endpoint properties (realtimeUrl, authUrl, etc.) are now URL instances, and consumers call .toString() where needed.
  • Deep merge of default and custom headers added in applySettingDefaults.
  • Old client.test.ts removed and replaced with a new, more comprehensive SupabaseClient.test.ts.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/helpers.test.ts Update header assertion to use toStrictEqual
test/client.test.ts Remove deprecated client tests (superseded by SupabaseClient suite)
test/SupabaseClient.test.ts Add comprehensive tests for URL construction, clients, and behaviors
src/lib/helpers.ts Explicitly merge default and custom headers in applySettingDefaults
src/SupabaseClient.ts Change endpoint props to URL, use URL API for building endpoints, update consumers
Comments suppressed due to low confidence (1)

test/helpers.test.ts:39

  • Add a unit test case to verify that when global.headers are provided, applySettingDefaults correctly merges them with the default headers.
expect(settings.global.headers).toStrictEqual(DEFAULT_HEADERS)

this.storageUrl = `${_supabaseUrl}/storage/v1`
this.functionsUrl = `${_supabaseUrl}/functions/v1`
this.realtimeUrl = new URL('/realtime/v1', baseUrl)
this.realtimeUrl.protocol = this.realtimeUrl.protocol.replace('http', 'ws')
Copy link
Contributor

Choose a reason for hiding this comment

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

Was gonna say just do = 'ws:' but I see what you did. ✅

@@ -137,7 +139,7 @@ export default class SupabaseClient<
* Supabase Functions allows you to deploy and invoke edge functions.
*/
get functions(): FunctionsClient {
return new FunctionsClient(this.functionsUrl, {
return new FunctionsClient(this.functionsUrl.toString(), {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this the right way?

Suggested change
return new FunctionsClient(this.functionsUrl.toString(), {
return new FunctionsClient(this.functionsUrl.href, {

@grdsdev grdsdev merged commit bc4bce1 into master May 19, 2025
2 checks passed
@grdsdev grdsdev deleted the guilherme/use-url-api branch May 19, 2025 16:02
grdsdev added a commit that referenced this pull request May 20, 2025
* fix: merge global passed headers with default headers

* refactor: use URL type for manipulating urls

* use baeUrl directly

* use href
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