Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
peternhale committed Jan 22, 2025
1 parent aa5599f commit 995d97c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type ESR = JsonMap & {
const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8"?>\n';

export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadataTransformer {
// eslint-disable-next-line @typescript-eslint/require-await,class-methods-use-this,@typescript-eslint/no-unused-vars
public async toSourceFormat(input: {
component: SourceComponent;
mergeWith?: SourceComponent | undefined;
Expand Down Expand Up @@ -75,7 +74,6 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
return writeInfos;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/require-await
public async toMetadataFormat(component: SourceComponent): Promise<WriteInfo[]> {
// only need to do this once
this.context.decomposedExternalServiceRegistration.externalServiceRegistration ??=
Expand All @@ -87,21 +85,24 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
const schemaFileName = `${component.fullName}.yaml`; // or .json based on your logic
const schemaFilePath = path.join(path.dirname(esrFilePath ?? ''), schemaFileName);
// Add schema content back to ESR content
esrContent.schema = await fs.readFile(schemaFilePath, 'utf8');
esrContent.schema = await this.readSchemaFile(schemaFilePath);

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
// Write combined content back to md format

this.context.decomposedExternalServiceRegistration.transactionState.esrRecords.set(component.fullName, {
// @ts-expect-error abdc
// @ts-expect-error Object literal may only specify known properties
[XML_NS_KEY]: XML_DECL,
...esrContent,
});

return [];
}

// eslint-disable-next-line class-methods-use-this,@typescript-eslint/no-unused-vars
// eslint-disable-next-line class-methods-use-this
public readSchemaFile(schemaFilePath: string): Promise<string> {
return fs.readFile(schemaFilePath, 'utf8');
}

// eslint-disable-next-line class-methods-use-this
private getOutputFolder(format: string, component: SourceComponent, mergeWith?: SourceComponent): string {
const base = format === 'source' ? DEFAULT_PACKAGE_ROOT_SFDX : '';
const { type } = mergeWith ?? component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
*/
import { join } from 'node:path';
import { expect } from 'chai';
import { RegistryAccess } from '../../../src';
import { createSandbox } from 'sinon';
import { RegistryAccess, VirtualTreeContainer } from '../../../src';
import { getEffectiveRegistry } from '../../../src/registry/variants';
import { presetMap } from '../../../src';
import {
MD_FORMAT_ESR,
SAMPLE_OAS_DOC,
SOURCE_FORMAT_ESR,
} from '../../mock/type-constants/decomposeExternalServiceRegistrationConstants';
import { DecomposeExternalServiceRegistrationTransformer } from '../../../src/convert/transformers/decomposeExternalServiceRegistrationTransformer';
Expand Down Expand Up @@ -46,6 +48,19 @@ describe('DecomposeExternalServiceRegistrationTransformer', () => {
});

describe('toMetadataFormat', () => {
const sandbox = createSandbox();

beforeEach(() => {
sandbox.stub(VirtualTreeContainer.prototype, 'readFileSync').returns(Buffer.from(SAMPLE_OAS_DOC));
sandbox
.stub(DecomposeExternalServiceRegistrationTransformer.prototype, 'readSchemaFile')
.resolves(SAMPLE_OAS_DOC);
});

afterEach(() => {
sandbox.restore();
});

it('decomposed ESR combined to md-format', async () => {
const component = SOURCE_FORMAT_ESR;
const xf = new DecomposeExternalServiceRegistrationTransformer(regAcc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,7 @@ const externalServiceRegistration = regAcc.getTypeByName('ExternalServiceRegistr
const MDAPI_XML_NAME = 'myESR.externalServiceRegistration';
const SOURCE_XML_NAME = 'myESR.externalServiceRegistration-meta.xml';

export const MD_FORMAT_ESR = new SourceComponent(
{
name: 'myESR',
type: externalServiceRegistration,
xml: join('externalServiceRegistrations', MDAPI_XML_NAME),
},
new VirtualTreeContainer([
{
dirPath: 'externalServiceRegistrations',
children: [
{
name: MDAPI_XML_NAME,
data: Buffer.from(`<?xml version="1.0" encoding="UTF-8"?>
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata">
<description>external service</description>
<label>OpenAPIChallenge</label>
<namedCredentialReference>ncred</namedCredentialReference>
<registrationProviderType>Custom</registrationProviderType>
<schema>openapi: 3.0.0
export const SAMPLE_OAS_DOC = `openapi: 3.0.0
info:
title: OpenAPIChallenge
description: Now is the time for Apex OpenAPI
Expand Down Expand Up @@ -82,7 +64,28 @@ paths:
description: need to figure out what this means
operationId: getWelcomeMessage
responses: {}
</schema>
`;

export const MD_FORMAT_ESR = new SourceComponent(
{
name: 'myESR',
type: externalServiceRegistration,
xml: join('externalServiceRegistrations', MDAPI_XML_NAME),
},
new VirtualTreeContainer([
{
dirPath: 'externalServiceRegistrations',
children: [
{
name: MDAPI_XML_NAME,
data: Buffer.from(`<?xml version="1.0" encoding="UTF-8"?>
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata">
<description>external service</description>
<label>OpenAPIChallenge</label>
<namedCredentialReference>ncred</namedCredentialReference>
<registrationProviderType>Custom</registrationProviderType>
<schema>${SAMPLE_OAS_DOC}
</schema>
<schemaType>OpenApi3</schemaType>
<schemaUploadFileExtension>yaml</schemaUploadFileExtension>
<schemaUploadFileName>OpenAPIChallenge</schemaUploadFileName>
Expand All @@ -102,7 +105,7 @@ export const SOURCE_FORMAT_ESR = new SourceComponent(
{
name: 'myESR',
type: externalServiceRegistration,
xml: join('externalServiceRegistrations', SOURCE_XML_NAME),
xml: join('main', 'default', 'externalServiceRegistrations', SOURCE_XML_NAME),
},
new VirtualTreeContainer([
{
Expand All @@ -128,55 +131,7 @@ export const SOURCE_FORMAT_ESR = new SourceComponent(
},
{
name: 'myESR.yaml',
data: Buffer.from(`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: {}
`),
data: Buffer.from(SAMPLE_OAS_DOC),
},
],
},
Expand Down

2 comments on commit 995d97c

@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: 995d97c Previous: fbd0528 Ratio
eda-componentSetCreate-linux 223 ms 223 ms 1
eda-sourceToMdapi-linux 2079 ms 1975 ms 1.05
eda-sourceToZip-linux 1894 ms 1717 ms 1.10
eda-mdapiToSource-linux 2699 ms 2614 ms 1.03
lotsOfClasses-componentSetCreate-linux 508 ms 414 ms 1.23
lotsOfClasses-sourceToMdapi-linux 3725 ms 3508 ms 1.06
lotsOfClasses-sourceToZip-linux 2945 ms 2869 ms 1.03
lotsOfClasses-mdapiToSource-linux 3598 ms 3364 ms 1.07
lotsOfClassesOneDir-componentSetCreate-linux 921 ms 728 ms 1.27
lotsOfClassesOneDir-sourceToMdapi-linux 6682 ms 6181 ms 1.08
lotsOfClassesOneDir-sourceToZip-linux 5148 ms 4906 ms 1.05
lotsOfClassesOneDir-mdapiToSource-linux 6327 ms 6035 ms 1.05

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: 995d97c Previous: fbd0528 Ratio
eda-componentSetCreate-win32 685 ms 662 ms 1.03
eda-sourceToMdapi-win32 4145 ms 3964 ms 1.05
eda-sourceToZip-win32 3283 ms 3094 ms 1.06
eda-mdapiToSource-win32 6106 ms 6010 ms 1.02
lotsOfClasses-componentSetCreate-win32 1409 ms 1221 ms 1.15
lotsOfClasses-sourceToMdapi-win32 8204 ms 7574 ms 1.08
lotsOfClasses-sourceToZip-win32 5351 ms 4845 ms 1.10
lotsOfClasses-mdapiToSource-win32 8256 ms 7412 ms 1.11
lotsOfClassesOneDir-componentSetCreate-win32 2478 ms 2120 ms 1.17
lotsOfClassesOneDir-sourceToMdapi-win32 14830 ms 13291 ms 1.12
lotsOfClassesOneDir-sourceToZip-win32 9416 ms 8453 ms 1.11
lotsOfClassesOneDir-mdapiToSource-win32 15057 ms 13806 ms 1.09

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

Please sign in to comment.