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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//! Query and ordering surface for presentation-codec-governed fields.
//!
//! This module provides the types that generated visage fields return when
//! a field is governed by a `protected(per_scope = { ... })` declaration.
//! The surface is intentionally narrow: callers cannot reach the underlying
//! storage `FieldRef` directly — they interact only through the codec
//! trait gates.
//!
//! # Access control
//!
//! - Predicate access is available only when `Codec: PresentationQueryCodec<FieldTy>`.
//! - Order access is available only when `Codec: PresentationOrderCodec<FieldTy>`.
//! - The `eq_storage`, `asc_storage`, `desc_storage` methods on
//! [`PresentationQueryField`] / [`PresentationOrderField`] are public for
//! codec implementations but are not directly reachable from generated
//! user-facing visage accessors. Callers obtain them only through
//! `PresentationFieldRef`'s codec-gated methods.
//!
//! # Two-layer design
//!
//! Generated field surfaces return `PresentationFieldRef<Source, Codec, FieldTy>`.
//! That type exposes predicate/order methods only when `Codec` implements the
//! matching query codec trait. Those public methods construct a temporary
//! `PresentationQueryField` / `PresentationOrderField` and delegate to the
//! codec trait implementation, which in turn calls the narrow storage-delegate
//! methods (`eq_storage`, `asc_storage`, `desc_storage`) to produce the final
//! `Q<M>` / `OrderExpr`.
//!
//! This layering ensures:
//! 1. The underlying storage `FieldRef` is never exposed to callers.
//! 2. The only queryability path is through explicit codec trait impls.
//! 3. `Identity` (which delegates storage-value equality) works naturally.
use crateModel;
use crate;
use PresentationCodecInfo;
/// User-facing accessor for a presentation-governed protected field.
///
/// Generated by `#[model]` for each field with a `per_scope` block.
/// The `Source` parameter is the owning model type, `Codec` is the
/// selected presentation codec for this scope, and `FieldTy` is the
/// field's storage type.
///
/// Predicate methods (`eq`) are only available when
/// `Codec: PresentationQueryCodec<FieldTy>`. Ordering methods (`asc`, `desc`)
/// are only available when `Codec: PresentationOrderCodec<FieldTy>`.
///
/// # Security note
///
/// `PresentationFieldRef` never exposes the underlying `FieldRef<Source,
/// FieldTy>` getter. Storage-level predicates on this field are only
/// available through `Model::objects()` on the source model, which remains
/// privileged and is not narrowed by presentation rules.
/// Narrow predicate-construction handle passed to codec implementations.
///
/// `PresentationQueryField` is the gateway through which a
/// [`PresentationQueryCodec`] implementation produces a `Q<M>` predicate.
/// The codec calls one of the narrow storage-delegate methods (`eq_storage`)
/// to construct the predicate.
///
/// # Security boundary
///
/// The underlying `FieldRef` is crate-private. Codec implementations that
/// receive this type in their trait method can only call the narrow public
/// surface below. A downstream adopter cannot construct `PresentationQueryField`
/// directly — it arrives from `PresentationFieldRef::eq`, which is gated
/// by the `PresentationQueryCodec` bound.
///
/// # Granting storage-predicate power
///
/// Implementing `PresentationQueryCodec` with an `eq_storage`-based
/// implementation (as `Identity` does) grants storage-value predicates for
/// that protected presentation. Document this clearly in codec rustdoc.
/// Narrow ordering-construction handle passed to codec implementations.
///
/// `PresentationOrderField` is the gateway through which a
/// [`PresentationOrderCodec`] implementation produces `OrderExpr` values.
/// The codec calls one of the narrow storage-delegate methods.
///
/// Same security boundary as [`PresentationQueryField`].
/// Query codec gate — enables predicate access on a presentation field.
///
/// A codec implements this trait to declare that presented values support
/// equality predicates against the original query surface. The `QueryValue`
/// associated type controls what the caller provides.
///
/// # Security
///
/// Implementing this trait grants callers the ability to probe field values
/// through the generated visage accessor. Use only for transforms where
/// predicate access is safe (e.g. `Identity`, or a blind-index HMAC where
/// the query value is itself HMAC output).
///
/// Default queryability is [`Disabled`](super::Queryability::Disabled). Set
/// [`PresentationCodecInfo::QUERYABILITY`] to at least
/// [`PredicateOnly`](super::Queryability::PredicateOnly) when implementing
/// this trait.
/// Order codec gate — enables ascending/descending ordering on a
/// presentation field.
///
/// A codec implements this trait to declare that presented values support
/// ordering. The trait itself has no required methods — ordering is always
/// over the storage column, delegated through
/// `PresentationFieldRef::asc` / `PresentationFieldRef::desc` which call
/// `FieldRef::asc` / `FieldRef::desc` directly.
///
/// Default queryability is [`Disabled`](super::Queryability::Disabled). Set
/// [`PresentationCodecInfo::QUERYABILITY`] to at least
/// [`OrderOnly`](super::Queryability::OrderOnly) when implementing this
/// trait.