-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ccca40
commit c5d5b3d
Showing
16 changed files
with
444 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/convert/convertContext/decomposedExternalServiceRegistrationFinalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* 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 { WriterFormat } from '../types'; | ||
import { MetadataType } from '../../registry'; | ||
import { ConvertTransactionFinalizer } from './transactionFinalizer'; | ||
|
||
type ExternalServiceRegistration = unknown; | ||
|
||
export class DecomposedExternalServiceRegistrationFinalizer extends ConvertTransactionFinalizer<ExternalServiceRegistration> { | ||
/** 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; | ||
protected transactionState: ExternalServiceRegistration; | ||
// eslint-disable-next-line class-methods-use-this | ||
protected defaultDir: string | undefined; | ||
|
||
public finalize(defaultDirectory: string | undefined): Promise<WriterFormat[]> { | ||
this.defaultDir = defaultDirectory; | ||
return Promise.resolve([]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) 2024, salesforce.com, inc. | ||
* All rights reserved. | ||
* 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 * as fs from 'node:fs/promises'; | ||
// import * as path from 'node:path'; | ||
// import { Readable } from 'node:stream'; | ||
// import { XMLParser, XMLBuilder } from 'fast-xml-parser'; | ||
import * as yaml from 'yaml'; | ||
import { JsonMap } from '@salesforce/ts-types'; | ||
import { WriteInfo } from '../types'; | ||
import { SourceComponent } from '../../resolve'; | ||
import { BaseMetadataTransformer } from './baseMetadataTransformer'; | ||
|
||
export type ESR = JsonMap & { | ||
ExternalServiceRegistration: { | ||
schema?: { | ||
_text: string; | ||
}; | ||
}; | ||
}; | ||
|
||
export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadataTransformer { | ||
// private xmlParser = new XMLParser({ ignoreAttributes: false }); | ||
// private xmlBuilder = new XMLBuilder({ ignoreAttributes: false }); | ||
|
||
// 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; | ||
}): Promise<WriteInfo[]> { | ||
const writeInfos: WriteInfo[] = []; | ||
// const { component, mergeWith } = input; | ||
// const xmlContent = await component.parseXml<ESR>(); | ||
// const esrContent = xmlContent.ExternalServiceRegistration; | ||
// | ||
// // Extract schema content | ||
// // eslint-disable-next-line no-underscore-dangle | ||
// const schemaContent = esrContent.schema?._text ?? ''; | ||
// const schemaExtension = this.getSchemaExtension(schemaContent); | ||
// const schemaFileName = `${component.fullName}.schema.${schemaExtension}`; | ||
// const schemaFilePath = path.join(this.defaultDirectory ?? '', schemaFileName); | ||
// | ||
// // Write schema content to file | ||
// writeInfos.push({ | ||
// source: Readable.from(schemaContent), | ||
// output: schemaFilePath | ||
// }); | ||
// | ||
// // Remove schema content from ESR content | ||
// delete esrContent.schema; | ||
// | ||
// // Write remaining ESR content to file | ||
// const esrFileName = `${component.fullName}.externalServiceRegistration`; | ||
// const esrFilePath = path.join(this.defaultDirectory ?? '', esrFileName); | ||
// writeInfos.push({ | ||
// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
// source: this.xmlBuilder.build({ ExternalServiceRegistration: esrContent }), | ||
// output: esrFilePath | ||
// }); | ||
|
||
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 ??= | ||
this.registry.getTypeByName('ExternalServiceRegistration'); | ||
const writeInfos: WriteInfo[] = []; | ||
// const esrFilePath = this.getOutputFile(component); | ||
// const esrContent = await fs.readFile(esrFilePath, 'utf8'); | ||
// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
// 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 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 }; | ||
// | ||
// // 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 | ||
// }); | ||
|
||
return writeInfos; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
protected getOutputFile(component: SourceComponent, mergeWith?: SourceComponent): string { | ||
if (mergeWith?.xml) { | ||
return mergeWith.xml; | ||
} | ||
return component.xml ?? ''; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
protected getSchemaExtension(content: string): string { | ||
try { | ||
yaml.parse(content); | ||
return 'yaml'; | ||
} catch { | ||
return 'json'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/registry/presets/decomposeExternalServiceRegistration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"types": { | ||
"externalserviceregistration": { | ||
"children": { | ||
"types": { | ||
"schema": { | ||
"directoryName": "externalServiceRegistrations", | ||
"id": "schema", | ||
"isAddressable": false, | ||
"name": "Schema", | ||
"suffix": "schema", | ||
"xmlElementName": "schema" | ||
} | ||
}, | ||
"suffixes": { | ||
"schema": "schema" | ||
} | ||
}, | ||
"directoryName": "externalServiceRegistrations", | ||
"id": "externalserviceregistration", | ||
"ignoreParsedFullName": false, | ||
"name": "ExternalServiceRegistration", | ||
"strategies": { | ||
"adapter": "decomposed", | ||
"decomposition": "topLevel", | ||
"transformer": "decomposeExternalServiceRegistration" | ||
}, | ||
"strictDirectoryName": true, | ||
"suffix": "externalServiceRegistration", | ||
"supportsPartialDelete": true | ||
} | ||
}, | ||
"suffixes": { | ||
"schema": "schema", | ||
"externalServiceRegistration": "externalserviceregistration" | ||
}, | ||
"strictDirectoryNames": { | ||
"externalServiceRegistrations": "externalserviceregistration" | ||
}, | ||
"childTypes": { | ||
"schema": "externalserviceregistration" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
test/convert/transformers/decomposedExternalServiceRegistration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* 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 { expect } from 'chai'; | ||
import { RegistryAccess } from '../../../src'; | ||
import { getEffectiveRegistry } from '../../../src/registry/variants'; | ||
import { presetMap } from '../../../src'; | ||
import { MD_FORMAT_ESR, SOURCE_FORMAT_ESR } from '../../mock/type-constants/decomposeExternalServiceRegistration'; | ||
import { DecomposeExternalServiceRegistrationTransformer } from '../../../src/convert/transformers/decomposeExternalServiceRegistrationTransformer'; | ||
|
||
describe('DecomposeExternalServiceRegistrationTransformer', () => { | ||
const preset = presetMap.get('decomposeExternalServiceRegistration'); | ||
const regAcc = new RegistryAccess(getEffectiveRegistry({ presets: [preset!] })); | ||
|
||
describe('toSourceFormat', () => { | ||
describe('WriteInfo output (where the file will write to)', () => { | ||
it('write yaml file and meta.xml', async () => { | ||
const component = MD_FORMAT_ESR; | ||
const xf = new DecomposeExternalServiceRegistrationTransformer(regAcc); | ||
const result = await xf.toSourceFormat({ component }); | ||
expect(result).to.have.length(1); | ||
result.map((l) => { | ||
expect(l.output).to.include(join('main', 'default', 'externalServiceRegistrations')); | ||
}); | ||
expect(result[0].output).to.match(/myESR.externalServiceRegistrations-meta.xml$/); | ||
expect(result[1].output).to.match(/myESR.schema.yaml$/); | ||
}); | ||
|
||
it('merge component in defaultDir', async () => { | ||
const component = MD_FORMAT_ESR; | ||
const xf = new DecomposeExternalServiceRegistrationTransformer(regAcc); | ||
const result = await xf.toSourceFormat({ | ||
component, | ||
mergeWith: SOURCE_FORMAT_ESR, | ||
}); | ||
expect(result).to.have.length(5); | ||
expect(result[4].output).to.equal(SOURCE_FORMAT_ESR.xml); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('toMetadataFormat', () => { | ||
it('decomposed ESR combined to md-format', async () => { | ||
const component = SOURCE_FORMAT_ESR; | ||
const xf = new DecomposeExternalServiceRegistrationTransformer(regAcc); | ||
const result = await xf.toMetadataFormat(component); | ||
expect(result).to.deep.equal([]); | ||
expect(xf.context.decomposedPermissionSet.permissionSetType).to.equal(regAcc.getTypeByName('PermissionSet')); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
c5d5b3d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
eda-componentSetCreate-linux
209
ms212
ms0.99
eda-sourceToMdapi-linux
1923
ms1954
ms0.98
eda-sourceToZip-linux
1714
ms1697
ms1.01
eda-mdapiToSource-linux
2618
ms3703
ms0.71
lotsOfClasses-componentSetCreate-linux
419
ms430
ms0.97
lotsOfClasses-sourceToMdapi-linux
3550
ms3531
ms1.01
lotsOfClasses-sourceToZip-linux
2849
ms2855
ms1.00
lotsOfClasses-mdapiToSource-linux
3380
ms3438
ms0.98
lotsOfClassesOneDir-componentSetCreate-linux
716
ms738
ms0.97
lotsOfClassesOneDir-sourceToMdapi-linux
6163
ms6241
ms0.99
lotsOfClassesOneDir-sourceToZip-linux
4812
ms4885
ms0.99
lotsOfClassesOneDir-mdapiToSource-linux
6067
ms6123
ms0.99
This comment was automatically generated by workflow using github-action-benchmark.
c5d5b3d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
eda-componentSetCreate-win32
622
ms699
ms0.89
eda-sourceToMdapi-win32
3690
ms4049
ms0.91
eda-sourceToZip-win32
2842
ms3130
ms0.91
eda-mdapiToSource-win32
5546
ms6129
ms0.90
lotsOfClasses-componentSetCreate-win32
1246
ms1243
ms1.00
lotsOfClasses-sourceToMdapi-win32
7802
ms7562
ms1.03
lotsOfClasses-sourceToZip-win32
5048
ms4766
ms1.06
lotsOfClasses-mdapiToSource-win32
7694
ms7665
ms1.00
lotsOfClassesOneDir-componentSetCreate-win32
2145
ms2084
ms1.03
lotsOfClassesOneDir-sourceToMdapi-win32
13721
ms13442
ms1.02
lotsOfClassesOneDir-sourceToZip-win32
9224
ms8570
ms1.08
lotsOfClassesOneDir-mdapiToSource-win32
13821
ms13513
ms1.02
This comment was automatically generated by workflow using github-action-benchmark.