Skip to content

Commit 2eef7d5

Browse files
feat: Add Option to Suppress Pre- and Post-Retrieve Events (#854)
* 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>
1 parent 4b5017b commit 2eef7d5

File tree

10 files changed

+87
-14
lines changed

10 files changed

+87
-14
lines changed

METADATA_SUPPORT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ v58 introduces the following new types. Here's their current level of support
557557
|Ai4mSettings|||
558558
|CodeBuilderSettings|||
559559
|DataWeaveResource|||
560+
|DynamicFormsSettings|||
560561
|OmniChannelPricingSettings|||
561562
|PriceSheetDefinition||Not supported, but support could be added|
562563
|ProcessFlowMigration||Not supported, but support could be added|

src/client/metadataApiRetrieve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class MetadataApiRetrieve extends MetadataTransfer<
198198
components ??= new ComponentSet(undefined, this.options.registry);
199199

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

228228
// only do event hooks if source, (NOT a metadata format) retrieve
229-
if (this.options.components) {
229+
if (this.options.components && !this.options.suppressEvents) {
230230
await Lifecycle.getInstance().emit('scopedPreRetrieve', {
231231
componentSet: this.options.components,
232232
orgId: this.orgId,

src/client/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ export interface RetrieveOptions {
326326
* Specifies whether to unzip the retrieved zip file. Only applies when `format: metadata`.
327327
*/
328328
unzip?: boolean;
329+
/**
330+
* Specifies whether to suppress the <Pre|Post><Retrieve> events
331+
*/
332+
suppressEvents?: boolean;
329333
}
330334

331335
export interface MetadataApiDeployOptions {

test/collections/componentSet.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ describe('ComponentSet', () => {
208208
unpackaged: { types: [{ members: ['Test'], name: 'ApexClass' }], version: manifestVersion },
209209
});
210210
});
211+
212+
it('should not emit pre- or post-retrieve events with the suppressEvents setting set to true', async () => {
213+
componentSet = await ComponentSetBuilder.build({ sourcepath: [sourcepath] });
214+
await stubConnection();
215+
await componentSet.retrieve({ output: '', usernameOrConnection: connection, suppressEvents: true });
216+
217+
let preAndPostRetrieveEventCount = 0;
218+
lifecycleEmitStub.args.forEach((event) => {
219+
if (event[0] === ('scopedPreRetrieve' || 'scopedPostRetrieve')) {
220+
preAndPostRetrieveEventCount = preAndPostRetrieveEventCount + 1;
221+
}
222+
});
223+
expect(preAndPostRetrieveEventCount).to.equal(0);
224+
});
211225
});
212226

213227
describe('deploy', () => {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[
22
{
33
"name": "componentSetCreate",
4-
"duration": 314.8237599999993
4+
"duration": 344.26991400000406
55
},
66
{
77
"name": "sourceToMdapi",
8-
"duration": 7607.062248000002
8+
"duration": 8409.486489000003
99
},
1010
{
1111
"name": "sourceToZip",
12-
"duration": 6249.7481109999935
12+
"duration": 6911.691437000001
1313
},
1414
{
1515
"name": "mdapiToSource",
16-
"duration": 5729.999462999986
16+
"duration": 5980.411838
1717
}
1818
]
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[
22
{
33
"name": "componentSetCreate",
4-
"duration": 677.3227829999814
4+
"duration": 666.2776299999969
55
},
66
{
77
"name": "sourceToMdapi",
8-
"duration": 11628.18376700001
8+
"duration": 11784.642793000006
99
},
1010
{
1111
"name": "sourceToZip",
12-
"duration": 9789.493870999984
12+
"duration": 9004.190682999993
1313
},
1414
{
1515
"name": "mdapiToSource",
16-
"duration": 8767.531892999978
16+
"duration": 8077.6561640000145
1717
}
1818
]
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[
22
{
33
"name": "componentSetCreate",
4-
"duration": 1097.0085559999861
4+
"duration": 1166.675390999997
55
},
66
{
77
"name": "sourceToMdapi",
8-
"duration": 16553.773215000023
8+
"duration": 18113.351571000007
99
},
1010
{
1111
"name": "sourceToZip",
12-
"duration": 14349.35624600001
12+
"duration": 14997.718697000004
1313
},
1414
{
1515
"name": "mdapiToSource",
16-
"duration": 14337.243206000014
16+
"duration": 13485.154669999989
1717
}
1818
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"name": "componentSetCreate",
4+
"duration": 199.62190299999202
5+
},
6+
{
7+
"name": "sourceToMdapi",
8+
"duration": 5130.159515000007
9+
},
10+
{
11+
"name": "sourceToZip",
12+
"duration": 4675.235429000022
13+
},
14+
{
15+
"name": "mdapiToSource",
16+
"duration": 3208.6088720000116
17+
}
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"name": "componentSetCreate",
4+
"duration": 410.4985020000022
5+
},
6+
{
7+
"name": "sourceToMdapi",
8+
"duration": 7788.398672999989
9+
},
10+
{
11+
"name": "sourceToZip",
12+
"duration": 8867.863911000022
13+
},
14+
{
15+
"name": "mdapiToSource",
16+
"duration": 4871.89470200002
17+
}
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"name": "componentSetCreate",
4+
"duration": 656.9274350000196
5+
},
6+
{
7+
"name": "sourceToMdapi",
8+
"duration": 11477.084537999996
9+
},
10+
{
11+
"name": "sourceToZip",
12+
"duration": 11235.755581000005
13+
},
14+
{
15+
"name": "mdapiToSource",
16+
"duration": 8346.796450999973
17+
}
18+
]

0 commit comments

Comments
 (0)