feat(plugin-import-export): give import/export hooks access to the triggering document - #17797
Draft
nathanlentz wants to merge 5 commits into
Draft
feat(plugin-import-export): give import/export hooks access to the triggering document#17797nathanlentz wants to merge 5 commits into
nathanlentz wants to merge 5 commits into
Conversation
…iggering document The collection-level import/export hooks received no reference to the document that started the run, so a field added to the imports/exports collection via `overrideCollection` could not be read while processing. That also left no way to correlate a running job with its document in jobs mode. Adds `importDoc` to `ImportBeforeHook`/`ImportAfterHook` and `exportDoc` to `ExportBeforeHook`/`ExportAfterHook`, covering all seven hook contexts: - import jobs and sync, which already held the saved document - export jobs, which now reads the document back — the job input schema is a fixed whitelist, so fields added via `overrideCollection` do not survive serialization - export sync, download, and both preview endpoints, which pass the submitted form data `id` is optional on both types because only the export jobs path has a saved document when the hooks run. Export sync runs in `beforeOperation`, and the download and preview paths never persist one. On those, every user-authored field is present but `id`, `createdAt` and `updatedAt` are not, and the values are unvalidated request input — both documented. The document is read once when the run starts and passed unchanged to every batch, so it is a snapshot rather than live state. A long run would otherwise add a database read per batch to observe a change nothing needs. Closes #16961
…w endpoints The preview components built their request bodies from a fixed list of built-in fields, so a field added to an imports/exports collection via `overrideCollection` never reached the collection-level hooks. Both now forward the whole form, and re-fetch when a custom value changes. The endpoints drop `id`, `createdAt` and `updatedAt` from the incoming body, so an `id` on `exportDoc`/`importDoc` means the document really is saved rather than something a caller can put on a request. Adds coverage for the queued-import, synchronous-export and download after hooks, for document identity across batches, and for two cases where a form value changes the rows that get written. The new tests clean up the import and export documents and the job records they create.
…ming Cleanup no longer catches deletion failures, so a delete that does not succeed fails the test rather than passing quietly. Job records are tracked per test: a snapshot of the existing payload-jobs IDs is taken before each test and only the records added on top of it are removed, instead of deleting every job record. Splits the download test so each one checks a single hook, routes the repeated post-and-export setup through helpers, and renames `withBatchRefField` and `generatedKeys` to describe what they actually do.
Contributor
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
importDocandexportDocto the collection-level before/after hooks so custom fields added withoverrideCollectioncan influence every processed row. Saved documents also provide the ID needed to associate queued work with its import or export.Addresses #16961.
Behavior
beforeOperation; downloads and previews use submitted form values. These paths omitid,createdAt, andupdatedAt.ImportDocandExportDocare exported from@payloadcms/plugin-import-export/types. An ID identifies persistence, not authorization for actions performed by a hook.Updated against current
main, including migration to the shared integration-test fixture. Tests retain coverage of synchronous, queued, download, and preview paths, row transformations, and shared document identity across batches.Validation
fromTokenFileexport. Standalone test-suite type checking also reports existing workspace/config errors; the hook test file has no remaining type errors.The PR remains a draft pending refreshed CI.