angular-odata 0.102.6 → 0.105.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 (50) hide show
  1. package/esm2020/lib/api.mjs +4 -2
  2. package/esm2020/lib/helper.mjs +7 -10
  3. package/esm2020/lib/models/collection.mjs +9 -3
  4. package/esm2020/lib/models/model.mjs +9 -6
  5. package/esm2020/lib/models/options.mjs +43 -22
  6. package/esm2020/lib/options.mjs +8 -2
  7. package/esm2020/lib/resources/query/expressions/compute.mjs +3 -9
  8. package/esm2020/lib/resources/query/expressions/expand.mjs +3 -9
  9. package/esm2020/lib/resources/query/expressions/filter.mjs +11 -14
  10. package/esm2020/lib/resources/query/expressions/orderby.mjs +3 -9
  11. package/esm2020/lib/resources/query/expressions/search.mjs +2 -5
  12. package/esm2020/lib/resources/query/expressions/select.mjs +3 -9
  13. package/esm2020/lib/resources/query/expressions/syntax.mjs +12 -7
  14. package/esm2020/lib/resources/query/options.mjs +9 -3
  15. package/esm2020/lib/resources/resource.mjs +7 -10
  16. package/esm2020/lib/resources/responses/annotations.mjs +7 -1
  17. package/esm2020/lib/schema/callable.mjs +4 -4
  18. package/esm2020/lib/schema/enum-type.mjs +9 -6
  19. package/esm2020/lib/schema/parsers/callable.mjs +9 -11
  20. package/esm2020/lib/schema/parsers/edm.mjs +11 -3
  21. package/esm2020/lib/schema/parsers/enum-type.mjs +21 -23
  22. package/esm2020/lib/schema/parsers/structured-type.mjs +10 -10
  23. package/esm2020/lib/schema/schema.mjs +5 -5
  24. package/esm2020/lib/schema/structured-type.mjs +6 -4
  25. package/esm2020/lib/types.mjs +1 -1
  26. package/esm2020/lib/utils/enums.mjs +1 -1
  27. package/fesm2015/angular-odata.mjs +200 -200
  28. package/fesm2015/angular-odata.mjs.map +1 -1
  29. package/fesm2020/angular-odata.mjs +190 -162
  30. package/fesm2020/angular-odata.mjs.map +1 -1
  31. package/lib/helper.d.ts +3 -0
  32. package/lib/models/collection.d.ts +3 -2
  33. package/lib/models/options.d.ts +12 -6
  34. package/lib/options.d.ts +8 -2
  35. package/lib/resources/query/expressions/compute.d.ts +1 -3
  36. package/lib/resources/query/expressions/expand.d.ts +1 -3
  37. package/lib/resources/query/expressions/filter.d.ts +2 -4
  38. package/lib/resources/query/expressions/orderby.d.ts +1 -3
  39. package/lib/resources/query/expressions/search.d.ts +0 -1
  40. package/lib/resources/query/expressions/select.d.ts +1 -3
  41. package/lib/resources/responses/annotations.d.ts +3 -0
  42. package/lib/schema/callable.d.ts +3 -1
  43. package/lib/schema/enum-type.d.ts +8 -2
  44. package/lib/schema/parsers/callable.d.ts +6 -6
  45. package/lib/schema/parsers/enum-type.d.ts +5 -10
  46. package/lib/schema/parsers/structured-type.d.ts +7 -5
  47. package/lib/schema/schema.d.ts +3 -2
  48. package/lib/schema/structured-type.d.ts +4 -3
  49. package/lib/types.d.ts +4 -1
  50. package/package.json +1 -1
@@ -1884,12 +1884,17 @@ class Lambda {
1884
1884
  render({ aliases, escape, prefix, }) {
1885
1885
  let [left, right] = this.values;
1886
1886
  left = render(left, { aliases, escape, prefix });
1887
- let alias = this.alias || left.split('/').pop().toLowerCase()[0];
1888
- return `${left}/${this.op}(${alias}:${render(right, {
1889
- aliases,
1890
- escape,
1891
- prefix: alias,
1892
- })})`;
1887
+ if (right) {
1888
+ let alias = this.alias || left.split('/').pop().toLowerCase()[0];
1889
+ return `${left}/${this.op}(${alias}:${render(right, {
1890
+ aliases,
1891
+ escape,
1892
+ prefix: alias,
1893
+ })})`;
1894
+ }
1895
+ else {
1896
+ return `${left}/${this.op}()`;
1897
+ }
1893
1898
  }
1894
1899
  clone() {
1895
1900
  return new Lambda(this.op, this.values.map((v) => Objects.clone(v)), this.alias);
@@ -1934,16 +1939,10 @@ class ComputeExpression extends Expression {
1934
1939
  super({ children });
1935
1940
  this.names = names || [];
1936
1941
  }
1937
- static expression() {
1938
- return new ComputeExpression();
1939
- }
1940
- static type() {
1941
- return Field$1.factory();
1942
- }
1943
1942
  static compute(opts, current) {
1944
1943
  return opts({
1945
- t: ComputeExpression.type(),
1946
- e: ComputeExpression.expression,
1944
+ t: Field$1.factory(),
1945
+ e: () => new ComputeExpression(),
1947
1946
  }, current);
1948
1947
  }
1949
1948
  render({ aliases, escape, prefix, } = {}) {
@@ -1978,16 +1977,10 @@ class FilterExpression extends Expression {
1978
1977
  this._connector = connector || 'and';
1979
1978
  this._negated = negated || false;
1980
1979
  }
1981
- static type() {
1982
- return Field$1.factory();
1983
- }
1984
- static expression(connector = 'and') {
1985
- return new FilterExpression({ connector });
1986
- }
1987
1980
  static filter(opts, current) {
1988
1981
  return opts({
1989
- t: FilterExpression.type(),
1990
- e: FilterExpression.expression,
1982
+ t: Field$1.factory(),
1983
+ e: (connector = 'and') => new FilterExpression({ connector }),
1991
1984
  o: operators,
1992
1985
  f: functions,
1993
1986
  }, current);
@@ -2112,16 +2105,19 @@ class FilterExpression extends Expression {
2112
2105
  return this._add(functions.endsWith(left, right, normalize));
2113
2106
  }
2114
2107
  any(left, opts, alias) {
2115
- const exp = opts({
2116
- t: Field$1.factory(),
2117
- e: FilterExpression.expression,
2118
- });
2108
+ let exp = undefined;
2109
+ if (opts !== undefined) {
2110
+ exp = opts({
2111
+ t: Field$1.factory(),
2112
+ e: (connector = 'and') => new FilterExpression({ connector }),
2113
+ });
2114
+ }
2119
2115
  return this._add(syntax.any(left, exp, alias));
2120
2116
  }
2121
2117
  all(left, opts, alias) {
2122
2118
  const exp = opts({
2123
2119
  t: Field$1.factory(),
2124
- e: FilterExpression.expression,
2120
+ e: (connector = 'and') => new FilterExpression({ connector }),
2125
2121
  });
2126
2122
  return this._add(syntax.all(left, exp, alias));
2127
2123
  }
@@ -2155,16 +2151,10 @@ class OrderByExpression extends Expression {
2155
2151
  constructor({ children, } = {}) {
2156
2152
  super({ children });
2157
2153
  }
2158
- static expression() {
2159
- return new OrderByExpression();
2160
- }
2161
- static type() {
2162
- return Field$1.factory();
2163
- }
2164
2154
  static orderBy(opts, current) {
2165
2155
  return opts({
2166
- t: OrderByExpression.type(),
2167
- e: OrderByExpression.expression,
2156
+ t: Field$1.factory(),
2157
+ e: () => new OrderByExpression(),
2168
2158
  }, current);
2169
2159
  }
2170
2160
  _add(node) {
@@ -2216,12 +2206,9 @@ class SearchExpression extends Expression {
2216
2206
  this._connector = connector || 'AND';
2217
2207
  this._negated = negated || false;
2218
2208
  }
2219
- static expression(connector = 'AND') {
2220
- return new SearchExpression({ connector });
2221
- }
2222
2209
  static search(opts, current) {
2223
2210
  return opts({
2224
- e: SearchExpression.expression,
2211
+ e: (connector = 'AND') => new SearchExpression({ connector }),
2225
2212
  }, current);
2226
2213
  }
2227
2214
  _add(node, connector) {
@@ -2316,16 +2303,10 @@ class SelectExpression extends Expression {
2316
2303
  constructor({ children, } = {}) {
2317
2304
  super({ children });
2318
2305
  }
2319
- static expression() {
2320
- return new SelectExpression();
2321
- }
2322
- static type() {
2323
- return Field$1.factory();
2324
- }
2325
2306
  static select(opts, current) {
2326
2307
  return opts({
2327
- t: SelectExpression.type(),
2328
- e: SelectExpression.expression,
2308
+ t: Field$1.factory(),
2309
+ e: () => new SelectExpression(),
2329
2310
  }, current);
2330
2311
  }
2331
2312
  render({ aliases, escape, prefix, } = {}) {
@@ -2426,16 +2407,10 @@ class ExpandExpression extends Expression {
2426
2407
  constructor({ children, } = {}) {
2427
2408
  super({ children });
2428
2409
  }
2429
- static expression() {
2430
- return new ExpandExpression();
2431
- }
2432
- static type() {
2433
- return Field$1.factory();
2434
- }
2435
2410
  static expand(opts, current) {
2436
2411
  return opts({
2437
- t: ExpandExpression.type(),
2438
- e: ExpandExpression.expression,
2412
+ t: Field$1.factory(),
2413
+ e: () => new ExpandExpression(),
2439
2414
  }, current);
2440
2415
  }
2441
2416
  render({ aliases, escape, prefix, } = {}) {
@@ -2869,8 +2844,14 @@ class ODataQueryOptions {
2869
2844
  .filter((key) => !Types.isEmpty(this.values.get(key)))
2870
2845
  .reduce((acc, key) => {
2871
2846
  let value = this.values.get(key);
2872
- if (Types.rawType(value).endsWith('Expression')) {
2873
- value = value.render({ aliases });
2847
+ if (Types.rawType(value).endsWith('Expression') ||
2848
+ (Types.isArray(value) &&
2849
+ value.some((v) => Types.rawType(v).endsWith('Expression')))) {
2850
+ value = Types.isArray(value)
2851
+ ? value.map((v) => Types.rawType(v).endsWith('Expression')
2852
+ ? v.render({ aliases })
2853
+ : v)
2854
+ : value.render({ aliases });
2874
2855
  }
2875
2856
  return Object.assign(acc, { [key]: value });
2876
2857
  }, {});
@@ -3419,7 +3400,7 @@ const ODataVersionBaseHelper = {
3419
3400
  };
3420
3401
  const ODataHelper = {
3421
3402
  //#region Version 4.0
3422
- [VERSION_4_0]: Object.assign({}, ODataVersionBaseHelper, {
3403
+ [VERSION_4_0]: { ...ODataVersionBaseHelper,
3423
3404
  VALUE: 'value',
3424
3405
  ODATA_ANNOTATION_PREFIX: '@odata',
3425
3406
  ODATA_FUNCTION_PREFIX: '#',
@@ -3503,11 +3484,10 @@ const ODataHelper = {
3503
3484
  },
3504
3485
  countParam() {
3505
3486
  return { [$COUNT]: 'true' };
3506
- },
3507
- }),
3487
+ }, },
3508
3488
  //#endregion
3509
3489
  //#region Version 3.0
3510
- [VERSION_3_0]: Object.assign({}, ODataVersionBaseHelper, {
3490
+ [VERSION_3_0]: { ...ODataVersionBaseHelper,
3511
3491
  ODATA_ANNOTATION_PREFIX: 'odata.',
3512
3492
  ODATA_FUNCTION_PREFIX: '',
3513
3493
  ODATA_ID: 'odata.id',
@@ -3534,11 +3514,10 @@ const ODataHelper = {
3534
3514
  },
3535
3515
  countParam() {
3536
3516
  return { [$INLINECOUNT]: 'allpages' };
3537
- },
3538
- }),
3517
+ }, },
3539
3518
  //#endregion
3540
3519
  //#region Version 2.0
3541
- [VERSION_2_0]: Object.assign({}, ODataVersionBaseHelper, {
3520
+ [VERSION_2_0]: { ...ODataVersionBaseHelper,
3542
3521
  ODATA_ID: 'id',
3543
3522
  ODATA_ETAG: 'etag',
3544
3523
  ODATA_ANNOTATION: '__metadata',
@@ -3559,8 +3538,7 @@ const ODataHelper = {
3559
3538
  },
3560
3539
  countParam() {
3561
3540
  return { [$INLINECOUNT]: 'allpages' };
3562
- },
3563
- }),
3541
+ }, },
3564
3542
  //#endregion
3565
3543
  };
3566
3544
 
@@ -3762,12 +3740,20 @@ const EDM_PARSERS = {
3762
3740
  return v;
3763
3741
  }, (v, o) => {
3764
3742
  if (o.ieee754Compatible) {
3765
- return parseFloat(v.toPrecision(o.field.precision)).toFixed(o.field.scale);
3743
+ let vstr = v.toPrecision(o.field.precision);
3744
+ if (typeof o.field.scale === 'number') {
3745
+ vstr = parseFloat(vstr).toFixed(o.field.scale);
3746
+ }
3747
+ return vstr;
3766
3748
  }
3767
3749
  return v;
3768
3750
  }, (v, o) => {
3769
3751
  if (o.ieee754Compatible) {
3770
- return parseFloat(v.toPrecision(o.field.precision)).toFixed(o.field.scale);
3752
+ let vstr = v.toPrecision(o.field.precision);
3753
+ if (typeof o.field.scale === 'number') {
3754
+ vstr = parseFloat(vstr).toFixed(o.field.scale);
3755
+ }
3756
+ return vstr;
3771
3757
  }
3772
3758
  return v;
3773
3759
  }),
@@ -3818,17 +3804,7 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3818
3804
  this.members = config.members;
3819
3805
  this._fields = Object.entries(config.fields).map(([name, f]) => new ODataEnumTypeFieldParser(name, f));
3820
3806
  }
3821
- /**
3822
- * Create a nicer looking title.
3823
- * Titleize is meant for creating pretty output.
3824
- * @param term The term of the annotation to find.
3825
- * @returns The titleized string.
3826
- */
3827
- ttitelize(term) {
3828
- return (term && this.annotatedValue(term)) || Strings.titleCase(this.name);
3829
- }
3830
- configure({ stringAsEnum, options, }) {
3831
- this.stringAsEnum = stringAsEnum;
3807
+ configure({ options, parserForType, findOptionsForType, }) {
3832
3808
  this.parserOptions = options;
3833
3809
  }
3834
3810
  isTypeOf(type) {
@@ -3860,7 +3836,7 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3860
3836
  // Deserialize
3861
3837
  deserialize(value, options) {
3862
3838
  // string -> number
3863
- const parserOptions = options || this.parserOptions;
3839
+ const parserOptions = { ...this.parserOptions, ...options };
3864
3840
  if (this.flags) {
3865
3841
  return Enums.toValues(this.members, value).reduce((acc, v) => acc | v, 0);
3866
3842
  }
@@ -3872,31 +3848,33 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3872
3848
  serialize(value, options) {
3873
3849
  // Enum are string | number
3874
3850
  // string | number -> string
3875
- const parserOptions = options || this.parserOptions;
3851
+ const parserOptions = { ...this.parserOptions, ...options };
3876
3852
  if (this.flags) {
3877
- const names = Enums.toNames(this.members, value);
3853
+ let names = Enums.toNames(this.members, value);
3878
3854
  if (names.length === 0)
3879
- return undefined;
3880
- return !this.stringAsEnum
3855
+ names = [`${value}`];
3856
+ return !parserOptions?.stringAsEnum
3881
3857
  ? `${this.namespace}.${this.name}'${names.join(', ')}'`
3882
3858
  : names.join(', ');
3883
3859
  }
3884
3860
  else {
3885
- const name = Enums.toName(this.members, value);
3861
+ let name = Enums.toName(this.members, value);
3886
3862
  if (name === undefined)
3887
- return undefined;
3888
- return !this.stringAsEnum
3863
+ name = `${value}`;
3864
+ return !parserOptions?.stringAsEnum
3889
3865
  ? `${this.namespace}.${this.name}'${name}'`
3890
3866
  : name;
3891
3867
  }
3892
3868
  }
3893
3869
  //Encode
3894
3870
  encode(value, options) {
3895
- const parserOptions = options || this.parserOptions;
3871
+ const parserOptions = { ...this.parserOptions, ...options };
3896
3872
  const serialized = this.serialize(value, parserOptions);
3897
3873
  if (serialized === undefined)
3898
3874
  return undefined;
3899
- return this.stringAsEnum ? raw(`'${serialized}'`) : raw(serialized);
3875
+ return parserOptions?.stringAsEnum
3876
+ ? raw(`'${serialized}'`)
3877
+ : raw(serialized);
3900
3878
  }
3901
3879
  // Json Schema
3902
3880
  toJsonSchema() {
@@ -3918,6 +3896,12 @@ class ODataEnumTypeParser extends ODataAnnotatable {
3918
3896
  return !(member in this.members) ? ['mismatch'] : undefined;
3919
3897
  }
3920
3898
  }
3899
+ unpack(value) {
3900
+ return Enums.toValues(this.members, value);
3901
+ }
3902
+ pack(value) {
3903
+ return Enums.toValues(this.members, value).reduce((acc, v) => acc | v, 0);
3904
+ }
3921
3905
  }
3922
3906
 
3923
3907
  class ODataEntityTypeKey {
@@ -3996,7 +3980,7 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
3996
3980
  return parser.deserialize(value, options);
3997
3981
  }
3998
3982
  deserialize(value, options) {
3999
- const parserOptions = options || this.parserOptions;
3983
+ const parserOptions = { ...this.parserOptions, ...options };
4000
3984
  if (this.parser instanceof ODataStructuredTypeParser) {
4001
3985
  const parser = this.parser;
4002
3986
  return Array.isArray(value)
@@ -4022,7 +4006,7 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
4022
4006
  return parser.serialize(value, options);
4023
4007
  }
4024
4008
  serialize(value, options) {
4025
- const parserOptions = options || this.parserOptions;
4009
+ const parserOptions = { ...this.parserOptions, ...options };
4026
4010
  if (this.parser instanceof ODataStructuredTypeParser) {
4027
4011
  const parser = this.parser;
4028
4012
  return Array.isArray(value)
@@ -4037,14 +4021,14 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
4037
4021
  //#endregion
4038
4022
  //#region Encode
4039
4023
  encode(value, options) {
4040
- const parserOptions = options || this.parserOptions;
4024
+ const parserOptions = { ...this.parserOptions, ...options };
4041
4025
  return this.parser.encode(value, {
4042
4026
  field: this,
4043
4027
  ...parserOptions,
4044
4028
  });
4045
4029
  }
4046
4030
  //#endregion
4047
- configure({ parserForType, options, }) {
4031
+ configure({ options, parserForType, findOptionsForType, }) {
4048
4032
  this.parserOptions = options;
4049
4033
  this.parser = parserForType(this.type);
4050
4034
  if (this.default !== undefined) {
@@ -4189,7 +4173,7 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
4189
4173
  }
4190
4174
  // Deserialize
4191
4175
  deserialize(value, options) {
4192
- const parserOptions = options || this.parserOptions;
4176
+ const parserOptions = { ...this.parserOptions, ...options };
4193
4177
  const fields = this.fields({
4194
4178
  include_navigation: true,
4195
4179
  include_parents: true,
@@ -4204,7 +4188,7 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
4204
4188
  }
4205
4189
  // Serialize
4206
4190
  serialize(value, options) {
4207
- const parserOptions = options || this.parserOptions;
4191
+ const parserOptions = { ...this.parserOptions, ...options };
4208
4192
  const fields = this.fields({
4209
4193
  include_navigation: true,
4210
4194
  include_parents: true,
@@ -4221,17 +4205,17 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
4221
4205
  }
4222
4206
  // Encode
4223
4207
  encode(value, options) {
4224
- const parserOptions = options || this.parserOptions;
4208
+ const parserOptions = { ...this.parserOptions, ...options };
4225
4209
  return raw(JSON.stringify(this.serialize(value, parserOptions)));
4226
4210
  }
4227
- configure({ parserForType, options, }) {
4211
+ configure({ options, parserForType, findOptionsForType, }) {
4228
4212
  this.parserOptions = options;
4229
4213
  if (this.base) {
4230
4214
  const parent = parserForType(this.base);
4231
4215
  parent.children.push(this);
4232
4216
  this.parent = parent;
4233
4217
  }
4234
- this._fields.forEach((f) => f.configure({ parserForType, options }));
4218
+ this._fields.forEach((f) => f.configure({ options, parserForType, findOptionsForType }));
4235
4219
  }
4236
4220
  /**
4237
4221
  * Returns all fields of the structured type.
@@ -4400,19 +4384,19 @@ class ODataParameterParser {
4400
4384
  this.collection = parameter.collection;
4401
4385
  }
4402
4386
  serialize(value, options) {
4403
- const parserOptions = options || this.parserOptions;
4387
+ const parserOptions = { ...this.parserOptions, ...options };
4404
4388
  return Array.isArray(value)
4405
4389
  ? value.map((v) => this.parser.serialize(v, parserOptions))
4406
4390
  : this.parser.serialize(value, parserOptions);
4407
4391
  }
4408
4392
  //Encode
4409
4393
  encode(value, options) {
4410
- const parserOptions = options || this.parserOptions;
4394
+ const parserOptions = { ...this.parserOptions, ...options };
4411
4395
  return Array.isArray(value)
4412
4396
  ? value.map((v) => this.parser.encode(v, parserOptions))
4413
4397
  : this.parser.encode(value, parserOptions);
4414
4398
  }
4415
- configure({ parserForType, options, }) {
4399
+ configure({ options, parserForType, findOptionsForType, }) {
4416
4400
  this.parserOptions = options;
4417
4401
  this.parser = parserForType(this.type);
4418
4402
  }
@@ -4458,12 +4442,12 @@ class ODataCallableParser {
4458
4442
  }
4459
4443
  // Deserialize
4460
4444
  deserialize(value, options) {
4461
- const parserOptions = options || this.parserOptions;
4445
+ const parserOptions = { ...this.parserOptions, ...options };
4462
4446
  return this.parser.deserialize(value, parserOptions);
4463
4447
  }
4464
4448
  // Serialize
4465
4449
  serialize(params, options) {
4466
- const parserOptions = options || this.parserOptions;
4450
+ const parserOptions = { ...this.parserOptions, ...options };
4467
4451
  const parameters = this.parameters
4468
4452
  .filter((p) => p.name !== CALLABLE_BINDING_PARAMETER)
4469
4453
  .filter((p) => p.name in params && params[p.name] !== undefined);
@@ -4474,7 +4458,7 @@ class ODataCallableParser {
4474
4458
  }
4475
4459
  //Encode
4476
4460
  encode(params, options) {
4477
- const parserOptions = options || this.parserOptions;
4461
+ const parserOptions = { ...this.parserOptions, ...options };
4478
4462
  const parameters = this.parameters
4479
4463
  .filter((p) => p.name !== CALLABLE_BINDING_PARAMETER)
4480
4464
  .filter((p) => p.name in params && params[p.name] !== undefined);
@@ -4483,13 +4467,11 @@ class ODataCallableParser {
4483
4467
  [p.name]: p.encode(params[p.name], parserOptions),
4484
4468
  }), {});
4485
4469
  }
4486
- configure({ nonParenthesisForEmptyParameterFunction, parserForType, options, }) {
4487
- this.nonParenthesisForEmptyParameterFunction =
4488
- nonParenthesisForEmptyParameterFunction;
4470
+ configure({ options, parserForType, findOptionsForType, }) {
4489
4471
  this.parserOptions = options;
4490
4472
  if (this.return)
4491
4473
  this.parser = parserForType(this.return.type) || NONE_PARSER;
4492
- this.parameters.forEach((p) => p.configure({ parserForType, options }));
4474
+ this.parameters.forEach((p) => p.configure({ options, parserForType, findOptionsForType }));
4493
4475
  }
4494
4476
  binding() {
4495
4477
  return this.parameters.find((p) => p.name === CALLABLE_BINDING_PARAMETER);
@@ -4517,11 +4499,11 @@ class ODataCallable extends ODataSchemaElement {
4517
4499
  : this.name;
4518
4500
  return path;
4519
4501
  }
4520
- configure({ parserForType, }) {
4502
+ configure({ options, parserForType, findOptionsForType, }) {
4521
4503
  this.parser.configure({
4522
- nonParenthesisForEmptyParameterFunction: this.api.options.nonParenthesisForEmptyParameterFunction,
4523
- options: this.api.options.parserOptions,
4504
+ options,
4524
4505
  parserForType,
4506
+ findOptionsForType,
4525
4507
  });
4526
4508
  }
4527
4509
  /**
@@ -4581,11 +4563,8 @@ class ODataEnumType extends ODataSchemaElement {
4581
4563
  this.members = config.members;
4582
4564
  this.parser = new ODataEnumTypeParser(config, schema.namespace, schema.alias);
4583
4565
  }
4584
- configure() {
4585
- this.parser.configure({
4586
- stringAsEnum: this.api.options.stringAsEnum,
4587
- options: this.api.options.parserOptions,
4588
- });
4566
+ configure({ options, parserForType, findOptionsForType, }) {
4567
+ this.parser.configure({ options, parserForType, findOptionsForType });
4589
4568
  }
4590
4569
  /**
4591
4570
  * Returns the fields of the enum type.
@@ -4637,6 +4616,12 @@ class ODataEnumType extends ODataSchemaElement {
4637
4616
  encode(value, options) {
4638
4617
  return this.parser.encode(value, options);
4639
4618
  }
4619
+ unpack(value) {
4620
+ return this.parser.unpack(value);
4621
+ }
4622
+ pack(value) {
4623
+ return this.parser.pack(value);
4624
+ }
4640
4625
  }
4641
4626
 
4642
4627
  class ODataStructuredType extends ODataSchemaElement {
@@ -4658,20 +4643,22 @@ class ODataStructuredType extends ODataSchemaElement {
4658
4643
  this.collection.model = this.model;
4659
4644
  }
4660
4645
  }
4661
- configure({ parserForType, findOptionsForType, }) {
4646
+ configure({ options, parserForType, findOptionsForType, }) {
4662
4647
  if (this.base) {
4663
4648
  const parent = this.api.findStructuredTypeForType(this.base);
4664
4649
  parent.children.push(this);
4665
4650
  this.parent = parent;
4666
4651
  }
4667
4652
  this.parser.configure({
4653
+ options,
4668
4654
  parserForType,
4669
- options: this.api.options.parserOptions,
4655
+ findOptionsForType,
4670
4656
  });
4671
4657
  if (this.model !== undefined && this.model.options !== null) {
4672
4658
  this.model.meta.configure({
4659
+ options,
4660
+ parserForType,
4673
4661
  findOptionsForType,
4674
- options: this.api.options.parserOptions,
4675
4662
  });
4676
4663
  }
4677
4664
  }
@@ -4876,13 +4863,13 @@ class ODataSchema extends ODataAnnotatable {
4876
4863
  return this.entitySets.find((e) => e.isTypeOf(type));
4877
4864
  }
4878
4865
  //#endregion
4879
- configure({ parserForType, findOptionsForType, }) {
4866
+ configure({ options, parserForType, findOptionsForType, }) {
4880
4867
  // Configure Enums
4881
- this.enums.forEach((enu) => enu.configure());
4868
+ this.enums.forEach((enu) => enu.configure({ options, parserForType, findOptionsForType }));
4882
4869
  // Configure Entities
4883
- this.entities.forEach((config) => config.configure({ parserForType, findOptionsForType }));
4870
+ this.entities.forEach((config) => config.configure({ options, parserForType, findOptionsForType }));
4884
4871
  // Configure callables
4885
- this.callables.forEach((callable) => callable.configure({ parserForType }));
4872
+ this.callables.forEach((callable) => callable.configure({ options, parserForType, findOptionsForType }));
4886
4873
  }
4887
4874
  }
4888
4875
 
@@ -5018,7 +5005,6 @@ class ODataResource {
5018
5005
  return undefined;
5019
5006
  }
5020
5007
  deserialize(value, options) {
5021
- const parserOptions = options || this.api.options.parserOptions;
5022
5008
  const resourceType = this.returnType();
5023
5009
  const _d = (value, options) => {
5024
5010
  const parser = this.__parser(value, options, resourceType);
@@ -5027,11 +5013,10 @@ class ODataResource {
5027
5013
  : value;
5028
5014
  };
5029
5015
  return Array.isArray(value)
5030
- ? value.map((v) => _d(v, parserOptions))
5031
- : _d(value, parserOptions);
5016
+ ? value.map((v) => _d(v, options))
5017
+ : _d(value, options);
5032
5018
  }
5033
5019
  serialize(value, options) {
5034
- const parserOptions = options || this.api.options.parserOptions;
5035
5020
  const resourceType = this.type();
5036
5021
  const _s = (value, options) => {
5037
5022
  const parser = this.__parser(value, options, resourceType);
@@ -5040,11 +5025,10 @@ class ODataResource {
5040
5025
  : value;
5041
5026
  };
5042
5027
  return Array.isArray(value)
5043
- ? value.map((v) => _s(v, parserOptions))
5044
- : _s(value, parserOptions);
5028
+ ? value.map((v) => _s(v, options))
5029
+ : _s(value, options);
5045
5030
  }
5046
5031
  encode(value, options) {
5047
- const parserOptions = options || this.api.options.parserOptions;
5048
5032
  const resourceType = this.type();
5049
5033
  const _e = (value, options) => {
5050
5034
  const parser = this.__parser(value, options, resourceType);
@@ -5053,8 +5037,8 @@ class ODataResource {
5053
5037
  : value;
5054
5038
  };
5055
5039
  return Array.isArray(value)
5056
- ? value.map((v) => _e(v, parserOptions))
5057
- : _e(value, parserOptions);
5040
+ ? value.map((v) => _e(v, options))
5041
+ : _e(value, options);
5058
5042
  }
5059
5043
  toJSON() {
5060
5044
  return {
@@ -6530,6 +6514,12 @@ class ODataAnnotations {
6530
6514
  attributes(data, metadata) {
6531
6515
  return this.helper.attributes(data, metadata);
6532
6516
  }
6517
+ update(data) {
6518
+ this.annotations = new Map([
6519
+ ...this.annotations,
6520
+ ...this.helper.annotations(data),
6521
+ ]);
6522
+ }
6533
6523
  get entitySet() {
6534
6524
  return this.context?.entitySet;
6535
6525
  }
@@ -8108,23 +8098,38 @@ class ODataModelField {
8108
8098
  schemaFactory(base) {
8109
8099
  return this.api.findStructuredTypeForType(this.parser.type);
8110
8100
  }
8111
- modelCollectionFactory({ parent, value, reset, }) {
8101
+ modelFactory({ parent, value, reset, }) {
8102
+ // Model
8103
+ const annots = this.annotationsFactory(parent.annots());
8104
+ let Model = this.api.modelForType(this.parser.type);
8105
+ if (Model === undefined)
8106
+ throw Error(`No Model type for ${this.name}`);
8107
+ if (value !== undefined) {
8108
+ annots.update(value);
8109
+ }
8110
+ if (annots?.type !== undefined && Model.meta !== null) {
8111
+ let schema = Model.meta.findChildOptions((o) => o.isTypeOf(annots.type))?.schema;
8112
+ if (schema !== undefined && schema.model !== undefined)
8113
+ // Change to child model
8114
+ Model = schema.model;
8115
+ }
8116
+ return new Model((value || {}), {
8117
+ annots,
8118
+ reset,
8119
+ parent: [parent, this],
8120
+ });
8121
+ }
8122
+ collectionFactory({ parent, value, reset, }) {
8123
+ // Collection Factory
8112
8124
  const annots = this.annotationsFactory(parent.annots());
8113
- const Model = this.api.modelForType(this.parser.type);
8114
8125
  const Collection = this.api.collectionForType(this.parser.type);
8115
- if (Model === undefined || Collection === undefined)
8116
- throw Error(`No model for ${this.name}`);
8117
- return this.parser.collection
8118
- ? new Collection((value || []), {
8119
- annots: annots,
8120
- parent: [parent, this],
8121
- reset,
8122
- })
8123
- : new Model((value || {}), {
8124
- annots: annots,
8125
- parent: [parent, this],
8126
- reset,
8127
- });
8126
+ if (Collection === undefined)
8127
+ throw Error(`No Collection type for ${this.name}`);
8128
+ return new Collection((value || []), {
8129
+ annots: annots,
8130
+ parent: [parent, this],
8131
+ reset,
8132
+ });
8128
8133
  }
8129
8134
  }
8130
8135
  class ODataModelOptions {
@@ -8178,7 +8183,7 @@ class ODataModelOptions {
8178
8183
  }
8179
8184
  return match;
8180
8185
  }
8181
- configure({ findOptionsForType, options, }) {
8186
+ configure({ options, parserForType, findOptionsForType, }) {
8182
8187
  if (this.base) {
8183
8188
  const parent = findOptionsForType(this.base);
8184
8189
  parent.children.push(this);
@@ -8793,11 +8798,17 @@ class ODataModelOptions {
8793
8798
  ODataModelOptions.isCollection(value) ||
8794
8799
  ODataModelOptions.isModel(value)
8795
8800
  ? value
8796
- : field.modelCollectionFactory({
8797
- parent: self,
8798
- value: value,
8799
- reset: self._reset,
8800
- });
8801
+ : field.collection
8802
+ ? field.collectionFactory({
8803
+ parent: self,
8804
+ value: value,
8805
+ reset: self._reset,
8806
+ })
8807
+ : field.modelFactory({
8808
+ parent: self,
8809
+ value: value,
8810
+ reset: self._reset,
8811
+ });
8801
8812
  // Link new model/collection
8802
8813
  this._link(self, relation);
8803
8814
  changed = true;
@@ -8936,6 +8947,12 @@ class ODataCollection {
8936
8947
  get length() {
8937
8948
  return this.models().length;
8938
8949
  }
8950
+ isEmpty() {
8951
+ // Local length and if exists remote length
8952
+ return (this.length === 0 &&
8953
+ this.annots().count !== undefined &&
8954
+ this.annots().count === 0);
8955
+ }
8939
8956
  isParentOf(child) {
8940
8957
  return (child !== this &&
8941
8958
  ODataModelOptions.chain(child).some((p) => p[0] === this));
@@ -8994,8 +9011,8 @@ class ODataCollection {
8994
9011
  }
8995
9012
  modelFactory(data, { reset = false } = {}) {
8996
9013
  let Model = this._model;
8997
- const helper = this._annotations.helper;
8998
- const annots = new ODataEntityAnnotations(helper, helper.annotations(data));
9014
+ const annots = new ODataEntityAnnotations(this._annotations.helper);
9015
+ annots.update(data);
8999
9016
  if (annots?.type !== undefined && Model.meta !== null) {
9000
9017
  let schema = Model.meta.findChildOptions((o) => o.isTypeOf(annots.type))?.schema;
9001
9018
  if (schema !== undefined && schema.model !== undefined)
@@ -10112,11 +10129,14 @@ class ODataModel {
10112
10129
  if (model === null)
10113
10130
  return null;
10114
10131
  if (model === undefined) {
10115
- const value = field.collection ? [] : this.referenced(field);
10116
- model =
10117
- value !== null
10118
- ? field.modelCollectionFactory({ parent: this, value })
10119
- : null;
10132
+ if (field.collection) {
10133
+ model = field.collectionFactory({ parent: this });
10134
+ }
10135
+ else {
10136
+ const value = this.referenced(field);
10137
+ model =
10138
+ value === null ? null : field.modelFactory({ parent: this, value });
10139
+ }
10120
10140
  this[name] = model;
10121
10141
  }
10122
10142
  return model;
@@ -10169,7 +10189,13 @@ class ODataApiOptions {
10169
10189
  config.nonParenthesisForEmptyParameterFunction || false;
10170
10190
  }
10171
10191
  get parserOptions() {
10172
- return { version: this.version, ...this.accept };
10192
+ return {
10193
+ version: this.version,
10194
+ stringAsEnum: this.stringAsEnum,
10195
+ deleteRefBy: this.deleteRefBy,
10196
+ nonParenthesisForEmptyParameterFunction: this.nonParenthesisForEmptyParameterFunction,
10197
+ ...this.accept,
10198
+ };
10173
10199
  }
10174
10200
  get helper() {
10175
10201
  return ODataHelper[this.version];
@@ -10219,6 +10245,7 @@ class ODataApi {
10219
10245
  this.requester = settings.requester;
10220
10246
  this.schemas.forEach((schema) => {
10221
10247
  schema.configure({
10248
+ options: this.options.parserOptions,
10222
10249
  parserForType: (type) => this.parserForType(type),
10223
10250
  findOptionsForType: (type) => this.findOptionsForType(type),
10224
10251
  });
@@ -10372,8 +10399,9 @@ class ODataApi {
10372
10399
  Model.buildMeta({ schema });
10373
10400
  // Configure
10374
10401
  Model.meta.configure({
10375
- findOptionsForType: (type) => this.findOptionsForType(type),
10376
10402
  options: this.options.parserOptions,
10403
+ parserForType: (type) => this.parserForType(type),
10404
+ findOptionsForType: (type) => this.findOptionsForType(type),
10377
10405
  });
10378
10406
  // Store New Model for next time
10379
10407
  schema.model = Model;