@firebaseextensions/firestore-bigquery-change-tracker 1.1.14 → 1.1.15

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.
@@ -4,6 +4,8 @@ exports.Partitioning = void 0;
4
4
  const firebase = require("firebase-admin");
5
5
  const logs = require("../logs");
6
6
  const schema_1 = require("./schema");
7
+ const bigquery_1 = require("@google-cloud/bigquery");
8
+ const types_1 = require("../types");
7
9
  class Partitioning {
8
10
  constructor(config, table, schema) {
9
11
  this.config = config;
@@ -32,7 +34,11 @@ class Partitioning {
32
34
  return metadata.schema.fields;
33
35
  }
34
36
  isValidPartitionTypeDate(value) {
35
- return value instanceof firebase.firestore.Timestamp;
37
+ /* Check if valid timestamp value from sdk */
38
+ if (value instanceof firebase.firestore.Timestamp)
39
+ return true;
40
+ /* Check if valid date/time value from console */
41
+ return Object.prototype.toString.call(value) === "[object Date]";
36
42
  }
37
43
  hasHourAndDatePartitionConfig() {
38
44
  if (this.config.timePartitioning === "HOUR" &&
@@ -110,6 +116,19 @@ class Partitioning {
110
116
  return false;
111
117
  return this.hasValidCustomPartitionConfig();
112
118
  }
119
+ convertDateValue(fieldValue) {
120
+ const { timePartitioningFieldType } = this.config;
121
+ /* Return as Datetime value */
122
+ if (timePartitioningFieldType === types_1.PartitionFieldType.DATETIME) {
123
+ return bigquery_1.BigQuery.datetime(fieldValue.toISOString()).value;
124
+ }
125
+ /* Return as Date value */
126
+ if (timePartitioningFieldType === types_1.PartitionFieldType.DATE) {
127
+ return bigquery_1.BigQuery.date(fieldValue.toISOString().substring(0, 10)).value;
128
+ }
129
+ /* Return as Timestamp */
130
+ return bigquery_1.BigQuery.timestamp(fieldValue).value;
131
+ }
113
132
  /*
114
133
  Extracts a valid Partition field from the Document Change Event.
115
134
  Matches result based on a pre-defined Firestore field matching the event data object.
@@ -130,8 +149,14 @@ class Partitioning {
130
149
  if (this.isValidPartitionTypeString(fieldValue)) {
131
150
  return { [fieldName]: fieldValue };
132
151
  }
133
- if (this.isValidPartitionTypeDate(fieldValue))
134
- return { [fieldName]: fieldValue.toDate() };
152
+ if (this.isValidPartitionTypeDate(fieldValue)) {
153
+ /* Return converted console value */
154
+ if (fieldValue.toDate) {
155
+ return { [fieldName]: this.convertDateValue(fieldValue.toDate()) };
156
+ }
157
+ /* Return standard date value */
158
+ return { [fieldName]: fieldValue };
159
+ }
135
160
  logs.firestoreTimePartitionFieldError(event.documentName, fieldName, firestoreFieldName, fieldValue);
136
161
  return {};
137
162
  }
package/lib/types.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PartitionFieldType = void 0;
4
+ var PartitionFieldType;
5
+ (function (PartitionFieldType) {
6
+ PartitionFieldType["DATE"] = "DATE";
7
+ PartitionFieldType["DATETIME"] = "DATETIME";
8
+ PartitionFieldType["TIMESTAMP"] = "TIMESTAMP";
9
+ })(PartitionFieldType = exports.PartitionFieldType || (exports.PartitionFieldType = {}));
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.14",
8
+ "version": "1.1.15",
9
9
  "description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
10
10
  "main": "./lib/index.js",
11
11
  "scripts": {