Skip to content

refactor: domain-scoped src/ folder structure#7

Merged
bntvllnt merged 5 commits intomainfrom
refactor/domain-scoped-src
Mar 27, 2026
Merged

refactor: domain-scoped src/ folder structure#7
bntvllnt merged 5 commits intomainfrom
refactor/domain-scoped-src

Conversation

@bntvllnt
Copy link
Copy Markdown
Contributor

Summary

  • Restructures flat src/ (8 files, server.ts at 458 LOC) into domain-scoped folders
  • src/tools/ — registration, hooks, helpers (query/mutation/action)
  • src/resources/ — registration, helpers (resource)
  • src/pagination/ — cursor HMAC, handler overrides, config validation
  • src/server.ts reduced from 458 to ~130 LOC (thin orchestrator)
  • Zero public API changes — DTS output identical (4.90 KB)

Structure

src/
├── server.ts          ~130 LOC (thin orchestrator)
├── auth.ts             47  (unchanged)
├── validators.ts      126  (unchanged)
├── types.ts           shared types + re-exports
├── tools/
│   ├── register.ts    tool registration + hooks
│   ├── helpers.ts     query(), mutation(), action()
│   └── types.ts       ToolDef, CallContext, etc.
├── resources/
│   ├── register.ts    resource registration
│   ├── helpers.ts     resource()
│   └── types.ts       ResourceDef
└── pagination/
    ├── cursor.ts      HMAC encode/decode
    ├── handlers.ts    handler overrides
    ├── context.ts     config validation
    └── types.ts       PaginationConfig, ToolSummary, ToolPage

Test plan

  • 103 tests passing (all existing tests, updated imports)
  • 100% line/statement/function coverage
  • Typecheck clean (both tsconfigs)
  • Build output identical (ESM + CJS + DTS, 4.90 KB types)
  • Lint clean (0 errors)
  • Public API surface unchanged

Split server.ts (458 LOC) into thin orchestrator (~130 LOC) + domain modules:

- src/tools/ — register.ts (tool registration + hooks), helpers.ts (query/mutation/action), types.ts
- src/resources/ — register.ts (resource registration), helpers.ts (resource wrapper), types.ts
- src/pagination/ — handlers.ts (handler overrides), cursor.ts (HMAC), context.ts (config), types.ts
- src/types.ts — shared types only (ConvexValidator, ConvexClient, AuthConfig, ServerConfig)
- src/auth.ts, src/validators.ts — unchanged (standalone)

Zero public API changes. 103 tests pass. DTS output identical (4.90 KB).
- Replace inline import() in ServerConfig with re-exported type names
- Restore assertCanSetRequestHandler explanation comment
- Make PreparedTool/PreparedResource non-exported (internal only)
@bntvllnt bntvllnt self-assigned this Mar 27, 2026
- Add direct decodeCursor tests for version/method/offset validation branches
- Remove unused tool list cache (per-request server creation means cache never hits)
- Restore branch threshold to 100% (was 98%)
- 108 tests, 100% on all coverage metrics
…asts

- validators.ts: type guards for literal values, record validators, tuple construction
- cursor.ts: isCursorPayload runtime validator replaces as CursorPayload cast
- register.ts: typed callback params, guard-proven narrowing for hook phases
- resources/register.ts: typed params removes as Record cast
- 113 tests, 100% coverage on all metrics

Remaining as assertions (3, all guard-proven or unfixable):
- cursor.ts: as Record<string, unknown> inside type guard (TS limitation)
- handlers.ts: as unknown as { _requestHandlers } (SDK private API, unfixable)
- register.ts: ctx as CallContext & { phase: "error" } (if-guarded narrowing)
- CLAUDE.md/AGENTS.md: domain-scoped architecture, 113 tests, 100% coverage
- CHANGELOG.md: add refactor + type safety notes to v0.2.0 entry
- docs/api-reference.md: version 0.2.0, PaginationConfig section, pagination docs
@bntvllnt bntvllnt merged commit 8a95cd4 into main Mar 27, 2026
2 checks passed
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.

1 participant