refactor(plugin-sql): extract domain stores from BaseDrizzleAdapter#6366
refactor(plugin-sql): extract domain stores from BaseDrizzleAdapter#6366
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
|
1. task.store.ts:39 - entityId unused in getAll 2. task.store.ts:142-146 - Missing agentId filter in delete ✅ 3. entity.store.ts:228 - SQL injection in searchByName 4. entity.store.ts:185 - SQL injection in getByNames 5. agent.store.ts:107 - Settings mutation 6. component.store.ts:40-41 - Empty string as UUID fallback 7. log.store.ts:66-71 - JSON SQL interpolation |
This comment was marked as resolved.
This comment was marked as resolved.
…elds and adjust utility imports
…tegration and unit tests
Split the memory lookup and embedding fetch into separate queries to work around a Drizzle ORM issue with leftJoin on dynamic vector columns that causes "Object.entries requires that input parameter not be null" errors. Related Drizzle issues: - drizzle-team/drizzle-orm#1603 - drizzle-team/drizzle-orm#2157
|
Claude finished @standujar's task in 1m 57s —— View job Reviewing PR #6366: Extract domain stores from BaseDrizzleAdapter
SummaryThis is a well-executed refactoring that extracts ~3,900 lines from ✅ Verified Implementations
Architecture Quality ✅Strengths:
Security ✅
Test Coverage ✅
Minor Notes (Non-blocking)💡 💡 Empty string UUID fallbacks in Verdict✅ APPROVE The refactoring is clean, well-tested, and maintains API compatibility. Previous review feedback has been addressed:
|
Refactors
BaseDrizzleAdapter(~3,900 lines) into composable domain stores. This improves maintainability, testability, and separation of concerns without changing the public API.Changes
New Domain Stores (
src/stores/)AgentStoreMemoryStoreRoomStoreParticipantStoreEntityStoreComponentStoreRelationshipStoreCacheStoreWorldStoreTaskStoreLogStoreMessagingStoreArchitecture
Key Design Decisions
Shared Context: All stores receive a
StoreContextwith database access, retry logic, and RLS isolationNo API Changes: All public methods remain identical - only internal implementation refactored
Impact
base.tsfrom ~3,900 to ~1,350 lines (~65% reduction)src/stores/Testing
Migration
No migration needed - this is a pure refactoring with no public API changes.
Greptile Summary
Refactors
BaseDrizzleAdapterfrom a monolithic ~3,900-line class into 12 composable domain stores, reducing the base adapter to ~1,350 lines while maintaining identical public API.Key Changes:
StoreContextinterface for dependency injection, providing stores with database access, retry logic, RLS isolation, and agent contextBaseDrizzleAdapternow delegate to appropriate storesinitStores()calls in all three adapter implementations (PG, PGLite, Neon)Architecture:
Notable Implementation Details:
MemoryStore.getByIdsplits queries to work around Drizzle leftJoin issue with dynamic vector columns (lines 140-164)sqltagged templates for dynamic queriesConfidence Score: 5/5
Important Files Changed
StoreContextinterface for dependency injection, providing clean abstraction for database access, retry logic, and RLS isolation.sqltagged template.Sequence Diagram
sequenceDiagram participant Client participant BaseDrizzleAdapter participant StoreContext participant MemoryStore participant EntityStore participant Database Note over BaseDrizzleAdapter: Constructor called BaseDrizzleAdapter->>BaseDrizzleAdapter: Set db instance BaseDrizzleAdapter->>BaseDrizzleAdapter: initStores() BaseDrizzleAdapter->>StoreContext: Create context with<br/>getDb(), withRetry(),<br/>withIsolationContext() BaseDrizzleAdapter->>MemoryStore: new MemoryStore(ctx) BaseDrizzleAdapter->>EntityStore: new EntityStore(ctx) Note over BaseDrizzleAdapter: All 12 stores initialized Client->>BaseDrizzleAdapter: createMemory(memory, tableName) BaseDrizzleAdapter->>BaseDrizzleAdapter: withDatabase(operation) BaseDrizzleAdapter->>MemoryStore: create(memory, tableName) MemoryStore->>StoreContext: withIsolationContext(entityId, callback) StoreContext->>BaseDrizzleAdapter: withIsolationContext(entityId, callback) BaseDrizzleAdapter->>Database: Execute with RLS context Database-->>BaseDrizzleAdapter: Result BaseDrizzleAdapter-->>StoreContext: Result StoreContext-->>MemoryStore: Result MemoryStore-->>BaseDrizzleAdapter: UUID BaseDrizzleAdapter-->>Client: UUID Client->>BaseDrizzleAdapter: getEntitiesByIds(entityIds) BaseDrizzleAdapter->>BaseDrizzleAdapter: withDatabase(operation) BaseDrizzleAdapter->>EntityStore: getByIds(entityIds) EntityStore->>StoreContext: withRetry(operation) StoreContext->>BaseDrizzleAdapter: withRetry(operation) BaseDrizzleAdapter->>Database: SELECT with JOIN Database-->>BaseDrizzleAdapter: Rows BaseDrizzleAdapter-->>StoreContext: Rows StoreContext-->>EntityStore: Rows EntityStore-->>BaseDrizzleAdapter: Entity[] BaseDrizzleAdapter-->>Client: Entity[]