Skip to main content

zenkey_model/
lib.rs

1//! zk2 keys and contracts, without a Zenoh session.
2//!
3//! This is the static half of zk2 (epic #585, issue #608): everything that
4//! can be decided from files, and never needs a bus. The design of record is
5//! `docs/zk2/architecture.md` (r4), stated normatively by `spec/core.md`;
6//! the authoring format is draft 3
7//! (`examples/zk2/README.md`).
8//!
9//! Layer map:
10//! - [`chunk`]: the plain-chunk charset and the small lexical predicates.
11//! - [`slug`]: canonical, injective slugging of foreign values into chunks,
12//!   ported unchanged from v1.
13//! - [`grammar`]: the zk2 key grammar. Data keys, instance and interface
14//!   tokens, member tokens and contract keys, as typed values over
15//!   `zenoh_keyexpr::OwnedKeyExpr`, with a parser that refuses anything
16//!   outside the grammar; and §1.3's selectors: the ambient one, the exact
17//!   kind selectors, and the verbatim chunks a selector cannot reach
18//!   ([`grammar::blind_spots`], #614 FL4).
19//! - [`template`]: resource templates, with build, match, overlap and the
20//!   most-literal-first precedence (r3.3 D1).
21//! - [`authoring`]: the TOML authoring format, draft 3, as serde types;
22//!   `spec/contract.schema.json` is generated from them.
23//! - [`diag`]: diagnostics with stable codes, the conformance surface of
24//!   the lints.
25//! - [`schema`]: schema artifacts (protobuf through `protox`, JSON Schema)
26//!   and type resolution.
27//! - [`contract`]: the contract model: defaults expanded, types resolved,
28//!   every lint run; or read back from a bundle
29//!   ([`contract::Contract::from_bundle`], #611).
30//! - [`canonical`]: the canonical JSON form, its restrictions, and the
31//!   fingerprint.
32//! - [`bundle`]: the bundle container, built and verified Merkle-style.
33//! - [`history`]: the append-only `.history` of published revisions.
34//! - [`compat`]: the FULL_TRANSITIVE compatibility classifier (spec §9.8),
35//!   over revisions from contracts or bundles, and the retention rule's
36//!   identity check.
37//! - [`budget`]: the population budget (core §2.7, 0.24; #735): a
38//!   templated resource's bound in an instance, what an event's `rate`
39//!   bounds, and the pure judgement of a reading against them. The reads
40//!   are the tools'.
41//! - [`catalog`]: the deployment catalog (core §8.6; #980 C1a): its
42//!   reading with §8.6's refusals, its id, append-only succession, and a
43//!   reader's resolution of the catalog an owner names, through a
44//!   successor below its predecessor's count. It holds the deployment
45//!   epoch and each revision's index; provisioning it is the deployment's.
46//! - [`descriptor`]: the descriptor record an instance serves, checked
47//!   against its contracts; `spec/descriptor.schema.json` is generated
48//!   from it.
49//! - [`envelope`]: a failed call's error in its error form (core §5.2,
50//!   §7.5), read by its `Encoding` first, and an `app` error's detail.
51//! - [`decode`]: a payload decoded from a bundle alone, for tools (§7.2).
52//! - [`validate`]: a value checked against a JSON Schema type of a bundle,
53//!   the §7.3 subset and nothing more, for tools that build a payload from
54//!   JSON (#671).
55//! - [`hostid`]: `hostid.v1`'s derivation of a system from a machine id
56//!   (`spec/profiles/hostid/v1.md`, #719). The inputs, the shared file and
57//!   failing closed are the runtime's.
58//! - [`freshness`]: `freshness.v1`'s horizon and its pure judgement of a
59//!   member's freshness (`spec/profiles/freshness/v1.md`, #720). The
60//!   owner's re-puts are the runtime's.
61//! - [`words`]: words by table, what the profiles whose records carry an
62//!   index where an earlier major carried text share (`desired.v2` §2.10,
63//!   `health.v2` §2.10; #986): an index read as its table's entry, its
64//!   number or `out_of_range`, a word written as its index, an
65//!   annotation's value read as a table, and a lint's finding.
66//! - [`seed`]: a late joiner's merge (core §4.2, 0.26; 0.27, #752): per
67//!   key, which arriving sample replaces what is held, by the stamp — an
68//!   unstamped sample ranked below every stamped one, equal times ordered
69//!   by the id as zenoh orders it. The GET and the subscription are the
70//!   tools'.
71//! - [`health`]: `health.v1`'s levels, fault codes, and its pure judgement
72//!   of one reading of a service, on top of [`freshness`]
73//!   (`spec/profiles/health/v1.md`, #721). The owner's puts and its
74//!   `clock_ahead` fault are the runtime's. [`health::v2`] is
75//!   `health.v2`'s (`spec/profiles/health/v2.md`, #986): the three packed
76//!   records, words by table (the profile's and the service's own), a late
77//!   joiner's two snapshots and whether they are one instant, and a clock
78//!   question the last read heartbeat's time answers. The judgement is one
79//!   for both majors ([`health::judge_status`], [`health::Major`]).
80//! - [`config`]: `config.v1`'s wire types, its validators, the window,
81//!   redaction, and a pure state machine of one owner's configuration
82//!   (`spec/profiles/config/v1.md`, #768). The device, the persisted layer
83//!   and the timers are the runtime's.
84//! - [`link`]: `link.v1`'s exposure, the face policy a deployment writes
85//!   and its lints, the plan a generator derives from both (denies, one
86//!   downsampling rule per concrete key, the attachment, window floors,
87//!   liveness evidence), and the checks of a router's block
88//!   (`spec/profiles/link/v1.md`, #769). The router's configuration is the
89//!   generator's.
90//! - [`alarms`]: `alarms.v1`'s key recipe, byte for byte ZenSight's, with
91//!   its sanitizing step; the document and its checks; one key's samples
92//!   read into transitions; a reference to an alarm; and §5's questions,
93//!   on top of [`freshness`] (`spec/profiles/alarms/v1.md`, #800). The
94//!   owner's puts, its confirmations and its adoption at a restart are the
95//!   runtime's. [`alarms::v2`] is `alarms.v2`'s
96//!   (`spec/profiles/alarms/v2.md`, #984): the packed record on a slot, the
97//!   service's table of rules and its lints, slot choice, words taken by
98//!   the key, transitions by identity, and what one complete snapshot
99//!   establishes; [`alarms::Major`] says which a descriptor is read by.
100//! - [`telemetry`]: `telemetry.v1`'s vocabulary and standard schema, the
101//!   declaration read from a resolved resource, one sample's conformance
102//!   with the member's kind and unit, and a pair's continuity and rate, its
103//!   epoch in-band or from presence (`spec/profiles/telemetry/v1.md`,
104//!   #819). The owner's in-band epoch is the runtime's.
105//! - [`desired`]: `desired.v1`'s vocabulary and standard schema, the
106//!   declaration read from a resolved resource, a requirement's binding and
107//!   its slice's key, the standard `Report` with its reading and its
108//!   consistency, a target's pure two-phase state machine (each version
109//!   ordered by its author's stamp, acted on once, the same document
110//!   adopted without an act, refused whole or reverted), and §5's four
111//!   questions (`spec/profiles/desired/v1.md`,
112//!   #840). The author's writes and record, and the target's subscription,
113//!   seed and archive read, are the runtime's. [`desired::v2`] is
114//!   `desired.v2`'s (`spec/profiles/desired/v2.md`, #986): a version its
115//!   put's in-band stamp, written `<run>/<seq>`; the same state machine
116//!   over runs and seqs, with a snapshot with no entry; the watch of the
117//!   author's heartbeat; the packed `Report`, a refusal's place and line
118//!   indices into the report resource's two tables; and the same judges.
119//! - [`redundancy`]: `redundancy.v1`'s vocabulary, the declaration read
120//!   from a contract (governed, its election `claim` or `external`), how
121//!   instance ids compare, the descriptor's standby mark read and checked,
122//!   the election's decision over one read and the heal's over two, one
123//!   candidate's pure two-phase state machine (claim, stand by, take over,
124//!   step down), and §5's four questions of an address and an instance
125//!   (`spec/profiles/redundancy/v1.md`, #841); and `redundancy.v2`'s
126//!   (`v2.md`, #987): its declaration, either major read, a descriptor's
127//!   run, the follower's fence by `meta.zid` or by run with its hold for
128//!   one read, the draw, and an address's governance from both majors. The
129//!   reads, the watch, the timers, the lock and the acts in core §8.2's
130//!   order are the runtime's.
131//! - [`timing`]: `timing.v1`'s vocabulary, the declaration read from a
132//!   resolved resource (a stream's period, deadline and lifespan), a
133//!   reader's deadline tracker for one provider and resource as a pure state
134//!   machine (missed, met and ended, edge-triggered, its detection bound,
135//!   the members it holds under the bound), one sample's lifespan on the
136//!   deployment's stated bound, the period over a tool's window, and §5's
137//!   three questions (`spec/profiles/timing/v1.md`, #908). The subscription,
138//!   the timer, the presence it follows and the stamps it reads are the
139//!   runtime's.
140//! - [`arbitration`]: `arbitration.v1`'s vocabulary, a role's declaration
141//!   read from its contract's requirement and the revision of the required
142//!   interface held (the first profile to read a requirement's
143//!   annotations), the ranking of a binding's providers, one role's
144//!   arbitration as a pure state machine (eligibility by the deadline and
145//!   by withdrawals, re-admission by a token or a read, a move of the watch
146//!   held back, the active provider and its switches, the dead-man), and
147//!   §5's three questions (`spec/profiles/arbitration/v1.md`, #909). The
148//!   subscription, the watch, the reads, the timer and the safe value are
149//!   the runtime's and the application's.
150//! - [`packed`]: the `packed` type kind (core §7.6, 0.75; #979 B1): its
151//!   schema file and lints (E038 to E045), each type's layout, its layout
152//!   form and tag, and an interpreted codec over JSON values, exact in its
153//!   fixed point: the source of truth generated code (B2) matches.
154//! - [`frame`]: frames (core §7.7, 0.83; #981 K1): a frame resource's
155//!   `frame` table resolved (E048), its layout over a packed record type
156//!   with no marker, the frame form and tag, and one body read and written
157//!   back, with §7.7's refusals. A reader's field states across frames are
158//!   K2's, the owner's writer K3's.
159//! - [`wire`]: the zk2c envelope (core §7.5, 0.72; #976): CH's form, run
160//!   width and tag, the run and the seq, a put's mutation and a delete's
161//!   attachment, parsed without a contract with §7.5's refusals and written
162//!   back byte for byte. Defined ahead of its use: no rule adopts it yet,
163//!   and nothing else in the workspace reads or writes one.
164//! - [`forms`]: a call's forms by its operation's types (core §5.1, §5.2,
165//!   0.94; #985's C4c): each type's tag and a packed type's layout, the
166//!   request, value, summary and error written, and an owner's read of a
167//!   request, refused `invalid_request`.
168//! - [`heartbeat`]: the zk2c envelope's form 6 (core §7.5, 0.81; #978's
169//!   F1): a revision's collections (its `state` and `@state` resources with
170//!   a horizon above 0) as a [`heartbeat::Layout`] with its tag, a body
171//!   read and written with them and §7.5's refusals, and a collection's
172//!   [`heartbeat::Digest`]. `freshness.v2` adopts it (core 0.82; #978's
173//!   F3): [`freshness::uses_v2`], and a reader's [`freshness::View`]. Its
174//!   second layout, the owner heartbeat (core 0.108; #1110's H1, adopted
175//!   by no rule yet), is a [`heartbeat::OwnerHeartbeat`] of
176//!   [`heartbeat::Group`]s, one for each covered interface: the groups
177//!   read with no contract, then each one's sections with its revision.
178//! - [`collection`]: the zk2c envelope's form 7, a collection's snapshot
179//!   (core §7.5, 0.97; #977's E1): a GET reply's page, its body read and
180//!   written with §7.5's refusals, a snapshot cut into pages under a page
181//!   size, and a complete set of pages assembled. Defined: no rule adopts
182//!   it yet (E2 reads it, E3 has owners write it).
183//!
184//! No item here opens a session or depends on `zenoh`: build scripts, CI
185//! tools and the Python verifier's fixtures all stand on this crate.
186
187pub mod alarms;
188pub mod arbitration;
189pub mod attachment;
190pub mod authoring;
191pub mod budget;
192pub mod bundle;
193pub mod canonical;
194pub mod catalog;
195pub mod chunk;
196pub mod collection;
197pub mod compat;
198pub mod config;
199pub mod contract;
200pub mod decode;
201pub mod descriptor;
202pub mod desired;
203pub mod diag;
204pub mod envelope;
205pub mod forms;
206pub mod frame;
207pub mod freshness;
208pub mod grammar;
209pub mod health;
210pub mod heartbeat;
211pub mod history;
212pub mod hostid;
213pub mod link;
214pub mod packed;
215pub mod redundancy;
216pub mod schema;
217pub mod seed;
218pub mod slug;
219mod strict;
220pub mod telemetry;
221pub mod template;
222pub mod timing;
223mod toml10;
224mod unbundle;
225pub mod validate;
226pub mod wire;
227pub mod words;