UNPKG

@salesforce/source-deploy-retrieve

Version:

JavaScript library to run Salesforce metadata deploys and retrieves

31 lines 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.objectHasSomeRealValues = exports.unwrapAndOmitNS = exports.getXmlElement = exports.extractUniqueElementValue = void 0; /* * 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 */ 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