@nmtjs/type 0.6.4 → 0.7.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.
- package/dist/index.js +31 -31
- package/dist/index.js.map +1 -1
- package/dist/temporal.js +7 -8
- package/dist/temporal.js.map +1 -1
- package/dist/types/any.js +4 -4
- package/dist/types/any.js.map +1 -1
- package/dist/types/array.js +23 -23
- package/dist/types/array.js.map +1 -1
- package/dist/types/base.js +65 -66
- package/dist/types/base.js.map +1 -1
- package/dist/types/boolean.js +4 -4
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/custom.js +10 -9
- package/dist/types/custom.js.map +1 -1
- package/dist/types/date.js +6 -13
- package/dist/types/date.js.map +1 -1
- package/dist/types/enum.js +7 -16
- package/dist/types/enum.js.map +1 -1
- package/dist/types/literal.js +7 -6
- package/dist/types/literal.js.map +1 -1
- package/dist/types/never.js +4 -4
- package/dist/types/never.js.map +1 -1
- package/dist/types/number.js +26 -93
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +42 -31
- package/dist/types/object.js.map +1 -1
- package/dist/types/string.js +31 -47
- package/dist/types/string.js.map +1 -1
- package/dist/types/temporal.js +40 -41
- package/dist/types/temporal.js.map +1 -1
- package/dist/types/union.js +25 -18
- package/dist/types/union.js.map +1 -1
- package/dist/utils.js +0 -1
- package/dist/utils.js.map +1 -1
- package/package.json +7 -19
- package/src/index.ts +24 -25
- package/src/temporal.ts +8 -8
- package/src/types/any.ts +5 -3
- package/src/types/array.ts +24 -22
- package/src/types/base.ts +148 -81
- package/src/types/boolean.ts +5 -3
- package/src/types/custom.ts +43 -24
- package/src/types/date.ts +17 -16
- package/src/types/enum.ts +12 -22
- package/src/types/literal.ts +9 -6
- package/src/types/never.ts +5 -3
- package/src/types/number.ts +31 -93
- package/src/types/object.ts +44 -37
- package/src/types/string.ts +41 -39
- package/src/types/temporal.ts +72 -32
- package/src/types/union.ts +59 -50
- package/src/utils.ts +22 -22
- package/dist/compiler.js +0 -55
- package/dist/compiler.js.map +0 -1
- package/dist/formats.js +0 -127
- package/dist/formats.js.map +0 -1
- package/dist/inference.js +0 -1
- package/dist/inference.js.map +0 -1
- package/dist/parse.js +0 -145
- package/dist/parse.js.map +0 -1
- package/dist/runtime.js +0 -73
- package/dist/runtime.js.map +0 -1
- package/dist/schemas/default.js +0 -6
- package/dist/schemas/default.js.map +0 -1
- package/dist/schemas/discriminated-union.js +0 -9
- package/dist/schemas/discriminated-union.js.map +0 -1
- package/dist/schemas/nullable.js +0 -11
- package/dist/schemas/nullable.js.map +0 -1
- package/src/compiler.ts +0 -100
- package/src/formats.ts +0 -182
- package/src/inference.ts +0 -128
- package/src/parse.ts +0 -217
- package/src/runtime.ts +0 -137
- package/src/schemas/default.ts +0 -12
- package/src/schemas/discriminated-union.ts +0 -49
- package/src/schemas/nullable.ts +0 -20
package/src/types/enum.ts
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type core, enum as enum_, type ZodMiniEnum } from '@zod/mini'
|
|
2
2
|
import { BaseType } from './base.ts'
|
|
3
3
|
|
|
4
|
-
export class ObjectEnumType<
|
|
5
|
-
T extends { [K in string]: K } = { [K in string]: K },
|
|
6
|
-
> extends BaseType<TEnum<T>, { values: T[keyof T] }, T[keyof T]> {
|
|
7
|
-
static factory<T extends { [K in string]: K }>(values: T) {
|
|
8
|
-
return new ObjectEnumType<T>(Type.Enum(values as any), {
|
|
9
|
-
values: Object.values(values) as unknown as T[keyof T],
|
|
10
|
-
})
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
4
|
export class EnumType<
|
|
15
|
-
T extends
|
|
16
|
-
> extends BaseType<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
static factory<T extends
|
|
22
|
-
return new EnumType
|
|
23
|
-
|
|
24
|
-
{ values },
|
|
25
|
-
)
|
|
5
|
+
T extends core.utils.EnumLike = core.utils.EnumLike,
|
|
6
|
+
> extends BaseType<ZodMiniEnum<T>, ZodMiniEnum<T>, { values: T }> {
|
|
7
|
+
static factory<T extends core.utils.EnumLike>(values: T): EnumType<T>
|
|
8
|
+
static factory<T extends string[]>(
|
|
9
|
+
values: T,
|
|
10
|
+
): EnumType<core.utils.ToEnum<T[number]>>
|
|
11
|
+
static factory<T extends core.utils.EnumLike | string[]>(values: T) {
|
|
12
|
+
return new EnumType({
|
|
13
|
+
encodedZodType: enum_(values as any),
|
|
14
|
+
props: { values },
|
|
15
|
+
})
|
|
26
16
|
}
|
|
27
17
|
}
|
package/src/types/literal.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseType } from './base.ts'
|
|
1
|
+
import { literal, type ZodMiniLiteral } from '@zod/mini'
|
|
2
|
+
import { BaseType, type PrimitiveValueType } from './base.ts'
|
|
3
3
|
|
|
4
4
|
export class LiteralType<
|
|
5
|
-
T extends
|
|
6
|
-
> extends BaseType<
|
|
7
|
-
static factory<T extends
|
|
8
|
-
return new LiteralType<T>(
|
|
5
|
+
T extends PrimitiveValueType = PrimitiveValueType,
|
|
6
|
+
> extends BaseType<ZodMiniLiteral<T>, ZodMiniLiteral<T>, { value: T }> {
|
|
7
|
+
static factory<T extends PrimitiveValueType>(value: T) {
|
|
8
|
+
return new LiteralType<T>({
|
|
9
|
+
encodedZodType: literal(value),
|
|
10
|
+
props: { value },
|
|
11
|
+
})
|
|
9
12
|
}
|
|
10
13
|
}
|
package/src/types/never.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { never, type ZodMiniNever } from '@zod/mini'
|
|
2
2
|
import { BaseType } from './base.ts'
|
|
3
3
|
|
|
4
|
-
export class NeverType extends BaseType<
|
|
4
|
+
export class NeverType extends BaseType<ZodMiniNever> {
|
|
5
5
|
static factory() {
|
|
6
|
-
return new NeverType(
|
|
6
|
+
return new NeverType({
|
|
7
|
+
encodedZodType: never(),
|
|
8
|
+
})
|
|
7
9
|
}
|
|
8
10
|
}
|
package/src/types/number.ts
CHANGED
|
@@ -1,117 +1,55 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
type core,
|
|
3
|
+
gt,
|
|
4
|
+
gte,
|
|
5
|
+
int,
|
|
6
|
+
lt,
|
|
7
|
+
lte,
|
|
8
|
+
number,
|
|
9
|
+
type ZodMiniNumber,
|
|
10
|
+
} from '@zod/mini'
|
|
10
11
|
import { BaseType } from './base.ts'
|
|
11
12
|
|
|
13
|
+
type Check = core.CheckFn<number> | core.$ZodCheck<number>
|
|
14
|
+
|
|
12
15
|
export class NumberType extends BaseType<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
ZodMiniNumber<number>,
|
|
17
|
+
ZodMiniNumber<number>,
|
|
18
|
+
{ checks: Check[] }
|
|
16
19
|
> {
|
|
17
|
-
static factory(
|
|
18
|
-
return new NumberType(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
positive() {
|
|
22
|
-
return this.min(0, true)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
negative() {
|
|
26
|
-
return this.max(0, true)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
max(value: number, exclusive?: true) {
|
|
30
|
-
return NumberType.factory({
|
|
31
|
-
...this.props.options,
|
|
32
|
-
maximum: value,
|
|
33
|
-
...(!exclusive ? {} : { exclusiveMaximum: value }),
|
|
20
|
+
static factory(...checks: Check[]) {
|
|
21
|
+
return new NumberType({
|
|
22
|
+
encodedZodType: number().check(...checks),
|
|
34
23
|
})
|
|
35
24
|
}
|
|
36
25
|
|
|
37
|
-
min(value: number, exclusive?: true) {
|
|
38
|
-
return NumberType.factory({
|
|
39
|
-
...this.props.options,
|
|
40
|
-
minimum: value,
|
|
41
|
-
...(!exclusive ? {} : { exclusiveMinimum: value }),
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export class IntegerType extends BaseType<
|
|
47
|
-
TInteger,
|
|
48
|
-
{ options: IntegerOptions },
|
|
49
|
-
number
|
|
50
|
-
> {
|
|
51
|
-
static factory(options: IntegerOptions = {}) {
|
|
52
|
-
return new IntegerType(Type.Integer(options), { options })
|
|
53
|
-
}
|
|
54
|
-
|
|
55
26
|
positive() {
|
|
56
|
-
return this.
|
|
27
|
+
return NumberType.factory(...this.props.checks, gte(0))
|
|
57
28
|
}
|
|
58
29
|
|
|
59
30
|
negative() {
|
|
60
|
-
return this.
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
max(value: number, exclusive?: true) {
|
|
64
|
-
return IntegerType.factory({
|
|
65
|
-
...this.props.options,
|
|
66
|
-
maximum: value,
|
|
67
|
-
...(!exclusive ? {} : { exclusiveMaximum: value }),
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
min(value: number, exclusive?: true) {
|
|
72
|
-
return IntegerType.factory({
|
|
73
|
-
...this.props.options,
|
|
74
|
-
minimum: value,
|
|
75
|
-
...(!exclusive ? {} : { exclusiveMinimum: value }),
|
|
76
|
-
})
|
|
31
|
+
return NumberType.factory(...this.props.checks, lte(0))
|
|
77
32
|
}
|
|
78
|
-
}
|
|
79
33
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
TBigInt,
|
|
83
|
-
{ options: BigIntOptions },
|
|
84
|
-
bigint
|
|
85
|
-
> {
|
|
86
|
-
static factory(options: BigIntOptions = {}) {
|
|
87
|
-
return new BigIntType(
|
|
88
|
-
Type.BigInt(options),
|
|
89
|
-
{ options },
|
|
90
|
-
{ encode: (value) => `${value}` },
|
|
91
|
-
)
|
|
34
|
+
lt(value: number) {
|
|
35
|
+
return NumberType.factory(...this.props.checks, lt(value))
|
|
92
36
|
}
|
|
93
37
|
|
|
94
|
-
|
|
95
|
-
return this.
|
|
38
|
+
lte(value: number) {
|
|
39
|
+
return NumberType.factory(...this.props.checks, lte(value))
|
|
96
40
|
}
|
|
97
41
|
|
|
98
|
-
|
|
99
|
-
return this.
|
|
42
|
+
gte(value: number) {
|
|
43
|
+
return NumberType.factory(...this.props.checks, gte(value))
|
|
100
44
|
}
|
|
101
45
|
|
|
102
|
-
|
|
103
|
-
return
|
|
104
|
-
...this.props.options,
|
|
105
|
-
maximum: value,
|
|
106
|
-
...(!exclusive ? {} : { exclusiveMaximum: value }),
|
|
107
|
-
})
|
|
46
|
+
gt(value: number) {
|
|
47
|
+
return NumberType.factory(...this.props.checks, gt(value))
|
|
108
48
|
}
|
|
49
|
+
}
|
|
109
50
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
minimum: value,
|
|
114
|
-
...(!exclusive ? {} : { exclusiveMinimum: value }),
|
|
115
|
-
})
|
|
51
|
+
export class IntegerType extends NumberType {
|
|
52
|
+
static factory(...checks: Check[]) {
|
|
53
|
+
return NumberType.factory(...checks, int())
|
|
116
54
|
}
|
|
117
55
|
}
|
package/src/types/object.ts
CHANGED
|
@@ -1,64 +1,73 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
} from '@
|
|
8
|
-
|
|
9
|
-
import type { UnionToTupleString } from '../utils.ts'
|
|
2
|
+
type core,
|
|
3
|
+
object,
|
|
4
|
+
record,
|
|
5
|
+
type ZodMiniObject,
|
|
6
|
+
type ZodMiniRecord,
|
|
7
|
+
} from '@zod/mini'
|
|
8
|
+
|
|
10
9
|
import { BaseType, type BaseTypeAny, type OptionalType } from './base.ts'
|
|
11
|
-
import { EnumType
|
|
10
|
+
import { EnumType } from './enum.ts'
|
|
12
11
|
import type { LiteralType } from './literal.ts'
|
|
13
12
|
import type { StringType } from './string.ts'
|
|
14
13
|
|
|
15
14
|
export type ObjectTypeProps = { [k: string]: BaseTypeAny }
|
|
16
15
|
export type AnyObjectType = ObjectType<ObjectTypeProps>
|
|
17
16
|
export class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
|
|
17
|
+
ZodMiniObject<{ [K in keyof T]: T[K]['encodedZodType'] }>,
|
|
18
|
+
ZodMiniObject<{ [K in keyof T]: T[K]['decodedZodType'] }>,
|
|
19
|
+
{ properties: T }
|
|
21
20
|
> {
|
|
22
|
-
static factory<T extends ObjectTypeProps = {}>(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
[K in keyof T]: T[K]['
|
|
21
|
+
static factory<T extends ObjectTypeProps = {}>(properties: T) {
|
|
22
|
+
const encodeProperties = {} as {
|
|
23
|
+
[K in keyof T]: T[K]['encodedZodType']
|
|
24
|
+
}
|
|
25
|
+
const decodeProperties = {} as {
|
|
26
|
+
[K in keyof T]: T[K]['decodedZodType']
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
for (const key in properties) {
|
|
31
|
-
|
|
30
|
+
encodeProperties[key] = properties[key].encodedZodType
|
|
31
|
+
decodeProperties[key] = properties[key].decodedZodType
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
return new ObjectType<T>(
|
|
35
|
-
|
|
34
|
+
return new ObjectType<T>({
|
|
35
|
+
encodedZodType: object(encodeProperties),
|
|
36
|
+
decodedZodType: object(decodeProperties),
|
|
37
|
+
props: { properties },
|
|
36
38
|
})
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export class RecordType<
|
|
41
|
-
K extends LiteralType |
|
|
43
|
+
K extends LiteralType<string | number> | EnumType | StringType,
|
|
42
44
|
E extends BaseType,
|
|
43
|
-
> extends BaseType<
|
|
45
|
+
> extends BaseType<
|
|
46
|
+
ZodMiniRecord<K['encodedZodType'], E['encodedZodType']>,
|
|
47
|
+
ZodMiniRecord<K['decodedZodType'], E['decodedZodType']>
|
|
48
|
+
> {
|
|
44
49
|
static factory<
|
|
45
|
-
K extends
|
|
46
|
-
| LiteralType<any>
|
|
47
|
-
| EnumType<any>
|
|
48
|
-
| ObjectEnumType<any>
|
|
49
|
-
| StringType,
|
|
50
|
+
K extends LiteralType<string | number> | EnumType | StringType,
|
|
50
51
|
E extends BaseType,
|
|
51
|
-
>(key: K, element: E
|
|
52
|
-
return new RecordType<K, E>(
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
>(key: K, element: E) {
|
|
53
|
+
return new RecordType<K, E>({
|
|
54
|
+
encodedZodType: record(
|
|
55
|
+
(key as any).encodedZodType,
|
|
56
|
+
element.encodedZodType,
|
|
57
|
+
),
|
|
58
|
+
decodedZodType: record(
|
|
59
|
+
(key as any).decodedZodType,
|
|
60
|
+
element.decodedZodType,
|
|
61
|
+
),
|
|
62
|
+
props: { key, element },
|
|
63
|
+
})
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
export function keyof<T extends ObjectType>(
|
|
59
68
|
type: T,
|
|
60
69
|
): EnumType<
|
|
61
|
-
|
|
70
|
+
core.utils.ToEnum<Extract<keyof T['props']['properties'], string>>
|
|
62
71
|
> {
|
|
63
72
|
return EnumType.factory(Object.keys(type.props.properties) as any)
|
|
64
73
|
}
|
|
@@ -139,9 +148,7 @@ export function partial<
|
|
|
139
148
|
>(
|
|
140
149
|
object: T,
|
|
141
150
|
): ObjectType<{
|
|
142
|
-
[K in keyof P]: P[K]
|
|
143
|
-
? OptionalType<P[K], T>
|
|
144
|
-
: never
|
|
151
|
+
[K in keyof P]: OptionalType<P[K]>
|
|
145
152
|
}> {
|
|
146
153
|
const properties = {} as any
|
|
147
154
|
|
|
@@ -149,5 +156,5 @@ export function partial<
|
|
|
149
156
|
properties[key] = value.optional()
|
|
150
157
|
}
|
|
151
158
|
|
|
152
|
-
return ObjectType.factory(properties
|
|
159
|
+
return ObjectType.factory(properties)
|
|
153
160
|
}
|
package/src/types/string.ts
CHANGED
|
@@ -1,63 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type core,
|
|
3
|
+
email,
|
|
4
|
+
ipv4,
|
|
5
|
+
ipv6,
|
|
6
|
+
maxLength,
|
|
7
|
+
minLength,
|
|
8
|
+
regex,
|
|
9
|
+
string,
|
|
10
|
+
url,
|
|
11
|
+
uuid,
|
|
12
|
+
type ZodMiniString,
|
|
13
|
+
} from '@zod/mini'
|
|
14
|
+
|
|
3
15
|
import { BaseType } from './base.ts'
|
|
4
16
|
|
|
17
|
+
type Check = core.CheckFn<string> | core.$ZodCheck<string>
|
|
18
|
+
|
|
5
19
|
export class StringType extends BaseType<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
20
|
+
ZodMiniString<string>,
|
|
21
|
+
ZodMiniString<string>,
|
|
22
|
+
{ checks: Check[] }
|
|
9
23
|
> {
|
|
10
|
-
static factory(
|
|
11
|
-
return new StringType(
|
|
24
|
+
static factory(...checks: Check[]) {
|
|
25
|
+
return new StringType({
|
|
26
|
+
encodedZodType: string().check(...checks),
|
|
27
|
+
props: { checks },
|
|
28
|
+
})
|
|
12
29
|
}
|
|
13
30
|
|
|
14
31
|
max(value: number) {
|
|
15
|
-
return StringType.factory(
|
|
16
|
-
...this.props.options,
|
|
17
|
-
maxLength: value,
|
|
18
|
-
})
|
|
32
|
+
return StringType.factory(...this.props.checks, maxLength(value))
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
min(value: number) {
|
|
22
|
-
return StringType.factory(
|
|
23
|
-
...this.props.options,
|
|
24
|
-
minLength: value,
|
|
25
|
-
})
|
|
36
|
+
return StringType.factory(...this.props.checks, minLength(value))
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
return StringType.factory(
|
|
30
|
-
...this.props.
|
|
31
|
-
pattern:
|
|
32
|
-
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
pattern(pattern: string) {
|
|
37
|
-
return StringType.factory({
|
|
38
|
-
...this.props.options,
|
|
39
|
-
format: undefined,
|
|
40
|
-
pattern,
|
|
41
|
-
})
|
|
39
|
+
pattern(pattern: string | RegExp) {
|
|
40
|
+
return StringType.factory(
|
|
41
|
+
...this.props.checks,
|
|
42
|
+
regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern),
|
|
43
|
+
)
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
email() {
|
|
45
|
-
return this.
|
|
46
|
+
email(options?: core.$ZodEmailParams) {
|
|
47
|
+
return StringType.factory(...this.props.checks, email(options))
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
url() {
|
|
49
|
-
return this.
|
|
50
|
+
url(options?: core.$ZodURLParams) {
|
|
51
|
+
return StringType.factory(...this.props.checks, url(options))
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
ipv4() {
|
|
53
|
-
return this.
|
|
54
|
+
ipv4(options?: core.$ZodIPv4Params) {
|
|
55
|
+
return StringType.factory(...this.props.checks, ipv4(options))
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
ipv6() {
|
|
57
|
-
return this.
|
|
58
|
+
ipv6(options?: core.$ZodIPv6Params) {
|
|
59
|
+
return StringType.factory(...this.props.checks, ipv6(options))
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
uuid() {
|
|
61
|
-
return this.
|
|
62
|
+
uuid(options?: core.$ZodUUIDParams) {
|
|
63
|
+
return StringType.factory(...this.props.checks, uuid(options))
|
|
62
64
|
}
|
|
63
65
|
}
|
package/src/types/temporal.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
custom,
|
|
3
|
+
string,
|
|
4
|
+
type ZodMiniCustom,
|
|
5
|
+
type ZodMiniString,
|
|
6
|
+
} from '@zod/mini'
|
|
2
7
|
import { Temporal } from 'temporal-polyfill'
|
|
3
8
|
import { CustomType, TransformType } from './custom.ts'
|
|
4
9
|
|
|
@@ -29,102 +34,137 @@ const createTemporalTransformer = <T extends Types>(
|
|
|
29
34
|
} as TemporalTransformer<T>
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
export class PlainDateType extends TransformType<
|
|
33
|
-
|
|
37
|
+
export class PlainDateType extends TransformType<
|
|
38
|
+
Temporal.PlainDate,
|
|
39
|
+
ZodMiniString
|
|
40
|
+
> {
|
|
41
|
+
static transformer = createTemporalTransformer('PlainDate')
|
|
34
42
|
|
|
35
43
|
static factory() {
|
|
36
|
-
return CustomType.factory
|
|
44
|
+
return CustomType.factory<
|
|
45
|
+
Temporal.PlainDate,
|
|
46
|
+
ZodMiniString,
|
|
47
|
+
ZodMiniCustom<Temporal.PlainDate, Temporal.PlainDate>
|
|
48
|
+
>(
|
|
37
49
|
PlainDateType.transformer.decode,
|
|
38
50
|
PlainDateType.transformer.encode,
|
|
39
|
-
|
|
51
|
+
string(),
|
|
40
52
|
)
|
|
41
53
|
}
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
export class PlainDateTimeType extends TransformType<
|
|
45
57
|
Temporal.PlainDateTime,
|
|
46
|
-
|
|
58
|
+
ZodMiniString
|
|
47
59
|
> {
|
|
48
|
-
static
|
|
49
|
-
protected _encode = PlainDateTimeType.transformer.encode
|
|
60
|
+
static transformer = createTemporalTransformer('PlainDateTime')
|
|
50
61
|
|
|
51
62
|
static factory() {
|
|
52
|
-
return CustomType.factory
|
|
63
|
+
return CustomType.factory<
|
|
64
|
+
Temporal.PlainDateTime,
|
|
65
|
+
ZodMiniString,
|
|
66
|
+
ZodMiniCustom<Temporal.PlainDateTime, Temporal.PlainDateTime>
|
|
67
|
+
>(
|
|
53
68
|
PlainDateTimeType.transformer.decode,
|
|
54
69
|
PlainDateTimeType.transformer.encode,
|
|
55
|
-
|
|
70
|
+
string(),
|
|
56
71
|
)
|
|
57
72
|
}
|
|
58
73
|
}
|
|
59
74
|
|
|
60
75
|
export class ZonedDateTimeType extends TransformType<
|
|
61
76
|
Temporal.ZonedDateTime,
|
|
62
|
-
|
|
77
|
+
ZodMiniString
|
|
63
78
|
> {
|
|
64
|
-
static
|
|
65
|
-
'
|
|
66
|
-
(value) => Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),
|
|
79
|
+
static transformer = createTemporalTransformer('ZonedDateTime', (value) =>
|
|
80
|
+
Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),
|
|
67
81
|
)
|
|
68
82
|
|
|
69
83
|
static factory() {
|
|
70
|
-
return CustomType.factory
|
|
84
|
+
return CustomType.factory<
|
|
85
|
+
Temporal.ZonedDateTime,
|
|
86
|
+
ZodMiniString,
|
|
87
|
+
ZodMiniCustom<Temporal.ZonedDateTime, Temporal.ZonedDateTime>
|
|
88
|
+
>(
|
|
71
89
|
ZonedDateTimeType.transformer.decode,
|
|
72
90
|
ZonedDateTimeType.transformer.encode,
|
|
73
|
-
|
|
91
|
+
string(),
|
|
74
92
|
)
|
|
75
93
|
}
|
|
76
94
|
}
|
|
77
95
|
|
|
78
|
-
export class PlainTimeType extends TransformType<
|
|
79
|
-
|
|
96
|
+
export class PlainTimeType extends TransformType<
|
|
97
|
+
Temporal.PlainTime,
|
|
98
|
+
ZodMiniString
|
|
99
|
+
> {
|
|
100
|
+
static transformer = createTemporalTransformer('PlainTime')
|
|
80
101
|
|
|
81
102
|
static factory() {
|
|
82
|
-
return CustomType.factory
|
|
103
|
+
return CustomType.factory<
|
|
104
|
+
Temporal.PlainTime,
|
|
105
|
+
ZodMiniString,
|
|
106
|
+
ZodMiniCustom<Temporal.PlainTime, Temporal.PlainTime>
|
|
107
|
+
>(
|
|
83
108
|
PlainTimeType.transformer.decode,
|
|
84
109
|
PlainTimeType.transformer.encode,
|
|
85
|
-
|
|
110
|
+
string(),
|
|
86
111
|
)
|
|
87
112
|
}
|
|
88
113
|
}
|
|
89
114
|
|
|
90
|
-
export class DurationType extends TransformType<
|
|
91
|
-
|
|
115
|
+
export class DurationType extends TransformType<
|
|
116
|
+
Temporal.Duration,
|
|
117
|
+
ZodMiniString
|
|
118
|
+
> {
|
|
119
|
+
static transformer = createTemporalTransformer('Duration')
|
|
92
120
|
|
|
93
121
|
static factory() {
|
|
94
|
-
return CustomType.factory
|
|
122
|
+
return CustomType.factory<
|
|
123
|
+
Temporal.Duration,
|
|
124
|
+
ZodMiniString,
|
|
125
|
+
ZodMiniCustom<Temporal.Duration, Temporal.Duration>
|
|
126
|
+
>(
|
|
95
127
|
DurationType.transformer.decode,
|
|
96
128
|
DurationType.transformer.encode,
|
|
97
|
-
|
|
129
|
+
string(),
|
|
98
130
|
)
|
|
99
131
|
}
|
|
100
132
|
}
|
|
101
133
|
|
|
102
134
|
export class PlainYearMonthType extends TransformType<
|
|
103
135
|
Temporal.PlainYearMonth,
|
|
104
|
-
|
|
136
|
+
ZodMiniString
|
|
105
137
|
> {
|
|
106
|
-
static
|
|
138
|
+
static transformer = createTemporalTransformer('PlainYearMonth')
|
|
107
139
|
|
|
108
140
|
static factory() {
|
|
109
|
-
return CustomType.factory
|
|
141
|
+
return CustomType.factory<
|
|
142
|
+
Temporal.PlainYearMonth,
|
|
143
|
+
ZodMiniString,
|
|
144
|
+
ZodMiniCustom<Temporal.PlainYearMonth, Temporal.PlainYearMonth>
|
|
145
|
+
>(
|
|
110
146
|
PlainYearMonthType.transformer.decode,
|
|
111
147
|
PlainYearMonthType.transformer.encode,
|
|
112
|
-
|
|
148
|
+
string(),
|
|
113
149
|
)
|
|
114
150
|
}
|
|
115
151
|
}
|
|
116
152
|
|
|
117
153
|
export class PlainMonthDayType extends TransformType<
|
|
118
154
|
Temporal.PlainMonthDay,
|
|
119
|
-
|
|
155
|
+
ZodMiniString
|
|
120
156
|
> {
|
|
121
|
-
static
|
|
157
|
+
static transformer = createTemporalTransformer('PlainMonthDay')
|
|
122
158
|
|
|
123
159
|
static factory() {
|
|
124
|
-
return CustomType.factory
|
|
160
|
+
return CustomType.factory<
|
|
161
|
+
Temporal.PlainMonthDay,
|
|
162
|
+
ZodMiniString,
|
|
163
|
+
ZodMiniCustom<Temporal.PlainMonthDay, Temporal.PlainMonthDay>
|
|
164
|
+
>(
|
|
125
165
|
PlainMonthDayType.transformer.decode,
|
|
126
166
|
PlainMonthDayType.transformer.encode,
|
|
127
|
-
|
|
167
|
+
string(),
|
|
128
168
|
)
|
|
129
169
|
}
|
|
130
170
|
}
|