-
Notifications
You must be signed in to change notification settings - Fork 145
feat: add decomposition preset for external service registration #1493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c5d5b3d
chore: wip
peternhale e307240
chore: license year
iowillhoit 87eb63f
chore(release): 12.11.0 [skip ci]
svc-cli-bot 3e0eeff
chore: only check md file (#1475)
iowillhoit 4af7d65
fix: add workflow flow actions to decomposed workflow preset and allo…
mcarvin8 417f8ea
chore(release): 12.11.1 [skip ci]
svc-cli-bot e23df2f
W-17279149 Register MD APIs to metadata registry (#1472)
IdanRoas ff1c9f3
chore(release): 12.11.2 [skip ci]
svc-cli-bot e509950
chore: auto-update metadata coverage in METADATA_SUPPORT.md [no ci]
svc-cli-bot bf10db9
fix: update snapshot (#1478)
WillieRuemmele 8f4918a
chore(release): 12.11.3 [skip ci]
svc-cli-bot c201414
feat(mdTypes): register tua viz and ws metadata types (#1479)
PraveenViswanathan cd1b3b9
chore(release): 12.12.0 [skip ci]
svc-cli-bot 7098545
chore: auto-update metadata coverage in METADATA_SUPPORT.md [no ci]
svc-cli-bot 00792f0
fix: resolve strict dirs before suffixes for potential metadata files…
shetzel 8c57c40
chore(release): 12.12.1 [skip ci]
svc-cli-bot e963eb4
chore: wip
peternhale 484663a
chore: wip
peternhale 5f64455
chore: wip
peternhale fc61ee0
chore: encoded in MD, chars in SD (#1485)
WillieRuemmele 57bc064
chore: wip
peternhale 35ad23a
chore: wip
peternhale f5d552b
chore: update md xml to include xml header
peternhale fbd0528
chore: temp (#1490)
WillieRuemmele aa5599f
Merge branch 'main' of github.com:forcedotcom/source-deploy-retrieve …
peternhale 995d97c
chore: wip
peternhale 1f7d429
Wr/decompose esr (#1492)
WillieRuemmele 17b1a11
Merge branch 'main' into phale/decompose-esr
peternhale a89796b
chore: fix test
peternhale b01a935
chore: address review suggestions
peternhale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
50 changes: 50 additions & 0 deletions
50
src/convert/convertContext/decomposedExternalServiceRegistrationFinalizer.ts
This file contains hidden or 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,50 @@ | ||
| /* | ||
| * Copyright (c) 2025, 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 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 { JsToXml } from '../streams'; | ||
| import { ConvertTransactionFinalizer } from './transactionFinalizer'; | ||
|
|
||
| type ExternalServiceRegistrationState = { | ||
| 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: 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.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); | ||
| } | ||
| } |
This file contains hidden or 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
122 changes: 122 additions & 0 deletions
122
src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts
This file contains hidden or 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,122 @@ | ||
| /* | ||
| * 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 * as path from 'node:path'; | ||
| import { Readable } from 'node:stream'; | ||
| import * as yaml from 'yaml'; | ||
| import { XMLBuilder } from 'fast-xml-parser'; | ||
| import type { ExternalServiceRegistration } from '@jsforce/jsforce-node/lib/api/metadata/schema'; | ||
| import { JsonMap } from '@salesforce/ts-types'; | ||
| import { WriteInfo } from '../types'; | ||
| import { SourceComponent } from '../../resolve'; | ||
| import { DEFAULT_PACKAGE_ROOT_SFDX, META_XML_SUFFIX, XML_DECL, XML_NS_KEY } from '../../common'; | ||
| import { BaseMetadataTransformer } from './baseMetadataTransformer'; | ||
|
|
||
| type SchemaType = 'json' | 'yaml'; | ||
|
|
||
| type ESR = JsonMap & { | ||
| ExternalServiceRegistration: ExternalServiceRegistration & | ||
| { schemaUploadFileExtension: SchemaType }; | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8"?>\n'; | ||
|
|
||
| export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadataTransformer { | ||
| public async toSourceFormat(input: { | ||
| component: SourceComponent; | ||
| mergeWith?: SourceComponent | undefined; | ||
| }): Promise<WriteInfo[]> { | ||
| this.context.decomposedExternalServiceRegistration.externalServiceRegistration ??= | ||
| this.registry.getTypeByName('ExternalServiceRegistration'); | ||
| const writeInfos: WriteInfo[] = []; | ||
| const { component } = input; | ||
| const outputDir = path.join( | ||
| this.getOutputFolder('source', component), | ||
| this.context.decomposedExternalServiceRegistration.externalServiceRegistration.directoryName | ||
| ); | ||
| const xmlContent = { ...(await component.parseXml<ESR>()).ExternalServiceRegistration }; | ||
|
|
||
| // Extract schema content | ||
| // eslint-disable-next-line no-underscore-dangle | ||
|
||
| const schemaContent: string = xmlContent.schema ?? ''; | ||
| const schemaType = xmlContent.schemaUploadFileExtension ?? this.getSchemaType(schemaContent); | ||
| const asYaml = schemaType === 'yaml' ? schemaContent : yaml.stringify(JSON.parse(schemaContent)); | ||
| const schemaFileName = `${component.fullName}.yaml`; | ||
| const schemaFilePath = path.join(path.dirname(outputDir), schemaFileName); | ||
|
|
||
| // make sure the schema type is set | ||
| xmlContent.schemaUploadFileExtension = schemaType; | ||
|
|
||
| // Write schema content to file | ||
| writeInfos.push({ | ||
| source: Readable.from(asYaml), | ||
| output: schemaFilePath, | ||
| }); | ||
|
|
||
| // Remove schema content from ESR content | ||
| delete xmlContent.schema; | ||
|
|
||
| // Write remaining ESR content to file | ||
| const esrFileName = `${component.fullName}.externalServiceRegistration`; | ||
| const esrFilePath = path.join(path.dirname(outputDir), `${esrFileName}${META_XML_SUFFIX}`); | ||
| 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: xmlContent }); | ||
| writeInfos.push({ | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
| source: Readable.from(Buffer.from(xmlDeclaration + source)), | ||
| output: esrFilePath, | ||
| }); | ||
|
|
||
| return writeInfos; | ||
| } | ||
|
|
||
| public async toMetadataFormat(component: SourceComponent): Promise<WriteInfo[]> { | ||
| // only need to do this once | ||
| this.context.decomposedExternalServiceRegistration.externalServiceRegistration ??= | ||
| this.registry.getTypeByName('ExternalServiceRegistration'); | ||
| const esrFilePath = component.xml; | ||
| const esrContent = { ...(await component.parseXml<ESR>()).ExternalServiceRegistration }; | ||
|
|
||
| // Read schema content from file | ||
| const schemaFileName = `${component.fullName}.yaml`; // or .json based on your logic | ||
| const schemaFilePath = path.join(path.dirname(esrFilePath ?? ''), schemaFileName); | ||
| // load the schema content from the file | ||
| const schemaContent = (await component.tree.readFile(schemaFilePath)).toString(); | ||
| // Add schema content back to ESR content in its original format | ||
| // if the original format was JSON, then convert the yaml to json otherwise leave as is | ||
| esrContent.schema = esrContent.schemaUploadFileExtension === 'json' ? JSON.stringify(yaml.parse(schemaContent), undefined, 2) : schemaContent; | ||
|
|
||
| // Write combined content back to md format | ||
| this.context.decomposedExternalServiceRegistration.transactionState.esrRecords.set(component.fullName, { | ||
| // @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 | ||
| private getOutputFolder(format: string, component: SourceComponent, mergeWith?: SourceComponent): string { | ||
| const base = format === 'source' ? DEFAULT_PACKAGE_ROOT_SFDX : ''; | ||
| const { type } = mergeWith ?? component; | ||
| return path.join(base, type.directoryName); | ||
| } | ||
|
|
||
| // eslint-disable-next-line class-methods-use-this | ||
| private getSchemaType(content: string): SchemaType { | ||
| return content.trim().startsWith('{') ? 'json' : 'yaml'; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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/decomposeExternalServiceRegistrationBeta.json
This file contains hidden or 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": { | ||
| "yaml": { | ||
| "strategies": { | ||
| "adapter": "partiallyDecomposed" | ||
| }, | ||
| "directoryName": "externalServiceRegistrations", | ||
| "id": "yaml", | ||
| "isAddressable": false, | ||
| "name": "OAS Yaml Schema", | ||
| "suffix": "yaml", | ||
| "xmlElementName": "schema" | ||
| } | ||
| }, | ||
| "suffixes": { | ||
| "yaml": "yaml" | ||
| } | ||
| }, | ||
| "directoryName": "externalServiceRegistrations", | ||
| "id": "externalserviceregistration", | ||
| "ignoreParsedFullName": false, | ||
| "name": "ExternalServiceRegistration", | ||
| "strategies": { | ||
| "adapter": "partiallyDecomposed", | ||
| "decomposition": "topLevel", | ||
| "transformer": "decomposeExternalServiceRegistration" | ||
| }, | ||
| "suffix": "externalServiceRegistration", | ||
| "supportsPartialDelete": false | ||
| } | ||
| }, | ||
| "suffixes": { | ||
| "yaml": "yaml", | ||
| "externalServiceRegistration": "externalserviceregistration" | ||
| }, | ||
| "strictDirectoryNames": {}, | ||
| "childTypes": { | ||
| "yaml": "externalserviceregistration" | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any way this can be a stronger type? JsonMap is pretty generic.