Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@castore/event-type-zod

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@castore/event-type-zod

DRY Castore EventType definition using zod

latest
Source
npmnpm
Version
2.4.2
Version published
Weekly downloads
360
141.61%
Maintainers
4
Weekly downloads
 
Created
Source

Zod Event

DRY Castore EventType definition using zod.

📥 Installation

# npm
npm install @castore/event-type-zod

# yarn
yarn add @castore/event-type-zod

This package has @castore/core and zod (above v3) as peer dependencies, so you will have to install them as well:

# npm
npm install @castore/core zod

# yarn
yarn add @castore/core zod

👩‍💻 Usage

import z from 'zod';

import { ZodEventType } from '@castore/event-type-zod';

const pokemonAppearedPayloadSchema = z.object({
  name: z.string(),
  level: z.number(),
});

const pokemonAppearedMetadataSchema = z.object({
  trigger: z.enum(['random', 'scripted']).optional(),
});

// 👇 generics are correctly inferred
const pokemonAppearedEventType = new ZodEventType({
  type: 'POKEMON_APPEARED',
  payloadSchema: pokemonAppearedPayloadSchema,
  metadataSchema: pokemonAppearedMetadataSchema,
});

👇 Equivalent to:

import { EventType } from '@castore/core';

const pokemonAppearedEventType = new EventType<
  'POKEMON_APPEARED',
  { name: string; level: number },
  { trigger?: 'random' | 'scripted' }
>({ type: 'POKEMON_APPEARED' });

⚙️ Properties & Methods

ZodEventType implements the EventType class and adds the following properties to it:

  • payloadSchema (?object): The event type payload zod schema
const payloadSchema = pokemonAppearedEventType.payloadSchema;
// => pokemonAppearedPayloadSchema
  • metadataSchema (?object): The event type metadata zod schema
const metadataSchema = pokemonAppearedEventType.metadataSchema;
// => pokemonAppearedMetadataSchema

Keywords

event

FAQs

Package last updated on 18 Apr 2025

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