@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,302 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IIdentifiable,
|
|
3
|
+
ReadSelectedComparisonOperator,
|
|
4
|
+
ReadSelectedDefinitionDto,
|
|
5
|
+
ReadSelectedLogicalOperator,
|
|
6
|
+
ReadSelectedOrderingDirection,
|
|
7
|
+
ReadSelectedPropertyType,
|
|
8
|
+
ReadSelectedSearchDefinitionDto,
|
|
9
|
+
ReadSelectedSearchPropertyDefinitionDto,
|
|
10
|
+
} from '@data';
|
|
11
|
+
import { ApiReadControllerClient } from '@services';
|
|
12
|
+
|
|
13
|
+
export type SearchAdapterOptions<T> = {
|
|
14
|
+
controllerName: string;
|
|
15
|
+
typesToSearch: string[]; // provide known searchable types
|
|
16
|
+
multiselect: boolean;
|
|
17
|
+
searchTriggerMinLength: number;
|
|
18
|
+
searchDebounceDelay: number;
|
|
19
|
+
limitSearchToSelectedType: boolean; // when item is selected, limit results to items of same type
|
|
20
|
+
resultsLimit: number;
|
|
21
|
+
additionalSearchDefinitions?: ReadSelectedSearchDefinitionDto<T>[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
class SingularEventTarget<T> {
|
|
25
|
+
private _target = new EventTarget();
|
|
26
|
+
|
|
27
|
+
public addEventListener(callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void {
|
|
28
|
+
this._target.addEventListener('change', callback, options);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public dispatchEvent(value: T) {
|
|
32
|
+
this._target.dispatchEvent(new CustomEvent('change', { detail: value }));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IGlobalSearchable<TKey> extends IIdentifiable<TKey> {
|
|
37
|
+
type: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class SearchAdapter<TKey, TDto extends IGlobalSearchable<TKey>> {
|
|
41
|
+
public onChange = new SingularEventTarget<string>();
|
|
42
|
+
// inputs
|
|
43
|
+
private _readClient!: ApiReadControllerClient<TKey, TDto, TDto>;
|
|
44
|
+
public options!: SearchAdapterOptions<TDto>;
|
|
45
|
+
private _isLoading = false;
|
|
46
|
+
private _currentAbortController?: AbortController;
|
|
47
|
+
private _lastSearchedValue: string | undefined = undefined;
|
|
48
|
+
private _typesToSearch: string[] = [];
|
|
49
|
+
private _fetchResultsDataTimeout?: any;
|
|
50
|
+
private _fetchResultsPromises: {
|
|
51
|
+
resolve: (value: TDto[] | PromiseLike<TDto[]>) => void;
|
|
52
|
+
reject: (reason?: unknown) => void;
|
|
53
|
+
}[] = [];
|
|
54
|
+
private _totalCount = 0;
|
|
55
|
+
|
|
56
|
+
constructor(options: SearchAdapterOptions<TDto>) {
|
|
57
|
+
this.options = options;
|
|
58
|
+
this._readClient = new ApiReadControllerClient<TKey, TDto, TDto>(options.controllerName);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public get searchTriggerMinLength() {
|
|
62
|
+
return this.options.searchTriggerMinLength;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public get multiselect() {
|
|
66
|
+
return this.options.multiselect;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public get isLoading() {
|
|
70
|
+
return this._isLoading;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public get totalCount() {
|
|
74
|
+
return this._totalCount;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public get hasMoreRecords() {
|
|
78
|
+
return this._totalCount > this._searchResults.length;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private _searchText: string = '';
|
|
82
|
+
|
|
83
|
+
public get searchText() {
|
|
84
|
+
return this._searchText;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public set searchText(searchText: string) {
|
|
88
|
+
this._searchText = searchText;
|
|
89
|
+
this._trySearch();
|
|
90
|
+
this._emitChange();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private _searchResults: TDto[] = [];
|
|
94
|
+
|
|
95
|
+
public get searchResults() {
|
|
96
|
+
return this._searchResults;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected set searchResults(searchResults: TDto[]) {
|
|
100
|
+
this._searchResults = [...searchResults];
|
|
101
|
+
this._emitChange();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private _selectedItems: TDto[] = [];
|
|
105
|
+
|
|
106
|
+
public get selectedItems() {
|
|
107
|
+
return this._selectedItems;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public set selectedItems(selectedItems: TDto[]) {
|
|
111
|
+
this._selectedItems = [...selectedItems];
|
|
112
|
+
this._emitChange();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public addToSelection(item: TDto): void {
|
|
116
|
+
if (!this._selectedItems) {
|
|
117
|
+
this.selectedItems = [];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// selection mode
|
|
121
|
+
if (this.options.multiselect) {
|
|
122
|
+
if (!this._selectedItems.find(s => s.id === item.id)) {
|
|
123
|
+
this.selectedItems = [...this.selectedItems, item];
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
// single-select mode - replace the item and return the old one to shown results
|
|
127
|
+
if (this._selectedItems.length > 0) {
|
|
128
|
+
this.searchResults = this._sortByName([...this._searchResults, ...this._selectedItems]); // return the to-be-replaced selected item back to shown results list
|
|
129
|
+
}
|
|
130
|
+
this.selectedItems = [item];
|
|
131
|
+
}
|
|
132
|
+
this.searchResults = this._sortByName(this._searchResults.filter(d => d.id !== item.id)); // remove the new selection from the shown results
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public removeFromSelection(item: TDto): void {
|
|
136
|
+
if (!this._selectedItems) {
|
|
137
|
+
this.selectedItems = [];
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this.selectedItems = this._selectedItems.filter(s => s.id !== item.id);
|
|
142
|
+
this.searchResults = this._sortByName([...this._searchResults, item]);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private _emitChange() {
|
|
146
|
+
this.onChange.dispatchEvent('onChange');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private async _trySearch() {
|
|
150
|
+
const options = this.options;
|
|
151
|
+
|
|
152
|
+
this.searchResults = [];
|
|
153
|
+
if (this._searchText.length < options.searchTriggerMinLength) return;
|
|
154
|
+
if (this._searchText === this._lastSearchedValue) return;
|
|
155
|
+
this._lastSearchedValue = this._searchText;
|
|
156
|
+
|
|
157
|
+
this._typesToSearch =
|
|
158
|
+
options.limitSearchToSelectedType && this._selectedItems.length ? [(this._selectedItems[0] as TDto).type] : this.options.typesToSearch;
|
|
159
|
+
|
|
160
|
+
this.searchResults = this._sortByName(await this._fetchResults(options.searchDebounceDelay));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private async _fetchResults(debounceDelay: number): Promise<TDto[]> {
|
|
164
|
+
this._isLoading = true;
|
|
165
|
+
|
|
166
|
+
return new Promise((resolve, reject) => {
|
|
167
|
+
this._fetchResultsPromises.push({ resolve, reject });
|
|
168
|
+
if (this._fetchResultsDataTimeout !== undefined) {
|
|
169
|
+
clearTimeout(this._fetchResultsDataTimeout);
|
|
170
|
+
}
|
|
171
|
+
this._fetchResultsDataTimeout = setTimeout(async () => {
|
|
172
|
+
try {
|
|
173
|
+
const result = await this._fetchResultsDebounced();
|
|
174
|
+
const promises = this._fetchResultsPromises.splice(0, this._fetchResultsPromises.length);
|
|
175
|
+
for (const p of promises) p.resolve(result);
|
|
176
|
+
} catch (err) {
|
|
177
|
+
const promises = this._fetchResultsPromises.splice(0, this._fetchResultsPromises.length);
|
|
178
|
+
for (const p of promises) p.reject(err);
|
|
179
|
+
}
|
|
180
|
+
}, debounceDelay);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private async _fetchResultsDebounced(): Promise<TDto[]> {
|
|
185
|
+
let abortController: AbortController | undefined;
|
|
186
|
+
let caughtError: unknown;
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
// Cancel any in-flight request before starting a new one
|
|
190
|
+
if (this._currentAbortController) {
|
|
191
|
+
try {
|
|
192
|
+
this._currentAbortController.abort();
|
|
193
|
+
} catch {
|
|
194
|
+
// Ignore abort errors as they are expected when debouncing
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
abortController = new AbortController();
|
|
198
|
+
this._currentAbortController = abortController;
|
|
199
|
+
|
|
200
|
+
const definition = this._parseToSearchDefinition();
|
|
201
|
+
const response = await this._readClient.readSelected(definition, abortController?.signal);
|
|
202
|
+
|
|
203
|
+
if (!response.ok) {
|
|
204
|
+
throw response.error;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Update total count from response metadata
|
|
208
|
+
this._totalCount = response.metadata?.totalCount ?? response.result.length;
|
|
209
|
+
|
|
210
|
+
// Filter out selected items from new results
|
|
211
|
+
const selectedIds = new Set((this.selectedItems || []).map(item => item.id));
|
|
212
|
+
return response.result.filter(item => !selectedIds.has(item.id));
|
|
213
|
+
} catch (error: unknown) {
|
|
214
|
+
caughtError = error;
|
|
215
|
+
|
|
216
|
+
// Do not log abort-related errors as they are expected when debouncing
|
|
217
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
218
|
+
return Promise.reject(error);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
console.error('Error fetching data:', error);
|
|
222
|
+
return Promise.reject(error);
|
|
223
|
+
} finally {
|
|
224
|
+
this._isLoading = false;
|
|
225
|
+
|
|
226
|
+
let errorName: string | undefined;
|
|
227
|
+
if (caughtError && !(caughtError instanceof DOMException && caughtError.name === 'AbortError')) {
|
|
228
|
+
errorName = caughtError instanceof Error ? caughtError.name : undefined;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Clear the abort controller only if it belongs to this request (avoid racing with a newer one)
|
|
232
|
+
if (abortController && this._currentAbortController === abortController) {
|
|
233
|
+
this._currentAbortController = undefined;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private _parseToSearchDefinition(): ReadSelectedDefinitionDto<TDto> {
|
|
239
|
+
const definition: ReadSelectedDefinitionDto<TDto> = {
|
|
240
|
+
paginationDefinition: {
|
|
241
|
+
skip: 0,
|
|
242
|
+
limit: this.options.resultsLimit,
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// Apply ordering
|
|
247
|
+
definition.orderingDefinition = {
|
|
248
|
+
order: [
|
|
249
|
+
{
|
|
250
|
+
propertyPath: ['Name'],
|
|
251
|
+
direction: ReadSelectedOrderingDirection.Ascending,
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// Apply search
|
|
257
|
+
const propertyCriteria: ReadSelectedSearchPropertyDefinitionDto<TDto, keyof TDto>[] = [
|
|
258
|
+
{
|
|
259
|
+
propertyName: 'Name' as any,
|
|
260
|
+
comparisonOperator: ReadSelectedComparisonOperator.IContains,
|
|
261
|
+
valueType: ReadSelectedPropertyType.String,
|
|
262
|
+
value: this._searchText,
|
|
263
|
+
},
|
|
264
|
+
];
|
|
265
|
+
|
|
266
|
+
definition.searchDefinition = {
|
|
267
|
+
logicalOperator: ReadSelectedLogicalOperator.And,
|
|
268
|
+
propertyCriteria: propertyCriteria,
|
|
269
|
+
} as ReadSelectedSearchDefinitionDto<TDto>;
|
|
270
|
+
|
|
271
|
+
if (this._typesToSearch !== undefined && this._typesToSearch.length > 0) {
|
|
272
|
+
definition.searchDefinition.searches = [
|
|
273
|
+
{
|
|
274
|
+
logicalOperator: ReadSelectedLogicalOperator.Or,
|
|
275
|
+
propertyCriteria: this._typesToSearch.map(
|
|
276
|
+
type =>
|
|
277
|
+
({
|
|
278
|
+
propertyName: 'Type',
|
|
279
|
+
comparisonOperator: ReadSelectedComparisonOperator.IEqual,
|
|
280
|
+
valueType: ReadSelectedPropertyType.String,
|
|
281
|
+
value: type,
|
|
282
|
+
}) as ReadSelectedSearchPropertyDefinitionDto<TDto, keyof TDto>,
|
|
283
|
+
),
|
|
284
|
+
},
|
|
285
|
+
];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (this.options.additionalSearchDefinitions && this.options.additionalSearchDefinitions.length > 0) {
|
|
289
|
+
definition.searchDefinition.searches = [...(definition.searchDefinition.searches ?? []), ...this.options.additionalSearchDefinitions];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return definition;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
private _sortByName(array: TDto[]): TDto[] {
|
|
296
|
+
return array.sort((a, b) => {
|
|
297
|
+
const nameA = (a as any).name?.toLowerCase() || '';
|
|
298
|
+
const nameB = (b as any).name?.toLowerCase() || '';
|
|
299
|
+
return nameA.localeCompare(nameB);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReadResultMetadataDto } from './ReadResultMetadataDto';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a read result containing a collection of results and metadata.
|
|
5
|
+
*
|
|
6
|
+
* @template T The type of result in the collection.
|
|
7
|
+
* @property {T[]} items - The collection of results returned.
|
|
8
|
+
* @property {ReadResultMetadata} metadata - Metadata about the paginated result.
|
|
9
|
+
*/
|
|
10
|
+
export type ReadResultDto<T> = {
|
|
11
|
+
results: T[];
|
|
12
|
+
metadata: ReadResultMetadataDto;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CrudMetadataDto';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReadSelectedPaginationDefinitionDto, ReadSelectedOrderingDefinitionDto, ReadSelectedSearchDefinitionDto } from '@data';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defines the selection criteria for a controller to fetch multiple records
|
|
5
|
+
*/
|
|
6
|
+
export type ReadSelectedDefinitionDto<T> = {
|
|
7
|
+
/**
|
|
8
|
+
* Pagination definition
|
|
9
|
+
*/
|
|
10
|
+
paginationDefinition?: ReadSelectedPaginationDefinitionDto;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Ordering definition
|
|
14
|
+
*/
|
|
15
|
+
orderingDefinition?: ReadSelectedOrderingDefinitionDto;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Search definition (supports both simple search and nested logical groups)
|
|
19
|
+
*/
|
|
20
|
+
searchDefinition?: ReadSelectedSearchDefinitionDto<T>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ReadSelectedCollectionOperator, ReadSelectedSearchDefinitionDto } from '@data';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defines criteria for searching within a collection navigation property using quantifiers (Any/All).
|
|
5
|
+
*
|
|
6
|
+
* This DTO allows navigation into a collection property and applying search criteria
|
|
7
|
+
* with a quantifier to determine if any or all elements match.
|
|
8
|
+
*/
|
|
9
|
+
export type ReadSelectedNestedCollectionCriteriaDto<T, TPropertyName extends keyof T> = {
|
|
10
|
+
/**
|
|
11
|
+
* The name of the collection navigation property to navigate into.
|
|
12
|
+
*/
|
|
13
|
+
propertyName: TPropertyName;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The quantifier operator determining whether any or all elements must match.
|
|
17
|
+
*/
|
|
18
|
+
collectionOperator: ReadSelectedCollectionOperator;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The search criteria to apply to elements in the collection.
|
|
22
|
+
* Type should be ReadSelectedSearchDefinitionDto of the collection element type.
|
|
23
|
+
*/
|
|
24
|
+
criteria: ReadSelectedSearchDefinitionDto<unknown>;
|
|
25
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {ReadSelectedSearchDefinitionDto} from '@data';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defines criteria for searching within a nested object property.
|
|
5
|
+
*
|
|
6
|
+
* This DTO allows navigation into a nested object property and applying search criteria
|
|
7
|
+
* to that nested object. The property name must refer to a navigation property (not a collection).
|
|
8
|
+
*/
|
|
9
|
+
export type ReadSelectedNestedCriteriaDto<T, TPropertyName extends keyof T> = {
|
|
10
|
+
/**
|
|
11
|
+
* The name of the navigation property to navigate into.
|
|
12
|
+
*/
|
|
13
|
+
propertyName: TPropertyName;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The search criteria to apply to the nested object.
|
|
17
|
+
* Type should be ReadSelectedSearchDefinitionDto of the nested object type.
|
|
18
|
+
*/
|
|
19
|
+
criteria: ReadSelectedSearchDefinitionDto<unknown>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PropertyPathDto, ReadSelectedOrderingDirection } from '@data';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defines the ordering property for a controller.
|
|
5
|
+
*/
|
|
6
|
+
export type ReadSelectedOrderingPropertyDefinitionDto = {
|
|
7
|
+
/**
|
|
8
|
+
* Gets or sets the property path.
|
|
9
|
+
*/
|
|
10
|
+
propertyPath: PropertyPathDto;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Gets or sets the ordering direction.
|
|
14
|
+
*/
|
|
15
|
+
direction: ReadSelectedOrderingDirection;
|
|
16
|
+
};
|