@nmtjs/type 0.12.5 → 0.12.7
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.d.ts +4 -0
- package/dist/index.js +1 -3
- package/dist/temporal.d.ts +1 -0
- package/dist/temporal.js +0 -2
- package/dist/types/any.d.ts +6 -0
- package/dist/types/any.js +6 -6
- package/dist/types/array.d.ts +13 -0
- package/dist/types/array.js +21 -23
- package/dist/types/base.d.ts +62 -0
- package/dist/types/base.js +67 -65
- package/dist/types/boolean.d.ts +6 -0
- package/dist/types/boolean.js +6 -6
- package/dist/types/custom.d.ts +14 -0
- package/dist/types/custom.js +21 -21
- package/dist/types/date.d.ts +6 -0
- package/dist/types/date.js +8 -10
- package/dist/types/enum.d.ts +10 -0
- package/dist/types/enum.js +7 -9
- package/dist/types/literal.d.ts +8 -0
- package/dist/types/literal.js +7 -9
- package/dist/types/never.d.ts +6 -0
- package/dist/types/never.js +6 -6
- package/dist/types/number.d.ts +23 -0
- package/dist/types/number.js +36 -38
- package/dist/types/object.d.ts +43 -0
- package/dist/types/object.js +39 -44
- package/dist/types/string.d.ts +22 -0
- package/dist/types/string.js +49 -51
- package/dist/types/temporal.d.ts +45 -0
- package/dist/types/temporal.js +74 -76
- package/dist/types/tuple.d.ts +13 -0
- package/dist/types/tuple.js +12 -15
- package/dist/types/type.d.ts +24 -0
- package/dist/types/type.js +0 -2
- package/dist/types/union.d.ts +40 -0
- package/dist/types/union.js +29 -32
- package/package.json +8 -7
- package/dist/index.js.map +0 -1
- package/dist/temporal.js.map +0 -1
- package/dist/types/any.js.map +0 -1
- package/dist/types/array.js.map +0 -1
- package/dist/types/base.js.map +0 -1
- package/dist/types/boolean.js.map +0 -1
- package/dist/types/custom.js.map +0 -1
- package/dist/types/date.js.map +0 -1
- package/dist/types/enum.js.map +0 -1
- package/dist/types/literal.js.map +0 -1
- package/dist/types/never.js.map +0 -1
- package/dist/types/number.js.map +0 -1
- package/dist/types/object.js.map +0 -1
- package/dist/types/string.js.map +0 -1
- package/dist/types/temporal.js.map +0 -1
- package/dist/types/tuple.js.map +0 -1
- package/dist/types/type.js.map +0 -1
- package/dist/types/union.js.map +0 -1
- package/src/index.ts +0 -8
- package/src/temporal.ts +0 -1
- package/src/types/any.ts +0 -12
- package/src/types/array.ts +0 -48
- package/src/types/base.ts +0 -183
- package/src/types/boolean.ts +0 -12
- package/src/types/custom.ts +0 -79
- package/src/types/date.ts +0 -20
- package/src/types/enum.ts +0 -21
- package/src/types/literal.ts +0 -15
- package/src/types/never.ts +0 -12
- package/src/types/number.ts +0 -65
- package/src/types/object.ts +0 -163
- package/src/types/string.ts +0 -78
- package/src/types/temporal.ts +0 -154
- package/src/types/tuple.ts +0 -36
- package/src/types/type.ts +0 -31
- package/src/types/union.ts +0 -113
package/src/types/date.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod/v4-mini'
|
|
2
|
-
import { CustomType, TransformType } from './custom.ts'
|
|
3
|
-
|
|
4
|
-
export class DateType extends TransformType<
|
|
5
|
-
Date,
|
|
6
|
-
zod.ZodMiniUnion<[zod.iso.ZodMiniISODate, zod.iso.ZodMiniISODateTime]>
|
|
7
|
-
> {
|
|
8
|
-
static factory() {
|
|
9
|
-
return CustomType.factory<
|
|
10
|
-
Date,
|
|
11
|
-
zod.ZodMiniUnion<[zod.iso.ZodMiniISODate, zod.iso.ZodMiniISODateTime]>
|
|
12
|
-
>({
|
|
13
|
-
decode: (value: string): Date => new Date(value),
|
|
14
|
-
encode: (value: Date): string => value.toISOString(),
|
|
15
|
-
type: zod.union([zod.iso.date(), zod.iso.datetime()]),
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const date = DateType.factory
|
package/src/types/enum.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod/v4-mini'
|
|
2
|
-
import { BaseType } from './base.ts'
|
|
3
|
-
|
|
4
|
-
export class EnumType<
|
|
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
|
-
static factory<T extends string[]>(
|
|
9
|
-
values: T,
|
|
10
|
-
): EnumType<zod.core.util.ToEnum<T[number]>>
|
|
11
|
-
static factory<T extends zod.core.util.EnumLike | string[]>(values: T) {
|
|
12
|
-
return new EnumType({
|
|
13
|
-
encodedZodType: zod.enum(values as any),
|
|
14
|
-
props: { values },
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const _enum = EnumType.factory
|
|
20
|
-
|
|
21
|
-
export { _enum as enum }
|
package/src/types/literal.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod/v4-mini'
|
|
2
|
-
import { BaseType, type PrimitiveValueType } from './base.ts'
|
|
3
|
-
|
|
4
|
-
export class LiteralType<
|
|
5
|
-
T extends PrimitiveValueType = PrimitiveValueType,
|
|
6
|
-
> extends BaseType<zod.ZodMiniLiteral<T>, zod.ZodMiniLiteral<T>, { value: T }> {
|
|
7
|
-
static factory<T extends PrimitiveValueType>(value: T) {
|
|
8
|
-
return new LiteralType<T>({
|
|
9
|
-
encodedZodType: zod.literal(value),
|
|
10
|
-
props: { value },
|
|
11
|
-
})
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const literal = LiteralType.factory
|
package/src/types/never.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod/v4-mini'
|
|
2
|
-
import { BaseType } from './base.ts'
|
|
3
|
-
|
|
4
|
-
export class NeverType extends BaseType<zod.ZodMiniNever> {
|
|
5
|
-
static factory() {
|
|
6
|
-
return new NeverType({
|
|
7
|
-
encodedZodType: zod.never(),
|
|
8
|
-
})
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const never = NeverType.factory
|
package/src/types/number.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod/v4-mini'
|
|
2
|
-
import { BaseType } from './base.ts'
|
|
3
|
-
import { CustomType, TransformType } from './custom.ts'
|
|
4
|
-
|
|
5
|
-
type Check = zod.core.CheckFn<number> | zod.core.$ZodCheck<number>
|
|
6
|
-
|
|
7
|
-
export class NumberType extends BaseType<
|
|
8
|
-
zod.ZodMiniNumber<number>,
|
|
9
|
-
zod.ZodMiniNumber<number>
|
|
10
|
-
> {
|
|
11
|
-
static factory(...checks: Check[]) {
|
|
12
|
-
return new NumberType({
|
|
13
|
-
encodedZodType: zod.number().check(...checks),
|
|
14
|
-
params: { checks },
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
positive() {
|
|
19
|
-
return NumberType.factory(...this.params.checks, zod.gte(0))
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
negative() {
|
|
23
|
-
return NumberType.factory(...this.params.checks, zod.lte(0))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
lt(value: number) {
|
|
27
|
-
return NumberType.factory(...this.params.checks, zod.lt(value))
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
lte(value: number) {
|
|
31
|
-
return NumberType.factory(...this.params.checks, zod.lte(value))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
gte(value: number) {
|
|
35
|
-
return NumberType.factory(...this.params.checks, zod.gte(value))
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
gt(value: number) {
|
|
39
|
-
return NumberType.factory(...this.params.checks, zod.gt(value))
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export class IntegerType extends NumberType {
|
|
44
|
-
static factory(...checks: Check[]) {
|
|
45
|
-
return NumberType.factory(...checks, zod.int())
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export class BigIntType extends TransformType<
|
|
50
|
-
bigint,
|
|
51
|
-
zod.ZodMiniString<string>
|
|
52
|
-
> {
|
|
53
|
-
static factory() {
|
|
54
|
-
return CustomType.factory<bigint, zod.ZodMiniString<string>>({
|
|
55
|
-
decode: (value) => BigInt(value),
|
|
56
|
-
encode: (value) => value.toString(),
|
|
57
|
-
type: zod.string().check(zod.regex(/^-?\d+$/)),
|
|
58
|
-
error: 'Invalid bigint format',
|
|
59
|
-
})
|
|
60
|
-
}
|
|
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
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod/v4-mini'
|
|
2
|
-
|
|
3
|
-
import { BaseType, type BaseTypeAny, type OptionalType } from './base.ts'
|
|
4
|
-
import { EnumType } from './enum.ts'
|
|
5
|
-
import type { LiteralType } from './literal.ts'
|
|
6
|
-
import type { StringType } from './string.ts'
|
|
7
|
-
|
|
8
|
-
export type ObjectTypeProps = { [k: string]: BaseTypeAny }
|
|
9
|
-
export type AnyObjectType = ObjectType<ObjectTypeProps>
|
|
10
|
-
export class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<
|
|
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
|
-
>,
|
|
19
|
-
{ properties: T }
|
|
20
|
-
> {
|
|
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']
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
for (const key in properties) {
|
|
30
|
-
encodeProperties[key] = properties[key].encodedZodType
|
|
31
|
-
decodeProperties[key] = properties[key].decodedZodType
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return new ObjectType<T>({
|
|
35
|
-
encodedZodType: zod.object(encodeProperties),
|
|
36
|
-
decodedZodType: zod.object(decodeProperties),
|
|
37
|
-
props: { properties },
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class RecordType<
|
|
43
|
-
K extends LiteralType<string | number> | EnumType | StringType,
|
|
44
|
-
E extends BaseType,
|
|
45
|
-
> extends BaseType<
|
|
46
|
-
zod.ZodMiniRecord<K['encodedZodType'], E['encodedZodType']>,
|
|
47
|
-
zod.ZodMiniRecord<K['decodedZodType'], E['decodedZodType']>
|
|
48
|
-
> {
|
|
49
|
-
static factory<
|
|
50
|
-
K extends LiteralType<string | number> | EnumType | StringType,
|
|
51
|
-
E extends BaseType,
|
|
52
|
-
>(key: K, element: E) {
|
|
53
|
-
return new RecordType<K, E>({
|
|
54
|
-
encodedZodType: zod.record(
|
|
55
|
-
(key as any).encodedZodType,
|
|
56
|
-
element.encodedZodType,
|
|
57
|
-
),
|
|
58
|
-
decodedZodType: zod.record(
|
|
59
|
-
(key as any).decodedZodType,
|
|
60
|
-
element.decodedZodType,
|
|
61
|
-
),
|
|
62
|
-
props: { key, element },
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function keyof<T extends ObjectType>(
|
|
68
|
-
type: T,
|
|
69
|
-
): EnumType<
|
|
70
|
-
zod.core.util.ToEnum<Extract<keyof T['props']['properties'], string>>
|
|
71
|
-
> {
|
|
72
|
-
return EnumType.factory(Object.keys(type.props.properties) as any)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function pick<
|
|
76
|
-
T extends AnyObjectType,
|
|
77
|
-
P extends { [K in keyof T['props']['properties']]?: true },
|
|
78
|
-
>(
|
|
79
|
-
source: T,
|
|
80
|
-
pick: P,
|
|
81
|
-
): ObjectType<{
|
|
82
|
-
[K in keyof P]: P[K] extends true
|
|
83
|
-
? K extends keyof T['props']['properties']
|
|
84
|
-
? T['props']['properties'][K]
|
|
85
|
-
: never
|
|
86
|
-
: never
|
|
87
|
-
}> {
|
|
88
|
-
const properties = Object.fromEntries(
|
|
89
|
-
Object.entries(source.props.properties).filter(([key]) => pick[key]),
|
|
90
|
-
)
|
|
91
|
-
return ObjectType.factory(properties) as any
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function omit<
|
|
95
|
-
T extends AnyObjectType,
|
|
96
|
-
P extends { [K in keyof T['props']['properties']]?: true },
|
|
97
|
-
>(
|
|
98
|
-
source: T,
|
|
99
|
-
omit: P,
|
|
100
|
-
): ObjectType<{
|
|
101
|
-
[K in keyof T['props']['properties'] as K extends keyof P
|
|
102
|
-
? never
|
|
103
|
-
: K]: T['props']['properties'][K]
|
|
104
|
-
}> {
|
|
105
|
-
const properties = Object.fromEntries(
|
|
106
|
-
Object.entries(source.props.properties).filter(([key]) => !omit[key]),
|
|
107
|
-
)
|
|
108
|
-
return ObjectType.factory(properties) as any
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function extend<T extends AnyObjectType, P extends ObjectTypeProps>(
|
|
112
|
-
object1: T,
|
|
113
|
-
properties: P,
|
|
114
|
-
): ObjectType<{
|
|
115
|
-
[K in keyof T['props']['properties'] | keyof P]: K extends keyof P
|
|
116
|
-
? P[K]
|
|
117
|
-
: K extends keyof T['props']['properties']
|
|
118
|
-
? T['props']['properties'][K]
|
|
119
|
-
: never
|
|
120
|
-
}> {
|
|
121
|
-
return ObjectType.factory({
|
|
122
|
-
...object1.props.properties,
|
|
123
|
-
...properties,
|
|
124
|
-
}) as any
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function merge<T1 extends AnyObjectType, T2 extends AnyObjectType>(
|
|
128
|
-
object1: T1,
|
|
129
|
-
object2: T2,
|
|
130
|
-
): ObjectType<{
|
|
131
|
-
[K in
|
|
132
|
-
| keyof T1['props']['properties']
|
|
133
|
-
| keyof T2['props']['properties']]: K extends keyof T2['props']['properties']
|
|
134
|
-
? T2['props']['properties'][K]
|
|
135
|
-
: K extends keyof T1['props']['properties']
|
|
136
|
-
? T1['props']['properties'][K]
|
|
137
|
-
: never
|
|
138
|
-
}> {
|
|
139
|
-
return ObjectType.factory({
|
|
140
|
-
...object1.props.properties,
|
|
141
|
-
...object2.props.properties,
|
|
142
|
-
}) as any
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function partial<
|
|
146
|
-
T extends AnyObjectType,
|
|
147
|
-
P extends T extends ObjectType<infer Props> ? Props : never,
|
|
148
|
-
>(
|
|
149
|
-
object: T,
|
|
150
|
-
): ObjectType<{
|
|
151
|
-
[K in keyof P]: OptionalType<P[K]>
|
|
152
|
-
}> {
|
|
153
|
-
const properties = {} as any
|
|
154
|
-
|
|
155
|
-
for (const [key, value] of Object.entries(object.props.properties)) {
|
|
156
|
-
properties[key] = value.optional()
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return ObjectType.factory(properties)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export const object = ObjectType.factory
|
|
163
|
-
export const record = RecordType.factory
|
package/src/types/string.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod/v4-mini'
|
|
2
|
-
|
|
3
|
-
import { BaseType } from './base.ts'
|
|
4
|
-
|
|
5
|
-
type Check = zod.core.CheckFn<string> | zod.core.$ZodCheck<string>
|
|
6
|
-
|
|
7
|
-
export class StringType extends BaseType<
|
|
8
|
-
zod.ZodMiniString<string>,
|
|
9
|
-
zod.ZodMiniString<string>
|
|
10
|
-
> {
|
|
11
|
-
static factory(...checks: Check[]) {
|
|
12
|
-
return new StringType({
|
|
13
|
-
encodedZodType: zod.string().check(...checks),
|
|
14
|
-
params: { checks },
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
max(value: number) {
|
|
19
|
-
return StringType.factory(...this.params.checks, zod.maxLength(value))
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
min(value: number) {
|
|
23
|
-
return StringType.factory(...this.params.checks, zod.minLength(value))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
pattern(pattern: string | RegExp) {
|
|
27
|
-
return StringType.factory(
|
|
28
|
-
...this.params.checks,
|
|
29
|
-
zod.regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern),
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
email(options?: zod.core.$ZodEmailParams) {
|
|
34
|
-
return StringType.factory(...this.params.checks, zod.email(options))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
url(options?: zod.core.$ZodURLParams) {
|
|
38
|
-
return StringType.factory(...this.params.checks, zod.url(options))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
ipv4(options?: zod.core.$ZodIPv4Params) {
|
|
42
|
-
return StringType.factory(...this.params.checks, zod.ipv4(options))
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
ipv6(options?: zod.core.$ZodIPv6Params) {
|
|
46
|
-
return StringType.factory(...this.params.checks, zod.ipv6(options))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
uuid(options?: zod.core.$ZodUUIDParams) {
|
|
50
|
-
return StringType.factory(...this.params.checks, zod.uuid(options))
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
emoji(options?: zod.core.$ZodEmojiParams) {
|
|
54
|
-
return StringType.factory(...this.params.checks, zod.emoji(options))
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
nanoid(options?: zod.core.$ZodNanoIDParams) {
|
|
58
|
-
return StringType.factory(...this.params.checks, zod.nanoid(options))
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
cuid(options?: zod.core.$ZodCUIDParams) {
|
|
62
|
-
return StringType.factory(...this.params.checks, zod.cuid(options))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
cuid2(options?: zod.core.$ZodCUID2Params) {
|
|
66
|
-
return StringType.factory(...this.params.checks, zod.cuid2(options))
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
e164(options?: zod.core.$ZodE164Params) {
|
|
70
|
-
return StringType.factory(...this.params.checks, zod.e164(options))
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
jwt(options?: zod.core.$ZodJWTParams) {
|
|
74
|
-
return StringType.factory(...this.params.checks, zod.jwt(options))
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const string = StringType.factory
|
package/src/types/temporal.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill'
|
|
2
|
-
import { iso, regex, string, type ZodMiniString } from 'zod/v4-mini'
|
|
3
|
-
import { CustomType, TransformType } from './custom.ts'
|
|
4
|
-
|
|
5
|
-
type Types = Exclude<
|
|
6
|
-
keyof typeof Temporal,
|
|
7
|
-
'Now' | 'Instant' | 'Calendar' | 'TimeZone'
|
|
8
|
-
>
|
|
9
|
-
|
|
10
|
-
type TemporalTransformer<T extends Types> = {
|
|
11
|
-
decode: (value: string) => ReturnType<(typeof Temporal)[T]['from']>
|
|
12
|
-
encode: (value: ReturnType<(typeof Temporal)[T]['from']>) => string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const createTemporalTransformer = <T extends Types>(
|
|
16
|
-
type: T,
|
|
17
|
-
decode = (value: string) => Temporal[type].from(value),
|
|
18
|
-
) => {
|
|
19
|
-
const encode = (value: ReturnType<(typeof Temporal)[T]['from']>) =>
|
|
20
|
-
value.toString({
|
|
21
|
-
calendarName: 'never',
|
|
22
|
-
smallestUnit: 'microsecond',
|
|
23
|
-
timeZoneName: 'never',
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
decode,
|
|
28
|
-
encode,
|
|
29
|
-
} as TemporalTransformer<T>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type EncodedType = ZodMiniString<string>
|
|
33
|
-
|
|
34
|
-
export class PlainDateType extends TransformType<
|
|
35
|
-
Temporal.PlainDate,
|
|
36
|
-
EncodedType
|
|
37
|
-
> {
|
|
38
|
-
static transformer = createTemporalTransformer('PlainDate')
|
|
39
|
-
|
|
40
|
-
static factory() {
|
|
41
|
-
return CustomType.factory<Temporal.PlainDate, EncodedType>({
|
|
42
|
-
decode: PlainDateType.transformer.decode,
|
|
43
|
-
encode: PlainDateType.transformer.encode,
|
|
44
|
-
type: iso.date(),
|
|
45
|
-
error: 'Invalid date format',
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export class PlainDateTimeType extends TransformType<
|
|
51
|
-
Temporal.PlainDateTime,
|
|
52
|
-
EncodedType
|
|
53
|
-
> {
|
|
54
|
-
static transformer = createTemporalTransformer('PlainDateTime')
|
|
55
|
-
|
|
56
|
-
static factory() {
|
|
57
|
-
return CustomType.factory<Temporal.PlainDateTime, EncodedType>({
|
|
58
|
-
decode: PlainDateTimeType.transformer.decode,
|
|
59
|
-
encode: PlainDateTimeType.transformer.encode,
|
|
60
|
-
type: iso.datetime({ local: true }),
|
|
61
|
-
error: 'Invalid datetime format',
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export class ZonedDateTimeType extends TransformType<
|
|
67
|
-
Temporal.ZonedDateTime,
|
|
68
|
-
EncodedType
|
|
69
|
-
> {
|
|
70
|
-
static transformer = createTemporalTransformer('ZonedDateTime', (value) =>
|
|
71
|
-
Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
static factory() {
|
|
75
|
-
return CustomType.factory<Temporal.ZonedDateTime, EncodedType>({
|
|
76
|
-
decode: ZonedDateTimeType.transformer.decode,
|
|
77
|
-
encode: ZonedDateTimeType.transformer.encode,
|
|
78
|
-
type: iso.datetime({ local: true }),
|
|
79
|
-
error: 'Invalid datetime format',
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export class PlainTimeType extends TransformType<
|
|
85
|
-
Temporal.PlainTime,
|
|
86
|
-
EncodedType
|
|
87
|
-
> {
|
|
88
|
-
static transformer = createTemporalTransformer('PlainTime')
|
|
89
|
-
|
|
90
|
-
static factory() {
|
|
91
|
-
return CustomType.factory<Temporal.PlainTime, EncodedType>({
|
|
92
|
-
decode: PlainTimeType.transformer.decode,
|
|
93
|
-
encode: PlainTimeType.transformer.encode,
|
|
94
|
-
type: iso.time(),
|
|
95
|
-
error: 'Invalid time format',
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export class DurationType extends TransformType<
|
|
101
|
-
Temporal.Duration,
|
|
102
|
-
EncodedType
|
|
103
|
-
> {
|
|
104
|
-
static transformer = createTemporalTransformer('Duration')
|
|
105
|
-
|
|
106
|
-
static factory() {
|
|
107
|
-
return CustomType.factory<Temporal.Duration, EncodedType>({
|
|
108
|
-
decode: DurationType.transformer.decode,
|
|
109
|
-
encode: DurationType.transformer.encode,
|
|
110
|
-
type: iso.duration(),
|
|
111
|
-
error: 'Invalid duration format',
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export class PlainYearMonthType extends TransformType<
|
|
117
|
-
Temporal.PlainYearMonth,
|
|
118
|
-
EncodedType
|
|
119
|
-
> {
|
|
120
|
-
static transformer = createTemporalTransformer('PlainYearMonth')
|
|
121
|
-
|
|
122
|
-
static factory() {
|
|
123
|
-
return CustomType.factory<Temporal.PlainYearMonth, EncodedType>({
|
|
124
|
-
decode: PlainYearMonthType.transformer.decode,
|
|
125
|
-
encode: PlainYearMonthType.transformer.encode,
|
|
126
|
-
type: string().check(regex(/^\d{4}-\d{2}$/)),
|
|
127
|
-
error: 'Invalid year-month format',
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export class PlainMonthDayType extends TransformType<
|
|
133
|
-
Temporal.PlainMonthDay,
|
|
134
|
-
EncodedType
|
|
135
|
-
> {
|
|
136
|
-
static transformer = createTemporalTransformer('PlainMonthDay')
|
|
137
|
-
|
|
138
|
-
static factory() {
|
|
139
|
-
return CustomType.factory<Temporal.PlainMonthDay, EncodedType>({
|
|
140
|
-
decode: PlainMonthDayType.transformer.decode,
|
|
141
|
-
encode: PlainMonthDayType.transformer.encode,
|
|
142
|
-
type: string().check(regex(/^\d{2}-\d{2}$/)),
|
|
143
|
-
error: 'Invalid month-day format',
|
|
144
|
-
})
|
|
145
|
-
}
|
|
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
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ArrayMap } from '@nmtjs/common'
|
|
2
|
-
import * as zod from 'zod/v4-mini'
|
|
3
|
-
import { BaseType } from './base.ts'
|
|
4
|
-
|
|
5
|
-
export class TupleType<
|
|
6
|
-
T extends readonly [BaseType, ...BaseType[]] = readonly [
|
|
7
|
-
BaseType,
|
|
8
|
-
...BaseType[],
|
|
9
|
-
],
|
|
10
|
-
R extends BaseType | null = BaseType | null,
|
|
11
|
-
> extends BaseType<
|
|
12
|
-
R extends BaseType
|
|
13
|
-
? zod.ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, R['encodedZodType']>
|
|
14
|
-
: zod.ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, null>,
|
|
15
|
-
R extends BaseType
|
|
16
|
-
? zod.ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, R['decodedZodType']>
|
|
17
|
-
: zod.ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, null>,
|
|
18
|
-
{ elements: T; rest?: R }
|
|
19
|
-
> {
|
|
20
|
-
static factory<
|
|
21
|
-
T extends readonly [BaseType, ...BaseType[]],
|
|
22
|
-
R extends BaseType | null = null,
|
|
23
|
-
>(elements: T, rest: R = null as R) {
|
|
24
|
-
const encoded = elements.map((el) => el.encodedZodType)
|
|
25
|
-
const decoded = elements.map((el) => el.decodedZodType)
|
|
26
|
-
return new TupleType<T, R>({
|
|
27
|
-
// @ts-expect-error
|
|
28
|
-
encodedZodType: zod.tuple(encoded, rest?.encodedZodType),
|
|
29
|
-
// @ts-expect-error
|
|
30
|
-
decodedZodType: zod.tuple(decoded, rest?.decodedZodType),
|
|
31
|
-
props: { elements, rest },
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const tuple = TupleType.factory
|
package/src/types/type.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|