Skip to content

Commit

Permalink
fix: confirm DCL behavior, fix snapshots, add .md entry
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Mar 27, 2024
1 parent 95114ed commit 7c055bb
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 74 deletions.
24 changes: 20 additions & 4 deletions src/Presets.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Available Registry Presets

## `decomposePermissionSet`
## `decomposePermissionSetBeta`

PermissionSet is decomposed to a folder named after the PermissionSet.

Expand All @@ -22,7 +22,7 @@ Simple fields (ex: `description`, `userLicense`) remain in the top-level `myPS.p

FieldPermissions for all objects are in the same folder (they're not in sub-folders by object). This is intentional--I wanted subfolders but couldn't get it to work well.

## `decomposeSharingRules`
## `decomposeSharingRulesBeta`

SharingRules is decomposed to a folder named after the sharingRules (which is named after an object)

Expand All @@ -42,12 +42,12 @@ source format
Each child of SharingRules that is a repeated xml element (ex: sharingTerritoryRules) is saved as a separate file
SharingRules has not simple fields, so the top-level `Account.sharingRules-meta.xml` will be an empty xml.

## `decomposeWorkflow`
## `decomposeWorkflowBeta`

Workflow is decomposed to a folder named after the Workflow (which is named after an object)

metadata format
`/workflows/Account.workflow`
`/workflows/Account.workflowBeta`

source format

Expand All @@ -61,3 +61,19 @@ source format

Each child of Workflow that is a repeated xml element (ex: workflowAlerts) is saved as a separate file
Simple fields (ex: `fullName`) can remain in the top-level `Account.workflow-meta.xml`. This could also have no children

## `decomposeCustomLabelsBeta`

CustomLabels are decomposed to a folder named `CustomLabels` the labels are then placed into individual files

metadata format
`/labels/CustomLabels.customlabes-meta.xml`

source format

```txt
/labels/CustomLabels/CustomLabels.labels-meta.xml (the non-decomposed parts)
/labels/CustomLabels/a.label-meta.xml
/labels/CustomLabels/b.label-meta.xml
/labels/CustomLabels/c.label-meta.xml
```
11 changes: 8 additions & 3 deletions src/collections/componentSetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class ComponentSetBuilder {
fromConnection.toArray().map(addToComponentSet(componentSet));
}
} catch (e) {
return fromConnectionErrorHandler(e);
return componentSetBuilderErrorHandler(e);
}

// there should have been a componentSet created by this point.
Expand All @@ -167,7 +167,7 @@ const addToComponentSet =
return cmp;
};

const fromConnectionErrorHandler = (e: unknown): never => {
const componentSetBuilderErrorHandler = (e: unknown): never => {
if (e instanceof Error && e.message.includes('Missing metadata type definition in registry for id')) {
// to remain generic to catch missing metadata types regardless of parameters, split on '
// example message : Missing metadata type definition in registry for id 'NonExistentType'
Expand Down Expand Up @@ -245,7 +245,12 @@ export const entryToTypeAndName =
(rawEntry: string): MetadataTypeAndMetadataName => {
// split on the first colon, and then join the rest back together to support names that include colons
const [typeName, ...name] = rawEntry.split(':').map((entry) => entry.trim());
return { type: reg.getTypeByName(typeName), metadataName: name.length ? name.join(':') : '*' };
const type = reg.getTypeByName(typeName);
const parent = reg.getParentType(typeName);
if (type.isAddressable === false && parent !== undefined && !type.unaddressableWithoutParent) {
throw new Error(`Cannot use this type, instead use ${parent.name}`);
}
return { type, metadataName: name.length ? name.join(':') : '*' };
};

const typeAndNameToMetadataComponents =
Expand Down
11 changes: 7 additions & 4 deletions src/registry/presets/decomposeCustomLabelsBeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"suffixes": {
"label": "customlabel"
},
"strictDirectoryNames": {
"labels": "customlabels"
},
"types": {
"customlabels": {
"children": {
Expand All @@ -13,27 +16,27 @@
},
"types": {
"customlabel": {
"directoryName": "labels",
"directoryName": "test",
"id": "customlabel",
"ignoreParentName": true,
"name": "CustomLabel",
"suffix": "label",
"isAddressable": false,
"supportsWildcardAndName": true,
"uniqueIdElement": "fullName",
"xmlElementName": "labels"
}
}
},
"strictDirectoryName": true,
"directoryName": "labels",
"id": "customlabels",
"ignoreParsedFullName": true,
"ignoreParsedFullName": false,
"name": "CustomLabels",
"strategies": {
"adapter": "decomposed",
"decomposition": "topLevel",
"transformer": "decomposed"
},
"strictDirectoryName": false,
"suffix": "labels"
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/registry/registryAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sd

export class RegistryAccess {
private registry: MetadataRegistry;

private strictFolderTypes?: MetadataType[];
private folderContentTypes?: MetadataType[];
private aliasTypes?: MetadataType[];
Expand All @@ -27,6 +26,10 @@ export class RegistryAccess {
this.registry = registry ?? getEffectiveRegistry({ projectDir });
}

public getRegistry(): MetadataRegistry {
return this.registry;
}

/**
* Query a metadata type by its name.
*
Expand Down
11 changes: 6 additions & 5 deletions src/resolve/connectionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { PollingClient, StatusResult, Connection, Logger, Messages, Lifecycle, S
import { Duration, ensureArray } from '@salesforce/kit';
import { ensurePlainObject, ensureString, isPlainObject } from '@salesforce/ts-types';
import { RegistryAccess } from '../registry/registryAccess';
import { registry as defaultRegistry } from '../registry/registry';
import { MetadataType } from '../registry/types';
import { standardValueSet } from '../registry/standardvalueset';
import { FileProperties, StdValueSetRecord, ListMetadataQuery } from '../client/types';
Expand Down Expand Up @@ -46,7 +45,7 @@ export class ConnectionResolver {
this.mdTypeNames = mdTypes?.length
? // ensure the types passed in are valid per the registry
mdTypes.filter((t) => this.registry.getTypeByName(t))
: Object.values(defaultRegistry.types).map((t) => t.name);
: Object.values(this.registry.getRegistry().types).map((t) => t.name);
}

public async resolve(
Expand Down Expand Up @@ -161,7 +160,7 @@ export class ConnectionResolver {
}

// Workaround because metadata.list({ type: 'StandardValueSet' }) returns []
if (query.type === defaultRegistry.types.standardvalueset.name && members.length === 0) {
if (query.type === this.registry.getRegistry().types.standardvalueset.name && members.length === 0) {
const standardValueSetPromises = standardValueSet.fullnames.map(async (standardValueSetFullName) => {
try {
// The 'singleRecordQuery' method was having connection errors, using `retry` resolves this
Expand Down Expand Up @@ -189,8 +188,10 @@ export class ConnectionResolver {
return (
standardValueSetRecord.Metadata.standardValue.length && {
fullName: standardValueSetRecord.MasterLabel,
fileName: `${defaultRegistry.types.standardvalueset.directoryName}/${standardValueSetRecord.MasterLabel}.${defaultRegistry.types.standardvalueset.suffix}`,
type: defaultRegistry.types.standardvalueset.name,
fileName: `${this.registry.getRegistry().types.standardvalueset.directoryName}/${
standardValueSetRecord.MasterLabel
}.${this.registry.getRegistry().types.standardvalueset.suffix}`,
type: this.registry.getRegistry().types.standardvalueset.name,
}
);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "variantTest",
"namespace": "",
"packageDirectories": [
{
"default": true,
"path": "force-app"
}
],
"registryPresets": ["decomposeCustomLabelsBeta"],
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "60.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
/* eslint-disable no-await-in-loop */

describe('decomposed custom labels', () => {
const testDir = path.join('test', 'snapshot', 'sampleProjects', 'variant-decomposeLabels');
const testDir = path.join('test', 'snapshot', 'sampleProjects', 'preset-decomposeLabels');
let sourceFiles: string[];
let mdFiles: string[];

Expand Down

This file was deleted.

2 comments on commit 7c055bb

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 7c055bb Previous: d2127a0 Ratio
eda-componentSetCreate-linux 177 ms 180 ms 0.98
eda-sourceToMdapi-linux 2274 ms 1923 ms 1.18
eda-sourceToZip-linux 1390 ms 1413 ms 0.98
eda-mdapiToSource-linux 2610 ms 2822 ms 0.92
lotsOfClasses-componentSetCreate-linux 374 ms 361 ms 1.04
lotsOfClasses-sourceToMdapi-linux 3462 ms 3664 ms 0.94
lotsOfClasses-sourceToZip-linux 3035 ms 3094 ms 0.98
lotsOfClasses-mdapiToSource-linux 3289 ms 3351 ms 0.98
lotsOfClassesOneDir-componentSetCreate-linux 614 ms 630 ms 0.97
lotsOfClassesOneDir-sourceToMdapi-linux 6153 ms 6259 ms 0.98
lotsOfClassesOneDir-sourceToZip-linux 5622 ms 5637 ms 1.00
lotsOfClassesOneDir-mdapiToSource-linux 6011 ms 6046 ms 0.99

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 7c055bb Previous: d2127a0 Ratio
eda-componentSetCreate-win32 418 ms 371 ms 1.13
eda-sourceToMdapi-win32 3775 ms 3474 ms 1.09
eda-sourceToZip-win32 2387 ms 2164 ms 1.10
eda-mdapiToSource-win32 6177 ms 5677 ms 1.09
lotsOfClasses-componentSetCreate-win32 917 ms 850 ms 1.08
lotsOfClasses-sourceToMdapi-win32 8013 ms 7290 ms 1.10
lotsOfClasses-sourceToZip-win32 5180 ms 4702 ms 1.10
lotsOfClasses-mdapiToSource-win32 7550 ms 7130 ms 1.06
lotsOfClassesOneDir-componentSetCreate-win32 1479 ms 1470 ms 1.01
lotsOfClassesOneDir-sourceToMdapi-win32 13376 ms 13343 ms 1.00
lotsOfClassesOneDir-sourceToZip-win32 8662 ms 8635 ms 1.00
lotsOfClassesOneDir-mdapiToSource-win32 13187 ms 13210 ms 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.