11import { HttpEvent , HttpEventType } from '@angular/common/http' ;
2- import { NEVER , Observable , of , throwError } from 'rxjs' ;
2+ import { firstValueFrom , NEVER , Observable , of , throwError } from 'rxjs' ;
33import { catchError , map , startWith , tap } from 'rxjs/operators' ;
44import { DEFAULT_VERSION } from './constants' ;
55import {
@@ -54,6 +54,7 @@ import {
5454} from './types' ;
5555import type { ODataMetadata } from './metadata/metadata' ;
5656import { ODataEntityAnnotations } from './annotations' ;
57+ import { ODataReference } from './schema/reference' ;
5758
5859const RESERVED_FIELD_NAMES = Object . getOwnPropertyNames ( ODataModel . prototype ) ;
5960
@@ -76,8 +77,12 @@ export class ODataApi {
7677 errorHandler ?: ( error : any , caught : Observable < any > ) => Observable < never > ;
7778 // Base Parsers
7879 parsers : Map < string , Parser < any > > ;
80+ // Populate from Metadata
81+ populateFromMetadata : boolean ;
7982 // Schemas
8083 schemas : ODataSchema [ ] ;
84+ // References
85+ references : ODataReference [ ] ;
8186 // Models
8287 models : { [ type : string ] : typeof ODataModel < any > } = { } ;
8388 // Collections
@@ -104,19 +109,17 @@ export class ODataApi {
104109 this . errorHandler = config . errorHandler ;
105110 this . parsers = new Map ( Object . entries ( config . parsers ?? EDM_PARSERS ) ) ;
106111
112+ this . populateFromMetadata = config . populateFromMetadata ?? false ;
107113 this . schemas = ( config . schemas ?? [ ] ) . map ( ( schema ) => new ODataSchema ( schema , this ) ) ;
114+ this . references = ( config . references ?? [ ] ) . map ( ( reference ) => new ODataReference ( reference , this ) ) ;
108115 this . models = ( config . models ?? { } ) as { [ type : string ] : typeof ODataModel < any > } ;
109116 this . collections = ( config . collections ?? { } ) as {
110117 [ type : string ] : typeof ODataCollection < any , ODataModel < any > > ;
111118 } ;
112119 }
113120
114- configure (
115- settings : {
116- requester ?: ( request : ODataRequest < any > ) => Observable < any > ;
117- } = { } ,
118- ) {
119- this . requester = settings . requester ;
121+ initialize ( requester : ( request : ODataRequest < any > ) => Observable < any > ) {
122+ this . requester = requester ;
120123 this . schemas . forEach ( ( schema ) => {
121124 schema . configure ( {
122125 options : this . options . parserOptions ,
@@ -132,6 +135,9 @@ export class ODataApi {
132135 }
133136 }
134137 } ) ;
138+ return ( this . populateFromMetadata ) ?
139+ firstValueFrom ( this . metadata ( ) . fetch ( ) . pipe ( map ( metadata => this . populate ( metadata ) ) ) ) :
140+ Promise . resolve ( true ) ;
135141 }
136142
137143 populate ( metadata : ODataMetadata ) {
@@ -144,6 +150,7 @@ export class ODataApi {
144150 options : this . options . parserOptions ,
145151 } ) ;
146152 } ) ;
153+ return true ;
147154 }
148155
149156 fromJson < P , R > ( json : {
0 commit comments