ontype
v1.0.14
Published
Ontype is a simple TypeScript-like schema language
Downloads
395
Readme
ontype
Ontype is a simple schema language similar to TypeScript.
Below is a valid Ontype schema, highlighted using TypeScript syntax:
type User {
id: char
password: string @hidden
passwordSalt: string @hidden
}
type Todo {
id: char
title: string(10)
deadline?: datetime @nullable
authorId: User[id]
status: TodoStatus
}
enum TodoStatus {
READY
IN_PROGRESS
DONE
}type User {}defines aUsertype.id: chardeclares that theidproperty is of typechar.password: string @hiddendefines a property with a decorator@hidden.deadline?: datetime @nullabledeclares an optional propertydeadline.authorId: User[id]indicates thatauthorIdreferences theidproperty ofUser.enum TodoStatusdefines an enum namedTodoStatus.READYis a member of the enum.
Parser
This repository includes an Ontype parser, available as an npm package.
npm i ontypeimport { parse } from "ontype";
const readStream = fs.createReadStream('./example.ontype', "utf-8");
const { errors, result } = await parse(readStream, {
enableSemanticTokens: true,
semanticTokens: [],
});
console.log(result.semanticTokens);
console.log(errors);