Skip to content

Commit f1b028c

Browse files
committed
updated docs, schema
1 parent cb2f9d7 commit f1b028c

File tree

8 files changed

+103
-1206
lines changed

8 files changed

+103
-1206
lines changed

Diff for: 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`.

0 commit comments

Comments
 (0)