@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 1.81 kB
Source Map (JSON)
{"version":3,"file":"fetch-refs.mjs","names":[],"sources":["../../../../../../src/libs/collection/custom-fields/fields/media/fetch-refs.ts"],"sourcesContent":["import type { ServiceFn } from \"../../../../../utils/services/types.js\";\nimport type { MediaPropsT } from \"../../../../formatters/media.js\";\nimport { MediaRepository } from \"../../../../repositories/index.js\";\nimport type {\n\tFieldRefFetchInput,\n\tFieldRefFetchOutput,\n} from \"../../utils/ref-fetch.js\";\n\nconst fetchMediaRefs: ServiceFn<\n\t[FieldRefFetchInput],\n\tFieldRefFetchOutput\n> = async (context, data) => {\n\tconst Media = new MediaRepository(context.db.client, context.config.db);\n\tconst ids = Array.from(\n\t\tnew Set(\n\t\t\tdata.relations.flatMap((relation) =>\n\t\t\t\tArray.from(relation.values).filter(\n\t\t\t\t\t(value): value is number => typeof value === \"number\",\n\t\t\t\t),\n\t\t\t),\n\t\t),\n\t);\n\n\tif (ids.length === 0) {\n\t\treturn {\n\t\t\tdata: {\n\t\t\t\trows: [] satisfies MediaPropsT[],\n\t\t\t},\n\t\t\terror: undefined,\n\t\t};\n\t}\n\n\tconst mediaRes = await Media.selectMultipleByIds({\n\t\tids,\n\t\tvalidation: {\n\t\t\tenabled: true,\n\t\t},\n\t});\n\tif (mediaRes.error) return mediaRes;\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: {\n\t\t\trows: mediaRes.data,\n\t\t},\n\t};\n};\n\nexport default fetchMediaRefs;\n"],"mappings":"kDAQA,MAAM,EAGF,MAAO,EAAS,IAAS,CAC5B,IAAM,EAAQ,IAAI,EAAgB,EAAQ,GAAG,OAAQ,EAAQ,OAAO,EAAE,EAChE,EAAM,MAAM,KACjB,IAAI,IACH,EAAK,UAAU,QAAS,GACvB,MAAM,KAAK,EAAS,MAAM,CAAC,CAAC,OAC1B,GAA2B,OAAO,GAAU,QAC9C,CACD,CACD,CACD,EAEA,GAAI,EAAI,SAAW,EAClB,MAAO,CACN,KAAM,CACL,KAAM,CAAC,CACR,EACA,MAAO,IAAA,EACR,EAGD,IAAM,EAAW,MAAM,EAAM,oBAAoB,CAChD,MACA,WAAY,CACX,QAAS,EACV,CACD,CAAC,EAGD,OAFI,EAAS,MAAc,EAEpB,CACN,MAAO,IAAA,GACP,KAAM,CACL,KAAM,EAAS,IAChB,CACD,CACD"}