UNPKG

@aurahelper/xml-compressor

Version:

Libraries to compress any Salesforce Metadata XML Files to change the format. This library make easy the work with GIT and other Version Control Systems because grant always the same order of the elements, compress the file for ocuppy less storage and mak

155 lines (154 loc) 8.8 kB
import { XMLSortOrder, XMLCompressorStatus } from "@aurahelper/core"; export declare const SORT_ORDER: XMLSortOrder; /** * Class to compress any Salesforce Metadata XML Files to change the format * to make easy the work with GIT or another Version Control Systems because grant always the same order of the elements, * compress the file for ocuppy less storage and make GIT faster and, * specially make merges conflict more easy to resolve because identify the changes better. * * You can choose the sort order of the elements to reorganize the XML data as you like. * * The setters methods are defined like a builder pattern to make it more usefull */ export declare class XMLCompressor { paths: string[]; sortOrder: string; content?: string; xmlRoot?: any; private _xmlDefinition?; private _compressedContent?; private _event; /** * Constructor to create a new XML Compressor object * @param {string | string[]} [pathOrPaths] Path or paths to files or folder to compress * @param {string} [sortOrder] Sort order to order the XML elements. Values: simpleFirst, complexFirst, alphabetAsc or alphabetDesc. (alphabetAsc by default) */ constructor(pathOrPaths?: string | string[], sortOrder?: string); /** * Method to handle when a file compression failed. The callback method will be execute with any file compression error when execute compress() method. * @param {Function} onFailedCallback Callback function to handle the event * * @returns {XMLCompressor} Return the XMLCompressor instance */ onCompressFailed(onFailedCallback: (status: XMLCompressorStatus) => void): XMLCompressor; /** * Method to handle when a file compressed succesfully. The callback method will be execute with any compressed file when execute compress() method. * @param {Function} onSuccessCallback Callback function to handle the event * * @returns {XMLCompressor} Return the XMLCompressor instance */ onCompressSuccess(onSuccessCallback: (status: XMLCompressorStatus) => void): XMLCompressor; /** * Method to set the file or folder path or paths to execute compressor operations * @param {string | string[]} pathOrPaths Path or paths to files or folder to compress * * @returns {XMLCompressor} Return the XMLCompressor instance */ setPaths(pathOrPaths: string | string[]): XMLCompressor; /** * Method to add a file or folder path or paths to execute compressor operations * @param {string | string[]} pathOrPaths Path or paths to files or folder to compress * * @returns {XMLCompressor} Return the XMLCompressor instance */ addPaths(pathOrPaths: string | string[]): XMLCompressor; /** * Method to set a XML string content to execute compressor operations (except compress() and compressSync() and methods because only work with file or folder paths) * @param {string} content string XML content to compress. * * @returns {XMLCompressor} Return the XMLCompressor instance */ setContent(content: string): XMLCompressor; /** * Method to set the XML Parsed object to execute compressor operations (except compress() and compressSync() and methods because only work with file or folder paths) (Usgin XMLParser from @aurahelper/languages module) * @param {any} xmlRoot XML Parsed object with XMLParser from languages module * * @returns {XMLCompressor} Return the XMLCompressor instance */ setXMLRoot(xmlRoot: any): XMLCompressor; /** * Method to set the sort order value to sort the XML Elements when compress * @param {string} sortOrder Sort order to order the XML elements. Values: simpleFirst, complexFirst, alphabetAsc or alphabetDesc. (alphabetAsc by default). * * @returns {XMLCompressor} Return the XMLCompressor instance */ setSortOrder(sortOrder: string): XMLCompressor; /** * Method to set Simple XML Elements first as sort order (simpleFirst) * @returns {XMLCompressor} Return the XMLCompressor instance */ sortSimpleFirst(): XMLCompressor; /** * Method to set Complex XML Elements first as sort order (complexFirst) * @returns {XMLCompressor} Return the XMLCompressor instance */ sortComplexFirst(): XMLCompressor; /** * Method to set Alphabet Asc as sort order (alphabetAsc) * @returns {XMLCompressor} Return the XMLCompressor instance */ sortAlphabetAsc(): XMLCompressor; /** * Method to set Alphabet Desc as sort order (alphabetDesc) * @returns {XMLCompressor} Return the XMLCompressor instance */ sortAlphabetDesc(): XMLCompressor; /** * Method to get the XML compressed content from a file path, string content or XMLRoot object on sync mode. * XMLRoot object has priority over string content to be processed, and string content priority over path. For example, if you pass content and XMLRoot object to compressor, this method will be run with the XMLRoot data. * @returns {string} Returns a string with the compressed content * * @throws {OperationNotSupportedException} If the file does not support compression * @throws {OperationNotAllowedException} If the file path is a folder path * @throws {DataNotFoundException} If has no paths, content or XML Root to process * @throws {WrongFilePathException} If the file Path is not a string or can't convert to absolute path * @throws {FileNotFoundException} If the file not exists or not have access to it * @throws {InvalidFilePathException} If the path is not a file */ getCompressedContentSync(): string; /** * Method to get the XML compressed content from a file path, string content or XMLRoot object on async mode. * XMLRoot object has priority over string content to be processed, and string content priority over path. For example, if you pass content and XMLRoot object to compressor, this method will be run with the XMLRoot data. * @returns {Promise<string>} Returns a string Promise with the compressed content * * @throws {OperationNotSupportedException} If the file does not support compression * @throws {OperationNotAllowedException} If the file path is a folder path * @throws {DataNotFoundException} If has no paths, content or XML Root to process * @throws {WrongFilePathException} If the file Path is not a string or can't convert to absolute path * @throws {FileNotFoundException} If the file not exists or not have access to it * @throws {InvalidFilePathException} If the path is not a file */ getCompressedContent(): Promise<string>; /** * Method to get the XML compressed content from a file path on sync mode. * * @throws {OperationNotSupportedException} If the file does not support compression * @throws {OperationNotAllowedException} If the file path is a folder path * @throws {DataNotFoundException} If has no paths to process * @throws {WrongFilePathException} If the file Path is not a string or can't convert to absolute path * @throws {FileNotFoundException} If the file not exists or not have access to it * @throws {InvalidFilePathException} If the path is not a file */ compressSync(): void; /** * Method to compress a XML File, a List of files or entire folder (and subfolders) in Async mode. This methods fire some events to handle compress progress. * Use onCompressFailed() and onCompressSuccess() methods to handling progress. * * @returns {Promise<void>} Returns an empty Promise * * @throws {OperationNotSupportedException} If try to compress more than one folder, or file and folders at the same time * @throws {DataNotFoundException} If has no paths to process * @throws {WrongFilePathException} If the file Path is not a string or can't convert to absolute path * @throws {FileNotFoundException} If the file not exists or not have access to it * @throws {InvalidFilePathException} If the path is not a file * @throws {WrongDirectoryPathException} If the folder Path is not a string or cant convert to absolute path * @throws {DirectoryNotFoundException} If the directory not exists or not have access to it * @throws {InvalidDirectoryPathException} If the path is not a directory */ compress(): Promise<void>; /** * Method to get the Sort Order values object * @returns {XMLSortOrder} Return and object with the available sort order values */ static getSortOrderValues(): XMLSortOrder; }