@zyacreatives/shared 2.5.55 → 2.5.57

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.
@@ -1,4 +1,5 @@
1
1
  import { z } from "@hono/zod-openapi";
2
+
2
3
  import {
3
4
  CLIENT_TYPES,
4
5
  PROJECT_STATUS,
@@ -6,6 +7,7 @@ import {
6
7
  VENTURE_STAGES,
7
8
  WAGES_CURRENCY,
8
9
  } from "../constants";
10
+
9
11
  import { CommentEntitySchema } from "./comment";
10
12
  import { BookmarkEntitySchema } from "./bookmark";
11
13
  import { MinimalUserSchema } from "./user";
@@ -13,42 +15,78 @@ import { ActivitySchema } from "./activity";
13
15
  import { FileEntitySchema } from "./file";
14
16
  import { LikeEntitySchema } from "./like";
15
17
 
18
+ /**
19
+ * --------------------------------
20
+ * SHAPE
21
+ * --------------------------------
22
+ */
23
+
24
+ const ProjectShape = z.object({
25
+ title: z.string(),
26
+ description: z.string().optional(),
27
+ overview: z.string().optional(),
28
+ url: z.url().optional(),
29
+
30
+ imagePlaceholderUrl: z.url(),
31
+
32
+ tags: z.array(z.string()).optional(),
33
+
34
+ projectCreatorType: z.enum(ROLES),
35
+
36
+ clientId: z.cuid2().optional(),
37
+ clientType: z.enum(CLIENT_TYPES).optional(),
38
+ clientName: z.string().optional(),
39
+
40
+ status: z.enum(PROJECT_STATUS),
41
+
42
+ isFeatured: z.boolean().optional(),
43
+
44
+ problemBeingSolved: z.string().max(600).optional(),
45
+ whoItsFor: z.string().max(600).optional(),
46
+
47
+ ventureStage: z.enum(VENTURE_STAGES).optional(),
48
+ capitalLookingToRaise: z.number(),
49
+ capitalLookingToRaiseCurrency: z.enum(WAGES_CURRENCY).optional(),
50
+
51
+ currentTraction: z.string().max(600),
52
+ isOpenToInvestment: z.boolean().default(false),
53
+
54
+ startDate: z.iso.datetime().optional(),
55
+ endDate: z.iso.datetime().optional(),
56
+ });
57
+
58
+ export type ProjectShapeType = z.infer<typeof ProjectShape>;
59
+
60
+ /**
61
+ * --------------------------------
62
+ * BASE ENTITY
63
+ * --------------------------------
64
+ */
65
+
16
66
  export const ProjectEntitySchema = z
17
67
  .object({
18
68
  id: z.cuid2(),
19
69
  userId: z.cuid2(),
20
- title: z.string(),
21
- description: z.string().optional(),
22
- overview: z.string().optional(),
23
- url: z.url().optional(),
24
- imagePlaceholderUrl: z.url(),
25
- tags: z.array(z.string()).optional(),
26
- projectCreatorType: z.enum(ROLES),
27
- clientId: z.cuid2().optional(),
28
- status: z.enum(PROJECT_STATUS),
29
- clientType: z.enum(CLIENT_TYPES).optional(),
30
- clientName: z.string().optional(),
31
- isFeatured: z.boolean().optional(),
32
- problemBeingSolved: z.string().max(600).optional(),
33
- whoItsFor: z.string().max(600).optional(),
34
- ventureStage: z.enum(VENTURE_STAGES).optional(),
35
- capitalLookingToRaise: z.number(),
36
- capitalLookingToRaiseCurrency: z.enum(WAGES_CURRENCY).optional(),
37
- currentTraction: z.string().max(600),
38
- isOpenToInvestment: z.boolean().default(false),
39
- startDate: z.coerce.date().optional(),
40
- endDate: z.coerce.date().optional(),
41
- createdAt: z.coerce.date(),
42
- updatedAt: z.coerce.date(),
43
- version: z.number().int(),
70
+
71
+ ...ProjectShape.shape,
72
+
73
+ createdAt: z.iso.datetime(),
74
+ updatedAt: z.iso.datetime(),
75
+ version: z.int(),
44
76
  })
45
- .openapi("ProjectEntity");
77
+ .openapi("Project");
46
78
 
47
79
  export type ProjectEntity = z.infer<typeof ProjectEntitySchema>;
48
80
 
81
+ /**
82
+ * --------------------------------
83
+ * DERIVED ENTITIES
84
+ * --------------------------------
85
+ */
86
+
49
87
  export const ProjectWithFilesEntitySchema = ProjectEntitySchema.extend({
50
88
  files: z.array(FileEntitySchema).optional(),
51
- }).openapi("ProjectWithFilesEntity");
89
+ }).openapi("ProjectWithFiles");
52
90
 
53
91
  export type ProjectWithFilesEntity = z.infer<
54
92
  typeof ProjectWithFilesEntitySchema
@@ -73,15 +111,93 @@ export const ProjectSocialGraphEntitySchema = z
73
111
  noOfBookmarks: z.number().int().optional(),
74
112
  noOfViews: z.number().int().optional(),
75
113
  })
76
- .openapi("ProjectSocialGraphEntity");
114
+ .openapi("ProjectSocialGraph");
77
115
 
78
116
  export type ProjectSocialGraphEntity = z.infer<
79
117
  typeof ProjectSocialGraphEntitySchema
80
118
  >;
119
+
81
120
  export type PostSocialGraphEntity = z.infer<
82
121
  typeof ProjectSocialGraphEntitySchema
83
122
  >;
84
123
 
124
+ export const ProjectDetailsEntitySchema = ProjectEntitySchema.extend({
125
+ user: MinimalUserSchema,
126
+ files: z.array(FileEntitySchema).optional(),
127
+ }).openapi("ProjectDetails");
128
+
129
+ export type ProjectDetailsEntity = z.infer<typeof ProjectDetailsEntitySchema>;
130
+
131
+ export const ProjectWithProjectCommentsEntitySchema =
132
+ MinimalProjectSchema.extend({
133
+ comments: z.array(CommentEntitySchema),
134
+ }).openapi("ProjectWithProjectComments");
135
+
136
+ export type ProjectWithProjectCommentsEntity = z.infer<
137
+ typeof ProjectWithProjectCommentsEntitySchema
138
+ >;
139
+
140
+ export const ProjectWithLikesEntitySchema = MinimalProjectSchema.extend({
141
+ likes: z.array(
142
+ ActivitySchema.extend({
143
+ followsYou: z.boolean().optional(),
144
+ isFollowing: z.boolean().optional(),
145
+ }),
146
+ ),
147
+ }).openapi("ProjectWithLikes");
148
+
149
+ export type ProjectWithLikesEntity = z.infer<
150
+ typeof ProjectWithLikesEntitySchema
151
+ >;
152
+
153
+ export const ProjectWithProjectBookmarksEntitySchema =
154
+ MinimalProjectSchema.extend({
155
+ bookmarks: z.array(BookmarkEntitySchema),
156
+ }).openapi("ProjectWithProjectBookmarks");
157
+
158
+ export type ProjectWithProjectBookmarksEntity = z.infer<
159
+ typeof ProjectWithProjectBookmarksEntitySchema
160
+ >;
161
+
162
+ /**
163
+ * --------------------------------
164
+ * INPUT HELPERS
165
+ * --------------------------------
166
+ */
167
+
168
+ const coerceArray = (value: unknown) => {
169
+ if (typeof value === "string") return value === "" ? [] : value.split(",");
170
+ return value;
171
+ };
172
+
173
+ const coerceBoolean = (value: unknown) => {
174
+ if (value === "true") return true;
175
+ if (value === "false") return false;
176
+ return value;
177
+ };
178
+
179
+ const nullableStringToUndefined = (value: unknown) => {
180
+ if (value === "" || value === null || value === undefined) return undefined;
181
+ return value;
182
+ };
183
+
184
+ const urlInputSchema = z
185
+ .string()
186
+ .transform((value) => {
187
+ if (!value) return value;
188
+ if (value.startsWith("http://") || value.startsWith("https://")) {
189
+ return value;
190
+ }
191
+ return `https://${value}`;
192
+ })
193
+ .pipe(z.url().or(z.literal("")));
194
+
195
+ /**
196
+ * --------------------------------
197
+ * INPUTS
198
+ * --------------------------------
199
+ */
200
+
85
201
  export const CreateProjectInputSchema = z
86
202
  .object({
87
203
  id: z.cuid2().optional(),
@@ -97,67 +213,81 @@ export type CreateProjectInput = z.infer<typeof CreateProjectInputSchema>;
97
213
  export const UpdateProjectInputSchema = z
98
214
  .object({
99
215
  id: z.cuid2(),
216
+
100
217
  title: z.string().optional(),
218
+
101
219
  description: z
102
220
  .string()
103
221
  .min(10, "Add a bit more detail to your description.")
104
222
  .optional(),
223
+
105
224
  overview: z.string().optional(),
106
- url: z
107
- .string()
108
- .transform((val) => {
109
- if (!val) return val;
110
- if (val.startsWith("http://") || val.startsWith("https://")) return val;
111
- return `https://${val}`;
112
- })
113
- .pipe(z.url("Check your link.").or(z.literal("")))
114
- .optional(),
225
+
226
+ url: urlInputSchema.optional(),
227
+
115
228
  imagePlaceholderUrl: z.url().optional().or(z.literal("")),
229
+
116
230
  tags: z.array(z.string()).optional(),
231
+
117
232
  projectCreatorType: z.enum(ROLES).optional(),
118
- clientId: z
119
- .string()
120
- .optional()
121
- .transform((val) => (val === "" || val === undefined ? undefined : val))
122
- .pipe(z.cuid2().optional()),
233
+
234
+ clientId: z.preprocess(nullableStringToUndefined, z.cuid2().optional()),
235
+
123
236
  clientType: z.enum(CLIENT_TYPES).optional(),
124
237
  clientName: z.string().optional(),
238
+
125
239
  isFeatured: z.boolean().optional(),
240
+
126
241
  status: z.enum(PROJECT_STATUS).optional(),
242
+
127
243
  problemBeingSolved: z
128
244
  .string()
129
245
  .min(20, "Describe the problem you're solving.")
130
246
  .max(600)
131
247
  .optional(),
248
+
132
249
  whoItsFor: z
133
250
  .string()
134
251
  .min(5, "Tell us who this is for.")
135
252
  .max(600)
136
253
  .optional(),
254
+
137
255
  ventureStage: z.enum(VENTURE_STAGES).optional(),
256
+
138
257
  capitalLookingToRaise: z.number().optional(),
139
258
  capitalLookingToRaiseCurrency: z.enum(WAGES_CURRENCY).optional(),
259
+
140
260
  currentTraction: z
141
261
  .string()
142
262
  .min(10, "Share your current traction.")
143
263
  .max(600)
144
264
  .optional(),
265
+
145
266
  isOpenToInvestment: z.boolean().default(false),
146
- startDate: z.coerce.date().optional(),
147
- endDate: z.coerce.date().optional(),
148
- version: z.number().int().default(1),
267
+
268
+ startDate: z.iso.datetime().optional(),
269
+ endDate: z.iso.datetime().optional(),
270
+
271
+ version: z.int().default(1),
149
272
  })
150
273
  .superRefine(({ startDate, endDate }, ctx) => {
274
+ if (!startDate) return;
275
+
151
276
  const today = new Date();
152
277
  today.setHours(0, 0, 0, 0);
153
- if (startDate && startDate > today) {
278
+
279
+ const parsedStartDate = new Date(startDate);
280
+ const parsedEndDate = endDate ? new Date(endDate) : undefined;
281
+
282
+ if (parsedStartDate > today) {
154
283
  ctx.addIssue({
155
284
  path: ["startDate"],
156
285
  code: "custom",
157
286
  message: "Start date cannot be in the future.",
158
287
  });
159
288
  }
160
- if (startDate && endDate && startDate > endDate) {
289
+
290
+ if (parsedEndDate && parsedStartDate > parsedEndDate) {
161
291
  ctx.addIssue({
162
292
  path: ["endDate"],
163
293
  code: "custom",
@@ -173,173 +303,164 @@ export const CommentOnProjectInputSchema = CommentEntitySchema;
173
303
 
174
304
  export type CommentOnProjectInput = z.infer<typeof CommentOnProjectInputSchema>;
175
305
 
176
- export const ProjectDetailsEntitySchema = ProjectEntitySchema.extend({
177
- user: MinimalUserSchema,
178
- files: z.array(FileEntitySchema).optional(),
179
- }).openapi("ProjectDetailsEntity");
306
+ export const SearchProjectsInputSchema = z
307
+ .object({
308
+ query: z.string().optional(),
180
309
 
181
- export type ProjectDetailsEntity = z.infer<typeof ProjectDetailsEntitySchema>;
310
+ limit: z.coerce.number().min(1).max(100).default(40),
311
+ cursor: z.string().optional(),
182
312
 
183
- export const GetProjectOutputSchema = ProjectDetailsEntitySchema.extend({
184
- isLiked: z.boolean().optional(),
185
- isBookmarked: z.boolean().optional(),
186
- }).openapi("GetProjectOutput");
313
+ tags: z.preprocess(coerceArray, z.array(z.string())).optional(),
187
314
 
188
- export type GetProjectOutput = z.infer<typeof GetProjectOutputSchema>;
315
+ isOpenToInvestment: z.preprocess(coerceBoolean, z.boolean()).optional(),
316
+
317
+ minCapital: z.coerce.number().optional(),
318
+ maxCapital: z.coerce.number().optional(),
319
+
320
+ ventureStages: z
321
+ .preprocess(coerceArray, z.array(z.enum(VENTURE_STAGES)))
322
+ .optional(),
323
+
324
+ projectCreatorTypes: z
325
+ .preprocess(coerceArray, z.array(z.enum(ROLES)))
326
+ .optional(),
327
+
328
+ clientTypes: z
329
+ .preprocess(coerceArray, z.array(z.enum(CLIENT_TYPES)))
330
+ .optional(),
331
+ })
332
+ .openapi("SearchProjectsInput");
333
+
334
+ export type SearchProjectsInput = z.infer<typeof SearchProjectsInputSchema>;
335
+
336
+ export const ProjectIdSchema = z.object({
337
+ projectId: z.cuid2(),
338
+ });
339
+
340
+ export type ProjectIdInput = z.infer<typeof ProjectIdSchema>;
341
+
342
+ /**
343
+ * --------------------------------
344
+ * SEARCH DOCUMENT
345
+ * --------------------------------
346
+ */
189
347
 
190
348
  export const ProjectSearchDocumentSchema = z
191
349
  .object({
192
- id: z.string(),
193
- userId: z.string(),
350
+ id: z.cuid2(),
351
+ userId: z.cuid2(),
352
+
194
353
  title: z.string(),
195
354
  imagePlaceholderUrl: z.url(),
355
+
196
356
  projectCreatorType: z.enum(ROLES),
197
357
  isOpenToInvestment: z.boolean(),
198
- createdAt: z.number(),
199
- updatedAt: z.number(),
358
+
359
+ createdAt: z.iso.datetime(),
360
+ updatedAt: z.iso.datetime(),
361
+
200
362
  description: z.string().optional(),
363
+
201
364
  capitalLookingToRaise: z.number().optional(),
202
365
  capitalLookingToRaiseCurrency: z.enum(WAGES_CURRENCY).optional(),
203
366
  ventureStage: z.enum(VENTURE_STAGES).optional(),
367
+
204
368
  url: z.url().optional(),
205
369
  tags: z.array(z.string()).optional(),
370
+
206
371
  creatorUsername: z.string(),
207
372
  creatorImageUrl: z.string(),
208
373
  creatorName: z.string(),
209
- clientId: z.string().optional(),
374
+
375
+ clientId: z.cuid2().optional(),
210
376
  clientType: z.enum(CLIENT_TYPES).optional(),
211
377
  clientName: z.string().optional(),
378
+
212
379
  isFeatured: z.boolean().optional(),
213
- startDate: z.number().optional(),
214
- endDate: z.number().optional(),
380
+
381
+ startDate: z.iso.datetime().optional(),
382
+ endDate: z.iso.datetime().optional(),
383
+
215
384
  files: z.array(FileEntitySchema).optional(),
216
385
  })
217
386
  .openapi("ProjectSearchDocument");
218
387
 
219
388
  export type ProjectSearchDocument = z.infer<typeof ProjectSearchDocumentSchema>;
220
389
 
221
- const coerceArray = (val: unknown) => {
222
- if (typeof val === "string") return val === "" ? [] : val.split(",");
223
- return val;
224
- };
225
-
226
- const coerceBoolean = (val: unknown) => {
227
- if (val === "true") return true;
228
- if (val === "false") return false;
229
- return val;
230
- };
231
-
232
- export const SearchProjectsInputSchema = z
233
- .object({
234
- query: z.string().optional(),
235
-
236
- limit: z.coerce.number().optional().default(40),
237
- cursor: z.string().optional().nullable(),
238
-
239
- tags: z.preprocess(coerceArray, z.array(z.string())).optional(),
390
+ /**
391
+ * --------------------------------
392
+ * OUTPUTS
393
+ * --------------------------------
394
+ */
240
395
 
241
- isOpenToInvestment: z.preprocess(coerceBoolean, z.boolean()).optional(),
242
-
243
- minCapital: z.coerce.number().optional(),
244
- maxCapital: z.coerce.number().optional(),
245
-
246
- ventureStages: z
247
- .preprocess(coerceArray, z.array(z.enum(VENTURE_STAGES)))
248
- .optional(),
249
-
250
- projectCreatorTypes: z
251
- .preprocess(coerceArray, z.array(z.enum(ROLES)))
252
- .optional(),
253
-
254
- clientTypes: z
255
- .preprocess(coerceArray, z.array(z.enum(CLIENT_TYPES)))
256
- .optional(),
257
- })
258
- .openapi("SearchProjectsInput");
396
+ export const GetProjectOutputSchema = ProjectDetailsEntitySchema.extend({
397
+ isLiked: z.boolean().optional(),
398
+ isBookmarked: z.boolean().optional(),
399
+ }).openapi("GetProjectOutput");
259
400
 
260
- export type SearchProjectsInput = z.infer<typeof SearchProjectsInputSchema>;
401
+ export type GetProjectOutput = z.infer<typeof GetProjectOutputSchema>;
261
402
 
262
403
  export const SearchProjectsOutputSchema = z
263
404
  .object({
264
405
  projects: z.array(ProjectSearchDocumentSchema),
265
- nextCursor: z.string().optional().nullable(),
406
+ nextCursor: z.string().optional(),
266
407
  })
267
408
  .openapi("SearchProjectsOutput");
268
409
 
269
410
  export type SearchProjectsOutput = z.infer<typeof SearchProjectsOutputSchema>;
270
411
 
271
- export const ProjectWithProjectCommentsEntitySchema =
272
- MinimalProjectSchema.extend({
273
- comments: z.array(CommentEntitySchema),
274
- }).openapi("ProjectWithProjectCommentsEntity");
275
-
276
- export type ProjectWithProjectCommentsEntity = z.infer<
277
- typeof ProjectWithProjectCommentsEntitySchema
278
- >;
279
-
280
412
  export const GetProjectWithCommentsOutputSchema =
281
413
  ProjectWithProjectCommentsEntitySchema.extend({
282
- nextCursor: z.string().optional().nullable(),
414
+ nextCursor: z.string().optional(),
283
415
  }).openapi("GetProjectWithCommentsOutput");
284
416
 
285
417
  export type GetProjectWithCommentsOutput = z.infer<
286
418
  typeof GetProjectWithCommentsOutputSchema
287
419
  >;
288
420
 
289
- export const ProjectWithLikesEntitySchema = MinimalProjectSchema.extend({
290
- likes: z.array(
291
- ActivitySchema.extend({
292
- followsYou: z.boolean().optional(),
293
- isFollowing: z.boolean().optional(),
294
- }),
295
- ),
296
- }).openapi("ProjectWithLikesEntity");
297
-
298
- export type ProjectWithLikesEntity = z.infer<
299
- typeof ProjectWithLikesEntitySchema
300
- >;
301
-
302
421
  export const GetProjectWithLikesOutputSchema =
303
422
  ProjectWithLikesEntitySchema.extend({
304
- nextCursor: z.string().optional().nullable(),
423
+ nextCursor: z.string().optional(),
305
424
  }).openapi("GetProjectWithLikesOutput");
306
425
 
307
426
  export type GetProjectWithLikesOutput = z.infer<
308
427
  typeof GetProjectWithLikesOutputSchema
309
428
  >;
310
429
 
311
- export const ProjectWithProjectBookmarksEntitySchema =
312
- MinimalProjectSchema.extend({
313
- bookmarks: z.array(BookmarkEntitySchema),
314
- }).openapi("ProjectWithProjectBookmarksEntity");
315
-
316
- export type ProjectWithProjectBookmarksEntity = z.infer<
317
- typeof ProjectWithProjectBookmarksEntitySchema
318
- >;
319
-
320
430
  export const ProjectUpdateOutputEntitySchema = z.object({
321
431
  id: z.cuid2(),
322
432
  });
323
433
 
434
+ export type ProjectUpdateOutputEntity = z.infer<
435
+ typeof ProjectUpdateOutputEntitySchema
436
+ >;
437
+
324
438
  export const CreateProjectOutputSchema = ProjectEntitySchema;
439
+
325
440
  export type CreateProjectOutput = z.infer<typeof CreateProjectOutputSchema>;
326
441
 
327
442
  export const UpdateProjectOutputSchema = ProjectEntitySchema;
443
+
328
444
  export type UpdateProjectOutput = z.infer<typeof UpdateProjectOutputSchema>;
329
445
 
330
446
  export const DeleteProjectOutputSchema = ProjectEntitySchema;
447
+
331
448
  export type DeleteProjectOutput = z.infer<typeof DeleteProjectOutputSchema>;
332
449
 
333
450
  export const CommentOnProjectOutputSchema = CommentEntitySchema.omit({
334
451
  likesCount: true,
335
452
  isLiked: true,
336
453
  });
454
+
337
455
  export type CommentOnProjectOutput = z.infer<
338
456
  typeof CommentOnProjectOutputSchema
339
457
  >;
340
458
 
341
- export const ProjectIdSchema = z.object({ projectId: z.cuid2() });
342
- export type ProjectIdInput = z.infer<typeof ProjectIdSchema>;
459
+ /**
460
+ * --------------------------------
461
+ * ALIASES
462
+ * --------------------------------
463
+ */
343
464
 
344
465
  export type ProjectLikeEntity = z.infer<typeof LikeEntitySchema>;
345
466
  export type ProjectCommentEntity = z.infer<typeof CommentEntitySchema>;