New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@kamidere/typeguard

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kamidere/typeguard

typeguard

latest
Source
npmnpm
Version
2.0.3
Version published
Maintainers
2
Created
Source

@kamidere/typeguard

Typeguard based on Zod schemas

Installation

$ npm i zod @kamidere/typeguard

# or

yarn add zod @kamidere/typeguard

Usage

create-user.dto.ts

import { TypeGuard } from "@kamidere/typeguard"
import { z } from "zod";

export const createUserDto = z.object({
  username: z.string().min(5).max(20),
  password: z.string().min(8),
  email: z.string().email(),
});

export type createUserDto = z.infer<typeof createUserDto>;

// TypeGuard<TYPE> is required to have proper type after use of assert method.

export const createUserDtoTypeGuard: TypeGuard<createUserDto> = new TypeGuard(createUserDto);

create-user.resolver.ts

import { createUserDtoTypeGuard } from "./create-user.dto.ts"
import { userService } from "../services/user.service.ts"


export const createUserResolver = ({ data }: Context) => {
  // data?: unknown
  createUserDtoTypeGuard.assert(data);
  // data: createUserDto

  // now we can safely pass our data knowing,
  // that our required parameters are correct
  userService.create(data);

}

Tests


$ cd ..
$ npm i
$ npx lerna run --scope "@kamidere/typeguard" test

FAQs

Package last updated on 26 Aug 2023

Did you know?

Socket

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.

Install

Related posts