@nmtjs/type 0.1.0 → 0.2.0

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/custom.ts"],"sourcesContent":["import { type TAny, type TTransform, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class CustomType<\n T,\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TAny, 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(Type.Transform(Type.Any()).Decode(decode).Encode(encode)),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new CustomType(this.decode, this.encode, ...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new CustomType(this.decode, this.encode, ...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new CustomType(this.decode, this.encode, ...args)\n }\n}\n"],"names":["Type","BaseType","CustomType","constructor","decode","encode","nullable","optional","Optional","Transform","Any","Decode","Encode","_","args","_nullable","_optional","nullish","_nullish"],"mappings":"AAAA,SAAqCA,IAAI,QAAQ,oBAAmB;AACpE,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAIHD;;;IACRE,YACE,AAAmBC,MAAyB,EAC5C,AAAmBC,MAAyB,EAC5CC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CACHP,KAAKQ,QAAQ,CAACR,KAAKS,SAAS,CAACT,KAAKU,GAAG,IAAIC,MAAM,CAACP,QAAQQ,MAAM,CAACP,UAC/DC,UACAC;aARiBH,SAAAA;aACAC,SAAAA;IASrB;IAEAC,WAAW;QACT,MAAM,CAACO,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACC,SAAS;QACnC,OAAO,IAAIb,WAAW,IAAI,CAACE,MAAM,EAAE,IAAI,CAACC,MAAM,KAAKS;IACrD;IAEAP,WAAW;QACT,MAAM,CAACM,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACE,SAAS;QACnC,OAAO,IAAId,WAAW,IAAI,CAACE,MAAM,EAAE,IAAI,CAACC,MAAM,KAAKS;IACrD;IAEAG,UAAU;QACR,MAAM,CAACJ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACI,QAAQ;QAClC,OAAO,IAAIhB,WAAW,IAAI,CAACE,MAAM,EAAE,IAAI,CAACC,MAAM,KAAKS;IACrD;AACF"}
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"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/never.ts"],"sourcesContent":["import { type TNever, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NeverType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TNever, N, O> {\n constructor(\n schema = Type.Never(),\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(schema, nullable, optional)\n }\n\n // @ts-expect-error\n nullable() {\n throw new Error('NeverType cannot be nullable')\n }\n\n // @ts-expect-error\n optional() {\n throw new Error('NeverType cannot be optional')\n }\n\n // @ts-expect-error\n nullish() {\n throw new Error('NeverType cannot be nullish')\n }\n}\n"],"names":["Type","BaseType","NeverType","constructor","schema","Never","nullable","optional","Error","nullish"],"mappings":"AAAA,SAAsBA,IAAI,QAAQ,oBAAmB;AACrD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,kBAGHD;IACRE,YACEC,SAASJ,KAAKK,KAAK,EAAE,EACrBC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACH,QAAQE,UAAUC;IAC1B;IAGAD,WAAW;QACT,MAAM,IAAIE,MAAM;IAClB;IAGAD,WAAW;QACT,MAAM,IAAIC,MAAM;IAClB;IAGAC,UAAU;QACR,MAAM,IAAID,MAAM;IAClB;AACF"}
1
+ {"version":3,"sources":["../../../src/types/never.ts"],"sourcesContent":["import { type TNever, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NeverType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TNever, N, O> {\n constructor(\n schema = Type.Never(),\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(schema, nullable, optional)\n }\n\n nullable(): NeverType<true, O> {\n throw new Error('NeverType cannot be nullable')\n }\n\n optional(): NeverType<N, true> {\n throw new Error('NeverType cannot be optional')\n }\n\n nullish(): NeverType<true, true> {\n throw new Error('NeverType cannot be nullish')\n }\n}\n"],"names":["Type","BaseType","NeverType","constructor","schema","Never","nullable","optional","Error","nullish"],"mappings":"AAAA,SAAsBA,IAAI,QAAQ,oBAAmB;AACrD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,kBAGHD;IACRE,YACEC,SAASJ,KAAKK,KAAK,EAAE,EACrBC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACH,QAAQE,UAAUC;IAC1B;IAEAD,WAA+B;QAC7B,MAAM,IAAIE,MAAM;IAClB;IAEAD,WAA+B;QAC7B,MAAM,IAAIC,MAAM;IAClB;IAEAC,UAAiC;QAC/B,MAAM,IAAID,MAAM;IAClB;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.1.0"
24
+ "@nmtjs/common": "0.2.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@sinclair/typebox": "^0.33.7",
28
28
  "temporal-polyfill": "^0.2.5",
29
- "@nmtjs/common": "0.1.0"
29
+ "@nmtjs/common": "0.2.0"
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.1.0",
38
+ "version": "0.2.0",
39
39
  "scripts": {
40
40
  "build": "neemata-build -p neutral --root=./src './**/*.ts'",
41
41
  "type-check": "tsc --noEmit"
@@ -1,11 +1,12 @@
1
- import { type TAny, type TTransform, Type } from '@sinclair/typebox'
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<TAny, T>, N, O> {
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(Type.Transform(Type.Any()).Decode(decode).Encode(encode)),
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(this.decode, this.encode, ...args)
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(this.decode, this.encode, ...args)
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(this.decode, this.encode, ...args)
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
  }
@@ -13,18 +13,15 @@ export class NeverType<
13
13
  super(schema, nullable, optional)
14
14
  }
15
15
 
16
- // @ts-expect-error
17
- nullable() {
16
+ nullable(): NeverType<true, O> {
18
17
  throw new Error('NeverType cannot be nullable')
19
18
  }
20
19
 
21
- // @ts-expect-error
22
- optional() {
20
+ optional(): NeverType<N, true> {
23
21
  throw new Error('NeverType cannot be optional')
24
22
  }
25
23
 
26
- // @ts-expect-error
27
- nullish() {
24
+ nullish(): NeverType<true, true> {
28
25
  throw new Error('NeverType cannot be nullish')
29
26
  }
30
27
  }