// The handlers of the module's procedures: each resolves its ports from the request's container and // calls one use case. No rule lives here. import type { Container } from "@conusai-kit/core" import { implement } from "@conusai-kit/core" import { DATA_SOURCE } from "@conusai-kit/data" import { filesDeps, toBase64 } from "@conusai-kit/files" import { proposalsDeps } from "@conusai-kit/proposals" import { documentGet, documentList, exportCreate, lineEdit } from "../contract/index.js" import { exportApproved } from "../core/export.js" import type { DocumentsDeps } from "../core/lines.js" import { editLine, getDocument, listDocuments } from "../core/review.js" /** The ports a handler needs: this module's data source and the two kernel modules it builds on. */ export function documentsDeps(container: Container): DocumentsDeps { return { data: container.resolve(DATA_SOURCE), files: filesDeps(container), proposals: proposalsDeps(container) } } export const documentListImpl = implement(documentList, async ({ ctx }) => ({ documents: await listDocuments(documentsDeps(ctx.container), ctx.scope), })) export const documentGetImpl = implement(documentGet, async ({ input, ctx }) => getDocument(documentsDeps(ctx.container), ctx.scope, input.fileId), ) export const lineEditImpl = implement(lineEdit, async ({ input, ctx }) => editLine(documentsDeps(ctx.container), ctx.scope, input), ) export const exportCreateImpl = implement(exportCreate, async ({ input, ctx }) => { const made = await exportApproved(documentsDeps(ctx.container), ctx.scope, input.fileId) return { filename: made.filename, contentType: made.contentType, body: toBase64(made.bytes), lineCount: made.lineCount, } }) export const DOCUMENT_PROCEDURES = [documentListImpl, documentGetImpl, lineEditImpl, exportCreateImpl]