@quatrain/cloudwrapper-supabase 1.1.11 → 1.1.13
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/lib/SupabaseCloudWrapper.d.ts +6 -1
- package/lib/SupabaseCloudWrapper.js +54 -10
- package/package.json +11 -8
|
@@ -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): void | {
|
|
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,68 @@ class SupabaseCloudWrapper extends cloudwrapper_1.AbstractCloudWrapper {
|
|
|
50
51
|
databaseTrigger(trigger) {
|
|
51
52
|
var _a;
|
|
52
53
|
this._initialize();
|
|
53
|
-
(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
if (Array.isArray(trigger.event)) {
|
|
61
|
+
const params = trigger.event.forEach((event) => {
|
|
62
|
+
return this.databaseTrigger(Object.assign(Object.assign({}, trigger), { event, name: `${trigger.name}-${event}` }));
|
|
63
|
+
});
|
|
64
|
+
return params;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const params = {
|
|
68
|
+
event: Reflect.get(exports.eventMap, trigger.event),
|
|
69
|
+
schema: 'public',
|
|
70
|
+
table: trigger.model,
|
|
71
|
+
};
|
|
72
|
+
cloudwrapper_1.CloudWrapper.info(`Set up DB trigger ${trigger.name} for ${trigger.event} event on table ${params.table}`);
|
|
73
|
+
(_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* () {
|
|
74
|
+
var { old: before, new: after } = _b, context = __rest(_b, ["old", "new"]);
|
|
75
|
+
cloudwrapper_1.CloudWrapper.info(`Triggering function on event ${trigger.name}`);
|
|
76
|
+
try {
|
|
77
|
+
return yield trigger.script({ before, after, context });
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
cloudwrapper_1.CloudWrapper.error(err.message);
|
|
81
|
+
console.log(err);
|
|
82
|
+
}
|
|
83
|
+
})).subscribe();
|
|
84
|
+
return params;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.log(err);
|
|
88
|
+
throw new Error(`Realtime channel subscription failed`);
|
|
89
|
+
}
|
|
61
90
|
}
|
|
62
91
|
triggersEnable() {
|
|
92
|
+
if (!this._realtimeClient) {
|
|
93
|
+
throw new Error(`Realtime client is not enabled`);
|
|
94
|
+
}
|
|
95
|
+
this._realtimeClient.subscribe((res) => {
|
|
96
|
+
cloudwrapper_1.CloudWrapper.info(`Enabling Realtime triggers: ${res}`);
|
|
97
|
+
if (res !== 'SUBSCRIBED') {
|
|
98
|
+
throw new Error(`Failed to subscribe to Realtime channels`);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
triggersDisable() {
|
|
63
103
|
var _a;
|
|
64
|
-
(
|
|
104
|
+
if (!this._realtimeClient) {
|
|
105
|
+
throw new Error(`Realtime channel is not enabled`);
|
|
106
|
+
}
|
|
107
|
+
cloudwrapper_1.CloudWrapper.info(`Disabling Realtime triggers`);
|
|
108
|
+
(_a = this._supabaseClient) === null || _a === void 0 ? void 0 : _a.removeAllChannels();
|
|
65
109
|
}
|
|
66
110
|
_initialize() {
|
|
67
111
|
if (this._isInitialized === false) {
|
|
68
|
-
cloudwrapper_1.CloudWrapper.log(`Supabase App init`);
|
|
69
112
|
this._supabaseClient = (0, supabase_js_1.createClient)(this._params.url, this._params.key);
|
|
70
113
|
this._realtimeClient = this._supabaseClient.channel('table-db-changes');
|
|
71
114
|
this._isInitialized = true;
|
|
115
|
+
cloudwrapper_1.CloudWrapper.info(`Supabase App initialized`);
|
|
72
116
|
}
|
|
73
117
|
}
|
|
74
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/cloudwrapper-supabase",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
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.
|
|
14
|
+
"@quatrain/core": "^1.1.14"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@quatrain/backend": "^1.1.
|
|
18
|
-
"@quatrain/cloudwrapper": "^1.1.
|
|
19
|
-
"@quatrain/core": "^1.1.
|
|
20
|
-
"@supabase/supabase-js": "^2.
|
|
17
|
+
"@quatrain/backend": "^1.1.12",
|
|
18
|
+
"@quatrain/cloudwrapper": "^1.1.12",
|
|
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
|
-
"
|
|
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
|
}
|