Skip to main content

is_wit_world_ref

Function is_wit_world_ref 

Source
pub fn is_wit_world_ref(s: &str) -> Result<(), String>
Expand description

Predicate: assert that s is a valid WIT (WebAssembly Component Model) world reference — the canonical shape every typed :contratos :wit value carries. The contract — modeled on the WIT IDL grammar (namespace:package(/interface)*(@version)?) restricted to the lowercase subset the pleme-io substrate dispatches on:

  • 1..=WIT_IDENT_MAX_LEN (128) bytes;
  • no whitespace, no control characters, no non-ASCII bytes;
  • exactly one : separator splitting the namespace from the package — wasi:http/proxy, nats:pub-sub, wasi:keyvalue/store (no : = there’s no namespace to dispatch on; multiple : = the package half can’t parse);
  • an optional /-separated interface suffix (one or more segments — the WIT grammar allows ('/' id)+ after the package);
  • an optional @<version> suffix (one trailing @ only; the version body is a structurally valid SemVer 2.0.0 version — non-empty, restricted to the accepted set [0-9A-Za-z.\-+], AND round-trippable through semver::Version::parse: three-part major.minor.patch numeric core mandatory (two-part 1.0 and four-part 1.0.0.0 reject), no leading zeros in numeric identifiers (01.0.0 rejects), no empty pre-release / build- metadata identifiers (1.0.0- and 1.0.0-.rc1 reject); the WIT IDL binds simple-version to SemVer verbatim so every byte-set- valid but shape-invalid version body fails the upstream WIT parser at consume time);
  • every identifier segment (namespace, package, each interface) is a lowercase kebab-case ASCII identifier: [a-z]([a-z0-9]|-)*, starting with a lowercase letter, no consecutive -, no trailing -.

Lowercase-only is deliberate — the substrate’s crate::aplicacao::WitContract::is_http / is_pubsub / is_store dispatch keys off the lowercase canonical prefix (wasi:http/, nats:, wasi:keyvalue/, kafka:, kv:, http:). An uppercase WASI:HTTP/proxy is structurally a valid WIT identifier under the upstream IDL grammar but silently falls through every is_* arm and renders as a capability-only L4-only edge — the canonical “I thought I had L7 HTTP routing, got L4-only” footgun. Lifting the lowercase rule to caixa-build time makes the dispatch reachable-by-construction: every validated :wit value matches exactly one of the three typed dispatch arms (or the explicit capability arm), structurally.

Returns the parser-shaped reason on rejection (without wrapping in any error variant) so each per-axis caller — WitContract::target for the :contratos :wit axis at validate time, the future M4 CR materializer’s per-contract WIT validator, the future per-edge WIT registry resolver — wraps the same reason in its own typed *Invalid { <axis>, reason } variant. The reason wording is axis-agnostic (“WIT identifiers allow only [a-z0-9-]”) so every call site reading the same diagnostic points at the same rule; drift between any two axes’ rule enforcement is a build error visible at this predicate, not a per-renderer “this passed validate but silently demoted to capability-only” surprise.

Empty input is rejected here (defensively) and at the call site via the narrower crate::AplicacaoError::EmptyWit variant — the same empty-first cascade is_dns_1123_label and is_gateway_api_http_path carry.

Lifted as a typed substrate-side primitive on the same trajectory the M2-overlay and label-selector helpers (9e3a057, 9d09cfb, 9dbeafd, 31455a7, 07a4544) and the value-shape predicates (is_dns_1123_label, is_gateway_api_http_path) already follow — the typed slot’s valid set matches its dispatch’s accepted set, structurally.

§Errors

Returns the parser-shaped reason naming the specific violation (length / separator / character-class / kebab-shape / SemVer 2.0.0 structural invariant), without wrapping in any error variant — every caller maps the same String into its own typed *Invalid { <axis>, reason } enum variant.