@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.
- package/dist/api/api-response.d.ts +8 -8
- package/dist/api/api-response.js +3 -3
- package/dist/datetime/index.d.ts +3 -1
- package/dist/datetime/index.js +3 -1
- package/dist/datetime/interval.d.ts +4 -4
- package/dist/datetime/interval.js +3 -3
- package/dist/datetime/operational-date-int.d.ts +1 -1
- package/dist/datetime/operational-date-int.js +4 -4
- package/dist/datetime/operational-time.d.ts +24 -0
- package/dist/datetime/operational-time.js +35 -0
- package/dist/datetime/unix-millis.d.ts +43 -0
- package/dist/datetime/{unix-timestamp.js → unix-millis.js} +19 -17
- package/dist/datetime/unix-seconds.d.ts +43 -0
- package/dist/datetime/unix-seconds.js +52 -0
- package/dist/documents/comment.d.ts +30 -30
- package/dist/documents/document.d.ts +4 -4
- package/dist/documents/document.js +3 -3
- package/dist/documents/proposed-change.d.ts +9 -9
- package/dist/numbers/float.d.ts +1 -1
- package/dist/numbers/float.js +2 -2
- package/dist/numbers/integer.d.ts +1 -1
- package/dist/numbers/integer.js +3 -3
- package/dist/numbers/non-negative-float.d.ts +1 -1
- package/dist/numbers/non-negative-float.js +3 -3
- package/dist/numbers/non-negative-integer.d.ts +1 -1
- package/dist/numbers/non-negative-integer.js +3 -4
- package/dist/numbers/percent.d.ts +1 -1
- package/dist/numbers/percent.js +3 -5
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/language-tag.d.ts +8 -0
- package/dist/utils/language-tag.js +9 -0
- package/package.json +1 -1
- package/dist/datetime/unix-timestamp.d.ts +0 -43
- package/dist/utils/i18n-code.d.ts +0 -4
- 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-
|
|
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: "
|
|
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-
|
|
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: "
|
|
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-
|
|
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: "
|
|
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-
|
|
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: "
|
|
69
|
+
__brand: "UnixMilliseconds";
|
|
70
70
|
};
|
|
71
71
|
}, {
|
|
72
72
|
data: null;
|
package/dist/api/api-response.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
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:
|
|
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:
|
|
27
|
+
timestamp: UnixMillisecondsSchema,
|
|
28
28
|
});
|
|
29
29
|
/* * */
|
|
30
30
|
export const ApiResponseSchema = z.discriminatedUnion('status_code', [ApiResponseSuccessSchema, ApiResponseErrorSchema]);
|
package/dist/datetime/index.d.ts
CHANGED
|
@@ -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-
|
|
9
|
+
export * from './unix-millis.js';
|
|
10
|
+
export * from './unix-seconds.js';
|
package/dist/datetime/index.js
CHANGED
|
@@ -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-
|
|
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-
|
|
4
|
-
start: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("./unix-
|
|
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: "
|
|
7
|
+
__brand: "UnixMilliseconds";
|
|
8
8
|
};
|
|
9
9
|
start: number & {
|
|
10
|
-
__brand: "
|
|
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 {
|
|
3
|
+
import { UnixMillisecondsSchema } from './unix-millis.js';
|
|
4
4
|
/* * */
|
|
5
5
|
export const TimeIntervalSchema = z.object({
|
|
6
|
-
end:
|
|
7
|
-
start:
|
|
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
|
-
.
|
|
21
|
-
.
|
|
22
|
-
.
|
|
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
|
|
9
|
-
* // => 1715025600000 as
|
|
8
|
+
* const unixMilliseconds = UnixMillisecondsSchema.parse(1715025600000);
|
|
9
|
+
* // => 1715025600000 as UnixMilliseconds
|
|
10
10
|
*
|
|
11
|
-
* const
|
|
12
|
-
* // => 1715025600000 as
|
|
11
|
+
* const unixMilliseconds = UnixMillisecondsSchema.parse('1715025600000');
|
|
12
|
+
* // => 1715025600000 as UnixMilliseconds
|
|
13
13
|
*
|
|
14
|
-
* const
|
|
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
|
|
18
|
+
export const UnixMillisecondsSchema = z
|
|
19
19
|
.union([z.string(), z.number()])
|
|
20
|
-
.transform(
|
|
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
|
|
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
|
|
31
|
-
* // => 1715025600000 as
|
|
30
|
+
* const unixMilliseconds = validateUnixMilliseconds(1715025600000);
|
|
31
|
+
* // => 1715025600000 as UnixMilliseconds
|
|
32
32
|
*
|
|
33
|
-
* const
|
|
34
|
-
* // => 1715025600000 as
|
|
33
|
+
* const unixMilliseconds = validateUnixMilliseconds('1715025600000');
|
|
34
|
+
* // => 1715025600000 as UnixMilliseconds
|
|
35
35
|
*
|
|
36
|
-
* const
|
|
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
|
|
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
|
|
49
|
-
return
|
|
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").
|
|
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").
|
|
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: "
|
|
31
|
+
__brand: "UnixMilliseconds";
|
|
32
32
|
};
|
|
33
33
|
created_by: string | null;
|
|
34
34
|
updated_at: number & {
|
|
35
|
-
__brand: "
|
|
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").
|
|
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").
|
|
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: "
|
|
88
|
+
__brand: "UnixMilliseconds";
|
|
89
89
|
};
|
|
90
90
|
created_by: string | null;
|
|
91
91
|
updated_at: number & {
|
|
92
|
-
__brand: "
|
|
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").
|
|
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").
|
|
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: "
|
|
135
|
+
__brand: "UnixMilliseconds";
|
|
136
136
|
};
|
|
137
137
|
created_by: string | null;
|
|
138
138
|
updated_at: number & {
|
|
139
|
-
__brand: "
|
|
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").
|
|
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").
|
|
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: "
|
|
165
|
+
__brand: "UnixMilliseconds";
|
|
166
166
|
};
|
|
167
167
|
created_by: string | null;
|
|
168
168
|
updated_at: number & {
|
|
169
|
-
__brand: "
|
|
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").
|
|
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").
|
|
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: "
|
|
221
|
+
__brand: "UnixMilliseconds";
|
|
222
222
|
};
|
|
223
223
|
created_by: string | null;
|
|
224
224
|
updated_at: number & {
|
|
225
|
-
__brand: "
|
|
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").
|
|
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").
|
|
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: "
|
|
267
|
+
__brand: "UnixMilliseconds";
|
|
268
268
|
};
|
|
269
269
|
created_by: string | null;
|
|
270
270
|
updated_at: number & {
|
|
271
|
-
__brand: "
|
|
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: "
|
|
288
|
+
__brand: "UnixMilliseconds";
|
|
289
289
|
};
|
|
290
290
|
created_by: string | null;
|
|
291
291
|
updated_at: number & {
|
|
292
|
-
__brand: "
|
|
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: "
|
|
299
|
+
__brand: "UnixMilliseconds";
|
|
300
300
|
};
|
|
301
301
|
created_by: string | null;
|
|
302
302
|
updated_at: number & {
|
|
303
|
-
__brand: "
|
|
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: "
|
|
320
|
+
__brand: "UnixMilliseconds";
|
|
321
321
|
};
|
|
322
322
|
created_by: string | null;
|
|
323
323
|
updated_at: number & {
|
|
324
|
-
__brand: "
|
|
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-
|
|
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-
|
|
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: "
|
|
12
|
+
__brand: "UnixMilliseconds";
|
|
13
13
|
};
|
|
14
14
|
created_by: string | null;
|
|
15
15
|
is_locked: boolean;
|
|
16
16
|
updated_at: number & {
|
|
17
|
-
__brand: "
|
|
17
|
+
__brand: "UnixMilliseconds";
|
|
18
18
|
};
|
|
19
19
|
updated_by?: string | undefined;
|
|
20
20
|
}, {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import {
|
|
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:
|
|
7
|
+
created_at: UnixMillisecondsSchema,
|
|
8
8
|
created_by: z.string().nullable().default(null),
|
|
9
9
|
is_locked: z.boolean().default(false),
|
|
10
|
-
updated_at:
|
|
10
|
+
updated_at: UnixMillisecondsSchema,
|
|
11
11
|
updated_by: z.string().optional(),
|
|
12
12
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type
|
|
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]>,
|
|
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]>,
|
|
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: "
|
|
23
|
+
__brand: "UnixMilliseconds";
|
|
24
24
|
};
|
|
25
25
|
created_by: string | null;
|
|
26
26
|
is_locked: boolean;
|
|
27
27
|
updated_at: number & {
|
|
28
|
-
__brand: "
|
|
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:
|
|
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:
|
|
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]>,
|
|
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]>,
|
|
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;
|
package/dist/numbers/float.d.ts
CHANGED
package/dist/numbers/float.js
CHANGED
package/dist/numbers/integer.js
CHANGED
|
@@ -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>;
|
package/dist/numbers/percent.js
CHANGED
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -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>;
|
package/package.json
CHANGED
|
@@ -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;
|