@ryan/nestjs-id-validation (2.3.6)

Published 2025-11-04 14:23:10 +00:00 by Ryan

Installation

@ryan:registry=
npm install @ryan/nestjs-id-validation@2.3.6
"@ryan/nestjs-id-validation": "2.3.6"

About this package

Installation

You can use the following .npmrc to configure installing this package:

@devdroplets:registry=http://git.devdroplets.com/api/v4/projects/222/packages/npm/
//git.devdroplets.com/api/v4/projects/222/packages/npm/:_auth=Z2l0bGFiK2RlcGxveS10b2tlbi04Njp4b3NHcVNCcDJyOWotc3cxeW0zVg==
always-auth=true

Publishing a new version

After you've modified code, you can easily publish a new version with the following command:

yarn new

This will ask you what the new version is and automatically commit the correct message for gitlab ci to build.

Defining typed contexts

You can define typescript contexts easily by overwriting the declared module namespace in a decleration file.

First create a types/id-validation.d.ts file (name and place does not matter).

/* ./types/id-validation.d.ts */
import "@devdroplets/nestjs-id-validation";
import { PrismaService } from "prisma/prisma.service";

declare module "@devdroplets/nestjs-id-validation" {
  export interface ValidationContext {
    prisma: PrismaService;
  }

  export interface ValidationPayload {
    /** Additional types in all validations */
  }
  export interface ValidationPayloadConstraint {
    /** Additional types in constraint validations */
  }
  export interface ValidationPayloadRequest {
    /** Additional types request validations */
  }
}

Next you add this in your tsconfig.json file as a typeRoots folder. For example:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2018",

    "outDir": "./dist",
    "baseUrl": "./",
    "typeRoots": ["./types"]
  }
}

No everywhere you use defineIdValidation(ctx => { ... }) your ctx argument is typed correctly.

Dependencies

Development dependencies

ID Version
@nestjs/common ^11.1.8
@nestjs/config ^4.0.2
@nestjs/core ^11.1.8
@nestjs/graphql ^13.2.0
@nestjs/platform-express ^11.1.8
@nestjs/testing ^11.1.8
@types/jest ^30.0.0
@types/lodash ^4.14.191
@typescript-eslint/eslint-plugin >=5.43.0
@typescript-eslint/parser >=5.43.0
class-validator ^0.14.0
eslint >=8.0.0
eslint-config-xo ^0.49.0
eslint-config-xo-typescript ^9.0.0
graphql ^16.6.0
jest ^30.2.0
lodash ^4.17.21
reflect-metadata ^0.2.2
rxjs ^7.8.0
ts-jest ^29.0.3
ts-morph ^27.0.2
typescript >=4.4

Peer dependencies

ID Version
@nestjs/common >=8
@nestjs/config >=2
@nestjs/core >=8
@nestjs/graphql >=10
@nestjs/platform-express >=9
class-transformer *
class-validator *
graphql >=15
reflect-metadata ^0.1.13
rxjs ^7.x
ts-morph >=13
Details
npm
2025-11-04 14:23:10 +00:00
13
Ryan Saebu
MIT
latest
6.5 KiB
Assets (1)
Versions (1) View all
2.3.6 2025-11-04