Pages
Add your own screens — a kanban board, a dashboard — to serve. A page is one HTML file that reads and writes your data through window.yamlite, limited to what yamlite.yaml allows it.
pages: board: path: .pages/kanban.html # a dot-folder: a plain folder under the root would become a table title: Task board access: { tasks: write, people: read } # tables and views; nothing else is reachable sql: false # true allows SELECT over the names in access network: [] # origins the page may load scripts, styles, images and fonts from, and connect to files: { .images/: read, .uploads/: write } # files the page may read (yamlite.files.read) or also write (yamlite.files.write); a folder ends in / ai: true # lets the page call the host's AI model; { maxOutputTokens: 2048 } raises the default 1024 (at most 8192)Start from examples/pages/kanban.html: copy it into .pages/, set TABLE, KEY, GROUP and TITLE at the top, and declare it as above. examples/pages/summary.html shows a page that asks AI to summarize a record. examples/pages/gallery.html lists a table’s image column and shows each file with yamlite.files.read.
To share a page with people who should see only that page, open it and click Copy app link. The link ends in /-/apps/<name>/ and shows the page alone, with its own title and look: no sidebar, tables, SQL console, command menu or links into other records. Once there are edits, a bar at the bottom shows their count and Send for review; an embedding host can add its own controls at the left of that bar with the appFooter mount option. A host whose app link opens a branch other than the one being viewed can add Copy branch link next to it with the branchAppLink mount option, so a review’s edits can be shown before they are applied. The part after # is where the page stands inside itself, which it sets with yamlite.history, so a reload, the back button and a copied address return there; changing it does not leave the app. It leaves the editor out of sight; it does not take it away, so anyone who removes -/apps/<name>/ from the address can still reach the rest of the UI. With serve, the copied link has no token, and the login cookie is not sent when a link is opened from another site such as mail or chat: share /-/apps/<name>/?token=… instead, on the origin of the URL serve printed and with its token. serve is meant for trying an app out; to share one with a team, use a host that gives each viewer their own branch. An export has the same entry at -/apps/<name>/ for each page it includes; open it with the trailing slash (static hosts add it), since without it the page’s relative paths resolve one folder too high.
| Call | Does |
|---|---|
await yamlite.ready |
{ page, title, access, sql, network, files, readOnly, ai }; ai is { provider, models } when the page has ai and the host holds a key, else null |
yamlite.rows(table, { filter, sort, search, limit, offset }) |
{ rows, total }, reads tables and views, same filters and search as the table screen; limit ≤ 500 |
yamlite.get(table, key) |
{ row, file }; tables only, a view gives 400 |
yamlite.create(table, key, values) / update(table, key, values, { base }) / remove(table, key, { base }) |
needs write; base is the record as the page last read it, or the fields of it the page relies on. update fails with status 409, extra.stale (the fields) and extra.current (the record now) if a field it saves changed since base; remove does if any field in base changed. Leaving base out skips the check |
yamlite.sql(select) |
needs sql: true; one SELECT over the names in access |
await yamlite.files.read(path) |
needs path to match one of the page’s files entries (read or write) and not be a denied path; resolves to a Blob typed by extension (image/png, image/jpeg, image/webp, image/gif, image/svg+xml, application/pdf, text/plain, otherwise application/octet-stream), for URL.createObjectURL. Files on the branch or commit the viewer has open, at most 10 MB; 403 when path matches no entry, 404 when there is no such file, 413 over the limit |
await yamlite.files.write(path, blob, { base }) / files.delete(path, { base }) |
needs path to fall under a write entry; write stores a PNG, JPEG, GIF, WebP or PDF file (the bytes must match the extension, at most 10 MB), creating its folders, and resolves to { sha256 }; delete removes the file. base is the Blob the page last got from files.read, the sha256 its last files.write returned, or null when it expects no file there; when the file has changed since, the call fails with status 409 and extra.current (the SHA-256 of the content now; absent when the file is over 10 MB). Leaving base out skips the check |
yamlite.on("change", ({ tables, files }) => …) |
called after a sync changes a table or view the page can read (tables), or after a file under the page’s files changes on disk (files, root-relative paths), whoever changed it |
yamlite.theme / yamlite.on("theme", ({ theme }) => …) |
the current theme (light or dark), and a call when it changes |
yamlite.ai.generate({ system, prompt, schema, model, maxOutputTokens }) |
needs ai (a page without it gets 403); { text }, or { object } matching schema (a JSON Schema). prompt is a string or a list of { role: "user" | "assistant", content }; model is one of ready’s ai.models, the first by default; maxOutputTokens may lower the page’s limit. Runs on the host’s key, never one from the page. Fails with 503 and extra.code: "no_key" when the host has no key, 429 with extra.retryAfter (seconds) when busy, and 502 when the provider fails: extra.provider is the provider id and the provider’s own text is in message |
yamlite.ai.stream({ system, prompt, model }) |
the same without schema, as an async iterable of text deltas: for await (const text of yamlite.ai.stream(…)); leaving the loop early cancels the call |
yamlite.open(table, key) |
opens the record in YAMLite’s own form; tables only, a view gives 400 |
yamlite.history |
where the page stands inside itself, with the history package’s shape (location, push, replace, go, back, forward, listen, createHref) that routers take; in an app it is kept after the # of the address, and back and go stay within the app. push(to, state) and replace(to, state) throw for a path outside the page or longer than 2048 characters; state must be structured-cloneable, and comes back as location.state on back and forward, and as JSON after a reload |
Errors reject with yamlite.YamliteError (status, message, extra).
Look and feel
Section titled “Look and feel”Every page gets the UI’s colours and fonts as CSS variables, and follows the theme switch without reloading:
| Variables | Use |
|---|---|
--y-bg, --y-panel, --y-panel-2, --y-line |
surfaces and borders |
--y-text, --y-muted |
text |
--y-accent, --y-accent-fill, --y-accent-soft, --y-on-accent |
emphasis |
--y-ok, --y-warn, --y-warn-soft, --y-err, --y-err-soft |
states |
--y-chip, --y-chip-text |
chips |
--y-font, --y-mono |
Outfit and JetBrains Mono (Latin); other scripts use the system font |
Native form controls and scrollbars follow the theme (color-scheme) only on pages with data-yamlite-ui.
<html> carries data-theme="light" or "dark"; yamlite.theme reads it and yamlite.on("theme", ({ theme }) => …) is called when it changes.
Add data-yamlite-ui to <html> to also get the UI’s look for plain elements — body, headings, links, button (.y-primary for the filled one), input, select, textarea, table (sticky header, wrapping cells), pre/code, details/summary — and these classes: .y-chip (with .y-ok, .y-warn, .y-err), .y-card, .y-toolbar, .y-muted, .y-link. All of it sits inside :where(), so any rule of your own wins.
The variable and class names are part of the page API: renaming one is a breaking change.
- The page runs in a sandboxed frame with no access to YAMLite’s session; every call goes through YAMLite, which checks it against
access. SQL runs on a read-only connection where SQLite itself refuses tables outsideaccess. networkis enforced with a Content Security Policy. It limits what the page loads and where it connects. Declaring an origin lets the page send data, including anything it can read throughaccess, off your machine to that origin.ailets the page send anything it can read throughaccessto the host’s AI provider, billed to the host’s key.- Every page, even with
network: [], can leak data by navigating its own frame to another site with the data in the URL. YAMLite then disconnects the page, but the data has already left. Only declare pages you trust, as you would any script you run. filesis a grant likeaccess: each entry isreadorwrite, the page can read every file under a declared folder, and anything a page can read can leave through navigation, as for records. An entry ending in/is a folder, any other entry one exact file;.., absolute paths and entries inside.yamlite/or namingyamlite.yamlare config errors, as is any level butreadorwrite. A page cannot read YAMLite’s state folder, the database (and its-wal,-shmand-journalfiles) or the config files, whateverfilessays: a broad folder entry still gets 403 for them. Symlinks are followed and must stay inside a granted path.- A
writeentry lets the page add, replace and delete files under it, but only pictures and PDFs whose bytes match their extension: never HTML, SVG or anything else that could run script where the files are later served. A page cannot write YAMLite’s own files, or through a symlinked file; a symlinked folder must lead to a path the page may write. Written files land in the working tree like any other edit, so Send for review lists them. Grantwriteonly on folders that hold nothing but what the page should manage. servereads the working tree, so afilesentry also covers files git does not track, such as a local.envor build output. Declare folders that hold only what the page should show.- In an export pages are read-only, and
accessdoes not hide data: the exporteddb.sqliteis downloadable, andsql: truereads every exported table. Pages whoseaccessnames a table left out of the export are skipped with a warning. An export also copies the files a page declares intodata/files/, each stored with a.binsuffix so a host serves it as a download rather than as a page; deploying the export makes them public; a file over 10 MB is skipped with a warning.