@aml-org/amf-custom-validator 1.2.3 → 1.3.0-SNAPSHOT.6
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/index.js +2 -2
- package/lib/main.wasm.gz +0 -0
- package/lib/wasm_exec.js +22 -101
- package/lib/wasm_exec_node.js +39 -0
- package/package.json +4 -1
- package/test/simple.js +25 -4
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require(__dirname + "/lib/
|
|
1
|
+
require(__dirname + "/lib/wasm_exec_node");
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const pako = require("pako");
|
|
4
4
|
let wasm_gz
|
|
@@ -66,7 +66,7 @@ const initialize = function(cb) {
|
|
|
66
66
|
go.run(result.instance);
|
|
67
67
|
initialized = true;
|
|
68
68
|
cb(undefined);
|
|
69
|
-
});
|
|
69
|
+
}).catch(rejection => console.log(rejection));
|
|
70
70
|
} else {
|
|
71
71
|
cb(new Error("WebAssembly is not supported in your JS environment"));
|
|
72
72
|
}
|
package/lib/main.wasm.gz
CHANGED
|
Binary file
|
package/lib/wasm_exec.js
CHANGED
|
@@ -2,47 +2,18 @@
|
|
|
2
2
|
// Use of this source code is governed by a BSD-style
|
|
3
3
|
// license that can be found in the LICENSE file.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
// Map multiple JavaScript environments to a single common API,
|
|
7
|
-
// preferring web standards over Node.js API.
|
|
8
|
-
//
|
|
9
|
-
// Environments considered:
|
|
10
|
-
// - Browsers
|
|
11
|
-
// - Node.js
|
|
12
|
-
// - Electron
|
|
13
|
-
// - Parcel
|
|
14
|
-
// - Webpack
|
|
15
|
-
|
|
16
|
-
if (typeof global !== "undefined") {
|
|
17
|
-
// global already exists
|
|
18
|
-
} else if (typeof window !== "undefined") {
|
|
19
|
-
window.global = window;
|
|
20
|
-
} else if (typeof self !== "undefined") {
|
|
21
|
-
self.global = self;
|
|
22
|
-
} else {
|
|
23
|
-
throw new Error("cannot export Go (neither global, window nor self is defined)");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!global.require && typeof require !== "undefined") {
|
|
27
|
-
global.require = require;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!global.fs && global.require) {
|
|
31
|
-
const fs = require("fs");
|
|
32
|
-
if (typeof fs === "object" && fs !== null && Object.keys(fs).length !== 0) {
|
|
33
|
-
global.fs = fs;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
5
|
+
"use strict";
|
|
36
6
|
|
|
7
|
+
(() => {
|
|
37
8
|
const enosys = () => {
|
|
38
9
|
const err = new Error("not implemented");
|
|
39
10
|
err.code = "ENOSYS";
|
|
40
11
|
return err;
|
|
41
12
|
};
|
|
42
13
|
|
|
43
|
-
if (!
|
|
14
|
+
if (!globalThis.fs) {
|
|
44
15
|
let outputBuf = "";
|
|
45
|
-
|
|
16
|
+
globalThis.fs = {
|
|
46
17
|
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused
|
|
47
18
|
writeSync(fd, buf) {
|
|
48
19
|
outputBuf += decoder.decode(buf);
|
|
@@ -87,8 +58,8 @@
|
|
|
87
58
|
};
|
|
88
59
|
}
|
|
89
60
|
|
|
90
|
-
if (!
|
|
91
|
-
|
|
61
|
+
if (!globalThis.process) {
|
|
62
|
+
globalThis.process = {
|
|
92
63
|
getuid() { return -1; },
|
|
93
64
|
getgid() { return -1; },
|
|
94
65
|
geteuid() { return -1; },
|
|
@@ -102,47 +73,26 @@
|
|
|
102
73
|
}
|
|
103
74
|
}
|
|
104
75
|
|
|
105
|
-
if (!
|
|
106
|
-
|
|
107
|
-
global.crypto = {
|
|
108
|
-
getRandomValues(b) {
|
|
109
|
-
nodeCrypto.randomFillSync(b);
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
if (!global.crypto) {
|
|
114
|
-
throw new Error("global.crypto is not available, polyfill required (getRandomValues only)");
|
|
76
|
+
if (!globalThis.crypto) {
|
|
77
|
+
throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
|
|
115
78
|
}
|
|
116
79
|
|
|
117
|
-
if (!
|
|
118
|
-
|
|
119
|
-
now() {
|
|
120
|
-
const [sec, nsec] = process.hrtime();
|
|
121
|
-
return sec * 1000 + nsec / 1000000;
|
|
122
|
-
},
|
|
123
|
-
};
|
|
80
|
+
if (!globalThis.performance) {
|
|
81
|
+
throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");
|
|
124
82
|
}
|
|
125
83
|
|
|
126
|
-
if (!
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
if (!global.TextEncoder) {
|
|
130
|
-
throw new Error("global.TextEncoder is not available, polyfill required");
|
|
84
|
+
if (!globalThis.TextEncoder) {
|
|
85
|
+
throw new Error("globalThis.TextEncoder is not available, polyfill required");
|
|
131
86
|
}
|
|
132
87
|
|
|
133
|
-
if (!
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
if (!global.TextDecoder) {
|
|
137
|
-
throw new Error("global.TextDecoder is not available, polyfill required");
|
|
88
|
+
if (!globalThis.TextDecoder) {
|
|
89
|
+
throw new Error("globalThis.TextDecoder is not available, polyfill required");
|
|
138
90
|
}
|
|
139
91
|
|
|
140
|
-
// End of polyfills for common API.
|
|
141
|
-
|
|
142
92
|
const encoder = new TextEncoder("utf-8");
|
|
143
93
|
const decoder = new TextDecoder("utf-8");
|
|
144
94
|
|
|
145
|
-
|
|
95
|
+
globalThis.Go = class {
|
|
146
96
|
constructor() {
|
|
147
97
|
this.argv = ["js"];
|
|
148
98
|
this.env = {};
|
|
@@ -296,8 +246,8 @@
|
|
|
296
246
|
setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
|
|
297
247
|
},
|
|
298
248
|
|
|
299
|
-
// func
|
|
300
|
-
"runtime.
|
|
249
|
+
// func walltime() (sec int64, nsec int32)
|
|
250
|
+
"runtime.walltime": (sp) => {
|
|
301
251
|
sp >>>= 0;
|
|
302
252
|
const msec = (new Date).getTime();
|
|
303
253
|
setInt64(sp + 8, msec / 1000);
|
|
@@ -401,6 +351,7 @@
|
|
|
401
351
|
storeValue(sp + 56, result);
|
|
402
352
|
this.mem.setUint8(sp + 64, 1);
|
|
403
353
|
} catch (err) {
|
|
354
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
404
355
|
storeValue(sp + 56, err);
|
|
405
356
|
this.mem.setUint8(sp + 64, 0);
|
|
406
357
|
}
|
|
@@ -417,6 +368,7 @@
|
|
|
417
368
|
storeValue(sp + 40, result);
|
|
418
369
|
this.mem.setUint8(sp + 48, 1);
|
|
419
370
|
} catch (err) {
|
|
371
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
420
372
|
storeValue(sp + 40, err);
|
|
421
373
|
this.mem.setUint8(sp + 48, 0);
|
|
422
374
|
}
|
|
@@ -433,6 +385,7 @@
|
|
|
433
385
|
storeValue(sp + 40, result);
|
|
434
386
|
this.mem.setUint8(sp + 48, 1);
|
|
435
387
|
} catch (err) {
|
|
388
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
436
389
|
storeValue(sp + 40, err);
|
|
437
390
|
this.mem.setUint8(sp + 48, 0);
|
|
438
391
|
}
|
|
@@ -514,7 +467,7 @@
|
|
|
514
467
|
null,
|
|
515
468
|
true,
|
|
516
469
|
false,
|
|
517
|
-
|
|
470
|
+
globalThis,
|
|
518
471
|
this,
|
|
519
472
|
];
|
|
520
473
|
this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id
|
|
@@ -523,7 +476,7 @@
|
|
|
523
476
|
[null, 2],
|
|
524
477
|
[true, 3],
|
|
525
478
|
[false, 4],
|
|
526
|
-
[
|
|
479
|
+
[globalThis, 5],
|
|
527
480
|
[this, 6],
|
|
528
481
|
]);
|
|
529
482
|
this._idPool = []; // unused ids that have been garbage collected
|
|
@@ -598,36 +551,4 @@
|
|
|
598
551
|
};
|
|
599
552
|
}
|
|
600
553
|
}
|
|
601
|
-
|
|
602
|
-
if (
|
|
603
|
-
typeof module !== "undefined" &&
|
|
604
|
-
global.require &&
|
|
605
|
-
global.require.main === module &&
|
|
606
|
-
global.process &&
|
|
607
|
-
global.process.versions &&
|
|
608
|
-
!global.process.versions.electron
|
|
609
|
-
) {
|
|
610
|
-
if (process.argv.length < 3) {
|
|
611
|
-
console.error("usage: go_js_wasm_exec [wasm binary] [arguments]");
|
|
612
|
-
process.exit(1);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
const go = new Go();
|
|
616
|
-
go.argv = process.argv.slice(2);
|
|
617
|
-
go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env);
|
|
618
|
-
go.exit = process.exit;
|
|
619
|
-
WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {
|
|
620
|
-
process.on("exit", (code) => { // Node.js exits if no event handler is pending
|
|
621
|
-
if (code === 0 && !go.exited) {
|
|
622
|
-
// deadlock, make Go print error and stack traces
|
|
623
|
-
go._pendingEvent = { id: 0 };
|
|
624
|
-
go._resume();
|
|
625
|
-
}
|
|
626
|
-
});
|
|
627
|
-
return go.run(result.instance);
|
|
628
|
-
}).catch((err) => {
|
|
629
|
-
console.error(err);
|
|
630
|
-
process.exit(1);
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
554
|
})();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright 2021 The Go Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Go 1.19 split the wasm_exec file into two:
|
|
10
|
+
* - a base wasm_exec file that requires to provide polyfills
|
|
11
|
+
* - a Node wasm_exec_node file that provides those Node polyfills and adds some CLI behavior
|
|
12
|
+
*
|
|
13
|
+
* Removed the CLI behavior stuff and left only the polyfill provision
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
globalThis.require = require;
|
|
17
|
+
globalThis.fs = require("fs");
|
|
18
|
+
globalThis.TextEncoder = require("util").TextEncoder;
|
|
19
|
+
globalThis.TextDecoder = require("util").TextDecoder;
|
|
20
|
+
|
|
21
|
+
if (!globalThis.performance || !globalThis.performance.now) {
|
|
22
|
+
globalThis.performance = {
|
|
23
|
+
now() {
|
|
24
|
+
const [sec, nsec] = process.hrtime();
|
|
25
|
+
return sec * 1000 + nsec / 1000000; // time in milliseconds
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const crypto = require("crypto")
|
|
31
|
+
if (!globalThis.crypto || !globalThis.crypto.getRandomValues) {
|
|
32
|
+
globalThis.crypto = {
|
|
33
|
+
getRandomValues(b) {
|
|
34
|
+
crypto.randomFillSync(b);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
require("./wasm_exec");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aml-org/amf-custom-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-SNAPSHOT.6",
|
|
4
4
|
"description": "AMF validator backed by OPA Rego",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
},
|
|
9
9
|
"author": "Antonio Garrote",
|
|
10
10
|
"license": "ISC",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=16.0.0"
|
|
13
|
+
},
|
|
11
14
|
"devDependencies": {
|
|
12
15
|
"mocha": "^8.4.0"
|
|
13
16
|
},
|
package/test/simple.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
var assert = require('assert');
|
|
3
3
|
|
|
4
|
+
function invalidReport(report) {
|
|
5
|
+
return report[0]["doc:encodes"][0]["conforms"] === false
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
describe('validator', () => {
|
|
5
9
|
|
|
6
10
|
describe('validate', () => {
|
|
7
11
|
|
|
8
|
-
function invalidReport(report) {
|
|
9
|
-
return report[0]["doc:encodes"][0]["conforms"] === false
|
|
10
|
-
}
|
|
11
|
-
|
|
12
12
|
it("should load the WASM code, validate a profile, exit", (done) => {
|
|
13
13
|
const profile = fs.readFileSync(__dirname + "/../../../test/data/integration/profile10/profile.yaml").toString()
|
|
14
14
|
const data = fs.readFileSync(__dirname + "/../../../test/data/integration/profile10/negative.data.jsonld").toString()
|
|
@@ -72,4 +72,25 @@ describe('validator', () => {
|
|
|
72
72
|
})
|
|
73
73
|
|
|
74
74
|
})
|
|
75
|
+
|
|
76
|
+
describe('validate with message expressions', () => {
|
|
77
|
+
|
|
78
|
+
it("validate and compute message expression value", (done) => {
|
|
79
|
+
const profile = fs.readFileSync(__dirname + "/../../../test/data/integration/profile26/profile.yaml").toString()
|
|
80
|
+
const data = fs.readFileSync(__dirname + "/../../../test/data/integration/profile26/negative.data.jsonld").toString()
|
|
81
|
+
const validator = require(__dirname + "/../index")
|
|
82
|
+
validator.initialize(() => {
|
|
83
|
+
validator.validate(profile, data, false, (r, err) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
done(err);
|
|
86
|
+
} else {
|
|
87
|
+
let report = JSON.parse(r)
|
|
88
|
+
assert.ok(report[0]["doc:encodes"][0]["result"][0]["resultMessage"] === "Movie 'Disaster Movie' has a rating of 1.9 but it does not have at least 10 reviews (actual reviews: 5) to support that rating")
|
|
89
|
+
validator.exit();
|
|
90
|
+
done();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
})
|
|
75
96
|
})
|