@@ -33,8 +33,6 @@ const urlPatterns = {
33
33
relationship : new UrlPattern ( '/:type/:id/relationships/:relationship' ) ,
34
34
} ;
35
35
36
- export const idDivider = '_' ;
37
-
38
36
/**
39
37
* Request handler options
40
38
*/
@@ -52,6 +50,12 @@ export type Options = {
52
50
* Defaults to 100. Set to Infinity to disable pagination.
53
51
*/
54
52
pageSize ?: number ;
53
+
54
+ /**
55
+ * The divider used to separate compound ID fields in the URL.
56
+ * Defaults to '_'.
57
+ */
58
+ idDivider ?: string ;
55
59
} ;
56
60
57
61
type RelationshipInfo = {
@@ -209,9 +213,11 @@ class RequestHandler extends APIHandlerBase {
209
213
210
214
// all known types and their metadata
211
215
private typeMap : Record < string , ModelInfo > ;
216
+ public idDivider ;
212
217
213
218
constructor ( private readonly options : Options ) {
214
219
super ( ) ;
220
+ this . idDivider = options . idDivider ?? '_' ;
215
221
}
216
222
217
223
async handleRequest ( {
@@ -1110,7 +1116,7 @@ class RequestHandler extends APIHandlerBase {
1110
1116
if ( ids . length === 0 ) {
1111
1117
return undefined ;
1112
1118
} else {
1113
- return data [ ids . map ( ( id ) => id . name ) . join ( idDivider ) ] ;
1119
+ return data [ ids . map ( ( id ) => id . name ) . join ( this . idDivider ) ] ;
1114
1120
}
1115
1121
}
1116
1122
@@ -1211,10 +1217,10 @@ class RequestHandler extends APIHandlerBase {
1211
1217
return { [ idFields [ 0 ] . name ] : this . coerce ( idFields [ 0 ] . type , resourceId ) } ;
1212
1218
} else {
1213
1219
return {
1214
- [ idFields . map ( ( idf ) => idf . name ) . join ( idDivider ) ] : idFields . reduce (
1220
+ [ idFields . map ( ( idf ) => idf . name ) . join ( this . idDivider ) ] : idFields . reduce (
1215
1221
( acc , curr , idx ) => ( {
1216
1222
...acc ,
1217
- [ curr . name ] : this . coerce ( curr . type , resourceId . split ( idDivider ) [ idx ] ) ,
1223
+ [ curr . name ] : this . coerce ( curr . type , resourceId . split ( this . idDivider ) [ idx ] ) ,
1218
1224
} ) ,
1219
1225
{ }
1220
1226
) ,
@@ -1230,11 +1236,11 @@ class RequestHandler extends APIHandlerBase {
1230
1236
}
1231
1237
1232
1238
private makeIdKey ( idFields : FieldInfo [ ] ) {
1233
- return idFields . map ( ( idf ) => idf . name ) . join ( idDivider ) ;
1239
+ return idFields . map ( ( idf ) => idf . name ) . join ( this . idDivider ) ;
1234
1240
}
1235
1241
1236
1242
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 ) ;
1238
1244
}
1239
1245
1240
1246
private includeRelationshipIds ( model : string , args : any , mode : 'select' | 'include' ) {
0 commit comments