@aml-org/amf-custom-validator
Advanced tools
Comparing version 0.1.0-SNAPSHOT.30 to 0.1.0-SNAPSHOT.31
46
index.js
@@ -7,4 +7,4 @@ require(__dirname + "/lib/wasm_exec"); | ||
let INIT = false | ||
let go = new Go(); | ||
let initialized = false | ||
let go = null; | ||
@@ -20,33 +20,39 @@ const run = function(profile, data, debug) { | ||
const validateCustomProfile = function(profile, data, debug, cb) { | ||
if (INIT) { | ||
if (initialized) { | ||
let res = run(profile, data, debug); | ||
cb(res,null); | ||
} else { | ||
if(!wasm_gz || !wasm) { | ||
wasm_gz = fs.readFileSync(__dirname + "/lib/main.wasm.gz") | ||
wasm = pako.ungzip(wasm_gz) | ||
} | ||
if (WebAssembly) { | ||
WebAssembly.instantiate(wasm, go.importObject).then((result) => { | ||
go.run(result.instance); | ||
INIT = true; | ||
let res = run(profile, data, debug); | ||
cb(res,null); | ||
}); | ||
} else { | ||
cb(null,new Error("WebAssembly is not supported in your JS environment")); | ||
} | ||
cb(null,new Error("WASM/GO not initialized")) | ||
} | ||
} | ||
const initialize = function(cb) { | ||
if (initialized === true) { | ||
cb(null) | ||
} | ||
go = new Go(); | ||
if(!wasm_gz || !wasm) { | ||
wasm_gz = fs.readFileSync(__dirname + "/lib/main.wasm.gz") | ||
wasm = pako.ungzip(wasm_gz) | ||
} | ||
if (WebAssembly) { | ||
WebAssembly.instantiate(wasm, go.importObject).then((result) => { | ||
go.run(result.instance); | ||
initialized = true; | ||
cb(null); | ||
}); | ||
} else { | ||
cb(new Error("WebAssembly is not supported in your JS environment")); | ||
} | ||
} | ||
const exit = function() { | ||
if(INIT) { | ||
if(initialized) { | ||
__AMF__terminateValidator() | ||
go.exit(0) | ||
INIT = false; | ||
go = new Go(); | ||
initialized = false; | ||
} | ||
} | ||
module.exports.initialize = initialize; | ||
module.exports.validate = validateCustomProfile; | ||
module.exports.exit = exit; |
{ | ||
"name": "@aml-org/amf-custom-validator", | ||
"version": "0.1.0-SNAPSHOT.30", | ||
"version": "0.1.0-SNAPSHOT.31", | ||
"description": "AMF validator backed by OPA Rego", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,22 +13,24 @@ const fs = require("fs"); | ||
validator.validate(profile, data, false, (r, err) => { | ||
if (err) { | ||
done(err); | ||
} else { | ||
let report = JSON.parse(r) | ||
assert.ok(report["conforms"] === false) | ||
validator.validate(profile, data, false, (r,err) => { | ||
if (err) { | ||
done(err) | ||
} else { | ||
let report = JSON.parse(r) | ||
assert.ok(report["conforms"] === false) | ||
validator.exit(); | ||
done(); | ||
} | ||
}); | ||
} | ||
}); | ||
validator.initialize(() => { | ||
validator.validate(profile, data, false, (r, err) => { | ||
if (err) { | ||
done(err); | ||
} else { | ||
let report = JSON.parse(r) | ||
assert.ok(report["conforms"] === false) | ||
validator.validate(profile, data, false, (r, err) => { | ||
if (err) { | ||
done(err) | ||
} else { | ||
let report = JSON.parse(r) | ||
assert.ok(report["conforms"] === false) | ||
validator.exit(); | ||
done(); | ||
} | ||
}); | ||
} | ||
}); | ||
}) | ||
}); | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4988949
620