13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- import * as admin from "firebase-admin" ;
17
16
import * as bigquery from "@google-cloud/bigquery" ;
18
17
import { DocumentReference } from "firebase-admin/firestore" ;
19
18
import * as traverse from "traverse" ;
@@ -45,25 +44,9 @@ import { tableRequiresUpdate, viewRequiresUpdate } from "./checkUpdates";
45
44
import { parseErrorMessage , waitForInitialization } from "./utils" ;
46
45
47
46
export { RawChangelogSchema , RawChangelogViewSchema } from "./schema" ;
48
-
49
- export interface FirestoreBigQueryEventHistoryTrackerConfig {
50
- datasetId : string ;
51
- tableId : string ;
52
- datasetLocation ?: string | undefined ;
53
- transformFunction ?: string | undefined ;
54
- timePartitioning ?: string | undefined ;
55
- timePartitioningField ?: string | undefined ;
56
- timePartitioningFieldType ?: string | undefined ;
57
- timePartitioningFirestoreField ?: string | undefined ;
58
- clustering : string [ ] | null ;
59
- databaseId ?: string | undefined ;
60
- wildcardIds ?: boolean ;
61
- bqProjectId ?: string | undefined ;
62
- backupTableId ?: string | undefined ;
63
- useNewSnapshotQuerySyntax ?: boolean ;
64
- skipInit ?: boolean ;
65
- kmsKeyName ?: string | undefined ;
66
- }
47
+ import type { Config } from "./types" ;
48
+ import { PartitioningConfig } from "./partitioning/config" ;
49
+ export type { Config } from "./types" ;
67
50
68
51
/**
69
52
* An FirestoreEventHistoryTracker that exports data to BigQuery.
@@ -80,12 +63,15 @@ export class FirestoreBigQueryEventHistoryTracker
80
63
{
81
64
bq : bigquery . BigQuery ;
82
65
_initialized : boolean = false ;
66
+ partitioningConfig : PartitioningConfig ;
83
67
84
- constructor ( public config : FirestoreBigQueryEventHistoryTrackerConfig ) {
68
+ constructor ( public config : Config ) {
85
69
this . bq = new bigquery . BigQuery ( ) ;
86
70
87
71
this . bq . projectId = config . bqProjectId || process . env . PROJECT_ID ;
88
72
73
+ this . partitioningConfig = new PartitioningConfig ( this . config . partitioning ) ;
74
+
89
75
if ( ! this . config . datasetLocation ) {
90
76
this . config . datasetLocation = "us" ;
91
77
}
@@ -96,7 +82,7 @@ export class FirestoreBigQueryEventHistoryTracker
96
82
await this . initialize ( ) ;
97
83
}
98
84
99
- const partitionHandler = new Partitioning ( this . config ) ;
85
+ const partitionHandler = new Partitioning ( this . partitioningConfig ) ;
100
86
101
87
const rows = events . map ( ( event ) => {
102
88
const partitionValue = partitionHandler . getPartitionValue ( event ) ;
@@ -327,7 +313,7 @@ export class FirestoreBigQueryEventHistoryTracker
327
313
const dataset = this . bigqueryDataset ( ) ;
328
314
const table = dataset . table ( changelogName ) ;
329
315
const [ tableExists ] = await table . exists ( ) ;
330
- const partitioning = new Partitioning ( this . config , table ) ;
316
+ const partitioning = new Partitioning ( this . partitioningConfig , table ) ;
331
317
const clustering = new Clustering ( this . config , table ) ;
332
318
333
319
if ( tableExists ) {
0 commit comments