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