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

nestjs-arktype

v1.3.2

Published

Define your NestJS DTOs and Swagger schemas using Arktype

Readme

NestJS ❤ ArkType

nestjs-arktype is a simple library to help you define and validate all your NestJS DTOs using ArkType

Features

  • Create your DTOs using ArkType and re-use them anywhere in your app
  • Auto validation of your input body / params / query with ArkValidationPipe
  • Generate a fully featured OpenAPI spec out of your DTOs with automatic Swagger decorators
  • Support for complex nested objects, arrays, and polymorphic types
  • Support for string literals and enumerations

Examples

// user.dto.ts
import { type } from 'arktype';
import { createArkDto } from 'nestjs-arktype';

const userDto = type({
    id: 'number.integer',
    email: 'string.email',
    points: 'number',
    firstName: 'string',
    lastName: 'string',
});

const createUserBody = type({
    email: 'string.email',
    firstName: 'string',
    lastName: 'string',
});

export class CreateUserBodyDto extends createArkDto(createUserBody, { name: 'CreateUserBodyDto', input: true }) {}
export class UserDto extends createArkDto(userDto, { name: 'UserDto' }) {}

// user.controller.ts
import { Body, Controller, Post } from '@nestjs/common';
import { ApiBody } from '@nestjs/swagger';

@Controller()
export class UserController {
  @Post('/user')
  @ApiBody({ type: CreateUserBodyDto })
  async createUser(@Body() body: CreateUserBodyDto): Promise<UserDto> {
    const user = this.service.createUser(body);
    return UserDto.parse(user); // Validate your output against the schema if you need to
  }
}

Requirements

  • arktype >= 2.1
  • @nestjs/common >= 11
  • @nestjs/swagger >= 11
  • Node.js 22.x or later

Important: NestJS doesn't support importing ESM only libraries. ArkType 2 is now ESM only. Fortunately Node.js 22 lets you require() ESM modules out of the box, so Node.js 22+ is a hard requirement.

Installation

npm install nestjs-arktype arktype @nestjs/swagger

Usage

Creating a DTO from an ArkType schema

export class MyDto extends createArkDto(schema, { name: 'MyDto', input: true })

| Option | Type | Description | | :-------- | :------- | :------------------------- | | schema | Type | Required. Any ArkType schema representing your DTO | | name | string | Required. The name of your DTO (used for OpenAPI generation) | | input | boolean | Whether the DTO should represent the input schema or output schema (useful for DTOs with defaults) |

DTO Methods

Generated DTOs provide static methods for parsing:

// Parse and validate data (throws on error)
const validatedData = MyDto.parse(inputData);

// Parse with error reporting only (logs errors instead of throwing)
const result = MyDto.parse(inputData, { reportOnly: true });

Validating your inputs

The validation pipe uses your ArkType schemas to parse and validate incoming data from your parameter decorators. When the data is not valid, it throws a BadRequestException with a detailed summary of what went wrong.

To use it, in your main app.module add the validation pipe:

import { Module } from '@nestjs/common';
import { APP_PIPE } from '@nestjs/core';
import { ArkValidationPipe } from 'nestjs-arktype';

@Module({
  providers: [
    {
      provide: APP_PIPE,
      useClass: ArkValidationPipe,
    },
  ],
})
export class AppModule {}

Now whenever you use a parameter decorator in your controllers, it will be automatically parsed through the ArkType schema if the DTO is an ArkTypeDto.

async createUser(@Body() body: CreateUserBodyDto) {
  return body; // Body is parsed and validated with the ArkType schema 
}

Acknowledgements