Skip to content

Recomposition for CustomObjects #95

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

Merged
merged 17 commits into from
Aug 12, 2020
Merged

Recomposition for CustomObjects #95

merged 17 commits into from
Aug 12, 2020

Conversation

brpowell
Copy link
Contributor

@brpowell brpowell commented Aug 3, 2020

What does this PR do?

Lays the foundation for metadata recomposition (source format -> metadata format). Some additional configuration will be needed to handle other types like CustomObjectTranslations but trying to keep this initial check-in simple.

What issues does this PR fix or reference?

@W-7672773@

@brpowell brpowell force-pushed the bp/recomposition branch 2 times, most recently from 8349e52 to a689d46 Compare August 5, 2020 22:55
@brpowell brpowell marked this pull request as ready for review August 5, 2020 23:01
@brpowell brpowell requested a review from a team as a code owner August 5, 2020 23:01
package.json Outdated
@@ -31,6 +31,8 @@
"@salesforce/core": "2.5.1",
"archiver": "4.0.1",
"ignore": "^5.1.8",
"fast-xml-parser": "^3.17.4",
"gitignore-parser": "^0.0.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove, added by accident on rebase

import { DecomposedMetadataTransformer } from './transformers/decomposedMetadataTransformer';
import { SourceComponent } from '../metadata-registry';

export type ConvertTransactionState = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Recomposition is special because there is an n:1 mapping of components to file. Before we can write the file we have to build the shape of the final XML and understand how many child components need to be included. We use a ConvertTransactionState to collect all the information before writing, and then finalize the conversion call by writing things left over in the state. While this is unique to recomposition, the constructs in this file are meant to generally handle anything that needs to be done at the end of a conversion if a future requirement needs it. The recompose key in this type is reserved for saving state for the RecompositionFinalizer.

It's possible this pattern will not be needed if we figure out a way to stream child components directly to the destination and know when to "close" the file currently being written.

Comment on lines +25 to +44
if (this.component.parent) {
const { state } = this.convertTransaction;
const { fullName: parentName } = this.component.parent;
if (!state.recompose[parentName]) {
state.recompose[parentName] = {
component: this.component.parent,
children: [],
};
}
state.recompose[parentName].children.push(this.component);
// noop since the finalizer will push the writes to the component writer
return { component: this.component, writeInfos: [] };
}

const baseXmlObj = parseXml(readFileSync(this.component.xml).toString());
const recomposedXmlObj = DecomposedMetadataTransformer.recompose(
this.component.getChildren(),
baseXmlObj
);
return DecomposedMetadataTransformer.createWriterFormat(this.component, recomposedXmlObj);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If a child component is trying to be converted, we save it in the convert transaction state to be dealt with at the end of the conversion. i.e. to be recomposed at the end. Otherwise if it's a parent object, we can recompose this all at once.

@brpowell brpowell merged commit e111e94 into develop Aug 12, 2020
@brpowell brpowell deleted the bp/recomposition branch August 12, 2020 00:41
sfsholden pushed a commit that referenced this pull request Aug 13, 2020
sfsholden pushed a commit that referenced this pull request Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants