@firebase-function-kits/firestore-bigquery-export 0.0.1 → 0.0.2-rc.0
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.
- package/CHANGELOG.md +1 -0
- package/README.md +234 -0
- package/lib/config.d.ts +33 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +345 -0
- package/lib/config.js.map +1 -0
- package/lib/events.d.ts +45 -0
- package/lib/events.d.ts.map +1 -0
- package/lib/events.js +154 -0
- package/lib/events.js.map +1 -0
- package/lib/export-config.d.ts +96 -0
- package/lib/export-config.d.ts.map +1 -0
- package/lib/export-config.js +77 -0
- package/lib/export-config.js.map +1 -0
- package/lib/handlers.d.ts +29 -0
- package/lib/handlers.d.ts.map +1 -0
- package/lib/handlers.js +165 -0
- package/lib/handlers.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +179 -0
- package/lib/index.js.map +1 -0
- package/lib/init.d.ts +16 -0
- package/lib/init.d.ts.map +1 -0
- package/lib/init.js +44 -0
- package/lib/init.js.map +1 -0
- package/lib/lib.d.ts +20 -0
- package/lib/lib.d.ts.map +1 -0
- package/lib/lib.js +47 -0
- package/lib/lib.js.map +1 -0
- package/lib/logs.d.ts +39 -0
- package/lib/logs.d.ts.map +1 -0
- package/lib/logs.js +186 -0
- package/lib/logs.js.map +1 -0
- package/lib/util.d.ts +23 -0
- package/lib/util.d.ts.map +1 -0
- package/lib/util.js +66 -0
- package/lib/util.js.map +1 -0
- package/package.json +33 -3
- package/src/config.ts +420 -0
- package/src/events.ts +146 -0
- package/src/export-config.ts +205 -0
- package/src/handlers.ts +211 -0
- package/src/index.ts +174 -0
- package/src/init.ts +45 -0
- package/src/lib.ts +55 -0
- package/src/logs.ts +233 -0
- package/src/util.ts +64 -0
- package/tests/config.test.ts +182 -0
- package/tests/events.test.ts +84 -0
- package/tests/export-config.test.ts +114 -0
- package/tests/handlers.test.ts +220 -0
- package/tests/init.test.ts +76 -0
- package/tests/util.test.ts +102 -0
- package/tsconfig.json +18 -0
- package/tsconfig.tsbuildinfo +1 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2019 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
51
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.setupBigQuerySync = exports.initBigQuerySync = exports.fsexportbigquery = void 0;
|
|
55
|
+
/**
|
|
56
|
+
* Main entry point. Exports the wired functions with deploy-time param
|
|
57
|
+
* expressions, then resolves concrete config lazily at runtime. Re-export
|
|
58
|
+
* `fsexportbigquery` and `initBigQuerySync` from your own functions codebase
|
|
59
|
+
* entry; configuration comes from a `.env` (or
|
|
60
|
+
* `.env.<projectId>`), which the Firebase CLI loads at deploy.
|
|
61
|
+
*
|
|
62
|
+
* Because this module initializes runtime dependencies lazily, deploy discovery
|
|
63
|
+
* can analyze it without resolving params too early.
|
|
64
|
+
* For side-effect-free imports (the handlers and config types), import from
|
|
65
|
+
* `./lib` instead.
|
|
66
|
+
*/
|
|
67
|
+
const firestore_bigquery_change_tracker_1 = require("@firebaseextensions/firestore-bigquery-change-tracker");
|
|
68
|
+
const app_1 = require("firebase-admin/app");
|
|
69
|
+
const firestore_1 = require("firebase-functions/firestore");
|
|
70
|
+
const params_1 = require("firebase-functions/params");
|
|
71
|
+
const tasks_1 = require("firebase-functions/tasks");
|
|
72
|
+
const v2_1 = require("firebase-functions/v2");
|
|
73
|
+
const lifecycle_1 = require("firebase-functions/v2/lifecycle");
|
|
74
|
+
const config_1 = require("./config");
|
|
75
|
+
const events = __importStar(require("./events"));
|
|
76
|
+
const export_config_1 = require("./export-config");
|
|
77
|
+
const handlers_1 = require("./handlers");
|
|
78
|
+
const init_1 = require("./init");
|
|
79
|
+
const logs = __importStar(require("./logs"));
|
|
80
|
+
// Re-export the side-effect-free library surface (handlers and config types).
|
|
81
|
+
__exportStar(require("./lib"), exports);
|
|
82
|
+
const INIT_BIGQUERY_SYNC_FUNCTION = "initBigQuerySync";
|
|
83
|
+
const SETUP_BIGQUERY_SYNC_FUNCTION = "setupBigQuerySync";
|
|
84
|
+
const LIFECYCLE_RETRY_CONFIG = {
|
|
85
|
+
maxAttempts: 15,
|
|
86
|
+
minBackoffSeconds: 60,
|
|
87
|
+
};
|
|
88
|
+
const REQUIRED_ROLES = [
|
|
89
|
+
"roles/bigquery.dataEditor",
|
|
90
|
+
"roles/datastore.user",
|
|
91
|
+
"roles/bigquery.user",
|
|
92
|
+
// Gen2 Firestore triggers need Eventarc receive and run.invoker on the function SA.
|
|
93
|
+
"roles/eventarc.eventReceiver",
|
|
94
|
+
"roles/run.invoker",
|
|
95
|
+
];
|
|
96
|
+
const REQUIRED_APIS = [
|
|
97
|
+
{
|
|
98
|
+
api: "bigquery.googleapis.com",
|
|
99
|
+
reason: "Mirrors data from your Cloud Firestore collection in BigQuery.",
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
for (const role of REQUIRED_ROLES) {
|
|
103
|
+
(0, v2_1.requiresRole)(role);
|
|
104
|
+
}
|
|
105
|
+
for (const { api, reason } of REQUIRED_APIS) {
|
|
106
|
+
(0, v2_1.requiresAPI)(api, reason);
|
|
107
|
+
}
|
|
108
|
+
(0, lifecycle_1.afterFirstDeploy)({
|
|
109
|
+
task: { function: INIT_BIGQUERY_SYNC_FUNCTION, body: { data: {} } },
|
|
110
|
+
});
|
|
111
|
+
(0, lifecycle_1.afterRedeploy)({
|
|
112
|
+
task: { function: SETUP_BIGQUERY_SYNC_FUNCTION, body: { data: {} } },
|
|
113
|
+
});
|
|
114
|
+
let ctx;
|
|
115
|
+
function getHandlerContext() {
|
|
116
|
+
if (ctx) {
|
|
117
|
+
return ctx;
|
|
118
|
+
}
|
|
119
|
+
const config = (0, export_config_1.resolveExportConfig)((0, config_1.configFromEnv)());
|
|
120
|
+
const tracker = new firestore_bigquery_change_tracker_1.FirestoreBigQueryEventHistoryTracker((0, export_config_1.toTrackerConfig)(config));
|
|
121
|
+
logs.logger.setLogLevel(config.logLevel);
|
|
122
|
+
logs.init(config);
|
|
123
|
+
if ((0, app_1.getApps)().length === 0) {
|
|
124
|
+
(0, app_1.initializeApp)();
|
|
125
|
+
}
|
|
126
|
+
events.setupEventChannel();
|
|
127
|
+
const ensureInitialized = (0, init_1.createEnsureInitialized)(tracker);
|
|
128
|
+
ctx = {
|
|
129
|
+
tracker,
|
|
130
|
+
config,
|
|
131
|
+
ensureInitialized,
|
|
132
|
+
};
|
|
133
|
+
return ctx;
|
|
134
|
+
}
|
|
135
|
+
const functionOptions = {
|
|
136
|
+
region: config_1.CONFIG_EXPRESSIONS.location,
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Firestore trigger: streams document writes on the watched collection into the
|
|
140
|
+
* BigQuery changelog table. Failed executions are retried by the Firebase
|
|
141
|
+
* Functions runtime.
|
|
142
|
+
*/
|
|
143
|
+
exports.fsexportbigquery = (0, firestore_1.onDocumentWritten)({
|
|
144
|
+
...functionOptions,
|
|
145
|
+
document: (0, params_1.expr) `${config_1.CONFIG_EXPRESSIONS.collectionPath}/{documentId}`,
|
|
146
|
+
database: config_1.CONFIG_EXPRESSIONS.database,
|
|
147
|
+
retry: true,
|
|
148
|
+
}, (event) => (0, handlers_1.handleDocumentWrite)(event, getHandlerContext()));
|
|
149
|
+
async function handleBigQuerySyncInitialization() {
|
|
150
|
+
try {
|
|
151
|
+
await getHandlerContext().ensureInitialized();
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
logs.error(false, "Failed to initialize BigQuery resources", err);
|
|
155
|
+
throw err;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* First-deploy provisioning task (`afterFirstDeploy`). Runs in the function's
|
|
160
|
+
* own identity, so it has the runtime service account and bound secrets that
|
|
161
|
+
* creating the dataset/table/views needs (e.g. CMEK). Cloud Tasks retries a
|
|
162
|
+
* failed initialization on its own schedule, so a transient BigQuery error does
|
|
163
|
+
* not leave the resources unprovisioned. It is idempotent (`initialize()`
|
|
164
|
+
* no-ops when resources already exist) and can also be invoked directly as an
|
|
165
|
+
* authenticated HTTP POST, without queue retries.
|
|
166
|
+
*/
|
|
167
|
+
exports.initBigQuerySync = (0, tasks_1.onTaskDispatched)({
|
|
168
|
+
...functionOptions,
|
|
169
|
+
retryConfig: LIFECYCLE_RETRY_CONFIG,
|
|
170
|
+
}, handleBigQuerySyncInitialization);
|
|
171
|
+
/**
|
|
172
|
+
* Update/configure lifecycle task. Uses the same idempotent provisioning path
|
|
173
|
+
* so BigQuery resources are reconciled after parameter changes.
|
|
174
|
+
*/
|
|
175
|
+
exports.setupBigQuerySync = (0, tasks_1.onTaskDispatched)({
|
|
176
|
+
...functionOptions,
|
|
177
|
+
retryConfig: LIFECYCLE_RETRY_CONFIG,
|
|
178
|
+
}, handleBigQuerySyncInitialization);
|
|
179
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH;;;;;;;;;;;GAWG;AAEH,6GAA6G;AAC7G,4CAA4D;AAC5D,4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GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACU,QAAA,gBAAgB,GAAG,IAAA,wBAAgB,EAC9C;IACE,GAAG,eAAe;IAClB,WAAW,EAAE,sBAAsB;CACpC,EACD,gCAAgC,CACjC,CAAC;AAEF;;;GAGG;AACU,QAAA,iBAAiB,GAAG,IAAA,wBAAgB,EAC/C;IACE,GAAG,eAAe;IAClB,WAAW,EAAE,sBAAsB;CACpC,EACD,gCAAgC,CACjC,CAAC"}
|
package/lib/init.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FirestoreBigQueryEventHistoryTracker } from "@firebaseextensions/firestore-bigquery-change-tracker";
|
|
2
|
+
/**
|
|
3
|
+
* Builds the provisioning guard used by the `initBigQuerySync` endpoint and the
|
|
4
|
+
* retry-path self-heal. The hot write path never calls it.
|
|
5
|
+
*
|
|
6
|
+
* The returned function runs `tracker.initialize()` at most once per instance:
|
|
7
|
+
* concurrent invocations on a cold instance share a single in-flight promise. A
|
|
8
|
+
* failed initialization resets the guard so a later invocation can retry after
|
|
9
|
+
* a transient error.
|
|
10
|
+
*
|
|
11
|
+
* @param tracker - The event history tracker whose `initialize()` provisions
|
|
12
|
+
* the BigQuery dataset, table, and views.
|
|
13
|
+
* @returns A function that resolves once the resources are provisioned.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createEnsureInitialized(tracker: FirestoreBigQueryEventHistoryTracker): () => Promise<void>;
|
|
16
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,uDAAuD,CAAC;AAElH;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,oCAAoC,GAC5C,MAAM,OAAO,CAAC,IAAI,CAAC,CAWrB"}
|
package/lib/init.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2019 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.createEnsureInitialized = createEnsureInitialized;
|
|
19
|
+
/**
|
|
20
|
+
* Builds the provisioning guard used by the `initBigQuerySync` endpoint and the
|
|
21
|
+
* retry-path self-heal. The hot write path never calls it.
|
|
22
|
+
*
|
|
23
|
+
* The returned function runs `tracker.initialize()` at most once per instance:
|
|
24
|
+
* concurrent invocations on a cold instance share a single in-flight promise. A
|
|
25
|
+
* failed initialization resets the guard so a later invocation can retry after
|
|
26
|
+
* a transient error.
|
|
27
|
+
*
|
|
28
|
+
* @param tracker - The event history tracker whose `initialize()` provisions
|
|
29
|
+
* the BigQuery dataset, table, and views.
|
|
30
|
+
* @returns A function that resolves once the resources are provisioned.
|
|
31
|
+
*/
|
|
32
|
+
function createEnsureInitialized(tracker) {
|
|
33
|
+
let initialization = null;
|
|
34
|
+
return () => {
|
|
35
|
+
if (!initialization) {
|
|
36
|
+
initialization = tracker.initialize().catch((err) => {
|
|
37
|
+
initialization = null;
|
|
38
|
+
throw err;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return initialization;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=init.js.map
|
package/lib/init.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH;;;;;;;;;;;;GAYG;AACH,iCACE,OAA6C;IAE7C,IAAI,cAAc,GAAyB,IAAI,CAAC;IAChD,OAAO,GAAG,EAAE;QACV,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,cAAc,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAClD,cAAc,GAAG,IAAI,CAAC;gBACtB,MAAM,GAAG,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/lib.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side-effect-free library surface:
|
|
3
|
+
*
|
|
4
|
+
* - {@link handleDocumentWrite} — the handler, for consumers who want to own
|
|
5
|
+
* trigger registration themselves. It takes an injected
|
|
6
|
+
* {@link HandlerContext}.
|
|
7
|
+
* - Config types and helpers ({@link ExportConfig}, {@link resolveExportConfig},
|
|
8
|
+
* {@link toTrackerConfig}) for building that context.
|
|
9
|
+
*
|
|
10
|
+
* Importing this module has no side effects (it reads no environment), so it is
|
|
11
|
+
* safe to import anywhere. The main entry point (`./index`) is the one that
|
|
12
|
+
* reads env params and exports the wired functions.
|
|
13
|
+
*
|
|
14
|
+
* The change-tracker engine is an internal dependency and is deliberately not
|
|
15
|
+
* re-exported; only the types the handler signatures need are surfaced.
|
|
16
|
+
*/
|
|
17
|
+
export { type ChangeTrackerConfig, ChangeType, type FirestoreBigQueryEventHistoryTracker, } from "@firebaseextensions/firestore-bigquery-change-tracker";
|
|
18
|
+
export { type ExportConfig, type ResolvedExportConfig, resolveExportConfig, toTrackerConfig, type ViewType, } from "./export-config";
|
|
19
|
+
export { type DocumentWriteEvent, type HandlerContext, handleDocumentWrite, } from "./handlers";
|
|
20
|
+
//# sourceMappingURL=lib.d.ts.map
|
package/lib/lib.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,EACL,KAAK,mBAAmB,EACxB,UAAU,EACV,KAAK,oCAAoC,GAC1C,MAAM,uDAAuD,CAAC;AAE/D,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,mBAAmB,EACnB,eAAe,EACf,KAAK,QAAQ,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
package/lib/lib.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2019 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.handleDocumentWrite = exports.toTrackerConfig = exports.resolveExportConfig = exports.ChangeType = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* Side-effect-free library surface:
|
|
21
|
+
*
|
|
22
|
+
* - {@link handleDocumentWrite} — the handler, for consumers who want to own
|
|
23
|
+
* trigger registration themselves. It takes an injected
|
|
24
|
+
* {@link HandlerContext}.
|
|
25
|
+
* - Config types and helpers ({@link ExportConfig}, {@link resolveExportConfig},
|
|
26
|
+
* {@link toTrackerConfig}) for building that context.
|
|
27
|
+
*
|
|
28
|
+
* Importing this module has no side effects (it reads no environment), so it is
|
|
29
|
+
* safe to import anywhere. The main entry point (`./index`) is the one that
|
|
30
|
+
* reads env params and exports the wired functions.
|
|
31
|
+
*
|
|
32
|
+
* The change-tracker engine is an internal dependency and is deliberately not
|
|
33
|
+
* re-exported; only the types the handler signatures need are surfaced.
|
|
34
|
+
*/
|
|
35
|
+
// Engine types referenced by the handler and config signatures. Type-only —
|
|
36
|
+
// the engine itself is internal. `ChangeType` is exported for handler tests and
|
|
37
|
+
// advanced consumers that build Firestore events directly.
|
|
38
|
+
var firestore_bigquery_change_tracker_1 = require("@firebaseextensions/firestore-bigquery-change-tracker");
|
|
39
|
+
Object.defineProperty(exports, "ChangeType", { enumerable: true, get: function () { return firestore_bigquery_change_tracker_1.ChangeType; } });
|
|
40
|
+
// Config types and helpers
|
|
41
|
+
var export_config_1 = require("./export-config");
|
|
42
|
+
Object.defineProperty(exports, "resolveExportConfig", { enumerable: true, get: function () { return export_config_1.resolveExportConfig; } });
|
|
43
|
+
Object.defineProperty(exports, "toTrackerConfig", { enumerable: true, get: function () { return export_config_1.toTrackerConfig; } });
|
|
44
|
+
// Handlers
|
|
45
|
+
var handlers_1 = require("./handlers");
|
|
46
|
+
Object.defineProperty(exports, "handleDocumentWrite", { enumerable: true, get: function () { return handlers_1.handleDocumentWrite; } });
|
|
47
|
+
//# sourceMappingURL=lib.js.map
|
package/lib/lib.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;;;;;;;;;;;;GAeG;AAEH,4EAA4E;AAC5E,gFAAgF;AAChF,2DAA2D;AAC3D,2GAI+D;AAF7D,+HAAA,UAAU,OAAA;AAGZ,2BAA2B;AAC3B,iDAMyB;AAHvB,oHAAA,mBAAmB,OAAA;AACnB,gHAAA,eAAe,OAAA;AAGjB,WAAW;AACX,uCAIoB;AADlB,+GAAA,mBAAmB,OAAA"}
|
package/lib/logs.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ChangeType, Logger } from "@firebaseextensions/firestore-bigquery-change-tracker";
|
|
2
|
+
export declare const logger: Logger;
|
|
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 bigQueryTableAlreadyExists: (tableName: string, datasetName: string) => void;
|
|
10
|
+
export declare const bigQueryTableCreated: (tableName: string) => void;
|
|
11
|
+
export declare const bigQueryTableCreating: (tableName: string) => void;
|
|
12
|
+
export declare const bigQueryTableUpdated: (tableName: string) => void;
|
|
13
|
+
export declare const bigQueryTableUpdating: (tableName: string) => void;
|
|
14
|
+
export declare const bigQueryTableUpToDate: (tableName: string) => void;
|
|
15
|
+
export declare const bigQueryTableValidated: (tableName: string) => void;
|
|
16
|
+
export declare const bigQueryTableValidating: (tableName: string) => void;
|
|
17
|
+
export declare const bigQueryUserDefinedFunctionCreating: (functionDefinition: string) => void;
|
|
18
|
+
export declare const bigQueryUserDefinedFunctionCreated: (functionDefinition: string) => void;
|
|
19
|
+
export declare const bigQueryViewCreated: (viewName: string) => void;
|
|
20
|
+
export declare const bigQueryViewCreating: (viewName: string) => void;
|
|
21
|
+
export declare const bigQueryViewAlreadyExists: (viewName: string, datasetName: string) => void;
|
|
22
|
+
export declare const bigQueryViewUpdated: (viewName: string) => void;
|
|
23
|
+
export declare const bigQueryViewUpdating: (viewName: string) => void;
|
|
24
|
+
export declare const bigQueryViewUpToDate: (viewName: string) => void;
|
|
25
|
+
export declare const bigQueryViewValidated: (viewName: string) => void;
|
|
26
|
+
export declare const bigQueryViewValidating: (viewName: string) => void;
|
|
27
|
+
export declare const complete: () => void;
|
|
28
|
+
export declare const dataInserted: (rowCount: number) => void;
|
|
29
|
+
export declare const dataInserting: (rowCount: number) => void;
|
|
30
|
+
export declare const dataTypeInvalid: (fieldName: string, fieldType: string, dataType: string) => void;
|
|
31
|
+
export declare const error: (includeEvent: boolean, message: string, err: Error, event?: any, // Made optional, as it is not always required
|
|
32
|
+
eventTrackerConfig?: any) => void;
|
|
33
|
+
export declare const init: (config?: unknown) => void;
|
|
34
|
+
export declare const start: (config?: unknown) => void;
|
|
35
|
+
export declare const timestampMissingValue: (fieldName: string) => void;
|
|
36
|
+
export declare const logEventAction: (action: string, document_name: string, event_id: string, operation: ChangeType) => void;
|
|
37
|
+
export declare const logFailedEventAction: (action: string, document_name: string, event_id: string, operation: ChangeType, error: Error) => void;
|
|
38
|
+
export declare const failedToWriteToBigQueryImmediately: (error: Error) => void;
|
|
39
|
+
//# sourceMappingURL=logs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../src/logs.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,KAAK,UAAU,EACf,MAAM,EACP,MAAM,uDAAuD,CAAC;AAE/D,eAAO,MAAM,MAAM,QAAe,CAAC;AAEnC,eAAO,MAAM,iBAAiB,cAAe,MAAM,SAElD,CAAC;AAEF,eAAO,MAAM,sBAAsB,cAAe,MAAM,SAEvD,CAAC;AAEF,eAAO,MAAM,uBAAuB,cAAe,MAAM,SA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aAAc,MAAM,SAE7C,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,MAAM,aACN,MAAM,YACP,MAAM,SAKjB,CAAC;AAEF,eAAO,MAAM,KAAK,iBACF,OAAO,WACZ,MAAM,OACV,KAAK,UACF,GAAG,EAAE,8CAA8C;qBACtC,GAAG,SAazB,CAAC;AAEF,eAAO,MAAM,IAAI,YAAa,OAAO,SAEpC,CAAC;AAEF,eAAO,MAAM,KAAK,YAAa,OAAO,SAErC,CAAC;AAEF,eAAO,MAAM,qBAAqB,cAAe,MAAM,SAItD,CAAC;AAEF,eAAO,MAAM,cAAc,WACjB,MAAM,iBACC,MAAM,YACX,MAAM,aACL,UAAU,SAOtB,CAAC;AAEF,eAAO,MAAM,oBAAoB,WACvB,MAAM,iBACC,MAAM,YACX,MAAM,aACL,UAAU,SACd,KAAK,SAeb,CAAC;AAEF,eAAO,MAAM,kCAAkC,UAAW,KAAK,SAK9D,CAAC"}
|
package/lib/logs.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2019 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.failedToWriteToBigQueryImmediately = exports.logFailedEventAction = exports.logEventAction = exports.timestampMissingValue = exports.start = exports.init = exports.error = exports.dataTypeInvalid = exports.dataInserting = exports.dataInserted = exports.complete = exports.bigQueryViewValidating = exports.bigQueryViewValidated = exports.bigQueryViewUpToDate = exports.bigQueryViewUpdating = exports.bigQueryViewUpdated = exports.bigQueryViewAlreadyExists = exports.bigQueryViewCreating = exports.bigQueryViewCreated = exports.bigQueryUserDefinedFunctionCreated = exports.bigQueryUserDefinedFunctionCreating = exports.bigQueryTableValidating = exports.bigQueryTableValidated = exports.bigQueryTableUpToDate = exports.bigQueryTableUpdating = exports.bigQueryTableUpdated = exports.bigQueryTableCreating = exports.bigQueryTableCreated = exports.bigQueryTableAlreadyExists = exports.bigQueryLatestSnapshotViewQueryCreated = exports.bigQueryErrorRecordingDocumentChange = exports.bigQueryDatasetExists = exports.bigQueryDatasetCreating = exports.bigQueryDatasetCreated = exports.arrayFieldInvalid = exports.logger = void 0;
|
|
19
|
+
const firestore_bigquery_change_tracker_1 = require("@firebaseextensions/firestore-bigquery-change-tracker");
|
|
20
|
+
exports.logger = new firestore_bigquery_change_tracker_1.Logger();
|
|
21
|
+
const arrayFieldInvalid = (fieldName) => {
|
|
22
|
+
exports.logger.warn(`Array field '${fieldName}' does not contain an array, skipping`);
|
|
23
|
+
};
|
|
24
|
+
exports.arrayFieldInvalid = arrayFieldInvalid;
|
|
25
|
+
const bigQueryDatasetCreated = (datasetId) => {
|
|
26
|
+
exports.logger.info(`Created BigQuery dataset: ${datasetId}`);
|
|
27
|
+
};
|
|
28
|
+
exports.bigQueryDatasetCreated = bigQueryDatasetCreated;
|
|
29
|
+
const bigQueryDatasetCreating = (datasetId) => {
|
|
30
|
+
exports.logger.debug(`Creating BigQuery dataset: ${datasetId}`);
|
|
31
|
+
};
|
|
32
|
+
exports.bigQueryDatasetCreating = bigQueryDatasetCreating;
|
|
33
|
+
const bigQueryDatasetExists = (datasetId) => {
|
|
34
|
+
exports.logger.info(`BigQuery dataset already exists: ${datasetId}`);
|
|
35
|
+
};
|
|
36
|
+
exports.bigQueryDatasetExists = bigQueryDatasetExists;
|
|
37
|
+
const bigQueryErrorRecordingDocumentChange = (e) => {
|
|
38
|
+
exports.logger.error(`Error recording document changes.`, e);
|
|
39
|
+
};
|
|
40
|
+
exports.bigQueryErrorRecordingDocumentChange = bigQueryErrorRecordingDocumentChange;
|
|
41
|
+
const bigQueryLatestSnapshotViewQueryCreated = (query) => {
|
|
42
|
+
exports.logger.info(`BigQuery latest snapshot view query:\n${query}`);
|
|
43
|
+
};
|
|
44
|
+
exports.bigQueryLatestSnapshotViewQueryCreated = bigQueryLatestSnapshotViewQueryCreated;
|
|
45
|
+
const bigQueryTableAlreadyExists = (tableName, datasetName) => {
|
|
46
|
+
exports.logger.info(`BigQuery table with name ${tableName} already ` +
|
|
47
|
+
`exists in dataset ${datasetName}!`);
|
|
48
|
+
};
|
|
49
|
+
exports.bigQueryTableAlreadyExists = bigQueryTableAlreadyExists;
|
|
50
|
+
const bigQueryTableCreated = (tableName) => {
|
|
51
|
+
exports.logger.info(`Created BigQuery table: ${tableName}`);
|
|
52
|
+
};
|
|
53
|
+
exports.bigQueryTableCreated = bigQueryTableCreated;
|
|
54
|
+
const bigQueryTableCreating = (tableName) => {
|
|
55
|
+
exports.logger.debug(`Creating BigQuery table: ${tableName}`);
|
|
56
|
+
};
|
|
57
|
+
exports.bigQueryTableCreating = bigQueryTableCreating;
|
|
58
|
+
const bigQueryTableUpdated = (tableName) => {
|
|
59
|
+
exports.logger.info(`Updated existing BigQuery table: ${tableName}`);
|
|
60
|
+
};
|
|
61
|
+
exports.bigQueryTableUpdated = bigQueryTableUpdated;
|
|
62
|
+
const bigQueryTableUpdating = (tableName) => {
|
|
63
|
+
exports.logger.debug(`Updating existing BigQuery table: ${tableName}`);
|
|
64
|
+
};
|
|
65
|
+
exports.bigQueryTableUpdating = bigQueryTableUpdating;
|
|
66
|
+
const bigQueryTableUpToDate = (tableName) => {
|
|
67
|
+
exports.logger.info(`BigQuery table: ${tableName} is up to date`);
|
|
68
|
+
};
|
|
69
|
+
exports.bigQueryTableUpToDate = bigQueryTableUpToDate;
|
|
70
|
+
const bigQueryTableValidated = (tableName) => {
|
|
71
|
+
exports.logger.info(`Validated existing BigQuery table: ${tableName}`);
|
|
72
|
+
};
|
|
73
|
+
exports.bigQueryTableValidated = bigQueryTableValidated;
|
|
74
|
+
const bigQueryTableValidating = (tableName) => {
|
|
75
|
+
exports.logger.debug(`Validating existing BigQuery table: ${tableName}`);
|
|
76
|
+
};
|
|
77
|
+
exports.bigQueryTableValidating = bigQueryTableValidating;
|
|
78
|
+
const bigQueryUserDefinedFunctionCreating = (functionDefinition) => {
|
|
79
|
+
exports.logger.debug(`Creating BigQuery User-defined Function:\n${functionDefinition}`);
|
|
80
|
+
};
|
|
81
|
+
exports.bigQueryUserDefinedFunctionCreating = bigQueryUserDefinedFunctionCreating;
|
|
82
|
+
const bigQueryUserDefinedFunctionCreated = (functionDefinition) => {
|
|
83
|
+
exports.logger.info(`Created BigQuery User-defined Function:\n${functionDefinition}`);
|
|
84
|
+
};
|
|
85
|
+
exports.bigQueryUserDefinedFunctionCreated = bigQueryUserDefinedFunctionCreated;
|
|
86
|
+
const bigQueryViewCreated = (viewName) => {
|
|
87
|
+
exports.logger.info(`Created BigQuery view: ${viewName}`);
|
|
88
|
+
};
|
|
89
|
+
exports.bigQueryViewCreated = bigQueryViewCreated;
|
|
90
|
+
const bigQueryViewCreating = (viewName) => {
|
|
91
|
+
exports.logger.debug(`Creating BigQuery view: ${viewName}`);
|
|
92
|
+
};
|
|
93
|
+
exports.bigQueryViewCreating = bigQueryViewCreating;
|
|
94
|
+
const bigQueryViewAlreadyExists = (viewName, datasetName) => {
|
|
95
|
+
exports.logger.info(`View with id ${viewName} already exists in dataset ${datasetName}.`);
|
|
96
|
+
};
|
|
97
|
+
exports.bigQueryViewAlreadyExists = bigQueryViewAlreadyExists;
|
|
98
|
+
const bigQueryViewUpdated = (viewName) => {
|
|
99
|
+
exports.logger.info(`Updated existing BigQuery view: ${viewName}`);
|
|
100
|
+
};
|
|
101
|
+
exports.bigQueryViewUpdated = bigQueryViewUpdated;
|
|
102
|
+
const bigQueryViewUpdating = (viewName) => {
|
|
103
|
+
exports.logger.debug(`Updating existing BigQuery view: ${viewName}`);
|
|
104
|
+
};
|
|
105
|
+
exports.bigQueryViewUpdating = bigQueryViewUpdating;
|
|
106
|
+
const bigQueryViewUpToDate = (viewName) => {
|
|
107
|
+
exports.logger.info(`BigQuery view: ${viewName} is up to date`);
|
|
108
|
+
};
|
|
109
|
+
exports.bigQueryViewUpToDate = bigQueryViewUpToDate;
|
|
110
|
+
const bigQueryViewValidated = (viewName) => {
|
|
111
|
+
exports.logger.info(`Validated existing BigQuery view: ${viewName}`);
|
|
112
|
+
};
|
|
113
|
+
exports.bigQueryViewValidated = bigQueryViewValidated;
|
|
114
|
+
const bigQueryViewValidating = (viewName) => {
|
|
115
|
+
exports.logger.debug(`Validating existing BigQuery view: ${viewName}`);
|
|
116
|
+
};
|
|
117
|
+
exports.bigQueryViewValidating = bigQueryViewValidating;
|
|
118
|
+
const complete = () => {
|
|
119
|
+
exports.logger.info("Completed execution of extension");
|
|
120
|
+
};
|
|
121
|
+
exports.complete = complete;
|
|
122
|
+
const dataInserted = (rowCount) => {
|
|
123
|
+
exports.logger.debug(`Inserted ${rowCount} row(s) of data into BigQuery`);
|
|
124
|
+
};
|
|
125
|
+
exports.dataInserted = dataInserted;
|
|
126
|
+
const dataInserting = (rowCount) => {
|
|
127
|
+
exports.logger.debug(`Inserting ${rowCount} row(s) of data into BigQuery`);
|
|
128
|
+
};
|
|
129
|
+
exports.dataInserting = dataInserting;
|
|
130
|
+
const dataTypeInvalid = (fieldName, fieldType, dataType) => {
|
|
131
|
+
exports.logger.warn(`Field '${fieldName}' has invalid data. Expected: ${fieldType}, received: ${dataType}`);
|
|
132
|
+
};
|
|
133
|
+
exports.dataTypeInvalid = dataTypeInvalid;
|
|
134
|
+
const error = (includeEvent, message, err, event, // Made optional, as it is not always required
|
|
135
|
+
eventTrackerConfig // Made optional, as it is not always required
|
|
136
|
+
) => {
|
|
137
|
+
const logDetails = { error: err };
|
|
138
|
+
if (includeEvent && event) {
|
|
139
|
+
logDetails.event = event;
|
|
140
|
+
}
|
|
141
|
+
if (includeEvent && eventTrackerConfig) {
|
|
142
|
+
logDetails.eventTrackerConfig = eventTrackerConfig;
|
|
143
|
+
}
|
|
144
|
+
exports.logger.error(`Error when mirroring data to BigQuery: ${message}`, logDetails);
|
|
145
|
+
};
|
|
146
|
+
exports.error = error;
|
|
147
|
+
const init = (config) => {
|
|
148
|
+
exports.logger.info("Initializing with configuration", config);
|
|
149
|
+
};
|
|
150
|
+
exports.init = init;
|
|
151
|
+
const start = (config) => {
|
|
152
|
+
exports.logger.info("Started execution with configuration", config);
|
|
153
|
+
};
|
|
154
|
+
exports.start = start;
|
|
155
|
+
const timestampMissingValue = (fieldName) => {
|
|
156
|
+
exports.logger.warn(`Missing value for timestamp field: ${fieldName}, using default timestamp instead.`);
|
|
157
|
+
};
|
|
158
|
+
exports.timestampMissingValue = timestampMissingValue;
|
|
159
|
+
const logEventAction = (action, document_name, event_id, operation) => {
|
|
160
|
+
exports.logger.info(action, {
|
|
161
|
+
document_name,
|
|
162
|
+
event_id,
|
|
163
|
+
operation,
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
exports.logEventAction = logEventAction;
|
|
167
|
+
const logFailedEventAction = (action, document_name, event_id, operation, error) => {
|
|
168
|
+
const changeTypeMap = {
|
|
169
|
+
0: "CREATE",
|
|
170
|
+
1: "DELETE",
|
|
171
|
+
2: "UPDATE",
|
|
172
|
+
3: "IMPORT",
|
|
173
|
+
};
|
|
174
|
+
exports.logger.error(action, {
|
|
175
|
+
document_name,
|
|
176
|
+
event_id,
|
|
177
|
+
operation: changeTypeMap[operation],
|
|
178
|
+
error,
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
exports.logFailedEventAction = logFailedEventAction;
|
|
182
|
+
const failedToWriteToBigQueryImmediately = (error) => {
|
|
183
|
+
exports.logger.warn("Failed to write event to BigQuery Immediately. Will attempt to Enqueue to Cloud Tasks.", error);
|
|
184
|
+
};
|
|
185
|
+
exports.failedToWriteToBigQueryImmediately = failedToWriteToBigQueryImmediately;
|
|
186
|
+
//# sourceMappingURL=logs.js.map
|
package/lib/logs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs.js","sourceRoot":"","sources":["../src/logs.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6GAG+D;AAElD,QAAA,MAAM,GAAG,IAAI,0CAAM,EAAE,CAAC;AAE5B,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAE,EAAE;IACrD,QAAA,MAAM,CAAC,IAAI,CAAC,gBAAgB,SAAS,uCAAuC,CAAC,CAAC;AAChF,CAAC,CAAC;AAFW,QAAA,iBAAiB,GAAjB,iBAAiB,CAE5B;AAEK,MAAM,sBAAsB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC1D,QAAA,MAAM,CAAC,IAAI,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;AACxD,CAAC,CAAC;AAFW,QAAA,sBAAsB,GAAtB,sBAAsB,CAEjC;AAEK,MAAM,uBAAuB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC3D,QAAA,MAAM,CAAC,KAAK,CAAC,8BAA8B,SAAS,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,uBAAuB,GAAvB,uBAAuB,CAElC;AAEK,MAAM,qBAAqB,GAAG,CAAC,SAAiB,EAAE,EAAE;IACzD,QAAA,MAAM,CAAC,IAAI,CAAC,oCAAoC,SAAS,EAAE,CAAC,CAAC;AAC/D,CAAC,CAAC;AAFW,QAAA,qBAAqB,GAArB,qBAAqB,CAEhC;AAEK,MAAM,oCAAoC,GAAG,CAAC,CAAQ,EAAE,EAAE;IAC/D,QAAA,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE,CAAC,CAAC,CAAC;AACvD,CA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J,CAAC,CAAC;AALW,QAAA,kCAAkC,GAAlC,kCAAkC,CAK7C"}
|
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ChangeType } from "@firebaseextensions/firestore-bigquery-change-tracker";
|
|
2
|
+
import type { Change, DocumentSnapshot } from "firebase-functions/firestore";
|
|
3
|
+
/**
|
|
4
|
+
* Get the change type (CREATE, UPDATE, DELETE) from the Firestore change.
|
|
5
|
+
* @param change Firestore document change object.
|
|
6
|
+
* @returns {ChangeType} The type of change.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getChangeType(change: Change<DocumentSnapshot>): ChangeType;
|
|
9
|
+
/**
|
|
10
|
+
* Get the document ID from the Firestore change.
|
|
11
|
+
* @param change Firestore document change object.
|
|
12
|
+
* @returns {string} The document ID.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getDocumentId(change: Change<DocumentSnapshot>): string;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param template - eg, regions/{regionId}/countries
|
|
18
|
+
* @param text - eg, regions/asia/countries
|
|
19
|
+
*
|
|
20
|
+
* @return - eg, { regionId: "asia" }
|
|
21
|
+
*/
|
|
22
|
+
export declare const resolveWildcardIds: (template: string, text: string) => {};
|
|
23
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,UAAU,EAAE,MAAM,uDAAuD,CAAC;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAE7E;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,gBAAgB,CAAC,GAAG,UAAU,CAQ1E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAKtE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,aAAc,MAAM,QAAQ,MAAM,OAUhE,CAAC"}
|