p2panda_rs/schema/system/
mod.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3//! System schemas are p2panda's built-in schema type.
4//!
5//! They are defined as part of the p2panda specification and may differ from application schemas
6//! in how they are materialised.
7use once_cell::sync::Lazy;
8
9use crate::schema::Schema;
10
11mod blob;
12mod blob_piece;
13mod error;
14mod schema_definition;
15mod schema_field_definition;
16mod schema_views;
17
18pub use error::SystemSchemaError;
19pub use schema_views::{SchemaFieldView, SchemaView};
20
21pub(super) use blob::get_blob;
22pub(super) use blob_piece::get_blob_piece;
23pub(super) use schema_definition::get_schema_definition;
24pub(super) use schema_field_definition::get_schema_field_definition;
25
26/// A vector of all system schemas in this version of the library.
27pub static SYSTEM_SCHEMAS: Lazy<Vec<&'static Schema>> = Lazy::new(|| {
28    // Unwrap here because we know that these system schema versions exist
29    vec![
30        get_schema_definition(1).unwrap(),
31        get_schema_field_definition(1).unwrap(),
32        get_blob(1).unwrap(),
33        get_blob_piece(1).unwrap(),
34    ]
35});
36
37#[cfg(test)]
38mod test {
39    use super::SYSTEM_SCHEMAS;
40
41    #[test]
42    fn test_static_system_schemas() {
43        assert_eq!(SYSTEM_SCHEMAS.len(), 4);
44    }
45}