Skip to content

Commit

Permalink
Revision 0.32.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 28, 2023
1 parent 573cdb1 commit 81bae60
Show file tree
Hide file tree
Showing 245 changed files with 12,253 additions and 5,166 deletions.
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-type-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Array, Any } from '@sinclair/typebox'

const T = Array(Any())
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-type-boolean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Boolean } from '@sinclair/typebox'

const T = Boolean()
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-type-extends.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Any, Extends } from '@sinclair/typebox'

const T = Extends(Any(), Any(), Any(), Any())
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-type-null.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Null } from '@sinclair/typebox'

const T = Null()
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-type-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Number } from '@sinclair/typebox'

const T = Number()
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-type-object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Object } from '@sinclair/typebox'

const T = Object({})
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-type-record.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Record, Any } from '@sinclair/typebox'

const T = Record(Any(), Any())
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-type-string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { String } from '@sinclair/typebox'

const T = String()
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Type } from '@sinclair/typebox'

const T = Type.String()
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-value-cast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Cast } from '@sinclair/typebox/value/cast'

console.log(Cast)
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-value-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Check } from '@sinclair/typebox/value/check'

console.log(Check)
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-value-convert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Convert } from '@sinclair/typebox/value/convert'

console.log(Convert)
3 changes: 3 additions & 0 deletions benchmark/compression/module/typebox-value-create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Create } from '@sinclair/typebox/value/create'

console.log(Create)
2 changes: 1 addition & 1 deletion benchmark/compression/module/typebox.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Type } from '@sinclair/typebox'
import Type from '@sinclair/typebox'

const T = Type.String()
7 changes: 7 additions & 0 deletions changelog/0.32.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## [0.32.0](https://www.npmjs.com/package/@sinclair/typebox/v/0.32.0)

## Overview

Revision 0.32.0 is milestone revision for the TypeBox project. This revision focuses on the modularization of all TypeBox types, reducing TypeBuilder size and reimplementing much of the TypeBox core to provide better inference stability for both indexed access types, composite types as well as to make provisions for ESM publishing in future.

This revision passes tests for TypeBox's public API, however internal type names related to inference resolution have been removed in this revision. This constitutes a minor breaking change.
6 changes: 3 additions & 3 deletions examples/collections/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { TypeCheck, TypeCompiler, ValueError } from '@sinclair/typebox/compiler'
import { TSchema, Static, TypeBoxError } from '@sinclair/typebox'
import { TSchema, Static } from '@sinclair/typebox'
import { Value } from '@sinclair/typebox/value'

// ----------------------------------------------------------------
// TypeArrayError
// ----------------------------------------------------------------
export class TypeArrayError extends TypeBoxError {
export class TypeArrayError extends Error {
constructor(message: string) {
super(`${message}`)
}
}
export class TypeArrayLengthError extends TypeBoxError {
export class TypeArrayLengthError extends Error {
constructor() {
super('arrayLength not a number')
}
Expand Down
6 changes: 3 additions & 3 deletions examples/collections/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { TypeCheck, TypeCompiler, ValueError } from '@sinclair/typebox/compiler'
import { TSchema, Static, TypeBoxError } from '@sinclair/typebox'
import { TSchema, Static } from '@sinclair/typebox'
import { Value } from '@sinclair/typebox/value'

// ----------------------------------------------------------------
// TypeMapKeyError
// ----------------------------------------------------------------
export class TypeMapKeyError extends TypeBoxError {
export class TypeMapKeyError extends Error {
constructor(message: string) {
super(`${message} for key`)
}
}
export class TypeMapValueError extends TypeBoxError {
export class TypeMapValueError extends Error {
constructor(key: unknown, message: string) {
super(`${message} for key ${JSON.stringify(key)}`)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/collections/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { TypeCheck, TypeCompiler, ValueError } from '@sinclair/typebox/compiler'
import { TSchema, Static, TypeBoxError } from '@sinclair/typebox'
import { TSchema, Static } from '@sinclair/typebox'
import { Value } from '@sinclair/typebox/value'

// ----------------------------------------------------------------
// Errors
// ----------------------------------------------------------------
export class TypeSetError extends TypeBoxError {
export class TypeSetError extends Error {
constructor(message: string) {
super(`${message}`)
}
Expand Down
56 changes: 22 additions & 34 deletions examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
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(),
import { Type, TypeGuard, Kind, Static, TSchema, TTuple, TIntersect, TUnion, TPromise, TAsyncIterator, TIterator, TArray, TConstructor, TFunction, Clone, TRef, TObject, TProperties } from '@sinclair/typebox'
import { CloneType } from '@sinclair/typebox'
import { ValueGuard } from '@sinclair/typebox'

const T = Type.Object(
{
x: Type.Number(),
y: Type.String(),
},
{ $id: 'T' },
)

const R1 = Type.Ref<typeof T>('T', { $id: 'R1' })
const R2 = Type.Ref<typeof R1>('R1', { $id: 'R2' })
const R3 = Type.Ref<typeof R2>('R2', { $id: 'R3' })
const R4 = Type.Ref<typeof R3>('R3', { $id: 'R4' })

const S = Type.Object({
a: Type.Ref<typeof R4>('R4'),
b: Type.Ref<typeof R4>('R4'),
})

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
// -----------------------------------------------------------
const X = Type.Deref(S, [T, R1, R2, R3, R4])

console.log(C.Check(V))
console.log(X)
3 changes: 1 addition & 2 deletions examples/prototypes/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
TTuple,
TProperties,
TIntersect,
IntersectType,
TUnion,
TNever
} from '@sinclair/typebox'
Expand Down Expand Up @@ -75,7 +74,7 @@ export type TEvaluateArray<T extends TSchema[]> = T extends [infer L, ...infer
[]
// prettier-ignore
export type TEvaluate<T extends TSchema> =
T extends TIntersect<infer S> ? IntersectType<TEvaluateIntersectRest<S>> :
T extends TIntersect<infer S> ? TIntersect<TEvaluateIntersectRest<S>> :
T extends TUnion<infer S> ? TUnion<TEvaluateArray<S>> :
T extends TConstructor<infer P, infer R> ? TConstructor<TEvaluateArray<P>, TEvaluate<R>> :
T extends TFunction<infer P, infer R> ? TFunction<TEvaluateArray<P>, TEvaluate<R>> :
Expand Down
1 change: 0 additions & 1 deletion examples/prototypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

export * from './const'
export * from './evaluate'
export * from './partial-deep'
export * from './union-enum'
Expand Down
9 changes: 5 additions & 4 deletions examples/prototypes/partial-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { TypeGuard, Type, TSchema, TIntersect, TUnion, TObject, TPartial, TProperties, AssertRest, AssertType, Evaluate } from '@sinclair/typebox'
import { TypeGuard, Type, TSchema, TIntersect, TUnion, TObject, TPartial, TProperties, Evaluate } from '@sinclair/typebox'

// -------------------------------------------------------------------------------------
// TDeepPartial
// -------------------------------------------------------------------------------------
export type TPartialDeepProperties<T extends TProperties> = {
[K in keyof T]: TPartial<T[K]>
}
export type TPartialDeepRest<T extends TSchema[]> = T extends [infer L, ...infer R]
? [TPartial<AssertType<L>>, ...TPartialDeepRest<AssertRest<R>>]
: []
export type TPartialDeepRest<T extends TSchema[]> =
T extends [infer L extends TSchema, ...infer R extends TSchema[]]
? [TPartial<L>, ...TPartialDeepRest<R>]
: []
export type TPartialDeep<T extends TSchema> =
T extends TIntersect<infer S> ? TIntersect<TPartialDeepRest<S>> :
T extends TUnion<infer S> ? TUnion<TPartialDeepRest<S>> :
Expand Down
23 changes: 6 additions & 17 deletions examples/typedef/typedef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,10 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

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

// --------------------------------------------------------------------------
// Utility Types
// --------------------------------------------------------------------------
export type Assert<T, U> = T extends U ? T : never
export type Base = { m: string, t: string }
export type Base16 = { m: 'F', t: '01', '0': '1', '1': '2', '2': '3', '3': '4', '4': '5', '5': '6', '6': '7', '7': '8', '8': '9', '9': 'A', 'A': 'B', 'B': 'C', 'C': 'D', 'D': 'E', 'E': 'F', 'F': '0' }
export type Base10 = { m: '9', t: '01', '0': '1', '1': '2', '2': '3', '3': '4', '4': '5', '5': '6', '6': '7', '7': '8', '8': '9', '9': '0' }
export type Reverse<T extends string> = T extends `${infer L}${infer R}` ? `${Reverse<R>}${L}` : T
export type Tick<T extends string, B extends Base> = T extends keyof B ? B[T] : never
export type Next<T extends string, B extends Base> = T extends Assert<B, Base>['m'] ? Assert<B, Base>['t'] : T extends `${infer L}${infer R}` ? L extends Assert<B, Base>['m'] ? `${Assert<Tick<L, B>, string>}${Next<R, B>}` : `${Assert<Tick<L, B>, string>}${R}` : never
export type Increment<T extends string, B extends Base = Base10> = Reverse<Next<Reverse<T>, B>>
// --------------------------------------------------------------------------
// SchemaOptions
// Metadata
// --------------------------------------------------------------------------
export interface Metadata {
[name: string]: any
Expand All @@ -65,8 +54,8 @@ export interface TBoolean extends Types.TSchema {
// --------------------------------------------------------------------------
// TUnion
// --------------------------------------------------------------------------
type InferUnion<T extends TStruct[], D extends string, Index = string> = T extends [infer L, ...infer R]
? Types.Evaluate<{ [_ in D]: Index } & Types.Static<Types.AssertType<L>>> | InferUnion<Types.AssertRest<R>, D, Increment<Types.Assert<Index, string>>>
export type InferUnion<T extends TStruct[], D extends string, Index = string> = T extends [infer L, ...infer R]
? Types.Evaluate<{ [_ in D]: Index } & Types.Static<Types.AssertType<L>>> | InferUnion<Types.AssertRest<R>, D, Types.Increment<Types.Assert<Index, string>>>
: never

export interface TUnion<T extends TStruct[] = TStruct[], D extends string = string> extends Types.TSchema {
Expand Down Expand Up @@ -177,7 +166,7 @@ export interface StructMetadata extends Metadata {
}
export interface TStruct<T extends TFields = TFields> extends Types.TSchema, StructMetadata {
[Types.Kind]: 'TypeDef:Struct'
static: Types.PropertiesReduce<T, this['params']>
static: Types.ObjectResolve<T, this['params']>
optionalProperties: { [K in Types.Assert<OptionalKeys<T>, keyof T>]: T[K] }
properties: { [K in Types.Assert<RequiredKeys<T>, keyof T>]: T[K] }
}
Expand Down Expand Up @@ -240,7 +229,7 @@ export namespace TimestampFormat {
// --------------------------------------------------------------------------
// ValueCheck
// --------------------------------------------------------------------------
export class ValueCheckError extends Types.TypeBoxError {
export class ValueCheckError extends Error {
constructor(public readonly schema: Types.TSchema) {
super('Unknown type')
}
Expand Down
8 changes: 8 additions & 0 deletions hammer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { readFileSync } from 'fs'
// Clean
// -------------------------------------------------------------------------------
export async function clean() {
await folder('node_modules/typebox').delete()
await folder('target').delete()
}
// -------------------------------------------------------------------------------
Expand Down Expand Up @@ -65,6 +66,13 @@ export async function build(target = 'target/build') {
await folder(target).add('license')
await shell(`cd ${target} && npm pack`)
}
// -------------------------------------------------------------------------------
// Install
// -------------------------------------------------------------------------------
export async function install_local(target = 'target/typebox') {
await build(target)
await folder('node_modules').add(target)
}
// -------------------------------------------------------------
// Publish
// -------------------------------------------------------------
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.31.28",
"version": "0.32.0-dev-1",
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
Expand All @@ -15,6 +15,7 @@
"exports": {
"./compiler": "./compiler/index.js",
"./errors": "./errors/index.js",
"./type": "./type/index.js",
"./system": "./system/index.js",
"./value/cast": "./value/cast.js",
"./value/check": "./value/check.js",
Expand All @@ -30,23 +31,24 @@
"./value/pointer": "./value/pointer.js",
"./value/transform": "./value/transform.js",
"./value": "./value/index.js",
".": "./typebox.js"
".": "./index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/sinclairzx81/typebox"
},
"scripts": {
"benchmark:compression": "hammer task benchmark_compression",
"benchmark:measurement": "hammer task benchmark_measurement",
"benchmark": "hammer task benchmark",
"install:local": "hammer task install_local",
"test:typescript": "hammer task test_typescript",
"test:static": "hammer task test_static",
"test:runtime": "hammer task test_runtime",
"test": "hammer task test",
"clean": "hammer task clean",
"format": "hammer task format",
"start": "hammer task start",
"benchmark:compression": "hammer task benchmark_compression",
"benchmark:measurement": "hammer task benchmark_measurement",
"benchmark": "hammer task benchmark",
"build": "hammer task build",
"publish": "hammer task publish",
"publish:dev": "hammer task publish_dev"
Expand Down
Loading

0 comments on commit 81bae60

Please sign in to comment.