@@ -213,7 +213,7 @@ class RequestHandler extends APIHandlerBase {
213
213
}
214
214
215
215
buildUrlPatterns ( idDivider : string ) {
216
- const options = { segmentNameCharset : `a-zA-Z0-9-_~ %${ idDivider } ` } ;
216
+ const options = { segmentValueCharset : `a-zA-Z0-9-_~ %${ idDivider } ` } ;
217
217
return {
218
218
// collection operations
219
219
collection : new UrlPattern ( '/:type' , options ) ,
@@ -403,7 +403,7 @@ class RequestHandler extends APIHandlerBase {
403
403
return this . makeUnsupportedModelError ( type ) ;
404
404
}
405
405
406
- const args : any = { where : this . makeIdFilter ( typeInfo . idFields , resourceId ) } ;
406
+ const args : any = { where : this . makePrismaIdFilter ( typeInfo . idFields , resourceId ) } ;
407
407
408
408
// include IDs of relation fields so that they can be serialized
409
409
this . includeRelationshipIds ( type , args , 'include' ) ;
@@ -468,7 +468,7 @@ class RequestHandler extends APIHandlerBase {
468
468
469
469
select = select ?? { [ relationship ] : true } ;
470
470
const args : any = {
471
- where : this . makeIdFilter ( typeInfo . idFields , resourceId ) ,
471
+ where : this . makePrismaIdFilter ( typeInfo . idFields , resourceId ) ,
472
472
select,
473
473
} ;
474
474
@@ -526,7 +526,7 @@ class RequestHandler extends APIHandlerBase {
526
526
}
527
527
528
528
const args : any = {
529
- where : this . makeIdFilter ( typeInfo . idFields , resourceId ) ,
529
+ where : this . makePrismaIdFilter ( typeInfo . idFields , resourceId ) ,
530
530
select : this . makeIdSelect ( typeInfo . idFields ) ,
531
531
} ;
532
532
@@ -765,7 +765,7 @@ class RequestHandler extends APIHandlerBase {
765
765
if ( relationInfo . isCollection ) {
766
766
createPayload . data [ key ] = {
767
767
connect : enumerate ( data . data ) . map ( ( item : any ) => ( {
768
- [ this . makeIdKey ( relationInfo . idFields ) ] : item . id ,
768
+ [ this . makePrismaIdKey ( relationInfo . idFields ) ] : item . id ,
769
769
} ) ) ,
770
770
} ;
771
771
} else {
@@ -774,15 +774,15 @@ class RequestHandler extends APIHandlerBase {
774
774
}
775
775
createPayload . data [ key ] = {
776
776
connect : {
777
- [ this . makeIdKey ( relationInfo . idFields ) ] : data . data . id ,
777
+ [ this . makePrismaIdKey ( relationInfo . idFields ) ] : data . data . id ,
778
778
} ,
779
779
} ;
780
780
}
781
781
782
782
// make sure ID fields are included for result serialization
783
783
createPayload . include = {
784
784
...createPayload . include ,
785
- [ key ] : { select : { [ this . makeIdKey ( relationInfo . idFields ) ] : true } } ,
785
+ [ key ] : { select : { [ this . makePrismaIdKey ( relationInfo . idFields ) ] : true } } ,
786
786
} ;
787
787
}
788
788
}
@@ -819,7 +819,7 @@ class RequestHandler extends APIHandlerBase {
819
819
}
820
820
821
821
const updateArgs : any = {
822
- where : this . makeIdFilter ( typeInfo . idFields , resourceId ) ,
822
+ where : this . makePrismaIdFilter ( typeInfo . idFields , resourceId ) ,
823
823
select : {
824
824
...typeInfo . idFields . reduce ( ( acc , field ) => ( { ...acc , [ field . name ] : true } ) , { } ) ,
825
825
[ relationship ] : { select : this . makeIdSelect ( relationInfo . idFields ) } ,
@@ -854,7 +854,7 @@ class RequestHandler extends APIHandlerBase {
854
854
updateArgs . data = {
855
855
[ relationship ] : {
856
856
connect : {
857
- [ this . makeIdKey ( relationInfo . idFields ) ] : parsed . data . data . id ,
857
+ [ this . makePrismaIdKey ( relationInfo . idFields ) ] : parsed . data . data . id ,
858
858
} ,
859
859
} ,
860
860
} ;
@@ -878,7 +878,7 @@ class RequestHandler extends APIHandlerBase {
878
878
updateArgs . data = {
879
879
[ relationship ] : {
880
880
[ relationVerb ] : enumerate ( parsed . data . data ) . map ( ( item : any ) =>
881
- this . makeIdFilter ( relationInfo . idFields , item . id )
881
+ this . makePrismaIdFilter ( relationInfo . idFields , item . id )
882
882
) ,
883
883
} ,
884
884
} ;
@@ -919,7 +919,7 @@ class RequestHandler extends APIHandlerBase {
919
919
}
920
920
921
921
const updatePayload : any = {
922
- where : this . makeIdFilter ( typeInfo . idFields , resourceId ) ,
922
+ where : this . makePrismaIdFilter ( typeInfo . idFields , resourceId ) ,
923
923
data : { ...attributes } ,
924
924
} ;
925
925
@@ -938,7 +938,7 @@ class RequestHandler extends APIHandlerBase {
938
938
if ( relationInfo . isCollection ) {
939
939
updatePayload . data [ key ] = {
940
940
set : enumerate ( data . data ) . map ( ( item : any ) => ( {
941
- [ this . makeIdKey ( relationInfo . idFields ) ] : item . id ,
941
+ [ this . makePrismaIdKey ( relationInfo . idFields ) ] : item . id ,
942
942
} ) ) ,
943
943
} ;
944
944
} else {
@@ -947,13 +947,13 @@ class RequestHandler extends APIHandlerBase {
947
947
}
948
948
updatePayload . data [ key ] = {
949
949
set : {
950
- [ this . makeIdKey ( relationInfo . idFields ) ] : data . data . id ,
950
+ [ this . makePrismaIdKey ( relationInfo . idFields ) ] : data . data . id ,
951
951
} ,
952
952
} ;
953
953
}
954
954
updatePayload . include = {
955
955
...updatePayload . include ,
956
- [ key ] : { select : { [ this . makeIdKey ( relationInfo . idFields ) ] : true } } ,
956
+ [ key ] : { select : { [ this . makePrismaIdKey ( relationInfo . idFields ) ] : true } } ,
957
957
} ;
958
958
}
959
959
}
@@ -972,7 +972,7 @@ class RequestHandler extends APIHandlerBase {
972
972
}
973
973
974
974
await prisma [ type ] . delete ( {
975
- where : this . makeIdFilter ( typeInfo . idFields , resourceId ) ,
975
+ where : this . makePrismaIdFilter ( typeInfo . idFields , resourceId ) ,
976
976
} ) ;
977
977
return {
978
978
status : 204 ,
@@ -1218,12 +1218,13 @@ class RequestHandler extends APIHandlerBase {
1218
1218
return r . toString ( ) ;
1219
1219
}
1220
1220
1221
- private makeIdFilter ( idFields : FieldInfo [ ] , resourceId : string ) {
1221
+ private makePrismaIdFilter ( idFields : FieldInfo [ ] , resourceId : string ) {
1222
1222
if ( idFields . length === 1 ) {
1223
1223
return { [ idFields [ 0 ] . name ] : this . coerce ( idFields [ 0 ] . type , resourceId ) } ;
1224
1224
} else {
1225
1225
return {
1226
- [ idFields . map ( ( idf ) => idf . name ) . join ( this . idDivider ) ] : idFields . reduce (
1226
+ // TODO: support `@@id` with custom name
1227
+ [ idFields . map ( ( idf ) => idf . name ) . join ( '_' ) ] : idFields . reduce (
1227
1228
( acc , curr , idx ) => ( {
1228
1229
...acc ,
1229
1230
[ curr . name ] : this . coerce ( curr . type , resourceId . split ( this . idDivider ) [ idx ] ) ,
@@ -1245,6 +1246,11 @@ class RequestHandler extends APIHandlerBase {
1245
1246
return idFields . map ( ( idf ) => idf . name ) . join ( this . idDivider ) ;
1246
1247
}
1247
1248
1249
+ private makePrismaIdKey ( idFields : FieldInfo [ ] ) {
1250
+ // TODO: support `@@id` with custom name
1251
+ return idFields . map ( ( idf ) => idf . name ) . join ( '_' ) ;
1252
+ }
1253
+
1248
1254
private makeCompoundId ( idFields : FieldInfo [ ] , item : any ) {
1249
1255
return idFields . map ( ( idf ) => item [ idf . name ] ) . join ( this . idDivider ) ;
1250
1256
}
@@ -1569,11 +1575,11 @@ class RequestHandler extends APIHandlerBase {
1569
1575
const values = value . split ( ',' ) . filter ( ( i ) => i ) ;
1570
1576
const filterValue =
1571
1577
values . length > 1
1572
- ? { OR : values . map ( ( v ) => this . makeIdFilter ( info . idFields , v ) ) }
1573
- : this . makeIdFilter ( info . idFields , value ) ;
1578
+ ? { OR : values . map ( ( v ) => this . makePrismaIdFilter ( info . idFields , v ) ) }
1579
+ : this . makePrismaIdFilter ( info . idFields , value ) ;
1574
1580
return { some : filterValue } ;
1575
1581
} else {
1576
- return { is : this . makeIdFilter ( info . idFields , value ) } ;
1582
+ return { is : this . makePrismaIdFilter ( info . idFields , value ) } ;
1577
1583
}
1578
1584
} else {
1579
1585
const coerced = this . coerce ( fieldInfo . type , value ) ;
0 commit comments