-
Notifications
You must be signed in to change notification settings - Fork 125
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
Conversation
8349e52
to
a689d46
Compare
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", |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
31684b5
to
3485c30
Compare
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@