X Tutup
Skip to content

Commit 866cdbc

Browse files
committed
schemas schema.json and evaluate.json are generated by templates
1 parent 352d7cc commit 866cdbc

17 files changed

+541
-159
lines changed

instructions/data.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "$data",
3+
"description": "data from the data instance using JSON-pointer expression, $data value should evalute to a string before the expression is evaluated",
4+
"keywords": ["$data"],
5+
"required": ["$data"],
6+
"evaluate": {
7+
"keyword": "getData",
8+
"title": "$data reference to the part of the data instance",
9+
"description": "Keyword should replace $data instruction with the data value at the position defined by JSON-pointer"
10+
},
11+
"schema": {
12+
"$data": {
13+
"type": "string",
14+
"anyOf": [
15+
{ "format": "json-pointer" },
16+
{ "format": "relative-json-pointer" }
17+
]
18+
}
19+
}
20+
}

instructions/exec.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "$exec",
3+
"description": "call to external object, $exec and $method values should evaluate to a string",
4+
"keywords": ["$exec", "$method", "$args"],
5+
"required": ["$exec"],
6+
"evaluate": {
7+
"keyword": "callExec",
8+
"title": "$exec call",
9+
"description": "call function or method in $exec instruction; keyword should replace the instruction with the result or with the promise"
10+
},
11+
"schema": {
12+
"$exec": {
13+
"type": "string",
14+
"anyOf": [
15+
{ "format": "js-identifier" },
16+
{ "format": "uuid" }
17+
]
18+
},
19+
"$method": {
20+
"type": "string",
21+
"format": "js-identifier"
22+
}
23+
}
24+
}

instructions/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
module.exports = [
4+
require('./exec.json'),
5+
require('./ref.json'),
6+
require('./data.json')
7+
];

instructions/ref.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "$ref",
3+
"description": "data/script from the current script using absolute/relative JSON-pointer expression",
4+
"keywords": ["$ref"],
5+
"required": ["$ref"],
6+
"evaluate": {
7+
"keyword": "getRef",
8+
"title": "$ref to the part of the script",
9+
"description": "Keyword should replace $ref instruction with the result of the script evaluation at this position"
10+
},
11+
"schema": {
12+
"$ref": {
13+
"type": "string",
14+
"format": "json-pointer"
15+
}
16+
}
17+
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "Platform independent asynchronous and concurrent scripting language using JSON format",
55
"main": "index.js",
66
"scripts": {
7-
"test": "mocha --recursive --reporter=spec spec"
7+
"generate": "node scripts/generate",
8+
"test-spec": "mocha --recursive --reporter=spec spec",
9+
"test": "npm run generate && npm run test-spec"
810
},
911
"repository": {
1012
"type": "git",
@@ -24,5 +26,8 @@
2426
"ajv": "^3.5.3",
2527
"json-schema-test": "^1.2.1",
2628
"mocha": "^2.2.5"
29+
},
30+
"dependencies": {
31+
"dot": "^1.0.3"
2732
}
2833
}

schema/evaluate.json

Lines changed: 111 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,135 @@
44
"description": "schema with custom keywords that evaluates JSON script. It assumes that the script is valid",
55
"switch": [
66
{
7-
"if": { "type": "object" },
7+
"if": {
8+
"type": "object"
9+
},
810
"then": {
911
"title": "parallel execution or script command",
1012
"description": "evaluates all properties in parallel or executes script command (its keywords are evaluated in parallel too)",
11-
"allOf":[
13+
"allOf": [
1214
{
1315
"title": "evaluate properties",
1416
"description": "evaluates all properties using the same schema, properties-scripts are replaced with returned data or 'promise'",
15-
"additionalProperties": { "$ref": "#" }
17+
"additionalProperties": {
18+
"$ref": "#"
19+
}
1620
},
1721
{
18-
"title": "validate keywords",
19-
"description": "validates script keyword values or chains promises to validate resolved values of keywords",
20-
"properties": {
21-
"$func": { "thenValue": { "$ref": "#uuidOrIdentifier" } },
22-
"$object": { "thenValue": { "$ref": "#uuidOrIdentifier" } },
23-
"$method": { "thenValue": { "$ref": "#identifier" } },
24-
"$ref": { "thenValue": { "$ref": "#jsonPointer" } },
25-
"$data": { "thenValue": { "$ref": "#anyJsonPointer" } }
26-
}
22+
"title": "object to promise",
23+
"description": "merge object properties into a single promise",
24+
"objectToPromise": true
2725
},
2826
{
29-
"title": "execute command",
30-
"description": "executes supported script commands",
31-
"switch": [
32-
{
33-
"if": { "required": [ "$func" ] },
34-
"then": { "callFunc": true }
35-
},
36-
{
37-
"if": { "required": [ "$method" ] },
38-
"then": { "callMethod": true }
39-
},
40-
{
41-
"if": { "required": [ "$ref" ] },
42-
"then": { "getRef": true }
43-
},
44-
{
45-
"if": { "required": [ "$data" ] },
46-
"then": { "getData": true }
47-
}
48-
]
27+
"title": "execute instruction",
28+
"description": "executes supported script instructions",
29+
"thenValue": {
30+
"switch": [
31+
{
32+
"if": {
33+
"required": [
34+
"$exec"
35+
]
36+
},
37+
"then": {
38+
"allOf": [
39+
{
40+
"description": "valdate evaluated instruction keywords",
41+
"properties": {
42+
"$exec": {
43+
"type": "string",
44+
"anyOf": [
45+
{
46+
"format": "js-identifier"
47+
},
48+
{
49+
"format": "uuid"
50+
}
51+
]
52+
},
53+
"$method": {
54+
"type": "string",
55+
"format": "js-identifier"
56+
}
57+
}
58+
},
59+
{
60+
"description": "execute instruction using custom keyword",
61+
"callExec": true
62+
}
63+
]
64+
}
65+
},
66+
{
67+
"if": {
68+
"required": [
69+
"$ref"
70+
]
71+
},
72+
"then": {
73+
"allOf": [
74+
{
75+
"description": "valdate evaluated instruction keywords",
76+
"properties": {
77+
"$ref": {
78+
"type": "string",
79+
"format": "json-pointer"
80+
}
81+
}
82+
},
83+
{
84+
"description": "execute instruction using custom keyword",
85+
"getRef": true
86+
}
87+
]
88+
}
89+
},
90+
{
91+
"if": {
92+
"required": [
93+
"$data"
94+
]
95+
},
96+
"then": {
97+
"allOf": [
98+
{
99+
"description": "valdate evaluated instruction keywords",
100+
"properties": {
101+
"$data": {
102+
"type": "string",
103+
"anyOf": [
104+
{
105+
"format": "json-pointer"
106+
},
107+
{
108+
"format": "relative-json-pointer"
109+
}
110+
]
111+
}
112+
}
113+
},
114+
{
115+
"description": "execute instruction using custom keyword",
116+
"getData": true
117+
}
118+
]
119+
}
120+
}
121+
]
122+
}
49123
}
50124
]
51125
}
52126
},
53127
{
54-
"if": { "type": "array" },
128+
"if": {
129+
"type": "array"
130+
},
55131
"then": {
56132
"title": "sequential execution",
57133
"description": "queues items so that the next promise is created only after the previous one is resolved",
58134
"queueItems": true
59135
}
60136
}
61-
],
62-
"definitions": {
63-
"identifier": {
64-
"id": "#identifier",
65-
"type": "string",
66-
"pattern": "^[A-Za-z$_][A-Za-z$_0-9]*$"
67-
},
68-
"uuidOrIdentifier": {
69-
"id": "#uuidOrIdentifier",
70-
"type": "string",
71-
"anyOf": [
72-
{ "pattern": "^[A-Za-z$_][A-Za-z$_0-9]*$" },
73-
{ "format": "uuid" }
74-
]
75-
},
76-
"jsonPointer": {
77-
"id": "#jsonPointer",
78-
"type": "string",
79-
"format": "json-pointer"
80-
},
81-
"anyJsonPointer": {
82-
"id": "#anyJsonPointer",
83-
"type": "string",
84-
"anyOf": [
85-
{ "format": "json-pointer" },
86-
{ "format": "relative-json-pointer" }
87-
]
88-
}
89-
}
90-
}
137+
]
138+
}

schema/evaluate.json.dot

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"id": "http://json-script.com/schema/evaluate.json#",
3+
"$schema": "http://json-script.com/schema/evaluate_metaschema.json#",
4+
"description": "schema with custom keywords that evaluates JSON script. It assumes that the script is valid",
5+
"switch": [
6+
{
7+
"if": { "type": "object" },
8+
"then": {
9+
"title": "parallel execution or script command",
10+
"description": "evaluates all properties in parallel or executes script command (its keywords are evaluated in parallel too)",
11+
"allOf":[
12+
{
13+
"title": "evaluate properties",
14+
"description": "evaluates all properties using the same schema, properties-scripts are replaced with returned data or 'promise'",
15+
"additionalProperties": { "$ref": "#" }
16+
},
17+
{
18+
"title": "object to promise",
19+
"description": "merge object properties into a single promise",
20+
"objectToPromise": true
21+
},
22+
{
23+
"title": "execute instruction",
24+
"description": "executes supported script instructions",
25+
"thenValue": {
26+
"switch": [
27+
{{~ it.instructions:inst:i }}
28+
{{?i}},{{?}}
29+
{
30+
"if": { "required": [ "{{=inst.name}}" ] },
31+
"then": {
32+
"allOf": [
33+
{
34+
"description": "valdate evaluated instruction keywords",
35+
"properties": {{= JSON.stringify(inst.schema) }}
36+
},
37+
{
38+
"description": "execute instruction using custom keyword",
39+
"{{=inst.evaluate.keyword}}": true
40+
}
41+
]
42+
}
43+
}
44+
{{~}}
45+
]
46+
}
47+
}
48+
]
49+
}
50+
},
51+
{
52+
"if": { "type": "array" },
53+
"then": {
54+
"title": "sequential execution",
55+
"description": "queues items so that the next promise is created only after the previous one is resolved",
56+
"queueItems": true
57+
}
58+
}
59+
]
60+
}

0 commit comments

Comments
 (0)
X Tutup