-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
258c013
commit b2960fe
Showing
7 changed files
with
119 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,49 @@ | ||
import { TypeSystem } from '@sinclair/typebox/system' | ||
import { TypeCompiler } from '@sinclair/typebox/compiler' | ||
import { Value, ValuePointer, ParseRegistry } from '@sinclair/typebox/value' | ||
import { Value, ValuePointer } from '@sinclair/typebox/value' | ||
import { Parse, StaticParseAsType } from '@sinclair/typebox/syntax' | ||
import { Type, TypeGuard, Kind, Static, TSchema } from '@sinclair/typebox' | ||
|
||
ParseRegistry.Set('Foo', (a, b, c) => c) | ||
// ----------------------------------------------------------- | ||
// Create: Type | ||
// ----------------------------------------------------------- | ||
|
||
console.time() | ||
for (let i = 0; i < 1_000_000; i += 1) { | ||
Value.Parse(['Convert', 'Assert', 'Clone'], Type.String(), 1) | ||
} | ||
console.timeEnd() | ||
const T = Type.Object({ | ||
x: Type.Number(), | ||
y: Type.Number(), | ||
z: Type.Number(), | ||
}) | ||
|
||
type T = Static<typeof T> | ||
|
||
console.log(T) | ||
|
||
// ----------------------------------------------------------- | ||
// Parse: Type | ||
// ----------------------------------------------------------- | ||
|
||
const S = Parse({ T }, `{ x: T, y: T, z: T }`) | ||
|
||
type S = Static<typeof S> | ||
|
||
// ----------------------------------------------------------- | ||
// 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { TypeCompiler } from '@sinclair/typebox/compiler' | ||
import { Type, TypeGuard, ValueGuard } from '@sinclair/typebox' | ||
import { Assert } from '../assert/index' | ||
|
||
describe('compiler/TypeCheckMembers', () => { | ||
it('Should return Schema', () => { | ||
const A = TypeCompiler.Compile(Type.Number(), [Type.String(), Type.Boolean()]) | ||
Assert.IsTrue(TypeGuard.IsNumber(A.Schema())) | ||
}) | ||
it('Should return References', () => { | ||
const A = TypeCompiler.Compile(Type.Number(), [Type.String(), Type.Boolean()]) | ||
Assert.IsTrue(TypeGuard.IsNumber(A.Schema())) | ||
Assert.IsTrue(TypeGuard.IsString(A.References()[0])) | ||
Assert.IsTrue(TypeGuard.IsBoolean(A.References()[1])) | ||
}) | ||
it('Should return Code', () => { | ||
const A = TypeCompiler.Compile(Type.Number(), [Type.String(), Type.Boolean()]) | ||
Assert.IsTrue(ValueGuard.IsString(A.Code())) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import './__members' | ||
import './any' | ||
import './array' | ||
import './async-iterator' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters