Use the generated client
The task example compiles to build/tasks.reception.mjs with an accompanying type declaration file. Import its tasksClient factory to use the model.
Open the example in a test
Section titled “Open the example in a test”import { testHolon } from "@githolon/testing";import { tasksClient, isUnavailableRecord } from "../build/tasks.reception.mjs";
const device = await testHolon({ law: new URL("../build/tasks.law.usdz", import.meta.url), deterministic: true,});const app = device.app(tasksClient, { actor: "person:alice" });These paths are relative to the example’s test file. testHolon opens a temporary workspace using the real runtime. deterministic fixes the test clock and random seed. Use this setup in tests; a deployed application uses its platform host and authenticated participant.
Write and read a task
Section titled “Write and read a task”const { task } = await app.addTask({ text: "Inspect the pump" });const record = await app.tasks.find(task);await app.completeTask({ task });task is a typed reference. Pass it to other operations on that task. find returns a record, undefined for a missing record, or a typed unavailable result when the client cannot read the required fields. A successful local write is not confirmation that another device has received it.
Check the result before accessing its fields:
if (record === undefined) { console.log("Task not found");} else if (isUnavailableRecord(record)) { console.log("Task unavailable", record.members);} else { console.log(record.text);}An unavailable result is not a deleted task. Its member details describe the compatibility problem and whether the app or workspace needs an update. The example’s readTask helper fails the test if the expected record is missing or unavailable.
Read a page
Section titled “Read a page”const page = await app.tasksByDonePages( { done: false }, { pageSize: 20 },);page.rows contains the records. When page.done is false, pass page.cursor to the next call with the same query parameters. Keep the cursor opaque.
Update the screen
Section titled “Update the screen”Use the returned record or repeat the relevant read after an accepted action. In a platform-hosted application, the generated client also exposes subscriptions to receive later changes.
The current Node test harness does not implement the generated query subscription adapter. The runnable example checks writes and explicit reads; it does not demonstrate a reactive UI. Calling watchTasksByDone through this harness currently throws holon.__nomosWatchResults is not a function.
Handle a rejected change
Section titled “Handle a rejected change”import { Refusal } from "@githolon/testing";
await expect(app.addTask({ text: "" })).rejects.toBeInstanceOf(Refusal);This is the test assertion for an invalid payload. The example also checks that the history is unchanged. In a UI, handle a failed action and explain the relevant validation error to the user; do not mark the operation as saved on failure.
Keep runtime failures distinct from validation refusals. A runtime that could not open or read a workspace has not established that a business action is invalid.
Next: offline work and sync.