angular-odata 0.140.0 → 0.141.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 (58) hide show
  1. package/fesm2022/angular-odata.mjs +82 -61
  2. package/fesm2022/angular-odata.mjs.map +1 -1
  3. package/index.d.ts +243 -213
  4. package/package.json +1 -1
  5. package/schematics/apigen/angular/api-config.d.ts +2 -1
  6. package/schematics/apigen/angular/api-config.js +9 -3
  7. package/schematics/apigen/angular/api-config.js.map +1 -1
  8. package/schematics/apigen/angular/base.d.ts +12 -3
  9. package/schematics/apigen/angular/base.js +87 -5
  10. package/schematics/apigen/angular/base.js.map +1 -1
  11. package/schematics/apigen/angular/collection.d.ts +23 -0
  12. package/schematics/apigen/angular/collection.js +79 -0
  13. package/schematics/apigen/angular/collection.js.map +1 -0
  14. package/schematics/apigen/angular/entity.d.ts +8 -2
  15. package/schematics/apigen/angular/entity.js +45 -14
  16. package/schematics/apigen/angular/entity.js.map +1 -1
  17. package/schematics/apigen/angular/enum.d.ts +2 -1
  18. package/schematics/apigen/angular/enum.js +2 -2
  19. package/schematics/apigen/angular/enum.js.map +1 -1
  20. package/schematics/apigen/angular/model.d.ts +40 -0
  21. package/schematics/apigen/angular/model.js +265 -0
  22. package/schematics/apigen/angular/model.js.map +1 -0
  23. package/schematics/apigen/angular/module.d.ts +3 -1
  24. package/schematics/apigen/angular/module.js +3 -2
  25. package/schematics/apigen/angular/module.js.map +1 -1
  26. package/schematics/apigen/angular/package.d.ts +38 -0
  27. package/schematics/apigen/angular/package.js +169 -0
  28. package/schematics/apigen/angular/package.js.map +1 -0
  29. package/schematics/apigen/angular/service.d.ts +2 -1
  30. package/schematics/apigen/angular/service.js +2 -2
  31. package/schematics/apigen/angular/service.js.map +1 -1
  32. package/schematics/apigen/files/api-config/__fileName__.ts +9 -2
  33. package/schematics/apigen/files/collection/__fileName__.ts +20 -0
  34. package/schematics/apigen/files/entity/__fileName__.ts +2 -1
  35. package/schematics/apigen/files/model/__fileName__.ts +31 -0
  36. package/schematics/apigen/index.js +6 -88
  37. package/schematics/apigen/index.js.map +1 -1
  38. package/schematics/apigen/metadata/csdl/csdl-entity-set.js +1 -1
  39. package/schematics/apigen/metadata/csdl/csdl-entity-set.js.map +1 -1
  40. package/schematics/apigen/metadata/csdl/csdl-function-action.d.ts +1 -0
  41. package/schematics/apigen/metadata/csdl/csdl-function-action.js +6 -0
  42. package/schematics/apigen/metadata/csdl/csdl-function-action.js.map +1 -1
  43. package/schematics/apigen/metadata/csdl/csdl-navigation-property-binding.d.ts +9 -1
  44. package/schematics/apigen/metadata/csdl/csdl-navigation-property-binding.js +34 -1
  45. package/schematics/apigen/metadata/csdl/csdl-navigation-property-binding.js.map +1 -1
  46. package/schematics/apigen/metadata/csdl/csdl-singleton.js +1 -1
  47. package/schematics/apigen/metadata/csdl/csdl-singleton.js.map +1 -1
  48. package/schematics/apigen/metadata/csdl/csdl-structural-property.d.ts +8 -3
  49. package/schematics/apigen/metadata/csdl/csdl-structural-property.js +11 -5
  50. package/schematics/apigen/metadata/csdl/csdl-structural-property.js.map +1 -1
  51. package/schematics/apigen/metadata/csdl/csdl-structured-type.d.ts +1 -0
  52. package/schematics/apigen/metadata/csdl/csdl-structured-type.js +16 -2
  53. package/schematics/apigen/metadata/csdl/csdl-structured-type.js.map +1 -1
  54. package/schematics/apigen/metadata/metadata.d.ts +12 -1
  55. package/schematics/apigen/metadata/metadata.js +44 -2
  56. package/schematics/apigen/metadata/metadata.js.map +1 -1
  57. package/schematics/apigen/schema.d.ts +1 -0
  58. package/schematics/apigen/schema.json +5 -0
@@ -497,21 +497,19 @@ const SUPPORTED_EXPAND_PROPERTIES = [
497
497
  ];
498
498
  const FUNCTION_REGEX = /\((.*)\)/;
499
499
  const INDEXOF_REGEX = /(?!indexof)\((\w+)\)/;
500
- var StandardAggregateMethods;
501
- (function (StandardAggregateMethods) {
502
- StandardAggregateMethods["sum"] = "sum";
503
- StandardAggregateMethods["min"] = "min";
504
- StandardAggregateMethods["max"] = "max";
505
- StandardAggregateMethods["average"] = "average";
506
- StandardAggregateMethods["countdistinct"] = "countdistinct";
507
- })(StandardAggregateMethods || (StandardAggregateMethods = {}));
508
- var QueryCustomTypes;
509
- (function (QueryCustomTypes) {
510
- QueryCustomTypes[QueryCustomTypes["Raw"] = 0] = "Raw";
511
- QueryCustomTypes[QueryCustomTypes["Alias"] = 1] = "Alias";
512
- QueryCustomTypes[QueryCustomTypes["Duration"] = 2] = "Duration";
513
- QueryCustomTypes[QueryCustomTypes["Binary"] = 3] = "Binary";
514
- })(QueryCustomTypes || (QueryCustomTypes = {}));
500
+ const StandardAggregateMethods = {
501
+ sum: 'sum',
502
+ min: 'min',
503
+ max: 'max',
504
+ average: 'average',
505
+ countdistinct: 'countdistinct'
506
+ };
507
+ const QueryCustomTypes = {
508
+ Raw: 'Raw',
509
+ Alias: 'Alias',
510
+ Duration: 'Duration',
511
+ Binary: 'Binary'
512
+ };
515
513
  //https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_QueryOptions
516
514
  const raw = (value) => ({
517
515
  type: QueryCustomTypes.Raw,
@@ -887,10 +885,8 @@ function buildFilter(filters = {}, { aliases, propPrefix, escape, }) {
887
885
  }
888
886
  }
889
887
  function getStringCollectionClause(lambdaParameter, value, collectionOperator, propName) {
890
- let clause = '';
891
888
  const conditionOperator = collectionOperator == 'all' ? 'ne' : 'eq';
892
- clause = `${propName}/${collectionOperator}(${lambdaParameter}: ${lambdaParameter} ${conditionOperator} '${value}')`;
893
- return clause;
889
+ return `${propName}/${collectionOperator}(${lambdaParameter}: ${lambdaParameter} ${conditionOperator} '${value}')`;
894
890
  }
895
891
  function escapeIllegalChars(string) {
896
892
  string = string.replace(/%/g, '%25');
@@ -1028,27 +1024,40 @@ function buildTransforms(transforms, { aliases, escape = false }) {
1028
1024
  // Wrap single object an array for simplified processing
1029
1025
  const transformsArray = Array.isArray(transforms) ? transforms : [transforms];
1030
1026
  const transformsResult = transformsArray.reduce((result, transform) => {
1031
- const { aggregate, filter, groupBy, ...rest } = transform;
1032
- // TODO: support as many of the following:
1033
- // topcount, topsum, toppercent,
1034
- // bottomsum, bottomcount, bottompercent,
1035
- // identity, concat, expand, search, compute, isdefined
1036
- const unsupportedKeys = Object.keys(rest);
1037
- if (unsupportedKeys.length) {
1038
- throw new Error(`Unsupported transform(s): ${unsupportedKeys}`);
1039
- }
1040
- if (aggregate) {
1041
- result.push(`aggregate(${buildAggregate(aggregate)})`);
1042
- }
1043
- if (filter) {
1044
- const builtFilter = buildFilter(filter, { aliases, escape });
1045
- if (builtFilter) {
1046
- result.push(`filter(${buildFilter(builtFilter, { aliases, escape })})`);
1027
+ for (const key of Object.keys(transform)) {
1028
+ switch (key) {
1029
+ // TODO: support as many of the following:
1030
+ // topcount, topsum, toppercent,
1031
+ // bottomsum, bottomcount, bottompercent,
1032
+ // identity, concat, expand, search, compute, isdefined
1033
+ case 'aggregate': {
1034
+ const aggregate = transform[key];
1035
+ if (aggregate) {
1036
+ result.push(`aggregate(${buildAggregate(aggregate)})`);
1037
+ }
1038
+ break;
1039
+ }
1040
+ case 'filter': {
1041
+ const filter = transform[key];
1042
+ if (filter) {
1043
+ const builtFilter = buildFilter(filter, { aliases, escape });
1044
+ if (builtFilter) {
1045
+ result.push(`filter(${builtFilter})`);
1046
+ }
1047
+ }
1048
+ break;
1049
+ }
1050
+ case 'groupBy': {
1051
+ const groupBy = transform[key];
1052
+ if (groupBy) {
1053
+ result.push(`groupby(${buildGroupBy(groupBy, { aliases, escape })})`);
1054
+ }
1055
+ break;
1056
+ }
1057
+ default:
1058
+ throw new Error(`Unsupported transform(s): ${key}`);
1047
1059
  }
1048
1060
  }
1049
- if (groupBy) {
1050
- result.push(`groupby(${buildGroupBy(groupBy, { aliases, escape })})`);
1051
- }
1052
1061
  return result;
1053
1062
  }, []);
1054
1063
  return transformsResult.join('/') || undefined;
@@ -2977,14 +2986,7 @@ class ODataStructuredType extends ODataParserSchemaElement {
2977
2986
  parserForType: (t) => this.api.parserForType(t),
2978
2987
  });
2979
2988
  if (this.model !== undefined) {
2980
- this.model.meta = this.api.optionsForType(this.type(), {
2981
- config: this.model.options,
2982
- structuredType: this,
2983
- });
2984
- if (this.model.meta !== undefined) {
2985
- // Configure
2986
- this.model.meta.configure({ options });
2987
- }
2989
+ this.api.configureModel(this, this.model);
2988
2990
  if (this.collection !== undefined) {
2989
2991
  this.collection.model = this.model;
2990
2992
  }
@@ -9177,7 +9179,7 @@ class ODataMetadataParser {
9177
9179
  try {
9178
9180
  const parser = new DOMParser();
9179
9181
  this.document = parser.parseFromString(xml, 'text/xml');
9180
- this.checkVersion(document);
9182
+ this.checkVersion(this.document);
9181
9183
  }
9182
9184
  catch (error) {
9183
9185
  throw new Error('Unable to parse metadata, ' + error);
@@ -9207,9 +9209,9 @@ class ODataMetadataParser {
9207
9209
  ]);
9208
9210
  return new ODataMetadata(version, references, schemas);
9209
9211
  }
9210
- checkVersion(document) {
9212
+ checkVersion(doc) {
9211
9213
  // check version
9212
- const attributes = document.documentElement.attributes;
9214
+ const attributes = doc.documentElement.attributes;
9213
9215
  if (!attributes) {
9214
9216
  throw new Error('OData version is not specified in the metadata');
9215
9217
  }
@@ -12789,6 +12791,10 @@ class ODataApi {
12789
12791
  parsers;
12790
12792
  // Schemas
12791
12793
  schemas;
12794
+ // Models
12795
+ models = {};
12796
+ // Collections
12797
+ collections = {};
12792
12798
  constructor(config) {
12793
12799
  this.serviceRootUrl = config.serviceRootUrl;
12794
12800
  if (this.serviceRootUrl.includes('?'))
@@ -12808,6 +12814,8 @@ class ODataApi {
12808
12814
  this.errorHandler = config.errorHandler;
12809
12815
  this.parsers = new Map(Object.entries(config.parsers ?? EDM_PARSERS));
12810
12816
  this.schemas = (config.schemas ?? []).map((schema) => new ODataSchema(schema, this));
12817
+ this.models = (config.models ?? {});
12818
+ this.collections = (config.collections ?? {});
12811
12819
  }
12812
12820
  configure(settings = {}) {
12813
12821
  this.requester = settings.requester;
@@ -12816,6 +12824,16 @@ class ODataApi {
12816
12824
  options: this.options.parserOptions,
12817
12825
  });
12818
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
+ });
12819
12837
  }
12820
12838
  populate(metadata) {
12821
12839
  const config = metadata.toConfig();
@@ -13084,8 +13102,18 @@ class ODataApi {
13084
13102
  return singleton;
13085
13103
  }
13086
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
+ }
13087
13115
  findModel(type) {
13088
- return this.findStructuredType(type)?.model;
13116
+ return (this.models[type] ?? this.findStructuredType(type)?.model);
13089
13117
  }
13090
13118
  createModel(structured) {
13091
13119
  if (structured.model !== undefined)
@@ -13093,17 +13121,7 @@ class ODataApi {
13093
13121
  // Build Ad-hoc model
13094
13122
  const Model = class extends ODataModel {
13095
13123
  };
13096
- // Build Meta
13097
- Model.meta = this.optionsForType(structured.type(), {
13098
- structuredType: structured,
13099
- });
13100
- if (Model.meta !== undefined) {
13101
- // Configure
13102
- Model.meta.configure({
13103
- options: this.options.parserOptions,
13104
- });
13105
- }
13106
- // Store New Model for next time
13124
+ // Store New Model structured for next time
13107
13125
  structured.model = Model;
13108
13126
  return Model;
13109
13127
  }
@@ -13114,20 +13132,23 @@ class ODataApi {
13114
13132
  if (structured === undefined)
13115
13133
  throw Error(`No structured type for ${type}`);
13116
13134
  Model = this.createModel(structured);
13135
+ this.configureModel(structured, Model);
13117
13136
  }
13118
13137
  return Model;
13119
13138
  }
13120
13139
  findCollection(type) {
13121
- return this.findStructuredType(type)?.collection;
13140
+ return (this.collections[type] ?? this.findStructuredType(type)?.collection);
13122
13141
  }
13123
13142
  createCollection(structured, model) {
13124
13143
  if (structured.collection !== undefined)
13125
13144
  return structured.collection;
13126
13145
  if (model === undefined)
13127
13146
  model = this.createModel(structured);
13147
+ // Build Ad-hoc collection
13128
13148
  const Collection = class extends ODataCollection {
13129
13149
  static model = model;
13130
13150
  };
13151
+ // Store New Collection structured for next time
13131
13152
  structured.collection = Collection;
13132
13153
  return Collection;
13133
13154
  }