idiolect-records 0.8.0

Rust record types mirroring the dev.idiolect.* Lexicon family.
Documentation
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
// @generated by idiolect-codegen. do not edit.
// source: dev.idiolect.community

//! A group of DIDs that declare shared conventions. Self-constituted per P4: no central roll, no grading of legitimacy. Communities may be small and many.

#![allow(
    missing_docs,
    clippy::doc_markdown,
    clippy::struct_excessive_bools,
    clippy::derive_partial_eq_without_eq,
    clippy::large_enum_variant
)]
use serde::{Deserialize, Serialize};

/// A community is a self-constituted group declaring shared schemas, lenses, and conventions. Membership may be listed inline for small communities, or referenced for larger ones.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Community {
    /// URL of the community AppView, when `recordHosting` is `community-hosted` or `hybrid`. Consumers route XRPC reads through this endpoint.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub appview_endpoint: Option<idiolect_records::Uri>,
    /// Structured community conventions the decidable subset. Review cadence, verification requirements, deprecation policies. Style/tone norms live in `conventionsText`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub conventions: Option<Vec<CommunityConventions>>,
    /// Narrative conventions: style guides, tone, conventions not expressible as a structured predicate. Companion to `conventions`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub conventions_text: Option<String>,
    /// Lenses the community treats as canonical.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub core_lenses: Option<Vec<crate::generated::dev::idiolect::defs::LensRef>>,
    /// Schemas the community treats as canonical for its purposes.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub core_schemas: Option<Vec<crate::generated::dev::idiolect::defs::SchemaRef>>,
    pub created_at: idiolect_records::Datetime,
    /// Purpose, norms, and scope of the community. Narrative, not machine-interpreted.
    pub description: String,
    /// Other communities this community recognises as legitimate interlocutors. Endorsement is not transitive.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub endorsed_communities: Option<Vec<idiolect_records::AtUri>>,
    /// Vocabulary the role slugs in `roleAssignments[].role` resolve against. Omit to use the canonical idiolect community-roles vocabulary.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub member_role_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
    /// Inline list of member DIDs, for small communities. Use membershipRoll instead for communities above ~200 members.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub members: Option<Vec<idiolect_records::Did>>,
    /// AT-URI pointing to an externally maintained membership record for larger communities.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub membership_roll: Option<idiolect_records::AtUri>,
    /// Human-readable community name.
    pub name: String,
    /// Where the community's records live. `member-hosted` (default ATProto) means records live on individual member PDSes. `community-hosted` (Acorn-style) means records live on a community AppView, gated by membership. `hybrid` means both. Consumers crawling for community records use this to choose a surface.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub record_hosting: Option<CommunityRecordHosting>,
    /// Sparse role assignments for members. Only members whose role differs from the implicit default need an entry; the default role is named on the role vocabulary's top node. A DID may appear multiple times when the role vocabulary supports multiple roles per member.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub role_assignments: Option<Vec<RoleAssignment>>,
}

impl crate::Record for Community {
    const NSID: &'static str = "dev.idiolect.community";
}

/// How the community handles deprecation: minimum notice, replacement requirements.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConventionDeprecationPolicy {
    /// Minimum days of advance notice before a deprecated lens is removed.
    pub notice_period_days: i64,
    /// Whether deprecations must point at a replacement lens before publication.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub replacement_required: Option<bool>,
}

/// Expected turnaround for community review of proposed lenses/verifications.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConventionReviewCadence {
    /// Maximum business-days expected before a review is posted.
    pub max_days: i64,
    /// Optional narrowing (e.g. 'lens-review', 'verification-review', 'all').
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub scope: Option<String>,
}

/// A verification the community requires before endorsing a lens.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConventionVerificationReq {
    /// Open-enum slug naming the verification kind. Resolved against `kindVocab` when present, otherwise against the canonical idiolect verification-kinds vocabulary.
    pub kind: ConventionVerificationReqKind,
    /// Vocabulary the `kind` slug resolves against. Omit to use the canonical idiolect default.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub kind_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
    /// Optional specific property required.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub property: Option<crate::generated::dev::idiolect::defs::LensProperty>,
}

/// A role assignment for a single member DID. The role slug resolves through the community record's `memberRoleVocab` (or the canonical idiolect default when unset).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoleAssignment {
    /// DID of the member receiving the role.
    pub did: idiolect_records::Did,
    /// Open-enum role slug. The default vocabulary seeds `member` (top), `moderator`, `delegate`, `author`; communities extend by referencing a custom `memberRoleVocab`.
    pub role: RoleAssignmentRole,
}

/// ConventionVerificationReqKind. Open-enum slug; known values are kebab-cased; community-extended values pass through as `Other(String)`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConventionVerificationReqKind {
    RoundtripTest,
    PropertyTest,
    FormalProof,
    ConformanceTest,
    StaticCheck,
    ConvergencePreserving,
    /// Community-extended slug not present in the lexicon's
    /// `knownValues`. Resolves through the sibling
    /// `*Vocab` field on the containing record.
    Other(String),
}
impl ConventionVerificationReqKind {
    /// Wire-form slug for this value. Known variants render
    /// kebab-case; the fallback variant passes through verbatim.
    #[must_use]
    pub fn as_str(&self) -> &str {
        match self {
            Self::RoundtripTest => "roundtrip-test",
            Self::PropertyTest => "property-test",
            Self::FormalProof => "formal-proof",
            Self::ConformanceTest => "conformance-test",
            Self::StaticCheck => "static-check",
            Self::ConvergencePreserving => "convergence-preserving",
            Self::Other(s) => s.as_str(),
        }
    }
    /// Whether this slug is subsumed by `ancestor` under the
    /// `subsumed_by` relation in the supplied vocab. Reflexive:
    /// every slug is subsumed by itself.
    #[must_use]
    pub fn is_subsumed_by(
        &self,
        vocab: &idiolect_records::vocab::VocabGraph,
        ancestor: &str,
    ) -> bool {
        vocab.is_subsumed_by(self.as_str(), ancestor)
    }
    /// Whether this slug satisfies a requirement of `target`
    /// under the named `relation` in the supplied vocab.
    /// Generalises `is_subsumed_by` to any directed relation
    /// (e.g. `stronger_than`, `provides_at_least`,
    /// `equivalent_to`). Reflexive: a slug satisfies itself.
    #[must_use]
    pub fn satisfies(
        &self,
        vocab: &idiolect_records::vocab::VocabGraph,
        relation: &str,
        target: &str,
    ) -> bool {
        if self.as_str() == target {
            return true;
        }
        vocab
            .walk_relation(self.as_str(), relation, false)
            .iter()
            .any(|n| n == target)
    }
    /// Translate this slug across vocabularies via
    /// `equivalent_to` edges. Returns the translated slug as
    /// a target enum value when a translation exists, `None`
    /// when no path is found (callers fall back to passing
    /// the slug through verbatim, which is wire-compatible).
    #[must_use]
    pub fn translate_to<T: From<String>>(
        &self,
        src_vocab_uri: &str,
        tgt_vocab_uri: &str,
        registry: &idiolect_records::vocab::VocabRegistry,
    ) -> Option<T> {
        registry
            .translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
            .map(T::from)
    }
}
impl From<String> for ConventionVerificationReqKind {
    fn from(s: String) -> Self {
        match s.as_str() {
            "roundtrip-test" => Self::RoundtripTest,
            "property-test" => Self::PropertyTest,
            "formal-proof" => Self::FormalProof,
            "conformance-test" => Self::ConformanceTest,
            "static-check" => Self::StaticCheck,
            "convergence-preserving" => Self::ConvergencePreserving,
            _ => Self::Other(s),
        }
    }
}
impl From<&str> for ConventionVerificationReqKind {
    fn from(s: &str) -> Self {
        match s {
            "roundtrip-test" => Self::RoundtripTest,
            "property-test" => Self::PropertyTest,
            "formal-proof" => Self::FormalProof,
            "conformance-test" => Self::ConformanceTest,
            "static-check" => Self::StaticCheck,
            "convergence-preserving" => Self::ConvergencePreserving,
            _ => Self::Other(s.to_owned()),
        }
    }
}
impl serde::Serialize for ConventionVerificationReqKind {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}
impl<'de> serde::Deserialize<'de> for ConventionVerificationReqKind {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

/// RoleAssignmentRole. Open-enum slug; known values are kebab-cased; community-extended values pass through as `Other(String)`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RoleAssignmentRole {
    Member,
    Moderator,
    Delegate,
    Author,
    /// Community-extended slug not present in the lexicon's
    /// `knownValues`. Resolves through the sibling
    /// `*Vocab` field on the containing record.
    Other(String),
}
impl RoleAssignmentRole {
    /// Wire-form slug for this value. Known variants render
    /// kebab-case; the fallback variant passes through verbatim.
    #[must_use]
    pub fn as_str(&self) -> &str {
        match self {
            Self::Member => "member",
            Self::Moderator => "moderator",
            Self::Delegate => "delegate",
            Self::Author => "author",
            Self::Other(s) => s.as_str(),
        }
    }
    /// Whether this slug is subsumed by `ancestor` under the
    /// `subsumed_by` relation in the supplied vocab. Reflexive:
    /// every slug is subsumed by itself.
    #[must_use]
    pub fn is_subsumed_by(
        &self,
        vocab: &idiolect_records::vocab::VocabGraph,
        ancestor: &str,
    ) -> bool {
        vocab.is_subsumed_by(self.as_str(), ancestor)
    }
    /// Whether this slug satisfies a requirement of `target`
    /// under the named `relation` in the supplied vocab.
    /// Generalises `is_subsumed_by` to any directed relation
    /// (e.g. `stronger_than`, `provides_at_least`,
    /// `equivalent_to`). Reflexive: a slug satisfies itself.
    #[must_use]
    pub fn satisfies(
        &self,
        vocab: &idiolect_records::vocab::VocabGraph,
        relation: &str,
        target: &str,
    ) -> bool {
        if self.as_str() == target {
            return true;
        }
        vocab
            .walk_relation(self.as_str(), relation, false)
            .iter()
            .any(|n| n == target)
    }
    /// Translate this slug across vocabularies via
    /// `equivalent_to` edges. Returns the translated slug as
    /// a target enum value when a translation exists, `None`
    /// when no path is found (callers fall back to passing
    /// the slug through verbatim, which is wire-compatible).
    #[must_use]
    pub fn translate_to<T: From<String>>(
        &self,
        src_vocab_uri: &str,
        tgt_vocab_uri: &str,
        registry: &idiolect_records::vocab::VocabRegistry,
    ) -> Option<T> {
        registry
            .translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
            .map(T::from)
    }
}
impl From<String> for RoleAssignmentRole {
    fn from(s: String) -> Self {
        match s.as_str() {
            "member" => Self::Member,
            "moderator" => Self::Moderator,
            "delegate" => Self::Delegate,
            "author" => Self::Author,
            _ => Self::Other(s),
        }
    }
}
impl From<&str> for RoleAssignmentRole {
    fn from(s: &str) -> Self {
        match s {
            "member" => Self::Member,
            "moderator" => Self::Moderator,
            "delegate" => Self::Delegate,
            "author" => Self::Author,
            _ => Self::Other(s.to_owned()),
        }
    }
}
impl serde::Serialize for RoleAssignmentRole {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}
impl<'de> serde::Deserialize<'de> for RoleAssignmentRole {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

/// CommunityConventions tagged union.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "$type")]
pub enum CommunityConventions {
    #[serde(rename = "dev.idiolect.community#conventionReviewCadence")]
    ConventionReviewCadence(ConventionReviewCadence),
    #[serde(rename = "dev.idiolect.community#conventionVerificationReq")]
    ConventionVerificationReq(ConventionVerificationReq),
    #[serde(rename = "dev.idiolect.community#conventionDeprecationPolicy")]
    ConventionDeprecationPolicy(ConventionDeprecationPolicy),
}

/// CommunityRecordHosting. Open-enum slug; known values are kebab-cased; community-extended values pass through as `Other(String)`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CommunityRecordHosting {
    MemberHosted,
    CommunityHosted,
    Hybrid,
    /// Community-extended slug not present in the lexicon's
    /// `knownValues`. Resolves through the sibling
    /// `*Vocab` field on the containing record.
    Other(String),
}
impl CommunityRecordHosting {
    /// Wire-form slug for this value. Known variants render
    /// kebab-case; the fallback variant passes through verbatim.
    #[must_use]
    pub fn as_str(&self) -> &str {
        match self {
            Self::MemberHosted => "member-hosted",
            Self::CommunityHosted => "community-hosted",
            Self::Hybrid => "hybrid",
            Self::Other(s) => s.as_str(),
        }
    }
    /// Whether this slug is subsumed by `ancestor` under the
    /// `subsumed_by` relation in the supplied vocab. Reflexive:
    /// every slug is subsumed by itself.
    #[must_use]
    pub fn is_subsumed_by(
        &self,
        vocab: &idiolect_records::vocab::VocabGraph,
        ancestor: &str,
    ) -> bool {
        vocab.is_subsumed_by(self.as_str(), ancestor)
    }
    /// Whether this slug satisfies a requirement of `target`
    /// under the named `relation` in the supplied vocab.
    /// Generalises `is_subsumed_by` to any directed relation
    /// (e.g. `stronger_than`, `provides_at_least`,
    /// `equivalent_to`). Reflexive: a slug satisfies itself.
    #[must_use]
    pub fn satisfies(
        &self,
        vocab: &idiolect_records::vocab::VocabGraph,
        relation: &str,
        target: &str,
    ) -> bool {
        if self.as_str() == target {
            return true;
        }
        vocab
            .walk_relation(self.as_str(), relation, false)
            .iter()
            .any(|n| n == target)
    }
    /// Translate this slug across vocabularies via
    /// `equivalent_to` edges. Returns the translated slug as
    /// a target enum value when a translation exists, `None`
    /// when no path is found (callers fall back to passing
    /// the slug through verbatim, which is wire-compatible).
    #[must_use]
    pub fn translate_to<T: From<String>>(
        &self,
        src_vocab_uri: &str,
        tgt_vocab_uri: &str,
        registry: &idiolect_records::vocab::VocabRegistry,
    ) -> Option<T> {
        registry
            .translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
            .map(T::from)
    }
}
impl From<String> for CommunityRecordHosting {
    fn from(s: String) -> Self {
        match s.as_str() {
            "member-hosted" => Self::MemberHosted,
            "community-hosted" => Self::CommunityHosted,
            "hybrid" => Self::Hybrid,
            _ => Self::Other(s),
        }
    }
}
impl From<&str> for CommunityRecordHosting {
    fn from(s: &str) -> Self {
        match s {
            "member-hosted" => Self::MemberHosted,
            "community-hosted" => Self::CommunityHosted,
            "hybrid" => Self::Hybrid,
            _ => Self::Other(s.to_owned()),
        }
    }
}
impl serde::Serialize for CommunityRecordHosting {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}
impl<'de> serde::Deserialize<'de> for CommunityRecordHosting {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}