Skip to content

Commit 2009922

Browse files
committed
$wait is server-side, $sleep is client-side #484
1 parent 0beee9d commit 2009922

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

dashjoin-docs/docs/appendix-jsonata.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,3 +842,12 @@ Sample output:
842842
"version" : 2
843843
} ]
844844
```
845+
## wait
846+
Waits before returning the parameter (server-side equivalent of $sleep)
847+
```
848+
$wait('delayed by 1 second', 1000)
849+
```
850+
Sample output:
851+
```json
852+
"delayed by 1 second"
853+
```

dashjoin-docs/docs/faq.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ $call("openai", {
168168
)
169169
```
170170

171-
* **I need to ETL from an API that has a rate limit. How can I throttle my requests?** You can use the sleep function in your JSONata expression:
172-
Let's assume $openJson(url) is called on several array elements. Simply change it to ($openJson(x); $sleep(1000)) to introduce a 1 second delay after each call.
171+
* **I need to ETL from an API that has a rate limit. How can I throttle my requests?** You can use the wait function in your JSONata expression (server-side equivalent of sleep): Let's assume $openJson(url) is called on several array elements. Simply change it to $wait($openJson(x), 1000) to introduce a 1 second delay after each call.
173172

174173
* **How can I realize an audit log that keeps track of all changes to a table?** You can define a triggers for create, update, and delete operations on the table that must be audited. Create an audit log table with the following columns: autoincrementing ID, user, timestamp, operation, and payload. The trigger `$create("db", "audit", {"timestamp": $now(), "user": user, "operation": "update", "payload": $})` will log changes to the table.
175174

dashjoin-docs/llms/jsonata.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
{
22
"confirm": [
33
{
4+
"client": true,
45
"description": "displays a confirmation dialog and returns true if the user clicked yes",
56
"code": "$confirm('Are you sure') ? 'you clicked yes'",
67
"output": true
78
}
89
],
910
"setVariable": [
1011
{
12+
"client": true,
1113
"description": "Sets the browser session variable x to 1. The new value can be read in other places via variable.x",
1214
"code": "$setVariable('x', 1)"
1315
}
1416
],
1517
"prompt": [
1618
{
19+
"client": true,
1720
"description": "Prompts the user for an input. Returns the input or undefined if the prompt is cancelled",
1821
"code": "(\n $name := $prompt('What is your name?');\n $name ? ('Hello ' & $name);\n)",
1922
"output": "Joe"
2023
}
2124
],
2225
"alert": [
2326
{
27+
"client": true,
2428
"description": "Shows a model popup with a message",
2529
"code": "$alert('FYI')",
2630
"output": "OK"
2731
}
2832
],
2933
"dialog": [
3034
{
35+
"client": true,
3136
"description": "Shows a dialog to enter 'to' and 'text'. If the user submits via 'ok', an object with these fields is returned",
3237
"code": "$dialog({\n 'title':'Send Message', \n 'message':'Please enter your message', \n 'inputs':['to', 'content'], \n 'buttons':[{'label':'ok', 'type':'submit'},'cancel'], \n 'options':{'alert':'info'}\n})",
3338
"oputput": {
@@ -38,64 +43,75 @@
3843
],
3944
"notify": [
4045
{
46+
"client": true,
4147
"description": "Shows a message in the snackbar at the bottom of the screen",
4248
"code": "$notify('Hi from the snackbar!')"
4349
}
4450
],
4551
"refresh": [
4652
{
53+
"client": true,
4754
"description": "refreshes the screen just (just like hitting the refresh icon in the toolbar)",
4855
"code": "$refresh()"
4956
}
5057
],
5158
"reload": [
5259
{
60+
"client": true,
5361
"description": "reloads the browser page",
5462
"code": "$reload()"
5563
}
5664
],
5765
"navigate": [
5866
{
67+
"client": true,
5968
"description": "points the browser to the URL",
6069
"code": "$navigate('http://dashjoin.com')"
6170
},
6271
{
72+
"client": true,
6373
"description": "scrolls the page to the DOM element with the given id. In this case, we scroll to the widget that has the title 'Top'",
6474
"code": "$navigate({'id': 'dj-Top'})"
6575
}
6676
],
6777
"clearCache": [
6878
{
79+
"client": true,
6980
"description": "clears the HTTP cache - can be used in conjunction with expressions that trigger side effects on the backend",
7081
"code": "$clearCache()"
7182
}
7283
],
7384
"progress": [
7485
{
86+
"client": true,
7587
"description": "shows a progress indicator with the message 'working...' for 1 second until the expression execution completes",
7688
"code": "(\n $progress({'message':'working...'});\n $sleep(1000)\n)"
7789
}
7890
],
7991
"sleep": [
8092
{
93+
"client": true,
8194
"description": "sleeps for 1000 milliseconds",
8295
"code": "$sleep(1000)"
8396
}
8497
],
8598
"speak": [
8699
{
100+
"client": true,
87101
"description": "performs a text to english speech for 'Test'",
88102
"code": "$speak('Test', 'en')"
89103
}
90104
],
91105
"stopSpeech": [
92106
{
107+
"client": true,
93108
"description": "stops any text to speech that's in progress",
94109
"code": "$stopSpeech()"
95110
}
96111
],
97112
"translate": [
98113
{
114+
"client": true,
99115
"description": "Lookup the text in the translation file and return the match for the current locale",
100116
"code": "$translate('ra.action.select_all_button')",
101117
"output": "Select all"
@@ -707,5 +723,12 @@
707723
}
708724
]
709725
}
726+
],
727+
"wait": [
728+
{
729+
"description": "Waits before returning the parameter (server-side equivalent of $sleep)",
730+
"code": "$wait('delayed by 1 second', 1000)",
731+
"output": "delayed by 1 second"
732+
}
710733
]
711734
}

llms.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,3 +1589,8 @@ DESCRIPTION: Compares two tables with URL / file information to determine which
15891589
LANGUAGE: jsonata
15901590
CODE: $etlSync([{'url':'file:a', 'version': 2}], [{'url':'file:a', 'version': 1}], 'url')
15911591

1592+
TITLE: wait
1593+
DESCRIPTION: Waits before returning the parameter (server-side equivalent of $sleep)
1594+
LANGUAGE: jsonata
1595+
CODE: $wait('delayed by 1 second', 1000)
1596+

0 commit comments

Comments
 (0)