@firebase-function-kits/firestore-bigquery-export 0.0.1 → 0.0.2-rc.1

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/README.md +303 -0
  3. package/lib/config.d.ts +33 -0
  4. package/lib/config.d.ts.map +1 -0
  5. package/lib/config.js +569 -0
  6. package/lib/config.js.map +1 -0
  7. package/lib/events.d.ts +45 -0
  8. package/lib/events.d.ts.map +1 -0
  9. package/lib/events.js +154 -0
  10. package/lib/events.js.map +1 -0
  11. package/lib/export-config.d.ts +96 -0
  12. package/lib/export-config.d.ts.map +1 -0
  13. package/lib/export-config.js +77 -0
  14. package/lib/export-config.js.map +1 -0
  15. package/lib/handlers.d.ts +29 -0
  16. package/lib/handlers.d.ts.map +1 -0
  17. package/lib/handlers.js +165 -0
  18. package/lib/handlers.js.map +1 -0
  19. package/lib/index.d.ts +23 -0
  20. package/lib/index.d.ts.map +1 -0
  21. package/lib/index.js +179 -0
  22. package/lib/index.js.map +1 -0
  23. package/lib/init.d.ts +16 -0
  24. package/lib/init.d.ts.map +1 -0
  25. package/lib/init.js +44 -0
  26. package/lib/init.js.map +1 -0
  27. package/lib/lib.d.ts +20 -0
  28. package/lib/lib.d.ts.map +1 -0
  29. package/lib/lib.js +47 -0
  30. package/lib/lib.js.map +1 -0
  31. package/lib/logs.d.ts +39 -0
  32. package/lib/logs.d.ts.map +1 -0
  33. package/lib/logs.js +186 -0
  34. package/lib/logs.js.map +1 -0
  35. package/lib/util.d.ts +23 -0
  36. package/lib/util.d.ts.map +1 -0
  37. package/lib/util.js +66 -0
  38. package/lib/util.js.map +1 -0
  39. package/npm-shrinkwrap.json +7016 -0
  40. package/package.json +37 -3
  41. package/src/config.ts +696 -0
  42. package/src/events.ts +146 -0
  43. package/src/export-config.ts +205 -0
  44. package/src/handlers.ts +211 -0
  45. package/src/index.ts +174 -0
  46. package/src/init.ts +45 -0
  47. package/src/lib.ts +55 -0
  48. package/src/logs.ts +233 -0
  49. package/src/util.ts +64 -0
  50. package/tests/config.test.ts +182 -0
  51. package/tests/events.test.ts +84 -0
  52. package/tests/export-config.test.ts +114 -0
  53. package/tests/handlers.test.ts +220 -0
  54. package/tests/init.test.ts +76 -0
  55. package/tests/util.test.ts +102 -0
  56. package/tsconfig.json +18 -0
  57. package/tsconfig.tsbuildinfo +1 -0
package/src/events.ts ADDED
@@ -0,0 +1,146 @@
1
+ /*
2
+ * Copyright 2019 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import * as eventArc from "firebase-admin/eventarc";
17
+
18
+ const { getEventarc } = eventArc;
19
+
20
+ /**
21
+ * Builds the Eventarc event type for this extension.
22
+ *
23
+ * @param eventName The name of the event (e.g., "onStart", "onError", etc.)
24
+ * @returns The event type string.
25
+ */
26
+ const getEventTypes = (eventName: string) => [
27
+ `firebase.extensions.firestore-bigquery-export.v1.${eventName}`,
28
+ ];
29
+
30
+ let eventChannel: eventArc.Channel | undefined;
31
+
32
+ /**
33
+ * Sets up the Eventarc channel.
34
+ *
35
+ * This function retrieves the Eventarc channel based on the environment variables:
36
+ * - `EVENTARC_CHANNEL` specifies the channel to use for publishing events.
37
+ * - `EXT_SELECTED_EVENTS` defines the allowed event types.
38
+ *
39
+ * @function setupEventChannel
40
+ */
41
+ export const setupEventChannel = () => {
42
+ eventChannel = process.env.EVENTARC_CHANNEL
43
+ ? getEventarc().channel(process.env.EVENTARC_CHANNEL, {
44
+ allowedEventTypes: process.env.EXT_SELECTED_EVENTS,
45
+ })
46
+ : undefined;
47
+ };
48
+
49
+ /**
50
+ * Publishes a "start" event using both OLD and NEW event types.
51
+ *
52
+ * @param data The payload to send with the event. Can be a string or an object.
53
+ * @returns A Promise resolving when both events are published.
54
+ */
55
+ export const recordStartEvent = async (data: string | object) => {
56
+ if (!eventChannel) return Promise.resolve();
57
+
58
+ const eventTypes = getEventTypes("onStart");
59
+
60
+ // Publish events for both OLD and NEW event types
61
+ return Promise.all(
62
+ eventTypes.map((type) =>
63
+ eventChannel.publish({
64
+ type,
65
+ data,
66
+ })
67
+ )
68
+ );
69
+ };
70
+
71
+ /**
72
+ * Publishes an "error" event using both OLD and NEW event types.
73
+ *
74
+ * @param err The Error object containing the error message.
75
+ * @param subject (Optional) Subject identifier related to the error event.
76
+ * @returns A Promise resolving when both events are published.
77
+ */
78
+ export const recordErrorEvent = async (err: Error, subject?: string) => {
79
+ if (!eventChannel) return Promise.resolve();
80
+
81
+ const eventTypes = getEventTypes("onError");
82
+
83
+ // Publish events for both OLD and NEW event types
84
+ return Promise.all(
85
+ eventTypes.map((type) =>
86
+ eventChannel.publish({
87
+ type,
88
+ data: { message: err.message },
89
+ subject,
90
+ })
91
+ )
92
+ );
93
+ };
94
+
95
+ /**
96
+ * Publishes a "success" event using both OLD and NEW event types.
97
+ *
98
+ * @param params An object containing the subject and the event data.
99
+ * @param params.subject A string representing the subject of the event.
100
+ * @param params.data The payload to send with the event.
101
+ * @returns A Promise resolving when both events are published.
102
+ */
103
+ export const recordSuccessEvent = async ({
104
+ subject,
105
+ data,
106
+ }: {
107
+ subject: string;
108
+ data: string | object;
109
+ }) => {
110
+ if (!eventChannel) return Promise.resolve();
111
+
112
+ const eventTypes = getEventTypes("onSuccess");
113
+
114
+ // Publish events for both OLD and NEW event types
115
+ return Promise.all(
116
+ eventTypes.map((type) =>
117
+ eventChannel.publish({
118
+ type,
119
+ subject,
120
+ data,
121
+ })
122
+ )
123
+ );
124
+ };
125
+
126
+ /**
127
+ * Publishes a "completion" event using both OLD and NEW event types.
128
+ *
129
+ * @param data The payload to send with the event. Can be a string or an object.
130
+ * @returns A Promise resolving when both events are published.
131
+ */
132
+ export const recordCompletionEvent = async (data: string | object) => {
133
+ if (!eventChannel) return Promise.resolve();
134
+
135
+ const eventTypes = getEventTypes("onCompletion");
136
+
137
+ // Publish events for both OLD and NEW event types
138
+ return Promise.all(
139
+ eventTypes.map((type) =>
140
+ eventChannel.publish({
141
+ type,
142
+ data,
143
+ })
144
+ )
145
+ );
146
+ };
@@ -0,0 +1,205 @@
1
+ /*
2
+ * Copyright 2019 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type {
17
+ ChangeTrackerConfig,
18
+ LogLevel,
19
+ } from "@firebaseextensions/firestore-bigquery-change-tracker";
20
+ import type { Expression } from "firebase-functions/params";
21
+
22
+ type TrackerLogLevel = "debug" | "info" | "warn" | "error" | "silent";
23
+ type ConfigValue<T extends string | number | boolean | string[]> =
24
+ | T
25
+ | Expression<T>;
26
+
27
+ /** How the BigQuery changelog view is materialized. */
28
+ export type ViewType =
29
+ | "view"
30
+ | "materialized_incremental"
31
+ | "materialized_non_incremental";
32
+
33
+ /**
34
+ * The export configuration. The main entry point builds it from deploy-time
35
+ * params; handler consumers can construct it directly.
36
+ *
37
+ * `collectionPath`, `datasetId`, `tableId`, `location`, and `projectId` are
38
+ * required; everything else has a sensible default.
39
+ */
40
+ export interface ExportConfig {
41
+ /** Firestore collection (or collection group) path to mirror, e.g. `users`
42
+ * or `regions/{regionId}/users`. */
43
+ collectionPath: ConfigValue<string>;
44
+ /** BigQuery dataset id to write into. */
45
+ datasetId: ConfigValue<string>;
46
+ /** BigQuery changelog table id. */
47
+ tableId: ConfigValue<string>;
48
+
49
+ /** Region for the trigger and task queue. */
50
+ location: ConfigValue<string>;
51
+ /** BigQuery dataset location, e.g. `us`, `eu`. Defaults to `us`. */
52
+ datasetLocation?: ConfigValue<string>;
53
+ /** Project that owns the BigQuery dataset, if different from the function's
54
+ * project. */
55
+ bqProjectId?: ConfigValue<string>;
56
+ /** GCP project id. */
57
+ projectId: ConfigValue<string>;
58
+ /** Firestore database id. Defaults to `(default)`. */
59
+ databaseId?: ConfigValue<string>;
60
+
61
+ /** Include path-param values as columns. Defaults to `false`. */
62
+ wildcardIds?: ConfigValue<boolean>;
63
+ /** Skip writing the previous document state on updates. Defaults to `false`. */
64
+ excludeOldData?: ConfigValue<boolean>;
65
+ /** Use the newer snapshot view query syntax. Defaults to `false`. */
66
+ useNewSnapshotQuerySyntax?: ConfigValue<boolean>;
67
+ /** Changelog view strategy. Defaults to `view`. */
68
+ viewType?: ConfigValue<ViewType>;
69
+
70
+ /** Partitioning strategy for the changelog table. */
71
+ partitioning?: ChangeTrackerConfig["partitioning"];
72
+ /** Clustering columns (max 4). */
73
+ clustering?: string[] | null;
74
+ /** Materialized-view max staleness interval, e.g. `0-0 0 4:0:0`. */
75
+ maxStaleness?: ConfigValue<string>;
76
+ /** Incremental materialized-view refresh interval in minutes. */
77
+ refreshIntervalMinutes?: ConfigValue<number>;
78
+
79
+ /** Collection id used for the changelog backup table. */
80
+ backupCollectionId?: ConfigValue<string>;
81
+ /** Name of a transform function to apply before writing. */
82
+ transformFunction?: ConfigValue<string>;
83
+ /** Customer-managed encryption key for the dataset. */
84
+ kmsKeyName?: ConfigValue<string>;
85
+
86
+ /** Log verbosity. Defaults to `info`. */
87
+ logLevel?: ConfigValue<TrackerLogLevel | LogLevel>;
88
+ }
89
+
90
+ /** {@link ExportConfig} with all defaults applied. */
91
+ export interface ResolvedExportConfig {
92
+ collectionPath: string;
93
+ datasetId: string;
94
+ tableId: string;
95
+ location: string;
96
+ datasetLocation: string;
97
+ bqProjectId?: string;
98
+ projectId: string;
99
+ databaseId: string;
100
+ wildcardIds: boolean;
101
+ excludeOldData: boolean;
102
+ useNewSnapshotQuerySyntax: boolean;
103
+ viewType: ViewType;
104
+ partitioning?: ChangeTrackerConfig["partitioning"];
105
+ clustering: string[] | null;
106
+ maxStaleness?: string;
107
+ refreshIntervalMinutes?: number;
108
+ backupCollectionId?: string;
109
+ transformFunction?: string;
110
+ kmsKeyName?: string;
111
+ logLevel: TrackerLogLevel;
112
+ }
113
+
114
+ function isExpression<T extends string | number | boolean | string[]>(
115
+ value: ConfigValue<T>
116
+ ): value is Expression<T> {
117
+ return typeof value === "object" && value !== null && "value" in value;
118
+ }
119
+
120
+ function resolveConfigValue<T extends string | number | boolean | string[]>(
121
+ value: ConfigValue<T>
122
+ ): T {
123
+ return isExpression(value) ? value.value() : value;
124
+ }
125
+
126
+ function resolveOptionalConfigValue<
127
+ T extends string | number | boolean | string[]
128
+ >(value: ConfigValue<T> | undefined): T | undefined {
129
+ return value === undefined ? undefined : resolveConfigValue(value);
130
+ }
131
+
132
+ /**
133
+ * Applies defaults to an {@link ExportConfig}.
134
+ *
135
+ * @param config - The user-supplied configuration.
136
+ * @returns The configuration with every field populated.
137
+ */
138
+ export function resolveExportConfig(
139
+ config: ExportConfig
140
+ ): ResolvedExportConfig {
141
+ const projectId = resolveConfigValue(config.projectId);
142
+ const viewType = resolveOptionalConfigValue(config.viewType);
143
+ const logLevel = resolveOptionalConfigValue(config.logLevel);
144
+
145
+ return {
146
+ collectionPath: resolveConfigValue(config.collectionPath),
147
+ datasetId: resolveConfigValue(config.datasetId),
148
+ tableId: resolveConfigValue(config.tableId),
149
+ location: resolveConfigValue(config.location),
150
+ datasetLocation: resolveOptionalConfigValue(config.datasetLocation) ?? "us",
151
+ bqProjectId: resolveOptionalConfigValue(config.bqProjectId),
152
+ projectId,
153
+ databaseId: resolveOptionalConfigValue(config.databaseId) ?? "(default)",
154
+ wildcardIds: resolveOptionalConfigValue(config.wildcardIds) ?? false,
155
+ excludeOldData: resolveOptionalConfigValue(config.excludeOldData) ?? false,
156
+ useNewSnapshotQuerySyntax:
157
+ resolveOptionalConfigValue(config.useNewSnapshotQuerySyntax) ?? false,
158
+ viewType: viewType ?? "view",
159
+ partitioning: config.partitioning,
160
+ clustering: config.clustering ?? null,
161
+ maxStaleness: resolveOptionalConfigValue(config.maxStaleness),
162
+ refreshIntervalMinutes: resolveOptionalConfigValue(
163
+ config.refreshIntervalMinutes
164
+ ),
165
+ backupCollectionId: resolveOptionalConfigValue(config.backupCollectionId),
166
+ transformFunction: resolveOptionalConfigValue(config.transformFunction),
167
+ kmsKeyName: resolveOptionalConfigValue(config.kmsKeyName),
168
+ logLevel: (logLevel as TrackerLogLevel) ?? "info",
169
+ };
170
+ }
171
+
172
+ /**
173
+ * Maps a resolved export config onto the change-tracker's config shape.
174
+ *
175
+ * @param config - The resolved export configuration.
176
+ * @returns The {@link ChangeTrackerConfig} for the event history tracker.
177
+ */
178
+ export function toTrackerConfig(
179
+ config: ResolvedExportConfig
180
+ ): ChangeTrackerConfig {
181
+ return {
182
+ firestoreInstanceId: config.databaseId,
183
+ tableId: config.tableId,
184
+ datasetId: config.datasetId,
185
+ datasetLocation: config.datasetLocation,
186
+ backupTableId: config.backupCollectionId,
187
+ transformFunction: config.transformFunction,
188
+ partitioning: config.partitioning,
189
+ databaseId: config.databaseId,
190
+ clustering: config.clustering,
191
+ wildcardIds: config.wildcardIds,
192
+ bqProjectId: config.bqProjectId ?? config.projectId,
193
+ useNewSnapshotQuerySyntax: config.useNewSnapshotQuerySyntax,
194
+ skipInit: true,
195
+ kmsKeyName: config.kmsKeyName,
196
+ useMaterializedView:
197
+ config.viewType === "materialized_incremental" ||
198
+ config.viewType === "materialized_non_incremental",
199
+ useIncrementalMaterializedView:
200
+ config.viewType === "materialized_incremental",
201
+ maxStaleness: config.maxStaleness,
202
+ refreshIntervalMinutes: config.refreshIntervalMinutes,
203
+ logLevel: config.logLevel,
204
+ };
205
+ }
@@ -0,0 +1,211 @@
1
+ /*
2
+ * Copyright 2019 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import {
18
+ ChangeType,
19
+ type FirestoreBigQueryEventHistoryTracker,
20
+ type FirestoreDocumentChangeEvent,
21
+ } from "@firebaseextensions/firestore-bigquery-change-tracker";
22
+ import type {
23
+ Change,
24
+ DocumentSnapshot,
25
+ FirestoreEvent,
26
+ } from "firebase-functions/firestore";
27
+ import * as events from "./events";
28
+ import type { ResolvedExportConfig } from "./export-config";
29
+ import * as logs from "./logs";
30
+ import { getChangeType, getDocumentId } from "./util";
31
+
32
+ /** Serialized Firestore change ready to write to BigQuery. */
33
+ interface SerializedDocumentChange {
34
+ timestamp: string;
35
+ eventId: string;
36
+ fullResourceName: string;
37
+ changeType: ChangeType;
38
+ documentId: string;
39
+ params: FirestoreDocumentChangeEvent["pathParams"] | null;
40
+ data: FirestoreDocumentChangeEvent["data"];
41
+ oldData: FirestoreDocumentChangeEvent["oldData"];
42
+ }
43
+
44
+ /** The Firestore document-write event passed to {@link handleDocumentWrite}. */
45
+ export type DocumentWriteEvent = FirestoreEvent<
46
+ Change<DocumentSnapshot> | undefined,
47
+ Record<string, string>
48
+ >;
49
+
50
+ /**
51
+ * Everything a handler needs to do its work, injected by the caller so the
52
+ * handlers stay free of global state.
53
+ */
54
+ export interface HandlerContext {
55
+ tracker: FirestoreBigQueryEventHistoryTracker;
56
+ config: ResolvedExportConfig;
57
+ /**
58
+ * Provisions the BigQuery dataset/table/views once per instance. Only called
59
+ * after an inline write failure as a self-heal; the hot path relies on
60
+ * out-of-band provisioning (`initBigQuerySync` / `setupBigQuerySync`).
61
+ */
62
+ ensureInitialized: () => Promise<void>;
63
+ }
64
+
65
+ /**
66
+ * Records a Firestore document change to BigQuery.
67
+ *
68
+ * @param change - Serialized change metadata and payload.
69
+ * @param tracker - The event history tracker to write through.
70
+ */
71
+ async function recordEventToBigQuery(
72
+ change: SerializedDocumentChange,
73
+ tracker: FirestoreBigQueryEventHistoryTracker
74
+ ): Promise<void> {
75
+ const event: FirestoreDocumentChangeEvent = {
76
+ timestamp: change.timestamp,
77
+ operation: change.changeType,
78
+ documentName: change.fullResourceName,
79
+ documentId: change.documentId,
80
+ pathParams: change.params,
81
+ eventId: change.eventId,
82
+ data: change.data,
83
+ oldData: change.oldData,
84
+ };
85
+
86
+ await tracker.record([event]);
87
+ }
88
+
89
+ /**
90
+ * Gives a failed inline write one self-heal attempt before surfacing it to the
91
+ * Firestore trigger retry policy.
92
+ *
93
+ * @param change - The serialized change to write.
94
+ * @param ctx - The handler context.
95
+ */
96
+ async function retryAfterSelfHeal(
97
+ change: SerializedDocumentChange,
98
+ ctx: HandlerContext
99
+ ): Promise<void> {
100
+ try {
101
+ await ctx.ensureInitialized();
102
+ await recordEventToBigQuery(change, ctx.tracker);
103
+ } catch (retryErr) {
104
+ await events.recordErrorEvent(retryErr as Error);
105
+
106
+ logs.logFailedEventAction(
107
+ "Failed to write event to BigQuery from onWrite handler after self-heal",
108
+ change.fullResourceName,
109
+ change.eventId,
110
+ change.changeType,
111
+ retryErr as Error
112
+ );
113
+
114
+ throw retryErr;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Handles a Firestore document write: serializes the change and writes it to
120
+ * BigQuery. Failed writes are surfaced to the trigger retry policy after one
121
+ * self-heal attempt.
122
+ *
123
+ * @param event - The Firestore document-write event.
124
+ * @param ctx - The handler context.
125
+ */
126
+ export async function handleDocumentWrite(
127
+ event: DocumentWriteEvent,
128
+ ctx: HandlerContext
129
+ ): Promise<void> {
130
+ const { data, ...context } = event;
131
+ if (!data) return;
132
+
133
+ logs.start();
134
+
135
+ // No provisioning on the hot path: BigQuery resources are provisioned
136
+ // out-of-band (afterFirstDeploy / afterRedeploy tasks). If they are missing,
137
+ // the inline write fails, self-heals once, then falls back to the trigger
138
+ // retry policy.
139
+ const { config, tracker } = ctx;
140
+ const changeType = getChangeType(data);
141
+ const documentId = getDocumentId(data);
142
+ const isCreated = changeType === ChangeType.CREATE;
143
+ const isDeleted = changeType === ChangeType.DELETE;
144
+
145
+ const newData = isDeleted ? undefined : data.after.data();
146
+ const oldData =
147
+ isCreated || config.excludeOldData ? undefined : data.before.data();
148
+
149
+ const relativeName = context.document;
150
+ const projectId = config.projectId;
151
+ const fullResourceName = `projects/${projectId}/databases/${config.databaseId}/documents/${relativeName}`;
152
+ const eventId = context.id;
153
+ const operation = changeType;
154
+
155
+ logs.logEventAction(
156
+ "Firestore event received by onDocumentWritten trigger",
157
+ fullResourceName,
158
+ eventId,
159
+ operation
160
+ );
161
+
162
+ let serializedData: FirestoreDocumentChangeEvent["data"];
163
+ let serializedOldData: FirestoreDocumentChangeEvent["oldData"];
164
+
165
+ try {
166
+ serializedData = tracker.serializeData(newData);
167
+ serializedOldData = tracker.serializeData(oldData);
168
+ } catch (err) {
169
+ logs.logFailedEventAction(
170
+ "Failed to serialize data",
171
+ fullResourceName,
172
+ eventId,
173
+ operation,
174
+ err as Error
175
+ );
176
+ throw err;
177
+ }
178
+
179
+ try {
180
+ await events.recordStartEvent({
181
+ documentId,
182
+ changeType,
183
+ before: { data: data.before.data() },
184
+ after: { data: data.after.data() },
185
+ context,
186
+ });
187
+ } catch (err) {
188
+ logs.error(false, "Failed to record start event", err);
189
+ throw err;
190
+ }
191
+
192
+ const change: SerializedDocumentChange = {
193
+ timestamp: context.time,
194
+ eventId: context.id,
195
+ fullResourceName,
196
+ changeType,
197
+ documentId,
198
+ params: config.wildcardIds ? { ...context.params, documentId } : null,
199
+ data: serializedData,
200
+ oldData: serializedOldData,
201
+ };
202
+
203
+ try {
204
+ await recordEventToBigQuery(change, tracker);
205
+ } catch (err) {
206
+ logs.failedToWriteToBigQueryImmediately(err as Error);
207
+ await retryAfterSelfHeal(change, ctx);
208
+ }
209
+
210
+ logs.complete();
211
+ }