firebase-functions 6.6.0 → 7.0.0-rc.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.
- package/lib/_virtual/rolldown_runtime.js +34 -0
- package/lib/bin/firebase-functions.js +78 -103
- package/lib/common/app.js +35 -55
- package/lib/common/change.js +54 -75
- package/lib/common/config.js +41 -41
- package/lib/common/debug.js +23 -47
- package/lib/common/encoding.js +59 -82
- package/lib/common/onInit.js +26 -28
- package/lib/common/options.js +22 -42
- package/lib/common/params.d.ts +6 -6
- package/lib/common/params.js +0 -23
- package/lib/common/providers/database.js +270 -300
- package/lib/common/providers/firestore.js +66 -92
- package/lib/common/providers/https.d.ts +0 -1
- package/lib/common/providers/https.js +537 -539
- package/lib/common/providers/identity.js +393 -444
- package/lib/common/providers/tasks.js +64 -98
- package/lib/common/timezone.js +544 -542
- package/lib/common/trace.d.ts +0 -1
- package/lib/common/trace.js +63 -55
- package/lib/common/utilities/assertions.d.ts +11 -0
- package/lib/common/utilities/assertions.js +18 -0
- package/lib/common/utilities/encoder.js +20 -37
- package/lib/common/utilities/path-pattern.js +106 -132
- package/lib/common/utilities/path.js +28 -27
- package/lib/common/utilities/utils.js +23 -45
- package/lib/esm/_virtual/rolldown_runtime.mjs +16 -0
- package/lib/esm/bin/firebase-functions.mjs +91 -0
- package/lib/esm/common/app.mjs +39 -0
- package/lib/esm/common/change.mjs +57 -0
- package/lib/esm/common/config.mjs +45 -0
- package/lib/esm/common/debug.mjs +28 -0
- package/lib/esm/common/encoding.mjs +69 -0
- package/lib/esm/common/onInit.mjs +33 -0
- package/lib/esm/common/options.mjs +22 -0
- package/lib/esm/common/params.mjs +1 -0
- package/lib/esm/common/providers/database.mjs +269 -0
- package/lib/esm/common/providers/firestore.mjs +78 -0
- package/lib/esm/common/providers/https.mjs +573 -0
- package/lib/esm/common/providers/identity.mjs +428 -0
- package/lib/esm/common/providers/tasks.mjs +67 -0
- package/lib/esm/common/timezone.mjs +544 -0
- package/lib/esm/common/trace.mjs +73 -0
- package/lib/esm/common/utilities/assertions.mjs +17 -0
- package/lib/esm/common/utilities/encoder.mjs +21 -0
- package/lib/esm/common/utilities/path-pattern.mjs +116 -0
- package/lib/esm/common/utilities/path.mjs +35 -0
- package/lib/esm/common/utilities/utils.mjs +29 -0
- package/lib/esm/function-configuration.mjs +1 -0
- package/lib/esm/logger/common.mjs +23 -0
- package/lib/esm/logger/compat.mjs +25 -0
- package/lib/esm/logger/index.mjs +131 -0
- package/lib/esm/params/index.mjs +160 -0
- package/lib/esm/params/types.mjs +400 -0
- package/lib/esm/runtime/loader.mjs +132 -0
- package/lib/esm/runtime/manifest.mjs +134 -0
- package/lib/esm/types/global.d.mjs +1 -0
- package/lib/esm/v1/cloud-functions.mjs +206 -0
- package/lib/esm/v1/config.mjs +14 -0
- package/lib/esm/v1/function-builder.mjs +252 -0
- package/lib/esm/v1/function-configuration.mjs +72 -0
- package/lib/esm/v1/index.mjs +27 -0
- package/lib/esm/v1/providers/analytics.mjs +212 -0
- package/lib/esm/v1/providers/auth.mjs +156 -0
- package/lib/esm/v1/providers/database.mjs +243 -0
- package/lib/esm/v1/providers/firestore.mjs +131 -0
- package/lib/esm/v1/providers/https.mjs +82 -0
- package/lib/esm/v1/providers/pubsub.mjs +175 -0
- package/lib/esm/v1/providers/remoteConfig.mjs +64 -0
- package/lib/esm/v1/providers/storage.mjs +163 -0
- package/lib/esm/v1/providers/tasks.mjs +63 -0
- package/lib/esm/v1/providers/testLab.mjs +94 -0
- package/lib/esm/v2/core.mjs +4 -0
- package/lib/esm/v2/index.mjs +28 -0
- package/lib/esm/v2/options.mjs +102 -0
- package/lib/esm/v2/providers/alerts/alerts.mjs +85 -0
- package/lib/esm/v2/providers/alerts/appDistribution.mjs +75 -0
- package/lib/esm/v2/providers/alerts/billing.mjs +51 -0
- package/lib/esm/v2/providers/alerts/crashlytics.mjs +122 -0
- package/lib/esm/v2/providers/alerts/index.mjs +22 -0
- package/lib/esm/v2/providers/alerts/performance.mjs +66 -0
- package/lib/esm/v2/providers/database.mjs +197 -0
- package/lib/esm/v2/providers/dataconnect.mjs +130 -0
- package/lib/esm/v2/providers/eventarc.mjs +51 -0
- package/lib/esm/v2/providers/firestore.mjs +294 -0
- package/lib/esm/v2/providers/https.mjs +210 -0
- package/lib/esm/v2/providers/identity.mjs +103 -0
- package/lib/esm/v2/providers/pubsub.mjs +148 -0
- package/lib/esm/v2/providers/remoteConfig.mjs +52 -0
- package/lib/esm/v2/providers/scheduler.mjs +84 -0
- package/lib/esm/v2/providers/storage.mjs +155 -0
- package/lib/esm/v2/providers/tasks.mjs +65 -0
- package/lib/esm/v2/providers/testLab.mjs +53 -0
- package/lib/esm/v2/trace.mjs +20 -0
- package/lib/function-configuration.d.ts +0 -0
- package/lib/function-configuration.js +0 -0
- package/lib/logger/common.js +21 -41
- package/lib/logger/compat.js +18 -33
- package/lib/logger/index.js +119 -130
- package/lib/params/index.d.ts +4 -2
- package/lib/params/index.js +150 -144
- package/lib/params/types.js +389 -423
- package/lib/runtime/loader.js +114 -148
- package/lib/runtime/manifest.js +106 -126
- package/lib/types/global.d.js +0 -0
- package/lib/v1/cloud-functions.d.ts +2 -2
- package/lib/v1/cloud-functions.js +193 -241
- package/lib/v1/config.d.ts +4 -7
- package/lib/v1/config.js +13 -75
- package/lib/v1/function-builder.js +239 -368
- package/lib/v1/function-configuration.js +70 -63
- package/lib/v1/index.js +118 -73
- package/lib/v1/providers/analytics.js +188 -235
- package/lib/v1/providers/auth.d.ts +2 -1
- package/lib/v1/providers/auth.js +159 -164
- package/lib/v1/providers/database.js +237 -242
- package/lib/v1/providers/firestore.js +131 -130
- package/lib/v1/providers/https.d.ts +2 -1
- package/lib/v1/providers/https.js +79 -86
- package/lib/v1/providers/pubsub.js +175 -172
- package/lib/v1/providers/remoteConfig.js +64 -68
- package/lib/v1/providers/storage.js +161 -163
- package/lib/v1/providers/tasks.d.ts +1 -1
- package/lib/v1/providers/tasks.js +65 -80
- package/lib/v1/providers/testLab.js +94 -94
- package/lib/v2/core.d.ts +1 -1
- package/lib/v2/core.js +5 -32
- package/lib/v2/index.d.ts +6 -3
- package/lib/v2/index.js +123 -75
- package/lib/v2/options.js +88 -114
- package/lib/v2/providers/alerts/alerts.js +76 -95
- package/lib/v2/providers/alerts/appDistribution.js +73 -78
- package/lib/v2/providers/alerts/billing.js +49 -53
- package/lib/v2/providers/alerts/crashlytics.js +110 -102
- package/lib/v2/providers/alerts/index.js +56 -53
- package/lib/v2/providers/alerts/performance.js +64 -74
- package/lib/v2/providers/database.js +177 -180
- package/lib/v2/providers/dataconnect.d.ts +95 -0
- package/lib/v2/providers/dataconnect.js +137 -0
- package/lib/v2/providers/eventarc.js +55 -77
- package/lib/v2/providers/firestore.js +262 -260
- package/lib/v2/providers/https.d.ts +3 -2
- package/lib/v2/providers/https.js +210 -247
- package/lib/v2/providers/identity.d.ts +2 -1
- package/lib/v2/providers/identity.js +96 -105
- package/lib/v2/providers/pubsub.js +149 -167
- package/lib/v2/providers/remoteConfig.js +54 -63
- package/lib/v2/providers/scheduler.js +84 -96
- package/lib/v2/providers/storage.js +147 -162
- package/lib/v2/providers/tasks.d.ts +1 -1
- package/lib/v2/providers/tasks.js +68 -95
- package/lib/v2/providers/testLab.js +55 -64
- package/lib/v2/trace.js +18 -19
- package/package.json +290 -226
- package/protos/compiledFirestore.mjs +3512 -0
- package/protos/update.sh +28 -7
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { Change } from "../../common/change.mjs";
|
|
3
|
+
import { makeCloudFunction } from "../cloud-functions.mjs";
|
|
4
|
+
import { createBeforeSnapshotFromJson, createSnapshotFromJson } from "../../common/providers/firestore.mjs";
|
|
5
|
+
import { posix } from "path";
|
|
6
|
+
|
|
7
|
+
//#region src/v1/providers/firestore.ts
|
|
8
|
+
var firestore_exports = /* @__PURE__ */ __export({
|
|
9
|
+
DatabaseBuilder: () => DatabaseBuilder,
|
|
10
|
+
DocumentBuilder: () => DocumentBuilder,
|
|
11
|
+
NamespaceBuilder: () => NamespaceBuilder,
|
|
12
|
+
_databaseWithOptions: () => _databaseWithOptions,
|
|
13
|
+
_documentWithOptions: () => _documentWithOptions,
|
|
14
|
+
_namespaceWithOptions: () => _namespaceWithOptions,
|
|
15
|
+
beforeSnapshotConstructor: () => beforeSnapshotConstructor,
|
|
16
|
+
database: () => database,
|
|
17
|
+
defaultDatabase: () => defaultDatabase,
|
|
18
|
+
document: () => document,
|
|
19
|
+
namespace: () => namespace,
|
|
20
|
+
provider: () => provider,
|
|
21
|
+
service: () => service,
|
|
22
|
+
snapshotConstructor: () => snapshotConstructor
|
|
23
|
+
});
|
|
24
|
+
/** @internal */
|
|
25
|
+
const provider = "google.firestore";
|
|
26
|
+
/** @internal */
|
|
27
|
+
const service = "firestore.googleapis.com";
|
|
28
|
+
/** @internal */
|
|
29
|
+
const defaultDatabase = "(default)";
|
|
30
|
+
/**
|
|
31
|
+
* Select the Firestore document to listen to for events.
|
|
32
|
+
* @param path Full database path to listen to. This includes the name of
|
|
33
|
+
* the collection that the document is a part of. For example, if the
|
|
34
|
+
* collection is named "users" and the document is named "Ada", then the
|
|
35
|
+
* path is "/users/Ada".
|
|
36
|
+
*/
|
|
37
|
+
function document(path) {
|
|
38
|
+
return _documentWithOptions(path, {});
|
|
39
|
+
}
|
|
40
|
+
function namespace(namespace$1) {
|
|
41
|
+
return _namespaceWithOptions(namespace$1, {});
|
|
42
|
+
}
|
|
43
|
+
function database(database$1) {
|
|
44
|
+
return _databaseWithOptions(database$1, {});
|
|
45
|
+
}
|
|
46
|
+
/** @internal */
|
|
47
|
+
function _databaseWithOptions(database$1 = defaultDatabase, options) {
|
|
48
|
+
return new DatabaseBuilder(database$1, options);
|
|
49
|
+
}
|
|
50
|
+
/** @internal */
|
|
51
|
+
function _namespaceWithOptions(namespace$1, options) {
|
|
52
|
+
return _databaseWithOptions(defaultDatabase, options).namespace(namespace$1);
|
|
53
|
+
}
|
|
54
|
+
/** @internal */
|
|
55
|
+
function _documentWithOptions(path, options) {
|
|
56
|
+
return _databaseWithOptions(defaultDatabase, options).document(path);
|
|
57
|
+
}
|
|
58
|
+
var DatabaseBuilder = class {
|
|
59
|
+
constructor(database$1, options) {
|
|
60
|
+
this.database = database$1;
|
|
61
|
+
this.options = options;
|
|
62
|
+
}
|
|
63
|
+
namespace(namespace$1) {
|
|
64
|
+
return new NamespaceBuilder(this.database, this.options, namespace$1);
|
|
65
|
+
}
|
|
66
|
+
document(path) {
|
|
67
|
+
return new NamespaceBuilder(this.database, this.options).document(path);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var NamespaceBuilder = class {
|
|
71
|
+
constructor(database$1, options, namespace$1) {
|
|
72
|
+
this.database = database$1;
|
|
73
|
+
this.options = options;
|
|
74
|
+
this.namespace = namespace$1;
|
|
75
|
+
}
|
|
76
|
+
document(path) {
|
|
77
|
+
return new DocumentBuilder(() => {
|
|
78
|
+
if (!process.env.GCLOUD_PROJECT) {
|
|
79
|
+
throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
|
80
|
+
}
|
|
81
|
+
const database$1 = posix.join("projects", process.env.GCLOUD_PROJECT, "databases", this.database);
|
|
82
|
+
return posix.join(database$1, this.namespace ? `documents@${this.namespace}` : "documents", path);
|
|
83
|
+
}, this.options);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
function snapshotConstructor(event) {
|
|
87
|
+
return createSnapshotFromJson(event.data, event.context.resource.name, event?.data?.value?.readTime, event?.data?.value?.updateTime);
|
|
88
|
+
}
|
|
89
|
+
function beforeSnapshotConstructor(event) {
|
|
90
|
+
return createBeforeSnapshotFromJson(event.data, event.context.resource.name, event?.data?.oldValue?.readTime, undefined);
|
|
91
|
+
}
|
|
92
|
+
function changeConstructor(raw) {
|
|
93
|
+
return Change.fromObjects(beforeSnapshotConstructor(raw), snapshotConstructor(raw));
|
|
94
|
+
}
|
|
95
|
+
var DocumentBuilder = class {
|
|
96
|
+
constructor(triggerResource, options) {
|
|
97
|
+
this.triggerResource = triggerResource;
|
|
98
|
+
this.options = options;
|
|
99
|
+
}
|
|
100
|
+
/** Respond to all document writes (creates, updates, or deletes). */
|
|
101
|
+
onWrite(handler) {
|
|
102
|
+
return this.onOperation(handler, "document.write", changeConstructor);
|
|
103
|
+
}
|
|
104
|
+
/** Respond only to document updates. */
|
|
105
|
+
onUpdate(handler) {
|
|
106
|
+
return this.onOperation(handler, "document.update", changeConstructor);
|
|
107
|
+
}
|
|
108
|
+
/** Respond only to document creations. */
|
|
109
|
+
onCreate(handler) {
|
|
110
|
+
return this.onOperation(handler, "document.create", snapshotConstructor);
|
|
111
|
+
}
|
|
112
|
+
/** Respond only to document deletions. */
|
|
113
|
+
onDelete(handler) {
|
|
114
|
+
return this.onOperation(handler, "document.delete", beforeSnapshotConstructor);
|
|
115
|
+
}
|
|
116
|
+
onOperation(handler, eventType, dataConstructor) {
|
|
117
|
+
return makeCloudFunction({
|
|
118
|
+
handler,
|
|
119
|
+
provider,
|
|
120
|
+
eventType,
|
|
121
|
+
service,
|
|
122
|
+
triggerResource: this.triggerResource,
|
|
123
|
+
legacyEventType: `providers/cloud.firestore/eventTypes/${eventType}`,
|
|
124
|
+
dataConstructor,
|
|
125
|
+
options: this.options
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
export { DatabaseBuilder, DocumentBuilder, NamespaceBuilder, _databaseWithOptions, _documentWithOptions, _namespaceWithOptions, beforeSnapshotConstructor, database, defaultDatabase, document, firestore_exports, namespace, provider, service, snapshotConstructor };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { initV1Endpoint } from "../../runtime/manifest.mjs";
|
|
3
|
+
import { convertIfPresent, convertInvoker } from "../../common/encoding.mjs";
|
|
4
|
+
import { withInit } from "../../common/onInit.mjs";
|
|
5
|
+
import { optionsToEndpoint, optionsToTrigger } from "../cloud-functions.mjs";
|
|
6
|
+
import { HttpsError, onCallHandler, withErrorHandler } from "../../common/providers/https.mjs";
|
|
7
|
+
import { wrapTraceContext } from "../../v2/trace.mjs";
|
|
8
|
+
|
|
9
|
+
//#region src/v1/providers/https.ts
|
|
10
|
+
var https_exports = /* @__PURE__ */ __export({
|
|
11
|
+
HttpsError: () => HttpsError,
|
|
12
|
+
_onCallWithOptions: () => _onCallWithOptions,
|
|
13
|
+
_onRequestWithOptions: () => _onRequestWithOptions,
|
|
14
|
+
onCall: () => onCall,
|
|
15
|
+
onRequest: () => onRequest
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Handle HTTP requests.
|
|
19
|
+
* @param handler A function that takes a request and response object,
|
|
20
|
+
* same signature as an Express app.
|
|
21
|
+
*/
|
|
22
|
+
function onRequest(handler) {
|
|
23
|
+
return _onRequestWithOptions(handler, {});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Declares a callable method for clients to call using a Firebase SDK.
|
|
27
|
+
* @param handler A method that takes a data and context and returns a value.
|
|
28
|
+
*/
|
|
29
|
+
function onCall(handler) {
|
|
30
|
+
return _onCallWithOptions(handler, {});
|
|
31
|
+
}
|
|
32
|
+
/** @internal */
|
|
33
|
+
function _onRequestWithOptions(handler, options) {
|
|
34
|
+
const cloudFunction = (req, res) => {
|
|
35
|
+
return wrapTraceContext(withInit(withErrorHandler(handler)))(req, res);
|
|
36
|
+
};
|
|
37
|
+
cloudFunction.__trigger = {
|
|
38
|
+
...optionsToTrigger(options),
|
|
39
|
+
httpsTrigger: {}
|
|
40
|
+
};
|
|
41
|
+
convertIfPresent(cloudFunction.__trigger.httpsTrigger, options, "invoker", "invoker", convertInvoker);
|
|
42
|
+
cloudFunction.__endpoint = {
|
|
43
|
+
platform: "gcfv1",
|
|
44
|
+
...initV1Endpoint(options),
|
|
45
|
+
...optionsToEndpoint(options),
|
|
46
|
+
httpsTrigger: {}
|
|
47
|
+
};
|
|
48
|
+
convertIfPresent(cloudFunction.__endpoint.httpsTrigger, options, "invoker", "invoker", convertInvoker);
|
|
49
|
+
return cloudFunction;
|
|
50
|
+
}
|
|
51
|
+
/** @internal */
|
|
52
|
+
function _onCallWithOptions(handler, options) {
|
|
53
|
+
const fixedLen = (data, context) => {
|
|
54
|
+
return withInit(handler)(data, context);
|
|
55
|
+
};
|
|
56
|
+
const func = wrapTraceContext(onCallHandler({
|
|
57
|
+
enforceAppCheck: options.enforceAppCheck,
|
|
58
|
+
consumeAppCheckToken: options.consumeAppCheckToken,
|
|
59
|
+
cors: {
|
|
60
|
+
origin: true,
|
|
61
|
+
methods: "POST"
|
|
62
|
+
}
|
|
63
|
+
}, fixedLen, "gcfv1"));
|
|
64
|
+
func.__trigger = {
|
|
65
|
+
labels: {},
|
|
66
|
+
...optionsToTrigger(options),
|
|
67
|
+
httpsTrigger: {}
|
|
68
|
+
};
|
|
69
|
+
func.__trigger.labels["deployment-callable"] = "true";
|
|
70
|
+
func.__endpoint = {
|
|
71
|
+
platform: "gcfv1",
|
|
72
|
+
labels: {},
|
|
73
|
+
...initV1Endpoint(options),
|
|
74
|
+
...optionsToEndpoint(options),
|
|
75
|
+
callableTrigger: {}
|
|
76
|
+
};
|
|
77
|
+
func.run = fixedLen;
|
|
78
|
+
return func;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
export { HttpsError, _onCallWithOptions, _onRequestWithOptions, https_exports, onCall, onRequest };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { makeCloudFunction } from "../cloud-functions.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/v1/providers/pubsub.ts
|
|
5
|
+
var pubsub_exports = /* @__PURE__ */ __export({
|
|
6
|
+
Message: () => Message,
|
|
7
|
+
ScheduleBuilder: () => ScheduleBuilder,
|
|
8
|
+
TopicBuilder: () => TopicBuilder,
|
|
9
|
+
_scheduleWithOptions: () => _scheduleWithOptions,
|
|
10
|
+
_topicWithOptions: () => _topicWithOptions,
|
|
11
|
+
provider: () => provider,
|
|
12
|
+
schedule: () => schedule,
|
|
13
|
+
service: () => service,
|
|
14
|
+
topic: () => topic
|
|
15
|
+
});
|
|
16
|
+
/** @internal */
|
|
17
|
+
const provider = "google.pubsub";
|
|
18
|
+
/** @internal */
|
|
19
|
+
const service = "pubsub.googleapis.com";
|
|
20
|
+
/**
|
|
21
|
+
* Registers a Cloud Function triggered when a Google Cloud Pub/Sub message
|
|
22
|
+
* is sent to a specified topic.
|
|
23
|
+
*
|
|
24
|
+
* @param topic - The Pub/Sub topic to watch for message events.
|
|
25
|
+
* @returns Pub/Sub topic builder interface.
|
|
26
|
+
*/
|
|
27
|
+
function topic(topic$1) {
|
|
28
|
+
return _topicWithOptions(topic$1, {});
|
|
29
|
+
}
|
|
30
|
+
/** @internal */
|
|
31
|
+
function _topicWithOptions(topic$1, options) {
|
|
32
|
+
if (topic$1.indexOf("/") !== -1) {
|
|
33
|
+
throw new Error("Topic name may not have a /");
|
|
34
|
+
}
|
|
35
|
+
return new TopicBuilder(() => {
|
|
36
|
+
if (!process.env.GCLOUD_PROJECT) {
|
|
37
|
+
throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
|
38
|
+
}
|
|
39
|
+
return `projects/${process.env.GCLOUD_PROJECT}/topics/${topic$1}`;
|
|
40
|
+
}, options);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The Google Cloud Pub/Sub topic builder.
|
|
44
|
+
*
|
|
45
|
+
* Access via `functions.pubsub.topic()`.
|
|
46
|
+
*/
|
|
47
|
+
var TopicBuilder = class {
|
|
48
|
+
/** @hidden */
|
|
49
|
+
constructor(triggerResource, options) {
|
|
50
|
+
this.triggerResource = triggerResource;
|
|
51
|
+
this.options = options;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Event handler that fires every time a Cloud Pub/Sub message is
|
|
55
|
+
* published.
|
|
56
|
+
*
|
|
57
|
+
* @param handler - Event handler that runs every time a Cloud Pub/Sub message
|
|
58
|
+
* is published.
|
|
59
|
+
* @returns A function that you can export and deploy.
|
|
60
|
+
*/
|
|
61
|
+
onPublish(handler) {
|
|
62
|
+
return makeCloudFunction({
|
|
63
|
+
handler,
|
|
64
|
+
provider,
|
|
65
|
+
service,
|
|
66
|
+
triggerResource: this.triggerResource,
|
|
67
|
+
eventType: "topic.publish",
|
|
68
|
+
dataConstructor: (raw) => new Message(raw.data),
|
|
69
|
+
options: this.options
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Registers a Cloud Function to run at specified times.
|
|
75
|
+
*
|
|
76
|
+
* @param schedule - The schedule, in Unix Crontab or AppEngine syntax.
|
|
77
|
+
* @returns ScheduleBuilder interface.
|
|
78
|
+
*/
|
|
79
|
+
function schedule(schedule$1) {
|
|
80
|
+
return _scheduleWithOptions(schedule$1, {});
|
|
81
|
+
}
|
|
82
|
+
/** @internal */
|
|
83
|
+
function _scheduleWithOptions(schedule$1, options) {
|
|
84
|
+
const triggerResource = () => {
|
|
85
|
+
if (!process.env.GCLOUD_PROJECT) {
|
|
86
|
+
throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
|
87
|
+
}
|
|
88
|
+
return `projects/${process.env.GCLOUD_PROJECT}/topics`;
|
|
89
|
+
};
|
|
90
|
+
return new ScheduleBuilder(triggerResource, {
|
|
91
|
+
...options,
|
|
92
|
+
schedule: { schedule: schedule$1 }
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The builder for scheduled functions, which are powered by
|
|
97
|
+
* Google Pub/Sub and Cloud Scheduler. Describes the Cloud Scheduler
|
|
98
|
+
* job that is deployed to trigger a scheduled function at the provided
|
|
99
|
+
* frequency. For more information, see
|
|
100
|
+
* [Schedule functions](/docs/functions/schedule-functions).
|
|
101
|
+
*
|
|
102
|
+
* Access via `functions.pubsub.schedule()`.
|
|
103
|
+
*/
|
|
104
|
+
var ScheduleBuilder = class {
|
|
105
|
+
/** @hidden */
|
|
106
|
+
constructor(triggerResource, options) {
|
|
107
|
+
this.triggerResource = triggerResource;
|
|
108
|
+
this.options = options;
|
|
109
|
+
}
|
|
110
|
+
retryConfig(config) {
|
|
111
|
+
this.options.schedule.retryConfig = config;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
timeZone(timeZone) {
|
|
115
|
+
this.options.schedule.timeZone = timeZone;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Event handler for scheduled functions. Triggered whenever the associated
|
|
120
|
+
* scheduler job sends a Pub/Sub message.
|
|
121
|
+
*
|
|
122
|
+
* @param handler - Handler that fires whenever the associated
|
|
123
|
+
* scheduler job sends a Pub/Sub message.
|
|
124
|
+
* @returns A function that you can export and deploy.
|
|
125
|
+
*/
|
|
126
|
+
onRun(handler) {
|
|
127
|
+
const cloudFunction = makeCloudFunction({
|
|
128
|
+
contextOnlyHandler: handler,
|
|
129
|
+
provider,
|
|
130
|
+
service,
|
|
131
|
+
triggerResource: this.triggerResource,
|
|
132
|
+
eventType: "topic.publish",
|
|
133
|
+
options: this.options,
|
|
134
|
+
labels: { "deployment-scheduled": "true" }
|
|
135
|
+
});
|
|
136
|
+
return cloudFunction;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Interface representing a Google Cloud Pub/Sub message.
|
|
141
|
+
*
|
|
142
|
+
* @param data - Payload of a Pub/Sub message.
|
|
143
|
+
*/
|
|
144
|
+
var Message = class {
|
|
145
|
+
constructor(data) {
|
|
146
|
+
[this.data, this.attributes, this._json] = [
|
|
147
|
+
data.data,
|
|
148
|
+
data.attributes || {},
|
|
149
|
+
data.json
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The JSON data payload of this message object, if any.
|
|
154
|
+
*/
|
|
155
|
+
get json() {
|
|
156
|
+
if (typeof this._json === "undefined") {
|
|
157
|
+
this._json = JSON.parse(Buffer.from(this.data, "base64").toString("utf8"));
|
|
158
|
+
}
|
|
159
|
+
return this._json;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns a JSON-serializable representation of this object.
|
|
163
|
+
*
|
|
164
|
+
* @returns A JSON-serializable representation of this object.
|
|
165
|
+
*/
|
|
166
|
+
toJSON() {
|
|
167
|
+
return {
|
|
168
|
+
data: this.data,
|
|
169
|
+
attributes: this.attributes
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
export { Message, ScheduleBuilder, TopicBuilder, _scheduleWithOptions, _topicWithOptions, provider, pubsub_exports, schedule, service, topic };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { makeCloudFunction } from "../cloud-functions.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/v1/providers/remoteConfig.ts
|
|
5
|
+
var remoteConfig_exports = /* @__PURE__ */ __export({
|
|
6
|
+
UpdateBuilder: () => UpdateBuilder,
|
|
7
|
+
_onUpdateWithOptions: () => _onUpdateWithOptions,
|
|
8
|
+
onUpdate: () => onUpdate,
|
|
9
|
+
provider: () => provider,
|
|
10
|
+
service: () => service
|
|
11
|
+
});
|
|
12
|
+
/** @internal */
|
|
13
|
+
const provider = "google.firebase.remoteconfig";
|
|
14
|
+
/** @internal */
|
|
15
|
+
const service = "firebaseremoteconfig.googleapis.com";
|
|
16
|
+
/**
|
|
17
|
+
* Registers a function that triggers on Firebase Remote Config template
|
|
18
|
+
* update events.
|
|
19
|
+
*
|
|
20
|
+
* @param handler A function that takes the updated Remote Config
|
|
21
|
+
* template version metadata as an argument.
|
|
22
|
+
*
|
|
23
|
+
* @returns A function that you can export and deploy.
|
|
24
|
+
*/
|
|
25
|
+
function onUpdate(handler) {
|
|
26
|
+
return _onUpdateWithOptions(handler, {});
|
|
27
|
+
}
|
|
28
|
+
/** @internal */
|
|
29
|
+
function _onUpdateWithOptions(handler, options) {
|
|
30
|
+
const triggerResource = () => {
|
|
31
|
+
if (!process.env.GCLOUD_PROJECT) {
|
|
32
|
+
throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
|
33
|
+
}
|
|
34
|
+
return `projects/${process.env.GCLOUD_PROJECT}`;
|
|
35
|
+
};
|
|
36
|
+
return new UpdateBuilder(triggerResource, options).onUpdate(handler);
|
|
37
|
+
}
|
|
38
|
+
/** Builder used to create Cloud Functions for Remote Config. */
|
|
39
|
+
var UpdateBuilder = class {
|
|
40
|
+
/** @internal */
|
|
41
|
+
constructor(triggerResource, options) {
|
|
42
|
+
this.triggerResource = triggerResource;
|
|
43
|
+
this.options = options;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Handle all updates (including rollbacks) that affect a Remote Config
|
|
47
|
+
* project.
|
|
48
|
+
* @param handler A function that takes the updated Remote Config template
|
|
49
|
+
* version metadata as an argument.
|
|
50
|
+
*/
|
|
51
|
+
onUpdate(handler) {
|
|
52
|
+
return makeCloudFunction({
|
|
53
|
+
handler,
|
|
54
|
+
provider,
|
|
55
|
+
service,
|
|
56
|
+
triggerResource: this.triggerResource,
|
|
57
|
+
eventType: "update",
|
|
58
|
+
options: this.options
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { UpdateBuilder, _onUpdateWithOptions, onUpdate, provider, remoteConfig_exports, service };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { firebaseConfig } from "../../common/config.mjs";
|
|
3
|
+
import { makeCloudFunction } from "../cloud-functions.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/v1/providers/storage.ts
|
|
6
|
+
var storage_exports = /* @__PURE__ */ __export({
|
|
7
|
+
BucketBuilder: () => BucketBuilder,
|
|
8
|
+
ObjectBuilder: () => ObjectBuilder,
|
|
9
|
+
_bucketWithOptions: () => _bucketWithOptions,
|
|
10
|
+
_objectWithOptions: () => _objectWithOptions,
|
|
11
|
+
bucket: () => bucket,
|
|
12
|
+
object: () => object,
|
|
13
|
+
provider: () => provider,
|
|
14
|
+
service: () => service
|
|
15
|
+
});
|
|
16
|
+
/** @internal */
|
|
17
|
+
const provider = "google.storage";
|
|
18
|
+
/** @internal */
|
|
19
|
+
const service = "storage.googleapis.com";
|
|
20
|
+
/**
|
|
21
|
+
* Registers a Cloud Function scoped to a specific storage bucket.
|
|
22
|
+
*
|
|
23
|
+
* @param bucket Name of the bucket to which this Cloud Function is
|
|
24
|
+
* scoped.
|
|
25
|
+
*
|
|
26
|
+
* @returns Storage bucket builder interface.
|
|
27
|
+
*/
|
|
28
|
+
function bucket(bucket$1) {
|
|
29
|
+
return _bucketWithOptions({}, bucket$1);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Registers a Cloud Function scoped to the default storage bucket for the
|
|
33
|
+
* project.
|
|
34
|
+
*
|
|
35
|
+
* @returns Storage object builder interface.
|
|
36
|
+
*/
|
|
37
|
+
function object() {
|
|
38
|
+
return _objectWithOptions({});
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
function _bucketWithOptions(options, bucket$1) {
|
|
42
|
+
const resourceGetter = () => {
|
|
43
|
+
bucket$1 = bucket$1 || firebaseConfig().storageBucket;
|
|
44
|
+
if (!bucket$1) {
|
|
45
|
+
throw new Error("Missing bucket name. If you are unit testing, please provide a bucket name" + " through `functions.storage.bucket(bucketName)`, or set process.env.FIREBASE_CONFIG.");
|
|
46
|
+
}
|
|
47
|
+
if (!/^[a-z\d][a-z\d\\._-]{1,230}[a-z\d]$/.test(bucket$1)) {
|
|
48
|
+
throw new Error(`Invalid bucket name ${bucket$1}`);
|
|
49
|
+
}
|
|
50
|
+
return `projects/_/buckets/${bucket$1}`;
|
|
51
|
+
};
|
|
52
|
+
return new BucketBuilder(resourceGetter, options);
|
|
53
|
+
}
|
|
54
|
+
/** @internal */
|
|
55
|
+
function _objectWithOptions(options) {
|
|
56
|
+
return _bucketWithOptions(options).object();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The Google Cloud Storage bucket builder interface.
|
|
60
|
+
*
|
|
61
|
+
* Access via `functions.storage.bucket()`.
|
|
62
|
+
*/
|
|
63
|
+
var BucketBuilder = class {
|
|
64
|
+
/** @internal */
|
|
65
|
+
constructor(triggerResource, options) {
|
|
66
|
+
this.triggerResource = triggerResource;
|
|
67
|
+
this.options = options;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Event handler which fires every time a Google Cloud Storage change occurs.
|
|
71
|
+
*
|
|
72
|
+
* @returns Storage object builder interface scoped to the specified storage
|
|
73
|
+
* bucket.
|
|
74
|
+
*/
|
|
75
|
+
object() {
|
|
76
|
+
return new ObjectBuilder(this.triggerResource, this.options);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* The Google Cloud Storage object builder interface.
|
|
81
|
+
*
|
|
82
|
+
* Access via `functions.storage.object()`.
|
|
83
|
+
*/
|
|
84
|
+
var ObjectBuilder = class {
|
|
85
|
+
/** @internal */
|
|
86
|
+
constructor(triggerResource, options) {
|
|
87
|
+
this.triggerResource = triggerResource;
|
|
88
|
+
this.options = options;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Event handler sent only when a bucket has enabled object versioning.
|
|
92
|
+
* This event indicates that the live version of an object has become an
|
|
93
|
+
* archived version, either because it was archived or because it was
|
|
94
|
+
* overwritten by the upload of an object of the same name.
|
|
95
|
+
*
|
|
96
|
+
* @param handler Event handler which is run every time a Google Cloud Storage
|
|
97
|
+
* archival occurs.
|
|
98
|
+
*
|
|
99
|
+
* @returns A function which you can export and deploy.
|
|
100
|
+
*/
|
|
101
|
+
onArchive(handler) {
|
|
102
|
+
return this.onOperation(handler, "object.archive");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Event handler which fires every time a Google Cloud Storage deletion occurs.
|
|
106
|
+
*
|
|
107
|
+
* Sent when an object has been permanently deleted. This includes objects
|
|
108
|
+
* that are overwritten or are deleted as part of the bucket's lifecycle
|
|
109
|
+
* configuration. For buckets with object versioning enabled, this is not
|
|
110
|
+
* sent when an object is archived, even if archival occurs
|
|
111
|
+
* via the `storage.objects.delete` method.
|
|
112
|
+
*
|
|
113
|
+
* @param handler Event handler which is run every time a Google Cloud Storage
|
|
114
|
+
* deletion occurs.
|
|
115
|
+
*
|
|
116
|
+
* @returns A function which you can export and deploy.
|
|
117
|
+
*/
|
|
118
|
+
onDelete(handler) {
|
|
119
|
+
return this.onOperation(handler, "object.delete");
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Event handler which fires every time a Google Cloud Storage object
|
|
123
|
+
* creation occurs.
|
|
124
|
+
*
|
|
125
|
+
* Sent when a new object (or a new generation of an existing object)
|
|
126
|
+
* is successfully created in the bucket. This includes copying or rewriting
|
|
127
|
+
* an existing object. A failed upload does not trigger this event.
|
|
128
|
+
*
|
|
129
|
+
* @param handler Event handler which is run every time a Google Cloud Storage
|
|
130
|
+
* object creation occurs.
|
|
131
|
+
*
|
|
132
|
+
* @returns A function which you can export and deploy.
|
|
133
|
+
*/
|
|
134
|
+
onFinalize(handler) {
|
|
135
|
+
return this.onOperation(handler, "object.finalize");
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Event handler which fires every time the metadata of an existing object
|
|
139
|
+
* changes.
|
|
140
|
+
*
|
|
141
|
+
* @param handler Event handler which is run every time a Google Cloud Storage
|
|
142
|
+
* metadata update occurs.
|
|
143
|
+
*
|
|
144
|
+
* @returns A function which you can export and deploy.
|
|
145
|
+
*/
|
|
146
|
+
onMetadataUpdate(handler) {
|
|
147
|
+
return this.onOperation(handler, "object.metadataUpdate");
|
|
148
|
+
}
|
|
149
|
+
/** @hidden */
|
|
150
|
+
onOperation(handler, eventType) {
|
|
151
|
+
return makeCloudFunction({
|
|
152
|
+
handler,
|
|
153
|
+
provider,
|
|
154
|
+
service,
|
|
155
|
+
eventType,
|
|
156
|
+
triggerResource: this.triggerResource,
|
|
157
|
+
options: this.options
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
export { BucketBuilder, ObjectBuilder, _bucketWithOptions, _objectWithOptions, bucket, object, provider, service, storage_exports };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { initTaskQueueTrigger, initV1Endpoint } from "../../runtime/manifest.mjs";
|
|
3
|
+
import { convertIfPresent, convertInvoker, copyIfPresent } from "../../common/encoding.mjs";
|
|
4
|
+
import { optionsToEndpoint, optionsToTrigger } from "../cloud-functions.mjs";
|
|
5
|
+
import { onDispatchHandler } from "../../common/providers/tasks.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/v1/providers/tasks.ts
|
|
8
|
+
var tasks_exports = /* @__PURE__ */ __export({
|
|
9
|
+
TaskQueueBuilder: () => TaskQueueBuilder,
|
|
10
|
+
taskQueue: () => taskQueue
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Builder for creating a `TaskQueueFunction`.
|
|
14
|
+
*/
|
|
15
|
+
var TaskQueueBuilder = class {
|
|
16
|
+
/** @internal */
|
|
17
|
+
constructor(tqOpts, depOpts) {
|
|
18
|
+
this.tqOpts = tqOpts;
|
|
19
|
+
this.depOpts = depOpts;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
|
|
23
|
+
* @param handler - A callback to handle task requests.
|
|
24
|
+
* @returns A function you can export and deploy.
|
|
25
|
+
*/
|
|
26
|
+
onDispatch(handler) {
|
|
27
|
+
const fixedLen = (data, context) => handler(data, context);
|
|
28
|
+
const func = onDispatchHandler(fixedLen);
|
|
29
|
+
func.__trigger = {
|
|
30
|
+
...optionsToTrigger(this.depOpts || {}),
|
|
31
|
+
taskQueueTrigger: {}
|
|
32
|
+
};
|
|
33
|
+
copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, "retryConfig");
|
|
34
|
+
copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, "rateLimits");
|
|
35
|
+
convertIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, "invoker", "invoker", convertInvoker);
|
|
36
|
+
func.__endpoint = {
|
|
37
|
+
platform: "gcfv1",
|
|
38
|
+
...initV1Endpoint(this.depOpts),
|
|
39
|
+
...optionsToEndpoint(this.depOpts),
|
|
40
|
+
taskQueueTrigger: initTaskQueueTrigger(this.depOpts)
|
|
41
|
+
};
|
|
42
|
+
copyIfPresent(func.__endpoint.taskQueueTrigger.retryConfig, this.tqOpts?.retryConfig || {}, "maxAttempts", "maxBackoffSeconds", "maxDoublings", "maxRetrySeconds", "minBackoffSeconds");
|
|
43
|
+
copyIfPresent(func.__endpoint.taskQueueTrigger.rateLimits, this.tqOpts?.rateLimits || {}, "maxConcurrentDispatches", "maxDispatchesPerSecond");
|
|
44
|
+
convertIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, "invoker", "invoker", convertInvoker);
|
|
45
|
+
func.__requiredAPIs = [{
|
|
46
|
+
api: "cloudtasks.googleapis.com",
|
|
47
|
+
reason: "Needed for task queue functions"
|
|
48
|
+
}];
|
|
49
|
+
func.run = handler;
|
|
50
|
+
return func;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
|
|
55
|
+
* @param options - Configuration for the Task Queue that feeds into this function.
|
|
56
|
+
* Omitting options will configure a Task Queue with default settings.
|
|
57
|
+
*/
|
|
58
|
+
function taskQueue(options) {
|
|
59
|
+
return new TaskQueueBuilder(options);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { TaskQueueBuilder, taskQueue, tasks_exports };
|