Skip to content

Commit

Permalink
refactor: remove doT
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Aug 25, 2020
1 parent f3f353a commit 188eadf
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 759 deletions.
2 changes: 0 additions & 2 deletions .codeclimate.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ node_modules

.DS_Store

# Compiled templates
lib/dotjs/*.js

# Browserified tests
.browser

Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ spec/JSON-Schema-Test-Suite
coverage
dist
.nyc_output
lib/dotjs
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,9 @@ npm run test-fast
git commit -nm 'type: message'
```

All validation functions are generated using doT templates in [dot](https://github.com/ajv-validator/ajv/tree/master/lib/dot) folder. Templates are precompiled so doT is not a run-time dependency.
`npm run build` - compiles typescript to dist folder.

`npm run build` - compiles templates to [dotjs](https://github.com/ajv-validator/ajv/tree/master/lib/dotjs) folder.

`npm run watch` - automatically compiles templates when files in dot folder change
`npm run watch` - automatically compiles typescript when files in lib folder change

#### Pull requests

Expand Down
8 changes: 4 additions & 4 deletions CUSTOM.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ Example. `constant` keyword (a synonym for draft-06 keyword `const`, it is equiv
```javascript
ajv.addKeyword("constant", {
validate: function (schema, data) {
return typeof schema == "object" && schema !== null
? deepEqual(schema, data)
: schema === data
return typeof schema == "object" && schema !== null ? deepEqual(schema, data) : schema === data
},
errors: false,
})
Expand Down Expand Up @@ -388,7 +386,9 @@ All custom keywords but macro keywords can optionally create custom error messag

Synchronous validating and compiled keywords should define errors by assigning them to `.errors` property of the validation function. Asynchronous keywords can return promise that rejects with `new Ajv.ValidationError(errors)`, where `errors` is an array of custom validation errors (if you don't want to define custom errors in asynchronous keyword, its validation function can return the promise that resolves with `false`).

Inline custom keyword should increase error counter `errors` and add error to `vErrors` array (it can be null). This can be done for both synchronous and asynchronous keywords. See [example range keyword](https://github.com/ajv-validator/ajv/blob/master/spec/custom_rules/range_with_errors.jst).
TODO replace "inline" keywords with "code" keywords

Inline custom keyword should increase error counter `errors` and add error to `vErrors` array (it can be null). This can be done for both synchronous and asynchronous keywords.

When inline keyword performs validation Ajv checks whether it created errors by comparing errors count before and after validation. To skip this check add option `errors` (can be `"full"`, `true` or `false`) to keyword definition:

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-06.json"))

## Performance

Ajv generates code using [doT templates](https://github.com/olado/doT) to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization.
Ajv generates code to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization.

Currently Ajv is the fastest and the most standard compliant validator according to these benchmarks:

Expand Down Expand Up @@ -1370,11 +1370,9 @@ npm test

## Contributing

All validation functions are generated using doT templates in [dot](https://github.com/ajv-validator/ajv/tree/master/lib/dot) folder. Templates are precompiled so doT is not a run-time dependency.
`npm run build` - compiles typescript to dist folder.

`npm run build` - compiles templates to [dotjs](https://github.com/ajv-validator/ajv/tree/master/lib/dotjs) folder.

`npm run watch` - automatically compiles templates when files in dot folder change
`npm run watch` - automatically compiles typescript when files in lib folder change

Please see [Contributing guidelines](https://github.com/ajv-validator/ajv/blob/master/CONTRIBUTING.md)

Expand Down
2 changes: 1 addition & 1 deletion lib/compile/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface RuleGroup {

export interface Rule {
keyword: string
code: (it: CompilationContext, keyword?: string, ruleType?: string) => void
code: (it: CompilationContext, keyword: string, ruleType?: string) => void
implements?: string[]
definition?: KeywordDefinition
custom?: true
Expand Down
8 changes: 1 addition & 7 deletions lib/compile/validate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function validateCode(
if ($comment && schema.$comment) commentKeyword(it)

if (isTop) {
updateTopContext(it)
delete it.isTop
checkNoDefault(it)
initializeTop(it)
typeAndKeywords()
Expand Down Expand Up @@ -136,12 +136,6 @@ function startFunction({
)
}

function updateTopContext(it: CompilationContext): void {
// it.rootId = resolve.fullPath(it.root.schema.$id)
// it.baseId = it.baseId || it.rootId
delete it.isTop
}

function checkNoDefault({
schema,
opts: {useDefaults, strictDefaults},
Expand Down
2 changes: 1 addition & 1 deletion lib/compile/validate/iterate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function schemaKeywords(
it: CompilationContext,
types: string[],
typeErrors: boolean,
top: boolean
top?: boolean
): void {
const {
gen,
Expand Down
2 changes: 1 addition & 1 deletion lib/compile/validate/keyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "../../types"
import {applySubschema} from "../subschema"
import {reportError, reportExtraError, extendErrors} from "../errors"
import {getParentData, dataNotType} from "../../vocabularies/util"
import {getParentData} from "../../vocabularies/util"

export const keywordError: KeywordErrorDefinition = {
message: ({keyword}) => `'should pass "${keyword}" keyword validation'`,
Expand Down
213 changes: 0 additions & 213 deletions lib/dot/custom.jst

This file was deleted.

Loading

0 comments on commit 188eadf

Please sign in to comment.