Skip to content

Commit f1b028c

Browse files
committedMay 22, 2016
updated docs, schema
1 parent cb2f9d7 commit f1b028c

File tree

8 files changed

+103
-1206
lines changed

8 files changed

+103
-1206
lines changed
 

‎LANGUAGE.md

+5-223
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,6 @@ An asynchronous value is a value that is currently not available and will be ava
4848

4949
JSONScript can include several instructions that will be executed sequentially:
5050

51-
```json
52-
[
53-
{
54-
"$exec": "router",
55-
"$method": "get",
56-
"$args": { "path": "/resource/1" }
57-
},
58-
{
59-
"$exec": "router",
60-
"$method": "put",
61-
"$args": { "path": "/resource/1", "body": "test" }
62-
}
63-
]
64-
```
65-
66-
or with short syntax:
67-
6851
```json
6952
[
7053
{ "$$router.get": { "path": "/resource/1" } },
@@ -82,37 +65,6 @@ Sequential evaluation is not limited to executing individual instructions - any
8265

8366
For example, this script does the same as the script above for two resources:
8467

85-
```json
86-
[
87-
[
88-
{
89-
"$exec": "router",
90-
"$method": "get",
91-
"$args": { "path": "/resource/1" }
92-
},
93-
{
94-
"$exec": "router",
95-
"$method": "put",
96-
"$args": { "path": "/resource/1", "body": "test" }
97-
}
98-
],
99-
[
100-
{
101-
"$exec": "router",
102-
"$method": "get",
103-
"$args": { "path": "/resource/2" }
104-
},
105-
{
106-
"$exec": "router",
107-
"$method": "put",
108-
"$args": { "path": "/resource/2", "body": "test" }
109-
}
110-
]
111-
]
112-
```
113-
114-
or with short syntax:
115-
11668
```json
11769
[
11870
[
@@ -134,23 +86,6 @@ The result of this script evaluation is the array of two arrays containing two i
13486

13587
JSONScript can include several instructions that will be executed in parallel:
13688

137-
```json
138-
{
139-
"res1": {
140-
"$exec": "router",
141-
"$method": "get",
142-
"$args": { "path": "/resource/1" }
143-
},
144-
"res2": {
145-
"$exec": "router",
146-
"$method": "get",
147-
"$args": { "path": "/resource/2" }
148-
}
149-
}
150-
```
151-
152-
or with short syntax:
153-
15489
```json
15590
{
15691
"res1": { "$$router.get": { "path": "/resource/1" } },
@@ -168,37 +103,6 @@ Parallel evaluation is not limited to executing individual instructions - any sc
168103

169104
For example, the script below is similar to the example in the previous section that updates two resources but it does it in parallel:
170105

171-
```json
172-
{
173-
"res1": [
174-
{
175-
"$exec": "router",
176-
"$method": "get",
177-
"$args": { "path": "/resource/1" }
178-
},
179-
{
180-
"$exec": "router",
181-
"$method": "put",
182-
"$args": { "path": "/resource/1", "body": "test" }
183-
}
184-
],
185-
"res2": [
186-
{
187-
"$exec": "router",
188-
"$method": "get",
189-
"$args": { "path": "/resource/2" }
190-
},
191-
{
192-
"$exec": "router",
193-
"$method": "put",
194-
"$args": { "path": "/resource/2", "body": "test" }
195-
}
196-
]
197-
}
198-
```
199-
200-
or with short syntax:
201-
202106
```json
203107
{
204108
"res1": [
@@ -225,23 +129,6 @@ Let's see what other instructions are defined in JSONScript core.
225129

226130
During the evaluation the script can use the data instance passed to the interpeter in addition to the script:
227131

228-
```json
229-
[
230-
{
231-
"$exec": "router",
232-
"$method": "get",
233-
"$args": { "path": { "$data": "/path" } }
234-
},
235-
{
236-
"$exec": "router",
237-
"$method": "put",
238-
"$args": { "$data": "" }
239-
}
240-
]
241-
```
242-
243-
or with short syntax:
244-
245132
```json
246133
[
247134
{ "$$router.get": { "path": { "$data": "/path" } } },
@@ -314,24 +201,6 @@ JSONScript interpreters should both try to determine such situations as early as
314201

315202
`$if` instruction can be used to choose the strict that will be evaluated based on some condition:
316203

317-
```json
318-
{
319-
"$if": { "$exec": "checkAvailability", "$args": "router1" },
320-
"$then": {
321-
"$exec": "router1",
322-
"$method": "get",
323-
"$args": { "path": "/resource/1" }
324-
},
325-
"$else": {
326-
"$exec": "router2",
327-
"$method": "get",
328-
"$args": { "path": "/resource/1" }
329-
}
330-
}
331-
```
332-
333-
or with short syntax:
334-
335204
```json
336205
{
337206
"$if": { "$$checkAvailability": "router1" },
@@ -353,7 +222,7 @@ Scalar values can be used in any place where the script is expected - they evalu
353222
```json
354223
{
355224
"$exec": {
356-
"$if": { "$exec": "checkAvailability", "$args": "router1" },
225+
"$if": { "$$checkAvailability": "router1" },
357226
"$then": "router1",
358227
"$else": "router2"
359228
},
@@ -367,7 +236,7 @@ or using reference:
367236
```json
368237
{
369238
"router": {
370-
"$if": { "$exec": "checkAvailability", "$args": "router1" },
239+
"$if": { "$$checkAvailability": "router1" },
371240
"$then": "router1",
372241
"$else": "router2"
373242
},
@@ -386,26 +255,6 @@ or using reference:
386255

387256
`$delay` instruction can be used to delay the start of evaluation of any script. That can be useful, for example, if you need to ensure that one script starts evaluating after another script starts, but you don't need for it to wait for the completion (as in sequential processing):
388257

389-
```json
390-
{
391-
"res1": {
392-
"$exec": "router",
393-
"$method": "get",
394-
"$args": { "path": "/resource/1" }
395-
},
396-
"res2": {
397-
"$delay": {
398-
"$exec": "router",
399-
"$method": "get",
400-
"$args": { "path": "/resource/2" }
401-
},
402-
"$wait": 50
403-
}
404-
}
405-
```
406-
407-
or with short syntax:
408-
409258
```json
410259
{
411260
"res1": { "$$router.get": { "path": "/resource/1" } },
@@ -420,19 +269,6 @@ The evaluation result will be the same as without `$delay` istruction, but the s
420269

421270
This instruction can also be used to create asynchronous value from synchronous value. For example if some executor expects an asynchronous value as an argument and you want to pass a constant, you can use `$delay`:
422271

423-
```json
424-
{
425-
"$exec": "logger",
426-
"$method": "resolve",
427-
"$args": {
428-
"message": "Resolved",
429-
"asyncValue": { "$delay": "test", "$wait": 1000 }
430-
}
431-
}
432-
```
433-
434-
or with short syntax:
435-
436272
```json
437273
{
438274
"$$logger.resolve": {
@@ -451,34 +287,6 @@ In the example above a hypothetical logger logs message when asynchronous value
451287

452288
Anonymous or named function can be defined in the script to be passed to executors (either predefined or supplied by user) or simply to be used multiple times.
453289

454-
```json
455-
[
456-
{
457-
"$func": {
458-
"$exec": "router",
459-
"$method": "get",
460-
"$args": { "path": { "$data": "/path" } }
461-
},
462-
"$name": "getRes",
463-
"$args": [ "path" ]
464-
},
465-
{
466-
"$call": "getRes",
467-
"$args": [ "/resource/1" ]
468-
},
469-
{
470-
"$call": { "$ref": "/0" },
471-
"$args": { "path": "/resource/2" }
472-
},
473-
{
474-
"$call": { "$ref": "1/0" },
475-
"$args": "/resource/3"
476-
}
477-
]
478-
```
479-
480-
or with short syntax:
481-
482290
```json
483291
[
484292
{
@@ -502,32 +310,6 @@ In the example above the same function `getRes` is used three times, being calle
502310

503311
Functions can be used as parameters in the executors:
504312

505-
```json
506-
{
507-
"$exec": "array",
508-
"$method": "map",
509-
"$args": {
510-
"data": [
511-
"/resource/1",
512-
"/resource/2",
513-
"/resource/3"
514-
],
515-
"iterator": {
516-
"$func": {
517-
"$exec": "router1",
518-
"$method": "get",
519-
"$args": {
520-
"path": { "$data": "/path" }
521-
}
522-
},
523-
"$args": ["path"]
524-
}
525-
}
526-
}
527-
```
528-
529-
or with short syntax:
530-
531313
```json
532314
{
533315
"$$array.map": {
@@ -546,6 +328,8 @@ or with short syntax:
546328
}
547329
```
548330

331+
See [Array iteration](#array-iteration).
332+
549333
If the function was previously defined it can be passed either using `"$ref"` with an absolute or relative JSON-pointer or `{ "$func": "myfunc" }. The latter always evaluates as the reference to the existing function rather than the function that always returns string "myfunc", to define the function that always returns the same string you can use "$quote".
550334

551335

@@ -566,9 +350,7 @@ evaluates as: `{ "$exec": "myExec" }` and the executor is not called.
566350
`$quote` can also be used to define the function that always returns the same string:
567351

568352
```json
569-
{
570-
"$func": { "$quote": "foo" }
571-
}
353+
{ "$func": { "$quote": "foo" } }
572354
```
573355

574356
The anonymous function defined above always returns the string `"foo"`. Without `$quote` it would have been the reference to the function with the name `foo`.

‎README.md

+41-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
11
# JSONScript
22

3-
Platform independent asynchronous and concurrent scripting language using JSON format.
4-
5-
JSONScript is created to manage scripted execution in remote systems to avoid the latency between requests and unnecessary transfers of intermediary results.
3+
Language for scripted server-side processing of existing endpoints and services.
64

75
[![Build Status](https://travis-ci.org/JSONScript/jsonscript.svg?branch=master)](https://travis-ci.org/JSONScript/jsonscript)
86
[![npm version](https://badge.fury.io/js/jsonscript.svg)](https://www.npmjs.com/package/jsonscript)
97

108

11-
## Features
12-
13-
JSONScript:
14-
15-
- uses JSON as its representaion format for both data and control structures, being similar to lisp (homoiconic).
16-
- defines simple control structures.
17-
- is asynchronous and concurrent without the need to use any special keywords.
18-
- actual processing in the remote system is done synchronously or asynchronously by the functions and objects supplied to JSONScript interpreter by the host environment.
9+
## Script example
10+
11+
```json
12+
{
13+
"$$array.map": {
14+
"data": [
15+
{ "path": "/resource/1", "body": { "test": 1 } },
16+
{ "path": "/resource/2", "body": { "test": 2 } },
17+
{ "path": "/resource/3", "body": { "test": 3 } },
18+
],
19+
"iterator": {
20+
"$func": [
21+
{ "$$router.get": { "path": { "$data": "/path" } } },
22+
{ "$$router.put": { "$data": "/" } },
23+
],
24+
"$args": ["path", "body"]
25+
}
26+
}
27+
}
28+
```
29+
30+
Using YAML for the same script makes it more readable:
31+
32+
```yaml
33+
$$array.map:
34+
data:
35+
- { path: /resource/1, body: { test: 1 } }
36+
- { path: /resource/2, body: { test: 2 } }
37+
- { path: /resource/3, body: { test: 3 } }
38+
iterator:
39+
$func:
40+
- $$router.get: { path: { $data: /path } }
41+
- $$router.put: { $data: / }
42+
$args: [ path, body ]
43+
```
44+
45+
When executed on the server, the script above iterates array of requests, retrieves resource for each path and then updates it with a new value.
46+
47+
See [Language](https://github.com/JSONScript/jsonscript/blob/master/LANGUAGE.md).
1948
2049
2150
## Problem
@@ -45,17 +74,12 @@ At the same time JSONScript allows keeping the remote system completely secure a
4574
As the script executes, each instruction returns some data. By default this data replaces the script itself and all results will be available to the interpreter to pass back to the host system that requested execution. Host system usually sends results back to the client, but can do anything else with them, e.g. logging, storing to the database, etc.).
4675
4776
48-
## Language
49-
50-
See [Language](https://github.com/JSONScript/jsonscript/blob/master/LANGUAGE.md)
51-
52-
5377
## Schema
5478
5579
See [Schema](https://github.com/JSONScript/jsonscript/blob/master/SCHEMA.md) for JSON-schemas for the script and for instruction definitions.
5680
5781
58-
## Implementation
82+
## Implementations
5983
6084
JSONScript interpreter for node-js: [jsonscript-js](https://github.com/epoberezkin/jsonscript-js)
6185

‎README_OLD.md

-904
This file was deleted.

‎SYNTAX.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# JSONScript syntax
22

3+
In progress - not complete, see [Language](https://github.com/JSONScript/jsonscript/blob/master/LANGUAGE.md).
4+
35

46
## Script
57

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonscript",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "Platform independent asynchronous and concurrent scripting language using JSON format",
55
"main": "index.js",
66
"scripts": {

‎schema/schema.json

+24-28
Original file line numberDiff line numberDiff line change
@@ -200,65 +200,61 @@
200200
"id": "#macro_exec_0",
201201
"description": "short syntax for executor call",
202202
"type": "object",
203-
"patternProperties": {
203+
"patternGroups": {
204204
"^\\$\\$([^\\.]+)\\.([^\\.]+)$": {
205-
"$ref": "#"
205+
"schema": {
206+
"$ref": "#"
207+
},
208+
"minimum": 1
206209
}
207210
},
208211
"maxProperties": 1,
209-
"minProperties": 1,
210-
"additionalProperties": false,
211-
"patternRequired": [
212-
"^\\$\\$([^\\.]+)\\.([^\\.]+)$"
213-
]
212+
"additionalProperties": false
214213
},
215214
"_macro_exec_1": {
216215
"id": "#macro_exec_1",
217216
"description": "short syntax for executor call",
218217
"type": "object",
219-
"patternProperties": {
218+
"patternGroups": {
220219
"^\\$\\$([^\\.]+)$": {
221-
"$ref": "#"
220+
"schema": {
221+
"$ref": "#"
222+
},
223+
"minimum": 1
222224
}
223225
},
224226
"maxProperties": 1,
225-
"minProperties": 1,
226-
"additionalProperties": false,
227-
"patternRequired": [
228-
"^\\$\\$([^\\.]+)$"
229-
]
227+
"additionalProperties": false
230228
},
231229
"_macro_call_0": {
232230
"id": "#macro_call_0",
233231
"description": "short syntax for function call",
234232
"type": "object",
235-
"patternProperties": {
233+
"patternGroups": {
236234
"^\\$\\#(.+)$": {
237-
"$ref": "#"
235+
"schema": {
236+
"$ref": "#"
237+
},
238+
"minimum": 1
238239
}
239240
},
240241
"maxProperties": 1,
241-
"minProperties": 1,
242-
"additionalProperties": false,
243-
"patternRequired": [
244-
"^\\$\\#(.+)$"
245-
]
242+
"additionalProperties": false
246243
},
247244
"_macro_calc_0": {
248245
"id": "#macro_calc_0",
249246
"description": "short calculations syntax",
250247
"type": "object",
251-
"patternProperties": {
248+
"patternGroups": {
252249
"\\$([+\\-*/=!<>&\\|^]{1,2})": {
253-
"$ref": "#"
250+
"schema": {
251+
"$ref": "#"
252+
},
253+
"minimum": 1
254254
}
255255
},
256256
"maxProperties": 1,
257-
"minProperties": 1,
258-
"additionalProperties": false,
259-
"patternRequired": [
260-
"\\$([+\\-*/=!<>&\\|^]{1,2})"
261-
]
257+
"additionalProperties": false
262258
},
263259
"parallel": {
264260
"id": "#parallel",

‎schema/schema.json.dot

+6-5
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@
5959
"id": "#macro_{{=macro.name}}_{{=i}}",
6060
"description": "{{=macro.description}}",
6161
"type": "object",
62-
"patternProperties": {
63-
"{{= patternKey }}": { "$ref": "#" }
62+
"patternGroups": {
63+
"{{= patternKey }}": {
64+
"schema": { "$ref": "#" },
65+
"minimum": 1
66+
}
6467
},
6568
"maxProperties": 1,
66-
"minProperties": 1,
67-
"additionalProperties": false,
68-
"patternRequired": [ "{{= patternKey }}" ]
69+
"additionalProperties": false
6970
},
7071
{{~}}
7172
{{~}}

‎schema/schema_strict.json

+24-28
Original file line numberDiff line numberDiff line change
@@ -346,65 +346,61 @@
346346
"id": "#macro_exec_0",
347347
"description": "short syntax for executor call",
348348
"type": "object",
349-
"patternProperties": {
349+
"patternGroups": {
350350
"^\\$\\$([^\\.]+)\\.([^\\.]+)$": {
351-
"$ref": "#"
351+
"schema": {
352+
"$ref": "#"
353+
},
354+
"minimum": 1
352355
}
353356
},
354357
"maxProperties": 1,
355-
"minProperties": 1,
356-
"additionalProperties": false,
357-
"patternRequired": [
358-
"^\\$\\$([^\\.]+)\\.([^\\.]+)$"
359-
]
358+
"additionalProperties": false
360359
},
361360
"_macro_exec_1": {
362361
"id": "#macro_exec_1",
363362
"description": "short syntax for executor call",
364363
"type": "object",
365-
"patternProperties": {
364+
"patternGroups": {
366365
"^\\$\\$([^\\.]+)$": {
367-
"$ref": "#"
366+
"schema": {
367+
"$ref": "#"
368+
},
369+
"minimum": 1
368370
}
369371
},
370372
"maxProperties": 1,
371-
"minProperties": 1,
372-
"additionalProperties": false,
373-
"patternRequired": [
374-
"^\\$\\$([^\\.]+)$"
375-
]
373+
"additionalProperties": false
376374
},
377375
"_macro_call_0": {
378376
"id": "#macro_call_0",
379377
"description": "short syntax for function call",
380378
"type": "object",
381-
"patternProperties": {
379+
"patternGroups": {
382380
"^\\$\\#(.+)$": {
383-
"$ref": "#"
381+
"schema": {
382+
"$ref": "#"
383+
},
384+
"minimum": 1
384385
}
385386
},
386387
"maxProperties": 1,
387-
"minProperties": 1,
388-
"additionalProperties": false,
389-
"patternRequired": [
390-
"^\\$\\#(.+)$"
391-
]
388+
"additionalProperties": false
392389
},
393390
"_macro_calc_0": {
394391
"id": "#macro_calc_0",
395392
"description": "short calculations syntax",
396393
"type": "object",
397-
"patternProperties": {
394+
"patternGroups": {
398395
"\\$([+\\-*/=!<>&\\|^]{1,2})": {
399-
"$ref": "#"
396+
"schema": {
397+
"$ref": "#"
398+
},
399+
"minimum": 1
400400
}
401401
},
402402
"maxProperties": 1,
403-
"minProperties": 1,
404-
"additionalProperties": false,
405-
"patternRequired": [
406-
"\\$([+\\-*/=!<>&\\|^]{1,2})"
407-
]
403+
"additionalProperties": false
408404
},
409405
"parallel": {
410406
"id": "#parallel",

0 commit comments

Comments
 (0)
Please sign in to comment.