Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
---

### Version Updates
- [Revision 1.1.28](https://github.com/sinclairzx81/typebox/pull/1582)
- Type Engine Optimization
- [Revision 1.1.27](https://github.com/sinclairzx81/typebox/pull/1580)
- Inference Optimization for XStaticProperties
- [Revision 1.1.26](https://github.com/sinclairzx81/typebox/pull/1578)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Type.ReadonlyType
# Type.ReadonlyObject

This type is an alias for the `Readonly<T>` TypeScript utility type. It makes all properties of an Object `readonly` or marks an Array or Tuple as immutable `readonly T[]`.
This type is an alias for TypeScript's `Readonly<T>` utility type. It will make all properties of a TObject readonly or marks an TArray or TTuple as immutable `readonly T[]`.

## Example

Expand All @@ -13,7 +13,7 @@ const T = Type.Object({ // const T = TObject<{
z: Type.Number() // z: TNumber,
}) // }>

const S = Type.ReadonlyType(T) // const S: TObject<{
const S = Type.ReadonlyObject(T) // const S: TObject<{
// x: TReadonly<TNumber>,
// y: TReadonly<TNumber>,
// z: TReadonly<TNumber>
Expand All @@ -28,7 +28,7 @@ const T = Type.Tuple([ // const T = TImmutable<TTup
Type.String(), // TString
]) // ]>>

const S = Type.ReadonlyType(T) // const S: TImmutable<TTuple<[
const S = Type.ReadonlyObject(T) // const S: TImmutable<TTuple<[
// TNumber,
// TString
// }>>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>Type.ReadonlyType</h1>
<p>This type is an alias for the <code>Readonly&lt;T&gt;</code> TypeScript utility type. It makes all properties of an Object <code>readonly</code> or marks an Array or Tuple as immutable <code>readonly T[]</code>.</p>
<h1>Type.ReadonlyObject</h1>
<p>This type is an alias for TypeScript&#39;s <code>Readonly&lt;T&gt;</code> utility type. It will make all properties of a TObject readonly or marks an TArray or TTuple as immutable <code>readonly T[]</code>.</p>
<h2>Example</h2>
<p>When applied to a Object, each property of the Object will be marked as <code>TReadonly&lt;T&gt;</code></p>
<pre><code class="language-typescript">const T = Type.Object({ // const T = TObject&lt;{
Expand All @@ -8,7 +8,7 @@ <h2>Example</h2>
z: Type.Number() // z: TNumber,
}) // }&gt;

const S = Type.ReadonlyType(T) // const S: TObject&lt;{
const S = Type.ReadonlyObject(T) // const S: TObject&lt;{
// x: TReadonly&lt;TNumber&gt;,
// y: TReadonly&lt;TNumber&gt;,
// z: TReadonly&lt;TNumber&gt;
Expand All @@ -20,7 +20,7 @@ <h2>Example</h2>
Type.String(), // TString
]) // ]&gt;&gt;

const S = Type.ReadonlyType(T) // const S: TImmutable&lt;TTuple&lt;[
const S = Type.ReadonlyObject(T) // const S: TImmutable&lt;TTuple&lt;[
// TNumber,
// TString
// }&gt;&gt;
Expand Down
2 changes: 1 addition & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"partial": "docs/type/partial.html",
"pick": "docs/type/pick.html",
"promise": "docs/type/promise.html",
"readonly-type": "docs/type/readonly-type.html",
"readonly-object": "docs/type/readonly-object.html",
"readonly": "docs/type/readonly.html",
"record": "docs/type/record.html",
"ref": "docs/type/ref.html",
Expand Down
7 changes: 3 additions & 4 deletions src/type/action/awaited.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ THE SOFTWARE.

---------------------------------------------------------------------------*/

// deno-lint-ignore-file ban-types
// deno-fmt-ignore-file

import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
import { type TDeferred, Deferred } from '../types/deferred.ts'
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
import { type TAwaitedAction, AwaitedAction } from '../engine/awaited/instantiate.ts'

// ------------------------------------------------------------------
// Deferred
Expand All @@ -49,9 +48,9 @@ export function AwaitedDeferred<Type extends TSchema>(type: Type, options: TSche
// ------------------------------------------------------------------
/** Applies an Awaited action to a type. */
export type TAwaited<Type extends TSchema> = (
TInstantiate<{}, TAwaitedDeferred<Type>>
TAwaitedAction<Type>
)
/** Applies an Awaited action to a type. */
export function Awaited<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TAwaited<Type> {
return Instantiate({}, AwaitedDeferred(type, options)) as never
return AwaitedAction(type, options)
}
7 changes: 3 additions & 4 deletions src/type/action/capitalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ THE SOFTWARE.

---------------------------------------------------------------------------*/

// deno-lint-ignore-file ban-types
// deno-fmt-ignore-file

import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
import { type TDeferred, Deferred } from '../types/deferred.ts'
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
import { type TCapitalizeAction, CapitalizeAction } from '../engine/intrinsics/instantiate.ts'

// ------------------------------------------------------------------
// Deferred
Expand All @@ -49,9 +48,9 @@ export function CapitalizeDeferred<Type extends TSchema>(type: Type, options: TS
// ------------------------------------------------------------------
/** Applies a Capitalize action to the given type. */
export type TCapitalize<Type extends TSchema> = (
TInstantiate<{}, TCapitalizeDeferred<Type>>
TCapitalizeAction<Type>
)
/** Applies a Capitalize action to the given type. */
export function Capitalize<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TCapitalize<Type> {
return Instantiate({}, CapitalizeDeferred(type, options)) as never
return CapitalizeAction(type, options)
}
14 changes: 9 additions & 5 deletions src/type/action/conditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ THE SOFTWARE.

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

// ------------------------------------------------------------------
// Deferred
Expand All @@ -41,17 +41,21 @@ export type TConditionalDeferred<Left extends TSchema, Right extends TSchema, Tr
TDeferred<'Conditional', [Left, Right, True, False]>
)
/** Creates a deferred Conditional action. */
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> {
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> {
return Deferred('Conditional', [left, right, true_, false_], options) as never
}
// ------------------------------------------------------------------
// Type
// ------------------------------------------------------------------
/** Applies a Conditional action to the given types. */
export type TConditional<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema> = (
TInstantiate<{}, TConditionalDeferred<Left, Right, True, False>>
TConditionalAction<{}, { callstack: [] }, Left, Right, True, False>
)
/** Applies a Conditional action to the given types. */
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> {
return Instantiate({}, ConditionalDeferred(left, right, true_, false_, options)) as never
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> {
return ConditionalAction({}, { callstack: [] }, left, right, true_, false_, options)
}
7 changes: 3 additions & 4 deletions src/type/action/constructor-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ THE SOFTWARE.

---------------------------------------------------------------------------*/

// deno-lint-ignore-file ban-types
// deno-fmt-ignore-file

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

// ------------------------------------------------------------------
// Deferred
Expand All @@ -49,9 +48,9 @@ export function ConstructorParametersDeferred<Type extends TSchema>(type: Type,
// ------------------------------------------------------------------
/** Applies a ConstructorParameters action to a type. */
export type TConstructorParameters<Type extends TSchema> = (
TInstantiate<{}, TConstructorParametersDeferred<Type>>
TConstructorParametersAction<Type>
)
/** Applies a ConstructorParameters action to a type. */
export function ConstructorParameters<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TConstructorParameters<Type> {
return Instantiate({}, ConstructorParametersDeferred(type, options)) as never
return ConstructorParametersAction(type, options)
}
7 changes: 3 additions & 4 deletions src/type/action/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ THE SOFTWARE.

---------------------------------------------------------------------------*/

// deno-lint-ignore-file ban-types
// deno-fmt-ignore-file

import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
import { type TDeferred, Deferred } from '../types/deferred.ts'
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
import { type TEvaluateAction, EvaluateAction } from '../engine/evaluate/instantiate.ts'

// ------------------------------------------------------------------
// Deferred
Expand All @@ -49,9 +48,9 @@ export function EvaluateDeferred<Type extends TSchema>(type: Type, options: TSch
// ------------------------------------------------------------------
/** Applies an Evaluate action to a type. */
export type TEvaluate<Type extends TSchema> = (
TInstantiate<{}, TEvaluateDeferred<Type>>
TEvaluateAction<Type>
)
/** Applies an Evaluate action to a type. */
export function Evaluate<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TEvaluate<Type> {
return Instantiate({}, EvaluateDeferred(type, options)) as never
return EvaluateAction(type, options)
}
7 changes: 3 additions & 4 deletions src/type/action/exclude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ THE SOFTWARE.

---------------------------------------------------------------------------*/

// deno-lint-ignore-file ban-types
// deno-fmt-ignore-file

import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
import { type TDeferred, Deferred } from '../types/deferred.ts'
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
import { type TExcludeAction, ExcludeAction } from '../engine/exclude/instantiate.ts'

// ------------------------------------------------------------------
// Deferred
Expand All @@ -49,9 +48,9 @@ export function ExcludeDeferred<Left extends TSchema, Right extends TSchema>(lef
// ------------------------------------------------------------------
/** Applies a Exclude action using the given types */
export type TExclude<Left extends TSchema, Right extends TSchema> = (
TInstantiate<{}, TExcludeDeferred<Left, Right>>
TExcludeAction<Left, Right>
)
/** Applies a Exclude action using the given types */
export function Exclude<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options: TSchemaOptions = {}): TExclude<Left, Right> {
return Instantiate({}, ExcludeDeferred(left, right, options)) as never
return ExcludeAction(left, right, options)
}
7 changes: 3 additions & 4 deletions src/type/action/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ THE SOFTWARE.

---------------------------------------------------------------------------*/

// deno-lint-ignore-file ban-types
// deno-fmt-ignore-file

import { type TSchema, type TSchemaOptions } from '../types/schema.ts'
import { type TDeferred, Deferred } from '../types/deferred.ts'
import { type TInstantiate, Instantiate } from '../engine/instantiate.ts'
import { type TExtractAction, ExtractAction } from '../engine/extract/instantiate.ts'

// ------------------------------------------------------------------
// Deferred
Expand All @@ -49,9 +48,9 @@ export function ExtractDeferred<Left extends TSchema, Right extends TSchema>(lef
// ------------------------------------------------------------------
/** Applies an Extract action using the given types. */
export type TExtract<Left extends TSchema, Right extends TSchema> = (
TInstantiate<{}, TExtractDeferred<Left, Right>>
TExtractAction<Left, Right>
)
/** Applies an Extract action using the given types. */
export function Extract<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options: TSchemaOptions = {}): TExtract<Left, Right> {
return Instantiate({}, ExtractDeferred(left, right, options)) as never
return ExtractAction(left, right, options)
}
2 changes: 1 addition & 1 deletion src/type/action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export * from './options.ts'
export * from './parameters.ts'
export * from './partial.ts'
export * from './pick.ts'
export * from './readonly-type.ts'
export * from './readonly-object.ts'
export * from './required.ts'
export * from './return-type.ts'
export * from './uncapitalize.ts'
Expand Down
9 changes: 4 additions & 5 deletions src/type/action/indexed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ THE SOFTWARE.

---------------------------------------------------------------------------*/

// deno-lint-ignore-file ban-types
// deno-fmt-ignore-file

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

// ------------------------------------------------------------------
// Deferred
Expand All @@ -51,14 +50,14 @@ export function IndexDeferred<Type extends TSchema, Indexer extends TSchema>(typ
// ------------------------------------------------------------------
/** Applies a Index action using the given types. */
export type TIndex<Type extends TSchema, Indexer extends TSchema> = (
TInstantiate<{}, TIndexDeferred<Type, Indexer>>
TIndexAction<Type, Indexer>
)
/** Applies a Index action using the given types. */
export function Index<Type extends TSchema, Indexer extends PropertyKey[]>(type: Type, indexer: readonly [...Indexer], options?: TSchemaOptions): TIndex<Type, TKeysToIndexer<Indexer>>
/** Applies a Index action using the given types. */
export function Index<Type extends TSchema, Indexer extends TSchema>(type: Type, indexer: Indexer, options?: TSchemaOptions): TIndex<Type, Indexer>
export function Index<Type extends TSchema, Indexer extends TSchema>(type: Type, indexer: Indexer, options?: TSchemaOptions): TIndex<Type, Indexer>
/** Applies a Index action using the given types. */
export function Index(type: TSchema, indexer_or_keys: PropertyKey[] | TSchema, options: TSchemaOptions = {}): never {
const indexer = Guard.IsArray(indexer_or_keys) ? KeysToIndexer(indexer_or_keys as PropertyKey[]) : indexer_or_keys
return Instantiate({}, IndexDeferred(type, indexer, options)) as never
return IndexAction(type, indexer, options) as never
}
7 changes: 3 additions & 4 deletions src/type/action/instance-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ THE SOFTWARE.

---------------------------------------------------------------------------*/

// deno-lint-ignore-file ban-types
// deno-fmt-ignore-file

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

// ------------------------------------------------------------------
// Deferred
Expand All @@ -49,9 +48,9 @@ export function InstanceTypeDeferred<Type extends TSchema>(type: Type, options:
// ------------------------------------------------------------------
/** Applies a InstanceType action to the given type. */
export type TInstanceType<Type extends TSchema> = (
TInstantiate<{}, TInstanceTypeDeferred<Type>>
TInstanceTypeAction<Type>
)
/** Applies a InstanceType action to the given type. */
export function InstanceType<Type extends TSchema>(type: Type, options: TSchemaOptions = {}): TInstanceType<Type> {
return Instantiate({}, InstanceTypeDeferred(type, options)) as never
return InstanceTypeAction(type, options)
}
Loading
Loading