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

Expose JSON schema transformation tools as part of API #89

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jgaehring
Copy link
Member

@duarteoctavio, if this looks good to you, I can merge and tag it as 2.0.0-beta.16.

@jgaehring
Copy link
Member Author

I also parameterized the Drupal meta fields on the transformD9Schema function, so you can pass it an optional second parameter, which is an object with the attributes and relationships you want to remove from the schema, something like this:

const exclude = {
  attributes: [
    'created',
    'changed',
    'drupal_internal__id',
    'drupal_internal__revision_id',
    'langcode',
    'revision_created',
    'revision_log_message',
    'default_langcode',
    'revision_translation_affected',
    'revision_default',
  ],
  relationships: ['revision_user', 'uid'],
};
const dedrupalizedSchema = transformD9Schema(drupalificSchema, exclude);

The ones above there are the defaults if you don't pass the parameter. If you do pass a parameter, only the ones you explicitly list will be removed; in other words, your exclude replaces the default exclude, it doesn't add to it. If Drupal was consistent and always used that drupal_internal__ prefix this could probably be done with some regex or something more subtle, but alas...

There are some other ways those meta fields are used internally, such as in transformRemoteEntity, which does a similar operation on the actual data, but at the same time plucks information from the Drupal meta data, transforms and moves it to a dedicated meta property, outside of attributes and relationships, so properties like created, the internal drupal_internal__id and drupal_internal__revision_id are not lost but can still be used for the purposes of syncing and subrequests and what have you. So just be mindful, @duarteoctavio, you could introduce some bugs if you combine usage of transformD9Schema with normal usage of farm.log.fetch() or farm.log.update(). Hopefully not, but I haven't tested it.

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

Successfully merging this pull request may close these issues.

None yet

1 participant