**Transaction System (TIER 1.2)** - Atomic operations with automatic rollback - 36 unit tests + 35 integration tests passing - Full documentation in docs/transactions.md **Duplicate Check Optimization (TIER 1.4)** - Optimized from O(n) to O(log n) using GraphAdjacencyIndex - Uses LSM-tree for efficient lookups - Tests verify performance improvements **GraphIndex Pagination (TIER 1.5)** - Production-scale pagination for high-degree nodes - Backward compatible API - 18 pagination tests passing **Comprehensive Filter Documentation (TIER 1.6)** - Complete operator reference (15 operators) - Compound filters (anyOf, allOf, nested logic) - Common query patterns and troubleshooting guide - 642 lines of new documentation **README Updates** - Added Filter & Query Syntax Guide to Essential Reading - Added Transactions to Core Concepts section All changes tested and production-ready for v5.8.0 release. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
103 lines
2.1 KiB
TypeScript
103 lines
2.1 KiB
TypeScript
/**
|
|
* Transaction System Types
|
|
*
|
|
* Provides atomicity for Brainy operations - all succeed or all rollback.
|
|
* Prevents partial failures that leave system in inconsistent state.
|
|
*/
|
|
|
|
/**
|
|
* Transaction state
|
|
*/
|
|
export type TransactionState =
|
|
| 'pending' // Created but not executed
|
|
| 'executing' // Currently executing operations
|
|
| 'committed' // Successfully committed
|
|
| 'rolling_back' // Rolling back due to failure
|
|
| 'rolled_back' // Successfully rolled back
|
|
|
|
/**
|
|
* Rollback action - undoes an operation
|
|
* Must be idempotent (safe to call multiple times)
|
|
*/
|
|
export type RollbackAction = () => Promise<void>
|
|
|
|
/**
|
|
* Operation that can be executed and rolled back
|
|
*/
|
|
export interface Operation {
|
|
/**
|
|
* Execute the operation
|
|
* @returns Rollback action to undo this operation (or undefined if no rollback needed)
|
|
*/
|
|
execute(): Promise<RollbackAction | undefined>
|
|
|
|
/**
|
|
* Optional: Name of operation for debugging
|
|
*/
|
|
readonly name?: string
|
|
}
|
|
|
|
/**
|
|
* Transaction context passed to user functions
|
|
*/
|
|
export interface TransactionContext {
|
|
/**
|
|
* Add an operation to the transaction
|
|
*/
|
|
addOperation(operation: Operation): void
|
|
|
|
/**
|
|
* Get current transaction state
|
|
*/
|
|
getState(): TransactionState
|
|
|
|
/**
|
|
* Get number of operations in transaction
|
|
*/
|
|
getOperationCount(): number
|
|
}
|
|
|
|
/**
|
|
* Function that builds a transaction
|
|
*/
|
|
export type TransactionFunction<T> = (ctx: TransactionContext) => Promise<T>
|
|
|
|
/**
|
|
* Transaction execution result
|
|
*/
|
|
export interface TransactionResult<T> {
|
|
/**
|
|
* Result value from user function
|
|
*/
|
|
value: T
|
|
|
|
/**
|
|
* Number of operations executed
|
|
*/
|
|
operationCount: number
|
|
|
|
/**
|
|
* Execution time in milliseconds
|
|
*/
|
|
executionTimeMs: number
|
|
}
|
|
|
|
/**
|
|
* Transaction execution options
|
|
*/
|
|
export interface TransactionOptions {
|
|
/**
|
|
* Timeout in milliseconds (default: 30000 = 30 seconds)
|
|
*/
|
|
timeout?: number
|
|
|
|
/**
|
|
* Whether to log transaction execution (default: false)
|
|
*/
|
|
logging?: boolean
|
|
|
|
/**
|
|
* Maximum number of rollback retry attempts (default: 3)
|
|
*/
|
|
maxRollbackRetries?: number
|
|
}
|