Skip to content

Add a ?dryRun=true mode to POST /api/v1/anchors/bulk that validates the batch without persisting #152

Description

@Jagadeeshftw

📌 Description

AnchorService.registerBulk already validates an entire batch (duplicate ids, conflicts with the existing registry) before persisting any of it. Integrators building an onboarding UI would benefit from being able to run that same validation as a preflight check — e.g. to show inline errors before committing — without actually registering the anchors.

🧩 Requirements and context

  • Accept an optional ?dryRun=true query param on POST /api/v1/anchors/bulk.
  • When set, run the exact same validation registerBulk already performs, but return the would-be-registered anchors (or a success indicator) without calling this.repo.upsert for any of them.
  • Validation errors (duplicate/conflicting ids) must behave identically in dry-run and real mode.

🛠️ Suggested execution

  • Refactor src/services/anchorService.ts's registerBulk to separate the "validate" and "persist" phases internally (it likely already does this via its parsed intermediate array), then add a dryRun boolean parameter that skips the persist phase.
  • Modify src/routes/anchors.ts's POST /bulk handler to read req.query.dryRun and pass it through.
  • Update src/openapi.ts with the new parameter.
  • Add tests in src/services/anchorService.test.ts and src/routes/anchors.test.ts asserting dry-run mode reports the same validation outcome but leaves the repository unchanged.

✅ Acceptance criteria

  • POST /api/v1/anchors/bulk?dryRun=true returns the same success/error outcome as a real call would, but registers nothing.
  • A batch that would fail validation fails identically in both modes.
  • Repository state is provably unchanged after a dry run, verified by a test checking AnchorRepository.count()/all() before and after.

🔒 Security notes

N/A — read-only preflight validation; no new data exposure, and explicitly prevents any persistence side effect when requested.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issueapiHTTP/WebSocket APIenhancementNew feature or improvement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions