@mml-io/mml-schema-validator 0.17.1 → 0.18.1
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/build/index.js +27 -10
- package/build/index.js.map +2 -2
- package/build/validate.d.ts +19 -1
- package/package.json +4 -4
package/build/index.js
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
// src/validate.ts
|
|
2
2
|
import { schemaXML } from "@mml-io/mml-schema";
|
|
3
|
-
import
|
|
4
|
-
function validateMMLDocument(
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
3
|
+
import { XmlDocument, XmlValidateError, XsdValidator } from "libxml2-wasm";
|
|
4
|
+
function validateMMLDocument(xml) {
|
|
5
|
+
const parsedXML = XmlDocument.fromString(xml.toString());
|
|
6
|
+
const parsedSchema = XmlDocument.fromString(schemaXML.toString());
|
|
7
|
+
const validator = XsdValidator.fromDoc(parsedSchema);
|
|
8
|
+
let error = null;
|
|
9
|
+
try {
|
|
10
|
+
validator.validate(parsedXML);
|
|
11
|
+
} catch (e) {
|
|
12
|
+
error = e;
|
|
13
13
|
}
|
|
14
|
+
parsedXML.dispose();
|
|
15
|
+
parsedSchema.dispose();
|
|
16
|
+
validator.dispose();
|
|
17
|
+
if (error) {
|
|
18
|
+
if (error instanceof XmlValidateError) {
|
|
19
|
+
return error.details.map((detail) => ({
|
|
20
|
+
name: "ValidationError",
|
|
21
|
+
message: detail.message,
|
|
22
|
+
file: detail.file,
|
|
23
|
+
line: detail.line,
|
|
24
|
+
col: detail.col
|
|
25
|
+
}));
|
|
26
|
+
} else {
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
14
31
|
}
|
|
15
32
|
export {
|
|
16
33
|
validateMMLDocument
|
package/build/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/validate.ts"],
|
|
4
|
-
"sourcesContent": ["import { schemaXML } from \"@mml-io/mml-schema\";\nimport
|
|
5
|
-
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,
|
|
4
|
+
"sourcesContent": ["import { schemaXML } from \"@mml-io/mml-schema\";\nimport { XmlDocument, XmlError, XmlValidateError, XsdValidator } from \"libxml2-wasm\";\n\nexport interface ValidationError extends Error {\n /**\n * The message of the error during processing.\n */\n message: string;\n /**\n * The filename\n */\n file?: string;\n /**\n * The line number of the xml file, where the error is occurred.\n */\n line: number;\n /**\n * The column number of the xml file, where the error is occurred.\n */\n col: number;\n}\n\nexport function validateMMLDocument(xml: string | Buffer): null | ValidationError[] {\n const parsedXML = XmlDocument.fromString(xml.toString());\n const parsedSchema = XmlDocument.fromString(schemaXML.toString());\n const validator = XsdValidator.fromDoc(parsedSchema);\n\n let error: XmlValidateError | XmlError | null = null;\n try {\n validator.validate(parsedXML);\n } catch (e) {\n error = e;\n }\n parsedXML.dispose();\n parsedSchema.dispose();\n validator.dispose();\n\n if (error) {\n if (error instanceof XmlValidateError) {\n return error.details.map((detail) => ({\n name: \"ValidationError\",\n message: detail.message,\n file: detail.file,\n line: detail.line,\n col: detail.col,\n }));\n } else {\n throw error;\n }\n }\n return null;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,aAAuB,kBAAkB,oBAAoB;AAqB/D,SAAS,oBAAoB,KAAgD;AAClF,QAAM,YAAY,YAAY,WAAW,IAAI,SAAS,CAAC;AACvD,QAAM,eAAe,YAAY,WAAW,UAAU,SAAS,CAAC;AAChE,QAAM,YAAY,aAAa,QAAQ,YAAY;AAEnD,MAAI,QAA4C;AAChD,MAAI;AACF,cAAU,SAAS,SAAS;AAAA,EAC9B,SAAS,GAAG;AACV,YAAQ;AAAA,EACV;AACA,YAAU,QAAQ;AAClB,eAAa,QAAQ;AACrB,YAAU,QAAQ;AAElB,MAAI,OAAO;AACT,QAAI,iBAAiB,kBAAkB;AACrC,aAAO,MAAM,QAAQ,IAAI,CAAC,YAAY;AAAA,QACpC,MAAM;AAAA,QACN,SAAS,OAAO;AAAA,QAChB,MAAM,OAAO;AAAA,QACb,MAAM,OAAO;AAAA,QACb,KAAK,OAAO;AAAA,MACd,EAAE;AAAA,IACJ,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/validate.d.ts
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface ValidationError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* The message of the error during processing.
|
|
4
|
+
*/
|
|
5
|
+
message: string;
|
|
6
|
+
/**
|
|
7
|
+
* The filename
|
|
8
|
+
*/
|
|
9
|
+
file?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The line number of the xml file, where the error is occurred.
|
|
12
|
+
*/
|
|
13
|
+
line: number;
|
|
14
|
+
/**
|
|
15
|
+
* The column number of the xml file, where the error is occurred.
|
|
16
|
+
*/
|
|
17
|
+
col: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function validateMMLDocument(xml: string | Buffer): null | ValidationError[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mml-io/mml-schema-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@mml-io/mml-schema": "^0.
|
|
21
|
-
"
|
|
20
|
+
"@mml-io/mml-schema": "^0.18.1",
|
|
21
|
+
"libxml2-wasm": "0.4.0"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "ef5baff6cda84a1acaed56a957c6b81f4c5acfd5"
|
|
24
24
|
}
|