@vibeorm/parser 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -0
- package/package.json +42 -0
- package/src/index.ts +27 -0
- package/src/parser.ts +688 -0
- package/src/schema-validator.ts +625 -0
- package/src/types.ts +223 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @vibeorm/parser
|
|
2
|
+
|
|
3
|
+
Prisma schema parser for VibeORM. Parses `.prisma` files into a typed intermediate representation (IR) used by the generator, migrate, and CLI packages.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @vibeorm/parser
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { parsePrismaSchema, validateSchema, formatValidationErrors } from "@vibeorm/parser";
|
|
15
|
+
|
|
16
|
+
const schema = parsePrismaSchema({
|
|
17
|
+
source: `
|
|
18
|
+
model User {
|
|
19
|
+
id Int @id @default(autoincrement())
|
|
20
|
+
email String @unique
|
|
21
|
+
name String?
|
|
22
|
+
posts Post[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
model Post {
|
|
26
|
+
id Int @id @default(autoincrement())
|
|
27
|
+
title String
|
|
28
|
+
authorId Int
|
|
29
|
+
author User @relation(fields: [authorId], references: [id])
|
|
30
|
+
}
|
|
31
|
+
`,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Validate the parsed schema
|
|
35
|
+
const result = validateSchema({ schema });
|
|
36
|
+
if (!result.valid) {
|
|
37
|
+
console.error(formatValidationErrors({ result }));
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
### `parsePrismaSchema({ source })`
|
|
44
|
+
|
|
45
|
+
Parses a raw `.prisma` string into a `Schema` object containing models and enums with fully resolved relations.
|
|
46
|
+
|
|
47
|
+
### `validateSchema({ schema })`
|
|
48
|
+
|
|
49
|
+
Performs semantic validation on a parsed schema — checks for missing primary keys, dangling relations, FK type mismatches, and more. Returns a `ValidationResult` with errors and warnings.
|
|
50
|
+
|
|
51
|
+
### `formatValidationErrors({ result })`
|
|
52
|
+
|
|
53
|
+
Formats a `ValidationResult` into human-readable output for CLI display.
|
|
54
|
+
|
|
55
|
+
### Constants
|
|
56
|
+
|
|
57
|
+
- `PRISMA_TO_TS` — maps Prisma scalar types to TypeScript types
|
|
58
|
+
- `PRISMA_TO_PG` — maps Prisma scalar types to PostgreSQL types
|
|
59
|
+
|
|
60
|
+
### Types
|
|
61
|
+
|
|
62
|
+
The package exports all IR types: `Schema`, `Model`, `Field`, `ScalarField`, `EnumField`, `RelationField`, `RelationInfo`, `RelationType`, `PrimaryKey`, `UniqueConstraint`, `IndexDefinition`, `Enum`, `EnumValue`, `DefaultValue`, `PrismaScalarType`, `TypeScriptType`, `PostgresType`, `ValidationResult`, `SchemaValidationError`, `ValidationSeverity`.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
[MIT](../../LICENSE)
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vibeorm/parser",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Prisma schema parser for VibeORM — parses .prisma files into a typed intermediate representation",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"orm",
|
|
8
|
+
"parser",
|
|
9
|
+
"prisma",
|
|
10
|
+
"bun",
|
|
11
|
+
"typescript",
|
|
12
|
+
"postgresql"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"default": "./src/index.ts",
|
|
18
|
+
"types": "./src/index.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/vibeorm/vibeorm.git",
|
|
27
|
+
"directory": "packages/parser"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/vibeorm/vibeorm/tree/master/packages/parser",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/vibeorm/vibeorm/issues"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"bun": ">=1.1.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@mrleebo/prisma-ast": "^0.13.1"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { parsePrismaSchema } from "./parser.ts";
|
|
2
|
+
export { validateSchema, formatValidationErrors } from "./schema-validator.ts";
|
|
3
|
+
export type {
|
|
4
|
+
ValidationResult,
|
|
5
|
+
SchemaValidationError,
|
|
6
|
+
ValidationSeverity,
|
|
7
|
+
} from "./schema-validator.ts";
|
|
8
|
+
export type {
|
|
9
|
+
Schema,
|
|
10
|
+
Model,
|
|
11
|
+
Field,
|
|
12
|
+
ScalarField,
|
|
13
|
+
EnumField,
|
|
14
|
+
RelationField,
|
|
15
|
+
RelationInfo,
|
|
16
|
+
RelationType,
|
|
17
|
+
PrimaryKey,
|
|
18
|
+
UniqueConstraint,
|
|
19
|
+
IndexDefinition,
|
|
20
|
+
Enum,
|
|
21
|
+
EnumValue,
|
|
22
|
+
DefaultValue,
|
|
23
|
+
PrismaScalarType,
|
|
24
|
+
TypeScriptType,
|
|
25
|
+
PostgresType,
|
|
26
|
+
} from "./types.ts";
|
|
27
|
+
export { PRISMA_TO_TS, PRISMA_TO_PG } from "./types.ts";
|