@sinclair/typebox
Advanced tools
Comparing version 0.24.0 to 0.24.1
import * as Types from '../typebox'; | ||
export declare type CheckFunction = (value: unknown) => CheckOk | CheckFail; | ||
export interface CheckOk { | ||
ok: true; | ||
} | ||
export interface CheckFail { | ||
ok: false; | ||
} | ||
export declare type CheckFunction = (value: unknown) => boolean; | ||
export declare class TypeCheckAssertError extends Error { | ||
@@ -10,0 +4,0 @@ readonly schema: Types.TSchema; |
@@ -54,4 +54,3 @@ "use strict"; | ||
Check(value) { | ||
const result = this.checkFunc(value); | ||
return result.ok; | ||
return this.checkFunc(value); | ||
} | ||
@@ -63,4 +62,3 @@ /** Asserts the given value and throws a TypeCheckAssertError if invalid. */ | ||
// https://github.com/microsoft/TypeScript/issues/36931 | ||
const result = this.checkFunc(value); | ||
if (!result.ok) | ||
if (!this.checkFunc(value)) | ||
throw new TypeCheckAssertError(this.schema, value); | ||
@@ -192,7 +190,7 @@ } | ||
const func = CreateFunctionName(schema.$ref); | ||
yield CreateCondition(schema, path, `(${func}(${path}).ok)`); | ||
yield CreateCondition(schema, path, `(${func}(${path}))`); | ||
} | ||
function* Self(schema, path) { | ||
const func = CreateFunctionName(schema.$ref); | ||
yield CreateCondition(schema, path, `(${func}(${path}).ok)`); | ||
yield CreateCondition(schema, path, `(${func}(${path}))`); | ||
} | ||
@@ -246,3 +244,3 @@ function* String(schema, path) { | ||
PushLocal(body); | ||
yield CreateCondition(schema, path, `(${name}(${path}).ok)`); | ||
yield CreateCondition(schema, path, `(${name}(${path}))`); | ||
return; | ||
@@ -333,4 +331,4 @@ } | ||
function CreateFunction(name, conditions) { | ||
const statements = conditions.map((condition, index) => ` if(!${condition.expr}) { return { ok: false } }`); | ||
return `function ${name}(value) {\n${statements.join('\n')}\n return { ok: true }\n}`; | ||
const statements = conditions.map((condition, index) => ` if(!${condition.expr}) { return false }`); | ||
return `function ${name}(value) {\n${statements.join('\n')}\n return true\n}`; | ||
} | ||
@@ -337,0 +335,0 @@ // ------------------------------------------------------------------- |
{ | ||
"name": "@sinclair/typebox", | ||
"version": "0.24.0", | ||
"version": "0.24.1", | ||
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -87,11 +87,2 @@ export declare const Kind: unique symbol; | ||
} | ||
export interface TExclude<T extends TUnion, U extends TUnion> extends TUnion { | ||
[Kind]: 'Union'; | ||
static: Exclude<Static<T, this['params']>, Static<U, this['params']>>; | ||
} | ||
export interface TExtract<T extends TSchema, U extends TUnion> extends TUnion { | ||
[Kind]: 'Union'; | ||
static: Extract<Static<T, this['params']>, Static<U, this['params']>>; | ||
} | ||
export declare type TExtends<T extends TSchema, U extends TSchema, X extends TSchema, Y extends TSchema> = T extends TAny ? (U extends TUnknown ? X : U extends TAny ? X : TUnion<[X, Y]>) : T extends U ? X : Y; | ||
export declare type TFunctionParameters<T extends readonly TSchema[], P extends unknown[]> = [...{ | ||
@@ -98,0 +89,0 @@ [K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
6
164156
2445