@schemat/parser-sequelize
v0.2.1
Published
Sequelize parser for Schemat (Model.define / Model.init -> IR, static AST).
Maintainers
Readme
@schemat/parser-sequelize
Sequelize parser for Schemat: turns
Sequelize models into the canonical Schemat IR by statically parsing the
TypeScript/JavaScript (via ts-morph) — it never connects to a database or
runs your code.
Supported shapes
sequelize.define('Name', attributes, options)Model.init(attributes, { sequelize, modelName, tableName })- Associations:
belongsTo,hasMany,hasOne,belongsToMany
Install
npm i @schemat/parser-sequelizeUsage
import { sequelizeParser } from "@schemat/parser-sequelize";
const result = await sequelizeParser.parse({ projectPath: "." });
// result.schema is an IRSchema; result.warnings are non-fatal diagnosticsLimitations (v1)
- Static parse only. Attributes built at runtime — spread from a shared
object, computed in a loop, or returned by a factory — are not visible. Only
literal attribute objects in
sequelize.define(...)/Model.init(...)are read. - Synthetic FK naming. When an association has no explicit
foreignKey, the column is assumed to be<model>Idtargetingid. An unconventional naming strategy needsforeignKeyspelled out. hasManyinverse sides are skipped so abelongsTo/hasManypair yields one edge, not two.belongsToManyemits amany-to-manyedge without the join table, even whenthroughnames a real model.- Associations whose target cannot be resolved to a parsed model are skipped with a warning rather than emitted as a dangling edge.
License
MIT © Ali Reza Hamid
