UNPKG

@salesforce/source-deploy-retrieve

Version:

JavaScript library to run Salesforce metadata deploys and retrieves

40 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.objectHasSomeRealValues = exports.unwrapAndOmitNS = exports.getXmlElement = exports.extractUniqueElementValue = void 0; /* * Copyright 2025, Salesforce, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ts_types_1 = require("@salesforce/ts-types"); const constants_1 = require("../common/constants"); /** handle wide-open reading of values from elements inside any metadata xml file...we don't know the type * Return the value of the matching element if supplied, or defaults `fullName` then `name` */ const extractUniqueElementValue = (xml, uniqueId) => uniqueId ? (0, ts_types_1.getString)(xml, uniqueId) ?? getStandardElements(xml) : getStandardElements(xml); exports.extractUniqueElementValue = extractUniqueElementValue; const getStandardElements = (xml) => (0, ts_types_1.getString)(xml, 'fullName') ?? (0, ts_types_1.getString)(xml, 'name') ?? undefined; /** @returns xmlElementName if specified, otherwise returns the directoryName */ const getXmlElement = (mdType) => mdType.xmlElementName ?? mdType.directoryName; exports.getXmlElement = getXmlElement; /** composed function, exported from module for test */ const unwrapAndOmitNS = (outerType) => (xml) => omitNsKey(unwrapXml(outerType)(xml)); exports.unwrapAndOmitNS = unwrapAndOmitNS; /** Remove the namespace key from the json object. Only the parent needs one */ const omitNsKey = (obj) => Object.fromEntries(Object.entries(obj).filter(([key]) => key !== constants_1.XML_NS_KEY)); const unwrapXml = (outerType) => (xml) => // assert that the outerType is also a metadata type name (ex: CustomObject) xml[outerType] ?? xml; /** Ex: CustomObject: { '@_xmlns': 'http://soap.sforce.com/2006/04/metadata' } has no real values */ const objectHasSomeRealValues = (type) => (obj) => Object.keys(obj[type.name] ?? {}).length > 1; exports.objectHasSomeRealValues = objectHasSomeRealValues; //# sourceMappingURL=decomposed.js.map