| import { type TLocalizedValidationError } from '../error/index.mjs'; | ||
| import { type StaticDecode, type StaticEncode, type TProperties, type TSchema, Base } from '../type/index.mjs'; | ||
| import { type StaticDecode, type StaticEncode, type TProperties, type TSchema } from '../type/index.mjs'; | ||
| import { BuildResult, EvaluateResult } from '../schema/index.mjs'; | ||
| export declare class Validator<Context extends TProperties = TProperties, Type extends TSchema = TSchema, Encode extends unknown = StaticEncode<Type, Context>, Decode extends unknown = StaticDecode<Type, Context>> extends Base<Encode> { | ||
| export declare class Validator<Context extends TProperties = TProperties, Type extends TSchema = TSchema, Encode extends unknown = StaticEncode<Type, Context>, Decode extends unknown = StaticDecode<Type, Context>> { | ||
| private readonly hasCodec; | ||
@@ -38,7 +38,2 @@ private readonly buildResult; | ||
| Encode(value: unknown): Encode; | ||
| /** | ||
| * @deprecated Validator instances should not support Clone because they are owners of JIT evaluated functions. This function will be | ||
| * removed in the next version of TypeBox (relates to Type.Base deprecation) | ||
| */ | ||
| Clone(): Validator<Context, Type>; | ||
| } |
| // deno-fmt-ignore-file | ||
| import { Settings } from '../system/settings/index.mjs'; | ||
| import { Arguments } from '../system/arguments/index.mjs'; | ||
| import { Base } from '../type/index.mjs'; | ||
| import { Errors, Clean, Convert, Create, Default, Decode, Encode, HasCodec, Parser, ParseError } from '../value/index.mjs'; | ||
| import { Build, BuildResult, EvaluateResult } from '../schema/index.mjs'; | ||
| import { Build } from '../schema/index.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // Validator<...> | ||
| // ------------------------------------------------------------------ | ||
| export class Validator extends Base { | ||
| export class Validator { | ||
| /** Constructs a Validator. */ | ||
| constructor(...args) { | ||
| super(); | ||
| const matched = Arguments.Match(args, { | ||
| 3: (hasCodec, buildResult, evaluateResult) => [hasCodec, buildResult, evaluateResult], | ||
| 2: (context, type) => [context, type] | ||
| }); | ||
| // Note: The Base type requires this Validator to be Clone, but where we cannot safely clone | ||
| // the BuildResult or the EvaluateResult. For now we pass the Validator constructor a shared | ||
| // reference of BuildResult and EvaluateResult to mitigate re-compile on Clone. We must remove | ||
| // this overload when Base is removed (memory-gc-ref) | ||
| if (matched.length === 3 && matched[1] instanceof BuildResult && matched[2] instanceof EvaluateResult) { | ||
| const [hasCodec, buildResult, evaluateResult] = matched; | ||
| this.hasCodec = hasCodec; | ||
| this.buildResult = buildResult; | ||
| this.evaluateResult = evaluateResult; | ||
| } | ||
| else { | ||
| const [context, type] = matched; | ||
| this.hasCodec = HasCodec(context, type); | ||
| this.buildResult = Build(context, type); | ||
| this.evaluateResult = this.buildResult.Evaluate(); | ||
| } | ||
| constructor(context, type) { | ||
| this.hasCodec = HasCodec(context, type); | ||
| this.buildResult = Build(context, type); | ||
| this.evaluateResult = this.buildResult.Evaluate(); | ||
| } | ||
@@ -111,12 +91,2 @@ // ---------------------------------------------------------------- | ||
| } | ||
| // ---------------------------------------------------------------- | ||
| // Deprecations | ||
| // ---------------------------------------------------------------- | ||
| /** | ||
| * @deprecated Validator instances should not support Clone because they are owners of JIT evaluated functions. This function will be | ||
| * removed in the next version of TypeBox (relates to Type.Base deprecation) | ||
| */ | ||
| Clone() { | ||
| return new Validator(this.hasCodec, this.buildResult, this.evaluateResult); | ||
| } | ||
| } |
@@ -1,2 +0,2 @@ | ||
| export type TValidationError = TAdditionalPropertiesError | TAnyOfError | TBooleanError | TConstError | TContainsError | TDependenciesError | TDependentRequiredError | TEnumError | TExclusiveMaximumError | TExclusiveMinimumError | TFormatError | TGuardError | TIfError | TMaximumError | TMaxItemsError | TMaxLengthError | TMaxPropertiesError | TMinimumError | TMinItemsError | TMinLengthError | TMinPropertiesError | TMultipleOfError | TNotError | TOneOfError | TPatternError | TPropertyNamesError | TRefineError | TRequiredError | TTypeError | TUnevaluatedItemsError | TUnevaluatedPropertiesError | TUniqueItemsError; | ||
| export type TValidationError = TAdditionalPropertiesError | TAnyOfError | TBooleanError | TConstError | TContainsError | TDependenciesError | TDependentRequiredError | TEnumError | TExclusiveMaximumError | TExclusiveMinimumError | TFormatError | TIfError | TMaximumError | TMaxItemsError | TMaxLengthError | TMaxPropertiesError | TMinimumError | TMinItemsError | TMinLengthError | TMinPropertiesError | TMultipleOfError | TNotError | TOneOfError | TPatternError | TPropertyNamesError | TRefineError | TRequiredError | TTypeError | TUnevaluatedItemsError | TUnevaluatedPropertiesError | TUniqueItemsError; | ||
| export declare function IsValidationError(value: unknown): value is TValidationError; | ||
@@ -81,8 +81,2 @@ export type TLocalizedValidationError = TValidationError & { | ||
| } | ||
| export interface TGuardError extends TValidationErrorBase { | ||
| keyword: '~guard'; | ||
| params: { | ||
| errors: object[]; | ||
| }; | ||
| } | ||
| export interface TIfError extends TValidationErrorBase { | ||
@@ -89,0 +83,0 @@ keyword: 'if'; |
@@ -6,4 +6,2 @@ export declare function And(left: string, right: string): string; | ||
| export declare function IsArray(value: string): string; | ||
| /** Returns true if this value is an async iterator */ | ||
| export declare function IsAsyncIterator(value: unknown): string; | ||
| /** Returns true if this value is bigint */ | ||
@@ -15,4 +13,2 @@ export declare function IsBigInt(value: string): string; | ||
| export declare function IsInteger(value: string): string; | ||
| /** Returns true if this value is an iterator */ | ||
| export declare function IsIterator(value: unknown): string; | ||
| /** Returns true if this value is null */ | ||
@@ -19,0 +15,0 @@ export declare function IsNull(value: string): string; |
@@ -29,6 +29,2 @@ import * as G from './guard.mjs'; | ||
| } | ||
| /** Returns true if this value is an async iterator */ | ||
| export function IsAsyncIterator(value) { | ||
| return `Guard.IsAsyncIterator(${value})`; | ||
| } | ||
| /** Returns true if this value is bigint */ | ||
@@ -46,6 +42,2 @@ export function IsBigInt(value) { | ||
| } | ||
| /** Returns true if this value is an iterator */ | ||
| export function IsIterator(value) { | ||
| return `Guard.IsIterator(${value})`; | ||
| } | ||
| /** Returns true if this value is null */ | ||
@@ -52,0 +44,0 @@ export function IsNull(value) { |
| /** Returns true if this value is an array */ | ||
| export declare function IsArray(value: unknown): value is unknown[]; | ||
| /** Returns true if this value is an async iterator */ | ||
| export declare function IsAsyncIterator(value: unknown): value is AsyncIterableIterator<unknown>; | ||
| /** Returns true if this value is bigint */ | ||
@@ -15,4 +13,2 @@ export declare function IsBigInt(value: unknown): value is bigint; | ||
| export declare function IsInteger(value: unknown): value is number; | ||
| /** Returns true if this value is an iterator */ | ||
| export declare function IsIterator(value: unknown): value is IterableIterator<unknown>; | ||
| /** Returns true if this value is null */ | ||
@@ -19,0 +15,0 @@ export declare function IsNull(value: unknown): value is null; |
@@ -9,6 +9,2 @@ import * as String from './string.mjs'; | ||
| } | ||
| /** Returns true if this value is an async iterator */ | ||
| export function IsAsyncIterator(value) { | ||
| return IsObject(value) && Symbol.asyncIterator in value; | ||
| } | ||
| /** Returns true if this value is bigint */ | ||
@@ -41,6 +37,2 @@ export function IsBigInt(value) { | ||
| } | ||
| /** Returns true if this value is an iterator */ | ||
| export function IsIterator(value) { | ||
| return IsObject(value) && Symbol.iterator in value; | ||
| } | ||
| /** Returns true if this value is null */ | ||
@@ -47,0 +39,0 @@ export function IsNull(value) { |
| export * from './_context.mjs'; | ||
| export * from './_externals.mjs'; | ||
| export * from './_guard.mjs'; | ||
| export * from './_functions.mjs'; | ||
@@ -5,0 +4,0 @@ export * from './_reducer.mjs'; |
@@ -6,3 +6,2 @@ // ------------------------------------------------------------------ | ||
| export * from './_externals.mjs'; | ||
| export * from './_guard.mjs'; | ||
| export * from './_functions.mjs'; | ||
@@ -9,0 +8,0 @@ export * from './_reducer.mjs'; |
| // deno-fmt-ignore-file | ||
| import * as Schema from '../types/index.mjs'; | ||
| import { BuildRefine, CheckRefine, ErrorRefine } from './_refine.mjs'; | ||
| import { BuildGuard, CheckGuard, ErrorGuard } from './_guard.mjs'; | ||
| import { EmitGuard as E, Guard as G } from '../../guard/index.mjs'; | ||
@@ -219,4 +218,2 @@ import { BuildAdditionalItems, CheckAdditionalItems, ErrorAdditionalItems } from './additionalItems.mjs'; | ||
| conditions.push(BuildDynamicRef(stack, context, schema, value)); | ||
| if (Schema.IsGuard(schema)) | ||
| conditions.push(BuildGuard(stack, context, schema, value)); | ||
| if (Schema.IsConst(schema)) | ||
@@ -286,3 +283,2 @@ conditions.push(BuildConst(stack, context, schema, value)); | ||
| (!Schema.IsDynamicRef(schema) || CheckDynamicRef(stack, context, schema, value)) && | ||
| (!Schema.IsGuard(schema) || CheckGuard(stack, context, schema, value)) && | ||
| (!Schema.IsConst(schema) || CheckConst(stack, context, schema, value)) && | ||
@@ -341,3 +337,2 @@ (!Schema.IsEnum(schema) || CheckEnum(stack, context, schema, value)) && | ||
| +(!Schema.IsDynamicRef(schema) || ErrorDynamicRef(stack, context, schemaPath, instancePath, schema, value)) & | ||
| +(!Schema.IsGuard(schema) || ErrorGuard(stack, context, schemaPath, instancePath, schema, value)) & | ||
| +(!Schema.IsConst(schema) || ErrorConst(stack, context, schemaPath, instancePath, schema, value)) & | ||
@@ -344,0 +339,0 @@ +(!Schema.IsEnum(schema) || ErrorEnum(stack, context, schemaPath, instancePath, schema, value)) & |
@@ -17,11 +17,9 @@ // deno-fmt-ignore-file | ||
| // xschema | ||
| G.IsEqual(type, 'asyncIterator') ? E.IsAsyncIterator(value) : | ||
| G.IsEqual(type, 'bigint') ? E.IsBigInt(value) : | ||
| G.IsEqual(type, 'constructor') ? E.IsConstructor(value) : | ||
| G.IsEqual(type, 'function') ? E.IsFunction(value) : | ||
| G.IsEqual(type, 'iterator') ? E.IsIterator(value) : | ||
| G.IsEqual(type, 'symbol') ? E.IsSymbol(value) : | ||
| G.IsEqual(type, 'undefined') ? E.IsUndefined(value) : | ||
| G.IsEqual(type, 'void') ? E.IsUndefined(value) : | ||
| E.Constant(true)); | ||
| G.IsEqual(type, 'bigint') ? E.IsBigInt(value) : | ||
| G.IsEqual(type, 'constructor') ? E.IsConstructor(value) : | ||
| G.IsEqual(type, 'function') ? E.IsFunction(value) : | ||
| G.IsEqual(type, 'symbol') ? E.IsSymbol(value) : | ||
| G.IsEqual(type, 'undefined') ? E.IsUndefined(value) : | ||
| G.IsEqual(type, 'void') ? E.IsUndefined(value) : | ||
| E.Constant(true)); | ||
| } | ||
@@ -39,11 +37,9 @@ function CheckTypeName(_stack, _context, type, _schema, value) { | ||
| // xschema | ||
| G.IsEqual(type, 'asyncIterator') ? G.IsAsyncIterator(value) : | ||
| G.IsEqual(type, 'bigint') ? G.IsBigInt(value) : | ||
| G.IsEqual(type, 'constructor') ? G.IsConstructor(value) : | ||
| G.IsEqual(type, 'function') ? G.IsFunction(value) : | ||
| G.IsEqual(type, 'iterator') ? G.IsIterator(value) : | ||
| G.IsEqual(type, 'symbol') ? G.IsSymbol(value) : | ||
| G.IsEqual(type, 'undefined') ? G.IsUndefined(value) : | ||
| G.IsEqual(type, 'void') ? G.IsUndefined(value) : | ||
| true); | ||
| G.IsEqual(type, 'bigint') ? G.IsBigInt(value) : | ||
| G.IsEqual(type, 'constructor') ? G.IsConstructor(value) : | ||
| G.IsEqual(type, 'function') ? G.IsFunction(value) : | ||
| G.IsEqual(type, 'symbol') ? G.IsSymbol(value) : | ||
| G.IsEqual(type, 'undefined') ? G.IsUndefined(value) : | ||
| G.IsEqual(type, 'void') ? G.IsUndefined(value) : | ||
| true); | ||
| } | ||
@@ -50,0 +46,0 @@ // ------------------------------------------------------------------ |
@@ -1,2 +0,1 @@ | ||
| export * from './_guard.mjs'; | ||
| export * from './_refine.mjs'; | ||
@@ -3,0 +2,0 @@ export * from './additionalItems.mjs'; |
| // ------------------------------------------------------------------ | ||
| // Extensions | ||
| // ------------------------------------------------------------------ | ||
| export * from './_guard.mjs'; | ||
| export * from './_refine.mjs'; | ||
@@ -6,0 +5,0 @@ // ------------------------------------------------------------------ |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `يجب ألا يحتوي على عناصر مكررة`; | ||
| case '~guard': return `يجب أن يتطابق مع دالة الفحص`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'حدث خطأ غير معروف في التحقق من الصحة'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `অনুলিপি আইটেম থাকতে পারবে না`; | ||
| case '~guard': return `চেক ফাংশনের সাথে মেলাতে হবে`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'একটি অজানা বৈধকরণ ত্রুটি ঘটেছে'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `nesmí mít duplicitní položky`; | ||
| case '~guard': return `musí odpovídat kontrolní funkci`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'došlo k neznámé chybě ověření'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `darf keine doppelten Elemente haben`; | ||
| case '~guard': return `muss der Prüffunktion entsprechen`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ein unbekannter Validierungsfehler ist aufgetreten'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `δεν πρέπει να έχει διπλά στοιχεία`; | ||
| case '~guard': return `πρέπει να αντιστοιχεί στη συνάρτηση ελέγχου`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'προέκυψε ένα άγνωστο σφάλμα επικύρωσης'; |
@@ -35,3 +35,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `must not have duplicate items`; | ||
| case '~guard': return `must match check function`; | ||
| case '~refine': return error.params.message; | ||
@@ -38,0 +37,0 @@ // deno-coverage-ignore - unreachable |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `no debe tener elementos duplicados`; | ||
| case '~guard': return `debe coincidir con la función de verificación`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ocurrió un error de validación desconocido'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `no debe tener elementos duplicados`; | ||
| case '~guard': return `debe coincidir con la función de verificación`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ocurrió un error de validación desconocido'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `no debe tener elementos duplicados`; | ||
| case '~guard': return `debe coincidir con la función de verificación`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ha ocurrido un error de validación desconocido'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `no debe tener elementos duplicados`; | ||
| case '~guard': return `debe coincidir con la función de verificación`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ocurrió un error de validación desconocido'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `نباید آیتمهای تکراری داشته باشد`; | ||
| case '~guard': return `باید با تابع بررسی مطابقت داشته باشد`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'یک خطای اعتبارسنجی ناشناخته رخ داده است'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `hindi dapat magkaroon ng mga duplicate na item`; | ||
| case '~guard': return `dapat tumugma sa function ng pagsusuri`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'nagkaroon ng hindi kilalang error sa pagpapatunay'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `ne doit pas avoir d'éléments en double`; | ||
| case '~guard': return `doit correspondre à la fonction de vérification`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'une erreur de validation inconnue est survenue'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `ne doit pas avoir d'éléments en double`; | ||
| case '~guard': return `doit correspondre à la fonction de vérification`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'une erreur de validation inconnue est survenue'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `kada ya kasance yana da abubuwan da suka yi kama`; | ||
| case '~guard': return `dole ne ya dace da aikin duba`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'an sami kuskuren tabbatarwa da ba a sani ba'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `में डुप्लिकेट आइटम नहीं होने चाहिए`; | ||
| case '~guard': return `चेक फ़ंक्शन से मेल खाना चाहिए`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'एक अज्ञात सत्यापन त्रुटि हुई'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `nem lehetnek ismétlődő elemei`; | ||
| case '~guard': return `meg kell felelnie az ellenőrző függvénynek`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ismeretlen validációs hiba történt'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `tidak boleh memiliki item duplikat`; | ||
| case '~guard': return `harus sesuai dengan fungsi pemeriksaan`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'terjadi kesalahan validasi yang tidak diketahui'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `non deve avere elementi duplicati`; | ||
| case '~guard': return `deve corrispondere alla funzione di controllo`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'si è verificato un errore di validazione sconosciuto'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `重複するアイテムを持つことはできません`; | ||
| case '~guard': return `チェック関数と一致する必要があります`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return '不明なバリデーションエラーが発生しました'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `중복 항목을 가질 수 없습니다`; | ||
| case '~guard': return `체크 함수와 일치해야 합니다`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return '알 수 없는 유효성 검사 오류가 발생했습니다'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `tidak boleh mempunyai item pendua`; | ||
| case '~guard': return `mestilah sepadan dengan fungsi semak`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ralat pengesahan yang tidak diketahui berlaku'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `mag geen dubbele items hebben`; | ||
| case '~guard': return `moet overeenkomen met de controlefunctie`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'er is een onbekende validatiefout opgetreden'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `nie może zawierać zduplikowanych elementów`; | ||
| case '~guard': return `musi pasować do funkcji sprawdzającej`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'wystąpił nieznany błąd walidacji'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `não deve ter itens duplicados`; | ||
| case '~guard': return `deve corresponder à função de verificação`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ocorreu um erro de validação desconhecido'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `não deve ter itens duplicados`; | ||
| case '~guard': return `deve corresponder à função de verificação`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ocorreu um erro de validação desconhecido'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `nu trebuie să aibă elemente duplicate`; | ||
| case '~guard': return `trebuie să corespundă funcției de verificare`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'a apărut o eroare de validare necunoscută'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `не должно быть повторяющихся элементов`; | ||
| case '~guard': return `должно соответствовать проверочной функции`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'произошла неизвестная ошибка валидации'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `får inte ha dubbletter`; | ||
| case '~guard': return `måste matcha kontrollfunktionen`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'ett okänt valideringsfel uppstod'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `haipaswi kuwa na vitu vilivyofanana`; | ||
| case '~guard': return `inapaswa kulingana na kipengele cha ukaguzi`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'hitilafu isiyojulikana ya uthibitishaji imetokea'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `ต้องไม่มีรายการที่ซ้ำกัน`; | ||
| case '~guard': return `ต้องตรงกับฟังก์ชันตรวจสอบ`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'เกิดข้อผิดพลาดในการตรวจสอบที่ไม่รู้จัก'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `yinelenen öğelere sahip olmamalıdır`; | ||
| case '~guard': return `kontrol fonksiyonuyla eşleşmelidir`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'bilinmeyen bir doğrulama hatası oluştu'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `не повинно мати повторюваних елементів`; | ||
| case '~guard': return `повинно відповідати функції перевірки`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'виникла невідома помилка валідації'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `ڈپلیکیٹ آئٹمز نہیں ہونے چاہئیں`; | ||
| case '~guard': return `چیک فنکشن سے مطابقت ہونی چاہیے`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'تصدیق میں ایک نامعلوم خرابی پیش آئی'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `không được có các mục trùng lặp`; | ||
| case '~guard': return `phải khớp với hàm kiểm tra`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'đã xảy ra lỗi xác thực không xác định'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `ko gbọdọ ni awọn ohun elo ẹda`; | ||
| case '~guard': return `gbogbo yẹ ki o ba iṣẹ́ ṣàyẹ̀wò mu`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return 'aṣiṣe ijẹrisi aimọ waye'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `不得有重复项`; | ||
| case '~guard': return `必须与检查函数匹配`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return '发生未知验证错误'; |
@@ -36,3 +36,2 @@ // deno-fmt-ignore-file | ||
| case 'uniqueItems': return `不得有重複項目`; | ||
| case '~guard': return `必須與檢查函數匹配`; | ||
| case '~refine': return error.params.message; | ||
@@ -39,0 +38,0 @@ default: return '發生未知驗證錯誤'; |
| /** | ||
| * Clones a value using the TypeBox type cloning strategy. This function preserves non-enumerable | ||
| * properties from the source value. This is to ensure cloned types retain discriminable | ||
| * hidden properties. | ||
| * Returns a Clone of the given value. This function is similar to structuredClone() | ||
| * but also supports deep cloning instances of Map, Set and TypeArray. | ||
| */ | ||
| export declare function Clone<Value extends unknown = unknown>(value: Value): Value; |
| // deno-fmt-ignore-file | ||
| import { Guard } from '../../guard/index.mjs'; | ||
| import { Guard, GlobalsGuard } from '../../guard/index.mjs'; | ||
| import { Metrics } from './metrics.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // Guard | ||
| // ClassInstance | ||
| // | ||
| // TypeBox does not clone arbitrary class instances. Class instances | ||
| // cannot be safely cloned without potentially breaking private | ||
| // members of the instance. | ||
| // | ||
| // ------------------------------------------------------------------ | ||
| function IsGuard(value) { | ||
| return Guard.IsObject(value) && Guard.HasPropertyKey(value, '~guard'); | ||
| function FromClassInstance(value) { | ||
| return value; // atomic | ||
| } | ||
| function FromGuard(value) { | ||
| return value; // non-clonable | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Array | ||
| // KindedObject | ||
| // | ||
| // Types have non-enumerable properties that MUST be preserved on Clone. | ||
| // The following is the optimal path for TypeBox types. | ||
| // ------------------------------------------------------------------ | ||
| function FromArray(value) { | ||
| return value.map((value) => FromValue(value)); | ||
| function IsKindedObject(value) { | ||
| return Guard.HasPropertyKey(value, '~kind'); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Object | ||
| // ------------------------------------------------------------------ | ||
| function FromObject(value) { | ||
| function FromKindedObject(value) { | ||
| const result = {}; | ||
| const descriptors = Object.getOwnPropertyDescriptors(value); | ||
| for (const key of Object.keys(descriptors)) { | ||
| if (Guard.IsUnsafePropertyKey(key)) | ||
| continue; // (ignore: prototype-pollution) | ||
| const descriptor = descriptors[key]; | ||
@@ -34,2 +38,37 @@ if (Guard.HasPropertyKey(descriptor, 'value')) { | ||
| // ------------------------------------------------------------------ | ||
| // PlainObject | ||
| // ------------------------------------------------------------------ | ||
| function FromPlainObject(value) { | ||
| const result = {}; | ||
| for (const key of Guard.Keys(value)) { | ||
| if (Guard.IsUnsafePropertyKey(key)) | ||
| continue; // (ignore: prototype-pollution) | ||
| result[key] = FromValue(value[key]); | ||
| } | ||
| for (const key of Guard.Symbols(value)) { | ||
| result[key] = FromValue(value[key]); | ||
| } | ||
| return result; | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Object | ||
| // ------------------------------------------------------------------ | ||
| function FromObject(value) { | ||
| return (Guard.IsClassInstance(value) ? FromClassInstance(value) : | ||
| IsKindedObject(value) ? FromKindedObject(value) : | ||
| FromPlainObject(value)); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Array | ||
| // ------------------------------------------------------------------ | ||
| function FromArray(value) { | ||
| return value.map((element) => FromValue(element)); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // TypeArray | ||
| // ------------------------------------------------------------------ | ||
| function FromTypedArray(value) { | ||
| return value.slice(); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // RegExp | ||
@@ -41,21 +80,28 @@ // ------------------------------------------------------------------ | ||
| // ------------------------------------------------------------------ | ||
| // RegExp | ||
| // Map | ||
| // ------------------------------------------------------------------ | ||
| function FromUnknown(value) { | ||
| return value; | ||
| function FromMap(value) { | ||
| return new Map(FromValue([...value.entries()])); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Value | ||
| // Set | ||
| // ------------------------------------------------------------------ | ||
| function FromSet(value) { | ||
| return new Set(FromValue([...value.values()])); | ||
| } | ||
| function FromValue(value) { | ||
| return (value instanceof RegExp ? FromRegExp(value) : | ||
| IsGuard(value) ? FromGuard(value) : | ||
| Guard.IsArray(value) ? FromArray(value) : | ||
| Guard.IsObject(value) ? FromObject(value) : | ||
| FromUnknown(value)); | ||
| return (GlobalsGuard.IsTypeArray(value) ? FromTypedArray(value) : | ||
| GlobalsGuard.IsRegExp(value) ? FromRegExp(value) : | ||
| GlobalsGuard.IsMap(value) ? FromMap(value) : | ||
| GlobalsGuard.IsSet(value) ? FromSet(value) : | ||
| Guard.IsArray(value) ? FromArray(value) : | ||
| Guard.IsObject(value) ? FromObject(value) : | ||
| value); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Clone | ||
| // ------------------------------------------------------------------ | ||
| /** | ||
| * Clones a value using the TypeBox type cloning strategy. This function preserves non-enumerable | ||
| * properties from the source value. This is to ensure cloned types retain discriminable | ||
| * hidden properties. | ||
| * Returns a Clone of the given value. This function is similar to structuredClone() | ||
| * but also supports deep cloning instances of Map, Set and TypeArray. | ||
| */ | ||
@@ -62,0 +108,0 @@ export function Clone(value) { |
@@ -7,3 +7,2 @@ export * from './_add_immutable.mjs'; | ||
| export * from './_remove_optional.mjs'; | ||
| export * from './awaited.mjs'; | ||
| export * from './capitalize.mjs'; | ||
@@ -10,0 +9,0 @@ export * from './conditional.mjs'; |
@@ -7,3 +7,2 @@ export * from './_add_immutable.mjs'; | ||
| export * from './_remove_optional.mjs'; | ||
| export * from './awaited.mjs'; | ||
| export * from './capitalize.mjs'; | ||
@@ -10,0 +9,0 @@ export * from './conditional.mjs'; |
@@ -12,6 +12,1 @@ import { type TSchema, type TSchemaOptions } from '../types/schema.mjs'; | ||
| export declare function ReadonlyObject<Type extends TSchema>(type: Type, options?: TSchemaOptions): TReadonlyObject<Type>; | ||
| /** | ||
| * This type has been renamed to ReadonlyObject. | ||
| * @deprecated | ||
| */ | ||
| export declare const ReadonlyType: typeof ReadonlyObject; |
@@ -12,6 +12,1 @@ // deno-fmt-ignore-file | ||
| } | ||
| /** | ||
| * This type has been renamed to ReadonlyObject. | ||
| * @deprecated | ||
| */ | ||
| export const ReadonlyType = ReadonlyObject; |
@@ -12,11 +12,1 @@ import { type TSchema } from '../types/schema.mjs'; | ||
| export declare function With<Type extends TSchema, const Options extends TSchema>(type: Type, options: Options): TWithAction<Type, Options>; | ||
| /** | ||
| * @deprecated Type.TOptions\<T\> has been renamed to Type.TWith\<T\>. This type will be removed in the | ||
| * next version of TypeBox. | ||
| */ | ||
| export type TOptions<Type extends TSchema, Options extends TSchema> = TWith<Type, Options>; | ||
| /** | ||
| * @deprecated Type.Options\<T\> has been renamed to Type.With\<T\>. This type will be removed in the | ||
| * next version of TypeBox. | ||
| */ | ||
| export declare function Options<Type extends TSchema, const Options extends TSchema>(type: Type, options: Options): TOptions<Type, Options>; |
@@ -12,9 +12,1 @@ // deno-fmt-ignore-file | ||
| } | ||
| /** | ||
| * @deprecated Type.Options\<T\> has been renamed to Type.With\<T\>. This type will be removed in the | ||
| * next version of TypeBox. | ||
| */ | ||
| export function Options(type, options) { | ||
| return With(type, options); | ||
| } | ||
| // deno-coverage-ignore-stop |
| import { type TSchema } from '../../types/schema.mjs'; | ||
| import { type TArray } from '../../types/array.mjs'; | ||
| import { type TAsyncIterator } from '../../types/async_iterator.mjs'; | ||
| import { type TConstructor } from '../../types/constructor.mjs'; | ||
| import { type TFunction } from '../../types/function.mjs'; | ||
| import { type TIntersect } from '../../types/intersect.mjs'; | ||
| import { type TIterator } from '../../types/iterator.mjs'; | ||
| import { type TObject } from '../../types/object.mjs'; | ||
| import { type TPromise } from '../../types/promise.mjs'; | ||
| import { type TProperties, type TPropertyValues } from '../../types/properties.mjs'; | ||
@@ -19,3 +16,3 @@ import { type TRecord } from '../../types/record.mjs'; | ||
| type TFromTypes<Stack extends (keyof Context)[], Context extends TProperties, Types extends TSchema[]> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromType<Stack, Context, Left> extends true ? true : TFromTypes<Stack, Context, Right> : false; | ||
| type TFromType<Stack extends (keyof Context)[], Context extends TProperties, Type extends TSchema> = (Type extends TRef<infer Ref extends string> ? TFromRef<Stack, Context, Ref> : Type extends TArray<infer Type extends TSchema> ? TFromType<Stack, Context, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromType<Stack, Context, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromTypes<Stack, Context, [...Parameters, InstanceType]> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromTypes<Stack, Context, [...Parameters, ReturnType]> : Type extends TInterfaceDeferred<TSchema[], infer Properties extends TProperties> ? TFromProperties<Stack, Context, Properties> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromTypes<Stack, Context, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromType<Stack, Context, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromProperties<Stack, Context, Properties> : Type extends TPromise<infer Type extends TSchema> ? TFromType<Stack, Context, Type> : Type extends TUnion<infer Types extends TSchema[]> ? TFromTypes<Stack, Context, Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTypes<Stack, Context, Types> : Type extends TRecord<string, infer Type extends TSchema> ? TFromType<Stack, Context, Type> : false); | ||
| type TFromType<Stack extends (keyof Context)[], Context extends TProperties, Type extends TSchema> = (Type extends TRef<infer Ref extends string> ? TFromRef<Stack, Context, Ref> : Type extends TArray<infer Type extends TSchema> ? TFromType<Stack, Context, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromTypes<Stack, Context, [...Parameters, InstanceType]> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromTypes<Stack, Context, [...Parameters, ReturnType]> : Type extends TInterfaceDeferred<TSchema[], infer Properties extends TProperties> ? TFromProperties<Stack, Context, Properties> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromTypes<Stack, Context, Types> : Type extends TObject<infer Properties extends TProperties> ? TFromProperties<Stack, Context, Properties> : Type extends TUnion<infer Types extends TSchema[]> ? TFromTypes<Stack, Context, Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTypes<Stack, Context, Types> : Type extends TRecord<string, infer Type extends TSchema> ? TFromType<Stack, Context, Type> : false); | ||
| /** Performs a cyclic check on the given type. Initial key stack can be empty, but faster if specified */ | ||
@@ -22,0 +19,0 @@ export type TCyclicCheck<Stack extends (keyof Context)[], Context extends TProperties, Type extends TSchema, Result extends boolean = TFromType<Stack, Context, Type>> = Result; |
| // deno-fmt-ignore-file | ||
| import { Guard } from '../../../guard/index.mjs'; | ||
| import { IsArray } from '../../types/array.mjs'; | ||
| import { IsAsyncIterator } from '../../types/async_iterator.mjs'; | ||
| import { IsConstructor } from '../../types/constructor.mjs'; | ||
| import { IsFunction } from '../../types/function.mjs'; | ||
| import { IsIntersect } from '../../types/intersect.mjs'; | ||
| import { IsIterator } from '../../types/iterator.mjs'; | ||
| import { IsObject } from '../../types/object.mjs'; | ||
| import { IsPromise } from '../../types/promise.mjs'; | ||
| import { PropertyValues } from '../../types/properties.mjs'; | ||
@@ -34,14 +31,11 @@ import { IsRecord, RecordValue } from '../../types/record.mjs'; | ||
| IsArray(type) ? FromType(stack, context, type.items) : | ||
| IsAsyncIterator(type) ? FromType(stack, context, type.iteratorItems) : | ||
| IsConstructor(type) ? FromTypes(stack, context, [...type.parameters, type.instanceType]) : | ||
| IsFunction(type) ? FromTypes(stack, context, [...type.parameters, type.returnType]) : | ||
| IsInterfaceDeferred(type) ? FromProperties(stack, context, type.parameters[1]) : | ||
| IsIntersect(type) ? FromTypes(stack, context, type.allOf) : | ||
| IsIterator(type) ? FromType(stack, context, type.iteratorItems) : | ||
| IsObject(type) ? FromProperties(stack, context, type.properties) : | ||
| IsPromise(type) ? FromType(stack, context, type.item) : | ||
| IsUnion(type) ? FromTypes(stack, context, type.anyOf) : | ||
| IsTuple(type) ? FromTypes(stack, context, type.items) : | ||
| IsRecord(type) ? FromType(stack, context, RecordValue(type)) : | ||
| false); | ||
| IsConstructor(type) ? FromTypes(stack, context, [...type.parameters, type.instanceType]) : | ||
| IsFunction(type) ? FromTypes(stack, context, [...type.parameters, type.returnType]) : | ||
| IsInterfaceDeferred(type) ? FromProperties(stack, context, type.parameters[1]) : | ||
| IsIntersect(type) ? FromTypes(stack, context, type.allOf) : | ||
| IsObject(type) ? FromProperties(stack, context, type.properties) : | ||
| IsUnion(type) ? FromTypes(stack, context, type.anyOf) : | ||
| IsTuple(type) ? FromTypes(stack, context, type.items) : | ||
| IsRecord(type) ? FromType(stack, context, RecordValue(type)) : | ||
| false); | ||
| } | ||
@@ -48,0 +42,0 @@ /** Performs a cyclic check on the given type. Initial key stack can be empty, but faster if specified */ |
| import { type TUnreachable } from '../../../system/unreachable/index.mjs'; | ||
| import { type TSchema } from '../../types/schema.mjs'; | ||
| import { type TArray } from '../../types/array.mjs'; | ||
| import { type TAsyncIterator } from '../../types/async_iterator.mjs'; | ||
| import { type TConstructor } from '../../types/constructor.mjs'; | ||
| import { type TFunction } from '../../types/function.mjs'; | ||
| import { type TIntersect } from '../../types/intersect.mjs'; | ||
| import { type TIterator } from '../../types/iterator.mjs'; | ||
| import { type TObject } from '../../types/object.mjs'; | ||
| import { type TPromise } from '../../types/promise.mjs'; | ||
| import { type TProperties, type TPropertyValues } from '../../types/properties.mjs'; | ||
@@ -20,3 +17,3 @@ import { type TRecord } from '../../types/record.mjs'; | ||
| type TFromTypes<Context extends TProperties, Types extends TSchema[], Dependencies extends string[]> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Context, Right, TFromType<Context, Left, Dependencies>> : Dependencies; | ||
| type TFromType<Context extends TProperties, Type extends TSchema, Result extends string[]> = (Type extends TRef<infer Ref extends string> ? TFromRef<Context, Ref, Result> : Type extends TArray<infer Type extends TSchema> ? TFromType<Context, Type, Result> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromType<Context, Type, Result> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromTypes<Context, [...Parameters, InstanceType], Result> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromTypes<Context, [...Parameters, ReturnType], Result> : Type extends TInterfaceDeferred<TSchema[], infer Properties extends TProperties> ? TFromProperties<Context, Properties, Result> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromTypes<Context, Types, Result> : Type extends TIterator<infer Type extends TSchema> ? TFromType<Context, Type, Result> : Type extends TObject<infer Properties extends TProperties> ? TFromProperties<Context, Properties, Result> : Type extends TPromise<infer Type extends TSchema> ? TFromType<Context, Type, Result> : Type extends TUnion<infer Types extends TSchema[]> ? TFromTypes<Context, Types, Result> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTypes<Context, Types, Result> : Type extends TRecord<string, infer Type extends TSchema> ? TFromType<Context, Type, Result> : Result); | ||
| type TFromType<Context extends TProperties, Type extends TSchema, Result extends string[]> = (Type extends TRef<infer Ref extends string> ? TFromRef<Context, Ref, Result> : Type extends TArray<infer Type extends TSchema> ? TFromType<Context, Type, Result> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromTypes<Context, [...Parameters, InstanceType], Result> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromTypes<Context, [...Parameters, ReturnType], Result> : Type extends TInterfaceDeferred<TSchema[], infer Properties extends TProperties> ? TFromProperties<Context, Properties, Result> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromTypes<Context, Types, Result> : Type extends TObject<infer Properties extends TProperties> ? TFromProperties<Context, Properties, Result> : Type extends TUnion<infer Types extends TSchema[]> ? TFromTypes<Context, Types, Result> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTypes<Context, Types, Result> : Type extends TRecord<string, infer Type extends TSchema> ? TFromType<Context, Type, Result> : Result); | ||
| /** Returns dependent cyclic keys for the given type. This function is used to dead-type-eliminate (DTE) for initializing TCyclic types. */ | ||
@@ -23,0 +20,0 @@ export type TCyclicDependencies<Context extends TProperties, Key extends string, Type extends TSchema, Result extends string[] = TFromType<Context, Type, [Key]>> = Result; |
| // deno-fmt-ignore-file | ||
| import { Unreachable } from '../../../system/unreachable/index.mjs'; | ||
| import { IsArray } from '../../types/array.mjs'; | ||
| import { IsAsyncIterator } from '../../types/async_iterator.mjs'; | ||
| import { IsConstructor } from '../../types/constructor.mjs'; | ||
| import { IsFunction } from '../../types/function.mjs'; | ||
| import { IsIntersect } from '../../types/intersect.mjs'; | ||
| import { IsIterator } from '../../types/iterator.mjs'; | ||
| import { IsObject } from '../../types/object.mjs'; | ||
| import { IsPromise } from '../../types/promise.mjs'; | ||
| import { PropertyValues } from '../../types/properties.mjs'; | ||
@@ -36,14 +33,11 @@ import { IsRecord, RecordValue } from '../../types/record.mjs'; | ||
| IsArray(type) ? FromType(context, type.items, result) : | ||
| IsAsyncIterator(type) ? FromType(context, type.iteratorItems, result) : | ||
| IsConstructor(type) ? FromTypes(context, [...type.parameters, type.instanceType], result) : | ||
| IsFunction(type) ? FromTypes(context, [...type.parameters, type.returnType], result) : | ||
| IsInterfaceDeferred(type) ? FromProperties(context, type.parameters[1], result) : | ||
| IsIntersect(type) ? FromTypes(context, type.allOf, result) : | ||
| IsIterator(type) ? FromType(context, type.iteratorItems, result) : | ||
| IsObject(type) ? FromProperties(context, type.properties, result) : | ||
| IsPromise(type) ? FromType(context, type.item, result) : | ||
| IsUnion(type) ? FromTypes(context, type.anyOf, result) : | ||
| IsTuple(type) ? FromTypes(context, type.items, result) : | ||
| IsRecord(type) ? FromType(context, RecordValue(type), result) : | ||
| result); | ||
| IsConstructor(type) ? FromTypes(context, [...type.parameters, type.instanceType], result) : | ||
| IsFunction(type) ? FromTypes(context, [...type.parameters, type.returnType], result) : | ||
| IsInterfaceDeferred(type) ? FromProperties(context, type.parameters[1], result) : | ||
| IsIntersect(type) ? FromTypes(context, type.allOf, result) : | ||
| IsObject(type) ? FromProperties(context, type.properties, result) : | ||
| IsUnion(type) ? FromTypes(context, type.anyOf, result) : | ||
| IsTuple(type) ? FromTypes(context, type.items, result) : | ||
| IsRecord(type) ? FromType(context, RecordValue(type), result) : | ||
| result); | ||
| } | ||
@@ -50,0 +44,0 @@ /** Returns dependent cyclic keys for the given type. This function is used to dead-type-eliminate (DTE) for initializing TCyclic types. */ |
| import { type TSchema } from '../../types/schema.mjs'; | ||
| import { type TAny } from '../../types/any.mjs'; | ||
| import { type TArray } from '../../types/array.mjs'; | ||
| import { type TAsyncIterator } from '../../types/async_iterator.mjs'; | ||
| import { type TConstructor } from '../../types/constructor.mjs'; | ||
@@ -9,5 +8,3 @@ import { type TCyclic } from '../../types/cyclic.mjs'; | ||
| import { type TIntersect } from '../../types/intersect.mjs'; | ||
| import { type TIterator } from '../../types/iterator.mjs'; | ||
| import { type TObject } from '../../types/object.mjs'; | ||
| import { type TPromise } from '../../types/promise.mjs'; | ||
| import { type TProperties } from '../../types/properties.mjs'; | ||
@@ -26,3 +23,3 @@ import { type TRecord } from '../../types/record.mjs'; | ||
| type TFromTypes<Types extends TSchema[], Result extends TSchema[] = []> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Right, [...Result, TFromType<Left>]> : Result; | ||
| type TFromType<Type extends TSchema> = (Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TFromType<Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TFromType<Type>> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFunction<TFromTypes<Parameters>, TFromType<InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TFromTypes<Parameters>, TFromType<ReturnType>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromTypes<Types>> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TFromType<Type>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TFromProperties<Properties>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TFromType<Type>> : Type extends TRecord<infer Pattern extends string, infer Value extends TSchema> ? TRecord<Pattern, TFromType<Value>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromTypes<Types>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TFromTypes<Types>> : Type); | ||
| type TFromType<Type extends TSchema> = (Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TFromType<Type>> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFunction<TFromTypes<Parameters>, TFromType<InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TFromTypes<Parameters>, TFromType<ReturnType>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromTypes<Types>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TFromProperties<Properties>> : Type extends TRecord<infer Pattern extends string, infer Value extends TSchema> ? TRecord<Pattern, TFromType<Value>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromTypes<Types>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TFromTypes<Types>> : Type); | ||
| type TCyclicAnyFromParameters<Defs extends TProperties, Ref extends string> = (Ref extends keyof Defs ? TFromType<Defs[Ref]> : TUnknown); | ||
@@ -29,0 +26,0 @@ /** Transforms TCyclic TRef's into TAny's. This function is used prior to TExtends checks to enable cyclics to be structurally checked and terminated (with TAny) at first point of recursion, what would otherwise be a recursive TRef.*/ |
@@ -5,9 +5,6 @@ // deno-fmt-ignore-file | ||
| import { Array as _Array_, IsArray, ArrayOptions } from '../../types/array.mjs'; | ||
| import { AsyncIterator, IsAsyncIterator } from '../../types/async_iterator.mjs'; | ||
| import { Constructor, IsConstructor } from '../../types/constructor.mjs'; | ||
| import { Function as _Function_, IsFunction } from '../../types/function.mjs'; | ||
| import { Intersect, IsIntersect } from '../../types/intersect.mjs'; | ||
| import { Iterator, IsIterator } from '../../types/iterator.mjs'; | ||
| import { Object, IsObject } from '../../types/object.mjs'; | ||
| import { Promise, IsPromise } from '../../types/promise.mjs'; | ||
| import { IsRecord, Record, RecordKey, RecordValue } from '../../types/record.mjs'; | ||
@@ -34,13 +31,10 @@ import { IsRef } from '../../types/ref.mjs'; | ||
| IsArray(type) ? _Array_(FromType(type.items), ArrayOptions(type)) : | ||
| IsAsyncIterator(type) ? AsyncIterator(FromType(type.iteratorItems)) : | ||
| IsConstructor(type) ? Constructor(FromTypes(type.parameters), FromType(type.instanceType)) : | ||
| IsFunction(type) ? _Function_(FromTypes(type.parameters), FromType(type.returnType)) : | ||
| IsIntersect(type) ? Intersect(FromTypes(type.allOf)) : | ||
| IsIterator(type) ? Iterator(FromType(type.iteratorItems)) : | ||
| IsObject(type) ? Object(FromProperties(type.properties)) : | ||
| IsPromise(type) ? Promise(FromType(type.item)) : | ||
| IsRecord(type) ? Record(RecordKey(type), FromType(RecordValue(type))) : | ||
| IsUnion(type) ? Union(FromTypes(type.anyOf)) : | ||
| IsTuple(type) ? Tuple(FromTypes(type.items)) : | ||
| type); | ||
| IsConstructor(type) ? Constructor(FromTypes(type.parameters), FromType(type.instanceType)) : | ||
| IsFunction(type) ? _Function_(FromTypes(type.parameters), FromType(type.returnType)) : | ||
| IsIntersect(type) ? Intersect(FromTypes(type.allOf)) : | ||
| IsObject(type) ? Object(FromProperties(type.properties)) : | ||
| IsRecord(type) ? Record(RecordKey(type), FromType(RecordValue(type))) : | ||
| IsUnion(type) ? Union(FromTypes(type.anyOf)) : | ||
| IsTuple(type) ? Tuple(FromTypes(type.items)) : | ||
| type); | ||
| } | ||
@@ -47,0 +41,0 @@ function CyclicAnyFromParameters(defs, ref) { |
| export { Instantiate, type TInstantiate } from './instantiate.mjs'; | ||
| export * from './awaited/index.mjs'; | ||
| export * from './conditional/index.mjs'; | ||
@@ -4,0 +3,0 @@ export * from './constructor_parameters/index.mjs'; |
@@ -8,3 +8,2 @@ // ------------------------------------------------------------------ | ||
| // ------------------------------------------------------------------ | ||
| export * from './awaited/index.mjs'; | ||
| export * from './conditional/index.mjs'; | ||
@@ -11,0 +10,0 @@ export * from './constructor_parameters/index.mjs'; |
@@ -6,3 +6,2 @@ import { type TAddImmutableAction } from './immutable/instantiate_add.mjs'; | ||
| import { type TArray } from '../types/array.mjs'; | ||
| import { type TAsyncIterator } from '../types/async_iterator.mjs'; | ||
| import { type TConstructor } from '../types/constructor.mjs'; | ||
@@ -15,5 +14,3 @@ import { type TDeferred } from '../types/deferred.mjs'; | ||
| import { type TIntersect } from '../types/intersect.mjs'; | ||
| import { type TIterator } from '../types/iterator.mjs'; | ||
| import { type TObject } from '../types/object.mjs'; | ||
| import { type TPromise } from '../types/promise.mjs'; | ||
| import { type TProperties } from '../types/properties.mjs'; | ||
@@ -34,3 +31,2 @@ import { type TRecord } from '../types/record.mjs'; | ||
| import { type TReadonly } from '../types/_readonly.mjs'; | ||
| import { type TAwaitedInstantiate } from './awaited/instantiate.mjs'; | ||
| import { type TCallInstantiate } from './call/instantiate.mjs'; | ||
@@ -102,5 +98,2 @@ import { type TCapitalizeInstantiate } from './intrinsics/instantiate.mjs'; | ||
| Parameters | ||
| ] extends ['Awaited', [infer Type extends TSchema]] ? TAwaitedInstantiate<Context, State, Type> : [ | ||
| Action, | ||
| Parameters | ||
| ] extends ['Capitalize', [infer Type extends TSchema]] ? TCapitalizeInstantiate<Context, State, Type> : [ | ||
@@ -182,3 +175,3 @@ Action, | ||
| ] extends ['With', [infer Type extends TSchema, infer Options extends TSchema]] ? TWithInstantiate<Context, State, Type, Options> : TDeferred<Action, Parameters>); | ||
| type TInstantiateImmediate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = (Type extends TRef<infer Ref extends string> ? TRefInstantiate<Context, State, Type, Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TInstantiateType<Context, State, Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TInstantiateType<Context, State, Type>> : Type extends TCall<infer Target extends TSchema, infer Parameters extends TSchema[]> ? TCallInstantiate<Context, State, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, ReturnType>> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TDependent<TInstantiateType<Context, State, If>, TInstantiateType<Context, State, Then>, TInstantiateType<Context, State, Else>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TInstantiateTypes<Context, State, Types>> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TInstantiateType<Context, State, Type>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TInstantiateProperties<Context, State, Properties>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TInstantiateType<Context, State, Type>> : Type extends TRecord<infer Key extends string, infer Type extends TSchema> ? TRecord<Key, TInstantiateType<Context, State, Type>> : Type extends TRest<infer Type extends TSchema> ? TRest<TInstantiateType<Context, State, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TInstantiateElements<Context, State, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TInstantiateTypes<Context, State, Types>> : Type), WithModifiers extends TSchema = TWithModifiers<Type, InstantiatedType>> = WithModifiers; | ||
| type TInstantiateImmediate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = (Type extends TRef<infer Ref extends string> ? TRefInstantiate<Context, State, Type, Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TInstantiateType<Context, State, Type>> : Type extends TCall<infer Target extends TSchema, infer Parameters extends TSchema[]> ? TCallInstantiate<Context, State, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, ReturnType>> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TDependent<TInstantiateType<Context, State, If>, TInstantiateType<Context, State, Then>, TInstantiateType<Context, State, Else>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TInstantiateTypes<Context, State, Types>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TInstantiateProperties<Context, State, Properties>> : Type extends TRecord<infer Key extends string, infer Type extends TSchema> ? TRecord<Key, TInstantiateType<Context, State, Type>> : Type extends TRest<infer Type extends TSchema> ? TRest<TInstantiateType<Context, State, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TInstantiateElements<Context, State, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TInstantiateTypes<Context, State, Types>> : Type), WithModifiers extends TSchema = TWithModifiers<Type, InstantiatedType>> = WithModifiers; | ||
| export type TInstantiateType<Context extends TProperties, State extends TState, Type extends TSchema, Result extends TSchema = Type extends TDeferred<infer Action extends string, infer Types extends TSchema[]> ? TInstantiateDeferred<Context, State, Action, Types> : TInstantiateImmediate<Context, State, Type>> = Result; | ||
@@ -185,0 +178,0 @@ export declare function InstantiateType<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type): TInstantiateImmediate<Context, State, Type>; |
@@ -11,3 +11,2 @@ // deno-fmt-ignore-file | ||
| import { _Array_, IsArray, ArrayOptions } from '../types/array.mjs'; | ||
| import { AsyncIterator, IsAsyncIterator, AsyncIteratorOptions } from '../types/async_iterator.mjs'; | ||
| import { Constructor, IsConstructor, ConstructorOptions } from '../types/constructor.mjs'; | ||
@@ -19,5 +18,3 @@ import { Deferred, IsDeferred } from '../types/deferred.mjs'; | ||
| import { Intersect, IsIntersect, IntersectOptions } from '../types/intersect.mjs'; | ||
| import { Iterator, IsIterator, IteratorOptions } from '../types/iterator.mjs'; | ||
| import { Object, IsObject, ObjectOptions } from '../types/object.mjs'; | ||
| import { _Promise_, IsPromise, PromiseOptions } from '../types/promise.mjs'; | ||
| import { RecordFromPattern, IsRecord, RecordPattern, RecordValue } from '../types/record.mjs'; | ||
@@ -43,3 +40,2 @@ import { Tuple, IsTuple, TupleOptions } from '../types/tuple.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| import { AwaitedInstantiate } from './awaited/instantiate.mjs'; | ||
| import { CallInstantiate } from './call/instantiate.mjs'; | ||
@@ -111,30 +107,29 @@ import { CapitalizeInstantiate } from './intrinsics/instantiate.mjs'; | ||
| // Actions | ||
| Guard.IsEqual(action, 'Awaited') ? AwaitedInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Capitalize') ? CapitalizeInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Conditional') ? ConditionalInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) : | ||
| Guard.IsEqual(action, 'ConstructorParameters') ? ConstructorParametersInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Evaluate') ? EvaluateInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Exclude') ? ExcludeInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'Extract') ? ExtractInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'Index') ? IndexInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'InstanceType') ? InstanceTypeInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Interface') ? InterfaceInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'KeyOf') ? KeyOfInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Lowercase') ? LowercaseInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Mapped') ? MappedInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) : | ||
| Guard.IsEqual(action, 'Module') ? ModuleInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'NonNullable') ? NonNullableInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Pick') ? PickInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'Parameters') ? ParametersInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Partial') ? PartialInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Omit') ? OmitInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'ReadonlyObject') ? ReadonlyObjectInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Record') ? RecordInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'Required') ? RequiredInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'ReturnType') ? ReturnTypeInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'TemplateLiteral') ? TemplateLiteralInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Uncapitalize') ? UncapitalizeInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Uppercase') ? UppercaseInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'With') ? WithInstantiate(context, state, parameters[0], parameters[1]) : | ||
| Deferred(action, parameters, options)); | ||
| Guard.IsEqual(action, 'Capitalize') ? CapitalizeInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Conditional') ? ConditionalInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) : | ||
| Guard.IsEqual(action, 'ConstructorParameters') ? ConstructorParametersInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Evaluate') ? EvaluateInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Exclude') ? ExcludeInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'Extract') ? ExtractInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'Index') ? IndexInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'InstanceType') ? InstanceTypeInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Interface') ? InterfaceInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'KeyOf') ? KeyOfInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Lowercase') ? LowercaseInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Mapped') ? MappedInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) : | ||
| Guard.IsEqual(action, 'Module') ? ModuleInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'NonNullable') ? NonNullableInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Pick') ? PickInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'Parameters') ? ParametersInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Partial') ? PartialInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Omit') ? OmitInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'ReadonlyObject') ? ReadonlyObjectInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Record') ? RecordInstantiate(context, state, parameters[0], parameters[1], options) : | ||
| Guard.IsEqual(action, 'Required') ? RequiredInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'ReturnType') ? ReturnTypeInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'TemplateLiteral') ? TemplateLiteralInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Uncapitalize') ? UncapitalizeInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'Uppercase') ? UppercaseInstantiate(context, state, parameters[0], options) : | ||
| Guard.IsEqual(action, 'With') ? WithInstantiate(context, state, parameters[0], parameters[1]) : | ||
| Deferred(action, parameters, options)); | ||
| } | ||
@@ -144,16 +139,13 @@ function InstantiateImmediate(context, state, type) { | ||
| IsArray(type) ? _Array_(InstantiateType(context, state, type.items), ArrayOptions(type)) : | ||
| IsAsyncIterator(type) ? AsyncIterator(InstantiateType(context, state, type.iteratorItems), AsyncIteratorOptions(type)) : | ||
| IsCall(type) ? CallInstantiate(context, state, type.target, type.arguments) : | ||
| IsConstructor(type) ? Constructor(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.instanceType), ConstructorOptions(type)) : | ||
| IsFunction(type) ? _Function_(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.returnType), FunctionOptions(type)) : | ||
| IsDependent(type) ? Dependent(InstantiateType(context, state, type.if), InstantiateType(context, state, type.then), InstantiateType(context, state, type.else), DependentOptions(type)) : | ||
| IsIntersect(type) ? Intersect(InstantiateTypes(context, state, type.allOf), IntersectOptions(type)) : | ||
| IsIterator(type) ? Iterator(InstantiateType(context, state, type.iteratorItems), IteratorOptions(type)) : | ||
| IsObject(type) ? Object(InstantiateProperties(context, state, type.properties), ObjectOptions(type)) : | ||
| IsPromise(type) ? _Promise_(InstantiateType(context, state, type.item), PromiseOptions(type)) : | ||
| IsRecord(type) ? RecordFromPattern(RecordPattern(type), InstantiateType(context, state, RecordValue(type))) : | ||
| IsRest(type) ? Rest(InstantiateType(context, state, type.items)) : | ||
| IsTuple(type) ? Tuple(InstantiateElements(context, state, type.items), TupleOptions(type)) : | ||
| IsUnion(type) ? Union(InstantiateTypes(context, state, type.anyOf), UnionOptions(type)) : | ||
| type); | ||
| IsCall(type) ? CallInstantiate(context, state, type.target, type.arguments) : | ||
| IsConstructor(type) ? Constructor(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.instanceType), ConstructorOptions(type)) : | ||
| IsFunction(type) ? _Function_(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.returnType), FunctionOptions(type)) : | ||
| IsDependent(type) ? Dependent(InstantiateType(context, state, type.if), InstantiateType(context, state, type.then), InstantiateType(context, state, type.else), DependentOptions(type)) : | ||
| IsIntersect(type) ? Intersect(InstantiateTypes(context, state, type.allOf), IntersectOptions(type)) : | ||
| IsObject(type) ? Object(InstantiateProperties(context, state, type.properties), ObjectOptions(type)) : | ||
| IsRecord(type) ? RecordFromPattern(RecordPattern(type), InstantiateType(context, state, RecordValue(type))) : | ||
| IsRest(type) ? Rest(InstantiateType(context, state, type.items)) : | ||
| IsTuple(type) ? Tuple(InstantiateElements(context, state, type.items), TupleOptions(type)) : | ||
| IsUnion(type) ? Union(InstantiateTypes(context, state, type.anyOf), UnionOptions(type)) : | ||
| type); | ||
| const withModifiers = WithModifiers(type, instantiatedType); | ||
@@ -160,0 +152,0 @@ return withModifiers; |
| import { type TArray } from '../../types/array.mjs'; | ||
| import { type TAsyncIterator } from '../../types/async_iterator.mjs'; | ||
| import { type TConstructor } from '../../types/constructor.mjs'; | ||
| import { type TFunction } from '../../types/function.mjs'; | ||
| import { type TIterator } from '../../types/iterator.mjs'; | ||
| import { type TIntersect } from '../../types/intersect.mjs'; | ||
@@ -10,3 +8,2 @@ import { type TObject } from '../../types/object.mjs'; | ||
| import { type TSchema } from '../../types/schema.mjs'; | ||
| import { type TPromise } from '../../types/promise.mjs'; | ||
| import { type TTuple } from '../../types/tuple.mjs'; | ||
@@ -16,3 +13,3 @@ import { type TThis } from '../../types/this.mjs'; | ||
| type TFromTypes<Properties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Properties, Right, [...Result, TFromType<Properties, Left>]> : Result); | ||
| export type TFromType<Properties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TArray<TFromType<Properties, Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TFromType<Properties, Type>> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TFromTypes<Properties, Parameters>, TFromType<Properties, InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TFromTypes<Properties, Parameters>, TFromType<Properties, ReturnType>> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TFromType<Properties, Type>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TFromType<Properties, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TFromTypes<Properties, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromTypes<Properties, Types>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromTypes<Properties, Types>> : Type extends TThis ? TObject<Properties> : Type); | ||
| export type TFromType<Properties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TArray<TFromType<Properties, Type>> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TFromTypes<Properties, Parameters>, TFromType<Properties, InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TFromTypes<Properties, Parameters>, TFromType<Properties, ReturnType>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TFromTypes<Properties, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromTypes<Properties, Types>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromTypes<Properties, Types>> : Type extends TThis ? TObject<Properties> : Type); | ||
| export declare function FromType<Properties extends TProperties, Type extends TSchema>(properties: Properties, type: Type): TFromType<Properties, Type>; | ||
@@ -19,0 +16,0 @@ export type TExpandThis<Properties extends TProperties, Type extends TSchema, Result extends TSchema = TFromType<Properties, Type>> = Result; |
| // deno-fmt-ignore-file | ||
| import { IsArray, _Array_ } from '../../types/array.mjs'; | ||
| import { IsAsyncIterator, AsyncIterator } from '../../types/async_iterator.mjs'; | ||
| import { IsConstructor, Constructor } from '../../types/constructor.mjs'; | ||
| import { IsFunction, _Function_ } from '../../types/function.mjs'; | ||
| import { IsIterator, Iterator } from '../../types/iterator.mjs'; | ||
| import { IsIntersect, Intersect } from '../../types/intersect.mjs'; | ||
| import { _Object_ } from '../../types/object.mjs'; | ||
| import { IsPromise, Promise } from '../../types/promise.mjs'; | ||
| import { IsTuple, Tuple } from '../../types/tuple.mjs'; | ||
@@ -18,12 +15,9 @@ import { IsThis } from '../../types/this.mjs'; | ||
| return (IsArray(type) ? _Array_(FromType(properties, type.items)) : | ||
| IsAsyncIterator(type) ? AsyncIterator(FromType(properties, type.iteratorItems)) : | ||
| IsConstructor(type) ? Constructor(FromTypes(properties, type.parameters), FromType(properties, type.instanceType)) : | ||
| IsFunction(type) ? _Function_(FromTypes(properties, type.parameters), FromType(properties, type.returnType)) : | ||
| IsIterator(type) ? Iterator(FromType(properties, type.iteratorItems)) : | ||
| IsPromise(type) ? Promise(FromType(properties, type.item)) : | ||
| IsTuple(type) ? Tuple(FromTypes(properties, type.items)) : | ||
| IsUnion(type) ? Union(FromTypes(properties, type.anyOf)) : | ||
| IsIntersect(type) ? Intersect(FromTypes(properties, type.allOf)) : | ||
| IsThis(type) ? _Object_(properties) : | ||
| type); | ||
| IsConstructor(type) ? Constructor(FromTypes(properties, type.parameters), FromType(properties, type.instanceType)) : | ||
| IsFunction(type) ? _Function_(FromTypes(properties, type.parameters), FromType(properties, type.returnType)) : | ||
| IsTuple(type) ? Tuple(FromTypes(properties, type.items)) : | ||
| IsUnion(type) ? Union(FromTypes(properties, type.anyOf)) : | ||
| IsIntersect(type) ? Intersect(FromTypes(properties, type.allOf)) : | ||
| IsThis(type) ? _Object_(properties) : | ||
| type); | ||
| } | ||
@@ -30,0 +24,0 @@ export function ExpandThis(properties, type) { |
| import { type TExtendsAny } from './any.mjs'; | ||
| import { type TExtendsArray } from './array.mjs'; | ||
| import { type TExtendsAsyncIterator } from './async_iterator.mjs'; | ||
| import { type TExtendsBigInt } from './bigint.mjs'; | ||
@@ -12,3 +11,2 @@ import { type TExtendsBoolean } from './boolean.mjs'; | ||
| import { type TExtendsIntersect } from './intersect.mjs'; | ||
| import { type TExtendsIterator } from './iterator.mjs'; | ||
| import { type TExtendsLiteral } from './literal.mjs'; | ||
@@ -19,3 +17,2 @@ import { type TExtendsNever } from './never.mjs'; | ||
| import { type TExtendsObject } from './object.mjs'; | ||
| import { type TExtendsPromise } from './promise.mjs'; | ||
| import { type TExtendsRecord } from './record.mjs'; | ||
@@ -32,3 +29,2 @@ import { type TExtendsString } from './string.mjs'; | ||
| import { type TArray } from '../types/array.mjs'; | ||
| import { type TAsyncIterator } from '../types/async_iterator.mjs'; | ||
| import { type TBigInt } from '../types/bigint.mjs'; | ||
@@ -42,3 +38,2 @@ import { type TBoolean } from '../types/boolean.mjs'; | ||
| import { type TIntersect } from '../types/intersect.mjs'; | ||
| import { type TIterator } from '../types/iterator.mjs'; | ||
| import { type TLiteral } from '../types/literal.mjs'; | ||
@@ -49,3 +44,2 @@ import { type TNever } from '../types/never.mjs'; | ||
| import { type TObject } from '../types/object.mjs'; | ||
| import { type TPromise } from '../types/promise.mjs'; | ||
| import { type TRecord } from '../types/record.mjs'; | ||
@@ -63,3 +57,3 @@ import { type TSchema } from '../types/schema.mjs'; | ||
| import * as Result from './result.mjs'; | ||
| export type TExtendsLeft<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Left extends TAny ? TExtendsAny<Inferred, Left, Right> : Left extends TArray<infer Items extends TSchema> ? TExtendsArray<Inferred, Left, Items, Right> : Left extends TAsyncIterator<infer Type extends TSchema> ? TExtendsAsyncIterator<Inferred, Type, Right> : Left extends TBigInt ? TExtendsBigInt<Inferred, Left, Right> : Left extends TBoolean ? TExtendsBoolean<Inferred, Left, Right> : Left extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TExtendsConstructor<Inferred, Parameters, InstanceType, Right> : Left extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TExtendsDependent<Inferred, If, Then, Else, Right> : Left extends TEnum<infer Values extends TEnumValue[]> ? TExtendsEnum<Inferred, Values, Right> : Left extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TExtendsFunction<Inferred, Parameters, ReturnType, Right> : Left extends TInteger ? TExtendsInteger<Inferred, Left, Right> : Left extends TIntersect<infer Types extends TSchema[]> ? TExtendsIntersect<Inferred, Types, Right> : Left extends TIterator<infer Type extends TSchema> ? TExtendsIterator<Inferred, Type, Right> : Left extends TLiteral ? TExtendsLiteral<Inferred, Left, Right> : Left extends TNever ? TExtendsNever<Inferred, Left, Right> : Left extends TNull ? TExtendsNull<Inferred, Left, Right> : Left extends TNumber ? TExtendsNumber<Inferred, Left, Right> : Left extends TObject<infer Properties extends TProperties> ? TExtendsObject<Inferred, Properties, Right> : Left extends TPromise<infer Type extends TSchema> ? TExtendsPromise<Inferred, Type, Right> : Left extends TRecord<infer Pattern extends string, infer Value extends TSchema> ? TExtendsRecord<Inferred, Pattern, Value, Right> : Left extends TString ? TExtendsString<Inferred, Left, Right> : Left extends TSymbol ? TExtendsSymbol<Inferred, Left, Right> : Left extends TTemplateLiteral<infer Pattern extends string> ? TExtendsTemplateLiteral<Inferred, Pattern, Right> : Left extends TTuple<infer Types extends TSchema[]> ? TExtendsTuple<Inferred, Types, Right> : Left extends TUndefined ? TExtendsUndefined<Inferred, Left, Right> : Left extends TUnion<infer Types extends TSchema[]> ? TExtendsUnion<Inferred, Types, Right> : Left extends TUnknown ? TExtendsUnknown<Inferred, Left, Right> : Left extends TVoid ? TExtendsVoid<Inferred, Left, Right> : Result.TExtendsFalse); | ||
| export type TExtendsLeft<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Left extends TAny ? TExtendsAny<Inferred, Left, Right> : Left extends TArray<infer Items extends TSchema> ? TExtendsArray<Inferred, Left, Items, Right> : Left extends TBigInt ? TExtendsBigInt<Inferred, Left, Right> : Left extends TBoolean ? TExtendsBoolean<Inferred, Left, Right> : Left extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TExtendsConstructor<Inferred, Parameters, InstanceType, Right> : Left extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TExtendsDependent<Inferred, If, Then, Else, Right> : Left extends TEnum<infer Values extends TEnumValue[]> ? TExtendsEnum<Inferred, Values, Right> : Left extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TExtendsFunction<Inferred, Parameters, ReturnType, Right> : Left extends TInteger ? TExtendsInteger<Inferred, Left, Right> : Left extends TIntersect<infer Types extends TSchema[]> ? TExtendsIntersect<Inferred, Types, Right> : Left extends TLiteral ? TExtendsLiteral<Inferred, Left, Right> : Left extends TNever ? TExtendsNever<Inferred, Left, Right> : Left extends TNull ? TExtendsNull<Inferred, Left, Right> : Left extends TNumber ? TExtendsNumber<Inferred, Left, Right> : Left extends TObject<infer Properties extends TProperties> ? TExtendsObject<Inferred, Properties, Right> : Left extends TRecord<infer Pattern extends string, infer Value extends TSchema> ? TExtendsRecord<Inferred, Pattern, Value, Right> : Left extends TString ? TExtendsString<Inferred, Left, Right> : Left extends TSymbol ? TExtendsSymbol<Inferred, Left, Right> : Left extends TTemplateLiteral<infer Pattern extends string> ? TExtendsTemplateLiteral<Inferred, Pattern, Right> : Left extends TTuple<infer Types extends TSchema[]> ? TExtendsTuple<Inferred, Types, Right> : Left extends TUndefined ? TExtendsUndefined<Inferred, Left, Right> : Left extends TUnion<infer Types extends TSchema[]> ? TExtendsUnion<Inferred, Types, Right> : Left extends TUnknown ? TExtendsUnknown<Inferred, Left, Right> : Left extends TVoid ? TExtendsVoid<Inferred, Left, Right> : Result.TExtendsFalse); | ||
| export declare function ExtendsLeft<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsLeft<Inferred, Left, Right>; |
| // deno-fmt-ignore-file | ||
| import { ExtendsAny } from './any.mjs'; | ||
| import { ExtendsArray } from './array.mjs'; | ||
| import { ExtendsAsyncIterator } from './async_iterator.mjs'; | ||
| import { ExtendsBigInt } from './bigint.mjs'; | ||
@@ -13,3 +12,2 @@ import { ExtendsBoolean } from './boolean.mjs'; | ||
| import { ExtendsIntersect } from './intersect.mjs'; | ||
| import { ExtendsIterator } from './iterator.mjs'; | ||
| import { ExtendsLiteral } from './literal.mjs'; | ||
@@ -20,3 +18,2 @@ import { ExtendsNever } from './never.mjs'; | ||
| import { ExtendsObject } from './object.mjs'; | ||
| import { ExtendsPromise } from './promise.mjs'; | ||
| import { ExtendsRecord } from './record.mjs'; | ||
@@ -36,3 +33,2 @@ import { ExtendsString } from './string.mjs'; | ||
| import { IsArray } from '../types/array.mjs'; | ||
| import { IsAsyncIterator } from '../types/async_iterator.mjs'; | ||
| import { IsBigInt } from '../types/bigint.mjs'; | ||
@@ -46,3 +42,2 @@ import { IsBoolean } from '../types/boolean.mjs'; | ||
| import { IsIntersect } from '../types/intersect.mjs'; | ||
| import { IsIterator } from '../types/iterator.mjs'; | ||
| import { IsLiteral } from '../types/literal.mjs'; | ||
@@ -53,3 +48,2 @@ import { IsNever } from '../types/never.mjs'; | ||
| import { IsObject } from '../types/object.mjs'; | ||
| import { IsPromise } from '../types/promise.mjs'; | ||
| import { IsRecord, RecordPattern, RecordValue } from '../types/record.mjs'; | ||
@@ -68,28 +62,25 @@ import { IsString } from '../types/string.mjs'; | ||
| IsArray(left) ? ExtendsArray(inferred, left, left.items, right) : | ||
| IsAsyncIterator(left) ? ExtendsAsyncIterator(inferred, left.iteratorItems, right) : | ||
| IsBigInt(left) ? ExtendsBigInt(inferred, left, right) : | ||
| IsBoolean(left) ? ExtendsBoolean(inferred, left, right) : | ||
| IsConstructor(left) ? ExtendsConstructor(inferred, left.parameters, left.instanceType, right) : | ||
| IsDependent(left) ? ExtendsDependent(inferred, left.if, left.then, left.else, right) : | ||
| IsEnum(left) ? ExtendsEnum(inferred, left.enum, right) : | ||
| IsFunction(left) ? ExtendsFunction(inferred, left.parameters, left.returnType, right) : | ||
| IsInteger(left) ? ExtendsInteger(inferred, left, right) : | ||
| IsIntersect(left) ? ExtendsIntersect(inferred, left.allOf, right) : | ||
| IsIterator(left) ? ExtendsIterator(inferred, left.iteratorItems, right) : | ||
| IsLiteral(left) ? ExtendsLiteral(inferred, left, right) : | ||
| IsNever(left) ? ExtendsNever(inferred, left, right) : | ||
| IsNull(left) ? ExtendsNull(inferred, left, right) : | ||
| IsNumber(left) ? ExtendsNumber(inferred, left, right) : | ||
| IsObject(left) ? ExtendsObject(inferred, left.properties, right) : | ||
| IsPromise(left) ? ExtendsPromise(inferred, left.item, right) : | ||
| IsRecord(left) ? ExtendsRecord(inferred, RecordPattern(left), RecordValue(left), right) : | ||
| IsString(left) ? ExtendsString(inferred, left, right) : | ||
| IsSymbol(left) ? ExtendsSymbol(inferred, left, right) : | ||
| IsTemplateLiteral(left) ? ExtendsTemplateLiteral(inferred, left.pattern, right) : | ||
| IsTuple(left) ? ExtendsTuple(inferred, left.items, right) : | ||
| IsUndefined(left) ? ExtendsUndefined(inferred, left, right) : | ||
| IsUnion(left) ? ExtendsUnion(inferred, left.anyOf, right) : | ||
| IsUnknown(left) ? ExtendsUnknown(inferred, left, right) : | ||
| IsVoid(left) ? ExtendsVoid(inferred, left, right) : | ||
| Result.ExtendsFalse()); | ||
| IsBigInt(left) ? ExtendsBigInt(inferred, left, right) : | ||
| IsBoolean(left) ? ExtendsBoolean(inferred, left, right) : | ||
| IsConstructor(left) ? ExtendsConstructor(inferred, left.parameters, left.instanceType, right) : | ||
| IsDependent(left) ? ExtendsDependent(inferred, left.if, left.then, left.else, right) : | ||
| IsEnum(left) ? ExtendsEnum(inferred, left.enum, right) : | ||
| IsFunction(left) ? ExtendsFunction(inferred, left.parameters, left.returnType, right) : | ||
| IsInteger(left) ? ExtendsInteger(inferred, left, right) : | ||
| IsIntersect(left) ? ExtendsIntersect(inferred, left.allOf, right) : | ||
| IsLiteral(left) ? ExtendsLiteral(inferred, left, right) : | ||
| IsNever(left) ? ExtendsNever(inferred, left, right) : | ||
| IsNull(left) ? ExtendsNull(inferred, left, right) : | ||
| IsNumber(left) ? ExtendsNumber(inferred, left, right) : | ||
| IsObject(left) ? ExtendsObject(inferred, left.properties, right) : | ||
| IsRecord(left) ? ExtendsRecord(inferred, RecordPattern(left), RecordValue(left), right) : | ||
| IsString(left) ? ExtendsString(inferred, left, right) : | ||
| IsSymbol(left) ? ExtendsSymbol(inferred, left, right) : | ||
| IsTemplateLiteral(left) ? ExtendsTemplateLiteral(inferred, left.pattern, right) : | ||
| IsTuple(left) ? ExtendsTuple(inferred, left.items, right) : | ||
| IsUndefined(left) ? ExtendsUndefined(inferred, left, right) : | ||
| IsUnion(left) ? ExtendsUnion(inferred, left.anyOf, right) : | ||
| IsUnknown(left) ? ExtendsUnknown(inferred, left, right) : | ||
| IsVoid(left) ? ExtendsVoid(inferred, left, right) : | ||
| Result.ExtendsFalse()); | ||
| } |
@@ -10,14 +10,2 @@ import { Memory } from '../../system/memory/index.mjs'; | ||
| Parameters | ||
| ] extends ['AsyncIterator', [infer Type extends T.TSchema]] ? T.TAsyncIterator<Type> : [ | ||
| Target, | ||
| Parameters | ||
| ] extends ['Promise', [infer Type extends T.TSchema]] ? T.TPromise<Type> : [ | ||
| Target, | ||
| Parameters | ||
| ] extends ['Iterator', [infer Type extends T.TSchema]] ? T.TIterator<Type> : [ | ||
| Target, | ||
| Parameters | ||
| ] extends ['Awaited', [infer Type extends T.TSchema]] ? S.TAwaitedDeferred<Type> : [ | ||
| Target, | ||
| Parameters | ||
| ] extends ['Capitalize', [infer Type extends T.TSchema]] ? S.TCapitalizeDeferred<Type> : [ | ||
@@ -24,0 +12,0 @@ Target, |
@@ -12,27 +12,23 @@ // deno-fmt-ignore-file | ||
| return (Guard.IsEqual(ref, 'Array') ? T.Array(parameters[0]) : | ||
| Guard.IsEqual(ref, 'AsyncIterator') ? T.AsyncIterator(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Iterator') ? T.Iterator(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Promise') ? T.Promise(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Awaited') ? S.AwaitedDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Capitalize') ? S.CapitalizeDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'ConstructorParameters') ? S.ConstructorParametersDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Evaluate') ? S.EvaluateDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Exclude') ? S.ExcludeDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Extract') ? S.ExtractDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Index') ? S.IndexDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'InstanceType') ? S.InstanceTypeDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Lowercase') ? S.LowercaseDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'NonNullable') ? S.NonNullableDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Omit') ? S.OmitDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Parameters') ? S.ParametersDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Partial') ? S.PartialDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Pick') ? S.PickDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Readonly') ? S.ReadonlyObjectDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'KeyOf') ? S.KeyOfDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Record') ? T.RecordDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Required') ? S.RequiredDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'ReturnType') ? S.ReturnTypeDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Uncapitalize') ? S.UncapitalizeDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Uppercase') ? S.UppercaseDeferred(parameters[0]) : | ||
| T.CallConstruct(T.Ref(ref), parameters)); | ||
| Guard.IsEqual(ref, 'Capitalize') ? S.CapitalizeDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'ConstructorParameters') ? S.ConstructorParametersDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Evaluate') ? S.EvaluateDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Exclude') ? S.ExcludeDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Extract') ? S.ExtractDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Index') ? S.IndexDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'InstanceType') ? S.InstanceTypeDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Lowercase') ? S.LowercaseDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'NonNullable') ? S.NonNullableDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Omit') ? S.OmitDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Parameters') ? S.ParametersDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Partial') ? S.PartialDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Pick') ? S.PickDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Readonly') ? S.ReadonlyObjectDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'KeyOf') ? S.KeyOfDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Record') ? T.RecordDeferred(parameters[0], parameters[1]) : | ||
| Guard.IsEqual(ref, 'Required') ? S.RequiredDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'ReturnType') ? S.ReturnTypeDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Uncapitalize') ? S.UncapitalizeDeferred(parameters[0]) : | ||
| Guard.IsEqual(ref, 'Uppercase') ? S.UppercaseDeferred(parameters[0]) : | ||
| T.CallConstruct(T.Ref(ref), parameters)); | ||
| // deno-coverage-ignore-stop | ||
@@ -39,0 +35,0 @@ } |
@@ -21,4 +21,2 @@ import { type TSchema } from './schema.mjs'; | ||
| export declare function Refine<Type extends TSchema, Value = Static<Type>>(type: Type, check: TRefineCheckCallback<Value>): TRefineAdd<Type>; | ||
| /** @deprecated Use the error callback signature to generate error message. This overload will be removed in the next version */ | ||
| export declare function Refine<Type extends TSchema, Value = Static<Type>>(type: Type, check: TRefineCheckCallback<Value>, message: string): TRefineAdd<Type>; | ||
| /** Returns true if the given value is a TRefinement. */ | ||
@@ -25,0 +23,0 @@ export declare function IsRefinement(value: unknown): value is TRefinement; |
@@ -13,7 +13,6 @@ // deno-fmt-ignore-file | ||
| export function Refine(...args) { | ||
| const [type, check, error_or_message] = Arguments.Match(args, { | ||
| const [type, check, error] = Arguments.Match(args, { | ||
| 3: (type, check, error) => [type, check, error], | ||
| 2: (type, check) => [type, check, () => 'Refine Error'], | ||
| }); | ||
| const error = Guard.IsString(error_or_message) ? () => error_or_message : error_or_message; | ||
| return RefineAdd(type, { check, error }); | ||
@@ -20,0 +19,0 @@ } |
@@ -8,4 +8,2 @@ export * from './_codec.mjs'; | ||
| export * from './array.mjs'; | ||
| export * from './async_iterator.mjs'; | ||
| export * from './base.mjs'; | ||
| export * from './bigint.mjs'; | ||
@@ -25,3 +23,2 @@ export * from './boolean.mjs'; | ||
| export * from './intersect.mjs'; | ||
| export * from './iterator.mjs'; | ||
| export * from './literal.mjs'; | ||
@@ -35,3 +32,2 @@ export * from './never.mjs'; | ||
| export * from './parameter.mjs'; | ||
| export * from './promise.mjs'; | ||
| export * from './properties.mjs'; | ||
@@ -38,0 +34,0 @@ export * from './record.mjs'; |
@@ -14,4 +14,2 @@ // ------------------------------------------------------------------ | ||
| export * from './array.mjs'; | ||
| export * from './async_iterator.mjs'; | ||
| export * from './base.mjs'; | ||
| export * from './bigint.mjs'; | ||
@@ -31,3 +29,2 @@ export * from './boolean.mjs'; | ||
| export * from './intersect.mjs'; | ||
| export * from './iterator.mjs'; | ||
| export * from './literal.mjs'; | ||
@@ -41,3 +38,2 @@ export * from './never.mjs'; | ||
| export * from './parameter.mjs'; | ||
| export * from './promise.mjs'; | ||
| export * from './properties.mjs'; | ||
@@ -44,0 +40,0 @@ export * from './record.mjs'; |
| import type { StaticCodec, TCodec } from './_codec.mjs'; | ||
| import type { StaticAny, TAny } from './any.mjs'; | ||
| import type { StaticArray, TArray } from './array.mjs'; | ||
| import type { StaticAsyncIterator, TAsyncIterator } from './async_iterator.mjs'; | ||
| import type { StaticBase, Base } from './base.mjs'; | ||
| import type { StaticBigInt, TBigInt } from './bigint.mjs'; | ||
@@ -15,3 +13,2 @@ import type { StaticBoolean, TBoolean } from './boolean.mjs'; | ||
| import type { StaticIntersect, TIntersect } from './intersect.mjs'; | ||
| import type { StaticIterator, TIterator } from './iterator.mjs'; | ||
| import type { StaticLiteral, TLiteral, TLiteralValue } from './literal.mjs'; | ||
@@ -22,3 +19,2 @@ import type { StaticNever, TNever } from './never.mjs'; | ||
| import type { StaticObject, TObject } from './object.mjs'; | ||
| import type { StaticPromise, TPromise } from './promise.mjs'; | ||
| import type { TProperties } from './properties.mjs'; | ||
@@ -43,3 +39,3 @@ import type { StaticRecord, TRecord } from './record.mjs'; | ||
| export type StaticDirection = 'Encode' | 'Decode'; | ||
| 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 TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? StaticDependent<Stack, Direction, Context, This, If, Then, Else> : 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>); | ||
| 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 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 TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? StaticDependent<Stack, Direction, Context, This, If, Then, Else> : Type extends TInteger ? StaticInteger : Type extends TIntersect<infer Types extends TSchema[]> ? StaticIntersect<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 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>); | ||
| /** Infers a static type from a TypeBox type using Parse logic. */ | ||
@@ -46,0 +42,0 @@ export type StaticParse<Type extends TSchema, Context extends TProperties = {}, Result extends unknown = StaticType<[], 'Encode', Context, {}, Type>> = Result; |
| export { Instantiate, type TInstantiate } from './type/engine/instantiate.mjs'; | ||
| export { Extends, ExtendsResult, type TExtends } from './type/extends/index.mjs'; | ||
| export { Script, type TScript } from './type/script/index.mjs'; | ||
| export { Awaited, type TAwaited, type TAwaitedDeferred } from './type/action/awaited.mjs'; | ||
| export { Capitalize, type TCapitalize, type TCapitalizeDeferred } from './type/action/capitalize.mjs'; | ||
@@ -23,3 +22,3 @@ export { Conditional, type TConditional, type TConditionalDeferred } from './type/action/conditional.mjs'; | ||
| export { Pick, type TPick, type TPickDeferred } from './type/action/pick.mjs'; | ||
| export { ReadonlyObject, ReadonlyType, type TReadonlyObject, type TReadonlyObjectDeferred } from './type/action/readonly_object.mjs'; | ||
| export { ReadonlyObject, type TReadonlyObject, type TReadonlyObjectDeferred } from './type/action/readonly_object.mjs'; | ||
| export { Required, type TRequired, type TRequiredDeferred } from './type/action/required.mjs'; | ||
@@ -29,3 +28,3 @@ export { ReturnType, type TReturnType, type TReturnTypeDeferred } from './type/action/return_type.mjs'; | ||
| export { type TUppercase, type TUppercaseDeferred, Uppercase } from './type/action/uppercase.mjs'; | ||
| export { Options, type TOptions, type TWith, With } from './type/action/with.mjs'; | ||
| export { type TWith, With } from './type/action/with.mjs'; | ||
| export { Codec, Decode, DecodeBuilder, Encode, EncodeBuilder, IsCodec, type TCodec } from './type/types/_codec.mjs'; | ||
@@ -38,4 +37,2 @@ export { Immutable, IsImmutable, type TImmutable } from './type/types/_immutable.mjs'; | ||
| export { Array, IsArray, type TArray } from './type/types/array.mjs'; | ||
| export { AsyncIterator, IsAsyncIterator, type TAsyncIterator } from './type/types/async_iterator.mjs'; | ||
| export { Base, IsBase } from './type/types/base.mjs'; | ||
| export { BigInt, IsBigInt, type TBigInt } from './type/types/bigint.mjs'; | ||
@@ -54,3 +51,2 @@ export { Boolean, IsBoolean, type TBoolean } from './type/types/boolean.mjs'; | ||
| export { Intersect, IsIntersect, type TIntersect } from './type/types/intersect.mjs'; | ||
| export { IsIterator, Iterator, type TIterator } from './type/types/iterator.mjs'; | ||
| export { IsLiteral, Literal, type TLiteral, type TLiteralValue } from './type/types/literal.mjs'; | ||
@@ -62,3 +58,2 @@ export { IsNever, Never, type TNever } from './type/types/never.mjs'; | ||
| export { IsParameter, Parameter, type TParameter } from './type/types/parameter.mjs'; | ||
| export { IsPromise, Promise, type TPromise } from './type/types/promise.mjs'; | ||
| export { type TProperties, type TRequiredArray } from './type/types/properties.mjs'; | ||
@@ -65,0 +60,0 @@ export { IsRecord, Record, RecordKey, RecordPattern, RecordValue, type TRecord, type TRecordKey, type TRecordPattern, type TRecordValue } from './type/types/record.mjs'; |
@@ -16,3 +16,2 @@ // ------------------------------------------------------------------ | ||
| // ------------------------------------------------------------------ | ||
| export { Awaited } from './type/action/awaited.mjs'; | ||
| export { Capitalize } from './type/action/capitalize.mjs'; | ||
@@ -36,3 +35,3 @@ export { Conditional } from './type/action/conditional.mjs'; | ||
| export { Pick } from './type/action/pick.mjs'; | ||
| export { ReadonlyObject, ReadonlyType } from './type/action/readonly_object.mjs'; | ||
| export { ReadonlyObject } from './type/action/readonly_object.mjs'; | ||
| export { Required } from './type/action/required.mjs'; | ||
@@ -42,3 +41,3 @@ export { ReturnType } from './type/action/return_type.mjs'; | ||
| export { Uppercase } from './type/action/uppercase.mjs'; | ||
| export { Options, With } from './type/action/with.mjs'; | ||
| export { With } from './type/action/with.mjs'; | ||
| // ------------------------------------------------------------------ | ||
@@ -57,4 +56,2 @@ // Extension | ||
| export { Array, IsArray } from './type/types/array.mjs'; | ||
| export { AsyncIterator, IsAsyncIterator } from './type/types/async_iterator.mjs'; | ||
| export { Base, IsBase } from './type/types/base.mjs'; | ||
| export { BigInt, IsBigInt } from './type/types/bigint.mjs'; | ||
@@ -73,3 +70,2 @@ export { Boolean, IsBoolean } from './type/types/boolean.mjs'; | ||
| export { Intersect, IsIntersect } from './type/types/intersect.mjs'; | ||
| export { IsIterator, Iterator } from './type/types/iterator.mjs'; | ||
| export { IsLiteral, Literal } from './type/types/literal.mjs'; | ||
@@ -81,3 +77,2 @@ export { IsNever, Never } from './type/types/never.mjs'; | ||
| export { IsParameter, Parameter } from './type/types/parameter.mjs'; | ||
| export { IsPromise, Promise } from './type/types/promise.mjs'; | ||
| export { IsRecord, Record, RecordKey, RecordPattern, RecordValue } from './type/types/record.mjs'; | ||
@@ -84,0 +79,0 @@ export { IsRef, Ref } from './type/types/ref.mjs'; |
| // deno-fmt-ignore-file | ||
| import * as T from '../../type/index.mjs'; | ||
| import { FromArray } from './from_array.mjs'; | ||
| import { FromBase } from './from_base.mjs'; | ||
| import { FromCyclic } from './from_cyclic.mjs'; | ||
@@ -14,11 +13,10 @@ import { FromIntersect } from './from_intersect.mjs'; | ||
| return (T.IsArray(type) ? FromArray(context, type, value) : | ||
| T.IsBase(type) ? FromBase(context, type, value) : | ||
| T.IsCyclic(type) ? FromCyclic(context, type, value) : | ||
| T.IsIntersect(type) ? FromIntersect(context, type, value) : | ||
| T.IsObject(type) ? FromObject(context, type, value) : | ||
| T.IsRecord(type) ? FromRecord(context, type, value) : | ||
| T.IsRef(type) ? FromRef(context, type, value) : | ||
| T.IsTuple(type) ? FromTuple(context, type, value) : | ||
| T.IsUnion(type) ? FromUnion(context, type, value) : | ||
| value); | ||
| T.IsCyclic(type) ? FromCyclic(context, type, value) : | ||
| T.IsIntersect(type) ? FromIntersect(context, type, value) : | ||
| T.IsObject(type) ? FromObject(context, type, value) : | ||
| T.IsRecord(type) ? FromRecord(context, type, value) : | ||
| T.IsRef(type) ? FromRef(context, type, value) : | ||
| T.IsTuple(type) ? FromTuple(context, type, value) : | ||
| T.IsUnion(type) ? FromUnion(context, type, value) : | ||
| value); | ||
| } |
| // deno-fmt-ignore-file | ||
| import { Guard, GlobalsGuard } from '../../guard/index.mjs'; | ||
| import { Clone as SystemClone } from '../../system/memory/clone.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // ClassInstance | ||
| // | ||
| // TypeBox does not support cloning arbitrary class instances. It treats | ||
| // class instances as atomic values, similar to number, boolean, and | ||
| // string. In the future, an implementation could detect the presence of | ||
| // a .clone() method, but no formal specification for this behavior | ||
| // exists, so we don't. | ||
| // | ||
| // ------------------------------------------------------------------ | ||
| function FromClassInstance(value) { | ||
| return value; // atomic | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // TypeInstance | ||
| // | ||
| // TypeBox types have non-enumerable properties that should be | ||
| // retained on Clone. We need to use a SystemClone for this | ||
| // to ensure the non-enumerable properties are preserved. | ||
| // ------------------------------------------------------------------ | ||
| function IsTypeInstance(value) { | ||
| return Guard.HasPropertyKey(value, '~kind'); | ||
| } | ||
| function FromTypeInstance(value) { | ||
| return SystemClone(value); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // ObjectInstance | ||
| // ------------------------------------------------------------------ | ||
| function FromObjectInstance(value) { | ||
| const result = {}; | ||
| for (const key of Guard.Keys(value)) { | ||
| if (Guard.IsUnsafePropertyKey(key)) | ||
| continue; // (ignore: prototype-pollution) | ||
| result[key] = Clone(value[key]); | ||
| } | ||
| for (const key of Guard.Symbols(value)) { | ||
| result[key] = Clone(value[key]); | ||
| } | ||
| return result; | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Object | ||
| // ------------------------------------------------------------------ | ||
| function FromObject(value) { | ||
| return (Guard.IsClassInstance(value) ? FromClassInstance(value) : | ||
| IsTypeInstance(value) ? FromTypeInstance(value) : | ||
| FromObjectInstance(value)); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Array | ||
| // ------------------------------------------------------------------ | ||
| function FromArray(value) { | ||
| return value.map((element) => Clone(element)); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // TypeArray | ||
| // ------------------------------------------------------------------ | ||
| function FromTypedArray(value) { | ||
| return value.slice(); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Map | ||
| // ------------------------------------------------------------------ | ||
| function FromMap(value) { | ||
| return new Map(Clone([...value.entries()])); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Set | ||
| // ------------------------------------------------------------------ | ||
| function FromSet(value) { | ||
| return new Set(Clone([...value.values()])); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Value | ||
| // ------------------------------------------------------------------ | ||
| function FromValue(value) { | ||
| return value; | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Clone | ||
@@ -91,8 +11,3 @@ // ------------------------------------------------------------------ | ||
| export function Clone(value) { | ||
| return (GlobalsGuard.IsTypeArray(value) ? FromTypedArray(value) : | ||
| GlobalsGuard.IsMap(value) ? FromMap(value) : | ||
| GlobalsGuard.IsSet(value) ? FromSet(value) : | ||
| Guard.IsArray(value) ? FromArray(value) : | ||
| Guard.IsObject(value) ? FromObject(value) : | ||
| FromValue(value)); | ||
| return SystemClone(value); | ||
| } |
| // deno-fmt-ignore-file | ||
| import * as Type from '../../type/index.mjs'; | ||
| import { FromArray } from './from_array.mjs'; | ||
| import { FromBase } from './from_base.mjs'; | ||
| import { FromBigInt } from './from_bigint.mjs'; | ||
@@ -25,22 +24,21 @@ import { FromBoolean } from './from_boolean.mjs'; | ||
| return (Type.IsArray(type) ? FromArray(context, type, value) : | ||
| Type.IsBase(type) ? FromBase(context, type, value) : | ||
| Type.IsBigInt(type) ? FromBigInt(context, type, value) : | ||
| Type.IsBoolean(type) ? FromBoolean(context, type, value) : | ||
| Type.IsCyclic(type) ? FromCyclic(context, type, value) : | ||
| Type.IsEnum(type) ? FromEnum(context, type, value) : | ||
| Type.IsInteger(type) ? FromInteger(context, type, value) : | ||
| Type.IsIntersect(type) ? FromIntersect(context, type, value) : | ||
| Type.IsLiteral(type) ? FromLiteral(context, type, value) : | ||
| Type.IsNull(type) ? FromNull(context, type, value) : | ||
| Type.IsNumber(type) ? FromNumber(context, type, value) : | ||
| Type.IsObject(type) ? FromObject(context, type, value) : | ||
| Type.IsRecord(type) ? FromRecord(context, type, value) : | ||
| Type.IsRef(type) ? FromRef(context, type, value) : | ||
| Type.IsString(type) ? FromString(context, type, value) : | ||
| Type.IsTemplateLiteral(type) ? FromTemplateLiteral(context, type, value) : | ||
| Type.IsTuple(type) ? FromTuple(context, type, value) : | ||
| Type.IsUndefined(type) ? FromUndefined(context, type, value) : | ||
| Type.IsUnion(type) ? FromUnion(context, type, value) : | ||
| Type.IsVoid(type) ? FromVoid(context, type, value) : | ||
| value); | ||
| Type.IsBigInt(type) ? FromBigInt(context, type, value) : | ||
| Type.IsBoolean(type) ? FromBoolean(context, type, value) : | ||
| Type.IsCyclic(type) ? FromCyclic(context, type, value) : | ||
| Type.IsEnum(type) ? FromEnum(context, type, value) : | ||
| Type.IsInteger(type) ? FromInteger(context, type, value) : | ||
| Type.IsIntersect(type) ? FromIntersect(context, type, value) : | ||
| Type.IsLiteral(type) ? FromLiteral(context, type, value) : | ||
| Type.IsNull(type) ? FromNull(context, type, value) : | ||
| Type.IsNumber(type) ? FromNumber(context, type, value) : | ||
| Type.IsObject(type) ? FromObject(context, type, value) : | ||
| Type.IsRecord(type) ? FromRecord(context, type, value) : | ||
| Type.IsRef(type) ? FromRef(context, type, value) : | ||
| Type.IsString(type) ? FromString(context, type, value) : | ||
| Type.IsTemplateLiteral(type) ? FromTemplateLiteral(context, type, value) : | ||
| Type.IsTuple(type) ? FromTuple(context, type, value) : | ||
| Type.IsUndefined(type) ? FromUndefined(context, type, value) : | ||
| Type.IsUnion(type) ? FromUnion(context, type, value) : | ||
| Type.IsVoid(type) ? FromVoid(context, type, value) : | ||
| value); | ||
| } |
@@ -6,4 +6,2 @@ // deno-fmt-ignore-file | ||
| import { FromArray } from './from_array.mjs'; | ||
| import { FromAsyncIterator } from './from_async_iterator.mjs'; | ||
| import { FromBase } from './from_base.mjs'; | ||
| import { FromBigInt } from './from_bigint.mjs'; | ||
@@ -17,3 +15,2 @@ import { FromBoolean } from './from_boolean.mjs'; | ||
| import { FromIntersect } from './from_intersect.mjs'; | ||
| import { FromIterator } from './from_iterator.mjs'; | ||
| import { FromLiteral } from './from_literal.mjs'; | ||
@@ -24,3 +21,2 @@ import { FromNever } from './from_never.mjs'; | ||
| import { FromObject } from './from_object.mjs'; | ||
| import { FromPromise } from './from_promise.mjs'; | ||
| import { FromRecord } from './from_record.mjs'; | ||
@@ -45,29 +41,25 @@ import { FromRef } from './from_ref.mjs'; | ||
| T.IsArray(type) ? FromArray(context, type) : | ||
| T.IsAsyncIterator(type) ? FromAsyncIterator(context, type) : | ||
| T.IsBase(type) ? FromBase(context, type) : | ||
| T.IsBigInt(type) ? FromBigInt(context, type) : | ||
| T.IsBoolean(type) ? FromBoolean(context, type) : | ||
| T.IsConstructor(type) ? FromConstructor(context, type) : | ||
| T.IsCyclic(type) ? FromCyclic(context, type) : | ||
| T.IsEnum(type) ? FromEnum(context, type) : | ||
| T.IsFunction(type) ? FromFunction(context, type) : | ||
| T.IsInteger(type) ? FromInteger(context, type) : | ||
| T.IsIntersect(type) ? FromIntersect(context, type) : | ||
| T.IsIterator(type) ? FromIterator(context, type) : | ||
| T.IsLiteral(type) ? FromLiteral(context, type) : | ||
| T.IsNever(type) ? FromNever(context, type) : | ||
| T.IsNull(type) ? FromNull(context, type) : | ||
| T.IsNumber(type) ? FromNumber(context, type) : | ||
| T.IsObject(type) ? FromObject(context, type) : | ||
| T.IsPromise(type) ? FromPromise(context, type) : | ||
| T.IsRecord(type) ? FromRecord(context, type) : | ||
| T.IsRef(type) ? FromRef(context, type) : | ||
| T.IsString(type) ? FromString(context, type) : | ||
| T.IsSymbol(type) ? FromSymbol(context, type) : | ||
| T.IsTemplateLiteral(type) ? FromTemplateLiteral(context, type) : | ||
| T.IsTuple(type) ? FromTuple(context, type) : | ||
| T.IsUndefined(type) ? FromUndefined(context, type) : | ||
| T.IsUnion(type) ? FromUnion(context, type) : | ||
| T.IsVoid(type) ? FromVoid(context, type) : | ||
| undefined); | ||
| T.IsBigInt(type) ? FromBigInt(context, type) : | ||
| T.IsBoolean(type) ? FromBoolean(context, type) : | ||
| T.IsConstructor(type) ? FromConstructor(context, type) : | ||
| T.IsCyclic(type) ? FromCyclic(context, type) : | ||
| T.IsEnum(type) ? FromEnum(context, type) : | ||
| T.IsFunction(type) ? FromFunction(context, type) : | ||
| T.IsInteger(type) ? FromInteger(context, type) : | ||
| T.IsIntersect(type) ? FromIntersect(context, type) : | ||
| T.IsLiteral(type) ? FromLiteral(context, type) : | ||
| T.IsNever(type) ? FromNever(context, type) : | ||
| T.IsNull(type) ? FromNull(context, type) : | ||
| T.IsNumber(type) ? FromNumber(context, type) : | ||
| T.IsObject(type) ? FromObject(context, type) : | ||
| T.IsRecord(type) ? FromRecord(context, type) : | ||
| T.IsRef(type) ? FromRef(context, type) : | ||
| T.IsString(type) ? FromString(context, type) : | ||
| T.IsSymbol(type) ? FromSymbol(context, type) : | ||
| T.IsTemplateLiteral(type) ? FromTemplateLiteral(context, type) : | ||
| T.IsTuple(type) ? FromTuple(context, type) : | ||
| T.IsUndefined(type) ? FromUndefined(context, type) : | ||
| T.IsUnion(type) ? FromUnion(context, type) : | ||
| T.IsVoid(type) ? FromVoid(context, type) : | ||
| undefined); | ||
| } |
@@ -6,3 +6,2 @@ // deno-fmt-ignore-file | ||
| import { FromArray } from './from_array.mjs'; | ||
| import { FromBase } from './from_base.mjs'; | ||
| import { FromCyclic } from './from_cyclic.mjs'; | ||
@@ -19,11 +18,10 @@ import { FromDefault } from './from_default.mjs'; | ||
| return (T.IsArray(type) ? FromArray(context, type, defaulted) : | ||
| T.IsBase(type) ? FromBase(context, type, defaulted) : | ||
| T.IsCyclic(type) ? FromCyclic(context, type, defaulted) : | ||
| T.IsIntersect(type) ? FromIntersect(context, type, defaulted) : | ||
| T.IsObject(type) ? FromObject(context, type, defaulted) : | ||
| T.IsRecord(type) ? FromRecord(context, type, defaulted) : | ||
| T.IsRef(type) ? FromRef(context, type, defaulted) : | ||
| T.IsTuple(type) ? FromTuple(context, type, defaulted) : | ||
| T.IsUnion(type) ? FromUnion(context, type, defaulted) : | ||
| defaulted); | ||
| T.IsCyclic(type) ? FromCyclic(context, type, defaulted) : | ||
| T.IsIntersect(type) ? FromIntersect(context, type, defaulted) : | ||
| T.IsObject(type) ? FromObject(context, type, defaulted) : | ||
| T.IsRecord(type) ? FromRecord(context, type, defaulted) : | ||
| T.IsRef(type) ? FromRef(context, type, defaulted) : | ||
| T.IsTuple(type) ? FromTuple(context, type, defaulted) : | ||
| T.IsUnion(type) ? FromUnion(context, type, defaulted) : | ||
| defaulted); | ||
| } |
@@ -12,3 +12,2 @@ export * from './assert/index.mjs'; | ||
| export * from './hash/index.mjs'; | ||
| export * from './mutate/index.mjs'; | ||
| export * from './parse/index.mjs'; | ||
@@ -15,0 +14,0 @@ export * from './delta/index.mjs'; |
@@ -15,3 +15,2 @@ // ------------------------------------------------------------------ | ||
| export * from './hash/index.mjs'; | ||
| export * from './mutate/index.mjs'; | ||
| export * from './parse/index.mjs'; | ||
@@ -18,0 +17,0 @@ export * from './delta/index.mjs'; |
@@ -7,3 +7,2 @@ // deno-fmt-ignore-file | ||
| import { FromArray } from './from_array.mjs'; | ||
| import { FromBase } from './from_base.mjs'; | ||
| import { FromEnum } from './from_enum.mjs'; | ||
@@ -37,8 +36,5 @@ import { FromIntersect } from './from_intersect.mjs'; | ||
| function AssertRepairableType(context, type, value) { | ||
| const unsupported = T.IsAsyncIterator(type) | ||
| || T.IsIterator(type) | ||
| || T.IsConstructor(type) | ||
| const unsupported = T.IsConstructor(type) | ||
| || T.IsFunction(type) | ||
| || T.IsNever(type) | ||
| || T.IsPromise(type); | ||
| || T.IsNever(type); | ||
| if (unsupported) { | ||
@@ -69,8 +65,2 @@ throw new RepairError(context, type, value, 'Type is not repairable'); | ||
| export function FromType(context, type, value) { | ||
| // Base Repair | ||
| if (T.IsBase(type)) { | ||
| const repaired = FromBase(context, type, value); | ||
| return FinalizeRepair(context, type, repaired); | ||
| } | ||
| // Schema Repair | ||
| AssertRepairableValue(context, type, value); | ||
@@ -77,0 +67,0 @@ AssertRepairableType(context, type, value); |
@@ -12,3 +12,2 @@ export { Assert } from './assert/index.mjs'; | ||
| export { Hash } from './hash/index.mjs'; | ||
| export { Mutate, type TMutable } from './mutate/index.mjs'; | ||
| export { Parse } from './parse/index.mjs'; | ||
@@ -15,0 +14,0 @@ export { Diff, Patch } from './delta/index.mjs'; |
@@ -12,3 +12,2 @@ export { Assert } from './assert/index.mjs'; | ||
| export { Hash } from './hash/index.mjs'; | ||
| export { Mutate } from './mutate/index.mjs'; | ||
| export { Parse } from './parse/index.mjs'; | ||
@@ -15,0 +14,0 @@ export { Diff, Patch } from './delta/index.mjs'; |
+1
-1
| { | ||
| "name": "typebox", | ||
| "description": "Json Schema Type Builder with Static Type Resolution for TypeScript", | ||
| "version": "1.2.19", | ||
| "version": "1.3.0", | ||
| "keywords": [ | ||
@@ -6,0 +6,0 @@ "typescript", |
+1
-1
@@ -114,3 +114,3 @@ <div align='center'> | ||
| [Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdAGUAxlGBgYACjwC5eAJS9G3VWvXdqdOADkAhiFQBnMHpGpKIiADsj8ALJ6YACzgBeREWFiJ0gAaUcHCEaHAAaqgiMNAATO5wAN5wZABccNYAriDEqFAANHBIaZnZuXAAvoHBROGR0VAAzPEAogBuegA2GU6oADwRUbFwAGSJcABexVk5UBUAfFUh6AP1ACwt7V09-XXQTaNJAO5TpbPlC35KygAiqGjWACao1vD6hiZmFla28En2xq5yvF+KhvOJJFIknIBI4XBUCn4gosahFYKgyPEElUgpAjMAYMAbGkVtBVnlseloCBOsTdo1yUEghlWrTBlAYlVKkElnAAOKoHCoGBQJCYimtXIE8xGWlosgAbQAugzGcBHsBpScZkrOcjQrDcsBOmLGXADMRgM8YKy1iqgg9gBgMBkjKgbaS7XATJEMh09FB3VBVrruTV-kZXB4saaAOYCwzCop8+NCkWe6kwQ00uAG8SdXWXLT0ABKGReoHQxdQGA6dUJ1ko4ecAjA2DQsEtRgEccFiZbbclnYEEo70oE+NQIC7rYg7YJxhbEDxBJs-dng4XZEbALXc6HPYTIt3G67I6lC4nU+PHYX1ipnWv867W6bj-3Kb7M73C7PGovmavL8TwEZk303bcIzArsMyzDooIEB0nRdUEgJvZ8IObVCnwEGC8zgrCh3NS0Xngl8dwIhdcKNfCBzQgRvREX1-VIos4CEGAnA1OAAElrAwXJnnMShnWsKJ6zgKBnieKApHeZw0hBYQOKlXolggDAcwBOYFESKo5O7D8j1-aV5QABkVRdl3rAQtyCfSD1TJBh0HEzzIEO8oGpODbLgezDKc4zjDMizQJ8-SqIfRDnVdGy9J3CK4KIq1Yrs+Kejw+i0EYv0oFi8ogA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdACpejbuImTu1OnAByAQxCoAzmAUBjVJQB2S1eq1wAsgpgALOAG9KcOKjKRYcDRB0r4ANVQaY0AExwALyIRAIA8sQAVj4wABRWcGQAXKGCcgCuIMSoUHEAlAA0cEip-KgCmdm5BXAAvvm29o7Q8K7uXrHQAMzBaRUAogBuCgA2GWaoceUCAJI6MLkqsXEA2t6+AcUzkTG+CXAAXmVhVTl5+fX5ALr5jXYOTm1uHnAbflAALH0zw2MTi2mYXmiygy326y6UG62zCuxWiQA7id0llzrUGrdGnUZPQACKoNA6AAmqAW8n0ak02nar28sAcPzh0QRTUgKmAMGAblSpgsAne0E+hSaOmgIDGvLM5gFUJhTQyQyl-MFUH8lAalFp8AA4qgcKgYFAkEzBPD9jY7ENclytCoURUAIJQKAKJBxemLMhFJrAEnAO0OgTO13umZnGp3DWNbUmSZQYBjU0Vc3xS1wJTEYBkmDKmWq4VNYnADAYDLLPOyzZfEV2NQ+DKjBRQSsF6Nal7wYyqSwhHYsi1NADm+uURtKcD1BvHtbgEtBidGytyi-bogAShkFqB0OvUBhRrFuTpKN2VDKwNg0LBsyoBCPp8aBJeINeuaoBNab3aBJzUCA7xfN9b2fCAOS5NxnyvG0QLIU8eyg18YI-B8xyfIDkLvL9bQ-P8AMQ4CPzFKAJVGAjMIEOCzwvaCbxQ0dDXQ2j3ywmCfzwwDmJAxVyLou8qIQjC+IEecVzGXiWIEYtS3LCohMkgTzwkkDRITcT5JAzNswWZSP0UmikOE1TF10u96w0Rtm1MyjcTgABlGAzADOB5gwXIyS0Sgyx0XxjzgKAyVJPJlHPIMHKcjQAB5CDQCAMBMHsAD5LnTEKZVQxikE-NjVFWAAGa5QPA48bLsNL7wY8dsu-XKCoEYjSNKucEIyqrsIDWrCp4uCyoQ4zxOkstlia8r+rIrScxGvr4xM8zLKgGy6iAA) | [Challenges](test/typescript/readme.md) | ||
| [Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdAGUAxlGBgYACjwC5eAJS9G3VWvXdqdOADkAhiFQBnMHpGpKIiADsj8ALJ6YACzgBeREWFiJ0gAaUcHCEaHAAaqgiMNAATO5wAN5wZABccNYAriDEqFAANHBIaZnZuXAAvoHBROGR0VAAzPEAogBuegA2GU6oADwRUbFwAGSJcABexVk5UBUAfFUh6AP1ACwt7V09-XXQTaNJAO5TpbPlC35KygAiqGjWACao1vD6hiZmFla28En2xq5yvF+KhvOJJFIknIBI4XBUCn4gosahFYKgyPEElUgpAjMAYMAbGkVtBVnlseloCBOsTdo1yUEghlWrTBlAYlVKkElnAAOKoHCoGBQJCYimtXIE8xGWlosgAbQAugzGcBHsBpScZkrOcjQrDcsBOmLGXADMRgM8YKy1iqgg9gBgMBkjKgbaS7XATJEMh09FB3VBVrruTV-kZXB4saaAOYCwzCop8+NCkWe6kwQ00uAG8SdXWXLT0ABKGReoHQxdQGA6dUJ1ko4ecAjA2DQsEtRgEccFiZbbclnYEEo70oE+NQIC7rYg7YJxhbEDxBJs-dng4XZEbALXc6HPYTIt3G67I6lC4nU+PHYX1ipnWv867W6bj-3Kb7M73C7PGovmavL8TwEZk303bcIzArsMyzDooIEB0nRdUEgJvZ8IObVCnwEGC8zgrCh3NS0Xngl8dwIhdcKNfCBzQgRvREX1-VIos4CEGAnA1OAAElrAwXJnnMShnWsKJ6zgKBnieKApHeZw0hBYQOKlXolggDAcwBOYFESKo5O7D8j1-aV5QABkVRdl3rAQtyCfSD1TJBh0HEzzIEO8oGpODbLgezDKc4zjDMizQJ8-SqIfRDnVdGy9J3CK4KIq1Yrs+Kejw+i0EYv0oFi8ogA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdACpejbuImTu1OnAByAQxCoAzmAUBjVJQB2S1eq1wAsgpgALOAG9KcOKjKRYcDRB0r4ANVQaY0AExwALyIRAIA8sQAVj4wABRWcGQAXKGCcgCuIMSoUHEAlAA0cEip-KgCmdm5BXAAvvm29o7Q8K7uXrHQAMzBaRUAogBuCgA2GWaoceUCAJI6MLkqsXEA2t6+AcUzkTG+CXAAXmVhVTl5+fX5ALr5jXYOTm1uHnAbflAALH0zw2MTi2mYXmiygy326y6UG62zCuxWiQA7id0llzrUGrdGnUZPQACKoNA6AAmqAW8n0ak02nar28sAcPzh0QRTUgKmAMGAblSpgsAne0E+hSaOmgIDGvLM5gFUJhTQyQyl-MFUH8lAalFp8AA4qgcKgYFAkEzBPD9jY7ENclytCoURUAIJQKAKJBxemLMhFJrAEnAO0OgTO13umZnGp3DWNbUmSZQYBjU0Vc3xS1wJTEYBkmDKmWq4VNYnADAYDLLPOyzZfEV2NQ+DKjBRQSsF6Nal7wYyqSwhHYsi1NADm+uURtKcD1BvHtbgEtBidGytyi-bogAShkFqB0OvUBhRrFuTpKN2VDKwNg0LBsyoBCPp8aBJeINeuaoBNab3aBJzUCA7xfN9b2fCAOS5NxnyvG0QLIU8eyg18YI-B8xyfIDkLvL9bQ-P8AMQ4CPzFKAJVGAjMIEOCzwvaCbxQ0dDXQ2j3ywmCfzwwDmJAxVyLou8qIQjC+IEecVzGXiWIEYtS3LCohMkgTzwkkDRITcT5JAzNswWZSP0UmikOE1TF10u96w0Rtm1MyjcTgABlGAzADOB5gwXIyS0Sgyx0XxjzgKAyVJPJlHPIMHKcjQAB5CDQCAMBMHsAD5LnTEKZVQxikE-NjVFWAAGa5QPA48bLsNL7wY8dsu-XKCoEYjSNKucEIyqrsIDWrCp4uCyoQ4zxOkstlia8r+rIrScxGvr4xM8zLKgGy6iAA) | [Challenge](test/typescript/readme.md) | ||
@@ -117,0 +117,0 @@ TypeBox includes a syntax engine that can transform TypeScript declarations into JSON Schema. The engine is a full syntactic frontend to Type.* and supports many advanced type-level constructs such as Conditional, Mapped, Indexed, Infer, Generics, Distributed types and more. This feature is implemented symmetrically at runtime and statically via TypeScript Template Literal types. |
| import * as Schema from '../types/index.mjs'; | ||
| import { Stack } from './_stack.mjs'; | ||
| import { BuildContext, CheckContext, ErrorContext } from './_context.mjs'; | ||
| export declare function BuildGuard(_stack: Stack, _context: BuildContext, schema: Schema.XGuard, value: string): string; | ||
| export declare function CheckGuard(_stack: Stack, _context: CheckContext, schema: Schema.XGuard, value: unknown): boolean; | ||
| export declare function ErrorGuard(_stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XGuard, value: unknown): boolean; |
| // deno-fmt-ignore-file | ||
| import * as Externals from './_externals.mjs'; | ||
| import { EmitGuard as E } from '../../guard/index.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // Build | ||
| // ------------------------------------------------------------------ | ||
| export function BuildGuard(_stack, _context, schema, value) { | ||
| return E.Call(E.Member(E.Member(Externals.CreateVariable(schema), '~guard'), 'check'), [value]); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Check | ||
| // ------------------------------------------------------------------ | ||
| export function CheckGuard(_stack, _context, schema, value) { | ||
| return schema['~guard'].check(value); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Error | ||
| // ------------------------------------------------------------------ | ||
| export function ErrorGuard(_stack, context, schemaPath, instancePath, schema, value) { | ||
| return schema['~guard'].check(value) || context.AddError({ | ||
| keyword: '~guard', | ||
| schemaPath, | ||
| instancePath, | ||
| params: { errors: schema['~guard'].errors(value) }, | ||
| }); | ||
| } |
| import type { XSchemaObject } from './schema.mjs'; | ||
| export interface XGuardInterface<Value extends unknown = unknown> { | ||
| check(value: unknown): value is Value; | ||
| errors(value: unknown): object[]; | ||
| } | ||
| export interface XGuard<Value extends unknown = unknown> { | ||
| '~guard': XGuardInterface<Value>; | ||
| } | ||
| export declare function IsGuardInterface(value: unknown): value is XGuardInterface; | ||
| export declare function IsGuard(value: XSchemaObject): value is XGuard; |
| // deno-fmt-ignore-file | ||
| import { Guard } from '../../guard/index.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // Guard | ||
| // ------------------------------------------------------------------ | ||
| export function IsGuardInterface(value) { | ||
| return Guard.IsObject(value) | ||
| && Guard.HasPropertyKey(value, 'check') | ||
| && Guard.HasPropertyKey(value, 'errors') | ||
| && Guard.IsFunction(value.check) | ||
| && Guard.IsFunction(value.errors); | ||
| } | ||
| export function IsGuard(value) { | ||
| return Guard.HasPropertyKey(value, '~guard') | ||
| && IsGuardInterface(value['~guard']); | ||
| } |
| import { type TSchema, type TSchemaOptions } from '../types/schema.mjs'; | ||
| import { type TDeferred } from '../types/deferred.mjs'; | ||
| import { type TAwaitedAction } from '../engine/awaited/instantiate.mjs'; | ||
| /** Creates a deferred Awaited action. */ | ||
| export type TAwaitedDeferred<Type extends TSchema> = (TDeferred<'Awaited', [Type]>); | ||
| /** Creates a deferred Awaited action. */ | ||
| export declare function AwaitedDeferred<Type extends TSchema>(type: Type, options?: TSchemaOptions): TAwaitedDeferred<Type>; | ||
| /** Applies an Awaited action to a type. */ | ||
| export type TAwaited<Type extends TSchema> = (TAwaitedAction<Type>); | ||
| /** | ||
| * Applies an Awaited action to a type. | ||
| * | ||
| * @deprecated This action is being removed in the next version of TypeBox. | ||
| */ | ||
| export declare function Awaited<Type extends TSchema>(type: Type, options?: TSchemaOptions): TAwaited<Type>; |
| // deno-fmt-ignore-file | ||
| import { Deferred } from '../types/deferred.mjs'; | ||
| import { AwaitedAction } from '../engine/awaited/instantiate.mjs'; | ||
| /** Creates a deferred Awaited action. */ | ||
| export function AwaitedDeferred(type, options = {}) { | ||
| return Deferred('Awaited', [type], options); | ||
| } | ||
| /** | ||
| * Applies an Awaited action to a type. | ||
| * | ||
| * @deprecated This action is being removed in the next version of TypeBox. | ||
| */ | ||
| export function Awaited(type, options = {}) { | ||
| return AwaitedAction(type, options); | ||
| } |
| export * from './instantiate.mjs'; |
| export * from './instantiate.mjs'; |
| import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs'; | ||
| import { type TProperties } from '../../types/properties.mjs'; | ||
| import { type TPromise } from '../../types/promise.mjs'; | ||
| import { type TAwaitedDeferred } from '../../action/awaited.mjs'; | ||
| import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs'; | ||
| type TAwaitedOperation<Type extends TSchema> = (Type extends TPromise<infer Type extends TSchema> ? TAwaitedOperation<Type> : Type); | ||
| export type TAwaitedAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TAwaitedOperation<Type> : TAwaitedDeferred<Type>> = Result; | ||
| export declare function AwaitedAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAwaitedAction<Type>; | ||
| export type TAwaitedInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAwaitedAction<InstantiateType>; | ||
| export declare function AwaitedInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAwaitedInstantiate<Context, State, Type>; | ||
| export {}; |
| // deno-fmt-ignore-file | ||
| import { Memory } from '../../../system/memory/index.mjs'; | ||
| import { IsPromise } from '../../types/promise.mjs'; | ||
| import { AwaitedDeferred } from '../../action/awaited.mjs'; | ||
| import { InstantiateType, CanInstantiate } from '../instantiate.mjs'; | ||
| function AwaitedOperation(type) { | ||
| return (IsPromise(type) | ||
| ? AwaitedOperation(type.item) | ||
| : type); | ||
| } | ||
| export function AwaitedAction(type, options) { | ||
| const result = CanInstantiate([type]) | ||
| ? Memory.Update(AwaitedOperation(type), {}, options) | ||
| : AwaitedDeferred(type, options); | ||
| return result; | ||
| } | ||
| export function AwaitedInstantiate(context, state, type, options) { | ||
| const instantiatedType = InstantiateType(context, state, type); | ||
| return AwaitedAction(instantiatedType, options); | ||
| } |
| import { type TSchema } from '../types/schema.mjs'; | ||
| import { type TProperties } from '../types/properties.mjs'; | ||
| import { type TAsyncIterator } from '../types/async_iterator.mjs'; | ||
| import { type TExtendsRight } from './extends_right.mjs'; | ||
| import { type TExtendsLeft } from './extends_left.mjs'; | ||
| export type TExtendsAsyncIterator<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TAsyncIterator<infer Type extends TSchema> ? TExtendsLeft<Inferred, Left, Type> : TExtendsRight<Inferred, TAsyncIterator<Left>, Right>); | ||
| export declare function ExtendsAsyncIterator<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsAsyncIterator<Inferred, Left, Right>; |
| // deno-fmt-ignore-file | ||
| import { AsyncIterator, IsAsyncIterator } from '../types/async_iterator.mjs'; | ||
| import { ExtendsRight } from './extends_right.mjs'; | ||
| import { ExtendsLeft } from './extends_left.mjs'; | ||
| export function ExtendsAsyncIterator(inferred, left, right) { | ||
| return (IsAsyncIterator(right) | ||
| ? ExtendsLeft(inferred, left, right.iteratorItems) | ||
| : ExtendsRight(inferred, AsyncIterator(left), right)); | ||
| } |
| import { type TSchema } from '../types/schema.mjs'; | ||
| import { type TProperties } from '../types/properties.mjs'; | ||
| import { type TIterator } from '../types/iterator.mjs'; | ||
| import { type TExtendsRight } from './extends_right.mjs'; | ||
| import { type TExtendsLeft } from './extends_left.mjs'; | ||
| export type TExtendsIterator<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TIterator<infer Type extends TSchema> ? TExtendsLeft<Inferred, Left, Type> : TExtendsRight<Inferred, TIterator<Left>, Right>); | ||
| export declare function ExtendsIterator<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsIterator<Inferred, Left, Right>; |
| // deno-fmt-ignore-file | ||
| import { Iterator, IsIterator } from '../types/iterator.mjs'; | ||
| import { ExtendsRight } from './extends_right.mjs'; | ||
| import { ExtendsLeft } from './extends_left.mjs'; | ||
| export function ExtendsIterator(inferred, left, right) { | ||
| return (IsIterator(right) | ||
| ? ExtendsLeft(inferred, left, right.iteratorItems) | ||
| : ExtendsRight(inferred, Iterator(left), right)); | ||
| } |
| import { type TSchema } from '../types/schema.mjs'; | ||
| import { type TProperties } from '../types/properties.mjs'; | ||
| import { type TPromise } from '../types/promise.mjs'; | ||
| import { type TExtendsRight } from './extends_right.mjs'; | ||
| import { type TExtendsLeft } from './extends_left.mjs'; | ||
| export type TExtendsPromise<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TPromise<infer Type extends TSchema> ? TExtendsLeft<Inferred, Left, Type> : TExtendsRight<Inferred, TPromise<Left>, Right>); | ||
| export declare function ExtendsPromise<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsPromise<Inferred, Left, Right>; |
| // deno-fmt-ignore-file | ||
| import { Promise, IsPromise } from '../types/promise.mjs'; | ||
| import { ExtendsRight } from './extends_right.mjs'; | ||
| import { ExtendsLeft } from './extends_left.mjs'; | ||
| export function ExtendsPromise(inferred, left, right) { | ||
| return (IsPromise(right) | ||
| ? ExtendsLeft(inferred, left, right.item) | ||
| : ExtendsRight(inferred, Promise(left), right)); | ||
| } |
| import { type StaticType, type StaticDirection } from './static.mjs'; | ||
| import { type TSchema, type TSchemaOptions } from './schema.mjs'; | ||
| import { type TProperties } from './properties.mjs'; | ||
| export type StaticAsyncIterator<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = AsyncIterableIterator<StaticType<Stack, Direction, Context, This, Type>>> = Result; | ||
| /** Represents a AsyncIterator. */ | ||
| export interface TAsyncIterator<Type extends TSchema = TSchema> extends TSchema { | ||
| '~kind': 'AsyncIterator'; | ||
| type: 'asyncIterator'; | ||
| iteratorItems: Type; | ||
| } | ||
| /** | ||
| * Creates a AsyncIterator type. | ||
| * | ||
| * @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples. | ||
| */ | ||
| export declare function AsyncIterator<Type extends TSchema>(iteratorItems: Type, options?: TSchemaOptions): TAsyncIterator<Type>; | ||
| /** Returns true if the given value is a TAsyncIterator */ | ||
| export declare function IsAsyncIterator(value: unknown): value is TAsyncIterator; | ||
| /** Extracts options from a TAsyncIterator. */ | ||
| export declare function AsyncIteratorOptions(type: TAsyncIterator): TSchemaOptions; |
| // deno-fmt-ignore-file | ||
| import { Memory } from '../../system/memory/index.mjs'; | ||
| import { IsKind } from './schema.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // Factory | ||
| // ------------------------------------------------------------------ | ||
| /** | ||
| * Creates a AsyncIterator type. | ||
| * | ||
| * @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples. | ||
| */ | ||
| export function AsyncIterator(iteratorItems, options) { | ||
| return Memory.Create({ '~kind': 'AsyncIterator' }, { type: 'asyncIterator', iteratorItems }, options); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Guard | ||
| // ------------------------------------------------------------------ | ||
| /** Returns true if the given value is a TAsyncIterator */ | ||
| export function IsAsyncIterator(value) { | ||
| return IsKind(value, 'AsyncIterator'); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Options | ||
| // ------------------------------------------------------------------ | ||
| /** Extracts options from a TAsyncIterator. */ | ||
| export function AsyncIteratorOptions(type) { | ||
| return Memory.Discard(type, ['~kind', 'type', 'iteratorItems']); | ||
| } |
| import { type TSchema } from './schema.mjs'; | ||
| import { type XGuard, type XGuardInterface } from '../../schema/types/index.mjs'; | ||
| export type StaticBase<Value extends unknown> = Value; | ||
| /** | ||
| * @deprecated Use Type.Refine() + Type.Unsafe() instead. | ||
| * | ||
| * | ||
| * **Reason:** It is noted that JavaScript class instances do not behave like | ||
| * plain objects during structural clone or when the TB compositor needs to | ||
| * assign dynamic modifier properties (such as '~optional'). | ||
| * | ||
| * Because the TypeBox compositor needs to transform schematics via object clone / | ||
| * property spread, these operations can result in class instance types losing | ||
| * methods on the prototype (via clone), which can lead to unexpected structures being | ||
| * returned. This has led to special-case (non-clone) handling for Base which needs | ||
| * to be removed as it has proven orthogonal to the TypeBox 1.x design. | ||
| * | ||
| * The Base type was introduced in 1.x to try integrate / embed Standard Schema into JSON | ||
| * Schema; however, support for integrated Standard Schema embedding will not be continued | ||
| * in TypeBox. This type will be removed in the next minor revision of TypeBox. | ||
| * | ||
| * ```typescript | ||
| * // (Deprecated) | ||
| * class DateType extends Type.Base<Date> { Check(value) { return value instanceof Date } } | ||
| * | ||
| * // (Future) | ||
| * const DateType = Type.Refine(Type.Unsafe<Date>({}), value => value instanceof Date) | ||
| * ``` | ||
| */ | ||
| export declare class Base<Value extends unknown = unknown> implements TSchema, XGuard<Value> { | ||
| readonly '~kind': 'Base'; | ||
| readonly '~guard': XGuardInterface<Value>; | ||
| constructor(); | ||
| /** Checks a value or returns false if invalid */ | ||
| Check(_value: unknown): _value is Value; | ||
| /** Returns errors for a value. Return an empty array if valid. */ | ||
| Errors(_value: unknown): object[]; | ||
| /** Converts a value into this type */ | ||
| Convert(value: unknown): unknown; | ||
| /** Cleans a value according to this type */ | ||
| Clean(value: unknown): unknown; | ||
| /** Returns a default value for this type */ | ||
| Default(value: unknown): unknown; | ||
| /** Creates a new instance of this type */ | ||
| Create(): Value; | ||
| /** Clones this type */ | ||
| Clone(): Base; | ||
| } | ||
| /** Returns true if the given value is a Base type. */ | ||
| export declare function IsBase(value: unknown): value is Base; |
| // deno-fmt-ignore-file | ||
| import { Settings } from '../../system/settings/index.mjs'; | ||
| import { IsKind } from './schema.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // Type.Base<...> | ||
| // ------------------------------------------------------------------ | ||
| function BaseProperty(value) { | ||
| return { | ||
| enumerable: Settings.Get().enumerableKind, | ||
| writable: false, | ||
| configurable: false, | ||
| value | ||
| }; | ||
| } | ||
| /** | ||
| * @deprecated Use Type.Refine() + Type.Unsafe() instead. | ||
| * | ||
| * | ||
| * **Reason:** It is noted that JavaScript class instances do not behave like | ||
| * plain objects during structural clone or when the TB compositor needs to | ||
| * assign dynamic modifier properties (such as '~optional'). | ||
| * | ||
| * Because the TypeBox compositor needs to transform schematics via object clone / | ||
| * property spread, these operations can result in class instance types losing | ||
| * methods on the prototype (via clone), which can lead to unexpected structures being | ||
| * returned. This has led to special-case (non-clone) handling for Base which needs | ||
| * to be removed as it has proven orthogonal to the TypeBox 1.x design. | ||
| * | ||
| * The Base type was introduced in 1.x to try integrate / embed Standard Schema into JSON | ||
| * Schema; however, support for integrated Standard Schema embedding will not be continued | ||
| * in TypeBox. This type will be removed in the next minor revision of TypeBox. | ||
| * | ||
| * ```typescript | ||
| * // (Deprecated) | ||
| * class DateType extends Type.Base<Date> { Check(value) { return value instanceof Date } } | ||
| * | ||
| * // (Future) | ||
| * const DateType = Type.Refine(Type.Unsafe<Date>({}), value => value instanceof Date) | ||
| * ``` | ||
| */ | ||
| export class Base { | ||
| constructor() { | ||
| globalThis.Object.defineProperty(this, '~kind', BaseProperty('Base')); | ||
| globalThis.Object.defineProperty(this, '~guard', BaseProperty({ | ||
| check: (value) => this.Check(value), | ||
| errors: (value) => this.Errors(value) | ||
| })); | ||
| } | ||
| /** Checks a value or returns false if invalid */ | ||
| Check(_value) { | ||
| return true; | ||
| } | ||
| /** Returns errors for a value. Return an empty array if valid. */ | ||
| Errors(_value) { | ||
| return []; | ||
| } | ||
| /** Converts a value into this type */ | ||
| Convert(value) { | ||
| return value; | ||
| } | ||
| /** Cleans a value according to this type */ | ||
| Clean(value) { | ||
| return value; | ||
| } | ||
| /** Returns a default value for this type */ | ||
| Default(value) { | ||
| return value; | ||
| } | ||
| /** Creates a new instance of this type */ | ||
| Create() { | ||
| throw new Error('Create not implemented'); | ||
| } | ||
| /** Clones this type */ | ||
| Clone() { | ||
| throw Error('Clone not implemented'); | ||
| } | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Guard | ||
| // ------------------------------------------------------------------ | ||
| /** Returns true if the given value is a Base type. */ | ||
| export function IsBase(value) { | ||
| return IsKind(value, 'Base'); | ||
| } |
| import { type StaticType, type StaticDirection } from './static.mjs'; | ||
| import { type TSchema, type TSchemaOptions } from './schema.mjs'; | ||
| import { type TProperties } from './properties.mjs'; | ||
| export type StaticIterator<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = IterableIterator<StaticType<Stack, Direction, Context, This, Type>>> = Result; | ||
| /** Represents an Iterator. */ | ||
| export interface TIterator<Type extends TSchema = TSchema> extends TSchema { | ||
| '~kind': 'Iterator'; | ||
| type: 'iterator'; | ||
| iteratorItems: Type; | ||
| } | ||
| /** | ||
| * Creates a Iterator type. | ||
| * | ||
| * @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples. | ||
| */ | ||
| export declare function Iterator<Type extends TSchema>(iteratorItems: Type, options?: TSchemaOptions): TIterator<Type>; | ||
| /** Returns true if the given value is TIterator. */ | ||
| export declare function IsIterator(value: unknown): value is TIterator; | ||
| /** Extracts options from a TIterator. */ | ||
| export declare function IteratorOptions(type: TIterator): TSchemaOptions; |
| // deno-fmt-ignore-file | ||
| import { Memory } from '../../system/memory/index.mjs'; | ||
| import { IsKind } from './schema.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // Factory | ||
| // ------------------------------------------------------------------ | ||
| /** | ||
| * Creates a Iterator type. | ||
| * | ||
| * @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples. | ||
| */ | ||
| export function Iterator(iteratorItems, options) { | ||
| return Memory.Create({ '~kind': 'Iterator' }, { type: 'iterator', iteratorItems }, options); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Guard | ||
| // ------------------------------------------------------------------ | ||
| /** Returns true if the given value is TIterator. */ | ||
| export function IsIterator(value) { | ||
| return IsKind(value, 'Iterator'); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Options | ||
| // ------------------------------------------------------------------ | ||
| /** Extracts options from a TIterator. */ | ||
| export function IteratorOptions(type) { | ||
| return Memory.Discard(type, ['~kind', 'type', 'iteratorItems']); | ||
| } |
| import { type StaticType, type StaticDirection } from './static.mjs'; | ||
| import { type TSchema, type TSchemaOptions } from './schema.mjs'; | ||
| import { type TProperties } from './properties.mjs'; | ||
| export type StaticPromise<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = Promise<StaticType<Stack, Direction, Context, This, Type>>> = Result; | ||
| /** Represents a Promise type. */ | ||
| export interface TPromise<Type extends TSchema = TSchema> extends TSchema { | ||
| '~kind': 'Promise'; | ||
| type: 'promise'; | ||
| item: Type; | ||
| } | ||
| /** | ||
| * Creates a Promise type. | ||
| * | ||
| * @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples. | ||
| */ | ||
| export declare function _Promise_<Type extends TSchema>(item: Type, options?: TSchemaOptions): TPromise<Type>; | ||
| export { _Promise_ as Promise }; | ||
| /** Returns true if the given type is TPromise. */ | ||
| export declare function IsPromise(value: unknown): value is TPromise; | ||
| /** Extracts options from a TPromise. */ | ||
| export declare function PromiseOptions(type: TPromise): TSchemaOptions; |
| // deno-fmt-ignore-file | ||
| import { Memory } from '../../system/memory/index.mjs'; | ||
| import { IsKind } from './schema.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // Factory | ||
| // ------------------------------------------------------------------ | ||
| /** | ||
| * Creates a Promise type. | ||
| * | ||
| * @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples. | ||
| */ | ||
| export function _Promise_(item, options) { | ||
| return Memory.Create({ ['~kind']: 'Promise' }, { type: 'promise', item }, options); | ||
| } | ||
| export { _Promise_ as Promise }; | ||
| // ------------------------------------------------------------------ | ||
| // Guard | ||
| // ------------------------------------------------------------------ | ||
| /** Returns true if the given type is TPromise. */ | ||
| export function IsPromise(value) { | ||
| return IsKind(value, 'Promise'); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Options | ||
| // ------------------------------------------------------------------ | ||
| /** Extracts options from a TPromise. */ | ||
| export function PromiseOptions(type) { | ||
| return Memory.Discard(type, ['~kind', 'type', 'item']); | ||
| } |
| import type { TProperties, Base } from '../../type/index.mjs'; | ||
| export declare function FromBase(_context: TProperties, type: Base, value: unknown): unknown; |
| // deno-fmt-ignore-file | ||
| export function FromBase(_context, type, value) { | ||
| return type.Clean(value); | ||
| } |
| import type { Base, TProperties } from '../../type/index.mjs'; | ||
| export declare function FromBase(_context: TProperties, type: Base, value: unknown): unknown; |
| // deno-fmt-ignore-file | ||
| export function FromBase(_context, type, value) { | ||
| return type.Convert(value); | ||
| } |
| import type { TProperties, TAsyncIterator } from '../../type/index.mjs'; | ||
| export declare function FromAsyncIterator(_context: TProperties, _type: TAsyncIterator): unknown; |
| // deno-fmt-ignore-file | ||
| async function* CreateAsyncIterator() { } | ||
| export function FromAsyncIterator(_context, _type) { | ||
| return CreateAsyncIterator(); | ||
| } |
| import type { TProperties, Base } from '../../type/index.mjs'; | ||
| export declare function FromBase(_context: TProperties, type: Base): unknown; |
| // deno-fmt-ignore-file | ||
| export function FromBase(_context, type) { | ||
| return type.Create(); | ||
| } |
| import type { TProperties, TIterator } from '../../type/index.mjs'; | ||
| export declare function FromIterator(_context: TProperties, _type: TIterator): unknown; |
| // deno-fmt-ignore-file | ||
| function* CreateIterator() { } | ||
| export function FromIterator(_context, _type) { | ||
| return CreateIterator(); | ||
| } |
| import type { TProperties, TPromise } from '../../type/index.mjs'; | ||
| export declare function FromPromise(context: TProperties, type: TPromise): unknown; |
| // deno-fmt-ignore-file | ||
| import { FromType } from './from_type.mjs'; | ||
| export function FromPromise(context, type) { | ||
| return Promise.resolve(FromType(context, type.item)); | ||
| } |
| import type { TProperties, Base } from '../../type/index.mjs'; | ||
| export declare function FromBase(context: TProperties, type: Base, value: unknown): unknown; |
| // deno-fmt-ignore-file | ||
| // deno-lint-ignore-file | ||
| export function FromBase(context, type, value) { | ||
| return type.Default(value); | ||
| } |
| export declare class MutateError extends Error { | ||
| constructor(message: string); | ||
| } |
| // deno-fmt-ignore-file | ||
| export class MutateError extends Error { | ||
| constructor(message) { | ||
| super(message); | ||
| } | ||
| } |
| import { type TMutable } from './mutate.mjs'; | ||
| export declare function FromArray(root: TMutable, path: string, current: unknown, next: unknown[]): void; |
| // deno-fmt-ignore-file | ||
| import { Guard } from '../../guard/index.mjs'; | ||
| import { Clone } from '../clone/index.mjs'; | ||
| import { Pointer } from '../pointer/index.mjs'; | ||
| import { FromValue } from './from_value.mjs'; | ||
| export function FromArray(root, path, current, next) { | ||
| if (!Guard.IsArray(current)) { | ||
| Pointer.Set(root, path, Clone(next)); | ||
| } | ||
| else { | ||
| for (let index = 0; index < next.length; index++) { | ||
| FromValue(root, `${path}/${index}`, current[index], next[index]); | ||
| } | ||
| current.splice(next.length); | ||
| } | ||
| } |
| import { type TMutable } from './mutate.mjs'; | ||
| export declare function FromObject(root: TMutable, path: string, current: unknown, next: Record<string, unknown>): void; |
| // deno-fmt-ignore-file | ||
| import { Guard } from '../../guard/index.mjs'; | ||
| import { Pointer } from '../pointer/index.mjs'; | ||
| import { Clone } from '../clone/index.mjs'; | ||
| import { FromValue } from './from_value.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // AssertKey | ||
| // ------------------------------------------------------------------ | ||
| function AssertKey(key) { | ||
| if (Guard.IsUnsafePropertyKey(key)) | ||
| throw Error('Attempted to Mutate with unsafe property key'); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // AssertKey | ||
| // ------------------------------------------------------------------ | ||
| export function FromObject(root, path, current, next) { | ||
| if (!Guard.IsObjectNotArray(current)) { | ||
| Pointer.Set(root, path, Clone(next)); | ||
| } | ||
| else { | ||
| const currentKeys = Guard.Keys(current); | ||
| const nextKeys = Guard.Keys(next); | ||
| for (const currentKey of currentKeys) { | ||
| AssertKey(currentKey); | ||
| if (!nextKeys.includes(currentKey)) { | ||
| delete current[currentKey]; | ||
| } | ||
| } | ||
| for (const nextKey of nextKeys) { | ||
| AssertKey(nextKey); | ||
| if (!currentKeys.includes(nextKey)) { | ||
| current[nextKey] = next[nextKey]; | ||
| } | ||
| } | ||
| for (const nextKey of nextKeys) { | ||
| AssertKey(nextKey); | ||
| FromValue(root, `${path}/${nextKey}`, current[nextKey], next[nextKey]); | ||
| } | ||
| } | ||
| } |
| import { type TMutable } from './mutate.mjs'; | ||
| export declare function FromUnknown(root: TMutable, path: string, current: unknown, next: unknown): void; |
| // deno-fmt-ignore-file | ||
| import { Pointer } from '../pointer/index.mjs'; | ||
| export function FromUnknown(root, path, current, next) { | ||
| if (current === next) | ||
| return; | ||
| Pointer.Set(root, path, next); | ||
| } |
| import { type TMutable } from './mutate.mjs'; | ||
| export declare function FromValue(root: TMutable, path: string, current: unknown, next: unknown): void; |
| // deno-fmt-ignore-file | ||
| import { Guard } from '../../guard/index.mjs'; | ||
| import { FromArray } from './from_array.mjs'; | ||
| import { FromObject } from './from_object.mjs'; | ||
| import { FromUnknown } from './from_unknown.mjs'; | ||
| export function FromValue(root, path, current, next) { | ||
| if (Guard.IsArray(next)) | ||
| return FromArray(root, path, current, next); | ||
| if (Guard.IsObject(next)) | ||
| return FromObject(root, path, current, next); | ||
| return FromUnknown(root, path, current, next); | ||
| } |
| export * from './mutate.mjs'; |
| export * from './mutate.mjs'; |
| export type TMutable = { | ||
| [key: string]: unknown; | ||
| } | unknown[]; | ||
| /** | ||
| * Performs a deep structural assignment, applying values from next to current while retaining internal references. This function | ||
| * is written for use in infrastructure that interprets reference changes as a signal to perform some action (i.e. React redraw), this | ||
| * function can mitigate this by applying mutable updates deep within a value, ensuring parent references are retained. | ||
| * | ||
| * @deprecated This function is being removed in the next version but will be retained as a reference under examples. | ||
| */ | ||
| export declare function Mutate(current: TMutable, next: TMutable): void; |
| // deno-fmt-ignore-file | ||
| import { Guard, GlobalsGuard } from '../../guard/index.mjs'; | ||
| import { MutateError } from './error.mjs'; | ||
| import { FromValue } from './from_value.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // IsNonMutableValue | ||
| // ------------------------------------------------------------------ | ||
| function IsNonMutableValue(value) { | ||
| return GlobalsGuard.IsTypeArray(value) | ||
| || GlobalsGuard.IsDate(value) | ||
| || GlobalsGuard.IsMap(value) | ||
| || GlobalsGuard.IsSet(value) | ||
| || Guard.IsNumber(value) | ||
| || Guard.IsString(value) | ||
| || Guard.IsBoolean(value) | ||
| || Guard.IsSymbol(value); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // IsTrueObject | ||
| // ------------------------------------------------------------------ | ||
| function IsMismatchedValue(left, right) { | ||
| return ((Guard.IsObjectNotArray(left) && Guard.IsArray(right)) || | ||
| (Guard.IsArray(left) && Guard.IsObjectNotArray(right))); | ||
| } | ||
| // ------------------------------------------------------------------ | ||
| // Mutate | ||
| // ------------------------------------------------------------------ | ||
| /** | ||
| * Performs a deep structural assignment, applying values from next to current while retaining internal references. This function | ||
| * is written for use in infrastructure that interprets reference changes as a signal to perform some action (i.e. React redraw), this | ||
| * function can mitigate this by applying mutable updates deep within a value, ensuring parent references are retained. | ||
| * | ||
| * @deprecated This function is being removed in the next version but will be retained as a reference under examples. | ||
| */ | ||
| export function Mutate(current, next) { | ||
| if (IsNonMutableValue(current) || IsNonMutableValue(next)) | ||
| throw new MutateError('Only object and array types can be mutated at the root level'); | ||
| if (IsMismatchedValue(current, next)) | ||
| throw new MutateError('Cannot assign due type mismatch of assignable values'); | ||
| FromValue(current, '', current, next); | ||
| } |
| import type { TProperties, Base } from '../../type/index.mjs'; | ||
| export declare function FromBase(context: TProperties, type: Base, value: unknown): unknown; |
| // deno-fmt-ignore-file | ||
| import { FromUnknown } from './from_unknown.mjs'; | ||
| // ------------------------------------------------------------------ | ||
| // FromBase | ||
| // ------------------------------------------------------------------ | ||
| export function FromBase(context, type, value) { | ||
| return FromUnknown(context, type, value); | ||
| } |
1460060
-3.49%1367
-3.8%16598
-3.86%