1- import { compile , getSchema } from "@hyperjump/json-schema/experimental" ;
1+ import { compile , getKeyword , getSchema } from "@hyperjump/json-schema/experimental" ;
22import * as Instance from "@hyperjump/json-schema/instance/experimental" ;
33import { pointerSegments } from "@hyperjump/json-pointer" ;
44import * as Browser from "@hyperjump/browser" ;
@@ -22,9 +22,14 @@ export const setNormalizationHandler = (uri, handler) => {
2222export const evaluateSchema = ( schemaLocation , instance , context ) => {
2323 const instanceLocation = Instance . uri ( instance ) ;
2424
25+ let valid = true ;
2526 /** @type API.NormalizedOutput */
2627 const output = { [ instanceLocation ] : { } } ;
2728
29+ for ( const plugin of context . plugins ) {
30+ plugin . beforeSchema ?. ( schemaLocation , instance , context ) ;
31+ }
32+
2833 const schemaNode = context . ast [ schemaLocation ] ;
2934 if ( typeof schemaNode === "boolean" ) {
3035 output [ instanceLocation ] = {
@@ -37,13 +42,22 @@ export const evaluateSchema = (schemaLocation, instance, context) => {
3742 const [ keywordUri , keywordLocation , keywordValue ] = node ;
3843 const keyword = keywordHandlers [ keywordUri ] ?? { } ;
3944
45+ const validationKeyword = getKeyword ( keywordUri ) ;
46+
4047 const keywordContext = {
4148 ast : context . ast ,
42- errorIndex : context . errorIndex
49+ errorIndex : context . errorIndex ,
50+ plugins : context . plugins
4351 } ;
52+ for ( const plugin of context . plugins ) {
53+ plugin . beforeKeyword ?. ( node , instance , keywordContext , context , validationKeyword ) ;
54+ }
4455
4556 const keywordOutput = keyword . evaluate ?. ( keywordValue , instance , keywordContext ) ;
4657 const isKeywordValid = ! context . errorIndex [ keywordLocation ] ?. [ instanceLocation ] ;
58+ if ( ! isKeywordValid ) {
59+ valid = false ;
60+ }
4761
4862 if ( keyword . simpleApplicator ) {
4963 for ( const suboutput of ( keywordOutput ?? [ ] ) ) {
@@ -56,9 +70,17 @@ export const evaluateSchema = (schemaLocation, instance, context) => {
5670 output [ instanceLocation ] [ keywordUri ] ??= { } ;
5771 output [ instanceLocation ] [ keywordUri ] [ keywordLocation ] = isKeywordValid ;
5872 }
73+
74+ for ( const plugin of context . plugins ) {
75+ plugin . afterKeyword ?. ( node , instance , keywordContext , isKeywordValid , context , validationKeyword ) ;
76+ }
5977 }
6078 }
6179
80+ for ( const plugin of context . plugins ) {
81+ plugin . afterSchema ?. ( schemaLocation , instance , context , valid ) ;
82+ }
83+
6284 return output ;
6385} ;
6486
@@ -122,6 +144,6 @@ export async function normalizedErrorOuput(instance, errorOutput, subjectUri) {
122144 const { schemaUri, ast } = await compile ( schema ) ;
123145 const value = Instance . fromJs ( instance ) ;
124146 /** @type API.EvaluationContext */
125- const context = { ast, errorIndex } ;
147+ const context = { ast, errorIndex, plugins : [ ] } ;
126148 return evaluateSchema ( schemaUri , value , context ) ;
127149}
0 commit comments