Skip to content

Commit d8fddf8

Browse files
committed
add: ValidateReturnType
1 parent 90e8abd commit d8fddf8

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { compileSchema } from "./src/compileSchema";
22
export type { CompileOptions } from "./src/compileSchema";
3-
export type { Context, SchemaNode, GetNodeOptions } from "./src/SchemaNode";
3+
export type { Context, SchemaNode, GetNodeOptions, ValidateReturnType } from "./src/SchemaNode";
44
export type { DataNode } from "./src/methods/toDataNodes";
55
export type { Draft, DraftVersion } from "./src/Draft";
66
export type { JsonError, JsonPointer, JsonSchema, OptionalNodeOrError, NodeOrError } from "./src/types";

src/SchemaNode.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ export type GetNodeOptions = {
155155
pointer?: string;
156156
};
157157

158+
export type ValidateReturnType = {
159+
/**
160+
* True, if data is valid to the compiled schema.
161+
* Does not include async errors.
162+
*/
163+
valid: boolean;
164+
/**
165+
* List of validation errors or empty
166+
*/
167+
errors: JsonError[];
168+
/**
169+
* List of Promises resolving to `JsonError|undefined` or empty.
170+
*/
171+
errorsAsync: Promise<JsonError | undefined>[];
172+
};
173+
158174
export function joinDynamicId(a?: string, b?: string) {
159175
if (a == b) {
160176
return a ?? "";
@@ -334,7 +350,7 @@ export const SchemaNodeMethods = {
334350
}
335351
});
336352

337-
const result: { valid: boolean; errors: JsonError[]; errorsAsync: Promise<JsonError | undefined>[] } = {
353+
const result: ValidateReturnType = {
338354
valid: flatErrorList.length === 0,
339355
errors: syncErrors,
340356
errorsAsync

0 commit comments

Comments
 (0)