@nmtjs/type 0.13.1 → 0.14.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.d.ts +1 -1
- package/dist/index.js +4 -3
- package/dist/types/{type.d.ts → _type.d.ts} +6 -6
- package/dist/types/any.d.ts +2 -2
- package/dist/types/any.js +2 -4
- package/dist/types/array.d.ts +3 -3
- package/dist/types/array.js +6 -6
- package/dist/types/base.d.ts +23 -22
- package/dist/types/base.js +20 -18
- package/dist/types/boolean.d.ts +2 -2
- package/dist/types/boolean.js +2 -4
- package/dist/types/custom.d.ts +11 -10
- package/dist/types/custom.js +5 -14
- package/dist/types/date.d.ts +4 -3
- package/dist/types/date.js +2 -2
- package/dist/types/enum.d.ts +4 -4
- package/dist/types/enum.js +2 -2
- package/dist/types/literal.d.ts +4 -3
- package/dist/types/literal.js +2 -2
- package/dist/types/never.d.ts +2 -2
- package/dist/types/never.js +2 -4
- package/dist/types/number.d.ts +5 -5
- package/dist/types/number.js +10 -10
- package/dist/types/object.d.ts +11 -10
- package/dist/types/object.js +7 -7
- package/dist/types/string.d.ts +14 -14
- package/dist/types/string.js +16 -16
- package/dist/types/temporal.d.ts +16 -16
- package/dist/types/temporal.js +2 -5
- package/dist/types/tuple.d.ts +2 -2
- package/dist/types/tuple.js +5 -5
- package/dist/types/union.d.ts +6 -5
- package/dist/types/union.js +11 -11
- package/package.json +10 -5
- /package/dist/types/{type.js → _type.js} +0 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { en } from 'zod/locales';
|
|
2
|
+
import { config } from 'zod/mini';
|
|
3
|
+
import * as type from "./types/_type.js";
|
|
4
|
+
config(en());
|
|
4
5
|
export * from "./types/base.js";
|
|
5
6
|
export { type, type as t };
|
|
6
7
|
export default type;
|
|
@@ -13,12 +13,12 @@ export * from './string.ts';
|
|
|
13
13
|
export * from './tuple.ts';
|
|
14
14
|
export * from './union.ts';
|
|
15
15
|
export declare namespace infer {
|
|
16
|
-
namespace
|
|
17
|
-
type input<T extends BaseTypeAny> = T['
|
|
18
|
-
type output<T extends BaseTypeAny> = T['
|
|
16
|
+
namespace decode {
|
|
17
|
+
type input<T extends BaseTypeAny> = T['decodeZodType']['_zod']['input'];
|
|
18
|
+
type output<T extends BaseTypeAny> = T['decodeZodType']['_zod']['output'];
|
|
19
19
|
}
|
|
20
|
-
namespace
|
|
21
|
-
type input<T extends BaseTypeAny> = T['
|
|
22
|
-
type output<T extends BaseTypeAny> = T['
|
|
20
|
+
namespace encode {
|
|
21
|
+
type input<T extends BaseTypeAny> = T['encodeZodType']['_zod']['input'];
|
|
22
|
+
type output<T extends BaseTypeAny> = T['encodeZodType']['_zod']['output'];
|
|
23
23
|
}
|
|
24
24
|
}
|
package/dist/types/any.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ZodMiniAny } from 'zod/mini';
|
|
2
2
|
import { BaseType } from './base.ts';
|
|
3
|
-
export declare class AnyType extends BaseType<
|
|
3
|
+
export declare class AnyType extends BaseType<ZodMiniAny> {
|
|
4
4
|
static factory(): AnyType;
|
|
5
5
|
}
|
|
6
6
|
export declare const any: typeof AnyType.factory;
|
package/dist/types/any.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { any as zodAny } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class AnyType extends BaseType {
|
|
4
4
|
static factory() {
|
|
5
|
-
return new AnyType({
|
|
6
|
-
encodedZodType: zod.any(),
|
|
7
|
-
});
|
|
5
|
+
return new AnyType({ encodeZodType: zodAny() });
|
|
8
6
|
}
|
|
9
7
|
}
|
|
10
8
|
export const any = AnyType.factory;
|
package/dist/types/array.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { core, ZodMiniArray } from 'zod/mini';
|
|
2
2
|
import { BaseType } from './base.ts';
|
|
3
|
-
type Check =
|
|
4
|
-
export declare class ArrayType<T extends BaseType = BaseType> extends BaseType<
|
|
3
|
+
type Check = core.CheckFn<any[]> | core.$ZodCheck<any[]>;
|
|
4
|
+
export declare class ArrayType<T extends BaseType = BaseType> extends BaseType<ZodMiniArray<T['encodeZodType']>, ZodMiniArray<T['decodeZodType']>, {
|
|
5
5
|
element: T;
|
|
6
6
|
}> {
|
|
7
7
|
static factory<T extends BaseType>(element: T, ...checks: Check[]): ArrayType<T>;
|
package/dist/types/array.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { length, maxLength, minLength, array as zodArray } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class ArrayType extends BaseType {
|
|
4
4
|
static factory(element, ...checks) {
|
|
5
5
|
return new ArrayType({
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
encodeZodType: zodArray(element.encodeZodType).check(...checks),
|
|
7
|
+
decodeZodType: zodArray(element.decodeZodType).check(...checks),
|
|
8
8
|
params: { checks },
|
|
9
9
|
props: { element },
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
min(value) {
|
|
13
|
-
const check =
|
|
13
|
+
const check = minLength(value);
|
|
14
14
|
return ArrayType.factory(this.props.element, ...this.params.checks, check);
|
|
15
15
|
}
|
|
16
16
|
max(value) {
|
|
17
|
-
const check =
|
|
17
|
+
const check = maxLength(value);
|
|
18
18
|
return ArrayType.factory(this.props.element, ...this.params.checks, check);
|
|
19
19
|
}
|
|
20
20
|
length(value) {
|
|
21
|
-
const check =
|
|
21
|
+
const check = length(value);
|
|
22
22
|
return ArrayType.factory(this.props.element, ...this.params.checks, check);
|
|
23
23
|
}
|
|
24
24
|
}
|
package/dist/types/base.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ZodMiniAny, ZodMiniArray, ZodMiniBoolean, ZodMiniDefault, ZodMiniEnum, ZodMiniIntersection, ZodMiniLiteral, ZodMiniNever, ZodMiniNullable, ZodMiniNumber, ZodMiniObject, ZodMiniOptional, ZodMiniRecord, ZodMiniString, ZodMiniType, ZodMiniUnion } from 'zod/mini';
|
|
2
|
+
import { core } from 'zod/mini';
|
|
2
3
|
export type PrimitiveValueType = string | number | boolean | null;
|
|
3
|
-
export type PrimitiveZodType =
|
|
4
|
-
export type SimpleZodType =
|
|
5
|
-
export type ZodType = SimpleZodType |
|
|
4
|
+
export type PrimitiveZodType = ZodMiniNever | ZodMiniDefault | ZodMiniNullable | ZodMiniOptional | ZodMiniString | ZodMiniObject | ZodMiniAny | ZodMiniArray | ZodMiniBoolean | ZodMiniNumber | ZodMiniEnum<any> | ZodMiniLiteral<PrimitiveValueType> | ZodMiniUnion | ZodMiniIntersection | ZodMiniRecord;
|
|
5
|
+
export type SimpleZodType = ZodMiniType;
|
|
6
|
+
export type ZodType = SimpleZodType | ZodMiniType;
|
|
6
7
|
export type TypeProps = Record<string, any>;
|
|
7
8
|
export type TypeMetadata<T = any> = {
|
|
8
9
|
id?: string;
|
|
@@ -13,49 +14,49 @@ export type TypeMetadata<T = any> = {
|
|
|
13
14
|
export type TypeParams = {
|
|
14
15
|
encode?: (value: any) => any;
|
|
15
16
|
metadata?: TypeMetadata;
|
|
16
|
-
checks: Array<
|
|
17
|
+
checks: Array<core.CheckFn<any> | core.$ZodCheck<any>>;
|
|
17
18
|
};
|
|
18
19
|
export type DefaultTypeParams = {
|
|
19
20
|
encode?: TypeParams['encode'];
|
|
20
21
|
metadata?: TypeMetadata;
|
|
21
22
|
};
|
|
22
|
-
export type BaseTypeAny<EncodedZodType extends SimpleZodType = SimpleZodType, DecodedZodType extends ZodType =
|
|
23
|
-
export declare const typesRegistry:
|
|
24
|
-
export declare const NeemataTypeError:
|
|
25
|
-
export type NeemataTypeError =
|
|
26
|
-
export declare abstract class BaseType<
|
|
27
|
-
readonly
|
|
28
|
-
readonly
|
|
23
|
+
export type BaseTypeAny<EncodedZodType extends SimpleZodType = SimpleZodType, DecodedZodType extends ZodType = ZodMiniType> = BaseType<EncodedZodType, DecodedZodType, TypeProps>;
|
|
24
|
+
export declare const typesRegistry: core.$ZodRegistry<TypeMetadata<any>, core.$ZodType<unknown, unknown, core.$ZodTypeInternals<unknown, unknown>>>;
|
|
25
|
+
export declare const NeemataTypeError: core.$constructor<core.$ZodError<unknown>, core.$ZodIssue[]>;
|
|
26
|
+
export type NeemataTypeError = core.$ZodError;
|
|
27
|
+
export declare abstract class BaseType<EncodeZodType extends SimpleZodType = SimpleZodType, DecodeZodType extends ZodType = EncodeZodType, Props extends TypeProps = TypeProps> {
|
|
28
|
+
readonly encodeZodType: EncodeZodType;
|
|
29
|
+
readonly decodeZodType: DecodeZodType;
|
|
29
30
|
readonly props: Props;
|
|
30
31
|
readonly params: TypeParams;
|
|
31
|
-
constructor({
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
constructor({ encodeZodType, decodeZodType, props, params, }: {
|
|
33
|
+
encodeZodType: EncodeZodType;
|
|
34
|
+
decodeZodType?: DecodeZodType;
|
|
34
35
|
props?: Props;
|
|
35
36
|
params?: Partial<TypeParams>;
|
|
36
37
|
});
|
|
37
38
|
optional(): OptionalType<this>;
|
|
38
39
|
nullable(): NullableType<this>;
|
|
39
40
|
nullish(): OptionalType<NullableType<this>>;
|
|
40
|
-
default(value: this['
|
|
41
|
+
default(value: this['encodeZodType']['_zod']['input']): DefaultType<this>;
|
|
41
42
|
title(title: string): this;
|
|
42
43
|
description(description: string): this;
|
|
43
|
-
examples(...examples: this['
|
|
44
|
+
examples(...examples: this['encodeZodType']['_zod']['input'][]): this;
|
|
44
45
|
meta(newMetadata: TypeMetadata): this;
|
|
45
|
-
encode(data: this['
|
|
46
|
-
decode(data: this['
|
|
46
|
+
encode(data: this['encodeZodType']['_zod']['input'], context?: core.ParseContext<core.$ZodIssue>): this['encodeZodType']['_zod']['output'];
|
|
47
|
+
decode(data: this['decodeZodType']['_zod']['input'], context?: core.ParseContext<core.$ZodIssue>): this['decodeZodType']['_zod']['output'];
|
|
47
48
|
}
|
|
48
|
-
export declare class OptionalType<Type extends BaseTypeAny = BaseTypeAny> extends BaseType<
|
|
49
|
+
export declare class OptionalType<Type extends BaseTypeAny = BaseTypeAny> extends BaseType<ZodMiniOptional<Type['encodeZodType']>, ZodMiniOptional<Type['decodeZodType']>, {
|
|
49
50
|
inner: Type;
|
|
50
51
|
}> {
|
|
51
52
|
static factory<T extends BaseTypeAny>(type: T): OptionalType<T>;
|
|
52
53
|
}
|
|
53
|
-
export declare class NullableType<Type extends BaseTypeAny<any> = BaseTypeAny<any>> extends BaseType<
|
|
54
|
+
export declare class NullableType<Type extends BaseTypeAny<any> = BaseTypeAny<any>> extends BaseType<ZodMiniNullable<Type['encodeZodType']>, ZodMiniNullable<Type['decodeZodType']>, {
|
|
54
55
|
inner: Type;
|
|
55
56
|
}> {
|
|
56
57
|
static factory<T extends BaseTypeAny<any>>(type: T): NullableType<T>;
|
|
57
58
|
}
|
|
58
|
-
export declare class DefaultType<Type extends BaseTypeAny = BaseTypeAny> extends BaseType<
|
|
59
|
+
export declare class DefaultType<Type extends BaseTypeAny = BaseTypeAny> extends BaseType<ZodMiniDefault<Type['encodeZodType']>, ZodMiniDefault<Type['decodeZodType']>, {
|
|
59
60
|
inner: Type;
|
|
60
61
|
}> {
|
|
61
62
|
static factory<T extends BaseTypeAny<any>>(type: T, defaultValue: any): DefaultType<T>;
|
package/dist/types/base.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
export const typesRegistry =
|
|
3
|
-
export const NeemataTypeError =
|
|
1
|
+
import { _default, core, nullable, optional, registry } from 'zod/mini';
|
|
2
|
+
export const typesRegistry = registry();
|
|
3
|
+
export const NeemataTypeError = core.$ZodError;
|
|
4
4
|
export class BaseType {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
encodeZodType;
|
|
6
|
+
decodeZodType;
|
|
7
7
|
props;
|
|
8
8
|
params;
|
|
9
|
-
constructor({
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
9
|
+
constructor({ encodeZodType, decodeZodType = encodeZodType, props = {}, params = {}, }) {
|
|
10
|
+
this.encodeZodType = encodeZodType;
|
|
11
|
+
this.decodeZodType = decodeZodType;
|
|
12
12
|
this.props = props;
|
|
13
13
|
this.params = Object.assign({ checks: [] }, params);
|
|
14
14
|
}
|
|
@@ -38,22 +38,23 @@ export class BaseType {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
meta(newMetadata) {
|
|
41
|
-
const metadata = typesRegistry.get(this.
|
|
41
|
+
const metadata = typesRegistry.get(this.encodeZodType) ?? {};
|
|
42
42
|
Object.assign(metadata, newMetadata);
|
|
43
|
-
typesRegistry.add(this.
|
|
43
|
+
typesRegistry.add(this.encodeZodType, metadata);
|
|
44
44
|
return this;
|
|
45
45
|
}
|
|
46
|
-
encode(data) {
|
|
47
|
-
return this.
|
|
46
|
+
encode(data, context = {}) {
|
|
47
|
+
return this.encodeZodType.parse(data, { reportInput: true, ...context });
|
|
48
48
|
}
|
|
49
|
-
decode(data) {
|
|
50
|
-
return this.
|
|
49
|
+
decode(data, context = {}) {
|
|
50
|
+
return this.decodeZodType.parse(data, { reportInput: true, ...context });
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
export class OptionalType extends BaseType {
|
|
54
54
|
static factory(type) {
|
|
55
55
|
return new OptionalType({
|
|
56
|
-
|
|
56
|
+
encodeZodType: optional(type.encodeZodType),
|
|
57
|
+
decodeZodType: optional(type.decodeZodType),
|
|
57
58
|
props: { inner: type },
|
|
58
59
|
});
|
|
59
60
|
}
|
|
@@ -61,7 +62,8 @@ export class OptionalType extends BaseType {
|
|
|
61
62
|
export class NullableType extends BaseType {
|
|
62
63
|
static factory(type) {
|
|
63
64
|
return new NullableType({
|
|
64
|
-
|
|
65
|
+
encodeZodType: nullable(type.encodeZodType),
|
|
66
|
+
decodeZodType: nullable(type.decodeZodType),
|
|
65
67
|
props: { inner: type },
|
|
66
68
|
});
|
|
67
69
|
}
|
|
@@ -69,8 +71,8 @@ export class NullableType extends BaseType {
|
|
|
69
71
|
export class DefaultType extends BaseType {
|
|
70
72
|
static factory(type, defaultValue) {
|
|
71
73
|
return new DefaultType({
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
encodeZodType: _default(type.encodeZodType, type.params.encode?.(defaultValue) ?? defaultValue),
|
|
75
|
+
decodeZodType: _default(type.decodeZodType, defaultValue),
|
|
74
76
|
props: { inner: type },
|
|
75
77
|
});
|
|
76
78
|
}
|
package/dist/types/boolean.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ZodMiniBoolean } from 'zod/mini';
|
|
2
2
|
import { BaseType } from './base.ts';
|
|
3
|
-
export declare class BooleanType extends BaseType<
|
|
3
|
+
export declare class BooleanType extends BaseType<ZodMiniBoolean<boolean>> {
|
|
4
4
|
static factory(): BooleanType;
|
|
5
5
|
}
|
|
6
6
|
export declare const boolean: typeof BooleanType.factory;
|
package/dist/types/boolean.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { boolean as zodBoolean } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class BooleanType extends BaseType {
|
|
4
4
|
static factory() {
|
|
5
|
-
return new BooleanType({
|
|
6
|
-
encodedZodType: zod.boolean(),
|
|
7
|
-
});
|
|
5
|
+
return new BooleanType({ encodeZodType: zodBoolean() });
|
|
8
6
|
}
|
|
9
7
|
}
|
|
10
8
|
export const boolean = BooleanType.factory;
|
package/dist/types/custom.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import type { core, ZodMiniType } from 'zod/mini';
|
|
2
|
+
import type { SimpleZodType, ZodType } from './base.ts';
|
|
3
|
+
import { BaseType } from './base.ts';
|
|
3
4
|
export type CustomTransformFn<I, O> = (value: I) => O;
|
|
4
|
-
export declare abstract class TransformType<Type,
|
|
5
|
+
export declare abstract class TransformType<Type, EncodeType extends SimpleZodType = ZodMiniType<Type, Type>, DecodeType extends ZodType = ZodMiniType<Type, Type>> extends BaseType<ZodMiniType<EncodeType['_zod']['output'], DecodeType['_zod']['input']>, ZodMiniType<DecodeType['_zod']['output'], EncodeType['_zod']['input']>> {
|
|
5
6
|
}
|
|
6
|
-
export declare class CustomType<Type,
|
|
7
|
-
static factory<Type,
|
|
8
|
-
decode: CustomTransformFn<
|
|
9
|
-
encode: CustomTransformFn<
|
|
10
|
-
error?: string |
|
|
11
|
-
type?:
|
|
12
|
-
}): CustomType<Type,
|
|
7
|
+
export declare class CustomType<Type, EncodeType extends SimpleZodType = ZodMiniType<Type, Type>, DecodeType extends ZodType = ZodMiniType<Type, Type>> extends TransformType<Type, EncodeType, DecodeType> {
|
|
8
|
+
static factory<Type, EncodeType extends SimpleZodType = ZodMiniType<Type, Type>, DecodeType extends ZodType = ZodMiniType<Type, Type>>({ decode, encode, error, type, }: {
|
|
9
|
+
decode: CustomTransformFn<EncodeType['_zod']['input'], DecodeType['_zod']['output']>;
|
|
10
|
+
encode: CustomTransformFn<DecodeType['_zod']['input'], EncodeType['_zod']['output']>;
|
|
11
|
+
error?: string | core.$ZodErrorMap<core.$ZodIssueBase>;
|
|
12
|
+
type?: EncodeType;
|
|
13
|
+
}): CustomType<Type, EncodeType, DecodeType>;
|
|
13
14
|
}
|
|
14
15
|
export declare const custom: typeof CustomType.factory;
|
package/dist/types/custom.js
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { any, overwrite, pipe, refine, custom as zodCustom } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class TransformType extends BaseType {
|
|
4
4
|
}
|
|
5
5
|
export class CustomType extends TransformType {
|
|
6
|
-
static factory({ decode, encode, error, type =
|
|
6
|
+
static factory({ decode, encode, error, type = any(), }) {
|
|
7
7
|
return new CustomType({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
abort: true,
|
|
11
|
-
}), zod.overwrite(encode)), type),
|
|
8
|
+
encodeZodType: pipe(zodCustom().check(refine((val) => typeof val !== 'undefined', { error, abort: true }), overwrite(encode)), type),
|
|
9
|
+
decodeZodType: pipe(type,
|
|
12
10
|
// @ts-expect-error
|
|
13
|
-
|
|
14
|
-
// @ts-expect-error
|
|
15
|
-
zod
|
|
16
|
-
.custom()
|
|
17
|
-
.check(zod.refine((val) => typeof val !== 'undefined', {
|
|
18
|
-
error,
|
|
19
|
-
abort: true,
|
|
20
|
-
}), zod.overwrite(decode))),
|
|
11
|
+
zodCustom().check(refine((val) => typeof val !== 'undefined', { error, abort: true }), overwrite(decode))),
|
|
21
12
|
params: { encode },
|
|
22
13
|
});
|
|
23
14
|
}
|
package/dist/types/date.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ZodMiniUnion } from 'zod/mini';
|
|
2
|
+
import { iso } from 'zod/mini';
|
|
2
3
|
import { CustomType, TransformType } from './custom.ts';
|
|
3
|
-
export declare class DateType extends TransformType<Date,
|
|
4
|
-
static factory(): CustomType<Date,
|
|
4
|
+
export declare class DateType extends TransformType<Date, ZodMiniUnion<[iso.ZodMiniISODate, iso.ZodMiniISODateTime]>> {
|
|
5
|
+
static factory(): CustomType<Date, ZodMiniUnion<[iso.ZodMiniISODate, iso.ZodMiniISODateTime]>, import("zod/mini").ZodMiniType<Date, Date, import("zod/v4/core").$ZodTypeInternals<Date, Date>>>;
|
|
5
6
|
}
|
|
6
7
|
export declare const date: typeof DateType.factory;
|
package/dist/types/date.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { iso, union } from 'zod/mini';
|
|
2
2
|
import { CustomType, TransformType } from "./custom.js";
|
|
3
3
|
export class DateType extends TransformType {
|
|
4
4
|
static factory() {
|
|
5
5
|
return CustomType.factory({
|
|
6
6
|
decode: (value) => new Date(value),
|
|
7
7
|
encode: (value) => value.toISOString(),
|
|
8
|
-
type:
|
|
8
|
+
type: union([iso.date(), iso.datetime()]),
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
}
|
package/dist/types/enum.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { core, ZodMiniEnum } from 'zod/mini';
|
|
2
2
|
import { BaseType } from './base.ts';
|
|
3
|
-
export declare class EnumType<T extends
|
|
3
|
+
export declare class EnumType<T extends core.util.EnumLike = core.util.EnumLike> extends BaseType<ZodMiniEnum<T>, ZodMiniEnum<T>, {
|
|
4
4
|
values: T;
|
|
5
5
|
}> {
|
|
6
|
-
static factory<T extends
|
|
7
|
-
static factory<T extends string[]>(values: T): EnumType<
|
|
6
|
+
static factory<T extends core.util.EnumLike>(values: T): EnumType<T>;
|
|
7
|
+
static factory<T extends string[]>(values: T): EnumType<core.util.ToEnum<T[number]>>;
|
|
8
8
|
}
|
|
9
9
|
declare const _enum: typeof EnumType.factory;
|
|
10
10
|
export { _enum as enum };
|
package/dist/types/enum.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { enum as zodEnum } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class EnumType extends BaseType {
|
|
4
4
|
static factory(values) {
|
|
5
5
|
return new EnumType({
|
|
6
|
-
|
|
6
|
+
encodeZodType: zodEnum(values),
|
|
7
7
|
props: { values },
|
|
8
8
|
});
|
|
9
9
|
}
|
package/dist/types/literal.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { ZodMiniLiteral } from 'zod/mini';
|
|
2
|
+
import type { PrimitiveValueType } from './base.ts';
|
|
3
|
+
import { BaseType } from './base.ts';
|
|
4
|
+
export declare class LiteralType<T extends PrimitiveValueType = PrimitiveValueType> extends BaseType<ZodMiniLiteral<T>, ZodMiniLiteral<T>, {
|
|
4
5
|
value: T;
|
|
5
6
|
}> {
|
|
6
7
|
static factory<T extends PrimitiveValueType>(value: T): LiteralType<T>;
|
package/dist/types/literal.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { literal as zodLiteral } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class LiteralType extends BaseType {
|
|
4
4
|
static factory(value) {
|
|
5
5
|
return new LiteralType({
|
|
6
|
-
|
|
6
|
+
encodeZodType: zodLiteral(value),
|
|
7
7
|
props: { value },
|
|
8
8
|
});
|
|
9
9
|
}
|
package/dist/types/never.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ZodMiniNever } from 'zod/mini';
|
|
2
2
|
import { BaseType } from './base.ts';
|
|
3
|
-
export declare class NeverType extends BaseType<
|
|
3
|
+
export declare class NeverType extends BaseType<ZodMiniNever> {
|
|
4
4
|
static factory(): NeverType;
|
|
5
5
|
}
|
|
6
6
|
export declare const never: typeof NeverType.factory;
|
package/dist/types/never.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { never as zodNever } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class NeverType extends BaseType {
|
|
4
4
|
static factory() {
|
|
5
|
-
return new NeverType({
|
|
6
|
-
encodedZodType: zod.never(),
|
|
7
|
-
});
|
|
5
|
+
return new NeverType({ encodeZodType: zodNever() });
|
|
8
6
|
}
|
|
9
7
|
}
|
|
10
8
|
export const never = NeverType.factory;
|
package/dist/types/number.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { core, ZodMiniNumber, ZodMiniString } from 'zod/mini';
|
|
2
2
|
import { BaseType } from './base.ts';
|
|
3
3
|
import { CustomType, TransformType } from './custom.ts';
|
|
4
|
-
type Check =
|
|
5
|
-
export declare class NumberType extends BaseType<
|
|
4
|
+
type Check = core.CheckFn<number> | core.$ZodCheck<number>;
|
|
5
|
+
export declare class NumberType extends BaseType<ZodMiniNumber<number>, ZodMiniNumber<number>> {
|
|
6
6
|
static factory(...checks: Check[]): NumberType;
|
|
7
7
|
positive(): NumberType;
|
|
8
8
|
negative(): NumberType;
|
|
@@ -14,8 +14,8 @@ export declare class NumberType extends BaseType<zod.ZodMiniNumber<number>, zod.
|
|
|
14
14
|
export declare class IntegerType extends NumberType {
|
|
15
15
|
static factory(...checks: Check[]): NumberType;
|
|
16
16
|
}
|
|
17
|
-
export declare class BigIntType extends TransformType<bigint,
|
|
18
|
-
static factory(): CustomType<bigint,
|
|
17
|
+
export declare class BigIntType extends TransformType<bigint, ZodMiniString<string>> {
|
|
18
|
+
static factory(): CustomType<bigint, ZodMiniString<string>, import("zod/mini").ZodMiniType<bigint, bigint, core.$ZodTypeInternals<bigint, bigint>>>;
|
|
19
19
|
}
|
|
20
20
|
export declare const number: typeof NumberType.factory;
|
|
21
21
|
export declare const integer: typeof IntegerType.factory;
|
package/dist/types/number.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { gt, gte, int, lt, lte, regex, number as zodNumber, string as zodString, } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
import { CustomType, TransformType } from "./custom.js";
|
|
4
4
|
export class NumberType extends BaseType {
|
|
5
5
|
static factory(...checks) {
|
|
6
6
|
return new NumberType({
|
|
7
|
-
|
|
7
|
+
encodeZodType: zodNumber().check(...checks),
|
|
8
8
|
params: { checks },
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
positive() {
|
|
12
|
-
return NumberType.factory(...this.params.checks,
|
|
12
|
+
return NumberType.factory(...this.params.checks, gte(0));
|
|
13
13
|
}
|
|
14
14
|
negative() {
|
|
15
|
-
return NumberType.factory(...this.params.checks,
|
|
15
|
+
return NumberType.factory(...this.params.checks, lte(0));
|
|
16
16
|
}
|
|
17
17
|
lt(value) {
|
|
18
|
-
return NumberType.factory(...this.params.checks,
|
|
18
|
+
return NumberType.factory(...this.params.checks, lt(value));
|
|
19
19
|
}
|
|
20
20
|
lte(value) {
|
|
21
|
-
return NumberType.factory(...this.params.checks,
|
|
21
|
+
return NumberType.factory(...this.params.checks, lte(value));
|
|
22
22
|
}
|
|
23
23
|
gte(value) {
|
|
24
|
-
return NumberType.factory(...this.params.checks,
|
|
24
|
+
return NumberType.factory(...this.params.checks, gte(value));
|
|
25
25
|
}
|
|
26
26
|
gt(value) {
|
|
27
|
-
return NumberType.factory(...this.params.checks,
|
|
27
|
+
return NumberType.factory(...this.params.checks, gt(value));
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export class IntegerType extends NumberType {
|
|
31
31
|
static factory(...checks) {
|
|
32
|
-
return NumberType.factory(...checks,
|
|
32
|
+
return NumberType.factory(...checks, int());
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
export class BigIntType extends TransformType {
|
|
@@ -37,7 +37,7 @@ export class BigIntType extends TransformType {
|
|
|
37
37
|
return CustomType.factory({
|
|
38
38
|
decode: (value) => BigInt(value),
|
|
39
39
|
encode: (value) => value.toString(),
|
|
40
|
-
type:
|
|
40
|
+
type: zodString().check(regex(/^-?\d+$/)),
|
|
41
41
|
error: 'Invalid bigint format',
|
|
42
42
|
});
|
|
43
43
|
}
|
package/dist/types/object.d.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { EnumType } from './enum.ts';
|
|
1
|
+
import type { core, ZodMiniObject, ZodMiniRecord } from 'zod/mini';
|
|
2
|
+
import type { BaseTypeAny, OptionalType } from './base.ts';
|
|
4
3
|
import type { LiteralType } from './literal.ts';
|
|
5
4
|
import type { StringType } from './string.ts';
|
|
5
|
+
import { BaseType } from './base.ts';
|
|
6
|
+
import { EnumType } from './enum.ts';
|
|
6
7
|
export type ObjectTypeProps = {
|
|
7
8
|
[k: string]: BaseTypeAny;
|
|
8
9
|
};
|
|
9
10
|
export type AnyObjectType = ObjectType<ObjectTypeProps>;
|
|
10
|
-
export declare class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<
|
|
11
|
-
[K in keyof T]: T[K]['
|
|
12
|
-
},
|
|
13
|
-
[K in keyof T]: T[K]['
|
|
14
|
-
},
|
|
11
|
+
export declare class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<ZodMiniObject<{
|
|
12
|
+
[K in keyof T]: T[K]['encodeZodType'];
|
|
13
|
+
}, core.$strict>, ZodMiniObject<{
|
|
14
|
+
[K in keyof T]: T[K]['decodeZodType'];
|
|
15
|
+
}, core.$strict>, {
|
|
15
16
|
properties: T;
|
|
16
17
|
}> {
|
|
17
18
|
static factory<T extends ObjectTypeProps = {}>(properties: T): ObjectType<T>;
|
|
18
19
|
}
|
|
19
|
-
export declare class RecordType<K extends LiteralType<string | number> | EnumType | StringType, E extends BaseType> extends BaseType<
|
|
20
|
+
export declare class RecordType<K extends LiteralType<string | number> | EnumType | StringType, E extends BaseType> extends BaseType<ZodMiniRecord<K['encodeZodType'], E['encodeZodType']>, ZodMiniRecord<K['decodeZodType'], E['decodeZodType']>> {
|
|
20
21
|
static factory<K extends LiteralType<string | number> | EnumType | StringType, E extends BaseType>(key: K, element: E): RecordType<K, E>;
|
|
21
22
|
}
|
|
22
|
-
export declare function keyof<T extends ObjectType>(type: T): EnumType<
|
|
23
|
+
export declare function keyof<T extends ObjectType>(type: T): EnumType<core.util.ToEnum<Extract<keyof T['props']['properties'], string>>>;
|
|
23
24
|
export declare function pick<T extends AnyObjectType, P extends {
|
|
24
25
|
[K in keyof T['props']['properties']]?: true;
|
|
25
26
|
}>(source: T, pick: P): ObjectType<{
|
package/dist/types/object.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { object as zodObject, record as zodRecord } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
import { EnumType } from "./enum.js";
|
|
4
4
|
export class ObjectType extends BaseType {
|
|
@@ -6,12 +6,12 @@ export class ObjectType extends BaseType {
|
|
|
6
6
|
const encodeProperties = {};
|
|
7
7
|
const decodeProperties = {};
|
|
8
8
|
for (const key in properties) {
|
|
9
|
-
encodeProperties[key] = properties[key].
|
|
10
|
-
decodeProperties[key] = properties[key].
|
|
9
|
+
encodeProperties[key] = properties[key].encodeZodType;
|
|
10
|
+
decodeProperties[key] = properties[key].decodeZodType;
|
|
11
11
|
}
|
|
12
12
|
return new ObjectType({
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
encodeZodType: zodObject(encodeProperties),
|
|
14
|
+
decodeZodType: zodObject(decodeProperties),
|
|
15
15
|
props: { properties },
|
|
16
16
|
});
|
|
17
17
|
}
|
|
@@ -19,8 +19,8 @@ export class ObjectType extends BaseType {
|
|
|
19
19
|
export class RecordType extends BaseType {
|
|
20
20
|
static factory(key, element) {
|
|
21
21
|
return new RecordType({
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
encodeZodType: zodRecord(key.encodeZodType, element.encodeZodType),
|
|
23
|
+
decodeZodType: zodRecord(key.decodeZodType, element.decodeZodType),
|
|
24
24
|
props: { key, element },
|
|
25
25
|
});
|
|
26
26
|
}
|
package/dist/types/string.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { core, ZodMiniString } from 'zod/mini';
|
|
2
2
|
import { BaseType } from './base.ts';
|
|
3
|
-
type Check =
|
|
4
|
-
export declare class StringType extends BaseType<
|
|
3
|
+
type Check = core.CheckFn<string> | core.$ZodCheck<string>;
|
|
4
|
+
export declare class StringType extends BaseType<ZodMiniString<string>, ZodMiniString<string>> {
|
|
5
5
|
static factory(...checks: Check[]): StringType;
|
|
6
6
|
max(value: number): StringType;
|
|
7
7
|
min(value: number): StringType;
|
|
8
8
|
pattern(pattern: string | RegExp): StringType;
|
|
9
|
-
email(options?:
|
|
10
|
-
url(options?:
|
|
11
|
-
ipv4(options?:
|
|
12
|
-
ipv6(options?:
|
|
13
|
-
uuid(options?:
|
|
14
|
-
emoji(options?:
|
|
15
|
-
nanoid(options?:
|
|
16
|
-
cuid(options?:
|
|
17
|
-
cuid2(options?:
|
|
18
|
-
e164(options?:
|
|
19
|
-
jwt(options?:
|
|
9
|
+
email(options?: core.$ZodEmailParams): StringType;
|
|
10
|
+
url(options?: core.$ZodURLParams): StringType;
|
|
11
|
+
ipv4(options?: core.$ZodIPv4Params): StringType;
|
|
12
|
+
ipv6(options?: core.$ZodIPv6Params): StringType;
|
|
13
|
+
uuid(options?: core.$ZodUUIDParams): StringType;
|
|
14
|
+
emoji(options?: core.$ZodEmojiParams): StringType;
|
|
15
|
+
nanoid(options?: core.$ZodNanoIDParams): StringType;
|
|
16
|
+
cuid(options?: core.$ZodCUIDParams): StringType;
|
|
17
|
+
cuid2(options?: core.$ZodCUID2Params): StringType;
|
|
18
|
+
e164(options?: core.$ZodE164Params): StringType;
|
|
19
|
+
jwt(options?: core.$ZodJWTParams): StringType;
|
|
20
20
|
}
|
|
21
21
|
export declare const string: typeof StringType.factory;
|
|
22
22
|
export {};
|
package/dist/types/string.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { cuid, cuid2, e164, email, emoji, ipv4, ipv6, jwt, maxLength, minLength, nanoid, regex, url, uuid, string as zodString, } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class StringType extends BaseType {
|
|
4
4
|
static factory(...checks) {
|
|
5
5
|
return new StringType({
|
|
6
|
-
|
|
6
|
+
encodeZodType: zodString().check(...checks),
|
|
7
7
|
params: { checks },
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
max(value) {
|
|
11
|
-
return StringType.factory(...this.params.checks,
|
|
11
|
+
return StringType.factory(...this.params.checks, maxLength(value));
|
|
12
12
|
}
|
|
13
13
|
min(value) {
|
|
14
|
-
return StringType.factory(...this.params.checks,
|
|
14
|
+
return StringType.factory(...this.params.checks, minLength(value));
|
|
15
15
|
}
|
|
16
16
|
pattern(pattern) {
|
|
17
|
-
return StringType.factory(...this.params.checks,
|
|
17
|
+
return StringType.factory(...this.params.checks, regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern));
|
|
18
18
|
}
|
|
19
19
|
email(options) {
|
|
20
|
-
return StringType.factory(...this.params.checks,
|
|
20
|
+
return StringType.factory(...this.params.checks, email(options));
|
|
21
21
|
}
|
|
22
22
|
url(options) {
|
|
23
|
-
return StringType.factory(...this.params.checks,
|
|
23
|
+
return StringType.factory(...this.params.checks, url(options));
|
|
24
24
|
}
|
|
25
25
|
ipv4(options) {
|
|
26
|
-
return StringType.factory(...this.params.checks,
|
|
26
|
+
return StringType.factory(...this.params.checks, ipv4(options));
|
|
27
27
|
}
|
|
28
28
|
ipv6(options) {
|
|
29
|
-
return StringType.factory(...this.params.checks,
|
|
29
|
+
return StringType.factory(...this.params.checks, ipv6(options));
|
|
30
30
|
}
|
|
31
31
|
uuid(options) {
|
|
32
|
-
return StringType.factory(...this.params.checks,
|
|
32
|
+
return StringType.factory(...this.params.checks, uuid(options));
|
|
33
33
|
}
|
|
34
34
|
emoji(options) {
|
|
35
|
-
return StringType.factory(...this.params.checks,
|
|
35
|
+
return StringType.factory(...this.params.checks, emoji(options));
|
|
36
36
|
}
|
|
37
37
|
nanoid(options) {
|
|
38
|
-
return StringType.factory(...this.params.checks,
|
|
38
|
+
return StringType.factory(...this.params.checks, nanoid(options));
|
|
39
39
|
}
|
|
40
40
|
cuid(options) {
|
|
41
|
-
return StringType.factory(...this.params.checks,
|
|
41
|
+
return StringType.factory(...this.params.checks, cuid(options));
|
|
42
42
|
}
|
|
43
43
|
cuid2(options) {
|
|
44
|
-
return StringType.factory(...this.params.checks,
|
|
44
|
+
return StringType.factory(...this.params.checks, cuid2(options));
|
|
45
45
|
}
|
|
46
46
|
e164(options) {
|
|
47
|
-
return StringType.factory(...this.params.checks,
|
|
47
|
+
return StringType.factory(...this.params.checks, e164(options));
|
|
48
48
|
}
|
|
49
49
|
jwt(options) {
|
|
50
|
-
return StringType.factory(...this.params.checks,
|
|
50
|
+
return StringType.factory(...this.params.checks, jwt(options));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
export const string = StringType.factory;
|
package/dist/types/temporal.d.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
+
import type { ZodMiniString } from 'zod/mini';
|
|
1
2
|
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import { type ZodMiniString } from 'zod/v4-mini';
|
|
3
3
|
import { CustomType, TransformType } from './custom.ts';
|
|
4
4
|
type Types = Exclude<keyof typeof Temporal, 'Now' | 'Instant' | 'Calendar' | 'TimeZone'>;
|
|
5
5
|
type TemporalTransformer<T extends Types> = {
|
|
6
6
|
decode: (value: string) => ReturnType<(typeof Temporal)[T]['from']>;
|
|
7
7
|
encode: (value: ReturnType<(typeof Temporal)[T]['from']>) => string;
|
|
8
8
|
};
|
|
9
|
-
type
|
|
10
|
-
export declare class PlainDateType extends TransformType<Temporal.PlainDate,
|
|
9
|
+
type EncodeType = ZodMiniString<string>;
|
|
10
|
+
export declare class PlainDateType extends TransformType<Temporal.PlainDate, EncodeType> {
|
|
11
11
|
static transformer: TemporalTransformer<"PlainDate">;
|
|
12
|
-
static factory(): CustomType<Temporal.PlainDate,
|
|
12
|
+
static factory(): CustomType<Temporal.PlainDate, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainDate, Temporal.PlainDate, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainDate, Temporal.PlainDate>>>;
|
|
13
13
|
}
|
|
14
|
-
export declare class PlainDateTimeType extends TransformType<Temporal.PlainDateTime,
|
|
14
|
+
export declare class PlainDateTimeType extends TransformType<Temporal.PlainDateTime, EncodeType> {
|
|
15
15
|
static transformer: TemporalTransformer<"PlainDateTime">;
|
|
16
|
-
static factory(): CustomType<Temporal.PlainDateTime,
|
|
16
|
+
static factory(): CustomType<Temporal.PlainDateTime, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainDateTime, Temporal.PlainDateTime, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainDateTime, Temporal.PlainDateTime>>>;
|
|
17
17
|
}
|
|
18
|
-
export declare class ZonedDateTimeType extends TransformType<Temporal.ZonedDateTime,
|
|
18
|
+
export declare class ZonedDateTimeType extends TransformType<Temporal.ZonedDateTime, EncodeType> {
|
|
19
19
|
static transformer: TemporalTransformer<"ZonedDateTime">;
|
|
20
|
-
static factory(): CustomType<Temporal.ZonedDateTime,
|
|
20
|
+
static factory(): CustomType<Temporal.ZonedDateTime, EncodeType, import("zod/mini").ZodMiniType<Temporal.ZonedDateTime, Temporal.ZonedDateTime, import("zod/v4/core").$ZodTypeInternals<Temporal.ZonedDateTime, Temporal.ZonedDateTime>>>;
|
|
21
21
|
}
|
|
22
|
-
export declare class PlainTimeType extends TransformType<Temporal.PlainTime,
|
|
22
|
+
export declare class PlainTimeType extends TransformType<Temporal.PlainTime, EncodeType> {
|
|
23
23
|
static transformer: TemporalTransformer<"PlainTime">;
|
|
24
|
-
static factory(): CustomType<Temporal.PlainTime,
|
|
24
|
+
static factory(): CustomType<Temporal.PlainTime, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainTime, Temporal.PlainTime, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainTime, Temporal.PlainTime>>>;
|
|
25
25
|
}
|
|
26
|
-
export declare class DurationType extends TransformType<Temporal.Duration,
|
|
26
|
+
export declare class DurationType extends TransformType<Temporal.Duration, EncodeType> {
|
|
27
27
|
static transformer: TemporalTransformer<"Duration">;
|
|
28
|
-
static factory(): CustomType<Temporal.Duration,
|
|
28
|
+
static factory(): CustomType<Temporal.Duration, EncodeType, import("zod/mini").ZodMiniType<Temporal.Duration, Temporal.Duration, import("zod/v4/core").$ZodTypeInternals<Temporal.Duration, Temporal.Duration>>>;
|
|
29
29
|
}
|
|
30
|
-
export declare class PlainYearMonthType extends TransformType<Temporal.PlainYearMonth,
|
|
30
|
+
export declare class PlainYearMonthType extends TransformType<Temporal.PlainYearMonth, EncodeType> {
|
|
31
31
|
static transformer: TemporalTransformer<"PlainYearMonth">;
|
|
32
|
-
static factory(): CustomType<Temporal.PlainYearMonth,
|
|
32
|
+
static factory(): CustomType<Temporal.PlainYearMonth, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainYearMonth, Temporal.PlainYearMonth, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainYearMonth, Temporal.PlainYearMonth>>>;
|
|
33
33
|
}
|
|
34
|
-
export declare class PlainMonthDayType extends TransformType<Temporal.PlainMonthDay,
|
|
34
|
+
export declare class PlainMonthDayType extends TransformType<Temporal.PlainMonthDay, EncodeType> {
|
|
35
35
|
static transformer: TemporalTransformer<"PlainMonthDay">;
|
|
36
|
-
static factory(): CustomType<Temporal.PlainMonthDay,
|
|
36
|
+
static factory(): CustomType<Temporal.PlainMonthDay, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainMonthDay, Temporal.PlainMonthDay, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainMonthDay, Temporal.PlainMonthDay>>>;
|
|
37
37
|
}
|
|
38
38
|
export declare const plainDate: typeof PlainDateType.factory;
|
|
39
39
|
export declare const plainDatetime: typeof PlainDateTimeType.factory;
|
package/dist/types/temporal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import { iso, regex, string } from 'zod/
|
|
2
|
+
import { iso, regex, string } from 'zod/mini';
|
|
3
3
|
import { CustomType, TransformType } from "./custom.js";
|
|
4
4
|
const createTemporalTransformer = (type, decode = (value) => Temporal[type].from(value)) => {
|
|
5
5
|
const encode = (value) => value.toString({
|
|
@@ -7,10 +7,7 @@ const createTemporalTransformer = (type, decode = (value) => Temporal[type].from
|
|
|
7
7
|
smallestUnit: 'microsecond',
|
|
8
8
|
timeZoneName: 'never',
|
|
9
9
|
});
|
|
10
|
-
return {
|
|
11
|
-
decode,
|
|
12
|
-
encode,
|
|
13
|
-
};
|
|
10
|
+
return { decode, encode };
|
|
14
11
|
};
|
|
15
12
|
export class PlainDateType extends TransformType {
|
|
16
13
|
static transformer = createTemporalTransformer('PlainDate');
|
package/dist/types/tuple.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ArrayMap } from '@nmtjs/common';
|
|
2
|
-
import
|
|
2
|
+
import type { ZodMiniTuple } from 'zod/mini';
|
|
3
3
|
import { BaseType } from './base.ts';
|
|
4
4
|
export declare class TupleType<T extends readonly [BaseType, ...BaseType[]] = readonly [
|
|
5
5
|
BaseType,
|
|
6
6
|
...BaseType[]
|
|
7
|
-
], R extends BaseType | null = BaseType | null> extends BaseType<R extends BaseType ?
|
|
7
|
+
], R extends BaseType | null = BaseType | null> extends BaseType<R extends BaseType ? ZodMiniTuple<ArrayMap<T, 'encodeZodType'>, R['encodeZodType']> : ZodMiniTuple<ArrayMap<T, 'encodeZodType'>, null>, R extends BaseType ? ZodMiniTuple<ArrayMap<T, 'decodeZodType'>, R['decodeZodType']> : ZodMiniTuple<ArrayMap<T, 'decodeZodType'>, null>, {
|
|
8
8
|
elements: T;
|
|
9
9
|
rest?: R;
|
|
10
10
|
}> {
|
package/dist/types/tuple.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { tuple as zodTuple } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class TupleType extends BaseType {
|
|
4
4
|
static factory(elements, rest = null) {
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const encode = elements.map((el) => el.encodeZodType);
|
|
6
|
+
const decode = elements.map((el) => el.decodeZodType);
|
|
7
7
|
return new TupleType({
|
|
8
8
|
// @ts-expect-error
|
|
9
|
-
|
|
9
|
+
encodeZodType: zodTuple(encode, rest?.encodeZodType),
|
|
10
10
|
// @ts-expect-error
|
|
11
|
-
|
|
11
|
+
decodeZodType: zodTuple(decode, rest?.decodeZodType),
|
|
12
12
|
props: { elements, rest },
|
|
13
13
|
});
|
|
14
14
|
}
|
package/dist/types/union.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ArrayMap } from '@nmtjs/common';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import type { ZodMiniDiscriminatedUnion, ZodMiniIntersection, ZodMiniUnion } from 'zod/mini';
|
|
3
|
+
import type { BaseTypeAny } from './base.ts';
|
|
4
4
|
import type { LiteralType } from './literal.ts';
|
|
5
5
|
import type { ObjectType, ObjectTypeProps } from './object.ts';
|
|
6
|
+
import { BaseType } from './base.ts';
|
|
6
7
|
export declare class UnionType<T extends readonly [BaseType, ...BaseType[]] = readonly [
|
|
7
8
|
BaseType,
|
|
8
9
|
...BaseType[]
|
|
9
|
-
]> extends BaseType<
|
|
10
|
+
]> extends BaseType<ZodMiniUnion<ArrayMap<T, 'encodeZodType'>>, ZodMiniUnion<ArrayMap<T, 'decodeZodType'>>, {
|
|
10
11
|
options: T;
|
|
11
12
|
}> {
|
|
12
13
|
static factory<T extends readonly [BaseType, ...BaseType[]] = readonly [
|
|
@@ -14,7 +15,7 @@ export declare class UnionType<T extends readonly [BaseType, ...BaseType[]] = re
|
|
|
14
15
|
...BaseType[]
|
|
15
16
|
]>(...options: T): UnionType<T>;
|
|
16
17
|
}
|
|
17
|
-
export declare class IntersactionType<T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType]> extends BaseType<
|
|
18
|
+
export declare class IntersactionType<T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType]> extends BaseType<ZodMiniIntersection<T[0]['encodeZodType'], T[1]['encodeZodType']>, ZodMiniIntersection<T[0]['decodeZodType'], T[1]['decodeZodType']>, {
|
|
18
19
|
options: T;
|
|
19
20
|
}> {
|
|
20
21
|
static factory<T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType]>(...options: T): IntersactionType<T>;
|
|
@@ -27,7 +28,7 @@ export type DiscriminatedUnionProperties<K extends string = string> = {
|
|
|
27
28
|
export type DiscriminatedUnionOptionType<K extends string> = ObjectType<ObjectTypeProps & {
|
|
28
29
|
[_ in K]: BaseTypeAny;
|
|
29
30
|
}>;
|
|
30
|
-
export declare class DiscriminatedUnionType<K extends string = string, T extends readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[]> extends BaseType<
|
|
31
|
+
export declare class DiscriminatedUnionType<K extends string = string, T extends readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[]> extends BaseType<ZodMiniDiscriminatedUnion<ArrayMap<T, 'encodeZodType'>>, ZodMiniDiscriminatedUnion<ArrayMap<T, 'decodeZodType'>>, {
|
|
31
32
|
key: K;
|
|
32
33
|
options: T;
|
|
33
34
|
}> {
|
package/dist/types/union.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { discriminatedUnion as zodDiscriminatedUnion, intersection as zodIntersection, union as zodUnion, } from 'zod/mini';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class UnionType extends BaseType {
|
|
4
4
|
static factory(...options) {
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const encode = options.map((t) => t.encodeZodType);
|
|
6
|
+
const decode = options.map((t) => t.decodeZodType);
|
|
7
7
|
return new UnionType({
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
encodeZodType: zodUnion(encode),
|
|
9
|
+
decodeZodType: zodUnion(decode),
|
|
10
10
|
props: { options },
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -15,21 +15,21 @@ export class IntersactionType extends BaseType {
|
|
|
15
15
|
static factory(...options) {
|
|
16
16
|
const [first, second] = options;
|
|
17
17
|
return new IntersactionType({
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
encodeZodType: zodIntersection(first.encodeZodType, second.encodeZodType),
|
|
19
|
+
decodeZodType: zodIntersection(first.decodeZodType, second.decodeZodType),
|
|
20
20
|
props: { options },
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
export class DiscriminatedUnionType extends BaseType {
|
|
25
25
|
static factory(key, ...options) {
|
|
26
|
-
const
|
|
27
|
-
const
|
|
26
|
+
const encode = options.map((t) => t.encodeZodType);
|
|
27
|
+
const decode = options.map((t) => t.decodeZodType);
|
|
28
28
|
return new DiscriminatedUnionType({
|
|
29
29
|
// @ts-expect-error
|
|
30
|
-
|
|
30
|
+
encodeZodType: zodDiscriminatedUnion(key, encode),
|
|
31
31
|
// @ts-expect-error
|
|
32
|
-
|
|
32
|
+
decodeZodType: zodDiscriminatedUnion(key, decode),
|
|
33
33
|
props: { key, options },
|
|
34
34
|
});
|
|
35
35
|
}
|
package/package.json
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
"import": "./dist/index.js",
|
|
8
8
|
"module-sync": "./dist/index.js"
|
|
9
9
|
},
|
|
10
|
+
"./*": {
|
|
11
|
+
"types": "./dist/types/*.d.ts",
|
|
12
|
+
"import": "./dist/types/*.js",
|
|
13
|
+
"module-sync": "./dist/types/*.js"
|
|
14
|
+
},
|
|
10
15
|
"./temporal": {
|
|
11
16
|
"types": "./dist/temporal.d.ts",
|
|
12
17
|
"import": "./dist/temporal.js",
|
|
@@ -15,20 +20,20 @@
|
|
|
15
20
|
},
|
|
16
21
|
"peerDependencies": {
|
|
17
22
|
"temporal-polyfill": "^0.3.0",
|
|
18
|
-
"zod": "^
|
|
19
|
-
"@nmtjs/common": "0.
|
|
23
|
+
"zod": "^4.0.0",
|
|
24
|
+
"@nmtjs/common": "0.14.1"
|
|
20
25
|
},
|
|
21
26
|
"devDependencies": {
|
|
22
27
|
"temporal-polyfill": "^0.3.0",
|
|
23
|
-
"zod": "^
|
|
24
|
-
"@nmtjs/common": "0.
|
|
28
|
+
"zod": "^4.0.0",
|
|
29
|
+
"@nmtjs/common": "0.14.1"
|
|
25
30
|
},
|
|
26
31
|
"files": [
|
|
27
32
|
"dist",
|
|
28
33
|
"LICENSE.md",
|
|
29
34
|
"README.md"
|
|
30
35
|
],
|
|
31
|
-
"version": "0.
|
|
36
|
+
"version": "0.14.1",
|
|
32
37
|
"scripts": {
|
|
33
38
|
"build": "tsc",
|
|
34
39
|
"type-check": "tsc --noEmit"
|
|
File without changes
|