{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../../../src/libs/collection/custom-fields/utils/helpers.ts"],"sourcesContent":["import z, { type ZodType } from \"zod\";\nimport type { CFConfig, FieldTypes } from \"../types.js\";\n\n/**\n * Checks if the custom field config property has a runtime config object.\n */\nexport const hasRuntimeConfig = (\n\tconfig: CFConfig<FieldTypes>,\n): config is CFConfig<FieldTypes> & {\n\tlocalized?: boolean;\n\tdefault?: unknown;\n} => {\n\treturn (\n\t\ttypeof config === \"object\" &&\n\t\tconfig !== null &&\n\t\t(\"localized\" in config || \"default\" in config)\n\t);\n};\n\n/**\n * Checks if the custom field config property has a validation config object.\n */\nexport const hasValidationConfig = (\n\tconfig: CFConfig<FieldTypes>,\n): config is CFConfig<FieldTypes> & {\n\tvalidation?: {\n\t\trequired?: boolean;\n\t\tzod?: ZodType<unknown>;\n\t};\n} => {\n\treturn (\n\t\ttypeof config === \"object\" && config !== null && \"validation\" in config\n\t);\n};\n\n/**\n * Checks if the validation config object has a zod validation object.\n */\nexport const hasZodValidation = (\n\tvalidation: unknown,\n): validation is {\n\tzod?: ZodType<unknown>;\n} => {\n\treturn (\n\t\ttypeof validation === \"object\" && validation !== null && \"zod\" in validation\n\t);\n};\n\n/**\n * Converts zod validation into JSON schema, falling back when conversion is not possible.\n */\nexport const zodToJsonSchema = (\n\tschema: ZodType<unknown> | undefined,\n\tfallback: Record<string, unknown>,\n) => {\n\tif (schema === undefined) return fallback;\n\n\ttry {\n\t\treturn z.toJSONSchema(schema) as Record<string, unknown>;\n\t} catch {\n\t\treturn fallback;\n\t}\n};\n"],"mappings":"mBAMA,MAAa,EACZ,GAMC,OAAO,GAAW,YAClB,IACC,cAAe,GAAU,YAAa,GAO5B,EACZ,GAQC,OAAO,GAAW,YAAY,GAAmB,eAAgB,EAOtD,EACZ,GAKC,OAAO,GAAe,YAAY,GAAuB,QAAS,EAOvD,GACZ,EACA,IACI,CACJ,GAAI,IAAW,IAAA,GAAW,OAAO,EAEjC,GAAI,CACH,OAAO,EAAE,aAAa,CAAM,CAC7B,MAAQ,CACP,OAAO,CACR,CACD"}