UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

53 lines (51 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AjaxResponseUpdater = void 0; const common_1 = require("../../../common"); const logger_1 = require("../../utils/logger"); /** * Updater for AjaxResponse errors. */ class AjaxResponseUpdater { /** * The update function. * @param fileData the file data. * @param error the error object. * @returns The updated file data. */ update(fileData, error) { if (!fileData) { logger_1.Logger.error(`Cannot find file data`); } const result = this.regexFixer(fileData); error.resolved = common_1.ResolveState.Resolved; return new Promise(resolve => resolve(result)); } /** * Fix file data by regex matching. * @param inputString the input file data string. * @returns the updated file data string. */ regexFixer(inputString) { const regexPattern = /AjaxResponse/; if (regexPattern.test(inputString)) { const data = inputString.split('\n'); const goodIndicater = ['<AjaxResponse', ':AjaxResponse', ': AjaxResponse']; for (let i = 0; i < data.length; i++) { for (let j = 0; j < goodIndicater.length; j++) { if (data[i].includes(goodIndicater[j]) && !data[i].includes('AjaxResponse<any>')) { data[i] = data[i].replace('AjaxResponse', 'AjaxResponse<any>'); logger_1.Logger.log(data[i]); } } } return data.join('\n'); } else { logger_1.Logger.log('no-op'); } return inputString; } } exports.AjaxResponseUpdater = AjaxResponseUpdater; //# sourceMappingURL=ajax-response-updater.js.map