Skip to content

Commit

Permalink
feat: Add Option to Suppress Pre- and Post-Retrieve Events (#854)
Browse files Browse the repository at this point in the history
* feat: add option to suppress retrieve events

* chore: auto-update metadata coverage in METADATA_SUPPORT.md

* test: record perf

* test: draft unit test

* chore: auto-update metadata coverage in METADATA_SUPPORT.md

* test: update description to be more accurate

since the apiVersionRetrieve event is not suppressed

* test: simplify expects

* test: record perf

* test: only check for absence of specific events

* test: record perf

---------

Co-authored-by: svc-cli-bot <svc_cli_bot@salesforce.com>
  • Loading branch information
klewis-sfdc and svc-cli-bot authored Feb 17, 2023
1 parent 4b5017b commit 2eef7d5
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 14 deletions.
1 change: 1 addition & 0 deletions METADATA_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ v58 introduces the following new types. Here's their current level of support
|Ai4mSettings|||
|CodeBuilderSettings|||
|DataWeaveResource|||
|DynamicFormsSettings|||
|OmniChannelPricingSettings|||
|PriceSheetDefinition||Not supported, but support could be added|
|ProcessFlowMigration||Not supported, but support could be added|
Expand Down
4 changes: 2 additions & 2 deletions src/client/metadataApiRetrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class MetadataApiRetrieve extends MetadataTransfer<
components ??= new ComponentSet(undefined, this.options.registry);

const retrieveResult = new RetrieveResult(result, components, this.components);
if (!isMdapiRetrieve) {
if (!isMdapiRetrieve && !this.options.suppressEvents) {
// This should only be done when retrieving source format since retrieving
// mdapi format has no conversion or events/hooks
await this.maybeSaveTempDirectory('source', components);
Expand Down Expand Up @@ -226,7 +226,7 @@ export class MetadataApiRetrieve extends MetadataTransfer<
this.components.sourceApiVersion ??= apiVersion;

// only do event hooks if source, (NOT a metadata format) retrieve
if (this.options.components) {
if (this.options.components && !this.options.suppressEvents) {
await Lifecycle.getInstance().emit('scopedPreRetrieve', {
componentSet: this.options.components,
orgId: this.orgId,
Expand Down
4 changes: 4 additions & 0 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ export interface RetrieveOptions {
* Specifies whether to unzip the retrieved zip file. Only applies when `format: metadata`.
*/
unzip?: boolean;
/**
* Specifies whether to suppress the <Pre|Post><Retrieve> events
*/
suppressEvents?: boolean;
}

export interface MetadataApiDeployOptions {
Expand Down
14 changes: 14 additions & 0 deletions test/collections/componentSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ describe('ComponentSet', () => {
unpackaged: { types: [{ members: ['Test'], name: 'ApexClass' }], version: manifestVersion },
});
});

it('should not emit pre- or post-retrieve events with the suppressEvents setting set to true', async () => {
componentSet = await ComponentSetBuilder.build({ sourcepath: [sourcepath] });
await stubConnection();
await componentSet.retrieve({ output: '', usernameOrConnection: connection, suppressEvents: true });

let preAndPostRetrieveEventCount = 0;
lifecycleEmitStub.args.forEach((event) => {
if (event[0] === ('scopedPreRetrieve' || 'scopedPostRetrieve')) {
preAndPostRetrieveEventCount = preAndPostRetrieveEventCount + 1;
}
});
expect(preAndPostRetrieveEventCount).to.equal(0);
});
});

describe('deploy', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 314.8237599999993
"duration": 344.26991400000406
},
{
"name": "sourceToMdapi",
"duration": 7607.062248000002
"duration": 8409.486489000003
},
{
"name": "sourceToZip",
"duration": 6249.7481109999935
"duration": 6911.691437000001
},
{
"name": "mdapiToSource",
"duration": 5729.999462999986
"duration": 5980.411838
}
]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 677.3227829999814
"duration": 666.2776299999969
},
{
"name": "sourceToMdapi",
"duration": 11628.18376700001
"duration": 11784.642793000006
},
{
"name": "sourceToZip",
"duration": 9789.493870999984
"duration": 9004.190682999993
},
{
"name": "mdapiToSource",
"duration": 8767.531892999978
"duration": 8077.6561640000145
}
]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 1097.0085559999861
"duration": 1166.675390999997
},
{
"name": "sourceToMdapi",
"duration": 16553.773215000023
"duration": 18113.351571000007
},
{
"name": "sourceToZip",
"duration": 14349.35624600001
"duration": 14997.718697000004
},
{
"name": "mdapiToSource",
"duration": 14337.243206000014
"duration": 13485.154669999989
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 199.62190299999202
},
{
"name": "sourceToMdapi",
"duration": 5130.159515000007
},
{
"name": "sourceToZip",
"duration": 4675.235429000022
},
{
"name": "mdapiToSource",
"duration": 3208.6088720000116
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 410.4985020000022
},
{
"name": "sourceToMdapi",
"duration": 7788.398672999989
},
{
"name": "sourceToZip",
"duration": 8867.863911000022
},
{
"name": "mdapiToSource",
"duration": 4871.89470200002
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 656.9274350000196
},
{
"name": "sourceToMdapi",
"duration": 11477.084537999996
},
{
"name": "sourceToZip",
"duration": 11235.755581000005
},
{
"name": "mdapiToSource",
"duration": 8346.796450999973
}
]

0 comments on commit 2eef7d5

Please sign in to comment.