@firebaseextensions/firestore-bigquery-change-tracker 1.1.31 → 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 = firebase.firestore();
10
+ const db = (0, firestore_1.getFirestore)();
10
11
  const batchArray = [db.batch()];
11
12
  let operationCounter = 0;
12
13
  let batchIndex = 0;
@@ -87,44 +87,36 @@ class Partitioning {
87
87
  return !!metadata.schema;
88
88
  }
89
89
  hasValidTableReference() {
90
- logs.invalidTableReference();
90
+ if (!this.table) {
91
+ logs.invalidTableReference();
92
+ }
91
93
  return !!this.table;
92
94
  }
93
95
  async isTablePartitioned() {
94
- if (!this.table)
95
- return Promise.resolve(false);
96
- // No table provided, cannot evaluate
97
- if (this.table.exists()) {
98
- logs.cannotPartitionExistingTable(this.table);
99
- return Promise.resolve(false);
100
- }
101
- /*** No table exists, return */
102
- const [tableExists] = await this.table.exists();
103
- if (!tableExists)
104
- return Promise.resolve(false);
105
- /* Check if partition metadata already exists */
96
+ /* Return true if partition metadata already exists */
106
97
  const [metadata] = await this.table.getMetadata();
107
- if (!!metadata.timePartitioning)
98
+ if (!!metadata.timePartitioning) {
99
+ logs.cannotPartitionExistingTable(this.table);
108
100
  return Promise.resolve(true);
101
+ }
109
102
  /** Find schema fields **/
110
103
  const schemaFields = await this.metaDataSchemaFields();
111
- /** No Schema exists, return */
104
+ /** Return false if no schema exists */
112
105
  if (!schemaFields)
113
106
  return Promise.resolve(false);
114
107
  /* Return false if time partition field not found */
115
108
  return schemaFields.some((column) => column.name === this.config.timePartitioningField);
116
109
  }
117
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 */
118
115
  const isPartitioned = await this.isTablePartitioned();
119
116
  if (isPartitioned)
120
117
  return Promise.resolve(false);
121
118
  return this.hasValidCustomPartitionConfig();
122
119
  }
123
- isValidPartitionForNewTable() {
124
- if (!this.isPartitioningEnabled())
125
- return false;
126
- return this.hasValidCustomPartitionConfig();
127
- }
128
120
  convertDateValue(fieldValue) {
129
121
  const { timePartitioningFieldType } = this.config;
130
122
  /* Return as Datetime value */
@@ -182,56 +174,61 @@ class Partitioning {
182
174
  return fields.map(($) => $.name).includes(timePartitioningField);
183
175
  }
184
176
  async addPartitioningToSchema(fields = []) {
185
- /** check if class has valid table reference */
177
+ /** Return if partition type option has not been set */
178
+ if (!this.isPartitioningEnabled())
179
+ return;
180
+ /** Return if class has invalid table reference */
186
181
  if (!this.hasValidTableReference())
187
182
  return;
188
- /** return if table is already partitioned **/
183
+ /** Return if table is already partitioned **/
189
184
  if (await this.isTablePartitioned())
190
185
  return;
191
- /** return if an invalid partition type has been requested**/
192
- if (!this.hasValidTimePartitionType())
193
- return;
194
- /** Return if invalid partitioning and field type combination */
195
- if (this.hasHourAndDatePartitionConfig())
196
- return;
197
- /** return if an invalid partition type has been requested**/
186
+ /** Return if partition config is invalid */
198
187
  if (!this.hasValidCustomPartitionConfig())
199
188
  return;
200
- /** return if an invalid partition type has been requested**/
201
- if (!this.hasValidCustomPartitionConfig())
189
+ /** Return if an invalid partition type has been requested */
190
+ if (!this.hasValidTimePartitionType())
202
191
  return;
203
- /** update fields with new schema option ** */
192
+ /** Return if an invalid partition option has been requested */
204
193
  if (!this.hasValidTimePartitionOption())
205
194
  return;
206
- /* Check if partition field has been provided */
195
+ /** Return if invalid partitioning and field type combination */
196
+ if (this.hasHourAndDatePartitionConfig())
197
+ return;
198
+ /** Return if partition field has not been provided */
207
199
  if (!this.config.timePartitioningField)
208
200
  return;
209
- // if (await !this.hasExistingSchema) return Promise.resolve();
210
- // Field already exists on schema, skip
201
+ /** Return if field already exists on schema */
211
202
  if (this.customFieldExists(fields))
212
203
  return;
204
+ /** Add new partitioning field **/
213
205
  fields.push((0, schema_1.getNewPartitionField)(this.config));
214
- /** log successful addition of partition column */
206
+ /** Log successful addition of partition column */
215
207
  logs.addPartitionFieldColumn(this.table.id, this.config.timePartitioningField);
216
208
  return;
217
209
  }
218
210
  async updateTableMetadata(options) {
219
- /** return if table is already partitioned **/
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 **/
220
218
  if (await this.isTablePartitioned())
221
219
  return;
222
- /** return if an invalid partition type has been requested**/
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**/
223
224
  if (!this.hasValidTimePartitionType())
224
225
  return;
225
- /** update fields with new schema option ** */
226
+ /** Update fields with new schema option ** */
226
227
  if (!this.hasValidTimePartitionOption())
227
228
  return;
228
229
  /** Return if invalid partitioning and field type combination */
229
230
  if (this.hasHourAndDatePartitionConfig())
230
231
  return;
231
- /** return if an invalid partition type has been requested**/
232
- if (!this.hasValidCustomPartitionConfig())
233
- return;
234
- // if (await !this.hasExistingSchema) return Promise.resolve();
235
232
  if (this.config.timePartitioning) {
236
233
  options.timePartitioning = { type: this.config.timePartitioning };
237
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.31",
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.4.1",
29
- "firebase-functions": "^3.13.2",
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",