angular-odata 0.152.0 → 0.154.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.
@@ -9687,13 +9687,17 @@ class ODataMetadataParser {
9687
9687
  }
9688
9688
  getAttributeValue(attributes, attributeName) {
9689
9689
  const attribute = attributes.getNamedItem(attributeName);
9690
- return attribute !== null && attribute.nodeValue ? attribute.nodeValue : undefined;
9690
+ return attribute !== null && attribute.nodeValue != null ? attribute.nodeValue : undefined;
9691
9691
  }
9692
9692
  propertyValueToNumber(attributeValue) {
9693
9693
  return attributeValue !== undefined ? Number(attributeValue) : undefined;
9694
9694
  }
9695
9695
  propertyValueToBoolean(attributeValue) {
9696
- return attributeValue !== undefined ? attributeValue === 'true' : false;
9696
+ return attributeValue !== undefined && attributeValue === 'true'
9697
+ ? true
9698
+ : attributeValue !== undefined && attributeValue === 'false'
9699
+ ? false
9700
+ : undefined;
9697
9701
  }
9698
9702
  propertyValueToDate(attributeValue) {
9699
9703
  return attributeValue !== undefined ? new Date(attributeValue) : undefined;
@@ -11819,31 +11823,37 @@ class ODataModelField {
11819
11823
  }
11820
11824
  else {
11821
11825
  const computed = this.annotatedValue(COMPUTED);
11822
- const errors = this.parser?.validate(value, { method, navigation }) || [];
11826
+ const errors = this.parser?.validate(value, { method, navigation }) ?? [];
11823
11827
  if (this.required &&
11824
11828
  (value === null || (value === undefined && method !== 'modify')) && // Is null or undefined without patch?
11825
11829
  !(computed && method === 'create') // Not (Is Computed field and create) ?
11826
11830
  ) {
11827
- errors['push'](`required`);
11831
+ if (errors.indexOf('required') === -1)
11832
+ errors.push(`required`);
11828
11833
  }
11829
11834
  if (this.maxLength !== undefined &&
11830
11835
  typeof value === 'string' &&
11831
11836
  value.length > this.maxLength) {
11832
- errors['push'](`maxlength`);
11837
+ if (errors.indexOf('maxlength') === -1)
11838
+ errors.push(`maxlength`);
11833
11839
  }
11834
11840
  if (this.minLength !== undefined &&
11835
11841
  typeof value === 'string' &&
11836
11842
  value.length < this.minLength) {
11837
- errors['push'](`minlength`);
11843
+ if (errors.indexOf('minlength') === -1)
11844
+ errors.push(`minlength`);
11838
11845
  }
11839
11846
  if (this.min !== undefined && typeof value === 'number' && value < this.min) {
11840
- errors['push'](`min`);
11847
+ if (errors.indexOf('min') === -1)
11848
+ errors.push(`min`);
11841
11849
  }
11842
11850
  if (this.max !== undefined && typeof value === 'number' && value > this.max) {
11843
- errors['push'](`max`);
11851
+ if (errors.indexOf('max') === -1)
11852
+ errors.push(`max`);
11844
11853
  }
11845
11854
  if (this.pattern !== undefined && typeof value === 'string' && !this.pattern.test(value)) {
11846
- errors['push'](`pattern`);
11855
+ if (errors.indexOf('pattern') === -1)
11856
+ errors.push(`pattern`);
11847
11857
  }
11848
11858
  return !Types.isEmpty(errors) ? errors : undefined;
11849
11859
  }
@@ -12901,9 +12911,9 @@ class ODataApi {
12901
12911
  // Populate from Metadata
12902
12912
  populateFromMetadata;
12903
12913
  // Schemas
12904
- schemas;
12914
+ schemas = [];
12905
12915
  // References
12906
- references;
12916
+ references = [];
12907
12917
  // Models
12908
12918
  models = {};
12909
12919
  // Collections
@@ -12927,13 +12937,17 @@ class ODataApi {
12927
12937
  this.errorHandler = config.errorHandler;
12928
12938
  this.parsers = new Map(Object.entries(config.parsers ?? EDM_PARSERS));
12929
12939
  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 ?? {});
12940
+ this.populate(config);
12934
12941
  }
12935
12942
  initialize(requester) {
12936
12943
  this.requester = requester;
12944
+ return (this.populateFromMetadata
12945
+ ? firstValueFrom(this.metadata()
12946
+ .fetch()
12947
+ .pipe(map((metadata) => this.populate(metadata.toConfig()))))
12948
+ : Promise.resolve()).then(() => this.configure());
12949
+ }
12950
+ configure() {
12937
12951
  this.schemas.forEach((schema) => {
12938
12952
  schema.configure({
12939
12953
  options: this.options.parserOptions,
@@ -12949,24 +12963,19 @@ class ODataApi {
12949
12963
  }
12950
12964
  }
12951
12965
  });
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
12966
  return true;
12969
12967
  }
12968
+ populate({ schemas, references, models, collections }) {
12969
+ const odataSchemas = (schemas ?? []).map((schema) => new ODataSchema(schema, this));
12970
+ //TODO: Merge duplicates
12971
+ this.schemas = [...this.schemas, ...odataSchemas];
12972
+ const odataReferences = (references ?? []).map((reference) => new ODataReference(reference, this));
12973
+ this.references = [...this.references, ...odataReferences];
12974
+ const odataModels = (models ?? {});
12975
+ this.models = { ...this.models, ...odataModels };
12976
+ const odataCollections = (collections ?? {});
12977
+ this.collections = { ...this.collections, ...odataCollections };
12978
+ }
12970
12979
  fromJson(json) {
12971
12980
  const segments = ODataPathSegments.fromJson(json.segments);
12972
12981
  const query = ODataQueryOptions.fromJson(json.options);
@@ -13612,7 +13621,7 @@ class ODataClient {
13612
13621
  if (value instanceof ODataResource)
13613
13622
  api = this.settings.findApiForTypes(value.types());
13614
13623
  else if (typeof value === 'string')
13615
- api = this.settings.findApiByName(value) || this.settings.findApiForType(value);
13624
+ api = this.settings.findApiByName(value) ?? this.settings.findApiForType(value);
13616
13625
  return api ?? this.settings.defaultApi();
13617
13626
  }
13618
13627
  defaultApi() {