angular-odata 0.95.0 → 0.99.5

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 (81) hide show
  1. package/README.md +31 -25
  2. package/esm2020/lib/cache/cache.mjs +2 -2
  3. package/esm2020/lib/client.mjs +3 -3
  4. package/esm2020/lib/models/collection.mjs +53 -48
  5. package/esm2020/lib/models/model.mjs +33 -37
  6. package/esm2020/lib/models/options.mjs +35 -14
  7. package/esm2020/lib/module.mjs +4 -4
  8. package/esm2020/lib/resources/query/builder.mjs +2 -1
  9. package/esm2020/lib/resources/query/expressions/base.mjs +20 -0
  10. package/esm2020/lib/resources/query/expressions/compute.mjs +45 -0
  11. package/esm2020/lib/resources/query/expressions/expand.mjs +121 -0
  12. package/esm2020/lib/resources/query/expressions/filter.mjs +160 -0
  13. package/esm2020/lib/resources/query/expressions/index.mjs +7 -0
  14. package/esm2020/lib/resources/query/expressions/orderby.mjs +62 -0
  15. package/esm2020/lib/resources/query/expressions/search.mjs +125 -0
  16. package/esm2020/lib/resources/query/expressions/select.mjs +37 -0
  17. package/esm2020/lib/resources/query/expressions/syntax.mjs +404 -0
  18. package/esm2020/lib/resources/query/handlers.mjs +22 -20
  19. package/esm2020/lib/resources/query/options.mjs +34 -37
  20. package/esm2020/lib/resources/resource.mjs +6 -14
  21. package/esm2020/lib/resources/types/action.mjs +4 -1
  22. package/esm2020/lib/resources/types/batch.mjs +36 -10
  23. package/esm2020/lib/resources/types/count.mjs +4 -1
  24. package/esm2020/lib/resources/types/entity-set.mjs +4 -1
  25. package/esm2020/lib/resources/types/entity.mjs +6 -3
  26. package/esm2020/lib/resources/types/function.mjs +4 -1
  27. package/esm2020/lib/resources/types/media.mjs +4 -1
  28. package/esm2020/lib/resources/types/metadata.mjs +4 -1
  29. package/esm2020/lib/resources/types/navigation-property.mjs +4 -1
  30. package/esm2020/lib/resources/types/property.mjs +4 -1
  31. package/esm2020/lib/resources/types/reference.mjs +4 -1
  32. package/esm2020/lib/resources/types/singleton.mjs +4 -1
  33. package/esm2020/lib/resources/types/value.mjs +4 -1
  34. package/esm2020/lib/schema/element.mjs +12 -2
  35. package/esm2020/lib/schema/enum-type.mjs +9 -1
  36. package/esm2020/lib/schema/structured-type.mjs +11 -2
  37. package/esm2020/lib/services/entity-set.mjs +6 -6
  38. package/esm2020/lib/services/factory.mjs +3 -3
  39. package/esm2020/lib/types.mjs +2 -1
  40. package/esm2020/lib/utils/objects.mjs +5 -1
  41. package/fesm2015/angular-odata.mjs +751 -297
  42. package/fesm2015/angular-odata.mjs.map +1 -1
  43. package/fesm2020/angular-odata.mjs +750 -301
  44. package/fesm2020/angular-odata.mjs.map +1 -1
  45. package/lib/models/collection.d.ts +4 -2
  46. package/lib/models/model.d.ts +1 -1
  47. package/lib/models/options.d.ts +12 -10
  48. package/lib/resources/query/builder.d.ts +1 -0
  49. package/lib/resources/query/expressions/base.d.ts +20 -0
  50. package/lib/resources/query/expressions/compute.d.ts +27 -0
  51. package/lib/resources/query/expressions/expand.d.ts +68 -0
  52. package/lib/resources/query/expressions/filter.d.ts +59 -0
  53. package/lib/resources/query/expressions/index.d.ts +6 -0
  54. package/lib/resources/query/expressions/orderby.d.ts +39 -0
  55. package/lib/resources/query/expressions/search.d.ts +50 -0
  56. package/lib/resources/query/expressions/select.d.ts +22 -0
  57. package/lib/resources/query/{syntax.d.ts → expressions/syntax.d.ts} +21 -9
  58. package/lib/resources/query/handlers.d.ts +27 -12
  59. package/lib/resources/query/options.d.ts +10 -8
  60. package/lib/resources/resource.d.ts +2 -1
  61. package/lib/resources/types/action.d.ts +1 -0
  62. package/lib/resources/types/batch.d.ts +10 -0
  63. package/lib/resources/types/count.d.ts +1 -0
  64. package/lib/resources/types/entity-set.d.ts +1 -0
  65. package/lib/resources/types/entity.d.ts +1 -0
  66. package/lib/resources/types/function.d.ts +1 -0
  67. package/lib/resources/types/media.d.ts +1 -0
  68. package/lib/resources/types/metadata.d.ts +1 -0
  69. package/lib/resources/types/navigation-property.d.ts +1 -0
  70. package/lib/resources/types/property.d.ts +1 -0
  71. package/lib/resources/types/reference.d.ts +1 -0
  72. package/lib/resources/types/singleton.d.ts +1 -0
  73. package/lib/resources/types/value.d.ts +1 -0
  74. package/lib/schema/element.d.ts +7 -1
  75. package/lib/schema/enum-type.d.ts +6 -0
  76. package/lib/schema/structured-type.d.ts +7 -1
  77. package/lib/types.d.ts +1 -0
  78. package/package.json +1 -1
  79. package/esm2020/lib/resources/query/expressions.mjs +0 -207
  80. package/esm2020/lib/resources/query/syntax.mjs +0 -406
  81. package/lib/resources/query/expressions.d.ts +0 -63
@@ -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' ||
@@ -746,6 +747,7 @@ function buildExpand(expands, { aliases, escape = false }) {
746
747
  case 'levels':
747
748
  case 'count':
748
749
  case 'top':
750
+ case 'skip':
749
751
  value = `${expands[key]}`;
750
752
  break;
751
753
  default:
@@ -1332,6 +1334,10 @@ const Objects = {
1332
1334
  if (typeof target != 'object' || target == null) {
1333
1335
  return target;
1334
1336
  }
1337
+ if (Types.isObject(target) && 'clone' in target) {
1338
+ // target is a cloneable object
1339
+ return target.clone();
1340
+ }
1335
1341
  const type = Types.rawType(target);
1336
1342
  let cloneTarget = null;
1337
1343
  if (map.get(target)) {
@@ -1438,22 +1444,57 @@ const Urls = {
1438
1444
  },
1439
1445
  };
1440
1446
 
1441
- //export type Field<T> = keyof T | Funcs<keyof T>;
1447
+ class Expression {
1448
+ constructor({ children, } = {}) {
1449
+ this._children = children || [];
1450
+ }
1451
+ get [Symbol.toStringTag]() {
1452
+ return 'Expression';
1453
+ }
1454
+ children() {
1455
+ return this._children;
1456
+ }
1457
+ length() {
1458
+ return this._children.length;
1459
+ }
1460
+ toJSON() {
1461
+ return {
1462
+ children: this._children.map((c) => c.toJSON()),
1463
+ };
1464
+ }
1465
+ }
1466
+
1442
1467
  class Field$1 {
1443
1468
  constructor(name = '') {
1444
1469
  this.name = name;
1445
1470
  }
1446
- static factory() {
1447
- const h = new Field$1();
1448
- return new Proxy({ _name: '' }, h);
1471
+ static factory(name = '') {
1472
+ return new Proxy({ _name: name }, new Field$1());
1449
1473
  }
1450
- get(target, p) {
1474
+ get(target, key) {
1451
1475
  let name = target['_name'];
1452
- if (p === 'render') {
1476
+ if (key === 'render') {
1453
1477
  return ({ prefix }) => prefix ? `${prefix}/${name}` : name;
1454
1478
  }
1455
- name = name ? `${name}/${p}` : p;
1456
- return new Proxy({ _name: name }, this);
1479
+ else if (key === 'clone') {
1480
+ return () => Field$1.factory(name);
1481
+ }
1482
+ else if (key === Symbol.toStringTag) {
1483
+ return () => 'Field';
1484
+ }
1485
+ else if (key === 'toJSON') {
1486
+ return () => ({
1487
+ $type: Types.rawType(this),
1488
+ name: name,
1489
+ });
1490
+ }
1491
+ else {
1492
+ name = name ? `${name}/${key}` : key;
1493
+ return new Proxy({ _name: name }, this);
1494
+ }
1495
+ }
1496
+ has(target, key) {
1497
+ return ['toJSON', 'clone', 'render'].includes(key) || key in target;
1457
1498
  }
1458
1499
  }
1459
1500
  function applyMixins(derivedCtor, constructors) {
@@ -1492,6 +1533,7 @@ class Function {
1492
1533
  }
1493
1534
  toJSON() {
1494
1535
  return {
1536
+ $type: Types.rawType(this),
1495
1537
  name: this.name,
1496
1538
  values: this.values,
1497
1539
  normalize: this.normalize,
@@ -1500,12 +1542,15 @@ class Function {
1500
1542
  render({ aliases, escape, prefix, }) {
1501
1543
  let [field, ...values] = this.values;
1502
1544
  field = render(field, { aliases, escape, prefix });
1503
- let params = [
1545
+ const params = [
1504
1546
  field,
1505
1547
  ...values.map((v) => render(v, { aliases, escape, prefix, normalize: this.normalize })),
1506
1548
  ];
1507
1549
  return `${this.name}(${params.join(', ')})`;
1508
1550
  }
1551
+ clone() {
1552
+ return new Function(this.name, this.values.map((v) => Objects.clone(v)), this.normalize, this.escape);
1553
+ }
1509
1554
  }
1510
1555
  class StringAndCollectionFunctions {
1511
1556
  concat(field, value, normalize) {
@@ -1646,6 +1691,7 @@ class Operator {
1646
1691
  }
1647
1692
  toJSON() {
1648
1693
  return {
1694
+ $type: Types.rawType(this),
1649
1695
  op: this.op,
1650
1696
  values: this.values,
1651
1697
  normalize: this.normalize,
@@ -1674,6 +1720,9 @@ class Operator {
1674
1720
  }
1675
1721
  return `${this.op}(${left})`;
1676
1722
  }
1723
+ clone() {
1724
+ return new Operator(this.op, this.values.map((v) => Objects.clone(v)), this.normalize);
1725
+ }
1677
1726
  }
1678
1727
  class LogicalOperators {
1679
1728
  eq(left, right, normalize) {
@@ -1741,44 +1790,15 @@ class Grouping {
1741
1790
  }
1742
1791
  toJSON() {
1743
1792
  return {
1793
+ $type: Types.rawType(this),
1744
1794
  group: this.group.toJSON(),
1745
1795
  };
1746
1796
  }
1747
1797
  render({ aliases, escape, prefix, }) {
1748
1798
  return `(${render(this.group, { aliases, escape, prefix })})`;
1749
1799
  }
1750
- }
1751
- /*
1752
- export class Navigation<T, N> implements Renderable {
1753
- constructor(protected field: T, protected value: Field<N>) {}
1754
-
1755
- get [Symbol.toStringTag]() {
1756
- return 'Navigation';
1757
- }
1758
-
1759
- toJSON() {
1760
- return {
1761
- field: this.field,
1762
- value: this.value,
1763
- };
1764
- }
1765
-
1766
- render({
1767
- aliases,
1768
- escape,
1769
- prefix,
1770
- }: {
1771
- aliases?: QueryCustomType[];
1772
- escape?: boolean;
1773
- prefix?: string;
1774
- }): string {
1775
- return `${this.field}/${render(this.value, { aliases, escape, prefix })}`;
1776
- }
1777
- }
1778
- */
1779
- class GroupingOperators {
1780
- grouping(value) {
1781
- return new Grouping(value);
1800
+ clone() {
1801
+ return new Grouping(Objects.clone(this.group));
1782
1802
  }
1783
1803
  }
1784
1804
  class Lambda {
@@ -1792,6 +1812,7 @@ class Lambda {
1792
1812
  }
1793
1813
  toJSON() {
1794
1814
  return {
1815
+ $type: Types.rawType(this),
1795
1816
  op: this.op,
1796
1817
  values: this.values,
1797
1818
  alias: this.alias,
@@ -1807,6 +1828,9 @@ class Lambda {
1807
1828
  prefix: alias,
1808
1829
  })})`;
1809
1830
  }
1831
+ clone() {
1832
+ return new Lambda(this.op, this.values.map((v) => Objects.clone(v)), this.alias);
1833
+ }
1810
1834
  }
1811
1835
  class LambdaOperators {
1812
1836
  any(field, value, alias) {
@@ -1821,7 +1845,6 @@ class ODataOperators {
1821
1845
  applyMixins(ODataOperators, [
1822
1846
  LogicalOperators,
1823
1847
  ArithmeticOperators,
1824
- GroupingOperators,
1825
1848
  LambdaOperators,
1826
1849
  ]);
1827
1850
  const operators = new ODataOperators();
@@ -1843,34 +1866,68 @@ class ODataSyntax {
1843
1866
  applyMixins(ODataSyntax, [ODataOperators, ODataFunctions]);
1844
1867
  const syntax = new ODataSyntax();
1845
1868
 
1846
- class Expression {
1869
+ class ComputeExpression extends Expression {
1870
+ constructor({ children, names, } = {}) {
1871
+ super({ children });
1872
+ this.names = names || [];
1873
+ }
1874
+ static e() {
1875
+ return new ComputeExpression();
1876
+ }
1877
+ static s() {
1878
+ return Field$1.factory();
1879
+ }
1880
+ static compute(opts, current) {
1881
+ return opts({
1882
+ s: ComputeExpression.s(),
1883
+ e: ComputeExpression.e,
1884
+ }, current);
1885
+ }
1886
+ render({ aliases, escape, prefix, } = {}) {
1887
+ let children = this._children.map((n) => n.render({ aliases, escape, prefix }));
1888
+ return this.names
1889
+ .map((name, index) => `${children[index]} as ${name}`)
1890
+ .join(',');
1891
+ }
1892
+ clone() {
1893
+ return new ComputeExpression({
1894
+ children: this._children.map((c) => c.clone()),
1895
+ names: [...this.names],
1896
+ });
1897
+ }
1898
+ _add(name, node) {
1899
+ this.names.push(name);
1900
+ this._children.push(node);
1901
+ return this;
1902
+ }
1903
+ field(name, opts) {
1904
+ const node = opts({
1905
+ o: operators,
1906
+ f: functions,
1907
+ });
1908
+ return this._add(name, node);
1909
+ }
1910
+ }
1911
+
1912
+ class FilterExpression extends Expression {
1847
1913
  constructor({ children, connector, negated, } = {}) {
1848
- this._children = children || [];
1914
+ super({ children });
1849
1915
  this._connector = connector || 'and';
1850
1916
  this._negated = negated || false;
1851
1917
  }
1852
- get [Symbol.toStringTag]() {
1853
- return 'Expression';
1854
- }
1855
1918
  static s() {
1856
1919
  return Field$1.factory();
1857
1920
  }
1858
1921
  static e(connector = 'and') {
1859
- return new Expression({ connector });
1860
- }
1861
- static o() {
1862
- return operators;
1922
+ return new FilterExpression({ connector });
1863
1923
  }
1864
- static f() {
1865
- return functions;
1866
- }
1867
- static filter(opts) {
1924
+ static filter(opts, current) {
1868
1925
  return opts({
1869
- s: Expression.s(),
1870
- e: Expression.e,
1871
- o: Expression.o(),
1872
- f: Expression.f(),
1873
- });
1926
+ s: FilterExpression.s(),
1927
+ e: FilterExpression.e,
1928
+ o: operators,
1929
+ f: functions,
1930
+ }, current);
1874
1931
  }
1875
1932
  toJSON() {
1876
1933
  return {
@@ -1879,18 +1936,12 @@ class Expression {
1879
1936
  negated: this._negated,
1880
1937
  };
1881
1938
  }
1882
- children() {
1883
- return this._children;
1884
- }
1885
1939
  connector() {
1886
1940
  return this._connector;
1887
1941
  }
1888
1942
  negated() {
1889
1943
  return this._negated;
1890
1944
  }
1891
- length() {
1892
- return this._children.length;
1893
- }
1894
1945
  render({ aliases, escape, prefix, } = {}) {
1895
1946
  let content = this._children
1896
1947
  .map((n) => n.render({ aliases, escape, prefix }))
@@ -1900,6 +1951,13 @@ class Expression {
1900
1951
  }
1901
1952
  return content;
1902
1953
  }
1954
+ clone() {
1955
+ return new FilterExpression({
1956
+ children: this._children.map((c) => c.clone()),
1957
+ connector: this._connector,
1958
+ negated: this._negated,
1959
+ });
1960
+ }
1903
1961
  _add(node, connector) {
1904
1962
  if (connector !== undefined && this._connector !== connector) {
1905
1963
  let children = [];
@@ -1908,37 +1966,37 @@ class Expression {
1908
1966
  children = [...this._children];
1909
1967
  }
1910
1968
  else {
1911
- let exp = new Expression({
1969
+ let exp = new FilterExpression({
1912
1970
  children: this._children,
1913
1971
  connector: this._connector,
1914
1972
  negated: this._negated,
1915
1973
  });
1916
1974
  if (exp.length() > 1) {
1917
- children.push(syntax.grouping(exp));
1975
+ children.push(new Grouping(exp));
1918
1976
  }
1919
1977
  else {
1920
1978
  children.push(exp);
1921
1979
  }
1922
1980
  }
1923
1981
  }
1924
- if (node instanceof Expression &&
1982
+ if (node instanceof FilterExpression &&
1925
1983
  (node.connector() === connector || node.length() === 1)) {
1926
1984
  children = [...children, ...node.children()];
1927
1985
  }
1928
1986
  else {
1929
- children.push(syntax.grouping(node));
1987
+ children.push(new Grouping(node));
1930
1988
  }
1931
1989
  this._connector = connector;
1932
1990
  this._children = children;
1933
1991
  }
1934
- else if (node instanceof Expression &&
1992
+ else if (node instanceof FilterExpression &&
1935
1993
  !node.negated() &&
1936
1994
  (node.connector() === connector || node.length() === 1)) {
1937
1995
  this._children = [...this._children, ...node.children()];
1938
1996
  }
1939
1997
  else {
1940
- this._children.push(node instanceof Expression && !node.negated()
1941
- ? syntax.grouping(node)
1998
+ this._children.push(node instanceof FilterExpression && !node.negated()
1999
+ ? new Grouping(node)
1942
2000
  : node);
1943
2001
  }
1944
2002
  return this;
@@ -1950,7 +2008,7 @@ class Expression {
1950
2008
  return this._add(exp, 'and');
1951
2009
  }
1952
2010
  not(exp) {
1953
- const notExp = new Expression({
2011
+ const notExp = new FilterExpression({
1954
2012
  children: exp.children(),
1955
2013
  connector: exp.connector(),
1956
2014
  negated: true,
@@ -1993,14 +2051,14 @@ class Expression {
1993
2051
  any(left, opts, alias) {
1994
2052
  const exp = opts({
1995
2053
  s: Field$1.factory(),
1996
- e: Expression.e,
2054
+ e: FilterExpression.e,
1997
2055
  });
1998
2056
  return this._add(syntax.any(left, exp, alias));
1999
2057
  }
2000
2058
  all(left, opts, alias) {
2001
2059
  const exp = opts({
2002
2060
  s: Field$1.factory(),
2003
- e: Expression.e,
2061
+ e: FilterExpression.e,
2004
2062
  });
2005
2063
  return this._add(syntax.all(left, exp, alias));
2006
2064
  }
@@ -2008,45 +2066,336 @@ class Expression {
2008
2066
  return this._add(syntax.isof(left, type));
2009
2067
  }
2010
2068
  }
2011
- /*
2012
- export class FilterExpression<T> extends Expression<T> {
2013
- constructor({
2014
- children,
2015
- connector,
2016
- negated,
2017
- }: {
2018
- children?: Renderable[];
2019
- connector?: Connector;
2020
- negated?: boolean;
2021
- } = {}) {
2022
- super({ children, connector, negated });
2023
- }
2024
-
2025
- get [Symbol.toStringTag]() {
2026
- return 'FilterExpression';
2027
- }
2028
2069
 
2029
- static e<T>() {
2030
- return new FilterExpression<T>({ connector: Connector.AND });
2031
- }
2070
+ class OrderByField {
2071
+ constructor(field, order) {
2072
+ this.field = field;
2073
+ this.order = order;
2074
+ }
2075
+ get [Symbol.toStringTag]() {
2076
+ return 'OrderByField';
2077
+ }
2078
+ toJSON() {
2079
+ return {
2080
+ field: this.field.toJSON(),
2081
+ order: this.order,
2082
+ };
2083
+ }
2084
+ render({ aliases, escape, prefix, }) {
2085
+ return `${render(this.field, { aliases, escape, prefix })} ${this.order}`;
2086
+ }
2087
+ clone() {
2088
+ return new OrderByField(this.field.clone(), this.order);
2089
+ }
2090
+ }
2091
+ class OrderByExpression extends Expression {
2092
+ constructor({ children, } = {}) {
2093
+ super({ children });
2094
+ }
2095
+ static e() {
2096
+ return new OrderByExpression();
2097
+ }
2098
+ static s() {
2099
+ return Field$1.factory();
2100
+ }
2101
+ static orderBy(opts, current) {
2102
+ return opts({
2103
+ s: OrderByExpression.s(),
2104
+ e: OrderByExpression.e,
2105
+ }, current);
2106
+ }
2107
+ _add(node) {
2108
+ this._children.push(node);
2109
+ return this;
2110
+ }
2111
+ render({ aliases, escape, prefix, } = {}) {
2112
+ let content = this._children
2113
+ .map((n) => n.render({ aliases, escape, prefix }))
2114
+ .join(`,`);
2115
+ return content;
2116
+ }
2117
+ clone() {
2118
+ return new OrderByExpression({
2119
+ children: this._children.map((c) => c.clone()),
2120
+ });
2121
+ }
2122
+ ascending(field) {
2123
+ return this._add(new OrderByField(field, 'asc'));
2124
+ }
2125
+ descending(field) {
2126
+ return this._add(new OrderByField(field, 'desc'));
2127
+ }
2128
+ }
2032
2129
 
2033
- static and<T>() {
2034
- return new FilterExpression<T>({ connector: Connector.AND });
2035
- }
2130
+ class SearchTerm {
2131
+ constructor(value) {
2132
+ this.value = value;
2133
+ }
2134
+ get [Symbol.toStringTag]() {
2135
+ return 'SearchTerm';
2136
+ }
2137
+ toJSON() {
2138
+ return {
2139
+ $type: Types.rawType(this),
2140
+ value: this.value,
2141
+ };
2142
+ }
2143
+ render({ aliases, escape, prefix, }) {
2144
+ return `${render(this.value, { aliases, escape, prefix })}`;
2145
+ }
2146
+ clone() {
2147
+ return new SearchTerm(this.value);
2148
+ }
2149
+ }
2150
+ class SearchExpression extends Expression {
2151
+ constructor({ children, connector, negated, } = {}) {
2152
+ super({ children });
2153
+ this._connector = connector || 'AND';
2154
+ this._negated = negated || false;
2155
+ }
2156
+ static e(connector = 'AND') {
2157
+ return new SearchExpression({ connector });
2158
+ }
2159
+ static search(opts, current) {
2160
+ return opts({
2161
+ e: SearchExpression.e,
2162
+ }, current);
2163
+ }
2164
+ _add(node, connector) {
2165
+ if (connector !== undefined && this._connector !== connector) {
2166
+ let children = [];
2167
+ if (this._children.length > 0) {
2168
+ if (this._children.length === 1) {
2169
+ children = [...this._children];
2170
+ }
2171
+ else {
2172
+ let exp = new SearchExpression({
2173
+ children: this._children,
2174
+ connector: this._connector,
2175
+ negated: this._negated,
2176
+ });
2177
+ if (exp.length() > 1) {
2178
+ children.push(new Grouping(exp));
2179
+ }
2180
+ else {
2181
+ children.push(exp);
2182
+ }
2183
+ }
2184
+ }
2185
+ if (node instanceof SearchExpression &&
2186
+ (node.connector() === connector || node.length() === 1)) {
2187
+ children = [...children, ...node.children()];
2188
+ }
2189
+ else {
2190
+ children.push(new Grouping(node));
2191
+ }
2192
+ this._connector = connector;
2193
+ this._children = children;
2194
+ }
2195
+ else if (node instanceof SearchExpression &&
2196
+ !node.negated() &&
2197
+ (node.connector() === connector || node.length() === 1)) {
2198
+ this._children = [...this._children, ...node.children()];
2199
+ }
2200
+ else {
2201
+ this._children.push(node instanceof SearchExpression && !node.negated()
2202
+ ? new Grouping(node)
2203
+ : node);
2204
+ }
2205
+ return this;
2206
+ }
2207
+ render({ aliases, escape, prefix, } = {}) {
2208
+ let content = this._children
2209
+ .map((n) => n.render({ aliases, escape, prefix }))
2210
+ .join(` ${this._connector} `);
2211
+ return content;
2212
+ }
2213
+ clone() {
2214
+ return new SearchExpression({
2215
+ children: this._children.map((c) => c.clone()),
2216
+ connector: this._connector,
2217
+ negated: this._negated,
2218
+ });
2219
+ }
2220
+ toJSON() {
2221
+ return {
2222
+ children: this._children.map((c) => c.toJSON()),
2223
+ connector: this._connector,
2224
+ negated: this._negated,
2225
+ };
2226
+ }
2227
+ connector() {
2228
+ return this._connector;
2229
+ }
2230
+ negated() {
2231
+ return this._negated;
2232
+ }
2233
+ or(exp) {
2234
+ return this._add(exp, 'OR');
2235
+ }
2236
+ and(exp) {
2237
+ return this._add(exp, 'AND');
2238
+ }
2239
+ not(exp) {
2240
+ const notExp = new SearchExpression({
2241
+ children: exp.children(),
2242
+ connector: exp.connector(),
2243
+ negated: true,
2244
+ });
2245
+ return this._add(notExp, this._connector);
2246
+ }
2247
+ term(value) {
2248
+ return this._add(new SearchTerm(value));
2249
+ }
2250
+ }
2036
2251
 
2037
- static or<T>() {
2038
- return new FilterExpression<T>({ connector: Connector.OR });
2039
- }
2252
+ class SelectExpression extends Expression {
2253
+ constructor({ children, } = {}) {
2254
+ super({ children });
2255
+ }
2256
+ static e() {
2257
+ return new SelectExpression();
2258
+ }
2259
+ static s() {
2260
+ return Field$1.factory();
2261
+ }
2262
+ static select(builder, current) {
2263
+ return builder({
2264
+ s: SelectExpression.s(),
2265
+ e: SelectExpression.e,
2266
+ }, current);
2267
+ }
2268
+ render({ aliases, escape, prefix, } = {}) {
2269
+ return this._children
2270
+ .map((n) => n.render({ aliases, escape, prefix }))
2271
+ .join(',');
2272
+ }
2273
+ clone() {
2274
+ return new SelectExpression({
2275
+ children: this._children.map((c) => c.clone()),
2276
+ });
2277
+ }
2278
+ _add(node) {
2279
+ this._children.push(node);
2280
+ return this;
2281
+ }
2282
+ field(field) {
2283
+ return this._add(field);
2284
+ }
2285
+ }
2040
2286
 
2041
- static not<T>(exp: FilterExpression<T>) {
2042
- return new FilterExpression<T>({
2043
- children: exp.children(),
2044
- connector: exp.connector(),
2045
- negated: true,
2046
- });
2047
- }
2287
+ class ExpandField {
2288
+ constructor(field, values = {}) {
2289
+ this.field = field;
2290
+ this.values = values;
2291
+ }
2292
+ get [Symbol.toStringTag]() {
2293
+ return 'ExpandField';
2294
+ }
2295
+ toJSON() {
2296
+ return {
2297
+ field: this.field.toJSON(),
2298
+ };
2299
+ }
2300
+ render({ aliases, escape, prefix, }) {
2301
+ const params = [
2302
+ QueryOptionNames.select,
2303
+ QueryOptionNames.expand,
2304
+ QueryOptionNames.filter,
2305
+ QueryOptionNames.search,
2306
+ QueryOptionNames.orderBy,
2307
+ QueryOptionNames.skip,
2308
+ QueryOptionNames.top,
2309
+ QueryOptionNames.levels,
2310
+ ]
2311
+ .filter((key) => !Types.isEmpty(this.values[key]))
2312
+ .reduce((acc, key) => {
2313
+ let value = this.values[key];
2314
+ if (Types.rawType(value).endsWith('Expression')) {
2315
+ value = value.render({ aliases, prefix, escape });
2316
+ }
2317
+ return Object.assign(acc, { [key]: value });
2318
+ }, {});
2319
+ let expand = `${render(this.field, { aliases, escape, prefix })}`;
2320
+ if (!Types.isEmpty(params)) {
2321
+ expand = `${expand}(${Object.keys(params)
2322
+ .map((key) => `$${key}=${params[key]}`)
2323
+ .join(';')})`;
2324
+ }
2325
+ return expand;
2326
+ }
2327
+ clone() {
2328
+ const values = Object.keys(this.values).reduce((acc, key) => Object.assign(acc, { [key]: Objects.clone(this.values[key]) }), {});
2329
+ return new ExpandField(this.field.clone(), values);
2330
+ }
2331
+ select(opts) {
2332
+ return this.option(QueryOptionNames.select, SelectExpression.select(opts, this.values[QueryOptionNames.select]));
2333
+ }
2334
+ expand(opts) {
2335
+ return this.option(QueryOptionNames.expand, ExpandExpression.expand(opts, this.values[QueryOptionNames.expand]));
2336
+ }
2337
+ filter(opts) {
2338
+ return this.option(QueryOptionNames.filter, FilterExpression.filter(opts, this.values[QueryOptionNames.filter]));
2339
+ }
2340
+ search(opts) {
2341
+ return this.option(QueryOptionNames.search, SearchExpression.search(opts, this.values[QueryOptionNames.search]));
2342
+ }
2343
+ orderBy(opts) {
2344
+ return this.option(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts, this.values[QueryOptionNames.orderBy]));
2345
+ }
2346
+ skip(n) {
2347
+ return this.option(QueryOptionNames.skip, n);
2348
+ }
2349
+ top(n) {
2350
+ return this.option(QueryOptionNames.top, n);
2351
+ }
2352
+ levels(n) {
2353
+ return this.option(QueryOptionNames.levels, n);
2354
+ }
2355
+ // Option Handler
2356
+ option(name, opts) {
2357
+ if (opts !== undefined)
2358
+ this.values[name] = opts;
2359
+ return this.values[name];
2360
+ }
2361
+ }
2362
+ class ExpandExpression extends Expression {
2363
+ constructor({ children, } = {}) {
2364
+ super({ children });
2365
+ }
2366
+ static e() {
2367
+ return new ExpandExpression();
2368
+ }
2369
+ static s() {
2370
+ return Field$1.factory();
2371
+ }
2372
+ static expand(opts, current) {
2373
+ return opts({
2374
+ s: ExpandExpression.s(),
2375
+ e: ExpandExpression.e,
2376
+ }, current);
2377
+ }
2378
+ render({ aliases, escape, prefix, } = {}) {
2379
+ return this._children
2380
+ .map((n) => n.render({ aliases, escape, prefix }))
2381
+ .join(',');
2382
+ }
2383
+ clone() {
2384
+ return new ExpandExpression({
2385
+ children: this._children.map((c) => c.clone()),
2386
+ });
2387
+ }
2388
+ _add(node) {
2389
+ this._children.push(node);
2390
+ return this;
2391
+ }
2392
+ field(field, opts) {
2393
+ let node = new ExpandField(field);
2394
+ if (opts !== undefined)
2395
+ opts(node);
2396
+ return this._add(node);
2397
+ }
2048
2398
  }
2049
- */
2050
2399
 
2051
2400
  class ODataQueryOptionHandler {
2052
2401
  constructor(o, n) {
@@ -2144,16 +2493,20 @@ class ODataQueryOptionsHandler {
2144
2493
  return alias(value, name);
2145
2494
  }
2146
2495
  select(opts) {
2496
+ if (Types.isFunction(opts)) {
2497
+ return this.options.expression(QueryOptionNames.select, SelectExpression.select(opts, this.options.expression(QueryOptionNames.select)));
2498
+ }
2147
2499
  return this.options.option(QueryOptionNames.select, opts);
2148
2500
  }
2149
2501
  expand(opts) {
2502
+ if (Types.isFunction(opts)) {
2503
+ return this.options.expression(QueryOptionNames.expand, ExpandExpression.expand(opts, this.options.expression(QueryOptionNames.expand)));
2504
+ }
2150
2505
  return this.options.option(QueryOptionNames.expand, opts);
2151
2506
  }
2152
2507
  compute(opts) {
2153
2508
  if (Types.isFunction(opts)) {
2154
- return this.options.expression(QueryOptionNames.compute, opts({
2155
- e: () => Expression.e(),
2156
- }));
2509
+ return this.options.expression(QueryOptionNames.compute, ComputeExpression.compute(opts, this.options.expression(QueryOptionNames.compute)));
2157
2510
  }
2158
2511
  return this.options.option(QueryOptionNames.compute, opts);
2159
2512
  }
@@ -2164,24 +2517,20 @@ class ODataQueryOptionsHandler {
2164
2517
  return this.options.option(QueryOptionNames.transform, opts);
2165
2518
  }
2166
2519
  search(opts) {
2520
+ if (Types.isFunction(opts)) {
2521
+ return this.options.expression(QueryOptionNames.search, SearchExpression.search(opts, this.options.expression(QueryOptionNames.search)));
2522
+ }
2167
2523
  return this.options.option(QueryOptionNames.search, opts);
2168
2524
  }
2169
2525
  filter(opts) {
2170
2526
  if (Types.isFunction(opts)) {
2171
- return this.options.expression(QueryOptionNames.filter, opts({
2172
- s: Expression.s(),
2173
- e: Expression.e,
2174
- o: Expression.o(),
2175
- f: Expression.f(),
2176
- }));
2527
+ return this.options.expression(QueryOptionNames.filter, FilterExpression.filter(opts, this.options.expression(QueryOptionNames.filter)));
2177
2528
  }
2178
2529
  return this.options.option(QueryOptionNames.filter, opts);
2179
2530
  }
2180
2531
  orderBy(opts) {
2181
2532
  if (Types.isFunction(opts)) {
2182
- return this.options.expression(QueryOptionNames.orderBy, opts({
2183
- e: () => Expression.e(),
2184
- }));
2533
+ return this.options.option(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts, this.options.expression(QueryOptionNames.orderBy)));
2185
2534
  }
2186
2535
  return this.options.option(QueryOptionNames.orderBy, opts);
2187
2536
  }
@@ -2209,22 +2558,22 @@ class ODataQueryOptionsHandler {
2209
2558
  }
2210
2559
  apply(query) {
2211
2560
  if (query.select !== undefined) {
2212
- this.select(query.select);
2561
+ this.options.option(QueryOptionNames.select, query.select);
2213
2562
  }
2214
2563
  if (query.expand !== undefined) {
2215
- this.expand(query.expand);
2564
+ this.options.option(QueryOptionNames.expand, query.expand);
2216
2565
  }
2217
2566
  if (query.transform !== undefined) {
2218
- this.transform(query.transform);
2567
+ this.options.option(QueryOptionNames.transform, query.transform);
2219
2568
  }
2220
2569
  if (query.search !== undefined) {
2221
- this.search(query.search);
2570
+ this.options.option(QueryOptionNames.search, query.search);
2222
2571
  }
2223
2572
  if (query.filter !== undefined) {
2224
- this.filter(query.filter);
2573
+ this.options.option(QueryOptionNames.filter, query.filter);
2225
2574
  }
2226
2575
  if (query.orderBy !== undefined) {
2227
- this.orderBy(query.orderBy);
2576
+ this.options.option(QueryOptionNames.orderBy, query.orderBy);
2228
2577
  }
2229
2578
  this.paging(query);
2230
2579
  }
@@ -2232,7 +2581,7 @@ class ODataQueryOptionsHandler {
2232
2581
 
2233
2582
  class ODataQueryOptions {
2234
2583
  constructor(options) {
2235
- this.options = options || {};
2584
+ this.values = options || {};
2236
2585
  }
2237
2586
  // Params
2238
2587
  pathAndParams(escape = false) {
@@ -2250,11 +2599,11 @@ class ODataQueryOptions {
2250
2599
  QueryOptionNames.expand,
2251
2600
  QueryOptionNames.format,
2252
2601
  ]
2253
- .filter((key) => !Types.isEmpty(this.options[key]))
2602
+ .filter((key) => !Types.isEmpty(this.values[key]))
2254
2603
  .reduce((acc, key) => {
2255
- let value = this.options[key];
2256
- if (Types.rawType(value) === 'Expression') {
2257
- value = value.render(aliases);
2604
+ let value = this.values[key];
2605
+ if (Types.rawType(value).endsWith('Expression')) {
2606
+ value = value.render({ aliases });
2258
2607
  }
2259
2608
  return Object.assign(acc, { [key]: value });
2260
2609
  }, {});
@@ -2269,63 +2618,60 @@ class ODataQueryOptions {
2269
2618
  .join('&'));
2270
2619
  }
2271
2620
  toJSON() {
2272
- return Object.keys(this.options).reduce((acc, key) => {
2273
- let value = this.options[key];
2274
- if (Types.rawType(value) === 'Expression') {
2275
- value = value.toJSON();
2276
- }
2621
+ return Object.keys(this.values).reduce((acc, key) => {
2622
+ let value = this.values[key];
2623
+ value =
2624
+ Types.isObject(value) && 'toJSON' in value ? value.toJSON() : value;
2277
2625
  return Object.assign(acc, { [key]: value });
2278
2626
  }, {});
2279
2627
  }
2280
2628
  toQueryArguments() {
2281
2629
  return {
2282
- select: this.options[QueryOptionNames.select],
2283
- expand: this.options[QueryOptionNames.expand],
2284
- transform: this.options[QueryOptionNames.transform],
2285
- compute: this.options[QueryOptionNames.compute],
2286
- search: this.options[QueryOptionNames.search],
2287
- filter: this.options[QueryOptionNames.filter],
2288
- orderBy: this.options[QueryOptionNames.orderBy],
2289
- top: this.options[QueryOptionNames.top],
2290
- skip: this.options[QueryOptionNames.skip],
2291
- skiptoken: this.options[QueryOptionNames.skiptoken],
2630
+ select: this.values[QueryOptionNames.select],
2631
+ expand: this.values[QueryOptionNames.expand],
2632
+ transform: this.values[QueryOptionNames.transform],
2633
+ compute: this.values[QueryOptionNames.compute],
2634
+ search: this.values[QueryOptionNames.search],
2635
+ filter: this.values[QueryOptionNames.filter],
2636
+ orderBy: this.values[QueryOptionNames.orderBy],
2637
+ top: this.values[QueryOptionNames.top],
2638
+ skip: this.values[QueryOptionNames.skip],
2639
+ skiptoken: this.values[QueryOptionNames.skiptoken],
2292
2640
  };
2293
2641
  }
2294
2642
  clone() {
2295
- const options = Object.keys(this.options).reduce((acc, key) => {
2296
- let value = this.options[key];
2297
- if (Types.rawType(value) !== 'Expression') {
2298
- value = Objects.clone(value);
2299
- }
2300
- return Object.assign(acc, { [key]: value });
2301
- }, {});
2643
+ const options = Object.keys(this.values).reduce((acc, key) => Object.assign(acc, { [key]: Objects.clone(this.values[key]) }), {});
2302
2644
  return new ODataQueryOptions(options);
2303
2645
  }
2304
- // Set Expression
2646
+ // Set Renderable
2305
2647
  expression(name, exp) {
2306
- return (this.options[name] = exp);
2648
+ if (exp !== undefined)
2649
+ this.values[name] = exp;
2650
+ return this.values[name];
2307
2651
  }
2308
2652
  // Option Handler
2309
2653
  option(name, opts) {
2310
2654
  if (opts !== undefined)
2311
- this.options[name] = opts;
2312
- return new ODataQueryOptionHandler(this.options, name);
2655
+ this.values[name] = opts;
2656
+ return new ODataQueryOptionHandler(this.values, name);
2313
2657
  }
2314
2658
  // Query Options tools
2315
2659
  has(name) {
2316
- return this.options[name] !== undefined;
2660
+ return this.values[name] !== undefined;
2317
2661
  }
2318
2662
  remove(...names) {
2319
- names.forEach((name) => this.option(name).clear());
2663
+ names.forEach((name) => {
2664
+ delete this.values[name];
2665
+ });
2320
2666
  }
2321
2667
  keep(...names) {
2322
- this.options = Object.keys(this.options)
2668
+ this.values = Object.keys(this.values)
2323
2669
  .filter((k) => names.indexOf(k) !== -1)
2324
- .reduce((acc, k) => Object.assign(acc, { [k]: this.options[k] }), {});
2670
+ .reduce((acc, k) => Object.assign(acc, { [k]: this.values[k] }), {});
2325
2671
  }
2326
2672
  // Clear
2327
2673
  clear() {
2328
- this.options = {};
2674
+ this.values = {};
2329
2675
  }
2330
2676
  }
2331
2677
 
@@ -2756,7 +3102,7 @@ class ODataSchemaElement extends ODataAnnotatable {
2756
3102
  return names.indexOf(type) !== -1;
2757
3103
  }
2758
3104
  /**
2759
- * Returns a boolean indicating if the structured type is a sub type of the given type.
3105
+ * Returns a boolean indicating if the structured type is a subtype of the given type.
2760
3106
  * @param type String representation of the type
2761
3107
  * @returns True if the callable is type of the given type
2762
3108
  */
@@ -2765,6 +3111,16 @@ class ODataSchemaElement extends ODataAnnotatable {
2765
3111
  return true;
2766
3112
  return false;
2767
3113
  }
3114
+ /**
3115
+ * Returns a boolean indicating if the structured type is a supertype of the given type.
3116
+ * @param type String representation of the type
3117
+ * @returns True if the callable is type of the given type
3118
+ */
3119
+ isSupertypeOf(schema) {
3120
+ if (this.isTypeOf(schema.type()))
3121
+ return true;
3122
+ return false;
3123
+ }
2768
3124
  }
2769
3125
 
2770
3126
  //https://github.com/niklasvh/base64-arraybuffer
@@ -3901,6 +4257,14 @@ class ODataEnumType extends ODataSchemaElement {
3901
4257
  findFieldByValue(value) {
3902
4258
  return this.fields().find((f) => f.value === value);
3903
4259
  }
4260
+ /**
4261
+ * Find a fields by flag.
4262
+ * @param value The value of the field
4263
+ * @returns The fields with the given flag
4264
+ */
4265
+ findFieldsByValue(value) {
4266
+ return this.fields().filter((f) => Boolean(f.value & value));
4267
+ }
3904
4268
  /**
3905
4269
  * Map the fields of the enum type.
3906
4270
  * @param mapper Function that maps the value to the new value
@@ -3972,7 +4336,7 @@ class ODataStructuredType extends ODataSchemaElement {
3972
4336
  }
3973
4337
  }
3974
4338
  /**
3975
- * Returns a boolean indicating if the structured type is a sub type of the given type.
4339
+ * Returns a boolean indicating if the structured type is a subtype of the given type.
3976
4340
  * @param type String representation of the type
3977
4341
  * @returns True if the callable is type of the given type
3978
4342
  */
@@ -3980,6 +4344,15 @@ class ODataStructuredType extends ODataSchemaElement {
3980
4344
  return (super.isSubtypeOf(schema) ||
3981
4345
  (this.parent !== undefined && this.parent.isSubtypeOf(schema)));
3982
4346
  }
4347
+ /**
4348
+ * Returns a boolean indicating if the structured type is a supertype of the given type.
4349
+ * @param type String representation of the type
4350
+ * @returns True if the callable is type of the given type
4351
+ */
4352
+ isSupertypeOf(schema) {
4353
+ return (super.isSupertypeOf(schema) ||
4354
+ this.children.some((c) => c.isSupertypeOf(schema)));
4355
+ }
3983
4356
  /**
3984
4357
  * Returns a boolean indicating if the structured type has a simple key.
3985
4358
  * @returns True if the structured type has a simple key
@@ -4262,19 +4635,12 @@ class ODataResource {
4262
4635
  other.schema !== undefined &&
4263
4636
  ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.isSubtypeOf(other.schema)));
4264
4637
  }
4265
- /*
4266
- isParentOf(other: ODataResource<any>) {
4267
- const [selfPath] = this.pathAndParams();
4268
- const [otherPath] = other.pathAndParams();
4269
- return otherPath !== selfPath && otherPath.startsWith(selfPath);
4270
- }
4271
-
4272
- isChildOf(other: ODataResource<any>) {
4273
- const [selfPath] = this.pathAndParams();
4274
- const [otherPath] = other.pathAndParams();
4275
- return otherPath !== selfPath && selfPath.startsWith(otherPath);
4638
+ isSupertypeOf(other) {
4639
+ var _a;
4640
+ return (this.schema !== undefined &&
4641
+ other.schema !== undefined &&
4642
+ ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.isSupertypeOf(other.schema)));
4276
4643
  }
4277
- */
4278
4644
  isEqualTo(other, test) {
4279
4645
  const [selfPath, selfParams] = this.pathAndParams();
4280
4646
  const [otherPath, otherParams] = other.pathAndParams();
@@ -4549,6 +4915,9 @@ class ODataActionResource extends ODataResource {
4549
4915
  }
4550
4916
  return action;
4551
4917
  }
4918
+ clone() {
4919
+ return super.clone();
4920
+ }
4552
4921
  //#endregion
4553
4922
  returnType() {
4554
4923
  var _a;
@@ -5857,15 +6226,13 @@ class ODataBatchResource extends ODataResource {
5857
6226
  segments.add(PathSegmentNames.batch, $BATCH);
5858
6227
  return new ODataBatchResource(api, { segments });
5859
6228
  }
6229
+ clone() {
6230
+ const batch = super.clone();
6231
+ batch._requests = [...this._requests];
6232
+ return batch;
6233
+ }
5860
6234
  //#endregion
5861
- /**
5862
- * Execute the batch request
5863
- * @param ctx The context for the request
5864
- * @param options The options of the batch request
5865
- * @returns The result of execute the context
5866
- */
5867
- exec(ctx, options) {
5868
- // Store original requester
6235
+ storeRequester() {
5869
6236
  const current = this.api.request;
5870
6237
  // Switch to the batch requester
5871
6238
  this.api.request = (req) => {
@@ -5876,13 +6243,31 @@ class ODataBatchResource extends ODataResource {
5876
6243
  this._requests.push(new ODataBatchRequest(req));
5877
6244
  return this._requests[this._requests.length - 1];
5878
6245
  };
6246
+ return current;
6247
+ }
6248
+ restoreRequester(handler) {
6249
+ this.api.request = handler;
6250
+ }
6251
+ /**
6252
+ * Add to batch request
6253
+ * @param ctx The context for the request
6254
+ * @returns The result of execute the context
6255
+ */
6256
+ add(ctx) {
6257
+ // Store original requester
6258
+ var handler = this.storeRequester();
5879
6259
  // Execute the context
5880
6260
  const obs$ = ctx(this);
5881
6261
  // Restore original requester
5882
- this.api.request = current;
6262
+ this.restoreRequester(handler);
6263
+ return obs$;
6264
+ }
6265
+ send(options) {
5883
6266
  if (this._requests.length >= 0) {
5884
6267
  const bound = Strings.uniqueId(BATCH_PREFIX);
5885
6268
  const requests = this._requests;
6269
+ // Clean requests
6270
+ this._requests = [];
5886
6271
  const headers = Http.mergeHttpHeaders((options && options.headers) || {}, {
5887
6272
  [ODATA_VERSION]: VERSION_4_0,
5888
6273
  [CONTENT_TYPE]: MULTIPART_MIXED_BOUNDARY + bound,
@@ -5903,6 +6288,16 @@ class ODataBatchResource extends ODataResource {
5903
6288
  ODataBatchResource.handleResponse(requests, response);
5904
6289
  });
5905
6290
  }
6291
+ }
6292
+ /**
6293
+ * Execute the batch request
6294
+ * @param ctx The context for the request
6295
+ * @param options The options of the batch request
6296
+ * @returns The result of execute the context
6297
+ */
6298
+ exec(ctx, options) {
6299
+ const obs$ = this.add(ctx);
6300
+ this.send(options);
5906
6301
  return obs$;
5907
6302
  }
5908
6303
  body() {
@@ -6031,6 +6426,9 @@ class ODataCountResource extends ODataResource {
6031
6426
  query === null || query === void 0 ? void 0 : query.keep(QueryOptionNames.filter, QueryOptionNames.search);
6032
6427
  return new ODataCountResource(api, { segments, query });
6033
6428
  }
6429
+ clone() {
6430
+ return super.clone();
6431
+ }
6034
6432
  //#endregion
6035
6433
  //#region Requests
6036
6434
  get(options) {
@@ -6083,6 +6481,9 @@ class ODataFunctionResource extends ODataResource {
6083
6481
  }
6084
6482
  return func;
6085
6483
  }
6484
+ clone() {
6485
+ return super.clone();
6486
+ }
6086
6487
  //#endregion
6087
6488
  returnType() {
6088
6489
  var _a;
@@ -6174,6 +6575,9 @@ class ODataMediaResource extends ODataResource {
6174
6575
  segments.add(PathSegmentNames.value, $VALUE);
6175
6576
  return new ODataMediaResource(api, { segments, query });
6176
6577
  }
6578
+ clone() {
6579
+ return super.clone();
6580
+ }
6177
6581
  //#endregion
6178
6582
  //#region Requests
6179
6583
  get(options) {
@@ -6226,6 +6630,9 @@ class ODataValueResource extends ODataResource {
6226
6630
  }
6227
6631
  return value;
6228
6632
  }
6633
+ clone() {
6634
+ return super.clone();
6635
+ }
6229
6636
  //#endregion
6230
6637
  //#region Requests
6231
6638
  get(options) {
@@ -6291,6 +6698,9 @@ class ODataPropertyResource extends ODataResource {
6291
6698
  }
6292
6699
  return property;
6293
6700
  }
6701
+ clone() {
6702
+ return super.clone();
6703
+ }
6294
6704
  //#endregion
6295
6705
  key(value) {
6296
6706
  const property = this.clone();
@@ -6426,6 +6836,9 @@ class ODataReferenceResource extends ODataResource {
6426
6836
  query === null || query === void 0 ? void 0 : query.clear();
6427
6837
  return new ODataReferenceResource(api, { segments, query });
6428
6838
  }
6839
+ clone() {
6840
+ return super.clone();
6841
+ }
6429
6842
  //#endregion
6430
6843
  //#region Requests
6431
6844
  post(target, options) {
@@ -6554,6 +6967,9 @@ class ODataNavigationPropertyResource extends ODataResource {
6554
6967
  }
6555
6968
  return navigation;
6556
6969
  }
6970
+ clone() {
6971
+ return super.clone();
6972
+ }
6557
6973
  //#endregion
6558
6974
  key(value) {
6559
6975
  const navigation = this.clone();
@@ -6725,6 +7141,9 @@ class ODataEntityResource extends ODataResource {
6725
7141
  query === null || query === void 0 ? void 0 : query.keep(QueryOptionNames.expand, QueryOptionNames.select, QueryOptionNames.format);
6726
7142
  return new ODataEntityResource(api, { segments, query, schema });
6727
7143
  }
7144
+ clone() {
7145
+ return super.clone();
7146
+ }
6728
7147
  //#endregion
6729
7148
  key(value) {
6730
7149
  const entity = this.clone();
@@ -6764,7 +7183,7 @@ class ODataEntityResource extends ODataResource {
6764
7183
  if (castSchema !== undefined &&
6765
7184
  baseSchema !== undefined &&
6766
7185
  !castSchema.isSubtypeOf(baseSchema))
6767
- throw new Error(`Cannot cast to ${type}`);
7186
+ throw new Error(`cast: Cannot cast to ${type}`);
6768
7187
  const segments = this.cloneSegments();
6769
7188
  segments.add(PathSegmentNames.type, type).type(type);
6770
7189
  return new ODataEntityResource(this.api, {
@@ -6805,7 +7224,7 @@ class ODataEntityResource extends ODataResource {
6805
7224
  }
6806
7225
  fetch(options) {
6807
7226
  if (!this.hasKey())
6808
- return throwError('Entity resource without key');
7227
+ return throwError(() => new Error('fetch: Entity resource without key'));
6809
7228
  return this.get(options);
6810
7229
  }
6811
7230
  fetchEntity(options) {
@@ -6825,6 +7244,9 @@ class ODataEntitySetResource extends ODataResource {
6825
7244
  segment.type(schema.type());
6826
7245
  return new ODataEntitySetResource(api, { segments, query, schema });
6827
7246
  }
7247
+ clone() {
7248
+ return super.clone();
7249
+ }
6828
7250
  //#endregion
6829
7251
  entity(key) {
6830
7252
  const entity = ODataEntityResource.factory(this.api, {
@@ -6911,6 +7333,9 @@ class ODataMetadataResource extends ODataResource {
6911
7333
  segments.add(PathSegmentNames.metadata, $METADATA);
6912
7334
  return new ODataMetadataResource(api, segments);
6913
7335
  }
7336
+ clone() {
7337
+ return super.clone();
7338
+ }
6914
7339
  //#endregion
6915
7340
  //#region Requests
6916
7341
  get(options) {
@@ -6934,6 +7359,9 @@ class ODataSingletonResource extends ODataResource {
6934
7359
  segment.type(schema.type());
6935
7360
  return new ODataSingletonResource(api, { segments, query, schema });
6936
7361
  }
7362
+ clone() {
7363
+ return super.clone();
7364
+ }
6937
7365
  //#endregion
6938
7366
  key(value) {
6939
7367
  const singleton = this.clone();
@@ -7114,6 +7542,16 @@ class ODataModelEvent {
7114
7542
  : '')
7115
7543
  .join('');
7116
7544
  }
7545
+ //Identifies the current model for the event
7546
+ get currentModel() {
7547
+ const link = this.chain.find(c => ODataModelOptions.isModel(c[0]));
7548
+ return link !== undefined ? link[0] : undefined;
7549
+ }
7550
+ //Identifies the current collection for the event
7551
+ get currentCollection() {
7552
+ const link = this.chain.find(c => ODataModelOptions.isCollection(c[0]));
7553
+ return link !== undefined ? link[0] : undefined;
7554
+ }
7117
7555
  }
7118
7556
  const BUBBLING = [
7119
7557
  'change',
@@ -7415,8 +7853,8 @@ class ODataModelOptions {
7415
7853
  attach(self, resource) {
7416
7854
  if (self._resource !== null &&
7417
7855
  resource.type() !== self._resource.type() &&
7418
- !resource.isSubtypeOf(self._resource))
7419
- throw new Error(`Can't reattach ${resource.type()} to ${self._resource.type()}`);
7856
+ !self._resource.isSubtypeOf(resource))
7857
+ throw new Error(`Can't attach ${resource.type()} to ${self._resource.type()}`);
7420
7858
  const current = self._resource;
7421
7859
  if (current === null || !current.isEqualTo(resource)) {
7422
7860
  self._resource = resource;
@@ -7444,12 +7882,7 @@ class ODataModelOptions {
7444
7882
  var _a;
7445
7883
  let resource = undefined;
7446
7884
  for (let [model, field] of ODataModelOptions.chain(child)) {
7447
- resource =
7448
- resource ||
7449
- model._resource ||
7450
- (ODataModelOptions.isModel(model)
7451
- ? model._meta.modelResourceFactory()
7452
- : model._model.meta.collectionResourceFactory());
7885
+ resource = resource || model._resource;
7453
7886
  if (resource === undefined)
7454
7887
  break;
7455
7888
  if (ODataModelOptions.isModel(model)) {
@@ -7464,7 +7897,7 @@ class ODataModelOptions {
7464
7897
  }
7465
7898
  if (field === null) {
7466
7899
  const query = (_a = model._resource) === null || _a === void 0 ? void 0 : _a.cloneQuery().toQueryArguments();
7467
- if (query !== undefined)
7900
+ if (query !== undefined && resource !== undefined)
7468
7901
  resource.query((q) => q.apply(query));
7469
7902
  continue;
7470
7903
  }
@@ -7505,7 +7938,8 @@ class ODataModelOptions {
7505
7938
  self._parent = parent;
7506
7939
  }
7507
7940
  // Resource
7508
- resource = resource || this.modelResourceFactory();
7941
+ if (self._parent === null && resource === undefined)
7942
+ resource = this.modelResourceFactory();
7509
7943
  if (resource !== undefined) {
7510
7944
  this.attach(self, resource);
7511
7945
  }
@@ -7628,14 +8062,29 @@ class ODataModelOptions {
7628
8062
  (model != undefined && model.hasChanged({ include_navigation })))));
7629
8063
  }
7630
8064
  asEntity(self, func) {
7631
- const parent = self._parent;
8065
+ // Build new resource
8066
+ const query = self.resource().cloneQuery();
8067
+ let resource = this.modelResourceFactory(query);
8068
+ if (resource === undefined)
8069
+ throw new Error('Model does not have associated Entity endpoint');
8070
+ // Store parent and resource
8071
+ const store = { parent: self._parent, resource: self._resource };
8072
+ // Replace parent and resource
7632
8073
  self._parent = null;
8074
+ self._resource = resource;
8075
+ // Execute function
7633
8076
  const result = func(self);
7634
8077
  if (result instanceof Observable) {
7635
- return result.pipe(finalize(() => (self._parent = parent)));
8078
+ return result.pipe(finalize(() => {
8079
+ // Restore parent and resource
8080
+ self._parent = store.parent;
8081
+ self._resource = store.resource;
8082
+ }));
7636
8083
  }
7637
8084
  else {
7638
- self._parent = parent;
8085
+ // Restore parent and resource
8086
+ self._parent = store.parent;
8087
+ self._resource = store.resource;
7639
8088
  return result;
7640
8089
  }
7641
8090
  }
@@ -8028,14 +8477,15 @@ class ODataCollection {
8028
8477
  if (model === undefined && Klass.model !== null)
8029
8478
  model = Klass.model;
8030
8479
  if (model === undefined)
8031
- throw new Error('Collection need model');
8480
+ throw new Error('Collection: Collection need model');
8032
8481
  this._model = model;
8033
8482
  // Parent
8034
8483
  if (parent !== undefined) {
8035
8484
  this._parent = parent;
8036
8485
  }
8037
8486
  // Resource
8038
- resource = (resource || this._model.meta.collectionResourceFactory());
8487
+ if (this._parent === null && resource === undefined)
8488
+ resource = this._model.meta.collectionResourceFactory();
8039
8489
  if (resource !== undefined) {
8040
8490
  this.attach(resource);
8041
8491
  }
@@ -8064,8 +8514,8 @@ class ODataCollection {
8064
8514
  attach(resource) {
8065
8515
  if (this._resource !== null &&
8066
8516
  this._resource.type() !== resource.type() &&
8067
- !resource.isSubtypeOf(this._resource))
8068
- throw new Error(`Can't reattach ${resource.type()} to ${this._resource.type()}`);
8517
+ !this._resource.isSubtypeOf(resource))
8518
+ throw new Error(`attach: Can't reattach ${this._resource.type()} to ${resource.type()}`);
8069
8519
  this._entries.forEach(({ model }) => {
8070
8520
  const mr = this._model.meta.modelResourceFactory(resource.cloneQuery());
8071
8521
  model.attach(mr);
@@ -8081,14 +8531,29 @@ class ODataCollection {
8081
8531
  }
8082
8532
  }
8083
8533
  asEntitySet(func) {
8084
- const parent = this._parent;
8534
+ // Build new resource
8535
+ const query = this.resource().cloneQuery();
8536
+ let resource = this._model.meta.collectionResourceFactory(query);
8537
+ if (resource === undefined)
8538
+ throw new Error('asEntitySet: Collection does not have associated EntitySet endpoint');
8539
+ // Store parent and resource
8540
+ const store = { parent: this._parent, resource: this._resource };
8541
+ // Replace parent and resource
8085
8542
  this._parent = null;
8543
+ this._resource = resource;
8544
+ // Execute
8086
8545
  const result = func(this);
8087
8546
  if (result instanceof Observable) {
8088
- return result.pipe(finalize(() => (this._parent = parent)));
8547
+ return result.pipe(finalize(() => {
8548
+ // Restore
8549
+ this._parent = store.parent;
8550
+ this._resource = store.resource;
8551
+ }));
8089
8552
  }
8090
8553
  else {
8091
- this._parent = parent;
8554
+ // Restore
8555
+ this._parent = store.parent;
8556
+ this._resource = store.resource;
8092
8557
  return result;
8093
8558
  }
8094
8559
  }
@@ -8147,18 +8612,9 @@ class ODataCollection {
8147
8612
  fetch(_a = {}) {
8148
8613
  var { withCount } = _a, options = __rest(_a, ["withCount"]);
8149
8614
  const resource = this.resource();
8150
- if (resource === undefined)
8151
- return throwError('fetch: Resource is undefined');
8152
- let obs$;
8153
- if (resource instanceof ODataEntitySetResource) {
8154
- obs$ = resource.fetch(Object.assign({ withCount }, options));
8155
- }
8156
- else if (resource instanceof ODataNavigationPropertyResource) {
8157
- obs$ = resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
8158
- }
8159
- else {
8160
- obs$ = resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
8161
- }
8615
+ const obs$ = resource instanceof ODataEntitySetResource
8616
+ ? resource.fetch(Object.assign({ withCount }, options))
8617
+ : resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
8162
8618
  this.events$.emit(new ODataModelEvent('request', { collection: this, value: obs$ }));
8163
8619
  return obs$.pipe(map(({ entities, annots }) => {
8164
8620
  this._annotations = annots;
@@ -8169,10 +8625,8 @@ class ODataCollection {
8169
8625
  }
8170
8626
  fetchAll(options) {
8171
8627
  const resource = this.resource();
8172
- if (resource === undefined)
8173
- return throwError('fetchAll: Resource is undefined');
8174
8628
  if (resource instanceof ODataPropertyResource)
8175
- return throwError('fetchAll: Resource is ODataPropertyResource');
8629
+ return throwError(() => new Error('fetchAll: Resource is ODataPropertyResource'));
8176
8630
  const obs$ = resource.fetchAll(options);
8177
8631
  this.events$.emit(new ODataModelEvent('request', {
8178
8632
  collection: this,
@@ -8197,10 +8651,8 @@ class ODataCollection {
8197
8651
  save(_a = {}) {
8198
8652
  var { relModel = false, method } = _a, options = __rest(_a, ["relModel", "method"]);
8199
8653
  const resource = this.resource();
8200
- if (resource === undefined)
8201
- return throwError('saveAll: Resource is undefined');
8202
8654
  if (resource instanceof ODataPropertyResource)
8203
- return throwError('fetchAll: Resource is ODataPropertyResource');
8655
+ return throwError(() => new Error('save: Resource is ODataPropertyResource'));
8204
8656
  let toDestroyEntity = [];
8205
8657
  let toRemoveReference = [];
8206
8658
  let toDestroyContained = [];
@@ -8568,26 +9020,26 @@ class ODataCollection {
8568
9020
  return func.call(params, Object.assign({ responseType }, options));
8569
9021
  }
8570
9022
  }
8571
- return throwError(`Can't function without ODataEntitySetResource`);
9023
+ return throwError(() => new Error(`callFunction: Can't function without ODataEntitySetResource`));
8572
9024
  }
8573
9025
  callAction(name, params, responseType, _a = {}) {
8574
9026
  var options = __rest(_a, []);
8575
9027
  const resource = this.resource();
8576
- if (resource instanceof ODataEntitySetResource) {
8577
- const action = resource.action(name);
8578
- action.query((q) => q.apply(options));
8579
- switch (responseType) {
8580
- case 'property':
8581
- return action.callProperty(params, options);
8582
- case 'model':
8583
- return action.callModel(params, options);
8584
- case 'collection':
8585
- return action.callCollection(params, options);
8586
- default:
8587
- return action.call(params, Object.assign({ responseType }, options));
8588
- }
9028
+ if (!(resource instanceof ODataEntitySetResource)) {
9029
+ return throwError(() => new Error(`callAction: Can't action without ODataEntitySetResource`));
9030
+ }
9031
+ const action = resource.action(name);
9032
+ action.query((q) => q.apply(options));
9033
+ switch (responseType) {
9034
+ case 'property':
9035
+ return action.callProperty(params, options);
9036
+ case 'model':
9037
+ return action.callModel(params, options);
9038
+ case 'collection':
9039
+ return action.callCollection(params, options);
9040
+ default:
9041
+ return action.call(params, Object.assign({ responseType }, options));
8589
9042
  }
8590
- return throwError(`Can't action without ODataEntitySetResource`);
8591
9043
  }
8592
9044
  _unsubscribe(entry) {
8593
9045
  if (entry.subscription) {
@@ -8597,7 +9049,7 @@ class ODataCollection {
8597
9049
  }
8598
9050
  _subscribe(entry) {
8599
9051
  if (entry.subscription) {
8600
- throw new Error('Subscription already exists');
9052
+ throw new Error('Collection: Subscription already exists');
8601
9053
  }
8602
9054
  entry.subscription = entry.model.events$.subscribe((event) => {
8603
9055
  var _a;
@@ -8647,12 +9099,18 @@ class ODataCollection {
8647
9099
  },
8648
9100
  };
8649
9101
  }
8650
- filter(predicate) {
9102
+ filter(predicate, thisArg) {
8651
9103
  return this.models().filter(predicate);
8652
9104
  }
8653
- find(predicate) {
9105
+ map(callbackfn, thisArg) {
9106
+ return this.models().map(callbackfn, thisArg);
9107
+ }
9108
+ find(predicate, thisArg) {
8654
9109
  return this.models().find(predicate);
8655
9110
  }
9111
+ reduce(callbackfn, initialValue) {
9112
+ return this.models().reduce(callbackfn, initialValue);
9113
+ }
8656
9114
  first() {
8657
9115
  return this.models()[0];
8658
9116
  }
@@ -8760,7 +9218,7 @@ class ODataModel {
8760
9218
  this.events$ = new EventEmitter();
8761
9219
  const Klass = this.constructor;
8762
9220
  if (Klass.meta === undefined)
8763
- throw new Error(`Can't create model without metadata`);
9221
+ throw new Error(`ODataModel: Can't create model without metadata`);
8764
9222
  this._meta = Klass.meta;
8765
9223
  this._meta.bind(this, { parent, resource, annots });
8766
9224
  // Client Id
@@ -8800,19 +9258,19 @@ class ODataModel {
8800
9258
  navigationProperty(name) {
8801
9259
  const field = this._meta.field(name);
8802
9260
  if (field === undefined || !field.navigation)
8803
- throw Error(`Can't find navigation property ${name}`);
9261
+ throw Error(`navigationProperty: Can't find navigation property ${name}`);
8804
9262
  const resource = this.resource();
8805
9263
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
8806
- throw Error("Can't get navigation without ODataEntityResource with key");
9264
+ throw Error("navigationProperty: Can't get navigation without ODataEntityResource with key");
8807
9265
  return field.resourceFactory(resource);
8808
9266
  }
8809
9267
  property(name) {
8810
9268
  const field = this._meta.field(name);
8811
9269
  if (field === undefined || field.navigation)
8812
- throw Error(`Can't find property ${name}`);
9270
+ throw Error(`property: Can't find property ${name}`);
8813
9271
  const resource = this.resource();
8814
9272
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
8815
- throw Error("Can't get property without ODataEntityResource with key");
9273
+ throw Error("property: Can't get property without ODataEntityResource with key");
8816
9274
  return field.resourceFactory(resource);
8817
9275
  }
8818
9276
  attach(resource) {
@@ -8958,11 +9416,11 @@ class ODataModel {
8958
9416
  var options = __rest(_a, []);
8959
9417
  let resource = this.resource();
8960
9418
  if (resource === undefined)
8961
- return throwError('fetch: Resource is undefined');
9419
+ return throwError(() => new Error('fetch: Resource is undefined'));
8962
9420
  let obs$;
8963
9421
  if (resource instanceof ODataEntityResource) {
8964
9422
  if (!resource.hasKey())
8965
- return throwError("fetch: Can't fetch model without key");
9423
+ return throwError(() => new Error("fetch: Can't fetch model without key"));
8966
9424
  obs$ = resource.fetch(options);
8967
9425
  }
8968
9426
  else if (resource instanceof ODataNavigationPropertyResource) {
@@ -8977,50 +9435,46 @@ class ODataModel {
8977
9435
  var { method, navigation = false, validate = true } = _a, options = __rest(_a, ["method", "navigation", "validate"]);
8978
9436
  let resource = this.resource();
8979
9437
  if (resource === undefined)
8980
- return throwError('save: Resource is undefined');
9438
+ return throwError(() => new Error('save: Resource is undefined'));
8981
9439
  if (!(resource instanceof ODataEntityResource ||
8982
9440
  resource instanceof ODataNavigationPropertyResource))
8983
- return throwError('save: Resource type ODataEntityResource/ODataNavigationPropertyResource needed');
9441
+ return throwError(() => new Error('save: Resource type ODataEntityResource/ODataNavigationPropertyResource needed'));
8984
9442
  // Resolve method and resource key
8985
9443
  if (method === undefined && this.schema().isCompoundKey())
8986
- return throwError('save: Composite key require a specific method, use create/update/modify');
9444
+ return throwError(() => new Error('save: Composite key require a specific method, use create/update/modify'));
8987
9445
  method = method || (!resource.hasKey() ? 'create' : 'update');
8988
9446
  if (resource instanceof ODataEntityResource &&
8989
9447
  (method === 'update' || method === 'modify') &&
8990
9448
  !resource.hasKey())
8991
- return throwError('save: Update/Patch require entity key');
9449
+ return throwError(() => new Error('save: Update/Patch require entity key'));
8992
9450
  if (resource instanceof ODataNavigationPropertyResource ||
8993
9451
  method === 'create')
8994
9452
  resource.clearKey();
8995
- let obs$;
8996
- if (!validate || this.isValid({ method, navigation })) {
8997
- const _entity = this.toEntity({
8998
- changes_only: method === 'modify',
8999
- field_mapping: true,
9000
- include_concurrency: true,
9001
- include_navigation: navigation,
9002
- });
9003
- obs$ = (method === 'create'
9004
- ? resource.create(_entity, options)
9005
- : method === 'modify'
9006
- ? resource.modify(_entity, Object.assign({ etag: this.annots().etag }, options))
9007
- : resource.update(_entity, Object.assign({ etag: this.annots().etag }, options))).pipe(map(({ entity, annots }) => ({ entity: entity || _entity, annots })));
9453
+ if (validate && !this.isValid({ method, navigation })) {
9454
+ return throwError(() => new Error('save: Validation errors'));
9008
9455
  }
9009
- else {
9010
- obs$ = throwError(this._errors);
9011
- }
9012
- return this._request(obs$);
9456
+ const _entity = this.toEntity({
9457
+ changes_only: method === 'modify',
9458
+ field_mapping: true,
9459
+ include_concurrency: true,
9460
+ include_navigation: navigation,
9461
+ });
9462
+ return this._request((method === 'create'
9463
+ ? resource.create(_entity, options)
9464
+ : method === 'modify'
9465
+ ? resource.modify(_entity, Object.assign({ etag: this.annots().etag }, options))
9466
+ : resource.update(_entity, Object.assign({ etag: this.annots().etag }, options))).pipe(map(({ entity, annots }) => ({ entity: entity || _entity, annots }))));
9013
9467
  }
9014
9468
  destroy(_a = {}) {
9015
9469
  var options = __rest(_a, []);
9016
9470
  let resource = this.resource();
9017
9471
  if (resource === undefined)
9018
- return throwError('destroy: Resource is undefined');
9472
+ return throwError(() => new Error('destroy: Resource is undefined'));
9019
9473
  if (!(resource instanceof ODataEntityResource ||
9020
9474
  resource instanceof ODataNavigationPropertyResource))
9021
- return throwError('destroy: Resource type ODataEntityResource/ODataNavigationPropertyResource needed');
9475
+ return throwError(() => new Error('destroy: Resource type ODataEntityResource/ODataNavigationPropertyResource needed'));
9022
9476
  if (!resource.hasKey())
9023
- return throwError("destroy: Can't destroy model without key");
9477
+ return throwError(() => new Error("destroy: Can't destroy model without key"));
9024
9478
  const _entity = this.toEntity({ field_mapping: true });
9025
9479
  const obs$ = resource
9026
9480
  .destroy(Object.assign({ etag: this.annots().etag }, options))
@@ -9054,7 +9508,7 @@ class ODataModel {
9054
9508
  var options = __rest(_a, []);
9055
9509
  const resource = this.resource();
9056
9510
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9057
- return throwError("Can't call function without ODataEntityResource with key");
9511
+ return throwError(() => new Error("callFunction: Can't call function without ODataEntityResource with key"));
9058
9512
  const func = resource.function(name).query((q) => q.apply(options));
9059
9513
  switch (responseType) {
9060
9514
  case 'property':
@@ -9071,7 +9525,7 @@ class ODataModel {
9071
9525
  var options = __rest(_a, []);
9072
9526
  const resource = this.resource();
9073
9527
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9074
- return throwError("Can't call action without ODataEntityResource with key");
9528
+ return throwError(() => new Error("callAction: Can't call action without ODataEntityResource with key"));
9075
9529
  const action = resource.action(name).query((q) => q.apply(options));
9076
9530
  switch (responseType) {
9077
9531
  case 'property':
@@ -9088,7 +9542,7 @@ class ODataModel {
9088
9542
  cast(type) {
9089
9543
  const resource = this.resource();
9090
9544
  if (!(resource instanceof ODataEntityResource))
9091
- throw new Error(`Can't cast to derived model without ODataEntityResource`);
9545
+ throw new Error(`cast: Can't cast to derived model without ODataEntityResource`);
9092
9546
  return resource
9093
9547
  .cast(type)
9094
9548
  .asModel(this.toEntity(INCLUDE_DEEP), { annots: this.annots() });
@@ -9108,7 +9562,7 @@ class ODataModel {
9108
9562
  getValue(name, options) {
9109
9563
  const field = this._meta.field(name);
9110
9564
  if (field === undefined || field.navigation)
9111
- throw Error(`Can't find property ${name}`);
9565
+ throw Error(`getValue: Can't find property ${name}`);
9112
9566
  let value = this[name];
9113
9567
  if (value === undefined) {
9114
9568
  const prop = field.resourceFactory(this.resource());
@@ -9155,7 +9609,7 @@ class ODataModel {
9155
9609
  getReference(name) {
9156
9610
  const field = this._meta.field(name);
9157
9611
  if (field === undefined || !field.navigation)
9158
- throw Error(`Can't find navigation property ${name}`);
9612
+ throw Error(`getReference: Can't find navigation property ${name}`);
9159
9613
  let model = this[name];
9160
9614
  if (model === undefined) {
9161
9615
  const value = field.collection ? [] : this.referenced(field);
@@ -9962,9 +10416,9 @@ class ODataClient {
9962
10416
  return this.request('PUT', resource, addBody(options, body));
9963
10417
  }
9964
10418
  }
9965
- ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataSettings }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
9966
- ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataClient, providedIn: 'root' });
9967
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataClient, decorators: [{
10419
+ ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataSettings }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
10420
+ ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataClient, providedIn: 'root' });
10421
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataClient, decorators: [{
9968
10422
  type: Injectable,
9969
10423
  args: [{
9970
10424
  providedIn: 'root',
@@ -10077,7 +10531,7 @@ class ODataEntitySetService extends ODataEntityService {
10077
10531
  update(key, attrs, options) {
10078
10532
  const res = this.entity(key);
10079
10533
  if (!res.hasKey())
10080
- return throwError('Resource without key');
10534
+ return throwError(() => new Error('update: Resource without key'));
10081
10535
  return res.update(attrs, options);
10082
10536
  }
10083
10537
  /**
@@ -10090,7 +10544,7 @@ class ODataEntitySetService extends ODataEntityService {
10090
10544
  modify(key, attrs, options) {
10091
10545
  const res = this.entity(key);
10092
10546
  if (!res.hasKey())
10093
- return throwError('Resource without key');
10547
+ return throwError(() => new Error('modify: Resource without key'));
10094
10548
  return res.modify(attrs, options);
10095
10549
  }
10096
10550
  /**
@@ -10102,7 +10556,7 @@ class ODataEntitySetService extends ODataEntityService {
10102
10556
  destroy(key, options) {
10103
10557
  const res = this.entity(key);
10104
10558
  if (!res.hasKey())
10105
- return throwError('Resource without key');
10559
+ return throwError(() => new Error('destroy: Resource without key'));
10106
10560
  return res.destroy(options);
10107
10561
  }
10108
10562
  //#region Shortcuts
@@ -10133,12 +10587,12 @@ class ODataEntitySetService extends ODataEntityService {
10133
10587
  var { etag, method } = _a, options = __rest(_a, ["etag", "method"]);
10134
10588
  let schema = this.structuredTypeSchema;
10135
10589
  if (method === undefined && schema !== undefined && schema.isCompoundKey())
10136
- return throwError('Composite key require a specific method, use create/update/patch');
10590
+ return throwError(() => new Error('save: Composite key require a specific method, use create/update/patch'));
10137
10591
  let key = schema && schema.resolveKey(attrs);
10138
10592
  if (method === undefined)
10139
10593
  method = key !== undefined ? 'update' : 'create';
10140
10594
  if ((method === 'update' || method === 'modify') && key === undefined)
10141
- return throwError("Can't update/patch entity without key");
10595
+ return throwError(() => new Error("save: Can't update/patch entity without key"));
10142
10596
  return method === 'create'
10143
10597
  ? this.create(attrs, options)
10144
10598
  : method === 'modify'
@@ -10216,9 +10670,9 @@ class ODataServiceFactory {
10216
10670
  })(this.client, singletonName, apiNameOrEntityType);
10217
10671
  }
10218
10672
  }
10219
- ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10220
- ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory });
10221
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory, decorators: [{
10673
+ ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10674
+ ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataServiceFactory });
10675
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataServiceFactory, decorators: [{
10222
10676
  type: Injectable
10223
10677
  }], ctorParameters: function () { return [{ type: ODataClient }]; } });
10224
10678
 
@@ -10242,10 +10696,10 @@ class ODataModule {
10242
10696
  };
10243
10697
  }
10244
10698
  }
10245
- ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10246
- ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10247
- ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10248
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, decorators: [{
10699
+ ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10700
+ ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10701
+ ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10702
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, decorators: [{
10249
10703
  type: NgModule,
10250
10704
  args: [{
10251
10705
  imports: [HttpClientModule],