-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbowtie_jsonschema.js
More file actions
117 lines (99 loc) · 2.99 KB
/
Copy pathbowtie_jsonschema.js
File metadata and controls
117 lines (99 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import readline from "readline/promises";
import os from "os";
import process from "process";
import { Validator } from "jsonschema";
import packageJson from "./node_modules/jsonschema/package.json" with { type: "json" };
import draft3 from "json-metaschema/draft-03-schema.json" with { type: "json" };
import draft4 from "json-metaschema/draft-04-schema.json" with { type: "json" };
import draft6 from "json-metaschema/draft-06-schema.json" with { type: "json" };
import draft7 from "json-metaschema/draft-07-schema.json" with { type: "json" };
const jsonschema_version = packageJson.version;
const stdio = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false,
});
function send(data) {
console.log(JSON.stringify(data));
}
var started = false;
const cmds = {
start: async (args) => {
console.assert(args.version === 1, { args });
started = true;
return {
version: 1,
implementation: {
language: "javascript",
name: "jsonschema",
version: jsonschema_version,
homepage: "https://github.com/tdegrunt/jsonschema",
issues: "https://github.com/tdegrunt/jsonschema/issues",
source: "https://github.com/tdegrunt/jsonschema",
dialects: [
"http://json-schema.org/draft-07/schema#",
"http://json-schema.org/draft-06/schema#",
"http://json-schema.org/draft-04/schema#",
"http://json-schema.org/draft-03/schema#",
],
os: os.platform(),
os_version: os.release(),
language_version: process.version,
},
};
},
dialect: async (_) => {
console.assert(started, "Not started!");
return { ok: false };
},
run: async (args) => {
console.assert(started, "Not started!");
const testCase = args.case;
try {
const validator = new Validator();
validator.addSchema(draft3);
validator.addSchema(draft4);
validator.addSchema(draft6);
validator.addSchema(draft7);
for (const id in testCase.registry) {
validator.addSchema(testCase.registry[id], id);
}
const results = testCase.tests.map((test) => {
try {
const result = validator.validate(test.instance, testCase.schema);
return { valid: result.valid };
} catch (error) {
return {
errored: true,
context: {
traceback: error.stack,
message: error.message,
},
};
}
});
return { seq: args.seq, results: results };
} catch (error) {
return {
errored: true,
seq: args.seq,
context: {
traceback: error.stack,
message: error.message,
},
};
}
},
stop: async (_) => {
console.assert(started, "Not started!");
process.exit(0);
},
};
async function main() {
for await (const line of stdio) {
const request = JSON.parse(line);
const response = await cmds[request.cmd](request);
send(response);
}
}
main();