@smallpearl/ngx-helper 0.33.16 → 0.33.18

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.
@@ -99,7 +99,7 @@ export declare abstract class SPPagedEntityLoader<TEntity extends {
99
99
  searchParamName: import("@angular/core").InputSignal<string>;
100
100
  idKey: import("@angular/core").InputSignal<string>;
101
101
  pluralEntityName: import("@angular/core").InputSignal<string | undefined>;
102
- httpReqContext: import("@angular/core").InputSignal<[HttpContextToken<any>, any] | [[HttpContextToken<any>, any]] | undefined>;
102
+ httpReqContext: import("@angular/core").InputSignal<[HttpContextToken<any>, any] | [[HttpContextToken<any>, any]] | HttpContext | undefined>;
103
103
  httpParams: import("@angular/core").InputSignal<HttpParams | undefined>;
104
104
  protected loadRequest$: Subject<LoadRequest>;
105
105
  protected sub$: Subscription | undefined;
@@ -212,6 +212,10 @@ class SPPagedEntityLoader {
212
212
  _capitalizedEntityName = computed(() => capitalize(this.entityName()));
213
213
  _httpReqContext = computed(() => {
214
214
  let reqContext = this.httpReqContext();
215
+ if (reqContext instanceof HttpContext) {
216
+ return reqContext;
217
+ }
218
+ // Likely to be array of `(HttpContextToken, value)` pairs.
215
219
  const context = new HttpContext();
216
220
  if (reqContext && Array.isArray(reqContext)) {
217
221
  if (reqContext.length == 2 && !Array.isArray(reqContext[0])) {
@@ -1 +1 @@
1
- {"version":3,"file":"smallpearl-ngx-helper-entities.mjs","sources":["../../../../projects/smallpearl/ngx-helper/entities/src/paged-loader.ts","../../../../projects/smallpearl/ngx-helper/entities/smallpearl-ngx-helper-entities.ts"],"sourcesContent":["import {\n HttpClient,\n HttpContext,\n HttpContextToken,\n HttpParams,\n} from '@angular/common/http';\nimport { computed, Directive, inject, input } from '@angular/core';\nimport { createStore, select, setProps, withProps } from '@ngneat/elf';\nimport { getAllEntities, getEntitiesCount, getEntity, upsertEntities, withEntities } from '@ngneat/elf-entities';\nimport { getPaginationData, setPage, skipWhilePageExists, updatePaginationData, withPagination } from '@ngneat/elf-pagination';\nimport { SP_MAT_ENTITY_LIST_CONFIG, SPMatEntityListPaginator, SPPageParams } from '@smallpearl/ngx-helper/mat-entity-list';\nimport { capitalize } from 'lodash';\nimport { plural } from 'pluralize';\nimport {\n distinctUntilChanged,\n filter,\n finalize,\n Observable,\n of,\n Subject,\n Subscription,\n switchMap,\n tap\n} from 'rxjs';\n\n/**\n * A type representing an entity loader function that takes page number,\n * page size, and an optional search value and returns an Observable of\n * the response. This is similar the http.get() method of HttpClient but\n * with pagination parameters. The return value is deliberately kept generic\n * (Observable<any>) to allow flexibility in the response type. This reponse\n * will be parsed by the provided paginator's parseRequestResponse() method.\n * So as long as the function return type and paginator are compatible,\n * any response type can be handled.\n *\n * Ideally the response should contain the total number of entities available\n * at the remote and the array of entities for the requested page.\n */\nexport type SPEntityLoaderFn = (\n page: number,\n pageSize: number,\n searchValue: string | undefined\n) => Observable<any>;\n\n/**\n * Represents a request to load entities from the remote. This is used to\n * compare two requests to determine if they are equal. This is useful to\n * prevent duplicate requests being sent to the remote.\n */\nclass LoadRequest {\n constructor(\n public endpoint: string | SPEntityLoaderFn,\n public pageNumber: number,\n public searchStr: string | undefined,\n public force = false\n ) {}\n\n // Returns true if two LoadRequest objects are equal and this object's\n // 'force' is not set to true.\n isEqualToAndNotForced(prev: LoadRequest): boolean {\n // console.log(\n // `isEqualToAndNotForced - ${this.endpoint}, ${this.params.toString()} ${\n // this.force\n // }, other: ${prev.endpoint}, ${prev.params.toString()}, ${prev.force}`\n // );\n return this.force\n ? false\n : (typeof this.endpoint === 'function' ||\n this.endpoint.localeCompare(prev.endpoint as string) === 0) &&\n this.pageNumber === prev.pageNumber &&\n this.searchStr === prev.searchStr;\n }\n}\n\ntype StateProps = {\n allEntitiesLoaded: boolean;\n loading: boolean;\n loaded: boolean\n};\n\nconst DEFAULT_STATE_PROPS: StateProps = {\n allEntitiesLoaded: false,\n loading: false,\n loaded: false\n}\n\n// Default paginator implementation. This can handle dynamic-rest and DRF\n// native pagination schemes. It also has a fallback to handle response conists\n// of an array of entities.\nclass DefaultPaginator implements SPMatEntityListPaginator {\n getRequestPageParams(\n endpoint: string,\n page: number,\n pageSize: number\n ): SPPageParams {\n return {\n page: page + 1,\n pageSize,\n };\n }\n\n parseRequestResponse<\n TEntity extends { [P in IdKey]: PropertyKey },\n IdKey extends string = 'id'\n >(\n entityName: string,\n entityNamePlural: string,\n endpoint: string,\n params: SPPageParams,\n resp: any\n ) {\n if (Array.isArray(resp)) {\n return {\n total: resp.length,\n entities: resp,\n };\n }\n\n if (typeof resp === 'object') {\n const keys = Object.keys(resp);\n // Handle dynamic-rest sideloaded response\n // Rudimentary sideloaded response support. This should work for most\n // of the sideloaded responses where the main entities are stored\n // under the plural entity name key and resp['meta'] object contains\n // the total count.\n if (\n keys.includes(entityNamePlural) &&\n Array.isArray(resp[entityNamePlural])\n ) {\n let total = resp[entityNamePlural].length;\n if (\n keys.includes('meta') &&\n typeof resp['meta'] === 'object' &&\n typeof resp['meta']['total'] === 'number'\n ) {\n total = resp['meta']['total'];\n }\n return {\n total,\n entities: resp[entityNamePlural],\n };\n }\n\n // Handle django-rest-framework style response\n if (keys.includes('results') && Array.isArray(resp['results'])) {\n let total = resp['results'].length;\n if (keys.includes('count') && typeof resp['count'] === 'number') {\n total = resp['count'];\n }\n return {\n total,\n entities: resp['results'],\n };\n }\n\n // Finally, look for \"items\" key\n if (keys.includes('items') && Array.isArray(resp['items'])) {\n return {\n total: resp['items'].length,\n entities: resp['items'],\n };\n }\n }\n\n return {\n total: 0,\n entities: [],\n };\n }\n}\n\n/**\n * An abstract class that you can use wherever you would like to load entities\n * from a remote endpoint in a paged manner. Entities can be loaded in one of\n * two ways:\n *\n * 1. By providing an entityLoaderFn that takes an endpoint and HttpParams\n * and returns a Observable of entities.\n * 2. Or by providing a URL and using the default loader that uses HttpClient\n * to load entities.\n * This class uses RxJS to manage the loading of entities and provides\n * signals to track the loading state, entity count, page index, page size,\n * and whether more entities are available to load.\n *\n * How to use this class:\n *\n * 1. Dervice your component from SPPagedEntityLoader.\n * 2. After your component is initialized, call the startLoader() method to\n * get the component going. This sets up the necessary subscriptions to\n * listen for load requests. Load requests are triggered by calling the\n * loadPage() or loadNextPage() methods.\n * 3. If your component supports infinite scrolling, call loadMoreEntities()\n * method to load the next page of entities when it detects a scroll event.\n * 4. If you component needs to load a specific page (via a pagination control),\n * call the loadPage(pageNumber) method to load the specified page.\n * 5. Entities are stored in an internal entities store which is an @ngneat/elf\n * store. You can subscribe to the store's query to get the list of entities.\n * 6. When your component is destroyed, call the stopLoader() method to clean up\n * internal subscriptions.\n *\n * The class is decorated with Angular's @Directive decorator so that we can\n * use signals for the input properties and dependency injection for HttpClient.\n * There are no abstract methods as such, but the class is meant to be extended\n * by your component to provide the necessary configuration via input properties.\n * This is why it is declared as abstract.\n */\n@Directive({\n selector: '**spPagedEntityLoader**',\n})\nexport abstract class SPPagedEntityLoader<\n TEntity extends { [P in IdKey]: PropertyKey },\n IdKey extends string = 'id'\n> {\n // We cache the entities that we fetch from remote here. Cache is indexed\n // by the endpoint. Each endpoint also keeps a refCount, which is incremented\n // for each instance of the component using the same endpoint. When this\n // refcount reaches 0, the endpoint is removed from the cache.\n //\n // This mechanism is to suppress multiple fetches from the remote from the\n // same endpoint as that can occur if a form has multiple instances of\n // this component with the same url.\n static _entitiesCache = new Map<string, { refCount: number; resp: any }>();\n // cache keys for this instance\n cacheKeys = new Set<string>();\n\n // Current search parameter value. This is used to load entities\n // matching the search string.\n searchParamValue: string | undefined;\n\n //** REQUIRED ATTRIBUTES **//\n /**\n * Entity name, that is used to form the \"New { item }\" menu item if\n * inlineNew=true. This is also used as the key of the object in GET response\n * if the reponse JSON is an object (sideloaded response), where the values\n * are stored indexed by the server model name. For eg:-\n *\n * {\n * 'customers': [\n * {...},\n * {...},\n * {...},\n * ]\n * }\n */\n entityName = input.required<string>();\n url = input.required<string | SPEntityLoaderFn>();\n\n //** OPTIONAL ATTRIBUTES **//\n // Number of entities to be loaded per page from the server. This will be\n // passed to PagedEntityLoader to load entities in pages. Defaults to 50.\n // Adjust this accordingly based on the average size of your entities to\n // optimize server round-trips and memory usage.\n pageSize = input<number>(50);\n\n // Paginator for the remote entity list. This is used to determine the\n // pagination parameters for the API request. If not specified, the global\n // paginator specified in SPMatEntityListConfig will be used. If that too is\n // not specified, a default paginator will be used. Default paginator can\n // handle DRF native PageNumberPagination and dynamic-rest style pagination.\n paginator = input<SPMatEntityListPaginator>();\n\n // Search parameter name to be used in the HTTP request.\n // Defaults to 'search'. That is when a search string is specified and\n // the entire entity list has not been fetched, a fresh HTTP request is made\n // to the remote server with `?<searchParamName>=<search string>` parameter.\n searchParamName = input<string>('search');\n\n // Entity idKey, if idKey is different from the default 'id'.\n idKey = input<string>('id');\n\n // Plural entity name, used when grouping options. If not specified, it is\n // derived by pluralizing the entityName.\n pluralEntityName = input<string | undefined>(undefined); // defaults to pluralized entityName\n\n httpReqContext = input<\n [[HttpContextToken<any>, any]] | [HttpContextToken<any>, any] | undefined\n >(undefined); // defaults to empty context\n\n // Parameters to be added to the HTTP request to retrieve data from\n // remote. This won't be used if `loadFromRemoteFn` is specified.\n httpParams = input<HttpParams | undefined>(undefined); // defaults to empty params\n\n // Mechanism to default pageSize to last entities length.\n protected loadRequest$ = new Subject<LoadRequest>();\n protected sub$: Subscription | undefined;\n protected _pageSize = computed<number>(() =>\n this.pageSize() ? this.pageSize() : 50\n );\n\n protected _pluralEntityName = computed<string>(() => {\n const pluralEntityName = this.pluralEntityName();\n return pluralEntityName ? pluralEntityName : plural(this.entityName());\n });\n\n protected _capitalizedEntityName = computed<string>(() =>\n capitalize(this.entityName())\n );\n\n protected _httpReqContext = computed(() => {\n let reqContext = this.httpReqContext();\n const context = new HttpContext();\n if (reqContext && Array.isArray(reqContext)) {\n if (reqContext.length == 2 && !Array.isArray(reqContext[0])) {\n // one dimensional array of a key, value pair.\n context.set(reqContext[0], reqContext[1]);\n } else {\n reqContext.forEach(([k, v]) => context.set(k, v));\n }\n }\n return context;\n });\n\n entityListConfig = inject(SP_MAT_ENTITY_LIST_CONFIG, {\n optional: true,\n });\n protected _paginator = computed<SPMatEntityListPaginator>(() => {\n const paginator = this.paginator();\n const entityListConfigPaginator = this.entityListConfig\n ? (this.entityListConfig.paginator as SPMatEntityListPaginator)\n : undefined;\n return paginator\n ? paginator\n : entityListConfigPaginator\n ? entityListConfigPaginator\n : new DefaultPaginator();\n });\n\n // We create it here so that store member variable will have the correct\n // type. Unfortunately elf doesn't have a simple generic type that we can\n // use to declare the type of the store and then initialize it later.\n // We will recreate it in the constructor to have the correct idKey.\n protected store = createStore(\n { name: Math.random().toString(36).slice(2) },\n withEntities<TEntity, IdKey>({ idKey: 'id' as IdKey }),\n withProps<StateProps>(DEFAULT_STATE_PROPS),\n withPagination({\n initialPage: 0,\n })\n );\n\n protected http = inject(HttpClient);\n\n constructor() {}\n\n /**\n * Starts listening for load requests and processes them. Call this from your\n * component's ngOnInit() or ngAfterViewInit() method.\n */\n startLoader() {\n // Recreate store with the correct idKey. We have to do this after\n // the idKey is available from the constructor argument.\n const entities = this.store.query(getAllEntities());\n this.store = createStore(\n { name: Math.random().toString(36).slice(2) },\n withEntities<TEntity, IdKey>({\n initialValue: entities,\n idKey: this.idKey() as IdKey,\n }),\n withProps<StateProps>(DEFAULT_STATE_PROPS),\n withPagination({\n initialPage: 0,\n })\n );\n\n this.sub$ = this.loadRequest$\n .pipe(\n filter((lr) => lr.endpoint !== '' || lr.force === true),\n distinctUntilChanged((prev, current) =>\n current.isEqualToAndNotForced(prev)\n ),\n switchMap((lr: LoadRequest) => this.doActualLoad(lr))\n )\n .subscribe();\n }\n\n /**\n * Stops listening for load requests and cleans up subscriptions.\n */\n stopLoader() {\n if (this.sub$) {\n this.sub$.unsubscribe();\n this.sub$ = undefined;\n }\n // Remove references to this component's pages from the cache. If this\n // is the only component using those cached pages, they will be cleared\n // from the cache.\n this.removeFromCache();\n }\n\n hasStarted(): boolean {\n return this.sub$ !== undefined;\n }\n\n /**\n * Returns a boolean indicating whether all entities at the remote have been\n * loaded. All entities are considered loaded when there are no more entities\n * to load from the remote (that is all pages have been loaded without\n * a search filter).\n * @returns\n */\n allEntitiesLoaded(): boolean {\n return this.store.query((state) => state.allEntitiesLoaded);\n }\n\n /**\n * Returns the total number of entities at the remote as reported by the\n * server (or load fn) during each load.\n * @returns\n */\n totalEntitiesAtRemote(): number {\n return this.store.query(getPaginationData()).total;\n }\n\n /**\n * Returns number of entities currently stored in the internal store.\n * @returns\n */\n totalEntitiesCount(): number {\n return this.store.query(getEntitiesCount());\n }\n\n /**\n * Returns true if there are more entities to load from the remote.\n * This is computed based on the total entities count and the number of\n * entities loaded so far. For this method to work correctly, an initial\n * load must have been performed to get the total count from the remote.\n * @returns\n */\n hasMore(): boolean {\n const paginationData = this.store.query(getPaginationData());\n return (\n Object.keys(paginationData.pages).length * paginationData.perPage <\n paginationData.total\n );\n // return this.store.query((state) => state.hasMore);\n }\n\n /**\n * Returns true if a load operation is in progress. The load async operation\n * method turns the loading state to true when a load operation starts and\n * turns it to false when the operation completes.\n * @returns\n */\n loading(): boolean {\n return this.store.query((state) => state.loading);\n }\n\n /**\n * Returns the loading state as an Observable that emits when the state changes.\n * @returns\n */\n get loading$() {\n return this.store.pipe(\n select((state) => state.loading),\n distinctUntilChanged()\n );\n }\n\n /**\n * Boolean indicates whether the loader has completed at least one load\n * operation.\n */\n loaded(): boolean {\n return this.store.query((state) => state.loaded);\n }\n\n /**\n * Returns the endpoint URL if the loader was created with an endpoint.\n * If the loader was created with a loader function, an empty string is\n * returned.\n * @returns\n */\n endpoint(): string {\n return this.url() instanceof Function ? '' : (this.url() as string);\n }\n\n /**\n * Loads the specified page number of entities from the remote.\n * @param pageNumber\n */\n loadPage(pageNumber: number) {\n this.loadRequest$.next(\n new LoadRequest(this.url(), pageNumber, this.searchParamValue, false)\n );\n }\n\n /**\n * Returns the total number of pages available at the remote.\n * @returns\n */\n totalPages(): number {\n const paginationData = this.store.query(getPaginationData());\n return Math.ceil(paginationData.total / paginationData.perPage);\n }\n\n /**\n * Loads the next page of entities from the remote.\n *\n * @param searchParamValue Optional search parameter value. If specified\n * and is different from the current search parameter value, the internal\n * store is reset and entities are loaded from page 0 with the new search\n * parameter value. Otherwise, the next page of entities is loaded.\n */\n loadNextPage() {\n if (\n this.store.query(getPaginationData()).currentPage >= this.totalPages() &&\n this.loaded()\n ) {\n return;\n }\n\n const paginationData = this.store.query(getPaginationData());\n // console.log(`Loading page - forceRefresh: ${forceRefresh}, currentPage: ${paginationData.currentPage}...`);\n this.loadRequest$.next(\n new LoadRequest(\n this.url(),\n paginationData.currentPage,\n this.searchParamValue,\n false\n )\n );\n }\n\n // Sets the search parameter value to be used in subsequent loads.\n // If the search parameter value is different from the current value,\n // the internal store is reset to clear any previously loaded entities.\n setSearchParamValue(searchStr: string) {\n if (searchStr !== this.searchParamValue) {\n this.searchParamValue = searchStr;\n this.store.reset();\n }\n }\n\n setEntities(entities: TEntity[]) {\n this.store.update(upsertEntities(entities as any));\n }\n\n getEntities(): TEntity[] {\n return this.store.query(getAllEntities());\n }\n\n getEntity(id: TEntity[IdKey]): TEntity | undefined {\n return this.store.query(getEntity(id));\n }\n\n // Does the actual loading of entities from the remote or the loader\n // function. Once loaded, the entities are stored in the internal store and\n // pagination properties are updated.\n protected doActualLoad(lr: LoadRequest) {\n const loaderFn =\n typeof this.url() === 'function'\n ? (this.url() as SPEntityLoaderFn)\n : undefined;\n let obs: Observable<any>;\n let paramsObj: any = {};\n const pageSize = this._pageSize();\n if (loaderFn) {\n obs = (loaderFn as SPEntityLoaderFn)(\n lr.pageNumber,\n pageSize,\n lr.searchStr\n );\n paramsObj = {\n page: lr.pageNumber,\n pageSize,\n };\n if (lr.searchStr) {\n paramsObj[this.searchParamName()] = lr.searchStr || '';\n }\n } else {\n // Form the HttpParams which consists of pagination params and any\n // embedded params in the URL which doesn't conflict with the page\n // params.\n const urlParts = (this.url() as string).split('?');\n const pageParams = this._paginator().getRequestPageParams(\n urlParts[0],\n lr.pageNumber,\n pageSize\n );\n if (lr.searchStr) {\n pageParams[this.searchParamName()] = lr.searchStr || '';\n }\n let httpParams = new HttpParams({ fromObject: pageParams });\n if (this.httpParams()) {\n this.httpParams()!\n .keys()\n .forEach((key) => {\n const value = this.httpParams()!.getAll(key);\n (value || []).forEach((v) => {\n httpParams = httpParams.append(key, v);\n });\n });\n }\n if (urlParts.length > 1) {\n const embeddedParams = new HttpParams({ fromString: urlParts[1] });\n embeddedParams.keys().forEach((key) => {\n const value = embeddedParams.getAll(key);\n (value || []).forEach((v) => {\n if (!httpParams.has(key)) {\n httpParams = httpParams.append(key, v);\n }\n });\n });\n }\n const cacheKey = this.getCacheKey(urlParts[0], httpParams);\n if (this.existsInCache(cacheKey)) {\n obs = of(this.getFromCache(cacheKey));\n } else {\n obs = this.http\n .get<any>(urlParts[0], {\n context: this._httpReqContext(),\n params: httpParams,\n })\n .pipe(tap((resp) => this.addToCache(cacheKey, resp)));\n }\n\n // Convert HttpParams to JS object\n httpParams.keys().forEach((key) => {\n paramsObj[key] = httpParams.get(key);\n });\n }\n\n this.store.update(\n setProps((state) => ({\n ...state,\n loading: true,\n }))\n );\n return obs.pipe(\n // skipWhilePageExistsInCacheOrCache(cacheKey, resp),\n skipWhilePageExists(this.store, lr.pageNumber),\n tap((resp) => {\n let hasMore = false;\n\n let entities: TEntity[] = [];\n let total = 0;\n\n if (Array.isArray(resp)) {\n // If the response is an array, we assume it's the array of entities.\n // Obviously, in this case, there's no pagination and therefore\n // set the total number of entities to the length of the array.\n total = resp.length;\n entities = resp;\n } else {\n const result = this._paginator().parseRequestResponse(\n this.entityName(),\n this._pluralEntityName()!,\n this.endpoint(),\n paramsObj,\n resp\n );\n total = result.total;\n entities = result.entities as unknown as TEntity[];\n }\n\n this.store.update(\n upsertEntities(entities as any),\n setProps((state) => ({\n ...state,\n totalCount: total,\n })),\n updatePaginationData({\n total: total,\n perPage: this.pageSize(),\n lastPage: lr.pageNumber,\n currentPage: lr.pageNumber + 1,\n }),\n setPage(\n lr.pageNumber,\n entities.map((e) => (e as any)[this.idKey()])\n )\n );\n }),\n finalize(() => {\n this.store.update(\n setProps((state) => ({\n ...state,\n allEntitiesLoaded: !this.hasMore() && !this.searchParamValue,\n loading: false,\n loaded: true,\n }))\n );\n })\n );\n }\n\n private existsInCache(cacheKey: string): boolean {\n return SPPagedEntityLoader._entitiesCache.has(cacheKey);\n }\n\n private getCacheKey(url: string, params?: HttpParams): string {\n if (params) {\n return `${url}?${params.toString()}`;\n }\n return url;\n }\n\n private getFromCache(cacheKey: string): any {\n if (cacheKey && SPPagedEntityLoader._entitiesCache.has(cacheKey)) {\n return SPPagedEntityLoader._entitiesCache.get(cacheKey)?.resp;\n }\n return [];\n }\n\n addToCache(cacheKey: string, resp: any) {\n if (!SPPagedEntityLoader._entitiesCache.has(cacheKey)) {\n SPPagedEntityLoader._entitiesCache.set(cacheKey, {\n refCount: 0,\n resp,\n });\n }\n const cacheEntry = SPPagedEntityLoader._entitiesCache.get(cacheKey);\n cacheEntry!.refCount += 1;\n this.cacheKeys.add(cacheKey);\n }\n\n private removeFromCache() {\n for (const cacheKey of this.cacheKeys) {\n const cacheEntry = SPPagedEntityLoader._entitiesCache.get(cacheKey);\n if (cacheEntry) {\n cacheEntry!.refCount -= 1;\n if (cacheEntry.refCount <= 0) {\n SPPagedEntityLoader._entitiesCache.delete(cacheKey);\n }\n }\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;AA4CA;;;;AAIG;AACH,MAAM,WAAW,CAAA;AAEN,IAAA,QAAA;AACA,IAAA,UAAA;AACA,IAAA,SAAA;AACA,IAAA,KAAA;AAJT,IAAA,WAAA,CACS,QAAmC,EACnC,UAAkB,EAClB,SAA6B,EAC7B,QAAQ,KAAK,EAAA;QAHb,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAU,CAAA,UAAA,GAAV,UAAU;QACV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IAAA,EAAA,EAAA,SAAA,EAAA,EAAA,iBAAA,EAAA,WAAA,EAAA,UAAA,EAAA,WAAA,EAAA,QAAA,EAAA,IAAA,EAAA,UAAA,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,eAAA,EAAA,EAAA,iBAAA,EAAA,iBAAA,EAAA,UAAA,EAAA,iBAAA,EAAA,QAAA,EAAA,IAAA,EAAA,UAAA,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,KAAA,EAAA,EAAA,iBAAA,EAAA,OAAA,EAAA,UAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,UAAA,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,gBAAA,EAAA,EAAA,iBAAA,EAAA,kBAAA,EAAA,UAAA,EAAA,kBAAA,EAAA,QAAA,EAAA,IAAA,EAAA,UAAA,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,cAAA,EAAA,EAAA,iBAAA,EAAA,gBAAA,EAAA,UAAA,EAAA,gBAAA,EAAA,QAAA,EAAA,IAAA,EAAA,UAAA,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,UAAA,EAAA,EAAA,iBAAA,EAAA,YAAA,EAAA,UAAA,EAAA,YAAA,EAAA,QAAA,EAAA,IAAA,EAAA,UAAA,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA;;2FAAnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAHxC,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,yBAAyB;AACpC,iBAAA;;;AChND;;AAEG;;;;"}
1
+ {"version":3,"file":"smallpearl-ngx-helper-entities.mjs","sources":["../../../../projects/smallpearl/ngx-helper/entities/src/paged-loader.ts","../../../../projects/smallpearl/ngx-helper/entities/smallpearl-ngx-helper-entities.ts"],"sourcesContent":["import {\n HttpClient,\n HttpContext,\n HttpContextToken,\n HttpParams,\n} from '@angular/common/http';\nimport { computed, Directive, inject, input } from '@angular/core';\nimport { createStore, select, setProps, withProps } from '@ngneat/elf';\nimport { getAllEntities, getEntitiesCount, getEntity, upsertEntities, withEntities } from '@ngneat/elf-entities';\nimport { getPaginationData, setPage, skipWhilePageExists, updatePaginationData, withPagination } from '@ngneat/elf-pagination';\nimport { SP_MAT_ENTITY_LIST_CONFIG, SPMatEntityListPaginator, SPPageParams } from '@smallpearl/ngx-helper/mat-entity-list';\nimport { capitalize } from 'lodash';\nimport { plural } from 'pluralize';\nimport {\n distinctUntilChanged,\n filter,\n finalize,\n Observable,\n of,\n Subject,\n Subscription,\n switchMap,\n tap\n} from 'rxjs';\n\n/**\n * A type representing an entity loader function that takes page number,\n * page size, and an optional search value and returns an Observable of\n * the response. This is similar the http.get() method of HttpClient but\n * with pagination parameters. The return value is deliberately kept generic\n * (Observable<any>) to allow flexibility in the response type. This reponse\n * will be parsed by the provided paginator's parseRequestResponse() method.\n * So as long as the function return type and paginator are compatible,\n * any response type can be handled.\n *\n * Ideally the response should contain the total number of entities available\n * at the remote and the array of entities for the requested page.\n */\nexport type SPEntityLoaderFn = (\n page: number,\n pageSize: number,\n searchValue: string | undefined\n) => Observable<any>;\n\n/**\n * Represents a request to load entities from the remote. This is used to\n * compare two requests to determine if they are equal. This is useful to\n * prevent duplicate requests being sent to the remote.\n */\nclass LoadRequest {\n constructor(\n public endpoint: string | SPEntityLoaderFn,\n public pageNumber: number,\n public searchStr: string | undefined,\n public force = false\n ) {}\n\n // Returns true if two LoadRequest objects are equal and this object's\n // 'force' is not set to true.\n isEqualToAndNotForced(prev: LoadRequest): boolean {\n // console.log(\n // `isEqualToAndNotForced - ${this.endpoint}, ${this.params.toString()} ${\n // this.force\n // }, other: ${prev.endpoint}, ${prev.params.toString()}, ${prev.force}`\n // );\n return this.force\n ? false\n : (typeof this.endpoint === 'function' ||\n this.endpoint.localeCompare(prev.endpoint as string) === 0) &&\n this.pageNumber === prev.pageNumber &&\n this.searchStr === prev.searchStr;\n }\n}\n\ntype StateProps = {\n allEntitiesLoaded: boolean;\n loading: boolean;\n loaded: boolean\n};\n\nconst DEFAULT_STATE_PROPS: StateProps = {\n allEntitiesLoaded: false,\n loading: false,\n loaded: false\n}\n\n// Default paginator implementation. This can handle dynamic-rest and DRF\n// native pagination schemes. It also has a fallback to handle response conists\n// of an array of entities.\nclass DefaultPaginator implements SPMatEntityListPaginator {\n getRequestPageParams(\n endpoint: string,\n page: number,\n pageSize: number\n ): SPPageParams {\n return {\n page: page + 1,\n pageSize,\n };\n }\n\n parseRequestResponse<\n TEntity extends { [P in IdKey]: PropertyKey },\n IdKey extends string = 'id'\n >(\n entityName: string,\n entityNamePlural: string,\n endpoint: string,\n params: SPPageParams,\n resp: any\n ) {\n if (Array.isArray(resp)) {\n return {\n total: resp.length,\n entities: resp,\n };\n }\n\n if (typeof resp === 'object') {\n const keys = Object.keys(resp);\n // Handle dynamic-rest sideloaded response\n // Rudimentary sideloaded response support. This should work for most\n // of the sideloaded responses where the main entities are stored\n // under the plural entity name key and resp['meta'] object contains\n // the total count.\n if (\n keys.includes(entityNamePlural) &&\n Array.isArray(resp[entityNamePlural])\n ) {\n let total = resp[entityNamePlural].length;\n if (\n keys.includes('meta') &&\n typeof resp['meta'] === 'object' &&\n typeof resp['meta']['total'] === 'number'\n ) {\n total = resp['meta']['total'];\n }\n return {\n total,\n entities: resp[entityNamePlural],\n };\n }\n\n // Handle django-rest-framework style response\n if (keys.includes('results') && Array.isArray(resp['results'])) {\n let total = resp['results'].length;\n if (keys.includes('count') && typeof resp['count'] === 'number') {\n total = resp['count'];\n }\n return {\n total,\n entities: resp['results'],\n };\n }\n\n // Finally, look for \"items\" key\n if (keys.includes('items') && Array.isArray(resp['items'])) {\n return {\n total: resp['items'].length,\n entities: resp['items'],\n };\n }\n }\n\n return {\n total: 0,\n entities: [],\n };\n }\n}\n\n/**\n * An abstract class that you can use wherever you would like to load entities\n * from a remote endpoint in a paged manner. Entities can be loaded in one of\n * two ways:\n *\n * 1. By providing an entityLoaderFn that takes an endpoint and HttpParams\n * and returns a Observable of entities.\n * 2. Or by providing a URL and using the default loader that uses HttpClient\n * to load entities.\n * This class uses RxJS to manage the loading of entities and provides\n * signals to track the loading state, entity count, page index, page size,\n * and whether more entities are available to load.\n *\n * How to use this class:\n *\n * 1. Dervice your component from SPPagedEntityLoader.\n * 2. After your component is initialized, call the startLoader() method to\n * get the component going. This sets up the necessary subscriptions to\n * listen for load requests. Load requests are triggered by calling the\n * loadPage() or loadNextPage() methods.\n * 3. If your component supports infinite scrolling, call loadMoreEntities()\n * method to load the next page of entities when it detects a scroll event.\n * 4. If you component needs to load a specific page (via a pagination control),\n * call the loadPage(pageNumber) method to load the specified page.\n * 5. Entities are stored in an internal entities store which is an @ngneat/elf\n * store. You can subscribe to the store's query to get the list of entities.\n * 6. When your component is destroyed, call the stopLoader() method to clean up\n * internal subscriptions.\n *\n * The class is decorated with Angular's @Directive decorator so that we can\n * use signals for the input properties and dependency injection for HttpClient.\n * There are no abstract methods as such, but the class is meant to be extended\n * by your component to provide the necessary configuration via input properties.\n * This is why it is declared as abstract.\n */\n@Directive({\n selector: '**spPagedEntityLoader**',\n})\nexport abstract class SPPagedEntityLoader<\n TEntity extends { [P in IdKey]: PropertyKey },\n IdKey extends string = 'id'\n> {\n // We cache the entities that we fetch from remote here. Cache is indexed\n // by the endpoint. Each endpoint also keeps a refCount, which is incremented\n // for each instance of the component using the same endpoint. When this\n // refcount reaches 0, the endpoint is removed from the cache.\n //\n // This mechanism is to suppress multiple fetches from the remote from the\n // same endpoint as that can occur if a form has multiple instances of\n // this component with the same url.\n static _entitiesCache = new Map<string, { refCount: number; resp: any }>();\n // cache keys for this instance\n cacheKeys = new Set<string>();\n\n // Current search parameter value. This is used to load entities\n // matching the search string.\n searchParamValue: string | undefined;\n\n //** REQUIRED ATTRIBUTES **//\n /**\n * Entity name, that is used to form the \"New { item }\" menu item if\n * inlineNew=true. This is also used as the key of the object in GET response\n * if the reponse JSON is an object (sideloaded response), where the values\n * are stored indexed by the server model name. For eg:-\n *\n * {\n * 'customers': [\n * {...},\n * {...},\n * {...},\n * ]\n * }\n */\n entityName = input.required<string>();\n url = input.required<string | SPEntityLoaderFn>();\n\n //** OPTIONAL ATTRIBUTES **//\n // Number of entities to be loaded per page from the server. This will be\n // passed to PagedEntityLoader to load entities in pages. Defaults to 50.\n // Adjust this accordingly based on the average size of your entities to\n // optimize server round-trips and memory usage.\n pageSize = input<number>(50);\n\n // Paginator for the remote entity list. This is used to determine the\n // pagination parameters for the API request. If not specified, the global\n // paginator specified in SPMatEntityListConfig will be used. If that too is\n // not specified, a default paginator will be used. Default paginator can\n // handle DRF native PageNumberPagination and dynamic-rest style pagination.\n paginator = input<SPMatEntityListPaginator>();\n\n // Search parameter name to be used in the HTTP request.\n // Defaults to 'search'. That is when a search string is specified and\n // the entire entity list has not been fetched, a fresh HTTP request is made\n // to the remote server with `?<searchParamName>=<search string>` parameter.\n searchParamName = input<string>('search');\n\n // Entity idKey, if idKey is different from the default 'id'.\n idKey = input<string>('id');\n\n // Plural entity name, used when grouping options. If not specified, it is\n // derived by pluralizing the entityName.\n pluralEntityName = input<string | undefined>(undefined); // defaults to pluralized entityName\n\n httpReqContext = input<\n [[HttpContextToken<any>, any]] | [HttpContextToken<any>, any] | HttpContext | undefined\n >(undefined); // defaults to empty context\n\n // Parameters to be added to the HTTP request to retrieve data from\n // remote. This won't be used if `loadFromRemoteFn` is specified.\n httpParams = input<HttpParams | undefined>(undefined); // defaults to empty params\n\n // Mechanism to default pageSize to last entities length.\n protected loadRequest$ = new Subject<LoadRequest>();\n protected sub$: Subscription | undefined;\n protected _pageSize = computed<number>(() =>\n this.pageSize() ? this.pageSize() : 50\n );\n\n protected _pluralEntityName = computed<string>(() => {\n const pluralEntityName = this.pluralEntityName();\n return pluralEntityName ? pluralEntityName : plural(this.entityName());\n });\n\n protected _capitalizedEntityName = computed<string>(() =>\n capitalize(this.entityName())\n );\n\n protected _httpReqContext = computed(() => {\n let reqContext = this.httpReqContext();\n if (reqContext instanceof HttpContext) {\n return reqContext;\n }\n\n // Likely to be array of `(HttpContextToken, value)` pairs.\n const context = new HttpContext();\n if (reqContext && Array.isArray(reqContext)) {\n if (reqContext.length == 2 && !Array.isArray(reqContext[0])) {\n // one dimensional array of a key, value pair.\n context.set(reqContext[0], reqContext[1]);\n } else {\n reqContext.forEach(([k, v]) => context.set(k, v));\n }\n }\n return context;\n });\n\n entityListConfig = inject(SP_MAT_ENTITY_LIST_CONFIG, {\n optional: true,\n });\n protected _paginator = computed<SPMatEntityListPaginator>(() => {\n const paginator = this.paginator();\n const entityListConfigPaginator = this.entityListConfig\n ? (this.entityListConfig.paginator as SPMatEntityListPaginator)\n : undefined;\n return paginator\n ? paginator\n : entityListConfigPaginator\n ? entityListConfigPaginator\n : new DefaultPaginator();\n });\n\n // We create it here so that store member variable will have the correct\n // type. Unfortunately elf doesn't have a simple generic type that we can\n // use to declare the type of the store and then initialize it later.\n // We will recreate it in the constructor to have the correct idKey.\n protected store = createStore(\n { name: Math.random().toString(36).slice(2) },\n withEntities<TEntity, IdKey>({ idKey: 'id' as IdKey }),\n withProps<StateProps>(DEFAULT_STATE_PROPS),\n withPagination({\n initialPage: 0,\n })\n );\n\n protected http = inject(HttpClient);\n\n constructor() {}\n\n /**\n * Starts listening for load requests and processes them. Call this from your\n * component's ngOnInit() or ngAfterViewInit() method.\n */\n startLoader() {\n // Recreate store with the correct idKey. We have to do this after\n // the idKey is available from the constructor argument.\n const entities = this.store.query(getAllEntities());\n this.store = createStore(\n { name: Math.random().toString(36).slice(2) },\n withEntities<TEntity, IdKey>({\n initialValue: entities,\n idKey: this.idKey() as IdKey,\n }),\n withProps<StateProps>(DEFAULT_STATE_PROPS),\n withPagination({\n initialPage: 0,\n })\n );\n\n this.sub$ = this.loadRequest$\n .pipe(\n filter((lr) => lr.endpoint !== '' || lr.force === true),\n distinctUntilChanged((prev, current) =>\n current.isEqualToAndNotForced(prev)\n ),\n switchMap((lr: LoadRequest) => this.doActualLoad(lr))\n )\n .subscribe();\n }\n\n /**\n * Stops listening for load requests and cleans up subscriptions.\n */\n stopLoader() {\n if (this.sub$) {\n this.sub$.unsubscribe();\n this.sub$ = undefined;\n }\n // Remove references to this component's pages from the cache. If this\n // is the only component using those cached pages, they will be cleared\n // from the cache.\n this.removeFromCache();\n }\n\n hasStarted(): boolean {\n return this.sub$ !== undefined;\n }\n\n /**\n * Returns a boolean indicating whether all entities at the remote have been\n * loaded. All entities are considered loaded when there are no more entities\n * to load from the remote (that is all pages have been loaded without\n * a search filter).\n * @returns\n */\n allEntitiesLoaded(): boolean {\n return this.store.query((state) => state.allEntitiesLoaded);\n }\n\n /**\n * Returns the total number of entities at the remote as reported by the\n * server (or load fn) during each load.\n * @returns\n */\n totalEntitiesAtRemote(): number {\n return this.store.query(getPaginationData()).total;\n }\n\n /**\n * Returns number of entities currently stored in the internal store.\n * @returns\n */\n totalEntitiesCount(): number {\n return this.store.query(getEntitiesCount());\n }\n\n /**\n * Returns true if there are more entities to load from the remote.\n * This is computed based on the total entities count and the number of\n * entities loaded so far. For this method to work correctly, an initial\n * load must have been performed to get the total count from the remote.\n * @returns\n */\n hasMore(): boolean {\n const paginationData = this.store.query(getPaginationData());\n return (\n Object.keys(paginationData.pages).length * paginationData.perPage <\n paginationData.total\n );\n // return this.store.query((state) => state.hasMore);\n }\n\n /**\n * Returns true if a load operation is in progress. The load async operation\n * method turns the loading state to true when a load operation starts and\n * turns it to false when the operation completes.\n * @returns\n */\n loading(): boolean {\n return this.store.query((state) => state.loading);\n }\n\n /**\n * Returns the loading state as an Observable that emits when the state changes.\n * @returns\n */\n get loading$() {\n return this.store.pipe(\n select((state) => state.loading),\n distinctUntilChanged()\n );\n }\n\n /**\n * Boolean indicates whether the loader has completed at least one load\n * operation.\n */\n loaded(): boolean {\n return this.store.query((state) => state.loaded);\n }\n\n /**\n * Returns the endpoint URL if the loader was created with an endpoint.\n * If the loader was created with a loader function, an empty string is\n * returned.\n * @returns\n */\n endpoint(): string {\n return this.url() instanceof Function ? '' : (this.url() as string);\n }\n\n /**\n * Loads the specified page number of entities from the remote.\n * @param pageNumber\n */\n loadPage(pageNumber: number) {\n this.loadRequest$.next(\n new LoadRequest(this.url(), pageNumber, this.searchParamValue, false)\n );\n }\n\n /**\n * Returns the total number of pages available at the remote.\n * @returns\n */\n totalPages(): number {\n const paginationData = this.store.query(getPaginationData());\n return Math.ceil(paginationData.total / paginationData.perPage);\n }\n\n /**\n * Loads the next page of entities from the remote.\n *\n * @param searchParamValue Optional search parameter value. If specified\n * and is different from the current search parameter value, the internal\n * store is reset and entities are loaded from page 0 with the new search\n * parameter value. Otherwise, the next page of entities is loaded.\n */\n loadNextPage() {\n if (\n this.store.query(getPaginationData()).currentPage >= this.totalPages() &&\n this.loaded()\n ) {\n return;\n }\n\n const paginationData = this.store.query(getPaginationData());\n // console.log(`Loading page - forceRefresh: ${forceRefresh}, currentPage: ${paginationData.currentPage}...`);\n this.loadRequest$.next(\n new LoadRequest(\n this.url(),\n paginationData.currentPage,\n this.searchParamValue,\n false\n )\n );\n }\n\n // Sets the search parameter value to be used in subsequent loads.\n // If the search parameter value is different from the current value,\n // the internal store is reset to clear any previously loaded entities.\n setSearchParamValue(searchStr: string) {\n if (searchStr !== this.searchParamValue) {\n this.searchParamValue = searchStr;\n this.store.reset();\n }\n }\n\n setEntities(entities: TEntity[]) {\n this.store.update(upsertEntities(entities as any));\n }\n\n getEntities(): TEntity[] {\n return this.store.query(getAllEntities());\n }\n\n getEntity(id: TEntity[IdKey]): TEntity | undefined {\n return this.store.query(getEntity(id));\n }\n\n // Does the actual loading of entities from the remote or the loader\n // function. Once loaded, the entities are stored in the internal store and\n // pagination properties are updated.\n protected doActualLoad(lr: LoadRequest) {\n const loaderFn =\n typeof this.url() === 'function'\n ? (this.url() as SPEntityLoaderFn)\n : undefined;\n let obs: Observable<any>;\n let paramsObj: any = {};\n const pageSize = this._pageSize();\n if (loaderFn) {\n obs = (loaderFn as SPEntityLoaderFn)(\n lr.pageNumber,\n pageSize,\n lr.searchStr\n );\n paramsObj = {\n page: lr.pageNumber,\n pageSize,\n };\n if (lr.searchStr) {\n paramsObj[this.searchParamName()] = lr.searchStr || '';\n }\n } else {\n // Form the HttpParams which consists of pagination params and any\n // embedded params in the URL which doesn't conflict with the page\n // params.\n const urlParts = (this.url() as string).split('?');\n const pageParams = this._paginator().getRequestPageParams(\n urlParts[0],\n lr.pageNumber,\n pageSize\n );\n if (lr.searchStr) {\n pageParams[this.searchParamName()] = lr.searchStr || '';\n }\n let httpParams = new HttpParams({ fromObject: pageParams });\n if (this.httpParams()) {\n this.httpParams()!\n .keys()\n .forEach((key) => {\n const value = this.httpParams()!.getAll(key);\n (value || []).forEach((v) => {\n httpParams = httpParams.append(key, v);\n });\n });\n }\n if (urlParts.length > 1) {\n const embeddedParams = new HttpParams({ fromString: urlParts[1] });\n embeddedParams.keys().forEach((key) => {\n const value = embeddedParams.getAll(key);\n (value || []).forEach((v) => {\n if (!httpParams.has(key)) {\n httpParams = httpParams.append(key, v);\n }\n });\n });\n }\n const cacheKey = this.getCacheKey(urlParts[0], httpParams);\n if (this.existsInCache(cacheKey)) {\n obs = of(this.getFromCache(cacheKey));\n } else {\n obs = this.http\n .get<any>(urlParts[0], {\n context: this._httpReqContext(),\n params: httpParams,\n })\n .pipe(tap((resp) => this.addToCache(cacheKey, resp)));\n }\n\n // Convert HttpParams to JS object\n httpParams.keys().forEach((key) => {\n paramsObj[key] = httpParams.get(key);\n });\n }\n\n this.store.update(\n setProps((state) => ({\n ...state,\n loading: true,\n }))\n );\n return obs.pipe(\n // skipWhilePageExistsInCacheOrCache(cacheKey, resp),\n skipWhilePageExists(this.store, lr.pageNumber),\n tap((resp) => {\n let hasMore = false;\n\n let entities: TEntity[] = [];\n let total = 0;\n\n if (Array.isArray(resp)) {\n // If the response is an array, we assume it's the array of entities.\n // Obviously, in this case, there's no pagination and therefore\n // set the total number of entities to the length of the array.\n total = resp.length;\n entities = resp;\n } else {\n const result = this._paginator().parseRequestResponse(\n this.entityName(),\n this._pluralEntityName()!,\n this.endpoint(),\n paramsObj,\n resp\n );\n total = result.total;\n entities = result.entities as unknown as TEntity[];\n }\n\n this.store.update(\n upsertEntities(entities as any),\n setProps((state) => ({\n ...state,\n totalCount: total,\n })),\n updatePaginationData({\n total: total,\n perPage: this.pageSize(),\n lastPage: lr.pageNumber,\n currentPage: lr.pageNumber + 1,\n }),\n setPage(\n lr.pageNumber,\n entities.map((e) => (e as any)[this.idKey()])\n )\n );\n }),\n finalize(() => {\n this.store.update(\n setProps((state) => ({\n ...state,\n allEntitiesLoaded: !this.hasMore() && !this.searchParamValue,\n loading: false,\n loaded: true,\n }))\n );\n })\n );\n }\n\n private existsInCache(cacheKey: string): boolean {\n return SPPagedEntityLoader._entitiesCache.has(cacheKey);\n }\n\n private getCacheKey(url: string, params?: HttpParams): string {\n if (params) {\n return `${url}?${params.toString()}`;\n }\n return url;\n }\n\n private getFromCache(cacheKey: string): any {\n if (cacheKey && SPPagedEntityLoader._entitiesCache.has(cacheKey)) {\n return SPPagedEntityLoader._entitiesCache.get(cacheKey)?.resp;\n }\n return [];\n }\n\n addToCache(cacheKey: string, resp: any) {\n if (!SPPagedEntityLoader._entitiesCache.has(cacheKey)) {\n SPPagedEntityLoader._entitiesCache.set(cacheKey, {\n refCount: 0,\n resp,\n });\n }\n const cacheEntry = SPPagedEntityLoader._entitiesCache.get(cacheKey);\n cacheEntry!.refCount += 1;\n this.cacheKeys.add(cacheKey);\n }\n\n private removeFromCache() {\n for (const cacheKey of this.cacheKeys) {\n const cacheEntry = SPPagedEntityLoader._entitiesCache.get(cacheKey);\n if (cacheEntry) {\n cacheEntry!.refCount -= 1;\n if (cacheEntry.refCount <= 0) {\n SPPagedEntityLoader._entitiesCache.delete(cacheKey);\n }\n }\n }\n }\n}\n","/**\n * Generated bundle index.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AAA,EAAA,UAAA,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA;;2FAAnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAHxC,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,yBAAyB;AACpC,iBAAA;;;AChND;;AAEG;;;;"}
@@ -431,16 +431,16 @@ class SPMatEntityCrudComponent extends SPMatEntityListComponent {
431
431
  */
432
432
  refreshAfterEdit = input('none');
433
433
  /**
434
- * HttpContext for crud requests - list, create, retrieve, update & delete.
435
- * The value can be an object where the property names reflect the CRUD
436
- * methods with each of these keys taking
437
- * `[[HttpContextToken<any>, any]] | [HttpContextToken<any>, any]` as its
438
- * value. This object has a special key 'crud', which if given a value for,
439
- * would be used for all CRUD requests (CREATE|READ|UPDATE|DELETE).
434
+ * HttpContext for crud requests - `create`, `retrieve`, `update` & `delete`.
435
+ * Note that HttpContext for `list` operation should be set using the
436
+ * `httpReqContext` property inherited from SPMatEntityListComponent.
437
+ * The value of the property is an object where the key names reflect the CRUD
438
+ * operation with each of these keys expected to have a value of type
439
+ * `[[HttpContextToken<any>, any]] | [HttpContextToken<any>, any] | HttpContext`.
440
440
  *
441
- * Alternatively the property can be set a
442
- * `[[HttpContextToken<any>, any]] | [HttpContextToken<any>, any]` as its
443
- * value, in which case the same context would be used for all HTTP requests.
441
+ * Alternatively the property value can be set to
442
+ * `[[HttpContextToken<any>, any]] | [HttpContextToken<any>, any] | HttpContext`,
443
+ * in which case the same context would be used for all HTTP requests.
444
444
  */
445
445
  crudHttpReqContext = input();
446
446
  /**
@@ -1009,30 +1009,59 @@ class SPMatEntityCrudComponent extends SPMatEntityListComponent {
1009
1009
  }
1010
1010
  }
1011
1011
  getCrudReqHttpContext(op) {
1012
+ /**
1013
+ * Converts array of HttpContextToken key, value pairs to HttpContext
1014
+ * object in argument 'context'.
1015
+ * @param context HTTP context to which the key, value pairs are added
1016
+ * @param reqContext HttpContextToken key, value pairs array
1017
+ * @returns HttpContext object, with the key, value pairs added. This is
1018
+ * the same object as the 'context' argument.
1019
+ */
1012
1020
  const contextParamToHttpContext = (context, reqContext) => {
1013
- if (reqContext.length == 2 && !Array.isArray(reqContext[0])) {
1021
+ if (reqContext instanceof HttpContext) {
1022
+ // reqContext is already an HttpContext object.
1023
+ for (const k of reqContext.keys()) {
1024
+ context.set(k, reqContext.get(k));
1025
+ }
1026
+ }
1027
+ else if (reqContext.length == 2 && !Array.isArray(reqContext[0])) {
1014
1028
  // one dimensional array of a key, value pair.
1015
1029
  context.set(reqContext[0], reqContext[1]);
1016
1030
  }
1017
1031
  else {
1018
1032
  reqContext.forEach(([k, v]) => context.set(k, v));
1019
1033
  }
1034
+ return context;
1020
1035
  };
1021
1036
  let context = new HttpContext();
1037
+ // HttpContext for crud operations are taken from either the global httpReqContext
1038
+ // or from the crudHttpReqContext, with the latter taking precedence.
1022
1039
  const crudHttpReqContext = this.crudHttpReqContext()
1023
1040
  ? this.crudHttpReqContext()
1024
1041
  : this.httpReqContext();
1025
1042
  if (crudHttpReqContext) {
1026
- if (Array.isArray(crudHttpReqContext)) {
1027
- // Same HttpContext for all crud requests
1028
- contextParamToHttpContext(context, crudHttpReqContext);
1043
+ if (crudHttpReqContext instanceof HttpContext) {
1044
+ // crudHttpReqContext is an object of type HttpContext. Which means
1045
+ // the same context is to be applied to all crud requests.
1046
+ for (const k of crudHttpReqContext.keys()) {
1047
+ context.set(k, crudHttpReqContext.get(k));
1048
+ }
1029
1049
  }
1030
- else if (typeof crudHttpReqContext === 'object' &&
1031
- op &&
1032
- crudHttpReqContext[op]) {
1033
- contextParamToHttpContext(context, crudHttpReqContext[op]);
1050
+ else {
1051
+ if (Array.isArray(crudHttpReqContext)) {
1052
+ // Same HttpContext for all crud requests. Being an array, it must
1053
+ // be an array of HttpContextToken key, value pairs.
1054
+ contextParamToHttpContext(context, crudHttpReqContext);
1055
+ }
1056
+ else if (typeof crudHttpReqContext === 'object' && op &&
1057
+ Object.keys(crudHttpReqContext).find((k) => k === op)) {
1058
+ // HttpContext specific to this crud operation, 'create'|'retrieve'|'update'|'delete'
1059
+ contextParamToHttpContext(context, crudHttpReqContext[op]);
1060
+ }
1034
1061
  }
1035
1062
  }
1063
+ // Add standard SP_MAT_ENTITY_CRUD_HTTP_CONTEXT info which is set for all
1064
+ // HTTP requests made by this component.
1036
1065
  context.set(SP_MAT_ENTITY_CRUD_HTTP_CONTEXT, {
1037
1066
  entityName: this.entityName(),
1038
1067
  entityNamePlural: this._entityNamePlural(),