@intuitionrobotics/firebase 2.0.12 → 2.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/dist/app-backend/FirebaseModule.d.ts +2 -2
- package/dist/app-backend/FirebaseModule.d.ts.map +1 -1
- package/dist/app-backend/FirebaseModule.js +14 -9
- package/dist/app-backend/FirebaseModule.js.map +1 -1
- package/dist/app-backend/functions/firebase-function-core.d.ts +105 -0
- package/dist/app-backend/functions/firebase-function-core.d.ts.map +1 -0
- package/dist/app-backend/functions/firebase-function-core.js +162 -0
- package/dist/app-backend/functions/firebase-function-core.js.map +1 -0
- package/dist/app-backend/functions/firebase-function-database.d.ts +10 -0
- package/dist/app-backend/functions/firebase-function-database.d.ts.map +1 -0
- package/dist/app-backend/functions/firebase-function-database.js +30 -0
- package/dist/app-backend/functions/firebase-function-database.js.map +1 -0
- package/dist/app-backend/functions/firebase-function-express.d.ts +18 -0
- package/dist/app-backend/functions/firebase-function-express.d.ts.map +1 -0
- package/dist/app-backend/functions/firebase-function-express.js +46 -0
- package/dist/app-backend/functions/firebase-function-express.js.map +1 -0
- package/dist/app-backend/functions/firebase-function-firestore.d.ts +13 -0
- package/dist/app-backend/functions/firebase-function-firestore.d.ts.map +1 -0
- package/dist/app-backend/functions/firebase-function-firestore.js +28 -0
- package/dist/app-backend/functions/firebase-function-firestore.js.map +1 -0
- package/dist/app-backend/functions/firebase-function-https.d.ts +8 -0
- package/dist/app-backend/functions/firebase-function-https.d.ts.map +1 -0
- package/dist/app-backend/functions/firebase-function-https.js +16 -0
- package/dist/app-backend/functions/firebase-function-https.js.map +1 -0
- package/dist/app-backend/functions/firebase-function-pubsub.d.ts +15 -0
- package/dist/app-backend/functions/firebase-function-pubsub.d.ts.map +1 -0
- package/dist/app-backend/functions/firebase-function-pubsub.js +51 -0
- package/dist/app-backend/functions/firebase-function-pubsub.js.map +1 -0
- package/dist/app-backend/functions/firebase-function-scheduled.d.ts +14 -0
- package/dist/app-backend/functions/firebase-function-scheduled.d.ts.map +1 -0
- package/dist/app-backend/functions/firebase-function-scheduled.js +41 -0
- package/dist/app-backend/functions/firebase-function-scheduled.js.map +1 -0
- package/dist/app-backend/functions/firebase-function-storage.d.ts +24 -0
- package/dist/app-backend/functions/firebase-function-storage.d.ts.map +1 -0
- package/dist/app-backend/functions/firebase-function-storage.js +32 -0
- package/dist/app-backend/functions/firebase-function-storage.js.map +1 -0
- package/dist/app-backend/functions/firebase-function.d.ts +8 -94
- package/dist/app-backend/functions/firebase-function.d.ts.map +1 -1
- package/dist/app-backend/functions/firebase-function.js +18 -349
- package/dist/app-backend/functions/firebase-function.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -18,10 +18,10 @@ type ConfigType = {
|
|
|
18
18
|
export declare class FirebaseModule_Class extends Module<ConfigType> {
|
|
19
19
|
private readonly adminSessions;
|
|
20
20
|
static localAdminConfigId: string;
|
|
21
|
-
private
|
|
21
|
+
private _localProjectId?;
|
|
22
22
|
constructor();
|
|
23
|
-
protected init(): void;
|
|
24
23
|
getLocalProjectId(): string;
|
|
24
|
+
private getLocalProjectIdSafe;
|
|
25
25
|
private deriveLocalProjectId;
|
|
26
26
|
protected connect(): Promise<void>;
|
|
27
27
|
protected disconnect(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirebaseModule.d.ts","sourceRoot":"","sources":["../../src/main/app-backend/FirebaseModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,MAAM,EAET,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAC,qBAAqB,EAAC,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAC,KAAK,uBAAuB,EAAC,MAAM,4BAA4B,CAAC;AAExE,MAAM,MAAM,QAAQ,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAA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F,qBAAa,oBACT,SAAQ,MAAM,CAAC,UAAU,CAAC;IAG1B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+C;IAC7E,OAAc,kBAAkB,EAAE,MAAM,CAAC;IAEzC,OAAO,CAAC,eAAe,CAAC,CAAS;;IAMjC,iBAAiB,IAAI,MAAM;IAI3B,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,oBAAoB;IAoB5B,SAAS,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAMlC,SAAS,CAAC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B,kBAAkB,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;IA6BpE,cAAc,CAAC,SAAS,EAAE,MAAM;CAGnC;AAED,eAAO,MAAM,cAAc,sBAA6B,CAAC"}
|
|
@@ -6,17 +6,21 @@ export class FirebaseModule_Class extends Module {
|
|
|
6
6
|
// private readonly tokenSessions: { [s: string]: FirebaseSession_UserPassword; } = {};
|
|
7
7
|
adminSessions = {};
|
|
8
8
|
static localAdminConfigId;
|
|
9
|
-
|
|
9
|
+
// Derived lazily on first use (was eagerly set in init()).
|
|
10
|
+
_localProjectId;
|
|
10
11
|
constructor() {
|
|
11
12
|
super("FirebaseModule");
|
|
12
|
-
if (process.env.GCLOUD_PROJECT)
|
|
13
|
-
this.localProjectId = process.env.GCLOUD_PROJECT;
|
|
14
|
-
}
|
|
15
|
-
init() {
|
|
16
|
-
this.localProjectId = this.deriveLocalProjectId();
|
|
17
13
|
}
|
|
18
14
|
getLocalProjectId() {
|
|
19
|
-
return this.
|
|
15
|
+
return this._localProjectId ??= this.deriveLocalProjectId();
|
|
16
|
+
}
|
|
17
|
+
getLocalProjectIdSafe() {
|
|
18
|
+
try {
|
|
19
|
+
return this.getLocalProjectId();
|
|
20
|
+
}
|
|
21
|
+
catch (_e) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
20
24
|
}
|
|
21
25
|
deriveLocalProjectId() {
|
|
22
26
|
let projectId;
|
|
@@ -46,14 +50,15 @@ export class FirebaseModule_Class extends Module {
|
|
|
46
50
|
createAdminSession(_projectId, _sessionName) {
|
|
47
51
|
let projectId = _projectId;
|
|
48
52
|
if (!projectId)
|
|
49
|
-
projectId = this.
|
|
53
|
+
projectId = this.getLocalProjectId();
|
|
50
54
|
const sessionName = _sessionName || projectId || "local-admin";
|
|
51
55
|
let session = this.adminSessions[sessionName];
|
|
52
56
|
if (session)
|
|
53
57
|
return session;
|
|
54
58
|
this.logInfo(`Creating Firebase session for project id: ${projectId}`);
|
|
55
59
|
let config = this.getProjectAuth(projectId);
|
|
56
|
-
|
|
60
|
+
const localProjectId = this.getLocalProjectIdSafe();
|
|
61
|
+
if (!config && _projectId && localProjectId && localProjectId !== _projectId)
|
|
57
62
|
throw new BadImplementationException(`Config for key ${_projectId} is not defined`);
|
|
58
63
|
if (typeof config === "string")
|
|
59
64
|
config = JSON.parse(readFileSync(config, "utf8"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirebaseModule.js","sourceRoot":"","sources":["../../src/main/app-backend/FirebaseModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,0BAA0B,EAC1B,8BAA8B,EAC9B,MAAM,EACN,4BAA4B,EAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAC,qBAAqB,EAAC,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAC,YAAY,EAAC,MAAM,IAAI,CAAC;AAChC,OAAO,EAA8B,MAAM,4BAA4B,CAAC;AAiBxE,MAAM,OAAO,oBACT,SAAQ,MAAkB;IAE1B,uFAAuF;IACtE,aAAa,GAA4C,EAAE,CAAC;IACtE,MAAM,CAAC,kBAAkB,CAAS;
|
|
1
|
+
{"version":3,"file":"FirebaseModule.js","sourceRoot":"","sources":["../../src/main/app-backend/FirebaseModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,0BAA0B,EAC1B,8BAA8B,EAC9B,MA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AC,aAAa,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC;QAE1C,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,cAAc,CAAC,SAAiB;QAC5B,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as functionsV1 from "firebase-functions/v1";
|
|
2
|
+
import { type CloudFunction, type HttpsFunction } from "firebase-functions/v1";
|
|
3
|
+
import { type HttpsFunction as HttpsFunctionV2 } from "firebase-functions/v2/https";
|
|
4
|
+
import { type MemoryOption } from "firebase-functions/v2/options";
|
|
5
|
+
import type { CloudFunction as CloudFunctionV2 } from "firebase-functions/v2/core";
|
|
6
|
+
import { Module } from "@intuitionrobotics/ts-common";
|
|
7
|
+
/**
|
|
8
|
+
* Which Cloud Functions generation a function deploys as.
|
|
9
|
+
* - "v1": legacy gen-1 (HTTPS, Pub/Sub-backed scheduler, classic event triggers)
|
|
10
|
+
* - "v2": gen-2 (Cloud Run backed) — the modern default
|
|
11
|
+
*/
|
|
12
|
+
export type FunctionGeneration = "v1" | "v2";
|
|
13
|
+
export declare const setDefaultFunctionGeneration: (generation: FunctionGeneration) => void;
|
|
14
|
+
export declare const getDefaultFunctionGeneration: () => FunctionGeneration;
|
|
15
|
+
/**
|
|
16
|
+
* Memory units accepted by the neutral options. Both v1 ("1GB") and
|
|
17
|
+
* v2 ("1GiB") spellings are tolerated and translated to the active generation.
|
|
18
|
+
*/
|
|
19
|
+
export type FirebaseFunctionMemory = "128MiB" | "256MiB" | "512MiB" | "1GiB" | "2GiB" | "4GiB" | "8GiB" | "16GiB" | "32GiB" | "128MB" | "256MB" | "512MB" | "1GB" | "2GB" | "4GB" | "8GB";
|
|
20
|
+
/**
|
|
21
|
+
* SDK-version-neutral runtime options. Replaces the v1-only `RuntimeOptions`
|
|
22
|
+
* in the public surface — each generation translates this to its own option shape.
|
|
23
|
+
*/
|
|
24
|
+
export type FirebaseFunctionOptions = {
|
|
25
|
+
generation?: FunctionGeneration;
|
|
26
|
+
region?: string | string[];
|
|
27
|
+
memory?: FirebaseFunctionMemory;
|
|
28
|
+
timeoutSeconds?: number;
|
|
29
|
+
minInstances?: number;
|
|
30
|
+
maxInstances?: number;
|
|
31
|
+
/** v2-only; ignored under v1. */
|
|
32
|
+
concurrency?: number;
|
|
33
|
+
serviceAccount?: string;
|
|
34
|
+
/** Names of secrets to bind (v2 Secret Manager / v1 runtime secrets). */
|
|
35
|
+
secrets?: string[];
|
|
36
|
+
labels?: Record<string, string>;
|
|
37
|
+
};
|
|
38
|
+
/** Any value the Firebase CLI can deploy — covers both generations' return types. */
|
|
39
|
+
export type DeployableFunction = HttpsFunction | CloudFunction<any> | HttpsFunctionV2 | CloudFunctionV2<any>;
|
|
40
|
+
/** Bootstrap config applied once at startup (see {@link configureFirebaseFunctionsRuntime}). */
|
|
41
|
+
export type FirebaseFunctionsRuntimeConfig = {
|
|
42
|
+
/** Pin the deploy region (matches the frontend's hardcoded cloudfunctions.net host). */
|
|
43
|
+
region?: string | string[];
|
|
44
|
+
/** Override the repo-wide default generation. */
|
|
45
|
+
defaultGeneration?: FunctionGeneration;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Call once at process startup (e.g. in the app's index.ts) before functions are built.
|
|
49
|
+
* Pins the region for both generations and optionally sets the default generation.
|
|
50
|
+
*/
|
|
51
|
+
export declare function configureFirebaseFunctionsRuntime(config: FirebaseFunctionsRuntimeConfig): void;
|
|
52
|
+
export interface FirebaseFunctionInterface {
|
|
53
|
+
onDestroy: (() => Promise<void>)[];
|
|
54
|
+
getFunction(): DeployableFunction;
|
|
55
|
+
addOnStart(onStart: () => Promise<void>): void;
|
|
56
|
+
addOnDestroy(onDestroy: () => Promise<void>): void;
|
|
57
|
+
}
|
|
58
|
+
/** Neutral event-context — both v1 `EventContext` and the v2 CloudEvent shim satisfy it. */
|
|
59
|
+
export type FirebaseEventContext = {
|
|
60
|
+
eventId?: string;
|
|
61
|
+
timestamp?: string;
|
|
62
|
+
eventType?: string;
|
|
63
|
+
resource?: any;
|
|
64
|
+
params?: {
|
|
65
|
+
[option: string]: any;
|
|
66
|
+
};
|
|
67
|
+
[key: string]: any;
|
|
68
|
+
};
|
|
69
|
+
export declare function getFormattedFunctionName(name: string): string;
|
|
70
|
+
export declare function buildLabels(name: string, type: string, generation: FunctionGeneration): Record<string, string>;
|
|
71
|
+
/** Runs every onStart hook, then the work, then (always) every onDestroy hook. */
|
|
72
|
+
export declare function runLifecycle<T>(onStart: (() => Promise<void>)[], onDestroy: (() => Promise<void>)[], work: () => Promise<T>): Promise<T | void>;
|
|
73
|
+
export type CommonV2Options = {
|
|
74
|
+
region?: string;
|
|
75
|
+
memory?: MemoryOption;
|
|
76
|
+
timeoutSeconds?: number;
|
|
77
|
+
minInstances?: number;
|
|
78
|
+
maxInstances?: number;
|
|
79
|
+
concurrency?: number;
|
|
80
|
+
serviceAccount?: string;
|
|
81
|
+
secrets?: string[];
|
|
82
|
+
labels?: Record<string, string>;
|
|
83
|
+
};
|
|
84
|
+
/** Build a region-scoped v1 FunctionBuilder with the translated RuntimeOptions + labels. */
|
|
85
|
+
export declare function v1Builder(options: FirebaseFunctionOptions, labels: Record<string, string>): functionsV1.FunctionBuilder;
|
|
86
|
+
/** Translate neutral options to a v2 options object (spread into each trigger's options). */
|
|
87
|
+
export declare function toV2Options(options: FirebaseFunctionOptions, labels: Record<string, string>): CommonV2Options;
|
|
88
|
+
export declare abstract class FirebaseFunction<Config = any> extends Module<Config> implements FirebaseFunctionInterface {
|
|
89
|
+
onDestroy: (() => Promise<void>)[];
|
|
90
|
+
onStart: (() => Promise<void>)[];
|
|
91
|
+
protected options: FirebaseFunctionOptions;
|
|
92
|
+
private generationOverride?;
|
|
93
|
+
constructor(name: string, onStart?: () => Promise<void>, onDestroy?: () => Promise<void>, options?: FirebaseFunctionOptions);
|
|
94
|
+
abstract getFunction(): DeployableFunction;
|
|
95
|
+
protected get generation(): FunctionGeneration;
|
|
96
|
+
/** Override the generation for this function only. */
|
|
97
|
+
setGeneration(generation: FunctionGeneration): this;
|
|
98
|
+
/** Merge in runtime options (memory, region, instances, secrets, generation, ...). */
|
|
99
|
+
setOptions(options: FirebaseFunctionOptions): this;
|
|
100
|
+
protected labels(type: string): Record<string, string>;
|
|
101
|
+
protected runLifecycle<T>(work: () => Promise<T>): Promise<void | T>;
|
|
102
|
+
addOnStart(onStart: () => Promise<void>): void;
|
|
103
|
+
addOnDestroy(onDestroy: () => Promise<void>): void;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=firebase-function-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-core.d.ts","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-core.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,KAAK,aAAa,EAAE,KAAK,aAAa,EAAsB,MAAM,uBAAuB,CAAC;AAClG,OAAO,EAAC,KAAK,aAAa,IAAI,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAmB,KAAK,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAClF,OAAO,KAAK,EAAC,aAAa,IAAI,eAAe,EAAC,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,IAAI,CAAC;AAU7C,eAAO,MAAM,4BAA4B,GAAI,YAAY,kBAAkB,SAE1E,CAAC;AACF,eAAO,MAAM,4BAA4B,0BAA2B,CAAC;AAKrE;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAC5B,QAAQ,GAAG,QAAQ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C,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAI9C,YAAY,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;CAI5D"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Shared infrastructure for the Firebase Function abstraction: the generation
|
|
2
|
+
// switch, SDK-neutral options + v1/v2 translators, lifecycle/label helpers and
|
|
3
|
+
// the FirebaseFunction base class. Each trigger family lives in its own sibling
|
|
4
|
+
// module (firebase-function-<trigger>.ts) and imports from here, so a bundled
|
|
5
|
+
// consumer that uses only one trigger never pulls in the others' v2 SDK subpaths.
|
|
6
|
+
import * as functionsV1 from "firebase-functions/v1";
|
|
7
|
+
import {} from "firebase-functions/v1";
|
|
8
|
+
import {} from "firebase-functions/v2/https";
|
|
9
|
+
import { setGlobalOptions } from "firebase-functions/v2/options";
|
|
10
|
+
import { Module } from "@intuitionrobotics/ts-common";
|
|
11
|
+
/**
|
|
12
|
+
* Repo-wide default generation. New functions deploy as this unless they
|
|
13
|
+
* override it (per instance via FirebaseFunction.setGeneration / options,
|
|
14
|
+
* or globally via {@link setDefaultFunctionGeneration}).
|
|
15
|
+
*
|
|
16
|
+
* One-line rollback: `setDefaultFunctionGeneration("v1")` and redeploy.
|
|
17
|
+
*/
|
|
18
|
+
let DEFAULT_GENERATION = "v2";
|
|
19
|
+
export const setDefaultFunctionGeneration = (generation) => {
|
|
20
|
+
DEFAULT_GENERATION = generation;
|
|
21
|
+
};
|
|
22
|
+
export const getDefaultFunctionGeneration = () => DEFAULT_GENERATION;
|
|
23
|
+
/** Region applied to v1 functions (v2 uses setGlobalOptions); set via {@link configureFirebaseFunctionsRuntime}. */
|
|
24
|
+
let DEFAULT_REGION;
|
|
25
|
+
/**
|
|
26
|
+
* Call once at process startup (e.g. in the app's index.ts) before functions are built.
|
|
27
|
+
* Pins the region for both generations and optionally sets the default generation.
|
|
28
|
+
*/
|
|
29
|
+
export function configureFirebaseFunctionsRuntime(config) {
|
|
30
|
+
if (config.defaultGeneration)
|
|
31
|
+
setDefaultFunctionGeneration(config.defaultGeneration);
|
|
32
|
+
if (config.region) {
|
|
33
|
+
DEFAULT_REGION = config.region;
|
|
34
|
+
// v2 global region is a single region; multi-region requires per-function (HTTPS only).
|
|
35
|
+
setGlobalOptions({ region: Array.isArray(config.region) ? config.region[0] : config.region });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// --- shared helpers (used by every trigger module) ----------------------------
|
|
39
|
+
export function getFormattedFunctionName(name) {
|
|
40
|
+
return name.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/\s/g, "_");
|
|
41
|
+
}
|
|
42
|
+
export function buildLabels(name, type, generation) {
|
|
43
|
+
return {
|
|
44
|
+
infra: "thunderstorm",
|
|
45
|
+
function_name: getFormattedFunctionName(name),
|
|
46
|
+
type,
|
|
47
|
+
version: generation
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Runs every onStart hook, then the work, then (always) every onDestroy hook. */
|
|
51
|
+
export async function runLifecycle(onStart, onDestroy, work) {
|
|
52
|
+
try {
|
|
53
|
+
for (const _onStart of onStart)
|
|
54
|
+
await _onStart();
|
|
55
|
+
return await work();
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
for (const _onDestroy of onDestroy)
|
|
59
|
+
await _onDestroy();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const V1_MEMORY = {
|
|
63
|
+
"128MB": "128MB", "256MB": "256MB", "512MB": "512MB", "1GB": "1GB", "2GB": "2GB", "4GB": "4GB", "8GB": "8GB",
|
|
64
|
+
"128MiB": "128MB", "256MiB": "256MB", "512MiB": "512MB", "1GiB": "1GB", "2GiB": "2GB", "4GiB": "4GB",
|
|
65
|
+
"8GiB": "8GB", "16GiB": "8GB", "32GiB": "8GB"
|
|
66
|
+
};
|
|
67
|
+
const V2_MEMORY = {
|
|
68
|
+
"128MiB": "128MiB", "256MiB": "256MiB", "512MiB": "512MiB", "1GiB": "1GiB", "2GiB": "2GiB", "4GiB": "4GiB",
|
|
69
|
+
"8GiB": "8GiB", "16GiB": "16GiB", "32GiB": "32GiB",
|
|
70
|
+
"128MB": "128MiB", "256MB": "256MiB", "512MB": "512MiB", "1GB": "1GiB", "2GB": "2GiB", "4GB": "4GiB", "8GB": "8GiB"
|
|
71
|
+
};
|
|
72
|
+
/** Build a region-scoped v1 FunctionBuilder with the translated RuntimeOptions + labels. */
|
|
73
|
+
export function v1Builder(options, labels) {
|
|
74
|
+
const runtimeOptions = { labels };
|
|
75
|
+
if (options.memory)
|
|
76
|
+
runtimeOptions.memory = V1_MEMORY[options.memory];
|
|
77
|
+
if (options.timeoutSeconds !== undefined)
|
|
78
|
+
runtimeOptions.timeoutSeconds = options.timeoutSeconds;
|
|
79
|
+
if (options.minInstances !== undefined)
|
|
80
|
+
runtimeOptions.minInstances = options.minInstances;
|
|
81
|
+
if (options.maxInstances !== undefined)
|
|
82
|
+
runtimeOptions.maxInstances = options.maxInstances;
|
|
83
|
+
if (options.serviceAccount)
|
|
84
|
+
runtimeOptions.serviceAccount = options.serviceAccount;
|
|
85
|
+
if (options.secrets)
|
|
86
|
+
runtimeOptions.secrets = options.secrets;
|
|
87
|
+
const region = options.region ?? DEFAULT_REGION;
|
|
88
|
+
const regions = region ? (Array.isArray(region) ? region : [region]) : undefined;
|
|
89
|
+
const base = regions ? functionsV1.region(...regions) : functionsV1;
|
|
90
|
+
return base.runWith(runtimeOptions);
|
|
91
|
+
}
|
|
92
|
+
/** Translate neutral options to a v2 options object (spread into each trigger's options). */
|
|
93
|
+
export function toV2Options(options, labels) {
|
|
94
|
+
const v2 = { labels };
|
|
95
|
+
if (options.memory)
|
|
96
|
+
v2.memory = V2_MEMORY[options.memory];
|
|
97
|
+
// global region already set; this is a per-fn override. v2 non-HTTPS triggers take a single region.
|
|
98
|
+
if (options.region)
|
|
99
|
+
v2.region = Array.isArray(options.region) ? options.region[0] : options.region;
|
|
100
|
+
if (options.timeoutSeconds !== undefined)
|
|
101
|
+
v2.timeoutSeconds = options.timeoutSeconds;
|
|
102
|
+
if (options.minInstances !== undefined)
|
|
103
|
+
v2.minInstances = options.minInstances;
|
|
104
|
+
if (options.maxInstances !== undefined)
|
|
105
|
+
v2.maxInstances = options.maxInstances;
|
|
106
|
+
if (options.concurrency !== undefined)
|
|
107
|
+
v2.concurrency = options.concurrency;
|
|
108
|
+
if (options.serviceAccount)
|
|
109
|
+
v2.serviceAccount = options.serviceAccount;
|
|
110
|
+
if (options.secrets)
|
|
111
|
+
v2.secrets = options.secrets;
|
|
112
|
+
return v2;
|
|
113
|
+
}
|
|
114
|
+
// --- base class ---------------------------------------------------------------
|
|
115
|
+
export class FirebaseFunction extends Module {
|
|
116
|
+
onDestroy = [];
|
|
117
|
+
onStart = [];
|
|
118
|
+
options;
|
|
119
|
+
generationOverride;
|
|
120
|
+
constructor(name, onStart, onDestroy, options = {}) {
|
|
121
|
+
super(name);
|
|
122
|
+
this.options = options;
|
|
123
|
+
this.generationOverride = options.generation;
|
|
124
|
+
if (onStart)
|
|
125
|
+
this.onStart.push(onStart);
|
|
126
|
+
if (onDestroy)
|
|
127
|
+
this.onDestroy.push(onDestroy);
|
|
128
|
+
}
|
|
129
|
+
// Resolved lazily (not in the constructor) so the repo-wide default set by
|
|
130
|
+
// configureFirebaseFunctionsRuntime() at startup wins, regardless of the
|
|
131
|
+
// order module singletons happen to be constructed in.
|
|
132
|
+
get generation() {
|
|
133
|
+
return this.generationOverride ?? DEFAULT_GENERATION;
|
|
134
|
+
}
|
|
135
|
+
/** Override the generation for this function only. */
|
|
136
|
+
setGeneration(generation) {
|
|
137
|
+
this.generationOverride = generation;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
/** Merge in runtime options (memory, region, instances, secrets, generation, ...). */
|
|
141
|
+
setOptions(options) {
|
|
142
|
+
this.options = { ...this.options, ...options };
|
|
143
|
+
if (options.generation)
|
|
144
|
+
this.generationOverride = options.generation;
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
labels(type) {
|
|
148
|
+
return buildLabels(this.getName(), type, this.generation);
|
|
149
|
+
}
|
|
150
|
+
runLifecycle(work) {
|
|
151
|
+
return runLifecycle(this.onStart, this.onDestroy, work);
|
|
152
|
+
}
|
|
153
|
+
addOnStart(onStart) {
|
|
154
|
+
this.onStart.push(onStart);
|
|
155
|
+
}
|
|
156
|
+
;
|
|
157
|
+
addOnDestroy(onDestroy) {
|
|
158
|
+
this.onDestroy.push(onDestroy);
|
|
159
|
+
}
|
|
160
|
+
;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=firebase-function-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-core.js","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-core.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+EAA+E;AAC/E,gFAAgF;AAChF,8EAA8E;AAC9E,kFAAkF;AAClF,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAA6D,MAAM,uBAAuB,CAAC;AAClG,OAAO,EAAuC,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAC,gBAAgB,EAAoB,MAAM,+BAA+B,CAAC;AAElF,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AASpD;;;;;;GAMG;AACH,IAAI,kBAAkB,GAAuB,IAAI,CAAC;AAClD,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,UAA8B,EAAE,EAAE;IAC3E,kBAAkB,GAAG,UAAU,CAAC;AACpC,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,EAAE,CAAC,kBAAkB,CAAC;AAErE,oHAAoH;AACpH,IAAI,cAA6C,CAAC;AA4ClD;;;GAGG;AACH,MAAM,UAAU,iCAAiC,CAAC,MAAsC;IACpF,IAAI,MAAM,CAAC,iBAAiB;QACxB,4BAA4B,CAAC,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AAC,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAC,CAAC;QAC7C,IAAI,OAAO,CAAC,UAAU;YAAE,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;QACrE,OAAO,IAAI,CAAC;IAChB,CAAC;IAES,MAAM,CAAC,IAAY;QACzB,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9D,CAAC;IAES,YAAY,CAAI,IAAsB;QAC5C,OAAO,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IAEM,UAAU,CAAC,OAA4B;QAC1C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAAA,CAAC;IAEK,YAAY,CAAC,SAA8B;QAC9C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAAA,CAAC;CAEL"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DeployableFunction, FirebaseFunction } from "./firebase-function-core.js";
|
|
2
|
+
export declare abstract class FirebaseFunctionModule<DataType = any, Config = any> extends FirebaseFunction<Config> {
|
|
3
|
+
private readonly listeningPath;
|
|
4
|
+
protected constructor(listeningPath: string, name: string, onStart?: () => Promise<void>, onDestroy?: () => Promise<void>);
|
|
5
|
+
abstract processChanges(before: DataType, after: DataType, params: {
|
|
6
|
+
[param: string]: any;
|
|
7
|
+
}): Promise<any>;
|
|
8
|
+
getFunction: () => DeployableFunction;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=firebase-function-database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-database.d.ts","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-database.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,KAAK,kBAAkB,EAAE,gBAAgB,EAAyB,MAAM,6BAA6B,CAAC;AAI9G,8BAAsB,sBAAsB,CAAC,QAAQ,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,CACrE,SAAQ,gBAAgB,CAAC,MAAM,CAAC;IAEhC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IAEvC,SAAS,aAAa,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC;IAOzH,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAE1G,WAAW,QAAO,kBAAkB,CAmBlC;CACL"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Change } from "firebase-functions/v1";
|
|
2
|
+
import { onValueWritten } from "firebase-functions/v2/database";
|
|
3
|
+
import { deepClone } from "@intuitionrobotics/ts-common";
|
|
4
|
+
import { FirebaseFunction, toV2Options, v1Builder } from "./firebase-function-core.js";
|
|
5
|
+
export class FirebaseFunctionModule extends FirebaseFunction {
|
|
6
|
+
listeningPath;
|
|
7
|
+
constructor(listeningPath, name, onStart, onDestroy) {
|
|
8
|
+
super(name);
|
|
9
|
+
this.listeningPath = listeningPath;
|
|
10
|
+
if (onStart)
|
|
11
|
+
this.addOnStart(onStart);
|
|
12
|
+
if (onDestroy)
|
|
13
|
+
this.addOnDestroy(onDestroy);
|
|
14
|
+
}
|
|
15
|
+
getFunction = () => {
|
|
16
|
+
const labels = this.labels("realtime-db-listener");
|
|
17
|
+
if (this.generation === "v1")
|
|
18
|
+
return v1Builder(this.options, labels).database.ref(this.listeningPath).onWrite(async (change, context) => this.runLifecycle(async () => {
|
|
19
|
+
const before = change.before && change.before.val();
|
|
20
|
+
const after = change.after && change.after.val();
|
|
21
|
+
return this.processChanges(before, after, deepClone(context.params));
|
|
22
|
+
}));
|
|
23
|
+
return onValueWritten({ ...toV2Options(this.options, labels), ref: this.listeningPath }, async (event) => this.runLifecycle(async () => {
|
|
24
|
+
const before = event.data.before && event.data.before.val();
|
|
25
|
+
const after = event.data.after && event.data.after.val();
|
|
26
|
+
return this.processChanges(before, after, deepClone(event.params));
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=firebase-function-database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-database.js","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAmC,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAC,cAAc,EAAC,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAA0B,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,6BAA6B,CAAC;AAI9G,MAAM,OAAgB,sBAClB,SAAQ,gBAAwB;IAEf,aAAa,CAAS;IAEvC,YAAsB,aAAqB,EAAE,IAAY,EAAE,OAA6B,EAAE,SAA+B;QACrH,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,OAAO;YAAE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,SAAS;YAAE,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;IAID,WAAW,GAAG,GAAuB,EAAE;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;QAEnD,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI;Y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, type FirebaseFunctionInterface, type FirebaseFunctionOptions } from "./firebase-function-core.js";
|
|
3
|
+
export declare class Firebase_ExpressFunction implements FirebaseFunctionInterface {
|
|
4
|
+
private readonly express;
|
|
5
|
+
private readonly name;
|
|
6
|
+
private readonly options;
|
|
7
|
+
private readonly generationOverride?;
|
|
8
|
+
onDestroy: (() => Promise<void>)[];
|
|
9
|
+
onStart: (() => Promise<void>)[];
|
|
10
|
+
constructor(_express: Express, name?: string, onStart?: () => Promise<void>, onDestroy?: () => Promise<void>, options?: FirebaseFunctionOptions);
|
|
11
|
+
private get generation();
|
|
12
|
+
addOnStart(onStart: () => Promise<void>): void;
|
|
13
|
+
addOnDestroy(onDestroy: () => Promise<void>): void;
|
|
14
|
+
getName(): string;
|
|
15
|
+
getFunction: () => DeployableFunction;
|
|
16
|
+
private runLifecycleAndExpress;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=firebase-function-express.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-express.d.ts","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-express.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,OAAO,EAA8B,MAAM,SAAS,CAAC;AAElE,OAAO,EAEH,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAM/B,MAAM,6BAA6B,CAAC;AAErC,qBAAa,wBACT,YAAW,yBAAyB;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAClD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAqB;IACzD,SAAS,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAM;IACxC,OAAO,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAM;gBAE1B,QAAQ,EAAE,OAAO,EAAE,IAAI,SAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,GAAE,uBAA4B;IASlJ,OAAO,KAAK,UAAU,GAErB;IAEM,UAAU,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAI9C,YAAY,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAIzD,OAAO;IAIP,WAAW,QAAO,kBAAkB,CASlC;IAEF,OAAO,CAAC,sBAAsB;CAGjC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {} from "express";
|
|
2
|
+
import { onRequest } from "firebase-functions/v2/https";
|
|
3
|
+
import { buildLabels, getDefaultFunctionGeneration, runLifecycle, toV2Options, v1Builder } from "./firebase-function-core.js";
|
|
4
|
+
export class Firebase_ExpressFunction {
|
|
5
|
+
express;
|
|
6
|
+
name;
|
|
7
|
+
options;
|
|
8
|
+
generationOverride;
|
|
9
|
+
onDestroy = [];
|
|
10
|
+
onStart = [];
|
|
11
|
+
constructor(_express, name = "api", onStart, onDestroy, options = {}) {
|
|
12
|
+
this.express = _express;
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.generationOverride = options.generation;
|
|
16
|
+
if (onStart)
|
|
17
|
+
this.onStart.push(onStart);
|
|
18
|
+
if (onDestroy)
|
|
19
|
+
this.onDestroy.push(onDestroy);
|
|
20
|
+
}
|
|
21
|
+
get generation() {
|
|
22
|
+
return this.generationOverride ?? getDefaultFunctionGeneration();
|
|
23
|
+
}
|
|
24
|
+
addOnStart(onStart) {
|
|
25
|
+
this.onStart.push(onStart);
|
|
26
|
+
}
|
|
27
|
+
;
|
|
28
|
+
addOnDestroy(onDestroy) {
|
|
29
|
+
this.onDestroy.push(onDestroy);
|
|
30
|
+
}
|
|
31
|
+
;
|
|
32
|
+
getName() {
|
|
33
|
+
return this.name;
|
|
34
|
+
}
|
|
35
|
+
getFunction = () => {
|
|
36
|
+
const labels = buildLabels(this.getName(), "https", this.generation);
|
|
37
|
+
const handler = async (req, resp) => this.runLifecycleAndExpress(req, resp);
|
|
38
|
+
if (this.generation === "v1")
|
|
39
|
+
return v1Builder(this.options, labels).https.onRequest(handler);
|
|
40
|
+
return onRequest(toV2Options(this.options, labels), handler);
|
|
41
|
+
};
|
|
42
|
+
runLifecycleAndExpress(req, resp) {
|
|
43
|
+
return runLifecycle(this.onStart, this.onDestroy, async () => this.express(req, resp));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=firebase-function-express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-express.js","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-express.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,MAAM,SAAS,CAAC;AAClE,OAAO,EAAC,SAAS,EAAC,MAAM,6BAA6B,CAAC;AACtD,OAAO,EACH,WAAW,EAKX,4BAA4B,EAC5B,YAAY,EACZ,WAAW,EACX,SAAS,EACZ,MAAM,6BAA6B,CAAC;AAErC,MAAM,OAAO,wBAAwB;IAEhB,OAAO,CAAU;IACjB,IAAI,CAAS;IACb,OAAO,CAA0B;IACjC,kBAAkB,CAAsB;IACzD,SAAS,GAA4B,EAAE,CAAC;IACxC,OAAO,GAA4B,EAAE,CAAC;IAEtC,YAAY,QAAiB,EAAE,IAAI,GAAG,KAAK,EAAE,OAA6B,EAAE,SAA+B,EAAE,UAAmC,EAAE;QAC9I,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;QAC7C,IAAI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IAAI,CAAC,CAAC,CAAC;IAC3F,CAAC;CACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DeployableFunction, FirebaseFunction } from "./firebase-function-core.js";
|
|
2
|
+
export type FirestoreConfigs = {
|
|
3
|
+
configs: any;
|
|
4
|
+
};
|
|
5
|
+
export declare abstract class FirestoreFunctionModule<DataType extends object, Config extends FirestoreConfigs = FirestoreConfigs> extends FirebaseFunction<Config> {
|
|
6
|
+
private readonly collectionName;
|
|
7
|
+
protected constructor(collectionName: string, name: string, onStart?: () => Promise<void>, onDestroy?: () => Promise<void>);
|
|
8
|
+
abstract processChanges(params: {
|
|
9
|
+
[param: string]: any;
|
|
10
|
+
}, before?: DataType, after?: DataType): Promise<any>;
|
|
11
|
+
getFunction: () => DeployableFunction;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=firebase-function-firestore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-firestore.d.ts","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-firestore.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,KAAK,kBAAkB,EAAE,gBAAgB,EAAyB,MAAM,6BAA6B,CAAC;AAI9G,MAAM,MAAM,gBAAgB,GAAG;IAC3B,OAAO,EAAE,GAAG,CAAA;CACf,CAAA;AAGD,8BAAsB,uBAAuB,CAAC,QAAQ,SAAS,MAAM,EAAE,MAAM,SAAS,gBAAgB,GAAG,gBAAgB,CACrH,SAAQ,gBAAgB,CAAC,MAAM,CAAC;IAEhC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAExC,SAAS,aAAa,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC;IAK1H,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAE5G,WAAW,QAAO,kBAAkB,CAoBlC;CACL"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Change } from "firebase-functions/v1";
|
|
2
|
+
import { onDocumentWritten } from "firebase-functions/v2/firestore";
|
|
3
|
+
import { deepClone } from "@intuitionrobotics/ts-common";
|
|
4
|
+
import { FirebaseFunction, toV2Options, v1Builder } from "./firebase-function-core.js";
|
|
5
|
+
//TODO: I would like to add a type for the params..
|
|
6
|
+
export class FirestoreFunctionModule extends FirebaseFunction {
|
|
7
|
+
collectionName;
|
|
8
|
+
constructor(collectionName, name, onStart, onDestroy) {
|
|
9
|
+
super(name, onStart, onDestroy);
|
|
10
|
+
this.collectionName = collectionName;
|
|
11
|
+
}
|
|
12
|
+
getFunction = () => {
|
|
13
|
+
const labels = this.labels("firestore-listener");
|
|
14
|
+
const documentPath = `${this.collectionName}/{docId}`;
|
|
15
|
+
if (this.generation === "v1")
|
|
16
|
+
return v1Builder(this.options, labels).firestore.document(documentPath).onWrite(async (change, context) => this.runLifecycle(async () => {
|
|
17
|
+
const before = change.before && change.before.data();
|
|
18
|
+
const after = change.after && change.after.data();
|
|
19
|
+
return this.processChanges(deepClone(context.params), before, after);
|
|
20
|
+
}));
|
|
21
|
+
return onDocumentWritten({ ...toV2Options(this.options, labels), document: documentPath }, async (event) => this.runLifecycle(async () => {
|
|
22
|
+
const before = event.data?.before.data();
|
|
23
|
+
const after = event.data?.after.data();
|
|
24
|
+
return this.processChanges(deepClone(event.params), before, after);
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=firebase-function-firestore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-firestore.js","sourceRoot":"","sources":["../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K,CAAC,CAAC;YACzE,CAAC,CAAC,CAAC,CAAC;QAEhB,OAAO,iBAAiB,CAAC,EAAC,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAC,EACnF,KAAK,EAAE,KAAK,EAAE,EAAE,CACZ,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;YACzB,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAA0B,CAAC;YACjE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAA0B,CAAC;YAC/D,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC,CAAC;IAChB,CAAC,CAAC;CACL"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Request, type Response } from "express";
|
|
2
|
+
import { type DeployableFunction, FirebaseFunction } from "./firebase-function-core.js";
|
|
3
|
+
export declare abstract class Firebase_HttpsFunction<Config = any> extends FirebaseFunction<Config> {
|
|
4
|
+
abstract process(req: Request, res: Response): Promise<any>;
|
|
5
|
+
getFunction: () => DeployableFunction;
|
|
6
|
+
onFunctionReady: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=firebase-function-https.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-https.d.ts","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-https.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEpD,OAAO,EAAC,KAAK,kBAAkB,EAAE,gBAAgB,EAAyB,MAAM,6BAA6B,CAAC;AAE9G,8BAAsB,sBAAsB,CAAC,MAAM,GAAG,GAAG,CACrD,SAAQ,gBAAgB,CAAC,MAAM,CAAC;IAEhC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAE3D,WAAW,QAAO,kBAAkB,CASlC;IAEF,eAAe,sBAEb;CACL"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {} from "express";
|
|
2
|
+
import { onRequest } from "firebase-functions/v2/https";
|
|
3
|
+
import { FirebaseFunction, toV2Options, v1Builder } from "./firebase-function-core.js";
|
|
4
|
+
export class Firebase_HttpsFunction extends FirebaseFunction {
|
|
5
|
+
getFunction = () => {
|
|
6
|
+
const labels = this.labels("https");
|
|
7
|
+
const handler = async (req, res) => this.runLifecycle(async () => this.process(req, res));
|
|
8
|
+
if (this.generation === "v1")
|
|
9
|
+
return v1Builder(this.options, labels).https.onRequest(handler);
|
|
10
|
+
return onRequest(toV2Options(this.options, labels), handler);
|
|
11
|
+
};
|
|
12
|
+
onFunctionReady = async () => {
|
|
13
|
+
return;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=firebase-function-https.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-https.js","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-https.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,MAAM,SAAS,CAAC;AACpD,OAAO,EAAC,SAAS,EAAC,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAA0B,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,6BAA6B,CAAC;AAE9G,MAAM,OAAgB,sBAClB,SAAQ,gBAAwB;IAIhC,WAAW,GAAG,GAAuB,EAAE;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,OAAO,GAAG,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE,CAClD,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAE1D,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI;YACxB,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAEpE,OAAO,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC,CAAC;IAEF,eAAe,GAAG,KAAK,IAAI,EAAE;QACzB,OAAO;IACX,CAAC,CAAC;CACL"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type StringMap } from "@intuitionrobotics/ts-common";
|
|
2
|
+
import { type DeployableFunction, type FirebaseEventContext, FirebaseFunction } from "./firebase-function-core.js";
|
|
3
|
+
export type TopicMessage = {
|
|
4
|
+
data: string;
|
|
5
|
+
attributes: StringMap;
|
|
6
|
+
};
|
|
7
|
+
export declare abstract class Firebase_PubSubFunction<T, Config = any> extends FirebaseFunction<Config> {
|
|
8
|
+
private readonly topic;
|
|
9
|
+
protected constructor(topic: string, name: string, onStart?: () => Promise<void>, onDestroy?: () => Promise<void>);
|
|
10
|
+
abstract onPublish(object: T | undefined, originalMessage: TopicMessage, context: FirebaseEventContext): Promise<any>;
|
|
11
|
+
private _onPublish;
|
|
12
|
+
private parseData;
|
|
13
|
+
getFunction: () => DeployableFunction;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=firebase-function-pubsub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-function-pubsub.d.ts","sourceRoot":"","sources":["../../../src/main/app-backend/functions/firebase-function-pubsub.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2D,KAAK,SAAS,EAAC,MAAM,8BAA8B,CAAC;AACtH,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,gBAAgB,EAGnB,MAAM,6BAA6B,CAAC;AAErC,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,SAAS,CAAA;CAAE,CAAC;AAEnE,8BAAsB,uBAAuB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CACzD,SAAQ,gBAAgB,CAAC,MAAM,CAAC;IAEhC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B,SAAS,aAAa,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC;IAKjH,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC;IAErH,OAAO,CAAC,UAAU,CAahB;IAEF,OAAO,CAAC,SAAS;IAUjB,WAAW,QAAO,kBAAkB,CAmBlC;CACL"}
|