@unito/integration-debugger
Version:
The Unito Integration Debugger
210 lines (209 loc) • 6.36 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.gradientStyles = exports.focusedList = exports.unfocusedList = exports.scrollbar = exports.unfocusablePane = exports.focusedPane = exports.pane = exports.paneBorder = void 0;
exports.paneTitle = paneTitle;
exports.statusIcon = statusIcon;
exports.jsonOutput = jsonOutput;
exports.renderCallEntry = renderCallEntry;
exports.renderInspectCall = renderInspectCall;
exports.indent = indent;
exports.generateLogo = generateLogo;
exports.uncolorize = uncolorize;
const chalk_1 = __importDefault(require("chalk"));
const gradient = __importStar(require("gradient-string"));
const json_colorizer_1 = __importDefault(require("json-colorizer"));
const store_1 = require("./store");
exports.paneBorder = {
type: 'line',
};
exports.pane = {
hover: {
border: {
fg: 'white',
},
},
focus: {
border: {
fg: 'yellow',
},
},
border: {
fg: 'gray',
},
};
exports.focusedPane = {
border: {
fg: 'yellow',
},
focus: {
border: {
fg: 'yellow',
},
},
};
exports.unfocusablePane = {
border: {
fg: 'gray',
},
};
exports.scrollbar = {
ch: ' ',
track: {
bg: 'cyan',
},
style: {
inverse: true,
},
};
exports.unfocusedList = {
hover: {
border: {
fg: 'white',
},
},
border: {
fg: 'gray',
},
selected: {
bg: '#58575b',
bold: true,
},
};
exports.focusedList = {
border: {
fg: 'yellow',
},
focus: {
border: {
fg: 'yellow',
},
},
selected: {
bg: '#58575b',
bold: true,
},
};
exports.gradientStyles = [
gradient.atlas,
gradient.cristal,
gradient.fruit,
gradient.instagram,
gradient.mind,
gradient.morning,
gradient.passion,
gradient.pastel,
gradient.rainbow,
gradient.retro,
gradient.summer,
gradient.teen,
gradient.vice,
];
function paneTitle(title) {
return gradient.fruit(title);
}
function statusIcon(status) {
return status ? chalk_1.default.greenBright('■') : chalk_1.default.redBright('■');
}
function jsonOutput(data) {
return (0, json_colorizer_1.default)(JSON.stringify(data, null, 2));
}
function renderCallEntry(step) {
const status = step.errors.length > 0
? chalk_1.default.redBright('■')
: step.warnings.length
? chalk_1.default.yellowBright('■')
: chalk_1.default.greenBright('■');
const stepDescriptionParts = [status, step.operation, step.path];
if (step.context) {
stepDescriptionParts.push(chalk_1.default.gray(step.context.name));
}
return stepDescriptionParts.join(' ');
}
function renderInspectCall(step, mode) {
let output = '';
if (mode === store_1.InspectMode.Warnings) {
output = jsonOutput(step.warnings);
}
else if (mode === store_1.InspectMode.Errors) {
output = jsonOutput(step.errors);
}
else if (mode === store_1.InspectMode.Payloads) {
output = [
'Payload In',
'',
jsonOutput(step.payloadIn ?? {}),
'',
'Payload Out',
'',
jsonOutput(step.payloadOut ?? {}),
'',
].join('\n');
}
else if (mode === store_1.InspectMode.Headers) {
output = [
'Headers In',
'',
jsonOutput(step.headersIn ?? {}),
'',
'Headers Out',
'',
jsonOutput(step.headersOut ?? {}),
'',
].join('\n');
}
return output;
}
function indent(paragraph, tabs = 1) {
return paragraph
.split('\n')
.map(line => [' '.repeat(Math.max(0, tabs) * 2), line].join(''))
.join('\n');
}
function generateLogo(tick) {
return exports.gradientStyles[tick % exports.gradientStyles.length].multiline([
' ',
'█ █▄░█ ▀█▀ █▀▀ █▀▀ █▀█ ▄▀█ ▀█▀ █ █▀█ █▄░█ █▀▄ █▀▀ █▄▄ █░█ █▀▀ █▀▀ █▀▀ █▀█',
'█ █░▀█ ░█░ ██▄ █▄█ █▀▄ █▀█ ░█░ █ █▄█ █░▀█ █▄▀ ██▄ █▄█ █▄█ █▄█ █▄█ ██▄ █▀▄',
' ',
].join('\n'));
}
function uncolorize(text) {
// eslint-disable-next-line
return text.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
}
;