@secrecy/lib 1.74.0-feat-groups-identity.3 → 1.74.0-feat-groups-identity.4

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.
@@ -13,6 +13,20 @@ async function getPublicUser(client, id) {
13
13
  usersCache.set(user.id, user);
14
14
  return user;
15
15
  }
16
+ async function getPublicUsers(client, ids) {
17
+ let users = ids
18
+ .map((id) => usersCache.get(id))
19
+ .filter((u) => u !== undefined);
20
+ const missingIds = ids.filter((id) => !usersCache.has(id));
21
+ if (missingIds.length > 0) {
22
+ const fetchedUsers = await client.user.byIds.query({
23
+ ids: missingIds,
24
+ });
25
+ fetchedUsers.forEach((user) => usersCache.set(user.id, user));
26
+ users = users.concat(fetchedUsers);
27
+ }
28
+ return users;
29
+ }
16
30
  export class BaseClient {
17
31
  static getBaseClient = (opts = {}) => createTRPCClient(opts);
18
32
  client;
@@ -75,6 +89,14 @@ export class BaseClient {
75
89
  const user = await getPublicUser(this.client, userId);
76
90
  return user;
77
91
  }
92
+ static async getUsers(userIds, opts) {
93
+ const users = await getPublicUsers(this.getBaseClient(opts), userIds);
94
+ return users;
95
+ }
96
+ async getUsers(userIds) {
97
+ const users = await getPublicUsers(this.client, userIds);
98
+ return users;
99
+ }
78
100
  async searchUsers(search) {
79
101
  const users = await this.client.user.searchMany.query({
80
102
  search,
@@ -23,6 +23,8 @@ export declare class BaseClient {
23
23
  me(): Promise<SelfUser>;
24
24
  static getUser(userId: string, opts?: CreateTrpcClientOptions): Promise<PublicUser>;
25
25
  getUser(userId: string): Promise<PublicUser>;
26
+ static getUsers(userIds: string[], opts?: CreateTrpcClientOptions): Promise<PublicUser[]>;
27
+ getUsers(userIds: string[]): Promise<PublicUser[]>;
26
28
  searchUsers(search: string): Promise<PublicUser[]>;
27
29
  updateProfile(data: RouterInputs['user']['updateProfile']): Promise<RouterOutputs['user']['updateProfile']>;
28
30
  static isCryptoTransactionDone({ idOrHash, network, opts, }: {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@secrecy/lib",
3
3
  "author": "Anonymize <anonymize@gmail.com>",
4
4
  "description": "Anonymize Secrecy Library",
5
- "version": "1.74.0-feat-groups-identity.3",
5
+ "version": "1.74.0-feat-groups-identity.4",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/anonymize-org/lib.git"