wip_protocol/lib.rs
1//! Canonical transport-independent logical types for the Web Interface Protocol.
2//!
3//! This crate follows the Core Model and `3-protocol.md` without assigning HTTP
4//! routes, methods, headers, URL encodings, or JSON envelopes. The correspondence
5//! between canonical logical concepts and this crate is direct:
6//!
7//! | Canonical protocol concept | Rust API |
8//! | --- | --- |
9//! | Object projection and ordered interface set | [`Object`] |
10//! | Optional object identity / state precondition | `Object::ref` / [`Object::validator`] |
11//! | Interface Descriptor | [`InterfaceDescriptor`] |
12//! | Named declaration and all schema expressions | [`TypeDeclaration`] / [`TypeExpr`] |
13//! | Schema-neutral primitive/composite value | [`Value`] |
14//! | `observe` | [`ObserveRequest`] / [`ObserveResponse`] |
15//! | `fetch_interface` | [`FetchInterfaceRequest`] / [`FetchInterfaceResponse`] |
16//! | Object and interface call preconditions | [`Target`] / [`InterfaceTarget`] |
17//! | `call_operation` | [`CallOperationRequest`] / [`CallOperationResponse`] |
18//! | Stable Host failure taxonomy | [`ProtocolErrorCode`] / [`ProtocolError`] |
19//! | Per-interaction allowed failure codes | [`ProtocolInteraction`] / [`ProtocolErrorCode::is_allowed_for`] |
20//!
21//! [`ProtocolErrorCode`] is a closed set of Host-returned wire failures. After a
22//! Client receives a response, an invalid Object, Descriptor, operation result,
23//! malformed error, or error code disallowed by [`ProtocolInteraction`] is a
24//! Client-local `InvalidResponse`, not another wire error. A descriptor whose
25//! `format` is not supported is a Client-local `UnsupportedDescriptorFormat`.
26//!
27//! For `call_operation`, [`ProtocolErrorCode::Internal`] and
28//! [`ProtocolErrorCode::ResourceLimitExceeded`] guarantee that the operation did
29//! not run or that all effects were rolled back. Only
30//! [`ProtocolErrorCode::OperationOutcomeUnknown`] means the Host cannot make that
31//! guarantee; Clients must not automatically retry it.
32//!
33//! Paths, object refs, interface refs, and validators remain separate concepts.
34//! They are represented by ordinary protocol strings/bytes in the corresponding
35//! fields. In particular, object refs are optional, operation targeting uses a
36//! path, and this crate defines no interaction that fetches an object by ref.
37//!
38//! [`Value`] contains only the canonical raw value kinds. A descriptor interprets
39//! enum values as strings, entries as canonical-path strings, and unions as
40//! records with a `$case` string plus an optional `value` payload. JSON uses the
41//! same value tree (`Unit` is JSON null) and rejects bytes.
42
43#![deny(missing_docs)]
44
45mod error;
46mod model;
47mod validation;
48
49pub use error::{
50 NameNamespace, PathSegment, ProtocolError, ProtocolErrorCode, ProtocolInteraction,
51 ValidationError, ValidationErrorKind, ValueKind,
52};
53pub use model::{
54 CallOperationRequest, CallOperationResponse, Documentation, EnumCase, FetchInterfaceRequest,
55 FetchInterfaceResponse, FieldDeclaration, InterfaceDescriptor, InterfaceTarget, Object,
56 ObjectObservation, ObserveRequest, ObserveResponse, OperationDeclaration, ParameterDeclaration,
57 ProtocolResult, ReturnDeclaration, Target, TypeDeclaration, TypeExpr, UnionCase, Value,
58};
59
60/// Validates a canonical absolute Worldspace path.
61pub fn validate_path(path: &str) -> Result<(), ValidationError> {
62 validation::validate_path(path)
63}
64
65/// Canonical format identifier for the first Interface Descriptor format.
66pub const INTERFACE_FORMAT_V1: &str = "wip-interface/1";
67
68/// Discriminator field used by a union's raw record value.
69pub const UNION_CASE_FIELD: &str = "$case";
70
71/// Optional payload field used by a union's raw record value.
72pub const UNION_VALUE_FIELD: &str = "value";
73
74/// Largest integer exactly interoperable with a JavaScript `Number`.
75pub const MAX_SAFE_INTEGER: i64 = 9_007_199_254_740_991;
76
77/// Smallest integer exactly interoperable with a JavaScript `Number`.
78pub const MIN_SAFE_INTEGER: i64 = -MAX_SAFE_INTEGER;