relate-core 1.4.0

Core values, errors, and IDs for Relate
Documentation
//! The integer-argument sites' authored texts.
//!
//! Written once so every layer that raises a site's rejection reads the
//! same text: the planner's checks at plan time and, for the sites with a
//! runtime coercion, the executor's argument coercion at run time. The
//! slice bounds are plan-time only — their runtime coercion has no type
//! rejection — and `SKIP` / `LIMIT` carry their own planner tokens.
//! [`crate::FUNCTION_REQUIRES_ONE_ARGUMENT`] sets the precedent for a
//! rejection spelling shared across layers. The `CALL { … } IN
//! TRANSACTIONS` modifier sites (the batch size, the concurrency hint,
//! REL8-2179) are rows in the same table: the planner's literal check
//! and the executor's runtime coercion read one row, so the plan-time
//! and run-time spellings cannot diverge.

/// One ADR-0175 function-argument site's authored texts.
pub struct IntegerArgSite {
    /// The `InvalidArgumentType` detail of a non-numeric argument.
    pub type_error: &'static str,
    /// The site label a `NumberOutOfRange` rejection names. `None` where the
    /// site has no runtime coercion to label: `range()`'s out-of-range
    /// rejection (zero step, overflowing length) is authored in its executor,
    /// not per argument.
    pub range: Option<&'static str>,
}

/// A site that only gates the argument's type at plan time.
const fn type_site(type_error: &'static str) -> IntegerArgSite {
    IntegerArgSite {
        type_error,
        range: None,
    }
}

/// A site whose runtime coercion raises `NumberOutOfRange`.
const fn coercion_site(type_error: &'static str, range: &'static str) -> IntegerArgSite {
    IntegerArgSite {
        type_error,
        range: Some(range),
    }
}

/// The `CALL { … } IN TRANSACTIONS` modifier sites (REL8-2179): the
/// `OF n ROWS` batch size and the `IN n CONCURRENT TRANSACTIONS` hint.
/// Both fields carry the class mapping, stated once: `type_error` is
/// the plan-time `InvalidArgumentType` sentence a non-INTEGER literal
/// rejects with and the runtime wrong-typed (`TypeError`) detail;
/// `range` is the plan-time `InvalidArgument` sentence a non-positive
/// INTEGER literal rejects with and the runtime `NumberOutOfRange`
/// (`ArgumentError`) detail for the batch size — a whole sentence,
/// where a function site's `range` names its site.
pub const TX_BATCH_SIZE: IntegerArgSite = coercion_site(
    "batch size must be an integer",
    "batch size must be a positive integer",
);
pub const TX_CONCURRENCY: IntegerArgSite = coercion_site(
    "concurrency must be an integer",
    "concurrency must be a positive integer",
);

/// The `ON ERROR RETRY … WAIT n` retry duration: the plan-time
/// shape gate's two sentences — the non-numeric rejection's type text
/// and the negative-duration rejection's range text.
pub const TX_RETRY_DURATION: IntegerArgSite = coercion_site(
    "retry duration must be numeric",
    "retry duration must be non-negative",
);

/// A site's range sentence — the one accessor every layer reads (the
/// planner's non-positive literal arms through
/// [`crate::invalid_argument_text`], the executor's runtime
/// `NumberOutOfRange` detail directly), owning the coercion-site
/// invariant the `string_index_arg` sites already rely on.
pub fn range_text(site: &IntegerArgSite) -> &'static str {
    site.range
        .expect("a coercion site states its range sentence")
}

pub const RANGE_START: IntegerArgSite = type_site("range() start");
pub const RANGE_END: IntegerArgSite = type_site("range() end");
pub const RANGE_STEP: IntegerArgSite = type_site("range() step");
pub const SUBSTRING_START: IntegerArgSite =
    coercion_site("substring() start must be an integer", "substring() start");
pub const SUBSTRING_LENGTH: IntegerArgSite = coercion_site(
    "substring() length must be an integer",
    "substring() length",
);
pub const LEFT_LENGTH: IntegerArgSite =
    coercion_site("left() length must be an integer", "left() length");
pub const RIGHT_LENGTH: IntegerArgSite =
    coercion_site("right() length must be an integer", "right() length");
pub const LIST_INDEX: IntegerArgSite = type_site("list index must be an integer");
pub const SLICE_START: IntegerArgSite = type_site("slice start must be an integer");
pub const SLICE_END: IntegerArgSite = type_site("slice end must be an integer");