@payloadcms/plugin-import-export 3.84.1 → 4.0.0-internal.d28e9fb
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/README.md +2 -2
- package/dist/export/batchProcessor.d.ts +9 -1
- package/dist/export/batchProcessor.d.ts.map +1 -1
- package/dist/export/batchProcessor.js +57 -15
- package/dist/export/batchProcessor.js.map +1 -1
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +98 -20
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/handlePreview.d.ts.map +1 -1
- package/dist/export/handlePreview.js +38 -13
- package/dist/export/handlePreview.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/import/batchProcessor.d.ts +14 -2
- package/dist/import/batchProcessor.d.ts.map +1 -1
- package/dist/import/batchProcessor.js +49 -27
- package/dist/import/batchProcessor.js.map +1 -1
- package/dist/import/createImport.d.ts +1 -10
- package/dist/import/createImport.d.ts.map +1 -1
- package/dist/import/createImport.js +33 -52
- package/dist/import/createImport.js.map +1 -1
- package/dist/import/handlePreview.d.ts.map +1 -1
- package/dist/import/handlePreview.js +32 -6
- package/dist/import/handlePreview.js.map +1 -1
- package/dist/index.d.ts +58 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +218 -39
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/applyFieldHooks.d.ts +23 -0
- package/dist/utilities/applyFieldHooks.d.ts.map +1 -0
- package/dist/utilities/applyFieldHooks.js +118 -0
- package/dist/utilities/applyFieldHooks.js.map +1 -0
- package/dist/utilities/applyFieldHooks.spec.js +205 -0
- package/dist/utilities/applyFieldHooks.spec.js.map +1 -0
- package/dist/utilities/collectDisabledFieldPaths.d.ts.map +1 -1
- package/dist/utilities/collectDisabledFieldPaths.js +1 -1
- package/dist/utilities/collectDisabledFieldPaths.js.map +1 -1
- package/dist/utilities/flattenObject.d.ts +8 -6
- package/dist/utilities/flattenObject.d.ts.map +1 -1
- package/dist/utilities/flattenObject.js +95 -75
- package/dist/utilities/flattenObject.js.map +1 -1
- package/dist/utilities/flattenObject.spec.js +158 -0
- package/dist/utilities/flattenObject.spec.js.map +1 -0
- package/dist/utilities/flattenedFields.d.ts +21 -0
- package/dist/utilities/flattenedFields.d.ts.map +1 -0
- package/dist/utilities/flattenedFields.js +34 -0
- package/dist/utilities/flattenedFields.js.map +1 -0
- package/dist/utilities/getExportFieldFunctions.d.ts +5 -5
- package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getExportFieldFunctions.js +92 -98
- package/dist/utilities/getExportFieldFunctions.js.map +1 -1
- package/dist/utilities/getExportFieldFunctions.spec.js +50 -0
- package/dist/utilities/getExportFieldFunctions.spec.js.map +1 -0
- package/dist/utilities/getImportFieldFunctions.d.ts +5 -5
- package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -1
- package/dist/utilities/getImportFieldFunctions.js +103 -103
- package/dist/utilities/getImportFieldFunctions.js.map +1 -1
- package/dist/utilities/getImportFieldFunctions.spec.js +167 -0
- package/dist/utilities/getImportFieldFunctions.spec.js.map +1 -0
- package/dist/utilities/isPlainObject.d.ts +2 -0
- package/dist/utilities/isPlainObject.d.ts.map +1 -0
- package/dist/utilities/isPlainObject.js +3 -0
- package/dist/utilities/isPlainObject.js.map +1 -0
- package/dist/utilities/legacyHookDispatch.spec.js +227 -0
- package/dist/utilities/legacyHookDispatch.spec.js.map +1 -0
- package/dist/utilities/polymorphicRel.d.ts +14 -0
- package/dist/utilities/polymorphicRel.d.ts.map +1 -0
- package/dist/utilities/polymorphicRel.js +17 -0
- package/dist/utilities/polymorphicRel.js.map +1 -0
- package/dist/utilities/processRichTextField.js.map +1 -1
- package/dist/utilities/removeDisabledFields.js.map +1 -1
- package/dist/utilities/setNestedValue.d.ts.map +1 -1
- package/dist/utilities/setNestedValue.js +10 -8
- package/dist/utilities/setNestedValue.js.map +1 -1
- package/dist/utilities/siblingDoc.spec.js +278 -0
- package/dist/utilities/siblingDoc.spec.js.map +1 -0
- package/dist/utilities/unflattenObject.d.ts +4 -3
- package/dist/utilities/unflattenObject.d.ts.map +1 -1
- package/dist/utilities/unflattenObject.js +57 -169
- package/dist/utilities/unflattenObject.js.map +1 -1
- package/dist/utilities/unflattenObject.spec.js +33 -0
- package/dist/utilities/unflattenObject.spec.js.map +1 -1
- package/dist/utilities/unflattenPostProcess.d.ts +11 -0
- package/dist/utilities/unflattenPostProcess.d.ts.map +1 -0
- package/dist/utilities/unflattenPostProcess.js +148 -0
- package/dist/utilities/unflattenPostProcess.js.map +1 -0
- package/package.json +7 -7
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionConfig, CollectionSlug, PayloadRequest } 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\nexport type ExportConfig = {\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 * 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\nexport type ImportConfig = {\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 * 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\nexport type PluginCollectionConfig = {\n /**\n * Override the import collection for this collection or disable it entirely with `false`.\n *\n * @default true\n */\n export?: boolean | ExportConfig\n /**\n * Override the export collection for this collection or disable it entirely with `false`.\n *\n * @default true\n */\n import?: boolean | ImportConfig\n /**\n * Target collection's slug for import/export functionality\n */\n slug: CollectionSlug\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[]\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 * Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value\n */\nexport type ToCSVFunction = (args: {\n /**\n * The path of the column for the field, for arrays this includes the index (zero-based)\n */\n columnName: string\n /**\n * Alias for `row`, the object that accumulates CSV output.\n * Use this to write additional fields into the exported row.\n */\n data: Record<string, unknown>\n /**\n * The top level document\n */\n doc: Document\n /**\n * The object data that can be manipulated to assign data to the CSV\n */\n row: Record<string, unknown>\n /**\n * The document data at the level where it belongs\n */\n siblingDoc: Record<string, unknown>\n /**\n * The data for the field.\n */\n value: unknown\n}) => unknown\n\n/**\n * Custom function used to transform incoming CSV data during import\n */\nexport type FromCSVFunction = (args: {\n /**\n * The path of the column for the field\n */\n columnName: string\n /**\n * The current row data being processed\n */\n data: Record<string, unknown>\n /**\n * The value being imported for this field\n */\n value: unknown\n}) => unknown\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":"AA0RA;;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/**\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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { FlattenedField, PayloadRequest } from 'payload';
|
|
2
|
+
import type { ExportFieldHookEntry, FieldBeforeExportHook, FieldBeforeImportHook, ImportFieldHookEntry } from '../types.js';
|
|
3
|
+
export type FieldHook = FieldBeforeExportHook | FieldBeforeImportHook;
|
|
4
|
+
export type FieldHookEntry = ExportFieldHookEntry | ImportFieldHookEntry;
|
|
5
|
+
export type Args = {
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
fieldHooks: Record<string, FieldHookEntry>;
|
|
8
|
+
fields: FlattenedField[];
|
|
9
|
+
format: 'csv' | 'json' | ({} & string);
|
|
10
|
+
operation: 'export' | 'import';
|
|
11
|
+
req: PayloadRequest;
|
|
12
|
+
type: 'beforeExport' | 'beforeImport';
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Walks a nested document and applies each field's `beforeExport` or
|
|
16
|
+
* `beforeImport` hook. Legacy `toCSV` / `fromCSV` hooks are handled by the
|
|
17
|
+
* flat CSV pipelines and skipped here.
|
|
18
|
+
*
|
|
19
|
+
* Field-level hook errors are logged and the field falls back to its
|
|
20
|
+
* original value so a single bad doc does not abort the batch.
|
|
21
|
+
*/
|
|
22
|
+
export declare const applyFieldHooks: (args: Args) => Record<string, unknown>;
|
|
23
|
+
//# sourceMappingURL=applyFieldHooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyFieldHooks.d.ts","sourceRoot":"","sources":["../../src/utilities/applyFieldHooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,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;AAuHD;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,SAAU,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAYlE,CAAA"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { isPlainObject } from './isPlainObject.js';
|
|
2
|
+
const joinPath = (parent, segment)=>parent ? `${parent}_${segment}` : segment;
|
|
3
|
+
const operationLabel = {
|
|
4
|
+
export: 'Export',
|
|
5
|
+
import: 'Import'
|
|
6
|
+
};
|
|
7
|
+
const traverseFields = ({ type, data, fieldHooks, fields, format, operation, path, req, schemaPath, siblingData })=>{
|
|
8
|
+
const result = {
|
|
9
|
+
...siblingData
|
|
10
|
+
};
|
|
11
|
+
for (const field of fields){
|
|
12
|
+
if (!('name' in field) || !field.name) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const fieldPath = joinPath(path, field.name);
|
|
16
|
+
const fieldSchemaPath = joinPath(schemaPath, field.name);
|
|
17
|
+
const entry = fieldHooks[fieldSchemaPath];
|
|
18
|
+
const hook = entry?.type === type ? entry.fn : undefined;
|
|
19
|
+
if (typeof hook === 'function' && field.name in result) {
|
|
20
|
+
try {
|
|
21
|
+
const transformed = hook({
|
|
22
|
+
columnName: fieldPath,
|
|
23
|
+
data,
|
|
24
|
+
format,
|
|
25
|
+
siblingData: result,
|
|
26
|
+
siblingDoc: siblingData,
|
|
27
|
+
value: result[field.name]
|
|
28
|
+
});
|
|
29
|
+
if (typeof transformed !== 'undefined') {
|
|
30
|
+
result[field.name] = transformed;
|
|
31
|
+
}
|
|
32
|
+
} catch (error) {
|
|
33
|
+
req.payload.logger.error({
|
|
34
|
+
err: error,
|
|
35
|
+
msg: `[plugin-import-export] Field-level before${operationLabel[operation]} hook for "${fieldPath}" threw — falling back to original value`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!(field.name in result)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const value = result[field.name];
|
|
43
|
+
if ((field.type === 'group' || field.type === 'tab') && isPlainObject(value)) {
|
|
44
|
+
result[field.name] = traverseFields({
|
|
45
|
+
type,
|
|
46
|
+
data,
|
|
47
|
+
fieldHooks,
|
|
48
|
+
fields: field.flattenedFields,
|
|
49
|
+
format,
|
|
50
|
+
operation,
|
|
51
|
+
path: fieldPath,
|
|
52
|
+
req,
|
|
53
|
+
schemaPath: fieldSchemaPath,
|
|
54
|
+
siblingData: value
|
|
55
|
+
});
|
|
56
|
+
} else if (field.type === 'array' && Array.isArray(value)) {
|
|
57
|
+
result[field.name] = value.map((item, index)=>{
|
|
58
|
+
if (!isPlainObject(item)) {
|
|
59
|
+
return item;
|
|
60
|
+
}
|
|
61
|
+
return traverseFields({
|
|
62
|
+
type,
|
|
63
|
+
data,
|
|
64
|
+
fieldHooks,
|
|
65
|
+
fields: field.flattenedFields,
|
|
66
|
+
format,
|
|
67
|
+
operation,
|
|
68
|
+
path: `${fieldPath}_${index}`,
|
|
69
|
+
req,
|
|
70
|
+
schemaPath: fieldSchemaPath,
|
|
71
|
+
siblingData: item
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
} else if (field.type === 'blocks' && Array.isArray(value)) {
|
|
75
|
+
result[field.name] = value.map((item, index)=>{
|
|
76
|
+
if (!isPlainObject(item)) {
|
|
77
|
+
return item;
|
|
78
|
+
}
|
|
79
|
+
const blockType = typeof item.blockType === 'string' ? item.blockType : undefined;
|
|
80
|
+
const block = blockType ? field.blocks.find((b)=>b.slug === blockType) : undefined;
|
|
81
|
+
return traverseFields({
|
|
82
|
+
type,
|
|
83
|
+
data,
|
|
84
|
+
fieldHooks,
|
|
85
|
+
fields: block?.flattenedFields ?? [],
|
|
86
|
+
format,
|
|
87
|
+
operation,
|
|
88
|
+
path: blockType ? `${fieldPath}_${index}_${blockType}` : `${fieldPath}_${index}`,
|
|
89
|
+
req,
|
|
90
|
+
schemaPath: blockType ? `${fieldSchemaPath}_${blockType}` : fieldSchemaPath,
|
|
91
|
+
siblingData: item
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Walks a nested document and applies each field's `beforeExport` or
|
|
100
|
+
* `beforeImport` hook. Legacy `toCSV` / `fromCSV` hooks are handled by the
|
|
101
|
+
* flat CSV pipelines and skipped here.
|
|
102
|
+
*
|
|
103
|
+
* Field-level hook errors are logged and the field falls back to its
|
|
104
|
+
* original value so a single bad doc does not abort the batch.
|
|
105
|
+
*/ export const applyFieldHooks = (args)=>{
|
|
106
|
+
const { data, fieldHooks } = args;
|
|
107
|
+
if (!data || typeof data !== 'object' || Object.keys(fieldHooks).length === 0) {
|
|
108
|
+
return data;
|
|
109
|
+
}
|
|
110
|
+
return traverseFields({
|
|
111
|
+
...args,
|
|
112
|
+
path: undefined,
|
|
113
|
+
schemaPath: undefined,
|
|
114
|
+
siblingData: data
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=applyFieldHooks.js.map
|
|
@@ -0,0 +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 ? field.blocks.find((b) => b.slug === blockType) : 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. Legacy `toCSV` / `fromCSV` hooks are handled by the\n * flat CSV pipelines and skipped here.\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,iBAAiB,CAAC,EACtBC,IAAI,EACJC,IAAI,EACJC,UAAU,EACVC,MAAM,EACNC,MAAM,EACNC,SAAS,EACTC,IAAI,EACJC,GAAG,EACHC,UAAU,EACVC,WAAW,EACE;IACb,MAAMC,SAAkC;QAAE,GAAGD,WAAW;IAAC;IAEzD,KAAK,MAAME,SAASR,OAAQ;QAC1B,IAAI,CAAE,CAAA,UAAUQ,KAAI,KAAM,CAACA,MAAMC,IAAI,EAAE;YACrC;QACF;QAEA,MAAMC,YAAYpB,SAASa,MAAMK,MAAMC,IAAI;QAC3C,MAAME,kBAAkBrB,SAASe,YAAYG,MAAMC,IAAI;QACvD,MAAMG,QAAQb,UAAU,CAACY,gBAAgB;QACzC,MAAME,OAAOD,OAAOf,SAASA,OAAQe,MAAME,EAAE,GAAiBC;QAE9D,IAAI,OAAOF,SAAS,cAAcL,MAAMC,IAAI,IAAIF,QAAQ;YACtD,IAAI;gBACF,MAAMS,cAAcH,KAAK;oBACvBI,YAAYP;oBACZZ;oBACAG;oBACAK,aAAaC;oBACbW,YAAYZ;oBACZa,OAAOZ,MAAM,CAACC,MAAMC,IAAI,CAAC;gBAC3B;gBAEA,IAAI,OAAOO,gBAAgB,a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,CAACzC,cAAcwC,OAAO;oBACxB,OAAOA;gBACT;gBACA,MAAME,YAAY,OAAOF,KAAKE,SAAS,KAAK,WAAWF,KAAKE,SAAS,GAAGhB;gBACxE,MAAMiB,QAAQD,YAAYvB,MAAMyB,MAAM,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKL,aAAahB;gBAC3E,OAAOnB,eAAe;oBACpBC;oBACAC;oBACAC;oBACAC,QAAQgC,OAAOP,mBAAmB,EAAE;oBACpCxB;oBACAC;oBACAC,MAAM4B,YAAY,GAAGrB,UAAU,CAAC,EAAEoB,MAAM,CAAC,EAAEC,WAAW,GAAG,GAAGrB,UAAU,CAAC,EAAEoB,OAAO;oBAChF1B;oBACAC,YAAY0B,YAAY,GAAGpB,gBAAgB,CAAC,EAAEoB,WAAW,GAAGpB;oBAC5DL,aAAauB;gBACf;YACF;QACF;IACF;IAEA,OAAOtB;AACT;AAEA;;;;;;;CAOC,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"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { applyFieldHooks } from './applyFieldHooks.js';
|
|
3
|
+
const mockReq = {
|
|
4
|
+
payload: {
|
|
5
|
+
logger: {
|
|
6
|
+
error: vi.fn()
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
describe('applyFieldHooks parent + child traversal', ()=>{
|
|
11
|
+
it('should run a parent group hook and still run child field hooks against the transformed value (export)', ()=>{
|
|
12
|
+
const fields = [
|
|
13
|
+
{
|
|
14
|
+
name: 'meta',
|
|
15
|
+
type: 'group',
|
|
16
|
+
flattenedFields: [
|
|
17
|
+
{
|
|
18
|
+
name: 'slug',
|
|
19
|
+
type: 'text'
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
const fieldHooks = {
|
|
25
|
+
meta: {
|
|
26
|
+
type: 'beforeExport',
|
|
27
|
+
fn: ({ value })=>{
|
|
28
|
+
const obj = value ?? {};
|
|
29
|
+
return {
|
|
30
|
+
...obj,
|
|
31
|
+
slug: `${obj.slug ?? ''}-from-parent`
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
meta_slug: {
|
|
36
|
+
type: 'beforeExport',
|
|
37
|
+
fn: ({ value })=>`${value}-from-child`
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const result = applyFieldHooks({
|
|
41
|
+
type: 'beforeExport',
|
|
42
|
+
data: {
|
|
43
|
+
meta: {
|
|
44
|
+
slug: 'raw'
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
fieldHooks,
|
|
48
|
+
fields,
|
|
49
|
+
format: 'json',
|
|
50
|
+
operation: 'export',
|
|
51
|
+
req: mockReq
|
|
52
|
+
});
|
|
53
|
+
// Parent hook ran first ('raw' → 'raw-from-parent'), then child hook ran against
|
|
54
|
+
// the transformed value ('raw-from-parent' → 'raw-from-parent-from-child').
|
|
55
|
+
expect(result.meta).toEqual({
|
|
56
|
+
slug: 'raw-from-parent-from-child'
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
it('should run a parent group hook and still run child field hooks (import)', ()=>{
|
|
60
|
+
const fields = [
|
|
61
|
+
{
|
|
62
|
+
name: 'meta',
|
|
63
|
+
type: 'group',
|
|
64
|
+
flattenedFields: [
|
|
65
|
+
{
|
|
66
|
+
name: 'slug',
|
|
67
|
+
type: 'text'
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
const fieldHooks = {
|
|
73
|
+
meta: {
|
|
74
|
+
type: 'beforeImport',
|
|
75
|
+
fn: ({ value })=>{
|
|
76
|
+
const obj = value ?? {};
|
|
77
|
+
return {
|
|
78
|
+
...obj,
|
|
79
|
+
slug: `${obj.slug ?? ''}-from-parent`
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
meta_slug: {
|
|
84
|
+
type: 'beforeImport',
|
|
85
|
+
fn: ({ value })=>`${value}-from-child`
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const result = applyFieldHooks({
|
|
89
|
+
type: 'beforeImport',
|
|
90
|
+
data: {
|
|
91
|
+
meta: {
|
|
92
|
+
slug: 'raw'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
fieldHooks,
|
|
96
|
+
fields,
|
|
97
|
+
format: 'json',
|
|
98
|
+
operation: 'import',
|
|
99
|
+
req: mockReq
|
|
100
|
+
});
|
|
101
|
+
expect(result.meta).toEqual({
|
|
102
|
+
slug: 'raw-from-parent-from-child'
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
it('should run a parent array hook then child hooks for each item', ()=>{
|
|
106
|
+
const fields = [
|
|
107
|
+
{
|
|
108
|
+
name: 'items',
|
|
109
|
+
type: 'array',
|
|
110
|
+
flattenedFields: [
|
|
111
|
+
{
|
|
112
|
+
name: 'note',
|
|
113
|
+
type: 'text'
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
const fieldHooks = {
|
|
119
|
+
items: {
|
|
120
|
+
type: 'beforeExport',
|
|
121
|
+
fn: ({ value })=>{
|
|
122
|
+
if (!Array.isArray(value)) {
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
return value.map((item)=>({
|
|
126
|
+
...item,
|
|
127
|
+
note: `${item.note ?? ''}-parent`
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
items_note: {
|
|
132
|
+
type: 'beforeExport',
|
|
133
|
+
fn: ({ value })=>`${value}-child`
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const result = applyFieldHooks({
|
|
137
|
+
type: 'beforeExport',
|
|
138
|
+
data: {
|
|
139
|
+
items: [
|
|
140
|
+
{
|
|
141
|
+
note: 'a'
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
note: 'b'
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
fieldHooks,
|
|
149
|
+
fields,
|
|
150
|
+
format: 'json',
|
|
151
|
+
operation: 'export',
|
|
152
|
+
req: mockReq
|
|
153
|
+
});
|
|
154
|
+
expect(result.items).toEqual([
|
|
155
|
+
{
|
|
156
|
+
note: 'a-parent-child'
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
note: 'b-parent-child'
|
|
160
|
+
}
|
|
161
|
+
]);
|
|
162
|
+
});
|
|
163
|
+
it('should not recurse into children when the parent hook returns a primitive', ()=>{
|
|
164
|
+
const fields = [
|
|
165
|
+
{
|
|
166
|
+
name: 'meta',
|
|
167
|
+
type: 'group',
|
|
168
|
+
flattenedFields: [
|
|
169
|
+
{
|
|
170
|
+
name: 'slug',
|
|
171
|
+
type: 'text'
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
];
|
|
176
|
+
const childFn = vi.fn(({ value })=>`${value}-from-child`);
|
|
177
|
+
const fieldHooks = {
|
|
178
|
+
meta: {
|
|
179
|
+
type: 'beforeExport',
|
|
180
|
+
fn: ()=>'serialized'
|
|
181
|
+
},
|
|
182
|
+
meta_slug: {
|
|
183
|
+
type: 'beforeExport',
|
|
184
|
+
fn: childFn
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const result = applyFieldHooks({
|
|
188
|
+
type: 'beforeExport',
|
|
189
|
+
data: {
|
|
190
|
+
meta: {
|
|
191
|
+
slug: 'raw'
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
fieldHooks,
|
|
195
|
+
fields,
|
|
196
|
+
format: 'json',
|
|
197
|
+
operation: 'export',
|
|
198
|
+
req: mockReq
|
|
199
|
+
});
|
|
200
|
+
expect(result.meta).toBe('serialized');
|
|
201
|
+
expect(childFn).not.toHaveBeenCalled();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
//# sourceMappingURL=applyFieldHooks.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/applyFieldHooks.spec.ts"],"sourcesContent":["import { FlattenedField, PayloadRequest } from 'payload'\n\nimport type { ExportFieldHookEntry, ImportFieldHookEntry } from '../types.js'\n\nimport { describe, expect, it, vi } from 'vitest'\n\nimport { applyFieldHooks } from './applyFieldHooks.js'\n\nconst mockReq = {\n payload: {\n logger: {\n error: vi.fn(),\n },\n },\n} as unknown as PayloadRequest\n\ndescribe('applyFieldHooks parent + child traversal', () => {\n it('should run a parent group hook and still run child field hooks against the transformed value (export)', () => {\n const fields: FlattenedField[] = [\n {\n name: 'meta',\n type: 'group',\n flattenedFields: [{ name: 'slug', type: 'text' } as FlattenedField],\n } as unknown as FlattenedField,\n ]\n\n const fieldHooks: Record<string, ExportFieldHookEntry> = {\n meta: {\n type: 'beforeExport',\n fn: ({ value }) => {\n const obj = (value ?? {}) as Record<string, unknown>\n return { ...obj, slug: `${obj.slug ?? ''}-from-parent` }\n },\n },\n meta_slug: {\n type: 'beforeExport',\n fn: ({ value }) => `${value}-from-child`,\n },\n }\n\n const result = applyFieldHooks({\n type: 'beforeExport',\n data: { meta: { slug: 'raw' } },\n fieldHooks,\n fields,\n format: 'json',\n operation: 'export',\n req: mockReq,\n })\n\n // Parent hook ran first ('raw' → 'raw-from-parent'), then child hook ran against\n // the transformed value ('raw-from-parent' → 'raw-from-parent-from-child').\n expect(result.meta).toEqual({ slug: 'raw-from-parent-from-child' })\n })\n\n it('should run a parent group hook and still run child field hooks (import)', () => {\n const fields: FlattenedField[] = [\n {\n name: 'meta',\n type: 'group',\n flattenedFields: [{ name: 'slug', type: 'text' } as FlattenedField],\n } as unknown as FlattenedField,\n ]\n\n const fieldHooks: Record<string, ImportFieldHookEntry> = {\n meta: {\n type: 'beforeImport',\n fn: ({ value }) => {\n const obj = (value ?? {}) as Record<string, unknown>\n return { ...obj, slug: `${obj.slug ?? ''}-from-parent` }\n },\n },\n meta_slug: {\n type: 'beforeImport',\n fn: ({ value }) => `${value}-from-child`,\n },\n }\n\n const result = applyFieldHooks({\n type: 'beforeImport',\n data: { meta: { slug: 'raw' } },\n fieldHooks,\n fields,\n format: 'json',\n operation: 'import',\n req: mockReq,\n })\n\n expect(result.meta).toEqual({ slug: 'raw-from-parent-from-child' })\n })\n\n it('should run a parent array hook then child hooks for each item', () => {\n const fields: FlattenedField[] = [\n {\n name: 'items',\n type: 'array',\n flattenedFields: [{ name: 'note', type: 'text' } as FlattenedField],\n } as unknown as FlattenedField,\n ]\n\n const fieldHooks: Record<string, ExportFieldHookEntry> = {\n items: {\n type: 'beforeExport',\n fn: ({ value }) => {\n if (!Array.isArray(value)) {\n return value\n }\n return value.map((item) => ({\n ...(item as Record<string, unknown>),\n note: `${(item as Record<string, unknown>).note ?? ''}-parent`,\n }))\n },\n },\n items_note: {\n type: 'beforeExport',\n fn: ({ value }) => `${value}-child`,\n },\n }\n\n const result = applyFieldHooks({\n type: 'beforeExport',\n data: { items: [{ note: 'a' }, { note: 'b' }] },\n fieldHooks,\n fields,\n format: 'json',\n operation: 'export',\n req: mockReq,\n })\n\n expect(result.items).toEqual([{ note: 'a-parent-child' }, { note: 'b-parent-child' }])\n })\n\n it('should not recurse into children when the parent hook returns a primitive', () => {\n const fields: FlattenedField[] = [\n {\n name: 'meta',\n type: 'group',\n flattenedFields: [{ name: 'slug', type: 'text' } as FlattenedField],\n } as unknown as FlattenedField,\n ]\n\n const childFn = vi.fn(({ value }: { value: unknown }) => `${value}-from-child`)\n const fieldHooks: Record<string, ExportFieldHookEntry> = {\n meta: {\n type: 'beforeExport',\n fn: () => 'serialized',\n },\n meta_slug: {\n type: 'beforeExport',\n fn: childFn,\n },\n }\n\n const result = applyFieldHooks({\n type: 'beforeExport',\n data: { meta: { slug: 'raw' } },\n fieldHooks,\n fields,\n format: 'json',\n operation: 'export',\n req: mockReq,\n })\n\n expect(result.meta).toBe('serialized')\n expect(childFn).not.toHaveBeenCalled()\n })\n})\n"],"names":["describe","expect","it","vi","applyFieldHooks","mockReq","payload","logger","error","fn","fields","name","type","flattenedFields","fieldHooks","meta","value","obj","slug","meta_slug","result","data","format","operation","req","toEqual","items","Array","isArray","map","item","note","items_note","childFn","toBe","not","toHaveBeenCalled"],"mappings":"AAIA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAEjD,SAASC,eAAe,QAAQ,uBAAsB;AAEtD,MAAMC,UAAU;IACdC,SAAS;QACPC,QAAQ;YACNC,OAAOL,GAAGM,EAAE;QACd;IACF;AACF;AAEAT,SAAS,4CAA4C;IACnDE,GAAG,yGAAyG;QAC1G,MAAMQ,SAA2B;YAC/B;gBACEC,MAAM;gBACNC,MAAM;gBACNC,iBAAiB;oBAAC;wBAAEF,MAAM;wBAAQC,MAAM;oBAAO;iBAAoB;YACrE;SACD;QAED,MAAME,aAAmD;YACvDC,MAAM;gBACJH,MAAM;gBACNH,IAAI,CAAC,EAAEO,KAAK,EAAE;oBACZ,MAAMC,MAAOD,SAAS,CAAC;oBACvB,OAAO;wBAAE,GAAGC,GAAG;wBAAEC,MAAM,GAAGD,IAAIC,IAAI,IAAI,GAAG,YAAY,CAAC;oBAAC;gBACzD;YACF;YACAC,WAAW;gBACTP,MAAM;gBACNH,IAAI,CAAC,EAAEO,KAAK,EAAE,GAAK,GAAGA,MAAM,WAAW,CAAC;YAC1C;QACF;QAEA,MAAMI,SAAShB,gBAAgB;YAC7BQ,MAAM;YACNS,MA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AgB;IACtC;AACF"}
|
|
@@ -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,WAAY,KAAK,EAAE,KAAG,MAAM,
|
|
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,WAAY,KAAK,EAAE,KAAG,MAAM,EAmEjE,CAAA"}
|
|
@@ -41,7 +41,7 @@ import { fieldAffectsData } from 'payload/shared';
|
|
|
41
41
|
let parentPath;
|
|
42
42
|
if (parentRef && typeof parentRef === 'object' && 'path' in parentRef && typeof parentRef.path === 'string') {
|
|
43
43
|
parentPath = parentRef.path;
|
|
44
|
-
} else if (ref
|
|
44
|
+
} else if (ref.__manualRef && typeof ref.path === 'string') {
|
|
45
45
|
// Fallback: if current ref is a manual tabRef, use its path
|
|
46
46
|
parentPath = ref.path;
|
|
47
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/collectDisabledFieldPaths.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { traverseFields } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\n/**\n * Recursively traverses a Payload field schema to collect all field paths\n * that are explicitly disabled for the import/export plugin via:\n * field.custom['plugin-import-export'].disabled\n *\n * Handles nested fields including named tabs, groups, arrays, blocks, etc.\n * Tracks each field’s path by storing it in `ref.path` and manually propagating\n * it through named tab layers via a temporary `__manualRef` marker.\n *\n * @param fields - The top-level array of Payload field definitions\n * @returns An array of dot-notated field paths that are marked as disabled\n */\nexport const collectDisabledFieldPaths = (fields: Field[]): string[] => {\n const disabledPaths: string[] = []\n\n traverseFields({\n callback: ({ field, next, parentRef, ref }) => {\n // Handle named tabs\n if (field.type === 'tabs' && Array.isArray(field.tabs)) {\n for (const tab of field.tabs) {\n if ('name' in tab && typeof tab.name === 'string') {\n // Build the path prefix for this tab\n const parentPath =\n parentRef && typeof (parentRef as { path?: unknown }).path === 'string'\n ? (parentRef as { path: string }).path\n : ''\n const tabPath = parentPath ? `${parentPath}.${tab.name}` : tab.name\n\n // Prepare a ref for this named tab's children to inherit the path\n const refObj = ref as Record<string,
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/collectDisabledFieldPaths.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { traverseFields } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\n/**\n * Recursively traverses a Payload field schema to collect all field paths\n * that are explicitly disabled for the import/export plugin via:\n * field.custom['plugin-import-export'].disabled\n *\n * Handles nested fields including named tabs, groups, arrays, blocks, etc.\n * Tracks each field’s path by storing it in `ref.path` and manually propagating\n * it through named tab layers via a temporary `__manualRef` marker.\n *\n * @param fields - The top-level array of Payload field definitions\n * @returns An array of dot-notated field paths that are marked as disabled\n */\nexport const collectDisabledFieldPaths = (fields: Field[]): string[] => {\n const disabledPaths: string[] = []\n\n traverseFields({\n callback: ({ field, next, parentRef, ref }) => {\n // Handle named tabs\n if (field.type === 'tabs' && Array.isArray(field.tabs)) {\n for (const tab of field.tabs) {\n if ('name' in tab && typeof tab.name === 'string') {\n // Build the path prefix for this tab\n const parentPath =\n parentRef && typeof (parentRef as { path?: unknown }).path === 'string'\n ? (parentRef as { path: string }).path\n : ''\n const tabPath = parentPath ? `${parentPath}.${tab.name}` : tab.name\n\n // Prepare a ref for this named tab's children to inherit the path\n const refObj = ref as Record<string, unknown>\n const tabRef = (refObj[tab.name] as Record<string, unknown>) ?? {}\n tabRef.path = tabPath\n tabRef.__manualRef = true // flag this as a manually constructed parentRef\n refObj[tab.name] = tabRef\n }\n }\n\n // Skip further processing of the tab container itself\n return\n }\n\n // Skip unnamed fields (e.g. rows/collapsibles)\n if (!('name' in field) || typeof field.name !== 'string') {\n return\n }\n\n // Determine the path to the current field\n let parentPath: string | undefined\n\n if (\n parentRef &&\n typeof parentRef === 'object' &&\n 'path' in parentRef &&\n typeof (parentRef as { path?: unknown }).path === 'string'\n ) {\n parentPath = (parentRef as { path: string }).path\n } else if (\n (ref as Record<string, unknown>).__manualRef &&\n typeof (ref as Record<string, unknown>).path === 'string'\n ) {\n // Fallback: if current ref is a manual tabRef, use its path\n parentPath = (ref as Record<string, unknown>).path as string\n }\n\n const fullPath = parentPath ? `${parentPath}.${field.name}` : field.name\n\n // Store current path for any nested children to use\n ;(ref as Record<string, unknown>).path = fullPath\n\n // If field is a data-affecting field and disabled via plugin config, collect its path\n if (fieldAffectsData(field) && field.custom?.['plugin-import-export']?.disabled) {\n disabledPaths.push(fullPath)\n return next?.()\n }\n },\n fields,\n })\n\n return disabledPaths\n}\n"],"names":["traverseFields","fieldAffectsData","collectDisabledFieldPaths","fields","disabledPaths","callback","field","next","parentRef","ref","type","Array","isArray","tabs","tab","name","parentPath","path","tabPath","refObj","tabRef","__manualRef","fullPath","custom","disabled","push"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AACxC,SAASC,gBAAgB,QAAQ,iBAAgB;AAEjD;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,4BAA4B,CAACC;IACxC,MAAMC,gBAA0B,EAAE;IAElCJ,eAAe;QACbK,UAAU,CAAC,EAAEC,KAAK,EAAEC,IAAI,EAAEC,SAAS,EAAEC,GAAG,EAAE;YACxC,oBAAoB;YACpB,IAAIH,MAAMI,IAAI,KAAK,UAAUC,MAAMC,OAAO,CAACN,MAAMO,IAAI,GAAG;gBACtD,KAAK,MAAMC,OAAOR,MAAMO,IAAI,CAAE;oBAC5B,IAAI,UAAUC,OAAO,OAAOA,IAAIC,IAA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
|
|
2
|
-
import type {
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { ExportFieldHookEntry } from '../types.js';
|
|
3
3
|
type Args = {
|
|
4
|
-
|
|
4
|
+
data: Record<string, unknown>;
|
|
5
|
+
exportFieldHooks: Record<string, ExportFieldHookEntry>;
|
|
5
6
|
fields?: string[];
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
format: 'csv' | 'json' | ({} & string);
|
|
8
|
+
path?: string;
|
|
9
|
+
req: PayloadRequest;
|
|
8
10
|
};
|
|
9
|
-
export declare const flattenObject: ({
|
|
11
|
+
export declare const flattenObject: ({ data, exportFieldHooks, fields, format, path, req, }: Args) => Record<string, unknown>;
|
|
10
12
|
export {};
|
|
11
13
|
//# sourceMappingURL=flattenObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
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,2DAOvB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAqL/B,CAAA"}
|