File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
packages/schema/src/language-server
tests/integration/tests/cli Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -105,7 +105,19 @@ export class ZModelFormatter extends AbstractFormatter {
105
105
}
106
106
107
107
private getFieldTypeLength ( field : ast . DataModelField ) {
108
- let length = ( field . type . type || field . type . reference ?. $refText ) ! . length ;
108
+ let length : number ;
109
+
110
+ if ( field . type . type ) {
111
+ length = field . type . type . length ;
112
+ } else if ( field . type . reference ) {
113
+ length = field . type . reference . $refText . length ;
114
+ } else if ( field . type . unsupported ) {
115
+ const name = `Unsupported("${ field . type . unsupported . value . value } ")` ;
116
+ length = name . length ;
117
+ } else {
118
+ // we shouldn't get here
119
+ length = 1 ;
120
+ }
109
121
110
122
if ( field . type . optional ) {
111
123
length += 1 ;
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ describe('CLI format test', () => {
22
22
const model = `
23
23
datasource db {provider="sqlite" url="file:./dev.db"}
24
24
generator client {provider = "prisma-client-js"}
25
- model Post {id Int @id() @default(autoincrement())users User[]}` ;
25
+ model Post {id Int @id() @default(autoincrement())users User[]foo Unsupported("foo") }` ;
26
26
27
27
const formattedModel = `
28
28
datasource db {
@@ -35,6 +35,7 @@ generator client {
35
35
model Post {
36
36
id Int @id() @default(autoincrement())
37
37
users User[]
38
+ foo Unsupported("foo")
38
39
}` ;
39
40
// set up schema
40
41
fs . writeFileSync ( 'schema.zmodel' , model , 'utf-8' ) ;
@@ -48,7 +49,7 @@ model Post {
48
49
const model = `
49
50
datasource db {provider="sqlite" url="file:./dev.db"}
50
51
generator client {provider = "prisma-client-js"}
51
- model Post {id Int @id() @default(autoincrement())users User[]}` ;
52
+ model Post {id Int @id() @default(autoincrement())users User[]foo Unsupported("foo") }` ;
52
53
53
54
const formattedModel = `
54
55
datasource db {
@@ -59,8 +60,9 @@ generator client {
59
60
provider = "prisma-client-js"
60
61
}
61
62
model Post {
62
- id Int @id() @default(autoincrement())
63
+ id Int @id() @default(autoincrement())
63
64
users User[]
65
+ foo Unsupported("foo")
64
66
}` ;
65
67
// set up schema
66
68
fs . writeFileSync ( 'schema.zmodel' , model , 'utf-8' ) ;
You can’t perform that action at this time.
0 commit comments