source: trip-planner-front/node_modules/ajv/lib/compile/rules.ts@ eed0bf8

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

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import type {AddedKeywordDefinition} from "../types"
2
3const _jsonTypes = ["string", "number", "integer", "boolean", "null", "object", "array"] as const
4
5export type JSONType = typeof _jsonTypes[number]
6
7const jsonTypes: Set<string> = new Set(_jsonTypes)
8
9export function isJSONType(x: unknown): x is JSONType {
10 return typeof x == "string" && jsonTypes.has(x)
11}
12
13type ValidationTypes = {
14 [K in JSONType]: boolean | RuleGroup | undefined
15}
16
17export interface ValidationRules {
18 rules: RuleGroup[]
19 post: RuleGroup
20 all: {[Key in string]?: boolean | Rule} // rules that have to be validated
21 keywords: {[Key in string]?: boolean} // all known keywords (superset of "all")
22 types: ValidationTypes
23}
24
25export interface RuleGroup {
26 type?: JSONType
27 rules: Rule[]
28}
29
30// This interface wraps KeywordDefinition because definition can have multiple keywords
31export interface Rule {
32 keyword: string
33 definition: AddedKeywordDefinition
34}
35
36export function getRules(): ValidationRules {
37 const groups: Record<"number" | "string" | "array" | "object", RuleGroup> = {
38 number: {type: "number", rules: []},
39 string: {type: "string", rules: []},
40 array: {type: "array", rules: []},
41 object: {type: "object", rules: []},
42 }
43 return {
44 types: {...groups, integer: true, boolean: true, null: true},
45 rules: [{rules: []}, groups.number, groups.string, groups.array, groups.object],
46 post: {rules: []},
47 all: {},
48 keywords: {},
49 }
50}
Note: See TracBrowser for help on using the repository browser.