@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.
@@ -6,7 +6,7 @@ import { InjectionToken, Injectable, Inject, Injector, NgModule, Optional, APP_I
6
6
  import * as extendProxy from 'extend';
7
7
  import * as i1$1 from '@ngrx/effects';
8
8
  import { createEffect, ofType } from '@ngrx/effects';
9
- import { fromEvent, merge, throwError, of, forkJoin, BehaviorSubject, defer, firstValueFrom, from, Subject, Observable } from 'rxjs';
9
+ import { fromEvent, merge, throwError, of, forkJoin, from, BehaviorSubject, defer, firstValueFrom, Subject, Observable } from 'rxjs';
10
10
  import { map, mapTo, mergeMap, tap, debounceTime, distinctUntilChanged, take, switchMap, catchError, concatMap, filter, takeUntil, finalize } from 'rxjs/operators';
11
11
  import * as i1$2 from '@ngx-translate/core';
12
12
  import { TranslateLoader } from '@ngx-translate/core';
@@ -1257,6 +1257,40 @@ function GrowlHttpErrorCallbackFn(error, injector) {
1257
1257
  asService.growlError(error.statusText);
1258
1258
  }
1259
1259
 
1260
+ /**
1261
+ * Service class for managing and processing a queue of API requests.
1262
+ *
1263
+ * This service provides functionality to add, remove, process, and manage HTTP requests stored in a queue.
1264
+ * It enables sequential or bulk processing of requests, ensuring controlled execution and handling of API calls.
1265
+ * The service methods offer features like processing individual items, processing all items in the queue either
1266
+ * sequentially or all at once, and removing items from the queue. Each method is designed to handle specific aspects
1267
+ * of queue management and processing, with attention to details like order of execution and error handling.
1268
+ *
1269
+ * Usage of this service is ideal in scenarios where API requests need to be managed in a queue structure, allowing
1270
+ * for controlled execution and monitoring of these requests.
1271
+ *
1272
+ * @example
1273
+ * // Adding a new item to the queue
1274
+ * apiQueueService.addQueueItem({ id: 'item124', method: 'POST', uri: '/api/data', payload: {...} });
1275
+ *
1276
+ * // Processing a single item from the queue
1277
+ * apiQueueService.processQueueItem('item123').subscribe(result => {
1278
+ * console.log('Processed item 123 with result:', result);
1279
+ * });
1280
+ *
1281
+ * // Processing all items in the queue in sequential order
1282
+ * apiQueueService.processAllQueueItemsSequential(false).subscribe(results => {
1283
+ * console.log('Processed all items in descending order of their timestamp:', results);
1284
+ * });
1285
+ *
1286
+ * // Removing an item from the queue
1287
+ * apiQueueService.removeQueueItem('item123');
1288
+ *
1289
+ * // Processing all items in the queue and continuing on error
1290
+ * apiQueueService.processAllQueueItems(true).subscribe(results => {
1291
+ * console.log('Processed all items in the queue with continuation on errors:', results);
1292
+ * });
1293
+ */
1260
1294
  class ApiQueueService {
1261
1295
  constructor(store, http, logService) {
1262
1296
  this.store = store;
@@ -1264,10 +1298,26 @@ class ApiQueueService {
1264
1298
  this.logService = logService;
1265
1299
  }
1266
1300
  /**
1267
- * Adds an item in the queue by dispatching an action to the store.
1268
- * @param id - The id of the item inside the queue.
1269
- * WARNING if matches any other queue item id will overwrite it.
1270
- * @param item - an item for Queue
1301
+ * Adds an item to the queue by dispatching an action to the store.
1302
+ * This function is specifically designed to enqueue API call requests represented by `ApiQueueItem` objects.
1303
+ * Each item is identified by a unique `id`, which is used to manage the queue.
1304
+ *
1305
+ * @param {string} id - The unique identifier for the queue item. It's crucial to ensure that this ID is unique within the queue.
1306
+ * If an item with the same ID already exists, the new item will overwrite the existing one.
1307
+ * WARNING: Duplicate IDs will lead to overwriting of queue items.
1308
+ *
1309
+ * @param {ApiQueueItem} item - The item to be enqueued. This should be an object of type `ApiQueueItem`.
1310
+ * The `method` property of the item must be one of the allowed methods ('post', 'put', 'get').
1311
+ * If an unsupported method is provided, the function will throw an error.
1312
+ *
1313
+ * @throws {Error} Throws an error if the `method` property of the `item` is not one of the allowed methods.
1314
+ * The error message is: `[ApiQueue] method "${item.method}" is not allowed`.
1315
+ *
1316
+ * @example
1317
+ * // Example of adding an item to the API queue
1318
+ * addQueueItem('12345', { method: 'post', url: '/api/data', payload: {...} });
1319
+ *
1320
+ * @returns {void} This function does not return a value. It adds the item to the queue via a dispatch action.
1271
1321
  */
1272
1322
  addQueueItem(id, item) {
1273
1323
  const allowedMethods = ['post', 'put', 'get'];
@@ -1277,8 +1327,25 @@ class ApiQueueService {
1277
1327
  this.store.dispatch(new AddApiQueueItemAction({ id, item }));
1278
1328
  }
1279
1329
  /**
1280
- * Subscribes to the store to retrieve queue and then converts the queue object to an array of items.
1281
- * @return An Observable of array of all items inside the current queue (ApiQueueItem[])
1330
+ * Retrieves the current state of the API queue and converts it into an array of Observables.
1331
+ *
1332
+ * This method subscribes to the store to access the API queue. It then maps the queue object,
1333
+ * which is an associative array, into a linear array of ApiQueueItem instances. If the queue is empty,
1334
+ * a warning is logged. This method is useful for tracking the state and contents of the API queue
1335
+ * at a given moment.
1336
+ *
1337
+ * Note: This method takes a snapshot of the queue at the time of subscription. It does not provide
1338
+ * a continuous stream of queue updates. To get real-time updates, consider subscribing directly
1339
+ * to the store's observable.
1340
+ *
1341
+ * @returns {Observable<ApiQueueItem[]>} An Observable that emits an array of ApiQueueItem.
1342
+ * The array represents all items currently in the queue. If the queue is empty, it emits an empty array.
1343
+ *
1344
+ * @example
1345
+ * // Example usage
1346
+ * this.getQueue().subscribe(queueItems => {
1347
+ * console.log('Current queue items:', queueItems);
1348
+ * });
1282
1349
  */
1283
1350
  getQueue() {
1284
1351
  return this.store.select(getApiQueue).pipe(take(1), map((queue) => {
@@ -1290,9 +1357,29 @@ class ApiQueueService {
1290
1357
  }));
1291
1358
  }
1292
1359
  /**
1293
- * Subscribes to the store to retrieve an item from the queue.
1294
- * @param id - id of the item inside the queue
1295
- * @return An Observable of ApiQueueItem type
1360
+ * Retrieves a specific item from the API queue by its ID.
1361
+ *
1362
+ * This method subscribes to the store and selects a single item from the API queue based on the provided ID.
1363
+ * It employs a pipeline to fetch the item: the `getApiQueueItem` selector is used to retrieve the item,
1364
+ * and a `map` operator processes the result. If the item with the specified ID does not exist in the queue,
1365
+ * a warning is logged, and `null` is returned.
1366
+ *
1367
+ * This method is ideal for accessing a specific queue item when its ID is known, allowing for targeted
1368
+ * operations or checks on that particular item.
1369
+ *
1370
+ * @param {string} id - The unique identifier of the item within the queue.
1371
+ * @returns {Observable<ApiQueueItem | null>} An Observable emitting the requested ApiQueueItem.
1372
+ * If no item with the given ID exists in the queue, the Observable emits `null`.
1373
+ *
1374
+ * @example
1375
+ * // Example usage
1376
+ * this.getQueueItem('item123').subscribe(item => {
1377
+ * if (item) {
1378
+ * console.log('Found item:', item);
1379
+ * } else {
1380
+ * console.log('Item not found in the queue');
1381
+ * }
1382
+ * });
1296
1383
  */
1297
1384
  getQueueItem(id) {
1298
1385
  return this.store.select(getApiQueueItem(id)).pipe(take(1), map((queue) => {
@@ -1304,24 +1391,65 @@ class ApiQueueService {
1304
1391
  }));
1305
1392
  }
1306
1393
  /**
1307
- * Removes a given item from the queue.
1308
- * @param id - id of the item inside the queue
1394
+ * Removes a specific item from the API queue using its ID.
1395
+ *
1396
+ * This method dispatches an action to remove an item from the queue, identified by the provided ID.
1397
+ * It is essential for managing the queue by eliminating items that are no longer needed or have been processed.
1398
+ * The function does not return any value, as it primarily triggers an action within the store.
1399
+ *
1400
+ * Note: This method assumes the existence of the item in the queue. It does not perform a check
1401
+ * to confirm the presence of the item before attempting to remove it. Therefore, it's recommended
1402
+ * to verify the item's existence in the queue if uncertainty exists.
1403
+ *
1404
+ * @param {string} id - The unique identifier of the item to be removed from the queue.
1405
+ *
1406
+ * @example
1407
+ * // Example usage
1408
+ * this.removeQueueItem('item123');
1409
+ * // The item with ID 'item123' will be dispatched for removal from the queue.
1309
1410
  */
1310
1411
  removeQueueItem(id) {
1311
1412
  this.store.dispatch(new RemoveApiQueueItemAction(id));
1312
1413
  }
1313
1414
  /**
1314
- * Removes all items placed in the queue.
1415
+ * Clears all items from the API queue.
1416
+ *
1417
+ * This method dispatches an action to empty the entire API queue, effectively removing all items that are currently queued.
1418
+ * It is useful for scenarios where a complete reset of the queue is required, such as during initialization or after processing
1419
+ * a batch of items. The function does not return any value, as its primary purpose is to trigger a state change in the store.
1420
+ *
1421
+ * Note: Use this method with caution as it will irreversibly clear all items in the queue. Ensure that this action does not
1422
+ * disrupt any ongoing processes that rely on the queue's contents.
1423
+ *
1424
+ * @example
1425
+ * // Example usage
1426
+ * this.removeAllQueueItem();
1427
+ * // This will dispatch an action to empty the entire API queue.
1315
1428
  */
1316
1429
  removeAllQueueItem() {
1317
1430
  this.store.dispatch(new EmptyApiQueueAction(null));
1318
1431
  }
1319
1432
  /**
1320
- * Process an item from the queue.
1321
- * @param id - id of the item inside the queue
1322
- * @return An Observable of type any
1433
+ * Processes an item from the API queue identified by its ID.
1434
+ *
1435
+ * Retrieves the specified item from the queue and applies processing logic as defined in `buildHttpRequest`.
1436
+ * If the item is not found, logs a warning and returns an Observable emitting `null`.
1437
+ *
1438
+ * @param {string} id - The unique identifier of the item within the queue to be processed.
1439
+ * @returns {Observable<any>} An Observable that emits the result of processing the queue item.
1440
+ * If the item does not exist, the Observable emits `null`.
1441
+ *
1442
+ * @example
1443
+ * // Example usage
1444
+ * this.processQueueItem('item123').subscribe(result => {
1445
+ * if (result) {
1446
+ * console.log('Processing result:', result);
1447
+ * } else {
1448
+ * console.log('Item not found in the queue');
1449
+ * }
1450
+ * });
1323
1451
  */
1324
- // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html
1452
+ // TODO: Replace `any` with a more specific type or make the method generic, https://www.typescriptlang.org/docs/handbook/2/generics.html
1325
1453
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1326
1454
  processQueueItem(id) {
1327
1455
  return this.store.select(getApiQueueItem(id)).pipe(take(1), switchMap((queue) => {
@@ -1333,11 +1461,26 @@ class ApiQueueService {
1333
1461
  }));
1334
1462
  }
1335
1463
  /**
1336
- * Process all the items inside the queue.
1337
- * @param [continueOnError=true] - in case of an item request fails continue with the rest in queue
1338
- * @return An Observable with an array which contains all responses from all items in queue.
1464
+ * Processes all items in the API queue and collects their responses.
1465
+ *
1466
+ * Iterates over each item in the queue and processes them using `buildHttpRequest`. If a request fails,
1467
+ * the method can either continue processing the remaining items or stop, based on the `continueOnError` parameter.
1468
+ * It returns an Observable that emits an array containing the responses or errors from all the processed items.
1469
+ *
1470
+ * The function currently returns `Observable<any[]>` indicating an array of any type. Future improvements
1471
+ * should aim to specify a more accurate return type or utilize generics for increased type safety.
1472
+ *
1473
+ * @param {boolean} [continueOnError=true] - Determines whether to continue with the next item in the queue
1474
+ * after a request failure. Defaults to `true`.
1475
+ * @returns {Observable<any[]>} An Observable emitting an array of either responses or errors from the processed
1476
+ * queue items.
1477
+ *
1478
+ * @example
1479
+ * this.processAllQueueItems().subscribe(results => {
1480
+ * // Handle the array of responses or errors
1481
+ * });
1339
1482
  */
1340
- // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html
1483
+ // TODO: Refine the return type to be more specific or implement generics, https://www.typescriptlang.org/docs/handbook/2/generics.html
1341
1484
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1342
1485
  processAllQueueItems(continueOnError = true) {
1343
1486
  return this.store.select(getApiQueue).pipe(map((queue) => Object.entries(queue).map(([key, value]) => this.buildHttpRequest(key, value).pipe(catchError((error) => {
@@ -1346,40 +1489,80 @@ class ApiQueueService {
1346
1489
  throw error;
1347
1490
  }
1348
1491
  return of(error);
1349
- })))),
1350
- // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html
1351
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1352
- switchMap((obsQueue) => forkJoin(Array.from(obsQueue))));
1492
+ })))), switchMap((obsQueue) => forkJoin(Array.from(obsQueue))));
1353
1493
  }
1354
1494
  /**
1355
- * Process all items in queue after it order them based on their timestamp. Beware that order
1356
- * matter in execution of Http Request in queue. When a request completes only then next will begin. Emission
1357
- * or Http response follows order.
1358
- * @param [ascending=true] - sets the order of queue items based on timestamp
1495
+ * Processes all items in the queue sequentially, based on their timestamp ordering.
1496
+ *
1497
+ * This method first orders the items in the API queue by their timestamp, either in ascending or descending
1498
+ * order as specified by the `ascending` parameter. It then processes each item using `buildHttpRequest`, ensuring
1499
+ * that each request is completed before the next begins. This sequential processing is crucial when the order of
1500
+ * execution matters for HTTP requests in the queue. The method returns an Observable that emits the responses
1501
+ * following the same order as the queue items were processed.
1502
+ *
1503
+ * The function currently returns `Observable<any>`, indicating a broad type. Future improvements should focus on
1504
+ * specifying a more accurate return type or utilizing generics for increased type safety.
1505
+ *
1506
+ * @param {boolean} [ascending=true] - Determines whether the queue items are processed in ascending order of their
1507
+ * timestamp. Defaults to `true`.
1508
+ * @returns {Observable<any>} An Observable emitting the responses of the HTTP requests in the order they were processed.
1509
+ *
1510
+ * @example
1511
+ * this.processAllQueueItemsSequential().subscribe(response => {
1512
+ * // Handle each response in the order of queue processing
1513
+ * });
1359
1514
  */
1360
- // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html
1515
+ // TODO: Refine the return type for more specific or implement generics, https://www.typescriptlang.org/docs/handbook/2/generics.html
1361
1516
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1362
1517
  processAllQueueItemsSequential(ascending = true) {
1363
- return this.store.select(getApiQueue).pipe(concatMap((queue) => Object.entries(queue)
1518
+ return this.store.select(getApiQueue).pipe(switchMap((queue) => from(Object.entries(queue)
1364
1519
  .sort((a, b) => (ascending ? this.sortOnTimestamp(a, b) : this.sortOnTimestamp(b, a)))
1365
- .map(([id, item]) => this.buildHttpRequest(id, item))));
1520
+ .map(([id, item]) => this.buildHttpRequest(id, item)))
1521
+ .pipe(concatMap(x => x))));
1366
1522
  }
1367
1523
  /**
1368
- * Short dates ascending based on input
1369
- * @param a - Date one
1370
- * @param b - Date two
1524
+ * Compares two queue items based on their timestamp and determines their order.
1525
+ *
1526
+ * This protected method is used to sort queue items. It takes two queue items as input, each represented
1527
+ * as a tuple containing an item ID and the `ApiQueueItem` object. The method compares these items based on
1528
+ * the `timestamp` property of the `ApiQueueItem` objects. It returns a number indicating the order in which
1529
+ * these items should be sorted.
1371
1530
  *
1531
+ * A positive return value indicates that the first item should come after the second, a negative value
1532
+ * indicates the opposite, and zero indicates that they are equal in terms of timestamp.
1533
+ *
1534
+ * @param {[string, ApiQueueItem]} a - The first queue item tuple for comparison.
1535
+ * @param {[string, ApiQueueItem]} b - The second queue item tuple for comparison.
1536
+ * @returns {number} A number indicating the order of the items: negative if `a` is earlier than `b`,
1537
+ * positive if `a` is later than `b`, and zero if they are equal.
1372
1538
  * @beta
1373
1539
  */
1374
1540
  sortOnTimestamp(a, b) {
1375
1541
  return +new Date(a[1].timestamp) - +new Date(b[1].timestamp);
1376
1542
  }
1377
1543
  /**
1378
- * build and HttpRequest Observable based on the given queue.
1379
- * After successful request completion removes the item from the queue.
1380
- * @param id - id of the item inside the queue
1381
- * @param item - the item of the queue that matches the id.
1382
- * @return An Observable of HttpClient Request
1544
+ * Constructs and executes an HTTP request based on the provided queue item details.
1545
+ *
1546
+ * This private method takes an ID and an `ApiQueueItem` object to build and execute an HTTP request.
1547
+ * It determines the HTTP method (like GET, POST, etc.) from the `method` property of the `ApiQueueItem`,
1548
+ * and uses the `uri` and `payload` properties for the request's URL and body, respectively. After the
1549
+ * request is executed, the corresponding queue item is removed from the queue.
1550
+ *
1551
+ * The method is generic, allowing the caller to specify the expected response type `T`. By default,
1552
+ * it uses `any` type, but specifying a more concrete type enhances type safety and clarity in usage.
1553
+ *
1554
+ * @param {string} id - The ID of the queue item being processed.
1555
+ * @param {ApiQueueItem} item - The queue item containing details for the HTTP request.
1556
+ * @returns {Observable<T>} An Observable of type T, representing the response of the HTTP request.
1557
+ *
1558
+ * @example
1559
+ * // Example usage for a specific response type
1560
+ * this.buildHttpRequest<MyResponseType>('item123', queueItem)
1561
+ * .subscribe(response => {
1562
+ * // Handle the response
1563
+ * });
1564
+ *
1565
+ * @template T - The expected type of the HTTP response. Defaults to `any`.
1383
1566
  */
1384
1567
  // TODO: add type for T and deprecate old function
1385
1568
  // TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html
@@ -2227,7 +2410,7 @@ class EuiDynamicMenuService {
2227
2410
  }
2228
2411
  filterEuiMenuItemsWithRights(links) {
2229
2412
  return links.filter((link) => {
2230
- if (link.hasChildren) {
2413
+ if (link.children != null) {
2231
2414
  link.children = this.filterEuiMenuItemsWithRights(link.children);
2232
2415
  }
2233
2416
  // First check if the user is denied access: