1.25.3 ā€¢ Published 7 months ago

@castore/zod-event v1.25.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Zod Event

DRY Castore EventType definition using zod.

šŸ“„ Installation

# npm
npm install @castore/zod-event

# yarn
yarn add @castore/zod-event

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/zod-event';

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
1.21.0

11 months ago

1.25.0

9 months ago

1.25.1

9 months ago

1.23.0

10 months ago

1.25.2

8 months ago

1.25.3

7 months ago

1.22.0

10 months ago

1.24.1

9 months ago

1.24.2

9 months ago

1.22.1

10 months ago

1.24.0

9 months ago

1.22.2

10 months ago

1.20.1

12 months ago

1.20.2

12 months ago

1.20.0

12 months ago

1.19.0

1 year ago

1.18.1

1 year ago

1.17.2

1 year ago

1.18.0

1 year ago

1.17.1

1 year ago

1.19.1

1 year ago

1.15.0

1 year ago

1.14.0

1 year ago

1.13.0

1 year ago

1.17.0

1 year ago

1.16.1

1 year ago

1.15.2

1 year ago

1.16.0

1 year ago

1.15.1

1 year ago

1.12.0

1 year ago

1.11.0

1 year ago

1.10.0

1 year ago

1.9.0

1 year ago

1.8.0

1 year ago

1.4.4

1 year ago

1.7.0

1 year ago

1.4.3

1 year ago

1.6.0

1 year ago

1.5.1

1 year ago

1.4.2

1 year ago

1.5.0

1 year ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.2.0

2 years ago

1.2.1

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.7

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.7.3

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.21

2 years ago