@@ -52,7 +52,6 @@ export type Options = {
5252 urlSegmentCharset ?: string ;
5353
5454 modelNameMapping ?: Record < string , string > ;
55- prefix ?: string ;
5655} ;
5756
5857type RelationshipInfo = {
@@ -239,14 +238,12 @@ class RequestHandler extends APIHandlerBase {
239238 private urlPatternMap : Record < UrlPatterns , UrlPattern > ;
240239 private modelNameMapping : Record < string , string > ;
241240 private reverseModelNameMapping : Record < string , string > ;
242- private prefix : string | undefined ;
243241
244242 constructor ( private readonly options : Options ) {
245243 super ( ) ;
246244 this . idDivider = options . idDivider ?? prismaIdDivider ;
247245 const segmentCharset = options . urlSegmentCharset ?? 'a-zA-Z0-9-_~ %' ;
248246
249- this . prefix = options . prefix ;
250247 this . modelNameMapping = options . modelNameMapping ?? { } ;
251248 this . reverseModelNameMapping = Object . fromEntries (
252249 Object . entries ( this . modelNameMapping ) . map ( ( [ k , v ] ) => [ v , k ] )
@@ -258,7 +255,7 @@ class RequestHandler extends APIHandlerBase {
258255 const options = { segmentValueCharset : urlSegmentNameCharset } ;
259256
260257 const buildPath = ( segments : string [ ] ) => {
261- return ( this . prefix ?? '' ) + '/' + segments . join ( '/' ) ;
258+ return '/' + segments . join ( '/' ) ;
262259 } ;
263260
264261 return {
@@ -285,7 +282,6 @@ class RequestHandler extends APIHandlerBase {
285282 const match = pattern . match ( path ) ;
286283 if ( match ) {
287284 match . type = this . modelNameMapping [ match . type ] ?? match . type ;
288- match . relationship = this . modelNameMapping [ match . relationship ] ?? match . relationship ;
289285 }
290286 return match ;
291287 }
@@ -574,12 +570,11 @@ class RequestHandler extends APIHandlerBase {
574570
575571 if ( entity ?. [ relationship ] ) {
576572 const mappedType = this . reverseModelNameMap ( type ) ;
577- const mappedRelationship = this . reverseModelNameMap ( relationship ) ;
578573 return {
579574 status : 200 ,
580575 body : await this . serializeItems ( relationInfo . type , entity [ relationship ] , {
581576 linkers : {
582- document : new Linker ( ( ) => this . makeLinkUrl ( `/${ mappedType } /${ resourceId } /${ mappedRelationship } ` ) ) ,
577+ document : new Linker ( ( ) => this . makeLinkUrl ( `/${ mappedType } /${ resourceId } /${ relationship } ` ) ) ,
583578 paginator,
584579 } ,
585580 include,
@@ -627,12 +622,11 @@ class RequestHandler extends APIHandlerBase {
627622
628623 const entity : any = await prisma [ type ] . findUnique ( args ) ;
629624 const mappedType = this . reverseModelNameMap ( type ) ;
630- const mappedRelationship = this . reverseModelNameMap ( relationship ) ;
631625
632626 if ( entity ?. _count ?. [ relationship ] !== undefined ) {
633627 // build up paginator
634628 const total = entity ?. _count ?. [ relationship ] as number ;
635- const url = this . makeNormalizedUrl ( `/${ mappedType } /${ resourceId } /relationships/${ mappedRelationship } ` , query ) ;
629+ const url = this . makeNormalizedUrl ( `/${ mappedType } /${ resourceId } /relationships/${ relationship } ` , query ) ;
636630 const { offset, limit } = this . getPagination ( query ) ;
637631 paginator = this . makePaginator ( url , offset , limit , total ) ;
638632 }
@@ -641,7 +635,7 @@ class RequestHandler extends APIHandlerBase {
641635 const serialized : any = await this . serializeItems ( relationInfo . type , entity [ relationship ] , {
642636 linkers : {
643637 document : new Linker ( ( ) =>
644- this . makeLinkUrl ( `/${ mappedType } /${ resourceId } /relationships/${ mappedRelationship } ` )
638+ this . makeLinkUrl ( `/${ mappedType } /${ resourceId } /relationships/${ relationship } ` )
645639 ) ,
646640 paginator,
647641 } ,
@@ -1057,11 +1051,12 @@ class RequestHandler extends APIHandlerBase {
10571051 const entity : any = await prisma [ type ] . update ( updateArgs ) ;
10581052
10591053 const mappedType = this . reverseModelNameMap ( type ) ;
1060- const mappedRelationship = this . reverseModelNameMap ( relationship ) ;
10611054
10621055 const serialized : any = await this . serializeItems ( relationInfo . type , entity [ relationship ] , {
10631056 linkers : {
1064- document : new Linker ( ( ) => this . makeLinkUrl ( `/${ mappedType } /${ resourceId } /relationships/${ mappedRelationship } ` ) ) ,
1057+ document : new Linker ( ( ) =>
1058+ this . makeLinkUrl ( `/${ mappedType } /${ resourceId } /relationships/${ relationship } ` )
1059+ ) ,
10651060 } ,
10661061 onlyIdentifier : true ,
10671062 } ) ;
@@ -1197,7 +1192,7 @@ class RequestHandler extends APIHandlerBase {
11971192 }
11981193
11991194 private makeLinkUrl ( path : string ) {
1200- return `${ this . options . endpoint } ${ this . prefix } ${ path } ` ;
1195+ return `${ this . options . endpoint } ${ path } ` ;
12011196 }
12021197
12031198 private buildSerializers ( modelMeta : ModelMeta ) {
@@ -1260,7 +1255,6 @@ class RequestHandler extends APIHandlerBase {
12601255 const fieldIds = getIdFields ( modelMeta , fieldMeta . type ) ;
12611256 if ( fieldIds . length > 0 ) {
12621257 const mappedModel = this . reverseModelNameMap ( model ) ;
1263- const mappedField = this . reverseModelNameMap ( field ) ;
12641258
12651259 const relator = new Relator (
12661260 async ( data ) => {
@@ -1272,7 +1266,7 @@ class RequestHandler extends APIHandlerBase {
12721266 linkers : {
12731267 related : new Linker ( ( primary ) =>
12741268 this . makeLinkUrl (
1275- `/${ lowerCaseFirst ( mappedModel ) } /${ this . getId ( model , primary , modelMeta ) } /${ mappedField } `
1269+ `/${ lowerCaseFirst ( model ) } /${ this . getId ( model , primary , modelMeta ) } /${ field } `
12761270 )
12771271 ) ,
12781272 relationship : new Linker ( ( primary ) =>
@@ -1281,7 +1275,7 @@ class RequestHandler extends APIHandlerBase {
12811275 model ,
12821276 primary ,
12831277 modelMeta
1284- ) } /relationships/${ mappedField } `
1278+ ) } /relationships/${ field } `
12851279 )
12861280 ) ,
12871281 } ,
0 commit comments