Skip to content

Nehonix-Team/fortify-schema

Fortify Schema

npm version TypeScript Build Status Bundle Size

Fortify Schema Logo

Important: Migration to Reliant-Type

The fortify-schema package is being deprecated and replaced by reliant-type.

While fortify-schema will continue to receive critical security patches, all new features, performance improvements, and ongoing development are now focused exclusively on reliant-type. We strongly recommend migrating to reliant-type for:

  • Latest features and improvements - All new capabilities are built into reliant-type
  • Active development - Ongoing enhancements and optimizations
  • Long-term support - Full maintenance and community support
  • Enhanced performance - Significant speed and efficiency gains
  • Expanded ecosystem - Growing tooling and integration support

Migration is straightforward - reliant-type maintains API compatibility with fortify-schema core features while introducing powerful new capabilities. See our Migration Guide for step-by-step instructions.

Quick Migration Example

// Before (fortify-schema)
import { Interface } from "fortify-schema";

// After (reliant-type)
import { Interface } from "reliant-type";

// Your existing schemas work without modification
const UserSchema = Interface({
  id: "uuid",
  email: "email!",
  name: "string(2,50)",
});

Overview

Fortify Schema is a TypeScript validation library featuring interface-like syntax and advanced conditional validation. Designed for TypeScript developers who value familiar patterns and powerful runtime validation capabilities.

VSCode extension preview

Key Capabilities

  • Interface-like Syntax - Define schemas using TypeScript-style interface definitions
  • Advanced Conditionals - Implement complex business logic with when expressions
  • Custom Error Messages - Provide context-specific validation feedback using the --> operator
  • Complete Type Safety - Full TypeScript inference with zero runtime overhead
  • High Performance - Automatic precompilation and optimization
  • Professional Tooling - VS Code extension with IntelliSense and real-time validation

Installation

npm install fortify-schema

Note: For new projects, consider starting with reliant-type instead:

npm install reliant-type

Quick Start

import { Interface } from "fortify-schema";

// Define schemas with familiar TypeScript-like syntax
const UserSchema = Interface({
  id: "uuid",
  email: "email! --> Please provide a valid email address",
  name: "string(2,50) --> Name must be between 2 and 50 characters",
  age: "number(18,120)? --> Age must be between 18 and 120",
  role: "admin|user|guest --> Role must be admin, user, or guest",
  tags: "string[]",
  metadata: "record<string, any>",

  // Advanced conditional validation
  permissions: "when role=admin *? string[] : =[]",
});

// Validate with complete TypeScript inference
const result = UserSchema.safeParse(userData);
if (result.success) {
  console.log("Valid user:", result.data); // Fully typed
} else {
  console.log("Validation errors:", result.errors);
}

Core Features

Type System

Comprehensive support for primitive types, collections, and advanced formats:

  • Primitives - string, number, boolean, null, undefined
  • Specialized - email, url, uuid, date, iso8601
  • Collections - Arrays (string[]), Records (record<string, any>)
  • Objects - Generic object validation with object and object?
  • Unions - Enumerated values with admin|user|guest

Validation Modifiers

  • Optional - Mark fields as optional with ? suffix (e.g., "string?")
  • Required - Enforce non-empty values with ! suffix (e.g., "email!")
  • Constraints - Apply ranges and limits with (min,max) syntax
  • Custom Messages - Define user-friendly errors with --> operator

Conditional Validation

Implement complex business rules based on runtime data:

const ProductSchema = Interface({
  inStock: "boolean",
  discount: "when inStock=true *? number(0,100)? : =0",
  maxQuantity: "when inStock=true *? int(1,1000) : int(1,10)",
});

Documentation

Getting Started

Core Concepts

Advanced Features

Reference

Common Use Cases

Form Validation

const FormSchema = Interface({
  email: "email! --> Please enter a valid email",
  password: "string(8,)! --> Password must be at least 8 characters",
  confirmPassword: "string --> Passwords must match",
  terms: "boolean! --> You must accept the terms",
});

API Request Validation

const APIRequestSchema = Interface({
  method: "GET|POST|PUT|DELETE",
  endpoint: "url",
  headers: "record<string, string>",
  body: "object?",
});

E-Commerce Products

const ProductSchema = Interface({
  id: "uuid",
  name: "string(3,100)",
  price: "number(0.01,) --> Price must be greater than 0",
  category: "electronics|clothing|food",
  inStock: "boolean",
  discount: "when inStock=true *? number(0,100)? : =0",
});

User Management

const UserSchema = Interface({
  id: "uuid",
  email: "email!",
  role: "admin|user|guest",
  permissions: "when role=admin *? string[] : =[]",
  maxProjects: "when role=admin *? int(1,100) : int(1,3)",
});

VS Code Extension

Enhance your development workflow with professional IDE integration:

  • Syntax Highlighting - Comprehensive highlighting for schema types
  • IntelliSense - Context-aware autocompletion
  • Hover Documentation - Inline documentation and examples
  • Error Detection - Real-time schema syntax validation
  • Code Snippets - Pre-built templates for common patterns

Download Extension | Extension Documentation

Performance

Fortify Schema is optimized for production environments:

  • Fast Validation - Optimized execution paths with schema precompilation
  • Memory Efficient - Minimal overhead per schema instance
  • Scalable - Predictable performance across data complexity levels
  • Benchmarked - Continuous performance monitoring and optimization

Run benchmarks locally:

npm run benchmark
npm run benchmark:nestedObject

View Benchmark Results

Comparison

Feature Fortify Schema Reliant-Type Zod Yup Joi
Interface-like syntax Yes Yes No No No
Conditional validation Yes Enhanced Limited No Limited
Custom error messages Yes Yes Yes Yes Yes
TypeScript inference Full Full Full Limited No
VS Code extension Yes Yes No No No
Active development Maintenance Active Active Active Active
Bundle size Small Small Medium Large Large

Note: reliant-type represents the evolution of fortify-schema with enhanced capabilities and ongoing development.

Community & Support

Get Help

Contributing

Contributions are welcome. Please review our Contributing Guide before submitting pull requests.

  • Report bugs and request features
  • Submit pull requests
  • Improve documentation
  • Share use cases and feedback

Stay Updated

License

MIT © Nehonix Team

Acknowledgments

Developed by the Nehonix Team with contributions from the open-source community.

Special recognition to:

  • The TypeScript team for language innovation
  • The open-source community for feedback and contributions
  • All contributors and users of Fortify Schema

About

Fortify Schema is A modern TypeScript validation library designed around familiar interface syntax and powerful conditional validation. Experience schema validation that feels natural to TypeScript developers while unlocking advanced runtime validation capabilities

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

 
 
 

Contributors