@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/temporal.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iso, regex, string, type ZodMiniString } from '@zod/mini'
|
|
2
1
|
import { Temporal } from 'temporal-polyfill'
|
|
2
|
+
import { iso, regex, string, type ZodMiniString } from 'zod/v4-mini'
|
|
3
3
|
import { CustomType, TransformType } from './custom.ts'
|
|
4
4
|
|
|
5
5
|
type Types = Exclude<
|
|
@@ -144,3 +144,11 @@ export class PlainMonthDayType extends TransformType<
|
|
|
144
144
|
})
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
+
|
|
148
|
+
export const plainDate = PlainDateType.factory
|
|
149
|
+
export const plainDatetime = PlainDateTimeType.factory
|
|
150
|
+
export const plainTime = PlainTimeType.factory
|
|
151
|
+
export const zonedDatetime = ZonedDateTimeType.factory
|
|
152
|
+
export const duration = DurationType.factory
|
|
153
|
+
export const plainYearMonth = PlainYearMonthType.factory
|
|
154
|
+
export const plainMonthDay = PlainMonthDayType.factory
|
package/src/types/tuple.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArrayMap } from '@nmtjs/common'
|
|
2
|
-
import
|
|
2
|
+
import * as zod from 'zod/v4-mini'
|
|
3
3
|
import { BaseType } from './base.ts'
|
|
4
4
|
|
|
5
5
|
export class TupleType<
|
|
@@ -10,11 +10,11 @@ export class TupleType<
|
|
|
10
10
|
R extends BaseType | null = BaseType | null,
|
|
11
11
|
> extends BaseType<
|
|
12
12
|
R extends BaseType
|
|
13
|
-
? ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, R['encodedZodType']>
|
|
14
|
-
: ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, null>,
|
|
13
|
+
? zod.ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, R['encodedZodType']>
|
|
14
|
+
: zod.ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, null>,
|
|
15
15
|
R extends BaseType
|
|
16
|
-
? ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, R['decodedZodType']>
|
|
17
|
-
: ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, null>,
|
|
16
|
+
? zod.ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, R['decodedZodType']>
|
|
17
|
+
: zod.ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, null>,
|
|
18
18
|
{ elements: T; rest?: R }
|
|
19
19
|
> {
|
|
20
20
|
static factory<
|
|
@@ -25,10 +25,12 @@ export class TupleType<
|
|
|
25
25
|
const decoded = elements.map((el) => el.decodedZodType)
|
|
26
26
|
return new TupleType<T, R>({
|
|
27
27
|
// @ts-expect-error
|
|
28
|
-
encodedZodType: tuple(encoded, rest?.encodedZodType),
|
|
28
|
+
encodedZodType: zod.tuple(encoded, rest?.encodedZodType),
|
|
29
29
|
// @ts-expect-error
|
|
30
|
-
decodedZodType: tuple(decoded, rest?.decodedZodType),
|
|
30
|
+
decodedZodType: zod.tuple(decoded, rest?.decodedZodType),
|
|
31
31
|
props: { elements, rest },
|
|
32
32
|
})
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
export const tuple = TupleType.factory
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BaseTypeAny } from './base.ts'
|
|
2
|
+
|
|
3
|
+
export * from './any.ts'
|
|
4
|
+
export * from './array.ts'
|
|
5
|
+
export * from './boolean.ts'
|
|
6
|
+
export * from './custom.ts'
|
|
7
|
+
export * from './date.ts'
|
|
8
|
+
export * from './enum.ts'
|
|
9
|
+
export * from './literal.ts'
|
|
10
|
+
export * from './never.ts'
|
|
11
|
+
export * from './number.ts'
|
|
12
|
+
export * from './object.ts'
|
|
13
|
+
export * from './string.ts'
|
|
14
|
+
export * from './tuple.ts'
|
|
15
|
+
export * from './union.ts'
|
|
16
|
+
|
|
17
|
+
export namespace infer {
|
|
18
|
+
export namespace decoded {
|
|
19
|
+
export type input<T extends BaseTypeAny> =
|
|
20
|
+
T['decodedZodType']['_zod']['input']
|
|
21
|
+
export type output<T extends BaseTypeAny> =
|
|
22
|
+
T['decodedZodType']['_zod']['output']
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export namespace encoded {
|
|
26
|
+
export type input<T extends BaseTypeAny> =
|
|
27
|
+
T['encodedZodType']['_zod']['input']
|
|
28
|
+
export type output<T extends BaseTypeAny> =
|
|
29
|
+
T['encodedZodType']['_zod']['output']
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/types/union.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import type { ArrayMap } from '@nmtjs/common'
|
|
2
|
-
import
|
|
3
|
-
type core,
|
|
4
|
-
discriminatedUnion,
|
|
5
|
-
intersection,
|
|
6
|
-
union,
|
|
7
|
-
type ZodMiniDiscriminatedUnion,
|
|
8
|
-
type ZodMiniIntersection,
|
|
9
|
-
type ZodMiniUnion,
|
|
10
|
-
} from '@zod/mini'
|
|
2
|
+
import * as zod from 'zod/v4-mini'
|
|
11
3
|
import { BaseType, type BaseTypeAny } from './base.ts'
|
|
12
4
|
import type { LiteralType } from './literal.ts'
|
|
13
5
|
import type { ObjectType, ObjectTypeProps } from './object.ts'
|
|
@@ -18,8 +10,8 @@ export class UnionType<
|
|
|
18
10
|
...BaseType[],
|
|
19
11
|
],
|
|
20
12
|
> extends BaseType<
|
|
21
|
-
ZodMiniUnion<ArrayMap<T, 'encodedZodType'>>,
|
|
22
|
-
ZodMiniUnion<ArrayMap<T, 'decodedZodType'>>,
|
|
13
|
+
zod.ZodMiniUnion<ArrayMap<T, 'encodedZodType'>>,
|
|
14
|
+
zod.ZodMiniUnion<ArrayMap<T, 'decodedZodType'>>,
|
|
23
15
|
{ options: T }
|
|
24
16
|
> {
|
|
25
17
|
static factory<
|
|
@@ -37,8 +29,8 @@ export class UnionType<
|
|
|
37
29
|
'decodedZodType'
|
|
38
30
|
>
|
|
39
31
|
return new UnionType<T>({
|
|
40
|
-
encodedZodType: union(encoded),
|
|
41
|
-
decodedZodType: union(decoded),
|
|
32
|
+
encodedZodType: zod.union(encoded),
|
|
33
|
+
decodedZodType: zod.union(decoded),
|
|
42
34
|
props: { options },
|
|
43
35
|
})
|
|
44
36
|
}
|
|
@@ -47,8 +39,8 @@ export class UnionType<
|
|
|
47
39
|
export class IntersactionType<
|
|
48
40
|
T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],
|
|
49
41
|
> extends BaseType<
|
|
50
|
-
ZodMiniIntersection<T[0]['encodedZodType'], T[1]['encodedZodType']>,
|
|
51
|
-
ZodMiniIntersection<T[0]['decodedZodType'], T[1]['decodedZodType']>,
|
|
42
|
+
zod.ZodMiniIntersection<T[0]['encodedZodType'], T[1]['encodedZodType']>,
|
|
43
|
+
zod.ZodMiniIntersection<T[0]['decodedZodType'], T[1]['decodedZodType']>,
|
|
52
44
|
{ options: T }
|
|
53
45
|
> {
|
|
54
46
|
static factory<
|
|
@@ -56,8 +48,14 @@ export class IntersactionType<
|
|
|
56
48
|
>(...options: T) {
|
|
57
49
|
const [first, second] = options
|
|
58
50
|
return new IntersactionType<T>({
|
|
59
|
-
encodedZodType: intersection(
|
|
60
|
-
|
|
51
|
+
encodedZodType: zod.intersection(
|
|
52
|
+
first.encodedZodType,
|
|
53
|
+
second.encodedZodType,
|
|
54
|
+
),
|
|
55
|
+
decodedZodType: zod.intersection(
|
|
56
|
+
first.decodedZodType,
|
|
57
|
+
second.decodedZodType,
|
|
58
|
+
),
|
|
61
59
|
props: { options },
|
|
62
60
|
})
|
|
63
61
|
}
|
|
@@ -78,8 +76,8 @@ export class DiscriminatedUnionType<
|
|
|
78
76
|
T extends
|
|
79
77
|
readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],
|
|
80
78
|
> extends BaseType<
|
|
81
|
-
ZodMiniDiscriminatedUnion<ArrayMap<T, 'encodedZodType'>>,
|
|
82
|
-
ZodMiniDiscriminatedUnion<ArrayMap<T, 'decodedZodType'>>,
|
|
79
|
+
zod.ZodMiniDiscriminatedUnion<ArrayMap<T, 'encodedZodType'>>,
|
|
80
|
+
zod.ZodMiniDiscriminatedUnion<ArrayMap<T, 'decodedZodType'>>,
|
|
83
81
|
{
|
|
84
82
|
key: K
|
|
85
83
|
options: T
|
|
@@ -100,10 +98,16 @@ export class DiscriminatedUnionType<
|
|
|
100
98
|
>
|
|
101
99
|
return new DiscriminatedUnionType<K, T>({
|
|
102
100
|
// @ts-expect-error
|
|
103
|
-
encodedZodType: discriminatedUnion(encoded),
|
|
101
|
+
encodedZodType: zod.discriminatedUnion(key, encoded),
|
|
104
102
|
// @ts-expect-error
|
|
105
|
-
decodedZodType: discriminatedUnion(decoded),
|
|
103
|
+
decodedZodType: zod.discriminatedUnion(key, decoded),
|
|
106
104
|
props: { key, options },
|
|
107
105
|
})
|
|
108
106
|
}
|
|
109
107
|
}
|
|
108
|
+
|
|
109
|
+
export const union = UnionType.factory
|
|
110
|
+
export const or = UnionType.factory
|
|
111
|
+
export const intersection = IntersactionType.factory
|
|
112
|
+
export const and = IntersactionType.factory
|
|
113
|
+
export const discriminatedUnion = DiscriminatedUnionType.factory
|