pico-engine 1.9.4 → 1.10.0
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 +13 -5
- package/demos/bootstrap/README.md +12 -0
- package/demos/bootstrap/com.example.visitors.bootstrap.krl +101 -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 +88 -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 +84 -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 +98 -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/json_query/README.md +11 -0
- package/demos/json_query/com.example.json_query.bootstrap.krl +84 -0
- package/demos/json_query/com.example.json_query.krl +162 -0
- package/demos/json_query/try-it.md +5 -0
- package/demos/kblog/README.md +14 -0
- package/demos/kblog/com.example.kblog.bootstrap.krl +135 -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 +87 -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 +107 -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 +130 -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 +134 -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 +95 -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 +7 -1
- package/dist/engineConfig.js +20 -1
- package/dist/identity/portableMove.js +5 -1
- package/dist/index.js +45 -12
- package/dist/internalAccess.js +110 -0
- package/dist/oauth/OAuthService.js +172 -10
- package/dist/oauth/acg.js +194 -24
- package/dist/oauth/cimd.js +381 -0
- package/dist/oauth/discovery.js +175 -0
- package/dist/runMcp.js +1 -1
- package/dist/server.js +210 -47
- package/dist/subtreeWrangler.js +8 -5
- package/dist/uiChannelPolicies.js +2 -0
- package/krl/io.picolabs.pds.krl +109 -21
- package/krl/io.picolabs.pico-engine-ui.krl +13 -7
- package/krl/io.picolabs.wrangler.krl +21 -9
- package/krl/io.picolabs.xmlui.krl +3 -2
- package/mcp/devResources.js +52 -0
- package/mcp/devTools.js +40 -9
- package/mcp/docs/CLAUDE.md +6 -4
- package/mcp/docs/cookbook/README.md +23 -0
- package/mcp/docs/cookbook/bootstrap/README.md +23 -0
- package/mcp/docs/cookbook/bootstrap/instructions.md +75 -0
- package/mcp/docs/cookbook/child_tasks/README.md +20 -0
- package/mcp/docs/cookbook/child_tasks/instructions.md +60 -0
- package/mcp/docs/cookbook/collection/README.md +21 -0
- package/mcp/docs/cookbook/collection/instructions.md +93 -0
- package/mcp/docs/cookbook/echo/README.md +19 -0
- package/mcp/docs/cookbook/echo/instructions.md +59 -0
- package/mcp/docs/cookbook/guard_rules/README.md +22 -0
- package/mcp/docs/cookbook/guard_rules/instructions.md +73 -0
- package/mcp/docs/cookbook/json_query/README.md +26 -0
- package/mcp/docs/cookbook/json_query/instructions.md +64 -0
- package/mcp/docs/cookbook/kblog/README.md +60 -0
- package/mcp/docs/cookbook/kblog/instructions.md +102 -0
- package/mcp/docs/cookbook/layered_rulesets/README.md +24 -0
- package/mcp/docs/cookbook/layered_rulesets/instructions.md +87 -0
- package/mcp/docs/cookbook/moving_picos/README.md +44 -0
- package/mcp/docs/cookbook/moving_picos/instructions.md +150 -0
- package/mcp/docs/cookbook/score_tracker/README.md +19 -0
- package/mcp/docs/cookbook/score_tracker/instructions.md +73 -0
- package/mcp/docs/cookbook/secrets/README.md +25 -0
- package/mcp/docs/cookbook/secrets/instructions.md +98 -0
- package/mcp/docs/cookbook/two_picos/README.md +20 -0
- package/mcp/docs/cookbook/two_picos/instructions.md +88 -0
- package/mcp/docs/cookbook/xmlui/README.md +23 -0
- package/mcp/docs/cookbook/xmlui/instructions.md +84 -0
- package/mcp/docs/developing/README.md +28 -0
- package/mcp/docs/developing/accepting-relationship-requests.md +65 -0
- package/mcp/docs/developing/arrays-and-maps.md +77 -0
- package/mcp/docs/developing/converting-time-formats.md +28 -0
- package/mcp/docs/developing/cookies-and-redirects.md +81 -0
- package/mcp/docs/developing/decoding-form-data.md +67 -0
- package/mcp/docs/developing/engine-log-files.md +34 -0
- package/mcp/docs/developing/event-loop.md +77 -0
- package/mcp/docs/developing/events-from-email.md +80 -0
- package/mcp/docs/developing/initializing-entity-variables.md +83 -0
- package/mcp/docs/developing/mcp-ai-tools.md +98 -0
- package/mcp/docs/developing/misconceptions.md +467 -0
- package/mcp/docs/developing/names-and-scope.md +44 -0
- package/mcp/docs/developing/postman.md +159 -0
- package/mcp/docs/developing/querying-another-pico.md +47 -0
- package/mcp/docs/developing/singleton-picos.md +36 -0
- package/mcp/docs/developing/tabular-data.md +67 -0
- package/mcp/docs/developing/tips.md +251 -0
- package/mcp/docs/developing/webhook-signatures.md +56 -0
- package/mcp/docs/developing/workflow.md +106 -0
- package/mcp/docs/exp/README.md +46 -0
- package/mcp/docs/exp/event.md +110 -0
- package/mcp/docs/exp/query.md +94 -0
- package/mcp/docs/lessons/README.md +59 -0
- package/mcp/docs/lessons/events-and-queries.md +247 -0
- package/mcp/docs/lessons/gossip.md +28 -0
- package/mcp/docs/lessons/modules-and-apis.md +270 -0
- package/mcp/docs/lessons/pico-based-systems.md +470 -0
- package/mcp/docs/lessons/pico-state.md +267 -0
- package/mcp/docs/lessons/pico-views.md +290 -0
- package/mcp/docs/lessons/quickstart.md +157 -0
- package/mcp/docs/lessons/relationships.md +530 -0
- package/mcp/docs/lessons/scatter-gather.md +362 -0
- package/mcp/docs/pico-engine.md +10 -5
- package/mcp/docs/pico-overview.md +3 -3
- package/mcp/docs/wrangler/README.md +47 -0
- package/mcp/docs/wrangler/channels.md +235 -0
- package/mcp/docs/wrangler/oauth.md +56 -0
- package/mcp/docs/wrangler/pds.md +423 -0
- package/mcp/docs/wrangler/portable-subtree.md +44 -0
- package/mcp/docs/wrangler/relationships.md +297 -0
- package/mcp/docs/wrangler/wrangler.md +253 -0
- package/mcp/docs/wrangler/xmlui.md +60 -0
- package/mcp/engineClient.js +57 -5
- package/mcp/mcpScopes.js +118 -0
- package/mcp/meshHttp.js +151 -45
- package/mcp/runStdio.js +2 -0
- package/mcp/subtreeTools.js +184 -0
- package/mcp/tryItTools.js +202 -0
- package/package.json +18 -9
- package/public/.DS_Store +0 -0
- package/public/pico-engine-ui.css +1 -1
- package/public/pico-engine-ui.js +26 -25
- package/src/bundledKrl.ts +118 -12
- package/src/cli.ts +8 -2
- package/src/engineConfig.ts +33 -2
- package/src/identity/portableMove.ts +6 -1
- package/src/index.ts +469 -422
- package/src/internalAccess.ts +127 -0
- package/src/oauth/OAuthService.ts +243 -11
- package/src/oauth/acg.ts +289 -25
- package/src/oauth/cimd.ts +508 -0
- package/src/oauth/discovery.ts +233 -0
- package/src/runMcp.ts +3 -1
- package/src/server.ts +266 -51
- package/src/subtreeWrangler.ts +17 -5
- package/src/uiChannelPolicies.ts +2 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Try It! bootstrap for the two picos demo. Install it on a new pico: it creates
|
|
3
|
+
* two children, Alice (com.example.two_picos.answerer) and Bob
|
|
4
|
+
* (com.example.two_picos.asker), and introduces Bob to Alice's well-known
|
|
5
|
+
* channel. Bob asks for a relationship, Alice accepts, and Bob asks his first
|
|
6
|
+
* question. tryIt() reports progress and links to both picos' pages.
|
|
7
|
+
*/
|
|
8
|
+
ruleset com.example.two_picos.bootstrap {
|
|
9
|
+
meta {
|
|
10
|
+
name "Two picos talking"
|
|
11
|
+
description "Shows relationships: asking through a well-known channel, accepting by role, and one pico querying another over the relationship with subscription:queryOnSub."
|
|
12
|
+
author "PICOLABS"
|
|
13
|
+
|
|
14
|
+
use module io.picolabs.wrangler alias wrangler
|
|
15
|
+
|
|
16
|
+
shares tryIt
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
global {
|
|
20
|
+
answerer_rid = "com.example.two_picos.answerer"
|
|
21
|
+
asker_rid = "com.example.two_picos.asker"
|
|
22
|
+
xmlui_rid = "io.picolabs.xmlui"
|
|
23
|
+
|
|
24
|
+
host = function() {
|
|
25
|
+
meta:host.defaultsTo("").replace(re#/$#, "")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
appLink = function(role, rid, label) {
|
|
29
|
+
child = ent:children{role}
|
|
30
|
+
channel = child => wrangler:picoQuery(child, "io.picolabs.wrangler", "channels",
|
|
31
|
+
{"tags": "two_picos," + role}).head() | null
|
|
32
|
+
channel => {"label": label, "url": host() + "/ui/" + channel{"id"} + "/" + rid + "/"} | null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Progress of this demo's setup, and the links to open when it is ready.
|
|
37
|
+
* @returns Map
|
|
38
|
+
*/
|
|
39
|
+
tryIt = function() {
|
|
40
|
+
ready = ent:stage == "ready"
|
|
41
|
+
links = ready => [
|
|
42
|
+
appLink("asker", asker_rid, "Bob's conversation"),
|
|
43
|
+
appLink("answerer", answerer_rid, "What Alice knows")
|
|
44
|
+
].filter(function(link) { link }) | []
|
|
45
|
+
status = {"ready": ready, "stage": ent:stage.defaultsTo("starting"), "links": links}
|
|
46
|
+
status
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
rule start {
|
|
51
|
+
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
|
|
52
|
+
always {
|
|
53
|
+
ent:stage := "creating picos"
|
|
54
|
+
raise wrangler event "new_channel_request" attributes {
|
|
55
|
+
"tags": ["try_it"],
|
|
56
|
+
"eventPolicy": {"allow": [], "deny": []},
|
|
57
|
+
"queryPolicy": {"allow": [{"rid": meta:rid, "name": "tryIt"}], "deny": []}
|
|
58
|
+
}
|
|
59
|
+
raise wrangler event "new_child_request" attributes
|
|
60
|
+
{"name": "Alice", "two_picos_role": "answerer", "backgroundColor": "#ffe0b2"}
|
|
61
|
+
raise wrangler event "new_child_request" attributes
|
|
62
|
+
{"name": "Bob", "two_picos_role": "asker", "backgroundColor": "#bbdefb"}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// A child is set up: install io.picolabs.xmlui, then its role's ruleset.
|
|
67
|
+
rule set_up_child {
|
|
68
|
+
select when wrangler child_initialized where event:attr("two_picos_role")
|
|
69
|
+
pre {
|
|
70
|
+
role = event:attr("two_picos_role")
|
|
71
|
+
child = event:attr("eci")
|
|
72
|
+
rid = role == "answerer" => answerer_rid | asker_rid
|
|
73
|
+
}
|
|
74
|
+
every {
|
|
75
|
+
event:send({
|
|
76
|
+
"eci": child,
|
|
77
|
+
"domain": "wrangler",
|
|
78
|
+
"type": "install_ruleset_request",
|
|
79
|
+
"attrs": {"url": host() + "/krl/" + xmlui_rid + ".krl"}
|
|
80
|
+
})
|
|
81
|
+
event:send({
|
|
82
|
+
"eci": child,
|
|
83
|
+
"domain": "wrangler",
|
|
84
|
+
"type": "install_ruleset_request",
|
|
85
|
+
"attrs": {"absoluteURL": meta:rulesetURI, "rid": rid}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
always {
|
|
89
|
+
ent:children{role} := child
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Both children have their rulesets: introduce Bob to Alice.
|
|
94
|
+
rule child_ready {
|
|
95
|
+
select when two_picos child_ready
|
|
96
|
+
role re#^(answerer|asker)$#
|
|
97
|
+
setting(role)
|
|
98
|
+
pre {
|
|
99
|
+
ready = ent:ready.defaultsTo({}).put(role, true)
|
|
100
|
+
both = (ready{"answerer"} && ready{"asker"}) => true | false
|
|
101
|
+
}
|
|
102
|
+
if both then noop()
|
|
103
|
+
fired {
|
|
104
|
+
raise two_picos event "both_ready"
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
ent:ready{role} := true
|
|
108
|
+
ent:stage := "installing rulesets"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
rule introduce {
|
|
113
|
+
select when two_picos both_ready
|
|
114
|
+
pre {
|
|
115
|
+
well_known = wrangler:picoQuery(ent:children{"answerer"}, "io.picolabs.subscription", "wellKnown_Rx"){"id"}
|
|
116
|
+
}
|
|
117
|
+
event:send({
|
|
118
|
+
"eci": ent:children{"asker"},
|
|
119
|
+
"domain": "two_picos",
|
|
120
|
+
"type": "introduce",
|
|
121
|
+
"attrs": {"wellKnown_Tx": well_known}
|
|
122
|
+
})
|
|
123
|
+
always {
|
|
124
|
+
ent:stage := "introducing Bob to Alice"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
rule connected {
|
|
129
|
+
select when two_picos connected
|
|
130
|
+
always {
|
|
131
|
+
ent:stage := "ready"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
- Leave the **Try It!** tab and close the pico, so the developer UI shows the pico tree. The demo's child has two children, Alice and Bob.
|
|
2
|
+
- Open each one's **Relationships** tab. Each has one relationship: Bob is the `asker` and Alice is the `answerer`.
|
|
3
|
+
- On **Bob's conversation**, ask about `cat`, `hometown`, or `name`. Then ask about something Alice doesn't know yet.
|
|
4
|
+
- On **What Alice knows**, teach Alice that fact, then ask Bob to ask again.
|
|
5
|
+
- Bob never uses Alice's family channel or her page's channel. Look at `ask` in `com.example.two_picos.asker.krl`: every question goes over the relationship with `subscription:queryOnSub`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Pico views demos
|
|
2
|
+
|
|
3
|
+
Rulesets that serve XMLUI pages from a pico. The engine's view tests also use them.
|
|
4
|
+
|
|
5
|
+
- Overview: [`docs/cookbook/xmlui/README.md`](../../docs/cookbook/xmlui/README.md) (on the docs site: https://docs.picolabs.io/#/cookbook/xmlui/)
|
|
6
|
+
- Instructions: [`docs/cookbook/xmlui/instructions.md`](../../docs/cookbook/xmlui/instructions.md)
|
|
7
|
+
|
|
8
|
+
| File | Shows |
|
|
9
|
+
|------|-------|
|
|
10
|
+
| `com.example.hello.krl` | A `@view` and nothing else |
|
|
11
|
+
| `com.example.fav_color.krl` | A query and an event |
|
|
12
|
+
| `com.example.guestbook.krl` | An app channel created on install |
|
|
13
|
+
| `com.example.contacts.krl` | A list page and a detail page |
|
|
14
|
+
| `com.example.thermostat.krl` | Two channels, an app `@component`, and the shared components |
|
|
15
|
+
| `com.example.thermostat.bootstrap.krl` | Sets up the Thermostat demo on a new pico; the **Try It!** tab runs it |
|
|
16
|
+
| `temperature_sensors.krl` | Sample data for the next one |
|
|
17
|
+
| `com.example.temperature_sensors_view.krl` | A view over another pico's data |
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
ruleset com.example.contacts {
|
|
2
|
+
meta {
|
|
3
|
+
name "Contacts"
|
|
4
|
+
use module io.picolabs.xmlui alias ui
|
|
5
|
+
shares contacts, contact, contactsPage, detail
|
|
6
|
+
}
|
|
7
|
+
global {
|
|
8
|
+
/**
|
|
9
|
+
* All contacts, sorted by name
|
|
10
|
+
* @returns Array
|
|
11
|
+
*/
|
|
12
|
+
contacts = function() {
|
|
13
|
+
ent:contacts.defaultsTo({}).values()
|
|
14
|
+
.sort(function(a, b) { a{"name"} cmp b{"name"} })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* One contact
|
|
19
|
+
* @param id Contact id
|
|
20
|
+
* @returns Map
|
|
21
|
+
*/
|
|
22
|
+
contact = function(id) {
|
|
23
|
+
ent:contacts{id}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Everyone, linking to each person's page
|
|
28
|
+
* @view "Contacts" /list
|
|
29
|
+
*/
|
|
30
|
+
contactsPage = function() {
|
|
31
|
+
<<<Component name="ContactsPage">
|
|
32
|
+
#{ui:query("contacts", "contacts", {"rid": meta:rid})}
|
|
33
|
+
#{ui:event("add", "contacts", "contact_added", {"rid": meta:rid, "refresh": ["contacts"]})}
|
|
34
|
+
<Form onSubmit="(data) => add.execute(data)">
|
|
35
|
+
<FormItem bindTo="name" label="Name" required />
|
|
36
|
+
<FormItem bindTo="email" label="Email" />
|
|
37
|
+
</Form>
|
|
38
|
+
<Table data="{contacts}">
|
|
39
|
+
<property name="noDataTemplate">
|
|
40
|
+
<Text value="No contacts" variant="strong" />
|
|
41
|
+
</property>
|
|
42
|
+
<Column header="Name">
|
|
43
|
+
<Link to="/contact/{$item.id}">{$item.name}</Link>
|
|
44
|
+
</Column>
|
|
45
|
+
<Column bindTo="email" header="Email" />
|
|
46
|
+
</Table>
|
|
47
|
+
</Component>
|
|
48
|
+
>>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* One person's details and notes
|
|
53
|
+
* @view "Contact" /contact/:id
|
|
54
|
+
*/
|
|
55
|
+
detail = function() {
|
|
56
|
+
<<<Component name="Detail">
|
|
57
|
+
#{ui:query("person", "contact", {"rid": meta:rid, "args": {"id": "{$routeParams.id}"}})}
|
|
58
|
+
#{ui:event("note", "contacts", "note_added", {"rid": meta:rid, "refresh": ["person"]})}
|
|
59
|
+
<Link to="/list">Back to contacts</Link>
|
|
60
|
+
<H2>{person.value.name}</H2>
|
|
61
|
+
<Text>{person.value.email}</Text>
|
|
62
|
+
<List data="{person.value.notes}">
|
|
63
|
+
<Text>{$item}</Text>
|
|
64
|
+
</List>
|
|
65
|
+
<Form onSubmit="(toSave) => note.execute({id: $routeParams.id, text: toSave.text})">
|
|
66
|
+
<FormItem bindTo="text" label="Add a note" type="textarea" />
|
|
67
|
+
</Form>
|
|
68
|
+
</Component>
|
|
69
|
+
>>
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
channel_tags = ["contacts", "app"]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
rule create_app_channel {
|
|
76
|
+
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
|
|
77
|
+
ui:create_app_channel(channel_tags, ["contacts"], null, meta:rid)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
rule seed_demo_contacts {
|
|
81
|
+
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
|
|
82
|
+
pre {
|
|
83
|
+
empty = ent:contacts.defaultsTo({}).isEmpty()
|
|
84
|
+
}
|
|
85
|
+
if empty then noop()
|
|
86
|
+
fired {
|
|
87
|
+
raise contacts event "contact_added" attributes {
|
|
88
|
+
"name": "Ada Lovelace",
|
|
89
|
+
"email": "ada@example.com"
|
|
90
|
+
}
|
|
91
|
+
raise contacts event "contact_added" attributes {
|
|
92
|
+
"name": "Grace Hopper",
|
|
93
|
+
"email": "grace@example.com"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Add a contact
|
|
100
|
+
* @attr name Full name
|
|
101
|
+
* @attr email Email address
|
|
102
|
+
*/
|
|
103
|
+
rule add_contact {
|
|
104
|
+
select when contacts contact_added
|
|
105
|
+
name re#(.+)# setting(name)
|
|
106
|
+
pre {
|
|
107
|
+
id = random:uuid()
|
|
108
|
+
}
|
|
109
|
+
fired {
|
|
110
|
+
ent:contacts{id} := {"id": id, "name": name, "email": event:attr("email"), "notes": []}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Add a note to a contact
|
|
116
|
+
* @attr id Contact id
|
|
117
|
+
* @attr text The note
|
|
118
|
+
*/
|
|
119
|
+
rule add_note {
|
|
120
|
+
select when contacts note_added
|
|
121
|
+
id re#(.+)#
|
|
122
|
+
text re#(.+)#
|
|
123
|
+
setting(id, text)
|
|
124
|
+
pre {
|
|
125
|
+
notes = ent:contacts{[id, "notes"]}
|
|
126
|
+
}
|
|
127
|
+
if notes then noop()
|
|
128
|
+
fired {
|
|
129
|
+
ent:contacts{[id, "notes"]} := notes.append(text)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
ruleset com.example.fav_color {
|
|
2
|
+
meta {
|
|
3
|
+
name "Favorite color"
|
|
4
|
+
use module io.picolabs.xmlui alias ui
|
|
5
|
+
shares favColor, colorView
|
|
6
|
+
}
|
|
7
|
+
global {
|
|
8
|
+
/** Current favorite color */
|
|
9
|
+
favColor = function() {
|
|
10
|
+
{"name": ent:colorname, "code": ent:colorcode}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Pick a favorite color
|
|
15
|
+
* @view "Favorite color"
|
|
16
|
+
*/
|
|
17
|
+
colorView = function() {
|
|
18
|
+
<<<Component name="ColorView">
|
|
19
|
+
#{ui:query("fav", "favColor", {"rid": meta:rid})}
|
|
20
|
+
<Text when="{!fav.value.name}">You have not yet selected a favorite color.</Text>
|
|
21
|
+
<Card when="{fav.value.name}" title="Your favorite color: {fav.value.name}" />
|
|
22
|
+
#{ui:event("pick", "fav_color", "fav_color_selected", {"rid": meta:rid, "refresh": ["fav"]})}
|
|
23
|
+
<Form onSubmit="(toSave) => pick.execute(toSave)">
|
|
24
|
+
<FormItem bindTo="fav_color" label="Color (#rrggbb, hex digits a–f or A–F)" />
|
|
25
|
+
</Form>
|
|
26
|
+
</Component>
|
|
27
|
+
>>
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
rule recordFavColor {
|
|
32
|
+
select when fav_color fav_color_selected
|
|
33
|
+
fav_color re#^(\#[a-fA-F0-9]{6})$# setting(fav_color)
|
|
34
|
+
fired {
|
|
35
|
+
ent:colorcode := fav_color
|
|
36
|
+
ent:colorname := fav_color
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
ruleset com.example.guestbook {
|
|
2
|
+
meta {
|
|
3
|
+
name "Guestbook"
|
|
4
|
+
use module io.picolabs.xmlui alias ui
|
|
5
|
+
shares entries, book
|
|
6
|
+
}
|
|
7
|
+
global {
|
|
8
|
+
/**
|
|
9
|
+
* Guestbook entries, newest first
|
|
10
|
+
* @returns Array
|
|
11
|
+
*/
|
|
12
|
+
entries = function() {
|
|
13
|
+
ent:entries.defaultsTo([]).reverse()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sign and read the guestbook
|
|
18
|
+
* @view "Guestbook"
|
|
19
|
+
*/
|
|
20
|
+
book = function() {
|
|
21
|
+
<<<Component name="Book">
|
|
22
|
+
#{ui:query("entries", "entries", {"rid": meta:rid})}
|
|
23
|
+
#{ui:event("sign", "guestbook", "signed", {"rid": meta:rid, "refresh": ["entries"]})}
|
|
24
|
+
<Form onSubmit="(toSave) => sign.execute(toSave)">
|
|
25
|
+
<FormItem bindTo="name" label="Name" />
|
|
26
|
+
<FormItem bindTo="message" label="Message" type="textarea" />
|
|
27
|
+
</Form>
|
|
28
|
+
<Table data="{entries}">
|
|
29
|
+
<Column bindTo="name" header="Name" />
|
|
30
|
+
<Column bindTo="message" header="Message" />
|
|
31
|
+
<Column bindTo="time" header="Signed" />
|
|
32
|
+
</Table>
|
|
33
|
+
</Component>
|
|
34
|
+
>>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
channel_tags = ["guestbook", "app"]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Add an entry
|
|
42
|
+
* @attr name Who is signing
|
|
43
|
+
* @attr message What they wrote
|
|
44
|
+
*/
|
|
45
|
+
rule sign {
|
|
46
|
+
select when guestbook signed
|
|
47
|
+
name re#(.+)# setting(name)
|
|
48
|
+
pre {
|
|
49
|
+
message = event:attr("message") || ""
|
|
50
|
+
}
|
|
51
|
+
fired {
|
|
52
|
+
ent:entries := ent:entries.defaultsTo([])
|
|
53
|
+
.append({"name": name, "message": message, "time": time:now()})
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
rule create_app_channel {
|
|
58
|
+
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
|
|
59
|
+
ui:create_app_channel(channel_tags, ["guestbook"], null, meta:rid)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
ruleset com.example.hello {
|
|
2
|
+
meta {
|
|
3
|
+
name "Hello"
|
|
4
|
+
shares hello
|
|
5
|
+
}
|
|
6
|
+
global {
|
|
7
|
+
/**
|
|
8
|
+
* A first view
|
|
9
|
+
* @view "Hello"
|
|
10
|
+
*/
|
|
11
|
+
hello = function() {
|
|
12
|
+
<<<Component name="Hello">
|
|
13
|
+
<H1>Hello</H1>
|
|
14
|
+
<Text>This view is a shared function in #{meta:rid}.</Text>
|
|
15
|
+
</Component>
|
|
16
|
+
>>
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo XMLUI view: shows readings from `com.example.temperature_sensors` on **another** pico.
|
|
3
|
+
*
|
|
4
|
+
* Install `demos/xmlui/temperature_sensors.krl` on the **data** pico and this ruleset on the **view** pico.
|
|
5
|
+
*
|
|
6
|
+
* **DID / layer-2 relationships:** do **not** pass `Remote Tx DID` (`did:peer:…`) to `wrangler:picoQuery` —
|
|
7
|
+
* that is not a channel ECI. Use the **relationship id** (same `Id` on both picos in Developer UI → Relationships)
|
|
8
|
+
* and `io.picolabs.subscription:queryOnSub` (wired below).
|
|
9
|
+
*
|
|
10
|
+
* raise temperature_sensors_view event "link_data_pico" attributes { "relationship_id": "<Id>" }
|
|
11
|
+
*
|
|
12
|
+
* **Legacy ECI relationships:** the established bus has a real **Remote Tx ECI**; you could call
|
|
13
|
+
* `wrangler:picoQuery` on that ECI directly, but `queryOnSub` still works if you store `relationship_id`.
|
|
14
|
+
*
|
|
15
|
+
* (`latestReadingsForView` is empty until `ent:sensors_relationship_id` is set.)
|
|
16
|
+
*
|
|
17
|
+
* The data pico's `readingAt` is a UTC string and `timestamp` is epoch milliseconds.
|
|
18
|
+
* This ruleset ignores that string and formats `timestamp` as Mountain Standard Time
|
|
19
|
+
* (UTC−7) before the table renders it.
|
|
20
|
+
*
|
|
21
|
+
* Open: Developer UI → View, or `/ui/<view-app-eci>/com.example.temperature_sensors_view/`
|
|
22
|
+
*/
|
|
23
|
+
ruleset com.example.temperature_sensors_view {
|
|
24
|
+
meta {
|
|
25
|
+
name "Temperature sensors (demo view)"
|
|
26
|
+
use module io.picolabs.subscription alias sub
|
|
27
|
+
use module io.picolabs.xmlui alias ui
|
|
28
|
+
shares dashboard, latestReadingsForView
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
global {
|
|
32
|
+
sensors_rid = "com.example.temperature_sensors"
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Format a UTC epoch-millisecond timestamp as Mountain Standard Time.
|
|
36
|
+
* `time:new` returns an ISO-8601 UTC string. Subtracting the offset first
|
|
37
|
+
* makes the date and clock in that string the MST reading time.
|
|
38
|
+
* @param timestamp Number milliseconds since the Unix epoch
|
|
39
|
+
* @returns String "YYYY-MM-DD HH:MM:SS MST"
|
|
40
|
+
*/
|
|
41
|
+
readingAtMst = function(timestamp) {
|
|
42
|
+
// Mountain Standard Time is a fixed seven hours behind UTC.
|
|
43
|
+
mst_offset_ms = 7 * 60 * 60 * 1000
|
|
44
|
+
iso = time:new(timestamp - mst_offset_ms)
|
|
45
|
+
date = iso.split("T")[0]
|
|
46
|
+
clock = iso.split("T")[1].split(".")[0]
|
|
47
|
+
date + " " + clock + " MST"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Readings from the data pico, with `readingAt` rewritten to MST.
|
|
52
|
+
* @returns Array
|
|
53
|
+
*/
|
|
54
|
+
latestReadingsForView = function() {
|
|
55
|
+
readings = ent:sensors_relationship_id.isnull() => [] |
|
|
56
|
+
sub:queryOnSub(ent:sensors_relationship_id, sensors_rid, "latestReadings", {})
|
|
57
|
+
readings.isnull() => readings |
|
|
58
|
+
readings.typeof() == "Array" => readings.map(function(row) {
|
|
59
|
+
row.put("readingAt", readingAtMst(row{"timestamp"}))
|
|
60
|
+
}) | readings
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @view "Dashboard"
|
|
65
|
+
*/
|
|
66
|
+
dashboard = function() {
|
|
67
|
+
<<<Component name="Dashboard">
|
|
68
|
+
#{ui:query("readings", "latestReadingsForView", {"rid": meta:rid})}
|
|
69
|
+
<Card title="Latest temperatures" subtitle="UTC timestamps from the data pico, shown here as MST" />
|
|
70
|
+
<Table data="{readings}">
|
|
71
|
+
<Column bindTo="name" header="Sensor" />
|
|
72
|
+
<Column bindTo="lastTemperature" header="Temp (F)" />
|
|
73
|
+
<Column bindTo="readingAt" header="Reading at (MST)" />
|
|
74
|
+
<Column bindTo="timestamp" header="Timestamp (ms)" />
|
|
75
|
+
</Table>
|
|
76
|
+
</Component>
|
|
77
|
+
>>
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Store the relationship id (established subscription bus `Id`, same string on both picos).
|
|
83
|
+
* @attr relationship_id String e.g. from Relationships tab next to the relationship name
|
|
84
|
+
*/
|
|
85
|
+
rule link_data_pico {
|
|
86
|
+
select when temperature_sensors_view link_data_pico
|
|
87
|
+
relationship_id re#(.+)# setting(relationship_id)
|
|
88
|
+
fired {
|
|
89
|
+
ent:sensors_relationship_id := relationship_id
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
rule create_app_channel {
|
|
94
|
+
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
|
|
95
|
+
// Pass null for queries so the channel allows every shared query on this RS
|
|
96
|
+
// (including `dashboard`, which @view needs for Main.xmlui). A narrow list that
|
|
97
|
+
// omits the view query leaves viewQueriesOnChannel empty → Main.xmlui fails.
|
|
98
|
+
ui:create_app_channel(
|
|
99
|
+
["temperature_sensors_view", "app"],
|
|
100
|
+
["temperature_sensors_view"],
|
|
101
|
+
null,
|
|
102
|
+
meta:rid
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Try It! bootstrap for the Thermostat demo. Install it on a new pico: it
|
|
3
|
+
* installs io.picolabs.xmlui and com.example.thermostat, then seeds three
|
|
4
|
+
* readings. tryIt() reports progress and links to the dashboard on the
|
|
5
|
+
* thermostat's viewer and admin channels.
|
|
6
|
+
*
|
|
7
|
+
* This ruleset does not use io.picolabs.xmlui as a module, because it is the
|
|
8
|
+
* one that installs it.
|
|
9
|
+
*/
|
|
10
|
+
ruleset com.example.thermostat.bootstrap {
|
|
11
|
+
meta {
|
|
12
|
+
name "Thermostat"
|
|
13
|
+
description "Shows pico views: a dashboard @view, an app @component, the shared settings and theme components, and two channels whose policies give viewers and admins different pages."
|
|
14
|
+
author "PICOLABS"
|
|
15
|
+
|
|
16
|
+
use module io.picolabs.wrangler alias wrangler
|
|
17
|
+
|
|
18
|
+
shares tryIt
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
global {
|
|
22
|
+
thermostat_rid = "com.example.thermostat"
|
|
23
|
+
xmlui_rid = "io.picolabs.xmlui"
|
|
24
|
+
seed_temperatures = ["70", "72", "75"]
|
|
25
|
+
|
|
26
|
+
host = function() {
|
|
27
|
+
meta:host.defaultsTo("").replace(re#/$#, "")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
appUrl = function(channel) {
|
|
31
|
+
host() + "/ui/" + channel{"id"} + "/" + thermostat_rid + "/"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Progress of this demo's setup, and the links to open when it is ready.
|
|
36
|
+
* @returns Map
|
|
37
|
+
*/
|
|
38
|
+
tryIt = function() {
|
|
39
|
+
viewer = wrangler:channels(["thermostat", "viewer"]).head()
|
|
40
|
+
admin = wrangler:channels(["thermostat", "admin"]).head()
|
|
41
|
+
ready = (ent:stage == "ready" && viewer && admin) => true | false
|
|
42
|
+
// A map on the line after `| false` would parse as false{...}.
|
|
43
|
+
status = {
|
|
44
|
+
"ready": ready,
|
|
45
|
+
"stage": ent:stage.defaultsTo("starting"),
|
|
46
|
+
"links": ready => [
|
|
47
|
+
{"label": "Dashboard (viewer channel)", "url": appUrl(viewer)},
|
|
48
|
+
{"label": "Dashboard and Settings (admin channel)", "url": appUrl(admin)}
|
|
49
|
+
] | []
|
|
50
|
+
}
|
|
51
|
+
status
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
rule start {
|
|
56
|
+
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
|
|
57
|
+
pre {
|
|
58
|
+
has_xmlui = wrangler:installedRIDs() >< xmlui_rid
|
|
59
|
+
}
|
|
60
|
+
if not has_xmlui then noop()
|
|
61
|
+
fired {
|
|
62
|
+
raise wrangler event "install_ruleset_request" attributes
|
|
63
|
+
{"url": host() + "/krl/" + xmlui_rid + ".krl"}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
raise wrangler event "install_ruleset_request" attributes
|
|
67
|
+
{"absoluteURL": meta:rulesetURI, "rid": thermostat_rid}
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
ent:stage := "installing"
|
|
71
|
+
raise wrangler event "new_channel_request" attributes {
|
|
72
|
+
"tags": ["try_it"],
|
|
73
|
+
"eventPolicy": {"allow": [], "deny": []},
|
|
74
|
+
"queryPolicy": {"allow": [{"rid": meta:rid, "name": "tryIt"}], "deny": []}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
rule install_thermostat {
|
|
80
|
+
select when wrangler ruleset_installed where event:attr("rids") >< xmlui_rid
|
|
81
|
+
always {
|
|
82
|
+
raise wrangler event "install_ruleset_request" attributes
|
|
83
|
+
{"absoluteURL": meta:rulesetURI, "rid": thermostat_rid}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
rule seed_readings {
|
|
88
|
+
select when wrangler ruleset_installed where event:attr("rids") >< thermostat_rid
|
|
89
|
+
foreach seed_temperatures setting(temperature)
|
|
90
|
+
always {
|
|
91
|
+
raise thermostat event "new_reading" attributes {"temperature": temperature}
|
|
92
|
+
ent:stage := "ready" on final
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|