Skip to content

Commit

Permalink
chore: temp
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Jan 21, 2025
1 parent f5d552b commit bf8b269
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,47 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { join } from 'node:path';
import type { ExternalServiceRegistration } from '@jsforce/jsforce-node/lib/api/metadata/schema';
import { ensure, ensureString } from '@salesforce/ts-types';
import { WriterFormat } from '../types';
import { MetadataType } from '../../registry';
import { WriteInfo } from '../types';
import { SourceComponent } from '../../resolve';
import { JsToXml } from '../streams';
import { ConvertTransactionFinalizer } from './transactionFinalizer';

type ExternalServiceRegistrationState = {
esrRecords: Array<{ component: SourceComponent; writeInfos: WriteInfo[] }>;
esrRecords: Map<string, ExternalServiceRegistration>;
};

export class DecomposedExternalServiceRegistrationFinalizer extends ConvertTransactionFinalizer<ExternalServiceRegistrationState> {
/** to support custom presets (the only way this code should get hit at all pass in the type from a transformer that has registry access */
public externalServiceRegistration?: MetadataType;
public transactionState: ExternalServiceRegistrationState = {
esrRecords: [],
esrRecords: new Map<string, ExternalServiceRegistration>(),
};
// eslint-disable-next-line class-methods-use-this
public defaultDir: string | undefined;

public finalize(defaultDirectory: string | undefined): Promise<WriterFormat[]> {
this.defaultDir = defaultDirectory;
const writerFormats: WriterFormat[] = this.transactionState.esrRecords.map((esrRecord) => {
const { component, writeInfos } = esrRecord;
const fullName = component.fullName ?? '';
const outputDir = this.defaultDir ? this.defaultDir : '';
const esrFileName = `${fullName}.externalServiceRegistration`;
const esrFilePath = `${outputDir}/${esrFileName}`;
return { component, writeInfos, output: esrFilePath };
});
const writerFormats: WriterFormat[] = [];
this.transactionState.esrRecords.forEach((esrRecord, parent) =>
writerFormats.push({
component: {
type: ensure(this.externalServiceRegistration, 'DecomposedESRFinalizer should have set .ESR'),
fullName: ensureString(parent),
},
writeInfos: [
{
output: join(
ensure(this.externalServiceRegistration?.directoryName, 'directory name missing'),
`${parent}.externalServiceRegistration`
),
source: new JsToXml({ ExternalServiceRegistration: { ...esrRecord } }),
},
],
})
);
return Promise.resolve(writerFormats);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { ExternalServiceRegistration } from '@jsforce/jsforce-node/lib/api/
import { JsonMap } from '@salesforce/ts-types';
import { WriteInfo } from '../types';
import { SourceComponent } from '../../resolve';
import { DEFAULT_PACKAGE_ROOT_SFDX, META_XML_SUFFIX } from '../../common';
import { DEFAULT_PACKAGE_ROOT_SFDX, META_XML_SUFFIX, XML_DECL, XML_NS_KEY } from '../../common';
import { BaseMetadataTransformer } from './baseMetadataTransformer';

type ESR = JsonMap & {
Expand Down Expand Up @@ -80,7 +80,6 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
// only need to do this once
this.context.decomposedExternalServiceRegistration.externalServiceRegistration ??=
this.registry.getTypeByName('ExternalServiceRegistration');
const writeInfos: WriteInfo[] = [];
const esrFilePath = component.xml;
const esrContent = { ...(await component.parseXml<ESR>()).ExternalServiceRegistration };

Expand All @@ -89,29 +88,15 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat
const schemaFilePath = path.join(path.dirname(esrFilePath ?? ''), schemaFileName);
// Add schema content back to ESR content
esrContent.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 = xmlBuilder.build({ ExternalServiceRegistration: esrContent });
// Write combined content back to md format
writeInfos.push({
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-assignment
source: Readable.from(Buffer.from(xmlDeclaration + source)),
output: path.resolve(esrMdApiFilePath),

this.context.decomposedExternalServiceRegistration.transactionState.esrRecords.set(component.fullName, {
// @ts-expect-error abdc
[XML_NS_KEY]: XML_DECL,
...esrContent,
});
this.context.decomposedExternalServiceRegistration.transactionState.esrRecords.push({ component, writeInfos });

return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<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 @@ -5,7 +5,6 @@
<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 @@ -5,7 +5,6 @@
<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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ paths:
</schema>
<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>

2 comments on commit bf8b269

@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: bf8b269 Previous: f5d552b Ratio
eda-componentSetCreate-linux 215 ms 211 ms 1.02
eda-sourceToMdapi-linux 1983 ms 1910 ms 1.04
eda-sourceToZip-linux 1766 ms 1699 ms 1.04
eda-mdapiToSource-linux 2664 ms 2616 ms 1.02
lotsOfClasses-componentSetCreate-linux 435 ms 420 ms 1.04
lotsOfClasses-sourceToMdapi-linux 3579 ms 4043 ms 0.89
lotsOfClasses-sourceToZip-linux 2949 ms 2843 ms 1.04
lotsOfClasses-mdapiToSource-linux 3503 ms 3469 ms 1.01
lotsOfClassesOneDir-componentSetCreate-linux 737 ms 718 ms 1.03
lotsOfClassesOneDir-sourceToMdapi-linux 6292 ms 6274 ms 1.00
lotsOfClassesOneDir-sourceToZip-linux 5040 ms 4888 ms 1.03
lotsOfClassesOneDir-mdapiToSource-linux 6271 ms 6111 ms 1.03

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: bf8b269 Previous: f5d552b Ratio
eda-componentSetCreate-win32 646 ms 707 ms 0.91
eda-sourceToMdapi-win32 3909 ms 4082 ms 0.96
eda-sourceToZip-win32 3001 ms 3112 ms 0.96
eda-mdapiToSource-win32 5879 ms 6014 ms 0.98
lotsOfClasses-componentSetCreate-win32 1307 ms 1367 ms 0.96
lotsOfClasses-sourceToMdapi-win32 8077 ms 8360 ms 0.97
lotsOfClasses-sourceToZip-win32 4915 ms 5029 ms 0.98
lotsOfClasses-mdapiToSource-win32 8041 ms 8366 ms 0.96
lotsOfClassesOneDir-componentSetCreate-win32 2301 ms 2372 ms 0.97
lotsOfClassesOneDir-sourceToMdapi-win32 13347 ms 14798 ms 0.90
lotsOfClassesOneDir-sourceToZip-win32 8292 ms 9373 ms 0.88
lotsOfClassesOneDir-mdapiToSource-win32 13443 ms 14888 ms 0.90

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

Please sign in to comment.