@payloadcms/plugin-import-export 3.77.0-internal.8cf758f → 3.77.0-internal.fd50432
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 +2 -2
- package/dist/components/CollectionField/index.d.ts.map +1 -1
- package/dist/components/CollectionField/index.js +5 -28
- package/dist/components/CollectionField/index.js.map +1 -1
- package/dist/components/CollectionSelectField/index.d.ts +13 -0
- package/dist/components/CollectionSelectField/index.d.ts.map +1 -0
- package/dist/components/CollectionSelectField/index.js +159 -0
- package/dist/components/CollectionSelectField/index.js.map +1 -0
- package/dist/components/ExportListMenuItem/index.d.ts.map +1 -1
- package/dist/components/ExportListMenuItem/index.js +5 -1
- package/dist/components/ExportListMenuItem/index.js.map +1 -1
- package/dist/components/ExportPreview/index.d.ts.map +1 -1
- package/dist/components/ExportPreview/index.js.map +1 -1
- package/dist/components/FieldsToExport/index.js +1 -1
- package/dist/components/FieldsToExport/index.js.map +1 -1
- package/dist/components/ImportPreview/index.d.ts.map +1 -1
- package/dist/components/ImportPreview/index.js +50 -30
- package/dist/components/ImportPreview/index.js.map +1 -1
- package/dist/export/createExport.d.ts +1 -2
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +4 -10
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
- package/dist/export/getCreateExportCollectionTask.js +12 -1
- package/dist/export/getCreateExportCollectionTask.js.map +1 -1
- package/dist/export/getExportCollection.d.ts +5 -1
- package/dist/export/getExportCollection.d.ts.map +1 -1
- package/dist/export/getExportCollection.js +20 -5
- package/dist/export/getExportCollection.js.map +1 -1
- package/dist/export/getFields.d.ts +7 -1
- package/dist/export/getFields.d.ts.map +1 -1
- package/dist/export/getFields.js +15 -3
- package/dist/export/getFields.js.map +1 -1
- package/dist/export/handlePreview.d.ts.map +1 -1
- package/dist/export/handlePreview.js +34 -17
- package/dist/export/handlePreview.js.map +1 -1
- package/dist/exports/rsc.d.ts +0 -1
- package/dist/exports/rsc.d.ts.map +1 -1
- package/dist/exports/rsc.js +0 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/import/batchProcessor.d.ts.map +1 -1
- package/dist/import/batchProcessor.js +9 -3
- package/dist/import/batchProcessor.js.map +1 -1
- package/dist/import/getFields.d.ts +7 -3
- package/dist/import/getFields.d.ts.map +1 -1
- package/dist/import/getFields.js +12 -7
- package/dist/import/getFields.js.map +1 -1
- package/dist/import/getImportCollection.d.ts +6 -3
- package/dist/import/getImportCollection.d.ts.map +1 -1
- package/dist/import/getImportCollection.js +7 -4
- package/dist/import/getImportCollection.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/utilities/filterToSelectedFields.spec.js +204 -0
- package/dist/utilities/filterToSelectedFields.spec.js.map +1 -0
- package/dist/utilities/flattenObject.d.ts +1 -7
- package/dist/utilities/flattenObject.d.ts.map +1 -1
- package/dist/utilities/flattenObject.js +14 -25
- package/dist/utilities/flattenObject.js.map +1 -1
- package/dist/utilities/getFilename.d.ts +1 -1
- package/dist/utilities/getFilename.js +3 -3
- package/dist/utilities/getFilename.js.map +1 -1
- package/dist/utilities/getPluginCollections.d.ts.map +1 -1
- package/dist/utilities/getPluginCollections.js +106 -34
- package/dist/utilities/getPluginCollections.js.map +1 -1
- package/dist/utilities/getSchemaColumns.d.ts +11 -7
- package/dist/utilities/getSchemaColumns.d.ts.map +1 -1
- package/dist/utilities/getSchemaColumns.js +35 -77
- package/dist/utilities/getSchemaColumns.js.map +1 -1
- package/dist/utilities/getSchemaColumns.spec.js +157 -0
- package/dist/utilities/getSchemaColumns.spec.js.map +1 -0
- package/dist/utilities/parseCSV.d.ts.map +1 -1
- package/dist/utilities/parseCSV.js +1 -0
- package/dist/utilities/parseCSV.js.map +1 -1
- package/dist/utilities/parseCSV.spec.js +26 -0
- package/dist/utilities/parseCSV.spec.js.map +1 -1
- package/package.json +7 -7
- package/dist/components/ImportCollectionField/index.d.ts +0 -3
- package/dist/components/ImportCollectionField/index.d.ts.map +0 -1
- package/dist/components/ImportCollectionField/index.js +0 -17
- package/dist/components/ImportCollectionField/index.js.map +0 -1
- package/dist/utilities/collectTimezoneCompanionFields.d.ts +0 -24
- package/dist/utilities/collectTimezoneCompanionFields.d.ts.map +0 -1
- package/dist/utilities/collectTimezoneCompanionFields.js +0 -89
- package/dist/utilities/collectTimezoneCompanionFields.js.map +0 -1
- package/dist/utilities/collectTimezoneCompanionFields.spec.js +0 -319
- package/dist/utilities/collectTimezoneCompanionFields.spec.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fieldToRegex } from './fieldToRegex.js';
|
|
2
|
-
export const flattenObject = ({ doc, fields, prefix,
|
|
2
|
+
export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
3
3
|
const row = {};
|
|
4
4
|
// Helper to get toCSV function by full path or base field name
|
|
5
5
|
// This allows functions registered for field names (e.g., 'richText') to work
|
|
@@ -7,13 +7,19 @@ export const flattenObject = ({ doc, fields, prefix, timezoneCompanionFields, to
|
|
|
7
7
|
const getToCSVFunction = (fullPath, baseFieldName)=>{
|
|
8
8
|
return toCSVFunctions?.[fullPath] ?? toCSVFunctions?.[baseFieldName];
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
// When fields are selected, build a set of top-level document keys to process.
|
|
11
|
+
// This prevents sibling fields with similar prefixes from being included
|
|
12
|
+
// (e.g. selecting 'dateWithTimezone' won't pull in 'dateWithTimezone_tz')
|
|
13
|
+
const selectedTopLevelKeys = Array.isArray(fields) && fields.length > 0 ? new Set(fields.map((f)=>f.split('.')[0])) : undefined;
|
|
14
|
+
const flattenWithFilter = (siblingDoc, currentPrefix)=>{
|
|
11
15
|
Object.entries(siblingDoc).forEach(([key, value])=>{
|
|
12
|
-
|
|
16
|
+
// At the document root, skip keys that don't match any selected field
|
|
17
|
+
if (!currentPrefix && selectedTopLevelKeys && !selectedTopLevelKeys.has(key)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const newKey = currentPrefix ? `${currentPrefix}_${key}` : key;
|
|
13
21
|
const toCSVFn = getToCSVFunction(newKey, key);
|
|
14
22
|
if (Array.isArray(value)) {
|
|
15
|
-
// If a custom toCSV function exists for this array field, run it first.
|
|
16
|
-
// If it produces output, skip per-item handling; otherwise, fall back.
|
|
17
23
|
if (toCSVFn) {
|
|
18
24
|
try {
|
|
19
25
|
const result = toCSVFn({
|
|
@@ -25,17 +31,14 @@ export const flattenObject = ({ doc, fields, prefix, timezoneCompanionFields, to
|
|
|
25
31
|
value
|
|
26
32
|
});
|
|
27
33
|
if (typeof result !== 'undefined') {
|
|
28
|
-
// Custom function returned a single value for this array field.
|
|
29
34
|
row[newKey] = result;
|
|
30
35
|
return;
|
|
31
36
|
}
|
|
32
|
-
// If the custom function wrote any keys for this field, consider it handled.
|
|
33
37
|
for(const k in row){
|
|
34
38
|
if (k === newKey || k.startsWith(`${newKey}_`)) {
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
|
-
// Otherwise, fall through to per-item handling.
|
|
39
42
|
} catch (error) {
|
|
40
43
|
throw new Error(`Error in toCSVFunction for array "${newKey}": ${JSON.stringify(value)}\n${error.message}`);
|
|
41
44
|
}
|
|
@@ -44,23 +47,19 @@ export const flattenObject = ({ doc, fields, prefix, timezoneCompanionFields, to
|
|
|
44
47
|
if (typeof item === 'object' && item !== null) {
|
|
45
48
|
const blockType = typeof item.blockType === 'string' ? item.blockType : undefined;
|
|
46
49
|
const itemPrefix = blockType ? `${newKey}_${index}_${blockType}` : `${newKey}_${index}`;
|
|
47
|
-
// Case: hasMany polymorphic relationships
|
|
48
50
|
if ('relationTo' in item && 'value' in item && typeof item.value === 'object' && item.value !== null) {
|
|
49
51
|
row[`${itemPrefix}_relationTo`] = item.relationTo;
|
|
50
52
|
row[`${itemPrefix}_id`] = item.value.id;
|
|
51
53
|
return;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
flatten(item, itemPrefix);
|
|
55
|
+
flattenWithFilter(item, itemPrefix);
|
|
55
56
|
} else {
|
|
56
|
-
// Primitive array item.
|
|
57
57
|
row[`${newKey}_${index}`] = item;
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
} else if (typeof value === 'object' && value !== null) {
|
|
61
|
-
// Object field: use custom toCSV if present, else recurse.
|
|
62
61
|
if (!toCSVFn) {
|
|
63
|
-
|
|
62
|
+
flattenWithFilter(value, newKey);
|
|
64
63
|
} else {
|
|
65
64
|
try {
|
|
66
65
|
const result = toCSVFn({
|
|
@@ -101,7 +100,7 @@ export const flattenObject = ({ doc, fields, prefix, timezoneCompanionFields, to
|
|
|
101
100
|
}
|
|
102
101
|
});
|
|
103
102
|
};
|
|
104
|
-
|
|
103
|
+
flattenWithFilter(doc, prefix);
|
|
105
104
|
if (Array.isArray(fields) && fields.length > 0) {
|
|
106
105
|
const orderedResult = {};
|
|
107
106
|
// Build all field regexes once
|
|
@@ -109,12 +108,6 @@ export const flattenObject = ({ doc, fields, prefix, timezoneCompanionFields, to
|
|
|
109
108
|
field,
|
|
110
109
|
regex: fieldToRegex(field)
|
|
111
110
|
}));
|
|
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
111
|
// Single pass through row keys - O(keys * fields) regex tests but only one iteration
|
|
119
112
|
const rowKeys = Object.keys(row);
|
|
120
113
|
// Process in field order to maintain user's specified ordering
|
|
@@ -124,10 +117,6 @@ export const flattenObject = ({ doc, fields, prefix, timezoneCompanionFields, to
|
|
|
124
117
|
if (key in orderedResult) {
|
|
125
118
|
continue;
|
|
126
119
|
}
|
|
127
|
-
// Skip auto-generated timezone companion fields unless explicitly selected
|
|
128
|
-
if (timezoneCompanionFields?.has(key) && !explicitlySelectedTimezoneFields.has(key)) {
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
120
|
if (regex.test(key)) {
|
|
132
121
|
orderedResult[key] = row[key];
|
|
133
122
|
}
|
|
@@ -1 +1 @@
|
|
|
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+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;IAE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;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
|
+
{"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 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 // When fields are selected, build a set of top-level document keys to process.\n // This prevents sibling fields with similar prefixes from being included\n // (e.g. selecting 'dateWithTimezone' won't pull in 'dateWithTimezone_tz')\n const selectedTopLevelKeys =\n Array.isArray(fields) && fields.length > 0\n ? new Set(fields.map((f) => f.split('.')[0]))\n : undefined\n\n const flattenWithFilter = (siblingDoc: Document, currentPrefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n // At the document root, skip keys that don't match any selected field\n if (!currentPrefix && selectedTopLevelKeys && !selectedTopLevelKeys.has(key)) {\n return\n }\n\n const newKey = currentPrefix ? `${currentPrefix}_${key}` : key\n const toCSVFn = getToCSVFunction(newKey, key)\n\n if (Array.isArray(value)) {\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\n if (typeof result !== 'undefined') {\n row[newKey] = result\n return\n }\n\n for (const k in row) {\n if (k === newKey || k.startsWith(`${newKey}_`)) {\n return\n }\n }\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 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 flattenWithFilter(item, itemPrefix)\n } else {\n row[`${newKey}_${index}`] = item\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n if (!toCSVFn) {\n flattenWithFilter(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 flattenWithFilter(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 // 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 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","toCSVFunctions","row","getToCSVFunction","fullPath","baseFieldName","selectedTopLevelKeys","Array","isArray","length","Set","map","f","split","undefined","flattenWithFilter","siblingDoc","currentPrefix","Object","entries","forEach","key","value","has","newKey","toCSVFn","result","columnName","data","k","startsWith","error","Error","JSON","stringify","message","item","index","blockType","itemPrefix","relationTo","id","orderedResult","fieldPat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* Format: "YYYY-MM-
|
|
3
|
+
* Format: "YYYY-MM-DD_HH-MM-SS" (filesystem-safe characters)
|
|
4
4
|
*/ export const getFilename = ()=>{
|
|
5
5
|
const now = new Date();
|
|
6
6
|
const yyymmdd = now.toISOString().split('T')[0] // "YYYY-MM-DD"
|
|
7
7
|
;
|
|
8
|
-
const hhmmss = now.toTimeString().split(' ')[0] // "HH
|
|
8
|
+
const hhmmss = now.toTimeString().split(' ')[0]?.replace(/:/g, '-') || '' // "HH-MM-SS"
|
|
9
9
|
;
|
|
10
|
-
return `${yyymmdd}
|
|
10
|
+
return `${yyymmdd}_${hhmmss}`;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
//# sourceMappingURL=getFilename.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getFilename.ts"],"sourcesContent":["/**\n * Generates a filename based on current date and time.\n * Format: \"YYYY-MM-
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getFilename.ts"],"sourcesContent":["/**\n * Generates a filename based on current date and time.\n * Format: \"YYYY-MM-DD_HH-MM-SS\" (filesystem-safe characters)\n */\nexport const getFilename = () => {\n const now = new Date()\n const yyymmdd = now.toISOString().split('T')[0] // \"YYYY-MM-DD\"\n const hhmmss = now.toTimeString().split(' ')[0]?.replace(/:/g, '-') || '' // \"HH-MM-SS\"\n\n return `${yyymmdd}_${hhmmss}`\n}\n"],"names":["getFilename","now","Date","yyymmdd","toISOString","split","hhmmss","toTimeString","replace"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,cAAc;IACzB,MAAMC,MAAM,IAAIC;IAChB,MAAMC,UAAUF,IAAIG,WAAW,GAAGC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe;;IAC/D,MAAMC,SAASL,IAAIM,YAAY,GAAGF,KAAK,CAAC,IAAI,CAAC,EAAE,EAAEG,QAAQ,MAAM,QAAQ,GAAG,aAAa;;IAEvF,OAAO,GAAGL,QAAQ,CAAC,EAAEG,QAAQ;AAC/B,EAAC"}
|
|
@@ -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;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,8BAG9B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,OAAO,CAAC,uBAAuB,
|
|
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,CAuOlC,CAAA"}
|
|
@@ -13,12 +13,27 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
13
13
|
* @param pluginConfig - The import/export plugin config
|
|
14
14
|
* @returns Object containing arrays of export and import collections
|
|
15
15
|
*/ export const getPluginCollections = async ({ config, pluginConfig })=>{
|
|
16
|
+
// Calculate collection slugs for base export/import collections
|
|
17
|
+
// If pluginConfig.collections is provided, filter by export/import !== false
|
|
18
|
+
// Otherwise, use all config collections
|
|
19
|
+
let baseExportSlugs;
|
|
20
|
+
let baseImportSlugs;
|
|
21
|
+
if (pluginConfig.collections && pluginConfig.collections.length > 0) {
|
|
22
|
+
baseExportSlugs = pluginConfig.collections.filter((c)=>c.export !== false).map((c)=>c.slug);
|
|
23
|
+
baseImportSlugs = pluginConfig.collections.filter((c)=>c.import !== false).map((c)=>c.slug);
|
|
24
|
+
} else {
|
|
25
|
+
// Fall back to all collections
|
|
26
|
+
const allSlugs = config.collections?.map((c)=>c.slug) || [];
|
|
27
|
+
baseExportSlugs = allSlugs;
|
|
28
|
+
baseImportSlugs = allSlugs;
|
|
29
|
+
}
|
|
16
30
|
let baseExportCollection = getExportCollection({
|
|
31
|
+
collectionSlugs: baseExportSlugs,
|
|
17
32
|
config,
|
|
18
33
|
pluginConfig
|
|
19
34
|
});
|
|
20
35
|
let baseImportCollection = getImportCollection({
|
|
21
|
-
|
|
36
|
+
collectionSlugs: baseImportSlugs,
|
|
22
37
|
pluginConfig
|
|
23
38
|
});
|
|
24
39
|
if (pluginConfig.overrideExportCollection && typeof pluginConfig.overrideExportCollection === 'function') {
|
|
@@ -40,58 +55,84 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
40
55
|
for (const collectionConfig of pluginConfig.collections){
|
|
41
56
|
const exportConfig = typeof collectionConfig.export === 'object' ? collectionConfig.export : undefined;
|
|
42
57
|
if (exportConfig?.overrideCollection) {
|
|
43
|
-
//
|
|
44
|
-
const
|
|
58
|
+
// Create collection specific to this target collection
|
|
59
|
+
const collection = getExportCollection({
|
|
60
|
+
collectionSlugs: [
|
|
61
|
+
collectionConfig.slug
|
|
62
|
+
],
|
|
45
63
|
config,
|
|
46
64
|
exportConfig,
|
|
47
65
|
pluginConfig
|
|
48
66
|
});
|
|
49
|
-
|
|
50
|
-
|
|
67
|
+
// Call override once to determine user intent
|
|
68
|
+
const overridden = await exportConfig.overrideCollection({
|
|
69
|
+
collection
|
|
51
70
|
});
|
|
52
71
|
// If the slug changed, this is a separate collection; otherwise it modifies the base
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
if (overridden.slug !== baseExportCollection.slug) {
|
|
73
|
+
exportCollections.push(overridden);
|
|
74
|
+
customExportSlugMap.set(collectionConfig.slug, overridden.slug);
|
|
75
|
+
} else {
|
|
76
|
+
// Slug didn't change - merge settings into base collection while preserving all slugs
|
|
77
|
+
baseExportCollection = {
|
|
78
|
+
...baseExportCollection,
|
|
79
|
+
...overridden,
|
|
80
|
+
admin: {
|
|
81
|
+
...baseExportCollection.admin,
|
|
82
|
+
...overridden.admin,
|
|
83
|
+
custom: {
|
|
84
|
+
...baseExportCollection.admin?.custom,
|
|
85
|
+
...overridden.admin?.custom,
|
|
86
|
+
'plugin-import-export': {
|
|
87
|
+
...overridden.admin?.custom?.['plugin-import-export'],
|
|
88
|
+
...baseExportCollection.admin?.custom?.['plugin-import-export'],
|
|
89
|
+
// Ensure base collection's slug list is preserved
|
|
90
|
+
collectionSlugs: baseExportCollection.admin?.custom?.['plugin-import-export']?.collectionSlugs
|
|
91
|
+
}
|
|
92
|
+
}
|
|
60
93
|
}
|
|
61
94
|
};
|
|
62
|
-
exportCollections.push(customExport);
|
|
63
|
-
customExportSlugMap.set(collectionConfig.slug, customExport.slug);
|
|
64
|
-
} else {
|
|
65
|
-
baseExportCollection = customExport;
|
|
66
95
|
}
|
|
67
96
|
}
|
|
68
97
|
const importConf = typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined;
|
|
69
98
|
if (importConf?.overrideCollection) {
|
|
70
|
-
//
|
|
71
|
-
const
|
|
72
|
-
|
|
99
|
+
// Create collection specific to this target collection
|
|
100
|
+
const collection = getImportCollection({
|
|
101
|
+
collectionSlugs: [
|
|
102
|
+
collectionConfig.slug
|
|
103
|
+
],
|
|
73
104
|
importConfig: importConf,
|
|
74
105
|
pluginConfig
|
|
75
106
|
});
|
|
76
|
-
|
|
77
|
-
|
|
107
|
+
// Call override once to determine user intent
|
|
108
|
+
const overridden = await importConf.overrideCollection({
|
|
109
|
+
collection
|
|
78
110
|
});
|
|
79
111
|
// If the slug changed, this is a separate collection; otherwise it modifies the base
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
customImport.admin = {
|
|
83
|
-
...customImport.admin,
|
|
84
|
-
custom: {
|
|
85
|
-
...customImport.admin?.custom,
|
|
86
|
-
defaultCollectionSlug: collectionConfig.slug
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
importCollections.push(customImport);
|
|
112
|
+
if (overridden.slug !== baseImportCollection.slug) {
|
|
113
|
+
importCollections.push(overridden);
|
|
90
114
|
// Map this target collection to its custom import collection
|
|
91
|
-
customImportSlugMap.set(collectionConfig.slug,
|
|
115
|
+
customImportSlugMap.set(collectionConfig.slug, overridden.slug);
|
|
92
116
|
} else {
|
|
93
|
-
//
|
|
94
|
-
baseImportCollection =
|
|
117
|
+
// Slug didn't change - merge settings into base collection while preserving all slugs
|
|
118
|
+
baseImportCollection = {
|
|
119
|
+
...baseImportCollection,
|
|
120
|
+
...overridden,
|
|
121
|
+
admin: {
|
|
122
|
+
...baseImportCollection.admin,
|
|
123
|
+
...overridden.admin,
|
|
124
|
+
custom: {
|
|
125
|
+
...baseImportCollection.admin?.custom,
|
|
126
|
+
...overridden.admin?.custom,
|
|
127
|
+
'plugin-import-export': {
|
|
128
|
+
...overridden.admin?.custom?.['plugin-import-export'],
|
|
129
|
+
...baseImportCollection.admin?.custom?.['plugin-import-export'],
|
|
130
|
+
// Ensure base collection's slug list is preserved
|
|
131
|
+
collectionSlugs: baseImportCollection.admin?.custom?.['plugin-import-export']?.collectionSlugs
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
95
136
|
}
|
|
96
137
|
}
|
|
97
138
|
}
|
|
@@ -138,6 +179,37 @@ import { getImportCollection } from '../import/getImportCollection.js';
|
|
|
138
179
|
};
|
|
139
180
|
}
|
|
140
181
|
}
|
|
182
|
+
// Filter out slugs that have custom export/import collections from the base collections
|
|
183
|
+
// Collections with custom collections should ONLY be exportable/importable through those
|
|
184
|
+
const filteredExportSlugs = baseExportSlugs.filter((slug)=>!customExportSlugMap.has(slug));
|
|
185
|
+
const filteredImportSlugs = baseImportSlugs.filter((slug)=>!customImportSlugMap.has(slug));
|
|
186
|
+
// Update base collections with filtered slugs
|
|
187
|
+
baseExportCollection = {
|
|
188
|
+
...baseExportCollection,
|
|
189
|
+
admin: {
|
|
190
|
+
...baseExportCollection.admin,
|
|
191
|
+
custom: {
|
|
192
|
+
...baseExportCollection.admin?.custom,
|
|
193
|
+
'plugin-import-export': {
|
|
194
|
+
...baseExportCollection.admin?.custom?.['plugin-import-export'],
|
|
195
|
+
collectionSlugs: filteredExportSlugs
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
baseImportCollection = {
|
|
201
|
+
...baseImportCollection,
|
|
202
|
+
admin: {
|
|
203
|
+
...baseImportCollection.admin,
|
|
204
|
+
custom: {
|
|
205
|
+
...baseImportCollection.admin?.custom,
|
|
206
|
+
'plugin-import-export': {
|
|
207
|
+
...baseImportCollection.admin?.custom?.['plugin-import-export'],
|
|
208
|
+
collectionSlugs: filteredImportSlugs
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
141
213
|
exportCollections.unshift(baseExportCollection);
|
|
142
214
|
importCollections.unshift(baseImportCollection);
|
|
143
215
|
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 * - 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":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AM,KAAK,WAAWd,iBAAiBc,MAAM,GAAGX;YAE1E,IAAIgB,cAAc,CAACA,WAAWf,kBAAkB,EAAE;gBAChDa,uBAAuB;oBAAE,GAAGA,oBAAoB;oBAAE,GAAGE,UAAU;gBAAC;YAClE;YACA,IAAIN,cAAc,CAACA,WAAWT,kBAAkB,EAAE;gBAChDc,uBAAuB;oBAAE,GAAGA,oBAAoB;oBAAE,GAAGL,UAAU;gBAAC;YAClE;QACF;QAEA,IACEI,qBAAqBG,MAAM,KAAKjB,aAChCc,qBAAqBI,WAAW,KAAKlB,aACrCc,qBAAqBK,eAAe,KAAKnB,WACzC;YACAf,uBAAuB;gBACrB,GAAGA,oBAAoB;gBACvBoB,OAAO;oBACL,GAAGpB,qBAAqBoB,KAAK;oBAC7BC,QAAQ;wBACN,GAAGrB,qBAAqBoB,KAAK,EAAEC,MAAM;wBACrC,GAAIQ,qBAAqBK,eAAe,KAAKnB,aAAa;4BACxDmB,iBAAiBL,qBAAqBK,eAAe;wBACvD,CAAC;wBACD,GAAIL,qBAAqBI,WAAW,KAAKlB,aAAa;4BACpDkB,aAAaJ,qBAAqBI,WAAW;wBAC/C,CAAC;wBACD,GAAIJ,qBAAqBG,MAAM,KAAKjB,aAAa;4BAC/CiB,QAAQH,qBAAqBG,MAAM;wBACrC,CAAC;oBACH;gBACF;YACF;QACF;IACF;IAEA3B,kBAAkB8B,OAAO,CAACnC;IAC1BM,kBAAkB6B,OAAO,CAAClC;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 // Calculate collection slugs for base export/import collections\n // If pluginConfig.collections is provided, filter by export/import !== false\n // Otherwise, use all config collections\n let baseExportSlugs: string[]\n let baseImportSlugs: string[]\n\n if (pluginConfig.collections && pluginConfig.collections.length > 0) {\n baseExportSlugs = pluginConfig.collections.filter((c) => c.export !== false).map((c) => c.slug)\n baseImportSlugs = pluginConfig.collections.filter((c) => c.import !== false).map((c) => c.slug)\n } else {\n // Fall back to all collections\n const allSlugs = config.collections?.map((c) => c.slug) || []\n baseExportSlugs = allSlugs\n baseImportSlugs = allSlugs\n }\n\n let baseExportCollection = getExportCollection({\n collectionSlugs: baseExportSlugs,\n config,\n pluginConfig,\n })\n let baseImportCollection = getImportCollection({\n collectionSlugs: baseImportSlugs,\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\n if (exportConfig?.overrideCollection) {\n // Create collection specific to this target collection\n const collection = getExportCollection({\n collectionSlugs: [collectionConfig.slug],\n config,\n exportConfig,\n pluginConfig,\n })\n\n // Call override once to determine user intent\n const overridden = await exportConfig.overrideCollection({ collection })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (overridden.slug !== baseExportCollection.slug) {\n exportCollections.push(overridden)\n customExportSlugMap.set(collectionConfig.slug, overridden.slug)\n } else {\n // Slug didn't change - merge settings into base collection while preserving all slugs\n baseExportCollection = {\n ...baseExportCollection,\n ...overridden,\n admin: {\n ...baseExportCollection.admin,\n ...overridden.admin,\n custom: {\n ...baseExportCollection.admin?.custom,\n ...overridden.admin?.custom,\n 'plugin-import-export': {\n ...overridden.admin?.custom?.['plugin-import-export'],\n ...baseExportCollection.admin?.custom?.['plugin-import-export'],\n // Ensure base collection's slug list is preserved\n collectionSlugs:\n baseExportCollection.admin?.custom?.['plugin-import-export']?.collectionSlugs,\n },\n },\n },\n }\n }\n }\n\n const importConf =\n typeof collectionConfig.import === 'object' ? collectionConfig.import : undefined\n\n if (importConf?.overrideCollection) {\n // Create collection specific to this target collection\n const collection = getImportCollection({\n collectionSlugs: [collectionConfig.slug],\n importConfig: importConf,\n pluginConfig,\n })\n\n // Call override once to determine user intent\n const overridden = await importConf.overrideCollection({ collection })\n\n // If the slug changed, this is a separate collection; otherwise it modifies the base\n if (overridden.slug !== baseImportCollection.slug) {\n importCollections.push(overridden)\n // Map this target collection to its custom import collection\n customImportSlugMap.set(collectionConfig.slug, overridden.slug)\n } else {\n // Slug didn't change - merge settings into base collection while preserving all slugs\n baseImportCollection = {\n ...baseImportCollection,\n ...overridden,\n admin: {\n ...baseImportCollection.admin,\n ...overridden.admin,\n custom: {\n ...baseImportCollection.admin?.custom,\n ...overridden.admin?.custom,\n 'plugin-import-export': {\n ...overridden.admin?.custom?.['plugin-import-export'],\n ...baseImportCollection.admin?.custom?.['plugin-import-export'],\n // Ensure base collection's slug list is preserved\n collectionSlugs:\n baseImportCollection.admin?.custom?.['plugin-import-export']?.collectionSlugs,\n },\n },\n },\n }\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 // Filter out slugs that have custom export/import collections from the base collections\n // Collections with custom collections should ONLY be exportable/importable through those\n const filteredExportSlugs = baseExportSlugs.filter((slug) => !customExportSlugMap.has(slug))\n const filteredImportSlugs = baseImportSlugs.filter((slug) => !customImportSlugMap.has(slug))\n\n // Update base collections with filtered slugs\n baseExportCollection = {\n ...baseExportCollection,\n admin: {\n ...baseExportCollection.admin,\n custom: {\n ...baseExportCollection.admin?.custom,\n 'plugin-import-export': {\n ...baseExportCollection.admin?.custom?.['plugin-import-export'],\n collectionSlugs: filteredExportSlugs,\n },\n },\n },\n }\n\n baseImportCollection = {\n ...baseImportCollection,\n admin: {\n ...baseImportCollection.admin,\n custom: {\n ...baseImportCollection.admin?.custom,\n 'plugin-import-export': {\n ...baseImportCollection.admin?.custom?.['plugin-import-export'],\n collectionSlugs: filteredImportSlugs,\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","baseExportSlugs","baseImportSlugs","collections","length","filter","c","export","map","slug","import","allSlugs","baseExportCollection","collectionSlugs","baseImportCollection","overrideExportCollection","collection","overrideImportCollection","exportCollections","importCollections","customExportSlugMap","Map","customImportSlugMap","collectionConfig","exportConfig","undefined","overrideCollection","overridden","push","set","admin","custom","importConf","importConfig","mergedExportSettings","mergedImportSettings","exportConf","format","disableSave","disableDownload","filteredExportSlugs","has","filteredImportSlugs","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,gEAAgE;IAChE,6EAA6E;IAC7E,wCAAwC;IACxC,IAAIC;IACJ,IAAIC;IAEJ,IAAIF,aAAaG,WAAW,IAAIH,aAAaG,WAAW,CAACC,MAAM,GAAG,GAAG;QACnEH,kBAAkBD,aAAaG,WAAW,CAACE,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AEC,QAAQ,CAAC,uBAAuB;oBAC/DlB,iBAAiB6B;gBACnB;YACF;QACF;IACF;IAEAxB,kBAAkByB,OAAO,CAAC/B;IAC1BO,kBAAkBwB,OAAO,CAAC7B;IAE1B,OAAO;QACLM;QACAE;QACAJ;QACAC;IACF;AACF,EAAC"}
|
|
@@ -20,12 +20,6 @@ export type GetSchemaColumnsArgs = {
|
|
|
20
20
|
* Available locale codes from config. Required when locale='all'.
|
|
21
21
|
*/
|
|
22
22
|
localeCodes?: string[];
|
|
23
|
-
/**
|
|
24
|
-
* Set of auto-generated timezone companion field names (from collectTimezoneCompanionFields).
|
|
25
|
-
* These fields are excluded unless explicitly selected.
|
|
26
|
-
* If not provided, no timezone filtering is applied.
|
|
27
|
-
*/
|
|
28
|
-
timezoneCompanionFields?: Set<string>;
|
|
29
23
|
};
|
|
30
24
|
/**
|
|
31
25
|
* Derives CSV column names from the collection schema.
|
|
@@ -39,11 +33,21 @@ export type GetSchemaColumnsArgs = {
|
|
|
39
33
|
* - Works for empty exports
|
|
40
34
|
* - Ensures proper column ordering
|
|
41
35
|
*/
|
|
42
|
-
export declare const getSchemaColumns: ({ collectionConfig, disabledFields, fields: selectedFields, locale, localeCodes,
|
|
36
|
+
export declare const getSchemaColumns: ({ collectionConfig, disabledFields, fields: selectedFields, locale, localeCodes, }: GetSchemaColumnsArgs) => string[];
|
|
43
37
|
/**
|
|
44
38
|
* Merges schema-derived columns with data-discovered columns.
|
|
45
39
|
* Schema columns provide the base ordering, data columns add any additional
|
|
46
40
|
* columns (e.g., array indices beyond 0, dynamic fields, derived columns from toCSV).
|
|
47
41
|
*/
|
|
48
42
|
export declare const mergeColumns: (schemaColumns: string[], dataColumns: string[]) => string[];
|
|
43
|
+
/**
|
|
44
|
+
* Filters schema columns to only include those matching user-selected fields.
|
|
45
|
+
* Preserves the order specified by the user in selectedFields.
|
|
46
|
+
*
|
|
47
|
+
* Container fields (groups, arrays, blocks) don't produce their own column, so we prefix-expand
|
|
48
|
+
* to find their children (e.g., 'group' → 'group_name', 'group_age').
|
|
49
|
+
* Leaf fields (date, text, select) produce an exact column, so we only match exactly to avoid
|
|
50
|
+
* including siblings with similar prefixes (e.g., 'dateWithTimezone' won't pull 'dateWithTimezone_tz').
|
|
51
|
+
*/
|
|
52
|
+
export declare function filterToSelectedFields(columns: string[], selectedFields: string[]): string[];
|
|
49
53
|
//# sourceMappingURL=getSchemaColumns.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSchemaColumns.d.ts","sourceRoot":"","sources":["../../src/utilities/getSchemaColumns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAIxD,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"getSchemaColumns.d.ts","sourceRoot":"","sources":["../../src/utilities/getSchemaColumns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAIxD,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,uFAM1B,oBAAoB,KAAG,MAAM,EAmC/B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,kBAAmB,MAAM,EAAE,eAAe,MAAM,EAAE,KAAG,MAAM,EAqEnF,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAmC5F"}
|