lix 0.18.0

Embeddable version control for apps and AI agents.
Documentation
#![recursion_limit = "256"]
// The hard-cut Rust SDK keeps implementation-only subsystems available inside
// the crate while intentionally no longer exporting them. Some are exercised
// only by feature-gated integrations and maintenance tooling.
#![cfg_attr(not(test), allow(dead_code, unused_imports))]

//! Rust SDK for Lix.
//!
//! Embedded version control for files and data.
//!
//! # Quick start
//!
//! ```no_run
//! # async fn example() -> Result<(), lix::LixError> {
//! let lix = lix::open_lix().await?;
//! # Ok(())
//! # }
//! ```
//!
//! [`open_lix`] opens an in-memory repository. Add a storage adapter with
//! [`OpenLixBuilder::with_storage`] when persistence is needed.

#![cfg_attr(
    test,
    allow(
        clippy::cast_possible_truncation,
        clippy::cloned_ref_to_slice_refs,
        clippy::large_futures,
        clippy::redundant_clone,
        clippy::suspicious_operation_groupings,
        clippy::useless_vec
    )
)]

pub const SERVER_PROTOCOL_VERSION: u32 = 12;
/// Current persisted repository format. Supported older stores upgrade automatically during opening.
#[cfg(not(all(target_arch = "wasm32", target_os = "wasi", target_env = "p2")))]
pub const CURRENT_STORAGE_FORMAT_VERSION: u32 = init::CURRENT_FORMAT_VERSION;
/// Current sync wire epoch; obsolete clients are rejected before mutation.
#[cfg(not(all(target_arch = "wasm32", target_os = "wasi", target_env = "p2")))]
pub const SYNC_PROTOCOL_VERSION: u32 = sync::SYNC_PROTOCOL_VERSION;

// Hosts can parse SQL with the same dialect and parameter rules as execution.
#[cfg(not(all(target_arch = "wasm32", target_os = "wasi", target_env = "p2")))]
pub use sql2::script::{SqlScriptPlan, SqlScriptStatement, parse_sql_script};

// Let implementation modules use the same `lix::...` paths as external
// consumers now that the former engine and SDK share one crate.
extern crate self as lix;

pub mod plugin;

#[cfg(not(all(target_arch = "wasm32", target_os = "wasi", target_env = "p2")))]
macro_rules! engine_surface {
    ($($item:item)*) => {
        $($item)*
    };
}

#[cfg(not(all(target_arch = "wasm32", target_os = "wasi", target_env = "p2")))]
engine_surface! {
pub(crate) mod account;
mod binary_cas;
pub(crate) mod branch;
mod background_task;
mod authority_client;
pub(crate) mod catalog;
#[cfg(feature = "storage-benches")]
pub mod changelog;
#[cfg(not(feature = "storage-benches"))]
pub(crate) mod changelog;
pub(crate) mod checkpoint;
pub(crate) mod collection_generation;
pub(crate) mod columnar_row_group;
pub(crate) mod commit_graph;
mod common;
pub(crate) mod compression;
pub(crate) mod domain;
mod engine;
pub(crate) mod row_columnar;
pub(crate) mod row_pk;
pub(crate) mod row_payload;
pub(crate) mod row_state;
pub(crate) mod row_ref;
pub(crate) mod filesystem;
pub(crate) mod functions;
pub(crate) mod gc;
mod handle;
#[cfg(test)]
mod hot_index_aging_probe;
#[cfg(test)]
mod hot_row_tombstone_probe;
// Calls `SessionContext::execute_profiled`, which is `storage-benches`-only, so
// the module needs the same gate. Without it `cargo check -p lix --tests` --
// cfg(test) with the feature off, which is what a plain `cargo test -p lix`
// builds -- fails while `--all-features` and clippy stay green.
#[cfg(all(test, feature = "storage-benches"))]
mod json_predicate_pushdown_probe;
pub(crate) mod hot_state;
pub(crate) mod init;
pub mod migration;
mod open_types;
/// The declared module layer order and the test that enforces it. Test-only:
/// it contains no engine code, just the layering artifact and its guard.
#[cfg(test)]
mod module_layers;
pub(crate) mod observe_coordinator;
pub(crate) mod observe_invalidation;
pub(crate) mod order_preserving_key;
// A `pub` view of `storage_spaces`, which is itself unconditional. This module
// stays gated on its own merits rather than mirroring the registry's: a build
// with neither `cfg(test)` nor `storage-benches` has no consumer for the
// handles, and publishing them there would widen the public surface for
// nothing.
#[cfg(any(test, feature = "storage-benches"))]
pub mod registered_spaces;
mod schema;
pub mod snapshot;
#[cfg(any(feature = "server-protocol", feature = "server-protocol-client"))]
pub mod server_protocol;
#[cfg(not(any(feature = "server-protocol", feature = "server-protocol-client")))]
mod server_protocol;
mod session;
#[doc(hidden)]
mod sync;
pub use sync::{SyncFailure, SyncHealth, SyncHealthState, SyncPhase};
pub(crate) mod sql2;
#[cfg(feature = "storage-benches")]
mod sql_profile;
mod sql_telemetry;
pub mod storage;
#[cfg(feature = "storage-benches")]
pub mod storage_adapter;
#[cfg(not(feature = "storage-benches"))]
pub(crate) mod storage_adapter;
#[cfg(feature = "storage-benches")]
pub mod storage_bench;
pub(crate) mod storage_codec;
// Unconditional: `StorageSpace::mutable`/`::immutable` check the id they are
// given against this registry, and those constructors exist in every build.
// A guard that is only compiled when a test feature is on is not a guard on
// the shipped crate.
pub(crate) mod storage_spaces;
pub mod telemetry;
#[cfg(any(test, feature = "storage-benches"))]
pub(crate) mod test_support;
#[cfg(feature = "storage-benches")]
pub mod tracked_state;
#[cfg(not(feature = "storage-benches"))]
pub(crate) mod tracked_state;
#[cfg(feature = "storage-benches")]
pub mod transaction;
#[cfg(not(feature = "storage-benches"))]
pub(crate) mod transaction;
pub(crate) mod transaction_types;
pub(crate) mod undo_redo;
pub mod wasm;

#[cfg(feature = "default_wasm_runtime")]
#[doc(hidden)]
pub use plugin::runtime::default::runtime as default_wasm_runtime;
mod lifecycle;
pub use lifecycle::{create_lix, delete_lix, CreateLixBuilder, DeleteLixBuilder, HostedLix};
pub use handle::{
    Durability,
    CallbackOpenProgressSink, ExecuteBatchBuilder, ExecuteBuilder, Lix, LixTransaction,
    ObserveEvents, OpenAnotherSessionBuilder, OpenLixBuilder, OpenLixFromSnapshotBuilder,
    ServerOptions, TransactionExecuteBuilder, UnconfiguredOpenLixBuilder, RemoteOpenLixBuilder,
    RemoteLix, RemoteExecuteBuilder, RemoteLixTransaction, RemoteObserveEvents,
    RemoteOpenAnotherSessionBuilder, RemoteTransactionExecuteBuilder, RemoteExecuteBatchBuilder, open_lix,
};
pub use open_types::{
    OpenMigration, OpenMigrationReport, OpenPhase, OpenProgress, OpenProgressSink, OpenReport, OpenScope,
};
#[cfg(target_family = "wasm")]
#[doc(hidden)]
pub use sync::{
    BROWSER_TRANSPORT_CONFIG_HEADER, register_browser_sync_transport,
    unregister_browser_sync_transport,
};
pub use telemetry::bind_session;

pub use schema::{
    lix_schema_definition, lix_schema_definition_json, validate_lix_schema,
    validate_lix_schema_definition,
};

/// PostgreSQL-derived Lix Schema v1 model and validation API.
pub use lix_schema as schema_v1;

pub use common::LixError;
pub use common::{
    Blob, Json, LixNotice, NullableKeyFilter, ResultColumnType, RowRef, SharedStr, SqlQueryResult,
    Value,
};
pub use common::{BranchId, CanonicalPluginKey, CanonicalSchemaKey, FileId};
pub use common::{LixPath, validate_lix_path_segment};
pub use common::{WireQueryResult, WireValue};
pub(crate) use common::{parse_row_metadata_value, serialize_row_metadata};
pub use session::{
    CreateBranchOptions, CreateBranchReceipt, MergeBranchOptions,
    MergeBranchOutcome, MergeBranchPreview, MergeBranchPreviewOptions, MergeBranchReceipt,
    MergeChangeStats, SessionTransaction, SwitchBranchOptions, SwitchBranchReceipt,
};
pub use session::{
    CommitReceipt, CommitSpan, ExecuteBatchResult, ExecuteBatchStatement, ExecuteResult, ObserveEvent, ResultRowRef, Row,
    TryFromValue,
};
#[doc(hidden)]
pub use session::CoherentReadBatch;
pub(crate) use session::{
    ExecuteIdempotency, ExecuteStatementMetadata, ExecutionDisposition, FileRead,
    FileUploadProgress,
};
#[cfg(feature = "server-protocol")]
pub(crate) use session::VerifiedRequestBlob;
#[cfg(feature = "storage-benches")]
pub(crate) use sql_profile::SqlReadProfile;
pub use migration::upgrade_authority_for_partial_sync;
pub use handle::{convert_replica_to_partial, retry_replica_migration_cleanup};
pub use storage::Memory;
pub use sync::{
    ReplicaRecoveryBlob, ReplicaRecoveryBranch, ReplicaRecoveryExport, ReplicaRecoveryFile,
    ReplicaRecoveryReceipt, ReplicaRecoveryRow, ReplicaRecoverySource,
};

/// Reserved high UUID sentinel for repository-global state.
pub const GLOBAL_BRANCH_ID: &str = "ffffffff-ffff-7fff-bfff-ffffffffffff";

/// Fixed author for engine-owned initialization and maintenance changes.
pub const SYSTEM_ACCOUNT_ID: &str = "00000000-0000-7000-8000-000000000001";

/// Fixed author used when a host opens a session without an authenticated account.
pub const ANONYMOUS_ACCOUNT_ID: &str = "00000000-0000-7000-8000-000000000002";

// Keep engine-level verification inside the crate. These tests deliberately
// exercise implementation details that are not part of the Rust SDK.
#[cfg(test)]
#[macro_use]
#[path = "../tests/integration/support/mod.rs"]
mod support;
#[cfg(test)]
#[path = "../tests/integration/main.rs"]
mod integration_tests;

#[cfg(test)]
mod native_partial_sql_tests;
#[cfg(test)]
mod native_partial_bootstrap_tests;
}