Restricted card host types
@erpforall/expr/restricted-host is a type-only entry point for the version 1 card
host contract.
It describes capabilities for the restricted JavaScript card language. The Python
modifier evaluator remains a separate API.
Declare the fields, context keys and registered helper signatures that a card can
use. Names are closed: a declared field does not grant access to every record
field, and a declared helper does not grant access to arbitrary JavaScript
functions. Fields, Context and Helpers must have finite, explicitly declared
key sets: broad string, number and symbol index signatures are rejected. The same
restriction applies recursively to field data, context data and helper arguments
and results. Open dictionaries are permitted only by the explicit JSON data type
accepted by JSON.stringify; JSON.parse still returns unknown, which requires
validation before use. This example is checked in
web/packages/expr/tests/restricted-host.types.ts:
import type { RestrictedCardHostV1 } from "@erpforall/expr/restricted-host";
type Fields = { title: string; total: number; tags: readonly string[] };type Context = { lang: string; active_ids: readonly number[] };type Helpers = { badge: (label: string, total: number) => string };declare const host: RestrictedCardHostV1<Fields, Context, Helpers>;const title: string = host.record.title.value;const rawTotal: number = host.record.total.raw_value;const badge: string = host.badge(title, rawTotal);Field values are readonly wrappers: value is formatted text, raw_value retains
the declared data type, and name is the declared field name. record.id is an id
wrapper with numeric-or-false value and raw_value. The ADR’s shorthand
record.id includes that wrapper: the pinned Community card context and the
extracted card corpus use record.id.raw_value. record.context and context
retain only the explicitly declared context keys. Nested data and arrays are
readonly. Addon helpers are registered code; they are never supplied as functions
in template data, cannot replace a builtin host name, and cannot use prototype
names.
The contract names widget flags and selection/read-only mode flags, the specified
Luxon DateTime construction and instance methods, duration results, JSON
parse/stringify, pure Math members, Array.isArray, scalar conversions and the
listed image, colour and formatting helpers. The Math list is explicit and omits
random. The Luxon list is explicit, rather than importing the full library type.
JSON.parse returns unknown, so a helper consuming its result must validate or
narrow it. A host implementation must enforce its data and resource limits when
parsing JSON; a TypeScript return type does not establish runtime admission.
Keep the V1 contract stable. A later addon may add declared fields or helpers without changing existing signatures. An incompatible contract requires a new versioned type; editing V1 would break existing consumers. This slice adds no runtime registration service or shared state.
These declarations provide authoring checks, not sandbox enforcement. TypeScript structural types and primitive/array methods cannot establish a secure member allowlist. A later delivery owns static and computed member admission, the runtime host membrane and quotas, unknown-member errors, the restricted grammar, and markup and URL sanitisation. Importing this type-only entry point does not activate those features or certify a card as safe. The compile contract tests are part of the web workspace typecheck; runtime enforcement has no acceptance result in UIX-DONE.
Corpus maintenance and evaluation evidence
Section titled “Corpus maintenance and evaluation evidence”docs/specs/corpus/card-expr-corpus.json retains occurrences from the exact Community tree pinned in
bench/odoo/ODOO_COMMIT. The extractor reads Git objects, so refreshing the source checkout does not
silently change historical provenance. Run regeneration in a configured build environment:
python3 -I scripts/card-expr-corpus.py --odoo-root /path/to/odoo-referenceThe docs CI lane regenerates and compares bytes. Its source checkout must contain the pinned commit;
a missing object fails the check. Copy generated data back to the author branch and review the diff.
After changing the corpus or Rust fixture tooling, regenerate scripts/ui-generated.py --write on the
build host and preserve its source/output identity manifest with the generated oracle.
The structural corpus includes card template roots in kanban views and standalone card/menu templates. Inherited xpath fragments outside those roots are excluded; it does not reconstruct effective database views. The Python-compatible expressions run against both expression implementations over 1,000 seeded fixture records. Named JavaScript-only exclusions are pinned visibly. Agreement does not establish restricted JavaScript behavior, sanitisation, or effective inherited-view coverage. UI2-DONE owns that admission gate.