GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: //usr/local/lib/node_modules/firebase-tools/lib/firestore/fsConfig.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFirestoreConfig = void 0;
const error_1 = require("../error");
const logger_1 = require("../logger");
function getFirestoreConfig(projectId, options) {
    const fsConfig = options.config.src.firestore;
    if (fsConfig === undefined) {
        return [];
    }
    const rc = options.rc;
    let allDatabases = !options.only;
    const onlyDatabases = new Set();
    if (options.only) {
        const split = options.only.split(",");
        if (split.includes("firestore")) {
            allDatabases = true;
        }
        else {
            for (const value of split) {
                if (value.startsWith("firestore:")) {
                    const target = value.split(":")[1];
                    onlyDatabases.add(target);
                }
            }
        }
    }
    if (!Array.isArray(fsConfig)) {
        if (fsConfig) {
            const databaseId = fsConfig.database || `(default)`;
            return [{ rules: fsConfig.rules, indexes: fsConfig.indexes, database: databaseId }];
        }
        else {
            logger_1.logger.debug("Possibly invalid database config: ", JSON.stringify(fsConfig));
            return [];
        }
    }
    const results = [];
    for (const c of fsConfig) {
        const { database, target } = c;
        if (target) {
            if (allDatabases || onlyDatabases.has(target)) {
                rc.requireTarget(projectId, "firestore", target);
                const databases = rc.target(projectId, "firestore", target);
                for (const database of databases) {
                    results.push({ database, rules: c.rules, indexes: c.indexes });
                }
                onlyDatabases.delete(target);
            }
        }
        else if (database) {
            if (allDatabases || onlyDatabases.has(database)) {
                results.push(c);
                onlyDatabases.delete(database);
            }
        }
        else {
            throw new error_1.FirebaseError('Must supply either "target" or "databaseId" in firestore config');
        }
    }
    if (onlyDatabases.has("rules")) {
        onlyDatabases.delete("rules");
    }
    if (onlyDatabases.has("indexes")) {
        onlyDatabases.delete("indexes");
    }
    if (!allDatabases && onlyDatabases.size !== 0) {
        throw new error_1.FirebaseError(`Could not find configurations in firebase.json for the following database targets: ${[
            ...onlyDatabases,
        ].join(", ")}`);
    }
    return results;
}
exports.getFirestoreConfig = getFirestoreConfig;