@naturalcycles/js-lib 15.4.0 → 15.5.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,4 +1,6 @@
1
1
  export * from './zod.shared.schemas.js';
2
2
  export * from './zod.util.js';
3
+ import type { ZodJSONSchema } from 'zod/v4';
3
4
  import { z, ZodType } from 'zod/v4';
4
5
  export { z, ZodType };
6
+ export type { ZodJSONSchema };
@@ -6,8 +6,9 @@ export declare const zUnixTimestamp2000: z.ZodNumber;
6
6
  export declare const zUnixTimestampMillis: z.ZodNumber;
7
7
  export declare const zUnixTimestampMillis2000: z.ZodNumber;
8
8
  export declare const zSemVer: z.ZodString;
9
- export declare const zIsoDateString: z.ZodString;
9
+ export declare const zIsoDate: z.ZodString;
10
10
  export declare const zEmail: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
11
+ export declare const zEmailNoLowercase: z.ZodString;
11
12
  export declare const BASE62_REGEX: RegExp;
12
13
  export declare const BASE64_REGEX: RegExp;
13
14
  export declare const BASE64URL_REGEX: RegExp;
@@ -6,40 +6,51 @@ export const zUnixTimestamp = z
6
6
  .int()
7
7
  .min(0)
8
8
  .max(TS_2500, 'Must be a UnixTimestamp number')
9
+ // .transform(v => v as UnixTimestamp) // breaks jsonSchema
9
10
  .describe('UnixTimestamp');
10
11
  export const zUnixTimestamp2000 = z
11
12
  .number()
12
13
  .int()
13
14
  .min(TS_2000)
14
15
  .max(TS_2500, 'Must be a UnixTimestamp number after 2000-01-01')
16
+ // .transform(v => v as UnixTimestamp)
15
17
  .describe('UnixTimestamp2000');
16
18
  export const zUnixTimestampMillis = z
17
19
  .number()
18
20
  .int()
19
21
  .min(0)
20
22
  .max(TS_2500 * 1000, 'Must be a UnixTimestampMillis number')
23
+ // .transform(v => v as UnixTimestampMillis)
21
24
  .describe('UnixTimestampMillis');
22
25
  export const zUnixTimestampMillis2000 = z
23
26
  .number()
24
27
  .int()
25
28
  .min(TS_2000 * 1000)
26
29
  .max(TS_2500 * 1000, 'Must be a UnixTimestampMillis number after 2000-01-01')
30
+ // .transform(v => v as UnixTimestampMillis)
27
31
  .describe('UnixTimestampMillis2000');
28
32
  export const zSemVer = z
29
33
  .string()
30
34
  .regex(/^[0-9]+\.[0-9]+\.[0-9]+$/, 'Must be a SemVer string')
31
35
  .describe('SemVer');
32
- export const zIsoDateString = z
36
+ export const zIsoDate = z
33
37
  .string()
34
38
  .refine(v => {
35
39
  return /^\d{4}-\d{2}-\d{2}$/.test(v);
36
40
  }, 'Must be an IsoDateString')
41
+ // .transform(v => v as IsoDate)
37
42
  .describe('IsoDateString');
38
43
  export const zEmail = z
39
44
  .string()
40
45
  .trim()
41
46
  .email() // keeping as-is, so trim happens before email validation
42
- .transform(s => s.toLowerCase())
47
+ .transform(s => s.toLowerCase()) // breaks toJsonSchema
48
+ .describe('Email');
49
+ export const zEmailNoLowercase = z
50
+ .string()
51
+ .trim()
52
+ .email() // keeping as-is, so trim happens before email validation
53
+ // .transform(s => s.toLowerCase()) // breaks toJsonSchema
43
54
  .describe('Email');
44
55
  export const BASE62_REGEX = /^[a-zA-Z0-9]+$/;
45
56
  export const BASE64_REGEX = /^[A-Za-z0-9+/]+={0,2}$/;
@@ -60,7 +71,7 @@ export const JWT_REGEX = /^[\w-]+\.[\w-]+\.[\w-]+$/;
60
71
  export const zJwt = z.string().regex(JWT_REGEX, 'Must be a JWT string').describe('JWTString');
61
72
  export const zId = z
62
73
  .string()
63
- .regex(/^[a-zA-Z0-9_]{6,64}$/, 'Must be an id string')
74
+ .regex(/^[a-zA-Z0-9_]{6,64}$/, 'Must be an id string (6 to 64 chars long)')
64
75
  .describe('IdString');
65
76
  export const zIdBase62 = z
66
77
  .string()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.4.0",
4
+ "version": "15.5.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2",
7
7
  "zod": "^3"
package/src/zod/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from './zod.shared.schemas.js'
2
2
  export * from './zod.util.js'
3
+ import type { ZodJSONSchema } from 'zod/v4'
3
4
  import { z, ZodType } from 'zod/v4'
4
5
 
5
6
  export { z, ZodType }
7
+ export type { ZodJSONSchema }
@@ -8,24 +8,28 @@ export const zUnixTimestamp = z
8
8
  .int()
9
9
  .min(0)
10
10
  .max(TS_2500, 'Must be a UnixTimestamp number')
11
+ // .transform(v => v as UnixTimestamp) // breaks jsonSchema
11
12
  .describe('UnixTimestamp')
12
13
  export const zUnixTimestamp2000 = z
13
14
  .number()
14
15
  .int()
15
16
  .min(TS_2000)
16
17
  .max(TS_2500, 'Must be a UnixTimestamp number after 2000-01-01')
18
+ // .transform(v => v as UnixTimestamp)
17
19
  .describe('UnixTimestamp2000')
18
20
  export const zUnixTimestampMillis = z
19
21
  .number()
20
22
  .int()
21
23
  .min(0)
22
24
  .max(TS_2500 * 1000, 'Must be a UnixTimestampMillis number')
25
+ // .transform(v => v as UnixTimestampMillis)
23
26
  .describe('UnixTimestampMillis')
24
27
  export const zUnixTimestampMillis2000 = z
25
28
  .number()
26
29
  .int()
27
30
  .min(TS_2000 * 1000)
28
31
  .max(TS_2500 * 1000, 'Must be a UnixTimestampMillis number after 2000-01-01')
32
+ // .transform(v => v as UnixTimestampMillis)
29
33
  .describe('UnixTimestampMillis2000')
30
34
 
31
35
  export const zSemVer = z
@@ -33,18 +37,26 @@ export const zSemVer = z
33
37
  .regex(/^[0-9]+\.[0-9]+\.[0-9]+$/, 'Must be a SemVer string')
34
38
  .describe('SemVer')
35
39
 
36
- export const zIsoDateString = z
40
+ export const zIsoDate = z
37
41
  .string()
38
42
  .refine(v => {
39
43
  return /^\d{4}-\d{2}-\d{2}$/.test(v)
40
44
  }, 'Must be an IsoDateString')
45
+ // .transform(v => v as IsoDate)
41
46
  .describe('IsoDateString')
42
47
 
43
48
  export const zEmail = z
44
49
  .string()
45
50
  .trim()
46
51
  .email() // keeping as-is, so trim happens before email validation
47
- .transform(s => s.toLowerCase())
52
+ .transform(s => s.toLowerCase()) // breaks toJsonSchema
53
+ .describe('Email')
54
+
55
+ export const zEmailNoLowercase = z
56
+ .string()
57
+ .trim()
58
+ .email() // keeping as-is, so trim happens before email validation
59
+ // .transform(s => s.toLowerCase()) // breaks toJsonSchema
48
60
  .describe('Email')
49
61
 
50
62
  export const BASE62_REGEX = /^[a-zA-Z0-9]+$/
@@ -68,7 +80,7 @@ export const zJwt = z.string().regex(JWT_REGEX, 'Must be a JWT string').describe
68
80
 
69
81
  export const zId = z
70
82
  .string()
71
- .regex(/^[a-zA-Z0-9_]{6,64}$/, 'Must be an id string')
83
+ .regex(/^[a-zA-Z0-9_]{6,64}$/, 'Must be an id string (6 to 64 chars long)')
72
84
  .describe('IdString')
73
85
  export const zIdBase62 = z
74
86
  .string()