@bpmn-io/element-templates-validator 2.7.0 → 2.8.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/README.md +22 -2
- package/dist/index.cjs +40 -18
- package/dist/index.js +40 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,6 @@ const {
|
|
|
27
27
|
if (!valid) {
|
|
28
28
|
console.error('Invalid JSON detected:', errors);
|
|
29
29
|
}
|
|
30
|
-
|
|
31
30
|
```
|
|
32
31
|
|
|
33
32
|
This will print detailed information about errors inside the sample:
|
|
@@ -59,7 +58,28 @@ This will print detailed information about errors inside the sample:
|
|
|
59
58
|
]
|
|
60
59
|
```
|
|
61
60
|
|
|
62
|
-
|
|
61
|
+
You can also pass a stringified template to ensure that the `dataPointers` of the errors reflect the correct position in the original string.
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import { validate } from '@bpmn-io/element-templates-validator';
|
|
65
|
+
|
|
66
|
+
import { readFileSync } from 'node:fs';
|
|
67
|
+
|
|
68
|
+
const sample = readFileSync('./test/fixtures/rpa-broken.json', 'utf-8');
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
valid,
|
|
72
|
+
errors
|
|
73
|
+
} = validate(sample);
|
|
74
|
+
|
|
75
|
+
if (!valid) {
|
|
76
|
+
console.error('Invalid JSON detected:', errors);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
If a parsed JSON object is passed, the `dataPointers` will assume that the source template is formatted with `JSON.stringify(template, null, 2)`.
|
|
81
|
+
|
|
82
|
+
It's also possible to validate multiple objects at once. In this case, the list of templates supports only objects, not strings.
|
|
63
83
|
|
|
64
84
|
```js
|
|
65
85
|
import { validateAll } from '@bpmn-io/element-templates-validator';
|
package/dist/index.cjs
CHANGED
|
@@ -570,8 +570,22 @@ function requireJsonSourceMap () {
|
|
|
570
570
|
var jsonSourceMapExports = requireJsonSourceMap();
|
|
571
571
|
var jsonMap = /*@__PURE__*/getDefaultExportFromCjs(jsonSourceMapExports);
|
|
572
572
|
|
|
573
|
-
function _validate(
|
|
574
|
-
|
|
573
|
+
function _validate(jsonString, validateFn) {
|
|
574
|
+
let dataPointerMap;
|
|
575
|
+
|
|
576
|
+
try {
|
|
577
|
+
dataPointerMap = generateDataPointerMap(jsonString);
|
|
578
|
+
} catch (err) {
|
|
579
|
+
return {
|
|
580
|
+
valid: false,
|
|
581
|
+
object: null,
|
|
582
|
+
errors: [ err ]
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
let object;
|
|
587
|
+
|
|
588
|
+
object = JSON.parse(jsonString);
|
|
575
589
|
|
|
576
590
|
const valid = validateFn(object);
|
|
577
591
|
|
|
@@ -651,7 +665,7 @@ function ignoreSupportiveErrors(errors) {
|
|
|
651
665
|
}
|
|
652
666
|
|
|
653
667
|
/**
|
|
654
|
-
* Generates a key-pointer map for the
|
|
668
|
+
* Generates a key-pointer map for the JSON string.
|
|
655
669
|
*
|
|
656
670
|
* Example:
|
|
657
671
|
*
|
|
@@ -674,11 +688,11 @@ function ignoreSupportiveErrors(errors) {
|
|
|
674
688
|
* }
|
|
675
689
|
* }
|
|
676
690
|
*
|
|
677
|
-
* @param {
|
|
691
|
+
* @param {string} jsonString
|
|
678
692
|
* @return {Object}
|
|
679
693
|
*/
|
|
680
|
-
function generateDataPointerMap(
|
|
681
|
-
return jsonMap.
|
|
694
|
+
function generateDataPointerMap(jsonString) {
|
|
695
|
+
return jsonMap.parse(jsonString).pointers;
|
|
682
696
|
}
|
|
683
697
|
|
|
684
698
|
function getSchemaVersion() {
|
|
@@ -690,13 +704,17 @@ function getSchemaPackage() {
|
|
|
690
704
|
}
|
|
691
705
|
|
|
692
706
|
/**
|
|
693
|
-
* Validate a single object.
|
|
694
|
-
*
|
|
695
|
-
* @param {Object}
|
|
696
|
-
* @return {Object} single
|
|
707
|
+
* Validate a single template, which can be either a string or an object.
|
|
708
|
+
* If an **object** is passed, the data pointers assume double-space nesting, and empty lines will be discarded.
|
|
709
|
+
* @param {Object|string} template
|
|
710
|
+
* @return {Object} single template validation result
|
|
697
711
|
*/
|
|
698
|
-
function validate(
|
|
699
|
-
|
|
712
|
+
function validate(template) {
|
|
713
|
+
if (typeof template !== 'string') {
|
|
714
|
+
template = JSON.stringify(template, null, 2);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
return _validate(template, validateTemplate$1);
|
|
700
718
|
}
|
|
701
719
|
|
|
702
720
|
/**
|
|
@@ -735,13 +753,17 @@ function getZeebeSchemaVersion() {
|
|
|
735
753
|
}
|
|
736
754
|
|
|
737
755
|
/**
|
|
738
|
-
* Validate a single object.
|
|
739
|
-
*
|
|
740
|
-
* @param {Object}
|
|
741
|
-
* @return {Object} single
|
|
756
|
+
* Validate a single template, which can be either a string or an object.
|
|
757
|
+
* If an **object** is passed, the data pointers assume double-space nesting, and empty lines will be discarded.
|
|
758
|
+
* @param {Object|string} template
|
|
759
|
+
* @return {Object} single template validation result
|
|
742
760
|
*/
|
|
743
|
-
function validateZeebe(
|
|
744
|
-
|
|
761
|
+
function validateZeebe(template) {
|
|
762
|
+
if (typeof template !== 'string') {
|
|
763
|
+
template = JSON.stringify(template, null, 2);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
return _validate(template, validateTemplate);
|
|
745
767
|
}
|
|
746
768
|
|
|
747
769
|
/**
|
package/dist/index.js
CHANGED
|
@@ -568,8 +568,22 @@ function requireJsonSourceMap () {
|
|
|
568
568
|
var jsonSourceMapExports = requireJsonSourceMap();
|
|
569
569
|
var jsonMap = /*@__PURE__*/getDefaultExportFromCjs(jsonSourceMapExports);
|
|
570
570
|
|
|
571
|
-
function _validate(
|
|
572
|
-
|
|
571
|
+
function _validate(jsonString, validateFn) {
|
|
572
|
+
let dataPointerMap;
|
|
573
|
+
|
|
574
|
+
try {
|
|
575
|
+
dataPointerMap = generateDataPointerMap(jsonString);
|
|
576
|
+
} catch (err) {
|
|
577
|
+
return {
|
|
578
|
+
valid: false,
|
|
579
|
+
object: null,
|
|
580
|
+
errors: [ err ]
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
let object;
|
|
585
|
+
|
|
586
|
+
object = JSON.parse(jsonString);
|
|
573
587
|
|
|
574
588
|
const valid = validateFn(object);
|
|
575
589
|
|
|
@@ -649,7 +663,7 @@ function ignoreSupportiveErrors(errors) {
|
|
|
649
663
|
}
|
|
650
664
|
|
|
651
665
|
/**
|
|
652
|
-
* Generates a key-pointer map for the
|
|
666
|
+
* Generates a key-pointer map for the JSON string.
|
|
653
667
|
*
|
|
654
668
|
* Example:
|
|
655
669
|
*
|
|
@@ -672,11 +686,11 @@ function ignoreSupportiveErrors(errors) {
|
|
|
672
686
|
* }
|
|
673
687
|
* }
|
|
674
688
|
*
|
|
675
|
-
* @param {
|
|
689
|
+
* @param {string} jsonString
|
|
676
690
|
* @return {Object}
|
|
677
691
|
*/
|
|
678
|
-
function generateDataPointerMap(
|
|
679
|
-
return jsonMap.
|
|
692
|
+
function generateDataPointerMap(jsonString) {
|
|
693
|
+
return jsonMap.parse(jsonString).pointers;
|
|
680
694
|
}
|
|
681
695
|
|
|
682
696
|
function getSchemaVersion() {
|
|
@@ -688,13 +702,17 @@ function getSchemaPackage() {
|
|
|
688
702
|
}
|
|
689
703
|
|
|
690
704
|
/**
|
|
691
|
-
* Validate a single object.
|
|
692
|
-
*
|
|
693
|
-
* @param {Object}
|
|
694
|
-
* @return {Object} single
|
|
705
|
+
* Validate a single template, which can be either a string or an object.
|
|
706
|
+
* If an **object** is passed, the data pointers assume double-space nesting, and empty lines will be discarded.
|
|
707
|
+
* @param {Object|string} template
|
|
708
|
+
* @return {Object} single template validation result
|
|
695
709
|
*/
|
|
696
|
-
function validate(
|
|
697
|
-
|
|
710
|
+
function validate(template) {
|
|
711
|
+
if (typeof template !== 'string') {
|
|
712
|
+
template = JSON.stringify(template, null, 2);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
return _validate(template, validateTemplate$1);
|
|
698
716
|
}
|
|
699
717
|
|
|
700
718
|
/**
|
|
@@ -733,13 +751,17 @@ function getZeebeSchemaVersion() {
|
|
|
733
751
|
}
|
|
734
752
|
|
|
735
753
|
/**
|
|
736
|
-
* Validate a single object.
|
|
737
|
-
*
|
|
738
|
-
* @param {Object}
|
|
739
|
-
* @return {Object} single
|
|
754
|
+
* Validate a single template, which can be either a string or an object.
|
|
755
|
+
* If an **object** is passed, the data pointers assume double-space nesting, and empty lines will be discarded.
|
|
756
|
+
* @param {Object|string} template
|
|
757
|
+
* @return {Object} single template validation result
|
|
740
758
|
*/
|
|
741
|
-
function validateZeebe(
|
|
742
|
-
|
|
759
|
+
function validateZeebe(template) {
|
|
760
|
+
if (typeof template !== 'string') {
|
|
761
|
+
template = JSON.stringify(template, null, 2);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
return _validate(template, validateTemplate);
|
|
743
765
|
}
|
|
744
766
|
|
|
745
767
|
/**
|