angular-odata 0.99.0 → 0.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +31 -25
  2. package/esm2020/lib/api.mjs +2 -2
  3. package/esm2020/lib/cache/cache.mjs +2 -2
  4. package/esm2020/lib/client.mjs +3 -3
  5. package/esm2020/lib/models/collection.mjs +53 -48
  6. package/esm2020/lib/models/model.mjs +33 -37
  7. package/esm2020/lib/models/options.mjs +35 -14
  8. package/esm2020/lib/module.mjs +4 -4
  9. package/esm2020/lib/options.mjs +4 -3
  10. package/esm2020/lib/resources/query/builder.mjs +4 -6
  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 +13 -13
  20. package/esm2020/lib/resources/query/options.mjs +33 -36
  21. package/esm2020/lib/resources/resource.mjs +27 -74
  22. package/esm2020/lib/resources/responses/options.mjs +1 -2
  23. package/esm2020/lib/resources/types/action.mjs +4 -1
  24. package/esm2020/lib/resources/types/batch.mjs +6 -1
  25. package/esm2020/lib/resources/types/count.mjs +4 -1
  26. package/esm2020/lib/resources/types/entity-set.mjs +4 -1
  27. package/esm2020/lib/resources/types/entity.mjs +6 -3
  28. package/esm2020/lib/resources/types/function.mjs +11 -1
  29. package/esm2020/lib/resources/types/media.mjs +4 -1
  30. package/esm2020/lib/resources/types/metadata.mjs +4 -1
  31. package/esm2020/lib/resources/types/navigation-property.mjs +4 -1
  32. package/esm2020/lib/resources/types/property.mjs +4 -1
  33. package/esm2020/lib/resources/types/reference.mjs +4 -1
  34. package/esm2020/lib/resources/types/singleton.mjs +4 -1
  35. package/esm2020/lib/resources/types/value.mjs +4 -1
  36. package/esm2020/lib/schema/callable.mjs +6 -2
  37. package/esm2020/lib/schema/element.mjs +12 -2
  38. package/esm2020/lib/schema/enum-type.mjs +10 -2
  39. package/esm2020/lib/schema/parsers/callable.mjs +3 -2
  40. package/esm2020/lib/schema/parsers/enum-type.mjs +6 -5
  41. package/esm2020/lib/schema/parsers/structured-type.mjs +1 -1
  42. package/esm2020/lib/schema/structured-type.mjs +11 -2
  43. package/esm2020/lib/services/entity-set.mjs +6 -6
  44. package/esm2020/lib/services/factory.mjs +3 -3
  45. package/esm2020/lib/types.mjs +2 -1
  46. package/esm2020/lib/utils/objects.mjs +5 -1
  47. package/fesm2015/angular-odata.mjs +494 -305
  48. package/fesm2015/angular-odata.mjs.map +1 -1
  49. package/fesm2020/angular-odata.mjs +493 -309
  50. package/fesm2020/angular-odata.mjs.map +1 -1
  51. package/lib/models/collection.d.ts +4 -2
  52. package/lib/models/model.d.ts +1 -1
  53. package/lib/models/options.d.ts +16 -14
  54. package/lib/options.d.ts +4 -4
  55. package/lib/resources/query/builder.d.ts +1 -0
  56. package/lib/resources/query/expressions/base.d.ts +1 -0
  57. package/lib/resources/query/expressions/compute.d.ts +3 -2
  58. package/lib/resources/query/expressions/expand.d.ts +40 -12
  59. package/lib/resources/query/expressions/filter.d.ts +22 -21
  60. package/lib/resources/query/expressions/orderby.d.ts +4 -2
  61. package/lib/resources/query/expressions/search.d.ts +5 -2
  62. package/lib/resources/query/expressions/select.d.ts +3 -2
  63. package/lib/resources/query/expressions/syntax.d.ts +12 -2
  64. package/lib/resources/query/handlers.d.ts +12 -12
  65. package/lib/resources/query/options.d.ts +10 -8
  66. package/lib/resources/resource.d.ts +3 -1
  67. package/lib/resources/responses/options.d.ts +2 -3
  68. package/lib/resources/types/action.d.ts +1 -0
  69. package/lib/resources/types/batch.d.ts +1 -0
  70. package/lib/resources/types/count.d.ts +1 -0
  71. package/lib/resources/types/entity-set.d.ts +2 -1
  72. package/lib/resources/types/entity.d.ts +1 -0
  73. package/lib/resources/types/function.d.ts +4 -0
  74. package/lib/resources/types/media.d.ts +1 -0
  75. package/lib/resources/types/metadata.d.ts +1 -0
  76. package/lib/resources/types/navigation-property.d.ts +1 -0
  77. package/lib/resources/types/property.d.ts +1 -0
  78. package/lib/resources/types/reference.d.ts +1 -0
  79. package/lib/resources/types/singleton.d.ts +1 -0
  80. package/lib/resources/types/value.d.ts +1 -0
  81. package/lib/schema/callable.d.ts +4 -4
  82. package/lib/schema/element.d.ts +7 -1
  83. package/lib/schema/enum-type.d.ts +10 -4
  84. package/lib/schema/parsers/callable.d.ts +9 -7
  85. package/lib/schema/parsers/enum-type.d.ts +7 -5
  86. package/lib/schema/parsers/structured-type.d.ts +7 -7
  87. package/lib/schema/structured-type.d.ts +11 -5
  88. package/lib/types.d.ts +6 -5
  89. package/package.json +1 -1
@@ -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) {
@@ -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)) {
@@ -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;
@@ -2360,19 +2491,19 @@ class ODataQueryOptionsHandler {
2360
2491
  }
2361
2492
  select(opts) {
2362
2493
  if (Types.isFunction(opts)) {
2363
- return this.options.expression(QueryOptionNames.select, SelectExpression.select(opts));
2494
+ return this.options.expression(QueryOptionNames.select, SelectExpression.select(opts, this.options.expression(QueryOptionNames.select)));
2364
2495
  }
2365
2496
  return this.options.option(QueryOptionNames.select, opts);
2366
2497
  }
2367
2498
  expand(opts) {
2368
2499
  if (Types.isFunction(opts)) {
2369
- return this.options.expression(QueryOptionNames.expand, ExpandExpression.expand(opts));
2500
+ return this.options.expression(QueryOptionNames.expand, ExpandExpression.expand(opts, this.options.expression(QueryOptionNames.expand)));
2370
2501
  }
2371
2502
  return this.options.option(QueryOptionNames.expand, opts);
2372
2503
  }
2373
2504
  compute(opts) {
2374
2505
  if (Types.isFunction(opts)) {
2375
- return this.options.expression(QueryOptionNames.compute, ComputeExpression.compute(opts));
2506
+ return this.options.expression(QueryOptionNames.compute, ComputeExpression.compute(opts, this.options.expression(QueryOptionNames.compute)));
2376
2507
  }
2377
2508
  return this.options.option(QueryOptionNames.compute, opts);
2378
2509
  }
@@ -2384,19 +2515,19 @@ class ODataQueryOptionsHandler {
2384
2515
  }
2385
2516
  search(opts) {
2386
2517
  if (Types.isFunction(opts)) {
2387
- return this.options.expression(QueryOptionNames.search, SearchExpression.search(opts));
2518
+ return this.options.expression(QueryOptionNames.search, SearchExpression.search(opts, this.options.expression(QueryOptionNames.search)));
2388
2519
  }
2389
2520
  return this.options.option(QueryOptionNames.search, opts);
2390
2521
  }
2391
2522
  filter(opts) {
2392
2523
  if (Types.isFunction(opts)) {
2393
- return this.options.expression(QueryOptionNames.filter, FilterExpression.filter(opts));
2524
+ return this.options.expression(QueryOptionNames.filter, FilterExpression.filter(opts, this.options.expression(QueryOptionNames.filter)));
2394
2525
  }
2395
2526
  return this.options.option(QueryOptionNames.filter, opts);
2396
2527
  }
2397
2528
  orderBy(opts) {
2398
2529
  if (Types.isFunction(opts)) {
2399
- return this.options.expression(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts));
2530
+ return this.options.option(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts, this.options.expression(QueryOptionNames.orderBy)));
2400
2531
  }
2401
2532
  return this.options.option(QueryOptionNames.orderBy, opts);
2402
2533
  }
@@ -2424,22 +2555,22 @@ class ODataQueryOptionsHandler {
2424
2555
  }
2425
2556
  apply(query) {
2426
2557
  if (query.select !== undefined) {
2427
- this.select(query.select);
2558
+ this.options.option(QueryOptionNames.select, query.select);
2428
2559
  }
2429
2560
  if (query.expand !== undefined) {
2430
- this.expand(query.expand);
2561
+ this.options.option(QueryOptionNames.expand, query.expand);
2431
2562
  }
2432
2563
  if (query.transform !== undefined) {
2433
- this.transform(query.transform);
2564
+ this.options.option(QueryOptionNames.transform, query.transform);
2434
2565
  }
2435
2566
  if (query.search !== undefined) {
2436
- this.search(query.search);
2567
+ this.options.option(QueryOptionNames.search, query.search);
2437
2568
  }
2438
2569
  if (query.filter !== undefined) {
2439
- this.filter(query.filter);
2570
+ this.options.option(QueryOptionNames.filter, query.filter);
2440
2571
  }
2441
2572
  if (query.orderBy !== undefined) {
2442
- this.orderBy(query.orderBy);
2573
+ this.options.option(QueryOptionNames.orderBy, query.orderBy);
2443
2574
  }
2444
2575
  this.paging(query);
2445
2576
  }
@@ -2447,7 +2578,7 @@ class ODataQueryOptionsHandler {
2447
2578
 
2448
2579
  class ODataQueryOptions {
2449
2580
  constructor(options) {
2450
- this.options = options || {};
2581
+ this.values = options || {};
2451
2582
  }
2452
2583
  // Params
2453
2584
  pathAndParams(escape = false) {
@@ -2465,11 +2596,11 @@ class ODataQueryOptions {
2465
2596
  QueryOptionNames.expand,
2466
2597
  QueryOptionNames.format,
2467
2598
  ]
2468
- .filter((key) => !Types.isEmpty(this.options[key]))
2599
+ .filter((key) => !Types.isEmpty(this.values[key]))
2469
2600
  .reduce((acc, key) => {
2470
- let value = this.options[key];
2471
- if (Types.rawType(value) === 'Expression') {
2472
- value = value.render(aliases);
2601
+ let value = this.values[key];
2602
+ if (Types.rawType(value).endsWith('Expression')) {
2603
+ value = value.render({ aliases });
2473
2604
  }
2474
2605
  return Object.assign(acc, { [key]: value });
2475
2606
  }, {});
@@ -2484,63 +2615,60 @@ class ODataQueryOptions {
2484
2615
  .join('&'));
2485
2616
  }
2486
2617
  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
- }
2618
+ return Object.keys(this.values).reduce((acc, key) => {
2619
+ let value = this.values[key];
2620
+ value =
2621
+ Types.isObject(value) && 'toJSON' in value ? value.toJSON() : value;
2492
2622
  return Object.assign(acc, { [key]: value });
2493
2623
  }, {});
2494
2624
  }
2495
2625
  toQueryArguments() {
2496
2626
  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],
2627
+ select: this.values[QueryOptionNames.select],
2628
+ expand: this.values[QueryOptionNames.expand],
2629
+ transform: this.values[QueryOptionNames.transform],
2630
+ compute: this.values[QueryOptionNames.compute],
2631
+ search: this.values[QueryOptionNames.search],
2632
+ filter: this.values[QueryOptionNames.filter],
2633
+ orderBy: this.values[QueryOptionNames.orderBy],
2634
+ top: this.values[QueryOptionNames.top],
2635
+ skip: this.values[QueryOptionNames.skip],
2636
+ skiptoken: this.values[QueryOptionNames.skiptoken],
2507
2637
  };
2508
2638
  }
2509
2639
  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
- }, {});
2640
+ const options = Object.keys(this.values).reduce((acc, key) => Object.assign(acc, { [key]: Objects.clone(this.values[key]) }), {});
2517
2641
  return new ODataQueryOptions(options);
2518
2642
  }
2519
2643
  // Set Renderable
2520
2644
  expression(name, exp) {
2521
- return (this.options[name] = exp);
2645
+ if (exp !== undefined)
2646
+ this.values[name] = exp;
2647
+ return this.values[name];
2522
2648
  }
2523
2649
  // Option Handler
2524
2650
  option(name, opts) {
2525
2651
  if (opts !== undefined)
2526
- this.options[name] = opts;
2527
- return new ODataQueryOptionHandler(this.options, name);
2652
+ this.values[name] = opts;
2653
+ return new ODataQueryOptionHandler(this.values, name);
2528
2654
  }
2529
2655
  // Query Options tools
2530
2656
  has(name) {
2531
- return this.options[name] !== undefined;
2657
+ return this.values[name] !== undefined;
2532
2658
  }
2533
2659
  remove(...names) {
2534
- names.forEach((name) => this.option(name).clear());
2660
+ names.forEach((name) => {
2661
+ delete this.values[name];
2662
+ });
2535
2663
  }
2536
2664
  keep(...names) {
2537
- this.options = Object.keys(this.options)
2665
+ this.values = Object.keys(this.values)
2538
2666
  .filter((k) => names.indexOf(k) !== -1)
2539
- .reduce((acc, k) => Object.assign(acc, { [k]: this.options[k] }), {});
2667
+ .reduce((acc, k) => Object.assign(acc, { [k]: this.values[k] }), {});
2540
2668
  }
2541
2669
  // Clear
2542
2670
  clear() {
2543
- this.options = {};
2671
+ this.values = {};
2544
2672
  }
2545
2673
  }
2546
2674
 
@@ -2971,7 +3099,7 @@ class ODataSchemaElement extends ODataAnnotatable {
2971
3099
  return names.indexOf(type) !== -1;
2972
3100
  }
2973
3101
  /**
2974
- * Returns a boolean indicating if the structured type is a sub type of the given type.
3102
+ * Returns a boolean indicating if the structured type is a subtype of the given type.
2975
3103
  * @param type String representation of the type
2976
3104
  * @returns True if the callable is type of the given type
2977
3105
  */
@@ -2980,6 +3108,16 @@ class ODataSchemaElement extends ODataAnnotatable {
2980
3108
  return true;
2981
3109
  return false;
2982
3110
  }
3111
+ /**
3112
+ * Returns a boolean indicating if the structured type is a supertype of the given type.
3113
+ * @param type String representation of the type
3114
+ * @returns True if the callable is type of the given type
3115
+ */
3116
+ isSupertypeOf(schema) {
3117
+ if (this.isTypeOf(schema.type()))
3118
+ return true;
3119
+ return false;
3120
+ }
2983
3121
  }
2984
3122
 
2985
3123
  //https://github.com/niklasvh/base64-arraybuffer
@@ -3391,7 +3529,7 @@ class ODataApiOptions {
3391
3529
  constructor(config) {
3392
3530
  this.etag = { ifMatch: true, ifNoneMatch: false };
3393
3531
  this.version = config.version || DEFAULT_VERSION;
3394
- this.stringAsEnum = config.stringAsEnum;
3532
+ this.stringAsEnum = config.stringAsEnum || false;
3395
3533
  this.params = config.params || {};
3396
3534
  this.headers = config.headers || {};
3397
3535
  this.withCredentials = config.withCredentials;
@@ -3402,6 +3540,8 @@ class ODataApiOptions {
3402
3540
  Object.assign(this.etag, config.etag || {});
3403
3541
  this.prefer = config.prefer;
3404
3542
  this.deleteRefBy = config.deleteRefBy || 'path';
3543
+ this.nonParenthesisForEmptyParameterFunction =
3544
+ config.nonParenthesisForEmptyParameterFunction || false;
3405
3545
  }
3406
3546
  get helper() {
3407
3547
  return ODataHelper[this.version];
@@ -3410,7 +3550,6 @@ class ODataApiOptions {
3410
3550
  class ODataParserOptions {
3411
3551
  constructor(config) {
3412
3552
  this.version = config.version || DEFAULT_VERSION;
3413
- this.stringAsEnum = config.stringAsEnum;
3414
3553
  }
3415
3554
  get helper() {
3416
3555
  return ODataHelper[this.version];
@@ -3446,7 +3585,8 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3446
3585
  ttitelize(term) {
3447
3586
  return (term && this.annotatedValue(term)) || Strings.titleCase(this.name);
3448
3587
  }
3449
- configure({ options }) {
3588
+ configure({ stringAsEnum, options }) {
3589
+ this.stringAsEnum = stringAsEnum;
3450
3590
  this.optionsHelper = options;
3451
3591
  }
3452
3592
  isTypeOf(type) {
@@ -3477,13 +3617,13 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3477
3617
  : this.optionsHelper;
3478
3618
  if (this.flags) {
3479
3619
  const names = Enums.toNames(this.members, value);
3480
- return !(parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.stringAsEnum)
3620
+ return !this.stringAsEnum
3481
3621
  ? `${this.namespace}.${this.name}'${names.join(', ')}'`
3482
3622
  : names.join(', ');
3483
3623
  }
3484
3624
  else {
3485
3625
  const name = Enums.toName(this.members, value);
3486
- return !(parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.stringAsEnum)
3626
+ return !this.stringAsEnum
3487
3627
  ? `${this.namespace}.${this.name}'${name}'`
3488
3628
  : name;
3489
3629
  }
@@ -3494,7 +3634,7 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3494
3634
  ? new ODataParserOptions(options)
3495
3635
  : this.optionsHelper;
3496
3636
  const serialized = this.serialize(value, parserOptions);
3497
- return (parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.stringAsEnum)
3637
+ return this.stringAsEnum
3498
3638
  ? raw(`'${serialized}'`)
3499
3639
  : raw(serialized);
3500
3640
  }
@@ -3997,7 +4137,8 @@ class ODataCallableParser {
3997
4137
  .filter((p) => p.name in params && params[p.name] !== undefined);
3998
4138
  return parameters.reduce((acc, p) => (Object.assign(Object.assign({}, acc), { [p.name]: p.encode(params[p.name], parserOptions) })), {});
3999
4139
  }
4000
- configure({ parserForType, options, }) {
4140
+ configure({ nonParenthesisForEmptyParameterFunction, parserForType, options, }) {
4141
+ this.nonParenthesisForEmptyParameterFunction = nonParenthesisForEmptyParameterFunction;
4001
4142
  this.optionsHelper = options;
4002
4143
  if (this.return)
4003
4144
  this.parser = parserForType(this.return.type) || NONE_PARSER;
@@ -4031,7 +4172,11 @@ class ODataCallable extends ODataSchemaElement {
4031
4172
  return path;
4032
4173
  }
4033
4174
  configure({ parserForType, }) {
4034
- this.parser.configure({ options: this.api.options, parserForType });
4175
+ this.parser.configure({
4176
+ nonParenthesisForEmptyParameterFunction: this.api.options.nonParenthesisForEmptyParameterFunction,
4177
+ options: this.api.options,
4178
+ parserForType
4179
+ });
4035
4180
  }
4036
4181
  /**
4037
4182
  * Deseialize the given value from the callable.
@@ -4091,7 +4236,7 @@ class ODataEnumType extends ODataSchemaElement {
4091
4236
  this.parser = new ODataEnumTypeParser(config, schema.namespace, schema.alias);
4092
4237
  }
4093
4238
  configure() {
4094
- this.parser.configure({ options: this.api.options });
4239
+ this.parser.configure({ stringAsEnum: this.api.options.stringAsEnum, options: this.api.options });
4095
4240
  }
4096
4241
  /**
4097
4242
  * Returns the fields of the enum type.
@@ -4116,6 +4261,14 @@ class ODataEnumType extends ODataSchemaElement {
4116
4261
  findFieldByValue(value) {
4117
4262
  return this.fields().find((f) => f.value === value);
4118
4263
  }
4264
+ /**
4265
+ * Find a fields by flag.
4266
+ * @param value The value of the field
4267
+ * @returns The fields with the given flag
4268
+ */
4269
+ findFieldsByValue(value) {
4270
+ return this.fields().filter((f) => Boolean(f.value & value));
4271
+ }
4119
4272
  /**
4120
4273
  * Map the fields of the enum type.
4121
4274
  * @param mapper Function that maps the value to the new value
@@ -4187,7 +4340,7 @@ class ODataStructuredType extends ODataSchemaElement {
4187
4340
  }
4188
4341
  }
4189
4342
  /**
4190
- * Returns a boolean indicating if the structured type is a sub type of the given type.
4343
+ * Returns a boolean indicating if the structured type is a subtype of the given type.
4191
4344
  * @param type String representation of the type
4192
4345
  * @returns True if the callable is type of the given type
4193
4346
  */
@@ -4195,6 +4348,15 @@ class ODataStructuredType extends ODataSchemaElement {
4195
4348
  return (super.isSubtypeOf(schema) ||
4196
4349
  (this.parent !== undefined && this.parent.isSubtypeOf(schema)));
4197
4350
  }
4351
+ /**
4352
+ * Returns a boolean indicating if the structured type is a supertype of the given type.
4353
+ * @param type String representation of the type
4354
+ * @returns True if the callable is type of the given type
4355
+ */
4356
+ isSupertypeOf(schema) {
4357
+ return (super.isSupertypeOf(schema) ||
4358
+ this.children.some((c) => c.isSupertypeOf(schema)));
4359
+ }
4198
4360
  /**
4199
4361
  * Returns a boolean indicating if the structured type has a simple key.
4200
4362
  * @returns True if the structured type has a simple key
@@ -4477,19 +4639,12 @@ class ODataResource {
4477
4639
  other.schema !== undefined &&
4478
4640
  ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.isSubtypeOf(other.schema)));
4479
4641
  }
4480
- /*
4481
- isParentOf(other: ODataResource<any>) {
4482
- const [selfPath] = this.pathAndParams();
4483
- const [otherPath] = other.pathAndParams();
4484
- return otherPath !== selfPath && otherPath.startsWith(selfPath);
4485
- }
4486
-
4487
- isChildOf(other: ODataResource<any>) {
4488
- const [selfPath] = this.pathAndParams();
4489
- const [otherPath] = other.pathAndParams();
4490
- return otherPath !== selfPath && selfPath.startsWith(otherPath);
4642
+ isSupertypeOf(other) {
4643
+ var _a;
4644
+ return (this.schema !== undefined &&
4645
+ other.schema !== undefined &&
4646
+ ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.isSupertypeOf(other.schema)));
4491
4647
  }
4492
- */
4493
4648
  isEqualTo(other, test) {
4494
4649
  const [selfPath, selfParams] = this.pathAndParams();
4495
4650
  const [otherPath, otherParams] = other.pathAndParams();
@@ -4528,29 +4683,28 @@ class ODataResource {
4528
4683
  query: this.cloneQuery(),
4529
4684
  });
4530
4685
  }
4686
+ __parser(value, options, type) {
4687
+ const dataType = options !== undefined && Types.isPlainObject(value)
4688
+ ? options.helper.type(value)
4689
+ : undefined;
4690
+ if (dataType !== undefined) {
4691
+ // Parser from data type
4692
+ return this.api.parserForType(dataType);
4693
+ }
4694
+ else if (this.schema !== undefined && 'parser' in this.schema) {
4695
+ // Parser from resource schema
4696
+ return this.schema.parser;
4697
+ }
4698
+ else if (type !== undefined) {
4699
+ // Parser from resource type
4700
+ return this.api.parserForType(type);
4701
+ }
4702
+ return undefined;
4703
+ }
4531
4704
  deserialize(value, options) {
4532
4705
  const resourceType = this.returnType();
4533
- const resourceSchema = this.schema;
4534
- const _p = (value, options) => {
4535
- const dataType = Types.isPlainObject(value)
4536
- ? options.helper.type(value)
4537
- : undefined;
4538
- if (dataType !== undefined) {
4539
- // Parser from data type
4540
- return this.api.parserForType(dataType);
4541
- }
4542
- else if (resourceSchema !== undefined && 'parser' in resourceSchema) {
4543
- // Parser from resource schema
4544
- return resourceSchema.parser;
4545
- }
4546
- else if (resourceType !== undefined) {
4547
- // Parser from resource type
4548
- return this.api.parserForType(resourceType);
4549
- }
4550
- return undefined;
4551
- };
4552
4706
  const _d = (value, options) => {
4553
- const parser = _p(value, options);
4707
+ const parser = this.__parser(value, options, resourceType);
4554
4708
  return parser !== undefined && 'deserialize' in parser
4555
4709
  ? parser.deserialize(value, options)
4556
4710
  : value;
@@ -4561,27 +4715,8 @@ class ODataResource {
4561
4715
  }
4562
4716
  serialize(value, options) {
4563
4717
  const resourceType = this.type();
4564
- const resourceSchema = this.schema;
4565
- const _p = (value, options) => {
4566
- const dataType = Types.isPlainObject(value)
4567
- ? options.helper.type(value)
4568
- : undefined;
4569
- if (dataType !== undefined) {
4570
- // Parser from data type
4571
- return this.api.parserForType(dataType);
4572
- }
4573
- else if (resourceSchema !== undefined && 'parser' in resourceSchema) {
4574
- // Parser from resource schema
4575
- return resourceSchema.parser;
4576
- }
4577
- else if (resourceType !== undefined) {
4578
- // Parser from resource type
4579
- return this.api.parserForType(resourceType);
4580
- }
4581
- return undefined;
4582
- };
4583
4718
  const _s = (value, options) => {
4584
- const parser = _p(value, options);
4719
+ const parser = this.__parser(value, options, resourceType);
4585
4720
  return parser !== undefined && 'serialize' in parser
4586
4721
  ? parser.serialize(value, options)
4587
4722
  : value;
@@ -4592,27 +4727,8 @@ class ODataResource {
4592
4727
  }
4593
4728
  encode(value, options) {
4594
4729
  const resourceType = this.type();
4595
- const resourceSchema = this.schema;
4596
- const _p = (value, options) => {
4597
- const dataType = Types.isPlainObject(value)
4598
- ? options.helper.type(value)
4599
- : undefined;
4600
- if (dataType !== undefined) {
4601
- // Parser from data type
4602
- return this.api.parserForType(dataType);
4603
- }
4604
- else if (resourceSchema !== undefined && 'parser' in resourceSchema) {
4605
- // Parser from resource schema
4606
- return resourceSchema.parser;
4607
- }
4608
- else if (resourceType !== undefined) {
4609
- // Parser from resource type
4610
- return this.api.parserForType(resourceType);
4611
- }
4612
- return undefined;
4613
- };
4614
4730
  const _e = (value, options) => {
4615
- const parser = _p(value, options);
4731
+ const parser = this.__parser(value, options, resourceType);
4616
4732
  return parser !== undefined && 'encode' in parser
4617
4733
  ? parser.encode(value, options)
4618
4734
  : value;
@@ -4764,6 +4880,9 @@ class ODataActionResource extends ODataResource {
4764
4880
  }
4765
4881
  return action;
4766
4882
  }
4883
+ clone() {
4884
+ return super.clone();
4885
+ }
4767
4886
  //#endregion
4768
4887
  returnType() {
4769
4888
  var _a;
@@ -4951,7 +5070,6 @@ class ODataEntitiesAnnotations extends ODataAnnotations {
4951
5070
  class ODataResponseOptions {
4952
5071
  constructor(config) {
4953
5072
  this.version = config.version || DEFAULT_VERSION;
4954
- this.stringAsEnum = config.stringAsEnum;
4955
5073
  }
4956
5074
  get helper() {
4957
5075
  return ODataHelper[this.version];
@@ -6072,6 +6190,11 @@ class ODataBatchResource extends ODataResource {
6072
6190
  segments.add(PathSegmentNames.batch, $BATCH);
6073
6191
  return new ODataBatchResource(api, { segments });
6074
6192
  }
6193
+ clone() {
6194
+ const batch = super.clone();
6195
+ batch._requests = [...this._requests];
6196
+ return batch;
6197
+ }
6075
6198
  //#endregion
6076
6199
  storeRequester() {
6077
6200
  const current = this.api.request;
@@ -6267,6 +6390,9 @@ class ODataCountResource extends ODataResource {
6267
6390
  query === null || query === void 0 ? void 0 : query.keep(QueryOptionNames.filter, QueryOptionNames.search);
6268
6391
  return new ODataCountResource(api, { segments, query });
6269
6392
  }
6393
+ clone() {
6394
+ return super.clone();
6395
+ }
6270
6396
  //#endregion
6271
6397
  //#region Requests
6272
6398
  get(options) {
@@ -6319,6 +6445,9 @@ class ODataFunctionResource extends ODataResource {
6319
6445
  }
6320
6446
  return func;
6321
6447
  }
6448
+ clone() {
6449
+ return super.clone();
6450
+ }
6322
6451
  //#endregion
6323
6452
  returnType() {
6324
6453
  var _a;
@@ -6326,6 +6455,13 @@ class ODataFunctionResource extends ODataResource {
6326
6455
  ? (_a = this.schema.parser.return) === null || _a === void 0 ? void 0 : _a.type
6327
6456
  : undefined;
6328
6457
  }
6458
+ pathAndParams(escape = false) {
6459
+ let [path, params] = super.pathAndParams(escape);
6460
+ if (path.endsWith('()') && this.api.options.nonParenthesisForEmptyParameterFunction) {
6461
+ path = path.substring(0, path.length - 2);
6462
+ }
6463
+ return [path, params];
6464
+ }
6329
6465
  parameters(params, { alias } = {}) {
6330
6466
  let parameters = params !== null ? this.encode(params) : null;
6331
6467
  if (alias && parameters !== null) {
@@ -6410,6 +6546,9 @@ class ODataMediaResource extends ODataResource {
6410
6546
  segments.add(PathSegmentNames.value, $VALUE);
6411
6547
  return new ODataMediaResource(api, { segments, query });
6412
6548
  }
6549
+ clone() {
6550
+ return super.clone();
6551
+ }
6413
6552
  //#endregion
6414
6553
  //#region Requests
6415
6554
  get(options) {
@@ -6462,6 +6601,9 @@ class ODataValueResource extends ODataResource {
6462
6601
  }
6463
6602
  return value;
6464
6603
  }
6604
+ clone() {
6605
+ return super.clone();
6606
+ }
6465
6607
  //#endregion
6466
6608
  //#region Requests
6467
6609
  get(options) {
@@ -6527,6 +6669,9 @@ class ODataPropertyResource extends ODataResource {
6527
6669
  }
6528
6670
  return property;
6529
6671
  }
6672
+ clone() {
6673
+ return super.clone();
6674
+ }
6530
6675
  //#endregion
6531
6676
  key(value) {
6532
6677
  const property = this.clone();
@@ -6662,6 +6807,9 @@ class ODataReferenceResource extends ODataResource {
6662
6807
  query === null || query === void 0 ? void 0 : query.clear();
6663
6808
  return new ODataReferenceResource(api, { segments, query });
6664
6809
  }
6810
+ clone() {
6811
+ return super.clone();
6812
+ }
6665
6813
  //#endregion
6666
6814
  //#region Requests
6667
6815
  post(target, options) {
@@ -6790,6 +6938,9 @@ class ODataNavigationPropertyResource extends ODataResource {
6790
6938
  }
6791
6939
  return navigation;
6792
6940
  }
6941
+ clone() {
6942
+ return super.clone();
6943
+ }
6793
6944
  //#endregion
6794
6945
  key(value) {
6795
6946
  const navigation = this.clone();
@@ -6961,6 +7112,9 @@ class ODataEntityResource extends ODataResource {
6961
7112
  query === null || query === void 0 ? void 0 : query.keep(QueryOptionNames.expand, QueryOptionNames.select, QueryOptionNames.format);
6962
7113
  return new ODataEntityResource(api, { segments, query, schema });
6963
7114
  }
7115
+ clone() {
7116
+ return super.clone();
7117
+ }
6964
7118
  //#endregion
6965
7119
  key(value) {
6966
7120
  const entity = this.clone();
@@ -7000,7 +7154,7 @@ class ODataEntityResource extends ODataResource {
7000
7154
  if (castSchema !== undefined &&
7001
7155
  baseSchema !== undefined &&
7002
7156
  !castSchema.isSubtypeOf(baseSchema))
7003
- throw new Error(`Cannot cast to ${type}`);
7157
+ throw new Error(`cast: Cannot cast to ${type}`);
7004
7158
  const segments = this.cloneSegments();
7005
7159
  segments.add(PathSegmentNames.type, type).type(type);
7006
7160
  return new ODataEntityResource(this.api, {
@@ -7041,7 +7195,7 @@ class ODataEntityResource extends ODataResource {
7041
7195
  }
7042
7196
  fetch(options) {
7043
7197
  if (!this.hasKey())
7044
- return throwError('Entity resource without key');
7198
+ return throwError(() => new Error('fetch: Entity resource without key'));
7045
7199
  return this.get(options);
7046
7200
  }
7047
7201
  fetchEntity(options) {
@@ -7061,6 +7215,9 @@ class ODataEntitySetResource extends ODataResource {
7061
7215
  segment.type(schema.type());
7062
7216
  return new ODataEntitySetResource(api, { segments, query, schema });
7063
7217
  }
7218
+ clone() {
7219
+ return super.clone();
7220
+ }
7064
7221
  //#endregion
7065
7222
  entity(key) {
7066
7223
  const entity = ODataEntityResource.factory(this.api, {
@@ -7147,6 +7304,9 @@ class ODataMetadataResource extends ODataResource {
7147
7304
  segments.add(PathSegmentNames.metadata, $METADATA);
7148
7305
  return new ODataMetadataResource(api, segments);
7149
7306
  }
7307
+ clone() {
7308
+ return super.clone();
7309
+ }
7150
7310
  //#endregion
7151
7311
  //#region Requests
7152
7312
  get(options) {
@@ -7170,6 +7330,9 @@ class ODataSingletonResource extends ODataResource {
7170
7330
  segment.type(schema.type());
7171
7331
  return new ODataSingletonResource(api, { segments, query, schema });
7172
7332
  }
7333
+ clone() {
7334
+ return super.clone();
7335
+ }
7173
7336
  //#endregion
7174
7337
  key(value) {
7175
7338
  const singleton = this.clone();
@@ -7350,6 +7513,16 @@ class ODataModelEvent {
7350
7513
  : '')
7351
7514
  .join('');
7352
7515
  }
7516
+ //Identifies the current model for the event
7517
+ get currentModel() {
7518
+ const link = this.chain.find(c => ODataModelOptions.isModel(c[0]));
7519
+ return link !== undefined ? link[0] : undefined;
7520
+ }
7521
+ //Identifies the current collection for the event
7522
+ get currentCollection() {
7523
+ const link = this.chain.find(c => ODataModelOptions.isCollection(c[0]));
7524
+ return link !== undefined ? link[0] : undefined;
7525
+ }
7353
7526
  }
7354
7527
  const BUBBLING = [
7355
7528
  'change',
@@ -7651,8 +7824,8 @@ class ODataModelOptions {
7651
7824
  attach(self, resource) {
7652
7825
  if (self._resource !== null &&
7653
7826
  resource.type() !== self._resource.type() &&
7654
- !resource.isSubtypeOf(self._resource))
7655
- throw new Error(`Can't reattach ${resource.type()} to ${self._resource.type()}`);
7827
+ !self._resource.isSubtypeOf(resource))
7828
+ throw new Error(`Can't attach ${resource.type()} to ${self._resource.type()}`);
7656
7829
  const current = self._resource;
7657
7830
  if (current === null || !current.isEqualTo(resource)) {
7658
7831
  self._resource = resource;
@@ -7680,12 +7853,7 @@ class ODataModelOptions {
7680
7853
  var _a;
7681
7854
  let resource = undefined;
7682
7855
  for (let [model, field] of ODataModelOptions.chain(child)) {
7683
- resource =
7684
- resource ||
7685
- model._resource ||
7686
- (ODataModelOptions.isModel(model)
7687
- ? model._meta.modelResourceFactory()
7688
- : model._model.meta.collectionResourceFactory());
7856
+ resource = resource || model._resource;
7689
7857
  if (resource === undefined)
7690
7858
  break;
7691
7859
  if (ODataModelOptions.isModel(model)) {
@@ -7700,7 +7868,7 @@ class ODataModelOptions {
7700
7868
  }
7701
7869
  if (field === null) {
7702
7870
  const query = (_a = model._resource) === null || _a === void 0 ? void 0 : _a.cloneQuery().toQueryArguments();
7703
- if (query !== undefined)
7871
+ if (query !== undefined && resource !== undefined)
7704
7872
  resource.query((q) => q.apply(query));
7705
7873
  continue;
7706
7874
  }
@@ -7741,7 +7909,8 @@ class ODataModelOptions {
7741
7909
  self._parent = parent;
7742
7910
  }
7743
7911
  // Resource
7744
- resource = resource || this.modelResourceFactory();
7912
+ if (self._parent === null && resource === undefined)
7913
+ resource = this.modelResourceFactory();
7745
7914
  if (resource !== undefined) {
7746
7915
  this.attach(self, resource);
7747
7916
  }
@@ -7864,14 +8033,29 @@ class ODataModelOptions {
7864
8033
  (model != undefined && model.hasChanged({ include_navigation })))));
7865
8034
  }
7866
8035
  asEntity(self, func) {
7867
- const parent = self._parent;
8036
+ // Build new resource
8037
+ const query = self.resource().cloneQuery();
8038
+ let resource = this.modelResourceFactory(query);
8039
+ if (resource === undefined)
8040
+ throw new Error('Model does not have associated Entity endpoint');
8041
+ // Store parent and resource
8042
+ const store = { parent: self._parent, resource: self._resource };
8043
+ // Replace parent and resource
7868
8044
  self._parent = null;
8045
+ self._resource = resource;
8046
+ // Execute function
7869
8047
  const result = func(self);
7870
8048
  if (result instanceof Observable) {
7871
- return result.pipe(finalize(() => (self._parent = parent)));
8049
+ return result.pipe(finalize(() => {
8050
+ // Restore parent and resource
8051
+ self._parent = store.parent;
8052
+ self._resource = store.resource;
8053
+ }));
7872
8054
  }
7873
8055
  else {
7874
- self._parent = parent;
8056
+ // Restore parent and resource
8057
+ self._parent = store.parent;
8058
+ self._resource = store.resource;
7875
8059
  return result;
7876
8060
  }
7877
8061
  }
@@ -8264,14 +8448,15 @@ class ODataCollection {
8264
8448
  if (model === undefined && Klass.model !== null)
8265
8449
  model = Klass.model;
8266
8450
  if (model === undefined)
8267
- throw new Error('Collection need model');
8451
+ throw new Error('Collection: Collection need model');
8268
8452
  this._model = model;
8269
8453
  // Parent
8270
8454
  if (parent !== undefined) {
8271
8455
  this._parent = parent;
8272
8456
  }
8273
8457
  // Resource
8274
- resource = (resource || this._model.meta.collectionResourceFactory());
8458
+ if (this._parent === null && resource === undefined)
8459
+ resource = this._model.meta.collectionResourceFactory();
8275
8460
  if (resource !== undefined) {
8276
8461
  this.attach(resource);
8277
8462
  }
@@ -8300,8 +8485,8 @@ class ODataCollection {
8300
8485
  attach(resource) {
8301
8486
  if (this._resource !== null &&
8302
8487
  this._resource.type() !== resource.type() &&
8303
- !resource.isSubtypeOf(this._resource))
8304
- throw new Error(`Can't reattach ${resource.type()} to ${this._resource.type()}`);
8488
+ !this._resource.isSubtypeOf(resource))
8489
+ throw new Error(`attach: Can't reattach ${this._resource.type()} to ${resource.type()}`);
8305
8490
  this._entries.forEach(({ model }) => {
8306
8491
  const mr = this._model.meta.modelResourceFactory(resource.cloneQuery());
8307
8492
  model.attach(mr);
@@ -8317,14 +8502,29 @@ class ODataCollection {
8317
8502
  }
8318
8503
  }
8319
8504
  asEntitySet(func) {
8320
- const parent = this._parent;
8505
+ // Build new resource
8506
+ const query = this.resource().cloneQuery();
8507
+ let resource = this._model.meta.collectionResourceFactory(query);
8508
+ if (resource === undefined)
8509
+ throw new Error('asEntitySet: Collection does not have associated EntitySet endpoint');
8510
+ // Store parent and resource
8511
+ const store = { parent: this._parent, resource: this._resource };
8512
+ // Replace parent and resource
8321
8513
  this._parent = null;
8514
+ this._resource = resource;
8515
+ // Execute
8322
8516
  const result = func(this);
8323
8517
  if (result instanceof Observable) {
8324
- return result.pipe(finalize(() => (this._parent = parent)));
8518
+ return result.pipe(finalize(() => {
8519
+ // Restore
8520
+ this._parent = store.parent;
8521
+ this._resource = store.resource;
8522
+ }));
8325
8523
  }
8326
8524
  else {
8327
- this._parent = parent;
8525
+ // Restore
8526
+ this._parent = store.parent;
8527
+ this._resource = store.resource;
8328
8528
  return result;
8329
8529
  }
8330
8530
  }
@@ -8383,18 +8583,9 @@ class ODataCollection {
8383
8583
  fetch(_a = {}) {
8384
8584
  var { withCount } = _a, options = __rest(_a, ["withCount"]);
8385
8585
  const resource = this.resource();
8386
- if (resource === undefined)
8387
- return throwError('fetch: Resource is undefined');
8388
- let obs$;
8389
- if (resource instanceof ODataEntitySetResource) {
8390
- obs$ = resource.fetch(Object.assign({ withCount }, options));
8391
- }
8392
- else if (resource instanceof ODataNavigationPropertyResource) {
8393
- obs$ = resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
8394
- }
8395
- else {
8396
- obs$ = resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
8397
- }
8586
+ const obs$ = resource instanceof ODataEntitySetResource
8587
+ ? resource.fetch(Object.assign({ withCount }, options))
8588
+ : resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
8398
8589
  this.events$.emit(new ODataModelEvent('request', { collection: this, value: obs$ }));
8399
8590
  return obs$.pipe(map(({ entities, annots }) => {
8400
8591
  this._annotations = annots;
@@ -8405,10 +8596,8 @@ class ODataCollection {
8405
8596
  }
8406
8597
  fetchAll(options) {
8407
8598
  const resource = this.resource();
8408
- if (resource === undefined)
8409
- return throwError('fetchAll: Resource is undefined');
8410
8599
  if (resource instanceof ODataPropertyResource)
8411
- return throwError('fetchAll: Resource is ODataPropertyResource');
8600
+ return throwError(() => new Error('fetchAll: Resource is ODataPropertyResource'));
8412
8601
  const obs$ = resource.fetchAll(options);
8413
8602
  this.events$.emit(new ODataModelEvent('request', {
8414
8603
  collection: this,
@@ -8433,10 +8622,8 @@ class ODataCollection {
8433
8622
  save(_a = {}) {
8434
8623
  var { relModel = false, method } = _a, options = __rest(_a, ["relModel", "method"]);
8435
8624
  const resource = this.resource();
8436
- if (resource === undefined)
8437
- return throwError('saveAll: Resource is undefined');
8438
8625
  if (resource instanceof ODataPropertyResource)
8439
- return throwError('fetchAll: Resource is ODataPropertyResource');
8626
+ return throwError(() => new Error('save: Resource is ODataPropertyResource'));
8440
8627
  let toDestroyEntity = [];
8441
8628
  let toRemoveReference = [];
8442
8629
  let toDestroyContained = [];
@@ -8804,26 +8991,26 @@ class ODataCollection {
8804
8991
  return func.call(params, Object.assign({ responseType }, options));
8805
8992
  }
8806
8993
  }
8807
- return throwError(`Can't function without ODataEntitySetResource`);
8994
+ return throwError(() => new Error(`callFunction: Can't function without ODataEntitySetResource`));
8808
8995
  }
8809
8996
  callAction(name, params, responseType, _a = {}) {
8810
8997
  var options = __rest(_a, []);
8811
8998
  const resource = this.resource();
8812
- if (resource instanceof ODataEntitySetResource) {
8813
- const action = resource.action(name);
8814
- action.query((q) => q.apply(options));
8815
- switch (responseType) {
8816
- case 'property':
8817
- return action.callProperty(params, options);
8818
- case 'model':
8819
- return action.callModel(params, options);
8820
- case 'collection':
8821
- return action.callCollection(params, options);
8822
- default:
8823
- return action.call(params, Object.assign({ responseType }, options));
8824
- }
8999
+ if (!(resource instanceof ODataEntitySetResource)) {
9000
+ return throwError(() => new Error(`callAction: Can't action without ODataEntitySetResource`));
9001
+ }
9002
+ const action = resource.action(name);
9003
+ action.query((q) => q.apply(options));
9004
+ switch (responseType) {
9005
+ case 'property':
9006
+ return action.callProperty(params, options);
9007
+ case 'model':
9008
+ return action.callModel(params, options);
9009
+ case 'collection':
9010
+ return action.callCollection(params, options);
9011
+ default:
9012
+ return action.call(params, Object.assign({ responseType }, options));
8825
9013
  }
8826
- return throwError(`Can't action without ODataEntitySetResource`);
8827
9014
  }
8828
9015
  _unsubscribe(entry) {
8829
9016
  if (entry.subscription) {
@@ -8833,7 +9020,7 @@ class ODataCollection {
8833
9020
  }
8834
9021
  _subscribe(entry) {
8835
9022
  if (entry.subscription) {
8836
- throw new Error('Subscription already exists');
9023
+ throw new Error('Collection: Subscription already exists');
8837
9024
  }
8838
9025
  entry.subscription = entry.model.events$.subscribe((event) => {
8839
9026
  var _a;
@@ -8883,12 +9070,18 @@ class ODataCollection {
8883
9070
  },
8884
9071
  };
8885
9072
  }
8886
- filter(predicate) {
9073
+ filter(predicate, thisArg) {
8887
9074
  return this.models().filter(predicate);
8888
9075
  }
8889
- find(predicate) {
9076
+ map(callbackfn, thisArg) {
9077
+ return this.models().map(callbackfn, thisArg);
9078
+ }
9079
+ find(predicate, thisArg) {
8890
9080
  return this.models().find(predicate);
8891
9081
  }
9082
+ reduce(callbackfn, initialValue) {
9083
+ return this.models().reduce(callbackfn, initialValue);
9084
+ }
8892
9085
  first() {
8893
9086
  return this.models()[0];
8894
9087
  }
@@ -8996,7 +9189,7 @@ class ODataModel {
8996
9189
  this.events$ = new EventEmitter();
8997
9190
  const Klass = this.constructor;
8998
9191
  if (Klass.meta === undefined)
8999
- throw new Error(`Can't create model without metadata`);
9192
+ throw new Error(`ODataModel: Can't create model without metadata`);
9000
9193
  this._meta = Klass.meta;
9001
9194
  this._meta.bind(this, { parent, resource, annots });
9002
9195
  // Client Id
@@ -9036,19 +9229,19 @@ class ODataModel {
9036
9229
  navigationProperty(name) {
9037
9230
  const field = this._meta.field(name);
9038
9231
  if (field === undefined || !field.navigation)
9039
- throw Error(`Can't find navigation property ${name}`);
9232
+ throw Error(`navigationProperty: Can't find navigation property ${name}`);
9040
9233
  const resource = this.resource();
9041
9234
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9042
- throw Error("Can't get navigation without ODataEntityResource with key");
9235
+ throw Error("navigationProperty: Can't get navigation without ODataEntityResource with key");
9043
9236
  return field.resourceFactory(resource);
9044
9237
  }
9045
9238
  property(name) {
9046
9239
  const field = this._meta.field(name);
9047
9240
  if (field === undefined || field.navigation)
9048
- throw Error(`Can't find property ${name}`);
9241
+ throw Error(`property: Can't find property ${name}`);
9049
9242
  const resource = this.resource();
9050
9243
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9051
- throw Error("Can't get property without ODataEntityResource with key");
9244
+ throw Error("property: Can't get property without ODataEntityResource with key");
9052
9245
  return field.resourceFactory(resource);
9053
9246
  }
9054
9247
  attach(resource) {
@@ -9194,11 +9387,11 @@ class ODataModel {
9194
9387
  var options = __rest(_a, []);
9195
9388
  let resource = this.resource();
9196
9389
  if (resource === undefined)
9197
- return throwError('fetch: Resource is undefined');
9390
+ return throwError(() => new Error('fetch: Resource is undefined'));
9198
9391
  let obs$;
9199
9392
  if (resource instanceof ODataEntityResource) {
9200
9393
  if (!resource.hasKey())
9201
- return throwError("fetch: Can't fetch model without key");
9394
+ return throwError(() => new Error("fetch: Can't fetch model without key"));
9202
9395
  obs$ = resource.fetch(options);
9203
9396
  }
9204
9397
  else if (resource instanceof ODataNavigationPropertyResource) {
@@ -9213,50 +9406,46 @@ class ODataModel {
9213
9406
  var { method, navigation = false, validate = true } = _a, options = __rest(_a, ["method", "navigation", "validate"]);
9214
9407
  let resource = this.resource();
9215
9408
  if (resource === undefined)
9216
- return throwError('save: Resource is undefined');
9409
+ return throwError(() => new Error('save: Resource is undefined'));
9217
9410
  if (!(resource instanceof ODataEntityResource ||
9218
9411
  resource instanceof ODataNavigationPropertyResource))
9219
- return throwError('save: Resource type ODataEntityResource/ODataNavigationPropertyResource needed');
9412
+ return throwError(() => new Error('save: Resource type ODataEntityResource/ODataNavigationPropertyResource needed'));
9220
9413
  // Resolve method and resource key
9221
9414
  if (method === undefined && this.schema().isCompoundKey())
9222
- return throwError('save: Composite key require a specific method, use create/update/modify');
9415
+ return throwError(() => new Error('save: Composite key require a specific method, use create/update/modify'));
9223
9416
  method = method || (!resource.hasKey() ? 'create' : 'update');
9224
9417
  if (resource instanceof ODataEntityResource &&
9225
9418
  (method === 'update' || method === 'modify') &&
9226
9419
  !resource.hasKey())
9227
- return throwError('save: Update/Patch require entity key');
9420
+ return throwError(() => new Error('save: Update/Patch require entity key'));
9228
9421
  if (resource instanceof ODataNavigationPropertyResource ||
9229
9422
  method === 'create')
9230
9423
  resource.clearKey();
9231
- let obs$;
9232
- if (!validate || this.isValid({ method, navigation })) {
9233
- const _entity = this.toEntity({
9234
- changes_only: method === 'modify',
9235
- field_mapping: true,
9236
- include_concurrency: true,
9237
- include_navigation: navigation,
9238
- });
9239
- obs$ = (method === 'create'
9240
- ? resource.create(_entity, options)
9241
- : method === 'modify'
9242
- ? resource.modify(_entity, Object.assign({ etag: this.annots().etag }, options))
9243
- : resource.update(_entity, Object.assign({ etag: this.annots().etag }, options))).pipe(map(({ entity, annots }) => ({ entity: entity || _entity, annots })));
9244
- }
9245
- else {
9246
- obs$ = throwError(this._errors);
9424
+ if (validate && !this.isValid({ method, navigation })) {
9425
+ return throwError(() => new Error('save: Validation errors'));
9247
9426
  }
9248
- return this._request(obs$);
9427
+ const _entity = this.toEntity({
9428
+ changes_only: method === 'modify',
9429
+ field_mapping: true,
9430
+ include_concurrency: true,
9431
+ include_navigation: navigation,
9432
+ });
9433
+ return this._request((method === 'create'
9434
+ ? resource.create(_entity, options)
9435
+ : method === 'modify'
9436
+ ? resource.modify(_entity, Object.assign({ etag: this.annots().etag }, options))
9437
+ : resource.update(_entity, Object.assign({ etag: this.annots().etag }, options))).pipe(map(({ entity, annots }) => ({ entity: entity || _entity, annots }))));
9249
9438
  }
9250
9439
  destroy(_a = {}) {
9251
9440
  var options = __rest(_a, []);
9252
9441
  let resource = this.resource();
9253
9442
  if (resource === undefined)
9254
- return throwError('destroy: Resource is undefined');
9443
+ return throwError(() => new Error('destroy: Resource is undefined'));
9255
9444
  if (!(resource instanceof ODataEntityResource ||
9256
9445
  resource instanceof ODataNavigationPropertyResource))
9257
- return throwError('destroy: Resource type ODataEntityResource/ODataNavigationPropertyResource needed');
9446
+ return throwError(() => new Error('destroy: Resource type ODataEntityResource/ODataNavigationPropertyResource needed'));
9258
9447
  if (!resource.hasKey())
9259
- return throwError("destroy: Can't destroy model without key");
9448
+ return throwError(() => new Error("destroy: Can't destroy model without key"));
9260
9449
  const _entity = this.toEntity({ field_mapping: true });
9261
9450
  const obs$ = resource
9262
9451
  .destroy(Object.assign({ etag: this.annots().etag }, options))
@@ -9290,7 +9479,7 @@ class ODataModel {
9290
9479
  var options = __rest(_a, []);
9291
9480
  const resource = this.resource();
9292
9481
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9293
- return throwError("Can't call function without ODataEntityResource with key");
9482
+ return throwError(() => new Error("callFunction: Can't call function without ODataEntityResource with key"));
9294
9483
  const func = resource.function(name).query((q) => q.apply(options));
9295
9484
  switch (responseType) {
9296
9485
  case 'property':
@@ -9307,7 +9496,7 @@ class ODataModel {
9307
9496
  var options = __rest(_a, []);
9308
9497
  const resource = this.resource();
9309
9498
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9310
- return throwError("Can't call action without ODataEntityResource with key");
9499
+ return throwError(() => new Error("callAction: Can't call action without ODataEntityResource with key"));
9311
9500
  const action = resource.action(name).query((q) => q.apply(options));
9312
9501
  switch (responseType) {
9313
9502
  case 'property':
@@ -9324,7 +9513,7 @@ class ODataModel {
9324
9513
  cast(type) {
9325
9514
  const resource = this.resource();
9326
9515
  if (!(resource instanceof ODataEntityResource))
9327
- throw new Error(`Can't cast to derived model without ODataEntityResource`);
9516
+ throw new Error(`cast: Can't cast to derived model without ODataEntityResource`);
9328
9517
  return resource
9329
9518
  .cast(type)
9330
9519
  .asModel(this.toEntity(INCLUDE_DEEP), { annots: this.annots() });
@@ -9344,7 +9533,7 @@ class ODataModel {
9344
9533
  getValue(name, options) {
9345
9534
  const field = this._meta.field(name);
9346
9535
  if (field === undefined || field.navigation)
9347
- throw Error(`Can't find property ${name}`);
9536
+ throw Error(`getValue: Can't find property ${name}`);
9348
9537
  let value = this[name];
9349
9538
  if (value === undefined) {
9350
9539
  const prop = field.resourceFactory(this.resource());
@@ -9391,7 +9580,7 @@ class ODataModel {
9391
9580
  getReference(name) {
9392
9581
  const field = this._meta.field(name);
9393
9582
  if (field === undefined || !field.navigation)
9394
- throw Error(`Can't find navigation property ${name}`);
9583
+ throw Error(`getReference: Can't find navigation property ${name}`);
9395
9584
  let model = this[name];
9396
9585
  if (model === undefined) {
9397
9586
  const value = field.collection ? [] : this.referenced(field);
@@ -10198,9 +10387,9 @@ class ODataClient {
10198
10387
  return this.request('PUT', resource, addBody(options, body));
10199
10388
  }
10200
10389
  }
10201
- 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 });
10202
- ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataClient, providedIn: 'root' });
10203
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataClient, decorators: [{
10390
+ 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 });
10391
+ ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataClient, providedIn: 'root' });
10392
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataClient, decorators: [{
10204
10393
  type: Injectable,
10205
10394
  args: [{
10206
10395
  providedIn: 'root',
@@ -10313,7 +10502,7 @@ class ODataEntitySetService extends ODataEntityService {
10313
10502
  update(key, attrs, options) {
10314
10503
  const res = this.entity(key);
10315
10504
  if (!res.hasKey())
10316
- return throwError('Resource without key');
10505
+ return throwError(() => new Error('update: Resource without key'));
10317
10506
  return res.update(attrs, options);
10318
10507
  }
10319
10508
  /**
@@ -10326,7 +10515,7 @@ class ODataEntitySetService extends ODataEntityService {
10326
10515
  modify(key, attrs, options) {
10327
10516
  const res = this.entity(key);
10328
10517
  if (!res.hasKey())
10329
- return throwError('Resource without key');
10518
+ return throwError(() => new Error('modify: Resource without key'));
10330
10519
  return res.modify(attrs, options);
10331
10520
  }
10332
10521
  /**
@@ -10338,7 +10527,7 @@ class ODataEntitySetService extends ODataEntityService {
10338
10527
  destroy(key, options) {
10339
10528
  const res = this.entity(key);
10340
10529
  if (!res.hasKey())
10341
- return throwError('Resource without key');
10530
+ return throwError(() => new Error('destroy: Resource without key'));
10342
10531
  return res.destroy(options);
10343
10532
  }
10344
10533
  //#region Shortcuts
@@ -10369,12 +10558,12 @@ class ODataEntitySetService extends ODataEntityService {
10369
10558
  var { etag, method } = _a, options = __rest(_a, ["etag", "method"]);
10370
10559
  let schema = this.structuredTypeSchema;
10371
10560
  if (method === undefined && schema !== undefined && schema.isCompoundKey())
10372
- return throwError('Composite key require a specific method, use create/update/patch');
10561
+ return throwError(() => new Error('save: Composite key require a specific method, use create/update/patch'));
10373
10562
  let key = schema && schema.resolveKey(attrs);
10374
10563
  if (method === undefined)
10375
10564
  method = key !== undefined ? 'update' : 'create';
10376
10565
  if ((method === 'update' || method === 'modify') && key === undefined)
10377
- return throwError("Can't update/patch entity without key");
10566
+ return throwError(() => new Error("save: Can't update/patch entity without key"));
10378
10567
  return method === 'create'
10379
10568
  ? this.create(attrs, options)
10380
10569
  : method === 'modify'
@@ -10452,9 +10641,9 @@ class ODataServiceFactory {
10452
10641
  })(this.client, singletonName, apiNameOrEntityType);
10453
10642
  }
10454
10643
  }
10455
- ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10456
- ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory });
10457
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory, decorators: [{
10644
+ ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10645
+ ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataServiceFactory });
10646
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataServiceFactory, decorators: [{
10458
10647
  type: Injectable
10459
10648
  }], ctorParameters: function () { return [{ type: ODataClient }]; } });
10460
10649
 
@@ -10478,10 +10667,10 @@ class ODataModule {
10478
10667
  };
10479
10668
  }
10480
10669
  }
10481
- ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10482
- ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10483
- ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10484
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, decorators: [{
10670
+ ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10671
+ ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10672
+ ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10673
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, decorators: [{
10485
10674
  type: NgModule,
10486
10675
  args: [{
10487
10676
  imports: [HttpClientModule],