@ork-orm/schema-parser
v0.0.1-alpha.1
Published
TypeScript-native Prisma Schema Language parser for Ork ORM
Readme
@ork-orm/schema-parser
TypeScript-native Prisma Schema Language parser for Ork ORM.
Overview
This package provides a complete TypeScript-native implementation for parsing Prisma Schema Language (PSL) files, replacing the Rust-based schema engine with a lightweight, extensible TypeScript solution.
Features
- Pure TypeScript: No binary dependencies, runs anywhere Node.js runs
- AST Generation: Converts PSL into structured Abstract Syntax Trees
- Code Generation: Generates TypeScript interfaces and types from schemas
- Error Handling: Comprehensive error reporting with source locations
- ESM-only: Modern ES module architecture
Installation
pnpm add @ork-orm/schema-parserUsage
import { parseSchema } from '@ork-orm/schema-parser'
const schema = `
datasource db {
provider = "postgresql"
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
`
const result = parseSchema(schema)
if (result.errors.length === 0) {
console.log('Schema parsed successfully:', result.ast)
} else {
console.error('Parse errors:', result.errors)
}API Reference
parseSchema(schema: string, options?: ParseOptions): ParseResult
Main parsing function that converts PSL source code into an AST.
Parameters
schema: The Prisma schema source code as a stringoptions: Optional parsing configuration
Returns
ParseResultcontaining the AST and any parsing errors
Classes
Lexer: Tokenizes PSL source codeParser: Converts tokens into AST nodesCodeGenerator: Generates TypeScript code from AST
Development
This package is part of the Ork ORM project and follows its development conventions:
# Build the package
pnpm build
# Run tests
pnpm test
# Development mode with watching
pnpm devArchitecture
The parser consists of three main phases:
- Lexical Analysis (
Lexer): Converts source text into tokens - Parsing (
Parser): Builds AST from tokens - Code Generation (
CodeGenerator): Generates TypeScript from AST
License
Apache-2.0
