@@ -33,8 +33,6 @@ const urlPatterns = {
3333 relationship : new UrlPattern ( '/:type/:id/relationships/:relationship' ) ,
3434} ;
3535
36- export const idDivider = '_' ;
37-
3836/**
3937 * Request handler options
4038 */
@@ -52,6 +50,12 @@ export type Options = {
5250 * Defaults to 100. Set to Infinity to disable pagination.
5351 */
5452 pageSize ?: number ;
53+
54+ /**
55+ * The divider used to separate compound ID fields in the URL.
56+ * Defaults to '_'.
57+ */
58+ idDivider ?: string ;
5559} ;
5660
5761type RelationshipInfo = {
@@ -209,9 +213,11 @@ class RequestHandler extends APIHandlerBase {
209213
210214 // all known types and their metadata
211215 private typeMap : Record < string , ModelInfo > ;
216+ public idDivider ;
212217
213218 constructor ( private readonly options : Options ) {
214219 super ( ) ;
220+ this . idDivider = options . idDivider ?? '_' ;
215221 }
216222
217223 async handleRequest ( {
@@ -1110,7 +1116,7 @@ class RequestHandler extends APIHandlerBase {
11101116 if ( ids . length === 0 ) {
11111117 return undefined ;
11121118 } else {
1113- return data [ ids . map ( ( id ) => id . name ) . join ( idDivider ) ] ;
1119+ return data [ ids . map ( ( id ) => id . name ) . join ( this . idDivider ) ] ;
11141120 }
11151121 }
11161122
@@ -1211,10 +1217,10 @@ class RequestHandler extends APIHandlerBase {
12111217 return { [ idFields [ 0 ] . name ] : this . coerce ( idFields [ 0 ] . type , resourceId ) } ;
12121218 } else {
12131219 return {
1214- [ idFields . map ( ( idf ) => idf . name ) . join ( idDivider ) ] : idFields . reduce (
1220+ [ idFields . map ( ( idf ) => idf . name ) . join ( this . idDivider ) ] : idFields . reduce (
12151221 ( acc , curr , idx ) => ( {
12161222 ...acc ,
1217- [ curr . name ] : this . coerce ( curr . type , resourceId . split ( idDivider ) [ idx ] ) ,
1223+ [ curr . name ] : this . coerce ( curr . type , resourceId . split ( this . idDivider ) [ idx ] ) ,
12181224 } ) ,
12191225 { }
12201226 ) ,
@@ -1230,11 +1236,11 @@ class RequestHandler extends APIHandlerBase {
12301236 }
12311237
12321238 private makeIdKey ( idFields : FieldInfo [ ] ) {
1233- return idFields . map ( ( idf ) => idf . name ) . join ( idDivider ) ;
1239+ return idFields . map ( ( idf ) => idf . name ) . join ( this . idDivider ) ;
12341240 }
12351241
12361242 private makeCompoundId ( idFields : FieldInfo [ ] , item : any ) {
1237- return idFields . map ( ( idf ) => item [ idf . name ] ) . join ( idDivider ) ;
1243+ return idFields . map ( ( idf ) => item [ idf . name ] ) . join ( this . idDivider ) ;
12381244 }
12391245
12401246 private includeRelationshipIds ( model : string , args : any , mode : 'select' | 'include' ) {
0 commit comments