@schemat/parser-mikroorm
v0.2.1
Published
MikroORM parser for Schemat (entity decorators -> IR, static AST).
Maintainers
Readme
@schemat/parser-mikroorm
MikroORM parser for Schemat: turns
MikroORM entity classes into the canonical Schemat IR by statically parsing the
TypeScript (via ts-morph) — it never connects to a database or runs code.
Install
npm i @schemat/parser-mikroormUsage
import { mikroormParser } from "@schemat/parser-mikroorm";
const ir = await mikroormParser.parse({ projectPath: "." });mikroormParser implements the SchemaParser interface (detect + parse)
from @schemat/core.
Detection
Detects a MikroORM project when any of these hold:
- a
@mikro-orm/*package is inpackage.jsondeps, or - a source file imports from
@mikro-orm/core(or any@mikro-orm/*).
A @Entity decorator alone is not enough — a @mikro-orm import signal is
required so TypeORM projects (which also use @Entity) aren't mis-detected.
What it maps
@Entity()classes → tables (name from@Entity({ tableName }), else the class name)@PrimaryKey→ primary-key columns;@Property→ columns (nullable,unique,default,type/fieldName/name,comment)@Enum(() => SomeEnum)→ an enum resolved from theenumdeclaration;@Enum({ items: ['a','b'] })→ a synthetic<table>_<col>_enum- Relations:
@ManyToOne→one-to-many(FK owner),@OneToOne(owner) →one-to-one,@ManyToMany(owner, nomappedBy) →many-to-many;@OneToManyandmappedByinverse sides are skipped to avoid duplicate edges - Relation targets referenced by class (
() => User) resolve to that entity's real table name
Limitations (v1)
- Synthetic FK column naming (
<property>Id→['id']); explicit@ManyToOne({ joinColumn })/referencedColumnNameand composite keys aren't read yet. - Relations to a class that isn't a parsed
@Entityare skipped rather than emitted as a dangling edge. @Enumvalues referenced from anenumdeclaration outside the parsed files resolve to no enum node (the column keeps the referenced type name).
License
MIT © Ali Reza Hamid
