angular-odata 0.99.2 → 0.100.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.
Files changed (72) hide show
  1. package/esm2020/lib/api.mjs +65 -55
  2. package/esm2020/lib/cache/cache.mjs +2 -2
  3. package/esm2020/lib/client.mjs +3 -3
  4. package/esm2020/lib/helper.mjs +91 -86
  5. package/esm2020/lib/models/collection.mjs +35 -46
  6. package/esm2020/lib/models/model.mjs +36 -40
  7. package/esm2020/lib/models/options.mjs +53 -36
  8. package/esm2020/lib/module.mjs +4 -4
  9. package/esm2020/lib/options.mjs +4 -3
  10. package/esm2020/lib/resources/query/builder.mjs +5 -7
  11. package/esm2020/lib/resources/query/expressions/base.mjs +1 -1
  12. package/esm2020/lib/resources/query/expressions/compute.mjs +13 -6
  13. package/esm2020/lib/resources/query/expressions/expand.mjs +77 -13
  14. package/esm2020/lib/resources/query/expressions/filter.mjs +11 -5
  15. package/esm2020/lib/resources/query/expressions/orderby.mjs +11 -3
  16. package/esm2020/lib/resources/query/expressions/search.mjs +15 -3
  17. package/esm2020/lib/resources/query/expressions/select.mjs +10 -5
  18. package/esm2020/lib/resources/query/expressions/syntax.mjs +42 -9
  19. package/esm2020/lib/resources/query/handlers.mjs +41 -30
  20. package/esm2020/lib/resources/query/options.mjs +47 -44
  21. package/esm2020/lib/resources/resource.mjs +22 -61
  22. package/esm2020/lib/resources/responses/annotations.mjs +6 -6
  23. package/esm2020/lib/resources/responses/options.mjs +1 -2
  24. package/esm2020/lib/resources/responses/response.mjs +3 -3
  25. package/esm2020/lib/resources/types/entity-set.mjs +1 -1
  26. package/esm2020/lib/resources/types/entity.mjs +3 -3
  27. package/esm2020/lib/resources/types/function.mjs +9 -1
  28. package/esm2020/lib/schema/callable.mjs +6 -2
  29. package/esm2020/lib/schema/enum-type.mjs +10 -2
  30. package/esm2020/lib/schema/parsers/callable.mjs +3 -2
  31. package/esm2020/lib/schema/parsers/enum-type.mjs +6 -5
  32. package/esm2020/lib/schema/parsers/structured-type.mjs +5 -5
  33. package/esm2020/lib/schema/structured-type.mjs +4 -9
  34. package/esm2020/lib/services/entity-set.mjs +6 -6
  35. package/esm2020/lib/services/factory.mjs +3 -3
  36. package/esm2020/lib/types.mjs +2 -1
  37. package/esm2020/lib/utils/objects.mjs +5 -1
  38. package/esm2020/lib/utils/urls.mjs +2 -2
  39. package/fesm2015/angular-odata.mjs +642 -498
  40. package/fesm2015/angular-odata.mjs.map +1 -1
  41. package/fesm2020/angular-odata.mjs +642 -502
  42. package/fesm2020/angular-odata.mjs.map +1 -1
  43. package/lib/helper.d.ts +28 -57
  44. package/lib/models/collection.d.ts +4 -2
  45. package/lib/models/model.d.ts +3 -9
  46. package/lib/models/options.d.ts +13 -11
  47. package/lib/options.d.ts +4 -4
  48. package/lib/resources/query/builder.d.ts +2 -1
  49. package/lib/resources/query/expressions/base.d.ts +1 -0
  50. package/lib/resources/query/expressions/compute.d.ts +3 -2
  51. package/lib/resources/query/expressions/expand.d.ts +40 -12
  52. package/lib/resources/query/expressions/filter.d.ts +22 -21
  53. package/lib/resources/query/expressions/orderby.d.ts +4 -2
  54. package/lib/resources/query/expressions/search.d.ts +5 -2
  55. package/lib/resources/query/expressions/select.d.ts +3 -2
  56. package/lib/resources/query/expressions/syntax.d.ts +12 -2
  57. package/lib/resources/query/handlers.d.ts +19 -15
  58. package/lib/resources/query/options.d.ts +15 -15
  59. package/lib/resources/resource.d.ts +1 -0
  60. package/lib/resources/responses/annotations.d.ts +12 -18
  61. package/lib/resources/responses/options.d.ts +2 -3
  62. package/lib/resources/responses/response.d.ts +1 -3
  63. package/lib/resources/types/entity-set.d.ts +1 -1
  64. package/lib/resources/types/function.d.ts +3 -0
  65. package/lib/schema/callable.d.ts +4 -4
  66. package/lib/schema/enum-type.d.ts +10 -4
  67. package/lib/schema/parsers/callable.d.ts +9 -7
  68. package/lib/schema/parsers/enum-type.d.ts +7 -5
  69. package/lib/schema/parsers/structured-type.d.ts +7 -7
  70. package/lib/schema/structured-type.d.ts +4 -4
  71. package/lib/types.d.ts +6 -5
  72. package/package.json +3 -3
@@ -34,6 +34,7 @@ var QueryOptionNames;
34
34
  QueryOptionNames["skip"] = "skip";
35
35
  QueryOptionNames["skiptoken"] = "skiptoken";
36
36
  QueryOptionNames["format"] = "format";
37
+ QueryOptionNames["levels"] = "levels";
37
38
  QueryOptionNames["count"] = "count";
38
39
  })(QueryOptionNames || (QueryOptionNames = {}));
39
40
  const NONE_PARSER = {
@@ -214,7 +215,7 @@ class ODataCache {
214
215
  return of(cached);
215
216
  }
216
217
  else {
217
- return throwError('No Cached');
218
+ return throwError(() => new Error('No Cached'));
218
219
  }
219
220
  }
220
221
  if (policy === 'cache-first' ||
@@ -391,7 +392,7 @@ function buildPathAndQuery({ select, search, skiptoken, format, top, skip, filte
391
392
  }
392
393
  if (func) {
393
394
  if (typeof func === 'string') {
394
- path += `/${func}`;
395
+ path += `/${func}()`;
395
396
  }
396
397
  else if (typeof func === 'object') {
397
398
  const [funcName] = Object.keys(func);
@@ -399,10 +400,7 @@ function buildPathAndQuery({ select, search, skiptoken, format, top, skip, filte
399
400
  aliases,
400
401
  escape,
401
402
  });
402
- path += `/${funcName}`;
403
- if (funcArgs !== '') {
404
- path += `(${funcArgs})`;
405
- }
403
+ path += `/${funcName}(${funcArgs})`;
406
404
  }
407
405
  }
408
406
  if (aliases.length > 0) {
@@ -651,7 +649,7 @@ function escapeIllegalChars(string) {
651
649
  string = string.replace(/'/g, "''");
652
650
  return string;
653
651
  }
654
- function normalizeValue(value, { aliases, escape = false }) {
652
+ function normalizeValue(value, { aliases, escape = false, } = {}) {
655
653
  if (typeof value === 'string') {
656
654
  return escape ? `'${escapeIllegalChars(value)}'` : `'${value}'`;
657
655
  }
@@ -746,6 +744,7 @@ function buildExpand(expands, { aliases, escape = false }) {
746
744
  case 'levels':
747
745
  case 'count':
748
746
  case 'top':
747
+ case 'skip':
749
748
  value = `${expands[key]}`;
750
749
  break;
751
750
  default:
@@ -1332,6 +1331,10 @@ const Objects = {
1332
1331
  if (typeof target != 'object' || target == null) {
1333
1332
  return target;
1334
1333
  }
1334
+ if (Types.isObject(target) && 'clone' in target) {
1335
+ // target is a cloneable object
1336
+ return target.clone();
1337
+ }
1335
1338
  const type = Types.rawType(target);
1336
1339
  let cloneTarget = null;
1337
1340
  if (map.get(target)) {
@@ -1421,7 +1424,7 @@ const Urls = {
1421
1424
  let index = param.indexOf(VALUE_SEPARATOR);
1422
1425
  if (index !== -1)
1423
1426
  Object.assign(acc, {
1424
- [param.substr(0, index)]: param.substr(index + 1),
1427
+ [param.substring(0, index)]: param.substring(index + 1),
1425
1428
  });
1426
1429
  return acc;
1427
1430
  }, {});
@@ -1462,17 +1465,33 @@ class Field$1 {
1462
1465
  constructor(name = '') {
1463
1466
  this.name = name;
1464
1467
  }
1465
- static factory() {
1466
- const h = new Field$1();
1467
- return new Proxy({ _name: '' }, h);
1468
+ static factory(name = '') {
1469
+ return new Proxy({ _name: name }, new Field$1());
1468
1470
  }
1469
- get(target, p) {
1471
+ get(target, key) {
1470
1472
  let name = target['_name'];
1471
- if (p === 'render') {
1473
+ if (key === 'render') {
1472
1474
  return ({ prefix }) => prefix ? `${prefix}/${name}` : name;
1473
1475
  }
1474
- name = name ? `${name}/${p}` : p;
1475
- return new Proxy({ _name: name }, this);
1476
+ else if (key === 'clone') {
1477
+ return () => Field$1.factory(name);
1478
+ }
1479
+ else if (key === Symbol.toStringTag) {
1480
+ return () => 'Field';
1481
+ }
1482
+ else if (key === 'toJSON') {
1483
+ return () => ({
1484
+ $type: Types.rawType(this),
1485
+ name: name,
1486
+ });
1487
+ }
1488
+ else {
1489
+ name = name ? `${name}/${key}` : key;
1490
+ return new Proxy({ _name: name }, this);
1491
+ }
1492
+ }
1493
+ has(target, key) {
1494
+ return ['toJSON', 'clone', 'render'].includes(key) || key in target;
1476
1495
  }
1477
1496
  }
1478
1497
  function applyMixins(derivedCtor, constructors) {
@@ -1511,6 +1530,7 @@ class Function {
1511
1530
  }
1512
1531
  toJSON() {
1513
1532
  return {
1533
+ $type: Types.rawType(this),
1514
1534
  name: this.name,
1515
1535
  values: this.values,
1516
1536
  normalize: this.normalize,
@@ -1519,12 +1539,15 @@ class Function {
1519
1539
  render({ aliases, escape, prefix, }) {
1520
1540
  let [field, ...values] = this.values;
1521
1541
  field = render(field, { aliases, escape, prefix });
1522
- let params = [
1542
+ const params = [
1523
1543
  field,
1524
1544
  ...values.map((v) => render(v, { aliases, escape, prefix, normalize: this.normalize })),
1525
1545
  ];
1526
1546
  return `${this.name}(${params.join(', ')})`;
1527
1547
  }
1548
+ clone() {
1549
+ return new Function(this.name, this.values.map((v) => Objects.clone(v)), this.normalize, this.escape);
1550
+ }
1528
1551
  }
1529
1552
  class StringAndCollectionFunctions {
1530
1553
  concat(field, value, normalize) {
@@ -1665,6 +1688,7 @@ class Operator {
1665
1688
  }
1666
1689
  toJSON() {
1667
1690
  return {
1691
+ $type: Types.rawType(this),
1668
1692
  op: this.op,
1669
1693
  values: this.values,
1670
1694
  normalize: this.normalize,
@@ -1693,6 +1717,9 @@ class Operator {
1693
1717
  }
1694
1718
  return `${this.op}(${left})`;
1695
1719
  }
1720
+ clone() {
1721
+ return new Operator(this.op, this.values.map((v) => Objects.clone(v)), this.normalize);
1722
+ }
1696
1723
  }
1697
1724
  class LogicalOperators {
1698
1725
  eq(left, right, normalize) {
@@ -1760,12 +1787,16 @@ class Grouping {
1760
1787
  }
1761
1788
  toJSON() {
1762
1789
  return {
1790
+ $type: Types.rawType(this),
1763
1791
  group: this.group.toJSON(),
1764
1792
  };
1765
1793
  }
1766
1794
  render({ aliases, escape, prefix, }) {
1767
1795
  return `(${render(this.group, { aliases, escape, prefix })})`;
1768
1796
  }
1797
+ clone() {
1798
+ return new Grouping(Objects.clone(this.group));
1799
+ }
1769
1800
  }
1770
1801
  class Lambda {
1771
1802
  constructor(op, values, alias) {
@@ -1778,6 +1809,7 @@ class Lambda {
1778
1809
  }
1779
1810
  toJSON() {
1780
1811
  return {
1812
+ $type: Types.rawType(this),
1781
1813
  op: this.op,
1782
1814
  values: this.values,
1783
1815
  alias: this.alias,
@@ -1793,6 +1825,9 @@ class Lambda {
1793
1825
  prefix: alias,
1794
1826
  })})`;
1795
1827
  }
1828
+ clone() {
1829
+ return new Lambda(this.op, this.values.map((v) => Objects.clone(v)), this.alias);
1830
+ }
1796
1831
  }
1797
1832
  class LambdaOperators {
1798
1833
  any(field, value, alias) {
@@ -1839,16 +1874,23 @@ class ComputeExpression extends Expression {
1839
1874
  static s() {
1840
1875
  return Field$1.factory();
1841
1876
  }
1842
- static compute(opts) {
1877
+ static compute(opts, current) {
1843
1878
  return opts({
1844
1879
  s: ComputeExpression.s(),
1845
1880
  e: ComputeExpression.e,
1846
- });
1881
+ }, current);
1847
1882
  }
1848
1883
  render({ aliases, escape, prefix, } = {}) {
1849
- let children = this._children
1850
- .map((n) => n.render({ aliases, escape, prefix }));
1851
- return this.names.map((name, index) => `${children[index]} as ${name}`).join(',');
1884
+ let children = this._children.map((n) => n.render({ aliases, escape, prefix }));
1885
+ return this.names
1886
+ .map((name, index) => `${children[index]} as ${name}`)
1887
+ .join(',');
1888
+ }
1889
+ clone() {
1890
+ return new ComputeExpression({
1891
+ children: this._children.map((c) => c.clone()),
1892
+ names: [...this.names],
1893
+ });
1852
1894
  }
1853
1895
  _add(name, node) {
1854
1896
  this.names.push(name);
@@ -1876,13 +1918,13 @@ class FilterExpression extends Expression {
1876
1918
  static e(connector = 'and') {
1877
1919
  return new FilterExpression({ connector });
1878
1920
  }
1879
- static filter(opts) {
1921
+ static filter(opts, current) {
1880
1922
  return opts({
1881
1923
  s: FilterExpression.s(),
1882
1924
  e: FilterExpression.e,
1883
1925
  o: operators,
1884
1926
  f: functions,
1885
- });
1927
+ }, current);
1886
1928
  }
1887
1929
  toJSON() {
1888
1930
  return {
@@ -1906,6 +1948,13 @@ class FilterExpression extends Expression {
1906
1948
  }
1907
1949
  return content;
1908
1950
  }
1951
+ clone() {
1952
+ return new FilterExpression({
1953
+ children: this._children.map((c) => c.clone()),
1954
+ connector: this._connector,
1955
+ negated: this._negated,
1956
+ });
1957
+ }
1909
1958
  _add(node, connector) {
1910
1959
  if (connector !== undefined && this._connector !== connector) {
1911
1960
  let children = [];
@@ -2032,6 +2081,9 @@ class OrderByField {
2032
2081
  render({ aliases, escape, prefix, }) {
2033
2082
  return `${render(this.field, { aliases, escape, prefix })} ${this.order}`;
2034
2083
  }
2084
+ clone() {
2085
+ return new OrderByField(this.field.clone(), this.order);
2086
+ }
2035
2087
  }
2036
2088
  class OrderByExpression extends Expression {
2037
2089
  constructor({ children, } = {}) {
@@ -2043,11 +2095,11 @@ class OrderByExpression extends Expression {
2043
2095
  static s() {
2044
2096
  return Field$1.factory();
2045
2097
  }
2046
- static orderBy(opts) {
2098
+ static orderBy(opts, current) {
2047
2099
  return opts({
2048
2100
  s: OrderByExpression.s(),
2049
2101
  e: OrderByExpression.e,
2050
- });
2102
+ }, current);
2051
2103
  }
2052
2104
  _add(node) {
2053
2105
  this._children.push(node);
@@ -2059,6 +2111,11 @@ class OrderByExpression extends Expression {
2059
2111
  .join(`,`);
2060
2112
  return content;
2061
2113
  }
2114
+ clone() {
2115
+ return new OrderByExpression({
2116
+ children: this._children.map((c) => c.clone()),
2117
+ });
2118
+ }
2062
2119
  ascending(field) {
2063
2120
  return this._add(new OrderByField(field, 'asc'));
2064
2121
  }
@@ -2076,12 +2133,16 @@ class SearchTerm {
2076
2133
  }
2077
2134
  toJSON() {
2078
2135
  return {
2136
+ $type: Types.rawType(this),
2079
2137
  value: this.value,
2080
2138
  };
2081
2139
  }
2082
2140
  render({ aliases, escape, prefix, }) {
2083
2141
  return `${render(this.value, { aliases, escape, prefix })}`;
2084
2142
  }
2143
+ clone() {
2144
+ return new SearchTerm(this.value);
2145
+ }
2085
2146
  }
2086
2147
  class SearchExpression extends Expression {
2087
2148
  constructor({ children, connector, negated, } = {}) {
@@ -2092,10 +2153,10 @@ class SearchExpression extends Expression {
2092
2153
  static e(connector = 'AND') {
2093
2154
  return new SearchExpression({ connector });
2094
2155
  }
2095
- static search(opts) {
2156
+ static search(opts, current) {
2096
2157
  return opts({
2097
2158
  e: SearchExpression.e,
2098
- });
2159
+ }, current);
2099
2160
  }
2100
2161
  _add(node, connector) {
2101
2162
  if (connector !== undefined && this._connector !== connector) {
@@ -2146,6 +2207,13 @@ class SearchExpression extends Expression {
2146
2207
  .join(` ${this._connector} `);
2147
2208
  return content;
2148
2209
  }
2210
+ clone() {
2211
+ return new SearchExpression({
2212
+ children: this._children.map((c) => c.clone()),
2213
+ connector: this._connector,
2214
+ negated: this._negated,
2215
+ });
2216
+ }
2149
2217
  toJSON() {
2150
2218
  return {
2151
2219
  children: this._children.map((c) => c.toJSON()),
@@ -2178,9 +2246,45 @@ class SearchExpression extends Expression {
2178
2246
  }
2179
2247
  }
2180
2248
 
2249
+ class SelectExpression extends Expression {
2250
+ constructor({ children, } = {}) {
2251
+ super({ children });
2252
+ }
2253
+ static e() {
2254
+ return new SelectExpression();
2255
+ }
2256
+ static s() {
2257
+ return Field$1.factory();
2258
+ }
2259
+ static select(builder, current) {
2260
+ return builder({
2261
+ s: SelectExpression.s(),
2262
+ e: SelectExpression.e,
2263
+ }, current);
2264
+ }
2265
+ render({ aliases, escape, prefix, } = {}) {
2266
+ return this._children
2267
+ .map((n) => n.render({ aliases, escape, prefix }))
2268
+ .join(',');
2269
+ }
2270
+ clone() {
2271
+ return new SelectExpression({
2272
+ children: this._children.map((c) => c.clone()),
2273
+ });
2274
+ }
2275
+ _add(node) {
2276
+ this._children.push(node);
2277
+ return this;
2278
+ }
2279
+ field(field) {
2280
+ return this._add(field);
2281
+ }
2282
+ }
2283
+
2181
2284
  class ExpandField {
2182
- constructor(field) {
2285
+ constructor(field, values = {}) {
2183
2286
  this.field = field;
2287
+ this.values = values;
2184
2288
  }
2185
2289
  get [Symbol.toStringTag]() {
2186
2290
  return 'ExpandField';
@@ -2191,14 +2295,66 @@ class ExpandField {
2191
2295
  };
2192
2296
  }
2193
2297
  render({ aliases, escape, prefix, }) {
2194
- return `${render(this.field, { aliases, escape, prefix })}`;
2298
+ const params = [
2299
+ QueryOptionNames.select,
2300
+ QueryOptionNames.expand,
2301
+ QueryOptionNames.filter,
2302
+ QueryOptionNames.search,
2303
+ QueryOptionNames.orderBy,
2304
+ QueryOptionNames.skip,
2305
+ QueryOptionNames.top,
2306
+ QueryOptionNames.levels,
2307
+ ]
2308
+ .filter((key) => !Types.isEmpty(this.values[key]))
2309
+ .reduce((acc, key) => {
2310
+ let value = this.values[key];
2311
+ if (Types.rawType(value).endsWith('Expression')) {
2312
+ value = value.render({ aliases, prefix, escape });
2313
+ }
2314
+ return Object.assign(acc, { [key]: value });
2315
+ }, {});
2316
+ let expand = `${render(this.field, { aliases, escape, prefix })}`;
2317
+ if (!Types.isEmpty(params)) {
2318
+ expand = `${expand}(${Object.keys(params)
2319
+ .map((key) => `$${key}=${params[key]}`)
2320
+ .join(';')})`;
2321
+ }
2322
+ return expand;
2323
+ }
2324
+ clone() {
2325
+ const values = Object.keys(this.values).reduce((acc, key) => Object.assign(acc, { [key]: Objects.clone(this.values[key]) }), {});
2326
+ return new ExpandField(this.field.clone(), values);
2327
+ }
2328
+ select(opts) {
2329
+ return this.option(QueryOptionNames.select, SelectExpression.select(opts, this.values[QueryOptionNames.select]));
2330
+ }
2331
+ expand(opts) {
2332
+ return this.option(QueryOptionNames.expand, ExpandExpression.expand(opts, this.values[QueryOptionNames.expand]));
2333
+ }
2334
+ filter(opts) {
2335
+ return this.option(QueryOptionNames.filter, FilterExpression.filter(opts, this.values[QueryOptionNames.filter]));
2336
+ }
2337
+ search(opts) {
2338
+ return this.option(QueryOptionNames.search, SearchExpression.search(opts, this.values[QueryOptionNames.search]));
2339
+ }
2340
+ orderBy(opts) {
2341
+ return this.option(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts, this.values[QueryOptionNames.orderBy]));
2342
+ }
2343
+ skip(n) {
2344
+ return this.option(QueryOptionNames.skip, n);
2345
+ }
2346
+ top(n) {
2347
+ return this.option(QueryOptionNames.top, n);
2348
+ }
2349
+ levels(n) {
2350
+ return this.option(QueryOptionNames.levels, n);
2351
+ }
2352
+ // Option Handler
2353
+ option(name, opts) {
2354
+ if (opts !== undefined)
2355
+ this.values[name] = opts;
2356
+ return this.values[name];
2195
2357
  }
2196
- select() { }
2197
- filter() { }
2198
- levels() { }
2199
- orderBy() { }
2200
- top() { }
2201
- skip() { }
2202
2358
  }
2203
2359
  class ExpandExpression extends Expression {
2204
2360
  constructor({ children, } = {}) {
@@ -2210,17 +2366,22 @@ class ExpandExpression extends Expression {
2210
2366
  static s() {
2211
2367
  return Field$1.factory();
2212
2368
  }
2213
- static expand(opts) {
2369
+ static expand(opts, current) {
2214
2370
  return opts({
2215
2371
  s: ExpandExpression.s(),
2216
2372
  e: ExpandExpression.e,
2217
- });
2373
+ }, current);
2218
2374
  }
2219
2375
  render({ aliases, escape, prefix, } = {}) {
2220
2376
  return this._children
2221
2377
  .map((n) => n.render({ aliases, escape, prefix }))
2222
2378
  .join(',');
2223
2379
  }
2380
+ clone() {
2381
+ return new ExpandExpression({
2382
+ children: this._children.map((c) => c.clone()),
2383
+ });
2384
+ }
2224
2385
  _add(node) {
2225
2386
  this._children.push(node);
2226
2387
  return this;
@@ -2233,36 +2394,6 @@ class ExpandExpression extends Expression {
2233
2394
  }
2234
2395
  }
2235
2396
 
2236
- class SelectExpression extends Expression {
2237
- constructor({ children, } = {}) {
2238
- super({ children });
2239
- }
2240
- static e() {
2241
- return new SelectExpression();
2242
- }
2243
- static s() {
2244
- return Field$1.factory();
2245
- }
2246
- static select(opts) {
2247
- return opts({
2248
- s: SelectExpression.s(),
2249
- e: SelectExpression.e,
2250
- });
2251
- }
2252
- render({ aliases, escape, prefix, } = {}) {
2253
- return this._children
2254
- .map((n) => n.render({ aliases, escape, prefix }))
2255
- .join(',');
2256
- }
2257
- _add(node) {
2258
- this._children.push(node);
2259
- return this;
2260
- }
2261
- field(field) {
2262
- return this._add(field);
2263
- }
2264
- }
2265
-
2266
2397
  class ODataQueryOptionHandler {
2267
2398
  constructor(o, n) {
2268
2399
  this.o = o;
@@ -2272,30 +2403,32 @@ class ODataQueryOptionHandler {
2272
2403
  return this.n;
2273
2404
  }
2274
2405
  toJSON() {
2275
- return this.o[this.n];
2406
+ return this.o.get(this.n);
2276
2407
  }
2277
2408
  empty() {
2278
- return Types.isEmpty(this.o[this.n]);
2409
+ return Types.isEmpty(this.o.get(this.n));
2279
2410
  }
2280
2411
  //#region Primitive Value
2281
2412
  value(v) {
2282
- return (v !== undefined && (this.o[this.n] = v)) || this.o[this.n];
2413
+ if (v !== undefined)
2414
+ this.o.set(this.n, v);
2415
+ return this.o.get(this.n);
2283
2416
  }
2284
2417
  //#endregion
2285
2418
  //#region Array Value
2286
2419
  assertArray() {
2287
- if (!Types.isArray(this.o[this.n]))
2288
- this.o[this.n] = this.o[this.n] !== undefined ? [this.o[this.n]] : [];
2289
- return this.o[this.n];
2420
+ if (!Types.isArray(this.o.get(this.n)))
2421
+ this.o.set(this.n, this.o.has(this.n) ? [this.o.get(this.n)] : []);
2422
+ return this.o.get(this.n);
2290
2423
  }
2291
2424
  push(value) {
2292
2425
  this.assertArray().push(value);
2293
2426
  }
2294
2427
  remove(value) {
2295
- this.o[this.n] = this.assertArray().filter((v) => v !== value);
2428
+ this.o.set(this.n, this.assertArray().filter((v) => v !== value));
2296
2429
  // If only one... down to value
2297
- if (this.o[this.n].length === 1)
2298
- this.o[this.n] = this.o[this.n][0];
2430
+ if (this.o.get(this.n).length === 1)
2431
+ this.o.set(this.n, this.o.get(this.n)[0]);
2299
2432
  }
2300
2433
  at(index) {
2301
2434
  return this.assertArray()[index];
@@ -2303,8 +2436,9 @@ class ODataQueryOptionHandler {
2303
2436
  //#endregion
2304
2437
  //#region HashMap Value
2305
2438
  assertObject(create) {
2306
- if (!Types.isArray(this.o[this.n]) && Types.isPlainObject(this.o[this.n])) {
2307
- return this.o[this.n];
2439
+ if (!Types.isArray(this.o.get(this.n)) &&
2440
+ Types.isPlainObject(this.o.get(this.n))) {
2441
+ return this.o.get(this.n);
2308
2442
  }
2309
2443
  let arr = this.assertArray();
2310
2444
  let obj = arr.find((v) => Types.isPlainObject(v));
@@ -2325,10 +2459,10 @@ class ODataQueryOptionHandler {
2325
2459
  unset(path) {
2326
2460
  let obj = this.assertObject(true);
2327
2461
  Objects.unset(obj, path);
2328
- if (Types.isArray(this.o[this.n])) {
2329
- this.o[this.n] = this.o[this.n].filter((v) => !Types.isEmpty(v));
2330
- if (this.o[this.n].length === 1)
2331
- this.o[this.n] = this.o[this.n][0];
2462
+ if (Types.isArray(this.o.get(this.n))) {
2463
+ this.o.set(this.n, this.o.get(this.n).filter((v) => !Types.isEmpty(v)));
2464
+ if (this.o.get(this.n).length === 1)
2465
+ this.o.set(this.n, this.o.get(this.n)[0]);
2332
2466
  }
2333
2467
  }
2334
2468
  has(path) {
@@ -2341,7 +2475,7 @@ class ODataQueryOptionHandler {
2341
2475
  }
2342
2476
  //#endregion
2343
2477
  clear() {
2344
- delete this.o[this.n];
2478
+ this.o.delete(this.n);
2345
2479
  }
2346
2480
  }
2347
2481
  class ODataQueryOptionsHandler {
@@ -2358,21 +2492,29 @@ class ODataQueryOptionsHandler {
2358
2492
  alias(value, name) {
2359
2493
  return alias(value, name);
2360
2494
  }
2495
+ /**
2496
+ * Normalize the given value to a valid odata value
2497
+ * @param value The value to normalize
2498
+ * @returns The normalized value
2499
+ */
2500
+ normalize(value) {
2501
+ return normalizeValue(value);
2502
+ }
2361
2503
  select(opts) {
2362
2504
  if (Types.isFunction(opts)) {
2363
- return this.options.expression(QueryOptionNames.select, SelectExpression.select(opts));
2505
+ return this.options.expression(QueryOptionNames.select, SelectExpression.select(opts, this.options.expression(QueryOptionNames.select)));
2364
2506
  }
2365
2507
  return this.options.option(QueryOptionNames.select, opts);
2366
2508
  }
2367
2509
  expand(opts) {
2368
2510
  if (Types.isFunction(opts)) {
2369
- return this.options.expression(QueryOptionNames.expand, ExpandExpression.expand(opts));
2511
+ return this.options.expression(QueryOptionNames.expand, ExpandExpression.expand(opts, this.options.expression(QueryOptionNames.expand)));
2370
2512
  }
2371
2513
  return this.options.option(QueryOptionNames.expand, opts);
2372
2514
  }
2373
2515
  compute(opts) {
2374
2516
  if (Types.isFunction(opts)) {
2375
- return this.options.expression(QueryOptionNames.compute, ComputeExpression.compute(opts));
2517
+ return this.options.expression(QueryOptionNames.compute, ComputeExpression.compute(opts, this.options.expression(QueryOptionNames.compute)));
2376
2518
  }
2377
2519
  return this.options.option(QueryOptionNames.compute, opts);
2378
2520
  }
@@ -2384,19 +2526,19 @@ class ODataQueryOptionsHandler {
2384
2526
  }
2385
2527
  search(opts) {
2386
2528
  if (Types.isFunction(opts)) {
2387
- return this.options.expression(QueryOptionNames.search, SearchExpression.search(opts));
2529
+ return this.options.expression(QueryOptionNames.search, SearchExpression.search(opts, this.options.expression(QueryOptionNames.search)));
2388
2530
  }
2389
2531
  return this.options.option(QueryOptionNames.search, opts);
2390
2532
  }
2391
2533
  filter(opts) {
2392
2534
  if (Types.isFunction(opts)) {
2393
- return this.options.expression(QueryOptionNames.filter, FilterExpression.filter(opts));
2535
+ return this.options.expression(QueryOptionNames.filter, FilterExpression.filter(opts, this.options.expression(QueryOptionNames.filter)));
2394
2536
  }
2395
2537
  return this.options.option(QueryOptionNames.filter, opts);
2396
2538
  }
2397
2539
  orderBy(opts) {
2398
2540
  if (Types.isFunction(opts)) {
2399
- return this.options.expression(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts));
2541
+ return this.options.option(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts, this.options.expression(QueryOptionNames.orderBy)));
2400
2542
  }
2401
2543
  return this.options.option(QueryOptionNames.orderBy, opts);
2402
2544
  }
@@ -2424,30 +2566,33 @@ class ODataQueryOptionsHandler {
2424
2566
  }
2425
2567
  apply(query) {
2426
2568
  if (query.select !== undefined) {
2427
- this.select(query.select);
2569
+ this.options.option(QueryOptionNames.select, query.select);
2428
2570
  }
2429
2571
  if (query.expand !== undefined) {
2430
- this.expand(query.expand);
2572
+ this.options.option(QueryOptionNames.expand, query.expand);
2431
2573
  }
2432
2574
  if (query.transform !== undefined) {
2433
- this.transform(query.transform);
2575
+ this.options.option(QueryOptionNames.transform, query.transform);
2434
2576
  }
2435
2577
  if (query.search !== undefined) {
2436
- this.search(query.search);
2578
+ this.options.option(QueryOptionNames.search, query.search);
2437
2579
  }
2438
2580
  if (query.filter !== undefined) {
2439
- this.filter(query.filter);
2581
+ this.options.option(QueryOptionNames.filter, query.filter);
2440
2582
  }
2441
2583
  if (query.orderBy !== undefined) {
2442
- this.orderBy(query.orderBy);
2584
+ this.options.option(QueryOptionNames.orderBy, query.orderBy);
2443
2585
  }
2444
2586
  this.paging(query);
2445
2587
  }
2446
2588
  }
2447
2589
 
2448
2590
  class ODataQueryOptions {
2449
- constructor(options) {
2450
- this.options = options || {};
2591
+ constructor(values) {
2592
+ this.values =
2593
+ values instanceof Map
2594
+ ? values
2595
+ : new Map(Object.entries(values || {}));
2451
2596
  }
2452
2597
  // Params
2453
2598
  pathAndParams(escape = false) {
@@ -2465,11 +2610,11 @@ class ODataQueryOptions {
2465
2610
  QueryOptionNames.expand,
2466
2611
  QueryOptionNames.format,
2467
2612
  ]
2468
- .filter((key) => !Types.isEmpty(this.options[key]))
2613
+ .filter((key) => !Types.isEmpty(this.values.get(key)))
2469
2614
  .reduce((acc, key) => {
2470
- let value = this.options[key];
2471
- if (Types.rawType(value) === 'Expression') {
2472
- value = value.render(aliases);
2615
+ let value = this.values.get(key);
2616
+ if (Types.rawType(value).endsWith('Expression')) {
2617
+ value = value.render({ aliases });
2473
2618
  }
2474
2619
  return Object.assign(acc, { [key]: value });
2475
2620
  }, {});
@@ -2484,63 +2629,63 @@ class ODataQueryOptions {
2484
2629
  .join('&'));
2485
2630
  }
2486
2631
  toJSON() {
2487
- return Object.keys(this.options).reduce((acc, key) => {
2488
- let value = this.options[key];
2489
- if (Types.rawType(value) === 'Expression') {
2490
- value = value.toJSON();
2491
- }
2632
+ return [...this.values.keys()].reduce((acc, key) => {
2633
+ let value = this.values.get(key);
2634
+ value =
2635
+ Types.isObject(value) && 'toJSON' in value ? value.toJSON() : value;
2492
2636
  return Object.assign(acc, { [key]: value });
2493
2637
  }, {});
2494
2638
  }
2495
2639
  toQueryArguments() {
2496
2640
  return {
2497
- select: this.options[QueryOptionNames.select],
2498
- expand: this.options[QueryOptionNames.expand],
2499
- transform: this.options[QueryOptionNames.transform],
2500
- compute: this.options[QueryOptionNames.compute],
2501
- search: this.options[QueryOptionNames.search],
2502
- filter: this.options[QueryOptionNames.filter],
2503
- orderBy: this.options[QueryOptionNames.orderBy],
2504
- top: this.options[QueryOptionNames.top],
2505
- skip: this.options[QueryOptionNames.skip],
2506
- skiptoken: this.options[QueryOptionNames.skiptoken],
2641
+ select: this.values.get(QueryOptionNames.select),
2642
+ expand: this.values.get(QueryOptionNames.expand),
2643
+ transform: this.values.get(QueryOptionNames.transform),
2644
+ compute: this.values.get(QueryOptionNames.compute),
2645
+ search: this.values.get(QueryOptionNames.search),
2646
+ filter: this.values.get(QueryOptionNames.filter),
2647
+ orderBy: this.values.get(QueryOptionNames.orderBy),
2648
+ top: this.values.get(QueryOptionNames.top),
2649
+ skip: this.values.get(QueryOptionNames.skip),
2650
+ skiptoken: this.values.get(QueryOptionNames.skiptoken),
2507
2651
  };
2508
2652
  }
2509
2653
  clone() {
2510
- const options = Object.keys(this.options).reduce((acc, key) => {
2511
- let value = this.options[key];
2512
- if (Types.rawType(value) !== 'Expression') {
2513
- value = Objects.clone(value);
2514
- }
2515
- return Object.assign(acc, { [key]: value });
2516
- }, {});
2517
- return new ODataQueryOptions(options);
2654
+ return new ODataQueryOptions(Objects.clone(this.values));
2518
2655
  }
2519
2656
  // Set Renderable
2520
- expression(name, exp) {
2521
- return (this.options[name] = exp);
2657
+ expression(key, exp) {
2658
+ if (exp !== undefined)
2659
+ this.values.set(key, exp);
2660
+ return this.values.get(key);
2522
2661
  }
2523
2662
  // Option Handler
2524
- option(name, opts) {
2663
+ option(key, opts) {
2525
2664
  if (opts !== undefined)
2526
- this.options[name] = opts;
2527
- return new ODataQueryOptionHandler(this.options, name);
2665
+ this.values.set(key, opts);
2666
+ return new ODataQueryOptionHandler(this.values, key);
2528
2667
  }
2529
2668
  // Query Options tools
2530
- has(name) {
2531
- return this.options[name] !== undefined;
2532
- }
2533
- remove(...names) {
2534
- names.forEach((name) => this.option(name).clear());
2669
+ has(key) {
2670
+ return this.values.has(key);
2671
+ }
2672
+ remove(...keys) {
2673
+ [...this.values.keys()]
2674
+ .filter((k) => keys.indexOf(k) !== -1)
2675
+ .forEach((key) => {
2676
+ this.values.delete(key);
2677
+ });
2535
2678
  }
2536
- keep(...names) {
2537
- this.options = Object.keys(this.options)
2538
- .filter((k) => names.indexOf(k) !== -1)
2539
- .reduce((acc, k) => Object.assign(acc, { [k]: this.options[k] }), {});
2679
+ keep(...keys) {
2680
+ [...this.values.keys()]
2681
+ .filter((k) => keys.indexOf(k) === -1)
2682
+ .forEach((key) => {
2683
+ this.values.delete(key);
2684
+ });
2540
2685
  }
2541
2686
  // Clear
2542
2687
  clear() {
2543
- this.options = {};
2688
+ this.values.clear();
2544
2689
  }
2545
2690
  }
2546
2691
 
@@ -3143,70 +3288,69 @@ const ODataVersionBaseHelper = {
3143
3288
  property(data) {
3144
3289
  return this.VALUE in data ? data[this.VALUE] : data;
3145
3290
  },
3146
- functions(value) {
3147
- return Object.keys(value)
3148
- .filter((k) => k.startsWith(this.ODATA_FUNCTION_PREFIX))
3149
- .reduce((acc, key) => Object.assign(acc, { [key.substr(1)]: value[key] }), {});
3291
+ functions(annots) {
3292
+ const funcs = new Map();
3293
+ [...annots.keys()]
3294
+ .filter((key) => key.startsWith(this.ODATA_FUNCTION_PREFIX))
3295
+ .forEach((key) => funcs.set(key.substring(this.ODATA_FUNCTION_PREFIX.length), annots.get(key)));
3296
+ return funcs;
3150
3297
  },
3151
- properties(value) {
3152
- return Object.keys(value)
3153
- .filter((k) => k.indexOf(this.ODATA_ANNOTATION_PREFIX) > 0)
3154
- .reduce((acc, key) => {
3155
- let name = key.substr(0, key.indexOf(this.ODATA_ANNOTATION_PREFIX));
3156
- if (!(name in acc)) {
3157
- acc[name] = {};
3158
- }
3159
- Object.assign(acc[name], {
3160
- [key.substr(key.indexOf(this.ODATA_ANNOTATION_PREFIX))]: value[key],
3161
- });
3162
- return acc;
3163
- }, {});
3298
+ properties(annots) {
3299
+ const props = new Map();
3300
+ [...annots.keys()]
3301
+ .filter((key) => key.indexOf(this.ODATA_ANNOTATION_PREFIX) > 0)
3302
+ .forEach((key) => {
3303
+ let name = key.substring(0, key.indexOf(this.ODATA_ANNOTATION_PREFIX));
3304
+ let prop = props.has(name) ? props.get(name) : new Map();
3305
+ prop.set(key.substring(key.indexOf(this.ODATA_ANNOTATION_PREFIX)), annots.get(key));
3306
+ props.set(name, prop);
3307
+ });
3308
+ return props;
3164
3309
  },
3165
- id(value, id) {
3166
- if (id !== undefined)
3167
- value[this.ODATA_ID] = id;
3168
- return this.ODATA_ID in value
3169
- ? value[this.ODATA_ID]
3170
- : undefined;
3310
+ id(annots) {
3311
+ return annots instanceof Map
3312
+ ? annots.get(this.ODATA_ID)
3313
+ : annots[this.ODATA_ID];
3171
3314
  },
3172
- etag(value, etag) {
3173
- if (etag !== undefined)
3174
- value[this.ODATA_ETAG] = etag;
3175
- return this.ODATA_ETAG in value
3176
- ? value[this.ODATA_ETAG]
3177
- : undefined;
3315
+ etag(annots) {
3316
+ return annots instanceof Map
3317
+ ? annots.get(this.ODATA_ETAG)
3318
+ : annots[this.ODATA_ETAG];
3178
3319
  },
3179
- type(value, type) {
3180
- if (type !== undefined)
3181
- value[this.ODATA_TYPE] = `#${type}`;
3182
- if (!(this.ODATA_TYPE in value))
3320
+ type(annots) {
3321
+ let type = annots instanceof Map
3322
+ ? annots.get(this.ODATA_TYPE)
3323
+ : annots[this.ODATA_TYPE];
3324
+ if (!type)
3183
3325
  return undefined;
3184
- const t = value[this.ODATA_TYPE].substr(1);
3185
- const matches = COLLECTION.exec(t);
3326
+ type = type.substring(1);
3327
+ const matches = COLLECTION.exec(type);
3186
3328
  if (matches)
3187
3329
  return matches[1].indexOf('.') === -1 ? `Edm.${matches[1]}` : matches[1];
3188
- return t;
3330
+ return type;
3189
3331
  },
3190
- mediaEtag(value) {
3191
- return this.ODATA_MEDIA_ETAG in value
3192
- ? decodeURIComponent(value[this.ODATA_MEDIA_ETAG])
3332
+ mediaEtag(annots) {
3333
+ return annots.has(this.ODATA_MEDIA_ETAG)
3334
+ ? decodeURIComponent(annots.get(this.ODATA_MEDIA_ETAG))
3193
3335
  : undefined;
3194
3336
  },
3195
- metadataEtag(value) {
3196
- return this.ODATA_METADATA_ETAG in value
3197
- ? decodeURIComponent(value[this.ODATA_METADATA_ETAG])
3337
+ metadataEtag(annots) {
3338
+ return annots.has(this.ODATA_METADATA_ETAG)
3339
+ ? decodeURIComponent(annots.get(this.ODATA_METADATA_ETAG))
3198
3340
  : undefined;
3199
3341
  },
3200
- count(value) {
3201
- return this.ODATA_COUNT in value
3202
- ? Number(value[this.ODATA_COUNT])
3342
+ count(annots) {
3343
+ return annots.has(this.ODATA_COUNT)
3344
+ ? Number(annots.get(this.ODATA_COUNT))
3203
3345
  : undefined;
3204
3346
  },
3205
3347
  annotations(value) {
3206
- return Object.keys(value)
3207
- .filter((key) => key.indexOf(this.ODATA_ANNOTATION_PREFIX) !== -1 ||
3348
+ const annots = new Map();
3349
+ Object.entries(value)
3350
+ .filter(([key]) => key.indexOf(this.ODATA_ANNOTATION_PREFIX) !== -1 ||
3208
3351
  key.startsWith(this.ODATA_FUNCTION_PREFIX))
3209
- .reduce((acc, key) => Object.assign(acc, { [key]: value[key] }), {});
3352
+ .forEach(([key, value]) => annots.set(key, value));
3353
+ return annots;
3210
3354
  },
3211
3355
  attributes(value, metadata) {
3212
3356
  return Object.entries(value)
@@ -3220,39 +3364,39 @@ const ODataVersionBaseHelper = {
3220
3364
  !k.startsWith(this.ODATA_FUNCTION_PREFIX)))
3221
3365
  .reduce((acc, e) => (Object.assign(Object.assign({}, acc), { [e[0]]: e[1] })), {});
3222
3366
  },
3223
- nextLink(value) {
3224
- return this.ODATA_NEXTLINK in value
3225
- ? decodeURIComponent(value[this.ODATA_NEXTLINK])
3367
+ nextLink(annots) {
3368
+ return annots.has(this.ODATA_NEXTLINK)
3369
+ ? decodeURIComponent(annots.get(this.ODATA_NEXTLINK))
3226
3370
  : undefined;
3227
3371
  },
3228
- readLink(value) {
3229
- return this.ODATA_READLINK in value
3230
- ? decodeURIComponent(value[this.ODATA_READLINK])
3372
+ readLink(annots) {
3373
+ return annots.has(this.ODATA_READLINK)
3374
+ ? decodeURIComponent(annots.get(this.ODATA_READLINK))
3231
3375
  : undefined;
3232
3376
  },
3233
- mediaReadLink(value) {
3234
- return this.ODATA_MEDIA_READLINK in value
3235
- ? decodeURIComponent(value[this.ODATA_MEDIA_READLINK])
3377
+ mediaReadLink(annots) {
3378
+ return annots.has(this.ODATA_MEDIA_READLINK)
3379
+ ? decodeURIComponent(annots.get(this.ODATA_MEDIA_READLINK))
3236
3380
  : undefined;
3237
3381
  },
3238
- editLink(value) {
3239
- return this.ODATA_EDITLINK in value
3240
- ? decodeURIComponent(value[this.ODATA_EDITLINK])
3382
+ editLink(annots) {
3383
+ return annots.has(this.ODATA_EDITLINK)
3384
+ ? decodeURIComponent(annots.get(this.ODATA_EDITLINK))
3241
3385
  : undefined;
3242
3386
  },
3243
- mediaEditLink(value) {
3244
- return this.ODATA_MEDIA_EDITLINK in value
3245
- ? decodeURIComponent(value[this.ODATA_MEDIA_EDITLINK])
3387
+ mediaEditLink(annots) {
3388
+ return annots.has(this.ODATA_MEDIA_EDITLINK)
3389
+ ? decodeURIComponent(annots.get(this.ODATA_MEDIA_EDITLINK))
3246
3390
  : undefined;
3247
3391
  },
3248
- deltaLink(value) {
3249
- return this.ODATA_DELTALINK in value
3250
- ? decodeURIComponent(value[this.ODATA_DELTALINK])
3392
+ deltaLink(annots) {
3393
+ return annots.has(this.ODATA_DELTALINK)
3394
+ ? decodeURIComponent(annots.get(this.ODATA_DELTALINK))
3251
3395
  : undefined;
3252
3396
  },
3253
- mediaContentType(value) {
3254
- return this.ODATA_MEDIA_CONTENTTYPE in value
3255
- ? decodeURIComponent(value[this.ODATA_MEDIA_CONTENTTYPE])
3397
+ mediaContentType(annots) {
3398
+ return annots.has(this.ODATA_MEDIA_CONTENTTYPE)
3399
+ ? decodeURIComponent(annots.get(this.ODATA_MEDIA_CONTENTTYPE))
3256
3400
  : undefined;
3257
3401
  },
3258
3402
  };
@@ -3271,7 +3415,7 @@ const ODataHelper = {
3271
3415
  //odata.etag: the ETag of the entity
3272
3416
  ODATA_ETAG: '@odata.etag',
3273
3417
  ODATA_METADATA_ETAG: '@odata.metadataEtag',
3274
- //odata.type: the type of the containing {[name: string]: any} or targeted property if the type of the {[name: string]: any} or targeted property cannot be heuristically determined
3418
+ //odata.type: the type of the containing {[key: string]: any} or targeted property if the type of the {[key: string]: any} or targeted property cannot be heuristically determined
3275
3419
  ODATA_TYPE: '@odata.type',
3276
3420
  //odata.nextLink: the next link of a collection with partial results
3277
3421
  ODATA_NEXTLINK: '@odata.nextLink',
@@ -3302,15 +3446,17 @@ const ODataHelper = {
3302
3446
  //http://nb-mdp-dev01:57970/$metadata#categorias(children(children(children(children(children(children(children(children(children(children()))))))))))/$entity
3303
3447
  //http://nb-mdp-dev01:57970/$metadata#recursos/SIU.Documentos.Documento/$entity
3304
3448
  //http://nb-mdp-dev01:57970/$metadata#SIU.Api.Infrastructure.Storage.Backend.SiuUrls
3305
- context(value) {
3449
+ context(annots) {
3306
3450
  let ctx = {};
3307
- if (this.ODATA_CONTEXT in value) {
3308
- const str = value[this.ODATA_CONTEXT];
3451
+ const str = annots instanceof Map
3452
+ ? annots.get(this.ODATA_CONTEXT)
3453
+ : annots[this.ODATA_CONTEXT];
3454
+ if (typeof str === 'string') {
3309
3455
  let index = str.indexOf('$metadata');
3310
- ctx.serviceRootUrl = str.substr(0, index);
3456
+ ctx.serviceRootUrl = str.substring(0, index);
3311
3457
  index = str.indexOf('#');
3312
- ctx.metadataUrl = str.substr(0, index);
3313
- const parts = str.substr(index + 1).split('/');
3458
+ ctx.metadataUrl = str.substring(0, index);
3459
+ const parts = str.substring(index + 1).split('/');
3314
3460
  const col = COLLECTION.exec(parts[0]);
3315
3461
  if (col) {
3316
3462
  ctx.type = col[1];
@@ -3354,15 +3500,17 @@ const ODataHelper = {
3354
3500
  ODATA_TYPE: 'odata.type',
3355
3501
  ODATA_COUNT: 'odata.count',
3356
3502
  VALUE: 'value',
3357
- context(value) {
3503
+ context(annots) {
3358
3504
  let ctx = {};
3359
- if (this.ODATA_CONTEXT in value) {
3360
- const str = value[this.ODATA_CONTEXT];
3505
+ const str = annots instanceof Map
3506
+ ? annots.get(this.ODATA_CONTEXT)
3507
+ : annots[this.ODATA_CONTEXT];
3508
+ if (typeof str === 'string') {
3361
3509
  let index = str.indexOf('$metadata');
3362
- ctx.serviceRootUrl = str.substr(0, index);
3510
+ ctx.serviceRootUrl = str.substring(0, index);
3363
3511
  index = str.indexOf('#');
3364
- ctx.metadataUrl = str.substr(0, index);
3365
- const parts = str.substr(index + 1).split('/');
3512
+ ctx.metadataUrl = str.substring(0, index);
3513
+ const parts = str.substring(index + 1).split('/');
3366
3514
  ctx.entitySet = parts[0];
3367
3515
  }
3368
3516
  return ctx;
@@ -3383,9 +3531,11 @@ const ODataHelper = {
3383
3531
  ODATA_TYPE: 'type',
3384
3532
  VALUE: 'results',
3385
3533
  annotations(value) {
3386
- if (this.ODATA_ANNOTATION in value)
3387
- return value[this.ODATA_ANNOTATION];
3388
- return value;
3534
+ const annots = new Map();
3535
+ if (this.ODATA_ANNOTATION in value) {
3536
+ Object.entries(value[this.ODATA_ANNOTATION]).forEach(([key, value]) => annots.set(key, value));
3537
+ }
3538
+ return annots;
3389
3539
  },
3390
3540
  attributes(value, metadata) {
3391
3541
  return value;
@@ -3401,7 +3551,7 @@ class ODataApiOptions {
3401
3551
  constructor(config) {
3402
3552
  this.etag = { ifMatch: true, ifNoneMatch: false };
3403
3553
  this.version = config.version || DEFAULT_VERSION;
3404
- this.stringAsEnum = config.stringAsEnum;
3554
+ this.stringAsEnum = config.stringAsEnum || false;
3405
3555
  this.params = config.params || {};
3406
3556
  this.headers = config.headers || {};
3407
3557
  this.withCredentials = config.withCredentials;
@@ -3412,6 +3562,8 @@ class ODataApiOptions {
3412
3562
  Object.assign(this.etag, config.etag || {});
3413
3563
  this.prefer = config.prefer;
3414
3564
  this.deleteRefBy = config.deleteRefBy || 'path';
3565
+ this.nonParenthesisForEmptyParameterFunction =
3566
+ config.nonParenthesisForEmptyParameterFunction || false;
3415
3567
  }
3416
3568
  get helper() {
3417
3569
  return ODataHelper[this.version];
@@ -3420,7 +3572,6 @@ class ODataApiOptions {
3420
3572
  class ODataParserOptions {
3421
3573
  constructor(config) {
3422
3574
  this.version = config.version || DEFAULT_VERSION;
3423
- this.stringAsEnum = config.stringAsEnum;
3424
3575
  }
3425
3576
  get helper() {
3426
3577
  return ODataHelper[this.version];
@@ -3456,7 +3607,8 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3456
3607
  ttitelize(term) {
3457
3608
  return (term && this.annotatedValue(term)) || Strings.titleCase(this.name);
3458
3609
  }
3459
- configure({ options }) {
3610
+ configure({ stringAsEnum, options }) {
3611
+ this.stringAsEnum = stringAsEnum;
3460
3612
  this.optionsHelper = options;
3461
3613
  }
3462
3614
  isTypeOf(type) {
@@ -3487,13 +3639,13 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3487
3639
  : this.optionsHelper;
3488
3640
  if (this.flags) {
3489
3641
  const names = Enums.toNames(this.members, value);
3490
- return !(parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.stringAsEnum)
3642
+ return !this.stringAsEnum
3491
3643
  ? `${this.namespace}.${this.name}'${names.join(', ')}'`
3492
3644
  : names.join(', ');
3493
3645
  }
3494
3646
  else {
3495
3647
  const name = Enums.toName(this.members, value);
3496
- return !(parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.stringAsEnum)
3648
+ return !this.stringAsEnum
3497
3649
  ? `${this.namespace}.${this.name}'${name}'`
3498
3650
  : name;
3499
3651
  }
@@ -3504,7 +3656,7 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3504
3656
  ? new ODataParserOptions(options)
3505
3657
  : this.optionsHelper;
3506
3658
  const serialized = this.serialize(value, parserOptions);
3507
- return (parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.stringAsEnum)
3659
+ return this.stringAsEnum
3508
3660
  ? raw(`'${serialized}'`)
3509
3661
  : raw(serialized);
3510
3662
  }
@@ -3595,8 +3747,8 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
3595
3747
  }
3596
3748
  //#region Deserialize
3597
3749
  parse(parser, value, options) {
3598
- const type = Types.isPlainObject(value)
3599
- ? options === null || options === void 0 ? void 0 : options.helper.type(value)
3750
+ const type = options !== undefined && Types.isPlainObject(value)
3751
+ ? options.helper.type(value)
3600
3752
  : undefined;
3601
3753
  if (type !== undefined) {
3602
3754
  return parser
@@ -3620,8 +3772,8 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
3620
3772
  //#endregion
3621
3773
  //#region Serialize
3622
3774
  toJson(parser, value, options) {
3623
- const type = Types.isPlainObject(value)
3624
- ? options === null || options === void 0 ? void 0 : options.helper.type(value)
3775
+ const type = options !== undefined && Types.isPlainObject(value)
3776
+ ? options.helper.type(value)
3625
3777
  : undefined;
3626
3778
  if (type !== undefined) {
3627
3779
  return parser
@@ -4007,7 +4159,8 @@ class ODataCallableParser {
4007
4159
  .filter((p) => p.name in params && params[p.name] !== undefined);
4008
4160
  return parameters.reduce((acc, p) => (Object.assign(Object.assign({}, acc), { [p.name]: p.encode(params[p.name], parserOptions) })), {});
4009
4161
  }
4010
- configure({ parserForType, options, }) {
4162
+ configure({ nonParenthesisForEmptyParameterFunction, parserForType, options, }) {
4163
+ this.nonParenthesisForEmptyParameterFunction = nonParenthesisForEmptyParameterFunction;
4011
4164
  this.optionsHelper = options;
4012
4165
  if (this.return)
4013
4166
  this.parser = parserForType(this.return.type) || NONE_PARSER;
@@ -4041,7 +4194,11 @@ class ODataCallable extends ODataSchemaElement {
4041
4194
  return path;
4042
4195
  }
4043
4196
  configure({ parserForType, }) {
4044
- this.parser.configure({ options: this.api.options, parserForType });
4197
+ this.parser.configure({
4198
+ nonParenthesisForEmptyParameterFunction: this.api.options.nonParenthesisForEmptyParameterFunction,
4199
+ options: this.api.options,
4200
+ parserForType
4201
+ });
4045
4202
  }
4046
4203
  /**
4047
4204
  * Deseialize the given value from the callable.
@@ -4101,7 +4258,7 @@ class ODataEnumType extends ODataSchemaElement {
4101
4258
  this.parser = new ODataEnumTypeParser(config, schema.namespace, schema.alias);
4102
4259
  }
4103
4260
  configure() {
4104
- this.parser.configure({ options: this.api.options });
4261
+ this.parser.configure({ stringAsEnum: this.api.options.stringAsEnum, options: this.api.options });
4105
4262
  }
4106
4263
  /**
4107
4264
  * Returns the fields of the enum type.
@@ -4126,6 +4283,14 @@ class ODataEnumType extends ODataSchemaElement {
4126
4283
  findFieldByValue(value) {
4127
4284
  return this.fields().find((f) => f.value === value);
4128
4285
  }
4286
+ /**
4287
+ * Find a fields by flag.
4288
+ * @param value The value of the field
4289
+ * @returns The fields with the given flag
4290
+ */
4291
+ findFieldsByValue(value) {
4292
+ return this.fields().filter((f) => Boolean(f.value & value));
4293
+ }
4129
4294
  /**
4130
4295
  * Map the fields of the enum type.
4131
4296
  * @param mapper Function that maps the value to the new value
@@ -4298,14 +4463,9 @@ class ODataStructuredType extends ODataSchemaElement {
4298
4463
  */
4299
4464
  pick(attrs, { include_parents = true, include_navigation = false, include_etag = true, } = {}) {
4300
4465
  const names = this.fields({ include_parents, include_navigation }).map((f) => f.name);
4301
- let values = Object.keys(attrs)
4302
- .filter((k) => names.indexOf(k) !== -1)
4303
- .reduce((acc, k) => Object.assign(acc, { [k]: attrs[k] }), {});
4304
- if (include_etag) {
4305
- const etag = this.api.options.helper.etag(attrs);
4306
- this.api.options.helper.etag(attrs, etag);
4307
- }
4308
- return values;
4466
+ return Object.keys(attrs)
4467
+ .filter((key) => names.indexOf(key) !== -1 || (key == this.api.options.helper.ODATA_ETAG && include_etag))
4468
+ .reduce((acc, key) => Object.assign(acc, { [key]: attrs[key] }), {});
4309
4469
  }
4310
4470
  /**
4311
4471
  * Deseialize the given value from the structured type.
@@ -4540,29 +4700,28 @@ class ODataResource {
4540
4700
  query: this.cloneQuery(),
4541
4701
  });
4542
4702
  }
4703
+ __parser(value, options, type) {
4704
+ const dataType = options !== undefined && Types.isPlainObject(value)
4705
+ ? options.helper.type(value)
4706
+ : undefined;
4707
+ if (dataType !== undefined) {
4708
+ // Parser from data type
4709
+ return this.api.parserForType(dataType);
4710
+ }
4711
+ else if (this.schema !== undefined && 'parser' in this.schema) {
4712
+ // Parser from resource schema
4713
+ return this.schema.parser;
4714
+ }
4715
+ else if (type !== undefined) {
4716
+ // Parser from resource type
4717
+ return this.api.parserForType(type);
4718
+ }
4719
+ return undefined;
4720
+ }
4543
4721
  deserialize(value, options) {
4544
4722
  const resourceType = this.returnType();
4545
- const resourceSchema = this.schema;
4546
- const _p = (value, options) => {
4547
- const dataType = Types.isPlainObject(value)
4548
- ? options.helper.type(value)
4549
- : undefined;
4550
- if (dataType !== undefined) {
4551
- // Parser from data type
4552
- return this.api.parserForType(dataType);
4553
- }
4554
- else if (resourceSchema !== undefined && 'parser' in resourceSchema) {
4555
- // Parser from resource schema
4556
- return resourceSchema.parser;
4557
- }
4558
- else if (resourceType !== undefined) {
4559
- // Parser from resource type
4560
- return this.api.parserForType(resourceType);
4561
- }
4562
- return undefined;
4563
- };
4564
4723
  const _d = (value, options) => {
4565
- const parser = _p(value, options);
4724
+ const parser = this.__parser(value, options, resourceType);
4566
4725
  return parser !== undefined && 'deserialize' in parser
4567
4726
  ? parser.deserialize(value, options)
4568
4727
  : value;
@@ -4573,27 +4732,8 @@ class ODataResource {
4573
4732
  }
4574
4733
  serialize(value, options) {
4575
4734
  const resourceType = this.type();
4576
- const resourceSchema = this.schema;
4577
- const _p = (value, options) => {
4578
- const dataType = Types.isPlainObject(value)
4579
- ? options.helper.type(value)
4580
- : undefined;
4581
- if (dataType !== undefined) {
4582
- // Parser from data type
4583
- return this.api.parserForType(dataType);
4584
- }
4585
- else if (resourceSchema !== undefined && 'parser' in resourceSchema) {
4586
- // Parser from resource schema
4587
- return resourceSchema.parser;
4588
- }
4589
- else if (resourceType !== undefined) {
4590
- // Parser from resource type
4591
- return this.api.parserForType(resourceType);
4592
- }
4593
- return undefined;
4594
- };
4595
4735
  const _s = (value, options) => {
4596
- const parser = _p(value, options);
4736
+ const parser = this.__parser(value, options, resourceType);
4597
4737
  return parser !== undefined && 'serialize' in parser
4598
4738
  ? parser.serialize(value, options)
4599
4739
  : value;
@@ -4604,27 +4744,8 @@ class ODataResource {
4604
4744
  }
4605
4745
  encode(value, options) {
4606
4746
  const resourceType = this.type();
4607
- const resourceSchema = this.schema;
4608
- const _p = (value, options) => {
4609
- const dataType = Types.isPlainObject(value)
4610
- ? options.helper.type(value)
4611
- : undefined;
4612
- if (dataType !== undefined) {
4613
- // Parser from data type
4614
- return this.api.parserForType(dataType);
4615
- }
4616
- else if (resourceSchema !== undefined && 'parser' in resourceSchema) {
4617
- // Parser from resource schema
4618
- return resourceSchema.parser;
4619
- }
4620
- else if (resourceType !== undefined) {
4621
- // Parser from resource type
4622
- return this.api.parserForType(resourceType);
4623
- }
4624
- return undefined;
4625
- };
4626
4747
  const _e = (value, options) => {
4627
- const parser = _p(value, options);
4748
+ const parser = this.__parser(value, options, resourceType);
4628
4749
  return parser !== undefined && 'encode' in parser
4629
4750
  ? parser.encode(value, options)
4630
4751
  : value;
@@ -4843,7 +4964,7 @@ class ODataActionResource extends ODataResource {
4843
4964
  }
4844
4965
 
4845
4966
  class ODataAnnotations {
4846
- constructor(helper, annotations = {}, context) {
4967
+ constructor(helper, annotations = new Map(), context) {
4847
4968
  this.helper = helper;
4848
4969
  this.annotations = annotations;
4849
4970
  this.context = context;
@@ -4862,7 +4983,7 @@ class ODataAnnotations {
4862
4983
  }
4863
4984
  class ODataPropertyAnnotations extends ODataAnnotations {
4864
4985
  clone() {
4865
- return new ODataPropertyAnnotations(this.helper, Object.assign({}, this.annotations), this.context);
4986
+ return new ODataPropertyAnnotations(this.helper, new Map(this.annotations), this.context);
4866
4987
  }
4867
4988
  data(data) {
4868
4989
  return this.helper.property(data);
@@ -4870,7 +4991,7 @@ class ODataPropertyAnnotations extends ODataAnnotations {
4870
4991
  }
4871
4992
  class ODataEntityAnnotations extends ODataAnnotations {
4872
4993
  clone() {
4873
- return new ODataEntityAnnotations(this.helper, Object.assign({}, this.annotations), this.context);
4994
+ return new ODataEntityAnnotations(this.helper, new Map(this.annotations), this.context);
4874
4995
  }
4875
4996
  data(data) {
4876
4997
  return this.helper.entity(data);
@@ -4909,7 +5030,7 @@ class ODataEntityAnnotations extends ODataAnnotations {
4909
5030
  return this._properties;
4910
5031
  }
4911
5032
  property(name) {
4912
- return this.properties[name];
5033
+ return this.properties.get(name);
4913
5034
  }
4914
5035
  get functions() {
4915
5036
  if (this._functions === undefined) {
@@ -4923,7 +5044,7 @@ class ODataEntityAnnotations extends ODataAnnotations {
4923
5044
  }
4924
5045
  class ODataEntitiesAnnotations extends ODataAnnotations {
4925
5046
  clone() {
4926
- return new ODataEntitiesAnnotations(this.helper, Object.assign({}, this.annotations), this.context);
5047
+ return new ODataEntitiesAnnotations(this.helper, new Map(this.annotations), this.context);
4927
5048
  }
4928
5049
  data(data) {
4929
5050
  return this.helper.entities(data);
@@ -4966,7 +5087,6 @@ class ODataEntitiesAnnotations extends ODataAnnotations {
4966
5087
  class ODataResponseOptions {
4967
5088
  constructor(config) {
4968
5089
  this.version = config.version || DEFAULT_VERSION;
4969
- this.stringAsEnum = config.stringAsEnum;
4970
5090
  }
4971
5091
  get helper() {
4972
5092
  return ODataHelper[this.version];
@@ -5105,13 +5225,13 @@ class ODataResponse extends HttpResponse {
5105
5225
  if (key) {
5106
5226
  const etag = this.headers.get(key);
5107
5227
  if (etag)
5108
- options.helper.etag(this._annotations, etag);
5228
+ this._annotations.set(options.helper.ODATA_ETAG, etag);
5109
5229
  }
5110
5230
  key = Http.resolveHeaderKey(this.headers, ODATA_ENTITYID_HEADERS);
5111
5231
  if (key) {
5112
5232
  const entityId = this.headers.get(key);
5113
5233
  if (entityId)
5114
- options.helper.id(this._annotations, entityId);
5234
+ this._annotations.set(options.helper.ODATA_ID, entityId);
5115
5235
  }
5116
5236
  }
5117
5237
  return this._annotations;
@@ -6352,6 +6472,14 @@ class ODataFunctionResource extends ODataResource {
6352
6472
  ? (_a = this.schema.parser.return) === null || _a === void 0 ? void 0 : _a.type
6353
6473
  : undefined;
6354
6474
  }
6475
+ pathAndParams(escape = false) {
6476
+ let [path, params] = super.pathAndParams(escape);
6477
+ if (path.endsWith('()') &&
6478
+ this.api.options.nonParenthesisForEmptyParameterFunction) {
6479
+ path = path.substring(0, path.length - 2);
6480
+ }
6481
+ return [path, params];
6482
+ }
6355
6483
  parameters(params, { alias } = {}) {
6356
6484
  let parameters = params !== null ? this.encode(params) : null;
6357
6485
  if (alias && parameters !== null) {
@@ -7044,7 +7172,7 @@ class ODataEntityResource extends ODataResource {
7044
7172
  if (castSchema !== undefined &&
7045
7173
  baseSchema !== undefined &&
7046
7174
  !castSchema.isSubtypeOf(baseSchema))
7047
- throw new Error(`Cannot cast to ${type}`);
7175
+ throw new Error(`cast: Cannot cast to ${type}`);
7048
7176
  const segments = this.cloneSegments();
7049
7177
  segments.add(PathSegmentNames.type, type).type(type);
7050
7178
  return new ODataEntityResource(this.api, {
@@ -7085,7 +7213,7 @@ class ODataEntityResource extends ODataResource {
7085
7213
  }
7086
7214
  fetch(options) {
7087
7215
  if (!this.hasKey())
7088
- return throwError('Entity resource without key');
7216
+ return throwError(() => new Error('fetch: Entity resource without key'));
7089
7217
  return this.get(options);
7090
7218
  }
7091
7219
  fetchEntity(options) {
@@ -7403,6 +7531,18 @@ class ODataModelEvent {
7403
7531
  : '')
7404
7532
  .join('');
7405
7533
  }
7534
+ //Identifies the current model for the event
7535
+ get currentModel() {
7536
+ const link = this.chain.find((c) => ODataModelOptions.isModel(c[0]));
7537
+ return link !== undefined ? link[0] : undefined;
7538
+ }
7539
+ //Identifies the current collection for the event
7540
+ get currentCollection() {
7541
+ const link = this.chain.find((c) => ODataModelOptions.isCollection(c[0]));
7542
+ return link !== undefined
7543
+ ? link[0]
7544
+ : undefined;
7545
+ }
7406
7546
  }
7407
7547
  const BUBBLING = [
7408
7548
  'change',
@@ -7599,8 +7739,8 @@ class ODataModelField {
7599
7739
  }
7600
7740
  annotationsFactory(base) {
7601
7741
  return this.parser.collection
7602
- ? new ODataEntitiesAnnotations(base.helper, base.property(this.parser.name) || {})
7603
- : new ODataEntityAnnotations(base.helper, base.property(this.parser.name) || {});
7742
+ ? new ODataEntitiesAnnotations(base.helper, base.property(this.parser.name))
7743
+ : new ODataEntityAnnotations(base.helper, base.property(this.parser.name));
7604
7744
  }
7605
7745
  schemaFactory(base) {
7606
7746
  return this.api.findStructuredTypeForType(this.parser.type);
@@ -7731,30 +7871,35 @@ class ODataModelOptions {
7731
7871
  }
7732
7872
  static resource(child) {
7733
7873
  var _a;
7734
- let resource = undefined;
7874
+ let resource = null;
7875
+ let prevField = null;
7735
7876
  for (let [model, field] of ODataModelOptions.chain(child)) {
7736
7877
  resource = resource || model._resource;
7737
- if (resource === undefined)
7878
+ if (resource === null)
7738
7879
  break;
7739
- if (ODataModelOptions.isModel(model)) {
7740
- let key = model.key({
7880
+ if (ODataModelOptions.isModel(model) &&
7881
+ (prevField === null || prevField.collection)) {
7882
+ // Resolve key
7883
+ let modelKey = model.key({
7741
7884
  field_mapping: true,
7742
7885
  });
7743
- if (key !== undefined)
7886
+ if (modelKey !== undefined)
7744
7887
  resource =
7745
7888
  resource instanceof ODataEntitySetResource
7746
- ? resource.entity(key)
7747
- : resource.key(key);
7889
+ ? resource.entity(modelKey)
7890
+ : resource.key(modelKey);
7748
7891
  }
7892
+ prevField = field;
7749
7893
  if (field === null) {
7894
+ // Apply the query from model to new resource
7750
7895
  const query = (_a = model._resource) === null || _a === void 0 ? void 0 : _a.cloneQuery().toQueryArguments();
7751
- if (query !== undefined && resource !== undefined)
7896
+ if (query !== undefined)
7752
7897
  resource.query((q) => q.apply(query));
7753
7898
  continue;
7754
7899
  }
7755
7900
  resource = field.resourceFactory(resource);
7756
7901
  }
7757
- if (resource === undefined)
7902
+ if (resource === null)
7758
7903
  throw new Error(`resource: Can't build resource for ${child}`);
7759
7904
  return resource;
7760
7905
  }
@@ -7905,8 +8050,8 @@ class ODataModelOptions {
7905
8050
  return !Types.isEmpty(defs) ? defs : undefined;
7906
8051
  }
7907
8052
  hasChanged(self, { include_navigation = false } = {}) {
7908
- return (!Types.isEmpty(self._changes) ||
7909
- Object.values(self._relations)
8053
+ return (self._changes.size != 0 ||
8054
+ [...self._relations.values()]
7910
8055
  .filter(({ field }) => !field.navigation || include_navigation)
7911
8056
  .some(({ field, state, model }) => (!include_navigation || field.navigation) &&
7912
8057
  (state === ODataModelState.Changed ||
@@ -7947,7 +8092,7 @@ class ODataModelOptions {
7947
8092
  include_computed,
7948
8093
  include_non_field,
7949
8094
  });
7950
- let relations = Object.entries(self._relations)
8095
+ let relations = [...self._relations.entries()]
7951
8096
  .filter(
7952
8097
  // Chain
7953
8098
  ([, { model }]) => chain.every((c) => c !== model))
@@ -8022,19 +8167,19 @@ class ODataModelOptions {
8022
8167
  (ODataModelOptions.isCollection(self._parent[0]) &&
8023
8168
  self._parent[0]._model
8024
8169
  .meta !== self._meta))) {
8025
- this.api.options.helper.type(entity, this.schema.type());
8170
+ entity[this.api.options.helper.ODATA_TYPE] = `#${this.schema.type()}`;
8026
8171
  }
8027
8172
  return entity;
8028
8173
  }
8029
8174
  attributes(self, { changes_only = false, include_concurrency = false, include_computed = false, include_non_field = false, field_mapping = false, } = {}) {
8030
8175
  // Attributes by fields (attributes for the model type)
8031
8176
  const fieldAttrs = this.fields().reduce((acc, f) => {
8032
- const isChanged = f.name in self._changes;
8177
+ const isChanged = self._changes.has(f.name);
8033
8178
  const name = field_mapping ? f.field : f.name;
8034
8179
  const computed = f.annotatedValue(COMPUTED);
8035
8180
  const value = isChanged
8036
- ? self._changes[f.name]
8037
- : self._attributes[f.name];
8181
+ ? self._changes.get(f.name)
8182
+ : self._attributes.get(f.name);
8038
8183
  if (f.concurrency && include_concurrency) {
8039
8184
  return Object.assign(acc, { [name]: value });
8040
8185
  }
@@ -8061,10 +8206,10 @@ class ODataModelOptions {
8061
8206
  return Object.assign(Object.assign({}, fieldAttrs), nonFieldAttrs);
8062
8207
  }
8063
8208
  reset(self, { name, silent = false } = {}) {
8064
- if (!Types.isEmpty(name) && name in self._changes) {
8065
- const value = self._attributes[name];
8066
- const previous = self._changes[name];
8067
- delete self._changes[name];
8209
+ if (!Types.isEmpty(name) && self._changes.has(name)) {
8210
+ const value = self._attributes.get(name);
8211
+ const previous = self._changes.get(name);
8212
+ self._changes.delete(name);
8068
8213
  if (!silent) {
8069
8214
  self.events$.emit(new ODataModelEvent('change', {
8070
8215
  model: self,
@@ -8075,14 +8220,14 @@ class ODataModelOptions {
8075
8220
  }
8076
8221
  }
8077
8222
  else if (Types.isEmpty(name)) {
8078
- const entries = Object.entries(self._changes);
8079
- self._changes = {};
8223
+ const entries = [...self._changes.entries()];
8224
+ self._changes.clear();
8080
8225
  if (!silent) {
8081
8226
  entries.forEach((entry) => {
8082
8227
  self.events$.emit(new ODataModelEvent('change', {
8083
8228
  track: entry[0],
8084
8229
  model: self,
8085
- value: self._attributes[entry[0]],
8230
+ value: self._attributes.get(entry[0]),
8086
8231
  previous: entry[1],
8087
8232
  }));
8088
8233
  });
@@ -8154,7 +8299,7 @@ class ODataModelOptions {
8154
8299
  _get(self, field) {
8155
8300
  var _a;
8156
8301
  if (field.isStructuredType()) {
8157
- return (_a = self._relations[field.name]) === null || _a === void 0 ? void 0 : _a.model;
8302
+ return (_a = self._relations.get(field.name)) === null || _a === void 0 ? void 0 : _a.model;
8158
8303
  }
8159
8304
  else {
8160
8305
  return this.attributes(self, {
@@ -8167,13 +8312,13 @@ class ODataModelOptions {
8167
8312
  var _a;
8168
8313
  let changed = false;
8169
8314
  // Ensures that the relation exists
8170
- if (!(field.name in self._relations)) {
8171
- self._relations[field.name] = {
8315
+ if (!self._relations.has(field.name)) {
8316
+ self._relations.set(field.name, {
8172
8317
  state: ODataModelState.Unchanged,
8173
8318
  field: field,
8174
- };
8319
+ });
8175
8320
  }
8176
- const relation = self._relations[field.name];
8321
+ const relation = self._relations.get(field.name);
8177
8322
  const currentModel = relation.model;
8178
8323
  if (value === null) {
8179
8324
  relation.model = value;
@@ -8256,14 +8401,14 @@ class ODataModelOptions {
8256
8401
  const currentValue = attrs[field];
8257
8402
  changed = !Types.isEqual(currentValue, value);
8258
8403
  if (self._reset) {
8259
- delete self._changes[field];
8260
- self._attributes[field] = value;
8404
+ self._changes.delete(field);
8405
+ self._attributes.set(field, value);
8261
8406
  }
8262
- else if (Types.isEqual(value, self._attributes[field])) {
8263
- delete self._changes[field];
8407
+ else if (Types.isEqual(value, self._attributes.get(field))) {
8408
+ self._changes.delete(field);
8264
8409
  }
8265
8410
  else if (changed) {
8266
- self._changes[field] = value;
8411
+ self._changes.set(field, value);
8267
8412
  }
8268
8413
  if (!self._silent && changed) {
8269
8414
  self.events$.emit(new ODataModelEvent('change', {
@@ -8328,7 +8473,7 @@ class ODataCollection {
8328
8473
  if (model === undefined && Klass.model !== null)
8329
8474
  model = Klass.model;
8330
8475
  if (model === undefined)
8331
- throw new Error('Collection need model');
8476
+ throw new Error('Collection: Collection need model');
8332
8477
  this._model = model;
8333
8478
  // Parent
8334
8479
  if (parent !== undefined) {
@@ -8366,7 +8511,7 @@ class ODataCollection {
8366
8511
  if (this._resource !== null &&
8367
8512
  this._resource.type() !== resource.type() &&
8368
8513
  !this._resource.isSubtypeOf(resource))
8369
- throw new Error(`Can't reattach ${this._resource.type()} to ${resource.type()}`);
8514
+ throw new Error(`attach: Can't reattach ${this._resource.type()} to ${resource.type()}`);
8370
8515
  this._entries.forEach(({ model }) => {
8371
8516
  const mr = this._model.meta.modelResourceFactory(resource.cloneQuery());
8372
8517
  model.attach(mr);
@@ -8386,7 +8531,7 @@ class ODataCollection {
8386
8531
  const query = this.resource().cloneQuery();
8387
8532
  let resource = this._model.meta.collectionResourceFactory(query);
8388
8533
  if (resource === undefined)
8389
- throw new Error('Collection does not have associated EntitySet endpoint');
8534
+ throw new Error('asEntitySet: Collection does not have associated EntitySet endpoint');
8390
8535
  // Store parent and resource
8391
8536
  const store = { parent: this._parent, resource: this._resource };
8392
8537
  // Replace parent and resource
@@ -8415,7 +8560,7 @@ class ODataCollection {
8415
8560
  var _a;
8416
8561
  let Model = this._model;
8417
8562
  const helper = this._annotations.helper;
8418
- const annots = new ODataEntityAnnotations(helper, helper.annotations(data) || {});
8563
+ const annots = new ODataEntityAnnotations(helper, helper.annotations(data));
8419
8564
  if ((annots === null || annots === void 0 ? void 0 : annots.type) !== undefined && Model.meta !== null) {
8420
8565
  let schema = (_a = Model.meta.findChildOptions((o) => o.isTypeOf(annots.type))) === null || _a === void 0 ? void 0 : _a.schema;
8421
8566
  if (schema !== undefined && schema.model !== undefined)
@@ -8463,18 +8608,9 @@ class ODataCollection {
8463
8608
  fetch(_a = {}) {
8464
8609
  var { withCount } = _a, options = __rest(_a, ["withCount"]);
8465
8610
  const resource = this.resource();
8466
- if (resource === undefined)
8467
- return throwError('fetch: Resource is undefined');
8468
- let obs$;
8469
- if (resource instanceof ODataEntitySetResource) {
8470
- obs$ = resource.fetch(Object.assign({ withCount }, options));
8471
- }
8472
- else if (resource instanceof ODataNavigationPropertyResource) {
8473
- obs$ = resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
8474
- }
8475
- else {
8476
- obs$ = resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
8477
- }
8611
+ const obs$ = resource instanceof ODataEntitySetResource
8612
+ ? resource.fetch(Object.assign({ withCount }, options))
8613
+ : resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
8478
8614
  this.events$.emit(new ODataModelEvent('request', { collection: this, value: obs$ }));
8479
8615
  return obs$.pipe(map(({ entities, annots }) => {
8480
8616
  this._annotations = annots;
@@ -8485,10 +8621,8 @@ class ODataCollection {
8485
8621
  }
8486
8622
  fetchAll(options) {
8487
8623
  const resource = this.resource();
8488
- if (resource === undefined)
8489
- return throwError('fetchAll: Resource is undefined');
8490
8624
  if (resource instanceof ODataPropertyResource)
8491
- return throwError('fetchAll: Resource is ODataPropertyResource');
8625
+ return throwError(() => new Error('fetchAll: Resource is ODataPropertyResource'));
8492
8626
  const obs$ = resource.fetchAll(options);
8493
8627
  this.events$.emit(new ODataModelEvent('request', {
8494
8628
  collection: this,
@@ -8513,10 +8647,8 @@ class ODataCollection {
8513
8647
  save(_a = {}) {
8514
8648
  var { relModel = false, method } = _a, options = __rest(_a, ["relModel", "method"]);
8515
8649
  const resource = this.resource();
8516
- if (resource === undefined)
8517
- return throwError('saveAll: Resource is undefined');
8518
8650
  if (resource instanceof ODataPropertyResource)
8519
- return throwError('fetchAll: Resource is ODataPropertyResource');
8651
+ return throwError(() => new Error('save: Resource is ODataPropertyResource'));
8520
8652
  let toDestroyEntity = [];
8521
8653
  let toRemoveReference = [];
8522
8654
  let toDestroyContained = [];
@@ -8803,7 +8935,7 @@ class ODataCollection {
8803
8935
  }
8804
8936
  else {
8805
8937
  const helper = this._annotations.helper;
8806
- const annots = new ODataEntityAnnotations(helper, helper.annotations(obj) || {});
8938
+ const annots = new ODataEntityAnnotations(helper, helper.annotations(obj));
8807
8939
  const entity = annots.attributes(obj, 'full');
8808
8940
  model._annotations = annots;
8809
8941
  model.assign(entity, { reset, silent });
@@ -8884,26 +9016,26 @@ class ODataCollection {
8884
9016
  return func.call(params, Object.assign({ responseType }, options));
8885
9017
  }
8886
9018
  }
8887
- return throwError(`Can't function without ODataEntitySetResource`);
9019
+ return throwError(() => new Error(`callFunction: Can't function without ODataEntitySetResource`));
8888
9020
  }
8889
9021
  callAction(name, params, responseType, _a = {}) {
8890
9022
  var options = __rest(_a, []);
8891
9023
  const resource = this.resource();
8892
- if (resource instanceof ODataEntitySetResource) {
8893
- const action = resource.action(name);
8894
- action.query((q) => q.apply(options));
8895
- switch (responseType) {
8896
- case 'property':
8897
- return action.callProperty(params, options);
8898
- case 'model':
8899
- return action.callModel(params, options);
8900
- case 'collection':
8901
- return action.callCollection(params, options);
8902
- default:
8903
- return action.call(params, Object.assign({ responseType }, options));
8904
- }
9024
+ if (!(resource instanceof ODataEntitySetResource)) {
9025
+ return throwError(() => new Error(`callAction: Can't action without ODataEntitySetResource`));
9026
+ }
9027
+ const action = resource.action(name);
9028
+ action.query((q) => q.apply(options));
9029
+ switch (responseType) {
9030
+ case 'property':
9031
+ return action.callProperty(params, options);
9032
+ case 'model':
9033
+ return action.callModel(params, options);
9034
+ case 'collection':
9035
+ return action.callCollection(params, options);
9036
+ default:
9037
+ return action.call(params, Object.assign({ responseType }, options));
8905
9038
  }
8906
- return throwError(`Can't action without ODataEntitySetResource`);
8907
9039
  }
8908
9040
  _unsubscribe(entry) {
8909
9041
  if (entry.subscription) {
@@ -8913,7 +9045,7 @@ class ODataCollection {
8913
9045
  }
8914
9046
  _subscribe(entry) {
8915
9047
  if (entry.subscription) {
8916
- throw new Error('Subscription already exists');
9048
+ throw new Error('Collection: Subscription already exists');
8917
9049
  }
8918
9050
  entry.subscription = entry.model.events$.subscribe((event) => {
8919
9051
  var _a;
@@ -8963,12 +9095,18 @@ class ODataCollection {
8963
9095
  },
8964
9096
  };
8965
9097
  }
8966
- filter(predicate) {
9098
+ filter(predicate, thisArg) {
8967
9099
  return this.models().filter(predicate);
8968
9100
  }
8969
- find(predicate) {
9101
+ map(callbackfn, thisArg) {
9102
+ return this.models().map(callbackfn, thisArg);
9103
+ }
9104
+ find(predicate, thisArg) {
8970
9105
  return this.models().find(predicate);
8971
9106
  }
9107
+ reduce(callbackfn, initialValue) {
9108
+ return this.models().reduce(callbackfn, initialValue);
9109
+ }
8972
9110
  first() {
8973
9111
  return this.models()[0];
8974
9112
  }
@@ -9065,9 +9203,9 @@ class ODataModel {
9065
9203
  constructor(data = {}, { parent, resource, annots, reset = false, } = {}) {
9066
9204
  // Parent
9067
9205
  this._parent = null;
9068
- this._attributes = {};
9069
- this._changes = {};
9070
- this._relations = {};
9206
+ this._attributes = new Map();
9207
+ this._changes = new Map();
9208
+ this._relations = new Map();
9071
9209
  this._resource = null;
9072
9210
  this._reset = false;
9073
9211
  this._reparent = false;
@@ -9076,7 +9214,7 @@ class ODataModel {
9076
9214
  this.events$ = new EventEmitter();
9077
9215
  const Klass = this.constructor;
9078
9216
  if (Klass.meta === undefined)
9079
- throw new Error(`Can't create model without metadata`);
9217
+ throw new Error(`ODataModel: Can't create model without metadata`);
9080
9218
  this._meta = Klass.meta;
9081
9219
  this._meta.bind(this, { parent, resource, annots });
9082
9220
  // Client Id
@@ -9116,19 +9254,19 @@ class ODataModel {
9116
9254
  navigationProperty(name) {
9117
9255
  const field = this._meta.field(name);
9118
9256
  if (field === undefined || !field.navigation)
9119
- throw Error(`Can't find navigation property ${name}`);
9257
+ throw Error(`navigationProperty: Can't find navigation property ${name}`);
9120
9258
  const resource = this.resource();
9121
9259
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9122
- throw Error("Can't get navigation without ODataEntityResource with key");
9260
+ throw Error("navigationProperty: Can't get navigation without ODataEntityResource with key");
9123
9261
  return field.resourceFactory(resource);
9124
9262
  }
9125
9263
  property(name) {
9126
9264
  const field = this._meta.field(name);
9127
9265
  if (field === undefined || field.navigation)
9128
- throw Error(`Can't find property ${name}`);
9266
+ throw Error(`property: Can't find property ${name}`);
9129
9267
  const resource = this.resource();
9130
9268
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9131
- throw Error("Can't get property without ODataEntityResource with key");
9269
+ throw Error("property: Can't get property without ODataEntityResource with key");
9132
9270
  return field.resourceFactory(resource);
9133
9271
  }
9134
9272
  attach(resource) {
@@ -9274,11 +9412,11 @@ class ODataModel {
9274
9412
  var options = __rest(_a, []);
9275
9413
  let resource = this.resource();
9276
9414
  if (resource === undefined)
9277
- return throwError('fetch: Resource is undefined');
9415
+ return throwError(() => new Error('fetch: Resource is undefined'));
9278
9416
  let obs$;
9279
9417
  if (resource instanceof ODataEntityResource) {
9280
9418
  if (!resource.hasKey())
9281
- return throwError("fetch: Can't fetch model without key");
9419
+ return throwError(() => new Error("fetch: Can't fetch model without key"));
9282
9420
  obs$ = resource.fetch(options);
9283
9421
  }
9284
9422
  else if (resource instanceof ODataNavigationPropertyResource) {
@@ -9293,50 +9431,46 @@ class ODataModel {
9293
9431
  var { method, navigation = false, validate = true } = _a, options = __rest(_a, ["method", "navigation", "validate"]);
9294
9432
  let resource = this.resource();
9295
9433
  if (resource === undefined)
9296
- return throwError('save: Resource is undefined');
9434
+ return throwError(() => new Error('save: Resource is undefined'));
9297
9435
  if (!(resource instanceof ODataEntityResource ||
9298
9436
  resource instanceof ODataNavigationPropertyResource))
9299
- return throwError('save: Resource type ODataEntityResource/ODataNavigationPropertyResource needed');
9437
+ return throwError(() => new Error('save: Resource type ODataEntityResource/ODataNavigationPropertyResource needed'));
9300
9438
  // Resolve method and resource key
9301
9439
  if (method === undefined && this.schema().isCompoundKey())
9302
- return throwError('save: Composite key require a specific method, use create/update/modify');
9440
+ return throwError(() => new Error('save: Composite key require a specific method, use create/update/modify'));
9303
9441
  method = method || (!resource.hasKey() ? 'create' : 'update');
9304
9442
  if (resource instanceof ODataEntityResource &&
9305
9443
  (method === 'update' || method === 'modify') &&
9306
9444
  !resource.hasKey())
9307
- return throwError('save: Update/Patch require entity key');
9445
+ return throwError(() => new Error('save: Update/Patch require entity key'));
9308
9446
  if (resource instanceof ODataNavigationPropertyResource ||
9309
9447
  method === 'create')
9310
9448
  resource.clearKey();
9311
- let obs$;
9312
- if (!validate || this.isValid({ method, navigation })) {
9313
- const _entity = this.toEntity({
9314
- changes_only: method === 'modify',
9315
- field_mapping: true,
9316
- include_concurrency: true,
9317
- include_navigation: navigation,
9318
- });
9319
- obs$ = (method === 'create'
9320
- ? resource.create(_entity, options)
9321
- : method === 'modify'
9322
- ? resource.modify(_entity, Object.assign({ etag: this.annots().etag }, options))
9323
- : resource.update(_entity, Object.assign({ etag: this.annots().etag }, options))).pipe(map(({ entity, annots }) => ({ entity: entity || _entity, annots })));
9449
+ if (validate && !this.isValid({ method, navigation })) {
9450
+ return throwError(() => new Error('save: Validation errors'));
9324
9451
  }
9325
- else {
9326
- obs$ = throwError(this._errors);
9327
- }
9328
- return this._request(obs$);
9452
+ const _entity = this.toEntity({
9453
+ changes_only: method === 'modify',
9454
+ field_mapping: true,
9455
+ include_concurrency: true,
9456
+ include_navigation: navigation,
9457
+ });
9458
+ return this._request((method === 'create'
9459
+ ? resource.create(_entity, options)
9460
+ : method === 'modify'
9461
+ ? resource.modify(_entity, Object.assign({ etag: this.annots().etag }, options))
9462
+ : resource.update(_entity, Object.assign({ etag: this.annots().etag }, options))).pipe(map(({ entity, annots }) => ({ entity: entity || _entity, annots }))));
9329
9463
  }
9330
9464
  destroy(_a = {}) {
9331
9465
  var options = __rest(_a, []);
9332
9466
  let resource = this.resource();
9333
9467
  if (resource === undefined)
9334
- return throwError('destroy: Resource is undefined');
9468
+ return throwError(() => new Error('destroy: Resource is undefined'));
9335
9469
  if (!(resource instanceof ODataEntityResource ||
9336
9470
  resource instanceof ODataNavigationPropertyResource))
9337
- return throwError('destroy: Resource type ODataEntityResource/ODataNavigationPropertyResource needed');
9471
+ return throwError(() => new Error('destroy: Resource type ODataEntityResource/ODataNavigationPropertyResource needed'));
9338
9472
  if (!resource.hasKey())
9339
- return throwError("destroy: Can't destroy model without key");
9473
+ return throwError(() => new Error("destroy: Can't destroy model without key"));
9340
9474
  const _entity = this.toEntity({ field_mapping: true });
9341
9475
  const obs$ = resource
9342
9476
  .destroy(Object.assign({ etag: this.annots().etag }, options))
@@ -9370,7 +9504,7 @@ class ODataModel {
9370
9504
  var options = __rest(_a, []);
9371
9505
  const resource = this.resource();
9372
9506
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9373
- return throwError("Can't call function without ODataEntityResource with key");
9507
+ return throwError(() => new Error("callFunction: Can't call function without ODataEntityResource with key"));
9374
9508
  const func = resource.function(name).query((q) => q.apply(options));
9375
9509
  switch (responseType) {
9376
9510
  case 'property':
@@ -9387,7 +9521,7 @@ class ODataModel {
9387
9521
  var options = __rest(_a, []);
9388
9522
  const resource = this.resource();
9389
9523
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9390
- return throwError("Can't call action without ODataEntityResource with key");
9524
+ return throwError(() => new Error("callAction: Can't call action without ODataEntityResource with key"));
9391
9525
  const action = resource.action(name).query((q) => q.apply(options));
9392
9526
  switch (responseType) {
9393
9527
  case 'property':
@@ -9404,7 +9538,7 @@ class ODataModel {
9404
9538
  cast(type) {
9405
9539
  const resource = this.resource();
9406
9540
  if (!(resource instanceof ODataEntityResource))
9407
- throw new Error(`Can't cast to derived model without ODataEntityResource`);
9541
+ throw new Error(`cast: Can't cast to derived model without ODataEntityResource`);
9408
9542
  return resource
9409
9543
  .cast(type)
9410
9544
  .asModel(this.toEntity(INCLUDE_DEEP), { annots: this.annots() });
@@ -9424,7 +9558,7 @@ class ODataModel {
9424
9558
  getValue(name, options) {
9425
9559
  const field = this._meta.field(name);
9426
9560
  if (field === undefined || field.navigation)
9427
- throw Error(`Can't find property ${name}`);
9561
+ throw Error(`getValue: Can't find property ${name}`);
9428
9562
  let value = this[name];
9429
9563
  if (value === undefined) {
9430
9564
  const prop = field.resourceFactory(this.resource());
@@ -9471,7 +9605,7 @@ class ODataModel {
9471
9605
  getReference(name) {
9472
9606
  const field = this._meta.field(name);
9473
9607
  if (field === undefined || !field.navigation)
9474
- throw Error(`Can't find navigation property ${name}`);
9608
+ throw Error(`getReference: Can't find navigation property ${name}`);
9475
9609
  let model = this[name];
9476
9610
  if (model === undefined) {
9477
9611
  const value = field.collection ? [] : this.referenced(field);
@@ -9520,14 +9654,19 @@ class ODataApi {
9520
9654
  // Memoize
9521
9655
  this.memo = {
9522
9656
  forType: {
9523
- enum: {},
9524
- structured: {},
9525
- callable: {},
9526
- entitySet: {},
9527
- parser: {},
9528
- options: {},
9657
+ enum: new Map(),
9658
+ structured: new Map(),
9659
+ callable: new Map(),
9660
+ entitySet: new Map(),
9661
+ parser: new Map(),
9662
+ options: new Map(),
9663
+ },
9664
+ byName: {
9665
+ enum: new Map(),
9666
+ structured: new Map(),
9667
+ callable: new Map(),
9668
+ entitySet: new Map(),
9529
9669
  },
9530
- byName: { enum: {}, structured: {}, callable: {}, entitySet: {} },
9531
9670
  };
9532
9671
  this.serviceRootUrl = config.serviceRootUrl;
9533
9672
  if (this.serviceRootUrl.indexOf('?') != -1)
@@ -9656,31 +9795,32 @@ class ODataApi {
9656
9795
  }
9657
9796
  findEnumTypeForType(type) {
9658
9797
  var _a;
9659
- if (!(type in this.memo.forType.enum))
9660
- this.memo.forType.enum[type] =
9661
- (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findEnumTypeForType(type);
9662
- return this.memo.forType.enum[type];
9798
+ if (!this.memo.forType.enum.has(type)) {
9799
+ this.memo.forType.enum.set(type, (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findEnumTypeForType(type));
9800
+ }
9801
+ return this.memo.forType.enum.get(type);
9663
9802
  }
9664
9803
  findStructuredTypeForType(type) {
9665
9804
  var _a;
9666
- if (!(type in this.memo.forType.structured))
9667
- this.memo.forType.structured[type] =
9668
- (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findStructuredTypeForType(type);
9669
- return this.memo.forType.structured[type];
9805
+ if (!this.memo.forType.structured.has(type)) {
9806
+ this.memo.forType.structured.set(type, (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findStructuredTypeForType(type));
9807
+ }
9808
+ return this.memo.forType.structured.get(type);
9670
9809
  }
9671
9810
  findCallableForType(type, bindingType) {
9672
9811
  var _a;
9673
9812
  const key = bindingType !== undefined ? `${bindingType}/${type}` : type;
9674
- if (!(key in this.memo.forType.callable))
9675
- this.memo.forType.callable[key] = (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findCallableForType(type, bindingType);
9676
- return this.memo.forType.callable[key];
9813
+ if (!this.memo.forType.callable.has(key)) {
9814
+ this.memo.forType.callable.set(key, (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findCallableForType(type, bindingType));
9815
+ }
9816
+ return this.memo.forType.callable.get(key);
9677
9817
  }
9678
9818
  findEntitySetForType(type) {
9679
9819
  var _a;
9680
- if (!(type in this.memo.forType.entitySet))
9681
- this.memo.forType.entitySet[type] =
9682
- (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findEntitySetForType(type);
9683
- return this.memo.forType.entitySet[type];
9820
+ if (!this.memo.forType.entitySet.has(type)) {
9821
+ this.memo.forType.entitySet.set(type, (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findEntitySetForType(type));
9822
+ }
9823
+ return this.memo.forType.entitySet.get(type);
9684
9824
  }
9685
9825
  findModelForType(type) {
9686
9826
  var _a;
@@ -9730,48 +9870,53 @@ class ODataApi {
9730
9870
  return (_a = this.findEntitySetForType(type)) === null || _a === void 0 ? void 0 : _a.service;
9731
9871
  }
9732
9872
  findEntitySetForEntityType(entityType) {
9733
- if (!(entityType in this.memo.forType.entitySet))
9734
- this.memo.forType.entitySet[entityType] = this.schemas
9873
+ if (!this.memo.forType.entitySet.has(entityType)) {
9874
+ this.memo.forType.entitySet.set(entityType, this.schemas
9735
9875
  .reduce((acc, schema) => [...acc, ...schema.entitySets], [])
9736
- .find((e) => e.entityType === entityType);
9737
- return this.memo.forType.entitySet[entityType];
9876
+ .find((e) => e.entityType === entityType));
9877
+ }
9878
+ return this.memo.forType.entitySet.get(entityType);
9738
9879
  }
9739
9880
  findServiceForEntityType(entityType) {
9740
9881
  var _a;
9741
9882
  return (_a = this.findEntitySetForEntityType(entityType)) === null || _a === void 0 ? void 0 : _a.service;
9742
9883
  }
9743
9884
  findEnumTypeByName(name) {
9744
- if (!(name in this.memo.byName.enum))
9745
- this.memo.byName.enum[name] = this.schemas
9885
+ if (!this.memo.byName.enum.has(name)) {
9886
+ this.memo.byName.enum.set(name, this.schemas
9746
9887
  .reduce((acc, schema) => [...acc, ...schema.enums], [])
9747
- .find((e) => e.name === name);
9748
- return this.memo.byName.enum[name];
9888
+ .find((e) => e.name === name));
9889
+ }
9890
+ return this.memo.byName.enum.get(name);
9749
9891
  }
9750
9892
  findStructuredTypeByName(name) {
9751
- if (!(name in this.memo.byName.structured))
9752
- this.memo.byName.structured[name] = this.schemas
9893
+ if (!this.memo.byName.structured.has(name)) {
9894
+ this.memo.byName.structured.set(name, this.schemas
9753
9895
  .reduce((acc, schema) => [...acc, ...schema.entities], [])
9754
- .find((e) => e.name === name);
9755
- return this.memo.byName.structured[name];
9896
+ .find((e) => e.name === name));
9897
+ }
9898
+ return this.memo.byName.structured.get(name);
9756
9899
  }
9757
9900
  findCallableByName(name, bindingType) {
9758
9901
  const key = bindingType !== undefined ? `${bindingType}/${name}` : name;
9759
- if (!(key in this.memo.byName.callable))
9760
- this.memo.byName.callable[key] = this.schemas
9902
+ if (!this.memo.byName.callable.has(key)) {
9903
+ this.memo.byName.callable.set(key, this.schemas
9761
9904
  .reduce((acc, schema) => [...acc, ...schema.callables], [])
9762
9905
  .find((c) => {
9763
9906
  var _a;
9764
9907
  return c.name === name &&
9765
9908
  (bindingType === undefined || ((_a = c.binding()) === null || _a === void 0 ? void 0 : _a.type) === bindingType);
9766
- });
9767
- return this.memo.byName.callable[key];
9909
+ }));
9910
+ }
9911
+ return this.memo.byName.callable.get(key);
9768
9912
  }
9769
9913
  findEntitySetByName(name) {
9770
- if (!(name in this.memo.byName.entitySet))
9771
- this.memo.byName.entitySet[name] = this.schemas
9914
+ if (!this.memo.byName.entitySet.has(name)) {
9915
+ this.memo.byName.entitySet.set(name, this.schemas
9772
9916
  .reduce((acc, schema) => [...acc, ...schema.entitySets], [])
9773
- .find((e) => e.name === name);
9774
- return this.memo.byName.entitySet[name];
9917
+ .find((e) => e.name === name));
9918
+ }
9919
+ return this.memo.byName.entitySet.get(name);
9775
9920
  }
9776
9921
  findModelByName(name) {
9777
9922
  var _a;
@@ -9787,36 +9932,35 @@ class ODataApi {
9787
9932
  }
9788
9933
  parserForType(type, bindingType) {
9789
9934
  const key = bindingType !== undefined ? `${bindingType}/${type}` : type;
9790
- if (!(key in this.memo.forType.parser)) {
9935
+ if (!this.memo.forType.parser.has(key)) {
9791
9936
  if (type in this.parsers) {
9792
9937
  // Edm, Base Parsers
9793
- this.memo.forType.parser[key] = this.parsers[type];
9938
+ this.memo.forType.parser.set(key, this.parsers[type]);
9794
9939
  }
9795
9940
  else if (!type.startsWith('Edm.')) {
9796
9941
  // EnumType, ComplexType and EntityType Parsers
9797
9942
  let value = this.findCallableForType(type, bindingType) ||
9798
9943
  this.findEnumTypeForType(type) ||
9799
9944
  this.findStructuredTypeForType(type);
9800
- this.memo.forType.parser[key] = value === null || value === void 0 ? void 0 : value.parser;
9945
+ this.memo.forType.parser.set(key, value === null || value === void 0 ? void 0 : value.parser);
9801
9946
  }
9802
9947
  else {
9803
9948
  // None Parser
9804
- this.memo.forType.parser[key] = NONE_PARSER;
9949
+ this.memo.forType.parser.set(key, NONE_PARSER);
9805
9950
  }
9806
9951
  }
9807
- return this.memo.forType.parser[key];
9952
+ return this.memo.forType.parser.get(key);
9808
9953
  }
9809
9954
  findOptionsForType(type) {
9810
9955
  var _a;
9811
9956
  // Strucutred Options
9812
- if (!(type in this.memo.forType.options)) {
9957
+ if (!this.memo.forType.options.has(type)) {
9813
9958
  let st = this.findStructuredTypeForType(type);
9814
- this.memo.forType.options[type] =
9815
- st !== undefined && st.model !== undefined && ((_a = st.model) === null || _a === void 0 ? void 0 : _a.meta) !== null
9816
- ? st.model.meta
9817
- : undefined;
9959
+ this.memo.forType.options.set(type, st !== undefined && st.model !== undefined && ((_a = st.model) === null || _a === void 0 ? void 0 : _a.meta) !== null
9960
+ ? st.model.meta
9961
+ : undefined);
9818
9962
  }
9819
- return this.memo.forType.options[type];
9963
+ return this.memo.forType.options.get(type);
9820
9964
  }
9821
9965
  }
9822
9966
 
@@ -10278,9 +10422,9 @@ class ODataClient {
10278
10422
  return this.request('PUT', resource, addBody(options, body));
10279
10423
  }
10280
10424
  }
10281
- 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 });
10282
- ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataClient, providedIn: 'root' });
10283
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataClient, decorators: [{
10425
+ ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataSettings }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
10426
+ ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataClient, providedIn: 'root' });
10427
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataClient, decorators: [{
10284
10428
  type: Injectable,
10285
10429
  args: [{
10286
10430
  providedIn: 'root',
@@ -10393,7 +10537,7 @@ class ODataEntitySetService extends ODataEntityService {
10393
10537
  update(key, attrs, options) {
10394
10538
  const res = this.entity(key);
10395
10539
  if (!res.hasKey())
10396
- return throwError('Resource without key');
10540
+ return throwError(() => new Error('update: Resource without key'));
10397
10541
  return res.update(attrs, options);
10398
10542
  }
10399
10543
  /**
@@ -10406,7 +10550,7 @@ class ODataEntitySetService extends ODataEntityService {
10406
10550
  modify(key, attrs, options) {
10407
10551
  const res = this.entity(key);
10408
10552
  if (!res.hasKey())
10409
- return throwError('Resource without key');
10553
+ return throwError(() => new Error('modify: Resource without key'));
10410
10554
  return res.modify(attrs, options);
10411
10555
  }
10412
10556
  /**
@@ -10418,7 +10562,7 @@ class ODataEntitySetService extends ODataEntityService {
10418
10562
  destroy(key, options) {
10419
10563
  const res = this.entity(key);
10420
10564
  if (!res.hasKey())
10421
- return throwError('Resource without key');
10565
+ return throwError(() => new Error('destroy: Resource without key'));
10422
10566
  return res.destroy(options);
10423
10567
  }
10424
10568
  //#region Shortcuts
@@ -10449,12 +10593,12 @@ class ODataEntitySetService extends ODataEntityService {
10449
10593
  var { etag, method } = _a, options = __rest(_a, ["etag", "method"]);
10450
10594
  let schema = this.structuredTypeSchema;
10451
10595
  if (method === undefined && schema !== undefined && schema.isCompoundKey())
10452
- return throwError('Composite key require a specific method, use create/update/patch');
10596
+ return throwError(() => new Error('save: Composite key require a specific method, use create/update/patch'));
10453
10597
  let key = schema && schema.resolveKey(attrs);
10454
10598
  if (method === undefined)
10455
10599
  method = key !== undefined ? 'update' : 'create';
10456
10600
  if ((method === 'update' || method === 'modify') && key === undefined)
10457
- return throwError("Can't update/patch entity without key");
10601
+ return throwError(() => new Error("save: Can't update/patch entity without key"));
10458
10602
  return method === 'create'
10459
10603
  ? this.create(attrs, options)
10460
10604
  : method === 'modify'
@@ -10532,9 +10676,9 @@ class ODataServiceFactory {
10532
10676
  })(this.client, singletonName, apiNameOrEntityType);
10533
10677
  }
10534
10678
  }
10535
- ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10536
- ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataServiceFactory });
10537
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataServiceFactory, decorators: [{
10679
+ ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10680
+ ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataServiceFactory });
10681
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataServiceFactory, decorators: [{
10538
10682
  type: Injectable
10539
10683
  }], ctorParameters: function () { return [{ type: ODataClient }]; } });
10540
10684
 
@@ -10558,10 +10702,10 @@ class ODataModule {
10558
10702
  };
10559
10703
  }
10560
10704
  }
10561
- ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10562
- ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10563
- ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10564
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ODataModule, decorators: [{
10705
+ ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10706
+ ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10707
+ ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10708
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ODataModule, decorators: [{
10565
10709
  type: NgModule,
10566
10710
  args: [{
10567
10711
  imports: [HttpClientModule],