angular-odata 0.153.0 → 0.155.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;
@@ -10860,7 +10864,9 @@ class ODataCollection {
10860
10864
  const resource = this.resource();
10861
10865
  if (!(resource instanceof ODataEntitySetResource))
10862
10866
  return throwError(() => new Error("callFunction: Can't call function without ODataEntitySetResource"));
10863
- const func = resource.function(name).query((q) => q.restore(options));
10867
+ let func = resource.function(name);
10868
+ if (options.query !== undefined)
10869
+ func = func.query(options.query);
10864
10870
  switch (responseType) {
10865
10871
  case 'property':
10866
10872
  return this._request(func.callProperty(params, options), (resp) => resp);
@@ -10877,7 +10883,9 @@ class ODataCollection {
10877
10883
  if (!(resource instanceof ODataEntitySetResource)) {
10878
10884
  return throwError(() => new Error(`callAction: Can't call action without ODataEntitySetResource`));
10879
10885
  }
10880
- const action = resource.action(name).query((q) => q.restore(options));
10886
+ let action = resource.action(name);
10887
+ if (options.query !== undefined)
10888
+ action = action.query(options.query);
10881
10889
  switch (responseType) {
10882
10890
  case 'property':
10883
10891
  return this._request(action.callProperty(params, options), (resp) => resp);
@@ -11364,7 +11372,9 @@ class ODataModel {
11364
11372
  const resource = this.resource();
11365
11373
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
11366
11374
  return throwError(() => new Error("callFunction: Can't call function without ODataEntityResource with key"));
11367
- const func = resource.function(name).query((q) => q.restore(options));
11375
+ let func = resource.function(name);
11376
+ if (options.query !== undefined)
11377
+ func = func.query(options.query);
11368
11378
  switch (responseType) {
11369
11379
  case 'property':
11370
11380
  return this._request(func.callProperty(params, options), (resp) => resp);
@@ -11384,7 +11394,9 @@ class ODataModel {
11384
11394
  const resource = this.resource();
11385
11395
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
11386
11396
  return throwError(() => new Error("callAction: Can't call action without ODataEntityResource with key"));
11387
- const action = resource.action(name).query((q) => q.restore(options));
11397
+ let action = resource.action(name);
11398
+ if (options.query !== undefined)
11399
+ action = action.query(options.query);
11388
11400
  switch (responseType) {
11389
11401
  case 'property':
11390
11402
  return this._request(action.callProperty(params, options), (resp) => resp);
@@ -11410,8 +11422,9 @@ class ODataModel {
11410
11422
  });
11411
11423
  }
11412
11424
  fetchNavigationProperty(name, responseType, options = {}) {
11413
- const nav = this.navigationProperty(name);
11414
- nav.query((q) => q.restore(options));
11425
+ let nav = this.navigationProperty(name);
11426
+ if (options.query !== undefined)
11427
+ nav = nav.query(options.query);
11415
11428
  switch (responseType) {
11416
11429
  case 'model':
11417
11430
  return nav.fetchModel(options);
@@ -11424,24 +11437,27 @@ class ODataModel {
11424
11437
  if (!field)
11425
11438
  throw Error(`fetchAttribute: Can't find attribute ${name}`);
11426
11439
  if (field.isStructuredType() && field.collection) {
11427
- const collection = field.collectionFactory({ parent: this });
11428
- collection.query((q) => q.restore(options));
11440
+ let collection = field.collectionFactory({ parent: this });
11441
+ if (options.query !== undefined)
11442
+ collection = collection.query(options.query);
11429
11443
  return this._request(collection.fetch(options), () => {
11430
11444
  this.assign({ [name]: collection });
11431
11445
  return collection;
11432
11446
  });
11433
11447
  }
11434
11448
  else if (field.isStructuredType()) {
11435
- const model = field.modelFactory({ parent: this });
11436
- model.query((q) => q.restore(options));
11449
+ let model = field.modelFactory({ parent: this });
11450
+ if (options.query !== undefined)
11451
+ model = model.query(options.query);
11437
11452
  return this._request(model.fetch(options), () => {
11438
11453
  this.assign({ [name]: model });
11439
11454
  return model;
11440
11455
  });
11441
11456
  }
11442
11457
  else {
11443
- const prop = field.resourceFactory(this.resource());
11444
- prop.query((q) => q.restore(options));
11458
+ let prop = field.resourceFactory(this.resource());
11459
+ if (options.query !== undefined)
11460
+ prop = prop.query(options.query);
11445
11461
  return this._request(prop.fetchProperty(options), (resp) => {
11446
11462
  this.assign({ [name]: resp });
11447
11463
  return resp;
@@ -11819,31 +11835,37 @@ class ODataModelField {
11819
11835
  }
11820
11836
  else {
11821
11837
  const computed = this.annotatedValue(COMPUTED);
11822
- const errors = this.parser?.validate(value, { method, navigation }) || [];
11838
+ const errors = this.parser?.validate(value, { method, navigation }) ?? [];
11823
11839
  if (this.required &&
11824
11840
  (value === null || (value === undefined && method !== 'modify')) && // Is null or undefined without patch?
11825
11841
  !(computed && method === 'create') // Not (Is Computed field and create) ?
11826
11842
  ) {
11827
- errors['push'](`required`);
11843
+ if (errors.indexOf('required') === -1)
11844
+ errors.push(`required`);
11828
11845
  }
11829
11846
  if (this.maxLength !== undefined &&
11830
11847
  typeof value === 'string' &&
11831
11848
  value.length > this.maxLength) {
11832
- errors['push'](`maxlength`);
11849
+ if (errors.indexOf('maxlength') === -1)
11850
+ errors.push(`maxlength`);
11833
11851
  }
11834
11852
  if (this.minLength !== undefined &&
11835
11853
  typeof value === 'string' &&
11836
11854
  value.length < this.minLength) {
11837
- errors['push'](`minlength`);
11855
+ if (errors.indexOf('minlength') === -1)
11856
+ errors.push(`minlength`);
11838
11857
  }
11839
11858
  if (this.min !== undefined && typeof value === 'number' && value < this.min) {
11840
- errors['push'](`min`);
11859
+ if (errors.indexOf('min') === -1)
11860
+ errors.push(`min`);
11841
11861
  }
11842
11862
  if (this.max !== undefined && typeof value === 'number' && value > this.max) {
11843
- errors['push'](`max`);
11863
+ if (errors.indexOf('max') === -1)
11864
+ errors.push(`max`);
11844
11865
  }
11845
11866
  if (this.pattern !== undefined && typeof value === 'string' && !this.pattern.test(value)) {
11846
- errors['push'](`pattern`);
11867
+ if (errors.indexOf('pattern') === -1)
11868
+ errors.push(`pattern`);
11847
11869
  }
11848
11870
  return !Types.isEmpty(errors) ? errors : undefined;
11849
11871
  }
@@ -13783,21 +13805,24 @@ class ODataBaseService {
13783
13805
  return this.client.apiFor(this.apiNameOrEntityType);
13784
13806
  }
13785
13807
  callFunction(params, resource, responseType, options = {}) {
13786
- resource.query((q) => q.restore(options));
13808
+ if (options.query !== undefined)
13809
+ resource = resource.query(options.query);
13787
13810
  return resource.call(params, {
13788
13811
  responseType: responseType,
13789
13812
  ...options,
13790
13813
  });
13791
13814
  }
13792
13815
  callAction(params, resource, responseType, options = {}) {
13793
- resource.query((q) => q.restore(options));
13816
+ if (options.query !== undefined)
13817
+ resource = resource.query(options.query);
13794
13818
  return resource.call(params, {
13795
13819
  responseType: responseType,
13796
13820
  ...options,
13797
13821
  });
13798
13822
  }
13799
13823
  fetchNavigationProperty(resource, responseType, options = {}) {
13800
- resource.query((q) => q.restore(options));
13824
+ if (options.query !== undefined)
13825
+ resource = resource.query(options.query);
13801
13826
  return resource.fetch({ responseType: responseType, ...options });
13802
13827
  }
13803
13828
  }