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 {
105105 }
106106
107107 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+ }
109121
110122 if ( field . type . optional ) {
111123 length += 1 ;
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ describe('CLI format test', () => {
2222 const model = `
2323 datasource db {provider="sqlite" url="file:./dev.db"}
2424 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") }` ;
2626
2727 const formattedModel = `
2828datasource db {
@@ -35,6 +35,7 @@ generator client {
3535model Post {
3636 id Int @id() @default(autoincrement())
3737 users User[]
38+ foo Unsupported("foo")
3839}` ;
3940 // set up schema
4041 fs . writeFileSync ( 'schema.zmodel' , model , 'utf-8' ) ;
@@ -48,7 +49,7 @@ model Post {
4849 const model = `
4950 datasource db {provider="sqlite" url="file:./dev.db"}
5051 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") }` ;
5253
5354 const formattedModel = `
5455datasource db {
@@ -59,8 +60,9 @@ generator client {
5960 provider = "prisma-client-js"
6061}
6162model Post {
62- id Int @id() @default(autoincrement())
63+ id Int @id() @default(autoincrement())
6364 users User[]
65+ foo Unsupported("foo")
6466}` ;
6567 // set up schema
6668 fs . writeFileSync ( 'schema.zmodel' , model , 'utf-8' ) ;
You can’t perform that action at this time.
0 commit comments