UNPKG

prismaql

Version:

A powerful tool for managing and editing Prisma schema files using a SQL-like DSL.

54 lines 1.98 kB
import { printSchema } from "@mrleebo/prisma-ast"; import { handlerResponse } from "../../handler-registries/handler-registry.js"; import { useHelper } from "../../utils/schema-helper.js"; import boxen from "boxen"; import { PrismaHighlighter } from "prismalux"; import chalk from "chalk"; const highlightPrismaSchema = new PrismaHighlighter(); export const getEnums = (prismaState, data) => { const response = handlerResponse(data); const options = data.options; const helper = useHelper(prismaState); let enums = helper.getEnums(); const onlyEnums = data.args?.enums || []; if (onlyEnums.length && !onlyEnums.includes("*")) { enums = enums.filter(e => onlyEnums.includes(e.name)); } if (!enums.length) { return response.result(chalk.yellow(`⚠ No enums found`)); } const totalEnums = enums.length; const statistic = `📌 Enums in schema: ${chalk.bold(totalEnums)}`; if (options?.raw) { const schema = { type: 'schema', list: enums }; const parsed = printSchema(schema); const rawOutput = highlightPrismaSchema.highlight(parsed); return response.result(boxen(`${statistic}\n${rawOutput}`, { padding: 1, width: 100, borderColor: "cyan", title: "Prisma Enums", titleAlignment: "center" })); } const list = []; enums.forEach(e => { list.push({ name: chalk.white.bold(e.name), options: e.enumerators?.filter(e => e.type == "enumerator").map((en) => chalk.green(en?.name)) || [] }); }); const renderedList = list.map(e => { return `${e.name}\n${e.options.join(", ")}\n`; }); return response.result(boxen(`${statistic}\n${renderedList.join('\n')}`, { padding: 1, borderColor: "cyan", title: "Prisma Enums", titleAlignment: "center" })); }; //# sourceMappingURL=get-enums.js.map