From d5e9c99e6ef068bff4c4f92db5ccc0835f6b84b3 Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Wed, 2 Nov 2022 16:51:40 -0400 Subject: [PATCH] feat: add some more type exports --- src/index.ts | 5 ++++- src/object.ts | 11 +++++++---- src/schema.ts | 5 ++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index e8226ad67..8300d83d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,7 @@ import isSchema from './util/isSchema'; import setLocale, { LocaleObject } from './setLocale'; import Schema, { AnySchema, + CastOptions as BaseCastOptions, SchemaRefDescription, SchemaInnerTypeDescription, SchemaObjectDescription, @@ -51,6 +52,8 @@ function addMethod(schemaType: any, name: string, fn: any) { export type AnyObjectSchema = ObjectSchema; +export type CastOptions = Omit; + export type { AnyObject, InferType, @@ -67,7 +70,7 @@ export type { SchemaFieldDescription, SchemaDescription, LocaleObject, - ValidateOptions + ValidateOptions, }; export { diff --git a/src/object.ts b/src/object.ts index fbdcc00fb..dc5ce2ac0 100644 --- a/src/object.ts +++ b/src/object.ts @@ -183,7 +183,6 @@ export default class ObjectSchema< // safe to mutate since this is fired in sequence innerOptions.path = (options.path ? `${options.path}.` : '') + prop; - // innerOptions.value = value[prop]; field = field.resolve({ value: inputValue, @@ -268,9 +267,13 @@ export default class ObjectSchema< ); } - this.runTests({ tests, value }, panic, (fieldErrors) => { - next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value); - }); + this.runTests( + { tests, value, originalValue, options }, + panic, + (fieldErrors) => { + next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value); + }, + ); }); } diff --git a/src/schema.ts b/src/schema.ts index 92b696452..8d0f65d99 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -67,6 +67,7 @@ export interface CastOptions { stripUnknown?: boolean; // XXX: should be private? path?: string; + resolved?: boolean; } export interface CastOptionalityOptions @@ -449,9 +450,7 @@ export default abstract class Schema< /** * Executes a set of validations, either schema, produced Tests or a nested - * schema validate result. `args` is intended for schema validation tests, but - * isn't required to allow the helper to awkwardly be used to run nested array/object - * validations. + * schema validate result. */ protected runTests( runOptions: TestRunOptions,