All files / src/storage datasource.ts

100% Statements 219/219
100% Branches 93/93
100% Functions 57/57
100% Lines 213/213

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 77021x 21x 21x 21x           21x       136x                   136x         136x         136x         136x         136x         136x         136x         136x         136x         136x         136x                   136x         136x         136x         136x                                 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x   136x 136x 136x       124x 124x       1x     136x   136x   136x           167x       253x 253x 3x               686x       238x 87x 87x 1x                 96x       97x 52x 52x 1x                     237x 79x 79x 79x 79x 79x 79x                   79x 79x 79x                 151x 151x 75x 18x     151x                   79x 3x   76x                   79x                   79x 15x   64x                   79x 7x   72x             136x 62x                 72x               72x               134x                             72x 72x                                                       6x 6x 3x 1x   2x 2x 2x 2x     6x                   5x 3x 3x   2x                 5x 5x                 3x 3x 6x 4x   2x       3x               1x 1x               12x 12x 12x 12x 10x 10x 10x 10x 6x 1x 1x     10x 10x           12x                 11x                   3x 3x 2x   3x                   11x 11x 6x   11x                   3x 3x 3x 2x   1x   3x                 3x 3x 2x   3x                 8x 8x               2x 2x               16x 6x   16x               30x 30x 30x                 2x 2x   2x   1x                 8x               7x 7x 6x 6x                 2x 2x                 4x 4x 2x                   11x             36x 36x 7x 15x           97x 92x 92x 8x   5x 2x   2x 1x     89x                       1879x 1879x 1x 1878x 841x 841x   1879x             248x             5x                                           126x 75x 2x 2x     73x     124x                 34x 34x 65x   65x   34x 34x   34x 34x   34x           136x           3x             100x   100x                 2x      
import { AccessorManager, IAccessorManager } from '../accessor';
import { Config } from '../config';
import { Event } from '../event';
import { IDictionary, URL, Utils } from '../utils';
import { Callback, IDatasource, IDatasourceEvents, Order } from './interfaces';
 
/**
 * Base class used to define data sources and perform CRUD methods.
 */
export abstract class Datasource implements IDatasource {
	/**
	 * Data collection
	 */
	public data: IDictionary<any>[] = [];
 
	/**
	 * Preserves configured limit
	 */
	public defaultLimit: number;
 
	/**
	 * Filter value
	 */
	public filter: IDictionary<any> = {};
 
	/**
	 * Defines if the datasource will load all data or do a pagination using limit property
	 */
	public loadAll = false;
 
	/**
	 * Defines if the datasource are loading
	 */
	public loading = false;
 
	/**
	 * Order value
	 */
	public order: string[] = [];
 
	/**
	 * Page value
	 */
	public page = 1;
 
	/**
	 * Search value
	 */
	public search = '';
 
	/**
	 * Defines which row column should be able to search
	 */
	public searchIn: string[] = [];
 
	/**
	 * All selected rows
	 */
	public selectedRows: IDictionary<any>[] = [];
 
	/**
	 * The column that should be used as unique key
	 */
	public uniqueKey = 'id';
 
	/**
	 * Page selected rows
	 */
	public visibleSelectedRows: IDictionary<any>[] = [];
 
	/**
	 * Defines if the datasource should watch URL changes for updates
	 */
	public watchUrl = false;
 
	/**
	 * Stores the datasource request error
	 */
	public error: any;
 
	/**
	 * Events registered to the component.
	 */
	public events: IDatasourceEvents = {};
 
	/**
	 * Filter applied flag
	 */
	protected filterApplied = '';
 
	/**
	 * Datasource first page
	 */
	protected firstPage = 1;
 
	/**
	 * URL reserved keys
	 */
	protected reservedKeys: IDictionary<boolean> = {
		page: true,
		limit: true,
		order: true,
		filter: true,
		in: true,
		search: true,
		search_in: true,
	};
 
	private accessorManager!: IAccessorManager;
 
	/**
	 * Create a Datasource
	 * @param datasource Datasource structure
	 */
	constructor(datasource: IDatasource) {
		this.accessorManager = new AccessorManager();
		this.watchUrl = this.getInitValue('watchUrl', datasource.watchUrl, this.watchUrl);
		this.currentRow = this.getInitValue('currentRow', datasource.currentRow, this.currentRow);
		this.data = this.getInitValue('data', datasource.data, this.data);
		this.limit = this.getInitValue('limit', Number(datasource.limit) || datasource.limit, this.limit);
		this.events = Event.factory(datasource.events || this.events);
		this.loadAll = this.getInitValue('loadAll', datasource.loadAll, this.loadAll);
		this.loading = this.getInitValue('loading', datasource.loading, this.loading);
		this.searchIn = this.getInitValue('searchIn', datasource.searchIn, this.searchIn);
		this.uniqueKey = this.getInitValue('uniqueKey', datasource.uniqueKey, this.uniqueKey);
		this.filter = this.getInitValue('filter', datasource.filter, this.filter);
		this.order = this.getInitValue('order', datasource.order, this.order);
		this.search = this.getInitValue('search', datasource.search, this.search);
		this.page = this.getInitValue('page', Number(datasource.page) || datasource.page, this.page);
 
		this.defaultLimit = this.limit;
		this.updateInternalProperties(datasource);
		this.updateUrlQueryString();
	}
 
	public initialize(): Promise<void> | void {
		this.createAccessors();
		this.createObjAccessors(this.filter, 'filter');
	}
 
	public destroy() {
		return;
	}
 
	protected currentRowValue: IDictionary<any> = {};
 
	protected limitValue: number = Config.datasourceLimit || 10;
 
	protected totalValue = 0;
 
	/**
	 * Current (selected) row
	 */
	get currentRow() {
		return this.currentRowValue;
	}
 
	set currentRow(value: IDictionary<any>) {
		this.currentRowValue = value;
		if (this.events.onChangeCurrentRow) {
			this.events.onChangeCurrentRow({ component: this });
		}
	}
 
	/**
	 * Limit value
	 */
	get limit() {
		return this.limitValue;
	}
 
	set limit(value: number) {
		if (this.limitValue !== value) {
			this.limitValue = value;
			if (this.events.onChangePagination) {
				this.events.onChangePagination({ component: this });
			}
		}
	}
 
	/**
	 * Number of lines
	 */
	get total() {
		return this.totalValue;
	}
 
	set total(value: number) {
		if (this.totalValue !== value) {
			this.totalValue = value;
			if (this.events.onChangePagination) {
				this.events.onChangePagination({ component: this });
			}
		}
	}
 
	/**
	 * Updates all properties affected by URL if the datasource is configured to
	 * watch url changes
	 * @param datasource Datasource structure
	 */
	protected updateInternalProperties(datasource: IDatasource = {}) {
		if (!this.watchUrl) return;
		const queryString = URL.getParsedQueryStringFromUrl();
		this.filter = this.getFilter(queryString, datasource.filter);
		this.order = this.getOrder(queryString.order, datasource.order);
		this.search = this.getSearch(queryString.search, datasource.search);
		this.page = this.getPage(queryString.page, Number(datasource.page));
		this.limit = this.getLimit(queryString.limit, Number(datasource.limit));
	}
 
	/**
	 * Retrieves filter value from url and datasource config
	 * @param datasource Datasource config
	 * @param queryString Query string values
	 * @returns Filter value
	 */
	protected getFilter(queryString: IDictionary<any>, filter: IDictionary<any> = {}): IDictionary<any> {
		this.filterApplied = queryString.filter || '';
		const urlFilter = this.getFilterFromUrl(queryString);
		return this.filterApplied ? urlFilter : { ...filter, ...urlFilter };
	}
 
	/**
	 * Retrieves filter from url, ignoring reserved keys
	 * @param queryString Query string values
	 * @returns Filter from url
	 */
	protected getFilterFromUrl(queryString: IDictionary<any>) {
		const filter: IDictionary<any> = {};
		for (const key in queryString) {
			if (!this.reservedKeys[key]) {
				filter[key] = queryString[key];
			}
		}
		return filter;
	}
 
	/**
	 * Retrieves order value from url and datasource config
	 * @param order Query string order value
	 * @param localOrder Datasource order value
	 * @returns Order value
	 */
	protected getOrder(urlOrder?: string | string[], datasourceOrder: string[] = []) {
		if (urlOrder) {
			return Array.isArray(urlOrder) ? urlOrder : [urlOrder];
		}
		return datasourceOrder;
	}
 
	/**
	 * Retrieves search value from url and datasource config
	 * @param urlSearch Query string search value
	 * @param datasourceSearch Datasource search value
	 * @returns Search value
	 */
	protected getSearch(urlSearch?: string, datasourceSearch = '') {
		return urlSearch || datasourceSearch;
	}
 
	/**
	 * Retrieves page value from url and datasource config
	 * @param urlPage Query string page value
	 * @param datasourcePage Datasource page value
	 * @returns Page value
	 */
	protected getPage(urlPage?: string | number, datasourcePage?: number): number {
		if (urlPage) {
			return +urlPage;
		}
		return datasourcePage || this.firstPage;
	}
 
	/**
	 * Retrieves Limit value from url and datasource config
	 * @param urlLimit Query string limit value
	 * @param datasourceLimit Datasource limit value
	 * @returns Limit value
	 */
	protected getLimit(urlLimit?: string | number, datasourceLimit?: number): number {
		if (urlLimit) {
			return Number(urlLimit);
		}
		return datasourceLimit || this.defaultLimit;
	}
 
	/**
	 * Updates url query string
	 */
	protected updateUrlQueryString() {
		if (this.watchUrl && this.urlHasChanged()) {
			URL.replaceQueryString(this.getQueryStringValues());
		}
	}
 
	/**
	 * Checks if the query string value has changed
	 * @returns URL has changed
	 */
	public urlHasChanged(): boolean {
		return this.watchUrl && this.getUrlQueryString() !== this.getDatasourceAsQueryString();
	}
 
	/**
	 * Retrieves a query string from datasource values
	 * @returns Datasource values as query string
	 */
	protected getDatasourceAsQueryString() {
		return URL.getFormattedQueryString(this.getQueryStringValues());
	}
 
	/**
	 * Retrieves an object with all properties that affect the url
	 * @returns Query string object value
	 */
	protected getQueryStringValues(): IDictionary<any> {
		return {
			page: this.page.toString(),
			limit: this.limit.toString(),
			order: this.order,
			search: this.search ? this.search : undefined,
			filter: this.filterApplied || undefined,
			...this.filter,
		};
	}
 
	/**
	 * Retrieves current query string with default values
	 * @returns Query string with defaults
	 */
	protected getUrlQueryString() {
		const query = URL.getParsedQueryStringFromUrl();
		return URL.getFormattedQueryString({
			page: query.page || this.firstPage.toString(),
			limit: query.limit || this.defaultLimit.toString(),
			order: query.order || [],
			search: query.search || undefined,
			filter: query.filter || undefined,
			...this.getFilterFromUrl(query),
		});
	}
 
	public abstract get(): Promise<any>;
 
	public abstract post(row: IDictionary<any>): Promise<any>;
 
	public abstract put(row: IDictionary<any>): Promise<any>;
 
	public abstract delete(row?: IDictionary<any>): Promise<any>;
 
	public abstract updateData(data: IDictionary<any>[]): Promise<any>;
 
	public abstract getLoadedData(): IDictionary[];
 
	/**
	 * Updates search value
	 * @param search Search value
	 * @returns Promise with data collection
	 */
	public setSearch(search: string) {
		this.search = search;
		if (this.watchUrl) {
			if (search) {
				URL.updateQueryString({ search });
			} else {
				const query = URL.getParsedQueryStringFromUrl();
				const map = Object.create(null);
				delete map[query.search];
				URL.setQueryString(query);
			}
		}
		return this.get();
	}
 
	/**
	 * Adds a new filter position or replace if exists
	 * @param column Filter column name
	 * @param value Filter value
	 * @returns Promise with data collection
	 */
	public addFilter(column: string, value: any) {
		if (this.isValidFilterValue(column, value)) {
			this.filter[column] = value;
			return this.updateFilter();
		}
		return this.removeFilter(column);
	}
 
	/**
	 * Removes a filter position
	 * @param column Filter column name
	 * @returns Promise with data collection
	 */
	public removeFilter(column: string) {
		delete this.filter[column];
		return this.updateFilter();
	}
 
	/**
	 * Sets new filter value
	 * @param filter Filter value
	 * @returns Promise with data collection
	 */
	public setFilter(filter: IDictionary<any>) {
		this.filter = {};
		for (const column in filter) {
			if (this.isValidFilterValue(column, filter[column])) {
				this.filter[column] = filter[column];
			} else {
				delete this.filter[column];
			}
		}
 
		return this.updateFilter();
	}
 
	/**
	 * Clears filter value
	 * @returns Promise with data collection
	 */
	public clearFilter() {
		this.filter = {};
		return this.updateFilter();
	}
 
	/**
	 * Resets page and selected rows and tries to update the url
	 * @returns Promise with data collection
	 */
	protected async updateFilter() {
		this.page = this.firstPage;
		this.selectedRows = [];
		this.visibleSelectedRows = [];
		if (this.watchUrl) {
			this.filterApplied = 'applied';
			const query = URL.getParsedQueryStringFromUrl();
			const reservedValues: IDictionary<any> = {};
			for (const key in query) {
				if (this.reservedKeys[key]) {
					reservedValues[key] = query[key];
					delete query[key];
				}
			}
			reservedValues.page = this.firstPage;
			URL.setQueryString({
				...reservedValues,
				...this.filter,
				filter: this.filterApplied,
			});
		}
		return this.get();
	}
 
	/**
	 * Checks if a filter value is valid
	 * @param value Filter value
	 * @returns Is valid filter value
	 */
	protected isValidFilterValue(column: string, value: string | number | any[]) {
		return !this.reservedKeys[column] && value !== '' && value != null;
	}
 
	/**
	 * Updates datasource limit
	 * @param limit Limit value
	 * @param replaceUrl Should replace or push url
	 * @returns Promise with data collection
	 */
	public async setLimit(limit: number, replaceUrl = false) {
		this.limit = limit;
		if (this.watchUrl) {
			URL.updateQueryString({ limit }, replaceUrl);
		}
		return this.reloadAndUpdateSelectedRows();
	}
 
	/**
	 * Updates datasource page
	 * @param page Page value
	 * @param replaceUrl Should replace or push url
	 * @returns Promise with data collection
	 */
	public async setPage(page: number, replaceUrl = false) {
		this.page = page;
		if (this.watchUrl) {
			URL.updateQueryString({ page }, replaceUrl);
		}
		return this.reloadAndUpdateSelectedRows();
	}
 
	/**
	 * Adds or updates an order for specific column
	 * @param column Order column name
	 * @param value Order value
	 * @returns Promise with data collection
	 */
	public addOrder(column: string, value: Order) {
		const parsedValue = `${column}.${value}`;
		const index: number = this.findOrderIndex(column);
		if (index !== -1) {
			this.order[index] = parsedValue;
		} else {
			this.order.push(parsedValue);
		}
		return this.updateOrder();
	}
 
	/**
	 * Removes an order for specific column
	 * @param column Order column name
	 * @returns Promise with data collection
	 */
	public removeOrder(column: string) {
		const index: number = this.findOrderIndex(column);
		if (index !== -1) {
			this.order.splice(index, 1);
		}
		return this.updateOrder();
	}
 
	/**
	 * Sets new order value
	 * @param order Order values
	 * @returns Promise with data collection
	 */
	public setOrder(order: string[]) {
		this.order = order;
		return this.updateOrder();
	}
 
	/**
	 * Clears order value
	 * @returns Promise with data collection
	 */
	public clearOrder() {
		this.order = [];
		return this.updateOrder();
	}
 
	/**
	 * Updates order on query string
	 * @returns Promise with data collection
	 */
	protected async updateOrder() {
		if (this.watchUrl) {
			URL.updateQueryString({ order: this.order });
		}
		return this.reloadAndUpdateSelectedRows();
	}
 
	/**
	 * Updates selected rows, fetches and retrieves data collection
	 * @returns Promise with data collection
	 */
	protected async reloadAndUpdateSelectedRows() {
		const response = await this.get();
		this.updateVisibleSelectedRows();
		return response;
	}
 
	/**
	 * Retrieve the current sort for a column
	 * @param column Column name
	 * @returns Column order or null
	 */
	public getOrderByColumn(column: string): Order | null {
		const index: number = this.findOrderIndex(column);
		const order = index !== -1 ? this.order[index].split('.')[1] : null;
 
		if (order !== 'asc' && order !== 'desc') return null;
 
		return order;
	}
 
	/**
	 * Retrieves column index of order collection
	 * @param column Columns name
	 * @returns Column index
	 */
	protected findOrderIndex(column: string): number {
		return this.order.findIndex((order: string) => order.split('.')[0] === column);
	}
 
	/**
	 * Selects a row
	 * @param row Datasource row
	 */
	public selectRow(row: IDictionary<any>) {
		const index = this.selectedRowIndex(this.selectedRows, row);
		if (index === -1) {
			this.selectedRows.push(row);
			this.updateVisibleSelectedRows();
		}
	}
 
	/**
	 * Deselects a row
	 * @param row Datasource row
	 */
	public deselectRow(row: IDictionary<any>) {
		this.removeSelectedRow(this.selectedRows, row);
		this.removeSelectedRow(this.visibleSelectedRows, row);
	}
 
	/**
	 * Removes a row from selected rows collection
	 * @param selectedRows Selected rows collection
	 * @param row Row to remove
	 */
	protected removeSelectedRow(selectedRows: IDictionary<any>[], row: IDictionary<any>) {
		const index = this.selectedRowIndex(selectedRows, row);
		if (index !== -1) {
			selectedRows.splice(index, 1);
		}
	}
 
	/**
	 * Retrieves row index from selected rows collection
	 * @param selectedRows Selected rows collection
	 * @param row Datasource row
	 */
	protected selectedRowIndex(selectedRows: IDictionary<any>[], row: IDictionary<any>) {
		return selectedRows.findIndex((selected) => selected[this.uniqueKey] === row[this.uniqueKey]);
	}
 
	/**
	 * Updates visible selected rows collection based on data collection
	 */
	protected updateVisibleSelectedRows() {
		this.visibleSelectedRows = [];
		for (const selectedRow of this.selectedRows) {
			this.visibleSelectedRows = this.data
				.filter((row: IDictionary<any>) => selectedRow[this.uniqueKey] === row[this.uniqueKey])
				.concat(this.visibleSelectedRows);
		}
	}
 
	public updateSelectedPage() {
		if (!this.loadAll) {
			const lastPage = Math.ceil(this.total / this.limit);
			if (lastPage && lastPage < this.page) {
				return this.setPage(lastPage, true);
			}
		} else if (this.page !== 1) {
			this.page = 1;
 
			if (this.watchUrl) {
				URL.updateQueryString({ page: this.page }, true);
			}
		}
		return this.data;
	}
 
	/**
	 * Retrieves initial value for the attribute and if it is an accessor,
	 * updates props value.
	 * @param name Attribute name
	 * @param value Attribute value
	 * @param defaultValue Attribute default value
	 * @returns Initial value
	 */
	protected getInitValue(name: string, value: any, defaultValue: any) {
		let returnValue = defaultValue;
		if (this.accessorManager.hasAccessor(name)) {
			returnValue = (this as any)[name];
		} else if (typeof value !== 'undefined') {
			returnValue = value;
			this.accessorManager.addProp(name, value);
		}
		return returnValue;
	}
 
	/**
	 * Creates all accessors based on props value.
	 */
	protected createAccessors() {
		this.accessorManager.createAccessors(this);
	}
 
	/**
	 * Clones all datasource props
	 */
	public clone(): IDatasource {
		return {
			currentRow: this.currentRow,
			data: this.data,
			filter: this.filter,
			limit: this.limit,
			loadAll: this.loadAll,
			order: this.order,
			page: this.page,
			search: this.search,
			searchIn: this.searchIn,
			uniqueKey: this.uniqueKey,
			watchUrl: this.watchUrl,
			events: this.events,
		};
	}
 
	/**
	 * Creates the accessors defined inside an object recursively
	 * @param obj Object having the accessors
	 * @param path Name of the `obj` property inside the component
	 */
	protected createObjAccessors(obj: any, path: string) {
		for (const key in obj) {
			if (obj[key] instanceof Object) {
				this.createObjAccessors(obj[key], `${path}.${key}`);
				return;
			}
 
			this.accessorManager.addProp(`${path}.${key}`, obj[key]);
		}
 
		this.createAccessors();
	}
 
	/**
	 * Checks if row passed on current search
	 * @param row Each datasource row
	 * @returns Row passed
	 */
	protected getRowBySearch(row: IDictionary<any>) {
		let filtered = false;
		Object.keys(row).some((key) => {
			const searchInKey = this.searchIn.indexOf(key) !== -1;
 
			if (!searchInKey) return false;
 
			const lowerValue = Utils.normalize(row[key].toString());
			const lowerSearch = Utils.normalize(this.search);
 
			filtered = lowerValue.indexOf(lowerSearch) !== -1;
			return filtered;
		});
		return filtered;
	}
 
	/**
	 * Callbacks that will be executed after each `get()` call
	 */
	private getCallbacks: Callback[] = [];
 
	/**
	 * Registers a get callback
	 */
	public registerGetCallback(callback: Callback) {
		this.getCallbacks.push(callback);
	}
 
	/**
	 * Runs all get callbacks
	 */
	protected runGetCallbacks() {
		const promises = this.getCallbacks.map(async (callback) => callback(this.data));
 
		return Promise.all(promises);
	}
 
	/**
	 * Checks if there is a filter defined for a column
	 * @param columnName name of the column
	 * @returns whether the column has a filter defined
	 */
	public hasFilter(columnName: string): boolean {
		return this.filter[columnName] && this.filter[columnName].length > 0;
	}
}