@nmtjs/type 0.14.4 → 0.15.0-beta.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/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2024 Denis Ilchyshyn
1
+ Copyright (c) 2025 Denys Ilchyshyn
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -6,4 +6,4 @@
6
6
  - binary data streaming and event subscriptions
7
7
  - contract-based API
8
8
  - end-to-end type safety
9
- - CPU-intensive task execution on separate workers
9
+ - CPU-intensive task execution on separate workers
package/package.json CHANGED
@@ -7,48 +7,34 @@
7
7
  "README.md"
8
8
  ],
9
9
  "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "module-sync": "./dist/index.js"
14
- },
15
- "./*": {
16
- "types": "./dist/types/*.d.ts",
17
- "import": "./dist/types/*.js",
18
- "module-sync": "./dist/types/*.js"
19
- },
20
- "./temporal": {
21
- "types": "./dist/temporal/global.d.ts",
22
- "import": "./dist/temporal/global.js",
23
- "module-sync": "./dist/temporal/global.js"
24
- },
25
- "./temporal-polyfill": {
26
- "types": "./dist/temporal/polyfill.d.ts",
27
- "import": "./dist/temporal/polyfill.js",
28
- "module-sync": "./dist/temporal/polyfill.js"
29
- }
10
+ ".": "./dist/index.js",
11
+ "./*": "./dist/types/*.js",
12
+ "./temporal": "./dist/temporal/global.js",
13
+ "./temporal-polyfill": "./dist/temporal/polyfill.js"
30
14
  },
31
15
  "dependencies": {
32
16
  "temporal-spec": "^0.3.0"
33
17
  },
34
18
  "peerDependencies": {
35
19
  "temporal-polyfill": "^0.3.0",
36
- "zod": "^4.0.0",
37
- "@nmtjs/common": "0.14.4"
20
+ "zod": "^4.1.0",
21
+ "@nmtjs/common": "0.15.0-beta.1"
38
22
  },
39
23
  "devDependencies": {
40
24
  "temporal-polyfill": "^0.3.0",
41
- "zod": "^4.0.0",
42
- "@nmtjs/common": "0.14.4"
25
+ "zod": "^4.1.0",
26
+ "@nmtjs/common": "0.15.0-beta.1"
43
27
  },
44
28
  "peerDependenciesMeta": {
45
29
  "temporal-polyfill": {
46
30
  "optional": true
47
31
  }
48
32
  },
49
- "version": "0.14.4",
33
+ "version": "0.15.0-beta.1",
50
34
  "scripts": {
35
+ "clean-build": "rm -rf ./dist",
51
36
  "build": "tsc",
37
+ "dev": "tsc --watch",
52
38
  "type-check": "tsc --noEmit"
53
39
  }
54
40
  }
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import * as type from './types/_type.ts';
2
- export * from './types/base.ts';
3
- export { type, type as t };
4
- export default type;
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- import { en } from 'zod/locales';
2
- import { config } from 'zod/mini';
3
- import * as type from "./types/_type.js";
4
- config(en());
5
- export * from "./types/base.js";
6
- export { type, type as t };
7
- export default type;
@@ -1,8 +0,0 @@
1
- import 'temporal-spec/global';
2
- export declare const plainDate: () => import("../types/custom.ts").CustomType<import("temporal-spec").Temporal.PlainDate, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<import("temporal-spec").Temporal.PlainDate, import("temporal-spec").Temporal.PlainDate, import("zod/v4/core").$ZodTypeInternals<import("temporal-spec").Temporal.PlainDate, import("temporal-spec").Temporal.PlainDate>>>;
3
- export declare const plainDatetime: () => import("../types/custom.ts").CustomType<import("temporal-spec").Temporal.PlainDateTime, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<import("temporal-spec").Temporal.PlainDateTime, import("temporal-spec").Temporal.PlainDateTime, import("zod/v4/core").$ZodTypeInternals<import("temporal-spec").Temporal.PlainDateTime, import("temporal-spec").Temporal.PlainDateTime>>>;
4
- export declare const plainTime: () => import("../types/custom.ts").CustomType<import("temporal-spec").Temporal.PlainTime, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<import("temporal-spec").Temporal.PlainTime, import("temporal-spec").Temporal.PlainTime, import("zod/v4/core").$ZodTypeInternals<import("temporal-spec").Temporal.PlainTime, import("temporal-spec").Temporal.PlainTime>>>;
5
- export declare const zonedDatetime: () => import("../types/custom.ts").CustomType<import("temporal-spec").Temporal.ZonedDateTime, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<import("temporal-spec").Temporal.ZonedDateTime, import("temporal-spec").Temporal.ZonedDateTime, import("zod/v4/core").$ZodTypeInternals<import("temporal-spec").Temporal.ZonedDateTime, import("temporal-spec").Temporal.ZonedDateTime>>>;
6
- export declare const duration: () => import("../types/custom.ts").CustomType<import("temporal-spec").Temporal.Duration, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<import("temporal-spec").Temporal.Duration, import("temporal-spec").Temporal.Duration, import("zod/v4/core").$ZodTypeInternals<import("temporal-spec").Temporal.Duration, import("temporal-spec").Temporal.Duration>>>;
7
- export declare const plainYearMonth: () => import("../types/custom.ts").CustomType<import("temporal-spec").Temporal.PlainYearMonth, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<import("temporal-spec").Temporal.PlainYearMonth, import("temporal-spec").Temporal.PlainYearMonth, import("zod/v4/core").$ZodTypeInternals<import("temporal-spec").Temporal.PlainYearMonth, import("temporal-spec").Temporal.PlainYearMonth>>>;
8
- export declare const plainMonthDay: () => import("../types/custom.ts").CustomType<import("temporal-spec").Temporal.PlainMonthDay, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<import("temporal-spec").Temporal.PlainMonthDay, import("temporal-spec").Temporal.PlainMonthDay, import("zod/v4/core").$ZodTypeInternals<import("temporal-spec").Temporal.PlainMonthDay, import("temporal-spec").Temporal.PlainMonthDay>>>;
@@ -1,9 +0,0 @@
1
- import 'temporal-spec/global';
2
- import { DurationType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType, } from "../types/temporal.js";
3
- export const plainDate = PlainDateType.factory.bind(PlainDateType, Temporal);
4
- export const plainDatetime = PlainDateTimeType.factory.bind(PlainDateTimeType, Temporal);
5
- export const plainTime = PlainTimeType.factory.bind(PlainTimeType, Temporal);
6
- export const zonedDatetime = ZonedDateTimeType.factory.bind(ZonedDateTimeType, Temporal);
7
- export const duration = DurationType.factory.bind(DurationType, Temporal);
8
- export const plainYearMonth = PlainYearMonthType.factory.bind(PlainYearMonthType, Temporal);
9
- export const plainMonthDay = PlainMonthDayType.factory.bind(PlainMonthDayType, Temporal);
@@ -1,8 +0,0 @@
1
- import { Temporal } from 'temporal-polyfill';
2
- export declare const plainDate: () => import("../types/custom.ts").CustomType<Temporal.PlainDate, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<Temporal.PlainDate, Temporal.PlainDate, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainDate, Temporal.PlainDate>>>;
3
- export declare const plainDatetime: () => import("../types/custom.ts").CustomType<Temporal.PlainDateTime, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<Temporal.PlainDateTime, Temporal.PlainDateTime, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainDateTime, Temporal.PlainDateTime>>>;
4
- export declare const plainTime: () => import("../types/custom.ts").CustomType<Temporal.PlainTime, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<Temporal.PlainTime, Temporal.PlainTime, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainTime, Temporal.PlainTime>>>;
5
- export declare const zonedDatetime: () => import("../types/custom.ts").CustomType<Temporal.ZonedDateTime, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<Temporal.ZonedDateTime, Temporal.ZonedDateTime, import("zod/v4/core").$ZodTypeInternals<Temporal.ZonedDateTime, Temporal.ZonedDateTime>>>;
6
- export declare const duration: () => import("../types/custom.ts").CustomType<Temporal.Duration, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<Temporal.Duration, Temporal.Duration, import("zod/v4/core").$ZodTypeInternals<Temporal.Duration, Temporal.Duration>>>;
7
- export declare const plainYearMonth: () => import("../types/custom.ts").CustomType<Temporal.PlainYearMonth, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<Temporal.PlainYearMonth, Temporal.PlainYearMonth, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainYearMonth, Temporal.PlainYearMonth>>>;
8
- export declare const plainMonthDay: () => import("../types/custom.ts").CustomType<Temporal.PlainMonthDay, import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniType<Temporal.PlainMonthDay, Temporal.PlainMonthDay, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainMonthDay, Temporal.PlainMonthDay>>>;
@@ -1,9 +0,0 @@
1
- import { Temporal } from 'temporal-polyfill';
2
- import { DurationType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType, } from "../types/temporal.js";
3
- export const plainDate = PlainDateType.factory.bind(PlainDateType, Temporal);
4
- export const plainDatetime = PlainDateTimeType.factory.bind(PlainDateTimeType, Temporal);
5
- export const plainTime = PlainTimeType.factory.bind(PlainTimeType, Temporal);
6
- export const zonedDatetime = ZonedDateTimeType.factory.bind(ZonedDateTimeType, Temporal);
7
- export const duration = DurationType.factory.bind(DurationType, Temporal);
8
- export const plainYearMonth = PlainYearMonthType.factory.bind(PlainYearMonthType, Temporal);
9
- export const plainMonthDay = PlainMonthDayType.factory.bind(PlainMonthDayType, Temporal);
@@ -1,24 +0,0 @@
1
- import type { BaseTypeAny } from './base.ts';
2
- export * from './any.ts';
3
- export * from './array.ts';
4
- export * from './boolean.ts';
5
- export * from './custom.ts';
6
- export * from './date.ts';
7
- export * from './enum.ts';
8
- export * from './literal.ts';
9
- export * from './never.ts';
10
- export * from './number.ts';
11
- export * from './object.ts';
12
- export * from './string.ts';
13
- export * from './tuple.ts';
14
- export * from './union.ts';
15
- export declare namespace infer {
16
- namespace decode {
17
- type input<T extends BaseTypeAny> = T['decodeZodType']['_zod']['input'];
18
- type output<T extends BaseTypeAny> = T['decodeZodType']['_zod']['output'];
19
- }
20
- namespace encode {
21
- type input<T extends BaseTypeAny> = T['encodeZodType']['_zod']['input'];
22
- type output<T extends BaseTypeAny> = T['encodeZodType']['_zod']['output'];
23
- }
24
- }
@@ -1,13 +0,0 @@
1
- export * from "./any.js";
2
- export * from "./array.js";
3
- export * from "./boolean.js";
4
- export * from "./custom.js";
5
- export * from "./date.js";
6
- export * from "./enum.js";
7
- export * from "./literal.js";
8
- export * from "./never.js";
9
- export * from "./number.js";
10
- export * from "./object.js";
11
- export * from "./string.js";
12
- export * from "./tuple.js";
13
- export * from "./union.js";
@@ -1,6 +0,0 @@
1
- import type { ZodMiniAny } from 'zod/mini';
2
- import { BaseType } from './base.ts';
3
- export declare class AnyType extends BaseType<ZodMiniAny> {
4
- static factory(): AnyType;
5
- }
6
- export declare const any: typeof AnyType.factory;
package/dist/types/any.js DELETED
@@ -1,8 +0,0 @@
1
- import { any as zodAny } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class AnyType extends BaseType {
4
- static factory() {
5
- return new AnyType({ encodeZodType: zodAny() });
6
- }
7
- }
8
- export const any = AnyType.factory;
@@ -1,13 +0,0 @@
1
- import type { core, ZodMiniArray } from 'zod/mini';
2
- import { BaseType } from './base.ts';
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
- element: T;
6
- }> {
7
- static factory<T extends BaseType>(element: T, ...checks: Check[]): ArrayType<T>;
8
- min(value: number): ArrayType<T>;
9
- max(value: number): ArrayType<T>;
10
- length(value: number): ArrayType<T>;
11
- }
12
- export declare const array: typeof ArrayType.factory;
13
- export {};
@@ -1,25 +0,0 @@
1
- import { length, maxLength, minLength, array as zodArray } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class ArrayType extends BaseType {
4
- static factory(element, ...checks) {
5
- return new ArrayType({
6
- encodeZodType: zodArray(element.encodeZodType).check(...checks),
7
- decodeZodType: zodArray(element.decodeZodType).check(...checks),
8
- params: { checks },
9
- props: { element },
10
- });
11
- }
12
- min(value) {
13
- const check = minLength(value);
14
- return ArrayType.factory(this.props.element, ...this.params.checks, check);
15
- }
16
- max(value) {
17
- const check = maxLength(value);
18
- return ArrayType.factory(this.props.element, ...this.params.checks, check);
19
- }
20
- length(value) {
21
- const check = length(value);
22
- return ArrayType.factory(this.props.element, ...this.params.checks, check);
23
- }
24
- }
25
- export const array = ArrayType.factory;
@@ -1,63 +0,0 @@
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';
3
- export type PrimitiveValueType = string | number | boolean | null;
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;
7
- export type TypeProps = Record<string, any>;
8
- export type TypeMetadata<T = any> = {
9
- id?: string;
10
- description?: string;
11
- examples?: T[];
12
- title?: string;
13
- };
14
- export type TypeParams = {
15
- encode?: (value: any) => any;
16
- metadata?: TypeMetadata;
17
- checks: Array<core.CheckFn<any> | core.$ZodCheck<any>>;
18
- };
19
- export type DefaultTypeParams = {
20
- encode?: TypeParams['encode'];
21
- metadata?: TypeMetadata;
22
- };
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;
30
- readonly props: Props;
31
- readonly params: TypeParams;
32
- constructor({ encodeZodType, decodeZodType, props, params, }: {
33
- encodeZodType: EncodeZodType;
34
- decodeZodType?: DecodeZodType;
35
- props?: Props;
36
- params?: Partial<TypeParams>;
37
- });
38
- optional(): OptionalType<this>;
39
- nullable(): NullableType<this>;
40
- nullish(): OptionalType<NullableType<this>>;
41
- default(value: this['encodeZodType']['_zod']['input']): DefaultType<this>;
42
- title(title: string): this;
43
- description(description: string): this;
44
- examples(...examples: this['encodeZodType']['_zod']['input'][]): this;
45
- meta(newMetadata: TypeMetadata): 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'];
48
- }
49
- export declare class OptionalType<Type extends BaseTypeAny = BaseTypeAny> extends BaseType<ZodMiniOptional<Type['encodeZodType']>, ZodMiniOptional<Type['decodeZodType']>, {
50
- inner: Type;
51
- }> {
52
- static factory<T extends BaseTypeAny>(type: T): OptionalType<T>;
53
- }
54
- export declare class NullableType<Type extends BaseTypeAny<any> = BaseTypeAny<any>> extends BaseType<ZodMiniNullable<Type['encodeZodType']>, ZodMiniNullable<Type['decodeZodType']>, {
55
- inner: Type;
56
- }> {
57
- static factory<T extends BaseTypeAny<any>>(type: T): NullableType<T>;
58
- }
59
- export declare class DefaultType<Type extends BaseTypeAny = BaseTypeAny> extends BaseType<ZodMiniDefault<Type['encodeZodType']>, ZodMiniDefault<Type['decodeZodType']>, {
60
- inner: Type;
61
- }> {
62
- static factory<T extends BaseTypeAny<any>>(type: T, defaultValue: any): DefaultType<T>;
63
- }
@@ -1,79 +0,0 @@
1
- import { _default, core, nullable, optional, registry } from 'zod/mini';
2
- export const typesRegistry = registry();
3
- export const NeemataTypeError = core.$ZodError;
4
- export class BaseType {
5
- encodeZodType;
6
- decodeZodType;
7
- props;
8
- params;
9
- constructor({ encodeZodType, decodeZodType = encodeZodType, props = {}, params = {}, }) {
10
- this.encodeZodType = encodeZodType;
11
- this.decodeZodType = decodeZodType;
12
- this.props = props;
13
- this.params = Object.assign({ checks: [] }, params);
14
- }
15
- optional() {
16
- return OptionalType.factory(this);
17
- }
18
- nullable() {
19
- return NullableType.factory(this);
20
- }
21
- nullish() {
22
- return this.nullable().optional();
23
- }
24
- default(value) {
25
- return DefaultType.factory(this, value);
26
- }
27
- title(title) {
28
- return this.meta({ title });
29
- }
30
- description(description) {
31
- return this.meta({ description });
32
- }
33
- examples(...examples) {
34
- return this.meta({
35
- examples: this.params.encode
36
- ? examples.map(this.params.encode)
37
- : examples,
38
- });
39
- }
40
- meta(newMetadata) {
41
- const metadata = typesRegistry.get(this.encodeZodType) ?? {};
42
- Object.assign(metadata, newMetadata);
43
- typesRegistry.add(this.encodeZodType, metadata);
44
- return this;
45
- }
46
- encode(data, context = {}) {
47
- return this.encodeZodType.parse(data, { reportInput: true, ...context });
48
- }
49
- decode(data, context = {}) {
50
- return this.decodeZodType.parse(data, { reportInput: true, ...context });
51
- }
52
- }
53
- export class OptionalType extends BaseType {
54
- static factory(type) {
55
- return new OptionalType({
56
- encodeZodType: optional(type.encodeZodType),
57
- decodeZodType: optional(type.decodeZodType),
58
- props: { inner: type },
59
- });
60
- }
61
- }
62
- export class NullableType extends BaseType {
63
- static factory(type) {
64
- return new NullableType({
65
- encodeZodType: nullable(type.encodeZodType),
66
- decodeZodType: nullable(type.decodeZodType),
67
- props: { inner: type },
68
- });
69
- }
70
- }
71
- export class DefaultType extends BaseType {
72
- static factory(type, defaultValue) {
73
- return new DefaultType({
74
- encodeZodType: _default(type.encodeZodType, type.params.encode?.(defaultValue) ?? defaultValue),
75
- decodeZodType: _default(type.decodeZodType, defaultValue),
76
- props: { inner: type },
77
- });
78
- }
79
- }
@@ -1,6 +0,0 @@
1
- import type { ZodMiniBoolean } from 'zod/mini';
2
- import { BaseType } from './base.ts';
3
- export declare class BooleanType extends BaseType<ZodMiniBoolean<boolean>> {
4
- static factory(): BooleanType;
5
- }
6
- export declare const boolean: typeof BooleanType.factory;
@@ -1,8 +0,0 @@
1
- import { boolean as zodBoolean } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class BooleanType extends BaseType {
4
- static factory() {
5
- return new BooleanType({ encodeZodType: zodBoolean() });
6
- }
7
- }
8
- export const boolean = BooleanType.factory;
@@ -1,15 +0,0 @@
1
- import type { core, ZodMiniType } from 'zod/mini';
2
- import type { SimpleZodType, ZodType } from './base.ts';
3
- import { BaseType } from './base.ts';
4
- export type CustomTransformFn<I, O> = (value: I) => O;
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']>> {
6
- }
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>;
14
- }
15
- export declare const custom: typeof CustomType.factory;
@@ -1,16 +0,0 @@
1
- import { any, overwrite, pipe, refine, custom as zodCustom } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class TransformType extends BaseType {
4
- }
5
- export class CustomType extends TransformType {
6
- static factory({ decode, encode, error, type = any(), }) {
7
- return new CustomType({
8
- encodeZodType: pipe(zodCustom().check(refine((val) => typeof val !== 'undefined', { error, abort: true }), overwrite(encode)), type),
9
- decodeZodType: pipe(type,
10
- // @ts-expect-error
11
- zodCustom().check(refine((val) => typeof val !== 'undefined', { error, abort: true }), overwrite(decode))),
12
- params: { encode },
13
- });
14
- }
15
- }
16
- export const custom = CustomType.factory;
@@ -1,7 +0,0 @@
1
- import type { ZodMiniUnion } from 'zod/mini';
2
- import { iso } from 'zod/mini';
3
- import { CustomType, TransformType } from './custom.ts';
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>>>;
6
- }
7
- export declare const date: typeof DateType.factory;
@@ -1,12 +0,0 @@
1
- import { iso, union } from 'zod/mini';
2
- import { CustomType, TransformType } from "./custom.js";
3
- export class DateType extends TransformType {
4
- static factory() {
5
- return CustomType.factory({
6
- decode: (value) => new Date(value),
7
- encode: (value) => value.toISOString(),
8
- type: union([iso.date(), iso.datetime()]),
9
- });
10
- }
11
- }
12
- export const date = DateType.factory;
@@ -1,10 +0,0 @@
1
- import type { core, ZodMiniEnum } from 'zod/mini';
2
- import { BaseType } from './base.ts';
3
- export declare class EnumType<T extends core.util.EnumLike = core.util.EnumLike> extends BaseType<ZodMiniEnum<T>, ZodMiniEnum<T>, {
4
- values: T;
5
- }> {
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
- }
9
- declare const _enum: typeof EnumType.factory;
10
- export { _enum as enum };
@@ -1,12 +0,0 @@
1
- import { enum as zodEnum } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class EnumType extends BaseType {
4
- static factory(values) {
5
- return new EnumType({
6
- encodeZodType: zodEnum(values),
7
- props: { values },
8
- });
9
- }
10
- }
11
- const _enum = EnumType.factory;
12
- export { _enum as enum };
@@ -1,9 +0,0 @@
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>, {
5
- value: T;
6
- }> {
7
- static factory<T extends PrimitiveValueType>(value: T): LiteralType<T>;
8
- }
9
- export declare const literal: typeof LiteralType.factory;
@@ -1,11 +0,0 @@
1
- import { literal as zodLiteral } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class LiteralType extends BaseType {
4
- static factory(value) {
5
- return new LiteralType({
6
- encodeZodType: zodLiteral(value),
7
- props: { value },
8
- });
9
- }
10
- }
11
- export const literal = LiteralType.factory;
@@ -1,6 +0,0 @@
1
- import type { ZodMiniNever } from 'zod/mini';
2
- import { BaseType } from './base.ts';
3
- export declare class NeverType extends BaseType<ZodMiniNever> {
4
- static factory(): NeverType;
5
- }
6
- export declare const never: typeof NeverType.factory;
@@ -1,8 +0,0 @@
1
- import { never as zodNever } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class NeverType extends BaseType {
4
- static factory() {
5
- return new NeverType({ encodeZodType: zodNever() });
6
- }
7
- }
8
- export const never = NeverType.factory;
@@ -1,23 +0,0 @@
1
- import type { core, ZodMiniNumber, ZodMiniString } from 'zod/mini';
2
- import { BaseType } from './base.ts';
3
- import { CustomType, TransformType } from './custom.ts';
4
- type Check = core.CheckFn<number> | core.$ZodCheck<number>;
5
- export declare class NumberType extends BaseType<ZodMiniNumber<number>, ZodMiniNumber<number>> {
6
- static factory(...checks: Check[]): NumberType;
7
- positive(): NumberType;
8
- negative(): NumberType;
9
- lt(value: number): NumberType;
10
- lte(value: number): NumberType;
11
- gte(value: number): NumberType;
12
- gt(value: number): NumberType;
13
- }
14
- export declare class IntegerType extends NumberType {
15
- static factory(...checks: Check[]): NumberType;
16
- }
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
- }
20
- export declare const number: typeof NumberType.factory;
21
- export declare const integer: typeof IntegerType.factory;
22
- export declare const bigInt: typeof BigIntType.factory;
23
- export {};
@@ -1,47 +0,0 @@
1
- import { gt, gte, int, lt, lte, regex, number as zodNumber, string as zodString, } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- import { CustomType, TransformType } from "./custom.js";
4
- export class NumberType extends BaseType {
5
- static factory(...checks) {
6
- return new NumberType({
7
- encodeZodType: zodNumber().check(...checks),
8
- params: { checks },
9
- });
10
- }
11
- positive() {
12
- return NumberType.factory(...this.params.checks, gte(0));
13
- }
14
- negative() {
15
- return NumberType.factory(...this.params.checks, lte(0));
16
- }
17
- lt(value) {
18
- return NumberType.factory(...this.params.checks, lt(value));
19
- }
20
- lte(value) {
21
- return NumberType.factory(...this.params.checks, lte(value));
22
- }
23
- gte(value) {
24
- return NumberType.factory(...this.params.checks, gte(value));
25
- }
26
- gt(value) {
27
- return NumberType.factory(...this.params.checks, gt(value));
28
- }
29
- }
30
- export class IntegerType extends NumberType {
31
- static factory(...checks) {
32
- return NumberType.factory(...checks, int());
33
- }
34
- }
35
- export class BigIntType extends TransformType {
36
- static factory() {
37
- return CustomType.factory({
38
- decode: (value) => BigInt(value),
39
- encode: (value) => value.toString(),
40
- type: zodString().check(regex(/^-?\d+$/)),
41
- error: 'Invalid bigint format',
42
- });
43
- }
44
- }
45
- export const number = NumberType.factory;
46
- export const integer = IntegerType.factory;
47
- export const bigInt = BigIntType.factory;
@@ -1,44 +0,0 @@
1
- import type { core, ZodMiniObject, ZodMiniRecord } from 'zod/mini';
2
- import type { BaseTypeAny, OptionalType } from './base.ts';
3
- import type { LiteralType } from './literal.ts';
4
- import type { StringType } from './string.ts';
5
- import { BaseType } from './base.ts';
6
- import { EnumType } from './enum.ts';
7
- export type ObjectTypeProps = {
8
- [k: string]: BaseTypeAny;
9
- };
10
- export type AnyObjectType = ObjectType<ObjectTypeProps>;
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>, {
16
- properties: T;
17
- }> {
18
- static factory<T extends ObjectTypeProps = {}>(properties: T): ObjectType<T>;
19
- }
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']>> {
21
- static factory<K extends LiteralType<string | number> | EnumType | StringType, E extends BaseType>(key: K, element: E): RecordType<K, E>;
22
- }
23
- export declare function keyof<T extends ObjectType>(type: T): EnumType<core.util.ToEnum<Extract<keyof T['props']['properties'], string>>>;
24
- export declare function pick<T extends AnyObjectType, P extends {
25
- [K in keyof T['props']['properties']]?: true;
26
- }>(source: T, pick: P): ObjectType<{
27
- [K in keyof P]: P[K] extends true ? K extends keyof T['props']['properties'] ? T['props']['properties'][K] : never : never;
28
- }>;
29
- export declare function omit<T extends AnyObjectType, P extends {
30
- [K in keyof T['props']['properties']]?: true;
31
- }>(source: T, omit: P): ObjectType<{
32
- [K in keyof T['props']['properties'] as K extends keyof P ? never : K]: T['props']['properties'][K];
33
- }>;
34
- export declare function extend<T extends AnyObjectType, P extends ObjectTypeProps>(object1: T, properties: P): ObjectType<{
35
- [K in keyof T['props']['properties'] | keyof P]: K extends keyof P ? P[K] : K extends keyof T['props']['properties'] ? T['props']['properties'][K] : never;
36
- }>;
37
- export declare function merge<T1 extends AnyObjectType, T2 extends AnyObjectType>(object1: T1, object2: T2): ObjectType<{
38
- [K in keyof T1['props']['properties'] | keyof T2['props']['properties']]: K extends keyof T2['props']['properties'] ? T2['props']['properties'][K] : K extends keyof T1['props']['properties'] ? T1['props']['properties'][K] : never;
39
- }>;
40
- export declare function partial<T extends AnyObjectType, P extends T extends ObjectType<infer Props> ? Props : never>(object: T): ObjectType<{
41
- [K in keyof P]: OptionalType<P[K]>;
42
- }>;
43
- export declare const object: typeof ObjectType.factory;
44
- export declare const record: typeof RecordType.factory;
@@ -1,59 +0,0 @@
1
- import { object as zodObject, record as zodRecord } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- import { EnumType } from "./enum.js";
4
- export class ObjectType extends BaseType {
5
- static factory(properties) {
6
- const encodeProperties = {};
7
- const decodeProperties = {};
8
- for (const key in properties) {
9
- encodeProperties[key] = properties[key].encodeZodType;
10
- decodeProperties[key] = properties[key].decodeZodType;
11
- }
12
- return new ObjectType({
13
- encodeZodType: zodObject(encodeProperties),
14
- decodeZodType: zodObject(decodeProperties),
15
- props: { properties },
16
- });
17
- }
18
- }
19
- export class RecordType extends BaseType {
20
- static factory(key, element) {
21
- return new RecordType({
22
- encodeZodType: zodRecord(key.encodeZodType, element.encodeZodType),
23
- decodeZodType: zodRecord(key.decodeZodType, element.decodeZodType),
24
- props: { key, element },
25
- });
26
- }
27
- }
28
- export function keyof(type) {
29
- return EnumType.factory(Object.keys(type.props.properties));
30
- }
31
- export function pick(source, pick) {
32
- const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key]) => pick[key]));
33
- return ObjectType.factory(properties);
34
- }
35
- export function omit(source, omit) {
36
- const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key]) => !omit[key]));
37
- return ObjectType.factory(properties);
38
- }
39
- export function extend(object1, properties) {
40
- return ObjectType.factory({
41
- ...object1.props.properties,
42
- ...properties,
43
- });
44
- }
45
- export function merge(object1, object2) {
46
- return ObjectType.factory({
47
- ...object1.props.properties,
48
- ...object2.props.properties,
49
- });
50
- }
51
- export function partial(object) {
52
- const properties = {};
53
- for (const [key, value] of Object.entries(object.props.properties)) {
54
- properties[key] = value.optional();
55
- }
56
- return ObjectType.factory(properties);
57
- }
58
- export const object = ObjectType.factory;
59
- export const record = RecordType.factory;
@@ -1,22 +0,0 @@
1
- import type { core, ZodMiniString } from 'zod/mini';
2
- import { BaseType } from './base.ts';
3
- type Check = core.CheckFn<string> | core.$ZodCheck<string>;
4
- export declare class StringType extends BaseType<ZodMiniString<string>, ZodMiniString<string>> {
5
- static factory(...checks: Check[]): StringType;
6
- max(value: number): StringType;
7
- min(value: number): StringType;
8
- pattern(pattern: string | RegExp): StringType;
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
- }
21
- export declare const string: typeof StringType.factory;
22
- export {};
@@ -1,53 +0,0 @@
1
- import { cuid, cuid2, e164, email, emoji, ipv4, ipv6, jwt, maxLength, minLength, nanoid, regex, url, uuid, string as zodString, } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class StringType extends BaseType {
4
- static factory(...checks) {
5
- return new StringType({
6
- encodeZodType: zodString().check(...checks),
7
- params: { checks },
8
- });
9
- }
10
- max(value) {
11
- return StringType.factory(...this.params.checks, maxLength(value));
12
- }
13
- min(value) {
14
- return StringType.factory(...this.params.checks, minLength(value));
15
- }
16
- pattern(pattern) {
17
- return StringType.factory(...this.params.checks, regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern));
18
- }
19
- email(options) {
20
- return StringType.factory(...this.params.checks, email(options));
21
- }
22
- url(options) {
23
- return StringType.factory(...this.params.checks, url(options));
24
- }
25
- ipv4(options) {
26
- return StringType.factory(...this.params.checks, ipv4(options));
27
- }
28
- ipv6(options) {
29
- return StringType.factory(...this.params.checks, ipv6(options));
30
- }
31
- uuid(options) {
32
- return StringType.factory(...this.params.checks, uuid(options));
33
- }
34
- emoji(options) {
35
- return StringType.factory(...this.params.checks, emoji(options));
36
- }
37
- nanoid(options) {
38
- return StringType.factory(...this.params.checks, nanoid(options));
39
- }
40
- cuid(options) {
41
- return StringType.factory(...this.params.checks, cuid(options));
42
- }
43
- cuid2(options) {
44
- return StringType.factory(...this.params.checks, cuid2(options));
45
- }
46
- e164(options) {
47
- return StringType.factory(...this.params.checks, e164(options));
48
- }
49
- jwt(options) {
50
- return StringType.factory(...this.params.checks, jwt(options));
51
- }
52
- }
53
- export const string = StringType.factory;
@@ -1,26 +0,0 @@
1
- import type { Temporal } from 'temporal-spec';
2
- import type { ZodMiniString } from 'zod/mini';
3
- import { CustomType, TransformType } from './custom.ts';
4
- type EncodeType = ZodMiniString<string>;
5
- export declare class PlainDateType extends TransformType<Temporal.PlainDate, EncodeType> {
6
- static factory(implementation: typeof Temporal): CustomType<Temporal.PlainDate, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainDate, Temporal.PlainDate, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainDate, Temporal.PlainDate>>>;
7
- }
8
- export declare class PlainDateTimeType extends TransformType<Temporal.PlainDateTime, EncodeType> {
9
- static factory(implementation: typeof Temporal): CustomType<Temporal.PlainDateTime, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainDateTime, Temporal.PlainDateTime, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainDateTime, Temporal.PlainDateTime>>>;
10
- }
11
- export declare class ZonedDateTimeType extends TransformType<Temporal.ZonedDateTime, EncodeType> {
12
- static factory(implementation: typeof Temporal): CustomType<Temporal.ZonedDateTime, EncodeType, import("zod/mini").ZodMiniType<Temporal.ZonedDateTime, Temporal.ZonedDateTime, import("zod/v4/core").$ZodTypeInternals<Temporal.ZonedDateTime, Temporal.ZonedDateTime>>>;
13
- }
14
- export declare class PlainTimeType extends TransformType<Temporal.PlainTime, EncodeType> {
15
- static factory(implementation: typeof Temporal): CustomType<Temporal.PlainTime, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainTime, Temporal.PlainTime, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainTime, Temporal.PlainTime>>>;
16
- }
17
- export declare class DurationType extends TransformType<Temporal.Duration, EncodeType> {
18
- static factory(implementation: typeof Temporal): CustomType<Temporal.Duration, EncodeType, import("zod/mini").ZodMiniType<Temporal.Duration, Temporal.Duration, import("zod/v4/core").$ZodTypeInternals<Temporal.Duration, Temporal.Duration>>>;
19
- }
20
- export declare class PlainYearMonthType extends TransformType<Temporal.PlainYearMonth, EncodeType> {
21
- static factory(implementation: typeof Temporal): CustomType<Temporal.PlainYearMonth, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainYearMonth, Temporal.PlainYearMonth, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainYearMonth, Temporal.PlainYearMonth>>>;
22
- }
23
- export declare class PlainMonthDayType extends TransformType<Temporal.PlainMonthDay, EncodeType> {
24
- static factory(implementation: typeof Temporal): CustomType<Temporal.PlainMonthDay, EncodeType, import("zod/mini").ZodMiniType<Temporal.PlainMonthDay, Temporal.PlainMonthDay, import("zod/v4/core").$ZodTypeInternals<Temporal.PlainMonthDay, Temporal.PlainMonthDay>>>;
25
- }
26
- export {};
@@ -1,93 +0,0 @@
1
- import { iso, regex, string } from 'zod/mini';
2
- import { CustomType, TransformType } from "./custom.js";
3
- const createTemporalTransformer = (implementation, type, decode = (value) => implementation[type].from(value), encode = (value) => value.toString({
4
- calendarName: 'never',
5
- smallestUnit: 'microsecond',
6
- timeZoneName: 'never',
7
- })) => {
8
- return { decode, encode };
9
- };
10
- export class PlainDateType extends TransformType {
11
- static factory(implementation) {
12
- const transformer = createTemporalTransformer(implementation, 'PlainDate');
13
- return CustomType.factory({
14
- decode: transformer.decode,
15
- encode: transformer.encode,
16
- type: iso.date(),
17
- error: 'Invalid date format',
18
- });
19
- }
20
- }
21
- export class PlainDateTimeType extends TransformType {
22
- static factory(implementation) {
23
- const transformer = createTemporalTransformer(implementation, 'PlainDateTime');
24
- return CustomType.factory({
25
- decode: transformer.decode,
26
- encode: transformer.encode,
27
- type: iso.datetime({ local: true }),
28
- error: 'Invalid datetime format',
29
- });
30
- }
31
- }
32
- export class ZonedDateTimeType extends TransformType {
33
- static factory(implementation) {
34
- const transformer = createTemporalTransformer(implementation, 'ZonedDateTime', (value) => implementation.Instant.from(value).toZonedDateTimeISO('UTC'), (value) => value
35
- .withTimeZone('UTC')
36
- .toString({
37
- smallestUnit: 'milliseconds',
38
- timeZoneName: 'never',
39
- calendarName: 'never',
40
- offset: 'never',
41
- }) + 'Z');
42
- return CustomType.factory({
43
- decode: transformer.decode,
44
- encode: transformer.encode,
45
- type: iso.datetime(),
46
- error: 'Invalid datetime format',
47
- });
48
- }
49
- }
50
- export class PlainTimeType extends TransformType {
51
- static factory(implementation) {
52
- const transformer = createTemporalTransformer(implementation, 'PlainTime');
53
- return CustomType.factory({
54
- decode: transformer.decode,
55
- encode: transformer.encode,
56
- type: iso.time(),
57
- error: 'Invalid time format',
58
- });
59
- }
60
- }
61
- export class DurationType extends TransformType {
62
- static factory(implementation) {
63
- const transformer = createTemporalTransformer(implementation, 'Duration');
64
- return CustomType.factory({
65
- decode: transformer.decode,
66
- encode: transformer.encode,
67
- type: iso.duration(),
68
- error: 'Invalid duration format',
69
- });
70
- }
71
- }
72
- export class PlainYearMonthType extends TransformType {
73
- static factory(implementation) {
74
- const transformer = createTemporalTransformer(implementation, 'PlainYearMonth');
75
- return CustomType.factory({
76
- decode: transformer.decode,
77
- encode: transformer.encode,
78
- type: string().check(regex(/^\d{4}-\d{2}$/)),
79
- error: 'Invalid year-month format',
80
- });
81
- }
82
- }
83
- export class PlainMonthDayType extends TransformType {
84
- static factory(implementation) {
85
- const transformer = createTemporalTransformer(implementation, 'PlainMonthDay');
86
- return CustomType.factory({
87
- decode: transformer.decode,
88
- encode: transformer.encode,
89
- type: string().check(regex(/^\d{2}-\d{2}$/)),
90
- error: 'Invalid month-day format',
91
- });
92
- }
93
- }
@@ -1,13 +0,0 @@
1
- import type { ArrayMap } from '@nmtjs/common';
2
- import type { ZodMiniTuple } from 'zod/mini';
3
- import { BaseType } from './base.ts';
4
- export declare class TupleType<T extends readonly [BaseType, ...BaseType[]] = readonly [
5
- BaseType,
6
- ...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
- elements: T;
9
- rest?: R;
10
- }> {
11
- static factory<T extends readonly [BaseType, ...BaseType[]], R extends BaseType | null = null>(elements: T, rest?: R): TupleType<T, R>;
12
- }
13
- export declare const tuple: typeof TupleType.factory;
@@ -1,16 +0,0 @@
1
- import { tuple as zodTuple } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class TupleType extends BaseType {
4
- static factory(elements, rest = null) {
5
- const encode = elements.map((el) => el.encodeZodType);
6
- const decode = elements.map((el) => el.decodeZodType);
7
- return new TupleType({
8
- // @ts-expect-error
9
- encodeZodType: zodTuple(encode, rest?.encodeZodType),
10
- // @ts-expect-error
11
- decodeZodType: zodTuple(decode, rest?.decodeZodType),
12
- props: { elements, rest },
13
- });
14
- }
15
- }
16
- export const tuple = TupleType.factory;
@@ -1,41 +0,0 @@
1
- import type { ArrayMap } from '@nmtjs/common';
2
- import type { ZodMiniDiscriminatedUnion, ZodMiniIntersection, ZodMiniUnion } from 'zod/mini';
3
- import type { BaseTypeAny } from './base.ts';
4
- import type { LiteralType } from './literal.ts';
5
- import type { ObjectType, ObjectTypeProps } from './object.ts';
6
- import { BaseType } from './base.ts';
7
- export declare class UnionType<T extends readonly [BaseType, ...BaseType[]] = readonly [
8
- BaseType,
9
- ...BaseType[]
10
- ]> extends BaseType<ZodMiniUnion<ArrayMap<T, 'encodeZodType'>>, ZodMiniUnion<ArrayMap<T, 'decodeZodType'>>, {
11
- options: T;
12
- }> {
13
- static factory<T extends readonly [BaseType, ...BaseType[]] = readonly [
14
- BaseType,
15
- ...BaseType[]
16
- ]>(...options: T): UnionType<T>;
17
- }
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']>, {
19
- options: T;
20
- }> {
21
- static factory<T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType]>(...options: T): IntersactionType<T>;
22
- }
23
- export type DiscriminatedUnionProperties<K extends string = string> = {
24
- [OK in K]: LiteralType<string>;
25
- } & {
26
- [OK in string]: any;
27
- };
28
- export type DiscriminatedUnionOptionType<K extends string> = ObjectType<ObjectTypeProps & {
29
- [_ in K]: BaseTypeAny;
30
- }>;
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'>>, {
32
- key: K;
33
- options: T;
34
- }> {
35
- static factory<K extends string = string, T extends readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[]>(key: K, ...options: T): DiscriminatedUnionType<K, T>;
36
- }
37
- export declare const union: typeof UnionType.factory;
38
- export declare const or: typeof UnionType.factory;
39
- export declare const intersection: typeof IntersactionType.factory;
40
- export declare const and: typeof IntersactionType.factory;
41
- export declare const discriminatedUnion: typeof DiscriminatedUnionType.factory;
@@ -1,41 +0,0 @@
1
- import { discriminatedUnion as zodDiscriminatedUnion, intersection as zodIntersection, union as zodUnion, } from 'zod/mini';
2
- import { BaseType } from "./base.js";
3
- export class UnionType extends BaseType {
4
- static factory(...options) {
5
- const encode = options.map((t) => t.encodeZodType);
6
- const decode = options.map((t) => t.decodeZodType);
7
- return new UnionType({
8
- encodeZodType: zodUnion(encode),
9
- decodeZodType: zodUnion(decode),
10
- props: { options },
11
- });
12
- }
13
- }
14
- export class IntersactionType extends BaseType {
15
- static factory(...options) {
16
- const [first, second] = options;
17
- return new IntersactionType({
18
- encodeZodType: zodIntersection(first.encodeZodType, second.encodeZodType),
19
- decodeZodType: zodIntersection(first.decodeZodType, second.decodeZodType),
20
- props: { options },
21
- });
22
- }
23
- }
24
- export class DiscriminatedUnionType extends BaseType {
25
- static factory(key, ...options) {
26
- const encode = options.map((t) => t.encodeZodType);
27
- const decode = options.map((t) => t.decodeZodType);
28
- return new DiscriminatedUnionType({
29
- // @ts-expect-error
30
- encodeZodType: zodDiscriminatedUnion(key, encode),
31
- // @ts-expect-error
32
- decodeZodType: zodDiscriminatedUnion(key, decode),
33
- props: { key, options },
34
- });
35
- }
36
- }
37
- export const union = UnionType.factory;
38
- export const or = UnionType.factory;
39
- export const intersection = IntersactionType.factory;
40
- export const and = IntersactionType.factory;
41
- export const discriminatedUnion = DiscriminatedUnionType.factory;