UNPKG

payloadcms-import-export-plugin

Version:

A comprehensive Payload CMS plugin that enables seamless import and export of collection data with support for CSV and JSON formats, featuring advanced field mapping, duplicate handling, and batch processing capabilities.

44 lines (43 loc) 1.92 kB
import { traverseFields } from 'payload'; export const getCustomFieldFunctions = ({ fields })=>{ const result = {}; const buildCustomFunctions = ({ field, parentRef, ref })=>{ // @ts-expect-error ref is untyped ref.prefix = parentRef.prefix || ''; if (field.type === 'group' || field.type === 'tab') { // @ts-expect-error ref is untyped const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''; // @ts-expect-error ref is untyped ref.prefix = `${parentPrefix}${field.name}_`; } if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') { // @ts-expect-error ref is untyped result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV; } else if (field.type === 'richText') { // @ts-expect-error ref is untyped result[`${ref.prefix}${field.name}`] = ({ value })=>{ if (value && (typeof value === 'object' || Array.isArray(value))) { return JSON.stringify(value); } return value; }; } else if (field.type === 'relationship' || field.type === 'upload') { // @ts-expect-error ref is untyped console.log("field type ", field.type, `${ref.prefix}${field.name}`); // @ts-expect-error ref is untyped result[`${ref.prefix}${field.name}`] = ({ value })=>{ console.log("field type ", field.type, value); if (value && (typeof value === 'object' || Array.isArray(value))) { return JSON.stringify(value); } return value; }; } }; traverseFields({ callback: buildCustomFunctions, fields }); return result; }; //# sourceMappingURL=getCustomFieldFunctions.js.map