npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hamstore/command-standard-schema

v3.1.0

Published

DRY Hamstore Command definition using Standard Schema with runtime validation

Downloads

259

Readme

@hamstore/command-standard-schema

DRY Hamstore Command definition using Standard Schema.

Installation

# npm
npm install @hamstore/command-standard-schema

# yarn
yarn add @hamstore/command-standard-schema

# pnpm
pnpm add @hamstore/command-standard-schema

You also need a Standard Schema-compatible validation library as a peer dependency, for example:

Usage

import { StandardSchemaCommand } from '@hamstore/command-standard-schema';
import { z } from 'zod'; // or valibot, arktype, etc.

const catchPokemonCommand = new StandardSchemaCommand({
  commandId: 'CATCH_POKEMON',
  requiredEventStores: [pokemonsEventStore],
  inputSchema: z.object({
    pokemonId: z.string(),
    trainerName: z.string(),
  }),
  outputSchema: z.object({
    caughtAt: z.date(),
  }),
  handler: async (input, [pokemonsEventStore]) => {
    // ... business logic
    return { caughtAt: new Date() };
  },
});

The StandardSchemaCommand extends the core Command with runtime validation:

  • The inputSchema is required and validates every command invocation before the handler runs. The handler receives the parsed/transformed output of the schema (e.g. after Zod transforms).
  • The outputSchema is optional and validates the handler's return value if provided.

If validation fails, the command throws an error with the schema's validation issues. Input validation failures do not trigger the retry mechanism (retries only apply to EventAlreadyExistsError).

Controlling validation

By default, validation throws on invalid data. You can change this behavior with the validate option:

// Disable all validation (type inference only, like command-zod)
new StandardSchemaCommand({ validate: false, ... });

// Log warnings instead of throwing
new StandardSchemaCommand({ validate: 'warn', ... });

// Custom error handler
new StandardSchemaCommand({
  validate: (error) => myLogger.error(error),
  ...
});

// Different modes for input and output
new StandardSchemaCommand({
  validate: { input: true, output: 'warn' },
  ...
});

The validate option accepts:

  • true — throw on validation failure (default for input)
  • false — skip validation entirely
  • 'auto' — validate if a schema exists, skip if not (default for output)
  • 'warn' — log a warning via console.warn and continue with the original value
  • (error: Error) => void — call a custom handler and continue with the original value

For granular control, pass an object with input and/or output keys, each accepting the same options above. Unspecified input defaults to true; unspecified output defaults to 'auto'.

When using the shorthand form (e.g. validate: true), output is always resolved as 'auto' — meaning it validates when outputSchema is provided and skips otherwise. If you explicitly set validate: { output: true } without providing an outputSchema, the constructor throws an error to catch the misconfiguration early.

Why Standard Schema?

Standard Schema is a shared interface implemented by multiple validation libraries. Using @hamstore/command-standard-schema means your commands work with any Standard Schema-compatible library, without library-specific adapters.

This package is the recommended replacement for @hamstore/command-zod.