@firebaseextensions/firestore-bigquery-change-tracker 1.1.28 → 1.1.30
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/bigquery/index.js +0 -19
- package/lib/bigquery/partitioning.js +24 -2
- package/package.json +9 -9
package/lib/bigquery/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FirestoreBigQueryEventHistoryTracker = exports.RawChangelogViewSchema = exports.RawChangelogSchema = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* Copyright 2019 Google LLC
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
const admin = require("firebase-admin");
|
|
20
4
|
const bigquery = require("@google-cloud/bigquery");
|
|
21
5
|
const firestore_1 = require("firebase-admin/firestore");
|
|
22
6
|
const traverse = require("traverse");
|
|
@@ -105,9 +89,6 @@ class FirestoreBigQueryEventHistoryTracker {
|
|
|
105
89
|
if (property.constructor.name === firestore_1.DocumentReference.name) {
|
|
106
90
|
this.update(property.path);
|
|
107
91
|
}
|
|
108
|
-
if (property instanceof admin.firestore.Timestamp) {
|
|
109
|
-
this.update(property.toDate());
|
|
110
|
-
}
|
|
111
92
|
}
|
|
112
93
|
});
|
|
113
94
|
return data;
|
|
@@ -35,7 +35,8 @@ class Partitioning {
|
|
|
35
35
|
}
|
|
36
36
|
isValidPartitionTypeDate(value) {
|
|
37
37
|
/* Check if valid timestamp value from sdk */
|
|
38
|
-
if (value instanceof firebase.firestore.Timestamp)
|
|
38
|
+
// if (value instanceof firebase.firestore.Timestamp) return true;
|
|
39
|
+
if (isTimestampLike(value))
|
|
39
40
|
return true;
|
|
40
41
|
/* Check if valid date/timstemap, expedted result from production */
|
|
41
42
|
if (value && value.toDate && value.toDate())
|
|
@@ -137,7 +138,7 @@ class Partitioning {
|
|
|
137
138
|
Extracts a valid Partition field from the Document Change Event.
|
|
138
139
|
Matches result based on a pre-defined Firestore field matching the event data object.
|
|
139
140
|
Return an empty object if no field name or value provided.
|
|
140
|
-
Returns empty object if not a string or timestamp
|
|
141
|
+
Returns empty object if not a string or timestamp (or result of serializing a timestamp)
|
|
141
142
|
Logs warning if not a valid datatype
|
|
142
143
|
Delete changes events have no data, return early as cannot partition on empty data.
|
|
143
144
|
**/
|
|
@@ -155,6 +156,12 @@ class Partitioning {
|
|
|
155
156
|
}
|
|
156
157
|
if (this.isValidPartitionTypeDate(fieldValue)) {
|
|
157
158
|
/* Return converted console value */
|
|
159
|
+
if (isTimestampLike(fieldValue)) {
|
|
160
|
+
const convertedTimestampFieldValue = convertToTimestamp(fieldValue);
|
|
161
|
+
return {
|
|
162
|
+
[fieldName]: this.convertDateValue(convertedTimestampFieldValue.toDate()),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
158
165
|
if (fieldValue.toDate) {
|
|
159
166
|
return { [fieldName]: this.convertDateValue(fieldValue.toDate()) };
|
|
160
167
|
}
|
|
@@ -234,3 +241,18 @@ class Partitioning {
|
|
|
234
241
|
}
|
|
235
242
|
}
|
|
236
243
|
exports.Partitioning = Partitioning;
|
|
244
|
+
const isTimestampLike = (value) => {
|
|
245
|
+
if (value instanceof firebase.firestore.Timestamp)
|
|
246
|
+
return true;
|
|
247
|
+
return (typeof value === "object" &&
|
|
248
|
+
value !== null &&
|
|
249
|
+
"_seconds" in value &&
|
|
250
|
+
typeof value["_seconds"] === "number" &&
|
|
251
|
+
"_nanoseconds" in value &&
|
|
252
|
+
typeof value["_nanoseconds"] === "number");
|
|
253
|
+
};
|
|
254
|
+
const convertToTimestamp = (value) => {
|
|
255
|
+
if (value instanceof firebase.firestore.Timestamp)
|
|
256
|
+
return value;
|
|
257
|
+
return new firebase.firestore.Timestamp(value._seconds, value._nanoseconds);
|
|
258
|
+
};
|
package/package.json
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
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.30",
|
|
9
9
|
"description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
|
|
10
10
|
"main": "./lib/index.js",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "npm run clean && npm run compile",
|
|
13
13
|
"clean": "rimraf lib",
|
|
14
14
|
"compile": "tsc",
|
|
15
|
-
"test:local": "
|
|
15
|
+
"test:local": "jest",
|
|
16
16
|
"prepare": "npm run build",
|
|
17
17
|
"generate-stresstest-table": "bq query --project_id=extensions-testing --use_legacy_sql=false < ./src/__tests__/fixtures/sql/generateSnapshotStresstestTable.sql"
|
|
18
18
|
},
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
"traverse": "^0.6.6"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
+
"@types/chai": "^4.1.6",
|
|
39
|
+
"@types/jest": "^24.0.18",
|
|
38
40
|
"@types/node": "14.18.34",
|
|
39
41
|
"@types/traverse": "^0.6.32",
|
|
40
|
-
"typescript": "^4.9.4",
|
|
41
|
-
"rimraf": "^2.6.3",
|
|
42
|
-
"nyc": "^14.0.0",
|
|
43
|
-
"jest": "^24.9.0",
|
|
44
42
|
"chai": "^4.2.0",
|
|
45
|
-
"
|
|
43
|
+
"jest": "^24.9.0",
|
|
44
|
+
"nyc": "^14.0.0",
|
|
45
|
+
"rimraf": "^2.6.3",
|
|
46
46
|
"ts-jest": "^24.1.0",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"ts-node": "^7.0.1",
|
|
48
|
+
"typescript": "^4.9.4"
|
|
49
49
|
}
|
|
50
50
|
}
|