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 64b867e
Show file tree
Hide file tree
Showing 236 changed files with 11,469 additions and 5,277 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files.exclude": {
"node_modules": true,
"node_modules": false,
"package-lock.json": true
},
"editor.suggest.showStatusBar": false,
Expand Down
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()
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
2 changes: 1 addition & 1 deletion examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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'
import { Type, TypeGuard, Symbols, Static, TSchema } from '@sinclair/typebox'

// -----------------------------------------------------------
// Create: Type
Expand Down
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
6 changes: 3 additions & 3 deletions examples/prototypes/union-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { TypeRegistry, Kind, TSchema, SchemaOptions } from '@sinclair/typebox'
import { TypeRegistry, Symbols, TSchema, SchemaOptions } from '@sinclair/typebox'

// -------------------------------------------------------------------------------------
// TUnionEnum
// -------------------------------------------------------------------------------------
export interface TUnionEnum<T extends (string | number)[]> extends TSchema {
[Kind]: 'UnionEnum'
[Symbols.Kind]: 'UnionEnum'
static: T[number]
enum: T
}
Expand All @@ -45,5 +45,5 @@ export function UnionEnum<T extends (string | number)[]>(values: [...T], options
return (typeof value === 'string' || typeof value === 'number') && schema.enum.includes(value)
}
if (!TypeRegistry.Has('UnionEnum')) TypeRegistry.Set('UnionEnum', UnionEnumCheck)
return { ...options, [Kind]: 'UnionEnum', enum: values } as TUnionEnum<T>
return { ...options, [Symbols.Kind]: 'UnionEnum', enum: values } as TUnionEnum<T>
}
6 changes: 3 additions & 3 deletions examples/prototypes/union-oneof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { TypeRegistry, Kind, Static, TSchema, SchemaOptions } from '@sinclair/typebox'
import { TypeRegistry, Symbols, Static, TSchema, SchemaOptions } from '@sinclair/typebox'
import { Value } from '@sinclair/typebox/value'

// -------------------------------------------------------------------------------------
// TUnionOneOf
// -------------------------------------------------------------------------------------
export interface TUnionOneOf<T extends TSchema[]> extends TSchema {
[Kind]: 'UnionOneOf'
[Symbols.Kind]: 'UnionOneOf'
static: { [K in keyof T]: Static<T[K]> }[number]
oneOf: T
}
Expand All @@ -46,5 +46,5 @@ export function UnionOneOf<T extends TSchema[]>(oneOf: [...T], options: SchemaOp
return 1 === schema.oneOf.reduce((acc: number, schema: any) => (Value.Check(schema, value) ? acc + 1 : acc), 0)
}
if (!TypeRegistry.Has('UnionOneOf')) TypeRegistry.Set('UnionOneOf', UnionOneOfCheck)
return { ...options, [Kind]: 'UnionOneOf', oneOf } as TUnionOneOf<T>
return { ...options, [Symbols.Kind]: 'UnionOneOf', oneOf } as TUnionOneOf<T>
}
Loading

0 comments on commit 64b867e

Please sign in to comment.