Skip to content

Commit 0c90112

Browse files
committed
Engine Optimization Work
1 parent 0133310 commit 0c90112

52 files changed

Lines changed: 1163 additions & 1045 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

example/index.ts

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,44 @@ import Guard from 'typebox/guard'
44
import Format from 'typebox/format'
55
import Schema from 'typebox/schema'
66
import Value from 'typebox/value'
7-
import Type from 'typebox'
8-
9-
// ------------------------------------------------------------------
10-
// Settings
11-
// ------------------------------------------------------------------
12-
13-
System.Settings.Set({ enumerableKind: false })
147

15-
// ------------------------------------------------------------------
16-
// Guard
17-
// ------------------------------------------------------------------
8+
// import * as Type from 'typebox'
9+
10+
// Awaited
11+
// Conditional
12+
// ConstructorParameters
13+
// Evaluate
14+
// Exclude
15+
// Extract
16+
// Index
17+
// InstanceType
18+
// KeyOf
19+
// Mapped
20+
// Options
21+
// Parameters
22+
// Partial
23+
// Required
24+
// ReturnType
25+
// Omit
26+
// Pick
1827

19-
const A = Guard.GraphemeCount('type-📦') // 6
20-
const B = Guard.HasPropertyKey({ x: 1 }, 'x') // true
28+
import Type from 'typebox'
2129

22-
// ------------------------------------------------------------------
23-
// Type
24-
// ------------------------------------------------------------------
2530

26-
const T = Type.Object({
31+
const A = Type.Partial(Type.Object({
2732
x: Type.Number(),
2833
y: Type.Number(),
2934
z: Type.Number()
35+
}))
36+
const B = Type.Object({
37+
name: Type.String(),
38+
time: Type.Number()
3039
})
3140

32-
// ------------------------------------------------------------------
33-
// Script
34-
// ------------------------------------------------------------------
35-
36-
const S = Type.Script({ T }, `{
37-
[K in keyof T]: T[K] | null
38-
}`)
39-
40-
// ------------------------------------------------------------------
41-
// Infer
42-
// ------------------------------------------------------------------
43-
44-
type T = Type.Static<typeof T>
45-
type S = Type.Static<typeof S>
46-
47-
// ------------------------------------------------------------------
48-
// Parse
49-
// ------------------------------------------------------------------
50-
51-
const R = Value.Parse(T, { x: 1, y: 2, z: 3 })
52-
53-
// ------------------------------------------------------------------
54-
// Compile
55-
// ------------------------------------------------------------------
56-
const C = Compile(S)
57-
58-
const X = C.Parse({ x: 1, y: 2, z: 3 })
59-
60-
// ------------------------------------------------------------------
61-
// Format
62-
// ------------------------------------------------------------------
63-
64-
const E = Format.IsEmail('user@domain.com')
65-
66-
// ------------------------------------------------------------------
67-
// Schema
68-
// ------------------------------------------------------------------
41+
const M = Type.ReturnType(Type.Function([], Type.Object({
42+
x: Type.Number(),
43+
y: Type.Number(),
44+
z: Type.Number()
45+
})))
6946

70-
const D = Schema.Parse({ const: 'hello' }, 'hello')
47+
console.log(M)

src/type/action/awaited.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
// deno-lint-ignore-file ban-types
3029
// deno-fmt-ignore-file
3130

3231
import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
3332
import { type TDeferred, Deferred } from '../types/deferred.ts'
34-
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
33+
import { type TAwaitedAction, AwaitedAction } from '../engine/awaited/instantiate.ts'
3534

3635
// ------------------------------------------------------------------
3736
// Deferred
@@ -48,10 +47,6 @@ export function AwaitedDeferred<Type extends TSchema>(type: Type, options: TSche
4847
// Type
4948
// ------------------------------------------------------------------
5049
/** Applies an Awaited action to a type. */
51-
export type TAwaited<Type extends TSchema> = (
52-
TInstantiate<{}, TAwaitedDeferred<Type>>
53-
)
54-
/** Applies an Awaited action to a type. */
55-
export function Awaited<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TAwaited<Type> {
56-
return Instantiate({}, AwaitedDeferred(type, options)) as never
50+
export function Awaited<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TAwaitedAction<Type> {
51+
return AwaitedAction(type, options)
5752
}

src/type/action/conditional.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ THE SOFTWARE.
3131

3232
import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
3333
import { type TDeferred, Deferred } from '../types/deferred.ts'
34-
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
34+
import { type TConditionalAction, ConditionalAction } from '../engine/conditional/instantiate.ts'
3535

3636
// ------------------------------------------------------------------
3737
// Deferred
@@ -41,17 +41,17 @@ export type TConditionalDeferred<Left extends TSchema, Right extends TSchema, Tr
4141
TDeferred<'Conditional', [Left, Right, True, False]>
4242
)
4343
/** Creates a deferred Conditional action. */
44-
export function ConditionalDeferred<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema>(left: Left, right: Right, true_: True, false_: False, options: TSchemaOptions = {}): TConditionalDeferred<Left, Right, True, False> {
44+
export function ConditionalDeferred<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema>
45+
(left: Left, right: Right, true_: True, false_: False, options: TSchemaOptions = {}):
46+
TConditionalDeferred<Left, Right, True, False> {
4547
return Deferred('Conditional', [left, right, true_, false_], options) as never
4648
}
4749
// ------------------------------------------------------------------
4850
// Type
4951
// ------------------------------------------------------------------
5052
/** Applies a Conditional action to the given types. */
51-
export type TConditional<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema> = (
52-
TInstantiate<{}, TConditionalDeferred<Left, Right, True, False>>
53-
)
54-
/** Applies a Conditional action to the given types. */
55-
export function Conditional<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema>(left: Left, right: Right, true_: True, false_: False, options: TSchemaOptions = {}): TConditional<Left, Right, True, False> {
56-
return Instantiate({}, ConditionalDeferred(left, right, true_, false_, options)) as never
53+
export function Conditional<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema>
54+
(left: Left, right: Right, true_: True, false_: False, options: TSchemaOptions = {}):
55+
TConditionalAction<{}, { callstack: [] }, Left, Right, True, False> {
56+
return ConditionalAction({}, { callstack: [] }, left, right, true_, false_, options) as never
5757
}

src/type/action/constructor-parameters.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
// deno-lint-ignore-file ban-types
3029
// deno-fmt-ignore-file
3130

3231
import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
3332
import { type TDeferred, Deferred } from '../types/deferred.ts'
34-
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
33+
import { type TConstructorParametersAction, ConstructorParametersAction } from '../engine/constructor-parameters/instantiate.ts'
3534

3635
// ------------------------------------------------------------------
3736
// Deferred
@@ -48,10 +47,6 @@ export function ConstructorParametersDeferred<Type extends TSchema>(type: Type,
4847
// Type
4948
// ------------------------------------------------------------------
5049
/** Applies a ConstructorParameters action to a type. */
51-
export type TConstructorParameters<Type extends TSchema> = (
52-
TInstantiate<{}, TConstructorParametersDeferred<Type>>
53-
)
54-
/** Applies a ConstructorParameters action to a type. */
55-
export function ConstructorParameters<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TConstructorParameters<Type> {
56-
return Instantiate({}, ConstructorParametersDeferred(type, options)) as never
50+
export function ConstructorParameters<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TConstructorParametersAction<Type> {
51+
return ConstructorParametersAction(type, options) as never
5752
}

src/type/action/evaluate.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
// deno-lint-ignore-file ban-types
3029
// deno-fmt-ignore-file
3130

3231
import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
3332
import { type TDeferred, Deferred } from '../types/deferred.ts'
34-
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
33+
import { type TEvaluateAction, EvaluateAction } from '../engine/evaluate/instantiate.ts'
3534

3635
// ------------------------------------------------------------------
3736
// Deferred
@@ -48,10 +47,6 @@ export function EvaluateDeferred<Type extends TSchema>(type: Type, options: TSch
4847
// Type
4948
// ------------------------------------------------------------------
5049
/** Applies an Evaluate action to a type. */
51-
export type TEvaluate<Type extends TSchema> = (
52-
TInstantiate<{}, TEvaluateDeferred<Type>>
53-
)
54-
/** Applies an Evaluate action to a type. */
55-
export function Evaluate<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TEvaluate<Type> {
56-
return Instantiate({}, EvaluateDeferred(type, options)) as never
50+
export function Evaluate<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TEvaluateAction<Type> {
51+
return EvaluateAction(type, options) as never
5752
}

src/type/action/exclude.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
// deno-lint-ignore-file ban-types
3029
// deno-fmt-ignore-file
3130

3231
import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
3332
import { type TDeferred, Deferred } from '../types/deferred.ts'
34-
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
33+
import { type TExcludeAction, ExcludeAction } from '../engine/exclude/instantiate.ts'
3534

3635
// ------------------------------------------------------------------
3736
// Deferred
@@ -48,10 +47,6 @@ export function ExcludeDeferred<Left extends TSchema, Right extends TSchema>(lef
4847
// Type
4948
// ------------------------------------------------------------------
5049
/** Applies a Exclude action using the given types */
51-
export type TExclude<Left extends TSchema, Right extends TSchema> = (
52-
TInstantiate<{}, TExcludeDeferred<Left, Right>>
53-
)
54-
/** Applies a Exclude action using the given types */
55-
export function Exclude<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options: TSchemaOptions = {}): TExclude<Left, Right> {
56-
return Instantiate({}, ExcludeDeferred(left, right, options)) as never
50+
export function Exclude<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options: TSchemaOptions = {}): TExcludeAction<Left, Right> {
51+
return ExcludeAction(left, right, options) as never
5752
}

src/type/action/extract.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
// deno-lint-ignore-file ban-types
3029
// deno-fmt-ignore-file
3130

3231
import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
3332
import { type TDeferred, Deferred } from '../types/deferred.ts'
34-
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
33+
import { type TExtractAction, ExtractAction } from '../engine/extract/instantiate.ts'
3534

3635
// ------------------------------------------------------------------
3736
// Deferred
@@ -48,10 +47,6 @@ export function ExtractDeferred<Left extends TSchema, Right extends TSchema>(lef
4847
// Type
4948
// ------------------------------------------------------------------
5049
/** Applies an Extract action using the given types. */
51-
export type TExtract<Left extends TSchema, Right extends TSchema> = (
52-
TInstantiate<{}, TExtractDeferred<Left, Right>>
53-
)
54-
/** Applies an Extract action using the given types. */
55-
export function Extract<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options: TSchemaOptions = {}): TExtract<Left, Right> {
56-
return Instantiate({}, ExtractDeferred(left, right, options)) as never
50+
export function Extract<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options: TSchemaOptions = {}): TExtractAction<Left, Right> {
51+
return ExtractAction(left, right, options) as never
5752
}

src/type/action/indexed.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
// deno-lint-ignore-file ban-types
3029
// deno-fmt-ignore-file
3130

3231
import { Guard } from '../../guard/index.ts'
3332
import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
3433
import { type TDeferred, Deferred } from '../types/deferred.ts'
3534
import { type TKeysToIndexer, KeysToIndexer } from '../engine/helpers/keys-to-indexer.ts'
36-
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
35+
import { type TIndexAction, IndexAction } from '../engine/indexed/instantiate.ts'
3736

3837
// ------------------------------------------------------------------
3938
// Deferred
@@ -50,15 +49,11 @@ export function IndexDeferred<Type extends TSchema, Indexer extends TSchema>(typ
5049
// Index
5150
// ------------------------------------------------------------------
5251
/** Applies a Index action using the given types. */
53-
export type TIndex<Type extends TSchema, Indexer extends TSchema> = (
54-
TInstantiate<{}, TIndexDeferred<Type, Indexer>>
55-
)
56-
/** Applies a Index action using the given types. */
57-
export function Index<Type extends TSchema, Indexer extends PropertyKey[]>(type: Type, indexer: readonly [...Indexer], options?: TSchemaOptions): TIndex<Type, TKeysToIndexer<Indexer>>
52+
export function Index<Type extends TSchema, Indexer extends PropertyKey[]>(type: Type, indexer: readonly [...Indexer], options?: TSchemaOptions): TIndexAction<Type, TKeysToIndexer<Indexer>>
5853
/** Applies a Index action using the given types. */
59-
export function Index<Type extends TSchema, Indexer extends TSchema>(type: Type, indexer: Indexer, options?: TSchemaOptions): TIndex<Type, Indexer>
54+
export function Index<Type extends TSchema, Indexer extends TSchema>(type: Type, indexer: Indexer, options?: TSchemaOptions): TIndexAction<Type, Indexer>
6055
/** Applies a Index action using the given types. */
6156
export function Index(type: TSchema, indexer_or_keys: PropertyKey[] | TSchema, options: TSchemaOptions = {}): never {
6257
const indexer = Guard.IsArray(indexer_or_keys) ? KeysToIndexer(indexer_or_keys as PropertyKey[]) : indexer_or_keys
63-
return Instantiate({}, IndexDeferred(type, indexer, options)) as never
58+
return IndexAction(type, indexer, options) as never
6459
}

src/type/action/instance-type.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
// deno-lint-ignore-file ban-types
3029
// deno-fmt-ignore-file
3130

3231
import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
3332
import { type TDeferred, Deferred } from '../types/deferred.ts'
34-
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
33+
import { type TInstanceTypeAction, InstanceTypeAction } from '../engine/instance-type/instantiate.ts'
3534

3635
// ------------------------------------------------------------------
3736
// Deferred
@@ -48,10 +47,6 @@ export function InstanceTypeDeferred<Type extends TSchema>(type: Type, options:
4847
// Type
4948
// ------------------------------------------------------------------
5049
/** Applies a InstanceType action to the given type. */
51-
export type TInstanceType<Type extends TSchema> = (
52-
TInstantiate<{}, TInstanceTypeDeferred<Type>>
53-
)
54-
/** Applies a InstanceType action to the given type. */
55-
export function InstanceType<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TInstanceType<Type> {
56-
return Instantiate({}, InstanceTypeDeferred(type, options)) as never
50+
export function InstanceType<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TInstanceTypeAction<Type> {
51+
return InstanceTypeAction(type, options) as never
5752
}

src/type/action/keyof.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
// deno-lint-ignore-file ban-types
3029
// deno-fmt-ignore-file
3130

3231
import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
3332
import { type TDeferred, Deferred } from '../types/deferred.ts'
34-
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
33+
import { type TKeyOfAction, KeyOfAction } from '../engine/keyof/instantiate.ts'
3534

3635
// ------------------------------------------------------------------
3736
// Deferred
@@ -48,10 +47,6 @@ export function KeyOfDeferred<Type extends TSchema>(type: Type, options: TSchema
4847
// Type
4948
// ------------------------------------------------------------------
5049
/** Applies a KeyOf action to the given type. */
51-
export type TKeyOf<Type extends TSchema> = (
52-
TInstantiate<{}, TKeyOfDeferred<Type>>
53-
)
54-
/** Applies a KeyOf action to the given type. */
55-
export function KeyOf<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TKeyOf<Type> {
56-
return Instantiate({}, KeyOfDeferred(type, options)) as never
50+
export function KeyOf<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TKeyOfAction<Type> {
51+
return KeyOfAction(type, options)
5752
}

0 commit comments

Comments
 (0)