import { responder } from "../../responder/index.js"; import { NotFoundError } from "../utils/NotFoundError.js"; import { render } from "../../render/index.js"; import { functionContext } from "../../fn/functionContext.js"; import { getRenderDocument } from "../../operations/getRenderDocument.js"; export const documents = async (c, next) => { const client = c.get('client'); const path = c.req.path; const isAuthenticated = c.get('isAuthenticated') || false; try { return await responder({ path, getRender: doc => { return render(doc, { fn: functionContext(client, doc, c.req.query()), query: c.req.query(), }); }, getDocument: async ({ path }) => { const doc = await getRenderDocument(client, { path }, { ...(isAuthenticated ? { draft: true } : { published: true }), includeSlot: true, includeTemplate: true, }); if (doc) return doc; throw new NotFoundError('Document not found'); }, }); } catch (error) { if (error instanceof NotFoundError) { return next(); } else { throw error; } } }; //# sourceMappingURL=documents.js.map