@firebaseextensions/firestore-bigquery-change-tracker 1.1.36 → 1.1.38

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.
@@ -0,0 +1,19 @@
1
+ import { Table, TableMetadata } from "@google-cloud/bigquery/build/src/table";
2
+ import { FirestoreBigQueryEventHistoryTrackerConfig } from ".";
3
+ interface TableRequiresUpdateOptions {
4
+ table: Table;
5
+ config: FirestoreBigQueryEventHistoryTrackerConfig;
6
+ documentIdColExists: boolean;
7
+ pathParamsColExists: boolean;
8
+ oldDataColExists: boolean;
9
+ }
10
+ export declare function tableRequiresUpdate({ table, config, documentIdColExists, pathParamsColExists, oldDataColExists, }: TableRequiresUpdateOptions): Promise<boolean>;
11
+ interface ViewRequiresUpdateOptions {
12
+ metadata?: TableMetadata;
13
+ config: FirestoreBigQueryEventHistoryTrackerConfig;
14
+ documentIdColExists: boolean;
15
+ pathParamsColExists: boolean;
16
+ oldDataColExists: boolean;
17
+ }
18
+ export declare function viewRequiresUpdate({ metadata, config, documentIdColExists, pathParamsColExists, oldDataColExists, }: ViewRequiresUpdateOptions): boolean;
19
+ export {};
@@ -0,0 +1,14 @@
1
+ import { FirestoreBigQueryEventHistoryTrackerConfig } from ".";
2
+ import * as bigquery from "@google-cloud/bigquery";
3
+ import { TableMetadata } from "@google-cloud/bigquery";
4
+ export declare class Clustering {
5
+ config: FirestoreBigQueryEventHistoryTrackerConfig;
6
+ table: bigquery.Table;
7
+ schema: object;
8
+ constructor(config: FirestoreBigQueryEventHistoryTrackerConfig, table?: bigquery.Table, schema?: object);
9
+ hasValidTableReference(): boolean;
10
+ private hasInvalidFields;
11
+ private updateCluster;
12
+ private removeCluster;
13
+ updateClustering: (metaData: TableMetadata) => Promise<void>;
14
+ }
@@ -0,0 +1,3 @@
1
+ import { FirestoreBigQueryEventHistoryTrackerConfig } from ".";
2
+ declare const _default: (rows: any[], config: FirestoreBigQueryEventHistoryTrackerConfig, e: Error) => Promise<void>;
3
+ export default _default;
@@ -0,0 +1,77 @@
1
+ import * as bigquery from "@google-cloud/bigquery";
2
+ import { FirestoreEventHistoryTracker, FirestoreDocumentChangeEvent } from "../tracker";
3
+ export { RawChangelogSchema, RawChangelogViewSchema } from "./schema";
4
+ export interface FirestoreBigQueryEventHistoryTrackerConfig {
5
+ datasetId: string;
6
+ tableId: string;
7
+ datasetLocation?: string | undefined;
8
+ transformFunction?: string | undefined;
9
+ timePartitioning?: string | undefined;
10
+ timePartitioningField?: string | undefined;
11
+ timePartitioningFieldType?: string | undefined;
12
+ timePartitioningFirestoreField?: string | undefined;
13
+ clustering: string[] | null;
14
+ databaseId?: string | undefined;
15
+ wildcardIds?: boolean;
16
+ bqProjectId?: string | undefined;
17
+ backupTableId?: string | undefined;
18
+ useNewSnapshotQuerySyntax?: boolean;
19
+ skipInit?: boolean;
20
+ kmsKeyName?: string | undefined;
21
+ }
22
+ /**
23
+ * An FirestoreEventHistoryTracker that exports data to BigQuery.
24
+ *
25
+ * When the first event is received, it creates necessary BigQuery resources:
26
+ * - Dataset: {@link FirestoreBigQueryEventHistoryTrackerConfig#datasetId}.
27
+ * - Table: Raw change log table {@link FirestoreBigQueryEventHistoryTracker#rawChangeLogTableName}.
28
+ * - View: Latest view {@link FirestoreBigQueryEventHistoryTracker#rawLatestView}.
29
+ * If any subsequent data export fails, it will attempt to reinitialize.
30
+ */
31
+ export declare class FirestoreBigQueryEventHistoryTracker implements FirestoreEventHistoryTracker {
32
+ config: FirestoreBigQueryEventHistoryTrackerConfig;
33
+ bq: bigquery.BigQuery;
34
+ _initialized: boolean;
35
+ constructor(config: FirestoreBigQueryEventHistoryTrackerConfig);
36
+ record(events: FirestoreDocumentChangeEvent[]): Promise<void>;
37
+ private transformRows;
38
+ serializeData(eventData: any): any;
39
+ /**
40
+ * Check whether a failed operation is retryable or not.
41
+ * Reasons for retrying:
42
+ * 1) We added a new column to our schema. Sometimes BQ is not ready to stream insertion records immediately
43
+ * after adding a new column to an existing table (https://issuetracker.google.com/35905247)
44
+ */
45
+ private isRetryableInsertionError;
46
+ /**
47
+ * Tables can often take time to create and propagate.
48
+ * A half a second delay is added per check while the function
49
+ * continually re-checks until the referenced dataset and table become available.
50
+ */
51
+ private _waitForInitialization;
52
+ /**
53
+ * Inserts rows of data into the BigQuery raw change log table.
54
+ */
55
+ private insertData;
56
+ /**
57
+ * Creates the BigQuery resources with the expected schema for {@link FirestoreEventHistoryTracker}.
58
+ * After the first invokation, it skips initialization assuming these resources are still there.
59
+ */
60
+ initialize(): Promise<void>;
61
+ /**
62
+ * Creates the specified dataset if it doesn't already exists.
63
+ */
64
+ private initializeDataset;
65
+ /**
66
+ * Creates the raw change log table if it doesn't already exist.
67
+ */
68
+ private initializeRawChangeLogTable;
69
+ /**
70
+ * Creates the latest snapshot view, which returns only latest operations
71
+ * of all existing documents over the raw change log table.
72
+ */
73
+ private initializeLatestView;
74
+ bigqueryDataset(): bigquery.Dataset;
75
+ private rawChangeLogTableName;
76
+ private rawLatestView;
77
+ }
@@ -0,0 +1,29 @@
1
+ import { FirestoreBigQueryEventHistoryTrackerConfig } from ".";
2
+ import { FirestoreDocumentChangeEvent } from "..";
3
+ import * as bigquery from "@google-cloud/bigquery";
4
+ export declare class Partitioning {
5
+ config: FirestoreBigQueryEventHistoryTrackerConfig;
6
+ table: bigquery.Table;
7
+ schema: object;
8
+ constructor(config: FirestoreBigQueryEventHistoryTrackerConfig, table?: bigquery.Table, schema?: object);
9
+ private isPartitioningEnabled;
10
+ private isValidPartitionTypeString;
11
+ private metaDataSchemaFields;
12
+ private isValidPartitionTypeDate;
13
+ private hasHourAndDatePartitionConfig;
14
+ private hasValidCustomPartitionConfig;
15
+ private hasValidTimePartitionOption;
16
+ private hasValidTimePartitionType;
17
+ hasExistingSchema(): Promise<boolean>;
18
+ hasValidTableReference(): boolean;
19
+ private isTablePartitioned;
20
+ isValidPartitionForExistingTable(): Promise<boolean>;
21
+ convertDateValue(fieldValue: Date): string;
22
+ getPartitionValue(event: FirestoreDocumentChangeEvent): {
23
+ [x: string]: any;
24
+ };
25
+ customFieldExists(fields?: any[]): boolean;
26
+ private shouldAddPartitioningToSchema;
27
+ addPartitioningToSchema(fields?: any[]): Promise<void>;
28
+ updateTableMetadata(options: bigquery.TableMetadata): Promise<void>;
29
+ }
@@ -0,0 +1,56 @@
1
+ import { FirestoreBigQueryEventHistoryTrackerConfig } from ".";
2
+ export type BigQueryFieldMode = "NULLABLE" | "REPEATED" | "REQUIRED";
3
+ export type BigQueryFieldType = "BOOLEAN" | "NUMERIC" | "RECORD" | "STRING" | "TIMESTAMP";
4
+ export type BigQueryField = {
5
+ fields?: BigQueryField[];
6
+ mode: BigQueryFieldMode;
7
+ name: string;
8
+ type: BigQueryFieldType;
9
+ };
10
+ export declare const dataField: BigQueryField;
11
+ export declare const documentNameField: BigQueryField;
12
+ export declare const eventIdField: BigQueryField;
13
+ export declare const operationField: BigQueryField;
14
+ export declare const timestampField: BigQueryField;
15
+ export declare const latitudeField: BigQueryField;
16
+ export declare const longitudeField: BigQueryField;
17
+ export declare const documentIdField: {
18
+ name: string;
19
+ mode: string;
20
+ type: string;
21
+ description: string;
22
+ };
23
+ export declare const documentPathParams: {
24
+ name: string;
25
+ mode: string;
26
+ type: string;
27
+ description: string;
28
+ };
29
+ export declare const oldDataField: {
30
+ name: string;
31
+ mode: string;
32
+ type: string;
33
+ description: string;
34
+ };
35
+ export declare const RawChangelogViewSchema: {
36
+ fields: {
37
+ name: string;
38
+ mode: string;
39
+ type: string;
40
+ description: string;
41
+ }[];
42
+ };
43
+ export declare const RawChangelogSchema: {
44
+ fields: {
45
+ name: string;
46
+ mode: string;
47
+ type: string;
48
+ description: string;
49
+ }[];
50
+ };
51
+ export declare const getNewPartitionField: (config: FirestoreBigQueryEventHistoryTrackerConfig) => {
52
+ name: string;
53
+ mode: string;
54
+ type: string;
55
+ description: string;
56
+ };
@@ -0,0 +1,21 @@
1
+ interface LatestConsistentSnapshotViewOptions {
2
+ datasetId: string;
3
+ tableName: string;
4
+ schema: any;
5
+ bqProjectId?: string;
6
+ useLegacyQuery?: boolean;
7
+ }
8
+ export declare const latestConsistentSnapshotView: ({ datasetId, tableName, schema, bqProjectId, useLegacyQuery, }: LatestConsistentSnapshotViewOptions) => {
9
+ query: string;
10
+ useLegacySql: boolean;
11
+ };
12
+ interface buildLatestSnapshotViewQueryOptions {
13
+ datasetId: string;
14
+ tableName: string;
15
+ timestampColumnName: string;
16
+ groupByColumns: string[];
17
+ bqProjectId?: string;
18
+ useLegacyQuery?: boolean;
19
+ }
20
+ export declare function buildLatestSnapshotViewQuery({ datasetId, tableName, timestampColumnName, groupByColumns, bqProjectId, useLegacyQuery, }: buildLatestSnapshotViewQueryOptions): string;
21
+ export {};
@@ -0,0 +1,15 @@
1
+ import { Dataset, Table } from "@google-cloud/bigquery";
2
+ interface WaitForInitializationParams {
3
+ dataset: Dataset;
4
+ changelogName: string;
5
+ }
6
+ /**
7
+ * Periodically checks for the existence of a dataset and table until both are found or a maximum number of attempts is reached.
8
+ * @param {WaitForInitializationParams} params - Parameters for initialization including the dataset and the table name to check.
9
+ * @param {number} maxAttempts - Maximum number of attempts before giving up (defaults to 12).
10
+ * @returns {Promise<Table>} A promise that resolves with the Table if it exists, or rejects if it doesn't exist after maxAttempts or an error occurs.
11
+ * @throws {Error} Throws an error if the dataset or table cannot be verified to exist after multiple attempts or if an unexpected error occurs.
12
+ */
13
+ export declare function waitForInitialization({ dataset, changelogName }: WaitForInitializationParams, maxAttempts?: number): Promise<Table>;
14
+ export declare function parseErrorMessage(error: unknown, process?: string): string;
15
+ export {};
@@ -0,0 +1 @@
1
+ export declare const validateProject: (id: string) => Promise<boolean>;
@@ -0,0 +1,2 @@
1
+ export declare const changedFieldMode: (fieldName: string, bqMode: string, schemaMode: string) => Error;
2
+ export declare const changedFieldType: (fieldName: string, bqType: string, schemaType: string) => Error;
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { FirestoreBigQueryEventHistoryTracker, RawChangelogSchema, RawChangelogViewSchema, } from "./bigquery";
2
+ export { ChangeType, FirestoreDocumentChangeEvent, FirestoreEventHistoryTracker, } from "./tracker";
package/lib/logs.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { Table } from "@google-cloud/bigquery";
2
+ import { firestore } from "firebase-admin";
3
+ export declare const arrayFieldInvalid: (fieldName: string) => void;
4
+ export declare const bigQueryDatasetCreated: (datasetId: string) => void;
5
+ export declare const bigQueryDatasetCreating: (datasetId: string) => void;
6
+ export declare const bigQueryDatasetExists: (datasetId: string) => void;
7
+ export declare const bigQueryErrorRecordingDocumentChange: (e: Error) => void;
8
+ export declare const bigQueryLatestSnapshotViewQueryCreated: (query: string) => void;
9
+ export declare const bigQuerySchemaViewCreated: (name: string) => void;
10
+ export declare const bigQueryTableAlreadyExists: (tableName: string, datasetName: string) => void;
11
+ export declare const bigQueryTableCreated: (tableName: string) => void;
12
+ export declare const bigQueryTableCreating: (tableName: string) => void;
13
+ export declare const bigQueryTableUpdated: (tableName: string) => void;
14
+ export declare const bigQueryTableUpdating: (tableName: string) => void;
15
+ export declare const bigQueryTableUpToDate: (tableName: string) => void;
16
+ export declare const bigQueryTableValidated: (tableName: string) => void;
17
+ export declare const bigQueryTableValidating: (tableName: string) => void;
18
+ export declare const bigQueryUserDefinedFunctionCreating: (functionName: string) => void;
19
+ export declare const bigQueryUserDefinedFunctionCreated: (functionName: string) => void;
20
+ export declare const bigQueryViewCreated: (viewName: string) => void;
21
+ export declare const bigQueryViewCreating: (viewName: string, query: string) => void;
22
+ export declare const bigQueryViewAlreadyExists: (viewName: string, datasetName: string) => void;
23
+ export declare const bigQueryViewUpdated: (viewName: string) => void;
24
+ export declare const bigQueryViewUpdating: (viewName: string) => void;
25
+ export declare const bigQueryViewUpToDate: (viewName: string) => void;
26
+ export declare const bigQueryViewValidated: (viewName: string) => void;
27
+ export declare const bigQueryViewValidating: (viewName: string) => void;
28
+ export declare const complete: () => void;
29
+ export declare const dataInserted: (rowCount: number) => void;
30
+ export declare const dataInsertRetried: (rowCount: number) => void;
31
+ export declare const dataInserting: (rowCount: number) => void;
32
+ export declare const dataTypeInvalid: (fieldName: string, fieldType: string, dataType: string) => void;
33
+ export declare const error: (err: Error) => void;
34
+ export declare const timestampMissingValue: (fieldName: string) => void;
35
+ export declare const addNewColumn: (table: string, field: string) => void;
36
+ export declare const addPartitionFieldColumn: (table: any, field: any) => void;
37
+ export declare const firestoreTimePartitionFieldError: (documentName: string | undefined, fieldName: string | undefined, firestoreFieldName: string | undefined, firestoreFieldData: any) => void;
38
+ export declare const firestoreTimePartitioningParametersWarning: (fieldName: string | undefined, fieldType: string | undefined, firestoreFieldName: string | undefined, dataFirestoreField: firestore.Timestamp | string | undefined) => void;
39
+ export declare const bigQueryTableInsertErrors: (insertErrors: [
40
+ {
41
+ row: object;
42
+ errors: Array<{
43
+ message: string;
44
+ }>;
45
+ }
46
+ ]) => void;
47
+ export declare const updatedClustering: (fields: string) => void;
48
+ export declare const removedClustering: (tableName: string) => void;
49
+ export declare const cannotPartitionExistingTable: (table: Table) => void;
50
+ export declare function invalidProjectIdWarning(bqProjectId: string): void;
51
+ export declare function invalidTableReference(): void;
52
+ export declare function hourAndDatePartitioningWarning(): void;
53
+ export declare function invalidClustering(fields: string): void;
54
+ export declare const tableCreationError: (table: any, message: any) => void;
55
+ export declare const failedToInitializeWait: (message: any) => void;
56
+ export declare const updatingMetadata: (tableName: any, resources: any) => void;
@@ -0,0 +1,23 @@
1
+ export declare enum ChangeType {
2
+ CREATE = 0,
3
+ DELETE = 1,
4
+ UPDATE = 2,
5
+ IMPORT = 3
6
+ }
7
+ export interface FirestoreDocumentChangeEvent {
8
+ timestamp: string;
9
+ operation: ChangeType;
10
+ documentName: string;
11
+ eventId: string;
12
+ documentId: string;
13
+ pathParams?: {
14
+ documentId: string;
15
+ [key: string]: string;
16
+ } | null;
17
+ data: Object;
18
+ oldData?: Object | null;
19
+ useNewSnapshotQuerySyntax?: boolean | null;
20
+ }
21
+ export interface FirestoreEventHistoryTracker {
22
+ record(event: FirestoreDocumentChangeEvent[]): any;
23
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare enum PartitionFieldType {
2
+ DATE = "DATE",
3
+ DATETIME = "DATETIME",
4
+ TIMESTAMP = "TIMESTAMP"
5
+ }
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.36",
8
+ "version": "1.1.38",
9
9
  "description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
10
10
  "main": "./lib/index.js",
11
11
  "scripts": {
@@ -18,7 +18,9 @@
18
18
  },
19
19
  "files": [
20
20
  "lib/*.js",
21
- "lib/bigquery/*.js"
21
+ "lib/bigquery/*.js",
22
+ "lib/*.d.ts",
23
+ "lib/bigquery/*.d.ts"
22
24
  ],
23
25
  "author": "Jan Wyszynski <wyszynski@google.com>",
24
26
  "license": "Apache-2.0",