typebox 1.0.35 → 1.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/schema/build.d.mts +6 -6
- package/build/schema/check.d.mts +3 -3
- package/build/schema/deref/deref.d.mts +1 -1
- package/build/schema/deref/deref.mjs +2 -2
- package/build/schema/engine/_context.d.mts +7 -7
- package/build/schema/engine/_functions.d.mts +1 -1
- package/build/schema/engine/_reducer.d.mts +1 -1
- package/build/schema/engine/ref.mjs +3 -3
- package/build/schema/engine/schema.d.mts +3 -3
- package/build/schema/engine/schema.mjs +4 -4
- package/build/schema/errors.d.mts +3 -3
- package/build/schema/schema.d.mts +1 -0
- package/build/schema/schema.mjs +1 -0
- package/build/schema/static/additionalProperties.d.mts +7 -0
- package/build/schema/static/allOf.d.mts +3 -0
- package/build/schema/static/allOf.mjs +2 -0
- package/build/schema/static/anyOf.d.mts +3 -0
- package/build/schema/static/anyOf.mjs +2 -0
- package/build/schema/static/const.d.mts +1 -0
- package/build/schema/static/const.mjs +2 -0
- package/build/schema/static/enum.d.mts +1 -0
- package/build/schema/static/enum.mjs +2 -0
- package/build/schema/static/index.d.mts +1 -0
- package/build/schema/static/index.mjs +1 -0
- package/build/schema/static/items.d.mts +6 -0
- package/build/schema/static/items.mjs +2 -0
- package/build/schema/static/oneOf.d.mts +3 -0
- package/build/schema/static/oneOf.mjs +2 -0
- package/build/schema/static/patternProperties.d.mts +7 -0
- package/build/schema/static/patternProperties.mjs +2 -0
- package/build/schema/static/prefixItems.d.mts +3 -0
- package/build/schema/static/prefixItems.mjs +2 -0
- package/build/schema/static/properties.d.mts +11 -0
- package/build/schema/static/properties.mjs +2 -0
- package/build/schema/static/required.d.mts +13 -0
- package/build/schema/static/required.mjs +2 -0
- package/build/schema/static/schema.d.mts +48 -0
- package/build/schema/static/schema.mjs +2 -0
- package/build/schema/static/static.d.mts +5 -0
- package/build/schema/static/static.mjs +2 -0
- package/build/schema/static/type.d.mts +4 -0
- package/build/schema/static/type.mjs +2 -0
- package/build/schema/static/unevaluatedProperties.d.mts +7 -0
- package/build/schema/static/unevaluatedProperties.mjs +2 -0
- package/build/schema/static/~mutable.d.mts +7 -0
- package/build/schema/static/~mutable.mjs +2 -0
- package/build/schema/static/~readonly.d.mts +6 -0
- package/build/schema/static/~readonly.mjs +2 -0
- package/build/schema/types/_guard.d.mts +2 -2
- package/build/schema/types/_refine.d.mts +2 -2
- package/build/schema/types/additionalItems.d.mts +3 -3
- package/build/schema/types/additionalItems.mjs +2 -2
- package/build/schema/types/additionalProperties.d.mts +3 -3
- package/build/schema/types/additionalProperties.mjs +2 -2
- package/build/schema/types/allOf.d.mts +3 -3
- package/build/schema/types/allOf.mjs +2 -2
- package/build/schema/types/anyOf.d.mts +3 -3
- package/build/schema/types/anyOf.mjs +2 -2
- package/build/schema/types/const.d.mts +2 -2
- package/build/schema/types/contains.d.mts +3 -3
- package/build/schema/types/contains.mjs +2 -2
- package/build/schema/types/contentEncoding.d.mts +2 -2
- package/build/schema/types/contentMediaType.d.mts +2 -2
- package/build/schema/types/default.d.mts +2 -2
- package/build/schema/types/defs.d.mts +3 -3
- package/build/schema/types/defs.mjs +2 -2
- package/build/schema/types/dependencies.d.mts +2 -2
- package/build/schema/types/dependencies.mjs +2 -2
- package/build/schema/types/dependentRequired.d.mts +2 -2
- package/build/schema/types/dependentSchemas.d.mts +3 -3
- package/build/schema/types/dependentSchemas.mjs +2 -2
- package/build/schema/types/else.d.mts +3 -3
- package/build/schema/types/else.mjs +2 -2
- package/build/schema/types/enum.d.mts +2 -2
- package/build/schema/types/exclusiveMaximum.d.mts +2 -2
- package/build/schema/types/exclusiveMinimum.d.mts +2 -2
- package/build/schema/types/format.d.mts +2 -2
- package/build/schema/types/id.d.mts +2 -2
- package/build/schema/types/if.d.mts +3 -3
- package/build/schema/types/if.mjs +2 -2
- package/build/schema/types/index.d.mts +0 -1
- package/build/schema/types/index.mjs +0 -1
- package/build/schema/types/items.d.mts +7 -7
- package/build/schema/types/items.mjs +3 -3
- package/build/schema/types/maxContains.d.mts +2 -2
- package/build/schema/types/maxItems.d.mts +2 -2
- package/build/schema/types/maxLength.d.mts +2 -2
- package/build/schema/types/maxProperties.d.mts +2 -2
- package/build/schema/types/maximum.d.mts +2 -2
- package/build/schema/types/minContains.d.mts +2 -2
- package/build/schema/types/minItems.d.mts +2 -2
- package/build/schema/types/minLength.d.mts +2 -2
- package/build/schema/types/minProperties.d.mts +2 -2
- package/build/schema/types/minimum.d.mts +2 -2
- package/build/schema/types/multipleOf.d.mts +2 -2
- package/build/schema/types/not.d.mts +3 -3
- package/build/schema/types/not.mjs +2 -2
- package/build/schema/types/oneOf.d.mts +3 -3
- package/build/schema/types/oneOf.mjs +2 -2
- package/build/schema/types/pattern.d.mts +2 -2
- package/build/schema/types/patternProperties.d.mts +3 -3
- package/build/schema/types/patternProperties.mjs +2 -2
- package/build/schema/types/prefixItems.d.mts +3 -3
- package/build/schema/types/prefixItems.mjs +2 -2
- package/build/schema/types/properties.d.mts +3 -3
- package/build/schema/types/properties.mjs +2 -2
- package/build/schema/types/propertyNames.d.mts +3 -3
- package/build/schema/types/propertyNames.mjs +2 -2
- package/build/schema/types/ref.d.mts +2 -2
- package/build/schema/types/required.d.mts +2 -2
- package/build/schema/types/schema.d.mts +4 -4
- package/build/schema/types/schema.mjs +3 -3
- package/build/schema/types/then.d.mts +3 -3
- package/build/schema/types/then.mjs +2 -2
- package/build/schema/types/type.d.mts +2 -2
- package/build/schema/types/unevaluatedItems.d.mts +4 -4
- package/build/schema/types/unevaluatedItems.mjs +2 -2
- package/build/schema/types/unevaluatedProperties.d.mts +3 -3
- package/build/schema/types/unevaluatedProperties.mjs +2 -2
- package/build/schema/types/uniqueItems.d.mts +2 -2
- package/build/type/engine/instantiate.d.mts +2 -1
- package/build/type/engine/instantiate.mjs +5 -1
- package/build/type/extends/array.d.mts +15 -2
- package/build/type/extends/array.mjs +16 -4
- package/build/type/extends/extends-left.d.mts +1 -1
- package/build/type/extends/extends-left.mjs +1 -1
- package/build/type/extends/literal.d.mts +2 -1
- package/build/type/extends/literal.mjs +4 -1
- package/build/type/script/mapping.d.mts +2 -0
- package/build/type/script/mapping.mjs +3 -0
- package/build/type/script/parser.d.mts +3 -1
- package/build/type/script/parser.mjs +2 -1
- package/build/type/types/_immutable.d.mts +16 -0
- package/build/type/types/_immutable.mjs +26 -0
- package/build/type/types/_readonly.d.mts +2 -2
- package/build/type/types/_readonly.mjs +3 -3
- package/build/type/types/_refine.mjs +1 -1
- package/build/type/types/array.d.mts +2 -1
- package/build/type/types/base.d.mts +1 -7
- package/build/type/types/base.mjs +12 -20
- package/build/type/types/index.d.mts +1 -0
- package/build/type/types/index.mjs +1 -0
- package/build/type/types/literal.d.mts +9 -0
- package/build/type/types/literal.mjs +22 -1
- package/build/type/types/static.d.mts +3 -2
- package/build/type/types/tuple.d.mts +2 -1
- package/build/typebox.d.mts +1 -0
- package/build/typebox.mjs +1 -0
- package/package.json +28 -28
- package/readme.md +1 -1
- package/build/schema/types/static.d.mts +0 -113
- /package/build/schema/{types/static.mjs → static/additionalProperties.mjs} +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type StaticType, type StaticDirection } from './static.mjs';
|
|
2
2
|
import { type TSchema, type TArrayOptions } from './schema.mjs';
|
|
3
|
+
import { type TImmutable } from './_immutable.mjs';
|
|
3
4
|
import { type TProperties } from './properties.mjs';
|
|
4
|
-
export type StaticArray<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties,
|
|
5
|
+
export type StaticArray<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Array extends TSchema, Item extends TSchema, Result extends readonly unknown[] = Array extends TImmutable ? readonly StaticType<Stack, Direction, Context, This, Item>[] : StaticType<Stack, Direction, Context, This, Item>[]> = Result;
|
|
5
6
|
/** Represents an Array type. */
|
|
6
7
|
export interface TArray<Type extends TSchema = TSchema> extends TSchema {
|
|
7
8
|
'~kind': 'Array';
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { type TSchema } from './schema.mjs';
|
|
2
2
|
import { type XGuard, type XGuardInterface } from '../../schema/types/index.mjs';
|
|
3
|
-
export
|
|
4
|
-
readonly cause: {
|
|
5
|
-
type: Base;
|
|
6
|
-
method: string;
|
|
7
|
-
};
|
|
8
|
-
constructor(type: Base, method: string);
|
|
9
|
-
}
|
|
3
|
+
export type StaticBase<Value extends unknown> = Value;
|
|
10
4
|
/** Base class for creating extension types. */
|
|
11
5
|
export declare class Base<Value extends unknown = unknown> implements TSchema, XGuard<Value> {
|
|
12
6
|
readonly '~kind': 'Base';
|
|
@@ -2,35 +2,27 @@
|
|
|
2
2
|
import { Settings } from '../../system/settings/index.mjs';
|
|
3
3
|
import { IsKind } from './schema.mjs';
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
|
-
// NotImplemented
|
|
6
|
-
// ------------------------------------------------------------------
|
|
7
|
-
export class NotImplemented extends Error {
|
|
8
|
-
constructor(type, method) {
|
|
9
|
-
super(`Base type does not implement the '${method}' function`);
|
|
10
|
-
Object.defineProperty(this, 'cause', {
|
|
11
|
-
value: { type, method },
|
|
12
|
-
writable: false,
|
|
13
|
-
configurable: false,
|
|
14
|
-
enumerable: false
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
// ------------------------------------------------------------------
|
|
19
5
|
// Type.Base<...>
|
|
20
6
|
// ------------------------------------------------------------------
|
|
21
7
|
/** Base class for creating extension types. */
|
|
22
8
|
export class Base {
|
|
23
9
|
constructor() {
|
|
24
|
-
|
|
10
|
+
const configuration = {
|
|
25
11
|
enumerable: Settings.Get().enumerableKind,
|
|
26
12
|
writable: false,
|
|
27
13
|
configurable: false,
|
|
14
|
+
};
|
|
15
|
+
globalThis.Object.defineProperty(this, '~kind', {
|
|
16
|
+
...configuration,
|
|
28
17
|
value: 'Base'
|
|
29
18
|
});
|
|
30
|
-
this
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
globalThis.Object.defineProperty(this, '~guard', {
|
|
20
|
+
...configuration,
|
|
21
|
+
value: {
|
|
22
|
+
check: (value) => this.Check(value),
|
|
23
|
+
errors: (value) => this.Errors(value)
|
|
24
|
+
}
|
|
25
|
+
});
|
|
34
26
|
}
|
|
35
27
|
/** Checks a value or returns false if invalid */
|
|
36
28
|
Check(value) {
|
|
@@ -54,7 +46,7 @@ export class Base {
|
|
|
54
46
|
}
|
|
55
47
|
/** Creates a new instance of this type */
|
|
56
48
|
Create() {
|
|
57
|
-
throw new
|
|
49
|
+
throw new Error('Create not implemented');
|
|
58
50
|
}
|
|
59
51
|
}
|
|
60
52
|
// ------------------------------------------------------------------
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { type TSchema, type TSchemaOptions } from './schema.mjs';
|
|
2
|
+
export declare class InvalidLiteralValue extends Error {
|
|
3
|
+
readonly cause: {
|
|
4
|
+
value: unknown;
|
|
5
|
+
};
|
|
6
|
+
constructor(value: unknown);
|
|
7
|
+
}
|
|
2
8
|
export type StaticLiteral<Value extends TLiteralValue> = (Value);
|
|
9
|
+
export type TLiteralTypeName<Value extends TLiteralValue> = (Value extends bigint ? 'bigint' : Value extends boolean ? 'boolean' : Value extends number ? 'number' : Value extends string ? 'string' : never);
|
|
10
|
+
export declare function LiteralTypeName<Value extends TLiteralValue>(value: Value): TLiteralTypeName<Value>;
|
|
3
11
|
export type TLiteralValue = string | number | boolean | bigint;
|
|
4
12
|
/** Represents a Literal type. */
|
|
5
13
|
export interface TLiteral<Value extends TLiteralValue = TLiteralValue> extends TSchema {
|
|
6
14
|
'~kind': 'Literal';
|
|
15
|
+
type: TLiteralTypeName<Value>;
|
|
7
16
|
const: Value;
|
|
8
17
|
}
|
|
9
18
|
/** Creates a Literal type. */
|
|
@@ -3,11 +3,32 @@ import { Memory } from '../../system/memory/index.mjs';
|
|
|
3
3
|
import { Guard } from '../../guard/index.mjs';
|
|
4
4
|
import { IsKind } from './schema.mjs';
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
+
// InvalidLiteralValue
|
|
7
|
+
// ------------------------------------------------------------------
|
|
8
|
+
export class InvalidLiteralValue extends Error {
|
|
9
|
+
constructor(value) {
|
|
10
|
+
super(`Invalid Literal value`);
|
|
11
|
+
Object.defineProperty(this, 'cause', {
|
|
12
|
+
value: { value },
|
|
13
|
+
writable: false,
|
|
14
|
+
configurable: false,
|
|
15
|
+
enumerable: false
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function LiteralTypeName(value) {
|
|
20
|
+
return (Guard.IsBigInt(value) ? 'bigint' :
|
|
21
|
+
Guard.IsBoolean(value) ? 'boolean' :
|
|
22
|
+
Guard.IsNumber(value) ? 'number' :
|
|
23
|
+
Guard.IsString(value) ? 'string' :
|
|
24
|
+
(() => { throw new InvalidLiteralValue(value); })());
|
|
25
|
+
}
|
|
26
|
+
// ------------------------------------------------------------------
|
|
6
27
|
// Factory
|
|
7
28
|
// ------------------------------------------------------------------
|
|
8
29
|
/** Creates a Literal type. */
|
|
9
30
|
export function Literal(value, options) {
|
|
10
|
-
return Memory.Create({ '~kind': 'Literal' }, { const: value }, options);
|
|
31
|
+
return Memory.Create({ '~kind': 'Literal' }, { type: LiteralTypeName(value), const: value }, options);
|
|
11
32
|
}
|
|
12
33
|
// ------------------------------------------------------------------
|
|
13
34
|
// Guards
|
|
@@ -2,6 +2,7 @@ import type { StaticCodec, TCodec } from './_codec.mjs';
|
|
|
2
2
|
import type { StaticAny, TAny } from './any.mjs';
|
|
3
3
|
import type { StaticArray, TArray } from './array.mjs';
|
|
4
4
|
import type { StaticAsyncIterator, TAsyncIterator } from './async-iterator.mjs';
|
|
5
|
+
import type { StaticBase, Base } from './base.mjs';
|
|
5
6
|
import type { StaticBigInt, TBigInt } from './bigint.mjs';
|
|
6
7
|
import type { StaticBoolean, TBoolean } from './boolean.mjs';
|
|
7
8
|
import type { StaticConstructor, TConstructor } from './constructor.mjs';
|
|
@@ -31,12 +32,12 @@ import type { StaticUnion, TUnion } from './union.mjs';
|
|
|
31
32
|
import type { StaticUnknown, TUnknown } from './unknown.mjs';
|
|
32
33
|
import type { StaticUnsafe, TUnsafe } from './unsafe.mjs';
|
|
33
34
|
import type { StaticVoid, TVoid } from './void.mjs';
|
|
34
|
-
import type { XStatic } from '../../schema/
|
|
35
|
+
import type { XStatic } from '../../schema/static/static.mjs';
|
|
35
36
|
export type StaticEvaluate<T> = {
|
|
36
37
|
[K in keyof T]: T[K];
|
|
37
38
|
} & {};
|
|
38
39
|
export type StaticDirection = 'Encode' | 'Decode';
|
|
39
|
-
export type StaticType<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema> = (Type extends TCodec<infer Type extends TSchema, infer Decoded extends unknown> ? StaticCodec<Stack, Direction, Context, This, Type, Decoded> : Type extends TAny ? StaticAny : Type extends TArray<infer
|
|
40
|
+
export type StaticType<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema> = (Type extends TCodec<infer Type extends TSchema, infer Decoded extends unknown> ? StaticCodec<Stack, Direction, Context, This, Type, Decoded> : Type extends TAny ? StaticAny : Type extends TArray<infer Items extends TSchema> ? StaticArray<Stack, Direction, Context, This, Type, Items> : Type extends TAsyncIterator<infer Type extends TSchema> ? StaticAsyncIterator<Stack, Direction, Context, This, Type> : Type extends Base<infer Value extends unknown> ? StaticBase<Value> : Type extends TBigInt ? StaticBigInt : Type extends TBoolean ? StaticBoolean : Type extends TConstructor<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticConstructor<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TEnum<infer Values extends TEnumValue[]> ? StaticEnum<Values> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticFunction<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TInteger ? StaticInteger : Type extends TIntersect<infer Types extends TSchema[]> ? StaticIntersect<Stack, Direction, Context, This, Types> : Type extends TIterator<infer Types extends TSchema> ? StaticIterator<Stack, Direction, Context, This, Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? StaticLiteral<Value> : Type extends TNever ? StaticNever : Type extends TNull ? StaticNull : Type extends TNumber ? StaticNumber : Type extends TObject<infer Properties extends TProperties> ? StaticObject<Stack, Direction, Context, This, Properties> : Type extends TPromise<infer Type extends TSchema> ? StaticPromise<Stack, Direction, Context, This, Type> : Type extends TRecord<infer Key extends string, infer Value extends TSchema> ? StaticRecord<Stack, Direction, Context, This, Key, Value> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? StaticCyclic<Stack, Direction, Context, This, Defs, Ref> : Type extends TRef<infer Ref extends string> ? StaticRef<Stack, Direction, Context, This, Ref> : Type extends TString ? StaticString : Type extends TSymbol ? StaticSymbol : Type extends TTemplateLiteral<infer Pattern extends string> ? StaticTemplateLiteral<Pattern> : Type extends TThis ? StaticThis<Stack, Direction, Context, This> : Type extends TTuple<infer Items extends TSchema[]> ? StaticTuple<Stack, Direction, Context, This, Type, Items> : Type extends TUndefined ? StaticUndefined : Type extends TUnion<infer Types extends TSchema[]> ? StaticUnion<Stack, Direction, Context, This, Types> : Type extends TUnknown ? StaticUnknown : Type extends TUnsafe<infer Type extends unknown> ? StaticUnsafe<Type> : Type extends TVoid ? StaticVoid : XStatic<Type>);
|
|
40
41
|
/** Infers a static type from a TypeBox type using Parse logic. */
|
|
41
42
|
export type StaticParse<Type extends TSchema, Context extends TProperties = {}> = StaticType<[], 'Decode', Context, {}, Type>;
|
|
42
43
|
/** Infers a static type from a TypeBox type using Decode logic. */
|
|
@@ -3,6 +3,7 @@ import { type TSchema, type TTupleOptions } from './schema.mjs';
|
|
|
3
3
|
import { type TArray } from './array.mjs';
|
|
4
4
|
import { type TOptional } from './_optional.mjs';
|
|
5
5
|
import { type TProperties } from './properties.mjs';
|
|
6
|
+
import { type TImmutable } from './_immutable.mjs';
|
|
6
7
|
import { type TReadonly } from './_readonly.mjs';
|
|
7
8
|
import { type TRest } from './rest.mjs';
|
|
8
9
|
type StaticLast<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result extends unknown[]> = (Type extends TRest<infer RestType extends TSchema> ? RestType extends TArray<infer ArrayType extends TSchema> ? [...Result, ...TStaticElement<Stack, Direction, Context, This, ArrayType>[0][]] : [...Result, never] : [...Result, ...TStaticElement<Stack, Direction, Context, This, Type>]);
|
|
@@ -19,7 +20,7 @@ type TStaticElement<Stack extends string[], Direction extends StaticDirection, C
|
|
|
19
20
|
Inferred
|
|
20
21
|
])> = Result;
|
|
21
22
|
export type TStaticElements<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer Last extends TSchema] ? StaticLast<Stack, Direction, Context, This, Last, Result> : Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TStaticElements<Stack, Direction, Context, This, Right, [...Result, ...TStaticElement<Stack, Direction, Context, This, Left>]> : Result);
|
|
22
|
-
export type StaticTuple<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties,
|
|
23
|
+
export type StaticTuple<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Tuple extends TSchema, Items extends TSchema[], Elements extends unknown[] = TStaticElements<Stack, Direction, Context, This, Items>, Result extends readonly unknown[] = (Tuple extends TImmutable ? readonly [...Elements] : Elements)> = Result;
|
|
23
24
|
/** Represents a Tuple type. */
|
|
24
25
|
export interface TTuple<Types extends TSchema[] = TSchema[]> extends TSchema {
|
|
25
26
|
'~kind': 'Tuple';
|
package/build/typebox.d.mts
CHANGED
|
@@ -26,6 +26,7 @@ export { ReturnType, type TReturnType, type TReturnTypeDeferred } from './type/a
|
|
|
26
26
|
export { type TUncapitalize, type TUncapitalizeDeferred, Uncapitalize } from './type/action/uncapitalize.mjs';
|
|
27
27
|
export { type TUppercase, type TUppercaseDeferred, Uppercase } from './type/action/uppercase.mjs';
|
|
28
28
|
export { Codec, Decode, DecodeBuilder, Encode, EncodeBuilder, IsCodec, type TCodec } from './type/types/_codec.mjs';
|
|
29
|
+
export { Immutable, IsImmutable, type TImmutable } from './type/types/_immutable.mjs';
|
|
29
30
|
export { IsOptional, Optional, type TOptional } from './type/types/_optional.mjs';
|
|
30
31
|
export { IsReadonly, Readonly, type TReadonly } from './type/types/_readonly.mjs';
|
|
31
32
|
export { IsRefine, Refine, type TRefine, type TRefineCallback, type TRefinement } from './type/types/_refine.mjs';
|
package/build/typebox.mjs
CHANGED
|
@@ -41,6 +41,7 @@ export { Uppercase } from './type/action/uppercase.mjs';
|
|
|
41
41
|
// Extension
|
|
42
42
|
// ------------------------------------------------------------------
|
|
43
43
|
export { Codec, Decode, DecodeBuilder, Encode, EncodeBuilder, IsCodec } from './type/types/_codec.mjs';
|
|
44
|
+
export { Immutable, IsImmutable } from './type/types/_immutable.mjs';
|
|
44
45
|
export { IsOptional, Optional } from './type/types/_optional.mjs';
|
|
45
46
|
export { IsReadonly, Readonly } from './type/types/_readonly.mjs';
|
|
46
47
|
export { IsRefine, Refine } from './type/types/_refine.mjs';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typebox",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "1.0.
|
|
3
|
+
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
|
|
4
|
+
"version": "1.0.37",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
7
7
|
"jsonschema"
|
|
@@ -16,38 +16,38 @@
|
|
|
16
16
|
"types": "./build/index.d.mts",
|
|
17
17
|
"module": "./build/index.mjs",
|
|
18
18
|
"exports": {
|
|
19
|
-
"./
|
|
20
|
-
"import": "./build/
|
|
21
|
-
"default": "./build/
|
|
19
|
+
"./error": {
|
|
20
|
+
"import": "./build/error/index.mjs",
|
|
21
|
+
"default": "./build/error/index.mjs"
|
|
22
22
|
},
|
|
23
23
|
"./schema": {
|
|
24
24
|
"import": "./build/schema/index.mjs",
|
|
25
25
|
"default": "./build/schema/index.mjs"
|
|
26
26
|
},
|
|
27
|
-
"./value": {
|
|
28
|
-
"import": "./build/value/index.mjs",
|
|
29
|
-
"default": "./build/value/index.mjs"
|
|
30
|
-
},
|
|
31
27
|
"./format": {
|
|
32
28
|
"import": "./build/format/index.mjs",
|
|
33
29
|
"default": "./build/format/index.mjs"
|
|
34
30
|
},
|
|
31
|
+
"./compile": {
|
|
32
|
+
"import": "./build/compile/index.mjs",
|
|
33
|
+
"default": "./build/compile/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./guard": {
|
|
36
|
+
"import": "./build/guard/index.mjs",
|
|
37
|
+
"default": "./build/guard/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./value": {
|
|
40
|
+
"import": "./build/value/index.mjs",
|
|
41
|
+
"default": "./build/value/index.mjs"
|
|
42
|
+
},
|
|
35
43
|
"./type": {
|
|
36
44
|
"import": "./build/type/index.mjs",
|
|
37
45
|
"default": "./build/type/index.mjs"
|
|
38
46
|
},
|
|
39
|
-
"./error": {
|
|
40
|
-
"import": "./build/error/index.mjs",
|
|
41
|
-
"default": "./build/error/index.mjs"
|
|
42
|
-
},
|
|
43
47
|
"./system": {
|
|
44
48
|
"import": "./build/system/index.mjs",
|
|
45
49
|
"default": "./build/system/index.mjs"
|
|
46
50
|
},
|
|
47
|
-
"./compile": {
|
|
48
|
-
"import": "./build/compile/index.mjs",
|
|
49
|
-
"default": "./build/compile/index.mjs"
|
|
50
|
-
},
|
|
51
51
|
".": {
|
|
52
52
|
"import": "./build/index.mjs",
|
|
53
53
|
"default": "./build/index.mjs"
|
|
@@ -55,30 +55,30 @@
|
|
|
55
55
|
},
|
|
56
56
|
"typesVersions": {
|
|
57
57
|
"*": {
|
|
58
|
-
"
|
|
59
|
-
"./build/
|
|
58
|
+
"error": [
|
|
59
|
+
"./build/error/index.d.mts"
|
|
60
60
|
],
|
|
61
61
|
"schema": [
|
|
62
62
|
"./build/schema/index.d.mts"
|
|
63
63
|
],
|
|
64
|
-
"value": [
|
|
65
|
-
"./build/value/index.d.mts"
|
|
66
|
-
],
|
|
67
64
|
"format": [
|
|
68
65
|
"./build/format/index.d.mts"
|
|
69
66
|
],
|
|
67
|
+
"compile": [
|
|
68
|
+
"./build/compile/index.d.mts"
|
|
69
|
+
],
|
|
70
|
+
"guard": [
|
|
71
|
+
"./build/guard/index.d.mts"
|
|
72
|
+
],
|
|
73
|
+
"value": [
|
|
74
|
+
"./build/value/index.d.mts"
|
|
75
|
+
],
|
|
70
76
|
"type": [
|
|
71
77
|
"./build/type/index.d.mts"
|
|
72
78
|
],
|
|
73
|
-
"error": [
|
|
74
|
-
"./build/error/index.d.mts"
|
|
75
|
-
],
|
|
76
79
|
"system": [
|
|
77
80
|
"./build/system/index.d.mts"
|
|
78
81
|
],
|
|
79
|
-
"compile": [
|
|
80
|
-
"./build/compile/index.d.mts"
|
|
81
|
-
],
|
|
82
82
|
".": [
|
|
83
83
|
"./build/index.d.mts"
|
|
84
84
|
]
|
package/readme.md
CHANGED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { XGuard } from './_guard.mjs';
|
|
2
|
-
import type { XSchemaLike } from './schema.mjs';
|
|
3
|
-
import type { XAdditionalProperties } from './additionalProperties.mjs';
|
|
4
|
-
import type { XAnyOf } from './anyOf.mjs';
|
|
5
|
-
import type { XAllOf } from './allOf.mjs';
|
|
6
|
-
import type { XConst } from './const.mjs';
|
|
7
|
-
import type { XEnum } from './enum.mjs';
|
|
8
|
-
import type { XItems } from './items.mjs';
|
|
9
|
-
import type { XOneOf } from './oneOf.mjs';
|
|
10
|
-
import type { XPatternProperties } from './patternProperties.mjs';
|
|
11
|
-
import type { XPrefixItems } from './prefixItems.mjs';
|
|
12
|
-
import type { XProperties } from './properties.mjs';
|
|
13
|
-
import type { XRequired } from './required.mjs';
|
|
14
|
-
export type XStaticBase<Value extends unknown> = Value;
|
|
15
|
-
type XStaticAdditionalProperties<Schema extends XSchemaLike, Result extends Record<PropertyKey, unknown> = (Schema extends true ? {
|
|
16
|
-
[key: string]: unknown;
|
|
17
|
-
} : Schema extends false ? {} : {
|
|
18
|
-
[key: string]: XStaticType<Schema>;
|
|
19
|
-
})> = Result;
|
|
20
|
-
type XStaticAllOf<Schemas extends XSchemaLike[], Result extends unknown = unknown> = Schemas extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticAllOf<Right, XStaticType<Left> & Result> : Result;
|
|
21
|
-
type XStaticAnyOf<Schemas extends XSchemaLike[], Result extends unknown = never> = Schemas extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticAnyOf<Right, XStaticType<Left> | Result> : Result;
|
|
22
|
-
type XStaticConst<Value extends unknown> = Value;
|
|
23
|
-
type XStaticEnum<Values extends unknown[], Result extends unknown = never> = Values extends [infer Left extends unknown, ...infer Right extends unknown[]] ? XStaticEnum<Right, Left | Result> : Result;
|
|
24
|
-
type XStaticItemsUnsized<Schema extends XSchemaLike> = XStaticType<Schema>[];
|
|
25
|
-
type XStaticItemsSized<Schema extends XSchemaLike[], Result extends unknown[] = []> = Schema extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticItemsSized<Right, [...Result, XStaticType<Left>]> : Result;
|
|
26
|
-
type XStaticItems<Schemas extends XSchemaLike[] | XSchemaLike, Result extends unknown = (Schemas extends XSchemaLike[] ? XStaticItemsSized<[...Schemas]> : Schemas extends XSchemaLike ? XStaticItemsUnsized<Schemas> : never)> = Result;
|
|
27
|
-
type XStaticOneOf<Schemas extends XSchemaLike[], Result extends unknown = never> = Schemas extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticOneOf<Right, XStaticType<Left> | Result> : Result;
|
|
28
|
-
type XStaticPatternProperties<Properties extends Record<PropertyKey, XSchemaLike> = Record<PropertyKey, XSchemaLike>, InferredProperties extends Record<PropertyKey, unknown> = {
|
|
29
|
-
[Key in keyof Properties]: XStaticType<Properties[Key]>;
|
|
30
|
-
}, EvaluatedProperties extends unknown = {
|
|
31
|
-
[key: string]: InferredProperties[keyof InferredProperties];
|
|
32
|
-
}> = EvaluatedProperties;
|
|
33
|
-
type XStaticPrefixItems<Schemas extends XSchemaLike[], Result extends unknown[] = []> = Schemas extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticPrefixItems<Right, [...Result, XStaticType<Left>]> : Result;
|
|
34
|
-
type XStaticProperties<Properties extends Record<PropertyKey, XSchemaLike>, Readonly extends Record<PropertyKey, unknown> = {
|
|
35
|
-
readonly [Key in keyof Properties as Properties[Key] extends {
|
|
36
|
-
readOnly: true;
|
|
37
|
-
} ? Key : never]?: XStaticType<Properties[Key]>;
|
|
38
|
-
}, Standard extends Record<PropertyKey, unknown> = {
|
|
39
|
-
[Key in keyof Properties as Properties[Key] extends {
|
|
40
|
-
readOnly: true;
|
|
41
|
-
} ? never : Key]?: XStaticType<Properties[Key]>;
|
|
42
|
-
}, Result extends Record<PropertyKey, unknown> = Readonly & Standard> = Result;
|
|
43
|
-
type RequiredSelectProperty<Properties extends Record<PropertyKey, XSchemaLike>, Key extends string, Result extends Record<PropertyKey, unknown> = (Key extends keyof Properties ? Properties[Key] extends {
|
|
44
|
-
readOnly: true;
|
|
45
|
-
} ? {
|
|
46
|
-
readonly [_ in Key]: XStaticType<Properties[Key]>;
|
|
47
|
-
} : {
|
|
48
|
-
[_ in Key]: XStaticType<Properties[Key]>;
|
|
49
|
-
} : {
|
|
50
|
-
[_ in Key]: unknown;
|
|
51
|
-
})> = Result;
|
|
52
|
-
type RequiredSelectProperties<Properties extends Record<PropertyKey, XSchemaLike>, Keys extends string[], Result extends Record<PropertyKey, unknown> = {}> = Keys extends [infer Left extends string, ...infer Right extends string[]] ? RequiredSelectProperties<Properties, Right, Result & RequiredSelectProperty<Properties, Left>> : Result;
|
|
53
|
-
type RequiredGetProperties<Schema extends XSchemaLike, Result extends Record<PropertyKey, unknown> = (Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchemaLike>> ? Properties : {})> = Result;
|
|
54
|
-
type XStaticRequired<Schema extends XSchemaLike, Keys extends string[], Properties extends Record<PropertyKey, XSchemaLike> = RequiredGetProperties<Schema>, Result extends Record<PropertyKey, unknown> = RequiredSelectProperties<Properties, Keys>> = Result;
|
|
55
|
-
type XStaticKeywords<Schema, Result extends unknown[] = [
|
|
56
|
-
Schema extends XAdditionalProperties<infer Type extends XSchemaLike> ? XStaticAdditionalProperties<Type> : unknown,
|
|
57
|
-
Schema extends XAllOf<infer Types extends XSchemaLike[]> ? XStaticAllOf<Types> : unknown,
|
|
58
|
-
Schema extends XAnyOf<infer Types extends XSchemaLike[]> ? XStaticAnyOf<Types> : unknown,
|
|
59
|
-
Schema extends XConst<infer Value extends unknown> ? XStaticConst<Value> : unknown,
|
|
60
|
-
Schema extends XEnum<infer Values extends unknown[]> ? XStaticEnum<Values> : unknown,
|
|
61
|
-
Schema extends XItems<infer Types extends XSchemaLike[] | XSchemaLike> ? XStaticItems<Types> : unknown,
|
|
62
|
-
Schema extends XOneOf<infer Types extends XSchemaLike[]> ? XStaticOneOf<Types> : unknown,
|
|
63
|
-
Schema extends XPatternProperties<infer Properties extends Record<PropertyKey, XSchemaLike>> ? XStaticPatternProperties<Properties> : unknown,
|
|
64
|
-
Schema extends XPrefixItems<infer Types extends XSchemaLike[]> ? XStaticPrefixItems<Types> : unknown,
|
|
65
|
-
Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchemaLike>> ? XStaticProperties<Properties> : unknown,
|
|
66
|
-
Schema extends XRequired<infer Keys extends string[]> ? XStaticRequired<Schema, Keys> : unknown,
|
|
67
|
-
Schema extends {
|
|
68
|
-
type: 'array';
|
|
69
|
-
} ? {} : unknown,
|
|
70
|
-
Schema extends {
|
|
71
|
-
type: 'bigint';
|
|
72
|
-
} ? bigint : unknown,
|
|
73
|
-
Schema extends {
|
|
74
|
-
type: 'boolean';
|
|
75
|
-
} ? boolean : unknown,
|
|
76
|
-
Schema extends {
|
|
77
|
-
type: 'integer';
|
|
78
|
-
} ? number : unknown,
|
|
79
|
-
Schema extends {
|
|
80
|
-
type: 'object';
|
|
81
|
-
} ? object : unknown,
|
|
82
|
-
Schema extends {
|
|
83
|
-
type: 'null';
|
|
84
|
-
} ? null : unknown,
|
|
85
|
-
Schema extends {
|
|
86
|
-
type: 'number';
|
|
87
|
-
} ? number : unknown,
|
|
88
|
-
Schema extends {
|
|
89
|
-
type: 'string';
|
|
90
|
-
} ? string : unknown,
|
|
91
|
-
Schema extends {
|
|
92
|
-
type: 'symbol';
|
|
93
|
-
} ? symbol : unknown,
|
|
94
|
-
Schema extends {
|
|
95
|
-
type: 'undefined';
|
|
96
|
-
} ? undefined : unknown
|
|
97
|
-
]> = Result;
|
|
98
|
-
type XStaticKeywordIntersect<Schemas extends unknown[], Result extends unknown = unknown> = (Schemas extends [infer Left extends unknown, ...infer Right extends unknown[]] ? XStaticKeywordIntersect<Right, Result & Left> : Result);
|
|
99
|
-
type XStaticEvaluate<Schema extends unknown, Result extends unknown = Schema extends object ? {
|
|
100
|
-
[Key in keyof Schema]: Schema[Key];
|
|
101
|
-
} : Schema> = Result;
|
|
102
|
-
type XStaticJsonSchema<Schema extends unknown, Keywords extends unknown[] = XStaticKeywords<Schema>, Intersect extends unknown = XStaticKeywordIntersect<Keywords>, Result extends unknown = XStaticEvaluate<Intersect>> = Result;
|
|
103
|
-
/** Statically infers a JSON Schema or Validator */
|
|
104
|
-
export type XStaticType<Schema extends XSchemaLike, Result extends unknown = (Schema extends XGuard<infer Value> ? Value : XStaticJsonSchema<Schema>)> = Result;
|
|
105
|
-
type XStaticMutableTuple<Schemas extends readonly unknown[]> = (Schemas extends [infer Left, ...infer Right extends unknown[]] ? [XStaticMutable<Left>, ...XStaticMutableTuple<Right>] : []);
|
|
106
|
-
type XStaticMutableArray<Schema extends unknown, Result extends unknown[] = XStaticMutable<Schema>[]> = Result;
|
|
107
|
-
type XStaticMutableObject<Schema extends object, Result extends Record<PropertyKey, unknown> = {
|
|
108
|
-
-readonly [K in keyof Schema]: XStaticMutable<Schema[K]>;
|
|
109
|
-
}> = Result;
|
|
110
|
-
type XStaticMutable<Schema> = (Schema extends XGuard ? Schema : Schema extends readonly [...infer Schemas extends unknown[]] ? XStaticMutableTuple<Schemas> : Schema extends readonly (infer Schema)[] ? XStaticMutableArray<Schema> : Schema extends object ? XStaticMutableObject<Schema> : Schema);
|
|
111
|
-
/** Statically infers a JSON Schema */
|
|
112
|
-
export type XStatic<Schema extends XSchemaLike, Mutable extends XSchemaLike = XStaticMutable<Schema>, Result extends unknown = XStaticType<Mutable>> = Result;
|
|
113
|
-
export {};
|
|
File without changes
|