accounts are strings in the client side

This commit is contained in:
Priec
2026-08-08 20:30:57 +02:00
parent 7db328ca2b
commit a7b8d2021a
10 changed files with 69 additions and 81 deletions

Binary file not shown.

View File

@@ -3,8 +3,9 @@
pub struct EnsureAccountRequest {
#[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String,
#[prost(string, repeated, tag = "2")]
pub segments: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Slash-delimited root-to-leaf account path, for example "123/12/1".
#[prost(string, tag = "2")]
pub account: ::prost::alloc::string::String,
/// Currency accepted by source postings to the leaf account. Empty uses the
/// profile accounting currency. Missing ancestors are created in the profile
/// accounting currency.
@@ -19,10 +20,9 @@ pub struct Account {
pub parent_account_id: ::core::option::Option<i64>,
#[prost(string, tag = "3")]
pub segment: ::prost::alloc::string::String,
/// Root-to-leaf path of this account. Same shape as the request that created
/// it; the server never joins segments into a delimited code.
#[prost(string, repeated, tag = "4")]
pub segments: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Slash-delimited root-to-leaf account path.
#[prost(string, tag = "4")]
pub account: ::prost::alloc::string::String,
#[prost(string, tag = "5")]
pub denomination_currency: ::prost::alloc::string::String,
}
@@ -68,10 +68,9 @@ pub struct PostJournalRequest {
pub struct JournalLineInput {
#[prost(enumeration = "JournalSide", tag = "1")]
pub side: i32,
/// Parsed account path segments. The client owns presentation parsing; the
/// server accepts no delimiter-encoded account string.
#[prost(string, repeated, tag = "2")]
pub account_segments: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Slash-delimited root-to-leaf account path.
#[prost(string, tag = "2")]
pub account: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub amount: ::prost::alloc::string::String,
#[prost(string, tag = "4")]
@@ -238,9 +237,9 @@ pub struct JournalLine {
pub line_number: i32,
#[prost(enumeration = "JournalSide", tag = "3")]
pub side: i32,
/// Root-to-leaf path of the posted account, as sent on JournalLineInput.
#[prost(string, repeated, tag = "4")]
pub account_segments: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Slash-delimited root-to-leaf path of the posted account.
#[prost(string, tag = "4")]
pub account: ::prost::alloc::string::String,
#[prost(string, tag = "5")]
pub amount: ::prost::alloc::string::String,
#[prost(string, tag = "6")]
@@ -386,9 +385,9 @@ pub struct ListPeriodBalancesRequest {
pub struct PeriodBalance {
#[prost(int64, tag = "1")]
pub period_id: i64,
/// Root-to-leaf path of the account this frozen balance belongs to.
#[prost(string, repeated, tag = "2")]
pub account_segments: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Slash-delimited root-to-leaf path of this frozen balance's account.
#[prost(string, tag = "2")]
pub account: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub currency: ::prost::alloc::string::String,
/// Signed nets use debit-positive convention.
@@ -407,8 +406,8 @@ pub struct PeriodDenominationBalance {
pub period_id: i64,
/// Exact denominated account. Unlike book balances, this quantity is not
/// rolled up into parent accounts with a different denomination.
#[prost(string, repeated, tag = "2")]
pub account_segments: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, tag = "2")]
pub account: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub denomination_currency: ::prost::alloc::string::String,
/// Signed nets use debit-positive convention and remain in the denomination
@@ -453,23 +452,17 @@ pub struct MapOpeningBalanceAccountRequest {
/// previous_period_id identifies the source profile and period.
#[prost(int64, tag = "1")]
pub target_period_id: i64,
#[prost(string, repeated, tag = "2")]
pub source_account_segments: ::prost::alloc::vec::Vec<
::prost::alloc::string::String,
>,
#[prost(string, repeated, tag = "3")]
pub target_account_segments: ::prost::alloc::vec::Vec<
::prost::alloc::string::String,
>,
#[prost(string, tag = "2")]
pub source_account: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub target_account: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct UnmapOpeningBalanceAccountRequest {
#[prost(int64, tag = "1")]
pub target_period_id: i64,
#[prost(string, repeated, tag = "2")]
pub target_account_segments: ::prost::alloc::vec::Vec<
::prost::alloc::string::String,
>,
#[prost(string, tag = "2")]
pub target_account: ::prost::alloc::string::String,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct UnmapOpeningBalanceAccountResponse {
@@ -489,16 +482,12 @@ pub struct OpeningBalanceAccountMapping {
pub source_period_id: i64,
#[prost(string, tag = "3")]
pub source_profile_name: ::prost::alloc::string::String,
#[prost(string, repeated, tag = "4")]
pub source_account_segments: ::prost::alloc::vec::Vec<
::prost::alloc::string::String,
>,
#[prost(string, tag = "4")]
pub source_account: ::prost::alloc::string::String,
#[prost(string, tag = "5")]
pub target_profile_name: ::prost::alloc::string::String,
#[prost(string, repeated, tag = "6")]
pub target_account_segments: ::prost::alloc::vec::Vec<
::prost::alloc::string::String,
>,
#[prost(string, tag = "6")]
pub target_account: ::prost::alloc::string::String,
#[prost(string, tag = "7")]
pub currency: ::prost::alloc::string::String,
/// Signed balances use the debit-positive convention.
@@ -536,10 +525,8 @@ pub struct UnmappedSourceBalance {
pub source_period_id: i64,
#[prost(string, tag = "2")]
pub source_profile_name: ::prost::alloc::string::String,
#[prost(string, repeated, tag = "3")]
pub source_account_segments: ::prost::alloc::vec::Vec<
::prost::alloc::string::String,
>,
#[prost(string, tag = "3")]
pub source_account: ::prost::alloc::string::String,
#[prost(string, tag = "4")]
pub currency: ::prost::alloc::string::String,
/// Signed portion not covered by a mapping, using the debit-positive
@@ -556,10 +543,8 @@ pub struct UnmappedSourceDenominationBalance {
pub source_period_id: i64,
#[prost(string, tag = "2")]
pub source_profile_name: ::prost::alloc::string::String,
#[prost(string, repeated, tag = "3")]
pub source_account_segments: ::prost::alloc::vec::Vec<
::prost::alloc::string::String,
>,
#[prost(string, tag = "3")]
pub source_account: ::prost::alloc::string::String,
#[prost(string, tag = "4")]
pub denomination_currency: ::prost::alloc::string::String,
/// Exact foreign-currency quantity that no mapping carries forward.

View File

@@ -26,7 +26,7 @@ pub struct GetTableStructureResponse {
pub struct TableStructureResponse {
/// Columns of the physical table, including system columns (id, deleted,
/// created_at, row_revision), user-defined columns, and any foreign-key columns such as
/// named by whoever declared each link, plus the dedicated "account_id" on
/// named by whoever declared each link, plus the dedicated "account" on
/// ACCOUNTING-enabled tables. May be empty if the physical table is missing.
#[prost(message, repeated, tag = "1")]
pub columns: ::prost::alloc::vec::Vec<TableColumn>,
@@ -34,7 +34,7 @@ pub struct TableStructureResponse {
/// One physical column entry as reported by information_schema.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TableColumn {
/// Column name exactly as defined in PostgreSQL.
/// Public column name. Physical account_id columns are exposed as account.
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
/// Normalized data type string derived from information_schema:

View File

@@ -18,7 +18,7 @@ pub struct PostTableDataRequest {
/// * System/FK columns:
/// • "deleted" (BOOLEAN), optional; default FALSE if not provided
/// • one BIGINT per link, named by whoever declared it
/// • "account_id" (BIGINT) on ACCOUNTING-enabled tables
/// • "account" (slash-delimited account string) on ACCOUNTING-enabled tables
///
/// Type expectations by SQL type:
///
@@ -191,7 +191,7 @@ pub struct GetTableDataResponse {
/// * id, deleted
/// * all user-defined columns from the table definition
/// * one column per link, named by whoever declared it
/// * account_id for ACCOUNTING-enabled tables
/// * account for ACCOUNTING-enabled tables
///
/// All values are returned as TEXT via col::TEXT and COALESCEed to empty string
/// (NULL becomes ""). The row is returned only if deleted = FALSE.
@@ -482,7 +482,7 @@ pub mod tables_data_client {
/// * Validates profile and table definition
/// * Returns all columns as strings (COALESCE(col::TEXT, '') AS col)
/// including: id, deleted, row_revision, all user-defined columns, and FK columns
/// named by whoever declared each link, plus "account_id" on
/// named by whoever declared each link, plus "account" on
/// ACCOUNTING-enabled tables
/// * Fails with NOT_FOUND if record does not exist or is soft-deleted
/// * If the physical table is missing but the definition exists, returns INTERNAL
@@ -675,7 +675,7 @@ pub mod tables_data_server {
/// * Validates profile and table definition
/// * Returns all columns as strings (COALESCE(col::TEXT, '') AS col)
/// including: id, deleted, row_revision, all user-defined columns, and FK columns
/// named by whoever declared each link, plus "account_id" on
/// named by whoever declared each link, plus "account" on
/// ACCOUNTING-enabled tables
/// * Fails with NOT_FOUND if record does not exist or is soft-deleted
/// * If the physical table is missing but the definition exists, returns INTERNAL

View File

@@ -43,6 +43,7 @@ pub const TRAILING_SYSTEM_COLUMNS: [SystemColumn; 1] = [SystemColumn {
/// Its declaration names that profile's schema, so it is built where the
/// profile is known rather than spelled out here.
pub const ACCOUNT_REFERENCE_COLUMN: &str = "account_id";
pub const ACCOUNT_API_COLUMN: &str = "account";
/// Every system column name, whether or not the column is on a given table.
///
@@ -59,12 +60,13 @@ pub fn system_column_names() -> impl Iterator<Item = &'static str> {
/// Whether `name` is a system column: a name that is safe to show a client
/// as-is, and that a user may not claim for a column alias or a table.
pub fn is_system_column(name: &str) -> bool {
system_column_names().any(|system_name| system_name == name)
name == ACCOUNT_API_COLUMN || system_column_names().any(|system_name| system_name == name)
}
/// The system column names in a message, as `'id', 'deleted', ...`.
pub fn system_column_name_list() -> String {
system_column_names()
.chain(std::iter::once(ACCOUNT_API_COLUMN))
.map(|name| format!("'{name}'"))
.collect::<Vec<_>>()
.join(", ")
@@ -73,7 +75,8 @@ pub fn system_column_name_list() -> String {
#[cfg(test)]
mod tests {
use super::{
ACCOUNT_REFERENCE_COLUMN, is_system_column, system_column_name_list, system_column_names,
ACCOUNT_API_COLUMN, ACCOUNT_REFERENCE_COLUMN, is_system_column, system_column_name_list,
system_column_names,
};
#[test]
@@ -86,6 +89,7 @@ mod tests {
#[test]
fn a_conditional_column_is_reserved_on_every_table() {
assert!(is_system_column(ACCOUNT_REFERENCE_COLUMN));
assert!(is_system_column(ACCOUNT_API_COLUMN));
}
#[test]
@@ -98,7 +102,7 @@ mod tests {
fn the_name_list_reads_as_a_sentence_fragment() {
assert_eq!(
system_column_name_list(),
"'id', 'deleted', 'row_revision', 'created_at', 'account_id'"
"'id', 'deleted', 'row_revision', 'created_at', 'account_id', 'account'"
);
}
}