Skip to content

Commit 468f3ed

Browse files
committed
dist: update
1 parent af54dde commit 468f3ed

14 files changed

+81
-175
lines changed

dist/jsonSchemaLibrary.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/module/src/SchemaNode.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,23 @@ export const SchemaNodeMethods = {
175175
validate(data, pointer = "#", path = []) {
176176
var _a;
177177
const errors = (_a = validateNode(this, data, pointer, path)) !== null && _a !== void 0 ? _a : [];
178+
const syncErrors = [];
178179
const flatErrorList = sanitizeErrors(Array.isArray(errors) ? errors : [errors]).filter(isJsonError);
179-
return {
180+
const errorsAsync = [];
181+
sanitizeErrors(Array.isArray(errors) ? errors : [errors]).forEach((error) => {
182+
if (isJsonError(error)) {
183+
syncErrors.push(error);
184+
}
185+
else if (error instanceof Promise) {
186+
errorsAsync.push(error);
187+
}
188+
});
189+
const result = {
180190
valid: flatErrorList.length === 0,
181-
errors: flatErrorList
182-
};
183-
},
184-
/**
185-
* @returns a promise which resolves to validation-result
186-
*/
187-
async validateAsync(data, pointer = "#", path = []) {
188-
var _a;
189-
const errors = (_a = validateNode(this, data, pointer, path)) !== null && _a !== void 0 ? _a : [];
190-
let resolvedErrors = await Promise.all(sanitizeErrors(Array.isArray(errors) ? errors : [errors]));
191-
resolvedErrors = sanitizeErrors(resolvedErrors);
192-
return {
193-
valid: resolvedErrors.length === 0,
194-
errors: resolvedErrors
191+
errors: syncErrors,
192+
errorsAsync
195193
};
194+
return result;
196195
},
197196
/**
198197
* Register a JSON Schema as a remote-schema to be resolved by $ref, $anchor, etc

dist/module/src/compileSchema.reduceSchema.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ describe("compileSchema : reduceNode", () => {
114114
dependencies: { one: ["two"], two: { type: "number" } }
115115
});
116116
const { node: reduced } = node.reduceNode({});
117-
console.log("reudced schema", reduced.schema);
118117
assert.deepEqual(reduced.schema, {
119118
type: "object",
120119
properties: { one: { type: "string" } }

dist/module/src/compileSchema.validate.test.js

Lines changed: 19 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -842,108 +842,50 @@ describe("compileSchema.validate : format", () => {
842842
});
843843
});
844844
});
845-
describe("compileSchema.validateAsync", () => {
846-
it("should return a promise", () => {
847-
const promise = compileSchema({
848-
type: "number"
849-
}).validateAsync(4);
850-
assert(promise instanceof Promise);
851-
});
845+
describe("compileSchema.validate - errorsAsync", () => {
852846
it("should resolve successfull with an empty error", async () => {
853-
const promise = compileSchema({
854-
type: "number"
855-
}).validateAsync(4);
856-
const { errors } = await promise;
857-
assert.deepEqual(errors.length, 0);
858-
});
859-
it("should resolve with errors for a failed validation", async () => {
860-
const promise = compileSchema({
847+
const { errorsAsync } = compileSchema({
861848
type: "number"
862-
}).validateAsync("4");
863-
const { errors } = await promise;
864-
assert.deepEqual(errors.length, 1);
865-
assert.deepEqual(errors[0].code, "type-error");
849+
}).validate(4);
850+
const asyncErrors = await Promise.all(errorsAsync);
851+
assert.deepEqual(asyncErrors.length, 0);
866852
});
867853
describe("async validation", () => {
868854
let draft;
869855
beforeEach(() => {
870856
draft = {
871857
...draft2020,
872858
keywords: [
873-
// @ts-expect-error asd
874859
...draft2020.keywords,
875860
{
876861
id: "async",
877862
keyword: "async-error",
878863
addValidate: (node) => node.schema.asyncError != null,
879-
// @ts-expect-error asd
880-
validate: ({ node }) => {
864+
validate: async ({ node }) => {
881865
if (node.schema.asyncError === false) {
882-
return;
866+
return undefined;
883867
}
884-
return new Promise((resolve) => resolve([
885-
node.createError("type-error", {
886-
schema: {},
887-
pointer: "",
888-
value: ""
889-
})
890-
]));
868+
return node.createError("type-error", {
869+
schema: {},
870+
pointer: "",
871+
value: ""
872+
});
891873
}
892874
}
893875
]
894876
};
895877
it("should resolve async validation returning no error", async () => {
896-
const { errors } = await compileSchema({ type: "number", asyncError: false }, { drafts: [draft] }).validateAsync(4);
878+
const { errors, errorsAsync } = compileSchema({ type: "number", asyncError: false }, { drafts: [draft] }).validate(4);
879+
const asyncErrors = await Promise.all(errorsAsync);
897880
assert.deepEqual(errors.length, 0);
881+
assert.deepEqual(asyncErrors.length, 0);
898882
});
899883
it("should resolve async validation errors", async () => {
900-
const { errors } = await compileSchema({ type: "number", asyncError: true }, { drafts: [draft] }).validateAsync(4);
901-
assert.deepEqual(errors.length, 1);
902-
assert.deepEqual(errors[0].code, "type-error");
884+
const { errorsAsync } = compileSchema({ type: "number", asyncError: true }, { drafts: [draft] }).validate(4);
885+
const asyncErrors = await Promise.all(errorsAsync);
886+
assert.deepEqual(asyncErrors.length, 1);
887+
assert.deepEqual(asyncErrors[0].code, "type-error");
903888
});
904889
});
905890
});
906-
// describe("on-error", () => {
907-
// before(() => {
908-
// // adds an async validation helper to { type: 'string', asyncError: true }
909-
// // @ts-expect-error type mismatch of vladation function
910-
// addValidator.keyword(draft, "string", "async-error", (node) => {
911-
// return node.schema.asyncError
912-
// ? new Promise((resolve) =>
913-
// // eslint-disable-next-line max-nested-callbacks
914-
// resolve({
915-
// type: "error",
916-
// name: "async-error",
917-
// code: "test-async-error",
918-
// message: "custom test error"
919-
// })
920-
// )
921-
// : Promise.resolve();
922-
// });
923-
// });
924-
// it("should call onProgress immediately with error", async () => {
925-
// const errors: JsonError[] = [];
926-
// return validateAsync(
927-
// draft,
928-
// {
929-
// async: "test async progres",
930-
// anotherError: 44
931-
// },
932-
// {
933-
// schema: {
934-
// type: "object",
935-
// properties: {
936-
// async: { type: "string", asyncError: true },
937-
// anotherError: { type: "string" }
938-
// }
939-
// },
940-
// onError: (err) => errors.push(err)
941-
// }
942-
// ).then(() => {
943-
// assert.deepEqual(errors.length, 2);
944-
// assert.deepEqual(errors[0].name).to.eq("type-error");
945-
// assert.deepEqual(errors[1].name).to.eq("async-error");
946-
// });
947-
// });
948-
// });
949891
});

dist/module/src/draft2019-09/compileSchema.validate.test.js

Lines changed: 33 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -872,68 +872,41 @@ describe("compileSchema.validate : format", () => {
872872
});
873873
});
874874
});
875-
describe("compileSchema.validateAsync", () => {
876-
it("should return a promise", () => {
877-
const promise = compileSchema({
878-
$schema,
879-
type: "number"
880-
}).validateAsync(4);
881-
assert(promise instanceof Promise);
882-
});
883-
it("should resolve successfull with an empty error", async () => {
884-
const promise = compileSchema({
885-
$schema,
886-
type: "number"
887-
}).validateAsync(4);
888-
const { errors } = await promise;
889-
assert.deepEqual(errors.length, 0);
890-
});
891-
it("should resolve with errors for a failed validation", async () => {
892-
const promise = compileSchema({
893-
$schema,
894-
type: "number"
895-
}).validateAsync("4");
896-
const { errors } = await promise;
897-
assert.deepEqual(errors.length, 1);
898-
assert.deepEqual(errors[0].code, "type-error");
899-
});
900-
describe("async validation", () => {
901-
let draft;
902-
beforeEach(() => {
903-
draft = {
904-
...draft2019,
905-
keywords: [
906-
// @ts-expect-error asd
907-
...draft2019.keywords,
908-
{
909-
id: "async",
910-
keyword: "asyncError",
911-
addValidate: (node) => node.schema.asyncError != null,
912-
// @ts-expect-error asd
913-
validate: ({ node }) => {
914-
if (node.schema.asyncError === false) {
915-
return;
916-
}
917-
return new Promise((resolve) => resolve([
918-
node.createError("type-error", {
919-
schema: {},
920-
pointer: "",
921-
value: ""
922-
})
923-
]));
875+
describe("async validation", () => {
876+
let draft;
877+
beforeEach(() => {
878+
draft = {
879+
...draft2019,
880+
keywords: [
881+
...draft2019.keywords,
882+
{
883+
id: "async",
884+
keyword: "async-error",
885+
addValidate: (node) => node.schema.asyncError != null,
886+
validate: async ({ node }) => {
887+
if (node.schema.asyncError === false) {
888+
return undefined;
924889
}
890+
return node.createError("type-error", {
891+
schema: {},
892+
pointer: "",
893+
value: ""
894+
});
925895
}
926-
]
927-
};
928-
it("should resolve async validation returning no error", async () => {
929-
const { errors } = await compileSchema({ type: "number", asyncError: false }, { drafts: [draft] }).validateAsync(4);
930-
assert.deepEqual(errors.length, 0);
931-
});
932-
it("should resolve async validation errors", async () => {
933-
const { errors } = await compileSchema({ type: "number", asyncError: true }, { drafts: [draft] }).validateAsync(4);
934-
assert.deepEqual(errors.length, 1);
935-
assert.deepEqual(errors[0].code, "type-error");
936-
});
896+
}
897+
]
898+
};
899+
it("should resolve async validation returning no error", async () => {
900+
const { errors, errorsAsync } = compileSchema({ type: "number", asyncError: false }, { drafts: [draft] }).validate(4);
901+
const asyncErrors = await Promise.all(errorsAsync);
902+
assert.deepEqual(errors.length, 0);
903+
assert.deepEqual(asyncErrors.length, 0);
904+
});
905+
it("should resolve async validation errors", async () => {
906+
const { errorsAsync } = compileSchema({ type: "number", asyncError: true }, { drafts: [draft] }).validate(4);
907+
const asyncErrors = await Promise.all(errorsAsync);
908+
assert.deepEqual(asyncErrors.length, 1);
909+
assert.deepEqual(asyncErrors[0].code, "type-error");
937910
});
938911
});
939912
});

dist/module/src/draftEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const draftEditor = extendDraft(draft2019, {
2323
return {
2424
type: "error",
2525
code: "min-length-error",
26-
message: render("Value in `{{pointer}}` is `{{length}}`, but should be `{{minimum}}` at minimum", data),
26+
message: render("Value in `{{pointer}}` is `{{length}}`, but should be `{{minLength}}` at minimum", data),
2727
data
2828
};
2929
}

dist/module/src/keywords/dependencies.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export function reduceDependencies({ node, data, key, path }) {
4747
if (node.dependentRequired) {
4848
Object.keys(node.dependentRequired).forEach((propertyName) => {
4949
if (!hasProperty(data, propertyName) && !required.includes(propertyName)) {
50-
console.log(propertyName, "abort", required);
5150
return;
5251
}
5352
if (node.dependentRequired[propertyName] == null) {

dist/src/Draft.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { Keyword } from "./Keyword";
1+
import type { JsonSchemaValidator, Keyword } from "./Keyword";
22
import { createSchema } from "./methods/createSchema";
33
import { toDataNodes } from "./methods/toDataNodes";
44
import { ErrorConfig } from "./types";
5-
import { formats } from "./formats/formats";
65
import { getChildSelection } from "./methods/getChildSelection";
76
import { getData } from "./methods/getData";
87
export type DraftVersion = "draft-04" | "draft-06" | "draft-07" | "draft-2019-09" | "draft-2020-12" | "latest";
@@ -24,7 +23,7 @@ export interface Draft {
2423
$schema?: string;
2524
/** draft errors (this can still be global) */
2625
errors: ErrorConfig;
27-
formats: typeof formats;
26+
formats: Record<string, JsonSchemaValidator>;
2827
}
2928
type PartialDraft = Partial<Omit<Draft, "errors" | "formats">> & {
3029
errors?: Partial<Draft["errors"]>;

dist/src/Keyword.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type JsonSchemaValidatorParams = {
4040
export interface JsonSchemaValidator {
4141
toJSON?: () => string;
4242
order?: number;
43-
(options: JsonSchemaValidatorParams): undefined | JsonError | ValidationResult[];
43+
(options: JsonSchemaValidatorParams): undefined | ValidationResult | ValidationResult[];
4444
}
4545
export type Keyword = {
4646
id: string;

dist/src/SchemaNode.d.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,8 @@ export declare const SchemaNodeMethods: {
141141
readonly validate: (data: unknown, pointer?: string, path?: ValidationPath) => {
142142
valid: boolean;
143143
errors: JsonError[];
144+
errorsAsync: Promise<JsonError | undefined>[];
144145
};
145-
/**
146-
* @returns a promise which resolves to validation-result
147-
*/
148-
readonly validateAsync: (data: unknown, pointer?: string, path?: ValidationPath) => Promise<{
149-
valid: boolean;
150-
errors: JsonError[];
151-
}>;
152146
/**
153147
* Register a JSON Schema as a remote-schema to be resolved by $ref, $anchor, etc
154148
* @returns the current node (not the remote schema-node)

0 commit comments

Comments
 (0)