
Research
/Security News
Miasma Mini Shai-Hulud Hits ImmobiliareLabs npm Packages
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.
@fluojs/validation
Advanced tools
Input-side validation decorators, mapped DTO helpers, and validation engine for Fluo.
English 한국어
Input-side validation decorators, mapped DTO helpers, and the validation engine for fluo.
pnpm add @fluojs/validation
PickType, PartialType, and IntersectionType@ValidateClass(...)@fluojs/i18n/validationimport { DefaultValidator, DtoValidationError, IsEmail, IsString, MinLength } from '@fluojs/validation';
class CreateUserDto {
@IsEmail()
email = '';
@IsString()
@MinLength(2)
name = '';
}
const validator = new DefaultValidator();
try {
const dto = await validator.materialize(
{ email: 'hello@example.com', name: 'fluo' },
CreateUserDto,
);
console.log(dto instanceof CreateUserDto);
} catch (error) {
if (error instanceof DtoValidationError) {
console.log(error.issues);
}
}
materialize() vs validate()materialize(value, Target) builds a typed instance and validates it recursivelyvalidate(instance, Target) validates an already-created root value and may
temporarily materialize plain nested @ValidateNested(...) values to run their
nested DTO rules without replacing the caller's propertiesvalidate() rejects malformed roots such as strings, arrays, null, and
undefined with a deterministic DtoValidationError before field or class rules
run. It accepts already-created target DTO instances and plain root objects so
request-pipeline binders can validate their prepared DTO payloads without scalar
coercion.
materialize() copies safe own enumerable properties from plain input objects,
applies DTO binding metadata, and recursively hydrates @ValidateNested(...)
fields. It preserves the request-pipeline contract that transports or binders own
source selection and scalar conversion before validation runs.
Existing nested values that are already instances of the declared nested DTO are
preserved; plain nested values are hydrated only for the affected nested field or
collection entry.
The root value passed to materialize() must already be a plain object or an
instance of the target DTO; malformed roots such as strings, arrays, and null
are rejected before the target DTO constructor or field initializers run.
DtoValidationError.issues is a stable DTO for request-pipeline error details:
type ValidationIssue = {
code: string;
field?: string;
message: string;
source?: 'path' | 'query' | 'header' | 'cookie' | 'body';
};
Nested DTOs use dot paths and collection indexes, such as address.city or
items[0].name. HTTP bindings attach source when the rule came from request
metadata; standalone validation and Standard Schema issues may leave it unset.
@fluojs/validation always emits its normal human-readable message values. Applications that need localized messages can opt into @fluojs/i18n/validation after validation fails. That integration maps source, field, and code to translation keys without changing validator execution or coupling this package to HTTP locale resolution.
import { IsEmail, IsString, PartialType, PickType } from '@fluojs/validation';
class UserDto {
@IsString() name = '';
@IsEmail() email = '';
}
class EmailOnlyDto extends PickType(UserDto, ['email']) {}
class UpdateUserDto extends PartialType(UserDto) {}
Standard Schema adapters are expected to report invalid input through explicit issues. Validation results without issues are treated as successful.
import { ValidateClass } from '@fluojs/validation';
import { z } from 'zod';
const UserSchema = z.object({ age: z.number().min(18) });
@ValidateClass(UserSchema)
class RestrictedUserDto {
age = 0;
}
ValidateClass(...) also accepts custom class-level validators. Validate(...) attaches custom field-level validators when built-in decorators are not enough, and ValidateIf(...) short-circuits dependent validators when its predicate returns false.
@ValidateNested(...) supports object fields, arrays, Set, and Map. Nested DTO paths use dot/index notation in validation issues, cycles are detected safely, and shared references are allowed.
Pass either a DTO class or a lazy constructor factory such as () => ChildDto or function resolveChildDto() { return ChildDto; } when nested types need deferred resolution.
materialize() is intentionally strict. If a transport gives you '42' and your DTO expects number, the transport or binding layer must convert it first.
Numeric validators, including @IsLatitude() and @IsLongitude(), validate numeric DTO values without treating numeric strings as already-converted numbers.
DefaultValidator, DtoValidationError, ValidationIssue, ValidatorIsString, IsNumber, IsBoolean, IsDate, IsArray, IsObject, IsEnum, IsInt, IsDefined, IsOptional, ValidateNested, ValidateIf, Validate, ValidateClassIsEmpty, IsNotEmpty, Equals, NotEquals, IsIn, IsNotInIsEmail, IsUrl, IsUUID, IsIP, IsAlpha, IsAlphanumeric, IsAscii, IsBase64, IsBooleanString, IsDataURI, IsDateString, IsDecimal, IsFQDN, IsHexColor, IsHexadecimal, IsJSON, IsJWT, IsLocale, IsLowercase, IsMagnetURI, IsMimeType, IsMongoId, IsNumberString, IsPort, IsRFC3339, IsSemVer, IsUppercase, IsISO8601, Matches, Length, MinLength, MaxLength, Contains, NotContainsMin, Max, IsPositive, IsNegative, IsDivisibleBy, MinDate, MaxDate, IsLatitude, IsLongitude, IsLatLong, IsISBN, IsISSN, IsMobilePhone, IsPostalCode, IsRgbColor, IsCurrencyArrayContains, ArrayNotContains, ArrayNotEmpty, ArrayMinSize, ArrayMaxSize, ArrayUniquePickType, OmitType, PartialType, IntersectionType@fluojs/validation/mapped-typesStandardSchemaV1Like for typing ValidateClass(...) schemasmaterialize() for hydration + validation, validate() for validation-only checks@fluojs/http: binds request data, then uses this package to validate it@fluojs/i18n: exposes @fluojs/i18n/validation for opt-in localized validation issue messages@fluojs/serialization: shapes output DTOs on the response side@fluojs/core: provides the metadata primitives used by validation decoratorspackages/validation/src/validation.test.tspackages/validation/src/mapped-types.test.tsexamples/realworld-api/src/users/create-user.dto.tsexamples/auth-jwt-passport/src/auth/login.dto.tsFAQs
Input-side validation decorators, mapped DTO helpers, and validation engine for Fluo.
The npm package @fluojs/validation receives a total of 36 weekly downloads. As such, @fluojs/validation popularity was classified as not popular.
We found that @fluojs/validation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.

Security News
Rolldown paused Rust React Compiler integration after a 5MB binary size increase raised concerns about shipping React-specific code to all Vite users.

Security News
/Research
Mini Shai-Hulud expands into the Go ecosystem after hitting LeoPlatform npm packages and targeting GitHub Actions workflows.