@tmlmobilidade/go-types-shared 20260828.1727.14 → 20260829.23.20

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 (36) hide show
  1. package/dist/api/api-response.d.ts +8 -8
  2. package/dist/api/api-response.js +3 -3
  3. package/dist/datetime/index.d.ts +3 -1
  4. package/dist/datetime/index.js +3 -1
  5. package/dist/datetime/interval.d.ts +4 -4
  6. package/dist/datetime/interval.js +3 -3
  7. package/dist/datetime/operational-date-int.d.ts +1 -1
  8. package/dist/datetime/operational-date-int.js +4 -4
  9. package/dist/datetime/operational-time.d.ts +24 -0
  10. package/dist/datetime/operational-time.js +35 -0
  11. package/dist/datetime/unix-millis.d.ts +43 -0
  12. package/dist/datetime/{unix-timestamp.js → unix-millis.js} +19 -17
  13. package/dist/datetime/unix-seconds.d.ts +43 -0
  14. package/dist/datetime/unix-seconds.js +52 -0
  15. package/dist/documents/comment.d.ts +30 -30
  16. package/dist/documents/document.d.ts +4 -4
  17. package/dist/documents/document.js +3 -3
  18. package/dist/documents/proposed-change.d.ts +9 -9
  19. package/dist/numbers/float.d.ts +1 -1
  20. package/dist/numbers/float.js +2 -2
  21. package/dist/numbers/integer.d.ts +1 -1
  22. package/dist/numbers/integer.js +3 -3
  23. package/dist/numbers/non-negative-float.d.ts +1 -1
  24. package/dist/numbers/non-negative-float.js +3 -3
  25. package/dist/numbers/non-negative-integer.d.ts +1 -1
  26. package/dist/numbers/non-negative-integer.js +3 -4
  27. package/dist/numbers/percent.d.ts +1 -1
  28. package/dist/numbers/percent.js +3 -5
  29. package/dist/utils/index.d.ts +1 -1
  30. package/dist/utils/index.js +1 -1
  31. package/dist/utils/language-tag.d.ts +8 -0
  32. package/dist/utils/language-tag.js +9 -0
  33. package/package.json +1 -1
  34. package/dist/datetime/unix-timestamp.d.ts +0 -43
  35. package/dist/utils/i18n-code.d.ts +0 -4
  36. package/dist/utils/i18n-code.js +0 -9
@@ -3,12 +3,12 @@ export declare const ApiResponseSuccessSchema: z.ZodObject<{
3
3
  data: z.ZodUnknown;
4
4
  error: z.ZodNull;
5
5
  status_code: z.ZodEnum<["200", "201", "204"]>;
6
- timestamp: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-timestamp.js").UnixTimestamp, string | number>;
6
+ timestamp: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-millis.js").UnixMilliseconds, string | number>;
7
7
  }, "strip", z.ZodTypeAny, {
8
8
  error: null;
9
9
  status_code: "200" | "201" | "204";
10
10
  timestamp: number & {
11
- __brand: "UnixTimestamp";
11
+ __brand: "UnixMilliseconds";
12
12
  };
13
13
  data?: unknown;
14
14
  }, {
@@ -24,13 +24,13 @@ export declare const ApiResponseErrorSchema: z.ZodObject<{
24
24
  data: z.ZodNull;
25
25
  error: z.ZodString;
26
26
  status_code: z.ZodEnum<["400", "401", "403", "404", "500"]>;
27
- timestamp: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-timestamp.js").UnixTimestamp, string | number>;
27
+ timestamp: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-millis.js").UnixMilliseconds, string | number>;
28
28
  }, "strip", z.ZodTypeAny, {
29
29
  data: null;
30
30
  error: string;
31
31
  status_code: "400" | "401" | "403" | "404" | "500";
32
32
  timestamp: number & {
33
- __brand: "UnixTimestamp";
33
+ __brand: "UnixMilliseconds";
34
34
  };
35
35
  }, {
36
36
  data: null;
@@ -43,12 +43,12 @@ export declare const ApiResponseSchema: z.ZodDiscriminatedUnion<"status_code", [
43
43
  data: z.ZodUnknown;
44
44
  error: z.ZodNull;
45
45
  status_code: z.ZodEnum<["200", "201", "204"]>;
46
- timestamp: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-timestamp.js").UnixTimestamp, string | number>;
46
+ timestamp: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-millis.js").UnixMilliseconds, string | number>;
47
47
  }, "strip", z.ZodTypeAny, {
48
48
  error: null;
49
49
  status_code: "200" | "201" | "204";
50
50
  timestamp: number & {
51
- __brand: "UnixTimestamp";
51
+ __brand: "UnixMilliseconds";
52
52
  };
53
53
  data?: unknown;
54
54
  }, {
@@ -60,13 +60,13 @@ export declare const ApiResponseSchema: z.ZodDiscriminatedUnion<"status_code", [
60
60
  data: z.ZodNull;
61
61
  error: z.ZodString;
62
62
  status_code: z.ZodEnum<["400", "401", "403", "404", "500"]>;
63
- timestamp: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-timestamp.js").UnixTimestamp, string | number>;
63
+ timestamp: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-millis.js").UnixMilliseconds, string | number>;
64
64
  }, "strip", z.ZodTypeAny, {
65
65
  data: null;
66
66
  error: string;
67
67
  status_code: "400" | "401" | "403" | "404" | "500";
68
68
  timestamp: number & {
69
- __brand: "UnixTimestamp";
69
+ __brand: "UnixMilliseconds";
70
70
  };
71
71
  }, {
72
72
  data: null;
@@ -1,6 +1,6 @@
1
1
  /* * */
2
2
  import { z } from 'zod';
3
- import { UnixTimestampSchema } from '../datetime/unix-timestamp.js';
3
+ import { UnixMillisecondsSchema } from '../datetime/unix-millis.js';
4
4
  import { HttpStatusSchema } from './http-status.js';
5
5
  /* * */
6
6
  export const ApiResponseSuccessSchema = z.object({
@@ -11,7 +11,7 @@ export const ApiResponseSuccessSchema = z.object({
11
11
  '201', // Created
12
12
  '204', // No Content
13
13
  ]),
14
- timestamp: UnixTimestampSchema,
14
+ timestamp: UnixMillisecondsSchema,
15
15
  });
16
16
  /* * */
17
17
  export const ApiResponseErrorSchema = z.object({
@@ -24,7 +24,7 @@ export const ApiResponseErrorSchema = z.object({
24
24
  '404', // Not Found
25
25
  '500', // Internal Server Error
26
26
  ]),
27
- timestamp: UnixTimestampSchema,
27
+ timestamp: UnixMillisecondsSchema,
28
28
  });
29
29
  /* * */
30
30
  export const ApiResponseSchema = z.discriminatedUnion('status_code', [ApiResponseSuccessSchema, ApiResponseErrorSchema]);
@@ -3,6 +3,8 @@ export * from './date-format.js';
3
3
  export * from './interval.js';
4
4
  export * from './operational-date-int.js';
5
5
  export * from './operational-date.js';
6
+ export * from './operational-time.js';
6
7
  export * from './time-slot.js';
7
8
  export * from './timezone-identified.js';
8
- export * from './unix-timestamp.js';
9
+ export * from './unix-millis.js';
10
+ export * from './unix-seconds.js';
@@ -3,6 +3,8 @@ export * from './date-format.js';
3
3
  export * from './interval.js';
4
4
  export * from './operational-date-int.js';
5
5
  export * from './operational-date.js';
6
+ export * from './operational-time.js';
6
7
  export * from './time-slot.js';
7
8
  export * from './timezone-identified.js';
8
- export * from './unix-timestamp.js';
9
+ export * from './unix-millis.js';
10
+ export * from './unix-seconds.js';
@@ -1,13 +1,13 @@
1
1
  import { z } from 'zod';
2
2
  export declare const TimeIntervalSchema: z.ZodObject<{
3
- end: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("./unix-timestamp.js").UnixTimestamp, string | number>;
4
- start: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("./unix-timestamp.js").UnixTimestamp, string | number>;
3
+ end: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("./unix-millis.js").UnixMilliseconds, string | number>;
4
+ start: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("./unix-millis.js").UnixMilliseconds, string | number>;
5
5
  }, "strip", z.ZodTypeAny, {
6
6
  end: number & {
7
- __brand: "UnixTimestamp";
7
+ __brand: "UnixMilliseconds";
8
8
  };
9
9
  start: number & {
10
- __brand: "UnixTimestamp";
10
+ __brand: "UnixMilliseconds";
11
11
  };
12
12
  }, {
13
13
  end: string | number;
@@ -1,8 +1,8 @@
1
1
  /* * */
2
2
  import { z } from 'zod';
3
- import { UnixTimestampSchema } from './unix-timestamp.js';
3
+ import { UnixMillisecondsSchema } from './unix-millis.js';
4
4
  /* * */
5
5
  export const TimeIntervalSchema = z.object({
6
- end: UnixTimestampSchema,
7
- start: UnixTimestampSchema,
6
+ end: UnixMillisecondsSchema,
7
+ start: UnixMillisecondsSchema,
8
8
  });
@@ -21,4 +21,4 @@ export type OperationalDateInt = number & {
21
21
  * // => 20260620 as OperationalDateInt
22
22
  * ```
23
23
  */
24
- export declare const OperationalDateIntSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>, OperationalDateInt, string>;
24
+ export declare const OperationalDateIntSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, string, string | number>, string, string | number>, OperationalDateInt, string | number>;
@@ -1,6 +1,7 @@
1
1
  /* * */
2
2
  import { DateTime } from 'luxon';
3
3
  import { z } from 'zod';
4
+ import { CALENDAR_DATE_FORMAT } from './calendar-date.js';
4
5
  /**
5
6
  * The format for an operational date.
6
7
  */
@@ -17,8 +18,7 @@ export const OPERATIONAL_DATE_FORMAT = 'yyyyMMdd';
17
18
  * ```
18
19
  */
19
20
  export const OperationalDateIntSchema = z
20
- .coerce
21
- .string()
22
- .transform(value => value.replaceAll('-', ''))
23
- .refine(value => DateTime.fromFormat(value, OPERATIONAL_DATE_FORMAT).isValid, { message: `Expected a date in the format ${OPERATIONAL_DATE_FORMAT} (or yyyy-MM-dd)` })
21
+ .union([z.string(), z.number()])
22
+ .transform(value => String(value).replaceAll('-', ''))
23
+ .refine(value => DateTime.fromFormat(value, OPERATIONAL_DATE_FORMAT).isValid, { message: `Expected a date in the format ${OPERATIONAL_DATE_FORMAT} or ${CALENDAR_DATE_FORMAT}` })
24
24
  .transform(value => Number(value));
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ export declare const OPERATIONAL_TIME_FORMAT = "HH:mm:ss";
3
+ /**
4
+ * Represents a Operational time in the format 'HH:mm:ss'.
5
+ * Times in this format represent the time of the day
6
+ * in which the given entity (trip, alerts, etc.) is valid.
7
+ * For example, a trip starting at 3:00 AM, with a a GTFS date of `20260619`,
8
+ * would have a start time of `27:00:00`, longer than 24 hours.
9
+ */
10
+ export type OperationalTime = string & {
11
+ __brand: 'OperationalTime';
12
+ };
13
+ /**
14
+ * Represents a Operational time as a string in the format 'HH:mm:ss'.
15
+ */
16
+ export declare const OperationalTimeSchema: z.ZodEffects<z.ZodString, OperationalTime, string>;
17
+ /**
18
+ * This function validates if a string is a valid
19
+ * Operational time in the format 'HH:mm:ss'.
20
+ * Throws an error if the time is invalid.
21
+ * @param time The time to be validated.
22
+ * @returns The given string as a Operational time.
23
+ */
24
+ export declare function validateOperationalTime(value: string): OperationalTime;
@@ -0,0 +1,35 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const OPERATIONAL_TIME_FORMAT = 'HH:mm:ss';
5
+ /**
6
+ * Represents a Operational time as a string in the format 'HH:mm:ss'.
7
+ */
8
+ export const OperationalTimeSchema = z
9
+ .string()
10
+ .transform(validateOperationalTime);
11
+ /**
12
+ * This function validates if a string is a valid
13
+ * Operational time in the format 'HH:mm:ss'.
14
+ * Throws an error if the time is invalid.
15
+ * @param time The time to be validated.
16
+ * @returns The given string as a Operational time.
17
+ */
18
+ export function validateOperationalTime(value) {
19
+ // Check the structure of the time string
20
+ if (!value.match(/^\d{2}:\d{2}:\d{2}$/))
21
+ throw new Error(`Invalid time format '${value}', expected format: ${OPERATIONAL_TIME_FORMAT}`);
22
+ // Parse the time string into hours, minutes, and seconds
23
+ const [hours, minutes, seconds] = value.split(':').map(Number);
24
+ // Check if hours are valid (hours can exceed 24)
25
+ if (hours < 0)
26
+ throw new Error(`Invalid hours in time value '${value}', expected format: ${OPERATIONAL_TIME_FORMAT}. Hours must be greater than or equal to 0.`);
27
+ // Check if minutes are valid
28
+ if (minutes < 0 || minutes > 59)
29
+ throw new Error(`Invalid minutes in time value '${value}', expected format: ${OPERATIONAL_TIME_FORMAT}. Minutes must be between 0 and 59.`);
30
+ // Check if seconds are valid
31
+ if (seconds < 0 || seconds > 59)
32
+ throw new Error(`Invalid seconds in time value '${value}', expected format: ${OPERATIONAL_TIME_FORMAT}. Seconds must be between 0 and 59.`);
33
+ // Return the time as a GTFS time
34
+ return value;
35
+ }
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * UnixMilliseconds, 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 UnixMilliseconds = number & {
7
+ __brand: 'UnixMilliseconds';
8
+ };
9
+ /**
10
+ * The schema for a Unix timestamp value in milliseconds.
11
+ * @example
12
+ * ```ts
13
+ * const unixMilliseconds = UnixMillisecondsSchema.parse(1715025600000);
14
+ * // => 1715025600000 as UnixMilliseconds
15
+ *
16
+ * const unixMilliseconds = UnixMillisecondsSchema.parse('1715025600000');
17
+ * // => 1715025600000 as UnixMilliseconds
18
+ *
19
+ * const unixMilliseconds = UnixMillisecondsSchema.parse('not a number');
20
+ * // => Throws an error: 'Invalid value 'not a number', expected a number or string in milliseconds, but received a NaN'
21
+ * ```
22
+ */
23
+ export declare const UnixMillisecondsSchema: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixMilliseconds, string | number>;
24
+ /**
25
+ * This function validates if a number is a valid Unix Timestamp, in milliseconds.
26
+ * It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in milliseconds.
27
+ * Throws an error if the date is invalid.
28
+ * @param value The number to be validated.
29
+ * @returns The given number as a UnixMilliseconds.
30
+ * @throws An error if the value is invalid.
31
+ * @example
32
+ * ```ts
33
+ * const unixMilliseconds = validateUnixMilliseconds(1715025600000);
34
+ * // => 1715025600000 as UnixMilliseconds
35
+ *
36
+ * const unixMilliseconds = validateUnixMilliseconds('1715025600000');
37
+ * // => 1715025600000 as UnixMilliseconds
38
+ *
39
+ * const unixMilliseconds = validateUnixMilliseconds('not a number');
40
+ * // => Throws an error: 'Invalid value 'not a number', expected a number in milliseconds but received a NaN'
41
+ * ```
42
+ */
43
+ export declare function validateUnixMilliseconds(value: number | string): UnixMilliseconds;
@@ -2,49 +2,51 @@
2
2
  import { DateTime } from 'luxon';
3
3
  import { z } from 'zod';
4
4
  /**
5
- * The schema for a Unix timestamp value.
5
+ * The schema for a Unix timestamp value in milliseconds.
6
6
  * @example
7
7
  * ```ts
8
- * const unixTimestamp = UnixTimestampSchema.parse(1715025600000);
9
- * // => 1715025600000 as UnixTimestamp
8
+ * const unixMilliseconds = UnixMillisecondsSchema.parse(1715025600000);
9
+ * // => 1715025600000 as UnixMilliseconds
10
10
  *
11
- * const unixTimestamp = UnixTimestampSchema.parse('1715025600000');
12
- * // => 1715025600000 as UnixTimestamp
11
+ * const unixMilliseconds = UnixMillisecondsSchema.parse('1715025600000');
12
+ * // => 1715025600000 as UnixMilliseconds
13
13
  *
14
- * const unixTimestamp = UnixTimestampSchema.parse('not a number');
14
+ * const unixMilliseconds = UnixMillisecondsSchema.parse('not a number');
15
15
  * // => Throws an error: 'Invalid value 'not a number', expected a number or string in milliseconds, but received a NaN'
16
16
  * ```
17
17
  */
18
- export const UnixTimestampSchema = z
18
+ export const UnixMillisecondsSchema = z
19
19
  .union([z.string(), z.number()])
20
- .transform(validateUnixTimestamp);
20
+ .transform(validateUnixMilliseconds);
21
21
  /**
22
22
  * This function validates if a number is a valid Unix Timestamp, in milliseconds.
23
23
  * It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in milliseconds.
24
24
  * Throws an error if the date is invalid.
25
25
  * @param value The number to be validated.
26
- * @returns The given number as a UnixTimestamp.
26
+ * @returns The given number as a UnixMilliseconds.
27
27
  * @throws An error if the value is invalid.
28
28
  * @example
29
29
  * ```ts
30
- * const unixTimestamp = validateUnixTimestamp(1715025600000);
31
- * // => 1715025600000 as UnixTimestamp
30
+ * const unixMilliseconds = validateUnixMilliseconds(1715025600000);
31
+ * // => 1715025600000 as UnixMilliseconds
32
32
  *
33
- * const unixTimestamp = validateUnixTimestamp('1715025600000');
34
- * // => 1715025600000 as UnixTimestamp
33
+ * const unixMilliseconds = validateUnixMilliseconds('1715025600000');
34
+ * // => 1715025600000 as UnixMilliseconds
35
35
  *
36
- * const unixTimestamp = validateUnixTimestamp('not a number');
36
+ * const unixMilliseconds = validateUnixMilliseconds('not a number');
37
37
  * // => Throws an error: 'Invalid value 'not a number', expected a number in milliseconds but received a NaN'
38
38
  * ```
39
39
  */
40
- export function validateUnixTimestamp(value) {
40
+ export function validateUnixMilliseconds(value) {
41
41
  const valueAsNumber = Number(value);
42
42
  if (Number.isNaN(valueAsNumber))
43
43
  throw new Error(`Invalid value '${value}', expected a number in milliseconds but received a NaN`);
44
+ if (valueAsNumber <= 0)
45
+ throw new Error(`Invalid value '${value}', expected a number in milliseconds but received a number less than or equal to 0`);
44
46
  if (valueAsNumber < 1e10)
45
47
  throw new Error(`Invalid value '${value}', expected a number in milliseconds but received a number smaller than 1e10`);
46
48
  const parsedDate = DateTime.fromMillis(valueAsNumber);
47
49
  if (!parsedDate.isValid)
48
- throw new Error(`Invalid UnixTimestamp value '${value}', explanation: ${parsedDate.invalidExplanation}`);
49
- return parsedDate.toMillis();
50
+ throw new Error(`Invalid UnixMilliseconds value '${value}', explanation: ${parsedDate.invalidExplanation}`);
51
+ return valueAsNumber;
50
52
  }
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * UnixSeconds, in this context, is a number that represents
4
+ * the number of seconds since the Unix epoch (1970-01-01T00:00:00Z).
5
+ */
6
+ export type UnixSeconds = number & {
7
+ __brand: 'UnixSeconds';
8
+ };
9
+ /**
10
+ * The schema for a Unix timestamp value in seconds.
11
+ * @example
12
+ * ```ts
13
+ * const unixSeconds = UnixSecondsSchema.parse(1715025600);
14
+ * // => 1715025600 as UnixSeconds
15
+ *
16
+ * const unixSeconds = UnixSecondsSchema.parse('1715025600');
17
+ * // => 1715025600 as UnixSeconds
18
+ *
19
+ * const unixSeconds = UnixSecondsSchema.parse('not a number');
20
+ * // => Throws an error: 'Invalid value 'not a number', expected a number or string in seconds, but received a NaN'
21
+ * ```
22
+ */
23
+ export declare const UnixSecondsSchema: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixSeconds, string | number>;
24
+ /**
25
+ * This function validates if a number is a valid Unix Seconds, in seconds.
26
+ * It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in seconds.
27
+ * Throws an error if the date is invalid.
28
+ * @param value The number to be validated.
29
+ * @returns The given number as a UnixSeconds.
30
+ * @throws An error if the value is invalid.
31
+ * @example
32
+ * ```ts
33
+ * const unixSeconds = validateUnixSeconds(1715025600);
34
+ * // => 1715025600 as UnixSeconds
35
+ *
36
+ * const unixSeconds = validateUnixSeconds('1715025600');
37
+ * // => 1715025600 as UnixSeconds
38
+ *
39
+ * const unixSeconds = validateUnixSeconds('not a number');
40
+ * // => Throws an error: 'Invalid value 'not a number', expected a number in seconds but received a NaN'
41
+ * ```
42
+ */
43
+ export declare function validateUnixSeconds(value: number | string): UnixSeconds;
@@ -0,0 +1,52 @@
1
+ /* * */
2
+ import { DateTime } from 'luxon';
3
+ import { z } from 'zod';
4
+ /**
5
+ * The schema for a Unix timestamp value in seconds.
6
+ * @example
7
+ * ```ts
8
+ * const unixSeconds = UnixSecondsSchema.parse(1715025600);
9
+ * // => 1715025600 as UnixSeconds
10
+ *
11
+ * const unixSeconds = UnixSecondsSchema.parse('1715025600');
12
+ * // => 1715025600 as UnixSeconds
13
+ *
14
+ * const unixSeconds = UnixSecondsSchema.parse('not a number');
15
+ * // => Throws an error: 'Invalid value 'not a number', expected a number or string in seconds, but received a NaN'
16
+ * ```
17
+ */
18
+ export const UnixSecondsSchema = z
19
+ .union([z.string(), z.number()])
20
+ .transform(validateUnixSeconds);
21
+ /**
22
+ * This function validates if a number is a valid Unix Seconds, in seconds.
23
+ * It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in seconds.
24
+ * Throws an error if the date is invalid.
25
+ * @param value The number to be validated.
26
+ * @returns The given number as a UnixSeconds.
27
+ * @throws An error if the value is invalid.
28
+ * @example
29
+ * ```ts
30
+ * const unixSeconds = validateUnixSeconds(1715025600);
31
+ * // => 1715025600 as UnixSeconds
32
+ *
33
+ * const unixSeconds = validateUnixSeconds('1715025600');
34
+ * // => 1715025600 as UnixSeconds
35
+ *
36
+ * const unixSeconds = validateUnixSeconds('not a number');
37
+ * // => Throws an error: 'Invalid value 'not a number', expected a number in seconds but received a NaN'
38
+ * ```
39
+ */
40
+ export function validateUnixSeconds(value) {
41
+ const valueAsNumber = Number(value);
42
+ if (Number.isNaN(valueAsNumber))
43
+ throw new Error(`Invalid value '${value}', expected a number in seconds but received a NaN`);
44
+ if (valueAsNumber <= 0)
45
+ throw new Error(`Invalid value '${value}', expected a number in seconds but received a number less than or equal to 0`);
46
+ if (valueAsNumber < 1e9)
47
+ throw new Error(`Invalid value '${value}', expected a number in seconds but received a number smaller than 1e9`);
48
+ const parsedDate = DateTime.fromSeconds(valueAsNumber);
49
+ if (!parsedDate.isValid)
50
+ throw new Error(`Invalid UnixSeconds value '${value}', explanation: ${parsedDate.invalidExplanation}`);
51
+ return valueAsNumber;
52
+ }
@@ -20,19 +20,19 @@ export declare const NoteCommentSchema: z.ZodObject<{
20
20
  message: z.ZodString;
21
21
  type: z.ZodLiteral<"note">;
22
22
  _id: z.ZodOptional<z.ZodString>;
23
- created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
23
+ created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
24
24
  created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
25
- updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
25
+ updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
26
26
  updated_by: z.ZodOptional<z.ZodString>;
27
27
  }, "strip", z.ZodTypeAny, {
28
28
  message: string;
29
29
  type: "note";
30
30
  created_at: number & {
31
- __brand: "UnixTimestamp";
31
+ __brand: "UnixMilliseconds";
32
32
  };
33
33
  created_by: string | null;
34
34
  updated_at: number & {
35
- __brand: "UnixTimestamp";
35
+ __brand: "UnixMilliseconds";
36
36
  };
37
37
  _id?: string | undefined;
38
38
  updated_by?: string | undefined;
@@ -48,9 +48,9 @@ export declare const NoteCommentSchema: z.ZodObject<{
48
48
  export declare const FieldChangedCommentSchema: z.ZodObject<{
49
49
  type: z.ZodLiteral<"field_changed">;
50
50
  _id: z.ZodOptional<z.ZodString>;
51
- created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
51
+ created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
52
52
  created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
53
- updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
53
+ updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
54
54
  updated_by: z.ZodOptional<z.ZodString>;
55
55
  curr_value: z.ZodAny;
56
56
  field: z.ZodString;
@@ -85,11 +85,11 @@ export declare const FieldChangedCommentSchema: z.ZodObject<{
85
85
  }, "strip", z.ZodTypeAny, {
86
86
  type: "field_changed";
87
87
  created_at: number & {
88
- __brand: "UnixTimestamp";
88
+ __brand: "UnixMilliseconds";
89
89
  };
90
90
  created_by: string | null;
91
91
  updated_at: number & {
92
- __brand: "UnixTimestamp";
92
+ __brand: "UnixMilliseconds";
93
93
  };
94
94
  field: string;
95
95
  _id?: string | undefined;
@@ -124,19 +124,19 @@ export declare const FieldChangedCommentSchema: z.ZodObject<{
124
124
  export declare const CrudCommentSchema: z.ZodObject<{
125
125
  type: z.ZodLiteral<"crud">;
126
126
  _id: z.ZodOptional<z.ZodString>;
127
- created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
127
+ created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
128
128
  created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
129
- updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
129
+ updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
130
130
  updated_by: z.ZodOptional<z.ZodString>;
131
131
  action: z.ZodEnum<["create", "update", "delete", "archive", "restore"]>;
132
132
  }, "strip", z.ZodTypeAny, {
133
133
  type: "crud";
134
134
  created_at: number & {
135
- __brand: "UnixTimestamp";
135
+ __brand: "UnixMilliseconds";
136
136
  };
137
137
  created_by: string | null;
138
138
  updated_at: number & {
139
- __brand: "UnixTimestamp";
139
+ __brand: "UnixMilliseconds";
140
140
  };
141
141
  action: "create" | "update" | "delete" | "archive" | "restore";
142
142
  _id?: string | undefined;
@@ -154,19 +154,19 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
154
154
  message: z.ZodString;
155
155
  type: z.ZodLiteral<"note">;
156
156
  _id: z.ZodOptional<z.ZodString>;
157
- created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
157
+ created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
158
158
  created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
159
- updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
159
+ updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
160
160
  updated_by: z.ZodOptional<z.ZodString>;
161
161
  }, "strip", z.ZodTypeAny, {
162
162
  message: string;
163
163
  type: "note";
164
164
  created_at: number & {
165
- __brand: "UnixTimestamp";
165
+ __brand: "UnixMilliseconds";
166
166
  };
167
167
  created_by: string | null;
168
168
  updated_at: number & {
169
- __brand: "UnixTimestamp";
169
+ __brand: "UnixMilliseconds";
170
170
  };
171
171
  _id?: string | undefined;
172
172
  updated_by?: string | undefined;
@@ -181,9 +181,9 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
181
181
  }>, z.ZodObject<{
182
182
  type: z.ZodLiteral<"field_changed">;
183
183
  _id: z.ZodOptional<z.ZodString>;
184
- created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
184
+ created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
185
185
  created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
186
- updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
186
+ updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
187
187
  updated_by: z.ZodOptional<z.ZodString>;
188
188
  curr_value: z.ZodAny;
189
189
  field: z.ZodString;
@@ -218,11 +218,11 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
218
218
  }, "strip", z.ZodTypeAny, {
219
219
  type: "field_changed";
220
220
  created_at: number & {
221
- __brand: "UnixTimestamp";
221
+ __brand: "UnixMilliseconds";
222
222
  };
223
223
  created_by: string | null;
224
224
  updated_at: number & {
225
- __brand: "UnixTimestamp";
225
+ __brand: "UnixMilliseconds";
226
226
  };
227
227
  field: string;
228
228
  _id?: string | undefined;
@@ -256,19 +256,19 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
256
256
  }>, z.ZodObject<{
257
257
  type: z.ZodLiteral<"crud">;
258
258
  _id: z.ZodOptional<z.ZodString>;
259
- created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
259
+ created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
260
260
  created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
261
- updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
261
+ updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixMilliseconds, string | number>;
262
262
  updated_by: z.ZodOptional<z.ZodString>;
263
263
  action: z.ZodEnum<["create", "update", "delete", "archive", "restore"]>;
264
264
  }, "strip", z.ZodTypeAny, {
265
265
  type: "crud";
266
266
  created_at: number & {
267
- __brand: "UnixTimestamp";
267
+ __brand: "UnixMilliseconds";
268
268
  };
269
269
  created_by: string | null;
270
270
  updated_at: number & {
271
- __brand: "UnixTimestamp";
271
+ __brand: "UnixMilliseconds";
272
272
  };
273
273
  action: "create" | "update" | "delete" | "archive" | "restore";
274
274
  _id?: string | undefined;
@@ -285,22 +285,22 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
285
285
  message: string;
286
286
  type: "note";
287
287
  created_at: number & {
288
- __brand: "UnixTimestamp";
288
+ __brand: "UnixMilliseconds";
289
289
  };
290
290
  created_by: string | null;
291
291
  updated_at: number & {
292
- __brand: "UnixTimestamp";
292
+ __brand: "UnixMilliseconds";
293
293
  };
294
294
  _id?: string | undefined;
295
295
  updated_by?: string | undefined;
296
296
  } | {
297
297
  type: "field_changed";
298
298
  created_at: number & {
299
- __brand: "UnixTimestamp";
299
+ __brand: "UnixMilliseconds";
300
300
  };
301
301
  created_by: string | null;
302
302
  updated_at: number & {
303
- __brand: "UnixTimestamp";
303
+ __brand: "UnixMilliseconds";
304
304
  };
305
305
  field: string;
306
306
  _id?: string | undefined;
@@ -317,11 +317,11 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
317
317
  } | {
318
318
  type: "crud";
319
319
  created_at: number & {
320
- __brand: "UnixTimestamp";
320
+ __brand: "UnixMilliseconds";
321
321
  };
322
322
  created_by: string | null;
323
323
  updated_at: number & {
324
- __brand: "UnixTimestamp";
324
+ __brand: "UnixMilliseconds";
325
325
  };
326
326
  action: "create" | "update" | "delete" | "archive" | "restore";
327
327
  _id?: string | undefined;
@@ -1,20 +1,20 @@
1
1
  import { z } from 'zod';
2
2
  export declare const BaseDocumentSchema: z.ZodObject<{
3
3
  _id: z.ZodString;
4
- created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-timestamp.js").UnixTimestamp, string | number>;
4
+ created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-millis.js").UnixMilliseconds, string | number>;
5
5
  created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
6
6
  is_locked: z.ZodDefault<z.ZodBoolean>;
7
- updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-timestamp.js").UnixTimestamp, string | number>;
7
+ updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../datetime/unix-millis.js").UnixMilliseconds, string | number>;
8
8
  updated_by: z.ZodOptional<z.ZodString>;
9
9
  }, "strip", z.ZodTypeAny, {
10
10
  _id: string;
11
11
  created_at: number & {
12
- __brand: "UnixTimestamp";
12
+ __brand: "UnixMilliseconds";
13
13
  };
14
14
  created_by: string | null;
15
15
  is_locked: boolean;
16
16
  updated_at: number & {
17
- __brand: "UnixTimestamp";
17
+ __brand: "UnixMilliseconds";
18
18
  };
19
19
  updated_by?: string | undefined;
20
20
  }, {
@@ -1,12 +1,12 @@
1
1
  /* * */
2
- import { UnixTimestampSchema } from '../datetime/unix-timestamp.js';
2
+ import { UnixMillisecondsSchema } from '../datetime/unix-millis.js';
3
3
  import { z } from 'zod';
4
4
  /* * */
5
5
  export const BaseDocumentSchema = z.object({
6
6
  _id: z.string(),
7
- created_at: UnixTimestampSchema,
7
+ created_at: UnixMillisecondsSchema,
8
8
  created_by: z.string().nullable().default(null),
9
9
  is_locked: z.boolean().default(false),
10
- updated_at: UnixTimestampSchema,
10
+ updated_at: UnixMillisecondsSchema,
11
11
  updated_by: z.string().optional(),
12
12
  });
@@ -1,14 +1,14 @@
1
- import { type UnixTimestamp } from '../datetime/unix-timestamp.js';
1
+ import { type UnixMilliseconds } from '../datetime/unix-millis.js';
2
2
  import { type ApprovalStatus } from '../status/approval.js';
3
3
  import { z } from 'zod';
4
4
  export declare const ScopeSchema: z.ZodEnum<["stop", "lines"]>;
5
5
  export type Scope = z.infer<typeof ScopeSchema>;
6
6
  export declare const ProposedChangeSchema: z.ZodObject<{
7
7
  _id: z.ZodString;
8
- created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixTimestamp, string | number>;
8
+ created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixMilliseconds, string | number>;
9
9
  created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
10
10
  is_locked: z.ZodDefault<z.ZodBoolean>;
11
- updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixTimestamp, string | number>;
11
+ updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixMilliseconds, string | number>;
12
12
  updated_by: z.ZodOptional<z.ZodString>;
13
13
  } & {
14
14
  curr_value: z.ZodAny;
@@ -20,12 +20,12 @@ export declare const ProposedChangeSchema: z.ZodObject<{
20
20
  status: "pending" | "approved" | "rejected" | "none";
21
21
  _id: string;
22
22
  created_at: number & {
23
- __brand: "UnixTimestamp";
23
+ __brand: "UnixMilliseconds";
24
24
  };
25
25
  created_by: string | null;
26
26
  is_locked: boolean;
27
27
  updated_at: number & {
28
- __brand: "UnixTimestamp";
28
+ __brand: "UnixMilliseconds";
29
29
  };
30
30
  field: string;
31
31
  related_id: string;
@@ -48,23 +48,23 @@ export declare const ProposedChangeSchema: z.ZodObject<{
48
48
  export type ProposedChange<T> = {
49
49
  [P in keyof T]: {
50
50
  _id: string;
51
- created_at: UnixTimestamp;
51
+ created_at: UnixMilliseconds;
52
52
  created_by: string;
53
53
  curr_value: T[P];
54
54
  field: P;
55
55
  related_id: string;
56
56
  scope: Scope;
57
57
  status: ApprovalStatus;
58
- updated_at: UnixTimestamp;
58
+ updated_at: UnixMilliseconds;
59
59
  updated_by: string;
60
60
  };
61
61
  }[keyof T];
62
62
  export declare const CreateProposedChangeSchema: z.ZodObject<Omit<{
63
63
  _id: z.ZodString;
64
- created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixTimestamp, string | number>;
64
+ created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixMilliseconds, string | number>;
65
65
  created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
66
66
  is_locked: z.ZodDefault<z.ZodBoolean>;
67
- updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixTimestamp, string | number>;
67
+ updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixMilliseconds, string | number>;
68
68
  updated_by: z.ZodOptional<z.ZodString>;
69
69
  } & {
70
70
  curr_value: z.ZodAny;
@@ -12,4 +12,4 @@ import { z } from 'zod';
12
12
  * // => 1
13
13
  * ```
14
14
  */
15
- export declare const FloatSchema: z.ZodNumber;
15
+ export declare const FloatSchema: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>;
@@ -14,5 +14,5 @@ import { z } from 'zod';
14
14
  * ```
15
15
  */
16
16
  export const FloatSchema = z
17
- .coerce
18
- .number();
17
+ .union([z.string(), z.number()])
18
+ .transform(value => Number(value));
@@ -12,4 +12,4 @@ import { z } from 'zod';
12
12
  * // => 1
13
13
  * ```
14
14
  */
15
- export declare const IntegerSchema: z.ZodNumber;
15
+ export declare const IntegerSchema: z.ZodPipeline<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>, z.ZodNumber>;
@@ -14,6 +14,6 @@ import { z } from 'zod';
14
14
  * ```
15
15
  */
16
16
  export const IntegerSchema = z
17
- .coerce
18
- .number()
19
- .int();
17
+ .union([z.string(), z.number()])
18
+ .transform(value => Number(value))
19
+ .pipe(z.number().int());
@@ -14,4 +14,4 @@ import { z } from 'zod';
14
14
  * // => 0
15
15
  * ```
16
16
  */
17
- export declare const NonNegativeFloatSchema: z.ZodNumber;
17
+ export declare const NonNegativeFloatSchema: z.ZodPipeline<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>, z.ZodNumber>;
@@ -16,6 +16,6 @@ import { z } from 'zod';
16
16
  * ```
17
17
  */
18
18
  export const NonNegativeFloatSchema = z
19
- .coerce
20
- .number()
21
- .nonnegative();
19
+ .union([z.string(), z.number()])
20
+ .transform(value => Number(value))
21
+ .pipe(z.number().nonnegative());
@@ -14,4 +14,4 @@ import { z } from 'zod';
14
14
  * // => 0
15
15
  * ```
16
16
  */
17
- export declare const NonNegativeIntegerSchema: z.ZodNumber;
17
+ export declare const NonNegativeIntegerSchema: z.ZodPipeline<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>, z.ZodNumber>;
@@ -16,7 +16,6 @@ import { z } from 'zod';
16
16
  * ```
17
17
  */
18
18
  export const NonNegativeIntegerSchema = z
19
- .coerce
20
- .number()
21
- .int()
22
- .nonnegative();
19
+ .union([z.string(), z.number()])
20
+ .transform(value => Number(value))
21
+ .pipe(z.number().int().nonnegative());
@@ -16,4 +16,4 @@ import { z } from 'zod';
16
16
  * // => throws an error
17
17
  * ```
18
18
  */
19
- export declare const PercentSchema: z.ZodNumber;
19
+ export declare const PercentSchema: z.ZodPipeline<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>, z.ZodNumber>;
@@ -18,8 +18,6 @@ import { z } from 'zod';
18
18
  * ```
19
19
  */
20
20
  export const PercentSchema = z
21
- .coerce
22
- .number()
23
- .int()
24
- .min(0)
25
- .max(100);
21
+ .union([z.string(), z.number()])
22
+ .transform(value => Number(value))
23
+ .pipe(z.number().int().min(0).max(100));
@@ -1,3 +1,3 @@
1
1
  export * from './environment.js';
2
2
  export * from './hex-color.js';
3
- export * from './i18n-code.js';
3
+ export * from './language-tag.js';
@@ -1,3 +1,3 @@
1
1
  export * from './environment.js';
2
2
  export * from './hex-color.js';
3
- export * from './i18n-code.js';
3
+ export * from './language-tag.js';
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ export declare const LanguageTagValues: readonly ["pt", "es", "en"];
3
+ export declare const LanguageTagSchema: z.ZodEnum<["pt", "es", "en"]>;
4
+ /**
5
+ * A language tag as defined by the IANA language subtag registry.
6
+ * @see https://www.w3.org/International/articles/language-tags
7
+ */
8
+ export type LanguageTag = z.infer<typeof LanguageTagSchema>;
@@ -0,0 +1,9 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const LanguageTagValues = [
5
+ 'pt',
6
+ 'es',
7
+ 'en',
8
+ ];
9
+ export const LanguageTagSchema = z.enum(LanguageTagValues);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/go-types-shared",
3
- "version": "20260828.1727.14",
3
+ "version": "20260829.23.20",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"
@@ -1,43 +0,0 @@
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
- /**
10
- * The schema for a Unix timestamp value.
11
- * @example
12
- * ```ts
13
- * const unixTimestamp = UnixTimestampSchema.parse(1715025600000);
14
- * // => 1715025600000 as UnixTimestamp
15
- *
16
- * const unixTimestamp = UnixTimestampSchema.parse('1715025600000');
17
- * // => 1715025600000 as UnixTimestamp
18
- *
19
- * const unixTimestamp = UnixTimestampSchema.parse('not a number');
20
- * // => Throws an error: 'Invalid value 'not a number', expected a number or string in milliseconds, but received a NaN'
21
- * ```
22
- */
23
- export declare const UnixTimestampSchema: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixTimestamp, string | number>;
24
- /**
25
- * This function validates if a number is a valid Unix Timestamp, in milliseconds.
26
- * It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in milliseconds.
27
- * Throws an error if the date is invalid.
28
- * @param value The number to be validated.
29
- * @returns The given number as a UnixTimestamp.
30
- * @throws An error if the value is invalid.
31
- * @example
32
- * ```ts
33
- * const unixTimestamp = validateUnixTimestamp(1715025600000);
34
- * // => 1715025600000 as UnixTimestamp
35
- *
36
- * const unixTimestamp = validateUnixTimestamp('1715025600000');
37
- * // => 1715025600000 as UnixTimestamp
38
- *
39
- * const unixTimestamp = validateUnixTimestamp('not a number');
40
- * // => Throws an error: 'Invalid value 'not a number', expected a number in milliseconds but received a NaN'
41
- * ```
42
- */
43
- export declare function validateUnixTimestamp(value: number | string): UnixTimestamp;
@@ -1,4 +0,0 @@
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>;
@@ -1,9 +0,0 @@
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);