@eui/core 17.0.0-rc.7 → 17.0.0-rc.8

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.
@@ -4,71 +4,256 @@ import { ApiQueueItem } from '@eui/base';
4
4
  import { LogService } from '../log';
5
5
  import { StoreService } from '../store';
6
6
  import * as i0 from "@angular/core";
7
+ /**
8
+ * Service class for managing and processing a queue of API requests.
9
+ *
10
+ * This service provides functionality to add, remove, process, and manage HTTP requests stored in a queue.
11
+ * It enables sequential or bulk processing of requests, ensuring controlled execution and handling of API calls.
12
+ * The service methods offer features like processing individual items, processing all items in the queue either
13
+ * sequentially or all at once, and removing items from the queue. Each method is designed to handle specific aspects
14
+ * of queue management and processing, with attention to details like order of execution and error handling.
15
+ *
16
+ * Usage of this service is ideal in scenarios where API requests need to be managed in a queue structure, allowing
17
+ * for controlled execution and monitoring of these requests.
18
+ *
19
+ * @example
20
+ * // Adding a new item to the queue
21
+ * apiQueueService.addQueueItem({ id: 'item124', method: 'POST', uri: '/api/data', payload: {...} });
22
+ *
23
+ * // Processing a single item from the queue
24
+ * apiQueueService.processQueueItem('item123').subscribe(result => {
25
+ * console.log('Processed item 123 with result:', result);
26
+ * });
27
+ *
28
+ * // Processing all items in the queue in sequential order
29
+ * apiQueueService.processAllQueueItemsSequential(false).subscribe(results => {
30
+ * console.log('Processed all items in descending order of their timestamp:', results);
31
+ * });
32
+ *
33
+ * // Removing an item from the queue
34
+ * apiQueueService.removeQueueItem('item123');
35
+ *
36
+ * // Processing all items in the queue and continuing on error
37
+ * apiQueueService.processAllQueueItems(true).subscribe(results => {
38
+ * console.log('Processed all items in the queue with continuation on errors:', results);
39
+ * });
40
+ */
7
41
  export declare class ApiQueueService {
8
42
  protected store: StoreService;
9
43
  protected http: HttpClient;
10
44
  protected logService: LogService;
11
45
  constructor(store: StoreService, http: HttpClient, logService: LogService);
12
46
  /**
13
- * Adds an item in the queue by dispatching an action to the store.
14
- * @param id - The id of the item inside the queue.
15
- * WARNING if matches any other queue item id will overwrite it.
16
- * @param item - an item for Queue
47
+ * Adds an item to the queue by dispatching an action to the store.
48
+ * This function is specifically designed to enqueue API call requests represented by `ApiQueueItem` objects.
49
+ * Each item is identified by a unique `id`, which is used to manage the queue.
50
+ *
51
+ * @param {string} id - The unique identifier for the queue item. It's crucial to ensure that this ID is unique within the queue.
52
+ * If an item with the same ID already exists, the new item will overwrite the existing one.
53
+ * WARNING: Duplicate IDs will lead to overwriting of queue items.
54
+ *
55
+ * @param {ApiQueueItem} item - The item to be enqueued. This should be an object of type `ApiQueueItem`.
56
+ * The `method` property of the item must be one of the allowed methods ('post', 'put', 'get').
57
+ * If an unsupported method is provided, the function will throw an error.
58
+ *
59
+ * @throws {Error} Throws an error if the `method` property of the `item` is not one of the allowed methods.
60
+ * The error message is: `[ApiQueue] method "${item.method}" is not allowed`.
61
+ *
62
+ * @example
63
+ * // Example of adding an item to the API queue
64
+ * addQueueItem('12345', { method: 'post', url: '/api/data', payload: {...} });
65
+ *
66
+ * @returns {void} This function does not return a value. It adds the item to the queue via a dispatch action.
17
67
  */
18
68
  addQueueItem(id: string, item: ApiQueueItem): void;
19
69
  /**
20
- * Subscribes to the store to retrieve queue and then converts the queue object to an array of items.
21
- * @return An Observable of array of all items inside the current queue (ApiQueueItem[])
70
+ * Retrieves the current state of the API queue and converts it into an array of Observables.
71
+ *
72
+ * This method subscribes to the store to access the API queue. It then maps the queue object,
73
+ * which is an associative array, into a linear array of ApiQueueItem instances. If the queue is empty,
74
+ * a warning is logged. This method is useful for tracking the state and contents of the API queue
75
+ * at a given moment.
76
+ *
77
+ * Note: This method takes a snapshot of the queue at the time of subscription. It does not provide
78
+ * a continuous stream of queue updates. To get real-time updates, consider subscribing directly
79
+ * to the store's observable.
80
+ *
81
+ * @returns {Observable<ApiQueueItem[]>} An Observable that emits an array of ApiQueueItem.
82
+ * The array represents all items currently in the queue. If the queue is empty, it emits an empty array.
83
+ *
84
+ * @example
85
+ * // Example usage
86
+ * this.getQueue().subscribe(queueItems => {
87
+ * console.log('Current queue items:', queueItems);
88
+ * });
22
89
  */
23
90
  getQueue(): Observable<ApiQueueItem[]>;
24
91
  /**
25
- * Subscribes to the store to retrieve an item from the queue.
26
- * @param id - id of the item inside the queue
27
- * @return An Observable of ApiQueueItem type
92
+ * Retrieves a specific item from the API queue by its ID.
93
+ *
94
+ * This method subscribes to the store and selects a single item from the API queue based on the provided ID.
95
+ * It employs a pipeline to fetch the item: the `getApiQueueItem` selector is used to retrieve the item,
96
+ * and a `map` operator processes the result. If the item with the specified ID does not exist in the queue,
97
+ * a warning is logged, and `null` is returned.
98
+ *
99
+ * This method is ideal for accessing a specific queue item when its ID is known, allowing for targeted
100
+ * operations or checks on that particular item.
101
+ *
102
+ * @param {string} id - The unique identifier of the item within the queue.
103
+ * @returns {Observable<ApiQueueItem | null>} An Observable emitting the requested ApiQueueItem.
104
+ * If no item with the given ID exists in the queue, the Observable emits `null`.
105
+ *
106
+ * @example
107
+ * // Example usage
108
+ * this.getQueueItem('item123').subscribe(item => {
109
+ * if (item) {
110
+ * console.log('Found item:', item);
111
+ * } else {
112
+ * console.log('Item not found in the queue');
113
+ * }
114
+ * });
28
115
  */
29
116
  getQueueItem(id: string): Observable<ApiQueueItem>;
30
117
  /**
31
- * Removes a given item from the queue.
32
- * @param id - id of the item inside the queue
118
+ * Removes a specific item from the API queue using its ID.
119
+ *
120
+ * This method dispatches an action to remove an item from the queue, identified by the provided ID.
121
+ * It is essential for managing the queue by eliminating items that are no longer needed or have been processed.
122
+ * The function does not return any value, as it primarily triggers an action within the store.
123
+ *
124
+ * Note: This method assumes the existence of the item in the queue. It does not perform a check
125
+ * to confirm the presence of the item before attempting to remove it. Therefore, it's recommended
126
+ * to verify the item's existence in the queue if uncertainty exists.
127
+ *
128
+ * @param {string} id - The unique identifier of the item to be removed from the queue.
129
+ *
130
+ * @example
131
+ * // Example usage
132
+ * this.removeQueueItem('item123');
133
+ * // The item with ID 'item123' will be dispatched for removal from the queue.
33
134
  */
34
135
  removeQueueItem(id: string): void;
35
136
  /**
36
- * Removes all items placed in the queue.
137
+ * Clears all items from the API queue.
138
+ *
139
+ * This method dispatches an action to empty the entire API queue, effectively removing all items that are currently queued.
140
+ * It is useful for scenarios where a complete reset of the queue is required, such as during initialization or after processing
141
+ * a batch of items. The function does not return any value, as its primary purpose is to trigger a state change in the store.
142
+ *
143
+ * Note: Use this method with caution as it will irreversibly clear all items in the queue. Ensure that this action does not
144
+ * disrupt any ongoing processes that rely on the queue's contents.
145
+ *
146
+ * @example
147
+ * // Example usage
148
+ * this.removeAllQueueItem();
149
+ * // This will dispatch an action to empty the entire API queue.
37
150
  */
38
151
  removeAllQueueItem(): void;
39
152
  /**
40
- * Process an item from the queue.
41
- * @param id - id of the item inside the queue
42
- * @return An Observable of type any
153
+ * Processes an item from the API queue identified by its ID.
154
+ *
155
+ * Retrieves the specified item from the queue and applies processing logic as defined in `buildHttpRequest`.
156
+ * If the item is not found, logs a warning and returns an Observable emitting `null`.
157
+ *
158
+ * @param {string} id - The unique identifier of the item within the queue to be processed.
159
+ * @returns {Observable<any>} An Observable that emits the result of processing the queue item.
160
+ * If the item does not exist, the Observable emits `null`.
161
+ *
162
+ * @example
163
+ * // Example usage
164
+ * this.processQueueItem('item123').subscribe(result => {
165
+ * if (result) {
166
+ * console.log('Processing result:', result);
167
+ * } else {
168
+ * console.log('Item not found in the queue');
169
+ * }
170
+ * });
43
171
  */
44
172
  processQueueItem(id: string): Observable<any>;
45
173
  /**
46
- * Process all the items inside the queue.
47
- * @param [continueOnError=true] - in case of an item request fails continue with the rest in queue
48
- * @return An Observable with an array which contains all responses from all items in queue.
174
+ * Processes all items in the API queue and collects their responses.
175
+ *
176
+ * Iterates over each item in the queue and processes them using `buildHttpRequest`. If a request fails,
177
+ * the method can either continue processing the remaining items or stop, based on the `continueOnError` parameter.
178
+ * It returns an Observable that emits an array containing the responses or errors from all the processed items.
179
+ *
180
+ * The function currently returns `Observable<any[]>` indicating an array of any type. Future improvements
181
+ * should aim to specify a more accurate return type or utilize generics for increased type safety.
182
+ *
183
+ * @param {boolean} [continueOnError=true] - Determines whether to continue with the next item in the queue
184
+ * after a request failure. Defaults to `true`.
185
+ * @returns {Observable<any[]>} An Observable emitting an array of either responses or errors from the processed
186
+ * queue items.
187
+ *
188
+ * @example
189
+ * this.processAllQueueItems().subscribe(results => {
190
+ * // Handle the array of responses or errors
191
+ * });
49
192
  */
50
- processAllQueueItems(continueOnError?: boolean): Observable<any[]>;
193
+ processAllQueueItems<T = any>(continueOnError?: boolean): Observable<T[]>;
51
194
  /**
52
- * Process all items in queue after it order them based on their timestamp. Beware that order
53
- * matter in execution of Http Request in queue. When a request completes only then next will begin. Emission
54
- * or Http response follows order.
55
- * @param [ascending=true] - sets the order of queue items based on timestamp
195
+ * Processes all items in the queue sequentially, based on their timestamp ordering.
196
+ *
197
+ * This method first orders the items in the API queue by their timestamp, either in ascending or descending
198
+ * order as specified by the `ascending` parameter. It then processes each item using `buildHttpRequest`, ensuring
199
+ * that each request is completed before the next begins. This sequential processing is crucial when the order of
200
+ * execution matters for HTTP requests in the queue. The method returns an Observable that emits the responses
201
+ * following the same order as the queue items were processed.
202
+ *
203
+ * The function currently returns `Observable<any>`, indicating a broad type. Future improvements should focus on
204
+ * specifying a more accurate return type or utilizing generics for increased type safety.
205
+ *
206
+ * @param {boolean} [ascending=true] - Determines whether the queue items are processed in ascending order of their
207
+ * timestamp. Defaults to `true`.
208
+ * @returns {Observable<any>} An Observable emitting the responses of the HTTP requests in the order they were processed.
209
+ *
210
+ * @example
211
+ * this.processAllQueueItemsSequential().subscribe(response => {
212
+ * // Handle each response in the order of queue processing
213
+ * });
56
214
  */
57
215
  processAllQueueItemsSequential(ascending?: boolean): Observable<any>;
58
216
  /**
59
- * Short dates ascending based on input
60
- * @param a - Date one
61
- * @param b - Date two
217
+ * Compares two queue items based on their timestamp and determines their order.
218
+ *
219
+ * This protected method is used to sort queue items. It takes two queue items as input, each represented
220
+ * as a tuple containing an item ID and the `ApiQueueItem` object. The method compares these items based on
221
+ * the `timestamp` property of the `ApiQueueItem` objects. It returns a number indicating the order in which
222
+ * these items should be sorted.
62
223
  *
224
+ * A positive return value indicates that the first item should come after the second, a negative value
225
+ * indicates the opposite, and zero indicates that they are equal in terms of timestamp.
226
+ *
227
+ * @param {[string, ApiQueueItem]} a - The first queue item tuple for comparison.
228
+ * @param {[string, ApiQueueItem]} b - The second queue item tuple for comparison.
229
+ * @returns {number} A number indicating the order of the items: negative if `a` is earlier than `b`,
230
+ * positive if `a` is later than `b`, and zero if they are equal.
63
231
  * @beta
64
232
  */
65
233
  protected sortOnTimestamp(a: [string, ApiQueueItem], b: [string, ApiQueueItem]): number;
66
234
  /**
67
- * build and HttpRequest Observable based on the given queue.
68
- * After successful request completion removes the item from the queue.
69
- * @param id - id of the item inside the queue
70
- * @param item - the item of the queue that matches the id.
71
- * @return An Observable of HttpClient Request
235
+ * Constructs and executes an HTTP request based on the provided queue item details.
236
+ *
237
+ * This private method takes an ID and an `ApiQueueItem` object to build and execute an HTTP request.
238
+ * It determines the HTTP method (like GET, POST, etc.) from the `method` property of the `ApiQueueItem`,
239
+ * and uses the `uri` and `payload` properties for the request's URL and body, respectively. After the
240
+ * request is executed, the corresponding queue item is removed from the queue.
241
+ *
242
+ * The method is generic, allowing the caller to specify the expected response type `T`. By default,
243
+ * it uses `any` type, but specifying a more concrete type enhances type safety and clarity in usage.
244
+ *
245
+ * @param {string} id - The ID of the queue item being processed.
246
+ * @param {ApiQueueItem} item - The queue item containing details for the HTTP request.
247
+ * @returns {Observable<T>} An Observable of type T, representing the response of the HTTP request.
248
+ *
249
+ * @example
250
+ * // Example usage for a specific response type
251
+ * this.buildHttpRequest<MyResponseType>('item123', queueItem)
252
+ * .subscribe(response => {
253
+ * // Handle the response
254
+ * });
255
+ *
256
+ * @template T - The expected type of the HTTP response. Defaults to `any`.
72
257
  */
73
258
  private buildHttpRequest;
74
259
  static ɵfac: i0.ɵɵFactoryDeclaration<ApiQueueService, [null, null, { optional: true; }]>;
@@ -1 +1 @@
1
- {"version":3,"file":"api-queue.service.d.ts","sourceRoot":"","sources":["../../../../src/lib/services/queue/api-queue.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAgB,MAAM,MAAM,CAAC;AAEhD,OAAO,EAA0C,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAwE,MAAM,UAAU,CAAC;;AAE9G,qBAGa,eAAe;IAEpB,SAAS,CAAC,KAAK,EAAE,YAAY;IAC7B,SAAS,CAAC,IAAI,EAAE,UAAU;IACd,SAAS,CAAC,UAAU,EAAE,UAAU;gBAFlC,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,UAAU,EACJ,UAAU,EAAE,UAAU;IAGhD;;;;;OAKG;IACH,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI;IAUlD;;;OAGG;IACH,QAAQ,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;IActC;;;;OAIG;IACH,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC,YAAY,CAAC;IAalD;;;OAGG;IACH,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIjC;;OAEG;IACH,kBAAkB,IAAI,IAAI;IAI1B;;;;OAIG;IAGH,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC;IAc7C;;;;OAIG;IAGH,oBAAoB,CAAC,eAAe,UAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC;IAuB/D;;;;;OAKG;IAGH,8BAA8B,CAAC,SAAS,UAAO,GAAG,UAAU,CAAC,GAAG,CAAC;IAUjE;;;;;;OAMG;IACH,SAAS,CAAC,eAAe,CAAC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;;;;;;;;;;OAmBG;IAGH,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC;IAc7C;;;;;;;;;;;;;;;;;;;OAmBG;IAGH,oBAAoB,CAAC,CAAC,GAAG,GAAG,EAAE,eAAe,UAAO,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC;IAqBtE;;;;;;;;;;;;;;;;;;;;OAoBG;IAGH,8BAA8B,CAAC,SAAS,UAAO,GAAG,UAAU,CAAC,GAAG,CAAC;IAWjE;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM;IAIvF;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAIH,OAAO,CAAC,gBAAgB;yCA1Tf,eAAe;6CAAf,eAAe;CA6T3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eui/core",
3
- "version": "17.0.0-rc.7",
3
+ "version": "17.0.0-rc.8",
4
4
  "tag": "next",
5
5
  "description": "eUI core package - holding UI components for Desktop applications",
6
6
  "homepage": "https://eui.ecdevops.eu",