@tmlmobilidade/types 20260605.142.19 → 20260605.149.34

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.
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ export declare const CALENDAR_DATE_FORMAT = "yyyy-MM-dd";
3
+ export type CalendarDate = string & {
4
+ __brand: 'CalendarDate';
5
+ };
6
+ export declare const CalendarDateSchema: z.ZodEffects<z.ZodString, CalendarDate, string>;
7
+ /**
8
+ * This function validates if a string is a valid calendar date.
9
+ * Throws an error if the date is invalid.
10
+ * @param date - The date to be validated.
11
+ * @returns The given string as a CalendarDate.
12
+ */
13
+ export declare function validateCalendarDate(date: string): CalendarDate;
@@ -0,0 +1,20 @@
1
+ /* * */
2
+ import { DateTime } from 'luxon';
3
+ import { z } from 'zod';
4
+ /* * */
5
+ export const CALENDAR_DATE_FORMAT = 'yyyy-MM-dd';
6
+ export const CalendarDateSchema = z
7
+ .string()
8
+ .transform(validateCalendarDate);
9
+ /**
10
+ * This function validates if a string is a valid calendar date.
11
+ * Throws an error if the date is invalid.
12
+ * @param date - The date to be validated.
13
+ * @returns The given string as a CalendarDate.
14
+ */
15
+ export function validateCalendarDate(date) {
16
+ const parsedDate = DateTime.fromFormat(date, CALENDAR_DATE_FORMAT);
17
+ if (!parsedDate.isValid)
18
+ throw new Error(`Invalid date format '${date}', expected format: ${CALENDAR_DATE_FORMAT}, explanation: ${parsedDate.invalidExplanation}`);
19
+ return date;
20
+ }
@@ -1,3 +1,4 @@
1
+ export * from './calendar-date.js';
1
2
  export * from './comment.js';
2
3
  export * from './document.js';
3
4
  export * from './environment.js';
@@ -1,3 +1,4 @@
1
+ export * from './calendar-date.js';
1
2
  export * from './comment.js';
2
3
  export * from './document.js';
3
4
  export * from './environment.js';
@@ -2,12 +2,12 @@ import { z } from 'zod';
2
2
  export declare const HubVehiclePositionSchema: z.ZodObject<{
3
3
  _id: z.ZodString;
4
4
  agency_id: z.ZodString;
5
- calendar_date: z.ZodEffects<z.ZodString, import("../../../index.js").OperationalDate, string>;
6
- created_at: z.ZodEffects<z.ZodNumber, import("../../../index.js").UnixTimestamp, number>;
5
+ calendar_date: z.ZodEffects<z.ZodString, import("../../../_common/index.js").CalendarDate, string>;
6
+ created_at: z.ZodEffects<z.ZodNumber, import("../../../_common/unix-timestamp.js").UnixTimestamp, number>;
7
7
  geohash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
- latitude: z.ZodEffects<z.ZodNumber, number, number>;
9
- longitude: z.ZodEffects<z.ZodNumber, number, number>;
10
- received_at: z.ZodEffects<z.ZodNumber, import("../../../index.js").UnixTimestamp, number>;
8
+ latitude: z.ZodEffects<z.ZodEffects<z.ZodNumber, string, number>, number, number>;
9
+ longitude: z.ZodEffects<z.ZodEffects<z.ZodNumber, string, number>, number, number>;
10
+ received_at: z.ZodEffects<z.ZodNumber, import("../../../_common/unix-timestamp.js").UnixTimestamp, number>;
11
11
  trip_id: z.ZodString;
12
12
  vehicle_id: z.ZodString;
13
13
  bearing: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
@@ -32,7 +32,7 @@ export declare const HubVehiclePositionSchema: z.ZodObject<{
32
32
  speed: number | null;
33
33
  current_status: "INCOMING_AT" | "STOPPED_AT" | "IN_TRANSIT_TO" | null;
34
34
  calendar_date: string & {
35
- __brand: "OperationalDate";
35
+ __brand: "CalendarDate";
36
36
  };
37
37
  geohash?: string | null | undefined;
38
38
  }, {
@@ -1,6 +1,6 @@
1
1
  /* * */
2
+ import { CalendarDateSchema } from '../../../_common/index.js';
2
3
  import { UnixTimestampSchema } from '../../../_common/unix-timestamp.js';
3
- import { OperationalDateSchema } from '../../../index.js';
4
4
  import { z } from 'zod';
5
5
  /* * */
6
6
  export const HubVehiclePositionSchema = z.object({
@@ -8,17 +8,19 @@ export const HubVehiclePositionSchema = z.object({
8
8
  // Required Fields
9
9
  _id: z.string(),
10
10
  agency_id: z.string(),
11
- calendar_date: OperationalDateSchema,
11
+ calendar_date: CalendarDateSchema,
12
12
  created_at: UnixTimestampSchema,
13
13
  geohash: z.string().nullish(),
14
14
  latitude: z.number()
15
15
  .min(-90)
16
16
  .max(90)
17
- .refine(value => value.toFixed(6) === value.toString()),
17
+ .transform(value => value.toFixed(6))
18
+ .transform(value => parseFloat(value)),
18
19
  longitude: z.number()
19
20
  .min(-180)
20
21
  .max(180)
21
- .refine(value => value.toFixed(6) === value.toString()),
22
+ .transform(value => value.toFixed(6))
23
+ .transform(value => parseFloat(value)),
22
24
  received_at: UnixTimestampSchema,
23
25
  trip_id: z.string(),
24
26
  vehicle_id: z.string(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/types",
3
- "version": "20260605.142.19",
3
+ "version": "20260605.149.34",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"