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
@@ -33,6 +33,7 @@ var QueryOptionNames;
33
33
  QueryOptionNames["skip"] = "skip";
34
34
  QueryOptionNames["skiptoken"] = "skiptoken";
35
35
  QueryOptionNames["format"] = "format";
36
+ QueryOptionNames["levels"] = "levels";
36
37
  QueryOptionNames["count"] = "count";
37
38
  })(QueryOptionNames || (QueryOptionNames = {}));
38
39
  const NONE_PARSER = {
@@ -213,7 +214,7 @@ class ODataCache {
213
214
  return of(cached);
214
215
  }
215
216
  else {
216
- return throwError('No Cached');
217
+ return throwError(() => new Error('No Cached'));
217
218
  }
218
219
  }
219
220
  if (policy === 'cache-first' ||
@@ -390,7 +391,7 @@ function buildPathAndQuery({ select, search, skiptoken, format, top, skip, filte
390
391
  }
391
392
  if (func) {
392
393
  if (typeof func === 'string') {
393
- path += `/${func}`;
394
+ path += `/${func}()`;
394
395
  }
395
396
  else if (typeof func === 'object') {
396
397
  const [funcName] = Object.keys(func);
@@ -398,10 +399,7 @@ function buildPathAndQuery({ select, search, skiptoken, format, top, skip, filte
398
399
  aliases,
399
400
  escape,
400
401
  });
401
- path += `/${funcName}`;
402
- if (funcArgs !== '') {
403
- path += `(${funcArgs})`;
404
- }
402
+ path += `/${funcName}(${funcArgs})`;
405
403
  }
406
404
  }
407
405
  if (aliases.length > 0) {
@@ -745,6 +743,7 @@ function buildExpand(expands, { aliases, escape = false }) {
745
743
  case 'levels':
746
744
  case 'count':
747
745
  case 'top':
746
+ case 'skip':
748
747
  value = `${expands[key]}`;
749
748
  break;
750
749
  default:
@@ -1331,6 +1330,10 @@ const Objects = {
1331
1330
  if (typeof target != 'object' || target == null) {
1332
1331
  return target;
1333
1332
  }
1333
+ if (Types.isObject(target) && 'clone' in target) {
1334
+ // target is a cloneable object
1335
+ return target.clone();
1336
+ }
1334
1337
  const type = Types.rawType(target);
1335
1338
  let cloneTarget = null;
1336
1339
  if (map.get(target)) {
@@ -1461,17 +1464,33 @@ class Field$1 {
1461
1464
  constructor(name = '') {
1462
1465
  this.name = name;
1463
1466
  }
1464
- static factory() {
1465
- const h = new Field$1();
1466
- return new Proxy({ _name: '' }, h);
1467
+ static factory(name = '') {
1468
+ return new Proxy({ _name: name }, new Field$1());
1467
1469
  }
1468
- get(target, p) {
1470
+ get(target, key) {
1469
1471
  let name = target['_name'];
1470
- if (p === 'render') {
1472
+ if (key === 'render') {
1471
1473
  return ({ prefix }) => prefix ? `${prefix}/${name}` : name;
1472
1474
  }
1473
- name = name ? `${name}/${p}` : p;
1474
- return new Proxy({ _name: name }, this);
1475
+ else if (key === 'clone') {
1476
+ return () => Field$1.factory(name);
1477
+ }
1478
+ else if (key === Symbol.toStringTag) {
1479
+ return () => 'Field';
1480
+ }
1481
+ else if (key === 'toJSON') {
1482
+ return () => ({
1483
+ $type: Types.rawType(this),
1484
+ name: name,
1485
+ });
1486
+ }
1487
+ else {
1488
+ name = name ? `${name}/${key}` : key;
1489
+ return new Proxy({ _name: name }, this);
1490
+ }
1491
+ }
1492
+ has(target, key) {
1493
+ return ['toJSON', 'clone', 'render'].includes(key) || key in target;
1475
1494
  }
1476
1495
  }
1477
1496
  function applyMixins(derivedCtor, constructors) {
@@ -1510,6 +1529,7 @@ class Function {
1510
1529
  }
1511
1530
  toJSON() {
1512
1531
  return {
1532
+ $type: Types.rawType(this),
1513
1533
  name: this.name,
1514
1534
  values: this.values,
1515
1535
  normalize: this.normalize,
@@ -1518,12 +1538,15 @@ class Function {
1518
1538
  render({ aliases, escape, prefix, }) {
1519
1539
  let [field, ...values] = this.values;
1520
1540
  field = render(field, { aliases, escape, prefix });
1521
- let params = [
1541
+ const params = [
1522
1542
  field,
1523
1543
  ...values.map((v) => render(v, { aliases, escape, prefix, normalize: this.normalize })),
1524
1544
  ];
1525
1545
  return `${this.name}(${params.join(', ')})`;
1526
1546
  }
1547
+ clone() {
1548
+ return new Function(this.name, this.values.map((v) => Objects.clone(v)), this.normalize, this.escape);
1549
+ }
1527
1550
  }
1528
1551
  class StringAndCollectionFunctions {
1529
1552
  concat(field, value, normalize) {
@@ -1664,6 +1687,7 @@ class Operator {
1664
1687
  }
1665
1688
  toJSON() {
1666
1689
  return {
1690
+ $type: Types.rawType(this),
1667
1691
  op: this.op,
1668
1692
  values: this.values,
1669
1693
  normalize: this.normalize,
@@ -1692,6 +1716,9 @@ class Operator {
1692
1716
  }
1693
1717
  return `${this.op}(${left})`;
1694
1718
  }
1719
+ clone() {
1720
+ return new Operator(this.op, this.values.map((v) => Objects.clone(v)), this.normalize);
1721
+ }
1695
1722
  }
1696
1723
  class LogicalOperators {
1697
1724
  eq(left, right, normalize) {
@@ -1759,12 +1786,16 @@ class Grouping {
1759
1786
  }
1760
1787
  toJSON() {
1761
1788
  return {
1789
+ $type: Types.rawType(this),
1762
1790
  group: this.group.toJSON(),
1763
1791
  };
1764
1792
  }
1765
1793
  render({ aliases, escape, prefix, }) {
1766
1794
  return `(${render(this.group, { aliases, escape, prefix })})`;
1767
1795
  }
1796
+ clone() {
1797
+ return new Grouping(Objects.clone(this.group));
1798
+ }
1768
1799
  }
1769
1800
  class Lambda {
1770
1801
  constructor(op, values, alias) {
@@ -1777,6 +1808,7 @@ class Lambda {
1777
1808
  }
1778
1809
  toJSON() {
1779
1810
  return {
1811
+ $type: Types.rawType(this),
1780
1812
  op: this.op,
1781
1813
  values: this.values,
1782
1814
  alias: this.alias,
@@ -1792,6 +1824,9 @@ class Lambda {
1792
1824
  prefix: alias,
1793
1825
  })})`;
1794
1826
  }
1827
+ clone() {
1828
+ return new Lambda(this.op, this.values.map((v) => Objects.clone(v)), this.alias);
1829
+ }
1795
1830
  }
1796
1831
  class LambdaOperators {
1797
1832
  any(field, value, alias) {
@@ -1838,16 +1873,23 @@ class ComputeExpression extends Expression {
1838
1873
  static s() {
1839
1874
  return Field$1.factory();
1840
1875
  }
1841
- static compute(opts) {
1876
+ static compute(opts, current) {
1842
1877
  return opts({
1843
1878
  s: ComputeExpression.s(),
1844
1879
  e: ComputeExpression.e,
1845
- });
1880
+ }, current);
1846
1881
  }
1847
1882
  render({ aliases, escape, prefix, } = {}) {
1848
- let children = this._children
1849
- .map((n) => n.render({ aliases, escape, prefix }));
1850
- return this.names.map((name, index) => `${children[index]} as ${name}`).join(',');
1883
+ let children = this._children.map((n) => n.render({ aliases, escape, prefix }));
1884
+ return this.names
1885
+ .map((name, index) => `${children[index]} as ${name}`)
1886
+ .join(',');
1887
+ }
1888
+ clone() {
1889
+ return new ComputeExpression({
1890
+ children: this._children.map((c) => c.clone()),
1891
+ names: [...this.names],
1892
+ });
1851
1893
  }
1852
1894
  _add(name, node) {
1853
1895
  this.names.push(name);
@@ -1875,13 +1917,13 @@ class FilterExpression extends Expression {
1875
1917
  static e(connector = 'and') {
1876
1918
  return new FilterExpression({ connector });
1877
1919
  }
1878
- static filter(opts) {
1920
+ static filter(opts, current) {
1879
1921
  return opts({
1880
1922
  s: FilterExpression.s(),
1881
1923
  e: FilterExpression.e,
1882
1924
  o: operators,
1883
1925
  f: functions,
1884
- });
1926
+ }, current);
1885
1927
  }
1886
1928
  toJSON() {
1887
1929
  return {
@@ -1905,6 +1947,13 @@ class FilterExpression extends Expression {
1905
1947
  }
1906
1948
  return content;
1907
1949
  }
1950
+ clone() {
1951
+ return new FilterExpression({
1952
+ children: this._children.map((c) => c.clone()),
1953
+ connector: this._connector,
1954
+ negated: this._negated,
1955
+ });
1956
+ }
1908
1957
  _add(node, connector) {
1909
1958
  if (connector !== undefined && this._connector !== connector) {
1910
1959
  let children = [];
@@ -2031,6 +2080,9 @@ class OrderByField {
2031
2080
  render({ aliases, escape, prefix, }) {
2032
2081
  return `${render(this.field, { aliases, escape, prefix })} ${this.order}`;
2033
2082
  }
2083
+ clone() {
2084
+ return new OrderByField(this.field.clone(), this.order);
2085
+ }
2034
2086
  }
2035
2087
  class OrderByExpression extends Expression {
2036
2088
  constructor({ children, } = {}) {
@@ -2042,11 +2094,11 @@ class OrderByExpression extends Expression {
2042
2094
  static s() {
2043
2095
  return Field$1.factory();
2044
2096
  }
2045
- static orderBy(opts) {
2097
+ static orderBy(opts, current) {
2046
2098
  return opts({
2047
2099
  s: OrderByExpression.s(),
2048
2100
  e: OrderByExpression.e,
2049
- });
2101
+ }, current);
2050
2102
  }
2051
2103
  _add(node) {
2052
2104
  this._children.push(node);
@@ -2058,6 +2110,11 @@ class OrderByExpression extends Expression {
2058
2110
  .join(`,`);
2059
2111
  return content;
2060
2112
  }
2113
+ clone() {
2114
+ return new OrderByExpression({
2115
+ children: this._children.map((c) => c.clone()),
2116
+ });
2117
+ }
2061
2118
  ascending(field) {
2062
2119
  return this._add(new OrderByField(field, 'asc'));
2063
2120
  }
@@ -2075,12 +2132,16 @@ class SearchTerm {
2075
2132
  }
2076
2133
  toJSON() {
2077
2134
  return {
2135
+ $type: Types.rawType(this),
2078
2136
  value: this.value,
2079
2137
  };
2080
2138
  }
2081
2139
  render({ aliases, escape, prefix, }) {
2082
2140
  return `${render(this.value, { aliases, escape, prefix })}`;
2083
2141
  }
2142
+ clone() {
2143
+ return new SearchTerm(this.value);
2144
+ }
2084
2145
  }
2085
2146
  class SearchExpression extends Expression {
2086
2147
  constructor({ children, connector, negated, } = {}) {
@@ -2091,10 +2152,10 @@ class SearchExpression extends Expression {
2091
2152
  static e(connector = 'AND') {
2092
2153
  return new SearchExpression({ connector });
2093
2154
  }
2094
- static search(opts) {
2155
+ static search(opts, current) {
2095
2156
  return opts({
2096
2157
  e: SearchExpression.e,
2097
- });
2158
+ }, current);
2098
2159
  }
2099
2160
  _add(node, connector) {
2100
2161
  if (connector !== undefined && this._connector !== connector) {
@@ -2145,6 +2206,13 @@ class SearchExpression extends Expression {
2145
2206
  .join(` ${this._connector} `);
2146
2207
  return content;
2147
2208
  }
2209
+ clone() {
2210
+ return new SearchExpression({
2211
+ children: this._children.map((c) => c.clone()),
2212
+ connector: this._connector,
2213
+ negated: this._negated,
2214
+ });
2215
+ }
2148
2216
  toJSON() {
2149
2217
  return {
2150
2218
  children: this._children.map((c) => c.toJSON()),
@@ -2177,9 +2245,45 @@ class SearchExpression extends Expression {
2177
2245
  }
2178
2246
  }
2179
2247
 
2248
+ class SelectExpression extends Expression {
2249
+ constructor({ children, } = {}) {
2250
+ super({ children });
2251
+ }
2252
+ static e() {
2253
+ return new SelectExpression();
2254
+ }
2255
+ static s() {
2256
+ return Field$1.factory();
2257
+ }
2258
+ static select(builder, current) {
2259
+ return builder({
2260
+ s: SelectExpression.s(),
2261
+ e: SelectExpression.e,
2262
+ }, current);
2263
+ }
2264
+ render({ aliases, escape, prefix, } = {}) {
2265
+ return this._children
2266
+ .map((n) => n.render({ aliases, escape, prefix }))
2267
+ .join(',');
2268
+ }
2269
+ clone() {
2270
+ return new SelectExpression({
2271
+ children: this._children.map((c) => c.clone()),
2272
+ });
2273
+ }
2274
+ _add(node) {
2275
+ this._children.push(node);
2276
+ return this;
2277
+ }
2278
+ field(field) {
2279
+ return this._add(field);
2280
+ }
2281
+ }
2282
+
2180
2283
  class ExpandField {
2181
- constructor(field) {
2284
+ constructor(field, values = {}) {
2182
2285
  this.field = field;
2286
+ this.values = values;
2183
2287
  }
2184
2288
  get [Symbol.toStringTag]() {
2185
2289
  return 'ExpandField';
@@ -2190,14 +2294,66 @@ class ExpandField {
2190
2294
  };
2191
2295
  }
2192
2296
  render({ aliases, escape, prefix, }) {
2193
- return `${render(this.field, { aliases, escape, prefix })}`;
2297
+ const params = [
2298
+ QueryOptionNames.select,
2299
+ QueryOptionNames.expand,
2300
+ QueryOptionNames.filter,
2301
+ QueryOptionNames.search,
2302
+ QueryOptionNames.orderBy,
2303
+ QueryOptionNames.skip,
2304
+ QueryOptionNames.top,
2305
+ QueryOptionNames.levels,
2306
+ ]
2307
+ .filter((key) => !Types.isEmpty(this.values[key]))
2308
+ .reduce((acc, key) => {
2309
+ let value = this.values[key];
2310
+ if (Types.rawType(value).endsWith('Expression')) {
2311
+ value = value.render({ aliases, prefix, escape });
2312
+ }
2313
+ return Object.assign(acc, { [key]: value });
2314
+ }, {});
2315
+ let expand = `${render(this.field, { aliases, escape, prefix })}`;
2316
+ if (!Types.isEmpty(params)) {
2317
+ expand = `${expand}(${Object.keys(params)
2318
+ .map((key) => `$${key}=${params[key]}`)
2319
+ .join(';')})`;
2320
+ }
2321
+ return expand;
2322
+ }
2323
+ clone() {
2324
+ const values = Object.keys(this.values).reduce((acc, key) => Object.assign(acc, { [key]: Objects.clone(this.values[key]) }), {});
2325
+ return new ExpandField(this.field.clone(), values);
2326
+ }
2327
+ select(opts) {
2328
+ return this.option(QueryOptionNames.select, SelectExpression.select(opts, this.values[QueryOptionNames.select]));
2329
+ }
2330
+ expand(opts) {
2331
+ return this.option(QueryOptionNames.expand, ExpandExpression.expand(opts, this.values[QueryOptionNames.expand]));
2332
+ }
2333
+ filter(opts) {
2334
+ return this.option(QueryOptionNames.filter, FilterExpression.filter(opts, this.values[QueryOptionNames.filter]));
2335
+ }
2336
+ search(opts) {
2337
+ return this.option(QueryOptionNames.search, SearchExpression.search(opts, this.values[QueryOptionNames.search]));
2338
+ }
2339
+ orderBy(opts) {
2340
+ return this.option(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts, this.values[QueryOptionNames.orderBy]));
2341
+ }
2342
+ skip(n) {
2343
+ return this.option(QueryOptionNames.skip, n);
2344
+ }
2345
+ top(n) {
2346
+ return this.option(QueryOptionNames.top, n);
2347
+ }
2348
+ levels(n) {
2349
+ return this.option(QueryOptionNames.levels, n);
2350
+ }
2351
+ // Option Handler
2352
+ option(name, opts) {
2353
+ if (opts !== undefined)
2354
+ this.values[name] = opts;
2355
+ return this.values[name];
2194
2356
  }
2195
- select() { }
2196
- filter() { }
2197
- levels() { }
2198
- orderBy() { }
2199
- top() { }
2200
- skip() { }
2201
2357
  }
2202
2358
  class ExpandExpression extends Expression {
2203
2359
  constructor({ children, } = {}) {
@@ -2209,17 +2365,22 @@ class ExpandExpression extends Expression {
2209
2365
  static s() {
2210
2366
  return Field$1.factory();
2211
2367
  }
2212
- static expand(opts) {
2368
+ static expand(opts, current) {
2213
2369
  return opts({
2214
2370
  s: ExpandExpression.s(),
2215
2371
  e: ExpandExpression.e,
2216
- });
2372
+ }, current);
2217
2373
  }
2218
2374
  render({ aliases, escape, prefix, } = {}) {
2219
2375
  return this._children
2220
2376
  .map((n) => n.render({ aliases, escape, prefix }))
2221
2377
  .join(',');
2222
2378
  }
2379
+ clone() {
2380
+ return new ExpandExpression({
2381
+ children: this._children.map((c) => c.clone()),
2382
+ });
2383
+ }
2223
2384
  _add(node) {
2224
2385
  this._children.push(node);
2225
2386
  return this;
@@ -2232,36 +2393,6 @@ class ExpandExpression extends Expression {
2232
2393
  }
2233
2394
  }
2234
2395
 
2235
- class SelectExpression extends Expression {
2236
- constructor({ children, } = {}) {
2237
- super({ children });
2238
- }
2239
- static e() {
2240
- return new SelectExpression();
2241
- }
2242
- static s() {
2243
- return Field$1.factory();
2244
- }
2245
- static select(opts) {
2246
- return opts({
2247
- s: SelectExpression.s(),
2248
- e: SelectExpression.e,
2249
- });
2250
- }
2251
- render({ aliases, escape, prefix, } = {}) {
2252
- return this._children
2253
- .map((n) => n.render({ aliases, escape, prefix }))
2254
- .join(',');
2255
- }
2256
- _add(node) {
2257
- this._children.push(node);
2258
- return this;
2259
- }
2260
- field(field) {
2261
- return this._add(field);
2262
- }
2263
- }
2264
-
2265
2396
  class ODataQueryOptionHandler {
2266
2397
  constructor(o, n) {
2267
2398
  this.o = o;
@@ -2359,19 +2490,19 @@ class ODataQueryOptionsHandler {
2359
2490
  }
2360
2491
  select(opts) {
2361
2492
  if (Types.isFunction(opts)) {
2362
- return this.options.expression(QueryOptionNames.select, SelectExpression.select(opts));
2493
+ return this.options.expression(QueryOptionNames.select, SelectExpression.select(opts, this.options.expression(QueryOptionNames.select)));
2363
2494
  }
2364
2495
  return this.options.option(QueryOptionNames.select, opts);
2365
2496
  }
2366
2497
  expand(opts) {
2367
2498
  if (Types.isFunction(opts)) {
2368
- return this.options.expression(QueryOptionNames.expand, ExpandExpression.expand(opts));
2499
+ return this.options.expression(QueryOptionNames.expand, ExpandExpression.expand(opts, this.options.expression(QueryOptionNames.expand)));
2369
2500
  }
2370
2501
  return this.options.option(QueryOptionNames.expand, opts);
2371
2502
  }
2372
2503
  compute(opts) {
2373
2504
  if (Types.isFunction(opts)) {
2374
- return this.options.expression(QueryOptionNames.compute, ComputeExpression.compute(opts));
2505
+ return this.options.expression(QueryOptionNames.compute, ComputeExpression.compute(opts, this.options.expression(QueryOptionNames.compute)));
2375
2506
  }
2376
2507
  return this.options.option(QueryOptionNames.compute, opts);
2377
2508
  }
@@ -2383,19 +2514,19 @@ class ODataQueryOptionsHandler {
2383
2514
  }
2384
2515
  search(opts) {
2385
2516
  if (Types.isFunction(opts)) {
2386
- return this.options.expression(QueryOptionNames.search, SearchExpression.search(opts));
2517
+ return this.options.expression(QueryOptionNames.search, SearchExpression.search(opts, this.options.expression(QueryOptionNames.search)));
2387
2518
  }
2388
2519
  return this.options.option(QueryOptionNames.search, opts);
2389
2520
  }
2390
2521
  filter(opts) {
2391
2522
  if (Types.isFunction(opts)) {
2392
- return this.options.expression(QueryOptionNames.filter, FilterExpression.filter(opts));
2523
+ return this.options.expression(QueryOptionNames.filter, FilterExpression.filter(opts, this.options.expression(QueryOptionNames.filter)));
2393
2524
  }
2394
2525
  return this.options.option(QueryOptionNames.filter, opts);
2395
2526
  }
2396
2527
  orderBy(opts) {
2397
2528
  if (Types.isFunction(opts)) {
2398
- return this.options.expression(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts));
2529
+ return this.options.option(QueryOptionNames.orderBy, OrderByExpression.orderBy(opts, this.options.expression(QueryOptionNames.orderBy)));
2399
2530
  }
2400
2531
  return this.options.option(QueryOptionNames.orderBy, opts);
2401
2532
  }
@@ -2423,22 +2554,22 @@ class ODataQueryOptionsHandler {
2423
2554
  }
2424
2555
  apply(query) {
2425
2556
  if (query.select !== undefined) {
2426
- this.select(query.select);
2557
+ this.options.option(QueryOptionNames.select, query.select);
2427
2558
  }
2428
2559
  if (query.expand !== undefined) {
2429
- this.expand(query.expand);
2560
+ this.options.option(QueryOptionNames.expand, query.expand);
2430
2561
  }
2431
2562
  if (query.transform !== undefined) {
2432
- this.transform(query.transform);
2563
+ this.options.option(QueryOptionNames.transform, query.transform);
2433
2564
  }
2434
2565
  if (query.search !== undefined) {
2435
- this.search(query.search);
2566
+ this.options.option(QueryOptionNames.search, query.search);
2436
2567
  }
2437
2568
  if (query.filter !== undefined) {
2438
- this.filter(query.filter);
2569
+ this.options.option(QueryOptionNames.filter, query.filter);
2439
2570
  }
2440
2571
  if (query.orderBy !== undefined) {
2441
- this.orderBy(query.orderBy);
2572
+ this.options.option(QueryOptionNames.orderBy, query.orderBy);
2442
2573
  }
2443
2574
  this.paging(query);
2444
2575
  }
@@ -2446,7 +2577,7 @@ class ODataQueryOptionsHandler {
2446
2577
 
2447
2578
  class ODataQueryOptions {
2448
2579
  constructor(options) {
2449
- this.options = options || {};
2580
+ this.values = options || {};
2450
2581
  }
2451
2582
  // Params
2452
2583
  pathAndParams(escape = false) {
@@ -2464,11 +2595,11 @@ class ODataQueryOptions {
2464
2595
  QueryOptionNames.expand,
2465
2596
  QueryOptionNames.format,
2466
2597
  ]
2467
- .filter((key) => !Types.isEmpty(this.options[key]))
2598
+ .filter((key) => !Types.isEmpty(this.values[key]))
2468
2599
  .reduce((acc, key) => {
2469
- let value = this.options[key];
2470
- if (Types.rawType(value) === 'Expression') {
2471
- value = value.render(aliases);
2600
+ let value = this.values[key];
2601
+ if (Types.rawType(value).endsWith('Expression')) {
2602
+ value = value.render({ aliases });
2472
2603
  }
2473
2604
  return Object.assign(acc, { [key]: value });
2474
2605
  }, {});
@@ -2483,63 +2614,60 @@ class ODataQueryOptions {
2483
2614
  .join('&'));
2484
2615
  }
2485
2616
  toJSON() {
2486
- return Object.keys(this.options).reduce((acc, key) => {
2487
- let value = this.options[key];
2488
- if (Types.rawType(value) === 'Expression') {
2489
- value = value.toJSON();
2490
- }
2617
+ return Object.keys(this.values).reduce((acc, key) => {
2618
+ let value = this.values[key];
2619
+ value =
2620
+ Types.isObject(value) && 'toJSON' in value ? value.toJSON() : value;
2491
2621
  return Object.assign(acc, { [key]: value });
2492
2622
  }, {});
2493
2623
  }
2494
2624
  toQueryArguments() {
2495
2625
  return {
2496
- select: this.options[QueryOptionNames.select],
2497
- expand: this.options[QueryOptionNames.expand],
2498
- transform: this.options[QueryOptionNames.transform],
2499
- compute: this.options[QueryOptionNames.compute],
2500
- search: this.options[QueryOptionNames.search],
2501
- filter: this.options[QueryOptionNames.filter],
2502
- orderBy: this.options[QueryOptionNames.orderBy],
2503
- top: this.options[QueryOptionNames.top],
2504
- skip: this.options[QueryOptionNames.skip],
2505
- skiptoken: this.options[QueryOptionNames.skiptoken],
2626
+ select: this.values[QueryOptionNames.select],
2627
+ expand: this.values[QueryOptionNames.expand],
2628
+ transform: this.values[QueryOptionNames.transform],
2629
+ compute: this.values[QueryOptionNames.compute],
2630
+ search: this.values[QueryOptionNames.search],
2631
+ filter: this.values[QueryOptionNames.filter],
2632
+ orderBy: this.values[QueryOptionNames.orderBy],
2633
+ top: this.values[QueryOptionNames.top],
2634
+ skip: this.values[QueryOptionNames.skip],
2635
+ skiptoken: this.values[QueryOptionNames.skiptoken],
2506
2636
  };
2507
2637
  }
2508
2638
  clone() {
2509
- const options = Object.keys(this.options).reduce((acc, key) => {
2510
- let value = this.options[key];
2511
- if (Types.rawType(value) !== 'Expression') {
2512
- value = Objects.clone(value);
2513
- }
2514
- return Object.assign(acc, { [key]: value });
2515
- }, {});
2639
+ const options = Object.keys(this.values).reduce((acc, key) => Object.assign(acc, { [key]: Objects.clone(this.values[key]) }), {});
2516
2640
  return new ODataQueryOptions(options);
2517
2641
  }
2518
2642
  // Set Renderable
2519
2643
  expression(name, exp) {
2520
- return (this.options[name] = exp);
2644
+ if (exp !== undefined)
2645
+ this.values[name] = exp;
2646
+ return this.values[name];
2521
2647
  }
2522
2648
  // Option Handler
2523
2649
  option(name, opts) {
2524
2650
  if (opts !== undefined)
2525
- this.options[name] = opts;
2526
- return new ODataQueryOptionHandler(this.options, name);
2651
+ this.values[name] = opts;
2652
+ return new ODataQueryOptionHandler(this.values, name);
2527
2653
  }
2528
2654
  // Query Options tools
2529
2655
  has(name) {
2530
- return this.options[name] !== undefined;
2656
+ return this.values[name] !== undefined;
2531
2657
  }
2532
2658
  remove(...names) {
2533
- names.forEach((name) => this.option(name).clear());
2659
+ names.forEach((name) => {
2660
+ delete this.values[name];
2661
+ });
2534
2662
  }
2535
2663
  keep(...names) {
2536
- this.options = Object.keys(this.options)
2664
+ this.values = Object.keys(this.values)
2537
2665
  .filter((k) => names.indexOf(k) !== -1)
2538
- .reduce((acc, k) => Object.assign(acc, { [k]: this.options[k] }), {});
2666
+ .reduce((acc, k) => Object.assign(acc, { [k]: this.values[k] }), {});
2539
2667
  }
2540
2668
  // Clear
2541
2669
  clear() {
2542
- this.options = {};
2670
+ this.values = {};
2543
2671
  }
2544
2672
  }
2545
2673
 
@@ -2969,7 +3097,7 @@ class ODataSchemaElement extends ODataAnnotatable {
2969
3097
  return names.indexOf(type) !== -1;
2970
3098
  }
2971
3099
  /**
2972
- * Returns a boolean indicating if the structured type is a sub type of the given type.
3100
+ * Returns a boolean indicating if the structured type is a subtype of the given type.
2973
3101
  * @param type String representation of the type
2974
3102
  * @returns True if the callable is type of the given type
2975
3103
  */
@@ -2978,6 +3106,16 @@ class ODataSchemaElement extends ODataAnnotatable {
2978
3106
  return true;
2979
3107
  return false;
2980
3108
  }
3109
+ /**
3110
+ * Returns a boolean indicating if the structured type is a supertype of the given type.
3111
+ * @param type String representation of the type
3112
+ * @returns True if the callable is type of the given type
3113
+ */
3114
+ isSupertypeOf(schema) {
3115
+ if (this.isTypeOf(schema.type()))
3116
+ return true;
3117
+ return false;
3118
+ }
2981
3119
  }
2982
3120
 
2983
3121
  //https://github.com/niklasvh/base64-arraybuffer
@@ -3389,7 +3527,7 @@ class ODataApiOptions {
3389
3527
  constructor(config) {
3390
3528
  this.etag = { ifMatch: true, ifNoneMatch: false };
3391
3529
  this.version = config.version || DEFAULT_VERSION;
3392
- this.stringAsEnum = config.stringAsEnum;
3530
+ this.stringAsEnum = config.stringAsEnum || false;
3393
3531
  this.params = config.params || {};
3394
3532
  this.headers = config.headers || {};
3395
3533
  this.withCredentials = config.withCredentials;
@@ -3400,6 +3538,8 @@ class ODataApiOptions {
3400
3538
  Object.assign(this.etag, config.etag || {});
3401
3539
  this.prefer = config.prefer;
3402
3540
  this.deleteRefBy = config.deleteRefBy || 'path';
3541
+ this.nonParenthesisForEmptyParameterFunction =
3542
+ config.nonParenthesisForEmptyParameterFunction || false;
3403
3543
  }
3404
3544
  get helper() {
3405
3545
  return ODataHelper[this.version];
@@ -3408,7 +3548,6 @@ class ODataApiOptions {
3408
3548
  class ODataParserOptions {
3409
3549
  constructor(config) {
3410
3550
  this.version = config.version || DEFAULT_VERSION;
3411
- this.stringAsEnum = config.stringAsEnum;
3412
3551
  }
3413
3552
  get helper() {
3414
3553
  return ODataHelper[this.version];
@@ -3444,7 +3583,8 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3444
3583
  ttitelize(term) {
3445
3584
  return (term && this.annotatedValue(term)) || Strings.titleCase(this.name);
3446
3585
  }
3447
- configure({ options }) {
3586
+ configure({ stringAsEnum, options }) {
3587
+ this.stringAsEnum = stringAsEnum;
3448
3588
  this.optionsHelper = options;
3449
3589
  }
3450
3590
  isTypeOf(type) {
@@ -3475,13 +3615,13 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3475
3615
  : this.optionsHelper;
3476
3616
  if (this.flags) {
3477
3617
  const names = Enums.toNames(this.members, value);
3478
- return !parserOptions?.stringAsEnum
3618
+ return !this.stringAsEnum
3479
3619
  ? `${this.namespace}.${this.name}'${names.join(', ')}'`
3480
3620
  : names.join(', ');
3481
3621
  }
3482
3622
  else {
3483
3623
  const name = Enums.toName(this.members, value);
3484
- return !parserOptions?.stringAsEnum
3624
+ return !this.stringAsEnum
3485
3625
  ? `${this.namespace}.${this.name}'${name}'`
3486
3626
  : name;
3487
3627
  }
@@ -3492,7 +3632,7 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3492
3632
  ? new ODataParserOptions(options)
3493
3633
  : this.optionsHelper;
3494
3634
  const serialized = this.serialize(value, parserOptions);
3495
- return parserOptions?.stringAsEnum
3635
+ return this.stringAsEnum
3496
3636
  ? raw(`'${serialized}'`)
3497
3637
  : raw(serialized);
3498
3638
  }
@@ -4020,7 +4160,8 @@ class ODataCallableParser {
4020
4160
  [p.name]: p.encode(params[p.name], parserOptions),
4021
4161
  }), {});
4022
4162
  }
4023
- configure({ parserForType, options, }) {
4163
+ configure({ nonParenthesisForEmptyParameterFunction, parserForType, options, }) {
4164
+ this.nonParenthesisForEmptyParameterFunction = nonParenthesisForEmptyParameterFunction;
4024
4165
  this.optionsHelper = options;
4025
4166
  if (this.return)
4026
4167
  this.parser = parserForType(this.return.type) || NONE_PARSER;
@@ -4053,7 +4194,11 @@ class ODataCallable extends ODataSchemaElement {
4053
4194
  return path;
4054
4195
  }
4055
4196
  configure({ parserForType, }) {
4056
- this.parser.configure({ options: this.api.options, parserForType });
4197
+ this.parser.configure({
4198
+ nonParenthesisForEmptyParameterFunction: this.api.options.nonParenthesisForEmptyParameterFunction,
4199
+ options: this.api.options,
4200
+ parserForType
4201
+ });
4057
4202
  }
4058
4203
  /**
4059
4204
  * Deseialize the given value from the callable.
@@ -4113,7 +4258,7 @@ class ODataEnumType extends ODataSchemaElement {
4113
4258
  this.parser = new ODataEnumTypeParser(config, schema.namespace, schema.alias);
4114
4259
  }
4115
4260
  configure() {
4116
- this.parser.configure({ options: this.api.options });
4261
+ this.parser.configure({ stringAsEnum: this.api.options.stringAsEnum, options: this.api.options });
4117
4262
  }
4118
4263
  /**
4119
4264
  * Returns the fields of the enum type.
@@ -4138,6 +4283,14 @@ class ODataEnumType extends ODataSchemaElement {
4138
4283
  findFieldByValue(value) {
4139
4284
  return this.fields().find((f) => f.value === value);
4140
4285
  }
4286
+ /**
4287
+ * Find a fields by flag.
4288
+ * @param value The value of the field
4289
+ * @returns The fields with the given flag
4290
+ */
4291
+ findFieldsByValue(value) {
4292
+ return this.fields().filter((f) => Boolean(f.value & value));
4293
+ }
4141
4294
  /**
4142
4295
  * Map the fields of the enum type.
4143
4296
  * @param mapper Function that maps the value to the new value
@@ -4209,7 +4362,7 @@ class ODataStructuredType extends ODataSchemaElement {
4209
4362
  }
4210
4363
  }
4211
4364
  /**
4212
- * Returns a boolean indicating if the structured type is a sub type of the given type.
4365
+ * Returns a boolean indicating if the structured type is a subtype of the given type.
4213
4366
  * @param type String representation of the type
4214
4367
  * @returns True if the callable is type of the given type
4215
4368
  */
@@ -4217,6 +4370,15 @@ class ODataStructuredType extends ODataSchemaElement {
4217
4370
  return (super.isSubtypeOf(schema) ||
4218
4371
  (this.parent !== undefined && this.parent.isSubtypeOf(schema)));
4219
4372
  }
4373
+ /**
4374
+ * Returns a boolean indicating if the structured type is a supertype of the given type.
4375
+ * @param type String representation of the type
4376
+ * @returns True if the callable is type of the given type
4377
+ */
4378
+ isSupertypeOf(schema) {
4379
+ return (super.isSupertypeOf(schema) ||
4380
+ this.children.some((c) => c.isSupertypeOf(schema)));
4381
+ }
4220
4382
  /**
4221
4383
  * Returns a boolean indicating if the structured type has a simple key.
4222
4384
  * @returns True if the structured type has a simple key
@@ -4493,19 +4655,11 @@ class ODataResource {
4493
4655
  other.schema !== undefined &&
4494
4656
  this.schema?.isSubtypeOf(other.schema));
4495
4657
  }
4496
- /*
4497
- isParentOf(other: ODataResource<any>) {
4498
- const [selfPath] = this.pathAndParams();
4499
- const [otherPath] = other.pathAndParams();
4500
- return otherPath !== selfPath && otherPath.startsWith(selfPath);
4501
- }
4502
-
4503
- isChildOf(other: ODataResource<any>) {
4504
- const [selfPath] = this.pathAndParams();
4505
- const [otherPath] = other.pathAndParams();
4506
- return otherPath !== selfPath && selfPath.startsWith(otherPath);
4658
+ isSupertypeOf(other) {
4659
+ return (this.schema !== undefined &&
4660
+ other.schema !== undefined &&
4661
+ this.schema?.isSupertypeOf(other.schema));
4507
4662
  }
4508
- */
4509
4663
  isEqualTo(other, test) {
4510
4664
  const [selfPath, selfParams] = this.pathAndParams();
4511
4665
  const [otherPath, otherParams] = other.pathAndParams();
@@ -4544,29 +4698,28 @@ class ODataResource {
4544
4698
  query: this.cloneQuery(),
4545
4699
  });
4546
4700
  }
4701
+ __parser(value, options, type) {
4702
+ const dataType = options !== undefined && Types.isPlainObject(value)
4703
+ ? options.helper.type(value)
4704
+ : undefined;
4705
+ if (dataType !== undefined) {
4706
+ // Parser from data type
4707
+ return this.api.parserForType(dataType);
4708
+ }
4709
+ else if (this.schema !== undefined && 'parser' in this.schema) {
4710
+ // Parser from resource schema
4711
+ return this.schema.parser;
4712
+ }
4713
+ else if (type !== undefined) {
4714
+ // Parser from resource type
4715
+ return this.api.parserForType(type);
4716
+ }
4717
+ return undefined;
4718
+ }
4547
4719
  deserialize(value, options) {
4548
4720
  const resourceType = this.returnType();
4549
- const resourceSchema = this.schema;
4550
- const _p = (value, options) => {
4551
- const dataType = Types.isPlainObject(value)
4552
- ? options.helper.type(value)
4553
- : undefined;
4554
- if (dataType !== undefined) {
4555
- // Parser from data type
4556
- return this.api.parserForType(dataType);
4557
- }
4558
- else if (resourceSchema !== undefined && 'parser' in resourceSchema) {
4559
- // Parser from resource schema
4560
- return resourceSchema.parser;
4561
- }
4562
- else if (resourceType !== undefined) {
4563
- // Parser from resource type
4564
- return this.api.parserForType(resourceType);
4565
- }
4566
- return undefined;
4567
- };
4568
4721
  const _d = (value, options) => {
4569
- const parser = _p(value, options);
4722
+ const parser = this.__parser(value, options, resourceType);
4570
4723
  return parser !== undefined && 'deserialize' in parser
4571
4724
  ? parser.deserialize(value, options)
4572
4725
  : value;
@@ -4577,27 +4730,8 @@ class ODataResource {
4577
4730
  }
4578
4731
  serialize(value, options) {
4579
4732
  const resourceType = this.type();
4580
- const resourceSchema = this.schema;
4581
- const _p = (value, options) => {
4582
- const dataType = Types.isPlainObject(value)
4583
- ? options.helper.type(value)
4584
- : undefined;
4585
- if (dataType !== undefined) {
4586
- // Parser from data type
4587
- return this.api.parserForType(dataType);
4588
- }
4589
- else if (resourceSchema !== undefined && 'parser' in resourceSchema) {
4590
- // Parser from resource schema
4591
- return resourceSchema.parser;
4592
- }
4593
- else if (resourceType !== undefined) {
4594
- // Parser from resource type
4595
- return this.api.parserForType(resourceType);
4596
- }
4597
- return undefined;
4598
- };
4599
4733
  const _s = (value, options) => {
4600
- const parser = _p(value, options);
4734
+ const parser = this.__parser(value, options, resourceType);
4601
4735
  return parser !== undefined && 'serialize' in parser
4602
4736
  ? parser.serialize(value, options)
4603
4737
  : value;
@@ -4608,27 +4742,8 @@ class ODataResource {
4608
4742
  }
4609
4743
  encode(value, options) {
4610
4744
  const resourceType = this.type();
4611
- const resourceSchema = this.schema;
4612
- const _p = (value, options) => {
4613
- const dataType = Types.isPlainObject(value)
4614
- ? options.helper.type(value)
4615
- : undefined;
4616
- if (dataType !== undefined) {
4617
- // Parser from data type
4618
- return this.api.parserForType(dataType);
4619
- }
4620
- else if (resourceSchema !== undefined && 'parser' in resourceSchema) {
4621
- // Parser from resource schema
4622
- return resourceSchema.parser;
4623
- }
4624
- else if (resourceType !== undefined) {
4625
- // Parser from resource type
4626
- return this.api.parserForType(resourceType);
4627
- }
4628
- return undefined;
4629
- };
4630
4745
  const _e = (value, options) => {
4631
- const parser = _p(value, options);
4746
+ const parser = this.__parser(value, options, resourceType);
4632
4747
  return parser !== undefined && 'encode' in parser
4633
4748
  ? parser.encode(value, options)
4634
4749
  : value;
@@ -4779,6 +4894,9 @@ class ODataActionResource extends ODataResource {
4779
4894
  }
4780
4895
  return action;
4781
4896
  }
4897
+ clone() {
4898
+ return super.clone();
4899
+ }
4782
4900
  //#endregion
4783
4901
  returnType() {
4784
4902
  return this.schema instanceof ODataCallable
@@ -4963,7 +5081,6 @@ class ODataEntitiesAnnotations extends ODataAnnotations {
4963
5081
  class ODataResponseOptions {
4964
5082
  constructor(config) {
4965
5083
  this.version = config.version || DEFAULT_VERSION;
4966
- this.stringAsEnum = config.stringAsEnum;
4967
5084
  }
4968
5085
  get helper() {
4969
5086
  return ODataHelper[this.version];
@@ -6083,6 +6200,11 @@ class ODataBatchResource extends ODataResource {
6083
6200
  segments.add(PathSegmentNames.batch, $BATCH);
6084
6201
  return new ODataBatchResource(api, { segments });
6085
6202
  }
6203
+ clone() {
6204
+ const batch = super.clone();
6205
+ batch._requests = [...this._requests];
6206
+ return batch;
6207
+ }
6086
6208
  //#endregion
6087
6209
  storeRequester() {
6088
6210
  const current = this.api.request;
@@ -6278,6 +6400,9 @@ class ODataCountResource extends ODataResource {
6278
6400
  query?.keep(QueryOptionNames.filter, QueryOptionNames.search);
6279
6401
  return new ODataCountResource(api, { segments, query });
6280
6402
  }
6403
+ clone() {
6404
+ return super.clone();
6405
+ }
6281
6406
  //#endregion
6282
6407
  //#region Requests
6283
6408
  get(options) {
@@ -6329,12 +6454,22 @@ class ODataFunctionResource extends ODataResource {
6329
6454
  }
6330
6455
  return func;
6331
6456
  }
6457
+ clone() {
6458
+ return super.clone();
6459
+ }
6332
6460
  //#endregion
6333
6461
  returnType() {
6334
6462
  return this.schema instanceof ODataCallable
6335
6463
  ? this.schema.parser.return?.type
6336
6464
  : undefined;
6337
6465
  }
6466
+ pathAndParams(escape = false) {
6467
+ let [path, params] = super.pathAndParams(escape);
6468
+ if (path.endsWith('()') && this.api.options.nonParenthesisForEmptyParameterFunction) {
6469
+ path = path.substring(0, path.length - 2);
6470
+ }
6471
+ return [path, params];
6472
+ }
6338
6473
  parameters(params, { alias } = {}) {
6339
6474
  let parameters = params !== null ? this.encode(params) : null;
6340
6475
  if (alias && parameters !== null) {
@@ -6433,6 +6568,9 @@ class ODataMediaResource extends ODataResource {
6433
6568
  segments.add(PathSegmentNames.value, $VALUE);
6434
6569
  return new ODataMediaResource(api, { segments, query });
6435
6570
  }
6571
+ clone() {
6572
+ return super.clone();
6573
+ }
6436
6574
  //#endregion
6437
6575
  //#region Requests
6438
6576
  get(options) {
@@ -6485,6 +6623,9 @@ class ODataValueResource extends ODataResource {
6485
6623
  }
6486
6624
  return value;
6487
6625
  }
6626
+ clone() {
6627
+ return super.clone();
6628
+ }
6488
6629
  //#endregion
6489
6630
  //#region Requests
6490
6631
  get(options) {
@@ -6550,6 +6691,9 @@ class ODataPropertyResource extends ODataResource {
6550
6691
  }
6551
6692
  return property;
6552
6693
  }
6694
+ clone() {
6695
+ return super.clone();
6696
+ }
6553
6697
  //#endregion
6554
6698
  key(value) {
6555
6699
  const property = this.clone();
@@ -6685,6 +6829,9 @@ class ODataReferenceResource extends ODataResource {
6685
6829
  query?.clear();
6686
6830
  return new ODataReferenceResource(api, { segments, query });
6687
6831
  }
6832
+ clone() {
6833
+ return super.clone();
6834
+ }
6688
6835
  //#endregion
6689
6836
  //#region Requests
6690
6837
  post(target, options) {
@@ -6812,6 +6959,9 @@ class ODataNavigationPropertyResource extends ODataResource {
6812
6959
  }
6813
6960
  return navigation;
6814
6961
  }
6962
+ clone() {
6963
+ return super.clone();
6964
+ }
6815
6965
  //#endregion
6816
6966
  key(value) {
6817
6967
  const navigation = this.clone();
@@ -6983,6 +7133,9 @@ class ODataEntityResource extends ODataResource {
6983
7133
  query?.keep(QueryOptionNames.expand, QueryOptionNames.select, QueryOptionNames.format);
6984
7134
  return new ODataEntityResource(api, { segments, query, schema });
6985
7135
  }
7136
+ clone() {
7137
+ return super.clone();
7138
+ }
6986
7139
  //#endregion
6987
7140
  key(value) {
6988
7141
  const entity = this.clone();
@@ -7022,7 +7175,7 @@ class ODataEntityResource extends ODataResource {
7022
7175
  if (castSchema !== undefined &&
7023
7176
  baseSchema !== undefined &&
7024
7177
  !castSchema.isSubtypeOf(baseSchema))
7025
- throw new Error(`Cannot cast to ${type}`);
7178
+ throw new Error(`cast: Cannot cast to ${type}`);
7026
7179
  const segments = this.cloneSegments();
7027
7180
  segments.add(PathSegmentNames.type, type).type(type);
7028
7181
  return new ODataEntityResource(this.api, {
@@ -7063,7 +7216,7 @@ class ODataEntityResource extends ODataResource {
7063
7216
  }
7064
7217
  fetch(options) {
7065
7218
  if (!this.hasKey())
7066
- return throwError('Entity resource without key');
7219
+ return throwError(() => new Error('fetch: Entity resource without key'));
7067
7220
  return this.get(options);
7068
7221
  }
7069
7222
  fetchEntity(options) {
@@ -7083,6 +7236,9 @@ class ODataEntitySetResource extends ODataResource {
7083
7236
  segment.type(schema.type());
7084
7237
  return new ODataEntitySetResource(api, { segments, query, schema });
7085
7238
  }
7239
+ clone() {
7240
+ return super.clone();
7241
+ }
7086
7242
  //#endregion
7087
7243
  entity(key) {
7088
7244
  const entity = ODataEntityResource.factory(this.api, {
@@ -7169,6 +7325,9 @@ class ODataMetadataResource extends ODataResource {
7169
7325
  segments.add(PathSegmentNames.metadata, $METADATA);
7170
7326
  return new ODataMetadataResource(api, segments);
7171
7327
  }
7328
+ clone() {
7329
+ return super.clone();
7330
+ }
7172
7331
  //#endregion
7173
7332
  //#region Requests
7174
7333
  get(options) {
@@ -7192,6 +7351,9 @@ class ODataSingletonResource extends ODataResource {
7192
7351
  segment.type(schema.type());
7193
7352
  return new ODataSingletonResource(api, { segments, query, schema });
7194
7353
  }
7354
+ clone() {
7355
+ return super.clone();
7356
+ }
7195
7357
  //#endregion
7196
7358
  key(value) {
7197
7359
  const singleton = this.clone();
@@ -7372,6 +7534,16 @@ class ODataModelEvent {
7372
7534
  : '')
7373
7535
  .join('');
7374
7536
  }
7537
+ //Identifies the current model for the event
7538
+ get currentModel() {
7539
+ const link = this.chain.find(c => ODataModelOptions.isModel(c[0]));
7540
+ return link !== undefined ? link[0] : undefined;
7541
+ }
7542
+ //Identifies the current collection for the event
7543
+ get currentCollection() {
7544
+ const link = this.chain.find(c => ODataModelOptions.isCollection(c[0]));
7545
+ return link !== undefined ? link[0] : undefined;
7546
+ }
7375
7547
  }
7376
7548
  const BUBBLING = [
7377
7549
  'change',
@@ -7674,8 +7846,8 @@ class ODataModelOptions {
7674
7846
  attach(self, resource) {
7675
7847
  if (self._resource !== null &&
7676
7848
  resource.type() !== self._resource.type() &&
7677
- !resource.isSubtypeOf(self._resource))
7678
- throw new Error(`Can't reattach ${resource.type()} to ${self._resource.type()}`);
7849
+ !self._resource.isSubtypeOf(resource))
7850
+ throw new Error(`Can't attach ${resource.type()} to ${self._resource.type()}`);
7679
7851
  const current = self._resource;
7680
7852
  if (current === null || !current.isEqualTo(resource)) {
7681
7853
  self._resource = resource;
@@ -7702,12 +7874,7 @@ class ODataModelOptions {
7702
7874
  static resource(child) {
7703
7875
  let resource = undefined;
7704
7876
  for (let [model, field] of ODataModelOptions.chain(child)) {
7705
- resource =
7706
- resource ||
7707
- model._resource ||
7708
- (ODataModelOptions.isModel(model)
7709
- ? model._meta.modelResourceFactory()
7710
- : model._model.meta.collectionResourceFactory());
7877
+ resource = resource || model._resource;
7711
7878
  if (resource === undefined)
7712
7879
  break;
7713
7880
  if (ODataModelOptions.isModel(model)) {
@@ -7722,7 +7889,7 @@ class ODataModelOptions {
7722
7889
  }
7723
7890
  if (field === null) {
7724
7891
  const query = model._resource?.cloneQuery().toQueryArguments();
7725
- if (query !== undefined)
7892
+ if (query !== undefined && resource !== undefined)
7726
7893
  resource.query((q) => q.apply(query));
7727
7894
  continue;
7728
7895
  }
@@ -7763,7 +7930,8 @@ class ODataModelOptions {
7763
7930
  self._parent = parent;
7764
7931
  }
7765
7932
  // Resource
7766
- resource = resource || this.modelResourceFactory();
7933
+ if (self._parent === null && resource === undefined)
7934
+ resource = this.modelResourceFactory();
7767
7935
  if (resource !== undefined) {
7768
7936
  this.attach(self, resource);
7769
7937
  }
@@ -7886,14 +8054,29 @@ class ODataModelOptions {
7886
8054
  (model != undefined && model.hasChanged({ include_navigation })))));
7887
8055
  }
7888
8056
  asEntity(self, func) {
7889
- const parent = self._parent;
8057
+ // Build new resource
8058
+ const query = self.resource().cloneQuery();
8059
+ let resource = this.modelResourceFactory(query);
8060
+ if (resource === undefined)
8061
+ throw new Error('Model does not have associated Entity endpoint');
8062
+ // Store parent and resource
8063
+ const store = { parent: self._parent, resource: self._resource };
8064
+ // Replace parent and resource
7890
8065
  self._parent = null;
8066
+ self._resource = resource;
8067
+ // Execute function
7891
8068
  const result = func(self);
7892
8069
  if (result instanceof Observable) {
7893
- return result.pipe(finalize(() => (self._parent = parent)));
8070
+ return result.pipe(finalize(() => {
8071
+ // Restore parent and resource
8072
+ self._parent = store.parent;
8073
+ self._resource = store.resource;
8074
+ }));
7894
8075
  }
7895
8076
  else {
7896
- self._parent = parent;
8077
+ // Restore parent and resource
8078
+ self._parent = store.parent;
8079
+ self._resource = store.resource;
7897
8080
  return result;
7898
8081
  }
7899
8082
  }
@@ -8285,14 +8468,15 @@ class ODataCollection {
8285
8468
  if (model === undefined && Klass.model !== null)
8286
8469
  model = Klass.model;
8287
8470
  if (model === undefined)
8288
- throw new Error('Collection need model');
8471
+ throw new Error('Collection: Collection need model');
8289
8472
  this._model = model;
8290
8473
  // Parent
8291
8474
  if (parent !== undefined) {
8292
8475
  this._parent = parent;
8293
8476
  }
8294
8477
  // Resource
8295
- resource = (resource || this._model.meta.collectionResourceFactory());
8478
+ if (this._parent === null && resource === undefined)
8479
+ resource = this._model.meta.collectionResourceFactory();
8296
8480
  if (resource !== undefined) {
8297
8481
  this.attach(resource);
8298
8482
  }
@@ -8321,8 +8505,8 @@ class ODataCollection {
8321
8505
  attach(resource) {
8322
8506
  if (this._resource !== null &&
8323
8507
  this._resource.type() !== resource.type() &&
8324
- !resource.isSubtypeOf(this._resource))
8325
- throw new Error(`Can't reattach ${resource.type()} to ${this._resource.type()}`);
8508
+ !this._resource.isSubtypeOf(resource))
8509
+ throw new Error(`attach: Can't reattach ${this._resource.type()} to ${resource.type()}`);
8326
8510
  this._entries.forEach(({ model }) => {
8327
8511
  const mr = this._model.meta.modelResourceFactory(resource.cloneQuery());
8328
8512
  model.attach(mr);
@@ -8338,14 +8522,29 @@ class ODataCollection {
8338
8522
  }
8339
8523
  }
8340
8524
  asEntitySet(func) {
8341
- const parent = this._parent;
8525
+ // Build new resource
8526
+ const query = this.resource().cloneQuery();
8527
+ let resource = this._model.meta.collectionResourceFactory(query);
8528
+ if (resource === undefined)
8529
+ throw new Error('asEntitySet: Collection does not have associated EntitySet endpoint');
8530
+ // Store parent and resource
8531
+ const store = { parent: this._parent, resource: this._resource };
8532
+ // Replace parent and resource
8342
8533
  this._parent = null;
8534
+ this._resource = resource;
8535
+ // Execute
8343
8536
  const result = func(this);
8344
8537
  if (result instanceof Observable) {
8345
- return result.pipe(finalize(() => (this._parent = parent)));
8538
+ return result.pipe(finalize(() => {
8539
+ // Restore
8540
+ this._parent = store.parent;
8541
+ this._resource = store.resource;
8542
+ }));
8346
8543
  }
8347
8544
  else {
8348
- this._parent = parent;
8545
+ // Restore
8546
+ this._parent = store.parent;
8547
+ this._resource = store.resource;
8349
8548
  return result;
8350
8549
  }
8351
8550
  }
@@ -8402,26 +8601,13 @@ class ODataCollection {
8402
8601
  }
8403
8602
  fetch({ withCount, ...options } = {}) {
8404
8603
  const resource = this.resource();
8405
- if (resource === undefined)
8406
- return throwError('fetch: Resource is undefined');
8407
- let obs$;
8408
- if (resource instanceof ODataEntitySetResource) {
8409
- obs$ = resource.fetch({ withCount, ...options });
8410
- }
8411
- else if (resource instanceof ODataNavigationPropertyResource) {
8412
- obs$ = resource.fetch({
8413
- responseType: 'entities',
8414
- withCount,
8415
- ...options,
8416
- });
8417
- }
8418
- else {
8419
- obs$ = resource.fetch({
8604
+ const obs$ = resource instanceof ODataEntitySetResource
8605
+ ? resource.fetch({ withCount, ...options })
8606
+ : resource.fetch({
8420
8607
  responseType: 'entities',
8421
8608
  withCount,
8422
8609
  ...options,
8423
8610
  });
8424
- }
8425
8611
  this.events$.emit(new ODataModelEvent('request', { collection: this, value: obs$ }));
8426
8612
  return obs$.pipe(map(({ entities, annots }) => {
8427
8613
  this._annotations = annots;
@@ -8432,10 +8618,8 @@ class ODataCollection {
8432
8618
  }
8433
8619
  fetchAll(options) {
8434
8620
  const resource = this.resource();
8435
- if (resource === undefined)
8436
- return throwError('fetchAll: Resource is undefined');
8437
8621
  if (resource instanceof ODataPropertyResource)
8438
- return throwError('fetchAll: Resource is ODataPropertyResource');
8622
+ return throwError(() => new Error('fetchAll: Resource is ODataPropertyResource'));
8439
8623
  const obs$ = resource.fetchAll(options);
8440
8624
  this.events$.emit(new ODataModelEvent('request', {
8441
8625
  collection: this,
@@ -8459,10 +8643,8 @@ class ODataCollection {
8459
8643
  */
8460
8644
  save({ relModel = false, method, ...options } = {}) {
8461
8645
  const resource = this.resource();
8462
- if (resource === undefined)
8463
- return throwError('saveAll: Resource is undefined');
8464
8646
  if (resource instanceof ODataPropertyResource)
8465
- return throwError('fetchAll: Resource is ODataPropertyResource');
8647
+ return throwError(() => new Error('save: Resource is ODataPropertyResource'));
8466
8648
  let toDestroyEntity = [];
8467
8649
  let toRemoveReference = [];
8468
8650
  let toDestroyContained = [];
@@ -8832,25 +9014,25 @@ class ODataCollection {
8832
9014
  return func.call(params, { responseType, ...options });
8833
9015
  }
8834
9016
  }
8835
- return throwError(`Can't function without ODataEntitySetResource`);
9017
+ return throwError(() => new Error(`callFunction: Can't function without ODataEntitySetResource`));
8836
9018
  }
8837
9019
  callAction(name, params, responseType, { ...options } = {}) {
8838
9020
  const resource = this.resource();
8839
- if (resource instanceof ODataEntitySetResource) {
8840
- const action = resource.action(name);
8841
- action.query((q) => q.apply(options));
8842
- switch (responseType) {
8843
- case 'property':
8844
- return action.callProperty(params, options);
8845
- case 'model':
8846
- return action.callModel(params, options);
8847
- case 'collection':
8848
- return action.callCollection(params, options);
8849
- default:
8850
- return action.call(params, { responseType, ...options });
8851
- }
9021
+ if (!(resource instanceof ODataEntitySetResource)) {
9022
+ return throwError(() => new Error(`callAction: Can't action without ODataEntitySetResource`));
9023
+ }
9024
+ const action = resource.action(name);
9025
+ action.query((q) => q.apply(options));
9026
+ switch (responseType) {
9027
+ case 'property':
9028
+ return action.callProperty(params, options);
9029
+ case 'model':
9030
+ return action.callModel(params, options);
9031
+ case 'collection':
9032
+ return action.callCollection(params, options);
9033
+ default:
9034
+ return action.call(params, { responseType, ...options });
8852
9035
  }
8853
- return throwError(`Can't action without ODataEntitySetResource`);
8854
9036
  }
8855
9037
  _unsubscribe(entry) {
8856
9038
  if (entry.subscription) {
@@ -8860,7 +9042,7 @@ class ODataCollection {
8860
9042
  }
8861
9043
  _subscribe(entry) {
8862
9044
  if (entry.subscription) {
8863
- throw new Error('Subscription already exists');
9045
+ throw new Error('Collection: Subscription already exists');
8864
9046
  }
8865
9047
  entry.subscription = entry.model.events$.subscribe((event) => {
8866
9048
  if (BUBBLING.indexOf(event.name) !== -1 &&
@@ -8909,12 +9091,18 @@ class ODataCollection {
8909
9091
  },
8910
9092
  };
8911
9093
  }
8912
- filter(predicate) {
9094
+ filter(predicate, thisArg) {
8913
9095
  return this.models().filter(predicate);
8914
9096
  }
8915
- find(predicate) {
9097
+ map(callbackfn, thisArg) {
9098
+ return this.models().map(callbackfn, thisArg);
9099
+ }
9100
+ find(predicate, thisArg) {
8916
9101
  return this.models().find(predicate);
8917
9102
  }
9103
+ reduce(callbackfn, initialValue) {
9104
+ return this.models().reduce(callbackfn, initialValue);
9105
+ }
8918
9106
  first() {
8919
9107
  return this.models()[0];
8920
9108
  }
@@ -9022,7 +9210,7 @@ class ODataModel {
9022
9210
  this.events$ = new EventEmitter();
9023
9211
  const Klass = this.constructor;
9024
9212
  if (Klass.meta === undefined)
9025
- throw new Error(`Can't create model without metadata`);
9213
+ throw new Error(`ODataModel: Can't create model without metadata`);
9026
9214
  this._meta = Klass.meta;
9027
9215
  this._meta.bind(this, { parent, resource, annots });
9028
9216
  // Client Id
@@ -9062,19 +9250,19 @@ class ODataModel {
9062
9250
  navigationProperty(name) {
9063
9251
  const field = this._meta.field(name);
9064
9252
  if (field === undefined || !field.navigation)
9065
- throw Error(`Can't find navigation property ${name}`);
9253
+ throw Error(`navigationProperty: Can't find navigation property ${name}`);
9066
9254
  const resource = this.resource();
9067
9255
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9068
- throw Error("Can't get navigation without ODataEntityResource with key");
9256
+ throw Error("navigationProperty: Can't get navigation without ODataEntityResource with key");
9069
9257
  return field.resourceFactory(resource);
9070
9258
  }
9071
9259
  property(name) {
9072
9260
  const field = this._meta.field(name);
9073
9261
  if (field === undefined || field.navigation)
9074
- throw Error(`Can't find property ${name}`);
9262
+ throw Error(`property: Can't find property ${name}`);
9075
9263
  const resource = this.resource();
9076
9264
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9077
- throw Error("Can't get property without ODataEntityResource with key");
9265
+ throw Error("property: Can't get property without ODataEntityResource with key");
9078
9266
  return field.resourceFactory(resource);
9079
9267
  }
9080
9268
  attach(resource) {
@@ -9219,11 +9407,11 @@ class ODataModel {
9219
9407
  fetch({ ...options } = {}) {
9220
9408
  let resource = this.resource();
9221
9409
  if (resource === undefined)
9222
- return throwError('fetch: Resource is undefined');
9410
+ return throwError(() => new Error('fetch: Resource is undefined'));
9223
9411
  let obs$;
9224
9412
  if (resource instanceof ODataEntityResource) {
9225
9413
  if (!resource.hasKey())
9226
- return throwError("fetch: Can't fetch model without key");
9414
+ return throwError(() => new Error("fetch: Can't fetch model without key"));
9227
9415
  obs$ = resource.fetch(options);
9228
9416
  }
9229
9417
  else if (resource instanceof ODataNavigationPropertyResource) {
@@ -9240,49 +9428,45 @@ class ODataModel {
9240
9428
  save({ method, navigation = false, validate = true, ...options } = {}) {
9241
9429
  let resource = this.resource();
9242
9430
  if (resource === undefined)
9243
- return throwError('save: Resource is undefined');
9431
+ return throwError(() => new Error('save: Resource is undefined'));
9244
9432
  if (!(resource instanceof ODataEntityResource ||
9245
9433
  resource instanceof ODataNavigationPropertyResource))
9246
- return throwError('save: Resource type ODataEntityResource/ODataNavigationPropertyResource needed');
9434
+ return throwError(() => new Error('save: Resource type ODataEntityResource/ODataNavigationPropertyResource needed'));
9247
9435
  // Resolve method and resource key
9248
9436
  if (method === undefined && this.schema().isCompoundKey())
9249
- return throwError('save: Composite key require a specific method, use create/update/modify');
9437
+ return throwError(() => new Error('save: Composite key require a specific method, use create/update/modify'));
9250
9438
  method = method || (!resource.hasKey() ? 'create' : 'update');
9251
9439
  if (resource instanceof ODataEntityResource &&
9252
9440
  (method === 'update' || method === 'modify') &&
9253
9441
  !resource.hasKey())
9254
- return throwError('save: Update/Patch require entity key');
9442
+ return throwError(() => new Error('save: Update/Patch require entity key'));
9255
9443
  if (resource instanceof ODataNavigationPropertyResource ||
9256
9444
  method === 'create')
9257
9445
  resource.clearKey();
9258
- let obs$;
9259
- if (!validate || this.isValid({ method, navigation })) {
9260
- const _entity = this.toEntity({
9261
- changes_only: method === 'modify',
9262
- field_mapping: true,
9263
- include_concurrency: true,
9264
- include_navigation: navigation,
9265
- });
9266
- obs$ = (method === 'create'
9267
- ? resource.create(_entity, options)
9268
- : method === 'modify'
9269
- ? resource.modify(_entity, { etag: this.annots().etag, ...options })
9270
- : resource.update(_entity, { etag: this.annots().etag, ...options })).pipe(map(({ entity, annots }) => ({ entity: entity || _entity, annots })));
9271
- }
9272
- else {
9273
- obs$ = throwError(this._errors);
9446
+ if (validate && !this.isValid({ method, navigation })) {
9447
+ return throwError(() => new Error('save: Validation errors'));
9274
9448
  }
9275
- return this._request(obs$);
9449
+ const _entity = this.toEntity({
9450
+ changes_only: method === 'modify',
9451
+ field_mapping: true,
9452
+ include_concurrency: true,
9453
+ include_navigation: navigation,
9454
+ });
9455
+ return this._request((method === 'create'
9456
+ ? resource.create(_entity, options)
9457
+ : method === 'modify'
9458
+ ? resource.modify(_entity, { etag: this.annots().etag, ...options })
9459
+ : resource.update(_entity, { etag: this.annots().etag, ...options })).pipe(map(({ entity, annots }) => ({ entity: entity || _entity, annots }))));
9276
9460
  }
9277
9461
  destroy({ ...options } = {}) {
9278
9462
  let resource = this.resource();
9279
9463
  if (resource === undefined)
9280
- return throwError('destroy: Resource is undefined');
9464
+ return throwError(() => new Error('destroy: Resource is undefined'));
9281
9465
  if (!(resource instanceof ODataEntityResource ||
9282
9466
  resource instanceof ODataNavigationPropertyResource))
9283
- return throwError('destroy: Resource type ODataEntityResource/ODataNavigationPropertyResource needed');
9467
+ return throwError(() => new Error('destroy: Resource type ODataEntityResource/ODataNavigationPropertyResource needed'));
9284
9468
  if (!resource.hasKey())
9285
- return throwError("destroy: Can't destroy model without key");
9469
+ return throwError(() => new Error("destroy: Can't destroy model without key"));
9286
9470
  const _entity = this.toEntity({ field_mapping: true });
9287
9471
  const obs$ = resource
9288
9472
  .destroy({ etag: this.annots().etag, ...options })
@@ -9315,7 +9499,7 @@ class ODataModel {
9315
9499
  callFunction(name, params, responseType, { ...options } = {}) {
9316
9500
  const resource = this.resource();
9317
9501
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9318
- return throwError("Can't call function without ODataEntityResource with key");
9502
+ return throwError(() => new Error("callFunction: Can't call function without ODataEntityResource with key"));
9319
9503
  const func = resource.function(name).query((q) => q.apply(options));
9320
9504
  switch (responseType) {
9321
9505
  case 'property':
@@ -9331,7 +9515,7 @@ class ODataModel {
9331
9515
  callAction(name, params, responseType, { ...options } = {}) {
9332
9516
  const resource = this.resource();
9333
9517
  if (!(resource instanceof ODataEntityResource) || !resource.hasKey())
9334
- return throwError("Can't call action without ODataEntityResource with key");
9518
+ return throwError(() => new Error("callAction: Can't call action without ODataEntityResource with key"));
9335
9519
  const action = resource.action(name).query((q) => q.apply(options));
9336
9520
  switch (responseType) {
9337
9521
  case 'property':
@@ -9348,7 +9532,7 @@ class ODataModel {
9348
9532
  cast(type) {
9349
9533
  const resource = this.resource();
9350
9534
  if (!(resource instanceof ODataEntityResource))
9351
- throw new Error(`Can't cast to derived model without ODataEntityResource`);
9535
+ throw new Error(`cast: Can't cast to derived model without ODataEntityResource`);
9352
9536
  return resource
9353
9537
  .cast(type)
9354
9538
  .asModel(this.toEntity(INCLUDE_DEEP), { annots: this.annots() });
@@ -9367,7 +9551,7 @@ class ODataModel {
9367
9551
  getValue(name, options) {
9368
9552
  const field = this._meta.field(name);
9369
9553
  if (field === undefined || field.navigation)
9370
- throw Error(`Can't find property ${name}`);
9554
+ throw Error(`getValue: Can't find property ${name}`);
9371
9555
  let value = this[name];
9372
9556
  if (value === undefined) {
9373
9557
  const prop = field.resourceFactory(this.resource());
@@ -9414,7 +9598,7 @@ class ODataModel {
9414
9598
  getReference(name) {
9415
9599
  const field = this._meta.field(name);
9416
9600
  if (field === undefined || !field.navigation)
9417
- throw Error(`Can't find navigation property ${name}`);
9601
+ throw Error(`getReference: Can't find navigation property ${name}`);
9418
9602
  let model = this[name];
9419
9603
  if (model === undefined) {
9420
9604
  const value = field.collection ? [] : this.referenced(field);
@@ -10203,9 +10387,9 @@ class ODataClient {
10203
10387
  return this.request('PUT', resource, addBody(options, body));
10204
10388
  }
10205
10389
  }
10206
- 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 });
10207
- ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataClient, providedIn: 'root' });
10208
- 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: [{
10209
10393
  type: Injectable,
10210
10394
  args: [{
10211
10395
  providedIn: 'root',
@@ -10324,7 +10508,7 @@ class ODataEntitySetService extends ODataEntityService {
10324
10508
  update(key, attrs, options) {
10325
10509
  const res = this.entity(key);
10326
10510
  if (!res.hasKey())
10327
- return throwError('Resource without key');
10511
+ return throwError(() => new Error('update: Resource without key'));
10328
10512
  return res.update(attrs, options);
10329
10513
  }
10330
10514
  /**
@@ -10337,7 +10521,7 @@ class ODataEntitySetService extends ODataEntityService {
10337
10521
  modify(key, attrs, options) {
10338
10522
  const res = this.entity(key);
10339
10523
  if (!res.hasKey())
10340
- return throwError('Resource without key');
10524
+ return throwError(() => new Error('modify: Resource without key'));
10341
10525
  return res.modify(attrs, options);
10342
10526
  }
10343
10527
  /**
@@ -10349,7 +10533,7 @@ class ODataEntitySetService extends ODataEntityService {
10349
10533
  destroy(key, options) {
10350
10534
  const res = this.entity(key);
10351
10535
  if (!res.hasKey())
10352
- return throwError('Resource without key');
10536
+ return throwError(() => new Error('destroy: Resource without key'));
10353
10537
  return res.destroy(options);
10354
10538
  }
10355
10539
  //#region Shortcuts
@@ -10378,12 +10562,12 @@ class ODataEntitySetService extends ODataEntityService {
10378
10562
  save(attrs, { etag, method, ...options } = {}) {
10379
10563
  let schema = this.structuredTypeSchema;
10380
10564
  if (method === undefined && schema !== undefined && schema.isCompoundKey())
10381
- return throwError('Composite key require a specific method, use create/update/patch');
10565
+ return throwError(() => new Error('save: Composite key require a specific method, use create/update/patch'));
10382
10566
  let key = schema && schema.resolveKey(attrs);
10383
10567
  if (method === undefined)
10384
10568
  method = key !== undefined ? 'update' : 'create';
10385
10569
  if ((method === 'update' || method === 'modify') && key === undefined)
10386
- return throwError("Can't update/patch entity without key");
10570
+ return throwError(() => new Error("save: Can't update/patch entity without key"));
10387
10571
  return method === 'create'
10388
10572
  ? this.create(attrs, options)
10389
10573
  : method === 'modify'
@@ -10461,9 +10645,9 @@ class ODataServiceFactory {
10461
10645
  })(this.client, singletonName, apiNameOrEntityType);
10462
10646
  }
10463
10647
  }
10464
- ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10465
- ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory });
10466
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataServiceFactory, decorators: [{
10648
+ ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10649
+ ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataServiceFactory });
10650
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataServiceFactory, decorators: [{
10467
10651
  type: Injectable
10468
10652
  }], ctorParameters: function () { return [{ type: ODataClient }]; } });
10469
10653
 
@@ -10487,10 +10671,10 @@ class ODataModule {
10487
10671
  };
10488
10672
  }
10489
10673
  }
10490
- ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10491
- ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10492
- ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10493
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ODataModule, decorators: [{
10674
+ ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10675
+ ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10676
+ ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10677
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: ODataModule, decorators: [{
10494
10678
  type: NgModule,
10495
10679
  args: [{
10496
10680
  imports: [HttpClientModule],