UNPKG

@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
{"version":3,"file":"normalize-custom-field-generation-locale.mjs","names":[],"sources":["../../../../src/services/ai/helpers/normalize-custom-field-generation-locale.ts"],"sourcesContent":["/**\n * Keeps AI generation input in one locale when the target field is not localized.\n * The remote AI API still expects locale-shaped data, so we collapse to the default locale.\n */\nconst normalizeCustomFieldGenerationLocale = (props: {\n\tdefaultLocale: string;\n\tfieldIsLocalized: boolean;\n\tlocale: {\n\t\tsource?: string;\n\t\ttarget: string[];\n\t};\n\tvalue: Record<string, unknown>;\n}) => {\n\tif (props.fieldIsLocalized) {\n\t\treturn {\n\t\t\tlocale: props.locale,\n\t\t\tvalue: props.value,\n\t\t};\n\t}\n\n\tif (Object.hasOwn(props.value, props.defaultLocale)) {\n\t\treturn {\n\t\t\tlocale: {\n\t\t\t\tsource: props.defaultLocale,\n\t\t\t\ttarget: [props.defaultLocale],\n\t\t\t},\n\t\t\tvalue: {\n\t\t\t\t[props.defaultLocale]: props.value[props.defaultLocale],\n\t\t\t},\n\t\t};\n\t}\n\n\tconst fallbackValue = Object.values(props.value)[0];\n\n\treturn {\n\t\tlocale: {\n\t\t\tsource: props.defaultLocale,\n\t\t\ttarget: [props.defaultLocale],\n\t\t},\n\t\tvalue:\n\t\t\tfallbackValue === undefined\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\t[props.defaultLocale]: fallbackValue,\n\t\t\t\t\t},\n\t};\n};\n\nexport default normalizeCustomFieldGenerationLocale;\n"],"mappings":"AAIA,MAAM,EAAwC,GAQxC,CACL,GAAI,EAAM,iBACT,MAAO,CACN,OAAQ,EAAM,OACd,MAAO,EAAM,KACd,EAGD,GAAI,OAAO,OAAO,EAAM,MAAO,EAAM,aAAa,EACjD,MAAO,CACN,OAAQ,CACP,OAAQ,EAAM,cACd,OAAQ,CAAC,EAAM,aAAa,CAC7B,EACA,MAAO,EACL,EAAM,eAAgB,EAAM,MAAM,EAAM,cAC1C,CACD,EAGD,IAAM,EAAgB,OAAO,OAAO,EAAM,KAAK,CAAC,CAAC,GAEjD,MAAO,CACN,OAAQ,CACP,OAAQ,EAAM,cACd,OAAQ,CAAC,EAAM,aAAa,CAC7B,EACA,MACC,IAAkB,IAAA,GACf,CAAC,EACD,EACC,EAAM,eAAgB,CACxB,CACJ,CACD"}