1- import { getSchema } from "@hyperjump/json-schema/experimental" ;
2- import * as Schema from "@hyperjump/browser" ;
31import * as Instance from "@hyperjump/json-schema/instance/experimental" ;
42
53/**
64 * @import { ErrorHandler } from "../index.d.ts"
75 */
86
97/** @type ErrorHandler */
10- const maximumErrorHandler = async ( normalizedErrors , instance , localization ) => {
8+ const maximumErrorHandler = ( normalizedErrors , instance , localization , resolver ) => {
9+ /** @type {{
10+ * getCompiledKeywordValue?: (schemaLocation: string) => unknown;
11+ * getSiblingKeywordValue?: (schemaLocation: string, siblingKeywordUri: string) =>
12+ * { keywordLocation: string; keywordValue: unknown } | undefined
13+ * } | undefined } */
14+ if ( ! resolver ?. getCompiledKeywordValue || ! resolver . getSiblingKeywordValue ) {
15+ throw new Error ( "Missing resolver functions in error handler context" ) ;
16+ }
17+
1118 let lowestMaximum = Infinity ;
1219 let isExclusive = false ;
1320
@@ -19,8 +26,7 @@ const maximumErrorHandler = async (normalizedErrors, instance, localization) =>
1926 continue ;
2027 }
2128
22- const keyword = await getSchema ( schemaLocation ) ;
23- const maximum = /** @type number */ ( Schema . value ( keyword ) ) ;
29+ const maximum = /** @type number */ ( resolver . getCompiledKeywordValue ( schemaLocation ) ) ;
2430 if ( maximum < lowestMaximum ) {
2531 lowestMaximum = maximum ;
2632 schemaLocations = [ schemaLocation ] ;
@@ -32,8 +38,7 @@ const maximumErrorHandler = async (normalizedErrors, instance, localization) =>
3238 continue ;
3339 }
3440
35- const keyword = await getSchema ( schemaLocation ) ;
36- const exclusiveMaximum = /** @type number */ ( Schema . value ( keyword ) ) ;
41+ const exclusiveMaximum = /** @type number */ ( resolver . getCompiledKeywordValue ( schemaLocation ) ) ;
3742 if ( exclusiveMaximum < lowestMaximum ) {
3843 lowestMaximum = exclusiveMaximum ;
3944 isExclusive = true ;
@@ -46,26 +51,15 @@ const maximumErrorHandler = async (normalizedErrors, instance, localization) =>
4651 continue ;
4752 }
4853
49- const parentLocation = pointerPop ( schemaLocation ) ;
50- /** @type string */
51- let exclusiveLocation = "" ;
52- for ( const schemaLocation in normalizedErrors [ "https://json-schema.org/keyword/draft-04/exclusiveMaximum" ] ) {
53- const exclusiveParentLocation = pointerPop ( schemaLocation ) ;
54- if ( exclusiveParentLocation === parentLocation ) {
55- const exclusiveNode = await getSchema ( schemaLocation ) ;
56- if ( Schema . value ( exclusiveNode ) ) {
57- exclusiveLocation = schemaLocation ;
58- }
59- break ;
60- }
61- }
62-
63- const keywordNode = await getSchema ( schemaLocation ) ;
64- const maximum = /** @type number */ ( Schema . value ( keywordNode ) ) ;
54+ const draft04Maximum = /** @type [number, boolean] */ ( resolver . getCompiledKeywordValue ( schemaLocation ) ) ;
55+ const maximum = draft04Maximum [ 0 ] ;
56+ const exclusive = draft04Maximum [ 1 ] ;
57+ const exclusiveKeyword = resolver . getSiblingKeywordValue ( schemaLocation , "https://json-schema.org/keyword/draft-04/exclusiveMaximum" ) ;
58+ const exclusiveLocation = exclusive && exclusiveKeyword ? exclusiveKeyword . keywordLocation : "" ;
6559
6660 if ( maximum < lowestMaximum ) {
6761 lowestMaximum = maximum ;
68- isExclusive = ! ! exclusiveLocation ;
62+ isExclusive = exclusive ;
6963 schemaLocations = exclusiveLocation ? [ schemaLocation , exclusiveLocation ] : [ schemaLocation ] ;
7064 }
7165 }
@@ -87,7 +81,4 @@ const maximumErrorHandler = async (normalizedErrors, instance, localization) =>
8781 }
8882} ;
8983
90- /** @type (pointer: string) => string */
91- const pointerPop = ( pointer ) => pointer . replace ( / \/ [ ^ / ] + $ / , "" ) ;
92-
9384export default maximumErrorHandler ;
0 commit comments