Ontype is a simple schema language similar to TypeScript.
Below is a valid Ontype schema, highlighted using TypeScript syntax:
import "ontype/primitive.ontype"
type User {
@hogehoge
id: char
password: string @hidden
passwordSalt: string @hidden
}
type Todo {
id: char
title: string(10)
deadline?: datetime @nullable
authorId: User[id]
}
enum TodoStatus {
READY: 0
IN_PROGRESS: 1
DONE: "done"
}
import "ontype/primitive.ontype"
imports another Ontype file.type User {}
defines aUser
type.@hogehoge
is a type decorator forUser
.id: char
declares that theid
property is of typechar
.password: string @hidden
defines a property with a decorator@hidden
.deadline?: datetime @nullable
declares an optional propertydeadline
.authorId: User[id]
indicates thatauthorId
references theid
property ofUser
.enum TodoStatus
defines an enum namedTodoStatus
.READY: 0
assigns the value0
to theREADY
enum member.
This repository includes an Ontype parser, available as an npm package.
npm i ontype
import { parse } from "ontype";
const readStream = fs.createReadStream('./example.ontype', "utf-8");
const { errors, result } = await parse(readStream, {
enableAst: true,
ast: {
baseModels: [],
types: [],
enums: [],
},
enableSemanticTokens: true,
semanticTokens: [],
});
console.log(result.ast);
console.log(result.semanticTokens);
console.log(errors);