@quatrain/cloudwrapper-supabase 1.1.10 → 1.1.12

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.
@@ -15,7 +15,12 @@ export declare class SupabaseCloudWrapper extends AbstractCloudWrapper {
15
15
  protected _realtimeClient: RealtimeChannel | undefined;
16
16
  protected _isInitialized: boolean;
17
17
  constructor(params: SupabaseParams);
18
- databaseTrigger(trigger: DatabaseTriggerType): void;
18
+ databaseTrigger(trigger: DatabaseTriggerType): {
19
+ event: any;
20
+ schema: string;
21
+ table: string;
22
+ };
19
23
  triggersEnable(): void;
24
+ triggersDisable(): void;
20
25
  protected _initialize(): void;
21
26
  }
@@ -33,6 +33,7 @@ class SupabaseCloudWrapper extends cloudwrapper_1.AbstractCloudWrapper {
33
33
  constructor(params) {
34
34
  super(params);
35
35
  this._isInitialized = false;
36
+ this._initialize();
36
37
  }
37
38
  // httpsTrigger(
38
39
  // func: any,
@@ -50,25 +51,62 @@ class SupabaseCloudWrapper extends cloudwrapper_1.AbstractCloudWrapper {
50
51
  databaseTrigger(trigger) {
51
52
  var _a;
52
53
  this._initialize();
53
- (_a = this._realtimeClient) === null || _a === void 0 ? void 0 : _a.on('postgres_changes', {
54
- event: Reflect.get(exports.eventMap, trigger.event),
55
- schema: 'public',
56
- table: trigger.model,
57
- }, (_b) => __awaiter(this, void 0, void 0, function* () {
58
- var { old: before, new: after } = _b, context = __rest(_b, ["old", "new"]);
59
- return yield trigger.script({ before, after, context });
60
- }));
54
+ if (!this._realtimeClient) {
55
+ throw new Error(`Realtime channel is not enabled`);
56
+ }
57
+ if (typeof trigger.script !== 'function') {
58
+ throw new Error(`Passed script value is not a function`);
59
+ }
60
+ try {
61
+ const params = {
62
+ event: Reflect.get(exports.eventMap, trigger.event),
63
+ schema: 'public',
64
+ table: trigger.model,
65
+ };
66
+ (_a = this._supabaseClient) === null || _a === void 0 ? void 0 : _a.channel(trigger.name).on('postgres_changes', params, (_b) => __awaiter(this, void 0, void 0, function* () {
67
+ var { old: before, new: after } = _b, context = __rest(_b, ["old", "new"]);
68
+ console.log(after);
69
+ cloudwrapper_1.CloudWrapper.info(`Triggering function on event`);
70
+ try {
71
+ return yield trigger.script({ before, after, context });
72
+ }
73
+ catch (err) {
74
+ cloudwrapper_1.CloudWrapper.error(err.message);
75
+ console.log(err);
76
+ }
77
+ })).subscribe();
78
+ return params;
79
+ }
80
+ catch (err) {
81
+ console.log(err);
82
+ throw new Error(`Realtime channel subscription failed`);
83
+ }
61
84
  }
62
85
  triggersEnable() {
86
+ if (!this._realtimeClient) {
87
+ throw new Error(`Realtime client is not enabled`);
88
+ }
89
+ this._realtimeClient.subscribe((res) => {
90
+ cloudwrapper_1.CloudWrapper.info(`Enabling Realtime triggers: ${res}`);
91
+ if (res !== 'SUBSCRIBED') {
92
+ throw new Error(`Failed to subscribe to Realtime channels`);
93
+ }
94
+ });
95
+ }
96
+ triggersDisable() {
63
97
  var _a;
64
- (_a = this._realtimeClient) === null || _a === void 0 ? void 0 : _a.subscribe();
98
+ if (!this._realtimeClient) {
99
+ throw new Error(`Realtime channel is not enabled`);
100
+ }
101
+ cloudwrapper_1.CloudWrapper.info(`Disabling Realtime triggers`);
102
+ (_a = this._supabaseClient) === null || _a === void 0 ? void 0 : _a.removeAllChannels();
65
103
  }
66
104
  _initialize() {
67
105
  if (this._isInitialized === false) {
68
- cloudwrapper_1.CloudWrapper.log(`Supabase App init`);
69
106
  this._supabaseClient = (0, supabase_js_1.createClient)(this._params.url, this._params.key);
70
107
  this._realtimeClient = this._supabaseClient.channel('table-db-changes');
71
108
  this._isInitialized = true;
109
+ cloudwrapper_1.CloudWrapper.info(`Supabase App initialized`);
72
110
  }
73
111
  }
74
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/cloudwrapper-supabase",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "license": "MIT",
5
5
  "description": "Cloud Wrapper adapter for Supabase",
6
6
  "main": "lib/index.js",
@@ -11,13 +11,13 @@
11
11
  ],
12
12
  "author": "Quatrain Développement SAS <developers@quatrain.com>",
13
13
  "peerDependencies": {
14
- "@quatrain/core": "^1.1.10"
14
+ "@quatrain/core": "^1.1.14"
15
15
  },
16
16
  "dependencies": {
17
- "@quatrain/backend": "^1.1.10",
18
- "@quatrain/cloudwrapper": "^1.1.10",
19
- "@quatrain/core": "^1.1.10",
20
- "@supabase/supabase-js": "^2.45.1"
17
+ "@quatrain/backend": "^1.1.12",
18
+ "@quatrain/cloudwrapper": "^1.1.11",
19
+ "@quatrain/core": "^1.1.14",
20
+ "@supabase/supabase-js": "^2.47.15"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@tsconfig/recommended": "^1.0.1",
@@ -32,11 +32,14 @@
32
32
  "typescript": "^5.1.5"
33
33
  },
34
34
  "scripts": {
35
- "pretest": "tsc",
36
35
  "test-ci": "jest --runInBand",
37
36
  "build": "tsc",
38
37
  "wbuild": "tsc --watch",
39
38
  "bump-to": "yarn version",
40
- "publish": "yarn build && yarn npm publish --access public"
39
+ "hash": "node ../../bin/hashFolder.js",
40
+ "hash:persist": "yarn hash > .hash_latest.txt",
41
+ "hash:compare": "yarn hash > .hash_newest.txt && cmp -s .hash_latest.txt .hash_newest.txt",
42
+ "publish": "yarn hash:compare || yarn publish:process",
43
+ "publish:process": "yarn version patch && yarn build && yarn npm publish --access public && yarn hash:persist"
41
44
  }
42
45
  }