npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@injitools/contract

v0.2.1

Published

The DTO/validation layer of Inji: RequestDto/ResponseDto decorators, metadata store and Zod validation. Depends only on zod + reflect-metadata — no express or typeorm (layering hygiene).

Downloads

485

Readme

@injitools/contract

The DTO/validation layer of the Inji framework: the RequestDto/ResponseDto decorators, a metadata store, and Zod validation. It depends only on zod + reflect-metadatano express, no got, no typeorm, no node-core. This is deliberate layering hygiene: contract is the dependency-light base that core/db/auth build on, so keeping it free of server dependencies avoids dependency cycles.

You normally do not depend on this package directly: @injitools/core depends on @injitools/contract and re-exports the entire API, so backends import from @injitools/core.

What it exports

  • the RequestDto, ResponseDto decorators (the two DTO kinds) — plus Dto (deprecated alias of RequestDto) and the DtoProperty, DtoLink, DtoLinkArray field decorators;
  • DtoStorage, DtoType, DtoPropertyType, DtoDirection and the metadata types (TDto*);
  • generateZodValidation, generateSchema, generatePrimitiveZodValidation, detectContentType, isPrimitiveType, boolFromQueryOrJson;
  • dataToDto;
  • the type-level helpers Infer<typeof Dto> (output, ≡ z.infer) and InferInput<typeof Dto> (input before parsing, ≡ z.input);
  • the UrlLike / UrlLikeSchema primitives, PRIMITIVE_TYPES, the PrimitiveType type;
  • setOrmZodResolver / OrmZodResolver — the ORM-validation seam (the resolver is registered by @injitools/db, so typeorm never enters this graph). The resolver is direction-aware: the same column derives a request field (input semantics) or a response field (output semantics);
  • the canonical ErrorResponseDto.

Decorator metadata (important)

A DTO field's type is derived from the code via design:type, so the consumer must build with a toolchain that emits decorator metadata. Otherwise @DtoProperty() without an explicit type yields Reflect.getMetadata('design:type', …) === undefined and validation fails at runtime with Unsupported primitive: undefined.

  • reflect-metadata — nothing to do: the package loads it itself on the first line of the entry, before any DTO is declared (importing it again is harmless).
  • tsconfigexperimentalDecorators: true, emitDecoratorMetadata: true, and (with target ≥ ES2022) useDefineForClassFields: false so class fields don't overwrite decorator metadata.
  • transform — build through tsc or SWC (legacyDecorator + decoratorMetadata); esbuild/tsx do not emit metadata.

Checks (tests)

  • tests/no-orm-leak.test.ts — source scan: fails if any src/** import pulls in a server dependency (typeorm/@injitools/db/@injitools/auth/express/got).
  • tests/graph.test.ts — walks the built package graph: only zod + reflect-metadata allowed.
  • tests/contract.unit.test.ts — a smoke test of the DTO layer: type inference from design:type, dataToDto, ErrorResponseDto.
  • tests/infer.test-d.tstype-level Infer/InferInput tests (vitest --typecheck).
  • tests/infer.runtime.test.ts — a runtime check: the schema parses the input shape into the output shape exactly as the types promise (coercion, UrlLike, optional, strictObject).
npm test -w @injitools/contract