@nmtjs/type 0.14.5 → 0.15.0-beta.10
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 +1 -1
- package/README.md +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -0
- package/dist/temporal/global.d.ts +8 -7
- package/dist/temporal/global.js +1 -0
- package/dist/temporal/global.js.map +1 -0
- package/dist/temporal/polyfill.d.ts +8 -8
- package/dist/temporal/polyfill.js +1 -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 +1 -0
- package/dist/types/_type.js +2 -0
- package/dist/types/_type.js.map +1 -0
- package/dist/types/{_plain.d.ts → _utils.d.ts} +2 -0
- package/dist/types/{_plain.js → _utils.js} +1 -0
- package/dist/types/_utils.js.map +1 -0
- package/dist/types/any.js +1 -0
- package/dist/types/any.js.map +1 -0
- package/dist/types/array.d.ts +1 -1
- package/dist/types/array.js +1 -0
- package/dist/types/array.js.map +1 -0
- package/dist/types/base.js +1 -0
- package/dist/types/base.js.map +1 -0
- package/dist/types/boolean.js +1 -0
- package/dist/types/boolean.js.map +1 -0
- package/dist/types/custom.d.ts +7 -1
- package/dist/types/custom.js +22 -5
- package/dist/types/custom.js.map +1 -0
- package/dist/types/date.d.ts +2 -2
- package/dist/types/date.js +2 -0
- package/dist/types/date.js.map +1 -0
- package/dist/types/enum.js +1 -0
- package/dist/types/enum.js.map +1 -0
- package/dist/types/literal.js +1 -0
- package/dist/types/literal.js.map +1 -0
- package/dist/types/never.js +1 -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.js +1 -0
- package/dist/types/number.js.map +1 -0
- package/dist/types/object.d.ts +42 -15
- package/dist/types/object.js +19 -2
- package/dist/types/object.js.map +1 -0
- package/dist/types/string.js +1 -0
- package/dist/types/string.js.map +1 -0
- package/dist/types/temporal.d.ts +8 -8
- package/dist/types/temporal.js +1 -0
- package/dist/types/temporal.js.map +1 -0
- package/dist/types/tuple.d.ts +1 -1
- package/dist/types/tuple.js +1 -0
- package/dist/types/tuple.js.map +1 -0
- package/dist/types/union.d.ts +1 -1
- package/dist/types/union.js +1 -0
- package/dist/types/union.js.map +1 -0
- package/package.json +13 -26
- package/src/index.ts +14 -0
- package/src/temporal/global.ts +32 -0
- package/src/temporal/polyfill.ts +31 -0
- package/src/types/_convert.ts +68 -0
- package/src/types/_type.ts +46 -0
- package/src/types/_utils.ts +24 -0
- package/src/types/any.ts +12 -0
- package/src/types/array.ts +53 -0
- package/src/types/base.ts +209 -0
- package/src/types/boolean.ts +12 -0
- package/src/types/custom.ts +109 -0
- package/src/types/date.ts +23 -0
- package/src/types/enum.ts +23 -0
- package/src/types/literal.ts +18 -0
- package/src/types/never.ts +12 -0
- package/src/types/null.ts +14 -0
- package/src/types/number.ts +73 -0
- package/src/types/object.ts +225 -0
- package/src/types/string.ts +95 -0
- package/src/types/temporal.ts +155 -0
- package/src/types/tuple.ts +49 -0
- package/src/types/union.ts +120 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/types/string.ts"],"names":[],"mappings":"AACA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,SAAS,EACT,SAAS,EACT,MAAM,EACN,KAAK,EACL,GAAG,EACH,IAAI,EACJ,MAAM,IAAI,SAAS,GACpB,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAIpC,MAAM,OAAO,UAAW,SAAQ,QAG/B;IACC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAe;QAC/B,OA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@
|
|
|
1
1
|
import type { Temporal } from 'temporal-spec';
|
|
2
2
|
import type { ZodMiniString } from 'zod/mini';
|
|
3
|
-
import {
|
|
3
|
+
import { TransformType } from './custom.ts';
|
|
4
4
|
type EncodeType = ZodMiniString<string>;
|
|
5
5
|
export declare class PlainDateType extends TransformType<Temporal.PlainDate, EncodeType> {
|
|
6
|
-
static factory(implementation: typeof Temporal):
|
|
6
|
+
static factory(implementation: typeof Temporal): PlainDateType;
|
|
7
7
|
}
|
|
8
8
|
export declare class PlainDateTimeType extends TransformType<Temporal.PlainDateTime, EncodeType> {
|
|
9
|
-
static factory(implementation: typeof Temporal):
|
|
9
|
+
static factory(implementation: typeof Temporal): PlainDateTimeType;
|
|
10
10
|
}
|
|
11
11
|
export declare class ZonedDateTimeType extends TransformType<Temporal.ZonedDateTime, EncodeType> {
|
|
12
|
-
static factory(implementation: typeof Temporal):
|
|
12
|
+
static factory(implementation: typeof Temporal): ZonedDateTimeType;
|
|
13
13
|
}
|
|
14
14
|
export declare class PlainTimeType extends TransformType<Temporal.PlainTime, EncodeType> {
|
|
15
|
-
static factory(implementation: typeof Temporal):
|
|
15
|
+
static factory(implementation: typeof Temporal): PlainTimeType;
|
|
16
16
|
}
|
|
17
17
|
export declare class DurationType extends TransformType<Temporal.Duration, EncodeType> {
|
|
18
|
-
static factory(implementation: typeof Temporal):
|
|
18
|
+
static factory(implementation: typeof Temporal): DurationType;
|
|
19
19
|
}
|
|
20
20
|
export declare class PlainYearMonthType extends TransformType<Temporal.PlainYearMonth, EncodeType> {
|
|
21
|
-
static factory(implementation: typeof Temporal):
|
|
21
|
+
static factory(implementation: typeof Temporal): PlainYearMonthType;
|
|
22
22
|
}
|
|
23
23
|
export declare class PlainMonthDayType extends TransformType<Temporal.PlainMonthDay, EncodeType> {
|
|
24
|
-
static factory(implementation: typeof Temporal):
|
|
24
|
+
static factory(implementation: typeof Temporal): PlainMonthDayType;
|
|
25
25
|
}
|
|
26
26
|
export {};
|
package/dist/types/temporal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|
import type { ZodMiniTuple } from 'zod/mini';
|
|
3
|
-
import type { ZodPlainType } from './
|
|
3
|
+
import type { ZodPlainType } from './_utils.ts';
|
|
4
4
|
import { BaseType } from './base.ts';
|
|
5
5
|
export declare class TupleType<T extends readonly [BaseType, ...BaseType[]] = readonly [
|
|
6
6
|
BaseType,
|
package/dist/types/tuple.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../src/types/tuple.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAA;AAG5C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,OAAO,SAMX,SAAQ,QAkBT;IACC,MAAM,CAAC,OAAO,CAGZ,QAAW,EAAE,OAAU,IAAS;QAChC,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,aAAa,CAAC,CAAA;QACrD,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,aAAa,CAAC,CAAA;QACrD,OAAO,IAAI,SAAS,CAAO;YACzB,mBAAmB;YACnB,aAAa,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC;YACpD,mBAAmB;YACnB,aAAa,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC;YACpD,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC1B,CAAC,CAAA;IACJ,CAAC;CACF;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAA"}
|
package/dist/types/union.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ArrayMap } from '@nmtjs/common';
|
|
2
2
|
import type { ZodMiniDiscriminatedUnion, ZodMiniIntersection, ZodMiniUnion } from 'zod/mini';
|
|
3
|
-
import type { ZodPlainType } from './
|
|
3
|
+
import type { ZodPlainType } from './_utils.ts';
|
|
4
4
|
import type { BaseTypeAny } from './base.ts';
|
|
5
5
|
import type { LiteralType } from './literal.ts';
|
|
6
6
|
import type { ObjectType, ObjectTypeProps } from './object.ts';
|
package/dist/types/union.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/types/union.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,IAAI,qBAAqB,EAC3C,YAAY,IAAI,eAAe,EAC/B,KAAK,IAAI,QAAQ,GAClB,MAAM,UAAU,CAAA;AAMjB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,OAAO,SAKX,SAAQ,QAMT;IACC,MAAM,CAAC,OAAO,CAKZ,GAAG,OAAU;QACb,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAGhD,CAAA;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAGhD,CAAA;QACD,OAAO,IAAI,SAAS,CAAI;YACtB,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC;YAC/B,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC;YAC/B,KAAK,EAAE,EAAE,OAAO,EAAE;SACnB,CAAC,CAAA;IACJ,CAAC;CACF;AAED,MAAM,OAAO,gBAEX,SAAQ,QAIT;IACC,MAAM,CAAC,OAAO,CAEZ,GAAG,OAAU;QACb,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAAA;QAC/B,OAAO,IAAI,gBAAgB,CAAI;YAC7B,aAAa,EAAE,eAAe,CAAC,KAAK,CAAC,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC;YACzE,aAAa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|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
}
|
|
11
|
+
".": "./dist/index.js",
|
|
12
|
+
"./*": "./dist/types/*.js",
|
|
13
|
+
"./temporal": "./dist/temporal/global.js",
|
|
14
|
+
"./temporal-polyfill": "./dist/temporal/polyfill.js"
|
|
30
15
|
},
|
|
31
16
|
"dependencies": {
|
|
32
17
|
"temporal-spec": "^0.3.0"
|
|
33
18
|
},
|
|
34
19
|
"peerDependencies": {
|
|
35
20
|
"temporal-polyfill": "^0.3.0",
|
|
36
|
-
"zod": "^4.
|
|
37
|
-
"@nmtjs/common": "0.
|
|
21
|
+
"zod": "^4.1.0",
|
|
22
|
+
"@nmtjs/common": "0.15.0-beta.10"
|
|
38
23
|
},
|
|
39
24
|
"devDependencies": {
|
|
40
25
|
"temporal-polyfill": "^0.3.0",
|
|
41
|
-
"zod": "^4.
|
|
42
|
-
"@nmtjs/common": "0.
|
|
26
|
+
"zod": "^4.1.0",
|
|
27
|
+
"@nmtjs/common": "0.15.0-beta.10"
|
|
43
28
|
},
|
|
44
29
|
"peerDependenciesMeta": {
|
|
45
30
|
"temporal-polyfill": {
|
|
46
31
|
"optional": true
|
|
47
32
|
}
|
|
48
33
|
},
|
|
49
|
-
"version": "0.
|
|
34
|
+
"version": "0.15.0-beta.10",
|
|
50
35
|
"scripts": {
|
|
51
|
-
"build": "
|
|
36
|
+
"clean-build": "rm -rf ./dist",
|
|
37
|
+
"build": "tsc --declaration --sourcemap",
|
|
38
|
+
"dev": "tsc --watch",
|
|
52
39
|
"type-check": "tsc --noEmit"
|
|
53
40
|
}
|
|
54
41
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { en } from 'zod/locales'
|
|
2
|
+
import { config } from 'zod/mini'
|
|
3
|
+
|
|
4
|
+
import * as type from './types/_type.ts'
|
|
5
|
+
|
|
6
|
+
export * from './types/_convert.ts'
|
|
7
|
+
export * from './types/_utils.ts'
|
|
8
|
+
export * from './types/base.ts'
|
|
9
|
+
export { type, type as t }
|
|
10
|
+
export default type
|
|
11
|
+
|
|
12
|
+
export function registerDefaultLocale() {
|
|
13
|
+
config(en())
|
|
14
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import 'temporal-spec/global'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DurationType,
|
|
5
|
+
PlainDateTimeType,
|
|
6
|
+
PlainDateType,
|
|
7
|
+
PlainMonthDayType,
|
|
8
|
+
PlainTimeType,
|
|
9
|
+
PlainYearMonthType,
|
|
10
|
+
ZonedDateTimeType,
|
|
11
|
+
} from '../types/temporal.ts'
|
|
12
|
+
|
|
13
|
+
export const plainDate: () => PlainDateType = PlainDateType.factory.bind(
|
|
14
|
+
PlainDateType,
|
|
15
|
+
Temporal,
|
|
16
|
+
)
|
|
17
|
+
export const plainDatetime: () => PlainDateTimeType =
|
|
18
|
+
PlainDateTimeType.factory.bind(PlainDateTimeType, Temporal)
|
|
19
|
+
export const plainTime: () => PlainTimeType = PlainTimeType.factory.bind(
|
|
20
|
+
PlainTimeType,
|
|
21
|
+
Temporal,
|
|
22
|
+
)
|
|
23
|
+
export const zonedDatetime: () => ZonedDateTimeType =
|
|
24
|
+
ZonedDateTimeType.factory.bind(ZonedDateTimeType, Temporal)
|
|
25
|
+
export const duration: () => DurationType = DurationType.factory.bind(
|
|
26
|
+
DurationType,
|
|
27
|
+
Temporal,
|
|
28
|
+
)
|
|
29
|
+
export const plainYearMonth: () => PlainYearMonthType =
|
|
30
|
+
PlainYearMonthType.factory.bind(PlainYearMonthType, Temporal)
|
|
31
|
+
export const plainMonthDay: () => PlainMonthDayType =
|
|
32
|
+
PlainMonthDayType.factory.bind(PlainMonthDayType, Temporal)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Temporal } from 'temporal-polyfill'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DurationType,
|
|
5
|
+
PlainDateTimeType,
|
|
6
|
+
PlainDateType,
|
|
7
|
+
PlainMonthDayType,
|
|
8
|
+
PlainTimeType,
|
|
9
|
+
PlainYearMonthType,
|
|
10
|
+
ZonedDateTimeType,
|
|
11
|
+
} from '../types/temporal.ts'
|
|
12
|
+
|
|
13
|
+
export const plainDate = PlainDateType.factory.bind(PlainDateType, Temporal)
|
|
14
|
+
export const plainDatetime = PlainDateTimeType.factory.bind(
|
|
15
|
+
PlainDateTimeType,
|
|
16
|
+
Temporal,
|
|
17
|
+
)
|
|
18
|
+
export const plainTime = PlainTimeType.factory.bind(PlainTimeType, Temporal)
|
|
19
|
+
export const zonedDatetime = ZonedDateTimeType.factory.bind(
|
|
20
|
+
ZonedDateTimeType,
|
|
21
|
+
Temporal,
|
|
22
|
+
)
|
|
23
|
+
export const duration = DurationType.factory.bind(DurationType, Temporal)
|
|
24
|
+
export const plainYearMonth = PlainYearMonthType.factory.bind(
|
|
25
|
+
PlainYearMonthType,
|
|
26
|
+
Temporal,
|
|
27
|
+
)
|
|
28
|
+
export const plainMonthDay = PlainMonthDayType.factory.bind(
|
|
29
|
+
PlainMonthDayType,
|
|
30
|
+
Temporal,
|
|
31
|
+
)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { core } from 'zod/mini'
|
|
2
|
+
import { toJSONSchema } from 'zod/mini'
|
|
3
|
+
|
|
4
|
+
import type { BaseType } from './base.ts'
|
|
5
|
+
import { AnyType } from './any.ts'
|
|
6
|
+
import { ArrayType } from './array.ts'
|
|
7
|
+
import { NullableType, OptionalType } from './base.ts'
|
|
8
|
+
import { BooleanType } from './boolean.ts'
|
|
9
|
+
import { CustomType } from './custom.ts'
|
|
10
|
+
import { DateType } from './date.ts'
|
|
11
|
+
import { LiteralType } from './literal.ts'
|
|
12
|
+
import { NumberType } from './number.ts'
|
|
13
|
+
import { ObjectType } from './object.ts'
|
|
14
|
+
import { StringType } from './string.ts'
|
|
15
|
+
import { TupleType } from './tuple.ts'
|
|
16
|
+
|
|
17
|
+
export function typeToString(type: BaseType): string {
|
|
18
|
+
switch (true) {
|
|
19
|
+
case type instanceof OptionalType:
|
|
20
|
+
return `?<${typeToString(type.props.inner)}>`
|
|
21
|
+
case type instanceof NullableType:
|
|
22
|
+
return `null | ${typeToString(type.props.inner)}`
|
|
23
|
+
case type instanceof StringType:
|
|
24
|
+
return 'string'
|
|
25
|
+
case type instanceof NumberType:
|
|
26
|
+
return 'number'
|
|
27
|
+
case type instanceof LiteralType:
|
|
28
|
+
return `literal(${type.props.value})`
|
|
29
|
+
case type instanceof BooleanType:
|
|
30
|
+
return 'boolean'
|
|
31
|
+
case type instanceof DateType:
|
|
32
|
+
return 'string'
|
|
33
|
+
case type instanceof ArrayType:
|
|
34
|
+
return `array<${typeToString(type.props.element)}>`
|
|
35
|
+
case type instanceof ObjectType: {
|
|
36
|
+
const props = type.props.properties
|
|
37
|
+
const propsStrings = Object.keys(props).map(
|
|
38
|
+
(key) => `${key}: ${typeToString(props[key])}`,
|
|
39
|
+
)
|
|
40
|
+
return `{ ${propsStrings.join(', ')} }`
|
|
41
|
+
}
|
|
42
|
+
case type instanceof TupleType: {
|
|
43
|
+
const elements = type.props.elements
|
|
44
|
+
const elementsStrings = elements.map((el) => typeToString(el))
|
|
45
|
+
const rest = type.props.rest
|
|
46
|
+
? `, ...${typeToString(type.props.rest)}`
|
|
47
|
+
: ''
|
|
48
|
+
return `[${elementsStrings.join(', ')}${rest}]`
|
|
49
|
+
}
|
|
50
|
+
case type instanceof AnyType:
|
|
51
|
+
return 'any'
|
|
52
|
+
case type instanceof CustomType:
|
|
53
|
+
return typeToJsonSchema(type, 'decode').type || 'custom'
|
|
54
|
+
default:
|
|
55
|
+
return 'unknown'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function typeToJsonSchema(
|
|
60
|
+
type: BaseType,
|
|
61
|
+
mode: 'encode' | 'decode',
|
|
62
|
+
options?: Parameters<typeof toJSONSchema>[1],
|
|
63
|
+
): core.JSONSchema.JSONSchema {
|
|
64
|
+
const zodType = { encode: type.encodeZodType, decode: type.decodeZodType }[
|
|
65
|
+
mode
|
|
66
|
+
]
|
|
67
|
+
return toJSONSchema(zodType, options)
|
|
68
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { BaseTypeAny } from './base.ts'
|
|
2
|
+
|
|
3
|
+
export * from './any.ts'
|
|
4
|
+
export * from './array.ts'
|
|
5
|
+
export * from './boolean.ts'
|
|
6
|
+
export * from './custom.ts'
|
|
7
|
+
export * from './date.ts'
|
|
8
|
+
export * from './enum.ts'
|
|
9
|
+
export * from './literal.ts'
|
|
10
|
+
export * from './never.ts'
|
|
11
|
+
export * from './null.ts'
|
|
12
|
+
export * from './number.ts'
|
|
13
|
+
export * from './object.ts'
|
|
14
|
+
export * from './string.ts'
|
|
15
|
+
export * from './tuple.ts'
|
|
16
|
+
export * from './union.ts'
|
|
17
|
+
|
|
18
|
+
export namespace infer {
|
|
19
|
+
export namespace decode {
|
|
20
|
+
export type input<T extends BaseTypeAny> =
|
|
21
|
+
T['decodeZodType']['_zod']['input']
|
|
22
|
+
export type output<T extends BaseTypeAny> =
|
|
23
|
+
T['decodeZodType']['_zod']['output']
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export namespace encode {
|
|
27
|
+
export type input<T extends BaseTypeAny> =
|
|
28
|
+
T['encodeZodType']['_zod']['input']
|
|
29
|
+
export type output<T extends BaseTypeAny> =
|
|
30
|
+
T['encodeZodType']['_zod']['output']
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export namespace decodeRaw {
|
|
34
|
+
export type input<T extends BaseTypeAny> =
|
|
35
|
+
T['decodeRawZodType']['_zod']['input']
|
|
36
|
+
export type output<T extends BaseTypeAny> =
|
|
37
|
+
T['decodeRawZodType']['_zod']['output']
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export namespace encodeRaw {
|
|
41
|
+
export type input<T extends BaseTypeAny> =
|
|
42
|
+
T['encodeRawZodType']['_zod']['input']
|
|
43
|
+
export type output<T extends BaseTypeAny> =
|
|
44
|
+
T['encodeRawZodType']['_zod']['output']
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { core, ZodMiniType } from 'zod/mini'
|
|
2
|
+
|
|
3
|
+
import type { BaseType } from './base.ts'
|
|
4
|
+
|
|
5
|
+
export const PlainType: unique symbol = Symbol('PlainType')
|
|
6
|
+
export type PlainType = typeof PlainType
|
|
7
|
+
|
|
8
|
+
export type ZodPlainType<T extends ZodMiniType<any, any, any>> = T &
|
|
9
|
+
ZodMiniType<
|
|
10
|
+
T['_zod']['output'] & { [PlainType]?: true },
|
|
11
|
+
T['_zod']['input'] & { [PlainType]?: true },
|
|
12
|
+
core.$ZodTypeInternals<
|
|
13
|
+
T['_zod']['output'] & { [PlainType]?: true },
|
|
14
|
+
T['_zod']['input'] & { [PlainType]?: true }
|
|
15
|
+
>
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
export const zodPlainType = <T extends ZodMiniType<any, any, any>>(type: T) =>
|
|
19
|
+
type as ZodPlainType<T>
|
|
20
|
+
|
|
21
|
+
export type AnyCompatibleType<Encoded = any, Decoded = any> = BaseType<
|
|
22
|
+
ZodMiniType<any, Decoded>,
|
|
23
|
+
ZodMiniType<any, Encoded>
|
|
24
|
+
>
|
package/src/types/any.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ZodMiniAny } from 'zod/mini'
|
|
2
|
+
import { any as zodAny } from 'zod/mini'
|
|
3
|
+
|
|
4
|
+
import { BaseType } from './base.ts'
|
|
5
|
+
|
|
6
|
+
export class AnyType extends BaseType<ZodMiniAny> {
|
|
7
|
+
static factory() {
|
|
8
|
+
return new AnyType({ encodeZodType: zodAny() })
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const any = AnyType.factory
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { core, ZodMiniArray } from 'zod/mini'
|
|
2
|
+
import { length, maxLength, minLength, array as zodArray } from 'zod/mini'
|
|
3
|
+
|
|
4
|
+
import type { ZodPlainType } from './_utils.ts'
|
|
5
|
+
import { BaseType } from './base.ts'
|
|
6
|
+
|
|
7
|
+
type Check = core.CheckFn<any[]> | core.$ZodCheck<any[]>
|
|
8
|
+
|
|
9
|
+
export class ArrayType<T extends BaseType = BaseType> extends BaseType<
|
|
10
|
+
ZodMiniArray<T['encodeZodType']>,
|
|
11
|
+
ZodMiniArray<T['decodeZodType']>,
|
|
12
|
+
{ element: T },
|
|
13
|
+
ZodPlainType<ZodMiniArray<T['encodeZodType']>>,
|
|
14
|
+
ZodPlainType<ZodMiniArray<T['encodeZodType']>>
|
|
15
|
+
> {
|
|
16
|
+
static factory<T extends BaseType>(element: T, ...checks: Check[]) {
|
|
17
|
+
return new ArrayType<T>({
|
|
18
|
+
encodeZodType: zodArray(element.encodeZodType).check(...checks),
|
|
19
|
+
decodeZodType: zodArray(element.decodeZodType).check(...checks),
|
|
20
|
+
params: { checks },
|
|
21
|
+
props: { element },
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
min(value: number) {
|
|
26
|
+
const check = minLength(value)
|
|
27
|
+
return ArrayType.factory<T>(
|
|
28
|
+
this.props.element,
|
|
29
|
+
...this.params.checks,
|
|
30
|
+
check,
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
max(value: number) {
|
|
35
|
+
const check = maxLength(value)
|
|
36
|
+
return ArrayType.factory<T>(
|
|
37
|
+
this.props.element,
|
|
38
|
+
...this.params.checks,
|
|
39
|
+
check,
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
length(value: number) {
|
|
44
|
+
const check = length(value)
|
|
45
|
+
return ArrayType.factory<T>(
|
|
46
|
+
this.props.element,
|
|
47
|
+
...this.params.checks,
|
|
48
|
+
check,
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const array = ArrayType.factory
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ZodMiniAny,
|
|
3
|
+
ZodMiniArray,
|
|
4
|
+
ZodMiniBoolean,
|
|
5
|
+
ZodMiniDefault,
|
|
6
|
+
ZodMiniEnum,
|
|
7
|
+
ZodMiniIntersection,
|
|
8
|
+
ZodMiniLiteral,
|
|
9
|
+
ZodMiniNever,
|
|
10
|
+
ZodMiniNullable,
|
|
11
|
+
ZodMiniNumber,
|
|
12
|
+
ZodMiniObject,
|
|
13
|
+
ZodMiniOptional,
|
|
14
|
+
ZodMiniRecord,
|
|
15
|
+
ZodMiniString,
|
|
16
|
+
ZodMiniType,
|
|
17
|
+
ZodMiniUnion,
|
|
18
|
+
} from 'zod/mini'
|
|
19
|
+
import { _default, core, nullable, optional, registry } from 'zod/mini'
|
|
20
|
+
|
|
21
|
+
export type PrimitiveValueType = string | number | boolean | null
|
|
22
|
+
|
|
23
|
+
export type PrimitiveZodType =
|
|
24
|
+
| ZodMiniNever
|
|
25
|
+
| ZodMiniDefault
|
|
26
|
+
| ZodMiniNullable
|
|
27
|
+
| ZodMiniOptional
|
|
28
|
+
| ZodMiniString
|
|
29
|
+
| ZodMiniObject
|
|
30
|
+
| ZodMiniAny
|
|
31
|
+
| ZodMiniArray
|
|
32
|
+
| ZodMiniBoolean
|
|
33
|
+
| ZodMiniNumber
|
|
34
|
+
| ZodMiniEnum<any>
|
|
35
|
+
| ZodMiniLiteral<PrimitiveValueType>
|
|
36
|
+
| ZodMiniUnion
|
|
37
|
+
| ZodMiniIntersection
|
|
38
|
+
| ZodMiniRecord
|
|
39
|
+
|
|
40
|
+
export type SimpleZodType = ZodMiniType
|
|
41
|
+
|
|
42
|
+
export type ZodType = SimpleZodType | ZodMiniType
|
|
43
|
+
|
|
44
|
+
export type TypeProps = Record<string, any>
|
|
45
|
+
|
|
46
|
+
export type TypeMetadata<T = any> = {
|
|
47
|
+
id?: string
|
|
48
|
+
description?: string
|
|
49
|
+
examples?: T[]
|
|
50
|
+
title?: string
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type TypeParams = {
|
|
54
|
+
encode?: (value: any) => any
|
|
55
|
+
metadata?: TypeMetadata
|
|
56
|
+
checks: Array<core.CheckFn<any> | core.$ZodCheck<any>>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type DefaultTypeParams = {
|
|
60
|
+
encode?: TypeParams['encode']
|
|
61
|
+
metadata?: TypeMetadata
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type BaseTypeAny<
|
|
65
|
+
EncodedZodType extends SimpleZodType = SimpleZodType,
|
|
66
|
+
DecodedZodType extends ZodType = ZodMiniType,
|
|
67
|
+
> = BaseType<EncodedZodType, DecodedZodType, TypeProps>
|
|
68
|
+
|
|
69
|
+
export const typesRegistry = registry<TypeMetadata>()
|
|
70
|
+
|
|
71
|
+
export const NeemataTypeError = core.$ZodError
|
|
72
|
+
export type NeemataTypeError = core.$ZodError
|
|
73
|
+
|
|
74
|
+
export abstract class BaseType<
|
|
75
|
+
EncodeZodType extends SimpleZodType = SimpleZodType,
|
|
76
|
+
DecodeZodType extends ZodType = EncodeZodType,
|
|
77
|
+
Props extends TypeProps = TypeProps,
|
|
78
|
+
RawEncodeZodType extends SimpleZodType = EncodeZodType,
|
|
79
|
+
RawDecodeZodType extends ZodType = DecodeZodType,
|
|
80
|
+
> {
|
|
81
|
+
readonly encodeZodType: EncodeZodType
|
|
82
|
+
readonly decodeZodType: DecodeZodType
|
|
83
|
+
readonly encodeRawZodType!: RawEncodeZodType
|
|
84
|
+
readonly decodeRawZodType!: RawDecodeZodType
|
|
85
|
+
readonly props: Props
|
|
86
|
+
readonly params: TypeParams
|
|
87
|
+
|
|
88
|
+
constructor({
|
|
89
|
+
encodeZodType,
|
|
90
|
+
decodeZodType = encodeZodType as unknown as DecodeZodType,
|
|
91
|
+
props = {} as Props,
|
|
92
|
+
params = {} as Partial<TypeParams>,
|
|
93
|
+
}: {
|
|
94
|
+
encodeZodType: EncodeZodType
|
|
95
|
+
decodeZodType?: DecodeZodType
|
|
96
|
+
props?: Props
|
|
97
|
+
params?: Partial<TypeParams>
|
|
98
|
+
}) {
|
|
99
|
+
this.encodeZodType = encodeZodType
|
|
100
|
+
this.decodeZodType = decodeZodType
|
|
101
|
+
|
|
102
|
+
this.props = props
|
|
103
|
+
this.params = Object.assign({ checks: [] }, params)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
optional(): OptionalType<this> {
|
|
107
|
+
return OptionalType.factory(this)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
nullable(): NullableType<this> {
|
|
111
|
+
return NullableType.factory(this)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
nullish() {
|
|
115
|
+
return this.nullable().optional()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
default(value: this['encodeZodType']['_zod']['input']): DefaultType<this> {
|
|
119
|
+
return DefaultType.factory(this, value)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
title(title: string): this {
|
|
123
|
+
return this.meta({ title })
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
description(description: string): this {
|
|
127
|
+
return this.meta({ description })
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
examples(...examples: this['encodeZodType']['_zod']['input'][]): this {
|
|
131
|
+
return this.meta({
|
|
132
|
+
examples: this.params.encode
|
|
133
|
+
? examples.map(this.params.encode)
|
|
134
|
+
: examples,
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
meta(newMetadata: TypeMetadata): this {
|
|
139
|
+
const metadata = typesRegistry.get(this.encodeZodType) ?? {}
|
|
140
|
+
Object.assign(metadata, newMetadata)
|
|
141
|
+
typesRegistry.add(this.encodeZodType, metadata)
|
|
142
|
+
return this
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
encode(
|
|
146
|
+
data: this['encodeZodType']['_zod']['input'],
|
|
147
|
+
context: core.ParseContext<core.$ZodIssue> = {},
|
|
148
|
+
): this['encodeZodType']['_zod']['output'] {
|
|
149
|
+
return this.encodeZodType.parse(data, { reportInput: true, ...context })
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
decode(
|
|
153
|
+
data: this['decodeZodType']['_zod']['input'],
|
|
154
|
+
context: core.ParseContext<core.$ZodIssue> = {},
|
|
155
|
+
): this['decodeZodType']['_zod']['output'] {
|
|
156
|
+
return this.decodeZodType.parse(data, { reportInput: true, ...context })
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class OptionalType<
|
|
161
|
+
Type extends BaseTypeAny = BaseTypeAny,
|
|
162
|
+
> extends BaseType<
|
|
163
|
+
ZodMiniOptional<Type['encodeZodType']>,
|
|
164
|
+
ZodMiniOptional<Type['decodeZodType']>,
|
|
165
|
+
{ inner: Type }
|
|
166
|
+
> {
|
|
167
|
+
static factory<T extends BaseTypeAny>(type: T) {
|
|
168
|
+
return new OptionalType<T>({
|
|
169
|
+
encodeZodType: optional(type.encodeZodType),
|
|
170
|
+
decodeZodType: optional(type.decodeZodType),
|
|
171
|
+
props: { inner: type },
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export class NullableType<
|
|
177
|
+
Type extends BaseTypeAny<any> = BaseTypeAny<any>,
|
|
178
|
+
> extends BaseType<
|
|
179
|
+
ZodMiniNullable<Type['encodeZodType']>,
|
|
180
|
+
ZodMiniNullable<Type['decodeZodType']>,
|
|
181
|
+
{ inner: Type }
|
|
182
|
+
> {
|
|
183
|
+
static factory<T extends BaseTypeAny<any>>(type: T) {
|
|
184
|
+
return new NullableType<T>({
|
|
185
|
+
encodeZodType: nullable(type.encodeZodType),
|
|
186
|
+
decodeZodType: nullable(type.decodeZodType),
|
|
187
|
+
props: { inner: type },
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export class DefaultType<
|
|
193
|
+
Type extends BaseTypeAny = BaseTypeAny,
|
|
194
|
+
> extends BaseType<
|
|
195
|
+
ZodMiniDefault<Type['encodeZodType']>,
|
|
196
|
+
ZodMiniDefault<Type['decodeZodType']>,
|
|
197
|
+
{ inner: Type }
|
|
198
|
+
> {
|
|
199
|
+
static factory<T extends BaseTypeAny<any>>(type: T, defaultValue: any) {
|
|
200
|
+
return new DefaultType<T>({
|
|
201
|
+
encodeZodType: _default(
|
|
202
|
+
type.encodeZodType,
|
|
203
|
+
type.params.encode?.(defaultValue) ?? defaultValue,
|
|
204
|
+
),
|
|
205
|
+
decodeZodType: _default(type.decodeZodType, defaultValue),
|
|
206
|
+
props: { inner: type },
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
}
|