@only-chat/types 0.2.0-beta.26 → 0.2.0-beta.27
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/package.json +6 -6
- package/queue.d.ts +23 -0
- package/store.d.ts +106 -0
- package/transport.d.ts +3 -3
- package/userStore.d.ts +8 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@only-chat/types",
|
|
3
|
-
"version":
|
|
3
|
+
"version": "0.2.0-beta.27",
|
|
4
4
|
"description": "TypeScript definitions for only-chat",
|
|
5
5
|
"homepage": "https://github.com/only-chat/node-backend/packages/types",
|
|
6
6
|
"main": "",
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"scripts": {},
|
|
14
14
|
"author": "only-chat",
|
|
15
15
|
"license": "MIT",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@types/node": "^24.3.0"
|
|
18
|
-
},
|
|
19
16
|
"keywords": [
|
|
20
17
|
"only-chat",
|
|
21
18
|
"type"
|
|
22
|
-
]
|
|
23
|
-
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^25.0.3"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/queue.d.ts
CHANGED
|
@@ -48,8 +48,31 @@ export interface Message {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export interface MessageQueue {
|
|
51
|
+
// Provide list of accepted message types
|
|
51
52
|
readonly acceptTypes?: MessageType[]
|
|
53
|
+
/**
|
|
54
|
+
* Publishes a message to the queue if its type is accepted
|
|
55
|
+
*
|
|
56
|
+
* @param msg - The message object to publish
|
|
57
|
+
* @returns Promise<boolean> - true if message was published, false if message type is not accepted
|
|
58
|
+
*/
|
|
52
59
|
publish: (msg: Message) => Promise<boolean>
|
|
60
|
+
/**
|
|
61
|
+
* Subscribes a callback function to receive messages from the queue
|
|
62
|
+
*
|
|
63
|
+
* @param callback - Async function that processes incoming messages
|
|
64
|
+
* @returns Promise<boolean> - Always returns true when subscription is added
|
|
65
|
+
*
|
|
66
|
+
* Note: Multiple subscribers can be registered, and all will be called for each message
|
|
67
|
+
*/
|
|
53
68
|
subscribe: (callback: (msg: Message) => Promise<void>) => Promise<boolean>
|
|
69
|
+
/**
|
|
70
|
+
* Unsubscribes a previously registered callback function
|
|
71
|
+
*
|
|
72
|
+
* @param callback - The callback function to remove
|
|
73
|
+
* @returns Promise<boolean> - true if callback was found and removed, false otherwise
|
|
74
|
+
*
|
|
75
|
+
* Note: Only removes the last occurrence if the same callback was added multiple times
|
|
76
|
+
*/
|
|
54
77
|
unsubscribe?: (callback: (msg: Message) => Promise<void>) => Promise<boolean>
|
|
55
78
|
}
|
package/store.d.ts
CHANGED
|
@@ -107,13 +107,119 @@ export interface ConversationsResult {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
export interface MessageStore {
|
|
110
|
+
/**
|
|
111
|
+
* Searches for messages based on filter criteria with pagination and sorting support
|
|
112
|
+
*
|
|
113
|
+
* @param r - FindRequest object containing search parameters including:
|
|
114
|
+
* - ids: Message IDs to retrieve
|
|
115
|
+
* - conversationIds: Messages from specific conversations
|
|
116
|
+
* - text: Text content filter (searches within text messages)
|
|
117
|
+
* - fromIds: Sender IDs
|
|
118
|
+
* - types: Message types (e.g., 'text', 'file')
|
|
119
|
+
* - clientMessageIds: Client-provided message IDs
|
|
120
|
+
* - excludeIds: Message IDs to exclude from results
|
|
121
|
+
* - createdFrom/createdTo: Date range filters
|
|
122
|
+
* - sort: Field to sort by (e.g., 'createdAt')
|
|
123
|
+
* - sortDesc: Whether to sort in descending order
|
|
124
|
+
* - from: Pagination starting index
|
|
125
|
+
* - size: Maximum number of results to return
|
|
126
|
+
*
|
|
127
|
+
* @returns Promise<FindResult> containing filtered, sorted, and paginated messages
|
|
128
|
+
*/
|
|
110
129
|
findMessages: (r: FindRequest) => Promise<FindResult>
|
|
130
|
+
/**
|
|
131
|
+
* Retrieves the latest message and last participant message for each specified conversation
|
|
132
|
+
*
|
|
133
|
+
* @param participant - The user ID of the participant requesting the information
|
|
134
|
+
* @param conversationId - Array of conversation IDs to fetch last message info for
|
|
135
|
+
*
|
|
136
|
+
* @returns Promise<ConversationLastMessages> - Object mapping conversation IDs to:
|
|
137
|
+
* - latest: The most recent non-deleted message of type 'text' or 'file'
|
|
138
|
+
* - left: Timestamp of the last message sent by the specified participant
|
|
139
|
+
*/
|
|
111
140
|
getLastMessagesTimestamps: (fromId: string, conversationId: string[]) => Promise<ConversationLastMessages>
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves a single conversation by ID for a specific participant
|
|
143
|
+
*
|
|
144
|
+
* @param participant - Optional participant ID; if provided, verifies the participant is part of the conversation
|
|
145
|
+
* @param id - The unique identifier of the conversation to retrieve
|
|
146
|
+
*
|
|
147
|
+
* @returns Promise<Conversation | undefined> - The conversation object if found and accessible,
|
|
148
|
+
* undefined if conversation doesn't exist, is deleted, or doesn't have specified participant
|
|
149
|
+
*/
|
|
112
150
|
getParticipantConversationById: (participant: string | undefined, id: string) => Promise<Conversation | undefined>
|
|
151
|
+
/**
|
|
152
|
+
* Retrieves a paginated list of conversations for a specific participant with optional filtering
|
|
153
|
+
*
|
|
154
|
+
* @param participant - The user ID of the participant whose conversations to retrieve
|
|
155
|
+
* @param ids - Optional array of conversation IDs to filter by (if undefined, returns all conversations)
|
|
156
|
+
* @param excludeIds - Optional array of conversation IDs to exclude from results
|
|
157
|
+
* @param from - Pagination starting index (default: 0)
|
|
158
|
+
* @param size - Maximum number of conversations to return (default: 100)
|
|
159
|
+
*
|
|
160
|
+
* @returns Promise<ConversationsResult> - Paginated result containing:
|
|
161
|
+
* - conversations: Array of conversations sorted by creation date (newest first)
|
|
162
|
+
* - from: The starting index used for pagination
|
|
163
|
+
* - size: The number of conversations returned
|
|
164
|
+
* - total: The total number of conversations for the participant
|
|
165
|
+
*/
|
|
113
166
|
getParticipantConversations: (participant: string, ids?: string[], excludeIds?: string[], from?: number, size?: number) => Promise<ConversationsResult>
|
|
167
|
+
/**
|
|
168
|
+
* Retrieves the last non-deleted message sent by a specific participant in a conversation
|
|
169
|
+
*
|
|
170
|
+
* @param participant - The user ID of the participant whose last message to find
|
|
171
|
+
* @param conversationId - The unique identifier of the conversation
|
|
172
|
+
*
|
|
173
|
+
* @returns Promise<Message | undefined> - The last message sent by the participant in the conversation,
|
|
174
|
+
* undefined if conversation doesn't exist, is deleted, participant is not in conversation,
|
|
175
|
+
* or participant has no messages
|
|
176
|
+
*/
|
|
114
177
|
getParticipantLastMessage: (participant: string, conversationId: string) => Promise<Message | undefined>
|
|
178
|
+
/**
|
|
179
|
+
* Gets or creates a peer-to-peer conversation ID between two users
|
|
180
|
+
*
|
|
181
|
+
* @param peer1 - First user ID
|
|
182
|
+
* @param peer2 - Second user ID
|
|
183
|
+
*
|
|
184
|
+
* @returns Promise<ConversationIdResult | undefined> - Object containing:
|
|
185
|
+
* - id: The conversation ID (existing or newly created)
|
|
186
|
+
* - result: 'created' if a new conversation was created, undefined if existing conversation was found
|
|
187
|
+
*
|
|
188
|
+
* Note: The conversation ID is deterministic - same two users will always get the same ID
|
|
189
|
+
* regardless of parameter order (peer1 and peer2 are sorted internally)
|
|
190
|
+
*/
|
|
115
191
|
getPeerToPeerConversationId(peer1: string, peer2: string): Promise<ConversationIdResult | undefined>
|
|
192
|
+
/**
|
|
193
|
+
* Saves a connection record for a user instance (e.g., WebSocket connection)
|
|
194
|
+
*
|
|
195
|
+
* @param userId - The ID of the user establishing the connection
|
|
196
|
+
* @param instanceId - The instance identifier for this connection
|
|
197
|
+
*
|
|
198
|
+
* @returns Promise<SaveResponse> - Object containing:
|
|
199
|
+
* - _id: The auto-generated unique connection ID
|
|
200
|
+
* - result: Always 'created' since connections are always new entries
|
|
201
|
+
*/
|
|
116
202
|
saveConnection: (userId: string, instanceId: string) => Promise<SaveResponse>
|
|
203
|
+
/**
|
|
204
|
+
* Saves or updates a conversation in the store
|
|
205
|
+
*
|
|
206
|
+
* @param c - Conversation to save. If the conversation has an ID,
|
|
207
|
+
* it updates the existing conversation; otherwise creates a new one
|
|
208
|
+
*
|
|
209
|
+
* @returns Promise<SaveResponse> - Object containing:
|
|
210
|
+
* - _id: The conversation ID (preserved if provided, auto-generated if new)
|
|
211
|
+
* - result: 'created' for new conversations, 'updated' for existing ones
|
|
212
|
+
*/
|
|
117
213
|
saveConversation: (c: Conversation) => Promise<SaveResponse>
|
|
214
|
+
/**
|
|
215
|
+
* Saves or updates a message in the store and associates it with a conversation
|
|
216
|
+
*
|
|
217
|
+
* @param m - Message to save. If the message has an ID,
|
|
218
|
+
* it updates the existing message; otherwise creates a new one
|
|
219
|
+
*
|
|
220
|
+
* @returns Promise<SaveResponse> - Object containing:
|
|
221
|
+
* - _id: The message ID (preserved if provided, auto-generated if new)
|
|
222
|
+
* - result: 'created' for new messages, 'updated' for existing ones
|
|
223
|
+
*/
|
|
118
224
|
saveMessage: (m: Message) => Promise<SaveResponse>
|
|
119
225
|
}
|
package/transport.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface Transport extends EventEmitter {
|
|
|
16
16
|
|
|
17
17
|
close(code?: number, data?: string | Buffer): void
|
|
18
18
|
send(data: string, options: {
|
|
19
|
-
binary?: boolean
|
|
20
|
-
fin?: boolean
|
|
21
|
-
}
|
|
19
|
+
binary?: boolean
|
|
20
|
+
fin?: boolean
|
|
21
|
+
}): void
|
|
22
22
|
}
|
package/userStore.d.ts
CHANGED
|
@@ -2,10 +2,15 @@ export interface AuthenticationInfo {}
|
|
|
2
2
|
|
|
3
3
|
export interface UserStore {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Authenticates a user
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
8
|
-
*
|
|
7
|
+
* @param info - Authentication information containing name and password
|
|
8
|
+
*
|
|
9
|
+
* @returns Promise<string | undefined> - User ID if authentication successful
|
|
10
|
+
* or new user created, undefined if no name provided
|
|
11
|
+
*
|
|
12
|
+
* Security Consideration: In production, passwords should be hashed
|
|
13
|
+
* before storage.
|
|
9
14
|
*/
|
|
10
15
|
authenticate(authInfo: AuthenticationInfo): Promise<string | undefined>
|
|
11
16
|
}
|