@@ -9,11 +9,12 @@ import { isPrimitivePrismaFieldType } from "./primitiveField";
99import { wrapWithArray } from "./wrappers/array" ;
1010import { wrapWithNullable } from "./wrappers/nullable" ;
1111import { wrapWithPartial } from "./wrappers/partial" ;
12+ import { processedComposites } from "./composite" ;
1213
1314export const processedRelations : ProcessedModel [ ] = [ ] ;
1415
1516export function processRelations (
16- models : DMMF . Model [ ] | Readonly < DMMF . Model [ ] > ,
17+ models : DMMF . Model [ ] | Readonly < DMMF . Model [ ] >
1718) {
1819 for ( const m of models ) {
1920 const o = stringifyRelations ( m ) ;
@@ -35,13 +36,14 @@ export function stringifyRelations(data: DMMF.Model) {
3536 if (
3637 annotations . isHidden ||
3738 isPrimitivePrismaFieldType ( field . type ) ||
38- processedEnums . find ( ( e ) => e . name === field . type )
39+ processedEnums . find ( ( e ) => e . name === field . type ) ||
40+ processedComposites . find ( ( c ) => c . name === field . type )
3941 ) {
4042 return undefined ;
4143 }
4244
4345 let stringifiedType = processedPlain . find (
44- ( e ) => e . name === field . type ,
46+ ( e ) => e . name === field . type
4547 ) ?. stringRepresentation ;
4648
4749 if ( ! stringifiedType ) {
@@ -61,14 +63,14 @@ export function stringifyRelations(data: DMMF.Model) {
6163 . filter ( ( x ) => x ) as string [ ] ;
6264
6365 return `${ getConfig ( ) . typeboxImportVariableName } .Object({${ fields . join (
64- "," ,
66+ ","
6567 ) } },${ generateTypeboxOptions ( { input : annotations } ) } )\n`;
6668}
6769
6870export const processedRelationsInputCreate : ProcessedModel [ ] = [ ] ;
6971
7072export function processRelationsInputCreate (
71- models : DMMF . Model [ ] | Readonly < DMMF . Model [ ] > ,
73+ models : DMMF . Model [ ] | Readonly < DMMF . Model [ ] >
7274) {
7375 for ( const m of models ) {
7476 const o = stringifyRelationsInputCreate ( m , models ) ;
@@ -84,7 +86,7 @@ export function processRelationsInputCreate(
8486
8587export function stringifyRelationsInputCreate (
8688 data : DMMF . Model ,
87- allModels : DMMF . Model [ ] | Readonly < DMMF . Model [ ] > ,
89+ allModels : DMMF . Model [ ] | Readonly < DMMF . Model [ ] >
8890) {
8991 const annotations = extractAnnotations ( data . documentation ) ;
9092 if (
@@ -110,10 +112,10 @@ export function stringifyRelationsInputCreate(
110112
111113 let typeboxIdType = "String" ;
112114
113- switch (
114- allModels . find ( ( m ) => m . name === field . type ) ?. fields . find ( ( f ) => f . isId )
115- ?. type
116- ) {
115+ const t = allModels
116+ . find ( ( m ) => m . name === field . type )
117+ ?. fields . find ( ( f ) => f . isId ) ?. type ;
118+ switch ( t ) {
117119 case "String" :
118120 typeboxIdType = "String" ;
119121 break ;
@@ -124,7 +126,7 @@ export function stringifyRelationsInputCreate(
124126 typeboxIdType = "Integer" ;
125127 break ;
126128 default :
127- throw new Error ( " Unsupported id type" ) ;
129+ throw new Error ( ` Unsupported id type: ' ${ t } '` ) ;
128130 }
129131
130132 let connectString = `${ getConfig ( ) . typeboxImportVariableName } .Object({
@@ -152,14 +154,14 @@ export function stringifyRelationsInputCreate(
152154 . filter ( ( x ) => x ) as string [ ] ;
153155
154156 return `${ getConfig ( ) . typeboxImportVariableName } .Object({${ fields . join (
155- "," ,
157+ ","
156158 ) } },${ generateTypeboxOptions ( { input : annotations } ) } )\n`;
157159}
158160
159161export const processedRelationsInputUpdate : ProcessedModel [ ] = [ ] ;
160162
161163export function processRelationsInputUpdate (
162- models : DMMF . Model [ ] | Readonly < DMMF . Model [ ] > ,
164+ models : DMMF . Model [ ] | Readonly < DMMF . Model [ ] >
163165) {
164166 for ( const m of models ) {
165167 const o = stringifyRelationsInputUpdate ( m , models ) ;
@@ -175,7 +177,7 @@ export function processRelationsInputUpdate(
175177
176178export function stringifyRelationsInputUpdate (
177179 data : DMMF . Model ,
178- allModels : DMMF . Model [ ] | Readonly < DMMF . Model [ ] > ,
180+ allModels : DMMF . Model [ ] | Readonly < DMMF . Model [ ] >
179181) {
180182 const annotations = extractAnnotations ( data . documentation ) ;
181183 if (
@@ -201,10 +203,10 @@ export function stringifyRelationsInputUpdate(
201203
202204 let typeboxIdType = "String" ;
203205
204- switch (
205- allModels . find ( ( m ) => m . name === field . type ) ?. fields . find ( ( f ) => f . isId )
206- ?. type
207- ) {
206+ const t = allModels
207+ . find ( ( m ) => m . name === field . type )
208+ ?. fields . find ( ( f ) => f . isId ) ?. type ;
209+ switch ( t ) {
208210 case "String" :
209211 typeboxIdType = "String" ;
210212 break ;
@@ -215,7 +217,7 @@ export function stringifyRelationsInputUpdate(
215217 typeboxIdType = "Integer" ;
216218 break ;
217219 default :
218- throw new Error ( " Unsupported id type" ) ;
220+ throw new Error ( ` Unsupported id type: ' ${ t } '` ) ;
219221 }
220222
221223 let stringifiedType : string ;
@@ -264,7 +266,7 @@ export function stringifyRelationsInputUpdate(
264266
265267 return wrapWithPartial (
266268 `${ getConfig ( ) . typeboxImportVariableName } .Object({${ fields . join (
267- "," ,
268- ) } },${ generateTypeboxOptions ( { input : annotations } ) } )`,
269+ ","
270+ ) } },${ generateTypeboxOptions ( { input : annotations } ) } )`
269271 ) ;
270272}
0 commit comments