{"version":3,"file":"get-single.mjs","names":["collectionServices.getSingle"],"sources":["../../../../../src/libs/http/controllers/collections/get-single.ts"],"sourcesContent":["import { createFactory } from \"hono/factory\";\nimport { describeRoute } from \"hono-openapi\";\nimport z from \"zod\";\nimport { controllerSchemas } from \"../../../../schemas/collections.js\";\nimport { collectionServices } from \"../../../../services/index.js\";\nimport { LucidAPIError } from \"../../../../utils/errors/index.js\";\nimport serviceWrapper from \"../../../../utils/services/service-wrapper.js\";\nimport { copy } from \"../../../i18n/index.js\";\nimport authenticate from \"../../middleware/authenticate.js\";\nimport collectionPermissions from \"../../middleware/collection-permissions.js\";\nimport validate from \"../../middleware/validate.js\";\nimport openAPI from \"../../openapi/index.js\";\nimport formatAPIResponse from \"../../utils/build-response.js\";\nimport createServiceContext from \"../../utils/create-service-context.js\";\n\nconst factory = createFactory();\n\nconst getSingleController = factory.createHandlers(\n\tdescribeRoute({\n\t\tdescription: \"Get a single collection instance.\",\n\t\ttags: [\"collections\"],\n\t\tsummary: \"Get Collection\",\n\t\tresponses: openAPI.responses({\n\t\t\tschema: z.toJSONSchema(controllerSchemas.getSingle.response),\n\t\t}),\n\t\tparameters: openAPI.parameters({\n\t\t\tparams: controllerSchemas.getSingle.params,\n\t\t}),\n\t}),\n\tauthenticate(),\n\tvalidate(\"param\", controllerSchemas.getSingle.params),\n\tcollectionPermissions(\"read\"),\n\tasync (c) => {\n\t\tconst { key } = c.req.valid(\"param\");\n\t\tconst context = createServiceContext(c);\n\n\t\tconst collectionRes = await serviceWrapper(collectionServices.getSingle, {\n\t\t\ttransaction: false,\n\t\t\tdefaultError: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tname: copy(\"server:core.routes.collection.fetch.error.name\"),\n\t\t\t\tmessage: copy(\"server:core.routes.collection.fetch.error.message\"),\n\t\t\t},\n\t\t})(context, {\n\t\t\tkey,\n\t\t});\n\t\tif (collectionRes.error) throw new LucidAPIError(collectionRes.error);\n\n\t\tc.status(200);\n\t\treturn c.json(\n\t\t\tformatAPIResponse(c, {\n\t\t\t\tdata: collectionRes.data,\n\t\t\t}),\n\t\t);\n\t},\n);\n\nexport default getSingleController;\n"],"mappings":"gsBAiBA,MAAM,EAFU,EAEkB,CAAC,CAAC,eACnC,EAAc,CACb,YAAa,oCACb,KAAM,CAAC,aAAa,EACpB,QAAS,iBACT,UAAW,EAAQ,UAAU,CAC5B,OAAQ,EAAE,aAAa,EAAkB,UAAU,QAAQ,CAC5D,CAAC,EACD,WAAY,EAAQ,WAAW,CAC9B,OAAQ,EAAkB,UAAU,MACrC,CAAC,CACF,CAAC,EACD,EAAa,EACb,EAAS,QAAS,EAAkB,UAAU,MAAM,EACpD,EAAsB,MAAM,EAC5B,KAAO,IAAM,CACZ,GAAM,CAAE,OAAQ,EAAE,IAAI,MAAM,OAAO,EAC7B,EAAU,EAAqB,CAAC,EAEhC,EAAgB,MAAM,EAAeA,EAA8B,CACxE,YAAa,GACb,aAAc,CACb,KAAM,QACN,KAAM,EAAK,gDAAgD,EAC3D,QAAS,EAAK,mDAAmD,CAClE,CACD,CAAC,CAAC,CAAC,EAAS,CACX,KACD,CAAC,EACD,GAAI,EAAc,MAAO,MAAM,IAAI,EAAc,EAAc,KAAK,EAGpE,OADA,EAAE,OAAO,GAAG,EACL,EAAE,KACR,EAAkB,EAAG,CACpB,KAAM,EAAc,IACrB,CAAC,CACF,CACD,CACD"}