Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
peternhale committed Jan 9, 2025
1 parent 484663a commit 5f64455
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ export type ESR = JsonMap & {
};

export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadataTransformer {
private xmlParser = new XMLParser({ ignoreAttributes: false });
private xmlBuilder = new XMLBuilder({ ignoreAttributes: false });
private xmlParser = new XMLParser({
ignoreAttributes: false,
processEntities: false, // Disable automatic decoding of entities
});
private xmlBuilder = new XMLBuilder({
format: true,
ignoreAttributes: false,
suppressUnpairedNode: true,
processEntities: true,
indentBy: ' ',
});

// eslint-disable-next-line @typescript-eslint/require-await,class-methods-use-this,@typescript-eslint/no-unused-vars
public async toSourceFormat(input: {
Expand Down Expand Up @@ -88,19 +97,27 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
const esrXml = this.xmlParser.parse(esrContent);

// Read schema content from file
const schemaFileName = `${component.fullName}.schema.yaml`; // or .json based on your logic
const schemaFilePath = path.join(this.defaultDirectory ?? '', schemaFileName);
const schemaFileName = `${component.fullName}.yaml`; // or .json based on your logic
const schemaFilePath = path.join(path.dirname(esrFilePath) ?? '', schemaFileName);
const schemaContent = await fs.readFile(schemaFilePath, 'utf8');

// Add schema content back to ESR content
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
esrXml.ExternalServiceRegistration.schema = { _text: schemaContent };
esrXml.ExternalServiceRegistration['schema'] = schemaContent;
const esrMdApiFilePath = `${path.join(
this.defaultDirectory ?? '',
component.type.directoryName,
component.fullName
)}.externalServiceRegistration`;

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const source = this.xmlBuilder.build(esrXml);

// Write combined content back to source format
writeInfos.push({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
source: this.xmlBuilder.build(esrXml),
output: esrFilePath,
source,
output: path.resolve(esrMdApiFilePath),
});

return writeInfos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@
"decomposition": "topLevel",
"transformer": "decomposeExternalServiceRegistration"
},
"strictDirectoryName": true,
"suffix": "externalServiceRegistration",
"supportsPartialDelete": true
"supportsPartialDelete": false
}
},
"suffixes": {
"yaml": "yaml",
"externalServiceRegistration": "externalserviceregistration"
},
"strictDirectoryNames": {
"externalServiceRegistrations": "externalserviceregistration"
},
"strictDirectoryNames": {},
"childTypes": {
"yaml": "externalserviceregistration"
}
Expand Down
7 changes: 5 additions & 2 deletions test/snapshot/helper/conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ export const sourceToMdapi = async (testDir: string): Promise<string[]> => {
};

/** checks that the two xml bodies have the same equivalent json (handles out-of-order things, etc) */
export const compareTwoXml = (file1: string, file2: string): Chai.Assertion =>
expect(parser.parse(file1)).to.deep.equalInAnyOrder(parser.parse(file2));
export const compareTwoXml = (file1: string, file2: string): Chai.Assertion => {
const f1doc = parser.parse(file1);
const f2doc = parser.parse(file2);
return expect(f1doc).to.deep.equalInAnyOrder(f2doc);
};

/**
* catches missing files by asserting that two directories have the exact same children
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata">
<label>BankService</label>
<namedCredential>ntest</namedCredential>
<registrationProviderType>Custom</registrationProviderType>
<schemaType>OpenApi3</schemaType>
<schemaUrl>/accounts/schema</schemaUrl>
<serviceBinding>{&amp;quot;host&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;basePath&amp;quot;:&amp;quot;/&amp;quot;,&amp;quot;allowedSchemes&amp;quot;:[],&amp;quot;requestMediaTypes&amp;quot;:[],&amp;quot;responseMediaTypes&amp;quot;:[],&amp;quot;compatibleMediaTypes&amp;quot;:{}}</serviceBinding>
<status>Complete</status>
<systemVersion>3</systemVersion>
<schema>openapi: 3.0.0
info:
title: OpenAPIChallenge
description: Now is the time for Apex OpenAPI
version: 63.1.0
paths:
/getAccountSummaryWithOpportunities:
operations:
get:
summary: need to figure out what this means
description: need to figure out what this means
operationId: getAccountSummaryWithOpportunities
responses: {}
/getActiveCases:
operations:
get:
summary: need to figure out what this means
description: need to figure out what this means
operationId: getActiveCases
responses: {}
/getAllAccounts:
operations:
get:
summary: need to figure out what this means
description: need to figure out what this means
operationId: getAllAccounts
responses: {}
/getUserDetails:
operations:
get:
summary: need to figure out what this means
description: need to figure out what this means
operationId: getUserDetails
responses: {}
/updateContactDetails:
operations:
get:
summary: need to figure out what this means
description: need to figure out what this means
operationId: updateContactDetails
responses: {}
/getWelcomeMessage:
operations:
get:
summary: need to figure out what this means
description: need to figure out what this means
operationId: getWelcomeMessage
responses: {}</schema>
</ExternalServiceRegistration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>OpenAPIChallenge</members>
<name>ExternalServiceRegistration</name>
</types>
<version>60.0</version>
</Package>
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata"><label>BankService</label><namedCredential>ntest</namedCredential><registrationProviderType>Custom</registrationProviderType><schemaType>OpenApi3</schemaType><schemaUrl>/accounts/schema</schemaUrl><serviceBinding>{&quot;host&quot;:&quot;&quot;,&quot;basePath&quot;:&quot;/&quot;,&quot;allowedSchemes&quot;:[],&quot;requestMediaTypes&quot;:[],&quot;responseMediaTypes&quot;:[],&quot;compatibleMediaTypes&quot;:{}}</serviceBinding><status>Complete</status><systemVersion>3</systemVersion></ExternalServiceRegistration>
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata">
<label>BankService</label>
<namedCredential>ntest</namedCredential>
<registrationProviderType>Custom</registrationProviderType>
<schemaType>OpenApi3</schemaType>
<schemaUrl>/accounts/schema</schemaUrl>
<serviceBinding>{&quot;host&quot;:&quot;&quot;,&quot;basePath&quot;:&quot;/&quot;,&quot;allowedSchemes&quot;:[],&quot;requestMediaTypes&quot;:[],&quot;responseMediaTypes&quot;:[],&quot;compatibleMediaTypes&quot;:{}}</serviceBinding>
<status>Complete</status>
<systemVersion>3</systemVersion>
</ExternalServiceRegistration>
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('fully decomposed external service registration via decomposeExternalSe
await fileSnap(file, testDir);
}
await dirsAreIdentical(
path.join(testDir, 'force-app'),
path.join(testDir, '__snapshots__', 'verify-md-files.expected', 'force-app')
path.join(testDir, 'mdapiOutput'),
path.join(testDir, '__snapshots__', 'verify-md-files.expected')
);
});
it('round trip of metadata format is equivalent', async () => {
Expand Down

2 comments on commit 5f64455

@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: 5f64455 Previous: f9b2ab5 Ratio
eda-componentSetCreate-linux 211 ms 211 ms 1
eda-sourceToMdapi-linux 1952 ms 1908 ms 1.02
eda-sourceToZip-linux 1801 ms 1700 ms 1.06
eda-mdapiToSource-linux 3457 ms 2587 ms 1.34
lotsOfClasses-componentSetCreate-linux 429 ms 415 ms 1.03
lotsOfClasses-sourceToMdapi-linux 3594 ms 3589 ms 1.00
lotsOfClasses-sourceToZip-linux 2864 ms 2722 ms 1.05
lotsOfClasses-mdapiToSource-linux 3446 ms 3379 ms 1.02
lotsOfClassesOneDir-componentSetCreate-linux 741 ms 740 ms 1.00
lotsOfClassesOneDir-sourceToMdapi-linux 6275 ms 6227 ms 1.01
lotsOfClassesOneDir-sourceToZip-linux 4944 ms 4983 ms 0.99
lotsOfClassesOneDir-mdapiToSource-linux 6141 ms 6088 ms 1.01

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: 5f64455 Previous: f9b2ab5 Ratio
eda-componentSetCreate-win32 895 ms 698 ms 1.28
eda-sourceToMdapi-win32 5105 ms 4061 ms 1.26
eda-sourceToZip-win32 3851 ms 3115 ms 1.24
eda-mdapiToSource-win32 7408 ms 6177 ms 1.20
lotsOfClasses-componentSetCreate-win32 1818 ms 1338 ms 1.36
lotsOfClasses-sourceToMdapi-win32 12397 ms 8430 ms 1.47
lotsOfClasses-sourceToZip-win32 7189 ms 5314 ms 1.35
lotsOfClasses-mdapiToSource-win32 11002 ms 8222 ms 1.34
lotsOfClassesOneDir-componentSetCreate-win32 2997 ms 2127 ms 1.41
lotsOfClassesOneDir-sourceToMdapi-win32 17689 ms 13607 ms 1.30
lotsOfClassesOneDir-sourceToZip-win32 10522 ms 8636 ms 1.22
lotsOfClassesOneDir-mdapiToSource-win32 18737 ms 13755 ms 1.36

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

Please sign in to comment.