@nmtjs/type 0.10.2 → 0.10.4
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/index.js +4 -46
- package/dist/index.js.map +1 -1
- package/dist/temporal.js +1 -8
- package/dist/temporal.js.map +1 -1
- package/dist/types/any.js +3 -2
- package/dist/types/any.js.map +1 -1
- package/dist/types/array.js +7 -6
- package/dist/types/array.js.map +1 -1
- package/dist/types/base.js +7 -7
- package/dist/types/base.js.map +1 -1
- package/dist/types/boolean.js +3 -2
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/custom.js +13 -8
- package/dist/types/custom.js.map +1 -1
- package/dist/types/date.js +3 -2
- package/dist/types/date.js.map +1 -1
- package/dist/types/enum.js +4 -2
- package/dist/types/enum.js.map +1 -1
- package/dist/types/literal.js +3 -2
- package/dist/types/literal.js.map +1 -1
- package/dist/types/never.js +3 -2
- package/dist/types/never.js.map +1 -1
- package/dist/types/number.js +13 -10
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +7 -5
- package/dist/types/object.js.map +1 -1
- package/dist/types/string.js +17 -16
- package/dist/types/string.js.map +1 -1
- package/dist/types/temporal.js +8 -1
- package/dist/types/temporal.js.map +1 -1
- package/dist/types/tuple.js +4 -3
- package/dist/types/tuple.js.map +1 -1
- package/dist/types/type.js +15 -0
- package/dist/types/type.js.map +1 -0
- package/dist/types/union.js +12 -7
- package/dist/types/union.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +4 -97
- package/src/temporal.ts +1 -27
- package/src/types/any.ts +5 -3
- package/src/types/array.ts +11 -16
- package/src/types/base.ts +35 -61
- package/src/types/boolean.ts +5 -3
- package/src/types/custom.ts +37 -31
- package/src/types/date.ts +8 -4
- package/src/types/enum.ts +11 -7
- package/src/types/literal.ts +5 -3
- package/src/types/never.ts +5 -3
- package/src/types/number.ts +22 -27
- package/src/types/object.ts +21 -17
- package/src/types/string.ts +32 -48
- package/src/types/temporal.ts +9 -1
- package/src/types/tuple.ts +9 -7
- package/src/types/type.ts +31 -0
- package/src/types/union.ts +25 -21
package/src/types/base.ts
CHANGED
|
@@ -1,53 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
_default,
|
|
3
|
-
core,
|
|
4
|
-
nullable,
|
|
5
|
-
optional,
|
|
6
|
-
registry,
|
|
7
|
-
type ZodMiniAny,
|
|
8
|
-
type ZodMiniArray,
|
|
9
|
-
type ZodMiniBoolean,
|
|
10
|
-
type ZodMiniCustom,
|
|
11
|
-
type ZodMiniDefault,
|
|
12
|
-
type ZodMiniEnum,
|
|
13
|
-
type ZodMiniInterface,
|
|
14
|
-
type ZodMiniIntersection,
|
|
15
|
-
type ZodMiniLiteral,
|
|
16
|
-
type ZodMiniNever,
|
|
17
|
-
type ZodMiniNullable,
|
|
18
|
-
type ZodMiniNumber,
|
|
19
|
-
type ZodMiniObject,
|
|
20
|
-
type ZodMiniOptional,
|
|
21
|
-
type ZodMiniPipe,
|
|
22
|
-
type ZodMiniRecord,
|
|
23
|
-
type ZodMiniString,
|
|
24
|
-
type ZodMiniType,
|
|
25
|
-
type ZodMiniUnion,
|
|
26
|
-
} from '@zod/mini'
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
27
2
|
|
|
28
3
|
export type PrimitiveValueType = string | number | boolean | null
|
|
29
4
|
|
|
30
5
|
export type PrimitiveZodType =
|
|
31
|
-
| ZodMiniNever
|
|
32
|
-
| ZodMiniDefault
|
|
33
|
-
| ZodMiniNullable
|
|
34
|
-
| ZodMiniOptional
|
|
35
|
-
| ZodMiniString
|
|
36
|
-
| ZodMiniObject
|
|
37
|
-
| ZodMiniAny
|
|
38
|
-
| ZodMiniArray
|
|
39
|
-
| ZodMiniBoolean
|
|
40
|
-
| ZodMiniNumber
|
|
41
|
-
| ZodMiniEnum<any>
|
|
42
|
-
| ZodMiniLiteral<PrimitiveValueType>
|
|
43
|
-
| ZodMiniUnion
|
|
44
|
-
| ZodMiniIntersection
|
|
45
|
-
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export type ZodType = SimpleZodType | ZodMiniType
|
|
6
|
+
| zod.ZodMiniNever
|
|
7
|
+
| zod.ZodMiniDefault
|
|
8
|
+
| zod.ZodMiniNullable
|
|
9
|
+
| zod.ZodMiniOptional
|
|
10
|
+
| zod.ZodMiniString
|
|
11
|
+
| zod.ZodMiniObject
|
|
12
|
+
| zod.ZodMiniAny
|
|
13
|
+
| zod.ZodMiniArray
|
|
14
|
+
| zod.ZodMiniBoolean
|
|
15
|
+
| zod.ZodMiniNumber
|
|
16
|
+
| zod.ZodMiniEnum<any>
|
|
17
|
+
| zod.ZodMiniLiteral<PrimitiveValueType>
|
|
18
|
+
| zod.ZodMiniUnion
|
|
19
|
+
| zod.ZodMiniIntersection
|
|
20
|
+
| zod.ZodMiniRecord
|
|
21
|
+
|
|
22
|
+
export type SimpleZodType = zod.ZodMiniType
|
|
23
|
+
|
|
24
|
+
export type ZodType = SimpleZodType | zod.ZodMiniType
|
|
51
25
|
|
|
52
26
|
export type TypeProps = Record<string, any>
|
|
53
27
|
|
|
@@ -61,7 +35,7 @@ export type TypeMetadata<T = any> = {
|
|
|
61
35
|
export type TypeParams = {
|
|
62
36
|
encode?: (value: any) => any
|
|
63
37
|
metadata?: TypeMetadata
|
|
64
|
-
checks: Array<core.CheckFn<any> | core.$ZodCheck<any>>
|
|
38
|
+
checks: Array<zod.core.CheckFn<any> | zod.core.$ZodCheck<any>>
|
|
65
39
|
}
|
|
66
40
|
|
|
67
41
|
export type DefaultTypeParams = {
|
|
@@ -71,13 +45,13 @@ export type DefaultTypeParams = {
|
|
|
71
45
|
|
|
72
46
|
export type BaseTypeAny<
|
|
73
47
|
EncodedZodType extends SimpleZodType = SimpleZodType,
|
|
74
|
-
DecodedZodType extends ZodType = ZodMiniType,
|
|
48
|
+
DecodedZodType extends ZodType = zod.ZodMiniType,
|
|
75
49
|
> = BaseType<EncodedZodType, DecodedZodType, TypeProps>
|
|
76
50
|
|
|
77
|
-
export const typesRegistry = registry<TypeMetadata>()
|
|
51
|
+
export const typesRegistry = zod.registry<TypeMetadata>()
|
|
78
52
|
|
|
79
|
-
export const NeemataTypeError = core.$ZodError
|
|
80
|
-
export type NeemataTypeError = core.$ZodError
|
|
53
|
+
export const NeemataTypeError = zod.core.$ZodError
|
|
54
|
+
export type NeemataTypeError = zod.core.$ZodError
|
|
81
55
|
|
|
82
56
|
export abstract class BaseType<
|
|
83
57
|
EncodedZodType extends SimpleZodType = SimpleZodType,
|
|
@@ -162,13 +136,13 @@ export abstract class BaseType<
|
|
|
162
136
|
export class OptionalType<
|
|
163
137
|
Type extends BaseTypeAny = BaseTypeAny,
|
|
164
138
|
> extends BaseType<
|
|
165
|
-
ZodMiniOptional<Type['encodedZodType']>,
|
|
166
|
-
ZodMiniOptional<Type['decodedZodType']>,
|
|
139
|
+
zod.ZodMiniOptional<Type['encodedZodType']>,
|
|
140
|
+
zod.ZodMiniOptional<Type['decodedZodType']>,
|
|
167
141
|
{ inner: Type }
|
|
168
142
|
> {
|
|
169
143
|
static factory<T extends BaseTypeAny>(type: T) {
|
|
170
144
|
return new OptionalType<T>({
|
|
171
|
-
encodedZodType: optional(type.encodedZodType) as any,
|
|
145
|
+
encodedZodType: zod.optional(type.encodedZodType) as any,
|
|
172
146
|
props: { inner: type },
|
|
173
147
|
})
|
|
174
148
|
}
|
|
@@ -177,13 +151,13 @@ export class OptionalType<
|
|
|
177
151
|
export class NullableType<
|
|
178
152
|
Type extends BaseTypeAny<any> = BaseTypeAny<any>,
|
|
179
153
|
> extends BaseType<
|
|
180
|
-
ZodMiniNullable<Type['encodedZodType']>,
|
|
181
|
-
ZodMiniNullable<Type['decodedZodType']>,
|
|
154
|
+
zod.ZodMiniNullable<Type['encodedZodType']>,
|
|
155
|
+
zod.ZodMiniNullable<Type['decodedZodType']>,
|
|
182
156
|
{ inner: Type }
|
|
183
157
|
> {
|
|
184
158
|
static factory<T extends BaseTypeAny<any>>(type: T) {
|
|
185
159
|
return new NullableType<T>({
|
|
186
|
-
encodedZodType: nullable(type.encodedZodType),
|
|
160
|
+
encodedZodType: zod.nullable(type.encodedZodType),
|
|
187
161
|
props: { inner: type },
|
|
188
162
|
})
|
|
189
163
|
}
|
|
@@ -192,17 +166,17 @@ export class NullableType<
|
|
|
192
166
|
export class DefaultType<
|
|
193
167
|
Type extends BaseTypeAny = BaseTypeAny,
|
|
194
168
|
> extends BaseType<
|
|
195
|
-
ZodMiniDefault<Type['encodedZodType']>,
|
|
196
|
-
ZodMiniDefault<Type['decodedZodType']>,
|
|
169
|
+
zod.ZodMiniDefault<Type['encodedZodType']>,
|
|
170
|
+
zod.ZodMiniDefault<Type['decodedZodType']>,
|
|
197
171
|
{ inner: Type }
|
|
198
172
|
> {
|
|
199
173
|
static factory<T extends BaseTypeAny<any>>(type: T, defaultValue: any) {
|
|
200
174
|
return new DefaultType<T>({
|
|
201
|
-
encodedZodType: _default(
|
|
175
|
+
encodedZodType: zod._default(
|
|
202
176
|
type.encodedZodType,
|
|
203
177
|
type.params.encode?.(defaultValue) ?? defaultValue,
|
|
204
178
|
) as any,
|
|
205
|
-
decodedZodType: _default(type.decodedZodType, defaultValue) as any,
|
|
179
|
+
decodedZodType: zod._default(type.decodedZodType, defaultValue) as any,
|
|
206
180
|
props: { inner: type },
|
|
207
181
|
})
|
|
208
182
|
}
|
package/src/types/boolean.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
2
2
|
import { BaseType } from './base.ts'
|
|
3
3
|
|
|
4
|
-
export class BooleanType extends BaseType<ZodMiniBoolean<boolean>> {
|
|
4
|
+
export class BooleanType extends BaseType<zod.ZodMiniBoolean<boolean>> {
|
|
5
5
|
static factory() {
|
|
6
6
|
return new BooleanType({
|
|
7
|
-
encodedZodType: boolean(),
|
|
7
|
+
encodedZodType: zod.boolean(),
|
|
8
8
|
})
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
export const boolean = BooleanType.factory
|
package/src/types/custom.ts
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
any,
|
|
3
|
-
type core,
|
|
4
|
-
custom,
|
|
5
|
-
overwrite,
|
|
6
|
-
pipe,
|
|
7
|
-
refine,
|
|
8
|
-
type ZodMiniPipe,
|
|
9
|
-
type ZodMiniType,
|
|
10
|
-
} from '@zod/mini'
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
11
2
|
import { BaseType, type SimpleZodType, type ZodType } from './base.ts'
|
|
12
3
|
|
|
13
4
|
export type CustomTransformFn<I, O> = (value: I) => O
|
|
14
5
|
export abstract class TransformType<
|
|
15
6
|
Type,
|
|
16
|
-
EncodedType extends SimpleZodType = ZodMiniType<Type, Type>,
|
|
17
|
-
DecodedType extends ZodType = ZodMiniType<Type, Type>,
|
|
7
|
+
EncodedType extends SimpleZodType = zod.ZodMiniType<Type, Type>,
|
|
8
|
+
DecodedType extends ZodType = zod.ZodMiniType<Type, Type>,
|
|
18
9
|
> extends BaseType<
|
|
19
|
-
ZodMiniPipe<
|
|
20
|
-
ZodMiniType<
|
|
10
|
+
zod.ZodMiniPipe<
|
|
11
|
+
zod.ZodMiniType<
|
|
12
|
+
DecodedType['_zod']['output'],
|
|
13
|
+
DecodedType['_zod']['input']
|
|
14
|
+
>,
|
|
21
15
|
EncodedType
|
|
22
16
|
>,
|
|
23
|
-
ZodMiniPipe<
|
|
17
|
+
zod.ZodMiniPipe<
|
|
24
18
|
EncodedType,
|
|
25
|
-
ZodMiniType<EncodedType['_zod']['output'], EncodedType['_zod']['input']>
|
|
19
|
+
zod.ZodMiniType<EncodedType['_zod']['output'], EncodedType['_zod']['input']>
|
|
26
20
|
>
|
|
27
21
|
> {}
|
|
28
22
|
|
|
29
23
|
export class CustomType<
|
|
30
24
|
Type,
|
|
31
|
-
EncodedType extends SimpleZodType = ZodMiniType<Type, Type>,
|
|
32
|
-
DecodedType extends ZodType = ZodMiniType<Type, Type>,
|
|
25
|
+
EncodedType extends SimpleZodType = zod.ZodMiniType<Type, Type>,
|
|
26
|
+
DecodedType extends ZodType = zod.ZodMiniType<Type, Type>,
|
|
33
27
|
> extends TransformType<Type, EncodedType, DecodedType> {
|
|
34
28
|
static factory<
|
|
35
29
|
Type,
|
|
36
|
-
EncodedType extends SimpleZodType = ZodMiniType<Type, Type>,
|
|
37
|
-
DecodedType extends ZodType = ZodMiniType<Type, Type>,
|
|
30
|
+
EncodedType extends SimpleZodType = zod.ZodMiniType<Type, Type>,
|
|
31
|
+
DecodedType extends ZodType = zod.ZodMiniType<Type, Type>,
|
|
38
32
|
>({
|
|
39
33
|
decode,
|
|
40
34
|
encode,
|
|
41
35
|
error,
|
|
42
|
-
type = any() as unknown as EncodedType,
|
|
36
|
+
type = zod.any() as unknown as EncodedType,
|
|
43
37
|
}: {
|
|
44
38
|
decode: CustomTransformFn<
|
|
45
39
|
EncodedType['_zod']['input'],
|
|
@@ -49,25 +43,37 @@ export class CustomType<
|
|
|
49
43
|
DecodedType['_zod']['input'],
|
|
50
44
|
EncodedType['_zod']['output']
|
|
51
45
|
>
|
|
52
|
-
error?: string | core.$ZodErrorMap<core.$ZodIssueBase>
|
|
46
|
+
error?: string | zod.core.$ZodErrorMap<zod.core.$ZodIssueBase>
|
|
53
47
|
type?: EncodedType
|
|
54
48
|
}) {
|
|
55
49
|
return new CustomType<Type, EncodedType, DecodedType>({
|
|
56
|
-
encodedZodType: pipe(
|
|
57
|
-
custom().check(
|
|
58
|
-
refine((val) => typeof val !== 'undefined', {
|
|
59
|
-
|
|
50
|
+
encodedZodType: zod.pipe(
|
|
51
|
+
zod.custom().check(
|
|
52
|
+
zod.refine((val) => typeof val !== 'undefined', {
|
|
53
|
+
error,
|
|
54
|
+
abort: true,
|
|
55
|
+
}),
|
|
56
|
+
zod.overwrite(encode),
|
|
60
57
|
),
|
|
61
58
|
type,
|
|
62
59
|
),
|
|
63
|
-
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
decodedZodType: zod.pipe(
|
|
64
62
|
type,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
// @ts-expect-error
|
|
64
|
+
zod
|
|
65
|
+
.custom()
|
|
66
|
+
.check(
|
|
67
|
+
zod.refine((val) => typeof val !== 'undefined', {
|
|
68
|
+
error,
|
|
69
|
+
abort: true,
|
|
70
|
+
}),
|
|
71
|
+
zod.overwrite(decode),
|
|
72
|
+
),
|
|
69
73
|
),
|
|
70
74
|
params: { encode },
|
|
71
75
|
})
|
|
72
76
|
}
|
|
73
77
|
}
|
|
78
|
+
|
|
79
|
+
export const custom = CustomType.factory
|
package/src/types/date.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
2
2
|
import { CustomType, TransformType } from './custom.ts'
|
|
3
3
|
|
|
4
4
|
export class DateType extends TransformType<
|
|
5
5
|
Date,
|
|
6
|
-
ZodMiniUnion<[iso.ZodMiniISODate, iso.ZodMiniISODateTime]>
|
|
6
|
+
zod.ZodMiniUnion<[zod.iso.ZodMiniISODate, zod.iso.ZodMiniISODateTime]>
|
|
7
7
|
> {
|
|
8
8
|
static factory() {
|
|
9
9
|
return CustomType.factory<
|
|
10
10
|
Date,
|
|
11
|
-
ZodMiniUnion<
|
|
11
|
+
zod.ZodMiniUnion<
|
|
12
|
+
Array<zod.iso.ZodMiniISODate | zod.iso.ZodMiniISODateTime>
|
|
13
|
+
>
|
|
12
14
|
>({
|
|
13
15
|
decode: (value: string): Date => new Date(value),
|
|
14
16
|
encode: (value: Date): string => value.toISOString(),
|
|
15
|
-
type: union([iso.datetime(), iso.date()]),
|
|
17
|
+
type: zod.union([zod.iso.datetime(), zod.iso.date()]),
|
|
16
18
|
})
|
|
17
19
|
}
|
|
18
20
|
}
|
|
21
|
+
|
|
22
|
+
export const date = DateType.factory
|
package/src/types/enum.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
2
2
|
import { BaseType } from './base.ts'
|
|
3
3
|
|
|
4
4
|
export class EnumType<
|
|
5
|
-
T extends core.util.EnumLike = core.util.EnumLike,
|
|
6
|
-
> extends BaseType<ZodMiniEnum<T>, ZodMiniEnum<T>, { values: T }> {
|
|
7
|
-
static factory<T extends core.util.EnumLike>(values: T): EnumType<T>
|
|
5
|
+
T extends zod.core.util.EnumLike = zod.core.util.EnumLike,
|
|
6
|
+
> extends BaseType<zod.ZodMiniEnum<T>, zod.ZodMiniEnum<T>, { values: T }> {
|
|
7
|
+
static factory<T extends zod.core.util.EnumLike>(values: T): EnumType<T>
|
|
8
8
|
static factory<T extends string[]>(
|
|
9
9
|
values: T,
|
|
10
|
-
): EnumType<core.util.ToEnum<T[number]>>
|
|
11
|
-
static factory<T extends core.util.EnumLike | string[]>(values: T) {
|
|
10
|
+
): EnumType<zod.core.util.ToEnum<T[number]>>
|
|
11
|
+
static factory<T extends zod.core.util.EnumLike | string[]>(values: T) {
|
|
12
12
|
return new EnumType({
|
|
13
|
-
encodedZodType:
|
|
13
|
+
encodedZodType: zod.enum(values as any),
|
|
14
14
|
props: { values },
|
|
15
15
|
})
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
const _enum = EnumType.factory
|
|
20
|
+
|
|
21
|
+
export { _enum as enum }
|
package/src/types/literal.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
2
2
|
import { BaseType, type PrimitiveValueType } from './base.ts'
|
|
3
3
|
|
|
4
4
|
export class LiteralType<
|
|
5
5
|
T extends PrimitiveValueType = PrimitiveValueType,
|
|
6
|
-
> extends BaseType<ZodMiniLiteral<T>, ZodMiniLiteral<T>, { value: T }> {
|
|
6
|
+
> extends BaseType<zod.ZodMiniLiteral<T>, zod.ZodMiniLiteral<T>, { value: T }> {
|
|
7
7
|
static factory<T extends PrimitiveValueType>(value: T) {
|
|
8
8
|
return new LiteralType<T>({
|
|
9
|
-
encodedZodType: literal(value),
|
|
9
|
+
encodedZodType: zod.literal(value),
|
|
10
10
|
props: { value },
|
|
11
11
|
})
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
export const literal = LiteralType.factory
|
package/src/types/never.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
2
2
|
import { BaseType } from './base.ts'
|
|
3
3
|
|
|
4
|
-
export class NeverType extends BaseType<ZodMiniNever> {
|
|
4
|
+
export class NeverType extends BaseType<zod.ZodMiniNever> {
|
|
5
5
|
static factory() {
|
|
6
6
|
return new NeverType({
|
|
7
|
-
encodedZodType: never(),
|
|
7
|
+
encodedZodType: zod.never(),
|
|
8
8
|
})
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
export const never = NeverType.factory
|
package/src/types/number.ts
CHANGED
|
@@ -1,70 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
type core,
|
|
3
|
-
gt,
|
|
4
|
-
gte,
|
|
5
|
-
int,
|
|
6
|
-
lt,
|
|
7
|
-
lte,
|
|
8
|
-
number,
|
|
9
|
-
regex,
|
|
10
|
-
string,
|
|
11
|
-
type ZodMiniNumber,
|
|
12
|
-
type ZodMiniString,
|
|
13
|
-
} from '@zod/mini'
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
14
2
|
import { BaseType } from './base.ts'
|
|
15
3
|
import { CustomType, TransformType } from './custom.ts'
|
|
16
4
|
|
|
17
|
-
type Check = core.CheckFn<number> | core.$ZodCheck<number>
|
|
5
|
+
type Check = zod.core.CheckFn<number> | zod.core.$ZodCheck<number>
|
|
18
6
|
|
|
19
7
|
export class NumberType extends BaseType<
|
|
20
|
-
ZodMiniNumber<number>,
|
|
21
|
-
ZodMiniNumber<number>
|
|
8
|
+
zod.ZodMiniNumber<number>,
|
|
9
|
+
zod.ZodMiniNumber<number>
|
|
22
10
|
> {
|
|
23
11
|
static factory(...checks: Check[]) {
|
|
24
12
|
return new NumberType({
|
|
25
|
-
encodedZodType: number().check(...checks),
|
|
13
|
+
encodedZodType: zod.number().check(...checks),
|
|
26
14
|
params: { checks },
|
|
27
15
|
})
|
|
28
16
|
}
|
|
29
17
|
|
|
30
18
|
positive() {
|
|
31
|
-
return NumberType.factory(...this.params.checks, gte(0))
|
|
19
|
+
return NumberType.factory(...this.params.checks, zod.gte(0))
|
|
32
20
|
}
|
|
33
21
|
|
|
34
22
|
negative() {
|
|
35
|
-
return NumberType.factory(...this.params.checks, lte(0))
|
|
23
|
+
return NumberType.factory(...this.params.checks, zod.lte(0))
|
|
36
24
|
}
|
|
37
25
|
|
|
38
26
|
lt(value: number) {
|
|
39
|
-
return NumberType.factory(...this.params.checks, lt(value))
|
|
27
|
+
return NumberType.factory(...this.params.checks, zod.lt(value))
|
|
40
28
|
}
|
|
41
29
|
|
|
42
30
|
lte(value: number) {
|
|
43
|
-
return NumberType.factory(...this.params.checks, lte(value))
|
|
31
|
+
return NumberType.factory(...this.params.checks, zod.lte(value))
|
|
44
32
|
}
|
|
45
33
|
|
|
46
34
|
gte(value: number) {
|
|
47
|
-
return NumberType.factory(...this.params.checks, gte(value))
|
|
35
|
+
return NumberType.factory(...this.params.checks, zod.gte(value))
|
|
48
36
|
}
|
|
49
37
|
|
|
50
38
|
gt(value: number) {
|
|
51
|
-
return NumberType.factory(...this.params.checks, gt(value))
|
|
39
|
+
return NumberType.factory(...this.params.checks, zod.gt(value))
|
|
52
40
|
}
|
|
53
41
|
}
|
|
54
42
|
|
|
55
43
|
export class IntegerType extends NumberType {
|
|
56
44
|
static factory(...checks: Check[]) {
|
|
57
|
-
return NumberType.factory(...checks, int())
|
|
45
|
+
return NumberType.factory(...checks, zod.int())
|
|
58
46
|
}
|
|
59
47
|
}
|
|
60
48
|
|
|
61
|
-
export class BigIntType extends TransformType<
|
|
49
|
+
export class BigIntType extends TransformType<
|
|
50
|
+
bigint,
|
|
51
|
+
zod.ZodMiniString<string>
|
|
52
|
+
> {
|
|
62
53
|
static factory() {
|
|
63
|
-
return CustomType.factory<bigint, ZodMiniString<string>>({
|
|
54
|
+
return CustomType.factory<bigint, zod.ZodMiniString<string>>({
|
|
64
55
|
decode: (value) => BigInt(value),
|
|
65
56
|
encode: (value) => value.toString(),
|
|
66
|
-
type: string().check(regex(/^-?\d+$/)),
|
|
57
|
+
type: zod.string().check(zod.regex(/^-?\d+$/)),
|
|
67
58
|
error: 'Invalid bigint format',
|
|
68
59
|
})
|
|
69
60
|
}
|
|
70
61
|
}
|
|
62
|
+
|
|
63
|
+
export const number = NumberType.factory
|
|
64
|
+
export const integer = IntegerType.factory
|
|
65
|
+
export const bigInt = BigIntType.factory
|
package/src/types/object.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
type core,
|
|
3
|
-
object,
|
|
4
|
-
record,
|
|
5
|
-
strictObject,
|
|
6
|
-
type ZodMiniObject,
|
|
7
|
-
type ZodMiniRecord,
|
|
8
|
-
} from '@zod/mini'
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
9
2
|
|
|
10
3
|
import { BaseType, type BaseTypeAny, type OptionalType } from './base.ts'
|
|
11
4
|
import { EnumType } from './enum.ts'
|
|
@@ -15,8 +8,14 @@ import type { StringType } from './string.ts'
|
|
|
15
8
|
export type ObjectTypeProps = { [k: string]: BaseTypeAny }
|
|
16
9
|
export type AnyObjectType = ObjectType<ObjectTypeProps>
|
|
17
10
|
export class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<
|
|
18
|
-
ZodMiniObject<
|
|
19
|
-
|
|
11
|
+
zod.ZodMiniObject<
|
|
12
|
+
{ [K in keyof T]: T[K]['encodedZodType'] },
|
|
13
|
+
zod.core.$strict
|
|
14
|
+
>,
|
|
15
|
+
zod.ZodMiniObject<
|
|
16
|
+
{ [K in keyof T]: T[K]['decodedZodType'] },
|
|
17
|
+
zod.core.$strict
|
|
18
|
+
>,
|
|
20
19
|
{ properties: T }
|
|
21
20
|
> {
|
|
22
21
|
static factory<T extends ObjectTypeProps = {}>(properties: T) {
|
|
@@ -33,8 +32,8 @@ export class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
return new ObjectType<T>({
|
|
36
|
-
encodedZodType: object(encodeProperties),
|
|
37
|
-
decodedZodType: object(decodeProperties),
|
|
35
|
+
encodedZodType: zod.object(encodeProperties),
|
|
36
|
+
decodedZodType: zod.object(decodeProperties),
|
|
38
37
|
props: { properties },
|
|
39
38
|
})
|
|
40
39
|
}
|
|
@@ -44,19 +43,19 @@ export class RecordType<
|
|
|
44
43
|
K extends LiteralType<string | number> | EnumType | StringType,
|
|
45
44
|
E extends BaseType,
|
|
46
45
|
> extends BaseType<
|
|
47
|
-
ZodMiniRecord<K['encodedZodType'], E['encodedZodType']>,
|
|
48
|
-
ZodMiniRecord<K['decodedZodType'], E['decodedZodType']>
|
|
46
|
+
zod.ZodMiniRecord<K['encodedZodType'], E['encodedZodType']>,
|
|
47
|
+
zod.ZodMiniRecord<K['decodedZodType'], E['decodedZodType']>
|
|
49
48
|
> {
|
|
50
49
|
static factory<
|
|
51
50
|
K extends LiteralType<string | number> | EnumType | StringType,
|
|
52
51
|
E extends BaseType,
|
|
53
52
|
>(key: K, element: E) {
|
|
54
53
|
return new RecordType<K, E>({
|
|
55
|
-
encodedZodType: record(
|
|
54
|
+
encodedZodType: zod.record(
|
|
56
55
|
(key as any).encodedZodType,
|
|
57
56
|
element.encodedZodType,
|
|
58
57
|
),
|
|
59
|
-
decodedZodType: record(
|
|
58
|
+
decodedZodType: zod.record(
|
|
60
59
|
(key as any).decodedZodType,
|
|
61
60
|
element.decodedZodType,
|
|
62
61
|
),
|
|
@@ -67,7 +66,9 @@ export class RecordType<
|
|
|
67
66
|
|
|
68
67
|
export function keyof<T extends ObjectType>(
|
|
69
68
|
type: T,
|
|
70
|
-
): EnumType<
|
|
69
|
+
): EnumType<
|
|
70
|
+
zod.core.util.ToEnum<Extract<keyof T['props']['properties'], string>>
|
|
71
|
+
> {
|
|
71
72
|
return EnumType.factory(Object.keys(type.props.properties) as any)
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -157,3 +158,6 @@ export function partial<
|
|
|
157
158
|
|
|
158
159
|
return ObjectType.factory(properties)
|
|
159
160
|
}
|
|
161
|
+
|
|
162
|
+
export const object = ObjectType.factory
|
|
163
|
+
export const record = RecordType.factory
|
package/src/types/string.ts
CHANGED
|
@@ -1,94 +1,78 @@
|
|
|
1
|
-
import
|
|
2
|
-
type core,
|
|
3
|
-
cuid,
|
|
4
|
-
cuid2,
|
|
5
|
-
e164,
|
|
6
|
-
email,
|
|
7
|
-
emoji,
|
|
8
|
-
ipv4,
|
|
9
|
-
ipv6,
|
|
10
|
-
jwt,
|
|
11
|
-
maxLength,
|
|
12
|
-
minLength,
|
|
13
|
-
nanoid,
|
|
14
|
-
regex,
|
|
15
|
-
string,
|
|
16
|
-
url,
|
|
17
|
-
uuid,
|
|
18
|
-
type ZodMiniString,
|
|
19
|
-
} from '@zod/mini'
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
20
2
|
|
|
21
3
|
import { BaseType } from './base.ts'
|
|
22
4
|
|
|
23
|
-
type Check = core.CheckFn<string> | core.$ZodCheck<string>
|
|
5
|
+
type Check = zod.core.CheckFn<string> | zod.core.$ZodCheck<string>
|
|
24
6
|
|
|
25
7
|
export class StringType extends BaseType<
|
|
26
|
-
ZodMiniString<string>,
|
|
27
|
-
ZodMiniString<string>
|
|
8
|
+
zod.ZodMiniString<string>,
|
|
9
|
+
zod.ZodMiniString<string>
|
|
28
10
|
> {
|
|
29
11
|
static factory(...checks: Check[]) {
|
|
30
12
|
return new StringType({
|
|
31
|
-
encodedZodType: string().check(...checks),
|
|
13
|
+
encodedZodType: zod.string().check(...checks),
|
|
32
14
|
params: { checks },
|
|
33
15
|
})
|
|
34
16
|
}
|
|
35
17
|
|
|
36
18
|
max(value: number) {
|
|
37
|
-
return StringType.factory(...this.params.checks, maxLength(value))
|
|
19
|
+
return StringType.factory(...this.params.checks, zod.maxLength(value))
|
|
38
20
|
}
|
|
39
21
|
|
|
40
22
|
min(value: number) {
|
|
41
|
-
return StringType.factory(...this.params.checks, minLength(value))
|
|
23
|
+
return StringType.factory(...this.params.checks, zod.minLength(value))
|
|
42
24
|
}
|
|
43
25
|
|
|
44
26
|
pattern(pattern: string | RegExp) {
|
|
45
27
|
return StringType.factory(
|
|
46
28
|
...this.params.checks,
|
|
47
|
-
regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern),
|
|
29
|
+
zod.regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern),
|
|
48
30
|
)
|
|
49
31
|
}
|
|
50
32
|
|
|
51
|
-
email(options?: core.$ZodEmailParams) {
|
|
52
|
-
return StringType.factory(...this.params.checks, email(options))
|
|
33
|
+
email(options?: zod.core.$ZodEmailParams) {
|
|
34
|
+
return StringType.factory(...this.params.checks, zod.email(options))
|
|
53
35
|
}
|
|
54
36
|
|
|
55
|
-
url(options?: core.$ZodURLParams) {
|
|
56
|
-
return StringType.factory(...this.params.checks, url(options))
|
|
37
|
+
url(options?: zod.core.$ZodURLParams) {
|
|
38
|
+
return StringType.factory(...this.params.checks, zod.url(options))
|
|
57
39
|
}
|
|
58
40
|
|
|
59
|
-
ipv4(options?: core.$ZodIPv4Params) {
|
|
60
|
-
return StringType.factory(...this.params.checks, ipv4(options))
|
|
41
|
+
ipv4(options?: zod.core.$ZodIPv4Params) {
|
|
42
|
+
return StringType.factory(...this.params.checks, zod.ipv4(options))
|
|
61
43
|
}
|
|
62
44
|
|
|
63
|
-
ipv6(options?: core.$ZodIPv6Params) {
|
|
64
|
-
return StringType.factory(...this.params.checks, ipv6(options))
|
|
45
|
+
ipv6(options?: zod.core.$ZodIPv6Params) {
|
|
46
|
+
return StringType.factory(...this.params.checks, zod.ipv6(options))
|
|
65
47
|
}
|
|
66
48
|
|
|
67
|
-
uuid(options?: core.$ZodUUIDParams) {
|
|
68
|
-
return StringType.factory(...this.params.checks, uuid(options))
|
|
49
|
+
uuid(options?: zod.core.$ZodUUIDParams) {
|
|
50
|
+
return StringType.factory(...this.params.checks, zod.uuid(options))
|
|
69
51
|
}
|
|
70
52
|
|
|
71
|
-
emoji(options?: core.$ZodEmojiParams) {
|
|
72
|
-
return StringType.factory(...this.params.checks, emoji(options))
|
|
53
|
+
emoji(options?: zod.core.$ZodEmojiParams) {
|
|
54
|
+
return StringType.factory(...this.params.checks, zod.emoji(options))
|
|
73
55
|
}
|
|
74
56
|
|
|
75
|
-
nanoid(options?: core.$ZodNanoIDParams) {
|
|
76
|
-
return StringType.factory(...this.params.checks, nanoid(options))
|
|
57
|
+
nanoid(options?: zod.core.$ZodNanoIDParams) {
|
|
58
|
+
return StringType.factory(...this.params.checks, zod.nanoid(options))
|
|
77
59
|
}
|
|
78
60
|
|
|
79
|
-
cuid(options?: core.$ZodCUIDParams) {
|
|
80
|
-
return StringType.factory(...this.params.checks, cuid(options))
|
|
61
|
+
cuid(options?: zod.core.$ZodCUIDParams) {
|
|
62
|
+
return StringType.factory(...this.params.checks, zod.cuid(options))
|
|
81
63
|
}
|
|
82
64
|
|
|
83
|
-
cuid2(options?: core.$ZodCUID2Params) {
|
|
84
|
-
return StringType.factory(...this.params.checks, cuid2(options))
|
|
65
|
+
cuid2(options?: zod.core.$ZodCUID2Params) {
|
|
66
|
+
return StringType.factory(...this.params.checks, zod.cuid2(options))
|
|
85
67
|
}
|
|
86
68
|
|
|
87
|
-
e164(options?: core.$ZodE164Params) {
|
|
88
|
-
return StringType.factory(...this.params.checks, e164(options))
|
|
69
|
+
e164(options?: zod.core.$ZodE164Params) {
|
|
70
|
+
return StringType.factory(...this.params.checks, zod.e164(options))
|
|
89
71
|
}
|
|
90
72
|
|
|
91
|
-
jwt(options?: core.$ZodJWTParams) {
|
|
92
|
-
return StringType.factory(...this.params.checks, jwt(options))
|
|
73
|
+
jwt(options?: zod.core.$ZodJWTParams) {
|
|
74
|
+
return StringType.factory(...this.params.checks, zod.jwt(options))
|
|
93
75
|
}
|
|
94
76
|
}
|
|
77
|
+
|
|
78
|
+
export const string = StringType.factory
|