
Datastar Aether SDK
An Aether SDK for
Datastar — hypermedia-driven UIs, where the
server pushes DOM patches and signal updates to the browser over
Server-Sent Events.
Ported from the Datastar Go SDK,
and verified against the same cross-SDK conformance suite every other
Datastar SDK is held to: 20/20 upstream golden cases pass, both
offline and over HTTP against the upstream runner.
Quick start
You need Aether 0.931.0 or later
and a C compiler. If you don't have ae yet, this installs a prebuilt release
into ~/.local:
curl -fsSL https://raw.githubusercontent.com/aether-lang-dev/aether/main/get.sh \
| sh -s -- v0.931.0
Then make a project and add the SDK:
ae init myapp && cd myapp
ae add github.com/aether-lang-dev/datastar-aether@v0.2.0
ae add records the dependency in your aether.toml and fetches the tagged
source. From then on ae build and ae run put the SDK on the module path,
so import datastar just works: no --lib, no vendoring. Put the
Usage example in src/main.ae, then:
ae run # then open http://localhost:8080 and click the button
To see the raw event stream instead:
curl -N 'http://localhost:8080/updates?datastar=%7B%22count%22%3A41%7D'.
The package exports one module, datastar; nothing else in this repo is API.
Versions are git tags.
License
MIT, as the Go SDK it was ported from. Copyright is shared: the
wire-format behaviour, the option surface and the vendored conformance
goldens are derived from Star Federation's work and stay theirs; the
Aether implementation, tests and harness are mine. Both under the same
terms — see LICENSE.
Requirements
Aether 0.931.0 — pinned in ci/versions.env, the
single place to bump — plus contrib.tinyweb for routing (it ships with a
standard Aether install). The SDK itself depends on nothing but the stdlib.
Verified on 0.931.0 (2026-11-20): the conformance, unit, streaming and TLS
suites pass; every program in cmd/ builds; and the six component suites (47
tests) pass under a virtual display. The component suites ran against
selaenium's main branch through ae run --override, because the released
selaenium 0.14.2 does not compile on 0.931.0; tests/component/aether.toml
keeps naming 0.14.2 until selaenium cuts a release that does.
What the move from 0.841 to 0.931 changed for this repo: a ptr read from
list.get or map.get can no longer be given to a string parameter (E0202,
0.927.0), so the string lists in the SDK, harness and conformance test use
list.get_string / map.get_string.
What the move from 0.824 to 0.841 changed for this repo, all fixed in-tree:
std.json's exported spellings are encode / str (no longer stringify /
json_create_string); a ptr from list.get / map.get must be read with the
typed get_string before it is interpolated or assigned to a string; and a
spec.before_each callback that captures the WebDriver handle needs that
parameter marked @keep ptr.
Working on this repo
./bootstrap.sh installs the ae pinned in ci/versions.env and then runs
the offline suites, so a fresh clone proves itself in one command.
NO_TEST=1 ./bootstrap.sh installs only.
This repo builds and tests with plain ae, through task targets. The one
external dependency, the Selenium binding for the component tests, is declared
in tests/component/aether.toml (see Testing), not in the root
manifest, so it is never pulled into a project that uses the SDK.
Fixes and features this SDK depends on, all upstream — several fixed at
this port's request:
| version |
what it fixed for us |
| 0.629.0 |
an E0200 false positive that took out the native WebDriver binding, so the component tests could not compile |
| 0.630.0 |
a stale-cache bug that let a suite report green against code it never compiled |
| 0.631.0 |
a value-returning builder running its body twice — for a send verb, every event went out twice |
| 0.634.0 |
SSE upgrade-in-place and the retry: field, which together let this SDK serve HTTPS |
| 0.635.0 |
tinyweb.with_tls, which made that HTTPS path testable in-tree |
| 0.637.0 |
[dependencies] resolution — the selaenium binding is now one line in aether.toml, no hand-rolled --lib resolver |
| 0.643.0 |
a struct-prefix-punning codegen bug (a string-field write clobbered an adjacent int in a wider struct) that hit datastar's own option structs |
The SDK's core builds on older toolchains; the *_with verbs and the
component tests do not.
Usage
A complete app: a page with a button, and an endpoint that answers each click
over SSE. Save it as src/main.ae, ae run, and open http://localhost:8080.
import contrib.tinyweb
import std.json
import datastar
const PAGE = "<!doctype html>
<html><head>
<script type=\"module\" src=\"https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.3/bundles/datastar.js\"></script>
</head><body data-signals:count=\"0\">
<button data-on:click=\"@get('/updates')\">Click me</button>
<p>Clicks: <span data-text=\"$count\"></span></p>
<div id=\"output\">Not clicked yet.</div>
</body></html>"
main() {
server = tinyweb.web_server_host("localhost", 8080) {
tinyweb.end_point(tinyweb.GET, "/") |req: ptr, res: ptr, ctx: ptr| {
tinyweb.response_set_header(res, "Content-Type", "text/html; charset=utf-8")
tinyweb.response_write(res, PAGE)
}
tinyweb.end_point(tinyweb.GET, "/updates") |req: ptr, res: ptr, ctx: ptr| {
// Read the client's signal store off the request.
signals, err = datastar.read_signals(req)
if err != "" { return }
defer json.json_free(signals)
count = 0
v, _ = json.object_get(signals, "count")
if v != null { count = json.json_get_int(v) }
count = count + 1
// Upgrade the response to an event stream.
sse, serr = datastar.new_sse(res)
if serr != "" { return }
defer datastar.sse_close(sse)
// Patch elements into the DOM (matched by id).
_e1 = datastar.patch_elements(sse, "<div id=\"output\">Hello from the server, ${count} time(s)!</div>", null)
// Patch signals (client-side state); data-text re-renders.
_e2 = datastar.patch_signals(sse, "{\"count\":${count}}", null)
// Run a script in the browser. (datastar.redirect(sse, url)
// would navigate it elsewhere.)
_e3 = datastar.console_log(sse, "click ${count} handled")
}
}
tinyweb.tw_start(server)
}
Options
Go's variadic functional options become an options bag. The shortest form
puts the block on the call itself:
err = datastar.patch_elements_with(sse, "<div>appended</div>") {
datastar.with_selector("#target")
datastar.with_mode_append()
}
patch_elements_with / patch_signals_with / execute_script_with
build the bag, let the block fill it, send, and release it. They need
Aether 0.631.0 or later — before that, a value-returning builder in
assignment position ran its body twice
(aether#1888),
which for a send verb meant every event went out twice.
Where a bag is reused across several sends, build it once:
opts = datastar.element_options() {
datastar.with_selector("#target")
datastar.with_mode_append()
datastar.with_view_transitions()
datastar.with_retry_duration(2000)
}
defer datastar.element_options_free(opts)
err = datastar.patch_elements(sse, "<div>appended</div>", opts)
Pass null instead for all-defaults, which allocates nothing. A bag is
reusable across a stream — build it once outside the loop.
There are three bags, one per event kind:
| Constructor |
Setters |
Free with |
element_options() |
with_selector, with_selector_id, with_mode*, with_namespace*, with_view_transitions, with_view_transition_selector, with_event_id, with_retry_duration |
element_options_free |
signal_options() |
with_only_if_missing, with_event_id, with_retry_duration |
signal_options_free |
script_options() |
with_auto_remove, with_script_attribute, with_script_attribute_kv, with_event_id, with_retry_duration |
script_options_free |
The wire format, without a server
The SDK splits in two: a pure format engine and a thin transport. The
engine is string-in, string-out, so you can see and test exactly what
goes on the wire with no socket involved:
frame = datastar.patch_elements_frame("<div>hi</div>", null)
// event: datastar-patch-elements
// data: elements <div>hi</div>
//
patch_elements_frame, patch_signals_frame and
execute_script_frame are what the conformance suite asserts against.
Examples
| Example |
What it shows |
cmd/examples/helloworld |
Streaming a message a character at a time, at a delay the client's signal controls |
cmd/examples/hotreload |
Refreshing the browser once per server start, so a file watcher gives you live reload |
cmd/testserver |
The SDK conformance server the upstream cross-SDK runner drives |
task hello # http://localhost:1337
task hotreload # http://localhost:9001
Module map
Three layers, each depending only downward. The SDK depends on nothing in
the repo; everything else consumes it.
datastar/ THE SDK — ported from datastar-go, std-only deps
module.ae new_sse, patch_signals/elements, option bags
testevents/module.ae the conformance event model
harness/ THE EXAMPLE APP + its test infrastructure
components/
card/ the card, DECOMPOSED into pure, offline-tested parts:
brand/ number/ expiry/ cvc/ preview/
card2/module.ae the composition — mounts those, wires Datastar
inbox/module.ae a second example component
module.ae the component registry
stub/ mock collaborators (where the test speed comes from):
cards/ processor verdict clock/ "now" messages/ inbox corpus
storaebook/module.ae Datastar StoraeBook (see below)
stories/module.ae the story catalogue (data)
page/module.ae the plain page shell (raw view)
cmd/ ENTRY POINTS
harness/main.ae the harness AND StoraeBook server (task harness / storaebook)
testserver/main.ae SDK conformance server [[bin]] datastar-testserver
examples/helloworld, hotreload [[bin]] datastar-{helloworld,hotreload}
The card is the decomposition showcase: every rule (brand from PAN, Luhn,
expiry-not-past against an injected clock, CVC length) is a pure module
with fast offline tests; card2 only composes them and glues them to
Datastar, so the browser tests prove integration, not the rules.
Datastar StoraeBook
A Storybook-alike for the components — a small homage to
Storybook (portions © 2024 Storybook, MIT),
rebuilt as idiomatic Datastar: story tree, canvas toolbar, Canvas/Docs
tabs, and live Controls, all via signals — no JS framework.