refactor(8.0): delete DataAPI — superseded by Db persist/restore + import API + stats
The legacy backup/import/export/stats facade (src/api/DataAPI.ts) drifted from the modern entity shape and every job it did now has a first-class surface. Delete it and brain.data(), and rewire the CLI: - data-stats → brain.stats() (full BrainyStats report: per-type breakdowns, indexed fields, index health, storage backend, writer lock, version) - clean → brain.clear() - export → alias of snapshot; a db.persist() snapshot is the full-fidelity export format (open with Brainy.load, load wholesale with brainy restore); external data ingestion remains brainy import (UniversalImportAPI) Rewiring clean onto brain.clear() exposed two real bugs, both fixed: - clear() left this.graphIndex undefined forever — any graph-touching call afterwards (relate, getNeighbors, stats) crashed. clear() now re-resolves the graph index exactly as init() does and re-wires the shared UUID↔int resolver, and re-resolves the metadata index with the same provider fallback as init(). - storage.clear() reset the legacy totals but not the per-type/subtype count rollups or id→type caches, so stats() reported phantom counts for deleted entities. Both adapters now delegate derived-state reset to reloadDerivedState(), the same path restore-from-snapshot uses. One-shot CLI commands (data-stats, clean, snapshot/export, restore, history, generation) now close the brain and exit explicitly — global cache timers otherwise keep the process alive holding the writer lock. Verified: build clean, 1383/1383 unit tests, 24/24 db-mvcc integration, plus an end-to-end CLI smoke (add → data-stats → export → clean → data-stats).
This commit is contained in:
parent
cc8037db10
commit
478fa176f2
12 changed files with 262 additions and 639 deletions
|
|
@ -142,11 +142,11 @@ export const utilityCommands = {
|
|||
|
||||
// Show warning before clearing
|
||||
console.log(chalk.yellow('\n⚠️ WARNING: This will permanently delete ALL data!'))
|
||||
const dataApi = await brain.data()
|
||||
|
||||
// Clear all data
|
||||
// Clear all data (entities, relationships, and every index)
|
||||
spinner.text = 'Clearing all data...'
|
||||
await dataApi.clear({ entities: true, relations: true })
|
||||
await brain.init()
|
||||
await brain.clear()
|
||||
|
||||
spinner.succeed('Database cleared')
|
||||
|
||||
|
|
@ -156,6 +156,12 @@ export const utilityCommands = {
|
|||
} else {
|
||||
formatOutput({ cleared: true, success: true }, options)
|
||||
}
|
||||
|
||||
// close() releases the writer lock and indexes, but global timers
|
||||
// (UnifiedCache bookkeeping, PathResolver stats) keep the event loop
|
||||
// alive. CLI commands are one-shot — exit explicitly.
|
||||
await brain.close()
|
||||
process.exit(0)
|
||||
} catch (error: any) {
|
||||
spinner.fail('Cleanup failed')
|
||||
console.error(chalk.red(error.message))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue