Revision 0.8.5 (#14)
* Remove WeakMap lookup on Validator (Optimization) * Version
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@sinclair/typemap",
|
||||
"version": "0.8.4",
|
||||
"version": "0.8.5",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@sinclair/typemap",
|
||||
"version": "0.8.4",
|
||||
"version": "0.8.5",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@arethetypeswrong/cli": "^0.17.2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sinclair/typemap",
|
||||
"version": "0.8.4",
|
||||
"version": "0.8.5",
|
||||
"description": "Unified Syntax and Type Compiler for Runtime Type Systems",
|
||||
"author": "sinclairzx81",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -72,31 +72,31 @@ export class StandardSchemaProps<Type extends t.TSchema> implements StandardSche
|
||||
// Validator<TSchema>
|
||||
// ------------------------------------------------------------------
|
||||
export class Validator<Type extends t.TSchema> implements StandardSchemaV1<Type, t.Static<Type>> {
|
||||
readonly #standard: StandardSchemaProps<Type>
|
||||
readonly #check: TypeCheck<Type>
|
||||
private readonly _standard: StandardSchemaProps<Type>
|
||||
private readonly _check: TypeCheck<Type>
|
||||
constructor(check: TypeCheck<Type>) {
|
||||
this.#standard = new StandardSchemaProps<Type>(check)
|
||||
this.#check = check
|
||||
this._standard = new StandardSchemaProps<Type>(check)
|
||||
this._check = check
|
||||
}
|
||||
/** Standard Schema Interface */
|
||||
public get ['~standard'](): StandardSchemaProps<Type> {
|
||||
return this.#standard
|
||||
return this._standard
|
||||
}
|
||||
/** Returns the code used by this validator. */
|
||||
public Code(): string {
|
||||
return this.#check.Code()
|
||||
return this._check.Code()
|
||||
}
|
||||
/** Parses this value. Do not use this function for high throughput validation */
|
||||
public Parse(value: unknown): t.StaticDecode<Type> {
|
||||
return Value.Parse(this.#check.Schema(), value)
|
||||
return Value.Parse(this._check.Schema(), value)
|
||||
}
|
||||
/** Checks if this value matches the type */
|
||||
public Check(value: unknown): value is t.Static<Type> {
|
||||
return this.#check.Check(value)
|
||||
return this._check.Check(value)
|
||||
}
|
||||
/** Returns errors for this value */
|
||||
public Errors(value: unknown): ValueErrorIterator {
|
||||
return this.#check.Errors(value)
|
||||
return this._check.Errors(value)
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
@@ -108,4 +108,4 @@ export function Signature(args: any[]): [parameter: Record<PropertyKey, object>,
|
||||
Signature4(args) ? [{}, args[0], {}] :
|
||||
[{}, 'never', {}]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,6 @@ export function TypeBox(...args: any[]): never {
|
||||
options) as never
|
||||
}
|
||||
|
||||
|
||||
/** Creates a TypeBox type from Syntax or another Type */
|
||||
export function Type<Parameter extends TParameter, Type extends string>(parameter: Parameter, type: Type, options?: TSyntaxOptions): TTypeBox<Parameter, Type>
|
||||
/** Creates a TypeBox type from Syntax or another Type */
|
||||
@@ -99,4 +98,4 @@ export function Type<Type extends object | string>(type: Type, options?: TSyntax
|
||||
// prettier-ignore
|
||||
export function Type(...args: any[]): never {
|
||||
return TypeBox.apply(null, args as never) as never
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user