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

@xfe-repo/bff-validation

v1.6.10

Published

bff validation 验证库

Readme

@xfe-repo/bff-validation

bff validation 验证库

原生 API

原入口导出 class-validator 和 class-transformer 的公共 API 与类型,业务仓库通过本包使用时无需单独安装两库。

import { IsEmail, IsNumber, Transform, Type } from '@xfe-repo/bff-validation'
import type { ClassTransformOptions, ValidationOptions } from '@xfe-repo/bff-validation'

IsNumber 保留本包原有封装,原生装饰器通过 IsNumberOrigin 导出。其他原生 API 保持上游签名和行为。 直接调用 validate 或 plainToInstance 不会自动应用本包 ValidationPipe 的默认配置。

DTO 转换上下文

本包通过类型扩展为 ClassTransformOptions 增加可选的 execute: 'in' | 'out',字段的 Transform 回调可从 options.execute 读取执行方向。该标记由框架设置,不是 class-transformer 原生提供的 HTTP 语义。

  • ValidationPipe 沿用框架约定:validateCustomDecorators: true 推导为 execute: 'out',否则为 'in';错误信息的调试后缀使用相同判断。
  • ApiResponseInterceptor 的专用管道只需传入 validateCustomDecorators: true,同时启用 type: 'custom' 的 DTO 转换校验和出参上下文。
  • 局部 transformOptions 与框架默认选项合并,但不能覆盖管道推导的 execute。嵌套 DTO 继承相同上下文;自行调用 plainToInstance 派生嵌套 DTO 时也应传递父级选项。

validateCustomDecorators 原本是 Nest 自定义请求参数的校验开关。本框架同时用它推导方向,因此请求管道若设置为 true,也会使用出参方向,不能将其作为独立的入参校验开关。

业务字段装饰器消费上下文,不要求业务 DTO 声明入出参方向。未经过框架管道的原生转换没有 execute,依赖执行方向的装饰器应保留原值。

1.6.9 升级说明

IsNumber 保持 (validationOptions, options?) 的参数顺序和原有行为,现有调用无需迁移。 IsNumberOrigin 是 class-validator 的原生装饰器,参数顺序为 (options?, validationOptions?)。

import { IsNumber, IsNumberOrigin } from '@xfe-repo/bff-validation'

class ExampleDto {
  @IsNumberOrigin({ maxDecimalPlaces: 2 }, { message: '金额最多保留两位小数' })
  amount: number

  @IsNumber({ message: '金额最多保留两位小数' }, { maxDecimalPlaces: 2 })
  legacyAmount: number
}

IsNumberRequired、IsNumberOptional 和数字数组封装保持原有行为。