@@ -80,7 +80,7 @@ export class Generator {
8080}
8181
8282export class DeclarationBase {
83- public documentations : string [ ] = [ ] ;
83+ constructor ( public documentations : string [ ] = [ ] ) { }
8484
8585 addComment ( name : string ) : string {
8686 this . documentations . push ( name ) ;
@@ -91,26 +91,38 @@ export class DeclarationBase {
9191 return this . documentations . map ( ( x ) => `${ x } \n` ) . join ( '' ) ;
9292 }
9393}
94- export class Model extends DeclarationBase {
94+
95+ export class ContainerDeclaration extends DeclarationBase {
96+ constructor ( documentations : string [ ] = [ ] , public attributes : ( ContainerAttribute | PassThroughAttribute ) [ ] = [ ] ) {
97+ super ( documentations ) ;
98+ }
99+ }
100+
101+ export class FieldDeclaration extends DeclarationBase {
102+ constructor ( documentations : string [ ] = [ ] , public attributes : ( FieldAttribute | PassThroughAttribute ) [ ] = [ ] ) {
103+ super ( documentations ) ;
104+ }
105+ }
106+
107+ export class Model extends ContainerDeclaration {
95108 public fields : ModelField [ ] = [ ] ;
96- public attributes : ModelAttribute [ ] = [ ] ;
97- constructor ( public name : string , public documentations : string [ ] = [ ] ) {
98- super ( ) ;
109+ constructor ( public name : string , documentations : string [ ] = [ ] ) {
110+ super ( documentations ) ;
99111 }
100112
101113 addField (
102114 name : string ,
103115 type : ModelFieldType | string ,
104- attributes : FieldAttribute [ ] = [ ] ,
116+ attributes : ( FieldAttribute | PassThroughAttribute ) [ ] = [ ] ,
105117 documentations : string [ ] = [ ]
106118 ) : ModelField {
107119 const field = new ModelField ( name , type , attributes , documentations ) ;
108120 this . fields . push ( field ) ;
109121 return field ;
110122 }
111123
112- addAttribute ( name : string , args : AttributeArg [ ] = [ ] ) : ModelAttribute {
113- const attr = new ModelAttribute ( name , args ) ;
124+ addAttribute ( name : string , args : AttributeArg [ ] = [ ] ) {
125+ const attr = new ContainerAttribute ( name , args ) ;
114126 this . attributes . push ( attr ) ;
115127 return attr ;
116128 }
@@ -145,14 +157,14 @@ export class ModelFieldType {
145157 }
146158}
147159
148- export class ModelField extends DeclarationBase {
160+ export class ModelField extends FieldDeclaration {
149161 constructor (
150162 public name : string ,
151163 public type : ModelFieldType | string ,
152- public attributes : FieldAttribute [ ] = [ ] ,
153- public documentations : string [ ] = [ ]
164+ attributes : ( FieldAttribute | PassThroughAttribute ) [ ] = [ ] ,
165+ documentations : string [ ] = [ ]
154166 ) {
155- super ( ) ;
167+ super ( documentations , attributes ) ;
156168 }
157169
158170 addAttribute ( name : string , args : AttributeArg [ ] = [ ] ) : FieldAttribute {
@@ -178,14 +190,25 @@ export class FieldAttribute {
178190 }
179191}
180192
181- export class ModelAttribute {
193+ export class ContainerAttribute {
182194 constructor ( public name : string , public args : AttributeArg [ ] = [ ] ) { }
183195
184196 toString ( ) : string {
185197 return `${ this . name } (` + this . args . map ( ( a ) => a . toString ( ) ) . join ( ', ' ) + `)` ;
186198 }
187199}
188200
201+ /**
202+ * Represents @@prisma.passthrough and @prisma.passthrough
203+ */
204+ export class PassThroughAttribute {
205+ constructor ( public text : string ) { }
206+
207+ toString ( ) : string {
208+ return this . text ;
209+ }
210+ }
211+
189212export class AttributeArg {
190213 constructor ( public name : string | undefined , public value : AttributeArgValue ) { }
191214
@@ -287,22 +310,25 @@ export class FunctionCallArg {
287310 }
288311}
289312
290- export class Enum extends DeclarationBase {
313+ export class Enum extends ContainerDeclaration {
291314 public fields : EnumField [ ] = [ ] ;
292- public attributes : ModelAttribute [ ] = [ ] ;
293315
294316 constructor ( public name : string , public documentations : string [ ] = [ ] ) {
295- super ( ) ;
317+ super ( documentations ) ;
296318 }
297319
298- addField ( name : string , attributes : FieldAttribute [ ] = [ ] , documentations : string [ ] = [ ] ) : EnumField {
320+ addField (
321+ name : string ,
322+ attributes : ( FieldAttribute | PassThroughAttribute ) [ ] = [ ] ,
323+ documentations : string [ ] = [ ]
324+ ) : EnumField {
299325 const field = new EnumField ( name , attributes , documentations ) ;
300326 this . fields . push ( field ) ;
301327 return field ;
302328 }
303329
304- addAttribute ( name : string , args : AttributeArg [ ] = [ ] ) : ModelAttribute {
305- const attr = new ModelAttribute ( name , args ) ;
330+ addAttribute ( name : string , args : AttributeArg [ ] = [ ] ) {
331+ const attr = new ContainerAttribute ( name , args ) ;
306332 this . attributes . push ( attr ) ;
307333 return attr ;
308334 }
@@ -323,7 +349,11 @@ export class Enum extends DeclarationBase {
323349}
324350
325351export class EnumField extends DeclarationBase {
326- constructor ( public name : string , public attributes : FieldAttribute [ ] = [ ] , public documentations : string [ ] = [ ] ) {
352+ constructor (
353+ public name : string ,
354+ public attributes : ( FieldAttribute | PassThroughAttribute ) [ ] = [ ] ,
355+ public documentations : string [ ] = [ ]
356+ ) {
327357 super ( ) ;
328358 }
329359
0 commit comments