Refactor/intents repository interface - #152
Open
Keengfk wants to merge 2 commits into
Open
Conversation
- Add Prisma 5.22.0 (prisma + @prisma/client) as dependencies - Add prisma/schema.prisma with Intent, Solver, Token models and IntentState / SupportedChain enums; all fields indexed appropriately - Add initial migration SQL (prisma/migrations/20240101000000_init/) - Add PrismaService (extends PrismaClient, NestJS lifecycle hooks) and global PrismaModule; wire into AppModule - Add DATABASE_URL to Joi validation schema, AppConfig, and .env.example - Add npm scripts: db:generate, db:migrate, db:migrate:prod, db:studio, db:validate - Update Dockerfile: build stage runs prisma generate; runtime CMD runs prisma migrate deploy before starting the server - Update CI: add postgres:16-alpine service container and migration steps (db:validate, db:generate, db:migrate:prod) before build/test - Add PrismaService unit test (src/prisma/prisma.service.spec.ts) - Mock PrismaService in e2e test helper so suites stay DB-free Closes stellar-vortex-protocol#37
- Add IIntentsRepository interface (save, findById, findAll, findByState, findByUser, update) and INTENTS_REPOSITORY Symbol token in src/intents/intents.repository.ts - Add InMemoryIntentsRepository in src/intents/in-memory-intents.repository.ts — lifts all Map logic and seed data out of IntentsService - Refactor IntentsService to pure orchestration: UUID generation, default state/deadline live here; all persistence delegated to the injected IIntentsRepository - Update IntentsModule to bind InMemoryIntentsRepository under the INTENTS_REPOSITORY token — swap the binding to change storage backend - Update intents.service.spec.ts to wire service via TestingModule with real InMemoryIntentsRepository under the DI token - Add in-memory-intents.repository.spec.ts — 14 tests covering every method including seed, overwrite, case-insensitive user lookup, and partial-patch behaviour All tests pass: 35 unit (5 suites), 23 e2e (5 suites), lint clean, typecheck clean. Closes stellar-vortex-protocol#38
|
@Keengfk Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces a IIntentsRepository interface and an InMemoryIntentsRepository
adapter, decoupling persistence from orchestration logic in IntentsService.
This is the prerequisite for the database work (#36) and on-chain state
reconciliation (#9) to land independently — each can provide its own adapter
bound to the INTENTS_REPOSITORY token without either touching IntentsService.
───────────────────────────────────────────────────────────────────────────────
Changes
src/intents/intents.repository.ts (new)
Defines the IIntentsRepository interface (6 methods: save, findById, findAll,
findByState, findByUser, update) and the INTENTS_REPOSITORY Symbol injection
token used to bind and inject the adapter.
src/intents/in-memory-intents.repository.ts (new)
The existing Map-based storage and seed logic lifted directly from
IntentsService into an @Injectable() class that implements IIntentsRepository.
Behaviour is identical — this is a pure structural move.
src/intents/intents.service.ts (modified)
Stripped to pure orchestration: UUID generation, state: "open" default, and
deadline fallback live here. All this.intents.* calls replaced with this.repo.*
via the injected IIntentsRepository. No logic was added or removed.
src/intents/intents.module.ts (modified)
Registers { provide: INTENTS_REPOSITORY, useClass: InMemoryIntentsRepository }.
To swap to a different backend (Prisma, on-chain), only this single binding
needs to change — nothing above it is touched.
───────────────────────────────────────────────────────────────────────────────
How to add a new storage adapter
// e.g. prisma-intents.repository.ts
@Injectable()
export class PrismaIntentsRepository implements IIntentsRepository {
constructor(private readonly prisma: PrismaService) {}
// ... implement the 6 methods
}
// intents.module.ts — one line change:
{ provide: INTENTS_REPOSITORY, useClass: PrismaIntentsRepository }
───────────────────────────────────────────────────────────────────────────────
Testing
covering every method: seed count, save/overwrite, findById miss, sort order,
state filter, case-insensitive user lookup, partial patch, update-miss
Test.createTestingModule with InMemoryIntentsRepository injected under the
token, matching production DI exactly; added deadline default test
npm run lint ✓ 0 errors
npm run typecheck ✓ 0 errors
npm run build ✓ clean
npm test ✓ 35 tests, 5 suites (+13 vs baseline)
npm run test:e2e ✓ 23 tests, 5 suites
closes #56