firebase-functions 3.21.0 → 3.22.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/bin/firebase-functions.js +21 -0
- package/lib/cloud-functions.d.ts +54 -88
- package/lib/cloud-functions.js +2 -59
- package/lib/common/change.d.ts +46 -0
- package/lib/common/change.js +82 -0
- package/lib/common/encoding.js +21 -1
- package/lib/common/providers/database.d.ts +145 -0
- package/lib/common/providers/database.js +271 -0
- package/lib/common/providers/https.d.ts +37 -17
- package/lib/common/providers/https.js +3 -0
- package/lib/common/providers/identity.d.ts +5 -1
- package/lib/common/providers/identity.js +12 -4
- package/lib/common/providers/tasks.d.ts +9 -0
- package/lib/common/providers/tasks.js +13 -12
- package/lib/function-builder.d.ts +3 -3
- package/lib/function-builder.js +2 -2
- package/lib/logger/common.js +21 -0
- package/lib/logger/compat.js +21 -0
- package/lib/logger/index.d.ts +14 -6
- package/lib/logger/index.js +33 -6
- package/lib/providers/auth.d.ts +26 -5
- package/lib/providers/auth.js +18 -4
- package/lib/providers/database.d.ts +4 -146
- package/lib/providers/database.js +7 -251
- package/lib/providers/firestore.d.ts +2 -1
- package/lib/providers/firestore.js +2 -1
- package/lib/providers/pubsub.d.ts +6 -6
- package/lib/providers/pubsub.js +6 -6
- package/lib/providers/tasks.d.ts +29 -14
- package/lib/providers/tasks.js +10 -3
- package/lib/utilities/path-pattern.d.ts +1 -0
- package/lib/utilities/path-pattern.js +142 -0
- package/lib/v2/core.d.ts +25 -1
- package/lib/v2/core.js +7 -0
- package/lib/v2/index.d.ts +11 -3
- package/lib/v2/index.js +12 -3
- package/lib/v2/options.d.ts +13 -34
- package/lib/v2/options.js +6 -58
- package/lib/v2/params/index.d.ts +4 -1
- package/lib/v2/params/index.js +25 -1
- package/lib/v2/params/types.js +21 -0
- package/lib/v2/providers/alerts/alerts.d.ts +94 -3
- package/lib/v2/providers/alerts/alerts.js +23 -7
- package/lib/v2/providers/alerts/appDistribution.d.ts +101 -1
- package/lib/v2/providers/alerts/appDistribution.js +28 -1
- package/lib/v2/providers/alerts/billing.d.ts +23 -2
- package/lib/v2/providers/alerts/billing.js +37 -0
- package/lib/v2/providers/alerts/crashlytics.d.ts +193 -18
- package/lib/v2/providers/alerts/crashlytics.js +62 -1
- package/lib/v2/providers/alerts/index.d.ts +6 -0
- package/lib/v2/providers/alerts/index.js +27 -0
- package/lib/v2/providers/database.d.ts +182 -0
- package/lib/v2/providers/database.js +204 -0
- package/lib/v2/providers/eventarc.d.ts +89 -5
- package/lib/v2/providers/eventarc.js +4 -0
- package/lib/v2/providers/https.d.ts +123 -2
- package/lib/v2/providers/https.js +13 -3
- package/lib/v2/providers/identity.d.ts +108 -4
- package/lib/v2/providers/identity.js +33 -2
- package/lib/v2/providers/pubsub.d.ts +122 -5
- package/lib/v2/providers/pubsub.js +58 -2
- package/lib/v2/providers/storage.d.ts +192 -4
- package/lib/v2/providers/storage.js +52 -9
- package/lib/v2/providers/tasks.d.ts +106 -6
- package/lib/v2/providers/tasks.js +4 -0
- package/package.json +12 -6
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
// The MIT License (MIT)
|
|
4
|
+
//
|
|
5
|
+
// Copyright (c) 2022 Firebase
|
|
6
|
+
//
|
|
7
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
// in the Software without restriction, including without limitation the rights
|
|
10
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
// furnished to do so, subject to the following conditions:
|
|
13
|
+
//
|
|
14
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
// copies or substantial portions of the Software.
|
|
16
|
+
//
|
|
17
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
// SOFTWARE.
|
|
3
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
25
|
const express = require("express");
|
|
5
26
|
const loader_1 = require("../runtime/loader");
|
package/lib/cloud-functions.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DeploymentOptions, FailurePolicy, Schedule } from './function-configura
|
|
|
3
3
|
export { Request, Response };
|
|
4
4
|
import { Duration } from './common/encoding';
|
|
5
5
|
import { ManifestEndpoint, ManifestRequiredAPI } from './runtime/manifest';
|
|
6
|
+
export { Change } from './common/change';
|
|
6
7
|
/**
|
|
7
8
|
* @hidden
|
|
8
9
|
*
|
|
@@ -111,54 +112,6 @@ export interface EventContext {
|
|
|
111
112
|
*/
|
|
112
113
|
timestamp: string;
|
|
113
114
|
}
|
|
114
|
-
/**
|
|
115
|
-
* The Functions interface for events that change state, such as
|
|
116
|
-
* Realtime Database or Cloud Firestore `onWrite` and `onUpdate`.
|
|
117
|
-
*
|
|
118
|
-
* For more information about the format used to construct `Change` objects, see
|
|
119
|
-
* [`cloud-functions.ChangeJson`](/docs/reference/functions/cloud_functions_.changejson).
|
|
120
|
-
*
|
|
121
|
-
*/
|
|
122
|
-
export declare class Change<T> {
|
|
123
|
-
before: T;
|
|
124
|
-
after: T;
|
|
125
|
-
constructor(before: T, after: T);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* `ChangeJson` is the JSON format used to construct a Change object.
|
|
129
|
-
*/
|
|
130
|
-
export interface ChangeJson {
|
|
131
|
-
/**
|
|
132
|
-
* Key-value pairs representing state of data after the change.
|
|
133
|
-
*/
|
|
134
|
-
after?: any;
|
|
135
|
-
/**
|
|
136
|
-
* Key-value pairs representing state of data before the change. If
|
|
137
|
-
* `fieldMask` is set, then only fields that changed are present in `before`.
|
|
138
|
-
*/
|
|
139
|
-
before?: any;
|
|
140
|
-
/**
|
|
141
|
-
* @hidden
|
|
142
|
-
* Comma-separated string that represents names of fields that changed.
|
|
143
|
-
*/
|
|
144
|
-
fieldMask?: string;
|
|
145
|
-
}
|
|
146
|
-
export declare namespace Change {
|
|
147
|
-
/**
|
|
148
|
-
* @hidden
|
|
149
|
-
* Factory method for creating a Change from a `before` object and an `after`
|
|
150
|
-
* object.
|
|
151
|
-
*/
|
|
152
|
-
function fromObjects<T>(before: T, after: T): Change<T>;
|
|
153
|
-
/**
|
|
154
|
-
* @hidden
|
|
155
|
-
* Factory method for creating a Change from a JSON and an optional customizer
|
|
156
|
-
* function to be applied to both the `before` and the `after` fields.
|
|
157
|
-
*/
|
|
158
|
-
function fromJSON<T>(json: ChangeJson, customizer?: (x: any) => T): Change<T>;
|
|
159
|
-
/** @hidden */
|
|
160
|
-
function applyFieldMask(sparseBefore: any, after: any, fieldMask: string): any;
|
|
161
|
-
}
|
|
162
115
|
/**
|
|
163
116
|
* Resource is a standard format for defining a resource
|
|
164
117
|
* (google.rpc.context.AttributeContext.Resource). In Cloud Functions, it is the
|
|
@@ -173,46 +126,35 @@ export interface Resource {
|
|
|
173
126
|
};
|
|
174
127
|
}
|
|
175
128
|
/**
|
|
176
|
-
*
|
|
177
|
-
* TriggerAnnotated is used internally by the firebase CLI to understand what
|
|
129
|
+
* TriggerAnnotion is used internally by the firebase CLI to understand what
|
|
178
130
|
* type of Cloud Function to deploy.
|
|
179
131
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
options?: Record<string, unknown>;
|
|
186
|
-
};
|
|
187
|
-
eventTrigger?: {
|
|
188
|
-
eventType: string;
|
|
189
|
-
resource: string;
|
|
190
|
-
service: string;
|
|
191
|
-
};
|
|
192
|
-
failurePolicy?: FailurePolicy;
|
|
193
|
-
httpsTrigger?: {
|
|
194
|
-
invoker?: string[];
|
|
195
|
-
};
|
|
196
|
-
labels?: {
|
|
197
|
-
[key: string]: string;
|
|
198
|
-
};
|
|
199
|
-
regions?: string[];
|
|
200
|
-
schedule?: Schedule;
|
|
201
|
-
timeout?: Duration;
|
|
202
|
-
vpcConnector?: string;
|
|
203
|
-
vpcConnectorEgressSettings?: string;
|
|
204
|
-
serviceAccountEmail?: string;
|
|
205
|
-
ingressSettings?: string;
|
|
206
|
-
secrets?: string[];
|
|
132
|
+
interface TriggerAnnotation {
|
|
133
|
+
availableMemoryMb?: number;
|
|
134
|
+
blockingTrigger?: {
|
|
135
|
+
eventType: string;
|
|
136
|
+
options?: Record<string, unknown>;
|
|
207
137
|
};
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
138
|
+
eventTrigger?: {
|
|
139
|
+
eventType: string;
|
|
140
|
+
resource: string;
|
|
141
|
+
service: string;
|
|
142
|
+
};
|
|
143
|
+
failurePolicy?: FailurePolicy;
|
|
144
|
+
httpsTrigger?: {
|
|
145
|
+
invoker?: string[];
|
|
146
|
+
};
|
|
147
|
+
labels?: {
|
|
148
|
+
[key: string]: string;
|
|
149
|
+
};
|
|
150
|
+
regions?: string[];
|
|
151
|
+
schedule?: Schedule;
|
|
152
|
+
timeout?: Duration;
|
|
153
|
+
vpcConnector?: string;
|
|
154
|
+
vpcConnectorEgressSettings?: string;
|
|
155
|
+
serviceAccountEmail?: string;
|
|
156
|
+
ingressSettings?: string;
|
|
157
|
+
secrets?: string[];
|
|
216
158
|
}
|
|
217
159
|
/**
|
|
218
160
|
* A Runnable has a `run` method which directly invokes the user-defined
|
|
@@ -230,11 +172,27 @@ export interface Runnable<T> {
|
|
|
230
172
|
* [`Response`](https://expressjs.com/en/api.html#res) objects as its only
|
|
231
173
|
* arguments.
|
|
232
174
|
*/
|
|
233
|
-
export
|
|
175
|
+
export interface HttpsFunction {
|
|
176
|
+
(req: Request, resp: Response): void | Promise<void>;
|
|
177
|
+
/** @alpha */
|
|
178
|
+
__trigger: TriggerAnnotation;
|
|
179
|
+
/** @alpha */
|
|
180
|
+
__endpoint: ManifestEndpoint;
|
|
181
|
+
/** @alpha */
|
|
182
|
+
__requiredAPIs?: ManifestRequiredAPI[];
|
|
183
|
+
}
|
|
234
184
|
/**
|
|
235
185
|
* The Cloud Function type for Blocking triggers.
|
|
236
186
|
*/
|
|
237
|
-
export
|
|
187
|
+
export interface BlockingFunction {
|
|
188
|
+
(req: Request, resp: Response): void | Promise<void>;
|
|
189
|
+
/** @alpha */
|
|
190
|
+
__trigger: TriggerAnnotation;
|
|
191
|
+
/** @alpha */
|
|
192
|
+
__endpoint: ManifestEndpoint;
|
|
193
|
+
/** @alpha */
|
|
194
|
+
__requiredAPIs?: ManifestRequiredAPI[];
|
|
195
|
+
}
|
|
238
196
|
/**
|
|
239
197
|
* The Cloud Function type for all non-HTTPS triggers. This should be exported
|
|
240
198
|
* from your JavaScript file to define a Cloud Function.
|
|
@@ -242,7 +200,15 @@ export declare type BlockingFunction = HttpsFunction;
|
|
|
242
200
|
* This type is a special JavaScript function which takes a templated
|
|
243
201
|
* `Event` object as its only argument.
|
|
244
202
|
*/
|
|
245
|
-
export
|
|
203
|
+
export interface CloudFunction<T> extends Runnable<T> {
|
|
204
|
+
(input: any, context?: any): PromiseLike<any> | any;
|
|
205
|
+
/** @alpha */
|
|
206
|
+
__trigger: TriggerAnnotation;
|
|
207
|
+
/** @alpha */
|
|
208
|
+
__endpoint: ManifestEndpoint;
|
|
209
|
+
/** @alpha */
|
|
210
|
+
__requiredAPIs?: ManifestRequiredAPI[];
|
|
211
|
+
}
|
|
246
212
|
/** @hidden */
|
|
247
213
|
export interface MakeCloudFunctionArgs<EventData> {
|
|
248
214
|
after?: (raw: Event) => void;
|
package/lib/cloud-functions.js
CHANGED
|
@@ -26,67 +26,10 @@ const _ = require("lodash");
|
|
|
26
26
|
const function_configuration_1 = require("./function-configuration");
|
|
27
27
|
const logger_1 = require("./logger");
|
|
28
28
|
const encoding_1 = require("./common/encoding");
|
|
29
|
+
var change_1 = require("./common/change");
|
|
30
|
+
Object.defineProperty(exports, "Change", { enumerable: true, get: function () { return change_1.Change; } });
|
|
29
31
|
/** @hidden */
|
|
30
32
|
const WILDCARD_REGEX = new RegExp('{[^/{}]*}', 'g');
|
|
31
|
-
/**
|
|
32
|
-
* The Functions interface for events that change state, such as
|
|
33
|
-
* Realtime Database or Cloud Firestore `onWrite` and `onUpdate`.
|
|
34
|
-
*
|
|
35
|
-
* For more information about the format used to construct `Change` objects, see
|
|
36
|
-
* [`cloud-functions.ChangeJson`](/docs/reference/functions/cloud_functions_.changejson).
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
class Change {
|
|
40
|
-
constructor(before, after) {
|
|
41
|
-
this.before = before;
|
|
42
|
-
this.after = after;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.Change = Change;
|
|
46
|
-
(function (Change) {
|
|
47
|
-
/** @hidden */
|
|
48
|
-
function reinterpretCast(x) {
|
|
49
|
-
return x;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @hidden
|
|
53
|
-
* Factory method for creating a Change from a `before` object and an `after`
|
|
54
|
-
* object.
|
|
55
|
-
*/
|
|
56
|
-
function fromObjects(before, after) {
|
|
57
|
-
return new Change(before, after);
|
|
58
|
-
}
|
|
59
|
-
Change.fromObjects = fromObjects;
|
|
60
|
-
/**
|
|
61
|
-
* @hidden
|
|
62
|
-
* Factory method for creating a Change from a JSON and an optional customizer
|
|
63
|
-
* function to be applied to both the `before` and the `after` fields.
|
|
64
|
-
*/
|
|
65
|
-
function fromJSON(json, customizer = reinterpretCast) {
|
|
66
|
-
let before = { ...json.before };
|
|
67
|
-
if (json.fieldMask) {
|
|
68
|
-
before = applyFieldMask(before, json.after, json.fieldMask);
|
|
69
|
-
}
|
|
70
|
-
return Change.fromObjects(customizer(before || {}), customizer(json.after || {}));
|
|
71
|
-
}
|
|
72
|
-
Change.fromJSON = fromJSON;
|
|
73
|
-
/** @hidden */
|
|
74
|
-
function applyFieldMask(sparseBefore, after, fieldMask) {
|
|
75
|
-
const before = { ...after };
|
|
76
|
-
const masks = fieldMask.split(',');
|
|
77
|
-
masks.forEach((mask) => {
|
|
78
|
-
const val = _.get(sparseBefore, mask);
|
|
79
|
-
if (typeof val === 'undefined') {
|
|
80
|
-
_.unset(before, mask);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
_.set(before, mask, val);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
return before;
|
|
87
|
-
}
|
|
88
|
-
Change.applyFieldMask = applyFieldMask;
|
|
89
|
-
})(Change = exports.Change || (exports.Change = {}));
|
|
90
33
|
/** @hidden */
|
|
91
34
|
function makeCloudFunction({ after = () => { }, before = () => { }, contextOnlyHandler, dataConstructor = (raw) => raw.data, eventType, handler, labels = {}, legacyEventType, options = {}, provider, service, triggerResource, }) {
|
|
92
35
|
const cloudFunction = (data, context) => {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ChangeJson` is the JSON format used to construct a Change object.
|
|
3
|
+
*/
|
|
4
|
+
export interface ChangeJson {
|
|
5
|
+
/**
|
|
6
|
+
* Key-value pairs representing state of data after the change.
|
|
7
|
+
*/
|
|
8
|
+
after?: any;
|
|
9
|
+
/**
|
|
10
|
+
* Key-value pairs representing state of data before the change. If
|
|
11
|
+
* `fieldMask` is set, then only fields that changed are present in `before`.
|
|
12
|
+
*/
|
|
13
|
+
before?: any;
|
|
14
|
+
/**
|
|
15
|
+
* @hidden
|
|
16
|
+
* Comma-separated string that represents names of fields that changed.
|
|
17
|
+
*/
|
|
18
|
+
fieldMask?: string;
|
|
19
|
+
}
|
|
20
|
+
/** @hidden */
|
|
21
|
+
export declare function applyFieldMask(sparseBefore: any, after: any, fieldMask: string): any;
|
|
22
|
+
/**
|
|
23
|
+
* The Functions interface for events that change state, such as
|
|
24
|
+
* Realtime Database or Cloud Firestore `onWrite` and `onUpdate`.
|
|
25
|
+
*
|
|
26
|
+
* For more information about the format used to construct `Change` objects, see
|
|
27
|
+
* {@link ChangeJson} below.
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
export declare class Change<T> {
|
|
31
|
+
before: T;
|
|
32
|
+
after: T;
|
|
33
|
+
/**
|
|
34
|
+
* @hidden
|
|
35
|
+
* Factory method for creating a Change from a `before` object and an `after`
|
|
36
|
+
* object.
|
|
37
|
+
*/
|
|
38
|
+
static fromObjects<T>(before: T, after: T): Change<T>;
|
|
39
|
+
/**
|
|
40
|
+
* @hidden
|
|
41
|
+
* Factory method for creating a Change from a JSON and an optional customizer
|
|
42
|
+
* function to be applied to both the `before` and the `after` fields.
|
|
43
|
+
*/
|
|
44
|
+
static fromJSON<T>(json: ChangeJson, customizer?: (x: any) => T): Change<T>;
|
|
45
|
+
constructor(before: T, after: T);
|
|
46
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2022 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.Change = exports.applyFieldMask = void 0;
|
|
25
|
+
/** @hidden */
|
|
26
|
+
function applyFieldMask(sparseBefore, after, fieldMask) {
|
|
27
|
+
const before = { ...after };
|
|
28
|
+
const masks = fieldMask.split(',');
|
|
29
|
+
for (const mask of masks) {
|
|
30
|
+
const parts = mask.split('.');
|
|
31
|
+
const head = parts[0];
|
|
32
|
+
const tail = parts.slice(1).join('.');
|
|
33
|
+
if (parts.length > 1) {
|
|
34
|
+
before[head] = applyFieldMask(sparseBefore === null || sparseBefore === void 0 ? void 0 : sparseBefore[head], after[head], tail);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const val = sparseBefore === null || sparseBefore === void 0 ? void 0 : sparseBefore[head];
|
|
38
|
+
if (typeof val === 'undefined') {
|
|
39
|
+
delete before[mask];
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
before[mask] = val;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return before;
|
|
46
|
+
}
|
|
47
|
+
exports.applyFieldMask = applyFieldMask;
|
|
48
|
+
/**
|
|
49
|
+
* The Functions interface for events that change state, such as
|
|
50
|
+
* Realtime Database or Cloud Firestore `onWrite` and `onUpdate`.
|
|
51
|
+
*
|
|
52
|
+
* For more information about the format used to construct `Change` objects, see
|
|
53
|
+
* {@link ChangeJson} below.
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
class Change {
|
|
57
|
+
constructor(before, after) {
|
|
58
|
+
this.before = before;
|
|
59
|
+
this.after = after;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @hidden
|
|
63
|
+
* Factory method for creating a Change from a `before` object and an `after`
|
|
64
|
+
* object.
|
|
65
|
+
*/
|
|
66
|
+
static fromObjects(before, after) {
|
|
67
|
+
return new Change(before, after);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @hidden
|
|
71
|
+
* Factory method for creating a Change from a JSON and an optional customizer
|
|
72
|
+
* function to be applied to both the `before` and the `after` fields.
|
|
73
|
+
*/
|
|
74
|
+
static fromJSON(json, customizer = (x) => x) {
|
|
75
|
+
let before = { ...json.before };
|
|
76
|
+
if (json.fieldMask) {
|
|
77
|
+
before = applyFieldMask(before, json.after, json.fieldMask);
|
|
78
|
+
}
|
|
79
|
+
return Change.fromObjects(customizer(before || {}), customizer(json.after || {}));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.Change = Change;
|
package/lib/common/encoding.js
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2021 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
3
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
24
|
exports.convertInvoker = exports.serviceAccountFromShorthand = exports.convertIfPresent = exports.copyIfPresent = exports.durationFromSeconds = void 0;
|
|
5
25
|
/** Get a google.protobuf.Duration for a number of seconds. */
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as firebase from 'firebase-admin';
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a Firebase Realtime Database data snapshot.
|
|
4
|
+
*/
|
|
5
|
+
export declare class DataSnapshot {
|
|
6
|
+
private app?;
|
|
7
|
+
instance: string;
|
|
8
|
+
/** @hidden */
|
|
9
|
+
private _ref;
|
|
10
|
+
/** @hidden */
|
|
11
|
+
private _path;
|
|
12
|
+
/** @hidden */
|
|
13
|
+
private _data;
|
|
14
|
+
/** @hidden */
|
|
15
|
+
private _childPath;
|
|
16
|
+
constructor(data: any, path?: string, // path will be undefined for the database root
|
|
17
|
+
app?: firebase.app.App, instance?: string);
|
|
18
|
+
/**
|
|
19
|
+
* Returns a [`Reference`](/docs/reference/admin/node/admin.database.Reference)
|
|
20
|
+
* to the Database location where the triggering write occurred. Has
|
|
21
|
+
* full read and write access.
|
|
22
|
+
*/
|
|
23
|
+
get ref(): firebase.database.Reference;
|
|
24
|
+
/**
|
|
25
|
+
* The key (last part of the path) of the location of this `DataSnapshot`.
|
|
26
|
+
*
|
|
27
|
+
* The last token in a Database location is considered its key. For example,
|
|
28
|
+
* "ada" is the key for the `/users/ada/` node. Accessing the key on any
|
|
29
|
+
* `DataSnapshot` will return the key for the location that generated it.
|
|
30
|
+
* However, accessing the key on the root URL of a Database will return `null`.
|
|
31
|
+
*/
|
|
32
|
+
get key(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Extracts a JavaScript value from a `DataSnapshot`.
|
|
35
|
+
*
|
|
36
|
+
* Depending on the data in a `DataSnapshot`, the `val()` method may return a
|
|
37
|
+
* scalar type (string, number, or boolean), an array, or an object. It may also
|
|
38
|
+
* return `null`, indicating that the `DataSnapshot` is empty (contains no
|
|
39
|
+
* data).
|
|
40
|
+
*
|
|
41
|
+
* @return The DataSnapshot's contents as a JavaScript value (Object,
|
|
42
|
+
* Array, string, number, boolean, or `null`).
|
|
43
|
+
*/
|
|
44
|
+
val(): any;
|
|
45
|
+
/**
|
|
46
|
+
* Exports the entire contents of the `DataSnapshot` as a JavaScript object.
|
|
47
|
+
*
|
|
48
|
+
* The `exportVal()` method is similar to `val()`, except priority information
|
|
49
|
+
* is included (if available), making it suitable for backing up your data.
|
|
50
|
+
*
|
|
51
|
+
* @return The contents of the `DataSnapshot` as a JavaScript value
|
|
52
|
+
* (Object, Array, string, number, boolean, or `null`).
|
|
53
|
+
*/
|
|
54
|
+
exportVal(): any;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the priority value of the data in this `DataSnapshot`.
|
|
57
|
+
*
|
|
58
|
+
* As an alternative to using priority, applications can order collections by
|
|
59
|
+
* ordinary properties. See [Sorting and filtering
|
|
60
|
+
* data](/docs/database/web/lists-of-data#sorting_and_filtering_data).
|
|
61
|
+
*
|
|
62
|
+
* @return The priority value of the data.
|
|
63
|
+
*/
|
|
64
|
+
getPriority(): string | number | null;
|
|
65
|
+
/**
|
|
66
|
+
* Returns `true` if this `DataSnapshot` contains any data. It is slightly more
|
|
67
|
+
* efficient than using `snapshot.val() !== null`.
|
|
68
|
+
*
|
|
69
|
+
* @return `true` if this `DataSnapshot` contains any data; otherwise, `false`.
|
|
70
|
+
*/
|
|
71
|
+
exists(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Gets a `DataSnapshot` for the location at the specified relative path.
|
|
74
|
+
*
|
|
75
|
+
* The relative path can either be a simple child name (for example, "ada") or
|
|
76
|
+
* a deeper slash-separated path (for example, "ada/name/first").
|
|
77
|
+
*
|
|
78
|
+
* @param path A relative path from this location to the desired child
|
|
79
|
+
* location.
|
|
80
|
+
* @return The specified child location.
|
|
81
|
+
*/
|
|
82
|
+
child(childPath: string): DataSnapshot;
|
|
83
|
+
/**
|
|
84
|
+
* Enumerates the `DataSnapshot`s of the children items.
|
|
85
|
+
*
|
|
86
|
+
* Because of the way JavaScript objects work, the ordering of data in the
|
|
87
|
+
* JavaScript object returned by `val()` is not guaranteed to match the ordering
|
|
88
|
+
* on the server nor the ordering of `child_added` events. That is where
|
|
89
|
+
* `forEach()` comes in handy. It guarantees the children of a `DataSnapshot`
|
|
90
|
+
* will be iterated in their query order.
|
|
91
|
+
*
|
|
92
|
+
* If no explicit `orderBy*()` method is used, results are returned
|
|
93
|
+
* ordered by key (unless priorities are used, in which case, results are
|
|
94
|
+
* returned by priority).
|
|
95
|
+
*
|
|
96
|
+
* @param action A function that will be called for each child `DataSnapshot`.
|
|
97
|
+
* The callback can return `true` to cancel further enumeration.
|
|
98
|
+
*
|
|
99
|
+
* @return `true` if enumeration was canceled due to your callback
|
|
100
|
+
* returning `true`.
|
|
101
|
+
*/
|
|
102
|
+
forEach(action: (a: DataSnapshot) => boolean | void): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Returns `true` if the specified child path has (non-`null`) data.
|
|
105
|
+
*
|
|
106
|
+
* @param path A relative path to the location of a potential child.
|
|
107
|
+
* @return `true` if data exists at the specified child path; otherwise,
|
|
108
|
+
* `false`.
|
|
109
|
+
*/
|
|
110
|
+
hasChild(childPath: string): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Returns whether or not the `DataSnapshot` has any non-`null` child
|
|
113
|
+
* properties.
|
|
114
|
+
*
|
|
115
|
+
* You can use `hasChildren()` to determine if a `DataSnapshot` has any
|
|
116
|
+
* children. If it does, you can enumerate them using `forEach()`. If it
|
|
117
|
+
* doesn't, then either this snapshot contains a primitive value (which can be
|
|
118
|
+
* retrieved with `val()`) or it is empty (in which case, `val()` will return
|
|
119
|
+
* `null`).
|
|
120
|
+
*
|
|
121
|
+
* @return `true` if this snapshot has any children; else `false`.
|
|
122
|
+
*/
|
|
123
|
+
hasChildren(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Returns the number of child properties of this `DataSnapshot`.
|
|
126
|
+
*
|
|
127
|
+
* @return Number of child properties of this `DataSnapshot`.
|
|
128
|
+
*/
|
|
129
|
+
numChildren(): number;
|
|
130
|
+
/**
|
|
131
|
+
* Returns a JSON-serializable representation of this object.
|
|
132
|
+
*
|
|
133
|
+
* @return A JSON-serializable representation of this object.
|
|
134
|
+
*/
|
|
135
|
+
toJSON(): Object;
|
|
136
|
+
/** Recursive function to check if keys are numeric & convert node object to array if they are
|
|
137
|
+
*
|
|
138
|
+
* @hidden
|
|
139
|
+
*/
|
|
140
|
+
private _checkAndConvertToArray;
|
|
141
|
+
/** @hidden */
|
|
142
|
+
private _dup;
|
|
143
|
+
/** @hidden */
|
|
144
|
+
private _fullPath;
|
|
145
|
+
}
|