@nmtjs/type 0.15.0-beta.9 → 0.15.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/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/standart-schema.d.ts +12 -0
- package/dist/standart-schema.js +103 -0
- package/dist/standart-schema.js.map +1 -0
- package/dist/temporal/global.d.ts +2 -2
- package/dist/temporal/global.js +9 -9
- package/dist/temporal/global.js.map +1 -1
- package/dist/temporal/index.d.ts +9 -0
- package/dist/temporal/index.js +10 -0
- package/dist/temporal/index.js.map +1 -0
- package/dist/temporal/polyfill.d.ts +10 -8
- package/dist/temporal/polyfill.js +25 -8
- package/dist/temporal/polyfill.js.map +1 -1
- package/dist/types/_convert.js +11 -11
- package/dist/types/_convert.js.map +1 -1
- package/dist/types/_metadata.d.ts +8 -0
- package/dist/types/_metadata.js +3 -0
- package/dist/types/_metadata.js.map +1 -0
- package/dist/types/_type.d.ts +2 -0
- package/dist/types/_type.js +16 -14
- package/dist/types/_type.js.map +1 -1
- package/dist/types/any.js +1 -1
- package/dist/types/any.js.map +1 -1
- package/dist/types/array.js +1 -1
- package/dist/types/array.js.map +1 -1
- package/dist/types/base.d.ts +9 -9
- package/dist/types/base.js +10 -2
- package/dist/types/base.js.map +1 -1
- package/dist/types/boolean.js +1 -1
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/custom.d.ts +5 -5
- package/dist/types/custom.js +1 -1
- package/dist/types/custom.js.map +1 -1
- package/dist/types/date.js +1 -1
- package/dist/types/date.js.map +1 -1
- package/dist/types/enum.js +1 -1
- package/dist/types/enum.js.map +1 -1
- package/dist/types/literal.js +1 -1
- package/dist/types/literal.js.map +1 -1
- package/dist/types/never.js +1 -1
- package/dist/types/never.js.map +1 -1
- package/dist/types/null.js +1 -1
- package/dist/types/null.js.map +1 -1
- package/dist/types/number.js +2 -2
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +3 -3
- package/dist/types/object.js.map +1 -1
- package/dist/types/string.d.ts +2 -0
- package/dist/types/string.js +8 -2
- package/dist/types/string.js.map +1 -1
- package/dist/types/temporal.d.ts +17 -15
- package/dist/types/temporal.js +21 -11
- package/dist/types/temporal.js.map +1 -1
- package/dist/types/tuple.js +1 -1
- package/dist/types/tuple.js.map +1 -1
- package/dist/types/union.js +1 -1
- package/dist/types/union.js.map +1 -1
- package/dist/types/unknown.d.ts +6 -0
- package/dist/types/unknown.js +9 -0
- package/dist/types/unknown.js.map +1 -0
- package/package.json +35 -16
- package/src/index.ts +1 -0
- package/src/standart-schema.ts +146 -0
- package/src/temporal/global.ts +12 -9
- package/src/temporal/index.ts +20 -0
- package/src/temporal/polyfill.ts +60 -7
- package/src/types/_metadata.ts +12 -0
- package/src/types/_type.ts +9 -0
- package/src/types/base.ts +17 -11
- package/src/types/custom.ts +4 -5
- package/src/types/string.ts +10 -0
- package/src/types/temporal.ts +82 -61
- package/src/types/unknown.ts +12 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DurationType,
|
|
3
|
+
InstantType,
|
|
4
|
+
PlainDateTimeType,
|
|
5
|
+
PlainDateType,
|
|
6
|
+
PlainMonthDayType,
|
|
7
|
+
PlainTimeType,
|
|
8
|
+
PlainYearMonthType,
|
|
9
|
+
ZonedDateTimeType,
|
|
10
|
+
} from '../types/temporal.ts'
|
|
11
|
+
|
|
12
|
+
export const plainDate = PlainDateType.factory.bind(PlainDateType)
|
|
13
|
+
export const plainDatetime = PlainDateTimeType.factory.bind(PlainDateTimeType)
|
|
14
|
+
export const plainTime = PlainTimeType.factory.bind(PlainTimeType)
|
|
15
|
+
export const zonedDatetime = ZonedDateTimeType.factory.bind(ZonedDateTimeType)
|
|
16
|
+
export const instant = InstantType.factory.bind(InstantType)
|
|
17
|
+
export const duration = DurationType.factory.bind(DurationType)
|
|
18
|
+
export const plainYearMonth =
|
|
19
|
+
PlainYearMonthType.factory.bind(PlainYearMonthType)
|
|
20
|
+
export const plainMonthDay = PlainMonthDayType.factory.bind(PlainMonthDayType)
|
package/src/temporal/polyfill.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Temporal } from 'temporal-polyfill'
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
DurationType,
|
|
5
|
+
InstantType,
|
|
5
6
|
PlainDateTimeType,
|
|
6
7
|
PlainDateType,
|
|
7
8
|
PlainMonthDayType,
|
|
@@ -10,22 +11,74 @@ import {
|
|
|
10
11
|
ZonedDateTimeType,
|
|
11
12
|
} from '../types/temporal.ts'
|
|
12
13
|
|
|
13
|
-
export const plainDate = PlainDateType.factory.bind(
|
|
14
|
+
export const plainDate = PlainDateType.factory.bind(
|
|
15
|
+
PlainDateType,
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
Temporal,
|
|
18
|
+
) as () => PlainDateType<
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
typeof Temporal
|
|
21
|
+
>
|
|
22
|
+
|
|
14
23
|
export const plainDatetime = PlainDateTimeType.factory.bind(
|
|
15
24
|
PlainDateTimeType,
|
|
25
|
+
// @ts-expect-error
|
|
16
26
|
Temporal,
|
|
17
|
-
)
|
|
18
|
-
|
|
27
|
+
) as () => PlainDateTimeType<
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
typeof Temporal
|
|
30
|
+
>
|
|
31
|
+
|
|
32
|
+
export const plainTime = PlainTimeType.factory.bind(
|
|
33
|
+
PlainTimeType,
|
|
34
|
+
// @ts-expect-error
|
|
35
|
+
Temporal,
|
|
36
|
+
) as () => PlainTimeType<
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
typeof Temporal
|
|
39
|
+
>
|
|
40
|
+
|
|
19
41
|
export const zonedDatetime = ZonedDateTimeType.factory.bind(
|
|
20
42
|
ZonedDateTimeType,
|
|
43
|
+
// @ts-expect-error
|
|
21
44
|
Temporal,
|
|
22
|
-
)
|
|
23
|
-
|
|
45
|
+
) as () => ZonedDateTimeType<
|
|
46
|
+
// @ts-expect-error
|
|
47
|
+
typeof Temporal
|
|
48
|
+
>
|
|
49
|
+
|
|
50
|
+
export const instant = InstantType.factory.bind(
|
|
51
|
+
InstantType,
|
|
52
|
+
// @ts-expect-error
|
|
53
|
+
Temporal,
|
|
54
|
+
) as () => InstantType<
|
|
55
|
+
// @ts-expect-error
|
|
56
|
+
typeof Temporal
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
export const duration = DurationType.factory.bind(
|
|
60
|
+
DurationType,
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
Temporal,
|
|
63
|
+
) as () => DurationType<
|
|
64
|
+
// @ts-expect-error
|
|
65
|
+
typeof Temporal
|
|
66
|
+
>
|
|
67
|
+
|
|
24
68
|
export const plainYearMonth = PlainYearMonthType.factory.bind(
|
|
25
69
|
PlainYearMonthType,
|
|
70
|
+
// @ts-expect-error
|
|
26
71
|
Temporal,
|
|
27
|
-
)
|
|
72
|
+
) as () => PlainYearMonthType<
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
typeof Temporal
|
|
75
|
+
>
|
|
76
|
+
|
|
28
77
|
export const plainMonthDay = PlainMonthDayType.factory.bind(
|
|
29
78
|
PlainMonthDayType,
|
|
79
|
+
// @ts-expect-error
|
|
30
80
|
Temporal,
|
|
31
|
-
)
|
|
81
|
+
) as () => PlainMonthDayType<
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
typeof Temporal
|
|
84
|
+
>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { registry } from 'zod/mini'
|
|
2
|
+
|
|
3
|
+
export type TypeMetadata<T = any> = {
|
|
4
|
+
id?: string
|
|
5
|
+
description?: string
|
|
6
|
+
examples?: T[]
|
|
7
|
+
title?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const typesRegistry = registry<TypeMetadata>()
|
|
11
|
+
|
|
12
|
+
export type MetadataRegistry = typeof typesRegistry
|
package/src/types/_type.ts
CHANGED
|
@@ -2,6 +2,14 @@ import type { BaseTypeAny } from './base.ts'
|
|
|
2
2
|
|
|
3
3
|
export * from './any.ts'
|
|
4
4
|
export * from './array.ts'
|
|
5
|
+
export {
|
|
6
|
+
BaseType,
|
|
7
|
+
type BaseTypeAny,
|
|
8
|
+
DefaultType,
|
|
9
|
+
NeemataTypeError,
|
|
10
|
+
NullableType,
|
|
11
|
+
OptionalType,
|
|
12
|
+
} from './base.ts'
|
|
5
13
|
export * from './boolean.ts'
|
|
6
14
|
export * from './custom.ts'
|
|
7
15
|
export * from './date.ts'
|
|
@@ -14,6 +22,7 @@ export * from './object.ts'
|
|
|
14
22
|
export * from './string.ts'
|
|
15
23
|
export * from './tuple.ts'
|
|
16
24
|
export * from './union.ts'
|
|
25
|
+
export * from './unknown.ts'
|
|
17
26
|
|
|
18
27
|
export namespace infer {
|
|
19
28
|
export namespace decode {
|
package/src/types/base.ts
CHANGED
|
@@ -16,7 +16,11 @@ import type {
|
|
|
16
16
|
ZodMiniType,
|
|
17
17
|
ZodMiniUnion,
|
|
18
18
|
} from 'zod/mini'
|
|
19
|
-
import { _default, core, nullable, optional
|
|
19
|
+
import { _default, core, nullable, optional } from 'zod/mini'
|
|
20
|
+
|
|
21
|
+
import type { TypeMetadata } from './_metadata.ts'
|
|
22
|
+
import { standard } from '../standart-schema.ts'
|
|
23
|
+
import { typesRegistry } from './_metadata.ts'
|
|
20
24
|
|
|
21
25
|
export type PrimitiveValueType = string | number | boolean | null
|
|
22
26
|
|
|
@@ -43,13 +47,6 @@ export type ZodType = SimpleZodType | ZodMiniType
|
|
|
43
47
|
|
|
44
48
|
export type TypeProps = Record<string, any>
|
|
45
49
|
|
|
46
|
-
export type TypeMetadata<T = any> = {
|
|
47
|
-
id?: string
|
|
48
|
-
description?: string
|
|
49
|
-
examples?: T[]
|
|
50
|
-
title?: string
|
|
51
|
-
}
|
|
52
|
-
|
|
53
50
|
export type TypeParams = {
|
|
54
51
|
encode?: (value: any) => any
|
|
55
52
|
metadata?: TypeMetadata
|
|
@@ -66,8 +63,6 @@ export type BaseTypeAny<
|
|
|
66
63
|
DecodedZodType extends ZodType = ZodMiniType,
|
|
67
64
|
> = BaseType<EncodedZodType, DecodedZodType, TypeProps>
|
|
68
65
|
|
|
69
|
-
export const typesRegistry = registry<TypeMetadata>()
|
|
70
|
-
|
|
71
66
|
export const NeemataTypeError = core.$ZodError
|
|
72
67
|
export type NeemataTypeError = core.$ZodError
|
|
73
68
|
|
|
@@ -77,13 +72,19 @@ export abstract class BaseType<
|
|
|
77
72
|
Props extends TypeProps = TypeProps,
|
|
78
73
|
RawEncodeZodType extends SimpleZodType = EncodeZodType,
|
|
79
74
|
RawDecodeZodType extends ZodType = DecodeZodType,
|
|
80
|
-
>
|
|
75
|
+
> implements standard.Schema<DecodeZodType>
|
|
76
|
+
{
|
|
81
77
|
readonly encodeZodType: EncodeZodType
|
|
82
78
|
readonly decodeZodType: DecodeZodType
|
|
83
79
|
readonly encodeRawZodType!: RawEncodeZodType
|
|
84
80
|
readonly decodeRawZodType!: RawDecodeZodType
|
|
85
81
|
readonly props: Props
|
|
86
82
|
readonly params: TypeParams
|
|
83
|
+
readonly standard: {
|
|
84
|
+
encode: standard.Schema<EncodeZodType>
|
|
85
|
+
decode: standard.Schema<DecodeZodType>
|
|
86
|
+
}
|
|
87
|
+
readonly '~standard': standard.Props<DecodeZodType>
|
|
87
88
|
|
|
88
89
|
constructor({
|
|
89
90
|
encodeZodType,
|
|
@@ -101,6 +102,11 @@ export abstract class BaseType<
|
|
|
101
102
|
|
|
102
103
|
this.props = props
|
|
103
104
|
this.params = Object.assign({ checks: [] }, params)
|
|
105
|
+
this.standard = {
|
|
106
|
+
encode: standard.encode(this, typesRegistry),
|
|
107
|
+
decode: standard.decode(this, typesRegistry),
|
|
108
|
+
}
|
|
109
|
+
this['~standard'] = this.standard.decode['~standard']
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
optional(): OptionalType<this> {
|
package/src/types/custom.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MaybePromise } from '@nmtjs/common'
|
|
2
2
|
import type { core, ZodMiniType } from 'zod/mini'
|
|
3
3
|
import {
|
|
4
4
|
any,
|
|
@@ -50,20 +50,19 @@ export class CustomType<
|
|
|
50
50
|
validation?:
|
|
51
51
|
| ((
|
|
52
52
|
value: EncodeType['_zod']['input'] | DecodeType['_zod']['output'],
|
|
53
|
-
|
|
54
53
|
payload: core.$RefinementCtx<
|
|
55
54
|
EncodeType['_zod']['output'] | DecodeType['_zod']['output']
|
|
56
55
|
>,
|
|
57
|
-
) =>
|
|
56
|
+
) => MaybePromise<void>)
|
|
58
57
|
| {
|
|
59
58
|
encode?: (
|
|
60
59
|
value: EncodeType['_zod']['input'],
|
|
61
60
|
payload: core.$RefinementCtx<EncodeType['_zod']['output']>,
|
|
62
|
-
) =>
|
|
61
|
+
) => MaybePromise<void>
|
|
63
62
|
decode?: (
|
|
64
63
|
value: DecodeType['_zod']['output'],
|
|
65
64
|
payload: core.$RefinementCtx<DecodeType['_zod']['output']>,
|
|
66
|
-
) =>
|
|
65
|
+
) => MaybePromise<void>
|
|
67
66
|
}
|
|
68
67
|
error?: string | core.$ZodErrorMap<core.$ZodIssueBase>
|
|
69
68
|
type?: EncodeType
|
package/src/types/string.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { core, ZodMiniString } from 'zod/mini'
|
|
2
2
|
import {
|
|
3
|
+
base64,
|
|
4
|
+
base64url,
|
|
3
5
|
cuid,
|
|
4
6
|
cuid2,
|
|
5
7
|
e164,
|
|
@@ -90,6 +92,14 @@ export class StringType extends BaseType<
|
|
|
90
92
|
jwt(options?: core.$ZodJWTParams) {
|
|
91
93
|
return StringType.factory(...this.params.checks, jwt(options))
|
|
92
94
|
}
|
|
95
|
+
|
|
96
|
+
base64(options?: core.$ZodBase64Params) {
|
|
97
|
+
return StringType.factory(...this.params.checks, base64(options))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
base64URL(options?: core.$ZodBase64URLParams) {
|
|
101
|
+
return StringType.factory(...this.params.checks, base64url(options))
|
|
102
|
+
}
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
export const string = StringType.factory
|
package/src/types/temporal.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Temporal } from 'temporal-spec'
|
|
2
1
|
import type { ZodMiniString } from 'zod/mini'
|
|
3
2
|
import { iso, regex, string } from 'zod/mini'
|
|
4
3
|
|
|
@@ -9,34 +8,38 @@ type Types = Exclude<
|
|
|
9
8
|
'Now' | 'Instant' | 'Calendar' | 'TimeZone'
|
|
10
9
|
>
|
|
11
10
|
|
|
12
|
-
type TemporalTransformer<T extends Types> = {
|
|
13
|
-
decode: (value: string) =>
|
|
14
|
-
encode: (value:
|
|
11
|
+
type TemporalTransformer<T extends typeof Temporal, U extends Types> = {
|
|
12
|
+
decode: (value: string) => InstanceType<T[U]>
|
|
13
|
+
encode: (value: InstanceType<T[U]>) => string
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
const createTemporalTransformer = <T extends Types>(
|
|
18
|
-
implementation:
|
|
19
|
-
type:
|
|
20
|
-
decode = (value: string
|
|
21
|
-
|
|
16
|
+
const createTemporalTransformer = <T extends typeof Temporal, U extends Types>(
|
|
17
|
+
implementation: T,
|
|
18
|
+
type: U,
|
|
19
|
+
decode = (value: string | InstanceType<T[U]>) => {
|
|
20
|
+
if (typeof value === 'string') return implementation[type].from(value)
|
|
21
|
+
else return value
|
|
22
|
+
},
|
|
23
|
+
encode = (value: ReturnType<T[U]['from']>) =>
|
|
22
24
|
value.toString({
|
|
23
25
|
calendarName: 'never',
|
|
24
26
|
smallestUnit: 'microsecond',
|
|
25
27
|
timeZoneName: 'never',
|
|
26
28
|
}),
|
|
27
29
|
) => {
|
|
28
|
-
return { decode, encode } as TemporalTransformer<T>
|
|
30
|
+
return { decode, encode } as TemporalTransformer<T, U>
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
type EncodeType = ZodMiniString<string>
|
|
32
34
|
|
|
33
|
-
export class PlainDateType
|
|
34
|
-
Temporal
|
|
35
|
-
|
|
36
|
-
>
|
|
37
|
-
|
|
35
|
+
export class PlainDateType<
|
|
36
|
+
T extends typeof Temporal = typeof Temporal,
|
|
37
|
+
> extends TransformType<InstanceType<T['PlainDate']>, EncodeType> {
|
|
38
|
+
static factory<T extends typeof Temporal>(
|
|
39
|
+
implementation: T,
|
|
40
|
+
): PlainDateType<T> {
|
|
38
41
|
const transformer = createTemporalTransformer(implementation, 'PlainDate')
|
|
39
|
-
return CustomType.factory<
|
|
42
|
+
return CustomType.factory<InstanceType<T['PlainDate']>, EncodeType>({
|
|
40
43
|
decode: transformer.decode,
|
|
41
44
|
encode: transformer.encode,
|
|
42
45
|
type: iso.date(),
|
|
@@ -45,16 +48,17 @@ export class PlainDateType extends TransformType<
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
export class PlainDateTimeType
|
|
49
|
-
Temporal
|
|
50
|
-
|
|
51
|
-
>
|
|
52
|
-
|
|
51
|
+
export class PlainDateTimeType<
|
|
52
|
+
T extends typeof Temporal = typeof Temporal,
|
|
53
|
+
> extends TransformType<InstanceType<T['PlainDateTime']>, EncodeType> {
|
|
54
|
+
static factory<T extends typeof Temporal>(
|
|
55
|
+
implementation: T,
|
|
56
|
+
): PlainDateTimeType<T> {
|
|
53
57
|
const transformer = createTemporalTransformer(
|
|
54
58
|
implementation,
|
|
55
59
|
'PlainDateTime',
|
|
56
60
|
)
|
|
57
|
-
return CustomType.factory<
|
|
61
|
+
return CustomType.factory<InstanceType<T['PlainDateTime']>, EncodeType>({
|
|
58
62
|
decode: transformer.decode,
|
|
59
63
|
encode: transformer.encode,
|
|
60
64
|
type: iso.datetime({ local: true }),
|
|
@@ -63,41 +67,52 @@ export class PlainDateTimeType extends TransformType<
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
export class ZonedDateTimeType
|
|
67
|
-
Temporal
|
|
68
|
-
|
|
69
|
-
>
|
|
70
|
-
|
|
70
|
+
export class ZonedDateTimeType<
|
|
71
|
+
T extends typeof Temporal = typeof Temporal,
|
|
72
|
+
> extends TransformType<InstanceType<T['ZonedDateTime']>, EncodeType> {
|
|
73
|
+
static factory<T extends typeof Temporal>(
|
|
74
|
+
implementation: T,
|
|
75
|
+
): ZonedDateTimeType<T> {
|
|
71
76
|
const transformer = createTemporalTransformer(
|
|
72
77
|
implementation,
|
|
73
78
|
'ZonedDateTime',
|
|
74
|
-
(value) => implementation.
|
|
75
|
-
(value) =>
|
|
76
|
-
value
|
|
77
|
-
.withTimeZone('UTC')
|
|
78
|
-
.toString({
|
|
79
|
-
smallestUnit: 'milliseconds',
|
|
80
|
-
timeZoneName: 'never',
|
|
81
|
-
calendarName: 'never',
|
|
82
|
-
offset: 'never',
|
|
83
|
-
}) + 'Z',
|
|
79
|
+
(value) => implementation.ZonedDateTime.from(value),
|
|
80
|
+
(value) => value.toString({ smallestUnit: 'microsecond' }),
|
|
84
81
|
)
|
|
85
|
-
return CustomType.factory<
|
|
82
|
+
return CustomType.factory<InstanceType<T['ZonedDateTime']>, EncodeType>({
|
|
86
83
|
decode: transformer.decode,
|
|
87
84
|
encode: transformer.encode,
|
|
88
|
-
type:
|
|
89
|
-
error: 'Invalid datetime format',
|
|
85
|
+
type: string(),
|
|
86
|
+
error: 'Invalid zoned datetime format',
|
|
90
87
|
})
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
90
|
|
|
94
|
-
export class
|
|
95
|
-
Temporal
|
|
96
|
-
|
|
97
|
-
> {
|
|
98
|
-
|
|
91
|
+
export class InstantType<
|
|
92
|
+
T extends typeof Temporal = typeof Temporal,
|
|
93
|
+
> extends TransformType<InstanceType<T['Instant']>, EncodeType> {
|
|
94
|
+
static factory<T extends typeof Temporal>(implementation: T): InstantType<T> {
|
|
95
|
+
const decode = (value: string) =>
|
|
96
|
+
implementation.Instant.from(value) as InstanceType<T['Instant']>
|
|
97
|
+
const encode = (value: InstanceType<T['Instant']>) => value.toJSON()
|
|
98
|
+
|
|
99
|
+
return CustomType.factory<InstanceType<T['Instant']>, EncodeType>({
|
|
100
|
+
decode,
|
|
101
|
+
encode,
|
|
102
|
+
type: iso.datetime(),
|
|
103
|
+
error: 'Invalid instant format',
|
|
104
|
+
}) as InstantType<T>
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class PlainTimeType<
|
|
109
|
+
T extends typeof Temporal = typeof Temporal,
|
|
110
|
+
> extends TransformType<InstanceType<T['PlainTime']>, EncodeType> {
|
|
111
|
+
static factory<T extends typeof Temporal>(
|
|
112
|
+
implementation: T,
|
|
113
|
+
): PlainTimeType<T> {
|
|
99
114
|
const transformer = createTemporalTransformer(implementation, 'PlainTime')
|
|
100
|
-
return CustomType.factory<
|
|
115
|
+
return CustomType.factory<InstanceType<T['PlainTime']>, EncodeType>({
|
|
101
116
|
decode: transformer.decode,
|
|
102
117
|
encode: transformer.encode,
|
|
103
118
|
type: iso.time(),
|
|
@@ -106,10 +121,14 @@ export class PlainTimeType extends TransformType<
|
|
|
106
121
|
}
|
|
107
122
|
}
|
|
108
123
|
|
|
109
|
-
export class DurationType
|
|
110
|
-
|
|
124
|
+
export class DurationType<
|
|
125
|
+
T extends typeof Temporal = typeof Temporal,
|
|
126
|
+
> extends TransformType<InstanceType<T['Duration']>, EncodeType> {
|
|
127
|
+
static factory<T extends typeof Temporal>(
|
|
128
|
+
implementation: T,
|
|
129
|
+
): DurationType<T> {
|
|
111
130
|
const transformer = createTemporalTransformer(implementation, 'Duration')
|
|
112
|
-
return CustomType.factory<
|
|
131
|
+
return CustomType.factory<InstanceType<T['Duration']>, EncodeType>({
|
|
113
132
|
decode: transformer.decode,
|
|
114
133
|
encode: transformer.encode,
|
|
115
134
|
type: iso.duration(),
|
|
@@ -118,16 +137,17 @@ export class DurationType extends TransformType<Temporal.Duration, EncodeType> {
|
|
|
118
137
|
}
|
|
119
138
|
}
|
|
120
139
|
|
|
121
|
-
export class PlainYearMonthType
|
|
122
|
-
Temporal
|
|
123
|
-
|
|
124
|
-
>
|
|
125
|
-
|
|
140
|
+
export class PlainYearMonthType<
|
|
141
|
+
T extends typeof Temporal = typeof Temporal,
|
|
142
|
+
> extends TransformType<InstanceType<T['PlainYearMonth']>, EncodeType> {
|
|
143
|
+
static factory<T extends typeof Temporal>(
|
|
144
|
+
implementation: T,
|
|
145
|
+
): PlainYearMonthType<T> {
|
|
126
146
|
const transformer = createTemporalTransformer(
|
|
127
147
|
implementation,
|
|
128
148
|
'PlainYearMonth',
|
|
129
149
|
)
|
|
130
|
-
return CustomType.factory<
|
|
150
|
+
return CustomType.factory<InstanceType<T['PlainYearMonth']>, EncodeType>({
|
|
131
151
|
decode: transformer.decode,
|
|
132
152
|
encode: transformer.encode,
|
|
133
153
|
type: string().check(regex(/^\d{4}-\d{2}$/)),
|
|
@@ -136,16 +156,17 @@ export class PlainYearMonthType extends TransformType<
|
|
|
136
156
|
}
|
|
137
157
|
}
|
|
138
158
|
|
|
139
|
-
export class PlainMonthDayType
|
|
140
|
-
Temporal
|
|
141
|
-
|
|
142
|
-
>
|
|
143
|
-
|
|
159
|
+
export class PlainMonthDayType<
|
|
160
|
+
T extends typeof Temporal = typeof Temporal,
|
|
161
|
+
> extends TransformType<InstanceType<T['PlainMonthDay']>, EncodeType> {
|
|
162
|
+
static factory<T extends typeof Temporal>(
|
|
163
|
+
implementation: T,
|
|
164
|
+
): PlainMonthDayType<T> {
|
|
144
165
|
const transformer = createTemporalTransformer(
|
|
145
166
|
implementation,
|
|
146
167
|
'PlainMonthDay',
|
|
147
168
|
)
|
|
148
|
-
return CustomType.factory<
|
|
169
|
+
return CustomType.factory<InstanceType<T['PlainMonthDay']>, EncodeType>({
|
|
149
170
|
decode: transformer.decode,
|
|
150
171
|
encode: transformer.encode,
|
|
151
172
|
type: string().check(regex(/^\d{2}-\d{2}$/)),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ZodMiniUnknown } from 'zod/mini'
|
|
2
|
+
import { unknown as zodUnknown } from 'zod/mini'
|
|
3
|
+
|
|
4
|
+
import { BaseType } from './base.ts'
|
|
5
|
+
|
|
6
|
+
export class UnknownType extends BaseType<ZodMiniUnknown> {
|
|
7
|
+
static factory() {
|
|
8
|
+
return new UnknownType({ encodeZodType: zodUnknown() })
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const unknown = UnknownType.factory
|