@only-chat/types 0.2.0-beta.10

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/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # only-chat
2
+ TypeScript definitions for only-chat
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export type * as Log from './log.d.ts'
2
+ export type * as Queue from './queue.js'
3
+ export type * as Store from './store.js'
4
+ export type * as Transport from './transport.ts'
package/log.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export interface Log {
2
+ debug(message?: any, ...optionalParams: any[]): void
3
+ error(message?: any, ...optionalParams: any[]): void
4
+ info(message?: any, ...optionalParams: any[]): void
5
+ log(message?: any, ...optionalParams: any[]): void
6
+ trace(message?: any, ...optionalParams: any[]): void
7
+ warn(message?: any, ...optionalParams: any[]): void
8
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@only-chat/types",
3
+ "version": "0.2.0-beta.10",
4
+ "description": "TypeScript definitions for only-chat",
5
+ "homepage": "https://github.com/only-chat/node-backend/packages/types",
6
+ "main": "",
7
+ "types": "index.d.ts",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/only-chat/node-backend.git",
11
+ "directory": "packages/types"
12
+ },
13
+ "scripts": {},
14
+ "author": "only-chat",
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@types/node": "^22.7.4"
18
+ },
19
+ "keywords": [
20
+ "only-chat",
21
+ "type"
22
+ ]
23
+ }
package/queue.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ export interface ConversationUpdate {
2
+ conversationId?: string
3
+ title?: string
4
+ participants?: string[]
5
+ closedAt?: Date
6
+ deletedAt?: Date
7
+ updatedAt?: Date
8
+ }
9
+
10
+ export interface FileMessage {
11
+ link: string
12
+ name: string
13
+ type: string
14
+ size: number
15
+ }
16
+
17
+ export interface TextMessage {
18
+ text: string
19
+ }
20
+
21
+ export interface MessageDelete {
22
+ messageId: string
23
+ }
24
+
25
+ export interface MessageUpdate extends Partial<FileMessage>, Partial<TextMessage> {
26
+ messageId: string
27
+ updatedAt: Date
28
+ }
29
+
30
+ export type MessageType = 'connected' | 'disconnected' | 'joined' | 'left' | 'closed' | 'deleted' | 'loaded' | 'updated' | 'message-updated' | 'message-deleted' | 'text' | 'file'
31
+
32
+ export type MessageData = ConversationUpdate | FileMessage | MessageDelete | MessageUpdate | TextMessage | null
33
+
34
+ export interface Message {
35
+ type: MessageType
36
+ id?: string
37
+ clientMessageId?: string
38
+ instanceId: string
39
+ conversationId?: string
40
+ participants?: string[]
41
+ connectionId: string
42
+ fromId: string
43
+ data: MessageData
44
+ createdAt: Date
45
+ updatedAt?: Date
46
+ deletedAt?: Date
47
+ }
48
+
49
+ export interface MessageQueue {
50
+ acceptTypes?: MessageType[]
51
+ publish: (msg: Message) => Promise<boolean>
52
+ subscribe: (callback: (msg: Message) => Promise<void>) => Promise<boolean>
53
+ unsubscribe?: (callback: (msg: Message) => Promise<void>) => Promise<boolean>
54
+ }
package/store.d.ts ADDED
@@ -0,0 +1,114 @@
1
+ export interface Connection {
2
+ id?: string
3
+ instanceId: string
4
+ timestamp: Date
5
+ userId: string
6
+ }
7
+
8
+ export interface Conversation {
9
+ id?: string
10
+ title?: string
11
+ participants: string[]
12
+ createdBy: string
13
+ createdAt: Date
14
+ updatedAt?: Date
15
+ closedAt?: Date
16
+ deletedAt?: Date
17
+ }
18
+
19
+ export interface ConversationUpdate {
20
+ conversationId?: string
21
+ title?: string
22
+ participants?: string[]
23
+ closedAt?: Date
24
+ deletedAt?: Date
25
+ updatedAt?: Date
26
+ }
27
+
28
+ export interface FileMessage {
29
+ link: string
30
+ name: string
31
+ type: string
32
+ size: number
33
+ }
34
+
35
+ export interface TextMessage {
36
+ text: string
37
+ }
38
+
39
+ export interface MessageDelete {
40
+ messageId: string
41
+ }
42
+
43
+ export interface MessageUpdate extends Partial<FileMessage>, Partial<TextMessage> {
44
+ messageId: string
45
+ updatedAt: Date
46
+ }
47
+
48
+ export interface FindRequest {
49
+ from?: number
50
+ size?: number
51
+ sort?: string
52
+ sortDesc?: boolean
53
+ ids?: string[]
54
+ clientMessageIds?: string[]
55
+ excludeIds?: string[]
56
+ conversationIds?: string[]
57
+ fromIds?: string[]
58
+ types?: MessageType[]
59
+ createdFrom?: Date
60
+ createdTo?: Date
61
+ text?: string
62
+ }
63
+
64
+ export interface FindResult {
65
+ messages: Message[]
66
+ from: number
67
+ size: number
68
+ total: number
69
+ }
70
+
71
+ export type MessageType = 'joined' | 'left' | 'closed' | 'deleted' | 'updated' | 'message-updated' | 'message-deleted' | 'text' | 'file'
72
+
73
+ export type MessageData = ConversationUpdate | FileMessage | MessageDelete | MessageUpdate | TextMessage | null
74
+
75
+ export interface Message {
76
+ type: MessageType
77
+ id?: string
78
+ clientMessageId?: string
79
+ conversationId?: string
80
+ participants?: string[]
81
+ connectionId: string
82
+ fromId: string
83
+ data: MessageData
84
+ createdAt: Date
85
+ updatedAt?: Date
86
+ deletedAt?: Date
87
+ }
88
+
89
+ export interface SaveResponse {
90
+ _id: string
91
+ result: string
92
+ }
93
+
94
+ export type ConversationLastMessages = Record<string, { latest?: Message, left?: Date }>
95
+
96
+ export interface ConversationsResult {
97
+ conversations: Conversation[]
98
+ from: number
99
+ size: number
100
+ total: number
101
+ }
102
+
103
+ export interface MessageStore {
104
+ findMessages: (r: FindRequest) => Promise<FindResult>
105
+ getConversationById: (id: string) => Promise<Conversation | undefined>
106
+ getLastMessagesTimestamps: (fromId: string, conversationId: string[]) => Promise<ConversationLastMessages>
107
+ getParticipantConversationById: (participant: string | undefined, id: string) => Promise<Conversation | undefined>
108
+ getParticipantConversations: (participant: string, excludeIds: string[], from: number, size: number) => Promise<ConversationsResult>
109
+ getParticipantLastMessage: (participant: string, conversationId: string) => Promise<Message | undefined>
110
+ getPeerToPeerConversationId(peer1: string, peer2: string): Promise<string | undefined>
111
+ saveConnection: (userId: string, instanceId: string) => Promise<SaveResponse>
112
+ saveConversation: (c: Conversation) => Promise<SaveResponse>
113
+ saveMessage: (m: Message) => Promise<SaveResponse>
114
+ }
package/transport.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { EventEmitter } from 'events'
2
+
3
+ export declare enum TransportState {
4
+ /** The connection is not yet open. */
5
+ CONNECTING = 0,
6
+ /** The connection is open and ready to communicate. */
7
+ OPEN = 1,
8
+ /** The connection is in the process of closing. */
9
+ CLOSING = 2,
10
+ /** The connection is closed. */
11
+ CLOSED = 3
12
+ }
13
+
14
+ export interface Transport extends EventEmitter {
15
+ readonly readyState: TransportState
16
+
17
+ close(code?: number, data?: string | Buffer): void
18
+ send(data: string, options: {
19
+ binary?: boolean | undefined
20
+ fin?: boolean | undefined
21
+ },): void
22
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "NodeNext",
5
+ "lib": [
6
+ "ESNext"
7
+ ],
8
+ },
9
+ }
package/userStore.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export interface AuthenticationInfo {}
2
+
3
+ export interface UserStore {
4
+ /**
5
+ * Verifies provided user credentials
6
+ *
7
+ * @param authInfo User credentials
8
+ * @returns User identifier
9
+ */
10
+ authenticate(authInfo: AuthenticationInfo): Promise<string | undefined>
11
+ }