Expand description
§themql-core
Canonical owner of theMQL’s core type identities: Message, Query,
Response, Error, Context, and Resource identity.
Every other crate in theMQL is subordinate to this one for type
definitions. See specs/core.toml for the authoritative specification.
§Authority
Per SPEC.toml and prompts/SYSTEM.md, the canonical types here are
the semantic owners. Transport adapters (themql-mqtt,
themql-graphql, themql-sse) project these types; they do not
redefine them.
§Example
use themql_core::{Message, MessageId, Subject, Operation, Payload,
Metadata, Timestamp, TimestampKind};
let subject = Subject::from_str("vehicle.sensors.imu.gyro")
.expect("valid subject");
let msg = Message {
id: MessageId::new(),
timestamp: Timestamp::now_monotonic(),
subject,
operation: Operation::Telemetry,
payload: Payload::Unit,
metadata: Metadata::default(),
};
assert_eq!(msg.operation, Operation::Telemetry);Structs§
- Cache
Policy - Policy controlling how a
Queryresult is cached. Carried inContextand optionally overridden onQuery.cache_policy. - Cancellation
- Cancellation signal propagated through the resolution chain. A
resolver must check cancellation before returning a result and
return
ErrorCode::Timeoutif cancelled. - Causation
Id - Links an
Eventback to theCommandthat caused it. Required on Events; optional elsewhere. - Context
- Execution context propagated through every query resolution and command dispatch. Carries deadline, auth principal, trace id, cache policy, and cancellation signal.
- Correlation
Id - Links a
Response(or error) back to theQuery/Commandthat caused it. Required on Responses; optional on commands/events. - Deadline
- Absolute deadline for a
Queryresolution orCommanddispatch. Carried inContext. Resolvers must check the deadline before returning a result and returnErrorwith codeErrorCode::Timeoutif exceeded. - Error
- The canonical error type. Transport adapters project this into GraphQL errors, MQTT error topics, SSE error frames, etc. Transport adapters must not define their own error types.
- Field
Path - A dot-joined path into a resource (e.g.
position.x). - Message
- The fundamental primitive. Every request, command, event, stream,
response, telemetry reading, and error is carried by a
Message. - Message
Id - Unique identifier for a
Message. Wraps a UUID v7 (monotonic-ish). - Metadata
- Key-value bag carried on every
Message. Holds correlation id, causation id, trace id, auth principal, format hint, and arbitrary extension keys. - Principal
- Auth principal carried in
Metadata. - Projection
- Optional field projection narrowing which fields of each selected
entity appear in the
Response. Combined withSelection, this completes the ‘filter + projection’ shape. - Query
- A read-only, side-effect-free request against a named
Resource. AQueryis always carried inside aMessagewithoperation = Query. - Resource
- A named, addressable entity in theMQL. Every
Querytargets aResource. Resources have a hierarchical identity (aSubject). - Response
- The result of a
QueryorCommand. Carried inside aMessagewithoperation = Response. AResponsecontains either a value or anError; never both, never neither. - Subject
- A concrete, hierarchical, dot-separated routing key.
- Subject
Pattern - A
Subjectthat may contain wildcards. Used for subscriptions and cache invalidation patterns, never as a concreteMessage.subject. - Subject
Segment - A single non-empty segment of a
Subject. - Timestamp
- Timestamp on every
Message. Tagged explicitly so consumers know whether to trust it for ordering. - TraceId
- Trace identifier for distributed tracing.
Enums§
- Cache
Tier - Tier of the cache stack.
- Comparison
- Comparison operator for a selection predicate.
- Error
Code - Canonical error code. Transport adapters project this into GraphQL errors, MQTT error topics, SSE error frames, etc.
- Format
Tag - Tag identifying the serialisation format of a payload.
- Invalidation
Hint - Hint to the cache about when to invalidate an entry.
- Operation
- The verb of a
Message. Tags payload semantics. - Pattern
Segment - A single segment of a
SubjectPattern. - Payload
- Explicitly typed, serde-serialisable payload of a
Message. The format is tagged in the payload itself (never inferred from transport). - Predicate
- A boolean predicate tree over resource fields.
- Response
Value - The value carried by a successful
Response. MirrorsPayloadbut is a distinct type so transports can project independently. - Selection
- Optional filter predicate selecting a subset of a resource. Combined
with
Projection, this forms the ‘filter + projection’ shape: aQuerywithselection = Allreturns all entities of the resource;selection = Filter(p)narrows which entities are returned. - Subject
Error - Errors raised while constructing or parsing
Subject/SubjectPattern. - Timestamp
Kind - Kind of timestamp — monotonic vs wall-clock.
Traits§
- Message
Handler - Handler for incoming messages.
- Query
Executor - Orchestrator around
Resolver: applies caching, batching, deadline propagation, and cancellation checks. Declared here so transport adapters can depend on the trait without a hard dep on themql-query; implemented in themql-query. - Resolver
- Resolver for queries against a resource. Implementations are domain-specific (storage, analysis, telemetry).
- Resolver
Boxed - Blanket adapter: any
Resolverwhoseresolvereturns aSendfuture can be boxed intodyn Resolver.