@nmtjs/type 0.7.6 → 0.7.7
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/types/tuple.js.map +1 -1
- package/dist/types/union.js +8 -4
- package/dist/types/union.js.map +1 -1
- package/package.json +2 -2
- package/src/types/tuple.ts +5 -25
- package/src/types/union.ts +27 -12
package/dist/types/tuple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AACA,SAAS,aAAgC,WAAW;AACpD,SAAS,gBAAgB,WAAW;AAEpC,OAAO,MAAM,kBAMH,SAQR;CACA,OAAO,QAGLA,UAAaC,OAAU,MAAW;EAClC,MAAM,UAAU,SAAS,IAAI,CAAC,OAAO,GAAG,eAAe;EACvD,MAAM,UAAU,SAAS,IAAI,CAAC,OAAO,GAAG,eAAe;AACvD,SAAO,IAAI,UAAgB;GAEzB,gBAAgB,MAAM,SAAS,MAAM,eAAe;GAEpD,gBAAgB,MAAM,SAAS,MAAM,eAAe;GACpD,OAAO;IAAE;IAAU;GAAM;EAC1B;CACF;AACF","names":["elements: T","rest: R"],"sources":["src/types/tuple.ts"],"sourcesContent":["import type { ArrayMap } from '@nmtjs/common'\nimport { tuple, type ZodMiniTuple } from '@zod/mini'\nimport { BaseType } from './base.ts'\n\nexport class TupleType<\n T extends readonly [BaseType, ...BaseType[]] = readonly [\n BaseType,\n ...BaseType[],\n ],\n R extends BaseType | null = BaseType | null,\n> extends BaseType<\n R extends BaseType\n ? ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, R['encodedZodType']>\n : ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, null>,\n R extends BaseType\n ? ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, R['decodedZodType']>\n : ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, null>,\n { elements: T; rest?: R }\n> {\n static factory<\n T extends readonly [BaseType, ...BaseType[]],\n R extends BaseType | null = null,\n >(elements: T, rest: R = null as R) {\n const encoded = elements.map((el) => el.encodedZodType)\n const decoded = elements.map((el) => el.decodedZodType)\n return new TupleType<T, R>({\n // @ts-expect-error\n encodedZodType: tuple(encoded, rest?.encodedZodType),\n // @ts-expect-error\n decodedZodType: tuple(decoded, rest?.decodedZodType),\n props: { elements, rest },\n })\n }\n}\n"],"version":3}
|
package/dist/types/union.js
CHANGED
|
@@ -2,9 +2,11 @@ import { discriminatedUnion, intersection, union } from "@zod/mini";
|
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class UnionType extends BaseType {
|
|
4
4
|
static factory(...options) {
|
|
5
|
+
const encoded = options.map((t) => t.encodedZodType);
|
|
6
|
+
const decoded = options.map((t) => t.decodedZodType);
|
|
5
7
|
return new UnionType({
|
|
6
|
-
encodedZodType: union(
|
|
7
|
-
decodedZodType: union(
|
|
8
|
+
encodedZodType: union(encoded),
|
|
9
|
+
decodedZodType: union(decoded),
|
|
8
10
|
props: { options }
|
|
9
11
|
});
|
|
10
12
|
}
|
|
@@ -21,9 +23,11 @@ export class IntersactionType extends BaseType {
|
|
|
21
23
|
}
|
|
22
24
|
export class DiscriminatedUnionType extends BaseType {
|
|
23
25
|
static factory(key, ...options) {
|
|
26
|
+
const encoded = options.map((t) => t.encodedZodType);
|
|
27
|
+
const decoded = options.map((t) => t.decodedZodType);
|
|
24
28
|
return new DiscriminatedUnionType({
|
|
25
|
-
encodedZodType: discriminatedUnion(
|
|
26
|
-
decodedZodType: discriminatedUnion(
|
|
29
|
+
encodedZodType: discriminatedUnion(encoded),
|
|
30
|
+
decodedZodType: discriminatedUnion(decoded),
|
|
27
31
|
props: {
|
|
28
32
|
key,
|
|
29
33
|
options
|
package/dist/types/union.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AACA,SAEE,oBACA,cACA,aAIK,WAAW;AAClB,SAAS,gBAAkC,WAAW;AAItD,OAAO,MAAM,kBAKH,SAIR;CACA,OAAO,QAKL,GAAG,SAAY;EACf,MAAM,UAAU,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe;EAIpD,MAAM,UAAU,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe;AAIpD,SAAO,IAAI,UAAa;GACtB,gBAAgB,MAAM,QAAQ;GAC9B,gBAAgB,MAAM,QAAQ;GAC9B,OAAO,EAAE,QAAS;EACnB;CACF;AACF;AAED,OAAO,MAAM,yBAEH,SAIR;CACA,OAAO,QAEL,GAAG,SAAY;EACf,MAAM,CAAC,OAAO,OAAO,GAAG;AACxB,SAAO,IAAI,iBAAoB;GAC7B,gBAAgB,aAAa,MAAM,gBAAgB,OAAO,eAAe;GACzE,gBAAgB,aAAa,MAAM,gBAAgB,OAAO,eAAe;GACzE,OAAO,EAAE,QAAS;EACnB;CACF;AACF;AAYD,OAAO,MAAM,+BAIH,SAOR;CACA,OAAO,QAILA,KAAQ,GAAG,SAAY;EACvB,MAAM,UAAU,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe;EAIpD,MAAM,UAAU,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe;AAIpD,SAAO,IAAI,uBAA6B;GAEtC,gBAAgB,mBAAmB,QAAQ;GAE3C,gBAAgB,mBAAmB,QAAQ;GAC3C,OAAO;IAAE;IAAK;GAAS;EACxB;CACF;AACF","names":["key: K"],"sources":["src/types/union.ts"],"sourcesContent":["import type { ArrayMap } from '@nmtjs/common'\nimport {\n type core,\n discriminatedUnion,\n intersection,\n union,\n type ZodMiniDiscriminatedUnion,\n type ZodMiniIntersection,\n type ZodMiniUnion,\n} from '@zod/mini'\nimport { BaseType, type BaseTypeAny } from './base.ts'\nimport type { LiteralType } from './literal.ts'\nimport type { ObjectType, ObjectTypeProps } from './object.ts'\n\nexport class UnionType<\n T extends readonly [BaseType, ...BaseType[]] = readonly [\n BaseType,\n ...BaseType[],\n ],\n> extends BaseType<\n ZodMiniUnion<ArrayMap<T, 'encodedZodType'>>,\n ZodMiniUnion<ArrayMap<T, 'decodedZodType'>>,\n { options: T }\n> {\n static factory<\n T extends readonly [BaseType, ...BaseType[]] = readonly [\n BaseType,\n ...BaseType[],\n ],\n >(...options: T) {\n const encoded = options.map((t) => t.encodedZodType) as ArrayMap<\n T,\n 'encodedZodType'\n >\n const decoded = options.map((t) => t.decodedZodType) as ArrayMap<\n T,\n 'decodedZodType'\n >\n return new UnionType<T>({\n encodedZodType: union(encoded),\n decodedZodType: union(decoded),\n props: { options },\n })\n }\n}\n\nexport class IntersactionType<\n T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],\n> extends BaseType<\n ZodMiniIntersection<T[0]['encodedZodType'], T[1]['encodedZodType']>,\n ZodMiniIntersection<T[0]['decodedZodType'], T[1]['decodedZodType']>,\n { options: T }\n> {\n static factory<\n T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],\n >(...options: T) {\n const [first, second] = options\n return new IntersactionType<T>({\n encodedZodType: intersection(first.encodedZodType, second.encodedZodType),\n decodedZodType: intersection(first.decodedZodType, second.decodedZodType),\n props: { options },\n })\n }\n}\n\nexport type DiscriminatedUnionProperties<K extends string = string> = {\n [OK in K]: LiteralType<string>\n} & {\n [OK in string]: any\n}\n\nexport type DiscriminatedUnionOptionType<K extends string> = ObjectType<\n ObjectTypeProps & { [_ in K]: BaseTypeAny }\n>\n\nexport class DiscriminatedUnionType<\n K extends string = string,\n T extends\n readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],\n> extends BaseType<\n ZodMiniDiscriminatedUnion<ArrayMap<T, 'encodedZodType'>>,\n ZodMiniDiscriminatedUnion<ArrayMap<T, 'decodedZodType'>>,\n {\n key: K\n options: T\n }\n> {\n static factory<\n K extends string = string,\n T extends\n readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],\n >(key: K, ...options: T) {\n const encoded = options.map((t) => t.encodedZodType) as ArrayMap<\n T,\n 'encodedZodType'\n >\n const decoded = options.map((t) => t.decodedZodType) as ArrayMap<\n T,\n 'decodedZodType'\n >\n return new DiscriminatedUnionType<K, T>({\n // @ts-expect-error\n encodedZodType: discriminatedUnion(encoded),\n // @ts-expect-error\n decodedZodType: discriminatedUnion(decoded),\n props: { key, options },\n })\n }\n}\n"],"version":3}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@zod/mini": "4.0.0-beta.20250503T014749",
|
|
16
16
|
"temporal-polyfill": "^0.3.0",
|
|
17
|
-
"@nmtjs/common": "0.7.
|
|
17
|
+
"@nmtjs/common": "0.7.7"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"src",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"LICENSE.md",
|
|
23
23
|
"README.md"
|
|
24
24
|
],
|
|
25
|
-
"version": "0.7.
|
|
25
|
+
"version": "0.7.7",
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "neemata-build --root=./src './**/*.ts'",
|
|
28
28
|
"type-check": "tsc --noEmit"
|
package/src/types/tuple.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ArrayMap } from '@nmtjs/common'
|
|
1
2
|
import { tuple, type ZodMiniTuple } from '@zod/mini'
|
|
2
3
|
import { BaseType } from './base.ts'
|
|
3
4
|
|
|
@@ -9,31 +10,11 @@ export class TupleType<
|
|
|
9
10
|
R extends BaseType | null = BaseType | null,
|
|
10
11
|
> extends BaseType<
|
|
11
12
|
R extends BaseType
|
|
12
|
-
? ZodMiniTuple<
|
|
13
|
-
|
|
14
|
-
[K in keyof T]: T[K]['encodedZodType']
|
|
15
|
-
},
|
|
16
|
-
R['encodedZodType']
|
|
17
|
-
>
|
|
18
|
-
: ZodMiniTuple<
|
|
19
|
-
{
|
|
20
|
-
[K in keyof T]: T[K]['encodedZodType']
|
|
21
|
-
},
|
|
22
|
-
null
|
|
23
|
-
>,
|
|
13
|
+
? ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, R['encodedZodType']>
|
|
14
|
+
: ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, null>,
|
|
24
15
|
R extends BaseType
|
|
25
|
-
? ZodMiniTuple<
|
|
26
|
-
|
|
27
|
-
[K in keyof T]: T[K]['decodedZodType']
|
|
28
|
-
},
|
|
29
|
-
R['decodedZodType']
|
|
30
|
-
>
|
|
31
|
-
: ZodMiniTuple<
|
|
32
|
-
{
|
|
33
|
-
[K in keyof T]: T[K]['decodedZodType']
|
|
34
|
-
},
|
|
35
|
-
null
|
|
36
|
-
>,
|
|
16
|
+
? ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, R['decodedZodType']>
|
|
17
|
+
: ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, null>,
|
|
37
18
|
{ elements: T; rest?: R }
|
|
38
19
|
> {
|
|
39
20
|
static factory<
|
|
@@ -42,7 +23,6 @@ export class TupleType<
|
|
|
42
23
|
>(elements: T, rest: R = null as R) {
|
|
43
24
|
const encoded = elements.map((el) => el.encodedZodType)
|
|
44
25
|
const decoded = elements.map((el) => el.decodedZodType)
|
|
45
|
-
|
|
46
26
|
return new TupleType<T, R>({
|
|
47
27
|
// @ts-expect-error
|
|
48
28
|
encodedZodType: tuple(encoded, rest?.encodedZodType),
|
package/src/types/union.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ArrayMap } from '@nmtjs/common'
|
|
1
2
|
import {
|
|
2
3
|
type core,
|
|
3
4
|
discriminatedUnion,
|
|
@@ -17,8 +18,8 @@ export class UnionType<
|
|
|
17
18
|
...BaseType[],
|
|
18
19
|
],
|
|
19
20
|
> extends BaseType<
|
|
20
|
-
ZodMiniUnion<
|
|
21
|
-
ZodMiniUnion<
|
|
21
|
+
ZodMiniUnion<ArrayMap<T, 'encodedZodType'>>,
|
|
22
|
+
ZodMiniUnion<ArrayMap<T, 'decodedZodType'>>,
|
|
22
23
|
{ options: T }
|
|
23
24
|
> {
|
|
24
25
|
static factory<
|
|
@@ -27,9 +28,17 @@ export class UnionType<
|
|
|
27
28
|
...BaseType[],
|
|
28
29
|
],
|
|
29
30
|
>(...options: T) {
|
|
31
|
+
const encoded = options.map((t) => t.encodedZodType) as ArrayMap<
|
|
32
|
+
T,
|
|
33
|
+
'encodedZodType'
|
|
34
|
+
>
|
|
35
|
+
const decoded = options.map((t) => t.decodedZodType) as ArrayMap<
|
|
36
|
+
T,
|
|
37
|
+
'decodedZodType'
|
|
38
|
+
>
|
|
30
39
|
return new UnionType<T>({
|
|
31
|
-
encodedZodType: union(
|
|
32
|
-
decodedZodType: union(
|
|
40
|
+
encodedZodType: union(encoded),
|
|
41
|
+
decodedZodType: union(decoded),
|
|
33
42
|
props: { options },
|
|
34
43
|
})
|
|
35
44
|
}
|
|
@@ -69,8 +78,8 @@ export class DiscriminatedUnionType<
|
|
|
69
78
|
T extends
|
|
70
79
|
readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],
|
|
71
80
|
> extends BaseType<
|
|
72
|
-
ZodMiniDiscriminatedUnion<T
|
|
73
|
-
ZodMiniDiscriminatedUnion<T
|
|
81
|
+
ZodMiniDiscriminatedUnion<ArrayMap<T, 'encodedZodType'>>,
|
|
82
|
+
ZodMiniDiscriminatedUnion<ArrayMap<T, 'decodedZodType'>>,
|
|
74
83
|
{
|
|
75
84
|
key: K
|
|
76
85
|
options: T
|
|
@@ -81,13 +90,19 @@ export class DiscriminatedUnionType<
|
|
|
81
90
|
T extends
|
|
82
91
|
readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],
|
|
83
92
|
>(key: K, ...options: T) {
|
|
93
|
+
const encoded = options.map((t) => t.encodedZodType) as ArrayMap<
|
|
94
|
+
T,
|
|
95
|
+
'encodedZodType'
|
|
96
|
+
>
|
|
97
|
+
const decoded = options.map((t) => t.decodedZodType) as ArrayMap<
|
|
98
|
+
T,
|
|
99
|
+
'decodedZodType'
|
|
100
|
+
>
|
|
84
101
|
return new DiscriminatedUnionType<K, T>({
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
decodedZodType: discriminatedUnion(
|
|
89
|
-
options.map((t) => t.decodedZodType) as any,
|
|
90
|
-
),
|
|
102
|
+
// @ts-expect-error
|
|
103
|
+
encodedZodType: discriminatedUnion(encoded),
|
|
104
|
+
// @ts-expect-error
|
|
105
|
+
decodedZodType: discriminatedUnion(decoded),
|
|
91
106
|
props: { key, options },
|
|
92
107
|
})
|
|
93
108
|
}
|