@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 1.7 kB
Source Map (JSON)
{"version":3,"file":"get-single-instance.mjs","names":[],"sources":["../../../src/services/collections/get-single-instance.ts"],"sourcesContent":["import type CollectionBuilder from \"../../libs/collection/builders/collection-builder/index.js\";\nimport { copy } from \"../../libs/i18n/index.js\";\nimport { tenantAccessAllowed } from \"../../utils/helpers/index.js\";\nimport type {\n\tServiceContext,\n\tServiceResponse,\n} from \"../../utils/services/types.js\";\n\nconst getSingleInstance = (\n\tcontext: ServiceContext,\n\tdata: {\n\t\tkey: string;\n\t\tinstance?: CollectionBuilder;\n\t},\n): Awaited<ServiceResponse<CollectionBuilder>> => {\n\tconst collection =\n\t\tdata.instance ??\n\t\tcontext.config.collections?.find((c) => c.key === data.key);\n\n\tif (collection === undefined) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tmessage: copy(\"server:core.collections.not.found.message\"),\n\t\t\t\tstatus: 404,\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tif (\n\t\t!tenantAccessAllowed(collection.getData.tenants, context.request.tenantKey)\n\t) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tmessage: copy(\"server:core.collections.not.found.message\"),\n\t\t\t\tstatus: 404,\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: collection,\n\t};\n};\n\nexport default getSingleInstance;\n"],"mappings":"sHAQA,MAAM,GACL,EACA,IAIiD,CACjD,IAAM,EACL,EAAK,UACL,EAAQ,OAAO,aAAa,KAAM,GAAM,EAAE,MAAQ,EAAK,GAAG,EA0B3D,OAxBI,IAAe,IAAA,IAYlB,CAAC,EAAoB,EAAW,QAAQ,QAAS,EAAQ,QAAQ,SAAS,EAEnE,CACN,MAAO,CACN,KAAM,QACN,QAAS,EAAK,2CAA2C,EACzD,OAAQ,GACT,EACA,KAAM,IAAA,EACP,EAGM,CACN,MAAO,IAAA,GACP,KAAM,CACP,CACD"}