@quatrain/cloudwrapper-supabase 1.1.20 → 1.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,17 +1,25 @@
1
1
  # @quatrain/cloudwrapper-supabase
2
2
 
3
3
  This package provides a Cloud Wrapper adapter for Supabase Edge Functions. It allows you to invoke serverless functions in a consistent way across different BaaS providers.
4
+ This package provides a Cloud Wrapper for Supabase, enabling real-time database and storage triggers. It handles the WebSocket connection to Supabase's Realtime service, providing robust connection monitoring and configurable automatic reconnection logic.
4
5
 
5
6
  ## Features
6
7
 
7
- - Invokes Supabase Edge Functions.
8
- - Consistent interface provided by `@quatrain/cloudwrapper`.
9
- - Works with both SaaS and self-hosted Supabase instances.
8
+ - Listens to database changes (`INSERT`, `UPDATE`, `DELETE`) on your Supabase Postgres database.
9
+ - Listens to storage changes in Supabase Storage.
10
+ - Monitors connection health with a heartbeat mechanism.
11
+ - Provides a configurable strategy for handling disconnections (exit process or attempt to reconnect).
12
+ - Consistent interface provided by `@quatrain/cloudwrapper`.
13
+ - Works with both SaaS and self-hosted Supabase instances.
10
14
 
11
15
  ## Installation
12
16
 
13
17
  ```bash
18
+ # With npm
14
19
  npm install @quatrain/cloudwrapper-supabase @supabase/supabase-js
20
+
21
+ # With yarn
22
+ yarn add @quatrain/cloudwrapper-supabase @supabase/supabase-js
15
23
  ```
16
24
 
17
25
  ## Usage
@@ -19,6 +27,28 @@ npm install @quatrain/cloudwrapper-supabase @supabase/supabase-js
19
27
  ```typescript
20
28
  import { CloudWrapper } from '@quatrain/cloudwrapper'
21
29
  import { SupabaseCloudWrapperAdapter } from '@quatrain/cloudwrapper-supabase'
30
+ import { SupabaseCloudWrapper } from '@quatrain/cloudwrapper-supabase'
31
+ import { BackendAction } from '@quatrain/backend'
22
32
 
23
33
  // Setup and use the adapter with the CloudWrapper singleton.
34
+ const wrapper = new SupabaseCloudWrapper({
35
+ url: process.env.SUPABASE_URL,
36
+ key: process.env.SUPABASE_KEY,
37
+ // Optional: Determines behavior on disconnection.
38
+ // - true (default): Exits the process. Ideal for containerized environments
39
+ // (e.g., Kubernetes) that will automatically restart the service.
40
+ // - false: Attempts to reconnect internally.
41
+ exitOnDisconnect: true,
42
+ })
43
+
44
+ // Example: Set up a trigger for new rows in a 'profiles' table
45
+ wrapper.databaseTrigger({
46
+ name: 'new-profile-trigger',
47
+ model: 'profiles',
48
+ event: BackendAction.CREATE,
49
+ script: async ({ after }) => {
50
+ console.log(`A new profile was created:`, after)
51
+ // Add your business logic here
52
+ },
53
+ })
24
54
  ```
@@ -140,6 +140,7 @@ class SupabaseCloudWrapper extends cloudwrapper_1.AbstractCloudWrapper {
140
140
  realtime: {
141
141
  heartbeatIntervalMs: 5000,
142
142
  heartbeatCallback: (status) => {
143
+ console.log('status received', status);
143
144
  switch (status) {
144
145
  case 'ok':
145
146
  if (!this._heartbeatOkReceived) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/cloudwrapper-supabase",
3
- "version": "1.1.20",
3
+ "version": "1.1.21",
4
4
  "license": "MIT",
5
5
  "description": "Cloud Wrapper adapter for Supabase",
6
6
  "repository": {
@@ -192,6 +192,7 @@ export class SupabaseCloudWrapper extends AbstractCloudWrapper {
192
192
  realtime: {
193
193
  heartbeatIntervalMs: 5000,
194
194
  heartbeatCallback: (status: HeartbeatStatus) => {
195
+ console.log('status received', status)
195
196
  switch (status) {
196
197
  case 'ok':
197
198
  if (!this._heartbeatOkReceived) {