This commit is contained in:
girinb
2025-05-29 15:41:51 +09:00
parent a1bd4f87a1
commit 485098cd1a
5611 changed files with 881685 additions and 0 deletions

36
node_modules/firebase-functions/lib/common/onInit.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withInit = exports.onInit = void 0;
const logger = require("../logger");
let initCallback = null;
let didInit = false;
/**
* Registers a callback that should be run when in a production environment
* before executing any functions code.
* Calling this function more than once leads to undefined behavior.
* @param callback initialization callback to be run before any function executes.
*/
function onInit(callback) {
if (initCallback) {
logger.warn("Setting onInit callback more than once. Only the most recent callback will be called");
}
initCallback = callback;
didInit = false;
}
exports.onInit = onInit;
/** @internal */
function withInit(func) {
return async (...args) => {
if (!didInit) {
if (initCallback) {
await initCallback();
}
didInit = true;
}
// Note: This cast is actually inaccurate because it may be a promise, but
// it doesn't actually matter because the async function will promisify
// non-promises and forward promises.
return func(...args);
};
}
exports.withInit = withInit;