@nmtjs/contract 0.0.1 → 0.0.2

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/schemas/native-enum.ts"],"sourcesContent":["import {\n Kind,\n type SchemaOptions,\n type TSchema,\n TypeRegistry,\n} from '@sinclair/typebox/type'\n\nexport const NativeEnumKind = 'NativeEnum'\n\n// -------------------------------------------------------------------------------------\n// TNativeEnum\n// -------------------------------------------------------------------------------------\nexport interface TNativeEnum<T extends Record<string, string>> extends TSchema {\n [Kind]: typeof NativeEnumKind\n static: T[keyof T][]\n enum: T[keyof T][]\n}\n\n// -------------------------------------------------------------------------------------\n// NativeEnum\n// -------------------------------------------------------------------------------------\n/** `[Experimental]` Creates a Union type with a `enum` schema representation */\nexport function NativeEnum<T extends Record<string, string>>(\n value: T,\n options: SchemaOptions = {},\n) {\n const values = Object.values(value)\n\n function NativeEnumCheck(schema: TNativeEnum<T>, value: unknown) {\n return typeof value === 'string' && schema.enum.includes(value as any)\n }\n\n if (!TypeRegistry.Has(NativeEnumKind))\n TypeRegistry.Set(NativeEnumKind, NativeEnumCheck)\n\n return { ...options, [Kind]: NativeEnumKind, enum: values } as TNativeEnum<T>\n}\n"],"names":["Kind","TypeRegistry","NativeEnumKind","NativeEnum","value","options","values","Object","NativeEnumCheck","schema","enum","includes","Has","Set"],"mappings":"AAAA,SACEA,IAAI,EAGJC,YAAY,QACP,yBAAwB;AAE/B,OAAO,MAAMC,iBAAiB,aAAY;AAe1C,OAAO,SAASC,WACdC,KAAQ,EACRC,UAAyB,CAAC,CAAC;IAE3B,MAAMC,SAASC,OAAOD,MAAM,CAACF;IAE7B,SAASI,gBAAgBC,MAAsB,EAAEL,KAAc;QAC7D,OAAO,OAAOA,UAAU,YAAYK,OAAOC,IAAI,CAACC,QAAQ,CAACP;IAC3D;IAEA,IAAI,CAACH,aAAaW,GAAG,CAACV,iBACpBD,aAAaY,GAAG,CAACX,gBAAgBM;IAEnC,OAAO;QAAE,GAAGH,OAAO;QAAE,CAACL,KAAK,EAAEE;QAAgBQ,MAAMJ;IAAO;AAC5D"}
1
+ {"version":3,"sources":["../../../src/schemas/native-enum.ts"],"sourcesContent":["import {\n Kind,\n type SchemaOptions,\n type TSchema,\n TypeRegistry,\n} from '@sinclair/typebox/type'\n\nexport const NativeEnumKind = 'NativeEnum'\nexport interface TNativeEnum<T extends Record<string, string>> extends TSchema {\n [Kind]: typeof NativeEnumKind\n static: T[keyof T][]\n enum: T[keyof T][]\n}\n\nexport function NativeEnum<T extends Record<string, string>>(\n value: T,\n options: SchemaOptions = {},\n) {\n const values = Object.values(value)\n\n function NativeEnumCheck(schema: TNativeEnum<T>, value: unknown) {\n return typeof value === 'string' && schema.enum.includes(value as any)\n }\n\n if (!TypeRegistry.Has(NativeEnumKind))\n TypeRegistry.Set(NativeEnumKind, NativeEnumCheck)\n\n return { ...options, [Kind]: NativeEnumKind, enum: values } as TNativeEnum<T>\n}\n"],"names":["Kind","TypeRegistry","NativeEnumKind","NativeEnum","value","options","values","Object","NativeEnumCheck","schema","enum","includes","Has","Set"],"mappings":"AAAA,SACEA,IAAI,EAGJC,YAAY,QACP,yBAAwB;AAE/B,OAAO,MAAMC,iBAAiB,aAAY;AAO1C,OAAO,SAASC,WACdC,KAAQ,EACRC,UAAyB,CAAC,CAAC;IAE3B,MAAMC,SAASC,OAAOD,MAAM,CAACF;IAE7B,SAASI,gBAAgBC,MAAsB,EAAEL,KAAc;QAC7D,OAAO,OAAOA,UAAU,YAAYK,OAAOC,IAAI,CAACC,QAAQ,CAACP;IAC3D;IAEA,IAAI,CAACH,aAAaW,GAAG,CAACV,iBACpBD,aAAaY,GAAG,CAACX,gBAAgBM;IAEnC,OAAO;QAAE,GAAGH,OAAO;QAAE,CAACL,KAAK,EAAEE;QAAgBQ,MAAMJ;IAAO;AAC5D"}
@@ -1,5 +1,5 @@
1
1
  import { Type } from '@sinclair/typebox/type';
2
- export const Nullable = (schema)=>Type.Union([
2
+ export const Nullable = (schema, options = {})=>Type.Union([
3
3
  schema,
4
4
  Type.Null()
5
- ]);
5
+ ], options);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/schemas/nullable.ts"],"sourcesContent":["import { type TSchema, Type } from '@sinclair/typebox/type'\n\nexport const Nullable = <T extends TSchema>(schema: T) =>\n Type.Union([schema, Type.Null()])\n"],"names":["Type","Nullable","schema","Union","Null"],"mappings":"AAAA,SAAuBA,IAAI,QAAQ,yBAAwB;AAE3D,OAAO,MAAMC,WAAW,CAAoBC,SAC1CF,KAAKG,KAAK,CAAC;QAACD;QAAQF,KAAKI,IAAI;KAAG,EAAC"}
1
+ {"version":3,"sources":["../../../src/schemas/nullable.ts"],"sourcesContent":["import { type SchemaOptions, type TSchema, Type } from '@sinclair/typebox/type'\n\nexport const Nullable = <T extends TSchema>(\n schema: T,\n options: SchemaOptions = {},\n) => Type.Union([schema, Type.Null()], options)\n"],"names":["Type","Nullable","schema","options","Union","Null"],"mappings":"AAAA,SAA2CA,IAAI,QAAQ,yBAAwB;AAE/E,OAAO,MAAMC,WAAW,CACtBC,QACAC,UAAyB,CAAC,CAAC,GACxBH,KAAKI,KAAK,CAAC;QAACF;QAAQF,KAAKK,IAAI;KAAG,EAAEF,SAAQ"}
package/package.json CHANGED
@@ -20,11 +20,11 @@
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@sinclair/typebox": "^0.32.34",
23
- "@nmtjs/common": "0.0.1"
23
+ "@nmtjs/common": "0.0.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@sinclair/typebox": "^0.32.34",
27
- "@nmtjs/common": "0.0.1"
27
+ "@nmtjs/common": "0.0.2"
28
28
  },
29
29
  "files": [
30
30
  "src",
@@ -33,7 +33,7 @@
33
33
  "LICENSE.md",
34
34
  "README.md"
35
35
  ],
36
- "version": "0.0.1",
36
+ "version": "0.0.2",
37
37
  "scripts": {
38
38
  "build": "neemata-build -p neutral --root=./src './**/*.ts'",
39
39
  "type-check": "tsc --noEmit"
@@ -6,20 +6,12 @@ import {
6
6
  } from '@sinclair/typebox/type'
7
7
 
8
8
  export const NativeEnumKind = 'NativeEnum'
9
-
10
- // -------------------------------------------------------------------------------------
11
- // TNativeEnum
12
- // -------------------------------------------------------------------------------------
13
9
  export interface TNativeEnum<T extends Record<string, string>> extends TSchema {
14
10
  [Kind]: typeof NativeEnumKind
15
11
  static: T[keyof T][]
16
12
  enum: T[keyof T][]
17
13
  }
18
14
 
19
- // -------------------------------------------------------------------------------------
20
- // NativeEnum
21
- // -------------------------------------------------------------------------------------
22
- /** `[Experimental]` Creates a Union type with a `enum` schema representation */
23
15
  export function NativeEnum<T extends Record<string, string>>(
24
16
  value: T,
25
17
  options: SchemaOptions = {},
@@ -1,4 +1,6 @@
1
- import { type TSchema, Type } from '@sinclair/typebox/type'
1
+ import { type SchemaOptions, type TSchema, Type } from '@sinclair/typebox/type'
2
2
 
3
- export const Nullable = <T extends TSchema>(schema: T) =>
4
- Type.Union([schema, Type.Null()])
3
+ export const Nullable = <T extends TSchema>(
4
+ schema: T,
5
+ options: SchemaOptions = {},
6
+ ) => Type.Union([schema, Type.Null()], options)