@firebaseextensions/firestore-bigquery-change-tracker 1.1.30 → 1.1.32
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.
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const firebase = require("firebase-admin");
|
|
4
|
+
const firestore_1 = require("firebase-admin/firestore");
|
|
4
5
|
if (!firebase.apps.length) {
|
|
5
6
|
firebase.initializeApp();
|
|
6
7
|
firebase.firestore().settings({ ignoreUndefinedProperties: true });
|
|
7
8
|
}
|
|
8
9
|
exports.default = async (rows, config, e) => {
|
|
9
|
-
const db =
|
|
10
|
+
const db = (0, firestore_1.getFirestore)();
|
|
10
11
|
const batchArray = [db.batch()];
|
|
11
12
|
let operationCounter = 0;
|
|
12
13
|
let batchIndex = 0;
|
|
@@ -63,10 +63,14 @@ class Partitioning {
|
|
|
63
63
|
/* No custom config has been set, use partition value option only */
|
|
64
64
|
if (hasNoCustomOptions)
|
|
65
65
|
return true;
|
|
66
|
-
/* check if all
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
/* check if all valid combinations have been provided*/
|
|
67
|
+
const hasOnlyTimestamp = timePartitioningField === "timestamp" &&
|
|
68
|
+
!timePartitioningFieldType &&
|
|
69
|
+
!timePartitioningFirestoreField;
|
|
70
|
+
return (hasOnlyTimestamp ||
|
|
71
|
+
(!!timePartitioningField &&
|
|
72
|
+
!!timePartitioningFieldType &&
|
|
73
|
+
!!timePartitioningFirestoreField));
|
|
70
74
|
}
|
|
71
75
|
hasValidTimePartitionOption() {
|
|
72
76
|
const { timePartitioning } = this.config;
|
|
@@ -83,44 +87,36 @@ class Partitioning {
|
|
|
83
87
|
return !!metadata.schema;
|
|
84
88
|
}
|
|
85
89
|
hasValidTableReference() {
|
|
86
|
-
|
|
90
|
+
if (!this.table) {
|
|
91
|
+
logs.invalidTableReference();
|
|
92
|
+
}
|
|
87
93
|
return !!this.table;
|
|
88
94
|
}
|
|
89
95
|
async isTablePartitioned() {
|
|
90
|
-
if
|
|
91
|
-
return Promise.resolve(false);
|
|
92
|
-
// No table provided, cannot evaluate
|
|
93
|
-
if (this.table.exists()) {
|
|
94
|
-
logs.cannotPartitionExistingTable(this.table);
|
|
95
|
-
return Promise.resolve(false);
|
|
96
|
-
}
|
|
97
|
-
/*** No table exists, return */
|
|
98
|
-
const [tableExists] = await this.table.exists();
|
|
99
|
-
if (!tableExists)
|
|
100
|
-
return Promise.resolve(false);
|
|
101
|
-
/* Check if partition metadata already exists */
|
|
96
|
+
/* Return true if partition metadata already exists */
|
|
102
97
|
const [metadata] = await this.table.getMetadata();
|
|
103
|
-
if (!!metadata.timePartitioning)
|
|
98
|
+
if (!!metadata.timePartitioning) {
|
|
99
|
+
logs.cannotPartitionExistingTable(this.table);
|
|
104
100
|
return Promise.resolve(true);
|
|
101
|
+
}
|
|
105
102
|
/** Find schema fields **/
|
|
106
103
|
const schemaFields = await this.metaDataSchemaFields();
|
|
107
|
-
/**
|
|
104
|
+
/** Return false if no schema exists */
|
|
108
105
|
if (!schemaFields)
|
|
109
106
|
return Promise.resolve(false);
|
|
110
107
|
/* Return false if time partition field not found */
|
|
111
108
|
return schemaFields.some((column) => column.name === this.config.timePartitioningField);
|
|
112
109
|
}
|
|
113
110
|
async isValidPartitionForExistingTable() {
|
|
111
|
+
/** Return false if partition type option has not been set */
|
|
112
|
+
if (!this.isPartitioningEnabled())
|
|
113
|
+
return Promise.resolve(false);
|
|
114
|
+
/* Return false if table is already partitioned */
|
|
114
115
|
const isPartitioned = await this.isTablePartitioned();
|
|
115
116
|
if (isPartitioned)
|
|
116
117
|
return Promise.resolve(false);
|
|
117
118
|
return this.hasValidCustomPartitionConfig();
|
|
118
119
|
}
|
|
119
|
-
isValidPartitionForNewTable() {
|
|
120
|
-
if (!this.isPartitioningEnabled())
|
|
121
|
-
return false;
|
|
122
|
-
return this.hasValidCustomPartitionConfig();
|
|
123
|
-
}
|
|
124
120
|
convertDateValue(fieldValue) {
|
|
125
121
|
const { timePartitioningFieldType } = this.config;
|
|
126
122
|
/* Return as Datetime value */
|
|
@@ -178,56 +174,61 @@ class Partitioning {
|
|
|
178
174
|
return fields.map(($) => $.name).includes(timePartitioningField);
|
|
179
175
|
}
|
|
180
176
|
async addPartitioningToSchema(fields = []) {
|
|
181
|
-
/**
|
|
177
|
+
/** Return if partition type option has not been set */
|
|
178
|
+
if (!this.isPartitioningEnabled())
|
|
179
|
+
return;
|
|
180
|
+
/** Return if class has invalid table reference */
|
|
182
181
|
if (!this.hasValidTableReference())
|
|
183
|
-
return
|
|
184
|
-
/**
|
|
182
|
+
return;
|
|
183
|
+
/** Return if table is already partitioned **/
|
|
185
184
|
if (await this.isTablePartitioned())
|
|
186
|
-
return
|
|
187
|
-
/**
|
|
185
|
+
return;
|
|
186
|
+
/** Return if partition config is invalid */
|
|
187
|
+
if (!this.hasValidCustomPartitionConfig())
|
|
188
|
+
return;
|
|
189
|
+
/** Return if an invalid partition type has been requested */
|
|
188
190
|
if (!this.hasValidTimePartitionType())
|
|
189
|
-
return
|
|
191
|
+
return;
|
|
192
|
+
/** Return if an invalid partition option has been requested */
|
|
193
|
+
if (!this.hasValidTimePartitionOption())
|
|
194
|
+
return;
|
|
190
195
|
/** Return if invalid partitioning and field type combination */
|
|
191
196
|
if (this.hasHourAndDatePartitionConfig())
|
|
192
|
-
return
|
|
193
|
-
/**
|
|
194
|
-
if (!this.hasValidCustomPartitionConfig())
|
|
195
|
-
return Promise.resolve();
|
|
196
|
-
/** return if an invalid partition type has been requested**/
|
|
197
|
-
if (!this.hasValidCustomPartitionConfig())
|
|
198
|
-
return Promise.resolve();
|
|
199
|
-
/** update fields with new schema option ** */
|
|
200
|
-
if (!this.hasValidTimePartitionOption())
|
|
201
|
-
return Promise.resolve();
|
|
202
|
-
/* Check if partition field has been provided */
|
|
197
|
+
return;
|
|
198
|
+
/** Return if partition field has not been provided */
|
|
203
199
|
if (!this.config.timePartitioningField)
|
|
204
|
-
return
|
|
205
|
-
|
|
206
|
-
// Field already exists on schema, skip
|
|
200
|
+
return;
|
|
201
|
+
/** Return if field already exists on schema */
|
|
207
202
|
if (this.customFieldExists(fields))
|
|
208
|
-
return
|
|
203
|
+
return;
|
|
204
|
+
/** Add new partitioning field **/
|
|
209
205
|
fields.push((0, schema_1.getNewPartitionField)(this.config));
|
|
210
|
-
/**
|
|
206
|
+
/** Log successful addition of partition column */
|
|
211
207
|
logs.addPartitionFieldColumn(this.table.id, this.config.timePartitioningField);
|
|
212
|
-
return
|
|
208
|
+
return;
|
|
213
209
|
}
|
|
214
210
|
async updateTableMetadata(options) {
|
|
215
|
-
/**
|
|
211
|
+
/** Return if partition type option has not been set */
|
|
212
|
+
if (!this.isPartitioningEnabled())
|
|
213
|
+
return;
|
|
214
|
+
/** Return if class has invalid table reference */
|
|
215
|
+
if (!this.hasValidTableReference())
|
|
216
|
+
return;
|
|
217
|
+
/** Return if table is already partitioned **/
|
|
216
218
|
if (await this.isTablePartitioned())
|
|
217
|
-
return
|
|
218
|
-
/**
|
|
219
|
+
return;
|
|
220
|
+
/** Return if an invalid partition type has been requested**/
|
|
221
|
+
if (!this.hasValidCustomPartitionConfig())
|
|
222
|
+
return;
|
|
223
|
+
/** Return if an invalid partition type has been requested**/
|
|
219
224
|
if (!this.hasValidTimePartitionType())
|
|
220
|
-
return
|
|
221
|
-
/**
|
|
225
|
+
return;
|
|
226
|
+
/** Update fields with new schema option ** */
|
|
222
227
|
if (!this.hasValidTimePartitionOption())
|
|
223
|
-
return
|
|
228
|
+
return;
|
|
224
229
|
/** Return if invalid partitioning and field type combination */
|
|
225
230
|
if (this.hasHourAndDatePartitionConfig())
|
|
226
|
-
return
|
|
227
|
-
/** return if an invalid partition type has been requested**/
|
|
228
|
-
if (!this.hasValidCustomPartitionConfig())
|
|
229
|
-
return Promise.resolve();
|
|
230
|
-
// if (await !this.hasExistingSchema) return Promise.resolve();
|
|
231
|
+
return;
|
|
231
232
|
if (this.config.timePartitioning) {
|
|
232
233
|
options.timePartitioning = { type: this.config.timePartitioning };
|
|
233
234
|
}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "github.com/firebase/extensions.git",
|
|
6
6
|
"directory": "firestore-bigquery-export/firestore-bigquery-change-tracker"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.1.
|
|
8
|
+
"version": "1.1.32",
|
|
9
9
|
"description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
|
|
10
10
|
"main": "./lib/index.js",
|
|
11
11
|
"scripts": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@google-cloud/bigquery": "^4.7.0",
|
|
27
27
|
"@google-cloud/resource-manager": "^3.0.0",
|
|
28
|
-
"firebase-admin": "^11.
|
|
29
|
-
"firebase-functions": "^
|
|
28
|
+
"firebase-admin": "^11.11.1",
|
|
29
|
+
"firebase-functions": "^4.6.0",
|
|
30
30
|
"generate-schema": "^2.6.0",
|
|
31
31
|
"inquirer": "^6.4.0",
|
|
32
32
|
"lodash": "^4.17.14",
|