@nmtjs/type 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/custom.js.map +1 -1
- package/package.json +3 -3
- package/src/types/custom.ts +23 -6
package/dist/types/custom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/custom.ts"],"sourcesContent":["import { type
|
|
1
|
+
{"version":3,"sources":["../../../src/types/custom.ts"],"sourcesContent":["import { type TTransform, type TUnsafe, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class CustomType<\n T,\n S = T,\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TUnsafe<S>, T>, N, O> {\n constructor(\n protected readonly decode: (value: any) => T,\n protected readonly encode: (value: T) => any,\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(\n Type.Optional(\n Type.Transform(Type.Any() as unknown as TUnsafe<S>)\n .Decode(decode)\n .Encode(encode),\n ),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new CustomType<T, S, (typeof args)[0], (typeof args)[1]>(\n this.decode,\n this.encode,\n ...args,\n )\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new CustomType<T, S, (typeof args)[0], (typeof args)[1]>(\n this.decode,\n this.encode,\n ...args,\n )\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new CustomType<T, S, (typeof args)[0], (typeof args)[1]>(\n this.decode,\n this.encode,\n ...args,\n )\n }\n}\n"],"names":["Type","BaseType","CustomType","constructor","decode","encode","nullable","optional","Optional","Transform","Any","Decode","Encode","_","args","_nullable","_optional","nullish","_nullish"],"mappings":"AAAA,SAAwCA,IAAI,QAAQ,oBAAmB;AACvE,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAKHD;;;IACRE,YACE,AAAmBC,MAAyB,EAC5C,AAAmBC,MAAyB,EAC5CC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CACHP,KAAKQ,QAAQ,CACXR,KAAKS,SAAS,CAACT,KAAKU,GAAG,IACpBC,MAAM,CAACP,QACPQ,MAAM,CAACP,UAEZC,UACAC;aAZiBH,SAAAA;aACAC,SAAAA;IAarB;IAEAC,WAAW;QACT,MAAM,CAACO,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACC,SAAS;QACnC,OAAO,IAAIb,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACRS;IAEP;IAEAP,WAAW;QACT,MAAM,CAACM,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACE,SAAS;QACnC,OAAO,IAAId,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACRS;IAEP;IAEAG,UAAU;QACR,MAAM,CAACJ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACI,QAAQ;QAClC,OAAO,IAAIhB,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACRS;IAEP;AACF"}
|
package/package.json
CHANGED
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@sinclair/typebox": "^0.33.7",
|
|
23
23
|
"temporal-polyfill": "^0.2.5",
|
|
24
|
-
"@nmtjs/common": "0.
|
|
24
|
+
"@nmtjs/common": "0.2.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@sinclair/typebox": "^0.33.7",
|
|
28
28
|
"temporal-polyfill": "^0.2.5",
|
|
29
|
-
"@nmtjs/common": "0.
|
|
29
|
+
"@nmtjs/common": "0.2.1"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"src",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"LICENSE.md",
|
|
36
36
|
"README.md"
|
|
37
37
|
],
|
|
38
|
-
"version": "0.
|
|
38
|
+
"version": "0.2.1",
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "neemata-build -p neutral --root=./src './**/*.ts'",
|
|
41
41
|
"type-check": "tsc --noEmit"
|
package/src/types/custom.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type TTransform, type TUnsafe, Type } from '@sinclair/typebox'
|
|
2
2
|
import { BaseType } from './base.ts'
|
|
3
3
|
|
|
4
4
|
export class CustomType<
|
|
5
5
|
T,
|
|
6
|
+
S = T,
|
|
6
7
|
N extends boolean = false,
|
|
7
8
|
O extends boolean = false,
|
|
8
|
-
> extends BaseType<TTransform<
|
|
9
|
+
> extends BaseType<TTransform<TUnsafe<S>, T>, N, O> {
|
|
9
10
|
constructor(
|
|
10
11
|
protected readonly decode: (value: any) => T,
|
|
11
12
|
protected readonly encode: (value: T) => any,
|
|
@@ -13,7 +14,11 @@ export class CustomType<
|
|
|
13
14
|
optional: O = false as O,
|
|
14
15
|
) {
|
|
15
16
|
super(
|
|
16
|
-
Type.Optional(
|
|
17
|
+
Type.Optional(
|
|
18
|
+
Type.Transform(Type.Any() as unknown as TUnsafe<S>)
|
|
19
|
+
.Decode(decode)
|
|
20
|
+
.Encode(encode),
|
|
21
|
+
),
|
|
17
22
|
nullable,
|
|
18
23
|
optional,
|
|
19
24
|
)
|
|
@@ -21,16 +26,28 @@ export class CustomType<
|
|
|
21
26
|
|
|
22
27
|
nullable() {
|
|
23
28
|
const [_, ...args] = this._nullable()
|
|
24
|
-
return new CustomType
|
|
29
|
+
return new CustomType<T, S, (typeof args)[0], (typeof args)[1]>(
|
|
30
|
+
this.decode,
|
|
31
|
+
this.encode,
|
|
32
|
+
...args,
|
|
33
|
+
)
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
optional() {
|
|
28
37
|
const [_, ...args] = this._optional()
|
|
29
|
-
return new CustomType
|
|
38
|
+
return new CustomType<T, S, (typeof args)[0], (typeof args)[1]>(
|
|
39
|
+
this.decode,
|
|
40
|
+
this.encode,
|
|
41
|
+
...args,
|
|
42
|
+
)
|
|
30
43
|
}
|
|
31
44
|
|
|
32
45
|
nullish() {
|
|
33
46
|
const [_, ...args] = this._nullish()
|
|
34
|
-
return new CustomType
|
|
47
|
+
return new CustomType<T, S, (typeof args)[0], (typeof args)[1]>(
|
|
48
|
+
this.decode,
|
|
49
|
+
this.encode,
|
|
50
|
+
...args,
|
|
51
|
+
)
|
|
35
52
|
}
|
|
36
53
|
}
|