@vibeorm/schema
v5.11.0
Published
Canonical schema IR, validation, dialect/capability types, and error codes for VibeORM v2
Maintainers
Readme
@vibeorm/schema
Part of VibeORM — a type-safe TypeScript ORM for Bun and Node. Prisma-schema or TypeScript-DSL input, a canonical schema IR, a generated client, and a dialect-aware SQL layer over PostgreSQL, PGlite, SQLite and MySQL.
The canonical Schema IR: the data shape every other VibeORM package reads. It exists as its own package because the parser, the DSL, the generator, migrate and the runtime all need the same schema type without depending on each other.
bun add @vibeorm/schemaStable.
2.0.0, published under thelatestdist-tag. The v1 line stays installable asvibeorm@1.
Most users never install this directly — it ships as a dependency of vibeorm. Reach for it when you are building tooling on the IR or SQL layer.
What it exports
- The IR types:
SchemaIR,ModelIR,FieldIR,RelationIR,IndexIR,IndexFieldIR,EnumIR,DatasourceIR,ExtensionDeclIR, plus the enumerationsFieldType,ScalarType,RelationType,IndexKind,CascadeAction,DefaultValueIR. Helpers:isEnumType,providerToDialect,DIALECTS. - Validation:
validateSchemaIR({ schema })returnsValidationIssue[];assertValidSchemaIRthrows instead. Both are shared by the parser and the DSL, so an IR built either way is held to one set of structural rules. - Dialect identity: the
ProviderandDialecttypes, and theDialectCapabilities/FullTextEngineshapes. The capability tables themselves live in@vibeorm/sql; this package only fixes their shape. - Errors:
VibeError, theVibeErrorCodeunion, theVIBE_ERROR_CODESlist, and the constructorsinternalErrorandunsupportedCapability. Every error VibeORM throws is aVibeErrorwith a stablecode, so callers branch on codes and never on message text. - Reserved names:
RESERVED_CLIENT_NAMES,RESERVED_DELEGATE_NAMES,isReservedClientName,isReservedDelegateName— the collision guard between user models and the client surface. - The implicit many-to-many rule:
implicitJoinTableandImplicitJoinTable. One shared definition of the join table an implicit m2m relation maps to, used by the parser and by migrate. Self relations are refused rather than supported (validateSchemaIRruleimplicit-self-many-to-many): one model name on both ends means both relation fields would own column"A". The function still derives a self join table's NAME, because introspection and the migration differ must recognise one that already exists in a database. - The extension framework:
defineExtension,buildExtensionRegistry,extensionDeclarations,mergeExtensionDeclarations,extensionManifestEntry,extensionOptionsHash,EMPTY_EXTENSION_REGISTRY, and theVibeExtension/ExtensionRegistrytypes.
The error codes
| Code | Meaning |
|---|---|
| VIBE_NOT_FOUND | findUniqueOrThrow / findFirstOrThrow / update / delete target missing |
| VIBE_UNIQUE_VIOLATION | unique constraint violation (driver-mapped) |
| VIBE_FK_VIOLATION | foreign key constraint violation (driver-mapped) |
| VIBE_VALIDATION | input failed validation before reaching the database |
| VIBE_SCHEMA_INVALID | schema failed structural validation |
| VIBE_UNSUPPORTED_CAPABILITY | feature requested on a dialect that does not support it |
| VIBE_STALE_CLIENT | generated client is stale relative to config/schema |
| VIBE_CONFIG | configuration problem (config file, flags, env) |
| VIBE_MIGRATION | migration engine failure, including checksum mismatch |
| VIBE_TRANSACTION | transaction begin/commit/rollback/serialization failure |
| VIBE_ADAPTER | driver or connection failure without a more specific code |
| VIBE_INTERNAL | invariant broken inside VibeORM; always a bug |
Why the IR is the only currency
Both schema inputs compile to SchemaIR: the .prisma parser (@vibeorm/parser) and the TypeScript DSL (@vibeorm/dsl). Nothing downstream parses schema text.
The generator, migrate and the runtime read the IR and only the IR. That is what makes the two input formats interchangeable, and what makes vibeorm convert a mechanical translation in both directions rather than a rewrite.
