Skip to content

Commit

Permalink
chore: encoded in MD, chars in SD
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Jan 13, 2025
1 parent 5f64455 commit b100e30
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ export type ESR = JsonMap & {
};

export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadataTransformer {
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: {
component: SourceComponent;
Expand Down Expand Up @@ -76,9 +64,16 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
component.type.directoryName,
`${esrFileName}-meta.xml`
);
const xmlBuilder = new XMLBuilder({
format: true,
ignoreAttributes: false,
suppressUnpairedNode: true,
processEntities: false,
indentBy: ' ',
});
writeInfos.push({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
source: this.xmlBuilder.build({ ExternalServiceRegistration: esrContent }),
source: xmlBuilder.build({ ExternalServiceRegistration: esrContent }),
output: esrFilePath,
});

Expand All @@ -93,25 +88,34 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
const writeInfos: WriteInfo[] = [];
const esrFilePath = this.getOutputFile(component);
const esrContent = await fs.readFile(esrFilePath, 'utf8');
const xmlParser = new XMLParser({
ignoreAttributes: false,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const esrXml = this.xmlParser.parse(esrContent);
const esrXml = xmlParser.parse(esrContent);

// Read schema content from file
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'] = schemaContent;
esrXml.ExternalServiceRegistration['schema'] = await fs.readFile(schemaFilePath, 'utf8');
const esrMdApiFilePath = `${path.join(
this.defaultDirectory ?? '',
component.type.directoryName,
component.fullName
)}.externalServiceRegistration`;

const xmlBuilder = new XMLBuilder({
format: true,
ignoreAttributes: false,
suppressUnpairedNode: true,
processEntities: true,
indentBy: ' ',
});

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

// Write combined content back to source format
writeInfos.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<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>
<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>
<schema>openapi: 3.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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>{"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}}</serviceBinding>
<status>Complete</status>
<systemVersion>3</systemVersion>
</ExternalServiceRegistration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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: {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<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>
<serviceBinding>{"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}}</serviceBinding>
<status>Complete</status>
<systemVersion>3</systemVersion>
</ExternalServiceRegistration>
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>{&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>
<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>

2 comments on commit b100e30

@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: b100e30 Previous: 40af18e Ratio
eda-componentSetCreate-linux 215 ms 225 ms 0.96
eda-sourceToMdapi-linux 2001 ms 2057 ms 0.97
eda-sourceToZip-linux 1812 ms 1920 ms 0.94
eda-mdapiToSource-linux 2770 ms 2675 ms 1.04
lotsOfClasses-componentSetCreate-linux 436 ms 472 ms 0.92
lotsOfClasses-sourceToMdapi-linux 4077 ms 3637 ms 1.12
lotsOfClasses-sourceToZip-linux 2924 ms 2900 ms 1.01
lotsOfClasses-mdapiToSource-linux 3445 ms 3465 ms 0.99
lotsOfClassesOneDir-componentSetCreate-linux 736 ms 839 ms 0.88
lotsOfClassesOneDir-sourceToMdapi-linux 6362 ms 6362 ms 1
lotsOfClassesOneDir-sourceToZip-linux 5105 ms 5190 ms 0.98
lotsOfClassesOneDir-mdapiToSource-linux 6258 ms 6279 ms 1.00

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: b100e30 Previous: 40af18e Ratio
eda-componentSetCreate-win32 657 ms 716 ms 0.92
eda-sourceToMdapi-win32 3903 ms 4192 ms 0.93
eda-sourceToZip-win32 2964 ms 3259 ms 0.91
eda-mdapiToSource-win32 5751 ms 5914 ms 0.97
lotsOfClasses-componentSetCreate-win32 1280 ms 1381 ms 0.93
lotsOfClasses-sourceToMdapi-win32 7977 ms 8117 ms 0.98
lotsOfClasses-sourceToZip-win32 4973 ms 5037 ms 0.99
lotsOfClasses-mdapiToSource-win32 7781 ms 7985 ms 0.97
lotsOfClassesOneDir-componentSetCreate-win32 2204 ms 2444 ms 0.90
lotsOfClassesOneDir-sourceToMdapi-win32 14026 ms 14548 ms 0.96
lotsOfClassesOneDir-sourceToZip-win32 9113 ms 9238 ms 0.99
lotsOfClassesOneDir-mdapiToSource-win32 13987 ms 14650 ms 0.95

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

Please sign in to comment.