@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 2.92 kB
Source Map (JSON)
{"version":3,"file":"check-collection-environment-version-map.mjs","names":[],"sources":["../../../../src/libs/config/checks/check-collection-environment-version-map.ts"],"sourcesContent":["import type { Config } from \"../../../types.js\";\nimport { translate } from \"../../i18n/index.js\";\n\nconst latestVersionType = \"latest\";\n\n/**\n * Ensures configured collection version mappings point at known collections and\n * versions before cross-collection reads resolve against them at runtime.\n */\nconst checkCollectionEnvironmentVersionMap = (config: Config) => {\n\tconst collectionsByKey = new Map(\n\t\tconfig.collections.map((collection) => [collection.key, collection]),\n\t);\n\n\tfor (const collection of config.collections) {\n\t\tfor (const environment of collection.getData.environments) {\n\t\t\tfor (const [targetCollectionKey, targetVersionType] of Object.entries(\n\t\t\t\tenvironment.collectionVersions ?? {},\n\t\t\t)) {\n\t\t\t\tconst targetCollection = collectionsByKey.get(targetCollectionKey);\n\n\t\t\t\tif (!targetCollection) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\ttranslate(\n\t\t\t\t\t\t\t\"server:core.config.collection.environment.version.map.collection.not.found\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tcollection: collection.key,\n\t\t\t\t\t\t\t\t\tenvironment: environment.key,\n\t\t\t\t\t\t\t\t\ttargetCollection: targetCollectionKey,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (targetVersionType === latestVersionType) continue;\n\n\t\t\t\tconst targetEnvironmentExists =\n\t\t\t\t\ttargetCollection.getData.environments.some(\n\t\t\t\t\t\t(targetEnvironment) => targetEnvironment.key === targetVersionType,\n\t\t\t\t\t);\n\n\t\t\t\tif (!targetEnvironmentExists) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\ttranslate(\n\t\t\t\t\t\t\t\"server:core.config.collection.environment.version.map.target.not.found\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tcollection: collection.key,\n\t\t\t\t\t\t\t\t\tenvironment: environment.key,\n\t\t\t\t\t\t\t\t\ttargetCollection: targetCollectionKey,\n\t\t\t\t\t\t\t\t\ttargetVersion: targetVersionType,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};\n\nexport default checkCollectionEnvironmentVersionMap;\n"],"mappings":"qDAGA,MAMM,EAAwC,GAAmB,CAChE,IAAM,EAAmB,IAAI,IAC5B,EAAO,YAAY,IAAK,GAAe,CAAC,EAAW,IAAK,CAAU,CAAC,CACpE,EAEA,IAAK,IAAM,KAAc,EAAO,YAC/B,IAAK,IAAM,KAAe,EAAW,QAAQ,aAC5C,IAAK,GAAM,CAAC,EAAqB,KAAsB,OAAO,QAC7D,EAAY,oBAAsB,CAAC,CACpC,EAAG,CACF,IAAM,EAAmB,EAAiB,IAAI,CAAmB,EAEjE,GAAI,CAAC,EACJ,MAAU,MACT,EACC,6EACA,CACC,KAAM,CACL,WAAY,EAAW,IACvB,YAAa,EAAY,IACzB,iBAAkB,CACnB,CACD,CACD,CACD,EAGG,OAAsB,UAOtB,CAJH,EAAiB,QAAQ,aAAa,KACpC,GAAsB,EAAkB,MAAQ,CAGxB,EAC1B,MAAU,MACT,EACC,yEACA,CACC,KAAM,CACL,WAAY,EAAW,IACvB,YAAa,EAAY,IACzB,iBAAkB,EAClB,cAAe,CAChB,CACD,CACD,CACD,CAEF,CAGH"}