@zyacreatives/shared 2.2.30 → 2.2.32

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.
@@ -9,11 +9,11 @@ export declare const BaseChatEntitySchema: z.ZodObject<{
9
9
  readonly ACCEPTED: "ACCEPTED";
10
10
  readonly DECLINED: "DECLINED";
11
11
  }>>;
12
- acceptedAt: z.ZodCoercedDate<unknown>;
13
- declinedAt: z.ZodCoercedDate<unknown>;
12
+ acceptedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
13
+ declinedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
14
14
  createdAt: z.ZodCoercedDate<unknown>;
15
15
  updatedAt: z.ZodCoercedDate<unknown>;
16
- deletedAt: z.ZodCoercedDate<unknown>;
16
+ deletedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
17
17
  }, z.core.$strip>;
18
18
  export declare const ChatEntitySchema: z.ZodObject<{
19
19
  id: z.ZodCUID2;
@@ -25,20 +25,21 @@ export declare const ChatEntitySchema: z.ZodObject<{
25
25
  readonly ACCEPTED: "ACCEPTED";
26
26
  readonly DECLINED: "DECLINED";
27
27
  }>>;
28
- acceptedAt: z.ZodCoercedDate<unknown>;
29
- declinedAt: z.ZodCoercedDate<unknown>;
28
+ acceptedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
29
+ declinedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
30
30
  createdAt: z.ZodCoercedDate<unknown>;
31
31
  updatedAt: z.ZodCoercedDate<unknown>;
32
- deletedAt: z.ZodCoercedDate<unknown>;
33
- senderImgUrl: z.ZodOptional<z.ZodString>;
32
+ deletedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
34
33
  senderName: z.ZodString;
35
34
  senderUsername: z.ZodString;
35
+ senderImgUrl: z.ZodOptional<z.ZodString>;
36
+ receiverName: z.ZodString;
36
37
  receiverUsername: z.ZodString;
37
38
  receiverImgUrl: z.ZodOptional<z.ZodString>;
38
- receiverName: z.ZodString;
39
39
  lastMessageSent: z.ZodOptional<z.ZodString>;
40
- unreadCount: z.ZodOptional<z.ZodInt>;
41
- isOnline: z.ZodOptional<z.ZodBoolean>;
40
+ lastMessageAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
41
+ unreadCount: z.ZodDefault<z.ZodNumber>;
42
+ isOnline: z.ZodDefault<z.ZodBoolean>;
42
43
  }, z.core.$strip>;
43
44
  export declare const CreateChatInputSchema: z.ZodObject<{
44
45
  senderId: z.ZodCUID2;
@@ -54,11 +55,11 @@ export declare const CreateChatOutputSchema: z.ZodObject<{
54
55
  readonly ACCEPTED: "ACCEPTED";
55
56
  readonly DECLINED: "DECLINED";
56
57
  }>>;
57
- acceptedAt: z.ZodCoercedDate<unknown>;
58
- declinedAt: z.ZodCoercedDate<unknown>;
58
+ acceptedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
59
+ declinedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
59
60
  createdAt: z.ZodCoercedDate<unknown>;
60
61
  updatedAt: z.ZodCoercedDate<unknown>;
61
- deletedAt: z.ZodCoercedDate<unknown>;
62
+ deletedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
62
63
  }, z.core.$strip>;
63
64
  export declare const ChatIdSchema: z.ZodObject<{
64
65
  chatId: z.ZodCUID2;
@@ -73,18 +74,19 @@ export declare const GetChatsOutputSchema: z.ZodArray<z.ZodObject<{
73
74
  readonly ACCEPTED: "ACCEPTED";
74
75
  readonly DECLINED: "DECLINED";
75
76
  }>>;
76
- acceptedAt: z.ZodCoercedDate<unknown>;
77
- declinedAt: z.ZodCoercedDate<unknown>;
77
+ acceptedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
78
+ declinedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
78
79
  createdAt: z.ZodCoercedDate<unknown>;
79
80
  updatedAt: z.ZodCoercedDate<unknown>;
80
- deletedAt: z.ZodCoercedDate<unknown>;
81
- senderImgUrl: z.ZodOptional<z.ZodString>;
81
+ deletedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
82
82
  senderName: z.ZodString;
83
83
  senderUsername: z.ZodString;
84
+ senderImgUrl: z.ZodOptional<z.ZodString>;
85
+ receiverName: z.ZodString;
84
86
  receiverUsername: z.ZodString;
85
87
  receiverImgUrl: z.ZodOptional<z.ZodString>;
86
- receiverName: z.ZodString;
87
88
  lastMessageSent: z.ZodOptional<z.ZodString>;
88
- unreadCount: z.ZodOptional<z.ZodInt>;
89
- isOnline: z.ZodOptional<z.ZodBoolean>;
89
+ lastMessageAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
90
+ unreadCount: z.ZodDefault<z.ZodNumber>;
91
+ isOnline: z.ZodDefault<z.ZodBoolean>;
90
92
  }, z.core.$strip>>;
@@ -3,28 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetChatsOutputSchema = exports.ChatIdSchema = exports.CreateChatOutputSchema = exports.CreateChatInputSchema = exports.ChatEntitySchema = exports.BaseChatEntitySchema = void 0;
4
4
  const zod_openapi_1 = require("@hono/zod-openapi");
5
5
  const constants_1 = require("../constants");
6
+ // 1. DB Representation (What is actually in Postgres)
6
7
  exports.BaseChatEntitySchema = zod_openapi_1.z.object({
7
8
  id: zod_openapi_1.z.cuid2(),
8
9
  senderId: zod_openapi_1.z.cuid2(),
9
10
  receiverId: zod_openapi_1.z.cuid2(),
10
11
  isMessageRequest: zod_openapi_1.z.boolean().default(true),
11
12
  messageRequestStatus: zod_openapi_1.z.enum(constants_1.MESSAGE_REQUEST_STATUS).default("PENDING"),
12
- acceptedAt: zod_openapi_1.z.coerce.date(),
13
- declinedAt: zod_openapi_1.z.coerce.date(),
13
+ acceptedAt: zod_openapi_1.z.coerce.date().nullable(),
14
+ declinedAt: zod_openapi_1.z.coerce.date().nullable(),
14
15
  createdAt: zod_openapi_1.z.coerce.date(),
15
16
  updatedAt: zod_openapi_1.z.coerce.date(),
16
- deletedAt: zod_openapi_1.z.coerce.date(),
17
+ deletedAt: zod_openapi_1.z.coerce.date().nullable(),
17
18
  });
19
+ // 2. API Representation (Enriched with Redis/User data)
18
20
  exports.ChatEntitySchema = exports.BaseChatEntitySchema.extend({
19
- senderImgUrl: zod_openapi_1.z.string().optional(),
21
+ // User Details (Joined)
20
22
  senderName: zod_openapi_1.z.string(),
21
23
  senderUsername: zod_openapi_1.z.string(),
24
+ senderImgUrl: zod_openapi_1.z.string().optional(),
25
+ receiverName: zod_openapi_1.z.string(),
22
26
  receiverUsername: zod_openapi_1.z.string(),
23
27
  receiverImgUrl: zod_openapi_1.z.string().optional(),
24
- receiverName: zod_openapi_1.z.string(),
28
+ // Ephemeral/Cached Data
25
29
  lastMessageSent: zod_openapi_1.z.string().optional(),
26
- unreadCount: zod_openapi_1.z.int().optional(),
27
- isOnline: zod_openapi_1.z.boolean().optional(),
30
+ lastMessageAt: zod_openapi_1.z.coerce.date().optional(), // Important for UI sorting
31
+ unreadCount: zod_openapi_1.z.number().int().default(0),
32
+ isOnline: zod_openapi_1.z.boolean().default(false),
28
33
  });
29
34
  exports.CreateChatInputSchema = zod_openapi_1.z.object({
30
35
  senderId: zod_openapi_1.z.cuid2(),
@@ -1,6 +1,18 @@
1
1
  import { z } from "@hono/zod-openapi";
2
2
  export declare const MessageEntitySchema: z.ZodObject<{
3
3
  id: z.ZodCUID2;
4
+ chatId: z.ZodCUID2;
5
+ senderId: z.ZodCUID2;
6
+ content: z.ZodDefault<z.ZodOptional<z.ZodString>>;
7
+ messageType: z.ZodDefault<z.ZodEnum<{
8
+ readonly MARKETPLACE: "MARKETPLACE";
9
+ readonly PROJECT: "PROJECT";
10
+ readonly JOB_OPENING: "JOB_OPENING";
11
+ readonly DEFAULT_MESSAGE: "DEFAULT_MESSAGE";
12
+ readonly MESSAGE_WITH_LINKS: "MESSAGE_WITH_LINKS";
13
+ readonly MESSAGE_WITH_MEDIA: "MESSAGE_WITH_MEDIA";
14
+ readonly MESSAGE_WITH_MEDIA_AND_LINKS: "MESSAGE_WITH_MEDIA_AND_LINKS";
15
+ }>>;
4
16
  parentId: z.ZodOptional<z.ZodCUID2>;
5
17
  parentType: z.ZodOptional<z.ZodEnum<{
6
18
  readonly PROJECT: "PROJECT";
@@ -11,45 +23,45 @@ export declare const MessageEntitySchema: z.ZodObject<{
11
23
  readonly JOB_APPLICATION: "JOB_APPLICATION";
12
24
  }>>;
13
25
  replyToMessageId: z.ZodOptional<z.ZodCUID2>;
14
- chatId: z.ZodCUID2;
15
- senderId: z.ZodCUID2;
16
- receiverId: z.ZodCUID2;
17
- linkMeta: z.ZodOptional<z.ZodObject<{
26
+ replyToContent: z.ZodOptional<z.ZodString>;
27
+ replyToImages: z.ZodOptional<z.ZodArray<z.ZodURL>>;
28
+ replyToLinkMeta: z.ZodOptional<z.ZodObject<{
18
29
  url: z.ZodURL;
19
30
  title: z.ZodOptional<z.ZodString>;
20
31
  description: z.ZodOptional<z.ZodString>;
21
32
  image: z.ZodOptional<z.ZodURL>;
22
33
  }, z.core.$strip>>;
23
- content: z.ZodOptional<z.ZodString>;
24
- messageType: z.ZodDefault<z.ZodEnum<{
25
- readonly MARKETPLACE: "MARKETPLACE";
26
- readonly PROJECT: "PROJECT";
27
- readonly JOB_OPENING: "JOB_OPENING";
28
- readonly DEFAULT_MESSAGE: "DEFAULT_MESSAGE";
29
- readonly MESSAGE_WITH_LINKS: "MESSAGE_WITH_LINKS";
30
- readonly MESSAGE_WITH_MEDIA: "MESSAGE_WITH_MEDIA";
31
- readonly MESSAGE_WITH_MEDIA_AND_LINKS: "MESSAGE_WITH_MEDIA_AND_LINKS";
32
- }>>;
33
- replyToContent: z.ZodOptional<z.ZodString>;
34
- replyToImages: z.ZodOptional<z.ZodArray<z.ZodURL>>;
35
- replyToLinkMeta: z.ZodOptional<z.ZodObject<{
34
+ linkMeta: z.ZodOptional<z.ZodObject<{
36
35
  url: z.ZodURL;
37
36
  title: z.ZodOptional<z.ZodString>;
38
37
  description: z.ZodOptional<z.ZodString>;
39
38
  image: z.ZodOptional<z.ZodURL>;
40
39
  }, z.core.$strip>>;
41
- createdAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
40
+ createdAt: z.ZodCoercedDate<unknown>;
42
41
  updatedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
43
42
  deletedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
44
43
  }, z.core.$strip>;
45
44
  export declare const MessageFileEntitySchema: z.ZodObject<{
46
- id: z.ZodString;
47
- messageId: z.ZodString;
48
- fileId: z.ZodString;
49
- order: z.ZodNumber;
45
+ id: z.ZodCUID2;
46
+ messageId: z.ZodCUID2;
47
+ fileId: z.ZodCUID2;
48
+ url: z.ZodURL;
49
+ order: z.ZodDefault<z.ZodNumber>;
50
50
  }, z.core.$strip>;
51
51
  export declare const MessageWithFilesEntitySchema: z.ZodObject<{
52
52
  id: z.ZodCUID2;
53
+ chatId: z.ZodCUID2;
54
+ senderId: z.ZodCUID2;
55
+ content: z.ZodDefault<z.ZodOptional<z.ZodString>>;
56
+ messageType: z.ZodDefault<z.ZodEnum<{
57
+ readonly MARKETPLACE: "MARKETPLACE";
58
+ readonly PROJECT: "PROJECT";
59
+ readonly JOB_OPENING: "JOB_OPENING";
60
+ readonly DEFAULT_MESSAGE: "DEFAULT_MESSAGE";
61
+ readonly MESSAGE_WITH_LINKS: "MESSAGE_WITH_LINKS";
62
+ readonly MESSAGE_WITH_MEDIA: "MESSAGE_WITH_MEDIA";
63
+ readonly MESSAGE_WITH_MEDIA_AND_LINKS: "MESSAGE_WITH_MEDIA_AND_LINKS";
64
+ }>>;
53
65
  parentId: z.ZodOptional<z.ZodCUID2>;
54
66
  parentType: z.ZodOptional<z.ZodEnum<{
55
67
  readonly PROJECT: "PROJECT";
@@ -60,47 +72,36 @@ export declare const MessageWithFilesEntitySchema: z.ZodObject<{
60
72
  readonly JOB_APPLICATION: "JOB_APPLICATION";
61
73
  }>>;
62
74
  replyToMessageId: z.ZodOptional<z.ZodCUID2>;
63
- chatId: z.ZodCUID2;
64
- senderId: z.ZodCUID2;
65
- receiverId: z.ZodCUID2;
66
- linkMeta: z.ZodOptional<z.ZodObject<{
75
+ replyToContent: z.ZodOptional<z.ZodString>;
76
+ replyToImages: z.ZodOptional<z.ZodArray<z.ZodURL>>;
77
+ replyToLinkMeta: z.ZodOptional<z.ZodObject<{
67
78
  url: z.ZodURL;
68
79
  title: z.ZodOptional<z.ZodString>;
69
80
  description: z.ZodOptional<z.ZodString>;
70
81
  image: z.ZodOptional<z.ZodURL>;
71
82
  }, z.core.$strip>>;
72
- content: z.ZodOptional<z.ZodString>;
73
- messageType: z.ZodDefault<z.ZodEnum<{
74
- readonly MARKETPLACE: "MARKETPLACE";
75
- readonly PROJECT: "PROJECT";
76
- readonly JOB_OPENING: "JOB_OPENING";
77
- readonly DEFAULT_MESSAGE: "DEFAULT_MESSAGE";
78
- readonly MESSAGE_WITH_LINKS: "MESSAGE_WITH_LINKS";
79
- readonly MESSAGE_WITH_MEDIA: "MESSAGE_WITH_MEDIA";
80
- readonly MESSAGE_WITH_MEDIA_AND_LINKS: "MESSAGE_WITH_MEDIA_AND_LINKS";
81
- }>>;
82
- replyToContent: z.ZodOptional<z.ZodString>;
83
- replyToImages: z.ZodOptional<z.ZodArray<z.ZodURL>>;
84
- replyToLinkMeta: z.ZodOptional<z.ZodObject<{
83
+ linkMeta: z.ZodOptional<z.ZodObject<{
85
84
  url: z.ZodURL;
86
85
  title: z.ZodOptional<z.ZodString>;
87
86
  description: z.ZodOptional<z.ZodString>;
88
87
  image: z.ZodOptional<z.ZodURL>;
89
88
  }, z.core.$strip>>;
90
- createdAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
89
+ createdAt: z.ZodCoercedDate<unknown>;
91
90
  updatedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
92
91
  deletedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
93
- messageFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
94
- id: z.ZodString;
95
- messageId: z.ZodString;
96
- fileId: z.ZodString;
97
- order: z.ZodNumber;
92
+ messageFiles: z.ZodDefault<z.ZodArray<z.ZodObject<{
93
+ id: z.ZodCUID2;
94
+ messageId: z.ZodCUID2;
95
+ fileId: z.ZodCUID2;
98
96
  url: z.ZodURL;
97
+ order: z.ZodDefault<z.ZodNumber>;
99
98
  }, z.core.$strip>>>;
100
99
  }, z.core.$strip>;
101
100
  export declare const CreateMessageInputSchema: z.ZodObject<{
102
101
  id: z.ZodCUID2;
103
- parentId: z.ZodOptional<z.ZodCUID2>;
102
+ chatId: z.ZodCUID2;
103
+ senderId: z.ZodCUID2;
104
+ receiverId: z.ZodCUID2;
104
105
  content: z.ZodOptional<z.ZodString>;
105
106
  messageType: z.ZodDefault<z.ZodEnum<{
106
107
  readonly MARKETPLACE: "MARKETPLACE";
@@ -111,14 +112,7 @@ export declare const CreateMessageInputSchema: z.ZodObject<{
111
112
  readonly MESSAGE_WITH_MEDIA: "MESSAGE_WITH_MEDIA";
112
113
  readonly MESSAGE_WITH_MEDIA_AND_LINKS: "MESSAGE_WITH_MEDIA_AND_LINKS";
113
114
  }>>;
114
- files: z.ZodOptional<z.ZodArray<z.ZodObject<{
115
- key: z.ZodString;
116
- mimeType: z.ZodString;
117
- order: z.ZodDefault<z.ZodInt>;
118
- }, z.core.$strip>>>;
119
- chatId: z.ZodString;
120
- senderId: z.ZodString;
121
- receiverId: z.ZodString;
115
+ parentId: z.ZodOptional<z.ZodCUID2>;
122
116
  replyToMessageId: z.ZodOptional<z.ZodCUID2>;
123
117
  linkMeta: z.ZodOptional<z.ZodObject<{
124
118
  url: z.ZodURL;
@@ -126,9 +120,78 @@ export declare const CreateMessageInputSchema: z.ZodObject<{
126
120
  description: z.ZodOptional<z.ZodString>;
127
121
  image: z.ZodOptional<z.ZodURL>;
128
122
  }, z.core.$strip>>;
123
+ files: z.ZodOptional<z.ZodArray<z.ZodObject<{
124
+ key: z.ZodString;
125
+ mimeType: z.ZodString;
126
+ order: z.ZodNumber;
127
+ }, z.core.$strip>>>;
128
+ }, z.core.$strip>;
129
+ export declare const GetMessagesOutputSchema: z.ZodObject<{
130
+ messages: z.ZodArray<z.ZodObject<{
131
+ id: z.ZodCUID2;
132
+ chatId: z.ZodCUID2;
133
+ senderId: z.ZodCUID2;
134
+ content: z.ZodDefault<z.ZodOptional<z.ZodString>>;
135
+ messageType: z.ZodDefault<z.ZodEnum<{
136
+ readonly MARKETPLACE: "MARKETPLACE";
137
+ readonly PROJECT: "PROJECT";
138
+ readonly JOB_OPENING: "JOB_OPENING";
139
+ readonly DEFAULT_MESSAGE: "DEFAULT_MESSAGE";
140
+ readonly MESSAGE_WITH_LINKS: "MESSAGE_WITH_LINKS";
141
+ readonly MESSAGE_WITH_MEDIA: "MESSAGE_WITH_MEDIA";
142
+ readonly MESSAGE_WITH_MEDIA_AND_LINKS: "MESSAGE_WITH_MEDIA_AND_LINKS";
143
+ }>>;
144
+ parentId: z.ZodOptional<z.ZodCUID2>;
145
+ parentType: z.ZodOptional<z.ZodEnum<{
146
+ readonly PROJECT: "PROJECT";
147
+ readonly USER: "USER";
148
+ readonly JOB: "JOB";
149
+ readonly POST: "POST";
150
+ readonly COMMENT: "COMMENT";
151
+ readonly JOB_APPLICATION: "JOB_APPLICATION";
152
+ }>>;
153
+ replyToMessageId: z.ZodOptional<z.ZodCUID2>;
154
+ replyToContent: z.ZodOptional<z.ZodString>;
155
+ replyToImages: z.ZodOptional<z.ZodArray<z.ZodURL>>;
156
+ replyToLinkMeta: z.ZodOptional<z.ZodObject<{
157
+ url: z.ZodURL;
158
+ title: z.ZodOptional<z.ZodString>;
159
+ description: z.ZodOptional<z.ZodString>;
160
+ image: z.ZodOptional<z.ZodURL>;
161
+ }, z.core.$strip>>;
162
+ linkMeta: z.ZodOptional<z.ZodObject<{
163
+ url: z.ZodURL;
164
+ title: z.ZodOptional<z.ZodString>;
165
+ description: z.ZodOptional<z.ZodString>;
166
+ image: z.ZodOptional<z.ZodURL>;
167
+ }, z.core.$strip>>;
168
+ createdAt: z.ZodCoercedDate<unknown>;
169
+ updatedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
170
+ deletedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
171
+ messageFiles: z.ZodDefault<z.ZodArray<z.ZodObject<{
172
+ id: z.ZodCUID2;
173
+ messageId: z.ZodCUID2;
174
+ fileId: z.ZodCUID2;
175
+ url: z.ZodURL;
176
+ order: z.ZodDefault<z.ZodNumber>;
177
+ }, z.core.$strip>>>;
178
+ }, z.core.$strip>>;
179
+ nextCursor: z.ZodNullable<z.ZodString>;
129
180
  }, z.core.$strip>;
130
181
  export declare const CreateMessageOutputSchema: z.ZodObject<{
131
182
  id: z.ZodCUID2;
183
+ chatId: z.ZodCUID2;
184
+ senderId: z.ZodCUID2;
185
+ content: z.ZodDefault<z.ZodOptional<z.ZodString>>;
186
+ messageType: z.ZodDefault<z.ZodEnum<{
187
+ readonly MARKETPLACE: "MARKETPLACE";
188
+ readonly PROJECT: "PROJECT";
189
+ readonly JOB_OPENING: "JOB_OPENING";
190
+ readonly DEFAULT_MESSAGE: "DEFAULT_MESSAGE";
191
+ readonly MESSAGE_WITH_LINKS: "MESSAGE_WITH_LINKS";
192
+ readonly MESSAGE_WITH_MEDIA: "MESSAGE_WITH_MEDIA";
193
+ readonly MESSAGE_WITH_MEDIA_AND_LINKS: "MESSAGE_WITH_MEDIA_AND_LINKS";
194
+ }>>;
132
195
  parentId: z.ZodOptional<z.ZodCUID2>;
133
196
  parentType: z.ZodOptional<z.ZodEnum<{
134
197
  readonly PROJECT: "PROJECT";
@@ -139,40 +202,21 @@ export declare const CreateMessageOutputSchema: z.ZodObject<{
139
202
  readonly JOB_APPLICATION: "JOB_APPLICATION";
140
203
  }>>;
141
204
  replyToMessageId: z.ZodOptional<z.ZodCUID2>;
142
- chatId: z.ZodCUID2;
143
- senderId: z.ZodCUID2;
144
- receiverId: z.ZodCUID2;
145
- linkMeta: z.ZodOptional<z.ZodObject<{
205
+ replyToContent: z.ZodOptional<z.ZodString>;
206
+ replyToImages: z.ZodOptional<z.ZodArray<z.ZodURL>>;
207
+ replyToLinkMeta: z.ZodOptional<z.ZodObject<{
146
208
  url: z.ZodURL;
147
209
  title: z.ZodOptional<z.ZodString>;
148
210
  description: z.ZodOptional<z.ZodString>;
149
211
  image: z.ZodOptional<z.ZodURL>;
150
212
  }, z.core.$strip>>;
151
- content: z.ZodOptional<z.ZodString>;
152
- messageType: z.ZodDefault<z.ZodEnum<{
153
- readonly MARKETPLACE: "MARKETPLACE";
154
- readonly PROJECT: "PROJECT";
155
- readonly JOB_OPENING: "JOB_OPENING";
156
- readonly DEFAULT_MESSAGE: "DEFAULT_MESSAGE";
157
- readonly MESSAGE_WITH_LINKS: "MESSAGE_WITH_LINKS";
158
- readonly MESSAGE_WITH_MEDIA: "MESSAGE_WITH_MEDIA";
159
- readonly MESSAGE_WITH_MEDIA_AND_LINKS: "MESSAGE_WITH_MEDIA_AND_LINKS";
160
- }>>;
161
- replyToContent: z.ZodOptional<z.ZodString>;
162
- replyToImages: z.ZodOptional<z.ZodArray<z.ZodURL>>;
163
- replyToLinkMeta: z.ZodOptional<z.ZodObject<{
213
+ linkMeta: z.ZodOptional<z.ZodObject<{
164
214
  url: z.ZodURL;
165
215
  title: z.ZodOptional<z.ZodString>;
166
216
  description: z.ZodOptional<z.ZodString>;
167
217
  image: z.ZodOptional<z.ZodURL>;
168
218
  }, z.core.$strip>>;
169
- createdAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
219
+ createdAt: z.ZodCoercedDate<unknown>;
170
220
  updatedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
171
221
  deletedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
172
222
  }, z.core.$strip>;
173
- export declare const GetMessagesOutputSchema: z.ZodArray<z.ZodObject<{
174
- id: z.ZodString;
175
- messageId: z.ZodString;
176
- fileId: z.ZodString;
177
- order: z.ZodNumber;
178
- }, z.core.$strip>>;
@@ -1,110 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetMessagesOutputSchema = exports.CreateMessageOutputSchema = exports.CreateMessageInputSchema = exports.MessageWithFilesEntitySchema = exports.MessageFileEntitySchema = exports.MessageEntitySchema = void 0;
3
+ exports.CreateMessageOutputSchema = exports.GetMessagesOutputSchema = exports.CreateMessageInputSchema = exports.MessageWithFilesEntitySchema = exports.MessageFileEntitySchema = exports.MessageEntitySchema = void 0;
4
4
  const zod_openapi_1 = require("@hono/zod-openapi");
5
5
  const constants_1 = require("../constants");
6
6
  const file_1 = require("./file");
7
+ // 1. Base primitives
8
+ const LinkMetaSchema = zod_openapi_1.z.object({
9
+ url: zod_openapi_1.z.url(),
10
+ title: zod_openapi_1.z.string().optional(),
11
+ description: zod_openapi_1.z.string().optional(),
12
+ image: zod_openapi_1.z.url().optional(),
13
+ });
14
+ // 2. The API Output Schema (Enriched)
7
15
  exports.MessageEntitySchema = zod_openapi_1.z.object({
8
16
  id: zod_openapi_1.z.cuid2(),
9
- parentId: zod_openapi_1.z.cuid2().optional(),
10
- parentType: zod_openapi_1.z.enum(constants_1.ACTIVITY_PARENT_TYPES).optional(),
11
- replyToMessageId: zod_openapi_1.z.cuid2().optional(),
12
17
  chatId: zod_openapi_1.z.cuid2(),
13
18
  senderId: zod_openapi_1.z.cuid2(),
14
- receiverId: zod_openapi_1.z.cuid2(),
15
- linkMeta: zod_openapi_1.z
16
- .object({
17
- url: zod_openapi_1.z.url(),
18
- title: zod_openapi_1.z.string().optional(),
19
- description: zod_openapi_1.z.string().optional(),
20
- image: zod_openapi_1.z.url().optional(),
21
- })
22
- .optional(),
23
- content: zod_openapi_1.z.string().optional(),
24
- messageType: zod_openapi_1.z.enum(constants_1.MESSAGE_TYPES).default(constants_1.MESSAGE_TYPES.DEFAULT_MESSAGE),
19
+ // Content & Type
20
+ content: zod_openapi_1.z.string().optional().default(""),
21
+ messageType: zod_openapi_1.z.enum(constants_1.MESSAGE_TYPES).default("DEFAULT_MESSAGE"),
22
+ // Parent/Threading
23
+ parentId: zod_openapi_1.z.cuid2().optional(), // For threads/comments
24
+ parentType: zod_openapi_1.z.enum(constants_1.ACTIVITY_PARENT_TYPES).optional(),
25
+ // Reply Context (Flattened for UI convenience)
26
+ replyToMessageId: zod_openapi_1.z.cuid2().optional(),
25
27
  replyToContent: zod_openapi_1.z.string().optional(),
26
28
  replyToImages: zod_openapi_1.z.array(zod_openapi_1.z.url()).optional(),
27
- replyToLinkMeta: zod_openapi_1.z
28
- .object({
29
- url: zod_openapi_1.z.url(),
30
- title: zod_openapi_1.z.string().optional(),
31
- description: zod_openapi_1.z.string().optional(),
32
- image: zod_openapi_1.z.url().optional(),
33
- })
34
- .optional(),
35
- createdAt: zod_openapi_1.z.coerce.date().optional(),
29
+ replyToLinkMeta: LinkMetaSchema.optional(),
30
+ // Metadata
31
+ linkMeta: LinkMetaSchema.optional(),
32
+ createdAt: zod_openapi_1.z.coerce.date(),
36
33
  updatedAt: zod_openapi_1.z.coerce.date().optional(),
37
34
  deletedAt: zod_openapi_1.z.coerce.date().optional(),
38
35
  });
39
- exports.MessageFileEntitySchema = zod_openapi_1.z
40
- .object({
41
- id: zod_openapi_1.z
42
- .string()
43
- .openapi({ description: "CUID2 of the project file record." }),
44
- messageId: zod_openapi_1.z.string().openapi({
45
- description: "CUID2 of the message this file belongs to.",
46
- }),
47
- fileId: zod_openapi_1.z.string().openapi({ description: "CUID2 of the linked file." }),
48
- order: zod_openapi_1.z.number().int().openapi({
49
- description: "Order index of the file in the project.",
50
- example: 1,
51
- }),
52
- })
53
- .openapi({
54
- title: "Message File Entity",
55
- description: "Schema representing a file associated with a project.",
36
+ exports.MessageFileEntitySchema = zod_openapi_1.z.object({
37
+ id: zod_openapi_1.z.cuid2(),
38
+ messageId: zod_openapi_1.z.cuid2(),
39
+ fileId: zod_openapi_1.z.cuid2(),
40
+ url: zod_openapi_1.z.url(),
41
+ order: zod_openapi_1.z.number().int().default(0),
56
42
  });
57
43
  exports.MessageWithFilesEntitySchema = exports.MessageEntitySchema.extend({
58
- messageFiles: zod_openapi_1.z
59
- .array(exports.MessageFileEntitySchema.extend({
60
- url: zod_openapi_1.z.url(),
61
- }))
62
- .optional()
63
- .openapi({ description: "Files associated with the project." }),
44
+ messageFiles: zod_openapi_1.z.array(exports.MessageFileEntitySchema).default([]),
64
45
  });
46
+ // 3. Inputs
65
47
  exports.CreateMessageInputSchema = zod_openapi_1.z.object({
66
- id: zod_openapi_1.z.cuid2(),
67
- parentId: zod_openapi_1.z
68
- .cuid2()
69
- .optional()
70
- .openapi({ description: "Parent id", example: "ckl1a2b3c0000abc" }),
71
- content: zod_openapi_1.z
72
- .string()
73
- .openapi({
74
- description: "Message content",
75
- example: "New project announcement",
76
- })
77
- .optional(),
78
- messageType: zod_openapi_1.z
79
- .enum(constants_1.MESSAGE_TYPES)
80
- .default("DEFAULT_MESSAGE")
81
- .openapi({ description: "Message type", example: "PROJECT" }),
82
- files: zod_openapi_1.z
83
- .array(file_1.CreateFileInputSchema.extend({
84
- order: zod_openapi_1.z.int().default(1),
85
- }))
86
- .optional(),
87
- chatId: zod_openapi_1.z.string(),
88
- senderId: zod_openapi_1.z.string(),
89
- receiverId: zod_openapi_1.z.string(),
48
+ id: zod_openapi_1.z.cuid2(), // Frontend generates ID for optimistic updates
49
+ chatId: zod_openapi_1.z.cuid2(),
50
+ senderId: zod_openapi_1.z.cuid2(),
51
+ receiverId: zod_openapi_1.z.cuid2(),
52
+ content: zod_openapi_1.z.string().optional(),
53
+ messageType: zod_openapi_1.z.enum(constants_1.MESSAGE_TYPES).default("DEFAULT_MESSAGE"),
54
+ parentId: zod_openapi_1.z.cuid2().optional(),
90
55
  replyToMessageId: zod_openapi_1.z.cuid2().optional(),
91
- linkMeta: zod_openapi_1.z
92
- .object({
93
- url: zod_openapi_1.z.url(),
94
- title: zod_openapi_1.z.string().optional(),
95
- description: zod_openapi_1.z.string().optional(),
96
- image: zod_openapi_1.z.url().optional(),
97
- })
98
- .optional()
99
- .openapi({
100
- description: "Optional metadata for a single link in the message",
101
- example: {
102
- url: "https://example.com",
103
- title: "Example Website",
104
- description: "This is an example link",
105
- image: "https://example.com/preview.jpg",
106
- },
107
- }),
56
+ linkMeta: LinkMetaSchema.optional(),
57
+ files: zod_openapi_1.z.array(file_1.CreateFileInputSchema.extend({ order: zod_openapi_1.z.number().int() })).optional(),
58
+ });
59
+ exports.GetMessagesOutputSchema = zod_openapi_1.z.object({
60
+ messages: zod_openapi_1.z.array(exports.MessageWithFilesEntitySchema),
61
+ nextCursor: zod_openapi_1.z.string().nullable(),
108
62
  });
109
63
  exports.CreateMessageOutputSchema = exports.MessageEntitySchema;
110
- exports.GetMessagesOutputSchema = zod_openapi_1.z.array(exports.MessageFileEntitySchema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyacreatives/shared",
3
- "version": "2.2.30",
3
+ "version": "2.2.32",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,29 +1,36 @@
1
1
  import { z } from "@hono/zod-openapi";
2
2
  import { MESSAGE_REQUEST_STATUS } from "../constants";
3
3
 
4
+ // 1. DB Representation (What is actually in Postgres)
4
5
  export const BaseChatEntitySchema = z.object({
5
6
  id: z.cuid2(),
6
7
  senderId: z.cuid2(),
7
8
  receiverId: z.cuid2(),
8
9
  isMessageRequest: z.boolean().default(true),
9
10
  messageRequestStatus: z.enum(MESSAGE_REQUEST_STATUS).default("PENDING"),
10
- acceptedAt: z.coerce.date(),
11
- declinedAt: z.coerce.date(),
11
+ acceptedAt: z.coerce.date().nullable(),
12
+ declinedAt: z.coerce.date().nullable(),
12
13
  createdAt: z.coerce.date(),
13
14
  updatedAt: z.coerce.date(),
14
- deletedAt: z.coerce.date(),
15
+ deletedAt: z.coerce.date().nullable(),
15
16
  });
16
17
 
18
+ // 2. API Representation (Enriched with Redis/User data)
17
19
  export const ChatEntitySchema = BaseChatEntitySchema.extend({
18
- senderImgUrl: z.string().optional(),
20
+ // User Details (Joined)
19
21
  senderName: z.string(),
20
22
  senderUsername: z.string(),
23
+ senderImgUrl: z.string().optional(),
24
+
25
+ receiverName: z.string(),
21
26
  receiverUsername: z.string(),
22
27
  receiverImgUrl: z.string().optional(),
23
- receiverName: z.string(),
28
+
29
+ // Ephemeral/Cached Data
24
30
  lastMessageSent: z.string().optional(),
25
- unreadCount: z.int().optional(),
26
- isOnline: z.boolean().optional(),
31
+ lastMessageAt: z.coerce.date().optional(), // Important for UI sorting
32
+ unreadCount: z.number().int().default(0),
33
+ isOnline: z.boolean().default(false),
27
34
  });
28
35
 
29
36
  export const CreateChatInputSchema = z.object({
@@ -2,116 +2,74 @@ import { z } from "@hono/zod-openapi";
2
2
  import { ACTIVITY_PARENT_TYPES, MESSAGE_TYPES } from "../constants";
3
3
  import { CreateFileInputSchema } from "./file";
4
4
 
5
+ // 1. Base primitives
6
+ const LinkMetaSchema = z.object({
7
+ url: z.url(),
8
+ title: z.string().optional(),
9
+ description: z.string().optional(),
10
+ image: z.url().optional(),
11
+ });
12
+
13
+ // 2. The API Output Schema (Enriched)
5
14
  export const MessageEntitySchema = z.object({
6
15
  id: z.cuid2(),
7
- parentId: z.cuid2().optional(),
8
- parentType: z.enum(ACTIVITY_PARENT_TYPES).optional(),
9
- replyToMessageId: z.cuid2().optional(),
10
16
  chatId: z.cuid2(),
11
17
  senderId: z.cuid2(),
12
- receiverId: z.cuid2(),
13
- linkMeta: z
14
- .object({
15
- url: z.url(),
16
- title: z.string().optional(),
17
- description: z.string().optional(),
18
- image: z.url().optional(),
19
- })
20
- .optional(),
21
- content: z.string().optional(),
22
- messageType: z.enum(MESSAGE_TYPES).default(MESSAGE_TYPES.DEFAULT_MESSAGE),
18
+
19
+ // Content & Type
20
+ content: z.string().optional().default(""),
21
+ messageType: z.enum(MESSAGE_TYPES).default("DEFAULT_MESSAGE"),
22
+
23
+ // Parent/Threading
24
+ parentId: z.cuid2().optional(), // For threads/comments
25
+ parentType: z.enum(ACTIVITY_PARENT_TYPES).optional(),
26
+
27
+ // Reply Context (Flattened for UI convenience)
28
+ replyToMessageId: z.cuid2().optional(),
23
29
  replyToContent: z.string().optional(),
24
30
  replyToImages: z.array(z.url()).optional(),
25
- replyToLinkMeta: z
26
- .object({
27
- url: z.url(),
28
- title: z.string().optional(),
29
- description: z.string().optional(),
30
- image: z.url().optional(),
31
- })
32
- .optional(),
33
- createdAt: z.coerce.date().optional(),
31
+ replyToLinkMeta: LinkMetaSchema.optional(),
32
+
33
+ // Metadata
34
+ linkMeta: LinkMetaSchema.optional(),
35
+ createdAt: z.coerce.date(),
34
36
  updatedAt: z.coerce.date().optional(),
35
37
  deletedAt: z.coerce.date().optional(),
36
38
  });
37
39
 
38
- export const MessageFileEntitySchema = z
39
- .object({
40
- id: z
41
- .string()
42
- .openapi({ description: "CUID2 of the project file record." }),
43
- messageId: z.string().openapi({
44
- description: "CUID2 of the message this file belongs to.",
45
- }),
46
- fileId: z.string().openapi({ description: "CUID2 of the linked file." }),
47
- order: z.number().int().openapi({
48
- description: "Order index of the file in the project.",
49
- example: 1,
50
- }),
51
- })
52
- .openapi({
53
- title: "Message File Entity",
54
- description: "Schema representing a file associated with a project.",
55
- });
40
+ export const MessageFileEntitySchema = z.object({
41
+ id: z.cuid2(),
42
+ messageId: z.cuid2(),
43
+ fileId: z.cuid2(),
44
+ url: z.url(),
45
+ order: z.number().int().default(0),
46
+ });
56
47
 
57
48
  export const MessageWithFilesEntitySchema = MessageEntitySchema.extend({
58
- messageFiles: z
59
- .array(
60
- MessageFileEntitySchema.extend({
61
- url: z.url(),
62
- }),
63
- )
64
- .optional()
65
- .openapi({ description: "Files associated with the project." }),
49
+ messageFiles: z.array(MessageFileEntitySchema).default([]),
66
50
  });
67
51
 
52
+ // 3. Inputs
68
53
  export const CreateMessageInputSchema = z.object({
69
- id: z.cuid2(),
70
- parentId: z
71
- .cuid2()
72
- .optional()
73
- .openapi({ description: "Parent id", example: "ckl1a2b3c0000abc" }),
74
- content: z
75
- .string()
76
- .openapi({
77
- description: "Message content",
78
- example: "New project announcement",
79
- })
80
- .optional(),
81
- messageType: z
82
- .enum(MESSAGE_TYPES)
83
- .default("DEFAULT_MESSAGE")
84
- .openapi({ description: "Message type", example: "PROJECT" }),
85
- files: z
86
- .array(
87
- CreateFileInputSchema.extend({
88
- order: z.int().default(1),
89
- }),
90
- )
91
- .optional(),
92
- chatId: z.string(),
93
- senderId: z.string(),
94
- receiverId: z.string(),
54
+ id: z.cuid2(), // Frontend generates ID for optimistic updates
55
+ chatId: z.cuid2(),
56
+ senderId: z.cuid2(),
57
+ receiverId: z.cuid2(),
58
+
59
+ content: z.string().optional(),
60
+ messageType: z.enum(MESSAGE_TYPES).default("DEFAULT_MESSAGE"),
61
+
62
+ parentId: z.cuid2().optional(),
95
63
  replyToMessageId: z.cuid2().optional(),
96
- linkMeta: z
97
- .object({
98
- url: z.url(),
99
- title: z.string().optional(),
100
- description: z.string().optional(),
101
- image: z.url().optional(),
102
- })
103
- .optional()
104
- .openapi({
105
- description: "Optional metadata for a single link in the message",
106
- example: {
107
- url: "https://example.com",
108
- title: "Example Website",
109
- description: "This is an example link",
110
- image: "https://example.com/preview.jpg",
111
- },
112
- }),
64
+
65
+ linkMeta: LinkMetaSchema.optional(),
66
+ files: z.array(CreateFileInputSchema.extend({ order: z.number().int() })).optional(),
67
+ });
68
+
69
+ export const GetMessagesOutputSchema = z.object({
70
+ messages: z.array(MessageWithFilesEntitySchema),
71
+ nextCursor: z.string().nullable(),
113
72
  });
114
73
 
115
74
  export const CreateMessageOutputSchema = MessageEntitySchema;
116
75
 
117
- export const GetMessagesOutputSchema = z.array(MessageFileEntitySchema);