UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 2.02 kB
import{copy as e}from"../../../../i18n/copy.mjs";import{isJsonContainerValue as t}from"../../../../../utils/helpers/get-typed-value.mjs";import{zodToJsonSchema as n}from"../../utils/helpers.mjs";import r from"../../utils/zod-safe-parse.mjs";import i from"../../custom-field.mjs";import a from"../../utils/key-to-title.mjs";import{jsonFieldConfig as o}from"./config.mjs";import s from"zod";var c=class extends i{type=o.type;config;key;props;constructor(t,n){super(),this.key=t,this.props=n,this.config={key:this.key,type:this.type,details:{label:this.props?.details?.label??e(`admin:fields.${this.type}.${this.key}.label`,{defaultMessage:a(this.key)}),summary:this.props?.details?.summary,placeholder:this.props?.details?.placeholder},ai:this.props?.ai,localized:this.props?.localized??!1,default:this.props?.default??null,index:this.props?.index,ui:{hidden:this.props?.ui?.hidden,disabled:this.props?.ui?.disabled,condition:this.props?.ui?.condition,width:this.props?.ui?.width},validation:this.props?.validation}}get supportsAi(){return!0}get jsonSchema(){return n(this.config.validation?.zod,{type:`string`,description:`A serialized JSON value. Return only JSON.stringify(value) for the generated JSON field value. The decoded value may be an object, array, string, number, boolean, or null.`})}getSchemaDefinition(e){return{data:{columns:[{name:this.key,type:e.db.getDataType(`json`),nullable:!0,default:this.config.default}]},error:void 0}}formatResponseValue(e){return e??this.config.default??null}normalizeInputValue(e){return typeof e==`string`&&e.trim()===``?null:e}formatAiGeneratedValue(e){if(typeof e==`string`)try{let n=JSON.parse(e);return{success:!0,value:t(n)?n:{value:n}}}catch{return{success:!0,value:{value:e}}}return t(e)?{success:!0,value:e}:{success:!0,value:{value:e}}}uniqueValidation(e){if(Array.isArray(e))return{valid:!0};let t=r(e,s.record(s.union([s.string(),s.number(),s.symbol()]),s.unknown()));return t.valid?{valid:!0}:t}};export{c as default}; //# sourceMappingURL=custom-field.mjs.map