-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdaemon-jsonrpc-schema.js
97 lines (94 loc) · 2.5 KB
/
daemon-jsonrpc-schema.js
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
import { compile } from "json-schema-to-typescript";
import { fileURLToPath } from "url";
const _daemonJsonrpcSchema = {
"type": "object",
"title": 'DaemonJsonrpcType',
"oneOf": [
{
"$ref": "#/$defs/getIdsChanged_fill",
},
{
"$ref": "#/$defs/getAllContracts",
},
],
"required": ["jsonrpc", "id", "method"],
"$defs": {
"getIdsChanged_fill": {
"type": "object",
"properties": {
"jsonrpc": { "type": "string", "const": "2.0" },
"id": { "type": "string" },
"method": { "type": "string", "const": "getIdsChanged_fill" },
"params": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"type": "string"
}
}
},
"required": ["jsonrpc", "id", "method", "params"]
},
"getAllContracts": {
"type": "object",
"properties": {
"jsonrpc": { "type": "string", "const": "2.0" },
"id": { "type": "string" },
"method": { "type": "string", "const": "getAllContracts" },
},
"required": ["jsonrpc", "id", "method"]
}
},
}
export const daemonJsonrpcSchema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": 'DaemonJsonrpcType',
"oneOf": [
{ "$ref": "#/$defs/request" },
{ "type": "array", "items": { "$ref": "#/$defs/request" } }
],
"$defs": {
"request": {
"type": "object",
"oneOf": [
{
"$ref": "#/$defs/getIdsChanged_fill",
},
{
"$ref": "#/$defs/getUserContracts",
},
],
},
"getIdsChanged_fill": {
"type": "object",
"properties": {
"jsonrpc": { "type": "string", "const": "2.0" },
"id": { "type": "string" },
"method": { "type": "string", "const": "getIdsChanged_fill" },
"params": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"type": "number"
}
}
},
"required": ["jsonrpc", "id", "method", "params"]
},
"getUserContracts": {
"type": "object",
"properties": {
"jsonrpc": { "type": "string", "const": "2.0" },
"id": { "type": "string" },
"method": { "type": "string", "const": "getUserContracts" },
},
"required": ["jsonrpc", "id", "method"]
}
},
}
// This is called from package.json to compile the above type
if (process.argv[1] === fileURLToPath(import.meta.url)) {
compile(daemonJsonrpcSchema).then(console.log)
}