@futdevpro/fsm-dynamo 1.14.11 → 1.14.13

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.
Files changed (76) hide show
  1. package/.vscode/settings.json +11 -0
  2. package/build/_collections/utils/json-error-helper.util.d.ts.map +1 -1
  3. package/build/_collections/utils/json-error-helper.util.js.map +1 -1
  4. package/build/_collections/utils/stack.util.d.ts.map +1 -1
  5. package/build/_collections/utils/stack.util.js +3 -2
  6. package/build/_collections/utils/stack.util.js.map +1 -1
  7. package/build/_models/control-models/service-endpoint-settings-base.control-model.d.ts +22 -1
  8. package/build/_models/control-models/service-endpoint-settings-base.control-model.d.ts.map +1 -1
  9. package/build/_models/control-models/service-endpoint-settings-base.control-model.js +23 -1
  10. package/build/_models/control-models/service-endpoint-settings-base.control-model.js.map +1 -1
  11. package/build/_modules/ai/_modules/open-ai/index.d.ts.map +1 -1
  12. package/build/_modules/ai/_modules/open-ai/index.js +7 -7
  13. package/build/_modules/ai/_modules/open-ai/index.js.map +1 -1
  14. package/build/_modules/crypto/_collections/{crypto-2-non-stable.util.d.ts → crypto-v1.util.d.ts} +1 -1
  15. package/build/_modules/crypto/_collections/crypto-v1.util.d.ts.map +1 -0
  16. package/build/_modules/crypto/_collections/{crypto-2-non-stable.util.js → crypto-v1.util.js} +1 -1
  17. package/build/_modules/crypto/_collections/crypto-v1.util.js.map +1 -0
  18. package/build/_modules/crypto/_collections/{crypto-old.util.d.ts → crypto-v2.util.d.ts} +1 -1
  19. package/build/_modules/crypto/_collections/crypto-v2.util.d.ts.map +1 -0
  20. package/build/_modules/crypto/_collections/{crypto-old.util.js → crypto-v2.util.js} +10 -10
  21. package/build/_modules/crypto/_collections/crypto-v2.util.js.map +1 -0
  22. package/build/_modules/crypto/_collections/crypto-v4.util.d.ts +165 -0
  23. package/build/_modules/crypto/_collections/crypto-v4.util.d.ts.map +1 -0
  24. package/build/_modules/crypto/_collections/crypto-v4.util.js +611 -0
  25. package/build/_modules/crypto/_collections/crypto-v4.util.js.map +1 -0
  26. package/build/_modules/crypto/index.d.ts.map +1 -1
  27. package/build/_modules/crypto/index.js +7 -7
  28. package/build/_modules/crypto/index.js.map +1 -1
  29. package/build/_modules/data-handler/_models/data-handler-settings.control-model.d.ts +73 -0
  30. package/build/_modules/data-handler/_models/data-handler-settings.control-model.d.ts.map +1 -0
  31. package/build/_modules/data-handler/_models/data-handler-settings.control-model.js +83 -0
  32. package/build/_modules/data-handler/_models/data-handler-settings.control-model.js.map +1 -0
  33. package/build/_modules/data-handler/_models/data-handler.control-model.d.ts +136 -0
  34. package/build/_modules/data-handler/_models/data-handler.control-model.d.ts.map +1 -0
  35. package/build/_modules/data-handler/_models/data-handler.control-model.js +333 -0
  36. package/build/_modules/data-handler/_models/data-handler.control-model.js.map +1 -0
  37. package/build/_modules/data-handler/_models/data-list-handler.control-model.d.ts +111 -0
  38. package/build/_modules/data-handler/_models/data-list-handler.control-model.d.ts.map +1 -0
  39. package/build/_modules/data-handler/_models/data-list-handler.control-model.js +217 -0
  40. package/build/_modules/data-handler/_models/data-list-handler.control-model.js.map +1 -0
  41. package/build/_modules/data-handler/_models/data-search-handler.control-model.d.ts +172 -0
  42. package/build/_modules/data-handler/_models/data-search-handler.control-model.d.ts.map +1 -0
  43. package/build/_modules/data-handler/_models/data-search-handler.control-model.js +325 -0
  44. package/build/_modules/data-handler/_models/data-search-handler.control-model.js.map +1 -0
  45. package/build/_modules/data-handler/_models/list-collector-data-handler.control-model.d.ts +116 -0
  46. package/build/_modules/data-handler/_models/list-collector-data-handler.control-model.d.ts.map +1 -0
  47. package/build/_modules/data-handler/_models/list-collector-data-handler.control-model.js +245 -0
  48. package/build/_modules/data-handler/_models/list-collector-data-handler.control-model.js.map +1 -0
  49. package/build/_modules/data-handler/index.d.ts +6 -0
  50. package/build/_modules/data-handler/index.d.ts.map +1 -0
  51. package/build/_modules/data-handler/index.js +10 -0
  52. package/build/_modules/data-handler/index.js.map +1 -0
  53. package/eslint.config.js +4 -0
  54. package/futdevpro-fsm-dynamo-01.14.13.tgz +0 -0
  55. package/package.json +22 -3
  56. package/src/_collections/utils/json-error-helper.util.ts +5 -3
  57. package/src/_collections/utils/stack.util.ts +8 -4
  58. package/src/_models/control-models/service-endpoint-settings-base.control-model.ts +41 -4
  59. package/src/_modules/ai/_modules/open-ai/index.ts +4 -3
  60. package/src/_modules/crypto/_collections/{crypto-old.util.ts → crypto-v2.util.ts} +17 -9
  61. package/src/_modules/crypto/_collections/crypto-v4.util.ts +702 -0
  62. package/src/_modules/crypto/index.ts +4 -3
  63. package/src/_modules/data-handler/_models/data-handler-settings.control-model.ts +110 -0
  64. package/src/_modules/data-handler/_models/data-handler.control-model.ts +459 -0
  65. package/src/_modules/data-handler/_models/data-list-handler.control-model.ts +245 -0
  66. package/src/_modules/data-handler/_models/data-search-handler.control-model.ts +390 -0
  67. package/src/_modules/data-handler/_models/list-collector-data-handler.control-model.ts +274 -0
  68. package/src/_modules/data-handler/index.ts +6 -0
  69. package/src/_modules/usage/_collections/usg-module-settings.const.ts +1 -1
  70. package/.eslintrc.json +0 -155
  71. package/build/_modules/crypto/_collections/crypto-2-non-stable.util.d.ts.map +0 -1
  72. package/build/_modules/crypto/_collections/crypto-2-non-stable.util.js.map +0 -1
  73. package/build/_modules/crypto/_collections/crypto-old.util.d.ts.map +0 -1
  74. package/build/_modules/crypto/_collections/crypto-old.util.js.map +0 -1
  75. package/futdevpro-fsm-dynamo-01.14.11.tgz +0 -0
  76. /package/src/_modules/crypto/_collections/{crypto-2-non-stable.util.ts → crypto-v1.util.ts} +0 -0
@@ -0,0 +1,245 @@
1
+ import { BehaviorSubject, Observable } from 'rxjs';
2
+
3
+ import { DyFM_DataListHandler_Settings } from './data-handler-settings.control-model';
4
+
5
+ import { DyFM_DataHandler } from './data-handler.control-model';
6
+ import { DyFM_Metadata } from '../../../_models/data-models/metadata.data-model';
7
+ import { DyFM_Error } from '../../../_models/control-models/error.control-model';
8
+
9
+ /**
10
+ * A specialized data handler for managing arrays of data items.
11
+ * Extends DyFM_DataHandler to provide additional functionality for handling lists of data.
12
+ *
13
+ * @template T_DataList - The type of the data list (must be an array of T_DataItem)
14
+ * @template T_DependencyData - The type of dependency data (defaults to any)
15
+ * @template T_DataLoadBy - The type used to identify how data should be loaded (defaults to string)
16
+ * @template T_DataItem - The type of individual items in the list (must extend DyFM_Metadata)
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Create a data list handler for user messages
21
+ * const messagesHandler = new DyFM_DataListHandler<UserMessage[]>({
22
+ * get: async (userId: string): Promise<UserMessage[]> => {
23
+ * return await userApiService.getUserMessages(userId, 0, 100);
24
+ * }
25
+ * });
26
+ *
27
+ * // Access the data list
28
+ * const messages = messagesHandler.dataList;
29
+ *
30
+ * // Add a new message
31
+ * messagesHandler.addItem(newMessage);
32
+ *
33
+ * // Update an existing message
34
+ * messagesHandler.updateItem(updatedMessage);
35
+ *
36
+ * // Subscribe to changes
37
+ * messagesHandler.dataList$.subscribe(messages => {
38
+ * console.log('Messages updated:', messages);
39
+ * });
40
+ * ```
41
+ */
42
+ export class DyFM_DataListHandler<
43
+ T_DataItem extends DyFM_Metadata,
44
+ T_DependencyData extends DyFM_Metadata = any,
45
+ T_DataLoadBy = string,
46
+ T_UpdateItemBy = string,
47
+ > extends DyFM_DataHandler<T_DataItem[], T_DependencyData, T_DataLoadBy> {
48
+
49
+ protected readonly setItem: (item: T_DataItem, updateBy?: T_UpdateItemBy) => Promise<T_DataItem>;
50
+ protected readonly deleteItem: (id: string, updateBy?: T_UpdateItemBy) => Promise<void>;
51
+
52
+ /**
53
+ * BehaviorSubject that holds the current data list.
54
+ * Computed from the base data_BS BehaviorSubject, ensuring it always returns an array.
55
+ */
56
+ protected readonly dataList_BS: BehaviorSubject<T_DataItem[]>;
57
+
58
+ /**
59
+ * Observable that holds the current data list.
60
+ * Computed from the base data$ Observable, ensuring it always returns an array.
61
+ */
62
+ readonly dataList$: Observable<T_DataItem[]>;
63
+
64
+ /**
65
+ * BehaviorSubject that holds the currently active item.
66
+ */
67
+ readonly activeItem_BS: BehaviorSubject<T_DataItem>;
68
+
69
+ /**
70
+ * Observable that holds the currently active item.
71
+ */
72
+ readonly activeItem$: Observable<T_DataItem>;
73
+
74
+ /**
75
+ * Gets the current data list.
76
+ * @returns The current array of data items
77
+ */
78
+ override get data(): T_DataItem[] {
79
+ return this.dataList_BS.value;
80
+ }
81
+
82
+ /**
83
+ * Gets the current data list.
84
+ * Alias for data getter.
85
+ * @returns The current array of data items
86
+ */
87
+ get dataList(): T_DataItem[] {
88
+ return this.dataList_BS.value;
89
+ }
90
+
91
+ /**
92
+ * Creates a new instance of DyFM_DataListHandler.
93
+ *
94
+ * @param set - Configuration settings for the data handler
95
+ * @param skipDependencyConnections - Optional flag to skip dependency connections during construction
96
+ */
97
+ constructor(
98
+ set: DyFM_DataListHandler_Settings<T_DataItem, T_DependencyData, T_DataLoadBy, T_UpdateItemBy>,
99
+ /** is in construct?
100
+ * so the dependent data handlers are not added here, but in the extended class */
101
+ skipDependencyConnections?: boolean,
102
+ ) {
103
+ super(set, skipDependencyConnections);
104
+
105
+ // Initialize dataList BehaviorSubject and Observable
106
+ this.dataList_BS = new BehaviorSubject<T_DataItem[]>([]);
107
+ this.dataList$ = this.dataList_BS.asObservable();
108
+
109
+ // Initialize activeItem BehaviorSubject and Observable
110
+ this.activeItem_BS = new BehaviorSubject<T_DataItem>(null);
111
+ this.activeItem$ = this.activeItem_BS.asObservable();
112
+
113
+ // Subscribe to data changes to update dataList
114
+ this.data$.subscribe(data => {
115
+ const dataList = Array.isArray(data) ? data : [];
116
+ this.dataList_BS.next(dataList);
117
+ });
118
+
119
+ if (set.setItem) {
120
+ this.setItem = set.setItem;
121
+ }
122
+
123
+ if (set.deleteItem) {
124
+ this.deleteItem = set.deleteItem;
125
+ }
126
+
127
+ this.getPostProcesses.push((data: T_DataItem[]) => {
128
+ // check if data is an array
129
+ if (!Array.isArray(data) ) {
130
+ console.error(
131
+ `DYNAMO DataListHandler (${this.name}) ERROR: ` +
132
+ `\nData is not an array!:` +
133
+ '\n\n', data
134
+ );
135
+ throw new Error(`Data is not an array! (${this.name})`);
136
+ }
137
+
138
+ return data;
139
+ });
140
+
141
+ if (!skipDependencyConnections) {
142
+ if (set.dependencyDataHandler) {
143
+ this.addDependencyDataHandler(set.dependencyDataHandler);
144
+ }
145
+
146
+ if (set.dependentDataHandlers) {
147
+ this.addDependentDataHandlers(set.dependentDataHandlers, true);
148
+ }
149
+ }
150
+ }
151
+
152
+ override async reloadData(loadBy?: T_DataLoadBy): Promise<T_DataItem[]> {
153
+ const setActiveItem = !this.activeItem_BS.value || this.activeItem_BS.value?._id !== loadBy;
154
+ const dataList = await super.reloadData(loadBy);
155
+ if (setActiveItem && dataList.length > 0) {
156
+ this.setActiveItem(dataList[0]);
157
+ }
158
+ return dataList;
159
+ }
160
+
161
+ override clear(dontClearDependents?: boolean): void {
162
+ super.clear(dontClearDependents);
163
+ this.activeItem_BS.next(null);
164
+ }
165
+
166
+ /**
167
+ * Adds a new item to the data list.
168
+ *
169
+ * @param item - The item to add to the list
170
+ * @param updateBy - Optional parameter for update tracking
171
+ * @param dontSendUpdate - Optional flag to prevent sending update notification
172
+ */
173
+ async addItem(item: T_DataItem, updateBy?: T_UpdateItemBy, dontSendUpdate?: boolean): Promise<void> {
174
+ const currentData = this.data;
175
+ currentData.push(item);
176
+ if (this.setItem && !dontSendUpdate) {
177
+ await this.setItem(item, updateBy);
178
+ // dont send update because we already sent it to the setItem function
179
+ await this.updateData(this.dataList_BS.value, true);
180
+ } else {
181
+ await this.updateData(this.dataList_BS.value, dontSendUpdate);
182
+ }
183
+ this.activeItem_BS.next(item);
184
+ }
185
+
186
+ /**
187
+ * Removes an item from the data list.
188
+ * The item is identified by its _id property.
189
+ *
190
+ * @param id - The id of the item to remove from the list
191
+ * @param updateBy - Optional parameter for update tracking
192
+ * @param dontSendUpdate - Optional flag to prevent sending update notification
193
+ */
194
+ async removeItem(id: string, updateBy?: T_UpdateItemBy, dontSendUpdate?: boolean): Promise<void> {
195
+ const currentData = this.data;
196
+ const index = currentData.findIndex(i => i._id === id);
197
+ if (index !== -1) {
198
+ currentData.splice(index, 1);
199
+ if (this.deleteItem) {
200
+ await this.deleteItem(id, updateBy);
201
+ await this.updateData(this.dataList_BS.value, true);
202
+ } else {
203
+ await this.updateData(this.dataList_BS.value, dontSendUpdate);
204
+ }
205
+ }
206
+ if (this.activeItem_BS.value?._id === id) {
207
+ this.activeItem_BS.next(null);
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Updates an existing item in the data list.
213
+ * The item is identified by its _id property.
214
+ *
215
+ * @param item - The updated item
216
+ * @param updateBy - Optional parameter for update tracking
217
+ * @param dontSendUpdate - Optional flag to prevent sending update notification
218
+ * @throws Error if the item is not found in the list
219
+ */
220
+ async updateItem(item: T_DataItem, updateBy?: T_UpdateItemBy, dontSendUpdate?: boolean): Promise<void> {
221
+ const currentData = this.data;
222
+ const index = currentData.findIndex(i => i._id === item._id);
223
+ if (index !== -1) {
224
+ currentData[index] = item;
225
+ if (this.setItem) {
226
+ await this.setItem(item, updateBy);
227
+ await this.updateData(this.dataList_BS.value, true);
228
+ } else {
229
+ await this.updateData(this.dataList_BS.value, dontSendUpdate);
230
+ }
231
+ } else {
232
+ throw new DyFM_Error({
233
+ error: new Error(`Item not found! (${this.name})`),
234
+ errorCode: 'DyFM-DLH-UI1',
235
+ additionalContent: {
236
+ item: item,
237
+ },
238
+ });
239
+ }
240
+ }
241
+
242
+ setActiveItem(item: T_DataItem): void {
243
+ this.activeItem_BS.next(item);
244
+ }
245
+ }
@@ -0,0 +1,390 @@
1
+ import { debounceTime, Subject } from 'rxjs';
2
+
3
+ import { DyFM_DataSearchHandler_Settings } from './data-handler-settings.control-model';
4
+
5
+ import { DyFM_DataListHandler } from './data-list-handler.control-model';
6
+ import { DyFM_Object } from '../../../_collections/utils/object.util';
7
+ import { DyFM_Metadata } from '../../../_models/data-models/metadata.data-model';
8
+ import { DyFM_SearchQuery } from '../../../_models/interfaces/search-query.interface';
9
+ import { DyFM_SearchResult } from '../../../_models/interfaces/search-result.interface';
10
+ import { DyFM_DSFilter } from '../../../_models/types/ds-filter.type';
11
+ import { DyFM_DSSort, DyFM_DSPropertySort } from '../../../_models/types/ds-sort.type';
12
+
13
+ interface SearchCache<T> {
14
+ page: number;
15
+ loadPageSize: number;
16
+ data: T[];
17
+ }
18
+
19
+ /**
20
+ * A specialized data handler for managing searchable data with pagination and caching.
21
+ * Extends DyFM_DataListHandler to provide additional functionality for handling search results.
22
+ *
23
+ * @template T_Data - The type of data items in the search results
24
+ * @template T_DataLoadBy - The type of search query (must extend DyFM_SearchQuery)
25
+ * @template T_Result - The type of search result (must extend DyFM_SearchResult)
26
+ * @template T_DependencyData - The type of dependency data (defaults to any)
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * // Create a search handler for flow runs
31
+ * const flowRunsHandler = new DyFM_DataSearchHandler<FlowRun_Preview>({
32
+ * name: 'myRuns',
33
+ * get: async (query?: DyFM_SearchQuery<FlowRun>): Promise<DyFM_SearchResult<FlowRun_Preview>> => {
34
+ * return await flowRunService.searchFlowRuns(query);
35
+ * },
36
+ * defaultQuery: {
37
+ * filterBy: { userId: currentUserId },
38
+ * pageSize: 20
39
+ * },
40
+ * queryUpdateDebounceTime: 500
41
+ * });
42
+ *
43
+ * // Update search query
44
+ * flowRunsHandler.updateQuery({
45
+ * page: 0,
46
+ * pageSize: 10,
47
+ * filterBy: { status: 'completed' }
48
+ * });
49
+ *
50
+ * // Access search results
51
+ * const runs = flowRunsHandler.dataList;
52
+ *
53
+ * // Get total items count
54
+ * const totalItems = flowRunsHandler.totalItems;
55
+ * ```
56
+ */
57
+ export class DyFM_DataSearchHandler<
58
+ T_Data,
59
+ T_DataLoadBy extends DyFM_SearchQuery<any> = DyFM_SearchQuery<T_Data>,
60
+ T_Result extends DyFM_SearchResult<any> = DyFM_SearchResult<T_Data>,
61
+ T_DependencyData extends DyFM_Metadata = any,
62
+ > extends DyFM_DataListHandler<T_Data, T_DependencyData, T_DataLoadBy> {
63
+
64
+ /**
65
+ * Subject for handling fresh search queries with debouncing.
66
+ * Used internally to manage query updates.
67
+ */
68
+ protected readonly _freshQuery_S = new Subject<T_DataLoadBy>();
69
+
70
+ /**
71
+ * Cache of search results for different pages.
72
+ * Helps optimize performance by storing previously loaded results.
73
+ */
74
+ protected cache: SearchCache<T_Data>[] = [];
75
+
76
+ /**
77
+ * Override of the get method to handle search queries.
78
+ * Must be implemented to fetch search results from the data source.
79
+ */
80
+ // this is redundant, because the base class has the get method and it uses Generic type
81
+ /* override get: (query?: T_DataLoadBy) => Promise<T_Result>; */
82
+
83
+ /**
84
+ * Maximum number of cached pages to keep in memory.
85
+ * Default is 5 pages.
86
+ */
87
+ protected cacheSize: number = 5;
88
+
89
+ /**
90
+ * Default number of items per page.
91
+ * Used when no pageSize is specified in the query.
92
+ */
93
+ protected defaultPageSize: number = 10;
94
+
95
+ /**
96
+ * Default search query to use when no query is provided.
97
+ * Can include default filters, sorting, and pagination settings.
98
+ */
99
+ protected get defaultQuery(): T_DataLoadBy {
100
+ return DyFM_Object.clone(this._defaultQuery);
101
+ }
102
+
103
+ protected _defaultQuery?: T_DataLoadBy;
104
+
105
+ /**
106
+ * Total number of items available in the search results.
107
+ * Updated after each successful search.
108
+ */
109
+ protected totalItems: number;
110
+
111
+ /**
112
+ * Debounce time in milliseconds for query updates.
113
+ * Helps prevent too frequent API calls when query changes rapidly.
114
+ */
115
+ protected queryUpdateDebounceTime: number = 500;
116
+
117
+ /**
118
+ * Whether to perform initial search when handler is created.
119
+ * If true, will use defaultQuery for initial search.
120
+ */
121
+ protected searchOnInit: boolean = true;
122
+
123
+ /**
124
+ * Creates a new instance of DyFM_DataSearchHandler.
125
+ *
126
+ * @param set - Configuration settings for the search handler
127
+ */
128
+ constructor(
129
+ set: DyFM_DataSearchHandler_Settings<T_Data, T_DataLoadBy, T_DependencyData>
130
+ ) {
131
+ super({
132
+ ...set,
133
+ noId: true,
134
+ });
135
+
136
+ if (set.queryUpdateDebounceTime) {
137
+ this.queryUpdateDebounceTime = set.queryUpdateDebounceTime;
138
+ }
139
+
140
+ if (set.defaultQuery) {
141
+ this._defaultQuery = set.defaultQuery;
142
+ }
143
+
144
+ // 3
145
+ // Add post-processing for search results
146
+ this.getPostProcesses.unshift(
147
+ (searchResult: T_Result, loadedBy: T_DataLoadBy): T_Data[] => {
148
+ console.warn('WTF DyFM_Search_DataHandler getPostProcess', searchResult, this.lastLoadedBy);
149
+
150
+ this.cache = this.cache.filter((c) => c.loadPageSize !== this.lastLoadedBy?.pageSize);
151
+
152
+ if (this.cache.length >= this.cacheSize) {
153
+ this.cache.shift();
154
+ }
155
+
156
+ this.cache.push({
157
+ page: this.lastLoadedBy?.page,
158
+ loadPageSize: this.lastLoadedBy?.pageSize,
159
+ data: searchResult.results,
160
+ });
161
+
162
+ this.totalItems = searchResult.totalItems;
163
+
164
+ return searchResult.results;
165
+ }
166
+ );
167
+
168
+ // 2
169
+ // Set up query update handling with debouncing
170
+ this._freshQuery_S.pipe(
171
+ debounceTime(this.queryUpdateDebounceTime),
172
+ ).subscribe((query: T_DataLoadBy) => {
173
+ console.warn('asd', query, this.lastLoadedBy);
174
+
175
+ if (!query) {
176
+ if (!this._defaultQuery) {
177
+ this.reloadData();
178
+ return;
179
+ }
180
+
181
+ query = this.defaultQuery;
182
+ }
183
+
184
+ if (!query.page) {
185
+ query.page = 0;
186
+ }
187
+
188
+ if (!query.pageSize) {
189
+ query.pageSize = this.defaultPageSize;
190
+ }
191
+
192
+ if (this._defaultQuery?.filterBy) {
193
+ if (!query.filterBy) {
194
+ query.filterBy = {};
195
+ }
196
+
197
+ for (const key in this._defaultQuery.filterBy) {
198
+ if (!query.filterBy[key] && query.filterBy[key] !== null) {
199
+ query.filterBy[key] = this._defaultQuery.filterBy[key];
200
+ }
201
+ }
202
+ }
203
+
204
+ if (this._defaultQuery?.sortBy) {
205
+ if (!query.sortBy) {
206
+ query.sortBy = [];
207
+ }
208
+
209
+ if (!query.sortBy.length) {
210
+ query.sortBy = DyFM_Object.clone(this._defaultQuery.sortBy);
211
+ }
212
+ }
213
+
214
+ this.reloadData(query);
215
+ });
216
+
217
+ if (this.searchOnInit) {
218
+ this._freshQuery_S.next(this.defaultQuery);
219
+ }
220
+ }
221
+
222
+ // 1
223
+ /**
224
+ * Updates the search query and triggers a new search.
225
+ * The search will be debounced according to queryUpdateDebounceTime.
226
+ *
227
+ * @param query - The new search query to use
228
+ */
229
+ updateQuery(query: T_DataLoadBy): void {
230
+ this._freshQuery_S.next(query);
231
+ }
232
+
233
+ /**
234
+ * Override to prevent adding dependent data handlers.
235
+ * Search handlers cannot have dependencies.
236
+ *
237
+ * @throws Error - Always throws as search handlers cannot have dependencies
238
+ */
239
+ override addDependentDataHandlers(dependentDataHandlers: any[]): void {
240
+ throw new Error('Cannot add dependent data handlers to a search data handler');
241
+ }
242
+
243
+ /**
244
+ * Filters the current search query
245
+ *
246
+ * @param filterBy - The filter to apply to the current search query
247
+ */
248
+ filter(filterBy: DyFM_DSFilter<T_Data>): void {
249
+ const query = this.lastLoadedBy ?? this.defaultQuery;
250
+ if (query) {
251
+ query.filterBy = filterBy;
252
+ this.reloadData(query);
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Adds a filter to the current search query
258
+ *
259
+ * @param filterBy - The filter to add to the current search query
260
+ */
261
+ addFiler(filterBy: DyFM_DSFilter<T_Data>): void {
262
+ const query = this.lastLoadedBy ?? this.defaultQuery;
263
+ if (query) {
264
+ Object.assign(query.filterBy, filterBy);
265
+ this.reloadData(query);
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Removes a filter from the current search query
271
+ *
272
+ * @param keys - The keys of the filter to remove from the current search query
273
+ */
274
+ removeFilter(keys: (keyof T_Data)[]): void {
275
+ const query = this.lastLoadedBy ?? this.defaultQuery;
276
+ if (query) {
277
+ keys.forEach((key) => {
278
+ delete query.filterBy[key];
279
+ });
280
+
281
+ this.reloadData(query);
282
+ }
283
+ }
284
+
285
+ clearFilters(): void {
286
+ const query = this.lastLoadedBy ?? this.defaultQuery;
287
+ if (query) {
288
+ query.filterBy = {};
289
+ this.reloadData(query);
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Sorts the current search query
295
+ *
296
+ * @param sortBy - The sort to apply to the current search query
297
+ */
298
+ sort(sortBy: DyFM_DSSort[]): void {
299
+ const query = this.lastLoadedBy ?? this.defaultQuery;
300
+ if (query) {
301
+ query.sortBy = sortBy;
302
+ this.reloadData(query);
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Adds a sort to the current search query
308
+ *
309
+ * @param sortBy - The sort to add to the current search query
310
+ */
311
+ addSort(sortBy: DyFM_DSSort[]): void {
312
+ const query = this.lastLoadedBy ?? this.defaultQuery;
313
+ if (query) {
314
+ query.sortBy.push(...sortBy);
315
+ this.reloadData(query);
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Removes a sort from the current search query
321
+ *
322
+ * @param keys - The keys of the sort to remove from the current search query
323
+ */
324
+ removeSort(keys: string[]): void {
325
+ const query = this.lastLoadedBy ?? this.defaultQuery;
326
+ if (query) {
327
+ query.sortBy = query.sortBy.filter((sort) => !keys.includes((sort as DyFM_DSPropertySort).key));
328
+ this.reloadData(query);
329
+ }
330
+ }
331
+
332
+ clearSorts(): void {
333
+ const query = this.lastLoadedBy ?? this.defaultQuery;
334
+ if (query) {
335
+ query.sortBy = [];
336
+ this.reloadData(query);
337
+ }
338
+ }
339
+
340
+ /**
341
+ * Sets the page of the current search query
342
+ *
343
+ * @param page - The page to set to the current search query
344
+ */
345
+ page(page: number, pageSize?: number): void {
346
+ const query = this.lastLoadedBy ?? this.defaultQuery;
347
+ if (query) {
348
+ query.page = page;
349
+ if (pageSize) {
350
+ query.pageSize = pageSize;
351
+ }
352
+ this.reloadData(query);
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Sets the page size of the current search query
358
+ *
359
+ * @param pageSize - The page size to set to the current search query
360
+ */
361
+ pageSize(pageSize: number): void {
362
+ const query = this.lastLoadedBy ?? this.defaultQuery;
363
+ if (query) {
364
+ query.pageSize = pageSize;
365
+ this.reloadData(query);
366
+ }
367
+ }
368
+
369
+ resetPage(): void {
370
+ const query = this.lastLoadedBy ?? this.defaultQuery;
371
+ if (query) {
372
+ query.page = 0;
373
+ query.pageSize = this.defaultPageSize;
374
+ this.reloadData(query);
375
+ }
376
+ }
377
+
378
+ resetQuery(): void {
379
+ const query = this.defaultQuery;
380
+ if (query) {
381
+ this.reloadData(query);
382
+ } else {
383
+ query.filterBy = {};
384
+ query.sortBy = [];
385
+ query.page = 0;
386
+ query.pageSize = this.defaultPageSize;
387
+ this.reloadData(query);
388
+ }
389
+ }
390
+ }