@@ -21,34 +21,40 @@ export const generateOutput = (dmmfDocument: DmmfDocument, project: Project, out
2121    const  args : string [ ]  =  [ ] 
2222    const  outputs : string [ ]  =  [ ] 
2323    const  enums : string [ ]  =  [ ] 
24-     outputTypesToGenerate 
25-       . filter ( ( type )  =>  type . modelName  !==  model . name ) 
26-       . forEach ( ( type )  =>  { 
27-         // import args 
28-         for  ( const  item  of  [ ...new  Set ( type . fields . filter ( ( it )  =>  it . argsTypeName ) . map ( ( it )  =>  it . argsTypeName ! ) ) ] . sort ( ) )  { 
29-           if  ( ! args . includes ( item ) )  args . push ( item ) 
30-         } 
31-         // import outputs 
32-         for  ( const  item  of  [ 
33-           ...new  Set ( type . fields . filter ( ( field )  =>  field . outputType . location  ===  'outputObjectTypes' ) . map ( ( field )  =>  field . outputType . type ) ) , 
34-         ] . sort ( ) )  { 
35-           if  ( ! outputs . includes ( item ) )  outputs . push ( item ) 
36-         } 
37-         // import enums 
38-         for  ( const  item  of  [ 
39-           ...new  Set ( 
40-             type . fields 
41-               . map ( ( field )  =>  field . outputType ) 
42-               . filter ( ( fieldType )  =>  fieldType . location  ===  'enumTypes' ) 
43-               . map ( ( fieldType )  =>  fieldType . type ) , 
44-           ) , 
45-         ] . sort ( ) )  { 
46-           if  ( ! enums . includes ( item ) )  enums . push ( item ) 
47-         } 
48-       } ) 
49-     if  ( args . length )  sourceFile . addImportDeclaration ( {  moduleSpecifier : path . posix . join ( '.' ,  `${ modelName }  ) ,  namedImports : args  } ) 
50-     if  ( outputs . length )  sourceFile . addImportDeclaration ( {  moduleSpecifier : path . posix . join ( '.' ,  `${ modelName }  ) ,  namedImports : outputs  } ) 
51-     if  ( enums . length )  sourceFile . addImportDeclaration ( {  moduleSpecifier : path . posix . join ( '.' ,  `${ modelName }  ) ,  namedImports : enums  } ) 
24+     outputTypesToGenerate . forEach ( ( type )  =>  { 
25+       // import args 
26+       for  ( const  item  of  [ ...new  Set ( type . fields . filter ( ( it )  =>  it . argsTypeName ) . map ( ( it )  =>  it . argsTypeName ! ) ) ] . sort ( ) )  { 
27+         if  ( ! args . includes ( item ) )  args . push ( item ) 
28+       } 
29+       // import outputs 
30+       for  ( const  item  of  [ 
31+         ...new  Set ( type . fields . filter ( ( field )  =>  field . outputType . location  ===  'outputObjectTypes' ) . map ( ( field )  =>  field . outputType . type ) ) , 
32+       ] . sort ( ) )  { 
33+         if  ( ! outputs . includes ( item ) )  outputs . push ( item ) 
34+       } 
35+       // import enums 
36+       for  ( const  item  of  [ 
37+         ...new  Set ( 
38+           type . fields 
39+             . map ( ( field )  =>  field . outputType ) 
40+             . filter ( ( fieldType )  =>  fieldType . location  ===  'enumTypes'  &&  fieldType . namespace  ===  'model' ) 
41+             . map ( ( fieldType )  =>  fieldType . type ) , 
42+         ) , 
43+       ] . sort ( ) )  { 
44+         if  ( ! enums . includes ( item ) )  enums . push ( item ) 
45+       } 
46+     } ) 
47+     if  ( args . length )  sourceFile . addImportDeclaration ( {  moduleSpecifier : path . posix . join ( '..' ,  `${ modelName }  ) ,  namedImports : args  } ) 
48+     if  ( outputs . length )  { 
49+       for  ( const  item  of  [ ...new  Set ( outputs ) ] . sort ( ) )  { 
50+         sourceFile . addImportDeclaration ( {  moduleSpecifier : `./${ item }  ,  namedImports : [ item ]  } ) 
51+       } 
52+     } 
53+     if  ( enums . length )  { 
54+       for  ( const  item  of  [ ...new  Set ( enums ) ] . sort ( ) )  { 
55+         sourceFile . addImportDeclaration ( {  moduleSpecifier : path . posix . join ( `../../enums/${ item }  ) ,  namedImports : [ item ]  } ) 
56+       } 
57+     } 
5258
5359    sourceFile . addClass ( { 
5460      name : type . typeName , 
0 commit comments