Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

type-schema-compiler

HamzaM34ISC0.0.3

An intuitive type schema specification language

type, schema, compiler, generator, language, parsing, haskell, npx, executable, command, cli, safety, typecheck, check, type-check, programming-language, new, json-validator, validator, json, ajv, json-schema, jsonschema, json-schema-validator, json-schema-validation, validation, validator, error, api, api-validation, api-type-check, api-check, api-error, error-api, type-safety

readme

Type schema compiler

A compiler for an intuitive Javascript type schema definition language. Allows to build type checking schemas easily. For know, only compiles to AJV schemas.

(This software has been written using Haskell)

Usage

Run:

npx type-schema-compiler [files]

It will produce one js file per schema file that exports AJV schemas ready to compile.

Example

schema status
number
---
schema productStore
{
  products: [{
    name: string,
    stars: number,
    price: number
  }],
  store: string
}
---
schema user
[{
  id: number,
  name: string,
  age: number,
  worth: number,
  friends: [{
    id: number
  }]
}]

It will compile into a file of this shape

// schemaList.js
export const status = { type: "number" };
export const productStore = {type: ...};
export const user = {type: ...};

You can import them within a parent file and insert them in AJV compiler and move from there

import { status, productStore, user } from "./schemaList";
import Ajv from "ajv";

const ajv = new Ajv();

const statusValidator = ajv.compile(status);
const productValidator = ajv.compile(productStore);
const userValidator = ajv.compile(user);

const data = // .... the data to validate

const valid = productValidator.validate(data);

if (valid) {
  // ...
}

TODO

  • <input disabled="" type="checkbox"> Improve error messaging
  • <input disabled="" type="checkbox"> Improve export system
    • <input disabled="" type="checkbox"> Add the possibility to have API routes as schema names
    • <input disabled="" type="checkbox"> Make the compilation process within the export
  • <input disabled="" type="checkbox"> Control output folder
  • <input disabled="" type="checkbox"> Add more library choice
  • <input disabled="" type="checkbox"> Add watch mode
  • <input disabled="" type="checkbox"> Improve the complexity of the parsing algorithm
  • <input disabled="" type="checkbox"> Improve error catching
    • <input disabled="" type="checkbox"> Reserved keyword
    • <input disabled="" type="checkbox"> Distinct schema names
  • <input disabled="" type="checkbox"> Improve generality
    • <input disabled="" type="checkbox"> More general object fields
    • <input disabled="" type="checkbox"> Add tuples
    • <input disabled="" type="checkbox"> Add checks

Feel free to contribute and suggest more features.