@sourcemeta/blaze 15.6.3 → 15.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/describe.mjs +36 -3
- package/package.json +1 -1
package/describe.mjs
CHANGED
|
@@ -83,6 +83,37 @@ function escapeString(input) {
|
|
|
83
83
|
return '"' + String(input).replaceAll('"', '\\"') + '"';
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
function describeExtras(valid, target, allowed) {
|
|
87
|
+
if (valid || target === null || typeof target !== 'object' ||
|
|
88
|
+
Array.isArray(target)) {
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const extras = [];
|
|
93
|
+
for (const key in target) {
|
|
94
|
+
if (!allowed.has(key)) {
|
|
95
|
+
extras.push(key);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (extras.length === 0) return '';
|
|
100
|
+
extras.sort();
|
|
101
|
+
|
|
102
|
+
if (extras.length === 1) {
|
|
103
|
+
return ', but it also defines the property ' + escapeString(extras[0]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let message = ', but it also defines properties ';
|
|
107
|
+
for (let index = 0; index < extras.length; index++) {
|
|
108
|
+
if (index === extras.length - 1) {
|
|
109
|
+
message += 'and ' + escapeString(extras[index]);
|
|
110
|
+
} else {
|
|
111
|
+
message += escapeString(extras[index]) + ', ';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return message;
|
|
115
|
+
}
|
|
116
|
+
|
|
86
117
|
function stringifyValue(value) {
|
|
87
118
|
if (typeof value === 'bigint') return String(value);
|
|
88
119
|
return JSON.stringify(value, (key, current) =>
|
|
@@ -944,7 +975,7 @@ export function describe(valid, instruction, evaluatePath,
|
|
|
944
975
|
message += escapeString(sorted[index]) + ', ';
|
|
945
976
|
}
|
|
946
977
|
}
|
|
947
|
-
return message;
|
|
978
|
+
return message + describeExtras(valid, target, new Set(value));
|
|
948
979
|
}
|
|
949
980
|
|
|
950
981
|
if (opcode === ASSERTION_DEFINES_EXACTLY_STRICT) {
|
|
@@ -958,13 +989,15 @@ export function describe(valid, instruction, evaluatePath,
|
|
|
958
989
|
message += escapeString(sorted[index]) + ', ';
|
|
959
990
|
}
|
|
960
991
|
}
|
|
961
|
-
return message;
|
|
992
|
+
return message + describeExtras(valid, target, new Set(value));
|
|
962
993
|
}
|
|
963
994
|
|
|
964
995
|
if (opcode === ASSERTION_DEFINES_EXACTLY_STRICT_HASH3) {
|
|
965
996
|
const entries = value[0];
|
|
966
|
-
|
|
997
|
+
const message = 'The value was expected to be an object that only defines the ' +
|
|
967
998
|
entries.length + ' given properties';
|
|
999
|
+
return message + describeExtras(valid, target,
|
|
1000
|
+
new Set(entries.map(entry => entry[1])));
|
|
968
1001
|
}
|
|
969
1002
|
|
|
970
1003
|
if (opcode === ASSERTION_TYPE || opcode === ASSERTION_TYPE_STRICT) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sourcemeta/blaze",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.7.0",
|
|
4
4
|
"description": "A pure JavaScript port of the evaluator from Blaze, a high-performance C++ JSON Schema validator. Zero dependencies. Supports Draft 4, Draft 6, Draft 7, 2019-09, and 2020-12 with schema-specific code generation for near-native speed",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|