Storage Server

The Storage Server is a shared notebook for a whole network. Every program on the network, on the computer and on devices, can store values under names and read them back later. Use it to collect logs from autonomous devices or to share settings between programs.
How to get it
Section titled “How to get it”
Storage ServerPlace and connect
Section titled “Place and connect”Place it and link it to a Network Repeater. It needs no drive and runs no program.
Configure
Section titled “Configure”| Setting | Meaning |
|---|---|
| Device programs: write / read | Whether drive programs may change the data or only read it. Computer programs can always write. |
| View data | Shows the stored keys. |
| Clear data | Owner only: deletes everything stored. |
What can be stored
Section titled “What can be stored”nil, booleans, numbers, strings, lists, tuples and dictionaries, nested at most 16 levels, with no loops. Devices,
class objects and enum constants cannot be stored. Every read gives a copy, so changing it does not change the stored
value until you write it back.
Drive programs
Section titled “Drive programs”The Storage Server cannot run a program, but drive programs on its network can use it through a device constant:
const records = storageServers.named("records"), then records.append(...). They cannot clear() it.
Program API
Section titled “Program API”Getting it
Section titled “Getting it”storageServers.named(alias)
Refer to a Storage Server by its name. Use it in a constant, then handle its events with on NAME.event(...).
const records = storageServers.named("records")storageServers.from(alias)
Resolve a storage server by name.
server, err = storageServers.from("warehouse")Methods
Section titled “Methods”Properties: records.connected, records.id, records.kind, records.name. They are read-only.
records.append(key, value)
Add a value to the end of the list under a key, creating the list when needed.
server.append("visitors", name)records.clear()
Remove everything stored on the server.
server.clear()records.delete(key)
Remove a key. Gives false when nothing was stored.
server.delete("old")records.has(key)
True when something is stored under a key.
if server.has("diamonds") { print("stocked") }records.keys()
List the stored keys, oldest first.
names = server.keys()records.read(key)
Read a copy of the value stored under a key. A missing key gives the error storage.missing.
count = server.read("diamonds")records.usage()
Read used and capacity bytes and entries and maxEntries.
space = server.usage()records.write(key, value)
Store a copy of a value under a key, replacing any old value.
server.write("diamonds", 64)Events
Section titled “Events”| Event | When it runs |
|---|---|
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
Limits
Section titled “Limits”- 256 KiB in up to 1,024 keys, each value at most 64 KiB.
- Keys are 1 to 64 letters, digits or
_ . : -. - A write that does not fit fails with
storage.fulland changes nothing. - Data is saved with the world, never per write. A crash loses changes since the last save.
Example
Section titled “Example”const records = storageServers.named("records")
on startup { records.append("boots", "started") print(str(records.keys().length) + " keys stored")}