Skip to content

Commit b1eec20

Browse files
committed
LLM friendly docs: client side JSONata
1 parent 20adc63 commit b1eec20

File tree

7 files changed

+315
-9
lines changed

7 files changed

+315
-9
lines changed

dashjoin-core/src/test/java/org/dashjoin/util/LLMs.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,25 @@ public static void main(String[] args) throws Exception {
3636
b.append("========================\n\n");
3737

3838
for (File f : new File[] {new File("../dashjoin-docs/llms/widget.json"),
39-
new File("../dashjoin-docs/llms/input.json"),
40-
new File("../dashjoin-docs/llms/config.json")}) {
39+
new File("../dashjoin-docs/llms/input.json"), new File("../dashjoin-docs/llms/config.json"),
40+
new File("../dashjoin-docs/llms/jsonata.json")}) {
4141
Map<String, List<Example>> list =
4242
om.readValue(f, new TypeReference<Map<String, List<Example>>>() {});
4343

4444
for (Entry<String, List<Example>> entry : list.entrySet())
4545
for (Example e : entry.getValue()) {
4646
if (e.language == null)
4747
e.language = e.code instanceof String ? "jsonata" : "json";
48-
b.append("TITLE: " + e.title + "\n");
48+
b.append("TITLE: " + (e.title != null ? e.title : entry.getKey()) + "\n");
4949
b.append("DESCRIPTION: " + e.description + "\n");
5050
if (e.file != null)
5151
b.append("FILE: " + e.file + "\n");
5252
b.append("LANGUAGE: " + e.language + "\n");
53-
b.append(
54-
"CODE: " + om.writerWithDefaultPrettyPrinter().writeValueAsString(e.code) + "\n\n");
53+
if (e.code instanceof String)
54+
b.append("CODE: " + e.code + "\n\n");
55+
else
56+
b.append(
57+
"CODE: " + om.writerWithDefaultPrettyPrinter().writeValueAsString(e.code) + "\n\n");
5558
}
5659
}
5760

@@ -60,12 +63,13 @@ public static void main(String[] args) throws Exception {
6063
writeInput();
6164
writeWidget();
6265
writeConfig();
66+
writeJsonata();
6367
}
6468

6569
static void writeInput() throws Exception {
6670
StringBuffer b = new StringBuffer();
6771
b.append("# Appendix: Form Input Types\n");
68-
b.append("These are possible children of the create, edit, button, and variable widgets.");
72+
b.append("These are possible children of the create, edit, button, and variable widgets.\n");
6973
Map<String, List<Example>> list = om.readValue(new File("../dashjoin-docs/llms/input.json"),
7074
new TypeReference<Map<String, List<Example>>>() {});
7175

@@ -88,7 +92,6 @@ static void writeInput() throws Exception {
8892
static void writeConfig() throws Exception {
8993
StringBuffer b = new StringBuffer();
9094
b.append("# Appendix: Databases, Queries, Functions, and Configurations\n");
91-
b.append("These are possible children of the create, edit, button, and variable widgets.");
9295
Map<String, List<Example>> list = om.readValue(new File("../dashjoin-docs/llms/config.json"),
9396
new TypeReference<Map<String, List<Example>>>() {});
9497

@@ -106,6 +109,26 @@ static void writeConfig() throws Exception {
106109
Charset.defaultCharset());
107110
}
108111

112+
static void writeJsonata() throws Exception {
113+
StringBuffer b = new StringBuffer();
114+
b.append("# Appendix: JSONata function library\n");
115+
Map<String, List<Example>> list = om.readValue(new File("../dashjoin-docs/llms/jsonata.json"),
116+
new TypeReference<Map<String, List<Example>>>() {});
117+
118+
for (Entry<String, List<Example>> entry : list.entrySet())
119+
for (Example e : entry.getValue()) {
120+
if (e.language == null)
121+
e.language = e.code instanceof String ? "jsonata" : "json";
122+
b.append("## " + (e.title != null ? e.title : entry.getKey()) + "\n");
123+
b.append(e.description + "\n");
124+
b.append("```\n");
125+
b.append(e.code + "\n```\n");
126+
}
127+
128+
FileUtils.write(new File("../dashjoin-docs/docs/appendix-jsonata.md"), b,
129+
Charset.defaultCharset());
130+
}
131+
109132
@SuppressWarnings("unchecked")
110133
static void writeWidget() throws Exception {
111134
StringBuffer b = new StringBuffer();

dashjoin-docs/docs/appendix-configurations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Appendix: Databases, Queries, Functions, and Configurations
2-
These are possible children of the create, edit, button, and variable widgets.## query catalog
2+
## query catalog
33
a query on database 'dj/northwind' called 'group', executable for the 'authenticated' role
44
```json
55
{

dashjoin-docs/docs/appendix-inputs.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Appendix: Form Input Types
2-
These are possible children of the create, edit, button, and variable widgets.## boolean input
2+
These are possible children of the create, edit, button, and variable widgets.
3+
## boolean input
34
Boolean inputs show a on/off toggle. In this example, the toggle has the label 'Opt in'
45
```json
56
{
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Appendix: JSONata function library
2+
## confirm
3+
displays a confirmation dialog and returns true if the user clicked yes
4+
```
5+
$confirm('Are you sure') ? 'you clicked yes'
6+
```
7+
## setVariable
8+
Sets the browser session variable x to 1. The new value can be read in other places via variable.x
9+
```
10+
$setVariable('x', 1)
11+
```
12+
## prompt
13+
Prompts the user for an input. Returns the input or undefined if the prompt is cancelled
14+
```
15+
(
16+
$name := $prompt('What is your name?');
17+
$name ? ('Hello ' & $name);
18+
)
19+
```
20+
## alert
21+
Shows a model popup with a message
22+
```
23+
$alert('FYI')
24+
```
25+
## dialog
26+
Shows a dialog to enter 'to' and 'text'. If the user submits via 'ok', an object with these fields is returned
27+
```
28+
$dialog({
29+
'title':'Send Message',
30+
'message':'Please enter your message',
31+
'inputs':['to', 'content'],
32+
'buttons':[{'label':'ok', 'type':'submit'},'cancel'],
33+
'options':{'alert':'info'}
34+
})
35+
```
36+
## notify
37+
Shows a message in the snackbar at the bottom of the screen
38+
```
39+
$notify('Hi from the snackbar!')
40+
```
41+
## refresh
42+
refreshes the screen just (just like hitting the refresh icon in the toolbar)
43+
```
44+
$refresh()
45+
```
46+
## reload
47+
reloads the browser page
48+
```
49+
$reload()
50+
```
51+
## navigate
52+
points the browser to the URL
53+
```
54+
$navigate('http://dashjoin.com')
55+
```
56+
## navigate
57+
scrolls the page to the DOM element with the given id. In this case, we scroll to the widget that has the title 'Top'
58+
```
59+
$navigate({'id': 'dj-Top'})
60+
```
61+
## clearCache
62+
clears the HTTP cache - can be used in conjunction with expressions that trigger side effects on the backend
63+
```
64+
$clearCache()
65+
```
66+
## progress
67+
shows a progress indicator with the message 'working...' for 1 second until the expression execution completes
68+
```
69+
(
70+
$progress({'message':'working...'});
71+
$sleep(1000)
72+
)
73+
```
74+
## sleep
75+
sleeps for 1000 milliseconds
76+
```
77+
$sleep(1000)
78+
```
79+
## speak
80+
performs a text to english speech for 'Test'
81+
```
82+
$speak('Test', 'en')
83+
```
84+
## stopSpeech
85+
stops any text to speech that's in progress
86+
```
87+
$stopSpeech()
88+
```
89+
## translate
90+
Lookup the text in the translation file and return the match for the current locale
91+
```
92+
$translate('ra.action.select_all_button')
93+
```

dashjoin-docs/docs/developer-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ These functions can be classified as frontend and backend functions. Frontend fu
10051005
and can be used to trigger a screen popup or to set a browser session variable.
10061006
Backend functions typically access backend data.
10071007
You can mix both kinds in a single JSONata expression tree.
1008+
See [appendix JSONata](appendix-jsonata.md) for examples.
10081009

10091010
### Frontend Expressions
10101011

dashjoin-docs/llms/jsonata.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"confirm": [
3+
{
4+
"description": "displays a confirmation dialog and returns true if the user clicked yes",
5+
"code": "$confirm('Are you sure') ? 'you clicked yes'"
6+
}
7+
],
8+
"setVariable": [
9+
{
10+
"description": "Sets the browser session variable x to 1. The new value can be read in other places via variable.x",
11+
"code": "$setVariable('x', 1)"
12+
}
13+
],
14+
"prompt": [
15+
{
16+
"description": "Prompts the user for an input. Returns the input or undefined if the prompt is cancelled",
17+
"code": "(\n $name := $prompt('What is your name?');\n $name ? ('Hello ' & $name);\n)"
18+
}
19+
],
20+
"alert": [
21+
{
22+
"description": "Shows a model popup with a message",
23+
"code": "$alert('FYI')"
24+
}
25+
],
26+
"dialog": [
27+
{
28+
"description": "Shows a dialog to enter 'to' and 'text'. If the user submits via 'ok', an object with these fields is returned",
29+
"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})"
30+
}
31+
],
32+
"notify": [
33+
{
34+
"description": "Shows a message in the snackbar at the bottom of the screen",
35+
"code": "$notify('Hi from the snackbar!')"
36+
}
37+
],
38+
"refresh": [
39+
{
40+
"description": "refreshes the screen just (just like hitting the refresh icon in the toolbar)",
41+
"code": "$refresh()"
42+
}
43+
],
44+
"reload": [
45+
{
46+
"description": "reloads the browser page",
47+
"code": "$reload()"
48+
}
49+
],
50+
"navigate": [
51+
{
52+
"description": "points the browser to the URL",
53+
"code": "$navigate('http://dashjoin.com')"
54+
},
55+
{
56+
"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'",
57+
"code": "$navigate({'id': 'dj-Top'})"
58+
}
59+
],
60+
"clearCache": [
61+
{
62+
"description": "clears the HTTP cache - can be used in conjunction with expressions that trigger side effects on the backend",
63+
"code": "$clearCache()"
64+
}
65+
],
66+
"progress": [
67+
{
68+
"description": "shows a progress indicator with the message 'working...' for 1 second until the expression execution completes",
69+
"code": "(\n $progress({'message':'working...'});\n $sleep(1000)\n)"
70+
}
71+
],
72+
"sleep": [
73+
{
74+
"description": "sleeps for 1000 milliseconds",
75+
"code": "$sleep(1000)"
76+
}
77+
],
78+
"speak": [
79+
{
80+
"description": "performs a text to english speech for 'Test'",
81+
"code": "$speak('Test', 'en')"
82+
}
83+
],
84+
"stopSpeech": [
85+
{
86+
"description": "stops any text to speech that's in progress",
87+
"code": "$stopSpeech()"
88+
}
89+
],
90+
"translate": [
91+
{
92+
"description": "Lookup the text in the translation file and return the match for the current locale",
93+
"code": "$translate('ra.action.select_all_button')"
94+
}
95+
]
96+
}

llms.txt

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,95 @@ CODE: {
797797
"password" : "DJ1#\btW06MCaBJjnRvgvGgTaTpQ=="
798798
}
799799

800+
TITLE: confirm
801+
DESCRIPTION: displays a confirmation dialog and returns true if the user clicked yes
802+
LANGUAGE: jsonata
803+
CODE: $confirm('Are you sure') ? 'you clicked yes'
804+
805+
TITLE: setVariable
806+
DESCRIPTION: Sets the browser session variable x to 1. The new value can be read in other places via variable.x
807+
LANGUAGE: jsonata
808+
CODE: $setVariable('x', 1)
809+
810+
TITLE: prompt
811+
DESCRIPTION: Prompts the user for an input. Returns the input or undefined if the prompt is cancelled
812+
LANGUAGE: jsonata
813+
CODE: (
814+
$name := $prompt('What is your name?');
815+
$name ? ('Hello ' & $name);
816+
)
817+
818+
TITLE: alert
819+
DESCRIPTION: Shows a model popup with a message
820+
LANGUAGE: jsonata
821+
CODE: $alert('FYI')
822+
823+
TITLE: dialog
824+
DESCRIPTION: Shows a dialog to enter 'to' and 'text'. If the user submits via 'ok', an object with these fields is returned
825+
LANGUAGE: jsonata
826+
CODE: $dialog({
827+
'title':'Send Message',
828+
'message':'Please enter your message',
829+
'inputs':['to', 'content'],
830+
'buttons':[{'label':'ok', 'type':'submit'},'cancel'],
831+
'options':{'alert':'info'}
832+
})
833+
834+
TITLE: notify
835+
DESCRIPTION: Shows a message in the snackbar at the bottom of the screen
836+
LANGUAGE: jsonata
837+
CODE: $notify('Hi from the snackbar!')
838+
839+
TITLE: refresh
840+
DESCRIPTION: refreshes the screen just (just like hitting the refresh icon in the toolbar)
841+
LANGUAGE: jsonata
842+
CODE: $refresh()
843+
844+
TITLE: reload
845+
DESCRIPTION: reloads the browser page
846+
LANGUAGE: jsonata
847+
CODE: $reload()
848+
849+
TITLE: navigate
850+
DESCRIPTION: points the browser to the URL
851+
LANGUAGE: jsonata
852+
CODE: $navigate('http://dashjoin.com')
853+
854+
TITLE: navigate
855+
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'
856+
LANGUAGE: jsonata
857+
CODE: $navigate({'id': 'dj-Top'})
858+
859+
TITLE: clearCache
860+
DESCRIPTION: clears the HTTP cache - can be used in conjunction with expressions that trigger side effects on the backend
861+
LANGUAGE: jsonata
862+
CODE: $clearCache()
863+
864+
TITLE: progress
865+
DESCRIPTION: shows a progress indicator with the message 'working...' for 1 second until the expression execution completes
866+
LANGUAGE: jsonata
867+
CODE: (
868+
$progress({'message':'working...'});
869+
$sleep(1000)
870+
)
871+
872+
TITLE: sleep
873+
DESCRIPTION: sleeps for 1000 milliseconds
874+
LANGUAGE: jsonata
875+
CODE: $sleep(1000)
876+
877+
TITLE: speak
878+
DESCRIPTION: performs a text to english speech for 'Test'
879+
LANGUAGE: jsonata
880+
CODE: $speak('Test', 'en')
881+
882+
TITLE: stopSpeech
883+
DESCRIPTION: stops any text to speech that's in progress
884+
LANGUAGE: jsonata
885+
CODE: $stopSpeech()
886+
887+
TITLE: translate
888+
DESCRIPTION: Lookup the text in the translation file and return the match for the current locale
889+
LANGUAGE: jsonata
890+
CODE: $translate('ra.action.select_all_button')
891+

0 commit comments

Comments
 (0)