@quatrain/cloudwrapper-supabase 0.1.1
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 +20 -0
- package/lib/SupabaseCloudWrapper.js +70 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +5 -0
- package/package.json +41 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AbstractCloudWrapper, DatabaseTriggerType } from '@quatrain/core';
|
|
2
|
+
import { SupabaseClient, RealtimeChannel } from '@supabase/supabase-js';
|
|
3
|
+
export type SupabaseParams = {
|
|
4
|
+
useEmulator?: boolean;
|
|
5
|
+
url?: string;
|
|
6
|
+
key?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const eventMap: {
|
|
9
|
+
create: string;
|
|
10
|
+
update: string;
|
|
11
|
+
delete: string;
|
|
12
|
+
};
|
|
13
|
+
export declare class SupabaseCloudWrapper extends AbstractCloudWrapper {
|
|
14
|
+
protected _supabaseClient: SupabaseClient | undefined;
|
|
15
|
+
protected _realtimeClient: RealtimeChannel | undefined;
|
|
16
|
+
protected _isInitialized: boolean;
|
|
17
|
+
constructor(params: SupabaseParams);
|
|
18
|
+
databaseTrigger(trigger: DatabaseTriggerType): void;
|
|
19
|
+
protected _initialize(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.SupabaseCloudWrapper = exports.eventMap = void 0;
|
|
24
|
+
const core_1 = require("@quatrain/core");
|
|
25
|
+
const supabase_js_1 = require("@supabase/supabase-js");
|
|
26
|
+
exports.eventMap = {
|
|
27
|
+
[core_1.BackendAction.CREATE]: 'INSERT',
|
|
28
|
+
[core_1.BackendAction.UPDATE]: 'UPDATE',
|
|
29
|
+
[core_1.BackendAction.DELETE]: 'DELETE',
|
|
30
|
+
};
|
|
31
|
+
class SupabaseCloudWrapper extends core_1.AbstractCloudWrapper {
|
|
32
|
+
constructor(params) {
|
|
33
|
+
super(params);
|
|
34
|
+
this._isInitialized = false;
|
|
35
|
+
}
|
|
36
|
+
// httpsTrigger(
|
|
37
|
+
// func: any,
|
|
38
|
+
// params: HttpsOptions = { memory: '4GiB', timeoutSeconds: 500 }
|
|
39
|
+
// ): HttpsFunction {
|
|
40
|
+
// this._initialize()
|
|
41
|
+
// return onRequest(
|
|
42
|
+
// {
|
|
43
|
+
// concurrency: 500,
|
|
44
|
+
// ...params,
|
|
45
|
+
// },
|
|
46
|
+
// func
|
|
47
|
+
// )
|
|
48
|
+
// }
|
|
49
|
+
databaseTrigger(trigger) {
|
|
50
|
+
var _a;
|
|
51
|
+
this._initialize();
|
|
52
|
+
(_a = this._realtimeClient) === null || _a === void 0 ? void 0 : _a.on('postgres_changes', {
|
|
53
|
+
event: Reflect.get(exports.eventMap, trigger.event),
|
|
54
|
+
schema: 'public',
|
|
55
|
+
table: trigger.model,
|
|
56
|
+
}, (_b) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
var { old: before, new: after } = _b, context = __rest(_b, ["old", "new"]);
|
|
58
|
+
return yield trigger.script({ before, after, context });
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
_initialize() {
|
|
62
|
+
if (this._isInitialized === false) {
|
|
63
|
+
core_1.Core.log(`[SPB] Supabase App init`);
|
|
64
|
+
this._supabaseClient = (0, supabase_js_1.createClient)(this._params.url, this._params.key);
|
|
65
|
+
this._realtimeClient = this._supabaseClient.channel('table-db-changes');
|
|
66
|
+
this._isInitialized = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.SupabaseCloudWrapper = SupabaseCloudWrapper;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SupabaseCloudWrapper = void 0;
|
|
4
|
+
const SupabaseCloudWrapper_1 = require("./SupabaseCloudWrapper");
|
|
5
|
+
Object.defineProperty(exports, "SupabaseCloudWrapper", { enumerable: true, get: function () { return SupabaseCloudWrapper_1.SupabaseCloudWrapper; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quatrain/cloudwrapper-supabase",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Cloud Wrapper adapter for Supabase",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib/",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@quatrain/core": "^1.0.0-beta2"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@quatrain/core": "^1.0.0-beta16",
|
|
18
|
+
"@supabase/supabase-js": "^2.45.1",
|
|
19
|
+
"firebase-admin": "^12.1.0",
|
|
20
|
+
"firebase-functions": "^4.9.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@tsconfig/recommended": "^1.0.1",
|
|
24
|
+
"@types/jest": "^27.0.3",
|
|
25
|
+
"@types/pg": "^8.11.4",
|
|
26
|
+
"jest": "^27.4.7",
|
|
27
|
+
"jest-node-exports-resolver": "^1.1.6",
|
|
28
|
+
"jest-serial-runner": "^1.2.1",
|
|
29
|
+
"trace-unhandled": "^2.0.1",
|
|
30
|
+
"ts-jest": "^27.1.2",
|
|
31
|
+
"ts-node": "^10.9.1",
|
|
32
|
+
"typescript": "^5.1.5"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"pretest": "tsc",
|
|
36
|
+
"test-ci": "jest --runInBand",
|
|
37
|
+
"build": "tsc --watch",
|
|
38
|
+
"prepush": "tsc",
|
|
39
|
+
"push": "yarn publish --access public"
|
|
40
|
+
}
|
|
41
|
+
}
|