Skip to content

Server-side validation ​

Type safety can help you avoid most problems at development and build time, but what about protecting the server against unforeseeable bugs or bad actors?

Server-side validation is currently not included out of the box, but there are many great options already available to add validation with little effort.

With Prisma ​

Prisma includes validation, so you can simply export many prisma methods directly:

ts
import { prisma } from './prisma';

export const app = {
  artist: {
    findFirst: prisma.artist.findFirst,
    findMany: prisma.artist.findMany,
  },
};

With Typia ​

Typia includes an assertParameters() guard which validates the input parameters to a given function based only on TS types:

ts
import typia from 'typia';

export const app = {
  repeatString: assertParameters(
    (text: string, times: number) => Array(times).fill(text).join(', ')
  )
};

With Zod ​

ts
import z from 'zod';

export const app = {
  repeatString: z.function().args(z.string(), z.number()).implement(
    // parameter types are inferred via zod
    (text, times) => Array(times).fill(text).join(', ')
  ),
};

Released under the MIT License.