# Typed HTML and streamed documents SDK 0.5.59 is a private candidate with source 0.4.39, AST maximum 28 and wire 1. It adds a web compilation profile and five explicit Unicode operations. Its finite private web-profile installation is independently accepted. Whole-SDK public distribution remains a separate pending step. Existing public native and Wasm packages retain their earlier profiles. Compile the [example](#canonical-example) with `compileModule(source, {profile:'web'})`. Pure source functions can compose `Html` values. The compiler selects the HTML context of each binding and refuses ambiguous or executable contexts before execution. ```solon {title: name, destination: path |> navigationUrl()} |> html("{{title}}") ``` Text in a body escapes `&`, `<` and `>`. Quoted attributes also escape both quote characters. `NavigationUrl` and `ResourceUrl` validate the original spelling separately from attribute escaping. The first permits fragments, single-slash root-relative paths and absolute HTTPS without credentials. The second permits the latter two. Neither grants permission to fetch a resource. `Record |> htmlJson()` encodes JSON and escapes `<`, `>`, `&`, U+2028 and U+2029. The result can occupy the complete contents of a sole-attribute `script type="application/json"` element or a complete quoted `data-json` attribute. JSON encoding uses ordinary JSON number spelling, including `-0` as `0`. It does not invoke object or array `toJSON` hooks. The supported template subset refuses executable scripts, inline styles and event handlers, foreign namespaces, dynamic names, unquoted dynamic attributes, browser repairs and unsupported table/select/raw-text contexts. Original literal markup is preserved. There is no raw HTML cast. ## Documents ```solon derive fragment: Html = {} |> html("
x
"); derive unit: Document = fragment |> document(); derive page: Document = unit |> repeatDocument(131072); ``` The example describes one MiB of output using a shared immutable child and a repeat count. `appendDocument(other)` shares two children. A document is a rendering plan, so it does not inherit the single-Text concatenation limit. Exact safe byte accounting still rejects arithmetic overflow. ```js import {compileModule, execute} from 'soloncode'; import {openDocumentStream, writeDocument} from 'soloncode/web'; const program = compileModule(source, {profile: 'web'}); const receipt = await execute(program, inputs); const {stream, stats} = openDocumentStream(receipt, 'page', { chunkBytes: 16384, maxBufferedBytes: 16384, maxOutputBytes: null, maxWorkUnits: null, maxPlanBytes: null, }); // A Worker can return new Response(stream, {headers: {'content-type': 'text/html; charset=utf-8'}}). ``` Only an original successful receipt with that named Document output can open it. Copied JSON, matching hashes and foreign receipts confer no authority. Each original root is consumed once. The SDK does not tee, retry or replay it. The stream has a zero high-water mark and produces nothing before a read. Each chunk owns its buffer. UTF-8 scalars stay intact; HTML entities and JSON escapes may cross transport chunk boundaries. Concatenate bytes in order: individual chunks are transport data, not independently mountable HTML. `writeDocument(receipt, name, writable, policy)` waits for each sink write before producing the next chunk. It returns a promise for final counters, with a read-only live `stats` property. A failed write has an unknown delivery outcome and is never retried. Its diagnostic preserves the original `cause`, an `atFailure` snapshot, and final SDK-owned `counters` after cleanup. Counters describe exact output bytes, chunks, work, plan accounting and owned buffer accounting. Plan bytes use explicit node/reference accounting plus retained UTF-8 content; they are not measured heap or RSS. Consumer-retained chunks, the owning Program and receipt, DOM storage and trusted host callbacks have separate costs. Nullable quotas do not promise unlimited machine resources or hard interruption of a hanging host callback. ## Unicode `Text |> trimUnicode()` uses the 25 Unicode 18.0.0 White_Space code points. `trimECMAScript()` adds U+FEFF and excludes U+0085. Neither removes U+200B or U+180E. They perform no normalization. `utf8Bytes()`, `codePoints()` and `utf16Units()` name their counting domains explicitly. Existing Text can contain unpaired surrogates: UTF-8 counting replaces each unpaired surrogate as the existing encoder does, while web sinks refuse it. Existing `len()` and `slice()` semantics remain unchanged. ## Canonical example ```solon fn label(text: Text) -> Html { return {label: text} |> html("{{label}}
"); } solonsky WebPage { input title: Text = "SOLONCODE"; input destination: Text = "/docs/"; derive url: NavigationUrl = destination |> navigationUrl(); derive heading: Html = {title: title, url: url} |> html("Typed HTML & streamed documents