@sinclair/typebox
Advanced tools
Comparing version 0.33.22 to 0.34.0
import { ValueErrorIterator } from '../errors/index'; | ||
import { TypeBoxError } from '../type/error/index'; | ||
import type { TSchema } from '../type/schema/index'; | ||
import type { Static, StaticDecode } from '../type/static/index'; | ||
import type { Static, StaticDecode, StaticEncode } from '../type/static/index'; | ||
export type CheckFunction = (value: unknown) => boolean; | ||
@@ -22,3 +22,3 @@ export declare class TypeCheck<T extends TSchema> { | ||
/** Encodes a value or throws if error */ | ||
Encode<Static = StaticDecode<T>, Result extends Static = Static>(value: unknown): Result; | ||
Encode<Static = StaticEncode<T>, Result extends Static = Static>(value: unknown): Result; | ||
} | ||
@@ -25,0 +25,0 @@ export declare class TypeCompilerUnknownTypeError extends TypeBoxError { |
@@ -265,2 +265,7 @@ "use strict"; | ||
} | ||
function* FromImport(schema, references, value) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
yield* Visit(target, [...references, ...definitions], value); | ||
} | ||
function* FromInteger(schema, references, value) { | ||
@@ -383,5 +388,9 @@ yield `Number.isInteger(${value})`; | ||
// Reference: If we have seen this reference before we can just yield and return the function call. | ||
// If this isn't the case we defer to visit to generate and set the function for subsequent passes. | ||
if (state.functions.has(schema.$ref)) | ||
// If this isn't the case we defer to visit to generate and set the _recursion_end_for_ for subsequent | ||
// passes. This operation is very awkward as we are using the functions state to store values to | ||
// enable self referential types to terminate. This needs to be refactored. | ||
const recursiveEnd = `_recursion_end_for_${schema.$ref}`; | ||
if (state.functions.has(recursiveEnd)) | ||
return yield `${CreateFunctionName(schema.$ref)}(${value})`; | ||
state.functions.set(recursiveEnd, ''); // terminate recursion here by setting the name. | ||
yield* Visit(target, references, value); | ||
@@ -493,2 +502,4 @@ } | ||
return yield* FromFunction(schema_, references_, value); | ||
case 'Import': | ||
return yield* FromImport(schema_, references_, value); | ||
case 'Integer': | ||
@@ -495,0 +506,0 @@ return yield* FromInteger(schema_, references_, value); |
@@ -242,2 +242,7 @@ "use strict"; | ||
} | ||
function* FromImport(schema, references, path, value) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
yield* Visit(target, [...references, ...definitions], path, value); | ||
} | ||
function* FromInteger(schema, references, path, value) { | ||
@@ -534,2 +539,4 @@ if (!(0, index_10.IsInteger)(value)) | ||
return yield* FromFunction(schema_, references_, path, value); | ||
case 'Import': | ||
return yield* FromImport(schema_, references_, path, value); | ||
case 'Integer': | ||
@@ -536,0 +543,0 @@ return yield* FromInteger(schema_, references_, path, value); |
@@ -21,3 +21,2 @@ export * from './type/clone/index'; | ||
export * from './type/date/index'; | ||
export * from './type/deref/index'; | ||
export * from './type/enum/index'; | ||
@@ -36,2 +35,3 @@ export * from './type/exclude/index'; | ||
export * from './type/literal/index'; | ||
export * from './type/module/index'; | ||
export * from './type/mapped/index'; | ||
@@ -60,3 +60,2 @@ export * from './type/never/index'; | ||
export * from './type/static/index'; | ||
export * from './type/strict/index'; | ||
export * from './type/string/index'; | ||
@@ -63,0 +62,0 @@ export * from './type/symbol/index'; |
@@ -44,3 +44,2 @@ "use strict"; | ||
__exportStar(require("./type/date/index"), exports); | ||
__exportStar(require("./type/deref/index"), exports); | ||
__exportStar(require("./type/enum/index"), exports); | ||
@@ -59,2 +58,3 @@ __exportStar(require("./type/exclude/index"), exports); | ||
__exportStar(require("./type/literal/index"), exports); | ||
__exportStar(require("./type/module/index"), exports); | ||
__exportStar(require("./type/mapped/index"), exports); | ||
@@ -83,3 +83,2 @@ __exportStar(require("./type/never/index"), exports); | ||
__exportStar(require("./type/static/index"), exports); | ||
__exportStar(require("./type/strict/index"), exports); | ||
__exportStar(require("./type/string/index"), exports); | ||
@@ -86,0 +85,0 @@ __exportStar(require("./type/symbol/index"), exports); |
@@ -0,16 +1,15 @@ | ||
import * as Types from '../type/index'; | ||
import { Static } from './parsebox/index'; | ||
import { TSchema, SchemaOptions } from '../type/schema/index'; | ||
import { StaticDecode } from '../type/static/index'; | ||
import { Type } from './static'; | ||
/** `[Experimental]` Infers a TypeBox type from TypeScript syntax. */ | ||
export type StaticParseAsSchema<Context extends Record<PropertyKey, TSchema>, Code extends string> = Static.Parse<Type, Code, Context>[0]; | ||
/** `[Experimental]` Infers a TypeScript type from TypeScript syntax. */ | ||
export type StaticParseAsType<Context extends Record<PropertyKey, TSchema>, Code extends string> = StaticParseAsSchema<Context, Code> extends infer Type extends TSchema ? StaticDecode<Type> : undefined; | ||
/** `[Experimental]` Parses a TypeBox type from TypeScript syntax. */ | ||
export declare function Parse<Context extends Record<PropertyKey, TSchema>, Code extends string>(context: Context, code: Code, options?: SchemaOptions): StaticParseAsSchema<Context, Code>; | ||
/** `[Experimental]` Parses a TypeBox type from TypeScript syntax. */ | ||
export declare function Parse<Code extends string>(code: Code, options?: SchemaOptions): StaticParseAsSchema<{}, Code>; | ||
/** `[Experimental]` Parses a TypeBox TSchema from TypeScript syntax. This function does not infer the type. */ | ||
export declare function ParseOnly<Context extends Record<PropertyKey, TSchema>, Code extends string>(context: Context, code: Code, options?: SchemaOptions): TSchema | undefined; | ||
/** `[Experimental]` Parses a TypeBox TSchema from TypeScript syntax */ | ||
export declare function ParseOnly<Code extends string>(code: Code, options?: SchemaOptions): TSchema | undefined; | ||
import { Main } from './static'; | ||
/** `[Syntax]` Infers a TypeBox type from TypeScript syntax. */ | ||
export type StaticParseAsSchema<Context extends Record<PropertyKey, Types.TSchema>, Code extends string> = Static.Parse<Main, Code, Context>[0]; | ||
/** `[Syntax]` Infers a TypeScript type from TypeScript syntax. */ | ||
export type StaticParseAsType<Context extends Record<PropertyKey, Types.TSchema>, Code extends string> = StaticParseAsSchema<Context, Code> extends infer Type extends Types.TSchema ? Types.StaticDecode<Type> : undefined; | ||
/** `[Syntax]` Parses a TypeBox type from TypeScript syntax. */ | ||
export declare function Parse<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): StaticParseAsSchema<Context, Code>; | ||
/** `[Syntax]` Parses a TypeBox type from TypeScript syntax. */ | ||
export declare function Parse<Code extends string>(code: Code, options?: Types.SchemaOptions): StaticParseAsSchema<{}, Code>; | ||
/** `[Syntax]` Parses a TypeBox TSchema from TypeScript syntax. This function does not infer the type. */ | ||
export declare function ParseOnly<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined; | ||
/** `[Syntax]` Parses a TypeBox TSchema from TypeScript syntax */ | ||
export declare function ParseOnly<Code extends string>(code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined; |
@@ -6,14 +6,15 @@ "use strict"; | ||
exports.ParseOnly = ParseOnly; | ||
const type_1 = require("../type/create/type"); | ||
const Types = require("../type/index"); | ||
const runtime_1 = require("./runtime"); | ||
/** `[Experimental]` Parses a TypeBox type from TypeScript syntax. */ | ||
/** `[Syntax]` Parses a TypeBox type from TypeScript syntax. */ | ||
function Parse(...args) { | ||
return ParseOnly.apply(null, args); | ||
} | ||
/** `[Experimental]` Parses a TypeBox TSchema from TypeScript syntax. This function does not infer the type. */ | ||
/** `[Syntax]` Parses a TypeBox TSchema from TypeScript syntax. This function does not infer the type. */ | ||
function ParseOnly(...args) { | ||
const withContext = typeof args[0] === 'string' ? false : true; | ||
const [context, code, options] = withContext ? [args[0], args[1], args[2] || {}] : [{}, args[0], args[1] || {}]; | ||
const type = runtime_1.Module.Parse('Type', code, context)[0]; | ||
return (type !== undefined ? (0, type_1.CreateType)(type, options) : undefined); | ||
const type = runtime_1.Module.Parse('Main', code, context)[0]; | ||
// Note: Parsing may return either a ModuleInstance or Type. We only apply options on the Type. | ||
return Types.KindGuard.IsSchema(type) ? Types.CloneType(type, options) : type; | ||
} |
import { Runtime } from './parsebox/index'; | ||
import * as Types from '../type/index'; | ||
export declare const Module: Runtime.Module<{ | ||
ExportModifier: Runtime.IUnion<boolean>; | ||
HeritageList: Runtime.IUnion<Types.TSchema[]>; | ||
Heritage: Runtime.IUnion<unknown[]>; | ||
InterfaceDeclaration: Runtime.ITuple<{ | ||
[x: string]: Types.TIntersect<[...Types.TRef<string>[], Types.TObject<Types.TProperties>]>; | ||
}>; | ||
TypeAliasDeclaration: Runtime.ITuple<{ | ||
[x: string]: Types.TSchema; | ||
}>; | ||
ModuleType: Runtime.IUnion<unknown>; | ||
ModuleProperties: Runtime.IUnion<Types.TProperties>; | ||
ModuleDeclaration: Runtime.ITuple<Types.TModule<Types.TProperties>>; | ||
Literal: Runtime.IUnion<Types.TLiteral<string> | Types.TLiteral<number> | Types.TLiteral<boolean>>; | ||
@@ -17,4 +29,4 @@ Keyword: Runtime.IUnion<Types.TAny | Types.TNever | Types.TString | Types.TBoolean | Types.TNumber | Types.TInteger | Types.TBigInt | Types.TNull | Types.TSymbol | Types.TUndefined | Types.TUnknown | Types.TVoid>; | ||
PropertyKey: Runtime.IUnion<string>; | ||
PropertyReadonly: Runtime.IUnion<boolean>; | ||
PropertyOptional: Runtime.IUnion<boolean>; | ||
Readonly: Runtime.IUnion<boolean>; | ||
Optional: Runtime.IUnion<boolean>; | ||
Property: Runtime.ITuple<{ | ||
@@ -24,4 +36,4 @@ [x: string]: Types.TSchema; | ||
PropertyDelimiter: Runtime.IUnion<[","] | [",", "\n"] | [";"] | [";", "\n"] | ["\n"]>; | ||
Properties: Runtime.IUnion<unknown[]>; | ||
Object: Runtime.ITuple<Types.TObject<Record<string, Types.TSchema>>>; | ||
Properties: Runtime.IUnion<Types.TProperties>; | ||
Object: Runtime.ITuple<Types.TObject<Types.TProperties>>; | ||
Elements: Runtime.IUnion<unknown[]>; | ||
@@ -57,2 +69,3 @@ Tuple: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>; | ||
Reference: Runtime.IIdent<Types.TSchema>; | ||
Main: Runtime.IUnion<unknown>; | ||
}>; |
@@ -26,2 +26,3 @@ "use strict"; | ||
const Tilde = '`'; | ||
const Equals = '='; | ||
// ------------------------------------------------------------------ | ||
@@ -37,8 +38,129 @@ // DestructureRight | ||
// ------------------------------------------------------------------ | ||
// Deref | ||
// ------------------------------------------------------------------ | ||
const Deref = (context, key) => { | ||
return key in context ? context[key] : Types.Ref(key); | ||
}; | ||
// ------------------------------------------------------------------ | ||
// ExportModifier | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const ExportModifierMapping = (values) => { | ||
return values.length === 1; | ||
}; | ||
// prettier-ignore | ||
const ExportModifier = index_1.Runtime.Union([ | ||
index_1.Runtime.Tuple([index_1.Runtime.Const('export')]), index_1.Runtime.Tuple([]) | ||
], ExportModifierMapping); | ||
// ------------------------------------------------------------------ | ||
// TypeAliasDeclaration | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const TypeAliasDeclarationMapping = (_Export, _Keyword, Ident, _Equals, Type) => { | ||
return { [Ident]: Type }; | ||
}; | ||
// prettier-ignore | ||
const TypeAliasDeclaration = index_1.Runtime.Tuple([ | ||
index_1.Runtime.Ref('ExportModifier'), | ||
index_1.Runtime.Const('type'), | ||
index_1.Runtime.Ident(), | ||
index_1.Runtime.Const(Equals), | ||
index_1.Runtime.Ref('Type') | ||
], value => TypeAliasDeclarationMapping(...value)); | ||
// ------------------------------------------------------------------ | ||
// HeritageList | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore (note, heritage list should disallow trailing comma) | ||
const HeritageListDelimiter = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const(Comma), index_1.Runtime.Const(Newline)]), index_1.Runtime.Tuple([index_1.Runtime.Const(Comma)])]); | ||
// prettier-ignore | ||
const HeritageListMapping = (values, context) => { | ||
return (values.length === 3 ? [Deref(context, values[0]), ...values[2]] : | ||
values.length === 1 ? [Deref(context, values[0])] : | ||
[]); | ||
}; | ||
// prettier-ignore | ||
const HeritageList = index_1.Runtime.Union([ | ||
index_1.Runtime.Tuple([index_1.Runtime.Ident(), HeritageListDelimiter, index_1.Runtime.Ref('HeritageList')]), | ||
index_1.Runtime.Tuple([index_1.Runtime.Ident()]), | ||
index_1.Runtime.Tuple([]) | ||
], HeritageListMapping); | ||
// ------------------------------------------------------------------ | ||
// Heritage | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const HeritageMapping = (values) => { | ||
return (values.length === 2 ? values[1] : []); | ||
}; | ||
// prettier-ignore | ||
const Heritage = index_1.Runtime.Union([ | ||
index_1.Runtime.Tuple([index_1.Runtime.Const('extends'), index_1.Runtime.Ref('HeritageList')]), | ||
index_1.Runtime.Tuple([]) | ||
], HeritageMapping); | ||
// ------------------------------------------------------------------ | ||
// InterfaceDeclaration | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const InterfaceDeclarationMapping = (_0, _1, Ident, Heritage, _4, Properties, _6) => { | ||
return { [Ident]: Types.Intersect([...Heritage, Types.Object(Properties)]) }; | ||
}; | ||
// prettier-ignore | ||
const InterfaceDeclaration = index_1.Runtime.Tuple([ | ||
index_1.Runtime.Ref('ExportModifier'), | ||
index_1.Runtime.Const('interface'), | ||
index_1.Runtime.Ident(), | ||
index_1.Runtime.Ref('Heritage'), | ||
index_1.Runtime.Const(LBrace), | ||
index_1.Runtime.Ref('Properties'), | ||
index_1.Runtime.Const(RBrace), | ||
], values => InterfaceDeclarationMapping(...values)); | ||
// ------------------------------------------------------------------ | ||
// ModuleType | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const ModuleType = index_1.Runtime.Union([ | ||
index_1.Runtime.Ref('InterfaceDeclaration'), | ||
index_1.Runtime.Ref('TypeAliasDeclaration') | ||
]); | ||
// ------------------------------------------------------------------ | ||
// ModuleProperties | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const ModulePropertiesDelimiter = index_1.Runtime.Union([ | ||
index_1.Runtime.Tuple([index_1.Runtime.Const(SemiColon), index_1.Runtime.Const(Newline)]), | ||
index_1.Runtime.Tuple([index_1.Runtime.Const(SemiColon)]), | ||
index_1.Runtime.Tuple([index_1.Runtime.Const(Newline)]), | ||
]); | ||
// prettier-ignore | ||
const ModulePropertiesMapping = (values) => { | ||
return (values.length === 3 ? { ...values[0], ...values[2] } : | ||
values.length === 1 ? values[0] : | ||
{}); | ||
}; | ||
// prettier-ignore | ||
const ModuleProperties = index_1.Runtime.Union([ | ||
index_1.Runtime.Tuple([index_1.Runtime.Ref('ModuleType'), ModulePropertiesDelimiter, index_1.Runtime.Ref('ModuleProperties')]), | ||
index_1.Runtime.Tuple([index_1.Runtime.Ref('ModuleType')]), | ||
index_1.Runtime.Tuple([]), | ||
], ModulePropertiesMapping); | ||
// ------------------------------------------------------------------ | ||
// ModuleDeclaration | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const ModuleIdentifier = index_1.Runtime.Union([ | ||
index_1.Runtime.Tuple([index_1.Runtime.Ident()]), | ||
index_1.Runtime.Tuple([]) | ||
]); | ||
// prettier-ignore | ||
const ModuleDeclarationMapping = (_1, _2, _Ident, _3, Properties, _5) => { | ||
return Types.Module(Properties); | ||
}; | ||
// prettier-ignore | ||
const ModuleDeclaration = index_1.Runtime.Tuple([ | ||
index_1.Runtime.Ref('ExportModifier'), index_1.Runtime.Const('module'), ModuleIdentifier, index_1.Runtime.Const(LBrace), index_1.Runtime.Ref('ModuleProperties'), index_1.Runtime.Const(RBrace) | ||
], values => ModuleDeclarationMapping(...values)); | ||
// ------------------------------------------------------------------ | ||
// Reference | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const Reference = index_1.Runtime.Ident((value, context) => { | ||
return value in context ? context[value] : Types.Ref(value); | ||
}); | ||
const Reference = index_1.Runtime.Ident((value, context) => Deref(context, value)); | ||
// ------------------------------------------------------------------ | ||
@@ -229,13 +351,10 @@ // Literal | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const PropertyKey = index_1.Runtime.Union([index_1.Runtime.Ident(), index_1.Runtime.String([SingleQuote, DoubleQuote])]); | ||
const Readonly = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const('readonly')]), index_1.Runtime.Tuple([])], (value) => value.length > 0); | ||
const Optional = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const(Question)]), index_1.Runtime.Tuple([])], (value) => value.length > 0); | ||
// prettier-ignore | ||
const PropertyReadonly = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const('readonly')]), index_1.Runtime.Tuple([])], value => value.length > 0); | ||
// prettier-ignore | ||
const PropertyOptional = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const(Question)]), index_1.Runtime.Tuple([])], value => value.length > 0); | ||
// prettier-ignore | ||
const PropertyMapping = (Readonly, Key, Optional, _, Type) => ({ | ||
[Key]: (Readonly && Optional ? Types.ReadonlyOptional(Type) : | ||
Readonly && !Optional ? Types.Readonly(Type) : | ||
!Readonly && Optional ? Types.Optional(Type) : | ||
const PropertyMapping = (IsReadonly, Key, IsOptional, _, Type) => ({ | ||
[Key]: (IsReadonly && IsOptional ? Types.ReadonlyOptional(Type) : | ||
IsReadonly && !IsOptional ? Types.Readonly(Type) : | ||
!IsReadonly && IsOptional ? Types.Optional(Type) : | ||
Type) | ||
@@ -245,5 +364,5 @@ }); | ||
const Property = index_1.Runtime.Tuple([ | ||
index_1.Runtime.Ref('PropertyReadonly'), | ||
index_1.Runtime.Ref('Readonly'), | ||
index_1.Runtime.Ref('PropertyKey'), | ||
index_1.Runtime.Ref('PropertyOptional'), | ||
index_1.Runtime.Ref('Optional'), | ||
index_1.Runtime.Const(Colon), | ||
@@ -266,6 +385,6 @@ index_1.Runtime.Ref('Type'), | ||
index_1.Runtime.Tuple([]) | ||
], values => (values.length === 3 ? [values[0], ...values[2]] : | ||
values.length === 2 ? [values[0]] : | ||
values.length === 1 ? [values[0]] : | ||
[])); | ||
], values => (values.length === 3 ? { ...values[0], ...values[2] } : | ||
values.length === 2 ? values[0] : | ||
values.length === 1 ? values[0] : | ||
{})); | ||
// ------------------------------------------------------------------ | ||
@@ -275,5 +394,3 @@ // Object | ||
// prettier-ignore | ||
const ObjectMapping = (values) => Types.Object(values.reduce((properties, record) => { | ||
return { ...properties, ...record }; | ||
}, {})); | ||
const ObjectMapping = (_0, Properties, _2) => Types.Object(Properties); | ||
// prettier-ignore | ||
@@ -284,3 +401,3 @@ const _Object = index_1.Runtime.Tuple([ | ||
index_1.Runtime.Const(RBrace) | ||
], values => ObjectMapping(values[1])); | ||
], values => ObjectMapping(...values)); | ||
// ------------------------------------------------------------------ | ||
@@ -354,3 +471,11 @@ // Tuple | ||
const Mapped = index_1.Runtime.Tuple([ | ||
index_1.Runtime.Const(LBrace), index_1.Runtime.Const(LBracket), index_1.Runtime.Ident(), index_1.Runtime.Const('in'), index_1.Runtime.Ref('Type'), index_1.Runtime.Const(RBracket), index_1.Runtime.Const(Colon), index_1.Runtime.Ref('Type'), index_1.Runtime.Const(RBrace) | ||
index_1.Runtime.Const(LBrace), | ||
index_1.Runtime.Const(LBracket), | ||
index_1.Runtime.Ident(), | ||
index_1.Runtime.Const('in'), | ||
index_1.Runtime.Ref('Type'), | ||
index_1.Runtime.Const(RBracket), | ||
index_1.Runtime.Const(Colon), | ||
index_1.Runtime.Ref('Type'), | ||
index_1.Runtime.Const(RBrace) | ||
], MappedMapping); | ||
@@ -576,2 +701,12 @@ // ------------------------------------------------------------------ | ||
// ------------------------------------------------------------------ | ||
// Main | ||
// ------------------------------------------------------------------ | ||
// prettier-ignore | ||
const Main = index_1.Runtime.Union([ | ||
ModuleDeclaration, | ||
TypeAliasDeclaration, | ||
InterfaceDeclaration, | ||
Type | ||
]); | ||
// ------------------------------------------------------------------ | ||
// Module | ||
@@ -581,2 +716,16 @@ // ------------------------------------------------------------------ | ||
exports.Module = new index_1.Runtime.Module({ | ||
// ---------------------------------------------------------------- | ||
// Modules, Interfaces and Type Aliases | ||
// ---------------------------------------------------------------- | ||
ExportModifier, | ||
HeritageList, | ||
Heritage, | ||
InterfaceDeclaration, | ||
TypeAliasDeclaration, | ||
ModuleType, | ||
ModuleProperties, | ||
ModuleDeclaration, | ||
// ---------------------------------------------------------------- | ||
// Type Expressions | ||
// ---------------------------------------------------------------- | ||
Literal, | ||
@@ -593,6 +742,6 @@ Keyword, | ||
Expr, | ||
Type, | ||
Type, // Alias for Expr | ||
PropertyKey, | ||
PropertyReadonly, | ||
PropertyOptional, | ||
Readonly, | ||
Optional, | ||
Property, | ||
@@ -631,3 +780,7 @@ PropertyDelimiter, | ||
Uint8Array, | ||
Reference | ||
Reference, | ||
// ---------------------------------------------------------------- | ||
// Main | ||
// ---------------------------------------------------------------- | ||
Main | ||
}); |
@@ -19,2 +19,3 @@ import { Static } from './parsebox/index'; | ||
type Tilde = '`'; | ||
type Equals = '='; | ||
interface DelimitTailMapping<_ = unknown> extends Static.IMapping { | ||
@@ -45,6 +46,86 @@ output: (this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer F, _, infer G, _, infer H, _, infer I, _, infer Rest extends unknown[]] ? [A, B, C, D, E, F, G, H, I, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer F, _, infer G, _, infer H, _, infer Rest extends unknown[]] ? [A, B, C, D, E, F, G, H, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer F, _, infer G, _, infer Rest extends unknown[]] ? [A, B, C, D, E, F, G, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer F, _, infer Rest extends unknown[]] ? [A, B, C, D, E, F, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer Rest extends unknown[]] ? [A, B, C, D, E, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer Rest extends unknown[]] ? [A, B, C, D, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer Rest extends unknown[]] ? [A, B, C, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer Rest extends unknown[]] ? [A, B, ...Rest] : this['input'] extends [_, infer A, _, infer Rest extends unknown[]] ? [A, ...Rest] : this['input'] extends [_, infer Rest extends unknown[]] ? [...Rest] : this['input'] extends [_] ? [] : [ | ||
], DelimitMapping>); | ||
type Deref<Context extends Types.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : Types.TRef<Ref>); | ||
interface ExportModifierMapping extends Static.IMapping { | ||
output: this['input'] extends [string] ? true : false; | ||
} | ||
type ExportModifier = Static.Union<[ | ||
Static.Tuple<[Static.Const<'export'>]>, | ||
Static.Tuple<[]> | ||
], ExportModifierMapping>; | ||
interface TypeAliasDeclarationMapping extends Static.IMapping { | ||
output: this['input'] extends [infer _Export extends boolean, 'type', infer Ident extends string, Equals, infer Type extends Types.TSchema] ? { | ||
[_ in Ident]: Type; | ||
} : never; | ||
} | ||
type TypeAliasDeclaration = Static.Tuple<[ | ||
ExportModifier, | ||
Static.Const<'type'>, | ||
Static.Ident, | ||
Static.Const<Equals>, | ||
Type | ||
], TypeAliasDeclarationMapping>; | ||
type HeritageListDelimiter = Static.Union<[Static.Tuple<[Static.Const<Comma>, Static.Const<Newline>]>, Static.Tuple<[Static.Const<Comma>]>]>; | ||
type HeritageListReduce<Values extends string[], Context extends Types.TProperties, Result extends Types.TSchema[] = []> = (Values extends [infer Ref extends string, ...infer Rest extends string[]] ? HeritageListReduce<Rest, Context, [...Result, Deref<Context, Ref>]> : Result); | ||
interface HeritageListMapping extends Static.IMapping { | ||
output: (this['context'] extends Types.TProperties ? this['input'] extends string[] ? HeritageListReduce<this['input'], this['context']> : [] : []); | ||
} | ||
type HeritageList = Static.Union<[Delimit<Static.Ident, HeritageListDelimiter>], HeritageListMapping>; | ||
interface HeritageMapping extends Static.IMapping { | ||
output: this['input'] extends ['extends', infer List extends Types.TSchema[]] ? List : []; | ||
} | ||
type Heritage = Static.Union<[ | ||
Static.Tuple<[Static.Const<'extends'>, HeritageList]>, | ||
Static.Tuple<[]> | ||
], HeritageMapping>; | ||
interface InterfaceDeclarationMapping extends Static.IMapping { | ||
output: this['input'] extends [boolean, 'interface', infer Ident extends string, infer Heritage extends Types.TSchema[], LBrace, infer Properties extends Types.TProperties, RBrace] ? { | ||
[_ in Ident]: Types.TIntersectEvaluated<[...Heritage, Types.TObject<Properties>]>; | ||
} : never; | ||
} | ||
type InterfaceDeclaration = Static.Tuple<[ | ||
ExportModifier, | ||
Static.Const<'interface'>, | ||
Static.Ident, | ||
Heritage, | ||
Static.Const<LBrace>, | ||
Properties, | ||
Static.Const<RBrace> | ||
], InterfaceDeclarationMapping>; | ||
type ModuleType = Static.Union<[ | ||
InterfaceDeclaration, | ||
TypeAliasDeclaration | ||
]>; | ||
type ModulePropertiesDelimiter = Static.Union<[ | ||
Static.Tuple<[Static.Const<SemiColon>, Static.Const<Newline>]>, | ||
Static.Tuple<[Static.Const<SemiColon>]>, | ||
Static.Tuple<[Static.Const<Newline>]> | ||
]>; | ||
type ModulePropertiesReduce<Value extends unknown[], Result extends Types.TProperties = {}> = (Value extends [infer ModuleType extends Types.TProperties, unknown[], ...infer Rest extends unknown[]] ? ModulePropertiesReduce<Rest, Result & ModuleType> : Value extends [infer ModuleType extends Types.TProperties] ? ModulePropertiesReduce<[], Result & ModuleType> : Types.Evaluate<Result>); | ||
interface ModulePropertiesMapping extends Static.IMapping { | ||
output: this['input'] extends unknown[] ? ModulePropertiesReduce<this['input']> : never; | ||
} | ||
type ModuleProperties = Static.Union<[ | ||
Static.Tuple<[ModuleType, ModulePropertiesDelimiter, ModuleProperties]>, | ||
Static.Tuple<[ModuleType]>, | ||
Static.Tuple<[]> | ||
], ModulePropertiesMapping>; | ||
type ModuleIdentifier = Static.Union<[ | ||
Static.Tuple<[Static.Ident]>, | ||
Static.Tuple<[]> | ||
]>; | ||
interface ModuleDeclarationMapping extends Static.IMapping { | ||
output: this['input'] extends [boolean, 'module', infer _Ident extends string[], LBrace, infer Properties extends Types.TProperties, RBrace] ? Types.TModule<Properties> : never; | ||
} | ||
type ModuleDeclaration = Static.Tuple<[ | ||
ExportModifier, | ||
Static.Const<'module'>, | ||
ModuleIdentifier, | ||
Static.Const<LBrace>, | ||
ModuleProperties, | ||
Static.Const<RBrace> | ||
], ModuleDeclarationMapping>; | ||
interface ReferenceMapping extends Static.IMapping { | ||
output: this['input'] extends [infer Key extends string] ? Key extends keyof this['context'] ? this['context'][Key] : Types.TRef<Types.TUnknown> : never; | ||
output: this['context'] extends Types.TProperties ? this['input'] extends string ? Deref<this['context'], this['input']> : never : never; | ||
} | ||
type Reference = Static.Tuple<[Static.Ident], ReferenceMapping>; | ||
type Reference = Static.Ident<ReferenceMapping>; | ||
interface LiteralBooleanMapping extends Static.IMapping { | ||
@@ -176,3 +257,3 @@ output: this['input'] extends `${infer S extends boolean}` ? Types.TLiteral<S> : never; | ||
], ExprBinaryMapping>; | ||
export type Type = Expr; | ||
type Type = Expr; | ||
interface PropertyKeyStringMapping extends Static.IMapping { | ||
@@ -183,28 +264,25 @@ output: this['input']; | ||
type PropertyKey = Static.Union<[Static.Ident, PropertyKeyString]>; | ||
interface PropertyReadonlyMapping extends Static.IMapping { | ||
interface ReadonlyMapping extends Static.IMapping { | ||
output: this['input'] extends ['readonly'] ? true : false; | ||
} | ||
type PropertyReadonly = Static.Union<[Static.Tuple<[Static.Const<'readonly'>]>, Static.Tuple<[]>], PropertyReadonlyMapping>; | ||
interface PropertyOptionalMapping extends Static.IMapping { | ||
type Readonly = Static.Union<[Static.Tuple<[Static.Const<'readonly'>]>, Static.Tuple<[]>], ReadonlyMapping>; | ||
interface OptionalMapping extends Static.IMapping { | ||
output: this['input'] extends [Question] ? true : false; | ||
} | ||
type PropertyOptional = Static.Union<[Static.Tuple<[Static.Const<Question>]>, Static.Tuple<[]>], PropertyOptionalMapping>; | ||
type Optional = Static.Union<[Static.Tuple<[Static.Const<Question>]>, Static.Tuple<[]>], OptionalMapping>; | ||
interface PropertyMapping extends Static.IMapping { | ||
output: this['input'] extends [infer Readonly extends boolean, infer Key extends string, infer Optional extends boolean, string, infer Type extends Types.TSchema] ? { | ||
output: this['input'] extends [infer IsReadonly extends boolean, infer Key extends string, infer IsOptional extends boolean, string, infer Type extends Types.TSchema] ? { | ||
[_ in Key]: ([ | ||
Readonly, | ||
Optional | ||
IsReadonly, | ||
IsOptional | ||
] extends [true, true] ? Types.TReadonlyOptional<Type> : [ | ||
Readonly, | ||
Optional | ||
IsReadonly, | ||
IsOptional | ||
] extends [true, false] ? Types.TReadonly<Type> : [ | ||
Readonly, | ||
Optional | ||
IsReadonly, | ||
IsOptional | ||
] extends [false, true] ? Types.TOptional<Type> : Type); | ||
} : never; | ||
} | ||
type Property = Static.Tuple<[PropertyReadonly, PropertyKey, PropertyOptional, Static.Const<Colon>, Type], PropertyMapping>; | ||
type PropertiesEvaluate<T> = { | ||
[K in keyof T]: T[K]; | ||
} & {}; | ||
type Property = Static.Tuple<[Readonly, PropertyKey, Optional, Static.Const<Colon>, Type], PropertyMapping>; | ||
type PropertyDelimiter = Static.Union<[ | ||
@@ -217,3 +295,3 @@ Static.Tuple<[Static.Const<Comma>, Static.Const<Newline>]>, | ||
]>; | ||
type PropertiesReduce<PropertiesArray extends Types.TProperties[], Result extends Types.TProperties = {}> = (PropertiesArray extends [infer Left extends Types.TProperties, ...infer Right extends Types.TProperties[]] ? PropertiesReduce<Right, PropertiesEvaluate<Result & Left>> : Result); | ||
type PropertiesReduce<PropertiesArray extends Types.TProperties[], Result extends Types.TProperties = {}> = (PropertiesArray extends [infer Left extends Types.TProperties, ...infer Right extends Types.TProperties[]] ? PropertiesReduce<Right, Types.Evaluate<Result & Left>> : Result); | ||
interface PropertiesMapping extends Static.IMapping { | ||
@@ -271,3 +349,3 @@ output: this['input'] extends Types.TProperties[] ? PropertiesReduce<this['input']> : never; | ||
interface MappedMapping extends Static.IMapping { | ||
output: this['input'] extends [LBrace, LBracket, infer Key extends string, 'in', infer Right extends Types.TSchema, RBracket, Colon, infer Type extends Types.TSchema, RBrace] ? Types.TLiteral<'Mapped types not supported'> : this['input']; | ||
output: this['input'] extends [LBrace, LBracket, infer _Key extends string, 'in', infer _Right extends Types.TSchema, RBracket, Colon, infer Type extends Types.TSchema, RBrace] ? Types.TLiteral<'Mapped types not supported'> : this['input']; | ||
} | ||
@@ -477,2 +555,8 @@ type Mapped = Static.Tuple<[ | ||
type Uint8Array = Static.Const<'Uint8Array', Static.As<Types.TUint8Array>>; | ||
export type Main = Static.Union<[ | ||
ModuleDeclaration, | ||
TypeAliasDeclaration, | ||
InterfaceDeclaration, | ||
Type | ||
]>; | ||
export {}; |
@@ -14,2 +14,3 @@ import { Kind, Hint, TransformKind } from '../symbols/index'; | ||
import type { TFunction } from '../function/index'; | ||
import type { TImport } from '../module/index'; | ||
import type { TInteger } from '../integer/index'; | ||
@@ -61,2 +62,4 @@ import type { TIntersect } from '../intersect/index'; | ||
/** `[Kind-Only]` Returns true if the given value is TInteger */ | ||
export declare function IsImport(value: unknown): value is TImport; | ||
/** `[Kind-Only]` Returns true if the given value is TInteger */ | ||
export declare function IsInteger(value: unknown): value is TInteger; | ||
@@ -63,0 +66,0 @@ /** `[Kind-Only]` Returns true if the given schema is TProperties */ |
@@ -14,2 +14,3 @@ "use strict"; | ||
exports.IsFunction = IsFunction; | ||
exports.IsImport = IsImport; | ||
exports.IsInteger = IsInteger; | ||
@@ -93,2 +94,6 @@ exports.IsProperties = IsProperties; | ||
/** `[Kind-Only]` Returns true if the given value is TInteger */ | ||
function IsImport(value) { | ||
return IsKindOf(value, 'Import'); | ||
} | ||
/** `[Kind-Only]` Returns true if the given value is TInteger */ | ||
function IsInteger(value) { | ||
@@ -95,0 +100,0 @@ return IsKindOf(value, 'Integer'); |
@@ -15,2 +15,3 @@ import { Kind, Hint, TransformKind } from '../symbols/index'; | ||
import type { TFunction } from '../function/index'; | ||
import type { TImport } from '../module/index'; | ||
import type { TInteger } from '../integer/index'; | ||
@@ -63,2 +64,4 @@ import type { TIntersect } from '../intersect/index'; | ||
export declare function IsFunction(value: unknown): value is TFunction; | ||
/** Returns true if the given value is TImport */ | ||
export declare function IsImport(value: unknown): value is TImport; | ||
/** Returns true if the given value is TInteger */ | ||
@@ -65,0 +68,0 @@ export declare function IsInteger(value: unknown): value is TInteger; |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.IsFunction = IsFunction; | ||
exports.IsImport = IsImport; | ||
exports.IsInteger = IsInteger; | ||
@@ -229,2 +230,14 @@ exports.IsProperties = IsProperties; | ||
} | ||
/** Returns true if the given value is TImport */ | ||
function IsImport(value) { | ||
// prettier-ignore | ||
return (IsKindOf(value, 'Import') && | ||
ValueGuard.HasPropertyKey(value, '$defs') && | ||
ValueGuard.IsObject(value.$defs) && | ||
IsProperties(value.$defs) && | ||
ValueGuard.HasPropertyKey(value, '$ref') && | ||
ValueGuard.IsString(value.$ref) && | ||
value.$ref in value.$defs // required | ||
); | ||
} | ||
/** Returns true if the given value is TInteger */ | ||
@@ -231,0 +244,0 @@ function IsInteger(value) { |
@@ -13,3 +13,2 @@ export * from './any/index'; | ||
export * from './date/index'; | ||
export * from './deref/index'; | ||
export * from './discard/index'; | ||
@@ -33,2 +32,3 @@ export * from './enum/index'; | ||
export * from './mapped/index'; | ||
export * from './module/index'; | ||
export * from './never/index'; | ||
@@ -59,3 +59,2 @@ export * from './not/index'; | ||
export * from './static/index'; | ||
export * from './strict/index'; | ||
export * from './string/index'; | ||
@@ -62,0 +61,0 @@ export * from './symbol/index'; |
@@ -30,3 +30,2 @@ "use strict"; | ||
__exportStar(require("./date/index"), exports); | ||
__exportStar(require("./deref/index"), exports); | ||
__exportStar(require("./discard/index"), exports); | ||
@@ -50,2 +49,3 @@ __exportStar(require("./enum/index"), exports); | ||
__exportStar(require("./mapped/index"), exports); | ||
__exportStar(require("./module/index"), exports); | ||
__exportStar(require("./never/index"), exports); | ||
@@ -76,3 +76,2 @@ __exportStar(require("./not/index"), exports); | ||
__exportStar(require("./static/index"), exports); | ||
__exportStar(require("./strict/index"), exports); | ||
__exportStar(require("./string/index"), exports); | ||
@@ -79,0 +78,0 @@ __exportStar(require("./symbol/index"), exports); |
import type { TSchema, SchemaOptions } from '../schema/index'; | ||
import type { Static } from '../static/index'; | ||
import { Kind } from '../symbols/index'; | ||
export interface TRef<T extends TSchema = TSchema> extends TSchema { | ||
export interface TRef<Ref extends string = string> extends TSchema { | ||
[Kind]: 'Ref'; | ||
static: Static<T, this['params']>; | ||
$ref: string; | ||
static: unknown; | ||
$ref: Ref; | ||
} | ||
/** `[Json]` Creates a Ref type. The referenced type must contain a $id */ | ||
export declare function Ref<T extends TSchema>(schema: T, options?: SchemaOptions): TRef<T>; | ||
/** `[Json]` Creates a Ref type. */ | ||
export declare function Ref<T extends TSchema>($ref: string, options?: SchemaOptions): TRef<T>; | ||
export declare function Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>; |
@@ -7,13 +7,5 @@ "use strict"; | ||
const index_1 = require("../symbols/index"); | ||
// ------------------------------------------------------------------ | ||
// ValueGuard | ||
// ------------------------------------------------------------------ | ||
const value_1 = require("../guard/value"); | ||
/** `[Json]` Creates a Ref type. */ | ||
function Ref(unresolved, options) { | ||
if ((0, value_1.IsString)(unresolved)) | ||
return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref: unresolved }, options); | ||
if ((0, value_1.IsUndefined)(unresolved.$id)) | ||
throw new Error('Reference target type must specify an $id'); | ||
return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref: unresolved.$id }, options); | ||
/** `[Json]` Creates a Ref type. The referenced type must contain a $id */ | ||
function Ref($ref, options) { | ||
return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref }, options); | ||
} |
@@ -26,3 +26,3 @@ import type { Evaluate } from '../helpers/index'; | ||
export type TDecodeRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TDecodeRest<R, [...Acc, TDecodeType<L>]> : Acc; | ||
export type TDecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<TDecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<TDecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<TDecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<TDecodeRest<P>, TDecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<TDecodeRest<P>, TDecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TDecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<TDecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<TDecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, TDecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<TDecodeType<S>> : T extends TRef<infer S extends TSchema> ? TRef<TDecodeType<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TDecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TDecodeRest<S>> : T); | ||
export type TDecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<TDecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<TDecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<TDecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<TDecodeRest<P>, TDecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<TDecodeRest<P>, TDecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TDecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<TDecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<TDecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, TDecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<TDecodeType<S>> : T extends TRef<infer S extends string> ? TRef<S> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TDecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TDecodeRest<S>> : T); | ||
export type StaticDecodeIsAny<T> = boolean extends (T extends TSchema ? true : false) ? true : false; | ||
@@ -29,0 +29,0 @@ /** Creates an decoded static type from a TypeBox type */ |
@@ -6,3 +6,2 @@ import { type TAny } from '../any/index'; | ||
import { type TConst } from '../const/index'; | ||
import { type TDeref } from '../deref/index'; | ||
import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index'; | ||
@@ -23,2 +22,3 @@ import { type TExclude, type TExcludeFromMappedResult, type TExcludeFromTemplateLiteral } from '../exclude/index'; | ||
import { type TMappedKey } from '../mapped/index'; | ||
import { TModule } from '../module/index'; | ||
import { type TNumber, type NumberOptions } from '../number/index'; | ||
@@ -38,3 +38,2 @@ import { type TObject, type TProperties, type ObjectOptions } from '../object/index'; | ||
import { type TSchema, type SchemaOptions } from '../schema/index'; | ||
import { type TStrict } from '../strict/index'; | ||
import { type TString, type StringOptions } from '../string/index'; | ||
@@ -49,12 +48,2 @@ import { type TTemplateLiteral, type TTemplateLiteralKind, type TTemplateLiteralSyntax } from '../template-literal/index'; | ||
export declare class JsonTypeBuilder { | ||
/** | ||
* @deprecated `[Json]` Omits compositing symbols from this schema. It is recommended | ||
* to use the JSON parse/stringify to remove compositing symbols if needed. This | ||
* is how Strict works internally. | ||
* | ||
* ```typescript | ||
* JSON.parse(JSON.stringify(Type.String())) | ||
* ``` | ||
*/ | ||
Strict<T extends TSchema>(schema: T): TStrict<T>; | ||
/** `[Json]` Creates a Readonly and Optional property */ | ||
@@ -90,4 +79,2 @@ ReadonlyOptional<T extends TSchema>(schema: T): TReadonlyOptional<T>; | ||
Const</* const (not supported in 4.0) */ T>(value: T, options?: SchemaOptions): TConst<T>; | ||
/** `[Json]` Creates a dereferenced type */ | ||
Deref<T extends TSchema>(schema: T, references: TSchema[]): TDeref<T>; | ||
/** `[Json]` Creates a Enum type */ | ||
@@ -137,2 +124,4 @@ Enum<V extends TEnumValue, T extends Record<TEnumKey, V>>(item: T, options?: SchemaOptions): TEnum<T>; | ||
Mapped<K extends PropertyKey[], F extends TMappedFunction<K> = TMappedFunction<K>, R extends TMapped<K, F> = TMapped<K, F>>(key: [...K], map: F, options?: ObjectOptions): R; | ||
/** `[Json]` Creates a Type Definition Module. */ | ||
Module<Properties extends TProperties>(properties: Properties): TModule<Properties>; | ||
/** `[Json]` Creates a Never type */ | ||
@@ -172,6 +161,4 @@ Never(options?: SchemaOptions): TNever; | ||
Recursive<T extends TSchema>(callback: (thisType: TThis) => T, options?: SchemaOptions): TRecursive<T>; | ||
/** `[Json]` Creates a Ref type. The referenced type must contain a $id */ | ||
Ref<T extends TSchema>(schema: T, options?: SchemaOptions): TRef<T>; | ||
/** `[Json]` Creates a Ref type. */ | ||
Ref<T extends TSchema>($ref: string, options?: SchemaOptions): TRef<T>; | ||
Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>; | ||
/** `[Json]` Constructs a type where all properties are required */ | ||
@@ -178,0 +165,0 @@ Required<T extends TMappedResult>(T: T, options?: SchemaOptions): TRequiredFromMappedResult<T>; |
@@ -10,17 +10,17 @@ "use strict"; | ||
const index_5 = require("../const/index"); | ||
const index_6 = require("../deref/index"); | ||
const index_7 = require("../enum/index"); | ||
const index_8 = require("../exclude/index"); | ||
const index_9 = require("../extends/index"); | ||
const index_10 = require("../extract/index"); | ||
const index_11 = require("../indexed/index"); | ||
const index_12 = require("../integer/index"); | ||
const index_13 = require("../intersect/index"); | ||
const index_14 = require("../intrinsic/index"); | ||
const index_15 = require("../keyof/index"); | ||
const index_16 = require("../literal/index"); | ||
const index_17 = require("../mapped/index"); | ||
const index_18 = require("../never/index"); | ||
const index_19 = require("../not/index"); | ||
const index_20 = require("../null/index"); | ||
const index_6 = require("../enum/index"); | ||
const index_7 = require("../exclude/index"); | ||
const index_8 = require("../extends/index"); | ||
const index_9 = require("../extract/index"); | ||
const index_10 = require("../indexed/index"); | ||
const index_11 = require("../integer/index"); | ||
const index_12 = require("../intersect/index"); | ||
const index_13 = require("../intrinsic/index"); | ||
const index_14 = require("../keyof/index"); | ||
const index_15 = require("../literal/index"); | ||
const index_16 = require("../mapped/index"); | ||
const index_17 = require("../never/index"); | ||
const index_18 = require("../not/index"); | ||
const index_19 = require("../null/index"); | ||
const index_20 = require("../module/index"); | ||
const index_21 = require("../number/index"); | ||
@@ -39,28 +39,12 @@ const index_22 = require("../object/index"); | ||
const index_33 = require("../rest/index"); | ||
const index_34 = require("../strict/index"); | ||
const index_35 = require("../string/index"); | ||
const index_36 = require("../template-literal/index"); | ||
const index_37 = require("../transform/index"); | ||
const index_38 = require("../tuple/index"); | ||
const index_39 = require("../union/index"); | ||
const index_40 = require("../unknown/index"); | ||
const index_41 = require("../unsafe/index"); | ||
const index_34 = require("../string/index"); | ||
const index_35 = require("../template-literal/index"); | ||
const index_36 = require("../transform/index"); | ||
const index_37 = require("../tuple/index"); | ||
const index_38 = require("../union/index"); | ||
const index_39 = require("../unknown/index"); | ||
const index_40 = require("../unsafe/index"); | ||
/** Json Type Builder with Static Resolution for TypeScript */ | ||
class JsonTypeBuilder { | ||
// ------------------------------------------------------------------------ | ||
// Strict | ||
// ------------------------------------------------------------------------ | ||
/** | ||
* @deprecated `[Json]` Omits compositing symbols from this schema. It is recommended | ||
* to use the JSON parse/stringify to remove compositing symbols if needed. This | ||
* is how Strict works internally. | ||
* | ||
* ```typescript | ||
* JSON.parse(JSON.stringify(Type.String())) | ||
* ``` | ||
*/ | ||
Strict(schema) { | ||
return (0, index_34.Strict)(schema); | ||
} | ||
// ------------------------------------------------------------------------ | ||
// Modifiers | ||
@@ -97,3 +81,3 @@ // ------------------------------------------------------------------------ | ||
Capitalize(schema, options) { | ||
return (0, index_14.Capitalize)(schema, options); | ||
return (0, index_13.Capitalize)(schema, options); | ||
} | ||
@@ -108,61 +92,61 @@ /** `[Json]` Creates a Composite object type */ | ||
} | ||
/** `[Json]` Creates a dereferenced type */ | ||
Deref(schema, references) { | ||
return (0, index_6.Deref)(schema, references); | ||
} | ||
/** `[Json]` Creates a Enum type */ | ||
Enum(item, options) { | ||
return (0, index_7.Enum)(item, options); | ||
return (0, index_6.Enum)(item, options); | ||
} | ||
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */ | ||
Exclude(unionType, excludedMembers, options) { | ||
return (0, index_8.Exclude)(unionType, excludedMembers, options); | ||
return (0, index_7.Exclude)(unionType, excludedMembers, options); | ||
} | ||
/** `[Json]` Creates a Conditional type */ | ||
Extends(L, R, T, F, options) { | ||
return (0, index_9.Extends)(L, R, T, F, options); | ||
return (0, index_8.Extends)(L, R, T, F, options); | ||
} | ||
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */ | ||
Extract(type, union, options) { | ||
return (0, index_10.Extract)(type, union, options); | ||
return (0, index_9.Extract)(type, union, options); | ||
} | ||
/** `[Json]` Returns an Indexed property type for the given keys */ | ||
Index(schema, unresolved, options) { | ||
return (0, index_11.Index)(schema, unresolved, options); | ||
return (0, index_10.Index)(schema, unresolved, options); | ||
} | ||
/** `[Json]` Creates an Integer type */ | ||
Integer(options) { | ||
return (0, index_12.Integer)(options); | ||
return (0, index_11.Integer)(options); | ||
} | ||
/** `[Json]` Creates an Intersect type */ | ||
Intersect(T, options) { | ||
return (0, index_13.Intersect)(T, options); | ||
return (0, index_12.Intersect)(T, options); | ||
} | ||
/** `[Json]` Creates a KeyOf type */ | ||
KeyOf(schema, options) { | ||
return (0, index_15.KeyOf)(schema, options); | ||
return (0, index_14.KeyOf)(schema, options); | ||
} | ||
/** `[Json]` Creates a Literal type */ | ||
Literal(value, options) { | ||
return (0, index_16.Literal)(value, options); | ||
return (0, index_15.Literal)(value, options); | ||
} | ||
/** `[Json]` Intrinsic function to Lowercase LiteralString types */ | ||
Lowercase(schema, options) { | ||
return (0, index_14.Lowercase)(schema, options); | ||
return (0, index_13.Lowercase)(schema, options); | ||
} | ||
/** `[Json]` Creates a Mapped object type */ | ||
Mapped(key, map, options) { | ||
return (0, index_17.Mapped)(key, map, options); | ||
return (0, index_16.Mapped)(key, map, options); | ||
} | ||
/** `[Json]` Creates a Type Definition Module. */ | ||
Module(properties) { | ||
return (0, index_20.Module)(properties); | ||
} | ||
/** `[Json]` Creates a Never type */ | ||
Never(options) { | ||
return (0, index_18.Never)(options); | ||
return (0, index_17.Never)(options); | ||
} | ||
/** `[Json]` Creates a Not type */ | ||
Not(schema, options) { | ||
return (0, index_19.Not)(schema, options); | ||
return (0, index_18.Not)(schema, options); | ||
} | ||
/** `[Json]` Creates a Null type */ | ||
Null(options) { | ||
return (0, index_20.Null)(options); | ||
return (0, index_19.Null)(options); | ||
} | ||
@@ -198,4 +182,4 @@ /** `[Json]` Creates a Number type */ | ||
/** `[Json]` Creates a Ref type. */ | ||
Ref(unresolved, options) { | ||
return (0, index_31.Ref)(unresolved, options); | ||
Ref($ref, options) { | ||
return (0, index_31.Ref)($ref, options); | ||
} | ||
@@ -212,37 +196,37 @@ /** `[Json]` Constructs a type where all properties are required */ | ||
String(options) { | ||
return (0, index_35.String)(options); | ||
return (0, index_34.String)(options); | ||
} | ||
/** `[Json]` Creates a TemplateLiteral type */ | ||
TemplateLiteral(unresolved, options) { | ||
return (0, index_36.TemplateLiteral)(unresolved, options); | ||
return (0, index_35.TemplateLiteral)(unresolved, options); | ||
} | ||
/** `[Json]` Creates a Transform type */ | ||
Transform(schema) { | ||
return (0, index_37.Transform)(schema); | ||
return (0, index_36.Transform)(schema); | ||
} | ||
/** `[Json]` Creates a Tuple type */ | ||
Tuple(items, options) { | ||
return (0, index_38.Tuple)(items, options); | ||
return (0, index_37.Tuple)(items, options); | ||
} | ||
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */ | ||
Uncapitalize(schema, options) { | ||
return (0, index_14.Uncapitalize)(schema, options); | ||
return (0, index_13.Uncapitalize)(schema, options); | ||
} | ||
/** `[Json]` Creates a Union type */ | ||
Union(schemas, options) { | ||
return (0, index_39.Union)(schemas, options); | ||
return (0, index_38.Union)(schemas, options); | ||
} | ||
/** `[Json]` Creates an Unknown type */ | ||
Unknown(options) { | ||
return (0, index_40.Unknown)(options); | ||
return (0, index_39.Unknown)(options); | ||
} | ||
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */ | ||
Unsafe(options) { | ||
return (0, index_41.Unsafe)(options); | ||
return (0, index_40.Unsafe)(options); | ||
} | ||
/** `[Json]` Intrinsic function to Uppercase LiteralString types */ | ||
Uppercase(schema, options) { | ||
return (0, index_14.Uppercase)(schema, options); | ||
return (0, index_13.Uppercase)(schema, options); | ||
} | ||
} | ||
exports.JsonTypeBuilder = JsonTypeBuilder; |
@@ -12,3 +12,2 @@ export { Any } from '../any/index'; | ||
export { Date } from '../date/index'; | ||
export { Deref } from '../deref/index'; | ||
export { Enum } from '../enum/index'; | ||
@@ -28,2 +27,3 @@ export { Exclude } from '../exclude/index'; | ||
export { Mapped } from '../mapped/index'; | ||
export { Module } from '../module/index'; | ||
export { Never } from '../never/index'; | ||
@@ -50,3 +50,2 @@ export { Not } from '../not/index'; | ||
export { String } from '../string/index'; | ||
export { Strict } from '../strict/index'; | ||
export { Symbol } from '../symbol/index'; | ||
@@ -53,0 +52,0 @@ export { TemplateLiteral } from '../template-literal/index'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.String = exports.ReturnType = exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.Readonly = exports.Promise = exports.Pick = exports.Partial = exports.Parameters = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.Mapped = exports.Literal = exports.KeyOf = exports.Iterator = exports.Uppercase = exports.Lowercase = exports.Uncapitalize = exports.Capitalize = exports.Intersect = exports.Integer = exports.InstanceType = exports.Index = exports.Function = exports.Extract = exports.Extends = exports.Exclude = exports.Enum = exports.Deref = exports.Date = exports.ConstructorParameters = exports.Constructor = exports.Const = exports.Composite = exports.Boolean = exports.BigInt = exports.Awaited = exports.AsyncIterator = exports.Array = exports.Any = void 0; | ||
exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.Transform = exports.TemplateLiteral = exports.Symbol = exports.Strict = void 0; | ||
exports.String = exports.ReturnType = exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.Readonly = exports.Promise = exports.Pick = exports.Partial = exports.Parameters = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.Module = exports.Mapped = exports.Literal = exports.KeyOf = exports.Iterator = exports.Uppercase = exports.Lowercase = exports.Uncapitalize = exports.Capitalize = exports.Intersect = exports.Integer = exports.InstanceType = exports.Index = exports.Function = exports.Extract = exports.Extends = exports.Exclude = exports.Enum = exports.Date = exports.ConstructorParameters = exports.Constructor = exports.Const = exports.Composite = exports.Boolean = exports.BigInt = exports.Awaited = exports.AsyncIterator = exports.Array = exports.Any = void 0; | ||
exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.Transform = exports.TemplateLiteral = exports.Symbol = void 0; | ||
// ------------------------------------------------------------------ | ||
@@ -31,35 +31,35 @@ // Type: Module | ||
Object.defineProperty(exports, "Date", { enumerable: true, get: function () { return index_11.Date; } }); | ||
var index_12 = require("../deref/index"); | ||
Object.defineProperty(exports, "Deref", { enumerable: true, get: function () { return index_12.Deref; } }); | ||
var index_13 = require("../enum/index"); | ||
Object.defineProperty(exports, "Enum", { enumerable: true, get: function () { return index_13.Enum; } }); | ||
var index_14 = require("../exclude/index"); | ||
Object.defineProperty(exports, "Exclude", { enumerable: true, get: function () { return index_14.Exclude; } }); | ||
var index_15 = require("../extends/index"); | ||
Object.defineProperty(exports, "Extends", { enumerable: true, get: function () { return index_15.Extends; } }); | ||
var index_16 = require("../extract/index"); | ||
Object.defineProperty(exports, "Extract", { enumerable: true, get: function () { return index_16.Extract; } }); | ||
var index_17 = require("../function/index"); | ||
Object.defineProperty(exports, "Function", { enumerable: true, get: function () { return index_17.Function; } }); | ||
var index_18 = require("../indexed/index"); | ||
Object.defineProperty(exports, "Index", { enumerable: true, get: function () { return index_18.Index; } }); | ||
var index_19 = require("../instance-type/index"); | ||
Object.defineProperty(exports, "InstanceType", { enumerable: true, get: function () { return index_19.InstanceType; } }); | ||
var index_20 = require("../integer/index"); | ||
Object.defineProperty(exports, "Integer", { enumerable: true, get: function () { return index_20.Integer; } }); | ||
var index_21 = require("../intersect/index"); | ||
Object.defineProperty(exports, "Intersect", { enumerable: true, get: function () { return index_21.Intersect; } }); | ||
var index_22 = require("../intrinsic/index"); | ||
Object.defineProperty(exports, "Capitalize", { enumerable: true, get: function () { return index_22.Capitalize; } }); | ||
Object.defineProperty(exports, "Uncapitalize", { enumerable: true, get: function () { return index_22.Uncapitalize; } }); | ||
Object.defineProperty(exports, "Lowercase", { enumerable: true, get: function () { return index_22.Lowercase; } }); | ||
Object.defineProperty(exports, "Uppercase", { enumerable: true, get: function () { return index_22.Uppercase; } }); | ||
var index_23 = require("../iterator/index"); | ||
Object.defineProperty(exports, "Iterator", { enumerable: true, get: function () { return index_23.Iterator; } }); | ||
var index_24 = require("../keyof/index"); | ||
Object.defineProperty(exports, "KeyOf", { enumerable: true, get: function () { return index_24.KeyOf; } }); | ||
var index_25 = require("../literal/index"); | ||
Object.defineProperty(exports, "Literal", { enumerable: true, get: function () { return index_25.Literal; } }); | ||
var index_26 = require("../mapped/index"); | ||
Object.defineProperty(exports, "Mapped", { enumerable: true, get: function () { return index_26.Mapped; } }); | ||
var index_12 = require("../enum/index"); | ||
Object.defineProperty(exports, "Enum", { enumerable: true, get: function () { return index_12.Enum; } }); | ||
var index_13 = require("../exclude/index"); | ||
Object.defineProperty(exports, "Exclude", { enumerable: true, get: function () { return index_13.Exclude; } }); | ||
var index_14 = require("../extends/index"); | ||
Object.defineProperty(exports, "Extends", { enumerable: true, get: function () { return index_14.Extends; } }); | ||
var index_15 = require("../extract/index"); | ||
Object.defineProperty(exports, "Extract", { enumerable: true, get: function () { return index_15.Extract; } }); | ||
var index_16 = require("../function/index"); | ||
Object.defineProperty(exports, "Function", { enumerable: true, get: function () { return index_16.Function; } }); | ||
var index_17 = require("../indexed/index"); | ||
Object.defineProperty(exports, "Index", { enumerable: true, get: function () { return index_17.Index; } }); | ||
var index_18 = require("../instance-type/index"); | ||
Object.defineProperty(exports, "InstanceType", { enumerable: true, get: function () { return index_18.InstanceType; } }); | ||
var index_19 = require("../integer/index"); | ||
Object.defineProperty(exports, "Integer", { enumerable: true, get: function () { return index_19.Integer; } }); | ||
var index_20 = require("../intersect/index"); | ||
Object.defineProperty(exports, "Intersect", { enumerable: true, get: function () { return index_20.Intersect; } }); | ||
var index_21 = require("../intrinsic/index"); | ||
Object.defineProperty(exports, "Capitalize", { enumerable: true, get: function () { return index_21.Capitalize; } }); | ||
Object.defineProperty(exports, "Uncapitalize", { enumerable: true, get: function () { return index_21.Uncapitalize; } }); | ||
Object.defineProperty(exports, "Lowercase", { enumerable: true, get: function () { return index_21.Lowercase; } }); | ||
Object.defineProperty(exports, "Uppercase", { enumerable: true, get: function () { return index_21.Uppercase; } }); | ||
var index_22 = require("../iterator/index"); | ||
Object.defineProperty(exports, "Iterator", { enumerable: true, get: function () { return index_22.Iterator; } }); | ||
var index_23 = require("../keyof/index"); | ||
Object.defineProperty(exports, "KeyOf", { enumerable: true, get: function () { return index_23.KeyOf; } }); | ||
var index_24 = require("../literal/index"); | ||
Object.defineProperty(exports, "Literal", { enumerable: true, get: function () { return index_24.Literal; } }); | ||
var index_25 = require("../mapped/index"); | ||
Object.defineProperty(exports, "Mapped", { enumerable: true, get: function () { return index_25.Mapped; } }); | ||
var index_26 = require("../module/index"); | ||
Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return index_26.Module; } }); | ||
var index_27 = require("../never/index"); | ||
@@ -107,23 +107,21 @@ Object.defineProperty(exports, "Never", { enumerable: true, get: function () { return index_27.Never; } }); | ||
Object.defineProperty(exports, "String", { enumerable: true, get: function () { return index_47.String; } }); | ||
var index_48 = require("../strict/index"); | ||
Object.defineProperty(exports, "Strict", { enumerable: true, get: function () { return index_48.Strict; } }); | ||
var index_49 = require("../symbol/index"); | ||
Object.defineProperty(exports, "Symbol", { enumerable: true, get: function () { return index_49.Symbol; } }); | ||
var index_50 = require("../template-literal/index"); | ||
Object.defineProperty(exports, "TemplateLiteral", { enumerable: true, get: function () { return index_50.TemplateLiteral; } }); | ||
var index_51 = require("../transform/index"); | ||
Object.defineProperty(exports, "Transform", { enumerable: true, get: function () { return index_51.Transform; } }); | ||
var index_52 = require("../tuple/index"); | ||
Object.defineProperty(exports, "Tuple", { enumerable: true, get: function () { return index_52.Tuple; } }); | ||
var index_53 = require("../uint8array/index"); | ||
Object.defineProperty(exports, "Uint8Array", { enumerable: true, get: function () { return index_53.Uint8Array; } }); | ||
var index_54 = require("../undefined/index"); | ||
Object.defineProperty(exports, "Undefined", { enumerable: true, get: function () { return index_54.Undefined; } }); | ||
var index_55 = require("../union/index"); | ||
Object.defineProperty(exports, "Union", { enumerable: true, get: function () { return index_55.Union; } }); | ||
var index_56 = require("../unknown/index"); | ||
Object.defineProperty(exports, "Unknown", { enumerable: true, get: function () { return index_56.Unknown; } }); | ||
var index_57 = require("../unsafe/index"); | ||
Object.defineProperty(exports, "Unsafe", { enumerable: true, get: function () { return index_57.Unsafe; } }); | ||
var index_58 = require("../void/index"); | ||
Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return index_58.Void; } }); | ||
var index_48 = require("../symbol/index"); | ||
Object.defineProperty(exports, "Symbol", { enumerable: true, get: function () { return index_48.Symbol; } }); | ||
var index_49 = require("../template-literal/index"); | ||
Object.defineProperty(exports, "TemplateLiteral", { enumerable: true, get: function () { return index_49.TemplateLiteral; } }); | ||
var index_50 = require("../transform/index"); | ||
Object.defineProperty(exports, "Transform", { enumerable: true, get: function () { return index_50.Transform; } }); | ||
var index_51 = require("../tuple/index"); | ||
Object.defineProperty(exports, "Tuple", { enumerable: true, get: function () { return index_51.Tuple; } }); | ||
var index_52 = require("../uint8array/index"); | ||
Object.defineProperty(exports, "Uint8Array", { enumerable: true, get: function () { return index_52.Uint8Array; } }); | ||
var index_53 = require("../undefined/index"); | ||
Object.defineProperty(exports, "Undefined", { enumerable: true, get: function () { return index_53.Undefined; } }); | ||
var index_54 = require("../union/index"); | ||
Object.defineProperty(exports, "Union", { enumerable: true, get: function () { return index_54.Union; } }); | ||
var index_55 = require("../unknown/index"); | ||
Object.defineProperty(exports, "Unknown", { enumerable: true, get: function () { return index_55.Unknown; } }); | ||
var index_56 = require("../unsafe/index"); | ||
Object.defineProperty(exports, "Unsafe", { enumerable: true, get: function () { return index_56.Unsafe; } }); | ||
var index_57 = require("../void/index"); | ||
Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return index_57.Void; } }); |
@@ -107,2 +107,7 @@ "use strict"; | ||
} | ||
function FromImport(schema, references, value) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
return Visit(target, [...references, ...definitions], value); | ||
} | ||
function FromIntersect(schema, references, value) { | ||
@@ -171,3 +176,3 @@ const created = (0, index_4.Create)(schema, references); | ||
function Visit(schema, references, value) { | ||
const references_ = (0, index_1.IsString)(schema.$id) ? [...references, schema] : references; | ||
const references_ = (0, index_1.IsString)(schema.$id) ? (0, index_7.Pushref)(schema, references) : references; | ||
const schema_ = schema; | ||
@@ -182,2 +187,4 @@ switch (schema[index_3.Kind]) { | ||
return FromConstructor(schema_, references_, value); | ||
case 'Import': | ||
return FromImport(schema_, references_, value); | ||
case 'Intersect': | ||
@@ -184,0 +191,0 @@ return FromIntersect(schema_, references_, value); |
@@ -144,2 +144,7 @@ "use strict"; | ||
} | ||
function FromImport(schema, references, value) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
return Visit(target, [...references, ...definitions], value); | ||
} | ||
function FromInteger(schema, references, value) { | ||
@@ -390,3 +395,3 @@ if (!(0, index_10.IsInteger)(value)) { | ||
function Visit(schema, references, value) { | ||
const references_ = IsDefined(schema.$id) ? [...references, schema] : references; | ||
const references_ = IsDefined(schema.$id) ? (0, index_2.Pushref)(schema, references) : references; | ||
const schema_ = schema; | ||
@@ -410,2 +415,4 @@ switch (schema_[index_4.Kind]) { | ||
return FromFunction(schema_, references_, value); | ||
case 'Import': | ||
return FromImport(schema_, references_, value); | ||
case 'Integer': | ||
@@ -412,0 +419,0 @@ return FromInteger(schema_, references_, value); |
@@ -34,2 +34,7 @@ "use strict"; | ||
} | ||
function FromImport(schema, references, value) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
return Visit(target, [...references, ...definitions], value); | ||
} | ||
function FromIntersect(schema, references, value) { | ||
@@ -117,3 +122,3 @@ const unevaluatedProperties = schema.unevaluatedProperties; | ||
function Visit(schema, references, value) { | ||
const references_ = (0, index_6.IsString)(schema.$id) ? [...references, schema] : references; | ||
const references_ = (0, index_6.IsString)(schema.$id) ? (0, index_4.Pushref)(schema, references) : references; | ||
const schema_ = schema; | ||
@@ -123,2 +128,4 @@ switch (schema_[index_5.Kind]) { | ||
return FromArray(schema_, references_, value); | ||
case 'Import': | ||
return FromImport(schema_, references_, value); | ||
case 'Intersect': | ||
@@ -125,0 +132,0 @@ return FromIntersect(schema_, references_, value); |
@@ -130,2 +130,7 @@ "use strict"; | ||
} | ||
function FromImport(schema, references, value) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
return Visit(target, [...references, ...definitions], value); | ||
} | ||
function FromInteger(schema, references, value) { | ||
@@ -215,2 +220,4 @@ return TryConvertInteger(value); | ||
return FromDate(schema_, references_, value); | ||
case 'Import': | ||
return FromImport(schema_, references_, value); | ||
case 'Integer': | ||
@@ -217,0 +224,0 @@ return FromInteger(schema_, references_, value); |
@@ -127,2 +127,7 @@ "use strict"; | ||
} | ||
function FromImport(schema, references) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
return Visit(target, [...references, ...definitions]); | ||
} | ||
function FromInteger(schema, references) { | ||
@@ -411,2 +416,4 @@ if ((0, index_1.HasPropertyKey)(schema, 'default')) { | ||
return FromFunction(schema_, references_); | ||
case 'Import': | ||
return FromImport(schema_, references_); | ||
case 'Integer': | ||
@@ -413,0 +420,0 @@ return FromInteger(schema_, references_); |
@@ -47,2 +47,7 @@ "use strict"; | ||
} | ||
function FromImport(schema, references, value) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
return Visit(target, [...references, ...definitions], value); | ||
} | ||
function FromIntersect(schema, references, value) { | ||
@@ -141,2 +146,4 @@ const defaulted = ValueOrDefault(schema, value); | ||
return FromDate(schema_, references_, value); | ||
case 'Import': | ||
return FromImport(schema_, references_, value); | ||
case 'Intersect': | ||
@@ -143,0 +150,0 @@ return FromIntersect(schema_, references_, value); |
@@ -86,2 +86,11 @@ "use strict"; | ||
} | ||
// prettier-ignore | ||
function FromImport(schema, references, path, value) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
const transform = schema[index_1.TransformKind]; | ||
// Note: we need to re-spec the target as TSchema + [TransformKind] | ||
const transformTarget = { [index_1.TransformKind]: transform, ...target }; | ||
return Visit(transformTarget, [...references, ...definitions], path, value); | ||
} | ||
function FromNot(schema, references, path, value) { | ||
@@ -177,2 +186,4 @@ return Default(schema, path, Visit(schema.not, references, path, value)); | ||
return FromArray(schema_, references_, path, value); | ||
case 'Import': | ||
return FromImport(schema_, references_, path, value); | ||
case 'Intersect': | ||
@@ -179,0 +190,0 @@ return FromIntersect(schema_, references_, path, value); |
@@ -64,2 +64,11 @@ "use strict"; | ||
// prettier-ignore | ||
function FromImport(schema, references, path, value) { | ||
const definitions = globalThis.Object.values(schema.$defs); | ||
const target = schema.$defs[schema.$ref]; | ||
const transform = schema[index_1.TransformKind]; | ||
// Note: we need to re-spec the target as TSchema + [TransformKind] | ||
const transformTarget = { [index_1.TransformKind]: transform, ...target }; | ||
return Visit(transformTarget, [...references, ...definitions], path, value); | ||
} | ||
// prettier-ignore | ||
function FromIntersect(schema, references, path, value) { | ||
@@ -189,2 +198,4 @@ const defaulted = Default(schema, path, value); | ||
return FromArray(schema_, references_, path, value); | ||
case 'Import': | ||
return FromImport(schema_, references_, path, value); | ||
case 'Intersect': | ||
@@ -191,0 +202,0 @@ return FromIntersect(schema_, references_, path, value); |
{ | ||
"name": "@sinclair/typebox", | ||
"version": "0.33.22", | ||
"version": "0.34.0", | ||
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1604074
27281
1899
335
7
93
1037
2