Skip to content

Refactor/intents repository interface - #152

Open
Keengfk wants to merge 2 commits into
stellar-vortex-protocol:mainfrom
Keengfk:refactor/intents-repository-interface
Open

Refactor/intents repository interface#152
Keengfk wants to merge 2 commits into
stellar-vortex-protocol:mainfrom
Keengfk:refactor/intents-repository-interface

Conversation

@Keengfk

@Keengfk Keengfk commented Jul 27, 2026

Copy link
Copy Markdown

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

  • src/intents/in-memory-intents.repository.spec.ts (new) — 14 unit tests
    covering every method: seed count, save/overwrite, findById miss, sort order,
    state filter, case-insensitive user lookup, partial patch, update-miss
  • src/intents/intents.service.spec.ts (updated) — now wires IntentsService via
    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

Keengfk added 2 commits July 27, 2026 20:12
- 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
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define an IntentsRepository interface with an in-memory adapter

1 participant