@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,233 @@
|
|
|
1
|
+
import { ReadSelectedComparisonOperator, ReadSelectedLogicalOperator, ReadSelectedOrderingDirection, ReadSelectedPropertyType, } from '../../data';
|
|
2
|
+
import { ApiReadControllerClient } from '../../services';
|
|
3
|
+
class SingularEventTarget {
|
|
4
|
+
_target = new EventTarget();
|
|
5
|
+
addEventListener(callback, options) {
|
|
6
|
+
this._target.addEventListener('change', callback, options);
|
|
7
|
+
}
|
|
8
|
+
dispatchEvent(value) {
|
|
9
|
+
this._target.dispatchEvent(new CustomEvent('change', { detail: value }));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class SearchAdapter {
|
|
13
|
+
onChange = new SingularEventTarget();
|
|
14
|
+
// inputs
|
|
15
|
+
_readClient;
|
|
16
|
+
options;
|
|
17
|
+
_isLoading = false;
|
|
18
|
+
_currentAbortController;
|
|
19
|
+
_lastSearchedValue = undefined;
|
|
20
|
+
_typesToSearch = [];
|
|
21
|
+
_fetchResultsDataTimeout;
|
|
22
|
+
_fetchResultsPromises = [];
|
|
23
|
+
_totalCount = 0;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.options = options;
|
|
26
|
+
this._readClient = new ApiReadControllerClient(options.controllerName);
|
|
27
|
+
}
|
|
28
|
+
get searchTriggerMinLength() {
|
|
29
|
+
return this.options.searchTriggerMinLength;
|
|
30
|
+
}
|
|
31
|
+
get multiselect() {
|
|
32
|
+
return this.options.multiselect;
|
|
33
|
+
}
|
|
34
|
+
get isLoading() {
|
|
35
|
+
return this._isLoading;
|
|
36
|
+
}
|
|
37
|
+
get totalCount() {
|
|
38
|
+
return this._totalCount;
|
|
39
|
+
}
|
|
40
|
+
get hasMoreRecords() {
|
|
41
|
+
return this._totalCount > this._searchResults.length;
|
|
42
|
+
}
|
|
43
|
+
_searchText = '';
|
|
44
|
+
get searchText() {
|
|
45
|
+
return this._searchText;
|
|
46
|
+
}
|
|
47
|
+
set searchText(searchText) {
|
|
48
|
+
this._searchText = searchText;
|
|
49
|
+
this._trySearch();
|
|
50
|
+
this._emitChange();
|
|
51
|
+
}
|
|
52
|
+
_searchResults = [];
|
|
53
|
+
get searchResults() {
|
|
54
|
+
return this._searchResults;
|
|
55
|
+
}
|
|
56
|
+
set searchResults(searchResults) {
|
|
57
|
+
this._searchResults = [...searchResults];
|
|
58
|
+
this._emitChange();
|
|
59
|
+
}
|
|
60
|
+
_selectedItems = [];
|
|
61
|
+
get selectedItems() {
|
|
62
|
+
return this._selectedItems;
|
|
63
|
+
}
|
|
64
|
+
set selectedItems(selectedItems) {
|
|
65
|
+
this._selectedItems = [...selectedItems];
|
|
66
|
+
this._emitChange();
|
|
67
|
+
}
|
|
68
|
+
addToSelection(item) {
|
|
69
|
+
if (!this._selectedItems) {
|
|
70
|
+
this.selectedItems = [];
|
|
71
|
+
}
|
|
72
|
+
// selection mode
|
|
73
|
+
if (this.options.multiselect) {
|
|
74
|
+
if (!this._selectedItems.find(s => s.id === item.id)) {
|
|
75
|
+
this.selectedItems = [...this.selectedItems, item];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// single-select mode - replace the item and return the old one to shown results
|
|
80
|
+
if (this._selectedItems.length > 0) {
|
|
81
|
+
this.searchResults = this._sortByName([...this._searchResults, ...this._selectedItems]); // return the to-be-replaced selected item back to shown results list
|
|
82
|
+
}
|
|
83
|
+
this.selectedItems = [item];
|
|
84
|
+
}
|
|
85
|
+
this.searchResults = this._sortByName(this._searchResults.filter(d => d.id !== item.id)); // remove the new selection from the shown results
|
|
86
|
+
}
|
|
87
|
+
removeFromSelection(item) {
|
|
88
|
+
if (!this._selectedItems) {
|
|
89
|
+
this.selectedItems = [];
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.selectedItems = this._selectedItems.filter(s => s.id !== item.id);
|
|
93
|
+
this.searchResults = this._sortByName([...this._searchResults, item]);
|
|
94
|
+
}
|
|
95
|
+
_emitChange() {
|
|
96
|
+
this.onChange.dispatchEvent('onChange');
|
|
97
|
+
}
|
|
98
|
+
async _trySearch() {
|
|
99
|
+
const options = this.options;
|
|
100
|
+
this.searchResults = [];
|
|
101
|
+
if (this._searchText.length < options.searchTriggerMinLength)
|
|
102
|
+
return;
|
|
103
|
+
if (this._searchText === this._lastSearchedValue)
|
|
104
|
+
return;
|
|
105
|
+
this._lastSearchedValue = this._searchText;
|
|
106
|
+
this._typesToSearch =
|
|
107
|
+
options.limitSearchToSelectedType && this._selectedItems.length ? [this._selectedItems[0].type] : this.options.typesToSearch;
|
|
108
|
+
this.searchResults = this._sortByName(await this._fetchResults(options.searchDebounceDelay));
|
|
109
|
+
}
|
|
110
|
+
async _fetchResults(debounceDelay) {
|
|
111
|
+
this._isLoading = true;
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
this._fetchResultsPromises.push({ resolve, reject });
|
|
114
|
+
if (this._fetchResultsDataTimeout !== undefined) {
|
|
115
|
+
clearTimeout(this._fetchResultsDataTimeout);
|
|
116
|
+
}
|
|
117
|
+
this._fetchResultsDataTimeout = setTimeout(async () => {
|
|
118
|
+
try {
|
|
119
|
+
const result = await this._fetchResultsDebounced();
|
|
120
|
+
const promises = this._fetchResultsPromises.splice(0, this._fetchResultsPromises.length);
|
|
121
|
+
for (const p of promises)
|
|
122
|
+
p.resolve(result);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
const promises = this._fetchResultsPromises.splice(0, this._fetchResultsPromises.length);
|
|
126
|
+
for (const p of promises)
|
|
127
|
+
p.reject(err);
|
|
128
|
+
}
|
|
129
|
+
}, debounceDelay);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async _fetchResultsDebounced() {
|
|
133
|
+
let abortController;
|
|
134
|
+
let caughtError;
|
|
135
|
+
try {
|
|
136
|
+
// Cancel any in-flight request before starting a new one
|
|
137
|
+
if (this._currentAbortController) {
|
|
138
|
+
try {
|
|
139
|
+
this._currentAbortController.abort();
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// Ignore abort errors as they are expected when debouncing
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
abortController = new AbortController();
|
|
146
|
+
this._currentAbortController = abortController;
|
|
147
|
+
const definition = this._parseToSearchDefinition();
|
|
148
|
+
const response = await this._readClient.readSelected(definition, abortController?.signal);
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
throw response.error;
|
|
151
|
+
}
|
|
152
|
+
// Update total count from response metadata
|
|
153
|
+
this._totalCount = response.metadata?.totalCount ?? response.result.length;
|
|
154
|
+
// Filter out selected items from new results
|
|
155
|
+
const selectedIds = new Set((this.selectedItems || []).map(item => item.id));
|
|
156
|
+
return response.result.filter(item => !selectedIds.has(item.id));
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
caughtError = error;
|
|
160
|
+
// Do not log abort-related errors as they are expected when debouncing
|
|
161
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
162
|
+
return Promise.reject(error);
|
|
163
|
+
}
|
|
164
|
+
console.error('Error fetching data:', error);
|
|
165
|
+
return Promise.reject(error);
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
this._isLoading = false;
|
|
169
|
+
let errorName;
|
|
170
|
+
if (caughtError && !(caughtError instanceof DOMException && caughtError.name === 'AbortError')) {
|
|
171
|
+
errorName = caughtError instanceof Error ? caughtError.name : undefined;
|
|
172
|
+
}
|
|
173
|
+
// Clear the abort controller only if it belongs to this request (avoid racing with a newer one)
|
|
174
|
+
if (abortController && this._currentAbortController === abortController) {
|
|
175
|
+
this._currentAbortController = undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
_parseToSearchDefinition() {
|
|
180
|
+
const definition = {
|
|
181
|
+
paginationDefinition: {
|
|
182
|
+
skip: 0,
|
|
183
|
+
limit: this.options.resultsLimit,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
// Apply ordering
|
|
187
|
+
definition.orderingDefinition = {
|
|
188
|
+
order: [
|
|
189
|
+
{
|
|
190
|
+
propertyPath: ['Name'],
|
|
191
|
+
direction: ReadSelectedOrderingDirection.Ascending,
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
};
|
|
195
|
+
// Apply search
|
|
196
|
+
const propertyCriteria = [
|
|
197
|
+
{
|
|
198
|
+
propertyName: 'Name',
|
|
199
|
+
comparisonOperator: ReadSelectedComparisonOperator.IContains,
|
|
200
|
+
valueType: ReadSelectedPropertyType.String,
|
|
201
|
+
value: this._searchText,
|
|
202
|
+
},
|
|
203
|
+
];
|
|
204
|
+
definition.searchDefinition = {
|
|
205
|
+
logicalOperator: ReadSelectedLogicalOperator.And,
|
|
206
|
+
propertyCriteria: propertyCriteria,
|
|
207
|
+
};
|
|
208
|
+
if (this._typesToSearch !== undefined && this._typesToSearch.length > 0) {
|
|
209
|
+
definition.searchDefinition.searches = [
|
|
210
|
+
{
|
|
211
|
+
logicalOperator: ReadSelectedLogicalOperator.Or,
|
|
212
|
+
propertyCriteria: this._typesToSearch.map(type => ({
|
|
213
|
+
propertyName: 'Type',
|
|
214
|
+
comparisonOperator: ReadSelectedComparisonOperator.IEqual,
|
|
215
|
+
valueType: ReadSelectedPropertyType.String,
|
|
216
|
+
value: type,
|
|
217
|
+
})),
|
|
218
|
+
},
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
if (this.options.additionalSearchDefinitions && this.options.additionalSearchDefinitions.length > 0) {
|
|
222
|
+
definition.searchDefinition.searches = [...(definition.searchDefinition.searches ?? []), ...this.options.additionalSearchDefinitions];
|
|
223
|
+
}
|
|
224
|
+
return definition;
|
|
225
|
+
}
|
|
226
|
+
_sortByName(array) {
|
|
227
|
+
return array.sort((a, b) => {
|
|
228
|
+
const nameA = a.name?.toLowerCase() || '';
|
|
229
|
+
const nameB = b.name?.toLowerCase() || '';
|
|
230
|
+
return nameA.localeCompare(nameB);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReadResultMetadataDto } from './ReadResultMetadataDto';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a read result containing a collection of results and metadata.
|
|
4
|
+
*
|
|
5
|
+
* @template T The type of result in the collection.
|
|
6
|
+
* @property {T[]} items - The collection of results returned.
|
|
7
|
+
* @property {ReadResultMetadata} metadata - Metadata about the paginated result.
|
|
8
|
+
*/
|
|
9
|
+
export type ReadResultDto<T> = {
|
|
10
|
+
results: T[];
|
|
11
|
+
metadata: ReadResultMetadataDto;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CrudMetadataDto';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CrudMetadataDto';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReadSelectedPaginationDefinitionDto, ReadSelectedOrderingDefinitionDto, ReadSelectedSearchDefinitionDto } from '../../..';
|
|
2
|
+
/**
|
|
3
|
+
* Defines the selection criteria for a controller to fetch multiple records
|
|
4
|
+
*/
|
|
5
|
+
export type ReadSelectedDefinitionDto<T> = {
|
|
6
|
+
/**
|
|
7
|
+
* Pagination definition
|
|
8
|
+
*/
|
|
9
|
+
paginationDefinition?: ReadSelectedPaginationDefinitionDto;
|
|
10
|
+
/**
|
|
11
|
+
* Ordering definition
|
|
12
|
+
*/
|
|
13
|
+
orderingDefinition?: ReadSelectedOrderingDefinitionDto;
|
|
14
|
+
/**
|
|
15
|
+
* Search definition (supports both simple search and nested logical groups)
|
|
16
|
+
*/
|
|
17
|
+
searchDefinition?: ReadSelectedSearchDefinitionDto<T>;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ReadSelectedCollectionOperator, ReadSelectedSearchDefinitionDto } from '../../..';
|
|
2
|
+
/**
|
|
3
|
+
* Defines criteria for searching within a collection navigation property using quantifiers (Any/All).
|
|
4
|
+
*
|
|
5
|
+
* This DTO allows navigation into a collection property and applying search criteria
|
|
6
|
+
* with a quantifier to determine if any or all elements match.
|
|
7
|
+
*/
|
|
8
|
+
export type ReadSelectedNestedCollectionCriteriaDto<T, TPropertyName extends keyof T> = {
|
|
9
|
+
/**
|
|
10
|
+
* The name of the collection navigation property to navigate into.
|
|
11
|
+
*/
|
|
12
|
+
propertyName: TPropertyName;
|
|
13
|
+
/**
|
|
14
|
+
* The quantifier operator determining whether any or all elements must match.
|
|
15
|
+
*/
|
|
16
|
+
collectionOperator: ReadSelectedCollectionOperator;
|
|
17
|
+
/**
|
|
18
|
+
* The search criteria to apply to elements in the collection.
|
|
19
|
+
* Type should be ReadSelectedSearchDefinitionDto of the collection element type.
|
|
20
|
+
*/
|
|
21
|
+
criteria: ReadSelectedSearchDefinitionDto<unknown>;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReadSelectedSearchDefinitionDto } from '../../..';
|
|
2
|
+
/**
|
|
3
|
+
* Defines criteria for searching within a nested object property.
|
|
4
|
+
*
|
|
5
|
+
* This DTO allows navigation into a nested object property and applying search criteria
|
|
6
|
+
* to that nested object. The property name must refer to a navigation property (not a collection).
|
|
7
|
+
*/
|
|
8
|
+
export type ReadSelectedNestedCriteriaDto<T, TPropertyName extends keyof T> = {
|
|
9
|
+
/**
|
|
10
|
+
* The name of the navigation property to navigate into.
|
|
11
|
+
*/
|
|
12
|
+
propertyName: TPropertyName;
|
|
13
|
+
/**
|
|
14
|
+
* The search criteria to apply to the nested object.
|
|
15
|
+
* Type should be ReadSelectedSearchDefinitionDto of the nested object type.
|
|
16
|
+
*/
|
|
17
|
+
criteria: ReadSelectedSearchDefinitionDto<unknown>;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PropertyPathDto, ReadSelectedOrderingDirection } from '../../..';
|
|
2
|
+
/**
|
|
3
|
+
* Defines the ordering property for a controller.
|
|
4
|
+
*/
|
|
5
|
+
export type ReadSelectedOrderingPropertyDefinitionDto = {
|
|
6
|
+
/**
|
|
7
|
+
* Gets or sets the property path.
|
|
8
|
+
*/
|
|
9
|
+
propertyPath: PropertyPathDto;
|
|
10
|
+
/**
|
|
11
|
+
* Gets or sets the ordering direction.
|
|
12
|
+
*/
|
|
13
|
+
direction: ReadSelectedOrderingDirection;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { ReadSelectedComparisonOperator, ReadSelectedPropertyType } from '../../..';
|
|
2
|
+
import { ReadSelectedSearchDefinitionDto } from './ReadSelectedSearchDefinitionDto';
|
|
3
|
+
/**
|
|
4
|
+
* Builder class for constructing ReadSelectedSearchDefinitionDto with a fluent API.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Simple AND search with property criteria
|
|
8
|
+
* const search = SearchBuilder.and<User>()
|
|
9
|
+
* .whereString('name', ReadSelectedComparisonOperator.IContains, 'John')
|
|
10
|
+
* .whereNumber('age', ReadSelectedComparisonOperator.GreaterThan, 18)
|
|
11
|
+
* .build();
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // OR search with nested criteria (specify nested type for intellisense)
|
|
15
|
+
* const search = SearchBuilder.or<User>()
|
|
16
|
+
* .whereString('status', ReadSelectedComparisonOperator.Equal, 'active')
|
|
17
|
+
* .nested<Address>('address', nested =>
|
|
18
|
+
* nested.whereString('city', ReadSelectedComparisonOperator.Equal, 'NYC')
|
|
19
|
+
* )
|
|
20
|
+
* .build();
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Complex nested search with collection criteria
|
|
24
|
+
* const search = SearchBuilder.and<Order>()
|
|
25
|
+
* .whereString('status', ReadSelectedComparisonOperator.Equal, 'pending')
|
|
26
|
+
* .any<OrderItem>('items', itemSearch =>
|
|
27
|
+
* itemSearch.whereNumber('quantity', ReadSelectedComparisonOperator.GreaterThan, 5)
|
|
28
|
+
* )
|
|
29
|
+
* .group(sub => sub.or()
|
|
30
|
+
* .whereString('priority', ReadSelectedComparisonOperator.Equal, 'high')
|
|
31
|
+
* .whereString('priority', ReadSelectedComparisonOperator.Equal, 'urgent')
|
|
32
|
+
* )
|
|
33
|
+
* .build();
|
|
34
|
+
*/
|
|
35
|
+
export declare class SearchBuilder<T> {
|
|
36
|
+
private _logicalOperator;
|
|
37
|
+
private _searches;
|
|
38
|
+
private _propertyCriteria;
|
|
39
|
+
private _nestedCriteria;
|
|
40
|
+
private _nestedCollectionCriteria;
|
|
41
|
+
private constructor();
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new builder with AND logical operator.
|
|
44
|
+
* All criteria added to this builder will be combined with AND.
|
|
45
|
+
*/
|
|
46
|
+
static and<T>(): SearchBuilder<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new builder with OR logical operator.
|
|
49
|
+
* All criteria added to this builder will be combined with OR.
|
|
50
|
+
*/
|
|
51
|
+
static or<T>(): SearchBuilder<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Sets the logical operator to AND.
|
|
54
|
+
*/
|
|
55
|
+
and(): this;
|
|
56
|
+
/**
|
|
57
|
+
* Sets the logical operator to OR.
|
|
58
|
+
*/
|
|
59
|
+
or(): this;
|
|
60
|
+
/**
|
|
61
|
+
* Adds a property comparison criterion.
|
|
62
|
+
*
|
|
63
|
+
* @param propertyName - The property to compare
|
|
64
|
+
* @param comparisonOperator - The comparison operator to use
|
|
65
|
+
* @param value - The value to compare against
|
|
66
|
+
* @param valueType - The type of the value
|
|
67
|
+
*/
|
|
68
|
+
where<K extends keyof T>(propertyName: K, comparisonOperator: ReadSelectedComparisonOperator, value: unknown, valueType: ReadSelectedPropertyType): this;
|
|
69
|
+
/**
|
|
70
|
+
* Adds a string property comparison with common string operations.
|
|
71
|
+
*/
|
|
72
|
+
whereString<K extends keyof T>(propertyName: K, comparisonOperator: ReadSelectedComparisonOperator.Equal | ReadSelectedComparisonOperator.NotEqual | ReadSelectedComparisonOperator.Contains | ReadSelectedComparisonOperator.StartsWith | ReadSelectedComparisonOperator.EndsWith | ReadSelectedComparisonOperator.IContains | ReadSelectedComparisonOperator.IStartsWith | ReadSelectedComparisonOperator.IEndsWith | ReadSelectedComparisonOperator.IEqual | ReadSelectedComparisonOperator.INotEqual, value: string): this;
|
|
73
|
+
/**
|
|
74
|
+
* Adds a number property comparison.
|
|
75
|
+
*/
|
|
76
|
+
whereNumber<K extends keyof T>(propertyName: K, comparisonOperator: ReadSelectedComparisonOperator.Equal | ReadSelectedComparisonOperator.NotEqual | ReadSelectedComparisonOperator.LessThan | ReadSelectedComparisonOperator.LessOrEqual | ReadSelectedComparisonOperator.GreaterThan | ReadSelectedComparisonOperator.GreaterOrEqual, value: number, valueType?: ReadSelectedPropertyType.Int | ReadSelectedPropertyType.Short | ReadSelectedPropertyType.Long | ReadSelectedPropertyType.Decimal | ReadSelectedPropertyType.Double | ReadSelectedPropertyType.Float): this;
|
|
77
|
+
/**
|
|
78
|
+
* Adds a boolean property comparison.
|
|
79
|
+
*/
|
|
80
|
+
whereBool<K extends keyof T>(propertyName: K, comparisonOperator: ReadSelectedComparisonOperator.Equal | ReadSelectedComparisonOperator.NotEqual, value: boolean): this;
|
|
81
|
+
/**
|
|
82
|
+
* Adds a date/time property comparison.
|
|
83
|
+
*/
|
|
84
|
+
whereDate<K extends keyof T>(propertyName: K, comparisonOperator: ReadSelectedComparisonOperator.Equal | ReadSelectedComparisonOperator.NotEqual | ReadSelectedComparisonOperator.LessThan | ReadSelectedComparisonOperator.LessOrEqual | ReadSelectedComparisonOperator.GreaterThan | ReadSelectedComparisonOperator.GreaterOrEqual, value: string | Date, valueType?: ReadSelectedPropertyType.DateTime | ReadSelectedPropertyType.DateTimeOffset | ReadSelectedPropertyType.DateOnly | ReadSelectedPropertyType.TimeOnly | ReadSelectedPropertyType.TimeSpan): this;
|
|
85
|
+
/**
|
|
86
|
+
* Adds an isNull check for a property.
|
|
87
|
+
*/
|
|
88
|
+
whereNull<K extends keyof T>(propertyName: K): this;
|
|
89
|
+
/**
|
|
90
|
+
* Adds an isNotNull check for a property.
|
|
91
|
+
*/
|
|
92
|
+
whereNotNull<K extends keyof T>(propertyName: K): this;
|
|
93
|
+
/**
|
|
94
|
+
* Adds criteria for a nested object property (navigation property).
|
|
95
|
+
*
|
|
96
|
+
* @param propertyName - The navigation property name
|
|
97
|
+
* @param builderFn - A function that receives a new builder for the nested type
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* // With explicit type for proper intellisense
|
|
101
|
+
* SearchBuilder.and<VehicleDto>()
|
|
102
|
+
* .nested<PersonDto>('driver', nested =>
|
|
103
|
+
* nested.whereString('name', ReadSelectedComparisonOperator.Contains, 'Alice')
|
|
104
|
+
* )
|
|
105
|
+
* .build();
|
|
106
|
+
*/
|
|
107
|
+
nested<TNested, K extends keyof T = keyof T>(propertyName: K, builderFn: (builder: SearchBuilder<TNested>) => SearchBuilder<TNested>): this;
|
|
108
|
+
/**
|
|
109
|
+
* Adds criteria for a collection property with Any quantifier.
|
|
110
|
+
* Matches if at least one element in the collection satisfies the criteria.
|
|
111
|
+
*
|
|
112
|
+
* @param propertyName - The collection property name
|
|
113
|
+
* @param builderFn - A function that receives a new builder for the collection element type
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* // With explicit type for proper intellisense
|
|
117
|
+
* SearchBuilder.and<VehicleDto>()
|
|
118
|
+
* .any<PersonDto>('passengers', passengers =>
|
|
119
|
+
* passengers.whereString('name', ReadSelectedComparisonOperator.Contains, 'Bob')
|
|
120
|
+
* )
|
|
121
|
+
* .build();
|
|
122
|
+
*/
|
|
123
|
+
any<TElement, K extends keyof T = keyof T>(propertyName: K, builderFn: (builder: SearchBuilder<TElement>) => SearchBuilder<TElement>): this;
|
|
124
|
+
/**
|
|
125
|
+
* Adds criteria for a collection property with All quantifier.
|
|
126
|
+
* Matches if all elements in the collection satisfy the criteria.
|
|
127
|
+
*
|
|
128
|
+
* @param propertyName - The collection property name
|
|
129
|
+
* @param builderFn - A function that receives a new builder for the collection element type
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* // With explicit type for proper intellisense
|
|
133
|
+
* SearchBuilder.and<VehicleDto>()
|
|
134
|
+
* .all<PersonDto>('passengers', passengers =>
|
|
135
|
+
* passengers.whereNumber('age', ReadSelectedComparisonOperator.GreaterThan, 18)
|
|
136
|
+
* )
|
|
137
|
+
* .build();
|
|
138
|
+
*/
|
|
139
|
+
all<TElement, K extends keyof T = keyof T>(propertyName: K, builderFn: (builder: SearchBuilder<TElement>) => SearchBuilder<TElement>): this;
|
|
140
|
+
/**
|
|
141
|
+
* Adds a nested search group. Use this for complex logical groupings.
|
|
142
|
+
*
|
|
143
|
+
* @param builderFn - A function that receives a new builder for creating the nested search
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* // (name contains 'John') AND ((age > 18) OR (status = 'verified'))
|
|
147
|
+
* SearchBuilder.and<User>()
|
|
148
|
+
* .whereString('name', ReadSelectedComparisonOperator.IContains, 'John')
|
|
149
|
+
* .group(sub => sub.or()
|
|
150
|
+
* .whereNumber('age', ReadSelectedComparisonOperator.GreaterThan, 18)
|
|
151
|
+
* .whereString('status', ReadSelectedComparisonOperator.Equal, 'verified')
|
|
152
|
+
* )
|
|
153
|
+
* .build();
|
|
154
|
+
*/
|
|
155
|
+
group(builderFn: (builder: SearchBuilder<T>) => SearchBuilder<T>): this;
|
|
156
|
+
/**
|
|
157
|
+
* Adds an existing search definition as a nested search.
|
|
158
|
+
*
|
|
159
|
+
* @param search - An existing ReadSelectedSearchDefinitionDto
|
|
160
|
+
*/
|
|
161
|
+
addSearch(search: ReadSelectedSearchDefinitionDto<T>): this;
|
|
162
|
+
/**
|
|
163
|
+
* Builds and returns the ReadSelectedSearchDefinitionDto.
|
|
164
|
+
*/
|
|
165
|
+
build(): ReadSelectedSearchDefinitionDto<T>;
|
|
166
|
+
private toPascalCase;
|
|
167
|
+
}
|