@@ -45,17 +45,19 @@ const transformFields = (fields: DMMF.Field[]) => {
45
45
} ;
46
46
} ;
47
47
48
- const transformModel = ( model : DMMF . Model , dependant : string | null = null ) => {
48
+ const transformModel = ( model : DMMF . Model , models ?: DMMF . Model [ ] ) => {
49
49
const fields = transformFields ( model . fields ) ;
50
50
let raw = [
51
- `${ dependant ? '' : `export const ${ model . name } = ` } Type.Object({\n\t` ,
51
+ `${ models ? '' : `export const ${ model . name } = ` } Type.Object({\n\t` ,
52
52
fields . rawString ,
53
53
'})' ,
54
54
] . join ( '\n' ) ;
55
55
56
- if ( typeof dependant === 'string' ) {
57
- const re = new RegExp ( `.+::${ dependant } .+\n` ) ;
58
- raw = raw . replace ( re , '' ) ;
56
+ if ( Array . isArray ( models ) ) {
57
+ models . forEach ( ( md ) => {
58
+ const re = new RegExp ( `.+::${ md . name } .+\n` , 'gm' ) ;
59
+ raw = raw . replace ( re , '' ) ;
60
+ } ) ;
59
61
}
60
62
61
63
return {
@@ -91,7 +93,7 @@ export function transformDMMF(dmmf: DMMF.Document) {
91
93
[ ...deps ] . forEach ( ( d ) => {
92
94
const depsModel = models . find ( ( m ) => m . name === d ) as DMMF . Model ;
93
95
if ( depsModel ) {
94
- const replacer = transformModel ( depsModel , model . name ) ;
96
+ const replacer = transformModel ( depsModel , models ) ;
95
97
const re = new RegExp ( `::${ d } ::` , 'gm' ) ;
96
98
raw = raw . replace ( re , replacer . raw ) ;
97
99
}
0 commit comments