@naturalcycles/js-lib 15.20.0 → 15.21.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,3 +1,4 @@
1
+ import type { ZodString } from 'zod';
1
2
  import { z } from 'zod';
2
3
  import type { IsoDate, UnixTimestamp, UnixTimestampMillis } from '../types.js';
3
4
  type ZodBranded<T, B> = T & Record<'_zod', Record<'output', number & B>>;
@@ -26,10 +27,23 @@ export declare const zJwt: () => z.ZodString;
26
27
  */
27
28
  export declare const zSlug: () => z.ZodString;
28
29
  export declare const zIanaTimezone: () => z.ZodEnum;
30
+ export declare const zBaseDBEntity: () => z.ZodObject<{
31
+ id: ZodString;
32
+ created: ZodBrandedInt<UnixTimestamp>;
33
+ updated: ZodBrandedInt<UnixTimestamp>;
34
+ }>;
35
+ type BaseDBEntityZodShape = {
36
+ id: ZodString;
37
+ created: ZodBrandedInt<UnixTimestamp>;
38
+ updated: ZodBrandedInt<UnixTimestamp>;
39
+ };
40
+ declare function zDBEntity(): z.ZodObject<BaseDBEntityZodShape>;
41
+ declare function zDBEntity<T extends z.ZodRawShape>(shape: T): z.ZodObject<BaseDBEntityZodShape & T>;
29
42
  export declare const customZodSchemas: {
30
43
  base62: () => z.ZodString;
31
44
  base64: () => z.ZodString;
32
45
  base64Url: () => z.ZodString;
46
+ dbEntity: typeof zDBEntity;
33
47
  email: () => z.ZodEmail;
34
48
  ianaTimezone: () => z.ZodEnum;
35
49
  isoDate: () => ZodBrandedString<IsoDate>;
@@ -54,10 +54,21 @@ export const zSlug = () => z
54
54
  export const zIanaTimezone = () => z
55
55
  // UTC is added to assist unit-testing, which uses UTC by default (not technically a valid Iana timezone identifier)
56
56
  .enum([...Intl.supportedValuesOf('timeZone'), 'UTC']);
57
+ export const zBaseDBEntity = () => {
58
+ return z.object({
59
+ id: z.string(),
60
+ created: zUnixTimestamp2000(),
61
+ updated: zUnixTimestamp2000(),
62
+ });
63
+ };
64
+ function zDBEntity(shape) {
65
+ return zBaseDBEntity().extend(shape ?? {});
66
+ }
57
67
  export const customZodSchemas = {
58
68
  base62: zBase62,
59
69
  base64: zBase64,
60
70
  base64Url: zBase64Url,
71
+ dbEntity: zDBEntity,
61
72
  email: zEmail,
62
73
  ianaTimezone: zIanaTimezone,
63
74
  isoDate: zIsoDate,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.20.0",
4
+ "version": "15.21.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2",
7
7
  "zod": "^4"
@@ -12,7 +12,7 @@
12
12
  "@types/semver": "^7",
13
13
  "crypto-js": "^4",
14
14
  "dayjs": "^1",
15
- "@naturalcycles/dev-lib": "19.14.0"
15
+ "@naturalcycles/dev-lib": "18.4.2"
16
16
  },
17
17
  "exports": {
18
18
  ".": "./dist/index.js",
@@ -1,3 +1,4 @@
1
+ import type { ZodString } from 'zod'
1
2
  import { z } from 'zod'
2
3
  import type { IsoDate, UnixTimestamp, UnixTimestampMillis } from '../types.js'
3
4
 
@@ -88,10 +89,37 @@ export const zIanaTimezone = (): z.ZodEnum =>
88
89
  // UTC is added to assist unit-testing, which uses UTC by default (not technically a valid Iana timezone identifier)
89
90
  .enum([...Intl.supportedValuesOf('timeZone'), 'UTC'])
90
91
 
92
+ export const zBaseDBEntity = (): z.ZodObject<{
93
+ id: ZodString
94
+ created: ZodBrandedInt<UnixTimestamp>
95
+ updated: ZodBrandedInt<UnixTimestamp>
96
+ }> => {
97
+ return z.object({
98
+ id: z.string(),
99
+ created: zUnixTimestamp2000(),
100
+ updated: zUnixTimestamp2000(),
101
+ })
102
+ }
103
+
104
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
105
+ type BaseDBEntityZodShape = {
106
+ id: ZodString
107
+ created: ZodBrandedInt<UnixTimestamp>
108
+ updated: ZodBrandedInt<UnixTimestamp>
109
+ }
110
+
111
+ function zDBEntity(): z.ZodObject<BaseDBEntityZodShape>
112
+ function zDBEntity<T extends z.ZodRawShape>(shape: T): z.ZodObject<BaseDBEntityZodShape & T>
113
+
114
+ function zDBEntity<T extends z.ZodRawShape>(shape?: T): z.ZodObject<BaseDBEntityZodShape & T> {
115
+ return zBaseDBEntity().extend(shape ?? {}) as z.ZodObject<BaseDBEntityZodShape & T>
116
+ }
117
+
91
118
  export const customZodSchemas = {
92
119
  base62: zBase62,
93
120
  base64: zBase64,
94
121
  base64Url: zBase64Url,
122
+ dbEntity: zDBEntity,
95
123
  email: zEmail,
96
124
  ianaTimezone: zIanaTimezone,
97
125
  isoDate: zIsoDate,