TypeScript-native Prisma Schema Language parser for Ork ORM
npm install @ork-orm/schema-parserTypeScript-native Prisma Schema Language parser for Ork ORM.
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.
- 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
``bash`
pnpm add @ork-orm/schema-parser
`typescript
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)
}
`
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
- ParseResult containing the AST and any parsing errors
- Lexer: Tokenizes PSL source codeParser
- : Converts tokens into AST nodesCodeGenerator
- : Generates TypeScript code from AST
This package is part of the Ork ORM project and follows its development conventions:
`bashBuild the package
pnpm build
Architecture
The parser consists of three main phases:
1. Lexical Analysis (
Lexer): Converts source text into tokens
2. Parsing (Parser): Builds AST from tokens
3. Code Generation (CodeGenerator`): Generates TypeScript from ASTApache-2.0