-
-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43df463
commit db7574d
Showing
19 changed files
with
240 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
interface ContextConstructorArgument { | ||
ajv: any | ||
schema: any | ||
isRoot: boolean | ||
baseId: string | ||
} | ||
|
||
export default class SchemaCompilationContext { | ||
isTop?: boolean = true | ||
async: boolean | ||
schema: any | ||
isRoot: boolean | ||
baseId: string | ||
|
||
// TODO ajv type | ||
constructor({ajv, schema, isRoot, baseId}: ContextConstructorArgument) { | ||
this.async = schema.$async === true | ||
this.schema = schema | ||
this.isRoot = isRoot | ||
this.baseId = baseId | ||
} | ||
} | ||
|
||
|
||
// root: _root, | ||
// schemaPath: "", | ||
// errSchemaPath: "#", | ||
// errorPath: '""', | ||
// dataPathArr: [""], | ||
// level: 0, | ||
// dataLevel: 0, | ||
// data: "data", // TODO get unique name when passed from applicator keywords | ||
// gen: new CodeGen(), | ||
// MissingRefError, | ||
// RULES: RULES, | ||
// validate: validateCode, | ||
// util: util, | ||
// resolve: resolve, | ||
// resolveRef: resolveRef, | ||
// usePattern: usePattern, | ||
// useDefault: useDefault, | ||
// useCustomRule: useCustomRule, | ||
// opts: opts, | ||
// formats: formats, | ||
// logger: self.logger, | ||
// self: self, | ||
|
||
|
||
// level: number | ||
// dataLevel: number | ||
// data: string | ||
// dataPathArr: string[] | ||
// schemaPath: string | ||
// errorPath: string | ||
// errSchemaPath: string | ||
// gen: CodeGen | ||
// createErrors?: boolean // TODO maybe remove later | ||
// opts: Options | ||
// formats: { | ||
// [index: string]: Format | undefined | ||
// } | ||
// // keywords: { | ||
// // [index: string]: KeywordDefinition | undefined | ||
// // } | ||
// compositeRule?: boolean | ||
// validate: (it: CompilationContext) => string | ||
// usePattern: (str: string) => string | ||
// useDefault: (value: any) => string | ||
// useCustomRule: (rule: Rule, schema: any, parentSchema: object, it: CompilationContext) => any | ||
// util: object // TODO | ||
// self: object // TODO | ||
// RULES: ValidationRules | ||
// logger: Logger // TODO ? | ||
// isTop: boolean // TODO ? | ||
// root: SchemaRoot // TODO ? | ||
// rootId?: string // TODO ? | ||
// MissingRefError: typeof MissingRefError | ||
// resolve: any | ||
// resolveRef: (...args: any[]) => any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {CompilationContext} from "../types" | ||
import validateCode from "./validate" | ||
import {getProperty, escapeFragment} from "./util" | ||
|
||
export interface Subschema { | ||
schema: any | ||
schemaPath: string | ||
errSchemaPath: string | ||
} | ||
|
||
export function applySchema(it: CompilationContext, subschema: Subschema): string { | ||
const {gen, level} = it | ||
const nextIt = {...it, ...subschema, level: level + 1} | ||
const nextValid = gen.name("valid") | ||
// TODO remove true once appendGen is removed | ||
validateCode(nextIt, nextValid, true) | ||
return nextValid | ||
} | ||
|
||
export function applyKeywordSubschema( | ||
it: CompilationContext, | ||
keyword: string, | ||
prop: string | number | ||
): string { | ||
return applySchema(it, { | ||
schema: it.schema[keyword][prop], | ||
schemaPath: it.schemaPath + getProperty(keyword) + getProperty(prop), | ||
errSchemaPath: `${it.errSchemaPath}/${keyword}/${escapeFragment("" + prop)}`, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.