@nmtjs/type 0.15.0-beta.1 → 0.15.0-beta.3
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 +7 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/temporal/global.d.ts +9 -0
- package/dist/temporal/global.js +10 -0
- package/dist/temporal/global.js.map +1 -0
- package/dist/temporal/polyfill.d.ts +8 -0
- package/dist/temporal/polyfill.js +10 -0
- package/dist/temporal/polyfill.js.map +1 -0
- package/dist/types/_convert.d.ts +5 -0
- package/dist/types/_convert.js +56 -0
- package/dist/types/_convert.js.map +1 -0
- package/dist/types/_type.d.ts +33 -0
- package/dist/types/_type.js +15 -0
- package/dist/types/_type.js.map +1 -0
- package/dist/types/_utils.d.ts +15 -0
- package/dist/types/_utils.js +3 -0
- package/dist/types/_utils.js.map +1 -0
- package/dist/types/any.d.ts +6 -0
- package/dist/types/any.js +9 -0
- package/dist/types/any.js.map +1 -0
- package/dist/types/array.d.ts +14 -0
- package/dist/types/array.js +26 -0
- package/dist/types/array.js.map +1 -0
- package/dist/types/base.d.ts +65 -0
- package/dist/types/base.js +82 -0
- package/dist/types/base.js.map +1 -0
- package/dist/types/boolean.d.ts +6 -0
- package/dist/types/boolean.js +9 -0
- package/dist/types/boolean.js.map +1 -0
- package/dist/types/custom.d.ts +21 -0
- package/dist/types/custom.js +33 -0
- package/dist/types/custom.js.map +1 -0
- package/dist/types/date.d.ts +7 -0
- package/dist/types/date.js +14 -0
- package/dist/types/date.js.map +1 -0
- package/dist/types/enum.d.ts +10 -0
- package/dist/types/enum.js +13 -0
- package/dist/types/enum.js.map +1 -0
- package/dist/types/literal.d.ts +9 -0
- package/dist/types/literal.js +12 -0
- package/dist/types/literal.js.map +1 -0
- package/dist/types/never.d.ts +6 -0
- package/dist/types/never.js +9 -0
- package/dist/types/never.js.map +1 -0
- package/dist/types/null.d.ts +7 -0
- package/dist/types/null.js +10 -0
- package/dist/types/null.js.map +1 -0
- package/dist/types/number.d.ts +23 -0
- package/dist/types/number.js +48 -0
- package/dist/types/number.js.map +1 -0
- package/dist/types/object.d.ts +79 -0
- package/dist/types/object.js +77 -0
- package/dist/types/object.js.map +1 -0
- package/dist/types/string.d.ts +22 -0
- package/dist/types/string.js +54 -0
- package/dist/types/string.js.map +1 -0
- package/dist/types/temporal.d.ts +26 -0
- package/dist/types/temporal.js +94 -0
- package/dist/types/temporal.js.map +1 -0
- package/dist/types/tuple.d.ts +14 -0
- package/dist/types/tuple.js +17 -0
- package/dist/types/tuple.js.map +1 -0
- package/dist/types/union.d.ts +42 -0
- package/dist/types/union.js +42 -0
- package/dist/types/union.js.map +1 -0
- package/package.json +4 -4
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { en } from 'zod/locales';
|
|
2
|
+
import { config } from 'zod/mini';
|
|
3
|
+
import * as type from "./types/_type.js";
|
|
4
|
+
export * from "./types/_convert.js";
|
|
5
|
+
export * from "./types/_utils.js";
|
|
6
|
+
export * from "./types/base.js";
|
|
7
|
+
export { type, type as t };
|
|
8
|
+
export default type;
|
|
9
|
+
export function registerDefaultLocale() {
|
|
10
|
+
config(en());
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA;AAExC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,CAAA;AAC1B,eAAe,IAAI,CAAA;AAEnB,MAAM,UAAU,qBAAqB;IACnC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import 'temporal-spec/global';
|
|
2
|
+
import { DurationType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType } from '../types/temporal.ts';
|
|
3
|
+
export declare const plainDate: () => PlainDateType;
|
|
4
|
+
export declare const plainDatetime: () => PlainDateTimeType;
|
|
5
|
+
export declare const plainTime: () => PlainTimeType;
|
|
6
|
+
export declare const zonedDatetime: () => ZonedDateTimeType;
|
|
7
|
+
export declare const duration: () => DurationType;
|
|
8
|
+
export declare const plainYearMonth: () => PlainYearMonthType;
|
|
9
|
+
export declare const plainMonthDay: () => PlainMonthDayType;
|
|
@@ -0,0 +1,10 @@
|
|
|
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);
|
|
10
|
+
//# sourceMappingURL=global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/temporal/global.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAA;AAE7B,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,sBAAsB,CAAA;AAE7B,MAAM,CAAC,MAAM,SAAS,GAAwB,aAAa,CAAC,OAAO,CAAC,IAAI,CACtE,aAAa,EACb,QAAQ,CACT,CAAA;AACD,MAAM,CAAC,MAAM,aAAa,GACxB,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;AAC7D,MAAM,CAAC,MAAM,SAAS,GAAwB,aAAa,CAAC,OAAO,CAAC,IAAI,CACtE,aAAa,EACb,QAAQ,CACT,CAAA;AACD,MAAM,CAAC,MAAM,aAAa,GACxB,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;AAC7D,MAAM,CAAC,MAAM,QAAQ,GAAuB,YAAY,CAAC,OAAO,CAAC,IAAI,CACnE,YAAY,EACZ,QAAQ,CACT,CAAA;AACD,MAAM,CAAC,MAAM,cAAc,GACzB,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAA;AAC/D,MAAM,CAAC,MAAM,aAAa,GACxB,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DurationType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType } from '../types/temporal.ts';
|
|
2
|
+
export declare const plainDate: () => PlainDateType;
|
|
3
|
+
export declare const plainDatetime: () => PlainDateTimeType;
|
|
4
|
+
export declare const plainTime: () => PlainTimeType;
|
|
5
|
+
export declare const zonedDatetime: () => ZonedDateTimeType;
|
|
6
|
+
export declare const duration: () => DurationType;
|
|
7
|
+
export declare const plainYearMonth: () => PlainYearMonthType;
|
|
8
|
+
export declare const plainMonthDay: () => PlainMonthDayType;
|
|
@@ -0,0 +1,10 @@
|
|
|
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);
|
|
10
|
+
//# sourceMappingURL=polyfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../../src/temporal/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,sBAAsB,CAAA;AAE7B,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAA;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,IAAI,CACzD,iBAAiB,EACjB,QAAQ,CACT,CAAA;AACD,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAA;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,IAAI,CACzD,iBAAiB,EACjB,QAAQ,CACT,CAAA;AACD,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;AACzE,MAAM,CAAC,MAAM,cAAc,GAAG,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAC3D,kBAAkB,EAClB,QAAQ,CACT,CAAA;AACD,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,IAAI,CACzD,iBAAiB,EACjB,QAAQ,CACT,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { core } from 'zod/mini';
|
|
2
|
+
import { toJSONSchema } from 'zod/mini';
|
|
3
|
+
import type { BaseType } from './base.ts';
|
|
4
|
+
export declare function typeToString(type: BaseType): string;
|
|
5
|
+
export declare function typeToJsonSchema(type: BaseType, mode: 'encode' | 'decode', options?: Parameters<typeof toJSONSchema>[1]): core.JSONSchema.JSONSchema;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { toJSONSchema } from 'zod/mini';
|
|
2
|
+
import { AnyType } from "./any.js";
|
|
3
|
+
import { ArrayType } from "./array.js";
|
|
4
|
+
import { NullableType, OptionalType } from "./base.js";
|
|
5
|
+
import { BooleanType } from "./boolean.js";
|
|
6
|
+
import { CustomType } from "./custom.js";
|
|
7
|
+
import { DateType } from "./date.js";
|
|
8
|
+
import { LiteralType } from "./literal.js";
|
|
9
|
+
import { NumberType } from "./number.js";
|
|
10
|
+
import { ObjectType } from "./object.js";
|
|
11
|
+
import { StringType } from "./string.js";
|
|
12
|
+
import { TupleType } from "./tuple.js";
|
|
13
|
+
export function typeToString(type) {
|
|
14
|
+
switch (true) {
|
|
15
|
+
case type instanceof OptionalType:
|
|
16
|
+
return `?<${typeToString(type.props.inner)}>`;
|
|
17
|
+
case type instanceof NullableType:
|
|
18
|
+
return `null | ${typeToString(type.props.inner)}`;
|
|
19
|
+
case type instanceof StringType:
|
|
20
|
+
return 'string';
|
|
21
|
+
case type instanceof NumberType:
|
|
22
|
+
return 'number';
|
|
23
|
+
case type instanceof LiteralType:
|
|
24
|
+
return `literal(${type.props.value})`;
|
|
25
|
+
case type instanceof BooleanType:
|
|
26
|
+
return 'boolean';
|
|
27
|
+
case type instanceof DateType:
|
|
28
|
+
return 'string';
|
|
29
|
+
case type instanceof ArrayType:
|
|
30
|
+
return `array<${typeToString(type.props.element)}>`;
|
|
31
|
+
case type instanceof ObjectType: {
|
|
32
|
+
const props = type.props.properties;
|
|
33
|
+
const propsStrings = Object.keys(props).map((key) => `${key}: ${typeToString(props[key])}`);
|
|
34
|
+
return `{ ${propsStrings.join(', ')} }`;
|
|
35
|
+
}
|
|
36
|
+
case type instanceof TupleType: {
|
|
37
|
+
const elements = type.props.elements;
|
|
38
|
+
const elementsStrings = elements.map((el) => typeToString(el));
|
|
39
|
+
const rest = type.props.rest
|
|
40
|
+
? `, ...${typeToString(type.props.rest)}`
|
|
41
|
+
: '';
|
|
42
|
+
return `[${elementsStrings.join(', ')}${rest}]`;
|
|
43
|
+
}
|
|
44
|
+
case type instanceof AnyType:
|
|
45
|
+
return 'any';
|
|
46
|
+
case type instanceof CustomType:
|
|
47
|
+
return typeToJsonSchema(type, 'decode').type || 'custom';
|
|
48
|
+
default:
|
|
49
|
+
return 'unknown';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export function typeToJsonSchema(type, mode, options) {
|
|
53
|
+
const zodType = { encode: type.encodeZodType, decode: type.decodeZodType }[mode];
|
|
54
|
+
return toJSONSchema(zodType, options);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=_convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_convert.js","sourceRoot":"","sources":["../../src/types/_convert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY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EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,CACxE,IAAI,CACL,CAAA;IACD,OAAO,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 './null.ts';
|
|
11
|
+
export * from './number.ts';
|
|
12
|
+
export * from './object.ts';
|
|
13
|
+
export * from './string.ts';
|
|
14
|
+
export * from './tuple.ts';
|
|
15
|
+
export * from './union.ts';
|
|
16
|
+
export declare namespace infer {
|
|
17
|
+
namespace decode {
|
|
18
|
+
type input<T extends BaseTypeAny> = T['decodeZodType']['_zod']['input'];
|
|
19
|
+
type output<T extends BaseTypeAny> = T['decodeZodType']['_zod']['output'];
|
|
20
|
+
}
|
|
21
|
+
namespace encode {
|
|
22
|
+
type input<T extends BaseTypeAny> = T['encodeZodType']['_zod']['input'];
|
|
23
|
+
type output<T extends BaseTypeAny> = T['encodeZodType']['_zod']['output'];
|
|
24
|
+
}
|
|
25
|
+
namespace decodeRaw {
|
|
26
|
+
type input<T extends BaseTypeAny> = T['decodeRawZodType']['_zod']['input'];
|
|
27
|
+
type output<T extends BaseTypeAny> = T['decodeRawZodType']['_zod']['output'];
|
|
28
|
+
}
|
|
29
|
+
namespace encodeRaw {
|
|
30
|
+
type input<T extends BaseTypeAny> = T['encodeRawZodType']['_zod']['input'];
|
|
31
|
+
type output<T extends BaseTypeAny> = T['encodeRawZodType']['_zod']['output'];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 "./null.js";
|
|
10
|
+
export * from "./number.js";
|
|
11
|
+
export * from "./object.js";
|
|
12
|
+
export * from "./string.js";
|
|
13
|
+
export * from "./tuple.js";
|
|
14
|
+
export * from "./union.js";
|
|
15
|
+
//# sourceMappingURL=_type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_type.js","sourceRoot":"","sources":["../../src/types/_type.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { core, ZodMiniType } from 'zod/mini';
|
|
2
|
+
import type { BaseType } from './base.ts';
|
|
3
|
+
export declare const PlainType: unique symbol;
|
|
4
|
+
export type PlainType = typeof PlainType;
|
|
5
|
+
export type ZodPlainType<T extends ZodMiniType<any, any, any>> = T & ZodMiniType<T['_zod']['output'] & {
|
|
6
|
+
[PlainType]?: true;
|
|
7
|
+
}, T['_zod']['input'] & {
|
|
8
|
+
[PlainType]?: true;
|
|
9
|
+
}, core.$ZodTypeInternals<T['_zod']['output'] & {
|
|
10
|
+
[PlainType]?: true;
|
|
11
|
+
}, T['_zod']['input'] & {
|
|
12
|
+
[PlainType]?: true;
|
|
13
|
+
}>>;
|
|
14
|
+
export declare const zodPlainType: <T extends ZodMiniType<any, any, any>>(type: T) => ZodPlainType<T>;
|
|
15
|
+
export type AnyCompatibleType<Encoded = any, Decoded = any> = BaseType<ZodMiniType<any, Decoded>, ZodMiniType<any, Encoded>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_utils.js","sourceRoot":"","sources":["../../src/types/_utils.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,SAAS,GAAkB,MAAM,CAAC,WAAW,CAAC,CAAA;AAa3D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAuC,IAAO,EAAE,EAAE,CAC5E,IAAuB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
9
|
+
//# sourceMappingURL=any.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"any.js","sourceRoot":"","sources":["../../src/types/any.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,OAAO,OAAQ,SAAQ,QAAoB;IAC/C,MAAM,CAAC,OAAO;QACZ,OAAO,IAAI,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;IACjD,CAAC;CACF;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { core, ZodMiniArray } from 'zod/mini';
|
|
2
|
+
import type { ZodPlainType } from './_utils.ts';
|
|
3
|
+
import { BaseType } from './base.ts';
|
|
4
|
+
type Check = core.CheckFn<any[]> | core.$ZodCheck<any[]>;
|
|
5
|
+
export declare class ArrayType<T extends BaseType = BaseType> extends BaseType<ZodMiniArray<T['encodeZodType']>, ZodMiniArray<T['decodeZodType']>, {
|
|
6
|
+
element: T;
|
|
7
|
+
}, ZodPlainType<ZodMiniArray<T['encodeZodType']>>, ZodPlainType<ZodMiniArray<T['encodeZodType']>>> {
|
|
8
|
+
static factory<T extends BaseType>(element: T, ...checks: Check[]): ArrayType<T>;
|
|
9
|
+
min(value: number): ArrayType<T>;
|
|
10
|
+
max(value: number): ArrayType<T>;
|
|
11
|
+
length(value: number): ArrayType<T>;
|
|
12
|
+
}
|
|
13
|
+
export declare const array: typeof ArrayType.factory;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
26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tB,IAAI,CAAC,KAAK,CAAC,OAAO,EAClB,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EACrB,KAAK,CACN,CAAA;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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, RawEncodeZodType extends SimpleZodType = EncodeZodType, RawDecodeZodType extends ZodType = DecodeZodType> {
|
|
28
|
+
readonly encodeZodType: EncodeZodType;
|
|
29
|
+
readonly decodeZodType: DecodeZodType;
|
|
30
|
+
readonly encodeRawZodType: RawEncodeZodType;
|
|
31
|
+
readonly decodeRawZodType: RawDecodeZodType;
|
|
32
|
+
readonly props: Props;
|
|
33
|
+
readonly params: TypeParams;
|
|
34
|
+
constructor({ encodeZodType, decodeZodType, props, params, }: {
|
|
35
|
+
encodeZodType: EncodeZodType;
|
|
36
|
+
decodeZodType?: DecodeZodType;
|
|
37
|
+
props?: Props;
|
|
38
|
+
params?: Partial<TypeParams>;
|
|
39
|
+
});
|
|
40
|
+
optional(): OptionalType<this>;
|
|
41
|
+
nullable(): NullableType<this>;
|
|
42
|
+
nullish(): OptionalType<NullableType<this>>;
|
|
43
|
+
default(value: this['encodeZodType']['_zod']['input']): DefaultType<this>;
|
|
44
|
+
title(title: string): this;
|
|
45
|
+
description(description: string): this;
|
|
46
|
+
examples(...examples: this['encodeZodType']['_zod']['input'][]): this;
|
|
47
|
+
meta(newMetadata: TypeMetadata): this;
|
|
48
|
+
encode(data: this['encodeZodType']['_zod']['input'], context?: core.ParseContext<core.$ZodIssue>): this['encodeZodType']['_zod']['output'];
|
|
49
|
+
decode(data: this['decodeZodType']['_zod']['input'], context?: core.ParseContext<core.$ZodIssue>): this['decodeZodType']['_zod']['output'];
|
|
50
|
+
}
|
|
51
|
+
export declare class OptionalType<Type extends BaseTypeAny = BaseTypeAny> extends BaseType<ZodMiniOptional<Type['encodeZodType']>, ZodMiniOptional<Type['decodeZodType']>, {
|
|
52
|
+
inner: Type;
|
|
53
|
+
}> {
|
|
54
|
+
static factory<T extends BaseTypeAny>(type: T): OptionalType<T>;
|
|
55
|
+
}
|
|
56
|
+
export declare class NullableType<Type extends BaseTypeAny<any> = BaseTypeAny<any>> extends BaseType<ZodMiniNullable<Type['encodeZodType']>, ZodMiniNullable<Type['decodeZodType']>, {
|
|
57
|
+
inner: Type;
|
|
58
|
+
}> {
|
|
59
|
+
static factory<T extends BaseTypeAny<any>>(type: T): NullableType<T>;
|
|
60
|
+
}
|
|
61
|
+
export declare class DefaultType<Type extends BaseTypeAny = BaseTypeAny> extends BaseType<ZodMiniDefault<Type['encodeZodType']>, ZodMiniDefault<Type['decodeZodType']>, {
|
|
62
|
+
inner: Type;
|
|
63
|
+
}> {
|
|
64
|
+
static factory<T extends BaseTypeAny<any>>(type: T, defaultValue: any): DefaultType<T>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
encodeRawZodType;
|
|
8
|
+
decodeRawZodType;
|
|
9
|
+
props;
|
|
10
|
+
params;
|
|
11
|
+
constructor({ encodeZodType, decodeZodType = encodeZodType, props = {}, params = {}, }) {
|
|
12
|
+
this.encodeZodType = encodeZodType;
|
|
13
|
+
this.decodeZodType = decodeZodType;
|
|
14
|
+
this.props = props;
|
|
15
|
+
this.params = Object.assign({ checks: [] }, params);
|
|
16
|
+
}
|
|
17
|
+
optional() {
|
|
18
|
+
return OptionalType.factory(this);
|
|
19
|
+
}
|
|
20
|
+
nullable() {
|
|
21
|
+
return NullableType.factory(this);
|
|
22
|
+
}
|
|
23
|
+
nullish() {
|
|
24
|
+
return this.nullable().optional();
|
|
25
|
+
}
|
|
26
|
+
default(value) {
|
|
27
|
+
return DefaultType.factory(this, value);
|
|
28
|
+
}
|
|
29
|
+
title(title) {
|
|
30
|
+
return this.meta({ title });
|
|
31
|
+
}
|
|
32
|
+
description(description) {
|
|
33
|
+
return this.meta({ description });
|
|
34
|
+
}
|
|
35
|
+
examples(...examples) {
|
|
36
|
+
return this.meta({
|
|
37
|
+
examples: this.params.encode
|
|
38
|
+
? examples.map(this.params.encode)
|
|
39
|
+
: examples,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
meta(newMetadata) {
|
|
43
|
+
const metadata = typesRegistry.get(this.encodeZodType) ?? {};
|
|
44
|
+
Object.assign(metadata, newMetadata);
|
|
45
|
+
typesRegistry.add(this.encodeZodType, metadata);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
encode(data, context = {}) {
|
|
49
|
+
return this.encodeZodType.parse(data, { reportInput: true, ...context });
|
|
50
|
+
}
|
|
51
|
+
decode(data, context = {}) {
|
|
52
|
+
return this.decodeZodType.parse(data, { reportInput: true, ...context });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class OptionalType extends BaseType {
|
|
56
|
+
static factory(type) {
|
|
57
|
+
return new OptionalType({
|
|
58
|
+
encodeZodType: optional(type.encodeZodType),
|
|
59
|
+
decodeZodType: optional(type.decodeZodType),
|
|
60
|
+
props: { inner: type },
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export class NullableType extends BaseType {
|
|
65
|
+
static factory(type) {
|
|
66
|
+
return new NullableType({
|
|
67
|
+
encodeZodType: nullable(type.encodeZodType),
|
|
68
|
+
decodeZodType: nullable(type.decodeZodType),
|
|
69
|
+
props: { inner: type },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export class DefaultType extends BaseType {
|
|
74
|
+
static factory(type, defaultValue) {
|
|
75
|
+
return new DefaultType({
|
|
76
|
+
encodeZodType: _default(type.encodeZodType, type.params.encode?.(defaultValue) ?? defaultValue),
|
|
77
|
+
decodeZodType: _default(type.decodeZodType, defaultValue),
|
|
78
|
+
props: { inner: type },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/types/base.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAkDvE,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,EAAgB,CAAA;AAErD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAA;AAG9C,MAAM,OAAgB,QAAQ;IAOnB,aAAa,CAAe;IAC5B,aAAa,CAAe;IAC5B,gBAAgB,CAAmB;IACnC,gBAAgB,CAAmB;IACnC,KAAK,CAAO;IACZ,MAAM,CAAY;IAE3B,YAAY,EACV,aAAa,EACb,aAAa,GAAG,aAAyC,EACzD,KAAK,GAAG,EAAW,EACnB,MAAM,GAAG,EAAyB,GAMnC;QACC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAElC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IACrD,CAAC;IAED,QAAQ;QACN,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAED,QAAQ;QACN,OAAO,Y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aseType {
|
|
4
|
+
static factory() {
|
|
5
|
+
return new BooleanType({ encodeZodType: zodBoolean() });
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export const boolean = BooleanType.factory;
|
|
9
|
+
//# sourceMappingURL=boolean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/types/boolean.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,UAAU,CAAA;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,OAAO,WAAY,SAAQ,QAAiC;IAChE,MAAM,CAAC,OAAO;QACZ,OAAO,IAAI,WAAW,CAAC,EAAE,aAAa,EAAE,UAAU,EAAE,EAAE,CAAC,CAAA;IACzD,CAAC;CACF;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Async } from '@nmtjs/common';
|
|
2
|
+
import type { core, ZodMiniType } from 'zod/mini';
|
|
3
|
+
import type { SimpleZodType, ZodType } from './base.ts';
|
|
4
|
+
import { BaseType } from './base.ts';
|
|
5
|
+
export type CustomTransformFn<I, O> = (value: I) => O;
|
|
6
|
+
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']>> {
|
|
7
|
+
}
|
|
8
|
+
export declare class CustomType<Type, EncodeType extends SimpleZodType = ZodMiniType<Type, Type>, DecodeType extends ZodType = ZodMiniType<Type, Type>> extends TransformType<Type, EncodeType, DecodeType> {
|
|
9
|
+
static factory<Type, EncodeType extends SimpleZodType = ZodMiniType<Type, Type>, DecodeType extends ZodType = ZodMiniType<Type, Type>>({ decode, encode, validation, error, type, prototype, }: {
|
|
10
|
+
decode: CustomTransformFn<EncodeType['_zod']['input'], DecodeType['_zod']['output']>;
|
|
11
|
+
encode: CustomTransformFn<DecodeType['_zod']['input'], EncodeType['_zod']['output']>;
|
|
12
|
+
validation?: ((value: EncodeType['_zod']['input'] | DecodeType['_zod']['output'], payload: core.$RefinementCtx<EncodeType['_zod']['output'] | DecodeType['_zod']['output']>) => Async<void>) | {
|
|
13
|
+
encode?: (value: EncodeType['_zod']['input'], payload: core.$RefinementCtx<EncodeType['_zod']['output']>) => Async<void>;
|
|
14
|
+
decode?: (value: DecodeType['_zod']['output'], payload: core.$RefinementCtx<DecodeType['_zod']['output']>) => Async<void>;
|
|
15
|
+
};
|
|
16
|
+
error?: string | core.$ZodErrorMap<core.$ZodIssueBase>;
|
|
17
|
+
type?: EncodeType;
|
|
18
|
+
prototype?: object;
|
|
19
|
+
}): CustomType<Type, EncodeType, DecodeType>;
|
|
20
|
+
}
|
|
21
|
+
export declare const custom: typeof CustomType.factory;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { any, overwrite, pipe, refine, superRefine, 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, validation, error, type = any(), prototype, }) {
|
|
7
|
+
const _validation = validation
|
|
8
|
+
? typeof validation === 'function'
|
|
9
|
+
? { encode: validation, decode: validation }
|
|
10
|
+
: validation
|
|
11
|
+
: undefined;
|
|
12
|
+
const instance = new CustomType({
|
|
13
|
+
encodeZodType: pipe(zodCustom().check(...[
|
|
14
|
+
refine((val) => typeof val !== 'undefined', { abort: true }),
|
|
15
|
+
_validation?.encode ? superRefine(_validation.encode) : undefined,
|
|
16
|
+
overwrite(encode),
|
|
17
|
+
].filter((v) => !!v)), type),
|
|
18
|
+
decodeZodType: pipe(type,
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
zodCustom().check(...[
|
|
21
|
+
refine((val) => typeof val !== 'undefined', { abort: true }),
|
|
22
|
+
overwrite(decode),
|
|
23
|
+
_validation?.decode ? superRefine(_validation.decode) : undefined,
|
|
24
|
+
].filter((v) => !!v))),
|
|
25
|
+
params: { encode },
|
|
26
|
+
});
|
|
27
|
+
if (prototype)
|
|
28
|
+
Object.setPrototypeOf(instance, prototype);
|
|
29
|
+
return instance;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export const custom = CustomType.factory;
|
|
33
|
+
//# sourceMappingURL=custom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.js","sourceRoot":"","sources":["../../src/types/custom.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,GAAG,EACH,SAAS,EACT,IAAI,EACJ,MAAM,EACN,WAAW,EACX,MAAM,IAAI,SAAS,GACpB,MAAM,UAAU,CAAA;AAGjB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAGpC,MAAM,OAAgB,aAIpB,SAAQ,QAGT;CAAG;AAEJ,MAAM,OAAO,UAIX,SAAQ,aAA2C;IACnD,MAAM,CAAC,OAAO,CAIZ,EACA,MAAM,EACN,MAAM,EACN,UAAU,EACV,KAAK,EACL,IAAI,GAAG,GAAG,EAA2B,EACrC,SAAS,GA+BV;QACC,MAAM,WAAW,GAAG,UAAU;YAC5B,CAAC,CAAC,OAAO,UAAU,KAAK,UAAU;gBAChC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE;gBAC5C,CAAC,CAAC,UAAU;YACd,CAAC,CAAC,SAAS,CAAA;QAEb,MAAM,QAAQ,GAAG,IAAI,UAAU,CAA+B;YAC5D,aAAa,EAAE,IAAI,CACjB,SAAS,EAAE,CAAC,KAAK,CACf,GAAG;gBACD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBAC5D,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;gBACjE,SAAS,CAAC,MAAM,CAAC;aAClB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CACrB,EACD,IAAI,CACL;YACD,aAAa,EAAE,IAAI,CACjB,IAAI;YACJ,mBAAmB;YACnB,SAAS,EAAE,CAAC,KAAK,CACf,GAAG;gBACD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBAC5D,SAAS,CAAC,MAAM,CAAC;gBACjB,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;aAClE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CACrB,CACF;YACD,MAAM,EAAE,EAAE,MAAM,EAAE;SACnB,CAAC,CAAA;QAEF,IAAI,SAAS;YAAE,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;QAEzD,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ZodMiniUnion } from 'zod/mini';
|
|
2
|
+
import { iso } from 'zod/mini';
|
|
3
|
+
import { TransformType } from './custom.ts';
|
|
4
|
+
export declare class DateType extends TransformType<Date, ZodMiniUnion<[iso.ZodMiniISODate, iso.ZodMiniISODateTime]>> {
|
|
5
|
+
static factory(): DateType;
|
|
6
|
+
}
|
|
7
|
+
export declare const date: typeof DateType.factory;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
prototype: DateType.prototype,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const date = DateType.factory;
|
|
14
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/types/date.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEvD,MAAM,OAAO,QAAS,SAAQ,aAG7B;IACC,MAAM,CAAC,OAAO;QACZ,OAAO,UAAU,CAAC,OAAO,CAGvB;YACA,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC;YAClC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE;YACtC,IAAI,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YACzC,SAAS,EAAE,QAAQ,CAAC,SAAS;SAC9B,CAAC,CAAA;IACJ,CAAC;CACF;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 };
|
|
@@ -0,0 +1,13 @@
|
|
|
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 };
|
|
13
|
+
//# sourceMappingURL=enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/types/enum.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,UAAU,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,OAAO,QAEX,SAAQ,QAAuD;IAK/D,MAAM,CAAC,OAAO,CAA0C,MAAS;QAC/D,OAAO,IAAI,QAAQ,CAAC;YAClB,aAAa,EAAE,OAAO,CAAC,MAAa,CAAC;YACrC,KAAK,EAAE,EAAE,MAAM,EAAE;SAClB,CAAC,CAAA;IACJ,CAAC;CACF;AAED,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAA;AAE9B,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
12
|
+
//# sourceMappingURL=literal.js.map
|