angular-odata 0.140.0 → 0.140.1

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.
@@ -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;