@nmtjs/type 0.7.0 → 0.7.1

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/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as zod from '@zod/mini'
1
2
  import { AnyType } from './types/any.ts'
2
3
  import { ArrayType } from './types/array.ts'
3
4
  import type { BaseTypeAny } from './types/base.ts'
@@ -7,11 +8,7 @@ import { DateType } from './types/date.ts'
7
8
  import { EnumType } from './types/enum.ts'
8
9
  import { LiteralType } from './types/literal.ts'
9
10
  import { NeverType } from './types/never.ts'
10
- import {
11
- // BigIntType,
12
- IntegerType,
13
- NumberType,
14
- } from './types/number.ts'
11
+ import { BigIntType, IntegerType, NumberType } from './types/number.ts'
15
12
  import {
16
13
  extend,
17
14
  keyof,
@@ -29,6 +26,8 @@ import {
29
26
  UnionType,
30
27
  } from './types/union.ts'
31
28
 
29
+ zod.config(zod.core.locales.en())
30
+
32
31
  export { NeemataTypeError } from './types/base.ts'
33
32
  export { BaseType, type BaseTypeAny } from './types/base.ts'
34
33
  export {
@@ -52,17 +51,17 @@ export {
52
51
 
53
52
  export namespace type {
54
53
  export namespace infer {
55
- export type decoded<T extends BaseTypeAny<any>> =
54
+ export type decoded<T extends BaseTypeAny> =
56
55
  T['decodedZodType']['_zod']['output']
57
56
 
58
- export type encoded<T extends BaseTypeAny<any>> =
57
+ export type encoded<T extends BaseTypeAny> =
59
58
  T['encodedZodType']['_zod']['output']
60
59
 
61
60
  export namespace input {
62
- export type decoded<T extends BaseTypeAny<any>> =
61
+ export type decoded<T extends BaseTypeAny> =
63
62
  T['decodedZodType']['_zod']['input']
64
63
 
65
- export type encoded<T extends BaseTypeAny<any>> =
64
+ export type encoded<T extends BaseTypeAny> =
66
65
  T['encodedZodType']['_zod']['input']
67
66
  }
68
67
  }
@@ -72,7 +71,7 @@ export namespace type {
72
71
  export const string = StringType.factory
73
72
  export const number = NumberType.factory
74
73
  export const integer = IntegerType.factory
75
- // export const bitint = BigIntType.factory
74
+ export const bitint = BigIntType.factory
76
75
  export const literal = LiteralType.factory
77
76
  export const enumeration = EnumType.factory
78
77
  export const date = DateType.factory
@@ -95,4 +94,4 @@ export namespace type {
95
94
  })
96
95
  }
97
96
 
98
- export { type as t }
97
+ export { type as t, zod }
package/src/temporal.ts CHANGED
@@ -8,13 +8,13 @@ import {
8
8
  ZonedDateTimeType,
9
9
  } from './types/temporal.ts'
10
10
 
11
- export const plainDate = PlainDateType
12
- export const plainDatetime = PlainDateTimeType
13
- export const plainTime = PlainTimeType
14
- export const zonedDatetime = ZonedDateTimeType
15
- export const duration = DurationType
16
- export const plainYearMonth = PlainYearMonthType
17
- export const plainMonthDay = PlainMonthDayType
11
+ export const plainDate = PlainDateType.factory
12
+ export const plainDatetime = PlainDateTimeType.factory
13
+ export const plainTime = PlainTimeType.factory
14
+ export const zonedDatetime = ZonedDateTimeType.factory
15
+ export const duration = DurationType.factory
16
+ export const plainYearMonth = PlainYearMonthType.factory
17
+ export const plainMonthDay = PlainMonthDayType.factory
18
18
 
19
19
  export type {
20
20
  DurationType,
@@ -13,28 +13,41 @@ type Check = core.CheckFn<any[]> | core.$ZodCheck<any[]>
13
13
  export class ArrayType<T extends BaseType = BaseType> extends BaseType<
14
14
  ZodMiniArray<T['encodedZodType']>,
15
15
  ZodMiniArray<T['decodedZodType']>,
16
- { element: T; checks: Check[] }
16
+ { element: T }
17
17
  > {
18
18
  static factory<T extends BaseType>(element: T, ...checks: Check[]) {
19
19
  return new ArrayType<T>({
20
20
  encodedZodType: array(element.encodedZodType).check(...checks),
21
21
  decodedZodType: array(element.decodedZodType).check(...checks),
22
- props: { element, checks },
22
+ params: { checks },
23
+ props: { element },
23
24
  })
24
25
  }
25
26
 
26
27
  min(value: number) {
27
28
  const check = minLength(value)
28
- return ArrayType.factory<T>(this.props.element, ...this.props.checks, check)
29
+ return ArrayType.factory<T>(
30
+ this.props.element,
31
+ ...this.params.checks,
32
+ check,
33
+ )
29
34
  }
30
35
 
31
36
  max(value: number) {
32
37
  const check = maxLength(value)
33
- return ArrayType.factory<T>(this.props.element, ...this.props.checks, check)
38
+ return ArrayType.factory<T>(
39
+ this.props.element,
40
+ ...this.params.checks,
41
+ check,
42
+ )
34
43
  }
35
44
 
36
45
  length(value: number) {
37
46
  const check = length(value)
38
- return ArrayType.factory<T>(this.props.element, ...this.props.checks, check)
47
+ return ArrayType.factory<T>(
48
+ this.props.element,
49
+ ...this.params.checks,
50
+ check,
51
+ )
39
52
  }
40
53
  }
package/src/types/base.ts CHANGED
@@ -59,6 +59,7 @@ export type TypeMetadata<T = any> = {
59
59
  export type TypeParams = {
60
60
  encode?: (value: any) => any
61
61
  metadata?: TypeMetadata
62
+ checks: Array<core.CheckFn<any> | core.$ZodCheck<any>>
62
63
  }
63
64
 
64
65
  export type DefaultTypeParams = {
@@ -90,18 +91,18 @@ export abstract class BaseType<
90
91
  encodedZodType,
91
92
  decodedZodType = encodedZodType as unknown as DecodedZodType,
92
93
  props = {} as Props,
93
- params = {} as TypeParams,
94
+ params = {} as Partial<TypeParams>,
94
95
  }: {
95
96
  encodedZodType: EncodedZodType
96
97
  decodedZodType?: DecodedZodType
97
98
  props?: Props
98
- params?: TypeParams
99
+ params?: Partial<TypeParams>
99
100
  }) {
100
101
  this.encodedZodType = encodedZodType
101
102
  this.decodedZodType = decodedZodType
102
103
 
103
104
  this.props = props
104
- this.params = params
105
+ this.params = Object.assign({ checks: [] }, params)
105
106
  }
106
107
 
107
108
  optional(): OptionalType<this> {
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  any,
3
+ type core,
3
4
  custom,
4
5
  overwrite,
5
6
  pipe,
@@ -15,37 +16,50 @@ export type CustomTypeEncode<I, O> = (value: I) => O
15
16
  export abstract class TransformType<
16
17
  Type,
17
18
  EncodedType extends SimpleZodType = ZodMiniAny,
18
- DecodedType extends ZodType = ZodMiniCustom<Type>,
19
- > extends BaseType<EncodedType, DecodedType> {}
19
+ DecodedType extends ZodType = ZodMiniCustom<Type, Type>,
20
+ > extends BaseType<
21
+ ZodMiniPipe<
22
+ ZodMiniCustom<DecodedType['_zod']['output'], DecodedType['_zod']['input']>,
23
+ EncodedType
24
+ >,
25
+ ZodMiniPipe<
26
+ EncodedType,
27
+ ZodMiniCustom<EncodedType['_zod']['output'], EncodedType['_zod']['input']>
28
+ >
29
+ > {}
20
30
 
21
31
  export class CustomType<
22
32
  Type,
23
33
  EncodedType extends SimpleZodType = ZodMiniAny,
24
34
  DecodedType extends ZodType = ZodMiniCustom<Type, Type>,
25
- > extends BaseType<
26
- ZodMiniPipe<DecodedType, EncodedType>,
27
- ZodMiniPipe<EncodedType, DecodedType>
28
- > {
35
+ > extends TransformType<Type, EncodedType, DecodedType> {
29
36
  static factory<
30
37
  Type,
31
38
  EncodedType extends SimpleZodType = ZodMiniAny,
32
- DecodedType extends ZodType = ZodMiniCustom<Type>,
33
- >(
39
+ DecodedType extends ZodType = ZodMiniCustom<Type, Type>,
40
+ >({
41
+ decode,
42
+ encode,
43
+ error,
44
+ type = any() as unknown as EncodedType,
45
+ }: {
34
46
  decode: CustomTypeDecode<
35
- EncodedType['_zod']['output'],
47
+ EncodedType['_zod']['input'],
36
48
  DecodedType['_zod']['output']
37
- >,
49
+ >
38
50
  encode: CustomTypeEncode<
39
- DecodedType['_zod']['output'],
51
+ DecodedType['_zod']['input'],
40
52
  EncodedType['_zod']['output']
41
- >,
42
- type: EncodedType = any() as unknown as EncodedType,
43
- ) {
53
+ >
54
+ error?: string | core.$ZodErrorMap<core.$ZodIssueBase>
55
+ type?: EncodedType
56
+ }) {
44
57
  return new CustomType<Type, EncodedType, DecodedType>({
45
- //@ts-expect-error
46
58
  encodedZodType: pipe(custom().check(overwrite(encode)), type),
47
- //@ts-expect-error
48
- decodedZodType: pipe(type, custom().check(overwrite(decode))),
59
+ decodedZodType: pipe(
60
+ type,
61
+ custom(undefined, { error }).check(overwrite(decode)),
62
+ ),
49
63
  params: { encode },
50
64
  })
51
65
  }
package/src/types/date.ts CHANGED
@@ -1,15 +1,6 @@
1
- import {
2
- date,
3
- iso,
4
- union,
5
- type ZodMiniDate,
6
- type ZodMiniUnion,
7
- } from '@zod/mini'
1
+ import { iso, union, type ZodMiniUnion } from '@zod/mini'
8
2
  import { CustomType, TransformType } from './custom.ts'
9
3
 
10
- const decode = (value: string): Date => new Date(value)
11
- const encode = (value: Date): string => value.toISOString()
12
-
13
4
  export class DateType extends TransformType<
14
5
  Date,
15
6
  ZodMiniUnion<[iso.ZodMiniISODate, iso.ZodMiniISODateTime]>
@@ -18,6 +9,10 @@ export class DateType extends TransformType<
18
9
  return CustomType.factory<
19
10
  Date,
20
11
  ZodMiniUnion<Array<iso.ZodMiniISODate | iso.ZodMiniISODateTime>>
21
- >(decode, encode, union([iso.datetime(), iso.date()]))
12
+ >({
13
+ decode: (value: string): Date => new Date(value),
14
+ encode: (value: Date): string => value.toISOString(),
15
+ type: union([iso.datetime(), iso.date()]),
16
+ })
22
17
  }
23
18
  }
@@ -6,45 +6,49 @@ import {
6
6
  lt,
7
7
  lte,
8
8
  number,
9
+ regex,
10
+ string,
9
11
  type ZodMiniNumber,
12
+ type ZodMiniString,
10
13
  } from '@zod/mini'
11
14
  import { BaseType } from './base.ts'
15
+ import { CustomType, TransformType } from './custom.ts'
12
16
 
13
17
  type Check = core.CheckFn<number> | core.$ZodCheck<number>
14
18
 
15
19
  export class NumberType extends BaseType<
16
20
  ZodMiniNumber<number>,
17
- ZodMiniNumber<number>,
18
- { checks: Check[] }
21
+ ZodMiniNumber<number>
19
22
  > {
20
23
  static factory(...checks: Check[]) {
21
24
  return new NumberType({
22
25
  encodedZodType: number().check(...checks),
26
+ params: { checks },
23
27
  })
24
28
  }
25
29
 
26
30
  positive() {
27
- return NumberType.factory(...this.props.checks, gte(0))
31
+ return NumberType.factory(...this.params.checks, gte(0))
28
32
  }
29
33
 
30
34
  negative() {
31
- return NumberType.factory(...this.props.checks, lte(0))
35
+ return NumberType.factory(...this.params.checks, lte(0))
32
36
  }
33
37
 
34
38
  lt(value: number) {
35
- return NumberType.factory(...this.props.checks, lt(value))
39
+ return NumberType.factory(...this.params.checks, lt(value))
36
40
  }
37
41
 
38
42
  lte(value: number) {
39
- return NumberType.factory(...this.props.checks, lte(value))
43
+ return NumberType.factory(...this.params.checks, lte(value))
40
44
  }
41
45
 
42
46
  gte(value: number) {
43
- return NumberType.factory(...this.props.checks, gte(value))
47
+ return NumberType.factory(...this.params.checks, gte(value))
44
48
  }
45
49
 
46
50
  gt(value: number) {
47
- return NumberType.factory(...this.props.checks, gt(value))
51
+ return NumberType.factory(...this.params.checks, gt(value))
48
52
  }
49
53
  }
50
54
 
@@ -53,3 +57,14 @@ export class IntegerType extends NumberType {
53
57
  return NumberType.factory(...checks, int())
54
58
  }
55
59
  }
60
+
61
+ export class BigIntType extends TransformType<bigint, ZodMiniString<string>> {
62
+ static factory() {
63
+ return CustomType.factory<bigint, ZodMiniString<string>>({
64
+ decode: (value) => BigInt(value),
65
+ encode: (value) => value.toString(),
66
+ type: string().check(regex(/^-?\d+$/)),
67
+ error: 'Invalid bigint format',
68
+ })
69
+ }
70
+ }
@@ -2,6 +2,7 @@ import {
2
2
  type core,
3
3
  object,
4
4
  record,
5
+ strictObject,
5
6
  type ZodMiniObject,
6
7
  type ZodMiniRecord,
7
8
  } from '@zod/mini'
@@ -14,8 +15,8 @@ import type { StringType } from './string.ts'
14
15
  export type ObjectTypeProps = { [k: string]: BaseTypeAny }
15
16
  export type AnyObjectType = ObjectType<ObjectTypeProps>
16
17
  export class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<
17
- ZodMiniObject<{ [K in keyof T]: T[K]['encodedZodType'] }>,
18
- ZodMiniObject<{ [K in keyof T]: T[K]['decodedZodType'] }>,
18
+ ZodMiniObject<{ [K in keyof T]: T[K]['encodedZodType'] }, {}>,
19
+ ZodMiniObject<{ [K in keyof T]: T[K]['decodedZodType'] }, {}>,
19
20
  { properties: T }
20
21
  > {
21
22
  static factory<T extends ObjectTypeProps = {}>(properties: T) {
@@ -1,10 +1,16 @@
1
1
  import {
2
2
  type core,
3
+ cuid,
4
+ cuid2,
5
+ e164,
3
6
  email,
7
+ emoji,
4
8
  ipv4,
5
9
  ipv6,
10
+ jwt,
6
11
  maxLength,
7
12
  minLength,
13
+ nanoid,
8
14
  regex,
9
15
  string,
10
16
  url,
@@ -18,48 +24,71 @@ type Check = core.CheckFn<string> | core.$ZodCheck<string>
18
24
 
19
25
  export class StringType extends BaseType<
20
26
  ZodMiniString<string>,
21
- ZodMiniString<string>,
22
- { checks: Check[] }
27
+ ZodMiniString<string>
23
28
  > {
24
29
  static factory(...checks: Check[]) {
25
30
  return new StringType({
26
31
  encodedZodType: string().check(...checks),
27
- props: { checks },
32
+ params: { checks },
28
33
  })
29
34
  }
30
35
 
31
36
  max(value: number) {
32
- return StringType.factory(...this.props.checks, maxLength(value))
37
+ return StringType.factory(...this.params.checks, maxLength(value))
33
38
  }
34
39
 
35
40
  min(value: number) {
36
- return StringType.factory(...this.props.checks, minLength(value))
41
+ return StringType.factory(...this.params.checks, minLength(value))
37
42
  }
38
43
 
39
44
  pattern(pattern: string | RegExp) {
40
45
  return StringType.factory(
41
- ...this.props.checks,
46
+ ...this.params.checks,
42
47
  regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern),
43
48
  )
44
49
  }
45
50
 
46
51
  email(options?: core.$ZodEmailParams) {
47
- return StringType.factory(...this.props.checks, email(options))
52
+ return StringType.factory(...this.params.checks, email(options))
48
53
  }
49
54
 
50
55
  url(options?: core.$ZodURLParams) {
51
- return StringType.factory(...this.props.checks, url(options))
56
+ return StringType.factory(...this.params.checks, url(options))
52
57
  }
53
58
 
54
59
  ipv4(options?: core.$ZodIPv4Params) {
55
- return StringType.factory(...this.props.checks, ipv4(options))
60
+ return StringType.factory(...this.params.checks, ipv4(options))
56
61
  }
57
62
 
58
63
  ipv6(options?: core.$ZodIPv6Params) {
59
- return StringType.factory(...this.props.checks, ipv6(options))
64
+ return StringType.factory(...this.params.checks, ipv6(options))
60
65
  }
61
66
 
62
67
  uuid(options?: core.$ZodUUIDParams) {
63
- return StringType.factory(...this.props.checks, uuid(options))
68
+ return StringType.factory(...this.params.checks, uuid(options))
69
+ }
70
+
71
+ emoji(options?: core.$ZodEmojiParams) {
72
+ return StringType.factory(...this.params.checks, emoji(options))
73
+ }
74
+
75
+ nanoid(options?: core.$ZodNanoIDParams) {
76
+ return StringType.factory(...this.params.checks, nanoid(options))
77
+ }
78
+
79
+ cuid(options?: core.$ZodCUIDParams) {
80
+ return StringType.factory(...this.params.checks, cuid(options))
81
+ }
82
+
83
+ cuid2(options?: core.$ZodCUID2Params) {
84
+ return StringType.factory(...this.params.checks, cuid2(options))
85
+ }
86
+
87
+ e164(options?: core.$ZodE164Params) {
88
+ return StringType.factory(...this.params.checks, e164(options))
89
+ }
90
+
91
+ jwt(options?: core.$ZodJWTParams) {
92
+ return StringType.factory(...this.params.checks, jwt(options))
64
93
  }
65
94
  }
@@ -1,9 +1,4 @@
1
- import {
2
- custom,
3
- string,
4
- type ZodMiniCustom,
5
- type ZodMiniString,
6
- } from '@zod/mini'
1
+ import { iso, regex, string, type ZodMiniString } from '@zod/mini'
7
2
  import { Temporal } from 'temporal-polyfill'
8
3
  import { CustomType, TransformType } from './custom.ts'
9
4
 
@@ -34,137 +29,118 @@ const createTemporalTransformer = <T extends Types>(
34
29
  } as TemporalTransformer<T>
35
30
  }
36
31
 
32
+ type EncodedType = ZodMiniString<string>
33
+
37
34
  export class PlainDateType extends TransformType<
38
35
  Temporal.PlainDate,
39
- ZodMiniString
36
+ EncodedType
40
37
  > {
41
38
  static transformer = createTemporalTransformer('PlainDate')
42
39
 
43
40
  static factory() {
44
- return CustomType.factory<
45
- Temporal.PlainDate,
46
- ZodMiniString,
47
- ZodMiniCustom<Temporal.PlainDate, Temporal.PlainDate>
48
- >(
49
- PlainDateType.transformer.decode,
50
- PlainDateType.transformer.encode,
51
- string(),
52
- )
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
+ })
53
47
  }
54
48
  }
55
49
 
56
50
  export class PlainDateTimeType extends TransformType<
57
51
  Temporal.PlainDateTime,
58
- ZodMiniString
52
+ EncodedType
59
53
  > {
60
54
  static transformer = createTemporalTransformer('PlainDateTime')
61
55
 
62
56
  static factory() {
63
- return CustomType.factory<
64
- Temporal.PlainDateTime,
65
- ZodMiniString,
66
- ZodMiniCustom<Temporal.PlainDateTime, Temporal.PlainDateTime>
67
- >(
68
- PlainDateTimeType.transformer.decode,
69
- PlainDateTimeType.transformer.encode,
70
- string(),
71
- )
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
+ })
72
63
  }
73
64
  }
74
65
 
75
66
  export class ZonedDateTimeType extends TransformType<
76
67
  Temporal.ZonedDateTime,
77
- ZodMiniString
68
+ EncodedType
78
69
  > {
79
70
  static transformer = createTemporalTransformer('ZonedDateTime', (value) =>
80
71
  Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),
81
72
  )
82
73
 
83
74
  static factory() {
84
- return CustomType.factory<
85
- Temporal.ZonedDateTime,
86
- ZodMiniString,
87
- ZodMiniCustom<Temporal.ZonedDateTime, Temporal.ZonedDateTime>
88
- >(
89
- ZonedDateTimeType.transformer.decode,
90
- ZonedDateTimeType.transformer.encode,
91
- string(),
92
- )
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
+ })
93
81
  }
94
82
  }
95
83
 
96
84
  export class PlainTimeType extends TransformType<
97
85
  Temporal.PlainTime,
98
- ZodMiniString
86
+ EncodedType
99
87
  > {
100
88
  static transformer = createTemporalTransformer('PlainTime')
101
89
 
102
90
  static factory() {
103
- return CustomType.factory<
104
- Temporal.PlainTime,
105
- ZodMiniString,
106
- ZodMiniCustom<Temporal.PlainTime, Temporal.PlainTime>
107
- >(
108
- PlainTimeType.transformer.decode,
109
- PlainTimeType.transformer.encode,
110
- string(),
111
- )
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
+ })
112
97
  }
113
98
  }
114
99
 
115
100
  export class DurationType extends TransformType<
116
101
  Temporal.Duration,
117
- ZodMiniString
102
+ EncodedType
118
103
  > {
119
104
  static transformer = createTemporalTransformer('Duration')
120
105
 
121
106
  static factory() {
122
- return CustomType.factory<
123
- Temporal.Duration,
124
- ZodMiniString,
125
- ZodMiniCustom<Temporal.Duration, Temporal.Duration>
126
- >(
127
- DurationType.transformer.decode,
128
- DurationType.transformer.encode,
129
- string(),
130
- )
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
+ })
131
113
  }
132
114
  }
133
115
 
134
116
  export class PlainYearMonthType extends TransformType<
135
117
  Temporal.PlainYearMonth,
136
- ZodMiniString
118
+ EncodedType
137
119
  > {
138
120
  static transformer = createTemporalTransformer('PlainYearMonth')
139
121
 
140
122
  static factory() {
141
- return CustomType.factory<
142
- Temporal.PlainYearMonth,
143
- ZodMiniString,
144
- ZodMiniCustom<Temporal.PlainYearMonth, Temporal.PlainYearMonth>
145
- >(
146
- PlainYearMonthType.transformer.decode,
147
- PlainYearMonthType.transformer.encode,
148
- string(),
149
- )
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
+ })
150
129
  }
151
130
  }
152
131
 
153
132
  export class PlainMonthDayType extends TransformType<
154
133
  Temporal.PlainMonthDay,
155
- ZodMiniString
134
+ EncodedType
156
135
  > {
157
136
  static transformer = createTemporalTransformer('PlainMonthDay')
158
137
 
159
138
  static factory() {
160
- return CustomType.factory<
161
- Temporal.PlainMonthDay,
162
- ZodMiniString,
163
- ZodMiniCustom<Temporal.PlainMonthDay, Temporal.PlainMonthDay>
164
- >(
165
- PlainMonthDayType.transformer.decode,
166
- PlainMonthDayType.transformer.encode,
167
- string(),
168
- )
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
+ })
169
145
  }
170
146
  }
@@ -39,15 +39,10 @@ export class IntersactionType<
39
39
  static factory<
40
40
  T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],
41
41
  >(...options: T) {
42
+ const [first, second] = options
42
43
  return new IntersactionType<T>({
43
- encodedZodType: intersection(
44
- options[0].encodedZodType,
45
- options[1].encodedZodType,
46
- ),
47
- decodedZodType: intersection(
48
- options[0].decodedZodType,
49
- options[1].decodedZodType,
50
- ),
44
+ encodedZodType: intersection(first.encodedZodType, second.encodedZodType),
45
+ decodedZodType: intersection(first.decodedZodType, second.decodedZodType),
51
46
  props: { options },
52
47
  })
53
48
  }
package/dist/utils.js DELETED
File without changes