@tty-pt/hyle logo

@tty-pt/hyle

npm version License: BSD-2-Clause TypeScript Ready Node.js Native WebAssembly Zero Dependencies

Universal Node.js and Browser bindings for libhyle, the pure-C schema descriptor and row-level data purification engine. Features TypeScript-first declarative schema definitions, isomorphic form validation, and automated TypeScript codegen. Canonical C header: <hyle/hyle.h>.

๐Ÿ“– Full C & Schema Engine Documentation: See the main libhyle GitHub README for hyle_schema_desc_t field macros, row purification rules, and C API details.


1. Quickstart & Installation

npm config set @tty-pt:registry https://tty.pt/npm/
npm install @tty-pt/hyle

Native OS & Mobile Packages (tty.pt): Prebuilt native C packages (libhyle) for Linux (apt, apk, pacman, dnf), macOS (brew), Windows (winget, MSYS2), and OpenBSD (pkg_add), plus static mobile sysroots for Android (https://tty.pt/android/) and iOS (https://tty.pt/ios/ โ€” libhyle.xcframework) are available via the tty.pt package repositories.

import { defineSchema, createFormValidator } from "@tty-pt/hyle";

// 1. Author schemas in natural TypeScript (no C knowledge required)
export const MemberSchema = defineSchema({
  fullName: { type: "string", required: true, minLength: 2 },
  email: { type: "string", required: true, pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$" },
  credits: { type: "int", min: 1 }
});

// 2. Validate input on server or client with C99 purify engine:
const result = MemberSchema.validate({
  fullName: "Ana Martins",
  email: "ana@example.com",
  credits: 5
});

console.log(result.valid); // true
console.log(result.errors); // []

2. Framework-Agnostic Reactive Form Controller

Provides instant keystroke validation with zero external framework dependencies (works with vanilla DOM, React, Svelte, Vue):

import { createFormValidator } from "@tty-pt/hyle";

const form = createFormValidator(MemberSchema, { fullName: "", email: "" });

// Subscribe to state updates (validity, dirty state, errors):
const unsubscribe = form.subscribe(({ values, errors, isValid, isDirty }) => {
  submitButton.disabled = !isValid;
  errorMessage.innerText = errors.map(e => e.message).join("\n");
});

// Bind to input events:
nameInput.addEventListener("input", (e) => form.setField("fullName", e.target.value));

3. Automated Schema-to-TypeScript Codegen (hyle-to-ts)

Convert shared C/JSON schema descriptors into exact TypeScript interfaces automatically:

npx hyle-to-ts --schema var/member.schema.json --name Member --out lib/types.ts

Outputs:

export interface Member {
  fullName: string;
  email: string;
  credits: number;
}

4. JavaScript / TypeScript API Reference

defineSchema(fieldMap: Record<string, FieldConfig>): HyleSchema

Creates a schema definition with declarative validation rules.

HyleSchema

validateRow(fields: FieldDescriptor[], values: Record<string, any>): ValidationError[]

Low-level field validator executing C hyle_purify logic via WebAssembly.

createFormValidator(schema: HyleSchema, initialValues?: Record<string, any>)

Reactive form validator providing observable state updates (isValid, isDirty, values, errors).

generateTypeScriptTypes(schema: HyleSchema, interfaceName?: string): string

Generates formatted TypeScript interface source code matching the schema fields.

getHyleWasm(): WebAssembly.Instance

Returns the WebAssembly instance loaded on the Stele shared-memory substrate.


5. Single Source of Truth Validation


6. C Development Headers & Native Integration

CFLAGS += -I./node_modules/@tty-pt/hyle/include
LDLIBS += -lhyle

License

BSD-2-Clause โ€” Copyright (c) 2026, Paulo Quirino <quirinpa@gmail.com>. See LICENSE.