@payloadcms/plugin-import-export 3.75.0 → 3.76.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CollectionField/index.d.ts.map +1 -1
- package/dist/components/CollectionField/index.js +6 -2
- package/dist/components/CollectionField/index.js.map +1 -1
- package/dist/components/ExportPreview/index.d.ts.map +1 -1
- package/dist/components/ExportPreview/index.js +30 -12
- package/dist/components/ExportPreview/index.js.map +1 -1
- package/dist/components/ExportPreview/index.scss +12 -0
- package/dist/components/ImportPreview/index.js +3 -15
- package/dist/components/ImportPreview/index.js.map +1 -1
- package/dist/export/createExport.d.ts +6 -1
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +37 -13
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
- package/dist/export/getCreateExportCollectionTask.js +4 -1
- package/dist/export/getCreateExportCollectionTask.js.map +1 -1
- package/dist/export/getExportCollection.d.ts.map +1 -1
- package/dist/export/getExportCollection.js +23 -3
- package/dist/export/getExportCollection.js.map +1 -1
- package/dist/export/getFields.d.ts.map +1 -1
- package/dist/export/getFields.js +7 -3
- package/dist/export/getFields.js.map +1 -1
- package/dist/export/handleDownload.d.ts.map +1 -1
- package/dist/export/handleDownload.js +18 -1
- package/dist/export/handleDownload.js.map +1 -1
- package/dist/export/handlePreview.d.ts.map +1 -1
- package/dist/export/handlePreview.js +32 -10
- package/dist/export/handlePreview.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/import/batchProcessor.d.ts.map +1 -1
- package/dist/import/batchProcessor.js +54 -55
- package/dist/import/batchProcessor.js.map +1 -1
- package/dist/import/createImport.d.ts +6 -1
- package/dist/import/createImport.d.ts.map +1 -1
- package/dist/import/createImport.js +5 -1
- package/dist/import/createImport.js.map +1 -1
- package/dist/import/getCreateImportCollectionTask.d.ts +9 -6
- package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
- package/dist/import/getCreateImportCollectionTask.js +105 -65
- package/dist/import/getCreateImportCollectionTask.js.map +1 -1
- package/dist/import/getImportCollection.d.ts.map +1 -1
- package/dist/import/getImportCollection.js +39 -45
- package/dist/import/getImportCollection.js.map +1 -1
- package/dist/import/handlePreview.d.ts.map +1 -1
- package/dist/import/handlePreview.js +11 -0
- package/dist/import/handlePreview.js.map +1 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -2
- package/dist/index.js.map +1 -1
- package/dist/translations/languages/ar.d.ts.map +1 -1
- package/dist/translations/languages/ar.js +3 -0
- package/dist/translations/languages/ar.js.map +1 -1
- package/dist/translations/languages/az.d.ts.map +1 -1
- package/dist/translations/languages/az.js +3 -0
- package/dist/translations/languages/az.js.map +1 -1
- package/dist/translations/languages/bg.d.ts.map +1 -1
- package/dist/translations/languages/bg.js +3 -0
- package/dist/translations/languages/bg.js.map +1 -1
- package/dist/translations/languages/bnBd.d.ts.map +1 -1
- package/dist/translations/languages/bnBd.js +22 -19
- package/dist/translations/languages/bnBd.js.map +1 -1
- package/dist/translations/languages/bnIn.d.ts.map +1 -1
- package/dist/translations/languages/bnIn.js +22 -19
- package/dist/translations/languages/bnIn.js.map +1 -1
- package/dist/translations/languages/ca.d.ts.map +1 -1
- package/dist/translations/languages/ca.js +3 -0
- package/dist/translations/languages/ca.js.map +1 -1
- package/dist/translations/languages/cs.d.ts.map +1 -1
- package/dist/translations/languages/cs.js +3 -0
- package/dist/translations/languages/cs.js.map +1 -1
- package/dist/translations/languages/da.d.ts.map +1 -1
- package/dist/translations/languages/da.js +3 -0
- package/dist/translations/languages/da.js.map +1 -1
- package/dist/translations/languages/de.d.ts.map +1 -1
- package/dist/translations/languages/de.js +3 -0
- package/dist/translations/languages/de.js.map +1 -1
- package/dist/translations/languages/en.d.ts +3 -0
- package/dist/translations/languages/en.d.ts.map +1 -1
- package/dist/translations/languages/en.js +3 -0
- package/dist/translations/languages/en.js.map +1 -1
- package/dist/translations/languages/es.d.ts.map +1 -1
- package/dist/translations/languages/es.js +3 -0
- package/dist/translations/languages/es.js.map +1 -1
- package/dist/translations/languages/et.d.ts.map +1 -1
- package/dist/translations/languages/et.js +3 -0
- package/dist/translations/languages/et.js.map +1 -1
- package/dist/translations/languages/fa.d.ts.map +1 -1
- package/dist/translations/languages/fa.js +3 -0
- package/dist/translations/languages/fa.js.map +1 -1
- package/dist/translations/languages/fr.d.ts.map +1 -1
- package/dist/translations/languages/fr.js +3 -0
- package/dist/translations/languages/fr.js.map +1 -1
- package/dist/translations/languages/he.d.ts.map +1 -1
- package/dist/translations/languages/he.js +3 -0
- package/dist/translations/languages/he.js.map +1 -1
- package/dist/translations/languages/hr.d.ts.map +1 -1
- package/dist/translations/languages/hr.js +3 -0
- package/dist/translations/languages/hr.js.map +1 -1
- package/dist/translations/languages/hu.d.ts.map +1 -1
- package/dist/translations/languages/hu.js +3 -0
- package/dist/translations/languages/hu.js.map +1 -1
- package/dist/translations/languages/hy.d.ts.map +1 -1
- package/dist/translations/languages/hy.js +3 -0
- package/dist/translations/languages/hy.js.map +1 -1
- package/dist/translations/languages/id.d.ts.map +1 -1
- package/dist/translations/languages/id.js +13 -10
- package/dist/translations/languages/id.js.map +1 -1
- package/dist/translations/languages/is.d.ts.map +1 -1
- package/dist/translations/languages/is.js +3 -0
- package/dist/translations/languages/is.js.map +1 -1
- package/dist/translations/languages/it.d.ts.map +1 -1
- package/dist/translations/languages/it.js +3 -0
- package/dist/translations/languages/it.js.map +1 -1
- package/dist/translations/languages/ja.d.ts.map +1 -1
- package/dist/translations/languages/ja.js +3 -0
- package/dist/translations/languages/ja.js.map +1 -1
- package/dist/translations/languages/ko.d.ts.map +1 -1
- package/dist/translations/languages/ko.js +3 -0
- package/dist/translations/languages/ko.js.map +1 -1
- package/dist/translations/languages/lt.d.ts.map +1 -1
- package/dist/translations/languages/lt.js +3 -0
- package/dist/translations/languages/lt.js.map +1 -1
- package/dist/translations/languages/lv.d.ts.map +1 -1
- package/dist/translations/languages/lv.js +16 -13
- package/dist/translations/languages/lv.js.map +1 -1
- package/dist/translations/languages/my.d.ts.map +1 -1
- package/dist/translations/languages/my.js +3 -0
- package/dist/translations/languages/my.js.map +1 -1
- package/dist/translations/languages/nb.d.ts.map +1 -1
- package/dist/translations/languages/nb.js +3 -0
- package/dist/translations/languages/nb.js.map +1 -1
- package/dist/translations/languages/nl.d.ts.map +1 -1
- package/dist/translations/languages/nl.js +3 -0
- package/dist/translations/languages/nl.js.map +1 -1
- package/dist/translations/languages/pl.d.ts.map +1 -1
- package/dist/translations/languages/pl.js +3 -0
- package/dist/translations/languages/pl.js.map +1 -1
- package/dist/translations/languages/pt.d.ts.map +1 -1
- package/dist/translations/languages/pt.js +3 -0
- package/dist/translations/languages/pt.js.map +1 -1
- package/dist/translations/languages/ro.d.ts.map +1 -1
- package/dist/translations/languages/ro.js +3 -0
- package/dist/translations/languages/ro.js.map +1 -1
- package/dist/translations/languages/rs.d.ts.map +1 -1
- package/dist/translations/languages/rs.js +3 -0
- package/dist/translations/languages/rs.js.map +1 -1
- package/dist/translations/languages/rsLatin.d.ts.map +1 -1
- package/dist/translations/languages/rsLatin.js +3 -0
- package/dist/translations/languages/rsLatin.js.map +1 -1
- package/dist/translations/languages/ru.d.ts.map +1 -1
- package/dist/translations/languages/ru.js +3 -0
- package/dist/translations/languages/ru.js.map +1 -1
- package/dist/translations/languages/sk.d.ts.map +1 -1
- package/dist/translations/languages/sk.js +3 -0
- package/dist/translations/languages/sk.js.map +1 -1
- package/dist/translations/languages/sl.d.ts.map +1 -1
- package/dist/translations/languages/sl.js +3 -0
- package/dist/translations/languages/sl.js.map +1 -1
- package/dist/translations/languages/sv.d.ts.map +1 -1
- package/dist/translations/languages/sv.js +3 -0
- package/dist/translations/languages/sv.js.map +1 -1
- package/dist/translations/languages/ta.d.ts.map +1 -1
- package/dist/translations/languages/ta.js +3 -0
- package/dist/translations/languages/ta.js.map +1 -1
- package/dist/translations/languages/th.d.ts.map +1 -1
- package/dist/translations/languages/th.js +3 -0
- package/dist/translations/languages/th.js.map +1 -1
- package/dist/translations/languages/tr.d.ts.map +1 -1
- package/dist/translations/languages/tr.js +3 -0
- package/dist/translations/languages/tr.js.map +1 -1
- package/dist/translations/languages/uk.d.ts.map +1 -1
- package/dist/translations/languages/uk.js +3 -0
- package/dist/translations/languages/uk.js.map +1 -1
- package/dist/translations/languages/vi.d.ts.map +1 -1
- package/dist/translations/languages/vi.js +3 -0
- package/dist/translations/languages/vi.js.map +1 -1
- package/dist/translations/languages/zh.d.ts.map +1 -1
- package/dist/translations/languages/zh.js +3 -0
- package/dist/translations/languages/zh.js.map +1 -1
- package/dist/translations/languages/zhTw.d.ts.map +1 -1
- package/dist/translations/languages/zhTw.js +3 -0
- package/dist/translations/languages/zhTw.js.map +1 -1
- package/dist/types.d.ts +44 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/buildDisabledFieldRegex.d.ts +11 -2
- package/dist/utilities/buildDisabledFieldRegex.d.ts.map +1 -1
- package/dist/utilities/buildDisabledFieldRegex.js +33 -7
- package/dist/utilities/buildDisabledFieldRegex.js.map +1 -1
- package/dist/utilities/buildDisabledFieldRegex.spec.js +64 -0
- package/dist/utilities/buildDisabledFieldRegex.spec.js.map +1 -0
- package/dist/utilities/collectTimezoneCompanionFields.d.ts +24 -0
- package/dist/utilities/collectTimezoneCompanionFields.d.ts.map +1 -0
- package/dist/utilities/collectTimezoneCompanionFields.js +89 -0
- package/dist/utilities/collectTimezoneCompanionFields.js.map +1 -0
- package/dist/utilities/collectTimezoneCompanionFields.spec.js +319 -0
- package/dist/utilities/collectTimezoneCompanionFields.spec.js.map +1 -0
- package/dist/utilities/fieldToRegex.d.ts +14 -0
- package/dist/utilities/fieldToRegex.d.ts.map +1 -0
- package/dist/utilities/fieldToRegex.js +34 -0
- package/dist/utilities/fieldToRegex.js.map +1 -0
- package/dist/utilities/fieldToRegex.spec.js +151 -0
- package/dist/utilities/fieldToRegex.spec.js.map +1 -0
- package/dist/utilities/flattenObject.d.ts +7 -1
- package/dist/utilities/flattenObject.d.ts.map +1 -1
- package/dist/utilities/flattenObject.js +30 -18
- package/dist/utilities/flattenObject.js.map +1 -1
- package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getExportFieldFunctions.js +7 -0
- package/dist/utilities/getExportFieldFunctions.js.map +1 -1
- package/dist/utilities/getFileFromDoc.d.ts +26 -0
- package/dist/utilities/getFileFromDoc.d.ts.map +1 -0
- package/dist/utilities/getFileFromDoc.js +67 -0
- package/dist/utilities/getFileFromDoc.js.map +1 -0
- package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getImportFieldFunctions.js +2 -16
- package/dist/utilities/getImportFieldFunctions.js.map +1 -1
- package/dist/utilities/getPluginCollections.d.ts +1 -0
- package/dist/utilities/getPluginCollections.d.ts.map +1 -1
- package/dist/utilities/getPluginCollections.js +59 -10
- package/dist/utilities/getPluginCollections.js.map +1 -1
- package/dist/utilities/getSchemaColumns.d.ts +8 -2
- package/dist/utilities/getSchemaColumns.d.ts.map +1 -1
- package/dist/utilities/getSchemaColumns.js +61 -27
- package/dist/utilities/getSchemaColumns.js.map +1 -1
- package/dist/utilities/parseCSV.d.ts.map +1 -1
- package/dist/utilities/parseCSV.js +4 -10
- package/dist/utilities/parseCSV.js.map +1 -1
- package/dist/utilities/resolveLimit.d.ts +15 -0
- package/dist/utilities/resolveLimit.d.ts.map +1 -0
- package/dist/utilities/resolveLimit.js +21 -0
- package/dist/utilities/resolveLimit.js.map +1 -0
- package/dist/utilities/unflattenObject.d.ts +13 -0
- package/dist/utilities/unflattenObject.d.ts.map +1 -1
- package/dist/utilities/unflattenObject.js +64 -65
- package/dist/utilities/unflattenObject.js.map +1 -1
- package/package.json +8 -8
- package/dist/utilities/getvalueAtPath.d.ts +0 -15
- package/dist/utilities/getvalueAtPath.d.ts.map +0 -1
- package/dist/utilities/getvalueAtPath.js +0 -49
- package/dist/utilities/getvalueAtPath.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { fieldToRegex } from './fieldToRegex.js';
|
|
2
|
+
export const flattenObject = ({ doc, fields, prefix, timezoneCompanionFields, toCSVFunctions })=>{
|
|
2
3
|
const row = {};
|
|
3
4
|
// Helper to get toCSV function by full path or base field name
|
|
4
5
|
// This allows functions registered for field names (e.g., 'richText') to work
|
|
@@ -103,24 +104,35 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
103
104
|
flatten(doc, prefix);
|
|
104
105
|
if (Array.isArray(fields) && fields.length > 0) {
|
|
105
106
|
const orderedResult = {};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
fields
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
// Build all field regexes once
|
|
108
|
+
const fieldPatterns = fields.map((field)=>({
|
|
109
|
+
field,
|
|
110
|
+
regex: fieldToRegex(field)
|
|
111
|
+
}));
|
|
112
|
+
// Track which timezone companion fields were explicitly selected
|
|
113
|
+
// Convert dotted notation to underscore for matching against flattened keys
|
|
114
|
+
const explicitlySelectedTimezoneFields = new Set(fields.filter((f)=>{
|
|
115
|
+
const underscored = f.replace(/\./g, '_');
|
|
116
|
+
return timezoneCompanionFields?.has(underscored);
|
|
117
|
+
}).map((f)=>f.replace(/\./g, '_')));
|
|
118
|
+
// Single pass through row keys - O(keys * fields) regex tests but only one iteration
|
|
119
|
+
const rowKeys = Object.keys(row);
|
|
120
|
+
// Process in field order to maintain user's specified ordering
|
|
121
|
+
for (const { regex } of fieldPatterns){
|
|
122
|
+
for (const key of rowKeys){
|
|
123
|
+
// Skip if already added (a key might match multiple field patterns)
|
|
124
|
+
if (key in orderedResult) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
// Skip auto-generated timezone companion fields unless explicitly selected
|
|
128
|
+
if (timezoneCompanionFields?.has(key) && !explicitlySelectedTimezoneFields.has(key)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (regex.test(key)) {
|
|
132
|
+
orderedResult[key] = row[key];
|
|
133
|
+
}
|
|
122
134
|
}
|
|
123
|
-
}
|
|
135
|
+
}
|
|
124
136
|
return orderedResult;
|
|
125
137
|
}
|
|
126
138
|
return row;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n // Helper to get toCSV function by full path or base field name\n // This allows functions registered for field names (e.g., 'richText') to work\n // even when the field is nested in arrays/blocks (e.g., 'blocks_0_content_richText')\n const getToCSVFunction = (fullPath: string, baseFieldName: string): ToCSVFunction | undefined => {\n return toCSVFunctions?.[fullPath] ?? toCSVFunctions?.[baseFieldName]\n }\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n const toCSVFn = getToCSVFunction(newKey, key)\n\n if (Array.isArray(value)) {\n // If a custom toCSV function exists for this array field, run it first.\n // If it produces output, skip per-item handling; otherwise, fall back.\n if (toCSVFn) {\n try {\n const result = toCSVFn({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value, // whole array\n })\n\n if (typeof result !== 'undefined') {\n // Custom function returned a single value for this array field.\n row[newKey] = result\n return\n }\n\n // If the custom function wrote any keys for this field, consider it handled.\n for (const k in row) {\n if (k === newKey || k.startsWith(`${newKey}_`)) {\n return\n }\n }\n // Otherwise, fall through to per-item handling.\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for array \"${newKey}\": ${JSON.stringify(value)}\\n${\n (error as Error).message\n }`,\n )\n }\n }\n\n value.forEach((item, index) => {\n if (typeof item === 'object' && item !== null) {\n const blockType = typeof item.blockType === 'string' ? item.blockType : undefined\n const itemPrefix = blockType ? `${newKey}_${index}_${blockType}` : `${newKey}_${index}`\n\n // Case: hasMany polymorphic relationships\n if (\n 'relationTo' in item &&\n 'value' in item &&\n typeof item.value === 'object' &&\n item.value !== null\n ) {\n row[`${itemPrefix}_relationTo`] = item.relationTo\n row[`${itemPrefix}_id`] = item.value.id\n return\n }\n\n // Fallback: deep-flatten nested objects\n flatten(item, itemPrefix)\n } else {\n // Primitive array item.\n row[`${newKey}_${index}`] = item\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n // Object field: use custom toCSV if present, else recurse.\n if (!toCSVFn) {\n flatten(value, newKey)\n } else {\n try {\n const result = toCSVFn({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for nested object \"${newKey}\": ${JSON.stringify(value)}\\n${\n (error as Error).message\n }`,\n )\n }\n }\n } else {\n if (toCSVFn) {\n try {\n const result = toCSVFn({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for field \"${newKey}\": ${JSON.stringify(value)}\\n${\n (error as Error).message\n }`,\n )\n }\n } else {\n row[newKey] = value\n }\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n const pattern = `^${parts.join('_')}`\n return new RegExp(pattern)\n }\n\n fields.forEach((field) => {\n if (row[field.replace(/\\./g, '_')]) {\n const sanitizedField = field.replace(/\\./g, '_')\n orderedResult[sanitizedField] = row[sanitizedField]\n } else {\n const regex = fieldToRegex(field)\n Object.keys(row).forEach((key) => {\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n })\n }\n })\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["flattenObject","doc","fields","prefix","toCSVFunctions","row","getToCSVFunction","fullPath","baseFieldName","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","toCSVFn","Array","isArray","result","columnName","data","k","startsWith","error","Error","JSON","stringify","message","item","index","blockType","undefined","itemPrefix","relationTo","id","length","orderedResult","fieldToRegex","field","parts","split","map","part","pattern","join","RegExp","replace","sanitizedField","regex","keys","test"],"mappings":"AAWA,OAAO,MAAMA,gBAAgB,CAAC,EAC5BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,cAAc,EACT;IACL,MAAMC,MAA+B,CAAC;IAEtC,+DAA+D;IAC/D,8EAA8E;IAC9E,qFAAqF;IACrF,MAAMC,mBAAmB,CAACC,UAAkBC;QAC1C,OAAOJ,gBAAgB,CAACG,SAAS,IAAIH,gBAAgB,CAACI,cAAc;IACtE;IAEA,MAAMC,UAAU,CAACC,YAAsBP;QACrCQ,OAAOC,OAAO,CAACF,YAAYG,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC9C,MAAMC,SAASb,SAAS,GAAGA,OAAO,CAAC,EAAEW,KAAK,GAAGA;YAC7C,MAAMG,UAAUX,iBAAiBU,QAAQF;YAEzC,IAAII,MAAMC,OAAO,CAACJ,QAAQ;gBACxB,wEAAwE;gBACxE,uEAAuE;gBACvE,IAAIE,SAAS;oBACX,IAAI;wBACF,MAAMG,SAASH,QAAQ;4BACrBI,YAAYL;4BACZM,MAAMjB;4BAC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AC2B;YACd,IAAInC,GAAG,CAACmC,MAAMQ,OAAO,CAAC,OAAO,KAAK,EAAE;gBAClC,MAAMC,iBAAiBT,MAAMQ,OAAO,CAAC,OAAO;gBAC5CV,aAAa,CAACW,eAAe,GAAG5C,GAAG,CAAC4C,eAAe;YACrD,OAAO;gBACL,MAAMC,QAAQX,aAAaC;gBAC3B7B,OAAOwC,IAAI,CAAC9C,KAAKQ,OAAO,CAAC,CAACC;oBACxB,IAAIoC,MAAME,IAAI,CAACtC,MAAM;wBACnBwB,aAAa,CAACxB,IAAI,GAAGT,GAAG,CAACS,IAAI;oBAC/B;gBACF;YACF;QACF;QAEA,OAAOwB;IACT;IAEA,OAAOjC;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\nimport { fieldToRegex } from './fieldToRegex.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n /**\n * Set of auto-generated timezone companion field names (from collectTimezoneCompanionFields).\n * These fields are excluded unless explicitly selected.\n * If not provided, no timezone filtering is applied.\n */\n timezoneCompanionFields?: Set<string>\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n timezoneCompanionFields,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n // Helper to get toCSV function by full path or base field name\n // This allows functions registered for field names (e.g., 'richText') to work\n // even when the field is nested in arrays/blocks (e.g., 'blocks_0_content_richText')\n const getToCSVFunction = (fullPath: string, baseFieldName: string): ToCSVFunction | undefined => {\n return toCSVFunctions?.[fullPath] ?? toCSVFunctions?.[baseFieldName]\n }\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n const toCSVFn = getToCSVFunction(newKey, key)\n\n if (Array.isArray(value)) {\n // If a custom toCSV function exists for this array field, run it first.\n // If it produces output, skip per-item handling; otherwise, fall back.\n if (toCSVFn) {\n try {\n const result = toCSVFn({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value, // whole array\n })\n\n if (typeof result !== 'undefined') {\n // Custom function returned a single value for this array field.\n row[newKey] = result\n return\n }\n\n // If the custom function wrote any keys for this field, consider it handled.\n for (const k in row) {\n if (k === newKey || k.startsWith(`${newKey}_`)) {\n return\n }\n }\n // Otherwise, fall through to per-item handling.\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for array \"${newKey}\": ${JSON.stringify(value)}\\n${\n (error as Error).message\n }`,\n )\n }\n }\n\n value.forEach((item, index) => {\n if (typeof item === 'object' && item !== null) {\n const blockType = typeof item.blockType === 'string' ? item.blockType : undefined\n const itemPrefix = blockType ? `${newKey}_${index}_${blockType}` : `${newKey}_${index}`\n\n // Case: hasMany polymorphic relationships\n if (\n 'relationTo' in item &&\n 'value' in item &&\n typeof item.value === 'object' &&\n item.value !== null\n ) {\n row[`${itemPrefix}_relationTo`] = item.relationTo\n row[`${itemPrefix}_id`] = item.value.id\n return\n }\n\n // Fallback: deep-flatten nested objects\n flatten(item, itemPrefix)\n } else {\n // Primitive array item.\n row[`${newKey}_${index}`] = item\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n // Object field: use custom toCSV if present, else recurse.\n if (!toCSVFn) {\n flatten(value, newKey)\n } else {\n try {\n const result = toCSVFn({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for nested object \"${newKey}\": ${JSON.stringify(value)}\\n${\n (error as Error).message\n }`,\n )\n }\n }\n } else {\n if (toCSVFn) {\n try {\n const result = toCSVFn({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for field \"${newKey}\": ${JSON.stringify(value)}\\n${\n (error as Error).message\n }`,\n )\n }\n } else {\n row[newKey] = value\n }\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n // Build all field regexes once\n const fieldPatterns = fields.map((field) => ({\n field,\n regex: fieldToRegex(field),\n }))\n\n // Track which timezone companion fields were explicitly selected\n // Convert dotted notation to underscore for matching against flattened keys\n const explicitlySelectedTimezoneFields = new Set(\n fields\n .filter((f) => {\n const underscored = f.replace(/\\./g, '_')\n return timezoneCompanionFields?.has(underscored)\n })\n .map((f) => f.replace(/\\./g, '_')),\n )\n\n // Single pass through row keys - O(keys * fields) regex tests but only one iteration\n const rowKeys = Object.keys(row)\n\n // Process in field order to maintain user's specified ordering\n for (const { regex } of fieldPatterns) {\n for (const key of rowKeys) {\n // Skip if already added (a key might match multiple field patterns)\n if (key in orderedResult) {\n continue\n }\n\n // Skip auto-generated timezone companion fields unless explicitly selected\n if (timezoneCompanionFields?.has(key) && !explicitlySelectedTimezoneFields.has(key)) {\n continue\n }\n\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n }\n }\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["fieldToRegex","flattenObject","doc","fields","prefix","timezoneCompanionFields","toCSVFunctions","row","getToCSVFunction","fullPath","baseFieldName","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","toCSVFn","Array","isArray","result","columnName","data","k","startsWith","error","Error","JSON","stringify","message","item","index","blockType","undefined","itemPrefix","relationTo","id","length","orderedResult","fieldPatterns","map","field","regex","explicitlySelectedTimezoneFields","Set","filter","f","underscored","replace","has","rowKeys","keys","test"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAehD,OAAO,MAAMC,gBAAgB,CAAC,EAC5BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,uBAAuB,EACvBC,cAAc,EACT;IACL,MAAMC,MAA+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,EAAEV,OAAO,GAAG,EAAEW,KAAKC,SAAS,CAACb,OAAO,EAAE,EACvE,AAACU,MAAgBI,OAAO,EACxB;oBAEN;gBACF,OAAO;oBACLxB,GAAG,CAACW,OAAO,GAAGD;gBAChB;YACF;QACF;IACF;IAEAN,QAAQT,KAAKE;IAEb,IAAIgB,MAAMC,OAAO,CAAClB,WAAWA,OAAOoC,MAAM,GAAG,GAAG;QAC9C,MAAMC,gBAAyC,CAAC;QAEhD,+BAA+B;QAC/B,MAAMC,gBAAgBtC,OAAOuC,GAAG,CAAC,CAACC,QAAW,CAAA;gBAC3CA;gBACAC,OAAO5C,aAAa2C;YACtB,CAAA;QAEA,iEAAiE;QACjE,4EAA4E;QAC5E,MAAME,mCAAmC,IAAIC,IAC3C3C,OACG4C,MAAM,CAAC,CAACC;YACP,MAAMC,cAAcD,EAAEE,OAAO,CAAC,OAAO;YACrC,OAAO7C,yBAAyB8C,IAAIF;QACtC,GACCP,GAAG,CAAC,CAACM,IAAMA,EAAEE,OAAO,CAAC,OAAO;QAGjC,qFAAqF;QACrF,MAAME,UAAUvC,OAAOwC,IAAI,CAAC9C;QAE5B,+DAA+D;QAC/D,KAAK,MAAM,EAAEqC,KAAK,EAAE,IAAIH,cAAe;YACrC,KAAK,MAAMzB,OAAOoC,QAAS;gBACzB,oEAAoE;gBACpE,IAAIpC,OAAOwB,eAAe;oBACxB;gBACF;gBAEA,2EAA2E;gBAC3E,IAAInC,yBAAyB8C,IAAInC,QAAQ,CAAC6B,iCAAiCM,GAAG,CAACnC,MAAM;oBACnF;gBACF;gBAEA,IAAI4B,MAAMU,IAAI,CAACtC,MAAM;oBACnBwB,aAAa,CAACxB,IAAI,GAAGT,GAAG,CAACS,IAAI;gBAC/B;YACF;QACF;QAEA,OAAOwB;IACT;IAEA,OAAOjC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExportFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/getExportFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+C,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"getExportFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/getExportFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+C,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAqHtF,CAAA"}
|
|
@@ -29,6 +29,13 @@ import { traverseFields } from 'payload';
|
|
|
29
29
|
}
|
|
30
30
|
return value;
|
|
31
31
|
};
|
|
32
|
+
} else if (field.type === 'date') {
|
|
33
|
+
// Handle date fields - return value as-is (ISO string format)
|
|
34
|
+
// This prevents the flattener from treating the document as having
|
|
35
|
+
// nested sibling properties like _tz that shouldn't be auto-included
|
|
36
|
+
// @ts-expect-error ref is untyped
|
|
37
|
+
const fieldKey = `${ref.prefix}${field.name}`;
|
|
38
|
+
result[fieldKey] = ({ value })=>value;
|
|
32
39
|
} else if (field.type === 'relationship' || field.type === 'upload') {
|
|
33
40
|
if (field.hasMany !== true) {
|
|
34
41
|
if (!Array.isArray(field.relationTo)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getExportFieldFunctions.ts"],"sourcesContent":["import { type FlattenedField, traverseFields, type TraverseFieldsCallback } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\n/**\n * Gets custom toCSV field functions for export.\n * These functions transform field values when flattening documents for CSV export.\n */\nexport const getExportFieldFunctions = ({ fields }: Args): Record<string, ToCSVFunction> => {\n const result: Record<string, ToCSVFunction> = {}\n\n const buildCustomFunctions: TraverseFieldsCallback = ({ field, parentRef, ref }) => {\n // @ts-expect-error ref is untyped\n ref.prefix = parentRef.prefix || ''\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}_`\n }\n\n if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV\n } else if (field.type === 'json' || field.type === 'richText') {\n // Serialize JSON and richText fields as JSON strings in a single column\n // This prevents them from being flattened into multiple columns\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (value === null || value === undefined) {\n return value\n }\n if (typeof value === 'object') {\n return JSON.stringify(value)\n }\n return value\n }\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) =>\n typeof value === 'object' && value && 'id' in value ? value.id : value\n } else {\n // polymorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ data, value }) => {\n if (value && typeof value === 'object' && 'relationTo' in value && 'value' in value) {\n const relationTo = (value as { relationTo: string; value: { id: number | string } })\n .relationTo\n const relatedDoc = (value as { relationTo: string; value: { id: number | string } })\n .value\n if (relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_relationTo`] = relationTo\n }\n }\n return undefined // prevents further flattening\n }\n }\n } else {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n data,\n value,\n }: {\n data: Record<string, unknown>\n value: Array<number | Record<string, any> | string> | undefined\n }) => {\n if (Array.isArray(value)) {\n value.forEach((val, i) => {\n const id = typeof val === 'object' && val ? val.id : val\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_id`] = id\n })\n }\n return undefined // prevents further flattening\n }\n } else {\n // polymorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n data,\n value,\n }: {\n data: Record<string, unknown>\n value: Array<Record<string, any>> | undefined\n }) => {\n if (Array.isArray(value)) {\n value.forEach((val, i) => {\n if (val && typeof val === 'object') {\n const relationTo = val.relationTo\n const relatedDoc = val.value\n if (relationTo && relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_relationTo`] = relationTo\n }\n }\n })\n }\n return undefined\n }\n }\n }\n }\n }\n\n traverseFields({ callback: buildCustomFunctions, fields })\n\n return result\n}\n"],"names":["traverseFields","getExportFieldFunctions","fields","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","toCSV","value","undefined","JSON","stringify","hasMany","Array","isArray","relationTo","id","data","relatedDoc","forEach","val","i","callback"],"mappings":"AAAA,SAA8BA,cAAc,QAAqC,UAAS;AAQ1F;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAAC,EAAEC,MAAM,EAAQ;IACtD,MAAMC,SAAwC,CAAC;IAE/C,MAAMC,uBAA+C,CAAC,EAAEC,KAAK,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC7E,kCAAkC;QAClCA,IAAIC,MAAM,GAAGF,UAAUE,MAAM,IAAI;QACjC,IAAIH,MAAMI,IAAI,KAAK,WAAWJ,MAAMI,IAAI,KAAK,OAAO;YAClD,kCAAkC;YAClC,MAAMC,eAAeJ,WAAWE,SAAS,GAAGF,UAAUE,MAAM,CAAC,CAAC,CAAC,GAAG;YAClE,kCAAkC;YAClCD,IAAIC,MAAM,GAAG,GAAGE,eAAeL,MAAMM,IAAI,CAAC,CAAC,CAAC;QAC9C;QAEA,IAAI,OAAON,MAAMO,MAAM,EAAE,CAAC,uBAAuB,EAAEC,UAAU,YAAY;YACvE,kCAAkC;YAClCV,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAGN,MAAMO,MAAM,CAAC,uBAAuB,EAAEC;QAC/E,OAAO,IAAIR,MAAMI,IAAI,KAAK,UAAUJ,MAAMI,IAAI,KAAK,YAAY;YAC7D,wEAAwE;YACxE,gEAAgE;YAChE,kCAAkC;YAClCN,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAG,CAAC,EAAEG,KAAK,EAAE;gBAC/C,IAAIA,UAAU,QAAQA,UAAUC,WAAW;oBACzC,OAAOD;gBACT;gBACA,IAAI,OAAOA,UAAU,UAAU;oBAC7B,OAAOE,KAAKC,SAAS,CAACH;gBACxB;gBACA,OAAOA;YACT;QACF,OAAO,IAAIT,MAAMI,IAAI,KAAK,kBAAkBJ,MAAMI,IAAI,KAAK,UAAU;YACnE,IAAIJ,
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getExportFieldFunctions.ts"],"sourcesContent":["import { type FlattenedField, traverseFields, type TraverseFieldsCallback } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\n/**\n * Gets custom toCSV field functions for export.\n * These functions transform field values when flattening documents for CSV export.\n */\nexport const getExportFieldFunctions = ({ fields }: Args): Record<string, ToCSVFunction> => {\n const result: Record<string, ToCSVFunction> = {}\n\n const buildCustomFunctions: TraverseFieldsCallback = ({ field, parentRef, ref }) => {\n // @ts-expect-error ref is untyped\n ref.prefix = parentRef.prefix || ''\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}_`\n }\n\n if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV\n } else if (field.type === 'json' || field.type === 'richText') {\n // Serialize JSON and richText fields as JSON strings in a single column\n // This prevents them from being flattened into multiple columns\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (value === null || value === undefined) {\n return value\n }\n if (typeof value === 'object') {\n return JSON.stringify(value)\n }\n return value\n }\n } else if (field.type === 'date') {\n // Handle date fields - return value as-is (ISO string format)\n // This prevents the flattener from treating the document as having\n // nested sibling properties like _tz that shouldn't be auto-included\n // @ts-expect-error ref is untyped\n const fieldKey = `${ref.prefix}${field.name}`\n\n result[fieldKey] = ({ value }) => value\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) =>\n typeof value === 'object' && value && 'id' in value ? value.id : value\n } else {\n // polymorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ data, value }) => {\n if (value && typeof value === 'object' && 'relationTo' in value && 'value' in value) {\n const relationTo = (value as { relationTo: string; value: { id: number | string } })\n .relationTo\n const relatedDoc = (value as { relationTo: string; value: { id: number | string } })\n .value\n if (relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_relationTo`] = relationTo\n }\n }\n return undefined // prevents further flattening\n }\n }\n } else {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n data,\n value,\n }: {\n data: Record<string, unknown>\n value: Array<number | Record<string, any> | string> | undefined\n }) => {\n if (Array.isArray(value)) {\n value.forEach((val, i) => {\n const id = typeof val === 'object' && val ? val.id : val\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_id`] = id\n })\n }\n return undefined // prevents further flattening\n }\n } else {\n // polymorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n data,\n value,\n }: {\n data: Record<string, unknown>\n value: Array<Record<string, any>> | undefined\n }) => {\n if (Array.isArray(value)) {\n value.forEach((val, i) => {\n if (val && typeof val === 'object') {\n const relationTo = val.relationTo\n const relatedDoc = val.value\n if (relationTo && relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_relationTo`] = relationTo\n }\n }\n })\n }\n return undefined\n }\n }\n }\n }\n }\n\n traverseFields({ callback: buildCustomFunctions, fields })\n\n return result\n}\n"],"names":["traverseFields","getExportFieldFunctions","fields","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","toCSV","value","undefined","JSON","stringify","fieldKey","hasMany","Array","isArray","relationTo","id","data","relatedDoc","forEach","val","i","callback"],"mappings":"AAAA,SAA8BA,cAAc,QAAqC,UAAS;AAQ1F;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAAC,EAAEC,MAAM,EAAQ;IACtD,MAAMC,SAAwC,CAAC;IAE/C,MAAMC,uBAA+C,CAAC,EAAEC,KAAK,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC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OI,QAAQ,YAAYA,MAAMA,IAAIJ,EAAE,GAAGI;gCACrD,kCAAkC;gCAClCH,IAAI,CAAC,GAAGjB,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEiB,EAAE,GAAG,CAAC,CAAC,GAAGL;4BAC/C;wBACF;wBACA,OAAOR,UAAU,8BAA8B;;oBACjD;gBACF,OAAO;oBACL,mBAAmB;oBACnB,kCAAkC;oBAClCZ,MAAM,CAAC,GAAGI,IAAIC,MAAM,GAAGH,MAAMM,IAAI,EAAE,CAAC,GAAG,CAAC,EACtCa,IAAI,EACJV,KAAK,EAIN;wBACC,IAAIM,MAAMC,OAAO,CAACP,QAAQ;4BACxBA,MAAMY,OAAO,CAAC,CAACC,KAAKC;gCAClB,IAAID,OAAO,OAAOA,QAAQ,UAAU;oCAClC,MAAML,aAAaK,IAAIL,UAAU;oCACjC,MAAMG,aAAaE,IAAIb,KAAK;oCAC5B,IAAIQ,cAAcG,cAAc,OAAOA,eAAe,UAAU;wCAC9D,kCAAkC;wCAClCD,IAAI,CAAC,GAAGjB,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEiB,EAAE,GAAG,CAAC,CAAC,GAAGH,WAAWF,EAAE;wCAC1D,kCAAkC;wCAClCC,IAAI,CAAC,GAAGjB,IAAIC,MAAM,GAAGH,MAAMM,IAAI,CAAC,CAAC,EAAEiB,EAAE,WAAW,CAAC,CAAC,GAAGN;oCACvD;gCACF;4BACF;wBACF;wBACA,OAAOP;oBACT;gBACF;YACF;QACF;IACF;IAEAf,eAAe;QAAE6B,UAAUzB;QAAsBF;IAAO;IAExD,OAAOC;AACT,EAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CollectionConfig, PayloadRequest } from 'payload';
|
|
2
|
+
type Args = {
|
|
3
|
+
collectionConfig: CollectionConfig;
|
|
4
|
+
doc: {
|
|
5
|
+
filename: string;
|
|
6
|
+
mimeType?: string;
|
|
7
|
+
url?: string;
|
|
8
|
+
};
|
|
9
|
+
req: PayloadRequest;
|
|
10
|
+
};
|
|
11
|
+
type Result = {
|
|
12
|
+
data: Buffer;
|
|
13
|
+
mimetype: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves file data from an uploaded document, handling both local storage
|
|
17
|
+
* and cloud storage (S3, Azure, GCS, etc.) scenarios correctly.
|
|
18
|
+
*
|
|
19
|
+
* This function uses the same pattern as Payload's internal file retrieval:
|
|
20
|
+
* - For local storage: reads directly from disk (efficient, no HTTP roundtrip)
|
|
21
|
+
* - For cloud storage: fetches via Payload's file endpoint, which triggers
|
|
22
|
+
* the storage adapter's staticHandler to serve the file
|
|
23
|
+
*/
|
|
24
|
+
export declare const getFileFromDoc: ({ collectionConfig, doc, req }: Args) => Promise<Result>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=getFileFromDoc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFileFromDoc.d.ts","sourceRoot":"","sources":["../../src/utilities/getFileFromDoc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAY,cAAc,EAAgB,MAAM,SAAS,CAAA;AAMvF,KAAK,IAAI,GAAG;IACV,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,GAAG,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC1D,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,mCAA0C,IAAI,KAAG,OAAO,CAAC,MAAM,CAkEzF,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { FileRetrievalError, getFileByPath } from 'payload';
|
|
2
|
+
import { getExternalFile } from 'payload/internal';
|
|
3
|
+
import { formatAdminURL } from 'payload/shared';
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves file data from an uploaded document, handling both local storage
|
|
6
|
+
* and cloud storage (S3, Azure, GCS, etc.) scenarios correctly.
|
|
7
|
+
*
|
|
8
|
+
* This function uses the same pattern as Payload's internal file retrieval:
|
|
9
|
+
* - For local storage: reads directly from disk (efficient, no HTTP roundtrip)
|
|
10
|
+
* - For cloud storage: fetches via Payload's file endpoint, which triggers
|
|
11
|
+
* the storage adapter's staticHandler to serve the file
|
|
12
|
+
*/ export const getFileFromDoc = async ({ collectionConfig, doc, req })=>{
|
|
13
|
+
const uploadConfig = typeof collectionConfig.upload === 'object' ? collectionConfig.upload : {};
|
|
14
|
+
const disableLocalStorage = uploadConfig.disableLocalStorage ?? false;
|
|
15
|
+
const staticDir = uploadConfig.staticDir || collectionConfig.slug;
|
|
16
|
+
const serverURL = req.payload.config.serverURL;
|
|
17
|
+
const isLocalFile = serverURL && doc.url?.startsWith(serverURL) || doc.url?.startsWith('/');
|
|
18
|
+
if (!disableLocalStorage && isLocalFile && doc.filename) {
|
|
19
|
+
// Local storage enabled - read directly from disk (efficient, no HTTP roundtrip)
|
|
20
|
+
const filePath = `${staticDir}/${doc.filename}`;
|
|
21
|
+
const file = await getFileByPath(filePath);
|
|
22
|
+
if (!file) {
|
|
23
|
+
throw new Error(`File not found at path: ${filePath}`);
|
|
24
|
+
}
|
|
25
|
+
const mimetype = file.mimetype || doc.mimeType;
|
|
26
|
+
if (!mimetype) {
|
|
27
|
+
throw new FileRetrievalError(req.t, `Unable to determine mimetype for file: ${doc.filename}`);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
data: file.data,
|
|
31
|
+
mimetype
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (doc.filename && doc.url) {
|
|
35
|
+
// Cloud storage or external - fetch via Payload's file endpoint
|
|
36
|
+
// getExternalFile constructs full URL, includes cookies for auth, and
|
|
37
|
+
// the request goes through Payload's handler chain (including storage adapter)
|
|
38
|
+
// For relative URLs, construct a full URL using formatAdminURL which properly
|
|
39
|
+
// handles serverURL, basePath, and other config. This is important in job contexts
|
|
40
|
+
// where request headers may not be available for URL construction.
|
|
41
|
+
// Use serverURL from config, falling back to req.origin for local/job requests.
|
|
42
|
+
const fileUrl = doc.url.startsWith('http') ? doc.url : formatAdminURL({
|
|
43
|
+
apiRoute: '',
|
|
44
|
+
path: doc.url,
|
|
45
|
+
serverURL: serverURL || req.origin
|
|
46
|
+
});
|
|
47
|
+
const file = await getExternalFile({
|
|
48
|
+
data: {
|
|
49
|
+
filename: doc.filename,
|
|
50
|
+
url: fileUrl
|
|
51
|
+
},
|
|
52
|
+
req,
|
|
53
|
+
uploadConfig
|
|
54
|
+
});
|
|
55
|
+
const mimetype = file.mimetype || doc.mimeType;
|
|
56
|
+
if (!mimetype) {
|
|
57
|
+
throw new FileRetrievalError(req.t, `Unable to determine mimetype for file: ${doc.filename}`);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
data: file.data,
|
|
61
|
+
mimetype
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
throw new Error('Unable to retrieve file: missing filename or url');
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=getFileFromDoc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getFileFromDoc.ts"],"sourcesContent":["import type { CollectionConfig, FileData, PayloadRequest, UploadConfig } from 'payload'\n\nimport { FileRetrievalError, getFileByPath } from 'payload'\nimport { getExternalFile } from 'payload/internal'\nimport { formatAdminURL } from 'payload/shared'\n\ntype Args = {\n collectionConfig: CollectionConfig\n doc: { filename: string; mimeType?: string; url?: string }\n req: PayloadRequest\n}\n\ntype Result = {\n data: Buffer\n mimetype: string\n}\n\n/**\n * Retrieves file data from an uploaded document, handling both local storage\n * and cloud storage (S3, Azure, GCS, etc.) scenarios correctly.\n *\n * This function uses the same pattern as Payload's internal file retrieval:\n * - For local storage: reads directly from disk (efficient, no HTTP roundtrip)\n * - For cloud storage: fetches via Payload's file endpoint, which triggers\n * the storage adapter's staticHandler to serve the file\n */\nexport const getFileFromDoc = async ({ collectionConfig, doc, req }: Args): Promise<Result> => {\n const uploadConfig: UploadConfig =\n typeof collectionConfig.upload === 'object' ? collectionConfig.upload : {}\n const disableLocalStorage = uploadConfig.disableLocalStorage ?? false\n const staticDir = uploadConfig.staticDir || collectionConfig.slug\n\n const serverURL = req.payload.config.serverURL\n const isLocalFile = (serverURL && doc.url?.startsWith(serverURL)) || doc.url?.startsWith('/')\n\n if (!disableLocalStorage && isLocalFile && doc.filename) {\n // Local storage enabled - read directly from disk (efficient, no HTTP roundtrip)\n const filePath = `${staticDir}/${doc.filename}`\n const file = await getFileByPath(filePath)\n\n if (!file) {\n throw new Error(`File not found at path: ${filePath}`)\n }\n\n const mimetype = file.mimetype || doc.mimeType\n\n if (!mimetype) {\n throw new FileRetrievalError(req.t, `Unable to determine mimetype for file: ${doc.filename}`)\n }\n\n return {\n data: file.data,\n mimetype,\n }\n }\n\n if (doc.filename && doc.url) {\n // Cloud storage or external - fetch via Payload's file endpoint\n // getExternalFile constructs full URL, includes cookies for auth, and\n // the request goes through Payload's handler chain (including storage adapter)\n\n // For relative URLs, construct a full URL using formatAdminURL which properly\n // handles serverURL, basePath, and other config. This is important in job contexts\n // where request headers may not be available for URL construction.\n // Use serverURL from config, falling back to req.origin for local/job requests.\n const fileUrl = doc.url.startsWith('http')\n ? doc.url\n : formatAdminURL({\n apiRoute: '',\n path: doc.url as `/${string}`,\n serverURL: serverURL || req.origin,\n })\n\n const file = await getExternalFile({\n data: { filename: doc.filename, url: fileUrl } as FileData,\n req,\n uploadConfig,\n })\n\n const mimetype = file.mimetype || doc.mimeType\n\n if (!mimetype) {\n throw new FileRetrievalError(req.t, `Unable to determine mimetype for file: ${doc.filename}`)\n }\n\n return {\n data: file.data,\n mimetype,\n }\n }\n\n throw new Error('Unable to retrieve file: missing filename or url')\n}\n"],"names":["FileRetrievalError","getFileByPath","getExternalFile","formatAdminURL","getFileFromDoc","collectionConfig","doc","req","uploadConfig","upload","disableLocalStorage","staticDir","slug","serverURL","payload","config","isLocalFile","url","startsWith","filename","filePath","file","Error","mimetype","mimeType","t","data","fileUrl","apiRoute","path","origin"],"mappings":"AAEA,SAASA,kBAAkB,EAAEC,aAAa,QAAQ,UAAS;AAC3D,SAASC,eAAe,QAAQ,mBAAkB;AAClD,SAASC,cAAc,QAAQ,iBAAgB;AAa/C;;;;;;;;CAQC,GACD,OAAO,MAAMC,iBAAiB,OAAO,EAAEC,gBAAgB,EAAEC,GAAG,EAAEC,GAAG,EAAQ;IACvE,MAAMC,eACJ,OAAOH,iBAAiBI,MAAM,KAAK,WAAWJ,iBAAiBI,MAAM,GAAG,CAAC;IAC3E,MAAMC,sBAAsBF,aAAaE,mBAAmB,IAAI;IAChE,MAAMC,YAAYH,aAAaG,SAAS,IAAIN,iBAAiBO,IAAI;IAEjE,MAAMC,YAAYN,IAAIO,OAAO,CAACC,MAAM,CAACF,SAAS;IAC9C,MAAMG,cAAc,AAACH,aAAaP,IAAIW,GAAG,EAAEC,WAAWL,cAAeP,IAAIW,GAAG,EAAEC,WAAW;IAEzF,IAAI,CAACR,uBAAuBM,eAAeV,IAAIa,QAAQ,EAAE;QACvD,iFAAiF;QACjF,MAAMC,WAAW,GAAGT,UAAU,CAAC,EAAEL,IAAIa,QAAQ,EAAE;QAC/C,MAAME,OAAO,MAAMpB,cAAcmB;QAEjC,IAAI,CAACC,MAAM;YACT,MAAM,IAAIC,MAAM,CAAC,wBAAwB,EAAEF,UAAU;QACvD;QAEA,MAAMG,WAAWF,KAAKE,QAAQ,IAAIjB,IAAIkB,QAAQ;QAE9C,IAAI,CAACD,UAAU;YACb,MAAM,IAAIvB,mBAAmBO,IAAIkB,CAAC,EAAE,CAAC,uCAAuC,EAAEnB,IAAIa,QAAQ,EAAE;QAC9F;QAEA,OAAO;YACLO,MAAML,KAAKK,IAAI;YACfH;QACF;IACF;IAEA,IAAIjB,IAAIa,QAAQ,IAAIb,IAAIW,GAAG,EAAE;QAC3B,gEAAgE;QAChE,sEAAsE;QACtE,+EAA+E;QAE/E,8EAA8E;QAC9E,mFAAmF;QACnF,mEAAmE;QACnE,gFAAgF;QAChF,MAAMU,UAAUrB,IAAIW,GAAG,CAACC,UAAU,CAAC,UAC/BZ,IAAIW,GAAG,GACPd,eAAe;YACbyB,UAAU;YACVC,MAAMvB,IAAIW,GAAG;YACbJ,WAAWA,aAAaN,IAAIuB,MAAM;QACpC;QAEJ,MAAMT,OAAO,MAAMnB,gBAAgB;YACjCwB,MAAM;gBAAEP,UAAUb,IAAIa,QAAQ;gBAAEF,KAAKU;YAAQ;YAC7CpB;YACAC;QACF;QAEA,MAAMe,WAAWF,KAAKE,QAAQ,IAAIjB,IAAIkB,QAAQ;QAE9C,IAAI,CAACD,UAAU;YACb,MAAM,IAAIvB,mBAAmBO,IAAIkB,CAAC,EAAE,CAAC,uCAAuC,EAAEnB,IAAIa,QAAQ,EAAE;QAC9F;QAEA,OAAO;YACLO,MAAML,KAAKK,IAAI;YACfH;QACF;IACF;IAEA,MAAM,IAAID,MAAM;AAClB,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getImportFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/getImportFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+C,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"getImportFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/getImportFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+C,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CA8GxF,CAAA"}
|
|
@@ -30,35 +30,26 @@ import { traverseFields } from 'payload';
|
|
|
30
30
|
return value;
|
|
31
31
|
};
|
|
32
32
|
} else {
|
|
33
|
-
//
|
|
34
|
-
// The CSV has field_id and field_relationTo columns
|
|
35
|
-
// We need to combine them back into { relationTo, value } format
|
|
36
|
-
// This is handled in unflattenObject, so we don't need a fromCSV here
|
|
33
|
+
// Polymorphic single: handled in unflattenObject via _id/_relationTo columns
|
|
37
34
|
}
|
|
38
35
|
} else {
|
|
39
36
|
if (!Array.isArray(field.relationTo)) {
|
|
40
37
|
// @ts-expect-error ref is untyped
|
|
41
38
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
42
|
-
// If it's already an array (from JSON import), return as-is
|
|
43
39
|
if (Array.isArray(value)) {
|
|
44
40
|
return value;
|
|
45
41
|
}
|
|
46
|
-
// For CSV, this is handled by array unflattening in unflattenObject
|
|
47
42
|
return value;
|
|
48
43
|
};
|
|
49
44
|
} else {
|
|
50
|
-
//
|
|
51
|
-
// Similar to polymorphic single, handled in unflattenObject
|
|
45
|
+
// Polymorphic many: handled in unflattenObject
|
|
52
46
|
}
|
|
53
47
|
}
|
|
54
48
|
} else if (field.type === 'number') {
|
|
55
|
-
// For hasMany number fields, preserve comma-separated strings for later processing
|
|
56
49
|
if (field.hasMany) {
|
|
57
|
-
// Don't convert - let unflattenObject handle comma-separated values
|
|
58
50
|
// @ts-expect-error ref is untyped
|
|
59
51
|
result[`${ref.prefix}${field.name}`] = ({ value })=>value;
|
|
60
52
|
} else {
|
|
61
|
-
// Ensure single numbers are parsed correctly from CSV strings
|
|
62
53
|
// @ts-expect-error ref is untyped
|
|
63
54
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
64
55
|
if (typeof value === 'number') {
|
|
@@ -72,7 +63,6 @@ import { traverseFields } from 'payload';
|
|
|
72
63
|
};
|
|
73
64
|
}
|
|
74
65
|
} else if (field.type === 'checkbox') {
|
|
75
|
-
// Convert string boolean values to actual booleans
|
|
76
66
|
// @ts-expect-error ref is untyped
|
|
77
67
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
78
68
|
if (typeof value === 'boolean') {
|
|
@@ -84,17 +74,14 @@ import { traverseFields } from 'payload';
|
|
|
84
74
|
return Boolean(value);
|
|
85
75
|
};
|
|
86
76
|
} else if (field.type === 'date') {
|
|
87
|
-
// Ensure dates are in proper format
|
|
88
77
|
// @ts-expect-error ref is untyped
|
|
89
78
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
90
79
|
if (!value) {
|
|
91
80
|
return value;
|
|
92
81
|
}
|
|
93
|
-
// If it's already a valid date string, return as-is
|
|
94
82
|
if (typeof value === 'string' && !isNaN(Date.parse(value))) {
|
|
95
83
|
return value;
|
|
96
84
|
}
|
|
97
|
-
// Try to parse and format
|
|
98
85
|
try {
|
|
99
86
|
const date = new Date(value);
|
|
100
87
|
return isNaN(date.getTime()) ? value : date.toISOString();
|
|
@@ -103,7 +90,6 @@ import { traverseFields } from 'payload';
|
|
|
103
90
|
}
|
|
104
91
|
};
|
|
105
92
|
} else if (field.type === 'json' || field.type === 'richText') {
|
|
106
|
-
// Parse JSON strings back to objects (both json and richText fields)
|
|
107
93
|
// @ts-expect-error ref is untyped
|
|
108
94
|
result[`${ref.prefix}${field.name}`] = ({ value })=>{
|
|
109
95
|
if (typeof value === 'object') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getImportFieldFunctions.ts"],"sourcesContent":["import { type FlattenedField, traverseFields, type TraverseFieldsCallback } from 'payload'\n\nimport type { FromCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\n/**\n * Gets custom fromCSV field functions for import.\n * These functions transform field values when unflattening CSV data for import.\n */\nexport const getImportFieldFunctions = ({ fields }: Args): Record<string, FromCSVFunction> => {\n const result: Record<string, FromCSVFunction> = {}\n\n const buildCustomFunctions: TraverseFieldsCallback = ({ field, parentRef, ref }) => {\n // @ts-expect-error ref is untyped\n ref.prefix = parentRef.prefix || ''\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}_`\n }\n\n if (typeof field.custom?.['plugin-import-export']?.fromCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.fromCSV\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single relationship - simple ID to value conversion\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n // If it's already an object (from JSON import), return as-is\n if (typeof value === 'object' && value !== null) {\n return value\n }\n // Convert string/number ID to relationship value\n return value\n }\n } else {\n //
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getImportFieldFunctions.ts"],"sourcesContent":["import { type FlattenedField, traverseFields, type TraverseFieldsCallback } from 'payload'\n\nimport type { FromCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\n/**\n * Gets custom fromCSV field functions for import.\n * These functions transform field values when unflattening CSV data for import.\n */\nexport const getImportFieldFunctions = ({ fields }: Args): Record<string, FromCSVFunction> => {\n const result: Record<string, FromCSVFunction> = {}\n\n const buildCustomFunctions: TraverseFieldsCallback = ({ field, parentRef, ref }) => {\n // @ts-expect-error ref is untyped\n ref.prefix = parentRef.prefix || ''\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}_`\n }\n\n if (typeof field.custom?.['plugin-import-export']?.fromCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.fromCSV\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single relationship - simple ID to value conversion\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n // If it's already an object (from JSON import), return as-is\n if (typeof value === 'object' && value !== null) {\n return value\n }\n // Convert string/number ID to relationship value\n return value\n }\n } else {\n // Polymorphic single: handled in unflattenObject via _id/_relationTo columns\n }\n } else {\n if (!Array.isArray(field.relationTo)) {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (Array.isArray(value)) {\n return value\n }\n return value\n }\n } else {\n // Polymorphic many: handled in unflattenObject\n }\n }\n } else if (field.type === 'number') {\n if (field.hasMany) {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => value\n } else {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (typeof value === 'number') {\n return value\n }\n if (typeof value === 'string') {\n const parsed = parseFloat(value)\n return isNaN(parsed) ? 0 : parsed\n }\n return value\n }\n }\n } else if (field.type === 'checkbox') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (typeof value === 'boolean') {\n return value\n }\n if (typeof value === 'string') {\n return value.toLowerCase() === 'true' || value === '1'\n }\n return Boolean(value)\n }\n } else if (field.type === 'date') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (!value) {\n return value\n }\n if (typeof value === 'string' && !isNaN(Date.parse(value))) {\n return value\n }\n try {\n const date = new Date(value as string)\n return isNaN(date.getTime()) ? value : date.toISOString()\n } catch {\n return value\n }\n }\n } else if (field.type === 'json' || field.type === 'richText') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) => {\n if (typeof value === 'object') {\n return value\n }\n if (typeof value === 'string') {\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n }\n return value\n }\n }\n }\n\n traverseFields({ callback: buildCustomFunctions, fields })\n\n return result\n}\n"],"names":["traverseFields","getImportFieldFunctions","fields","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","fromCSV","hasMany","Array","isArray","relationTo","value","parsed","parseFloat","isNaN","toLowerCase","Boolean","Date","parse","date","getTime","toISOString","JSON","callback"],"mappings":"AAAA,SAA8BA,cAAc,QAAqC,UAAS;AAQ1F;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAAC,EAAEC,MAAM,EAAQ;IACtD,MAAMC,SAA0C,CAAC;IAEjD,MAAMC,uBAA+C,CAAC,EAAEC,KAAK,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC7E,kCAAkC;QAClCA,IAAIC,MAAM,GAAGF,UAAUE,MAAM,IAAI;QACjC,IAAIH,MAAMI,IAAI,KAAK,WAAWJ,MAAMI,IAAI,KAAK,OAAO;YAClD,kCAAkC;YAClC,MAAMC,eAAeJ,WAAWE,SAAS,GAAGF,UAAUE,MAAM,CAAC,CAAC,CAAC,GAAG;YAClE,kCAAkC;YAClCD,IAAIC,MAAM,GAAG,GAAGE,eAAeL,MAAMM,IAAI,CAAC,CAAC,CAAC;QAC9C;QAEA,IAAI,OAAON,MAAMO,MAAM,EAAE,CAAC,uBAAuB,EAAEC,YAAY,YAAY;YACzE,kCAAkC;YAClCV,MAAM,CAAC,GAAGI,IAAIC,MAAM,G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KAAK,CAACP;oBACpB,EAAE,OAAM;wBACN,OAAOA;oBACT;gBACF;gBACA,OAAOA;YACT;QACF;IACF;IAEAlB,eAAe;QAAE8B,UAAU1B;QAAsBF;IAAO;IAExD,OAAOC;AACT,EAAC"}
|
|
@@ -27,6 +27,7 @@ export type PluginCollectionsResult = {
|
|
|
27
27
|
* - Applies top-level overrideExportCollection/overrideImportCollection if provided
|
|
28
28
|
* - For each collection in `pluginConfig.collections` that has a function override
|
|
29
29
|
* for `export` or `import`, applies the override to create customized collections
|
|
30
|
+
* - Applies settings from collections without overrideCollection to the base collection
|
|
30
31
|
*
|
|
31
32
|
* @param config - The Payload config
|
|
32
33
|
* @param pluginConfig - The import/export plugin config
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPluginCollections.d.ts","sourceRoot":"","sources":["../../src/utilities/getPluginCollections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAA8B,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAKvF,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC;;;OAGG;IACH,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;IACrC;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;CACtC,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"getPluginCollections.d.ts","sourceRoot":"","sources":["../../src/utilities/getPluginCollections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAA8B,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAKvF,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC;;;OAGG;IACH,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;IACrC;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;CACtC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,8BAG9B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,OAAO,CAAC,uBAAuB,CA8JlC,CAAA"}
|
|
@@ -7,12 +7,12 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
7
7
|
* - Applies top-level overrideExportCollection/overrideImportCollection if provided
|
|
8
8
|
* - For each collection in `pluginConfig.collections` that has a function override
|
|
9
9
|
* for `export` or `import`, applies the override to create customized collections
|
|
10
|
+
* - Applies settings from collections without overrideCollection to the base collection
|
|
10
11
|
*
|
|
11
12
|
* @param config - The Payload config
|
|
12
13
|
* @param pluginConfig - The import/export plugin config
|
|
13
14
|
* @returns Object containing arrays of export and import collections
|
|
14
15
|
*/ export const getPluginCollections = async ({ config, pluginConfig })=>{
|
|
15
|
-
// Get the base export and import collections with default configs (no per-collection settings)
|
|
16
16
|
let baseExportCollection = getExportCollection({
|
|
17
17
|
config,
|
|
18
18
|
pluginConfig
|
|
@@ -21,7 +21,6 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
21
21
|
config,
|
|
22
22
|
pluginConfig
|
|
23
23
|
});
|
|
24
|
-
// Apply top-level collection overrides if provided
|
|
25
24
|
if (pluginConfig.overrideExportCollection && typeof pluginConfig.overrideExportCollection === 'function') {
|
|
26
25
|
baseExportCollection = await pluginConfig.overrideExportCollection({
|
|
27
26
|
collection: baseExportCollection
|
|
@@ -34,14 +33,11 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
34
33
|
}
|
|
35
34
|
const exportCollections = [];
|
|
36
35
|
const importCollections = [];
|
|
37
|
-
// Maps from target collection slug to the export/import collection slug to use
|
|
38
36
|
const customExportSlugMap = new Map();
|
|
39
37
|
const customImportSlugMap = new Map();
|
|
40
38
|
// Process each collection config for custom collection overrides
|
|
41
39
|
if (pluginConfig.collections && pluginConfig.collections.length > 0) {
|
|
42
40
|
for (const collectionConfig of pluginConfig.collections){
|
|
43
|
-
// Handle export config - only process if overrideCollection is provided
|
|
44
|
-
// Settings like disableJobsQueue require a custom slug to work properly
|
|
45
41
|
const exportConfig = typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined;
|
|
46
42
|
if (exportConfig?.overrideCollection) {
|
|
47
43
|
// Generate a collection with this export config's settings (like disableJobsQueue)
|
|
@@ -55,16 +51,20 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
55
51
|
});
|
|
56
52
|
// If the slug changed, this is a separate collection; otherwise it modifies the base
|
|
57
53
|
if (customExport.slug !== baseExportCollection.slug) {
|
|
54
|
+
// Store the source collection slug so CollectionField can use it as default
|
|
55
|
+
customExport.admin = {
|
|
56
|
+
...customExport.admin,
|
|
57
|
+
custom: {
|
|
58
|
+
...customExport.admin?.custom,
|
|
59
|
+
defaultCollectionSlug: collectionConfig.slug
|
|
60
|
+
}
|
|
61
|
+
};
|
|
58
62
|
exportCollections.push(customExport);
|
|
59
|
-
// Map this target collection to its custom export collection
|
|
60
63
|
customExportSlugMap.set(collectionConfig.slug, customExport.slug);
|
|
61
64
|
} else {
|
|
62
|
-
// Full override - replace the base
|
|
63
65
|
baseExportCollection = customExport;
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
// Handle import config - only process if overrideCollection is provided
|
|
67
|
-
// Settings like disableJobsQueue require a custom slug to work properly
|
|
68
68
|
const importConf = typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined;
|
|
69
69
|
if (importConf?.overrideCollection) {
|
|
70
70
|
// Generate a collection with this import config's settings (like disableJobsQueue)
|
|
@@ -78,6 +78,14 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
78
78
|
});
|
|
79
79
|
// If the slug changed, this is a separate collection; otherwise it modifies the base
|
|
80
80
|
if (customImport.slug !== baseImportCollection.slug) {
|
|
81
|
+
// Store the source collection slug so CollectionField can use it as default
|
|
82
|
+
customImport.admin = {
|
|
83
|
+
...customImport.admin,
|
|
84
|
+
custom: {
|
|
85
|
+
...customImport.admin?.custom,
|
|
86
|
+
defaultCollectionSlug: collectionConfig.slug
|
|
87
|
+
}
|
|
88
|
+
};
|
|
81
89
|
importCollections.push(customImport);
|
|
82
90
|
// Map this target collection to its custom import collection
|
|
83
91
|
customImportSlugMap.set(collectionConfig.slug, customImport.slug);
|
|
@@ -88,7 +96,48 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
}
|
|
91
|
-
//
|
|
99
|
+
// Apply settings from collections without overrideCollection to the base collection
|
|
100
|
+
// This is done AFTER all overrides so these settings take precedence
|
|
101
|
+
if (pluginConfig.collections && pluginConfig.collections.length > 0) {
|
|
102
|
+
let mergedExportSettings = {};
|
|
103
|
+
let mergedImportSettings = {};
|
|
104
|
+
for (const collectionConfig of pluginConfig.collections){
|
|
105
|
+
const exportConf = typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined;
|
|
106
|
+
const importConf = typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined;
|
|
107
|
+
if (exportConf && !exportConf.overrideCollection) {
|
|
108
|
+
mergedExportSettings = {
|
|
109
|
+
...mergedExportSettings,
|
|
110
|
+
...exportConf
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (importConf && !importConf.overrideCollection) {
|
|
114
|
+
mergedImportSettings = {
|
|
115
|
+
...mergedImportSettings,
|
|
116
|
+
...importConf
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (mergedExportSettings.format !== undefined || mergedExportSettings.disableSave !== undefined || mergedExportSettings.disableDownload !== undefined) {
|
|
121
|
+
baseExportCollection = {
|
|
122
|
+
...baseExportCollection,
|
|
123
|
+
admin: {
|
|
124
|
+
...baseExportCollection.admin,
|
|
125
|
+
custom: {
|
|
126
|
+
...baseExportCollection.admin?.custom,
|
|
127
|
+
...mergedExportSettings.disableDownload !== undefined && {
|
|
128
|
+
disableDownload: mergedExportSettings.disableDownload
|
|
129
|
+
},
|
|
130
|
+
...mergedExportSettings.disableSave !== undefined && {
|
|
131
|
+
disableSave: mergedExportSettings.disableSave
|
|
132
|
+
},
|
|
133
|
+
...mergedExportSettings.format !== undefined && {
|
|
134
|
+
format: mergedExportSettings.format
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
92
141
|
exportCollections.unshift(baseExportCollection);
|
|
93
142
|
importCollections.unshift(baseImportCollection);
|
|
94
143
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getPluginCollections.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload'\n\nimport type { ExportConfig, ImportConfig, ImportExportPluginConfig } from '../types.js'\n\nimport { getExportCollection } from '../export/getExportCollection.js'\nimport { getImportCollection } from '../import/getImportCollection.js'\n\nexport type PluginCollectionsResult = {\n /**\n * Map from target collection slug to the export collection slug to use for it.\n * Only contains entries for collections with custom export collection overrides.\n */\n customExportSlugMap: Map<string, string>\n /**\n * Map from target collection slug to the import collection slug to use for it.\n * Only contains entries for collections with custom import collection overrides.\n */\n customImportSlugMap: Map<string, string>\n /**\n * All export collections (base + any per-collection overrides)\n */\n exportCollections: CollectionConfig[]\n /**\n * All import collections (base + any per-collection overrides)\n */\n importCollections: CollectionConfig[]\n}\n\n/**\n * Processes the plugin config and returns export/import collections.\n *\n * - Creates the base export and import collections\n * - Applies top-level overrideExportCollection/overrideImportCollection if provided\n * - For each collection in `pluginConfig.collections` that has a function override\n * for `export` or `import`, applies the override to create customized collections\n *\n * @param config - The Payload config\n * @param pluginConfig - The import/export plugin config\n * @returns Object containing arrays of export and import collections\n */\nexport const getPluginCollections = async ({\n config,\n pluginConfig,\n}: {\n config: Config\n pluginConfig: ImportExportPluginConfig\n}): Promise<PluginCollectionsResult> => {\n // Get the base export and import collections with default configs (no per-collection settings)\n let baseExportCollection = getExportCollection({\n config,\n pluginConfig,\n })\n let baseImportCollection = getImportCollection({\n config,\n pluginConfig,\n })\n\n // Apply top-level collection overrides if provided\n if (\n pluginConfig.overrideExportCollection &&\n typeof pluginConfig.overrideExportCollection === 'function'\n ) {\n baseExportCollection = await pluginConfig.overrideExportCollection({\n collection: baseExportCollection,\n })\n }\n\n if (\n pluginConfig.overrideImportCollection &&\n typeof pluginConfig.overrideImportCollection === 'function'\n ) {\n baseImportCollection = await pluginConfig.overrideImportCollection({\n collection: baseImportCollection,\n })\n }\n\n const exportCollections: CollectionConfig[] = []\n const importCollections: CollectionConfig[] = []\n\n // Maps from target collection slug to the export/import collection slug to use\n const customExportSlugMap = new Map<string, string>()\n const customImportSlugMap = new Map<string, string>()\n\n // Process each collection config for custom collection overrides\n if (pluginConfig.collections && pluginConfig.collections.length > 0) {\n for (const collectionConfig of pluginConfig.collections) {\n // Handle export config - only process if overrideCollection is provided\n // Settings like disableJobsQueue require a custom slug to work properly\n const exportConfig =\n typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined\n if (exportConfig?.overrideCollection) {\n // Generate a collection with this export config's settings (like disableJobsQueue)\n const collectionWithSettings = getExportCollection({\n config,\n exportConfig,\n pluginConfig,\n })\n\n const customExport = await exportConfig.overrideCollection({\n collection: collectionWithSettings,\n })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (customExport.slug !== baseExportCollection.slug) {\n exportCollections.push(customExport)\n // Map this target collection to its custom export collection\n customExportSlugMap.set(collectionConfig.slug, customExport.slug)\n } else {\n // Full override - replace the base\n baseExportCollection = customExport\n }\n }\n\n // Handle import config - only process if overrideCollection is provided\n // Settings like disableJobsQueue require a custom slug to work properly\n const importConf =\n typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined\n if (importConf?.overrideCollection) {\n // Generate a collection with this import config's settings (like disableJobsQueue)\n const collectionWithSettings = getImportCollection({\n config,\n importConfig: importConf,\n pluginConfig,\n })\n\n const customImport = await importConf.overrideCollection({\n collection: collectionWithSettings,\n })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (customImport.slug !== baseImportCollection.slug) {\n importCollections.push(customImport)\n // Map this target collection to its custom import collection\n customImportSlugMap.set(collectionConfig.slug, customImport.slug)\n } else {\n // Full override - replace the base\n baseImportCollection = customImport\n }\n }\n }\n }\n\n // Add base collections to the front of the arrays\n exportCollections.unshift(baseExportCollection)\n importCollections.unshift(baseImportCollection)\n\n return {\n customExportSlugMap,\n customImportSlugMap,\n exportCollections,\n importCollections,\n }\n}\n"],"names":["getExportCollection","getImportCollection","getPluginCollections","config","pluginConfig","baseExportCollection","baseImportCollection","overrideExportCollection","collection","overrideImportCollection","exportCollections","importCollections","customExportSlugMap","Map","customImportSlugMap","collections","length","collectionConfig","exportConfig","export","undefined","overrideCollection","collectionWithSettings","customExport","slug","push","set","importConf","import","importConfig","customImport","unshift"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,mCAAkC;AACtE,SAASC,mBAAmB,QAAQ,mCAAkC;AAuBtE;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,MAAM,EACNC,YAAY,EAIb;IACC,+FAA+F;IAC/F,IAAIC,uBAAuBL,oBAAoB;QAC7CG;QACAC;IACF;IACA,IAAIE,uBAAuBL,oBAAoB;QAC7CE;QACAC;IACF;IAEA,mDAAmD;IACnD,IACEA,aAAaG,wBAAwB,IACrC,OAAOH,aAAaG,wBAAwB,KAAK,YACjD;QACAF,uBAAuB,MAAMD,aAAaG,wBAAwB,CAAC;YACjEC,Y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AYc;gBACd;gBAEA,qFAAqF;gBACrF,IAAIQ,aAAaN,IAAI,KAAKlB,qBAAqBkB,IAAI,EAAE;oBACnDb,kBAAkBc,IAAI,CAACK;oBACvB,6DAA6D;oBAC7DhB,oBAAoBY,GAAG,CAACT,iBAAiBO,IAAI,EAAEM,aAAaN,IAAI;gBAClE,OAAO;oBACL,mCAAmC;oBACnClB,uBAAuBwB;gBACzB;YACF;QACF;IACF;IAEA,kDAAkD;IAClDpB,kBAAkBqB,OAAO,CAAC1B;IAC1BM,kBAAkBoB,OAAO,CAACzB;IAE1B,OAAO;QACLM;QACAE;QACAJ;QACAC;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getPluginCollections.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload'\n\nimport type { ExportConfig, ImportConfig, ImportExportPluginConfig } from '../types.js'\n\nimport { getExportCollection } from '../export/getExportCollection.js'\nimport { getImportCollection } from '../import/getImportCollection.js'\n\nexport type PluginCollectionsResult = {\n /**\n * Map from target collection slug to the export collection slug to use for it.\n * Only contains entries for collections with custom export collection overrides.\n */\n customExportSlugMap: Map<string, string>\n /**\n * Map from target collection slug to the import collection slug to use for it.\n * Only contains entries for collections with custom import collection overrides.\n */\n customImportSlugMap: Map<string, string>\n /**\n * All export collections (base + any per-collection overrides)\n */\n exportCollections: CollectionConfig[]\n /**\n * All import collections (base + any per-collection overrides)\n */\n importCollections: CollectionConfig[]\n}\n\n/**\n * Processes the plugin config and returns export/import collections.\n *\n * - Creates the base export and import collections\n * - Applies top-level overrideExportCollection/overrideImportCollection if provided\n * - For each collection in `pluginConfig.collections` that has a function override\n * for `export` or `import`, applies the override to create customized collections\n * - Applies settings from collections without overrideCollection to the base collection\n *\n * @param config - The Payload config\n * @param pluginConfig - The import/export plugin config\n * @returns Object containing arrays of export and import collections\n */\nexport const getPluginCollections = async ({\n config,\n pluginConfig,\n}: {\n config: Config\n pluginConfig: ImportExportPluginConfig\n}): Promise<PluginCollectionsResult> => {\n let baseExportCollection = getExportCollection({\n config,\n pluginConfig,\n })\n let baseImportCollection = getImportCollection({\n config,\n pluginConfig,\n })\n\n if (\n pluginConfig.overrideExportCollection &&\n typeof pluginConfig.overrideExportCollection === 'function'\n ) {\n baseExportCollection = await pluginConfig.overrideExportCollection({\n collection: baseExportCollection,\n })\n }\n\n if (\n pluginConfig.overrideImportCollection &&\n typeof pluginConfig.overrideImportCollection === 'function'\n ) {\n baseImportCollection = await pluginConfig.overrideImportCollection({\n collection: baseImportCollection,\n })\n }\n\n const exportCollections: CollectionConfig[] = []\n const importCollections: CollectionConfig[] = []\n\n const customExportSlugMap = new Map<string, string>()\n const customImportSlugMap = new Map<string, string>()\n\n // Process each collection config for custom collection overrides\n if (pluginConfig.collections && pluginConfig.collections.length > 0) {\n for (const collectionConfig of pluginConfig.collections) {\n const exportConfig =\n typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined\n if (exportConfig?.overrideCollection) {\n // Generate a collection with this export config's settings (like disableJobsQueue)\n const collectionWithSettings = getExportCollection({\n config,\n exportConfig,\n pluginConfig,\n })\n\n const customExport = await exportConfig.overrideCollection({\n collection: collectionWithSettings,\n })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (customExport.slug !== baseExportCollection.slug) {\n // Store the source collection slug so CollectionField can use it as default\n customExport.admin = {\n ...customExport.admin,\n custom: {\n ...customExport.admin?.custom,\n defaultCollectionSlug: collectionConfig.slug,\n },\n }\n exportCollections.push(customExport)\n customExportSlugMap.set(collectionConfig.slug, customExport.slug)\n } else {\n baseExportCollection = customExport\n }\n }\n\n const importConf =\n typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined\n if (importConf?.overrideCollection) {\n // Generate a collection with this import config's settings (like disableJobsQueue)\n const collectionWithSettings = getImportCollection({\n config,\n importConfig: importConf,\n pluginConfig,\n })\n\n const customImport = await importConf.overrideCollection({\n collection: collectionWithSettings,\n })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (customImport.slug !== baseImportCollection.slug) {\n // Store the source collection slug so CollectionField can use it as default\n customImport.admin = {\n ...customImport.admin,\n custom: {\n ...customImport.admin?.custom,\n defaultCollectionSlug: collectionConfig.slug,\n },\n }\n importCollections.push(customImport)\n // Map this target collection to its custom import collection\n customImportSlugMap.set(collectionConfig.slug, customImport.slug)\n } else {\n // Full override - replace the base\n baseImportCollection = customImport\n }\n }\n }\n }\n\n // Apply settings from collections without overrideCollection to the base collection\n // This is done AFTER all overrides so these settings take precedence\n if (pluginConfig.collections && pluginConfig.collections.length > 0) {\n let mergedExportSettings: Partial<ExportConfig> = {}\n let mergedImportSettings: Partial<ImportConfig> = {}\n\n for (const collectionConfig of pluginConfig.collections) {\n const exportConf =\n typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined\n const importConf =\n typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined\n\n if (exportConf && !exportConf.overrideCollection) {\n mergedExportSettings = { ...mergedExportSettings, ...exportConf }\n }\n if (importConf && !importConf.overrideCollection) {\n mergedImportSettings = { ...mergedImportSettings, ...importConf }\n }\n }\n\n if (\n mergedExportSettings.format !== undefined ||\n mergedExportSettings.disableSave !== undefined ||\n mergedExportSettings.disableDownload !== undefined\n ) {\n baseExportCollection = {\n ...baseExportCollection,\n admin: {\n ...baseExportCollection.admin,\n custom: {\n ...baseExportCollection.admin?.custom,\n ...(mergedExportSettings.disableDownload !== undefined && {\n disableDownload: mergedExportSettings.disableDownload,\n }),\n ...(mergedExportSettings.disableSave !== undefined && {\n disableSave: mergedExportSettings.disableSave,\n }),\n ...(mergedExportSettings.format !== undefined && {\n format: mergedExportSettings.format,\n }),\n },\n },\n }\n }\n }\n\n exportCollections.unshift(baseExportCollection)\n importCollections.unshift(baseImportCollection)\n\n return {\n customExportSlugMap,\n customImportSlugMap,\n exportCollections,\n importCollections,\n }\n}\n"],"names":["getExportCollection","getImportCollection","getPluginCollections","config","pluginConfig","baseExportCollection","baseImportCollection","overrideExportCollection","collection","overrideImportCollection","exportCollections","importCollections","customExportSlugMap","Map","customImportSlugMap","collections","length","collectionConfig","exportConfig","export","undefined","overrideCollection","collectionWithSettings","customExport","slug","admin","custom","defaultCollectionSlug","push","set","importConf","import","importConfig","customImport","mergedExportSettings","mergedImportSettings","exportConf","format","disableSave","disableDownload","unshift"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,mCAAkC;AACtE,SAASC,mBAAmB,QAAQ,mCAAkC;AAuBtE;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,MAAM,EACNC,YAAY,EAIb;IACC,IAAIC,uBAAuBL,oBAAoB;QAC7CG;QACAC;IACF;IACA,IAAIE,uBAAuBL,oBAAoB;QAC7CE;QACAC;IACF;IAEA,IACEA,aAAaG,wBAAwB,IACrC,OAAOH,aAAaG,wBAAwB,KAAK,YACjD;QACAF,uBAAuB,MAAMD,aAAaG,wBAAwB,CAAC;YACjEC,YAAYH;QACd;IACF;IAEA,IACED,aAAaK,wBAAwB,IACrC,OAAOL,aAAaK,wBAAwB,KAAK,YACjD;QACAH,uBAAuB,MAAMF,aAAaK,wBAAwB,CAAC;YACjED,YAAYF;QACd;IACF;IAEA,MAAMI,oBAAwC,EAAE;IAChD,MAAMC,oBAAwC,EAAE;IAEhD,MAAMC,sBAAsB,IAAIC;IAChC,MAAMC,sBAAsB,IAAID;IAEhC,iEAAiE;IACjE,IAAIT,aAAaW,WAAW,IAAIX,aAAaW,WAAW,CAACC,MAAM,GAAG,GAAG;QACnE,KAAK,MAAMC,oBAAoBb,aAAaW,WAAW,CAAE;YACvD,MAAMG,eACJ,OAAOD,iBAAiBE,MAAM,KAAK,WAAWF,iBAAiBE,MAAM,GAAGC;YAC1E,IAAIF,cAAcG,oBAAoB;gBACpC,mFAAmF;gBACnF,MAAMC,yBAAyBtB,oBAAoB;oBACjDG;oBACAe;oBACAd;gBACF;gBAEA,MAAMmB,eAAe,MAAML,aAAaG,kBAAkB,CAAC;oBACzDb,YAAYc;gBAC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