@tmlmobilidade/go-types-shared 20260618.2106.1 → 20260620.940.32

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.
@@ -1,3 +1,4 @@
1
1
  export * from './calendar-date.js';
2
+ export * from './operational-date-int.js';
2
3
  export * from './operational-date.js';
3
4
  export * from './unix-timestamp.js';
@@ -1,3 +1,4 @@
1
1
  export * from './calendar-date.js';
2
+ export * from './operational-date-int.js';
2
3
  export * from './operational-date.js';
3
4
  export * from './unix-timestamp.js';
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ export declare const OPERATIONAL_DATE_FORMAT = "yyyyMMdd";
3
+ /**
4
+ * Represents an operational date as an integer in the format 'yyyyMMdd'.
5
+ * @example 20260620 (June 20, 2026 between 04:00 and 03:59 of the following day)
6
+ */
7
+ export type OperationalDateInt = number & {
8
+ __brand: 'OperationalDateInt';
9
+ };
10
+ export declare const OperationalDateIntSchema: z.ZodEffects<z.ZodNumber, OperationalDateInt, number>;
11
+ /**
12
+ * This function validates if a value is a valid operational date.
13
+ * Throws an error if the value is invalid.
14
+ * @param value The value to be validated.
15
+ * @returns The given value as an OperationalDateInt.
16
+ */
17
+ export declare function validateOperationalDateInt(value: number | string): OperationalDateInt;
@@ -0,0 +1,20 @@
1
+ /* * */
2
+ import { DateTime } from 'luxon';
3
+ import { z } from 'zod';
4
+ /* * */
5
+ export const OPERATIONAL_DATE_FORMAT = 'yyyyMMdd';
6
+ export const OperationalDateIntSchema = z
7
+ .number()
8
+ .transform(validateOperationalDateInt);
9
+ /**
10
+ * This function validates if a value is a valid operational date.
11
+ * Throws an error if the value is invalid.
12
+ * @param value The value to be validated.
13
+ * @returns The given value as an OperationalDateInt.
14
+ */
15
+ export function validateOperationalDateInt(value) {
16
+ const parsedDate = DateTime.fromFormat(String(value), OPERATIONAL_DATE_FORMAT);
17
+ if (!parsedDate.isValid)
18
+ throw new Error(`Invalid date format '${value}', expected format: ${OPERATIONAL_DATE_FORMAT}, explanation: ${parsedDate.invalidExplanation}`);
19
+ return Number(value);
20
+ }
@@ -1,13 +1,22 @@
1
1
  import { z } from 'zod';
2
- export declare const OPERATIONAL_DATE_FORMAT = "yyyyMMdd";
2
+ /**
3
+ * Represents an operational date in the format 'yyyyMMdd'.
4
+ * @deprecated Use the OperationalDateInt type instead, for better performance.
5
+ */
3
6
  export type OperationalDate = string & {
4
7
  __brand: 'OperationalDate';
5
8
  };
9
+ /**
10
+ * Represents an operational date as a string in the format 'yyyyMMdd'.
11
+ * @deprecated Use the OperationalDateIntSchema and validateOperationalDateInt function instead, for better performance.
12
+ */
6
13
  export declare const OperationalDateSchema: z.ZodEffects<z.ZodString, OperationalDate, string>;
7
14
  /**
8
- * This function validates if a string is a valid operational date.
15
+ * This function validates if a string is a valid
16
+ * operational date in the format 'yyyyMMdd'.
9
17
  * Throws an error if the date is invalid.
10
- * @param date - The date to be validated.
18
+ * @param date The date to be validated.
11
19
  * @returns The given string as an OperationalDate.
20
+ * @deprecated Use the OperationalDateIntSchema and validateOperationalDateInt function instead, for better performance.
12
21
  */
13
22
  export declare function validateOperationalDate(date: string): OperationalDate;
@@ -1,16 +1,21 @@
1
1
  /* * */
2
+ import { OPERATIONAL_DATE_FORMAT } from './operational-date-int.js';
2
3
  import { DateTime } from 'luxon';
3
4
  import { z } from 'zod';
4
- /* * */
5
- export const OPERATIONAL_DATE_FORMAT = 'yyyyMMdd';
5
+ /**
6
+ * Represents an operational date as a string in the format 'yyyyMMdd'.
7
+ * @deprecated Use the OperationalDateIntSchema and validateOperationalDateInt function instead, for better performance.
8
+ */
6
9
  export const OperationalDateSchema = z
7
10
  .string()
8
11
  .transform(validateOperationalDate);
9
12
  /**
10
- * This function validates if a string is a valid operational date.
13
+ * This function validates if a string is a valid
14
+ * operational date in the format 'yyyyMMdd'.
11
15
  * Throws an error if the date is invalid.
12
- * @param date - The date to be validated.
16
+ * @param date The date to be validated.
13
17
  * @returns The given string as an OperationalDate.
18
+ * @deprecated Use the OperationalDateIntSchema and validateOperationalDateInt function instead, for better performance.
14
19
  */
15
20
  export function validateOperationalDate(date) {
16
21
  const parsedDate = DateTime.fromFormat(date, OPERATIONAL_DATE_FORMAT);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/go-types-shared",
3
- "version": "20260618.2106.1",
3
+ "version": "20260620.940.32",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"