@payloadcms/plugin-import-export 3.84.1 → 3.85.0
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/export/batchProcessor.d.ts +9 -1
- package/dist/export/batchProcessor.d.ts.map +1 -1
- package/dist/export/batchProcessor.js +57 -15
- package/dist/export/batchProcessor.js.map +1 -1
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +98 -20
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/handlePreview.d.ts.map +1 -1
- package/dist/export/handlePreview.js +38 -13
- package/dist/export/handlePreview.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/import/batchProcessor.d.ts +14 -2
- package/dist/import/batchProcessor.d.ts.map +1 -1
- package/dist/import/batchProcessor.js +49 -27
- package/dist/import/batchProcessor.js.map +1 -1
- package/dist/import/createImport.d.ts +1 -10
- package/dist/import/createImport.d.ts.map +1 -1
- package/dist/import/createImport.js +33 -52
- package/dist/import/createImport.js.map +1 -1
- package/dist/import/handlePreview.d.ts.map +1 -1
- package/dist/import/handlePreview.js +32 -6
- package/dist/import/handlePreview.js.map +1 -1
- package/dist/index.d.ts +58 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +218 -39
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/applyFieldHooks.d.ts +23 -0
- package/dist/utilities/applyFieldHooks.d.ts.map +1 -0
- package/dist/utilities/applyFieldHooks.js +118 -0
- package/dist/utilities/applyFieldHooks.js.map +1 -0
- package/dist/utilities/applyFieldHooks.spec.js +205 -0
- package/dist/utilities/applyFieldHooks.spec.js.map +1 -0
- package/dist/utilities/collectDisabledFieldPaths.d.ts.map +1 -1
- package/dist/utilities/collectDisabledFieldPaths.js +1 -1
- package/dist/utilities/collectDisabledFieldPaths.js.map +1 -1
- package/dist/utilities/flattenObject.d.ts +8 -6
- package/dist/utilities/flattenObject.d.ts.map +1 -1
- package/dist/utilities/flattenObject.js +95 -75
- package/dist/utilities/flattenObject.js.map +1 -1
- package/dist/utilities/flattenObject.spec.js +158 -0
- package/dist/utilities/flattenObject.spec.js.map +1 -0
- package/dist/utilities/flattenedFields.d.ts +21 -0
- package/dist/utilities/flattenedFields.d.ts.map +1 -0
- package/dist/utilities/flattenedFields.js +34 -0
- package/dist/utilities/flattenedFields.js.map +1 -0
- package/dist/utilities/getExportFieldFunctions.d.ts +5 -5
- package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getExportFieldFunctions.js +92 -98
- package/dist/utilities/getExportFieldFunctions.js.map +1 -1
- package/dist/utilities/getExportFieldFunctions.spec.js +50 -0
- package/dist/utilities/getExportFieldFunctions.spec.js.map +1 -0
- package/dist/utilities/getImportFieldFunctions.d.ts +5 -5
- package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getImportFieldFunctions.js +103 -103
- package/dist/utilities/getImportFieldFunctions.js.map +1 -1
- package/dist/utilities/getImportFieldFunctions.spec.js +167 -0
- package/dist/utilities/getImportFieldFunctions.spec.js.map +1 -0
- package/dist/utilities/isPlainObject.d.ts +2 -0
- package/dist/utilities/isPlainObject.d.ts.map +1 -0
- package/dist/utilities/isPlainObject.js +3 -0
- package/dist/utilities/isPlainObject.js.map +1 -0
- package/dist/utilities/legacyHookDispatch.spec.js +227 -0
- package/dist/utilities/legacyHookDispatch.spec.js.map +1 -0
- package/dist/utilities/polymorphicRel.d.ts +14 -0
- package/dist/utilities/polymorphicRel.d.ts.map +1 -0
- package/dist/utilities/polymorphicRel.js +17 -0
- package/dist/utilities/polymorphicRel.js.map +1 -0
- package/dist/utilities/processRichTextField.js.map +1 -1
- package/dist/utilities/removeDisabledFields.js.map +1 -1
- package/dist/utilities/setNestedValue.d.ts.map +1 -1
- package/dist/utilities/setNestedValue.js +10 -8
- package/dist/utilities/setNestedValue.js.map +1 -1
- package/dist/utilities/siblingDoc.spec.js +278 -0
- package/dist/utilities/siblingDoc.spec.js.map +1 -0
- package/dist/utilities/unflattenObject.d.ts +4 -3
- package/dist/utilities/unflattenObject.d.ts.map +1 -1
- package/dist/utilities/unflattenObject.js +57 -169
- package/dist/utilities/unflattenObject.js.map +1 -1
- package/dist/utilities/unflattenObject.spec.js +33 -0
- package/dist/utilities/unflattenObject.spec.js.map +1 -1
- package/dist/utilities/unflattenPostProcess.d.ts +11 -0
- package/dist/utilities/unflattenPostProcess.d.ts.map +1 -0
- package/dist/utilities/unflattenPostProcess.js +148 -0
- package/dist/utilities/unflattenPostProcess.js.map +1 -0
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { Config } from 'payload';
|
|
2
|
-
import type { FromCSVFunction, ImportExportPluginConfig, Limit, ToCSVFunction } from './types.js';
|
|
2
|
+
import type { ExportAfterHook, ExportBeforeHook, FieldBeforeExportHook, FieldBeforeImportHook, FromCSVFunction, ImportAfterHook, ImportBeforeHook, ImportExportPluginConfig, Limit, ToCSVFunction } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Adds CSV/JSON import and export functionality to selected collections.
|
|
5
|
+
*
|
|
6
|
+
* Registers two upload collections (`exports`, `imports`) that drive the admin
|
|
7
|
+
* UI flow, plus the `createCollectionExport` and `createCollectionImport` jobs
|
|
8
|
+
* that run the work asynchronously. Per-collection settings (batch size, limits,
|
|
9
|
+
* format, lifecycle hooks, override) live on each entry of `collections`.
|
|
10
|
+
*
|
|
11
|
+
* @see https://payloadcms.com/docs/plugins/import-export
|
|
12
|
+
*/
|
|
3
13
|
export declare const importExportPlugin: (pluginConfig: ImportExportPluginConfig) => (config: Config) => Promise<Config>;
|
|
4
14
|
declare module 'payload' {
|
|
5
15
|
interface FieldCustom {
|
|
@@ -12,9 +22,30 @@ declare module 'payload' {
|
|
|
12
22
|
* @default false
|
|
13
23
|
*/
|
|
14
24
|
disabled?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated use `hooks.beforeImport` instead.
|
|
27
|
+
* Still functional, but will be removed in a future major version.
|
|
28
|
+
*/
|
|
15
29
|
fromCSV?: FromCSVFunction;
|
|
16
30
|
/**
|
|
17
|
-
*
|
|
31
|
+
* Field-level lifecycle hooks for import/export transformations.
|
|
32
|
+
* Works for both CSV and JSON formats.
|
|
33
|
+
*/
|
|
34
|
+
hooks?: {
|
|
35
|
+
/**
|
|
36
|
+
* Runs before a field value is exported. Return a transformed value,
|
|
37
|
+
* `undefined` to use default behavior, or mutate `siblingData` to add
|
|
38
|
+
* extra columns at the same level.
|
|
39
|
+
*/
|
|
40
|
+
beforeExport?: FieldBeforeExportHook;
|
|
41
|
+
/**
|
|
42
|
+
* Runs before a field value is imported. Return the transformed value.
|
|
43
|
+
*/
|
|
44
|
+
beforeImport?: FieldBeforeImportHook;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated use `hooks.beforeExport` instead.
|
|
48
|
+
* Still functional, but will be removed in a future major version.
|
|
18
49
|
*/
|
|
19
50
|
toCSV?: ToCSVFunction;
|
|
20
51
|
};
|
|
@@ -47,9 +78,17 @@ declare module 'payload' {
|
|
|
47
78
|
};
|
|
48
79
|
}
|
|
49
80
|
interface CollectionCustom {
|
|
81
|
+
/**
|
|
82
|
+
* @internal
|
|
83
|
+
* Server-side storage for resolved plugin config. Users should configure
|
|
84
|
+
* import/export via `importExportPlugin({ collections: [{ slug, export: { ... }, import: { ... } }] })`.
|
|
85
|
+
* These fields are populated automatically and are not part of the public
|
|
86
|
+
* API — the names here intentionally diverge from the user-facing nested
|
|
87
|
+
* `export.hooks` / `import.hooks` config and may change without notice.
|
|
88
|
+
*/
|
|
50
89
|
'plugin-import-export'?: {
|
|
51
90
|
/**
|
|
52
|
-
* Default version status for imported documents when _status field is not provided.
|
|
91
|
+
* @internal Default version status for imported documents when _status field is not provided.
|
|
53
92
|
* Only applies to collections with versions enabled.
|
|
54
93
|
* @default 'published'
|
|
55
94
|
*/
|
|
@@ -64,6 +103,14 @@ declare module 'payload' {
|
|
|
64
103
|
* @default false
|
|
65
104
|
*/
|
|
66
105
|
exportDisableJobsQueue?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Lifecycle hooks for export operations. Stored server-side since functions
|
|
108
|
+
* cannot be serialized to the client.
|
|
109
|
+
*/
|
|
110
|
+
exportHooks?: {
|
|
111
|
+
after?: ExportAfterHook;
|
|
112
|
+
before?: ExportBeforeHook;
|
|
113
|
+
};
|
|
67
114
|
/**
|
|
68
115
|
* Maximum number of documents that can be exported from this collection.
|
|
69
116
|
* Set to 0 for unlimited (default). Can be a number or function.
|
|
@@ -80,6 +127,14 @@ declare module 'payload' {
|
|
|
80
127
|
* @default false
|
|
81
128
|
*/
|
|
82
129
|
importDisableJobsQueue?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Lifecycle hooks for import operations. Stored server-side since functions
|
|
132
|
+
* cannot be serialized to the client.
|
|
133
|
+
*/
|
|
134
|
+
importHooks?: {
|
|
135
|
+
after?: ImportAfterHook;
|
|
136
|
+
before?: ImportBeforeHook;
|
|
137
|
+
};
|
|
83
138
|
/**
|
|
84
139
|
* Maximum number of documents that can be imported to this collection.
|
|
85
140
|
* Set to 0 for unlimited (default). Can be a number or function.
|
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":"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AAO,GAAG,WAAW,CAAA;YAC5C;;;eAGG;YACH,eAAe,CAAC,EAAE,MAAM,CAAA;YACxB;;;eAGG;YACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;YAChC;;;eAGG;YACH,WAAW,CAAC,EAAE;gBAAE,KAAK,CAAC,EAAE,eAAe,CAAC;gBAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;aAAE,CAAA;YACpE;;;;eAIG;YACH,WAAW,CAAC,EAAE,KAAK,CAAA;YACnB;;;eAGG;YACH,eAAe,CAAC,EAAE,MAAM,CAAA;YACxB;;;eAGG;YACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;YAChC;;;eAGG;YACH,WAAW,CAAC,EAAE;gBAAE,KAAK,CAAC,EAAE,eAAe,CAAC;gBAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;aAAE,CAAA;YACpE;;;;eAIG;YACH,WAAW,CAAC,EAAE,KAAK,CAAA;SACpB,CAAA;KACF;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,16 @@ import { getCreateCollectionImportTask } from './import/getCreateImportCollectio
|
|
|
4
4
|
import { translations } from './translations/index.js';
|
|
5
5
|
import { collectDisabledFieldPaths } from './utilities/collectDisabledFieldPaths.js';
|
|
6
6
|
import { getPluginCollections } from './utilities/getPluginCollections.js';
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Adds CSV/JSON import and export functionality to selected collections.
|
|
9
|
+
*
|
|
10
|
+
* Registers two upload collections (`exports`, `imports`) that drive the admin
|
|
11
|
+
* UI flow, plus the `createCollectionExport` and `createCollectionImport` jobs
|
|
12
|
+
* that run the work asynchronously. Per-collection settings (batch size, limits,
|
|
13
|
+
* format, lifecycle hooks, override) live on each entry of `collections`.
|
|
14
|
+
*
|
|
15
|
+
* @see https://payloadcms.com/docs/plugins/import-export
|
|
16
|
+
*/ export const importExportPlugin = (pluginConfig)=>async (config)=>{
|
|
8
17
|
// Get all export/import collections and the mappings from target collections to custom collections
|
|
9
18
|
const { customExportSlugMap, customImportSlugMap, exportCollections, importCollections } = await getPluginCollections({
|
|
10
19
|
config,
|
|
@@ -103,8 +112,10 @@ export const importExportPlugin = (pluginConfig)=>async (config)=>{
|
|
|
103
112
|
const importDisableJobsQueue = importConfig?.disableJobsQueue;
|
|
104
113
|
const importBatchSize = importConfig?.batchSize;
|
|
105
114
|
const exportLimit = exportConfig?.limit ?? pluginConfig.exportLimit;
|
|
115
|
+
const exportHooks = exportConfig?.hooks;
|
|
106
116
|
const importLimit = importConfig?.limit ?? pluginConfig.importLimit;
|
|
107
117
|
const importDefaultVersionStatus = importConfig?.defaultVersionStatus;
|
|
118
|
+
const importHooks = importConfig?.hooks;
|
|
108
119
|
collection.admin.custom = {
|
|
109
120
|
...collection.admin.custom || {},
|
|
110
121
|
'plugin-import-export': {
|
|
@@ -145,6 +156,12 @@ export const importExportPlugin = (pluginConfig)=>async (config)=>{
|
|
|
145
156
|
},
|
|
146
157
|
...importDefaultVersionStatus !== undefined && {
|
|
147
158
|
defaultVersionStatus: importDefaultVersionStatus
|
|
159
|
+
},
|
|
160
|
+
...exportHooks !== undefined && {
|
|
161
|
+
exportHooks
|
|
162
|
+
},
|
|
163
|
+
...importHooks !== undefined && {
|
|
164
|
+
importHooks
|
|
148
165
|
}
|
|
149
166
|
}
|
|
150
167
|
};
|
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 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 const exportDisableJobsQueue = exportConfig?.disableJobsQueue\n const exportBatchSize = exportConfig?.batchSize\n const exportDisableSave = exportConfig?.disableSave\n const exportDisableDownload = exportConfig?.disableDownload\n\n const importConfig =\n typeof collectionPluginConfig?.import === 'object'\n ? collectionPluginConfig.import\n : undefined\n const importDisableJobsQueue = importConfig?.disableJobsQueue\n const importBatchSize = importConfig?.batchSize\n\n const exportLimit = exportConfig?.limit ?? pluginConfig.exportLimit\n\n const importLimit = importConfig?.limit ?? pluginConfig.importLimit\n const importDefaultVersionStatus = importConfig?.defaultVersionStatus\n\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 ...(exportDisableSave !== undefined && { disableSave: exportDisableSave }),\n ...(exportDisableDownload !== undefined && { disableDownload: exportDisableDownload }),\n },\n }\n\n collection.custom = {\n ...(collection.custom || {}),\n 'plugin-import-export': {\n ...(collection.custom?.['plugin-import-export'] || {}),\n ...(exportLimit !== undefined && { exportLimit }),\n ...(exportDisableJobsQueue !== undefined && {\n exportDisableJobsQueue,\n }),\n ...(exportBatchSize !== undefined && { exportBatchSize }),\n ...(importLimit !== undefined && { importLimit }),\n ...(importDisableJobsQueue !== undefined && {\n importDisableJobsQueue,\n }),\n ...(importBatchSize !== undefined && { importBatchSize }),\n ...(importDefaultVersionStatus !== undefined && {\n defaultVersionStatus: importDefaultVersionStatus,\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 * If true, disables the download button in the export preview UI.\n */\n disableDownload?: boolean\n /**\n * If true, disables the save button in the export preview UI.\n */\n disableSave?: boolean\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 * Default version status for imported documents when _status field is not provided.\n * Only applies to collections with versions enabled.\n * @default 'published'\n */\n defaultVersionStatus?: 'draft' | 'published'\n /**\n * Number of documents to process in each batch during export.\n * @default 100\n */\n exportBatchSize?: number\n /**\n * If true, disables the jobs queue for exports and runs them synchronously.\n * @default false\n */\n exportDisableJobsQueue?: boolean\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 * Number of documents to process in each batch during import.\n * @default 100\n */\n importBatchSize?: number\n /**\n * If true, disables the jobs queue for imports and runs them synchronously.\n * @default false\n */\n importDisableJobsQueue?: boolean\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","exportDisableJobsQueue","disableJobsQueue","exportBatchSize","batchSize","exportDisableSave","disableSave","exportDisableDownload","disableDownload","importConfig","importDisableJobsQueue","importBatchSize","exportLimit","limit","importLimit","importDefaultVersionStatus","defaultVersionStatus","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;eAAsBC;SAAkB,CAAE;YACrE,MAAMW,aAAaf,OAAOa,WAAW,CAACG,IAAI,CAAC,CAACN,IAAMA,EAAEC,IAAI,KAAKG,WAAWH,IAAI;YAC5E,IAAI,CAACI,YAAY;gBACff,OAAOa,WAAW,CAACI,IAAI,CAACH;YAC1B;QACF;QAEA,uCAAuC;Q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7E,cAAc8E,MAAM,CAChE,CAACC,KAAK,CAACC,KAAKC,MAAM;YAChBF,GAAG,CAACC,IAAI,GAAGC,MAAMjF,YAAY;YAC7B,OAAO+E;QACT,GACA,CAAC;QAGH1E,OAAOqE,IAAI,GAAG;YACZ,GAAGrE,OAAOqE,IAAI;YACd1E,cAAcH,gBAAgB8E,wBAAwBtE,OAAOqE,IAAI,EAAE1E,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 ExportAfterHook,\n ExportBeforeHook,\n FieldBeforeExportHook,\n FieldBeforeImportHook,\n FromCSVFunction,\n ImportAfterHook,\n ImportBeforeHook,\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\n/**\n * Adds CSV/JSON import and export functionality to selected collections.\n *\n * Registers two upload collections (`exports`, `imports`) that drive the admin\n * UI flow, plus the `createCollectionExport` and `createCollectionImport` jobs\n * that run the work asynchronously. Per-collection settings (batch size, limits,\n * format, lifecycle hooks, override) live on each entry of `collections`.\n *\n * @see https://payloadcms.com/docs/plugins/import-export\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 const exportDisableJobsQueue = exportConfig?.disableJobsQueue\n const exportBatchSize = exportConfig?.batchSize\n const exportDisableSave = exportConfig?.disableSave\n const exportDisableDownload = exportConfig?.disableDownload\n\n const importConfig =\n typeof collectionPluginConfig?.import === 'object'\n ? collectionPluginConfig.import\n : undefined\n const importDisableJobsQueue = importConfig?.disableJobsQueue\n const importBatchSize = importConfig?.batchSize\n\n const exportLimit = exportConfig?.limit ?? pluginConfig.exportLimit\n const exportHooks = exportConfig?.hooks\n\n const importLimit = importConfig?.limit ?? pluginConfig.importLimit\n const importDefaultVersionStatus = importConfig?.defaultVersionStatus\n const importHooks = importConfig?.hooks\n\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 ...(exportDisableSave !== undefined && { disableSave: exportDisableSave }),\n ...(exportDisableDownload !== undefined && { disableDownload: exportDisableDownload }),\n },\n }\n\n collection.custom = {\n ...(collection.custom || {}),\n 'plugin-import-export': {\n ...(collection.custom?.['plugin-import-export'] || {}),\n ...(exportLimit !== undefined && { exportLimit }),\n ...(exportDisableJobsQueue !== undefined && {\n exportDisableJobsQueue,\n }),\n ...(exportBatchSize !== undefined && { exportBatchSize }),\n ...(importLimit !== undefined && { importLimit }),\n ...(importDisableJobsQueue !== undefined && {\n importDisableJobsQueue,\n }),\n ...(importBatchSize !== undefined && { importBatchSize }),\n ...(importDefaultVersionStatus !== undefined && {\n defaultVersionStatus: importDefaultVersionStatus,\n }),\n ...(exportHooks !== undefined && { exportHooks }),\n ...(importHooks !== undefined && { importHooks }),\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 /**\n * @deprecated use `hooks.beforeImport` instead.\n * Still functional, but will be removed in a future major version.\n */\n fromCSV?: FromCSVFunction\n /**\n * Field-level lifecycle hooks for import/export transformations.\n * Works for both CSV and JSON formats.\n */\n hooks?: {\n /**\n * Runs before a field value is exported. Return a transformed value,\n * `undefined` to use default behavior, or mutate `siblingData` to add\n * extra columns at the same level.\n */\n beforeExport?: FieldBeforeExportHook\n /**\n * Runs before a field value is imported. Return the transformed value.\n */\n beforeImport?: FieldBeforeImportHook\n }\n /**\n * @deprecated use `hooks.beforeExport` instead.\n * Still functional, but will be removed in a future major version.\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 * If true, disables the download button in the export preview UI.\n */\n disableDownload?: boolean\n /**\n * If true, disables the save button in the export preview UI.\n */\n disableSave?: boolean\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 /**\n * @internal\n * Server-side storage for resolved plugin config. Users should configure\n * import/export via `importExportPlugin({ collections: [{ slug, export: { ... }, import: { ... } }] })`.\n * These fields are populated automatically and are not part of the public\n * API — the names here intentionally diverge from the user-facing nested\n * `export.hooks` / `import.hooks` config and may change without notice.\n */\n 'plugin-import-export'?: {\n /**\n * @internal Default version status for imported documents when _status field is not provided.\n * Only applies to collections with versions enabled.\n * @default 'published'\n */\n defaultVersionStatus?: 'draft' | 'published'\n /**\n * Number of documents to process in each batch during export.\n * @default 100\n */\n exportBatchSize?: number\n /**\n * If true, disables the jobs queue for exports and runs them synchronously.\n * @default false\n */\n exportDisableJobsQueue?: boolean\n /**\n * Lifecycle hooks for export operations. Stored server-side since functions\n * cannot be serialized to the client.\n */\n exportHooks?: { after?: ExportAfterHook; before?: ExportBeforeHook }\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 * Number of documents to process in each batch during import.\n * @default 100\n */\n importBatchSize?: number\n /**\n * If true, disables the jobs queue for imports and runs them synchronously.\n * @default false\n */\n importDisableJobsQueue?: boolean\n /**\n * Lifecycle hooks for import operations. Stored server-side since functions\n * cannot be serialized to the client.\n */\n importHooks?: { after?: ImportAfterHook; before?: ImportBeforeHook }\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","exportDisableJobsQueue","disableJobsQueue","exportBatchSize","batchSize","exportDisableSave","disableSave","exportDisableDownload","disableDownload","importConfig","importDisableJobsQueue","importBatchSize","exportLimit","limit","exportHooks","hooks","importLimit","importDefaultVersionStatus","defaultVersionStatus","importHooks","custom","disabledFields","i18n","simplifiedTranslations","Object","entries","reduce","acc","key","value"],"mappings":"AAEA,SAASA,eAAe,QAAQ,UAAS;AAiBzC,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;;;;;;;;;CASC,GACD,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,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AC,uBAAuB,IAAI,CAAC,CAAC;oBACrD,GAAIR,gBAAgBd,aAAa;wBAAEc;oBAAY,CAAC;oBAChD,GAAIX,2BAA2BH,aAAa;wBAC1CG;oBACF,CAAC;oBACD,GAAIE,oBAAoBL,aAAa;wBAAEK;oBAAgB,CAAC;oBACxD,GAAIa,gBAAgBlB,aAAa;wBAAEkB;oBAAY,CAAC;oBAChD,GAAIN,2BAA2BZ,aAAa;wBAC1CY;oBACF,CAAC;oBACD,GAAIC,oBAAoBb,aAAa;wBAAEa;oBAAgB,CAAC;oBACxD,GAAIM,+BAA+BnB,aAAa;wBAC9CoB,sBAAsBD;oBACxB,CAAC;oBACD,GAAIH,gBAAgBhB,aAAa;wBAAEgB;oBAAY,CAAC;oBAChD,GAAIK,gBAAgBrB,aAAa;wBAAEqB;oBAAY,CAAC;gBAClD;YACF;YAEAvD,WAAWI,KAAK,CAACC,UAAU,GAAGA;QAChC;QAEA,IAAI,CAACnB,OAAOwE,IAAI,EAAE;YAChBxE,OAAOwE,IAAI,GAAG,CAAC;QACjB;QAEA;;KAEC,GACD,MAAMC,yBAAyBC,OAAOC,OAAO,CAAChF,cAAciF,MAAM,CAChE,CAACC,KAAK,CAACC,KAAKC,MAAM;YAChBF,GAAG,CAACC,IAAI,GAAGC,MAAMpF,YAAY;YAC7B,OAAOkF;QACT,GACA,CAAC;QAGH7E,OAAOwE,IAAI,GAAG;YACZ,GAAGxE,OAAOwE,IAAI;YACd7E,cAAcH,gBAAgBiF,wBAAwBzE,OAAOwE,IAAI,EAAE7E,gBAAgB,CAAC;QACtF;QAEA,OAAOK;IACT,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig, CollectionSlug, PayloadRequest } from 'payload';
|
|
1
|
+
import type { CollectionConfig, CollectionSlug, DataFromCollectionSlug, PayloadRequest } from 'payload';
|
|
2
2
|
/**
|
|
3
3
|
* Function to dynamically determine the limit based on request context
|
|
4
4
|
*/
|
|
@@ -16,7 +16,112 @@ export type Limit = LimitFunction | number;
|
|
|
16
16
|
export type CollectionOverride = ({ collection, }: {
|
|
17
17
|
collection: CollectionConfig;
|
|
18
18
|
}) => CollectionConfig | Promise<CollectionConfig>;
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Result of a completed import operation (or a single batch within one)
|
|
21
|
+
*/
|
|
22
|
+
export type ImportResult = {
|
|
23
|
+
errors: Array<{
|
|
24
|
+
doc: Record<string, unknown>;
|
|
25
|
+
error: string;
|
|
26
|
+
index: number;
|
|
27
|
+
}>;
|
|
28
|
+
imported: number;
|
|
29
|
+
total: number;
|
|
30
|
+
updated: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Hook called before each export batch is written to file.
|
|
34
|
+
* Receives the transformed batch data and the original DB documents.
|
|
35
|
+
* Return the modified data array — it replaces `data` for the write step.
|
|
36
|
+
*/
|
|
37
|
+
export type ExportBeforeHook<TSlug extends CollectionSlug = CollectionSlug> = (args: {
|
|
38
|
+
/** Current batch number, starting at 1 */
|
|
39
|
+
batchNumber: number;
|
|
40
|
+
/** Transformed batch — flat rows for CSV, nested docs for JSON. Modify and return this. */
|
|
41
|
+
data: Record<string, unknown>[];
|
|
42
|
+
/** Export format. Open-ended to support custom formats in the future. */
|
|
43
|
+
format: 'csv' | 'json' | ({} & string);
|
|
44
|
+
/**
|
|
45
|
+
* Raw DB documents before format-specific transformation. Read-only reference.
|
|
46
|
+
*
|
|
47
|
+
* Typed as a union so call sites that don't know the collection slug at
|
|
48
|
+
* compile time (e.g. job tasks) don't need `as any` casts. To get the
|
|
49
|
+
* narrower typed shape, declare your hook with a slug:
|
|
50
|
+
* `const hook: ExportBeforeHook<'posts'> = (args) => { ... }`.
|
|
51
|
+
*/
|
|
52
|
+
originalData: DataFromCollectionSlug<TSlug>[] | Record<string, unknown>[];
|
|
53
|
+
req: PayloadRequest;
|
|
54
|
+
/** Total number of batches for this export operation */
|
|
55
|
+
totalBatches: number;
|
|
56
|
+
}) => Promise<Record<string, unknown>[]> | Record<string, unknown>[];
|
|
57
|
+
/**
|
|
58
|
+
* Hook called after each export batch has been written to file.
|
|
59
|
+
* For logging and observability only — return value is ignored.
|
|
60
|
+
*/
|
|
61
|
+
export type ExportAfterHook = (args: {
|
|
62
|
+
/** Current batch number, starting at 1 */
|
|
63
|
+
batchNumber: number;
|
|
64
|
+
/** The batch data that was written */
|
|
65
|
+
data: Record<string, unknown>[];
|
|
66
|
+
/** Export format */
|
|
67
|
+
format: 'csv' | 'json' | ({} & string);
|
|
68
|
+
/** Raw DB documents before transformation */
|
|
69
|
+
originalData: Record<string, unknown>[];
|
|
70
|
+
req: PayloadRequest;
|
|
71
|
+
/** Total number of batches for this export operation */
|
|
72
|
+
totalBatches: number;
|
|
73
|
+
}) => Promise<void> | void;
|
|
74
|
+
/**
|
|
75
|
+
* Hook called before each import batch is written to the database.
|
|
76
|
+
* Receives the processed (unflattened) documents and the raw file rows.
|
|
77
|
+
* Return the modified documents array — it replaces `data` for the DB write step.
|
|
78
|
+
*/
|
|
79
|
+
export type ImportBeforeHook<TSlug extends CollectionSlug = CollectionSlug> = (args: {
|
|
80
|
+
/** Current batch number, starting at 1 */
|
|
81
|
+
batchNumber: number;
|
|
82
|
+
/**
|
|
83
|
+
* Unflattened documents ready to be written to the database. Modify and
|
|
84
|
+
* return this. Typed as `Partial<...>` because rows from a CSV or JSON
|
|
85
|
+
* import are not guaranteed to include every required field of the
|
|
86
|
+
* collection — required fields are validated at write time.
|
|
87
|
+
*/
|
|
88
|
+
data: Partial<DataFromCollectionSlug<TSlug>>[];
|
|
89
|
+
/** Import format. Open-ended to support custom formats in the future. */
|
|
90
|
+
format: 'csv' | 'json' | ({} & string);
|
|
91
|
+
/** Raw parsed file rows before unflattening. Read-only reference. */
|
|
92
|
+
originalData: Record<string, unknown>[];
|
|
93
|
+
req: PayloadRequest;
|
|
94
|
+
/** Total number of batches for this import operation */
|
|
95
|
+
totalBatches: number;
|
|
96
|
+
}) => Partial<DataFromCollectionSlug<TSlug>>[] | Promise<Partial<DataFromCollectionSlug<TSlug>>[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Hook called after each import batch has been written to the database.
|
|
99
|
+
* For logging and observability only — return value is ignored.
|
|
100
|
+
*/
|
|
101
|
+
export type ImportAfterHook = (args: {
|
|
102
|
+
/** Current batch number, starting at 1 */
|
|
103
|
+
batchNumber: number;
|
|
104
|
+
/** Import format */
|
|
105
|
+
format: 'csv' | 'json' | ({} & string);
|
|
106
|
+
/**
|
|
107
|
+
* Raw parsed file rows for this batch before unflattening and before-hook
|
|
108
|
+
* transformation. For CSV this is the flat key/value row; for JSON this is
|
|
109
|
+
* the top-level parsed document. Read-only reference.
|
|
110
|
+
*/
|
|
111
|
+
originalData: Record<string, unknown>[];
|
|
112
|
+
req: PayloadRequest;
|
|
113
|
+
/** Result of this batch — counts and errors. Not the cumulative total. */
|
|
114
|
+
result: ImportResult;
|
|
115
|
+
/** Total number of batches for this import operation */
|
|
116
|
+
totalBatches: number;
|
|
117
|
+
}) => Promise<void> | void;
|
|
118
|
+
/**
|
|
119
|
+
* Per-collection export configuration. Set on each entry of
|
|
120
|
+
* ```
|
|
121
|
+
* importExportPlugin({ collections: [{ slug, export: { ... } }] })
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export type ExportConfig<TSlug extends CollectionSlug = CollectionSlug> = {
|
|
20
125
|
/**
|
|
21
126
|
* Number of documents to process in each batch during export. This config is applied to both jobs and synchronous exports.
|
|
22
127
|
*
|
|
@@ -45,6 +150,22 @@ export type ExportConfig = {
|
|
|
45
150
|
* @default undefined
|
|
46
151
|
*/
|
|
47
152
|
format?: 'csv' | 'json';
|
|
153
|
+
/**
|
|
154
|
+
* Lifecycle hooks for export operations on this collection.
|
|
155
|
+
* Hooks fire once per batch.
|
|
156
|
+
*/
|
|
157
|
+
hooks?: {
|
|
158
|
+
/**
|
|
159
|
+
* Called after each batch is written to file. For logging/observability only.
|
|
160
|
+
* Return value is ignored.
|
|
161
|
+
*/
|
|
162
|
+
after?: ExportAfterHook;
|
|
163
|
+
/**
|
|
164
|
+
* Called before each batch is written to file.
|
|
165
|
+
* Return value replaces the batch data for the write step.
|
|
166
|
+
*/
|
|
167
|
+
before?: ExportBeforeHook<TSlug>;
|
|
168
|
+
};
|
|
48
169
|
/**
|
|
49
170
|
* Maximum number of documents that can be exported in a single operation.
|
|
50
171
|
* Can be a number or a function that returns a number based on request context.
|
|
@@ -58,7 +179,13 @@ export type ExportConfig = {
|
|
|
58
179
|
*/
|
|
59
180
|
overrideCollection?: CollectionOverride;
|
|
60
181
|
};
|
|
61
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Per-collection import configuration. Set on each entry of
|
|
184
|
+
* ```
|
|
185
|
+
* importExportPlugin({ collections: [{ slug, import: { ... } }] })
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export type ImportConfig<TSlug extends CollectionSlug = CollectionSlug> = {
|
|
62
189
|
/**
|
|
63
190
|
* Number of documents to process in each batch during import. This config is applied to both jobs and synchronous imports.
|
|
64
191
|
*
|
|
@@ -76,6 +203,22 @@ export type ImportConfig = {
|
|
|
76
203
|
* @default false
|
|
77
204
|
*/
|
|
78
205
|
disableJobsQueue?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Lifecycle hooks for import operations on this collection.
|
|
208
|
+
* Hooks fire once per batch.
|
|
209
|
+
*/
|
|
210
|
+
hooks?: {
|
|
211
|
+
/**
|
|
212
|
+
* Called after each batch is written to the database. For logging/observability only.
|
|
213
|
+
* Return value is ignored.
|
|
214
|
+
*/
|
|
215
|
+
after?: ImportAfterHook;
|
|
216
|
+
/**
|
|
217
|
+
* Called before each batch is written to the database.
|
|
218
|
+
* Return value replaces the batch data for the DB write step.
|
|
219
|
+
*/
|
|
220
|
+
before?: ImportBeforeHook<TSlug>;
|
|
221
|
+
};
|
|
79
222
|
/**
|
|
80
223
|
* Maximum number of documents that can be imported in a single operation.
|
|
81
224
|
* Can be a number or a function that returns a number based on request context.
|
|
@@ -89,23 +232,27 @@ export type ImportConfig = {
|
|
|
89
232
|
*/
|
|
90
233
|
overrideCollection?: CollectionOverride;
|
|
91
234
|
};
|
|
92
|
-
|
|
235
|
+
/**
|
|
236
|
+
* Per-collection plugin entry. Identifies a target collection by `slug` and
|
|
237
|
+
* configures its export/import behavior; either side can be disabled with `false`.
|
|
238
|
+
*/
|
|
239
|
+
export type PluginCollectionConfig<TSlug extends CollectionSlug = CollectionSlug> = {
|
|
93
240
|
/**
|
|
94
241
|
* Override the import collection for this collection or disable it entirely with `false`.
|
|
95
242
|
*
|
|
96
243
|
* @default true
|
|
97
244
|
*/
|
|
98
|
-
export?: boolean | ExportConfig
|
|
245
|
+
export?: boolean | ExportConfig<TSlug>;
|
|
99
246
|
/**
|
|
100
247
|
* Override the export collection for this collection or disable it entirely with `false`.
|
|
101
248
|
*
|
|
102
249
|
* @default true
|
|
103
250
|
*/
|
|
104
|
-
import?: boolean | ImportConfig
|
|
251
|
+
import?: boolean | ImportConfig<TSlug>;
|
|
105
252
|
/**
|
|
106
253
|
* Target collection's slug for import/export functionality
|
|
107
254
|
*/
|
|
108
|
-
slug:
|
|
255
|
+
slug: TSlug;
|
|
109
256
|
};
|
|
110
257
|
/**
|
|
111
258
|
* Configuration options for the Import/Export plugin
|
|
@@ -122,7 +269,7 @@ export type ImportExportPluginConfig = {
|
|
|
122
269
|
* If not specified, all collections will have import/export enabled.
|
|
123
270
|
* @default undefined (all collections)
|
|
124
271
|
*/
|
|
125
|
-
collections: PluginCollectionConfig[];
|
|
272
|
+
collections: PluginCollectionConfig<CollectionSlug>[];
|
|
126
273
|
/**
|
|
127
274
|
* Enable debug logging for troubleshooting import/export operations
|
|
128
275
|
* @default false
|
|
@@ -165,52 +312,84 @@ export type ImportExportPluginConfig = {
|
|
|
165
312
|
overrideImportCollection?: CollectionOverride;
|
|
166
313
|
};
|
|
167
314
|
/**
|
|
168
|
-
*
|
|
315
|
+
* Field-level hook that runs before a field value is exported. Works for both
|
|
316
|
+
* CSV and JSON. Return a value to replace the field, or `undefined` to fall
|
|
317
|
+
* back to default behavior. Mutate `siblingData` to add or remove columns at
|
|
318
|
+
* the same level.
|
|
319
|
+
*
|
|
320
|
+
* Return `null` (CSV only) when the hook has already written its replacement
|
|
321
|
+
* columns to `siblingData` and default flattening should be skipped — used by
|
|
322
|
+
* built-in handlers for polymorphic relationships to avoid duplicate columns.
|
|
323
|
+
*/
|
|
324
|
+
export type FieldBeforeExportHook = (args: {
|
|
325
|
+
/** Runtime column path, underscore-separated (includes array indices, e.g. `items_0_note`). */
|
|
326
|
+
columnName: string;
|
|
327
|
+
/** The top-level document being exported. */
|
|
328
|
+
data: Record<string, unknown>;
|
|
329
|
+
format: 'csv' | 'json' | ({} & string);
|
|
330
|
+
/** Writable output at the current level. CSV: the flat row accumulator. JSON: the sibling output object. */
|
|
331
|
+
siblingData: Record<string, unknown>;
|
|
332
|
+
/** Read-only source at the current level, before any transformation. */
|
|
333
|
+
siblingDoc: Record<string, unknown>;
|
|
334
|
+
value: unknown;
|
|
335
|
+
}) => unknown;
|
|
336
|
+
/**
|
|
337
|
+
* Field-level hook that runs before a field value is imported. Works for both
|
|
338
|
+
* CSV and JSON. Return the transformed value to use for this field.
|
|
339
|
+
*/
|
|
340
|
+
export type FieldBeforeImportHook = (args: {
|
|
341
|
+
columnName: string;
|
|
342
|
+
/** Full flat row (CSV) or top-level parsed document (JSON). */
|
|
343
|
+
data: Record<string, unknown>;
|
|
344
|
+
format: 'csv' | 'json' | ({} & string);
|
|
345
|
+
/** Data at the current level. CSV: same reference as `data`. JSON: the parent-level object. */
|
|
346
|
+
siblingData: Record<string, unknown>;
|
|
347
|
+
/** Read-only source at the current level, before any transformation. CSV: same as `data`. */
|
|
348
|
+
siblingDoc: Record<string, unknown>;
|
|
349
|
+
value: unknown;
|
|
350
|
+
}) => unknown;
|
|
351
|
+
/**
|
|
352
|
+
* @deprecated use `hooks.beforeExport`. Will be removed in a future major version.
|
|
353
|
+
* Original arg shape preserved for backwards compatibility.
|
|
169
354
|
*/
|
|
170
355
|
export type ToCSVFunction = (args: {
|
|
171
|
-
/**
|
|
172
|
-
* The path of the column for the field, for arrays this includes the index (zero-based)
|
|
173
|
-
*/
|
|
174
356
|
columnName: string;
|
|
175
|
-
/**
|
|
176
|
-
* Alias for `row`, the object that accumulates CSV output.
|
|
177
|
-
* Use this to write additional fields into the exported row.
|
|
178
|
-
*/
|
|
357
|
+
/** Alias for `row`. */
|
|
179
358
|
data: Record<string, unknown>;
|
|
180
|
-
/**
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
doc: Document;
|
|
184
|
-
/**
|
|
185
|
-
* The object data that can be manipulated to assign data to the CSV
|
|
186
|
-
*/
|
|
359
|
+
/** The top-level document being exported. */
|
|
360
|
+
doc: Record<string, unknown>;
|
|
361
|
+
/** Flat row accumulator at the current level. Mutate to add columns. */
|
|
187
362
|
row: Record<string, unknown>;
|
|
188
|
-
/**
|
|
189
|
-
* The document data at the level where it belongs
|
|
190
|
-
*/
|
|
363
|
+
/** Source document at the current level. */
|
|
191
364
|
siblingDoc: Record<string, unknown>;
|
|
192
|
-
/**
|
|
193
|
-
* The data for the field.
|
|
194
|
-
*/
|
|
195
365
|
value: unknown;
|
|
196
366
|
}) => unknown;
|
|
197
367
|
/**
|
|
198
|
-
*
|
|
368
|
+
* @deprecated use `hooks.beforeImport`. Will be removed in a future major version.
|
|
369
|
+
* Original arg shape preserved for backwards compatibility.
|
|
199
370
|
*/
|
|
200
371
|
export type FromCSVFunction = (args: {
|
|
201
|
-
/**
|
|
202
|
-
* The path of the column for the field
|
|
203
|
-
*/
|
|
204
372
|
columnName: string;
|
|
205
|
-
/**
|
|
206
|
-
* The current row data being processed
|
|
207
|
-
*/
|
|
373
|
+
/** The full flat row being imported. */
|
|
208
374
|
data: Record<string, unknown>;
|
|
209
|
-
/**
|
|
210
|
-
* The value being imported for this field
|
|
211
|
-
*/
|
|
212
375
|
value: unknown;
|
|
213
376
|
}) => unknown;
|
|
377
|
+
/** @internal */
|
|
378
|
+
export type ExportFieldHookEntry = {
|
|
379
|
+
fn: FieldBeforeExportHook;
|
|
380
|
+
type: 'beforeExport';
|
|
381
|
+
} | {
|
|
382
|
+
fn: ToCSVFunction;
|
|
383
|
+
type: 'toCSV';
|
|
384
|
+
};
|
|
385
|
+
/** @internal */
|
|
386
|
+
export type ImportFieldHookEntry = {
|
|
387
|
+
fn: FieldBeforeImportHook;
|
|
388
|
+
type: 'beforeImport';
|
|
389
|
+
} | {
|
|
390
|
+
fn: FromCSVFunction;
|
|
391
|
+
type: 'fromCSV';
|
|
392
|
+
};
|
|
214
393
|
/**
|
|
215
394
|
* Base pagination data returned from preview endpoints
|
|
216
395
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,cAAc,EACf,MAAM,SAAS,CAAA;AAEhB;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAEvF;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG,aAAa,GAAG,MAAM,CAAA;AAE1C;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,EAChC,UAAU,GACX,EAAE;IACD,UAAU,EAAE,gBAAgB,CAAA;CAC7B,KAAK,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;AAElD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,KAAK,CA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