Skip to content

Commit 0d13e04

Browse files
committed
Fix types
1 parent ed8d3ee commit 0d13e04

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

bundle/test-suite.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { bundle, URI, UUID } from "./index.js";
2121

2222
import type { BundleOptions } from "./index.js";
2323
import type { OutputUnit } from "../lib/index.js";
24-
import type { AnnotationsContext, ErrorsContext, ValidationContext } from "../lib/experimental.js";
24+
import type { ValidationContext } from "../lib/experimental.js";
2525

2626

2727
const suite = testSuite("./bundle/tests");
@@ -68,10 +68,10 @@ const testRunner = (version: number, dialect: string) => {
6868
const annotationsPlugin = new AnnotationsPlugin();
6969
const detailedOutputPlugin = new DetailedOutputPlugin();
7070
const instance = Instance.fromJs(test.instance);
71-
const context = {
71+
const context: ValidationContext = {
7272
ast,
7373
plugins: [detailedOutputPlugin, annotationsPlugin, ...ast.plugins]
74-
} as ValidationContext & ErrorsContext & AnnotationsContext;
74+
};
7575
const valid = Validation.interpret(schemaUri, instance, context);
7676

7777
const output = {

lib/experimental.d.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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";
33
import type { JsonNode } from "./instance.js";
44

55

@@ -18,7 +18,7 @@ export type CompiledSchema = {
1818

1919
type AST = {
2020
metaData: Record<string, MetaData>;
21-
plugins: Set<EvaluationPlugin<unknown>>;
21+
plugins: Set<EvaluationPlugin>;
2222
} & Record<string, Node<unknown>[] | boolean>;
2323

2424
type Node<A> = [keywordId: string, schemaUri: string, keywordValue: A];
@@ -31,14 +31,6 @@ type MetaData = {
3131

3232
type Anchors = Record<string, string>;
3333

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-
4234
// Output Formats
4335
export const BASIC: "BASIC";
4436
export const DETAILED: "DETAILED";
@@ -85,26 +77,49 @@ export type Keyword<A, Context extends ValidationContext = ValidationContext> =
8577

8678
export type ValidationContext = {
8779
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;
8989
};
9090

9191
export class BasicOutputPlugin implements EvaluationPlugin<ErrorsContext> {
9292
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;
9398
}
9499

95100
export class DetailedOutputPlugin implements EvaluationPlugin<ErrorsContext> {
96101
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;
97107
}
98108

99-
export type ErrorsContext = {
109+
export type ErrorsContext = ValidationContext & {
100110
errors: OutputUnit[];
101111
};
102112

103113
export class AnnotationsPlugin implements EvaluationPlugin<AnnotationsContext> {
104114
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;
105120
}
106121

107-
export type AnnotationsContext = {
122+
export type AnnotationsContext = ValidationContext & {
108123
annotations: OutputUnit[];
109124
};
110125

0 commit comments

Comments
 (0)