@intellegens/cornerstone-client 0.0.0-experimental-upgrade-20260302-1
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.
- package/README.md +256 -0
- package/demo/index.ts +29 -0
- package/demo/public_html/favicon.ico +0 -0
- package/demo/public_html/index.html +106 -0
- package/demo/public_html/websettings.json +3 -0
- package/dist/adapters/CollectionViewAdapter/index.d.ts +198 -0
- package/dist/adapters/CollectionViewAdapter/index.integration.test.d.ts +1 -0
- package/dist/adapters/CollectionViewAdapter/index.integration.test.js +163 -0
- package/dist/adapters/CollectionViewAdapter/index.js +381 -0
- package/dist/adapters/SearchAdapter/index.d.ts +55 -0
- package/dist/adapters/SearchAdapter/index.js +233 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.js +2 -0
- package/dist/data/api/dto/PropertyPathDto.d.ts +4 -0
- package/dist/data/api/dto/PropertyPathDto.js +1 -0
- package/dist/data/api/dto/ReadOptionsDto.d.ts +8 -0
- package/dist/data/api/dto/ReadOptionsDto.js +1 -0
- package/dist/data/api/dto/ReadResultDto.d.ts +12 -0
- package/dist/data/api/dto/ReadResultDto.js +1 -0
- package/dist/data/api/dto/ReadResultMetadataDto.d.ts +8 -0
- package/dist/data/api/dto/ReadResultMetadataDto.js +1 -0
- package/dist/data/api/dto/crud/CrudMetadataDto.d.ts +4 -0
- package/dist/data/api/dto/crud/CrudMetadataDto.js +1 -0
- package/dist/data/api/dto/crud/index.d.ts +1 -0
- package/dist/data/api/dto/crud/index.js +1 -0
- package/dist/data/api/dto/index.d.ts +4 -0
- package/dist/data/api/dto/index.js +4 -0
- package/dist/data/api/dto/read/ReadMetadataDto.d.ts +8 -0
- package/dist/data/api/dto/read/ReadMetadataDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedDefinitionDto.d.ts +18 -0
- package/dist/data/api/dto/read/ReadSelectedDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.d.ts +22 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCriteriaDto.d.ts +18 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCriteriaDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingDefinitionDto.d.ts +7 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.d.ts +14 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedPaginationDefinitionDto.d.ts +13 -0
- package/dist/data/api/dto/read/ReadSelectedPaginationDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.d.ts +167 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.js +267 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionDto.d.ts +33 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.d.ts +114 -0
- package/dist/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/index.d.ts +10 -0
- package/dist/data/api/dto/read/index.js +10 -0
- package/dist/data/api/dto/response/ApiErrorDto.d.ts +17 -0
- package/dist/data/api/dto/response/ApiErrorDto.js +1 -0
- package/dist/data/api/dto/response/ApiErrorResponseDto.d.ts +11 -0
- package/dist/data/api/dto/response/ApiErrorResponseDto.js +1 -0
- package/dist/data/api/dto/response/ApiResponseDto.d.ts +3 -0
- package/dist/data/api/dto/response/ApiResponseDto.js +1 -0
- package/dist/data/api/dto/response/ApiSuccessResponseDto.d.ts +13 -0
- package/dist/data/api/dto/response/ApiSuccessResponseDto.js +1 -0
- package/dist/data/api/dto/response/EmptyMetadataDto.d.ts +4 -0
- package/dist/data/api/dto/response/EmptyMetadataDto.js +1 -0
- package/dist/data/api/dto/response/MetadataDto.d.ts +25 -0
- package/dist/data/api/dto/response/MetadataDto.js +1 -0
- package/dist/data/api/dto/response/index.d.ts +5 -0
- package/dist/data/api/dto/response/index.js +5 -0
- package/dist/data/api/enum/index.d.ts +2 -0
- package/dist/data/api/enum/index.js +2 -0
- package/dist/data/api/enum/read/ReadSelectedCollectionOperator.d.ts +16 -0
- package/dist/data/api/enum/read/ReadSelectedCollectionOperator.js +17 -0
- package/dist/data/api/enum/read/ReadSelectedComparisonOperator.d.ts +69 -0
- package/dist/data/api/enum/read/ReadSelectedComparisonOperator.js +76 -0
- package/dist/data/api/enum/read/ReadSelectedLogicalOperator.d.ts +15 -0
- package/dist/data/api/enum/read/ReadSelectedLogicalOperator.js +16 -0
- package/dist/data/api/enum/read/ReadSelectedOrderingDirection.d.ts +13 -0
- package/dist/data/api/enum/read/ReadSelectedOrderingDirection.js +14 -0
- package/dist/data/api/enum/read/ReadSelectedPropertyType.d.ts +66 -0
- package/dist/data/api/enum/read/ReadSelectedPropertyType.js +75 -0
- package/dist/data/api/enum/read/index.d.ts +5 -0
- package/dist/data/api/enum/read/index.js +5 -0
- package/dist/data/api/enum/response/ApiErrorCodes.d.ts +7 -0
- package/dist/data/api/enum/response/ApiErrorCodes.js +8 -0
- package/dist/data/api/enum/response/ErrorCode.d.ts +13 -0
- package/dist/data/api/enum/response/ErrorCode.js +14 -0
- package/dist/data/api/enum/response/index.d.ts +1 -0
- package/dist/data/api/enum/response/index.js +1 -0
- package/dist/data/api/index.d.ts +3 -0
- package/dist/data/api/index.js +3 -0
- package/dist/data/api/interface/ICommonIdentifiable.d.ts +7 -0
- package/dist/data/api/interface/ICommonIdentifiable.js +1 -0
- package/dist/data/api/interface/IConcurrencySafe.d.ts +9 -0
- package/dist/data/api/interface/IConcurrencySafe.js +2 -0
- package/dist/data/api/interface/IIdentifiable.d.ts +11 -0
- package/dist/data/api/interface/IIdentifiable.js +1 -0
- package/dist/data/api/interface/IIdentifiableSecondary.d.ts +9 -0
- package/dist/data/api/interface/IIdentifiableSecondary.js +1 -0
- package/dist/data/api/interface/index.d.ts +3 -0
- package/dist/data/api/interface/index.js +3 -0
- package/dist/data/auth/dto/ClaimDto.d.ts +4 -0
- package/dist/data/auth/dto/ClaimDto.js +1 -0
- package/dist/data/auth/dto/RegisterRequestDto.d.ts +4 -0
- package/dist/data/auth/dto/RegisterRequestDto.js +1 -0
- package/dist/data/auth/dto/RoleDto.d.ts +5 -0
- package/dist/data/auth/dto/RoleDto.js +1 -0
- package/dist/data/auth/dto/SignInRequestDto.d.ts +4 -0
- package/dist/data/auth/dto/SignInRequestDto.js +1 -0
- package/dist/data/auth/dto/TokensDto.d.ts +4 -0
- package/dist/data/auth/dto/TokensDto.js +1 -0
- package/dist/data/auth/dto/UserDto.d.ts +17 -0
- package/dist/data/auth/dto/UserDto.js +1 -0
- package/dist/data/auth/dto/UserInfoDto.d.ts +14 -0
- package/dist/data/auth/dto/UserInfoDto.js +1 -0
- package/dist/data/auth/dto/index.d.ts +5 -0
- package/dist/data/auth/dto/index.js +5 -0
- package/dist/data/auth/index.d.ts +2 -0
- package/dist/data/auth/index.js +2 -0
- package/dist/data/auth/policy.d.ts +52 -0
- package/dist/data/auth/policy.js +44 -0
- package/dist/data/index.d.ts +2 -0
- package/dist/data/index.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/services/api/ApiCrudControllerClient/index.d.ts +41 -0
- package/dist/services/api/ApiCrudControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/ApiCrudControllerClient/index.integration.test.js +34 -0
- package/dist/services/api/ApiCrudControllerClient/index.js +116 -0
- package/dist/services/api/ApiInitializationService/index.d.ts +106 -0
- package/dist/services/api/ApiInitializationService/index.js +208 -0
- package/dist/services/api/ApiReadControllerClient/index.d.ts +40 -0
- package/dist/services/api/ApiReadControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/ApiReadControllerClient/index.integration.test.js +59 -0
- package/dist/services/api/ApiReadControllerClient/index.js +111 -0
- package/dist/services/api/HttpService/FetchHttpService.d.ts +7 -0
- package/dist/services/api/HttpService/FetchHttpService.integration.test.d.ts +1 -0
- package/dist/services/api/HttpService/FetchHttpService.integration.test.js +52 -0
- package/dist/services/api/HttpService/FetchHttpService.js +29 -0
- package/dist/services/api/HttpService/HttpRequestConfig.d.ts +10 -0
- package/dist/services/api/HttpService/HttpRequestConfig.js +1 -0
- package/dist/services/api/HttpService/HttpResponse.d.ts +11 -0
- package/dist/services/api/HttpService/HttpResponse.js +3 -0
- package/dist/services/api/HttpService/IHttpService.d.ts +13 -0
- package/dist/services/api/HttpService/IHttpService.js +3 -0
- package/dist/services/api/HttpService/index.d.ts +9 -0
- package/dist/services/api/HttpService/index.js +10 -0
- package/dist/services/api/UserManagementControllerClient/index.d.ts +41 -0
- package/dist/services/api/UserManagementControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/UserManagementControllerClient/index.integration.test.js +60 -0
- package/dist/services/api/UserManagementControllerClient/index.js +117 -0
- package/dist/services/api/index.d.ts +5 -0
- package/dist/services/api/index.js +5 -0
- package/dist/services/auth/client/AuthService/index.d.ts +75 -0
- package/dist/services/auth/client/AuthService/index.js +200 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +48 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.js +89 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.js +148 -0
- package/dist/services/auth/client/index.d.ts +2 -0
- package/dist/services/auth/client/index.js +2 -0
- package/dist/services/auth/index.d.ts +1 -0
- package/dist/services/auth/index.js +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/utils/authorization/index.d.ts +17 -0
- package/dist/utils/authorization/index.js +45 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/result/index.d.ts +21 -0
- package/dist/utils/result/index.js +16 -0
- package/dist/utils/search/index.d.ts +34 -0
- package/dist/utils/search/index.js +106 -0
- package/package.json +45 -0
- package/src/adapters/CollectionViewAdapter/index.integration.test.ts +197 -0
- package/src/adapters/CollectionViewAdapter/index.ts +477 -0
- package/src/adapters/SearchAdapter/index.ts +302 -0
- package/src/adapters/index.ts +2 -0
- package/src/data/api/dto/PropertyPathDto.ts +4 -0
- package/src/data/api/dto/ReadOptionsDto.ts +8 -0
- package/src/data/api/dto/ReadResultDto.ts +13 -0
- package/src/data/api/dto/ReadResultMetadataDto.ts +8 -0
- package/src/data/api/dto/crud/CrudMetadataDto.ts +4 -0
- package/src/data/api/dto/crud/index.ts +1 -0
- package/src/data/api/dto/index.ts +4 -0
- package/src/data/api/dto/read/ReadMetadataDto.ts +8 -0
- package/src/data/api/dto/read/ReadSelectedDefinitionDto.ts +21 -0
- package/src/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.ts +25 -0
- package/src/data/api/dto/read/ReadSelectedNestedCriteriaDto.ts +20 -0
- package/src/data/api/dto/read/ReadSelectedOrderingDefinitionDto.ts +8 -0
- package/src/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.ts +16 -0
- package/src/data/api/dto/read/ReadSelectedPaginationDefinitionDto.ts +13 -0
- package/src/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.ts +348 -0
- package/src/data/api/dto/read/ReadSelectedSearchDefinitionDto.ts +43 -0
- package/src/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.ts +186 -0
- package/src/data/api/dto/read/index.ts +10 -0
- package/src/data/api/dto/response/ApiErrorDto.ts +21 -0
- package/src/data/api/dto/response/ApiErrorResponseDto.ts +13 -0
- package/src/data/api/dto/response/ApiResponseDto.ts +7 -0
- package/src/data/api/dto/response/ApiSuccessResponseDto.ts +13 -0
- package/src/data/api/dto/response/MetadataDto.ts +24 -0
- package/src/data/api/dto/response/index.ts +5 -0
- package/src/data/api/enum/index.ts +2 -0
- package/src/data/api/enum/read/ReadSelectedCollectionOperator.ts +17 -0
- package/src/data/api/enum/read/ReadSelectedComparisonOperator.ts +96 -0
- package/src/data/api/enum/read/ReadSelectedLogicalOperator.ts +16 -0
- package/src/data/api/enum/read/ReadSelectedOrderingDirection.ts +13 -0
- package/src/data/api/enum/read/ReadSelectedPropertyType.ts +96 -0
- package/src/data/api/enum/read/index.ts +5 -0
- package/src/data/api/enum/response/ErrorCode.ts +13 -0
- package/src/data/api/enum/response/index.ts +1 -0
- package/src/data/api/index.ts +3 -0
- package/src/data/api/interface/ICommonIdentifiable.ts +9 -0
- package/src/data/api/interface/IConcurrencySafe.ts +9 -0
- package/src/data/api/interface/IIdentifiable.ts +12 -0
- package/src/data/api/interface/IIdentifiableSecondary.ts +9 -0
- package/src/data/api/interface/index.ts +3 -0
- package/src/data/auth/dto/ClaimDto.ts +4 -0
- package/src/data/auth/dto/RegisterRequestDto.ts +4 -0
- package/src/data/auth/dto/RoleDto.ts +6 -0
- package/src/data/auth/dto/SignInRequestDto.ts +4 -0
- package/src/data/auth/dto/TokensDto.ts +4 -0
- package/src/data/auth/dto/UserDto.ts +18 -0
- package/src/data/auth/dto/UserInfoDto.ts +15 -0
- package/src/data/auth/dto/index.ts +5 -0
- package/src/data/auth/index.ts +2 -0
- package/src/data/auth/policy.ts +63 -0
- package/src/data/index.ts +2 -0
- package/src/index.ts +4 -0
- package/src/services/api/ApiCrudControllerClient/index.integration.test.ts +46 -0
- package/src/services/api/ApiCrudControllerClient/index.ts +135 -0
- package/src/services/api/ApiInitializationService/index.ts +254 -0
- package/src/services/api/ApiReadControllerClient/index.integration.test.ts +71 -0
- package/src/services/api/ApiReadControllerClient/index.ts +137 -0
- package/src/services/api/HttpService/FetchHttpService.integration.test.ts +65 -0
- package/src/services/api/HttpService/FetchHttpService.ts +34 -0
- package/src/services/api/HttpService/HttpRequestConfig.ts +10 -0
- package/src/services/api/HttpService/HttpResponse.ts +14 -0
- package/src/services/api/HttpService/IHttpService.ts +17 -0
- package/src/services/api/HttpService/README.md +106 -0
- package/src/services/api/HttpService/index.ts +12 -0
- package/src/services/api/UserManagementControllerClient/index.integration.test.ts +69 -0
- package/src/services/api/UserManagementControllerClient/index.ts +134 -0
- package/src/services/api/index.ts +5 -0
- package/src/services/auth/client/AuthService/index.ts +233 -0
- package/src/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.ts +110 -0
- package/src/services/auth/client/AuthorizationManagementControllerClient/index.ts +165 -0
- package/src/services/auth/client/index.ts +2 -0
- package/src/services/auth/index.ts +1 -0
- package/src/services/index.ts +2 -0
- package/src/utils/authorization/index.ts +47 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/result/index.ts +25 -0
- package/src/utils/search/index.ts +150 -0
- package/tsconfig.json +19 -0
- package/vitest-setup.ts +43 -0
- package/vitest.config.ts +59 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
+
import { CollectionViewAdapter } from '.';
|
|
3
|
+
import { ReadSelectedComparisonOperator, ReadSelectedOrderingDirection, ReadSelectedPropertyType } from '../../data';
|
|
4
|
+
import { dateInterval, searchTerm } from '../../utils';
|
|
5
|
+
describe('CollectionViewAdapter', () => {
|
|
6
|
+
let data;
|
|
7
|
+
let error;
|
|
8
|
+
let isLoading;
|
|
9
|
+
const callback = vi.fn((_isLoading, _data, _error) => {
|
|
10
|
+
isLoading = _isLoading;
|
|
11
|
+
data = _data;
|
|
12
|
+
error = _error;
|
|
13
|
+
});
|
|
14
|
+
const options = {
|
|
15
|
+
pagination: { useTotalItemCount: true, pageSize: 5, pageNumber: 1 },
|
|
16
|
+
ordering: { maxActiveOrderingColumns: 1, orderByPaths: [] },
|
|
17
|
+
search: { textSearchableProperties: ['name'], numericSearchableProperties: ['id'] },
|
|
18
|
+
};
|
|
19
|
+
let adapter;
|
|
20
|
+
const waitForData = async (timeout = 2000) => {
|
|
21
|
+
const start = Date.now();
|
|
22
|
+
while (isLoading !== false && Date.now() - start < timeout) {
|
|
23
|
+
await new Promise(res => setTimeout(res, 50));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const resetAdapterState = () => {
|
|
27
|
+
data = undefined;
|
|
28
|
+
error = undefined;
|
|
29
|
+
isLoading = undefined;
|
|
30
|
+
};
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
data = undefined;
|
|
33
|
+
error = undefined;
|
|
34
|
+
isLoading = undefined;
|
|
35
|
+
});
|
|
36
|
+
it('callback returns correct loading status and collection data', async () => {
|
|
37
|
+
options.pagination.useTotalItemCount = true;
|
|
38
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
39
|
+
await waitForData();
|
|
40
|
+
expect(callback).toHaveBeenNthCalledWith(1, true, undefined, undefined);
|
|
41
|
+
expect(callback).toHaveBeenLastCalledWith(false, data, undefined);
|
|
42
|
+
expect(data).toBeDefined();
|
|
43
|
+
});
|
|
44
|
+
it('adapter options set correct ordering', async () => {
|
|
45
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
46
|
+
await waitForData();
|
|
47
|
+
resetAdapterState();
|
|
48
|
+
adapter.setOrdering(['name'], ReadSelectedOrderingDirection.Descending);
|
|
49
|
+
await waitForData();
|
|
50
|
+
expect(adapter.getCurrentOrdering()).toEqual([
|
|
51
|
+
{
|
|
52
|
+
orderByPath: ['name'],
|
|
53
|
+
orderDirection: ReadSelectedOrderingDirection.Descending,
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
it('text search is applied to adapter', async () => {
|
|
58
|
+
const searchDefinition = searchTerm('Flu', ['name'], ['id']);
|
|
59
|
+
if (!searchDefinition)
|
|
60
|
+
throw new Error('searchDefinition is undefined');
|
|
61
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
62
|
+
await waitForData();
|
|
63
|
+
resetAdapterState();
|
|
64
|
+
adapter.setSearchDefinition(searchDefinition);
|
|
65
|
+
await waitForData();
|
|
66
|
+
expect(data).toBeDefined();
|
|
67
|
+
expect(data.length).toBeGreaterThan(0);
|
|
68
|
+
for (const item of data) {
|
|
69
|
+
expect(item.name).toMatch(/flu/i);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
it('numeric search is applied to adapter', async () => {
|
|
73
|
+
const searchDefinition = searchTerm('10000001', ['id'], ['id']);
|
|
74
|
+
if (!searchDefinition)
|
|
75
|
+
throw new Error('searchDefinition is undefined');
|
|
76
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
77
|
+
await waitForData();
|
|
78
|
+
resetAdapterState();
|
|
79
|
+
adapter.setSearchDefinition(searchDefinition);
|
|
80
|
+
await waitForData();
|
|
81
|
+
expect(data).toBeDefined();
|
|
82
|
+
expect(data.length).toBe(1);
|
|
83
|
+
for (const item of data) {
|
|
84
|
+
expect(item.id).toBe(10000001);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
it('applies date range filter from-to on the same date type property', async () => {
|
|
88
|
+
adapter = new CollectionViewAdapter('PetsSlim', callback, options);
|
|
89
|
+
const from = new Date('2017-01-01T00:00:00.000Z');
|
|
90
|
+
const to = new Date('2017-12-31T00:00:00.000Z');
|
|
91
|
+
const searchDefinition = dateInterval(from, to, ReadSelectedComparisonOperator.GreaterOrEqual, ReadSelectedComparisonOperator.LessOrEqual, ReadSelectedPropertyType.DateOnly, 'dateOfBirth');
|
|
92
|
+
if (!searchDefinition)
|
|
93
|
+
throw new Error('searchDefinition is undefined');
|
|
94
|
+
await waitForData();
|
|
95
|
+
resetAdapterState();
|
|
96
|
+
adapter.setSearchDefinition(searchDefinition);
|
|
97
|
+
await waitForData();
|
|
98
|
+
expect(data).toBeDefined();
|
|
99
|
+
});
|
|
100
|
+
it('applies pagination: page size and jump to page set skip/limit', async () => {
|
|
101
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
102
|
+
await waitForData();
|
|
103
|
+
const firstPageData = data;
|
|
104
|
+
resetAdapterState();
|
|
105
|
+
adapter.jumpToPage(3);
|
|
106
|
+
await waitForData();
|
|
107
|
+
expect(data).toBeDefined();
|
|
108
|
+
expect(data.length).toBe(5);
|
|
109
|
+
// Check that data is different from first page
|
|
110
|
+
expect(data).not.toEqual(firstPageData);
|
|
111
|
+
});
|
|
112
|
+
it('calculates total when useTotalItemCount=false and last page is partial', async () => {
|
|
113
|
+
options.pagination.useTotalItemCount = false;
|
|
114
|
+
options.pagination.pageSize = 10;
|
|
115
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
116
|
+
await waitForData();
|
|
117
|
+
const firstPageData = data;
|
|
118
|
+
resetAdapterState();
|
|
119
|
+
adapter.jumpToPage(2);
|
|
120
|
+
await waitForData();
|
|
121
|
+
expect(adapter.totalItemCount).toBe(firstPageData.length + data.length);
|
|
122
|
+
});
|
|
123
|
+
it('setOrdering correctly handles PropertyPathDto array comparison and limits columns', async () => {
|
|
124
|
+
options.ordering.maxActiveOrderingColumns = 2;
|
|
125
|
+
// Add first ordering
|
|
126
|
+
adapter = new CollectionViewAdapter('AnythingManuallyMappedRead', callback, options);
|
|
127
|
+
adapter.setOrdering(['name'], ReadSelectedOrderingDirection.Descending);
|
|
128
|
+
await waitForData();
|
|
129
|
+
expect(adapter.getCurrentOrdering()).toEqual([
|
|
130
|
+
{
|
|
131
|
+
orderByPath: ['name'],
|
|
132
|
+
orderDirection: ReadSelectedOrderingDirection.Descending,
|
|
133
|
+
},
|
|
134
|
+
]);
|
|
135
|
+
// Add second ordering
|
|
136
|
+
adapter.setOrdering(['id'], ReadSelectedOrderingDirection.Ascending);
|
|
137
|
+
await waitForData();
|
|
138
|
+
// Should have both orderings, with 'id' first (most recent)
|
|
139
|
+
expect(adapter.getCurrentOrdering()).toEqual([
|
|
140
|
+
{
|
|
141
|
+
orderByPath: ['id'],
|
|
142
|
+
orderDirection: ReadSelectedOrderingDirection.Ascending,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
orderByPath: ['name'],
|
|
146
|
+
orderDirection: ReadSelectedOrderingDirection.Descending,
|
|
147
|
+
},
|
|
148
|
+
]);
|
|
149
|
+
// // Add third ordering - should remove the oldest one (name)
|
|
150
|
+
adapter.setOrdering(['description'], ReadSelectedOrderingDirection.Descending);
|
|
151
|
+
await waitForData();
|
|
152
|
+
expect(adapter.getCurrentOrdering()).toEqual([
|
|
153
|
+
{
|
|
154
|
+
orderByPath: ['description'],
|
|
155
|
+
orderDirection: ReadSelectedOrderingDirection.Descending,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
orderByPath: ['id'],
|
|
159
|
+
orderDirection: ReadSelectedOrderingDirection.Ascending,
|
|
160
|
+
},
|
|
161
|
+
]);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { toPascalCase } from '../../utils';
|
|
2
|
+
import { ApiReadControllerClient } from '../../services';
|
|
3
|
+
/**
|
|
4
|
+
* TS class for handling ordering, filtering and paginating collections
|
|
5
|
+
*
|
|
6
|
+
* @param controllerName - specify the target endpoint controller name.
|
|
7
|
+
* @param dataChangedCallback - Function invoked whenever the data changes.
|
|
8
|
+
* Receives a loading state flag and the updated data collection.
|
|
9
|
+
* @param options - Optional settings of type CollectionViewAdapter to customize the behavior of the adapter.
|
|
10
|
+
*/
|
|
11
|
+
export class CollectionViewAdapter {
|
|
12
|
+
_readClient;
|
|
13
|
+
_isLoading = false;
|
|
14
|
+
_pageData = [];
|
|
15
|
+
_selectedItems = [];
|
|
16
|
+
_defaultOptions = {
|
|
17
|
+
pagination: {
|
|
18
|
+
useTotalItemCount: false,
|
|
19
|
+
pageSize: 10,
|
|
20
|
+
pageNumber: 1,
|
|
21
|
+
},
|
|
22
|
+
ordering: {
|
|
23
|
+
maxActiveOrderingColumns: 1,
|
|
24
|
+
orderByPaths: [],
|
|
25
|
+
},
|
|
26
|
+
search: {
|
|
27
|
+
textSearchableProperties: [],
|
|
28
|
+
numericSearchableProperties: [],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
_initialOptions;
|
|
32
|
+
_currentOptions;
|
|
33
|
+
constructor(controllerName, dataChangedCallback, options) {
|
|
34
|
+
this._readClient = new ApiReadControllerClient(controllerName);
|
|
35
|
+
this._initialOptions = {
|
|
36
|
+
pagination: {
|
|
37
|
+
...this._defaultOptions.pagination,
|
|
38
|
+
...options?.pagination,
|
|
39
|
+
},
|
|
40
|
+
ordering: {
|
|
41
|
+
...this._defaultOptions.ordering,
|
|
42
|
+
...options?.ordering,
|
|
43
|
+
},
|
|
44
|
+
search: {
|
|
45
|
+
...this._defaultOptions.search,
|
|
46
|
+
...options?.search,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
this._currentOptions = {
|
|
50
|
+
pagination: { ...this._initialOptions.pagination },
|
|
51
|
+
ordering: { ...this._initialOptions.ordering },
|
|
52
|
+
search: { ...this._initialOptions.search },
|
|
53
|
+
};
|
|
54
|
+
this._dataChangedCallback = dataChangedCallback;
|
|
55
|
+
this._fetchCurrentPageData();
|
|
56
|
+
}
|
|
57
|
+
//#region SEARCH
|
|
58
|
+
/**
|
|
59
|
+
* Allows for adding any filtering criteria. Label is required to distinguish custom search categories (e.g. searchTerm, dateRange, anyCustom ...)
|
|
60
|
+
*/
|
|
61
|
+
setSearchDefinition(searchDefinition) {
|
|
62
|
+
this._currentOptions.search.searchDefinition = searchDefinition;
|
|
63
|
+
this._currentOptions.pagination.pageNumber = 1; // Reset to first page
|
|
64
|
+
return this._fetchCurrentPageData();
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region ORDERING
|
|
68
|
+
/**
|
|
69
|
+
* Compares two PropertyPathDto arrays for equality
|
|
70
|
+
*/
|
|
71
|
+
_arePropertyPathsEqual(path1, path2) {
|
|
72
|
+
if (path1.length !== path2.length)
|
|
73
|
+
return false;
|
|
74
|
+
return path1.every((segment, index) => segment === path2[index]);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Public method for ordering the collection by property path / column name.
|
|
78
|
+
*
|
|
79
|
+
* @param propertyPath - must match camel-cased property/column name being sorted
|
|
80
|
+
* @param orderDirection - use `ReadSelectedOrderingDirection` enum choices
|
|
81
|
+
*/
|
|
82
|
+
setOrdering(propertyPath, orderDirection) {
|
|
83
|
+
// Remove any existing ordering for this property path
|
|
84
|
+
this._currentOptions.ordering.orderByPaths = this._currentOptions.ordering.orderByPaths.filter(p => !this._arePropertyPathsEqual(p.orderByPath, propertyPath));
|
|
85
|
+
// Add the new ordering at the beginning
|
|
86
|
+
this._currentOptions.ordering.orderByPaths.unshift({
|
|
87
|
+
orderByPath: propertyPath,
|
|
88
|
+
orderDirection: orderDirection,
|
|
89
|
+
});
|
|
90
|
+
// Limit to maxActiveOrderingColumns
|
|
91
|
+
if (this._currentOptions.ordering.orderByPaths.length > this._currentOptions.ordering.maxActiveOrderingColumns) {
|
|
92
|
+
this._currentOptions.ordering.orderByPaths = this._currentOptions.ordering.orderByPaths.slice(0, this._currentOptions.ordering.maxActiveOrderingColumns);
|
|
93
|
+
}
|
|
94
|
+
this._currentOptions.pagination.pageNumber = 1; // Reset to first page
|
|
95
|
+
return this._fetchCurrentPageData();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns the property name of the current columns/properties on which ordering is applied, along with the `ReadSelectedOrderingDirection` direction
|
|
99
|
+
*/
|
|
100
|
+
getCurrentOrdering() {
|
|
101
|
+
return this._currentOptions.ordering.orderByPaths;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region PAGINATION
|
|
105
|
+
/**
|
|
106
|
+
* Returns the current page's page number
|
|
107
|
+
*/
|
|
108
|
+
get currentPage() {
|
|
109
|
+
return this._currentOptions.pagination.pageNumber;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Sets the current page to `pageNumber` and triggers data re-fetch
|
|
113
|
+
*
|
|
114
|
+
* @param pageNumber
|
|
115
|
+
*/
|
|
116
|
+
jumpToPage(pageNumber) {
|
|
117
|
+
this._currentOptions.pagination.pageNumber = pageNumber;
|
|
118
|
+
return this._fetchCurrentPageData();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns the currently set page size value
|
|
122
|
+
*/
|
|
123
|
+
get pageSize() {
|
|
124
|
+
return this._currentOptions.pagination.pageSize;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Page size dictates the number of items or rows being fetched in a single API call
|
|
128
|
+
*
|
|
129
|
+
* @param pageSize
|
|
130
|
+
*/
|
|
131
|
+
setPageSize(pageSize) {
|
|
132
|
+
this._currentOptions.pagination.pageSize = pageSize;
|
|
133
|
+
this._currentOptions.pagination.pageNumber = 1; // Reset to first page
|
|
134
|
+
return this._fetchCurrentPageData();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Refreshes the data by re-fetching the current page
|
|
138
|
+
*/
|
|
139
|
+
refreshData() {
|
|
140
|
+
return this._fetchCurrentPageData();
|
|
141
|
+
}
|
|
142
|
+
_totalItemCount = -1;
|
|
143
|
+
/**
|
|
144
|
+
* Returns the total count value of the collection.
|
|
145
|
+
*
|
|
146
|
+
* If `CollectionViewAdapterOptions` has set `pagination.useTotalItemCount` to `true`, the API will return this value along with the collection and it will be set automatically.
|
|
147
|
+
* Else this adapter will attempt to dynamically calculate this value via `_calculateTotal()`.
|
|
148
|
+
*/
|
|
149
|
+
get totalItemCount() {
|
|
150
|
+
return this._totalItemCount;
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
/**
|
|
154
|
+
* Callback function invoked whenever data changes.
|
|
155
|
+
* Receives a loading state flag and the updated data collection.
|
|
156
|
+
*/
|
|
157
|
+
_dataChangedCallback;
|
|
158
|
+
/**
|
|
159
|
+
* Timeout reference used to debounce calls to `_fetchCurrentPageData`.
|
|
160
|
+
*/
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
|
+
_fetchCurrentPageDataTimeout;
|
|
163
|
+
/**
|
|
164
|
+
* Queue of pending promises waiting for `_fetchCurrentPageData` to resolve or reject.
|
|
165
|
+
*/
|
|
166
|
+
_fetchCurrentPageDataPromises = [];
|
|
167
|
+
/**
|
|
168
|
+
* Tracks the current in-flight request controller to allow cancellation when a new fetch starts.
|
|
169
|
+
*/
|
|
170
|
+
_currentAbortController;
|
|
171
|
+
/**
|
|
172
|
+
* Fetches the current page of data with debouncing support.
|
|
173
|
+
* Consolidates multiple concurrent calls into a single execution,
|
|
174
|
+
* resolving all queued promises with the same result.
|
|
175
|
+
*
|
|
176
|
+
* @returns A promise resolving to the fetched page of data.
|
|
177
|
+
*/
|
|
178
|
+
async _fetchCurrentPageData() {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
this._fetchCurrentPageDataPromises.push({ resolve, reject });
|
|
181
|
+
if (this._fetchCurrentPageDataTimeout !== undefined) {
|
|
182
|
+
clearTimeout(this._fetchCurrentPageDataTimeout);
|
|
183
|
+
}
|
|
184
|
+
this._fetchCurrentPageDataTimeout = setTimeout(async () => {
|
|
185
|
+
try {
|
|
186
|
+
const result = await this._fetchCurrentPageDataDebounced();
|
|
187
|
+
const promises = this._fetchCurrentPageDataPromises.splice(0, this._fetchCurrentPageDataPromises.length);
|
|
188
|
+
for (const p of promises)
|
|
189
|
+
p.resolve(result);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
const promises = this._fetchCurrentPageDataPromises.splice(0, this._fetchCurrentPageDataPromises.length);
|
|
193
|
+
for (const p of promises)
|
|
194
|
+
p.reject(err);
|
|
195
|
+
}
|
|
196
|
+
}, 50);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Executes the actual data fetch operation after debounce delay.
|
|
201
|
+
* Updates the loading state, triggers data change callbacks,
|
|
202
|
+
* and handles total item count calculation if pagination is enabled.
|
|
203
|
+
*
|
|
204
|
+
* @returns A promise resolving to the fetched page of data.
|
|
205
|
+
*/
|
|
206
|
+
async _fetchCurrentPageDataDebounced() {
|
|
207
|
+
this._isLoading = true;
|
|
208
|
+
this._dataChangedCallback(this._isLoading, undefined, undefined);
|
|
209
|
+
let abortController;
|
|
210
|
+
let caughtError;
|
|
211
|
+
try {
|
|
212
|
+
// Cancel any in-flight request before starting a new one
|
|
213
|
+
if (this._currentAbortController) {
|
|
214
|
+
try {
|
|
215
|
+
this._currentAbortController.abort();
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
// Ignore abort errors as they are expected when debouncing
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
abortController = new AbortController();
|
|
222
|
+
this._currentAbortController = abortController;
|
|
223
|
+
const definition = this._parseOptionsToDefinition();
|
|
224
|
+
const response = await this._readClient.readSelected(definition, abortController?.signal);
|
|
225
|
+
if (!response.ok) {
|
|
226
|
+
throw response.error;
|
|
227
|
+
}
|
|
228
|
+
this._pageData = response.result;
|
|
229
|
+
if (this._currentOptions.pagination.useTotalItemCount && response.metadata.totalCount !== undefined) {
|
|
230
|
+
this._totalItemCount = response.metadata.totalCount;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
const pageSize = this._currentOptions.pagination.pageSize;
|
|
234
|
+
const currentPageNumber = this._currentOptions.pagination.pageNumber;
|
|
235
|
+
const itemsOnCurrentPageCount = this._pageData.length;
|
|
236
|
+
this._totalItemCount = this._calculateTotal(pageSize, currentPageNumber, itemsOnCurrentPageCount, this._totalItemCount);
|
|
237
|
+
}
|
|
238
|
+
return this._pageData;
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
caughtError = error;
|
|
242
|
+
// Do not log abort-related errors as they are expected when debouncing
|
|
243
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
244
|
+
return Promise.reject(error);
|
|
245
|
+
}
|
|
246
|
+
console.error('Error fetching data:', error);
|
|
247
|
+
return Promise.reject(error);
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
this._isLoading = false;
|
|
251
|
+
let errorName;
|
|
252
|
+
if (caughtError && !(caughtError instanceof DOMException && caughtError.name === 'AbortError')) {
|
|
253
|
+
errorName = caughtError instanceof Error ? caughtError.name : undefined;
|
|
254
|
+
}
|
|
255
|
+
this._dataChangedCallback(this._isLoading, this._pageData, errorName);
|
|
256
|
+
// Clear the abort controller only if it belongs to this request (avoid racing with a newer one)
|
|
257
|
+
if (abortController && this._currentAbortController === abortController) {
|
|
258
|
+
this._currentAbortController = undefined;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Takes current `CollectionViewAdapterOptions` and parses to `ReadSelectedDefinitionDto` which the cornerstone API expects.
|
|
264
|
+
*
|
|
265
|
+
* @returns - `ReadSelectedDefinitionDto` object
|
|
266
|
+
*/
|
|
267
|
+
_parseOptionsToDefinition() {
|
|
268
|
+
const definition = {
|
|
269
|
+
paginationDefinition: {
|
|
270
|
+
skip: (this._currentOptions.pagination.pageNumber - 1) * this._currentOptions.pagination.pageSize,
|
|
271
|
+
limit: this._currentOptions.pagination.pageSize,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
// Apply ordering
|
|
275
|
+
const orderByPaths = this._currentOptions.ordering.orderByPaths;
|
|
276
|
+
if (orderByPaths && orderByPaths.length > 0) {
|
|
277
|
+
definition.orderingDefinition = {
|
|
278
|
+
order: orderByPaths.map(orderPath => ({
|
|
279
|
+
propertyPath: orderPath.orderByPath.map(x => toPascalCase(x)),
|
|
280
|
+
direction: orderPath.orderDirection,
|
|
281
|
+
})),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
// Apply search
|
|
285
|
+
definition.searchDefinition = this._currentOptions.search.searchDefinition;
|
|
286
|
+
return definition;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Calculates the total item count given pagination inputs.
|
|
290
|
+
*
|
|
291
|
+
* For example, with 10 items per page, on page 2 with 3 items, total = 13.
|
|
292
|
+
* If the total cannot be inferred (e.g., a full page is returned), the previous total is returned unchanged.
|
|
293
|
+
*
|
|
294
|
+
* @param pageSize - Number of items per page
|
|
295
|
+
* @param currentPageNumber - Current page number (1-based)
|
|
296
|
+
* @param itemsOnCurrentPageCount - Number of items in the fetched page
|
|
297
|
+
* @param previousTotal - Previous known total to preserve when indeterminate
|
|
298
|
+
* @returns The computed total item count
|
|
299
|
+
*/
|
|
300
|
+
_calculateTotal(pageSize, currentPageNumber, itemsOnCurrentPageCount, previousTotal) {
|
|
301
|
+
if (itemsOnCurrentPageCount < pageSize && itemsOnCurrentPageCount !== 0) {
|
|
302
|
+
return pageSize * (currentPageNumber - 1) + itemsOnCurrentPageCount;
|
|
303
|
+
}
|
|
304
|
+
else if (itemsOnCurrentPageCount === 0 && pageSize === 0) {
|
|
305
|
+
return 0;
|
|
306
|
+
}
|
|
307
|
+
return previousTotal;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Selects or deselects an item based on its ID.
|
|
311
|
+
* @param item - The item to select or deselect.
|
|
312
|
+
*/
|
|
313
|
+
toggleItemSelected(item) {
|
|
314
|
+
// if item with the same id is not already selected, add it
|
|
315
|
+
// if item with the same id is already selected, remove it
|
|
316
|
+
if (this._selectedItems.find(x => x.id === item.id)) {
|
|
317
|
+
this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
this._selectedItems.push(item);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
clearSelectedItems() {
|
|
324
|
+
this._selectedItems = [];
|
|
325
|
+
}
|
|
326
|
+
selectItems(item) {
|
|
327
|
+
if (!this._selectedItems.find(x => x.id === item.id)) {
|
|
328
|
+
this._selectedItems.push(item);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
deselectItem(item) {
|
|
332
|
+
this._selectedItems = this._selectedItems.filter(x => x.id !== item.id);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Returns the currently selected items
|
|
336
|
+
*/
|
|
337
|
+
get selectedItems() {
|
|
338
|
+
return this._selectedItems;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Checks if an item is currently selected
|
|
342
|
+
* @param item - The item to check
|
|
343
|
+
*/
|
|
344
|
+
isItemSelected(item) {
|
|
345
|
+
return this._selectedItems.some(x => x.id === item.id);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Selects all items on the current page
|
|
349
|
+
*/
|
|
350
|
+
selectAllItemsOnCurrentPage() {
|
|
351
|
+
for (const item of this._pageData) {
|
|
352
|
+
if (!this.isItemSelected(item)) {
|
|
353
|
+
this._selectedItems.push(item);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Deselects all items on the current page
|
|
359
|
+
*/
|
|
360
|
+
deselectAllItemsOnCurrentPage() {
|
|
361
|
+
const pageItemIds = this._pageData.map(item => item.id);
|
|
362
|
+
this._selectedItems = this._selectedItems.filter(item => !pageItemIds.includes(item.id));
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Checks if all items on the current page are selected
|
|
366
|
+
*/
|
|
367
|
+
areAllItemsOnCurrentPageSelected() {
|
|
368
|
+
if (this._pageData.length === 0)
|
|
369
|
+
return false;
|
|
370
|
+
return this._pageData.every(item => this.isItemSelected(item));
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Checks if some (but not all) items on the current page are selected
|
|
374
|
+
*/
|
|
375
|
+
areSomeItemsOnCurrentPageSelected() {
|
|
376
|
+
if (this._pageData.length === 0)
|
|
377
|
+
return false;
|
|
378
|
+
const selectedCount = this._pageData.filter(item => this.isItemSelected(item)).length;
|
|
379
|
+
return selectedCount > 0 && selectedCount < this._pageData.length;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IIdentifiable, ReadSelectedSearchDefinitionDto } from '../../data';
|
|
2
|
+
export type SearchAdapterOptions<T> = {
|
|
3
|
+
controllerName: string;
|
|
4
|
+
typesToSearch: string[];
|
|
5
|
+
multiselect: boolean;
|
|
6
|
+
searchTriggerMinLength: number;
|
|
7
|
+
searchDebounceDelay: number;
|
|
8
|
+
limitSearchToSelectedType: boolean;
|
|
9
|
+
resultsLimit: number;
|
|
10
|
+
additionalSearchDefinitions?: ReadSelectedSearchDefinitionDto<T>[];
|
|
11
|
+
};
|
|
12
|
+
declare class SingularEventTarget<T> {
|
|
13
|
+
private _target;
|
|
14
|
+
addEventListener(callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void;
|
|
15
|
+
dispatchEvent(value: T): void;
|
|
16
|
+
}
|
|
17
|
+
export interface IGlobalSearchable<TKey> extends IIdentifiable<TKey> {
|
|
18
|
+
type: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class SearchAdapter<TKey, TDto extends IGlobalSearchable<TKey>> {
|
|
21
|
+
onChange: SingularEventTarget<string>;
|
|
22
|
+
private _readClient;
|
|
23
|
+
options: SearchAdapterOptions<TDto>;
|
|
24
|
+
private _isLoading;
|
|
25
|
+
private _currentAbortController?;
|
|
26
|
+
private _lastSearchedValue;
|
|
27
|
+
private _typesToSearch;
|
|
28
|
+
private _fetchResultsDataTimeout?;
|
|
29
|
+
private _fetchResultsPromises;
|
|
30
|
+
private _totalCount;
|
|
31
|
+
constructor(options: SearchAdapterOptions<TDto>);
|
|
32
|
+
get searchTriggerMinLength(): number;
|
|
33
|
+
get multiselect(): boolean;
|
|
34
|
+
get isLoading(): boolean;
|
|
35
|
+
get totalCount(): number;
|
|
36
|
+
get hasMoreRecords(): boolean;
|
|
37
|
+
private _searchText;
|
|
38
|
+
get searchText(): string;
|
|
39
|
+
set searchText(searchText: string);
|
|
40
|
+
private _searchResults;
|
|
41
|
+
get searchResults(): TDto[];
|
|
42
|
+
protected set searchResults(searchResults: TDto[]);
|
|
43
|
+
private _selectedItems;
|
|
44
|
+
get selectedItems(): TDto[];
|
|
45
|
+
set selectedItems(selectedItems: TDto[]);
|
|
46
|
+
addToSelection(item: TDto): void;
|
|
47
|
+
removeFromSelection(item: TDto): void;
|
|
48
|
+
private _emitChange;
|
|
49
|
+
private _trySearch;
|
|
50
|
+
private _fetchResults;
|
|
51
|
+
private _fetchResultsDebounced;
|
|
52
|
+
private _parseToSearchDefinition;
|
|
53
|
+
private _sortByName;
|
|
54
|
+
}
|
|
55
|
+
export {};
|