Skip to content

Commit

Permalink
Support ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 30, 2023
1 parent 65d9c8f commit 023208a
Show file tree
Hide file tree
Showing 290 changed files with 3,494 additions and 3,529 deletions.
41 changes: 1 addition & 40 deletions examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1 @@
import { TypeSystem } from '@sinclair/typebox/system'
import { TypeCompiler } from '@sinclair/typebox/compiler'
import { Value, ValuePointer } from '@sinclair/typebox/value'
import { Type, TypeGuard, Kind, Static, TSchema } from '@sinclair/typebox'

// -----------------------------------------------------------
// Create: Type
// -----------------------------------------------------------

const T = Type.Object({
x: Type.Number(),
y: Type.Number(),
z: Type.Number(),
})

type T = Static<typeof T>

console.log(T)

// -----------------------------------------------------------
// Create: Value
// -----------------------------------------------------------

const V = Value.Create(T)

console.log(V)

// -----------------------------------------------------------
// Compile: Type
// -----------------------------------------------------------

const C = TypeCompiler.Compile(T)

console.log(C.Code())

// -----------------------------------------------------------
// Check: Value
// -----------------------------------------------------------

console.log(C.Check(V))
import { String } from 'typebox'
2 changes: 1 addition & 1 deletion examples/typedef/typedef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { TypeSystemErrorFunction, DefaultErrorFunction } from '@sinclair/typebox/system'
import * as Types from '@sinclair/typebox/type'
import * as Types from '@sinclair/typebox/type/index.mjs'

// --------------------------------------------------------------------------
// Metadata
Expand Down
4 changes: 4 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

import { Any } from 'typebox'


16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
],
"author": "sinclairzx81",
"license": "MIT",
"main": "./typebox.js",
"types": "./typebox.d.ts",
"module": "./index.mjs",
"types": "./index.d.mts",
"exports": {
"./compiler": "./compiler/index.js",
"./errors": "./errors/index.js",
"./system": "./system/index.js",
"./type": "./type/index.js",
"./value": "./value/index.js",
".": "./index.js"
"./compiler": "./compiler/index.mjs",
"./errors": "./errors/index.mjs",
"./system": "./system/index.mjs",
"./type": "./type/index.mjs",
"./value": "./value/index.mjs",
".": "./index.mjs"
},
"repository": {
"type": "git",
Expand Down
86 changes: 43 additions & 43 deletions src/compiler/compiler.ts → src/compiler/compiler.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,51 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { Encode as TransformEncode, Decode as TransformDecode, HasTransform, TransformDecodeCheckError, TransformEncodeCheckError } from '../value/transform/index'
import { IsArray, IsString, IsNumber, IsBigInt } from '../value/guard/index'
import { Errors, ValueErrorIterator } from '../errors/index'
import { TypeSystemPolicy } from '../system/index'
import { Deref } from '../value/deref/index'
import { Hash } from '../value/hash/index'
import { Kind } from '../type/symbols/index'
import { Encode as TransformEncode, Decode as TransformDecode, HasTransform, TransformDecodeCheckError, TransformEncodeCheckError } from '../value/transform/index.mjs'
import { IsArray, IsString, IsNumber, IsBigInt } from '../value/guard/index.mjs'
import { Errors, ValueErrorIterator } from '../errors/index.mjs'
import { TypeSystemPolicy } from '../system/index.mjs'
import { Deref } from '../value/deref/index.mjs'
import { Hash } from '../value/hash/index.mjs'
import { Kind } from '../type/symbols/index.mjs'

import { TSchema as IsSchemaType } from '../type/guard/type'
import { TypeRegistry, FormatRegistry } from '../type/registry/index'
import { KeyOfStringResolvePattern } from '../type/keyof/index'
import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined'
import { TSchema as IsSchemaType } from '../type/guard/type.mjs'
import { TypeRegistry, FormatRegistry } from '../type/registry/index.mjs'
import { KeyOfStringResolvePattern } from '../type/keyof/index.mjs'
import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined.mjs'

import type { TSchema } from '../type/schema/index'
import type { TAsyncIterator } from '../type/async-iterator/index'
import type { TAny } from '../type/any/index'
import type { TArray } from '../type/array/index'
import type { TBigInt } from '../type/bigint/index'
import type { TBoolean } from '../type/boolean/index'
import type { TDate } from '../type/date/index'
import type { TConstructor } from '../type/constructor/index'
import type { TFunction } from '../type/function/index'
import type { TInteger } from '../type/integer/index'
import type { TIntersect } from '../type/intersect/index'
import type { TIterator } from '../type/iterator/index'
import type { TLiteral } from '../type/literal/index'
import { Never, type TNever } from '../type/never/index'
import type { TNot } from '../type/not/index'
import type { TNull } from '../type/null/index'
import type { TNumber } from '../type/number/index'
import type { TObject } from '../type/object/index'
import type { TPromise } from '../type/promise/index'
import type { TRecord } from '../type/record/index'
import type { TRef } from '../type/ref/index'
import type { TTemplateLiteral } from '../type/template-literal/index'
import type { TThis } from '../type/recursive/index'
import type { TTuple } from '../type/tuple/index'
import type { TUnion } from '../type/union/index'
import type { TUnknown } from '../type/unknown/index'
import type { Static, StaticDecode, StaticEncode } from '../type/static/index'
import type { TString } from '../type/string/index'
import type { TSymbol } from '../type/symbol/index'
import type { TUndefined } from '../type/undefined/index'
import type { TUint8Array } from '../type/uint8array/index'
import type { TVoid } from '../type/void/index'
import type { TSchema } from '../type/schema/index.mjs'
import type { TAsyncIterator } from '../type/async-iterator/index.mjs'
import type { TAny } from '../type/any/index.mjs'
import type { TArray } from '../type/array/index.mjs'
import type { TBigInt } from '../type/bigint/index.mjs'
import type { TBoolean } from '../type/boolean/index.mjs'
import type { TDate } from '../type/date/index.mjs'
import type { TConstructor } from '../type/constructor/index.mjs'
import type { TFunction } from '../type/function/index.mjs'
import type { TInteger } from '../type/integer/index.mjs'
import type { TIntersect } from '../type/intersect/index.mjs'
import type { TIterator } from '../type/iterator/index.mjs'
import type { TLiteral } from '../type/literal/index.mjs'
import { Never, type TNever } from '../type/never/index.mjs'
import type { TNot } from '../type/not/index.mjs'
import type { TNull } from '../type/null/index.mjs'
import type { TNumber } from '../type/number/index.mjs'
import type { TObject } from '../type/object/index.mjs'
import type { TPromise } from '../type/promise/index.mjs'
import type { TRecord } from '../type/record/index.mjs'
import type { TRef } from '../type/ref/index.mjs'
import type { TTemplateLiteral } from '../type/template-literal/index.mjs'
import type { TThis } from '../type/recursive/index.mjs'
import type { TTuple } from '../type/tuple/index.mjs'
import type { TUnion } from '../type/union/index.mjs'
import type { TUnknown } from '../type/unknown/index.mjs'
import type { Static, StaticDecode, StaticEncode } from '../type/static/index.mjs'
import type { TString } from '../type/string/index.mjs'
import type { TSymbol } from '../type/symbol/index.mjs'
import type { TUndefined } from '../type/undefined/index.mjs'
import type { TUint8Array } from '../type/uint8array/index.mjs'
import type { TVoid } from '../type/void/index.mjs'

// ------------------------------------------------------------------
// CheckFunction
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/index.ts → src/compiler/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index'
export * from './compiler'
export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index.mjs'
export * from './compiler.mjs'
78 changes: 39 additions & 39 deletions src/errors/errors.ts → src/errors/errors.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,46 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { IsArray, IsUint8Array, IsDate, IsPromise, IsFunction, IsAsyncIterator, IsIterator, IsBoolean, IsNumber, IsBigInt, IsString, IsSymbol, IsInteger, IsNull, IsUndefined } from '../value/guard/index'
import { TypeSystemPolicy, TypeSystemErrorFunction } from '../system/index'
import { KeyOfStringResolvePattern } from '../type/keyof/index'
import { TypeRegistry, FormatRegistry } from '../type/registry/index'
import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined'
import { Deref } from '../value/deref/index'
import { Hash } from '../value/hash/index'
import { Kind } from '../type/symbols/index'
import { IsArray, IsUint8Array, IsDate, IsPromise, IsFunction, IsAsyncIterator, IsIterator, IsBoolean, IsNumber, IsBigInt, IsString, IsSymbol, IsInteger, IsNull, IsUndefined } from '../value/guard/index.mjs'
import { TypeSystemPolicy, TypeSystemErrorFunction } from '../system/index.mjs'
import { KeyOfStringResolvePattern } from '../type/keyof/index.mjs'
import { TypeRegistry, FormatRegistry } from '../type/registry/index.mjs'
import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined.mjs'
import { Deref } from '../value/deref/index.mjs'
import { Hash } from '../value/hash/index.mjs'
import { Kind } from '../type/symbols/index.mjs'

import type { TSchema } from '../type/schema/index'
import type { TAsyncIterator } from '../type/async-iterator/index'
import type { TAny } from '../type/any/index'
import type { TArray } from '../type/array/index'
import type { TBigInt } from '../type/bigint/index'
import type { TBoolean } from '../type/boolean/index'
import type { TDate } from '../type/date/index'
import type { TConstructor } from '../type/constructor/index'
import type { TFunction } from '../type/function/index'
import type { TInteger } from '../type/integer/index'
import type { TIntersect } from '../type/intersect/index'
import type { TIterator } from '../type/iterator/index'
import type { TLiteral } from '../type/literal/index'
import { Never, type TNever } from '../type/never/index'
import type { TNot } from '../type/not/index'
import type { TNull } from '../type/null/index'
import type { TNumber } from '../type/number/index'
import type { TObject } from '../type/object/index'
import type { TPromise } from '../type/promise/index'
import type { TRecord } from '../type/record/index'
import type { TRef } from '../type/ref/index'
import type { TTemplateLiteral } from '../type/template-literal/index'
import type { TThis } from '../type/recursive/index'
import type { TTuple } from '../type/tuple/index'
import type { TUnion } from '../type/union/index'
import type { TUnknown } from '../type/unknown/index'
import type { TString } from '../type/string/index'
import type { TSymbol } from '../type/symbol/index'
import type { TUndefined } from '../type/undefined/index'
import type { TUint8Array } from '../type/uint8array/index'
import type { TVoid } from '../type/void/index'
import type { TSchema } from '../type/schema/index.mjs'
import type { TAsyncIterator } from '../type/async-iterator/index.mjs'
import type { TAny } from '../type/any/index.mjs'
import type { TArray } from '../type/array/index.mjs'
import type { TBigInt } from '../type/bigint/index.mjs'
import type { TBoolean } from '../type/boolean/index.mjs'
import type { TDate } from '../type/date/index.mjs'
import type { TConstructor } from '../type/constructor/index.mjs'
import type { TFunction } from '../type/function/index.mjs'
import type { TInteger } from '../type/integer/index.mjs'
import type { TIntersect } from '../type/intersect/index.mjs'
import type { TIterator } from '../type/iterator/index.mjs'
import type { TLiteral } from '../type/literal/index.mjs'
import { Never, type TNever } from '../type/never/index.mjs'
import type { TNot } from '../type/not/index.mjs'
import type { TNull } from '../type/null/index.mjs'
import type { TNumber } from '../type/number/index.mjs'
import type { TObject } from '../type/object/index.mjs'
import type { TPromise } from '../type/promise/index.mjs'
import type { TRecord } from '../type/record/index.mjs'
import type { TRef } from '../type/ref/index.mjs'
import type { TTemplateLiteral } from '../type/template-literal/index.mjs'
import type { TThis } from '../type/recursive/index.mjs'
import type { TTuple } from '../type/tuple/index.mjs'
import type { TUnion } from '../type/union/index.mjs'
import type { TUnknown } from '../type/unknown/index.mjs'
import type { TString } from '../type/string/index.mjs'
import type { TSymbol } from '../type/symbol/index.mjs'
import type { TUndefined } from '../type/undefined/index.mjs'
import type { TUint8Array } from '../type/uint8array/index.mjs'
import type { TVoid } from '../type/void/index.mjs'

// --------------------------------------------------------------------------
// ValueErrorType
Expand Down
2 changes: 1 addition & 1 deletion src/errors/index.ts → src/errors/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

export * from './errors'
export * from './errors.mjs'
Loading

0 comments on commit 023208a

Please sign in to comment.