UNPKG

firebase-tools

Version:
51 lines (50 loc) 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.delete_document = void 0; const zod_1 = require("zod"); const tool_1 = require("../../tool"); const util_1 = require("../../util"); const firestore_1 = require("../../../gcp/firestore"); const delete_1 = require("../../../firestore/delete"); const types_1 = require("../../../emulator/types"); exports.delete_document = (0, tool_1.tool)("firestore", { name: "delete_document", description: "Use this to delete a Firestore documents from a database in the current project by full document paths. Use this if you know the exact path of a document.", inputSchema: zod_1.z.object({ database: zod_1.z .string() .optional() .describe("Database id to use. Defaults to `(default)` if unspecified."), path: zod_1.z .string() .describe("A document path (e.g. `collectionName/documentId` or `parentCollection/parentDocument/collectionName/documentId`)"), use_emulator: zod_1.z.boolean().default(false).describe("Target the Firestore emulator if true."), }), annotations: { title: "Delete Firestore document", destructiveHint: true, }, _meta: { requiresAuth: true, requiresProject: true, }, }, async ({ path, database, use_emulator }, { projectId, host }) => { let emulatorUrl; if (use_emulator) { emulatorUrl = await host.getEmulatorUrl(types_1.Emulators.FIRESTORE); } const { documents, missing } = await (0, firestore_1.getDocuments)(projectId, [path], database, emulatorUrl); if (missing.length > 0 && documents && documents.length === 0) { return (0, util_1.mcpError)(`None of the specified documents were found in project '${projectId}'`); } const firestoreDelete = new delete_1.FirestoreDelete(projectId, path, { databaseId: database !== null && database !== void 0 ? database : "(default)", urlPrefix: emulatorUrl, }); await firestoreDelete.execute(); const { documents: postDeleteDocuments, missing: postDeleteMissing } = await (0, firestore_1.getDocuments)(projectId, [path], emulatorUrl); if (postDeleteMissing.length > 0 && postDeleteDocuments.length === 0) { return (0, util_1.toContent)(`Successfully removed document located at : ${path}`); } return (0, util_1.mcpError)(`Failed to remove document located at : ${path}`); });