@zyacreatives/shared 2.2.31 → 2.2.33

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(),
@@ -3,6 +3,7 @@ export declare const MessageEntitySchema: z.ZodObject<{
3
3
  id: z.ZodCUID2;
4
4
  chatId: z.ZodCUID2;
5
5
  senderId: z.ZodCUID2;
6
+ receiverId: z.ZodCUID2;
6
7
  content: z.ZodDefault<z.ZodOptional<z.ZodString>>;
7
8
  messageType: z.ZodDefault<z.ZodEnum<{
8
9
  readonly MARKETPLACE: "MARKETPLACE";
@@ -52,6 +53,7 @@ export declare const MessageWithFilesEntitySchema: z.ZodObject<{
52
53
  id: z.ZodCUID2;
53
54
  chatId: z.ZodCUID2;
54
55
  senderId: z.ZodCUID2;
56
+ receiverId: z.ZodCUID2;
55
57
  content: z.ZodDefault<z.ZodOptional<z.ZodString>>;
56
58
  messageType: z.ZodDefault<z.ZodEnum<{
57
59
  readonly MARKETPLACE: "MARKETPLACE";
@@ -131,6 +133,7 @@ export declare const GetMessagesOutputSchema: z.ZodObject<{
131
133
  id: z.ZodCUID2;
132
134
  chatId: z.ZodCUID2;
133
135
  senderId: z.ZodCUID2;
136
+ receiverId: z.ZodCUID2;
134
137
  content: z.ZodDefault<z.ZodOptional<z.ZodString>>;
135
138
  messageType: z.ZodDefault<z.ZodEnum<{
136
139
  readonly MARKETPLACE: "MARKETPLACE";
@@ -182,6 +185,7 @@ export declare const CreateMessageOutputSchema: z.ZodObject<{
182
185
  id: z.ZodCUID2;
183
186
  chatId: z.ZodCUID2;
184
187
  senderId: z.ZodCUID2;
188
+ receiverId: z.ZodCUID2;
185
189
  content: z.ZodDefault<z.ZodOptional<z.ZodString>>;
186
190
  messageType: z.ZodDefault<z.ZodEnum<{
187
191
  readonly MARKETPLACE: "MARKETPLACE";
@@ -16,6 +16,7 @@ exports.MessageEntitySchema = zod_openapi_1.z.object({
16
16
  id: zod_openapi_1.z.cuid2(),
17
17
  chatId: zod_openapi_1.z.cuid2(),
18
18
  senderId: zod_openapi_1.z.cuid2(),
19
+ receiverId: zod_openapi_1.z.cuid2(),
19
20
  // Content & Type
20
21
  content: zod_openapi_1.z.string().optional().default(""),
21
22
  messageType: zod_openapi_1.z.enum(constants_1.MESSAGE_TYPES).default("DEFAULT_MESSAGE"),
@@ -54,7 +55,9 @@ exports.CreateMessageInputSchema = zod_openapi_1.z.object({
54
55
  parentId: zod_openapi_1.z.cuid2().optional(),
55
56
  replyToMessageId: zod_openapi_1.z.cuid2().optional(),
56
57
  linkMeta: LinkMetaSchema.optional(),
57
- files: zod_openapi_1.z.array(file_1.CreateFileInputSchema.extend({ order: zod_openapi_1.z.number().int() })).optional(),
58
+ files: zod_openapi_1.z
59
+ .array(file_1.CreateFileInputSchema.extend({ order: zod_openapi_1.z.number().int() }))
60
+ .optional(),
58
61
  });
59
62
  exports.GetMessagesOutputSchema = zod_openapi_1.z.object({
60
63
  messages: zod_openapi_1.z.array(exports.MessageWithFilesEntitySchema),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyacreatives/shared",
3
- "version": "2.2.31",
3
+ "version": "2.2.33",
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({
@@ -15,15 +15,16 @@ export const MessageEntitySchema = z.object({
15
15
  id: z.cuid2(),
16
16
  chatId: z.cuid2(),
17
17
  senderId: z.cuid2(),
18
+ receiverId: z.cuid2(),
18
19
 
19
20
  // Content & Type
20
21
  content: z.string().optional().default(""),
21
22
  messageType: z.enum(MESSAGE_TYPES).default("DEFAULT_MESSAGE"),
22
-
23
+
23
24
  // Parent/Threading
24
25
  parentId: z.cuid2().optional(), // For threads/comments
25
26
  parentType: z.enum(ACTIVITY_PARENT_TYPES).optional(),
26
-
27
+
27
28
  // Reply Context (Flattened for UI convenience)
28
29
  replyToMessageId: z.cuid2().optional(),
29
30
  replyToContent: z.string().optional(),
@@ -55,15 +56,17 @@ export const CreateMessageInputSchema = z.object({
55
56
  chatId: z.cuid2(),
56
57
  senderId: z.cuid2(),
57
58
  receiverId: z.cuid2(),
58
-
59
+
59
60
  content: z.string().optional(),
60
61
  messageType: z.enum(MESSAGE_TYPES).default("DEFAULT_MESSAGE"),
61
-
62
+
62
63
  parentId: z.cuid2().optional(),
63
64
  replyToMessageId: z.cuid2().optional(),
64
-
65
+
65
66
  linkMeta: LinkMetaSchema.optional(),
66
- files: z.array(CreateFileInputSchema.extend({ order: z.number().int() })).optional(),
67
+ files: z
68
+ .array(CreateFileInputSchema.extend({ order: z.number().int() }))
69
+ .optional(),
67
70
  });
68
71
 
69
72
  export const GetMessagesOutputSchema = z.object({
@@ -72,4 +75,3 @@ export const GetMessagesOutputSchema = z.object({
72
75
  });
73
76
 
74
77
  export const CreateMessageOutputSchema = MessageEntitySchema;
75
-