1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//! What a response means, as against what its bytes are.
//!
//! A recorded query's body goes into the content-addressed store, so it is
//! canonicalised first, exactly as any other input is: two answers meaning
//! the same thing must hash the same, or a cache would miss on a server that
//! reordered its JSON and a drift report would cry wolf every week (D39).
//!
//! # Keys are sorted, and arrays are not
//!
//! Order is meaningless between the keys of a JSON object and meaningful
//! between the elements of an array, so the keys are sorted at every depth
//! and the arrays are left exactly as they came. That is D14's rule — sort
//! what has no order, keep what has — applied to one more format, and D41's
//! reason for a ranked list keeping its order is the same reason an array
//! keeps its own.
//!
//! No number is reformatted. A response carrying a twenty-digit identifier
//! has to be stored with that identifier intact, so numbers are kept as the
//! text the server sent rather than round-tripped through a double. The
//! consequence is that `1` and `1.0` canonicalise differently, which is the
//! honest answer: the engine does not claim an equality it has not
//! verified.
//!
//! # Volatile fields, and the one place it is safe to drop them
//!
//! A `requestId` or a `generatedAt` is the server's account of *how it
//! served this answer*. That is a signature rather than part of the answer,
//! and dropping a tool's signature before hashing is exactly what D22
//! settled for `@PG` lines.
//!
//! They are dropped **only from the top level of a JSON object**, and that
//! line is the whole of the care here. A `timestamp` key at the top of a
//! response envelope is the server describing its own work; the same key
//! inside a data record is what the record *says*, and dropping it
//! recursively would silently delete a time series. D26 draws that line —
//! a field that is part of what the data is about cannot be dropped — and
//! the top level is the one place the two cases can be told apart.
//!
//! Even there a dropped key might have been the user's own data, so every
//! drop is a [`Note`]: the hash stands and the engine says what it saw.
//!
//! # A body that is not JSON
//!
//! Falls back to its bytes, which needs no rule of its own because D21
//! already says canonicalisation falls back to them. A query answered with
//! TSV or plain text is recorded as it arrived.
//!
//! Note the layering: this produces the bytes that go **into** the store,
//! and the stored body is then read as its declared kind by the ordinary
//! loader. A query declared `EntitySet` over a TSV API canonicalises to its
//! bytes here and is parsed as a TSV there.
use ;
use crateForm;
use crateNote;
/// The response-body keys a server writes about itself.
///
/// Matched against a key lowercased with `-` and `_` removed, so
/// `requestId`, `request_id`, `request-id` and `REQUESTID` are one name.
///
/// Closed and listed here, on the reasoning the four locator schemes rest
/// on: a set extensible by configuration would be a promise the engine
/// could not keep, and the failure would be a silently deleted field rather
/// than an error.
const VOLATILE: = ;
/// A response body reduced to what it means.
/// Reduce a response body to what it means.
///
/// JSON is parsed, its keys sorted at every depth and the volatile keys
/// dropped from its top level. Anything that is not JSON is returned as it
/// arrived ([`Form::Raw`]).
///
/// `locator` is only for the notes, so that a run making several queries
/// can say which of them dropped a field.
/// The top-level fields, without the ones a server writes about itself.
/// Whether this key is one a server writes about itself.
///
/// Public to the crate because a knowledge graph's canonical form drops the
/// same closed set from its own top level, and the set is the thing worth
/// having exactly once: a graph fetched from a service and a graph on disk
/// must agree on what counts as a signature, or the same graph would hash
/// two ways depending on how it arrived.
pub
/// A key as [`VOLATILE`] spells it: lower-cased, with `-` and `_` removed.
///
/// So that one name written four ways by four APIs is one name, without an
/// entry per spelling.