@naturalcycles/js-lib 15.13.0 → 15.15.0
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.
|
@@ -2,15 +2,16 @@ import { z } from 'zod/v4';
|
|
|
2
2
|
import type { IsoDate, UnixTimestamp, UnixTimestampMillis } from '../types.js';
|
|
3
3
|
type ZodBranded<T, B> = T & Record<'_zod', Record<'output', number & B>>;
|
|
4
4
|
export type ZodBrandedString<B> = ZodBranded<z.ZodString, B>;
|
|
5
|
+
export type ZodBrandedInt<B> = ZodBranded<z.ZodInt, B>;
|
|
5
6
|
export type ZodBrandedNumber<B> = ZodBranded<z.ZodNumber, B>;
|
|
6
7
|
export declare const TS_2500 = 16725225600;
|
|
7
8
|
export declare const TS_2000 = 946684800;
|
|
8
|
-
export declare const zUnixTimestamp: () =>
|
|
9
|
-
export declare const zUnixTimestamp2000: () =>
|
|
9
|
+
export declare const zUnixTimestamp: () => ZodBrandedInt<UnixTimestamp>;
|
|
10
|
+
export declare const zUnixTimestamp2000: () => ZodBrandedInt<UnixTimestamp>;
|
|
10
11
|
export declare const zUnixTimestampMillis: () => ZodBranded<z.ZodNumber, UnixTimestampMillis>;
|
|
11
|
-
export declare const zUnixTimestampMillis2000: () =>
|
|
12
|
+
export declare const zUnixTimestampMillis2000: () => ZodBrandedInt<UnixTimestampMillis>;
|
|
12
13
|
export declare const zSemVer: () => z.ZodString;
|
|
13
|
-
export declare const zIsoDate: () =>
|
|
14
|
+
export declare const zIsoDate: () => ZodBrandedString<IsoDate>;
|
|
14
15
|
export declare const zEmail: () => z.ZodEmail;
|
|
15
16
|
export declare const BASE62_REGEX: RegExp;
|
|
16
17
|
export declare const BASE64_REGEX: RegExp;
|
|
@@ -31,13 +32,13 @@ export declare const customZodSchemas: {
|
|
|
31
32
|
base64Url: () => z.ZodString;
|
|
32
33
|
email: () => z.ZodEmail;
|
|
33
34
|
ianaTimezone: () => z.ZodEnum;
|
|
34
|
-
isoDate: () =>
|
|
35
|
+
isoDate: () => ZodBrandedString<IsoDate>;
|
|
35
36
|
jwt: () => z.ZodString;
|
|
36
37
|
slug: () => z.ZodString;
|
|
37
38
|
semver: () => z.ZodString;
|
|
38
|
-
unixTimestamp: () =>
|
|
39
|
-
unixTimestamp2000: () =>
|
|
39
|
+
unixTimestamp: () => ZodBrandedInt<UnixTimestamp>;
|
|
40
|
+
unixTimestamp2000: () => ZodBrandedInt<UnixTimestamp>;
|
|
40
41
|
unixTimestampMillis: () => ZodBranded<z.ZodNumber, UnixTimestampMillis>;
|
|
41
|
-
unixTimestampMillis2000: () =>
|
|
42
|
+
unixTimestampMillis2000: () => ZodBrandedInt<UnixTimestampMillis>;
|
|
42
43
|
};
|
|
43
44
|
export {};
|
package/package.json
CHANGED
|
@@ -3,26 +3,27 @@ import type { IsoDate, UnixTimestamp, UnixTimestampMillis } from '../types.js'
|
|
|
3
3
|
|
|
4
4
|
type ZodBranded<T, B> = T & Record<'_zod', Record<'output', number & B>>
|
|
5
5
|
export type ZodBrandedString<B> = ZodBranded<z.ZodString, B>
|
|
6
|
+
export type ZodBrandedInt<B> = ZodBranded<z.ZodInt, B>
|
|
6
7
|
export type ZodBrandedNumber<B> = ZodBranded<z.ZodNumber, B>
|
|
7
8
|
|
|
8
9
|
export const TS_2500 = 16725225600 // 2500-01-01
|
|
9
10
|
export const TS_2000 = 946684800 // 2000-01-01
|
|
10
11
|
|
|
11
|
-
export const zUnixTimestamp = ():
|
|
12
|
+
export const zUnixTimestamp = (): ZodBrandedInt<UnixTimestamp> =>
|
|
12
13
|
z
|
|
13
14
|
.number()
|
|
14
15
|
.int()
|
|
15
16
|
.min(0)
|
|
16
17
|
.max(TS_2500, 'Must be a UnixTimestamp number')
|
|
17
|
-
.describe('UnixTimestamp') as
|
|
18
|
+
.describe('UnixTimestamp') as ZodBrandedInt<UnixTimestamp>
|
|
18
19
|
|
|
19
|
-
export const zUnixTimestamp2000 = ():
|
|
20
|
+
export const zUnixTimestamp2000 = (): ZodBrandedInt<UnixTimestamp> =>
|
|
20
21
|
z
|
|
21
22
|
.number()
|
|
22
23
|
.int()
|
|
23
24
|
.min(TS_2000)
|
|
24
25
|
.max(TS_2500, 'Must be a UnixTimestamp number after 2000-01-01')
|
|
25
|
-
.describe('UnixTimestamp2000') as
|
|
26
|
+
.describe('UnixTimestamp2000') as ZodBrandedInt<UnixTimestamp>
|
|
26
27
|
|
|
27
28
|
export const zUnixTimestampMillis = (): ZodBranded<z.ZodNumber, UnixTimestampMillis> =>
|
|
28
29
|
z
|
|
@@ -30,15 +31,15 @@ export const zUnixTimestampMillis = (): ZodBranded<z.ZodNumber, UnixTimestampMil
|
|
|
30
31
|
.int()
|
|
31
32
|
.min(0)
|
|
32
33
|
.max(TS_2500 * 1000, 'Must be a UnixTimestampMillis number')
|
|
33
|
-
.describe('UnixTimestampMillis') as
|
|
34
|
+
.describe('UnixTimestampMillis') as ZodBrandedInt<UnixTimestampMillis>
|
|
34
35
|
|
|
35
|
-
export const zUnixTimestampMillis2000 = ():
|
|
36
|
+
export const zUnixTimestampMillis2000 = (): ZodBrandedInt<UnixTimestampMillis> =>
|
|
36
37
|
z
|
|
37
38
|
.number()
|
|
38
39
|
.int()
|
|
39
40
|
.min(TS_2000 * 1000)
|
|
40
41
|
.max(TS_2500 * 1000, 'Must be a UnixTimestampMillis number after 2000-01-01')
|
|
41
|
-
.describe('UnixTimestampMillis2000') as
|
|
42
|
+
.describe('UnixTimestampMillis2000') as ZodBrandedInt<UnixTimestampMillis>
|
|
42
43
|
|
|
43
44
|
export const zSemVer = (): z.ZodString =>
|
|
44
45
|
z
|
|
@@ -46,13 +47,13 @@ export const zSemVer = (): z.ZodString =>
|
|
|
46
47
|
.regex(/^[0-9]+\.[0-9]+\.[0-9]+$/, 'Must be a SemVer string')
|
|
47
48
|
.describe('SemVer')
|
|
48
49
|
|
|
49
|
-
export const zIsoDate = ():
|
|
50
|
+
export const zIsoDate = (): ZodBrandedString<IsoDate> =>
|
|
50
51
|
z
|
|
51
52
|
.string()
|
|
52
53
|
.refine(v => {
|
|
53
54
|
return /^\d{4}-\d{2}-\d{2}$/.test(v)
|
|
54
55
|
}, 'Must be an IsoDateString')
|
|
55
|
-
.describe('IsoDateString') as
|
|
56
|
+
.describe('IsoDateString') as ZodBrandedString<IsoDate>
|
|
56
57
|
|
|
57
58
|
export const zEmail = (): z.ZodEmail => z.email().describe('Email')
|
|
58
59
|
|