diff --git a/apps/reference/_supabase_js/generated/getchannels.mdx b/apps/reference/_supabase_js/generated/getchannels.mdx index befb08174ad..8297655b33e 100644 --- a/apps/reference/_supabase_js/generated/getchannels.mdx +++ b/apps/reference/_supabase_js/generated/getchannels.mdx @@ -1,6 +1,6 @@ --- id: getchannels -title: 'getSubscriptions()' +title: 'getChannels()' slug: /getchannels custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml --- @@ -11,13 +11,13 @@ import TabItem from '@theme/TabItem' Returns all Realtime channels. ```js -const subscriptions = supabase.getChannels() +const channels = supabase.getChannels() ``` ## Examples -### Get all subscriptions +### Get all channels ```js -const subscriptions = supabase.getChannels() +const channels = supabase.getChannels() ``` diff --git a/apps/reference/_supabase_js/generated/invoke.mdx b/apps/reference/_supabase_js/generated/invoke.mdx index bc2eb51a724..578710c2be4 100644 --- a/apps/reference/_supabase_js/generated/invoke.mdx +++ b/apps/reference/_supabase_js/generated/invoke.mdx @@ -115,7 +115,7 @@ object representing the headers to send with the request - Requires an Authorization header. - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec. -- When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as application/json. You can override this behaviour by passing in a Content-Type header of your own. +- When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as `application/json`. You can override this behaviour by passing in a `Content-Type` header of your own. - Responses are automatically parsed as `json`, `blob` and `form-data` depending on the `Content-Type` header sent by your function. Responses are parsed as `text` by default. ## Examples diff --git a/apps/reference/_supabase_js/generated/removeallchannels.mdx b/apps/reference/_supabase_js/generated/removeallchannels.mdx index b862afa2940..7083c443c91 100644 --- a/apps/reference/_supabase_js/generated/removeallchannels.mdx +++ b/apps/reference/_supabase_js/generated/removeallchannels.mdx @@ -1,6 +1,6 @@ --- id: removeallchannels -title: 'removeAllSubscriptions()' +title: 'removeAllChannels()' slug: /removeallchannels custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml --- @@ -16,11 +16,11 @@ supabase.removeAllChannels() ## Notes -- Removing subscriptions is a great way to maintain the performance of your project's database. Supabase will automatically handle cleanup 30 seconds after a user is disconnected, but unused subscriptions may cause degradation as more users are simultaneously subscribed. +- Removing channels is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Supabase will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed. ## Examples -### Removes all subscriptions +### Removes all channels ```js supabase.removeAllChannels() diff --git a/apps/reference/_supabase_js/generated/removechannel.mdx b/apps/reference/_supabase_js/generated/removechannel.mdx index cc658d7e96b..8572858e763 100644 --- a/apps/reference/_supabase_js/generated/removechannel.mdx +++ b/apps/reference/_supabase_js/generated/removechannel.mdx @@ -11,7 +11,7 @@ import TabItem from '@theme/TabItem' Unsubscribes and removes Realtime channel from Realtime client. ```js -supabase.removeChannel(mySubscription) +supabase.removeChannel(myChannel) ``` ## Parameters @@ -827,12 +827,12 @@ No description provided. ## Notes -- Removing subscriptions is a great way to maintain the performance of your project's database. Supabase will automatically handle cleanup 30 seconds after a user is disconnected, but unused subscriptions may cause degradation as more users are simultaneously subscribed. +- Removing a channel is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Supabase will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed. ## Examples -### Remove a subscription +### Remove a channel ```js -supabase.removeChannel(mySubscription) +supabase.removeChannel(myChannel) ``` diff --git a/apps/reference/_supabase_js/generated/subscribe.mdx b/apps/reference/_supabase_js/generated/subscribe.mdx index e53ecfccc36..46a10c22980 100644 --- a/apps/reference/_supabase_js/generated/subscribe.mdx +++ b/apps/reference/_supabase_js/generated/subscribe.mdx @@ -9,9 +9,9 @@ import Tabs from '@theme/Tabs' import TabItem from '@theme/TabItem' ```js -const mySubscription = supabase - .from('*') - .on('*', (payload) => { +const myChannel = supabase + .channel('*') + .on('postgres_changes', { event: '*', schema: '*' }, (payload) => { console.log('Change received!', payload) }) .subscribe() @@ -86,16 +86,18 @@ No description provided. ## Notes - Realtime is disabled by default for new Projects for better database performance and security. You can turn it on by [managing replication](/docs/guides/api#managing-realtime). +- Row level security is not applied to delete statements. - If you want to receive the "previous" data for updates and deletes, you will need to set `REPLICA IDENTITY` to `FULL`, like this: `ALTER TABLE your_table REPLICA IDENTITY FULL;` +- When a delete occurs, the contents of old_record will be broadcast to all subscribers to that table so ensure that each table's replica identity only contains information that is safe to expose publicly. ## Examples ### Listen to all database changes ```js -const mySubscription = supabase - .from('*') - .on('*', (payload) => { +const myChannel = supabase + .channel('*') + .on('postgres_changes', { event: '*', schema: '*' }, (payload) => { console.log('Change received!', payload) }) .subscribe() @@ -104,40 +106,52 @@ const mySubscription = supabase ### Listening to a specific table ```js -const mySubscription = supabase - .from('countries') - .on('*', (payload) => { - console.log('Change received!', payload) - }) +const myChannel = supabase + .channel('public:countries') + .on( + 'postgres_changes', + { event: '*', schema: 'public', table: 'countries' }, + (payload) => { + console.log('Change received!', payload) + } + ) .subscribe() ``` ### Listening to inserts ```js -const mySubscription = supabase - .from('countries') - .on('INSERT', (payload) => { - console.log('Change received!', payload) - }) +const myChannel = supabase + .channel('public:countries') + .on( + 'postgres_changes', + { event: 'INSERT', schema: 'public', table: 'countries' }, + (payload) => { + console.log('Change received!', payload) + } + ) .subscribe() ``` ### Listening to updates By default, Supabase will send only the updated record. If you want to receive the previous values as well you can -enable full replication for the table you are listening too: +enable full replication for the table you are listening to: ```sql alter table "your_table" replica identity full; ``` ```js -const mySubscription = supabase - .from('countries') - .on('UPDATE', (payload) => { - console.log('Change received!', payload) - }) +const myChannel = supabase + .channel('public:countries') + .on( + 'postgres_changes', + { event: 'UPDATE', schema: 'public', table: 'countries' }, + (payload) => { + console.log('Change received!', payload) + } + ) .subscribe() ``` @@ -151,11 +165,15 @@ alter table "your_table" replica identity full; ``` ```js -const mySubscription = supabase - .from('countries') - .on('DELETE', (payload) => { - console.log('Change received!', payload) - }) +const myChannel = supabase + .channel('public:countries') + .on( + 'postgres_changes', + { event: 'DELETE', schema: 'public', table: 'countries' }, + (payload) => { + console.log('Change received!', payload) + } + ) .subscribe() ``` @@ -164,10 +182,18 @@ const mySubscription = supabase You can chain listeners if you want to listen to multiple events for each table. ```js -const mySubscription = supabase - .from('countries') - .on('INSERT', handleRecordInserted) - .on('DELETE', handleRecordDeleted) +const myChannel = supabase + .channel('public:countries') + .on( + 'postgres_changes', + { event: 'INSERT', schema: 'public', table: 'countries' }, + handleRecordInserted + ) + .on( + 'postgres_changes', + { event: 'DELETE', schema: 'public', table: 'countries' }, + handleRecordDeleted + ) .subscribe() ``` @@ -176,8 +202,17 @@ const mySubscription = supabase You can listen to individual rows using the format `{table}:{col}=eq.{val}` - where `{col}` is the column name, and `{val}` is the value which you want to match. ```js -const mySubscription = supabase - .from('countries:id=eq.200') - .on('UPDATE', handleRecordUpdated) +const myChannel = supabase + .channel('public:countries:id=eq.200') + .on( + 'postgres_changes', + { + event: 'UPDATE', + schema: 'public', + table: 'countries', + filter: 'id=eq.200', + }, + handleRecordUpdated + ) .subscribe() ```