Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide entry id for transform and derive functions #1212

Merged
merged 2 commits into from
Jun 7, 2023

Conversation

marcolink
Copy link
Member

@marcolink marcolink commented Jun 6, 2023

Summary

Provide the entry id for several transform callbacks.

Description

For all transformation functions (transformEntries, deriveLinkedEntries and transformEntriesToType) we provide the entry id of the entry in scope in the call signature of the transform callbacks. This allows for cross checking the id with any other source, or more custom validations within scope.

We opted-in for an wrapping object as a third parameter to eventually enrich the callback with further data in the future.

Example: (more in the updated readme)

module.exports = function (migration) {
  migration.transformEntries({
    contentType: 'newsArticle',
    from: ['author', 'authorCity'],
    to: ['byline'],
    transformEntryForLocale: function (fromFields, currentLocale, {id}) {
      
      if(id === '<specific-entry-id>') {
        return;
      }
      
      if (currentLocale === 'de-DE') {
        return;
      }
      const newByline = `${fromFields.author[currentLocale]} ${fromFields.authorCity[currentLocale]}`;
      return { byline: newByline };
    }
  });
};

Motivation and Context

This is solves issues #1170, #1029, and the super seeds PR.

Todos

  • add tests
  • Update readme

@marcolink marcolink requested a review from a team as a code owner June 6, 2023 11:19
@marcolink marcolink force-pushed the feat/provide-entry-id branch 4 times, most recently from a06b657 to c6ca4e2 Compare June 6, 2023 11:55
@marcolink marcolink changed the title feat: provide entry id for transformEntryForLocale feat: provide entry id for transform and derive functions Jun 6, 2023
@marcolink marcolink force-pushed the feat/provide-entry-id branch from f5737f1 to 7ad0142 Compare June 7, 2023 05:56
Copy link
Contributor

@ruderngespra ruderngespra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool to see this tackled 🎉

If I see this correctly, this is no breaking change as this id can be completely ignored in the callbacks and never has to be provided or passed through by customers directly?

@marcolink marcolink merged commit 05f1135 into master Jun 7, 2023
@marcolink marcolink deleted the feat/provide-entry-id branch June 7, 2023 11:16
@contentful-automation
Copy link

🎉 This PR is included in version 4.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants