@tmlmobilidade/go-types-shared 20260722.1043.2 → 20260723.1350.16
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/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/conditions/exactly-one.d.ts +21 -0
- package/dist/conditions/index.d.ts +5 -0
- package/dist/conditions/index.js +5 -0
- package/dist/conditions/none-or-exactly-one.d.ts +21 -0
- package/dist/conditions/none-or-exactly-one.js +1 -0
- package/dist/conditions/one-or-more.d.ts +15 -0
- package/dist/conditions/one-or-more.js +1 -0
- package/dist/conditions/one-or-the-other.d.ts +18 -0
- package/dist/conditions/one-or-the-other.js +1 -0
- package/dist/conditions/optional-if.d.ts +23 -0
- package/dist/conditions/optional-if.js +1 -0
- package/dist/dates/operational-date-int.d.ts +30 -1
- package/dist/dates/operational-date-int.js +32 -3
- package/dist/dates/unix-timestamp.d.ts +29 -3
- package/dist/dates/unix-timestamp.js +36 -8
- package/dist/documents/comment.d.ts +30 -30
- package/dist/documents/document.d.ts +4 -4
- package/dist/documents/index.d.ts +3 -0
- package/dist/documents/index.js +3 -0
- package/dist/documents/proposed-change.d.ts +120 -0
- package/dist/documents/proposed-change.js +18 -0
- package/dist/geo/index.d.ts +2 -0
- package/dist/geo/index.js +2 -0
- package/dist/geo/latitude.d.ts +28 -0
- package/dist/geo/latitude.js +32 -0
- package/dist/geo/longitude.d.ts +28 -0
- package/dist/geo/longitude.js +32 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.js +5 -7
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/package.json +1 -1
- package/dist/position.d.ts +0 -160
- package/dist/position.js +0 -41
- package/dist/utility.d.ts +0 -108
- /package/dist/{fastify.d.ts → api/pagination.d.ts} +0 -0
- /package/dist/{fastify.js → api/pagination.js} +0 -0
- /package/dist/{utility.js → conditions/exactly-one.js} +0 -0
- /package/dist/{environment.d.ts → utils/environment.d.ts} +0 -0
- /package/dist/{environment.js → utils/environment.js} +0 -0
- /package/dist/{i18n-code.d.ts → utils/i18n-code.d.ts} +0 -0
- /package/dist/{i18n-code.js → utils/i18n-code.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pagination.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pagination.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type that represents exactly one key-value pair in the object T.
|
|
3
|
+
* @template T The type of the object.
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
type Action = ExactlyOne<{
|
|
7
|
+
create: { name: string };
|
|
8
|
+
update: { id: string; name?: string };
|
|
9
|
+
delete: { id: string };
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
const x: Action = { create: { name: "New" } }; // ✅
|
|
13
|
+
const y: Action = { update: { id: "123" } }; // ✅
|
|
14
|
+
const z: Action = { create: { name: "X" }, delete: { id: "1" } }; // ❌
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type ExactlyOne<T> = {
|
|
18
|
+
[K in keyof T]: Partial<Record<Exclude<keyof T, K>, never>> & {
|
|
19
|
+
[P in K]: T[P];
|
|
20
|
+
};
|
|
21
|
+
}[keyof T];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type that represents either none or exactly one key-value pair in the object T.
|
|
3
|
+
* @template T The type of the object.
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* type Filters = { name: string; age: number; email: string };
|
|
7
|
+
* type FilterChoice = NoneOrExactlyOne<Filters>;
|
|
8
|
+
*
|
|
9
|
+
* const a: FilterChoice = {}; // ✅ none
|
|
10
|
+
* const b: FilterChoice = { name: "Alice" }; // ✅ exactly one
|
|
11
|
+
* const c: FilterChoice = { age: 30 }; // ✅ exactly one
|
|
12
|
+
* const d: FilterChoice = { name: "Alice", age: 30 }; // ❌ error
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type NoneOrExactlyOne<T> = {
|
|
16
|
+
[K in keyof T]: Partial<Record<Exclude<keyof T, K>, never>> & {
|
|
17
|
+
[P in K]: T[P];
|
|
18
|
+
};
|
|
19
|
+
}[keyof T] | {
|
|
20
|
+
[K in keyof T]?: never;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type that represents either a single instance of type T or an array of type T.
|
|
3
|
+
* @template T The type of the element(s).
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* function processItems<T>(items: OneOrMore<T>) {
|
|
7
|
+
* const arr = Array.isArray(items) ? items : [items];
|
|
8
|
+
* console.log(arr);
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* processItems("apple"); // ["apple"]
|
|
12
|
+
* processItems(["a", "b"]); // ["a", "b"]
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type OneOrMore<T> = T | T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type that represents either A or B, but not both.
|
|
3
|
+
* @template A The first type.
|
|
4
|
+
* @template B The second type.
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* type Credentials = OneOrTheOther<{ email: string }, { username: string }>;
|
|
8
|
+
*
|
|
9
|
+
* const a: Credentials = { email: "a@b.com" }; // ✅
|
|
10
|
+
* const b: Credentials = { username: "user1" }; // ✅
|
|
11
|
+
* const c: Credentials = { email: "a@b.com", username: "user1" }; // ❌
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type OneOrTheOther<A, B> = (A & {
|
|
15
|
+
[K in keyof B]?: never;
|
|
16
|
+
}) | (B & {
|
|
17
|
+
[K in keyof A]?: never;
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes keys in `TFields` required when `TCondition` is absent,
|
|
3
|
+
* and optional when `TCondition` is present.
|
|
4
|
+
* @template T The base object type.
|
|
5
|
+
* @template TCondition The key that triggers optionality when present.
|
|
6
|
+
* @template TFields The keys that become optional when `TCondition` is present.
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* type Lookup = OptionalIf<
|
|
10
|
+
* { from: string; localField?: string; foreignField?: string; pipeline?: any[] },
|
|
11
|
+
* 'pipeline',
|
|
12
|
+
* 'localField' | 'foreignField'
|
|
13
|
+
* >;
|
|
14
|
+
*
|
|
15
|
+
* const a: Lookup = { from: "c", localField: "x", foreignField: "y" }; // ✅
|
|
16
|
+
* const b: Lookup = { from: "c", pipeline: [] }; // ✅
|
|
17
|
+
* const c: Lookup = { from: "c", pipeline: [], localField: "x" }; // ✅ (optional)
|
|
18
|
+
* const d: Lookup = { from: "c" }; // ❌ (localField/foreignField required when no pipeline)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type OptionalIf<T extends object, TCondition extends keyof T, TFields extends keyof T> = (Omit<T, TCondition | TFields> & Partial<Pick<T, TFields>> & Required<Pick<T, TCondition>>) | (Omit<T, TFields> & Required<Pick<T, TFields>> & {
|
|
22
|
+
[K in TCondition]?: never;
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The format for an operational date.
|
|
4
|
+
*/
|
|
2
5
|
export declare const OPERATIONAL_DATE_FORMAT = "yyyyMMdd";
|
|
3
6
|
/**
|
|
4
7
|
* Represents an operational date as an integer in the format 'yyyyMMdd'.
|
|
@@ -7,11 +10,37 @@ export declare const OPERATIONAL_DATE_FORMAT = "yyyyMMdd";
|
|
|
7
10
|
export type OperationalDateInt = number & {
|
|
8
11
|
__brand: 'OperationalDateInt';
|
|
9
12
|
};
|
|
10
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The schema for an operational date value.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const operationalDateInt = OperationalDateIntSchema.parse(20260620);
|
|
18
|
+
* // => 20260620 as OperationalDateInt
|
|
19
|
+
*
|
|
20
|
+
* const operationalDateInt = OperationalDateIntSchema.parse('20260620');
|
|
21
|
+
* // => 20260620 as OperationalDateInt
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const OperationalDateIntSchema: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, OperationalDateInt, string | number>;
|
|
11
25
|
/**
|
|
12
26
|
* This function validates if a value is a valid operational date.
|
|
13
27
|
* Throws an error if the value is invalid.
|
|
14
28
|
* @param value The value to be validated.
|
|
15
29
|
* @returns The given value as an OperationalDateInt.
|
|
30
|
+
* @throws An error if the value is invalid.
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const operationalDateInt = validateOperationalDateInt(20260620);
|
|
34
|
+
* // => 20260620 as OperationalDateInt
|
|
35
|
+
*
|
|
36
|
+
* const operationalDateInt = validateOperationalDateInt('20260620');
|
|
37
|
+
* // => 20260620 as OperationalDateInt
|
|
38
|
+
*
|
|
39
|
+
* const operationalDateInt = validateOperationalDateInt('2026-06-20');
|
|
40
|
+
* // => 20260620 as OperationalDateInt
|
|
41
|
+
*
|
|
42
|
+
* const operationalDateInt = validateOperationalDateInt('not a number');
|
|
43
|
+
* // => Throws an error: 'Invalid value 'not a number', expected a number or string in format 'yyyyMMdd' or a string in format 'yyyy-MM-dd', but received a NaN'
|
|
44
|
+
* ```
|
|
16
45
|
*/
|
|
17
46
|
export declare function validateOperationalDateInt(value: number | string): OperationalDateInt;
|
|
@@ -1,20 +1,49 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { DateTime } from 'luxon';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The format for an operational date.
|
|
6
|
+
*/
|
|
5
7
|
export const OPERATIONAL_DATE_FORMAT = 'yyyyMMdd';
|
|
8
|
+
/**
|
|
9
|
+
* The schema for an operational date value.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const operationalDateInt = OperationalDateIntSchema.parse(20260620);
|
|
13
|
+
* // => 20260620 as OperationalDateInt
|
|
14
|
+
*
|
|
15
|
+
* const operationalDateInt = OperationalDateIntSchema.parse('20260620');
|
|
16
|
+
* // => 20260620 as OperationalDateInt
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
6
19
|
export const OperationalDateIntSchema = z
|
|
7
|
-
.number()
|
|
20
|
+
.union([z.string(), z.number()])
|
|
8
21
|
.transform(validateOperationalDateInt);
|
|
9
22
|
/**
|
|
10
23
|
* This function validates if a value is a valid operational date.
|
|
11
24
|
* Throws an error if the value is invalid.
|
|
12
25
|
* @param value The value to be validated.
|
|
13
26
|
* @returns The given value as an OperationalDateInt.
|
|
27
|
+
* @throws An error if the value is invalid.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const operationalDateInt = validateOperationalDateInt(20260620);
|
|
31
|
+
* // => 20260620 as OperationalDateInt
|
|
32
|
+
*
|
|
33
|
+
* const operationalDateInt = validateOperationalDateInt('20260620');
|
|
34
|
+
* // => 20260620 as OperationalDateInt
|
|
35
|
+
*
|
|
36
|
+
* const operationalDateInt = validateOperationalDateInt('2026-06-20');
|
|
37
|
+
* // => 20260620 as OperationalDateInt
|
|
38
|
+
*
|
|
39
|
+
* const operationalDateInt = validateOperationalDateInt('not a number');
|
|
40
|
+
* // => Throws an error: 'Invalid value 'not a number', expected a number or string in format 'yyyyMMdd' or a string in format 'yyyy-MM-dd', but received a NaN'
|
|
41
|
+
* ```
|
|
14
42
|
*/
|
|
15
43
|
export function validateOperationalDateInt(value) {
|
|
44
|
+
const valueAsString = String(value).replaceAll('-', '');
|
|
16
45
|
const parsedDate = DateTime.fromFormat(String(value), OPERATIONAL_DATE_FORMAT);
|
|
17
46
|
if (!parsedDate.isValid)
|
|
18
47
|
throw new Error(`Invalid date format '${value}', expected format: ${OPERATIONAL_DATE_FORMAT}, explanation: ${parsedDate.invalidExplanation}`);
|
|
19
|
-
return Number(
|
|
48
|
+
return Number(valueAsString);
|
|
20
49
|
}
|
|
@@ -6,12 +6,38 @@ import { z } from 'zod';
|
|
|
6
6
|
export type UnixTimestamp = number & {
|
|
7
7
|
__brand: 'UnixTimestamp';
|
|
8
8
|
};
|
|
9
|
-
|
|
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>;
|
|
10
24
|
/**
|
|
11
25
|
* This function validates if a number is a valid Unix Timestamp, in milliseconds.
|
|
12
26
|
* It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in milliseconds.
|
|
13
27
|
* Throws an error if the date is invalid.
|
|
14
|
-
* @param
|
|
28
|
+
* @param value The number to be validated.
|
|
15
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
|
+
* ```
|
|
16
42
|
*/
|
|
17
|
-
export declare function validateUnixTimestamp(
|
|
43
|
+
export declare function validateUnixTimestamp(value: number | string): UnixTimestamp;
|
|
@@ -1,22 +1,50 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { DateTime } from 'luxon';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* The schema for a Unix timestamp value.
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const unixTimestamp = UnixTimestampSchema.parse(1715025600000);
|
|
9
|
+
* // => 1715025600000 as UnixTimestamp
|
|
10
|
+
*
|
|
11
|
+
* const unixTimestamp = UnixTimestampSchema.parse('1715025600000');
|
|
12
|
+
* // => 1715025600000 as UnixTimestamp
|
|
13
|
+
*
|
|
14
|
+
* const unixTimestamp = UnixTimestampSchema.parse('not a number');
|
|
15
|
+
* // => Throws an error: 'Invalid value 'not a number', expected a number or string in milliseconds, but received a NaN'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
4
18
|
export const UnixTimestampSchema = z
|
|
5
|
-
.
|
|
6
|
-
.number()
|
|
19
|
+
.union([z.string(), z.number()])
|
|
7
20
|
.transform(validateUnixTimestamp);
|
|
8
21
|
/**
|
|
9
22
|
* This function validates if a number is a valid Unix Timestamp, in milliseconds.
|
|
10
23
|
* It is assumed the number will always be greater than 10^10 (1e10) to ensure it is in milliseconds.
|
|
11
24
|
* Throws an error if the date is invalid.
|
|
12
|
-
* @param
|
|
25
|
+
* @param value The number to be validated.
|
|
13
26
|
* @returns The given number as a UnixTimestamp.
|
|
27
|
+
* @throws An error if the value is invalid.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const unixTimestamp = validateUnixTimestamp(1715025600000);
|
|
31
|
+
* // => 1715025600000 as UnixTimestamp
|
|
32
|
+
*
|
|
33
|
+
* const unixTimestamp = validateUnixTimestamp('1715025600000');
|
|
34
|
+
* // => 1715025600000 as UnixTimestamp
|
|
35
|
+
*
|
|
36
|
+
* const unixTimestamp = validateUnixTimestamp('not a number');
|
|
37
|
+
* // => Throws an error: 'Invalid value 'not a number', expected a number in milliseconds but received a NaN'
|
|
38
|
+
* ```
|
|
14
39
|
*/
|
|
15
|
-
export function validateUnixTimestamp(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
40
|
+
export function validateUnixTimestamp(value) {
|
|
41
|
+
const valueAsNumber = Number(value);
|
|
42
|
+
if (Number.isNaN(valueAsNumber))
|
|
43
|
+
throw new Error(`Invalid value '${value}', expected a number in milliseconds but received a NaN`);
|
|
44
|
+
if (valueAsNumber < 1e10)
|
|
45
|
+
throw new Error(`Invalid value '${value}', expected a number in milliseconds but received a number smaller than 1e10`);
|
|
46
|
+
const parsedDate = DateTime.fromMillis(valueAsNumber);
|
|
19
47
|
if (!parsedDate.isValid)
|
|
20
|
-
throw new Error(`Invalid
|
|
48
|
+
throw new Error(`Invalid UnixTimestamp value '${value}', explanation: ${parsedDate.invalidExplanation}`);
|
|
21
49
|
return parsedDate.toMillis();
|
|
22
50
|
}
|
|
@@ -20,9 +20,9 @@ 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.
|
|
23
|
+
created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
24
24
|
created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
25
|
-
updated_at: z.ZodEffects<z.
|
|
25
|
+
updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
26
26
|
updated_by: z.ZodOptional<z.ZodString>;
|
|
27
27
|
}, "strip", z.ZodTypeAny, {
|
|
28
28
|
message: string;
|
|
@@ -39,8 +39,8 @@ export declare const NoteCommentSchema: z.ZodObject<{
|
|
|
39
39
|
}, {
|
|
40
40
|
message: string;
|
|
41
41
|
type: "note";
|
|
42
|
-
created_at: number;
|
|
43
|
-
updated_at: number;
|
|
42
|
+
created_at: string | number;
|
|
43
|
+
updated_at: string | number;
|
|
44
44
|
_id?: string | undefined;
|
|
45
45
|
created_by?: string | null | undefined;
|
|
46
46
|
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.
|
|
51
|
+
created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
52
52
|
created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
53
|
-
updated_at: z.ZodEffects<z.
|
|
53
|
+
updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
54
54
|
updated_by: z.ZodOptional<z.ZodString>;
|
|
55
55
|
curr_value: z.ZodAny;
|
|
56
56
|
field: z.ZodString;
|
|
@@ -105,8 +105,8 @@ export declare const FieldChangedCommentSchema: z.ZodObject<{
|
|
|
105
105
|
} | null | undefined;
|
|
106
106
|
}, {
|
|
107
107
|
type: "field_changed";
|
|
108
|
-
created_at: number;
|
|
109
|
-
updated_at: number;
|
|
108
|
+
created_at: string | number;
|
|
109
|
+
updated_at: string | number;
|
|
110
110
|
field: string;
|
|
111
111
|
_id?: string | undefined;
|
|
112
112
|
created_by?: string | null | undefined;
|
|
@@ -124,9 +124,9 @@ 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.
|
|
127
|
+
created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
128
128
|
created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
129
|
-
updated_at: z.ZodEffects<z.
|
|
129
|
+
updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, 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, {
|
|
@@ -143,8 +143,8 @@ export declare const CrudCommentSchema: z.ZodObject<{
|
|
|
143
143
|
updated_by?: string | undefined;
|
|
144
144
|
}, {
|
|
145
145
|
type: "crud";
|
|
146
|
-
created_at: number;
|
|
147
|
-
updated_at: number;
|
|
146
|
+
created_at: string | number;
|
|
147
|
+
updated_at: string | number;
|
|
148
148
|
action: "create" | "update" | "delete" | "archive" | "restore";
|
|
149
149
|
_id?: string | undefined;
|
|
150
150
|
created_by?: string | null | undefined;
|
|
@@ -154,9 +154,9 @@ 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.
|
|
157
|
+
created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
158
158
|
created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
159
|
-
updated_at: z.ZodEffects<z.
|
|
159
|
+
updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
160
160
|
updated_by: z.ZodOptional<z.ZodString>;
|
|
161
161
|
}, "strip", z.ZodTypeAny, {
|
|
162
162
|
message: string;
|
|
@@ -173,17 +173,17 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
|
|
|
173
173
|
}, {
|
|
174
174
|
message: string;
|
|
175
175
|
type: "note";
|
|
176
|
-
created_at: number;
|
|
177
|
-
updated_at: number;
|
|
176
|
+
created_at: string | number;
|
|
177
|
+
updated_at: string | number;
|
|
178
178
|
_id?: string | undefined;
|
|
179
179
|
created_by?: string | null | undefined;
|
|
180
180
|
updated_by?: string | undefined;
|
|
181
181
|
}>, z.ZodObject<{
|
|
182
182
|
type: z.ZodLiteral<"field_changed">;
|
|
183
183
|
_id: z.ZodOptional<z.ZodString>;
|
|
184
|
-
created_at: z.ZodEffects<z.
|
|
184
|
+
created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
185
185
|
created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
186
|
-
updated_at: z.ZodEffects<z.
|
|
186
|
+
updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
187
187
|
updated_by: z.ZodOptional<z.ZodString>;
|
|
188
188
|
curr_value: z.ZodAny;
|
|
189
189
|
field: z.ZodString;
|
|
@@ -238,8 +238,8 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
|
|
|
238
238
|
} | null | undefined;
|
|
239
239
|
}, {
|
|
240
240
|
type: "field_changed";
|
|
241
|
-
created_at: number;
|
|
242
|
-
updated_at: number;
|
|
241
|
+
created_at: string | number;
|
|
242
|
+
updated_at: string | number;
|
|
243
243
|
field: string;
|
|
244
244
|
_id?: string | undefined;
|
|
245
245
|
created_by?: string | null | undefined;
|
|
@@ -256,9 +256,9 @@ 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.
|
|
259
|
+
created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, string | number>;
|
|
260
260
|
created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
261
|
-
updated_at: z.ZodEffects<z.
|
|
261
|
+
updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../index.js").UnixTimestamp, 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, {
|
|
@@ -275,8 +275,8 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
|
|
|
275
275
|
updated_by?: string | undefined;
|
|
276
276
|
}, {
|
|
277
277
|
type: "crud";
|
|
278
|
-
created_at: number;
|
|
279
|
-
updated_at: number;
|
|
278
|
+
created_at: string | number;
|
|
279
|
+
updated_at: string | number;
|
|
280
280
|
action: "create" | "update" | "delete" | "archive" | "restore";
|
|
281
281
|
_id?: string | undefined;
|
|
282
282
|
created_by?: string | null | undefined;
|
|
@@ -329,15 +329,15 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
|
|
|
329
329
|
}, {
|
|
330
330
|
message: string;
|
|
331
331
|
type: "note";
|
|
332
|
-
created_at: number;
|
|
333
|
-
updated_at: number;
|
|
332
|
+
created_at: string | number;
|
|
333
|
+
updated_at: string | number;
|
|
334
334
|
_id?: string | undefined;
|
|
335
335
|
created_by?: string | null | undefined;
|
|
336
336
|
updated_by?: string | undefined;
|
|
337
337
|
} | {
|
|
338
338
|
type: "field_changed";
|
|
339
|
-
created_at: number;
|
|
340
|
-
updated_at: number;
|
|
339
|
+
created_at: string | number;
|
|
340
|
+
updated_at: string | number;
|
|
341
341
|
field: string;
|
|
342
342
|
_id?: string | undefined;
|
|
343
343
|
created_by?: string | null | undefined;
|
|
@@ -353,8 +353,8 @@ export declare const CommentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type",
|
|
|
353
353
|
} | null | undefined;
|
|
354
354
|
} | {
|
|
355
355
|
type: "crud";
|
|
356
|
-
created_at: number;
|
|
357
|
-
updated_at: number;
|
|
356
|
+
created_at: string | number;
|
|
357
|
+
updated_at: string | number;
|
|
358
358
|
action: "create" | "update" | "delete" | "archive" | "restore";
|
|
359
359
|
_id?: string | undefined;
|
|
360
360
|
created_by?: string | null | undefined;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const DocumentSchema: z.ZodObject<{
|
|
3
3
|
_id: z.ZodString;
|
|
4
|
-
created_at: z.ZodEffects<z.
|
|
4
|
+
created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../dates/unix-timestamp.js").UnixTimestamp, 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.
|
|
7
|
+
updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, import("../dates/unix-timestamp.js").UnixTimestamp, string | number>;
|
|
8
8
|
updated_by: z.ZodOptional<z.ZodString>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
10
|
_id: string;
|
|
@@ -19,8 +19,8 @@ export declare const DocumentSchema: z.ZodObject<{
|
|
|
19
19
|
updated_by?: string | undefined;
|
|
20
20
|
}, {
|
|
21
21
|
_id: string;
|
|
22
|
-
created_at: number;
|
|
23
|
-
updated_at: number;
|
|
22
|
+
created_at: string | number;
|
|
23
|
+
updated_at: string | number;
|
|
24
24
|
created_by?: string | null | undefined;
|
|
25
25
|
is_locked?: boolean | undefined;
|
|
26
26
|
updated_by?: string | undefined;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type UnixTimestamp } from '../dates/unix-timestamp.js';
|
|
2
|
+
import { type ApprovalStatus } from '../status/approval.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export declare const ScopeSchema: z.ZodEnum<["stop", "lines"]>;
|
|
5
|
+
export type Scope = z.infer<typeof ScopeSchema>;
|
|
6
|
+
export declare const ProposedChangeSchema: z.ZodObject<{
|
|
7
|
+
_id: z.ZodString;
|
|
8
|
+
created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixTimestamp, string | number>;
|
|
9
|
+
created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
10
|
+
is_locked: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
+
updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixTimestamp, string | number>;
|
|
12
|
+
updated_by: z.ZodOptional<z.ZodString>;
|
|
13
|
+
} & {
|
|
14
|
+
curr_value: z.ZodAny;
|
|
15
|
+
field: z.ZodString;
|
|
16
|
+
related_id: z.ZodString;
|
|
17
|
+
scope: z.ZodEnum<["stop", "lines"]>;
|
|
18
|
+
status: z.ZodEnum<["pending", "approved", "rejected", "none"]>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
status: "pending" | "approved" | "rejected" | "none";
|
|
21
|
+
_id: string;
|
|
22
|
+
created_at: number & {
|
|
23
|
+
__brand: "UnixTimestamp";
|
|
24
|
+
};
|
|
25
|
+
created_by: string | null;
|
|
26
|
+
is_locked: boolean;
|
|
27
|
+
updated_at: number & {
|
|
28
|
+
__brand: "UnixTimestamp";
|
|
29
|
+
};
|
|
30
|
+
field: string;
|
|
31
|
+
related_id: string;
|
|
32
|
+
scope: "stop" | "lines";
|
|
33
|
+
updated_by?: string | undefined;
|
|
34
|
+
curr_value?: any;
|
|
35
|
+
}, {
|
|
36
|
+
status: "pending" | "approved" | "rejected" | "none";
|
|
37
|
+
_id: string;
|
|
38
|
+
created_at: string | number;
|
|
39
|
+
updated_at: string | number;
|
|
40
|
+
field: string;
|
|
41
|
+
related_id: string;
|
|
42
|
+
scope: "stop" | "lines";
|
|
43
|
+
created_by?: string | null | undefined;
|
|
44
|
+
is_locked?: boolean | undefined;
|
|
45
|
+
updated_by?: string | undefined;
|
|
46
|
+
curr_value?: any;
|
|
47
|
+
}>;
|
|
48
|
+
export type ProposedChange<T> = {
|
|
49
|
+
[P in keyof T]: {
|
|
50
|
+
_id: string;
|
|
51
|
+
created_at: UnixTimestamp;
|
|
52
|
+
created_by: string;
|
|
53
|
+
curr_value: T[P];
|
|
54
|
+
field: P;
|
|
55
|
+
related_id: string;
|
|
56
|
+
scope: Scope;
|
|
57
|
+
status: ApprovalStatus;
|
|
58
|
+
updated_at: UnixTimestamp;
|
|
59
|
+
updated_by: string;
|
|
60
|
+
};
|
|
61
|
+
}[keyof T];
|
|
62
|
+
export declare const CreateProposedChangeSchema: z.ZodObject<Omit<{
|
|
63
|
+
_id: z.ZodString;
|
|
64
|
+
created_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixTimestamp, string | number>;
|
|
65
|
+
created_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
66
|
+
is_locked: z.ZodDefault<z.ZodBoolean>;
|
|
67
|
+
updated_at: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, UnixTimestamp, string | number>;
|
|
68
|
+
updated_by: z.ZodOptional<z.ZodString>;
|
|
69
|
+
} & {
|
|
70
|
+
curr_value: z.ZodAny;
|
|
71
|
+
field: z.ZodString;
|
|
72
|
+
related_id: z.ZodString;
|
|
73
|
+
scope: z.ZodEnum<["stop", "lines"]>;
|
|
74
|
+
status: z.ZodEnum<["pending", "approved", "rejected", "none"]>;
|
|
75
|
+
}, "_id" | "created_at" | "updated_at">, "strip", z.ZodTypeAny, {
|
|
76
|
+
status: "pending" | "approved" | "rejected" | "none";
|
|
77
|
+
created_by: string | null;
|
|
78
|
+
is_locked: boolean;
|
|
79
|
+
field: string;
|
|
80
|
+
related_id: string;
|
|
81
|
+
scope: "stop" | "lines";
|
|
82
|
+
updated_by?: string | undefined;
|
|
83
|
+
curr_value?: any;
|
|
84
|
+
}, {
|
|
85
|
+
status: "pending" | "approved" | "rejected" | "none";
|
|
86
|
+
field: string;
|
|
87
|
+
related_id: string;
|
|
88
|
+
scope: "stop" | "lines";
|
|
89
|
+
created_by?: string | null | undefined;
|
|
90
|
+
is_locked?: boolean | undefined;
|
|
91
|
+
updated_by?: string | undefined;
|
|
92
|
+
curr_value?: any;
|
|
93
|
+
}>;
|
|
94
|
+
export declare const UpdateProposedChangeSchema: z.ZodObject<{
|
|
95
|
+
status: z.ZodOptional<z.ZodEnum<["pending", "approved", "rejected", "none"]>>;
|
|
96
|
+
is_locked: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
97
|
+
updated_by: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
98
|
+
curr_value: z.ZodOptional<z.ZodAny>;
|
|
99
|
+
field: z.ZodOptional<z.ZodString>;
|
|
100
|
+
related_id: z.ZodOptional<z.ZodString>;
|
|
101
|
+
scope: z.ZodOptional<z.ZodEnum<["stop", "lines"]>>;
|
|
102
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
|
+
status?: "pending" | "approved" | "rejected" | "none" | undefined;
|
|
104
|
+
is_locked?: boolean | undefined;
|
|
105
|
+
updated_by?: string | undefined;
|
|
106
|
+
curr_value?: any;
|
|
107
|
+
field?: string | undefined;
|
|
108
|
+
related_id?: string | undefined;
|
|
109
|
+
scope?: "stop" | "lines" | undefined;
|
|
110
|
+
}, {
|
|
111
|
+
status?: "pending" | "approved" | "rejected" | "none" | undefined;
|
|
112
|
+
is_locked?: boolean | undefined;
|
|
113
|
+
updated_by?: string | undefined;
|
|
114
|
+
curr_value?: any;
|
|
115
|
+
field?: string | undefined;
|
|
116
|
+
related_id?: string | undefined;
|
|
117
|
+
scope?: "stop" | "lines" | undefined;
|
|
118
|
+
}>;
|
|
119
|
+
export type CreateProposedChangeDto<T> = Omit<ProposedChange<T>, '_id' | 'created_at' | 'updated_at'>;
|
|
120
|
+
export type UpdateProposedChangeDto<T> = Omit<CreateProposedChangeDto<T>, 'created_by'>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { DocumentSchema } from './document.js';
|
|
3
|
+
import { ApprovalStatusSchema } from '../status/approval.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/* * */
|
|
6
|
+
//
|
|
7
|
+
// Define constants for enum values for better maintainability
|
|
8
|
+
export const ScopeSchema = z.enum(['stop', 'lines']);
|
|
9
|
+
// Define schemas using constants
|
|
10
|
+
export const ProposedChangeSchema = DocumentSchema.extend({
|
|
11
|
+
curr_value: z.any(),
|
|
12
|
+
field: z.string(),
|
|
13
|
+
related_id: z.string(),
|
|
14
|
+
scope: ScopeSchema,
|
|
15
|
+
status: ApprovalStatusSchema,
|
|
16
|
+
});
|
|
17
|
+
export const CreateProposedChangeSchema = ProposedChangeSchema.omit({ _id: true, created_at: true, updated_at: true });
|
|
18
|
+
export const UpdateProposedChangeSchema = CreateProposedChangeSchema.omit({ created_by: true }).partial();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The latitude of a geographic coordinate, in degrees.
|
|
4
|
+
*/
|
|
5
|
+
export type Latitude = number & {
|
|
6
|
+
__brand: 'Latitude';
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The schema for a latitude value.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const latitude = LatitudeSchema.parse('40.712886213');
|
|
13
|
+
* // => 40.712886
|
|
14
|
+
*
|
|
15
|
+
* const latitude = LatitudeSchema.parse(40.712886213);
|
|
16
|
+
* // => 40.712886
|
|
17
|
+
*
|
|
18
|
+
* const latitude = LatitudeSchema.parse('94.7128');
|
|
19
|
+
* // => Throws an error: 'Latitude must be between -90 and 90'
|
|
20
|
+
*/
|
|
21
|
+
export declare const LatitudeSchema: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, Latitude, string | number>;
|
|
22
|
+
/**
|
|
23
|
+
* Validate a latitude value.
|
|
24
|
+
* @param value The latitude value to validate.
|
|
25
|
+
* @throws An error if the latitude value is invalid.
|
|
26
|
+
* @returns The validated latitude value.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateLatitude(value: number | string): Latitude;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* The schema for a latitude value.
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const latitude = LatitudeSchema.parse('40.712886213');
|
|
8
|
+
* // => 40.712886
|
|
9
|
+
*
|
|
10
|
+
* const latitude = LatitudeSchema.parse(40.712886213);
|
|
11
|
+
* // => 40.712886
|
|
12
|
+
*
|
|
13
|
+
* const latitude = LatitudeSchema.parse('94.7128');
|
|
14
|
+
* // => Throws an error: 'Latitude must be between -90 and 90'
|
|
15
|
+
*/
|
|
16
|
+
export const LatitudeSchema = z
|
|
17
|
+
.union([z.string(), z.number()])
|
|
18
|
+
.transform(validateLatitude);
|
|
19
|
+
/**
|
|
20
|
+
* Validate a latitude value.
|
|
21
|
+
* @param value The latitude value to validate.
|
|
22
|
+
* @throws An error if the latitude value is invalid.
|
|
23
|
+
* @returns The validated latitude value.
|
|
24
|
+
*/
|
|
25
|
+
export function validateLatitude(value) {
|
|
26
|
+
const valueAsNumber = parseFloat(String(value));
|
|
27
|
+
if (Number.isNaN(valueAsNumber))
|
|
28
|
+
throw new Error('Latitude must be a valid number');
|
|
29
|
+
if (valueAsNumber < -90 || valueAsNumber > 90)
|
|
30
|
+
throw new Error('Latitude must be between -90 and 90');
|
|
31
|
+
return Number(valueAsNumber.toFixed(6));
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The longitude of a geographic coordinate, in degrees.
|
|
4
|
+
*/
|
|
5
|
+
export type Longitude = number & {
|
|
6
|
+
__brand: 'Longitude';
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The schema for a longitude value.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const longitude = LongitudeSchema.parse('-9.55841684');
|
|
13
|
+
* // => -9.558416
|
|
14
|
+
*
|
|
15
|
+
* const longitude = LongitudeSchema.parse(-9.55841684);
|
|
16
|
+
* // => -9.558416
|
|
17
|
+
*
|
|
18
|
+
* const longitude = LongitudeSchema.parse('180.1');
|
|
19
|
+
* // => Throws an error: 'Longitude must be between -180 and 180'
|
|
20
|
+
*/
|
|
21
|
+
export declare const LongitudeSchema: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, Longitude, string | number>;
|
|
22
|
+
/**
|
|
23
|
+
* Validate a longitude value.
|
|
24
|
+
* @param value The longitude value to validate.
|
|
25
|
+
* @throws An error if the longitude value is invalid.
|
|
26
|
+
* @returns The validated longitude value.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateLongitude(value: number | string): Longitude;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* The schema for a longitude value.
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const longitude = LongitudeSchema.parse('-9.55841684');
|
|
8
|
+
* // => -9.558416
|
|
9
|
+
*
|
|
10
|
+
* const longitude = LongitudeSchema.parse(-9.55841684);
|
|
11
|
+
* // => -9.558416
|
|
12
|
+
*
|
|
13
|
+
* const longitude = LongitudeSchema.parse('180.1');
|
|
14
|
+
* // => Throws an error: 'Longitude must be between -180 and 180'
|
|
15
|
+
*/
|
|
16
|
+
export const LongitudeSchema = z
|
|
17
|
+
.union([z.string(), z.number()])
|
|
18
|
+
.transform(validateLongitude);
|
|
19
|
+
/**
|
|
20
|
+
* Validate a longitude value.
|
|
21
|
+
* @param value The longitude value to validate.
|
|
22
|
+
* @throws An error if the longitude value is invalid.
|
|
23
|
+
* @returns The validated longitude value.
|
|
24
|
+
*/
|
|
25
|
+
export function validateLongitude(value) {
|
|
26
|
+
const valueAsNumber = parseFloat(String(value));
|
|
27
|
+
if (Number.isNaN(valueAsNumber))
|
|
28
|
+
throw new Error('Longitude must be a valid number');
|
|
29
|
+
if (valueAsNumber < -180 || valueAsNumber > 180)
|
|
30
|
+
throw new Error('Longitude must be between -180 and 180');
|
|
31
|
+
return Number(valueAsNumber.toFixed(6));
|
|
32
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
export * from './api/index.js';
|
|
2
|
+
export * from './conditions/index.js';
|
|
1
3
|
export * from './dates/index.js';
|
|
2
|
-
export * from './documents/
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './environment.js';
|
|
5
|
-
export * from './fastify.js';
|
|
6
|
-
export * from './i18n-code.js';
|
|
7
|
-
export * from './position.js';
|
|
4
|
+
export * from './documents/index.js';
|
|
5
|
+
export * from './geo/index.js';
|
|
8
6
|
export * from './status/index.js';
|
|
9
|
-
export * from './
|
|
7
|
+
export * from './utils/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
export * from './api/index.js';
|
|
2
|
+
export * from './conditions/index.js';
|
|
1
3
|
export * from './dates/index.js';
|
|
2
|
-
export * from './documents/
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './environment.js';
|
|
5
|
-
export * from './fastify.js';
|
|
6
|
-
export * from './i18n-code.js';
|
|
7
|
-
export * from './position.js';
|
|
4
|
+
export * from './documents/index.js';
|
|
5
|
+
export * from './geo/index.js';
|
|
8
6
|
export * from './status/index.js';
|
|
9
|
-
export * from './
|
|
7
|
+
export * from './utils/index.js';
|
package/package.json
CHANGED
package/dist/position.d.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
export declare const PositionSchema: z.ZodObject<{
|
|
3
|
-
geohash: z.ZodString;
|
|
4
|
-
h3: z.ZodString;
|
|
5
|
-
latitude: z.ZodNumber;
|
|
6
|
-
longitude: z.ZodNumber;
|
|
7
|
-
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
geohash: string;
|
|
9
|
-
h3: string;
|
|
10
|
-
latitude: number;
|
|
11
|
-
longitude: number;
|
|
12
|
-
}, {
|
|
13
|
-
geohash: string;
|
|
14
|
-
h3: string;
|
|
15
|
-
latitude: number;
|
|
16
|
-
longitude: number;
|
|
17
|
-
}>;
|
|
18
|
-
export declare const ExtendedPositionSchema: z.ZodObject<{
|
|
19
|
-
geohash: z.ZodObject<{
|
|
20
|
-
geohash_2: z.ZodString;
|
|
21
|
-
geohash_3: z.ZodString;
|
|
22
|
-
geohash_4: z.ZodString;
|
|
23
|
-
geohash_5: z.ZodString;
|
|
24
|
-
geohash_6: z.ZodString;
|
|
25
|
-
geohash_7: z.ZodString;
|
|
26
|
-
geohash_8: z.ZodString;
|
|
27
|
-
geohash_9: z.ZodString;
|
|
28
|
-
geohash_10: z.ZodString;
|
|
29
|
-
geohash_11: z.ZodString;
|
|
30
|
-
geohash_12: z.ZodString;
|
|
31
|
-
}, "strip", z.ZodTypeAny, {
|
|
32
|
-
geohash_2: string;
|
|
33
|
-
geohash_3: string;
|
|
34
|
-
geohash_4: string;
|
|
35
|
-
geohash_5: string;
|
|
36
|
-
geohash_6: string;
|
|
37
|
-
geohash_7: string;
|
|
38
|
-
geohash_8: string;
|
|
39
|
-
geohash_9: string;
|
|
40
|
-
geohash_10: string;
|
|
41
|
-
geohash_11: string;
|
|
42
|
-
geohash_12: string;
|
|
43
|
-
}, {
|
|
44
|
-
geohash_2: string;
|
|
45
|
-
geohash_3: string;
|
|
46
|
-
geohash_4: string;
|
|
47
|
-
geohash_5: string;
|
|
48
|
-
geohash_6: string;
|
|
49
|
-
geohash_7: string;
|
|
50
|
-
geohash_8: string;
|
|
51
|
-
geohash_9: string;
|
|
52
|
-
geohash_10: string;
|
|
53
|
-
geohash_11: string;
|
|
54
|
-
geohash_12: string;
|
|
55
|
-
}>;
|
|
56
|
-
h3: z.ZodObject<{
|
|
57
|
-
h3_1: z.ZodString;
|
|
58
|
-
h3_2: z.ZodString;
|
|
59
|
-
h3_3: z.ZodString;
|
|
60
|
-
h3_4: z.ZodString;
|
|
61
|
-
h3_5: z.ZodString;
|
|
62
|
-
h3_6: z.ZodString;
|
|
63
|
-
h3_7: z.ZodString;
|
|
64
|
-
h3_8: z.ZodString;
|
|
65
|
-
h3_9: z.ZodString;
|
|
66
|
-
h3_10: z.ZodString;
|
|
67
|
-
h3_11: z.ZodString;
|
|
68
|
-
h3_12: z.ZodString;
|
|
69
|
-
}, "strip", z.ZodTypeAny, {
|
|
70
|
-
h3_1: string;
|
|
71
|
-
h3_2: string;
|
|
72
|
-
h3_3: string;
|
|
73
|
-
h3_4: string;
|
|
74
|
-
h3_5: string;
|
|
75
|
-
h3_6: string;
|
|
76
|
-
h3_7: string;
|
|
77
|
-
h3_8: string;
|
|
78
|
-
h3_9: string;
|
|
79
|
-
h3_10: string;
|
|
80
|
-
h3_11: string;
|
|
81
|
-
h3_12: string;
|
|
82
|
-
}, {
|
|
83
|
-
h3_1: string;
|
|
84
|
-
h3_2: string;
|
|
85
|
-
h3_3: string;
|
|
86
|
-
h3_4: string;
|
|
87
|
-
h3_5: string;
|
|
88
|
-
h3_6: string;
|
|
89
|
-
h3_7: string;
|
|
90
|
-
h3_8: string;
|
|
91
|
-
h3_9: string;
|
|
92
|
-
h3_10: string;
|
|
93
|
-
h3_11: string;
|
|
94
|
-
h3_12: string;
|
|
95
|
-
}>;
|
|
96
|
-
latitude: z.ZodNumber;
|
|
97
|
-
longitude: z.ZodNumber;
|
|
98
|
-
}, "strip", z.ZodTypeAny, {
|
|
99
|
-
geohash: {
|
|
100
|
-
geohash_2: string;
|
|
101
|
-
geohash_3: string;
|
|
102
|
-
geohash_4: string;
|
|
103
|
-
geohash_5: string;
|
|
104
|
-
geohash_6: string;
|
|
105
|
-
geohash_7: string;
|
|
106
|
-
geohash_8: string;
|
|
107
|
-
geohash_9: string;
|
|
108
|
-
geohash_10: string;
|
|
109
|
-
geohash_11: string;
|
|
110
|
-
geohash_12: string;
|
|
111
|
-
};
|
|
112
|
-
h3: {
|
|
113
|
-
h3_1: string;
|
|
114
|
-
h3_2: string;
|
|
115
|
-
h3_3: string;
|
|
116
|
-
h3_4: string;
|
|
117
|
-
h3_5: string;
|
|
118
|
-
h3_6: string;
|
|
119
|
-
h3_7: string;
|
|
120
|
-
h3_8: string;
|
|
121
|
-
h3_9: string;
|
|
122
|
-
h3_10: string;
|
|
123
|
-
h3_11: string;
|
|
124
|
-
h3_12: string;
|
|
125
|
-
};
|
|
126
|
-
latitude: number;
|
|
127
|
-
longitude: number;
|
|
128
|
-
}, {
|
|
129
|
-
geohash: {
|
|
130
|
-
geohash_2: string;
|
|
131
|
-
geohash_3: string;
|
|
132
|
-
geohash_4: string;
|
|
133
|
-
geohash_5: string;
|
|
134
|
-
geohash_6: string;
|
|
135
|
-
geohash_7: string;
|
|
136
|
-
geohash_8: string;
|
|
137
|
-
geohash_9: string;
|
|
138
|
-
geohash_10: string;
|
|
139
|
-
geohash_11: string;
|
|
140
|
-
geohash_12: string;
|
|
141
|
-
};
|
|
142
|
-
h3: {
|
|
143
|
-
h3_1: string;
|
|
144
|
-
h3_2: string;
|
|
145
|
-
h3_3: string;
|
|
146
|
-
h3_4: string;
|
|
147
|
-
h3_5: string;
|
|
148
|
-
h3_6: string;
|
|
149
|
-
h3_7: string;
|
|
150
|
-
h3_8: string;
|
|
151
|
-
h3_9: string;
|
|
152
|
-
h3_10: string;
|
|
153
|
-
h3_11: string;
|
|
154
|
-
h3_12: string;
|
|
155
|
-
};
|
|
156
|
-
latitude: number;
|
|
157
|
-
longitude: number;
|
|
158
|
-
}>;
|
|
159
|
-
export type Position = z.infer<typeof PositionSchema>;
|
|
160
|
-
export type ExtendedPosition = z.infer<typeof ExtendedPositionSchema>;
|
package/dist/position.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
/* * */
|
|
3
|
-
export const PositionSchema = z.object({
|
|
4
|
-
geohash: z.string(),
|
|
5
|
-
h3: z.string(),
|
|
6
|
-
latitude: z.number(),
|
|
7
|
-
longitude: z.number(),
|
|
8
|
-
});
|
|
9
|
-
export const ExtendedPositionSchema = z.object({
|
|
10
|
-
geohash: z.object({
|
|
11
|
-
geohash_2: z.string(),
|
|
12
|
-
geohash_3: z.string(),
|
|
13
|
-
geohash_4: z.string(),
|
|
14
|
-
geohash_5: z.string(),
|
|
15
|
-
geohash_6: z.string(),
|
|
16
|
-
geohash_7: z.string(),
|
|
17
|
-
geohash_8: z.string(),
|
|
18
|
-
geohash_9: z.string(),
|
|
19
|
-
//
|
|
20
|
-
geohash_10: z.string(),
|
|
21
|
-
geohash_11: z.string(),
|
|
22
|
-
geohash_12: z.string(),
|
|
23
|
-
}),
|
|
24
|
-
h3: z.object({
|
|
25
|
-
h3_1: z.string(),
|
|
26
|
-
h3_2: z.string(),
|
|
27
|
-
h3_3: z.string(),
|
|
28
|
-
h3_4: z.string(),
|
|
29
|
-
h3_5: z.string(),
|
|
30
|
-
h3_6: z.string(),
|
|
31
|
-
h3_7: z.string(),
|
|
32
|
-
h3_8: z.string(),
|
|
33
|
-
h3_9: z.string(),
|
|
34
|
-
//
|
|
35
|
-
h3_10: z.string(),
|
|
36
|
-
h3_11: z.string(),
|
|
37
|
-
h3_12: z.string(),
|
|
38
|
-
}),
|
|
39
|
-
latitude: z.number(),
|
|
40
|
-
longitude: z.number(),
|
|
41
|
-
});
|
package/dist/utility.d.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A type that represents either a single instance of type T or an array of type T.
|
|
3
|
-
*
|
|
4
|
-
* @template T - The type of the element(s).
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* function processItems<T>(items: OneOrMore<T>) {
|
|
9
|
-
* const arr = Array.isArray(items) ? items : [items];
|
|
10
|
-
* console.log(arr);
|
|
11
|
-
* }
|
|
12
|
-
*
|
|
13
|
-
* processItems("apple"); // ["apple"]
|
|
14
|
-
* processItems(["a", "b"]); // ["a", "b"]
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export type OneOrMore<T> = T | T[];
|
|
18
|
-
/**
|
|
19
|
-
* A type that represents either A or B, but not both.
|
|
20
|
-
*
|
|
21
|
-
* @template A - The first type.
|
|
22
|
-
* @template B - The second type.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* type Credentials = OneOrTheOther<{ email: string }, { username: string }>;
|
|
27
|
-
*
|
|
28
|
-
* const a: Credentials = { email: "a@b.com" }; // ✅
|
|
29
|
-
* const b: Credentials = { username: "user1" }; // ✅
|
|
30
|
-
* const c: Credentials = { email: "a@b.com", username: "user1" }; // ❌
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export type OneOrTheOther<A, B> = (A & {
|
|
34
|
-
[K in keyof B]?: never;
|
|
35
|
-
}) | (B & {
|
|
36
|
-
[K in keyof A]?: never;
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* A type that represents exactly one key-value pair in the object T.
|
|
40
|
-
*
|
|
41
|
-
* @template T - The type of the object.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
type Action = ExactlyOne<{
|
|
46
|
-
create: { name: string };
|
|
47
|
-
update: { id: string; name?: string };
|
|
48
|
-
delete: { id: string };
|
|
49
|
-
}>;
|
|
50
|
-
|
|
51
|
-
const x: Action = { create: { name: "New" } }; // ✅
|
|
52
|
-
const y: Action = { update: { id: "123" } }; // ✅
|
|
53
|
-
const z: Action = { create: { name: "X" }, delete: { id: "1" } }; // ❌
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export type ExactlyOne<T> = {
|
|
57
|
-
[K in keyof T]: Partial<Record<Exclude<keyof T, K>, never>> & {
|
|
58
|
-
[P in K]: T[P];
|
|
59
|
-
};
|
|
60
|
-
}[keyof T];
|
|
61
|
-
/**
|
|
62
|
-
* A type that represents either none or exactly one key-value pair in the object T.
|
|
63
|
-
*
|
|
64
|
-
* @template T - The type of the object.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* type Filters = { name: string; age: number; email: string };
|
|
69
|
-
* type FilterChoice = NoneOrExactlyOne<Filters>;
|
|
70
|
-
*
|
|
71
|
-
* const a: FilterChoice = {}; // ✅ none
|
|
72
|
-
* const b: FilterChoice = { name: "Alice" }; // ✅ exactly one
|
|
73
|
-
* const c: FilterChoice = { age: 30 }; // ✅ exactly one
|
|
74
|
-
* const d: FilterChoice = { name: "Alice", age: 30 }; // ❌ error
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export type NoneOrExactlyOne<T> = {
|
|
78
|
-
[K in keyof T]: Partial<Record<Exclude<keyof T, K>, never>> & {
|
|
79
|
-
[P in K]: T[P];
|
|
80
|
-
};
|
|
81
|
-
}[keyof T] | {
|
|
82
|
-
[K in keyof T]?: never;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Makes keys in `TFields` required when `TCondition` is absent,
|
|
86
|
-
* and optional when `TCondition` is present.
|
|
87
|
-
*
|
|
88
|
-
* @template T - The base object type.
|
|
89
|
-
* @template TCondition - The key that triggers optionality when present.
|
|
90
|
-
* @template TFields - The keys that become optional when `TCondition` is present.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* type Lookup = OptionalIf<
|
|
95
|
-
* { from: string; localField?: string; foreignField?: string; pipeline?: any[] },
|
|
96
|
-
* 'pipeline',
|
|
97
|
-
* 'localField' | 'foreignField'
|
|
98
|
-
* >;
|
|
99
|
-
*
|
|
100
|
-
* const a: Lookup = { from: "c", localField: "x", foreignField: "y" }; // ✅
|
|
101
|
-
* const b: Lookup = { from: "c", pipeline: [] }; // ✅
|
|
102
|
-
* const c: Lookup = { from: "c", pipeline: [], localField: "x" }; // ✅ (optional)
|
|
103
|
-
* const d: Lookup = { from: "c" }; // ❌ (localField/foreignField required when no pipeline)
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
export type OptionalIf<T extends object, TCondition extends keyof T, TFields extends keyof T> = (Omit<T, TCondition | TFields> & Partial<Pick<T, TFields>> & Required<Pick<T, TCondition>>) | (Omit<T, TFields> & Required<Pick<T, TFields>> & {
|
|
107
|
-
[K in TCondition]?: never;
|
|
108
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|