Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 2.2.0

- Works on `firebase-admin` 14. 2.1.1 widened the range but the package still used the namespaced API (`admin.apps`, `admin.firestore.Timestamp`), which firebase-admin 14 removes, so it threw at import wherever it was resolved against admin 14. Every use is now the modular API from `firebase-admin/app` and `firebase-admin/firestore`, which works on 13 and 14 alike.
- `firebase-functions` 7.3 and later is accepted alongside 6. This package only uses its `logger`, but the firebase-functions 6 peer range for `firebase-admin` stops at 13, as does the range of firebase-functions 7.0 through 7.2, so on a consumer running firebase-admin 14 npm nested a second admin copy under this package however wide this package's own range was, and that nested copy has no default app.
- Declares `engines.node >=18`, the floor firebase-admin 13 already imposed, so an unsupported Node is reported at install rather than at runtime.
- Consumers that pin neither `firebase-admin` nor `firebase-functions` themselves and resolve fresh now get firebase-admin 14 and firebase-functions 7, which need Node 22 and Node 18 respectively. Pin firebase-admin `^13` to stay on Node 18 or 20.

## 2.1.1

- `firebase-admin` 14 is accepted alongside 13. With the previous `^13.2.0` range a consumer on 14 installed a second copy of the SDK under this package, and that copy never sees the consumer's `initializeApp()`, so every backup write to `backupTableId` failed with "The default Firebase app does not exist" and the rows were lost.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"url": "git+https://github.com/firebase/extensions.git",
"directory": "firestore-bigquery-export/firestore-bigquery-change-tracker"
},
"version": "2.1.1",
"version": "2.2.0",
"engines": {
"node": ">=18"
},
"description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
"main": "./lib/index.js",
"scripts": {
Expand All @@ -26,7 +29,7 @@
"@google-cloud/bigquery": "^7.6.0",
"@google-cloud/resource-manager": "^5.1.0",
"firebase-admin": "^13.2.0 || ^14.0.0",
"firebase-functions": "^6.3.2",
"firebase-functions": "^6.3.2 || ^7.3.0",
"sql-formatter": "^2.3.3",
"traverse": "^0.6.6"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ const settings = jest.fn();
const batch = jest.fn(() => ({ set, commit }));
const collection = jest.fn(() => ({ doc: (id: string) => ({ id }) }));

jest.mock("firebase-admin", () => ({ apps: [{}] }));
jest.mock("firebase-admin/app", () => ({ initializeApp: jest.fn() }));
jest.mock("firebase-admin/app", () => ({
getApps: jest.fn(() => [{}]),
initializeApp: jest.fn(),
}));
jest.mock("firebase-admin/firestore", () => ({
// A fresh object per call, deliberately: the guard must key on the database id
// rather than on instance identity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { latestConsistentSnapshotView } from "../../bigquery/snapshot";
import { deleteTable } from "../fixtures/clearTables";
import { changeTracker, changeTrackerEvent } from "../fixtures/changeTracker";
import { getBigQueryTableData } from "../fixtures/queries";
import { firestore } from "firebase-admin";
import { Timestamp } from "firebase-admin/firestore";

process.env.PROJECT_ID = "dev-extensions-testing";

Expand Down Expand Up @@ -167,7 +167,7 @@ describe("e2e", () => {
});

test("successfully partitions with a valid DateTime Timestamp", async () => {
const created = firestore.Timestamp.now();
const created = Timestamp.now();

const event: FirestoreDocumentChangeEvent = changeTrackerEvent({
data: { created },
Expand Down Expand Up @@ -206,7 +206,7 @@ describe("e2e", () => {
});

test("successfully partitions with a valid DateTime Timestamp Date", async () => {
const created = firestore.Timestamp.now().toDate();
const created = Timestamp.now().toDate();

const event: FirestoreDocumentChangeEvent = changeTrackerEvent({
data: { created },
Expand Down Expand Up @@ -243,7 +243,7 @@ describe("e2e", () => {
});

test("successfully partitions with a valid Firebase Timestamp value with a Timestamp partitioning type", async () => {
const created = firestore.Timestamp.now();
const created = Timestamp.now();

const event: FirestoreDocumentChangeEvent = changeTrackerEvent({
data: { created },
Expand Down Expand Up @@ -280,7 +280,7 @@ describe("e2e", () => {
});

test("successfully partitions with a valid Firebase Timestamp value with a Date partitioning type", async () => {
const created = firestore.Timestamp.now();
const created = Timestamp.now();
const expectedDate = created.toDate().toISOString().substring(0, 10);

const event: FirestoreDocumentChangeEvent = changeTrackerEvent({
Expand Down Expand Up @@ -316,7 +316,7 @@ describe("e2e", () => {
});

test("successfully partitions with a valid Firebase Timestamp value with a DateTime partitioning type", async () => {
const created = firestore.Timestamp.now();
const created = Timestamp.now();
const expectedDate = created.toDate().toISOString().substring(0, 22);

const event: FirestoreDocumentChangeEvent = changeTrackerEvent({
Expand Down Expand Up @@ -354,7 +354,7 @@ describe("e2e", () => {
});

test("successfully partitions with a valid Firebase Timestamp value with `timestamp` as field name and Timestamp type", async () => {
const created = firestore.Timestamp.now();
const created = Timestamp.now();
const expectedDate = created.toDate().toISOString().substring(0, 22);

const event: FirestoreDocumentChangeEvent = changeTrackerEvent({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
* limitations under the License.
*/

import * as admin from "firebase-admin";
import { Firestore, getFirestore } from "firebase-admin/firestore";
import { ChangeTrackerConfig } from "../../bigquery/types";

import handleFailedTransactions from "../../bigquery/handleFailedTransactions";

// admin.initializeApp();
const db = admin.firestore();
let db: Firestore;

describe("handleFailedTransactions", () => {
beforeAll(() => {
db = getFirestore();
});

it("should be defined", () => {
expect(handleFailedTransactions).toBeDefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
TableMetadata,
Table,
} from "@google-cloud/bigquery";
import { firestore } from "firebase-admin";
import { Timestamp } from "firebase-admin/firestore";
import { RawChangelogViewSchema } from "../../../bigquery/schema";
import { initializeLatestMaterializedView } from "../../../bigquery/initializeLatestMaterializedView";
import {
Expand Down Expand Up @@ -143,7 +143,7 @@ describe("initializeLatestMaterializedView", () => {

test("does not recreate view if configuration matches", async () => {
const event = changeTrackerEvent({
data: { end_date: firestore.Timestamp.now() },
data: { end_date: Timestamp.now() },
eventId: "testing2",
});

Expand Down Expand Up @@ -185,7 +185,7 @@ describe("initializeLatestMaterializedView", () => {

test("recreates view when switching from incremental to non-incremental", async () => {
const event = changeTrackerEvent({
data: { end_date: firestore.Timestamp.now() },
data: { end_date: Timestamp.now() },
eventId: "testing3",
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
changeTrackerEvent,
} from "../../fixtures/changeTracker";
import { getBigQueryTableData } from "../../fixtures/queries";
import { firestore } from "firebase-admin";
import { Timestamp } from "firebase-admin/firestore";

process.env.PROJECT_ID = "dev-extensions-testing";

Expand All @@ -45,7 +45,7 @@ process.env.PROJECT_ID = "dev-extensions-testing";
// eventId = "testing",
// documentId = "testing",
// pathParams = { documentId: "12345" },
// data = { end_date: firestore.Timestamp.now() },
// data = { end_date: Timestamp.now() },
// oldData = null,
// useNewSnapshotQuerySyntax = false,
// }: any): FirestoreDocumentChangeEvent => {
Expand All @@ -65,7 +65,7 @@ process.env.PROJECT_ID = "dev-extensions-testing";
const bq: BigQuery = new BigQuery({ projectId: process.env.PROJECT_ID });
const event: FirestoreDocumentChangeEvent = changeTrackerEvent({});
const event2: FirestoreDocumentChangeEvent = changeTrackerEvent({
data: { end_date: firestore.Timestamp.now() },
data: { end_date: Timestamp.now() },
eventId: "testing2",
});
let randomID: string;
Expand Down Expand Up @@ -329,7 +329,7 @@ describe("integration", () => {
eventId: "testing3",
documentId: "doc3",
pathParams: { documentId: "doc3" },
data: { end_date: firestore.Timestamp.now(), status: "completed" },
data: { end_date: Timestamp.now(), status: "completed" },
oldData: null,
});

Expand All @@ -340,7 +340,7 @@ describe("integration", () => {
eventId: "testing4",
documentId: "doc4",
pathParams: { documentId: "doc4" },
data: { end_date: firestore.Timestamp.now(), status: "pending" },
data: { end_date: Timestamp.now(), status: "pending" },
oldData: null,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { BigQuery, Dataset, TableMetadata } from "@google-cloud/bigquery";
import { firestore } from "firebase-admin";
import { Timestamp } from "firebase-admin/firestore";
import { RawChangelogViewSchema } from "../../../bigquery/schema";
import {
buildMaterializedViewQuery,
Expand Down Expand Up @@ -102,7 +102,7 @@ describe("Materialized View Recreation", () => {
test("should not recreate incremental materialized view when unchanged", async () => {
// Create initial event
const event = changeTrackerEvent({
data: { end_date: firestore.Timestamp.now() },
data: { end_date: Timestamp.now() },
eventId: "testing2",
});

Expand Down Expand Up @@ -162,7 +162,7 @@ describe("Materialized View Recreation", () => {
test("should not recreate non-incremental materialized view when unchanged", async () => {
// Create initial event
const event = changeTrackerEvent({
data: { end_date: firestore.Timestamp.now() },
data: { end_date: Timestamp.now() },
eventId: "testing2",
});

Expand Down Expand Up @@ -224,7 +224,7 @@ describe("Materialized View Recreation", () => {
test("should recreate materialized view when inc -> non-inc ", async () => {
// Create initial event
const event = changeTrackerEvent({
data: { end_date: firestore.Timestamp.now() },
data: { end_date: Timestamp.now() },
eventId: "testing2",
});

Expand Down Expand Up @@ -285,7 +285,7 @@ describe("Materialized View Recreation", () => {
test("should recreate materialized view when non-inc -> inc ", async () => {
// Create initial event
const event = changeTrackerEvent({
data: { end_date: firestore.Timestamp.now() },
data: { end_date: Timestamp.now() },
eventId: "testing2",
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as admin from "firebase-admin";
import { Timestamp } from "firebase-admin/firestore";

import { BigQuery, Dataset, Table } from "@google-cloud/bigquery";
import { ChangeType, FirestoreDocumentChangeEvent } from "../..";
Expand Down Expand Up @@ -236,7 +236,7 @@ describeIfBigQueryIntegration("processing partitions on a new table", () => {
bqProjectId: undefined,
};

const end_date = admin.firestore.Timestamp.now();
const end_date = Timestamp.now();

const event: FirestoreDocumentChangeEvent = {
timestamp: "",
Expand Down Expand Up @@ -382,7 +382,7 @@ describeIfBigQueryIntegration("processing partitions on a new table", () => {
bqProjectId: undefined,
};

const end_date = admin.firestore.Timestamp.now();
const end_date = Timestamp.now();

const event: FirestoreDocumentChangeEvent = {
timestamp: "",
Expand Down Expand Up @@ -415,7 +415,7 @@ describeIfBigQueryIntegration("processing partitions on a new table", () => {
bqProjectId: undefined,
};

const end_date = admin.firestore.Timestamp.now();
const end_date = Timestamp.now();

const event: FirestoreDocumentChangeEvent = {
timestamp: "",
Expand Down Expand Up @@ -449,7 +449,7 @@ describeIfBigQueryIntegration("processing partitions on a new table", () => {
bqProjectId: undefined,
};

const end_date = admin.firestore.Timestamp.now();
const end_date = Timestamp.now();

const event: FirestoreDocumentChangeEvent = {
timestamp: "",
Expand Down Expand Up @@ -777,9 +777,7 @@ describeIfBigQueryIntegration(
firestoreFieldName: "endDate",
});

const oldDate = admin.firestore.Timestamp.fromDate(
new Date("2024-01-15T10:00:00Z")
);
const oldDate = Timestamp.fromDate(new Date("2024-01-15T10:00:00Z"));

const event: FirestoreDocumentChangeEvent = {
timestamp: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
* limitations under the License.
*/

import * as admin from "firebase-admin";
import { Timestamp } from "firebase-admin/firestore";
import { PartitionValueConverter } from "../../../bigquery/partitioning/converter";

describe("PartitionValueConverter", () => {
describe("convert with TIMESTAMP type", () => {
const converter = new PartitionValueConverter("TIMESTAMP");

test("converts Firebase Timestamp to BigQuery timestamp string", () => {
const timestamp = admin.firestore.Timestamp.fromDate(
new Date("2024-01-15T10:30:00Z")
);
const timestamp = Timestamp.fromDate(new Date("2024-01-15T10:30:00Z"));
const result = converter.convert(timestamp);
expect(result).toBeDefined();
expect(typeof result).toBe("string");
Expand Down Expand Up @@ -195,9 +193,7 @@ describe("PartitionValueConverter", () => {
const converter = new PartitionValueConverter("DATE");

test("converts Firebase Timestamp to BigQuery date string", () => {
const timestamp = admin.firestore.Timestamp.fromDate(
new Date("2024-01-15T10:30:00Z")
);
const timestamp = Timestamp.fromDate(new Date("2024-01-15T10:30:00Z"));
const result = converter.convert(timestamp);
expect(result).toBe("2024-01-15");
});
Expand Down Expand Up @@ -248,9 +244,7 @@ describe("PartitionValueConverter", () => {
const converter = new PartitionValueConverter("DATETIME");

test("converts Firebase Timestamp to BigQuery datetime string", () => {
const timestamp = admin.firestore.Timestamp.fromDate(
new Date("2024-01-15T10:30:00Z")
);
const timestamp = Timestamp.fromDate(new Date("2024-01-15T10:30:00Z"));
const result = converter.convert(timestamp);
expect(result).toBeDefined();
expect(result).toContain("2024-01-15");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { firestore } from "firebase-admin";
import { Timestamp } from "firebase-admin/firestore";
import {
ChangeType,
FirestoreBigQueryEventHistoryTracker,
Expand Down Expand Up @@ -66,7 +66,7 @@ export const changeTrackerEvent = ({
eventId = "testing",
documentId = "testing",
pathParams = { documentId: "12345" },
data = { end_date: firestore.Timestamp.now() },
data = { end_date: Timestamp.now() },
oldData = null,
useNewSnapshotQuerySyntax = false,
}: any): FirestoreDocumentChangeEvent => {
Expand Down
Loading
Loading