ifc_lite_diff/
input.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! The input shapes an adapter fills in before hashing.
6//!
7//! Split out of `fingerprint.rs` so neither module carries both the data
8//! definitions and the canonical encoding. These are the Rust spelling of
9//! `DataFingerprintInput` and friends in `packages/diff/src/fingerprint.ts`;
10//! the reasoning for what each field may and may not carry lives with the
11//! hashing code that enforces it.
12
13use crate::JsString;
14use crate::sparse_collection::SparseCollection;
15
16/// A property or quantity value as supplied by an adapter.
17///
18/// Mirrors the `unknown` the TypeScript engine accepts, narrowed to the shapes
19/// an IFC property value can actually take.
20#[derive(Debug, Clone, PartialEq, Default)]
21pub enum PropertyValue {
22    #[default]
23    Null,
24    Bool(bool),
25    Number(f64),
26    String(JsString),
27    Array(Vec<PropertyValue>),
28    Object(Vec<(JsString, PropertyValue)>),
29}
30
31/// One named property or quantity.
32#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
33pub struct PropertyEntryInput {
34    pub name: JsString,
35    #[serde(default)]
36    pub value: PropertyValue,
37}
38
39/// A named property set with its members.
40#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
41pub struct PropertySetInput {
42    pub name: JsString,
43    pub properties: SparseCollection<PropertyEntryInput>,
44}
45
46/// A named quantity set with its members.
47#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
48pub struct QuantitySetInput {
49    pub name: JsString,
50    pub quantities: SparseCollection<PropertyEntryInput>,
51}
52
53/// An assigned type, projected to its semantic identity.
54///
55/// The type's `GlobalId` is deliberately not represented: it is not hashed,
56/// and carrying it here would invite a future change to hash it. See the
57/// module docs.
58#[derive(Debug, Clone, PartialEq, Default, serde::Deserialize)]
59#[serde(default)]
60pub struct TypeAssignmentInput {
61    /// Name of the assigned type, e.g. `WT-200`.
62    pub name: Option<JsString>,
63    /// IFC class of the assigned type, e.g. `IfcWallType`.
64    #[serde(rename = "type")]
65    pub type_name: Option<JsString>,
66}
67
68/// Everything the fingerprint hashes about one entity.
69#[derive(Debug, Clone, PartialEq, Default, serde::Deserialize)]
70#[serde(default, rename_all = "camelCase")]
71pub struct DataFingerprintInput {
72    pub ifc_type: JsString,
73    pub name: Option<JsString>,
74    pub description: Option<JsString>,
75    pub object_type: Option<JsString>,
76    pub predefined_type: Option<JsString>,
77    /// The entity's `Tag`, **for a type object only**. See the module docs.
78    pub tag: Option<JsString>,
79    #[serde(deserialize_with = "crate::sparse_collection::optional_sparse")]
80    pub property_sets: SparseCollection<PropertySetInput>,
81    #[serde(deserialize_with = "crate::sparse_collection::optional_sparse")]
82    pub quantity_sets: SparseCollection<QuantitySetInput>,
83    #[serde(deserialize_with = "crate::sparse_collection::optional_sparse")]
84    pub type_assignments: SparseCollection<TypeAssignmentInput>,
85    /// Resolved material NAMES, every indirection already followed.
86    #[serde(deserialize_with = "crate::input_decode::optional_values")]
87    pub materials: Vec<JsString>,
88    /// Resolved classification references, each already one string.
89    #[serde(deserialize_with = "crate::input_decode::optional_values")]
90    pub classifications: Vec<JsString>,
91}