Skip to content

@formajs/mold v2.1.0

Latest

Choose a tag to compare

@MenesesEvandro MenesesEvandro released this 23 Dec 15:03

Release Date: December 23, 2025

We're excited to present @formajs/mold v2.1.0 – a massive feature update that dramatically expands the schema definition capabilities. This release introduces support for complex data structures (Maps, Sets, Tuples), advanced type composition (Unions, Intersections), and powerful recursive schemas, bringing Mold to feature parity with major schema validation libraries while maintaining our lightweight orchestration philosophy.

🚀 What's New

✨ New Primitive & Complex Schemas

Mold now supports a much wider range of JavaScript types:

New Primitives

  • Boolean: Strict validation with f.boolean()
  • Date: Native Date object validation with f.date().min().max()
  • File: Generic file validation with f.file() supporting size and type checks

Complex Structures

const complexSchema = forma.object({
  // Validate JS Maps
  settings: forma.map(forma.string(), forma.boolean()),
  
  // Validate JS Sets
  tags: forma.set(forma.string()).min(1),
  
  // Fixed-length arrays (Tuples)
  coordinates: forma.tuple([forma.number(), forma.number()]),
  
  // Objects with uniform values (Records)
  metadata: forma.record(forma.string()),
});

� Advanced Type Composition

Model complex relationships with new type helpers:

  • Unions (.or): Match any of multiple schemas
  • Intersections (.and): Match all schemas combined
  • Literals & Enums: Exact value matching
  • Lazy/Recursive: Define circular references (e.g., generic trees, nested comments)
// Recursive schema example (Category Tree)
const categorySchema = forma.object({
  name: forma.string(),
  subcategories: forma.array(forma.lazy(() => categorySchema)).optional(),
});

// Union example
const idSchema = forma.union([
  forma.string().validateUUID(),
  forma.number().min(1)
]);

🛠 Enhanced Object & Base Capabilities

Existing schemas got smarter and more flexible:

  • Object Manipulation: .pick(), .omit(), .partial(), .required(), .extend()
  • Unknown Key Handling: .strip(), .strict(), .passthrough()
  • Transformation Pipelines: .transform(fn) and .refine(fn) for custom logic
  • Defaults & Coercion: .default(val), .catch(val), and f.coerce.x()

� Migration Guide

Update to v2.1.0

This is a minor release and is fully backward compatible with v2.0.0.

npm update @formajs/mold@^2.1.0

New Features Usage

No changes are required for existing code. You can incrementally adopt the new schemas and utilities.

🎯 Key Features

Complete Type System

  • Primitives: String, Number, Boolean, Date, File, Literal, Enum, Symbol, Void, Any, Unknown, Never, Null, Undefined
  • Structural: Object, Array, Tuple, Record, Map, Set
  • Flow: Promise, Function
  • Logical: Union, Intersection, Lazy (Recursive)

Developer Utilities

  • toJSONSchema(): Export standard JSON Draft-7 schemas for documentation or frontend usage.
  • Deep Partial: Create partial versions of deeply nested object schemas easily.

💡 Usage Examples

recursive Comment Thread

const commentSchema = forma.object({
  id: forma.string().validateUUID(),
  content: forma.string().min(1),
  author: forma.object({
    name: forma.string(),
    email: forma.string().validateEmail()
  }),
  // Recursive replies
  replies: forma.array(forma.lazy(() => commentSchema)).default([])
});

Polymorphic Input (Union)

const searchFilter = forma.object({
  query: forma.string(),
  // Status can be a specific string OR an array of strings
  status: forma.union([
    forma.enum(['active', 'pending', 'archived']),
    forma.array(forma.enum(['active', 'pending', 'archived']))
  ])
});

📚 Documentation

  • Updated API Reference: All new methods documented.
  • JSON Schema Interop: Guide on exporting schemas for OpenAPI/Swagger.

Ready to expand?

npm install @formajs/mold@^2.1.0

Happy modeling with @formajs/mold v2.1.0! 🧱✨