From bf8b269595366e316da34c4b985e2ab6cccd7fb4 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Tue, 21 Jan 2025 14:51:40 -0700 Subject: [PATCH] chore: temp --- ...sedExternalServiceRegistrationFinalizer.ts | 36 ++++++++++++------- ...eExternalServiceRegistrationTransformer.ts | 27 ++++---------- ...enAPIChallenge.externalServiceRegistration | 1 - ...lenge.externalServiceRegistration-meta.xml | 1 - ...lenge.externalServiceRegistration-meta.xml | 1 - ...enAPIChallenge.externalServiceRegistration | 1 - ...enAPIChallenge.externalServiceRegistration | 1 - 7 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/convert/convertContext/decomposedExternalServiceRegistrationFinalizer.ts b/src/convert/convertContext/decomposedExternalServiceRegistrationFinalizer.ts index c5ddf10d5..dd13c02c4 100644 --- a/src/convert/convertContext/decomposedExternalServiceRegistrationFinalizer.ts +++ b/src/convert/convertContext/decomposedExternalServiceRegistrationFinalizer.ts @@ -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; }; export class DecomposedExternalServiceRegistrationFinalizer extends ConvertTransactionFinalizer { /** 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(), }; // eslint-disable-next-line class-methods-use-this public defaultDir: string | undefined; public finalize(defaultDirectory: string | undefined): Promise { 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); } } diff --git a/src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts b/src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts index 87b9b16b3..284c8b643 100644 --- a/src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts +++ b/src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts @@ -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 & { @@ -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()).ExternalServiceRegistration }; @@ -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 []; } diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/__snapshots__/verify-md-files.expected/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration b/test/snapshot/sampleProjects/preset-decomposedESR/__snapshots__/verify-md-files.expected/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration index 92632d111..a74640ecc 100644 --- a/test/snapshot/sampleProjects/preset-decomposedESR/__snapshots__/verify-md-files.expected/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration +++ b/test/snapshot/sampleProjects/preset-decomposedESR/__snapshots__/verify-md-files.expected/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration @@ -5,7 +5,6 @@ Custom OpenApi3 /accounts/schema - {"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}} Complete 3 openapi: 3.0.0 diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/__snapshots__/verify-source-files.expected/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml b/test/snapshot/sampleProjects/preset-decomposedESR/__snapshots__/verify-source-files.expected/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml index 31d5e8bf7..f61221204 100644 --- a/test/snapshot/sampleProjects/preset-decomposedESR/__snapshots__/verify-source-files.expected/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml +++ b/test/snapshot/sampleProjects/preset-decomposedESR/__snapshots__/verify-source-files.expected/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml @@ -5,7 +5,6 @@ Custom OpenApi3 /accounts/schema - {"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}} Complete 3 diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml b/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml index 31d5e8bf7..f61221204 100644 --- a/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml +++ b/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml @@ -5,7 +5,6 @@ Custom OpenApi3 /accounts/schema - {"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}} Complete 3 diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/mdapiOutput/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration b/test/snapshot/sampleProjects/preset-decomposedESR/mdapiOutput/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration index 92632d111..a74640ecc 100644 --- a/test/snapshot/sampleProjects/preset-decomposedESR/mdapiOutput/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration +++ b/test/snapshot/sampleProjects/preset-decomposedESR/mdapiOutput/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration @@ -5,7 +5,6 @@ Custom OpenApi3 /accounts/schema - {"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}} Complete 3 openapi: 3.0.0 diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration b/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration index 5b59efc73..544cf8fc5 100644 --- a/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration +++ b/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration @@ -49,7 +49,6 @@ paths: OpenApi3 /accounts/schema - {"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}} Complete 3