dop-stick
Version:
Source control tooling for versionable-upgradeable smart contracts
210 lines • 10.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExecutionSummaryAdapter = void 0;
const terminal_1 = require("../core/terminal");
const timelineLogAdapter_1 = require("./timelineLogAdapter");
const finalSummaryAdapter_1 = require("./finalSummaryAdapter");
const box_1 = require("../core/box");
class ExecutionSummaryAdapter {
constructor(mode) {
this.mode = mode;
this.moduleMap = null;
// Reuse the prepareSummaryData method from FinalSummaryAdapter
this.prepareSummaryData = finalSummaryAdapter_1.FinalSummaryAdapter.prototype.prepareSummaryData;
// Reuse the getActionName method from FinalSummaryAdapter
this.getActionName = finalSummaryAdapter_1.FinalSummaryAdapter.prototype.getActionName;
this.timeline = new timelineLogAdapter_1.TimelineLogAdapter();
}
displayExecutionSummary(finalCuts) {
const startTime = Date.now();
this.moduleMap = this.prepareSummaryData(finalCuts);
this.timeline.startSection('EXECUTION SUMMARY');
this.timeline.logColoredStep('Preparing Diamond Cut Actions...', 0, terminal_1.Terminal.colors.magenta);
this.timeline.logEmptyStep();
// Display module summaries
Array.from(this.moduleMap.entries()).forEach(([_, summary], index) => {
// Module header with muted index
this.timeline.logStep(`${terminal_1.Terminal.colors.muted}[${index + 1}]${terminal_1.Terminal.colors.reset} ${summary.moduleName}`);
this.timeline.logInnerStep(`• ${summary.totalFunctions} functions processed`, 1);
// Display actions by type
const actionGroups = Array.from(summary.functionsByAction.entries())
.sort((a, b) => {
const [aAction] = a[0].split('-');
const [bAction] = b[0].split('-');
return Number(aAction) - Number(bAction);
});
actionGroups.forEach(([key, group]) => {
const [action] = key.split('-');
const count = group.signatures.length;
const actionName = this.getActionName(Number(action));
const actionText = `${count} ${actionName} action${count !== 1 ? 's' : ''}`;
this.timeline.logInnerStep(`• ${actionText}`, 1);
if (group.changed) {
const originalActionName = this.getActionName(group.originalAction);
this.timeline.logInnerColoredStep(` ↪ changed from ${originalActionName}`, 2, terminal_1.Terminal.colors.success);
}
else {
this.timeline.logInnerColoredStep(` ‣ unchanged`, 2, terminal_1.Terminal.colors.muted);
}
});
// Show discarded functions if any
if (summary.discardedFunctions.length > 0) {
this.timeline.logInnerColoredStep(`🔴 ${summary.discardedFunctions.length} functions discarded`, 1, terminal_1.Terminal.colors.error);
}
this.timeline.logEmptyStep();
});
this.displayFinalStatistics(this.moduleMap);
this.timeline.logEmptyStep();
this.timeline.logSuccessWithTime(`Execution summary completed`);
// Auto-proceed in auto-pilot-beta mode
if (this.mode === 'auto-pilot-beta') {
this.timeline.logStep('🤖 Auto-pilot: Automatically proceeding with execution');
this.timeline.logEmptyStep();
return;
}
// Interactive prompt for other modes
terminal_1.Terminal.writeLine('\nUse \'show <number>\' for detailed function information or \'proceed\' to continue');
terminal_1.Terminal.write('Proceed with upgrade? (y/N): ');
}
displayModuleSummaries(moduleMap) {
Array.from(moduleMap.entries()).forEach(([_, summary], index) => {
// Module header with index
this.timeline.logStep(`[${index + 1}] ${summary.moduleName}`);
this.timeline.logInnerStep(`• ${summary.totalFunctions} functions processed`, 1);
// Display actions by type
const actionGroups = Array.from(summary.functionsByAction.entries())
.sort((a, b) => {
const [aAction] = a[0].split('-');
const [bAction] = b[0].split('-');
return Number(aAction) - Number(bAction);
});
actionGroups.forEach(([key, group]) => {
const [action] = key.split('-');
const count = group.signatures.length;
const actionName = this.getActionName(Number(action));
if (group.changed) {
const originalActionName = this.getActionName(group.originalAction);
this.timeline.logInnerStep(`• ${actionName} actions (${count})`, 1);
this.timeline.logInnerColoredStep(` ↪ ${count} changed from ${originalActionName}`, 2, terminal_1.Terminal.colors.success);
}
else {
this.timeline.logInnerStep(`• ${actionName} actions (${count})`, 1);
}
});
// Show discarded functions if any
if (summary.discardedFunctions.length > 0) {
this.timeline.logInnerColoredStep(`🔴 ${summary.discardedFunctions.length} functions discarded`, 1, terminal_1.Terminal.colors.error);
}
this.timeline.logEmptyStep();
});
}
displayModuleDetails(moduleNumber) {
if (!this.moduleMap) {
terminal_1.Terminal.write('No summary data available');
return false;
}
const moduleSummary = Array.from(this.moduleMap.values())[moduleNumber - 1];
if (!moduleSummary) {
terminal_1.Terminal.write('Invalid module number');
return false;
}
this.timeline.startSection('MODULE DETAILS');
this.displayDetailedModuleView(moduleSummary, moduleNumber);
return true;
}
displayDetailedModuleView(summary, index) {
new box_1.Box(`${summary.moduleName} Details`, {
style: 'double',
color: 'muted',
padding: 1,
margin: 0,
align: 'left'
}).render();
// Show module overview
terminal_1.Terminal.writeLine(`\x1b[2m• ${summary.totalFunctions} functions processed\x1b[0m`);
terminal_1.Terminal.writeLine('');
const actionGroups = Array.from(summary.functionsByAction.entries())
.sort((a, b) => {
const [aAction] = a[0].split('-');
const [bAction] = b[0].split('-');
return Number(aAction) - Number(bAction);
});
// Display actions by type with their functions
actionGroups.forEach(([key, group]) => {
const [action] = key.split('-');
const actionName = this.getActionName(Number(action));
const count = group.signatures.length;
// Header for action group
if (group.changed) {
const originalActionName = this.getActionName(group.originalAction);
terminal_1.Terminal.writeLine(`\x1b[1m${actionName} ACTIONS (${count}) \x1b[32m(changed from ${originalActionName})\x1b[0m`);
}
else {
terminal_1.Terminal.writeLine(`\x1b[1m${actionName} ACTIONS (${count}) (unchanged)\x1b[0m`);
}
// Display functions in this group
group.signatures.forEach((signature, index) => {
terminal_1.Terminal.writeLine(` • ${signature}`);
terminal_1.Terminal.writeLine(` \x1b[2m→ Selector: ${group.selectors[index]}\x1b[0m`);
});
terminal_1.Terminal.writeLine('');
});
// Display discarded functions if any
if (summary.discardedFunctions.length > 0) {
terminal_1.Terminal.writeLine(`\x1b[31m🔴 DISCARDED FUNCTIONS (${summary.discardedFunctions.length})\x1b[0m`);
// Group discarded functions by reason
const groupedDiscarded = summary.discardedFunctions.reduce((acc, fn) => {
if (!acc[fn.reason])
acc[fn.reason] = [];
acc[fn.reason].push(fn.signature);
return acc;
}, {});
// Display grouped discarded functions
Object.entries(groupedDiscarded).forEach(([reason, signatures]) => {
terminal_1.Terminal.writeLine(`\n Reason: ${reason.toUpperCase()}`);
signatures.forEach(signature => {
terminal_1.Terminal.writeLine(` • ${signature}`);
});
});
}
terminal_1.Terminal.writeLine('');
terminal_1.Terminal.writeLine('\nUse \'back\' to return to summary');
terminal_1.Terminal.write('Enter command: ');
}
displayFinalStatistics(moduleMap) {
let totalFunctions = 0;
let totalDiscarded = 0;
let totalChanged = 0;
let totalUnchanged = 0;
moduleMap.forEach(summary => {
totalFunctions += summary.totalFunctions;
totalDiscarded += summary.discardedFunctions.length;
summary.functionsByAction.forEach(data => {
if (data.changed)
totalChanged += data.signatures.length;
else
totalUnchanged += data.signatures.length;
});
});
this.timeline.logStep('Final Statistics');
this.timeline.logInnerStep(`• Total Modules: ${moduleMap.size}`, 1);
this.timeline.logInnerStep(`• Total Functions: ${totalFunctions}`, 1);
this.timeline.logInnerColoredStep(`→ ${totalChanged} actions changed`, 2, terminal_1.Terminal.colors.magenta);
this.timeline.logInnerColoredStep(`→ ${totalUnchanged} actions unchanged`, 2, terminal_1.Terminal.colors.muted);
if (totalDiscarded > 0) {
this.timeline.logInnerColoredStep(`→ ${totalDiscarded} functions discarded`, 2, terminal_1.Terminal.colors.error);
}
}
getModuleCount() {
return this.moduleMap ? this.moduleMap.size : 0;
}
getModuleName(index) {
var _a;
if (!this.moduleMap)
return '';
const modules = Array.from(this.moduleMap.values());
return ((_a = modules[index - 1]) === null || _a === void 0 ? void 0 : _a.moduleName) || '';
}
}
exports.ExecutionSummaryAdapter = ExecutionSummaryAdapter;
//# sourceMappingURL=executionSummaryAdapter.js.map