@payloadcms/plugin-import-export 4.0.0-internal.d28e9fb → 4.0.0-internal.fa345ef
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/ExportPreview/index.css +55 -0
- package/dist/components/ExportPreview/index.d.ts +1 -1
- package/dist/components/ExportPreview/index.d.ts.map +1 -1
- package/dist/components/ExportPreview/index.js +1 -1
- package/dist/components/ExportPreview/index.js.map +1 -1
- package/dist/components/FieldsToExport/reduceFields.d.ts.map +1 -1
- package/dist/components/FormatField/index.d.ts.map +1 -1
- package/dist/components/FormatField/index.js +6 -3
- package/dist/components/FormatField/index.js.map +1 -1
- package/dist/components/ImportPreview/index.css +48 -0
- package/dist/components/ImportPreview/index.d.ts +1 -1
- package/dist/components/ImportPreview/index.d.ts.map +1 -1
- package/dist/components/ImportPreview/index.js +17 -3
- package/dist/components/ImportPreview/index.js.map +1 -1
- package/dist/components/Page/index.d.ts +1 -1
- package/dist/components/Page/index.d.ts.map +1 -1
- package/dist/components/Page/index.js +1 -1
- package/dist/components/Page/index.js.map +1 -1
- package/dist/components/SortBy/index.css +9 -0
- package/dist/components/SortBy/index.d.ts +1 -1
- package/dist/components/SortBy/index.d.ts.map +1 -1
- package/dist/components/SortBy/index.js +1 -2
- package/dist/components/SortBy/index.js.map +1 -1
- package/dist/components/SortOrder/index.css +9 -0
- package/dist/components/SortOrder/index.d.ts +1 -1
- package/dist/components/SortOrder/index.d.ts.map +1 -1
- package/dist/components/SortOrder/index.js +1 -2
- package/dist/components/SortOrder/index.js.map +1 -1
- package/dist/export/batchProcessor.d.ts +2 -2
- package/dist/export/batchProcessor.d.ts.map +1 -1
- package/dist/export/batchProcessor.js.map +1 -1
- package/dist/export/createExport.d.ts +2 -2
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +1 -1
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
- package/dist/export/getExportCollection.d.ts.map +1 -1
- package/dist/export/getExportCollection.js +4 -4
- package/dist/export/getExportCollection.js.map +1 -1
- package/dist/export/getFields.d.ts.map +1 -1
- package/dist/export/handleDownload.d.ts.map +1 -1
- package/dist/export/handleDownload.js +2 -2
- package/dist/export/handleDownload.js.map +1 -1
- package/dist/export/handlePreview.d.ts.map +1 -1
- package/dist/export/handlePreview.js +1 -1
- 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 +2 -2
- package/dist/import/batchProcessor.d.ts.map +1 -1
- package/dist/import/batchProcessor.js.map +1 -1
- package/dist/import/createImport.d.ts.map +1 -1
- package/dist/import/createImport.js +1 -1
- package/dist/import/createImport.js.map +1 -1
- package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
- package/dist/import/getFields.d.ts.map +1 -1
- package/dist/import/getImportCollection.d.ts.map +1 -1
- package/dist/import/getImportCollection.js +4 -4
- package/dist/import/getImportCollection.js.map +1 -1
- package/dist/import/handlePreview.d.ts.map +1 -1
- package/dist/index.d.ts +2 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -8
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +0 -32
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/applyFieldHooks.d.ts +1 -2
- package/dist/utilities/applyFieldHooks.d.ts.map +1 -1
- package/dist/utilities/applyFieldHooks.js +2 -3
- package/dist/utilities/applyFieldHooks.js.map +1 -1
- package/dist/utilities/buildDisabledFieldRegex.d.ts.map +1 -1
- package/dist/utilities/collectDisabledFieldPaths.d.ts.map +1 -1
- package/dist/utilities/fieldToRegex.d.ts.map +1 -1
- package/dist/utilities/flattenObject.d.ts.map +1 -1
- package/dist/utilities/flattenObject.js +3 -13
- package/dist/utilities/flattenObject.js.map +1 -1
- package/dist/utilities/flattenedFields.d.ts.map +1 -1
- package/dist/utilities/flattenedFields.js +3 -0
- package/dist/utilities/flattenedFields.js.map +1 -1
- package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getExportFieldFunctions.js +0 -8
- package/dist/utilities/getExportFieldFunctions.js.map +1 -1
- package/dist/utilities/getFileFromDoc.d.ts.map +1 -1
- package/dist/utilities/getFlattenedFieldKeys.d.ts.map +1 -1
- package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getImportFieldFunctions.js +0 -8
- package/dist/utilities/getImportFieldFunctions.js.map +1 -1
- package/dist/utilities/getPluginCollections.d.ts.map +1 -1
- package/dist/utilities/getSchemaColumns.d.ts +1 -1
- package/dist/utilities/getSchemaColumns.d.ts.map +1 -1
- package/dist/utilities/getSchemaColumns.js +2 -2
- package/dist/utilities/getSchemaColumns.js.map +1 -1
- package/dist/utilities/getSelect.d.ts.map +1 -1
- package/dist/utilities/isPlainObject.d.ts.map +1 -1
- package/dist/utilities/parseCSV.d.ts.map +1 -1
- package/dist/utilities/parseJSON.d.ts.map +1 -1
- package/dist/utilities/polymorphicRel.d.ts.map +1 -1
- package/dist/utilities/processRichTextField.d.ts.map +1 -1
- package/dist/utilities/processRichTextField.js +7 -0
- package/dist/utilities/processRichTextField.js.map +1 -1
- package/dist/utilities/processRichTextField.spec.js +308 -0
- package/dist/utilities/processRichTextField.spec.js.map +1 -0
- package/dist/utilities/removeDisabledFields.d.ts.map +1 -1
- package/dist/utilities/setNestedValue.d.ts.map +1 -1
- package/dist/utilities/sortHelpers.d.ts.map +1 -1
- package/dist/utilities/unflattenObject.d.ts.map +1 -1
- package/dist/utilities/unflattenObject.js +29 -18
- package/dist/utilities/unflattenObject.js.map +1 -1
- package/dist/utilities/unflattenObject.spec.js +106 -0
- package/dist/utilities/unflattenObject.spec.js.map +1 -1
- package/dist/utilities/unflattenPostProcess.d.ts.map +1 -1
- package/dist/utilities/unflattenPostProcess.js +39 -13
- package/dist/utilities/unflattenPostProcess.js.map +1 -1
- package/dist/utilities/validateLimitValue.d.ts.map +1 -1
- package/license.md +1 -1
- package/package.json +7 -7
- package/dist/components/ExportPreview/index.scss +0 -48
- package/dist/components/FieldsToExport/index.scss +0 -0
- package/dist/components/ImportPreview/index.scss +0 -41
- package/dist/components/SortBy/index.scss +0 -3
- package/dist/components/SortOrder/index.scss +0 -3
- package/dist/utilities/legacyHookDispatch.spec.js +0 -227
- package/dist/utilities/legacyHookDispatch.spec.js.map +0 -1
- /package/dist/components/Page/{index.scss → index.css} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlePreview.d.ts","sourceRoot":"","sources":["../../src/import/handlePreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAoB7C,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"handlePreview.d.ts","sourceRoot":"","sources":["../../src/import/handlePreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAoB7C,eAAO,MAAM,aAAa,GAAU,KAAK,cAAc,KAAG,OAAO,CAAC,QAAQ,CAuIzE,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ExportAfterHook, ExportBeforeHook, FieldBeforeExportHook, FieldBeforeImportHook, FromCSVFunction, ImportAfterHook, ImportBeforeHook, ImportExportPluginConfig, Limit, ToCSVFunction } from './types.js';
|
|
1
|
+
import type { ExportAfterHook, ExportBeforeHook, FieldBeforeExportHook, FieldBeforeImportHook, ImportAfterHook, ImportBeforeHook, ImportExportPluginConfig, Limit } from './types.js';
|
|
3
2
|
/**
|
|
4
3
|
* Adds CSV/JSON import and export functionality to selected collections.
|
|
5
4
|
*
|
|
@@ -10,7 +9,7 @@ import type { ExportAfterHook, ExportBeforeHook, FieldBeforeExportHook, FieldBef
|
|
|
10
9
|
*
|
|
11
10
|
* @see https://payloadcms.com/docs/plugins/import-export
|
|
12
11
|
*/
|
|
13
|
-
export declare const importExportPlugin: (
|
|
12
|
+
export declare const importExportPlugin: (options: ImportExportPluginConfig) => import("payload").Plugin;
|
|
14
13
|
declare module 'payload' {
|
|
15
14
|
interface FieldCustom {
|
|
16
15
|
'plugin-import-export'?: {
|
|
@@ -22,11 +21,6 @@ declare module 'payload' {
|
|
|
22
21
|
* @default false
|
|
23
22
|
*/
|
|
24
23
|
disabled?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated use `hooks.beforeImport` instead.
|
|
27
|
-
* Still functional, but will be removed in a future major version.
|
|
28
|
-
*/
|
|
29
|
-
fromCSV?: FromCSVFunction;
|
|
30
24
|
/**
|
|
31
25
|
* Field-level lifecycle hooks for import/export transformations.
|
|
32
26
|
* Works for both CSV and JSON formats.
|
|
@@ -43,11 +37,6 @@ declare module 'payload' {
|
|
|
43
37
|
*/
|
|
44
38
|
beforeImport?: FieldBeforeImportHook;
|
|
45
39
|
};
|
|
46
|
-
/**
|
|
47
|
-
* @deprecated use `hooks.beforeExport` instead.
|
|
48
|
-
* Still functional, but will be removed in a future major version.
|
|
49
|
-
*/
|
|
50
|
-
toCSV?: ToCSVFunction;
|
|
51
40
|
};
|
|
52
41
|
}
|
|
53
42
|
interface CollectionAdminCustom {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,EAEN,MAAM,YAAY,CAAA;AAQnB;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,iEAyM7B,CA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BAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;aAAE,CAAA;YACpE;;;;eAIG;YACH,WAAW,CAAC,EAAE,KAAK,CAAA;SACpB,CAAA;KACF;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deepMergeSimple } from 'payload';
|
|
1
|
+
import { deepMergeSimple, definePlugin } from 'payload';
|
|
2
2
|
import { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js';
|
|
3
3
|
import { getCreateCollectionImportTask } from './import/getCreateImportCollectionTask.js';
|
|
4
4
|
import { translations } from './translations/index.js';
|
|
@@ -13,7 +13,9 @@ import { getPluginCollections } from './utilities/getPluginCollections.js';
|
|
|
13
13
|
* format, lifecycle hooks, override) live on each entry of `collections`.
|
|
14
14
|
*
|
|
15
15
|
* @see https://payloadcms.com/docs/plugins/import-export
|
|
16
|
-
*/ export const importExportPlugin = (
|
|
16
|
+
*/ export const importExportPlugin = definePlugin({
|
|
17
|
+
slug: '@payloadcms/plugin-import-export',
|
|
18
|
+
plugin: async ({ config, options: pluginConfig })=>{
|
|
17
19
|
// Get all export/import collections and the mappings from target collections to custom collections
|
|
18
20
|
const { customExportSlugMap, customImportSlugMap, exportCollections, importCollections } = await getPluginCollections({
|
|
19
21
|
config,
|
|
@@ -171,16 +173,25 @@ import { getPluginCollections } from './utilities/getPluginCollections.js';
|
|
|
171
173
|
config.i18n = {};
|
|
172
174
|
}
|
|
173
175
|
/**
|
|
174
|
-
* Merge plugin translations
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
* Merge plugin translations — only for languages the user has enabled.
|
|
177
|
+
* Plugins run before sanitize, so `supportedLanguages` may be undefined; sanitize will
|
|
178
|
+
* default it to `{ en }`, so we mirror that here to avoid merging 30+ unused tables.
|
|
179
|
+
*/ const supportedLanguageKeys = config.i18n?.supportedLanguages ? Object.keys(config.i18n.supportedLanguages) : [
|
|
180
|
+
'en'
|
|
181
|
+
];
|
|
182
|
+
const simplifiedTranslations = {};
|
|
183
|
+
for (const lang of supportedLanguageKeys){
|
|
184
|
+
const entry = translations[lang];
|
|
185
|
+
if (entry) {
|
|
186
|
+
simplifiedTranslations[lang] = entry.translations;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
179
189
|
config.i18n = {
|
|
180
190
|
...config.i18n,
|
|
181
191
|
translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {})
|
|
182
192
|
};
|
|
183
193
|
return config;
|
|
184
|
-
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
185
196
|
|
|
186
197
|
//# sourceMappingURL=index.js.map
|
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 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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gBACvF;YACF;YAEA3C,WAAWwD,MAAM,GAAG;gBAClB,GAAIxD,WAAWwD,MAAM,IAAI,CAAC,CAAC;gBAC3B,wBAAwB;oBACtB,GAAIxD,WAAWwD,MAAM,EAAE,CAAC,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"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { deepMergeSimple, definePlugin } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type {\n ExportAfterHook,\n ExportBeforeHook,\n FieldBeforeExportHook,\n FieldBeforeImportHook,\n ImportAfterHook,\n ImportBeforeHook,\n ImportExportPluginConfig,\n Limit,\n PluginCollectionConfig,\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 = definePlugin<ImportExportPluginConfig>({\n slug: '@payloadcms/plugin-import-export',\n plugin: async ({ config, options: pluginConfig }) => {\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 — only for languages the user has enabled.\n * Plugins run before sanitize, so `supportedLanguages` may be undefined; sanitize will\n * default it to `{ en }`, so we mirror that here to avoid merging 30+ unused tables.\n */\n const supportedLanguageKeys = config.i18n?.supportedLanguages\n ? Object.keys(config.i18n.supportedLanguages)\n : ['en']\n\n const simplifiedTranslations: Record<string, PluginDefaultTranslationsObject> = {}\n for (const lang of supportedLanguageKeys) {\n const entry = translations[lang as keyof typeof translations]\n if (entry) {\n simplifiedTranslations[lang] = entry.translations\n }\n }\n\n config.i18n = {\n ...config.i18n,\n translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {}),\n }\n\n return config\n },\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 * 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 }\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","definePlugin","getCreateCollectionExportTask","getCreateCollectionImportTask","translations","collectDisabledFieldPaths","getPluginCollections","importExportPlugin","slug","plugin","config","options","pluginConfig","customExportSlugMap","customImportSlugMap","exportCollections","importCollections","baseExportCollection","baseImportCollection","allExportSlugs","Set","map","c","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","supportedLanguageKeys","supportedLanguages","Object","keys","simplifiedTranslations","lang","entry"],"mappings":"AAAA,SAASA,eAAe,EAAEC,YAAY,QAAQ,UAAS;AAevD,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,qBAAqBN,aAAuC;IACvEO,MAAM;IACNC,QAAQ,OAAO,EAAEC,MAAM,EAAEC,SAASC,YAAY,EAAE;QAC9C,mGAAmG;QACnG,MAAM,EAAEC,mBAAmB,EAAEC,mBAAmB,EAAEC,iBAAiB,EAAEC,iBAAiB,EAAE,GACtF,MAAMV,qBAAqB;YACzBI;YACAE;QACF;QAEF,mDAAmD;QACnD,MAAMK,uBAAuBF,iBAAiB,CAAC,EAAE;QACjD,MAAMG,uBAAuBF,iBAAiB,CAAC,EAAE;QAEjD,+DAA+D;QAC/D,MAAMG,iBAAiB,IAAIC,IAAIL,kBAAkBM,GAAG,CAAC,CAACC,IAAMA,EAAEd,IAAI;QAClE,MAAMe,iBAAiB,IAAIH,IAAIJ,kBAAkBK,GAAG,CAAC,CAACC,IAAMA,EAAEd,IAAI;QAElE,yCAAyC;QACzC,IAAI,CAACE,OAAOc,WA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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,CAACpB,OAAOyE,IAAI,EAAE;YAChBzE,OAAOyE,IAAI,GAAG,CAAC;QACjB;QAEA;;;;KAIC,GACD,MAAMC,wBAAwB1E,OAAOyE,IAAI,EAAEE,qBACvCC,OAAOC,IAAI,CAAC7E,OAAOyE,IAAI,CAACE,kBAAkB,IAC1C;YAAC;SAAK;QAEV,MAAMG,yBAA0E,CAAC;QACjF,KAAK,MAAMC,QAAQL,sBAAuB;YACxC,MAAMM,QAAQtF,YAAY,CAACqF,KAAkC;YAC7D,IAAIC,OAAO;gBACTF,sBAAsB,CAACC,KAAK,GAAGC,MAAMtF,YAAY;YACnD;QACF;QAEAM,OAAOyE,IAAI,GAAG;YACZ,GAAGzE,OAAOyE,IAAI;YACd/E,cAAcJ,gBAAgBwF,wBAAwB9E,OAAOyE,IAAI,EAAE/E,gBAAgB,CAAC;QACtF;QAEA,OAAOM;IACT;AACF,GAAE"}
|
package/dist/types.d.ts
CHANGED
|
@@ -348,47 +348,15 @@ export type FieldBeforeImportHook = (args: {
|
|
|
348
348
|
siblingDoc: Record<string, unknown>;
|
|
349
349
|
value: unknown;
|
|
350
350
|
}) => unknown;
|
|
351
|
-
/**
|
|
352
|
-
* @deprecated use `hooks.beforeExport`. Will be removed in a future major version.
|
|
353
|
-
* Original arg shape preserved for backwards compatibility.
|
|
354
|
-
*/
|
|
355
|
-
export type ToCSVFunction = (args: {
|
|
356
|
-
columnName: string;
|
|
357
|
-
/** Alias for `row`. */
|
|
358
|
-
data: Record<string, unknown>;
|
|
359
|
-
/** The top-level document being exported. */
|
|
360
|
-
doc: Record<string, unknown>;
|
|
361
|
-
/** Flat row accumulator at the current level. Mutate to add columns. */
|
|
362
|
-
row: Record<string, unknown>;
|
|
363
|
-
/** Source document at the current level. */
|
|
364
|
-
siblingDoc: Record<string, unknown>;
|
|
365
|
-
value: unknown;
|
|
366
|
-
}) => unknown;
|
|
367
|
-
/**
|
|
368
|
-
* @deprecated use `hooks.beforeImport`. Will be removed in a future major version.
|
|
369
|
-
* Original arg shape preserved for backwards compatibility.
|
|
370
|
-
*/
|
|
371
|
-
export type FromCSVFunction = (args: {
|
|
372
|
-
columnName: string;
|
|
373
|
-
/** The full flat row being imported. */
|
|
374
|
-
data: Record<string, unknown>;
|
|
375
|
-
value: unknown;
|
|
376
|
-
}) => unknown;
|
|
377
351
|
/** @internal */
|
|
378
352
|
export type ExportFieldHookEntry = {
|
|
379
353
|
fn: FieldBeforeExportHook;
|
|
380
354
|
type: 'beforeExport';
|
|
381
|
-
} | {
|
|
382
|
-
fn: ToCSVFunction;
|
|
383
|
-
type: 'toCSV';
|
|
384
355
|
};
|
|
385
356
|
/** @internal */
|
|
386
357
|
export type ImportFieldHookEntry = {
|
|
387
358
|
fn: FieldBeforeImportHook;
|
|
388
359
|
type: 'beforeImport';
|
|
389
|
-
} | {
|
|
390
|
-
fn: FromCSVFunction;
|
|
391
|
-
type: 'fromCSV';
|
|
392
360
|
};
|
|
393
361
|
/**
|
|
394
362
|
* Base pagination data returned from preview endpoints
|
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,EACV,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,cAAc,EACf,MAAM,SAAS,CAAA;AAEhB;;GAEG;AACH,M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AM,CAAA;IACjB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;CACxB,GAAG,qBAAqB,CAAA;AAEzB;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,GAAG,qBAAqB,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionConfig,\n CollectionSlug,\n DataFromCollectionSlug,\n PayloadRequest,\n} from 'payload'\n\n/**\n * Function to dynamically determine the limit based on request context\n */\nexport type LimitFunction = (args: { req: PayloadRequest }) => number | Promise<number>\n\n/**\n * Limit configuration - either a hard number or a function.\n * Set to 0 for unlimited (no restriction). Default is 0.\n */\nexport type Limit = LimitFunction | number\n\n/**\n * Type for overriding import/export collection configurations\n */\nexport type CollectionOverride = ({\n collection,\n}: {\n collection: CollectionConfig\n}) => CollectionConfig | Promise<CollectionConfig>\n\n/**\n * Result of a completed import operation (or a single batch within one)\n */\nexport type ImportResult = {\n errors: Array<{\n doc: Record<string, unknown>\n error: string\n index: number\n }>\n imported: number\n total: number\n updated: number\n}\n\n/**\n * Hook called before each export batch is written to file.\n * Receives the transformed batch data and the original DB documents.\n * Return the modified data array — it replaces `data` for the write step.\n */\nexport type ExportBeforeHook<TSlug extends CollectionSlug = CollectionSlug> = (args: {\n /** Current batch number, starting at 1 */\n batchNumber: number\n /** Transformed batch — flat rows for CSV, nested docs for JSON. Modify and return this. */\n data: Record<string, unknown>[]\n /** Export format. Open-ended to support custom formats in the future. */\n format: 'csv' | 'json' | ({} & string)\n /**\n * Raw DB documents before format-specific transformation. Read-only reference.\n *\n * Typed as a union so call sites that don't know the collection slug at\n * compile time (e.g. job tasks) don't need `as any` casts. To get the\n * narrower typed shape, declare your hook with a slug:\n * `const hook: ExportBeforeHook<'posts'> = (args) => { ... }`.\n */\n originalData: DataFromCollectionSlug<TSlug>[] | Record<string, unknown>[]\n req: PayloadRequest\n /** Total number of batches for this export operation */\n totalBatches: number\n}) => Promise<Record<string, unknown>[]> | Record<string, unknown>[]\n\n/**\n * Hook called after each export batch has been written to file.\n * For logging and observability only — return value is ignored.\n */\nexport type ExportAfterHook = (args: {\n /** Current batch number, starting at 1 */\n batchNumber: number\n /** The batch data that was written */\n data: Record<string, unknown>[]\n /** Export format */\n format: 'csv' | 'json' | ({} & string)\n /** Raw DB documents before transformation */\n originalData: Record<string, unknown>[]\n req: PayloadRequest\n /** Total number of batches for this export operation */\n totalBatches: number\n}) => Promise<void> | void\n\n/**\n * Hook called before each import batch is written to the database.\n * Receives the processed (unflattened) documents and the raw file rows.\n * Return the modified documents array — it replaces `data` for the DB write step.\n */\nexport type ImportBeforeHook<TSlug extends CollectionSlug = CollectionSlug> = (args: {\n /** Current batch number, starting at 1 */\n batchNumber: number\n /**\n * Unflattened documents ready to be written to the database. Modify and\n * return this. Typed as `Partial<...>` because rows from a CSV or JSON\n * import are not guaranteed to include every required field of the\n * collection — required fields are validated at write time.\n */\n data: Partial<DataFromCollectionSlug<TSlug>>[]\n /** Import format. Open-ended to support custom formats in the future. */\n format: 'csv' | 'json' | ({} & string)\n /** Raw parsed file rows before unflattening. Read-only reference. */\n originalData: Record<string, unknown>[]\n req: PayloadRequest\n /** Total number of batches for this import operation */\n totalBatches: number\n}) => Partial<DataFromCollectionSlug<TSlug>>[] | Promise<Partial<DataFromCollectionSlug<TSlug>>[]>\n\n/**\n * Hook called after each import batch has been written to the database.\n * For logging and observability only — return value is ignored.\n */\nexport type ImportAfterHook = (args: {\n /** Current batch number, starting at 1 */\n batchNumber: number\n /** Import format */\n format: 'csv' | 'json' | ({} & string)\n /**\n * Raw parsed file rows for this batch before unflattening and before-hook\n * transformation. For CSV this is the flat key/value row; for JSON this is\n * the top-level parsed document. Read-only reference.\n */\n originalData: Record<string, unknown>[]\n req: PayloadRequest\n /** Result of this batch — counts and errors. Not the cumulative total. */\n result: ImportResult\n /** Total number of batches for this import operation */\n totalBatches: number\n}) => Promise<void> | void\n\n/**\n * Per-collection export configuration. Set on each entry of\n * ```\n * importExportPlugin({ collections: [{ slug, export: { ... } }] })\n * ```\n */\nexport type ExportConfig<TSlug extends CollectionSlug = CollectionSlug> = {\n /**\n * Number of documents to process in each batch during export. This config is applied to both jobs and synchronous exports.\n *\n * @default 100\n */\n batchSize?: number\n /**\n * If true, disables the download button in the export preview UI\n * @default false\n */\n disableDownload?: boolean\n /**\n * If true, disables the jobs queue for exports and runs them synchronously.\n * @default false\n */\n disableJobsQueue?: boolean\n /**\n * If true, disables the save button in the export preview UI\n * @default false\n */\n disableSave?: boolean\n /**\n * Forces a specific export format (`csv` or `json`) and hides the format dropdown from the UI.\n * When defined, this overrides the user's ability to choose a format manually.\n * If not set, the user can choose between CSV and JSON in the export UI.\n * @default undefined\n */\n format?: 'csv' | 'json'\n /**\n * Lifecycle hooks for export operations on this collection.\n * Hooks fire once per batch.\n */\n hooks?: {\n /**\n * Called after each batch is written to file. For logging/observability only.\n * Return value is ignored.\n */\n after?: ExportAfterHook\n /**\n * Called before each batch is written to file.\n * Return value replaces the batch data for the write step.\n */\n before?: ExportBeforeHook<TSlug>\n }\n /**\n * Maximum number of documents that can be exported in a single operation.\n * Can be a number or a function that returns a number based on request context.\n * Set to 0 for unlimited (default). Overrides the global exportLimit if set.\n */\n limit?: Limit\n /**\n * Override the export collection for this collection.\n *\n * @default true\n */\n overrideCollection?: CollectionOverride\n}\n\n/**\n * Per-collection import configuration. Set on each entry of\n * ```\n * importExportPlugin({ collections: [{ slug, import: { ... } }] })\n * ```\n */\nexport type ImportConfig<TSlug extends CollectionSlug = CollectionSlug> = {\n /**\n * Number of documents to process in each batch during import. This config is applied to both jobs and synchronous imports.\n *\n * @default 100\n */\n batchSize?: number\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 * If true, disables the jobs queue for imports and runs them synchronously.\n * @default false\n */\n disableJobsQueue?: boolean\n /**\n * Lifecycle hooks for import operations on this collection.\n * Hooks fire once per batch.\n */\n hooks?: {\n /**\n * Called after each batch is written to the database. For logging/observability only.\n * Return value is ignored.\n */\n after?: ImportAfterHook\n /**\n * Called before each batch is written to the database.\n * Return value replaces the batch data for the DB write step.\n */\n before?: ImportBeforeHook<TSlug>\n }\n /**\n * Maximum number of documents that can be imported in a single operation.\n * Can be a number or a function that returns a number based on request context.\n * Set to 0 for unlimited (default). Overrides the global importLimit if set.\n */\n limit?: Limit\n /**\n * Override the import collection for this collection.\n *\n * @default true\n */\n overrideCollection?: CollectionOverride\n}\n\n/**\n * Per-collection plugin entry. Identifies a target collection by `slug` and\n * configures its export/import behavior; either side can be disabled with `false`.\n */\nexport type PluginCollectionConfig<TSlug extends CollectionSlug = CollectionSlug> = {\n /**\n * Override the import collection for this collection or disable it entirely with `false`.\n *\n * @default true\n */\n export?: boolean | ExportConfig<TSlug>\n /**\n * Override the export collection for this collection or disable it entirely with `false`.\n *\n * @default true\n */\n import?: boolean | ImportConfig<TSlug>\n /**\n * Target collection's slug for import/export functionality\n */\n slug: TSlug\n}\n\n/**\n * Configuration options for the Import/Export plugin\n */\nexport type ImportExportPluginConfig = {\n /**\n * Global default batch size for both import and export operations.\n * Can be overridden at the collection level via `export.batchSize` or `import.batchSize`.\n * @default 100\n */\n batchSize?: number\n\n /**\n * Collections to include the Import/Export controls in.\n * If not specified, all collections will have import/export enabled.\n * @default undefined (all collections)\n */\n collections: PluginCollectionConfig<CollectionSlug>[]\n\n /**\n * Enable debug logging for troubleshooting import/export operations\n * @default false\n */\n debug?: boolean\n\n /**\n * Global default version status for imported documents when _status field is not provided.\n * Only applies to collections with versions enabled.\n * Can be overridden at the collection level via `import.defaultVersionStatus`.\n * @default 'published'\n */\n defaultVersionStatus?: 'draft' | 'published'\n\n /**\n * Global maximum for export operations.\n * Can be a number or a function that returns a number based on request context.\n * Set to 0 for unlimited (default). Per-collection limits take precedence.\n */\n exportLimit?: Limit\n\n /**\n * Global maximum for import operations.\n * Can be a number or a function that returns a number based on request context.\n * Set to 0 for unlimited (default). Per-collection limits take precedence.\n */\n importLimit?: Limit\n\n /**\n * Function to override the default export collection configuration.\n * Takes the default export collection and allows you to modify and return it.\n * Useful for adding access control, changing upload directory, etc.\n *\n * This can also be set at the collection level via `export` config.\n */\n overrideExportCollection?: CollectionOverride\n\n /**\n * Function to override the default import collection configuration.\n * Takes the default import collection and allows you to modify and return it.\n * Useful for adding access control, changing upload directory, etc.\n *\n * This can also be set at the collection level via `import` config.\n */\n overrideImportCollection?: CollectionOverride\n}\n\n/**\n * Field-level hook that runs before a field value is exported. Works for both\n * CSV and JSON. Return a value to replace the field, or `undefined` to fall\n * back to default behavior. Mutate `siblingData` to add or remove columns at\n * the same level.\n *\n * Return `null` (CSV only) when the hook has already written its replacement\n * columns to `siblingData` and default flattening should be skipped — used by\n * built-in handlers for polymorphic relationships to avoid duplicate columns.\n */\nexport type FieldBeforeExportHook = (args: {\n /** Runtime column path, underscore-separated (includes array indices, e.g. `items_0_note`). */\n columnName: string\n /** The top-level document being exported. */\n data: Record<string, unknown>\n format: 'csv' | 'json' | ({} & string)\n /** Writable output at the current level. CSV: the flat row accumulator. JSON: the sibling output object. */\n siblingData: Record<string, unknown>\n /** Read-only source at the current level, before any transformation. */\n siblingDoc: Record<string, unknown>\n value: unknown\n}) => unknown\n\n/**\n * Field-level hook that runs before a field value is imported. Works for both\n * CSV and JSON. Return the transformed value to use for this field.\n */\nexport type FieldBeforeImportHook = (args: {\n columnName: string\n /** Full flat row (CSV) or top-level parsed document (JSON). */\n data: Record<string, unknown>\n format: 'csv' | 'json' | ({} & string)\n /** Data at the current level. CSV: same reference as `data`. JSON: the parent-level object. */\n siblingData: Record<string, unknown>\n /** Read-only source at the current level, before any transformation. CSV: same as `data`. */\n siblingDoc: Record<string, unknown>\n value: unknown\n}) => unknown\n\n/**\n * @deprecated use `hooks.beforeExport`. Will be removed in a future major version.\n * Original arg shape preserved for backwards compatibility.\n */\nexport type ToCSVFunction = (args: {\n columnName: string\n /** Alias for `row`. */\n data: Record<string, unknown>\n /** The top-level document being exported. */\n doc: Record<string, unknown>\n /** Flat row accumulator at the current level. Mutate to add columns. */\n row: Record<string, unknown>\n /** Source document at the current level. */\n siblingDoc: Record<string, unknown>\n value: unknown\n}) => unknown\n\n/**\n * @deprecated use `hooks.beforeImport`. Will be removed in a future major version.\n * Original arg shape preserved for backwards compatibility.\n */\nexport type FromCSVFunction = (args: {\n columnName: string\n /** The full flat row being imported. */\n data: Record<string, unknown>\n value: unknown\n}) => unknown\n\n/** @internal */\nexport type ExportFieldHookEntry =\n | { fn: FieldBeforeExportHook; type: 'beforeExport' }\n | { fn: ToCSVFunction; type: 'toCSV' }\n\n/** @internal */\nexport type ImportFieldHookEntry =\n | { fn: FieldBeforeImportHook; type: 'beforeImport' }\n | { fn: FromCSVFunction; type: 'fromCSV' }\n\n/**\n * Base pagination data returned from preview endpoints\n */\nexport type PreviewPaginationData = {\n /**\n * Whether there is a next page available\n */\n hasNextPage: boolean\n /**\n * Whether there is a previous page available\n */\n hasPrevPage: boolean\n /**\n * Number of documents per page\n */\n limit: number\n /**\n * The resolved max limit value (max documents allowed), if any\n */\n maxLimit?: number\n /**\n * Current page number (1-indexed)\n */\n page: number\n /**\n * Total number of documents\n */\n totalDocs: number\n /**\n * Total number of pages\n */\n totalPages: number\n}\n\n/**\n * Response from export preview endpoint\n */\nexport type ExportPreviewResponse = {\n /**\n * Column names for CSV format (undefined for JSON)\n */\n columns?: string[]\n /**\n * Preview documents (transformed for display)\n */\n docs: Record<string, unknown>[]\n /**\n * Actual count of docs that will be exported (respects export limit)\n */\n exportTotalDocs: number\n} & PreviewPaginationData\n\n/**\n * Response from import preview endpoint\n */\nexport type ImportPreviewResponse = {\n /**\n * Preview documents parsed from the import file\n */\n docs: Record<string, unknown>[]\n /**\n * Whether the file exceeds the max limit\n */\n limitExceeded?: boolean\n} & PreviewPaginationData\n"],"names":[],"mappings":"AAmdA;;CAEC,GACD,WASyB"}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionConfig,\n CollectionSlug,\n DataFromCollectionSlug,\n PayloadRequest,\n} from 'payload'\n\n/**\n * Function to dynamically determine the limit based on request context\n */\nexport type LimitFunction = (args: { req: PayloadRequest }) => number | Promise<number>\n\n/**\n * Limit configuration - either a hard number or a function.\n * Set to 0 for unlimited (no restriction). Default is 0.\n */\nexport type Limit = LimitFunction | number\n\n/**\n * Type for overriding import/export collection configurations\n */\nexport type CollectionOverride = ({\n collection,\n}: {\n collection: CollectionConfig\n}) => CollectionConfig | Promise<CollectionConfig>\n\n/**\n * Result of a completed import operation (or a single batch within one)\n */\nexport type ImportResult = {\n errors: Array<{\n doc: Record<string, unknown>\n error: string\n index: number\n }>\n imported: number\n total: number\n updated: number\n}\n\n/**\n * Hook called before each export batch is written to file.\n * Receives the transformed batch data and the original DB documents.\n * Return the modified data array — it replaces `data` for the write step.\n */\nexport type ExportBeforeHook<TSlug extends CollectionSlug = CollectionSlug> = (args: {\n /** Current batch number, starting at 1 */\n batchNumber: number\n /** Transformed batch — flat rows for CSV, nested docs for JSON. Modify and return this. */\n data: Record<string, unknown>[]\n /** Export format. Open-ended to support custom formats in the future. */\n format: 'csv' | 'json' | ({} & string)\n /**\n * Raw DB documents before format-specific transformation. Read-only reference.\n *\n * Typed as a union so call sites that don't know the collection slug at\n * compile time (e.g. job tasks) don't need `as any` casts. To get the\n * narrower typed shape, declare your hook with a slug:\n * `const hook: ExportBeforeHook<'posts'> = (args) => { ... }`.\n */\n originalData: DataFromCollectionSlug<TSlug>[] | Record<string, unknown>[]\n req: PayloadRequest\n /** Total number of batches for this export operation */\n totalBatches: number\n}) => Promise<Record<string, unknown>[]> | Record<string, unknown>[]\n\n/**\n * Hook called after each export batch has been written to file.\n * For logging and observability only — return value is ignored.\n */\nexport type ExportAfterHook = (args: {\n /** Current batch number, starting at 1 */\n batchNumber: number\n /** The batch data that was written */\n data: Record<string, unknown>[]\n /** Export format */\n format: 'csv' | 'json' | ({} & string)\n /** Raw DB documents before transformation */\n originalData: Record<string, unknown>[]\n req: PayloadRequest\n /** Total number of batches for this export operation */\n totalBatches: number\n}) => Promise<void> | void\n\n/**\n * Hook called before each import batch is written to the database.\n * Receives the processed (unflattened) documents and the raw file rows.\n * Return the modified documents array — it replaces `data` for the DB write step.\n */\nexport type ImportBeforeHook<TSlug extends CollectionSlug = CollectionSlug> = (args: {\n /** Current batch number, starting at 1 */\n batchNumber: number\n /**\n * Unflattened documents ready to be written to the database. Modify and\n * return this. Typed as `Partial<...>` because rows from a CSV or JSON\n * import are not guaranteed to include every required field of the\n * collection — required fields are validated at write time.\n */\n data: Partial<DataFromCollectionSlug<TSlug>>[]\n /** Import format. Open-ended to support custom formats in the future. */\n format: 'csv' | 'json' | ({} & string)\n /** Raw parsed file rows before unflattening. Read-only reference. */\n originalData: Record<string, unknown>[]\n req: PayloadRequest\n /** Total number of batches for this import operation */\n totalBatches: number\n}) => Partial<DataFromCollectionSlug<TSlug>>[] | Promise<Partial<DataFromCollectionSlug<TSlug>>[]>\n\n/**\n * Hook called after each import batch has been written to the database.\n * For logging and observability only — return value is ignored.\n */\nexport type ImportAfterHook = (args: {\n /** Current batch number, starting at 1 */\n batchNumber: number\n /** Import format */\n format: 'csv' | 'json' | ({} & string)\n /**\n * Raw parsed file rows for this batch before unflattening and before-hook\n * transformation. For CSV this is the flat key/value row; for JSON this is\n * the top-level parsed document. Read-only reference.\n */\n originalData: Record<string, unknown>[]\n req: PayloadRequest\n /** Result of this batch — counts and errors. Not the cumulative total. */\n result: ImportResult\n /** Total number of batches for this import operation */\n totalBatches: number\n}) => Promise<void> | void\n\n/**\n * Per-collection export configuration. Set on each entry of\n * ```\n * importExportPlugin({ collections: [{ slug, export: { ... } }] })\n * ```\n */\nexport type ExportConfig<TSlug extends CollectionSlug = CollectionSlug> = {\n /**\n * Number of documents to process in each batch during export. This config is applied to both jobs and synchronous exports.\n *\n * @default 100\n */\n batchSize?: number\n /**\n * If true, disables the download button in the export preview UI\n * @default false\n */\n disableDownload?: boolean\n /**\n * If true, disables the jobs queue for exports and runs them synchronously.\n * @default false\n */\n disableJobsQueue?: boolean\n /**\n * If true, disables the save button in the export preview UI\n * @default false\n */\n disableSave?: boolean\n /**\n * Forces a specific export format (`csv` or `json`) and hides the format dropdown from the UI.\n * When defined, this overrides the user's ability to choose a format manually.\n * If not set, the user can choose between CSV and JSON in the export UI.\n * @default undefined\n */\n format?: 'csv' | 'json'\n /**\n * Lifecycle hooks for export operations on this collection.\n * Hooks fire once per batch.\n */\n hooks?: {\n /**\n * Called after each batch is written to file. For logging/observability only.\n * Return value is ignored.\n */\n after?: ExportAfterHook\n /**\n * Called before each batch is written to file.\n * Return value replaces the batch data for the write step.\n */\n before?: ExportBeforeHook<TSlug>\n }\n /**\n * Maximum number of documents that can be exported in a single operation.\n * Can be a number or a function that returns a number based on request context.\n * Set to 0 for unlimited (default). Overrides the global exportLimit if set.\n */\n limit?: Limit\n /**\n * Override the export collection for this collection.\n *\n * @default true\n */\n overrideCollection?: CollectionOverride\n}\n\n/**\n * Per-collection import configuration. Set on each entry of\n * ```\n * importExportPlugin({ collections: [{ slug, import: { ... } }] })\n * ```\n */\nexport type ImportConfig<TSlug extends CollectionSlug = CollectionSlug> = {\n /**\n * Number of documents to process in each batch during import. This config is applied to both jobs and synchronous imports.\n *\n * @default 100\n */\n batchSize?: number\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 * If true, disables the jobs queue for imports and runs them synchronously.\n * @default false\n */\n disableJobsQueue?: boolean\n /**\n * Lifecycle hooks for import operations on this collection.\n * Hooks fire once per batch.\n */\n hooks?: {\n /**\n * Called after each batch is written to the database. For logging/observability only.\n * Return value is ignored.\n */\n after?: ImportAfterHook\n /**\n * Called before each batch is written to the database.\n * Return value replaces the batch data for the DB write step.\n */\n before?: ImportBeforeHook<TSlug>\n }\n /**\n * Maximum number of documents that can be imported in a single operation.\n * Can be a number or a function that returns a number based on request context.\n * Set to 0 for unlimited (default). Overrides the global importLimit if set.\n */\n limit?: Limit\n /**\n * Override the import collection for this collection.\n *\n * @default true\n */\n overrideCollection?: CollectionOverride\n}\n\n/**\n * Per-collection plugin entry. Identifies a target collection by `slug` and\n * configures its export/import behavior; either side can be disabled with `false`.\n */\nexport type PluginCollectionConfig<TSlug extends CollectionSlug = CollectionSlug> = {\n /**\n * Override the import collection for this collection or disable it entirely with `false`.\n *\n * @default true\n */\n export?: boolean | ExportConfig<TSlug>\n /**\n * Override the export collection for this collection or disable it entirely with `false`.\n *\n * @default true\n */\n import?: boolean | ImportConfig<TSlug>\n /**\n * Target collection's slug for import/export functionality\n */\n slug: TSlug\n}\n\n/**\n * Configuration options for the Import/Export plugin\n */\nexport type ImportExportPluginConfig = {\n /**\n * Global default batch size for both import and export operations.\n * Can be overridden at the collection level via `export.batchSize` or `import.batchSize`.\n * @default 100\n */\n batchSize?: number\n\n /**\n * Collections to include the Import/Export controls in.\n * If not specified, all collections will have import/export enabled.\n * @default undefined (all collections)\n */\n collections: PluginCollectionConfig<CollectionSlug>[]\n\n /**\n * Enable debug logging for troubleshooting import/export operations\n * @default false\n */\n debug?: boolean\n\n /**\n * Global default version status for imported documents when _status field is not provided.\n * Only applies to collections with versions enabled.\n * Can be overridden at the collection level via `import.defaultVersionStatus`.\n * @default 'published'\n */\n defaultVersionStatus?: 'draft' | 'published'\n\n /**\n * Global maximum for export operations.\n * Can be a number or a function that returns a number based on request context.\n * Set to 0 for unlimited (default). Per-collection limits take precedence.\n */\n exportLimit?: Limit\n\n /**\n * Global maximum for import operations.\n * Can be a number or a function that returns a number based on request context.\n * Set to 0 for unlimited (default). Per-collection limits take precedence.\n */\n importLimit?: Limit\n\n /**\n * Function to override the default export collection configuration.\n * Takes the default export collection and allows you to modify and return it.\n * Useful for adding access control, changing upload directory, etc.\n *\n * This can also be set at the collection level via `export` config.\n */\n overrideExportCollection?: CollectionOverride\n\n /**\n * Function to override the default import collection configuration.\n * Takes the default import collection and allows you to modify and return it.\n * Useful for adding access control, changing upload directory, etc.\n *\n * This can also be set at the collection level via `import` config.\n */\n overrideImportCollection?: CollectionOverride\n}\n\n/**\n * Field-level hook that runs before a field value is exported. Works for both\n * CSV and JSON. Return a value to replace the field, or `undefined` to fall\n * back to default behavior. Mutate `siblingData` to add or remove columns at\n * the same level.\n *\n * Return `null` (CSV only) when the hook has already written its replacement\n * columns to `siblingData` and default flattening should be skipped — used by\n * built-in handlers for polymorphic relationships to avoid duplicate columns.\n */\nexport type FieldBeforeExportHook = (args: {\n /** Runtime column path, underscore-separated (includes array indices, e.g. `items_0_note`). */\n columnName: string\n /** The top-level document being exported. */\n data: Record<string, unknown>\n format: 'csv' | 'json' | ({} & string)\n /** Writable output at the current level. CSV: the flat row accumulator. JSON: the sibling output object. */\n siblingData: Record<string, unknown>\n /** Read-only source at the current level, before any transformation. */\n siblingDoc: Record<string, unknown>\n value: unknown\n}) => unknown\n\n/**\n * Field-level hook that runs before a field value is imported. Works for both\n * CSV and JSON. Return the transformed value to use for this field.\n */\nexport type FieldBeforeImportHook = (args: {\n columnName: string\n /** Full flat row (CSV) or top-level parsed document (JSON). */\n data: Record<string, unknown>\n format: 'csv' | 'json' | ({} & string)\n /** Data at the current level. CSV: same reference as `data`. JSON: the parent-level object. */\n siblingData: Record<string, unknown>\n /** Read-only source at the current level, before any transformation. CSV: same as `data`. */\n siblingDoc: Record<string, unknown>\n value: unknown\n}) => unknown\n\n/** @internal */\nexport type ExportFieldHookEntry = { fn: FieldBeforeExportHook; type: 'beforeExport' }\n\n/** @internal */\nexport type ImportFieldHookEntry = { fn: FieldBeforeImportHook; type: 'beforeImport' }\n\n/**\n * Base pagination data returned from preview endpoints\n */\nexport type PreviewPaginationData = {\n /**\n * Whether there is a next page available\n */\n hasNextPage: boolean\n /**\n * Whether there is a previous page available\n */\n hasPrevPage: boolean\n /**\n * Number of documents per page\n */\n limit: number\n /**\n * The resolved max limit value (max documents allowed), if any\n */\n maxLimit?: number\n /**\n * Current page number (1-indexed)\n */\n page: number\n /**\n * Total number of documents\n */\n totalDocs: number\n /**\n * Total number of pages\n */\n totalPages: number\n}\n\n/**\n * Response from export preview endpoint\n */\nexport type ExportPreviewResponse = {\n /**\n * Column names for CSV format (undefined for JSON)\n */\n columns?: string[]\n /**\n * Preview documents (transformed for display)\n */\n docs: Record<string, unknown>[]\n /**\n * Actual count of docs that will be exported (respects export limit)\n */\n exportTotalDocs: number\n} & PreviewPaginationData\n\n/**\n * Response from import preview endpoint\n */\nexport type ImportPreviewResponse = {\n /**\n * Preview documents parsed from the import file\n */\n docs: Record<string, unknown>[]\n /**\n * Whether the file exceeds the max limit\n */\n limitExceeded?: boolean\n} & PreviewPaginationData\n"],"names":[],"mappings":"AAmbA;;CAEC,GACD,WASyB"}
|
|
@@ -13,8 +13,7 @@ export type Args = {
|
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Walks a nested document and applies each field's `beforeExport` or
|
|
16
|
-
* `beforeImport` hook.
|
|
17
|
-
* flat CSV pipelines and skipped here.
|
|
16
|
+
* `beforeImport` hook.
|
|
18
17
|
*
|
|
19
18
|
* Field-level hook errors are logged and the field falls back to its
|
|
20
19
|
* original value so a single bad doc does not abort the batch.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyFieldHooks.d.ts","sourceRoot":"","sources":["../../src/utilities/applyFieldHooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"applyFieldHooks.d.ts","sourceRoot":"","sources":["../../src/utilities/applyFieldHooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7E,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,aAAa,CAAA;AAIpB,MAAM,MAAM,SAAS,GAAG,qBAAqB,GAAG,qBAAqB,CAAA;AAErE,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAAG,oBAAoB,CAAA;AAKxE,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAC1C,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,CAAA;IACtC,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,EAAE,cAAc,GAAG,cAAc,CAAA;CACtC,CAAA;AA4HD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAYlE,CAAA"}
|
|
@@ -77,7 +77,7 @@ const traverseFields = ({ type, data, fieldHooks, fields, format, operation, pat
|
|
|
77
77
|
return item;
|
|
78
78
|
}
|
|
79
79
|
const blockType = typeof item.blockType === 'string' ? item.blockType : undefined;
|
|
80
|
-
const block = blockType ? field.blocks.find((b)=>b.slug === blockType) : undefined;
|
|
80
|
+
const block = blockType ? req.payload.blocks[blockType] ?? field.blocks.find((b)=>typeof b !== 'string' && b.slug === blockType) : undefined;
|
|
81
81
|
return traverseFields({
|
|
82
82
|
type,
|
|
83
83
|
data,
|
|
@@ -97,8 +97,7 @@ const traverseFields = ({ type, data, fieldHooks, fields, format, operation, pat
|
|
|
97
97
|
};
|
|
98
98
|
/**
|
|
99
99
|
* Walks a nested document and applies each field's `beforeExport` or
|
|
100
|
-
* `beforeImport` hook.
|
|
101
|
-
* flat CSV pipelines and skipped here.
|
|
100
|
+
* `beforeImport` hook.
|
|
102
101
|
*
|
|
103
102
|
* Field-level hook errors are logged and the field falls back to its
|
|
104
103
|
* original value so a single bad doc does not abort the batch.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/applyFieldHooks.ts"],"sourcesContent":["import type { FlattenedField, PayloadRequest } from 'payload'\n\nimport type {\n ExportFieldHookEntry,\n FieldBeforeExportHook,\n FieldBeforeImportHook,\n ImportFieldHookEntry,\n} from '../types.js'\n\nimport { isPlainObject } from './isPlainObject.js'\n\nexport type FieldHook = FieldBeforeExportHook | FieldBeforeImportHook\n\nexport type FieldHookEntry = ExportFieldHookEntry | ImportFieldHookEntry\n\nconst joinPath = (parent: string | undefined, segment: string): string =>\n parent ? `${parent}_${segment}` : segment\n\nexport type Args = {\n data: Record<string, unknown>\n fieldHooks: Record<string, FieldHookEntry>\n fields: FlattenedField[]\n format: 'csv' | 'json' | ({} & string)\n operation: 'export' | 'import'\n req: PayloadRequest\n type: 'beforeExport' | 'beforeImport'\n}\n\nconst operationLabel = { export: 'Export', import: 'Import' } as const\n\ntype TraverseArgs = {\n path: string | undefined\n schemaPath: string | undefined\n siblingData: Record<string, unknown>\n} & Args\n\nconst traverseFields = ({\n type,\n data,\n fieldHooks,\n fields,\n format,\n operation,\n path,\n req,\n schemaPath,\n siblingData,\n}: TraverseArgs): Record<string, unknown> => {\n const result: Record<string, unknown> = { ...siblingData }\n\n for (const field of fields) {\n if (!('name' in field) || !field.name) {\n continue\n }\n\n const fieldPath = joinPath(path, field.name)\n const fieldSchemaPath = joinPath(schemaPath, field.name)\n const entry = fieldHooks[fieldSchemaPath]\n const hook = entry?.type === type ? (entry.fn as FieldHook) : undefined\n\n if (typeof hook === 'function' && field.name in result) {\n try {\n const transformed = hook({\n columnName: fieldPath,\n data,\n format,\n siblingData: result,\n siblingDoc: siblingData,\n value: result[field.name],\n })\n\n if (typeof transformed !== 'undefined') {\n result[field.name] = transformed\n }\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level before${operationLabel[operation]} hook for \"${fieldPath}\" threw — falling back to original value`,\n })\n }\n }\n\n if (!(field.name in result)) {\n continue\n }\n\n const value = result[field.name]\n\n if ((field.type === 'group' || field.type === 'tab') && isPlainObject(value)) {\n result[field.name] = traverseFields({\n type,\n data,\n fieldHooks,\n fields: field.flattenedFields,\n format,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: value,\n })\n } else if (field.type === 'array' && Array.isArray(value)) {\n result[field.name] = value.map((item, index) => {\n if (!isPlainObject(item)) {\n return item\n }\n return traverseFields({\n type,\n data,\n fieldHooks,\n fields: field.flattenedFields,\n format,\n operation,\n path: `${fieldPath}_${index}`,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: item,\n })\n })\n } else if (field.type === 'blocks' && Array.isArray(value)) {\n result[field.name] = value.map((item, index) => {\n if (!isPlainObject(item)) {\n return item\n }\n const blockType = typeof item.blockType === 'string' ? item.blockType : undefined\n const block = blockType
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/applyFieldHooks.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedField, PayloadRequest } from 'payload'\n\nimport type {\n ExportFieldHookEntry,\n FieldBeforeExportHook,\n FieldBeforeImportHook,\n ImportFieldHookEntry,\n} from '../types.js'\n\nimport { isPlainObject } from './isPlainObject.js'\n\nexport type FieldHook = FieldBeforeExportHook | FieldBeforeImportHook\n\nexport type FieldHookEntry = ExportFieldHookEntry | ImportFieldHookEntry\n\nconst joinPath = (parent: string | undefined, segment: string): string =>\n parent ? `${parent}_${segment}` : segment\n\nexport type Args = {\n data: Record<string, unknown>\n fieldHooks: Record<string, FieldHookEntry>\n fields: FlattenedField[]\n format: 'csv' | 'json' | ({} & string)\n operation: 'export' | 'import'\n req: PayloadRequest\n type: 'beforeExport' | 'beforeImport'\n}\n\nconst operationLabel = { export: 'Export', import: 'Import' } as const\n\ntype TraverseArgs = {\n path: string | undefined\n schemaPath: string | undefined\n siblingData: Record<string, unknown>\n} & Args\n\nconst traverseFields = ({\n type,\n data,\n fieldHooks,\n fields,\n format,\n operation,\n path,\n req,\n schemaPath,\n siblingData,\n}: TraverseArgs): Record<string, unknown> => {\n const result: Record<string, unknown> = { ...siblingData }\n\n for (const field of fields) {\n if (!('name' in field) || !field.name) {\n continue\n }\n\n const fieldPath = joinPath(path, field.name)\n const fieldSchemaPath = joinPath(schemaPath, field.name)\n const entry = fieldHooks[fieldSchemaPath]\n const hook = entry?.type === type ? (entry.fn as FieldHook) : undefined\n\n if (typeof hook === 'function' && field.name in result) {\n try {\n const transformed = hook({\n columnName: fieldPath,\n data,\n format,\n siblingData: result,\n siblingDoc: siblingData,\n value: result[field.name],\n })\n\n if (typeof transformed !== 'undefined') {\n result[field.name] = transformed\n }\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level before${operationLabel[operation]} hook for \"${fieldPath}\" threw — falling back to original value`,\n })\n }\n }\n\n if (!(field.name in result)) {\n continue\n }\n\n const value = result[field.name]\n\n if ((field.type === 'group' || field.type === 'tab') && isPlainObject(value)) {\n result[field.name] = traverseFields({\n type,\n data,\n fieldHooks,\n fields: field.flattenedFields,\n format,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: value,\n })\n } else if (field.type === 'array' && Array.isArray(value)) {\n result[field.name] = value.map((item, index) => {\n if (!isPlainObject(item)) {\n return item\n }\n return traverseFields({\n type,\n data,\n fieldHooks,\n fields: field.flattenedFields,\n format,\n operation,\n path: `${fieldPath}_${index}`,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: item,\n })\n })\n } else if (field.type === 'blocks' && Array.isArray(value)) {\n result[field.name] = value.map((item, index) => {\n if (!isPlainObject(item)) {\n return item\n }\n const blockType = typeof item.blockType === 'string' ? item.blockType : undefined\n const block = blockType\n ? (req.payload.blocks[blockType] ??\n field.blocks.find(\n (b): b is FlattenedBlock => typeof b !== 'string' && b.slug === blockType,\n ))\n : undefined\n return traverseFields({\n type,\n data,\n fieldHooks,\n fields: block?.flattenedFields ?? [],\n format,\n operation,\n path: blockType ? `${fieldPath}_${index}_${blockType}` : `${fieldPath}_${index}`,\n req,\n schemaPath: blockType ? `${fieldSchemaPath}_${blockType}` : fieldSchemaPath,\n siblingData: item,\n })\n })\n }\n }\n\n return result\n}\n\n/**\n * Walks a nested document and applies each field's `beforeExport` or\n * `beforeImport` hook.\n *\n * Field-level hook errors are logged and the field falls back to its\n * original value so a single bad doc does not abort the batch.\n */\nexport const applyFieldHooks = (args: Args): Record<string, unknown> => {\n const { data, fieldHooks } = args\n if (!data || typeof data !== 'object' || Object.keys(fieldHooks).length === 0) {\n return data\n }\n\n return traverseFields({\n ...args,\n path: undefined,\n schemaPath: undefined,\n siblingData: data,\n })\n}\n"],"names":["isPlainObject","joinPath","parent","segment","operationLabel","export","import","traverseFields","type","data","fieldHooks","fields","format","operation","path","req","schemaPath","siblingData","result","field","name","fieldPath","fieldSchemaPath","entry","hook","fn","undefined","transformed","columnName","siblingDoc","value","error","payload","logger","err","msg","flattenedFields","Array","isArray","map","item","index","blockType","block","blocks","find","b","slug","applyFieldHooks","args","Object","keys","length"],"mappings":"AASA,SAASA,aAAa,QAAQ,qBAAoB;AAMlD,MAAMC,WAAW,CAACC,QAA4BC,UAC5CD,SAAS,GAAGA,OAAO,CAAC,EAAEC,SAAS,GAAGA;AAYpC,MAAMC,iBAAiB;IAAEC,QAAQ;IAAUC,QAAQ;AAAS;AAQ5D,MAAMC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AAC,EAAEoB,OAAO;oBAChF1B;oBACAC,YAAY0B,YAAY,GAAGpB,gBAAgB,CAAC,EAAEoB,WAAW,GAAGpB;oBAC5DL,aAAauB;gBACf;YACF;QACF;IACF;IAEA,OAAOtB;AACT;AAEA;;;;;;CAMC,GACD,OAAO,MAAM8B,kBAAkB,CAACC;IAC9B,MAAM,EAAExC,IAAI,EAAEC,UAAU,EAAE,GAAGuC;IAC7B,IAAI,CAACxC,QAAQ,OAAOA,SAAS,YAAYyC,OAAOC,IAAI,CAACzC,YAAY0C,MAAM,KAAK,GAAG;QAC7E,OAAO3C;IACT;IAEA,OAAOF,eAAe;QACpB,GAAG0C,IAAI;QACPnC,MAAMY;QACNV,YAAYU;QACZT,aAAaR;IACf;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildDisabledFieldRegex.d.ts","sourceRoot":"","sources":["../../src/utilities/buildDisabledFieldRegex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"buildDisabledFieldRegex.d.ts","sourceRoot":"","sources":["../../src/utilities/buildDisabledFieldRegex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,GAAI,WAAW,MAAM,KAAG,MAyB3D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collectDisabledFieldPaths.d.ts","sourceRoot":"","sources":["../../src/utilities/collectDisabledFieldPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAKpC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"collectDisabledFieldPaths.d.ts","sourceRoot":"","sources":["../../src/utilities/collectDisabledFieldPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAKpC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,yBAAyB,GAAI,QAAQ,KAAK,EAAE,KAAG,MAAM,EAmEjE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldToRegex.d.ts","sourceRoot":"","sources":["../../src/utilities/fieldToRegex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"fieldToRegex.d.ts","sourceRoot":"","sources":["../../src/utilities/fieldToRegex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,GAAI,WAAW,MAAM,KAAG,MAoBhD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAMvD,KAAK,IAAI,GAAG;IACV,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAA;IACtD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,CAAA;IACtC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAMvD,KAAK,IAAI,GAAG;IACV,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAA;IACtD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,CAAA;IACtC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,wDAO3B,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CA2K/B,CAAA"}
|
|
@@ -4,21 +4,11 @@ import { getPolymorphicRelId, isPolymorphicRelValue } from './polymorphicRel.js'
|
|
|
4
4
|
export const flattenObject = ({ data, exportFieldHooks, fields, format, path, req })=>{
|
|
5
5
|
const row = {};
|
|
6
6
|
const invokeHook = (entry, columnName, value, siblingSource)=>{
|
|
7
|
-
if (entry.type === 'beforeExport') {
|
|
8
|
-
return entry.fn({
|
|
9
|
-
columnName,
|
|
10
|
-
data,
|
|
11
|
-
format,
|
|
12
|
-
siblingData: row,
|
|
13
|
-
siblingDoc: siblingSource,
|
|
14
|
-
value
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
7
|
return entry.fn({
|
|
18
8
|
columnName,
|
|
19
|
-
data
|
|
20
|
-
|
|
21
|
-
row,
|
|
9
|
+
data,
|
|
10
|
+
format,
|
|
11
|
+
siblingData: row,
|
|
22
12
|
siblingDoc: siblingSource,
|
|
23
13
|
value
|
|
24
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/flattenObject.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport type { ExportFieldHookEntry } from '../types.js'\n\nimport { fieldToRegex } from './fieldToRegex.js'\nimport { isPlainObject } from './isPlainObject.js'\nimport { getPolymorphicRelId, isPolymorphicRelValue } from './polymorphicRel.js'\n\ntype Args = {\n data: Record<string, unknown>\n exportFieldHooks: Record<string, ExportFieldHookEntry>\n fields?: string[]\n format: 'csv' | 'json' | ({} & string)\n path?: string\n req: PayloadRequest\n}\n\nexport const flattenObject = ({\n data,\n exportFieldHooks,\n fields,\n format,\n path,\n req,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const invokeHook = (\n entry: ExportFieldHookEntry,\n columnName: string,\n value: unknown,\n siblingSource: Record<string, unknown>,\n ): unknown => {\n if (entry.type === 'beforeExport') {\n return entry.fn({\n columnName,\n data,\n format,\n siblingData: row,\n siblingDoc: siblingSource,\n value,\n })\n }\n return entry.fn({\n columnName,\n data: row,\n doc: data,\n row,\n siblingDoc: siblingSource,\n value,\n })\n }\n\n const selectedTopLevelKeys =\n Array.isArray(fields) && fields.length > 0\n ? new Set(fields.map((f) => f.split('.')[0]))\n : undefined\n\n const flattenWithFilter = (\n siblingSource: Record<string, unknown>,\n currentPath: string | undefined,\n currentSchemaPath: string | undefined,\n ) => {\n Object.entries(siblingSource).forEach(([key, value]) => {\n if (!currentPath && selectedTopLevelKeys && !selectedTopLevelKeys.has(key)) {\n return\n }\n\n const fieldPath = currentPath ? `${currentPath}_${key}` : key\n const fieldSchemaPath = currentSchemaPath ? `${currentSchemaPath}_${key}` : key\n const hookEntry = exportFieldHooks?.[fieldSchemaPath]\n\n const flattenArray = (items: unknown[], arrayPath: string, arraySchemaPath: string): void => {\n items.forEach((item, index) => {\n if (!isPlainObject(item)) {\n row[`${arrayPath}_${index}`] = item\n return\n }\n\n const blockType = typeof item.blockType === 'string' ? item.blockType : undefined\n const itemPath = blockType\n ? `${arrayPath}_${index}_${blockType}`\n : `${arrayPath}_${index}`\n const itemSchemaPath = blockType ? `${arraySchemaPath}_${blockType}` : arraySchemaPath\n\n if (isPolymorphicRelValue(item) && isPlainObject(item.value)) {\n const id = getPolymorphicRelId(item)\n if (id !== undefined) {\n row[`${itemPath}_relationTo`] = item.relationTo\n row[`${itemPath}_id`] = id\n return\n }\n }\n\n flattenWithFilter(item, itemPath, itemSchemaPath)\n })\n }\n\n if (Array.isArray(value)) {\n if (hookEntry) {\n try {\n const result = invokeHook(hookEntry, fieldPath, value, siblingSource)\n\n if (result === null) {\n return\n }\n\n if (Array.isArray(result)) {\n flattenArray(result, fieldPath, fieldSchemaPath)\n return\n }\n\n if (typeof result !== 'undefined') {\n row[fieldPath] = result\n return\n }\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level beforeExport hook for \"${fieldPath}\" threw — falling back to default flattening`,\n })\n }\n }\n\n flattenArray(value, fieldPath, fieldSchemaPath)\n } else if (typeof value === 'object' && value !== null) {\n if (!hookEntry) {\n flattenWithFilter(value as Record<string, unknown>, fieldPath, fieldSchemaPath)\n } else {\n const keysBeforeHook = new Set(Object.keys(row))\n try {\n const result = invokeHook(hookEntry, fieldPath, value, siblingSource)\n if (result === null) {\n return\n }\n if (typeof result === 'undefined') {\n const hookWroteForField = Object.keys(row).some(\n (k) => !keysBeforeHook.has(k) && (k === fieldPath || k.startsWith(`${fieldPath}_`)),\n )\n if (hookWroteForField) {\n return\n }\n flattenWithFilter(value as Record<string, unknown>, fieldPath, fieldSchemaPath)\n } else if (typeof result === 'object' && !Array.isArray(result)) {\n flattenWithFilter(result as Record<string, unknown>, fieldPath, fieldSchemaPath)\n } else {\n row[fieldPath] = result\n }\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level beforeExport hook for \"${fieldPath}\" threw — falling back to default flattening`,\n })\n flattenWithFilter(value as Record<string, unknown>, fieldPath, fieldSchemaPath)\n }\n }\n } else {\n if (hookEntry) {\n try {\n const result = invokeHook(hookEntry, fieldPath, value, siblingSource)\n if (typeof result !== 'undefined') {\n row[fieldPath] = result\n }\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level beforeExport hook for \"${fieldPath}\" threw — falling back to original value`,\n })\n row[fieldPath] = value\n }\n } else {\n row[fieldPath] = value\n }\n }\n })\n }\n\n flattenWithFilter(data, path, path)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldPatterns = fields.map((field) => ({\n field,\n regex: fieldToRegex(field),\n }))\n\n const rowKeys = Object.keys(row)\n\n for (const { regex } of fieldPatterns) {\n for (const key of rowKeys) {\n if (key in orderedResult) {\n continue\n }\n\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n }\n }\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["fieldToRegex","isPlainObject","getPolymorphicRelId","isPolymorphicRelValue","flattenObject","data","exportFieldHooks","fields","format","path","req","row","invokeHook","entry","columnName","value","siblingSource","type","fn","siblingData","siblingDoc","doc","selectedTopLevelKeys","Array","isArray","length","Set","map","f","split","undefined","flattenWithFilter","currentPath","currentSchemaPath","Object","entries","forEach","key","has","fieldPath","fieldSchemaPath","hookEntry","flattenArray","items","arrayPath","arraySchemaPath","item","index","blockType","itemPath","itemSchemaPath","id","relationTo","result","error","payload","logger","err","msg","keysBeforeHook","keys","hookWroteForField","some","k","startsWith","orderedResult","fieldPatterns","field","regex","rowKeys","test"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,mBAAmB,EAAEC,qBAAqB,QAAQ,sBAAqB;AAWhF,OAAO,MAAMC,gBAAgB,CAAC,EAC5BC,IAAI,EACJC,gBAAgB,EAChBC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,GAAG,EACE;IACL,MAAMC,MAA+B,CAAC;IAEtC,MAAMC,aAAa,CACjBC,OACAC,YACAC,OACAC;QAEA,IAAIH,MAAMI,IAAI,KAAK,gBAAgB;YACjC,OAAOJ,MAAMK,EAAE,CAAC;gBACdJ;gBACAT;gBACAG;gBACAW,aAAaR;gBACbS,YAAYJ;gBACZD;YACF;QACF;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;QAE5B,KAAK,MAAM,EAAEyD,KAAK,EAAE,IAAIF,cAAe;YACrC,KAAK,MAAM7B,OAAOgC,QAAS;gBACzB,IAAIhC,OAAO4B,eAAe;oBACxB;gBACF;gBAEA,IAAIG,MAAME,IAAI,CAACjC,MAAM;oBACnB4B,aAAa,CAAC5B,IAAI,GAAG1B,GAAG,CAAC0B,IAAI;gBAC/B;YACF;QACF;QAEA,OAAO4B;IACT;IAEA,OAAOtD;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/flattenObject.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport type { ExportFieldHookEntry } from '../types.js'\n\nimport { fieldToRegex } from './fieldToRegex.js'\nimport { isPlainObject } from './isPlainObject.js'\nimport { getPolymorphicRelId, isPolymorphicRelValue } from './polymorphicRel.js'\n\ntype Args = {\n data: Record<string, unknown>\n exportFieldHooks: Record<string, ExportFieldHookEntry>\n fields?: string[]\n format: 'csv' | 'json' | ({} & string)\n path?: string\n req: PayloadRequest\n}\n\nexport const flattenObject = ({\n data,\n exportFieldHooks,\n fields,\n format,\n path,\n req,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const invokeHook = (\n entry: ExportFieldHookEntry,\n columnName: string,\n value: unknown,\n siblingSource: Record<string, unknown>,\n ): unknown => {\n return entry.fn({\n columnName,\n data,\n format,\n siblingData: row,\n siblingDoc: siblingSource,\n value,\n })\n }\n\n const selectedTopLevelKeys =\n Array.isArray(fields) && fields.length > 0\n ? new Set(fields.map((f) => f.split('.')[0]))\n : undefined\n\n const flattenWithFilter = (\n siblingSource: Record<string, unknown>,\n currentPath: string | undefined,\n currentSchemaPath: string | undefined,\n ) => {\n Object.entries(siblingSource).forEach(([key, value]) => {\n if (!currentPath && selectedTopLevelKeys && !selectedTopLevelKeys.has(key)) {\n return\n }\n\n const fieldPath = currentPath ? `${currentPath}_${key}` : key\n const fieldSchemaPath = currentSchemaPath ? `${currentSchemaPath}_${key}` : key\n const hookEntry = exportFieldHooks?.[fieldSchemaPath]\n\n const flattenArray = (items: unknown[], arrayPath: string, arraySchemaPath: string): void => {\n items.forEach((item, index) => {\n if (!isPlainObject(item)) {\n row[`${arrayPath}_${index}`] = item\n return\n }\n\n const blockType = typeof item.blockType === 'string' ? item.blockType : undefined\n const itemPath = blockType\n ? `${arrayPath}_${index}_${blockType}`\n : `${arrayPath}_${index}`\n const itemSchemaPath = blockType ? `${arraySchemaPath}_${blockType}` : arraySchemaPath\n\n if (isPolymorphicRelValue(item) && isPlainObject(item.value)) {\n const id = getPolymorphicRelId(item)\n if (id !== undefined) {\n row[`${itemPath}_relationTo`] = item.relationTo\n row[`${itemPath}_id`] = id\n return\n }\n }\n\n flattenWithFilter(item, itemPath, itemSchemaPath)\n })\n }\n\n if (Array.isArray(value)) {\n if (hookEntry) {\n try {\n const result = invokeHook(hookEntry, fieldPath, value, siblingSource)\n\n if (result === null) {\n return\n }\n\n if (Array.isArray(result)) {\n flattenArray(result, fieldPath, fieldSchemaPath)\n return\n }\n\n if (typeof result !== 'undefined') {\n row[fieldPath] = result\n return\n }\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level beforeExport hook for \"${fieldPath}\" threw — falling back to default flattening`,\n })\n }\n }\n\n flattenArray(value, fieldPath, fieldSchemaPath)\n } else if (typeof value === 'object' && value !== null) {\n if (!hookEntry) {\n flattenWithFilter(value as Record<string, unknown>, fieldPath, fieldSchemaPath)\n } else {\n const keysBeforeHook = new Set(Object.keys(row))\n try {\n const result = invokeHook(hookEntry, fieldPath, value, siblingSource)\n if (result === null) {\n return\n }\n if (typeof result === 'undefined') {\n const hookWroteForField = Object.keys(row).some(\n (k) => !keysBeforeHook.has(k) && (k === fieldPath || k.startsWith(`${fieldPath}_`)),\n )\n if (hookWroteForField) {\n return\n }\n flattenWithFilter(value as Record<string, unknown>, fieldPath, fieldSchemaPath)\n } else if (typeof result === 'object' && !Array.isArray(result)) {\n flattenWithFilter(result as Record<string, unknown>, fieldPath, fieldSchemaPath)\n } else {\n row[fieldPath] = result\n }\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level beforeExport hook for \"${fieldPath}\" threw — falling back to default flattening`,\n })\n flattenWithFilter(value as Record<string, unknown>, fieldPath, fieldSchemaPath)\n }\n }\n } else {\n if (hookEntry) {\n try {\n const result = invokeHook(hookEntry, fieldPath, value, siblingSource)\n if (typeof result !== 'undefined') {\n row[fieldPath] = result\n }\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `[plugin-import-export] Field-level beforeExport hook for \"${fieldPath}\" threw — falling back to original value`,\n })\n row[fieldPath] = value\n }\n } else {\n row[fieldPath] = value\n }\n }\n })\n }\n\n flattenWithFilter(data, path, path)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldPatterns = fields.map((field) => ({\n field,\n regex: fieldToRegex(field),\n }))\n\n const rowKeys = Object.keys(row)\n\n for (const { regex } of fieldPatterns) {\n for (const key of rowKeys) {\n if (key in orderedResult) {\n continue\n }\n\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n }\n }\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["fieldToRegex","isPlainObject","getPolymorphicRelId","isPolymorphicRelValue","flattenObject","data","exportFieldHooks","fields","format","path","req","row","invokeHook","entry","columnName","value","siblingSource","fn","siblingData","siblingDoc","selectedTopLevelKeys","Array","isArray","length","Set","map","f","split","undefined","flattenWithFilter","currentPath","currentSchemaPath","Object","entries","forEach","key","has","fieldPath","fieldSchemaPath","hookEntry","flattenArray","items","arrayPath","arraySchemaPath","item","index","blockType","itemPath","itemSchemaPath","id","relationTo","result","error","payload","logger","err","msg","keysBeforeHook","keys","hookWroteForField","some","k","startsWith","orderedResult","fieldPatterns","field","regex","rowKeys","test"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,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OAAOgB,MAAM,GAAG,GAAG;QAC9C,MAAMwC,gBAAyC,CAAC;QAEhD,MAAMC,gBAAgBzD,OAAOkB,GAAG,CAAC,CAACwC,QAAW,CAAA;gBAC3CA;gBACAC,OAAOlE,aAAaiE;YACtB,CAAA;QAEA,MAAME,UAAUnC,OAAO0B,IAAI,CAAC/C;QAE5B,KAAK,MAAM,EAAEuD,KAAK,EAAE,IAAIF,cAAe;YACrC,KAAK,MAAM7B,OAAOgC,QAAS;gBACzB,IAAIhC,OAAO4B,eAAe;oBACxB;gBACF;gBAEA,IAAIG,MAAME,IAAI,CAACjC,MAAM;oBACnB4B,aAAa,CAAC5B,IAAI,GAAGxB,GAAG,CAACwB,IAAI;gBAC/B;YACF;QACF;QAEA,OAAO4B;IACT;IAEA,OAAOpD;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenedFields.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenedFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"flattenedFields.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenedFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,OAAO,cAAc,KAAG,cAAc,EAAE,GAAG,SACjB,CAAA;AAEnE;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO;IAC7C,eAAe,CAAC,EAAE,cAAc,EAAE,CAAA;CACnC,KAAG,cAAc,EAAiC,CAAA;AAEnD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,EACvC,QAAQ,cAAc,EAAE,EACxB,YAAY,MAAM,EAClB,QAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,iBAAiB,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,KAChG,IA6BF,CAAA"}
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
if (field.type === 'blocks') {
|
|
20
20
|
const base = parentPath ? `${parentPath}_${field.name}` : field.name;
|
|
21
21
|
for (const block of field.blocks ?? []){
|
|
22
|
+
if (typeof block === 'string') {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
22
25
|
registerFieldHooks(getBlockFlattenedFields(block), `${base}_${block.slug}`, result, registerHandler);
|
|
23
26
|
}
|
|
24
27
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/flattenedFields.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\n/**\n * Returns the `flattenedFields` of a group/tab/array field, or undefined for\n * field types that don't carry nested fields. Concentrates the cast for the\n * Payload core typing oversight (`FlattenedField` doesn't expose\n * `flattenedFields` on every variant).\n */\nexport const getNestedFlattenedFields = (field: FlattenedField): FlattenedField[] | undefined =>\n (field as { flattenedFields?: FlattenedField[] }).flattenedFields\n\n/**\n * Returns the `flattenedFields` of a `BlocksField` block (always an array).\n */\nexport const getBlockFlattenedFields = (block: {\n flattenedFields?: FlattenedField[]\n}): FlattenedField[] => block.flattenedFields ?? []\n\n/**\n * Traverses a flattened field schema and calls `registerHandler` for each\n * named field. Handles blocks (keyed by block slug), groups, tabs, and arrays.\n * Shared by `getExportFieldFunctions` and `getImportFieldFunctions`.\n */\nexport const registerFieldHooks = <TEntry>(\n fields: FlattenedField[],\n parentPath: string,\n result: Record<string, TEntry>,\n registerHandler: (field: FlattenedField, fullKey: string, result: Record<string, TEntry>) => void,\n): void => {\n for (const field of fields) {\n if (!('name' in field) || !field.name) {\n continue\n }\n\n if (field.type === 'blocks') {\n const base = parentPath ? `${parentPath}_${field.name}` : field.name\n for (const block of field.blocks ?? []) {\n registerFieldHooks(\n getBlockFlattenedFields(block),\n `${base}_${block.slug}`,\n result,\n registerHandler,\n )\n }\n continue\n }\n\n const fullKey = parentPath ? `${parentPath}_${field.name}` : field.name\n registerHandler(field, fullKey, result)\n\n if (field.type === 'group' || field.type === 'tab' || field.type === 'array') {\n registerFieldHooks(getNestedFlattenedFields(field) ?? [], fullKey, result, registerHandler)\n }\n }\n}\n"],"names":["getNestedFlattenedFields","field","flattenedFields","getBlockFlattenedFields","block","registerFieldHooks","fields","parentPath","result","registerHandler","name","type","base","blocks","slug","fullKey"],"mappings":"AAEA;;;;;CAKC,GACD,OAAO,MAAMA,2BAA2B,CAACC,QACvC,AAACA,MAAiDC,eAAe,CAAA;AAEnE;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC,QAEhBA,MAAMF,eAAe,IAAI,EAAE,CAAA;AAEnD;;;;CAIC,GACD,OAAO,MAAMG,qBAAqB,CAChCC,QACAC,YACAC,QACAC;IAEA,KAAK,MAAMR,SAASK,OAAQ;QAC1B,IAAI,CAAE,CAAA,UAAUL,KAAI,KAAM,CAACA,MAAMS,IAAI,EAAE;YACrC;QACF;QAEA,IAAIT,MAAMU,IAAI,KAAK,UAAU;YAC3B,MAAMC,OAAOL,aAAa,GAAGA,WAAW,CAAC,EAAEN,MAAMS,IAAI,EAAE,GAAGT,MAAMS,IAAI;YACpE,KAAK,MAAMN,SAASH,MAAMY,MAAM,IAAI,EAAE,CAAE;
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/flattenedFields.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\n/**\n * Returns the `flattenedFields` of a group/tab/array field, or undefined for\n * field types that don't carry nested fields. Concentrates the cast for the\n * Payload core typing oversight (`FlattenedField` doesn't expose\n * `flattenedFields` on every variant).\n */\nexport const getNestedFlattenedFields = (field: FlattenedField): FlattenedField[] | undefined =>\n (field as { flattenedFields?: FlattenedField[] }).flattenedFields\n\n/**\n * Returns the `flattenedFields` of a `BlocksField` block (always an array).\n */\nexport const getBlockFlattenedFields = (block: {\n flattenedFields?: FlattenedField[]\n}): FlattenedField[] => block.flattenedFields ?? []\n\n/**\n * Traverses a flattened field schema and calls `registerHandler` for each\n * named field. Handles blocks (keyed by block slug), groups, tabs, and arrays.\n * Shared by `getExportFieldFunctions` and `getImportFieldFunctions`.\n */\nexport const registerFieldHooks = <TEntry>(\n fields: FlattenedField[],\n parentPath: string,\n result: Record<string, TEntry>,\n registerHandler: (field: FlattenedField, fullKey: string, result: Record<string, TEntry>) => void,\n): void => {\n for (const field of fields) {\n if (!('name' in field) || !field.name) {\n continue\n }\n\n if (field.type === 'blocks') {\n const base = parentPath ? `${parentPath}_${field.name}` : field.name\n for (const block of field.blocks ?? []) {\n if (typeof block === 'string') {\n continue\n }\n registerFieldHooks(\n getBlockFlattenedFields(block),\n `${base}_${block.slug}`,\n result,\n registerHandler,\n )\n }\n continue\n }\n\n const fullKey = parentPath ? `${parentPath}_${field.name}` : field.name\n registerHandler(field, fullKey, result)\n\n if (field.type === 'group' || field.type === 'tab' || field.type === 'array') {\n registerFieldHooks(getNestedFlattenedFields(field) ?? [], fullKey, result, registerHandler)\n }\n }\n}\n"],"names":["getNestedFlattenedFields","field","flattenedFields","getBlockFlattenedFields","block","registerFieldHooks","fields","parentPath","result","registerHandler","name","type","base","blocks","slug","fullKey"],"mappings":"AAEA;;;;;CAKC,GACD,OAAO,MAAMA,2BAA2B,CAACC,QACvC,AAACA,MAAiDC,eAAe,CAAA;AAEnE;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC,QAEhBA,MAAMF,eAAe,IAAI,EAAE,CAAA;AAEnD;;;;CAIC,GACD,OAAO,MAAMG,qBAAqB,CAChCC,QACAC,YACAC,QACAC;IAEA,KAAK,MAAMR,SAASK,OAAQ;QAC1B,IAAI,CAAE,CAAA,UAAUL,KAAI,KAAM,CAACA,MAAMS,IAAI,EAAE;YACrC;QACF;QAEA,IAAIT,MAAMU,IAAI,KAAK,UAAU;YAC3B,MAAMC,OAAOL,aAAa,GAAGA,WAAW,CAAC,EAAEN,MAAMS,IAAI,EAAE,GAAGT,MAAMS,IAAI;YACpE,KAAK,MAAMN,SAASH,MAAMY,MAAM,IAAI,EAAE,CAAE;gBACtC,IAAI,OAAOT,UAAU,UAAU;oBAC7B;gBACF;gBACAC,mBACEF,wBAAwBC,QACxB,GAAGQ,KAAK,CAAC,EAAER,MAAMU,IAAI,EAAE,EACvBN,QACAC;YAEJ;YACA;QACF;QAEA,MAAMM,UAAUR,aAAa,GAAGA,WAAW,CAAC,EAAEN,MAAMS,IAAI,EAAE,GAAGT,MAAMS,IAAI;QACvED,gBAAgBR,OAAOc,SAASP;QAEhC,IAAIP,MAAMU,IAAI,KAAK,WAAWV,MAAMU,IAAI,KAAK,SAASV,MAAMU,IAAI,KAAK,SAAS;YAC5EN,mBAAmBL,yBAAyBC,UAAU,EAAE,EAAEc,SAASP,QAAQC;QAC7E;IACF;AACF,EAAC"}
|