@firebaseextensions/firestore-bigquery-change-tracker 1.1.33 → 1.1.35
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.
|
@@ -172,12 +172,12 @@ class Partitioning {
|
|
|
172
172
|
return {};
|
|
173
173
|
}
|
|
174
174
|
customFieldExists(fields = []) {
|
|
175
|
-
|
|
176
|
-
return false;
|
|
175
|
+
/** Extract the time partioning field name */
|
|
177
176
|
const { timePartitioningField } = this.config;
|
|
177
|
+
/** Return based the field already exist */
|
|
178
178
|
return fields.map(($) => $.name).includes(timePartitioningField);
|
|
179
179
|
}
|
|
180
|
-
async shouldAddPartitioningToSchema() {
|
|
180
|
+
async shouldAddPartitioningToSchema(fields) {
|
|
181
181
|
if (!this.isPartitioningEnabled()) {
|
|
182
182
|
return { proceed: false, message: "Partitioning not enabled" };
|
|
183
183
|
}
|
|
@@ -199,7 +199,7 @@ class Partitioning {
|
|
|
199
199
|
message: "Invalid partitioning and field type combination",
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
|
-
if (this.customFieldExists()) {
|
|
202
|
+
if (this.customFieldExists(fields)) {
|
|
203
203
|
return { proceed: false, message: "Field already exists on schema" };
|
|
204
204
|
}
|
|
205
205
|
if (await this.isTablePartitioned()) {
|
|
@@ -211,7 +211,7 @@ class Partitioning {
|
|
|
211
211
|
return { proceed: true, message: "" };
|
|
212
212
|
}
|
|
213
213
|
async addPartitioningToSchema(fields = []) {
|
|
214
|
-
const { proceed, message } = await this.shouldAddPartitioningToSchema();
|
|
214
|
+
const { proceed, message } = await this.shouldAddPartitioningToSchema(fields);
|
|
215
215
|
if (!proceed) {
|
|
216
216
|
functions.logger.warn(`Did not add partitioning to schema: ${message}`);
|
|
217
217
|
return;
|
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.35",
|
|
9
9
|
"description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
|
|
10
10
|
"main": "./lib/index.js",
|
|
11
11
|
"scripts": {
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("./utils");
|
|
4
|
-
const logs = require("../logs");
|
|
5
|
-
jest.mock("@google-cloud/bigquery");
|
|
6
|
-
jest.mock("../../logs");
|
|
7
|
-
const dataset = {
|
|
8
|
-
exists: jest.fn(),
|
|
9
|
-
table: jest.fn(),
|
|
10
|
-
};
|
|
11
|
-
const table = {
|
|
12
|
-
exists: jest.fn(),
|
|
13
|
-
};
|
|
14
|
-
const changelogName = "testTable";
|
|
15
|
-
describe("waitForInitialization", () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
jest.clearAllMocks();
|
|
18
|
-
dataset.table.mockReturnValue(table);
|
|
19
|
-
});
|
|
20
|
-
test("should successfully find the dataset and table", async () => {
|
|
21
|
-
dataset.exists.mockResolvedValue([true]);
|
|
22
|
-
table.exists.mockResolvedValue([true]);
|
|
23
|
-
const result = await (0, utils_1.waitForInitialization)({
|
|
24
|
-
dataset: dataset,
|
|
25
|
-
changelogName,
|
|
26
|
-
});
|
|
27
|
-
expect(result).toBe(table);
|
|
28
|
-
expect(dataset.exists).toHaveBeenCalledTimes(1);
|
|
29
|
-
expect(table.exists).toHaveBeenCalledTimes(1);
|
|
30
|
-
});
|
|
31
|
-
test("should fail after max attempts if table does not exist", async () => {
|
|
32
|
-
dataset.exists.mockResolvedValue([true]);
|
|
33
|
-
table.exists.mockResolvedValue([false]);
|
|
34
|
-
await expect((0, utils_1.waitForInitialization)({ dataset: dataset, changelogName }, 3)).rejects.toThrow("Initialization timed out. Dataset or table could not be verified to exist after multiple attempts.");
|
|
35
|
-
expect(dataset.exists).toHaveBeenCalledTimes(3);
|
|
36
|
-
expect(table.exists).toHaveBeenCalledTimes(3);
|
|
37
|
-
});
|
|
38
|
-
test("should handle and throw an error if dataset.exists throws", async () => {
|
|
39
|
-
const error = new Error("Access denied");
|
|
40
|
-
dataset.exists.mockRejectedValue(error);
|
|
41
|
-
await expect((0, utils_1.waitForInitialization)({
|
|
42
|
-
dataset: dataset,
|
|
43
|
-
changelogName,
|
|
44
|
-
})).rejects.toThrow("Access denied");
|
|
45
|
-
expect(logs.failedToInitializeWait).toHaveBeenCalledWith(error.message);
|
|
46
|
-
});
|
|
47
|
-
test("should handle and throw an error if table.exists throws", async () => {
|
|
48
|
-
dataset.exists.mockResolvedValue([true]);
|
|
49
|
-
const error = new Error("Table error");
|
|
50
|
-
table.exists.mockRejectedValue(error);
|
|
51
|
-
await expect((0, utils_1.waitForInitialization)({
|
|
52
|
-
dataset: dataset,
|
|
53
|
-
changelogName,
|
|
54
|
-
})).rejects.toThrow("Table error");
|
|
55
|
-
expect(logs.failedToInitializeWait).toHaveBeenCalledWith(error.message);
|
|
56
|
-
});
|
|
57
|
-
test("should handle unexpected error types gracefully", async () => {
|
|
58
|
-
dataset.exists.mockRejectedValue("String error");
|
|
59
|
-
await expect((0, utils_1.waitForInitialization)({
|
|
60
|
-
dataset: dataset,
|
|
61
|
-
changelogName,
|
|
62
|
-
})).rejects.toThrow("An unexpected error occurred");
|
|
63
|
-
expect(logs.failedToInitializeWait).toHaveBeenCalledWith("An unexpected error occurred");
|
|
64
|
-
});
|
|
65
|
-
});
|