@quatrain/cloudwrapper-firebase 0.1.0

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.
@@ -0,0 +1,13 @@
1
+ import { HttpsOptions } from 'firebase-functions/v2/https';
2
+ import { AbstractCloudWrapper, BackendAction } from '@quatrain/core';
3
+ export type FirebaseParams = {
4
+ region?: string;
5
+ useEmulator?: boolean;
6
+ };
7
+ export declare class FirebaseCloudWrapper extends AbstractCloudWrapper {
8
+ protected _isInitialized: boolean;
9
+ constructor(params: FirebaseParams);
10
+ httpsWrapper(func: any, params?: HttpsOptions): import("firebase-functions/v2/https").HttpsFunction;
11
+ databaseWrapper(func: any, eventType: BackendAction, rule?: string): import("firebase-functions/v2").CloudFunction<import("firebase-functions/v2/firestore").FirestoreEvent<import("firebase-functions/v2/firestore").QueryDocumentSnapshot | undefined, Record<string, string>>> | import("firebase-functions/v2").CloudFunction<import("firebase-functions/v2/firestore").FirestoreEvent<import("firebase-functions/v2").Change<import("firebase-functions/v2/firestore").QueryDocumentSnapshot> | undefined, Record<string, string>>>;
12
+ protected _initialize(): void;
13
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FirebaseCloudWrapper = void 0;
4
+ const app_1 = require("firebase-admin/app");
5
+ const https_1 = require("firebase-functions/v2/https");
6
+ const firestore_1 = require("firebase-functions/v2/firestore");
7
+ const v2_1 = require("firebase-functions/v2");
8
+ const core_1 = require("@quatrain/core");
9
+ class FirebaseCloudWrapper extends core_1.AbstractCloudWrapper {
10
+ constructor(params) {
11
+ super(params);
12
+ this._isInitialized = false;
13
+ const { useEmulator, region } = params;
14
+ if (useEmulator === false && region) {
15
+ (0, v2_1.setGlobalOptions)({ region });
16
+ }
17
+ }
18
+ httpsWrapper(func, params = { memory: '4GiB', timeoutSeconds: 500 }) {
19
+ this._initialize();
20
+ return (0, https_1.onRequest)(Object.assign({ concurrency: 500 }, params), func);
21
+ }
22
+ databaseWrapper(func, eventType, rule = 'videos/{vid}/vectos/{uid}') {
23
+ this._initialize();
24
+ switch (eventType) {
25
+ case core_1.BackendAction.CREATE:
26
+ return (0, firestore_1.onDocumentCreated)(rule, func);
27
+ case core_1.BackendAction.UPDATE:
28
+ return (0, firestore_1.onDocumentUpdated)(rule, func);
29
+ case core_1.BackendAction.DELETE:
30
+ return (0, firestore_1.onDocumentDeleted)(rule, func);
31
+ case core_1.BackendAction.WRITE:
32
+ return (0, firestore_1.onDocumentWritten)(rule, func);
33
+ default:
34
+ throw new Error(`Unknown event type '${eventType}'`);
35
+ }
36
+ }
37
+ _initialize() {
38
+ if (this._isInitialized === false) {
39
+ if (this._params.useEmulator === true) {
40
+ // if emulator is active, we need a service account to access storage functions
41
+ // @see bin/setServiceAccountPath.sh
42
+ (0, app_1.initializeApp)({
43
+ databaseURL: 'https://totalymage-staging.firebaseio.com',
44
+ storageBucket: 'totalymage-staging.appspot.com',
45
+ });
46
+ }
47
+ else {
48
+ (0, app_1.initializeApp)();
49
+ }
50
+ this._isInitialized = true;
51
+ }
52
+ }
53
+ }
54
+ exports.FirebaseCloudWrapper = FirebaseCloudWrapper;
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@quatrain/cloudwrapper-firebase",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Cloud Wrapper adapter for Firebase",
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
+ "firebase-admin": "^12.1.0",
18
+ "firebase-functions": "^4.9.0"
19
+ },
20
+ "devDependencies": {
21
+ "@tsconfig/recommended": "^1.0.1",
22
+ "@types/jest": "^27.0.3",
23
+ "@types/pg": "^8.11.4",
24
+ "jest": "^27.4.7",
25
+ "jest-node-exports-resolver": "^1.1.6",
26
+ "jest-serial-runner": "^1.2.1",
27
+ "trace-unhandled": "^2.0.1",
28
+ "ts-jest": "^27.1.2",
29
+ "ts-node": "^10.9.1",
30
+ "typescript": "^5.1.5"
31
+ },
32
+ "scripts": {
33
+ "pretest": "tsc",
34
+ "test-ci": "jest --runInBand",
35
+ "build": "tsc --watch",
36
+ "prepush": "tsc",
37
+ "push": "yarn publish --access public"
38
+ }
39
+ }