citum_schema_data/reference/input.rs
1/*
2SPDX-License-Identifier: MIT OR Apache-2.0
3SPDX-FileCopyrightText: © 2023-2026 Bruce D'Arcus and Citum contributors
4*/
5
6//! Public `InputReference` container and unknown-class payload.
7
8use std::sync::LazyLock;
9
10use serde::{Deserialize, Serialize};
11use serde_json::{Map as JsonMap, Value as JsonValue};
12
13#[cfg(feature = "bindings")]
14use specta::Type;
15
16use super::classes::ClassExtension;
17use super::types::common::FieldLanguageMap;
18
19/// Empty field-language map returned by accessors on unknown-class references.
20///
21/// `FieldLanguageMap` is a `HashMap`, whose `::new()` is not `const`, so a
22/// `LazyLock` is required. The map is constructed once for the process and
23/// reused by every unknown-class reference.
24pub(crate) static EMPTY_FIELD_LANGUAGES: LazyLock<FieldLanguageMap> =
25 LazyLock::new(FieldLanguageMap::new);
26
27/// The Reference model: a class-specific overlay reachable through accessor methods.
28///
29/// All shared bibliographic data (id, title, contributors, dates, publisher, ...)
30/// lives inside the class-specific payload in `extension`. The accessor methods
31/// (`id()`, `title()`, etc.) dispatch through the extension and are the public
32/// read path; the typed setters (`set_id`, ...) are the public mutation path.
33#[derive(Debug, Clone, PartialEq)]
34#[cfg_attr(feature = "bindings", derive(Type))]
35pub struct InputReference {
36 pub(crate) extension: ClassExtension,
37}
38
39/// Unknown reference-class payload captured by the discriminator dispatcher.
40#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
41#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
42#[cfg_attr(feature = "bindings", derive(Type))]
43pub struct UnknownClassData {
44 /// Raw `class:` string from the input object.
45 pub class: String,
46 /// Non-shared fields captured verbatim for round-trip preservation.
47 #[cfg_attr(feature = "bindings", specta(type = serde_json::Value))]
48 pub fields: JsonMap<String, JsonValue>,
49}