1
1
import type { Browser , Document } from "@hyperjump/browser" ;
2
- import type { Validator , OutputUnit , OutputFormat , SchemaObject , EvaluationPlugin } from "./index.js" ;
2
+ import type { Validator , OutputUnit , OutputFormat , SchemaObject } from "./index.js" ;
3
3
import type { JsonNode } from "./instance.js" ;
4
4
5
5
@@ -18,7 +18,7 @@ export type CompiledSchema = {
18
18
19
19
type AST = {
20
20
metaData : Record < string , MetaData > ;
21
- plugins : Set < EvaluationPlugin < unknown > > ;
21
+ plugins : Set < EvaluationPlugin > ;
22
22
} & Record < string , Node < unknown > [ ] | boolean > ;
23
23
24
24
type Node < A > = [ keywordId : string , schemaUri : string , keywordValue : A ] ;
@@ -31,14 +31,6 @@ type MetaData = {
31
31
32
32
type Anchors = Record < string , string > ;
33
33
34
- // Evaluation Plugins
35
- export type EvaluationPlugin < Context extends ValidationOptions = ValidationOptions > = {
36
- beforeSchema ?( url : string , instance : JsonNode , context : Context ) : void ;
37
- beforeKeyword ?( keywordNode : Node < unknown > , instance : JsonNode , context : Context , schemaContext : Context , keyword : Keyword ) : void ;
38
- afterKeyword ?( keywordNode : Node < unknown > , instance : JsonNode , context : Context , valid : boolean , schemaContext : Context , keyword : Keyword ) : void ;
39
- afterSchema ?( url : string , instance : JsonNode , context : Context , valid : boolean ) : void ;
40
- } ;
41
-
42
34
// Output Formats
43
35
export const BASIC : "BASIC" ;
44
36
export const DETAILED : "DETAILED" ;
@@ -85,26 +77,49 @@ export type Keyword<A, Context extends ValidationContext = ValidationContext> =
85
77
86
78
export type ValidationContext = {
87
79
ast : AST ;
88
- plugins : EvaluationPlugin < unknown > [ ] ;
80
+ plugins : EvaluationPlugin [ ] ;
81
+ } ;
82
+
83
+ // Evaluation Plugins
84
+ export type EvaluationPlugin < Context extends ValidationContext = ValidationContext > = {
85
+ beforeSchema ?( url : string , instance : JsonNode , context : Context ) : void ;
86
+ beforeKeyword ?( keywordNode : Node < unknown > , instance : JsonNode , context : Context , schemaContext : Context , keyword : Keyword ) : void ;
87
+ afterKeyword ?( keywordNode : Node < unknown > , instance : JsonNode , context : Context , valid : boolean , schemaContext : Context , keyword : Keyword ) : void ;
88
+ afterSchema ?( url : string , instance : JsonNode , context : Context , valid : boolean ) : void ;
89
89
} ;
90
90
91
91
export class BasicOutputPlugin implements EvaluationPlugin < ErrorsContext > {
92
92
errors : OutputUnit [ ] ;
93
+
94
+ beforeSchema ( url : string , instance : JsonNode , context : ErrorsContext ) : void ;
95
+ beforeKeyword ( keywordNode : Node < unknown > , instance : JsonNode , context : ErrorsContext , schemaContext : ErrorsContext , keyword : Keyword < unknown > ) : void ;
96
+ afterKeyword ( keywordNode : Node < unknown > , instance : JsonNode , context : ErrorsContext , valid : boolean , schemaContext : ErrorsContext , keyword : Keyword < unknown > ) : void ;
97
+ afterSchema ( url : string , instance : JsonNode , context : ErrorsContext , valid : boolean ) : void ;
93
98
}
94
99
95
100
export class DetailedOutputPlugin implements EvaluationPlugin < ErrorsContext > {
96
101
errors : OutputUnit [ ] ;
102
+
103
+ beforeSchema ( url : string , instance : JsonNode , context : ErrorsContext ) : void ;
104
+ beforeKeyword ( keywordNode : Node < unknown > , instance : JsonNode , context : ErrorsContext , schemaContext : ErrorsContext , keyword : Keyword < unknown > ) : void ;
105
+ afterKeyword ( keywordNode : Node < unknown > , instance : JsonNode , context : ErrorsContext , valid : boolean , schemaContext : ErrorsContext , keyword : Keyword < unknown > ) : void ;
106
+ afterSchema ( url : string , instance : JsonNode , context : ErrorsContext , valid : boolean ) : void ;
97
107
}
98
108
99
- export type ErrorsContext = {
109
+ export type ErrorsContext = ValidationContext & {
100
110
errors : OutputUnit [ ] ;
101
111
} ;
102
112
103
113
export class AnnotationsPlugin implements EvaluationPlugin < AnnotationsContext > {
104
114
annotations : OutputUnit [ ] ;
115
+
116
+ beforeSchema ( url : string , instance : JsonNode , context : AnnotationsContext ) : void ;
117
+ beforeKeyword ( keywordNode : Node < unknown > , instance : JsonNode , context : AnnotationsContext , schemaContext : AnnotationsContext , keyword : Keyword < unknown > ) : void ;
118
+ afterKeyword ( keywordNode : Node < unknown > , instance : JsonNode , context : AnnotationsContext , valid : boolean , schemaContext : AnnotationsContext , keyword : Keyword < unknown > ) : void ;
119
+ afterSchema ( url : string , instance : JsonNode , context : AnnotationsContext , valid : boolean ) : void ;
105
120
}
106
121
107
- export type AnnotationsContext = {
122
+ export type AnnotationsContext = ValidationContext & {
108
123
annotations : OutputUnit [ ] ;
109
124
} ;
110
125
0 commit comments