Skip to content

Commit 6d731d0

Browse files
authored
Parse Firebase extensions from code (#1590)
Parse Firebase extensions out of code
1 parent 5145e18 commit 6d731d0

File tree

30 files changed

+1135
-18
lines changed

30 files changed

+1135
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Future Extensions support (#1590)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* TaskQueue/LifecycleEvent/RuntimeStatus Tester SDK for [email protected]
3+
*
4+
* When filing bugs or feature requests please specify:
5+
* "Extensions SDK v1.0.0 for Local extension.
6+
* https://github.com/firebase/firebase-tools/issues/new/choose
7+
*
8+
* GENERATED FILE. DO NOT EDIT.
9+
*/
10+
export type DoBackfillParam = "True" | "False";
11+
export type LocationParam =
12+
| "us-central1"
13+
| "us-east1"
14+
| "us-east4"
15+
| "europe-west1"
16+
| "europe-west2"
17+
| "europe-west3"
18+
| "asia-east2"
19+
| "asia-northeast1";
20+
/**
21+
* Parameters for [email protected] extension
22+
*/
23+
export interface BackfillParams {
24+
/**
25+
* Do a backfill
26+
*/
27+
DO_BACKFILL: DoBackfillParam;
28+
/**
29+
* Cloud Functions location
30+
*/
31+
LOCATION: LocationParam;
32+
}
33+
export declare function backfill(instanceId: string, params: BackfillParams): Backfill;
34+
/**
35+
* TaskQueue/LifecycleEvent/RuntimeStatus Tester
36+
* A tester for the TaskQueue/LCE/RuntimeStatus project
37+
*/
38+
export declare class Backfill {
39+
private instanceId;
40+
private params;
41+
readonly FIREBASE_EXTENSION_LOCAL_PATH =
42+
"./functions/generated/extensions/local/backfill/0.0.2/src";
43+
constructor(instanceId: string, params: BackfillParams);
44+
getInstanceId(): string;
45+
getParams(): BackfillParams;
46+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
/**
3+
* TaskQueue/LifecycleEvent/RuntimeStatus Tester SDK for [email protected]
4+
*
5+
* When filing bugs or feature requests please specify:
6+
* "Extensions SDK v1.0.0 for Local extension.
7+
* https://github.com/firebase/firebase-tools/issues/new/choose
8+
*
9+
* GENERATED FILE. DO NOT EDIT.
10+
*/
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
exports.backfill = exports.backfill = void 0;
13+
function backfill(instanceId, params) {
14+
return new Backfill(instanceId, params);
15+
}
16+
exports.backfill = backfill;
17+
/**
18+
* TaskQueue/LifecycleEvent/RuntimeStatus Tester
19+
* A tester for the TaskQueue/LCE/RuntimeStatus project
20+
*/
21+
class Backfill {
22+
constructor(instanceId, params) {
23+
this.instanceId = instanceId;
24+
this.params = params;
25+
this.FIREBASE_EXTENSION_LOCAL_PATH = "./functions/generated/extensions/local/backfill/0.0.2/src";
26+
}
27+
getInstanceId() { return this.instanceId; }
28+
getParams() { return this.params; }
29+
}
30+
exports.Backfill = Backfill;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@firebase-extensions/local-backfill-sdk",
3+
"main": "./index.js"
4+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/**
2+
* Translate Text in Firestore SDK for [email protected]
3+
*
4+
* When filing bugs or feature requests please specify:
5+
* "Extensions SDK v1.0.0 for [email protected]"
6+
* https://github.com/firebase/firebase-tools/issues/new/choose
7+
*
8+
* GENERATED FILE. DO NOT EDIT.
9+
*/
10+
import { CloudEvent } from "../../../../v2";
11+
import { EventarcTriggerOptions } from "../../../../v2/eventarc";
12+
export type EventCallback<T> = (event: CloudEvent<T>) => unknown | Promise<unknown>;
13+
export type SimpleEventarcTriggerOptions = Omit<
14+
EventarcTriggerOptions,
15+
"eventType" | "channel" | "region"
16+
>;
17+
export type EventArcRegionType = "us-central1" | "us-west1" | "europe-west4" | "asia-northeast1";
18+
export type SystemFunctionVpcConnectorEgressSettingsParam =
19+
| "VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED"
20+
| "PRIVATE_RANGES_ONLY"
21+
| "ALL_TRAFFIC";
22+
export type SystemFunctionIngressSettingsParam =
23+
| "ALLOW_ALL"
24+
| "ALLOW_INTERNAL_ONLY"
25+
| "ALLOW_INTERNAL_AND_GCLB";
26+
export type SystemFunctionLocationParam =
27+
| "us-central1"
28+
| "us-east1"
29+
| "us-east4"
30+
| "us-west1"
31+
| "us-west2"
32+
| "us-west3"
33+
| "us-west4"
34+
| "europe-central2"
35+
| "europe-west1"
36+
| "europe-west2"
37+
| "europe-west3"
38+
| "europe-west6"
39+
| "asia-east1"
40+
| "asia-east2"
41+
| "asia-northeast1"
42+
| "asia-northeast2"
43+
| "asia-northeast3"
44+
| "asia-south1"
45+
| "asia-southeast1"
46+
| "asia-southeast2"
47+
| "northamerica-northeast1"
48+
| "southamerica-east1"
49+
| "australia-southeast1";
50+
export type SystemFunctionMemoryParam = "128" | "256" | "512" | "1024" | "2048" | "4096" | "8192";
51+
/**
52+
* Parameters for [email protected] extension
53+
*/
54+
export interface FirestoreTranslateTextParams {
55+
/**
56+
* Target languages for translations, as a comma-separated list
57+
*/
58+
LANGUAGES: string;
59+
/**
60+
* Collection path
61+
*/
62+
COLLECTION_PATH: string;
63+
/**
64+
* Input field name
65+
*/
66+
INPUT_FIELD_NAME: string;
67+
/**
68+
* Translations output field name
69+
*/
70+
OUTPUT_FIELD_NAME: string;
71+
/**
72+
* Languages field name
73+
*/
74+
LANGUAGES_FIELD_NAME?: string;
75+
/**
76+
* Event Arc Region
77+
*/
78+
_EVENT_ARC_REGION?: EventArcRegionType;
79+
/**
80+
* Function timeout seconds
81+
*/
82+
_FUNCTION_TIMEOUT_SECONDS?: string;
83+
/**
84+
* VPC Connector
85+
*/
86+
_FUNCTION_VPC_CONNECTOR?: string;
87+
/**
88+
* VPC Connector Egress settings
89+
*/
90+
_FUNCTION_VPC_CONNECTOR_EGRESS_SETTINGS?: SystemFunctionVpcConnectorEgressSettingsParam;
91+
/**
92+
* Minimum function instances
93+
*/
94+
_FUNCTION_MIN_INSTANCES?: string;
95+
/**
96+
* Maximum function instances
97+
*/
98+
_FUNCTION_MAX_INSTANCES?: string;
99+
/**
100+
* Function ingress settings
101+
*/
102+
_FUNCTION_INGRESS_SETTINGS?: SystemFunctionIngressSettingsParam;
103+
/**
104+
* Function labels
105+
*/
106+
_FUNCTION_LABELS?: string;
107+
/**
108+
* KMS key name
109+
*/
110+
_FUNCTION_KMS_KEY_NAME?: string;
111+
/**
112+
* Docker repository
113+
*/
114+
_FUNCTION_DOCKER_REPOSITORY?: string;
115+
/**
116+
* Cloud Functions location
117+
*/
118+
_FUNCTION_LOCATION: SystemFunctionLocationParam;
119+
/**
120+
* Function memory
121+
*/
122+
_FUNCTION_MEMORY?: SystemFunctionMemoryParam;
123+
}
124+
export declare function firestoreTranslateText(
125+
instanceId: string,
126+
params: FirestoreTranslateTextParams
127+
): FirestoreTranslateText;
128+
/**
129+
* Translate Text in Firestore
130+
* Translates strings written to a Cloud Firestore collection into multiple languages (uses Cloud Translation API).
131+
*/
132+
export declare class FirestoreTranslateText {
133+
private instanceId;
134+
private params;
135+
events: string[];
136+
readonly FIREBASE_EXTENSION_REFERENCE = "firebase/[email protected]";
137+
readonly EXTENSION_VERSION = "0.1.18";
138+
constructor(instanceId: string, params: FirestoreTranslateTextParams);
139+
getInstanceId(): string;
140+
getParams(): FirestoreTranslateTextParams;
141+
/**
142+
* Occurs when a trigger has been called within the Extension, and will include data such as the context of the trigger request.
143+
*/
144+
onStart<T = unknown>(
145+
callback: EventCallback<T>,
146+
options?: SimpleEventarcTriggerOptions
147+
): import("firebase-functions/v2").CloudFunction<CloudEvent<T>>;
148+
/**
149+
* Occurs when image resizing completes successfully. The event will contain further details about specific formats and sizes.
150+
*/
151+
onSuccess<T = unknown>(
152+
callback: EventCallback<T>,
153+
options?: SimpleEventarcTriggerOptions
154+
): import("firebase-functions/v2").CloudFunction<CloudEvent<T>>;
155+
/**
156+
* Occurs when an issue has been experienced in the Extension. This will include any error data that has been included within the Error Exception.
157+
*/
158+
onError<T = unknown>(
159+
callback: EventCallback<T>,
160+
options?: SimpleEventarcTriggerOptions
161+
): import("firebase-functions/v2").CloudFunction<CloudEvent<T>>;
162+
/**
163+
* Occurs when the function is settled. Provides no customized data other than the context.
164+
*/
165+
onCompletion<T = unknown>(
166+
callback: EventCallback<T>,
167+
options?: SimpleEventarcTriggerOptions
168+
): import("firebase-functions/v2").CloudFunction<CloudEvent<T>>;
169+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"use strict";
2+
/**
3+
* Translate Text in Firestore SDK for [email protected]
4+
*
5+
* When filing bugs or feature requests please specify:
6+
* "Extensions SDK v1.0.0 for [email protected]"
7+
* https://github.com/firebase/firebase-tools/issues/new/choose
8+
*
9+
* GENERATED FILE. DO NOT EDIT.
10+
*/
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
exports.FirestoreTranslateText = exports.firestoreTranslateText = void 0;
13+
const eventarc_1 = require("firebase-functions/v2/eventarc");
14+
function firestoreTranslateText(instanceId, params) {
15+
return new FirestoreTranslateText(instanceId, params);
16+
}
17+
exports.firestoreTranslateText = firestoreTranslateText;
18+
/**
19+
* Translate Text in Firestore
20+
* Translates strings written to a Cloud Firestore collection into multiple languages (uses Cloud Translation API).
21+
*/
22+
class FirestoreTranslateText {
23+
constructor(instanceId, params) {
24+
this.instanceId = instanceId;
25+
this.params = params;
26+
this.events = [];
27+
this.FIREBASE_EXTENSION_REFERENCE = "firebase/[email protected]";
28+
this.EXTENSION_VERSION = "0.1.18";
29+
}
30+
getInstanceId() { return this.instanceId; }
31+
getParams() { return this.params; }
32+
/**
33+
* Occurs when a trigger has been called within the Extension, and will include data such as the context of the trigger request.
34+
*/
35+
onStart(callback, options) {
36+
this.events.push("firebase.extensions.firestore-translate-text.v1.onStart");
37+
return (0, eventarc_1.onCustomEventPublished)(Object.assign(Object.assign({}, options), { "eventType": "firebase.extensions.firestore-translate-text.v1.onStart", "channel": `projects/locations/${this.params._EVENT_ARC_REGION}/channels/firebase`, "region": `${this.params._EVENT_ARC_REGION}` }), callback);
38+
}
39+
/**
40+
* Occurs when image resizing completes successfully. The event will contain further details about specific formats and sizes.
41+
*/
42+
onSuccess(callback, options) {
43+
this.events.push("firebase.extensions.firestore-translate-text.v1.onSuccess");
44+
return (0, eventarc_1.onCustomEventPublished)(Object.assign(Object.assign({}, options), { "eventType": "firebase.extensions.firestore-translate-text.v1.onSuccess", "channel": `projects/locations/${this.params._EVENT_ARC_REGION}/channels/firebase`, "region": `${this.params._EVENT_ARC_REGION}` }), callback);
45+
}
46+
/**
47+
* Occurs when an issue has been experienced in the Extension. This will include any error data that has been included within the Error Exception.
48+
*/
49+
onError(callback, options) {
50+
this.events.push("firebase.extensions.firestore-translate-text.v1.onError");
51+
return (0, eventarc_1.onCustomEventPublished)(Object.assign(Object.assign({}, options), { "eventType": "firebase.extensions.firestore-translate-text.v1.onError", "channel": `projects/locations/${this.params._EVENT_ARC_REGION}/channels/firebase`, "region": `${this.params._EVENT_ARC_REGION}` }), callback);
52+
}
53+
/**
54+
* Occurs when the function is settled. Provides no customized data other than the context.
55+
*/
56+
onCompletion(callback, options) {
57+
this.events.push("firebase.extensions.firestore-translate-text.v1.onCompletion");
58+
return (0, eventarc_1.onCustomEventPublished)(Object.assign(Object.assign({}, options), { "eventType": "firebase.extensions.firestore-translate-text.v1.onCompletion", "channel": `projects/locations/${this.params._EVENT_ARC_REGION}/channels/firebase`, "region": `${this.params._EVENT_ARC_REGION}` }), callback);
59+
}
60+
}
61+
exports.FirestoreTranslateText = FirestoreTranslateText;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@firebase-extensions/firebase-firestore-translate-text-sdk",
3+
"main": "./index.js"
4+
}

scripts/bin-test/run.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ set -ex # Immediately exit on failure
55
npm run build
66
npm link
77

8-
# Link local SDK to all test sources.
8+
# Link the extensions SDKs for the testing environment.
9+
(cd scripts/bin-test/extsdks/local && npm link)
10+
(cd scripts/bin-test/extsdks/translate && npm link)
11+
(cd scripts/bin-test/extsdks/translate && npm link firebase-functions)
12+
13+
# Link SDKs to all test sources.
914
for f in scripts/bin-test/sources/*; do
1015
if [ -d "$f" ]; then
1116
(cd "$f" && npm link firebase-functions)
17+
(cd "$f" && npm link @firebase-extensions/firebase-firestore-translate-text-sdk)
18+
(cd "$f" && npm link @firebase-extensions/local-backfill-sdk)
1219
fi
1320
done
1421

scripts/bin-test/sources/commonjs-grouped/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const functions = require("firebase-functions");
22
const functionsv2 = require("firebase-functions/v2");
3+
const firestoreTranslateText = require("@firebase-extensions/firebase-firestore-translate-text-sdk").firestoreTranslateText;
4+
const backfill = require("@firebase-extensions/local-backfill-sdk").backfill;
5+
36

47
exports.v1http = functions.https.onRequest((req, resp) => {
58
resp.status(200).send("PASS");
@@ -17,4 +20,27 @@ exports.v2callable = functionsv2.https.onCall(() => {
1720
return "PASS";
1821
});
1922

23+
// A Firebase extension by ref
24+
const extRef1 = firestoreTranslateText("extRef1", {
25+
"COLLECTION_PATH": "collection1",
26+
"INPUT_FIELD_NAME": "input1",
27+
"LANGUAGES": "de,es",
28+
"OUTPUT_FIELD_NAME": "translated",
29+
"_EVENT_ARC_REGION": "us-central1",
30+
"_FUNCTION_LOCATION": "us-central1",
31+
});
32+
exports.extRef1 = extRef1;
33+
34+
// A Firebase function defined by extension event
35+
const ttOnStart = extRef1.onStart((event) => {
36+
console.log("onStart got event: " + JSON.stringify(event, null, 2));
37+
});
38+
exports.ttOnStart = ttOnStart;
39+
40+
// A Firebase extension by localPath
41+
exports.extLocal2 = backfill("extLocal2", {
42+
DO_BACKFILL: "False",
43+
LOCATION: "us-central1",
44+
});
45+
2046
exports.g1 = require("./g1");

0 commit comments

Comments
 (0)