-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
16 changed files
with
465 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,19 @@ | ||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateConst(value, currentSchema, position) { | ||
if (value === currentSchema) { | ||
return true; | ||
} | ||
|
||
this.error( | ||
`Value "${value}" not accepted. Expected value: ${currentSchema}`, | ||
"const", | ||
position, | ||
); | ||
} | ||
|
||
module.exports = validateConst; |
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,36 @@ | ||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateIfThenElse(value, currentSchema, position) { | ||
let errorDepth = position.length + 1; | ||
let possibleError; | ||
|
||
try { | ||
// Run full validation | ||
this.validateSchema.call( | ||
{...this, catch: true}, | ||
value, | ||
position, | ||
currentSchema, | ||
); | ||
|
||
return; | ||
} catch (e) { | ||
if (e.position && e.position.length > errorDepth) { | ||
possibleError = "if"; | ||
errorDepth = e.position.length; | ||
} | ||
} | ||
|
||
// Guessing the error based on error depth | ||
if (possibleError) { | ||
return possibleError; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
module.exports = validateIfThenElse; |
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,25 @@ | ||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateNot(value, currentSchema, position) { | ||
try { | ||
// Run full validation | ||
this.validateSchema.call( | ||
{...this, catch: true}, | ||
value, | ||
position, | ||
currentSchema, | ||
); | ||
|
||
this.error("Value not accepted", "not", position); | ||
|
||
return; | ||
} catch (e) { | ||
return true; | ||
} | ||
} | ||
|
||
module.exports = validateNot; |
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.