@tmlmobilidade/go-types-shared 20261107.2347.22 → 20261109.1101.19
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 +25 -0
- package/dist/api/api-response.js +11 -0
- package/dist/api/http-status.d.ts +5 -1
- package/dist/api/http-status.js +4 -0
- package/dist/datetime/calendar-date.js +2 -1
- package/dist/datetime/operational-date-int.js +2 -1
- package/dist/datetime/operational-date.js +2 -1
- package/dist/datetime/operational-time.js +2 -1
- package/dist/datetime/unix-millis.js +2 -1
- package/dist/datetime/unix-seconds.js +2 -1
- package/dist/documents/comment.js +4 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/modules/module-id.d.ts +1 -1
- package/dist/modules/module-scope.d.ts +1 -1
- package/dist/modules/module-scope.js +2 -1
- package/dist/utils/hex-color.js +2 -1
- package/package.json +2 -1
|
@@ -13,16 +13,32 @@ export declare const ApiResponseSuccessSchema: z.ZodObject<{
|
|
|
13
13
|
export type ApiResponseSuccess<T> = Omit<z.infer<typeof ApiResponseSuccessSchema>, 'data'> & {
|
|
14
14
|
data: T;
|
|
15
15
|
};
|
|
16
|
+
/** Safe validation details; never contains submitted values or Zod internals. */
|
|
17
|
+
export declare const ApiValidationIssueSchema: z.ZodObject<{
|
|
18
|
+
code: z.ZodString;
|
|
19
|
+
message: z.ZodString;
|
|
20
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export type ApiValidationIssue = z.infer<typeof ApiValidationIssueSchema>;
|
|
16
23
|
export declare const ApiResponseErrorSchema: z.ZodObject<{
|
|
17
24
|
data: z.ZodNull;
|
|
18
25
|
error: z.ZodString;
|
|
26
|
+
issues: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
27
|
+
code: z.ZodString;
|
|
28
|
+
message: z.ZodString;
|
|
29
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
30
|
+
}, z.core.$strip>>>;
|
|
19
31
|
status_code: z.ZodEnum<{
|
|
20
32
|
400: "400";
|
|
21
33
|
401: "401";
|
|
22
34
|
403: "403";
|
|
23
35
|
404: "404";
|
|
36
|
+
405: "405";
|
|
37
|
+
408: "408";
|
|
24
38
|
409: "409";
|
|
39
|
+
413: "413";
|
|
25
40
|
415: "415";
|
|
41
|
+
422: "422";
|
|
26
42
|
429: "429";
|
|
27
43
|
500: "500";
|
|
28
44
|
502: "502";
|
|
@@ -45,13 +61,22 @@ export declare const ApiResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
45
61
|
}, z.core.$strip>, z.ZodObject<{
|
|
46
62
|
data: z.ZodNull;
|
|
47
63
|
error: z.ZodString;
|
|
64
|
+
issues: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
65
|
+
code: z.ZodString;
|
|
66
|
+
message: z.ZodString;
|
|
67
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
68
|
+
}, z.core.$strip>>>;
|
|
48
69
|
status_code: z.ZodEnum<{
|
|
49
70
|
400: "400";
|
|
50
71
|
401: "401";
|
|
51
72
|
403: "403";
|
|
52
73
|
404: "404";
|
|
74
|
+
405: "405";
|
|
75
|
+
408: "408";
|
|
53
76
|
409: "409";
|
|
77
|
+
413: "413";
|
|
54
78
|
415: "415";
|
|
79
|
+
422: "422";
|
|
55
80
|
429: "429";
|
|
56
81
|
500: "500";
|
|
57
82
|
502: "502";
|
package/dist/api/api-response.js
CHANGED
|
@@ -15,16 +15,27 @@ export const ApiResponseSuccessSchema = z.object({
|
|
|
15
15
|
timestamp: UnixMillisecondsSchema,
|
|
16
16
|
});
|
|
17
17
|
/* * */
|
|
18
|
+
/** Safe validation details; never contains submitted values or Zod internals. */
|
|
19
|
+
export const ApiValidationIssueSchema = z.object({
|
|
20
|
+
code: z.string(),
|
|
21
|
+
message: z.string(),
|
|
22
|
+
path: z.array(z.union([z.string(), z.number()])),
|
|
23
|
+
});
|
|
18
24
|
export const ApiResponseErrorSchema = z.object({
|
|
19
25
|
data: z.null(),
|
|
20
26
|
error: z.string(),
|
|
27
|
+
issues: z.array(ApiValidationIssueSchema).optional(),
|
|
21
28
|
status_code: HttpStatusSchema.extract([
|
|
22
29
|
'400', // Bad Request
|
|
23
30
|
'401', // Unauthorized
|
|
24
31
|
'403', // Forbidden
|
|
25
32
|
'404', // Not Found
|
|
33
|
+
'405', // Method Not Allowed
|
|
34
|
+
'408', // Request Timeout
|
|
26
35
|
'409', // Conflict
|
|
36
|
+
'413', // Payload Too Large
|
|
27
37
|
'415', // Unsupported Media Type
|
|
38
|
+
'422', // Unprocessable Content
|
|
28
39
|
'429', // Too Many Requests
|
|
29
40
|
'500', // Internal Server Error
|
|
30
41
|
'502', // Bad Gateway
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const HttpStatusValues: readonly ["200", "201", "204", "400", "401", "403", "404", "409", "415", "429", "500", "502", "503", "504"];
|
|
2
|
+
export declare const HttpStatusValues: readonly ["200", "201", "204", "400", "401", "403", "404", "405", "408", "409", "413", "415", "422", "429", "500", "502", "503", "504"];
|
|
3
3
|
export declare const HttpStatusSchema: z.ZodEnum<{
|
|
4
4
|
200: "200";
|
|
5
5
|
201: "201";
|
|
@@ -8,8 +8,12 @@ export declare const HttpStatusSchema: z.ZodEnum<{
|
|
|
8
8
|
401: "401";
|
|
9
9
|
403: "403";
|
|
10
10
|
404: "404";
|
|
11
|
+
405: "405";
|
|
12
|
+
408: "408";
|
|
11
13
|
409: "409";
|
|
14
|
+
413: "413";
|
|
12
15
|
415: "415";
|
|
16
|
+
422: "422";
|
|
13
17
|
429: "429";
|
|
14
18
|
500: "500";
|
|
15
19
|
502: "502";
|
package/dist/api/http-status.js
CHANGED
|
@@ -9,8 +9,12 @@ export const HttpStatusValues = [
|
|
|
9
9
|
'401', // Unauthorized
|
|
10
10
|
'403', // Forbidden
|
|
11
11
|
'404', // Not Found
|
|
12
|
+
'405', // Method Not Allowed
|
|
13
|
+
'408', // Request Timeout
|
|
12
14
|
'409', // Conflict
|
|
15
|
+
'413', // Payload Too Large
|
|
13
16
|
'415', // Unsupported Media Type
|
|
17
|
+
'422', // Unprocessable Content
|
|
14
18
|
'429', // Too Many Requests
|
|
15
19
|
'500', // Internal Server Error
|
|
16
20
|
'502', // Bad Gateway
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/* * */
|
|
2
|
+
import { validationTransform } from '@tmlmobilidade/go-utils-validation';
|
|
2
3
|
import { DateTime } from 'luxon';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
/* * */
|
|
5
6
|
export const CALENDAR_DATE_FORMAT = 'yyyy-MM-dd';
|
|
6
7
|
export const CalendarDateSchema = z
|
|
7
8
|
.string()
|
|
8
|
-
.transform(validateCalendarDate);
|
|
9
|
+
.transform(validationTransform(validateCalendarDate, 'custom.formats.date', { format: CALENDAR_DATE_FORMAT }));
|
|
9
10
|
/**
|
|
10
11
|
* This function validates if a string is a valid calendar date
|
|
11
12
|
* in the format `yyyy-MM-dd`.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
+
import { validationParams } from '@tmlmobilidade/go-utils-validation';
|
|
2
3
|
import { DateTime } from 'luxon';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { CALENDAR_DATE_FORMAT } from './calendar-date.js';
|
|
@@ -20,5 +21,5 @@ export const OPERATIONAL_DATE_FORMAT = 'yyyyMMdd';
|
|
|
20
21
|
export const OperationalDateIntSchema = z
|
|
21
22
|
.union([z.string(), z.number()])
|
|
22
23
|
.transform(value => String(value).replaceAll('-', ''))
|
|
23
|
-
.refine(value => DateTime.fromFormat(value, OPERATIONAL_DATE_FORMAT).isValid, {
|
|
24
|
+
.refine(value => DateTime.fromFormat(value, OPERATIONAL_DATE_FORMAT).isValid, validationParams('custom.formats.operational_date', { alternative: CALENDAR_DATE_FORMAT, format: OPERATIONAL_DATE_FORMAT }))
|
|
24
25
|
.transform(value => Number(value));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { OPERATIONAL_DATE_FORMAT } from './operational-date-int.js';
|
|
3
|
+
import { validationTransform } from '@tmlmobilidade/go-utils-validation';
|
|
3
4
|
import { DateTime } from 'luxon';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
/**
|
|
@@ -8,7 +9,7 @@ import { z } from 'zod';
|
|
|
8
9
|
*/
|
|
9
10
|
export const OperationalDateSchema = z
|
|
10
11
|
.string()
|
|
11
|
-
.transform(validateOperationalDate);
|
|
12
|
+
.transform(validationTransform(validateOperationalDate, 'custom.formats.date', { format: OPERATIONAL_DATE_FORMAT }));
|
|
12
13
|
/**
|
|
13
14
|
* This function validates if a string is a valid
|
|
14
15
|
* operational date in the format 'yyyyMMdd'.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
+
import { validationTransform } from '@tmlmobilidade/go-utils-validation';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
/* * */
|
|
4
5
|
export const OPERATIONAL_TIME_FORMAT = 'HH:mm:ss';
|
|
@@ -7,7 +8,7 @@ export const OPERATIONAL_TIME_FORMAT = 'HH:mm:ss';
|
|
|
7
8
|
*/
|
|
8
9
|
export const OperationalTimeSchema = z
|
|
9
10
|
.string()
|
|
10
|
-
.transform(validateOperationalTime);
|
|
11
|
+
.transform(validationTransform(validateOperationalTime, 'custom.formats.operational_time', { format: OPERATIONAL_TIME_FORMAT }));
|
|
11
12
|
/**
|
|
12
13
|
* This function validates if a string is a valid
|
|
13
14
|
* Operational time in the format 'HH:mm:ss'.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
+
import { validationTransform } from '@tmlmobilidade/go-utils-validation';
|
|
2
3
|
import { DateTime } from 'luxon';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
/**
|
|
@@ -17,7 +18,7 @@ import { z } from 'zod';
|
|
|
17
18
|
*/
|
|
18
19
|
export const UnixMillisecondsSchema = z
|
|
19
20
|
.union([z.string(), z.number()])
|
|
20
|
-
.transform(validateUnixMilliseconds);
|
|
21
|
+
.transform(validationTransform(validateUnixMilliseconds, 'custom.formats.unix_milliseconds', { minimum: 1e10 }));
|
|
21
22
|
/**
|
|
22
23
|
* This function validates if a number is a valid Unix Timestamp, in milliseconds.
|
|
23
24
|
* It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in milliseconds.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
+
import { validationTransform } from '@tmlmobilidade/go-utils-validation';
|
|
2
3
|
import { DateTime } from 'luxon';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
/**
|
|
@@ -17,7 +18,7 @@ import { z } from 'zod';
|
|
|
17
18
|
*/
|
|
18
19
|
export const UnixSecondsSchema = z
|
|
19
20
|
.union([z.string(), z.number()])
|
|
20
|
-
.transform(validateUnixSeconds);
|
|
21
|
+
.transform(validationTransform(validateUnixSeconds, 'custom.formats.unix_seconds', { minimum: 1e9 }));
|
|
21
22
|
/**
|
|
22
23
|
* This function validates if a number is a valid Unix Seconds, in seconds.
|
|
23
24
|
* It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in seconds.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { BaseDocumentSchema } from './document.js';
|
|
3
|
+
import { validationParams } from '@tmlmobilidade/go-utils-validation';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
/* * */
|
|
5
6
|
const COMMENT_TYPE_OPTIONS = ['field_changed', 'note', 'crud'];
|
|
@@ -54,14 +55,14 @@ export const CommentSchema = z
|
|
|
54
55
|
if (!data.metadata?.changes || data.metadata.changes.length === 0) {
|
|
55
56
|
ctx.addIssue({
|
|
56
57
|
code: 'custom',
|
|
57
|
-
|
|
58
|
+
...validationParams('custom.documents.changes_required'),
|
|
58
59
|
path: ['metadata', 'changes'],
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
if (data.curr_value !== null || data.prev_value !== null) {
|
|
62
63
|
ctx.addIssue({
|
|
63
64
|
code: 'custom',
|
|
64
|
-
|
|
65
|
+
...validationParams('custom.documents.null_values'),
|
|
65
66
|
path: ['curr_value'],
|
|
66
67
|
});
|
|
67
68
|
}
|
|
@@ -70,7 +71,7 @@ export const CommentSchema = z
|
|
|
70
71
|
// If field is NOT 'multiple_fields', curr_value and prev_value must differ
|
|
71
72
|
ctx.addIssue({
|
|
72
73
|
code: 'custom',
|
|
73
|
-
|
|
74
|
+
...validationParams('custom.documents.different_values'),
|
|
74
75
|
path: ['curr_value'],
|
|
75
76
|
});
|
|
76
77
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const ModuleIdValues: readonly ["apex", "core", "dates", "exporter", "hub", "infrastructure", "offer", "operation", "performance", "tracker"];
|
|
3
3
|
export declare const ModuleIdSchema: z.ZodEnum<{
|
|
4
|
+
dates: "dates";
|
|
4
5
|
apex: "apex";
|
|
5
6
|
core: "core";
|
|
6
|
-
dates: "dates";
|
|
7
7
|
exporter: "exporter";
|
|
8
8
|
hub: "hub";
|
|
9
9
|
infrastructure: "infrastructure";
|
|
@@ -3,9 +3,9 @@ export declare const ModuleScopeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
3
3
|
type: z.ZodLiteral<"platform">;
|
|
4
4
|
}, z.core.$strict>, z.ZodObject<{
|
|
5
5
|
module_ids: z.ZodArray<z.ZodEnum<{
|
|
6
|
+
dates: "dates";
|
|
6
7
|
apex: "apex";
|
|
7
8
|
core: "core";
|
|
8
|
-
dates: "dates";
|
|
9
9
|
exporter: "exporter";
|
|
10
10
|
hub: "hub";
|
|
11
11
|
infrastructure: "infrastructure";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { validationParams } from '@tmlmobilidade/go-utils-validation';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { ModuleIdSchema } from './module-id.js';
|
|
3
4
|
/* * */
|
|
4
5
|
export const ModuleScopeSchema = z.discriminatedUnion('type', [
|
|
5
6
|
z.object({ type: z.literal('platform') }).strict(),
|
|
6
7
|
z.object({
|
|
7
|
-
module_ids: z.array(ModuleIdSchema).nonempty().refine(ids => new Set(ids).size === ids.length, '
|
|
8
|
+
module_ids: z.array(ModuleIdSchema).nonempty().refine(ids => new Set(ids).size === ids.length, validationParams('custom.unique.module_ids')),
|
|
8
9
|
type: z.literal('modules'),
|
|
9
10
|
}).strict(),
|
|
10
11
|
]);
|
package/dist/utils/hex-color.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
+
import { validationParams } from '@tmlmobilidade/go-utils-validation';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
/**
|
|
4
5
|
* The schema for a hex color value.
|
|
@@ -15,5 +16,5 @@ export const HexColorSchema = z
|
|
|
15
16
|
.coerce
|
|
16
17
|
.string()
|
|
17
18
|
.transform(value => value.startsWith('#') ? value : `#${value}`)
|
|
18
|
-
.refine(value => /^#[0-9A-Fa-f]{6}$/.test(value), {
|
|
19
|
+
.refine(value => /^#[0-9A-Fa-f]{6}$/.test(value), validationParams('custom.formats.hex_color', { format: '#RRGGBB' }))
|
|
19
20
|
.transform(value => value.toUpperCase());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmlmobilidade/go-types-shared",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20261109.1101.19",
|
|
4
4
|
"author": {
|
|
5
5
|
"email": "iso@tmlmobilidade.pt",
|
|
6
6
|
"name": "TML-ISO"
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"watch": "tsc-watch --onSuccess 'resolve-tspaths'"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@tmlmobilidade/go-utils-validation": "*",
|
|
39
40
|
"luxon": "3.7.2",
|
|
40
41
|
"zod": "4.6.7"
|
|
41
42
|
},
|