angular-odata 0.140.1 → 0.142.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.
Files changed (67) hide show
  1. package/fesm2022/angular-odata.mjs +58 -44
  2. package/fesm2022/angular-odata.mjs.map +1 -1
  3. package/package.json +5 -5
  4. package/schematics/apigen/angular/api-config.d.ts +2 -1
  5. package/schematics/apigen/angular/api-config.js +9 -3
  6. package/schematics/apigen/angular/api-config.js.map +1 -1
  7. package/schematics/apigen/angular/base.d.ts +13 -4
  8. package/schematics/apigen/angular/base.js +104 -14
  9. package/schematics/apigen/angular/base.js.map +1 -1
  10. package/schematics/apigen/angular/collection.d.ts +23 -0
  11. package/schematics/apigen/angular/collection.js +76 -0
  12. package/schematics/apigen/angular/collection.js.map +1 -0
  13. package/schematics/apigen/angular/entity.d.ts +8 -2
  14. package/schematics/apigen/angular/entity.js +45 -14
  15. package/schematics/apigen/angular/entity.js.map +1 -1
  16. package/schematics/apigen/angular/enum.d.ts +2 -1
  17. package/schematics/apigen/angular/enum.js +2 -2
  18. package/schematics/apigen/angular/enum.js.map +1 -1
  19. package/schematics/apigen/angular/import.d.ts +3 -1
  20. package/schematics/apigen/angular/import.js +16 -2
  21. package/schematics/apigen/angular/import.js.map +1 -1
  22. package/schematics/apigen/angular/model.d.ts +40 -0
  23. package/schematics/apigen/angular/model.js +267 -0
  24. package/schematics/apigen/angular/model.js.map +1 -0
  25. package/schematics/apigen/angular/module.d.ts +3 -1
  26. package/schematics/apigen/angular/module.js +3 -2
  27. package/schematics/apigen/angular/module.js.map +1 -1
  28. package/schematics/apigen/angular/package.d.ts +38 -0
  29. package/schematics/apigen/angular/package.js +166 -0
  30. package/schematics/apigen/angular/package.js.map +1 -0
  31. package/schematics/apigen/angular/service.d.ts +2 -1
  32. package/schematics/apigen/angular/service.js +2 -2
  33. package/schematics/apigen/angular/service.js.map +1 -1
  34. package/schematics/apigen/files/api-config/__fileName__.ts +9 -2
  35. package/schematics/apigen/files/collection/__fileName__.ts +20 -0
  36. package/schematics/apigen/files/entity/__fileName__.ts +3 -2
  37. package/schematics/apigen/files/entitycontainer-service/__fileName__.ts +1 -1
  38. package/schematics/apigen/files/entityset-service/__fileName__.ts +1 -1
  39. package/schematics/apigen/files/model/__fileName__.ts +31 -0
  40. package/schematics/apigen/files/module/__fileName__.ts +1 -1
  41. package/schematics/apigen/files/singleton-service/__fileName__.ts +1 -1
  42. package/schematics/apigen/index.js +18 -97
  43. package/schematics/apigen/index.js.map +1 -1
  44. package/schematics/apigen/metadata/csdl/csdl-entity-set.js +1 -1
  45. package/schematics/apigen/metadata/csdl/csdl-entity-set.js.map +1 -1
  46. package/schematics/apigen/metadata/csdl/csdl-function-action.d.ts +1 -0
  47. package/schematics/apigen/metadata/csdl/csdl-function-action.js +6 -0
  48. package/schematics/apigen/metadata/csdl/csdl-function-action.js.map +1 -1
  49. package/schematics/apigen/metadata/csdl/csdl-navigation-property-binding.d.ts +9 -1
  50. package/schematics/apigen/metadata/csdl/csdl-navigation-property-binding.js +36 -1
  51. package/schematics/apigen/metadata/csdl/csdl-navigation-property-binding.js.map +1 -1
  52. package/schematics/apigen/metadata/csdl/csdl-singleton.js +1 -1
  53. package/schematics/apigen/metadata/csdl/csdl-singleton.js.map +1 -1
  54. package/schematics/apigen/metadata/csdl/csdl-structural-property.d.ts +8 -3
  55. package/schematics/apigen/metadata/csdl/csdl-structural-property.js +11 -5
  56. package/schematics/apigen/metadata/csdl/csdl-structural-property.js.map +1 -1
  57. package/schematics/apigen/metadata/csdl/csdl-structured-type.d.ts +1 -0
  58. package/schematics/apigen/metadata/csdl/csdl-structured-type.js +16 -2
  59. package/schematics/apigen/metadata/csdl/csdl-structured-type.js.map +1 -1
  60. package/schematics/apigen/metadata/metadata.d.ts +12 -1
  61. package/schematics/apigen/metadata/metadata.js +44 -2
  62. package/schematics/apigen/metadata/metadata.js.map +1 -1
  63. package/schematics/apigen/schema.d.ts +1 -0
  64. package/schematics/apigen/schema.json +5 -0
  65. package/schematics/random.js +1 -1
  66. package/schematics/random.js.map +1 -1
  67. package/{index.d.ts → types/angular-odata.d.ts} +1440 -1404
@@ -502,13 +502,13 @@ const StandardAggregateMethods = {
502
502
  min: 'min',
503
503
  max: 'max',
504
504
  average: 'average',
505
- countdistinct: 'countdistinct'
505
+ countdistinct: 'countdistinct',
506
506
  };
507
507
  const QueryCustomTypes = {
508
508
  Raw: 'Raw',
509
509
  Alias: 'Alias',
510
510
  Duration: 'Duration',
511
- Binary: 'Binary'
511
+ Binary: 'Binary',
512
512
  };
513
513
  //https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_QueryOptions
514
514
  const raw = (value) => ({
@@ -2986,14 +2986,7 @@ class ODataStructuredType extends ODataParserSchemaElement {
2986
2986
  parserForType: (t) => this.api.parserForType(t),
2987
2987
  });
2988
2988
  if (this.model !== undefined) {
2989
- this.model.meta = this.api.optionsForType(this.type(), {
2990
- config: this.model.options,
2991
- structuredType: this,
2992
- });
2993
- if (this.model.meta !== undefined) {
2994
- // Configure
2995
- this.model.meta.configure({ options });
2996
- }
2989
+ this.api.configureModel(this, this.model);
2997
2990
  if (this.collection !== undefined) {
2998
2991
  this.collection.model = this.model;
2999
2992
  }
@@ -9186,7 +9179,7 @@ class ODataMetadataParser {
9186
9179
  try {
9187
9180
  const parser = new DOMParser();
9188
9181
  this.document = parser.parseFromString(xml, 'text/xml');
9189
- this.checkVersion(document);
9182
+ this.checkVersion(this.document);
9190
9183
  }
9191
9184
  catch (error) {
9192
9185
  throw new Error('Unable to parse metadata, ' + error);
@@ -9216,9 +9209,9 @@ class ODataMetadataParser {
9216
9209
  ]);
9217
9210
  return new ODataMetadata(version, references, schemas);
9218
9211
  }
9219
- checkVersion(document) {
9212
+ checkVersion(doc) {
9220
9213
  // check version
9221
- const attributes = document.documentElement.attributes;
9214
+ const attributes = doc.documentElement.attributes;
9222
9215
  if (!attributes) {
9223
9216
  throw new Error('OData version is not specified in the metadata');
9224
9217
  }
@@ -10577,7 +10570,7 @@ class ODataCollection {
10577
10570
  }
10578
10571
  }
10579
10572
  else if (resource instanceof ODataEntitySetResource) {
10580
- return model.asEntity((e) => e.destroy(options));
10573
+ return model.asEntity((e) => e.destroy(options)).pipe(map(() => model));
10581
10574
  }
10582
10575
  else {
10583
10576
  return of(model);
@@ -12798,6 +12791,10 @@ class ODataApi {
12798
12791
  parsers;
12799
12792
  // Schemas
12800
12793
  schemas;
12794
+ // Models
12795
+ models = {};
12796
+ // Collections
12797
+ collections = {};
12801
12798
  constructor(config) {
12802
12799
  this.serviceRootUrl = config.serviceRootUrl;
12803
12800
  if (this.serviceRootUrl.includes('?'))
@@ -12817,6 +12814,8 @@ class ODataApi {
12817
12814
  this.errorHandler = config.errorHandler;
12818
12815
  this.parsers = new Map(Object.entries(config.parsers ?? EDM_PARSERS));
12819
12816
  this.schemas = (config.schemas ?? []).map((schema) => new ODataSchema(schema, this));
12817
+ this.models = (config.models ?? {});
12818
+ this.collections = (config.collections ?? {});
12820
12819
  }
12821
12820
  configure(settings = {}) {
12822
12821
  this.requester = settings.requester;
@@ -12825,6 +12824,16 @@ class ODataApi {
12825
12824
  options: this.options.parserOptions,
12826
12825
  });
12827
12826
  });
12827
+ Object.entries(this.models).forEach(([type, model]) => {
12828
+ const structured = this.findStructuredType(type);
12829
+ if (structured !== undefined) {
12830
+ this.configureModel(structured, model);
12831
+ const collection = this.collections[type];
12832
+ if (collection !== undefined) {
12833
+ collection.model = model;
12834
+ }
12835
+ }
12836
+ });
12828
12837
  }
12829
12838
  populate(metadata) {
12830
12839
  const config = metadata.toConfig();
@@ -13093,8 +13102,18 @@ class ODataApi {
13093
13102
  return singleton;
13094
13103
  }
13095
13104
  //#endregion
13105
+ configureModel(structured, model) {
13106
+ model.meta = this.optionsForType(structured.type(), {
13107
+ config: model.options,
13108
+ structuredType: structured,
13109
+ });
13110
+ if (model.meta !== undefined) {
13111
+ // Configure
13112
+ model.meta.configure({ options: this.options.parserOptions });
13113
+ }
13114
+ }
13096
13115
  findModel(type) {
13097
- return this.findStructuredType(type)?.model;
13116
+ return (this.models[type] ?? this.findStructuredType(type)?.model);
13098
13117
  }
13099
13118
  createModel(structured) {
13100
13119
  if (structured.model !== undefined)
@@ -13102,17 +13121,7 @@ class ODataApi {
13102
13121
  // Build Ad-hoc model
13103
13122
  const Model = class extends ODataModel {
13104
13123
  };
13105
- // Build Meta
13106
- Model.meta = this.optionsForType(structured.type(), {
13107
- structuredType: structured,
13108
- });
13109
- if (Model.meta !== undefined) {
13110
- // Configure
13111
- Model.meta.configure({
13112
- options: this.options.parserOptions,
13113
- });
13114
- }
13115
- // Store New Model for next time
13124
+ // Store New Model structured for next time
13116
13125
  structured.model = Model;
13117
13126
  return Model;
13118
13127
  }
@@ -13123,20 +13132,23 @@ class ODataApi {
13123
13132
  if (structured === undefined)
13124
13133
  throw Error(`No structured type for ${type}`);
13125
13134
  Model = this.createModel(structured);
13135
+ this.configureModel(structured, Model);
13126
13136
  }
13127
13137
  return Model;
13128
13138
  }
13129
13139
  findCollection(type) {
13130
- return this.findStructuredType(type)?.collection;
13140
+ return (this.collections[type] ?? this.findStructuredType(type)?.collection);
13131
13141
  }
13132
13142
  createCollection(structured, model) {
13133
13143
  if (structured.collection !== undefined)
13134
13144
  return structured.collection;
13135
13145
  if (model === undefined)
13136
13146
  model = this.createModel(structured);
13147
+ // Build Ad-hoc collection
13137
13148
  const Collection = class extends ODataCollection {
13138
13149
  static model = model;
13139
13150
  };
13151
+ // Store New Collection structured for next time
13140
13152
  structured.collection = Collection;
13141
13153
  return Collection;
13142
13154
  }
@@ -13535,10 +13547,10 @@ class ODataClient {
13535
13547
  put(resource, body, options = {}) {
13536
13548
  return this.request('PUT', resource, addBody(options, body));
13537
13549
  }
13538
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.2", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataConfigLoader }], target: i0.ɵɵFactoryTarget.Injectable });
13539
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.2", ngImport: i0, type: ODataClient });
13550
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataConfigLoader }], target: i0.ɵɵFactoryTarget.Injectable });
13551
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataClient });
13540
13552
  }
13541
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.2", ngImport: i0, type: ODataClient, decorators: [{
13553
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataClient, decorators: [{
13542
13554
  type: Injectable
13543
13555
  }], ctorParameters: () => [{ type: i1.HttpClient }, { type: ODataConfigLoader }] });
13544
13556
 
@@ -13822,10 +13834,10 @@ class ODataServiceFactory {
13822
13834
  };
13823
13835
  return new Service(this.client, singletonName, apiNameOrEntityType);
13824
13836
  }
13825
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.2", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
13826
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.2", ngImport: i0, type: ODataServiceFactory });
13837
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
13838
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataServiceFactory });
13827
13839
  }
13828
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.2", ngImport: i0, type: ODataServiceFactory, decorators: [{
13840
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataServiceFactory, decorators: [{
13829
13841
  type: Injectable
13830
13842
  }], ctorParameters: () => [{ type: ODataClient }] });
13831
13843
 
@@ -13865,11 +13877,11 @@ class ODataModule {
13865
13877
  ],
13866
13878
  };
13867
13879
  }
13868
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.2", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
13869
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.2.2", ngImport: i0, type: ODataModule, imports: [CommonModule] });
13870
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.2.2", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [CommonModule] });
13880
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
13881
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.5", ngImport: i0, type: ODataModule, imports: [CommonModule] });
13882
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [CommonModule] });
13871
13883
  }
13872
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.2", ngImport: i0, type: ODataModule, decorators: [{
13884
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataModule, decorators: [{
13873
13885
  type: NgModule,
13874
13886
  args: [{
13875
13887
  imports: [CommonModule],
@@ -13922,9 +13934,9 @@ class ODataBaseCache {
13922
13934
  buildEntry(payload, { timeout, tags }) {
13923
13935
  return {
13924
13936
  payload,
13925
- lastRead: Date.now(),
13926
- timeout: timeout || this.timeout,
13927
- tags: tags || [],
13937
+ lastread: Date.now(),
13938
+ timeout: (timeout ?? this.timeout) * 1000,
13939
+ tags: tags ?? [],
13928
13940
  };
13929
13941
  }
13930
13942
  /**
@@ -13945,9 +13957,8 @@ class ODataBaseCache {
13945
13957
  */
13946
13958
  put(name, payload, { timeout, scope, tags } = {}) {
13947
13959
  const entry = this.buildEntry(payload, { timeout, tags });
13948
- const key = this.buildKey([...(scope || []), name]);
13960
+ const key = this.buildKey([...(scope ?? []), name]);
13949
13961
  this.entries.set(key, entry);
13950
- this.forget();
13951
13962
  }
13952
13963
  /**
13953
13964
  * Return the payload from the cache if it exists and is not expired
@@ -13958,7 +13969,10 @@ class ODataBaseCache {
13958
13969
  get(name, { scope } = {}) {
13959
13970
  const key = this.buildKey([...(scope || []), name]);
13960
13971
  const entry = this.entries.get(key);
13961
- return entry !== undefined && !this.isExpired(entry) ? entry.payload : undefined;
13972
+ if (entry === undefined || this.isExpired(entry))
13973
+ return undefined;
13974
+ entry.lastread = Date.now();
13975
+ return entry.payload;
13962
13976
  }
13963
13977
  /**
13964
13978
  * Remove all cache entries that are matching with the given options
@@ -13989,7 +14003,7 @@ class ODataBaseCache {
13989
14003
  * @returns Boolean indicating if the entry is expired
13990
14004
  */
13991
14005
  isExpired(entry) {
13992
- return entry.lastRead < Date.now() - (entry.timeout || this.timeout) * 1000;
14006
+ return entry.lastread < (Date.now() - entry.timeout);
13993
14007
  }
13994
14008
  /**
13995
14009
  * Using the request, handle the fetching of the response