feat(smartdb): add operation log APIs, point-in-time revert support, and a web-based debug dashboard

This commit is contained in:
2026-04-02 17:02:03 +00:00
parent 943302f789
commit d34b8673e1
27 changed files with 3536 additions and 64 deletions

View File

@@ -3,6 +3,82 @@ import * as path from 'path';
import * as url from 'url';
import { EventEmitter } from 'events';
/**
* A single oplog entry returned from the Rust engine.
*/
export interface IOpLogEntry {
seq: number;
timestampMs: number;
op: 'insert' | 'update' | 'delete';
db: string;
collection: string;
documentId: string;
document: Record<string, any> | null;
previousDocument: Record<string, any> | null;
}
/**
* Aggregate oplog statistics.
*/
export interface IOpLogStats {
currentSeq: number;
totalEntries: number;
oldestSeq: number;
entriesByOp: {
insert: number;
update: number;
delete: number;
};
}
/**
* Result of a getOpLog query.
*/
export interface IOpLogResult {
entries: IOpLogEntry[];
currentSeq: number;
totalEntries: number;
}
/**
* Result of a revertToSeq command.
*/
export interface IRevertResult {
dryRun: boolean;
reverted: number;
targetSeq?: number;
entries?: IOpLogEntry[];
errors?: string[];
}
/**
* A collection info entry.
*/
export interface ICollectionInfo {
db: string;
name: string;
count: number;
}
/**
* Result of a getDocuments query.
*/
export interface IDocumentsResult {
documents: Record<string, any>[];
total: number;
}
/**
* Server metrics.
*/
export interface ISmartDbMetrics {
databases: number;
collections: number;
oplogEntries: number;
oplogCurrentSeq: number;
uptimeSeconds: number;
}
/**
* Type-safe command definitions for the RustDb IPC protocol.
*/
@@ -10,7 +86,24 @@ type TSmartDbCommands = {
start: { params: { config: ISmartDbRustConfig }; result: { connectionUri: string } };
stop: { params: Record<string, never>; result: void };
getStatus: { params: Record<string, never>; result: { running: boolean } };
getMetrics: { params: Record<string, never>; result: any };
getMetrics: { params: Record<string, never>; result: ISmartDbMetrics };
getOpLog: {
params: { sinceSeq?: number; limit?: number; db?: string; collection?: string };
result: IOpLogResult;
};
getOpLogStats: { params: Record<string, never>; result: IOpLogStats };
revertToSeq: {
params: { seq: number; dryRun?: boolean };
result: IRevertResult;
};
getCollections: {
params: { db?: string };
result: { collections: ICollectionInfo[] };
};
getDocuments: {
params: { db: string; collection: string; limit?: number; skip?: number };
result: IDocumentsResult;
};
};
/**
@@ -132,7 +225,38 @@ export class RustDbBridge extends EventEmitter {
return await this.bridge.sendCommand('getStatus', {} as Record<string, never>) as { running: boolean };
}
public async getMetrics(): Promise<any> {
return this.bridge.sendCommand('getMetrics', {} as Record<string, never>);
public async getMetrics(): Promise<ISmartDbMetrics> {
return this.bridge.sendCommand('getMetrics', {} as Record<string, never>) as Promise<ISmartDbMetrics>;
}
public async getOpLog(params: {
sinceSeq?: number;
limit?: number;
db?: string;
collection?: string;
} = {}): Promise<IOpLogResult> {
return this.bridge.sendCommand('getOpLog', params) as Promise<IOpLogResult>;
}
public async getOpLogStats(): Promise<IOpLogStats> {
return this.bridge.sendCommand('getOpLogStats', {} as Record<string, never>) as Promise<IOpLogStats>;
}
public async revertToSeq(seq: number, dryRun = false): Promise<IRevertResult> {
return this.bridge.sendCommand('revertToSeq', { seq, dryRun }) as Promise<IRevertResult>;
}
public async getCollections(db?: string): Promise<ICollectionInfo[]> {
const result = await this.bridge.sendCommand('getCollections', db ? { db } : {}) as { collections: ICollectionInfo[] };
return result.collections;
}
public async getDocuments(
db: string,
collection: string,
limit = 50,
skip = 0,
): Promise<IDocumentsResult> {
return this.bridge.sendCommand('getDocuments', { db, collection, limit, skip }) as Promise<IDocumentsResult>;
}
}