"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatPrismaSchema = formatPrismaSchema;
exports.lintPrismaSchema = lintPrismaSchema;
const prisma_schema_wasm_1 = require("@prisma/prisma-schema-wasm");
const utils_1 = require("@postxl/utils");
/**
 * Runs the Prisma schema formatter on the provided schema.
 */
function formatPrismaSchema(schema) {
    // Prisma format only works if proper URI is provided.
    const uri = `file://prisma.schema`;
    const formattedSchema = JSON.parse((0, prisma_schema_wasm_1.format)(JSON.stringify([[uri, schema]]), JSON.stringify({ textDocument: { uri }, options: { tabSize: 2, insertSpaces: false } })))[0][1];
    return formattedSchema;
}
/**
 *
 */
function lintPrismaSchema(schema) {
    const uri = `file://prisma.schema`;
    const lintResult = JSON.parse((0, prisma_schema_wasm_1.lint)(JSON.stringify([[uri, schema]])));
    if (lintResult.length === 0) {
        return (0, utils_1.ok)(undefined);
    }
    return (0, utils_1.err)(lintResult.map((error) => error.text));
}
//# sourceMappingURL=prisma.utils.js.map