angular-odata 0.146.1 → 0.147.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.
@@ -1,9 +1,8 @@
1
- import * as i1 from '@angular/common/http';
2
- import { HttpHeaders, HttpParams, HttpResponse, HttpErrorResponse, HttpEventType } from '@angular/common/http';
3
- import { Subject, map as map$1, EMPTY, throwError, Observable, forkJoin, of, NEVER } from 'rxjs';
4
- import { map, expand, reduce, finalize, defaultIfEmpty, switchMap, catchError, tap, startWith } from 'rxjs/operators';
1
+ import { HttpHeaders, HttpParams, HttpResponse, HttpErrorResponse, HttpEventType, provideHttpClient, HttpClient } from '@angular/common/http';
2
+ import { Subject, map as map$1, EMPTY, throwError, Observable, forkJoin, of, NEVER, firstValueFrom } from 'rxjs';
3
+ import { map, expand, reduce, finalize, defaultIfEmpty, switchMap, catchError, startWith, tap } from 'rxjs/operators';
5
4
  import * as i0 from '@angular/core';
6
- import { EventEmitter, Injectable, InjectionToken, makeEnvironmentProviders, NgModule } from '@angular/core';
5
+ import { EventEmitter, Injectable, InjectionToken, provideAppInitializer, inject, makeEnvironmentProviders, NgModule } from '@angular/core';
7
6
  import { CommonModule } from '@angular/common';
8
7
 
9
8
  var PathSegment;
@@ -528,7 +527,7 @@ const binary = (value) => ({
528
527
  type: QueryCustomTypes.Binary,
529
528
  value,
530
529
  });
531
- const isQueryCustomType = (value) => typeof value === 'object' && 'type' in value && value.type in QueryCustomTypes;
530
+ const isQueryCustomType = (value) => value !== null && value !== undefined && typeof value === 'object' && 'type' in value && value.type in QueryCustomTypes;
532
531
  const isRawType = (value) => isQueryCustomType(value) && value.type === QueryCustomTypes.Raw;
533
532
  const ITEM_ROOT = '';
534
533
  function builder ({ select, search, skiptoken, format, top, skip, filter, transform, compute, orderBy, key, count, expand, action, func, aliases, escape, } = {}) {
@@ -1849,10 +1848,7 @@ class ODataSchemaElement extends ODataAnnotatable {
1849
1848
  * @returns True if the callable is type of the given type
1850
1849
  */
1851
1850
  isTypeOf(element) {
1852
- const names = [`${this.schema.namespace}.${this.name}`];
1853
- if (this.schema.alias)
1854
- names.push(`${this.schema.alias}.${this.name}`);
1855
- return names.includes(element.type());
1851
+ return this.type() === element.type();
1856
1852
  }
1857
1853
  /**
1858
1854
  * Returns a boolean indicating if the structured type is a subtype of the given type.
@@ -1946,10 +1942,10 @@ const EdmParser = (_d, _s, _e) => ({
1946
1942
  },
1947
1943
  });
1948
1944
  const Identity = (v) => v;
1949
- const toNumber = (v) => Number(v);
1950
- const toString = (v) => v.toString();
1951
- const toBoolean = (v) => Boolean(v);
1952
- const toDate = (v) => new Date(v);
1945
+ const toNumber = (v) => v && Number(v);
1946
+ const toString = (v) => v && v.toString();
1947
+ const toBoolean = (v) => v && Boolean(v);
1948
+ const toDate = (v) => v && new Date(v);
1953
1949
  const EDM_PARSERS = {
1954
1950
  //Edm.Guid 16-byte (128-bit) unique identifier
1955
1951
  [EdmType.Guid]: EdmParser(Identity, Identity, (v) => raw(v)),
@@ -2112,8 +2108,8 @@ class ODataEnumTypeParser extends ODataAnnotatable {
2112
2108
  if (names.length === 0)
2113
2109
  names = [`${value}`];
2114
2110
  return !parserOptions?.stringAsEnum
2115
- ? `${this.namespace}.${this.name}'${names.join(', ')}'`
2116
- : names.join(', ');
2111
+ ? `${this.namespace}.${this.name}'${names.join(',')}'`
2112
+ : names.join(',');
2117
2113
  }
2118
2114
  else {
2119
2115
  let name = this.field(value)?.name;
@@ -3067,6 +3063,15 @@ class ODataStructuredType extends ODataParserSchemaElement {
3067
3063
  return undefined;
3068
3064
  return this.parent.findParentSchema(predicate);
3069
3065
  }
3066
+ /**
3067
+ * Find a parent schema of the structured type for the given field.
3068
+ * @param field Field that belongs to the structured type
3069
+ * @returns The schema of the field
3070
+ */
3071
+ findParentSchemaForField(field) {
3072
+ return this.findParentSchema((p) => p.fields({ include_parents: false, include_navigation: true }).find((f) => f === field) !==
3073
+ undefined);
3074
+ }
3070
3075
  findChildSchema(predicate) {
3071
3076
  if (predicate(this))
3072
3077
  return this;
@@ -3078,15 +3083,6 @@ class ODataStructuredType extends ODataParserSchemaElement {
3078
3083
  }
3079
3084
  return match;
3080
3085
  }
3081
- /**
3082
- * Find a parent schema of the structured type for the given field.
3083
- * @param field Field that belongs to the structured type
3084
- * @returns The schema of the field
3085
- */
3086
- findParentSchemaForField(field) {
3087
- return this.findParentSchema((p) => p.fields({ include_parents: false, include_navigation: true }).find((f) => f === field) !==
3088
- undefined);
3089
- }
3090
3086
  /**
3091
3087
  * Picks the fields from attributes.
3092
3088
  * @param attrs
@@ -6271,6 +6267,20 @@ class ODataResource {
6271
6267
  query: this.cloneQuery(),
6272
6268
  });
6273
6269
  }
6270
+ cast(type) {
6271
+ const Ctor = this.constructor;
6272
+ const thisType = this.incomingType();
6273
+ const baseSchema = thisType !== undefined ? this.api.structuredType(thisType) : undefined;
6274
+ const castSchema = this.api.findStructuredType(type);
6275
+ if (castSchema !== undefined && baseSchema !== undefined && !castSchema.isSubtypeOf(baseSchema))
6276
+ throw new Error(`cast: Cannot cast to ${type}`);
6277
+ const segments = this.cloneSegments();
6278
+ segments.add(PathSegment.type, type).incomingType(type);
6279
+ return new Ctor(this.api, {
6280
+ segments,
6281
+ query: this.cloneQuery(),
6282
+ });
6283
+ }
6274
6284
  __parser(value, options, resourceType, bindingType) {
6275
6285
  const dataType = options !== undefined && Types.isPlainObject(value)
6276
6286
  ? ODataHelper[options.version ?? DEFAULT_VERSION].type(value)
@@ -7551,17 +7561,7 @@ class ODataNavigationPropertyResource extends ODataResource {
7551
7561
  });
7552
7562
  }
7553
7563
  cast(type) {
7554
- const thisType = this.incomingType();
7555
- const baseSchema = thisType !== undefined ? this.api.structuredType(thisType) : undefined;
7556
- const castSchema = this.api.findStructuredType(type);
7557
- if (castSchema !== undefined && baseSchema !== undefined && !castSchema.isSubtypeOf(baseSchema))
7558
- throw new Error(`Cannot cast to ${type}`);
7559
- const segments = this.cloneSegments();
7560
- segments.add(PathSegment.type, type).incomingType(type);
7561
- return new ODataNavigationPropertyResource(this.api, {
7562
- segments,
7563
- query: this.cloneQuery(),
7564
- });
7564
+ return super.cast(type);
7565
7565
  }
7566
7566
  //#region Requests
7567
7567
  post(attrs, options = {}) {
@@ -7735,18 +7735,7 @@ class ODataEntityResource extends ODataResource {
7735
7735
  return ODataFunctionResource.fromResource(this, path);
7736
7736
  }
7737
7737
  cast(type) {
7738
- const thisType = this.incomingType();
7739
- const baseSchema = thisType !== undefined ? this.api.structuredType(thisType) : undefined;
7740
- // Downcast
7741
- const castSchema = baseSchema?.findChildSchema((s) => s.type() === type);
7742
- if (castSchema !== undefined && baseSchema !== undefined && !castSchema.isSubtypeOf(baseSchema))
7743
- throw new Error(`cast: Cannot cast to ${type}`);
7744
- const segments = this.cloneSegments();
7745
- segments.add(PathSegment.type, type).incomingType(type);
7746
- return new ODataEntityResource(this.api, {
7747
- segments,
7748
- query: this.cloneQuery(),
7749
- });
7738
+ return super.cast(type);
7750
7739
  }
7751
7740
  //#region Requests
7752
7741
  post(attrs, options = {}) {
@@ -7835,17 +7824,7 @@ class ODataEntitySetResource extends ODataResource {
7835
7824
  });
7836
7825
  }
7837
7826
  cast(type) {
7838
- const thisType = this.incomingType();
7839
- const baseSchema = thisType !== undefined ? this.api.structuredType(thisType) : undefined;
7840
- const castSchema = this.api.findStructuredType(type);
7841
- if (castSchema !== undefined && baseSchema !== undefined && !castSchema.isSubtypeOf(baseSchema))
7842
- throw new Error(`cast: Cannot cast to ${type}`);
7843
- const segments = this.cloneSegments();
7844
- segments.add(PathSegment.type, type).incomingType(type);
7845
- return new ODataEntitySetResource(this.api, {
7846
- segments,
7847
- query: this.cloneQuery(),
7848
- });
7827
+ return super.cast(type);
7849
7828
  }
7850
7829
  //#region Requests
7851
7830
  post(attrs, options) {
@@ -11409,7 +11388,6 @@ class ODataModel {
11409
11388
  }
11410
11389
  }
11411
11390
  cast(type, ModelType) {
11412
- //: ODataModel<S> {
11413
11391
  const resource = this.resource();
11414
11392
  if (!(resource instanceof ODataEntityResource))
11415
11393
  throw new Error(`cast: Can't cast to derived model without ODataEntityResource`);
@@ -11743,11 +11721,6 @@ class ODataModelField {
11743
11721
  field;
11744
11722
  parser;
11745
11723
  options;
11746
- optionsForType;
11747
- modelForType;
11748
- collectionForType;
11749
- enumForType;
11750
- structuredForType;
11751
11724
  default;
11752
11725
  required;
11753
11726
  concurrency;
@@ -11783,12 +11756,7 @@ class ODataModelField {
11783
11756
  annotatedValue(term) {
11784
11757
  return this.parser.annotatedValue(term);
11785
11758
  }
11786
- configure({ optionsForType, modelForType, collectionForType, enumForType, structuredForType, concurrency, options, }) {
11787
- this.optionsForType = optionsForType;
11788
- this.modelForType = modelForType;
11789
- this.collectionForType = collectionForType;
11790
- this.enumForType = enumForType;
11791
- this.structuredForType = structuredForType;
11759
+ configure({ concurrency, options, }) {
11792
11760
  this.parserOptions = options;
11793
11761
  if (concurrency)
11794
11762
  this.concurrency = concurrency;
@@ -11808,7 +11776,7 @@ class ODataModelField {
11808
11776
  return this.parser.isStructuredType();
11809
11777
  }
11810
11778
  structuredType() {
11811
- const structuredType = this.structuredForType ? this.structuredForType(this.type) : undefined;
11779
+ const structuredType = this.options.api.findStructuredType(this.type);
11812
11780
  //Throw error if not found
11813
11781
  if (!structuredType)
11814
11782
  throw new Error(`Could not find structured type for ${this.parser.type}`);
@@ -11821,7 +11789,7 @@ class ODataModelField {
11821
11789
  return this.parser.isEdmType();
11822
11790
  }
11823
11791
  enumType() {
11824
- const enumType = this.enumForType ? this.enumForType(this.type) : undefined;
11792
+ const enumType = this.options.api.findEnumType(this.type);
11825
11793
  //Throw error if not found
11826
11794
  if (!enumType)
11827
11795
  throw new Error(`Could not find enum type for ${this.parser.type}`);
@@ -11868,7 +11836,7 @@ class ODataModelField {
11868
11836
  }
11869
11837
  }
11870
11838
  defaults() {
11871
- const meta = this.optionsForType && this.isStructuredType() ? this.optionsForType(this.type) : undefined;
11839
+ const meta = this.isStructuredType() ? this.options.api.optionsForType(this.type) : undefined;
11872
11840
  return meta !== undefined ? meta.defaults() : this.default;
11873
11841
  }
11874
11842
  deserialize(value, options) {
@@ -11900,7 +11868,7 @@ class ODataModelField {
11900
11868
  modelFactory({ parent, value, reset, }) {
11901
11869
  // Model
11902
11870
  const annots = this.annotationsFactory(parent.annots());
11903
- let Model = this.modelForType ? this.modelForType(this.type) : undefined;
11871
+ let Model = this.options.api.modelForType(this.type);
11904
11872
  if (Model === undefined)
11905
11873
  throw Error(`No Model type for ${this.name}`);
11906
11874
  if (value !== undefined) {
@@ -11921,7 +11889,7 @@ class ODataModelField {
11921
11889
  collectionFactory({ parent, value, reset, }) {
11922
11890
  // Collection Factory
11923
11891
  const annots = this.annotationsFactory(parent.annots());
11924
- const Collection = this.collectionForType ? this.collectionForType(this.type) : undefined;
11892
+ const Collection = this.options.api.collectionForType(this.type);
11925
11893
  if (Collection === undefined)
11926
11894
  throw Error(`No Collection type for ${this.name}`);
11927
11895
  return Collection.factory((value || []), {
@@ -12129,11 +12097,6 @@ class ODataModelOptions {
12129
12097
  this._fields.forEach((field) => {
12130
12098
  const concurrency = concurrencyFields.indexOf(field.field) !== -1;
12131
12099
  field.configure({
12132
- optionsForType: (t) => this.api.optionsForType(t),
12133
- modelForType: (t) => this.api.modelForType(t),
12134
- collectionForType: (t) => this.api.collectionForType(t),
12135
- enumForType: (t) => this.api.findEnumType(t),
12136
- structuredForType: (t) => this.api.findStructuredType(t),
12137
12100
  concurrency,
12138
12101
  options,
12139
12102
  });
@@ -12195,11 +12158,6 @@ class ODataModelOptions {
12195
12158
  parser: structuredFieldParser,
12196
12159
  });
12197
12160
  modelField.configure({
12198
- optionsForType: (t) => this.api.optionsForType(t),
12199
- modelForType: (t) => this.api.modelForType(t),
12200
- collectionForType: (t) => this.api.collectionForType(t),
12201
- enumForType: (t) => this.api.findEnumType(t),
12202
- structuredForType: (t) => this.api.findStructuredType(t),
12203
12161
  options: this.api.options,
12204
12162
  concurrency: false,
12205
12163
  });
@@ -12241,38 +12199,38 @@ class ODataModelOptions {
12241
12199
  let resource = null;
12242
12200
  let prevField = null;
12243
12201
  for (const [model, field] of ODataModelOptions.chain(child)) {
12244
- resource = resource || model._resource?.clone();
12202
+ resource = resource ?? model._resource?.clone();
12203
+ // Break if no resource
12245
12204
  if (resource === null)
12246
12205
  break;
12247
- if (ODataModelOptions.isModel(model) && (prevField === null || prevField.collection)) {
12248
- const m = model;
12249
- // Resolve subtype if collection not is from field
12250
- // FIXME
12251
- /*
12252
- if (field === null) {
12253
- const r = m._meta.modelResourceFactory(resource.cloneQuery<T>());
12254
- if (r !== null && !r.isTypeOf(resource) && r.isSubtypeOf(resource)) {
12255
- resource = r;
12256
- }
12257
- }
12258
- */
12259
- // Resolve key
12260
- const mKey = m.key({ field_mapping: true });
12261
- if (mKey !== undefined) {
12206
+ // Resolve Key
12207
+ if ((prevField === null || prevField.collection) && ODataModelOptions.isModel(model) && model._meta.isEntityType()) {
12208
+ const key = model.key({ field_mapping: true });
12209
+ if (key !== undefined) {
12262
12210
  resource =
12263
12211
  resource instanceof ODataEntitySetResource
12264
- ? resource.entity(mKey)
12265
- : resource.key(mKey);
12212
+ ? resource.entity(key)
12213
+ : resource.key(key);
12266
12214
  }
12267
12215
  }
12268
- prevField = field;
12269
- if (field === null && model._resource !== null) {
12270
- // Apply the query from model to new resource
12271
- model._resource.query((qs) => resource?.query((qd) => qd.restore(qs.store())));
12272
- }
12273
- else if (field !== null) {
12216
+ if (field !== null) {
12217
+ // Resolve Structured Type Cast
12218
+ const resourceType = resource.structuredType();
12219
+ const fieldType = field.options.structuredType;
12220
+ if (resourceType !== undefined &&
12221
+ fieldType !== undefined &&
12222
+ fieldType !== resourceType &&
12223
+ fieldType.isSubtypeOf(resourceType)) {
12224
+ resource = resource.cast(fieldType.type());
12225
+ }
12226
+ // Build Resource from field
12274
12227
  resource = field.resourceFactory(resource);
12275
12228
  }
12229
+ else if (model._resource !== null) {
12230
+ // Apply parameters from model._resource to new resource
12231
+ model._resource.query((qs) => resource?.query((qd) => qd.restore(qs.store())));
12232
+ }
12233
+ prevField = field;
12276
12234
  }
12277
12235
  return resource;
12278
12236
  }
@@ -12861,6 +12819,52 @@ class ODataApiOptions {
12861
12819
  }
12862
12820
  }
12863
12821
 
12822
+ class ODataInclude {
12823
+ namespace;
12824
+ alias;
12825
+ reference;
12826
+ constructor(config, reference) {
12827
+ this.namespace = config.namespace;
12828
+ this.alias = config.alias;
12829
+ this.reference = reference;
12830
+ }
12831
+ configure({ options }) {
12832
+ }
12833
+ }
12834
+ class ODataIncludeAnnotation {
12835
+ termNamespace;
12836
+ qualifier;
12837
+ targetNamespace;
12838
+ reference;
12839
+ constructor(config, reference) {
12840
+ this.termNamespace = config.termNamespace;
12841
+ this.qualifier = config.qualifier;
12842
+ this.targetNamespace = config.targetNamespace;
12843
+ this.reference = reference;
12844
+ }
12845
+ configure({ options }) {
12846
+ }
12847
+ }
12848
+ class ODataReference extends ODataAnnotatable {
12849
+ api;
12850
+ uri;
12851
+ includes;
12852
+ includeAnnotations;
12853
+ constructor(config, api) {
12854
+ super(config);
12855
+ this.api = api;
12856
+ this.uri = config.uri;
12857
+ this.includes = (config.includes ?? []).map((config) => new ODataInclude(config, this));
12858
+ this.includeAnnotations = (config.includeAnnotations ?? []).map((config) => new ODataIncludeAnnotation(config, this));
12859
+ }
12860
+ configure({ options }) {
12861
+ // Configure Includes
12862
+ this.includes.forEach((include) => include.configure({ options }));
12863
+ // Configure IncludeAnnotations
12864
+ this.includeAnnotations.forEach((includeAnnotation) => includeAnnotation.configure({ options }));
12865
+ }
12866
+ }
12867
+
12864
12868
  const RESERVED_FIELD_NAMES = Object.getOwnPropertyNames(ODataModel.prototype);
12865
12869
  /**
12866
12870
  * Api abstraction for consuming OData services.
@@ -12881,8 +12885,12 @@ class ODataApi {
12881
12885
  errorHandler;
12882
12886
  // Base Parsers
12883
12887
  parsers;
12888
+ // Populate from Metadata
12889
+ populateFromMetadata;
12884
12890
  // Schemas
12885
12891
  schemas;
12892
+ // References
12893
+ references;
12886
12894
  // Models
12887
12895
  models = {};
12888
12896
  // Collections
@@ -12905,12 +12913,14 @@ class ODataApi {
12905
12913
  this.cache = config.cache;
12906
12914
  this.errorHandler = config.errorHandler;
12907
12915
  this.parsers = new Map(Object.entries(config.parsers ?? EDM_PARSERS));
12916
+ this.populateFromMetadata = config.populateFromMetadata ?? false;
12908
12917
  this.schemas = (config.schemas ?? []).map((schema) => new ODataSchema(schema, this));
12918
+ this.references = (config.references ?? []).map((reference) => new ODataReference(reference, this));
12909
12919
  this.models = (config.models ?? {});
12910
12920
  this.collections = (config.collections ?? {});
12911
12921
  }
12912
- configure(settings = {}) {
12913
- this.requester = settings.requester;
12922
+ initialize(requester) {
12923
+ this.requester = requester;
12914
12924
  this.schemas.forEach((schema) => {
12915
12925
  schema.configure({
12916
12926
  options: this.options.parserOptions,
@@ -12926,6 +12936,9 @@ class ODataApi {
12926
12936
  }
12927
12937
  }
12928
12938
  });
12939
+ return (this.populateFromMetadata) ?
12940
+ firstValueFrom(this.metadata().fetch().pipe(map(metadata => this.populate(metadata)))) :
12941
+ Promise.resolve(true);
12929
12942
  }
12930
12943
  populate(metadata) {
12931
12944
  const config = metadata.toConfig();
@@ -12937,6 +12950,7 @@ class ODataApi {
12937
12950
  options: this.options.parserOptions,
12938
12951
  });
12939
12952
  });
12953
+ return true;
12940
12954
  }
12941
12955
  fromJson(json) {
12942
12956
  const segments = ODataPathSegments.fromJson(json.segments);
@@ -13035,7 +13049,7 @@ class ODataApi {
13035
13049
  }
13036
13050
  //request(req: ODataRequest<any>): Observable<any> {
13037
13051
  request(method, resource, options) {
13038
- let req = ODataRequest.factory(this, method, resource, {
13052
+ const req = ODataRequest.factory(this, method, resource, {
13039
13053
  body: options.body,
13040
13054
  etag: options.etag,
13041
13055
  context: options.context,
@@ -13051,16 +13065,12 @@ class ODataApi {
13051
13065
  parserOptions: options.parserOptions,
13052
13066
  withCredentials: options.withCredentials,
13053
13067
  });
13054
- let res$ = this.requester !== undefined ? this.requester(req) : NEVER;
13055
- res$ = res$.pipe(map((res) => res.type === HttpEventType.Response ? ODataResponse.fromHttpResponse(req, res) : res));
13068
+ let res$ = this.handleRequest(req);
13056
13069
  if (this.errorHandler !== undefined)
13057
13070
  res$ = res$.pipe(catchError(this.errorHandler));
13058
13071
  if (options.observe === 'events') {
13059
13072
  return res$;
13060
13073
  }
13061
- if (this.cache !== undefined) {
13062
- res$ = this.handleRequest(req, res$);
13063
- }
13064
13074
  switch (options.observe || 'body') {
13065
13075
  case 'body':
13066
13076
  switch (options.responseType) {
@@ -13087,43 +13097,45 @@ class ODataApi {
13087
13097
  /**
13088
13098
  * Using the request, handle the fetching of the response
13089
13099
  * @param req The request to fetch
13090
- * @param res$ Observable of the response
13091
13100
  * @returns
13092
13101
  */
13093
- handleRequest(req, res$) {
13094
- return req.isFetch()
13095
- ? this.handleFetch(req, res$)
13096
- : req.isMutate()
13097
- ? this.handleMutate(req, res$)
13098
- : res$;
13102
+ handleRequest(req) {
13103
+ return (this.cache !== undefined && req.isFetch()) ? this.handleCacheFetch(req) :
13104
+ (this.cache !== undefined && req.isMutate()) ? this.handleCacheMutate(req) :
13105
+ this.handleRequester(req);
13099
13106
  }
13100
- handleFetch(req, res$) {
13107
+ handleRequester(req) {
13108
+ return (this.requester !== undefined ? this.requester(req) : NEVER).pipe(map((res) => res.type === HttpEventType.Response ? ODataResponse.fromHttpResponse(req, res) : res));
13109
+ }
13110
+ handleCacheFetch(req) {
13101
13111
  const policy = req.fetchPolicy;
13102
13112
  const cached = this.cache.getResponse(req);
13103
13113
  if (policy === 'no-cache') {
13104
- return res$;
13114
+ return this.handleRequester(req);
13105
13115
  }
13106
13116
  if (policy === 'cache-only') {
13107
- if (cached) {
13117
+ if (cached !== undefined) {
13108
13118
  return of(cached);
13109
13119
  }
13110
13120
  else {
13111
13121
  return throwError(() => new Error('No Cached'));
13112
13122
  }
13113
13123
  }
13114
- if (policy === 'cache-first' || policy === 'cache-and-network' || policy === 'network-only') {
13124
+ let res$ = cached !== undefined && policy !== 'network-only'
13125
+ ? policy === 'cache-and-network'
13126
+ ? this.handleRequester(req).pipe(startWith(cached))
13127
+ : of(cached)
13128
+ : this.handleRequester(req);
13129
+ if (cached === undefined && (policy === 'cache-first' || policy === 'cache-and-network' || policy === 'network-only')) {
13115
13130
  res$ = res$.pipe(tap((res) => {
13116
- if (res.options.cacheability !== 'no-store')
13131
+ if (res.options.cacheability !== 'no-store') {
13117
13132
  this.cache.putResponse(req, res);
13133
+ }
13118
13134
  }));
13119
13135
  }
13120
- return cached !== undefined && policy !== 'network-only'
13121
- ? policy === 'cache-and-network'
13122
- ? res$.pipe(startWith(cached))
13123
- : of(cached)
13124
- : res$;
13136
+ return res$;
13125
13137
  }
13126
- handleMutate(req, res$) {
13138
+ handleCacheMutate(req) {
13127
13139
  const requests = req.isBatch()
13128
13140
  ? req.resource.requests().filter((r) => r.isMutate())
13129
13141
  : [req];
@@ -13131,7 +13143,7 @@ class ODataApi {
13131
13143
  const scope = this.cache.scope(r);
13132
13144
  this.cache.forget({ scope });
13133
13145
  }
13134
- return res$;
13146
+ return this.handleRequester(req);
13135
13147
  }
13136
13148
  //# region Find by Type
13137
13149
  // Memoize
@@ -13167,6 +13179,7 @@ class ODataApi {
13167
13179
  }
13168
13180
  const enumTypes = this.schemas.reduce((acc, schema) => [...acc, ...schema.enums], []);
13169
13181
  let enumType = enumTypes.find((e) => e.type() === value);
13182
+ enumType = enumType ?? enumTypes.find((e) => e.type({ alias: true }) === value);
13170
13183
  enumType = enumType ?? enumTypes.find((e) => e.name === value);
13171
13184
  this.memo.enumTypes.set(value, enumType);
13172
13185
  return enumType;
@@ -13179,6 +13192,7 @@ class ODataApi {
13179
13192
  }
13180
13193
  const structuredTypes = this.schemas.reduce((acc, schema) => [...acc, ...schema.entities], []);
13181
13194
  let structuredType = structuredTypes.find((e) => e.type() === value);
13195
+ structuredType = structuredType ?? structuredTypes.find((e) => e.type({ alias: true }) === value);
13182
13196
  structuredType = structuredType ?? structuredTypes.find((e) => e.name === value);
13183
13197
  this.memo.structuredTypes.set(value, structuredType);
13184
13198
  return structuredType;
@@ -13203,6 +13217,19 @@ class ODataApi {
13203
13217
  (callableBindingStructuredType &&
13204
13218
  bindingStructuredType.isSubtypeOf(callableBindingStructuredType))));
13205
13219
  });
13220
+ callable =
13221
+ callable ??
13222
+ callables.find((c) => {
13223
+ const isCallableType = c.type({ alias: true }) == value;
13224
+ const callableBindingType = c.binding()?.type;
13225
+ const callableBindingStructuredType = callableBindingType !== undefined
13226
+ ? this.findStructuredType(callableBindingType)
13227
+ : undefined;
13228
+ return (isCallableType &&
13229
+ (!bindingStructuredType ||
13230
+ (callableBindingStructuredType &&
13231
+ bindingStructuredType.isSubtypeOf(callableBindingStructuredType))));
13232
+ });
13206
13233
  callable =
13207
13234
  callable ??
13208
13235
  callables.find((c) => {
@@ -13227,6 +13254,7 @@ class ODataApi {
13227
13254
  }
13228
13255
  const entitySets = this.schemas.reduce((acc, schema) => [...acc, ...schema.entitySets], []);
13229
13256
  let entitySet = entitySets.find((e) => e.type() === value);
13257
+ entitySet = entitySet ?? entitySets.find((e) => e.type({ alias: true }) === value);
13230
13258
  entitySet = entitySet ?? entitySets.find((e) => e.name === value);
13231
13259
  this.memo.entitySets.set(value, entitySet);
13232
13260
  return entitySet;
@@ -13239,6 +13267,7 @@ class ODataApi {
13239
13267
  }
13240
13268
  const singletons = this.schemas.reduce((acc, schema) => [...acc, ...schema.singletons], []);
13241
13269
  let singleton = singletons.find((e) => e.type() === value);
13270
+ singleton = singleton ?? singletons.find((e) => e.type({ alias: true }) === value);
13242
13271
  singleton = singleton ?? singletons.find((e) => e.name === value);
13243
13272
  this.memo.singletons.set(value, singleton);
13244
13273
  return singleton;
@@ -13388,8 +13417,8 @@ class ODataSettings {
13388
13417
  if (this.apis.every((c) => !c.default))
13389
13418
  this.apis[0].default = true;
13390
13419
  }
13391
- configure(settings) {
13392
- this.apis.forEach((api) => api.configure(settings));
13420
+ initialize(requester) {
13421
+ return Promise.all(this.apis.map((api) => api.initialize(requester)));
13393
13422
  }
13394
13423
  defaultApi() {
13395
13424
  return this.apis.find((c) => c.default);
@@ -13474,38 +13503,51 @@ class ODataSettings {
13474
13503
  }
13475
13504
  }
13476
13505
 
13477
- class ODataConfigLoader {
13506
+ class ODataLoader {
13478
13507
  }
13479
- class ODataConfigSyncLoader {
13508
+ class ODataSyncLoader {
13480
13509
  passedConfigs;
13481
- constructor(passedConfigs) {
13510
+ requester;
13511
+ constructor(passedConfigs, requester) {
13482
13512
  this.passedConfigs = passedConfigs;
13513
+ this.requester = requester;
13483
13514
  }
13484
- loadConfigs() {
13485
- return Array.isArray(this.passedConfigs) ? of(this.passedConfigs) : of([this.passedConfigs]);
13515
+ load() {
13516
+ const configs = Array.isArray(this.passedConfigs) ? this.passedConfigs : [this.passedConfigs];
13517
+ return Promise.resolve({ configs, requester: this.requester });
13486
13518
  }
13487
13519
  }
13488
- class ODataConfigAsyncLoader {
13520
+ class ODataAsyncLoader {
13489
13521
  configs$;
13490
- constructor(configs$) {
13522
+ requester;
13523
+ constructor(configs$, requester) {
13491
13524
  this.configs$ = configs$;
13525
+ this.requester = requester;
13492
13526
  }
13493
- loadConfigs() {
13494
- return Array.isArray(this.configs$)
13495
- ? forkJoin(this.configs$)
13496
- : this.configs$.pipe(map$1((value) => Array.isArray(value) ? value : [value]));
13527
+ load() {
13528
+ return firstValueFrom(Array.isArray(this.configs$)
13529
+ ? forkJoin(this.configs$).pipe(map$1(configs => ({ configs, requester: this.requester })))
13530
+ : this.configs$.pipe(map$1((value) => ({
13531
+ configs: Array.isArray(value) ? value : [value],
13532
+ requester: this.requester
13533
+ }))));
13497
13534
  }
13498
13535
  }
13499
13536
  class ODataMetadataLoader {
13500
13537
  sources$;
13501
13538
  baseConfigs;
13502
- constructor(sources$, baseConfigs) {
13539
+ requester;
13540
+ constructor(sources$, baseConfigs, requester) {
13503
13541
  this.sources$ = sources$;
13504
13542
  this.baseConfigs = baseConfigs;
13543
+ this.requester = requester;
13505
13544
  }
13506
- loadConfigs() {
13545
+ load() {
13507
13546
  const configs = Array.isArray(this.baseConfigs) ? this.baseConfigs : [this.baseConfigs];
13508
- return this.sources$.pipe(map$1((source) => (Array.isArray(source) ? source : [source]).map((m, i) => new ODataMetadataParser(m).metadata().toConfig(configs[i] ?? {}))));
13547
+ return firstValueFrom(this.sources$.pipe(map$1((source) => ({
13548
+ configs: (Array.isArray(source) ? source : [source]).map((m, i) => new ODataMetadataParser(m).metadata().toConfig(configs[i] ?? {})),
13549
+ requester: this.requester
13550
+ }))));
13509
13551
  }
13510
13552
  }
13511
13553
 
@@ -13523,27 +13565,18 @@ function addBody(options, body) {
13523
13565
  };
13524
13566
  }
13525
13567
  class ODataClient {
13526
- http;
13527
13568
  loader;
13528
13569
  settings;
13529
- constructor(http, loader) {
13530
- this.http = http;
13570
+ constructor(loader) {
13531
13571
  this.loader = loader;
13532
- this.loader.loadConfigs().subscribe((configs) => {
13572
+ }
13573
+ initialize() {
13574
+ return this.loader.load()
13575
+ .then(({ configs, requester }) => {
13533
13576
  this.settings = new ODataSettings(configs);
13534
- this.settings.configure({
13535
- requester: (req) => this.http.request(req.method, `${req.url}`, {
13536
- body: req.body,
13537
- context: req.context,
13538
- headers: req.headers,
13539
- observe: req.observe,
13540
- params: req.params,
13541
- reportProgress: req.reportProgress,
13542
- responseType: req.responseType,
13543
- withCredentials: req.withCredentials,
13544
- }),
13545
- });
13546
- });
13577
+ return this.settings.initialize(requester);
13578
+ })
13579
+ .then(results => results.every(v => v));
13547
13580
  }
13548
13581
  //#region Resolve Building Blocks
13549
13582
  /**
@@ -13708,12 +13741,13 @@ class ODataClient {
13708
13741
  put(resource, body, options = {}) {
13709
13742
  return this.request('PUT', resource, addBody(options, body));
13710
13743
  }
13711
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataConfigLoader }], target: i0.ɵɵFactoryTarget.Injectable });
13712
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataClient });
13744
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataClient, deps: [{ token: ODataLoader }], target: i0.ɵɵFactoryTarget.Injectable });
13745
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataClient, providedIn: 'root' });
13713
13746
  }
13714
13747
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataClient, decorators: [{
13715
- type: Injectable
13716
- }], ctorParameters: () => [{ type: i1.HttpClient }, { type: ODataConfigLoader }] });
13748
+ type: Injectable,
13749
+ args: [{ providedIn: 'root' }]
13750
+ }], ctorParameters: () => [{ type: ODataLoader }] });
13717
13751
 
13718
13752
  class ODataBaseService {
13719
13753
  client;
@@ -13996,57 +14030,86 @@ class ODataServiceFactory {
13996
14030
  return new Service(this.client, singletonName, apiNameOrEntityType);
13997
14031
  }
13998
14032
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
13999
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataServiceFactory });
14033
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataServiceFactory, providedIn: 'root' });
14000
14034
  }
14001
14035
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataServiceFactory, decorators: [{
14002
- type: Injectable
14036
+ type: Injectable,
14037
+ args: [{ providedIn: 'root' }]
14003
14038
  }], ctorParameters: () => [{ type: ODataClient }] });
14004
14039
 
14005
14040
  const ODATA_CONFIG = new InjectionToken('odata.config');
14006
- function createSyncLoader(passedConfig) {
14007
- return new ODataConfigSyncLoader(passedConfig.config);
14041
+ function defaultHttpSyncLoader(config, http) {
14042
+ return new ODataSyncLoader(config, (req) => http.request(req.method, `${req.url}`, {
14043
+ body: req.body,
14044
+ context: req.context,
14045
+ headers: req.headers,
14046
+ observe: req.observe,
14047
+ params: req.params,
14048
+ reportProgress: req.reportProgress,
14049
+ responseType: req.responseType,
14050
+ withCredentials: req.withCredentials,
14051
+ }));
14008
14052
  }
14009
14053
  // Standalone version
14010
14054
  function provideODataClient(passedConfig) {
14011
- return makeEnvironmentProviders([
14012
- { provide: ODATA_CONFIG, useValue: passedConfig },
14013
- passedConfig?.loader ?? {
14014
- provide: ODataConfigLoader,
14015
- useFactory: createSyncLoader,
14016
- deps: [ODATA_CONFIG],
14017
- },
14055
+ let providers = [
14056
+ // Make the ODATA_CONFIG available through injection
14057
+ { provide: ODATA_CONFIG, useValue: passedConfig.config ?? [] },
14058
+ // Register the startup task
14059
+ provideAppInitializer(() => inject(ODataClient).initialize()),
14018
14060
  ODataClient,
14019
14061
  ODataServiceFactory,
14020
- ]);
14062
+ ];
14063
+ if (passedConfig?.loader === undefined) {
14064
+ providers = [...providers,
14065
+ provideHttpClient(),
14066
+ {
14067
+ provide: ODataLoader,
14068
+ useFactory: defaultHttpSyncLoader,
14069
+ deps: [ODATA_CONFIG, HttpClient],
14070
+ }];
14071
+ }
14072
+ else {
14073
+ providers = [...providers, passedConfig.loader];
14074
+ }
14075
+ return makeEnvironmentProviders(providers);
14021
14076
  }
14022
14077
  // Module version
14023
14078
  class ODataModule {
14024
14079
  static forRoot(passedConfig) {
14080
+ let providers = [
14081
+ // Make the ODATA_CONFIG available through injection
14082
+ { provide: ODATA_CONFIG, useValue: passedConfig.config ?? [] },
14083
+ // Register the startup task
14084
+ provideAppInitializer(() => inject(ODataClient).initialize()),
14085
+ ODataClient,
14086
+ ODataServiceFactory,
14087
+ ];
14088
+ if (passedConfig?.loader === undefined) {
14089
+ providers = [...providers,
14090
+ provideHttpClient(),
14091
+ {
14092
+ provide: ODataLoader,
14093
+ useFactory: defaultHttpSyncLoader,
14094
+ deps: [ODATA_CONFIG, HttpClient],
14095
+ }];
14096
+ }
14097
+ else {
14098
+ providers = [...providers, passedConfig.loader];
14099
+ }
14025
14100
  return {
14026
14101
  ngModule: ODataModule,
14027
- providers: [
14028
- // Make the ODATA_CONFIG available through injection
14029
- { provide: ODATA_CONFIG, useValue: passedConfig },
14030
- // Create the loader: Either the one getting passed or a sync one
14031
- passedConfig?.loader ?? {
14032
- provide: ODataConfigLoader,
14033
- useFactory: createSyncLoader,
14034
- deps: [ODATA_CONFIG],
14035
- },
14036
- ODataClient,
14037
- ODataServiceFactory,
14038
- ],
14102
+ providers
14039
14103
  };
14040
14104
  }
14041
14105
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
14042
14106
  static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.5", ngImport: i0, type: ODataModule, imports: [CommonModule] });
14043
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [CommonModule] });
14107
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataModule, imports: [CommonModule] });
14044
14108
  }
14045
14109
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.5", ngImport: i0, type: ODataModule, decorators: [{
14046
14110
  type: NgModule,
14047
14111
  args: [{
14048
14112
  imports: [CommonModule],
14049
- providers: [ODataClient, ODataServiceFactory],
14050
14113
  }]
14051
14114
  }] });
14052
14115
 
@@ -14409,5 +14472,5 @@ class ODataIndexedDBCache extends ODataBaseCache {
14409
14472
  * Generated bundle index. Do not edit.
14410
14473
  */
14411
14474
 
14412
- export { Aggregate, ApplyExpression, ArithmeticFunctions, ArithmeticOperators, BUBBLES, Casting, CastingOperators, CollectionFunctions, ComputeExpression, ConditionalFunctions, DateAndTimeFunctions, Dates, Durations, EDM_PARSERS, EdmType, Enums, ExpandExpression, ExpandField, Expression, FieldFactory, FilterExpression, Function, GeoFunctions, GroupBy, GroupByTransformations, Grouping, GroupingOperators, Http, INCLUDE_DEEP, INCLUDE_SHALLOW, ITEM_ROOT, JsonSchemaType, Lambda, LambdaOperators, LogicalOperators, Model, ModelField, NONE_PARSER, ODATA_CONFIG, OData, ODataActionResource, ODataAnnotations, ODataApi, ODataBaseCache, ODataBaseService, ODataBatchRequest, ODataBatchResource, ODataCallable, ODataCallableParser, ODataClient, ODataCollection, ODataConfigAsyncLoader, ODataConfigLoader, ODataConfigSyncLoader, ODataCountResource, ODataEntitiesAnnotations, ODataEntityAnnotations, ODataEntityContainer, ODataEntityResource, ODataEntitySet, ODataEntitySetResource, ODataEntitySetService, ODataEntityTypeKey, ODataEnumType, ODataEnumTypeFieldParser, ODataEnumTypeParser, ODataFunctionResource, ODataFunctions, ODataInMemoryCache, ODataInStorageCache, ODataIndexedDBCache, ODataMediaResource, ODataMetadata, ODataMetadataLoader, ODataMetadataParser, ODataMetadataResource, ODataModel, ODataModelAttribute, ODataModelEvent, ODataModelEventEmitter, ODataModelEventType, ODataModelField, ODataModelOptions, ODataModelState, ODataModule, ODataNavigationPropertyResource, ODataOperators, ODataParameterParser, ODataPathSegments, ODataPathSegmentsHandler, ODataPropertyAnnotations, ODataPropertyResource, ODataQueryOptionHandler, ODataQueryOptions, ODataQueryOptionsHandler, ODataReferenceResource, ODataReferential, ODataRequest, ODataResource, ODataResponse, ODataSchema, ODataServiceFactory, ODataSettings, ODataSingleton, ODataSingletonResource, ODataSingletonService, ODataStructuredType, ODataStructuredTypeFieldParser, ODataStructuredTypeParser, ODataTransformations, ODataValueResource, Objects, Operator, OrderByExpression, OrderByField, PathSegment, QueryCustomTypes, QueryOption, RenderableFactory, SearchExpression, SearchTerm, SegmentHandler, SelectExpression, StandardAggregateMethods, StringAndCollectionFunctions, StringFunctions, Strings, Transformations, Type, TypeFunctions, Types, Urls, alias, binary, buildPathAndQuery, createSyncLoader, duration, encode, functions, isQueryCustomType, isRawType, normalizeValue, operators, pathAndParamsFromQueryOptions, pathAndParamsFromSegments, provideODataClient, raw, render, resolve, transformations };
14475
+ export { Aggregate, ApplyExpression, ArithmeticFunctions, ArithmeticOperators, BUBBLES, Casting, CastingOperators, CollectionFunctions, ComputeExpression, ConditionalFunctions, DateAndTimeFunctions, Dates, Durations, EDM_PARSERS, EdmType, Enums, ExpandExpression, ExpandField, Expression, FieldFactory, FilterExpression, Function, GeoFunctions, GroupBy, GroupByTransformations, Grouping, GroupingOperators, Http, INCLUDE_DEEP, INCLUDE_SHALLOW, ITEM_ROOT, JsonSchemaType, Lambda, LambdaOperators, LogicalOperators, Model, ModelField, NONE_PARSER, ODATA_CONFIG, OData, ODataActionResource, ODataAnnotations, ODataApi, ODataAsyncLoader, ODataBaseCache, ODataBaseService, ODataBatchRequest, ODataBatchResource, ODataCallable, ODataCallableParser, ODataClient, ODataCollection, ODataCountResource, ODataEntitiesAnnotations, ODataEntityAnnotations, ODataEntityContainer, ODataEntityResource, ODataEntitySet, ODataEntitySetResource, ODataEntitySetService, ODataEntityTypeKey, ODataEnumType, ODataEnumTypeFieldParser, ODataEnumTypeParser, ODataFunctionResource, ODataFunctions, ODataInMemoryCache, ODataInStorageCache, ODataIndexedDBCache, ODataLoader, ODataMediaResource, ODataMetadata, ODataMetadataLoader, ODataMetadataParser, ODataMetadataResource, ODataModel, ODataModelAttribute, ODataModelEvent, ODataModelEventEmitter, ODataModelEventType, ODataModelField, ODataModelOptions, ODataModelState, ODataModule, ODataNavigationPropertyResource, ODataOperators, ODataParameterParser, ODataPathSegments, ODataPathSegmentsHandler, ODataPropertyAnnotations, ODataPropertyResource, ODataQueryOptionHandler, ODataQueryOptions, ODataQueryOptionsHandler, ODataReferenceResource, ODataReferential, ODataRequest, ODataResource, ODataResponse, ODataSchema, ODataServiceFactory, ODataSettings, ODataSingleton, ODataSingletonResource, ODataSingletonService, ODataStructuredType, ODataStructuredTypeFieldParser, ODataStructuredTypeParser, ODataSyncLoader, ODataTransformations, ODataValueResource, Objects, Operator, OrderByExpression, OrderByField, PathSegment, QueryCustomTypes, QueryOption, RenderableFactory, SearchExpression, SearchTerm, SegmentHandler, SelectExpression, StandardAggregateMethods, StringAndCollectionFunctions, StringFunctions, Strings, Transformations, Type, TypeFunctions, Types, Urls, alias, binary, buildPathAndQuery, defaultHttpSyncLoader, duration, encode, functions, isQueryCustomType, isRawType, normalizeValue, operators, pathAndParamsFromQueryOptions, pathAndParamsFromSegments, provideODataClient, raw, render, resolve, transformations };
14413
14476
  //# sourceMappingURL=angular-odata.mjs.map