@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 1.98 kB
Source Map (JSON)
{"version":3,"file":"translate-error-data.mjs","names":[],"sources":["../../../src/utils/errors/translate-error-data.ts"],"sourcesContent":["import type { PublicErrorData } from \"@lucidcms/types\";\nimport { isTranslatableCopy } from \"../../libs/i18n/index.js\";\nimport type { Translator } from \"../../libs/i18n/types.js\";\nimport type { ErrorCopy, LucidErrorData } from \"../../types/errors.js\";\n\nconst translateErrorCopy = (\n\ttext: ErrorCopy | undefined,\n\ttranslator: Translator,\n) => {\n\tif (!text) return text;\n\treturn translator(text);\n};\n\nconst translateNestedErrorCopy = (\n\tvalue: unknown,\n\ttranslator: Translator,\n): unknown => {\n\tif (isTranslatableCopy(value)) return translator(value);\n\tif (Array.isArray(value)) {\n\t\treturn value.map((item) => translateNestedErrorCopy(item, translator));\n\t}\n\tif (value && typeof value === \"object\") {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(value).map(([key, nested]) => [\n\t\t\t\tkey,\n\t\t\t\ttranslateNestedErrorCopy(nested, translator),\n\t\t\t]),\n\t\t);\n\t}\n\treturn value;\n};\n\n/**\n * Resolves deferred server translation keys inside an API error payload.\n */\nconst translateErrorData = (\n\terror: LucidErrorData,\n\ttranslator: Translator,\n): PublicErrorData => ({\n\t...error,\n\tname: translateErrorCopy(error.name, translator),\n\tmessage: translateErrorCopy(error.message, translator),\n\terrors: translateNestedErrorCopy(\n\t\terror.errors,\n\t\ttranslator,\n\t) as PublicErrorData[\"errors\"],\n});\n\nexport default translateErrorData;\n"],"mappings":"8DAKA,MAAM,GACL,EACA,IAEK,GACE,EAAW,CAAI,EAGjB,GACL,EACA,IAEI,EAAmB,CAAK,EAAU,EAAW,CAAK,EAClD,MAAM,QAAQ,CAAK,EACf,EAAM,IAAK,GAAS,EAAyB,EAAM,CAAU,CAAC,EAElE,GAAS,OAAO,GAAU,SACtB,OAAO,YACb,OAAO,QAAQ,CAAK,CAAC,CAAC,KAAK,CAAC,EAAK,KAAY,CAC5C,EACA,EAAyB,EAAQ,CAAU,CAC5C,CAAC,CACF,EAEM,EAMF,GACL,EACA,KACsB,CACtB,GAAG,EACH,KAAM,EAAmB,EAAM,KAAM,CAAU,EAC/C,QAAS,EAAmB,EAAM,QAAS,CAAU,EACrD,OAAQ,EACP,EAAM,OACN,CACD,CACD"}