Getting Started

guts introduces a compiled abstract syntax architecture to data schema evaluation. By evaluating blueprints directly inside hardware-level machine layers via an optimized Rust framework, runtime overhead drops to absolute functional minimums.

// Core initiation contract
const { g } = require('guts');

Primitive Node Mapping

Core native datatypes and scalar constraint chaining structures.

Primitive boundaries evaluate string size limits, numerical intervals, and clean boolean truth passes natively on the stack space before heap assignments happen.

const userSchema = g.object({
  username: g.string().min(3).max(20),
  score: g.number().min(0).max(100),
  isActive: g.boolean()
});

High-Performance String Formats

Avoid context-switching overhead back to slow JavaScript execution arrays. Formats like `.email()` and `.uuid()` are evaluated entirely in Rust using zero-allocation byte validation sequences.

const secureIdentity = g.object({
  id: g.string().uuid(),
  contactEmail: g.string().email()
});

Inline Data Coercion

The `g.coerce` layer alters raw or stringified incoming parameters inside native memory spaces directly, ensuring clean typing before handing data packets back to the main V8 thread.

const gatewayPayload = g.object({
  port: g.coerce.number(),    // Converts "8080" to 8080 inline
  secure: g.coerce.boolean()  // Converts "true" to true
});

Advanced Complex Structures

Fixed tuples, native arrays, and uniform record map configurations.

const extendedMap = g.object({
  tags: g.array(g.string()),
  coordinates: g.tuple([g.string(), g.number()]), // Exact matching length and type
  registry: g.record(g.string().email())          // Dynamic keys mapping to emails
});

Polymorphic Logic & Decorators

Compose flexible architectures using options, literal declarations, and short-circuiting union logic pipelines.

const flexibleProfile = g.object({
  nickname: g.string().optional(),
  role: g.enum(["admin", "user"]),
  status: g.union([g.string(), g.number()])
});

Resilient Boundary AI Stream Repair

`parseStream()` tracks structural states of open arrays or objects on the fly, auto-synthesizing required trailing tags to safely assert limits mid-stream.

// Process raw string segments from live AI outputs directly
aiSchema.parseStream('{"summary": "Generative'); // Asserts valid pass

TypeScript Type Inference

Derive precise typescript interfaces compilation contracts from structural definition models directly without duplicating type schemas manually.

import { g, Infer } from 'guts';

const appSchema = g.object({ token: g.string().uuid() });
type AppConfig = Infer<typeof appSchema>;