mx-space/core
Overview
This skill provides a collection of Zod schema patterns and helpers tailored for building DTOs, validation schemas, and request validation in NestJS/TypeScript projects. It captures common patterns such as base schema extensions, custom validators for MongoDB, preprocessing, unions, arrays, nested objects, and mapping schemas to TypeGoose models. Use it to standardize input validation and infer TypeScript types directly from Zod schemas.
How this skill works
The skill exposes reusable Zod patterns and helper validators (e.g., MongoDB ObjectId, non-empty string, unique arrays, pin date) and example schema compositions. You create Zod objects, extend base schemas, or produce DTO classes from schemas to use in controllers and services. It also demonstrates preprocessing, conditional validation, defaults, and mapping between Zod schemas and TypeGoose models for consistent runtime validation and compile-time types.
When to use it
- Creating request DTOs and validation schemas for NestJS endpoints
- Defining and reusing project-wide field rules (ObjectId, non-empty strings, unique arrays)
- Building update DTOs using partial schemas for PATCH/PUT handlers
- Converting validated data into TypeScript types for services and database models
- Mapping validation rules to TypeGoose models for Mongoose integration
Best practices
- Define shared base schemas (write/read bases) and extend them for domain entities
- Use createZodDto to generate DTO classes for tight NestJS integration
- Prefer preprocessors to normalize incoming data (empty string -> null, string -> number) before validation
- Use .partial() to create update DTOs and avoid duplicating field definitions
- Keep custom validators (zMongoId, zNonEmptyString, zArrayUnique) centralized for consistency
Example use cases
- Define a PostSchema by extending a WriteBaseSchema to enforce title, slug, category, and optional tags
- Create MyDto from a Zod schema and derive MyType via z.infer for service method signatures
- Validate nested user addresses with AddressSchema and an optional addresses array on the UserSchema
- Preprocess query params converting numeric strings to numbers before validating as numbers
- Map a Zod schema to a TypeGoose model so required/optional semantics align with Mongoose properties
FAQ
Use createZodDto(MySchema) to produce a DTO class compatible with NestJS controllers.
How can I handle partial updates?
Call MySchema.partial() and wrap it with createZodDto to produce an update DTO where all fields are optional.
7 skills
This skill helps you generate and validate DTOs and schemas using Zod patterns for NestJS projects, ensuring consistent validation across APIs.
This skill helps you implement scalable TypeGoose data models and MongoDB patterns with decorators, inheritance, and plugins for robust backends.
This skill helps you create and apply robust database migrations in MongoDB-based apps, ensuring safe schema changes and data transformations.
This skill enforces MX Space API design conventions for controllers, authentication, responses, pagination, and errors to improve consistency and reliability.
This skill scaffolds a new NestJS module with controller, service, model, and schema, accelerating feature development.
This skill runs project tests efficiently, supporting all tests, single files, or patterns to streamline CI and local validation.
This skill generates an end-to-end test file template for a specified NestJS module, enabling quick controller testing setup.