11import { randomUUID } from "node:crypto" ;
22import { existsSync } from "node:fs" ;
3- import { readFile , writeFile } from "node:fs/promises" ;
4- import { extname , join } from "node:path" ;
5- import { pathToFileURL } from "node:url" ;
6- import { registerSchema as register , unregisterSchema as unregister , validate } from "./json-schema.js" ;
7- import { getKeywordId , getKeywordName , BASIC } from "@hyperjump/json-schema/experimental" ;
8- import YAML from "yaml" ;
3+ import { writeFile } from "node:fs/promises" ;
4+ import { join } from "node:path" ;
5+ import { registerSchema , unregisterSchema , validate } from "./json-schema.js" ;
6+ import { BASIC } from "@hyperjump/json-schema/experimental" ;
97import { FileCoverageMapService } from "./file-coverage-map-service.js" ;
108import { TestCoverageEvaluationPlugin } from "../test-coverage-evaluation-plugin.js" ;
11- import { toAbsoluteIri } from "@hyperjump/uri" ;
129
1310/**
14- * @import { OutputUnit, SchemaObject } from "@hyperjump/json-schema"
11+ * @import { OutputUnit } from "@hyperjump/json-schema"
1512 * @import * as API from "./index.d.ts"
1613 */
1714
@@ -51,12 +48,12 @@ export const matchJsonSchema = async (instance, uriOrSchema) => {
5148 } else {
5249 const schema = uriOrSchema ;
5350 const uri = `urn:uuid:${ randomUUID ( ) } ` ;
54- register ( schema , uri , "https://json-schema.org/draft/2020-12/schema" ) ;
51+ registerSchema ( schema , uri , "https://json-schema.org/draft/2020-12/schema" ) ;
5552 try {
5653 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
5754 output = await validate ( uri , instance , BASIC ) ;
5855 } finally {
59- unregister ( uri ) ;
56+ unregisterSchema ( uri ) ;
6057 }
6158 }
6259
@@ -67,56 +64,3 @@ export const matchJsonSchema = async (instance, uriOrSchema) => {
6764} ;
6865
6966export const toMatchJsonSchema = matchJsonSchema ;
70-
71- /** @type API.registerSchema */
72- export const registerSchema = async ( schemaPath ) => {
73- const text = await readFile ( schemaPath , "utf-8" ) ;
74- const extension = extname ( schemaPath ) ;
75-
76- /** @type SchemaObject */
77- let schema ;
78- switch ( extension ) {
79- case ".json" :
80- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
81- schema = JSON . parse ( text ) ;
82- break ;
83- case ".yaml" :
84- case ".yml" :
85- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
86- schema = YAML . parse ( text ) ;
87- break ;
88- default :
89- throw Error ( `File of type '${ extension } ' is not supported.` ) ;
90- }
91-
92- register ( schema ) ;
93- } ;
94-
95- /** @type (schemaPath: string) => Promise<void> */
96- export const unregisterSchema = async ( schemaPath ) => {
97- const text = await readFile ( schemaPath , "utf-8" ) ;
98- const extension = extname ( schemaPath ) ;
99-
100- /** @type SchemaObject */
101- let schema ;
102- switch ( extension ) {
103- case ".json" :
104- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
105- schema = JSON . parse ( text ) ;
106- break ;
107- case ".yaml" :
108- case ".yml" :
109- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
110- schema = YAML . parse ( text ) ;
111- break ;
112- default :
113- throw Error ( `File of type '${ extension } ' is not supported.` ) ;
114- }
115-
116- const dialectUri = toAbsoluteIri ( /** @type string */ ( schema . $schema ) ) ;
117- const idToken = getKeywordName ( dialectUri , "https://json-schema.org/keyword/id" )
118- ?? getKeywordId ( "https://json-schema.org/keyword/draft-04/id" , dialectUri ) ;
119- const schemaUri = /** @type string */ ( schema [ idToken ] ) ?? pathToFileURL ( schemaPath ) . toString ( ) ;
120-
121- unregister ( schemaUri ) ;
122- } ;
0 commit comments