itlab-internal-services 2.16.4 → 2.16.5

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.
@@ -24,7 +24,7 @@ export declare class TaskManager {
24
24
  * @param accountsService Service responsible for fetching users
25
25
  * @returns Map of userId -> user
26
26
  */
27
- static fetchAndMapUsers(userIdGroups: string[][], accountsService: AccountsService): Promise<Map<string, User>>;
27
+ static fetchAndMapUsers(userIdGroups: string[][], accountsService: AccountsService): Promise<FetchMap<User>>;
28
28
  /**
29
29
  * Fetches all users for the given ID groups and returns a mapping.
30
30
  * Ensures each user is fetched only once.
@@ -32,23 +32,7 @@ export declare class TaskManager {
32
32
  * @param accountsService Service responsible for fetching users
33
33
  * @returns Map of userId -> user
34
34
  */
35
- static fetchAndMapAccounts(accountIdGroups: string[][], accountsService: AccountsService): Promise<Map<string, Account>>;
36
- /**
37
- * Maps an array of IDs to user objects using a userMap.
38
- * Filters out any IDs that don’t have a corresponding user.
39
- * @param userIds Array of user IDs to map
40
- * @param userMap Map of userId -> user object
41
- * @returns Array of user objects
42
- */
43
- static mapIdsToUsers(userIds: string[], userMap: Map<string, User>): User[];
44
- /**
45
- * Maps an array of IDs to user objects using a userMap.
46
- * Filters out any IDs that don’t have a corresponding user.
47
- * @param accountIds Array of user IDs to map
48
- * @param accountMap Map of userId -> user object
49
- * @returns Array of user objects
50
- */
51
- static mapIdsToAccounts(accountIds: string[], accountMap: Map<string, Account>): Account[];
35
+ static fetchAndMapAccounts(accountIdGroups: string[][], accountsService: AccountsService): Promise<FetchMap<Account>>;
52
36
  /**
53
37
  * Adds a new asynchronous task to the queue.
54
38
  *
@@ -69,3 +53,23 @@ export declare class TaskManager {
69
53
  */
70
54
  clear(): void;
71
55
  }
56
+ declare class FetchMap<T extends User | Account> {
57
+ private readonly map;
58
+ constructor(items?: T[]);
59
+ /**
60
+ * Maps a single ID to an user/account object using a user/account Map.
61
+ * @param id ID of user/account to map
62
+ * @param map Map of id -> user/account object
63
+ * @returns user/account object
64
+ */
65
+ get(id: string): T;
66
+ /**
67
+ * Maps an array of IDs to user/account objects using a user/account Map.
68
+ * Filters out any IDs that don’t have a corresponding entity.
69
+ * @param ids Array of user/account IDs to map
70
+ * @param map Map of id -> user/account object
71
+ * @returns Array of user/account objects
72
+ */
73
+ getMultiple(ids: string[]): T[];
74
+ }
75
+ export {};
@@ -31,11 +31,11 @@ class TaskManager {
31
31
  // Collect all unique user IDs across all groups
32
32
  const uniqueUserIds = new Set(userIdGroups.flat());
33
33
  if (uniqueUserIds.size === 0)
34
- return new Map();
34
+ return new FetchMap();
35
35
  // Fetch all users once
36
36
  const userCollection = await accountsService.getUserCollection(Array.from(uniqueUserIds));
37
37
  // Build a map for quick lookup
38
- return new Map(userCollection.map((user) => [user.id, user]));
38
+ return new FetchMap(userCollection);
39
39
  }
40
40
  /**
41
41
  * Fetches all users for the given ID groups and returns a mapping.
@@ -48,31 +48,11 @@ class TaskManager {
48
48
  // Collect all unique user IDs across all groups
49
49
  const uniqueAccountIds = new Set(accountIdGroups.flat());
50
50
  if (uniqueAccountIds.size === 0)
51
- return new Map();
51
+ return new FetchMap();
52
52
  // Fetch all users once
53
53
  const accountCollection = await accountsService.getAccountCollection(Array.from(uniqueAccountIds));
54
54
  // Build a map for quick lookup
55
- return new Map(accountCollection.map((account) => [account.id, account]));
56
- }
57
- /**
58
- * Maps an array of IDs to user objects using a userMap.
59
- * Filters out any IDs that don’t have a corresponding user.
60
- * @param userIds Array of user IDs to map
61
- * @param userMap Map of userId -> user object
62
- * @returns Array of user objects
63
- */
64
- static mapIdsToUsers(userIds, userMap) {
65
- return userIds.map((userId) => userMap.get(userId)).filter(Boolean);
66
- }
67
- /**
68
- * Maps an array of IDs to user objects using a userMap.
69
- * Filters out any IDs that don’t have a corresponding user.
70
- * @param accountIds Array of user IDs to map
71
- * @param accountMap Map of userId -> user object
72
- * @returns Array of user objects
73
- */
74
- static mapIdsToAccounts(accountIds, accountMap) {
75
- return accountIds.map((accountId) => accountMap.get(accountId)).filter(Boolean);
55
+ return new FetchMap(accountCollection);
76
56
  }
77
57
  /**
78
58
  * Adds a new asynchronous task to the queue.
@@ -101,3 +81,27 @@ class TaskManager {
101
81
  }
102
82
  }
103
83
  exports.TaskManager = TaskManager;
84
+ class FetchMap {
85
+ constructor(items = []) {
86
+ this.map = new Map(items.map((item) => [item.id, item]));
87
+ }
88
+ /**
89
+ * Maps a single ID to an user/account object using a user/account Map.
90
+ * @param id ID of user/account to map
91
+ * @param map Map of id -> user/account object
92
+ * @returns user/account object
93
+ */
94
+ get(id) {
95
+ return this.map.get(id);
96
+ }
97
+ /**
98
+ * Maps an array of IDs to user/account objects using a user/account Map.
99
+ * Filters out any IDs that don’t have a corresponding entity.
100
+ * @param ids Array of user/account IDs to map
101
+ * @param map Map of id -> user/account object
102
+ * @returns Array of user/account objects
103
+ */
104
+ getMultiple(ids) {
105
+ return ids.map((id) => this.map.get(id)).filter(Boolean);
106
+ }
107
+ }
@@ -33,17 +33,7 @@ const HttpLoggingMiddleware = (req, res, next) => {
33
33
  next();
34
34
  return;
35
35
  }
36
- // Defer logging until after the response has finished,
37
- // ensuring accurate status information
38
- res.on('finish', () => {
39
- const { statusCode, statusMessage } = res;
40
- // Construct a standardized log message
41
- const logMessage = `${method} ${url} - ${statusCode} (${statusMessage})`;
42
- // Client errors (4xx) are logged at warn level for visibility
43
- // All other responses use standard log level
44
- const logLevel = statusCode >= 400 && statusCode < 500 ? 'warn' : 'log';
45
- logger[logLevel](logMessage);
46
- });
36
+ logger.log(`Handle ${method} ${url}`);
47
37
  // Continue to next middleware or request handler
48
38
  next();
49
39
  };
@@ -15,9 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.AccountsService = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
17
  const config_1 = require("@nestjs/config");
18
+ const itlab_functions_1 = require("itlab-functions");
18
19
  const authentication_1 = require("../../authentication");
19
20
  const base_http_service_1 = require("../base-http.service");
20
21
  const base_urls_1 = require("../base-urls");
22
+ const chunkSize = 100;
21
23
  /**
22
24
  * AccountsService
23
25
  *
@@ -57,7 +59,11 @@ let AccountsService = class AccountsService extends base_http_service_1.BaseHttp
57
59
  async getAccountCollection(accountIds) {
58
60
  if (accountIds.length === 0)
59
61
  return [];
60
- return this.fetchResourceCollection(`internal/accounts`, { params: { ids: accountIds } });
62
+ const chunkedAccountIds = (0, itlab_functions_1.createChunks)(accountIds, chunkSize);
63
+ const chunkedAccounts = chunkedAccountIds.map((accountIds) => {
64
+ return this.fetchResourceCollection(`internal/accounts`, { params: { ids: accountIds } });
65
+ });
66
+ return (await Promise.all(chunkedAccounts)).flat();
61
67
  }
62
68
  /**
63
69
  * Retrieves a single user entry derived from an account.
@@ -77,7 +83,11 @@ let AccountsService = class AccountsService extends base_http_service_1.BaseHttp
77
83
  async getUserCollection(userIds) {
78
84
  if (userIds.length === 0)
79
85
  return [];
80
- return this.fetchResourceCollection(`internal/users`, { params: { ids: userIds } });
86
+ const chunkedUserIds = (0, itlab_functions_1.createChunks)(userIds, chunkSize);
87
+ const chunkedUsers = chunkedUserIds.map((userIds) => {
88
+ return this.fetchResourceCollection(`internal/users`, { params: { ids: userIds } });
89
+ });
90
+ return (await Promise.all(chunkedUsers)).flat();
81
91
  }
82
92
  };
83
93
  exports.AccountsService = AccountsService;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "Timo Scheuermann",
5
5
  "email": "timo.scheuermann@sv-informatik.de"
6
6
  },
7
- "version": "2.16.4",
7
+ "version": "2.16.5",
8
8
  "type": "commonjs",
9
9
  "files": [
10
10
  "dist"