@payloadcms/plugin-import-export 3.77.0-internal.0b6b4e4 → 3.77.0-internal.16f474b
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 +2 -1
- 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/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/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.map +1 -1
- package/dist/utilities/getSchemaColumns.js +9 -56
- 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 +8 -8
- 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/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKrC,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EACxB,KAAK,EAEL,aAAa,EACd,MAAM,YAAY,CAAA;AAQnB,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cACxB,MAAM,KAAG,OAAO,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKrC,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EACxB,KAAK,EAEL,aAAa,EACd,MAAM,YAAY,CAAA;AAQnB,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cACxB,MAAM,KAAG,OAAO,CAAC,MAAM,CA6KrC,CAAA;AAEH,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,WAAW;QAC1B,sBAAsB,CAAC,EAAE;YACvB;;;;;;eAMG;YACH,QAAQ,CAAC,EAAE,OAAO,CAAA;YAClB,OAAO,CAAC,EAAE,eAAe,CAAA;YACzB;;eAEG;YACH,KAAK,CAAC,EAAE,aAAa,CAAA;SACtB,CAAA;KACF;IAED,UAAiB,qBAAqB;QACpC,sBAAsB,CAAC,EAAE;YACvB;;;eAGG;YACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;YAC1B;;;eAGG;YACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;YACzB;;;eAGG;YACH,YAAY,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;SAC9B,CAAA;KACF;IAED,UAAiB,gBAAgB;QAC/B,sBAAsB,CAAC,EAAE;YACvB;;;;eAIG;YACH,WAAW,CAAC,EAAE,KAAK,CAAA;YACnB;;;;eAIG;YACH,WAAW,CAAC,EAAE,KAAK,CAAA;SACpB,CAAA;KACF;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -75,6 +75,7 @@ export const importExportPlugin = (pluginConfig)=>async (config)=>{
|
|
|
75
75
|
if (!exportDisabled) {
|
|
76
76
|
components.listMenuItems.push({
|
|
77
77
|
clientProps: {
|
|
78
|
+
collectionSlug: collection.slug,
|
|
78
79
|
exportCollectionSlug: exportSlugForCollection
|
|
79
80
|
},
|
|
80
81
|
path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem'
|
|
@@ -84,6 +85,7 @@ export const importExportPlugin = (pluginConfig)=>async (config)=>{
|
|
|
84
85
|
if (!importDisabled) {
|
|
85
86
|
components.listMenuItems.push({
|
|
86
87
|
clientProps: {
|
|
88
|
+
collectionSlug: collection.slug,
|
|
87
89
|
importCollectionSlug: importSlugForCollection
|
|
88
90
|
},
|
|
89
91
|
path: '@payloadcms/plugin-import-export/rsc#ImportListMenuItem'
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport { deepMergeSimple } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type {\n FromCSVFunction,\n ImportExportPluginConfig,\n Limit,\n PluginCollectionConfig,\n ToCSVFunction,\n} from './types.js'\n\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getCreateCollectionImportTask } from './import/getCreateImportCollectionTask.js'\nimport { translations } from './translations/index.js'\nimport { collectDisabledFieldPaths } from './utilities/collectDisabledFieldPaths.js'\nimport { getPluginCollections } from './utilities/getPluginCollections.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n async (config: Config): Promise<Config> => {\n // Get all export/import collections and the mappings from target collections to custom collections\n const { customExportSlugMap, customImportSlugMap, exportCollections, importCollections } =\n await getPluginCollections({\n config,\n pluginConfig,\n })\n\n // Base collections are at index 0 (always present)\n const baseExportCollection = exportCollections[0]!\n const baseImportCollection = importCollections[0]!\n\n // Collect all export and import collection slugs for filtering\n const allExportSlugs = new Set(exportCollections.map((c) => c.slug))\n const allImportSlugs = new Set(importCollections.map((c) => c.slug))\n\n // Initialize collections array if needed\n if (!config.collections) {\n config.collections = []\n }\n\n // Push all export/import collections if their slugs don't already exist\n for (const collection of [...exportCollections, ...importCollections]) {\n const slugExists = config.collections.some((c) => c.slug === collection.slug)\n if (!slugExists) {\n config.collections.push(collection)\n }\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport and createImport jobs into the config\n ;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))\n config.jobs.tasks.push(getCreateCollectionImportTask(config))\n\n // Build a map of collection configs for quick lookup\n const collectionConfigMap = new Map<string, PluginCollectionConfig>()\n if (pluginConfig.collections) {\n for (const collectionConfig of pluginConfig.collections) {\n collectionConfigMap.set(collectionConfig.slug, collectionConfig)\n }\n }\n\n // Determine which collections to add import/export menu items to\n // Exclude all export and import collections\n const collectionsToUpdate = config.collections.filter(\n (c) => !allExportSlugs.has(c.slug) && !allImportSlugs.has(c.slug),\n )\n\n for (const collection of collectionsToUpdate) {\n // Get the plugin config for this collection (if specified)\n const collectionPluginConfig = collectionConfigMap.get(collection.slug)\n\n // If collections array is specified but this collection is not in it, skip\n if (\n pluginConfig.collections &&\n pluginConfig.collections.length > 0 &&\n !collectionPluginConfig\n ) {\n continue\n }\n\n // Determine which export/import collection to use for this collection\n const exportSlugForCollection =\n customExportSlugMap.get(collection.slug) || baseExportCollection.slug\n const importSlugForCollection =\n customImportSlugMap.get(collection.slug) || baseImportCollection.slug\n\n // Check if export/import are disabled for this collection\n const exportDisabled = collectionPluginConfig?.export === false\n const importDisabled = collectionPluginConfig?.import === false\n\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n\n // Add export menu item if not disabled\n if (!exportDisabled) {\n components.listMenuItems.push({\n clientProps: {\n exportCollectionSlug: exportSlugForCollection,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n }\n\n // Add import menu item if not disabled\n if (!importDisabled) {\n components.listMenuItems.push({\n clientProps: {\n importCollectionSlug: importSlugForCollection,\n },\n path: '@payloadcms/plugin-import-export/rsc#ImportListMenuItem',\n })\n }\n\n // Find fields explicitly marked as disabled for import/export\n const disabledFieldAccessors = collectDisabledFieldPaths(collection.fields)\n\n const exportConfig =\n typeof collectionPluginConfig?.export === 'object'\n ? collectionPluginConfig.export\n : undefined\n const exportFormat = exportConfig?.format\n\n const importConfig =\n typeof collectionPluginConfig?.import === 'object'\n ? collectionPluginConfig.import\n : undefined\n\n const exportLimit = exportConfig?.limit ?? pluginConfig.exportLimit\n\n const importLimit = importConfig?.limit ?? pluginConfig.importLimit\n\n // Store disabled field accessors and export format in the admin config for use in the UI\n // Note: limits are stored in collection.custom (server-only) because they can be functions\n collection.admin.custom = {\n ...(collection.admin.custom || {}),\n 'plugin-import-export': {\n ...(collection.admin.custom?.['plugin-import-export'] || {}),\n disabledFields: disabledFieldAccessors,\n ...(exportFormat !== undefined && { exportFormat }),\n },\n }\n\n // Store limits in collection.custom (server-only) since they can be functions\n if (exportLimit !== undefined || importLimit !== undefined) {\n collection.custom = {\n ...(collection.custom || {}),\n 'plugin-import-export': {\n ...(collection.custom?.['plugin-import-export'] || {}),\n ...(exportLimit !== undefined && { exportLimit }),\n ...(importLimit !== undefined && { importLimit }),\n },\n }\n }\n\n collection.admin.components = components\n }\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n /**\n * Merge plugin translations\n */\n const simplifiedTranslations = Object.entries(translations).reduce(\n (acc, [key, value]) => {\n acc[key] = value.translations\n return acc\n },\n {} as Record<string, PluginDefaultTranslationsObject>,\n )\n\n config.i18n = {\n ...config.i18n,\n translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {}),\n }\n\n return config\n }\n\ndeclare module 'payload' {\n export interface FieldCustom {\n 'plugin-import-export'?: {\n /**\n * When `true` the field is **completely excluded** from the import-export plugin:\n * - It will not appear in the \"Fields to export\" selector.\n * - It is hidden from the preview list when no specific fields are chosen.\n * - Its data is omitted from the final CSV / JSON export.\n * @default false\n */\n disabled?: boolean\n fromCSV?: FromCSVFunction\n /**\n * Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value\n */\n toCSV?: ToCSVFunction\n }\n }\n\n export interface CollectionAdminCustom {\n 'plugin-import-export'?: {\n /**\n * Array of field paths that are disabled for import/export.\n * These paths are collected from fields marked with `custom['plugin-import-export'].disabled = true`.\n */\n disabledFields?: string[]\n /**\n * When set, forces exports from this collection to use this format.\n * This value is read from the plugin config's `export.format` option.\n */\n exportFormat?: 'csv' | 'json'\n }\n }\n\n export interface CollectionCustom {\n 'plugin-import-export'?: {\n /**\n * Maximum number of documents that can be exported from this collection.\n * Set to 0 for unlimited (default). Can be a number or function.\n * Stored in collection.custom (server-only) since functions cannot be serialized to client.\n */\n exportLimit?: Limit\n /**\n * Maximum number of documents that can be imported to this collection.\n * Set to 0 for unlimited (default). Can be a number or function.\n * Stored in collection.custom (server-only) since functions cannot be serialized to client.\n */\n importLimit?: Limit\n }\n }\n}\n"],"names":["deepMergeSimple","getCreateCollectionExportTask","getCreateCollectionImportTask","translations","collectDisabledFieldPaths","getPluginCollections","importExportPlugin","pluginConfig","config","customExportSlugMap","customImportSlugMap","exportCollections","importCollections","baseExportCollection","baseImportCollection","allExportSlugs","Set","map","c","slug","allImportSlugs","collections","collection","slugExists","some","push","admin","components","providers","jobs","tasks","collectionConfigMap","Map","collectionConfig","set","collectionsToUpdate","filter","has","collectionPluginConfig","get","length","exportSlugForCollection","importSlugForCollection","exportDisabled","export","importDisabled","import","listMenuItems","clientProps","exportCollectionSlug","path","importCollectionSlug","disabledFieldAccessors","fields","exportConfig","undefined","exportFormat","format","importConfig","exportLimit","limit","importLimit","custom","disabledFields","i18n","simplifi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BN,WAAW;gBAC1DjC,WAAWwC,MAAM,GAAG;oBAClB,GAAIxC,WAAWwC,MAAM,IAAI,CAAC,CAAC;oBAC3B,wBAAwB;wBACtB,GAAIxC,WAAWwC,MAAM,EAAE,CAAC,uBAAuB,IAAI,CAAC,CAAC;wBACrD,GAAIH,gBAAgBJ,aAAa;4BAAEI;wBAAY,CAAC;wBAChD,GAAIE,gBAAgBN,aAAa;4BAAEM;wBAAY,CAAC;oBAClD;gBACF;YACF;YAEAvC,WAAWI,KAAK,CAACC,UAAU,GAAGA;QAChC;QAEA,IAAI,CAACnB,OAAOwD,IAAI,EAAE;YAChBxD,OAAOwD,IAAI,GAAG,CAAC;QACjB;QAEA;;KAEC,GACD,MAAMC,yBAAyBC,OAAOC,OAAO,CAAChE,cAAciE,MAAM,CAChE,CAACC,KAAK,CAACC,KAAKC,MAAM;YAChBF,GAAG,CAACC,IAAI,GAAGC,MAAMpE,YAAY;YAC7B,OAAOkE;QACT,GACA,CAAC;QAGH7D,OAAOwD,IAAI,GAAG;YACZ,GAAGxD,OAAOwD,IAAI;YACd7D,cAAcH,gBAAgBiE,wBAAwBzD,OAAOwD,IAAI,EAAE7D,gBAAgB,CAAC;QACtF;QAEA,OAAOK;IACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport { deepMergeSimple } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type {\n FromCSVFunction,\n ImportExportPluginConfig,\n Limit,\n PluginCollectionConfig,\n ToCSVFunction,\n} from './types.js'\n\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getCreateCollectionImportTask } from './import/getCreateImportCollectionTask.js'\nimport { translations } from './translations/index.js'\nimport { collectDisabledFieldPaths } from './utilities/collectDisabledFieldPaths.js'\nimport { getPluginCollections } from './utilities/getPluginCollections.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n async (config: Config): Promise<Config> => {\n // Get all export/import collections and the mappings from target collections to custom collections\n const { customExportSlugMap, customImportSlugMap, exportCollections, importCollections } =\n await getPluginCollections({\n config,\n pluginConfig,\n })\n\n // Base collections are at index 0 (always present)\n const baseExportCollection = exportCollections[0]!\n const baseImportCollection = importCollections[0]!\n\n // Collect all export and import collection slugs for filtering\n const allExportSlugs = new Set(exportCollections.map((c) => c.slug))\n const allImportSlugs = new Set(importCollections.map((c) => c.slug))\n\n // Initialize collections array if needed\n if (!config.collections) {\n config.collections = []\n }\n\n // Push all export/import collections if their slugs don't already exist\n for (const collection of [...exportCollections, ...importCollections]) {\n const slugExists = config.collections.some((c) => c.slug === collection.slug)\n if (!slugExists) {\n config.collections.push(collection)\n }\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport and createImport jobs into the config\n ;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))\n config.jobs.tasks.push(getCreateCollectionImportTask(config))\n\n // Build a map of collection configs for quick lookup\n const collectionConfigMap = new Map<string, PluginCollectionConfig>()\n if (pluginConfig.collections) {\n for (const collectionConfig of pluginConfig.collections) {\n collectionConfigMap.set(collectionConfig.slug, collectionConfig)\n }\n }\n\n // Determine which collections to add import/export menu items to\n // Exclude all export and import collections\n const collectionsToUpdate = config.collections.filter(\n (c) => !allExportSlugs.has(c.slug) && !allImportSlugs.has(c.slug),\n )\n\n for (const collection of collectionsToUpdate) {\n // Get the plugin config for this collection (if specified)\n const collectionPluginConfig = collectionConfigMap.get(collection.slug)\n\n // If collections array is specified but this collection is not in it, skip\n if (\n pluginConfig.collections &&\n pluginConfig.collections.length > 0 &&\n !collectionPluginConfig\n ) {\n continue\n }\n\n // Determine which export/import collection to use for this collection\n const exportSlugForCollection =\n customExportSlugMap.get(collection.slug) || baseExportCollection.slug\n const importSlugForCollection =\n customImportSlugMap.get(collection.slug) || baseImportCollection.slug\n\n // Check if export/import are disabled for this collection\n const exportDisabled = collectionPluginConfig?.export === false\n const importDisabled = collectionPluginConfig?.import === false\n\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n\n // Add export menu item if not disabled\n if (!exportDisabled) {\n components.listMenuItems.push({\n clientProps: {\n collectionSlug: collection.slug,\n exportCollectionSlug: exportSlugForCollection,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n }\n\n // Add import menu item if not disabled\n if (!importDisabled) {\n components.listMenuItems.push({\n clientProps: {\n collectionSlug: collection.slug,\n importCollectionSlug: importSlugForCollection,\n },\n path: '@payloadcms/plugin-import-export/rsc#ImportListMenuItem',\n })\n }\n\n // Find fields explicitly marked as disabled for import/export\n const disabledFieldAccessors = collectDisabledFieldPaths(collection.fields)\n\n const exportConfig =\n typeof collectionPluginConfig?.export === 'object'\n ? collectionPluginConfig.export\n : undefined\n const exportFormat = exportConfig?.format\n\n const importConfig =\n typeof collectionPluginConfig?.import === 'object'\n ? collectionPluginConfig.import\n : undefined\n\n const exportLimit = exportConfig?.limit ?? pluginConfig.exportLimit\n\n const importLimit = importConfig?.limit ?? pluginConfig.importLimit\n\n // Store disabled field accessors and export format in the admin config for use in the UI\n // Note: limits are stored in collection.custom (server-only) because they can be functions\n collection.admin.custom = {\n ...(collection.admin.custom || {}),\n 'plugin-import-export': {\n ...(collection.admin.custom?.['plugin-import-export'] || {}),\n disabledFields: disabledFieldAccessors,\n ...(exportFormat !== undefined && { exportFormat }),\n },\n }\n\n // Store limits in collection.custom (server-only) since they can be functions\n if (exportLimit !== undefined || importLimit !== undefined) {\n collection.custom = {\n ...(collection.custom || {}),\n 'plugin-import-export': {\n ...(collection.custom?.['plugin-import-export'] || {}),\n ...(exportLimit !== undefined && { exportLimit }),\n ...(importLimit !== undefined && { importLimit }),\n },\n }\n }\n\n collection.admin.components = components\n }\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n /**\n * Merge plugin translations\n */\n const simplifiedTranslations = Object.entries(translations).reduce(\n (acc, [key, value]) => {\n acc[key] = value.translations\n return acc\n },\n {} as Record<string, PluginDefaultTranslationsObject>,\n )\n\n config.i18n = {\n ...config.i18n,\n translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {}),\n }\n\n return config\n }\n\ndeclare module 'payload' {\n export interface FieldCustom {\n 'plugin-import-export'?: {\n /**\n * When `true` the field is **completely excluded** from the import-export plugin:\n * - It will not appear in the \"Fields to export\" selector.\n * - It is hidden from the preview list when no specific fields are chosen.\n * - Its data is omitted from the final CSV / JSON export.\n * @default false\n */\n disabled?: boolean\n fromCSV?: FromCSVFunction\n /**\n * Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value\n */\n toCSV?: ToCSVFunction\n }\n }\n\n export interface CollectionAdminCustom {\n 'plugin-import-export'?: {\n /**\n * Array of collection slugs that this export/import collection can target.\n * Used by CollectionField to populate the dropdown options.\n */\n collectionSlugs?: string[]\n /**\n * Array of field paths that are disabled for import/export.\n * These paths are collected from fields marked with `custom['plugin-import-export'].disabled = true`.\n */\n disabledFields?: string[]\n /**\n * When set, forces exports from this collection to use this format.\n * This value is read from the plugin config's `export.format` option.\n */\n exportFormat?: 'csv' | 'json'\n }\n }\n\n export interface CollectionCustom {\n 'plugin-import-export'?: {\n /**\n * Maximum number of documents that can be exported from this collection.\n * Set to 0 for unlimited (default). Can be a number or function.\n * Stored in collection.custom (server-only) since functions cannot be serialized to client.\n */\n exportLimit?: Limit\n /**\n * Maximum number of documents that can be imported to this collection.\n * Set to 0 for unlimited (default). Can be a number or function.\n * Stored in collection.custom (server-only) since functions cannot be serialized to client.\n */\n importLimit?: Limit\n }\n }\n}\n"],"names":["deepMergeSimple","getCreateCollectionExportTask","getCreateCollectionImportTask","translations","collectDisabledFieldPaths","getPluginCollections","importExportPlugin","pluginConfig","config","customExportSlugMap","customImportSlugMap","exportCollections","importCollections","baseExportCollection","baseImportCollection","allExportSlugs","Set","map","c","slug","allImportSlugs","collections","collection","slugExists","some","push","admin","components","providers","jobs","tasks","collectionConfigMap","Map","collectionConfig","set","collectionsToUpdate","filter","has","collectionPluginConfig","get","length","exportSlugForCollection","importSlugForCollection","exportDisabled","export","importDisabled","import","listMenuItems","clientProps","collectionSlug","exportCollectionSlug","path","importCollectionSlug","disabledFieldAccessors","fields","exportConfig","undefined","exportFormat","format","importConfig","exportLimit","limit","importLimit","custom","disabledFields","i18n","simplifiedTranslations","Object","entries","reduce","acc","key","value"],"mappings":"AAEA,SAASA,eAAe,QAAQ,UAAS;AAWzC,SAASC,6BAA6B,QAAQ,4CAA2C;AACzF,SAASC,6BAA6B,QAAQ,4CAA2C;AACzF,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,MAAMC,qBACX,CAACC,eACD,OAAOC;QACL,mGAAmG;QACnG,MAAM,EAAEC,mBAAmB,EAAEC,mBAAmB,EAAEC,iBAAiB,EAAEC,iBAAiB,EAAE,GACtF,MAAMP,qBAAqB;YACzBG;YACAD;QACF;QAEF,mDAAmD;QACnD,MAAMM,uBAAuBF,iBAAiB,CAAC,EAAE;QACjD,MAAMG,uBAAuBF,iBAAiB,CAAC,EAAE;QAEjD,+DAA+D;QAC/D,MAAMG,iBAAiB,IAAIC,IAAIL,kBAAkBM,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI;QAClE,MAAMC,iBAAiB,IAAIJ,IAAIJ,kBAAkBK,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI;QAElE,yCAAyC;QACzC,IAAI,CAACX,OAAOa,WAAW,EAAE;YACvBb,OAAOa,WAAW,GAAG,EAAE;QACzB;QAEA,wEAAwE;QACxE,KAAK,MAAMC,cAAc;eAAIX;eAAs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+1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates a filename based on current date and time.
|
|
3
|
-
* 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":"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;gBACd;gBAEA,qFAAqF;gBACrF,IAAIC,aAAaC,IAAI,KAAKnB,qBAAqBmB,IAAI,EAAE;oBACnD,4EAA4E;oBAC5ED,aAAaE,KAAK,GAAG;wBACn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WAAWF,iBAAiBE,MAAM,GAAGC;YAC1E,MAAMU,aACJ,OAAOb,iBAAiBc,MAAM,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,aAA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KAAK,EAAEC,MAAM;gBACrC,wBAAwB;oBACtB,GAAGjB,qBAAqBgB,KAAK,EAAEC,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"}
|
|
@@ -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;CACvB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,uFAM1B,oBAAoB,KAAG,MAAM,
|
|
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"}
|
|
@@ -11,36 +11,27 @@ import { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js';
|
|
|
11
11
|
* - Works for empty exports
|
|
12
12
|
* - Ensures proper column ordering
|
|
13
13
|
*/ export const getSchemaColumns = ({ collectionConfig, disabledFields = [], fields: selectedFields, locale, localeCodes })=>{
|
|
14
|
-
const hasVersions = Boolean(collectionConfig.versions);
|
|
15
|
-
// Determine if we need locale expansion
|
|
16
14
|
const expandLocales = locale === 'all' && localeCodes && localeCodes.length > 0;
|
|
17
|
-
// Get all possible columns from schema (excludes system fields like id, createdAt, updatedAt)
|
|
18
15
|
let schemaColumns = getFlattenedFieldKeys(collectionConfig.flattenedFields, '', expandLocales ? {
|
|
19
16
|
localeCodes
|
|
20
17
|
} : {});
|
|
21
|
-
// Add
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
...schemaColumns
|
|
30
|
-
];
|
|
31
|
-
// Filter to user-selected fields if specified
|
|
18
|
+
// Add id if not present in schema
|
|
19
|
+
const hasIdField = schemaColumns.includes('id');
|
|
20
|
+
if (!hasIdField) {
|
|
21
|
+
schemaColumns = [
|
|
22
|
+
'id',
|
|
23
|
+
...schemaColumns
|
|
24
|
+
];
|
|
25
|
+
}
|
|
32
26
|
if (selectedFields && selectedFields.length > 0) {
|
|
33
27
|
schemaColumns = filterToSelectedFields(schemaColumns, selectedFields);
|
|
34
28
|
}
|
|
35
|
-
// Remove disabled fields
|
|
36
29
|
if (disabledFields.length > 0) {
|
|
37
30
|
const disabledSet = new Set();
|
|
38
31
|
for (const path of disabledFields){
|
|
39
|
-
// Convert dot notation to underscore and add to set
|
|
40
32
|
disabledSet.add(path.replace(/\./g, '_'));
|
|
41
33
|
}
|
|
42
34
|
schemaColumns = schemaColumns.filter((col)=>{
|
|
43
|
-
// Check if column matches any disabled path
|
|
44
35
|
for (const disabled of disabledSet){
|
|
45
36
|
if (col === disabled || col.startsWith(`${disabled}_`)) {
|
|
46
37
|
return false;
|
|
@@ -49,41 +40,7 @@ import { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js';
|
|
|
49
40
|
return true;
|
|
50
41
|
});
|
|
51
42
|
}
|
|
52
|
-
|
|
53
|
-
// filterToSelectedFields() already returns columns in user's specified order
|
|
54
|
-
if (selectedFields && selectedFields.length > 0) {
|
|
55
|
-
return schemaColumns;
|
|
56
|
-
}
|
|
57
|
-
// No fields selected - apply default ordering (id first, timestamps last)
|
|
58
|
-
const orderedColumns = [];
|
|
59
|
-
// 1. ID always first
|
|
60
|
-
if (schemaColumns.includes('id')) {
|
|
61
|
-
orderedColumns.push('id');
|
|
62
|
-
}
|
|
63
|
-
// 2. Status field for versioned collections
|
|
64
|
-
if (hasVersions) {
|
|
65
|
-
orderedColumns.push('_status');
|
|
66
|
-
}
|
|
67
|
-
// 3. All other fields (excluding id, timestamps, status)
|
|
68
|
-
const excludeFromMiddle = new Set([
|
|
69
|
-
'_status',
|
|
70
|
-
'createdAt',
|
|
71
|
-
'id',
|
|
72
|
-
'updatedAt'
|
|
73
|
-
]);
|
|
74
|
-
for (const col of schemaColumns){
|
|
75
|
-
if (!excludeFromMiddle.has(col)) {
|
|
76
|
-
orderedColumns.push(col);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// 4. Timestamps at the end
|
|
80
|
-
if (schemaColumns.includes('createdAt')) {
|
|
81
|
-
orderedColumns.push('createdAt');
|
|
82
|
-
}
|
|
83
|
-
if (schemaColumns.includes('updatedAt')) {
|
|
84
|
-
orderedColumns.push('updatedAt');
|
|
85
|
-
}
|
|
86
|
-
return orderedColumns;
|
|
43
|
+
return schemaColumns;
|
|
87
44
|
};
|
|
88
45
|
/**
|
|
89
46
|
* Merges schema-derived columns with data-discovered columns.
|
|
@@ -95,12 +52,9 @@ import { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js';
|
|
|
95
52
|
];
|
|
96
53
|
const schemaSet = new Set(schemaColumns);
|
|
97
54
|
const insertedDerived = new Map();
|
|
98
|
-
// Add any data columns not in schema (preserves schema ordering, appends new ones)
|
|
99
55
|
for (const col of dataColumns){
|
|
100
56
|
if (!schemaSet.has(col)) {
|
|
101
57
|
let inserted = false;
|
|
102
|
-
// Check if this is a derived column from a schema column (e.g., field_id, field_email)
|
|
103
|
-
// Pattern: schemaCol_suffix where suffix is NOT a number (array indices are handled separately)
|
|
104
58
|
for (const schemaCol of schemaColumns){
|
|
105
59
|
if (col.startsWith(`${schemaCol}_`)) {
|
|
106
60
|
const suffix = col.slice(schemaCol.length + 1);
|
|
@@ -137,7 +91,6 @@ import { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js';
|
|
|
137
91
|
}
|
|
138
92
|
}
|
|
139
93
|
}
|
|
140
|
-
// Otherwise append at the end (before timestamps)
|
|
141
94
|
const createdAtIdx = result.indexOf('createdAt');
|
|
142
95
|
if (createdAtIdx !== -1) {
|
|
143
96
|
result.splice(createdAtIdx, 0, col);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getSchemaColumns.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from 'payload'\n\nimport { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js'\n\nexport type GetSchemaColumnsArgs = {\n /**\n * The collection configuration to derive columns from\n */\n collectionConfig: SanitizedCollectionConfig\n /**\n * Array of disabled field paths from plugin config\n */\n disabledFields?: string[]\n /**\n * User-selected fields to export. If provided, only these fields (and their nested fields) will be included.\n */\n fields?: string[]\n /**\n * The locale to export. When 'all', localized fields are expanded to include all locale suffixes.\n */\n locale?: null | string\n /**\n * Available locale codes from config. Required when locale='all'.\n */\n localeCodes?: string[]\n}\n\n/**\n * Derives CSV column names from the collection schema.\n * This provides a base set of columns from field definitions.\n *\n * Note: For arrays/blocks with multiple items, the schema only generates index 0.\n * Additional indices from actual data should be merged with these columns.\n *\n * Benefits:\n * - Provides consistent base columns\n * - Works for empty exports\n * - Ensures proper column ordering\n */\nexport const getSchemaColumns = ({\n collectionConfig,\n disabledFields = [],\n fields: selectedFields,\n locale,\n localeCodes,\n}: GetSchemaColumnsArgs): string[] => {\n const hasVersions = Boolean(collectionConfig.versions)\n\n // Determine if we need locale expansion\n const expandLocales = locale === 'all' && localeCodes && localeCodes.length > 0\n\n // Get all possible columns from schema (excludes system fields like id, createdAt, updatedAt)\n let schemaColumns = getFlattenedFieldKeys(\n collectionConfig.flattenedFields,\n '',\n expandLocales ? { localeCodes } : {},\n )\n\n // Add system fields that aren't in flattenedFields\n const systemFields = ['id', 'createdAt', 'updatedAt']\n schemaColumns = [...systemFields, ...schemaColumns]\n\n // Filter to user-selected fields if specified\n if (selectedFields && selectedFields.length > 0) {\n schemaColumns = filterToSelectedFields(schemaColumns, selectedFields)\n }\n\n // Remove disabled fields\n if (disabledFields.length > 0) {\n const disabledSet = new Set<string>()\n for (const path of disabledFields) {\n // Convert dot notation to underscore and add to set\n disabledSet.add(path.replace(/\\./g, '_'))\n }\n schemaColumns = schemaColumns.filter((col) => {\n // Check if column matches any disabled path\n for (const disabled of disabledSet) {\n if (col === disabled || col.startsWith(`${disabled}_`)) {\n return false\n }\n }\n return true\n })\n }\n\n // When user has selected specific fields, preserve their ordering\n // filterToSelectedFields() already returns columns in user's specified order\n if (selectedFields && selectedFields.length > 0) {\n return schemaColumns\n }\n\n // No fields selected - apply default ordering (id first, timestamps last)\n const orderedColumns: string[] = []\n\n // 1. ID always first\n if (schemaColumns.includes('id')) {\n orderedColumns.push('id')\n }\n\n // 2. Status field for versioned collections\n if (hasVersions) {\n orderedColumns.push('_status')\n }\n\n // 3. All other fields (excluding id, timestamps, status)\n const excludeFromMiddle = new Set(['_status', 'createdAt', 'id', 'updatedAt'])\n for (const col of schemaColumns) {\n if (!excludeFromMiddle.has(col)) {\n orderedColumns.push(col)\n }\n }\n\n // 4. Timestamps at the end\n if (schemaColumns.includes('createdAt')) {\n orderedColumns.push('createdAt')\n }\n if (schemaColumns.includes('updatedAt')) {\n orderedColumns.push('updatedAt')\n }\n\n return orderedColumns\n}\n\n/**\n * Merges schema-derived columns with data-discovered columns.\n * Schema columns provide the base ordering, data columns add any additional\n * columns (e.g., array indices beyond 0, dynamic fields, derived columns from toCSV).\n */\nexport const mergeColumns = (schemaColumns: string[], dataColumns: string[]): string[] => {\n const result = [...schemaColumns]\n const schemaSet = new Set(schemaColumns)\n const insertedDerived = new Map<string, string[]>()\n\n // Add any data columns not in schema (preserves schema ordering, appends new ones)\n for (const col of dataColumns) {\n if (!schemaSet.has(col)) {\n let inserted = false\n\n // Check if this is a derived column from a schema column (e.g., field_id, field_email)\n // Pattern: schemaCol_suffix where suffix is NOT a number (array indices are handled separately)\n for (const schemaCol of schemaColumns) {\n if (col.startsWith(`${schemaCol}_`)) {\n const suffix = col.slice(schemaCol.length + 1)\n // Skip if suffix starts with a digit (array index pattern like field_0_*)\n if (!/^\\d/.test(suffix)) {\n const baseIdx = result.indexOf(schemaCol)\n if (baseIdx !== -1) {\n const derivedList = insertedDerived.get(schemaCol) || []\n const insertIdx = baseIdx + 1 + derivedList.length\n result.splice(insertIdx, 0, col)\n derivedList.push(col)\n insertedDerived.set(schemaCol, derivedList)\n schemaSet.add(col)\n inserted = true\n break\n }\n }\n }\n }\n\n if (!inserted) {\n // Check for array indices (e.g., field_1_*), insert after field_0_*\n const match = col.match(/^(.+?)_(\\d+)(_.*)?$/)\n if (match) {\n const [, basePath, index, suffix] = match\n if (basePath && index) {\n const prevIndex = parseInt(index, 10) - 1\n const prevCol = `${basePath}_${prevIndex}${suffix ?? ''}`\n const prevIdx = result.indexOf(prevCol)\n if (prevIdx !== -1) {\n // Insert after the previous index column\n result.splice(prevIdx + 1, 0, col)\n schemaSet.add(col)\n continue\n }\n }\n }\n\n // Otherwise append at the end (before timestamps)\n const createdAtIdx = result.indexOf('createdAt')\n if (createdAtIdx !== -1) {\n result.splice(createdAtIdx, 0, col)\n } else {\n result.push(col)\n }\n schemaSet.add(col)\n }\n }\n }\n\n // Remove schema columns that were fully replaced by toCSV-derived columns (e.g. \"user\" → \"user_id\", \"user_email\")\n for (const [schemaCol, derivedCols] of insertedDerived) {\n if (!dataColumns.includes(schemaCol) && derivedCols.length > 0) {\n const idx = result.indexOf(schemaCol)\n if (idx !== -1) {\n result.splice(idx, 1)\n }\n }\n }\n\n return result\n}\n\n/**\n * Filters schema columns to only include those matching user-selected fields.\n * Preserves the order specified by the user in selectedFields.\n *\n * Container fields (groups, arrays, blocks) don't produce their own column, so we prefix-expand\n * to find their children (e.g., 'group' → 'group_name', 'group_age').\n * Leaf fields (date, text, select) produce an exact column, so we only match exactly to avoid\n * including siblings with similar prefixes (e.g., 'dateWithTimezone' won't pull 'dateWithTimezone_tz').\n */\nexport function filterToSelectedFields(columns: string[], selectedFields: string[]): string[] {\n const result: string[] = []\n const columnsSet = new Set(columns)\n\n // Convert selected fields to underscore notation patterns\n const patterns = selectedFields.map((field) => {\n const underscored = field.replace(/\\./g, '_')\n return {\n exact: underscored,\n original: field,\n prefix: `${underscored}_`,\n }\n })\n\n // Iterate through user-specified fields in order to preserve their ordering\n for (const pattern of patterns) {\n const hasExactColumn = columnsSet.has(pattern.exact)\n\n if (hasExactColumn && !result.includes(pattern.exact)) {\n result.push(pattern.exact)\n }\n\n // Only prefix-expand if no exact column match exists (containers need expansion, leaves don't)\n if (!hasExactColumn) {\n for (const column of columns) {\n if (column.startsWith(pattern.prefix)) {\n if (!result.includes(column)) {\n result.push(column)\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["getFlattenedFieldKeys","getSchemaColumns","collectionConfig","disabledFields","fields","selectedFields","locale","localeCodes","hasVersions","Boolean","versions","expandLocales","length","schemaColumns","flattenedFields","systemFields","filterToSelectedFields","disabledSet","Set","path","add","replace","filter","col","disabled","startsWith","orderedColumns","includes","push","excludeFromMiddle","has","mergeColumns","dataColumns","result","schemaSet","insertedDerived","Map","inserted","schemaCol","suffix","slice","test","baseIdx","indexOf","derivedList","get","insertIdx","splice","set","match","basePath","index","prevIndex","parseInt","prevCol","prevIdx","createdAtIdx","derivedCols","idx","columns","columnsSet","patterns","map","field","underscored","exact","original","prefix","pattern","hasExactColumn","column"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,6BAA4B;AAyBlE;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,mBAAmB,CAAC,EAC/BC,gBAAgB,EAChBC,iBAAiB,EAAE,EACnBC,QAAQC,cAAc,EACtBC,MAAM,EACNC,WAAW,EACU;IACrB,MAAMC,cAAcC,QAAQP,iBAAiBQ,QAAQ;IAErD,wCAAwC;IACxC,MAAMC,gBAAgBL,WAAW,SAASC,eAAeA,YAAYK,MAAM,GAAG;IAE9E,8FAA8F;IAC9F,IAAIC,gBAAgBb,sBAClBE,iBAAiBY,eAAe,EAChC,IACAH,gBAAgB;QAAEJ;IAAY,IAAI,CAAC;IAGrC,mDAAmD;IACnD,MAAMQ,eAAe;QAAC;QAAM;QAAa;KAAY;IACrDF,gBAAgB;WAAIE;WAAiBF;KAAc;IAEnD,8CAA8C;IAC9C,IAAIR,kBAAkBA,eAAeO,MAAM,GAAG,GAAG;QAC/CC,gBAAgBG,uBAAuBH,eAAeR;IACxD;IAEA,yBAAyB;IACzB,IAAIF,eAAeS,MAAM,GAAG,GAAG;QAC7B,MAAMK,cAAc,IAAIC;QACxB,KAAK,MAAMC,QAAQhB,eAA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3,"sources":["../../src/utilities/getSchemaColumns.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from 'payload'\n\nimport { getFlattenedFieldKeys } from './getFlattenedFieldKeys.js'\n\nexport type GetSchemaColumnsArgs = {\n /**\n * The collection configuration to derive columns from\n */\n collectionConfig: SanitizedCollectionConfig\n /**\n * Array of disabled field paths from plugin config\n */\n disabledFields?: string[]\n /**\n * User-selected fields to export. If provided, only these fields (and their nested fields) will be included.\n */\n fields?: string[]\n /**\n * The locale to export. When 'all', localized fields are expanded to include all locale suffixes.\n */\n locale?: null | string\n /**\n * Available locale codes from config. Required when locale='all'.\n */\n localeCodes?: string[]\n}\n\n/**\n * Derives CSV column names from the collection schema.\n * This provides a base set of columns from field definitions.\n *\n * Note: For arrays/blocks with multiple items, the schema only generates index 0.\n * Additional indices from actual data should be merged with these columns.\n *\n * Benefits:\n * - Provides consistent base columns\n * - Works for empty exports\n * - Ensures proper column ordering\n */\nexport const getSchemaColumns = ({\n collectionConfig,\n disabledFields = [],\n fields: selectedFields,\n locale,\n localeCodes,\n}: GetSchemaColumnsArgs): string[] => {\n const expandLocales = locale === 'all' && localeCodes && localeCodes.length > 0\n\n let schemaColumns = getFlattenedFieldKeys(\n collectionConfig.flattenedFields,\n '',\n expandLocales ? { localeCodes } : {},\n )\n\n // Add id if not present in schema\n const hasIdField = schemaColumns.includes('id')\n if (!hasIdField) {\n schemaColumns = ['id', ...schemaColumns]\n }\n\n if (selectedFields && selectedFields.length > 0) {\n schemaColumns = filterToSelectedFields(schemaColumns, selectedFields)\n }\n\n if (disabledFields.length > 0) {\n const disabledSet = new Set<string>()\n for (const path of disabledFields) {\n disabledSet.add(path.replace(/\\./g, '_'))\n }\n schemaColumns = schemaColumns.filter((col) => {\n for (const disabled of disabledSet) {\n if (col === disabled || col.startsWith(`${disabled}_`)) {\n return false\n }\n }\n return true\n })\n }\n\n return schemaColumns\n}\n\n/**\n * Merges schema-derived columns with data-discovered columns.\n * Schema columns provide the base ordering, data columns add any additional\n * columns (e.g., array indices beyond 0, dynamic fields, derived columns from toCSV).\n */\nexport const mergeColumns = (schemaColumns: string[], dataColumns: string[]): string[] => {\n const result = [...schemaColumns]\n const schemaSet = new Set(schemaColumns)\n const insertedDerived = new Map<string, string[]>()\n\n for (const col of dataColumns) {\n if (!schemaSet.has(col)) {\n let inserted = false\n\n for (const schemaCol of schemaColumns) {\n if (col.startsWith(`${schemaCol}_`)) {\n const suffix = col.slice(schemaCol.length + 1)\n // Skip if suffix starts with a digit (array index pattern like field_0_*)\n if (!/^\\d/.test(suffix)) {\n const baseIdx = result.indexOf(schemaCol)\n if (baseIdx !== -1) {\n const derivedList = insertedDerived.get(schemaCol) || []\n const insertIdx = baseIdx + 1 + derivedList.length\n result.splice(insertIdx, 0, col)\n derivedList.push(col)\n insertedDerived.set(schemaCol, derivedList)\n schemaSet.add(col)\n inserted = true\n break\n }\n }\n }\n }\n\n if (!inserted) {\n // Check for array indices (e.g., field_1_*), insert after field_0_*\n const match = col.match(/^(.+?)_(\\d+)(_.*)?$/)\n if (match) {\n const [, basePath, index, suffix] = match\n if (basePath && index) {\n const prevIndex = parseInt(index, 10) - 1\n const prevCol = `${basePath}_${prevIndex}${suffix ?? ''}`\n const prevIdx = result.indexOf(prevCol)\n if (prevIdx !== -1) {\n // Insert after the previous index column\n result.splice(prevIdx + 1, 0, col)\n schemaSet.add(col)\n continue\n }\n }\n }\n\n const createdAtIdx = result.indexOf('createdAt')\n if (createdAtIdx !== -1) {\n result.splice(createdAtIdx, 0, col)\n } else {\n result.push(col)\n }\n schemaSet.add(col)\n }\n }\n }\n\n // Remove schema columns that were fully replaced by toCSV-derived columns (e.g. \"user\" → \"user_id\", \"user_email\")\n for (const [schemaCol, derivedCols] of insertedDerived) {\n if (!dataColumns.includes(schemaCol) && derivedCols.length > 0) {\n const idx = result.indexOf(schemaCol)\n if (idx !== -1) {\n result.splice(idx, 1)\n }\n }\n }\n\n return result\n}\n\n/**\n * Filters schema columns to only include those matching user-selected fields.\n * Preserves the order specified by the user in selectedFields.\n *\n * Container fields (groups, arrays, blocks) don't produce their own column, so we prefix-expand\n * to find their children (e.g., 'group' → 'group_name', 'group_age').\n * Leaf fields (date, text, select) produce an exact column, so we only match exactly to avoid\n * including siblings with similar prefixes (e.g., 'dateWithTimezone' won't pull 'dateWithTimezone_tz').\n */\nexport function filterToSelectedFields(columns: string[], selectedFields: string[]): string[] {\n const result: string[] = []\n const columnsSet = new Set(columns)\n\n // Convert selected fields to underscore notation patterns\n const patterns = selectedFields.map((field) => {\n const underscored = field.replace(/\\./g, '_')\n return {\n exact: underscored,\n original: field,\n prefix: `${underscored}_`,\n }\n })\n\n // Iterate through user-specified fields in order to preserve their ordering\n for (const pattern of patterns) {\n const hasExactColumn = columnsSet.has(pattern.exact)\n\n if (hasExactColumn && !result.includes(pattern.exact)) {\n result.push(pattern.exact)\n }\n\n // Only prefix-expand if no exact column match exists (containers need expansion, leaves don't)\n if (!hasExactColumn) {\n for (const column of columns) {\n if (column.startsWith(pattern.prefix)) {\n if (!result.includes(column)) {\n result.push(column)\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["getFlattenedFieldKeys","getSchemaColumns","collectionConfig","disabledFields","fields","selectedFields","locale","localeCodes","expandLocales","length","schemaColumns","flattenedFields","hasIdField","includes","filterToSelectedFields","disabledSet","Set","path","add","replace","filter","col","disabled","startsWith","mergeColumns","dataColumns","result","schemaSet","insertedDerived","Map","has","inserted","schemaCol","suffix","slice","test","baseIdx","indexOf","derivedList","get","insertIdx","splice","push","set","match","basePath","index","prevIndex","parseInt","prevCol","prevIdx","createdAtIdx","derivedCols","idx","columns","columnsSet","patterns","map","field","underscored","exact","original","prefix","pattern","hasExactColumn","column"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,6BAA4B;AAyBlE;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,mBAAmB,CAAC,EAC/BC,gBAAgB,EAChBC,iBAAiB,EAAE,EACnBC,QAAQC,cAAc,EACtBC,MAAM,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