Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

11.8 KB
Raw Blame
//! Generated client vault datamodel registry data.
//!
//! @generated: do NOT edit this file directly. It is generated from
//! core/models/src/vault/VaultTableRegistry.ts by core/models/scripts/generate-vault-table-registry.cjs.
//! Edit the TypeScript source and run 'core/models/build.sh' to regenerate.

use super::{BlobColumn, SystemField, TableConfig};

/// All tables that need LWW merge, in registry order. Order matters: a merge inserts rows
/// in this order, so child tables must be listed after the table they reference (Items first).
/// Per-table rationale (merge key choices, natural keys) is documented in the TypeScript source.
pub static SYNCABLE_TABLES: &[TableConfig] = &[
    TableConfig::new("Items").manifest_scoped(),
    TableConfig::new("ItemStats").manifest_scoped().item_child().with_primary_key(&["Id", "DeviceId"]),
    TableConfig::new("FieldValues")
        .manifest_scoped()
        .item_child()
        .with_canonical_key(&["ManifestId", "ItemId", "FieldKey", "FieldDefinitionId", "Id"]),
    TableConfig::new("Folders").manifest_scoped(),
    TableConfig::new("Tags").manifest_scoped(),
    TableConfig::new("ItemTags").manifest_scoped().item_child().with_primary_key(&["ItemId", "TagId"]),
    TableConfig::new("Attachments").manifest_scoped().item_child(),
    TableConfig::new("TotpCodes").manifest_scoped().item_child(),
    TableConfig::new("Passkeys").manifest_scoped().item_child(),
    TableConfig::new("FieldDefinitions").manifest_scoped(),
    TableConfig::new("FieldHistories")
        .manifest_scoped()
        .item_child()
        .with_canonical_key(&["ManifestId", "ItemId", "FieldKey", "FieldDefinitionId", "ChangedAt"]),
    TableConfig::new("Logos").manifest_scoped(),
    TableConfig::new("EncryptionKeys").manifest_scoped(),
    TableConfig::new("Settings").manifest_scoped().with_primary_key(&["Key"]),
];

/// List of syncable table names (for clients to know which tables to read).
pub const SYNCABLE_TABLE_NAMES: &[&str] = &[
    "Items",
    "ItemStats",
    "FieldValues",
    "Folders",
    "Tags",
    "ItemTags",
    "Attachments",
    "TotpCodes",
    "Passkeys",
    "FieldDefinitions",
    "FieldHistories",
    "Logos",
    "EncryptionKeys",
    "Settings",
];

/// The columns whose bytes are extracted into content-addressed blobs.
pub static BLOB_COLUMNS: &[BlobColumn] = &[
    BlobColumn { table: "Attachments", column: "Blob", hash_column: "BlobHash", kind: "attachment" },
    BlobColumn { table: "Logos", column: "FileData", hash_column: "FileDataHash", kind: "favicon" },
];

/// Tables never serialized into the server-stored manifest: internal SQLite, platform, or EF bookkeeping
/// that is temporary and only used/required during runtime, and therefore should not become part of a persisted manifest.
pub static SKIP_TABLES: &[&str] = &[
    "__EFMigrationsHistory",
    "__EFMigrationsLock",
    "sqlite_sequence",
    "android_metadata",
    "Manifests",
];

/// Tables split out of the manifest into a data bucket, keyed by category, so each bucket syncs on its
/// own server revision without rewriting the manifest. Tuple form `(table_name, bucket_category)`;
/// `category` mirrors the server `VaultDataBucketCategory`. Several tables may share a category to sync together.
pub static BUCKET_TABLES: &[(&str, &str)] = &[
    ("Settings", "settings"),
    ("ItemStats", "stats"),
];

/// Tables that belong exclusively to the user's own (personal) vault, never to a shared manifest.
/// Deliberately independent of [`BUCKET_TABLES`]: a bucketed table is kept out of the manifest blob,
/// which is a different question from which manifests may hold its rows at all.
pub static PERSONAL_TABLES: &[&str] = &[];

/// System field keys whose field holds multiple values, derived from SystemFieldRegistry
/// (IsMultiValue). A value of such a field owns its row id (two devices each adding a value are
/// adding two different things) and is not derived.
pub static MULTI_VALUE_FIELD_KEYS: &[&str] = &["login.url"];

/// The system fields and their metadata, from SystemFieldRegistry, in registry order.
pub static SYSTEM_FIELDS: &[SystemField] = &[
    SystemField { key: "login.email", field_type: "Email", is_hidden: false, is_multi_value: false, enable_history: true, default_display_order: 10 },
    SystemField { key: "login.username", field_type: "Text", is_hidden: false, is_multi_value: false, enable_history: true, default_display_order: 15 },
    SystemField { key: "login.password", field_type: "Password", is_hidden: true, is_multi_value: false, enable_history: true, default_display_order: 20 },
    SystemField { key: "login.url", field_type: "URL", is_hidden: false, is_multi_value: true, enable_history: false, default_display_order: 5 },
    SystemField { key: "alias.first_name", field_type: "Text", is_hidden: false, is_multi_value: false, enable_history: false, default_display_order: 20 },
    SystemField { key: "alias.last_name", field_type: "Text", is_hidden: false, is_multi_value: false, enable_history: false, default_display_order: 30 },
    SystemField { key: "alias.gender", field_type: "Text", is_hidden: false, is_multi_value: false, enable_history: false, default_display_order: 50 },
    SystemField { key: "alias.birthdate", field_type: "Date", is_hidden: false, is_multi_value: false, enable_history: false, default_display_order: 60 },
    SystemField { key: "card.cardholder_name", field_type: "Text", is_hidden: false, is_multi_value: false, enable_history: false, default_display_order: 10 },
    SystemField { key: "card.number", field_type: "Hidden", is_hidden: true, is_multi_value: false, enable_history: false, default_display_order: 20 },
    SystemField { key: "card.expiry_month", field_type: "Text", is_hidden: false, is_multi_value: false, enable_history: false, default_display_order: 30 },
    SystemField { key: "card.expiry_year", field_type: "Text", is_hidden: false, is_multi_value: false, enable_history: false, default_display_order: 40 },
    SystemField { key: "card.cvv", field_type: "Hidden", is_hidden: true, is_multi_value: false, enable_history: false, default_display_order: 50 },
    SystemField { key: "card.pin", field_type: "Hidden", is_hidden: true, is_multi_value: false, enable_history: false, default_display_order: 60 },
    SystemField { key: "notes.content", field_type: "TextArea", is_hidden: false, is_multi_value: false, enable_history: false, default_display_order: 100 },
];

/// System field keys whose field holds one value. A key in neither list is a field this build does
/// not know (a newer writer's), whose rows the codec leaves as it found them.
pub static SINGLE_VALUE_FIELD_KEYS: &[&str] = &["login.email", "login.username", "login.password", "alias.first_name", "alias.last_name", "alias.gender", "alias.birthdate", "card.cardholder_name", "card.number", "card.expiry_month", "card.expiry_year", "card.cvv", "card.pin", "notes.content"];

/// The per-manifest delivery-keypair table. Every manifest carries its own asymmetric keypair(s),
/// stamped with that manifest's id (`ManifestId`).
pub const ENCRYPTION_KEYS_TABLE: &str = "EncryptionKeys";

/// The column every stamped table carries: the id of the manifest that owns the row.
pub const MANIFEST_ID_COL: &str = "ManifestId";

/// Local bookkeeping table materialize writes into the vault DB: one row per manifest this
/// vault is materialized from (`Id`, `Name`).
pub const MANIFESTS_TABLE: &str = "Manifests";

/// Client-local SQLite table that carries the codec overflow inside the vault database itself (see
/// `CodecOverflow`): materialize writes a single row `{ Id: OVERFLOW_ROW_ID, Data: <json> }`, and
/// canonicalize / extract_bucket consume it to build the manifest.
pub const OVERFLOW_TABLE: &str = "CodecOverflows";

/// Fixed sentinel primary key of the single `OVERFLOW_TABLE` row (deterministic on purpose:
/// materialize output must not depend on a random source).
pub const OVERFLOW_ROW_ID: &str = "00000000-0000-0000-0000-00000000c0de";

/// All zero GUID used for default values which indicate unstamped rows.
pub const UNSTAMPED_MANIFEST_ID: &str = "00000000-0000-0000-0000-000000000000";

/// Rows referenced from inside manifest content: `(target_table, [(referencing_table, column)])`.
/// On a manifest split the referenced rows are reference-copied into the destination manifest.
pub static REFERENCED_TABLES: &[(&str, &[(&str, &str)])] = &[
    ("Tags", &[("ItemTags", "TagId")]),
    ("FieldDefinitions", &[("FieldValues", "FieldDefinitionId"), ("FieldHistories", "FieldDefinitionId")]),
];

/// Default trash retention in days: how long a trashed item survives before the pruner deletes it.
pub const TRASH_RETENTION_DEFAULT_DAYS: u32 = 30;

/// Table, column, and logo-kind name vocabulary shared by the vault logic, so every module spells
/// them identically. The full column set of each table is deliberately not modeled here: it lives
/// in the SQL schema and is passed to the codec at runtime.
pub mod names {
    /// The `Items` table.
    pub const ITEMS_TABLE: &str = "Items";
    /// The `ItemStats` table.
    pub const ITEM_STATS_TABLE: &str = "ItemStats";
    /// The `FieldValues` table.
    pub const FIELD_VALUES_TABLE: &str = "FieldValues";
    /// The `Folders` table.
    pub const FOLDERS_TABLE: &str = "Folders";
    /// The `Tags` table.
    pub const TAGS_TABLE: &str = "Tags";
    /// The `ItemTags` table.
    pub const ITEM_TAGS_TABLE: &str = "ItemTags";
    /// The `Attachments` table.
    pub const ATTACHMENTS_TABLE: &str = "Attachments";
    /// The `TotpCodes` table.
    pub const TOTP_CODES_TABLE: &str = "TotpCodes";
    /// The `Passkeys` table.
    pub const PASSKEYS_TABLE: &str = "Passkeys";
    /// The `FieldDefinitions` table.
    pub const FIELD_DEFINITIONS_TABLE: &str = "FieldDefinitions";
    /// The `FieldHistories` table.
    pub const FIELD_HISTORIES_TABLE: &str = "FieldHistories";
    /// The `Logos` table.
    pub const LOGOS_TABLE: &str = "Logos";
    /// The `EncryptionKeys` table.
    pub const ENCRYPTION_KEYS_TABLE: &str = "EncryptionKeys";
    /// The `Settings` table.
    pub const SETTINGS_TABLE: &str = "Settings";

    /// The `Id` column.
    pub const ID_COL: &str = "Id";
    /// The `ItemId` column.
    pub const ITEM_ID_COL: &str = "ItemId";
    /// The `TagId` column.
    pub const TAG_ID_COL: &str = "TagId";
    /// The `FieldKey` column.
    pub const FIELD_KEY_COL: &str = "FieldKey";
    /// The `FieldDefinitionId` column.
    pub const FIELD_DEFINITION_ID_COL: &str = "FieldDefinitionId";
    /// The `ValueIndex` column.
    pub const VALUE_INDEX_COL: &str = "ValueIndex";
    /// The `ChangedAt` column.
    pub const CHANGED_AT_COL: &str = "ChangedAt";
    /// The `IsMultiValue` column.
    pub const IS_MULTI_VALUE_COL: &str = "IsMultiValue";
    /// The `ParentFolderId` column.
    pub const PARENT_FOLDER_ID_COL: &str = "ParentFolderId";
    /// The `FolderId` column.
    pub const FOLDER_ID_COL: &str = "FolderId";
    /// The `LogoId` column.
    pub const LOGO_ID_COL: &str = "LogoId";
    /// The `DeviceId` column.
    pub const DEVICE_ID_COL: &str = "DeviceId";
    /// The `Kind` column.
    pub const KIND_COL: &str = "Kind";
    /// The `Source` column.
    pub const SOURCE_COL: &str = "Source";
    /// The `FileData` column.
    pub const FILE_DATA_COL: &str = "FileData";
    /// The `Blob` column.
    pub const BLOB_COL: &str = "Blob";
    /// The `UpdatedAt` column.
    pub const UPDATED_AT_COL: &str = "UpdatedAt";
    /// The `DeletedAt` column.
    pub const DELETED_AT_COL: &str = "DeletedAt";
    /// The `PublicKey` column.
    pub const PUBLIC_KEY_COL: &str = "PublicKey";
    /// The `IsPrimary` column.
    pub const IS_PRIMARY_COL: &str = "IsPrimary";
    /// The `IsDeleted` column.
    pub const IS_DELETED_COL: &str = "IsDeleted";

    /// The `favicon` logo kind.
    pub const LOGO_KIND_FAVICON: &str = "favicon";
    /// The `builtin` logo kind.
    pub const LOGO_KIND_BUILTIN: &str = "builtin";
    /// The `custom` logo kind.
    pub const LOGO_KIND_CUSTOM: &str = "custom";
}