@fabriktor/fx 0.0.54 → 0.0.55

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,6 +4,7 @@ import { type SearchPage } from "../core/search.js";
4
4
  type ChatInsertOptions = Parameters<ChatOperator["insertOneChat"]>[0];
5
5
  type ChatReplaceOptions = Parameters<ChatOperator["replaceOneChat"]>[0];
6
6
  export type CreateChatOptions = ChatInsertOptions;
7
+ export type EnsureChatRoomOptions = Parameters<ChatOperator["ensureChatRoom"]>[0];
7
8
  export type MarkChatObjectsUploadedOptions = {
8
9
  id: ChatReplaceOptions["id"];
9
10
  };
@@ -104,6 +105,7 @@ export type GlobalChatRoomsSession = {
104
105
  };
105
106
  export interface ChatFXOperator {
106
107
  createChat(opts: CreateChatOptions): Promise<Chat>;
108
+ ensureChatRoom(opts: EnsureChatRoomOptions): Promise<string>;
107
109
  markChatObjectsUploaded(opts: MarkChatObjectsUploadedOptions): Promise<Chat>;
108
110
  searchChats(opts: SearchChatsOptions): Promise<SearchChatsPage>;
109
111
  newLatestChatsCursor(opts: LatestChatsOptions): LatestChatsCursor;
@@ -122,6 +124,7 @@ export declare class ChatFX implements ChatFXOperator {
122
124
  private users;
123
125
  constructor(opts: ChatFXOptions);
124
126
  createChat(opts: CreateChatOptions): Promise<Chat>;
127
+ ensureChatRoom(opts: EnsureChatRoomOptions): Promise<string>;
125
128
  markChatObjectsUploaded(opts: MarkChatObjectsUploadedOptions): Promise<Chat>;
126
129
  searchChats(opts: SearchChatsOptions): Promise<SearchChatsPage>;
127
130
  newLatestChatsCursor(opts: LatestChatsOptions): LatestChatsCursor;
@@ -12,6 +12,7 @@ const wsRefreshRetryMilliseconds = 30 * 1000;
12
12
  const resourceChat = "chat";
13
13
  const resourceUser = "user";
14
14
  const msgCreatedChatIDMissing = "Created chat response did not contain an ID.";
15
+ const msgEnsuredChatRoomIDMissing = "Ensured chat room response did not contain an ID.";
15
16
  const msgChatMissing = "Chat could not be resolved after the mutation.";
16
17
  const msgSearchQueryRequired = "Search query is required.";
17
18
  const msgChatObjectsUploading = "Cannot react to a chat while objects are still uploading.";
@@ -28,6 +29,10 @@ export class ChatFX {
28
29
  const id = requiredOperationID(out, msgCreatedChatIDMissing);
29
30
  return await this.findChat(id);
30
31
  }
32
+ async ensureChatRoom(opts) {
33
+ const out = await this.chat.ensureChatRoom(opts);
34
+ return requiredOperationID(out, msgEnsuredChatRoomIDMissing);
35
+ }
31
36
  async markChatObjectsUploaded(opts) {
32
37
  await this.chat.replaceOneChat({
33
38
  id: opts.id,
@@ -132,9 +137,7 @@ export class ChatFX {
132
137
  for (const member of members) {
133
138
  membersByRoom.get(member.chat_room_id)?.push(member);
134
139
  }
135
- const ownerIDs = [
136
- ...new Set(members.map((member) => member.owner_id)),
137
- ];
140
+ const ownerIDs = [...new Set(members.map((member) => member.owner_id))];
138
141
  const userResults = await Promise.allSettled(ownerIDs.map(async (id) => [id, await this.findUser(id)]));
139
142
  const usersByID = new Map(userResults.flatMap((result) => result.status === "fulfilled" ? [result.value] : []));
140
143
  return Object.fromEntries(roomIDs.map((chatRoomID) => {
@@ -453,7 +456,7 @@ function latestChatsPage(opts) {
453
456
  last_page: opts.raw.last_page,
454
457
  has_more: opts.raw.has_more,
455
458
  next_cursor: {
456
- chat_room_id: opts.chat_room_id,
459
+ chat_room_id: opts.raw.results[0]?.chat_room_id ?? opts.chat_room_id,
457
460
  next_page: opts.raw.next_page,
458
461
  per_page: opts.raw.per_page,
459
462
  done: opts.raw.done,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,7 +17,7 @@
17
17
  "typescript": "^6.0.3"
18
18
  },
19
19
  "dependencies": {
20
- "@fabriktor/client": "0.0.52",
20
+ "@fabriktor/client": "0.0.53",
21
21
  "@fabriktor/schema": "0.0.34"
22
22
  }
23
23
  }