UNPKG

@inaiat/fastify-papr

Version:
54 lines (52 loc) 1.39 kB
import { paprHelper } from "./chunk-Q3HDH7VO.js"; // src/fastify-papr-plugin.ts import fp from "fastify-plugin"; var asCollection = (name, schema, indexes) => ({ name, schema, indexes }); var fastifyPaprPlugin = async (mutable_fastify, options) => { const helper = paprHelper( mutable_fastify, options.db, options.disableSchemaReconciliation ); const models = await helper.register(options.models); const { name: dbName } = options; if (dbName) { if (mutable_fastify.papr) { if (mutable_fastify.papr[dbName]) { throw new Error(`Connection name already registered: ${dbName}`); } mutable_fastify.log.info(`Registering connection name: ${dbName}`); mutable_fastify.papr = { ...mutable_fastify.papr, [dbName]: models }; } else { mutable_fastify.decorate("papr", { [dbName]: models }); } } else { if (mutable_fastify.papr) { const items = Object.keys(mutable_fastify.papr).join(", "); throw new Error(`Models already registered: ${items}`); } else { mutable_fastify.decorate("papr", models); } } }; var fastify_papr_plugin_default = fp(fastifyPaprPlugin, { name: "fastify-papr-plugin", fastify: "4.x || 5.x" }); export { asCollection, fastifyPaprPlugin, fastify_papr_plugin_default }; //# sourceMappingURL=chunk-B4BWP7QX.js.map