Expression AST transport
Rust owns the expression syntax and wire declarations. The AST transport in
erp_expr::wire is schema version 1: an ordered node arena with the root last.
An edge refers to an earlier node, every other node has exactly one parent,
and no unused node is admitted. Literal integers use canonical decimal strings;
floating-point literals use hexadecimal binary64 bits. Do not convert integer
payloads through JavaScript number.
On the producer, parse source with erp_expr::parse, then serialize with
erp_expr::wire::encode. Both can fail. ValidatedAst::from_json validates
received transport bytes before exposing an immutable Rust AST through
as_expr(). A raw WireDocument deserialized by serde is still untrusted;
convert it through ValidatedAst::try_from before evaluation. Encoding checks
public AST values too, including trees constructed without the source parser.
The crate’s wire rustdoc contains an executable roundtrip example.
JSON numbers used for schema versions, child indices and bytes have value semantics:
0, 0.0 and 0e0 are equivalent. After binary64 rounding, the number must be an
integer within the field’s range. Literal integer payloads remain canonical strings.
To match browser Number rounding, erp-expr enables serde_json’s float_roundtrip
feature. Cargo feature unification also enables that decimal-parsing behavior in other
workspace consumers of the same serde_json dependency. Its performance impact outside
expression transport has not been measured.
In the browser, @erpforall/expr supplies readResponseJson for a streamed
response and parseBoundedJson for bounded text or UTF-8 bytes. The parser
rejects duplicate keys throughout the response, malformed Unicode, excessive
depth, and byte/allocation-ledger limits. Its returned containers are frozen.
After the owning view decoder validates its description’s shape, create one
DescriptionBudget for that parsed description subtree and pass that same
budget to each decodeAst call in the description. This counts expressions
and nodes together and includes nonexpression wrapper bytes in the byte cap.
decodeAst accepts only containers authenticated by the bounded reader; a
handwritten object or TypeScript cast is insufficient. Check isValidatedAst
when accepting a handle across another runtime trust boundary.
Limits may be lowered, never raised or disabled by zero. AST rejection returns
an InvalidAst kind, JSON path and diagnostic; it is distinct from a Python
evaluation exception. A schema-version mismatch requires reloading/upgrading
compatible client/server code. Consumers must surface the failure, rather than
rendering a partial view or substituting a false modifier.
The AST child supplies decoding, not the client evaluator. Evaluation and signal adapters remain the later UIX children; production view descriptions and response integration belong to WEB-SERVER-BASE and the view slices.
Schema maintainers enable the nondefault Rust schema-gen feature only in
tooling. scripts/gen-ui-types.sh --write refreshes the complete managed
declaration set; --check detects missing, extra or changed declarations
without editing them. The test-only nested response proves the derive path;
it is not a production view description. Import the generated wire declarations
through the package’s type-only @erpforall/expr/wire export.
Generator and test-only producer boundaries
Section titled “Generator and test-only producer boundaries”The generator pins optional ts-rs to 11.1.0. Its
documented export API
exports the registered roots and their dependencies to .d.ts files; the
version’s licence is MIT.
Run generation through the authorized remote build workflow. Enabling
schema-gen in production or wasm dependencies is not supported.
ts-rs reports that it ignores serde’s deny_unknown_fields and custom
deserialize_with admission attributes. These warnings remain visible.
The declarations describe JSON shape: they cannot enforce duplicate rejection,
integer bounds, canonical integer strings, float-bit syntax or mandatory-field
admission. For example, slice bounds and keyword names are required nullable
fields, and integer/float literal payloads remain strings. Keep the Rust and
browser runtime validators; do not remove fields with ts(skip) or disable
warnings globally to conceal an admission mismatch.
examples/support/schema.rs contains a test-only nested producer with
to_json_with_limits. It validates each raw expression, checks the expression
and aggregate-node counts, and serializes through a bounded writer that includes
description wrapper bytes and the complete response. Limit overrides must be
positive and may only lower the current limits. Failures return a typed error;
no partial response is returned. This helper encodes each expression once for
validation and again in the nested output. It proves the transport contract,
not the production view serializer’s performance; the owning view slice must
supply that implementation.
The ui_fixtures tooling example has separate goldens and differential
modes. goldens includes the authoritative Rust golden table and copies its
ordinal, source, success flag and expectation unchanged alongside its parsed
AST. differential labels a bounded seeded Rust oracle with its context and
limits, retaining source-parse failures as rows. The generated corpus also records
operation family, case and seed. web-expr-fuzz-smoke compares the browser’s actual
repr or PythonError class and complete text against Rust for every parsed row;
parser outcomes are replayed by the Rust exporter harness. The browser has no
source parser. Seeded fast-check properties shrink failures within the finite row
index domain; hostile wire properties shrink their generated fields/indices.
Ignored logs/uix-fuzz/ artifacts record the seed, shrink path, row or wire,
limits and context. Committed replay files are read-only regression inputs.
Neither generated mode changes the authoritative CPython expectations.
Generating TypeScript from validated wire types
Section titled “Generating TypeScript from validated wire types”Expression and human-view DTOs run their Serde derives before the optional
erp_macros::wire_ts attribute. The schema tool passes serialized names, tags,
optional fields and flattening through to ts-rs. Input validators such as
deserialize_with and deny_unknown_fields are enforced by Serde even when
schema-gen is enabled. A scalar newtype can use Serde conversion into its stored
wire type. A different outgoing type requires a schema that describes that type.
Run scripts/gen-ui-types.sh --check and compare the human_ui_schema output with
addons/web/static/src/generated/human-ui.ts after changing either wire contract.