@tmlmobilidade/go-types-shared 20260611.1527.25

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.
Files changed (51) hide show
  1. package/dist/dates/calendar-date.d.ts +13 -0
  2. package/dist/dates/calendar-date.js +20 -0
  3. package/dist/dates/index.d.ts +3 -0
  4. package/dist/dates/index.js +3 -0
  5. package/dist/dates/operational-date.d.ts +13 -0
  6. package/dist/dates/operational-date.js +20 -0
  7. package/dist/dates/unix-timestamp.d.ts +17 -0
  8. package/dist/dates/unix-timestamp.js +22 -0
  9. package/dist/documents/comment.d.ts +367 -0
  10. package/dist/documents/comment.js +83 -0
  11. package/dist/documents/document.d.ts +27 -0
  12. package/dist/documents/document.js +12 -0
  13. package/dist/environment.d.ts +16 -0
  14. package/dist/environment.js +15 -0
  15. package/dist/fastify.d.ts +11 -0
  16. package/dist/fastify.js +7 -0
  17. package/dist/i18n-code.d.ts +4 -0
  18. package/dist/i18n-code.js +9 -0
  19. package/dist/index.d.ts +9 -0
  20. package/dist/index.js +9 -0
  21. package/dist/position.d.ts +160 -0
  22. package/dist/position.js +41 -0
  23. package/dist/status/approval.d.ts +4 -0
  24. package/dist/status/approval.js +10 -0
  25. package/dist/status/availability.d.ts +4 -0
  26. package/dist/status/availability.js +9 -0
  27. package/dist/status/condition.d.ts +4 -0
  28. package/dist/status/condition.js +11 -0
  29. package/dist/status/delay.d.ts +4 -0
  30. package/dist/status/delay.js +10 -0
  31. package/dist/status/index.d.ts +12 -0
  32. package/dist/status/index.js +12 -0
  33. package/dist/status/lifecycle.d.ts +4 -0
  34. package/dist/status/lifecycle.js +12 -0
  35. package/dist/status/operational.d.ts +4 -0
  36. package/dist/status/operational.js +10 -0
  37. package/dist/status/processing.d.ts +4 -0
  38. package/dist/status/processing.js +11 -0
  39. package/dist/status/publish.d.ts +4 -0
  40. package/dist/status/publish.js +9 -0
  41. package/dist/status/seen.d.ts +4 -0
  42. package/dist/status/seen.js +9 -0
  43. package/dist/status/system.d.ts +4 -0
  44. package/dist/status/system.js +10 -0
  45. package/dist/status/ticketing.d.ts +4 -0
  46. package/dist/status/ticketing.js +8 -0
  47. package/dist/status/validity.d.ts +4 -0
  48. package/dist/status/validity.js +9 -0
  49. package/dist/utility.d.ts +83 -0
  50. package/dist/utility.js +1 -0
  51. package/package.json +50 -0
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ export declare const CALENDAR_DATE_FORMAT = "yyyy-MM-dd";
3
+ export type CalendarDate = string & {
4
+ __brand: 'CalendarDate';
5
+ };
6
+ export declare const CalendarDateSchema: z.ZodEffects<z.ZodString, CalendarDate, string>;
7
+ /**
8
+ * This function validates if a string is a valid calendar date.
9
+ * Throws an error if the date is invalid.
10
+ * @param date - The date to be validated.
11
+ * @returns The given string as a CalendarDate.
12
+ */
13
+ export declare function validateCalendarDate(date: string): CalendarDate;
@@ -0,0 +1,20 @@
1
+ /* * */
2
+ import { DateTime } from 'luxon';
3
+ import { z } from 'zod';
4
+ /* * */
5
+ export const CALENDAR_DATE_FORMAT = 'yyyy-MM-dd';
6
+ export const CalendarDateSchema = z
7
+ .string()
8
+ .transform(validateCalendarDate);
9
+ /**
10
+ * This function validates if a string is a valid calendar date.
11
+ * Throws an error if the date is invalid.
12
+ * @param date - The date to be validated.
13
+ * @returns The given string as a CalendarDate.
14
+ */
15
+ export function validateCalendarDate(date) {
16
+ const parsedDate = DateTime.fromFormat(date, CALENDAR_DATE_FORMAT);
17
+ if (!parsedDate.isValid)
18
+ throw new Error(`Invalid date format '${date}', expected format: ${CALENDAR_DATE_FORMAT}, explanation: ${parsedDate.invalidExplanation}`);
19
+ return date;
20
+ }
@@ -0,0 +1,3 @@
1
+ export * from './calendar-date.js';
2
+ export * from './operational-date.js';
3
+ export * from './unix-timestamp.js';
@@ -0,0 +1,3 @@
1
+ export * from './calendar-date.js';
2
+ export * from './operational-date.js';
3
+ export * from './unix-timestamp.js';
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ export declare const OPERATIONAL_DATE_FORMAT = "yyyyMMdd";
3
+ export type OperationalDate = string & {
4
+ __brand: 'OperationalDate';
5
+ };
6
+ export declare const OperationalDateSchema: z.ZodEffects<z.ZodString, OperationalDate, string>;
7
+ /**
8
+ * This function validates if a string is a valid operational date.
9
+ * Throws an error if the date is invalid.
10
+ * @param date - The date to be validated.
11
+ * @returns The given string as an OperationalDate.
12
+ */
13
+ export declare function validateOperationalDate(date: string): OperationalDate;
@@ -0,0 +1,20 @@
1
+ /* * */
2
+ import { DateTime } from 'luxon';
3
+ import { z } from 'zod';
4
+ /* * */
5
+ export const OPERATIONAL_DATE_FORMAT = 'yyyyMMdd';
6
+ export const OperationalDateSchema = z
7
+ .string()
8
+ .transform(validateOperationalDate);
9
+ /**
10
+ * This function validates if a string is a valid operational date.
11
+ * Throws an error if the date is invalid.
12
+ * @param date - The date to be validated.
13
+ * @returns The given string as an OperationalDate.
14
+ */
15
+ export function validateOperationalDate(date) {
16
+ const parsedDate = DateTime.fromFormat(date, OPERATIONAL_DATE_FORMAT);
17
+ if (!parsedDate.isValid)
18
+ throw new Error(`Invalid date format '${date}', expected format: ${OPERATIONAL_DATE_FORMAT}, explanation: ${parsedDate.invalidExplanation}`);
19
+ return date;
20
+ }
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * UnixTimestamp, in this context, is a number that represents
4
+ * the number of milliseconds since the Unix epoch (1970-01-01T00:00:00Z).
5
+ */
6
+ export type UnixTimestamp = number & {
7
+ __brand: 'UnixTimestamp';
8
+ };
9
+ export declare const UnixTimestampSchema: z.ZodEffects<z.ZodNumber, UnixTimestamp, number>;
10
+ /**
11
+ * This function validates if a number is a valid Unix Timestamp, in milliseconds.
12
+ * It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in milliseconds.
13
+ * Throws an error if the date is invalid.
14
+ * @param milliseconds - The number to be validated.
15
+ * @returns The given number as a UnixTimestamp.
16
+ */
17
+ export declare function validateUnixTimestamp(milliseconds: number): UnixTimestamp;
@@ -0,0 +1,22 @@
1
+ /* * */
2
+ import { DateTime } from 'luxon';
3
+ import { z } from 'zod';
4
+ export const UnixTimestampSchema = z
5
+ .coerce
6
+ .number()
7
+ .transform(validateUnixTimestamp);
8
+ /**
9
+ * This function validates if a number is a valid Unix Timestamp, in milliseconds.
10
+ * It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in milliseconds.
11
+ * Throws an error if the date is invalid.
12
+ * @param milliseconds - The number to be validated.
13
+ * @returns The given number as a UnixTimestamp.
14
+ */
15
+ export function validateUnixTimestamp(milliseconds) {
16
+ if (milliseconds < 1e10)
17
+ throw new Error(`Invalid value '${milliseconds}', expected a number in milliseconds but received a number smaller than 1e10`);
18
+ const parsedDate = DateTime.fromMillis(milliseconds);
19
+ if (!parsedDate.isValid)
20
+ throw new Error(`Invalid date '${milliseconds}, explanation: ${parsedDate.invalidExplanation}`);
21
+ return parsedDate.toMillis();
22
+ }
@@ -0,0 +1,367 @@
1
+ import { z } from 'zod';
2
+ export declare const CommentTypeSchema: z.ZodEnum<["field_changed", "note", "crud"]>;
3
+ export type CommentType = z.infer<typeof CommentTypeSchema>;
4
+ export declare const CrudCommentSchemaActionSchema: z.ZodEnum<["create", "update", "delete", "archive", "restore"]>;
5
+ export type CrudCommentSchemaAction = z.infer<typeof CrudCommentSchemaActionSchema>;
6
+ export declare const FieldChangeSchema: z.ZodObject<{
7
+ curr_value: z.ZodAny;
8
+ field: z.ZodString;
9
+ prev_value: z.ZodAny;
10
+ }, "strip", z.ZodTypeAny, {
11
+ field: string;
12
+ curr_value?: any;
13
+ prev_value?: any;
14
+ }, {
15
+ field: string;
16
+ curr_value?: any;
17
+ prev_value?: any;
18
+ }>;
19
+ export declare const NoteCommentSchema: z.ZodObject<{
20
+ message: z.ZodString;
21
+ type: z.ZodLiteral<"note">;
22
+ _id: z.ZodOptional<z.ZodString>;
23
+ created_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
24
+ created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
25
+ updated_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
26
+ updated_by: z.ZodOptional<z.ZodString>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ message: string;
29
+ type: "note";
30
+ created_at: number & {
31
+ __brand: "UnixTimestamp";
32
+ };
33
+ created_by: string | null;
34
+ updated_at: number & {
35
+ __brand: "UnixTimestamp";
36
+ };
37
+ _id?: string | undefined;
38
+ updated_by?: string | undefined;
39
+ }, {
40
+ message: string;
41
+ type: "note";
42
+ created_at: number;
43
+ updated_at: number;
44
+ _id?: string | undefined;
45
+ created_by?: string | null | undefined;
46
+ updated_by?: string | undefined;
47
+ }>;
48
+ export declare const FieldChangedCommentSchema: z.ZodObject<{
49
+ type: z.ZodLiteral<"field_changed">;
50
+ _id: z.ZodOptional<z.ZodString>;
51
+ created_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
52
+ created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
53
+ updated_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
54
+ updated_by: z.ZodOptional<z.ZodString>;
55
+ curr_value: z.ZodAny;
56
+ field: z.ZodString;
57
+ prev_value: z.ZodAny;
58
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodObject<{
59
+ changes: z.ZodOptional<z.ZodArray<z.ZodObject<{
60
+ curr_value: z.ZodAny;
61
+ field: z.ZodString;
62
+ prev_value: z.ZodAny;
63
+ }, "strip", z.ZodTypeAny, {
64
+ field: string;
65
+ curr_value?: any;
66
+ prev_value?: any;
67
+ }, {
68
+ field: string;
69
+ curr_value?: any;
70
+ prev_value?: any;
71
+ }>, "many">>;
72
+ }, "strip", z.ZodTypeAny, {
73
+ changes?: {
74
+ field: string;
75
+ curr_value?: any;
76
+ prev_value?: any;
77
+ }[] | undefined;
78
+ }, {
79
+ changes?: {
80
+ field: string;
81
+ curr_value?: any;
82
+ prev_value?: any;
83
+ }[] | undefined;
84
+ }>>>;
85
+ }, "strip", z.ZodTypeAny, {
86
+ type: "field_changed";
87
+ created_at: number & {
88
+ __brand: "UnixTimestamp";
89
+ };
90
+ created_by: string | null;
91
+ updated_at: number & {
92
+ __brand: "UnixTimestamp";
93
+ };
94
+ field: string;
95
+ _id?: string | undefined;
96
+ updated_by?: string | undefined;
97
+ curr_value?: any;
98
+ prev_value?: any;
99
+ metadata?: {
100
+ changes?: {
101
+ field: string;
102
+ curr_value?: any;
103
+ prev_value?: any;
104
+ }[] | undefined;
105
+ } | null | undefined;
106
+ }, {
107
+ type: "field_changed";
108
+ created_at: number;
109
+ updated_at: number;
110
+ field: string;
111
+ _id?: string | undefined;
112
+ created_by?: string | null | undefined;
113
+ updated_by?: string | undefined;
114
+ curr_value?: any;
115
+ prev_value?: any;
116
+ metadata?: {
117
+ changes?: {
118
+ field: string;
119
+ curr_value?: any;
120
+ prev_value?: any;
121
+ }[] | undefined;
122
+ } | null | undefined;
123
+ }>;
124
+ export declare const CrudCommentSchema: z.ZodObject<{
125
+ type: z.ZodLiteral<"crud">;
126
+ _id: z.ZodOptional<z.ZodString>;
127
+ created_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
128
+ created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
129
+ updated_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
130
+ updated_by: z.ZodOptional<z.ZodString>;
131
+ action: z.ZodEnum<["create", "update", "delete", "archive", "restore"]>;
132
+ }, "strip", z.ZodTypeAny, {
133
+ type: "crud";
134
+ created_at: number & {
135
+ __brand: "UnixTimestamp";
136
+ };
137
+ created_by: string | null;
138
+ updated_at: number & {
139
+ __brand: "UnixTimestamp";
140
+ };
141
+ action: "create" | "update" | "delete" | "archive" | "restore";
142
+ _id?: string | undefined;
143
+ updated_by?: string | undefined;
144
+ }, {
145
+ type: "crud";
146
+ created_at: number;
147
+ updated_at: number;
148
+ action: "create" | "update" | "delete" | "archive" | "restore";
149
+ _id?: string | undefined;
150
+ created_by?: string | null | undefined;
151
+ updated_by?: string | undefined;
152
+ }>;
153
+ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
154
+ message: z.ZodString;
155
+ type: z.ZodLiteral<"note">;
156
+ _id: z.ZodOptional<z.ZodString>;
157
+ created_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
158
+ created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
159
+ updated_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
160
+ updated_by: z.ZodOptional<z.ZodString>;
161
+ }, "strip", z.ZodTypeAny, {
162
+ message: string;
163
+ type: "note";
164
+ created_at: number & {
165
+ __brand: "UnixTimestamp";
166
+ };
167
+ created_by: string | null;
168
+ updated_at: number & {
169
+ __brand: "UnixTimestamp";
170
+ };
171
+ _id?: string | undefined;
172
+ updated_by?: string | undefined;
173
+ }, {
174
+ message: string;
175
+ type: "note";
176
+ created_at: number;
177
+ updated_at: number;
178
+ _id?: string | undefined;
179
+ created_by?: string | null | undefined;
180
+ updated_by?: string | undefined;
181
+ }>, z.ZodObject<{
182
+ type: z.ZodLiteral<"field_changed">;
183
+ _id: z.ZodOptional<z.ZodString>;
184
+ created_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
185
+ created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
186
+ updated_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
187
+ updated_by: z.ZodOptional<z.ZodString>;
188
+ curr_value: z.ZodAny;
189
+ field: z.ZodString;
190
+ prev_value: z.ZodAny;
191
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodObject<{
192
+ changes: z.ZodOptional<z.ZodArray<z.ZodObject<{
193
+ curr_value: z.ZodAny;
194
+ field: z.ZodString;
195
+ prev_value: z.ZodAny;
196
+ }, "strip", z.ZodTypeAny, {
197
+ field: string;
198
+ curr_value?: any;
199
+ prev_value?: any;
200
+ }, {
201
+ field: string;
202
+ curr_value?: any;
203
+ prev_value?: any;
204
+ }>, "many">>;
205
+ }, "strip", z.ZodTypeAny, {
206
+ changes?: {
207
+ field: string;
208
+ curr_value?: any;
209
+ prev_value?: any;
210
+ }[] | undefined;
211
+ }, {
212
+ changes?: {
213
+ field: string;
214
+ curr_value?: any;
215
+ prev_value?: any;
216
+ }[] | undefined;
217
+ }>>>;
218
+ }, "strip", z.ZodTypeAny, {
219
+ type: "field_changed";
220
+ created_at: number & {
221
+ __brand: "UnixTimestamp";
222
+ };
223
+ created_by: string | null;
224
+ updated_at: number & {
225
+ __brand: "UnixTimestamp";
226
+ };
227
+ field: string;
228
+ _id?: string | undefined;
229
+ updated_by?: string | undefined;
230
+ curr_value?: any;
231
+ prev_value?: any;
232
+ metadata?: {
233
+ changes?: {
234
+ field: string;
235
+ curr_value?: any;
236
+ prev_value?: any;
237
+ }[] | undefined;
238
+ } | null | undefined;
239
+ }, {
240
+ type: "field_changed";
241
+ created_at: number;
242
+ updated_at: number;
243
+ field: string;
244
+ _id?: string | undefined;
245
+ created_by?: string | null | undefined;
246
+ updated_by?: string | undefined;
247
+ curr_value?: any;
248
+ prev_value?: any;
249
+ metadata?: {
250
+ changes?: {
251
+ field: string;
252
+ curr_value?: any;
253
+ prev_value?: any;
254
+ }[] | undefined;
255
+ } | null | undefined;
256
+ }>, z.ZodObject<{
257
+ type: z.ZodLiteral<"crud">;
258
+ _id: z.ZodOptional<z.ZodString>;
259
+ created_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
260
+ created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
261
+ updated_at: z.ZodEffects<z.ZodNumber, import("../index.js").UnixTimestamp, number>;
262
+ updated_by: z.ZodOptional<z.ZodString>;
263
+ action: z.ZodEnum<["create", "update", "delete", "archive", "restore"]>;
264
+ }, "strip", z.ZodTypeAny, {
265
+ type: "crud";
266
+ created_at: number & {
267
+ __brand: "UnixTimestamp";
268
+ };
269
+ created_by: string | null;
270
+ updated_at: number & {
271
+ __brand: "UnixTimestamp";
272
+ };
273
+ action: "create" | "update" | "delete" | "archive" | "restore";
274
+ _id?: string | undefined;
275
+ updated_by?: string | undefined;
276
+ }, {
277
+ type: "crud";
278
+ created_at: number;
279
+ updated_at: number;
280
+ action: "create" | "update" | "delete" | "archive" | "restore";
281
+ _id?: string | undefined;
282
+ created_by?: string | null | undefined;
283
+ updated_by?: string | undefined;
284
+ }>]>, {
285
+ message: string;
286
+ type: "note";
287
+ created_at: number & {
288
+ __brand: "UnixTimestamp";
289
+ };
290
+ created_by: string | null;
291
+ updated_at: number & {
292
+ __brand: "UnixTimestamp";
293
+ };
294
+ _id?: string | undefined;
295
+ updated_by?: string | undefined;
296
+ } | {
297
+ type: "field_changed";
298
+ created_at: number & {
299
+ __brand: "UnixTimestamp";
300
+ };
301
+ created_by: string | null;
302
+ updated_at: number & {
303
+ __brand: "UnixTimestamp";
304
+ };
305
+ field: string;
306
+ _id?: string | undefined;
307
+ updated_by?: string | undefined;
308
+ curr_value?: any;
309
+ prev_value?: any;
310
+ metadata?: {
311
+ changes?: {
312
+ field: string;
313
+ curr_value?: any;
314
+ prev_value?: any;
315
+ }[] | undefined;
316
+ } | null | undefined;
317
+ } | {
318
+ type: "crud";
319
+ created_at: number & {
320
+ __brand: "UnixTimestamp";
321
+ };
322
+ created_by: string | null;
323
+ updated_at: number & {
324
+ __brand: "UnixTimestamp";
325
+ };
326
+ action: "create" | "update" | "delete" | "archive" | "restore";
327
+ _id?: string | undefined;
328
+ updated_by?: string | undefined;
329
+ }, {
330
+ message: string;
331
+ type: "note";
332
+ created_at: number;
333
+ updated_at: number;
334
+ _id?: string | undefined;
335
+ created_by?: string | null | undefined;
336
+ updated_by?: string | undefined;
337
+ } | {
338
+ type: "field_changed";
339
+ created_at: number;
340
+ updated_at: number;
341
+ field: string;
342
+ _id?: string | undefined;
343
+ created_by?: string | null | undefined;
344
+ updated_by?: string | undefined;
345
+ curr_value?: any;
346
+ prev_value?: any;
347
+ metadata?: {
348
+ changes?: {
349
+ field: string;
350
+ curr_value?: any;
351
+ prev_value?: any;
352
+ }[] | undefined;
353
+ } | null | undefined;
354
+ } | {
355
+ type: "crud";
356
+ created_at: number;
357
+ updated_at: number;
358
+ action: "create" | "update" | "delete" | "archive" | "restore";
359
+ _id?: string | undefined;
360
+ created_by?: string | null | undefined;
361
+ updated_by?: string | undefined;
362
+ }>;
363
+ export type Comment = z.infer<typeof CommentSchema>;
364
+ export type NoteComment = z.infer<typeof NoteCommentSchema>;
365
+ export type CrudComment = z.infer<typeof CrudCommentSchema>;
366
+ export type FieldChangedComment = z.infer<typeof FieldChangedCommentSchema>;
367
+ export type FieldChange = z.infer<typeof FieldChangeSchema>;
@@ -0,0 +1,83 @@
1
+ /* * */
2
+ import { DocumentSchema } from './document.js';
3
+ import { z } from 'zod';
4
+ /* * */
5
+ const COMMENT_TYPE_OPTIONS = ['field_changed', 'note', 'crud'];
6
+ export const CommentTypeSchema = z.enum(COMMENT_TYPE_OPTIONS);
7
+ const CRUD_COMMENT_ACTION_OPTIONS = ['create', 'update', 'delete', 'archive', 'restore'];
8
+ export const CrudCommentSchemaActionSchema = z.enum(CRUD_COMMENT_ACTION_OPTIONS);
9
+ /* * */
10
+ export const FieldChangeSchema = z.object({
11
+ curr_value: z.any(),
12
+ field: z.string(),
13
+ prev_value: z.any(),
14
+ });
15
+ /* * */
16
+ export const NoteCommentSchema = DocumentSchema
17
+ .omit({ is_locked: true })
18
+ .extend({
19
+ message: z.string(),
20
+ type: z.literal(CommentTypeSchema.enum.note),
21
+ })
22
+ .partial({ _id: true });
23
+ export const FieldChangedCommentSchema = DocumentSchema
24
+ .omit({ is_locked: true })
25
+ .extend({
26
+ curr_value: z.any(),
27
+ field: z.string(),
28
+ metadata: z.object({
29
+ changes: z.array(FieldChangeSchema).optional(),
30
+ }).nullish(),
31
+ prev_value: z.any(),
32
+ type: z.literal(CommentTypeSchema.enum.field_changed),
33
+ })
34
+ .partial({ _id: true });
35
+ export const CrudCommentSchema = DocumentSchema
36
+ .omit({ is_locked: true })
37
+ .extend({
38
+ action: CrudCommentSchemaActionSchema,
39
+ type: z.literal(CommentTypeSchema.enum.crud),
40
+ })
41
+ .partial({ _id: true });
42
+ /* * */
43
+ export const CommentSchema = z
44
+ .discriminatedUnion('type', [
45
+ NoteCommentSchema,
46
+ FieldChangedCommentSchema,
47
+ CrudCommentSchema,
48
+ ])
49
+ .superRefine((data, ctx) => {
50
+ // Apply validation after the discriminated union
51
+ if (data.type === 'field_changed') {
52
+ // If field is 'multiple_fields', metadata.changes must exist
53
+ if (data.field === 'multiple_fields') {
54
+ if (!data.metadata?.changes || data.metadata.changes.length === 0) {
55
+ ctx.addIssue({
56
+ code: z.ZodIssueCode.custom,
57
+ message: 'multiple_fields requires metadata.changes array',
58
+ path: ['metadata', 'changes'],
59
+ });
60
+ }
61
+ if (data.curr_value !== null || data.prev_value !== null) {
62
+ ctx.addIssue({
63
+ code: z.ZodIssueCode.custom,
64
+ message: 'multiple_fields must have null curr_value and prev_value',
65
+ path: ['curr_value'],
66
+ });
67
+ }
68
+ }
69
+ else if (data.curr_value === data.prev_value) {
70
+ // If field is NOT 'multiple_fields', curr_value and prev_value must differ
71
+ ctx.addIssue({
72
+ code: z.ZodIssueCode.custom,
73
+ message: 'curr_value and prev_value must differ',
74
+ path: ['curr_value'],
75
+ });
76
+ }
77
+ }
78
+ });
79
+ // export interface FieldChangedComment<T, K extends keyof T> extends Omit<z.infer<typeof FieldChangedCommentSchema>, 'curr_value' | 'field' | 'prev_value'> {
80
+ // curr_value: T[K]
81
+ // field: K
82
+ // prev_value: T[K]
83
+ // }
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ export declare const DocumentSchema: z.ZodObject<{
3
+ _id: z.ZodString;
4
+ created_at: z.ZodEffects<z.ZodNumber, import("../dates/unix-timestamp.js").UnixTimestamp, number>;
5
+ created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
6
+ is_locked: z.ZodDefault<z.ZodBoolean>;
7
+ updated_at: z.ZodEffects<z.ZodNumber, import("../dates/unix-timestamp.js").UnixTimestamp, number>;
8
+ updated_by: z.ZodOptional<z.ZodString>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ _id: string;
11
+ created_at: number & {
12
+ __brand: "UnixTimestamp";
13
+ };
14
+ created_by: string | null;
15
+ is_locked: boolean;
16
+ updated_at: number & {
17
+ __brand: "UnixTimestamp";
18
+ };
19
+ updated_by?: string | undefined;
20
+ }, {
21
+ _id: string;
22
+ created_at: number;
23
+ updated_at: number;
24
+ created_by?: string | null | undefined;
25
+ is_locked?: boolean | undefined;
26
+ updated_by?: string | undefined;
27
+ }>;
@@ -0,0 +1,12 @@
1
+ /* * */
2
+ import { UnixTimestampSchema } from '../dates/unix-timestamp.js';
3
+ import { z } from 'zod';
4
+ /* * */
5
+ export const DocumentSchema = z.object({
6
+ _id: z.string(),
7
+ created_at: UnixTimestampSchema,
8
+ created_by: z.string().nullable().default(null),
9
+ is_locked: z.boolean().default(false),
10
+ updated_at: UnixTimestampSchema,
11
+ updated_by: z.string().optional(),
12
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Allowed app Environment values.
3
+ * This type is used to define the environments in which the application can run.
4
+ * It has a companion function `getCurrentEnvironment` that retrieves the current
5
+ * environment based on the set environment variable.
6
+ * - `prd` is reserved for the live production environment.
7
+ * - `stg` is used for pre-production testing environments.
8
+ * - `dev` is used for local development environments. It uses staging variables.
9
+ */
10
+ export type Environment = 'dev' | 'prd' | 'stg';
11
+ /**
12
+ * Get the current environment from server-side `ENVIRONMENT`
13
+ * or client-side `NEXT_PUBLIC_ENVIRONMENT` variables.
14
+ * @returns The current environment value.
15
+ */
16
+ export declare function getCurrentEnvironment(): Environment;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Get the current environment from server-side `ENVIRONMENT`
3
+ * or client-side `NEXT_PUBLIC_ENVIRONMENT` variables.
4
+ * @returns The current environment value.
5
+ */
6
+ export function getCurrentEnvironment() {
7
+ // Prefer server-side environment variable
8
+ if (process.env.ENVIRONMENT)
9
+ return process.env.ENVIRONMENT;
10
+ // Fallback to client-side environment variable
11
+ if (process.env.NEXT_PUBLIC_ENVIRONMENT)
12
+ return process.env.NEXT_PUBLIC_ENVIRONMENT;
13
+ // Fallback to development
14
+ return 'dev';
15
+ }
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ export declare const PaginationSchema: z.ZodObject<{
3
+ limit: z.ZodDefault<z.ZodNumber>;
4
+ page: z.ZodDefault<z.ZodNumber>;
5
+ }, "strip", z.ZodTypeAny, {
6
+ limit: number;
7
+ page: number;
8
+ }, {
9
+ limit?: number | undefined;
10
+ page?: number | undefined;
11
+ }>;
@@ -0,0 +1,7 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const PaginationSchema = z.object({
5
+ limit: z.coerce.number().min(1).default(100),
6
+ page: z.coerce.number().min(1).default(1),
7
+ });
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod';
2
+ export declare const I18nCodeValues: readonly ["en", "pt"];
3
+ export declare const I18nCodeSchema: z.ZodEnum<["en", "pt"]>;
4
+ export type I18nCode = z.infer<typeof I18nCodeSchema>;
@@ -0,0 +1,9 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const I18nCodeValues = [
5
+ 'en',
6
+ // 'es',
7
+ 'pt',
8
+ ];
9
+ export const I18nCodeSchema = z.enum(I18nCodeValues);