MCPcopy Create free account
hub / github.com/code-pushup/cli / repack

Method repack

packages/utils/src/lib/wal.ts:225–246  ·  view source on GitHub ↗

* Repack the WAL by recovering all valid records and rewriting cleanly. * Removes corrupted entries and ensures clean formatting. * Updates the recovery state (accessible via getStats). * @param out - Output path (defaults to current file)

(out = this.#file)

Source from the content-addressed store, hash-verified

223 * @param out - Output path (defaults to current file)
224 */
225 repack(out = this.#file) {
226 this.close();
227 const r = this.recover();
228 if (r.errors.length > 0) {
229 // eslint-disable-next-line no-console
230 console.log('WAL repack encountered decode errors');
231 }
232
233 // Check if any records are invalid entries (from tolerant codec)
234 const hasInvalidEntries = r.records.some(
235 rec => typeof rec === 'object' && rec != null && '__invalid' in rec,
236 );
237 if (hasInvalidEntries) {
238 // eslint-disable-next-line no-console
239 console.log('Found invalid entries during WAL repack');
240 }
241 const recordsToWrite = hasInvalidEntries
242 ? filterValidRecords(r.records)
243 : (r.records as T[]);
244 ensureDirectoryExistsSync(path.dirname(out));
245 fs.writeFileSync(out, `${recordsToWrite.map(this.#encode).join('\n')}\n`);
246 }
247
248 /**
249 * Get comprehensive statistics about the WAL file state.

Callers 2

wal.int.test.tsFile · 0.80
wal.unit.test.tsFile · 0.80

Calls 4

recoverMethod · 0.95
filterValidRecordsFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected