国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

? ? ????? JS ???? zod ? ??? ??? ??? ? ??? ???

zod ? ??? ??? ??? ? ??? ???

Dec 19, 2024 am 11:42 AM

zod vs class-validator & class-transformer

NestJS? ??? ??? ??? ? ??? ???? zod ??

zod? ??? ??? ? ??? ??? ??? ?????? ??? ??????.
NestJS? ?? ?????? ?????.

??

?? ?? ????.

1. ??? ??? ? ??? ???? ???? ??

  • NestJS?? ????? ?? ???? ?? ??????
  • ?? ??? ????? ?? ??? ???? ??? ?? NestJS???.
  • ??? ??? ? ValidationPipe? ???? ???? ??? ??

2. Zod? ??? ??

  • ?????? ???? ??
  • ?? ???????
  • ??? ? ??? ?? ?? ??
  • ? ???? ???
  • ?? ? ?? ??? ??

??

class-validator ? class-transformer? NestJS?? ??? ??? ?? ????? ???? 2?? ??????.
?, ????? ??,
? ???? ?? ??? NestJS? ????? ?? ???. ?? ValidationPipe? ?? DTO

? ??? ? ?? ??? ???? ???? ?????.

??? ????? ??? ?? ???/????? ?? ??? ?? ?? ? ??/???????.
??? Zod? ??? ???/????? ???? ???? ???.
?, 1??? ?? 3??? ?????
?? ?? ??? ? ?? ????? ?? ????? ? ?? ?????.

?? ????

??? ??? ?? ?? ??(???? ? ??)???.

??? ??? ??? ? ??? ???

1. ??

npm install class-validator class-transformer

2. ??? ?? ???

// main.ts
....
import { ValidationPipe } from '@nestjs/common';

async function bootstrap() {
....
  // Enable validation globally
  app.useGlobalPipes(new ValidationPipe({
    transform: true, // Automatically transform payloads to DTO instances
    whitelist: true, // Strip unknown properties
    forbidNonWhitelisted: true, // Throw error for unknown properties
  }));
....
}
....

3. DTO(??? ?? ??) ??

import { IsNotEmpty, IsString, IsInt, Min } from "class-validator";
import { Type, Transform } from "class-transformer";

export class CreateUserDto {
    @Transform(({ value }) => value.trim()) // Trim whitespaces
    @IsNotEmpty({ message: "Nama tidak boleh kosong" })
    @IsString({ message: "Nama harus berupa string" })
    @Min(3, { message: "Minimal panjang nama 3 karakter" })
    name: string;

    @Type(() => Number) // Transform input ke tipe Number
    @IsNotEmpty({ message: "Nama tidak boleh kosong" })
    @IsInt({ message: "Umur harus berupa bilangan bulat" })
    @Min(17, { message: "Minimal umur terdaftar 17 tahun" })
    age: number;
}

? ??? ????? ?????.

4. ??? ??

import { Body, Controller, Post } from "@nestjs/common";
import { CreateUserDto } from "./create-user.dto";

@Controller("users")
export class UsersController {
    @Post()
    create(@Body() createUserDto: CreateUserDto) {
        // Pada titik ini data/payload createUserdDto
        // sudah tervalidasi & diubah sesuai definisinya
        // developer bisa langsung eksekusi service
        // atau logic yang lain
    }
}

??

1. ??

npm install zod

2. ?? ?? ??

// user.validaiton.ts
import { z, ZodType } from "zod";

export class UserValidation {
    static readonly CREATE: ZodType = z.object({
        name: z
            .string({ message: "Nama harus berupa string" })
            .nonempty({ message: "Nama tidak boleh kosong" })
            .min(3, "Minimal panjang nama 13 karakter"),
        age: z
            .number({ message: "Umur harus berupa angka" })
            .int({ message: "Umur harus berupa bilangan bulat" })
            .min(17, "Minimal umur terdaftar 17 tahub"),
    });
}

export type TCreateUserPayload = z.infer<typeof UserValidation.CREATE>;

*???: ?? ????? ? ???? ?? ?? ? ????

3. ??? ??

import { Body, Controller, Post } from "@nestjs/common";
import { UserValidation, TCreateUserPayload } from "./user.validation.ts";

@Controller("users")
export class UsersController {
    @Post()
    create(@Body() createUserPayload: TCreateUserPayload) {
        const payload = UserValidation.CREATE.parse(createUserPayload);
        // Pada titik ini data/payload payload
        // sudah tervalidasi & diubah sesuai definisinya
        // developer bisa langsung eksekusi service
        // atau logic yang lain
    }
}

??

?????? Zod? ???? ??? ?????.
??, ???? ? ?? ?? ??? ??? ?? ???? ????.

https://abdulghofurme.github.io/posts/zod-vs-class-validator-n-class-transformer/

? ??? zod ? ??? ??? ??? ? ??? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

?? ????
1747
16
Cakephp ????
1601
56
??? ????
1542
28
PHP ????
1402
31
???
Java vs. JavaScript : ??? ????? Java vs. JavaScript : ??? ????? Jun 20, 2025 am 12:27 AM

Java ? JavaScript? ?? ?? ????? ??? ?? ?? ?? ???? ????? ?????. Java? ??? ? ??? ?????? ??? ???? JavaScript? ?? ? ??? ??? ?????.

JavaScript ?? ??? ? : ??? ? ??? JavaScript ?? ??? ? : ??? ? ??? Jun 14, 2025 am 12:11 AM

CommentAreCrucialInjavaScriptFormainingClarityandFosteringCollAboration.1) 1) thehelpindebugging, onboarding ? undervestandingStandingCodeevolution.2) awithy-linecommentsforquickexplanationsandmulti-linecommentsfordeTailedDescriptions.3) BestPricticesInclud

JavaScript ?? : ?? ?? JavaScript ?? : ?? ?? Jun 19, 2025 am 12:40 AM

JavaScriptCommentsareEnsentialformaining, ?? ? ???? 1) Single-LinecommentsERUSEDFORQUICKEXPLANATIONS.2) Multi-linecommentSexplaincleClexLogicOrprovidedEdeDDocumentation.3) inlineecommentsClarifySpecificPartSofcode.bestPractic

JavaScript ??? ?? : ?? ??? JavaScript ??? ?? : ?? ??? Jun 13, 2025 am 12:10 AM

javascriptassseveralprimitavivedatatatatatypes : ??, ???, ??, ????, null, ??, andbigint, andnon-primitiveTypes like-rucial-writingefficial, numberusesa64-bitformat, leadingtofloating-pointsli

JS? ??? ???? ???? ??? JS? ??? ???? ???? ??? Jul 01, 2025 am 01:27 AM

JavaScript?? ??? ??? ?? ? ? ?? ??? ???????. 1. ?? ??? ??? ???? ?? ??? ????. ISO ?? ???? ???? ???? ???? ?? ????. 2. ?? ??? ?? ???? ??? ?? ???? ??? ? ??? ? ?? 0?? ????? ?? ??????. 3. ?? ?? ???? ???? ???? ?? ?????? ??? ? ????. 4. Luxon? ?? ???? ???? ?????? ???? ?? ????. ??? ?? ???? ????? ???? ??? ????? ?? ? ????.

JavaScript vs. Java : ?????? ??? ? ?? JavaScript vs. Java : ?????? ??? ? ?? Jun 20, 2025 am 12:21 AM

JavaScriptIspreferredforwebDevelopment, whithjavaisbetterforlarge-scalebackendsystemsandandandoidapps.1) javascriptexcelsincreatinginteractivewebexperiences withitsdynatureanddommanipulation.2) javaoffersstrongtypingandobject-Orientededededededededededededededededdec

JavaScript : ???? ????? ??? ?? ?? JavaScript : ???? ????? ??? ?? ?? Jun 20, 2025 am 12:46 AM

javascriptassevenfundamentalDatatatypes : ??, ???, ??, unull, ??, ? symbol.1) ?? seAdouble-precisionformat, ??? forwidevaluerangesbutbecautiouswithfatingfointarithmetic.2) stringsareimmutable, useefficientconcatenationmethendsf

? ? ???  ??? ?? ???? ??? ?????? ? ? ??? ??? ?? ???? ??? ?????? Jul 02, 2025 am 01:22 AM

TAGGSATTHEBOTTOMOFABLOGPOSTORWEBPAGESERVESPRACTICALPURSEO, USEREXPERIENCE, andDESIGN.1.ITHELPSWITHEOBYOWNSESPORENGENSTOESTOCESKESKERKESKERKERKERDER-RELEVANTTAGSWITHOUTHINGTEMAINCONTENT.2.ITIMPROVESEREXPERKEEPINGTOPONTEFOCUSOFOFOFOCUSOFOFOFOCUCUSONTHEATECLL

See all articles