JSPM

  • Created
  • Published
  • Downloads 236
  • Score
    100M100P100Q92362F
  • License ISC

Tool to prune records from indexdb that do not exist in statedb

Package Exports

  • @ocap/indexdb-prune
  • @ocap/indexdb-prune/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ocap/indexdb-prune) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

IndexDB Prune Tool

This tool helps identify and remove records from Elasticsearch-based IndexDB that do not exist in the StateDB. The process is now streamlined with an API-based approach for better integration with other systems.

Usage

Programmatic API

You can use the tool programmatically by importing it:

const pruneIndexDB = require('@ocap/tools-indexdb-prune');

async function runPrune() {
  try {
    const deletedRecords = await pruneIndexDB();
    console.log('Pruning completed successfully');
    console.log('Deleted records:', deletedRecords);
    // deletedRecords format: { account: ['id1', 'id2'], tx: ['txid1', 'txid2'] }
  } catch (err) {
    console.error('Pruning failed:', err);
  }
}

runPrune();

Process

The tool now performs these operations in a single flow:

  1. Establishes connections to both IndexDB (Elasticsearch) and StateDB (Dolt)
  2. Scans all tables in IndexDB (tx, account, asset, delegation, token, factory, stake, rollup, rollupBlock)
  3. For each record, verifies if it exists in StateDB
  4. Automatically deletes records that exist in IndexDB but not in StateDB
  5. Returns a map of deleted record IDs by table

Return Value

The function returns an object with tables as keys and arrays of deleted IDs as values:

{
  account: ['accountId1', 'accountId2', ...],
  tx: ['txId1', 'txId2', ...],
  asset: ['assetId1', 'assetId2', ...],
  // other tables...
}