UNPKG

firebase-tools

Version:
63 lines (62 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseVariables = exports.graphqlResponseToToolResponse = exports.sourceToText = exports.connectorToText = exports.schemaToText = void 0; const js_yaml_1 = require("js-yaml"); const types_1 = require("../../../dataconnect/types"); const util_1 = require("../../util"); function schemaToText(s) { return ((0, js_yaml_1.dump)({ name: s.name, datasources: s.datasources, }) + "\n\n" + sourceToText(s.source)); } exports.schemaToText = schemaToText; function connectorToText(s) { return ((0, js_yaml_1.dump)({ name: s.name, }) + "\n\n" + sourceToText(s.source)); } exports.connectorToText = connectorToText; function sourceToText(s) { var _a; let output = ""; (_a = s.files) === null || _a === void 0 ? void 0 : _a.forEach((f) => { output += `\n# ${f.path}`; output += "\n```graphql\n"; output += `${f.content.trim()}\n`; output += "```\n"; }); return output; } exports.sourceToText = sourceToText; function graphqlResponseToToolResponse(g) { var _a; if ((0, types_1.isGraphQLResponse)(g)) { const isError = ((_a = g.errors) === null || _a === void 0 ? void 0 : _a.length) > 0; const contentString = `${isError ? "A GraphQL error occurred while executing the operation:" : ""}${JSON.stringify(g, null, 2)}`; return { isError, content: [{ type: "text", text: contentString }], }; } else { return (0, util_1.mcpError)(JSON.stringify(g, null, 2)); } } exports.graphqlResponseToToolResponse = graphqlResponseToToolResponse; function parseVariables(unparsedVariables) { try { const variables = JSON.parse(unparsedVariables || "{}"); if (typeof variables !== "object") throw new Error("not an object"); return variables; } catch (e) { throw new Error("Provided variables string `" + unparsedVariables + "` is not valid JSON."); } } exports.parseVariables = parseVariables;