@tahanabavi/typewire-nestjs
The NestJS backend companion to typefetch. Bind routes and validate request input and response output on the server using the exact same Zod contracts your frontend consumes — one contract file, validated on both sides.
Latest v0.1.1
Overview
One shared contract, validated on both sides of the wire.
typewire-nestjs is the backend half of typefetch. The typefetch client validates requests on the way out; typewire-nestjs binds your NestJS routes and validates request input and response output on the way in — both from the exact same Zod contract file.
The contract is the single source of truth. The client and the server import it, so the frontend and backend can never drift apart: if a route changes shape, both ends fail to compile until they agree again.
text
01 frontend shared contract backend02┌─────────────────────┐ ┌────────────────────────┐ ┌────────────────────┐03│ ApiClient(contracts)│ ────▶ │ { method, path, │ ◀──── │ @TypeFetchEndpoint( │04│ api.user.getUser() │ │ request: z.object, │ │ contracts.user. │05│ ✓ input validated │ │ response: z.object } │ │ getUser) │06│ ✓ output validated │ └────────────────────────┘ │ ✓ route from path │07└─────────────────────┘ │ ✓ input validated │08 │ ✓ output validated │09 └────────────────────┘- Route — the HTTP method and path come from the contract, so there is no second place to update.
- Request validation — path, query, body, and declared headers are checked against endpoint.request before your handler runs.
- Response validation — the return value is checked against endpoint.response and stripped of undeclared fields, so entities never leak extra data.
- Interoperable — coercion, error shapes, the response envelope, and field-level encryption all mirror the typefetch client byte-for-byte.
1 / 18