import { describeVaultDataset } from "./describe" ; import VaultFormatA from "../VaultFormatA" ; import { FormatAVault } from "../../types" ; param command returns private static memberof function mustBePreserved ( command ) { const commandName = command . substr ( 0 , 3 ) ; return [ "cmm" ] . indexOf ( commandName ) >= 0 ; } /**
 * Flattener class for flattening archive history sets
 */ export default class Flattener { static memberof static FLATTENING_MIN_LINES = 6000 ; static memberof static PRESERVE_LINES = 5000 ; format : VaultFormatA ; constructor ( format ) { this . format = format ; } returns memberof canBeFlattened ( ) { return this . format . history . length >= Flattener . FLATTENING_MIN_LINES ; } param force returns memberof flatten ( force = false ) { const history = this . format . history ; const preservedLines = [ ] ; const tempFormat = new VaultFormatA ( ) ; let availableLines = history . length - Flattener . PRESERVE_LINES ; if ( availableLines <= 0 || ! this . canBeFlattened ( ) ) { if ( ! force ) { return false ; } availableLines = history . length ; } let currentCommand ; for ( let i = 0 ; i < availableLines ; i += 1 ) { currentCommand = history [ i ] ; if ( mustBePreserved ( currentCommand ) ) { preservedLines . push ( currentCommand ) ; } tempFormat . execute ( currentCommand ) ; } const cleanHistory = describeVaultDataset ( tempFormat . source as FormatAVault , "0" ) ; const newHistory = [ ... preservedLines , ... cleanHistory , ... history . slice ( availableLines ) ] ; this . format . erase ( ) ; this . format . execute ( newHistory ) ; return true ; } }