post_archiver/alias.rs
1use serde::{Deserialize, Serialize};
2use std::hash::Hash;
3
4#[cfg(feature = "typescript")]
5use ts_rs::TS;
6
7use crate::{AuthorId, PlatformId};
8/// A mapping between an alternative author name and their canonical identifier
9///
10/// - Links to [`Author`](crate::author::Author) through the target ID
11/// - Used by importer modules for author resolution
12/// - Referenced in post management for author lookups
13#[cfg_attr(feature = "typescript", derive(TS))]
14#[cfg_attr(feature = "typescript", ts(export))]
15#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
16pub struct Alias {
17 /// The alias name
18 ///
19 /// Should be unique across all aliases,
20 /// The name of the author on the platform,
21 /// It should be never changed.
22 ///
23 /// 1. id (e.g. `18623`, `11g978qh2ki-1hhf98aq9533a`)
24 /// 2. short name (e.g. `octocat`, `jack`)
25 /// 3. full name (e.g. `The Octocat`, `Jack Dorsey`)
26 ///
27 pub source: String,
28 /// The platform this alias belongs to
29 pub platform: PlatformId,
30 /// The target author ID this alias maps to
31 pub target: AuthorId,
32 /// A link to the author's profile on the platform
33 pub link: Option<String>,
34}
35
36impl Hash for Alias {
37 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
38 self.source.hash(state);
39 self.platform.hash(state);
40 self.target.hash(state);
41 }
42}
43
44#[cfg(feature = "utils")]
45crate::utils::macros::as_table! {
46 Alias {
47 source: "source",
48 platform: "platform",
49 target: "target",
50 link: "link",
51 }
52}