@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.
Files changed (55) hide show
  1. package/dist/index.js +4 -46
  2. package/dist/index.js.map +1 -1
  3. package/dist/temporal.js +1 -8
  4. package/dist/temporal.js.map +1 -1
  5. package/dist/types/any.js +3 -2
  6. package/dist/types/any.js.map +1 -1
  7. package/dist/types/array.js +7 -6
  8. package/dist/types/array.js.map +1 -1
  9. package/dist/types/base.js +7 -7
  10. package/dist/types/base.js.map +1 -1
  11. package/dist/types/boolean.js +3 -2
  12. package/dist/types/boolean.js.map +1 -1
  13. package/dist/types/custom.js +13 -8
  14. package/dist/types/custom.js.map +1 -1
  15. package/dist/types/date.js +3 -2
  16. package/dist/types/date.js.map +1 -1
  17. package/dist/types/enum.js +4 -2
  18. package/dist/types/enum.js.map +1 -1
  19. package/dist/types/literal.js +3 -2
  20. package/dist/types/literal.js.map +1 -1
  21. package/dist/types/never.js +3 -2
  22. package/dist/types/never.js.map +1 -1
  23. package/dist/types/number.js +13 -10
  24. package/dist/types/number.js.map +1 -1
  25. package/dist/types/object.js +7 -5
  26. package/dist/types/object.js.map +1 -1
  27. package/dist/types/string.js +17 -16
  28. package/dist/types/string.js.map +1 -1
  29. package/dist/types/temporal.js +8 -1
  30. package/dist/types/temporal.js.map +1 -1
  31. package/dist/types/tuple.js +4 -3
  32. package/dist/types/tuple.js.map +1 -1
  33. package/dist/types/type.js +15 -0
  34. package/dist/types/type.js.map +1 -0
  35. package/dist/types/union.js +12 -7
  36. package/dist/types/union.js.map +1 -1
  37. package/package.json +7 -7
  38. package/src/index.ts +4 -97
  39. package/src/temporal.ts +1 -27
  40. package/src/types/any.ts +5 -3
  41. package/src/types/array.ts +11 -16
  42. package/src/types/base.ts +35 -61
  43. package/src/types/boolean.ts +5 -3
  44. package/src/types/custom.ts +37 -31
  45. package/src/types/date.ts +8 -4
  46. package/src/types/enum.ts +11 -7
  47. package/src/types/literal.ts +5 -3
  48. package/src/types/never.ts +5 -3
  49. package/src/types/number.ts +22 -27
  50. package/src/types/object.ts +21 -17
  51. package/src/types/string.ts +32 -48
  52. package/src/types/temporal.ts +9 -1
  53. package/src/types/tuple.ts +9 -7
  54. package/src/types/type.ts +31 -0
  55. package/src/types/union.ts +25 -21
@@ -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
@@ -1,5 +1,5 @@
1
1
  import type { ArrayMap } from '@nmtjs/common'
2
- import { tuple, type ZodMiniTuple } from '@zod/mini'
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
+ }
@@ -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(first.encodedZodType, second.encodedZodType),
60
- decodedZodType: intersection(first.decodedZodType, second.decodedZodType),
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