angular-odata 0.101.0 → 0.102.6

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 (67) hide show
  1. package/esm2020/lib/api.mjs +83 -63
  2. package/esm2020/lib/cache/cache.mjs +1 -1
  3. package/esm2020/lib/cache/memory.mjs +3 -3
  4. package/esm2020/lib/cache/storage.mjs +3 -3
  5. package/esm2020/lib/client.mjs +3 -3
  6. package/esm2020/lib/models/collection.mjs +5 -6
  7. package/esm2020/lib/models/model.mjs +1 -3
  8. package/esm2020/lib/models/options.mjs +84 -44
  9. package/esm2020/lib/module.mjs +5 -5
  10. package/esm2020/lib/resources/query/builder.mjs +1 -1
  11. package/esm2020/lib/resources/query/expressions/compute.mjs +5 -5
  12. package/esm2020/lib/resources/query/expressions/expand.mjs +6 -6
  13. package/esm2020/lib/resources/query/expressions/filter.mjs +9 -9
  14. package/esm2020/lib/resources/query/expressions/index.mjs +3 -1
  15. package/esm2020/lib/resources/query/expressions/orderby.mjs +5 -5
  16. package/esm2020/lib/resources/query/expressions/search.mjs +3 -3
  17. package/esm2020/lib/resources/query/expressions/select.mjs +7 -7
  18. package/esm2020/lib/resources/query/handlers.mjs +140 -22
  19. package/esm2020/lib/resources/query/options.mjs +16 -13
  20. package/esm2020/lib/resources/request.mjs +31 -36
  21. package/esm2020/lib/resources/resource.mjs +15 -3
  22. package/esm2020/lib/resources/types/navigation-property.mjs +5 -3
  23. package/esm2020/lib/resources/types/options.mjs +1 -1
  24. package/esm2020/lib/resources/types/property.mjs +4 -4
  25. package/esm2020/lib/schema/enum-type.mjs +9 -25
  26. package/esm2020/lib/schema/parsers/callable.mjs +6 -1
  27. package/esm2020/lib/schema/parsers/enum-type.mjs +23 -3
  28. package/esm2020/lib/schema/parsers/structured-type.mjs +120 -42
  29. package/esm2020/lib/schema/structured-type.mjs +26 -38
  30. package/esm2020/lib/services/base.mjs +1 -1
  31. package/esm2020/lib/services/factory.mjs +3 -3
  32. package/esm2020/lib/types.mjs +1 -1
  33. package/esm2020/lib/utils/objects.mjs +2 -2
  34. package/esm2020/lib/utils/types.mjs +2 -7
  35. package/fesm2015/angular-odata.mjs +601 -342
  36. package/fesm2015/angular-odata.mjs.map +1 -1
  37. package/fesm2020/angular-odata.mjs +593 -335
  38. package/fesm2020/angular-odata.mjs.map +1 -1
  39. package/{angular-odata.d.ts → index.d.ts} +0 -0
  40. package/lib/api.d.ts +2 -4
  41. package/lib/models/collection.d.ts +5 -4
  42. package/lib/models/model.d.ts +4 -4
  43. package/lib/models/options.d.ts +20 -12
  44. package/lib/resources/query/builder.d.ts +1 -1
  45. package/lib/resources/query/expressions/compute.d.ts +7 -6
  46. package/lib/resources/query/expressions/expand.d.ts +17 -32
  47. package/lib/resources/query/expressions/filter.d.ts +11 -10
  48. package/lib/resources/query/expressions/index.d.ts +2 -0
  49. package/lib/resources/query/expressions/orderby.d.ts +7 -6
  50. package/lib/resources/query/expressions/search.d.ts +5 -4
  51. package/lib/resources/query/expressions/select.d.ts +7 -6
  52. package/lib/resources/query/handlers.d.ts +39 -33
  53. package/lib/resources/query/options.d.ts +14 -12
  54. package/lib/resources/request.d.ts +2 -1
  55. package/lib/resources/resource.d.ts +3 -2
  56. package/lib/resources/types/options.d.ts +4 -2
  57. package/lib/schema/enum-type.d.ts +7 -19
  58. package/lib/schema/parsers/callable.d.ts +1 -0
  59. package/lib/schema/parsers/enum-type.d.ts +18 -10
  60. package/lib/schema/parsers/structured-type.d.ts +47 -3
  61. package/lib/schema/structured-type.d.ts +19 -19
  62. package/lib/services/base.d.ts +9 -9
  63. package/lib/types.d.ts +5 -5
  64. package/lib/utils/objects.d.ts +1 -1
  65. package/lib/utils/strings.d.ts +1 -1
  66. package/lib/utils/types.d.ts +0 -1
  67. package/package.json +5 -5
@@ -311,7 +311,7 @@ class ODataInMemoryCache extends ODataCache {
311
311
  putResponse(req, res) {
312
312
  let scope = this.scope(req);
313
313
  let tags = this.tags(res);
314
- this.put(req.pathWithParams, res, {
314
+ this.put(req.cacheKey, res, {
315
315
  timeout: res.options.maxAge,
316
316
  scope,
317
317
  tags,
@@ -324,7 +324,7 @@ class ODataInMemoryCache extends ODataCache {
324
324
  */
325
325
  getResponse(req) {
326
326
  let scope = this.scope(req);
327
- return this.get(req.pathWithParams, { scope });
327
+ return this.get(req.cacheKey, { scope });
328
328
  }
329
329
  }
330
330
 
@@ -1032,10 +1032,6 @@ const Types = {
1032
1032
  rawType(value) {
1033
1033
  return Object.prototype.toString.call(value).slice(8, -1);
1034
1034
  },
1035
- isObject(value) {
1036
- var type = typeof value;
1037
- return value != null && (type === 'object' || type === 'function');
1038
- },
1039
1035
  isPlainObject(value) {
1040
1036
  if (this.rawType(value) !== 'Object') {
1041
1037
  return false;
@@ -1056,13 +1052,12 @@ const Types = {
1056
1052
  return (value === undefined ||
1057
1053
  value === null ||
1058
1054
  (typeof value === 'string' && !value.length) ||
1055
+ (value instanceof Date && isNaN(value.valueOf())) ||
1059
1056
  (Types.isMap(value) && !value.size) ||
1060
1057
  (Types.isArray(value) && !value.length) ||
1061
1058
  (Types.isFunction(value.isEmpty) && value.isEmpty()) ||
1062
1059
  (Types.isArray(value) &&
1063
1060
  value.every((v) => Types.isEmpty(v))) ||
1064
- (Types.isObject(value) &&
1065
- !Object.keys(value).filter((k) => value.hasOwnProperty(k)).length) ||
1066
1061
  (Types.isPlainObject(value) &&
1067
1062
  !Object.keys(value).filter((k) => value.hasOwnProperty(k)).length));
1068
1063
  },
@@ -1403,7 +1398,7 @@ const Objects = {
1403
1398
  if (typeof target != 'object' || target == null) {
1404
1399
  return target;
1405
1400
  }
1406
- if (Types.isObject(target) && 'clone' in target) {
1401
+ if ('clone' in target) {
1407
1402
  // target is a cloneable object
1408
1403
  return target.clone();
1409
1404
  }
@@ -1940,16 +1935,16 @@ class ComputeExpression extends Expression {
1940
1935
  super({ children });
1941
1936
  this.names = names || [];
1942
1937
  }
1943
- static e() {
1938
+ static expression() {
1944
1939
  return new ComputeExpression();
1945
1940
  }
1946
- static s() {
1941
+ static type() {
1947
1942
  return Field$1.factory();
1948
1943
  }
1949
1944
  static compute(opts, current) {
1950
1945
  return opts({
1951
- s: ComputeExpression.s(),
1952
- e: ComputeExpression.e,
1946
+ t: ComputeExpression.type(),
1947
+ e: ComputeExpression.expression,
1953
1948
  }, current);
1954
1949
  }
1955
1950
  render({ aliases, escape, prefix, } = {}) {
@@ -1984,16 +1979,16 @@ class FilterExpression extends Expression {
1984
1979
  this._connector = connector || 'and';
1985
1980
  this._negated = negated || false;
1986
1981
  }
1987
- static s() {
1982
+ static type() {
1988
1983
  return Field$1.factory();
1989
1984
  }
1990
- static e(connector = 'and') {
1985
+ static expression(connector = 'and') {
1991
1986
  return new FilterExpression({ connector });
1992
1987
  }
1993
1988
  static filter(opts, current) {
1994
1989
  return opts({
1995
- s: FilterExpression.s(),
1996
- e: FilterExpression.e,
1990
+ t: FilterExpression.type(),
1991
+ e: FilterExpression.expression,
1997
1992
  o: operators,
1998
1993
  f: functions,
1999
1994
  }, current);
@@ -2119,15 +2114,15 @@ class FilterExpression extends Expression {
2119
2114
  }
2120
2115
  any(left, opts, alias) {
2121
2116
  const exp = opts({
2122
- s: Field$1.factory(),
2123
- e: FilterExpression.e,
2117
+ t: Field$1.factory(),
2118
+ e: FilterExpression.expression,
2124
2119
  });
2125
2120
  return this._add(syntax.any(left, exp, alias));
2126
2121
  }
2127
2122
  all(left, opts, alias) {
2128
2123
  const exp = opts({
2129
- s: Field$1.factory(),
2130
- e: FilterExpression.e,
2124
+ t: Field$1.factory(),
2125
+ e: FilterExpression.expression,
2131
2126
  });
2132
2127
  return this._add(syntax.all(left, exp, alias));
2133
2128
  }
@@ -2161,16 +2156,16 @@ class OrderByExpression extends Expression {
2161
2156
  constructor({ children, } = {}) {
2162
2157
  super({ children });
2163
2158
  }
2164
- static e() {
2159
+ static expression() {
2165
2160
  return new OrderByExpression();
2166
2161
  }
2167
- static s() {
2162
+ static type() {
2168
2163
  return Field$1.factory();
2169
2164
  }
2170
2165
  static orderBy(opts, current) {
2171
2166
  return opts({
2172
- s: OrderByExpression.s(),
2173
- e: OrderByExpression.e,
2167
+ t: OrderByExpression.type(),
2168
+ e: OrderByExpression.expression,
2174
2169
  }, current);
2175
2170
  }
2176
2171
  _add(node) {
@@ -2222,12 +2217,12 @@ class SearchExpression extends Expression {
2222
2217
  this._connector = connector || 'AND';
2223
2218
  this._negated = negated || false;
2224
2219
  }
2225
- static e(connector = 'AND') {
2220
+ static expression(connector = 'AND') {
2226
2221
  return new SearchExpression({ connector });
2227
2222
  }
2228
2223
  static search(opts, current) {
2229
2224
  return opts({
2230
- e: SearchExpression.e,
2225
+ e: SearchExpression.expression,
2231
2226
  }, current);
2232
2227
  }
2233
2228
  _add(node, connector) {
@@ -2322,16 +2317,16 @@ class SelectExpression extends Expression {
2322
2317
  constructor({ children, } = {}) {
2323
2318
  super({ children });
2324
2319
  }
2325
- static e() {
2320
+ static expression() {
2326
2321
  return new SelectExpression();
2327
2322
  }
2328
- static s() {
2323
+ static type() {
2329
2324
  return Field$1.factory();
2330
2325
  }
2331
- static select(builder, current) {
2332
- return builder({
2333
- s: SelectExpression.s(),
2334
- e: SelectExpression.e,
2326
+ static select(opts, current) {
2327
+ return opts({
2328
+ t: SelectExpression.type(),
2329
+ e: SelectExpression.expression,
2335
2330
  }, current);
2336
2331
  }
2337
2332
  render({ aliases, escape, prefix, } = {}) {
@@ -2432,16 +2427,16 @@ class ExpandExpression extends Expression {
2432
2427
  constructor({ children, } = {}) {
2433
2428
  super({ children });
2434
2429
  }
2435
- static e() {
2430
+ static expression() {
2436
2431
  return new ExpandExpression();
2437
2432
  }
2438
- static s() {
2433
+ static type() {
2439
2434
  return Field$1.factory();
2440
2435
  }
2441
2436
  static expand(opts, current) {
2442
2437
  return opts({
2443
- s: ExpandExpression.s(),
2444
- e: ExpandExpression.e,
2438
+ t: ExpandExpression.type(),
2439
+ e: ExpandExpression.expression,
2445
2440
  }, current);
2446
2441
  }
2447
2442
  render({ aliases, escape, prefix, } = {}) {
@@ -2522,8 +2517,9 @@ class ODataQueryOptionHandler {
2522
2517
  */
2523
2518
  remove(value) {
2524
2519
  this.o.set(this.n, this.assertArray().filter((v) => v !== value));
2525
- // If only one... down to value
2526
- if (this.o.get(this.n).length === 1)
2520
+ // If only one and not is array... down to value
2521
+ if (this.o.get(this.n).length === 1 &&
2522
+ !Types.isArray(this.o.get(this.n)[0]))
2527
2523
  this.o.set(this.n, this.o.get(this.n)[0]);
2528
2524
  }
2529
2525
  /**
@@ -2534,6 +2530,15 @@ class ODataQueryOptionHandler {
2534
2530
  at(index) {
2535
2531
  return this.assertArray()[index];
2536
2532
  }
2533
+ some(predicate) {
2534
+ return this.assertArray().some(predicate);
2535
+ }
2536
+ every(predicate) {
2537
+ return this.assertArray().every(predicate);
2538
+ }
2539
+ find(predicate) {
2540
+ return this.assertArray().find(predicate);
2541
+ }
2537
2542
  //#endregion
2538
2543
  //#region HashMap Value
2539
2544
  assertObject(create) {
@@ -2611,6 +2616,14 @@ class ODataQueryOptionsHandler {
2611
2616
  constructor(options) {
2612
2617
  this.options = options;
2613
2618
  }
2619
+ /**
2620
+ * Create a raw odata value
2621
+ * @param value The value to raw
2622
+ * @returns The raw value
2623
+ */
2624
+ raw(value) {
2625
+ return raw(value);
2626
+ }
2614
2627
  /**
2615
2628
  * Create a new odata alias parameter
2616
2629
  * @link https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_ParameterAliases
@@ -2621,6 +2634,22 @@ class ODataQueryOptionsHandler {
2621
2634
  alias(value, name) {
2622
2635
  return alias(value, name);
2623
2636
  }
2637
+ /**
2638
+ * Create a duration odata value
2639
+ * @param value The value to duration
2640
+ * @returns The duration value
2641
+ */
2642
+ duration(value) {
2643
+ return duration(value);
2644
+ }
2645
+ /**
2646
+ * Create a binary odata value
2647
+ * @param value The value to binary
2648
+ * @returns The binary value
2649
+ */
2650
+ binary(value) {
2651
+ return binary(value);
2652
+ }
2624
2653
  /**
2625
2654
  * Normalize the given value to a valid odata value
2626
2655
  * @param value The value to normalize
@@ -2685,20 +2714,50 @@ class ODataQueryOptionsHandler {
2685
2714
  * @param param0 skip or top or skiptoken
2686
2715
  */
2687
2716
  paging({ skip, skiptoken, top, } = {}) {
2688
- if (skiptoken !== undefined)
2689
- this.skiptoken(skiptoken);
2690
- else if (skip !== undefined)
2691
- this.skip(skip);
2692
- if (top !== undefined)
2693
- this.top(top);
2717
+ if (skiptoken !== undefined) {
2718
+ if (skiptoken !== null) {
2719
+ this.skiptoken(skiptoken);
2720
+ }
2721
+ else {
2722
+ this.options.remove(QueryOptionNames.skiptoken);
2723
+ }
2724
+ }
2725
+ if (skip !== undefined) {
2726
+ if (skip !== null) {
2727
+ this.skip(skip);
2728
+ }
2729
+ else {
2730
+ this.options.remove(QueryOptionNames.skip);
2731
+ }
2732
+ }
2733
+ if (top !== undefined) {
2734
+ if (top !== null) {
2735
+ this.top(top);
2736
+ }
2737
+ else {
2738
+ this.options.remove(QueryOptionNames.top);
2739
+ }
2740
+ }
2694
2741
  }
2695
2742
  /**
2696
2743
  * Shortcut for clear pagination by unset $top, $skip, $skiptoken.
2697
2744
  */
2698
2745
  clearPaging() {
2699
- this.skip().clear();
2700
- this.top().clear();
2701
- this.skiptoken().clear();
2746
+ this.options.remove(QueryOptionNames.skip);
2747
+ this.options.remove(QueryOptionNames.top);
2748
+ this.options.remove(QueryOptionNames.skiptoken);
2749
+ }
2750
+ /**
2751
+ * Shortcut for clear query.
2752
+ */
2753
+ clear() {
2754
+ this.options.clear();
2755
+ }
2756
+ /**
2757
+ * Retrun the query.
2758
+ */
2759
+ query() {
2760
+ return this.options.toQueryArguments();
2702
2761
  }
2703
2762
  /**
2704
2763
  * Apply the given query options to the current query.
@@ -2706,22 +2765,78 @@ class ODataQueryOptionsHandler {
2706
2765
  */
2707
2766
  apply(query) {
2708
2767
  if (query.select !== undefined) {
2709
- this.options.option(QueryOptionNames.select, query.select);
2768
+ if (query.select instanceof SelectExpression) {
2769
+ this.options.expression(QueryOptionNames.select, query.select);
2770
+ }
2771
+ else if (query.select !== null) {
2772
+ this.options.option(QueryOptionNames.select, query.select);
2773
+ }
2774
+ else {
2775
+ this.options.remove(QueryOptionNames.select);
2776
+ }
2710
2777
  }
2711
2778
  if (query.expand !== undefined) {
2712
- this.options.option(QueryOptionNames.expand, query.expand);
2779
+ if (query.expand instanceof ExpandExpression) {
2780
+ this.options.expression(QueryOptionNames.expand, query.expand);
2781
+ }
2782
+ else if (query.expand !== null) {
2783
+ this.options.option(QueryOptionNames.expand, query.expand);
2784
+ }
2785
+ else {
2786
+ this.options.remove(QueryOptionNames.expand);
2787
+ }
2788
+ }
2789
+ if (query.compute !== undefined) {
2790
+ if (query.compute instanceof ComputeExpression) {
2791
+ this.options.expression(QueryOptionNames.compute, query.compute);
2792
+ }
2793
+ else if (query.compute !== null) {
2794
+ this.options.option(QueryOptionNames.compute, query.compute);
2795
+ }
2796
+ else {
2797
+ this.options.remove(QueryOptionNames.compute);
2798
+ }
2713
2799
  }
2714
2800
  if (query.transform !== undefined) {
2715
- this.options.option(QueryOptionNames.transform, query.transform);
2801
+ if (query.transform !== null) {
2802
+ this.options.option(QueryOptionNames.transform, query.transform);
2803
+ }
2804
+ else {
2805
+ this.options.remove(QueryOptionNames.transform);
2806
+ }
2716
2807
  }
2717
2808
  if (query.search !== undefined) {
2718
- this.options.option(QueryOptionNames.search, query.search);
2809
+ if (query.search instanceof SearchExpression) {
2810
+ this.options.expression(QueryOptionNames.search, query.search);
2811
+ }
2812
+ else if (query.search !== null) {
2813
+ this.options.option(QueryOptionNames.search, query.search);
2814
+ }
2815
+ else {
2816
+ this.options.remove(QueryOptionNames.search);
2817
+ }
2719
2818
  }
2720
2819
  if (query.filter !== undefined) {
2721
- this.options.option(QueryOptionNames.filter, query.filter);
2820
+ if (query.filter instanceof FilterExpression) {
2821
+ this.options.expression(QueryOptionNames.filter, query.filter);
2822
+ }
2823
+ else if (query.filter !== null) {
2824
+ this.options.option(QueryOptionNames.filter, query.filter);
2825
+ }
2826
+ else {
2827
+ this.options.remove(QueryOptionNames.filter);
2828
+ }
2722
2829
  }
2723
2830
  if (query.orderBy !== undefined) {
2724
- this.options.option(QueryOptionNames.orderBy, query.orderBy);
2831
+ if (query.orderBy instanceof OrderByExpression) {
2832
+ this.options.expression(QueryOptionNames.orderBy, query.orderBy);
2833
+ }
2834
+ else if (query.orderBy !== null) {
2835
+ this.options.option(QueryOptionNames.orderBy, query.orderBy);
2836
+ }
2837
+ else {
2838
+ this.options.remove(QueryOptionNames.orderBy);
2839
+ }
2725
2840
  }
2726
2841
  this.paging(query);
2727
2842
  }
@@ -2749,6 +2864,8 @@ class ODataQueryOptions {
2749
2864
  QueryOptionNames.skiptoken,
2750
2865
  QueryOptionNames.expand,
2751
2866
  QueryOptionNames.format,
2867
+ QueryOptionNames.levels,
2868
+ QueryOptionNames.count,
2752
2869
  ]
2753
2870
  .filter((key) => !Types.isEmpty(this.values.get(key)))
2754
2871
  .reduce((acc, key) => {
@@ -2771,23 +2888,24 @@ class ODataQueryOptions {
2771
2888
  toJSON() {
2772
2889
  return [...this.values.keys()].reduce((acc, key) => {
2773
2890
  let value = this.values.get(key);
2774
- value =
2775
- Types.isObject(value) && 'toJSON' in value ? value.toJSON() : value;
2891
+ value = 'toJSON' in value ? value.toJSON() : value;
2776
2892
  return Object.assign(acc, { [key]: value });
2777
2893
  }, {});
2778
2894
  }
2779
2895
  toQueryArguments() {
2780
2896
  return {
2781
- select: this.values.get(QueryOptionNames.select),
2782
- expand: this.values.get(QueryOptionNames.expand),
2783
- transform: this.values.get(QueryOptionNames.transform),
2784
- compute: this.values.get(QueryOptionNames.compute),
2785
- search: this.values.get(QueryOptionNames.search),
2786
- filter: this.values.get(QueryOptionNames.filter),
2787
- orderBy: this.values.get(QueryOptionNames.orderBy),
2788
- top: this.values.get(QueryOptionNames.top),
2789
- skip: this.values.get(QueryOptionNames.skip),
2790
- skiptoken: this.values.get(QueryOptionNames.skiptoken),
2897
+ select: this.values.get(QueryOptionNames.select) || null,
2898
+ expand: this.values.get(QueryOptionNames.expand) || null,
2899
+ transform: this.values.get(QueryOptionNames.transform) || null,
2900
+ compute: this.values.get(QueryOptionNames.compute) || null,
2901
+ search: this.values.get(QueryOptionNames.search) || null,
2902
+ filter: this.values.get(QueryOptionNames.filter) || null,
2903
+ orderBy: this.values.get(QueryOptionNames.orderBy) || null,
2904
+ top: this.values.get(QueryOptionNames.top) || null,
2905
+ skip: this.values.get(QueryOptionNames.skip) || null,
2906
+ skiptoken: this.values.get(QueryOptionNames.skiptoken) || null,
2907
+ levels: this.values.get(QueryOptionNames.levels) || null,
2908
+ count: this.values.get(QueryOptionNames.count) || null,
2791
2909
  };
2792
2910
  }
2793
2911
  clone() {
@@ -3034,8 +3152,10 @@ class ODataRequest {
3034
3152
  ? this.api.options.withCredentials
3035
3153
  : init.withCredentials;
3036
3154
  this.fetchPolicy = init.fetchPolicy || this.api.options.fetchPolicy;
3037
- this.bodyQueryOptions =
3038
- init.bodyQueryOptions || this.api.options.bodyQueryOptions;
3155
+ this.bodyQueryOptions = [
3156
+ ...(this.api.options.bodyQueryOptions || []),
3157
+ ...(init.bodyQueryOptions || []),
3158
+ ];
3039
3159
  // The Path and Params from resource
3040
3160
  const [resourcePath, resourceParams] = this.resource.pathAndParams();
3041
3161
  this._path = resourcePath;
@@ -3112,10 +3232,6 @@ class ODataRequest {
3112
3232
  ])
3113
3233
  : params;
3114
3234
  //#endregion
3115
- this._queryBody =
3116
- this._method === 'GET' &&
3117
- this.bodyQueryOptions.length > 0 &&
3118
- this.bodyQueryOptions.some((name) => this._params.has(`$${name}`));
3119
3235
  }
3120
3236
  get responseType() {
3121
3237
  return this._responseType &&
@@ -3126,52 +3242,49 @@ class ODataRequest {
3126
3242
  : this._responseType;
3127
3243
  }
3128
3244
  get path() {
3129
- return this._queryBody ? `${this._path}/${$QUERY}` : this._path;
3245
+ return this.isQueryBody() ? `${this._path}/${$QUERY}` : this._path;
3130
3246
  }
3131
3247
  get method() {
3132
- return this._queryBody ? 'POST' : this._method;
3248
+ return this.isQueryBody() ? 'POST' : this._method;
3133
3249
  }
3134
3250
  get body() {
3135
- if (this._queryBody) {
3136
- let [, bodyParams] = Http.splitHttpParams(this._params, this.bodyQueryOptions.map((name) => `$${name}`));
3137
- return bodyParams.toString();
3138
- }
3139
- else {
3140
- return this._body;
3141
- }
3251
+ return this.isQueryBody()
3252
+ ? Http.splitHttpParams(this._params, this.bodyQueryOptions.map((name) => `$${name}`))[1].toString()
3253
+ : this._body;
3142
3254
  }
3143
3255
  get params() {
3144
- if (this._queryBody) {
3145
- let [queryParams] = Http.splitHttpParams(this._params, this.bodyQueryOptions.map((name) => `$${name}`));
3146
- return queryParams;
3147
- }
3148
- else {
3149
- return this._params;
3150
- }
3256
+ return this.isQueryBody()
3257
+ ? Http.splitHttpParams(this._params, this.bodyQueryOptions.map((name) => `$${name}`))[0]
3258
+ : this._params;
3151
3259
  }
3152
3260
  get headers() {
3153
- if (this._queryBody) {
3154
- return Http.mergeHttpHeaders(this._headers, { CONTENT_TYPE: TEXT_PLAIN });
3155
- }
3156
- else {
3157
- return this._headers;
3158
- }
3261
+ return this.isQueryBody()
3262
+ ? Http.mergeHttpHeaders(this._headers, { CONTENT_TYPE: TEXT_PLAIN })
3263
+ : this._headers;
3159
3264
  }
3160
3265
  get pathWithParams() {
3161
- let path = this._path;
3162
- if (this._params.keys().length > 0) {
3163
- path = `${path}?${this._params}`;
3164
- }
3165
- return path;
3266
+ return this.params.keys().length > 0
3267
+ ? `${this.path}?${this.params}`
3268
+ : this.path;
3166
3269
  }
3167
3270
  get url() {
3168
- return `${this.api.serviceRootUrl}${this._path}`;
3271
+ return `${this.api.serviceRootUrl}${this.path}`;
3169
3272
  }
3170
3273
  get urlWithParams() {
3171
3274
  return `${this.api.serviceRootUrl}${this.pathWithParams}`;
3172
3275
  }
3276
+ get cacheKey() {
3277
+ return this._params.keys().length > 0
3278
+ ? `${this._path}?${this._params}`
3279
+ : this._path;
3280
+ }
3281
+ isQueryBody() {
3282
+ return (this._method === 'GET' &&
3283
+ this.bodyQueryOptions.length > 0 &&
3284
+ this.bodyQueryOptions.some((name) => this._params.has(`$${name}`)));
3285
+ }
3173
3286
  isBatch() {
3174
- return this._path.endsWith($BATCH);
3287
+ return this.path.endsWith($BATCH);
3175
3288
  }
3176
3289
  isFetch() {
3177
3290
  return ['GET'].indexOf(this._method) !== -1;
@@ -3705,7 +3818,7 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3705
3818
  this.alias = alias;
3706
3819
  this.flags = config.flags;
3707
3820
  this.members = config.members;
3708
- this.fields = Object.entries(config.fields).map(([name, f]) => new ODataEnumTypeFieldParser(name, f));
3821
+ this._fields = Object.entries(config.fields).map(([name, f]) => new ODataEnumTypeFieldParser(name, f));
3709
3822
  }
3710
3823
  /**
3711
3824
  * Create a nicer looking title.
@@ -3726,6 +3839,26 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3726
3839
  names.push(`${this.alias}.${this.name}`);
3727
3840
  return names.indexOf(type) !== -1;
3728
3841
  }
3842
+ fields(value) {
3843
+ return [
3844
+ ...this._fields.filter((f) => value === undefined || Boolean(f.value & value)),
3845
+ ];
3846
+ }
3847
+ field(nameValue) {
3848
+ let field = this.fields().find((f) => f.name === nameValue || f.value === nameValue);
3849
+ //Throw error if not found
3850
+ if (field === undefined)
3851
+ throw new Error(`${this.name} has no field named ${String(name)}`);
3852
+ return field;
3853
+ }
3854
+ /**
3855
+ * Map the fields of the enum type.
3856
+ * @param mapper Function that maps the value to the new value
3857
+ * @returns The fields mapped by the mapper
3858
+ */
3859
+ mapFields(mapper) {
3860
+ return this.fields().map(mapper);
3861
+ }
3729
3862
  // Deserialize
3730
3863
  deserialize(value, options) {
3731
3864
  // string -> number
@@ -3773,7 +3906,7 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3773
3906
  title: this.name,
3774
3907
  type: 'string',
3775
3908
  };
3776
- property.enum = this.fields.map((f) => f.name);
3909
+ property.enum = this._fields.map((f) => f.name);
3777
3910
  return property;
3778
3911
  }
3779
3912
  validate(member, { method, navigation = false, } = {}) {
@@ -3967,7 +4100,8 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
3967
4100
  //#endregion
3968
4101
  isKey() {
3969
4102
  var _a;
3970
- return (((_a = this.structuredType.keys) === null || _a === void 0 ? void 0 : _a.find((k) => k.name === this.name)) !== undefined);
4103
+ return (((_a = this.structuredType
4104
+ .keys({ include_parents: true })) === null || _a === void 0 ? void 0 : _a.find((k) => k.name === this.name)) !== undefined);
3971
4105
  }
3972
4106
  hasReferentials() {
3973
4107
  return this.referentials.length !== 0;
@@ -3991,6 +4125,11 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
3991
4125
  throw new Error('Field are not StrucuturedType');
3992
4126
  return this.parser;
3993
4127
  }
4128
+ field(name) {
4129
+ if (this.isStructuredType())
4130
+ return this.parser.field(name);
4131
+ throw new Error(`The field ${this.name} is not related to a StructuredType`);
4132
+ }
3994
4133
  }
3995
4134
  class ODataStructuredTypeParser extends ODataAnnotatable {
3996
4135
  constructor(config, namespace, alias) {
@@ -4002,8 +4141,8 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
4002
4141
  this.namespace = namespace;
4003
4142
  this.alias = alias;
4004
4143
  if (Array.isArray(config.keys))
4005
- this.keys = config.keys.map((key) => new ODataEntityTypeKey(key));
4006
- this.fields = Object.entries(config.fields).map(([name, config]) => new ODataStructuredTypeFieldParser(name, this, config));
4144
+ this._keys = config.keys.map((key) => new ODataEntityTypeKey(key));
4145
+ this._fields = Object.entries(config.fields).map(([name, config]) => new ODataStructuredTypeFieldParser(name, this, config));
4007
4146
  }
4008
4147
  /**
4009
4148
  * Create a nicer looking title.
@@ -4044,17 +4183,19 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
4044
4183
  // Deserialize
4045
4184
  deserialize(value, options) {
4046
4185
  const parserOptions = options || this.parserOptions;
4047
- if (this.parent !== undefined)
4048
- value = this.parent.deserialize(value, parserOptions);
4049
- const fields = this.fields.filter((f) => f.name in value && value[f.name] !== undefined && value[f.name] !== null);
4186
+ const fields = this.fields({
4187
+ include_navigation: true,
4188
+ include_parents: true,
4189
+ }).filter((f) => f.name in value && value[f.name] !== undefined && value[f.name] !== null);
4050
4190
  return Object.assign(Object.assign({}, value), fields.reduce((acc, f) => (Object.assign(Object.assign({}, acc), { [f.name]: f.deserialize(value[f.name], parserOptions) })), {}));
4051
4191
  }
4052
4192
  // Serialize
4053
4193
  serialize(value, options) {
4054
4194
  const parserOptions = options || this.parserOptions;
4055
- if (this.parent !== undefined)
4056
- value = this.parent.serialize(value, parserOptions);
4057
- const fields = this.fields.filter((f) => f.name in value &&
4195
+ const fields = this.fields({
4196
+ include_navigation: true,
4197
+ include_parents: true,
4198
+ }).filter((f) => f.name in value &&
4058
4199
  value[f.name] !== undefined &&
4059
4200
  value[f.name] !== null);
4060
4201
  return Object.assign(Object.assign({}, value), fields.reduce((acc, f) => (Object.assign(Object.assign({}, acc), { [f.name]: f.serialize(value[f.name], parserOptions) })), {}));
@@ -4071,41 +4212,104 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
4071
4212
  parent.children.push(this);
4072
4213
  this.parent = parent;
4073
4214
  }
4074
- this.fields.forEach((f) => f.configure({ parserForType, options }));
4215
+ this._fields.forEach((f) => f.configure({ parserForType, options }));
4075
4216
  }
4076
- resolveKey(value) {
4077
- var _a;
4078
- let key = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.resolveKey(value)) || {};
4079
- if (Array.isArray(this.keys) && this.keys.length > 0) {
4080
- for (var k of this.keys) {
4081
- let v = value;
4082
- let structured = this;
4083
- let field;
4084
- for (let name of k.name.split('/')) {
4085
- if (structured === undefined)
4086
- break;
4087
- field = structured.fields.find((f) => f.name === name);
4088
- if (field !== undefined) {
4089
- v = Types.isPlainObject(v) ? v[field.name] : v;
4090
- structured = field.isStructuredType()
4091
- ? field.structured()
4092
- : undefined;
4093
- }
4094
- }
4095
- if (field !== undefined && v !== undefined) {
4096
- key[k.alias || field.name] = field.encode(v);
4217
+ /**
4218
+ * Returns all fields of the structured type.
4219
+ * @param include_navigation Include navigation properties in the result.
4220
+ * @param include_parents Include the parent types in the result.
4221
+ * @returns All fields of the structured type.
4222
+ */
4223
+ fields({ include_navigation, include_parents, }) {
4224
+ return [
4225
+ ...(include_parents && this.parent !== undefined
4226
+ ? this.parent.fields({ include_parents, include_navigation })
4227
+ : []),
4228
+ ...this._fields.filter((field) => include_navigation || !field.navigation),
4229
+ ];
4230
+ }
4231
+ /**
4232
+ * Returns the keys of the structured type.
4233
+ * @param include_parents Include the parent fields
4234
+ * @returns The keys of the structured type
4235
+ */
4236
+ keys({ include_parents, }) {
4237
+ return [
4238
+ ...(include_parents && this.parent !== undefined
4239
+ ? this.parent.keys({ include_parents })
4240
+ : []),
4241
+ ...(this._keys || []),
4242
+ ];
4243
+ }
4244
+ /**
4245
+ * Find the field parser for the given field name.
4246
+ * @param name Name of the field
4247
+ * @returns The field parser
4248
+ */
4249
+ field(name) {
4250
+ let field = this.fields({
4251
+ include_parents: true,
4252
+ include_navigation: true,
4253
+ }).find((field) => field.name === name);
4254
+ //Throw error if not found
4255
+ if (field === undefined)
4256
+ throw new Error(`${this.name} has no field named ${String(name)}`);
4257
+ return field;
4258
+ }
4259
+ /**
4260
+ * Picks the fields from attributes.
4261
+ * @param attrs
4262
+ * @param include_parents Include the parent fields
4263
+ * @param include_navigation Include the navigation fields
4264
+ * @param include_etag Include the etag field
4265
+ * @returns The picked fields
4266
+ */
4267
+ pick(attrs, { include_parents = true, include_navigation = false, include_etag = true, options, } = {}) {
4268
+ const parserOptions = options || this.parserOptions;
4269
+ const names = this.fields({ include_parents, include_navigation }).map((f) => f.name);
4270
+ return Object.keys(attrs)
4271
+ .filter((key) => names.indexOf(key) !== -1 ||
4272
+ (key ==
4273
+ ODataHelper[(parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.version) || DEFAULT_VERSION].ODATA_ETAG &&
4274
+ include_etag))
4275
+ .reduce((acc, key) => Object.assign(acc, { [key]: attrs[key] }), {});
4276
+ }
4277
+ resolveKey(value, { resolve = true, single = true, } = {}) {
4278
+ const keyTypes = this.keys({ include_parents: true });
4279
+ const key = new Map();
4280
+ for (var kt of keyTypes) {
4281
+ let v = value;
4282
+ let structured = this;
4283
+ let field;
4284
+ for (let name of kt.name.split('/')) {
4285
+ if (structured === undefined)
4286
+ break;
4287
+ field = structured
4288
+ .fields({ include_navigation: false, include_parents: true })
4289
+ .find((f) => f.name === name);
4290
+ if (field !== undefined) {
4291
+ v = Types.isPlainObject(v) ? v[field.name] : v;
4292
+ structured = field.isStructuredType()
4293
+ ? field.structured()
4294
+ : undefined;
4097
4295
  }
4098
4296
  }
4297
+ if (field !== undefined && v !== undefined) {
4298
+ key.set(kt.alias || field.name, field.encode(v));
4299
+ }
4099
4300
  }
4100
- if (Types.isEmpty(key))
4301
+ if (key.size === 0)
4101
4302
  return undefined;
4102
- return Objects.resolveKey(key);
4303
+ return resolve
4304
+ ? Objects.resolveKey(key, { single })
4305
+ : Object.fromEntries(key);
4103
4306
  }
4104
4307
  defaults() {
4105
- var _a;
4106
- let value = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.defaults()) || {};
4107
- let fields = this.fields.filter((f) => f.default !== undefined || f.isStructuredType());
4108
- return Object.assign(Object.assign({}, value), fields.reduce((acc, f) => {
4308
+ let fields = this.fields({
4309
+ include_navigation: false,
4310
+ include_parents: true,
4311
+ }).filter((f) => f.default !== undefined || f.isStructuredType());
4312
+ return Object.assign({}, fields.reduce((acc, f) => {
4109
4313
  let value = f.isStructuredType()
4110
4314
  ? f.structured().defaults()
4111
4315
  : f.default;
@@ -4114,8 +4318,7 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
4114
4318
  }
4115
4319
  // Json Schema
4116
4320
  toJsonSchema(options = {}) {
4117
- var _a;
4118
- let schema = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.toJsonSchema(options)) || {
4321
+ let schema = {
4119
4322
  $schema: 'http://json-schema.org/draft-07/schema#',
4120
4323
  $id: `${this.namespace}.${this.name}`,
4121
4324
  title: this.titleize(DESCRIPTION),
@@ -4124,7 +4327,10 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
4124
4327
  properties: {},
4125
4328
  required: [],
4126
4329
  };
4127
- const fields = this.fields.filter((f) => (!f.navigation || (options.expand && f.name in options.expand)) &&
4330
+ const fields = this.fields({
4331
+ include_navigation: true,
4332
+ include_parents: true,
4333
+ }).filter((f) => (!f.navigation || (options.expand && f.name in options.expand)) &&
4128
4334
  (!options.select || options.select.indexOf(f.name) !== -1));
4129
4335
  schema.properties = Object.assign({}, schema.properties, fields
4130
4336
  .map((f) => {
@@ -4148,10 +4354,11 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
4148
4354
  return schema;
4149
4355
  }
4150
4356
  validate(attrs, { method, navigation = false, } = {}) {
4151
- var _a;
4152
- const errors = (((_a = this.parent) === null || _a === void 0 ? void 0 : _a.validate(attrs, { method, navigation })) ||
4153
- {});
4154
- const fields = this.fields.filter((f) => !f.navigation || navigation);
4357
+ const errors = {};
4358
+ const fields = this.fields({
4359
+ include_navigation: true,
4360
+ include_parents: true,
4361
+ }).filter((f) => !f.navigation || navigation);
4155
4362
  for (var field of fields) {
4156
4363
  const value = attrs[field.name];
4157
4364
  const errs = field.validate(value, { method, navigation });
@@ -4207,6 +4414,11 @@ class ODataParameterParser {
4207
4414
  throw new Error('Field are not StrucuturedType');
4208
4415
  return this.parser;
4209
4416
  }
4417
+ field(name) {
4418
+ if (this.isStructuredType())
4419
+ return this.parser.field(name);
4420
+ throw new Error(`The field ${this.name} is not related to a StructuredType`);
4421
+ }
4210
4422
  }
4211
4423
  class ODataCallableParser {
4212
4424
  constructor(config, namespace, alias) {
@@ -4353,32 +4565,16 @@ class ODataEnumType extends ODataSchemaElement {
4353
4565
  * Returns the fields of the enum type.
4354
4566
  * @returns The fields of the enum type.
4355
4567
  */
4356
- fields() {
4357
- return this.parser.fields;
4568
+ fields(value) {
4569
+ return this.parser.fields(value);
4358
4570
  }
4359
4571
  /**
4360
- * Find a field by name.
4361
- * @param name The name of the field
4362
- * @returns The field with the given name
4572
+ * Find a field by name or value.
4573
+ * @param enu The name or value of the field
4574
+ * @returns The field with the given name or value
4363
4575
  */
4364
- findFieldByName(name) {
4365
- return this.fields().find((f) => f.name === name);
4366
- }
4367
- /**
4368
- * Find a field by value.
4369
- * @param value The value of the field
4370
- * @returns The field with the given value
4371
- */
4372
- findFieldByValue(value) {
4373
- return this.fields().find((f) => f.value === value);
4374
- }
4375
- /**
4376
- * Find a fields by flag.
4377
- * @param value The value of the field
4378
- * @returns The fields with the given flag
4379
- */
4380
- findFieldsByValue(value) {
4381
- return this.fields().filter((f) => Boolean(f.value & value));
4576
+ field(enu) {
4577
+ return this.parser.field(enu);
4382
4578
  }
4383
4579
  /**
4384
4580
  * Map the fields of the enum type.
@@ -4386,7 +4582,7 @@ class ODataEnumType extends ODataSchemaElement {
4386
4582
  * @returns The fields mapped by the mapper
4387
4583
  */
4388
4584
  mapFields(mapper) {
4389
- return this.fields().map(mapper);
4585
+ return this.parser.mapFields(mapper);
4390
4586
  }
4391
4587
  /**
4392
4588
  * Deseialize the given value from the enum type.
@@ -4490,11 +4686,8 @@ class ODataStructuredType extends ODataSchemaElement {
4490
4686
  * @param name Name of the field
4491
4687
  * @returns The field parser
4492
4688
  */
4493
- findFieldByName(name) {
4494
- return this.fields({
4495
- include_parents: true,
4496
- include_navigation: true,
4497
- }).find((f) => f.name === name);
4689
+ field(name) {
4690
+ return this.parser.field(name);
4498
4691
  }
4499
4692
  /**
4500
4693
  * Find a parent schema of the structured type.
@@ -4518,33 +4711,6 @@ class ODataStructuredType extends ODataSchemaElement {
4518
4711
  .fields({ include_parents: false, include_navigation: true })
4519
4712
  .find((f) => f === field) !== undefined);
4520
4713
  }
4521
- /**
4522
- * Returns all fields of the structured type.
4523
- * @param include_navigation Include navigation properties in the result.
4524
- * @param include_parents Include the parent types in the result.
4525
- * @returns All fields of the structured type.
4526
- */
4527
- fields({ include_navigation, include_parents, }) {
4528
- return [
4529
- ...(include_parents && this.parent !== undefined
4530
- ? this.parent.fields({ include_parents, include_navigation })
4531
- : []),
4532
- ...this.parser.fields.filter((field) => include_navigation || !field.navigation),
4533
- ];
4534
- }
4535
- /**
4536
- * Returns the keys of the structured type.
4537
- * @param include_parents Include the parent fields
4538
- * @returns The keys of the structured type
4539
- */
4540
- keys({ include_parents = true, } = {}) {
4541
- return [
4542
- ...(include_parents && this.parent !== undefined
4543
- ? this.parent.keys({ include_parents })
4544
- : []),
4545
- ...(this.parser.keys || []),
4546
- ];
4547
- }
4548
4714
  /**
4549
4715
  * Picks the fields from attributes.
4550
4716
  * @param attrs
@@ -4554,11 +4720,12 @@ class ODataStructuredType extends ODataSchemaElement {
4554
4720
  * @returns The picked fields
4555
4721
  */
4556
4722
  pick(attrs, { include_parents = true, include_navigation = false, include_etag = true, } = {}) {
4557
- const names = this.fields({ include_parents, include_navigation }).map((f) => f.name);
4558
- return Object.keys(attrs)
4559
- .filter((key) => names.indexOf(key) !== -1 ||
4560
- (key == this.api.options.helper.ODATA_ETAG && include_etag))
4561
- .reduce((acc, key) => Object.assign(acc, { [key]: attrs[key] }), {});
4723
+ return this.parser.pick(attrs, {
4724
+ include_etag,
4725
+ include_navigation,
4726
+ include_parents,
4727
+ options: this.api.options,
4728
+ });
4562
4729
  }
4563
4730
  /**
4564
4731
  * Deseialize the given value from the structured type.
@@ -4587,6 +4754,23 @@ class ODataStructuredType extends ODataSchemaElement {
4587
4754
  encode(value, options) {
4588
4755
  return this.parser.encode(value, options);
4589
4756
  }
4757
+ /**
4758
+ * Returns all fields of the structured type.
4759
+ * @param include_navigation Include navigation properties in the result.
4760
+ * @param include_parents Include the parent types in the result.
4761
+ * @returns All fields of the structured type.
4762
+ */
4763
+ fields({ include_navigation, include_parents, }) {
4764
+ return this.parser.fields({ include_navigation, include_parents });
4765
+ }
4766
+ /**
4767
+ * Returns the keys of the structured type.
4768
+ * @param include_parents Include the parent fields
4769
+ * @returns The keys of the structured type
4770
+ */
4771
+ keys({ include_parents = true, } = {}) {
4772
+ return this.parser.keys({ include_parents });
4773
+ }
4590
4774
  /**
4591
4775
  * Resolve the key of the structured type for the given value.
4592
4776
  * @param attrs Attributes of the value
@@ -4711,6 +4895,10 @@ class ODataResource {
4711
4895
  var _a;
4712
4896
  return Boolean((_a = this.pathSegments.last({ key: true })) === null || _a === void 0 ? void 0 : _a.hasKey());
4713
4897
  }
4898
+ hasEntityKey() {
4899
+ var _a;
4900
+ return Boolean((_a = this.pathSegments.get(PathSegmentNames.entitySet)) === null || _a === void 0 ? void 0 : _a.hasKey());
4901
+ }
4714
4902
  clearKey() {
4715
4903
  var _a;
4716
4904
  return (_a = this.pathSegments.last({ key: true })) === null || _a === void 0 ? void 0 : _a.clearKey();
@@ -4873,7 +5061,11 @@ class ODataResource {
4873
5061
  * @returns ODataActionResource
4874
5062
  */
4875
5063
  segment(f) {
4876
- f(new ODataPathSegmentsHandler(this.pathSegments));
5064
+ /*
5065
+ const type = this.type();
5066
+ const schema = type ? this.api.findStructuredTypeForType<T>(type) : undefined;
5067
+ */
5068
+ f(new ODataPathSegmentsHandler(this.pathSegments), this.schema instanceof ODataStructuredType ? this.schema : undefined);
4877
5069
  return this;
4878
5070
  }
4879
5071
  /**
@@ -4882,7 +5074,11 @@ class ODataResource {
4882
5074
  * @param f Function context for handle the query options
4883
5075
  */
4884
5076
  query(f) {
4885
- f(new ODataQueryOptionsHandler(this.queryOptions));
5077
+ /*
5078
+ const type = this.returnType();
5079
+ const schema = type ? this.api.findStructuredTypeForType<T>(type) : undefined;
5080
+ */
5081
+ f(new ODataQueryOptionsHandler(this.queryOptions), this.schema instanceof ODataStructuredType ? this.schema : undefined);
4886
5082
  return this;
4887
5083
  }
4888
5084
  static resolveKey(value, schema) {
@@ -5644,7 +5840,7 @@ class ODataPropertyResource extends ODataResource {
5644
5840
  let fieldType;
5645
5841
  let fieldSchema;
5646
5842
  if (baseSchema !== undefined) {
5647
- const field = baseSchema.findFieldByName(path);
5843
+ const field = baseSchema.field(path);
5648
5844
  fieldType = field === null || field === void 0 ? void 0 : field.type;
5649
5845
  fieldSchema =
5650
5846
  fieldType !== undefined
@@ -5701,7 +5897,7 @@ class ODataPropertyResource extends ODataResource {
5701
5897
  navigationProperty<N>(path: string) {
5702
5898
  let schema: ODataStructuredType<N> | undefined;
5703
5899
  if (this.schema instanceof ODataStructuredType) {
5704
- const field = this.schema.findFieldByName<any>(path as keyof T);
5900
+ const field = this.schema.field<any>(path as keyof T);
5705
5901
  schema =
5706
5902
  field !== undefined
5707
5903
  ? this.schema.findSchemaForField<N>(field)
@@ -5719,7 +5915,7 @@ class ODataPropertyResource extends ODataResource {
5719
5915
  let type;
5720
5916
  let schema;
5721
5917
  if (this.schema instanceof ODataStructuredType) {
5722
- const field = this.schema.findFieldByName(path);
5918
+ const field = this.schema.field(path);
5723
5919
  type = field === null || field === void 0 ? void 0 : field.type;
5724
5920
  schema =
5725
5921
  field !== undefined
@@ -5913,7 +6109,7 @@ class ODataNavigationPropertyResource extends ODataResource {
5913
6109
  let fieldType;
5914
6110
  let fieldSchema;
5915
6111
  if (baseSchema !== undefined) {
5916
- const field = baseSchema.findFieldByName(path);
6112
+ const field = baseSchema.field(path);
5917
6113
  fieldType = field === null || field === void 0 ? void 0 : field.type;
5918
6114
  fieldSchema =
5919
6115
  fieldType !== undefined
@@ -6053,6 +6249,8 @@ class ODataNavigationPropertyResource extends ODataResource {
6053
6249
  return this.delete(options);
6054
6250
  }
6055
6251
  fetch(options = {}) {
6252
+ if (!this.hasEntityKey())
6253
+ return throwError(() => new Error('fetch: Navigation resource without entity key'));
6056
6254
  return this.get(options);
6057
6255
  }
6058
6256
  /**
@@ -7612,7 +7810,7 @@ class ODataInStorageCache extends ODataCache {
7612
7810
  putResponse(req, res) {
7613
7811
  const scope = this.scope(req);
7614
7812
  const tags = this.tags(res);
7615
- this.put(req.pathWithParams, res.toJSON(), {
7813
+ this.put(req.cacheKey, res.toJSON(), {
7616
7814
  timeout: res.options.maxAge,
7617
7815
  scope,
7618
7816
  tags,
@@ -7625,13 +7823,13 @@ class ODataInStorageCache extends ODataCache {
7625
7823
  */
7626
7824
  getResponse(req) {
7627
7825
  const scope = this.scope(req);
7628
- const data = this.get(req.pathWithParams, { scope });
7826
+ const data = this.get(req.cacheKey, { scope });
7629
7827
  return data !== undefined ? ODataResponse.fromJSON(req, data) : undefined;
7630
7828
  }
7631
7829
  }
7632
7830
 
7633
7831
  class ODataModelEvent {
7634
- constructor(name, { model, collection, previous, value, track, options, } = {}) {
7832
+ constructor(name, { model, collection, previous, value, field, options, } = {}) {
7635
7833
  this.bubbling = true;
7636
7834
  this.name = name;
7637
7835
  this.model = model;
@@ -7642,15 +7840,24 @@ class ODataModelEvent {
7642
7840
  this.chain = [
7643
7841
  [
7644
7842
  (this.collection || this.model),
7645
- track || null,
7843
+ field || null,
7646
7844
  ],
7647
7845
  ];
7648
7846
  }
7649
7847
  stopPropagation() {
7650
7848
  this.bubbling = false;
7651
7849
  }
7652
- push(model, track) {
7653
- this.chain.splice(0, 0, [model, track]);
7850
+ push(model, field) {
7851
+ let event = new ODataModelEvent(this.name, {
7852
+ model: this.model,
7853
+ collection: this.collection,
7854
+ previous: this.previous,
7855
+ value: this.value,
7856
+ options: this.options,
7857
+ });
7858
+ event.chain = [...this.chain];
7859
+ event.chain.splice(0, 0, [model, field]);
7860
+ return event;
7654
7861
  }
7655
7862
  visited(model) {
7656
7863
  return (this.chain.some((c) => c[0] === model) &&
@@ -7658,12 +7865,12 @@ class ODataModelEvent {
7658
7865
  }
7659
7866
  get path() {
7660
7867
  return this.chain
7661
- .map(([, track], index) => typeof track === 'number'
7662
- ? `[${track}]`
7663
- : typeof track === 'string'
7868
+ .map(([, field], index) => typeof field === 'number'
7869
+ ? `[${field}]`
7870
+ : field instanceof ODataModelField
7664
7871
  ? index === 0
7665
- ? track
7666
- : `.${track}`
7872
+ ? field.name
7873
+ : `.${field.name}`
7667
7874
  : '')
7668
7875
  .join('');
7669
7876
  }
@@ -7907,7 +8114,7 @@ class ODataModelOptions {
7907
8114
  const { field } = options, opts = __rest(options, ["field"]);
7908
8115
  if (field === undefined || name === undefined)
7909
8116
  throw new Error('Model Properties need name and field');
7910
- const parser = this.schema.findFieldByName(field);
8117
+ const parser = this.schema.field(field);
7911
8118
  if (parser === undefined)
7912
8119
  throw new Error(`No parser for ${field} with name = ${name}`);
7913
8120
  return new ODataModelField(this, Object.assign({ name, field, parser }, opts));
@@ -7916,12 +8123,25 @@ class ODataModelOptions {
7916
8123
  get api() {
7917
8124
  return this.schema.api;
7918
8125
  }
7919
- type() {
7920
- return this.schema.type();
8126
+ type({ alias = false } = {}) {
8127
+ return this.schema.type({ alias });
7921
8128
  }
7922
8129
  isTypeOf(type) {
7923
8130
  return this.schema.isTypeOf(type);
7924
8131
  }
8132
+ isModelFor(entity) {
8133
+ // Resolve By Type
8134
+ let type = this.api.options.helper.type(entity);
8135
+ if (type && this.isTypeOf(type))
8136
+ return true;
8137
+ // Resolve By fields
8138
+ let keys = Object.keys(entity);
8139
+ let names = this.fields({
8140
+ include_navigation: true,
8141
+ include_parents: true,
8142
+ }).map((f) => f.name);
8143
+ return keys.every((key) => names.includes(key));
8144
+ }
7925
8145
  findChildOptions(predicate) {
7926
8146
  if (predicate(this))
7927
8147
  return this;
@@ -7954,7 +8174,7 @@ class ODataModelOptions {
7954
8174
  });
7955
8175
  });
7956
8176
  }
7957
- fields({ include_navigation = false, include_parents = true, } = {}) {
8177
+ fields({ include_navigation, include_parents, }) {
7958
8178
  return [
7959
8179
  ...(include_parents && this.parent !== undefined
7960
8180
  ? this.parent.fields({ include_navigation, include_parents })
@@ -8090,7 +8310,7 @@ class ODataModelOptions {
8090
8310
  this.attach(self, resource);
8091
8311
  return self;
8092
8312
  }
8093
- resolveKey(value, { field_mapping = false, resolve = true, } = {}) {
8313
+ resolveKey(value, { field_mapping = false, resolve = true, single = true, } = {}) {
8094
8314
  const keyTypes = this.schema.keys({ include_parents: true });
8095
8315
  const key = new Map();
8096
8316
  for (let kt of keyTypes) {
@@ -8101,7 +8321,7 @@ class ODataModelOptions {
8101
8321
  if (options === undefined)
8102
8322
  break;
8103
8323
  field = options
8104
- .fields({ include_parents: true })
8324
+ .fields({ include_navigation: false, include_parents: true })
8105
8325
  .find((field) => field.field === name);
8106
8326
  if (field !== undefined) {
8107
8327
  v =
@@ -8120,14 +8340,19 @@ class ODataModelOptions {
8120
8340
  }
8121
8341
  if (key.size === 0)
8122
8342
  return undefined;
8123
- return resolve ? Objects.resolveKey(key) : Object.fromEntries(key);
8343
+ return resolve
8344
+ ? Objects.resolveKey(key, { single })
8345
+ : Object.fromEntries(key);
8124
8346
  }
8125
- resolveReferential(value, field, { field_mapping = false, resolve = true, } = {}) {
8347
+ resolveReferential(value, field, { field_mapping = false, resolve = true, single = false, } = {}) {
8126
8348
  const referential = new Map();
8127
8349
  for (let ref of field.referentials) {
8128
- let from = this.fields({ include_parents: true }).find((p) => p.field === ref.referencedProperty);
8350
+ let from = this.fields({
8351
+ include_navigation: false,
8352
+ include_parents: true,
8353
+ }).find((p) => p.field === ref.referencedProperty);
8129
8354
  let to = field.options
8130
- .fields({ include_parents: true })
8355
+ .fields({ include_navigation: false, include_parents: true })
8131
8356
  .find((field) => field.field === ref.property);
8132
8357
  if (from !== undefined && to !== undefined) {
8133
8358
  let name = field_mapping ? to.field : to.name;
@@ -8139,15 +8364,18 @@ class ODataModelOptions {
8139
8364
  if (referential.size === 1 && Array.from(referential.values())[0] === null)
8140
8365
  return null;
8141
8366
  return resolve
8142
- ? Objects.resolveKey(referential, { single: false })
8367
+ ? Objects.resolveKey(referential, { single })
8143
8368
  : Object.fromEntries(referential);
8144
8369
  }
8145
- resolveReferenced(value, field, { field_mapping = false, resolve = true, } = {}) {
8370
+ resolveReferenced(value, field, { field_mapping = false, resolve = true, single = false, } = {}) {
8146
8371
  const referenced = new Map();
8147
8372
  for (let ref of field.referentials) {
8148
- let from = this.fields({ include_parents: true }).find((field) => field.field === ref.property);
8373
+ let from = this.fields({
8374
+ include_navigation: false,
8375
+ include_parents: true,
8376
+ }).find((field) => field.field === ref.property);
8149
8377
  let to = field.meta
8150
- .fields({ include_parents: true })
8378
+ .fields({ include_navigation: false, include_parents: true })
8151
8379
  .find((field) => field.field === ref.referencedProperty);
8152
8380
  if (from !== undefined && to !== undefined) {
8153
8381
  let name = field_mapping ? to.field : to.name;
@@ -8159,7 +8387,7 @@ class ODataModelOptions {
8159
8387
  if (referenced.size === 1 && Array.from(referenced.values())[0] === null)
8160
8388
  return null;
8161
8389
  return resolve
8162
- ? Objects.resolveKey(referenced, { single: false })
8390
+ ? Objects.resolveKey(referenced, { single })
8163
8391
  : Object.fromEntries(referenced);
8164
8392
  }
8165
8393
  validate(self, { method, navigation = false, } = {}) {
@@ -8176,7 +8404,10 @@ class ODataModelOptions {
8176
8404
  return !Types.isEmpty(errors) ? errors : undefined;
8177
8405
  }
8178
8406
  defaults() {
8179
- const defs = this.fields().reduce((acc, field) => {
8407
+ const defs = this.fields({
8408
+ include_navigation: false,
8409
+ include_parents: true,
8410
+ }).reduce((acc, field) => {
8180
8411
  let value = field.defaults();
8181
8412
  return value !== undefined
8182
8413
  ? Object.assign(acc, { [field.name]: value })
@@ -8193,8 +8424,9 @@ class ODataModelOptions {
8193
8424
  (model != undefined && model.hasChanged({ include_navigation })))));
8194
8425
  }
8195
8426
  asEntity(self, func) {
8427
+ var _a;
8196
8428
  // Build new resource
8197
- const query = self.resource().cloneQuery();
8429
+ const query = (_a = self._resource) === null || _a === void 0 ? void 0 : _a.cloneQuery();
8198
8430
  let resource = this.modelResourceFactory(query);
8199
8431
  if (resource === undefined)
8200
8432
  throw new Error('Model does not have associated Entity endpoint');
@@ -8281,7 +8513,11 @@ class ODataModelOptions {
8281
8513
  .reduce((acc, [k, v]) => {
8282
8514
  var _a;
8283
8515
  const name = field_mapping
8284
- ? ((_a = this.fields().find((field) => field.name === k)) === null || _a === void 0 ? void 0 : _a.field) || k
8516
+ ? ((_a = this.fields({
8517
+ include_navigation: false,
8518
+ include_parents: true,
8519
+ }).find((field) => field.name === k)) === null || _a === void 0 ? void 0 : _a.field) ||
8520
+ k
8285
8521
  : k;
8286
8522
  return Object.assign(acc, { [name]: v });
8287
8523
  }, {});
@@ -8308,7 +8544,10 @@ class ODataModelOptions {
8308
8544
  }
8309
8545
  attributes(self, { changes_only = false, include_concurrency = false, include_computed = false, include_non_field = false, field_mapping = false, } = {}) {
8310
8546
  // Attributes by fields (attributes for the model type)
8311
- const fieldAttrs = this.fields().reduce((acc, f) => {
8547
+ const fieldAttrs = this.fields({
8548
+ include_navigation: false,
8549
+ include_parents: true,
8550
+ }).reduce((acc, f) => {
8312
8551
  const isChanged = self._changes.has(f.name);
8313
8552
  const name = field_mapping ? f.field : f.name;
8314
8553
  const computed = f.annotatedValue(COMPUTED);
@@ -8429,8 +8668,8 @@ class ODataModelOptions {
8429
8668
  _get(self, field) {
8430
8669
  if (field.isStructuredType()) {
8431
8670
  const relation = self._relations.get(field.name);
8432
- if ((relation === null || relation === void 0 ? void 0 : relation.model) === null ||
8433
- ODataModelOptions.isModel(relation === null || relation === void 0 ? void 0 : relation.model)) {
8671
+ if (field.navigation &&
8672
+ ((relation === null || relation === void 0 ? void 0 : relation.model) === null || ODataModelOptions.isModel(relation === null || relation === void 0 ? void 0 : relation.model))) {
8434
8673
  // Check for reference
8435
8674
  const referenced = this.resolveReferenced(self, field);
8436
8675
  if ((relation === null || relation === void 0 ? void 0 : relation.model) !== null &&
@@ -8543,7 +8782,7 @@ class ODataModelOptions {
8543
8782
  if (!ODataModelOptions.isCollection(relation.model)) {
8544
8783
  let ref = (_a = field.meta) === null || _a === void 0 ? void 0 : _a.resolveReferential(relation.model, field);
8545
8784
  if (ref !== null && ref !== undefined) {
8546
- Object.entries(ref).forEach(([k, v]) => this._setValue(self, k, v, false));
8785
+ Object.assign(self, ref);
8547
8786
  }
8548
8787
  }
8549
8788
  // Update state and emit event
@@ -8553,7 +8792,7 @@ class ODataModelOptions {
8553
8792
  : ODataModelState.Changed;
8554
8793
  if (!self._silent && changed) {
8555
8794
  self.events$.emit(new ODataModelEvent('change', {
8556
- track: field.name,
8795
+ field: field,
8557
8796
  model: self,
8558
8797
  value: relation.model,
8559
8798
  previous: current,
@@ -8567,21 +8806,22 @@ class ODataModelOptions {
8567
8806
  include_concurrency: true,
8568
8807
  include_computed: true,
8569
8808
  });
8570
- const currentValue = attrs[field];
8809
+ const name = field.name;
8810
+ const currentValue = attrs[name];
8571
8811
  changed = !Types.isEqual(currentValue, value);
8572
8812
  if (self._reset) {
8573
- self._changes.delete(field);
8574
- self._attributes.set(field, value);
8813
+ self._changes.delete(name);
8814
+ self._attributes.set(name, value);
8575
8815
  }
8576
- else if (Types.isEqual(value, self._attributes.get(field))) {
8577
- self._changes.delete(field);
8816
+ else if (Types.isEqual(value, self._attributes.get(name))) {
8817
+ self._changes.delete(name);
8578
8818
  }
8579
8819
  else if (changed) {
8580
- self._changes.set(field, value);
8820
+ self._changes.set(name, value);
8581
8821
  }
8582
8822
  if (!self._silent && changed) {
8583
8823
  self.events$.emit(new ODataModelEvent('change', {
8584
- track: field,
8824
+ field: field,
8585
8825
  model: self,
8586
8826
  value,
8587
8827
  previous: currentValue,
@@ -8593,7 +8833,7 @@ class ODataModelOptions {
8593
8833
  _set(self, field, value) {
8594
8834
  return field.isStructuredType()
8595
8835
  ? this._setStructured(self, field, value)
8596
- : this._setValue(self, field.name, value, field.isKey());
8836
+ : this._setValue(self, field, value, field.isKey());
8597
8837
  }
8598
8838
  _unlink(self, relation) {
8599
8839
  if (relation.subscription !== undefined) {
@@ -8624,12 +8864,11 @@ class ODataModelOptions {
8624
8864
  ((_a = event.options) === null || _a === void 0 ? void 0 : _a.key)) {
8625
8865
  let ref = relation.model.referential(relation.field);
8626
8866
  if (ref !== null && ref !== undefined) {
8627
- Object.entries(ref).forEach(([k, v]) => this._setValue(self, k, v, false));
8867
+ Object.assign(self, ref);
8628
8868
  }
8629
8869
  }
8630
8870
  }
8631
- event.push(self, relation.field.name);
8632
- self.events$.emit(event);
8871
+ self.events$.emit(event.push(self, relation.field));
8633
8872
  }
8634
8873
  });
8635
8874
  }
@@ -8637,6 +8876,7 @@ class ODataModelOptions {
8637
8876
 
8638
8877
  class ODataCollection {
8639
8878
  constructor(entities = [], { parent, resource, annots, model, reset = false, } = {}) {
8879
+ var _a;
8640
8880
  this._parent = null;
8641
8881
  this._resource = null;
8642
8882
  this._entries = [];
@@ -8662,7 +8902,7 @@ class ODataCollection {
8662
8902
  // Annotations
8663
8903
  this._annotations =
8664
8904
  annots ||
8665
- new ODataEntitiesAnnotations((resource === null || resource === void 0 ? void 0 : resource.api.options.helper) || ODataHelper[DEFAULT_VERSION]);
8905
+ new ODataEntitiesAnnotations(ODataHelper[((_a = resource === null || resource === void 0 ? void 0 : resource.api) === null || _a === void 0 ? void 0 : _a.options.version) || DEFAULT_VERSION]);
8666
8906
  entities = entities || [];
8667
8907
  this.assign(entities, { reset });
8668
8908
  }
@@ -8701,8 +8941,9 @@ class ODataCollection {
8701
8941
  }
8702
8942
  }
8703
8943
  asEntitySet(func) {
8944
+ var _a;
8704
8945
  // Build new resource
8705
- const query = this.resource().cloneQuery();
8946
+ const query = (_a = this._resource) === null || _a === void 0 ? void 0 : _a.cloneQuery();
8706
8947
  let resource = this._model.meta.collectionResourceFactory(query);
8707
8948
  if (resource === undefined)
8708
8949
  throw new Error('asEntitySet: Collection does not have associated EntitySet endpoint');
@@ -8803,7 +9044,8 @@ class ODataCollection {
8803
9044
  options: { observable: obs$ },
8804
9045
  }));
8805
9046
  return obs$.pipe(map((entities) => {
8806
- this._annotations = new ODataEntitiesAnnotations(resource === null || resource === void 0 ? void 0 : resource.api.options.helper);
9047
+ var _a;
9048
+ this._annotations = new ODataEntitiesAnnotations(ODataHelper[((_a = resource === null || resource === void 0 ? void 0 : resource.api) === null || _a === void 0 ? void 0 : _a.options.version) || DEFAULT_VERSION]);
8807
9049
  this.assign(entities || [], { reset: true });
8808
9050
  this.events$.emit(new ODataModelEvent('sync', {
8809
9051
  collection: this,
@@ -9296,8 +9538,7 @@ class ODataCollection {
9296
9538
  }
9297
9539
  }
9298
9540
  const index = this.models().indexOf(entry.model);
9299
- event.push(this, index);
9300
- this.events$.emit(event);
9541
+ this.events$.emit(event.push(this, index));
9301
9542
  }
9302
9543
  });
9303
9544
  }
@@ -9660,8 +9901,6 @@ class ODataModel {
9660
9901
  return throwError(() => new Error('fetch: Resource is undefined'));
9661
9902
  let obs$;
9662
9903
  if (resource instanceof ODataEntityResource) {
9663
- if (!resource.hasKey())
9664
- return throwError(() => new Error("fetch: Can't fetch model without key"));
9665
9904
  obs$ = resource.fetch(options);
9666
9905
  }
9667
9906
  else if (resource instanceof ODataNavigationPropertyResource) {
@@ -9957,7 +10196,7 @@ class ODataApi {
9957
10196
  this.options = new ODataApiOptions(Object.assign({ version: this.version }, config.options || {}));
9958
10197
  this.cache = config.cache || new ODataInMemoryCache();
9959
10198
  this.errorHandler = config.errorHandler;
9960
- this.parsers = config.parsers || EDM_PARSERS;
10199
+ this.parsers = new Map(Object.entries(config.parsers || EDM_PARSERS));
9961
10200
  this.schemas = (config.schemas || []).map((schema) => new ODataSchema(schema, this));
9962
10201
  }
9963
10202
  configure(settings = {}) {
@@ -10071,32 +10310,40 @@ class ODataApi {
10071
10310
  }
10072
10311
  findEnumTypeForType(type) {
10073
10312
  var _a;
10074
- if (!this.memo.forType.enum.has(type)) {
10075
- this.memo.forType.enum.set(type, (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findEnumTypeForType(type));
10313
+ if (this.memo.forType.enum.has(type)) {
10314
+ return this.memo.forType.enum.get(type);
10076
10315
  }
10077
- return this.memo.forType.enum.get(type);
10316
+ const enumType = (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findEnumTypeForType(type);
10317
+ this.memo.forType.enum.set(type, enumType);
10318
+ return enumType;
10078
10319
  }
10079
10320
  findStructuredTypeForType(type) {
10080
10321
  var _a;
10081
- if (!this.memo.forType.structured.has(type)) {
10082
- this.memo.forType.structured.set(type, (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findStructuredTypeForType(type));
10322
+ if (this.memo.forType.structured.has(type)) {
10323
+ return this.memo.forType.structured.get(type);
10083
10324
  }
10084
- return this.memo.forType.structured.get(type);
10325
+ const structuredType = (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findStructuredTypeForType(type);
10326
+ this.memo.forType.structured.set(type, structuredType);
10327
+ return structuredType;
10085
10328
  }
10086
10329
  findCallableForType(type, bindingType) {
10087
10330
  var _a;
10088
10331
  const key = bindingType !== undefined ? `${bindingType}/${type}` : type;
10089
- if (!this.memo.forType.callable.has(key)) {
10090
- this.memo.forType.callable.set(key, (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findCallableForType(type, bindingType));
10332
+ if (this.memo.forType.callable.has(key)) {
10333
+ return this.memo.forType.callable.get(key);
10091
10334
  }
10092
- return this.memo.forType.callable.get(key);
10335
+ const callable = (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findCallableForType(type, bindingType);
10336
+ this.memo.forType.callable.set(key, callable);
10337
+ return callable;
10093
10338
  }
10094
10339
  findEntitySetForType(type) {
10095
10340
  var _a;
10096
- if (!this.memo.forType.entitySet.has(type)) {
10097
- this.memo.forType.entitySet.set(type, (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findEntitySetForType(type));
10341
+ if (this.memo.forType.entitySet.has(type)) {
10342
+ return this.memo.forType.entitySet.get(type);
10098
10343
  }
10099
- return this.memo.forType.entitySet.get(type);
10344
+ const entitySet = (_a = this.findSchemaForType(type)) === null || _a === void 0 ? void 0 : _a.findEntitySetForType(type);
10345
+ this.memo.forType.entitySet.set(type, entitySet);
10346
+ return entitySet;
10100
10347
  }
10101
10348
  findModelForType(type) {
10102
10349
  var _a;
@@ -10146,53 +10393,63 @@ class ODataApi {
10146
10393
  return (_a = this.findEntitySetForType(type)) === null || _a === void 0 ? void 0 : _a.service;
10147
10394
  }
10148
10395
  findEntitySetForEntityType(entityType) {
10149
- if (!this.memo.forType.entitySet.has(entityType)) {
10150
- this.memo.forType.entitySet.set(entityType, this.schemas
10151
- .reduce((acc, schema) => [...acc, ...schema.entitySets], [])
10152
- .find((e) => e.entityType === entityType));
10396
+ if (this.memo.forType.entitySet.has(entityType)) {
10397
+ return this.memo.forType.entitySet.get(entityType);
10153
10398
  }
10154
- return this.memo.forType.entitySet.get(entityType);
10399
+ const entitySet = this.schemas
10400
+ .reduce((acc, schema) => [...acc, ...schema.entitySets], [])
10401
+ .find((e) => e.entityType === entityType);
10402
+ this.memo.forType.entitySet.set(entityType, entitySet);
10403
+ return entitySet;
10155
10404
  }
10156
10405
  findServiceForEntityType(entityType) {
10157
10406
  var _a;
10158
10407
  return (_a = this.findEntitySetForEntityType(entityType)) === null || _a === void 0 ? void 0 : _a.service;
10159
10408
  }
10160
10409
  findEnumTypeByName(name) {
10161
- if (!this.memo.byName.enum.has(name)) {
10162
- this.memo.byName.enum.set(name, this.schemas
10163
- .reduce((acc, schema) => [...acc, ...schema.enums], [])
10164
- .find((e) => e.name === name));
10410
+ if (this.memo.byName.enum.has(name)) {
10411
+ return this.memo.byName.enum.get(name);
10165
10412
  }
10166
- return this.memo.byName.enum.get(name);
10413
+ const enumType = this.schemas
10414
+ .reduce((acc, schema) => [...acc, ...schema.enums], [])
10415
+ .find((e) => e.name === name);
10416
+ this.memo.byName.enum.set(name, enumType);
10417
+ return enumType;
10167
10418
  }
10168
10419
  findStructuredTypeByName(name) {
10169
- if (!this.memo.byName.structured.has(name)) {
10170
- this.memo.byName.structured.set(name, this.schemas
10171
- .reduce((acc, schema) => [...acc, ...schema.entities], [])
10172
- .find((e) => e.name === name));
10420
+ if (this.memo.byName.structured.has(name)) {
10421
+ return this.memo.byName.structured.get(name);
10173
10422
  }
10174
- return this.memo.byName.structured.get(name);
10423
+ const structuredType = this.schemas
10424
+ .reduce((acc, schema) => [...acc, ...schema.entities], [])
10425
+ .find((e) => e.name === name);
10426
+ this.memo.byName.structured.set(name, structuredType);
10427
+ return structuredType;
10175
10428
  }
10176
10429
  findCallableByName(name, bindingType) {
10177
10430
  const key = bindingType !== undefined ? `${bindingType}/${name}` : name;
10178
- if (!this.memo.byName.callable.has(key)) {
10179
- this.memo.byName.callable.set(key, this.schemas
10180
- .reduce((acc, schema) => [...acc, ...schema.callables], [])
10181
- .find((c) => {
10182
- var _a;
10183
- return c.name === name &&
10184
- (bindingType === undefined || ((_a = c.binding()) === null || _a === void 0 ? void 0 : _a.type) === bindingType);
10185
- }));
10431
+ if (this.memo.byName.callable.has(key)) {
10432
+ return this.memo.byName.callable.get(key);
10186
10433
  }
10187
- return this.memo.byName.callable.get(key);
10434
+ const callable = this.schemas
10435
+ .reduce((acc, schema) => [...acc, ...schema.callables], [])
10436
+ .find((c) => {
10437
+ var _a;
10438
+ return c.name === name &&
10439
+ (bindingType === undefined || ((_a = c.binding()) === null || _a === void 0 ? void 0 : _a.type) === bindingType);
10440
+ });
10441
+ this.memo.byName.callable.set(key, callable);
10442
+ return callable;
10188
10443
  }
10189
10444
  findEntitySetByName(name) {
10190
- if (!this.memo.byName.entitySet.has(name)) {
10191
- this.memo.byName.entitySet.set(name, this.schemas
10192
- .reduce((acc, schema) => [...acc, ...schema.entitySets], [])
10193
- .find((e) => e.name === name));
10445
+ if (this.memo.byName.entitySet.has(name)) {
10446
+ return this.memo.byName.entitySet.get(name);
10194
10447
  }
10195
- return this.memo.byName.entitySet.get(name);
10448
+ const schema = this.schemas
10449
+ .reduce((acc, schema) => [...acc, ...schema.entitySets], [])
10450
+ .find((e) => e.name === name);
10451
+ this.memo.byName.entitySet.set(name, schema);
10452
+ return schema;
10196
10453
  }
10197
10454
  findModelByName(name) {
10198
10455
  var _a;
@@ -10208,35 +10465,37 @@ class ODataApi {
10208
10465
  }
10209
10466
  parserForType(type, bindingType) {
10210
10467
  const key = bindingType !== undefined ? `${bindingType}/${type}` : type;
10211
- if (!this.memo.forType.parser.has(key)) {
10212
- if (type in this.parsers) {
10213
- // Edm, Base Parsers
10214
- this.memo.forType.parser.set(key, this.parsers[type]);
10215
- }
10216
- else if (!type.startsWith('Edm.')) {
10217
- // EnumType, ComplexType and EntityType Parsers
10218
- let value = this.findCallableForType(type, bindingType) ||
10219
- this.findEnumTypeForType(type) ||
10220
- this.findStructuredTypeForType(type);
10221
- this.memo.forType.parser.set(key, value === null || value === void 0 ? void 0 : value.parser);
10222
- }
10223
- else {
10224
- // None Parser
10225
- this.memo.forType.parser.set(key, NONE_PARSER);
10226
- }
10227
- }
10228
- return this.memo.forType.parser.get(key);
10468
+ if (this.memo.forType.parser.has(key)) {
10469
+ return this.memo.forType.parser.get(key);
10470
+ }
10471
+ // None Parser by default
10472
+ let parser = NONE_PARSER;
10473
+ if (this.parsers.has(type)) {
10474
+ // Edm, Base Parsers
10475
+ parser = this.parsers.get(type);
10476
+ }
10477
+ else if (!type.startsWith('Edm.')) {
10478
+ // EnumType, ComplexType and EntityType Parsers
10479
+ let value = this.findCallableForType(type, bindingType) ||
10480
+ this.findEnumTypeForType(type) ||
10481
+ this.findStructuredTypeForType(type);
10482
+ parser = value === null || value === void 0 ? void 0 : value.parser;
10483
+ }
10484
+ // Set Parser for next time
10485
+ this.memo.forType.parser.set(key, parser);
10486
+ return parser;
10229
10487
  }
10230
10488
  findOptionsForType(type) {
10231
10489
  var _a;
10232
10490
  // Strucutred Options
10233
- if (!this.memo.forType.options.has(type)) {
10234
- let st = this.findStructuredTypeForType(type);
10235
- this.memo.forType.options.set(type, st !== undefined && st.model !== undefined && ((_a = st.model) === null || _a === void 0 ? void 0 : _a.meta) !== null
10236
- ? st.model.meta
10237
- : undefined);
10491
+ if (this.memo.forType.options.has(type)) {
10492
+ return this.memo.forType.options.get(type);
10238
10493
  }
10239
- return this.memo.forType.options.get(type);
10494
+ const st = this.findStructuredTypeForType(type);
10495
+ const options = (_a = st === null || st === void 0 ? void 0 : st.model) === null || _a === void 0 ? void 0 : _a.meta;
10496
+ // Set Options for next time
10497
+ this.memo.forType.options.set(type, options);
10498
+ return options;
10240
10499
  }
10241
10500
  }
10242
10501
 
@@ -10698,9 +10957,9 @@ class ODataClient {
10698
10957
  return this.request('PUT', resource, addBody(options, body));
10699
10958
  }
10700
10959
  }
10701
- ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataSettings }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
10702
- ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataClient, providedIn: 'root' });
10703
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataClient, decorators: [{
10960
+ ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataSettings }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
10961
+ ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: ODataClient, providedIn: 'root' });
10962
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: ODataClient, decorators: [{
10704
10963
  type: Injectable,
10705
10964
  args: [{
10706
10965
  providedIn: 'root',
@@ -10952,9 +11211,9 @@ class ODataServiceFactory {
10952
11211
  })(this.client, singletonName, apiNameOrEntityType);
10953
11212
  }
10954
11213
  }
10955
- ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
10956
- ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataServiceFactory });
10957
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataServiceFactory, decorators: [{
11214
+ ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
11215
+ ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: ODataServiceFactory });
11216
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: ODataServiceFactory, decorators: [{
10958
11217
  type: Injectable
10959
11218
  }], ctorParameters: function () { return [{ type: ODataClient }]; } });
10960
11219
 
@@ -10978,10 +11237,10 @@ class ODataModule {
10978
11237
  };
10979
11238
  }
10980
11239
  }
10981
- ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
10982
- ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
10983
- ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [[HttpClientModule]] });
10984
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.6", ngImport: i0, type: ODataModule, decorators: [{
11240
+ ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
11241
+ ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.1.1", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
11242
+ ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [HttpClientModule] });
11243
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: ODataModule, decorators: [{
10985
11244
  type: NgModule,
10986
11245
  args: [{
10987
11246
  imports: [HttpClientModule],