@@ -311,11 +311,6 @@ export class ODataModelField<F> {
311311 field : string ;
312312 parser : ODataStructuredTypeFieldParser < F > ;
313313 options : ODataModelOptions < any > ;
314- optionsForType ?: ( type : string ) => ODataModelOptions < any > | undefined ;
315- modelForType ?: ( t : string ) => typeof ODataModel < any > | undefined ;
316- collectionForType ?: ( t : string ) => typeof ODataCollection < any , ODataModel < any > > | undefined ;
317- enumForType ?: ( t : string ) => ODataEnumType < F > | undefined ;
318- structuredForType ?: ( t : string ) => ODataStructuredType < F > | undefined ;
319314 default ?: any ;
320315 required : boolean ;
321316 concurrency : boolean ;
@@ -361,27 +356,12 @@ export class ODataModelField<F> {
361356 }
362357
363358 configure ( {
364- optionsForType,
365- modelForType,
366- collectionForType,
367- enumForType,
368- structuredForType,
369359 concurrency,
370360 options,
371361 } : {
372- optionsForType : ( type : string ) => ODataModelOptions < any > | undefined ;
373- modelForType : ( t : string ) => typeof ODataModel < any > | undefined ;
374- collectionForType : ( t : string ) => typeof ODataCollection < any , any > | undefined ;
375- enumForType : ( t : string ) => ODataEnumType < any > | undefined ;
376- structuredForType : ( t : string ) => ODataStructuredType < any > | undefined ;
377362 concurrency : boolean ;
378363 options : ParserOptions ;
379364 } ) {
380- this . optionsForType = optionsForType ;
381- this . modelForType = modelForType ;
382- this . collectionForType = collectionForType ;
383- this . enumForType = enumForType ;
384- this . structuredForType = structuredForType ;
385365 this . parserOptions = options ;
386366 if ( concurrency ) this . concurrency = concurrency ;
387367 if ( this . default !== undefined ) this . default = this . deserialize ( this . default , options ) ;
@@ -404,7 +384,7 @@ export class ODataModelField<F> {
404384 }
405385
406386 structuredType ( ) {
407- const structuredType = this . structuredForType ? this . structuredForType ( this . type ) : undefined ;
387+ const structuredType = this . options . api . findStructuredType ( this . type ) ;
408388 //Throw error if not found
409389 if ( ! structuredType ) throw new Error ( `Could not find structured type for ${ this . parser . type } ` ) ;
410390 return structuredType ;
@@ -419,7 +399,7 @@ export class ODataModelField<F> {
419399 }
420400
421401 enumType ( ) {
422- const enumType = this . enumForType ? this . enumForType ( this . type ) : undefined ;
402+ const enumType = this . options . api . findEnumType ( this . type ) ;
423403 //Throw error if not found
424404 if ( ! enumType ) throw new Error ( `Could not find enum type for ${ this . parser . type } ` ) ;
425405 return enumType ;
@@ -479,8 +459,7 @@ export class ODataModelField<F> {
479459 }
480460
481461 defaults ( ) : any {
482- const meta =
483- this . optionsForType && this . isStructuredType ( ) ? this . optionsForType ( this . type ) : undefined ;
462+ const meta = this . isStructuredType ( ) ? this . options . api . optionsForType ( this . type ) : undefined ;
484463 return meta !== undefined ? meta . defaults ( ) : this . default ;
485464 }
486465
@@ -534,7 +513,7 @@ export class ODataModelField<F> {
534513 } ) : ODataModel < F > {
535514 // Model
536515 const annots = this . annotationsFactory ( parent . annots ( ) ) as ODataEntityAnnotations < F > ;
537- let Model = this . modelForType ? this . modelForType ( this . type ) : undefined ;
516+ let Model = this . options . api . modelForType ( this . type ) ;
538517 if ( Model === undefined ) throw Error ( `No Model type for ${ this . name } ` ) ;
539518 if ( value !== undefined ) {
540519 annots . update ( value ) ;
@@ -567,7 +546,7 @@ export class ODataModelField<F> {
567546 } ) : ODataCollection < F , ODataModel < F > > {
568547 // Collection Factory
569548 const annots = this . annotationsFactory ( parent . annots ( ) ) as ODataEntitiesAnnotations < F > ;
570- const Collection = this . collectionForType ? this . collectionForType ( this . type ) : undefined ;
549+ const Collection = this . options . api . collectionForType ( this . type ) ;
571550 if ( Collection === undefined ) throw Error ( `No Collection type for ${ this . name } ` ) ;
572551 return Collection . factory ( ( value || [ ] ) as Partial < F > [ ] | { [ name : string ] : any } [ ] , {
573552 annots : annots ,
@@ -870,11 +849,6 @@ export class ODataModelOptions<T> {
870849 this . _fields . forEach ( ( field ) => {
871850 const concurrency = concurrencyFields . indexOf ( field . field ) !== - 1 ;
872851 field . configure ( {
873- optionsForType : ( t : string ) => this . api . optionsForType ( t ) ,
874- modelForType : ( t : string ) => this . api . modelForType ( t ) ,
875- collectionForType : ( t : string ) => this . api . collectionForType ( t ) ,
876- enumForType : ( t : string ) => this . api . findEnumType ( t ) ,
877- structuredForType : ( t : string ) => this . api . findStructuredType ( t ) ,
878852 concurrency,
879853 options,
880854 } ) ;
@@ -951,11 +925,6 @@ export class ODataModelOptions<T> {
951925 parser : structuredFieldParser ,
952926 } ) ;
953927 modelField . configure ( {
954- optionsForType : ( t : string ) => this . api . optionsForType ( t ) ,
955- modelForType : ( t : string ) => this . api . modelForType ( t ) ,
956- collectionForType : ( t : string ) => this . api . collectionForType ( t ) ,
957- enumForType : ( t : string ) => this . api . findEnumType ( t ) ,
958- structuredForType : ( t : string ) => this . api . findStructuredType ( t ) ,
959928 options : this . api . options ,
960929 concurrency : false ,
961930 } ) ;
0 commit comments