pico-engine 1.9.3 → 1.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/demos/bootstrap/README.md +12 -0
- package/demos/bootstrap/com.example.visitors.bootstrap.krl +97 -0
- package/demos/bootstrap/com.example.visitors.format.krl +25 -0
- package/demos/bootstrap/com.example.visitors.krl +228 -0
- package/demos/bootstrap/try-it.md +5 -0
- package/demos/child_tasks/README.md +12 -0
- package/demos/child_tasks/com.example.task_runner.bootstrap.krl +85 -0
- package/demos/child_tasks/com.example.task_runner.krl +139 -0
- package/demos/child_tasks/com.example.task_worker.krl +45 -0
- package/demos/child_tasks/try-it.md +5 -0
- package/demos/collection/README.md +13 -0
- package/demos/collection/com.example.collection.bootstrap.krl +148 -0
- package/demos/collection/com.example.collection.krl +95 -0
- package/demos/collection/com.example.collection.report.krl +93 -0
- package/demos/collection/com.example.collection.room.krl +101 -0
- package/demos/collection/try-it.md +6 -0
- package/demos/echo/README.md +11 -0
- package/demos/echo/com.example.echo.bootstrap.krl +81 -0
- package/demos/echo/com.example.echo.krl +73 -0
- package/demos/echo/try-it.md +5 -0
- package/demos/guard_rules/README.md +12 -0
- package/demos/guard_rules/com.example.archive.bootstrap.krl +95 -0
- package/demos/guard_rules/com.example.archive.krl +213 -0
- package/demos/guard_rules/com.example.archive_store.krl +36 -0
- package/demos/guard_rules/try-it.md +5 -0
- package/demos/kblog/README.md +14 -0
- package/demos/kblog/com.example.kblog.bootstrap.krl +132 -0
- package/demos/kblog/com.example.kblog.config.krl +50 -0
- package/demos/kblog/com.example.kblog.data.krl +75 -0
- package/demos/kblog/com.example.kblog.krl +184 -0
- package/demos/kblog/com.example.kblog.posting.krl +109 -0
- package/demos/kblog/try-it.md +6 -0
- package/demos/layered_rulesets/README.md +13 -0
- package/demos/layered_rulesets/com.example.invitations.bootstrap.krl +84 -0
- package/demos/layered_rulesets/com.example.invitations.krl +164 -0
- package/demos/layered_rulesets/com.example.invitations.short_links.krl +45 -0
- package/demos/layered_rulesets/com.example.invitations.welcome.krl +39 -0
- package/demos/layered_rulesets/try-it.md +5 -0
- package/demos/moving_picos/README.md +15 -0
- package/demos/moving_picos/io.picolabs.club_gear_demo.krl +650 -0
- package/demos/moving_picos/io.picolabs.ride_coordinator_demo.krl +331 -0
- package/demos/score_tracker/README.md +11 -0
- package/demos/score_tracker/com.example.score_tracker.bootstrap.krl +104 -0
- package/demos/score_tracker/com.example.score_tracker.krl +162 -0
- package/demos/score_tracker/try-it.md +5 -0
- package/demos/secrets/README.md +12 -0
- package/demos/secrets/com.example.hook_service.krl +120 -0
- package/demos/secrets/com.example.notifier.bootstrap.krl +127 -0
- package/demos/secrets/com.example.notifier.krl +138 -0
- package/demos/secrets/try-it.md +5 -0
- package/demos/try-it-order.json +1 -0
- package/demos/two_picos/README.md +12 -0
- package/demos/two_picos/com.example.two_picos.answerer.krl +125 -0
- package/demos/two_picos/com.example.two_picos.asker.krl +124 -0
- package/demos/two_picos/com.example.two_picos.bootstrap.krl +131 -0
- package/demos/two_picos/try-it.md +5 -0
- package/demos/xmlui/README.md +17 -0
- package/demos/xmlui/com.example.contacts.krl +132 -0
- package/demos/xmlui/com.example.fav_color.krl +39 -0
- package/demos/xmlui/com.example.guestbook.krl +61 -0
- package/demos/xmlui/com.example.hello.krl +19 -0
- package/demos/xmlui/com.example.temperature_sensors_view.krl +105 -0
- package/demos/xmlui/com.example.thermostat.bootstrap.krl +92 -0
- package/demos/xmlui/com.example.thermostat.krl +124 -0
- package/demos/xmlui/temperature_sensors.krl +56 -0
- package/demos/xmlui/try-it.md +5 -0
- package/dist/bundledKrl.js +97 -12
- package/dist/cli.js +2 -0
- package/dist/engineConfig.js +19 -0
- package/dist/index.js +1 -0
- package/dist/server.js +18 -4
- package/dist/xmluiRuntime.js +28 -9
- package/krl/io.picolabs.xmlui.krl +149 -1
- package/mcp/docs/CLAUDE.md +3 -2
- package/mcp/docs/pico-engine.md +3 -0
- package/package.json +9 -6
- package/public/.DS_Store +0 -0
- package/public/pico-engine-ui.css +1 -1
- package/public/pico-engine-ui.js +23 -22
- package/src/bundledKrl.ts +118 -12
- package/src/cli.ts +2 -0
- package/src/engineConfig.ts +28 -0
- package/src/index.ts +8 -0
- package/src/server.ts +20 -5
- package/src/xmluiRuntime.ts +32 -9
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
ruleset com.example.thermostat {
|
|
2
|
+
meta {
|
|
3
|
+
name "Thermostat"
|
|
4
|
+
use module io.picolabs.xmlui alias ui
|
|
5
|
+
shares readings, threshold, dashboard, settings, readingHistory
|
|
6
|
+
}
|
|
7
|
+
global {
|
|
8
|
+
/**
|
|
9
|
+
* Recent readings, newest first (updates after thermostat new_reading).
|
|
10
|
+
* @returns Array
|
|
11
|
+
* @example "history" {}
|
|
12
|
+
*/
|
|
13
|
+
readings = function() {
|
|
14
|
+
ent:readings.defaultsTo([]).reverse()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Alert threshold in degrees F
|
|
19
|
+
* @returns Number
|
|
20
|
+
* @example "default" {}
|
|
21
|
+
*/
|
|
22
|
+
threshold = function() {
|
|
23
|
+
ent:threshold.defaultsTo(80)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Readings as a table. Props: rows (Array of { time, temperature }).
|
|
28
|
+
* @component
|
|
29
|
+
*/
|
|
30
|
+
readingHistory = function() {
|
|
31
|
+
<<
|
|
32
|
+
<Component name="ReadingHistory">
|
|
33
|
+
<Table data="{$props.rows}">
|
|
34
|
+
<Column bindTo="time" header="Time" />
|
|
35
|
+
<Column bindTo="temperature" header="Temperature (F)" />
|
|
36
|
+
</Table>
|
|
37
|
+
</Component>
|
|
38
|
+
>>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Current temperature and history. Display picks the theme, using the
|
|
43
|
+
* shared PicoSettings, PicoThemeField, and PicoTheme components.
|
|
44
|
+
* @view "Dashboard"
|
|
45
|
+
*/
|
|
46
|
+
dashboard = function() {
|
|
47
|
+
<<
|
|
48
|
+
<Component name="Dashboard">
|
|
49
|
+
#{ui:query("readings", "readings", {"rid": meta:rid})}
|
|
50
|
+
#{ui:query("threshold", "threshold", {"rid": meta:rid})}
|
|
51
|
+
<PicoSettings id="display" title="Display">
|
|
52
|
+
<PicoThemeField />
|
|
53
|
+
</PicoSettings>
|
|
54
|
+
<PicoTheme>
|
|
55
|
+
<HStack horizontalAlignment="end">
|
|
56
|
+
<Button label="Display" onClick="display.open()" />
|
|
57
|
+
</HStack>
|
|
58
|
+
<Card title="Now: {readings.value[0].temperature} F"
|
|
59
|
+
subtitle="Alert above {threshold.value} F" />
|
|
60
|
+
<ReadingHistory rows="{readings}" />
|
|
61
|
+
</PicoTheme>
|
|
62
|
+
</Component>
|
|
63
|
+
>>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Change the alert threshold
|
|
68
|
+
* @view "Settings"
|
|
69
|
+
*/
|
|
70
|
+
settings = function() {
|
|
71
|
+
<<
|
|
72
|
+
<Component name="Settings">
|
|
73
|
+
#{ui:query("threshold", "threshold", {"rid": meta:rid})}
|
|
74
|
+
#{ui:event("setThreshold", "thermostat", "threshold_set",
|
|
75
|
+
{"rid": meta:rid, "refresh": ["threshold"], "confirm": "Change the alert threshold?"})}
|
|
76
|
+
<Form data="{{ threshold: threshold.value }}"
|
|
77
|
+
onSubmit="(toSave) => setThreshold.execute(toSave)">
|
|
78
|
+
<FormItem bindTo="threshold" label="Alert above (F)" type="integer" />
|
|
79
|
+
</Form>
|
|
80
|
+
</Component>
|
|
81
|
+
>>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
viewer_tags = ["thermostat", "viewer"]
|
|
85
|
+
admin_tags = ["thermostat", "admin"]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Record a temperature reading (shown on the Dashboard view).
|
|
90
|
+
* @attr temperature Number Degrees Fahrenheit
|
|
91
|
+
* @example "room temperature" { "temperature": "72" }
|
|
92
|
+
* @example "warm alert" { "temperature": "85" }
|
|
93
|
+
*/
|
|
94
|
+
rule record_reading {
|
|
95
|
+
select when thermostat new_reading
|
|
96
|
+
temperature re#(.+)# setting(temperature)
|
|
97
|
+
fired {
|
|
98
|
+
ent:readings := ent:readings.defaultsTo([])
|
|
99
|
+
.append({"temperature": temperature.as("Number"), "time": time:now()})
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Set the alert threshold (same as the Settings view form).
|
|
105
|
+
* @attr threshold Number Degrees Fahrenheit
|
|
106
|
+
* @example "alert at 80 F" { "threshold": "80" }
|
|
107
|
+
* @example "alert at 75 F" { "threshold": "75" }
|
|
108
|
+
*/
|
|
109
|
+
rule set_threshold {
|
|
110
|
+
select when thermostat threshold_set
|
|
111
|
+
threshold re#^(\d+)$# setting(threshold)
|
|
112
|
+
fired {
|
|
113
|
+
ent:threshold := threshold.as("Number")
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
rule create_app_channels {
|
|
118
|
+
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
|
|
119
|
+
every {
|
|
120
|
+
ui:create_app_channel(viewer_tags, [], ["readings", "threshold", "dashboard"], meta:rid)
|
|
121
|
+
ui:create_app_channel(admin_tags, ["thermostat"], null, meta:rid)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo data ruleset: `latestReadings` returns a fixed array (no `picoQuery`).
|
|
3
|
+
* Install on the **data** pico. The view demo (`com.example.temperature_sensors_view`)
|
|
4
|
+
* queries this ruleset over a relationship/subscription Tx (`wrangler:picoQuery`).
|
|
5
|
+
*
|
|
6
|
+
* Shape per row: `name`, `lastTemperature`, `readingAt`, `timestamp`.
|
|
7
|
+
*/
|
|
8
|
+
ruleset com.example.temperature_sensors {
|
|
9
|
+
meta {
|
|
10
|
+
name "Temperature sensors (static demo)"
|
|
11
|
+
description "Static sample readings for XMLUI demos"
|
|
12
|
+
provides latestReadings
|
|
13
|
+
shares latestReadings
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
global {
|
|
17
|
+
/**
|
|
18
|
+
* Fixed sample readings (replace with real data or `ent:` when you are ready).
|
|
19
|
+
* @returns Array
|
|
20
|
+
*/
|
|
21
|
+
latestReadings = function() {
|
|
22
|
+
[
|
|
23
|
+
{
|
|
24
|
+
"name": "Sensors:Beehive",
|
|
25
|
+
"lastTemperature": 51.47,
|
|
26
|
+
"readingAt": "2026-11-06 19:11:14 Coordinated Universal Time",
|
|
27
|
+
"timestamp": 1793992274126
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "Sensors:Cabin Crawl Space",
|
|
31
|
+
"lastTemperature": 55.4,
|
|
32
|
+
"readingAt": "2026-11-06 19:01:48 Coordinated Universal Time",
|
|
33
|
+
"timestamp": 1793991708383
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "Sensors:Cabin North Side",
|
|
37
|
+
"lastTemperature": 38.46,
|
|
38
|
+
"readingAt": "2026-11-06 18:59:45 Coordinated Universal Time",
|
|
39
|
+
"timestamp": 1793991585382
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "Sensors:Pump House",
|
|
43
|
+
"lastTemperature": 51.15,
|
|
44
|
+
"readingAt": "2026-11-06 19:01:24 Coordinated Universal Time",
|
|
45
|
+
"timestamp": 1793991684238
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"name": "Sensors:Triple Temp",
|
|
49
|
+
"lastTemperature": 51.08,
|
|
50
|
+
"readingAt": "2026-11-06 19:11:54 Coordinated Universal Time",
|
|
51
|
+
"timestamp": 1793992314892
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
- Open both dashboard links. On the viewer channel the navigation has only Dashboard. On the admin channel it also has Settings.
|
|
2
|
+
- On **Settings**, change the alert threshold, then go back to the Dashboard.
|
|
3
|
+
- Click **Display** on the Dashboard. The theme picker is built from the shared `PicoSettings` and `PicoThemeField` components. The readings table is the ruleset's own `ReadingHistory` component.
|
|
4
|
+
- Open the child pico's **Channels** tab and compare the query policies of `thermostat, viewer` and `thermostat, admin`. That policy is the whole difference between the two views.
|
|
5
|
+
- On the **Testing** tab, raise `thermostat` `new_reading` with a `temperature`, and reload the dashboard.
|
package/dist/bundledKrl.js
CHANGED
|
@@ -7,7 +7,9 @@ exports.engineKrlHttpPath = engineKrlHttpPath;
|
|
|
7
7
|
exports.engineKrlFileUrl = engineKrlFileUrl;
|
|
8
8
|
exports.listEngineKrlSources = listEngineKrlSources;
|
|
9
9
|
exports.engineKrlRelativeFromUrl = engineKrlRelativeFromUrl;
|
|
10
|
+
exports.demosDir = demosDir;
|
|
10
11
|
exports.resolveEngineKrlFile = resolveEngineKrlFile;
|
|
12
|
+
exports.listTryItDemos = listTryItDemos;
|
|
11
13
|
exports.resolveBundledKrlUrl = resolveBundledKrlUrl;
|
|
12
14
|
const fs = require("fs");
|
|
13
15
|
const path = require("path");
|
|
@@ -126,27 +128,110 @@ function engineKrlRelativeFromUrl(url) {
|
|
|
126
128
|
}
|
|
127
129
|
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
|
128
130
|
const match = parsed.pathname.match(/^\/krl\/(.+\.krl)$/);
|
|
129
|
-
if (match) {
|
|
130
|
-
|
|
131
|
-
const candidate = path.join(bundledKrlDir(), relativePath);
|
|
132
|
-
if (fs.existsSync(candidate)) {
|
|
133
|
-
return match[1];
|
|
134
|
-
}
|
|
131
|
+
if (match && resolveEngineKrlFile(match[1])) {
|
|
132
|
+
return match[1];
|
|
135
133
|
}
|
|
136
134
|
}
|
|
137
135
|
return null;
|
|
138
136
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
/**
|
|
138
|
+
* The demos/ directory: PICO_ENGINE_DEMOS_DIR when set (a copy someone edits
|
|
139
|
+
* and keeps across upgrades), else inside the package when installed from npm
|
|
140
|
+
* (copied at pack time), else the repository root in a checkout.
|
|
141
|
+
*/
|
|
142
|
+
function demosDir() {
|
|
143
|
+
const override = process.env.PICO_ENGINE_DEMOS_DIR;
|
|
144
|
+
const candidates = [
|
|
145
|
+
...(override && override.trim() ? [path.resolve(override.trim())] : []),
|
|
146
|
+
path.resolve(__dirname, "..", "demos"),
|
|
147
|
+
path.resolve(__dirname, "..", "..", "..", "demos"),
|
|
148
|
+
];
|
|
149
|
+
for (const dir of candidates) {
|
|
150
|
+
if (fs.existsSync(dir) && fs.statSync(dir).isDirectory())
|
|
151
|
+
return dir;
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
function fileWithin(root, relativePath) {
|
|
156
|
+
const candidate = path.resolve(root, relativePath.split("/").join(path.sep));
|
|
143
157
|
if (candidate.startsWith(root + path.sep) &&
|
|
144
|
-
|
|
145
|
-
|
|
158
|
+
candidate.endsWith(".krl") &&
|
|
159
|
+
fs.existsSync(candidate)) {
|
|
146
160
|
return candidate;
|
|
147
161
|
}
|
|
148
162
|
return null;
|
|
149
163
|
}
|
|
164
|
+
/** `relativePath` is under krl/, or under demos/ when it starts with `demos/`. */
|
|
165
|
+
function resolveEngineKrlFile(relativePath) {
|
|
166
|
+
if (relativePath.startsWith("demos/")) {
|
|
167
|
+
const root = demosDir();
|
|
168
|
+
return root ? fileWithin(root, relativePath.slice("demos/".length)) : null;
|
|
169
|
+
}
|
|
170
|
+
return fileWithin(bundledKrlDir(), relativePath);
|
|
171
|
+
}
|
|
172
|
+
function readNotes(root, folder) {
|
|
173
|
+
try {
|
|
174
|
+
return fs.readFileSync(path.join(root, folder, "try-it.md"), "utf8");
|
|
175
|
+
}
|
|
176
|
+
catch (_a) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** Folder names from demos/try-it-order.json (a JSON array), or none if it is missing or invalid. */
|
|
181
|
+
function tryItOrder(root) {
|
|
182
|
+
try {
|
|
183
|
+
const order = JSON.parse(fs.readFileSync(path.join(root, "try-it-order.json"), "utf8"));
|
|
184
|
+
return Array.isArray(order) ? order.filter((f) => typeof f === "string") : [];
|
|
185
|
+
}
|
|
186
|
+
catch (_a) {
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Every demos/<folder>/<rid>.bootstrap.krl, for the developer UI's "Try It!" tab.
|
|
192
|
+
* Folders named in demos/try-it-order.json come first, in that order; the rest follow by path.
|
|
193
|
+
*/
|
|
194
|
+
function listTryItDemos(baseUrl) {
|
|
195
|
+
const root = demosDir();
|
|
196
|
+
if (!root)
|
|
197
|
+
return [];
|
|
198
|
+
const files = [];
|
|
199
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
200
|
+
if (!entry.isDirectory() || entry.name.startsWith("."))
|
|
201
|
+
continue;
|
|
202
|
+
walkKrlFiles(path.join(root, entry.name), root, files);
|
|
203
|
+
}
|
|
204
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
205
|
+
const fileInfo = (rel) => ({
|
|
206
|
+
rid: readKrlMeta(path.join(root, rel)).rid,
|
|
207
|
+
file: path.basename(rel),
|
|
208
|
+
url: `${base}/krl/demos/${rel}`,
|
|
209
|
+
path: path.join(root, rel),
|
|
210
|
+
});
|
|
211
|
+
const order = tryItOrder(root);
|
|
212
|
+
const rank = (rel) => {
|
|
213
|
+
const i = order.indexOf(rel.split("/")[0]);
|
|
214
|
+
return i < 0 ? order.length : i;
|
|
215
|
+
};
|
|
216
|
+
return files
|
|
217
|
+
.filter((rel) => rel.endsWith(".bootstrap.krl"))
|
|
218
|
+
.sort((a, b) => rank(a) - rank(b) || (a < b ? -1 : a > b ? 1 : 0))
|
|
219
|
+
.map((rel) => {
|
|
220
|
+
const meta = readKrlMeta(path.join(root, rel));
|
|
221
|
+
const folder = rel.split("/")[0];
|
|
222
|
+
return {
|
|
223
|
+
rid: meta.rid,
|
|
224
|
+
name: meta.name,
|
|
225
|
+
description: meta.description,
|
|
226
|
+
folder,
|
|
227
|
+
url: `${base}/krl/demos/${rel}`,
|
|
228
|
+
path: path.join(root, rel),
|
|
229
|
+
docs: `https://docs.picolabs.io/#/cookbook/${folder}/`,
|
|
230
|
+
notes: readNotes(root, folder),
|
|
231
|
+
files: files.filter((f) => f.split("/")[0] === folder).sort().map(fileInfo),
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
}
|
|
150
235
|
function resolveBundledKrlUrl(url) {
|
|
151
236
|
const relativePath = engineKrlRelativeFromUrl(url);
|
|
152
237
|
if (!relativePath) {
|
package/dist/cli.js
CHANGED
|
@@ -75,6 +75,8 @@ Environment (optional; Docker/CI when not set in config file):
|
|
|
75
75
|
PICO_ENGINE_LOG_FILE - Log path, or stdout/- / 0 for console-only
|
|
76
76
|
PICO_ENGINE_LOG_MIRROR - "true"/"1" or "false"/"0" (mirror JSON lines to \$PICO_ENGINE_HOME/pico-engine.log when stdout-only; default on)
|
|
77
77
|
PICO_ENGINE_LOG_RING - how many recent transactions per pico the Logging tab keeps in memory (default 200; cleared on restart)
|
|
78
|
+
PICO_ENGINE_SHOW_TRYIT_MENU - off, root_only (default), or all: where the Developer UI shows the Try It! tab (config: show_tryit_menu)
|
|
79
|
+
PICO_ENGINE_DEMOS_DIR - directory to serve as demos/ (/krl/demos/) instead of the shipped copy
|
|
78
80
|
`);
|
|
79
81
|
process.exit(0);
|
|
80
82
|
}
|
package/dist/engineConfig.js
CHANGED
|
@@ -14,6 +14,15 @@ const os = require("os");
|
|
|
14
14
|
const path = require("path");
|
|
15
15
|
const policyConfigFromJson_1 = require("./policyConfigFromJson");
|
|
16
16
|
const homeDir = require("home-dir");
|
|
17
|
+
const SHOW_TRY_IT_MENU_VALUES = ["off", "root_only", "all"];
|
|
18
|
+
function parseShowTryItMenu(val, source) {
|
|
19
|
+
if (val === undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (typeof val === "string" && SHOW_TRY_IT_MENU_VALUES.includes(val)) {
|
|
22
|
+
return val;
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`${source} must be one of ${SHOW_TRY_IT_MENU_VALUES.join(", ")} (got ${JSON.stringify(val)})`);
|
|
25
|
+
}
|
|
17
26
|
let runtimeSettings = null;
|
|
18
27
|
function installEngineRuntimeSettings(settings) {
|
|
19
28
|
runtimeSettings = settings;
|
|
@@ -34,6 +43,7 @@ function defaultEngineSettings() {
|
|
|
34
43
|
wildcardSkyRequireBearer: false,
|
|
35
44
|
logToStdout: false,
|
|
36
45
|
logMirror: true,
|
|
46
|
+
showTryItMenu: "root_only",
|
|
37
47
|
};
|
|
38
48
|
}
|
|
39
49
|
function defaultEngineConfigFilePath() {
|
|
@@ -146,6 +156,9 @@ function parseConfigFile(raw) {
|
|
|
146
156
|
out.logFile = path.resolve(expandHome(o.logFile));
|
|
147
157
|
}
|
|
148
158
|
}
|
|
159
|
+
const showTryItMenu = parseShowTryItMenu(o.show_tryit_menu, "show_tryit_menu");
|
|
160
|
+
if (showTryItMenu)
|
|
161
|
+
out.showTryItMenu = showTryItMenu;
|
|
149
162
|
const rootCeiling = (0, policyConfigFromJson_1.parsePolicyCeilingFromJson)(o.defaultRootPolicyCeiling, "defaultRootPolicyCeiling");
|
|
150
163
|
if (rootCeiling) {
|
|
151
164
|
out.defaultRootPolicyCeiling = rootCeiling;
|
|
@@ -227,6 +240,9 @@ function settingsFromEnv() {
|
|
|
227
240
|
if (logMirror !== undefined) {
|
|
228
241
|
out.logMirror = logMirror;
|
|
229
242
|
}
|
|
243
|
+
const showTryItMenu = parseShowTryItMenu(process.env.PICO_ENGINE_SHOW_TRYIT_MENU || undefined, "PICO_ENGINE_SHOW_TRYIT_MENU");
|
|
244
|
+
if (showTryItMenu)
|
|
245
|
+
out.showTryItMenu = showTryItMenu;
|
|
230
246
|
return out;
|
|
231
247
|
}
|
|
232
248
|
function mergeSettings(base, ...layers) {
|
|
@@ -277,6 +293,9 @@ function resolveEngineSettings(programmatic = {}) {
|
|
|
277
293
|
if (programmatic.logMirror !== undefined) {
|
|
278
294
|
fromProgrammatic.logMirror = programmatic.logMirror;
|
|
279
295
|
}
|
|
296
|
+
if (programmatic.showTryItMenu !== undefined) {
|
|
297
|
+
fromProgrammatic.showTryItMenu = programmatic.showTryItMenu;
|
|
298
|
+
}
|
|
280
299
|
if (programmatic.defaultRootPolicyCeiling !== undefined) {
|
|
281
300
|
fromProgrammatic.defaultRootPolicyCeiling =
|
|
282
301
|
programmatic.defaultRootPolicyCeiling;
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ async function startEngine(configuration = {}) {
|
|
|
45
45
|
rpName: configuration.rpName,
|
|
46
46
|
origin: configuration.origin,
|
|
47
47
|
allowSelfSignup: configuration.allowSelfSignup,
|
|
48
|
+
showTryItMenu: configuration.showTryItMenu,
|
|
48
49
|
defaultRootPolicyCeiling: configuration.defaultRootPolicyCeiling,
|
|
49
50
|
globalEventDeny: configuration.globalEventDeny,
|
|
50
51
|
globalQueryDeny: configuration.globalQueryDeny,
|
package/dist/server.js
CHANGED
|
@@ -302,6 +302,19 @@ function server(core, uiECI, auth, oauth, identity) {
|
|
|
302
302
|
next(err);
|
|
303
303
|
}
|
|
304
304
|
});
|
|
305
|
+
app.get("/api/try-it", function (req, res, next) {
|
|
306
|
+
try {
|
|
307
|
+
let baseUrl = core.base_url;
|
|
308
|
+
if (!baseUrl) {
|
|
309
|
+
baseUrl = `${req.protocol}://${req.get("host") || "localhost"}`;
|
|
310
|
+
}
|
|
311
|
+
const show = (0, engineConfig_1.getEngineRuntimeSettings)().showTryItMenu;
|
|
312
|
+
res.json({ show, demos: show === "off" ? [] : (0, bundledKrl_1.listTryItDemos)(baseUrl) });
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
next(err);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
305
318
|
app.post("/api/stage-krl", function (req, res, next) {
|
|
306
319
|
var _a, _b;
|
|
307
320
|
try {
|
|
@@ -344,6 +357,7 @@ function server(core, uiECI, auth, oauth, identity) {
|
|
|
344
357
|
version: engineVersion,
|
|
345
358
|
hasRoots,
|
|
346
359
|
allowSelfSignup: auth ? auth.allowSelfSignup() : false,
|
|
360
|
+
showTryItMenu: (0, engineConfig_1.getEngineRuntimeSettings)().showTryItMenu,
|
|
347
361
|
};
|
|
348
362
|
if (!auth) {
|
|
349
363
|
base.eci = uiECI;
|
|
@@ -635,15 +649,15 @@ function server(core, uiECI, auth, oauth, identity) {
|
|
|
635
649
|
if (componentName) {
|
|
636
650
|
const { pico } = pf.lookupChannel(eci);
|
|
637
651
|
const channelSchema = (0, pico_engine_core_2.channelSchemaForEci)(pico, core.rsRegistry, (channelEci) => pf.lookupChannel(channelEci), eci);
|
|
638
|
-
const
|
|
639
|
-
if (!
|
|
652
|
+
const source = (0, xmluiRuntime_1.queryForComponentFile)(channelSchema.queries, appRid, componentName);
|
|
653
|
+
if (!source) {
|
|
640
654
|
res.status(404).type("text/plain").end("Not found");
|
|
641
655
|
return;
|
|
642
656
|
}
|
|
643
657
|
data = await core.query({
|
|
644
658
|
eci,
|
|
645
|
-
rid:
|
|
646
|
-
name:
|
|
659
|
+
rid: source.rid,
|
|
660
|
+
name: source.name,
|
|
647
661
|
args: {},
|
|
648
662
|
});
|
|
649
663
|
}
|
package/dist/xmluiRuntime.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XMLUI_EMPTY_CODE_BEHIND = exports.XMLUI_RUNTIME_PUBLIC_PATH = exports.XMLUI_RUNTIME_VERSION = void 0;
|
|
3
|
+
exports.XMLUI_RID = exports.XMLUI_EMPTY_CODE_BEHIND = exports.XMLUI_RUNTIME_PUBLIC_PATH = exports.XMLUI_RUNTIME_VERSION = void 0;
|
|
4
|
+
exports.isXmluiBuiltin = isXmluiBuiltin;
|
|
4
5
|
exports.isXmluiCodeBehindPath = isXmluiCodeBehindPath;
|
|
5
6
|
exports.viewComponentFileName = viewComponentFileName;
|
|
6
7
|
exports.parseComponentXmluiPath = parseComponentXmluiPath;
|
|
7
8
|
exports.isXmluiSpaClientRoute = isXmluiSpaClientRoute;
|
|
8
|
-
exports.
|
|
9
|
+
exports.queryForComponentFile = queryForComponentFile;
|
|
9
10
|
exports.contentTypeForUiPath = contentTypeForUiPath;
|
|
11
|
+
const { xmluiBuiltins } = require("krl-compiler");
|
|
12
|
+
function isXmluiBuiltin(componentName) {
|
|
13
|
+
return xmluiBuiltins.isBuiltin(componentName);
|
|
14
|
+
}
|
|
10
15
|
/** Pinned XMLUI standalone runtime shipped under `public/xmlui/`. */
|
|
11
16
|
exports.XMLUI_RUNTIME_VERSION = "0.14.28";
|
|
12
17
|
exports.XMLUI_RUNTIME_PUBLIC_PATH = `/xmlui/${exports.XMLUI_RUNTIME_VERSION}.js`;
|
|
@@ -43,14 +48,28 @@ function isXmluiSpaClientRoute(relPath) {
|
|
|
43
48
|
return false;
|
|
44
49
|
return true;
|
|
45
50
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
exports.XMLUI_RID = "io.picolabs.xmlui";
|
|
52
|
+
/**
|
|
53
|
+
* The query that answers components/<componentName>.xmlui on a channel:
|
|
54
|
+
* the app ruleset's @view or @component, then io.picolabs.xmlui's
|
|
55
|
+
* @component, then the one other ruleset's @component. Two other rulesets
|
|
56
|
+
* with the same component name, or a built-in XMLUI name, answer nothing.
|
|
57
|
+
*/
|
|
58
|
+
function queryForComponentFile(queries, appRid, componentName) {
|
|
59
|
+
if (!(queries === null || queries === void 0 ? void 0 : queries.length) || isXmluiBuiltin(componentName))
|
|
60
|
+
return null;
|
|
61
|
+
const named = queries.filter((q) => viewComponentFileName(q.name) === componentName);
|
|
62
|
+
const fromApp = named.find((q) => q.rid === appRid && (q.view != null || q.component != null));
|
|
63
|
+
if (fromApp)
|
|
64
|
+
return { rid: fromApp.rid, name: fromApp.name };
|
|
65
|
+
const components = named.filter((q) => q.rid !== appRid && q.component != null);
|
|
66
|
+
const fromXmlui = components.find((q) => q.rid === exports.XMLUI_RID);
|
|
67
|
+
if (fromXmlui)
|
|
68
|
+
return { rid: fromXmlui.rid, name: fromXmlui.name };
|
|
69
|
+
const others = components.filter((q) => q.rid !== exports.XMLUI_RID);
|
|
70
|
+
if (others.length !== 1)
|
|
49
71
|
return null;
|
|
50
|
-
|
|
51
|
-
q.view != null &&
|
|
52
|
-
viewComponentFileName(q.name) === componentName);
|
|
53
|
-
return (_a = hit === null || hit === void 0 ? void 0 : hit.name) !== null && _a !== void 0 ? _a : null;
|
|
72
|
+
return { rid: others[0].rid, name: others[0].name };
|
|
54
73
|
}
|
|
55
74
|
function contentTypeForUiPath(filePath) {
|
|
56
75
|
const lower = filePath.toLowerCase();
|
|
@@ -7,7 +7,8 @@ ruleset io.picolabs.xmlui {
|
|
|
7
7
|
use module io.picolabs.wrangler alias wrangler
|
|
8
8
|
|
|
9
9
|
provides query_url, event_url, query, event, escape, app_url, create_app_channel, rotate_app_channel, xmluiRuntimePath
|
|
10
|
-
shares file, query_url, event_url, query, event, escape, app_url, xmluiRuntimePath
|
|
10
|
+
shares file, query_url, event_url, query, event, escape, app_url, xmluiRuntimePath,
|
|
11
|
+
picoTheme, picoSettings, picoThemeField, picoAccessTokenField
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
global {
|
|
@@ -115,12 +116,62 @@ ruleset io.picolabs.xmlui {
|
|
|
115
116
|
})
|
|
116
117
|
}
|
|
117
118
|
|
|
119
|
+
componentNamesFor = function(rid) {
|
|
120
|
+
wrangler:rulesetSchema(rid){"queries"}
|
|
121
|
+
.defaultsTo([])
|
|
122
|
+
.filter(function(q) {
|
|
123
|
+
not q{"component"}.isnull()
|
|
124
|
+
})
|
|
125
|
+
.map(function(q) {
|
|
126
|
+
q{"name"}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// The app's named queries, every @component of the app ruleset and of
|
|
131
|
+
// this ruleset, and file. A channel that omits a component cannot load it.
|
|
118
132
|
queryPolicyForApp = function(app_rid, queries) {
|
|
119
133
|
(queries.isnull() => shareNamesForApp(app_rid) | queries)
|
|
134
|
+
.append(componentNamesFor(app_rid))
|
|
120
135
|
.map(function(q) {
|
|
121
136
|
{ "rid": app_rid, "name": q }
|
|
122
137
|
})
|
|
138
|
+
.append(componentNamesFor(xmluiFileRid).map(function(q) {
|
|
139
|
+
{ "rid": xmluiFileRid, "name": q }
|
|
140
|
+
}))
|
|
123
141
|
.append([{ "rid": xmluiFileRid, "name": "file" }])
|
|
142
|
+
.reduce(function(acc, entry) {
|
|
143
|
+
acc.filter(function(r) {
|
|
144
|
+
r{"rid"} == entry{"rid"} && r{"name"} == entry{"name"}
|
|
145
|
+
}).length() > 0 => acc | acc.append([entry])
|
|
146
|
+
}, [])
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
allowsRule = function(allow, rid, name) {
|
|
150
|
+
allow.filter(function(r) {
|
|
151
|
+
r{"rid"} == rid && r{"name"} == name
|
|
152
|
+
}).length() > 0
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// App channels are the ones the UI route can serve from.
|
|
156
|
+
appChannels = function() {
|
|
157
|
+
wrangler:channels().filter(function(c) {
|
|
158
|
+
allowsRule(c{["queryPolicy", "allow"]}.defaultsTo([]), xmluiFileRid, "file")
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Component queries the channel lacks: every @component of each ruleset
|
|
163
|
+
// the channel already allows, and of this ruleset. Never a new ruleset.
|
|
164
|
+
missingComponentRules = function(channel) {
|
|
165
|
+
have = channel{["queryPolicy", "allow"]}.defaultsTo([])
|
|
166
|
+
rids = have.map(function(r) { r{"rid"} })
|
|
167
|
+
.filter(function(rid) { rid != xmluiFileRid })
|
|
168
|
+
.reduce(function(acc, rid) { acc >< rid => acc | acc.append(rid) }, [])
|
|
169
|
+
rids.append([xmluiFileRid])
|
|
170
|
+
.map(function(rid) {
|
|
171
|
+
componentNamesFor(rid).map(function(name) { {"rid": rid, "name": name} })
|
|
172
|
+
})
|
|
173
|
+
.reduce(function(acc, rules) { acc.append(rules) }, [])
|
|
174
|
+
.filter(function(entry) { not allowsRule(have, entry{"rid"}, entry{"name"}) })
|
|
124
175
|
}
|
|
125
176
|
|
|
126
177
|
eventPolicyForDomains = function(domains) {
|
|
@@ -302,6 +353,103 @@ ruleset io.picolabs.xmlui {
|
|
|
302
353
|
path.defaultsTo("index.html") == "config.json" => configJson(rid) |
|
|
303
354
|
null
|
|
304
355
|
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Applies the theme stored in this browser tab (sessionStorage
|
|
359
|
+
* picoViewTheme: default, dark, green, green-dark, gray, gray-dark) to
|
|
360
|
+
* its children, on the theme's page background so rows stay readable
|
|
361
|
+
* in dark tones. The padding keeps content off the panel's edge, which
|
|
362
|
+
* shows in dark tones.
|
|
363
|
+
* @component
|
|
364
|
+
*/
|
|
365
|
+
picoTheme = function() {
|
|
366
|
+
<<
|
|
367
|
+
<Component name="PicoTheme">
|
|
368
|
+
<Theme
|
|
369
|
+
themeId="{['green', 'green-dark'].includes(sessionStorage.getItem('picoViewTheme') || 'default') ? 'xmlui-green' : ['gray', 'gray-dark'].includes(sessionStorage.getItem('picoViewTheme') || 'default') ? 'xmlui-gray' : 'xmlui'}"
|
|
370
|
+
tone="{(sessionStorage.getItem('picoViewTheme') || 'default').endsWith('dark') ? 'dark' : 'light'}">
|
|
371
|
+
<VStack gap="$space-2" padding="$space-3" backgroundColor="$backgroundColor">
|
|
372
|
+
<Slot />
|
|
373
|
+
</VStack>
|
|
374
|
+
</Theme>
|
|
375
|
+
</Component>
|
|
376
|
+
>>
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Settings dialog with no fields of its own. The caller adds fields as
|
|
381
|
+
* children. Save stores each field in sessionStorage as picoView<Field>
|
|
382
|
+
* (theme becomes picoViewTheme) and reloads the page.
|
|
383
|
+
* Props: title, note. Method: open(). Event: saved(data).
|
|
384
|
+
* @component
|
|
385
|
+
*/
|
|
386
|
+
picoSettings = function() {
|
|
387
|
+
<<
|
|
388
|
+
<Component name="PicoSettings" method.open="() => dialog.open()">
|
|
389
|
+
<ModalDialog id="dialog" title="{$props.title ?? 'Settings'}">
|
|
390
|
+
<Form saveLabel="Save"
|
|
391
|
+
onSubmit="(data) => { Object.keys(data).forEach(k => sessionStorage.setItem('picoView' + k.charAt(0).toUpperCase() + k.slice(1), String(data[k] ?? '').trim())); emitEvent('saved', data); location.reload(); }">
|
|
392
|
+
<Slot />
|
|
393
|
+
<Text value="{($props.note ?? '') + ' This browser tab keeps these settings.'}" />
|
|
394
|
+
</Form>
|
|
395
|
+
</ModalDialog>
|
|
396
|
+
</Component>
|
|
397
|
+
>>
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Theme picker for PicoSettings. Pairs with PicoTheme.
|
|
402
|
+
* @component
|
|
403
|
+
*/
|
|
404
|
+
picoThemeField = function() {
|
|
405
|
+
<<
|
|
406
|
+
<Component name="PicoThemeField">
|
|
407
|
+
<FormItem bindTo="theme" label="Theme" type="select"
|
|
408
|
+
initialValue="{sessionStorage.getItem('picoViewTheme') || 'default'}">
|
|
409
|
+
<Option value="default" label="Default" />
|
|
410
|
+
<Option value="dark" label="Dark" />
|
|
411
|
+
<Option value="green" label="Green" />
|
|
412
|
+
<Option value="green-dark" label="Green, dark" />
|
|
413
|
+
<Option value="gray" label="Gray" />
|
|
414
|
+
<Option value="gray-dark" label="Gray, dark" />
|
|
415
|
+
</FormItem>
|
|
416
|
+
</Component>
|
|
417
|
+
>>
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Access token field for PicoSettings, for views on an OAuth mesh. It is
|
|
422
|
+
* stored as picoViewBearer, which the view shell sends as the bearer on
|
|
423
|
+
* Sky calls from this tab.
|
|
424
|
+
* @component
|
|
425
|
+
*/
|
|
426
|
+
picoAccessTokenField = function() {
|
|
427
|
+
<<
|
|
428
|
+
<Component name="PicoAccessTokenField">
|
|
429
|
+
<FormItem bindTo="bearer" label="Access token" type="password"
|
|
430
|
+
initialValue="{sessionStorage.getItem('picoViewBearer') || ''}" />
|
|
431
|
+
</Component>
|
|
432
|
+
>>
|
|
433
|
+
}
|
|
305
434
|
}
|
|
306
435
|
|
|
436
|
+
// When rulesets change, give each app channel the component queries it
|
|
437
|
+
// lacks, so a channel created before a component existed can load it.
|
|
438
|
+
rule allow_components_on_app_channels {
|
|
439
|
+
select when wrangler schema_updated
|
|
440
|
+
foreach appChannels() setting(channel)
|
|
441
|
+
pre {
|
|
442
|
+
missing = missingComponentRules(channel)
|
|
443
|
+
}
|
|
444
|
+
if missing.length() > 0 then
|
|
445
|
+
wrangler:updateChannel(
|
|
446
|
+
channel{"id"},
|
|
447
|
+
channel{"tags"},
|
|
448
|
+
channel{"eventPolicy"},
|
|
449
|
+
{
|
|
450
|
+
"allow": channel{["queryPolicy", "allow"]}.defaultsTo([]).append(missing),
|
|
451
|
+
"deny": channel{["queryPolicy", "deny"]}.defaultsTo([])
|
|
452
|
+
}
|
|
453
|
+
)
|
|
454
|
+
}
|
|
307
455
|
}
|