# 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("
{{title}}
"); derive body: Html = label("Typed HTML & streamed documents"); derive content: Html = {heading: heading, body: body} |> html("
{{heading}}{{body}}
"); derive page: Document = content |> document(); derive titleBytes: Int = title |> utf8Bytes(); output page; output titleBytes; } ``` The canonical example composes typed fragments and a navigation URL into one Document. With its default inputs, the expected output is: ```html
SOLONCODE

Typed HTML & streamed documents

``` Its separate `titleBytes` output is 9. The URL is navigation DATA; constructing it does not perform an HTTP request. The [document consumption rules](#documents) describes the single-consumption boundary. The separate [all-twelve-stage example](#all-twelve-stages) uses every web and Unicode stage in this guide. Its default Document contains three identical 167-byte articles, totaling 501 UTF-8 bytes. Its Unicode sample has 19 UTF-8 bytes, nine code points and ten UTF-16 units. One first local Source check for each canonical example matched its complete manually fixed output; neither check opens a network connection or invokes an adapter. ## All twelve stages ```solon solonsky WebStages { input title: Text = "A & B"; input destination: Text = "/docs/"; input resourcePath: Text = "/assets/plates/workflow-ribbon.png"; input sample: Text = "\u0020\u0085\uFEFFA\u0301\uD83D\uDE00\uFEFF\u0085\u0020"; derive navigation: NavigationUrl = destination |> navigationUrl(); derive resource: ResourceUrl = resourcePath |> resourceUrl(); derive payload: HtmlJson = {label: "demo"} |> htmlJson(); derive article: Html = {navigation: navigation, resource: resource, payload: payload, title: title} |> html("
{{title}}\"Workflow\"
"); derive unit: Document = article |> document(); derive repeated: Document = unit |> repeatDocument(2); derive page: Document = repeated |> appendDocument(unit); derive unicodeTrim: Text = sample |> trimUnicode(); derive ecmaTrim: Text = sample |> trimECMAScript(); derive bytes: Int = sample |> utf8Bytes(); derive points: Int = sample |> codePoints(); derive units: Int = sample |> utf16Units(); output page; output unicodeTrim; output ecmaTrim; output bytes; output points; output units; } ``` ## Verification and delivery boundaries The typed HTML, Document and Unicode core has 255 accepted checks in each of Node.js 24 and Node.js 22. Its separate Chromium scope contains 53 observations: 10 templates, 38 URL constructions and five document streams. Unicode stage operations have separate Core, JavaScript and Python checks; they are not those browser observations. The local build and development toolchain covers 20 unique Source definitions: 19 successes from the first attempt and one separately selected corrected negative observation. The original failed observation is retained. The application and adapter guides describe their separate finite checks. Local Cloudflare integration has independently accepted eight cases and 90 controller assertions against synthetic D1 and an original Document response. These counts do not form an overall completion percentage. The installed Node.js 24 coverage combines 377 original definitions: 374 earlier observations and three separately checked CLI definitions. Node.js 22 combines 376 original definitions: 373 earlier observations and three CLI definitions, plus one distinct fresh-close criterion. This is the independently accepted union of retained outcomes, not one all-377-pass run. Original data and harness failures remain separate records. Core execution and private standalone JavaScript support the new web profile. Emitted web modules have their own receipt issuer and document consumers. Python supports the new Unicode operations and explicitly refuses web values. Older wire/native/Wasm profiles refuse unsupported types or AST versions. Generated web JavaScript is currently a private build artifact containing runtime implementation. Public browser delivery requires a separate privacy review. This source candidate is not a public SDK archive or production database deployment. The implementation, source maps and readable SDK archives remain closed. Public native and Wasm downloads are unchanged. Local synthetic database checks do not establish a production Cloudflare deployment, distributed recovery or model-cost result. See [web applications](web-application.md), [HTTP and D1 adapters](web-effects.md) and [build tools](web-build.md).