Skip to content

Commit

Permalink
Esm
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 28, 2023
1 parent 2cf0546 commit 771291b
Show file tree
Hide file tree
Showing 74 changed files with 550 additions and 492 deletions.
12 changes: 10 additions & 2 deletions examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { String } from '@sinclair/typebox/type'
import { Static, String, Object, Number } from 'typebox'

console.log(String())
const A = Object({
x: Number(),
y: Number(),
z: String(),
})

type A = Static<typeof A>

console.log(A)
4 changes: 2 additions & 2 deletions hammer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export async function test_runtime(filter = '') {
await shell(`mocha target/test/runtime/index.js -g "${filter}"`)
}
export async function test(filter = '') {
// await test_static()
await test_static()
await test_runtime(filter)
}
// -------------------------------------------------------------------------------
// Build
// -------------------------------------------------------------------------------
export async function build(target = 'target/build') {
// await test()
await test()
await folder(target).delete()
await shell(`tsc -p ./src/tsconfig.json --outDir ${target}`)
await folder(target).add('package.json')
Expand Down
10 changes: 5 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 Down Expand Up @@ -38,17 +38,17 @@
"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",
"install:local": "hammer task install_local",
"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
38 changes: 17 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,9 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

// ----------------------------------------------------------------
// Default
// ----------------------------------------------------------------
import { Type, TypeBuilder } from './type/builder/index'
export { Type, TypeBuilder }
export default Type
// ----------------------------------------------------------------
// Runtime
// ----------------------------------------------------------------
export { CloneType, CloneRest } from './type/clone/type'

export * as TypeRegistry from './type/registry/type'
export * as FormatRegistry from './type/registry/format'
export * as ValueGuard from './type/guard/value'
export * as TypeGuard from './type/guard/type'

// ----------------------------------------------------------------
// ------------------------------------------------------------------
// Types
// ----------------------------------------------------------------
export { Strict } from './type/strict/index'
export { Symbols } from './type/symbols/index'

// ------------------------------------------------------------------
export { type TAny, Any } from './type/any/index'
export { type TArray, Array } from './type/array/index'
export { type TAsyncIterator, AsyncIterator } from './type/async-iterator/index'
Expand Down Expand Up @@ -107,3 +88,18 @@ export { type TUnknown, Unknown } from './type/unknown/index'
export { type TUnsafe, Unsafe } from './type/unsafe/index'
export { type TUppercase, Uppercase } from './type/intrinsic/index'
export { type TVoid, Void } from './type/void/index'
// ------------------------------------------------------------------
// Infrastructure
// ------------------------------------------------------------------
export { TypeRegistry, FormatRegistry } from './type/registry/index'
export { TypeGuard, ValueGuard } from './type/guard/index'
export { CloneType, CloneRest } from './type/clone/type'
export { Clone } from './type/clone/value'
export { Strict } from './type/strict/index'
export { Symbols } from './type/symbols/index'
// ------------------------------------------------------------------
// Builder
// ------------------------------------------------------------------
export { Type } from './type/builder/index'
import { Type } from './type/builder/index'
export default Type
3 changes: 3 additions & 0 deletions src/type/any/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ THE SOFTWARE.
import type { TSchema, SchemaOptions } from '../schema/index'
import { Symbols } from '../symbols/index'

// ------------------------------------------------------------------
// TAny
// ------------------------------------------------------------------
export interface TAny extends TSchema {
[Symbols.Kind]: 'Any'
static: any
Expand Down
3 changes: 3 additions & 0 deletions src/type/array/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import type { Static } from '../static/index'
import { Symbols } from '../symbols/index'
import { CloneType } from '../clone/type'

// ------------------------------------------------------------------
// TArray
// ------------------------------------------------------------------
export interface ArrayOptions extends SchemaOptions {
/** The minimum number of items in this array */
minItems?: number
Expand Down
3 changes: 3 additions & 0 deletions src/type/async-iterator/async-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import type { Static } from '../static/index'
import { Symbols } from '../symbols/index'
import { CloneType } from '../clone/type'

// ------------------------------------------------------------------
// TAsyncIterator
// ------------------------------------------------------------------
export interface TAsyncIterator<T extends TSchema = TSchema> extends TSchema {
[Symbols.Kind]: 'AsyncIterator'
static: AsyncIterableIterator<Static<T, this['params']>>
Expand Down
12 changes: 6 additions & 6 deletions src/type/awaited/awaited.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import { type TPromise } from '../promise/index'
import { CloneType } from '../clone/type'
import { TIntersect as IsIntersectType, TUnion as IsUnionType, TPromise as IsPromiseType } from '../guard/type'

// ----------------------------------------------------------------
// Unwrap
// ----------------------------------------------------------------
// ------------------------------------------------------------------
// AwaitedResolve
// ------------------------------------------------------------------
// prettier-ignore
export type AwaitedUnwrap<T extends TSchema[]> =
T extends [infer L extends TSchema, ...infer R extends TSchema[]]
Expand Down Expand Up @@ -94,9 +94,9 @@ export function Resolve<T extends TSchema>(T: T): AwaitedResolve<T> {
T
) as AwaitedResolve<T>
}
// ----------------------------------------------------------------
// Type
// ----------------------------------------------------------------
// ------------------------------------------------------------------
// TAwaited
// ------------------------------------------------------------------
export type TAwaited<T extends TSchema> = AwaitedResolve<T>

/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
Expand Down
3 changes: 3 additions & 0 deletions src/type/bigint/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ THE SOFTWARE.
import type { TSchema, SchemaOptions } from '../schema/index'
import { Symbols } from '../symbols/index'

// ------------------------------------------------------------------
// TBigInt
// ------------------------------------------------------------------
export interface BigIntOptions extends SchemaOptions {
exclusiveMaximum?: bigint
exclusiveMinimum?: bigint
Expand Down
4 changes: 3 additions & 1 deletion src/type/boolean/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ THE SOFTWARE.
import type { TSchema, SchemaOptions } from '../schema/index'
import { Symbols } from '../symbols/index'

// ------------------------------------------------------------------
// TBoolean
// ------------------------------------------------------------------
export interface TBoolean extends TSchema {
[Symbols.Kind]: 'Boolean'
static: boolean
type: 'boolean'
}

/** `[Json]` Creates a Boolean type */
export function Boolean(options: SchemaOptions = {}): TBoolean {
return {
Expand Down
176 changes: 58 additions & 118 deletions src/type/builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,122 +26,62 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { Any } from '../any/index'
import { Array } from '../array/index'
import { AsyncIterator } from '../async-iterator/index'
import { Awaited } from '../awaited/index'
import { BigInt } from '../bigint/index'
import { Boolean } from '../boolean/index'
import { Composite } from '../composite/index'
import { Constructor } from '../constructor/index'
import { ConstructorParameters } from '../constructor-parameters/index'
import { Date } from '../date/index'
import { Enum } from '../enum/index'
import { Exclude } from '../exclude/index'
import { Extends } from '../extends/index'
import { Extract } from '../extract/index'
import { Function } from '../function/index'
import { Index } from '../indexed/index'
import { InstanceType } from '../instance-type/index'
import { Integer } from '../integer/index'
import { Intersect } from '../intersect/index'
import { Capitalize, Uncapitalize, Lowercase, Uppercase } from '../intrinsic/index'
import { Iterator } from '../iterator/index'
import { KeyOf } from '../keyof/index'
import { Literal } from '../literal/index'
import { Never } from '../never/index'
import { Not } from '../not/index'
import { Null } from '../null/index'
import { Number } from '../number/index'
import { Object } from '../object/index'
import { Omit } from '../omit/index'
import { Optional } from '../optional/index'
import { Parameters } from '../parameters/index'
import { Partial } from '../partial/index'
import { Pick } from '../pick/index'
import { Promise } from '../promise/index'
import { Readonly } from '../readonly/index'
import { ReadonlyOptional } from '../readonly-optional/index'
import { Record } from '../record/index'
import { Recursive } from '../recursive/index'
import { Ref } from '../ref/index'
import { RegExp } from '../regexp/index'
import { Required } from '../required/index'
import { Rest } from '../rest/index'
import { ReturnType } from '../return-type/index'
import { Strict } from '../strict/index'
import { String } from '../string/index'
import { Symbol } from '../symbol/index'
import { TemplateLiteral } from '../template-literal/index'
import { Transform } from '../transform/index'
import { Tuple } from '../tuple/index'
import { Uint8Array } from '../uint8array/index'
import { Undefined } from '../undefined/index'
import { Union } from '../union/index'
import { Unknown } from '../unknown/index'
import { Unsafe } from '../unsafe/index'
import { Void } from '../void/index'
// ------------------------------------------------------------------
// TypeBuilder
// ------------------------------------------------------------------

export class TypeBuilder {
public Any = Any
public Array = Array
public AsyncIterator = AsyncIterator
public Awaited = Awaited
public BigInt = BigInt
public Boolean = Boolean
public Capitalize = Capitalize
public Composite = Composite
public Constructor = Constructor
public ConstructorParameters = ConstructorParameters
public Date = Date
public Enum = Enum
public Exclude = Exclude
public Extends = Extends
public Extract = Extract
public Function = Function
public Index = Index
public InstanceType = InstanceType
public Integer = Integer
public Intersect = Intersect
public Iterator = Iterator
public KeyOf = KeyOf
public Literal = Literal
public Lowercase = Lowercase
public Never = Never
public Not = Not
public Null = Null
public Number = Number
public Object = Object
public Omit = Omit
public Optional = Optional
public Parameters = Parameters
public Partial = Partial
public Pick = Pick
public Promise = Promise
public Readonly = Readonly
public ReadonlyOptional = ReadonlyOptional
public Record = Record
public Recursive = Recursive
public Ref = Ref
public RegExp = RegExp
public Required = Required
public Rest = Rest
public ReturnType = ReturnType
public Strict = Strict
public String = String
public Symbol = Symbol
public TemplateLiteral = TemplateLiteral
public Transform = Transform
public Tuple = Tuple
public Uint8Array = Uint8Array
public Uncapitalize = Uncapitalize
public Undefined = Undefined
public Union = Union
public Unknown = Unknown
public Unsafe = Unsafe
public Uppercase = Uppercase
public Void = Void
}

/** Json Schema Type Builder with Static Resolution for TypeScript */
export const Type = new TypeBuilder()
export { Any } from '../any/index'
export { Array } from '../array/index'
export { AsyncIterator } from '../async-iterator/index'
export { Awaited } from '../awaited/index'
export { BigInt } from '../bigint/index'
export { Boolean } from '../boolean/index'
export { Composite } from '../composite/index'
export { Constructor } from '../constructor/index'
export { ConstructorParameters } from '../constructor-parameters/index'
export { Date } from '../date/index'
export { Enum } from '../enum/index'
export { Exclude } from '../exclude/index'
export { Extends } from '../extends/index'
export { Extract } from '../extract/index'
export { Function } from '../function/index'
export { Index } from '../indexed/index'
export { InstanceType } from '../instance-type/index'
export { Integer } from '../integer/index'
export { Intersect } from '../intersect/index'
export { Capitalize, Uncapitalize, Lowercase, Uppercase } from '../intrinsic/index'
export { Iterator } from '../iterator/index'
export { KeyOf } from '../keyof/index'
export { Literal } from '../literal/index'
export { Never } from '../never/index'
export { Not } from '../not/index'
export { Null } from '../null/index'
export { Number } from '../number/index'
export { Object } from '../object/index'
export { Omit } from '../omit/index'
export { Optional } from '../optional/index'
export { Parameters } from '../parameters/index'
export { Partial } from '../partial/index'
export { Pick } from '../pick/index'
export { Promise } from '../promise/index'
export { Readonly } from '../readonly/index'
export { ReadonlyOptional } from '../readonly-optional/index'
export { Record } from '../record/index'
export { Recursive } from '../recursive/index'
export { Ref } from '../ref/index'
export { RegExp } from '../regexp/index'
export { Required } from '../required/index'
export { Rest } from '../rest/index'
export { ReturnType } from '../return-type/index'
export { Strict } from '../strict/index'
export { String } from '../string/index'
export { Symbol } from '../symbol/index'
export { TemplateLiteral } from '../template-literal/index'
export { Transform } from '../transform/index'
export { Tuple } from '../tuple/index'
export { Uint8Array } from '../uint8array/index'
export { Undefined } from '../undefined/index'
export { Union } from '../union/index'
export { Unknown } from '../unknown/index'
export { Unsafe } from '../unsafe/index'
export { Void } from '../void/index'
Loading

0 comments on commit 771291b

Please sign in to comment.