ifc_lite_diff/lib.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//! Store-agnostic entity diff engine for IFC models.
6//!
7//! A Rust port of `@ifc-lite/diff`, carrying the same contract: pure, no I/O,
8//! no parser, no geometry kernel. Callers extract fingerprints from whatever
9//! store they have and this crate compares them.
10//!
11//! # Byte-exactness is the contract, not just equal verdicts
12//!
13//! The fingerprints this crate produces must be **identical strings** to the
14//! TypeScript engine's, not merely consistent within Rust. `@ifc-lite/merge`
15//! consumes `stableHash` for its component snapshots, so a hash that differed
16//! would surface as spurious merge conflicts rather than as a test failure.
17//!
18//! That is harder than it looks, because the hash is taken over
19//! `JSON.stringify` output and the digest consumes UTF-16 code units. Three
20//! places where the obvious Rust is wrong, each measured against V8 rather
21//! than assumed:
22//!
23//! 1. **UTF-16 code-unit order is not codepoint order.** `"\u{E000}"` sorts
24//! *after* `"\u{10000}"` in JavaScript and *before* it in Rust. See
25//! [`utf16::cmp_code_units`].
26//! 2. **ECMAScript number formatting is not Rust's `Display`.** `1e21`
27//! renders as `1e+21`, not `1000000000000000000000`. Handled by `ryu-js`.
28//! 3. **`JSON.stringify` preserves key order; `stableSerialize` sorts.** Both
29//! are used, for different purposes. See [`js_json`].
30//!
31//! Canonical encoding, fingerprints, keyed comparison, content matching,
32//! split/merge, successors, lineage and sidecar wire records are implemented.
33//! The composed comparison entry point is [`engine::diff_models`].
34
35pub mod fingerprint;
36pub mod input;
37pub mod sparse_collection;
38mod input_decode;
39pub mod model;
40pub mod engine;
41pub mod columns;
42pub mod transport_options;
43pub mod transport_result;
44pub mod key_diff;
45pub mod geometry_compare;
46pub mod mutual_nearest;
47pub mod content_types;
48mod content_helpers;
49pub mod content_match;
50pub mod split_evidence;
51pub mod split_geometry;
52pub mod split_grid;
53pub mod class_families;
54#[doc(hidden)]
55pub mod class_normalization;
56pub mod split_types;
57mod split_lanes;
58pub mod split_merge;
59pub mod successor;
60pub mod identity_map;
61pub mod lineage;
62mod sidecar_json;
63pub mod sidecar;
64pub mod sidecar_validation;
65pub mod sidecar_document;
66
67// Internal. The canonical encoding and the code-unit helpers are
68// implementation detail of the fingerprint, not a surface worth promising:
69// this crate is published, so every public item is a semver commitment. The
70// one thing outside callers need is `stable_hash`, re-exported below because
71// `@ifc-lite/merge` hashes component snapshots with it.
72mod js_json;
73mod property_json;
74mod projections;
75mod utf16;
76
77pub use fingerprint::{build_component_fingerprint_entries, build_component_fingerprints, build_data_fingerprint};
78pub use input::{
79 DataFingerprintInput, PropertyEntryInput, PropertySetInput, PropertyValue, QuantitySetInput,
80 TypeAssignmentInput,
81};
82pub use utf16::{stable_hash, stable_hash_units};
83
84#[cfg(test)]
85mod content_tests;
86
87#[cfg(test)]
88mod split_geometry_tests;
89
90#[cfg(test)]
91mod split_merge_tests;
92
93#[cfg(test)]
94mod lineage_tests;
95
96mod sidecar_parse;
97
98mod sidecar_value;
99
100pub use sidecar_value::{JsString, DocumentValue, JsHash};
101pub mod document_serde;
102mod document_ser;
103mod document_key_ser;
104mod document_key_de;
105mod document_enum;