angular-odata 0.152.0 → 0.153.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12901,9 +12901,9 @@ class ODataApi {
12901
12901
  // Populate from Metadata
12902
12902
  populateFromMetadata;
12903
12903
  // Schemas
12904
- schemas;
12904
+ schemas = [];
12905
12905
  // References
12906
- references;
12906
+ references = [];
12907
12907
  // Models
12908
12908
  models = {};
12909
12909
  // Collections
@@ -12927,13 +12927,17 @@ class ODataApi {
12927
12927
  this.errorHandler = config.errorHandler;
12928
12928
  this.parsers = new Map(Object.entries(config.parsers ?? EDM_PARSERS));
12929
12929
  this.populateFromMetadata = config.populateFromMetadata ?? false;
12930
- this.schemas = (config.schemas ?? []).map((schema) => new ODataSchema(schema, this));
12931
- this.references = (config.references ?? []).map((reference) => new ODataReference(reference, this));
12932
- this.models = (config.models ?? {});
12933
- this.collections = (config.collections ?? {});
12930
+ this.populate(config);
12934
12931
  }
12935
12932
  initialize(requester) {
12936
12933
  this.requester = requester;
12934
+ return (this.populateFromMetadata
12935
+ ? firstValueFrom(this.metadata()
12936
+ .fetch()
12937
+ .pipe(map((metadata) => this.populate(metadata.toConfig()))))
12938
+ : Promise.resolve()).then(() => this.configure());
12939
+ }
12940
+ configure() {
12937
12941
  this.schemas.forEach((schema) => {
12938
12942
  schema.configure({
12939
12943
  options: this.options.parserOptions,
@@ -12949,24 +12953,19 @@ class ODataApi {
12949
12953
  }
12950
12954
  }
12951
12955
  });
12952
- return this.populateFromMetadata
12953
- ? firstValueFrom(this.metadata()
12954
- .fetch()
12955
- .pipe(map((metadata) => this.populate(metadata))))
12956
- : Promise.resolve(true);
12957
- }
12958
- populate(metadata) {
12959
- const config = metadata.toConfig();
12960
- this.version = config.version ?? DEFAULT_VERSION;
12961
- const schemas = (config.schemas ?? []).map((schema) => new ODataSchema(schema, this));
12962
- this.schemas = [...this.schemas, ...schemas];
12963
- schemas.forEach((schema) => {
12964
- schema.configure({
12965
- options: this.options.parserOptions,
12966
- });
12967
- });
12968
12956
  return true;
12969
12957
  }
12958
+ populate({ schemas, references, models, collections }) {
12959
+ const odataSchemas = (schemas ?? []).map((schema) => new ODataSchema(schema, this));
12960
+ //TODO: Merge duplicates
12961
+ this.schemas = [...this.schemas, ...odataSchemas];
12962
+ const odataReferences = (references ?? []).map((reference) => new ODataReference(reference, this));
12963
+ this.references = [...this.references, ...odataReferences];
12964
+ const odataModels = (models ?? {});
12965
+ this.models = { ...this.models, ...odataModels };
12966
+ const odataCollections = (collections ?? {});
12967
+ this.collections = { ...this.collections, ...odataCollections };
12968
+ }
12970
12969
  fromJson(json) {
12971
12970
  const segments = ODataPathSegments.fromJson(json.segments);
12972
12971
  const query = ODataQueryOptions.fromJson(json.options);
@@ -13612,7 +13611,7 @@ class ODataClient {
13612
13611
  if (value instanceof ODataResource)
13613
13612
  api = this.settings.findApiForTypes(value.types());
13614
13613
  else if (typeof value === 'string')
13615
- api = this.settings.findApiByName(value) || this.settings.findApiForType(value);
13614
+ api = this.settings.findApiByName(value) ?? this.settings.findApiForType(value);
13616
13615
  return api ?? this.settings.defaultApi();
13617
13616
  }
13618
13617
  defaultApi() {