@firebase-function-kits/firestore-bigquery-export 0.0.2-rc.0 → 0.0.2-rc.10
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/CHANGELOG.md +5 -1
- package/README.md +281 -60
- package/lib/config.d.ts +3 -2
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +295 -70
- package/lib/config.js.map +1 -1
- package/lib/events.d.ts.map +1 -1
- package/lib/events.js.map +1 -1
- package/lib/export-config.d.ts +19 -5
- package/lib/export-config.d.ts.map +1 -1
- package/lib/export-config.js +6 -1
- package/lib/export-config.js.map +1 -1
- package/lib/handlers.d.ts +38 -6
- package/lib/handlers.d.ts.map +1 -1
- package/lib/handlers.js +63 -18
- package/lib/handlers.js.map +1 -1
- package/lib/index.d.ts +13 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +51 -12
- package/lib/index.js.map +1 -1
- package/lib/init.d.ts +1 -1
- package/lib/init.js +1 -1
- package/lib/init.js.map +1 -1
- package/lib/lib.d.ts +1 -1
- package/lib/lib.d.ts.map +1 -1
- package/lib/lib.js +2 -1
- package/lib/lib.js.map +1 -1
- package/lib/logs.d.ts +2 -2
- package/lib/logs.d.ts.map +1 -1
- package/lib/logs.js +4 -3
- package/lib/logs.js.map +1 -1
- package/lib/region.d.ts +7 -0
- package/lib/region.d.ts.map +1 -0
- package/lib/region.js +37 -0
- package/lib/region.js.map +1 -0
- package/lib/tasks.d.ts +40 -0
- package/lib/tasks.d.ts.map +1 -0
- package/lib/tasks.js +107 -0
- package/lib/tasks.js.map +1 -0
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js.map +1 -1
- package/npm-shrinkwrap.json +6396 -0
- package/package.json +15 -5
- package/src/config.ts +359 -72
- package/src/export-config.ts +26 -6
- package/src/handlers.ts +96 -27
- package/src/index.ts +71 -13
- package/src/init.ts +1 -1
- package/src/lib.ts +2 -0
- package/src/logs.ts +5 -3
- package/src/region.ts +37 -0
- package/src/tasks.ts +126 -0
- package/tests/config.test.ts +101 -14
- package/tests/export-config.test.ts +10 -4
- package/tests/handlers.test.ts +139 -10
- package/tests/index.test.ts +162 -0
- package/tests/region.test.ts +44 -0
- package/tests/required-apis.test.ts +55 -0
- package/tests/tasks.emulator.test.ts +131 -0
- package/tests/tasks.test.ts +229 -0
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firebase-function-kits/firestore-bigquery-export",
|
|
3
|
-
"version": "0.0.2-rc.
|
|
4
|
-
"repository":
|
|
3
|
+
"version": "0.0.2-rc.10",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/firebase/extensions.git",
|
|
7
|
+
"directory": "kits/firestore-bigquery-export"
|
|
8
|
+
},
|
|
5
9
|
"description": "Stream a Cloud Firestore collection to BigQuery as a deployable Firebase Function",
|
|
6
10
|
"license": "Apache-2.0",
|
|
7
11
|
"main": "lib/index.js",
|
|
@@ -27,15 +31,21 @@
|
|
|
27
31
|
"serve": "firebase emulators:start --only functions"
|
|
28
32
|
},
|
|
29
33
|
"dependencies": {
|
|
30
|
-
"@firebaseextensions/firestore-bigquery-change-tracker": "^2.
|
|
34
|
+
"@firebaseextensions/firestore-bigquery-change-tracker": "^2.2.1",
|
|
31
35
|
"@google-cloud/bigquery": "^7.6.0",
|
|
32
|
-
"firebase-admin": "^14.
|
|
33
|
-
"firebase-functions": "7.3.
|
|
36
|
+
"firebase-admin": "^14.2.0",
|
|
37
|
+
"firebase-functions": "^7.3.3-rc.1",
|
|
34
38
|
"generate-schema": "^2.6.0",
|
|
35
39
|
"lodash": "^4.17.14"
|
|
36
40
|
},
|
|
41
|
+
"overrides": {
|
|
42
|
+
"@firebaseextensions/firestore-bigquery-change-tracker": {
|
|
43
|
+
"firebase-functions": "$firebase-functions"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
37
46
|
"devDependencies": {
|
|
38
47
|
"@types/lodash": "^4.17.0",
|
|
48
|
+
"typescript": "^5.9.3",
|
|
39
49
|
"vitest": "^3.2.4"
|
|
40
50
|
}
|
|
41
51
|
}
|
package/src/config.ts
CHANGED
|
@@ -20,9 +20,10 @@ import type {
|
|
|
20
20
|
TimePartitioningGranularity,
|
|
21
21
|
} from "@firebaseextensions/firestore-bigquery-change-tracker";
|
|
22
22
|
import { LogLevel } from "@firebaseextensions/firestore-bigquery-change-tracker";
|
|
23
|
-
import type { Expression } from "firebase-functions/params";
|
|
23
|
+
import type { Expression, IntParam } from "firebase-functions/params";
|
|
24
24
|
import {
|
|
25
25
|
defineBoolean,
|
|
26
|
+
defineInt,
|
|
26
27
|
defineString,
|
|
27
28
|
projectID,
|
|
28
29
|
select,
|
|
@@ -78,53 +79,6 @@ const DATASET_LOCATION_OPTIONS = [
|
|
|
78
79
|
"us-south1",
|
|
79
80
|
"us-east5",
|
|
80
81
|
] as const;
|
|
81
|
-
const DATABASE_REGION_OPTIONS = [
|
|
82
|
-
"eur3",
|
|
83
|
-
"nam5",
|
|
84
|
-
"nam7",
|
|
85
|
-
"us-central1",
|
|
86
|
-
"us-west1",
|
|
87
|
-
"us-west2",
|
|
88
|
-
"us-west3",
|
|
89
|
-
"us-west4",
|
|
90
|
-
"us-east1",
|
|
91
|
-
"us-east4",
|
|
92
|
-
"us-east5",
|
|
93
|
-
"us-south1",
|
|
94
|
-
"northamerica-northeast1",
|
|
95
|
-
"northamerica-northeast2",
|
|
96
|
-
"northamerica-south1",
|
|
97
|
-
"southamerica-east1",
|
|
98
|
-
"southamerica-west1",
|
|
99
|
-
"europe-west1",
|
|
100
|
-
"europe-west2",
|
|
101
|
-
"europe-west3",
|
|
102
|
-
"europe-west4",
|
|
103
|
-
"europe-west6",
|
|
104
|
-
"europe-west8",
|
|
105
|
-
"europe-west9",
|
|
106
|
-
"europe-west10",
|
|
107
|
-
"europe-west12",
|
|
108
|
-
"europe-southwest1",
|
|
109
|
-
"europe-north1",
|
|
110
|
-
"europe-north2",
|
|
111
|
-
"europe-central2",
|
|
112
|
-
"me-central1",
|
|
113
|
-
"me-central2",
|
|
114
|
-
"me-west1",
|
|
115
|
-
"asia-south1",
|
|
116
|
-
"asia-south2",
|
|
117
|
-
"asia-southeast1",
|
|
118
|
-
"asia-southeast2",
|
|
119
|
-
"asia-east1",
|
|
120
|
-
"asia-east2",
|
|
121
|
-
"asia-northeast1",
|
|
122
|
-
"asia-northeast2",
|
|
123
|
-
"asia-northeast3",
|
|
124
|
-
"australia-southeast1",
|
|
125
|
-
"australia-southeast2",
|
|
126
|
-
"africa-south1",
|
|
127
|
-
] as const;
|
|
128
82
|
const TABLE_PARTITIONING_OPTIONS = [
|
|
129
83
|
"HOUR",
|
|
130
84
|
"DAY",
|
|
@@ -148,8 +102,9 @@ export interface ConfigExpressions {
|
|
|
148
102
|
collectionPath: ConfigExpression<string>;
|
|
149
103
|
datasetId: ConfigExpression<string>;
|
|
150
104
|
tableId: ConfigExpression<string>;
|
|
151
|
-
location: ConfigExpression<string>;
|
|
152
105
|
database: ConfigExpression<string>;
|
|
106
|
+
/** An `IntParam`, not a bare expression: the queue's `rateLimits` guards it with a CEL comparison. */
|
|
107
|
+
maxDispatchesPerSecond: IntParam;
|
|
153
108
|
}
|
|
154
109
|
|
|
155
110
|
/**
|
|
@@ -160,58 +115,370 @@ export interface ConfigExpressions {
|
|
|
160
115
|
*/
|
|
161
116
|
const params = {
|
|
162
117
|
bigqueryProjectId: defineString("BIGQUERY_PROJECT_ID", {
|
|
118
|
+
label: "BigQuery Project ID",
|
|
119
|
+
description:
|
|
120
|
+
"Override the default project for BigQuery instance. This can allow updates to be directed to to a BigQuery instance on another GCP project.",
|
|
121
|
+
|
|
163
122
|
default: projectID,
|
|
164
123
|
}),
|
|
165
|
-
database: defineString("DATABASE", {
|
|
124
|
+
database: defineString("DATABASE", {
|
|
125
|
+
label: "Firestore Instance ID",
|
|
126
|
+
description:
|
|
127
|
+
'The Firestore database to use. Use "(default)" for the default database. You can view your available Firestore databases at https://console.cloud.google.com/firestore/databases.',
|
|
128
|
+
default: "(default)",
|
|
129
|
+
input: { text: { example: "(default)" } },
|
|
130
|
+
}),
|
|
131
|
+
// Declared so the CLI prompts for the value and persists it to `.env`; the
|
|
132
|
+
// function region option cannot be a param expression, so the entry point
|
|
133
|
+
// reads the same variable from `process.env` at module load instead.
|
|
166
134
|
databaseRegion: defineString("DATABASE_REGION", {
|
|
167
|
-
|
|
135
|
+
label: "Firestore Instance Location",
|
|
136
|
+
description:
|
|
137
|
+
"Where is the Firestore database located? You can check your current database location at https://console.cloud.google.com/firestore/databases. The functions in this kit deploy to the Cloud Run region closest to this location.",
|
|
138
|
+
|
|
139
|
+
input: select({
|
|
140
|
+
"Multi-region (Europe - Belgium and Netherlands)": "eur3",
|
|
141
|
+
"Multi-region (United States)": "nam5",
|
|
142
|
+
"Multi-region (Iowa, North Virginia, and Oklahoma)": "nam7",
|
|
143
|
+
"Iowa (us-central1)": "us-central1",
|
|
144
|
+
"Oregon (us-west1)": "us-west1",
|
|
145
|
+
"Los Angeles (us-west2)": "us-west2",
|
|
146
|
+
"Salt Lake City (us-west3)": "us-west3",
|
|
147
|
+
"Las Vegas (us-west4)": "us-west4",
|
|
148
|
+
"South Carolina (us-east1)": "us-east1",
|
|
149
|
+
"Northern Virginia (us-east4)": "us-east4",
|
|
150
|
+
"Columbus (us-east5)": "us-east5",
|
|
151
|
+
"Dallas (us-south1)": "us-south1",
|
|
152
|
+
"Montreal (northamerica-northeast1)": "northamerica-northeast1",
|
|
153
|
+
"Toronto (northamerica-northeast2)": "northamerica-northeast2",
|
|
154
|
+
"Queretaro (northamerica-south1)": "northamerica-south1",
|
|
155
|
+
"Sao Paulo (southamerica-east1)": "southamerica-east1",
|
|
156
|
+
"Santiago (southamerica-west1)": "southamerica-west1",
|
|
157
|
+
"Belgium (europe-west1)": "europe-west1",
|
|
158
|
+
"London (europe-west2)": "europe-west2",
|
|
159
|
+
"Frankfurt (europe-west3)": "europe-west3",
|
|
160
|
+
"Netherlands (europe-west4)": "europe-west4",
|
|
161
|
+
"Zurich (europe-west6)": "europe-west6",
|
|
162
|
+
"Milan (europe-west8)": "europe-west8",
|
|
163
|
+
"Paris (europe-west9)": "europe-west9",
|
|
164
|
+
"Berlin (europe-west10)": "europe-west10",
|
|
165
|
+
"Turin (europe-west12)": "europe-west12",
|
|
166
|
+
"Madrid (europe-southwest1)": "europe-southwest1",
|
|
167
|
+
"Finland (europe-north1)": "europe-north1",
|
|
168
|
+
"Stockholm (europe-north2)": "europe-north2",
|
|
169
|
+
"Warsaw (europe-central2)": "europe-central2",
|
|
170
|
+
"Doha (me-central1)": "me-central1",
|
|
171
|
+
"Dammam (me-central2)": "me-central2",
|
|
172
|
+
"Tel Aviv (me-west1)": "me-west1",
|
|
173
|
+
"Mumbai (asia-south1)": "asia-south1",
|
|
174
|
+
"Delhi (asia-south2)": "asia-south2",
|
|
175
|
+
"Singapore (asia-southeast1)": "asia-southeast1",
|
|
176
|
+
"Jakarta (asia-southeast2)": "asia-southeast2",
|
|
177
|
+
"Kuala Lumpur (asia-southeast3)": "asia-southeast3",
|
|
178
|
+
"Taiwan (asia-east1)": "asia-east1",
|
|
179
|
+
"Hong Kong (asia-east2)": "asia-east2",
|
|
180
|
+
"Tokyo (asia-northeast1)": "asia-northeast1",
|
|
181
|
+
"Osaka (asia-northeast2)": "asia-northeast2",
|
|
182
|
+
"Seoul (asia-northeast3)": "asia-northeast3",
|
|
183
|
+
"Sydney (australia-southeast1)": "australia-southeast1",
|
|
184
|
+
"Melbourne (australia-southeast2)": "australia-southeast2",
|
|
185
|
+
"Johannesburg (africa-south1)": "africa-south1",
|
|
186
|
+
}),
|
|
187
|
+
}),
|
|
188
|
+
collectionPath: defineString("COLLECTION_PATH", {
|
|
189
|
+
label: "Collection path",
|
|
190
|
+
description:
|
|
191
|
+
"What is the path of the collection that you would like to export? You may use `{wildcard}` notation to match a subcollection of all documents in a collection (for example: `chatrooms/{chatid}/posts`). Parent Firestore Document IDs from `{wildcards}` can be returned in `path_params` as a JSON formatted string.",
|
|
192
|
+
|
|
193
|
+
default: "posts",
|
|
194
|
+
input: {
|
|
195
|
+
text: {
|
|
196
|
+
example: "posts",
|
|
197
|
+
|
|
198
|
+
validationRegex: /^[^\/]+(\/[^\/]+\/[^\/]+)*$/,
|
|
199
|
+
validationErrorMessage:
|
|
200
|
+
'Firestore collection paths must be an odd number of segments separated by slashes, e.g. "path/to/collection".',
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
}),
|
|
204
|
+
datasetId: defineString("DATASET_ID", {
|
|
205
|
+
label: "Dataset ID",
|
|
206
|
+
description:
|
|
207
|
+
"What ID would you like to use for your BigQuery dataset? This extension will create the dataset, if it doesn't already exist.",
|
|
208
|
+
|
|
209
|
+
default: "firestore_export",
|
|
210
|
+
input: {
|
|
211
|
+
text: {
|
|
212
|
+
example: "firestore_export",
|
|
213
|
+
|
|
214
|
+
validationRegex: /^[a-zA-Z0-9_]+$/,
|
|
215
|
+
validationErrorMessage:
|
|
216
|
+
"BigQuery dataset IDs must be alphanumeric (plus underscores) and must be no more than 1024 characters.",
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
}),
|
|
220
|
+
tableId: defineString("TABLE_ID", {
|
|
221
|
+
label: "Table ID",
|
|
222
|
+
description:
|
|
223
|
+
"What identifying prefix would you like to use for your table and view inside your BigQuery dataset? This extension will create the table and view, if they don't already exist.",
|
|
224
|
+
|
|
225
|
+
default: "posts",
|
|
226
|
+
input: {
|
|
227
|
+
text: {
|
|
228
|
+
example: "posts",
|
|
229
|
+
|
|
230
|
+
validationRegex: /^[a-zA-Z0-9_]+$/,
|
|
231
|
+
validationErrorMessage:
|
|
232
|
+
"BigQuery table IDs must be alphanumeric (plus underscores) and must be no more than 1024 characters.",
|
|
233
|
+
},
|
|
234
|
+
},
|
|
168
235
|
}),
|
|
169
|
-
collectionPath: defineString("COLLECTION_PATH", { default: "posts" }),
|
|
170
|
-
datasetId: defineString("DATASET_ID", { default: "firestore_export" }),
|
|
171
|
-
tableId: defineString("TABLE_ID", { default: "posts" }),
|
|
172
236
|
datasetLocation: defineString("DATASET_LOCATION", {
|
|
237
|
+
label: "BigQuery Dataset location",
|
|
238
|
+
description:
|
|
239
|
+
"Where do you want to deploy the BigQuery dataset created for this extension? For help selecting a location, refer to the [location selection guide](https://cloud.google.com/bigquery/docs/locations).",
|
|
240
|
+
|
|
173
241
|
default: "us",
|
|
174
|
-
input: select(
|
|
242
|
+
input: select({
|
|
243
|
+
"Iowa (us-central1)": "us-central1",
|
|
244
|
+
"Las Vegas (us-west4)": "us-west4",
|
|
245
|
+
"Warsaw (europe-central2)": "europe-central2",
|
|
246
|
+
"Los Angeles (us-west2)": "us-west2",
|
|
247
|
+
"Montreal (northamerica-northeast1)": "northamerica-northeast1",
|
|
248
|
+
"Northern Virginia (us-east4)": "us-east4",
|
|
249
|
+
"Oregon (us-west1)": "us-west1",
|
|
250
|
+
"Salt Lake City (us-west3)": "us-west3",
|
|
251
|
+
"Sao Paulo (southamerica-east1)": "southamerica-east1",
|
|
252
|
+
"South Carolina (us-east1)": "us-east1",
|
|
253
|
+
"Belgium (europe-west1)": "europe-west1",
|
|
254
|
+
"Finland (europe-north1)": "europe-north1",
|
|
255
|
+
"Frankfurt (europe-west3)": "europe-west3",
|
|
256
|
+
"London (europe-west2)": "europe-west2",
|
|
257
|
+
"Netherlands (europe-west4)": "europe-west4",
|
|
258
|
+
"Zurich (europe-west6)": "europe-west6",
|
|
259
|
+
"Taiwan (asia-east1)": "asia-east1",
|
|
260
|
+
"Hong Kong (asia-east2)": "asia-east2",
|
|
261
|
+
"Jakarta (asia-southeast2)": "asia-southeast2",
|
|
262
|
+
"Mumbai (asia-south1)": "asia-south1",
|
|
263
|
+
"Singapore (asia-southeast1)": "asia-southeast1",
|
|
264
|
+
"Osaka (asia-northeast2)": "asia-northeast2",
|
|
265
|
+
"Seoul (asia-northeast3)": "asia-northeast3",
|
|
266
|
+
"Sydney (australia-southeast1)": "australia-southeast1",
|
|
267
|
+
"Tokyo (asia-northeast1)": "asia-northeast1",
|
|
268
|
+
"United States (multi-regional)": "us",
|
|
269
|
+
"Europe (multi-regional)": "eu",
|
|
270
|
+
"Johannesburg (africa-south1)": "africa-south1",
|
|
271
|
+
"Tel Aviv (me-west1)": "me-west1",
|
|
272
|
+
"Doha (me-central1)": "me-central1",
|
|
273
|
+
"Dammam (me-central2)": "me-central2",
|
|
274
|
+
"Zürich (europe-west6)": "europe-west6",
|
|
275
|
+
"Turin (europe-west12)": "europe-west12",
|
|
276
|
+
"Stockholm (europe-north2)": "europe-north2",
|
|
277
|
+
"Paris (europe-west9)": "europe-west9",
|
|
278
|
+
"Milan (europe-west8)": "europe-west8",
|
|
279
|
+
"Madrid (europe-southwest1)": "europe-southwest1",
|
|
280
|
+
"Berlin (europe-west10)": "europe-west10",
|
|
281
|
+
"Melbourne (australia-southeast2)": "australia-southeast2",
|
|
282
|
+
"Delhi (asia-south2)": "asia-south2",
|
|
283
|
+
"Toronto (northamerica-northeast2)": "northamerica-northeast2",
|
|
284
|
+
"Santiago (southamerica-west1)": "southamerica-west1",
|
|
285
|
+
"Mexico (northamerica-south1)": "northamerica-south1",
|
|
286
|
+
"Dallas (us-south1)": "us-south1",
|
|
287
|
+
"Columbus, Ohio (us-east5)": "us-east5",
|
|
288
|
+
}),
|
|
289
|
+
}),
|
|
290
|
+
backupCollection: defineString("BACKUP_COLLECTION", {
|
|
291
|
+
label: "Backup Collection Name",
|
|
292
|
+
description:
|
|
293
|
+
"Strongly recommended. The Firestore collection where rows whose BigQuery insert is rejected are written, on the inline attempt and on each queue attempt; without it, those rows are dropped once the queue gives up. A change that cannot be enqueued at all is not backed up. See the README for how to reconcile backed-up rows into BigQuery.",
|
|
294
|
+
default: "",
|
|
295
|
+
}),
|
|
296
|
+
maxDispatchesPerSecond: defineInt("MAX_DISPATCHES_PER_SECOND", {
|
|
297
|
+
label: "Maximum number of synced documents per second",
|
|
298
|
+
description:
|
|
299
|
+
"This parameter will set the maximum number of synchronized documents per second with BQ. Please note, any other external updates to a Big Query table will be included within this quota. Ensure that you have set a low enough number to compensate. Defaults to 100.",
|
|
300
|
+
|
|
301
|
+
default: 100,
|
|
302
|
+
input: {
|
|
303
|
+
text: {
|
|
304
|
+
example: "100",
|
|
305
|
+
|
|
306
|
+
validationRegex: /^([1-9]|[1-9][0-9]|[1-4][0-9]{2}|500)$/,
|
|
307
|
+
validationErrorMessage: "Please select a number between 1 and 500",
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
}),
|
|
311
|
+
maxEnqueueAttempts: defineInt("MAX_ENQUEUE_ATTEMPTS", {
|
|
312
|
+
label: "Maximum number of enqueue attempts",
|
|
313
|
+
description:
|
|
314
|
+
"This parameter will set the maximum number of attempts to enqueue a document to cloud tasks for export to BigQuery.",
|
|
315
|
+
|
|
316
|
+
default: 3,
|
|
317
|
+
input: {
|
|
318
|
+
text: {
|
|
319
|
+
example: "3",
|
|
320
|
+
|
|
321
|
+
validationRegex: /^(10|[1-9])$/,
|
|
322
|
+
validationErrorMessage: "Please select an integer between 1 and 10",
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
}),
|
|
326
|
+
transformFunction: defineString("TRANSFORM_FUNCTION", {
|
|
327
|
+
label: "Transform function URL",
|
|
328
|
+
description:
|
|
329
|
+
"Specify a function URL to call that will transform the payload that will be written to BigQuery. See the pre-install documentation for more details.",
|
|
330
|
+
default: "",
|
|
331
|
+
input: {
|
|
332
|
+
text: {
|
|
333
|
+
example:
|
|
334
|
+
"https://us-west1-my-project-id.cloudfunctions.net/myTransformFunction",
|
|
335
|
+
},
|
|
336
|
+
},
|
|
175
337
|
}),
|
|
176
|
-
backupCollection: defineString("BACKUP_COLLECTION", { default: "" }),
|
|
177
|
-
transformFunction: defineString("TRANSFORM_FUNCTION", { default: "" }),
|
|
178
338
|
tablePartitioning: defineString("TABLE_PARTITIONING", {
|
|
339
|
+
label: "BigQuery SQL table Time Partitioning option type",
|
|
340
|
+
description:
|
|
341
|
+
"This parameter will allow you to partition the BigQuery table and BigQuery view created by the extension based on data ingestion time. You may select the granularity of partitioning based upon one of: HOUR, DAY, MONTH, YEAR. This will generate one partition per day, hour, month or year, respectively.",
|
|
342
|
+
|
|
179
343
|
default: "NONE",
|
|
180
|
-
input: select(
|
|
344
|
+
input: select({
|
|
345
|
+
hour: "HOUR",
|
|
346
|
+
day: "DAY",
|
|
347
|
+
month: "MONTH",
|
|
348
|
+
year: "YEAR",
|
|
349
|
+
none: "NONE",
|
|
350
|
+
}),
|
|
181
351
|
}),
|
|
182
352
|
timePartitioningField: defineString("TIME_PARTITIONING_FIELD", {
|
|
353
|
+
label: "BigQuery Time Partitioning column name",
|
|
354
|
+
description:
|
|
355
|
+
"BigQuery table column/schema field name for TimePartitioning. You can choose schema available as `timestamp` OR a new custom defined column that will be assigned to the selected Firestore Document field below. Defaults to pseudo column _PARTITIONTIME if unspecified. Cannot be changed if Table is already partitioned.",
|
|
356
|
+
|
|
183
357
|
default: "",
|
|
184
358
|
}),
|
|
185
359
|
timePartitioningFieldType: defineString("TIME_PARTITIONING_FIELD_TYPE", {
|
|
360
|
+
label: "BigQuery SQL Time Partitioning table schema field(column) type",
|
|
361
|
+
description:
|
|
362
|
+
"Parameter for BigQuery SQL schema field type for the selected Time Partitioning Firestore Document field option. Cannot be changed if Table is already partitioned.",
|
|
363
|
+
|
|
186
364
|
default: "omit",
|
|
187
365
|
input: select([...TIME_PARTITIONING_FIELD_TYPE_OPTIONS]),
|
|
188
366
|
}),
|
|
189
367
|
timePartitioningFirestoreField: defineString(
|
|
190
368
|
"TIME_PARTITIONING_FIRESTORE_FIELD",
|
|
191
|
-
{
|
|
369
|
+
{
|
|
370
|
+
label:
|
|
371
|
+
"Firestore Document field name for BigQuery SQL Time Partitioning field option",
|
|
372
|
+
description:
|
|
373
|
+
"This parameter will allow you to partition the BigQuery table created by the extension based on the selected Firestore Document field. The Firestore Document field value must be a top-level TIMESTAMP, DATETIME, DATE field BigQuery string format or Firestore timestamp(will be converted to BigQuery TIMESTAMP). Cannot be changed if Table is already partitioned.\n example: `postDate`(Ensure that the Firestore-BigQuery export extension\ncreates the dataset and table before initiating any backfill scripts.\n This step is crucial for the partitioning to function correctly. It is\nessential for the script to insert data into an already partitioned table.)",
|
|
374
|
+
default: "",
|
|
375
|
+
}
|
|
192
376
|
),
|
|
193
|
-
clustering: defineString("CLUSTERING", {
|
|
377
|
+
clustering: defineString("CLUSTERING", {
|
|
378
|
+
label: "BigQuery SQL table clustering",
|
|
379
|
+
description:
|
|
380
|
+
"This parameter allows you to set up clustering for the BigQuery table created by the extension. Specify up to 4 comma-separated fields (for example: `data,document_id,timestamp` - no whitespaces). The order of the specified columns determines the sort order of the data. \nNote: Cluster columns must be top-level, non-repeated columns of one of the following types: BIGNUMERIC, BOOL, DATE, DATETIME, GEOGRAPHY, INT64, NUMERIC, RANGE, STRING, TIMESTAMP. Clustering will not be added if a field with an invalid type is present in this parameter.\nAvailable schema extensions table fields for clustering include: `document_id, document_name, timestamp, event_id, operation, data`.",
|
|
381
|
+
|
|
382
|
+
default: "",
|
|
383
|
+
input: {
|
|
384
|
+
text: {
|
|
385
|
+
example: "data,document_id,timestamp",
|
|
386
|
+
|
|
387
|
+
// Extension regex, with an empty branch added: the param is optional.
|
|
388
|
+
validationRegex: /^(?:[^,\s]+(?:,[^,\s]+){0,3}|)$/,
|
|
389
|
+
validationErrorMessage:
|
|
390
|
+
"No whitespaces. Max 4 fields. e.g. `data,timestamp,event_id,operation`",
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
}),
|
|
194
394
|
wildcardIds: defineBoolean("WILDCARD_IDS", {
|
|
395
|
+
label: "Enable Wildcard Column field with Parent Firestore Document IDs",
|
|
396
|
+
description:
|
|
397
|
+
"If enabled, creates a column containing a JSON object of all wildcard ids from a documents path.",
|
|
398
|
+
|
|
195
399
|
default: false,
|
|
196
400
|
}),
|
|
197
|
-
useNewSnapshotQuerySyntax:
|
|
198
|
-
|
|
401
|
+
useNewSnapshotQuerySyntax: defineString("USE_NEW_SNAPSHOT_QUERY_SYNTAX", {
|
|
402
|
+
label: "Use new query syntax for snapshots",
|
|
403
|
+
description:
|
|
404
|
+
"If enabled, snapshots will be generated with the new query syntax, which should be more performant, and avoid potential resource limitations.",
|
|
405
|
+
|
|
406
|
+
default: "no",
|
|
407
|
+
input: select({ Yes: "yes", No: "no" }),
|
|
199
408
|
}),
|
|
200
|
-
excludeOldData:
|
|
201
|
-
|
|
409
|
+
excludeOldData: defineString("EXCLUDE_OLD_DATA", {
|
|
410
|
+
label: "Exclude old data payloads",
|
|
411
|
+
description:
|
|
412
|
+
"If enabled, table rows will never contain old data (document snapshot before the Firestore onDocumentUpdate event: `change.before.data()`). The reduction in data should be more performant, and avoid potential resource limitations.",
|
|
413
|
+
|
|
414
|
+
default: "no",
|
|
415
|
+
input: select({ Yes: "yes", No: "no" }),
|
|
202
416
|
}),
|
|
203
417
|
viewType: defineString("VIEW_TYPE", {
|
|
418
|
+
label: "View Type",
|
|
419
|
+
description:
|
|
420
|
+
"Select the type of view to create in BigQuery. A regular view is a virtual table defined by a SQL query. A materialized view persists the results of a query for faster access, with either incremental or non-incremental updates. Please note that materialized views in this extension come with several important caveats and limitations - carefully review the pre-install documentation before selecting these options to ensure they are appropriate for your use case.",
|
|
421
|
+
|
|
204
422
|
default: "view",
|
|
205
|
-
input: select(
|
|
423
|
+
input: select({
|
|
424
|
+
View: "view",
|
|
425
|
+
"Materialized View (Incremental)": "materialized_incremental",
|
|
426
|
+
"Materialized View (Non-incremental)": "materialized_non_incremental",
|
|
427
|
+
}),
|
|
428
|
+
}),
|
|
429
|
+
maxStaleness: defineString("MAX_STALENESS", {
|
|
430
|
+
label: "Maximum Staleness Duration",
|
|
431
|
+
description:
|
|
432
|
+
"For materialized views only: Specifies the maximum staleness acceptable for the materialized view. Should be specified as an INTERVAL value following BigQuery SQL syntax. This parameter will only take effect if View Type is set to a materialized view option.",
|
|
433
|
+
default: "",
|
|
434
|
+
input: { text: { example: 'INTERVAL "8:0:0" HOUR TO SECOND' } },
|
|
206
435
|
}),
|
|
207
|
-
maxStaleness: defineString("MAX_STALENESS", { default: "" }),
|
|
208
436
|
refreshIntervalMinutes: defineString("REFRESH_INTERVAL_MINUTES", {
|
|
437
|
+
label: "Refresh Interval (Minutes)",
|
|
438
|
+
description:
|
|
439
|
+
"For materialized views only: Specifies how often the materialized view should be refreshed, in minutes. This parameter will only take effect if View Type is set to a materialized view option.",
|
|
440
|
+
|
|
209
441
|
default: "",
|
|
442
|
+
input: {
|
|
443
|
+
text: {
|
|
444
|
+
example: "60",
|
|
445
|
+
|
|
446
|
+
// Extension regex, with an empty branch added: the param is optional.
|
|
447
|
+
validationRegex: /^(?:[1-9][0-9]*|)$/,
|
|
448
|
+
validationErrorMessage: "Must be a positive integer",
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
}),
|
|
452
|
+
kmsKeyName: defineString("KMS_KEY_NAME", {
|
|
453
|
+
label: "Cloud KMS key name",
|
|
454
|
+
description:
|
|
455
|
+
"Instead of Google managing the key encryption keys that protect your data, you control and manage key encryption keys in Cloud KMS. If this parameter is set, the extension will specify the KMS key name when creating the BQ table. See the PREINSTALL.md for more details.",
|
|
456
|
+
|
|
457
|
+
default: "",
|
|
458
|
+
input: {
|
|
459
|
+
text: {
|
|
460
|
+
// Extension regex (unanchored, as upstream), with an empty branch
|
|
461
|
+
// added: the param is optional.
|
|
462
|
+
validationRegex:
|
|
463
|
+
/projects\/([^\/]+)\/locations\/([^\/]+)\/keyRings\/([^\/]+)\/cryptoKeys\/([^\/]+)|^$/,
|
|
464
|
+
validationErrorMessage:
|
|
465
|
+
"The key name must be of the format 'projects/PROJECT_NAME/locations/KEY_RING_LOCATION/keyRings/KEY_RING_ID/cryptoKeys/KEY_ID'.",
|
|
466
|
+
},
|
|
467
|
+
},
|
|
210
468
|
}),
|
|
211
|
-
kmsKeyName: defineString("KMS_KEY_NAME", { default: "" }),
|
|
212
469
|
logLevel: defineString("LOG_LEVEL", {
|
|
470
|
+
label: "Log level",
|
|
471
|
+
description:
|
|
472
|
+
"The log level for the extension. The log level controls the verbosity of the extension's logs. The available log levels are: debug, info, warn, and error. To reduce the volume of logs, use a log level of warn or error.",
|
|
473
|
+
|
|
213
474
|
default: "info",
|
|
214
|
-
input: select(
|
|
475
|
+
input: select({
|
|
476
|
+
Debug: "debug",
|
|
477
|
+
Info: "info",
|
|
478
|
+
Warn: "warn",
|
|
479
|
+
Error: "error",
|
|
480
|
+
Silent: "silent",
|
|
481
|
+
}),
|
|
215
482
|
}),
|
|
216
483
|
};
|
|
217
484
|
|
|
@@ -219,8 +486,8 @@ export const CONFIG_EXPRESSIONS: ConfigExpressions = {
|
|
|
219
486
|
collectionPath: params.collectionPath,
|
|
220
487
|
datasetId: params.datasetId,
|
|
221
488
|
tableId: params.tableId,
|
|
222
|
-
location: params.databaseRegion,
|
|
223
489
|
database: params.database,
|
|
490
|
+
maxDispatchesPerSecond: params.maxDispatchesPerSecond,
|
|
224
491
|
};
|
|
225
492
|
|
|
226
493
|
function timePartitioning(
|
|
@@ -368,11 +635,30 @@ function normalizePositiveInt(value: string): number | undefined {
|
|
|
368
635
|
return normalized > 0 ? normalized : undefined;
|
|
369
636
|
}
|
|
370
637
|
|
|
638
|
+
// The extension's select emits `yes` / `no`; its label is `Yes`, and the CLI
|
|
639
|
+
// copies .env values verbatim, so case and whitespace are forgiven.
|
|
640
|
+
function yesNo(value: string): boolean {
|
|
641
|
+
return value.trim().toLowerCase() === "yes";
|
|
642
|
+
}
|
|
643
|
+
|
|
371
644
|
/** Coerce an empty-string param value to `undefined`. */
|
|
372
645
|
function optional(value: string): string | undefined {
|
|
373
646
|
return value.length > 0 ? value : undefined;
|
|
374
647
|
}
|
|
375
648
|
|
|
649
|
+
/**
|
|
650
|
+
* Reads an int param, reporting a missing or blank env var as `undefined`.
|
|
651
|
+
*
|
|
652
|
+
* `IntParam.value()` is `parseInt(env || "0", 10) || 0` and never consults the
|
|
653
|
+
* declared default, so an unset param has to reach `resolveExportConfig` as
|
|
654
|
+
* `undefined` for the documented default to apply. An explicit `0` is a real
|
|
655
|
+
* setting and is preserved.
|
|
656
|
+
*/
|
|
657
|
+
function optionalInt(param: IntParam): number | undefined {
|
|
658
|
+
const raw = process.env[param.name]?.trim();
|
|
659
|
+
return raw === undefined || raw === "" ? undefined : param.value();
|
|
660
|
+
}
|
|
661
|
+
|
|
376
662
|
/**
|
|
377
663
|
* Resolves all deploy-time params into an {@link ExportConfig}.
|
|
378
664
|
*
|
|
@@ -391,14 +677,13 @@ export function configFromEnv(): ExportConfig {
|
|
|
391
677
|
collectionPath: params.collectionPath.value(),
|
|
392
678
|
datasetId: params.datasetId.value(),
|
|
393
679
|
tableId: params.tableId.value(),
|
|
394
|
-
location: params.databaseRegion.value(),
|
|
395
680
|
datasetLocation: optional(params.datasetLocation.value()),
|
|
396
681
|
bqProjectId: optional(params.bigqueryProjectId.value()),
|
|
397
682
|
projectId: projectID.value(),
|
|
398
683
|
databaseId: optional(params.database.value()) || "(default)",
|
|
399
684
|
wildcardIds: params.wildcardIds.value(),
|
|
400
|
-
excludeOldData: params.excludeOldData.value(),
|
|
401
|
-
useNewSnapshotQuerySyntax: params.useNewSnapshotQuerySyntax.value(),
|
|
685
|
+
excludeOldData: yesNo(params.excludeOldData.value()),
|
|
686
|
+
useNewSnapshotQuerySyntax: yesNo(params.useNewSnapshotQuerySyntax.value()),
|
|
402
687
|
viewType: (optional(params.viewType.value()) || "view") as ViewType,
|
|
403
688
|
partitioning: buildPartitioningConfig({
|
|
404
689
|
timePartitioning: timePartitioning(tablePartitioning),
|
|
@@ -416,5 +701,7 @@ export function configFromEnv(): ExportConfig {
|
|
|
416
701
|
transformFunction: optional(params.transformFunction.value()),
|
|
417
702
|
kmsKeyName: optional(params.kmsKeyName.value()),
|
|
418
703
|
logLevel: normalizeLogLevel(params.logLevel.value()),
|
|
704
|
+
maxDispatchesPerSecond: optionalInt(params.maxDispatchesPerSecond),
|
|
705
|
+
maxEnqueueAttempts: optionalInt(params.maxEnqueueAttempts),
|
|
419
706
|
};
|
|
420
707
|
}
|
package/src/export-config.ts
CHANGED
|
@@ -19,6 +19,9 @@ import type {
|
|
|
19
19
|
} from "@firebaseextensions/firestore-bigquery-change-tracker";
|
|
20
20
|
import type { Expression } from "firebase-functions/params";
|
|
21
21
|
|
|
22
|
+
/** Dispatch rate of the `syncBigQuery` queue when `MAX_DISPATCHES_PER_SECOND` is unset. */
|
|
23
|
+
export const DEFAULT_MAX_DISPATCHES_PER_SECOND = 100;
|
|
24
|
+
|
|
22
25
|
type TrackerLogLevel = "debug" | "info" | "warn" | "error" | "silent";
|
|
23
26
|
type ConfigValue<T extends string | number | boolean | string[]> =
|
|
24
27
|
| T
|
|
@@ -34,7 +37,7 @@ export type ViewType =
|
|
|
34
37
|
* The export configuration. The main entry point builds it from deploy-time
|
|
35
38
|
* params; handler consumers can construct it directly.
|
|
36
39
|
*
|
|
37
|
-
* `collectionPath`, `datasetId`, `tableId`,
|
|
40
|
+
* `collectionPath`, `datasetId`, `tableId`, and `projectId` are
|
|
38
41
|
* required; everything else has a sensible default.
|
|
39
42
|
*/
|
|
40
43
|
export interface ExportConfig {
|
|
@@ -46,8 +49,6 @@ export interface ExportConfig {
|
|
|
46
49
|
/** BigQuery changelog table id. */
|
|
47
50
|
tableId: ConfigValue<string>;
|
|
48
51
|
|
|
49
|
-
/** Region for the trigger and task queue. */
|
|
50
|
-
location: ConfigValue<string>;
|
|
51
52
|
/** BigQuery dataset location, e.g. `us`, `eu`. Defaults to `us`. */
|
|
52
53
|
datasetLocation?: ConfigValue<string>;
|
|
53
54
|
/** Project that owns the BigQuery dataset, if different from the function's
|
|
@@ -71,7 +72,10 @@ export interface ExportConfig {
|
|
|
71
72
|
partitioning?: ChangeTrackerConfig["partitioning"];
|
|
72
73
|
/** Clustering columns (max 4). */
|
|
73
74
|
clustering?: string[] | null;
|
|
74
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* Materialized-view max staleness interval, e.g.
|
|
77
|
+
* `INTERVAL "8:0:0" HOUR TO SECOND`.
|
|
78
|
+
*/
|
|
75
79
|
maxStaleness?: ConfigValue<string>;
|
|
76
80
|
/** Incremental materialized-view refresh interval in minutes. */
|
|
77
81
|
refreshIntervalMinutes?: ConfigValue<number>;
|
|
@@ -85,6 +89,17 @@ export interface ExportConfig {
|
|
|
85
89
|
|
|
86
90
|
/** Log verbosity. Defaults to `info`. */
|
|
87
91
|
logLevel?: ConfigValue<TrackerLogLevel | LogLevel>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Cloud Tasks dispatch rate for the `syncBigQuery` queue, in tasks per
|
|
95
|
+
* second. Defaults to `100`.
|
|
96
|
+
*/
|
|
97
|
+
maxDispatchesPerSecond?: ConfigValue<number>;
|
|
98
|
+
/**
|
|
99
|
+
* How many times the trigger tries to enqueue a failed write onto the
|
|
100
|
+
* `syncBigQuery` queue before giving up. Defaults to `3`.
|
|
101
|
+
*/
|
|
102
|
+
maxEnqueueAttempts?: ConfigValue<number>;
|
|
88
103
|
}
|
|
89
104
|
|
|
90
105
|
/** {@link ExportConfig} with all defaults applied. */
|
|
@@ -92,7 +107,6 @@ export interface ResolvedExportConfig {
|
|
|
92
107
|
collectionPath: string;
|
|
93
108
|
datasetId: string;
|
|
94
109
|
tableId: string;
|
|
95
|
-
location: string;
|
|
96
110
|
datasetLocation: string;
|
|
97
111
|
bqProjectId?: string;
|
|
98
112
|
projectId: string;
|
|
@@ -109,6 +123,8 @@ export interface ResolvedExportConfig {
|
|
|
109
123
|
transformFunction?: string;
|
|
110
124
|
kmsKeyName?: string;
|
|
111
125
|
logLevel: TrackerLogLevel;
|
|
126
|
+
maxDispatchesPerSecond: number;
|
|
127
|
+
maxEnqueueAttempts: number;
|
|
112
128
|
}
|
|
113
129
|
|
|
114
130
|
function isExpression<T extends string | number | boolean | string[]>(
|
|
@@ -146,7 +162,6 @@ export function resolveExportConfig(
|
|
|
146
162
|
collectionPath: resolveConfigValue(config.collectionPath),
|
|
147
163
|
datasetId: resolveConfigValue(config.datasetId),
|
|
148
164
|
tableId: resolveConfigValue(config.tableId),
|
|
149
|
-
location: resolveConfigValue(config.location),
|
|
150
165
|
datasetLocation: resolveOptionalConfigValue(config.datasetLocation) ?? "us",
|
|
151
166
|
bqProjectId: resolveOptionalConfigValue(config.bqProjectId),
|
|
152
167
|
projectId,
|
|
@@ -166,6 +181,11 @@ export function resolveExportConfig(
|
|
|
166
181
|
transformFunction: resolveOptionalConfigValue(config.transformFunction),
|
|
167
182
|
kmsKeyName: resolveOptionalConfigValue(config.kmsKeyName),
|
|
168
183
|
logLevel: (logLevel as TrackerLogLevel) ?? "info",
|
|
184
|
+
maxDispatchesPerSecond:
|
|
185
|
+
resolveOptionalConfigValue(config.maxDispatchesPerSecond) ??
|
|
186
|
+
DEFAULT_MAX_DISPATCHES_PER_SECOND,
|
|
187
|
+
maxEnqueueAttempts:
|
|
188
|
+
resolveOptionalConfigValue(config.maxEnqueueAttempts) ?? 3,
|
|
169
189
|
};
|
|
170
190
|
}
|
|
171
191
|
|