source: trip-planner-front/node_modules/ajv/lib/compile/validate/boolSchema.ts@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import type {KeywordErrorDefinition, KeywordErrorCxt} from "../../types"
2import type {SchemaCxt} from ".."
3import {reportError} from "../errors"
4import {_, Name} from "../codegen"
5import N from "../names"
6
7const boolError: KeywordErrorDefinition = {
8 message: "boolean schema is false",
9}
10
11export function topBoolOrEmptySchema(it: SchemaCxt): void {
12 const {gen, schema, validateName} = it
13 if (schema === false) {
14 falseSchemaError(it, false)
15 } else if (typeof schema == "object" && schema.$async === true) {
16 gen.return(N.data)
17 } else {
18 gen.assign(_`${validateName}.errors`, null)
19 gen.return(true)
20 }
21}
22
23export function boolOrEmptySchema(it: SchemaCxt, valid: Name): void {
24 const {gen, schema} = it
25 if (schema === false) {
26 gen.var(valid, false) // TODO var
27 falseSchemaError(it)
28 } else {
29 gen.var(valid, true) // TODO var
30 }
31}
32
33function falseSchemaError(it: SchemaCxt, overrideAllErrors?: boolean): void {
34 const {gen, data} = it
35 // TODO maybe some other interface should be used for non-keyword validation errors...
36 const cxt: KeywordErrorCxt = {
37 gen,
38 keyword: "false schema",
39 data,
40 schema: false,
41 schemaCode: false,
42 schemaValue: false,
43 params: {},
44 it,
45 }
46 reportError(cxt, boolError, undefined, overrideAllErrors)
47}
Note: See TracBrowser for help on using the repository browser.