Skip to content

Commit e6f25e8

Browse files
committed
Fix the Output type
1 parent f480861 commit e6f25e8

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

annotations/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OutputFormat, OutputUnit, ValidationOptions } from "../lib/index.js";
1+
import type { OutputFormat, Output, ValidationOptions } from "../lib/index.js";
22
import type { CompiledSchema } from "../lib/experimental.js";
33
import type { JsonNode } from "../lib/json-node.js";
44
import type { Json } from "@hyperjump/json-pointer";
@@ -15,7 +15,7 @@ export type Annotator = (value: Json, options?: OutputFormat | ValidationOptions
1515
export const interpret: (compiledSchema: CompiledSchema, value: JsonNode, options?: OutputFormat | ValidationOptions) => JsonNode;
1616

1717
export class ValidationError extends Error {
18-
public output: OutputUnit;
18+
public output: Output;
1919

20-
public constructor(output: OutputUnit);
20+
public constructor(output: Output);
2121
}

bundle/test-suite.spec.ts

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

2222
import type { BundleOptions } from "./index.js";
23-
import type { OutputUnit } from "../lib/index.js";
23+
import type { Output } from "../lib/index.js";
2424
import type { ValidationContext } from "../lib/experimental.js";
2525

2626

@@ -82,7 +82,7 @@ const testRunner = (version: number, dialect: string) => {
8282

8383
const testId = md5(`${version}|${dialect}|${testCase.description}|${testIndex}`);
8484
const expectedOutputJson = await readFile(`./bundle/snapshots/${testId}`, "utf-8");
85-
const expectedOutput = JSON.parse(expectedOutputJson) as OutputUnit;
85+
const expectedOutput = JSON.parse(expectedOutputJson) as Output;
8686
expect(output).to.eql(expectedOutput);
8787
});
8888
});

lib/experimental.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { Browser, Document } from "@hyperjump/browser";
2-
import type { Validator, OutputUnit, OutputFormat, SchemaObject } from "./index.js";
2+
import type { Validator, Output, OutputUnit, OutputFormat, SchemaObject } from "./index.js";
33
import type { JsonNode } from "./instance.js";
44

55

66
// Compile/interpret
77
export const compile: (schema: Browser<SchemaDocument>) => Promise<CompiledSchema>;
88
export const interpret: (
9-
(compiledSchema: CompiledSchema, value: JsonNode, outputFormat?: OutputFormat) => OutputUnit
9+
(compiledSchema: CompiledSchema, value: JsonNode, outputFormat?: OutputFormat) => Output
1010
) & (
1111
(compiledSchema: CompiledSchema) => Validator
1212
);

lib/index.d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ export type ValidationOptions = {
2323
};
2424

2525
export const validate: (
26-
(url: string, value: Json, options?: OutputFormat | ValidationOptions) => Promise<OutputUnit>
26+
(url: string, value: Json, options?: OutputFormat | ValidationOptions) => Promise<Output>
2727
) & (
2828
(url: string) => Promise<Validator>
2929
);
3030

31-
export type Validator = (value: Json, options?: OutputFormat | ValidationOptions) => OutputUnit;
31+
export type Validator = (value: Json, options?: OutputFormat | ValidationOptions) => Output;
32+
33+
export type Output = {
34+
valid: true;
35+
} | {
36+
valid: false;
37+
errors?: OutputUnit[];
38+
};
3239

3340
export type OutputUnit = {
3441
keyword: string;
@@ -49,7 +56,7 @@ export const setShouldValidateSchema: (isEnabled: boolean) => void;
4956
export const getShouldValidateSchema: () => boolean;
5057

5158
export class InvalidSchemaError extends Error {
52-
public output: OutputUnit;
59+
public output: Output;
5360

54-
public constructor(output: OutputUnit);
61+
public constructor(output: Output);
5562
}

0 commit comments

Comments
 (0)