@budibase/backend-core 2.10.10 → 2.10.12-alpha.0

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/dist/index.js CHANGED
@@ -5691,6 +5691,7 @@ var bustCache = performExport("bustCache");
5691
5691
  var user_exports = {};
5692
5692
  __export(user_exports, {
5693
5693
  getUser: () => getUser,
5694
+ getUsers: () => getUsers,
5694
5695
  invalidateUser: () => invalidateUser
5695
5696
  });
5696
5697
  init_init();
@@ -9997,6 +9998,27 @@ async function populateFromDB2(userId, tenantId) {
9997
9998
  }
9998
9999
  return user;
9999
10000
  }
10001
+ async function populateUsersFromDB(userIds) {
10002
+ const getUsersResponse = await UserDB.bulkGet(userIds);
10003
+ const notFoundIds = userIds.filter((uid, i) => !getUsersResponse[i]);
10004
+ const users = getUsersResponse.filter((x) => x);
10005
+ await Promise.all(
10006
+ users.map(async (user) => {
10007
+ user.budibaseAccess = true;
10008
+ if (!environment_default.SELF_HOSTED && !environment_default.DISABLE_ACCOUNT_PORTAL) {
10009
+ const account = await getAccount(user.email);
10010
+ if (account) {
10011
+ user.account = account;
10012
+ user.accountPortalAccess = true;
10013
+ }
10014
+ }
10015
+ })
10016
+ );
10017
+ if (notFoundIds.length) {
10018
+ return { users, notFoundIds };
10019
+ }
10020
+ return { users };
10021
+ }
10000
10022
  async function getUser(userId, tenantId, populateUser) {
10001
10023
  if (!populateUser) {
10002
10024
  populateUser = populateFromDB2;
@@ -10030,6 +10052,22 @@ async function getUser(userId, tenantId, populateUser) {
10030
10052
  }
10031
10053
  return user;
10032
10054
  }
10055
+ async function getUsers(userIds) {
10056
+ const client = await getUserClient();
10057
+ let usersFromCache = await client.bulkGet(userIds);
10058
+ const missingUsersFromCache = userIds.filter((uid) => !usersFromCache[uid]);
10059
+ const users = Object.values(usersFromCache);
10060
+ let notFoundIds;
10061
+ if (missingUsersFromCache.length) {
10062
+ const usersFromDb = await populateUsersFromDB(missingUsersFromCache);
10063
+ notFoundIds = usersFromDb.notFoundIds;
10064
+ for (const userToCache of usersFromDb.users) {
10065
+ await client.store(userToCache._id, userToCache, EXPIRY_SECONDS3);
10066
+ }
10067
+ users.push(...usersFromDb.users);
10068
+ }
10069
+ return { users, notFoundIds };
10070
+ }
10033
10071
  async function invalidateUser(userId) {
10034
10072
  const client = await getUserClient();
10035
10073
  await client.delete(userId);