11import { randomUUID } from "node:crypto" ;
22import { existsSync } from "node:fs" ;
3- import { writeFile } from "node:fs/promises" ;
4- import { registerSchema , unregisterSchema , validate } from "@hyperjump/json-schema/draft-2020-12" ;
3+ import { readFile , writeFile } from "node:fs/promises" ;
4+ import {
5+ registerSchema as register ,
6+ unregisterSchema ,
7+ validate
8+ } from "@hyperjump/json-schema/draft-2020-12" ;
59import "@hyperjump/json-schema/draft-2019-09" ;
610import "@hyperjump/json-schema/draft-07" ;
711import "@hyperjump/json-schema/draft-06" ;
@@ -13,10 +17,10 @@ import { TestCoverageEvaluationPlugin } from "../test-coverage-evaluation-plugin
1317
1418/**
1519 * @import { OutputUnit, SchemaObject } from "@hyperjump/json-schema"
16- * @import { AsyncExpectationResult } from "@vitest/expect "
20+ * @import * as API from "./json-schema-matcher.d.ts "
1721 */
1822
19- /** @type (instance: any, uriOrSchema: string | SchemaObject | boolean) => AsyncExpectationResult */
23+ /** @type API.matchJsonSchema */
2024export const matchJsonSchema = async ( instance , uriOrSchema ) => {
2125 /** @type OutputUnit */
2226 let output ;
@@ -43,7 +47,7 @@ export const matchJsonSchema = async (instance, uriOrSchema) => {
4347 } else {
4448 const schema = uriOrSchema ;
4549 const uri = `urn:uuid:${ randomUUID ( ) } ` ;
46- registerSchema ( schema , uri , "https://json-schema.org/draft/2020-12/schema" ) ;
50+ register ( schema , uri , "https://json-schema.org/draft/2020-12/schema" ) ;
4751 try {
4852 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
4953 output = await validate ( uri , instance , BASIC ) ;
@@ -59,5 +63,15 @@ export const matchJsonSchema = async (instance, uriOrSchema) => {
5963} ;
6064
6165export const toMatchJsonSchema = matchJsonSchema ;
62- export { registerSchema , unregisterSchema } from "@hyperjump/json-schema/draft-2020-12" ;
66+
67+ /** @type API.registerSchema */
68+ export const registerSchema = async ( filePath ) => {
69+ const json = await readFile ( filePath , "utf-8" ) ;
70+ /** @type SchemaObject */
71+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
72+ const schema = JSON . parse ( json ) ;
73+ register ( schema ) ;
74+ } ;
75+
76+ export { unregisterSchema } from "@hyperjump/json-schema/draft-2020-12" ;
6377export { loadDialect , defineVocabulary , addKeyword } from "@hyperjump/json-schema/experimental" ;
0 commit comments