@sourcemeta/blaze 0.0.1 → 0.0.2
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/README.md +4 -0
- package/index.mjs +13 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# @sourcemeta/blaze
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@sourcemeta/blaze)
|
|
4
|
+
[](https://www.npmjs.com/package/@sourcemeta/blaze)
|
|
5
|
+
[](https://github.com/sourcemeta/blaze/graphs/contributors/)
|
|
6
|
+
|
|
3
7
|
A pure JavaScript port of the evaluator from
|
|
4
8
|
[Blaze](https://github.com/sourcemeta/blaze), a high-performance
|
|
5
9
|
C++ JSON Schema validator. Zero dependencies. Supports Draft 4,
|
package/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const JSON_VERSION = 1;
|
|
1
2
|
const DEPTH_LIMIT = 300;
|
|
2
3
|
const ANNOTATION_EMIT = 44;
|
|
3
4
|
const ANNOTATION_TO_PARENT = 45;
|
|
@@ -194,7 +195,7 @@ function collectAnchorNamesFromInstructions(instructions, result) {
|
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
function compile(template) {
|
|
197
|
-
const targets = template[
|
|
198
|
+
const targets = template[3];
|
|
198
199
|
for (let targetIndex = 0; targetIndex < targets.length; targetIndex++) {
|
|
199
200
|
const target = targets[targetIndex];
|
|
200
201
|
for (let index = 0; index < target.length; index++) {
|
|
@@ -207,14 +208,14 @@ function compile(template) {
|
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
const labels = new Map();
|
|
210
|
-
const rawLabels = template[
|
|
211
|
+
const rawLabels = template[4];
|
|
211
212
|
for (let index = 0; index < rawLabels.length; index++) {
|
|
212
213
|
const pair = rawLabels[index];
|
|
213
214
|
labels.set(pair[0], pair[1]);
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
const anchors = new Map();
|
|
217
|
-
if (template[
|
|
218
|
+
if (template[1]) {
|
|
218
219
|
const anchorNames = new Set();
|
|
219
220
|
collectAnchorNames(targets, anchorNames);
|
|
220
221
|
const resourceCount = targets.length;
|
|
@@ -333,8 +334,8 @@ function compileInstructionToCode(instruction, captures, visited, budget) {
|
|
|
333
334
|
}
|
|
334
335
|
|
|
335
336
|
function generateNativeValidator(template) {
|
|
336
|
-
if (template[
|
|
337
|
-
const targets = template[
|
|
337
|
+
if (template[1] || template[2]) return null;
|
|
338
|
+
const targets = template[3];
|
|
338
339
|
if (targets.length === 0) return () => true;
|
|
339
340
|
const instructions = targets[0];
|
|
340
341
|
if (instructions.length === 0) return () => true;
|
|
@@ -367,6 +368,10 @@ function generateNativeValidator(template) {
|
|
|
367
368
|
|
|
368
369
|
class Blaze {
|
|
369
370
|
constructor(template) {
|
|
371
|
+
if (!Array.isArray(template) || template[0] !== JSON_VERSION) {
|
|
372
|
+
throw new Error(
|
|
373
|
+
`Only version ${JSON_VERSION} of the compiled template is supported by this version of the evaluator`);
|
|
374
|
+
}
|
|
370
375
|
compile(template);
|
|
371
376
|
this.template = template;
|
|
372
377
|
this.callbackMode = false;
|
|
@@ -391,11 +396,11 @@ class Blaze {
|
|
|
391
396
|
}
|
|
392
397
|
|
|
393
398
|
const template = this.template;
|
|
394
|
-
const targets = template[
|
|
399
|
+
const targets = template[3];
|
|
395
400
|
if (targets.length === 0) return true;
|
|
396
401
|
|
|
397
|
-
const track = template[
|
|
398
|
-
const dynamic = template[
|
|
402
|
+
const track = template[2];
|
|
403
|
+
const dynamic = template[1];
|
|
399
404
|
this.trackMode = track;
|
|
400
405
|
this.dynamicMode = dynamic;
|
|
401
406
|
this.callbackMode = callback !== undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sourcemeta/blaze",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
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",
|