angular-odata 0.105.0 → 0.115.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 (70) hide show
  1. package/esm2020/lib/api.mjs +44 -6
  2. package/esm2020/lib/client.mjs +9 -34
  3. package/esm2020/lib/constants.mjs +10 -5
  4. package/esm2020/lib/helper.mjs +17 -7
  5. package/esm2020/lib/models/collection.mjs +58 -44
  6. package/esm2020/lib/models/model.mjs +36 -9
  7. package/esm2020/lib/models/options.mjs +13 -15
  8. package/esm2020/lib/module.mjs +4 -4
  9. package/esm2020/lib/options.mjs +1 -1
  10. package/esm2020/lib/resources/query/expressions/count.mjs +89 -0
  11. package/esm2020/lib/resources/query/expressions/filter.mjs +5 -1
  12. package/esm2020/lib/resources/request.mjs +35 -2
  13. package/esm2020/lib/resources/resource.mjs +8 -51
  14. package/esm2020/lib/resources/responses/annotations.mjs +16 -4
  15. package/esm2020/lib/resources/responses/options.mjs +6 -1
  16. package/esm2020/lib/resources/responses/response.mjs +9 -5
  17. package/esm2020/lib/resources/responses/types.mjs +1 -1
  18. package/esm2020/lib/resources/types/batch.mjs +6 -9
  19. package/esm2020/lib/resources/types/count.mjs +1 -1
  20. package/esm2020/lib/resources/types/entity-set.mjs +34 -12
  21. package/esm2020/lib/resources/types/entity.mjs +1 -1
  22. package/esm2020/lib/resources/types/media.mjs +1 -1
  23. package/esm2020/lib/resources/types/metadata.mjs +3 -5
  24. package/esm2020/lib/resources/types/navigation-property.mjs +26 -6
  25. package/esm2020/lib/resources/types/options.mjs +1 -1
  26. package/esm2020/lib/resources/types/property.mjs +29 -4
  27. package/esm2020/lib/resources/types/reference.mjs +1 -1
  28. package/esm2020/lib/resources/types/singleton.mjs +1 -4
  29. package/esm2020/lib/resources/types/value.mjs +2 -2
  30. package/esm2020/lib/schema/parsers/callable.mjs +1 -1
  31. package/esm2020/lib/schema/parsers/edm.mjs +9 -9
  32. package/esm2020/lib/schema/parsers/enum-type.mjs +1 -1
  33. package/esm2020/lib/services/entity-set.mjs +9 -7
  34. package/esm2020/lib/services/factory.mjs +3 -3
  35. package/esm2020/lib/utils/http.mjs +1 -1
  36. package/esm2020/lib/utils/objects.mjs +1 -1
  37. package/fesm2015/angular-odata.mjs +435 -209
  38. package/fesm2015/angular-odata.mjs.map +1 -1
  39. package/fesm2020/angular-odata.mjs +444 -214
  40. package/fesm2020/angular-odata.mjs.map +1 -1
  41. package/lib/api.d.ts +10 -3
  42. package/lib/client.d.ts +139 -1425
  43. package/lib/constants.d.ts +5 -3
  44. package/lib/helper.d.ts +1 -1
  45. package/lib/models/collection.d.ts +26 -5
  46. package/lib/models/model.d.ts +21 -11
  47. package/lib/models/options.d.ts +4 -3
  48. package/lib/options.d.ts +4 -0
  49. package/lib/resources/query/expressions/count.d.ts +44 -0
  50. package/lib/resources/query/expressions/filter.d.ts +5 -0
  51. package/lib/resources/query/handlers.d.ts +3 -1
  52. package/lib/resources/request.d.ts +13 -2
  53. package/lib/resources/resource.d.ts +3 -10
  54. package/lib/resources/responses/annotations.d.ts +17 -12
  55. package/lib/resources/responses/options.d.ts +1 -0
  56. package/lib/resources/responses/types.d.ts +3 -3
  57. package/lib/resources/types/count.d.ts +1 -1
  58. package/lib/resources/types/entity-set.d.ts +24 -6
  59. package/lib/resources/types/entity.d.ts +8 -24
  60. package/lib/resources/types/media.d.ts +7 -15
  61. package/lib/resources/types/metadata.d.ts +1 -1
  62. package/lib/resources/types/navigation-property.d.ts +26 -28
  63. package/lib/resources/types/options.d.ts +4 -2
  64. package/lib/resources/types/property.d.ts +28 -15
  65. package/lib/resources/types/reference.d.ts +3 -12
  66. package/lib/resources/types/singleton.d.ts +8 -27
  67. package/lib/services/entity-set.d.ts +20 -6
  68. package/lib/utils/http.d.ts +1 -1
  69. package/lib/utils/objects.d.ts +19 -5
  70. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import * as i1 from '@angular/common/http';
2
2
  import { HttpHeaders, HttpParams, HttpResponse, HttpErrorResponse, HttpEventType, HttpClientModule } from '@angular/common/http';
3
3
  import { of, throwError, Subject, map as map$1, firstValueFrom, EMPTY, Observable, forkJoin, NEVER } from 'rxjs';
4
- import { tap, startWith, map, expand, concatMap, toArray, finalize, switchMap, catchError } from 'rxjs/operators';
4
+ import { tap, startWith, map, expand, reduce, finalize, switchMap, catchError } from 'rxjs/operators';
5
5
  import { __rest } from 'tslib';
6
6
  import * as i0 from '@angular/core';
7
7
  import { EventEmitter, Injectable, InjectionToken, NgModule } from '@angular/core';
@@ -58,18 +58,20 @@ const $INLINECOUNT = '$inlinecount';
58
58
  const IF_MATCH_HEADER = 'If-Match';
59
59
  const IF_NONE_MATCH_HEADER = 'If-None-Match';
60
60
  const CONTENT_TYPE = 'Content-Type';
61
- const CACHE_CONTROL = 'Cache-Control';
62
61
  const HTTP11 = 'HTTP/1.1';
63
62
  const ACCEPT = 'Accept';
64
63
  const PREFER = 'Prefer';
64
+ const CACHE_CONTROL = 'Cache-Control';
65
+ const CACHE_CONTROL_HEADERS = [
66
+ CACHE_CONTROL,
67
+ CACHE_CONTROL.toLowerCase(),
68
+ ];
65
69
  const ODATA_VERSION = 'OData-Version';
66
70
  const ODATA_VERSION_HEADERS = [
67
71
  ODATA_VERSION,
68
72
  ODATA_VERSION.toLowerCase(),
69
73
  'dataserviceversion',
70
74
  ];
71
- const ETAG_HEADER = 'ETag';
72
- const ETAG_HEADERS = [ETAG_HEADER, ETAG_HEADER.toLowerCase()];
73
75
  const LOCATION_HEADER = 'Location';
74
76
  const LOCATION_HEADERS = [
75
77
  LOCATION_HEADER,
@@ -85,6 +87,8 @@ const PREFERENCE_APPLIED_HEADERS = [
85
87
  PREFERENCE_APPLIED,
86
88
  PREFERENCE_APPLIED.toLowerCase(),
87
89
  ];
90
+ const ETAG_HEADER = 'ETag';
91
+ const ETAG_HEADERS = [ETAG_HEADER, ETAG_HEADER.toLowerCase()];
88
92
  const RETRY_AFTER = 'Retry-After';
89
93
  const RETRY_AFTER_HEADERS = [RETRY_AFTER, RETRY_AFTER.toLowerCase()];
90
94
  // HTTP HEADER VALUES
@@ -124,11 +128,12 @@ const CACHE_KEY_SEPARATOR = ':';
124
128
  // Models
125
129
  const CID_FIELD_NAME = '_cid';
126
130
  // Standard vocabularies for annotating OData services
127
- // http://docs.oasis-open.org/odata/odata-vocabularies/v4.0/csprd01/odata-vocabularies-v4.0-csprd01.html
131
+ // https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Core.V1.md
128
132
  const COMPUTED = /.*Computed$/;
129
133
  const OPTIMISTIC_CONCURRENCY = /.*OptimisticConcurrency$/;
130
134
  const DESCRIPTION = /.*Description$/;
131
135
  const LONG_DESCRIPTION = /.*LongDescription$/;
136
+ const OPTIONARL_PARAMETER = /.*OptionalParameter$/;
132
137
 
133
138
  class ODataCache {
134
139
  constructor({ timeout = DEFAULT_TIMEOUT }) {
@@ -1528,7 +1533,7 @@ class Expression {
1528
1533
  }
1529
1534
  }
1530
1535
 
1531
- class Field$1 {
1536
+ let Field$1 = class Field {
1532
1537
  constructor(name = '') {
1533
1538
  this.name = name;
1534
1539
  }
@@ -1560,7 +1565,7 @@ class Field$1 {
1560
1565
  has(target, key) {
1561
1566
  return ['toJSON', 'clone', 'render'].includes(key) || key in target;
1562
1567
  }
1563
- }
1568
+ };
1564
1569
  function applyMixins(derivedCtor, constructors) {
1565
1570
  constructors.forEach((baseCtor) => {
1566
1571
  Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
@@ -1972,6 +1977,90 @@ class ComputeExpression extends Expression {
1972
1977
  }
1973
1978
  }
1974
1979
 
1980
+ class CountField {
1981
+ constructor(field, values = {}) {
1982
+ this.field = field;
1983
+ this.values = values;
1984
+ }
1985
+ get [Symbol.toStringTag]() {
1986
+ return 'CountField';
1987
+ }
1988
+ toJSON() {
1989
+ return {
1990
+ field: this.field.toJSON(),
1991
+ };
1992
+ }
1993
+ render({ aliases, escape, prefix, }) {
1994
+ const params = [
1995
+ QueryOptionNames.filter,
1996
+ QueryOptionNames.search,
1997
+ ]
1998
+ .filter((key) => !Types.isEmpty(this.values[key]))
1999
+ .reduce((acc, key) => {
2000
+ let value = this.values[key];
2001
+ if (Types.rawType(value).endsWith('Expression')) {
2002
+ value = value.render({ aliases, prefix, escape });
2003
+ }
2004
+ return Object.assign(acc, { [key]: value });
2005
+ }, {});
2006
+ let count = `${render(this.field, { aliases, escape, prefix })}/$count`;
2007
+ if (!Types.isEmpty(params)) {
2008
+ count = `${count}(${Object.keys(params)
2009
+ .map((key) => `$${key}=${params[key]}`)
2010
+ .join(';')})`;
2011
+ }
2012
+ return count;
2013
+ }
2014
+ filter(opts) {
2015
+ return this.option(QueryOptionNames.filter, FilterExpression.filter(opts, this.values[QueryOptionNames.filter]));
2016
+ }
2017
+ clone() {
2018
+ const values = Object.keys(this.values).reduce((acc, key) => Object.assign(acc, { [key]: Objects.clone(this.values[key]) }), {});
2019
+ return new CountField(this.field.clone(), values);
2020
+ }
2021
+ // Option Handler
2022
+ option(name, opts) {
2023
+ if (opts !== undefined)
2024
+ this.values[name] = opts;
2025
+ return this.values[name];
2026
+ }
2027
+ }
2028
+ class CountExpression extends Expression {
2029
+ constructor({ children, } = {}) {
2030
+ super({ children });
2031
+ }
2032
+ static count(opts, current) {
2033
+ return opts({
2034
+ t: Field$1.factory(),
2035
+ e: () => new CountExpression(),
2036
+ }, current);
2037
+ }
2038
+ _add(node) {
2039
+ this._children.push(node);
2040
+ return this;
2041
+ }
2042
+ render({ aliases, escape, prefix, } = {}) {
2043
+ let content = this._children
2044
+ .map((n) => n.render({ aliases, escape, prefix }))
2045
+ .join(`,`);
2046
+ return content;
2047
+ }
2048
+ clone() {
2049
+ return new CountExpression({
2050
+ children: this._children.map((c) => c.clone()),
2051
+ });
2052
+ }
2053
+ field(field, opts) {
2054
+ let countField = new CountField(field);
2055
+ if (opts !== undefined)
2056
+ opts({
2057
+ t: Field$1.factory(),
2058
+ f: countField,
2059
+ });
2060
+ return this._add(countField);
2061
+ }
2062
+ }
2063
+
1975
2064
  class FilterExpression extends Expression {
1976
2065
  constructor({ children, connector, negated, } = {}) {
1977
2066
  super({ children });
@@ -2122,6 +2211,9 @@ class FilterExpression extends Expression {
2122
2211
  });
2123
2212
  return this._add(syntax.all(left, exp, alias));
2124
2213
  }
2214
+ count(left, opts) {
2215
+ return this._add(new CountExpression().field(left, opts));
2216
+ }
2125
2217
  isof(left, type) {
2126
2218
  return this._add(syntax.isof(left, type));
2127
2219
  }
@@ -3116,12 +3208,13 @@ class ODataPathSegments {
3116
3208
 
3117
3209
  class ODataRequest {
3118
3210
  constructor(init) {
3119
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
3211
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
3120
3212
  this._method = init.method;
3121
3213
  this.resource = init.resource;
3122
3214
  this.api = init.api;
3123
3215
  this.reportProgress = init.reportProgress;
3124
3216
  this.observe = init.observe;
3217
+ this.context = init.context;
3125
3218
  // Response Type
3126
3219
  this._responseType = init.responseType;
3127
3220
  // The Body
@@ -3182,7 +3275,12 @@ class ODataRequest {
3182
3275
  if (((_o = this.api.options.prefer) === null || _o === void 0 ? void 0 : _o.includeAnnotations) !== undefined &&
3183
3276
  ['GET'].indexOf(this._method) !== -1)
3184
3277
  prefer.push(`odata.include-annotations=${(_p = this.api.options.prefer) === null || _p === void 0 ? void 0 : _p.includeAnnotations}`);
3185
- if (((_q = this.api.options.prefer) === null || _q === void 0 ? void 0 : _q.continueOnError) === true &&
3278
+ // Omit Null Values
3279
+ if (((_q = this.api.options.prefer) === null || _q === void 0 ? void 0 : _q.omitNullValues) === true &&
3280
+ ['GET'].indexOf(this._method) !== -1)
3281
+ prefer.push(`omit-values=nulls`);
3282
+ // Continue on Error
3283
+ if (((_r = this.api.options.prefer) === null || _r === void 0 ? void 0 : _r.continueOnError) === true &&
3186
3284
  ['POST'].indexOf(this._method) !== -1)
3187
3285
  prefer.push(`odata.continue-on-error`);
3188
3286
  if (prefer.length > 0)
@@ -3214,6 +3312,33 @@ class ODataRequest {
3214
3312
  : params;
3215
3313
  //#endregion
3216
3314
  }
3315
+ static factory(api, method, resource, options) {
3316
+ const apiOptions = api.options;
3317
+ let params = options.params || {};
3318
+ if (options.withCount) {
3319
+ params = Http.mergeHttpParams(params, apiOptions.helper.countParam());
3320
+ }
3321
+ let etag = options.etag;
3322
+ if (etag === undefined && Types.isPlainObject(options.body)) {
3323
+ etag = apiOptions.helper.etag(options.body);
3324
+ }
3325
+ return new ODataRequest({
3326
+ method,
3327
+ etag,
3328
+ api,
3329
+ resource,
3330
+ params,
3331
+ context: options.context,
3332
+ body: options.body,
3333
+ observe: options.observe,
3334
+ headers: options.headers,
3335
+ reportProgress: options.reportProgress,
3336
+ responseType: options.responseType,
3337
+ fetchPolicy: options.fetchPolicy,
3338
+ withCredentials: options.withCredentials,
3339
+ bodyQueryOptions: options.bodyQueryOptions,
3340
+ });
3341
+ }
3217
3342
  get responseType() {
3218
3343
  return this._responseType &&
3219
3344
  ['property', 'entity', 'entities'].indexOf(this._responseType) !== -1
@@ -3512,6 +3637,10 @@ const ODataHelper = {
3512
3637
  }
3513
3638
  return annots;
3514
3639
  },
3640
+ context(annots) {
3641
+ let ctx = {};
3642
+ return ctx;
3643
+ },
3515
3644
  attributes(value, metadata) {
3516
3645
  return value;
3517
3646
  },
@@ -3704,13 +3833,13 @@ const EDM_PARSERS = {
3704
3833
  //Edm.Int64 Signed 16-bit integer
3705
3834
  'Edm.Int64': EdmParser(toNumber, toNumber, toNumber),
3706
3835
  //Edm.Date Date without a time-zone offset
3707
- 'Edm.Date': EdmParser((v) => new Date(`${v}T00:00:00.000Z`), (v) => toDate(v).toISOString().substring(0, 10), (v) => toDate(v).toISOString().substring(0, 10)),
3836
+ 'Edm.Date': EdmParser((v) => new Date(`${v}T00:00:00.000Z`), (v) => toDate(v).toISOString().substring(0, 10), (v) => raw(toDate(v).toISOString().substring(0, 10))),
3708
3837
  //Edm.TimeOfDay Clock time 00:00-23:59:59.999999999999
3709
- 'Edm.TimeOfDay': EdmParser((v) => new Date(`1970-01-01T${v}Z`), (v) => toDate(v).toISOString().substring(11, 23), (v) => toDate(v).toISOString().substring(11, 23)),
3838
+ 'Edm.TimeOfDay': EdmParser((v) => new Date(`1970-01-01T${v}Z`), (v) => toDate(v).toISOString().substring(11, 23), (v) => raw(toDate(v).toISOString().substring(11, 23))),
3710
3839
  //Edm.DateTimeOffset Date and time with a time-zone offset, no leap seconds
3711
- 'Edm.DateTimeOffset': EdmParser(toDate, (v) => toDate(v).toISOString(), (v) => toDate(v).toISOString()),
3840
+ 'Edm.DateTimeOffset': EdmParser(toDate, (v) => toDate(v).toISOString(), (v) => raw(toDate(v).toISOString())),
3712
3841
  //Edm.Duration Signed duration in days, hours, minutes, and (sub)seconds
3713
- 'Edm.Duration': EdmParser((v) => Durations.toDuration(v), (v) => Durations.toString(v), (v) => Durations.toString(v)),
3842
+ 'Edm.Duration': EdmParser((v) => Durations.toDuration(v), (v) => Durations.toString(v), (v) => raw(Durations.toString(v))),
3714
3843
  //Edm.Decimal Numeric values with fixed precision and scale
3715
3844
  'Edm.Decimal': EdmParser((v, o) => {
3716
3845
  if (typeof v === 'string' && o.ieee754Compatible) {
@@ -3732,16 +3861,16 @@ const EDM_PARSERS = {
3732
3861
  if (typeof o.field.scale === 'number') {
3733
3862
  vstr = parseFloat(vstr).toFixed(o.field.scale);
3734
3863
  }
3735
- return vstr;
3864
+ return raw(vstr);
3736
3865
  }
3737
3866
  return v;
3738
3867
  }),
3739
3868
  //Edm.Double IEEE 754 binary64 floating-point number (15-17 decimal digits)
3740
- 'Edm.Double': EdmParser((v) => (v === 'INF' ? Infinity : v), (v) => (v === Infinity ? 'INF' : v), (v) => (v === Infinity ? 'INF' : v)),
3869
+ 'Edm.Double': EdmParser((v) => (v === 'INF' ? Infinity : v), (v) => (v === Infinity ? 'INF' : v), (v) => raw(v === Infinity ? 'INF' : v.toString())),
3741
3870
  //Edm.Single IEEE 754 binary32 floating-point number (6-9 decimal digits)
3742
- 'Edm.Single': EdmParser((v) => (v === 'INF' ? Infinity : v), (v) => (v === Infinity ? 'INF' : v), (v) => (v === Infinity ? 'INF' : v)),
3871
+ 'Edm.Single': EdmParser((v) => (v === 'INF' ? Infinity : v), (v) => (v === Infinity ? 'INF' : v), (v) => raw(v === Infinity ? 'INF' : v.toString())),
3743
3872
  //Edm.Binary Binary data
3744
- 'Edm.Binary': EdmParser((v) => ArrayBuffers.toArrayBuffer(v), (v) => ArrayBuffers.toString(v), (v) => ArrayBuffers.toString(v)),
3873
+ 'Edm.Binary': EdmParser((v) => ArrayBuffers.toArrayBuffer(v), (v) => ArrayBuffers.toString(v), (v) => raw(ArrayBuffers.toString(v))),
3745
3874
  };
3746
3875
  /*
3747
3876
  Edm.Stream Binary data stream
@@ -4868,7 +4997,7 @@ class ODataResource {
4868
4997
  return (_a = this.pathSegments.last({ key: true })) === null || _a === void 0 ? void 0 : _a.clearKey();
4869
4998
  }
4870
4999
  //#region Models
4871
- asModel(entity, { annots, reset } = {}) {
5000
+ asModel(entity, { annots, reset, } = {}) {
4872
5001
  let resource = this;
4873
5002
  const type = (annots === null || annots === void 0 ? void 0 : annots.type) || this.returnType();
4874
5003
  if (type === undefined)
@@ -5057,61 +5186,20 @@ class ODataResource {
5057
5186
  return ODataResource.resolveKey(value, this.schema);
5058
5187
  }
5059
5188
  //#endregion
5060
- // Base Requests
5061
- request(method, options) {
5062
- const apiOptions = this.api.options;
5063
- let params = options.params || {};
5064
- if (options.withCount) {
5065
- params = Http.mergeHttpParams(params, apiOptions.helper.countParam());
5066
- }
5067
- let etag = options.etag;
5068
- if (etag === undefined && Types.isPlainObject(options.body)) {
5069
- etag = apiOptions.helper.etag(options.body);
5070
- }
5071
- const request = new ODataRequest({
5072
- method,
5073
- etag,
5074
- body: options.body,
5075
- api: this.api,
5076
- resource: this,
5077
- observe: 'response',
5078
- headers: options.headers,
5079
- reportProgress: options.reportProgress,
5080
- params: params,
5081
- responseType: options.responseType,
5082
- fetchPolicy: options.fetchPolicy,
5083
- withCredentials: options.withCredentials,
5084
- bodyQueryOptions: options.bodyQueryOptions,
5085
- });
5086
- const res$ = this.api.request(request);
5087
- switch (options.responseType) {
5088
- case 'entities':
5089
- return res$.pipe(map((res) => res.entities()));
5090
- case 'entity':
5091
- return res$.pipe(map((res) => res.entity()));
5092
- case 'property':
5093
- return res$.pipe(map((res) => res.property()));
5094
- case 'value':
5095
- return res$.pipe(map((res) => res.value()));
5096
- default:
5097
- // Other responseTypes (arraybuffer, blob, json, text) return body
5098
- return res$.pipe(map((res) => res.body));
5099
- }
5100
- }
5101
5189
  get(options = {}) {
5102
- return this.request('GET', options);
5190
+ return this.api.request('GET', this, options);
5103
5191
  }
5104
5192
  post(body, options = {}) {
5105
- return this.request('POST', Object.assign({ body }, options));
5193
+ return this.api.request('POST', this, Object.assign({ body }, options));
5106
5194
  }
5107
5195
  put(body, options = {}) {
5108
- return this.request('PUT', Object.assign({ body }, options));
5196
+ return this.api.request('PUT', this, Object.assign({ body }, options));
5109
5197
  }
5110
5198
  patch(body, options = {}) {
5111
- return this.request('PATCH', Object.assign({ body }, options));
5199
+ return this.api.request('PATCH', this, Object.assign({ body }, options));
5112
5200
  }
5113
5201
  delete(options = {}) {
5114
- return this.request('DELETE', options);
5202
+ return this.api.request('DELETE', this, options);
5115
5203
  }
5116
5204
  }
5117
5205
 
@@ -5335,18 +5423,16 @@ class ODataBatchResource extends ODataResource {
5335
5423
  [CONTENT_TYPE]: MULTIPART_MIXED_BOUNDARY + bound,
5336
5424
  [ACCEPT]: MULTIPART_MIXED,
5337
5425
  });
5338
- const request = new ODataRequest({
5339
- method: 'POST',
5426
+ return this.api
5427
+ .request('POST', this, {
5340
5428
  body: ODataBatchResource.buildBody(bound, this._requests),
5341
- api: this.api,
5342
- resource: this,
5343
- observe: 'response',
5344
5429
  responseType: 'text',
5430
+ observe: 'response',
5345
5431
  headers: headers,
5346
5432
  params: options ? options.params : undefined,
5347
5433
  withCredentials: options ? options.withCredentials : undefined,
5348
- });
5349
- return this.api.request(request).pipe(map$1((response) => {
5434
+ })
5435
+ .pipe(map$1((response) => {
5350
5436
  if (this._responses == null) {
5351
5437
  this._responses = [];
5352
5438
  }
@@ -5765,7 +5851,7 @@ class ODataValueResource extends ODataResource {
5765
5851
  }
5766
5852
  //#endregion
5767
5853
  //#region Requests
5768
- get(options) {
5854
+ get(options = {}) {
5769
5855
  return super.get(Object.assign({ responseType: 'value' }, options));
5770
5856
  }
5771
5857
  //#endregion
@@ -5940,6 +6026,29 @@ class ODataPropertyResource extends ODataResource {
5940
6026
  ? this.asCollection(entities, { annots, reset: true })
5941
6027
  : null));
5942
6028
  }
6029
+ fetchOne(options) {
6030
+ let res = this.clone();
6031
+ res.query((q) => q.top(1));
6032
+ return res
6033
+ .fetch(Object.assign({ responseType: 'entities' }, options))
6034
+ .pipe(map(({ entities, annots }) => ({
6035
+ entity: entities !== null ? entities[0] || null : null,
6036
+ annots,
6037
+ })));
6038
+ }
6039
+ fetchMany(top, options) {
6040
+ let res = this.clone();
6041
+ let fetch = (opts) => {
6042
+ if (opts) {
6043
+ res.query((q) => q.paging(opts));
6044
+ }
6045
+ return res.fetch(Object.assign({ responseType: 'entities' }, options));
6046
+ };
6047
+ return fetch({ top }).pipe(expand(({ annots }) => annots.skip || annots.skiptoken ? fetch(annots) : EMPTY), map(({ entities, annots }) => ({ entities: entities || [], annots })), reduce((acc, { entities, annots }) => ({
6048
+ entities: [...(acc.entities || []), ...(entities || [])],
6049
+ annots: acc.annots.union(annots),
6050
+ })));
6051
+ }
5943
6052
  /**
5944
6053
  * Fetch all entities
5945
6054
  * @param options Options for the request
@@ -5955,7 +6064,10 @@ class ODataPropertyResource extends ODataResource {
5955
6064
  }
5956
6065
  return res.fetch(Object.assign({ responseType: 'entities' }, options));
5957
6066
  };
5958
- return fetch().pipe(expand(({ annots: meta }) => meta.skip || meta.skiptoken ? fetch(meta) : EMPTY), concatMap(({ entities }) => entities || []), toArray());
6067
+ return fetch().pipe(expand(({ annots }) => annots.skip || annots.skiptoken ? fetch(annots) : EMPTY), map(({ entities, annots }) => ({ entities: entities || [], annots })), reduce((acc, { entities, annots }) => ({
6068
+ entities: [...(acc.entities || []), ...(entities || [])],
6069
+ annots: acc.annots.union(annots),
6070
+ })));
5959
6071
  }
5960
6072
  }
5961
6073
 
@@ -6184,7 +6296,6 @@ class ODataNavigationPropertyResource extends ODataResource {
6184
6296
  * Update an existing entity
6185
6297
  * @param attrs The entity attributes
6186
6298
  * @param options Options for the request
6187
- * @param etag The etag of the entity
6188
6299
  * @returns The updated entity with the annotations
6189
6300
  */
6190
6301
  update(attrs, options) {
@@ -6194,7 +6305,6 @@ class ODataNavigationPropertyResource extends ODataResource {
6194
6305
  * Modify an existing entity
6195
6306
  * @param attrs The entity attributes
6196
6307
  * @param options Options for the request
6197
- * @param etag The etag of the entity
6198
6308
  * @returns The modified entity with the annotations
6199
6309
  */
6200
6310
  modify(attrs, options) {
@@ -6203,7 +6313,6 @@ class ODataNavigationPropertyResource extends ODataResource {
6203
6313
  /**
6204
6314
  * Delete an existing entity
6205
6315
  * @param options Options for the request
6206
- * @param etag The etag of the entity
6207
6316
  * @returns An observable of the destroy
6208
6317
  */
6209
6318
  destroy(options) {
@@ -6263,7 +6372,30 @@ class ODataNavigationPropertyResource extends ODataResource {
6263
6372
  }
6264
6373
  return res.fetch(Object.assign({ responseType: 'entities' }, options));
6265
6374
  };
6266
- return fetch().pipe(expand(({ annots: meta }) => meta.skip || meta.skiptoken ? fetch(meta) : EMPTY), concatMap(({ entities }) => entities || []), toArray());
6375
+ return fetch().pipe(expand(({ annots }) => annots.skip || annots.skiptoken ? fetch(annots) : EMPTY), map(({ entities, annots }) => ({ entities: entities || [], annots })), reduce((acc, { entities, annots }) => ({
6376
+ entities: [...(acc.entities || []), ...(entities || [])],
6377
+ annots: acc.annots.union(annots),
6378
+ })));
6379
+ }
6380
+ //#endregion
6381
+ fetchMany(top, options) {
6382
+ let res = this.clone();
6383
+ let fetch = (opts) => {
6384
+ if (opts) {
6385
+ res.query((q) => q.paging(opts));
6386
+ }
6387
+ return res.fetch(Object.assign({ responseType: 'entities' }, options));
6388
+ };
6389
+ return fetch({ top }).pipe(expand(({ annots }) => annots.skip || annots.skiptoken ? fetch(annots) : EMPTY), map(({ entities, annots }) => ({ entities: entities || [], annots })), reduce((acc, { entities, annots }) => ({
6390
+ entities: [...(acc.entities || []), ...(entities || [])],
6391
+ annots: acc.annots.union(annots),
6392
+ })));
6393
+ }
6394
+ fetchOne(options) {
6395
+ return this.fetchMany(1, options).pipe(map(({ entities, annots }) => ({
6396
+ entity: entities.length === 1 ? entities[0] : null,
6397
+ annots,
6398
+ })));
6267
6399
  }
6268
6400
  }
6269
6401
 
@@ -6419,7 +6551,7 @@ class ODataEntitySetResource extends ODataResource {
6419
6551
  });
6420
6552
  }
6421
6553
  //#region Requests
6422
- post(attrs, options = {}) {
6554
+ post(attrs, options) {
6423
6555
  return super.post(attrs, Object.assign({ responseType: 'entity' }, options));
6424
6556
  }
6425
6557
  get(options = {}) {
@@ -6433,14 +6565,6 @@ class ODataEntitySetResource extends ODataResource {
6433
6565
  fetch(options) {
6434
6566
  return this.get(options);
6435
6567
  }
6436
- fetchEntities(options) {
6437
- return this.fetch(options).pipe(map(({ entities }) => entities));
6438
- }
6439
- fetchCollection(options) {
6440
- return this.fetch(options).pipe(map(({ entities, annots }) => entities
6441
- ? this.asCollection(entities, { annots, reset: true })
6442
- : null));
6443
- }
6444
6568
  fetchAll(options) {
6445
6569
  let res = this.clone();
6446
6570
  // Clean Paging
@@ -6451,7 +6575,37 @@ class ODataEntitySetResource extends ODataResource {
6451
6575
  }
6452
6576
  return res.fetch(options);
6453
6577
  };
6454
- return fetch().pipe(expand(({ annots: meta }) => meta.skip || meta.skiptoken ? fetch(meta) : EMPTY), concatMap(({ entities }) => entities || []), toArray());
6578
+ return fetch().pipe(expand(({ annots }) => annots.skip || annots.skiptoken ? fetch(annots) : EMPTY), map(({ entities, annots }) => ({ entities: entities || [], annots })), reduce((acc, { entities, annots }) => ({
6579
+ entities: [...(acc.entities || []), ...(entities || [])],
6580
+ annots: acc.annots.union(annots),
6581
+ })));
6582
+ }
6583
+ fetchMany(top, options) {
6584
+ let res = this.clone();
6585
+ let fetch = (opts) => {
6586
+ if (opts) {
6587
+ res.query((q) => q.paging(opts));
6588
+ }
6589
+ return res.fetch(options);
6590
+ };
6591
+ return fetch({ top }).pipe(expand(({ annots }) => annots.skip || annots.skiptoken ? fetch(annots) : EMPTY), map(({ entities, annots }) => ({ entities: entities || [], annots })), reduce((acc, { entities, annots }) => ({
6592
+ entities: [...(acc.entities || []), ...(entities || [])],
6593
+ annots: acc.annots.union(annots),
6594
+ })));
6595
+ }
6596
+ fetchOne(options) {
6597
+ return this.fetchMany(1, options).pipe(map(({ entities, annots }) => ({
6598
+ entity: entities.length === 1 ? entities[0] : null,
6599
+ annots,
6600
+ })));
6601
+ }
6602
+ fetchEntities(options) {
6603
+ return this.fetch(options).pipe(map(({ entities }) => entities));
6604
+ }
6605
+ fetchCollection(options) {
6606
+ return this.fetch(options).pipe(map(({ entities, annots }) => entities
6607
+ ? this.asCollection(entities, { annots, reset: true })
6608
+ : null));
6455
6609
  }
6456
6610
  }
6457
6611
 
@@ -6480,6 +6634,9 @@ class ODataAnnotations {
6480
6634
  }
6481
6635
  }
6482
6636
  class ODataPropertyAnnotations extends ODataAnnotations {
6637
+ union(other) {
6638
+ return new ODataPropertyAnnotations(this.helper, new Map([...this.annotations, ...other.annotations]), Object.assign({}, this.context, other.context));
6639
+ }
6483
6640
  clone() {
6484
6641
  return new ODataPropertyAnnotations(this.helper, new Map(this.annotations), this.context);
6485
6642
  }
@@ -6488,6 +6645,9 @@ class ODataPropertyAnnotations extends ODataAnnotations {
6488
6645
  }
6489
6646
  }
6490
6647
  class ODataEntityAnnotations extends ODataAnnotations {
6648
+ union(other) {
6649
+ return new ODataEntityAnnotations(this.helper, new Map([...this.annotations, ...other.annotations]), Object.assign({}, this.context, other.context));
6650
+ }
6491
6651
  clone() {
6492
6652
  return new ODataEntityAnnotations(this.helper, new Map(this.annotations), this.context);
6493
6653
  }
@@ -6527,8 +6687,11 @@ class ODataEntityAnnotations extends ODataAnnotations {
6527
6687
  }
6528
6688
  return this._properties;
6529
6689
  }
6530
- property(name) {
6531
- return this.properties.get(name);
6690
+ property(name, type) {
6691
+ const props = this.properties.get(name);
6692
+ return type === 'collection'
6693
+ ? new ODataEntitiesAnnotations(this.helper, props)
6694
+ : new ODataEntityAnnotations(this.helper, props);
6532
6695
  }
6533
6696
  get functions() {
6534
6697
  if (this._functions === undefined) {
@@ -6541,6 +6704,9 @@ class ODataEntityAnnotations extends ODataAnnotations {
6541
6704
  }
6542
6705
  }
6543
6706
  class ODataEntitiesAnnotations extends ODataAnnotations {
6707
+ union(other) {
6708
+ return new ODataEntitiesAnnotations(this.helper, new Map([...this.annotations, ...other.annotations]), Object.assign({}, this.context, other.context));
6709
+ }
6544
6710
  clone() {
6545
6711
  return new ODataEntitiesAnnotations(this.helper, new Map(this.annotations), this.context);
6546
6712
  }
@@ -6568,7 +6734,7 @@ class ODataEntitiesAnnotations extends ODataAnnotations {
6568
6734
  return match !== null ? Number(match[1]) : undefined;
6569
6735
  }
6570
6736
  get skiptoken() {
6571
- let match = (this.nextLink || '').match(/[&?]{1}\$skiptoken=([\d\w\s']+)/);
6737
+ let match = (this.nextLink || '').match(/[&?]{1}\$skiptoken=([\d\w\s'\-]+)/);
6572
6738
  return match !== null ? match[1] : undefined;
6573
6739
  }
6574
6740
  get functions() {
@@ -6617,6 +6783,11 @@ class ODataResponseOptions {
6617
6783
  // TODO: resolve location?
6618
6784
  this.location = location;
6619
6785
  }
6786
+ setPreferenceApplied(preference) {
6787
+ preference.split(',').forEach((prefer) => {
6788
+ // TODO: resolve preference
6789
+ });
6790
+ }
6620
6791
  setCache(cacheControl) {
6621
6792
  cacheControl.split(',').forEach((directive) => {
6622
6793
  if (directive.startsWith(MAX_AGE)) {
@@ -6684,11 +6855,15 @@ class ODataResponse extends HttpResponse {
6684
6855
  .find((p) => p.startsWith(APPLICATION_JSON));
6685
6856
  this._options.setFeatures(features);
6686
6857
  }
6687
- const header = Http.resolveHeaderKey(this.headers, ODATA_VERSION_HEADERS);
6688
- if (header) {
6689
- const version = (this.headers.get(header) || '').replace(/\;/g, '');
6858
+ const headerKey = Http.resolveHeaderKey(this.headers, ODATA_VERSION_HEADERS);
6859
+ if (headerKey) {
6860
+ const version = (this.headers.get(headerKey) || '').replace(/\;/g, '');
6690
6861
  this._options.setVersion(version);
6691
6862
  }
6863
+ const preferenceApplied = this.headers.get(PREFERENCE_APPLIED);
6864
+ if (preferenceApplied) {
6865
+ this._options.setPreferenceApplied(preferenceApplied);
6866
+ }
6692
6867
  const location = this.headers.get(LOCATION_HEADER);
6693
6868
  if (location) {
6694
6869
  this._options.setLocation(location);
@@ -7610,14 +7785,12 @@ class ODataMetadataResource extends ODataResource {
7610
7785
  //#endregion
7611
7786
  //#region Requests
7612
7787
  get(options) {
7613
- return super
7614
- .get(Object.assign({ responseType: 'text' }, options))
7615
- .pipe(map((body) => new ODataMetadata(body)));
7788
+ return super.get(Object.assign({ responseType: 'text' }, options));
7616
7789
  }
7617
7790
  //#endregion
7618
7791
  //#region Shortcuts
7619
7792
  fetch(options) {
7620
- return this.get(options);
7793
+ return this.get(options).pipe(map((body) => new ODataMetadata(body)));
7621
7794
  }
7622
7795
  }
7623
7796
 
@@ -7716,7 +7889,6 @@ class ODataSingletonResource extends ODataResource {
7716
7889
  /**
7717
7890
  * Fetch an existing entity.
7718
7891
  * @param options The options for the request.
7719
- * @param etag The etag to use for the request.
7720
7892
  * @returns Observable of the entity with the annotations.
7721
7893
  */
7722
7894
  fetch(options) {
@@ -7725,7 +7897,6 @@ class ODataSingletonResource extends ODataResource {
7725
7897
  /**
7726
7898
  * Fetch an existing entity.
7727
7899
  * @param options The options for the request.
7728
- * @param etag The etag to use for the request.
7729
7900
  * @returns Observable of the entity.
7730
7901
  */
7731
7902
  fetchEntity(options) {
@@ -7734,7 +7905,6 @@ class ODataSingletonResource extends ODataResource {
7734
7905
  /**
7735
7906
  * Fetch an existing entity and return a model.
7736
7907
  * @param options The options for the request.
7737
- * @param etag The etag to use for the request.
7738
7908
  * @returns Observable of the entity.
7739
7909
  */
7740
7910
  fetchModel(options) {
@@ -8044,8 +8214,8 @@ class ODataModelField {
8044
8214
  }
8045
8215
  annotationsFactory(base) {
8046
8216
  return this.parser.collection
8047
- ? new ODataEntitiesAnnotations(base.helper, base.property(this.parser.name))
8048
- : new ODataEntityAnnotations(base.helper, base.property(this.parser.name));
8217
+ ? base.property(this.parser.name, 'collection')
8218
+ : base.property(this.parser.name, 'single');
8049
8219
  }
8050
8220
  schemaFactory(base) {
8051
8221
  return this.api.findStructuredTypeForType(this.parser.type);
@@ -8406,6 +8576,9 @@ class ODataModelOptions {
8406
8576
  (state === ODataModelState.Changed ||
8407
8577
  (model != undefined && model.hasChanged({ include_navigation })))));
8408
8578
  }
8579
+ hasKey(self) {
8580
+ return this.resolveKey(self) !== undefined;
8581
+ }
8409
8582
  asEntity(self, func) {
8410
8583
  var _a;
8411
8584
  // Build new resource
@@ -8413,24 +8586,19 @@ class ODataModelOptions {
8413
8586
  let resource = this.modelResourceFactory(query);
8414
8587
  if (resource === undefined)
8415
8588
  throw new Error('Model does not have associated Entity endpoint');
8416
- // Store parent and resource
8417
- const store = { parent: self._parent, resource: self._resource };
8418
- // Replace parent and resource
8419
- self._parent = null;
8420
- self._resource = resource;
8589
+ // Push
8590
+ self.pushResource(resource);
8421
8591
  // Execute function
8422
8592
  const result = func(self);
8423
8593
  if (result instanceof Observable) {
8424
8594
  return result.pipe(finalize(() => {
8425
- // Restore parent and resource
8426
- self._parent = store.parent;
8427
- self._resource = store.resource;
8595
+ // Pop
8596
+ self.popResource();
8428
8597
  }));
8429
8598
  }
8430
8599
  else {
8431
- // Restore parent and resource
8432
- self._parent = store.parent;
8433
- self._resource = store.resource;
8600
+ // Pop
8601
+ self.popResource();
8434
8602
  return result;
8435
8603
  }
8436
8604
  }
@@ -8868,6 +9036,7 @@ class ODataCollection {
8868
9036
  var _a;
8869
9037
  this._parent = null;
8870
9038
  this._resource = null;
9039
+ this._resources = [];
8871
9040
  this._entries = [];
8872
9041
  //Events
8873
9042
  this.events$ = new EventEmitter();
@@ -8903,12 +9072,6 @@ class ODataCollection {
8903
9072
  get length() {
8904
9073
  return this.models().length;
8905
9074
  }
8906
- isEmpty() {
8907
- // Local length and if exists remote length
8908
- return (this.length === 0 &&
8909
- this.annots().count !== undefined &&
8910
- this.annots().count === 0);
8911
- }
8912
9075
  isParentOf(child) {
8913
9076
  return (child !== this &&
8914
9077
  ODataModelOptions.chain(child).some((p) => p[0] === this));
@@ -8916,6 +9079,24 @@ class ODataCollection {
8916
9079
  resource() {
8917
9080
  return ODataModelOptions.resource(this);
8918
9081
  }
9082
+ pushResource(resource) {
9083
+ // Push current parent and resource
9084
+ this._resources.push({ parent: this._parent, resource: this._resource });
9085
+ // Replace parent and resource
9086
+ this._parent = null;
9087
+ this._resource = resource;
9088
+ }
9089
+ popResource() {
9090
+ // Pop parent and resource
9091
+ const pop = this._resources.pop();
9092
+ if (pop !== undefined) {
9093
+ const current = { parent: this._parent, resource: this._resource };
9094
+ this._parent = pop.parent;
9095
+ this._resource = pop.resource;
9096
+ return current;
9097
+ }
9098
+ return undefined;
9099
+ }
8919
9100
  attach(resource) {
8920
9101
  if (this._resource !== null &&
8921
9102
  this._resource.type() !== resource.type() &&
@@ -8942,24 +9123,16 @@ class ODataCollection {
8942
9123
  let resource = this._model.meta.collectionResourceFactory(query);
8943
9124
  if (resource === undefined)
8944
9125
  throw new Error('asEntitySet: Collection does not have associated EntitySet endpoint');
8945
- // Store parent and resource
8946
- const store = { parent: this._parent, resource: this._resource };
8947
- // Replace parent and resource
8948
- this._parent = null;
8949
- this._resource = resource;
9126
+ // Push
9127
+ this.pushResource(resource);
8950
9128
  // Execute
8951
9129
  const result = func(this);
8952
9130
  if (result instanceof Observable) {
8953
- return result.pipe(finalize(() => {
8954
- // Restore
8955
- this._parent = store.parent;
8956
- this._resource = store.resource;
8957
- }));
9131
+ return result.pipe(finalize(() => this.popResource()));
8958
9132
  }
8959
9133
  else {
8960
- // Restore
8961
- this._parent = store.parent;
8962
- this._resource = store.resource;
9134
+ // Pop
9135
+ this.popResource();
8963
9136
  return result;
8964
9137
  }
8965
9138
  }
@@ -9015,40 +9188,45 @@ class ODataCollection {
9015
9188
  annots: this.annots(),
9016
9189
  });
9017
9190
  }
9018
- fetch(_a = {}) {
9019
- var { withCount } = _a, options = __rest(_a, ["withCount"]);
9020
- const resource = this.resource();
9021
- const obs$ = resource instanceof ODataEntitySetResource
9022
- ? resource.fetch(Object.assign({ withCount }, options))
9023
- : resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
9024
- this.events$.emit(new ODataModelEvent('request', { collection: this, value: obs$ }));
9025
- return obs$.pipe(map(({ entities, annots }) => {
9026
- this._annotations = annots;
9027
- this.assign(entities || [], { reset: true });
9028
- this.events$.emit(new ODataModelEvent('sync', { collection: this }));
9029
- return this;
9030
- }));
9031
- }
9032
- fetchAll(options) {
9033
- const resource = this.resource();
9034
- if (resource instanceof ODataPropertyResource)
9035
- return throwError(() => new Error('fetchAll: Resource is ODataPropertyResource'));
9036
- const obs$ = resource.fetchAll(options);
9191
+ _request(obs$) {
9037
9192
  this.events$.emit(new ODataModelEvent('request', {
9038
9193
  collection: this,
9039
9194
  options: { observable: obs$ },
9040
9195
  }));
9041
- return obs$.pipe(map((entities) => {
9042
- var _a;
9043
- 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]);
9196
+ return obs$.pipe(map(({ entities, annots }) => {
9197
+ this._annotations = annots;
9044
9198
  this.assign(entities || [], { reset: true });
9045
9199
  this.events$.emit(new ODataModelEvent('sync', {
9046
9200
  collection: this,
9047
- options: { entities },
9201
+ options: { entities, annots },
9048
9202
  }));
9049
9203
  return this;
9050
9204
  }));
9051
9205
  }
9206
+ fetch(_a = {}) {
9207
+ var { withCount } = _a, options = __rest(_a, ["withCount"]);
9208
+ const resource = this.resource();
9209
+ const obs$ = resource instanceof ODataEntitySetResource
9210
+ ? resource.fetch(Object.assign({ withCount }, options))
9211
+ : resource.fetch(Object.assign({ responseType: 'entities', withCount }, options));
9212
+ return this._request(obs$);
9213
+ }
9214
+ fetchAll(_a = {}) {
9215
+ var { withCount } = _a, options = __rest(_a, ["withCount"]);
9216
+ const resource = this.resource();
9217
+ const obs$ = resource.fetchAll(Object.assign({ withCount }, options));
9218
+ return this._request(obs$);
9219
+ }
9220
+ fetchMany(top, _a = {}) {
9221
+ var { withCount } = _a, options = __rest(_a, ["withCount"]);
9222
+ const resource = this.resource();
9223
+ const obs$ = resource.fetchMany(top, Object.assign({ withCount }, options));
9224
+ return this._request(obs$);
9225
+ }
9226
+ fetchOne(_a = {}) {
9227
+ var { withCount } = _a, options = __rest(_a, ["withCount"]);
9228
+ return this.fetchMany(1, Object.assign({ withCount }, options)).pipe(map((col) => col.first() || null));
9229
+ }
9052
9230
  /**
9053
9231
  * Save all models in the collection
9054
9232
  * @param relModel The model is relationship
@@ -9613,6 +9791,12 @@ class ODataCollection {
9613
9791
  const m = models.find((m) => m.equals(model));
9614
9792
  return m === undefined ? -1 : models.indexOf(m);
9615
9793
  }
9794
+ isEmpty() {
9795
+ // Local length and if exists remote length
9796
+ return (this.length === 0 &&
9797
+ this.annots().count !== undefined &&
9798
+ this.annots().count === 0);
9799
+ }
9616
9800
  //#region Sort
9617
9801
  _bisect(model) {
9618
9802
  let index = -1;
@@ -9674,10 +9858,12 @@ class ODataModel {
9674
9858
  constructor(data = {}, { parent, resource, annots, reset = false, } = {}) {
9675
9859
  // Parent
9676
9860
  this._parent = null;
9861
+ this._resource = null;
9862
+ this._resources = [];
9677
9863
  this._attributes = new Map();
9678
9864
  this._changes = new Map();
9679
9865
  this._relations = new Map();
9680
- this._resource = null;
9866
+ this._annotations = null;
9681
9867
  this._reset = false;
9682
9868
  this._reparent = false;
9683
9869
  this._silent = false;
@@ -9694,7 +9880,9 @@ class ODataModel {
9694
9880
  Strings.uniqueId(`${Klass.meta.schema.name.toLowerCase()}-`);
9695
9881
  let attrs = this.annots().attributes(data, 'full');
9696
9882
  let defaults = this.defaults();
9697
- this.assign(Objects.merge(defaults, attrs), { reset });
9883
+ this.assign(Objects.merge(defaults, attrs), {
9884
+ reset,
9885
+ });
9698
9886
  }
9699
9887
  static buildMeta({ options, schema, }) {
9700
9888
  if (options === undefined) {
@@ -9722,6 +9910,24 @@ class ODataModel {
9722
9910
  resource() {
9723
9911
  return ODataModelOptions.resource(this);
9724
9912
  }
9913
+ pushResource(resource) {
9914
+ // Push current parent and resource
9915
+ this._resources.push({ parent: this._parent, resource: this._resource });
9916
+ // Replace parent and resource
9917
+ this._parent = null;
9918
+ this._resource = resource;
9919
+ }
9920
+ popResource() {
9921
+ // Pop parent and resource
9922
+ const pop = this._resources.pop();
9923
+ if (pop !== undefined) {
9924
+ const current = { parent: this._parent, resource: this._resource };
9925
+ this._parent = pop.parent;
9926
+ this._resource = pop.resource;
9927
+ return current;
9928
+ }
9929
+ return undefined;
9930
+ }
9725
9931
  navigationProperty(name) {
9726
9932
  const field = this._meta.field(name);
9727
9933
  if (field === undefined || !field.navigation)
@@ -9748,14 +9954,12 @@ class ODataModel {
9748
9954
  return this._meta.schema;
9749
9955
  }
9750
9956
  annots() {
9751
- return this._annotations;
9957
+ var _a;
9958
+ return ((_a = this._annotations) !== null && _a !== void 0 ? _a : new ODataEntityAnnotations(ODataHelper[DEFAULT_VERSION]));
9752
9959
  }
9753
9960
  key({ field_mapping = false, resolve = true, } = {}) {
9754
9961
  return this._meta.resolveKey(this, { field_mapping, resolve });
9755
9962
  }
9756
- isNew() {
9757
- return this.key() === undefined;
9758
- }
9759
9963
  isParentOf(child) {
9760
9964
  return (child !== this &&
9761
9965
  ODataModelOptions.chain(child).some((p) => p[0] === this));
@@ -9971,6 +10175,9 @@ class ODataModel {
9971
10175
  hasChanged({ include_navigation = false, } = {}) {
9972
10176
  return this._meta.hasChanged(this, { include_navigation });
9973
10177
  }
10178
+ isNew() {
10179
+ return !this._meta.hasKey(this);
10180
+ }
9974
10181
  /**
9975
10182
  * Create an execution context for a given function, where the model is bound to its entity endpoint
9976
10183
  * @param ctx Context function
@@ -10020,7 +10227,9 @@ class ODataModel {
10020
10227
  throw new Error(`cast: Can't cast to derived model without ODataEntityResource`);
10021
10228
  return resource
10022
10229
  .cast(type)
10023
- .asModel(this.toEntity(INCLUDE_DEEP), { annots: this.annots() });
10230
+ .asModel(this.toEntity(INCLUDE_DEEP), {
10231
+ annots: this.annots(),
10232
+ });
10024
10233
  }
10025
10234
  fetchNavigationProperty(name, responseType, _a = {}) {
10026
10235
  var options = __rest(_a, []);
@@ -10286,16 +10495,54 @@ class ODataApi {
10286
10495
  const schema = this.findCallableForType(path);
10287
10496
  return ODataFunctionResource.factory(this, { path, schema });
10288
10497
  }
10289
- request(req) {
10498
+ //request(req: ODataRequest<any>): Observable<any> {
10499
+ request(method, resource, options) {
10500
+ let req = ODataRequest.factory(this, method, resource, {
10501
+ body: options.body,
10502
+ etag: options.etag,
10503
+ context: options.context,
10504
+ headers: options.headers,
10505
+ params: options.params,
10506
+ responseType: options.responseType,
10507
+ observe: (options.observe === 'events' ? 'events' : 'response'),
10508
+ withCount: options.withCount,
10509
+ bodyQueryOptions: options.bodyQueryOptions,
10510
+ reportProgress: options.reportProgress,
10511
+ fetchPolicy: options.fetchPolicy,
10512
+ withCredentials: options.withCredentials,
10513
+ });
10290
10514
  let res$ = this.requester !== undefined ? this.requester(req) : NEVER;
10291
10515
  res$ = res$.pipe(map((res) => res.type === HttpEventType.Response
10292
10516
  ? ODataResponse.fromHttpResponse(req, res)
10293
10517
  : res));
10294
10518
  if (this.errorHandler !== undefined)
10295
10519
  res$ = res$.pipe(catchError(this.errorHandler));
10296
- return req.observe === 'response'
10297
- ? this.cache.handleRequest(req, res$)
10298
- : res$;
10520
+ if (options.observe === 'events') {
10521
+ return res$;
10522
+ }
10523
+ res$ = this.cache.handleRequest(req, res$);
10524
+ switch (options.observe || 'body') {
10525
+ case 'body':
10526
+ switch (options.responseType) {
10527
+ case 'entities':
10528
+ return res$.pipe(map((res) => res.entities()));
10529
+ case 'entity':
10530
+ return res$.pipe(map((res) => res.entity()));
10531
+ case 'property':
10532
+ return res$.pipe(map((res) => res.property()));
10533
+ case 'value':
10534
+ return res$.pipe(map((res) => res.value()));
10535
+ default:
10536
+ // Other responseTypes (arraybuffer, blob, json, text) return body
10537
+ return res$.pipe(map((res) => res.body));
10538
+ }
10539
+ case 'response':
10540
+ // The response stream was requested directly, so return it.
10541
+ return res$;
10542
+ default:
10543
+ // Guard against new future observe types being added.
10544
+ throw new Error(`Unreachable: unhandled observe type ${options.observe}}`);
10545
+ }
10299
10546
  }
10300
10547
  findSchemaForType(type) {
10301
10548
  const schemas = this.schemas.filter((s) => s.isNamespaceOf(type));
@@ -10706,7 +10953,6 @@ function addBody(options, body) {
10706
10953
  return {
10707
10954
  body,
10708
10955
  etag: options.etag,
10709
- apiName: options.apiName,
10710
10956
  fetchPolicy: options.fetchPolicy,
10711
10957
  headers: options.headers,
10712
10958
  observe: options.observe,
@@ -10724,6 +10970,7 @@ class ODataClient {
10724
10970
  this.settings.configure({
10725
10971
  requester: (req) => this.http.request(req.method, `${req.url}`, {
10726
10972
  body: req.body,
10973
+ context: req.context,
10727
10974
  headers: req.headers,
10728
10975
  observe: req.observe,
10729
10976
  params: req.params,
@@ -10900,32 +11147,8 @@ class ODataClient {
10900
11147
  return this.apiFor(apiNameOrType).function(path);
10901
11148
  }
10902
11149
  request(method, resource, options) {
10903
- let api = options.apiName
10904
- ? this.settings.apiByName(options.apiName)
10905
- : resource.api;
10906
- if (!api)
10907
- throw new Error(`The types: '[${resource
10908
- .types()
10909
- .join(', ')}]' does not belongs to any known configuration`);
10910
- const request = new ODataRequest({
10911
- method,
10912
- api,
10913
- resource,
10914
- body: options.body,
10915
- observe: options.observe === 'events' ? 'events' : 'response',
10916
- etag: options.etag,
10917
- headers: options.headers,
10918
- reportProgress: options.reportProgress,
10919
- params: options.params,
10920
- responseType: options.responseType,
10921
- fetchPolicy: options.fetchPolicy,
10922
- withCredentials: options.withCredentials,
10923
- });
10924
- return api
10925
- .request(request)
10926
- .pipe(map((res) => options.observe === undefined || options.observe === 'body'
10927
- ? res.body
10928
- : res));
11150
+ let api = this.apiFor(resource);
11151
+ return api.request(method, resource, options);
10929
11152
  }
10930
11153
  delete(resource, options = {}) {
10931
11154
  return this.request('DELETE', resource, addBody(options, null));
@@ -10957,9 +11180,9 @@ class ODataClient {
10957
11180
  return this.request('PUT', resource, addBody(options, body));
10958
11181
  }
10959
11182
  }
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: [{
11183
+ ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataSettings }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
11184
+ ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ODataClient, providedIn: 'root' });
11185
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ODataClient, decorators: [{
10963
11186
  type: Injectable,
10964
11187
  args: [{
10965
11188
  providedIn: 'root',
@@ -11042,8 +11265,8 @@ class ODataEntitySetService extends ODataEntityService {
11042
11265
  * @param withCount Get the count of the entities.
11043
11266
  * @param options The options for the request.
11044
11267
  */
11045
- fetchMany(options) {
11046
- return this.entities().fetch(options);
11268
+ fetchMany(top, options) {
11269
+ return this.entities().fetchMany(top, options);
11047
11270
  }
11048
11271
  /**
11049
11272
  * Get an entity from the entity set.
@@ -11051,8 +11274,8 @@ class ODataEntitySetService extends ODataEntityService {
11051
11274
  * @param etag The etag for the entity.
11052
11275
  * @param options The options for the request.
11053
11276
  */
11054
- fetchOne(key, options) {
11055
- return this.entity(key).fetch(options);
11277
+ fetchOne(options) {
11278
+ return this.entities().fetchOne(options);
11056
11279
  }
11057
11280
  /**
11058
11281
  * Create an entity in the entity set.
@@ -11110,11 +11333,13 @@ class ODataEntitySetService extends ODataEntityService {
11110
11333
  */
11111
11334
  fetchOrCreate(key, attrs, _a = {}) {
11112
11335
  var { etag } = _a, options = __rest(_a, ["etag"]);
11113
- return this.fetchOne(key, Object.assign({ etag }, options)).pipe(catchError((error) => {
11336
+ return this.entity(key)
11337
+ .fetch(Object.assign({ etag }, options))
11338
+ .pipe(catchError((error) => {
11114
11339
  if (error.status === 404)
11115
11340
  return this.create(attrs, options);
11116
11341
  else
11117
- return throwError(error);
11342
+ return throwError(() => error);
11118
11343
  }));
11119
11344
  }
11120
11345
  /**
@@ -11211,9 +11436,9 @@ class ODataServiceFactory {
11211
11436
  })(this.client, singletonName, apiNameOrEntityType);
11212
11437
  }
11213
11438
  }
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: [{
11439
+ ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
11440
+ ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ODataServiceFactory });
11441
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ODataServiceFactory, decorators: [{
11217
11442
  type: Injectable
11218
11443
  }], ctorParameters: function () { return [{ type: ODataClient }]; } });
11219
11444
 
@@ -11237,10 +11462,10 @@ class ODataModule {
11237
11462
  };
11238
11463
  }
11239
11464
  }
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: [{
11465
+ ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
11466
+ ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.1", ngImport: i0, type: ODataModule, imports: [HttpClientModule] });
11467
+ ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [HttpClientModule] });
11468
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ODataModule, decorators: [{
11244
11469
  type: NgModule,
11245
11470
  args: [{
11246
11471
  imports: [HttpClientModule],
@@ -11258,3 +11483,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImpor
11258
11483
 
11259
11484
  export { BUBBLING, Dates, Durations, EDM_PARSERS, Enums, Http, INCLUDE_DEEP, INCLUDE_SHALLOW, ITEM_ROOT, Model, ModelField, NONE_PARSER, ODATA_CONFIGURATIONS, OData, ODataActionResource, ODataAnnotations, ODataApi, ODataBaseService, ODataBatchRequest, ODataBatchResource, ODataCache, ODataCallable, ODataCallableParser, ODataClient, ODataCollection, ODataCountResource, ODataEntitiesAnnotations, ODataEntityAnnotations, ODataEntityContainer, ODataEntityResource, ODataEntitySet, ODataEntitySetResource, ODataEntitySetService, ODataEntityTypeKey, ODataEnumType, ODataEnumTypeFieldParser, ODataEnumTypeParser, ODataFunctionResource, ODataInMemoryCache, ODataInStorageCache, ODataMediaResource, ODataMetadata, ODataMetadataResource, ODataModel, ODataModelEvent, ODataModelField, ODataModelOptions, ODataModelState, ODataModule, ODataNavigationPropertyResource, ODataParameterParser, ODataPathSegments, ODataPathSegmentsHandler, ODataPropertyAnnotations, ODataPropertyResource, ODataQueryOptionHandler, ODataQueryOptions, ODataQueryOptionsHandler, ODataReferenceResource, ODataReferential, ODataRequest, ODataResource, ODataResponse, ODataSchema, ODataServiceFactory, ODataSettings, ODataSingletonResource, ODataSingletonService, ODataStructuredType, ODataStructuredTypeFieldParser, ODataStructuredTypeParser, ODataValueResource, Objects, PathSegmentNames, QueryCustomTypes, QueryOptionNames, RESERVED_FIELD_NAMES, SegmentHandler, StandardAggregateMethods, Strings, Types, Urls, alias, binary, buildPathAndQuery, createSettings, duration, isQueryCustomType, normalizeValue, raw };
11260
11485
  //# sourceMappingURL=angular-odata.mjs.map
11486
+ //# sourceMappingURL=angular-odata.mjs.map