Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@castore/command-zod
Advanced tools
DRY Castore Command
definition using zod
.
# npm
npm install @castore/command-zod
# yarn
yarn add @castore/command-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
import z from 'zod';
import { ZodCommand } from '@castore/command-zod';
import { tuple } from '@castore/core';
const pokemonAppearedInputSchema = z.object({
name: z.string(),
level: z.number(),
});
const pokemonAppearedOutputSchema = z.object({
pokemonId: z.string().uuid(),
});
// 👇 generics are correctly inferred
const pokemonAppearCommand = new ZodCommand({
commandId: 'POKEMON_APPEAR',
requiredEventStores: tuple(pokemonsEventStore),
inputSchema: pokemonAppearedInputSchema,
outputSchema: pokemonAppearedOutputSchema,
// 👇 handler input/output types are correctly inferred
handler: async (
commandInput,
[pokemonsEventStore],
{ generateUuid }: { generateUuid: () => string },
) => {
const { name, level } = commandInput;
const pokemonId = generateUuid();
await pokemonsEventStore.pushEvent({
aggregateId: pokemonId,
version: 1,
type: 'POKEMON_APPEARED',
payload: { name, level },
});
return { pokemonId };
},
});
👇 Equivalent to:
import { Command } from '@castore/core';
type RequiredEventStores = [typeof pokemonsEventStore];
type CommandInput = { name: string; level: number };
type CommandOutput = { pokemonId: string };
const pokemonAppearCommand = new Command<
RequiredEventStores,
RequiredEventStores,
CommandInput,
CommandOutput
>({
commandId: 'POKEMON_APPEAR',
requiredEventStores: [pokemonsEventStore],
handler: async (commandInput, [pokemonsEventStore]) => {
// ...same code
},
});
ZodCommand
implements the Command
class and adds the following properties to it:
inputSchema (?object)
: The command input zod schemaconst inputSchema = pokemonAppearCommand.inputSchema;
// => pokemonAppearedInputSchema
outputSchema (?object)
: The command output zod schemaconst outputSchema = pokemonAppearCommand.outputSchema;
// => pokemonAppearedOutputSchema
FAQs
DRY Castore Command definition using Zod
The npm package @castore/command-zod receives a total of 472 weekly downloads. As such, @castore/command-zod popularity was classified as not popular.
We found that @castore/command-zod demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.