Skip to content

Commit

Permalink
feat: add some more type exports
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Nov 8, 2022
1 parent dcb4b63 commit d5e9c99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import isSchema from './util/isSchema';
import setLocale, { LocaleObject } from './setLocale';
import Schema, {
AnySchema,
CastOptions as BaseCastOptions,
SchemaRefDescription,
SchemaInnerTypeDescription,
SchemaObjectDescription,
Expand Down Expand Up @@ -51,6 +52,8 @@ function addMethod(schemaType: any, name: string, fn: any) {

export type AnyObjectSchema = ObjectSchema<any, any, any, any>;

export type CastOptions = Omit<BaseCastOptions, 'path' | 'resolved'>;

export type {
AnyObject,
InferType,
Expand All @@ -67,7 +70,7 @@ export type {
SchemaFieldDescription,
SchemaDescription,
LocaleObject,
ValidateOptions
ValidateOptions,
};

export {
Expand Down
11 changes: 7 additions & 4 deletions src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
},
);
});
}

Expand Down
5 changes: 2 additions & 3 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface CastOptions<C = {}> {
stripUnknown?: boolean;
// XXX: should be private?
path?: string;
resolved?: boolean;
}

export interface CastOptionalityOptions<C = {}>
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d5e9c99

Please sign in to comment.