@@ -142,7 +142,7 @@ export class Contentfully {
142
142
return links ;
143
143
}
144
144
145
- private _dereferenceLink ( reference : any , links : any ) {
145
+ private _dereferenceLink ( reference : any , links : any , level : number = 0 ) {
146
146
147
147
const sys = reference . sys ;
148
148
const modelId = sys . id ;
@@ -163,7 +163,7 @@ export class Contentfully {
163
163
link . _type = deferredSys . contentType . sys . id ;
164
164
165
165
// update entry with parsed value
166
- assign ( link , this . _parseEntry ( link . _deferred , links ) ) ;
166
+ assign ( link , this . _parseEntry ( link . _deferred , links , level ) ) ;
167
167
168
168
// prune deferral
169
169
delete link . _deferred ;
@@ -174,7 +174,6 @@ export class Contentfully {
174
174
}
175
175
176
176
private _parseEntries ( entries : any , links : any ) {
177
-
178
177
// convert entries to models and return result
179
178
return map ( entries , entry => {
180
179
// process entry if not processed
@@ -203,30 +202,36 @@ export class Contentfully {
203
202
} ) ;
204
203
}
205
204
206
- private _parseEntry ( entry : any , links : any ) {
205
+ private _parseEntry ( entry : any , links : any , level : number = 0 ) {
206
+ level += 1 ;
207
+ // This Value has to be somewhat small, as it will otherwise 'detect' circular structures when there are none
208
+ //TODO: Make this configurable in the request (possibly by using the include property of the request)
209
+ if ( level >= 10 )
210
+ return
211
+
207
212
208
213
// transform entry to model and return result
209
214
forEach ( entry . fields , ( value , key ) => {
210
215
// parse array of values
211
216
if ( isArray ( value ) ) {
212
- entry . fields [ key ] = compact ( map ( value , item => this . _parseValue ( item , links ) ) ) ;
217
+ entry . fields [ key ] = compact ( map ( value , item => this . _parseValue ( item , links , level ) ) ) ;
213
218
}
214
219
215
220
// or parse value
216
221
else {
217
222
// handle null values otherwise pass back the values
218
- if ( this . _parseValue ( value , links ) === undefined ) {
223
+ if ( this . _parseValue ( value , links , level ) === undefined ) {
219
224
unset ( entry . fields , key )
220
225
} else {
221
- entry . fields [ key ] = this . _parseValue ( value , links ) ;
226
+ entry . fields [ key ] = this . _parseValue ( value , links , level ) ;
222
227
}
223
228
}
224
229
} ) ;
225
230
226
231
return entry . fields ;
227
232
}
228
233
229
- private _parseValue ( value : any , links : any ) {
234
+ private _parseValue ( value : any , links : any , level : number = 0 ) {
230
235
231
236
// handle values without a link
232
237
const sys = value . sys ;
@@ -235,6 +240,6 @@ export class Contentfully {
235
240
}
236
241
237
242
// dereference link
238
- return this . _dereferenceLink ( value , links ) ;
243
+ return this . _dereferenceLink ( value , links , level ) ;
239
244
}
240
245
}
0 commit comments