angular-odata 0.99.0 → 0.99.2

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.
Files changed (46) hide show
  1. package/README.md +31 -25
  2. package/esm2020/lib/client.mjs +3 -3
  3. package/esm2020/lib/models/collection.mjs +23 -7
  4. package/esm2020/lib/models/model.mjs +1 -1
  5. package/esm2020/lib/models/options.mjs +25 -14
  6. package/esm2020/lib/module.mjs +4 -4
  7. package/esm2020/lib/resources/resource.mjs +6 -14
  8. package/esm2020/lib/resources/types/action.mjs +4 -1
  9. package/esm2020/lib/resources/types/batch.mjs +6 -1
  10. package/esm2020/lib/resources/types/count.mjs +4 -1
  11. package/esm2020/lib/resources/types/entity-set.mjs +4 -1
  12. package/esm2020/lib/resources/types/entity.mjs +4 -1
  13. package/esm2020/lib/resources/types/function.mjs +4 -1
  14. package/esm2020/lib/resources/types/media.mjs +4 -1
  15. package/esm2020/lib/resources/types/metadata.mjs +4 -1
  16. package/esm2020/lib/resources/types/navigation-property.mjs +4 -1
  17. package/esm2020/lib/resources/types/property.mjs +4 -1
  18. package/esm2020/lib/resources/types/reference.mjs +4 -1
  19. package/esm2020/lib/resources/types/singleton.mjs +4 -1
  20. package/esm2020/lib/resources/types/value.mjs +4 -1
  21. package/esm2020/lib/schema/element.mjs +12 -2
  22. package/esm2020/lib/schema/structured-type.mjs +11 -2
  23. package/esm2020/lib/services/factory.mjs +3 -3
  24. package/fesm2015/angular-odata.mjs +123 -43
  25. package/fesm2015/angular-odata.mjs.map +1 -1
  26. package/fesm2020/angular-odata.mjs +122 -43
  27. package/fesm2020/angular-odata.mjs.map +1 -1
  28. package/lib/models/model.d.ts +1 -1
  29. package/lib/models/options.d.ts +3 -3
  30. package/lib/resources/resource.d.ts +2 -1
  31. package/lib/resources/types/action.d.ts +1 -0
  32. package/lib/resources/types/batch.d.ts +1 -0
  33. package/lib/resources/types/count.d.ts +1 -0
  34. package/lib/resources/types/entity-set.d.ts +1 -0
  35. package/lib/resources/types/entity.d.ts +1 -0
  36. package/lib/resources/types/function.d.ts +1 -0
  37. package/lib/resources/types/media.d.ts +1 -0
  38. package/lib/resources/types/metadata.d.ts +1 -0
  39. package/lib/resources/types/navigation-property.d.ts +1 -0
  40. package/lib/resources/types/property.d.ts +1 -0
  41. package/lib/resources/types/reference.d.ts +1 -0
  42. package/lib/resources/types/singleton.d.ts +1 -0
  43. package/lib/resources/types/value.d.ts +1 -0
  44. package/lib/schema/element.d.ts +7 -1
  45. package/lib/schema/structured-type.d.ts +7 -1
  46. package/package.json +1 -1
@@ -2969,7 +2969,7 @@ class ODataSchemaElement extends ODataAnnotatable {
2969
2969
  return names.indexOf(type) !== -1;
2970
2970
  }
2971
2971
  /**
2972
- * Returns a boolean indicating if the structured type is a sub type of the given type.
2972
+ * Returns a boolean indicating if the structured type is a subtype of the given type.
2973
2973
  * @param type String representation of the type
2974
2974
  * @returns True if the callable is type of the given type
2975
2975
  */
@@ -2978,6 +2978,16 @@ class ODataSchemaElement extends ODataAnnotatable {
2978
2978
  return true;
2979
2979
  return false;
2980
2980
  }
2981
+ /**
2982
+ * Returns a boolean indicating if the structured type is a supertype of the given type.
2983
+ * @param type String representation of the type
2984
+ * @returns True if the callable is type of the given type
2985
+ */
2986
+ isSupertypeOf(schema) {
2987
+ if (this.isTypeOf(schema.type()))
2988
+ return true;
2989
+ return false;
2990
+ }
2981
2991
  }
2982
2992
 
2983
2993
  //https://github.com/niklasvh/base64-arraybuffer
@@ -4209,7 +4219,7 @@ class ODataStructuredType extends ODataSchemaElement {
4209
4219
  }
4210
4220
  }
4211
4221
  /**
4212
- * Returns a boolean indicating if the structured type is a sub type of the given type.
4222
+ * Returns a boolean indicating if the structured type is a subtype of the given type.
4213
4223
  * @param type String representation of the type
4214
4224
  * @returns True if the callable is type of the given type
4215
4225
  */
@@ -4217,6 +4227,15 @@ class ODataStructuredType extends ODataSchemaElement {
4217
4227
  return (super.isSubtypeOf(schema) ||
4218
4228
  (this.parent !== undefined && this.parent.isSubtypeOf(schema)));
4219
4229
  }
4230
+ /**
4231
+ * Returns a boolean indicating if the structured type is a supertype of the given type.
4232
+ * @param type String representation of the type
4233
+ * @returns True if the callable is type of the given type
4234
+ */
4235
+ isSupertypeOf(schema) {
4236
+ return (super.isSupertypeOf(schema) ||
4237
+ this.children.some((c) => c.isSupertypeOf(schema)));
4238
+ }
4220
4239
  /**
4221
4240
  * Returns a boolean indicating if the structured type has a simple key.
4222
4241
  * @returns True if the structured type has a simple key
@@ -4493,19 +4512,11 @@ class ODataResource {
4493
4512
  other.schema !== undefined &&
4494
4513
  this.schema?.isSubtypeOf(other.schema));
4495
4514
  }
4496
- /*
4497
- isParentOf(other: ODataResource<any>) {
4498
- const [selfPath] = this.pathAndParams();
4499
- const [otherPath] = other.pathAndParams();
4500
- return otherPath !== selfPath && otherPath.startsWith(selfPath);
4501
- }
4502
-
4503
- isChildOf(other: ODataResource<any>) {
4504
- const [selfPath] = this.pathAndParams();
4505
- const [otherPath] = other.pathAndParams();
4506
- return otherPath !== selfPath && selfPath.startsWith(otherPath);
4515
+ isSupertypeOf(other) {
4516
+ return (this.schema !== undefined &&
4517
+ other.schema !== undefined &&
4518
+ this.schema?.isSupertypeOf(other.schema));
4507
4519
  }
4508
- */
4509
4520
  isEqualTo(other, test) {
4510
4521
  const [selfPath, selfParams] = this.pathAndParams();
4511
4522
  const [otherPath, otherParams] = other.pathAndParams();
@@ -4779,6 +4790,9 @@ class ODataActionResource extends ODataResource {
4779
4790
  }
4780
4791
  return action;
4781
4792
  }
4793
+ clone() {
4794
+ return super.clone();
4795
+ }
4782
4796
  //#endregion
4783
4797
  returnType() {
4784
4798
  return this.schema instanceof ODataCallable
@@ -6083,6 +6097,11 @@ class ODataBatchResource extends ODataResource {
6083
6097
  segments.add(PathSegmentNames.batch, $BATCH);
6084
6098
  return new ODataBatchResource(api, { segments });
6085
6099
  }
6100
+ clone() {
6101
+ const batch = super.clone();
6102
+ batch._requests = [...this._requests];
6103
+ return batch;
6104
+ }
6086
6105
  //#endregion
6087
6106
  storeRequester() {
6088
6107
  const current = this.api.request;
@@ -6278,6 +6297,9 @@ class ODataCountResource extends ODataResource {
6278
6297
  query?.keep(QueryOptionNames.filter, QueryOptionNames.search);
6279
6298
  return new ODataCountResource(api, { segments, query });
6280
6299
  }
6300
+ clone() {
6301
+ return super.clone();
6302
+ }
6281
6303
  //#endregion
6282
6304
  //#region Requests
6283
6305
  get(options) {
@@ -6329,6 +6351,9 @@ class ODataFunctionResource extends ODataResource {
6329
6351
  }
6330
6352
  return func;
6331
6353
  }
6354
+ clone() {
6355
+ return super.clone();
6356
+ }
6332
6357
  //#endregion
6333
6358
  returnType() {
6334
6359
  return this.schema instanceof ODataCallable
@@ -6433,6 +6458,9 @@ class ODataMediaResource extends ODataResource {
6433
6458
  segments.add(PathSegmentNames.value, $VALUE);
6434
6459
  return new ODataMediaResource(api, { segments, query });
6435
6460
  }
6461
+ clone() {
6462
+ return super.clone();
6463
+ }
6436
6464
  //#endregion
6437
6465
  //#region Requests
6438
6466
  get(options) {
@@ -6485,6 +6513,9 @@ class ODataValueResource extends ODataResource {
6485
6513
  }
6486
6514
  return value;
6487
6515
  }
6516
+ clone() {
6517
+ return super.clone();
6518
+ }
6488
6519
  //#endregion
6489
6520
  //#region Requests
6490
6521
  get(options) {
@@ -6550,6 +6581,9 @@ class ODataPropertyResource extends ODataResource {
6550
6581
  }
6551
6582
  return property;
6552
6583
  }
6584
+ clone() {
6585
+ return super.clone();
6586
+ }
6553
6587
  //#endregion
6554
6588
  key(value) {
6555
6589
  const property = this.clone();
@@ -6685,6 +6719,9 @@ class ODataReferenceResource extends ODataResource {
6685
6719
  query?.clear();
6686
6720
  return new ODataReferenceResource(api, { segments, query });
6687
6721
  }
6722
+ clone() {
6723
+ return super.clone();
6724
+ }
6688
6725
  //#endregion
6689
6726
  //#region Requests
6690
6727
  post(target, options) {
@@ -6812,6 +6849,9 @@ class ODataNavigationPropertyResource extends ODataResource {
6812
6849
  }
6813
6850
  return navigation;
6814
6851
  }
6852
+ clone() {
6853
+ return super.clone();
6854
+ }
6815
6855
  //#endregion
6816
6856
  key(value) {
6817
6857
  const navigation = this.clone();
@@ -6983,6 +7023,9 @@ class ODataEntityResource extends ODataResource {
6983
7023
  query?.keep(QueryOptionNames.expand, QueryOptionNames.select, QueryOptionNames.format);
6984
7024
  return new ODataEntityResource(api, { segments, query, schema });
6985
7025
  }
7026
+ clone() {
7027
+ return super.clone();
7028
+ }
6986
7029
  //#endregion
6987
7030
  key(value) {
6988
7031
  const entity = this.clone();
@@ -7083,6 +7126,9 @@ class ODataEntitySetResource extends ODataResource {
7083
7126
  segment.type(schema.type());
7084
7127
  return new ODataEntitySetResource(api, { segments, query, schema });
7085
7128
  }
7129
+ clone() {
7130
+ return super.clone();
7131
+ }
7086
7132
  //#endregion
7087
7133
  entity(key) {
7088
7134
  const entity = ODataEntityResource.factory(this.api, {
@@ -7169,6 +7215,9 @@ class ODataMetadataResource extends ODataResource {
7169
7215
  segments.add(PathSegmentNames.metadata, $METADATA);
7170
7216
  return new ODataMetadataResource(api, segments);
7171
7217
  }
7218
+ clone() {
7219
+ return super.clone();
7220
+ }
7172
7221
  //#endregion
7173
7222
  //#region Requests
7174
7223
  get(options) {
@@ -7192,6 +7241,9 @@ class ODataSingletonResource extends ODataResource {
7192
7241
  segment.type(schema.type());
7193
7242
  return new ODataSingletonResource(api, { segments, query, schema });
7194
7243
  }
7244
+ clone() {
7245
+ return super.clone();
7246
+ }
7195
7247
  //#endregion
7196
7248
  key(value) {
7197
7249
  const singleton = this.clone();
@@ -7674,8 +7726,8 @@ class ODataModelOptions {
7674
7726
  attach(self, resource) {
7675
7727
  if (self._resource !== null &&
7676
7728
  resource.type() !== self._resource.type() &&
7677
- !resource.isSubtypeOf(self._resource))
7678
- throw new Error(`Can't reattach ${resource.type()} to ${self._resource.type()}`);
7729
+ !self._resource.isSubtypeOf(resource))
7730
+ throw new Error(`Can't attach ${resource.type()} to ${self._resource.type()}`);
7679
7731
  const current = self._resource;
7680
7732
  if (current === null || !current.isEqualTo(resource)) {
7681
7733
  self._resource = resource;
@@ -7702,12 +7754,7 @@ class ODataModelOptions {
7702
7754
  static resource(child) {
7703
7755
  let resource = undefined;
7704
7756
  for (let [model, field] of ODataModelOptions.chain(child)) {
7705
- resource =
7706
- resource ||
7707
- model._resource ||
7708
- (ODataModelOptions.isModel(model)
7709
- ? model._meta.modelResourceFactory()
7710
- : model._model.meta.collectionResourceFactory());
7757
+ resource = resource || model._resource;
7711
7758
  if (resource === undefined)
7712
7759
  break;
7713
7760
  if (ODataModelOptions.isModel(model)) {
@@ -7722,7 +7769,7 @@ class ODataModelOptions {
7722
7769
  }
7723
7770
  if (field === null) {
7724
7771
  const query = model._resource?.cloneQuery().toQueryArguments();
7725
- if (query !== undefined)
7772
+ if (query !== undefined && resource !== undefined)
7726
7773
  resource.query((q) => q.apply(query));
7727
7774
  continue;
7728
7775
  }
@@ -7763,7 +7810,8 @@ class ODataModelOptions {
7763
7810
  self._parent = parent;
7764
7811
  }
7765
7812
  // Resource
7766
- resource = resource || this.modelResourceFactory();
7813
+ if (self._parent === null && resource === undefined)
7814
+ resource = this.modelResourceFactory();
7767
7815
  if (resource !== undefined) {
7768
7816
  this.attach(self, resource);
7769
7817
  }
@@ -7886,14 +7934,29 @@ class ODataModelOptions {
7886
7934
  (model != undefined && model.hasChanged({ include_navigation })))));
7887
7935
  }
7888
7936
  asEntity(self, func) {
7889
- const parent = self._parent;
7937
+ // Build new resource
7938
+ const query = self.resource().cloneQuery();
7939
+ let resource = this.modelResourceFactory(query);
7940
+ if (resource === undefined)
7941
+ throw new Error('Model does not have associated Entity endpoint');
7942
+ // Store parent and resource
7943
+ const store = { parent: self._parent, resource: self._resource };
7944
+ // Replace parent and resource
7890
7945
  self._parent = null;
7946
+ self._resource = resource;
7947
+ // Execute function
7891
7948
  const result = func(self);
7892
7949
  if (result instanceof Observable) {
7893
- return result.pipe(finalize(() => (self._parent = parent)));
7950
+ return result.pipe(finalize(() => {
7951
+ // Restore parent and resource
7952
+ self._parent = store.parent;
7953
+ self._resource = store.resource;
7954
+ }));
7894
7955
  }
7895
7956
  else {
7896
- self._parent = parent;
7957
+ // Restore parent and resource
7958
+ self._parent = store.parent;
7959
+ self._resource = store.resource;
7897
7960
  return result;
7898
7961
  }
7899
7962
  }
@@ -8292,7 +8355,8 @@ class ODataCollection {
8292
8355
  this._parent = parent;
8293
8356
  }
8294
8357
  // Resource
8295
- resource = (resource || this._model.meta.collectionResourceFactory());
8358
+ if (this._parent === null && resource === undefined)
8359
+ resource = this._model.meta.collectionResourceFactory();
8296
8360
  if (resource !== undefined) {
8297
8361
  this.attach(resource);
8298
8362
  }
@@ -8321,8 +8385,8 @@ class ODataCollection {
8321
8385
  attach(resource) {
8322
8386
  if (this._resource !== null &&
8323
8387
  this._resource.type() !== resource.type() &&
8324
- !resource.isSubtypeOf(this._resource))
8325
- throw new Error(`Can't reattach ${resource.type()} to ${this._resource.type()}`);
8388
+ !this._resource.isSubtypeOf(resource))
8389
+ throw new Error(`Can't reattach ${this._resource.type()} to ${resource.type()}`);
8326
8390
  this._entries.forEach(({ model }) => {
8327
8391
  const mr = this._model.meta.modelResourceFactory(resource.cloneQuery());
8328
8392
  model.attach(mr);
@@ -8338,14 +8402,29 @@ class ODataCollection {
8338
8402
  }
8339
8403
  }
8340
8404
  asEntitySet(func) {
8341
- const parent = this._parent;
8405
+ // Build new resource
8406
+ const query = this.resource().cloneQuery();
8407
+ let resource = this._model.meta.collectionResourceFactory(query);
8408
+ if (resource === undefined)
8409
+ throw new Error('Collection does not have associated EntitySet endpoint');
8410
+ // Store parent and resource
8411
+ const store = { parent: this._parent, resource: this._resource };
8412
+ // Replace parent and resource
8342
8413
  this._parent = null;
8414
+ this._resource = resource;
8415
+ // Execute
8343
8416
  const result = func(this);
8344
8417
  if (result instanceof Observable) {
8345
- return result.pipe(finalize(() => (this._parent = parent)));
8418
+ return result.pipe(finalize(() => {
8419
+ // Restore
8420
+ this._parent = store.parent;
8421
+ this._resource = store.resource;
8422
+ }));
8346
8423
  }
8347
8424
  else {
8348
- this._parent = parent;
8425
+ // Restore
8426
+ this._parent = store.parent;
8427
+ this._resource = store.resource;
8349
8428
  return result;
8350
8429
  }
8351
8430
  }
@@ -10203,9 +10282,9 @@ class ODataClient {
10203
10282
  return this.request('PUT', resource, addBody(options, body));
10204
10283
  }
10205
10284
  }
10206
- ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataSettings }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
10207
- ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataClient, providedIn: 'root' });
10208
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataClient, decorators: [{
10285
+ ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataSettings }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
10286
+ ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataClient, providedIn: 'root' });
10287
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataClient, decorators: [{
10209
10288
  type: Injectable,
10210
10289
  args: [{
10211
10290
  providedIn: 'root',
@@ -10461,9 +10540,9 @@ class ODataServiceFactory {
10461
10540
  })(this.client, singletonName, apiNameOrEntityType);
10462
10541
  }
10463
10542
  }
10464
- ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10465
- ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory });
10466
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory, decorators: [{
10543
+ ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10544
+ ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataServiceFactory });
10545
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataServiceFactory, decorators: [{
10467
10546
  type: Injectable
10468
10547
  }], ctorParameters: function () { return [{ type: ODataClient }]; } });
10469
10548
 
@@ -10487,10 +10566,10 @@ class ODataModule {
10487
10566
  };
10488
10567
  }
10489
10568
  }
10490
- ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10491
- ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10492
- ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10493
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, decorators: [{
10569
+ ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10570
+ ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10571
+ ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10572
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataModule, decorators: [{
10494
10573
  type: NgModule,
10495
10574
  args: [{
10496
10575
  imports: [HttpClientModule],