feat: migrate protocol and HTTP to structured interface references
T-20: identify interfaces by exact scope/name pairs; add optional opaque scope_ref metadata and separate shape validation from path-dependent scope compatibility. Preserve call error precedence, strict JSON, validators and transport boundaries. Mechanically migrate consumers and document API/wire compatibility and deferred lifecycle semantics. Validation: cargo fmt --all --check; git diff --check; cargo check --workspace --all-targets; cargo test -p wip-protocol -p wip-http; cargo test --workspace (221 passing tests including doctests); cargo test --workspace --all-targets; nix develop --command cargo clippy --workspace --all-targets -- -D warnings; RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps. All pass. cargo/rustc 1.95.0; development-shell Clippy/rustc 1.97.1.
This commit is contained in:
@@ -296,11 +296,14 @@ pub fn decode_observe_request(body: &[u8], limits: Limits) -> Result<ObserveRequ
|
||||
}
|
||||
|
||||
/// Encodes a `fetch_interface` HTTP request.
|
||||
///
|
||||
/// Validates reference shape without requiring a target Object path.
|
||||
pub fn encode_fetch_interface_request(
|
||||
endpoint: &Endpoint,
|
||||
value: &FetchInterfaceRequest,
|
||||
limits: Limits,
|
||||
) -> Result<Request<Vec<u8>>, EncodeHttpError> {
|
||||
value.interface.validate().map_err(CodecError::from)?;
|
||||
let body = json::serialize(
|
||||
&json::fetch_interface_request_to_json(value),
|
||||
BodyKind::Request,
|
||||
@@ -358,6 +361,10 @@ impl CallOperationMetadata {
|
||||
}
|
||||
|
||||
/// Decodes descriptor-independent `call_operation` routing metadata.
|
||||
///
|
||||
/// Reference shape is validated, but scope ancestry and `scope_ref` identity
|
||||
/// are left to Host resolution so `NotFound`, validator failures, and
|
||||
/// `InterfaceMismatch` retain their protocol precedence.
|
||||
pub fn decode_call_operation_metadata(
|
||||
body: &[u8],
|
||||
limits: Limits,
|
||||
|
||||
+49
-14
@@ -8,9 +8,9 @@ use serde_json::{Map, Number, Value as Json};
|
||||
use wip_protocol::{
|
||||
CallOperationRequest, CallOperationResponse, Documentation, EnumCase, FetchInterfaceRequest,
|
||||
FetchInterfaceResponse, FieldDeclaration, INTERFACE_FORMAT_V1, InterfaceDescriptor,
|
||||
InterfaceTarget, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER, Object, ObjectObservation, ObserveRequest,
|
||||
ObserveResponse, OperationDeclaration, ParameterDeclaration, ReturnDeclaration, Target,
|
||||
TypeDeclaration, TypeExpr, UnionCase, Value,
|
||||
InterfaceReference, InterfaceTarget, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER, Object,
|
||||
ObjectObservation, ObserveRequest, ObserveResponse, OperationDeclaration, ParameterDeclaration,
|
||||
ReturnDeclaration, Target, TypeDeclaration, TypeExpr, UnionCase, Value,
|
||||
};
|
||||
|
||||
use crate::{BodyKind, CodecError, Limits};
|
||||
@@ -285,8 +285,25 @@ pub(crate) fn observe_request_from_json(value: &Json) -> Result<ObserveRequest,
|
||||
Ok(request)
|
||||
}
|
||||
|
||||
fn interface_reference_to_json(reference: &InterfaceReference) -> Json {
|
||||
serde_json::json!({"scope": reference.scope, "name": reference.name})
|
||||
}
|
||||
|
||||
fn interface_reference_from_json(
|
||||
value: &Json,
|
||||
field: &str,
|
||||
) -> Result<InterfaceReference, CodecError> {
|
||||
let fields = exact_object(value, field, &["scope", "name"])?;
|
||||
let reference = InterfaceReference {
|
||||
scope: string(required(fields, "scope")?, &qualified(field, "scope"))?,
|
||||
name: string(required(fields, "name")?, &qualified(field, "name"))?,
|
||||
};
|
||||
reference.validate()?;
|
||||
Ok(reference)
|
||||
}
|
||||
|
||||
pub(crate) fn fetch_interface_request_to_json(request: &FetchInterfaceRequest) -> Json {
|
||||
serde_json::json!({"interface": request.interface})
|
||||
serde_json::json!({"interface": interface_reference_to_json(&request.interface)})
|
||||
}
|
||||
|
||||
pub(crate) fn fetch_interface_request_from_json(
|
||||
@@ -294,7 +311,7 @@ pub(crate) fn fetch_interface_request_from_json(
|
||||
) -> Result<FetchInterfaceRequest, CodecError> {
|
||||
let fields = exact_object(value, "request", &["interface"])?;
|
||||
Ok(FetchInterfaceRequest {
|
||||
interface: string(required(fields, "interface")?, "interface")?,
|
||||
interface: interface_reference_from_json(required(fields, "interface")?, "interface")?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -308,8 +325,7 @@ pub(crate) fn object_to_json(object: &Object) -> Json {
|
||||
object
|
||||
.interfaces
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(Json::String)
|
||||
.map(interface_reference_to_json)
|
||||
.collect(),
|
||||
),
|
||||
);
|
||||
@@ -327,7 +343,7 @@ pub(crate) fn object_from_json(value: &Json, field: &str) -> Result<Object, Code
|
||||
let interfaces = array(required(fields, "interfaces")?, "interfaces")?
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, value)| string(value, &format!("interfaces[{index}]")))
|
||||
.map(|(index, value)| interface_reference_from_json(value, &format!("interfaces[{index}]")))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let object = Object {
|
||||
name: string(required(fields, "name")?, "name")?,
|
||||
@@ -745,7 +761,11 @@ pub(crate) fn descriptor_from_json(
|
||||
|
||||
pub(crate) fn fetch_interface_response_to_json(response: &FetchInterfaceResponse) -> Json {
|
||||
let mut fields = Map::new();
|
||||
fields.insert("interface".into(), Json::String(response.interface.clone()));
|
||||
fields.insert(
|
||||
"interface".into(),
|
||||
interface_reference_to_json(&response.interface),
|
||||
);
|
||||
insert_optional_string(&mut fields, "scope_ref", &response.scope_ref);
|
||||
fields.insert(
|
||||
"descriptor".into(),
|
||||
descriptor_to_json(&response.descriptor),
|
||||
@@ -757,8 +777,15 @@ pub(crate) fn fetch_interface_response_to_json(response: &FetchInterfaceResponse
|
||||
pub(crate) fn fetch_interface_response_from_json(
|
||||
value: &Json,
|
||||
) -> Result<FetchInterfaceResponse, CodecError> {
|
||||
let fields = exact_object(value, "response", &["interface", "descriptor", "validator"])?;
|
||||
let interface = string(required(fields, "interface")?, "interface")?;
|
||||
let fields = exact_object(
|
||||
value,
|
||||
"response",
|
||||
&["interface", "scope_ref", "descriptor", "validator"],
|
||||
)?;
|
||||
let interface = interface_reference_from_json(required(fields, "interface")?, "interface")?;
|
||||
let scope_ref = optional(fields, "scope_ref")?
|
||||
.map(|value| string(value, "scope_ref"))
|
||||
.transpose()?;
|
||||
let validator = optional(fields, "validator")?
|
||||
.map(|value| base64_decode(value, "validator"))
|
||||
.transpose()?;
|
||||
@@ -780,6 +807,7 @@ pub(crate) fn fetch_interface_response_from_json(
|
||||
};
|
||||
Ok(FetchInterfaceResponse {
|
||||
interface,
|
||||
scope_ref,
|
||||
descriptor,
|
||||
validator,
|
||||
})
|
||||
@@ -1121,18 +1149,25 @@ fn target_from_json(value: &Json, field: &str) -> Result<Target, CodecError> {
|
||||
|
||||
fn interface_target_to_json(target: &InterfaceTarget) -> Json {
|
||||
let mut fields = Map::new();
|
||||
fields.insert("reference".into(), Json::String(target.reference.clone()));
|
||||
fields.insert(
|
||||
"reference".into(),
|
||||
interface_reference_to_json(&target.reference),
|
||||
);
|
||||
insert_optional_string(&mut fields, "scope_ref", &target.scope_ref);
|
||||
insert_optional_bytes(&mut fields, "validator", &target.validator);
|
||||
Json::Object(fields)
|
||||
}
|
||||
|
||||
fn interface_target_from_json(value: &Json, field: &str) -> Result<InterfaceTarget, CodecError> {
|
||||
let fields = exact_object(value, field, &["reference", "validator"])?;
|
||||
let fields = exact_object(value, field, &["reference", "scope_ref", "validator"])?;
|
||||
Ok(InterfaceTarget {
|
||||
reference: string(
|
||||
reference: interface_reference_from_json(
|
||||
required(fields, "reference")?,
|
||||
&qualified(field, "reference"),
|
||||
)?,
|
||||
scope_ref: optional(fields, "scope_ref")?
|
||||
.map(|value| string(value, &qualified(field, "scope_ref")))
|
||||
.transpose()?,
|
||||
validator: optional(fields, "validator")?
|
||||
.map(|value| base64_decode(value, &qualified(field, "validator")))
|
||||
.transpose()?,
|
||||
|
||||
@@ -12,6 +12,14 @@
|
||||
//! encoded in JSON bodies using canonical RFC 4648 Section 4 base64; this crate
|
||||
//! does not infer WIP validator semantics from `ETag` or `If-Match`.
|
||||
//!
|
||||
//! Interface references use exact JSON objects with required `scope` and `name`
|
||||
//! strings in every position. Legacy strings and display shorthand are rejected.
|
||||
//! Scope is a canonical absolute Worldspace path, not an HTTP endpoint prefix.
|
||||
//! Optional `scope_ref` metadata on fetch responses and call interface targets is
|
||||
//! an opaque string, never base64; absent fields are omitted and null is rejected.
|
||||
//! Call metadata validates reference shape without resolving scope ancestry or
|
||||
//! identity, which remain Host checks with `InterfaceMismatch` precedence.
|
||||
//!
|
||||
//! ```
|
||||
//! use wip_http::{Endpoint, Limits, encode_observe_request};
|
||||
//! use wip_protocol::ObserveRequest;
|
||||
|
||||
Reference in New Issue
Block a user